blob: f82edd948b5958c9a82cf0a071abe075c73b8589 [file] [log] [blame]
Duncan Sands264d2e72012-04-11 10:25:24 +00001/*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\
2|* *|
Chandler Carruth2946cd72019-01-19 08:50:56 +00003|* 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 *|
Duncan Sands264d2e72012-04-11 10:25:24 +00007|* *|
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
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080022#include "llvm-c/ExternC.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include "llvm-c/Target.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000024#include "llvm-c/Types.h"
Duncan Sands264d2e72012-04-11 10:25:24 +000025
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080026LLVM_C_EXTERN_C_BEGIN
27
Filip Pizloc65a6d72013-05-01 22:41:26 +000028typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
Duncan Sands264d2e72012-04-11 10:25:24 +000029typedef struct LLVMTarget *LLVMTargetRef;
30
31typedef enum {
32 LLVMCodeGenLevelNone,
33 LLVMCodeGenLevelLess,
34 LLVMCodeGenLevelDefault,
35 LLVMCodeGenLevelAggressive
36} LLVMCodeGenOptLevel;
37
38typedef enum {
39 LLVMRelocDefault,
40 LLVMRelocStatic,
41 LLVMRelocPIC,
Robert Widmann7882b282019-01-03 00:33:44 +000042 LLVMRelocDynamicNoPic,
43 LLVMRelocROPI,
44 LLVMRelocRWPI,
45 LLVMRelocROPI_RWPI
Duncan Sands264d2e72012-04-11 10:25:24 +000046} LLVMRelocMode;
47
48typedef enum {
49 LLVMCodeModelDefault,
50 LLVMCodeModelJITDefault,
David Green9dd1d452018-08-22 11:31:39 +000051 LLVMCodeModelTiny,
Duncan Sands264d2e72012-04-11 10:25:24 +000052 LLVMCodeModelSmall,
53 LLVMCodeModelKernel,
54 LLVMCodeModelMedium,
55 LLVMCodeModelLarge
56} LLVMCodeModel;
57
58typedef enum {
59 LLVMAssemblyFile,
60 LLVMObjectFile
61} LLVMCodeGenFileType;
62
63/** Returns the first llvm::Target in the registered targets list. */
Anders Waldenborg5b154552013-09-19 19:43:55 +000064LLVMTargetRef LLVMGetFirstTarget(void);
Duncan Sands264d2e72012-04-11 10:25:24 +000065/** Returns the next llvm::Target given a previous one (or null if there's none) */
66LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
67
68/*===-- Target ------------------------------------------------------------===*/
NAKAMURA Takumiea1ff6f2014-01-10 11:12:01 +000069/** Finds the target corresponding to the given name and stores it in \p T.
Peter Zotov7b61b752013-11-06 10:25:18 +000070 Returns 0 on success. */
Peter Zotovb2c8b8a2013-11-15 02:51:01 +000071LLVMTargetRef LLVMGetTargetFromName(const char *Name);
Peter Zotov7b61b752013-11-06 10:25:18 +000072
73/** Finds the target corresponding to the given triple and stores it in \p T.
74 Returns 0 on success. Optionally returns any error in ErrorMessage.
75 Use LLVMDisposeMessage to dispose the message. */
76LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,
77 char **ErrorMessage);
78
Duncan Sands264d2e72012-04-11 10:25:24 +000079/** Returns the name of a target. See llvm::Target::getName */
80const char *LLVMGetTargetName(LLVMTargetRef T);
81
82/** Returns the description of a target. See llvm::Target::getDescription */
83const char *LLVMGetTargetDescription(LLVMTargetRef T);
84
85/** Returns if the target has a JIT */
86LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
87
88/** Returns if the target has a TargetMachine associated */
89LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
90
91/** Returns if the target as an ASM backend (required for emitting output) */
92LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
93
94/*===-- Target Machine ----------------------------------------------------===*/
95/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
Peter Zotov0e38fc82013-11-15 02:51:12 +000096LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
97 const char *Triple, const char *CPU, const char *Features,
98 LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
Duncan Sands264d2e72012-04-11 10:25:24 +000099
100/** Dispose the LLVMTargetMachineRef instance generated by
101 LLVMCreateTargetMachine. */
102void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
103
104/** Returns the Target used in a TargetMachine */
105LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
106
107/** Returns the triple used creating this target machine. See
108 llvm::TargetMachine::getTriple. The result needs to be disposed with
109 LLVMDisposeMessage. */
110char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
111
112/** Returns the cpu used creating this target machine. See
113 llvm::TargetMachine::getCPU. The result needs to be disposed with
114 LLVMDisposeMessage. */
115char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
116
117/** Returns the feature string used creating this target machine. See
118 llvm::TargetMachine::getFeatureString. The result needs to be disposed with
119 LLVMDisposeMessage. */
120char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
121
Amaury Sechet55909672016-02-16 05:11:24 +0000122/** Create a DataLayout based on the targetMachine. */
123LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T);
124
Peter Zotov7b61b752013-11-06 10:25:18 +0000125/** Set the target machine's ASM verbosity. */
126void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
127 LLVMBool VerboseAsm);
128
Duncan Sands264d2e72012-04-11 10:25:24 +0000129/** Emits an asm or object file for the given module to the filename. This
130 wraps several c++ only classes (among them a file stream). Returns any
131 error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
132LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
133 char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage);
134
Tom Stellardec924c52013-04-16 23:12:56 +0000135/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
136LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
137 LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
Peter Zotov7b61b752013-11-06 10:25:18 +0000138
139/*===-- Triple ------------------------------------------------------------===*/
140/** Get a triple for the host machine as a string. The result needs to be
141 disposed with LLVMDisposeMessage. */
142char* LLVMGetDefaultTargetTriple(void);
143
whitequark7c4a0742018-07-17 10:57:39 +0000144/** Normalize a target triple. The result needs to be disposed with
145 LLVMDisposeMessage. */
146char* LLVMNormalizeTargetTriple(const char* triple);
147
whitequark1ae61a62018-04-11 22:40:42 +0000148/** Get the host CPU as a string. The result needs to be disposed with
149 LLVMDisposeMessage. */
150char* LLVMGetHostCPUName(void);
151
152/** Get the host CPU's features as a string. The result needs to be disposed
153 with LLVMDisposeMessage. */
154char* LLVMGetHostCPUFeatures(void);
155
Juergen Ributzka5fe955c2014-01-23 19:23:28 +0000156/** Adds the target-specific analysis passes to the pass manager. */
157void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
158
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -0800159LLVM_C_EXTERN_C_END
Duncan Sands264d2e72012-04-11 10:25:24 +0000160
161#endif