diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp index b140b3605c97..6c50191981ee 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 d8fde8526e46..102f22ea0ac7 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 e9f99848e374..0b7f3b69d417 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;