blob: eb4a9fd282b1c5d68d6a85cd6c9c6813612eaa3a [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//===----------------------------------------------------------------------===//
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
23namespace Ice {
24
25class TargetMIPS32 : public TargetLowering {
26 TargetMIPS32() = delete;
27 TargetMIPS32(const TargetMIPS32 &) = delete;
28 TargetMIPS32 &operator=(const TargetMIPS32 &) = delete;
29
30public:
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 Voungfb792842015-06-11 15:27:50 -070059 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070060 llvm::report_fatal_error("Not yet implemented");
61 }
62 void emit(const ConstantInteger32 *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070063 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070064 llvm::report_fatal_error("Not yet implemented");
65 }
66 void emit(const ConstantInteger64 *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070067 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070068 llvm::report_fatal_error("Not yet implemented");
69 }
70 void emit(const ConstantFloat *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070071 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070072 llvm::report_fatal_error("Not yet implemented");
73 }
74 void emit(const ConstantDouble *C) const final {
Jan Voungfb792842015-06-11 15:27:50 -070075 (void)C;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -070076 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
83protected:
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 Stichnotheafb56c2015-06-22 10:35:22 -0700118 bool UsesFramePointer = false;
119 bool NeedsStackAlignment = false;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700120 llvm::SmallBitVector TypeToRegisterSet[IceType_NUM];
121 llvm::SmallBitVector ScratchRegs;
122 llvm::SmallBitVector RegsUsed;
123 VarList PhysicalRegisters[IceType_NUM];
124 static IceString RegNames[];
125
126private:
Jim Stichnothe587d942015-06-22 15:49:04 -0700127 ~TargetMIPS32() override = default;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700128};
129
John Porto0f86d032015-06-15 07:44:27 -0700130class TargetDataMIPS32 final : public TargetDataLowering {
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700131 TargetDataMIPS32() = delete;
132 TargetDataMIPS32(const TargetDataMIPS32 &) = delete;
133 TargetDataMIPS32 &operator=(const TargetDataMIPS32 &) = delete;
134
135public:
Jan Voungfb792842015-06-11 15:27:50 -0700136 static std::unique_ptr<TargetDataLowering> create(GlobalContext *Ctx) {
137 return std::unique_ptr<TargetDataLowering>(new TargetDataMIPS32(Ctx));
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700138 }
139
John Porto8b1a7052015-06-17 13:20:08 -0700140 void lowerGlobals(const VariableDeclarationList &Vars,
141 const IceString &SectionSuffix) override;
John Porto0f86d032015-06-15 07:44:27 -0700142 void lowerConstants() override;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700143
144protected:
145 explicit TargetDataMIPS32(GlobalContext *Ctx);
146
147private:
Jim Stichnothe587d942015-06-22 15:49:04 -0700148 ~TargetDataMIPS32() override = default;
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700149 template <typename T> static void emitConstantPool(GlobalContext *Ctx);
150};
151
Jan Voungfb792842015-06-11 15:27:50 -0700152class TargetHeaderMIPS32 final : public TargetHeaderLowering {
153 TargetHeaderMIPS32() = delete;
154 TargetHeaderMIPS32(const TargetHeaderMIPS32 &) = delete;
155 TargetHeaderMIPS32 &operator=(const TargetHeaderMIPS32 &) = delete;
156
157public:
158 static std::unique_ptr<TargetHeaderLowering> create(GlobalContext *Ctx) {
159 return std::unique_ptr<TargetHeaderLowering>(new TargetHeaderMIPS32(Ctx));
160 }
161
162protected:
163 explicit TargetHeaderMIPS32(GlobalContext *Ctx);
164
165private:
166 ~TargetHeaderMIPS32() = default;
167};
168
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700169} // end of namespace Ice
170
171#endif // SUBZERO_SRC_ICETARGETLOWERINGMIPS32_H