Subzero: Completely remove tracking of stack pointer live range. Specifically, if a variable is marked with IgnoreLiveness=true, then: 1. Completely avoid adding any segments to its live range 2. Assert that no one tries to add segments to its live range This is done in part by incorporating Variable::IgnoreLiveness into Liveness::RangeMask. Also, change a functor into a lambda because C++11. BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/1273823003.
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp index 44e9d3e..462cbcb 100644 --- a/src/IceCfgNode.cpp +++ b/src/IceCfgNode.cpp
@@ -667,15 +667,13 @@ std::sort(MapBegin.begin(), MapBegin.end()); std::sort(MapEnd.begin(), MapEnd.end()); // Verify there are no duplicates. - struct ComparePair { - bool operator()(const LiveBeginEndMapEntry &A, - const LiveBeginEndMapEntry &B) { - return A.first == B.first; - } - }; - assert(std::adjacent_find(MapBegin.begin(), MapBegin.end(), ComparePair()) == + auto ComparePair = + [](const LiveBeginEndMapEntry &A, const LiveBeginEndMapEntry &B) { + return A.first == B.first; + }; + assert(std::adjacent_find(MapBegin.begin(), MapBegin.end(), ComparePair) == MapBegin.end()); - assert(std::adjacent_find(MapEnd.begin(), MapEnd.end(), ComparePair()) == + assert(std::adjacent_find(MapEnd.begin(), MapEnd.end(), ComparePair) == MapEnd.end()); LivenessBV LiveInAndOut = LiveIn; @@ -700,21 +698,16 @@ InstNumberT LE = i == i2 ? IEB->second : LastInstNum + 1; Variable *Var = Liveness->getVariable(i, this); - // TODO(stichnot): Push getIgnoreLiveness() into the initialization of - // Liveness::RangeMask so that LiveBegin and LiveEnd never even reference - // such variables. - if (!Var->getIgnoreLiveness()) { - if (LB > LE) { - Var->addLiveRange(FirstInstNum, LE, 1); - Var->addLiveRange(LB, LastInstNum + 1, 1); - // Assert that Var is a global variable by checking that its - // liveness index is less than the number of globals. This - // ensures that the LiveInAndOut[] access is valid. - assert(i < Liveness->getNumGlobalVars()); - LiveInAndOut[i] = false; - } else { - Var->addLiveRange(LB, LE, 1); - } + if (LB > LE) { + Var->addLiveRange(FirstInstNum, LE, 1); + Var->addLiveRange(LB, LastInstNum + 1, 1); + // Assert that Var is a global variable by checking that its + // liveness index is less than the number of globals. This + // ensures that the LiveInAndOut[] access is valid. + assert(i < Liveness->getNumGlobalVars()); + LiveInAndOut[i] = false; + } else { + Var->addLiveRange(LB, LE, 1); } if (i == i1) ++IBB;
diff --git a/src/IceLiveness.cpp b/src/IceLiveness.cpp index a1de893..35e12b7 100644 --- a/src/IceLiveness.cpp +++ b/src/IceLiveness.cpp
@@ -71,8 +71,12 @@ if (IsFullInit) LiveToVarMap.assign(NumGlobals, nullptr); - // Sort each variable into the appropriate LiveToVarMap. Also set - // VarToLiveMap. + // Initialize the bitmask of which variables to track. + RangeMask.resize(NumVars); + RangeMask.set(0, NumVars); // Track all variables by default. + + // Sort each variable into the appropriate LiveToVarMap. Set VarToLiveMap. + // Set RangeMask correctly for each variable. TmpNumGlobals = 0; for (auto I = FirstVar, E = Func->getVariables().end(); I != E; ++I) { Variable *Var = *I; @@ -88,9 +92,20 @@ LiveIndex += NumGlobals; } VarToLiveMap[VarIndex] = LiveIndex; + if (Var->getIgnoreLiveness()) + RangeMask[VarIndex] = false; } assert(TmpNumGlobals == (IsFullInit ? NumGlobals : 0)); + // Fix up RangeMask for variables before FirstVar. + for (auto I = Func->getVariables().begin(); I != FirstVar; ++I) { + Variable *Var = *I; + SizeT VarIndex = Var->getIndex(); + if (Var->getIgnoreLiveness() || + (!IsFullInit && !Var->hasReg() && !Var->getWeight().isInf())) + RangeMask[VarIndex] = false; + } + // Process each node. for (auto I = FirstNode, E = Func->getNodes().end(); I != E; ++I) { LivenessNode &Node = Nodes[(*I)->getIndex()]; @@ -100,17 +115,6 @@ // LiveBegin and LiveEnd are reinitialized before each pass over // the block. } - - // Initialize the bitmask of which variables to track. - RangeMask.resize(NumVars); - RangeMask.set(0, NumVars); - if (!IsFullInit) { - // Reset initial variables that are not pre-colored or infinite-weight. - for (auto I = Func->getVariables().begin(); I != FirstVar; ++I) { - Variable *Var = *I; - RangeMask[Var->getIndex()] = (Var->hasReg() || Var->getWeight().isInf()); - } - } } void Liveness::init() {
diff --git a/src/IceOperand.h b/src/IceOperand.h index 5bf4676..bcb38d0 100644 --- a/src/IceOperand.h +++ b/src/IceOperand.h
@@ -463,6 +463,7 @@ void setLiveRange(const LiveRange &Range) { Live = Range; } void resetLiveRange() { Live.reset(); } void addLiveRange(InstNumberT Start, InstNumberT End, uint32_t WeightDelta) { + assert(!getIgnoreLiveness()); assert(WeightDelta != RegWeight::Inf); Live.addSegment(Start, End); if (Weight.isInf())
diff --git a/src/IceRegAlloc.cpp b/src/IceRegAlloc.cpp index c651ae2..d0dc3fb 100644 --- a/src/IceRegAlloc.cpp +++ b/src/IceRegAlloc.cpp
@@ -178,7 +178,8 @@ if (Inst.isDeleted()) continue; if (const Variable *Var = Inst.getDest()) { - if (Var->hasReg() || Var->getWeight().isInf()) { + if (!Var->getIgnoreLiveness() && + (Var->hasReg() || Var->getWeight().isInf())) { if (LRBegin[Var->getIndex()] == Inst::NumberSentinel) { LRBegin[Var->getIndex()] = Inst.getNumber(); ++NumVars; @@ -190,6 +191,8 @@ SizeT NumVars = Src->getNumVars(); for (SizeT J = 0; J < NumVars; ++J) { const Variable *Var = Src->getVar(J); + if (Var->getIgnoreLiveness()) + continue; if (Var->hasReg() || Var->getWeight().isInf()) LREnd[Var->getIndex()] = Inst.getNumber(); }