xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===----- JITTargetMachineBuilder.cpp - Build TargetMachines for JIT -----===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
10*0b57cec5SDimitry Andric 
11*0b57cec5SDimitry Andric #include "llvm/Support/TargetRegistry.h"
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric namespace llvm {
14*0b57cec5SDimitry Andric namespace orc {
15*0b57cec5SDimitry Andric 
16*0b57cec5SDimitry Andric JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT)
17*0b57cec5SDimitry Andric     : TT(std::move(TT)) {
18*0b57cec5SDimitry Andric   Options.EmulatedTLS = true;
19*0b57cec5SDimitry Andric   Options.ExplicitEmulatedTLS = true;
20*0b57cec5SDimitry Andric }
21*0b57cec5SDimitry Andric 
22*0b57cec5SDimitry Andric Expected<JITTargetMachineBuilder> JITTargetMachineBuilder::detectHost() {
23*0b57cec5SDimitry Andric   // FIXME: getProcessTriple is bogus. It returns the host LLVM was compiled on,
24*0b57cec5SDimitry Andric   //        rather than a valid triple for the current process.
25*0b57cec5SDimitry Andric   return JITTargetMachineBuilder(Triple(sys::getProcessTriple()));
26*0b57cec5SDimitry Andric }
27*0b57cec5SDimitry Andric 
28*0b57cec5SDimitry Andric Expected<std::unique_ptr<TargetMachine>>
29*0b57cec5SDimitry Andric JITTargetMachineBuilder::createTargetMachine() {
30*0b57cec5SDimitry Andric 
31*0b57cec5SDimitry Andric   std::string ErrMsg;
32*0b57cec5SDimitry Andric   auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg);
33*0b57cec5SDimitry Andric   if (!TheTarget)
34*0b57cec5SDimitry Andric     return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
35*0b57cec5SDimitry Andric 
36*0b57cec5SDimitry Andric   auto *TM =
37*0b57cec5SDimitry Andric       TheTarget->createTargetMachine(TT.getTriple(), CPU, Features.getString(),
38*0b57cec5SDimitry Andric                                      Options, RM, CM, OptLevel, /*JIT*/ true);
39*0b57cec5SDimitry Andric   if (!TM)
40*0b57cec5SDimitry Andric     return make_error<StringError>("Could not allocate target machine",
41*0b57cec5SDimitry Andric                                    inconvertibleErrorCode());
42*0b57cec5SDimitry Andric 
43*0b57cec5SDimitry Andric   return std::unique_ptr<TargetMachine>(TM);
44*0b57cec5SDimitry Andric }
45*0b57cec5SDimitry Andric 
46*0b57cec5SDimitry Andric JITTargetMachineBuilder &JITTargetMachineBuilder::addFeatures(
47*0b57cec5SDimitry Andric     const std::vector<std::string> &FeatureVec) {
48*0b57cec5SDimitry Andric   for (const auto &F : FeatureVec)
49*0b57cec5SDimitry Andric     Features.AddFeature(F);
50*0b57cec5SDimitry Andric   return *this;
51*0b57cec5SDimitry Andric }
52*0b57cec5SDimitry Andric 
53*0b57cec5SDimitry Andric } // End namespace orc.
54*0b57cec5SDimitry Andric } // End namespace llvm.
55