[ConstraintElimination] Remove unneeded StackEntry::Condition (NFC).

The field was only used for debug printing. Print constraint from the
system instead.
This commit is contained in:
Florian Hahn 2022-06-21 15:55:30 +02:00
parent 6a4056ab2a
commit 4ea6891f95
No known key found for this signature in database
GPG Key ID: CF59919C6547A668
2 changed files with 29 additions and 21 deletions

View File

@ -79,6 +79,7 @@ public:
bool isConditionImplied(SmallVector<int64_t, 8> R) const;
ArrayRef<int64_t> getLastConstraint() { return Constraints[0]; }
void popLastConstraint() { Constraints.pop_back(); }
void popLastNVariables(unsigned N) {
for (auto &C : Constraints) {

View File

@ -52,17 +52,16 @@ class ConstraintInfo;
struct StackEntry {
unsigned NumIn;
unsigned NumOut;
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, CmpInst *Condition, bool IsNot,
bool IsSigned, SmallVector<Value *, 2> ValuesToRelease)
: NumIn(NumIn), NumOut(NumOut), Condition(Condition), IsNot(IsNot),
IsSigned(IsSigned), ValuesToRelease(ValuesToRelease) {}
StackEntry(unsigned NumIn, unsigned NumOut, bool IsNot, bool IsSigned,
SmallVector<Value *, 2> ValuesToRelease)
: NumIn(NumIn), NumOut(NumOut), IsNot(IsNot), IsSigned(IsSigned),
ValuesToRelease(ValuesToRelease) {}
};
/// Struct to express a pre-condition of the form %Op0 Pred %Op1.
@ -435,16 +434,21 @@ struct State {
} // namespace
#ifndef NDEBUG
static void dumpWithNames(ConstraintTy &C,
static void dumpWithNames(const ConstraintSystem &CS,
DenseMap<Value *, unsigned> &Value2Index) {
SmallVector<std::string> Names(Value2Index.size(), "");
for (auto &KV : Value2Index) {
Names[KV.second - 1] = std::string("%") + KV.first->getName().str();
}
ConstraintSystem CS;
CS.addVariableRowFill(C.Coefficients);
CS.dump(Names);
}
static void dumpWithNames(ArrayRef<int64_t> C,
DenseMap<Value *, unsigned> &Value2Index) {
ConstraintSystem CS;
CS.addVariableRowFill(C);
dumpWithNames(CS, Value2Index);
}
#endif
void State::addInfoFor(BasicBlock &BB) {
@ -553,10 +557,10 @@ void ConstraintInfo::addFact(CmpInst *Condition, bool IsNegated, unsigned NumIn,
LLVM_DEBUG({
dbgs() << " constraint: ";
dumpWithNames(R, getValue2Index(R.IsSigned));
dumpWithNames(R.Coefficients, getValue2Index(R.IsSigned));
});
DFSInStack.emplace_back(NumIn, NumOut, Condition, IsNegated, R.IsSigned,
DFSInStack.emplace_back(NumIn, NumOut, IsNegated, R.IsSigned,
ValuesToRelease);
if (R.IsEq) {
@ -565,7 +569,7 @@ void ConstraintInfo::addFact(CmpInst *Condition, bool IsNegated, unsigned NumIn,
Coeff *= -1;
CSToUse.addVariableRowFill(R.Coefficients);
DFSInStack.emplace_back(NumIn, NumOut, Condition, IsNegated, R.IsSigned,
DFSInStack.emplace_back(NumIn, NumOut, IsNegated, R.IsSigned,
SmallVector<Value *, 2>());
}
}
@ -657,8 +661,13 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
assert(E.NumIn <= CB.NumIn);
if (CB.NumOut <= E.NumOut)
break;
LLVM_DEBUG(dbgs() << "Removing " << *E.Condition << " " << E.IsNot
<< "\n");
LLVM_DEBUG({
dbgs() << "Removing ";
dumpWithNames(Info.getCS(E.IsSigned).getLastConstraint(),
Info.getValue2Index(E.IsSigned));
dbgs() << "\n";
});
Info.popLastConstraint(E.IsSigned);
// Remove variables in the system that went out of scope.
auto &Mapping = Info.getValue2Index(E.IsSigned);
@ -700,11 +709,10 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
if (!DebugCounter::shouldExecute(EliminatedCounter))
continue;
LLVM_DEBUG(dbgs() << "Condition " << *Cmp
<< " implied by dominating constraints\n");
LLVM_DEBUG({
for (auto &E : reverse(DFSInStack))
dbgs() << " C " << *E.Condition << " " << E.IsNot << "\n";
dbgs() << "Condition " << *Cmp
<< " implied by dominating constraints\n";
dumpWithNames(CSToUse, Info.getValue2Index(R.IsSigned));
});
Cmp->replaceUsesWithIf(
ConstantInt::getTrue(F.getParent()->getContext()), [](Use &U) {
@ -721,11 +729,10 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
if (!DebugCounter::shouldExecute(EliminatedCounter))
continue;
LLVM_DEBUG(dbgs() << "Condition !" << *Cmp
<< " implied by dominating constraints\n");
LLVM_DEBUG({
for (auto &E : reverse(DFSInStack))
dbgs() << " C " << *E.Condition << " " << E.IsNot << "\n";
dbgs() << "Condition !" << *Cmp
<< " implied by dominating constraints\n";
dumpWithNames(CSToUse, Info.getValue2Index(R.IsSigned));
});
Cmp->replaceAllUsesWith(
ConstantInt::getFalse(F.getParent()->getContext()));