Scaffolding for convertToCFG pass that replaces all instances of ML functions with equivalent CFG functions. Traverses module MLIR, generates CFG functions (empty for now) and removes ML functions. Adds Transforms library and tests.

PiperOrigin-RevId: 205848367
diff --git a/tools/mlir-opt/mlir-opt.cpp b/tools/mlir-opt/mlir-opt.cpp
index 80baee1..f1ccddd 100644
--- a/tools/mlir-opt/mlir-opt.cpp
+++ b/tools/mlir-opt/mlir-opt.cpp
@@ -24,6 +24,7 @@
 #include "mlir/IR/MLIRContext.h"
 #include "mlir/IR/Module.h"
 #include "mlir/Parser.h"
+#include "mlir/Transforms/ConvertToCFG.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/InitLLVM.h"
@@ -44,6 +45,10 @@
 checkParserErrors("check-parser-errors", cl::desc("Check for parser errors"),
                   cl::init(false));
 
+static cl::opt<bool> convertToCFGOpt(
+    "convert-to-cfg",
+    cl::desc("Convert all ML functions in the module to CFG ones"));
+
 enum OptResult { OptSuccess, OptFailure };
 
 /// Open the specified output file and return it, exiting if there is any I/O or
@@ -61,7 +66,8 @@
 }
 
 /// Parses the memory buffer and, if successfully parsed, prints the parsed
-/// output.
+/// output. Optionally, convert ML functions into CFG functions.
+/// TODO: pull parsing and printing into separate functions.
 OptResult parseAndPrintMemoryBuffer(std::unique_ptr<MemoryBuffer> buffer) {
   // Tell sourceMgr about this buffer, which is what the parser will pick up.
   SourceMgr sourceMgr;
@@ -73,6 +79,10 @@
   if (!module)
     return OptFailure;
 
+  // Convert ML functions into CFG functions
+  if (convertToCFGOpt)
+    convertToCFG(module.get());
+
   // Print the output.
   auto output = getOutputStream();
   module->print(output->os());