[mlir] Add timings to mlir translate.
authorTobias Gysi <tobias.gysi@nextsilicon.com>
Fri, 12 May 2023 11:36:28 +0000 (11:36 +0000)
committerTobias Gysi <tobias.gysi@nextsilicon.com>
Fri, 12 May 2023 12:02:50 +0000 (12:02 +0000)
The revision adds basic timing to the mlir-translate tool.

Reviewed By: Dinistro

Differential Revision: https://reviews.llvm.org/D150434

mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
mlir/test/mlir-translate/export-timing.mlir [new file with mode: 0644]
mlir/test/mlir-translate/import-timing.ll [new file with mode: 0644]

index bdfa660..89ac271 100644 (file)
@@ -26,7 +26,7 @@ using namespace mlir;
 namespace mlir {
 void registerFromLLVMIRTranslation() {
   TranslateToMLIRRegistration registration(
-      "import-llvm", "translate llvmir to mlir",
+      "import-llvm", "Translate LLVMIR to MLIR",
       [](llvm::SourceMgr &sourceMgr,
          MLIRContext *context) -> OwningOpRef<Operation *> {
         llvm::SMDiagnostic err;
index 4f44770..4558893 100644 (file)
@@ -24,7 +24,7 @@ using namespace mlir;
 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);
index 8fc3abe..a79f6af 100644 (file)
@@ -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 @@ LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
   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<llvm::MemoryBuffer> input;
   if (auto inputAlignment = translationsRequested[0]->getInputAlignment())
@@ -103,6 +110,9 @@ LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
       }
 
       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 (file)
index 0000000..f10cfb9
--- /dev/null
@@ -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 (file)
index 0000000..60a21d4
--- /dev/null
@@ -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
+}