LLVM  14.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 
34 typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
35 typedef struct LLVMTarget *LLVMTargetRef;
36 
37 typedef enum {
43 
44 typedef enum {
53 
54 typedef enum {
63 
64 typedef 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. */
82 LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,
83  char **ErrorMessage);
84 
85 /** Returns the name of a target. See llvm::Target::getName */
86 const char *LLVMGetTargetName(LLVMTargetRef T);
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,
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  char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage);
140 
141 /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
143  LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
144 
145 /*===-- Triple ------------------------------------------------------------===*/
146 /** Get a triple for the host machine as a string. The result needs to be
147  disposed with LLVMDisposeMessage. */
148 char* LLVMGetDefaultTargetTriple(void);
149 
150 /** Normalize a target triple. The result needs to be disposed with
151  LLVMDisposeMessage. */
152 char* LLVMNormalizeTargetTriple(const char* triple);
153 
154 /** Get the host CPU as a string. The result needs to be disposed with
155  LLVMDisposeMessage. */
156 char* LLVMGetHostCPUName(void);
157 
158 /** Get the host CPU's features as a string. The result needs to be disposed
159  with LLVMDisposeMessage. */
160 char* LLVMGetHostCPUFeatures(void);
161 
162 /** Adds the target-specific analysis passes to the pass manager. */
164 
165 /**
166  * @}
167  */
168 
170 
171 #endif
LLVMCreateTargetMachine
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:102
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
LLVMGetTargetName
const char * LLVMGetTargetName(LLVMTargetRef T)
Returns the name of a target.
Definition: TargetMachineC.cpp:82
LLVMSetTargetMachineAsmVerbosity
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, LLVMBool VerboseAsm)
Set the target machine's ASM verbosity.
Definition: TargetMachineC.cpp:176
LLVMCodeGenFileType
LLVMCodeGenFileType
Definition: TargetMachine.h:64
LLVMRelocStatic
@ LLVMRelocStatic
Definition: TargetMachine.h:46
LLVMCodeGenOptLevel
LLVMCodeGenOptLevel
Definition: TargetMachine.h:37
Types.h
LLVMGetTargetDescription
const char * LLVMGetTargetDescription(LLVMTargetRef T)
Returns the description of a target.
Definition: TargetMachineC.cpp:86
codegen
Since we know that Vector is byte aligned and we know the element offset of we should change the load into a lve *x instead of doing a load store lve *x sequence Implement passing vectors by value into calls and receiving them as arguments GCC apparently tries to codegen
Definition: README_ALTIVEC.txt:46
LLVMCodeModelDefault
@ LLVMCodeModelDefault
Definition: TargetMachine.h:55
LLVMGetTargetMachineTarget
LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T)
Returns the Target used in a TargetMachine.
Definition: TargetMachineC.cpp:156
LLVMTargetMachineEmitToMemoryBuffer
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:232
T
#define T
Definition: Mips16ISelLowering.cpp:341
LLVMGetTargetFromName
LLVMTargetRef LLVMGetTargetFromName(const char *Name)
Finds the target corresponding to the given name and stores it in T.
Definition: TargetMachineC.cpp:59
LLVMRelocROPI
@ LLVMRelocROPI
Definition: TargetMachine.h:49
LLVMGetFirstTarget
LLVMTargetRef LLVMGetFirstTarget(void)
Returns the first llvm::Target in the registered targets list.
Definition: TargetMachineC.cpp:47
LLVMTargetDataRef
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: DataLayout.h:41
LLVMAssemblyFile
@ LLVMAssemblyFile
Definition: TargetMachine.h:65
LLVMCodeGenLevelLess
@ LLVMCodeGenLevelLess
Definition: TargetMachine.h:39
LLVMTargetHasTargetMachine
LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T)
Returns if the target has a TargetMachine associated.
Definition: TargetMachineC.cpp:94
LLVMTargetRef
struct LLVMTarget * LLVMTargetRef
Definition: TargetMachine.h:35
llvm::MSP430Attrs::CodeModel
CodeModel
Definition: MSP430Attributes.h:37
LLVMCreateTargetDataLayout
LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T)
Create a DataLayout based on the targetMachine.
Definition: TargetMachineC.cpp:181
LLVMRelocMode
LLVMRelocMode
Definition: TargetMachine.h:44
LLVMRelocPIC
@ LLVMRelocPIC
Definition: TargetMachine.h:47
LLVMTargetHasJIT
LLVMBool LLVMTargetHasJIT(LLVMTargetRef T)
Returns if the target has a JIT.
Definition: TargetMachineC.cpp:90
LLVMCodeModel
LLVMCodeModel
Definition: TargetMachine.h:54
Target.h
LLVMCodeGenLevelDefault
@ LLVMCodeGenLevelDefault
Definition: TargetMachine.h:40
LLVMGetTargetMachineCPU
char * LLVMGetTargetMachineCPU(LLVMTargetMachineRef T)
Returns the cpu used creating this target machine.
Definition: TargetMachineC.cpp:166
LLVMCodeModelSmall
@ LLVMCodeModelSmall
Definition: TargetMachine.h:58
LLVMCodeModelLarge
@ LLVMCodeModelLarge
Definition: TargetMachine.h:61
LLVMCodeGenLevelNone
@ LLVMCodeGenLevelNone
Definition: TargetMachine.h:38
LLVMPassManagerRef
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:127
LLVMCodeModelMedium
@ LLVMCodeModelMedium
Definition: TargetMachine.h:60
LLVMGetHostCPUFeatures
char * LLVMGetHostCPUFeatures(void)
Get the host CPU's features as a string.
Definition: TargetMachineC.cpp:257
LLVMDisposeTargetMachine
void LLVMDisposeTargetMachine(LLVMTargetMachineRef T)
Dispose the LLVMTargetMachineRef instance generated by LLVMCreateTargetMachine.
Definition: TargetMachineC.cpp:154
LLVMRelocDynamicNoPic
@ LLVMRelocDynamicNoPic
Definition: TargetMachine.h:48
LLVMCodeGenLevelAggressive
@ LLVMCodeGenLevelAggressive
Definition: TargetMachine.h:41
LLVMGetTargetMachineTriple
char * LLVMGetTargetMachineTriple(LLVMTargetMachineRef T)
Returns the triple used creating this target machine.
Definition: TargetMachineC.cpp:161
LLVMRelocROPI_RWPI
@ LLVMRelocROPI_RWPI
Definition: TargetMachine.h:51
llvm::PICLevel::Level
Level
Definition: CodeGen.h:33
LLVM_C_EXTERN_C_END
#define LLVM_C_EXTERN_C_END
Definition: ExternC.h:36
LLVMNormalizeTargetTriple
char * LLVMNormalizeTargetTriple(const char *triple)
Normalize a target triple.
Definition: TargetMachineC.cpp:249
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
LLVMCodeModelJITDefault
@ LLVMCodeModelJITDefault
Definition: TargetMachine.h:56
LLVMBool
int LLVMBool
Definition: Types.h:28
LLVMCodeModelKernel
@ LLVMCodeModelKernel
Definition: TargetMachine.h:59
LLVMGetDefaultTargetTriple
char * LLVMGetDefaultTargetTriple(void)
Get a triple for the host machine as a string.
Definition: TargetMachineC.cpp:245
LLVMGetTargetFromTriple
LLVMBool LLVMGetTargetFromTriple(const char *Triple, LLVMTargetRef *T, char **ErrorMessage)
Finds the target corresponding to the given triple and stores it in T.
Definition: TargetMachineC.cpp:66
LLVMGetTargetMachineFeatureString
char * LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T)
Returns the feature string used creating this target machine.
Definition: TargetMachineC.cpp:171
LLVM_C_EXTERN_C_BEGIN
#define LLVM_C_EXTERN_C_BEGIN
Definition: ExternC.h:35
LLVMTargetHasAsmBackend
LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T)
Returns if the target as an ASM backend (required for emitting output)
Definition: TargetMachineC.cpp:98
LLVMGetHostCPUName
char * LLVMGetHostCPUName(void)
Get the host CPU as a string.
Definition: TargetMachineC.cpp:253
LLVMTargetMachineEmitToFile
LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage)
Emits an asm or object file for the given module to the filename.
Definition: TargetMachineC.cpp:219
LLVMRelocRWPI
@ LLVMRelocRWPI
Definition: TargetMachine.h:50
LLVMCodeModelTiny
@ LLVMCodeModelTiny
Definition: TargetMachine.h:57
LLVMGetNextTarget
LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T)
Returns the next llvm::Target given a previous one (or null if there's none)
Definition: TargetMachineC.cpp:55
LLVMObjectFile
@ LLVMObjectFile
Definition: TargetMachine.h:66
LLVMRelocDefault
@ LLVMRelocDefault
Definition: TargetMachine.h:45
LLVMMemoryBufferRef
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
Definition: Types.h:48
LLVMAddAnalysisPasses
void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM)
Adds the target-specific analysis passes to the pass manager.
Definition: TargetMachineC.cpp:268
ExternC.h
LLVMTargetMachineRef
struct LLVMOpaqueTargetMachine * LLVMTargetMachineRef
Definition: TargetMachine.h:34
LLVMModuleRef
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61