| OLD | NEW |
| 1 //===- subzero/src/IceTargetLoweringMIPS32.cpp - MIPS32 lowering ----------===// | 1 //===- subzero/src/IceTargetLoweringMIPS32.cpp - MIPS32 lowering ----------===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 Type Ty = From->getType(); | 993 Type Ty = From->getType(); |
| 994 // Assert that a physical register is allowed. To date, all calls | 994 // Assert that a physical register is allowed. To date, all calls |
| 995 // to legalize() allow a physical register. Legal_Flex converts | 995 // to legalize() allow a physical register. Legal_Flex converts |
| 996 // registers to the right type OperandMIPS32FlexReg as needed. | 996 // registers to the right type OperandMIPS32FlexReg as needed. |
| 997 assert(Allowed & Legal_Reg); | 997 assert(Allowed & Legal_Reg); |
| 998 // Go through the various types of operands: | 998 // Go through the various types of operands: |
| 999 // OperandMIPS32Mem, OperandMIPS32Flex, Constant, and Variable. | 999 // OperandMIPS32Mem, OperandMIPS32Flex, Constant, and Variable. |
| 1000 // Given the above assertion, if type of operand is not legal | 1000 // Given the above assertion, if type of operand is not legal |
| 1001 // (e.g., OperandMIPS32Mem and !Legal_Mem), we can always copy | 1001 // (e.g., OperandMIPS32Mem and !Legal_Mem), we can always copy |
| 1002 // to a register. | 1002 // to a register. |
| 1003 if (auto C = llvm::dyn_cast<ConstantRelocatable>(From)) { | 1003 if (auto *C = llvm::dyn_cast<ConstantRelocatable>(From)) { |
| 1004 (void)C; | 1004 (void)C; |
| 1005 return From; | 1005 return From; |
| 1006 } else if (auto *C32 = llvm::dyn_cast<ConstantInteger32>(From)) { | 1006 } else if (auto *C32 = llvm::dyn_cast<ConstantInteger32>(From)) { |
| 1007 uint32_t Value = static_cast<uint32_t>(C32->getValue()); | 1007 uint32_t Value = static_cast<uint32_t>(C32->getValue()); |
| 1008 // Check if the immediate will fit in a Flexible second operand, | 1008 // Check if the immediate will fit in a Flexible second operand, |
| 1009 // if a Flexible second operand is allowed. We need to know the exact | 1009 // if a Flexible second operand is allowed. We need to know the exact |
| 1010 // value, so that rules out relocatable constants. | 1010 // value, so that rules out relocatable constants. |
| 1011 // Also try the inverse and use MVN if possible. | 1011 // Also try the inverse and use MVN if possible. |
| 1012 // Do a movw/movt to a register. | 1012 // Do a movw/movt to a register. |
| 1013 Variable *Reg; | 1013 Variable *Reg; |
| 1014 if (RegNum == Variable::NoRegister) | 1014 if (RegNum == Variable::NoRegister) |
| 1015 Reg = makeReg(Ty, RegNum); | 1015 Reg = makeReg(Ty, RegNum); |
| 1016 else | 1016 else |
| 1017 Reg = getPhysicalRegister(RegNum); | 1017 Reg = getPhysicalRegister(RegNum); |
| 1018 if (isInt<16>(int32_t(Value))) { | 1018 if (isInt<16>(int32_t(Value))) { |
| 1019 _addiu(Reg, getPhysicalRegister(RegMIPS32::Reg_ZERO, Ty), Value); | 1019 _addiu(Reg, getPhysicalRegister(RegMIPS32::Reg_ZERO, Ty), Value); |
| 1020 } else { | 1020 } else { |
| 1021 uint32_t UpperBits = (Value >> 16) & 0xFFFF; | 1021 uint32_t UpperBits = (Value >> 16) & 0xFFFF; |
| 1022 (void)UpperBits; | 1022 (void)UpperBits; |
| 1023 uint32_t LowerBits = Value & 0xFFFF; | 1023 uint32_t LowerBits = Value & 0xFFFF; |
| 1024 Variable *TReg = makeReg(Ty, RegNum); | 1024 Variable *TReg = makeReg(Ty, RegNum); |
| 1025 _lui(TReg, UpperBits); | 1025 _lui(TReg, UpperBits); |
| 1026 _ori(Reg, TReg, LowerBits); | 1026 _ori(Reg, TReg, LowerBits); |
| 1027 } | 1027 } |
| 1028 return Reg; | 1028 return Reg; |
| 1029 } | 1029 } |
| 1030 if (auto Var = llvm::dyn_cast<Variable>(From)) { | 1030 if (auto *Var = llvm::dyn_cast<Variable>(From)) { |
| 1031 // Check if the variable is guaranteed a physical register. This | 1031 // Check if the variable is guaranteed a physical register. This |
| 1032 // can happen either when the variable is pre-colored or when it is | 1032 // can happen either when the variable is pre-colored or when it is |
| 1033 // assigned infinite weight. | 1033 // assigned infinite weight. |
| 1034 bool MustHaveRegister = (Var->hasReg() || Var->mustHaveReg()); | 1034 bool MustHaveRegister = (Var->hasReg() || Var->mustHaveReg()); |
| 1035 // We need a new physical register for the operand if: | 1035 // We need a new physical register for the operand if: |
| 1036 // Mem is not allowed and Var isn't guaranteed a physical | 1036 // Mem is not allowed and Var isn't guaranteed a physical |
| 1037 // register, or | 1037 // register, or |
| 1038 // RegNum is required and Var->getRegNum() doesn't match. | 1038 // RegNum is required and Var->getRegNum() doesn't match. |
| 1039 if ((!(Allowed & Legal_Mem) && !MustHaveRegister) || | 1039 if ((!(Allowed & Legal_Mem) && !MustHaveRegister) || |
| 1040 (RegNum != Variable::NoRegister && RegNum != Var->getRegNum())) { | 1040 (RegNum != Variable::NoRegister && RegNum != Var->getRegNum())) { |
| 1041 From = copyToReg(From, RegNum); | 1041 From = copyToReg(From, RegNum); |
| 1042 } | 1042 } |
| 1043 return From; | 1043 return From; |
| 1044 } | 1044 } |
| 1045 return From; | 1045 return From; |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 TargetHeaderMIPS32::TargetHeaderMIPS32(GlobalContext *Ctx) | 1048 TargetHeaderMIPS32::TargetHeaderMIPS32(GlobalContext *Ctx) |
| 1049 : TargetHeaderLowering(Ctx) {} | 1049 : TargetHeaderLowering(Ctx) {} |
| 1050 | 1050 |
| 1051 void TargetHeaderMIPS32::lower() { | 1051 void TargetHeaderMIPS32::lower() { |
| 1052 OstreamLocker L(Ctx); | 1052 OstreamLocker L(Ctx); |
| 1053 Ostream &Str = Ctx->getStrEmit(); | 1053 Ostream &Str = Ctx->getStrEmit(); |
| 1054 Str << "\t.set\tnomicromips\n"; | 1054 Str << "\t.set\tnomicromips\n"; |
| 1055 Str << "\t.set\tnomips16\n"; | 1055 Str << "\t.set\tnomips16\n"; |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 } // end of namespace Ice | 1058 } // end of namespace Ice |
| OLD | NEW |