}
bool addVariableRowFill(ArrayRef<int64_t> R) {
+ // If all variable coefficients are 0, the constraint does not provide any
+ // usable information.
+ if (all_of(makeArrayRef(R).drop_front(1), [](int64_t C) { return C == 0; }))
+ return false;
+
for (auto &CR : Constraints) {
while (CR.size() != R.size())
CR.push_back(0);
bool isConditionImplied(SmallVector<int64_t, 8> R) const;
void popLastConstraint() { Constraints.pop_back(); }
+ void popLastNVariables(unsigned N) {
+ for (auto &C : Constraints) {
+ for (unsigned i = 0; i < N; i++)
+ C.pop_back();
+ }
+ }
/// Returns the number of rows in the constraint system.
unsigned size() const { return Constraints.size(); }
}
void popLastConstraint(bool Signed) { getCS(Signed).popLastConstraint(); }
+ void popLastNVariables(bool Signed, unsigned N) {
+ getCS(Signed).popLastNVariables(N);
+ }
};
/// Struct to express a pre-condition of the form %Op0 Pred %Op1.
Instruction *Condition;
bool IsNot;
bool IsSigned = false;
+ /// Variables that can be removed from the system once the stack entry gets
+ /// removed.
+ SmallVector<Value *, 2> ValuesToRelease;
- StackEntry(unsigned NumIn, unsigned NumOut, Instruction *Condition,
- bool IsNot, bool IsSigned)
+ StackEntry(unsigned NumIn, unsigned NumOut, CmpInst *Condition, bool IsNot,
+ bool IsSigned, SmallVector<Value *, 2> ValuesToRelease)
: NumIn(NumIn), NumOut(NumOut), Condition(Condition), IsNot(IsNot),
- IsSigned(IsSigned) {}
+ IsSigned(IsSigned), ValuesToRelease(ValuesToRelease) {}
};
} // namespace
break;
LLVM_DEBUG(dbgs() << "Removing " << *E.Condition << " " << E.IsNot
<< "\n");
- DFSInStack.pop_back();
Info.popLastConstraint(E.IsSigned);
+ // Remove variables in the system that went out of scope.
+ auto &Mapping = Info.getValue2Index(E.IsSigned);
+ for (Value *V : E.ValuesToRelease)
+ Mapping.erase(V);
+ Info.popLastNVariables(E.IsSigned, E.ValuesToRelease.size());
+ DFSInStack.pop_back();
}
LLVM_DEBUG({
if (!R.isValid(Info))
continue;
- for (auto &KV : NewIndices)
- Info.getValue2Index(CmpInst::isSigned(CB.Condition->getPredicate()))
- .insert(KV);
-
LLVM_DEBUG(dbgs() << "Adding " << *CB.Condition << " " << CB.Not << "\n");
bool Added = false;
assert(CmpInst::isSigned(CB.Condition->getPredicate()) == R.IsSigned &&
// If R has been added to the system, queue it for removal once it goes
// out-of-scope.
if (Added) {
- for (auto &KV : NewIndices)
+ SmallVector<Value *, 2> ValuesToRelease;
+ for (auto &KV : NewIndices) {
Info.getValue2Index(R.IsSigned).insert(KV);
+ ValuesToRelease.push_back(KV.first);
+ }
LLVM_DEBUG({
dbgs() << " constraint: ";
});
DFSInStack.emplace_back(CB.NumIn, CB.NumOut, CB.Condition, CB.Not,
- R.IsSigned);
+ R.IsSigned, ValuesToRelease);
if (R.IsEq) {
// Also add the inverted constraint for equality constraints.
CSToUse.addVariableRowFill(R.Coefficients);
DFSInStack.emplace_back(CB.NumIn, CB.NumOut, CB.Condition, CB.Not,
- R.IsSigned);
+ R.IsSigned, SmallVector<Value *, 2>());
}
}
}