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 \*===----------------------------------------------------------------------===*/
38 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
39 and 'unwrap' conversion functions. */
40 #include "llvm/Module.h"
41 #include "llvm/Support/IRBuilder.h"
50 * The top-level container for all other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
53 typedef struct LLVMOpaqueModule *LLVMModuleRef;
56 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
59 typedef struct LLVMOpaqueType *LLVMTypeRef;
62 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
63 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
64 * llvm::AbstractTypeHolder class.
66 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
68 typedef struct LLVMOpaqueValue *LLVMValueRef;
69 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
70 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
72 /* Used to provide a module to JIT or interpreter.
73 * See the llvm::ModuleProvider class.
75 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
77 /* Used to provide a module to JIT or interpreter.
78 * See the llvm::MemoryBuffer class.
80 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
82 /** See the llvm::PassManagerBase class. */
83 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
86 LLVMZExtAttribute = 1<<0,
87 LLVMSExtAttribute = 1<<1,
88 LLVMNoReturnAttribute = 1<<2,
89 LLVMInRegAttribute = 1<<3,
90 LLVMStructRetAttribute = 1<<4,
91 LLVMNoUnwindAttribute = 1<<5,
92 LLVMNoAliasAttribute = 1<<6,
93 LLVMByValAttribute = 1<<7,
94 LLVMNestAttribute = 1<<8,
95 LLVMReadNoneAttribute = 1<<9,
96 LLVMReadOnlyAttribute = 1<<10
100 LLVMVoidTypeKind, /**< type with no size */
101 LLVMFloatTypeKind, /**< 32 bit floating point type */
102 LLVMDoubleTypeKind, /**< 64 bit floating point type */
103 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
104 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
105 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
106 LLVMLabelTypeKind, /**< Labels */
107 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
108 LLVMFunctionTypeKind, /**< Functions */
109 LLVMStructTypeKind, /**< Structures */
110 LLVMArrayTypeKind, /**< Arrays */
111 LLVMPointerTypeKind, /**< Pointers */
112 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
113 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
117 LLVMExternalLinkage, /**< Externally visible function */
118 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
119 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
121 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
122 LLVMWeakODRLinkage, /**< Same, but only replaced by something
124 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
125 LLVMInternalLinkage, /**< Rename collisions when linking (static
127 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
128 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
129 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
130 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
131 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
133 LLVMCommonLinkage /**< Tentative definitions */
137 LLVMDefaultVisibility, /**< The GV is visible */
138 LLVMHiddenVisibility, /**< The GV is hidden */
139 LLVMProtectedVisibility /**< The GV is protected */
144 LLVMFastCallConv = 8,
145 LLVMColdCallConv = 9,
146 LLVMX86StdcallCallConv = 64,
147 LLVMX86FastcallCallConv = 65
151 LLVMIntEQ = 32, /**< equal */
152 LLVMIntNE, /**< not equal */
153 LLVMIntUGT, /**< unsigned greater than */
154 LLVMIntUGE, /**< unsigned greater or equal */
155 LLVMIntULT, /**< unsigned less than */
156 LLVMIntULE, /**< unsigned less or equal */
157 LLVMIntSGT, /**< signed greater than */
158 LLVMIntSGE, /**< signed greater or equal */
159 LLVMIntSLT, /**< signed less than */
160 LLVMIntSLE /**< signed less or equal */
164 LLVMRealPredicateFalse, /**< Always false (always folded) */
165 LLVMRealOEQ, /**< True if ordered and equal */
166 LLVMRealOGT, /**< True if ordered and greater than */
167 LLVMRealOGE, /**< True if ordered and greater than or equal */
168 LLVMRealOLT, /**< True if ordered and less than */
169 LLVMRealOLE, /**< True if ordered and less than or equal */
170 LLVMRealONE, /**< True if ordered and operands are unequal */
171 LLVMRealORD, /**< True if ordered (no nans) */
172 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
173 LLVMRealUEQ, /**< True if unordered or equal */
174 LLVMRealUGT, /**< True if unordered or greater than */
175 LLVMRealUGE, /**< True if unordered, greater than, or equal */
176 LLVMRealULT, /**< True if unordered or less than */
177 LLVMRealULE, /**< True if unordered, less than, or equal */
178 LLVMRealUNE, /**< True if unordered or not equal */
179 LLVMRealPredicateTrue /**< Always true (always folded) */
183 /*===-- Error handling ----------------------------------------------------===*/
185 void LLVMDisposeMessage(char *Message);
188 /*===-- Modules -----------------------------------------------------------===*/
190 /* Create and destroy modules. */
191 /** See llvm::Module::Module. */
192 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
194 /** See llvm::Module::~Module. */
195 void LLVMDisposeModule(LLVMModuleRef M);
197 /** Data layout. See Module::getDataLayout. */
198 const char *LLVMGetDataLayout(LLVMModuleRef M);
199 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
201 /** Target triple. See Module::getTargetTriple. */
202 const char *LLVMGetTarget(LLVMModuleRef M);
203 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
205 /** See Module::addTypeName. */
206 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
207 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
209 /** See Module::dump. */
210 void LLVMDumpModule(LLVMModuleRef M);
213 /*===-- Types -------------------------------------------------------------===*/
215 /* LLVM types conform to the following hierarchy:
230 /** See llvm::LLVMTypeKind::getTypeID. */
231 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
233 /* Operations on integer types */
234 LLVMTypeRef LLVMInt1Type(void);
235 LLVMTypeRef LLVMInt8Type(void);
236 LLVMTypeRef LLVMInt16Type(void);
237 LLVMTypeRef LLVMInt32Type(void);
238 LLVMTypeRef LLVMInt64Type(void);
239 LLVMTypeRef LLVMIntType(unsigned NumBits);
240 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
242 /* Operations on real types */
243 LLVMTypeRef LLVMFloatType(void);
244 LLVMTypeRef LLVMDoubleType(void);
245 LLVMTypeRef LLVMX86FP80Type(void);
246 LLVMTypeRef LLVMFP128Type(void);
247 LLVMTypeRef LLVMPPCFP128Type(void);
249 /* Operations on function types */
250 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
251 LLVMTypeRef *ParamTypes, unsigned ParamCount,
253 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
254 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
255 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
256 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
258 /* Operations on struct types */
259 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
261 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
262 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
263 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
265 /* Operations on array, pointer, and vector types (sequence types) */
266 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
267 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
268 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
270 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
271 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
272 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
273 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
275 /* Operations on other types */
276 LLVMTypeRef LLVMVoidType(void);
277 LLVMTypeRef LLVMLabelType(void);
278 LLVMTypeRef LLVMOpaqueType(void);
280 /* Operations on type handles */
281 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
282 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
283 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
284 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
287 /*===-- Values ------------------------------------------------------------===*/
289 /* The bulk of LLVM's object model consists of values, which comprise a very
290 * rich type hierarchy.
293 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
299 macro(ConstantAggregateZero) \
300 macro(ConstantArray) \
301 macro(ConstantExpr) \
304 macro(ConstantPointerNull) \
305 macro(ConstantStruct) \
306 macro(ConstantVector) \
310 macro(GlobalVariable) \
313 macro(BinaryOperator) \
315 macro(IntrinsicInst) \
316 macro(DbgInfoIntrinsic) \
317 macro(DbgDeclareInst) \
318 macro(DbgFuncStartInst) \
319 macro(DbgRegionEndInst) \
320 macro(DbgRegionStartInst) \
321 macro(DbgStopPointInst) \
322 macro(EHSelectorInst) \
323 macro(MemIntrinsic) \
332 macro(ExtractElementInst) \
333 macro(GetElementPtrInst) \
334 macro(InsertElementInst) \
335 macro(InsertValueInst) \
338 macro(ShuffleVectorInst) \
340 macro(TerminatorInst) \
345 macro(UnreachableInst) \
347 macro(UnaryInstruction) \
348 macro(AllocationInst) \
357 macro(IntToPtrInst) \
358 macro(PtrToIntInst) \
364 macro(ExtractValueInst) \
369 /* Operations on all values */
370 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
371 const char *LLVMGetValueName(LLVMValueRef Val);
372 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
373 void LLVMDumpValue(LLVMValueRef Val);
375 /* Conversion functions. Return the input value if it is an instance of the
376 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
377 #define LLVM_DECLARE_VALUE_CAST(name) \
378 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
379 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
381 /* Operations on constants of any type */
382 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
383 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
384 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
385 int LLVMIsConstant(LLVMValueRef Val);
386 int LLVMIsNull(LLVMValueRef Val);
387 int LLVMIsUndef(LLVMValueRef Val);
389 /* Operations on scalar constants */
390 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
392 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
393 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
395 /* Operations on composite constants */
396 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
397 int DontNullTerminate);
398 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
399 LLVMValueRef *ConstantVals, unsigned Length);
400 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
402 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
404 /* Constant expressions */
405 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
406 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
407 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
408 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
409 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
410 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
411 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
412 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
413 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
414 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
415 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
416 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
417 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
418 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
419 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
420 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
421 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
422 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
423 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
424 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
425 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
428 LLVMValueRef *ConstantIndices, unsigned NumIndices);
429 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
430 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
431 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
432 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
433 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
434 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
435 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
436 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
437 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
438 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
439 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
440 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
441 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
442 LLVMValueRef ConstantIfTrue,
443 LLVMValueRef ConstantIfFalse);
444 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
445 LLVMValueRef IndexConstant);
446 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
447 LLVMValueRef ElementValueConstant,
448 LLVMValueRef IndexConstant);
449 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
450 LLVMValueRef VectorBConstant,
451 LLVMValueRef MaskConstant);
452 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
454 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
455 LLVMValueRef ElementValueConstant,
456 unsigned *IdxList, unsigned NumIdx);
457 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
458 const char *AsmString, const char *Constraints,
461 /* Operations on global variables, functions, and aliases (globals) */
462 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
463 int LLVMIsDeclaration(LLVMValueRef Global);
464 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
465 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
466 const char *LLVMGetSection(LLVMValueRef Global);
467 void LLVMSetSection(LLVMValueRef Global, const char *Section);
468 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
469 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
470 unsigned LLVMGetAlignment(LLVMValueRef Global);
471 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
473 /* Operations on global variables */
474 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
475 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
476 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
477 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
478 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
479 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
480 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
481 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
482 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
483 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
484 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
485 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
486 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
488 /* Operations on aliases */
489 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
492 /* Operations on functions */
493 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
494 LLVMTypeRef FunctionTy);
495 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
496 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
497 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
498 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
499 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
500 void LLVMDeleteFunction(LLVMValueRef Fn);
501 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
502 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
503 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
504 const char *LLVMGetGC(LLVMValueRef Fn);
505 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
507 /* Operations on parameters */
508 unsigned LLVMCountParams(LLVMValueRef Fn);
509 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
510 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
511 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
512 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
513 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
514 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
515 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
516 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
517 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
518 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
520 /* Operations on basic blocks */
521 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
522 int LLVMValueIsBasicBlock(LLVMValueRef Val);
523 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
524 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
525 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
526 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
527 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
528 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
529 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
530 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
531 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
532 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
533 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
535 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
537 /* Operations on instructions */
538 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
539 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
540 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
541 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
542 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
544 /* Operations on call sites */
545 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
546 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
547 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
548 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
550 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
553 /* Operations on call instructions (only) */
554 int LLVMIsTailCall(LLVMValueRef CallInst);
555 void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
557 /* Operations on phi nodes */
558 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
559 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
560 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
561 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
562 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
564 /*===-- Instruction builders ----------------------------------------------===*/
566 /* An instruction builder represents a point within a basic block, and is the
567 * exclusive means of building instructions using the C interface.
570 LLVMBuilderRef LLVMCreateBuilder(void);
571 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
573 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
574 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
575 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
576 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
577 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
578 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
581 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
582 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
583 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
584 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
585 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
586 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
587 LLVMBasicBlockRef Else, unsigned NumCases);
588 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
589 LLVMValueRef *Args, unsigned NumArgs,
590 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
592 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
593 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
595 /* Add a case to the switch instruction */
596 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
597 LLVMBasicBlockRef Dest);
600 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
602 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
604 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
606 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
608 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
610 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
612 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
614 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
616 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
618 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
620 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
622 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
624 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
626 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
628 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
630 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
631 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
634 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
635 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
636 LLVMValueRef Val, const char *Name);
637 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
638 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
639 LLVMValueRef Val, const char *Name);
640 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
641 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
643 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
644 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
645 LLVMValueRef *Indices, unsigned NumIndices,
649 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
650 LLVMTypeRef DestTy, const char *Name);
651 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
652 LLVMTypeRef DestTy, const char *Name);
653 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
654 LLVMTypeRef DestTy, const char *Name);
655 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
656 LLVMTypeRef DestTy, const char *Name);
657 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
658 LLVMTypeRef DestTy, const char *Name);
659 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
660 LLVMTypeRef DestTy, const char *Name);
661 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
662 LLVMTypeRef DestTy, const char *Name);
663 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
664 LLVMTypeRef DestTy, const char *Name);
665 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
666 LLVMTypeRef DestTy, const char *Name);
667 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
668 LLVMTypeRef DestTy, const char *Name);
669 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
670 LLVMTypeRef DestTy, const char *Name);
671 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
672 LLVMTypeRef DestTy, const char *Name);
675 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
676 LLVMValueRef LHS, LLVMValueRef RHS,
678 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
679 LLVMValueRef LHS, LLVMValueRef RHS,
682 /* Miscellaneous instructions */
683 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
684 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
685 LLVMValueRef *Args, unsigned NumArgs,
687 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
688 LLVMValueRef Then, LLVMValueRef Else,
690 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
692 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
693 LLVMValueRef Index, const char *Name);
694 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
695 LLVMValueRef EltVal, LLVMValueRef Index,
697 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
698 LLVMValueRef V2, LLVMValueRef Mask,
700 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
701 unsigned Index, const char *Name);
702 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
703 LLVMValueRef EltVal, unsigned Index,
707 /*===-- Module providers --------------------------------------------------===*/
709 /* Encapsulates the module M in a module provider, taking ownership of the
711 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
713 LLVMModuleProviderRef
714 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
716 /* Destroys the module provider MP as well as the contained module.
717 * See the destructor llvm::ModuleProvider::~ModuleProvider.
719 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
722 /*===-- Memory buffers ----------------------------------------------------===*/
724 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
725 LLVMMemoryBufferRef *OutMemBuf,
727 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
729 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
732 /*===-- Pass Managers -----------------------------------------------------===*/
734 /** Constructs a new whole-module pass pipeline. This type of pipeline is
735 suitable for link-time optimization and whole-module transformations.
736 See llvm::PassManager::PassManager. */
737 LLVMPassManagerRef LLVMCreatePassManager(void);
739 /** Constructs a new function-by-function pass pipeline over the module
740 provider. It does not take ownership of the module provider. This type of
741 pipeline is suitable for code generation and JIT compilation tasks.
742 See llvm::FunctionPassManager::FunctionPassManager. */
743 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
745 /** Initializes, executes on the provided module, and finalizes all of the
746 passes scheduled in the pass manager. Returns 1 if any of the passes
747 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
748 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
750 /** Initializes all of the function passes scheduled in the function pass
751 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
752 See llvm::FunctionPassManager::doInitialization. */
753 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
755 /** Executes all of the function passes scheduled in the function pass manager
756 on the provided function. Returns 1 if any of the passes modified the
757 function, false otherwise.
758 See llvm::FunctionPassManager::run(Function&). */
759 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
761 /** Finalizes all of the function passes scheduled in in the function pass
762 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
763 See llvm::FunctionPassManager::doFinalization. */
764 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
766 /** Frees the memory of a pass pipeline. For function pipelines, does not free
768 See llvm::PassManagerBase::~PassManagerBase. */
769 void LLVMDisposePassManager(LLVMPassManagerRef PM);
776 class ModuleProvider;
778 class PassManagerBase;
780 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
781 inline ty *unwrap(ref P) { \
782 return reinterpret_cast<ty*>(P); \
785 inline ref wrap(const ty *P) { \
786 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
789 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
790 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
792 template<typename T> \
793 inline T *unwrap(ref P) { \
794 return cast<T>(unwrap(P)); \
797 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
798 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
800 template<typename T> \
801 inline T *unwrap(ref P) { \
802 T *Q = dynamic_cast<T*>(unwrap(P)); \
803 assert(Q && "Invalid cast!"); \
807 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
808 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
809 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
810 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
811 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
812 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
815 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
817 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
818 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
819 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
821 /* Specialized opaque type conversions.
823 inline Type **unwrap(LLVMTypeRef* Tys) {
824 return reinterpret_cast<Type**>(Tys);
827 inline LLVMTypeRef *wrap(const Type **Tys) {
828 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
831 /* Specialized opaque value conversions.
833 inline Value **unwrap(LLVMValueRef *Vals) {
834 return reinterpret_cast<Value**>(Vals);
838 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
840 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
843 return reinterpret_cast<T**>(Vals);
846 inline LLVMValueRef *wrap(const Value **Vals) {
847 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
851 #endif /* !defined(__cplusplus) */
853 #endif /* !defined(LLVM_C_CORE_H) */