Change mlir-opt.cpp to take a list of passes to run, simplifying the driver
code. Change printing of affine map's to not print a space between the dim and
symbol list.
PiperOrigin-RevId: 206505419
diff --git a/tools/mlir-opt/mlir-opt.cpp b/tools/mlir-opt/mlir-opt.cpp
index 8ec042b..ac9f6f6 100644
--- a/tools/mlir-opt/mlir-opt.cpp
+++ b/tools/mlir-opt/mlir-opt.cpp
@@ -49,18 +49,20 @@
checkParserErrors("check-parser-errors", cl::desc("Check for parser errors"),
cl::init(false));
-// TODO(clattner): replace these bool options with an enum list option.
-static cl::opt<bool> convertToCFGOpt(
- "convert-to-cfg",
- cl::desc("Convert all ML functions in the module to CFG ones"));
+enum Passes {
+ ConvertToCFG,
+ UnrollInnermostLoops,
+ TFRaiseControlFlow,
+};
-static cl::opt<bool> unrollInnermostLoops("unroll-innermost-loops",
- cl::desc("Unroll innermost loops"),
- cl::init(false));
-
-static cl::opt<bool> raiseTFControlFlow(
- "tf-raise-control-flow",
- cl::desc("Raise TensorFlow Switch/Match nodes to a CFG"));
+static cl::list<Passes> passList(
+ "", cl::desc("Compiler passes to run"),
+ cl::values(clEnumValN(ConvertToCFG, "convert-to-cfg",
+ "Convert all ML functions in the module to CFG ones"),
+ clEnumValN(UnrollInnermostLoops, "unroll-innermost-loops",
+ "Unroll innermost loops"),
+ clEnumValN(TFRaiseControlFlow, "tf-raise-control-flow",
+ "Dynamic TensorFlow Switch/Match nodes to a CFG")));
enum OptResult { OptSuccess, OptFailure };
@@ -97,23 +99,21 @@
if (!module)
return OptFailure;
- // Convert ML functions into CFG functions
- if (convertToCFGOpt) {
- auto *pass = createConvertToCFGPass();
- pass->runOnModule(module.get());
- delete pass;
- module->verify();
- }
+ // Run each of the passes that were selected.
+ for (auto passKind : passList) {
+ Pass *pass = nullptr;
+ switch (passKind) {
+ case ConvertToCFG:
+ pass = createConvertToCFGPass();
+ break;
+ case UnrollInnermostLoops:
+ pass = createLoopUnrollPass();
+ break;
+ case TFRaiseControlFlow:
+ pass = createRaiseTFControlFlowPass();
+ break;
+ }
- if (unrollInnermostLoops) {
- auto *pass = createLoopUnrollPass();
- pass->runOnModule(module.get());
- delete pass;
- module->verify();
- }
-
- if (raiseTFControlFlow) {
- auto *pass = createRaiseTFControlFlowPass();
pass->runOnModule(module.get());
delete pass;
module->verify();