LLVM 22.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#include "llvm-c/Visibility.h"
26
28
29/**
30 * @addtogroup LLVMCTarget
31 *
32 * @{
33 */
34
35typedef struct LLVMOpaqueTargetMachineOptions *LLVMTargetMachineOptionsRef;
36typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
37typedef struct LLVMTarget *LLVMTargetRef;
38
45
55
65
70
76
77/** Returns the first llvm::Target in the registered targets list. */
79/** Returns the next llvm::Target given a previous one (or null if there's none) */
81
82/*===-- Target ------------------------------------------------------------===*/
83/** Finds the target corresponding to the given name and stores it in \p T.
84 Returns 0 on success. */
86
87/** Finds the target corresponding to the given triple and stores it in \p T.
88 Returns 0 on success. Optionally returns any error in ErrorMessage.
89 Use LLVMDisposeMessage to dispose the message. */
92 char **ErrorMessage);
93
94/** Returns the name of a target. See llvm::Target::getName */
96
97/** Returns the description of a target. See llvm::Target::getDescription */
99
100/** Returns if the target has a JIT */
102
103/** Returns if the target has a TargetMachine associated */
105
106/** Returns if the target as an ASM backend (required for emitting output) */
108
109/*===-- Target Machine ----------------------------------------------------===*/
110/**
111 * Create a new set of options for an llvm::TargetMachine.
112 *
113 * The returned option structure must be released with
114 * LLVMDisposeTargetMachineOptions() after the call to
115 * LLVMCreateTargetMachineWithOptions().
116 */
118
119/**
120 * Dispose of an LLVMTargetMachineOptionsRef instance.
121 */
122LLVM_C_ABI void
124
125LLVM_C_ABI void
127 const char *CPU);
128
129/**
130 * Set the list of features for the target machine.
131 *
132 * \param Features a comma-separated list of features.
133 */
134LLVM_C_ABI void
136 const char *Features);
137
138LLVM_C_ABI void
140 const char *ABI);
141
142LLVM_C_ABI void
144 LLVMCodeGenOptLevel Level);
145
146LLVM_C_ABI void
148 LLVMRelocMode Reloc);
149
150LLVM_C_ABI void
152 LLVMCodeModel CodeModel);
153
154/**
155 * Create a new llvm::TargetMachine.
156 *
157 * \param T the target to create a machine for.
158 * \param Triple a triple describing the target machine.
159 * \param Options additional configuration (see
160 * LLVMCreateTargetMachineOptions()).
161 */
164
165/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
167 LLVMTargetRef T, const char *Triple, const char *CPU, const char *Features,
168 LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
169
170/** Dispose the LLVMTargetMachineRef instance generated by
171 LLVMCreateTargetMachine. */
173
174/** Returns the Target used in a TargetMachine */
176
177/** Returns the triple used creating this target machine. See
178 llvm::TargetMachine::getTriple. The result needs to be disposed with
179 LLVMDisposeMessage. */
181
182/** Returns the cpu used creating this target machine. See
183 llvm::TargetMachine::getCPU. The result needs to be disposed with
184 LLVMDisposeMessage. */
186
187/** Returns the feature string used creating this target machine. See
188 llvm::TargetMachine::getFeatureString. The result needs to be disposed with
189 LLVMDisposeMessage. */
191
192/** Create a DataLayout based on the targetMachine. */
194
195/** Set the target machine's ASM verbosity. */
197 LLVMBool VerboseAsm);
198
199/** Enable fast-path instruction selection. */
202
203/** Enable global instruction selection. */
206
207/** Set abort behaviour when global instruction selection fails to lower/select
208 * an instruction. */
209LLVM_C_ABI void
212
213/** Enable the MachineOutliner pass. */
216
217/** Emits an asm or object file for the given module to the filename. This
218 wraps several c++ only classes (among them a file stream). Returns any
219 error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
222 const char *Filename,
224 char **ErrorMessage);
225
226/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
229 char **ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
230
231/*===-- Triple ------------------------------------------------------------===*/
232/** Get a triple for the host machine as a string. The result needs to be
233 disposed with LLVMDisposeMessage. */
235
236/** Normalize a target triple. The result needs to be disposed with
237 LLVMDisposeMessage. */
238LLVM_C_ABI char *LLVMNormalizeTargetTriple(const char *triple);
239
240/** Get the host CPU as a string. The result needs to be disposed with
241 LLVMDisposeMessage. */
243
244/** Get the host CPU's features as a string. The result needs to be disposed
245 with LLVMDisposeMessage. */
247
248/** Adds the target-specific analysis passes to the pass manager. */
251
252/**
253 * @}
254 */
255
257
258#endif
@ Enable
#define LLVM_C_EXTERN_C_BEGIN
Definition ExternC.h:35
#define LLVM_C_EXTERN_C_END
Definition ExternC.h:36
static void codegen(const Config &Conf, TargetMachine *TM, AddStreamFn AddStream, unsigned Task, Module &Mod, const ModuleSummaryIndex &CombinedIndex)
static LVOptions Options
Definition LVOptions.cpp:25
#define T
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")))
#define LLVM_C_ABI
LLVM_C_ABI is the export/visibility macro used to mark symbols declared in llvm-c as exported when bu...
Definition Visibility.h:40
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
LLVM_C_ABI void LLVMTargetMachineOptionsSetCodeGenOptLevel(LLVMTargetMachineOptionsRef Options, LLVMCodeGenOptLevel Level)
LLVM_C_ABI void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM)
Adds the target-specific analysis passes to the pass manager.
LLVM_C_ABI char * LLVMGetTargetMachineCPU(LLVMTargetMachineRef T)
Returns the cpu used creating this target machine.
LLVM_C_ABI LLVMTargetRef LLVMGetFirstTarget(void)
Returns the first llvm::Target in the registered targets list.
LLVM_C_ABI void LLVMSetTargetMachineGlobalISelAbort(LLVMTargetMachineRef T, LLVMGlobalISelAbortMode Mode)
Set abort behaviour when global instruction selection fails to lower/select an instruction.
struct LLVMTarget * LLVMTargetRef
LLVM_C_ABI void LLVMTargetMachineOptionsSetABI(LLVMTargetMachineOptionsRef Options, const char *ABI)
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
LLVM_C_ABI LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T)
Returns the Target used in a TargetMachine.
LLVM_C_ABI LLVMTargetMachineRef LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *Triple, LLVMTargetMachineOptionsRef Options)
Create a new llvm::TargetMachine.
LLVMCodeModel
LLVM_C_ABI 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.
LLVM_C_ABI void LLVMSetTargetMachineMachineOutliner(LLVMTargetMachineRef T, LLVMBool Enable)
Enable the MachineOutliner pass.
struct LLVMOpaqueTargetMachineOptions * LLVMTargetMachineOptionsRef
LLVM_C_ABI LLVMTargetRef LLVMGetTargetFromName(const char *Name)
Finds the target corresponding to the given name and stores it in T.
LLVM_C_ABI void LLVMTargetMachineOptionsSetFeatures(LLVMTargetMachineOptionsRef Options, const char *Features)
Set the list of features for the target machine.
LLVM_C_ABI LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T)
Returns if the target as an ASM backend (required for emitting output)
LLVM_C_ABI char * LLVMGetDefaultTargetTriple(void)
Get a triple for the host machine as a string.
LLVM_C_ABI LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel)
Creates a new llvm::TargetMachine.
LLVM_C_ABI void LLVMTargetMachineOptionsSetRelocMode(LLVMTargetMachineOptionsRef Options, LLVMRelocMode Reloc)
LLVM_C_ABI LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T)
Returns the next llvm::Target given a previous one (or null if there's none)
LLVM_C_ABI char * LLVMGetHostCPUFeatures(void)
Get the host CPU's features as a string.
LLVM_C_ABI void LLVMDisposeTargetMachineOptions(LLVMTargetMachineOptionsRef Options)
Dispose of an LLVMTargetMachineOptionsRef instance.
LLVM_C_ABI LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T)
Returns if the target has a TargetMachine associated.
LLVM_C_ABI void LLVMSetTargetMachineFastISel(LLVMTargetMachineRef T, LLVMBool Enable)
Enable fast-path instruction selection.
LLVM_C_ABI char * LLVMNormalizeTargetTriple(const char *triple)
Normalize a target triple.
LLVM_C_ABI LLVMBool LLVMGetTargetFromTriple(const char *Triple, LLVMTargetRef *T, char **ErrorMessage)
Finds the target corresponding to the given triple and stores it in T.
LLVM_C_ABI char * LLVMGetTargetMachineTriple(LLVMTargetMachineRef T)
Returns the triple used creating this target machine.
LLVM_C_ABI char * LLVMGetHostCPUName(void)
Get the host CPU as a string.
LLVM_C_ABI void LLVMTargetMachineOptionsSetCPU(LLVMTargetMachineOptionsRef Options, const char *CPU)
LLVM_C_ABI void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, LLVMBool VerboseAsm)
Set the target machine's ASM verbosity.
LLVM_C_ABI void LLVMSetTargetMachineGlobalISel(LLVMTargetMachineRef T, LLVMBool Enable)
Enable global instruction selection.
LLVM_C_ABI void LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options, LLVMCodeModel CodeModel)
LLVM_C_ABI const char * LLVMGetTargetName(LLVMTargetRef T)
Returns the name of a target.
LLVM_C_ABI LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T)
Create a DataLayout based on the targetMachine.
LLVMRelocMode
LLVMCodeGenOptLevel
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition Target.h:38
LLVMGlobalISelAbortMode
LLVM_C_ABI 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.
LLVM_C_ABI const char * LLVMGetTargetDescription(LLVMTargetRef T)
Returns the description of a target.
LLVM_C_ABI char * LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T)
Returns the feature string used creating this target machine.
LLVM_C_ABI LLVMBool LLVMTargetHasJIT(LLVMTargetRef T)
Returns if the target has a JIT.
LLVM_C_ABI void LLVMDisposeTargetMachine(LLVMTargetMachineRef T)
Dispose the LLVMTargetMachineRef instance generated by LLVMCreateTargetMachine.
LLVM_C_ABI LLVMTargetMachineOptionsRef LLVMCreateTargetMachineOptions(void)
Create a new set of options for an llvm::TargetMachine.
@ LLVMAssemblyFile
@ LLVMObjectFile
@ LLVMCodeModelKernel
@ LLVMCodeModelTiny
@ LLVMCodeModelSmall
@ LLVMCodeModelMedium
@ LLVMCodeModelJITDefault
@ LLVMCodeModelDefault
@ LLVMCodeModelLarge
@ LLVMRelocPIC
@ LLVMRelocDynamicNoPic
@ LLVMRelocStatic
@ LLVMRelocRWPI
@ LLVMRelocROPI
@ LLVMRelocROPI_RWPI
@ LLVMRelocDefault
@ LLVMCodeGenLevelAggressive
@ LLVMCodeGenLevelDefault
@ LLVMCodeGenLevelNone
@ LLVMCodeGenLevelLess
@ LLVMGlobalISelAbortDisableWithDiag
@ LLVMGlobalISelAbortDisable
@ LLVMGlobalISelAbortEnable