Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:01

0001 /*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\
0002 |*                                                                            *|
0003 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
0004 |* Exceptions.                                                                *|
0005 |* See https://llvm.org/LICENSE.txt for license information.                  *|
0006 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
0007 |*                                                                            *|
0008 |*===----------------------------------------------------------------------===*|
0009 |*                                                                            *|
0010 |* This header declares the C interface to the Target and TargetMachine       *|
0011 |* classes, which can be used to generate assembly or object files.           *|
0012 |*                                                                            *|
0013 |* Many exotic languages can interoperate with C code but have a harder time  *|
0014 |* with C++ due to name mangling. So in addition to C, this interface enables *|
0015 |* tools written in such languages.                                           *|
0016 |*                                                                            *|
0017 \*===----------------------------------------------------------------------===*/
0018 
0019 #ifndef LLVM_C_TARGETMACHINE_H
0020 #define LLVM_C_TARGETMACHINE_H
0021 
0022 #include "llvm-c/ExternC.h"
0023 #include "llvm-c/Target.h"
0024 #include "llvm-c/Types.h"
0025 
0026 LLVM_C_EXTERN_C_BEGIN
0027 
0028 /**
0029  * @addtogroup LLVMCTarget
0030  *
0031  * @{
0032  */
0033 
0034 typedef struct LLVMOpaqueTargetMachineOptions *LLVMTargetMachineOptionsRef;
0035 typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
0036 typedef struct LLVMTarget *LLVMTargetRef;
0037 
0038 typedef enum {
0039     LLVMCodeGenLevelNone,
0040     LLVMCodeGenLevelLess,
0041     LLVMCodeGenLevelDefault,
0042     LLVMCodeGenLevelAggressive
0043 } LLVMCodeGenOptLevel;
0044 
0045 typedef enum {
0046     LLVMRelocDefault,
0047     LLVMRelocStatic,
0048     LLVMRelocPIC,
0049     LLVMRelocDynamicNoPic,
0050     LLVMRelocROPI,
0051     LLVMRelocRWPI,
0052     LLVMRelocROPI_RWPI
0053 } LLVMRelocMode;
0054 
0055 typedef enum {
0056     LLVMCodeModelDefault,
0057     LLVMCodeModelJITDefault,
0058     LLVMCodeModelTiny,
0059     LLVMCodeModelSmall,
0060     LLVMCodeModelKernel,
0061     LLVMCodeModelMedium,
0062     LLVMCodeModelLarge
0063 } LLVMCodeModel;
0064 
0065 typedef enum {
0066     LLVMAssemblyFile,
0067     LLVMObjectFile
0068 } LLVMCodeGenFileType;
0069 
0070 typedef enum {
0071   LLVMGlobalISelAbortEnable,
0072   LLVMGlobalISelAbortDisable,
0073   LLVMGlobalISelAbortDisableWithDiag,
0074 } LLVMGlobalISelAbortMode;
0075 
0076 /** Returns the first llvm::Target in the registered targets list. */
0077 LLVMTargetRef LLVMGetFirstTarget(void);
0078 /** Returns the next llvm::Target given a previous one (or null if there's none) */
0079 LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
0080 
0081 /*===-- Target ------------------------------------------------------------===*/
0082 /** Finds the target corresponding to the given name and stores it in \p T.
0083   Returns 0 on success. */
0084 LLVMTargetRef LLVMGetTargetFromName(const char *Name);
0085 
0086 /** Finds the target corresponding to the given triple and stores it in \p T.
0087   Returns 0 on success. Optionally returns any error in ErrorMessage.
0088   Use LLVMDisposeMessage to dispose the message. */
0089 LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,
0090                                  char **ErrorMessage);
0091 
0092 /** Returns the name of a target. See llvm::Target::getName */
0093 const char *LLVMGetTargetName(LLVMTargetRef T);
0094 
0095 /** Returns the description  of a target. See llvm::Target::getDescription */
0096 const char *LLVMGetTargetDescription(LLVMTargetRef T);
0097 
0098 /** Returns if the target has a JIT */
0099 LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
0100 
0101 /** Returns if the target has a TargetMachine associated */
0102 LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
0103 
0104 /** Returns if the target as an ASM backend (required for emitting output) */
0105 LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
0106 
0107 /*===-- Target Machine ----------------------------------------------------===*/
0108 /**
0109  * Create a new set of options for an llvm::TargetMachine.
0110  *
0111  * The returned option structure must be released with
0112  * LLVMDisposeTargetMachineOptions() after the call to
0113  * LLVMCreateTargetMachineWithOptions().
0114  */
0115 LLVMTargetMachineOptionsRef LLVMCreateTargetMachineOptions(void);
0116 
0117 /**
0118  * Dispose of an LLVMTargetMachineOptionsRef instance.
0119  */
0120 void LLVMDisposeTargetMachineOptions(LLVMTargetMachineOptionsRef Options);
0121 
0122 void LLVMTargetMachineOptionsSetCPU(LLVMTargetMachineOptionsRef Options,
0123                                     const char *CPU);
0124 
0125 /**
0126  * Set the list of features for the target machine.
0127  *
0128  * \param Features a comma-separated list of features.
0129  */
0130 void LLVMTargetMachineOptionsSetFeatures(LLVMTargetMachineOptionsRef Options,
0131                                          const char *Features);
0132 
0133 void LLVMTargetMachineOptionsSetABI(LLVMTargetMachineOptionsRef Options,
0134                                     const char *ABI);
0135 
0136 void LLVMTargetMachineOptionsSetCodeGenOptLevel(
0137     LLVMTargetMachineOptionsRef Options, LLVMCodeGenOptLevel Level);
0138 
0139 void LLVMTargetMachineOptionsSetRelocMode(LLVMTargetMachineOptionsRef Options,
0140                                           LLVMRelocMode Reloc);
0141 
0142 void LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options,
0143                                           LLVMCodeModel CodeModel);
0144 
0145 /**
0146  * Create a new llvm::TargetMachine.
0147  *
0148  * \param T the target to create a machine for.
0149  * \param Triple a triple describing the target machine.
0150  * \param Options additional configuration (see
0151  *                LLVMCreateTargetMachineOptions()).
0152  */
0153 LLVMTargetMachineRef
0154 LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *Triple,
0155                                    LLVMTargetMachineOptionsRef Options);
0156 
0157 /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
0158 LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
0159   const char *Triple, const char *CPU, const char *Features,
0160   LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
0161 
0162 /** Dispose the LLVMTargetMachineRef instance generated by
0163   LLVMCreateTargetMachine. */
0164 void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
0165 
0166 /** Returns the Target used in a TargetMachine */
0167 LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
0168 
0169 /** Returns the triple used creating this target machine. See
0170   llvm::TargetMachine::getTriple. The result needs to be disposed with
0171   LLVMDisposeMessage. */
0172 char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
0173 
0174 /** Returns the cpu used creating this target machine. See
0175   llvm::TargetMachine::getCPU. The result needs to be disposed with
0176   LLVMDisposeMessage. */
0177 char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
0178 
0179 /** Returns the feature string used creating this target machine. See
0180   llvm::TargetMachine::getFeatureString. The result needs to be disposed with
0181   LLVMDisposeMessage. */
0182 char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
0183 
0184 /** Create a DataLayout based on the targetMachine. */
0185 LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T);
0186 
0187 /** Set the target machine's ASM verbosity. */
0188 void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
0189                                       LLVMBool VerboseAsm);
0190 
0191 /** Enable fast-path instruction selection. */
0192 void LLVMSetTargetMachineFastISel(LLVMTargetMachineRef T, LLVMBool Enable);
0193 
0194 /** Enable global instruction selection. */
0195 void LLVMSetTargetMachineGlobalISel(LLVMTargetMachineRef T, LLVMBool Enable);
0196 
0197 /** Set abort behaviour when global instruction selection fails to lower/select
0198  * an instruction. */
0199 void LLVMSetTargetMachineGlobalISelAbort(LLVMTargetMachineRef T,
0200                                          LLVMGlobalISelAbortMode Mode);
0201 
0202 /** Enable the MachineOutliner pass. */
0203 void LLVMSetTargetMachineMachineOutliner(LLVMTargetMachineRef T,
0204                                          LLVMBool Enable);
0205 
0206 /** Emits an asm or object file for the given module to the filename. This
0207   wraps several c++ only classes (among them a file stream). Returns any
0208   error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
0209 LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
0210                                      const char *Filename,
0211                                      LLVMCodeGenFileType codegen,
0212                                      char **ErrorMessage);
0213 
0214 /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
0215 LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
0216   LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
0217 
0218 /*===-- Triple ------------------------------------------------------------===*/
0219 /** Get a triple for the host machine as a string. The result needs to be
0220   disposed with LLVMDisposeMessage. */
0221 char* LLVMGetDefaultTargetTriple(void);
0222 
0223 /** Normalize a target triple. The result needs to be disposed with
0224   LLVMDisposeMessage. */
0225 char* LLVMNormalizeTargetTriple(const char* triple);
0226 
0227 /** Get the host CPU as a string. The result needs to be disposed with
0228   LLVMDisposeMessage. */
0229 char* LLVMGetHostCPUName(void);
0230 
0231 /** Get the host CPU's features as a string. The result needs to be disposed
0232   with LLVMDisposeMessage. */
0233 char* LLVMGetHostCPUFeatures(void);
0234 
0235 /** Adds the target-specific analysis passes to the pass manager. */
0236 void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
0237 
0238 /**
0239  * @}
0240  */
0241 
0242 LLVM_C_EXTERN_C_END
0243 
0244 #endif