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) { |
Mohit Bhakkad | d1e9777 | 2016-07-07 05:07:35 -0700 | [diff] [blame] | 38 | if (auto *ConstDouble = llvm::dyn_cast<ConstantDouble>(C)) { |
| 39 | return !Utils::isPositiveZero(ConstDouble->getValue()); |
| 40 | } |
| 41 | if (llvm::isa<ConstantFloat>(C)) |
| 42 | return true; |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 43 | return false; |
| 44 | } |
John Porto | 53611e2 | 2015-12-30 07:30:10 -0800 | [diff] [blame] | 45 | static std::unique_ptr<::Ice::TargetLowering> create(Cfg *Func) { |
| 46 | return makeUnique<TargetMIPS32>(Func); |
| 47 | } |
| 48 | |
| 49 | std::unique_ptr<::Ice::Assembler> createAssembler() const override { |
| 50 | return makeUnique<MIPS32::AssemblerMIPS32>(); |
| 51 | } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 52 | |
Sagar Thakur | 5cce761 | 2016-05-24 06:25:50 -0700 | [diff] [blame] | 53 | void initNodeForLowering(CfgNode *Node) override { |
| 54 | Computations.forgetProducers(); |
| 55 | Computations.recordProducers(Node); |
| 56 | Computations.dump(Func); |
| 57 | } |
| 58 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 59 | void translateOm1() override; |
| 60 | void translateO2() override; |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 61 | bool doBranchOpt(Inst *Instr, const CfgNode *NextNode) override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 62 | |
| 63 | SizeT getNumRegisters() const override { return RegMIPS32::Reg_NUM; } |
Jim Stichnoth | 8aa3966 | 2016-02-10 11:20:30 -0800 | [diff] [blame] | 64 | Variable *getPhysicalRegister(RegNumT RegNum, |
| 65 | Type Ty = IceType_void) override; |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 66 | const char *getRegName(RegNumT RegNum, Type Ty) const override; |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 67 | SmallBitVector getRegisterSet(RegSetMask Include, |
| 68 | RegSetMask Exclude) const override; |
| 69 | const SmallBitVector & |
Jim Stichnoth | c59288b | 2015-11-09 11:38:40 -0800 | [diff] [blame] | 70 | getRegistersForVariable(const Variable *Var) const override { |
| 71 | RegClass RC = Var->getRegClass(); |
| 72 | assert(RC < RC_Target); |
| 73 | return TypeToRegisterSet[RC]; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 74 | } |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 75 | const SmallBitVector & |
Jim Stichnoth | b40595a | 2016-01-29 06:14:31 -0800 | [diff] [blame] | 76 | getAllRegistersForVariable(const Variable *Var) const override { |
| 77 | RegClass RC = Var->getRegClass(); |
| 78 | assert(RC < RC_Target); |
| 79 | return TypeToRegisterSetUnfiltered[RC]; |
| 80 | } |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 81 | const SmallBitVector &getAliasesForRegister(RegNumT Reg) const override { |
John Porto | bb0a5fe | 2015-09-04 11:23:41 -0700 | [diff] [blame] | 82 | return RegisterAliases[Reg]; |
| 83 | } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 84 | bool hasFramePointer() const override { return UsesFramePointer; } |
David Sehr | e39d0ca | 2015-11-06 11:25:41 -0800 | [diff] [blame] | 85 | void setHasFramePointer() override { UsesFramePointer = true; } |
Jim Stichnoth | 8aa3966 | 2016-02-10 11:20:30 -0800 | [diff] [blame] | 86 | RegNumT getStackReg() const override { return RegMIPS32::Reg_SP; } |
| 87 | RegNumT getFrameReg() const override { return RegMIPS32::Reg_FP; } |
| 88 | RegNumT getFrameOrStackReg() const override { |
David Sehr | 2f3b8ec | 2015-11-16 16:51:39 -0800 | [diff] [blame] | 89 | return UsesFramePointer ? getFrameReg() : getStackReg(); |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 90 | } |
| 91 | size_t typeWidthInBytesOnStack(Type Ty) const override { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 92 | // Round up to the next multiple of 4 bytes. In particular, i1, i8, and i16 |
| 93 | // are rounded up to 4 bytes. |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 94 | return (typeWidthInBytes(Ty) + 3) & ~3; |
| 95 | } |
Sagar Thakur | 1afb483 | 2016-06-16 15:30:24 -0700 | [diff] [blame] | 96 | uint32_t getStackAlignment() const override; |
David Sehr | 2f3b8ec | 2015-11-16 16:51:39 -0800 | [diff] [blame] | 97 | void reserveFixedAllocaArea(size_t Size, size_t Align) override { |
Sagar Thakur | 1afb483 | 2016-06-16 15:30:24 -0700 | [diff] [blame] | 98 | FixedAllocaSizeBytes = Size; |
| 99 | assert(llvm::isPowerOf2_32(Align)); |
| 100 | FixedAllocaAlignBytes = Align; |
| 101 | PrologEmitsFixedAllocas = true; |
David Sehr | 2f3b8ec | 2015-11-16 16:51:39 -0800 | [diff] [blame] | 102 | } |
| 103 | int32_t getFrameFixedAllocaOffset() const override { |
| 104 | // TODO(sehr): Implement fixed stack layout. |
| 105 | llvm::report_fatal_error("Not yet implemented"); |
| 106 | return 0; |
| 107 | } |
Andrew Scull | 87f80c1 | 2015-07-20 10:19:16 -0700 | [diff] [blame] | 108 | |
Sagar Thakur | 1afb483 | 2016-06-16 15:30:24 -0700 | [diff] [blame] | 109 | uint32_t maxOutArgsSizeBytes() const override { return MaxOutArgsSizeBytes; } |
| 110 | |
Andrew Scull | 6d47bcd | 2015-09-17 17:10:05 -0700 | [diff] [blame] | 111 | bool shouldSplitToVariable64On32(Type Ty) const override { |
| 112 | return Ty == IceType_i64; |
| 113 | } |
| 114 | |
Andrew Scull | 87f80c1 | 2015-07-20 10:19:16 -0700 | [diff] [blame] | 115 | // TODO(ascull): what is the best size of MIPS? |
| 116 | SizeT getMinJumpTableSize() const override { return 3; } |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 117 | void emitJumpTable(const Cfg *Func, |
| 118 | const InstJumpTable *JumpTable) const override; |
Andrew Scull | 87f80c1 | 2015-07-20 10:19:16 -0700 | [diff] [blame] | 119 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 120 | void emitVariable(const Variable *Var) const override; |
| 121 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 122 | void emit(const ConstantInteger32 *C) const final { |
Mohit Bhakkad | f3bc5cf | 2016-05-31 11:19:03 -0700 | [diff] [blame] | 123 | if (!BuildDefs::dump()) |
| 124 | return; |
| 125 | Ostream &Str = Ctx->getStrEmit(); |
| 126 | Str << C->getValue(); |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 127 | } |
| 128 | void emit(const ConstantInteger64 *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 129 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 130 | llvm::report_fatal_error("Not yet implemented"); |
| 131 | } |
| 132 | void emit(const ConstantFloat *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 133 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 134 | llvm::report_fatal_error("Not yet implemented"); |
| 135 | } |
| 136 | void emit(const ConstantDouble *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 137 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 138 | llvm::report_fatal_error("Not yet implemented"); |
| 139 | } |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame] | 140 | void emit(const ConstantUndef *C) const final { |
| 141 | (void)C; |
| 142 | llvm::report_fatal_error("Not yet implemented"); |
| 143 | } |
| 144 | void emit(const ConstantRelocatable *C) const final { |
| 145 | (void)C; |
| 146 | llvm::report_fatal_error("Not yet implemented"); |
| 147 | } |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 148 | |
| 149 | // The following are helpers that insert lowered MIPS32 instructions with |
| 150 | // minimal syntactic overhead, so that the lowering code can look as close to |
| 151 | // assembly as practical. |
| 152 | void _add(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 153 | Context.insert<InstMIPS32Add>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Reed Kotler | 00e3604 | 2016-02-01 20:52:19 -0800 | [diff] [blame] | 156 | void _addu(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 157 | Context.insert<InstMIPS32Addu>(Dest, Src0, Src1); |
| 158 | } |
| 159 | |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 160 | void _and(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 161 | Context.insert<InstMIPS32And>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Sagar Thakur | 38dcb59 | 2016-05-09 11:57:59 -0700 | [diff] [blame] | 164 | void _andi(Variable *Dest, Variable *Src, uint32_t Imm) { |
| 165 | Context.insert<InstMIPS32Andi>(Dest, Src, Imm); |
| 166 | } |
| 167 | |
Reed Kotler | 3fe4b57 | 2016-02-23 18:59:43 -0800 | [diff] [blame] | 168 | void _br(CfgNode *Target) { Context.insert<InstMIPS32Br>(Target); } |
| 169 | |
Sagar Thakur | 5cce761 | 2016-05-24 06:25:50 -0700 | [diff] [blame] | 170 | void _br(CfgNode *TargetTrue, CfgNode *TargetFalse, Operand *Src0, |
| 171 | Operand *Src1, CondMIPS32::Cond Condition) { |
| 172 | Context.insert<InstMIPS32Br>(TargetTrue, TargetFalse, Src0, Src1, |
| 173 | Condition); |
| 174 | } |
| 175 | |
| 176 | void _br(CfgNode *TargetTrue, CfgNode *TargetFalse, Operand *Src0, |
| 177 | CondMIPS32::Cond Condition) { |
| 178 | Context.insert<InstMIPS32Br>(TargetTrue, TargetFalse, Src0, Condition); |
| 179 | } |
| 180 | |
Reed Kotler | d00d48d | 2015-07-08 09:49:07 -0700 | [diff] [blame] | 181 | void _ret(Variable *RA, Variable *Src0 = nullptr) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 182 | Context.insert<InstMIPS32Ret>(RA, Src0); |
Reed Kotler | d00d48d | 2015-07-08 09:49:07 -0700 | [diff] [blame] | 183 | } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 184 | |
Srdjan Obucina | 2f593bb | 2016-05-27 14:40:32 -0700 | [diff] [blame] | 185 | void _add_d(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 186 | Context.insert<InstMIPS32Add_d>(Dest, Src0, Src1); |
| 187 | } |
| 188 | |
| 189 | void _add_s(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 190 | Context.insert<InstMIPS32Add_s>(Dest, Src0, Src1); |
| 191 | } |
| 192 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 193 | void _addiu(Variable *Dest, Variable *Src, uint32_t Imm) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 194 | Context.insert<InstMIPS32Addiu>(Dest, Src, Imm); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Srdjan Obucina | 418135a | 2016-06-02 06:47:06 -0700 | [diff] [blame] | 197 | void _cvt_d_l(Variable *Dest, Variable *Src) { |
| 198 | Context.insert<InstMIPS32Cvt_d_l>(Dest, Src); |
| 199 | } |
| 200 | |
| 201 | void _cvt_d_s(Variable *Dest, Variable *Src) { |
| 202 | Context.insert<InstMIPS32Cvt_d_s>(Dest, Src); |
| 203 | } |
| 204 | |
| 205 | void _cvt_d_w(Variable *Dest, Variable *Src) { |
| 206 | Context.insert<InstMIPS32Cvt_d_w>(Dest, Src); |
| 207 | } |
| 208 | |
| 209 | void _cvt_s_d(Variable *Dest, Variable *Src) { |
| 210 | Context.insert<InstMIPS32Cvt_s_d>(Dest, Src); |
| 211 | } |
| 212 | |
| 213 | void _cvt_s_l(Variable *Dest, Variable *Src) { |
| 214 | Context.insert<InstMIPS32Cvt_s_l>(Dest, Src); |
| 215 | } |
| 216 | |
| 217 | void _cvt_s_w(Variable *Dest, Variable *Src) { |
| 218 | Context.insert<InstMIPS32Cvt_s_w>(Dest, Src); |
| 219 | } |
| 220 | |
Srdjan Obucina | ae93eee | 2016-05-18 11:31:15 -0700 | [diff] [blame] | 221 | void _div(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 222 | Context.insert<InstMIPS32Div>(Dest, Src0, Src1); |
| 223 | } |
| 224 | |
Srdjan Obucina | 2f593bb | 2016-05-27 14:40:32 -0700 | [diff] [blame] | 225 | void _div_d(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 226 | Context.insert<InstMIPS32Div_d>(Dest, Src0, Src1); |
| 227 | } |
| 228 | |
| 229 | void _div_s(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 230 | Context.insert<InstMIPS32Div_s>(Dest, Src0, Src1); |
| 231 | } |
| 232 | |
Srdjan Obucina | ae93eee | 2016-05-18 11:31:15 -0700 | [diff] [blame] | 233 | void _divu(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 234 | Context.insert<InstMIPS32Divu>(Dest, Src0, Src1); |
| 235 | } |
| 236 | |
Mohit Bhakkad | d1e9777 | 2016-07-07 05:07:35 -0700 | [diff] [blame] | 237 | void _ldc1(Variable *Value, OperandMIPS32Mem *Mem, RelocOp Reloc = RO_No) { |
| 238 | Context.insert<InstMIPS32Ldc1>(Value, Mem, Reloc); |
Srdjan Obucina | 418135a | 2016-06-02 06:47:06 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Sagar Thakur | 633394c | 2016-06-25 08:34:10 -0700 | [diff] [blame] | 241 | void _lw(Variable *Value, OperandMIPS32Mem *Mem) { |
| 242 | Context.insert<InstMIPS32Lw>(Value, Mem); |
| 243 | } |
| 244 | |
Mohit Bhakkad | d1e9777 | 2016-07-07 05:07:35 -0700 | [diff] [blame] | 245 | void _lwc1(Variable *Value, OperandMIPS32Mem *Mem, RelocOp Reloc = RO_No) { |
| 246 | Context.insert<InstMIPS32Lwc1>(Value, Mem, Reloc); |
Srdjan Obucina | 418135a | 2016-06-02 06:47:06 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Mohit Bhakkad | d1e9777 | 2016-07-07 05:07:35 -0700 | [diff] [blame] | 249 | void _lui(Variable *Dest, Operand *Src, RelocOp Reloc = RO_No) { |
| 250 | Context.insert<InstMIPS32Lui>(Dest, Src, Reloc); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void _mov(Variable *Dest, Operand *Src0) { |
| 254 | assert(Dest != nullptr); |
| 255 | // Variable* Src0_ = llvm::dyn_cast<Variable>(Src0); |
| 256 | if (llvm::isa<ConstantRelocatable>(Src0)) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 257 | Context.insert<InstMIPS32La>(Dest, Src0); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 258 | } else { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 259 | auto *Instr = Context.insert<InstMIPS32Mov>(Dest, Src0); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 260 | if (Instr->isMultiDest()) { |
| 261 | // If Instr is multi-dest, then Dest must be a Variable64On32. We add a |
| 262 | // fake-def for Instr.DestHi here. |
| 263 | assert(llvm::isa<Variable64On32>(Dest)); |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 264 | Context.insert<InstFakeDef>(Instr->getDestHi()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
Srdjan Obucina | 2f593bb | 2016-05-27 14:40:32 -0700 | [diff] [blame] | 269 | void _mov_d(Variable *Dest, Variable *Src) { |
| 270 | Context.insert<InstMIPS32Mov_d>(Dest, Src); |
| 271 | } |
| 272 | |
| 273 | void _mov_s(Variable *Dest, Variable *Src) { |
| 274 | Context.insert<InstMIPS32Mov_s>(Dest, Src); |
| 275 | } |
| 276 | |
| 277 | void _mfc1(Variable *Dest, Variable *Src) { |
| 278 | Context.insert<InstMIPS32Mfc1>(Dest, Src); |
| 279 | } |
| 280 | |
Reed Kotler | a80cdbc | 2016-02-19 22:03:29 -0800 | [diff] [blame] | 281 | void _mfhi(Variable *Dest, Operand *Src) { |
| 282 | Context.insert<InstMIPS32Mfhi>(Dest, Src); |
| 283 | } |
| 284 | |
| 285 | void _mflo(Variable *Dest, Operand *Src) { |
| 286 | Context.insert<InstMIPS32Mflo>(Dest, Src); |
| 287 | } |
| 288 | |
Srdjan Obucina | 2f593bb | 2016-05-27 14:40:32 -0700 | [diff] [blame] | 289 | void _mtc1(Variable *Dest, Variable *Src) { |
| 290 | Context.insert<InstMIPS32Mtc1>(Dest, Src); |
| 291 | } |
| 292 | |
Reed Kotler | a80cdbc | 2016-02-19 22:03:29 -0800 | [diff] [blame] | 293 | void _mthi(Variable *Dest, Operand *Src) { |
| 294 | Context.insert<InstMIPS32Mthi>(Dest, Src); |
| 295 | } |
| 296 | |
| 297 | void _mtlo(Variable *Dest, Operand *Src) { |
| 298 | Context.insert<InstMIPS32Mtlo>(Dest, Src); |
| 299 | } |
| 300 | |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 301 | void _mul(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 302 | Context.insert<InstMIPS32Mul>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Srdjan Obucina | 2f593bb | 2016-05-27 14:40:32 -0700 | [diff] [blame] | 305 | void _mul_d(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 306 | Context.insert<InstMIPS32Mul_d>(Dest, Src0, Src1); |
| 307 | } |
| 308 | |
| 309 | void _mul_s(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 310 | Context.insert<InstMIPS32Mul_s>(Dest, Src0, Src1); |
| 311 | } |
| 312 | |
Reed Kotler | a80cdbc | 2016-02-19 22:03:29 -0800 | [diff] [blame] | 313 | void _mult(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 314 | Context.insert<InstMIPS32Mult>(Dest, Src0, Src1); |
| 315 | } |
| 316 | |
| 317 | void _multu(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 318 | Context.insert<InstMIPS32Multu>(Dest, Src0, Src1); |
| 319 | } |
| 320 | |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 321 | void _or(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 322 | Context.insert<InstMIPS32Or>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 325 | void _ori(Variable *Dest, Variable *Src, uint32_t Imm) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 326 | Context.insert<InstMIPS32Ori>(Dest, Src, Imm); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Srdjan Obucina | 418135a | 2016-06-02 06:47:06 -0700 | [diff] [blame] | 329 | void _sdc1(Variable *Value, OperandMIPS32Mem *Mem) { |
| 330 | Context.insert<InstMIPS32Sdc1>(Value, Mem); |
| 331 | } |
| 332 | |
Sagar Thakur | 38dcb59 | 2016-05-09 11:57:59 -0700 | [diff] [blame] | 333 | void _sll(Variable *Dest, Variable *Src, uint32_t Imm) { |
| 334 | Context.insert<InstMIPS32Sll>(Dest, Src, Imm); |
| 335 | } |
| 336 | |
Srdjan Obucina | c2ee36a | 2016-05-17 13:16:02 -0700 | [diff] [blame] | 337 | void _sllv(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 338 | Context.insert<InstMIPS32Sllv>(Dest, Src0, Src1); |
| 339 | } |
| 340 | |
Sagar Thakur | 1a478b1 | 2016-04-25 08:39:19 -0700 | [diff] [blame] | 341 | void _slt(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 342 | Context.insert<InstMIPS32Slt>(Dest, Src0, Src1); |
| 343 | } |
| 344 | |
| 345 | void _slti(Variable *Dest, Variable *Src, uint32_t Imm) { |
| 346 | Context.insert<InstMIPS32Slti>(Dest, Src, Imm); |
| 347 | } |
| 348 | |
| 349 | void _sltiu(Variable *Dest, Variable *Src, uint32_t Imm) { |
| 350 | Context.insert<InstMIPS32Sltiu>(Dest, Src, Imm); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 351 | } |
| 352 | |
Reed Kotler | 00e3604 | 2016-02-01 20:52:19 -0800 | [diff] [blame] | 353 | void _sltu(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 354 | Context.insert<InstMIPS32Sltu>(Dest, Src0, Src1); |
| 355 | } |
| 356 | |
Sagar Thakur | 38dcb59 | 2016-05-09 11:57:59 -0700 | [diff] [blame] | 357 | void _sra(Variable *Dest, Variable *Src, uint32_t Imm) { |
| 358 | Context.insert<InstMIPS32Sra>(Dest, Src, Imm); |
| 359 | } |
| 360 | |
Srdjan Obucina | c2ee36a | 2016-05-17 13:16:02 -0700 | [diff] [blame] | 361 | void _srav(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 362 | Context.insert<InstMIPS32Srav>(Dest, Src0, Src1); |
| 363 | } |
| 364 | |
| 365 | void _srl(Variable *Dest, Variable *Src, uint32_t Imm) { |
| 366 | Context.insert<InstMIPS32Srl>(Dest, Src, Imm); |
| 367 | } |
| 368 | |
| 369 | void _srlv(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 370 | Context.insert<InstMIPS32Srlv>(Dest, Src0, Src1); |
| 371 | } |
| 372 | |
Sagar Thakur | 1a478b1 | 2016-04-25 08:39:19 -0700 | [diff] [blame] | 373 | void _sub(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 374 | Context.insert<InstMIPS32Sub>(Dest, Src0, Src1); |
| 375 | } |
| 376 | |
Srdjan Obucina | 2f593bb | 2016-05-27 14:40:32 -0700 | [diff] [blame] | 377 | void _sub_d(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 378 | Context.insert<InstMIPS32Sub_d>(Dest, Src0, Src1); |
| 379 | } |
| 380 | |
| 381 | void _sub_s(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 382 | Context.insert<InstMIPS32Sub_s>(Dest, Src0, Src1); |
| 383 | } |
| 384 | |
Reed Kotler | 00e3604 | 2016-02-01 20:52:19 -0800 | [diff] [blame] | 385 | void _subu(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 386 | Context.insert<InstMIPS32Subu>(Dest, Src0, Src1); |
| 387 | } |
| 388 | |
Mohit Bhakkad | f3bc5cf | 2016-05-31 11:19:03 -0700 | [diff] [blame] | 389 | void _sw(Variable *Value, OperandMIPS32Mem *Mem) { |
| 390 | Context.insert<InstMIPS32Sw>(Value, Mem); |
| 391 | } |
| 392 | |
Srdjan Obucina | 418135a | 2016-06-02 06:47:06 -0700 | [diff] [blame] | 393 | void _swc1(Variable *Value, OperandMIPS32Mem *Mem) { |
| 394 | Context.insert<InstMIPS32Swc1>(Value, Mem); |
| 395 | } |
| 396 | |
| 397 | void _trunc_l_d(Variable *Dest, Variable *Src) { |
| 398 | Context.insert<InstMIPS32Trunc_l_d>(Dest, Src); |
| 399 | } |
| 400 | |
| 401 | void _trunc_l_s(Variable *Dest, Variable *Src) { |
| 402 | Context.insert<InstMIPS32Trunc_l_s>(Dest, Src); |
| 403 | } |
| 404 | |
| 405 | void _trunc_w_d(Variable *Dest, Variable *Src) { |
| 406 | Context.insert<InstMIPS32Trunc_w_d>(Dest, Src); |
| 407 | } |
| 408 | |
| 409 | void _trunc_w_s(Variable *Dest, Variable *Src) { |
| 410 | Context.insert<InstMIPS32Trunc_w_s>(Dest, Src); |
| 411 | } |
| 412 | |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 413 | void _xor(Variable *Dest, Variable *Src0, Variable *Src1) { |
John Porto | 1d937a8 | 2015-12-17 06:19:34 -0800 | [diff] [blame] | 414 | Context.insert<InstMIPS32Xor>(Dest, Src0, Src1); |
Reed Kotler | 37af5b0 | 2015-11-05 17:07:19 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Sagar Thakur | 1a478b1 | 2016-04-25 08:39:19 -0700 | [diff] [blame] | 417 | void _xori(Variable *Dest, Variable *Src, uint32_t Imm) { |
| 418 | Context.insert<InstMIPS32Xori>(Dest, Src, Imm); |
| 419 | } |
| 420 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 421 | void lowerArguments() override; |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 422 | |
| 423 | /// Operand legalization helpers. To deal with address mode constraints, |
| 424 | /// the helpers will create a new Operand and emit instructions that |
| 425 | /// guarantee that the Operand kind is one of those indicated by the |
| 426 | /// LegalMask (a bitmask of allowed kinds). If the input Operand is known |
| 427 | /// to already meet the constraints, it may be simply returned as the result, |
| 428 | /// without creating any new instructions or operands. |
| 429 | enum OperandLegalization { |
| 430 | Legal_None = 0, |
| 431 | Legal_Reg = 1 << 0, // physical register, not stack location |
| 432 | Legal_Imm = 1 << 1, |
| 433 | Legal_Mem = 1 << 2, |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame] | 434 | Legal_Default = ~Legal_None |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 435 | }; |
| 436 | typedef uint32_t LegalMask; |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame] | 437 | Operand *legalize(Operand *From, LegalMask Allowed = Legal_Default, |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 438 | RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 439 | |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 440 | Variable *legalizeToVar(Operand *From, RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 441 | |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 442 | Variable *legalizeToReg(Operand *From, RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 443 | |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 444 | Variable *makeReg(Type Ty, RegNumT RegNum = RegNumT()); |
Reed Kotler | 953568f | 2016-02-17 05:37:01 -0800 | [diff] [blame] | 445 | |
Sagar Thakur | 1a478b1 | 2016-04-25 08:39:19 -0700 | [diff] [blame] | 446 | Variable *getZero() { |
| 447 | return getPhysicalRegister(RegMIPS32::Reg_ZERO, IceType_i32); |
| 448 | } |
| 449 | |
Reed Kotler | 953568f | 2016-02-17 05:37:01 -0800 | [diff] [blame] | 450 | Variable *I32Reg(RegNumT RegNum = RegNumT()) { |
| 451 | return makeReg(IceType_i32, RegNum); |
| 452 | } |
| 453 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 454 | static Type stackSlotType(); |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 455 | Variable *copyToReg(Operand *Src, RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 456 | |
Sagar Thakur | 1afb483 | 2016-06-16 15:30:24 -0700 | [diff] [blame] | 457 | void unsetIfNonLeafFunc(); |
| 458 | |
Sagar Thakur | a49fce0 | 2016-06-13 05:55:00 -0700 | [diff] [blame] | 459 | // Iterates over the CFG and determines the maximum outgoing stack arguments |
| 460 | // bytes. This information is later used during addProlog() to pre-allocate |
| 461 | // the outargs area |
| 462 | void findMaxStackOutArgsSize(); |
| 463 | |
Sagar Thakur | 5674c91 | 2016-07-14 14:50:37 -0700 | [diff] [blame^] | 464 | void postLowerLegalization(); |
| 465 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 466 | void addProlog(CfgNode *Node) override; |
| 467 | void addEpilog(CfgNode *Node) override; |
| 468 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 469 | // Ensure that a 64-bit Variable has been split into 2 32-bit |
| 470 | // Variables, creating them if necessary. This is needed for all |
| 471 | // I64 operations. |
| 472 | void split64(Variable *Var); |
| 473 | Operand *loOperand(Operand *Operand); |
| 474 | Operand *hiOperand(Operand *Operand); |
| 475 | |
Sagar Thakur | a49fce0 | 2016-06-13 05:55:00 -0700 | [diff] [blame] | 476 | void finishArgumentLowering(Variable *Arg, Variable *FramePtr, |
| 477 | size_t BasicFrameOffset, size_t *InArgsSizeBytes); |
| 478 | |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 479 | Operand *legalizeUndef(Operand *From, RegNumT RegNum = RegNumT()); |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 480 | |
Mohit Bhakkad | f90118a | 2016-06-13 00:28:13 -0700 | [diff] [blame] | 481 | /// Helper class that understands the Calling Convention and register |
| 482 | /// assignments as per MIPS O32 abi. |
| 483 | class CallingConv { |
| 484 | CallingConv(const CallingConv &) = delete; |
| 485 | CallingConv &operator=(const CallingConv &) = delete; |
| 486 | |
| 487 | public: |
| 488 | CallingConv(); |
| 489 | ~CallingConv() = default; |
| 490 | |
| 491 | /// argInReg returns true if there is a Register available for the requested |
| 492 | /// type, and false otherwise. If it returns true, Reg is set to the |
| 493 | /// appropriate register number. Note that, when Ty == IceType_i64, Reg will |
| 494 | /// be an I64 register pair. |
| 495 | bool argInReg(Type Ty, uint32_t ArgNo, RegNumT *Reg); |
| 496 | |
| 497 | private: |
| 498 | // argInGPR is used to find if any GPR register is available for argument of |
| 499 | // type Ty |
| 500 | bool argInGPR(Type Ty, RegNumT *Reg); |
| 501 | /// argInVFP is to floating-point/vector types what argInGPR is for integer |
| 502 | /// types. |
| 503 | bool argInVFP(Type Ty, RegNumT *Reg); |
| 504 | inline void discardNextGPRAndItsAliases(CfgVector<RegNumT> *Regs); |
Mohit Bhakkad | bbb5fa7 | 2016-06-29 06:51:08 -0700 | [diff] [blame] | 505 | inline void alignGPR(CfgVector<RegNumT> *Regs); |
Mohit Bhakkad | f90118a | 2016-06-13 00:28:13 -0700 | [diff] [blame] | 506 | void discardUnavailableGPRsAndTheirAliases(CfgVector<RegNumT> *Regs); |
| 507 | SmallBitVector GPRegsUsed; |
| 508 | CfgVector<RegNumT> GPRArgs; |
| 509 | CfgVector<RegNumT> I64Args; |
| 510 | |
| 511 | void discardUnavailableVFPRegsAndTheirAliases(CfgVector<RegNumT> *Regs); |
| 512 | SmallBitVector VFPRegsUsed; |
| 513 | CfgVector<RegNumT> FP32Args; |
| 514 | CfgVector<RegNumT> FP64Args; |
| 515 | // UseFPRegs is a flag indicating if FP registers can be used |
| 516 | bool UseFPRegs = false; |
| 517 | }; |
| 518 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 519 | protected: |
| 520 | explicit TargetMIPS32(Cfg *Func); |
| 521 | |
| 522 | void postLower() override; |
| 523 | |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 524 | void lowerAlloca(const InstAlloca *Instr) override; |
| 525 | void lowerArithmetic(const InstArithmetic *Instr) override; |
| 526 | void lowerInt64Arithmetic(const InstArithmetic *Instr, Variable *Dest, |
Reed Kotler | 00e3604 | 2016-02-01 20:52:19 -0800 | [diff] [blame] | 527 | Operand *Src0, Operand *Src1); |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 528 | void lowerAssign(const InstAssign *Instr) override; |
| 529 | void lowerBr(const InstBr *Instr) override; |
Eric Holk | 67c7c41 | 2016-04-15 13:05:37 -0700 | [diff] [blame] | 530 | void lowerBreakpoint(const InstBreakpoint *Instr) override; |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 531 | void lowerCall(const InstCall *Instr) override; |
| 532 | void lowerCast(const InstCast *Instr) override; |
| 533 | void lowerExtractElement(const InstExtractElement *Instr) override; |
| 534 | void lowerFcmp(const InstFcmp *Instr) override; |
| 535 | void lowerIcmp(const InstIcmp *Instr) override; |
Sagar Thakur | 1a478b1 | 2016-04-25 08:39:19 -0700 | [diff] [blame] | 536 | void lower64Icmp(const InstIcmp *Instr); |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 537 | void lowerIntrinsicCall(const InstIntrinsicCall *Instr) override; |
| 538 | void lowerInsertElement(const InstInsertElement *Instr) override; |
| 539 | void lowerLoad(const InstLoad *Instr) override; |
| 540 | void lowerPhi(const InstPhi *Instr) override; |
| 541 | void lowerRet(const InstRet *Instr) override; |
| 542 | void lowerSelect(const InstSelect *Instr) override; |
John Porto | a47c11c | 2016-04-21 05:53:42 -0700 | [diff] [blame] | 543 | void lowerShuffleVector(const InstShuffleVector *Instr) override; |
Reed Kotler | 04bca5a | 2016-02-03 14:40:47 -0800 | [diff] [blame] | 544 | void lowerStore(const InstStore *Instr) override; |
| 545 | void lowerSwitch(const InstSwitch *Instr) override; |
| 546 | void lowerUnreachable(const InstUnreachable *Instr) override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 547 | void prelowerPhis() override; |
John Porto | f419854 | 2015-11-20 14:17:23 -0800 | [diff] [blame] | 548 | uint32_t getCallStackArgumentsSizeBytes(const InstCall *Instr) override { |
| 549 | (void)Instr; |
| 550 | return 0; |
| 551 | } |
John Porto | 5e0a8a7 | 2015-11-20 13:50:36 -0800 | [diff] [blame] | 552 | void genTargetHelperCallFor(Inst *Instr) override { (void)Instr; } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 553 | void doAddressOptLoad() override; |
| 554 | void doAddressOptStore() override; |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 555 | void randomlyInsertNop(float Probability, |
| 556 | RandomNumberGenerator &RNG) override; |
| 557 | void |
Jim Stichnoth | 8aa3966 | 2016-02-10 11:20:30 -0800 | [diff] [blame] | 558 | makeRandomRegisterPermutation(llvm::SmallVectorImpl<RegNumT> &Permutation, |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 559 | const SmallBitVector &ExcludeRegisters, |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 560 | uint64_t Salt) const override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 561 | |
Mohit Bhakkad | f3bc5cf | 2016-05-31 11:19:03 -0700 | [diff] [blame] | 562 | OperandMIPS32Mem *formMemoryOperand(Operand *Ptr, Type Ty); |
| 563 | |
Sagar Thakur | 5674c91 | 2016-07-14 14:50:37 -0700 | [diff] [blame^] | 564 | class PostLoweringLegalizer { |
| 565 | PostLoweringLegalizer() = delete; |
| 566 | PostLoweringLegalizer(const PostLoweringLegalizer &) = delete; |
| 567 | PostLoweringLegalizer &operator=(const PostLoweringLegalizer &) = delete; |
| 568 | |
| 569 | public: |
| 570 | explicit PostLoweringLegalizer(TargetMIPS32 *Target) |
| 571 | : Target(Target), StackOrFrameReg(Target->getPhysicalRegister( |
| 572 | Target->getFrameOrStackReg())) {} |
| 573 | |
| 574 | /// Legalizes Mov if its Source (or Destination) is a spilled Variable, or |
| 575 | /// if its Source is a Rematerializable variable (this form is used in lieu |
| 576 | /// of lea, which is not available in MIPS.) |
| 577 | /// |
| 578 | /// Moves to memory become store instructions, and moves from memory, loads. |
| 579 | void legalizeMov(InstMIPS32Mov *Mov); |
| 580 | |
| 581 | private: |
| 582 | /// Creates a new Base register centered around [Base, +/- Offset]. |
| 583 | Variable *newBaseRegister(Variable *Base, int32_t Offset, |
| 584 | RegNumT ScratchRegNum); |
| 585 | |
| 586 | TargetMIPS32 *const Target; |
| 587 | Variable *const StackOrFrameReg; |
| 588 | }; |
| 589 | |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 590 | bool UsesFramePointer = false; |
| 591 | bool NeedsStackAlignment = false; |
Sagar Thakur | a49fce0 | 2016-06-13 05:55:00 -0700 | [diff] [blame] | 592 | bool MaybeLeafFunc = true; |
| 593 | bool PrologEmitsFixedAllocas = false; |
Sagar Thakur | c930d59 | 2016-07-12 04:06:44 -0700 | [diff] [blame] | 594 | bool VariableAllocaUsed = false; |
Sagar Thakur | a49fce0 | 2016-06-13 05:55:00 -0700 | [diff] [blame] | 595 | uint32_t MaxOutArgsSizeBytes = 0; |
Sagar Thakur | 633394c | 2016-06-25 08:34:10 -0700 | [diff] [blame] | 596 | uint32_t TotalStackSizeBytes = 0; |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 597 | static SmallBitVector TypeToRegisterSet[RCMIPS32_NUM]; |
| 598 | static SmallBitVector TypeToRegisterSetUnfiltered[RCMIPS32_NUM]; |
| 599 | static SmallBitVector RegisterAliases[RegMIPS32::Reg_NUM]; |
| 600 | SmallBitVector RegsUsed; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 601 | VarList PhysicalRegisters[IceType_NUM]; |
Sagar Thakur | a49fce0 | 2016-06-13 05:55:00 -0700 | [diff] [blame] | 602 | VarList PreservedGPRs; |
Sagar Thakur | 38dcb59 | 2016-05-09 11:57:59 -0700 | [diff] [blame] | 603 | static constexpr uint32_t CHAR_BITS = 8; |
| 604 | static constexpr uint32_t INT32_BITS = 32; |
Sagar Thakur | a49fce0 | 2016-06-13 05:55:00 -0700 | [diff] [blame] | 605 | size_t SpillAreaSizeBytes = 0; |
Sagar Thakur | 1afb483 | 2016-06-16 15:30:24 -0700 | [diff] [blame] | 606 | size_t FixedAllocaSizeBytes = 0; |
| 607 | size_t FixedAllocaAlignBytes = 0; |
Sagar Thakur | 633394c | 2016-06-25 08:34:10 -0700 | [diff] [blame] | 608 | size_t PreservedRegsSizeBytes = 0; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 609 | |
| 610 | private: |
John Porto | 53611e2 | 2015-12-30 07:30:10 -0800 | [diff] [blame] | 611 | ENABLE_MAKE_UNIQUE; |
Sagar Thakur | 5cce761 | 2016-05-24 06:25:50 -0700 | [diff] [blame] | 612 | |
| 613 | class ComputationTracker { |
| 614 | public: |
| 615 | ComputationTracker() = default; |
| 616 | ~ComputationTracker() = default; |
| 617 | |
| 618 | void forgetProducers() { KnownComputations.clear(); } |
| 619 | void recordProducers(CfgNode *Node); |
| 620 | |
| 621 | const Inst *getProducerOf(const Operand *Opnd) const { |
| 622 | auto *Var = llvm::dyn_cast<Variable>(Opnd); |
| 623 | if (Var == nullptr) { |
| 624 | return nullptr; |
| 625 | } |
| 626 | |
| 627 | auto Iter = KnownComputations.find(Var->getIndex()); |
| 628 | if (Iter == KnownComputations.end()) { |
| 629 | return nullptr; |
| 630 | } |
| 631 | |
| 632 | return Iter->second.Instr; |
| 633 | } |
| 634 | |
| 635 | void dump(const Cfg *Func) const { |
| 636 | if (!BuildDefs::dump() || !Func->isVerbose(IceV_Folding)) |
| 637 | return; |
| 638 | OstreamLocker L(Func->getContext()); |
| 639 | Ostream &Str = Func->getContext()->getStrDump(); |
| 640 | Str << "foldable producer:\n"; |
| 641 | for (const auto &Computation : KnownComputations) { |
| 642 | Str << " "; |
| 643 | Computation.second.Instr->dump(Func); |
| 644 | Str << "\n"; |
| 645 | } |
| 646 | Str << "\n"; |
| 647 | } |
| 648 | |
| 649 | private: |
| 650 | class ComputationEntry { |
| 651 | public: |
| 652 | ComputationEntry(Inst *I, Type Ty) : Instr(I), ComputationType(Ty) {} |
| 653 | Inst *const Instr; |
| 654 | // Boolean folding is disabled for variables whose live range is multi |
| 655 | // block. We conservatively initialize IsLiveOut to true, and set it to |
| 656 | // false once we find the end of the live range for the variable defined |
| 657 | // by this instruction. If liveness analysis is not performed (e.g., in |
| 658 | // Om1 mode) IsLiveOut will never be set to false, and folding will be |
| 659 | // disabled. |
| 660 | bool IsLiveOut = true; |
| 661 | int32_t NumUses = 0; |
| 662 | Type ComputationType; |
| 663 | }; |
| 664 | |
| 665 | // ComputationMap maps a Variable number to a payload identifying which |
| 666 | // instruction defined it. |
| 667 | using ComputationMap = CfgUnorderedMap<SizeT, ComputationEntry>; |
| 668 | ComputationMap KnownComputations; |
| 669 | }; |
| 670 | |
| 671 | ComputationTracker Computations; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 672 | }; |
| 673 | |
John Porto | 0f86d03 | 2015-06-15 07:44:27 -0700 | [diff] [blame] | 674 | class TargetDataMIPS32 final : public TargetDataLowering { |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 675 | TargetDataMIPS32() = delete; |
| 676 | TargetDataMIPS32(const TargetDataMIPS32 &) = delete; |
| 677 | TargetDataMIPS32 &operator=(const TargetDataMIPS32 &) = delete; |
| 678 | |
| 679 | public: |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 680 | static std::unique_ptr<TargetDataLowering> create(GlobalContext *Ctx) { |
| 681 | return std::unique_ptr<TargetDataLowering>(new TargetDataMIPS32(Ctx)); |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 682 | } |
| 683 | |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 684 | void lowerGlobals(const VariableDeclarationList &Vars, |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 685 | const std::string &SectionSuffix) override; |
John Porto | 0f86d03 | 2015-06-15 07:44:27 -0700 | [diff] [blame] | 686 | void lowerConstants() override; |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 687 | void lowerJumpTables() override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 688 | |
| 689 | protected: |
| 690 | explicit TargetDataMIPS32(GlobalContext *Ctx); |
| 691 | |
| 692 | private: |
Jim Stichnoth | e587d94 | 2015-06-22 15:49:04 -0700 | [diff] [blame] | 693 | ~TargetDataMIPS32() override = default; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 694 | template <typename T> static void emitConstantPool(GlobalContext *Ctx); |
| 695 | }; |
| 696 | |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 697 | class TargetHeaderMIPS32 final : public TargetHeaderLowering { |
| 698 | TargetHeaderMIPS32() = delete; |
| 699 | TargetHeaderMIPS32(const TargetHeaderMIPS32 &) = delete; |
| 700 | TargetHeaderMIPS32 &operator=(const TargetHeaderMIPS32 &) = delete; |
| 701 | |
| 702 | public: |
| 703 | static std::unique_ptr<TargetHeaderLowering> create(GlobalContext *Ctx) { |
| 704 | return std::unique_ptr<TargetHeaderLowering>(new TargetHeaderMIPS32(Ctx)); |
| 705 | } |
| 706 | |
Jim Stichnoth | ac8da5c | 2015-10-21 06:57:46 -0700 | [diff] [blame] | 707 | void lower() override; |
| 708 | |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 709 | protected: |
| 710 | explicit TargetHeaderMIPS32(GlobalContext *Ctx); |
| 711 | |
| 712 | private: |
| 713 | ~TargetHeaderMIPS32() = default; |
| 714 | }; |
| 715 | |
John Porto | 4a56686 | 2016-01-04 09:33:41 -0800 | [diff] [blame] | 716 | } // end of namespace MIPS32 |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 717 | } // end of namespace Ice |
| 718 | |
| 719 | #endif // SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H |