Path: blob/main/contrib/llvm-project/llvm/include/llvm-c/TargetMachine.h
35233 views
/*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\1|* *|2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|3|* Exceptions. *|4|* See https://llvm.org/LICENSE.txt for license information. *|5|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|6|* *|7|*===----------------------------------------------------------------------===*|8|* *|9|* This header declares the C interface to the Target and TargetMachine *|10|* classes, which can be used to generate assembly or object files. *|11|* *|12|* Many exotic languages can interoperate with C code but have a harder time *|13|* with C++ due to name mangling. So in addition to C, this interface enables *|14|* tools written in such languages. *|15|* *|16\*===----------------------------------------------------------------------===*/1718#ifndef LLVM_C_TARGETMACHINE_H19#define LLVM_C_TARGETMACHINE_H2021#include "llvm-c/ExternC.h"22#include "llvm-c/Target.h"23#include "llvm-c/Types.h"2425LLVM_C_EXTERN_C_BEGIN2627/**28* @addtogroup LLVMCTarget29*30* @{31*/3233typedef struct LLVMOpaqueTargetMachineOptions *LLVMTargetMachineOptionsRef;34typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;35typedef struct LLVMTarget *LLVMTargetRef;3637typedef enum {38LLVMCodeGenLevelNone,39LLVMCodeGenLevelLess,40LLVMCodeGenLevelDefault,41LLVMCodeGenLevelAggressive42} LLVMCodeGenOptLevel;4344typedef enum {45LLVMRelocDefault,46LLVMRelocStatic,47LLVMRelocPIC,48LLVMRelocDynamicNoPic,49LLVMRelocROPI,50LLVMRelocRWPI,51LLVMRelocROPI_RWPI52} LLVMRelocMode;5354typedef enum {55LLVMCodeModelDefault,56LLVMCodeModelJITDefault,57LLVMCodeModelTiny,58LLVMCodeModelSmall,59LLVMCodeModelKernel,60LLVMCodeModelMedium,61LLVMCodeModelLarge62} LLVMCodeModel;6364typedef enum {65LLVMAssemblyFile,66LLVMObjectFile67} LLVMCodeGenFileType;6869typedef enum {70LLVMGlobalISelAbortEnable,71LLVMGlobalISelAbortDisable,72LLVMGlobalISelAbortDisableWithDiag,73} LLVMGlobalISelAbortMode;7475/** Returns the first llvm::Target in the registered targets list. */76LLVMTargetRef LLVMGetFirstTarget(void);77/** Returns the next llvm::Target given a previous one (or null if there's none) */78LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);7980/*===-- Target ------------------------------------------------------------===*/81/** Finds the target corresponding to the given name and stores it in \p T.82Returns 0 on success. */83LLVMTargetRef LLVMGetTargetFromName(const char *Name);8485/** Finds the target corresponding to the given triple and stores it in \p T.86Returns 0 on success. Optionally returns any error in ErrorMessage.87Use LLVMDisposeMessage to dispose the message. */88LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,89char **ErrorMessage);9091/** Returns the name of a target. See llvm::Target::getName */92const char *LLVMGetTargetName(LLVMTargetRef T);9394/** Returns the description of a target. See llvm::Target::getDescription */95const char *LLVMGetTargetDescription(LLVMTargetRef T);9697/** Returns if the target has a JIT */98LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);99100/** Returns if the target has a TargetMachine associated */101LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);102103/** Returns if the target as an ASM backend (required for emitting output) */104LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);105106/*===-- Target Machine ----------------------------------------------------===*/107/**108* Create a new set of options for an llvm::TargetMachine.109*110* The returned option structure must be released with111* LLVMDisposeTargetMachineOptions() after the call to112* LLVMCreateTargetMachineWithOptions().113*/114LLVMTargetMachineOptionsRef LLVMCreateTargetMachineOptions(void);115116/**117* Dispose of an LLVMTargetMachineOptionsRef instance.118*/119void LLVMDisposeTargetMachineOptions(LLVMTargetMachineOptionsRef Options);120121void LLVMTargetMachineOptionsSetCPU(LLVMTargetMachineOptionsRef Options,122const char *CPU);123124/**125* Set the list of features for the target machine.126*127* \param Features a comma-separated list of features.128*/129void LLVMTargetMachineOptionsSetFeatures(LLVMTargetMachineOptionsRef Options,130const char *Features);131132void LLVMTargetMachineOptionsSetABI(LLVMTargetMachineOptionsRef Options,133const char *ABI);134135void LLVMTargetMachineOptionsSetCodeGenOptLevel(136LLVMTargetMachineOptionsRef Options, LLVMCodeGenOptLevel Level);137138void LLVMTargetMachineOptionsSetRelocMode(LLVMTargetMachineOptionsRef Options,139LLVMRelocMode Reloc);140141void LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options,142LLVMCodeModel CodeModel);143144/**145* Create a new llvm::TargetMachine.146*147* \param T the target to create a machine for.148* \param Triple a triple describing the target machine.149* \param Options additional configuration (see150* LLVMCreateTargetMachineOptions()).151*/152LLVMTargetMachineRef153LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *Triple,154LLVMTargetMachineOptionsRef Options);155156/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */157LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,158const char *Triple, const char *CPU, const char *Features,159LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);160161/** Dispose the LLVMTargetMachineRef instance generated by162LLVMCreateTargetMachine. */163void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);164165/** Returns the Target used in a TargetMachine */166LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);167168/** Returns the triple used creating this target machine. See169llvm::TargetMachine::getTriple. The result needs to be disposed with170LLVMDisposeMessage. */171char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);172173/** Returns the cpu used creating this target machine. See174llvm::TargetMachine::getCPU. The result needs to be disposed with175LLVMDisposeMessage. */176char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);177178/** Returns the feature string used creating this target machine. See179llvm::TargetMachine::getFeatureString. The result needs to be disposed with180LLVMDisposeMessage. */181char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);182183/** Create a DataLayout based on the targetMachine. */184LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T);185186/** Set the target machine's ASM verbosity. */187void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,188LLVMBool VerboseAsm);189190/** Enable fast-path instruction selection. */191void LLVMSetTargetMachineFastISel(LLVMTargetMachineRef T, LLVMBool Enable);192193/** Enable global instruction selection. */194void LLVMSetTargetMachineGlobalISel(LLVMTargetMachineRef T, LLVMBool Enable);195196/** Set abort behaviour when global instruction selection fails to lower/select197* an instruction. */198void LLVMSetTargetMachineGlobalISelAbort(LLVMTargetMachineRef T,199LLVMGlobalISelAbortMode Mode);200201/** Enable the MachineOutliner pass. */202void LLVMSetTargetMachineMachineOutliner(LLVMTargetMachineRef T,203LLVMBool Enable);204205/** Emits an asm or object file for the given module to the filename. This206wraps several c++ only classes (among them a file stream). Returns any207error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */208LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,209const char *Filename,210LLVMCodeGenFileType codegen,211char **ErrorMessage);212213/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */214LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,215LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);216217/*===-- Triple ------------------------------------------------------------===*/218/** Get a triple for the host machine as a string. The result needs to be219disposed with LLVMDisposeMessage. */220char* LLVMGetDefaultTargetTriple(void);221222/** Normalize a target triple. The result needs to be disposed with223LLVMDisposeMessage. */224char* LLVMNormalizeTargetTriple(const char* triple);225226/** Get the host CPU as a string. The result needs to be disposed with227LLVMDisposeMessage. */228char* LLVMGetHostCPUName(void);229230/** Get the host CPU's features as a string. The result needs to be disposed231with LLVMDisposeMessage. */232char* LLVMGetHostCPUFeatures(void);233234/** Adds the target-specific analysis passes to the pass manager. */235void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);236237/**238* @}239*/240241LLVM_C_EXTERN_C_END242243#endif244245246