[llvm] 62d0e1a - Revert "[ConstraintElimination] Change debug output to display variable names."
Zain Jaffal via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 15 07:22:14 PST 2023
Author: Zain Jaffal
Date: 2023-02-15T15:21:46Z
New Revision: 62d0e1a8541f93dfbf66d982f66da32676df2df7
URL: https://github.com/llvm/llvm-project/commit/62d0e1a8541f93dfbf66d982f66da32676df2df7
DIFF: https://github.com/llvm/llvm-project/commit/62d0e1a8541f93dfbf66d982f66da32676df2df7.diff
LOG: Revert "[ConstraintElimination] Change debug output to display variable names."
This reverts commit 869c87ad10e87db7c032c3464338ab9d50916510.
`dumpWithNames` function should be removed
Added:
Modified:
llvm/include/llvm/Analysis/ConstraintSystem.h
llvm/lib/Analysis/ConstraintSystem.cpp
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ConstraintSystem.h b/llvm/include/llvm/Analysis/ConstraintSystem.h
index 14eab748d965a..e348b38f152ab 100644
--- a/llvm/include/llvm/Analysis/ConstraintSystem.h
+++ b/llvm/include/llvm/Analysis/ConstraintSystem.h
@@ -36,17 +36,13 @@ class ConstraintSystem {
// Eliminate constraints from the system using Fourier–Motzkin elimination.
bool eliminateUsingFM();
+ /// Print the constraints in the system, using x0...xn as variable names.
+ void dump() const;
+
/// Returns true if there may be a solution for the constraints in the system.
bool mayHaveSolutionImpl();
- /// Get list of variable names from the Value2Index map.
- SmallVector<std::string> getVarNamesList() const;
-
public:
- ConstraintSystem() {}
- ConstraintSystem(const DenseMap<Value *, unsigned> &Value2Index)
- : Value2Index(Value2Index) {}
-
bool addVariableRow(ArrayRef<int64_t> R) {
assert(Constraints.empty() || R.size() == Constraints.back().size());
// If all variable coefficients are 0, the constraint does not provide any
@@ -107,8 +103,8 @@ class ConstraintSystem {
/// Returns the number of rows in the constraint system.
unsigned size() const { return Constraints.size(); }
- /// Print the constraints in the system.
- void dump() const;
+ /// Print the constraints in the system, using \p Names as variable names.
+ void dump(ArrayRef<std::string> Names) const;
};
} // namespace llvm
diff --git a/llvm/lib/Analysis/ConstraintSystem.cpp b/llvm/lib/Analysis/ConstraintSystem.cpp
index 6e9be8745ebb3..fd96c61e9a94c 100644
--- a/llvm/lib/Analysis/ConstraintSystem.cpp
+++ b/llvm/lib/Analysis/ConstraintSystem.cpp
@@ -111,23 +111,10 @@ bool ConstraintSystem::mayHaveSolutionImpl() {
return all_of(Constraints, [](auto &R) { return R[0] >= 0; });
}
-SmallVector<std::string> ConstraintSystem::getVarNamesList() const {
- SmallVector<std::string> Names(Value2Index.size(), "");
- for (auto &[V, Index] : Value2Index) {
- std::string OperandName;
- if (V->getName().empty())
- OperandName = V->getNameOrAsOperand();
- else
- OperandName = std::string("%") + V->getName().str();
- Names[Index - 1] = OperandName;
- }
- return Names;
-}
-
-void ConstraintSystem::dump() const {
+void ConstraintSystem::dump(ArrayRef<std::string> Names) const {
if (Constraints.empty())
return;
- SmallVector<std::string> Names = getVarNamesList();
+
for (const auto &Row : Constraints) {
SmallVector<std::string, 16> Parts;
for (unsigned I = 1, S = Row.size(); I < S; ++I) {
@@ -144,6 +131,14 @@ void ConstraintSystem::dump() const {
}
}
+void ConstraintSystem::dump() const {
+ SmallVector<std::string, 16> Names;
+ for (unsigned i = 1; i < Constraints.back().size(); ++i)
+ Names.push_back("x" + std::to_string(i));
+ LLVM_DEBUG(dbgs() << "---\n");
+ dump(Names);
+}
+
bool ConstraintSystem::mayHaveSolution() {
LLVM_DEBUG(dump());
bool HasSolution = mayHaveSolutionImpl();
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 46b046127020a..4ec3a58f52584 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -644,12 +644,20 @@ struct State {
} // namespace
#ifndef NDEBUG
+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();
+ }
+ CS.dump(Names);
+}
-static void dumpConstraint(ArrayRef<int64_t> C,
- const DenseMap<Value *, unsigned> &Value2Index) {
- ConstraintSystem CS(Value2Index);
+static void dumpWithNames(ArrayRef<int64_t> C,
+ DenseMap<Value *, unsigned> &Value2Index) {
+ ConstraintSystem CS;
CS.addVariableRowFill(C);
- CS.dump();
+ dumpWithNames(CS, Value2Index);
}
#endif
@@ -997,7 +1005,7 @@ void ConstraintInfo::addFact(CmpInst::Predicate Pred, Value *A, Value *B,
LLVM_DEBUG({
dbgs() << " constraint: ";
- dumpConstraint(R.Coefficients, getValue2Index(R.IsSigned));
+ dumpWithNames(R.Coefficients, getValue2Index(R.IsSigned));
dbgs() << "\n";
});
@@ -1142,8 +1150,8 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT,
break;
LLVM_DEBUG({
dbgs() << "Removing ";
- dumpConstraint(Info.getCS(E.IsSigned).getLastConstraint(),
- Info.getValue2Index(E.IsSigned));
+ dumpWithNames(Info.getCS(E.IsSigned).getLastConstraint(),
+ Info.getValue2Index(E.IsSigned));
dbgs() << "\n";
});
More information about the llvm-commits
mailing list