2012-04-11 18:25:24 +08:00
|
|
|
/*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\
|
|
|
|
|* *|
|
2019-01-19 16:50:56 +08:00
|
|
|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
|
|
|
|* Exceptions. *|
|
|
|
|
|* See https://llvm.org/LICENSE.txt for license information. *|
|
|
|
|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
2012-04-11 18:25:24 +08:00
|
|
|
|* *|
|
|
|
|
|*===----------------------------------------------------------------------===*|
|
|
|
|
|* *|
|
|
|
|
|* This header declares the C interface to the Target and TargetMachine *|
|
|
|
|
|* classes, which can be used to generate assembly or object files. *|
|
|
|
|
|* *|
|
|
|
|
|* Many exotic languages can interoperate with C code but have a harder time *|
|
|
|
|
|* with C++ due to name mangling. So in addition to C, this interface enables *|
|
|
|
|
|* tools written in such languages. *|
|
|
|
|
|* *|
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#ifndef LLVM_C_TARGETMACHINE_H
|
|
|
|
#define LLVM_C_TARGETMACHINE_H
|
|
|
|
|
2019-11-15 05:57:57 +08:00
|
|
|
#include "llvm-c/ExternC.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm-c/Target.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm-c/Types.h"
|
2012-04-11 18:25:24 +08:00
|
|
|
|
2019-11-15 05:57:57 +08:00
|
|
|
LLVM_C_EXTERN_C_BEGIN
|
|
|
|
|
2013-05-02 06:41:26 +08:00
|
|
|
typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
|
2012-04-11 18:25:24 +08:00
|
|
|
typedef struct LLVMTarget *LLVMTargetRef;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LLVMCodeGenLevelNone,
|
|
|
|
LLVMCodeGenLevelLess,
|
|
|
|
LLVMCodeGenLevelDefault,
|
|
|
|
LLVMCodeGenLevelAggressive
|
|
|
|
} LLVMCodeGenOptLevel;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LLVMRelocDefault,
|
|
|
|
LLVMRelocStatic,
|
|
|
|
LLVMRelocPIC,
|
2019-01-03 08:33:44 +08:00
|
|
|
LLVMRelocDynamicNoPic,
|
|
|
|
LLVMRelocROPI,
|
|
|
|
LLVMRelocRWPI,
|
|
|
|
LLVMRelocROPI_RWPI
|
2012-04-11 18:25:24 +08:00
|
|
|
} LLVMRelocMode;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LLVMCodeModelDefault,
|
|
|
|
LLVMCodeModelJITDefault,
|
2018-08-22 19:31:39 +08:00
|
|
|
LLVMCodeModelTiny,
|
2012-04-11 18:25:24 +08:00
|
|
|
LLVMCodeModelSmall,
|
|
|
|
LLVMCodeModelKernel,
|
|
|
|
LLVMCodeModelMedium,
|
|
|
|
LLVMCodeModelLarge
|
|
|
|
} LLVMCodeModel;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LLVMAssemblyFile,
|
|
|
|
LLVMObjectFile
|
|
|
|
} LLVMCodeGenFileType;
|
|
|
|
|
|
|
|
/** Returns the first llvm::Target in the registered targets list. */
|
2013-09-20 03:43:55 +08:00
|
|
|
LLVMTargetRef LLVMGetFirstTarget(void);
|
2012-04-11 18:25:24 +08:00
|
|
|
/** Returns the next llvm::Target given a previous one (or null if there's none) */
|
|
|
|
LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
|
|
|
|
|
|
|
|
/*===-- Target ------------------------------------------------------------===*/
|
2014-01-10 19:12:01 +08:00
|
|
|
/** Finds the target corresponding to the given name and stores it in \p T.
|
2013-11-06 18:25:18 +08:00
|
|
|
Returns 0 on success. */
|
2013-11-15 10:51:01 +08:00
|
|
|
LLVMTargetRef LLVMGetTargetFromName(const char *Name);
|
2013-11-06 18:25:18 +08:00
|
|
|
|
|
|
|
/** Finds the target corresponding to the given triple and stores it in \p T.
|
|
|
|
Returns 0 on success. Optionally returns any error in ErrorMessage.
|
|
|
|
Use LLVMDisposeMessage to dispose the message. */
|
|
|
|
LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,
|
|
|
|
char **ErrorMessage);
|
|
|
|
|
2012-04-11 18:25:24 +08:00
|
|
|
/** Returns the name of a target. See llvm::Target::getName */
|
|
|
|
const char *LLVMGetTargetName(LLVMTargetRef T);
|
|
|
|
|
|
|
|
/** Returns the description of a target. See llvm::Target::getDescription */
|
|
|
|
const char *LLVMGetTargetDescription(LLVMTargetRef T);
|
|
|
|
|
|
|
|
/** Returns if the target has a JIT */
|
|
|
|
LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
|
|
|
|
|
|
|
|
/** Returns if the target has a TargetMachine associated */
|
|
|
|
LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
|
|
|
|
|
|
|
|
/** Returns if the target as an ASM backend (required for emitting output) */
|
|
|
|
LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
|
|
|
|
|
|
|
|
/*===-- Target Machine ----------------------------------------------------===*/
|
|
|
|
/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
|
2013-11-15 10:51:12 +08:00
|
|
|
LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
|
|
|
|
const char *Triple, const char *CPU, const char *Features,
|
|
|
|
LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
|
2012-04-11 18:25:24 +08:00
|
|
|
|
|
|
|
/** Dispose the LLVMTargetMachineRef instance generated by
|
|
|
|
LLVMCreateTargetMachine. */
|
|
|
|
void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
|
|
|
|
|
|
|
|
/** Returns the Target used in a TargetMachine */
|
|
|
|
LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
|
|
|
|
|
|
|
|
/** Returns the triple used creating this target machine. See
|
|
|
|
llvm::TargetMachine::getTriple. The result needs to be disposed with
|
|
|
|
LLVMDisposeMessage. */
|
|
|
|
char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
|
|
|
|
|
|
|
|
/** Returns the cpu used creating this target machine. See
|
|
|
|
llvm::TargetMachine::getCPU. The result needs to be disposed with
|
|
|
|
LLVMDisposeMessage. */
|
|
|
|
char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
|
|
|
|
|
|
|
|
/** Returns the feature string used creating this target machine. See
|
|
|
|
llvm::TargetMachine::getFeatureString. The result needs to be disposed with
|
|
|
|
LLVMDisposeMessage. */
|
|
|
|
char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
|
|
|
|
|
2016-02-16 13:11:24 +08:00
|
|
|
/** Create a DataLayout based on the targetMachine. */
|
|
|
|
LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T);
|
|
|
|
|
2013-11-06 18:25:18 +08:00
|
|
|
/** Set the target machine's ASM verbosity. */
|
|
|
|
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
|
|
|
|
LLVMBool VerboseAsm);
|
|
|
|
|
2012-04-11 18:25:24 +08:00
|
|
|
/** Emits an asm or object file for the given module to the filename. This
|
|
|
|
wraps several c++ only classes (among them a file stream). Returns any
|
|
|
|
error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
|
|
|
|
LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
|
|
|
|
char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage);
|
|
|
|
|
2013-04-17 07:12:56 +08:00
|
|
|
/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
|
|
|
|
LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
|
|
|
|
LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
|
2013-11-06 18:25:18 +08:00
|
|
|
|
|
|
|
/*===-- Triple ------------------------------------------------------------===*/
|
|
|
|
/** Get a triple for the host machine as a string. The result needs to be
|
|
|
|
disposed with LLVMDisposeMessage. */
|
|
|
|
char* LLVMGetDefaultTargetTriple(void);
|
|
|
|
|
2018-07-17 18:57:39 +08:00
|
|
|
/** Normalize a target triple. The result needs to be disposed with
|
|
|
|
LLVMDisposeMessage. */
|
|
|
|
char* LLVMNormalizeTargetTriple(const char* triple);
|
|
|
|
|
2018-04-12 06:40:42 +08:00
|
|
|
/** Get the host CPU as a string. The result needs to be disposed with
|
|
|
|
LLVMDisposeMessage. */
|
|
|
|
char* LLVMGetHostCPUName(void);
|
|
|
|
|
|
|
|
/** Get the host CPU's features as a string. The result needs to be disposed
|
|
|
|
with LLVMDisposeMessage. */
|
|
|
|
char* LLVMGetHostCPUFeatures(void);
|
|
|
|
|
2014-01-24 03:23:28 +08:00
|
|
|
/** Adds the target-specific analysis passes to the pass manager. */
|
|
|
|
void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
|
|
|
|
|
2019-11-15 05:57:57 +08:00
|
|
|
LLVM_C_EXTERN_C_END
|
2012-04-11 18:25:24 +08:00
|
|
|
|
|
|
|
#endif
|