You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mgb-opt.cpp 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "megbrain/jit/mlir/ir/dialect.h"
  2. #include "megbrain/jit/mlir/ir/passes.h"
  3. #include <llvm/Support/CommandLine.h>
  4. #include <llvm/Support/InitLLVM.h>
  5. #include <llvm/Support/PrettyStackTrace.h>
  6. #include <llvm/Support/SourceMgr.h>
  7. #include <llvm/Support/ToolOutputFile.h>
  8. #include <mlir/Dialect/Affine/IR/AffineOps.h>
  9. #include <mlir/Dialect/LLVMIR/LLVMDialect.h>
  10. #include <mlir/IR/AsmState.h>
  11. #include <mlir/InitAllDialects.h>
  12. #include <mlir/InitAllPasses.h>
  13. #include <mlir/Pass/Pass.h>
  14. #include <mlir/Pass/PassManager.h>
  15. #include <mlir/Support/FileUtilities.h>
  16. #include <mlir/Support/MlirOptMain.h>
  17. using namespace llvm;
  18. using namespace mlir;
  19. //! TODO: Implement a custom MlirOptMain that supports the following flags.
  20. static cl::opt<bool> print_mlir{
  21. "print-mlir",
  22. cl::desc("Prints MLIR IR after translation"),
  23. cl::init(false),
  24. };
  25. static cl::list<std::string> input_values{
  26. "input-value",
  27. cl::desc("Input shapes and optional values"),
  28. cl::ZeroOrMore,
  29. };
  30. static cl::opt<std::string> input_values_file{
  31. "input-value-file",
  32. cl::desc("Provides a file for input shapes and optional values (see "
  33. "ParseToVariantListFromFile in vm_util.h for details)"),
  34. cl::init(""),
  35. };
  36. static cl::opt<bool> run{
  37. "run",
  38. cl::desc("Runs the module (vs. just compiling and verifing)"),
  39. cl::init(true),
  40. };
  41. static cl::list<std::string> run_args{
  42. "run-arg",
  43. cl::desc("Argument passed to the execution flag parser"),
  44. cl::ZeroOrMore,
  45. };
  46. namespace mgb {
  47. namespace jit {
  48. void register_test_mgb_to_affine_lowering_pass();
  49. void register_test_affine_to_llvm_lowering_pass();
  50. } // namespace jit
  51. } // namespace mgb
  52. int main(int argc, char** argv) {
  53. mlir::registerAllPasses();
  54. mlir::DialectRegistry registry;
  55. mlir::registerAllDialects(registry);
  56. registry.insert<mgb::jit::MgbDialect>();
  57. mgb::jit::register_test_mgb_to_affine_lowering_pass();
  58. mgb::jit::register_test_affine_to_llvm_lowering_pass();
  59. return failed(MlirOptMain(argc, argv, "MLIR modular optimizer driver", registry));
  60. }