[llvm] [ConstraintSystem] Build constraint rows in sparse form (NFC). (PR #215735)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 01:49:53 PDT 2026


================
@@ -74,22 +87,20 @@ class ConstraintSystem {
   ConstraintSystem(const DenseMap<Value *, unsigned> &Value2Index)
       : NumVariables(Value2Index.size()), Value2Index(Value2Index) {}
 
-  bool addVariableRow(ArrayRef<int64_t> R) {
-    assert(Constraints.empty() || R.size() == NumVariables);
+  /// Add \p R to the system, where \p NumCols is the number of columns of \p R.
+  bool addRow(ArrayRef<Entry> R, size_t NumCols) {
     // If all variable coefficients are 0, the constraint does not provide any
     // usable information.
-    if (all_of(ArrayRef(R).drop_front(1), [](int64_t C) { return C == 0; }))
+    if (isConstantOnly(R))
       return false;
 
-    SmallVector<Entry, 4> NewRow;
-    for (const auto &[Idx, C] : enumerate(R)) {
-      if (C == 0)
-        continue;
-      NewRow.emplace_back(C, Idx);
-    }
-    if (Constraints.empty())
-      NumVariables = R.size();
-    Constraints.push_back(std::move(NewRow));
+    NumVariables = std::max(NumCols, NumVariables);
+    // Only keep non-zero coefficients; in particular drop the entry for the
----------------
fhahn wrote:

Ah yes, here we have a special case while solving. I remvoed the part from the comment above thanks

https://github.com/llvm/llvm-project/pull/215735


More information about the llvm-commits mailing list