LLVM 17.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 LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
35typedef struct LLVMTarget *LLVMTargetRef;
36
37typedef enum {
43
44typedef enum {
53
54typedef enum {
63
64typedef enum {
68
69/** Returns the first llvm::Target in the registered targets list. */
71/** Returns the next llvm::Target given a previous one (or null if there's none) */
73
74/*===-- Target ------------------------------------------------------------===*/
75/** Finds the target corresponding to the given name and stores it in \p T.
76 Returns 0 on success. */
78
79/** Finds the target corresponding to the given triple and stores it in \p T.
80 Returns 0 on success. Optionally returns any error in ErrorMessage.
81 Use LLVMDisposeMessage to dispose the message. */
83 char **ErrorMessage);
84
85/** Returns the name of a target. See llvm::Target::getName */
87
88/** Returns the description of a target. See llvm::Target::getDescription */
90
91/** Returns if the target has a JIT */
93
94/** Returns if the target has a TargetMachine associated */
96
97/** Returns if the target as an ASM backend (required for emitting output) */
99
100/*===-- Target Machine ----------------------------------------------------===*/
101/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
103 const char *Triple, const char *CPU, const char *Features,
104 LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
105
106/** Dispose the LLVMTargetMachineRef instance generated by
107 LLVMCreateTargetMachine. */
109
110/** Returns the Target used in a TargetMachine */
112
113/** Returns the triple used creating this target machine. See
114 llvm::TargetMachine::getTriple. The result needs to be disposed with
115 LLVMDisposeMessage. */
117
118/** Returns the cpu used creating this target machine. See
119 llvm::TargetMachine::getCPU. The result needs to be disposed with
120 LLVMDisposeMessage. */
122
123/** Returns the feature string used creating this target machine. See
124 llvm::TargetMachine::getFeatureString. The result needs to be disposed with
125 LLVMDisposeMessage. */
127
128/** Create a DataLayout based on the targetMachine. */
130
131/** Set the target machine's ASM verbosity. */
133 LLVMBool VerboseAsm);
134
135/** Emits an asm or object file for the given module to the filename. This
136 wraps several c++ only classes (among them a file stream). Returns any
137 error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
139 const char *Filename,
141 char **ErrorMessage);
142
143/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
145 LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
146
147/*===-- Triple ------------------------------------------------------------===*/
148/** Get a triple for the host machine as a string. The result needs to be
149 disposed with LLVMDisposeMessage. */
151
152/** Normalize a target triple. The result needs to be disposed with
153 LLVMDisposeMessage. */
154char* LLVMNormalizeTargetTriple(const char* triple);
155
156/** Get the host CPU as a string. The result needs to be disposed with
157 LLVMDisposeMessage. */
158char* LLVMGetHostCPUName(void);
159
160/** Get the host CPU's features as a string. The result needs to be disposed
161 with LLVMDisposeMessage. */
162char* LLVMGetHostCPUFeatures(void);
163
164/** Adds the target-specific analysis passes to the pass manager. */
166
167/**
168 * @}
169 */
170
172
173#endif
std::string Name
#define LLVM_C_EXTERN_C_BEGIN
Definition: ExternC.h:35
#define LLVM_C_EXTERN_C_END
Definition: ExternC.h:36
static void codegen(Module *M, llvm::raw_pwrite_stream &OS, function_ref< std::unique_ptr< TargetMachine >()> TMFactory, CodeGenFileType FileType)
Definition: ParallelCG.cpp:26
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:64
char * LLVMGetHostCPUFeatures(void)
Get the host CPU's features as a string.
LLVMTargetRef LLVMGetFirstTarget(void)
Returns the first llvm::Target in the registered targets list.
struct LLVMTarget * LLVMTargetRef
Definition: TargetMachine.h:35
char * LLVMGetHostCPUName(void)
Get the host CPU as a string.
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
Definition: TargetMachine.h:34
LLVMCodeModel
Definition: TargetMachine.h:54
char * LLVMGetTargetMachineCPU(LLVMTargetMachineRef T)
Returns the cpu used creating this target machine.
const char * LLVMGetTargetName(LLVMTargetRef T)
Returns the name of a target.
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.
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.
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.
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:44
LLVMCodeGenOptLevel
Definition: TargetMachine.h:37
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: Target.h:37
LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T)
Returns the Target used in a TargetMachine.
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:65
@ LLVMObjectFile
Definition: TargetMachine.h:66
@ LLVMCodeModelKernel
Definition: TargetMachine.h:59
@ LLVMCodeModelTiny
Definition: TargetMachine.h:57
@ LLVMCodeModelSmall
Definition: TargetMachine.h:58
@ LLVMCodeModelMedium
Definition: TargetMachine.h:60
@ LLVMCodeModelJITDefault
Definition: TargetMachine.h:56
@ LLVMCodeModelDefault
Definition: TargetMachine.h:55
@ LLVMCodeModelLarge
Definition: TargetMachine.h:61
@ LLVMRelocPIC
Definition: TargetMachine.h:47
@ LLVMRelocDynamicNoPic
Definition: TargetMachine.h:48
@ LLVMRelocStatic
Definition: TargetMachine.h:46
@ LLVMRelocRWPI
Definition: TargetMachine.h:50
@ LLVMRelocROPI
Definition: TargetMachine.h:49
@ LLVMRelocROPI_RWPI
Definition: TargetMachine.h:51
@ LLVMRelocDefault
Definition: TargetMachine.h:45
@ LLVMCodeGenLevelAggressive
Definition: TargetMachine.h:41
@ LLVMCodeGenLevelDefault
Definition: TargetMachine.h:40
@ LLVMCodeGenLevelNone
Definition: TargetMachine.h:38
@ LLVMCodeGenLevelLess
Definition: TargetMachine.h:39