Skip to content

Commit 07f93d8

Browse files
author
Zain Jaffal
committed
Recommit "[ConstraintElimination] Change debug output to display variable names."
This reverts commit 02ae7e7. include Value.h in ConstraintSystem.h
1 parent b413b84 commit 07f93d8

File tree

4 files changed

+36
-33
lines changed

4 files changed

+36
-33
lines changed

llvm/include/llvm/Analysis/ConstraintSystem.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ class ConstraintSystem {
3636
// Eliminate constraints from the system using Fourier–Motzkin elimination.
3737
bool eliminateUsingFM();
3838

39-
/// Print the constraints in the system, using x0...xn as variable names.
40-
void dump() const;
41-
4239
/// Returns true if there may be a solution for the constraints in the system.
4340
bool mayHaveSolutionImpl();
4441

42+
/// Get list of variable names from the Value2Index map.
43+
SmallVector<std::string> getVarNamesList() const;
44+
4545
public:
46+
ConstraintSystem() {}
47+
ConstraintSystem(const DenseMap<Value *, unsigned> &Value2Index)
48+
: Value2Index(Value2Index) {}
49+
4650
bool addVariableRow(ArrayRef<int64_t> R) {
4751
assert(Constraints.empty() || R.size() == Constraints.back().size());
4852
// If all variable coefficients are 0, the constraint does not provide any
@@ -103,8 +107,8 @@ class ConstraintSystem {
103107
/// Returns the number of rows in the constraint system.
104108
unsigned size() const { return Constraints.size(); }
105109

106-
/// Print the constraints in the system, using \p Names as variable names.
107-
void dump(ArrayRef<std::string> Names) const;
110+
/// Print the constraints in the system.
111+
void dump() const;
108112
};
109113
} // namespace llvm
110114

llvm/lib/Analysis/ConstraintSystem.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "llvm/ADT/SmallVector.h"
1111
#include "llvm/Support/MathExtras.h"
1212
#include "llvm/ADT/StringExtras.h"
13+
#include "llvm/IR/Value.h"
1314
#include "llvm/Support/Debug.h"
1415

1516
#include <string>
@@ -111,10 +112,23 @@ bool ConstraintSystem::mayHaveSolutionImpl() {
111112
return all_of(Constraints, [](auto &R) { return R[0] >= 0; });
112113
}
113114

114-
void ConstraintSystem::dump(ArrayRef<std::string> Names) const {
115+
SmallVector<std::string> ConstraintSystem::getVarNamesList() const {
116+
SmallVector<std::string> Names(Value2Index.size(), "");
117+
for (auto &[V, Index] : Value2Index) {
118+
std::string OperandName;
119+
if (V->getName().empty())
120+
OperandName = V->getNameOrAsOperand();
121+
else
122+
OperandName = std::string("%") + V->getName().str();
123+
Names[Index - 1] = OperandName;
124+
}
125+
return Names;
126+
}
127+
128+
void ConstraintSystem::dump() const {
115129
if (Constraints.empty())
116130
return;
117-
131+
SmallVector<std::string> Names = getVarNamesList();
118132
for (const auto &Row : Constraints) {
119133
SmallVector<std::string, 16> Parts;
120134
for (unsigned I = 1, S = Row.size(); I < S; ++I) {
@@ -131,15 +145,8 @@ void ConstraintSystem::dump(ArrayRef<std::string> Names) const {
131145
}
132146
}
133147

134-
void ConstraintSystem::dump() const {
135-
SmallVector<std::string, 16> Names;
136-
for (unsigned i = 1; i < Constraints.back().size(); ++i)
137-
Names.push_back("x" + std::to_string(i));
138-
LLVM_DEBUG(dbgs() << "---\n");
139-
dump(Names);
140-
}
141-
142148
bool ConstraintSystem::mayHaveSolution() {
149+
LLVM_DEBUG(dbgs() << "---\n");
143150
LLVM_DEBUG(dump());
144151
bool HasSolution = mayHaveSolutionImpl();
145152
LLVM_DEBUG(dbgs() << (HasSolution ? "sat" : "unsat") << "\n");

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -644,20 +644,12 @@ struct State {
644644
} // namespace
645645

646646
#ifndef NDEBUG
647-
static void dumpWithNames(const ConstraintSystem &CS,
648-
DenseMap<Value *, unsigned> &Value2Index) {
649-
SmallVector<std::string> Names(Value2Index.size(), "");
650-
for (auto &KV : Value2Index) {
651-
Names[KV.second - 1] = std::string("%") + KV.first->getName().str();
652-
}
653-
CS.dump(Names);
654-
}
655647

656-
static void dumpWithNames(ArrayRef<int64_t> C,
657-
DenseMap<Value *, unsigned> &Value2Index) {
658-
ConstraintSystem CS;
648+
static void dumpConstraint(ArrayRef<int64_t> C,
649+
const DenseMap<Value *, unsigned> &Value2Index) {
650+
ConstraintSystem CS(Value2Index);
659651
CS.addVariableRowFill(C);
660-
dumpWithNames(CS, Value2Index);
652+
CS.dump();
661653
}
662654
#endif
663655

@@ -941,7 +933,7 @@ static bool checkAndReplaceCondition(
941933

942934
LLVM_DEBUG({
943935
dbgs() << "Condition " << *Cmp << " implied by dominating constraints\n";
944-
dumpWithNames(CSToUse, Info.getValue2Index(R.IsSigned));
936+
CSToUse.dump();
945937
});
946938
generateReproducer(Cmp, ReproducerModule, ReproducerCondStack, Info, DT);
947939
Constant *TrueC =
@@ -961,7 +953,7 @@ static bool checkAndReplaceCondition(
961953

962954
LLVM_DEBUG({
963955
dbgs() << "Condition !" << *Cmp << " implied by dominating constraints\n";
964-
dumpWithNames(CSToUse, Info.getValue2Index(R.IsSigned));
956+
CSToUse.dump();
965957
});
966958
generateReproducer(Cmp, ReproducerModule, ReproducerCondStack, Info, DT);
967959
Constant *FalseC =
@@ -1005,7 +997,7 @@ void ConstraintInfo::addFact(CmpInst::Predicate Pred, Value *A, Value *B,
1005997

1006998
LLVM_DEBUG({
1007999
dbgs() << " constraint: ";
1008-
dumpWithNames(R.Coefficients, getValue2Index(R.IsSigned));
1000+
dumpConstraint(R.Coefficients, getValue2Index(R.IsSigned));
10091001
dbgs() << "\n";
10101002
});
10111003

@@ -1150,8 +1142,8 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT,
11501142
break;
11511143
LLVM_DEBUG({
11521144
dbgs() << "Removing ";
1153-
dumpWithNames(Info.getCS(E.IsSigned).getLastConstraint(),
1154-
Info.getValue2Index(E.IsSigned));
1145+
dumpConstraint(Info.getCS(E.IsSigned).getLastConstraint(),
1146+
Info.getValue2Index(E.IsSigned));
11551147
dbgs() << "\n";
11561148
});
11571149

llvm/test/Transforms/ConstraintElimination/reproducer-remarks-debug.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
66

77
; CHECK: Condition %c.2 = icmp eq ptr %a, null implied by dominating constraints
8-
; CHECK-NEXT: %a + -1 * % <= 0
8+
; CHECK-NEXT: %a + -1 * null <= 0
99
; CHECK-NEXT: Creating reproducer for %c.2 = icmp eq ptr %a, null
1010
; CHECK-NEXT: found external input ptr %a
1111
; CHECK-NEXT: Materializing assumption %c.1 = icmp eq ptr %a, null

0 commit comments

Comments
 (0)