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