| Index: src/IceTargetLowering.cpp
|
| diff --git a/src/IceTargetLowering.cpp b/src/IceTargetLowering.cpp
|
| index 207a76cbb0c1e060059bc7daed228c334a9ff6fb..f6c2a7810a2b48a7c47bcb63ed4969bb7f52af2b 100644
|
| --- a/src/IceTargetLowering.cpp
|
| +++ b/src/IceTargetLowering.cpp
|
| @@ -564,6 +564,16 @@ void TargetLowering::sortVarsByAlignment(VarList &Dest,
|
| });
|
| }
|
|
|
| +namespace {
|
| +bool mightHaveStackSlot(const Variable *Var, const BitVector &IsVarReferenced) {
|
| + if (!IsVarReferenced[Var->getIndex()])
|
| + return false;
|
| + if (Var->hasReg())
|
| + return false;
|
| + return true;
|
| +}
|
| +} // end of anonymous namespace
|
| +
|
| void TargetLowering::getVarStackSlotParams(
|
| VarList &SortedSpilledVariables, SmallBitVector &RegsUsed,
|
| size_t *GlobalsSize, size_t *SpillAreaSizeBytes,
|
| @@ -583,6 +593,30 @@ void TargetLowering::getVarStackSlotParams(
|
| }
|
| }
|
|
|
| + // Find each variable Var where:
|
| + // - Var is actively referenced
|
| + // - Var does not have a register
|
| + // - Var's furthest ancestor through LinkedTo: Root
|
| + // - Root has no active references, or has a register
|
| + //
|
| + // When any such Var is found, rotate the LinkedTo tree by swapping
|
| + // Var->LinkedTo and Root->LinkedTo. This ensures that when Var needs a stack
|
| + // slot, either its LinkedTo field is nullptr, or Var->getLinkedToRoot()
|
| + // returns a variable with a stack slot.
|
| + for (Variable *Var : Func->getVariables()) {
|
| + if (!mightHaveStackSlot(Var, IsVarReferenced))
|
| + continue;
|
| + if (Variable *Root = Var->getLinkedToRoot()) {
|
| + assert(Root->getLinkedTo() == nullptr);
|
| + if (mightHaveStackSlot(Root, IsVarReferenced)) {
|
| + // Found a "safe" root, no need to rotate the tree.
|
| + continue;
|
| + }
|
| + Var->setLinkedTo(nullptr);
|
| + Root->setLinkedTo(Var);
|
| + }
|
| + }
|
| +
|
| // If SimpleCoalescing is false, each variable without a register gets its
|
| // own unique stack slot, which leads to large stack frames. If
|
| // SimpleCoalescing is true, then each "global" variable without a register
|
|
|