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 |
| 11 | /// This file declares the TargetLoweringMIPS32 class, which implements the |
| 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 | |
| 19 | #include "IceDefs.h" |
| 20 | #include "IceInstMIPS32.h" |
| 21 | #include "IceRegistersMIPS32.h" |
| 22 | #include "IceTargetLowering.h" |
| 23 | |
| 24 | namespace Ice { |
| 25 | |
| 26 | class TargetMIPS32 : public TargetLowering { |
| 27 | TargetMIPS32() = delete; |
| 28 | TargetMIPS32(const TargetMIPS32 &) = delete; |
| 29 | TargetMIPS32 &operator=(const TargetMIPS32 &) = delete; |
| 30 | |
| 31 | public: |
| 32 | // TODO(jvoung): return a unique_ptr. |
| 33 | static TargetMIPS32 *create(Cfg *Func) { return new TargetMIPS32(Func); } |
| 34 | |
| 35 | void translateOm1() override; |
| 36 | void translateO2() override; |
| 37 | bool doBranchOpt(Inst *I, const CfgNode *NextNode) override; |
| 38 | |
| 39 | SizeT getNumRegisters() const override { return RegMIPS32::Reg_NUM; } |
| 40 | Variable *getPhysicalRegister(SizeT RegNum, Type Ty = IceType_void) override; |
| 41 | IceString getRegName(SizeT RegNum, Type Ty) const override; |
| 42 | llvm::SmallBitVector getRegisterSet(RegSetMask Include, |
| 43 | RegSetMask Exclude) const override; |
| 44 | const llvm::SmallBitVector &getRegisterSetForType(Type Ty) const override { |
| 45 | return TypeToRegisterSet[Ty]; |
| 46 | } |
John Porto | bb0a5fe | 2015-09-04 11:23:41 -0700 | [diff] [blame] | 47 | const llvm::SmallBitVector &getAliasesForRegister(SizeT Reg) const override { |
| 48 | return RegisterAliases[Reg]; |
| 49 | } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 50 | bool hasFramePointer() const override { return UsesFramePointer; } |
| 51 | SizeT getFrameOrStackReg() const override { |
| 52 | return UsesFramePointer ? RegMIPS32::Reg_FP : RegMIPS32::Reg_SP; |
| 53 | } |
| 54 | size_t typeWidthInBytesOnStack(Type Ty) const override { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 55 | // Round up to the next multiple of 4 bytes. In particular, i1, i8, and i16 |
| 56 | // are rounded up to 4 bytes. |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 57 | return (typeWidthInBytes(Ty) + 3) & ~3; |
| 58 | } |
Andrew Scull | 87f80c1 | 2015-07-20 10:19:16 -0700 | [diff] [blame] | 59 | |
| 60 | // TODO(ascull): what is the best size of MIPS? |
| 61 | SizeT getMinJumpTableSize() const override { return 3; } |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 62 | void emitJumpTable(const Cfg *Func, |
| 63 | const InstJumpTable *JumpTable) const override; |
Andrew Scull | 87f80c1 | 2015-07-20 10:19:16 -0700 | [diff] [blame] | 64 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 65 | void emitVariable(const Variable *Var) const override; |
| 66 | |
| 67 | const char *getConstantPrefix() const final { return ""; } |
| 68 | void emit(const ConstantUndef *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 69 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 70 | llvm::report_fatal_error("Not yet implemented"); |
| 71 | } |
| 72 | void emit(const ConstantInteger32 *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 73 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 74 | llvm::report_fatal_error("Not yet implemented"); |
| 75 | } |
| 76 | void emit(const ConstantInteger64 *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 77 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 78 | llvm::report_fatal_error("Not yet implemented"); |
| 79 | } |
| 80 | void emit(const ConstantFloat *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 81 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 82 | llvm::report_fatal_error("Not yet implemented"); |
| 83 | } |
| 84 | void emit(const ConstantDouble *C) const final { |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 85 | (void)C; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 86 | llvm::report_fatal_error("Not yet implemented"); |
| 87 | } |
Reed Kotler | d00d48d | 2015-07-08 09:49:07 -0700 | [diff] [blame] | 88 | void _ret(Variable *RA, Variable *Src0 = nullptr) { |
| 89 | Context.insert(InstMIPS32Ret::create(Func, RA, Src0)); |
| 90 | } |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 91 | |
| 92 | void lowerArguments() override; |
| 93 | void addProlog(CfgNode *Node) override; |
| 94 | void addEpilog(CfgNode *Node) override; |
| 95 | |
| 96 | protected: |
| 97 | explicit TargetMIPS32(Cfg *Func); |
| 98 | |
| 99 | void postLower() override; |
| 100 | |
| 101 | void lowerAlloca(const InstAlloca *Inst) override; |
| 102 | void lowerArithmetic(const InstArithmetic *Inst) override; |
| 103 | void lowerAssign(const InstAssign *Inst) override; |
| 104 | void lowerBr(const InstBr *Inst) override; |
| 105 | void lowerCall(const InstCall *Inst) override; |
| 106 | void lowerCast(const InstCast *Inst) override; |
| 107 | void lowerExtractElement(const InstExtractElement *Inst) override; |
| 108 | void lowerFcmp(const InstFcmp *Inst) override; |
| 109 | void lowerIcmp(const InstIcmp *Inst) override; |
| 110 | void lowerIntrinsicCall(const InstIntrinsicCall *Inst) override; |
| 111 | void lowerInsertElement(const InstInsertElement *Inst) override; |
| 112 | void lowerLoad(const InstLoad *Inst) override; |
| 113 | void lowerPhi(const InstPhi *Inst) override; |
| 114 | void lowerRet(const InstRet *Inst) override; |
| 115 | void lowerSelect(const InstSelect *Inst) override; |
| 116 | void lowerStore(const InstStore *Inst) override; |
| 117 | void lowerSwitch(const InstSwitch *Inst) override; |
| 118 | void lowerUnreachable(const InstUnreachable *Inst) override; |
| 119 | void prelowerPhis() override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 120 | void doAddressOptLoad() override; |
| 121 | void doAddressOptStore() override; |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 122 | void randomlyInsertNop(float Probability, |
| 123 | RandomNumberGenerator &RNG) override; |
| 124 | void |
| 125 | makeRandomRegisterPermutation(llvm::SmallVectorImpl<int32_t> &Permutation, |
| 126 | const llvm::SmallBitVector &ExcludeRegisters, |
| 127 | uint64_t Salt) const override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 128 | |
| 129 | static Type stackSlotType(); |
| 130 | |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 131 | bool UsesFramePointer = false; |
| 132 | bool NeedsStackAlignment = false; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 133 | llvm::SmallBitVector TypeToRegisterSet[IceType_NUM]; |
John Porto | bb0a5fe | 2015-09-04 11:23:41 -0700 | [diff] [blame] | 134 | llvm::SmallBitVector RegisterAliases[RegMIPS32::Reg_NUM]; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 135 | llvm::SmallBitVector ScratchRegs; |
| 136 | llvm::SmallBitVector RegsUsed; |
| 137 | VarList PhysicalRegisters[IceType_NUM]; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 138 | |
| 139 | private: |
Jim Stichnoth | e587d94 | 2015-06-22 15:49:04 -0700 | [diff] [blame] | 140 | ~TargetMIPS32() override = default; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
John Porto | 0f86d03 | 2015-06-15 07:44:27 -0700 | [diff] [blame] | 143 | class TargetDataMIPS32 final : public TargetDataLowering { |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 144 | TargetDataMIPS32() = delete; |
| 145 | TargetDataMIPS32(const TargetDataMIPS32 &) = delete; |
| 146 | TargetDataMIPS32 &operator=(const TargetDataMIPS32 &) = delete; |
| 147 | |
| 148 | public: |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 149 | static std::unique_ptr<TargetDataLowering> create(GlobalContext *Ctx) { |
| 150 | return std::unique_ptr<TargetDataLowering>(new TargetDataMIPS32(Ctx)); |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 151 | } |
| 152 | |
John Porto | 8b1a705 | 2015-06-17 13:20:08 -0700 | [diff] [blame] | 153 | void lowerGlobals(const VariableDeclarationList &Vars, |
| 154 | const IceString &SectionSuffix) override; |
John Porto | 0f86d03 | 2015-06-15 07:44:27 -0700 | [diff] [blame] | 155 | void lowerConstants() override; |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 156 | void lowerJumpTables() override; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 157 | |
| 158 | protected: |
| 159 | explicit TargetDataMIPS32(GlobalContext *Ctx); |
| 160 | |
| 161 | private: |
Jim Stichnoth | e587d94 | 2015-06-22 15:49:04 -0700 | [diff] [blame] | 162 | ~TargetDataMIPS32() override = default; |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 163 | template <typename T> static void emitConstantPool(GlobalContext *Ctx); |
| 164 | }; |
| 165 | |
Jan Voung | fb79284 | 2015-06-11 15:27:50 -0700 | [diff] [blame] | 166 | class TargetHeaderMIPS32 final : public TargetHeaderLowering { |
| 167 | TargetHeaderMIPS32() = delete; |
| 168 | TargetHeaderMIPS32(const TargetHeaderMIPS32 &) = delete; |
| 169 | TargetHeaderMIPS32 &operator=(const TargetHeaderMIPS32 &) = delete; |
| 170 | |
| 171 | public: |
| 172 | static std::unique_ptr<TargetHeaderLowering> create(GlobalContext *Ctx) { |
| 173 | return std::unique_ptr<TargetHeaderLowering>(new TargetHeaderMIPS32(Ctx)); |
| 174 | } |
| 175 | |
| 176 | protected: |
| 177 | explicit TargetHeaderMIPS32(GlobalContext *Ctx); |
| 178 | |
| 179 | private: |
| 180 | ~TargetHeaderMIPS32() = default; |
| 181 | }; |
| 182 | |
Jim Stichnoth | 6da4cef | 2015-06-11 13:26:33 -0700 | [diff] [blame] | 183 | } // end of namespace Ice |
| 184 | |
| 185 | #endif // SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H |