From 6c6ed466a6d8dc31e2e2db93ac38ed75b5a7d748 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Tue, 9 Apr 2019 00:19:40 -0700 Subject: [PATCH] Expose `setupTargetTriple` as a public static method on ExecutionEngine This allows client to be able to reuse the same logic to setup a module for the ExecutionEngine without instanciating one. One use case is running the optimization pipeline but not JIT-ing. -- PiperOrigin-RevId: 242614380 --- mlir/examples/toy/Ch5/toyc.cpp | 1 + mlir/include/mlir/ExecutionEngine/ExecutionEngine.h | 4 ++++ mlir/lib/ExecutionEngine/ExecutionEngine.cpp | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp index b140b36..6c50191 100644 --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -238,6 +238,7 @@ int dumpLLVMIR() { // Initialize LLVM targets. llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); + mlir::ExecutionEngine::setupTargetTriple(llvmModule.get()); auto optPipeline = mlir::makeOptimizingTransformer( /* optLevel=*/EnableOpt ? 3 : 0, /* sizeLevel=*/0); if (auto err = optPipeline(llvmModule.get())) { diff --git a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h index d8fde85..102f22e 100644 --- a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h +++ b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h @@ -87,6 +87,10 @@ public: /// the templated `invoke`. llvm::Error invoke(StringRef name, MutableArrayRef args); + /// Set the target triple on the module. This is implicitly done when creating + /// the engine. + static bool setupTargetTriple(llvm::Module *llvmModule); + private: // Ordering of llvmContext and jit is important for destruction purposes: the // jit must be destroyed before the context. diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp index e9f9984..0b7f3b6 100644 --- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp @@ -187,7 +187,7 @@ static void getDefaultPasses( } // Setup LLVM target triple from the current machine. -static bool setupTargetTriple(llvm::Module *llvmModule) { +bool ExecutionEngine::setupTargetTriple(llvm::Module *llvmModule) { // Setup the machine properties from the current architecture. auto targetTriple = llvm::sys::getDefaultTargetTriple(); std::string errorMessage; -- 2.7.4