[Mlir-commits] [mlir] Implement `insertVar` having `Identifier` parameter (PR #76993)

Zain Jaffal llvmlistbot at llvm.org
Thu Jan 4 11:54:34 PST 2024


https://github.com/zjaffal created https://github.com/llvm/llvm-project/pull/76993

None

>From c05022b29208df53ebefae435765652b86b251fe Mon Sep 17 00:00:00 2001
From: Zain Jaffal <zain at jjaffal.com>
Date: Thu, 4 Jan 2024 10:36:21 +0000
Subject: [PATCH] Implement `insertVar` having `Identifier` parameter

---
 .../mlir/Analysis/FlatLinearValueConstraints.h        |  5 +++--
 .../mlir/Analysis/Presburger/IntegerRelation.h        |  6 ++++--
 .../mlir/Analysis/Presburger/PresburgerRelation.h     |  3 ++-
 .../mlir/Analysis/Presburger/PresburgerSpace.h        |  6 ++----
 mlir/lib/Analysis/FlatLinearValueConstraints.cpp      |  5 +++--
 mlir/lib/Analysis/Presburger/IntegerRelation.cpp      | 11 ++++++-----
 mlir/lib/Analysis/Presburger/PresburgerRelation.cpp   |  6 +++---
 mlir/lib/Analysis/Presburger/PresburgerSpace.cpp      |  7 ++++---
 8 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/mlir/include/mlir/Analysis/FlatLinearValueConstraints.h b/mlir/include/mlir/Analysis/FlatLinearValueConstraints.h
index e4de5b0661571c..2458ef3004b8f2 100644
--- a/mlir/include/mlir/Analysis/FlatLinearValueConstraints.h
+++ b/mlir/include/mlir/Analysis/FlatLinearValueConstraints.h
@@ -346,8 +346,9 @@ class FlatLinearValueConstraints : public FlatLinearConstraints {
   unsigned insertSymbolVar(unsigned pos, ValueRange vals);
   using FlatLinearConstraints::insertSymbolVar;
 
-  unsigned insertVar(presburger::VarKind kind, unsigned pos,
-                     unsigned num = 1) override;
+  unsigned
+  insertVar(presburger::VarKind kind, unsigned pos, unsigned num = 1,
+            presburger::Identifier id = presburger::Identifier()) override;
   unsigned insertVar(presburger::VarKind kind, unsigned pos, ValueRange vals);
 
   /// Removes variables in the column range [varStart, varLimit), and copies any
diff --git a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
index 4c6b810f92e95a..aa96dfb3eaf99b 100644
--- a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
+++ b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
@@ -275,7 +275,8 @@ class IntegerRelation {
   /// corresponding to the added variables are initialized to zero. Return the
   /// absolute column position (i.e., not relative to the kind of variable)
   /// of the first added variable.
-  virtual unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1);
+  virtual unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1,
+                             Identifier id = Identifier());
 
   /// Append `num` variables of the specified kind after the last variable
   /// of that kind. The coefficient columns corresponding to the added variables
@@ -895,7 +896,8 @@ class IntegerPolyhedron : public IntegerRelation {
   /// Positions are relative to the kind of variable. Return the absolute
   /// column position (i.e., not relative to the kind of variable) of the
   /// first added variable.
-  unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1) override;
+  unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1,
+                     Identifier id = Identifier()) override;
 
   /// Return the intersection of the two relations.
   /// If there are locals, they will be merged.
diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
index c6b00eca90733a..e21f37ed867d8b 100644
--- a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
+++ b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
@@ -64,7 +64,8 @@ class PresburgerRelation {
   /// exceeds that of some disjunct, an assert failure will occur.
   void setSpace(const PresburgerSpace &oSpace);
 
-  void insertVarInPlace(VarKind kind, unsigned pos, unsigned num = 1);
+  void insertVarInPlace(VarKind kind, unsigned pos, unsigned num = 1,
+                        Identifier id = Identifier());
 
   /// Converts variables of the specified kind in the column range [srcPos,
   /// srcPos + num) to variables of the specified kind at position dstPos. The
diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
index 9fe2abafd36bad..0a9daed8762ef3 100644
--- a/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
+++ b/mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
@@ -215,10 +215,8 @@ class PresburgerSpace {
   /// Positions are relative to the kind of variable. Return the absolute
   /// column position (i.e., not relative to the kind of variable) of the
   /// first added variable.
-  ///
-  /// If identifiers are being used, the newly added variables have no
-  /// identifiers.
-  unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1);
+  unsigned insertVar(VarKind kind, unsigned pos, unsigned num = 1,
+                     Identifier id = Identifier());
 
   /// Removes variables of the specified kind in the column range [varStart,
   /// varLimit). The range is relative to the kind of variable.
diff --git a/mlir/lib/Analysis/FlatLinearValueConstraints.cpp b/mlir/lib/Analysis/FlatLinearValueConstraints.cpp
index 69846a356e0cc4..b1a81dd83ddfd0 100644
--- a/mlir/lib/Analysis/FlatLinearValueConstraints.cpp
+++ b/mlir/lib/Analysis/FlatLinearValueConstraints.cpp
@@ -9,6 +9,7 @@
 #include "mlir/Analysis//FlatLinearValueConstraints.h"
 
 #include "mlir/Analysis/Presburger/LinearTransform.h"
+#include "mlir/Analysis/Presburger/PresburgerSpace.h"
 #include "mlir/Analysis/Presburger/Simplex.h"
 #include "mlir/Analysis/Presburger/Utils.h"
 #include "mlir/IR/AffineExprVisitor.h"
@@ -870,8 +871,8 @@ unsigned FlatLinearValueConstraints::insertSymbolVar(unsigned pos,
 }
 
 unsigned FlatLinearValueConstraints::insertVar(VarKind kind, unsigned pos,
-                                               unsigned num) {
-  unsigned absolutePos = IntegerPolyhedron::insertVar(kind, pos, num);
+                                               unsigned num, Identifier id) {
+  unsigned absolutePos = IntegerPolyhedron::insertVar(kind, pos, num, id);
 
   if (kind != VarKind::Local) {
     values.insert(values.begin() + absolutePos, num, std::nullopt);
diff --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
index 0109384f1689dd..28b368ece33afe 100644
--- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
@@ -334,10 +334,11 @@ IntegerRelation::subtract(const PresburgerRelation &set) const {
   return PresburgerRelation(*this).subtract(set);
 }
 
-unsigned IntegerRelation::insertVar(VarKind kind, unsigned pos, unsigned num) {
+unsigned IntegerRelation::insertVar(VarKind kind, unsigned pos, unsigned num,
+                                    Identifier id) {
   assert(pos <= getNumVarKind(kind));
 
-  unsigned insertPos = space.insertVar(kind, pos, num);
+  unsigned insertPos = space.insertVar(kind, pos, num, id);
   inequalities.insertColumns(insertPos, num);
   equalities.insertColumns(insertPos, num);
   return insertPos;
@@ -2478,11 +2479,11 @@ void IntegerRelation::print(raw_ostream &os) const {
 
 void IntegerRelation::dump() const { print(llvm::errs()); }
 
-unsigned IntegerPolyhedron::insertVar(VarKind kind, unsigned pos,
-                                      unsigned num) {
+unsigned IntegerPolyhedron::insertVar(VarKind kind, unsigned pos, unsigned num,
+                                      Identifier id) {
   assert((kind != VarKind::Domain || num == 0) &&
          "Domain has to be zero in a set");
-  return IntegerRelation::insertVar(kind, pos, num);
+  return IntegerRelation::insertVar(kind, pos, num, id);
 }
 IntegerPolyhedron
 IntegerPolyhedron::intersect(const IntegerPolyhedron &other) const {
diff --git a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
index 787fc1c659a12e..d04dd9eecb5f60 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
@@ -41,10 +41,10 @@ void PresburgerRelation::setSpace(const PresburgerSpace &oSpace) {
 }
 
 void PresburgerRelation::insertVarInPlace(VarKind kind, unsigned pos,
-                                          unsigned num) {
+                                          unsigned num, Identifier id) {
   for (IntegerRelation &cs : disjuncts)
-    cs.insertVar(kind, pos, num);
-  space.insertVar(kind, pos, num);
+    cs.insertVar(kind, pos, num, id);
+  space.insertVar(kind, pos, num, id);
 }
 
 void PresburgerRelation::convertVarKind(VarKind srcKind, unsigned srcPos,
diff --git a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
index cf1b3befbc89f8..946d53a28a400d 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
@@ -108,7 +108,8 @@ VarKind PresburgerSpace::getVarKindAt(unsigned pos) const {
   llvm_unreachable("`pos` should represent a valid var position");
 }
 
-unsigned PresburgerSpace::insertVar(VarKind kind, unsigned pos, unsigned num) {
+unsigned PresburgerSpace::insertVar(VarKind kind, unsigned pos, unsigned num,
+                                    Identifier id) {
   assert(pos <= getNumVarKind(kind));
 
   unsigned absolutePos = getVarKindOffset(kind) + pos;
@@ -122,10 +123,10 @@ unsigned PresburgerSpace::insertVar(VarKind kind, unsigned pos, unsigned num) {
   else
     numLocals += num;
 
-  // Insert NULL identifiers if `usingIds` and variables inserted are
+  // Insert id identifiers if `usingIds` and variables inserted are
   // not locals.
   if (usingIds && kind != VarKind::Local)
-    identifiers.insert(identifiers.begin() + absolutePos, num, Identifier());
+    identifiers.insert(identifiers.begin() + absolutePos, num, id);
 
   return absolutePos;
 }



More information about the Mlir-commits mailing list