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 JITTargetMachineBuilder
TMBuilder((Triple(sys::getProcessTriple())));
27 // Retrieve host CPU name and sub-target features and add them to builder.
28 // Relocation model, code model and codegen opt level are kept to default
30 llvm::SubtargetFeatures SubtargetFeatures
;
31 llvm::StringMap
<bool> FeatureMap
;
32 llvm::sys::getHostCPUFeatures(FeatureMap
);
33 for (auto &Feature
: FeatureMap
)
34 SubtargetFeatures
.AddFeature(Feature
.first(), Feature
.second
);
36 TMBuilder
.setCPU(llvm::sys::getHostCPUName());
37 TMBuilder
.addFeatures(SubtargetFeatures
.getFeatures());
42 Expected
<std::unique_ptr
<TargetMachine
>>
43 JITTargetMachineBuilder::createTargetMachine() {
46 auto *TheTarget
= TargetRegistry::lookupTarget(TT
.getTriple(), ErrMsg
);
48 return make_error
<StringError
>(std::move(ErrMsg
), inconvertibleErrorCode());
51 TheTarget
->createTargetMachine(TT
.getTriple(), CPU
, Features
.getString(),
52 Options
, RM
, CM
, OptLevel
, /*JIT*/ true);
54 return make_error
<StringError
>("Could not allocate target machine",
55 inconvertibleErrorCode());
57 return std::unique_ptr
<TargetMachine
>(TM
);
60 JITTargetMachineBuilder
&JITTargetMachineBuilder::addFeatures(
61 const std::vector
<std::string
> &FeatureVec
) {
62 for (const auto &F
: FeatureVec
)
63 Features
.AddFeature(F
);
67 } // End namespace orc.
68 } // End namespace llvm.