Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===// | 1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering 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 /// \file | 10 /// \file |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 if (Instr.isDeleted()) | 576 if (Instr.isDeleted()) |
| 577 continue; | 577 continue; |
| 578 if (const Variable *Var = Instr.getDest()) | 578 if (const Variable *Var = Instr.getDest()) |
| 579 IsVarReferenced[Var->getIndex()] = true; | 579 IsVarReferenced[Var->getIndex()] = true; |
| 580 FOREACH_VAR_IN_INST(Var, Instr) { | 580 FOREACH_VAR_IN_INST(Var, Instr) { |
| 581 IsVarReferenced[Var->getIndex()] = true; | 581 IsVarReferenced[Var->getIndex()] = true; |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 | 585 |
| 586 // Find each variable Var where: | |
| 587 // - Var is actively referenced | |
| 588 // - Var does not have a register | |
| 589 // - Var's furthest ancestor through LinkedTo: Root | |
|
John
2016/07/06 16:07:39
Instead of Root, did you mean Ancestor?
Jim Stichnoth
2016/07/08 10:37:54
After patchset #1, I meant to change "ancestor" an
| |
| 590 // - Root has no active references, or has a register | |
| 591 // | |
| 592 // When any such Var is found, swap Var->LinkedTo and Root->LinkedTo. This | |
| 593 // ensures that when Var needs a stack slot, either its LinkedTo field is | |
| 594 // nullptr, or Var->getLinkedToRoot() returns a variable with a stack slot. | |
| 595 for (Variable *Var : Func->getVariables()) { | |
| 596 if (!IsVarReferenced[Var->getIndex()]) | |
|
John
2016/07/06 16:07:39
It took me a while to understand what this is doin
Jim Stichnoth
2016/07/08 10:37:54
Nice, done.
| |
| 597 continue; | |
| 598 if (Var->hasReg()) | |
| 599 continue; | |
| 600 Variable *Ancestor = Var->getLinkedToRoot(); | |
|
John
2016/07/06 16:07:39
auto?
Jim Stichnoth
2016/07/08 10:37:54
hmm, I think it wouldn't be obvious that getLinked
| |
| 601 if (Ancestor == nullptr) | |
| 602 continue; | |
| 603 assert(Ancestor->getLinkedTo() == nullptr); | |
| 604 if (!Ancestor->hasReg() && IsVarReferenced[Ancestor->getIndex()]) | |
| 605 continue; | |
| 606 Ancestor->setLinkedTo(Var); | |
| 607 Var->setLinkedTo(nullptr); | |
| 608 } | |
| 609 | |
| 586 // If SimpleCoalescing is false, each variable without a register gets its | 610 // If SimpleCoalescing is false, each variable without a register gets its |
| 587 // own unique stack slot, which leads to large stack frames. If | 611 // own unique stack slot, which leads to large stack frames. If |
| 588 // SimpleCoalescing is true, then each "global" variable without a register | 612 // SimpleCoalescing is true, then each "global" variable without a register |
| 589 // gets its own slot, but "local" variable slots are reused across basic | 613 // gets its own slot, but "local" variable slots are reused across basic |
| 590 // blocks. E.g., if A and B are local to block 1 and C is local to block 2, | 614 // blocks. E.g., if A and B are local to block 1 and C is local to block 2, |
| 591 // then C may share a slot with A or B. | 615 // then C may share a slot with A or B. |
| 592 // | 616 // |
| 593 // We cannot coalesce stack slots if this function calls a "returns twice" | 617 // We cannot coalesce stack slots if this function calls a "returns twice" |
| 594 // function. In that case, basic blocks may be revisited, and variables local | 618 // function. In that case, basic blocks may be revisited, and variables local |
| 595 // to those basic blocks are actually live until after the called function | 619 // to those basic blocks are actually live until after the called function |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 903 case TARGET_LOWERING_CLASS_FOR(X): \ | 927 case TARGET_LOWERING_CLASS_FOR(X): \ |
| 904 return ::X::createTargetHeaderLowering(Ctx); | 928 return ::X::createTargetHeaderLowering(Ctx); |
| 905 #include "SZTargets.def" | 929 #include "SZTargets.def" |
| 906 #undef SUBZERO_TARGET | 930 #undef SUBZERO_TARGET |
| 907 } | 931 } |
| 908 } | 932 } |
| 909 | 933 |
| 910 TargetHeaderLowering::~TargetHeaderLowering() = default; | 934 TargetHeaderLowering::~TargetHeaderLowering() = default; |
| 911 | 935 |
| 912 } // end of namespace Ice | 936 } // end of namespace Ice |
| OLD | NEW |