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;
71 typedef struct LLVMOpaqueValue *LLVMValueRef;
72 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
73 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
75 /* Interface used to provide a module to JIT or interpreter. This is now just a
76 * synonym for llvm::Module, but we have to keep using the different type to
77 * keep binary compatibility.
79 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
81 /* Used to provide a module to JIT or interpreter.
82 * See the llvm::MemoryBuffer class.
84 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
86 /** See the llvm::PassManagerBase class. */
87 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
89 /** See the llvm::PassRegistry class. */
90 typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
92 /** Used to get the users and usees of a Value. See the llvm::Use class. */
93 typedef struct LLVMOpaqueUse *LLVMUseRef;
96 LLVMZExtAttribute = 1<<0,
97 LLVMSExtAttribute = 1<<1,
98 LLVMNoReturnAttribute = 1<<2,
99 LLVMInRegAttribute = 1<<3,
100 LLVMStructRetAttribute = 1<<4,
101 LLVMNoUnwindAttribute = 1<<5,
102 LLVMNoAliasAttribute = 1<<6,
103 LLVMByValAttribute = 1<<7,
104 LLVMNestAttribute = 1<<8,
105 LLVMReadNoneAttribute = 1<<9,
106 LLVMReadOnlyAttribute = 1<<10,
107 LLVMNoInlineAttribute = 1<<11,
108 LLVMAlwaysInlineAttribute = 1<<12,
109 LLVMOptimizeForSizeAttribute = 1<<13,
110 LLVMStackProtectAttribute = 1<<14,
111 LLVMStackProtectReqAttribute = 1<<15,
112 LLVMAlignment = 31<<16,
113 LLVMNoCaptureAttribute = 1<<21,
114 LLVMNoRedZoneAttribute = 1<<22,
115 LLVMNoImplicitFloatAttribute = 1<<23,
116 LLVMNakedAttribute = 1<<24,
117 LLVMInlineHintAttribute = 1<<25,
118 LLVMStackAlignment = 7<<26,
119 LLVMReturnsTwice = 1 << 29,
120 LLVMUWTable = 1 << 30,
121 LLVMNonLazyBind = 1U << 31,
122 LLVMAddressSafety = 1ULL << 32,
126 /* Terminator Instructions */
132 /* removed 6 due to API changes */
135 /* Standard Binary Operators */
149 /* Logical Operators */
157 /* Memory Operators */
161 LLVMGetElementPtr = 29,
177 /* Other Operators */
186 LLVMExtractElement = 50,
187 LLVMInsertElement = 51,
188 LLVMShuffleVector = 52,
189 LLVMExtractValue = 53,
190 LLVMInsertValue = 54,
192 /* Atomic operators */
194 LLVMAtomicCmpXchg = 56,
197 /* Exception Handling Operators */
206 LLVMVoidTypeKind, /**< type with no size */
207 LLVMHalfTypeKind, /**< 16 bit floating point type */
208 LLVMFloatTypeKind, /**< 32 bit floating point type */
209 LLVMDoubleTypeKind, /**< 64 bit floating point type */
210 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
211 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
212 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
213 LLVMLabelTypeKind, /**< Labels */
214 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
215 LLVMFunctionTypeKind, /**< Functions */
216 LLVMStructTypeKind, /**< Structures */
217 LLVMArrayTypeKind, /**< Arrays */
218 LLVMPointerTypeKind, /**< Pointers */
219 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
220 LLVMMetadataTypeKind, /**< Metadata */
221 LLVMX86_MMXTypeKind /**< X86 MMX */
225 LLVMExternalLinkage, /**< Externally visible function */
226 LLVMAvailableExternallyLinkage,
227 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
228 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
230 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
231 LLVMWeakODRLinkage, /**< Same, but only replaced by something
233 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
234 LLVMInternalLinkage, /**< Rename collisions when linking (static
236 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
237 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
238 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
239 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
240 LLVMGhostLinkage, /**< Obsolete */
241 LLVMCommonLinkage, /**< Tentative definitions */
242 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
243 LLVMLinkerPrivateWeakLinkage, /**< Like LinkerPrivate, but is weak. */
244 LLVMLinkerPrivateWeakDefAutoLinkage /**< Like LinkerPrivateWeak, but possibly
249 LLVMDefaultVisibility, /**< The GV is visible */
250 LLVMHiddenVisibility, /**< The GV is hidden */
251 LLVMProtectedVisibility /**< The GV is protected */
256 LLVMFastCallConv = 8,
257 LLVMColdCallConv = 9,
258 LLVMX86StdcallCallConv = 64,
259 LLVMX86FastcallCallConv = 65
263 LLVMIntEQ = 32, /**< equal */
264 LLVMIntNE, /**< not equal */
265 LLVMIntUGT, /**< unsigned greater than */
266 LLVMIntUGE, /**< unsigned greater or equal */
267 LLVMIntULT, /**< unsigned less than */
268 LLVMIntULE, /**< unsigned less or equal */
269 LLVMIntSGT, /**< signed greater than */
270 LLVMIntSGE, /**< signed greater or equal */
271 LLVMIntSLT, /**< signed less than */
272 LLVMIntSLE /**< signed less or equal */
276 LLVMRealPredicateFalse, /**< Always false (always folded) */
277 LLVMRealOEQ, /**< True if ordered and equal */
278 LLVMRealOGT, /**< True if ordered and greater than */
279 LLVMRealOGE, /**< True if ordered and greater than or equal */
280 LLVMRealOLT, /**< True if ordered and less than */
281 LLVMRealOLE, /**< True if ordered and less than or equal */
282 LLVMRealONE, /**< True if ordered and operands are unequal */
283 LLVMRealORD, /**< True if ordered (no nans) */
284 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
285 LLVMRealUEQ, /**< True if unordered or equal */
286 LLVMRealUGT, /**< True if unordered or greater than */
287 LLVMRealUGE, /**< True if unordered, greater than, or equal */
288 LLVMRealULT, /**< True if unordered or less than */
289 LLVMRealULE, /**< True if unordered, less than, or equal */
290 LLVMRealUNE, /**< True if unordered or not equal */
291 LLVMRealPredicateTrue /**< Always true (always folded) */
295 LLVMLandingPadCatch, /**< A catch clause */
296 LLVMLandingPadFilter /**< A filter clause */
297 } LLVMLandingPadClauseTy;
299 void LLVMInitializeCore(LLVMPassRegistryRef R);
302 /*===-- Error handling ----------------------------------------------------===*/
304 void LLVMDisposeMessage(char *Message);
307 /*===-- Contexts ----------------------------------------------------------===*/
309 /* Create and destroy contexts. */
310 LLVMContextRef LLVMContextCreate(void);
311 LLVMContextRef LLVMGetGlobalContext(void);
312 void LLVMContextDispose(LLVMContextRef C);
314 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
316 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
318 /*===-- Modules -----------------------------------------------------------===*/
320 /* Create and destroy modules. */
321 /** See llvm::Module::Module. */
322 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
323 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
326 /** See llvm::Module::~Module. */
327 void LLVMDisposeModule(LLVMModuleRef M);
329 /** Data layout. See Module::getDataLayout. */
330 const char *LLVMGetDataLayout(LLVMModuleRef M);
331 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
333 /** Target triple. See Module::getTargetTriple. */
334 const char *LLVMGetTarget(LLVMModuleRef M);
335 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
337 /** See Module::dump. */
338 void LLVMDumpModule(LLVMModuleRef M);
340 /** See Module::setModuleInlineAsm. */
341 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
343 /** See Module::getContext. */
344 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
346 /*===-- Types -------------------------------------------------------------===*/
348 /* LLVM types conform to the following hierarchy:
363 /** See llvm::LLVMTypeKind::getTypeID. */
364 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
365 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
367 /** See llvm::LLVMType::getContext. */
368 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
370 /* Operations on integer types */
371 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
372 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
373 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
374 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
375 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
376 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
378 LLVMTypeRef LLVMInt1Type(void);
379 LLVMTypeRef LLVMInt8Type(void);
380 LLVMTypeRef LLVMInt16Type(void);
381 LLVMTypeRef LLVMInt32Type(void);
382 LLVMTypeRef LLVMInt64Type(void);
383 LLVMTypeRef LLVMIntType(unsigned NumBits);
384 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
386 /* Operations on real types */
387 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
388 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
389 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
390 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
391 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
392 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
394 LLVMTypeRef LLVMHalfType(void);
395 LLVMTypeRef LLVMFloatType(void);
396 LLVMTypeRef LLVMDoubleType(void);
397 LLVMTypeRef LLVMX86FP80Type(void);
398 LLVMTypeRef LLVMFP128Type(void);
399 LLVMTypeRef LLVMPPCFP128Type(void);
401 /* Operations on function types */
402 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
403 LLVMTypeRef *ParamTypes, unsigned ParamCount,
405 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
406 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
407 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
408 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
410 /* Operations on struct types */
411 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
412 unsigned ElementCount, LLVMBool Packed);
413 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
415 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
416 const char *LLVMGetStructName(LLVMTypeRef Ty);
417 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
418 unsigned ElementCount, LLVMBool Packed);
420 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
421 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
422 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
423 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
425 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
427 /* Operations on array, pointer, and vector types (sequence types) */
428 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
429 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
430 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
432 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
433 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
434 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
435 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
437 /* Operations on other types */
438 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
439 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
440 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
442 LLVMTypeRef LLVMVoidType(void);
443 LLVMTypeRef LLVMLabelType(void);
444 LLVMTypeRef LLVMX86MMXType(void);
446 /*===-- Values ------------------------------------------------------------===*/
448 /* The bulk of LLVM's object model consists of values, which comprise a very
449 * rich type hierarchy.
452 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
460 macro(BlockAddress) \
461 macro(ConstantAggregateZero) \
462 macro(ConstantArray) \
463 macro(ConstantExpr) \
466 macro(ConstantPointerNull) \
467 macro(ConstantStruct) \
468 macro(ConstantVector) \
472 macro(GlobalVariable) \
475 macro(BinaryOperator) \
477 macro(IntrinsicInst) \
478 macro(DbgInfoIntrinsic) \
479 macro(DbgDeclareInst) \
480 macro(EHExceptionInst) \
481 macro(EHSelectorInst) \
482 macro(MemIntrinsic) \
489 macro(ExtractElementInst) \
490 macro(GetElementPtrInst) \
491 macro(InsertElementInst) \
492 macro(InsertValueInst) \
493 macro(LandingPadInst) \
496 macro(ShuffleVectorInst) \
498 macro(TerminatorInst) \
500 macro(IndirectBrInst) \
504 macro(UnreachableInst) \
506 macro(UnaryInstruction) \
514 macro(IntToPtrInst) \
515 macro(PtrToIntInst) \
521 macro(ExtractValueInst) \
525 /* Operations on all values */
526 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
527 const char *LLVMGetValueName(LLVMValueRef Val);
528 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
529 void LLVMDumpValue(LLVMValueRef Val);
530 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
531 int LLVMHasMetadata(LLVMValueRef Val);
532 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
533 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
535 /* Conversion functions. Return the input value if it is an instance of the
536 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
537 #define LLVM_DECLARE_VALUE_CAST(name) \
538 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
539 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
541 /* Operations on Uses */
542 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
543 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
544 LLVMValueRef LLVMGetUser(LLVMUseRef U);
545 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
547 /* Operations on Users and metadata */
548 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
549 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
550 int LLVMGetNumOperands(LLVMValueRef Val);
552 /* Operations on constants of any type */
553 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
554 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
555 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
556 LLVMBool LLVMIsConstant(LLVMValueRef Val);
557 LLVMBool LLVMIsNull(LLVMValueRef Val);
558 LLVMBool LLVMIsUndef(LLVMValueRef Val);
559 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
561 /* Operations on metadata */
562 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
564 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
565 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
567 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
568 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
569 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
570 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
571 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
574 /* Operations on scalar constants */
575 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
576 LLVMBool SignExtend);
577 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
579 const uint64_t Words[]);
580 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
582 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
583 unsigned SLen, uint8_t Radix);
584 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
585 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
586 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
588 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
589 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
592 /* Operations on composite constants */
593 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
594 unsigned Length, LLVMBool DontNullTerminate);
595 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
596 LLVMValueRef *ConstantVals,
597 unsigned Count, LLVMBool Packed);
599 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
600 LLVMBool DontNullTerminate);
601 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
602 LLVMValueRef *ConstantVals, unsigned Length);
603 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
605 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
606 LLVMValueRef *ConstantVals,
608 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
610 /* Constant expressions */
611 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
612 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
613 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
614 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
615 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
616 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
617 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
618 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
619 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
620 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
621 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
622 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
623 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
624 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
625 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
626 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
627 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
628 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
629 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
630 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
631 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
632 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
633 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
634 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
635 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
636 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
637 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
638 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
639 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
640 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
641 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
642 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
643 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
644 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
645 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
646 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
647 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
648 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
649 LLVMValueRef *ConstantIndices, unsigned NumIndices);
650 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
651 LLVMValueRef *ConstantIndices,
652 unsigned NumIndices);
653 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
654 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
655 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
656 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
657 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
658 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
659 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
660 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
661 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
662 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
663 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
664 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
665 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
667 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
669 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
671 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
673 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
675 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
676 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
677 LLVMValueRef ConstantIfTrue,
678 LLVMValueRef ConstantIfFalse);
679 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
680 LLVMValueRef IndexConstant);
681 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
682 LLVMValueRef ElementValueConstant,
683 LLVMValueRef IndexConstant);
684 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
685 LLVMValueRef VectorBConstant,
686 LLVMValueRef MaskConstant);
687 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
689 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
690 LLVMValueRef ElementValueConstant,
691 unsigned *IdxList, unsigned NumIdx);
692 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
693 const char *AsmString, const char *Constraints,
694 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
695 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
697 /* Operations on global variables, functions, and aliases (globals) */
698 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
699 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
700 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
701 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
702 const char *LLVMGetSection(LLVMValueRef Global);
703 void LLVMSetSection(LLVMValueRef Global, const char *Section);
704 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
705 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
706 unsigned LLVMGetAlignment(LLVMValueRef Global);
707 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
709 /* Operations on global variables */
710 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
711 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
713 unsigned AddressSpace);
714 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
715 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
716 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
717 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
718 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
719 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
720 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
721 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
722 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
723 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
724 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
725 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
727 /* Operations on aliases */
728 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
731 /* Operations on functions */
732 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
733 LLVMTypeRef FunctionTy);
734 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
735 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
736 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
737 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
738 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
739 void LLVMDeleteFunction(LLVMValueRef Fn);
740 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
741 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
742 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
743 const char *LLVMGetGC(LLVMValueRef Fn);
744 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
745 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
746 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
747 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
749 /* Operations on parameters */
750 unsigned LLVMCountParams(LLVMValueRef Fn);
751 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
752 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
753 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
754 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
755 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
756 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
757 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
758 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
759 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
760 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
761 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
763 /* Operations on basic blocks */
764 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
765 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
766 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
767 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
768 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
769 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
770 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
771 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
772 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
773 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
774 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
775 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
777 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
780 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
781 LLVMBasicBlockRef BB,
784 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
785 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
787 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
788 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
790 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
791 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
793 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
794 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
796 /* Operations on instructions */
797 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
798 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
799 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
800 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
801 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
802 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
804 /* Operations on call sites */
805 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
806 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
807 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
808 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
810 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
813 /* Operations on call instructions (only) */
814 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
815 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
817 /* Operations on switch instructions (only) */
818 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
820 /* Operations on phi nodes */
821 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
822 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
823 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
824 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
825 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
827 /*===-- Instruction builders ----------------------------------------------===*/
829 /* An instruction builder represents a point within a basic block, and is the
830 * exclusive means of building instructions using the C interface.
833 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
834 LLVMBuilderRef LLVMCreateBuilder(void);
835 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
837 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
838 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
839 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
840 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
841 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
842 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
844 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
847 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
848 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
849 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
852 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
853 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
854 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
856 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
857 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
858 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
859 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
860 LLVMBasicBlockRef Else, unsigned NumCases);
861 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
863 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
864 LLVMValueRef *Args, unsigned NumArgs,
865 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
867 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
868 LLVMValueRef PersFn, unsigned NumClauses,
870 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
871 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
873 /* Add a case to the switch instruction */
874 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
875 LLVMBasicBlockRef Dest);
877 /* Add a destination to the indirectbr instruction */
878 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
880 /* Add a catch or filter clause to the landingpad instruction */
881 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
883 /* Set the 'cleanup' flag in the landingpad instruction */
884 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
887 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
889 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
891 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
893 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
895 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
897 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
899 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
901 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
903 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
905 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
907 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
909 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
911 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
913 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
915 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
917 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
919 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
921 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
923 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
925 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
927 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
929 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
931 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
933 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
935 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
937 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
938 LLVMValueRef LHS, LLVMValueRef RHS,
940 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
941 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
943 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
945 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
946 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
949 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
950 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
951 LLVMValueRef Val, const char *Name);
952 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
953 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
954 LLVMValueRef Val, const char *Name);
955 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
956 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
958 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
959 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
960 LLVMValueRef *Indices, unsigned NumIndices,
962 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
963 LLVMValueRef *Indices, unsigned NumIndices,
965 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
966 unsigned Idx, const char *Name);
967 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
969 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
973 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
974 LLVMTypeRef DestTy, const char *Name);
975 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
976 LLVMTypeRef DestTy, const char *Name);
977 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
978 LLVMTypeRef DestTy, const char *Name);
979 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
980 LLVMTypeRef DestTy, const char *Name);
981 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
982 LLVMTypeRef DestTy, const char *Name);
983 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
984 LLVMTypeRef DestTy, const char *Name);
985 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
986 LLVMTypeRef DestTy, const char *Name);
987 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
988 LLVMTypeRef DestTy, const char *Name);
989 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
990 LLVMTypeRef DestTy, const char *Name);
991 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
992 LLVMTypeRef DestTy, const char *Name);
993 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
994 LLVMTypeRef DestTy, const char *Name);
995 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
996 LLVMTypeRef DestTy, const char *Name);
997 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
998 LLVMTypeRef DestTy, const char *Name);
999 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
1000 LLVMTypeRef DestTy, const char *Name);
1001 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
1002 LLVMTypeRef DestTy, const char *Name);
1003 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
1004 LLVMTypeRef DestTy, const char *Name);
1005 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
1006 LLVMTypeRef DestTy, const char *Name);
1007 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
1008 LLVMTypeRef DestTy, const char *Name);
1009 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
1010 LLVMTypeRef DestTy, const char *Name);
1013 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
1014 LLVMValueRef LHS, LLVMValueRef RHS,
1016 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
1017 LLVMValueRef LHS, LLVMValueRef RHS,
1020 /* Miscellaneous instructions */
1021 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
1022 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
1023 LLVMValueRef *Args, unsigned NumArgs,
1025 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
1026 LLVMValueRef Then, LLVMValueRef Else,
1028 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
1030 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
1031 LLVMValueRef Index, const char *Name);
1032 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
1033 LLVMValueRef EltVal, LLVMValueRef Index,
1035 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
1036 LLVMValueRef V2, LLVMValueRef Mask,
1038 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
1039 unsigned Index, const char *Name);
1040 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
1041 LLVMValueRef EltVal, unsigned Index,
1044 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
1046 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
1048 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
1049 LLVMValueRef RHS, const char *Name);
1052 /*===-- Module providers --------------------------------------------------===*/
1054 /* Changes the type of M so it can be passed to FunctionPassManagers and the
1055 * JIT. They take ModuleProviders for historical reasons.
1057 LLVMModuleProviderRef
1058 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
1060 /* Destroys the module M.
1062 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
1065 /*===-- Memory buffers ----------------------------------------------------===*/
1067 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
1068 LLVMMemoryBufferRef *OutMemBuf,
1070 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
1072 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
1074 /*===-- Pass Registry -----------------------------------------------------===*/
1076 /** Return the global pass registry, for use with initialization functions.
1077 See llvm::PassRegistry::getPassRegistry. */
1078 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
1080 /*===-- Pass Managers -----------------------------------------------------===*/
1082 /** Constructs a new whole-module pass pipeline. This type of pipeline is
1083 suitable for link-time optimization and whole-module transformations.
1084 See llvm::PassManager::PassManager. */
1085 LLVMPassManagerRef LLVMCreatePassManager(void);
1087 /** Constructs a new function-by-function pass pipeline over the module
1088 provider. It does not take ownership of the module provider. This type of
1089 pipeline is suitable for code generation and JIT compilation tasks.
1090 See llvm::FunctionPassManager::FunctionPassManager. */
1091 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
1093 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
1094 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
1096 /** Initializes, executes on the provided module, and finalizes all of the
1097 passes scheduled in the pass manager. Returns 1 if any of the passes
1098 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
1099 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
1101 /** Initializes all of the function passes scheduled in the function pass
1102 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1103 See llvm::FunctionPassManager::doInitialization. */
1104 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
1106 /** Executes all of the function passes scheduled in the function pass manager
1107 on the provided function. Returns 1 if any of the passes modified the
1108 function, false otherwise.
1109 See llvm::FunctionPassManager::run(Function&). */
1110 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
1112 /** Finalizes all of the function passes scheduled in in the function pass
1113 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1114 See llvm::FunctionPassManager::doFinalization. */
1115 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
1117 /** Frees the memory of a pass pipeline. For function pipelines, does not free
1118 the module provider.
1119 See llvm::PassManagerBase::~PassManagerBase. */
1120 void LLVMDisposePassManager(LLVMPassManagerRef PM);
1128 class PassManagerBase;
1130 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1131 inline ty *unwrap(ref P) { \
1132 return reinterpret_cast<ty*>(P); \
1135 inline ref wrap(const ty *P) { \
1136 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
1139 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
1140 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1142 template<typename T> \
1143 inline T *unwrap(ref P) { \
1144 return cast<T>(unwrap(P)); \
1147 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
1148 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1150 template<typename T> \
1151 inline T *unwrap(ref P) { \
1152 T *Q = (T*)unwrap(P); \
1153 assert(Q && "Invalid cast!"); \
1157 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
1158 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
1159 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
1160 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
1161 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
1162 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
1163 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
1164 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
1165 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
1166 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
1167 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
1170 inline Module *unwrap(LLVMModuleProviderRef MP) {
1171 return reinterpret_cast<Module*>(MP);
1174 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
1175 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
1176 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
1178 /* Specialized opaque context conversions.
1180 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
1181 return reinterpret_cast<LLVMContext**>(Tys);
1184 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
1185 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
1188 /* Specialized opaque type conversions.
1190 inline Type **unwrap(LLVMTypeRef* Tys) {
1191 return reinterpret_cast<Type**>(Tys);
1194 inline LLVMTypeRef *wrap(Type **Tys) {
1195 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
1198 /* Specialized opaque value conversions.
1200 inline Value **unwrap(LLVMValueRef *Vals) {
1201 return reinterpret_cast<Value**>(Vals);
1204 template<typename T>
1205 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
1207 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
1211 return reinterpret_cast<T**>(Vals);
1214 inline LLVMValueRef *wrap(const Value **Vals) {
1215 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
1219 #endif /* !defined(__cplusplus) */
1221 #endif /* !defined(LLVM_C_CORE_H) */