LLVM  8.0.1
JITTargetMachineBuilder.h
Go to the documentation of this file.
1 //===- JITTargetMachineBuilder.h - Build TargetMachines for JIT -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // A utitily for building TargetMachines for JITs.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_EXECUTIONENGINE_ORC_JITTARGETMACHINEBUILDER_H
15 #define LLVM_EXECUTIONENGINE_ORC_JITTARGETMACHINEBUILDER_H
16 
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/CodeGen.h"
21 #include "llvm/Support/Error.h"
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 namespace llvm {
29 namespace orc {
30 
31 /// A utility class for building TargetMachines for JITs.
33 public:
34  /// Create a JITTargetMachineBuilder based on the given triple.
35  ///
36  /// Note: TargetOptions is default-constructed, then EmulatedTLS and
37  /// ExplicitEmulatedTLS are set to true. If EmulatedTLS is not
38  /// required, these values should be reset before calling
39  /// createTargetMachine.
41 
42  /// Create a JITTargetMachineBuilder for the host system.
43  ///
44  /// Note: TargetOptions is default-constructed, then EmulatedTLS and
45  /// ExplicitEmulatedTLS are set to true. If EmulatedTLS is not
46  /// required, these values should be reset before calling
47  /// createTargetMachine.
49 
50  /// Create a TargetMachine.
51  ///
52  /// This operation will fail if the requested target is not registered,
53  /// in which case see llvm/Support/TargetSelect.h. To JIT IR the Target and
54  /// the target's AsmPrinter must both be registered. To JIT assembly
55  /// (including inline and module level assembly) the target's AsmParser must
56  /// also be registered.
58 
59  /// Get the default DataLayout for the target.
60  ///
61  /// Note: This is reasonably expensive, as it creates a temporary
62  /// TargetMachine instance under the hood. It is only suitable for use during
63  /// JIT setup.
65  auto TM = createTargetMachine();
66  if (!TM)
67  return TM.takeError();
68  return (*TM)->createDataLayout();
69  }
70 
71  /// Set the CPU string.
72  JITTargetMachineBuilder &setCPU(std::string CPU) {
73  this->CPU = std::move(CPU);
74  return *this;
75  }
76 
77  /// Set the relocation model.
79  this->RM = std::move(RM);
80  return *this;
81  }
82 
83  /// Set the code model.
85  this->CM = std::move(CM);
86  return *this;
87  }
88 
89  /// Set the LLVM CodeGen optimization level.
91  this->OptLevel = OptLevel;
92  return *this;
93  }
94 
95  /// Add subtarget features.
97  addFeatures(const std::vector<std::string> &FeatureVec);
98 
99  /// Access subtarget features.
100  SubtargetFeatures &getFeatures() { return Features; }
101 
102  /// Access subtarget features.
103  const SubtargetFeatures &getFeatures() const { return Features; }
104 
105  /// Access TargetOptions.
106  TargetOptions &getOptions() { return Options; }
107 
108  /// Access TargetOptions.
109  const TargetOptions &getOptions() const { return Options; }
110 
111  /// Access Triple.
112  Triple &getTargetTriple() { return TT; }
113 
114  /// Access Triple.
115  const Triple &getTargetTriple() const { return TT; }
116 
117 private:
118  Triple TT;
119  std::string CPU;
120  SubtargetFeatures Features;
121  TargetOptions Options;
125 };
126 
127 } // end namespace orc
128 } // end namespace llvm
129 
130 #endif // LLVM_EXECUTIONENGINE_ORC_JITTARGETMACHINEBUILDER_H
const SubtargetFeatures & getFeatures() const
Access subtarget features.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
const TargetOptions & getOptions() const
Access TargetOptions.
JITTargetMachineBuilder & setRelocationModel(Optional< Reloc::Model > RM)
Set the relocation model.
SubtargetFeatures & getFeatures()
Access subtarget features.
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
static Expected< JITTargetMachineBuilder > detectHost()
Create a JITTargetMachineBuilder for the host system.
Expected< DataLayout > getDefaultDataLayoutForTarget()
Get the default DataLayout for the target.
JITTargetMachineBuilder(Triple TT)
Create a JITTargetMachineBuilder based on the given triple.
JITTargetMachineBuilder & addFeatures(const std::vector< std::string > &FeatureVec)
Add subtarget features.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Manages the enabling and disabling of subtarget specific features.
JITTargetMachineBuilder & setCPU(std::string CPU)
Set the CPU string.
const Triple & getTargetTriple() const
Access Triple.
Expected< std::unique_ptr< TargetMachine > > createTargetMachine()
Create a TargetMachine.
TargetOptions & getOptions()
Access TargetOptions.
JITTargetMachineBuilder & setCodeGenOptLevel(CodeGenOpt::Level OptLevel)
Set the LLVM CodeGen optimization level.
JITTargetMachineBuilder & setCodeModel(Optional< CodeModel::Model > CM)
Set the code model.
A utility class for building TargetMachines for JITs.