xref: /aosp_15_r20/external/llvm/include/llvm-c/TargetMachine.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker /*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\
2*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
3*9880d681SAndroid Build Coastguard Worker |*                     The LLVM Compiler Infrastructure                       *|
4*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
5*9880d681SAndroid Build Coastguard Worker |* This file is distributed under the University of Illinois Open Source      *|
6*9880d681SAndroid Build Coastguard Worker |* License. See LICENSE.TXT for details.                                      *|
7*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
8*9880d681SAndroid Build Coastguard Worker |*===----------------------------------------------------------------------===*|
9*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
10*9880d681SAndroid Build Coastguard Worker |* This header declares the C interface to the Target and TargetMachine       *|
11*9880d681SAndroid Build Coastguard Worker |* classes, which can be used to generate assembly or object files.           *|
12*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
13*9880d681SAndroid Build Coastguard Worker |* Many exotic languages can interoperate with C code but have a harder time  *|
14*9880d681SAndroid Build Coastguard Worker |* with C++ due to name mangling. So in addition to C, this interface enables *|
15*9880d681SAndroid Build Coastguard Worker |* tools written in such languages.                                           *|
16*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
17*9880d681SAndroid Build Coastguard Worker \*===----------------------------------------------------------------------===*/
18*9880d681SAndroid Build Coastguard Worker 
19*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_C_TARGETMACHINE_H
20*9880d681SAndroid Build Coastguard Worker #define LLVM_C_TARGETMACHINE_H
21*9880d681SAndroid Build Coastguard Worker 
22*9880d681SAndroid Build Coastguard Worker #include "llvm-c/Types.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm-c/Target.h"
24*9880d681SAndroid Build Coastguard Worker 
25*9880d681SAndroid Build Coastguard Worker #ifdef __cplusplus
26*9880d681SAndroid Build Coastguard Worker extern "C" {
27*9880d681SAndroid Build Coastguard Worker #endif
28*9880d681SAndroid Build Coastguard Worker typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
29*9880d681SAndroid Build Coastguard Worker typedef struct LLVMTarget *LLVMTargetRef;
30*9880d681SAndroid Build Coastguard Worker 
31*9880d681SAndroid Build Coastguard Worker typedef enum {
32*9880d681SAndroid Build Coastguard Worker     LLVMCodeGenLevelNone,
33*9880d681SAndroid Build Coastguard Worker     LLVMCodeGenLevelLess,
34*9880d681SAndroid Build Coastguard Worker     LLVMCodeGenLevelDefault,
35*9880d681SAndroid Build Coastguard Worker     LLVMCodeGenLevelAggressive
36*9880d681SAndroid Build Coastguard Worker } LLVMCodeGenOptLevel;
37*9880d681SAndroid Build Coastguard Worker 
38*9880d681SAndroid Build Coastguard Worker typedef enum {
39*9880d681SAndroid Build Coastguard Worker     LLVMRelocDefault,
40*9880d681SAndroid Build Coastguard Worker     LLVMRelocStatic,
41*9880d681SAndroid Build Coastguard Worker     LLVMRelocPIC,
42*9880d681SAndroid Build Coastguard Worker     LLVMRelocDynamicNoPic
43*9880d681SAndroid Build Coastguard Worker } LLVMRelocMode;
44*9880d681SAndroid Build Coastguard Worker 
45*9880d681SAndroid Build Coastguard Worker typedef enum {
46*9880d681SAndroid Build Coastguard Worker     LLVMCodeModelDefault,
47*9880d681SAndroid Build Coastguard Worker     LLVMCodeModelJITDefault,
48*9880d681SAndroid Build Coastguard Worker     LLVMCodeModelSmall,
49*9880d681SAndroid Build Coastguard Worker     LLVMCodeModelKernel,
50*9880d681SAndroid Build Coastguard Worker     LLVMCodeModelMedium,
51*9880d681SAndroid Build Coastguard Worker     LLVMCodeModelLarge
52*9880d681SAndroid Build Coastguard Worker } LLVMCodeModel;
53*9880d681SAndroid Build Coastguard Worker 
54*9880d681SAndroid Build Coastguard Worker typedef enum {
55*9880d681SAndroid Build Coastguard Worker     LLVMAssemblyFile,
56*9880d681SAndroid Build Coastguard Worker     LLVMObjectFile
57*9880d681SAndroid Build Coastguard Worker } LLVMCodeGenFileType;
58*9880d681SAndroid Build Coastguard Worker 
59*9880d681SAndroid Build Coastguard Worker /** Returns the first llvm::Target in the registered targets list. */
60*9880d681SAndroid Build Coastguard Worker LLVMTargetRef LLVMGetFirstTarget(void);
61*9880d681SAndroid Build Coastguard Worker /** Returns the next llvm::Target given a previous one (or null if there's none) */
62*9880d681SAndroid Build Coastguard Worker LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
63*9880d681SAndroid Build Coastguard Worker 
64*9880d681SAndroid Build Coastguard Worker /*===-- Target ------------------------------------------------------------===*/
65*9880d681SAndroid Build Coastguard Worker /** Finds the target corresponding to the given name and stores it in \p T.
66*9880d681SAndroid Build Coastguard Worker   Returns 0 on success. */
67*9880d681SAndroid Build Coastguard Worker LLVMTargetRef LLVMGetTargetFromName(const char *Name);
68*9880d681SAndroid Build Coastguard Worker 
69*9880d681SAndroid Build Coastguard Worker /** Finds the target corresponding to the given triple and stores it in \p T.
70*9880d681SAndroid Build Coastguard Worker   Returns 0 on success. Optionally returns any error in ErrorMessage.
71*9880d681SAndroid Build Coastguard Worker   Use LLVMDisposeMessage to dispose the message. */
72*9880d681SAndroid Build Coastguard Worker LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,
73*9880d681SAndroid Build Coastguard Worker                                  char **ErrorMessage);
74*9880d681SAndroid Build Coastguard Worker 
75*9880d681SAndroid Build Coastguard Worker /** Returns the name of a target. See llvm::Target::getName */
76*9880d681SAndroid Build Coastguard Worker const char *LLVMGetTargetName(LLVMTargetRef T);
77*9880d681SAndroid Build Coastguard Worker 
78*9880d681SAndroid Build Coastguard Worker /** Returns the description  of a target. See llvm::Target::getDescription */
79*9880d681SAndroid Build Coastguard Worker const char *LLVMGetTargetDescription(LLVMTargetRef T);
80*9880d681SAndroid Build Coastguard Worker 
81*9880d681SAndroid Build Coastguard Worker /** Returns if the target has a JIT */
82*9880d681SAndroid Build Coastguard Worker LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
83*9880d681SAndroid Build Coastguard Worker 
84*9880d681SAndroid Build Coastguard Worker /** Returns if the target has a TargetMachine associated */
85*9880d681SAndroid Build Coastguard Worker LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
86*9880d681SAndroid Build Coastguard Worker 
87*9880d681SAndroid Build Coastguard Worker /** Returns if the target as an ASM backend (required for emitting output) */
88*9880d681SAndroid Build Coastguard Worker LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
89*9880d681SAndroid Build Coastguard Worker 
90*9880d681SAndroid Build Coastguard Worker /*===-- Target Machine ----------------------------------------------------===*/
91*9880d681SAndroid Build Coastguard Worker /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
92*9880d681SAndroid Build Coastguard Worker LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
93*9880d681SAndroid Build Coastguard Worker   const char *Triple, const char *CPU, const char *Features,
94*9880d681SAndroid Build Coastguard Worker   LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
95*9880d681SAndroid Build Coastguard Worker 
96*9880d681SAndroid Build Coastguard Worker /** Dispose the LLVMTargetMachineRef instance generated by
97*9880d681SAndroid Build Coastguard Worker   LLVMCreateTargetMachine. */
98*9880d681SAndroid Build Coastguard Worker void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
99*9880d681SAndroid Build Coastguard Worker 
100*9880d681SAndroid Build Coastguard Worker /** Returns the Target used in a TargetMachine */
101*9880d681SAndroid Build Coastguard Worker LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
102*9880d681SAndroid Build Coastguard Worker 
103*9880d681SAndroid Build Coastguard Worker /** Returns the triple used creating this target machine. See
104*9880d681SAndroid Build Coastguard Worker   llvm::TargetMachine::getTriple. The result needs to be disposed with
105*9880d681SAndroid Build Coastguard Worker   LLVMDisposeMessage. */
106*9880d681SAndroid Build Coastguard Worker char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
107*9880d681SAndroid Build Coastguard Worker 
108*9880d681SAndroid Build Coastguard Worker /** Returns the cpu used creating this target machine. See
109*9880d681SAndroid Build Coastguard Worker   llvm::TargetMachine::getCPU. The result needs to be disposed with
110*9880d681SAndroid Build Coastguard Worker   LLVMDisposeMessage. */
111*9880d681SAndroid Build Coastguard Worker char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
112*9880d681SAndroid Build Coastguard Worker 
113*9880d681SAndroid Build Coastguard Worker /** Returns the feature string used creating this target machine. See
114*9880d681SAndroid Build Coastguard Worker   llvm::TargetMachine::getFeatureString. The result needs to be disposed with
115*9880d681SAndroid Build Coastguard Worker   LLVMDisposeMessage. */
116*9880d681SAndroid Build Coastguard Worker char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
117*9880d681SAndroid Build Coastguard Worker 
118*9880d681SAndroid Build Coastguard Worker /** Create a DataLayout based on the targetMachine. */
119*9880d681SAndroid Build Coastguard Worker LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T);
120*9880d681SAndroid Build Coastguard Worker 
121*9880d681SAndroid Build Coastguard Worker /** Set the target machine's ASM verbosity. */
122*9880d681SAndroid Build Coastguard Worker void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
123*9880d681SAndroid Build Coastguard Worker                                       LLVMBool VerboseAsm);
124*9880d681SAndroid Build Coastguard Worker 
125*9880d681SAndroid Build Coastguard Worker /** Emits an asm or object file for the given module to the filename. This
126*9880d681SAndroid Build Coastguard Worker   wraps several c++ only classes (among them a file stream). Returns any
127*9880d681SAndroid Build Coastguard Worker   error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
128*9880d681SAndroid Build Coastguard Worker LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
129*9880d681SAndroid Build Coastguard Worker   char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage);
130*9880d681SAndroid Build Coastguard Worker 
131*9880d681SAndroid Build Coastguard Worker /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
132*9880d681SAndroid Build Coastguard Worker LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
133*9880d681SAndroid Build Coastguard Worker   LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
134*9880d681SAndroid Build Coastguard Worker 
135*9880d681SAndroid Build Coastguard Worker /*===-- Triple ------------------------------------------------------------===*/
136*9880d681SAndroid Build Coastguard Worker /** Get a triple for the host machine as a string. The result needs to be
137*9880d681SAndroid Build Coastguard Worker   disposed with LLVMDisposeMessage. */
138*9880d681SAndroid Build Coastguard Worker char* LLVMGetDefaultTargetTriple(void);
139*9880d681SAndroid Build Coastguard Worker 
140*9880d681SAndroid Build Coastguard Worker /** Adds the target-specific analysis passes to the pass manager. */
141*9880d681SAndroid Build Coastguard Worker void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
142*9880d681SAndroid Build Coastguard Worker 
143*9880d681SAndroid Build Coastguard Worker #ifdef __cplusplus
144*9880d681SAndroid Build Coastguard Worker }
145*9880d681SAndroid Build Coastguard Worker #endif
146*9880d681SAndroid Build Coastguard Worker 
147*9880d681SAndroid Build Coastguard Worker #endif
148