[Mlir-commits] [mlir] [MLIR][Presburger] Make printing aligned to assist in debugging (PR #107648)
Amy Wang
llvmlistbot at llvm.org
Wed Sep 11 16:47:04 PDT 2024
================
@@ -292,6 +294,48 @@ std::vector<Fraction> multiplyPolynomials(ArrayRef<Fraction> a,
bool isRangeZero(ArrayRef<Fraction> arr);
+struct PrintTableMetrics {
+ // If unknown, set to 0 and pass the struct into updatePrintMetrics.
+ unsigned maxPreIndent;
+ unsigned maxPostIndent;
+ // The substring expected prior to alignment.
+ std::string preAlign;
+};
+
+// Updates 'm' given a table entry val. Iterate over each val in the table
+// with .maxPreIndent and .maxPostIndent initialized to 0.
+// class T is any type that can be handled by llvm::raw_string_ostream.
+template <class T>
+void updatePrintMetrics(T val, PrintTableMetrics &m) {
+ std::string str;
+ llvm::raw_string_ostream(str) << val;
+ if (str.length() == 0)
+ return;
+ unsigned int preIndent = str.find(m.preAlign);
+ preIndent = (preIndent != std::string::npos) ? preIndent + 1 : 0;
+ m.maxPreIndent = std::max(m.maxPreIndent, preIndent);
+ m.maxPostIndent =
+ std::max(m.maxPostIndent, (unsigned int)(str.length() - preIndent));
+}
+
+// Print val in the table with metrics specified in 'm'.
+template <class T>
+void printWithPrintMetrics(raw_ostream &os, T val, unsigned minSpacing,
+ const PrintTableMetrics &m) {
+ std::string str;
+ llvm::raw_string_ostream(str) << val;
+ unsigned preIndent;
+ if (str.length() != 0) {
+ preIndent = str.find(m.preAlign);
+ preIndent = (preIndent != std::string::npos) ? preIndent + 1 : 0;
+ } else
+ preIndent = 0;
+ for (unsigned i = 0; i < (minSpacing + m.maxPreIndent - preIndent); ++i)
----------------
kaitingwang wrote:
Fixed as suggested.
https://github.com/llvm/llvm-project/pull/107648
More information about the Mlir-commits
mailing list