Does the MLIR affine dialect support inverse of affine relations? Or is there a way to achieve the same through other means?
There doesn’t seem to be a specific function, but it should be pretty easy to implement somewhere here llvm-project/IntegerRelation.h at main · llvm/llvm-project · GitHub. If we are really interested in relations, the inverse relation has exactly the same constraints as the original one, but lives in a space with domain and range dimensions swapped. So it should be sufficient to create a new IntegerRelation
object from an existing one by swapping the column ranges of the equality/inequality matrices that correspond to domain and range dimensions.
As an aside, affine dialect is a client of the affine mathematics library (aka Presburger analysis), the dialect does not provide any mathematical capability whatsoever.
Not sure what you are looking for (the term affine relations
might have more context that I know), but in MLIR the only inversion of affine maps supported is when the affine map is a permutation (llvm-project/AffineMap.h at dbbbc9e2ca4bf0839cef49505a798d7404809e7c · llvm/llvm-project · GitHub). I am guessing looking for something more involved?
Thank you for the responses!
IIUC, I should use MLIR affine maps to represent the output of affine transformations rather than use that as a tool to perform the transformations?
On the affine mathematics library, are there methods to generate MLIR affine dialect constructs from, say, ISL (Public Git Hosting - isl.git/summary)?
I did not imply that. You may be confused by the naming: AffineMap
is not a part of the affine dialect. It is not a part of any dialect for that matter, it is just a built-in attribute-like construct that is associated with the MLIR context for lifetime management purposes. The affine dialect contains operations for, e.g., loops and conditionals.
In isl nomenclature, AffineMap
is close to isl_multi_aff
, with some caveats on how the vector spaces of the definition are modeled. If that is sufficient for your transformations, go for it.
There is no dependency on isl, and it is highly unlikely we will want to introduce one. Some out-of-tree projects may have created the conversions though.
Let me reiterate that the affine dialect does not represent mathematical constructs but loops and conditionals, so converting from isl to the dialect makes little sense. It should be relatively straightforward to convert most mathematical constructs from isl to MLIR Presburger objects: ultimately, isl_basic_set/map
is a matrix of coefficients for (in)equalities and so is FlatAffineConstraints
; copying the matrix over and setting up the proper vector space descriptor is all it should take. Similarly, isl AST, once generated, can be traversed to generate the equivalent loop structure using the affine dialect operations, with additional care to generate the bodies of control flow constructs.
Also to answer the original question, the inverse is being added in ⚙ D126327 [MLIR][Presburger] Add inverse to IntegerRelation