Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceTargetLoweringMIPS32.h - MIPS32 lowering ---*- C++-*-===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Jim Stichnoth | 92a6e5b | 2015-12-02 16:52:44 -0800 | [diff] [blame] | 11 | /// \brief Declares the TargetLoweringMIPS32 class, which implements the |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 12 | /// TargetLowering interface for the MIPS 32-bit architecture. |
| 13 | /// |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H |
| 17 | #define SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H |
| 18 | |
John Porto | 53611e2 | 2015-12-30 07:30:10 -0800 | [diff] [blame] | 19 | #include "IceAssemblerMIPS32.h" |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 20 | #include "IceDefs.h" |
| 21 | #include "IceInstMIPS32.h" |
| 22 | #include "IceRegistersMIPS32.h" |
| 23 | #include "IceTargetLowering.h" |
| 24 | |
| 25 | namespace Ice { |
John Porto | 4a56686 | 2016-01-04 09:33:41 -0800 | [diff] [blame] | 26 | namespace MIPS32 { |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 27 | |
| 28 | class TargetMIPS32 : public TargetLowering { |
| 29 | TargetMIPS32() = delete; |
| 30 | TargetMIPS32(const TargetMIPS32 &) = delete; |
| 31 | TargetMIPS32 &operator=(const TargetMIPS32 &) = delete; |
| 32 | |
| 33 | public: |
John Porto | 53611e2 | 2015-12-30 07:30:10 -0800 | [diff] [blame] | 34 | ~TargetMIPS32() override = default; |
| 35 | |
Karl Schimpf | 5403f5d | 2016-01-15 11:07:46 -0800 | [diff] [blame] | 36 | static void staticInit(GlobalContext *Ctx); |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 37 | static bool shouldBePooled(const Constant *C) { |
| 38 | (void)C; |
| 39 | return false; |
| 40 | } |
John Porto | 53611e2 | 2015-12-30 07:30:10 -0800 | [diff] [blame] | 41 | static std::unique_ptr<::Ice::TargetLowering> create(Cfg *Func) { |
| 42 | return makeUnique<TargetMIPS32>(Func); |
| 43 | } |
| 44 | |
| 45 | std::unique_ptr<::Ice::Assembler> createAssembler() const override { |
| 46 | return makeUnique<MIPS32::AssemblerMIPS32>(); |
| 47 | } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 48 | |
| 49 | void translateOm1() override; |
| 50 | void translateO2() override; |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 51 | bool doBranchOpt(Inst *Instr, const CfgNode *NextNode) override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 52 | |
| 53 | SizeT getNumRegisters() const override { return RegMIPS32::Reg_NUM; } |
Jim Stichnoth | 8aa3966 | 2016-02-10 11:20:30 -0800 | [diff] [blame] | 54 | Variable *getPhysicalRegister(RegNumT RegNum, |
| 55 | Type Ty = IceType_void) override; |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 56 | const char *getRegName(RegNumT RegNum, Type Ty) const override; |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 57 | SmallBitVector getRegisterSet(RegSetMask Include, |
| 58 | RegSetMask Exclude) const override; |
| 59 | const SmallBitVector & |
Jim Stichnoth | c59288b | 2015-11-09 11:38:40 -0800 | [diff] [blame] | 60 | getRegistersForVariable(const Variable *Var) const override { |
| 61 | RegClass RC = Var->getRegClass(); |
| 62 | assert(RC < RC_Target); |
| 63 | return TypeToRegisterSet[RC]; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 64 | } |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 65 | const SmallBitVector & |
Jim Stichnoth | b40595a | 2016-01-29 06:14:31 -0800 | [diff] [blame] | 66 | getAllRegistersForVariable(const Variable *Var) const override { |
| 67 | RegClass RC = Var->getRegClass(); |
| 68 | assert(RC < RC_Target); |
| 69 | return TypeToRegisterSetUnfiltered[RC]; |
| 70 | } |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 71 | const SmallBitVector &getAliasesForRegister(RegNumT Reg) const override { |
John Porto | bb0a5fe | 2015-09-04 11:23:41 -0700 | [diff] [blame] | 72 | return RegisterAliases[Reg]; |
| 73 | } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 74 | bool hasFramePointer() const override { return UsesFramePointer; } |
David Sehr | e39d0ca | 2015-11-06 11:25:41 -0800 | [diff] [blame] | 75 | void setHasFramePointer() override { UsesFramePointer = true; } |
Jim Stichnoth | 8aa3966 | 2016-02-10 11:20:30 -0800 | [diff] [blame] | 76 | RegNumT getStackReg() const override { return RegMIPS32::Reg_SP; } |
| 77 | RegNumT getFrameReg() const override { return RegMIPS32::Reg_FP; } |
| 78 | RegNumT getFrameOrStackReg() const override { |
David Sehr | 2f3b8ec | 2015-11-16 16:51:39 -0800 | [diff] [blame] | 79 | return UsesFramePointer ? getFrameReg() : getStackReg(); |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 80 | } |
| 81 | size_t typeWidthInBytesOnStack(Type Ty) const override { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 82 | // Round up to the next multiple of 4 bytes. In particular, i1, i8, and i16 |
| 83 | // are rounded up to 4 bytes. |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 84 | return (typeWidthInBytes(Ty) + 3) & ~3; |
| 85 | } |
David Sehr | e39d0ca | 2015-11-06 11:25:41 -0800 | [diff] [blame] | 86 | uint32_t getStackAlignment() const override { |
| 87 | // TODO(sehr): what is the stack alignment? |
| 88 | return 1; |
| 89 | } |
David Sehr | 2f3b8ec | 2015-11-16 16:51:39 -0800 | [diff] [blame] | 90 | void reserveFixedAllocaArea(size_t Size, size_t Align) override { |
| 91 | // TODO(sehr): Implement fixed stack layout. |
| 92 | (void)Size; |
| 93 | (void)Align; |
| 94 | llvm::report_fatal_error("Not yet implemented"); |
| 95 | } |
| 96 | int32_t getFrameFixedAllocaOffset() const override { |
| 97 | // TODO(sehr): Implement fixed stack layout. |
| 98 | llvm::report_fatal_error("Not yet implemented"); |
| 99 | return 0; |
| 100 | } |
Andrew Scull | 87f80c1 | 2015-07-20 10:19:16 -0700 | [diff] [blame] | 101 | |
Andrew Scull | 6d47bcd | 2015-09-17 17:10:05 -0700 | [diff] [blame] | 102 | bool shouldSplitToVariable64On32(Type Ty) const override { |
| 103 | return Ty == IceType_i64; |
| 104 | } |
| 105 | |
Andrew Scull | 87f80c1 | 2015-07-20 10:19:16 -0700 | [diff] [blame] | 106 | // TODO(ascull): what is the best size of MIPS? |
| 107 | SizeT getMinJumpTableSize() const override { return 3; } |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 108 | void emitJumpTable(const Cfg *Func, |
| 109 | const InstJumpTable *JumpTable) const override; |
Andrew Scull | 87f80c1 | 2015-07-20 10:19:16 -0700 | [diff] [blame] | 110 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 111 | void emitVariable(const Variable *Var) const override; |
| 112 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 113 | void emit(const ConstantInteger32 *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 114 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 115 | llvm::report_fatal_error("Not yet implemented"); |
| 116 | } |
| 117 | void emit(const ConstantInteger64 *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 118 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 119 | llvm::report_fatal_error("Not yet implemented"); |
| 120 | } |
| 121 | void emit(const ConstantFloat *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 122 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 123 | llvm::report_fatal_error("Not yet implemented"); |
| 124 | } |
| 125 | void emit(const ConstantDouble *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 126 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 127 | llvm::report_fatal_error("Not yet implemented"); |
| 128 | } |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame] | 129 | void emit(const ConstantUndef *C) const final { |
| 130 | (void)C; |
| 131 | llvm::report_fatal_error("Not yet implemented"); |
| 132 | } |
| 133 | void emit(const ConstantRelocatable *C) const final { |
| 134 | (void)C; |
| 135 | llvm::report_fatal_error("Not yet implemented"); |
| 136 | } |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 137 | |
| 138 | // The following are helpers that insert lowered MIPS32 instructions with |
| 139 | // minimal syntactic overhead, so that the lowering code can look as close to |
| 140 | // assembly as practical. |
| 141 | void _add(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 142 | Context.insert<InstMIPS32Add>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Reed Kotler | 00e3604 | 2016-02-01 20:52:19 -0800 | [diff] [blame] | 145 | void _addu(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 146 | Context.insert<InstMIPS32Addu>(Dest, Src0, Src1); |
| 147 | } |
| 148 | |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 149 | void _and(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 150 | Context.insert<InstMIPS32And>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Reed Kotler | 3fe4b57 | 2016-02-23 18:59:43 -0800 | [diff] [blame] | 153 | void _br(CfgNode *Target) { Context.insert<InstMIPS32Br>(Target); } |
| 154 | |
Reed Kotler | d00d48d | 2015-07-08 09:49:07 -0700 | [diff] [blame] | 155 | void _ret(Variable *RA, Variable *Src0 = nullptr) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 156 | Context.insert<InstMIPS32Ret>(RA, Src0); |
Reed Kotler | d00d48d | 2015-07-08 09:49:07 -0700 | [diff] [blame] | 157 | } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 158 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 159 | void _addiu(Variable *Dest, Variable *Src, uint32_t Imm) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 160 | Context.insert<InstMIPS32Addiu>(Dest, Src, Imm); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | void _lui(Variable *Dest, uint32_t Imm) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 164 | Context.insert<InstMIPS32Lui>(Dest, Imm); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void _mov(Variable *Dest, Operand *Src0) { |
| 168 | assert(Dest != nullptr); |
| 169 | // Variable* Src0_ = llvm::dyn_cast<Variable>(Src0); |
| 170 | if (llvm::isa<ConstantRelocatable>(Src0)) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 171 | Context.insert<InstMIPS32La>(Dest, Src0); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 172 | } else { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 173 | auto *Instr = Context.insert<InstMIPS32Mov>(Dest, Src0); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 174 | if (Instr->isMultiDest()) { |
| 175 | // If Instr is multi-dest, then Dest must be a Variable64On32. We add a |
| 176 | // fake-def for Instr.DestHi here. |
| 177 | assert(llvm::isa<Variable64On32>(Dest)); |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 178 | Context.insert<InstFakeDef>(Instr->getDestHi()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
Reed Kotler | a80cdbc | 2016-02-19 22:03:29 -0800 | [diff] [blame] | 183 | void _mfhi(Variable *Dest, Operand *Src) { |
| 184 | Context.insert<InstMIPS32Mfhi>(Dest, Src); |
| 185 | } |
| 186 | |
| 187 | void _mflo(Variable *Dest, Operand *Src) { |
| 188 | Context.insert<InstMIPS32Mflo>(Dest, Src); |
| 189 | } |
| 190 | |
| 191 | void _mthi(Variable *Dest, Operand *Src) { |
| 192 | Context.insert<InstMIPS32Mthi>(Dest, Src); |
| 193 | } |
| 194 | |
| 195 | void _mtlo(Variable *Dest, Operand *Src) { |
| 196 | Context.insert<InstMIPS32Mtlo>(Dest, Src); |
| 197 | } |
| 198 | |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 199 | void _mul(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 200 | Context.insert<InstMIPS32Mul>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Reed Kotler | a80cdbc | 2016-02-19 22:03:29 -0800 | [diff] [blame] | 203 | void _mult(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 204 | Context.insert<InstMIPS32Mult>(Dest, Src0, Src1); |
| 205 | } |
| 206 | |
| 207 | void _multu(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 208 | Context.insert<InstMIPS32Multu>(Dest, Src0, Src1); |
| 209 | } |
| 210 | |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 211 | void _or(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 212 | Context.insert<InstMIPS32Or>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 215 | void _ori(Variable *Dest, Variable *Src, uint32_t Imm) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 216 | Context.insert<InstMIPS32Ori>(Dest, Src, Imm); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 219 | void _sub(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 220 | Context.insert<InstMIPS32Sub>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Reed Kotler | 00e3604 | 2016-02-01 20:52:19 -0800 | [diff] [blame] | 223 | void _sltu(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 224 | Context.insert<InstMIPS32Sltu>(Dest, Src0, Src1); |
| 225 | } |
| 226 | |
| 227 | void _subu(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 228 | Context.insert<InstMIPS32Subu>(Dest, Src0, Src1); |
| 229 | } |
| 230 | |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 231 | void _xor(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 232 | Context.insert<InstMIPS32Xor>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 235 | void lowerArguments() override; |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 236 | |
| 237 | /// Operand legalization helpers. To deal with address mode constraints, |
| 238 | /// the helpers will create a new Operand and emit instructions that |
| 239 | /// guarantee that the Operand kind is one of those indicated by the |
| 240 | /// LegalMask (a bitmask of allowed kinds). If the input Operand is known |
| 241 | /// to already meet the constraints, it may be simply returned as the result, |
| 242 | /// without creating any new instructions or operands. |
| 243 | enum OperandLegalization { |
| 244 | Legal_None = 0, |
| 245 | Legal_Reg = 1 << 0, // physical register, not stack location |
| 246 | Legal_Imm = 1 << 1, |
| 247 | Legal_Mem = 1 << 2, |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame] | 248 | Legal_Default = ~Legal_None |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 249 | }; |
| 250 | typedef uint32_t LegalMask; |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame] | 251 | Operand *legalize(Operand *From, LegalMask Allowed = Legal_Default, |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 252 | RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 253 | |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 254 | Variable *legalizeToVar(Operand *From, RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 255 | |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 256 | Variable *legalizeToReg(Operand *From, RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 257 | |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 258 | Variable *makeReg(Type Ty, RegNumT RegNum = RegNumT()); |
Reed Kotler | 953568f | 2016-02-17 05:37:01 -0800 | [diff] [blame] | 259 | |
| 260 | Variable *I32Reg(RegNumT RegNum = RegNumT()) { |
| 261 | return makeReg(IceType_i32, RegNum); |
| 262 | } |
| 263 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 264 | static Type stackSlotType(); |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 265 | Variable *copyToReg(Operand *Src, RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 266 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 267 | void addProlog(CfgNode *Node) override; |
| 268 | void addEpilog(CfgNode *Node) override; |
| 269 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 270 | // Ensure that a 64-bit Variable has been split into 2 32-bit |
| 271 | // Variables, creating them if necessary. This is needed for all |
| 272 | // I64 operations. |
| 273 | void split64(Variable *Var); |
| 274 | Operand *loOperand(Operand *Operand); |
| 275 | Operand *hiOperand(Operand *Operand); |
| 276 | |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 277 | Operand *legalizeUndef(Operand *From, RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 278 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 279 | protected: |
| 280 | explicit TargetMIPS32(Cfg *Func); |
| 281 | |
| 282 | void postLower() override; |
| 283 | |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 284 | void lowerAlloca(const InstAlloca *Instr) override; |
| 285 | void lowerArithmetic(const InstArithmetic *Instr) override; |
| 286 | void lowerInt64Arithmetic(const InstArithmetic *Instr, Variable *Dest, |
Reed Kotler | 00e3604 | 2016-02-01 20:52:19 -0800 | [diff] [blame] | 287 | Operand *Src0, Operand *Src1); |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 288 | void lowerAssign(const InstAssign *Instr) override; |
| 289 | void lowerBr(const InstBr *Instr) override; |
Eric Holk | 67c7c41 | 2016-04-15 13:05:37 -0700 | [diff] [blame^] | 290 | void lowerBreakpoint(const InstBreakpoint *Instr) override; |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 291 | void lowerCall(const InstCall *Instr) override; |
| 292 | void lowerCast(const InstCast *Instr) override; |
| 293 | void lowerExtractElement(const InstExtractElement *Instr) override; |
| 294 | void lowerFcmp(const InstFcmp *Instr) override; |
| 295 | void lowerIcmp(const InstIcmp *Instr) override; |
| 296 | void lowerIntrinsicCall(const InstIntrinsicCall *Instr) override; |
| 297 | void lowerInsertElement(const InstInsertElement *Instr) override; |
| 298 | void lowerLoad(const InstLoad *Instr) override; |
| 299 | void lowerPhi(const InstPhi *Instr) override; |
| 300 | void lowerRet(const InstRet *Instr) override; |
| 301 | void lowerSelect(const InstSelect *Instr) override; |
| 302 | void lowerStore(const InstStore *Instr) override; |
| 303 | void lowerSwitch(const InstSwitch *Instr) override; |
| 304 | void lowerUnreachable(const InstUnreachable *Instr) override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 305 | void prelowerPhis() override; |
John Porto | f419854 | 2015-11-20 14:17:23 -0800 | [diff] [blame] | 306 | uint32_t getCallStackArgumentsSizeBytes(const InstCall *Instr) override { |
| 307 | (void)Instr; |
| 308 | return 0; |
| 309 | } |
John Porto | 5e0a8a7 | 2015-11-20 13:50:36 -0800 | [diff] [blame] | 310 | void genTargetHelperCallFor(Inst *Instr) override { (void)Instr; } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 311 | void doAddressOptLoad() override; |
| 312 | void doAddressOptStore() override; |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 313 | void randomlyInsertNop(float Probability, |
| 314 | RandomNumberGenerator &RNG) override; |
| 315 | void |
Jim Stichnoth | 8aa3966 | 2016-02-10 11:20:30 -0800 | [diff] [blame] | 316 | makeRandomRegisterPermutation(llvm::SmallVectorImpl<RegNumT> &Permutation, |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 317 | const SmallBitVector &ExcludeRegisters, |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 318 | uint64_t Salt) const override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 319 | |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 320 | bool UsesFramePointer = false; |
| 321 | bool NeedsStackAlignment = false; |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 322 | static SmallBitVector TypeToRegisterSet[RCMIPS32_NUM]; |
| 323 | static SmallBitVector TypeToRegisterSetUnfiltered[RCMIPS32_NUM]; |
| 324 | static SmallBitVector RegisterAliases[RegMIPS32::Reg_NUM]; |
| 325 | SmallBitVector RegsUsed; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 326 | VarList PhysicalRegisters[IceType_NUM]; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 327 | |
| 328 | private: |
John Porto | 53611e2 | 2015-12-30 07:30:10 -0800 | [diff] [blame] | 329 | ENABLE_MAKE_UNIQUE; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 330 | }; |
| 331 | |
John Porto | 0f86d03 | 2015-06-15 07:44:27 -0700 | [diff] [blame] | 332 | class TargetDataMIPS32 final : public TargetDataLowering { |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 333 | TargetDataMIPS32() = delete; |
| 334 | TargetDataMIPS32(const TargetDataMIPS32 &) = delete; |
| 335 | TargetDataMIPS32 &operator=(const TargetDataMIPS32 &) = delete; |
| 336 | |
| 337 | public: |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 338 | static std::unique_ptr<TargetDataLowering> create(GlobalContext *Ctx) { |
| 339 | return std::unique_ptr<TargetDataLowering>(new TargetDataMIPS32(Ctx)); |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 340 | } |
| 341 | |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 342 | void lowerGlobals(const VariableDeclarationList &Vars, |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 343 | const std::string &SectionSuffix) override; |
John Porto | 0f86d03 | 2015-06-15 07:44:27 -0700 | [diff] [blame] | 344 | void lowerConstants() override; |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 345 | void lowerJumpTables() override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 346 | |
| 347 | protected: |
| 348 | explicit TargetDataMIPS32(GlobalContext *Ctx); |
| 349 | |
| 350 | private: |
Jim Stichnoth | e587d94 | 2015-06-22 15:49:04 -0700 | [diff] [blame] | 351 | ~TargetDataMIPS32() override = default; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 352 | template <typename T> static void emitConstantPool(GlobalContext *Ctx); |
| 353 | }; |
| 354 | |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 355 | class TargetHeaderMIPS32 final : public TargetHeaderLowering { |
| 356 | TargetHeaderMIPS32() = delete; |
| 357 | TargetHeaderMIPS32(const TargetHeaderMIPS32 &) = delete; |
| 358 | TargetHeaderMIPS32 &operator=(const TargetHeaderMIPS32 &) = delete; |
| 359 | |
| 360 | public: |
| 361 | static std::unique_ptr<TargetHeaderLowering> create(GlobalContext *Ctx) { |
| 362 | return std::unique_ptr<TargetHeaderLowering>(new TargetHeaderMIPS32(Ctx)); |
| 363 | } |
| 364 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 365 | void lower() override; |
| 366 | |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 367 | protected: |
| 368 | explicit TargetHeaderMIPS32(GlobalContext *Ctx); |
| 369 | |
| 370 | private: |
| 371 | ~TargetHeaderMIPS32() = default; |
| 372 | }; |
| 373 | |
John Porto | 4a56686 | 2016-01-04 09:33:41 -0800 | [diff] [blame] | 374 | } // end of namespace MIPS32 |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 375 | } // end of namespace Ice |
| 376 | |
| 377 | #endif // SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H |