blob: 1ae0b28ff7595bd63e1ebfa11bff381093e238bd [file] [log] [blame]
Jim Stichnoth6da4cef2015-06-11 13:26:33 -07001//===- 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 Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
11/// This file declares the TargetLoweringMIPS32 class, which implements the
12/// TargetLowering interface for the MIPS 32-bit architecture.
13///
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070014//===----------------------------------------------------------------------===//
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
24namespace Ice {
25
26class TargetMIPS32 : public TargetLowering {
27 TargetMIPS32() = delete;
28 TargetMIPS32(const TargetMIPS32 &) = delete;
29 TargetMIPS32 &operator=(const TargetMIPS32 &) = delete;
30
31public:
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 Portobb0a5fe2015-09-04 11:23:41 -070047 const llvm::SmallBitVector &getAliasesForRegister(SizeT Reg) const override {
48 return RegisterAliases[Reg];
49 }
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070050 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 Scull57e12682015-09-16 11:30:19 -070055 // Round up to the next multiple of 4 bytes. In particular, i1, i8, and i16
56 // are rounded up to 4 bytes.
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070057 return (typeWidthInBytes(Ty) + 3) & ~3;
58 }
Andrew Scull87f80c12015-07-20 10:19:16 -070059
60 // TODO(ascull): what is the best size of MIPS?
61 SizeT getMinJumpTableSize() const override { return 3; }
Andrew Scull86df4e92015-07-30 13:54:44 -070062 void emitJumpTable(const Cfg *Func,
63 const InstJumpTable *JumpTable) const override;
Andrew Scull87f80c12015-07-20 10:19:16 -070064
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070065 void emitVariable(const Variable *Var) const override;
66
67 const char *getConstantPrefix() const final { return ""; }
68 void emit(const ConstantUndef *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070069 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070070 llvm::report_fatal_error("Not yet implemented");
71 }
72 void emit(const ConstantInteger32 *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070073 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070074 llvm::report_fatal_error("Not yet implemented");
75 }
76 void emit(const ConstantInteger64 *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070077 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070078 llvm::report_fatal_error("Not yet implemented");
79 }
80 void emit(const ConstantFloat *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070081 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070082 llvm::report_fatal_error("Not yet implemented");
83 }
84 void emit(const ConstantDouble *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070085 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070086 llvm::report_fatal_error("Not yet implemented");
87 }
Reed Kotlerd00d48d2015-07-08 09:49:07 -070088 void _ret(Variable *RA, Variable *Src0 = nullptr) {
89 Context.insert(InstMIPS32Ret::create(Func, RA, Src0));
90 }
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070091
92 void lowerArguments() override;
93 void addProlog(CfgNode *Node) override;
94 void addEpilog(CfgNode *Node) override;
95
96protected:
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 Stichnoth6da4cef2015-06-11 13:26:33 -0700120 void doAddressOptLoad() override;
121 void doAddressOptStore() override;
Qining Luaee5fa82015-08-20 14:59:03 -0700122 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 Stichnoth6da4cef2015-06-11 13:26:33 -0700128
129 static Type stackSlotType();
130
Jim Stichnotheafb56c2015-06-22 10:35:22 -0700131 bool UsesFramePointer = false;
132 bool NeedsStackAlignment = false;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700133 llvm::SmallBitVector TypeToRegisterSet[IceType_NUM];
John Portobb0a5fe2015-09-04 11:23:41 -0700134 llvm::SmallBitVector RegisterAliases[RegMIPS32::Reg_NUM];
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700135 llvm::SmallBitVector ScratchRegs;
136 llvm::SmallBitVector RegsUsed;
137 VarList PhysicalRegisters[IceType_NUM];
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700138
139private:
Jim Stichnothe587d942015-06-22 15:49:04 -0700140 ~TargetMIPS32() override = default;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700141};
142
John Porto0f86d032015-06-15 07:44:27 -0700143class TargetDataMIPS32 final : public TargetDataLowering {
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700144 TargetDataMIPS32() = delete;
145 TargetDataMIPS32(const TargetDataMIPS32 &) = delete;
146 TargetDataMIPS32 &operator=(const TargetDataMIPS32 &) = delete;
147
148public:
Jan Voungfb792842015-06-11 15:27:50 -0700149 static std::unique_ptr<TargetDataLowering> create(GlobalContext *Ctx) {
150 return std::unique_ptr<TargetDataLowering>(new TargetDataMIPS32(Ctx));
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700151 }
152
John Porto8b1a7052015-06-17 13:20:08 -0700153 void lowerGlobals(const VariableDeclarationList &Vars,
154 const IceString &SectionSuffix) override;
John Porto0f86d032015-06-15 07:44:27 -0700155 void lowerConstants() override;
Andrew Scull86df4e92015-07-30 13:54:44 -0700156 void lowerJumpTables() override;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700157
158protected:
159 explicit TargetDataMIPS32(GlobalContext *Ctx);
160
161private:
Jim Stichnothe587d942015-06-22 15:49:04 -0700162 ~TargetDataMIPS32() override = default;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700163 template <typename T> static void emitConstantPool(GlobalContext *Ctx);
164};
165
Jan Voungfb792842015-06-11 15:27:50 -0700166class TargetHeaderMIPS32 final : public TargetHeaderLowering {
167 TargetHeaderMIPS32() = delete;
168 TargetHeaderMIPS32(const TargetHeaderMIPS32 &) = delete;
169 TargetHeaderMIPS32 &operator=(const TargetHeaderMIPS32 &) = delete;
170
171public:
172 static std::unique_ptr<TargetHeaderLowering> create(GlobalContext *Ctx) {
173 return std::unique_ptr<TargetHeaderLowering>(new TargetHeaderMIPS32(Ctx));
174 }
175
176protected:
177 explicit TargetHeaderMIPS32(GlobalContext *Ctx);
178
179private:
180 ~TargetHeaderMIPS32() = default;
181};
182
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700183} // end of namespace Ice
184
185#endif // SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H