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