LLVM 24.0.0git
JITTargetMachineBuilder.h
Go to the documentation of this file.
1//===- JITTargetMachineBuilder.h - Build TargetMachines for JIT -*- C++ -*-===//
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//
9// A utitily for building TargetMachines for JITs.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_JITTARGETMACHINEBUILDER_H
14#define LLVM_EXECUTIONENGINE_ORC_JITTARGETMACHINEBUILDER_H
15
16#include "llvm/IR/DataLayout.h"
19#include "llvm/Support/Error.h"
24#include <memory>
25#include <optional>
26#include <string>
27#include <vector>
28
29namespace llvm {
30
31class raw_ostream;
32
33namespace orc {
34
35/// A utility class for building TargetMachines for JITs.
37#ifndef NDEBUG
39#endif
40public:
41 /// Create a JITTargetMachineBuilder based on the given triple.
42 ///
43 /// Note: TargetOptions is default-constructed, then EmulatedTLS is set to
44 /// true. If EmulatedTLS is not required, these values should be reset before
45 /// calling createTargetMachine.
47
48 /// Create a JITTargetMachineBuilder for the host system.
49 ///
50 /// Note: TargetOptions is default-constructed, then EmulatedTLS is set to
51 /// true. If EmulatedTLS is not required, these values should be reset before
52 /// calling createTargetMachine.
54
55 /// Create a TargetMachine.
56 ///
57 /// This operation will fail if the requested target is not registered,
58 /// in which case see llvm/Support/TargetSelect.h. To JIT IR the Target and
59 /// the target's AsmPrinter must both be registered. To JIT assembly
60 /// (including inline and module level assembly) the target's AsmParser must
61 /// also be registered.
63
64 /// Get the default DataLayout for the target.
65 ///
66 /// Note: This is reasonably expensive. It is only suitable for use during
67 /// JIT setup.
69
70 /// Set the CPU string.
71 JITTargetMachineBuilder &setCPU(std::string CPU) {
72 this->CPU = std::move(CPU);
73 return *this;
74 }
75
76 /// Returns the CPU string.
77 const std::string &getCPU() const { return CPU; }
78
79 /// Set the relocation model.
80 JITTargetMachineBuilder &setRelocationModel(std::optional<Reloc::Model> RM) {
81 this->RM = std::move(RM);
82 return *this;
83 }
84
85 /// Get the relocation model.
86 const std::optional<Reloc::Model> &getRelocationModel() const { return RM; }
87
88 /// Set the code model.
89 JITTargetMachineBuilder &setCodeModel(std::optional<CodeModel::Model> CM) {
90 this->CM = std::move(CM);
91 return *this;
92 }
93
94 /// Get the code model.
95 const std::optional<CodeModel::Model> &getCodeModel() const { return CM; }
96
97 /// Set the LLVM CodeGen optimization level.
99 this->OptLevel = OptLevel;
100 return *this;
101 }
102
103 /// Set subtarget features.
105 Features = SubtargetFeatures(FeatureString);
106 return *this;
107 }
108
109 /// Add subtarget features.
111 addFeatures(const std::vector<std::string> &FeatureVec);
112
113 /// Access subtarget features.
114 SubtargetFeatures &getFeatures() { return Features; }
115
116 /// Access subtarget features.
117 const SubtargetFeatures &getFeatures() const { return Features; }
118
119 /// Set TargetOptions.
120 ///
121 /// Note: This operation will overwrite any previously configured options,
122 /// including EmulatedTLS and UseInitArray which the JITTargetMachineBuilder
123 /// sets by default. Clients are responsible for re-enabling these overwritten
124 /// options.
126 this->Options = std::move(Options);
127 return *this;
128 }
129
130 /// Access TargetOptions.
131 TargetOptions &getOptions() { return Options; }
132
133 /// Access TargetOptions.
134 const TargetOptions &getOptions() const { return Options; }
135
136 /// Access Triple.
137 Triple &getTargetTriple() { return TT; }
138
139 /// Access Triple.
140 const Triple &getTargetTriple() const { return TT; }
141
142private:
143 Triple TT;
144 std::string CPU;
145 SubtargetFeatures Features;
147 std::optional<Reloc::Model> RM;
148 std::optional<CodeModel::Model> CM;
150};
151
152#ifndef NDEBUG
154public:
156 StringRef Indent)
157 : JTMB(JTMB), Indent(Indent) {}
158 LLVM_ABI void print(raw_ostream &OS) const;
159
161 const JITTargetMachineBuilderPrinter &JTMBP) {
162 JTMBP.print(OS);
163 return OS;
164 }
165
166private:
168 StringRef Indent;
169};
170#endif // NDEBUG
171
172} // end namespace orc
173} // end namespace llvm
174
175#endif // LLVM_EXECUTIONENGINE_ORC_JITTARGETMACHINEBUILDER_H
#define LLVM_ABI
Definition Compiler.h:215
static LVOptions Options
Definition LVOptions.cpp:25
Tagged union holding either a T or a Error.
Definition Error.h:485
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Manages the enabling and disabling of subtarget specific features.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
JITTargetMachineBuilderPrinter(JITTargetMachineBuilder &JTMB, StringRef Indent)
LLVM_ABI void print(raw_ostream &OS) const
friend raw_ostream & operator<<(raw_ostream &OS, const JITTargetMachineBuilderPrinter &JTMBP)
A utility class for building TargetMachines for JITs.
LLVM_ABI Expected< DataLayout > getDefaultDataLayoutForTarget() const
Get the default DataLayout for the target.
JITTargetMachineBuilder & setCodeGenOptLevel(CodeGenOptLevel OptLevel)
Set the LLVM CodeGen optimization level.
const std::string & getCPU() const
Returns the CPU string.
const std::optional< Reloc::Model > & getRelocationModel() const
Get the relocation model.
TargetOptions & getOptions()
Access TargetOptions.
const std::optional< CodeModel::Model > & getCodeModel() const
Get the code model.
LLVM_ABI JITTargetMachineBuilder & addFeatures(const std::vector< std::string > &FeatureVec)
Add subtarget features.
SubtargetFeatures & getFeatures()
Access subtarget features.
JITTargetMachineBuilder & setOptions(TargetOptions Options)
Set TargetOptions.
const Triple & getTargetTriple() const
Access Triple.
JITTargetMachineBuilder & setRelocationModel(std::optional< Reloc::Model > RM)
Set the relocation model.
const TargetOptions & getOptions() const
Access TargetOptions.
static LLVM_ABI Expected< JITTargetMachineBuilder > detectHost()
Create a JITTargetMachineBuilder for the host system.
JITTargetMachineBuilder & setCodeModel(std::optional< CodeModel::Model > CM)
Set the code model.
JITTargetMachineBuilder & setFeatures(StringRef FeatureString)
Set subtarget features.
const SubtargetFeatures & getFeatures() const
Access subtarget features.
LLVM_ABI JITTargetMachineBuilder(Triple TT)
Create a JITTargetMachineBuilder based on the given triple.
LLVM_ABI Expected< std::unique_ptr< TargetMachine > > createTargetMachine()
Create a TargetMachine.
JITTargetMachineBuilder & setCPU(std::string CPU)
Set the CPU string.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:227
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:230