OLD | NEW |
1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// | 1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the InstX8632 and OperandX8632 classes, | 10 // This file implements the InstX8632 and OperandX8632 classes, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 const char *InstX8632::getFldString(Type Ty) { | 83 const char *InstX8632::getFldString(Type Ty) { |
84 return TypeX8632Attributes[Ty].FldString; | 84 return TypeX8632Attributes[Ty].FldString; |
85 } | 85 } |
86 | 86 |
87 OperandX8632Mem::OperandX8632Mem(Cfg *Func, Type Ty, Variable *Base, | 87 OperandX8632Mem::OperandX8632Mem(Cfg *Func, Type Ty, Variable *Base, |
88 Constant *Offset, Variable *Index, | 88 Constant *Offset, Variable *Index, |
89 uint16_t Shift, SegmentRegisters SegmentReg) | 89 uint16_t Shift, SegmentRegisters SegmentReg) |
90 : OperandX8632(kMem, Ty), Base(Base), Offset(Offset), Index(Index), | 90 : OperandX8632(kMem, Ty), Base(Base), Offset(Offset), Index(Index), |
91 Shift(Shift), SegmentReg(SegmentReg) { | 91 Shift(Shift), SegmentReg(SegmentReg) { |
92 assert(Shift <= 3); | 92 assert(Shift <= 3); |
93 Vars = NULL; | 93 Vars = nullptr; |
94 NumVars = 0; | 94 NumVars = 0; |
95 if (Base) | 95 if (Base) |
96 ++NumVars; | 96 ++NumVars; |
97 if (Index) | 97 if (Index) |
98 ++NumVars; | 98 ++NumVars; |
99 if (NumVars) { | 99 if (NumVars) { |
100 Vars = Func->allocateArrayOf<Variable *>(NumVars); | 100 Vars = Func->allocateArrayOf<Variable *>(NumVars); |
101 SizeT I = 0; | 101 SizeT I = 0; |
102 if (Base) | 102 if (Base) |
103 Vars[I++] = Base; | 103 Vars[I++] = Base; |
(...skipping 26 matching lines...) Expand all Loading... |
130 | 130 |
131 InstX8632Shrd::InstX8632Shrd(Cfg *Func, Variable *Dest, Variable *Source1, | 131 InstX8632Shrd::InstX8632Shrd(Cfg *Func, Variable *Dest, Variable *Source1, |
132 Variable *Source2) | 132 Variable *Source2) |
133 : InstX8632(Func, InstX8632::Shrd, 3, Dest) { | 133 : InstX8632(Func, InstX8632::Shrd, 3, Dest) { |
134 addSource(Dest); | 134 addSource(Dest); |
135 addSource(Source1); | 135 addSource(Source1); |
136 addSource(Source2); | 136 addSource(Source2); |
137 } | 137 } |
138 | 138 |
139 InstX8632Label::InstX8632Label(Cfg *Func, TargetX8632 *Target) | 139 InstX8632Label::InstX8632Label(Cfg *Func, TargetX8632 *Target) |
140 : InstX8632(Func, InstX8632::Label, 0, NULL), | 140 : InstX8632(Func, InstX8632::Label, 0, nullptr), |
141 Number(Target->makeNextLabelNumber()) {} | 141 Number(Target->makeNextLabelNumber()) {} |
142 | 142 |
143 IceString InstX8632Label::getName(const Cfg *Func) const { | 143 IceString InstX8632Label::getName(const Cfg *Func) const { |
144 return ".L" + Func->getFunctionName() + "$local$__" + std::to_string(Number); | 144 return ".L" + Func->getFunctionName() + "$local$__" + std::to_string(Number); |
145 } | 145 } |
146 | 146 |
147 InstX8632Br::InstX8632Br(Cfg *Func, const CfgNode *TargetTrue, | 147 InstX8632Br::InstX8632Br(Cfg *Func, const CfgNode *TargetTrue, |
148 const CfgNode *TargetFalse, | 148 const CfgNode *TargetFalse, |
149 const InstX8632Label *Label, CondX86::BrCond Condition) | 149 const InstX8632Label *Label, CondX86::BrCond Condition) |
150 : InstX8632(Func, InstX8632::Br, 0, NULL), Condition(Condition), | 150 : InstX8632(Func, InstX8632::Br, 0, nullptr), Condition(Condition), |
151 TargetTrue(TargetTrue), TargetFalse(TargetFalse), Label(Label) {} | 151 TargetTrue(TargetTrue), TargetFalse(TargetFalse), Label(Label) {} |
152 | 152 |
153 bool InstX8632Br::optimizeBranch(const CfgNode *NextNode) { | 153 bool InstX8632Br::optimizeBranch(const CfgNode *NextNode) { |
154 // If there is no next block, then there can be no fallthrough to | 154 // If there is no next block, then there can be no fallthrough to |
155 // optimize. | 155 // optimize. |
156 if (NextNode == NULL) | 156 if (NextNode == nullptr) |
157 return false; | 157 return false; |
158 // Intra-block conditional branches can't be optimized. | 158 // Intra-block conditional branches can't be optimized. |
159 if (Label) | 159 if (Label) |
160 return false; | 160 return false; |
161 // If there is no fallthrough node, such as a non-default case label | 161 // If there is no fallthrough node, such as a non-default case label |
162 // for a switch instruction, then there is no opportunity to | 162 // for a switch instruction, then there is no opportunity to |
163 // optimize. | 163 // optimize. |
164 if (getTargetFalse() == NULL) | 164 if (getTargetFalse() == nullptr) |
165 return false; | 165 return false; |
166 | 166 |
167 // Unconditional branch to the next node can be removed. | 167 // Unconditional branch to the next node can be removed. |
168 if (Condition == CondX86::Br_None && getTargetFalse() == NextNode) { | 168 if (Condition == CondX86::Br_None && getTargetFalse() == NextNode) { |
169 assert(getTargetTrue() == NULL); | 169 assert(getTargetTrue() == nullptr); |
170 setDeleted(); | 170 setDeleted(); |
171 return true; | 171 return true; |
172 } | 172 } |
173 // If the fallthrough is to the next node, set fallthrough to NULL | 173 // If the fallthrough is to the next node, set fallthrough to nullptr |
174 // to indicate. | 174 // to indicate. |
175 if (getTargetFalse() == NextNode) { | 175 if (getTargetFalse() == NextNode) { |
176 TargetFalse = NULL; | 176 TargetFalse = nullptr; |
177 return true; | 177 return true; |
178 } | 178 } |
179 // If TargetTrue is the next node, and TargetFalse is non-NULL | 179 // If TargetTrue is the next node, and TargetFalse is not nullptr |
180 // (which was already tested above), then invert the branch | 180 // (which was already tested above), then invert the branch |
181 // condition, swap the targets, and set new fallthrough to NULL. | 181 // condition, swap the targets, and set new fallthrough to nullptr. |
182 if (getTargetTrue() == NextNode) { | 182 if (getTargetTrue() == NextNode) { |
183 assert(Condition != CondX86::Br_None); | 183 assert(Condition != CondX86::Br_None); |
184 Condition = InstX8632BrAttributes[Condition].Opposite; | 184 Condition = InstX8632BrAttributes[Condition].Opposite; |
185 TargetTrue = getTargetFalse(); | 185 TargetTrue = getTargetFalse(); |
186 TargetFalse = NULL; | 186 TargetFalse = nullptr; |
187 return true; | 187 return true; |
188 } | 188 } |
189 return false; | 189 return false; |
190 } | 190 } |
191 | 191 |
192 bool InstX8632Br::repointEdge(CfgNode *OldNode, CfgNode *NewNode) { | 192 bool InstX8632Br::repointEdge(CfgNode *OldNode, CfgNode *NewNode) { |
193 if (TargetFalse == OldNode) { | 193 if (TargetFalse == OldNode) { |
194 TargetFalse = NewNode; | 194 TargetFalse = NewNode; |
195 return true; | 195 return true; |
196 } else if (TargetTrue == OldNode) { | 196 } else if (TargetTrue == OldNode) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 assert(Eax->getRegNum() == RegX8632::Reg_eax); | 230 assert(Eax->getRegNum() == RegX8632::Reg_eax); |
231 addSource(DestOrAddr); | 231 addSource(DestOrAddr); |
232 addSource(Eax); | 232 addSource(Eax); |
233 addSource(Desired); | 233 addSource(Desired); |
234 } | 234 } |
235 | 235 |
236 InstX8632Cmpxchg8b::InstX8632Cmpxchg8b(Cfg *Func, OperandX8632Mem *Addr, | 236 InstX8632Cmpxchg8b::InstX8632Cmpxchg8b(Cfg *Func, OperandX8632Mem *Addr, |
237 Variable *Edx, Variable *Eax, | 237 Variable *Edx, Variable *Eax, |
238 Variable *Ecx, Variable *Ebx, | 238 Variable *Ecx, Variable *Ebx, |
239 bool Locked) | 239 bool Locked) |
240 : InstX8632Lockable(Func, InstX8632::Cmpxchg, 5, NULL, Locked) { | 240 : InstX8632Lockable(Func, InstX8632::Cmpxchg, 5, nullptr, Locked) { |
241 assert(Edx->getRegNum() == RegX8632::Reg_edx); | 241 assert(Edx->getRegNum() == RegX8632::Reg_edx); |
242 assert(Eax->getRegNum() == RegX8632::Reg_eax); | 242 assert(Eax->getRegNum() == RegX8632::Reg_eax); |
243 assert(Ecx->getRegNum() == RegX8632::Reg_ecx); | 243 assert(Ecx->getRegNum() == RegX8632::Reg_ecx); |
244 assert(Ebx->getRegNum() == RegX8632::Reg_ebx); | 244 assert(Ebx->getRegNum() == RegX8632::Reg_ebx); |
245 addSource(Addr); | 245 addSource(Addr); |
246 addSource(Edx); | 246 addSource(Edx); |
247 addSource(Eax); | 247 addSource(Eax); |
248 addSource(Ecx); | 248 addSource(Ecx); |
249 addSource(Ebx); | 249 addSource(Ebx); |
250 } | 250 } |
251 | 251 |
252 InstX8632Cvt::InstX8632Cvt(Cfg *Func, Variable *Dest, Operand *Source, | 252 InstX8632Cvt::InstX8632Cvt(Cfg *Func, Variable *Dest, Operand *Source, |
253 CvtVariant Variant) | 253 CvtVariant Variant) |
254 : InstX8632(Func, InstX8632::Cvt, 1, Dest), Variant(Variant) { | 254 : InstX8632(Func, InstX8632::Cvt, 1, Dest), Variant(Variant) { |
255 addSource(Source); | 255 addSource(Source); |
256 } | 256 } |
257 | 257 |
258 InstX8632Icmp::InstX8632Icmp(Cfg *Func, Operand *Src0, Operand *Src1) | 258 InstX8632Icmp::InstX8632Icmp(Cfg *Func, Operand *Src0, Operand *Src1) |
259 : InstX8632(Func, InstX8632::Icmp, 2, NULL) { | 259 : InstX8632(Func, InstX8632::Icmp, 2, nullptr) { |
260 addSource(Src0); | 260 addSource(Src0); |
261 addSource(Src1); | 261 addSource(Src1); |
262 } | 262 } |
263 | 263 |
264 InstX8632Ucomiss::InstX8632Ucomiss(Cfg *Func, Operand *Src0, Operand *Src1) | 264 InstX8632Ucomiss::InstX8632Ucomiss(Cfg *Func, Operand *Src0, Operand *Src1) |
265 : InstX8632(Func, InstX8632::Ucomiss, 2, NULL) { | 265 : InstX8632(Func, InstX8632::Ucomiss, 2, nullptr) { |
266 addSource(Src0); | 266 addSource(Src0); |
267 addSource(Src1); | 267 addSource(Src1); |
268 } | 268 } |
269 | 269 |
270 InstX8632UD2::InstX8632UD2(Cfg *Func) | 270 InstX8632UD2::InstX8632UD2(Cfg *Func) |
271 : InstX8632(Func, InstX8632::UD2, 0, NULL) {} | 271 : InstX8632(Func, InstX8632::UD2, 0, nullptr) {} |
272 | 272 |
273 InstX8632Test::InstX8632Test(Cfg *Func, Operand *Src1, Operand *Src2) | 273 InstX8632Test::InstX8632Test(Cfg *Func, Operand *Src1, Operand *Src2) |
274 : InstX8632(Func, InstX8632::Test, 2, NULL) { | 274 : InstX8632(Func, InstX8632::Test, 2, nullptr) { |
275 addSource(Src1); | 275 addSource(Src1); |
276 addSource(Src2); | 276 addSource(Src2); |
277 } | 277 } |
278 | 278 |
279 InstX8632Mfence::InstX8632Mfence(Cfg *Func) | 279 InstX8632Mfence::InstX8632Mfence(Cfg *Func) |
280 : InstX8632(Func, InstX8632::Mfence, 0, NULL) { | 280 : InstX8632(Func, InstX8632::Mfence, 0, nullptr) { |
281 HasSideEffects = true; | 281 HasSideEffects = true; |
282 } | 282 } |
283 | 283 |
284 InstX8632Store::InstX8632Store(Cfg *Func, Operand *Value, OperandX8632 *Mem) | 284 InstX8632Store::InstX8632Store(Cfg *Func, Operand *Value, OperandX8632 *Mem) |
285 : InstX8632(Func, InstX8632::Store, 2, NULL) { | 285 : InstX8632(Func, InstX8632::Store, 2, nullptr) { |
286 addSource(Value); | 286 addSource(Value); |
287 addSource(Mem); | 287 addSource(Mem); |
288 } | 288 } |
289 | 289 |
290 InstX8632StoreP::InstX8632StoreP(Cfg *Func, Variable *Value, | 290 InstX8632StoreP::InstX8632StoreP(Cfg *Func, Variable *Value, |
291 OperandX8632Mem *Mem) | 291 OperandX8632Mem *Mem) |
292 : InstX8632(Func, InstX8632::StoreP, 2, NULL) { | 292 : InstX8632(Func, InstX8632::StoreP, 2, nullptr) { |
293 addSource(Value); | 293 addSource(Value); |
294 addSource(Mem); | 294 addSource(Mem); |
295 } | 295 } |
296 | 296 |
297 InstX8632StoreQ::InstX8632StoreQ(Cfg *Func, Variable *Value, | 297 InstX8632StoreQ::InstX8632StoreQ(Cfg *Func, Variable *Value, |
298 OperandX8632Mem *Mem) | 298 OperandX8632Mem *Mem) |
299 : InstX8632(Func, InstX8632::StoreQ, 2, NULL) { | 299 : InstX8632(Func, InstX8632::StoreQ, 2, nullptr) { |
300 addSource(Value); | 300 addSource(Value); |
301 addSource(Mem); | 301 addSource(Mem); |
302 } | 302 } |
303 | 303 |
304 InstX8632Nop::InstX8632Nop(Cfg *Func, InstX8632Nop::NopVariant Variant) | 304 InstX8632Nop::InstX8632Nop(Cfg *Func, InstX8632Nop::NopVariant Variant) |
305 : InstX8632(Func, InstX8632::Nop, 0, NULL), Variant(Variant) {} | 305 : InstX8632(Func, InstX8632::Nop, 0, nullptr), Variant(Variant) {} |
306 | 306 |
307 InstX8632Fld::InstX8632Fld(Cfg *Func, Operand *Src) | 307 InstX8632Fld::InstX8632Fld(Cfg *Func, Operand *Src) |
308 : InstX8632(Func, InstX8632::Fld, 1, NULL) { | 308 : InstX8632(Func, InstX8632::Fld, 1, nullptr) { |
309 addSource(Src); | 309 addSource(Src); |
310 } | 310 } |
311 | 311 |
312 InstX8632Fstp::InstX8632Fstp(Cfg *Func, Variable *Dest) | 312 InstX8632Fstp::InstX8632Fstp(Cfg *Func, Variable *Dest) |
313 : InstX8632(Func, InstX8632::Fstp, 0, Dest) {} | 313 : InstX8632(Func, InstX8632::Fstp, 0, Dest) {} |
314 | 314 |
315 InstX8632Pop::InstX8632Pop(Cfg *Func, Variable *Dest) | 315 InstX8632Pop::InstX8632Pop(Cfg *Func, Variable *Dest) |
316 : InstX8632(Func, InstX8632::Pop, 0, Dest) {} | 316 : InstX8632(Func, InstX8632::Pop, 0, Dest) {} |
317 | 317 |
318 InstX8632Push::InstX8632Push(Cfg *Func, Variable *Source) | 318 InstX8632Push::InstX8632Push(Cfg *Func, Variable *Source) |
319 : InstX8632(Func, InstX8632::Push, 1, NULL) { | 319 : InstX8632(Func, InstX8632::Push, 1, nullptr) { |
320 addSource(Source); | 320 addSource(Source); |
321 } | 321 } |
322 | 322 |
323 InstX8632Ret::InstX8632Ret(Cfg *Func, Variable *Source) | 323 InstX8632Ret::InstX8632Ret(Cfg *Func, Variable *Source) |
324 : InstX8632(Func, InstX8632::Ret, Source ? 1 : 0, NULL) { | 324 : InstX8632(Func, InstX8632::Ret, Source ? 1 : 0, nullptr) { |
325 if (Source) | 325 if (Source) |
326 addSource(Source); | 326 addSource(Source); |
327 } | 327 } |
328 | 328 |
329 InstX8632Xadd::InstX8632Xadd(Cfg *Func, Operand *Dest, Variable *Source, | 329 InstX8632Xadd::InstX8632Xadd(Cfg *Func, Operand *Dest, Variable *Source, |
330 bool Locked) | 330 bool Locked) |
331 : InstX8632Lockable(Func, InstX8632::Xadd, 2, | 331 : InstX8632Lockable(Func, InstX8632::Xadd, 2, |
332 llvm::dyn_cast<Variable>(Dest), Locked) { | 332 llvm::dyn_cast<Variable>(Dest), Locked) { |
333 addSource(Dest); | 333 addSource(Dest); |
334 addSource(Source); | 334 addSource(Source); |
(...skipping 2579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2914 } | 2914 } |
2915 Str << "("; | 2915 Str << "("; |
2916 if (Func) | 2916 if (Func) |
2917 Var->dump(Func); | 2917 Var->dump(Func); |
2918 else | 2918 else |
2919 Var->dump(Str); | 2919 Var->dump(Str); |
2920 Str << ")"; | 2920 Str << ")"; |
2921 } | 2921 } |
2922 | 2922 |
2923 } // end of namespace Ice | 2923 } // end of namespace Ice |
OLD | NEW |