OLD | NEW |
---|---|
(Empty) | |
1 //===- subzero/src/IceTargetLoweringX8632.h - x86-32 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 TargetLoweringX8632 class, which | |
11 // implements the TargetLowering interface for the x86-32 | |
12 // architecture. | |
13 // | |
14 //===----------------------------------------------------------------------===// | |
15 | |
16 #ifndef SUBZERO_SRC_ICETARGETLOWERINGX8632_H | |
17 #define SUBZERO_SRC_ICETARGETLOWERINGX8632_H | |
18 | |
19 #include "IceDefs.h" | |
20 #include "IceTargetLowering.h" | |
21 #include "IceInstX8632.h" | |
22 | |
23 namespace Ice { | |
24 | |
25 class TargetX8632 : public TargetLowering { | |
26 public: | |
27 static TargetX8632 *create(Cfg *Func) { return new TargetX8632(Func); } | |
28 | |
29 virtual void translateOm1(); | |
30 | |
31 virtual Variable *getPhysicalRegister(SizeT RegNum); | |
32 virtual IceString getRegName(SizeT RegNum, Type Ty) const; | |
33 virtual llvm::SmallBitVector getRegisterSet(RegSetMask Include, | |
34 RegSetMask Exclude) const; | |
35 virtual const llvm::SmallBitVector &getRegisterSetForType(Type Ty) const { | |
36 return TypeToRegisterSet[Ty]; | |
37 } | |
38 virtual bool hasFramePointer() const { return IsEbpBasedFrame; } | |
39 virtual SizeT getFrameOrStackReg() const { | |
40 return IsEbpBasedFrame ? Reg_ebp : Reg_esp; | |
41 } | |
42 virtual size_t typeWidthInBytesOnStack(Type Ty) { | |
43 return (typeWidthInBytes(Ty) + 3) & ~3; | |
JF
2014/05/04 23:54:58
Can you explain?
Jim Stichnoth
2014/05/05 07:03:55
Done.
| |
44 } | |
45 virtual void emitVariable(const Variable *Var, const Cfg *Func) const; | |
46 virtual void addProlog(CfgNode *Node); | |
47 virtual void addEpilog(CfgNode *Node); | |
48 SizeT makeNextLabelNumber() { return NextLabelNumber++; } | |
49 // Ensure that a 64-bit Variable has been split into 2 32-bit | |
50 // Variables, creating them if necessary. This is needed for all | |
51 // I64 operations, and it is needed for pushing F64 arguments for | |
52 // function calls using the 32-bit push instruction (though the | |
53 // latter could be done by directly writing to the stack). | |
54 void split64(Variable *Var); | |
55 void setArgOffsetAndCopy(Variable *Arg, Variable *FramePtr, | |
56 int32_t BasicFrameOffset, int32_t &InArgsSizeBytes); | |
57 Operand *loOperand(Operand *Operand); | |
58 Operand *hiOperand(Operand *Operand); | |
59 | |
60 enum Registers { | |
61 #define X(val, init, name, name16, name8, scratch, preserved, stackptr, \ | |
62 frameptr, isI8, isInt, isFP) \ | |
63 val init, | |
64 REGX8632_TABLE | |
65 #undef X | |
66 Reg_NUM | |
67 }; | |
68 | |
69 protected: | |
70 TargetX8632(Cfg *Func); | |
71 | |
72 virtual void postLower(); | |
73 | |
74 virtual void lowerAlloca(const InstAlloca *Inst); | |
75 virtual void lowerArithmetic(const InstArithmetic *Inst); | |
76 virtual void lowerAssign(const InstAssign *Inst); | |
77 virtual void lowerBr(const InstBr *Inst); | |
78 virtual void lowerCall(const InstCall *Inst); | |
79 virtual void lowerCast(const InstCast *Inst); | |
80 virtual void lowerFcmp(const InstFcmp *Inst); | |
81 virtual void lowerIcmp(const InstIcmp *Inst); | |
82 virtual void lowerLoad(const InstLoad *Inst); | |
83 virtual void lowerPhi(const InstPhi *Inst); | |
84 virtual void lowerRet(const InstRet *Inst); | |
85 virtual void lowerSelect(const InstSelect *Inst); | |
86 virtual void lowerStore(const InstStore *Inst); | |
87 virtual void lowerSwitch(const InstSwitch *Inst); | |
88 virtual void lowerUnreachable(const InstUnreachable *Inst); | |
89 | |
90 enum OperandLegalization { | |
91 Legal_None = 0, | |
92 Legal_Reg = 1 << 0, | |
93 Legal_Imm = 1 << 1, | |
94 Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12] | |
95 Legal_All = ~Legal_None | |
96 }; | |
97 typedef uint32_t LegalMask; | |
98 Operand *legalize(Operand *From, LegalMask Allowed = Legal_All, | |
99 bool AllowOverlap = false, | |
100 int32_t RegNum = Variable::NoRegister); | |
101 Variable *legalizeToVar(Operand *From, bool AllowOverlap = false, | |
102 int32_t RegNum = Variable::NoRegister); | |
103 Variable *makeReg(Type Ty, int32_t RegNum = Variable::NoRegister); | |
104 InstCall *makeHelperCall(const IceString &Name, Variable *Dest, | |
105 SizeT MaxSrcs) { | |
106 bool SuppressMangling = true; | |
107 Type Ty = Dest ? Dest->getType() : IceType_void; | |
108 Constant *CallTarget = Ctx->getConstantSym(Ty, 0, Name, SuppressMangling); | |
109 InstCall *Call = InstCall::create(Func, MaxSrcs, Dest, CallTarget); | |
110 return Call; | |
111 } | |
112 | |
113 // The following are helpers that insert lowered x86 instructions | |
114 // with minimal syntactic overhead, so that the lowering code can | |
115 // look as close to assembly as practical. | |
116 void _adc(Variable *Dest, Operand *Src0) { | |
117 Context.insert(InstX8632Adc::create(Func, Dest, Src0)); | |
118 } | |
119 void _add(Variable *Dest, Operand *Src0) { | |
120 Context.insert(InstX8632Add::create(Func, Dest, Src0)); | |
121 } | |
122 void _addss(Variable *Dest, Operand *Src0) { | |
123 Context.insert(InstX8632Addss::create(Func, Dest, Src0)); | |
124 } | |
125 void _and(Variable *Dest, Operand *Src0) { | |
126 Context.insert(InstX8632And::create(Func, Dest, Src0)); | |
127 } | |
128 void _br(InstX8632Br::BrCond Condition, CfgNode *TargetTrue, | |
129 CfgNode *TargetFalse) { | |
130 Context.insert( | |
131 InstX8632Br::create(Func, TargetTrue, TargetFalse, Condition)); | |
132 } | |
133 void _br(CfgNode *Target) { | |
134 Context.insert(InstX8632Br::create(Func, Target)); | |
135 } | |
136 void _br(InstX8632Br::BrCond Condition, CfgNode *Target) { | |
137 Context.insert(InstX8632Br::create(Func, Target, Condition)); | |
138 } | |
139 void _br(InstX8632Br::BrCond Condition, InstX8632Label *Label) { | |
140 Context.insert(InstX8632Br::create(Func, Label, Condition)); | |
141 } | |
142 void _cdq(Variable *Dest, Operand *Src0) { | |
143 Context.insert(InstX8632Cdq::create(Func, Dest, Src0)); | |
144 } | |
145 void _cmp(Operand *Src0, Operand *Src1) { | |
146 Context.insert(InstX8632Icmp::create(Func, Src0, Src1)); | |
147 } | |
148 void _cvt(Variable *Dest, Operand *Src0) { | |
149 Context.insert(InstX8632Cvt::create(Func, Dest, Src0)); | |
150 } | |
151 void _div(Variable *Dest, Operand *Src0, Operand *Src1) { | |
152 Context.insert(InstX8632Div::create(Func, Dest, Src0, Src1)); | |
153 } | |
154 void _divss(Variable *Dest, Operand *Src0) { | |
155 Context.insert(InstX8632Divss::create(Func, Dest, Src0)); | |
156 } | |
157 void _fld(Operand *Src0) { Context.insert(InstX8632Fld::create(Func, Src0)); } | |
158 void _fstp(Variable *Dest) { | |
159 Context.insert(InstX8632Fstp::create(Func, Dest)); | |
160 } | |
161 void _idiv(Variable *Dest, Operand *Src0, Operand *Src1) { | |
162 Context.insert(InstX8632Idiv::create(Func, Dest, Src0, Src1)); | |
163 } | |
164 void _imul(Variable *Dest, Operand *Src0) { | |
165 Context.insert(InstX8632Imul::create(Func, Dest, Src0)); | |
166 } | |
167 // If Dest=NULL is passed in, then a new variable is created, marked | |
168 // as infinite register allocation weight, and returned through the | |
169 // in/out Dest argument. | |
170 void _mov(Variable *&Dest, Operand *Src0, | |
171 int32_t RegNum = Variable::NoRegister) { | |
172 if (Dest == NULL) { | |
173 Dest = legalizeToVar(Src0, false, RegNum); | |
174 } else { | |
175 Context.insert(InstX8632Mov::create(Func, Dest, Src0)); | |
176 } | |
177 } | |
178 void _movsx(Variable *Dest, Operand *Src0) { | |
179 Context.insert(InstX8632Movsx::create(Func, Dest, Src0)); | |
180 } | |
181 void _movzx(Variable *Dest, Operand *Src0) { | |
182 Context.insert(InstX8632Movzx::create(Func, Dest, Src0)); | |
183 } | |
184 void _mul(Variable *Dest, Variable *Src0, Operand *Src1) { | |
185 Context.insert(InstX8632Mul::create(Func, Dest, Src0, Src1)); | |
186 } | |
187 void _mulss(Variable *Dest, Operand *Src0) { | |
188 Context.insert(InstX8632Mulss::create(Func, Dest, Src0)); | |
189 } | |
190 void _or(Variable *Dest, Operand *Src0) { | |
191 Context.insert(InstX8632Or::create(Func, Dest, Src0)); | |
192 } | |
193 void _pop(Variable *Dest) { | |
194 Context.insert(InstX8632Pop::create(Func, Dest)); | |
195 } | |
196 void _push(Operand *Src0, bool SuppressStackAdjustment = false) { | |
197 Context.insert(InstX8632Push::create(Func, Src0, SuppressStackAdjustment)); | |
198 } | |
199 void _ret(Variable *Src0 = NULL) { | |
200 Context.insert(InstX8632Ret::create(Func, Src0)); | |
201 } | |
202 void _sar(Variable *Dest, Operand *Src0) { | |
203 Context.insert(InstX8632Sar::create(Func, Dest, Src0)); | |
204 } | |
205 void _sbb(Variable *Dest, Operand *Src0) { | |
206 Context.insert(InstX8632Sbb::create(Func, Dest, Src0)); | |
207 } | |
208 void _shl(Variable *Dest, Operand *Src0) { | |
209 Context.insert(InstX8632Shl::create(Func, Dest, Src0)); | |
210 } | |
211 void _shld(Variable *Dest, Variable *Src0, Variable *Src1) { | |
212 Context.insert(InstX8632Shld::create(Func, Dest, Src0, Src1)); | |
213 } | |
214 void _shr(Variable *Dest, Operand *Src0) { | |
215 Context.insert(InstX8632Shr::create(Func, Dest, Src0)); | |
216 } | |
217 void _shrd(Variable *Dest, Variable *Src0, Variable *Src1) { | |
218 Context.insert(InstX8632Shrd::create(Func, Dest, Src0, Src1)); | |
219 } | |
220 void _store(Operand *Value, OperandX8632 *Mem) { | |
221 Context.insert(InstX8632Store::create(Func, Value, Mem)); | |
222 } | |
223 void _sub(Variable *Dest, Operand *Src0) { | |
224 Context.insert(InstX8632Sub::create(Func, Dest, Src0)); | |
225 } | |
226 void _subss(Variable *Dest, Operand *Src0) { | |
227 Context.insert(InstX8632Subss::create(Func, Dest, Src0)); | |
228 } | |
229 void _test(Operand *Src0, Operand *Src1) { | |
230 Context.insert(InstX8632Test::create(Func, Src0, Src1)); | |
231 } | |
232 void _ucomiss(Operand *Src0, Operand *Src1) { | |
233 Context.insert(InstX8632Ucomiss::create(Func, Src0, Src1)); | |
234 } | |
235 void _xor(Variable *Dest, Operand *Src0) { | |
236 Context.insert(InstX8632Xor::create(Func, Dest, Src0)); | |
237 } | |
238 | |
239 bool IsEbpBasedFrame; | |
240 int32_t FrameSizeLocals; | |
241 int32_t LocalsSizeBytes; | |
242 llvm::SmallBitVector TypeToRegisterSet[IceType_NUM]; | |
243 llvm::SmallBitVector ScratchRegs; | |
244 llvm::SmallBitVector RegsUsed; | |
245 SizeT NextLabelNumber; | |
246 bool ComputedLiveRanges; | |
247 VarList PhysicalRegisters; | |
248 static IceString RegNames[]; | |
249 | |
250 private: | |
251 TargetX8632(const TargetX8632 &) LLVM_DELETED_FUNCTION; | |
252 TargetX8632 &operator=(const TargetX8632 &) LLVM_DELETED_FUNCTION; | |
253 virtual ~TargetX8632() {} | |
254 }; | |
255 | |
256 } // end of namespace Ice | |
257 | |
258 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8632_H | |
OLD | NEW |