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 LLVMZExtParamAttr = 1<<0,
87 LLVMSExtParamAttr = 1<<1,
88 LLVMNoReturnParamAttr = 1<<2,
89 LLVMNoUnwindParamAttr = 1<<3,
90 LLVMInRegParamAttr = 1<<4,
91 LLVMNoAliasParamAttr = 1<<5,
92 LLVMStructRetParamAttr = 1<<6,
93 LLVMByValParamAttr = 1<<7,
94 LLVMNestParamAttr = 1<<8,
95 LLVMReadNoneParamAttr = 1<<9,
96 LLVMReadOnlyParamAttr = 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 /** See llvm::DerivedType::refineAbstractTypeTo. */
228 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
230 /* Operations on integer types */
231 LLVMTypeRef LLVMInt1Type();
232 LLVMTypeRef LLVMInt8Type();
233 LLVMTypeRef LLVMInt16Type();
234 LLVMTypeRef LLVMInt32Type();
235 LLVMTypeRef LLVMInt64Type();
236 LLVMTypeRef LLVMIntType(unsigned NumBits);
237 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
239 /* Operations on real types */
240 LLVMTypeRef LLVMFloatType();
241 LLVMTypeRef LLVMDoubleType();
242 LLVMTypeRef LLVMX86FP80Type();
243 LLVMTypeRef LLVMFP128Type();
244 LLVMTypeRef LLVMPPCFP128Type();
246 /* Operations on function types */
247 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
248 LLVMTypeRef *ParamTypes, unsigned ParamCount,
250 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
251 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
252 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
253 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
255 /* Operations on struct types */
256 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
258 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
259 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
260 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
262 /* Operations on array, pointer, and vector types (sequence types) */
263 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
264 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
265 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
267 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
268 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
269 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
270 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
272 /* Operations on other types */
273 LLVMTypeRef LLVMVoidType();
274 LLVMTypeRef LLVMLabelType();
275 LLVMTypeRef LLVMOpaqueType();
277 /* Operations on type handles */
278 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
279 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
280 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
281 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
284 /*===-- Values ------------------------------------------------------------===*/
286 /* The bulk of LLVM's object model consists of values, which comprise a very
287 * rich type hierarchy.
300 /* Operations on all values */
301 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
302 const char *LLVMGetValueName(LLVMValueRef Val);
303 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
304 void LLVMDumpValue(LLVMValueRef Val);
306 /* Operations on constants of any type */
307 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
308 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
309 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
310 int LLVMIsConstant(LLVMValueRef Val);
311 int LLVMIsNull(LLVMValueRef Val);
312 int LLVMIsUndef(LLVMValueRef Val);
314 /* Operations on scalar constants */
315 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
317 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
318 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
320 /* Operations on composite constants */
321 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
322 int DontNullTerminate);
323 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
324 LLVMValueRef *ConstantVals, unsigned Length);
325 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
327 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
329 /* Constant expressions */
330 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
331 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
332 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
333 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
334 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
335 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
336 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
337 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
338 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
339 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
340 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
341 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
342 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
343 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
344 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
345 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
346 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
347 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
348 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
349 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
350 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
351 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
352 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
353 LLVMValueRef *ConstantIndices, unsigned NumIndices);
354 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
355 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
356 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
357 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
358 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
359 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
360 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
361 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
362 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
363 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
364 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
365 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
366 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
367 LLVMValueRef ConstantIfTrue,
368 LLVMValueRef ConstantIfFalse);
369 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
370 LLVMValueRef IndexConstant);
371 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
372 LLVMValueRef ElementValueConstant,
373 LLVMValueRef IndexConstant);
374 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
375 LLVMValueRef VectorBConstant,
376 LLVMValueRef MaskConstant);
378 /* Operations on global variables, functions, and aliases (globals) */
379 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
380 int LLVMIsDeclaration(LLVMValueRef Global);
381 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
382 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
383 const char *LLVMGetSection(LLVMValueRef Global);
384 void LLVMSetSection(LLVMValueRef Global, const char *Section);
385 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
386 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
387 unsigned LLVMGetAlignment(LLVMValueRef Global);
388 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
390 /* Operations on global variables */
391 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
392 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
393 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
394 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
395 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
396 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
397 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
398 int LLVMHasInitializer(LLVMValueRef GlobalVar);
399 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
400 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
401 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
402 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
403 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
404 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
406 /* Operations on functions */
407 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
408 LLVMTypeRef FunctionTy);
409 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
410 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
411 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
412 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
413 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
414 void LLVMDeleteFunction(LLVMValueRef Fn);
415 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
416 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
417 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
418 const char *LLVMGetCollector(LLVMValueRef Fn);
419 void LLVMSetCollector(LLVMValueRef Fn, const char *Coll);
421 /* Operations on parameters */
422 unsigned LLVMCountParams(LLVMValueRef Fn);
423 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
424 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
425 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
426 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
427 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
428 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
429 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
430 void LLVMAddParamAttr(LLVMValueRef Arg, LLVMParamAttr PA);
431 void LLVMRemoveParamAttr(LLVMValueRef Arg, LLVMParamAttr PA);
432 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
434 /* Operations on basic blocks */
435 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
436 int LLVMValueIsBasicBlock(LLVMValueRef Val);
437 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
438 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
439 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
440 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
441 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
442 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
443 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
444 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
445 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
446 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
447 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
449 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
451 /* Operations on instructions */
452 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
453 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
454 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
455 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
456 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
458 /* Operations on call sites */
459 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
460 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
461 void LLVMAddInstrParamAttr(LLVMValueRef Instr, unsigned index, LLVMParamAttr);
462 void LLVMRemoveInstrParamAttr(LLVMValueRef Instr, unsigned index,
464 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
467 /* Operations on phi nodes */
468 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
469 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
470 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
471 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
472 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
474 /*===-- Instruction builders ----------------------------------------------===*/
476 /* An instruction builder represents a point within a basic block, and is the
477 * exclusive means of building instructions using the C interface.
480 LLVMBuilderRef LLVMCreateBuilder();
481 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
483 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
484 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
485 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
486 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
489 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
490 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
491 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
492 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
493 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
494 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
495 LLVMBasicBlockRef Else, unsigned NumCases);
496 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
497 LLVMValueRef *Args, unsigned NumArgs,
498 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
500 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
501 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
503 /* Add a case to the switch instruction */
504 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
505 LLVMBasicBlockRef Dest);
508 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
510 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
512 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
514 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
516 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
518 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
520 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
522 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
524 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
526 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
528 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
530 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
532 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
534 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
536 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
538 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
539 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
542 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
543 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
544 LLVMValueRef Val, const char *Name);
545 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
546 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
547 LLVMValueRef Val, const char *Name);
548 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
549 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
551 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
552 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
553 LLVMValueRef *Indices, unsigned NumIndices,
557 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
558 LLVMTypeRef DestTy, const char *Name);
559 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
560 LLVMTypeRef DestTy, const char *Name);
561 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
562 LLVMTypeRef DestTy, const char *Name);
563 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
564 LLVMTypeRef DestTy, const char *Name);
565 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
566 LLVMTypeRef DestTy, const char *Name);
567 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
568 LLVMTypeRef DestTy, const char *Name);
569 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
570 LLVMTypeRef DestTy, const char *Name);
571 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
572 LLVMTypeRef DestTy, const char *Name);
573 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
574 LLVMTypeRef DestTy, const char *Name);
575 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
576 LLVMTypeRef DestTy, const char *Name);
577 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
578 LLVMTypeRef DestTy, const char *Name);
579 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
580 LLVMTypeRef DestTy, const char *Name);
583 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
584 LLVMValueRef LHS, LLVMValueRef RHS,
586 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
587 LLVMValueRef LHS, LLVMValueRef RHS,
590 /* Miscellaneous instructions */
591 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
592 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
593 LLVMValueRef *Args, unsigned NumArgs,
595 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
596 LLVMValueRef Then, LLVMValueRef Else,
598 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
600 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
601 LLVMValueRef Index, const char *Name);
602 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
603 LLVMValueRef EltVal, LLVMValueRef Index,
605 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
606 LLVMValueRef V2, LLVMValueRef Mask,
610 /*===-- Module providers --------------------------------------------------===*/
612 /* Encapsulates the module M in a module provider, taking ownership of the
614 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
616 LLVMModuleProviderRef
617 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
619 /* Destroys the module provider MP as well as the contained module.
620 * See the destructor llvm::ModuleProvider::~ModuleProvider.
622 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
625 /*===-- Memory buffers ----------------------------------------------------===*/
627 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
628 LLVMMemoryBufferRef *OutMemBuf,
630 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
632 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
635 /*===-- Pass Managers -----------------------------------------------------===*/
637 /** Constructs a new whole-module pass pipeline. This type of pipeline is
638 suitable for link-time optimization and whole-module transformations.
639 See llvm::PassManager::PassManager. */
640 LLVMPassManagerRef LLVMCreatePassManager();
642 /** Constructs a new function-by-function pass pipeline over the module
643 provider. It does not take ownership of the module provider. This type of
644 pipeline is suitable for code generation and JIT compilation tasks.
645 See llvm::FunctionPassManager::FunctionPassManager. */
646 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
648 /** Initializes, executes on the provided module, and finalizes all of the
649 passes scheduled in the pass manager. Returns 1 if any of the passes
650 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
651 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
653 /** Initializes all of the function passes scheduled in the function pass
654 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
655 See llvm::FunctionPassManager::doInitialization. */
656 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
658 /** Executes all of the function passes scheduled in the function pass manager
659 on the provided function. Returns 1 if any of the passes modified the
660 function, false otherwise.
661 See llvm::FunctionPassManager::run(Function&). */
662 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
664 /** Finalizes all of the function passes scheduled in in the function pass
665 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
666 See llvm::FunctionPassManager::doFinalization. */
667 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
669 /** Frees the memory of a pass pipeline. For function pipelines, does not free
671 See llvm::PassManagerBase::~PassManagerBase. */
672 void LLVMDisposePassManager(LLVMPassManagerRef PM);
679 class ModuleProvider;
681 class PassManagerBase;
683 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
684 inline ty *unwrap(ref P) { \
685 return reinterpret_cast<ty*>(P); \
688 inline ref wrap(const ty *P) { \
689 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
692 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
693 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
695 template<typename T> \
696 inline T *unwrap(ref P) { \
697 return cast<T>(unwrap(P)); \
700 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
701 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
703 template<typename T> \
704 inline T *unwrap(ref P) { \
705 T *Q = dynamic_cast<T*>(unwrap(P)); \
706 assert(Q && "Invalid cast!"); \
710 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
711 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
712 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
713 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
714 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder, LLVMBuilderRef )
715 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
716 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
717 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
718 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
720 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
721 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
722 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
724 /* Specialized opaque type conversions.
726 inline Type **unwrap(LLVMTypeRef* Tys) {
727 return reinterpret_cast<Type**>(Tys);
730 inline LLVMTypeRef *wrap(const Type **Tys) {
731 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
734 /* Specialized opaque value conversions.
736 inline Value **unwrap(LLVMValueRef *Vals) {
737 return reinterpret_cast<Value**>(Vals);
741 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
743 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
746 return reinterpret_cast<T**>(Vals);
749 inline LLVMValueRef *wrap(const Value **Vals) {
750 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
754 #endif /* !defined(__cplusplus) */
756 #endif /* !defined(LLVM_C_CORE_H) */