[llvm] 3e09bc2 - [ConstraintElimination] Add nicer way to dump constraints (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 08:37:29 PST 2021


Author: Florian Hahn
Date: 2021-02-02T16:36:45Z
New Revision: 3e09bc250044fc3d294cba23c8d797e12f30581d

URL: https://github.com/llvm/llvm-project/commit/3e09bc250044fc3d294cba23c8d797e12f30581d
DIFF: https://github.com/llvm/llvm-project/commit/3e09bc250044fc3d294cba23c8d797e12f30581d.diff

LOG: [ConstraintElimination] Add nicer way to dump constraints (NFC).

Use ConstraintSystem::dump(Names) to display the result of decomposing a
condition.

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 83c1fb4485fd..d5b8f208172b 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<std::string> Names) const;
-
   /// Print the constraints in the system, using x0...xn as variable names.
   void dump() const;
 
@@ -82,6 +79,9 @@ class ConstraintSystem {
 
   /// 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<std::string> Names) const;
 };
 } // namespace llvm
 

diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 84c3ec98b029..f190ddc29a9b 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 <string>
+
 using namespace llvm;
 using namespace PatternMatch;
 
@@ -214,6 +216,17 @@ struct StackEntry {
 };
 } // namespace
 
+static void dumpWithNames(ConstraintTy &C,
+                          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 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.


        


More information about the llvm-commits mailing list