[Mlir-commits] [mlir] mlir/Presburger: contribute a free-standing parser (PR #94916)

Kunwar Grover llvmlistbot at llvm.org
Mon Jul 8 00:57:23 PDT 2024


================
@@ -182,18 +183,43 @@ class PresburgerSpace {
   /// Get the space without local variables.
   PresburgerSpace getSpaceWithoutLocals() const;
 
-  unsigned getNumDomainVars() const { return numDomain; }
-  unsigned getNumRangeVars() const { return numRange; }
-  unsigned getNumSetDimVars() const { return numRange; }
-  unsigned getNumSymbolVars() const { return numSymbols; }
-  unsigned getNumLocalVars() const { return numLocals; }
+  constexpr unsigned getNumDomainVars() const { return numDomain; }
+  constexpr unsigned &numDomainVars() { return numDomain; }
+  constexpr unsigned getNumRangeVars() const { return numRange; }
+  constexpr unsigned &numRangeVars() { return numRange; }
+  constexpr unsigned getNumSetDimVars() const { return numRange; }
+  constexpr unsigned &numSetDimVars() { return numRange; }
+  constexpr unsigned getNumSymbolVars() const { return numSymbols; }
+  constexpr unsigned &numSymbolVars() { return numSymbols; }
+  constexpr unsigned getNumLocalVars() const { return numLocals; }
+  constexpr unsigned &numLocalVars() { return numLocals; }
+  constexpr unsigned getNumDimVars() const { return numDomain + numRange; }
+  constexpr unsigned getNumDimAndSymbolVars() const {
+    return getNumDimVars() + getNumSymbolVars();
+  }
+  constexpr unsigned getNumVars() const {
+    return getNumDimAndSymbolVars() + getNumLocalVars();
+  }
+  constexpr unsigned getNumCols() const { return getNumVars() + 1; }
+
+  constexpr unsigned getSetDimStartIdx() const { return 0; }
+  constexpr unsigned getSymbolStartIdx() const { return getNumDimVars(); }
+  constexpr unsigned getLocalVarStartIdx() const {
+    return getNumDimAndSymbolVars();
+  }
+  constexpr unsigned getConstantIdx() const { return getNumCols() - 1; }
 
-  unsigned getNumDimVars() const { return numDomain + numRange; }
-  unsigned getNumDimAndSymbolVars() const {
-    return numDomain + numRange + numSymbols;
+  constexpr bool isSetDimIdx(unsigned i) const {
+    return i < getSymbolStartIdx();
+  }
+  constexpr bool isSymbolIdx(unsigned i) const {
+    return i >= getSymbolStartIdx() && i < getLocalVarStartIdx();
+  }
+  constexpr bool isLocalVarIdx(unsigned i) const {
+    return i >= getLocalVarStartIdx() && i < getConstantIdx();
   }
-  unsigned getNumVars() const {
-    return numDomain + numRange + numSymbols + numLocals;
+  constexpr bool isConstantIdx(unsigned i) const {
+    return i == getConstantIdx();
   }
----------------
Groverkss wrote:

A user should not assume any ordering of different variable types. This is an internal detail and should not be exposed. I know there are some methods that exist, but they are supposed to be depreciated in future. You shouldn't have to make any ordering assumptions. If you absolutely have to, then please reuse the existing methods below.

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


More information about the Mlir-commits mailing list