blob: e63d7388de3209b87917050ca78976c78cff1c8f [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 }
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 Scull87f80c12015-07-20 10:19:16 -070056
57 // TODO(ascull): what is the best size of MIPS?
58 SizeT getMinJumpTableSize() const override { return 3; }
59
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070060 void emitVariable(const Variable *Var) const override;
61
62 const char *getConstantPrefix() const final { return ""; }
63 void emit(const ConstantUndef *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070064 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070065 llvm::report_fatal_error("Not yet implemented");
66 }
67 void emit(const ConstantInteger32 *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070068 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070069 llvm::report_fatal_error("Not yet implemented");
70 }
71 void emit(const ConstantInteger64 *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070072 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070073 llvm::report_fatal_error("Not yet implemented");
74 }
75 void emit(const ConstantFloat *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070076 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070077 llvm::report_fatal_error("Not yet implemented");
78 }
79 void emit(const ConstantDouble *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070080 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070081 llvm::report_fatal_error("Not yet implemented");
82 }
Reed Kotlerd00d48d2015-07-08 09:49:07 -070083 void _ret(Variable *RA, Variable *Src0 = nullptr) {
84 Context.insert(InstMIPS32Ret::create(Func, RA, Src0));
85 }
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070086
87 void lowerArguments() override;
88 void addProlog(CfgNode *Node) override;
89 void addEpilog(CfgNode *Node) override;
90
91protected:
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 Stichnotheafb56c2015-06-22 10:35:22 -0700126 bool UsesFramePointer = false;
127 bool NeedsStackAlignment = false;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700128 llvm::SmallBitVector TypeToRegisterSet[IceType_NUM];
129 llvm::SmallBitVector ScratchRegs;
130 llvm::SmallBitVector RegsUsed;
131 VarList PhysicalRegisters[IceType_NUM];
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700132
133private:
Jim Stichnothe587d942015-06-22 15:49:04 -0700134 ~TargetMIPS32() override = default;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700135};
136
John Porto0f86d032015-06-15 07:44:27 -0700137class TargetDataMIPS32 final : public TargetDataLowering {
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700138 TargetDataMIPS32() = delete;
139 TargetDataMIPS32(const TargetDataMIPS32 &) = delete;
140 TargetDataMIPS32 &operator=(const TargetDataMIPS32 &) = delete;
141
142public:
Jan Voungfb792842015-06-11 15:27:50 -0700143 static std::unique_ptr<TargetDataLowering> create(GlobalContext *Ctx) {
144 return std::unique_ptr<TargetDataLowering>(new TargetDataMIPS32(Ctx));
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700145 }
146
John Porto8b1a7052015-06-17 13:20:08 -0700147 void lowerGlobals(const VariableDeclarationList &Vars,
148 const IceString &SectionSuffix) override;
John Porto0f86d032015-06-15 07:44:27 -0700149 void lowerConstants() override;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700150
151protected:
152 explicit TargetDataMIPS32(GlobalContext *Ctx);
153
154private:
Jim Stichnothe587d942015-06-22 15:49:04 -0700155 ~TargetDataMIPS32() override = default;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700156 template <typename T> static void emitConstantPool(GlobalContext *Ctx);
157};
158
Jan Voungfb792842015-06-11 15:27:50 -0700159class TargetHeaderMIPS32 final : public TargetHeaderLowering {
160 TargetHeaderMIPS32() = delete;
161 TargetHeaderMIPS32(const TargetHeaderMIPS32 &) = delete;
162 TargetHeaderMIPS32 &operator=(const TargetHeaderMIPS32 &) = delete;
163
164public:
165 static std::unique_ptr<TargetHeaderLowering> create(GlobalContext *Ctx) {
166 return std::unique_ptr<TargetHeaderLowering>(new TargetHeaderMIPS32(Ctx));
167 }
168
169protected:
170 explicit TargetHeaderMIPS32(GlobalContext *Ctx);
171
172private:
173 ~TargetHeaderMIPS32() = default;
174};
175
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700176} // end of namespace Ice
177
178#endif // SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H