1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header declares the C interface to libLLVMCore.a, which implements *|
11 |* the LLVM intermediate representation. *|
13 |* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14 |* parameters must be passed as base types. Despite the declared types, most *|
15 |* of the functions provided operate only on branches of the type hierarchy. *|
16 |* The declared parameter names are descriptive and specify which type is *|
17 |* required. Additionally, each type hierarchy is documented along with the *|
18 |* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19 |* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
20 |* form unwrap<RequiredType>(Param). *|
22 |* Many exotic languages can interoperate with C code but have a harder time *|
23 |* with C++ due to name mangling. So in addition to C, this interface enables *|
24 |* tools written in such languages. *|
26 |* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
27 |* helpers to perform opaque reference<-->pointer conversions. These helpers *|
28 |* are shorter and more tightly typed than writing the casts by hand when *|
29 |* authoring bindings. In assert builds, they will do runtime type checking. *|
31 \*===----------------------------------------------------------------------===*/
36 #include "llvm/Support/DataTypes.h"
40 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
41 and 'unwrap' conversion functions. */
42 #include "llvm/Module.h"
43 #include "llvm/PassRegistry.h"
44 #include "llvm/Support/IRBuilder.h"
55 * The top-level container for all LLVM global data. See the LLVMContext class.
57 typedef struct LLVMOpaqueContext
*LLVMContextRef
;
60 * The top-level container for all other LLVM Intermediate Representation (IR)
61 * objects. See the llvm::Module class.
63 typedef struct LLVMOpaqueModule
*LLVMModuleRef
;
66 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
69 typedef struct LLVMOpaqueType
*LLVMTypeRef
;
72 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
73 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
74 * llvm::AbstractTypeHolder class.
76 typedef struct LLVMOpaqueTypeHandle
*LLVMTypeHandleRef
;
78 typedef struct LLVMOpaqueValue
*LLVMValueRef
;
79 typedef struct LLVMOpaqueBasicBlock
*LLVMBasicBlockRef
;
80 typedef struct LLVMOpaqueBuilder
*LLVMBuilderRef
;
82 /* Interface used to provide a module to JIT or interpreter. This is now just a
83 * synonym for llvm::Module, but we have to keep using the different type to
84 * keep binary compatibility.
86 typedef struct LLVMOpaqueModuleProvider
*LLVMModuleProviderRef
;
88 /* Used to provide a module to JIT or interpreter.
89 * See the llvm::MemoryBuffer class.
91 typedef struct LLVMOpaqueMemoryBuffer
*LLVMMemoryBufferRef
;
93 /** See the llvm::PassManagerBase class. */
94 typedef struct LLVMOpaquePassManager
*LLVMPassManagerRef
;
96 /** See the llvm::PassRegistry class. */
97 typedef struct LLVMOpaquePassRegistry
*LLVMPassRegistryRef
;
99 /** Used to get the users and usees of a Value. See the llvm::Use class. */
100 typedef struct LLVMOpaqueUse
*LLVMUseRef
;
103 LLVMZExtAttribute
= 1<<0,
104 LLVMSExtAttribute
= 1<<1,
105 LLVMNoReturnAttribute
= 1<<2,
106 LLVMInRegAttribute
= 1<<3,
107 LLVMStructRetAttribute
= 1<<4,
108 LLVMNoUnwindAttribute
= 1<<5,
109 LLVMNoAliasAttribute
= 1<<6,
110 LLVMByValAttribute
= 1<<7,
111 LLVMNestAttribute
= 1<<8,
112 LLVMReadNoneAttribute
= 1<<9,
113 LLVMReadOnlyAttribute
= 1<<10,
114 LLVMNoInlineAttribute
= 1<<11,
115 LLVMAlwaysInlineAttribute
= 1<<12,
116 LLVMOptimizeForSizeAttribute
= 1<<13,
117 LLVMStackProtectAttribute
= 1<<14,
118 LLVMStackProtectReqAttribute
= 1<<15,
119 LLVMAlignment
= 31<<16,
120 LLVMNoCaptureAttribute
= 1<<21,
121 LLVMNoRedZoneAttribute
= 1<<22,
122 LLVMNoImplicitFloatAttribute
= 1<<23,
123 LLVMNakedAttribute
= 1<<24,
124 LLVMInlineHintAttribute
= 1<<25,
125 LLVMStackAlignment
= 7<<26
129 /* Terminator Instructions */
138 /* Standard Binary Operators */
152 /* Logical Operators */
160 /* Memory Operators */
164 LLVMGetElementPtr
= 29,
180 /* Other Operators */
189 LLVMExtractElement
= 50,
190 LLVMInsertElement
= 51,
191 LLVMShuffleVector
= 52,
192 LLVMExtractValue
= 53,
197 LLVMVoidTypeKind
, /**< type with no size */
198 LLVMFloatTypeKind
, /**< 32 bit floating point type */
199 LLVMDoubleTypeKind
, /**< 64 bit floating point type */
200 LLVMX86_FP80TypeKind
, /**< 80 bit floating point type (X87) */
201 LLVMFP128TypeKind
, /**< 128 bit floating point type (112-bit mantissa)*/
202 LLVMPPC_FP128TypeKind
, /**< 128 bit floating point type (two 64-bits) */
203 LLVMLabelTypeKind
, /**< Labels */
204 LLVMIntegerTypeKind
, /**< Arbitrary bit width integers */
205 LLVMFunctionTypeKind
, /**< Functions */
206 LLVMStructTypeKind
, /**< Structures */
207 LLVMArrayTypeKind
, /**< Arrays */
208 LLVMPointerTypeKind
, /**< Pointers */
209 LLVMOpaqueTypeKind
, /**< Opaque: type with unknown structure */
210 LLVMVectorTypeKind
, /**< SIMD 'packed' format, or other vector type */
211 LLVMMetadataTypeKind
, /**< Metadata */
212 LLVMX86_MMXTypeKind
/**< X86 MMX */
216 LLVMExternalLinkage
, /**< Externally visible function */
217 LLVMAvailableExternallyLinkage
,
218 LLVMLinkOnceAnyLinkage
, /**< Keep one copy of function when linking (inline)*/
219 LLVMLinkOnceODRLinkage
, /**< Same, but only replaced by something
221 LLVMWeakAnyLinkage
, /**< Keep one copy of function when linking (weak) */
222 LLVMWeakODRLinkage
, /**< Same, but only replaced by something
224 LLVMAppendingLinkage
, /**< Special purpose, only applies to global arrays */
225 LLVMInternalLinkage
, /**< Rename collisions when linking (static
227 LLVMPrivateLinkage
, /**< Like Internal, but omit from symbol table */
228 LLVMDLLImportLinkage
, /**< Function to be imported from DLL */
229 LLVMDLLExportLinkage
, /**< Function to be accessible from DLL */
230 LLVMExternalWeakLinkage
,/**< ExternalWeak linkage description */
231 LLVMGhostLinkage
, /**< Obsolete */
232 LLVMCommonLinkage
, /**< Tentative definitions */
233 LLVMLinkerPrivateLinkage
, /**< Like Private, but linker removes. */
234 LLVMLinkerPrivateWeakLinkage
, /**< Like LinkerPrivate, but is weak. */
235 LLVMLinkerPrivateWeakDefAutoLinkage
/**< Like LinkerPrivateWeak, but possibly
240 LLVMDefaultVisibility
, /**< The GV is visible */
241 LLVMHiddenVisibility
, /**< The GV is hidden */
242 LLVMProtectedVisibility
/**< The GV is protected */
247 LLVMFastCallConv
= 8,
248 LLVMColdCallConv
= 9,
249 LLVMX86StdcallCallConv
= 64,
250 LLVMX86FastcallCallConv
= 65
254 LLVMIntEQ
= 32, /**< equal */
255 LLVMIntNE
, /**< not equal */
256 LLVMIntUGT
, /**< unsigned greater than */
257 LLVMIntUGE
, /**< unsigned greater or equal */
258 LLVMIntULT
, /**< unsigned less than */
259 LLVMIntULE
, /**< unsigned less or equal */
260 LLVMIntSGT
, /**< signed greater than */
261 LLVMIntSGE
, /**< signed greater or equal */
262 LLVMIntSLT
, /**< signed less than */
263 LLVMIntSLE
/**< signed less or equal */
267 LLVMRealPredicateFalse
, /**< Always false (always folded) */
268 LLVMRealOEQ
, /**< True if ordered and equal */
269 LLVMRealOGT
, /**< True if ordered and greater than */
270 LLVMRealOGE
, /**< True if ordered and greater than or equal */
271 LLVMRealOLT
, /**< True if ordered and less than */
272 LLVMRealOLE
, /**< True if ordered and less than or equal */
273 LLVMRealONE
, /**< True if ordered and operands are unequal */
274 LLVMRealORD
, /**< True if ordered (no nans) */
275 LLVMRealUNO
, /**< True if unordered: isnan(X) | isnan(Y) */
276 LLVMRealUEQ
, /**< True if unordered or equal */
277 LLVMRealUGT
, /**< True if unordered or greater than */
278 LLVMRealUGE
, /**< True if unordered, greater than, or equal */
279 LLVMRealULT
, /**< True if unordered or less than */
280 LLVMRealULE
, /**< True if unordered, less than, or equal */
281 LLVMRealUNE
, /**< True if unordered or not equal */
282 LLVMRealPredicateTrue
/**< Always true (always folded) */
285 void LLVMInitializeCore(LLVMPassRegistryRef R
);
288 /*===-- Error handling ----------------------------------------------------===*/
290 void LLVMDisposeMessage(char *Message
);
293 /*===-- Contexts ----------------------------------------------------------===*/
295 /* Create and destroy contexts. */
296 LLVMContextRef
LLVMContextCreate(void);
297 LLVMContextRef
LLVMGetGlobalContext(void);
298 void LLVMContextDispose(LLVMContextRef C
);
300 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C
, const char* Name
,
302 unsigned LLVMGetMDKindID(const char* Name
, unsigned SLen
);
304 /*===-- Modules -----------------------------------------------------------===*/
306 /* Create and destroy modules. */
307 /** See llvm::Module::Module. */
308 LLVMModuleRef
LLVMModuleCreateWithName(const char *ModuleID
);
309 LLVMModuleRef
LLVMModuleCreateWithNameInContext(const char *ModuleID
,
312 /** See llvm::Module::~Module. */
313 void LLVMDisposeModule(LLVMModuleRef M
);
315 /** Data layout. See Module::getDataLayout. */
316 const char *LLVMGetDataLayout(LLVMModuleRef M
);
317 void LLVMSetDataLayout(LLVMModuleRef M
, const char *Triple
);
319 /** Target triple. See Module::getTargetTriple. */
320 const char *LLVMGetTarget(LLVMModuleRef M
);
321 void LLVMSetTarget(LLVMModuleRef M
, const char *Triple
);
323 /** See Module::addTypeName. */
324 LLVMBool
LLVMAddTypeName(LLVMModuleRef M
, const char *Name
, LLVMTypeRef Ty
);
325 void LLVMDeleteTypeName(LLVMModuleRef M
, const char *Name
);
326 LLVMTypeRef
LLVMGetTypeByName(LLVMModuleRef M
, const char *Name
);
327 const char *LLVMGetTypeName(LLVMModuleRef M
, LLVMTypeRef Ty
);
329 /** See Module::dump. */
330 void LLVMDumpModule(LLVMModuleRef M
);
332 /** See Module::setModuleInlineAsm. */
333 void LLVMSetModuleInlineAsm(LLVMModuleRef M
, const char *Asm
);
335 /** See Module::getContext. */
336 LLVMContextRef
LLVMGetModuleContext(LLVMModuleRef M
);
338 /*===-- Types -------------------------------------------------------------===*/
340 /* LLVM types conform to the following hierarchy:
355 /** See llvm::LLVMTypeKind::getTypeID. */
356 LLVMTypeKind
LLVMGetTypeKind(LLVMTypeRef Ty
);
358 /** See llvm::LLVMType::getContext. */
359 LLVMContextRef
LLVMGetTypeContext(LLVMTypeRef Ty
);
361 /* Operations on integer types */
362 LLVMTypeRef
LLVMInt1TypeInContext(LLVMContextRef C
);
363 LLVMTypeRef
LLVMInt8TypeInContext(LLVMContextRef C
);
364 LLVMTypeRef
LLVMInt16TypeInContext(LLVMContextRef C
);
365 LLVMTypeRef
LLVMInt32TypeInContext(LLVMContextRef C
);
366 LLVMTypeRef
LLVMInt64TypeInContext(LLVMContextRef C
);
367 LLVMTypeRef
LLVMIntTypeInContext(LLVMContextRef C
, unsigned NumBits
);
369 LLVMTypeRef
LLVMInt1Type(void);
370 LLVMTypeRef
LLVMInt8Type(void);
371 LLVMTypeRef
LLVMInt16Type(void);
372 LLVMTypeRef
LLVMInt32Type(void);
373 LLVMTypeRef
LLVMInt64Type(void);
374 LLVMTypeRef
LLVMIntType(unsigned NumBits
);
375 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy
);
377 /* Operations on real types */
378 LLVMTypeRef
LLVMFloatTypeInContext(LLVMContextRef C
);
379 LLVMTypeRef
LLVMDoubleTypeInContext(LLVMContextRef C
);
380 LLVMTypeRef
LLVMX86FP80TypeInContext(LLVMContextRef C
);
381 LLVMTypeRef
LLVMFP128TypeInContext(LLVMContextRef C
);
382 LLVMTypeRef
LLVMPPCFP128TypeInContext(LLVMContextRef C
);
384 LLVMTypeRef
LLVMFloatType(void);
385 LLVMTypeRef
LLVMDoubleType(void);
386 LLVMTypeRef
LLVMX86FP80Type(void);
387 LLVMTypeRef
LLVMFP128Type(void);
388 LLVMTypeRef
LLVMPPCFP128Type(void);
390 /* Operations on function types */
391 LLVMTypeRef
LLVMFunctionType(LLVMTypeRef ReturnType
,
392 LLVMTypeRef
*ParamTypes
, unsigned ParamCount
,
394 LLVMBool
LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy
);
395 LLVMTypeRef
LLVMGetReturnType(LLVMTypeRef FunctionTy
);
396 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy
);
397 void LLVMGetParamTypes(LLVMTypeRef FunctionTy
, LLVMTypeRef
*Dest
);
399 /* Operations on struct types */
400 LLVMTypeRef
LLVMStructTypeInContext(LLVMContextRef C
, LLVMTypeRef
*ElementTypes
,
401 unsigned ElementCount
, LLVMBool Packed
);
402 LLVMTypeRef
LLVMStructType(LLVMTypeRef
*ElementTypes
, unsigned ElementCount
,
404 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy
);
405 void LLVMGetStructElementTypes(LLVMTypeRef StructTy
, LLVMTypeRef
*Dest
);
406 LLVMBool
LLVMIsPackedStruct(LLVMTypeRef StructTy
);
408 /* Operations on array, pointer, and vector types (sequence types) */
409 LLVMTypeRef
LLVMArrayType(LLVMTypeRef ElementType
, unsigned ElementCount
);
410 LLVMTypeRef
LLVMPointerType(LLVMTypeRef ElementType
, unsigned AddressSpace
);
411 LLVMTypeRef
LLVMVectorType(LLVMTypeRef ElementType
, unsigned ElementCount
);
413 LLVMTypeRef
LLVMGetElementType(LLVMTypeRef Ty
);
414 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy
);
415 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy
);
416 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy
);
418 /* Operations on other types */
419 LLVMTypeRef
LLVMVoidTypeInContext(LLVMContextRef C
);
420 LLVMTypeRef
LLVMLabelTypeInContext(LLVMContextRef C
);
421 LLVMTypeRef
LLVMOpaqueTypeInContext(LLVMContextRef C
);
422 LLVMTypeRef
LLVMX86MMXTypeInContext(LLVMContextRef C
);
424 LLVMTypeRef
LLVMVoidType(void);
425 LLVMTypeRef
LLVMLabelType(void);
426 LLVMTypeRef
LLVMOpaqueType(void);
427 LLVMTypeRef
LLVMX86MMXType(void);
429 /* Operations on type handles */
430 LLVMTypeHandleRef
LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy
);
431 void LLVMRefineType(LLVMTypeRef AbstractTy
, LLVMTypeRef ConcreteTy
);
432 LLVMTypeRef
LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle
);
433 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle
);
436 /*===-- Values ------------------------------------------------------------===*/
438 /* The bulk of LLVM's object model consists of values, which comprise a very
439 * rich type hierarchy.
442 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
448 macro(ConstantAggregateZero) \
449 macro(ConstantArray) \
450 macro(ConstantExpr) \
453 macro(ConstantPointerNull) \
454 macro(ConstantStruct) \
455 macro(ConstantVector) \
459 macro(GlobalVariable) \
462 macro(BinaryOperator) \
464 macro(IntrinsicInst) \
465 macro(DbgInfoIntrinsic) \
466 macro(DbgDeclareInst) \
467 macro(EHSelectorInst) \
468 macro(MemIntrinsic) \
475 macro(ExtractElementInst) \
476 macro(GetElementPtrInst) \
477 macro(InsertElementInst) \
478 macro(InsertValueInst) \
481 macro(ShuffleVectorInst) \
483 macro(TerminatorInst) \
488 macro(UnreachableInst) \
490 macro(UnaryInstruction) \
498 macro(IntToPtrInst) \
499 macro(PtrToIntInst) \
505 macro(ExtractValueInst) \
509 /* Operations on all values */
510 LLVMTypeRef
LLVMTypeOf(LLVMValueRef Val
);
511 const char *LLVMGetValueName(LLVMValueRef Val
);
512 void LLVMSetValueName(LLVMValueRef Val
, const char *Name
);
513 void LLVMDumpValue(LLVMValueRef Val
);
514 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal
, LLVMValueRef NewVal
);
515 int LLVMHasMetadata(LLVMValueRef Val
);
516 LLVMValueRef
LLVMGetMetadata(LLVMValueRef Val
, unsigned KindID
);
517 void LLVMSetMetadata(LLVMValueRef Val
, unsigned KindID
, LLVMValueRef Node
);
519 /* Conversion functions. Return the input value if it is an instance of the
520 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
521 #define LLVM_DECLARE_VALUE_CAST(name) \
522 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
523 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST
)
525 /* Operations on Uses */
526 LLVMUseRef
LLVMGetFirstUse(LLVMValueRef Val
);
527 LLVMUseRef
LLVMGetNextUse(LLVMUseRef U
);
528 LLVMValueRef
LLVMGetUser(LLVMUseRef U
);
529 LLVMValueRef
LLVMGetUsedValue(LLVMUseRef U
);
531 /* Operations on Users */
532 LLVMValueRef
LLVMGetOperand(LLVMValueRef Val
, unsigned Index
);
533 void LLVMSetOperand(LLVMValueRef User
, unsigned Index
, LLVMValueRef Val
);
534 int LLVMGetNumOperands(LLVMValueRef Val
);
536 /* Operations on constants of any type */
537 LLVMValueRef
LLVMConstNull(LLVMTypeRef Ty
); /* all zeroes */
538 LLVMValueRef
LLVMConstAllOnes(LLVMTypeRef Ty
); /* only for int/vector */
539 LLVMValueRef
LLVMGetUndef(LLVMTypeRef Ty
);
540 LLVMBool
LLVMIsConstant(LLVMValueRef Val
);
541 LLVMBool
LLVMIsNull(LLVMValueRef Val
);
542 LLVMBool
LLVMIsUndef(LLVMValueRef Val
);
543 LLVMValueRef
LLVMConstPointerNull(LLVMTypeRef Ty
);
545 /* Operations on metadata */
546 LLVMValueRef
LLVMMDStringInContext(LLVMContextRef C
, const char *Str
,
548 LLVMValueRef
LLVMMDString(const char *Str
, unsigned SLen
);
549 LLVMValueRef
LLVMMDNodeInContext(LLVMContextRef C
, LLVMValueRef
*Vals
,
551 LLVMValueRef
LLVMMDNode(LLVMValueRef
*Vals
, unsigned Count
);
553 /* Operations on scalar constants */
554 LLVMValueRef
LLVMConstInt(LLVMTypeRef IntTy
, unsigned long long N
,
555 LLVMBool SignExtend
);
556 LLVMValueRef
LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy
,
558 const uint64_t Words
[]);
559 LLVMValueRef
LLVMConstIntOfString(LLVMTypeRef IntTy
, const char *Text
,
561 LLVMValueRef
LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy
, const char *Text
,
562 unsigned SLen
, uint8_t Radix
);
563 LLVMValueRef
LLVMConstReal(LLVMTypeRef RealTy
, double N
);
564 LLVMValueRef
LLVMConstRealOfString(LLVMTypeRef RealTy
, const char *Text
);
565 LLVMValueRef
LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy
, const char *Text
,
567 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal
);
568 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal
);
571 /* Operations on composite constants */
572 LLVMValueRef
LLVMConstStringInContext(LLVMContextRef C
, const char *Str
,
573 unsigned Length
, LLVMBool DontNullTerminate
);
574 LLVMValueRef
LLVMConstStructInContext(LLVMContextRef C
,
575 LLVMValueRef
*ConstantVals
,
576 unsigned Count
, LLVMBool Packed
);
578 LLVMValueRef
LLVMConstString(const char *Str
, unsigned Length
,
579 LLVMBool DontNullTerminate
);
580 LLVMValueRef
LLVMConstArray(LLVMTypeRef ElementTy
,
581 LLVMValueRef
*ConstantVals
, unsigned Length
);
582 LLVMValueRef
LLVMConstStruct(LLVMValueRef
*ConstantVals
, unsigned Count
,
584 LLVMValueRef
LLVMConstVector(LLVMValueRef
*ScalarConstantVals
, unsigned Size
);
586 /* Constant expressions */
587 LLVMOpcode
LLVMGetConstOpcode(LLVMValueRef ConstantVal
);
588 LLVMValueRef
LLVMAlignOf(LLVMTypeRef Ty
);
589 LLVMValueRef
LLVMSizeOf(LLVMTypeRef Ty
);
590 LLVMValueRef
LLVMConstNeg(LLVMValueRef ConstantVal
);
591 LLVMValueRef
LLVMConstNSWNeg(LLVMValueRef ConstantVal
);
592 LLVMValueRef
LLVMConstNUWNeg(LLVMValueRef ConstantVal
);
593 LLVMValueRef
LLVMConstFNeg(LLVMValueRef ConstantVal
);
594 LLVMValueRef
LLVMConstNot(LLVMValueRef ConstantVal
);
595 LLVMValueRef
LLVMConstAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
596 LLVMValueRef
LLVMConstNSWAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
597 LLVMValueRef
LLVMConstNUWAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
598 LLVMValueRef
LLVMConstFAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
599 LLVMValueRef
LLVMConstSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
600 LLVMValueRef
LLVMConstNSWSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
601 LLVMValueRef
LLVMConstNUWSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
602 LLVMValueRef
LLVMConstFSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
603 LLVMValueRef
LLVMConstMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
604 LLVMValueRef
LLVMConstNSWMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
605 LLVMValueRef
LLVMConstNUWMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
606 LLVMValueRef
LLVMConstFMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
607 LLVMValueRef
LLVMConstUDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
608 LLVMValueRef
LLVMConstSDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
609 LLVMValueRef
LLVMConstExactSDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
610 LLVMValueRef
LLVMConstFDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
611 LLVMValueRef
LLVMConstURem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
612 LLVMValueRef
LLVMConstSRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
613 LLVMValueRef
LLVMConstFRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
614 LLVMValueRef
LLVMConstAnd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
615 LLVMValueRef
LLVMConstOr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
616 LLVMValueRef
LLVMConstXor(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
617 LLVMValueRef
LLVMConstICmp(LLVMIntPredicate Predicate
,
618 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
619 LLVMValueRef
LLVMConstFCmp(LLVMRealPredicate Predicate
,
620 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
621 LLVMValueRef
LLVMConstShl(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
622 LLVMValueRef
LLVMConstLShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
623 LLVMValueRef
LLVMConstAShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
);
624 LLVMValueRef
LLVMConstGEP(LLVMValueRef ConstantVal
,
625 LLVMValueRef
*ConstantIndices
, unsigned NumIndices
);
626 LLVMValueRef
LLVMConstInBoundsGEP(LLVMValueRef ConstantVal
,
627 LLVMValueRef
*ConstantIndices
,
628 unsigned NumIndices
);
629 LLVMValueRef
LLVMConstTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
630 LLVMValueRef
LLVMConstSExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
631 LLVMValueRef
LLVMConstZExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
632 LLVMValueRef
LLVMConstFPTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
633 LLVMValueRef
LLVMConstFPExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
634 LLVMValueRef
LLVMConstUIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
635 LLVMValueRef
LLVMConstSIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
636 LLVMValueRef
LLVMConstFPToUI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
637 LLVMValueRef
LLVMConstFPToSI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
638 LLVMValueRef
LLVMConstPtrToInt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
639 LLVMValueRef
LLVMConstIntToPtr(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
640 LLVMValueRef
LLVMConstBitCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
641 LLVMValueRef
LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal
,
643 LLVMValueRef
LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal
,
645 LLVMValueRef
LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal
,
647 LLVMValueRef
LLVMConstPointerCast(LLVMValueRef ConstantVal
,
649 LLVMValueRef
LLVMConstIntCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
,
651 LLVMValueRef
LLVMConstFPCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
);
652 LLVMValueRef
LLVMConstSelect(LLVMValueRef ConstantCondition
,
653 LLVMValueRef ConstantIfTrue
,
654 LLVMValueRef ConstantIfFalse
);
655 LLVMValueRef
LLVMConstExtractElement(LLVMValueRef VectorConstant
,
656 LLVMValueRef IndexConstant
);
657 LLVMValueRef
LLVMConstInsertElement(LLVMValueRef VectorConstant
,
658 LLVMValueRef ElementValueConstant
,
659 LLVMValueRef IndexConstant
);
660 LLVMValueRef
LLVMConstShuffleVector(LLVMValueRef VectorAConstant
,
661 LLVMValueRef VectorBConstant
,
662 LLVMValueRef MaskConstant
);
663 LLVMValueRef
LLVMConstExtractValue(LLVMValueRef AggConstant
, unsigned *IdxList
,
665 LLVMValueRef
LLVMConstInsertValue(LLVMValueRef AggConstant
,
666 LLVMValueRef ElementValueConstant
,
667 unsigned *IdxList
, unsigned NumIdx
);
668 LLVMValueRef
LLVMConstInlineAsm(LLVMTypeRef Ty
,
669 const char *AsmString
, const char *Constraints
,
670 LLVMBool HasSideEffects
, LLVMBool IsAlignStack
);
671 LLVMValueRef
LLVMBlockAddress(LLVMValueRef F
, LLVMBasicBlockRef BB
);
673 /* Operations on global variables, functions, and aliases (globals) */
674 LLVMModuleRef
LLVMGetGlobalParent(LLVMValueRef Global
);
675 LLVMBool
LLVMIsDeclaration(LLVMValueRef Global
);
676 LLVMLinkage
LLVMGetLinkage(LLVMValueRef Global
);
677 void LLVMSetLinkage(LLVMValueRef Global
, LLVMLinkage Linkage
);
678 const char *LLVMGetSection(LLVMValueRef Global
);
679 void LLVMSetSection(LLVMValueRef Global
, const char *Section
);
680 LLVMVisibility
LLVMGetVisibility(LLVMValueRef Global
);
681 void LLVMSetVisibility(LLVMValueRef Global
, LLVMVisibility Viz
);
682 unsigned LLVMGetAlignment(LLVMValueRef Global
);
683 void LLVMSetAlignment(LLVMValueRef Global
, unsigned Bytes
);
685 /* Operations on global variables */
686 LLVMValueRef
LLVMAddGlobal(LLVMModuleRef M
, LLVMTypeRef Ty
, const char *Name
);
687 LLVMValueRef
LLVMAddGlobalInAddressSpace(LLVMModuleRef M
, LLVMTypeRef Ty
,
689 unsigned AddressSpace
);
690 LLVMValueRef
LLVMGetNamedGlobal(LLVMModuleRef M
, const char *Name
);
691 LLVMValueRef
LLVMGetFirstGlobal(LLVMModuleRef M
);
692 LLVMValueRef
LLVMGetLastGlobal(LLVMModuleRef M
);
693 LLVMValueRef
LLVMGetNextGlobal(LLVMValueRef GlobalVar
);
694 LLVMValueRef
LLVMGetPreviousGlobal(LLVMValueRef GlobalVar
);
695 void LLVMDeleteGlobal(LLVMValueRef GlobalVar
);
696 LLVMValueRef
LLVMGetInitializer(LLVMValueRef GlobalVar
);
697 void LLVMSetInitializer(LLVMValueRef GlobalVar
, LLVMValueRef ConstantVal
);
698 LLVMBool
LLVMIsThreadLocal(LLVMValueRef GlobalVar
);
699 void LLVMSetThreadLocal(LLVMValueRef GlobalVar
, LLVMBool IsThreadLocal
);
700 LLVMBool
LLVMIsGlobalConstant(LLVMValueRef GlobalVar
);
701 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar
, LLVMBool IsConstant
);
703 /* Operations on aliases */
704 LLVMValueRef
LLVMAddAlias(LLVMModuleRef M
, LLVMTypeRef Ty
, LLVMValueRef Aliasee
,
707 /* Operations on functions */
708 LLVMValueRef
LLVMAddFunction(LLVMModuleRef M
, const char *Name
,
709 LLVMTypeRef FunctionTy
);
710 LLVMValueRef
LLVMGetNamedFunction(LLVMModuleRef M
, const char *Name
);
711 LLVMValueRef
LLVMGetFirstFunction(LLVMModuleRef M
);
712 LLVMValueRef
LLVMGetLastFunction(LLVMModuleRef M
);
713 LLVMValueRef
LLVMGetNextFunction(LLVMValueRef Fn
);
714 LLVMValueRef
LLVMGetPreviousFunction(LLVMValueRef Fn
);
715 void LLVMDeleteFunction(LLVMValueRef Fn
);
716 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn
);
717 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn
);
718 void LLVMSetFunctionCallConv(LLVMValueRef Fn
, unsigned CC
);
719 const char *LLVMGetGC(LLVMValueRef Fn
);
720 void LLVMSetGC(LLVMValueRef Fn
, const char *Name
);
721 void LLVMAddFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
);
722 LLVMAttribute
LLVMGetFunctionAttr(LLVMValueRef Fn
);
723 void LLVMRemoveFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
);
725 /* Operations on parameters */
726 unsigned LLVMCountParams(LLVMValueRef Fn
);
727 void LLVMGetParams(LLVMValueRef Fn
, LLVMValueRef
*Params
);
728 LLVMValueRef
LLVMGetParam(LLVMValueRef Fn
, unsigned Index
);
729 LLVMValueRef
LLVMGetParamParent(LLVMValueRef Inst
);
730 LLVMValueRef
LLVMGetFirstParam(LLVMValueRef Fn
);
731 LLVMValueRef
LLVMGetLastParam(LLVMValueRef Fn
);
732 LLVMValueRef
LLVMGetNextParam(LLVMValueRef Arg
);
733 LLVMValueRef
LLVMGetPreviousParam(LLVMValueRef Arg
);
734 void LLVMAddAttribute(LLVMValueRef Arg
, LLVMAttribute PA
);
735 void LLVMRemoveAttribute(LLVMValueRef Arg
, LLVMAttribute PA
);
736 LLVMAttribute
LLVMGetAttribute(LLVMValueRef Arg
);
737 void LLVMSetParamAlignment(LLVMValueRef Arg
, unsigned align
);
739 /* Operations on basic blocks */
740 LLVMValueRef
LLVMBasicBlockAsValue(LLVMBasicBlockRef BB
);
741 LLVMBool
LLVMValueIsBasicBlock(LLVMValueRef Val
);
742 LLVMBasicBlockRef
LLVMValueAsBasicBlock(LLVMValueRef Val
);
743 LLVMValueRef
LLVMGetBasicBlockParent(LLVMBasicBlockRef BB
);
744 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn
);
745 void LLVMGetBasicBlocks(LLVMValueRef Fn
, LLVMBasicBlockRef
*BasicBlocks
);
746 LLVMBasicBlockRef
LLVMGetFirstBasicBlock(LLVMValueRef Fn
);
747 LLVMBasicBlockRef
LLVMGetLastBasicBlock(LLVMValueRef Fn
);
748 LLVMBasicBlockRef
LLVMGetNextBasicBlock(LLVMBasicBlockRef BB
);
749 LLVMBasicBlockRef
LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB
);
750 LLVMBasicBlockRef
LLVMGetEntryBasicBlock(LLVMValueRef Fn
);
752 LLVMBasicBlockRef
LLVMAppendBasicBlockInContext(LLVMContextRef C
,
755 LLVMBasicBlockRef
LLVMInsertBasicBlockInContext(LLVMContextRef C
,
756 LLVMBasicBlockRef BB
,
759 LLVMBasicBlockRef
LLVMAppendBasicBlock(LLVMValueRef Fn
, const char *Name
);
760 LLVMBasicBlockRef
LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB
,
762 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB
);
764 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB
, LLVMBasicBlockRef MovePos
);
765 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB
, LLVMBasicBlockRef MovePos
);
767 /* Operations on instructions */
768 LLVMBasicBlockRef
LLVMGetInstructionParent(LLVMValueRef Inst
);
769 LLVMValueRef
LLVMGetFirstInstruction(LLVMBasicBlockRef BB
);
770 LLVMValueRef
LLVMGetLastInstruction(LLVMBasicBlockRef BB
);
771 LLVMValueRef
LLVMGetNextInstruction(LLVMValueRef Inst
);
772 LLVMValueRef
LLVMGetPreviousInstruction(LLVMValueRef Inst
);
774 /* Operations on call sites */
775 void LLVMSetInstructionCallConv(LLVMValueRef Instr
, unsigned CC
);
776 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr
);
777 void LLVMAddInstrAttribute(LLVMValueRef Instr
, unsigned index
, LLVMAttribute
);
778 void LLVMRemoveInstrAttribute(LLVMValueRef Instr
, unsigned index
,
780 void LLVMSetInstrParamAlignment(LLVMValueRef Instr
, unsigned index
,
783 /* Operations on call instructions (only) */
784 LLVMBool
LLVMIsTailCall(LLVMValueRef CallInst
);
785 void LLVMSetTailCall(LLVMValueRef CallInst
, LLVMBool IsTailCall
);
787 /* Operations on phi nodes */
788 void LLVMAddIncoming(LLVMValueRef PhiNode
, LLVMValueRef
*IncomingValues
,
789 LLVMBasicBlockRef
*IncomingBlocks
, unsigned Count
);
790 unsigned LLVMCountIncoming(LLVMValueRef PhiNode
);
791 LLVMValueRef
LLVMGetIncomingValue(LLVMValueRef PhiNode
, unsigned Index
);
792 LLVMBasicBlockRef
LLVMGetIncomingBlock(LLVMValueRef PhiNode
, unsigned Index
);
794 /*===-- Instruction builders ----------------------------------------------===*/
796 /* An instruction builder represents a point within a basic block, and is the
797 * exclusive means of building instructions using the C interface.
800 LLVMBuilderRef
LLVMCreateBuilderInContext(LLVMContextRef C
);
801 LLVMBuilderRef
LLVMCreateBuilder(void);
802 void LLVMPositionBuilder(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
,
804 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder
, LLVMValueRef Instr
);
805 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
);
806 LLVMBasicBlockRef
LLVMGetInsertBlock(LLVMBuilderRef Builder
);
807 void LLVMClearInsertionPosition(LLVMBuilderRef Builder
);
808 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder
, LLVMValueRef Instr
);
809 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder
, LLVMValueRef Instr
,
811 void LLVMDisposeBuilder(LLVMBuilderRef Builder
);
814 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder
, LLVMValueRef L
);
815 LLVMValueRef
LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder
);
816 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder
, LLVMValueRef Inst
);
819 LLVMValueRef
LLVMBuildRetVoid(LLVMBuilderRef
);
820 LLVMValueRef
LLVMBuildRet(LLVMBuilderRef
, LLVMValueRef V
);
821 LLVMValueRef
LLVMBuildAggregateRet(LLVMBuilderRef
, LLVMValueRef
*RetVals
,
823 LLVMValueRef
LLVMBuildBr(LLVMBuilderRef
, LLVMBasicBlockRef Dest
);
824 LLVMValueRef
LLVMBuildCondBr(LLVMBuilderRef
, LLVMValueRef If
,
825 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Else
);
826 LLVMValueRef
LLVMBuildSwitch(LLVMBuilderRef
, LLVMValueRef V
,
827 LLVMBasicBlockRef Else
, unsigned NumCases
);
828 LLVMValueRef
LLVMBuildIndirectBr(LLVMBuilderRef B
, LLVMValueRef Addr
,
830 LLVMValueRef
LLVMBuildInvoke(LLVMBuilderRef
, LLVMValueRef Fn
,
831 LLVMValueRef
*Args
, unsigned NumArgs
,
832 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Catch
,
834 LLVMValueRef
LLVMBuildUnwind(LLVMBuilderRef
);
835 LLVMValueRef
LLVMBuildUnreachable(LLVMBuilderRef
);
837 /* Add a case to the switch instruction */
838 void LLVMAddCase(LLVMValueRef Switch
, LLVMValueRef OnVal
,
839 LLVMBasicBlockRef Dest
);
841 /* Add a destination to the indirectbr instruction */
842 void LLVMAddDestination(LLVMValueRef IndirectBr
, LLVMBasicBlockRef Dest
);
845 LLVMValueRef
LLVMBuildAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
847 LLVMValueRef
LLVMBuildNSWAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
849 LLVMValueRef
LLVMBuildNUWAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
851 LLVMValueRef
LLVMBuildFAdd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
853 LLVMValueRef
LLVMBuildSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
855 LLVMValueRef
LLVMBuildNSWSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
857 LLVMValueRef
LLVMBuildNUWSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
859 LLVMValueRef
LLVMBuildFSub(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
861 LLVMValueRef
LLVMBuildMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
863 LLVMValueRef
LLVMBuildNSWMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
865 LLVMValueRef
LLVMBuildNUWMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
867 LLVMValueRef
LLVMBuildFMul(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
869 LLVMValueRef
LLVMBuildUDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
871 LLVMValueRef
LLVMBuildSDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
873 LLVMValueRef
LLVMBuildExactSDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
875 LLVMValueRef
LLVMBuildFDiv(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
877 LLVMValueRef
LLVMBuildURem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
879 LLVMValueRef
LLVMBuildSRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
881 LLVMValueRef
LLVMBuildFRem(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
883 LLVMValueRef
LLVMBuildShl(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
885 LLVMValueRef
LLVMBuildLShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
887 LLVMValueRef
LLVMBuildAShr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
889 LLVMValueRef
LLVMBuildAnd(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
891 LLVMValueRef
LLVMBuildOr(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
893 LLVMValueRef
LLVMBuildXor(LLVMBuilderRef
, LLVMValueRef LHS
, LLVMValueRef RHS
,
895 LLVMValueRef
LLVMBuildBinOp(LLVMBuilderRef B
, LLVMOpcode Op
,
896 LLVMValueRef LHS
, LLVMValueRef RHS
,
898 LLVMValueRef
LLVMBuildNeg(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
899 LLVMValueRef
LLVMBuildNSWNeg(LLVMBuilderRef B
, LLVMValueRef V
,
901 LLVMValueRef
LLVMBuildNUWNeg(LLVMBuilderRef B
, LLVMValueRef V
,
903 LLVMValueRef
LLVMBuildFNeg(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
904 LLVMValueRef
LLVMBuildNot(LLVMBuilderRef
, LLVMValueRef V
, const char *Name
);
907 LLVMValueRef
LLVMBuildMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
908 LLVMValueRef
LLVMBuildArrayMalloc(LLVMBuilderRef
, LLVMTypeRef Ty
,
909 LLVMValueRef Val
, const char *Name
);
910 LLVMValueRef
LLVMBuildAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
911 LLVMValueRef
LLVMBuildArrayAlloca(LLVMBuilderRef
, LLVMTypeRef Ty
,
912 LLVMValueRef Val
, const char *Name
);
913 LLVMValueRef
LLVMBuildFree(LLVMBuilderRef
, LLVMValueRef PointerVal
);
914 LLVMValueRef
LLVMBuildLoad(LLVMBuilderRef
, LLVMValueRef PointerVal
,
916 LLVMValueRef
LLVMBuildStore(LLVMBuilderRef
, LLVMValueRef Val
, LLVMValueRef Ptr
);
917 LLVMValueRef
LLVMBuildGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
918 LLVMValueRef
*Indices
, unsigned NumIndices
,
920 LLVMValueRef
LLVMBuildInBoundsGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
921 LLVMValueRef
*Indices
, unsigned NumIndices
,
923 LLVMValueRef
LLVMBuildStructGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
924 unsigned Idx
, const char *Name
);
925 LLVMValueRef
LLVMBuildGlobalString(LLVMBuilderRef B
, const char *Str
,
927 LLVMValueRef
LLVMBuildGlobalStringPtr(LLVMBuilderRef B
, const char *Str
,
931 LLVMValueRef
LLVMBuildTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
932 LLVMTypeRef DestTy
, const char *Name
);
933 LLVMValueRef
LLVMBuildZExt(LLVMBuilderRef
, LLVMValueRef Val
,
934 LLVMTypeRef DestTy
, const char *Name
);
935 LLVMValueRef
LLVMBuildSExt(LLVMBuilderRef
, LLVMValueRef Val
,
936 LLVMTypeRef DestTy
, const char *Name
);
937 LLVMValueRef
LLVMBuildFPToUI(LLVMBuilderRef
, LLVMValueRef Val
,
938 LLVMTypeRef DestTy
, const char *Name
);
939 LLVMValueRef
LLVMBuildFPToSI(LLVMBuilderRef
, LLVMValueRef Val
,
940 LLVMTypeRef DestTy
, const char *Name
);
941 LLVMValueRef
LLVMBuildUIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
942 LLVMTypeRef DestTy
, const char *Name
);
943 LLVMValueRef
LLVMBuildSIToFP(LLVMBuilderRef
, LLVMValueRef Val
,
944 LLVMTypeRef DestTy
, const char *Name
);
945 LLVMValueRef
LLVMBuildFPTrunc(LLVMBuilderRef
, LLVMValueRef Val
,
946 LLVMTypeRef DestTy
, const char *Name
);
947 LLVMValueRef
LLVMBuildFPExt(LLVMBuilderRef
, LLVMValueRef Val
,
948 LLVMTypeRef DestTy
, const char *Name
);
949 LLVMValueRef
LLVMBuildPtrToInt(LLVMBuilderRef
, LLVMValueRef Val
,
950 LLVMTypeRef DestTy
, const char *Name
);
951 LLVMValueRef
LLVMBuildIntToPtr(LLVMBuilderRef
, LLVMValueRef Val
,
952 LLVMTypeRef DestTy
, const char *Name
);
953 LLVMValueRef
LLVMBuildBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
954 LLVMTypeRef DestTy
, const char *Name
);
955 LLVMValueRef
LLVMBuildZExtOrBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
956 LLVMTypeRef DestTy
, const char *Name
);
957 LLVMValueRef
LLVMBuildSExtOrBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
958 LLVMTypeRef DestTy
, const char *Name
);
959 LLVMValueRef
LLVMBuildTruncOrBitCast(LLVMBuilderRef
, LLVMValueRef Val
,
960 LLVMTypeRef DestTy
, const char *Name
);
961 LLVMValueRef
LLVMBuildCast(LLVMBuilderRef B
, LLVMOpcode Op
, LLVMValueRef Val
,
962 LLVMTypeRef DestTy
, const char *Name
);
963 LLVMValueRef
LLVMBuildPointerCast(LLVMBuilderRef
, LLVMValueRef Val
,
964 LLVMTypeRef DestTy
, const char *Name
);
965 LLVMValueRef
LLVMBuildIntCast(LLVMBuilderRef
, LLVMValueRef Val
, /*Signed cast!*/
966 LLVMTypeRef DestTy
, const char *Name
);
967 LLVMValueRef
LLVMBuildFPCast(LLVMBuilderRef
, LLVMValueRef Val
,
968 LLVMTypeRef DestTy
, const char *Name
);
971 LLVMValueRef
LLVMBuildICmp(LLVMBuilderRef
, LLVMIntPredicate Op
,
972 LLVMValueRef LHS
, LLVMValueRef RHS
,
974 LLVMValueRef
LLVMBuildFCmp(LLVMBuilderRef
, LLVMRealPredicate Op
,
975 LLVMValueRef LHS
, LLVMValueRef RHS
,
978 /* Miscellaneous instructions */
979 LLVMValueRef
LLVMBuildPhi(LLVMBuilderRef
, LLVMTypeRef Ty
, const char *Name
);
980 LLVMValueRef
LLVMBuildCall(LLVMBuilderRef
, LLVMValueRef Fn
,
981 LLVMValueRef
*Args
, unsigned NumArgs
,
983 LLVMValueRef
LLVMBuildSelect(LLVMBuilderRef
, LLVMValueRef If
,
984 LLVMValueRef Then
, LLVMValueRef Else
,
986 LLVMValueRef
LLVMBuildVAArg(LLVMBuilderRef
, LLVMValueRef List
, LLVMTypeRef Ty
,
988 LLVMValueRef
LLVMBuildExtractElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
989 LLVMValueRef Index
, const char *Name
);
990 LLVMValueRef
LLVMBuildInsertElement(LLVMBuilderRef
, LLVMValueRef VecVal
,
991 LLVMValueRef EltVal
, LLVMValueRef Index
,
993 LLVMValueRef
LLVMBuildShuffleVector(LLVMBuilderRef
, LLVMValueRef V1
,
994 LLVMValueRef V2
, LLVMValueRef Mask
,
996 LLVMValueRef
LLVMBuildExtractValue(LLVMBuilderRef
, LLVMValueRef AggVal
,
997 unsigned Index
, const char *Name
);
998 LLVMValueRef
LLVMBuildInsertValue(LLVMBuilderRef
, LLVMValueRef AggVal
,
999 LLVMValueRef EltVal
, unsigned Index
,
1002 LLVMValueRef
LLVMBuildIsNull(LLVMBuilderRef
, LLVMValueRef Val
,
1004 LLVMValueRef
LLVMBuildIsNotNull(LLVMBuilderRef
, LLVMValueRef Val
,
1006 LLVMValueRef
LLVMBuildPtrDiff(LLVMBuilderRef
, LLVMValueRef LHS
,
1007 LLVMValueRef RHS
, const char *Name
);
1010 /*===-- Module providers --------------------------------------------------===*/
1012 /* Changes the type of M so it can be passed to FunctionPassManagers and the
1013 * JIT. They take ModuleProviders for historical reasons.
1015 LLVMModuleProviderRef
1016 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M
);
1018 /* Destroys the module M.
1020 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M
);
1023 /*===-- Memory buffers ----------------------------------------------------===*/
1025 LLVMBool
LLVMCreateMemoryBufferWithContentsOfFile(const char *Path
,
1026 LLVMMemoryBufferRef
*OutMemBuf
,
1028 LLVMBool
LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef
*OutMemBuf
,
1030 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf
);
1032 /*===-- Pass Registry -----------------------------------------------------===*/
1034 /** Return the global pass registry, for use with initialization functions.
1035 See llvm::PassRegistry::getPassRegistry. */
1036 LLVMPassRegistryRef
LLVMGetGlobalPassRegistry(void);
1038 /*===-- Pass Managers -----------------------------------------------------===*/
1040 /** Constructs a new whole-module pass pipeline. This type of pipeline is
1041 suitable for link-time optimization and whole-module transformations.
1042 See llvm::PassManager::PassManager. */
1043 LLVMPassManagerRef
LLVMCreatePassManager(void);
1045 /** Constructs a new function-by-function pass pipeline over the module
1046 provider. It does not take ownership of the module provider. This type of
1047 pipeline is suitable for code generation and JIT compilation tasks.
1048 See llvm::FunctionPassManager::FunctionPassManager. */
1049 LLVMPassManagerRef
LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M
);
1051 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
1052 LLVMPassManagerRef
LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP
);
1054 /** Initializes, executes on the provided module, and finalizes all of the
1055 passes scheduled in the pass manager. Returns 1 if any of the passes
1056 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
1057 LLVMBool
LLVMRunPassManager(LLVMPassManagerRef PM
, LLVMModuleRef M
);
1059 /** Initializes all of the function passes scheduled in the function pass
1060 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1061 See llvm::FunctionPassManager::doInitialization. */
1062 LLVMBool
LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM
);
1064 /** Executes all of the function passes scheduled in the function pass manager
1065 on the provided function. Returns 1 if any of the passes modified the
1066 function, false otherwise.
1067 See llvm::FunctionPassManager::run(Function&). */
1068 LLVMBool
LLVMRunFunctionPassManager(LLVMPassManagerRef FPM
, LLVMValueRef F
);
1070 /** Finalizes all of the function passes scheduled in in the function pass
1071 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1072 See llvm::FunctionPassManager::doFinalization. */
1073 LLVMBool
LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM
);
1075 /** Frees the memory of a pass pipeline. For function pipelines, does not free
1076 the module provider.
1077 See llvm::PassManagerBase::~PassManagerBase. */
1078 void LLVMDisposePassManager(LLVMPassManagerRef PM
);
1086 class PassManagerBase
;
1088 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1089 inline ty *unwrap(ref P) { \
1090 return reinterpret_cast<ty*>(P); \
1093 inline ref wrap(const ty *P) { \
1094 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
1097 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
1098 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1100 template<typename T> \
1101 inline T *unwrap(ref P) { \
1102 return cast<T>(unwrap(P)); \
1105 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
1106 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1108 template<typename T> \
1109 inline T *unwrap(ref P) { \
1110 T *Q = (T*)unwrap(P); \
1111 assert(Q && "Invalid cast!"); \
1115 DEFINE_ISA_CONVERSION_FUNCTIONS (Type
, LLVMTypeRef
)
1116 DEFINE_ISA_CONVERSION_FUNCTIONS (Value
, LLVMValueRef
)
1117 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module
, LLVMModuleRef
)
1118 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock
, LLVMBasicBlockRef
)
1119 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder
<>, LLVMBuilderRef
)
1120 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder
, LLVMTypeHandleRef
)
1121 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer
, LLVMMemoryBufferRef
)
1122 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext
, LLVMContextRef
)
1123 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use
, LLVMUseRef
)
1124 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase
, LLVMPassManagerRef
)
1125 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry
, LLVMPassRegistryRef
)
1126 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
1129 inline Module
*unwrap(LLVMModuleProviderRef MP
) {
1130 return reinterpret_cast<Module
*>(MP
);
1133 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
1134 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
1135 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
1137 /* Specialized opaque context conversions.
1139 inline LLVMContext
**unwrap(LLVMContextRef
* Tys
) {
1140 return reinterpret_cast<LLVMContext
**>(Tys
);
1143 inline LLVMContextRef
*wrap(const LLVMContext
**Tys
) {
1144 return reinterpret_cast<LLVMContextRef
*>(const_cast<LLVMContext
**>(Tys
));
1147 /* Specialized opaque type conversions.
1149 inline Type
**unwrap(LLVMTypeRef
* Tys
) {
1150 return reinterpret_cast<Type
**>(Tys
);
1153 inline LLVMTypeRef
*wrap(const Type
**Tys
) {
1154 return reinterpret_cast<LLVMTypeRef
*>(const_cast<Type
**>(Tys
));
1157 /* Specialized opaque value conversions.
1159 inline Value
**unwrap(LLVMValueRef
*Vals
) {
1160 return reinterpret_cast<Value
**>(Vals
);
1163 template<typename T
>
1164 inline T
**unwrap(LLVMValueRef
*Vals
, unsigned Length
) {
1166 for (LLVMValueRef
*I
= Vals
, *E
= Vals
+ Length
; I
!= E
; ++I
)
1169 return reinterpret_cast<T
**>(Vals
);
1172 inline LLVMValueRef
*wrap(const Value
**Vals
) {
1173 return reinterpret_cast<LLVMValueRef
*>(const_cast<Value
**>(Vals
));
1177 #endif /* !defined(__cplusplus) */
1179 #endif /* !defined(LLVM_C_CORE_H) */