1 //===----- JITTargetMachineBuilder.cpp - Build TargetMachines for JIT -----===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
11 #include "llvm/Support/TargetRegistry.h"
16 JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT)
18 Options.EmulatedTLS = true;
19 Options.ExplicitEmulatedTLS = true;
22 Expected<JITTargetMachineBuilder> JITTargetMachineBuilder::detectHost() {
23 // FIXME: getProcessTriple is bogus. It returns the host LLVM was compiled on,
24 // rather than a valid triple for the current process.
25 return JITTargetMachineBuilder(Triple(sys::getProcessTriple()));
28 Expected<std::unique_ptr<TargetMachine>>
29 JITTargetMachineBuilder::createTargetMachine() {
32 auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg);
34 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
37 TheTarget->createTargetMachine(TT.getTriple(), CPU, Features.getString(),
38 Options, RM, CM, OptLevel, /*JIT*/ true);
40 return make_error<StringError>("Could not allocate target machine",
41 inconvertibleErrorCode());
43 return std::unique_ptr<TargetMachine>(TM);
46 JITTargetMachineBuilder &JITTargetMachineBuilder::addFeatures(
47 const std::vector<std::string> &FeatureVec) {
48 for (const auto &F : FeatureVec)
49 Features.AddFeature(F);
53 } // End namespace orc.
54 } // End namespace llvm.