| OLD | NEW |
| 1 //===- subzero/src/IceInstX86BaseImpl.h - Generic X86 instructions -*- C++ -*=// | 1 //===- subzero/src/IceInstX86BaseImpl.h - Generic X86 instructions -*- C++ -*=// |
| 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 /// \file | 10 /// \file |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 template <class Machine> | 99 template <class Machine> |
| 100 IceString InstX86Label<Machine>::getName(const Cfg *Func) const { | 100 IceString InstX86Label<Machine>::getName(const Cfg *Func) const { |
| 101 return ".L" + Func->getFunctionName() + "$local$__" + std::to_string(Number); | 101 return ".L" + Func->getFunctionName() + "$local$__" + std::to_string(Number); |
| 102 } | 102 } |
| 103 | 103 |
| 104 template <class Machine> | 104 template <class Machine> |
| 105 InstX86Br<Machine>::InstX86Br( | 105 InstX86Br<Machine>::InstX86Br( |
| 106 Cfg *Func, const CfgNode *TargetTrue, const CfgNode *TargetFalse, | 106 Cfg *Func, const CfgNode *TargetTrue, const CfgNode *TargetFalse, |
| 107 const InstX86Label<Machine> *Label, | 107 const InstX86Label<Machine> *Label, |
| 108 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition) | 108 typename InstX86Base<Machine>::Traits::Cond::BrCond Condition, Mode Kind) |
| 109 : InstX86Base<Machine>(Func, InstX86Base<Machine>::Br, 0, nullptr), | 109 : InstX86Base<Machine>(Func, InstX86Base<Machine>::Br, 0, nullptr), |
| 110 Condition(Condition), TargetTrue(TargetTrue), TargetFalse(TargetFalse), | 110 Condition(Condition), TargetTrue(TargetTrue), TargetFalse(TargetFalse), |
| 111 Label(Label) {} | 111 Label(Label), Kind(Kind) {} |
| 112 | 112 |
| 113 template <class Machine> | 113 template <class Machine> |
| 114 bool InstX86Br<Machine>::optimizeBranch(const CfgNode *NextNode) { | 114 bool InstX86Br<Machine>::optimizeBranch(const CfgNode *NextNode) { |
| 115 // If there is no next block, then there can be no fallthrough to | 115 // If there is no next block, then there can be no fallthrough to |
| 116 // optimize. | 116 // optimize. |
| 117 if (NextNode == nullptr) | 117 if (NextNode == nullptr) |
| 118 return false; | 118 return false; |
| 119 // Intra-block conditional branches can't be optimized. | 119 // Intra-block conditional branches can't be optimized. |
| 120 if (Label) | 120 if (Label) |
| 121 return false; | 121 return false; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 if (!BuildDefs::dump()) | 397 if (!BuildDefs::dump()) |
| 398 return; | 398 return; |
| 399 Ostream &Str = Func->getContext()->getStrEmit(); | 399 Ostream &Str = Func->getContext()->getStrEmit(); |
| 400 Str << getName(Func) << ":"; | 400 Str << getName(Func) << ":"; |
| 401 } | 401 } |
| 402 | 402 |
| 403 template <class Machine> | 403 template <class Machine> |
| 404 void InstX86Label<Machine>::emitIAS(const Cfg *Func) const { | 404 void InstX86Label<Machine>::emitIAS(const Cfg *Func) const { |
| 405 typename InstX86Base<Machine>::Traits::Assembler *Asm = | 405 typename InstX86Base<Machine>::Traits::Assembler *Asm = |
| 406 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); | 406 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); |
| 407 Asm->BindLocalLabel(Number); | 407 Asm->bindLocalLabel(Number); |
| 408 } | 408 } |
| 409 | 409 |
| 410 template <class Machine> | 410 template <class Machine> |
| 411 void InstX86Label<Machine>::dump(const Cfg *Func) const { | 411 void InstX86Label<Machine>::dump(const Cfg *Func) const { |
| 412 if (!BuildDefs::dump()) | 412 if (!BuildDefs::dump()) |
| 413 return; | 413 return; |
| 414 Ostream &Str = Func->getContext()->getStrDump(); | 414 Ostream &Str = Func->getContext()->getStrDump(); |
| 415 Str << getName(Func) << ":"; | 415 Str << getName(Func) << ":"; |
| 416 } | 416 } |
| 417 | 417 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 template <class Machine> | 444 template <class Machine> |
| 445 void InstX86Br<Machine>::emitIAS(const Cfg *Func) const { | 445 void InstX86Br<Machine>::emitIAS(const Cfg *Func) const { |
| 446 typename InstX86Base<Machine>::Traits::Assembler *Asm = | 446 typename InstX86Base<Machine>::Traits::Assembler *Asm = |
| 447 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); | 447 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); |
| 448 if (Label) { | 448 if (Label) { |
| 449 class Label *L = Asm->GetOrCreateLocalLabel(Label->getNumber()); | 449 class Label *L = Asm->getOrCreateLocalLabel(Label->getNumber()); |
| 450 // In all these cases, local Labels should only be used for Near. | |
| 451 const bool Near = true; | |
| 452 if (Condition == InstX86Base<Machine>::Traits::Cond::Br_None) { | 450 if (Condition == InstX86Base<Machine>::Traits::Cond::Br_None) { |
| 453 Asm->jmp(L, Near); | 451 Asm->jmp(L, isNear()); |
| 454 } else { | 452 } else { |
| 455 Asm->j(Condition, L, Near); | 453 Asm->j(Condition, L, isNear()); |
| 456 } | 454 } |
| 457 } else { | 455 } else { |
| 458 // Pessimistically assume it's far. This only affects Labels that | |
| 459 // are not Bound. | |
| 460 const bool Near = false; | |
| 461 if (Condition == InstX86Base<Machine>::Traits::Cond::Br_None) { | 456 if (Condition == InstX86Base<Machine>::Traits::Cond::Br_None) { |
| 462 class Label *L = | 457 class Label *L = |
| 463 Asm->GetOrCreateCfgNodeLabel(getTargetFalse()->getIndex()); | 458 Asm->getOrCreateCfgNodeLabel(getTargetFalse()->getIndex()); |
| 464 assert(!getTargetTrue()); | 459 assert(!getTargetTrue()); |
| 465 Asm->jmp(L, Near); | 460 Asm->jmp(L, isNear()); |
| 466 } else { | 461 } else { |
| 467 class Label *L = | 462 class Label *L = |
| 468 Asm->GetOrCreateCfgNodeLabel(getTargetTrue()->getIndex()); | 463 Asm->getOrCreateCfgNodeLabel(getTargetTrue()->getIndex()); |
| 469 Asm->j(Condition, L, Near); | 464 Asm->j(Condition, L, isNear()); |
| 470 if (getTargetFalse()) { | 465 if (getTargetFalse()) { |
| 471 class Label *L2 = | 466 class Label *L2 = |
| 472 Asm->GetOrCreateCfgNodeLabel(getTargetFalse()->getIndex()); | 467 Asm->getOrCreateCfgNodeLabel(getTargetFalse()->getIndex()); |
| 473 Asm->jmp(L2, Near); | 468 Asm->jmp(L2, isNear()); |
| 474 } | 469 } |
| 475 } | 470 } |
| 476 } | 471 } |
| 477 } | 472 } |
| 478 | 473 |
| 479 template <class Machine> void InstX86Br<Machine>::dump(const Cfg *Func) const { | 474 template <class Machine> void InstX86Br<Machine>::dump(const Cfg *Func) const { |
| 480 if (!BuildDefs::dump()) | 475 if (!BuildDefs::dump()) |
| 481 return; | 476 return; |
| 482 Ostream &Str = Func->getContext()->getStrDump(); | 477 Ostream &Str = Func->getContext()->getStrDump(); |
| 483 Str << "br "; | 478 Str << "br "; |
| 484 | 479 |
| 485 if (Condition == InstX86Base<Machine>::Traits::Cond::Br_None) { | 480 if (Condition == InstX86Base<Machine>::Traits::Cond::Br_None) { |
| 486 Str << "label %" | 481 Str << "label %" |
| 487 << (Label ? Label->getName(Func) : getTargetFalse()->getName()); | 482 << (Label ? Label->getName(Func) : getTargetFalse()->getName()); |
| 488 return; | 483 return; |
| 489 } | 484 } |
| 490 | 485 |
| 491 Str << InstX86Base<Machine>::Traits::InstBrAttributes[Condition] | 486 Str << InstX86Base<Machine>::Traits::InstBrAttributes[Condition] |
| 492 .DisplayString; | 487 .DisplayString; |
| 493 if (Label) { | 488 if (Label) { |
| 494 Str << ", label %" << Label->getName(Func); | 489 Str << ", label %" << Label->getName(Func); |
| 495 } else { | 490 } else { |
| 496 Str << ", label %" << getTargetTrue()->getName(); | 491 Str << ", label %" << getTargetTrue()->getName(); |
| 497 if (getTargetFalse()) { | 492 if (getTargetFalse()) { |
| 498 Str << ", label %" << getTargetFalse()->getName(); | 493 Str << ", label %" << getTargetFalse()->getName(); |
| 499 } | 494 } |
| 500 } | 495 } |
| 496 |
| 497 Str << " // (" << (isNear() ? "near" : "far") << " jump)"; |
| 501 } | 498 } |
| 502 | 499 |
| 503 template <class Machine> void InstX86Jmp<Machine>::emit(const Cfg *Func) const { | 500 template <class Machine> void InstX86Jmp<Machine>::emit(const Cfg *Func) const { |
| 504 if (!BuildDefs::dump()) | 501 if (!BuildDefs::dump()) |
| 505 return; | 502 return; |
| 506 Ostream &Str = Func->getContext()->getStrEmit(); | 503 Ostream &Str = Func->getContext()->getStrEmit(); |
| 507 assert(this->getSrcSize() == 1); | 504 assert(this->getSrcSize() == 1); |
| 508 Str << "\tjmp\t*"; | 505 Str << "\tjmp\t*"; |
| 509 getJmpTarget()->emit(Func); | 506 getJmpTarget()->emit(Func); |
| 510 } | 507 } |
| (...skipping 2644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3155 Type Ty = this->getSrc(0)->getType(); | 3152 Type Ty = this->getSrc(0)->getType(); |
| 3156 Str << "xchg." << Ty << " "; | 3153 Str << "xchg." << Ty << " "; |
| 3157 this->dumpSources(Func); | 3154 this->dumpSources(Func); |
| 3158 } | 3155 } |
| 3159 | 3156 |
| 3160 } // end of namespace X86Internal | 3157 } // end of namespace X86Internal |
| 3161 | 3158 |
| 3162 } // end of namespace Ice | 3159 } // end of namespace Ice |
| 3163 | 3160 |
| 3164 #endif // SUBZERO_SRC_ICEINSTX86BASEIMPL_H | 3161 #endif // SUBZERO_SRC_ICEINSTX86BASEIMPL_H |
| OLD | NEW |