From fadb4af5f0c78c0dd0d897395af76809f67f5bab Mon Sep 17 00:00:00 2001 From: Diego Caballero Date: Wed, 7 Aug 2019 18:38:01 -0700 Subject: [PATCH] Enable TTI for host TargetMachine in JitRunner This commit improves JitRunner so that it creates a target machine for the current CPU host which is used to properly initialize LLVM's TargetTransformInfo for such a target. This will enable optimizations such as vectorization in LLVM when using JitRunner. Please, note that, as part of this work, JITTargetMachineBuilder::detectHost() has been extended to include the host CPU name and sub-target features as part of the host CPU detection (https://reviews.llvm.org/D65760). --- lib/Support/JitRunner.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Support/JitRunner.cpp b/lib/Support/JitRunner.cpp index 56058c27be35..919f829bdf77 100644 --- a/lib/Support/JitRunner.cpp +++ b/lib/Support/JitRunner.cpp @@ -40,6 +40,7 @@ #include "mlir/Transforms/Passes.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassNameParser.h" @@ -308,8 +309,19 @@ int mlir::JitRunnerMain( if (failed(mlirTransformer(m.get()))) return EXIT_FAILURE; + auto tmBuilderOrError = llvm::orc::JITTargetMachineBuilder::detectHost(); + if (!tmBuilderOrError) { + llvm::errs() << "Failed to create a JITTargetMachineBuilder for the host\n"; + return EXIT_FAILURE; + } + auto tmOrError = tmBuilderOrError->createTargetMachine(); + if (!tmOrError) { + llvm::errs() << "Failed to create a TargetMachine for the host\n"; + return EXIT_FAILURE; + } + auto transformer = mlir::makeLLVMPassesTransformer( - passes, optLevel, /*targetMachine=*/nullptr, optPosition); + passes, optLevel, /*targetMachine=*/tmOrError->get(), optPosition); auto error = mainFuncType.getValue() == "f32" ? compileAndExecuteSingleFloatReturnFunction( m.get(), mainFuncName.getValue(), transformer)