From 3e09bc250044fc3d294cba23c8d797e12f30581d Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Tue, 2 Feb 2021 15:27:58 +0000 Subject: [PATCH] [ConstraintElimination] Add nicer way to dump constraints (NFC). Use ConstraintSystem::dump(Names) to display the result of decomposing a condition. --- llvm/include/llvm/Analysis/ConstraintSystem.h | 6 +++--- llvm/lib/Transforms/Scalar/ConstraintElimination.cpp | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/Analysis/ConstraintSystem.h b/llvm/include/llvm/Analysis/ConstraintSystem.h index 83c1fb4..d5b8f20 100644 --- a/llvm/include/llvm/Analysis/ConstraintSystem.h +++ b/llvm/include/llvm/Analysis/ConstraintSystem.h @@ -30,9 +30,6 @@ class ConstraintSystem { // Eliminate constraints from the system using Fourier–Motzkin elimination. bool eliminateUsingFM(); - /// Print the constraints in the system, using \p Names as variable names. - void dump(ArrayRef Names) const; - /// Print the constraints in the system, using x0...xn as variable names. void dump() const; @@ -82,6 +79,9 @@ public: /// Returns the number of rows in the constraint system. unsigned size() const { return Constraints.size(); } + + /// Print the constraints in the system, using \p Names as variable names. + void dump(ArrayRef Names) const; }; } // namespace llvm diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index 84c3ec9..f190ddc 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -29,6 +29,8 @@ #include "llvm/Support/DebugCounter.h" #include "llvm/Transforms/Scalar.h" +#include + using namespace llvm; using namespace PatternMatch; @@ -214,6 +216,17 @@ struct StackEntry { }; } // namespace +static void dumpWithNames(ConstraintTy &C, + DenseMap &Value2Index) { + SmallVector 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 bool eliminateConstraints(Function &F, DominatorTree &DT) { bool Changed = false; DT.updateDFSNumbers(); @@ -380,7 +393,10 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) { bool Added = false; for (auto &C : R) { auto Coeffs = C.Coefficients; - + LLVM_DEBUG({ + dbgs() << " constraint: "; + dumpWithNames(C, Value2Index); + }); Added |= CS.addVariableRowFill(Coeffs); // If R has been added to the system, queue it for removal once it goes // out-of-scope. -- 2.7.4