[llvm] 4ea6891 - [ConstraintElimination] Remove unneeded StackEntry::Condition (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 21 06:57:49 PDT 2022
Author: Florian Hahn
Date: 2022-06-21T15:57:29+02:00
New Revision: 4ea6891f95a878af869e01425a69099a5e48e4c6
URL: https://github.com/llvm/llvm-project/commit/4ea6891f95a878af869e01425a69099a5e48e4c6
DIFF: https://github.com/llvm/llvm-project/commit/4ea6891f95a878af869e01425a69099a5e48e4c6.diff
LOG: [ConstraintElimination] Remove unneeded StackEntry::Condition (NFC).
The field was only used for debug printing. Print constraint from the
system instead.
Added:
Modified:
llvm/include/llvm/Analysis/ConstraintSystem.h
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ConstraintSystem.h b/llvm/include/llvm/Analysis/ConstraintSystem.h
index eab35b7a5923e..2c83658b81dcc 100644
--- a/llvm/include/llvm/Analysis/ConstraintSystem.h
+++ b/llvm/include/llvm/Analysis/ConstraintSystem.h
@@ -79,6 +79,7 @@ class ConstraintSystem {
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) {
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 9a574fa1eb24b..31c55b5244c99 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -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()));
More information about the llvm-commits
mailing list