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
26LLVM_C_EXTERN_C_BEGIN
27
28/**
29 * @addtogroup LLVMCTarget
30 *
31 * @{
32 */
33
34typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
35typedef struct LLVMTarget *LLVMTargetRef;
36
37typedef enum {
38 LLVMCodeGenLevelNone,
39 LLVMCodeGenLevelLess,
40 LLVMCodeGenLevelDefault,
41 LLVMCodeGenLevelAggressive
42} LLVMCodeGenOptLevel;
43
44typedef enum {
45 LLVMRelocDefault,
46 LLVMRelocStatic,
47 LLVMRelocPIC,
48 LLVMRelocDynamicNoPic,
49 LLVMRelocROPI,
50 LLVMRelocRWPI,
51 LLVMRelocROPI_RWPI
52} LLVMRelocMode;
53
54typedef enum {
55 LLVMCodeModelDefault,
56 LLVMCodeModelJITDefault,
57 LLVMCodeModelTiny,
58 LLVMCodeModelSmall,
59 LLVMCodeModelKernel,
60 LLVMCodeModelMedium,
61 LLVMCodeModelLarge
62} LLVMCodeModel;
63
64typedef enum {
65 LLVMAssemblyFile,
66 LLVMObjectFile
67} LLVMCodeGenFileType;
68
69/** Returns the first llvm::Target in the registered targets list. */
70LLVMTargetRef LLVMGetFirstTarget(void);
71/** Returns the next llvm::Target given a previous one (or null if there's none) */
72LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
73
74/*===-- Target ------------------------------------------------------------===*/
75/** Finds the target corresponding to the given name and stores it in \p T.
76 Returns 0 on success. */
77LLVMTargetRef LLVMGetTargetFromName(const char *Name);
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. */
82LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,
83 char **ErrorMessage);
84
85/** Returns the name of a target. See llvm::Target::getName */
86const char *LLVMGetTargetName(LLVMTargetRef T);
87
88/** Returns the description of a target. See llvm::Target::getDescription */
89const char *LLVMGetTargetDescription(LLVMTargetRef T);
90
91/** Returns if the target has a JIT */
92LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
93
94/** Returns if the target has a TargetMachine associated */
95LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
96
97/** Returns if the target as an ASM backend (required for emitting output) */
98LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
99
100/*===-- Target Machine ----------------------------------------------------===*/
101/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
102LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
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. */
108void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
109
110/** Returns the Target used in a TargetMachine */
111LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
112
113/** Returns the triple used creating this target machine. See
114 llvm::TargetMachine::getTriple. The result needs to be disposed with
115 LLVMDisposeMessage. */
116char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
117
118/** Returns the cpu used creating this target machine. See
119 llvm::TargetMachine::getCPU. The result needs to be disposed with
120 LLVMDisposeMessage. */
121char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
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. */
126char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
127
128/** Create a DataLayout based on the targetMachine. */
129LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T);
130
131/** Set the target machine's ASM verbosity. */
132void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
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. */
138LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
139 const char *Filename,
140 LLVMCodeGenFileType codegen,
141 char **ErrorMessage);
142
143/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
144LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
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. */
150char* LLVMGetDefaultTargetTriple(void);
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. */
165void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
166
167/**
168 * @}
169 */
170
171LLVM_C_EXTERN_C_END
172
173#endif
174

source code of llvm/include/llvm-c/TargetMachine.h