[ARM] Generate 8.1-m CSINC, CSNEG and CSINV instructions.
[llvm-core.git] / lib / ExecutionEngine / Orc / JITTargetMachineBuilder.cpp
blob359ef99472abcbf9415c555cd2ed1c8a9f6b29e1
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/TargetRegistry.h"
13 namespace llvm {
14 namespace orc {
16 JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT)
17 : TT(std::move(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
29 // values.
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());
39 return TMBuilder;
42 Expected<std::unique_ptr<TargetMachine>>
43 JITTargetMachineBuilder::createTargetMachine() {
45 std::string ErrMsg;
46 auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg);
47 if (!TheTarget)
48 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
50 auto *TM =
51 TheTarget->createTargetMachine(TT.getTriple(), CPU, Features.getString(),
52 Options, RM, CM, OptLevel, /*JIT*/ true);
53 if (!TM)
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);
64 return *this;
67 } // End namespace orc.
68 } // End namespace llvm.