[InstCombine] Signed saturation patterns
[llvm-core.git] / lib / ExecutionEngine / Orc / JITTargetMachineBuilder.cpp
blob1d3e6db913e21552ff3b969b7ded6e22cb34eb55
1 //===----- JITTargetMachineBuilder.cpp - Build TargetMachines for JIT -----===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
11 #include "llvm/Support/Host.h"
12 #include "llvm/Support/TargetRegistry.h"
14 namespace llvm {
15 namespace orc {
17 JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT)
18 : TT(std::move(TT)) {
19 Options.EmulatedTLS = true;
20 Options.ExplicitEmulatedTLS = true;
23 Expected<JITTargetMachineBuilder> JITTargetMachineBuilder::detectHost() {
24 // FIXME: getProcessTriple is bogus. It returns the host LLVM was compiled on,
25 // rather than a valid triple for the current process.
26 JITTargetMachineBuilder TMBuilder((Triple(sys::getProcessTriple())));
28 // Retrieve host CPU name and sub-target features and add them to builder.
29 // Relocation model, code model and codegen opt level are kept to default
30 // values.
31 llvm::SubtargetFeatures SubtargetFeatures;
32 llvm::StringMap<bool> FeatureMap;
33 llvm::sys::getHostCPUFeatures(FeatureMap);
34 for (auto &Feature : FeatureMap)
35 SubtargetFeatures.AddFeature(Feature.first(), Feature.second);
37 TMBuilder.setCPU(llvm::sys::getHostCPUName());
38 TMBuilder.addFeatures(SubtargetFeatures.getFeatures());
40 return TMBuilder;
43 Expected<std::unique_ptr<TargetMachine>>
44 JITTargetMachineBuilder::createTargetMachine() {
46 std::string ErrMsg;
47 auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg);
48 if (!TheTarget)
49 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
51 auto *TM =
52 TheTarget->createTargetMachine(TT.getTriple(), CPU, Features.getString(),
53 Options, RM, CM, OptLevel, /*JIT*/ true);
54 if (!TM)
55 return make_error<StringError>("Could not allocate target machine",
56 inconvertibleErrorCode());
58 return std::unique_ptr<TargetMachine>(TM);
61 JITTargetMachineBuilder &JITTargetMachineBuilder::addFeatures(
62 const std::vector<std::string> &FeatureVec) {
63 for (const auto &F : FeatureVec)
64 Features.AddFeature(F);
65 return *this;
68 } // End namespace orc.
69 } // End namespace llvm.