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/LLVMBuilder.h"
42 #include "llvm/Pass.h"
43 #include "llvm/PassManager.h"
52 * The top-level container for all other LLVM Intermediate Representation (IR)
53 * objects. See the llvm::Module class.
55 typedef struct LLVMOpaqueModule *LLVMModuleRef;
58 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
61 typedef struct LLVMOpaqueType *LLVMTypeRef;
64 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
65 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
66 * llvm::AbstractTypeHolder class.
68 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
70 typedef struct LLVMOpaqueValue *LLVMValueRef;
71 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
72 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
74 /* Used to provide a module to JIT or interpreter.
75 * See the llvm::ModuleProvider class.
77 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
79 /* Used to provide a module to JIT or interpreter.
80 * See the llvm::MemoryBuffer class.
82 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
84 /** See the llvm::PassManagerBase class. */
85 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
88 LLVMVoidTypeKind, /**< type with no size */
89 LLVMFloatTypeKind, /**< 32 bit floating point type */
90 LLVMDoubleTypeKind, /**< 64 bit floating point type */
91 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
92 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
93 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
94 LLVMLabelTypeKind, /**< Labels */
95 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
96 LLVMFunctionTypeKind, /**< Functions */
97 LLVMStructTypeKind, /**< Structures */
98 LLVMArrayTypeKind, /**< Arrays */
99 LLVMPointerTypeKind, /**< Pointers */
100 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
101 LLVMVectorTypeKind /**< SIMD 'packed' format, or other vector type */
105 LLVMExternalLinkage, /**< Externally visible function */
106 LLVMLinkOnceLinkage, /**< Keep one copy of function when linking (inline)*/
107 LLVMWeakLinkage, /**< Keep one copy of function when linking (weak) */
108 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
109 LLVMInternalLinkage, /**< Rename collisions when linking (static
111 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
112 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
113 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
114 LLVMGhostLinkage /**< Stand-in functions for streaming fns from
119 LLVMDefaultVisibility, /**< The GV is visible */
120 LLVMHiddenVisibility, /**< The GV is hidden */
121 LLVMProtectedVisibility /**< The GV is protected */
126 LLVMFastCallConv = 8,
127 LLVMColdCallConv = 9,
128 LLVMX86StdcallCallConv = 64,
129 LLVMX86FastcallCallConv = 65
133 LLVMIntEQ = 32, /**< equal */
134 LLVMIntNE, /**< not equal */
135 LLVMIntUGT, /**< unsigned greater than */
136 LLVMIntUGE, /**< unsigned greater or equal */
137 LLVMIntULT, /**< unsigned less than */
138 LLVMIntULE, /**< unsigned less or equal */
139 LLVMIntSGT, /**< signed greater than */
140 LLVMIntSGE, /**< signed greater or equal */
141 LLVMIntSLT, /**< signed less than */
142 LLVMIntSLE /**< signed less or equal */
146 LLVMRealPredicateFalse, /**< Always false (always folded) */
147 LLVMRealOEQ, /**< True if ordered and equal */
148 LLVMRealOGT, /**< True if ordered and greater than */
149 LLVMRealOGE, /**< True if ordered and greater than or equal */
150 LLVMRealOLT, /**< True if ordered and less than */
151 LLVMRealOLE, /**< True if ordered and less than or equal */
152 LLVMRealONE, /**< True if ordered and operands are unequal */
153 LLVMRealORD, /**< True if ordered (no nans) */
154 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
155 LLVMRealUEQ, /**< True if unordered or equal */
156 LLVMRealUGT, /**< True if unordered or greater than */
157 LLVMRealUGE, /**< True if unordered, greater than, or equal */
158 LLVMRealULT, /**< True if unordered or less than */
159 LLVMRealULE, /**< True if unordered, less than, or equal */
160 LLVMRealUNE, /**< True if unordered or not equal */
161 LLVMRealPredicateTrue /**< Always true (always folded) */
165 /*===-- Error handling ----------------------------------------------------===*/
167 void LLVMDisposeMessage(char *Message);
170 /*===-- Modules -----------------------------------------------------------===*/
172 /* Create and destroy modules. */
173 /** See llvm::Module::Module. */
174 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
176 /** See llvm::Module::~Module. */
177 void LLVMDisposeModule(LLVMModuleRef M);
179 /** Data layout. See Module::getDataLayout. */
180 const char *LLVMGetDataLayout(LLVMModuleRef M);
181 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
183 /** Target triple. See Module::getTargetTriple. */
184 const char *LLVMGetTarget(LLVMModuleRef M);
185 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
187 /** See Module::addTypeName. */
188 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
189 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
191 /** See Module::dump. */
192 void LLVMDumpModule(LLVMModuleRef M);
195 /*===-- Types -------------------------------------------------------------===*/
197 /* LLVM types conform to the following hierarchy:
212 /** See llvm::LLVMTypeKind::getTypeID. */
213 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
215 /** See llvm::DerivedType::refineAbstractTypeTo. */
216 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
218 /* Operations on integer types */
219 LLVMTypeRef LLVMInt1Type();
220 LLVMTypeRef LLVMInt8Type();
221 LLVMTypeRef LLVMInt16Type();
222 LLVMTypeRef LLVMInt32Type();
223 LLVMTypeRef LLVMInt64Type();
224 LLVMTypeRef LLVMIntType(unsigned NumBits);
225 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
227 /* Operations on real types */
228 LLVMTypeRef LLVMFloatType();
229 LLVMTypeRef LLVMDoubleType();
230 LLVMTypeRef LLVMX86FP80Type();
231 LLVMTypeRef LLVMFP128Type();
232 LLVMTypeRef LLVMPPCFP128Type();
234 /* Operations on function types */
235 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
236 LLVMTypeRef *ParamTypes, unsigned ParamCount,
238 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
239 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
240 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
241 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
243 /* Operations on struct types */
244 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
246 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
247 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
248 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
250 /* Operations on array, pointer, and vector types (sequence types) */
251 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
252 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
253 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
255 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
256 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
257 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
258 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
260 /* Operations on other types */
261 LLVMTypeRef LLVMVoidType();
262 LLVMTypeRef LLVMLabelType();
263 LLVMTypeRef LLVMOpaqueType();
265 /* Operations on type handles */
266 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
267 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
268 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
269 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
272 /*===-- Values ------------------------------------------------------------===*/
274 /* The bulk of LLVM's object model consists of values, which comprise a very
275 * rich type hierarchy.
288 /* Operations on all values */
289 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
290 const char *LLVMGetValueName(LLVMValueRef Val);
291 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
292 void LLVMDumpValue(LLVMValueRef Val);
294 /* Operations on constants of any type */
295 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
296 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
297 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
298 int LLVMIsConstant(LLVMValueRef Val);
299 int LLVMIsNull(LLVMValueRef Val);
300 int LLVMIsUndef(LLVMValueRef Val);
302 /* Operations on scalar constants */
303 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
305 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
306 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
308 /* Operations on composite constants */
309 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
310 int DontNullTerminate);
311 LLVMValueRef LLVMConstArray(LLVMTypeRef ArrayTy,
312 LLVMValueRef *ConstantVals, unsigned Length);
313 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
315 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
317 /* Constant expressions */
318 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
319 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
320 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
321 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
322 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
323 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
324 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
325 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
326 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
327 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
328 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
329 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
330 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
331 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
332 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
333 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
334 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
335 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
336 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
337 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
338 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
339 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
340 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
341 LLVMValueRef *ConstantIndices, unsigned NumIndices);
342 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
343 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
344 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
345 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
346 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
347 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
348 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
349 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
350 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
351 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
352 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
353 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
354 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
355 LLVMValueRef ConstantIfTrue,
356 LLVMValueRef ConstantIfFalse);
357 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
358 LLVMValueRef IndexConstant);
359 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
360 LLVMValueRef ElementValueConstant,
361 LLVMValueRef IndexConstant);
362 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
363 LLVMValueRef VectorBConstant,
364 LLVMValueRef MaskConstant);
366 /* Operations on global variables, functions, and aliases (globals) */
367 int LLVMIsDeclaration(LLVMValueRef Global);
368 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
369 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
370 const char *LLVMGetSection(LLVMValueRef Global);
371 void LLVMSetSection(LLVMValueRef Global, const char *Section);
372 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
373 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
374 unsigned LLVMGetAlignment(LLVMValueRef Global);
375 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
377 /* Operations on global variables */
378 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
379 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
380 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
381 int LLVMHasInitializer(LLVMValueRef GlobalVar);
382 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
383 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
384 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
385 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
386 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
387 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
389 /* Operations on functions */
390 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
391 LLVMTypeRef FunctionTy);
392 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
393 void LLVMDeleteFunction(LLVMValueRef Fn);
394 unsigned LLVMCountParams(LLVMValueRef Fn);
395 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
396 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
397 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
398 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
399 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
400 const char *LLVMGetCollector(LLVMValueRef Fn);
401 void LLVMSetCollector(LLVMValueRef Fn, const char *Coll);
403 /* Operations on basic blocks */
404 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
405 int LLVMValueIsBasicBlock(LLVMValueRef Val);
406 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
407 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
408 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
409 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
410 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
411 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
413 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
415 /* Operations on call sites */
416 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
417 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
419 /* Operations on phi nodes */
420 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
421 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
422 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
423 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
424 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
426 /*===-- Instruction builders ----------------------------------------------===*/
428 /* An instruction builder represents a point within a basic block, and is the
429 * exclusive means of building instructions using the C interface.
432 LLVMBuilderRef LLVMCreateBuilder();
433 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
434 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
435 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
438 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
439 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
440 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
441 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
442 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
443 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
444 LLVMBasicBlockRef Else, unsigned NumCases);
445 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
446 LLVMValueRef *Args, unsigned NumArgs,
447 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
449 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
450 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
452 /* Add a case to the switch instruction */
453 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
454 LLVMBasicBlockRef Dest);
457 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
459 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
461 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
463 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
465 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
467 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
469 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
471 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
473 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
475 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
477 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
479 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
481 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
483 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
485 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
487 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
488 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
491 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
492 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
493 LLVMValueRef Val, const char *Name);
494 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
495 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
496 LLVMValueRef Val, const char *Name);
497 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
498 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
500 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
501 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
502 LLVMValueRef *Indices, unsigned NumIndices,
506 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
507 LLVMTypeRef DestTy, const char *Name);
508 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
509 LLVMTypeRef DestTy, const char *Name);
510 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
511 LLVMTypeRef DestTy, const char *Name);
512 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
513 LLVMTypeRef DestTy, const char *Name);
514 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
515 LLVMTypeRef DestTy, const char *Name);
516 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
517 LLVMTypeRef DestTy, const char *Name);
518 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
519 LLVMTypeRef DestTy, const char *Name);
520 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
521 LLVMTypeRef DestTy, const char *Name);
522 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
523 LLVMTypeRef DestTy, const char *Name);
524 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
525 LLVMTypeRef DestTy, const char *Name);
526 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
527 LLVMTypeRef DestTy, const char *Name);
528 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
529 LLVMTypeRef DestTy, const char *Name);
532 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
533 LLVMValueRef LHS, LLVMValueRef RHS,
535 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
536 LLVMValueRef LHS, LLVMValueRef RHS,
539 /* Miscellaneous instructions */
540 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
541 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
542 LLVMValueRef *Args, unsigned NumArgs,
544 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
545 LLVMValueRef Then, LLVMValueRef Else,
547 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
549 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
550 LLVMValueRef Index, const char *Name);
551 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
552 LLVMValueRef EltVal, LLVMValueRef Index,
554 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
555 LLVMValueRef V2, LLVMValueRef Mask,
559 /*===-- Module providers --------------------------------------------------===*/
561 /* Encapsulates the module M in a module provider, taking ownership of the
563 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
565 LLVMModuleProviderRef
566 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
568 /* Destroys the module provider MP as well as the contained module.
569 * See the destructor llvm::ModuleProvider::~ModuleProvider.
571 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
574 /*===-- Memory buffers ----------------------------------------------------===*/
576 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
577 LLVMMemoryBufferRef *OutMemBuf,
579 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
581 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
584 /*===-- Pass Managers -----------------------------------------------------===*/
586 /** Constructs a new whole-module pass pipeline. This type of pipeline is
587 suitable for link-time optimization and whole-module transformations.
588 See llvm::PassManager::PassManager. */
589 LLVMPassManagerRef LLVMCreatePassManager();
591 /** Constructs a new function-by-function pass pipeline over the module
592 provider. It does not take ownership of the module provider. This type of
593 pipeline is suitable for code generation and JIT compilation tasks.
594 See llvm::FunctionPassManager::FunctionPassManager. */
595 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
597 /** Initializes, executes on the provided module, and finalizes all of the
598 passes scheduled in the pass manager. Returns 1 if any of the passes
599 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
600 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
602 /** Initializes all of the function passes scheduled in the function pass
603 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
604 See llvm::FunctionPassManager::doInitialization. */
605 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
607 /** Executes all of the function passes scheduled in the function pass manager
608 on the provided function. Returns 1 if any of the passes modified the
609 function, false otherwise.
610 See llvm::FunctionPassManager::run(Function&). */
611 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
613 /** Finalizes all of the function passes scheduled in in the function pass
614 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
615 See llvm::FunctionPassManager::doFinalization. */
616 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
618 /** Frees the memory of a pass pipeline. For function pipelines, does not free
620 See llvm::PassManagerBase::~PassManagerBase. */
621 void LLVMDisposePassManager(LLVMPassManagerRef PM);
628 class ModuleProvider;
631 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
632 inline ty *unwrap(ref P) { \
633 return reinterpret_cast<ty*>(P); \
636 inline ref wrap(const ty *P) { \
637 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
640 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
641 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
643 template<typename T> \
644 inline T *unwrap(ref P) { \
645 return cast<T>(unwrap(P)); \
648 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
649 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
651 template<typename T> \
652 inline T *unwrap(ref P) { \
653 T *Q = dynamic_cast<T*>(unwrap(P)); \
654 assert(Q && "Invalid cast!"); \
658 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
659 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
660 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
661 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
662 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef )
663 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
664 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
665 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
666 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
668 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
669 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
670 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
672 /* Specialized opaque type conversions.
674 inline Type **unwrap(LLVMTypeRef* Tys) {
675 return reinterpret_cast<Type**>(Tys);
678 inline LLVMTypeRef *wrap(const Type **Tys) {
679 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
682 /* Specialized opaque value conversions.
684 inline Value **unwrap(LLVMValueRef *Vals) {
685 return reinterpret_cast<Value**>(Vals);
689 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
691 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
694 return reinterpret_cast<T**>(Vals);
697 inline LLVMValueRef *wrap(const Value **Vals) {
698 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
702 #endif /* !defined(__cplusplus) */
704 #endif /* !defined(LLVM_C_CORE_H) */