From: Tobias Gysi Date: Fri, 12 May 2023 11:36:28 +0000 (+0000) Subject: [mlir] Add timings to mlir translate. X-Git-Tag: upstream/17.0.6~8711 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c3b4e279d465f6489c4af43637cf125e86859097;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp index bdfa660..89ac271 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 { llvm::SMDiagnostic err; diff --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp index 4f44770..4558893 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 8fc3abe..a79f6af 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 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 0000000..f10cfb9 --- /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 0000000..60a21d4 --- /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 +}