LLVM  10.0.0svn
JITTargetMachineBuilder.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 
10 
11 #include "llvm/Support/Host.h"
13 
14 namespace llvm {
15 namespace orc {
16 
18  : TT(std::move(TT)) {
19  Options.EmulatedTLS = true;
20  Options.ExplicitEmulatedTLS = true;
21 }
22 
24  // FIXME: getProcessTriple is bogus. It returns the host LLVM was compiled on,
25  // rather than a valid triple for the current process.
27 
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.
32  llvm::StringMap<bool> FeatureMap;
34  for (auto &Feature : FeatureMap)
35  SubtargetFeatures.AddFeature(Feature.first(), Feature.second);
36 
37  TMBuilder.setCPU(llvm::sys::getHostCPUName());
38  TMBuilder.addFeatures(SubtargetFeatures.getFeatures());
39 
40  return TMBuilder;
41 }
42 
45 
46  std::string ErrMsg;
47  auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg);
48  if (!TheTarget)
49  return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
50 
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",
57 
58  return std::unique_ptr<TargetMachine>(TM);
59 }
60 
62  const std::vector<std::string> &FeatureVec) {
63  for (const auto &F : FeatureVec)
64  Features.AddFeature(F);
65  return *this;
66 }
67 
68 } // End namespace orc.
69 } // End namespace llvm.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
std::string getString() const
Returns features as a string.
F(f)
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Definition: BitVector.h:937
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
static Expected< JITTargetMachineBuilder > detectHost()
Create a JITTargetMachineBuilder for the host system.
const std::vector< std::string > & getFeatures() const
Returns the vector of individual subtarget features.
unsigned ExplicitEmulatedTLS
Whether -emulated-tls or -no-emulated-tls is set.
JITTargetMachineBuilder(Triple TT)
Create a JITTargetMachineBuilder based on the given triple.
JITTargetMachineBuilder & addFeatures(const std::vector< std::string > &FeatureVec)
Add subtarget features.
std::string getProcessTriple()
getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...
Definition: Host.cpp:1530
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
Manages the enabling and disabling of subtarget specific features.
unsigned EmulatedTLS
EmulatedTLS - This flag enables emulated TLS model, using emutls function in the runtime library...
const std::string & getTriple() const
Definition: Triple.h:367
JITTargetMachineBuilder & setCPU(std::string CPU)
Set the CPU string.
Expected< std::unique_ptr< TargetMachine > > createTargetMachine()
Create a TargetMachine.
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
Definition: Host.cpp:1226
bool getHostCPUFeatures(StringMap< bool > &Features)
getHostCPUFeatures - Get the LLVM names for the host CPU features.
Definition: Host.cpp:1527
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
A utility class for building TargetMachines for JITs.