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 LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/
119 LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */
120 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
121 LLVMInternalLinkage, /**< Rename collisions when linking (static
123 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
124 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
125 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
126 LLVMGhostLinkage /**< Stand-in functions for streaming fns from
131 LLVMDefaultVisibility, /**< The GV is visible */
132 LLVMHiddenVisibility, /**< The GV is hidden */
133 LLVMProtectedVisibility /**< The GV is protected */
138 LLVMFastCallConv = 8,
139 LLVMColdCallConv = 9,
140 LLVMX86StdcallCallConv = 64,
141 LLVMX86FastcallCallConv = 65
145 LLVMIntEQ = 32, /**< equal */
146 LLVMIntNE, /**< not equal */
147 LLVMIntUGT, /**< unsigned greater than */
148 LLVMIntUGE, /**< unsigned greater or equal */
149 LLVMIntULT, /**< unsigned less than */
150 LLVMIntULE, /**< unsigned less or equal */
151 LLVMIntSGT, /**< signed greater than */
152 LLVMIntSGE, /**< signed greater or equal */
153 LLVMIntSLT, /**< signed less than */
154 LLVMIntSLE /**< signed less or equal */
158 LLVMRealPredicateFalse, /**< Always false (always folded) */
159 LLVMRealOEQ, /**< True if ordered and equal */
160 LLVMRealOGT, /**< True if ordered and greater than */
161 LLVMRealOGE, /**< True if ordered and greater than or equal */
162 LLVMRealOLT, /**< True if ordered and less than */
163 LLVMRealOLE, /**< True if ordered and less than or equal */
164 LLVMRealONE, /**< True if ordered and operands are unequal */
165 LLVMRealORD, /**< True if ordered (no nans) */
166 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
167 LLVMRealUEQ, /**< True if unordered or equal */
168 LLVMRealUGT, /**< True if unordered or greater than */
169 LLVMRealUGE, /**< True if unordered, greater than, or equal */
170 LLVMRealULT, /**< True if unordered or less than */
171 LLVMRealULE, /**< True if unordered, less than, or equal */
172 LLVMRealUNE, /**< True if unordered or not equal */
173 LLVMRealPredicateTrue /**< Always true (always folded) */
177 /*===-- Error handling ----------------------------------------------------===*/
179 void LLVMDisposeMessage(char *Message);
182 /*===-- Modules -----------------------------------------------------------===*/
184 /* Create and destroy modules. */
185 /** See llvm::Module::Module. */
186 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
188 /** See llvm::Module::~Module. */
189 void LLVMDisposeModule(LLVMModuleRef M);
191 /** Data layout. See Module::getDataLayout. */
192 const char *LLVMGetDataLayout(LLVMModuleRef M);
193 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
195 /** Target triple. See Module::getTargetTriple. */
196 const char *LLVMGetTarget(LLVMModuleRef M);
197 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
199 /** See Module::addTypeName. */
200 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
201 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
203 /** See Module::dump. */
204 void LLVMDumpModule(LLVMModuleRef M);
207 /*===-- Types -------------------------------------------------------------===*/
209 /* LLVM types conform to the following hierarchy:
224 /** See llvm::LLVMTypeKind::getTypeID. */
225 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
227 /* Operations on integer types */
228 LLVMTypeRef LLVMInt1Type(void);
229 LLVMTypeRef LLVMInt8Type(void);
230 LLVMTypeRef LLVMInt16Type(void);
231 LLVMTypeRef LLVMInt32Type(void);
232 LLVMTypeRef LLVMInt64Type(void);
233 LLVMTypeRef LLVMIntType(unsigned NumBits);
234 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
236 /* Operations on real types */
237 LLVMTypeRef LLVMFloatType(void);
238 LLVMTypeRef LLVMDoubleType(void);
239 LLVMTypeRef LLVMX86FP80Type(void);
240 LLVMTypeRef LLVMFP128Type(void);
241 LLVMTypeRef LLVMPPCFP128Type(void);
243 /* Operations on function types */
244 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
245 LLVMTypeRef *ParamTypes, unsigned ParamCount,
247 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
248 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
249 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
250 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
252 /* Operations on struct types */
253 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
255 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
256 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
257 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
259 /* Operations on array, pointer, and vector types (sequence types) */
260 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
261 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
262 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
264 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
265 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
266 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
267 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
269 /* Operations on other types */
270 LLVMTypeRef LLVMVoidType(void);
271 LLVMTypeRef LLVMLabelType(void);
272 LLVMTypeRef LLVMOpaqueType(void);
274 /* Operations on type handles */
275 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
276 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
277 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
278 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
281 /*===-- Values ------------------------------------------------------------===*/
283 /* The bulk of LLVM's object model consists of values, which comprise a very
284 * rich type hierarchy.
287 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
293 macro(ConstantAggregateZero) \
294 macro(ConstantArray) \
295 macro(ConstantExpr) \
298 macro(ConstantPointerNull) \
299 macro(ConstantStruct) \
300 macro(ConstantVector) \
304 macro(GlobalVariable) \
307 macro(BinaryOperator) \
309 macro(IntrinsicInst) \
310 macro(DbgInfoIntrinsic) \
311 macro(DbgDeclareInst) \
312 macro(DbgFuncStartInst) \
313 macro(DbgRegionEndInst) \
314 macro(DbgRegionStartInst) \
315 macro(DbgStopPointInst) \
316 macro(EHSelectorInst) \
317 macro(MemIntrinsic) \
326 macro(ExtractElementInst) \
327 macro(GetElementPtrInst) \
328 macro(InsertElementInst) \
329 macro(InsertValueInst) \
332 macro(ShuffleVectorInst) \
334 macro(TerminatorInst) \
339 macro(UnreachableInst) \
341 macro(UnaryInstruction) \
342 macro(AllocationInst) \
344 macro(ExtractValueInst)
346 /* Operations on all values */
347 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
348 const char *LLVMGetValueName(LLVMValueRef Val);
349 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
350 void LLVMDumpValue(LLVMValueRef Val);
352 /* Conversion functions. Return the input value if it is an instance of the
353 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
354 #define LLVM_DECLARE_VALUE_CAST(name) \
355 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
356 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
358 /* Operations on constants of any type */
359 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
360 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
361 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
362 int LLVMIsConstant(LLVMValueRef Val);
363 int LLVMIsNull(LLVMValueRef Val);
364 int LLVMIsUndef(LLVMValueRef Val);
366 /* Operations on scalar constants */
367 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
369 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
370 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
372 /* Operations on composite constants */
373 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
374 int DontNullTerminate);
375 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
376 LLVMValueRef *ConstantVals, unsigned Length);
377 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
379 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
381 /* Constant expressions */
382 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
383 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
384 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
385 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
386 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
387 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
388 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
389 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
390 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
391 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
392 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
393 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
394 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
395 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
396 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
397 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
398 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
399 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
400 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
401 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
402 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
403 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
404 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
405 LLVMValueRef *ConstantIndices, unsigned NumIndices);
406 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
407 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
408 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
409 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
410 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
411 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
412 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
413 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
414 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
415 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
416 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
417 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
418 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
419 LLVMValueRef ConstantIfTrue,
420 LLVMValueRef ConstantIfFalse);
421 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
422 LLVMValueRef IndexConstant);
423 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
424 LLVMValueRef ElementValueConstant,
425 LLVMValueRef IndexConstant);
426 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
427 LLVMValueRef VectorBConstant,
428 LLVMValueRef MaskConstant);
429 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
431 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
432 LLVMValueRef ElementValueConstant,
433 unsigned *IdxList, unsigned NumIdx);
434 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
435 const char *AsmString, const char *Constraints,
438 /* Operations on global variables, functions, and aliases (globals) */
439 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
440 int LLVMIsDeclaration(LLVMValueRef Global);
441 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
442 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
443 const char *LLVMGetSection(LLVMValueRef Global);
444 void LLVMSetSection(LLVMValueRef Global, const char *Section);
445 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
446 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
447 unsigned LLVMGetAlignment(LLVMValueRef Global);
448 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
450 /* Operations on global variables */
451 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
452 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
453 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
454 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
455 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
456 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
457 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
458 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
459 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
460 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
461 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
462 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
463 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
465 /* Operations on aliases */
466 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
469 /* Operations on functions */
470 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
471 LLVMTypeRef FunctionTy);
472 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
473 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
474 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
475 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
476 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
477 void LLVMDeleteFunction(LLVMValueRef Fn);
478 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
479 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
480 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
481 const char *LLVMGetGC(LLVMValueRef Fn);
482 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
484 /* Operations on parameters */
485 unsigned LLVMCountParams(LLVMValueRef Fn);
486 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
487 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
488 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
489 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
490 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
491 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
492 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
493 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
494 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
495 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
497 /* Operations on basic blocks */
498 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
499 int LLVMValueIsBasicBlock(LLVMValueRef Val);
500 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
501 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
502 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
503 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
504 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
505 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
506 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
507 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
508 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
509 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
510 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
512 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
514 /* Operations on instructions */
515 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
516 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
517 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
518 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
519 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
521 /* Operations on call sites */
522 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
523 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
524 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
525 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
527 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
530 /* Operations on call instructions (only) */
531 int LLVMIsTailCall(LLVMValueRef CallInst);
532 void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
534 /* Operations on phi nodes */
535 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
536 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
537 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
538 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
539 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
541 /*===-- Instruction builders ----------------------------------------------===*/
543 /* An instruction builder represents a point within a basic block, and is the
544 * exclusive means of building instructions using the C interface.
547 LLVMBuilderRef LLVMCreateBuilder(void);
548 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
550 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
551 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
552 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
553 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
554 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
555 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
558 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
559 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
560 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
561 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
562 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
563 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
564 LLVMBasicBlockRef Else, unsigned NumCases);
565 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
566 LLVMValueRef *Args, unsigned NumArgs,
567 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
569 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
570 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
572 /* Add a case to the switch instruction */
573 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
574 LLVMBasicBlockRef Dest);
577 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
579 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
581 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
583 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
585 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
587 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
589 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
591 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
593 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
595 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
597 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
599 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
601 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
603 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
605 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
607 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
608 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
611 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
612 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
613 LLVMValueRef Val, const char *Name);
614 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
615 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
616 LLVMValueRef Val, const char *Name);
617 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
618 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
620 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
621 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
622 LLVMValueRef *Indices, unsigned NumIndices,
626 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
627 LLVMTypeRef DestTy, const char *Name);
628 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
629 LLVMTypeRef DestTy, const char *Name);
630 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
631 LLVMTypeRef DestTy, const char *Name);
632 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
633 LLVMTypeRef DestTy, const char *Name);
634 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
635 LLVMTypeRef DestTy, const char *Name);
636 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
637 LLVMTypeRef DestTy, const char *Name);
638 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
639 LLVMTypeRef DestTy, const char *Name);
640 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
641 LLVMTypeRef DestTy, const char *Name);
642 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
643 LLVMTypeRef DestTy, const char *Name);
644 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
645 LLVMTypeRef DestTy, const char *Name);
646 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
647 LLVMTypeRef DestTy, const char *Name);
648 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
649 LLVMTypeRef DestTy, const char *Name);
652 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
653 LLVMValueRef LHS, LLVMValueRef RHS,
655 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
656 LLVMValueRef LHS, LLVMValueRef RHS,
659 /* Miscellaneous instructions */
660 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
661 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
662 LLVMValueRef *Args, unsigned NumArgs,
664 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
665 LLVMValueRef Then, LLVMValueRef Else,
667 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
669 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
670 LLVMValueRef Index, const char *Name);
671 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
672 LLVMValueRef EltVal, LLVMValueRef Index,
674 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
675 LLVMValueRef V2, LLVMValueRef Mask,
677 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
678 unsigned Index, const char *Name);
679 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
680 LLVMValueRef EltVal, unsigned Index,
684 /*===-- Module providers --------------------------------------------------===*/
686 /* Encapsulates the module M in a module provider, taking ownership of the
688 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
690 LLVMModuleProviderRef
691 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
693 /* Destroys the module provider MP as well as the contained module.
694 * See the destructor llvm::ModuleProvider::~ModuleProvider.
696 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
699 /*===-- Memory buffers ----------------------------------------------------===*/
701 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
702 LLVMMemoryBufferRef *OutMemBuf,
704 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
706 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
709 /*===-- Pass Managers -----------------------------------------------------===*/
711 /** Constructs a new whole-module pass pipeline. This type of pipeline is
712 suitable for link-time optimization and whole-module transformations.
713 See llvm::PassManager::PassManager. */
714 LLVMPassManagerRef LLVMCreatePassManager(void);
716 /** Constructs a new function-by-function pass pipeline over the module
717 provider. It does not take ownership of the module provider. This type of
718 pipeline is suitable for code generation and JIT compilation tasks.
719 See llvm::FunctionPassManager::FunctionPassManager. */
720 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
722 /** Initializes, executes on the provided module, and finalizes all of the
723 passes scheduled in the pass manager. Returns 1 if any of the passes
724 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
725 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
727 /** Initializes all of the function passes scheduled in the function pass
728 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
729 See llvm::FunctionPassManager::doInitialization. */
730 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
732 /** Executes all of the function passes scheduled in the function pass manager
733 on the provided function. Returns 1 if any of the passes modified the
734 function, false otherwise.
735 See llvm::FunctionPassManager::run(Function&). */
736 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
738 /** Finalizes all of the function passes scheduled in in the function pass
739 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
740 See llvm::FunctionPassManager::doFinalization. */
741 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
743 /** Frees the memory of a pass pipeline. For function pipelines, does not free
745 See llvm::PassManagerBase::~PassManagerBase. */
746 void LLVMDisposePassManager(LLVMPassManagerRef PM);
753 class ModuleProvider;
755 class PassManagerBase;
757 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
758 inline ty *unwrap(ref P) { \
759 return reinterpret_cast<ty*>(P); \
762 inline ref wrap(const ty *P) { \
763 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
766 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
767 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
769 template<typename T> \
770 inline T *unwrap(ref P) { \
771 return cast<T>(unwrap(P)); \
774 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
775 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
777 template<typename T> \
778 inline T *unwrap(ref P) { \
779 T *Q = dynamic_cast<T*>(unwrap(P)); \
780 assert(Q && "Invalid cast!"); \
784 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
785 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
786 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
787 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
788 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
789 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
790 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
791 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
792 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
794 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
795 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
796 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
798 /* Specialized opaque type conversions.
800 inline Type **unwrap(LLVMTypeRef* Tys) {
801 return reinterpret_cast<Type**>(Tys);
804 inline LLVMTypeRef *wrap(const Type **Tys) {
805 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
808 /* Specialized opaque value conversions.
810 inline Value **unwrap(LLVMValueRef *Vals) {
811 return reinterpret_cast<Value**>(Vals);
815 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
817 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
820 return reinterpret_cast<T**>(Vals);
823 inline LLVMValueRef *wrap(const Value **Vals) {
824 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
828 #endif /* !defined(__cplusplus) */
830 #endif /* !defined(LLVM_C_CORE_H) */