diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -26,7 +26,7 @@ namespace mlir { void registerFromLLVMIRTranslation() { TranslateToMLIRRegistration registration( - "import-llvm", "translate llvmir to mlir", + "import-llvm", "Translate LLVMIR to MLIR", [](llvm::SourceMgr &sourceMgr, MLIRContext *context) -> OwningOpRef { llvm::SMDiagnostic err; diff --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp --- a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp @@ -24,7 +24,7 @@ namespace mlir { void registerToLLVMIRTranslation() { TranslateFromMLIRRegistration registration( - "mlir-to-llvmir", "translate mlir to llvmir", + "mlir-to-llvmir", "Translate MLIR to LLVMIR", [](Operation *op, raw_ostream &output) { llvm::LLVMContext llvmContext; auto llvmModule = translateModuleToLLVMIR(op, llvmContext); diff --git a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp --- a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp +++ b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp @@ -14,6 +14,7 @@ #include "mlir/Parser/Parser.h" #include "mlir/Support/FileUtilities.h" #include "mlir/Support/LogicalResult.h" +#include "mlir/Support/Timing.h" #include "mlir/Support/ToolUtilities.h" #include "mlir/Tools/mlir-translate/Translation.h" #include "llvm/Support/InitLLVM.h" @@ -63,8 +64,14 @@ registerAsmPrinterCLOptions(); registerMLIRContextCLOptions(); registerTranslationCLOptions(); + registerDefaultTimingManagerCLOptions(); llvm::cl::ParseCommandLineOptions(argc, argv, toolName); + // Initialize the timing manager. + DefaultTimingManager tm; + applyDefaultTimingManagerCLOptions(tm); + TimingScope timing = tm.getRootScope(); + std::string errorMessage; std::unique_ptr input; if (auto inputAlignment = translationsRequested[0]->getInputAlignment()) @@ -103,6 +110,9 @@ } const Translation *translationRequested = translationsRequested[i]; + TimingScope translationTiming = + timing.nest(translationRequested->getDescription()); + MLIRContext context; context.allowUnregisteredDialects(allowUnregisteredDialects); context.printOpOnDiagnostic(!verifyDiagnostics); diff --git a/mlir/test/mlir-translate/export-timing.mlir b/mlir/test/mlir-translate/export-timing.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/mlir-translate/export-timing.mlir @@ -0,0 +1,10 @@ +// RUN: mlir-translate %s --mlir-to-llvmir -mlir-timing 2>&1 | FileCheck %s + +// CHECK: Execution time report +// CHECK: Total Execution Time: +// CHECK: Name +// CHECK-NEXT: Translate MLIR to LLVMIR + +llvm.func @foo() { + llvm.return +} diff --git a/mlir/test/mlir-translate/import-timing.ll b/mlir/test/mlir-translate/import-timing.ll new file mode 100644 --- /dev/null +++ b/mlir/test/mlir-translate/import-timing.ll @@ -0,0 +1,10 @@ +; RUN: mlir-translate %s -import-llvm -mlir-timing 2>&1 | FileCheck %s + +; CHECK: Execution time report +; CHECK: Total Execution Time: +; CHECK: Name +; CHECK-NEXT: Translate LLVMIR to MLIR + +define void @foo() { + ret void +}