diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp --- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp @@ -27,6 +27,7 @@ #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/MC/SubtargetFeature.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Error.h" #include "llvm/Support/Host.h" @@ -119,8 +120,16 @@ errs() << "NO target: " << errorMessage << "\n"; return true; } - std::unique_ptr machine( - target->createTargetMachine(targetTriple, "generic", "", {}, {})); + std::string cpu = std::string(llvm::sys::getHostCPUName()); + llvm::SubtargetFeatures features; + llvm::StringMap hostFeatures; + + if (llvm::sys::getHostCPUFeatures(hostFeatures)) + for (auto &f : hostFeatures) + features.AddFeature(f.first(), f.second); + + std::unique_ptr machine(target->createTargetMachine( + targetTriple, cpu, features.getString(), {}, {})); llvmModule->setDataLayout(machine->createDataLayout()); llvmModule->setTargetTriple(targetTriple); return false;