LLVM: lib/Target/TargetMachineC.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
27#include
28#include
29
30using namespace llvm;
31
32namespace llvm {
33
34
40 std::optionalReloc::Model RM;
41 std::optionalCodeModel::Model CM;
43};
44
45}
46
54 return reinterpret_cast<Target*>(P);
55}
62
65 return nullptr;
66 }
67
69 return wrap(target);
70}
74
78 [&](const Target &T) { return T.getName() == NameRef; });
80}
81
83 char **ErrorMessage) {
84 std::string Error;
85
88
89 if (!*T) {
90 if (ErrorMessage)
91 *ErrorMessage = strdup(Error.c_str());
92
93 return 1;
94 }
95
96 return 0;
97}
98
100 return unwrap(T)->getName();
101}
102
104 return unwrap(T)->getShortDescription();
105}
106
108 return unwrap(T)->hasJIT();
109}
110
112 return unwrap(T)->hasTargetMachine();
113}
114
116 return unwrap(T)->hasMCAsmBackend();
117}
118
122
126
128 const char *CPU) {
130}
131
133 const char *Features) {
135}
136
138 const char *ABI) {
140}
141
145
146 switch (Level) {
149 break;
152 break;
155 break;
158 break;
159 }
160
162}
163
166 std::optionalReloc::Model RM;
167
171 break;
174 break;
177 break;
180 break;
183 break;
186 break;
188 break;
189 }
190
192}
193
199
207 Opt->Features, TO, Opt->RM,
208 Opt->CM, Opt->OL, Opt->JIT));
209}
210
228
230
235
237 std::string StringRep = unwrap(T)->getTargetTriple().str();
238 return strdup(StringRep.c_str());
239}
240
242 std::string StringRep = std::string(unwrap(T)->getTargetCPU());
243 return strdup(StringRep.c_str());
244}
245
247 std::string StringRep = std::string(unwrap(T)->getTargetFeatureString());
248 return strdup(StringRep.c_str());
249}
250
253 unwrap(T)->Options.MCOptions.AsmVerbose = VerboseAsm;
254}
255
259
263
267 switch (Mode) {
270 break;
273 break;
276 break;
277 }
278
279 unwrap(T)->setGlobalISelAbort(AM);
280}
281
286
290
294 char **ErrorMessage) {
297
299
300 std::string error;
301
303
308 break;
309 default:
311 break;
312 }
314 error = "TargetMachine can't emit a file of this type";
315 *ErrorMessage = strdup(error.c_str());
316 return true;
317 }
318
320
322 return false;
323}
324
326 const char *Filename,
328 char **ErrorMessage) {
329 std::error_code EC;
331 if (EC) {
332 *ErrorMessage = strdup(EC.message().c_str());
333 return true;
334 }
337 return Result;
338}
339
346
348 *OutMemBuf =
350 return Result;
351}
352
356
360
364
368 Features.AddFeature(Feature, IsEnabled);
369
370 return strdup(Features.getString().c_str());
371}
372
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Module.h This file contains the declarations for the Module class.
modulo schedule Modulo Schedule test pass
static std::unique_ptr< TargetMachine > createTargetMachine(Function *F, CodeGenOptLevel OptLevel)
Create the TargetMachine object to query the backend for optimization preferences.
Function const char TargetMachine * Machine
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, raw_pwrite_stream &OS, LLVMCodeGenFileType codegen, char **ErrorMessage)
Definition TargetMachineC.cpp:291
This pass exposes codegen information to IR-level passes.
A parsed version of the target data layout string in and methods for querying it.
Lightweight error class with error context and mandatory checking.
A Module instance is used to store all the information related to an LLVM module.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
LLVM_ABI std::string getString() const
Returns features as a string.
LLVM_ABI void AddFeature(StringRef String, bool Enable=true)
Adds Features.
Primary interface to the complete machine description for the target machine.
virtual bool addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &, raw_pwrite_stream *, CodeGenFileType, bool=true, MachineModuleInfoWrapperPass *MMIWP=nullptr)
Add passes to the specified pass manager to get the specified file emitted.
const DataLayout createDataLayout() const
Create a DataLayout.
MCTargetOptions MCOptions
Machine level options.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
static LLVM_ABI std::string normalize(StringRef Str, CanonicalForm Form=CanonicalForm::ANY)
Turn an arbitrary machine specification into the canonical triple form (or something sensible that th...
PassManager manages ModulePassManagers.
A raw_ostream that writes to a file descriptor.
An abstract base class for streams implementations that also support a pwrite operation.
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
LLVM_C_ABI LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData, size_t InputDataLength, const char *BufferName)
struct LLVMOpaquePassManager * LLVMPassManagerRef
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
void LLVMTargetMachineOptionsSetCodeGenOptLevel(LLVMTargetMachineOptionsRef Options, LLVMCodeGenOptLevel Level)
Definition TargetMachineC.cpp:142
void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM)
Adds the target-specific analysis passes to the pass manager.
Definition TargetMachineC.cpp:373
char * LLVMGetTargetMachineCPU(LLVMTargetMachineRef T)
Returns the cpu used creating this target machine.
Definition TargetMachineC.cpp:241
LLVMTargetRef LLVMGetFirstTarget()
Returns the first llvm::Target in the registered targets list.
Definition TargetMachineC.cpp:63
void LLVMSetTargetMachineGlobalISelAbort(LLVMTargetMachineRef T, LLVMGlobalISelAbortMode Mode)
Set abort behaviour when global instruction selection fails to lower/select an instruction.
Definition TargetMachineC.cpp:264
struct LLVMTarget * LLVMTargetRef
void LLVMTargetMachineOptionsSetABI(LLVMTargetMachineOptionsRef Options, const char *ABI)
Definition TargetMachineC.cpp:137
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T)
Returns the Target used in a TargetMachine.
Definition TargetMachineC.cpp:231
LLVMTargetMachineRef LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *TripleStr, LLVMTargetMachineOptionsRef Options)
Create a new llvm::TargetMachine.
Definition TargetMachineC.cpp:201
LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, const char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage)
Emits an asm or object file for the given module to the filename.
Definition TargetMachineC.cpp:325
void LLVMSetTargetMachineMachineOutliner(LLVMTargetMachineRef T, LLVMBool Enable)
Enable the MachineOutliner pass.
Definition TargetMachineC.cpp:282
struct LLVMOpaqueTargetMachineOptions * LLVMTargetMachineOptionsRef
LLVMTargetRef LLVMGetTargetFromName(const char *Name)
Finds the target corresponding to the given name and stores it in T.
Definition TargetMachineC.cpp:75
void LLVMTargetMachineOptionsSetFeatures(LLVMTargetMachineOptionsRef Options, const char *Features)
Set the list of features for the target machine.
Definition TargetMachineC.cpp:132
LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T)
Returns if the target as an ASM backend (required for emitting output)
Definition TargetMachineC.cpp:115
char * LLVMGetDefaultTargetTriple(void)
Get a triple for the host machine as a string.
Definition TargetMachineC.cpp:353
LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel)
Creates a new llvm::TargetMachine.
Definition TargetMachineC.cpp:212
void LLVMTargetMachineOptionsSetRelocMode(LLVMTargetMachineOptionsRef Options, LLVMRelocMode Reloc)
Definition TargetMachineC.cpp:164
LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T)
Returns the next llvm::Target given a previous one (or null if there's none)
Definition TargetMachineC.cpp:71
char * LLVMGetHostCPUFeatures(void)
Get the host CPU's features as a string.
Definition TargetMachineC.cpp:365
void LLVMDisposeTargetMachineOptions(LLVMTargetMachineOptionsRef Options)
Dispose of an LLVMTargetMachineOptionsRef instance.
Definition TargetMachineC.cpp:123
LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T)
Returns if the target has a TargetMachine associated.
Definition TargetMachineC.cpp:111
void LLVMSetTargetMachineFastISel(LLVMTargetMachineRef T, LLVMBool Enable)
Enable fast-path instruction selection.
Definition TargetMachineC.cpp:256
char * LLVMNormalizeTargetTriple(const char *triple)
Normalize a target triple.
Definition TargetMachineC.cpp:357
LLVMBool LLVMGetTargetFromTriple(const char *TripleStr, LLVMTargetRef *T, char **ErrorMessage)
Finds the target corresponding to the given triple and stores it in T.
Definition TargetMachineC.cpp:82
char * LLVMGetTargetMachineTriple(LLVMTargetMachineRef T)
Returns the triple used creating this target machine.
Definition TargetMachineC.cpp:236
char * LLVMGetHostCPUName(void)
Get the host CPU as a string.
Definition TargetMachineC.cpp:361
void LLVMTargetMachineOptionsSetCPU(LLVMTargetMachineOptionsRef Options, const char *CPU)
Definition TargetMachineC.cpp:127
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, LLVMBool VerboseAsm)
Set the target machine's ASM verbosity.
Definition TargetMachineC.cpp:251
void LLVMSetTargetMachineGlobalISel(LLVMTargetMachineRef T, LLVMBool Enable)
Enable global instruction selection.
Definition TargetMachineC.cpp:260
void LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options, LLVMCodeModel CodeModel)
Definition TargetMachineC.cpp:194
const char * LLVMGetTargetName(LLVMTargetRef T)
Returns the name of a target.
Definition TargetMachineC.cpp:99
LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T)
Create a DataLayout based on the targetMachine.
Definition TargetMachineC.cpp:287
struct LLVMOpaqueTargetData * LLVMTargetDataRef
LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M, LLVMCodeGenFileType codegen, char **ErrorMessage, LLVMMemoryBufferRef *OutMemBuf)
Compile the LLVM IR stored in M and store the result in OutMemBuf.
Definition TargetMachineC.cpp:340
const char * LLVMGetTargetDescription(LLVMTargetRef T)
Returns the description of a target.
Definition TargetMachineC.cpp:103
char * LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T)
Returns the feature string used creating this target machine.
Definition TargetMachineC.cpp:246
LLVMBool LLVMTargetHasJIT(LLVMTargetRef T)
Returns if the target has a JIT.
Definition TargetMachineC.cpp:107
void LLVMDisposeTargetMachine(LLVMTargetMachineRef T)
Dispose the LLVMTargetMachineRef instance generated by LLVMCreateTargetMachine.
Definition TargetMachineC.cpp:229
LLVMTargetMachineOptionsRef LLVMCreateTargetMachineOptions(void)
Create a new set of options for an llvm::TargetMachine.
Definition TargetMachineC.cpp:119
@ LLVMCodeGenLevelAggressive
@ LLVMCodeGenLevelDefault
@ LLVMGlobalISelAbortDisableWithDiag
@ LLVMGlobalISelAbortDisable
@ LLVMGlobalISelAbortEnable
LLVM_ABI StringMap< bool, MallocAllocator > getHostCPUFeatures()
getHostCPUFeatures - Get the LLVM names for the host CPU features.
LLVM_ABI StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
LLVM_ABI std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
This is an optimization pass for GlobalISel generic memory operations.
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
CodeGenOptLevel
Code generation optimization level.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Attribute unwrap(LLVMAttributeRef Attr)
LLVM_ABI ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
LLVMAttributeRef wrap(Attribute Attr)
GlobalISelAbortMode
Enable abort calls when global instruction selection fails to lower/select an instruction.
Options for LLVMCreateTargetMachine().
Definition TargetMachineC.cpp:35
bool JIT
Definition TargetMachineC.cpp:42
std::optional< Reloc::Model > RM
Definition TargetMachineC.cpp:40
CodeGenOptLevel OL
Definition TargetMachineC.cpp:39
std::string CPU
Definition TargetMachineC.cpp:36
std::string Features
Definition TargetMachineC.cpp:37
std::string ABI
Definition TargetMachineC.cpp:38
std::optional< CodeModel::Model > CM
Definition TargetMachineC.cpp:41
static const Target * lookupTarget(StringRef TripleStr, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
static LLVM_ABI iterator_range< iterator > targets()