[Mlir-commits] [mlir] c3b4e27 - [mlir] Add timings to mlir translate.
Tobias Gysi
llvmlistbot at llvm.org
Fri May 12 05:16:53 PDT 2023
Author: Tobias Gysi
Date: 2023-05-12T12:02:50Z
New Revision: c3b4e279d465f6489c4af43637cf125e86859097
URL: https://github.com/llvm/llvm-project/commit/c3b4e279d465f6489c4af43637cf125e86859097
DIFF: https://github.com/llvm/llvm-project/commit/c3b4e279d465f6489c4af43637cf125e86859097.diff
LOG: [mlir] Add timings to mlir translate.
The revision adds basic timing to the mlir-translate tool.
Reviewed By: Dinistro
Differential Revision: https://reviews.llvm.org/D150434
Added:
mlir/test/mlir-translate/export-timing.mlir
mlir/test/mlir-translate/import-timing.ll
Modified:
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
index bdfa6602915ba..89ac271bfe4b1 100644
--- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
@@ -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;
diff --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
index 4f44770ec7f0e..4558893779534 100644
--- a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
@@ -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);
diff --git a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
index 8fc3abea47f21..a79f6afae25b3 100644
--- 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 @@ 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
index 0000000000000..f10cfb9bd815b
--- /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
index 0000000000000..60a21d4af54aa
--- /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
+}
More information about the Mlir-commits
mailing list