Affine expression analysis and simplification.
Outside of IR/
- simplify a MutableAffineMap by flattening the affine expressions
- add a simplify affine expression pass that uses this analysis
- update the FlatAffineConstraints API (to be used in the next CL)
In IR:
- add isMultipleOf and getKnownGCD for AffineExpr, and make the in-IR
simplication of simplifyMod simpler and more powerful.
- rename the AffineExpr visitor methods to distinguish b/w visiting and
walking, and to simplify API names based on context.
The next CL will use some of these for the loop unrolling/unroll-jam to make
the detection for the need of cleanup loop powerful/non-trivial.
A future CL will finally move this simplification to FlatAffineConstraints to
make it more powerful. For eg., currently, even if a mod expr appearing in a
part of the expression tree can't be simplified, the whole thing won't be
simplified.
PiperOrigin-RevId: 211012256
diff --git a/tools/mlir-opt/mlir-opt.cpp b/tools/mlir-opt/mlir-opt.cpp
index e1cba40..5bbf6b7 100644
--- a/tools/mlir-opt/mlir-opt.cpp
+++ b/tools/mlir-opt/mlir-opt.cpp
@@ -37,6 +37,7 @@
#include "llvm/Support/Regex.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/ToolOutputFile.h"
+
using namespace mlir;
using namespace llvm;
@@ -55,6 +56,7 @@
ConvertToCFG,
LoopUnroll,
LoopUnrollAndJam,
+ SimplifyAffineExpr,
TFRaiseControlFlow,
};
@@ -65,6 +67,8 @@
clEnumValN(LoopUnroll, "loop-unroll", "Unroll loops"),
clEnumValN(LoopUnrollAndJam, "loop-unroll-jam",
"Unroll and jam loops"),
+ clEnumValN(SimplifyAffineExpr, "simplify-affine-expr",
+ "Simplify affine expressions"),
clEnumValN(TFRaiseControlFlow, "tf-raise-control-flow",
"Dynamic TensorFlow Switch/Match nodes to a CFG")));
@@ -117,6 +121,9 @@
case LoopUnrollAndJam:
pass = createLoopUnrollAndJamPass();
break;
+ case SimplifyAffineExpr:
+ pass = createSimplifyAffineExprPass();
+ break;
case TFRaiseControlFlow:
pass = createRaiseTFControlFlowPass();
break;