LLVM 19.0.0git
TargetMachine.h
Go to the documentation of this file.
1/*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\
2|* *|
3|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4|* Exceptions. *|
5|* See https://llvm.org/LICENSE.txt for license information. *|
6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to the Target and TargetMachine *|
11|* classes, which can be used to generate assembly or object files. *|
12|* *|
13|* Many exotic languages can interoperate with C code but have a harder time *|
14|* with C++ due to name mangling. So in addition to C, this interface enables *|
15|* tools written in such languages. *|
16|* *|
17\*===----------------------------------------------------------------------===*/
18
19#ifndef LLVM_C_TARGETMACHINE_H
20#define LLVM_C_TARGETMACHINE_H
21
22#include "llvm-c/ExternC.h"
23#include "llvm-c/Target.h"
24#include "llvm-c/Types.h"
25
27
28/**
29 * @addtogroup LLVMCTarget
30 *
31 * @{
32 */
33
34typedef struct LLVMOpaqueTargetMachineOptions *LLVMTargetMachineOptionsRef;
35typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
36typedef struct LLVMTarget *LLVMTargetRef;
37
38typedef enum {
44
45typedef enum {
54
55typedef enum {
64
65typedef enum {
69
70typedef enum {
75
76/** Returns the first llvm::Target in the registered targets list. */
78/** Returns the next llvm::Target given a previous one (or null if there's none) */
80
81/*===-- Target ------------------------------------------------------------===*/
82/** Finds the target corresponding to the given name and stores it in \p T.
83 Returns 0 on success. */
85
86/** Finds the target corresponding to the given triple and stores it in \p T.
87 Returns 0 on success. Optionally returns any error in ErrorMessage.
88 Use LLVMDisposeMessage to dispose the message. */
90 char **ErrorMessage);
91
92/** Returns the name of a target. See llvm::Target::getName */
94
95/** Returns the description of a target. See llvm::Target::getDescription */
97
98/** Returns if the target has a JIT */
100
101/** Returns if the target has a TargetMachine associated */
103
104/** Returns if the target as an ASM backend (required for emitting output) */
106
107/*===-- Target Machine ----------------------------------------------------===*/
108/**
109 * Create a new set of options for an llvm::TargetMachine.
110 *
111 * The returned option structure must be released with
112 * LLVMDisposeTargetMachineOptions() after the call to
113 * LLVMCreateTargetMachineWithOptions().
114 */
116
117/**
118 * Dispose of an LLVMTargetMachineOptionsRef instance.
119 */
121
123 const char *CPU);
124
125/**
126 * Set the list of features for the target machine.
127 *
128 * \param Features a comma-separated list of features.
129 */
131 const char *Features);
132
134 const char *ABI);
135
138
140 LLVMRelocMode Reloc);
141
143 LLVMCodeModel CodeModel);
144
145/**
146 * Create a new llvm::TargetMachine.
147 *
148 * \param T the target to create a machine for.
149 * \param Triple a triple describing the target machine.
150 * \param Options additional configuration (see
151 * LLVMCreateTargetMachineOptions()).
152 */
156
157/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
159 const char *Triple, const char *CPU, const char *Features,
160 LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
161
162/** Dispose the LLVMTargetMachineRef instance generated by
163 LLVMCreateTargetMachine. */
165
166/** Returns the Target used in a TargetMachine */
168
169/** Returns the triple used creating this target machine. See
170 llvm::TargetMachine::getTriple. The result needs to be disposed with
171 LLVMDisposeMessage. */
173
174/** Returns the cpu used creating this target machine. See
175 llvm::TargetMachine::getCPU. The result needs to be disposed with
176 LLVMDisposeMessage. */
178
179/** Returns the feature string used creating this target machine. See
180 llvm::TargetMachine::getFeatureString. The result needs to be disposed with
181 LLVMDisposeMessage. */
183
184/** Create a DataLayout based on the targetMachine. */
186
187/** Set the target machine's ASM verbosity. */
189 LLVMBool VerboseAsm);
190
191/** Enable fast-path instruction selection. */
193
194/** Enable global instruction selection. */
196
197/** Set abort behaviour when global instruction selection fails to lower/select
198 * an instruction. */
201
202/** Enable the MachineOutliner pass. */
205
206/** Emits an asm or object file for the given module to the filename. This
207 wraps several c++ only classes (among them a file stream). Returns any
208 error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
210 const char *Filename,
212 char **ErrorMessage);
213
214/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
216 LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
217
218/*===-- Triple ------------------------------------------------------------===*/
219/** Get a triple for the host machine as a string. The result needs to be
220 disposed with LLVMDisposeMessage. */
222
223/** Normalize a target triple. The result needs to be disposed with
224 LLVMDisposeMessage. */
225char* LLVMNormalizeTargetTriple(const char* triple);
226
227/** Get the host CPU as a string. The result needs to be disposed with
228 LLVMDisposeMessage. */
229char* LLVMGetHostCPUName(void);
230
231/** Get the host CPU's features as a string. The result needs to be disposed
232 with LLVMDisposeMessage. */
233char* LLVMGetHostCPUFeatures(void);
234
235/** Adds the target-specific analysis passes to the pass manager. */
237
238/**
239 * @}
240 */
241
243
244#endif
@ Enable
Definition: DwarfDebug.cpp:87
std::string Name
#define LLVM_C_EXTERN_C_BEGIN
Definition: ExternC.h:35
#define LLVM_C_EXTERN_C_END
Definition: ExternC.h:36
static LVOptions Options
Definition: LVOptions.cpp:25
static void codegen(Module *M, llvm::raw_pwrite_stream &OS, function_ref< std::unique_ptr< TargetMachine >()> TMFactory, CodeGenFileType FileType)
Definition: ParallelCG.cpp:26
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
int LLVMBool
Definition: Types.h:28
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:127
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
Definition: Types.h:48
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
LLVMCodeGenFileType
Definition: TargetMachine.h:65
void LLVMTargetMachineOptionsSetCPU(LLVMTargetMachineOptionsRef Options, const char *CPU)
void LLVMTargetMachineOptionsSetFeatures(LLVMTargetMachineOptionsRef Options, const char *Features)
Set the list of features for the target machine.
void LLVMSetTargetMachineMachineOutliner(LLVMTargetMachineRef T, LLVMBool Enable)
Enable the MachineOutliner pass.
char * LLVMGetHostCPUFeatures(void)
Get the host CPU's features as a string.
void LLVMTargetMachineOptionsSetRelocMode(LLVMTargetMachineOptionsRef Options, LLVMRelocMode Reloc)
LLVMTargetRef LLVMGetFirstTarget(void)
Returns the first llvm::Target in the registered targets list.
struct LLVMTarget * LLVMTargetRef
Definition: TargetMachine.h:36
char * LLVMGetHostCPUName(void)
Get the host CPU as a string.
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
Definition: TargetMachine.h:35
LLVMCodeModel
Definition: TargetMachine.h:55
void LLVMTargetMachineOptionsSetCodeGenOptLevel(LLVMTargetMachineOptionsRef Options, LLVMCodeGenOptLevel Level)
char * LLVMGetTargetMachineCPU(LLVMTargetMachineRef T)
Returns the cpu used creating this target machine.
void LLVMDisposeTargetMachineOptions(LLVMTargetMachineOptionsRef Options)
Dispose of an LLVMTargetMachineOptionsRef instance.
const char * LLVMGetTargetName(LLVMTargetRef T)
Returns the name of a target.
struct LLVMOpaqueTargetMachineOptions * LLVMTargetMachineOptionsRef
Definition: TargetMachine.h:34
void LLVMSetTargetMachineGlobalISel(LLVMTargetMachineRef T, LLVMBool Enable)
Enable global instruction selection.
void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM)
Adds the target-specific analysis passes to the pass manager.
LLVMTargetRef LLVMGetTargetFromName(const char *Name)
Finds the target corresponding to the given name and stores it in T.
void LLVMSetTargetMachineFastISel(LLVMTargetMachineRef T, LLVMBool Enable)
Enable fast-path instruction selection.
const char * LLVMGetTargetDescription(LLVMTargetRef T)
Returns the description of a target.
char * LLVMGetDefaultTargetTriple(void)
Get a triple for the host machine as a string.
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, LLVMBool VerboseAsm)
Set the target machine's ASM verbosity.
LLVMTargetMachineOptionsRef LLVMCreateTargetMachineOptions(void)
Create a new set of options for an llvm::TargetMachine.
LLVMBool LLVMGetTargetFromTriple(const char *Triple, LLVMTargetRef *T, char **ErrorMessage)
Finds the target corresponding to the given triple and stores it in T.
char * LLVMNormalizeTargetTriple(const char *triple)
Normalize a target triple.
LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T)
Returns if the target as an ASM backend (required for emitting output)
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.
char * LLVMGetTargetMachineTriple(LLVMTargetMachineRef T)
Returns the triple used creating this target machine.
LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel)
Creates a new llvm::TargetMachine.
void LLVMTargetMachineOptionsSetABI(LLVMTargetMachineOptionsRef Options, const char *ABI)
LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T)
Returns the next llvm::Target given a previous one (or null if there's none)
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.
LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T)
Create a DataLayout based on the targetMachine.
LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T)
Returns if the target has a TargetMachine associated.
LLVMRelocMode
Definition: TargetMachine.h:45
LLVMCodeGenOptLevel
Definition: TargetMachine.h:38
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: Target.h:37
LLVMTargetMachineRef LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *Triple, LLVMTargetMachineOptionsRef Options)
Create a new llvm::TargetMachine.
LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T)
Returns the Target used in a TargetMachine.
LLVMGlobalISelAbortMode
Definition: TargetMachine.h:70
void LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options, LLVMCodeModel CodeModel)
void LLVMSetTargetMachineGlobalISelAbort(LLVMTargetMachineRef T, LLVMGlobalISelAbortMode Mode)
Set abort behaviour when global instruction selection fails to lower/select an instruction.
void LLVMDisposeTargetMachine(LLVMTargetMachineRef T)
Dispose the LLVMTargetMachineRef instance generated by LLVMCreateTargetMachine.
LLVMBool LLVMTargetHasJIT(LLVMTargetRef T)
Returns if the target has a JIT.
char * LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T)
Returns the feature string used creating this target machine.
@ LLVMAssemblyFile
Definition: TargetMachine.h:66
@ LLVMObjectFile
Definition: TargetMachine.h:67
@ LLVMCodeModelKernel
Definition: TargetMachine.h:60
@ LLVMCodeModelTiny
Definition: TargetMachine.h:58
@ LLVMCodeModelSmall
Definition: TargetMachine.h:59
@ LLVMCodeModelMedium
Definition: TargetMachine.h:61
@ LLVMCodeModelJITDefault
Definition: TargetMachine.h:57
@ LLVMCodeModelDefault
Definition: TargetMachine.h:56
@ LLVMCodeModelLarge
Definition: TargetMachine.h:62
@ LLVMRelocPIC
Definition: TargetMachine.h:48
@ LLVMRelocDynamicNoPic
Definition: TargetMachine.h:49
@ LLVMRelocStatic
Definition: TargetMachine.h:47
@ LLVMRelocRWPI
Definition: TargetMachine.h:51
@ LLVMRelocROPI
Definition: TargetMachine.h:50
@ LLVMRelocROPI_RWPI
Definition: TargetMachine.h:52
@ LLVMRelocDefault
Definition: TargetMachine.h:46
@ LLVMCodeGenLevelAggressive
Definition: TargetMachine.h:42
@ LLVMCodeGenLevelDefault
Definition: TargetMachine.h:41
@ LLVMCodeGenLevelNone
Definition: TargetMachine.h:39
@ LLVMCodeGenLevelLess
Definition: TargetMachine.h:40
@ LLVMGlobalISelAbortDisableWithDiag
Definition: TargetMachine.h:73
@ LLVMGlobalISelAbortDisable
Definition: TargetMachine.h:72
@ LLVMGlobalISelAbortEnable
Definition: TargetMachine.h:71