| 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, |
| 11 // primarily the constructors and the dump()/emit() methods. | 11 // primarily the constructors and the dump()/emit() methods. |
| 12 // | 12 // |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "IceCfg.h" | 15 #include "IceCfg.h" |
| 16 #include "IceCfgNode.h" | 16 #include "IceCfgNode.h" |
| 17 #include "IceInst.h" | 17 #include "IceInst.h" |
| 18 #include "IceInstX8632.h" | 18 #include "IceInstX8632.h" |
| 19 #include "IceTargetLoweringX8632.h" | 19 #include "IceTargetLoweringX8632.h" |
| 20 #include "IceOperand.h" | 20 #include "IceOperand.h" |
| 21 | 21 |
| 22 namespace Ice { | 22 namespace Ice { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const struct InstX8632BrAttributes_ { | 26 const struct InstX8632BrAttributes_ { |
| 27 InstX8632::BrCond Opposite; |
| 27 const char *DisplayString; | 28 const char *DisplayString; |
| 28 const char *EmitString; | 29 const char *EmitString; |
| 29 } InstX8632BrAttributes[] = { | 30 } InstX8632BrAttributes[] = { |
| 30 #define X(tag, dump, emit) \ | 31 #define X(tag, opp, dump, emit) \ |
| 31 { dump, emit } \ | 32 { InstX8632::opp, dump, emit } \ |
| 32 , | 33 , |
| 33 ICEINSTX8632BR_TABLE | 34 ICEINSTX8632BR_TABLE |
| 34 #undef X | 35 #undef X |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 const struct InstX8632CmppsAttributes_ { | 38 const struct InstX8632CmppsAttributes_ { |
| 38 const char *EmitString; | 39 const char *EmitString; |
| 39 } InstX8632CmppsAttributes[] = { | 40 } InstX8632CmppsAttributes[] = { |
| 40 #define X(tag, emit) \ | 41 #define X(tag, emit) \ |
| 41 { emit } \ | 42 { emit } \ |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 InstX8632Label::InstX8632Label(Cfg *Func, TargetX8632 *Target) | 122 InstX8632Label::InstX8632Label(Cfg *Func, TargetX8632 *Target) |
| 122 : InstX8632(Func, InstX8632::Label, 0, NULL), | 123 : InstX8632(Func, InstX8632::Label, 0, NULL), |
| 123 Number(Target->makeNextLabelNumber()) {} | 124 Number(Target->makeNextLabelNumber()) {} |
| 124 | 125 |
| 125 IceString InstX8632Label::getName(const Cfg *Func) const { | 126 IceString InstX8632Label::getName(const Cfg *Func) const { |
| 126 char buf[30]; | 127 char buf[30]; |
| 127 snprintf(buf, llvm::array_lengthof(buf), "%u", Number); | 128 snprintf(buf, llvm::array_lengthof(buf), "%u", Number); |
| 128 return ".L" + Func->getFunctionName() + "$local$__" + buf; | 129 return ".L" + Func->getFunctionName() + "$local$__" + buf; |
| 129 } | 130 } |
| 130 | 131 |
| 131 InstX8632Br::InstX8632Br(Cfg *Func, CfgNode *TargetTrue, CfgNode *TargetFalse, | 132 InstX8632Br::InstX8632Br(Cfg *Func, const CfgNode *TargetTrue, |
| 132 InstX8632Label *Label, InstX8632::BrCond Condition) | 133 const CfgNode *TargetFalse, |
| 134 const InstX8632Label *Label, |
| 135 InstX8632::BrCond Condition) |
| 133 : InstX8632(Func, InstX8632::Br, 0, NULL), Condition(Condition), | 136 : InstX8632(Func, InstX8632::Br, 0, NULL), Condition(Condition), |
| 134 TargetTrue(TargetTrue), TargetFalse(TargetFalse), Label(Label) {} | 137 TargetTrue(TargetTrue), TargetFalse(TargetFalse), Label(Label) {} |
| 135 | 138 |
| 136 InstX8632Call::InstX8632Call(Cfg *Func, Variable *Dest, Operand *CallTarget) | 139 InstX8632Call::InstX8632Call(Cfg *Func, Variable *Dest, Operand *CallTarget) |
| 137 : InstX8632(Func, InstX8632::Call, 1, Dest) { | 140 : InstX8632(Func, InstX8632::Call, 1, Dest) { |
| 138 HasSideEffects = true; | 141 HasSideEffects = true; |
| 139 addSource(CallTarget); | 142 addSource(CallTarget); |
| 140 } | 143 } |
| 141 | 144 |
| 142 InstX8632Cmov::InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source, | 145 InstX8632Cmov::InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 void InstX8632Label::emit(const Cfg *Func) const { | 297 void InstX8632Label::emit(const Cfg *Func) const { |
| 295 Ostream &Str = Func->getContext()->getStrEmit(); | 298 Ostream &Str = Func->getContext()->getStrEmit(); |
| 296 Str << getName(Func) << ":\n"; | 299 Str << getName(Func) << ":\n"; |
| 297 } | 300 } |
| 298 | 301 |
| 299 void InstX8632Label::dump(const Cfg *Func) const { | 302 void InstX8632Label::dump(const Cfg *Func) const { |
| 300 Ostream &Str = Func->getContext()->getStrDump(); | 303 Ostream &Str = Func->getContext()->getStrDump(); |
| 301 Str << getName(Func) << ":"; | 304 Str << getName(Func) << ":"; |
| 302 } | 305 } |
| 303 | 306 |
| 307 void InstX8632Br::optimizeBranch(const CfgNode *NextNode) { |
| 308 // If there is no next block, then there is no fallthrough to |
| 309 // optimize. |
| 310 if (NextNode == NULL) |
| 311 return; |
| 312 // Intra-block conditional branches can't be optimized. |
| 313 if (Label) |
| 314 return; |
| 315 // Unconditional branch to the next node can be removed. |
| 316 if (Condition == Br_None && getTargetFalse() == NextNode) { |
| 317 setDeleted(); |
| 318 return; |
| 319 } |
| 320 // If the fallthrough is to the next node, set fallthrough to NULL |
| 321 // to indicate. |
| 322 if (getTargetFalse() == NextNode) { |
| 323 TargetFalse = NULL; |
| 324 return; |
| 325 } |
| 326 // If TargetTrue is the next node, and TargetFalse is non-NULL, then |
| 327 // invert the branch condition, swap the targets, and set new |
| 328 // fallthrough to NULL. |
| 329 if (getTargetTrue() == NextNode && getTargetFalse()) { |
| 330 assert(Condition != Br_None); |
| 331 Condition = InstX8632BrAttributes[Condition].Opposite; |
| 332 TargetTrue = getTargetFalse(); |
| 333 TargetFalse = NULL; |
| 334 return; |
| 335 } |
| 336 } |
| 337 |
| 304 void InstX8632Br::emit(const Cfg *Func) const { | 338 void InstX8632Br::emit(const Cfg *Func) const { |
| 305 Ostream &Str = Func->getContext()->getStrEmit(); | 339 Ostream &Str = Func->getContext()->getStrEmit(); |
| 306 Str << "\t"; | 340 Str << "\t"; |
| 307 | 341 |
| 308 if (Condition == Br_None) { | 342 if (Condition == Br_None) { |
| 309 Str << "jmp"; | 343 Str << "jmp"; |
| 310 } else { | 344 } else { |
| 311 Str << InstX8632BrAttributes[Condition].EmitString; | 345 Str << InstX8632BrAttributes[Condition].EmitString; |
| 312 } | 346 } |
| 313 | 347 |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 } | 1522 } |
| 1489 Str << "("; | 1523 Str << "("; |
| 1490 if (Func) | 1524 if (Func) |
| 1491 Var->dump(Func); | 1525 Var->dump(Func); |
| 1492 else | 1526 else |
| 1493 Var->dump(Str); | 1527 Var->dump(Str); |
| 1494 Str << ")"; | 1528 Str << ")"; |
| 1495 } | 1529 } |
| 1496 | 1530 |
| 1497 } // end of namespace Ice | 1531 } // end of namespace Ice |
| OLD | NEW |