PPC::B and PPC::BCC's target operand may be an immediate.
[llvm/msp430.git] / include / llvm-c / Core.h
blobd2d88454d711ee2d11f2750044970ddddda5726e
1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2 |* *|
3 |* The LLVM Compiler Infrastructure *|
4 |* *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This header declares the C interface to libLLVMCore.a, which implements *|
11 |* the LLVM intermediate representation. *|
12 |* *|
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). *|
21 |* *|
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. *|
25 |* *|
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. *|
30 |* *|
31 \*===----------------------------------------------------------------------===*/
33 #ifndef LLVM_C_CORE_H
34 #define LLVM_C_CORE_H
36 #ifdef __cplusplus
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"
43 extern "C" {
44 #endif
47 /* Opaque types. */
49 /**
50 * The top-level container for all other LLVM Intermediate Representation (IR)
51 * objects. See the llvm::Module class.
53 typedef struct LLVMOpaqueModule *LLVMModuleRef;
55 /**
56 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
57 * class.
59 typedef struct LLVMOpaqueType *LLVMTypeRef;
61 /**
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;
85 typedef enum {
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
97 } LLVMAttribute;
99 typedef enum {
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 */
114 } LLVMTypeKind;
116 typedef enum {
117 LLVMExternalLinkage, /**< Externally visible function */
118 LLVMAvailableExternallyLinkage,
119 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
120 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
121 equivalent. */
122 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
123 LLVMWeakODRLinkage, /**< Same, but only replaced by something
124 equivalent. */
125 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
126 LLVMInternalLinkage, /**< Rename collisions when linking (static
127 functions) */
128 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
129 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
130 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
131 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
132 LLVMGhostLinkage, /**< Stand-in functions for streaming fns from
133 bitcode */
134 LLVMCommonLinkage /**< Tentative definitions */
135 } LLVMLinkage;
137 typedef enum {
138 LLVMDefaultVisibility, /**< The GV is visible */
139 LLVMHiddenVisibility, /**< The GV is hidden */
140 LLVMProtectedVisibility /**< The GV is protected */
141 } LLVMVisibility;
143 typedef enum {
144 LLVMCCallConv = 0,
145 LLVMFastCallConv = 8,
146 LLVMColdCallConv = 9,
147 LLVMX86StdcallCallConv = 64,
148 LLVMX86FastcallCallConv = 65
149 } LLVMCallConv;
151 typedef enum {
152 LLVMIntEQ = 32, /**< equal */
153 LLVMIntNE, /**< not equal */
154 LLVMIntUGT, /**< unsigned greater than */
155 LLVMIntUGE, /**< unsigned greater or equal */
156 LLVMIntULT, /**< unsigned less than */
157 LLVMIntULE, /**< unsigned less or equal */
158 LLVMIntSGT, /**< signed greater than */
159 LLVMIntSGE, /**< signed greater or equal */
160 LLVMIntSLT, /**< signed less than */
161 LLVMIntSLE /**< signed less or equal */
162 } LLVMIntPredicate;
164 typedef enum {
165 LLVMRealPredicateFalse, /**< Always false (always folded) */
166 LLVMRealOEQ, /**< True if ordered and equal */
167 LLVMRealOGT, /**< True if ordered and greater than */
168 LLVMRealOGE, /**< True if ordered and greater than or equal */
169 LLVMRealOLT, /**< True if ordered and less than */
170 LLVMRealOLE, /**< True if ordered and less than or equal */
171 LLVMRealONE, /**< True if ordered and operands are unequal */
172 LLVMRealORD, /**< True if ordered (no nans) */
173 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
174 LLVMRealUEQ, /**< True if unordered or equal */
175 LLVMRealUGT, /**< True if unordered or greater than */
176 LLVMRealUGE, /**< True if unordered, greater than, or equal */
177 LLVMRealULT, /**< True if unordered or less than */
178 LLVMRealULE, /**< True if unordered, less than, or equal */
179 LLVMRealUNE, /**< True if unordered or not equal */
180 LLVMRealPredicateTrue /**< Always true (always folded) */
181 } LLVMRealPredicate;
184 /*===-- Error handling ----------------------------------------------------===*/
186 void LLVMDisposeMessage(char *Message);
189 /*===-- Modules -----------------------------------------------------------===*/
191 /* Create and destroy modules. */
192 /** See llvm::Module::Module. */
193 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
195 /** See llvm::Module::~Module. */
196 void LLVMDisposeModule(LLVMModuleRef M);
198 /** Data layout. See Module::getDataLayout. */
199 const char *LLVMGetDataLayout(LLVMModuleRef M);
200 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
202 /** Target triple. See Module::getTargetTriple. */
203 const char *LLVMGetTarget(LLVMModuleRef M);
204 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
206 /** See Module::addTypeName. */
207 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
208 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
210 /** See Module::dump. */
211 void LLVMDumpModule(LLVMModuleRef M);
214 /*===-- Types -------------------------------------------------------------===*/
216 /* LLVM types conform to the following hierarchy:
218 * types:
219 * integer type
220 * real type
221 * function type
222 * sequence types:
223 * array type
224 * pointer type
225 * vector type
226 * void type
227 * label type
228 * opaque type
231 /** See llvm::LLVMTypeKind::getTypeID. */
232 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
234 /* Operations on integer types */
235 LLVMTypeRef LLVMInt1Type(void);
236 LLVMTypeRef LLVMInt8Type(void);
237 LLVMTypeRef LLVMInt16Type(void);
238 LLVMTypeRef LLVMInt32Type(void);
239 LLVMTypeRef LLVMInt64Type(void);
240 LLVMTypeRef LLVMIntType(unsigned NumBits);
241 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
243 /* Operations on real types */
244 LLVMTypeRef LLVMFloatType(void);
245 LLVMTypeRef LLVMDoubleType(void);
246 LLVMTypeRef LLVMX86FP80Type(void);
247 LLVMTypeRef LLVMFP128Type(void);
248 LLVMTypeRef LLVMPPCFP128Type(void);
250 /* Operations on function types */
251 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
252 LLVMTypeRef *ParamTypes, unsigned ParamCount,
253 int IsVarArg);
254 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
255 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
256 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
257 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
259 /* Operations on struct types */
260 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
261 int Packed);
262 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
263 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
264 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
266 /* Operations on array, pointer, and vector types (sequence types) */
267 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
268 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
269 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
271 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
272 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
273 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
274 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
276 /* Operations on other types */
277 LLVMTypeRef LLVMVoidType(void);
278 LLVMTypeRef LLVMLabelType(void);
279 LLVMTypeRef LLVMOpaqueType(void);
281 /* Operations on type handles */
282 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
283 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
284 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
285 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
288 /*===-- Values ------------------------------------------------------------===*/
290 /* The bulk of LLVM's object model consists of values, which comprise a very
291 * rich type hierarchy.
294 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
295 macro(Argument) \
296 macro(BasicBlock) \
297 macro(InlineAsm) \
298 macro(User) \
299 macro(Constant) \
300 macro(ConstantAggregateZero) \
301 macro(ConstantArray) \
302 macro(ConstantExpr) \
303 macro(ConstantFP) \
304 macro(ConstantInt) \
305 macro(ConstantPointerNull) \
306 macro(ConstantStruct) \
307 macro(ConstantVector) \
308 macro(GlobalValue) \
309 macro(Function) \
310 macro(GlobalAlias) \
311 macro(GlobalVariable) \
312 macro(UndefValue) \
313 macro(Instruction) \
314 macro(BinaryOperator) \
315 macro(CallInst) \
316 macro(IntrinsicInst) \
317 macro(DbgInfoIntrinsic) \
318 macro(DbgDeclareInst) \
319 macro(DbgFuncStartInst) \
320 macro(DbgRegionEndInst) \
321 macro(DbgRegionStartInst) \
322 macro(DbgStopPointInst) \
323 macro(EHSelectorInst) \
324 macro(MemIntrinsic) \
325 macro(MemCpyInst) \
326 macro(MemMoveInst) \
327 macro(MemSetInst) \
328 macro(CmpInst) \
329 macro(FCmpInst) \
330 macro(ICmpInst) \
331 macro(VFCmpInst) \
332 macro(VICmpInst) \
333 macro(ExtractElementInst) \
334 macro(GetElementPtrInst) \
335 macro(InsertElementInst) \
336 macro(InsertValueInst) \
337 macro(PHINode) \
338 macro(SelectInst) \
339 macro(ShuffleVectorInst) \
340 macro(StoreInst) \
341 macro(TerminatorInst) \
342 macro(BranchInst) \
343 macro(InvokeInst) \
344 macro(ReturnInst) \
345 macro(SwitchInst) \
346 macro(UnreachableInst) \
347 macro(UnwindInst) \
348 macro(UnaryInstruction) \
349 macro(AllocationInst) \
350 macro(AllocaInst) \
351 macro(MallocInst) \
352 macro(CastInst) \
353 macro(BitCastInst) \
354 macro(FPExtInst) \
355 macro(FPToSIInst) \
356 macro(FPToUIInst) \
357 macro(FPTruncInst) \
358 macro(IntToPtrInst) \
359 macro(PtrToIntInst) \
360 macro(SExtInst) \
361 macro(SIToFPInst) \
362 macro(TruncInst) \
363 macro(UIToFPInst) \
364 macro(ZExtInst) \
365 macro(ExtractValueInst) \
366 macro(FreeInst) \
367 macro(LoadInst) \
368 macro(VAArgInst)
370 /* Operations on all values */
371 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
372 const char *LLVMGetValueName(LLVMValueRef Val);
373 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
374 void LLVMDumpValue(LLVMValueRef Val);
376 /* Conversion functions. Return the input value if it is an instance of the
377 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
378 #define LLVM_DECLARE_VALUE_CAST(name) \
379 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
380 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
382 /* Operations on constants of any type */
383 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
384 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
385 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
386 int LLVMIsConstant(LLVMValueRef Val);
387 int LLVMIsNull(LLVMValueRef Val);
388 int LLVMIsUndef(LLVMValueRef Val);
390 /* Operations on scalar constants */
391 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
392 int SignExtend);
393 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
394 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
396 /* Operations on composite constants */
397 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
398 int DontNullTerminate);
399 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
400 LLVMValueRef *ConstantVals, unsigned Length);
401 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
402 int packed);
403 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
405 /* Constant expressions */
406 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
407 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
408 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
409 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
410 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
411 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
412 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
413 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
414 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
415 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
416 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
417 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
418 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
419 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
420 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
421 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
422 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
423 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
424 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
425 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
426 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
427 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
428 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
429 LLVMValueRef *ConstantIndices, unsigned NumIndices);
430 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
431 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
432 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
433 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
434 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
435 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
436 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
437 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
438 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
439 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
440 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
441 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
442 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
443 LLVMValueRef ConstantIfTrue,
444 LLVMValueRef ConstantIfFalse);
445 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
446 LLVMValueRef IndexConstant);
447 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
448 LLVMValueRef ElementValueConstant,
449 LLVMValueRef IndexConstant);
450 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
451 LLVMValueRef VectorBConstant,
452 LLVMValueRef MaskConstant);
453 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
454 unsigned NumIdx);
455 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
456 LLVMValueRef ElementValueConstant,
457 unsigned *IdxList, unsigned NumIdx);
458 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
459 const char *AsmString, const char *Constraints,
460 int HasSideEffects);
462 /* Operations on global variables, functions, and aliases (globals) */
463 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
464 int LLVMIsDeclaration(LLVMValueRef Global);
465 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
466 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
467 const char *LLVMGetSection(LLVMValueRef Global);
468 void LLVMSetSection(LLVMValueRef Global, const char *Section);
469 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
470 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
471 unsigned LLVMGetAlignment(LLVMValueRef Global);
472 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
474 /* Operations on global variables */
475 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
476 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
477 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
478 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
479 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
480 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
481 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
482 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
483 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
484 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
485 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
486 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
487 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
489 /* Operations on aliases */
490 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
491 const char *Name);
493 /* Operations on functions */
494 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
495 LLVMTypeRef FunctionTy);
496 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
497 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
498 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
499 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
500 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
501 void LLVMDeleteFunction(LLVMValueRef Fn);
502 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
503 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
504 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
505 const char *LLVMGetGC(LLVMValueRef Fn);
506 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
507 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
508 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
510 /* Operations on parameters */
511 unsigned LLVMCountParams(LLVMValueRef Fn);
512 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
513 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
514 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
515 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
516 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
517 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
518 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
519 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
520 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
521 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
523 /* Operations on basic blocks */
524 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
525 int LLVMValueIsBasicBlock(LLVMValueRef Val);
526 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
527 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
528 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
529 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
530 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
531 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
532 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
533 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
534 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
535 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
536 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
537 const char *Name);
538 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
540 /* Operations on instructions */
541 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
542 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
543 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
544 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
545 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
547 /* Operations on call sites */
548 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
549 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
550 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
551 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
552 LLVMAttribute);
553 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
554 unsigned align);
556 /* Operations on call instructions (only) */
557 int LLVMIsTailCall(LLVMValueRef CallInst);
558 void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
560 /* Operations on phi nodes */
561 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
562 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
563 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
564 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
565 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
567 /*===-- Instruction builders ----------------------------------------------===*/
569 /* An instruction builder represents a point within a basic block, and is the
570 * exclusive means of building instructions using the C interface.
573 LLVMBuilderRef LLVMCreateBuilder(void);
574 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
575 LLVMValueRef Instr);
576 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
577 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
578 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
579 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
580 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
581 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
583 /* Terminators */
584 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
585 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
586 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
587 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
588 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
589 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
590 LLVMBasicBlockRef Else, unsigned NumCases);
591 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
592 LLVMValueRef *Args, unsigned NumArgs,
593 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
594 const char *Name);
595 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
596 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
598 /* Add a case to the switch instruction */
599 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
600 LLVMBasicBlockRef Dest);
602 /* Arithmetic */
603 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
604 const char *Name);
605 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
606 const char *Name);
607 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
608 const char *Name);
609 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
610 const char *Name);
611 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
612 const char *Name);
613 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
614 const char *Name);
615 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
616 const char *Name);
617 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
618 const char *Name);
619 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
620 const char *Name);
621 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
622 const char *Name);
623 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
624 const char *Name);
625 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
626 const char *Name);
627 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
628 const char *Name);
629 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
630 const char *Name);
631 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
632 const char *Name);
633 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
634 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
636 /* Memory */
637 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
638 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
639 LLVMValueRef Val, const char *Name);
640 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
641 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
642 LLVMValueRef Val, const char *Name);
643 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
644 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
645 const char *Name);
646 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
647 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
648 LLVMValueRef *Indices, unsigned NumIndices,
649 const char *Name);
651 /* Casts */
652 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
653 LLVMTypeRef DestTy, const char *Name);
654 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
655 LLVMTypeRef DestTy, const char *Name);
656 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
657 LLVMTypeRef DestTy, const char *Name);
658 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
659 LLVMTypeRef DestTy, const char *Name);
660 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
661 LLVMTypeRef DestTy, const char *Name);
662 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
663 LLVMTypeRef DestTy, const char *Name);
664 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
665 LLVMTypeRef DestTy, const char *Name);
666 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
667 LLVMTypeRef DestTy, const char *Name);
668 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
669 LLVMTypeRef DestTy, const char *Name);
670 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
671 LLVMTypeRef DestTy, const char *Name);
672 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
673 LLVMTypeRef DestTy, const char *Name);
674 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
675 LLVMTypeRef DestTy, const char *Name);
677 /* Comparisons */
678 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
679 LLVMValueRef LHS, LLVMValueRef RHS,
680 const char *Name);
681 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
682 LLVMValueRef LHS, LLVMValueRef RHS,
683 const char *Name);
685 /* Miscellaneous instructions */
686 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
687 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
688 LLVMValueRef *Args, unsigned NumArgs,
689 const char *Name);
690 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
691 LLVMValueRef Then, LLVMValueRef Else,
692 const char *Name);
693 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
694 const char *Name);
695 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
696 LLVMValueRef Index, const char *Name);
697 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
698 LLVMValueRef EltVal, LLVMValueRef Index,
699 const char *Name);
700 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
701 LLVMValueRef V2, LLVMValueRef Mask,
702 const char *Name);
703 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
704 unsigned Index, const char *Name);
705 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
706 LLVMValueRef EltVal, unsigned Index,
707 const char *Name);
710 /*===-- Module providers --------------------------------------------------===*/
712 /* Encapsulates the module M in a module provider, taking ownership of the
713 * module.
714 * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
716 LLVMModuleProviderRef
717 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
719 /* Destroys the module provider MP as well as the contained module.
720 * See the destructor llvm::ModuleProvider::~ModuleProvider.
722 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
725 /*===-- Memory buffers ----------------------------------------------------===*/
727 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
728 LLVMMemoryBufferRef *OutMemBuf,
729 char **OutMessage);
730 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
731 char **OutMessage);
732 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
735 /*===-- Pass Managers -----------------------------------------------------===*/
737 /** Constructs a new whole-module pass pipeline. This type of pipeline is
738 suitable for link-time optimization and whole-module transformations.
739 See llvm::PassManager::PassManager. */
740 LLVMPassManagerRef LLVMCreatePassManager(void);
742 /** Constructs a new function-by-function pass pipeline over the module
743 provider. It does not take ownership of the module provider. This type of
744 pipeline is suitable for code generation and JIT compilation tasks.
745 See llvm::FunctionPassManager::FunctionPassManager. */
746 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
748 /** Initializes, executes on the provided module, and finalizes all of the
749 passes scheduled in the pass manager. Returns 1 if any of the passes
750 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
751 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
753 /** Initializes all of the function passes scheduled in the function pass
754 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
755 See llvm::FunctionPassManager::doInitialization. */
756 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
758 /** Executes all of the function passes scheduled in the function pass manager
759 on the provided function. Returns 1 if any of the passes modified the
760 function, false otherwise.
761 See llvm::FunctionPassManager::run(Function&). */
762 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
764 /** Finalizes all of the function passes scheduled in in the function pass
765 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
766 See llvm::FunctionPassManager::doFinalization. */
767 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
769 /** Frees the memory of a pass pipeline. For function pipelines, does not free
770 the module provider.
771 See llvm::PassManagerBase::~PassManagerBase. */
772 void LLVMDisposePassManager(LLVMPassManagerRef PM);
775 #ifdef __cplusplus
778 namespace llvm {
779 class ModuleProvider;
780 class MemoryBuffer;
781 class PassManagerBase;
783 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
784 inline ty *unwrap(ref P) { \
785 return reinterpret_cast<ty*>(P); \
788 inline ref wrap(const ty *P) { \
789 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
792 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
793 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
795 template<typename T> \
796 inline T *unwrap(ref P) { \
797 return cast<T>(unwrap(P)); \
800 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
801 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
803 template<typename T> \
804 inline T *unwrap(ref P) { \
805 T *Q = dynamic_cast<T*>(unwrap(P)); \
806 assert(Q && "Invalid cast!"); \
807 return Q; \
810 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
811 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
812 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
813 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
814 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
815 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
816 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider, LLVMModuleProviderRef)
817 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
818 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
820 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
821 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
822 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
824 /* Specialized opaque type conversions.
826 inline Type **unwrap(LLVMTypeRef* Tys) {
827 return reinterpret_cast<Type**>(Tys);
830 inline LLVMTypeRef *wrap(const Type **Tys) {
831 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
834 /* Specialized opaque value conversions.
836 inline Value **unwrap(LLVMValueRef *Vals) {
837 return reinterpret_cast<Value**>(Vals);
840 template<typename T>
841 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
842 #if DEBUG
843 for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
844 cast<T>(*I);
845 #endif
846 return reinterpret_cast<T**>(Vals);
849 inline LLVMValueRef *wrap(const Value **Vals) {
850 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
854 #endif /* !defined(__cplusplus) */
856 #endif /* !defined(LLVM_C_CORE_H) */