zpu: wip eke out some simple instructions for load/store/add
[llvm/zpu.git] / include / llvm-c / Core.h
blobd0fe536d5cf088a71f5940c889916f4ea4d4f72f
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 #include "llvm/System/DataTypes.h"
38 #ifdef __cplusplus
40 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
41 and 'unwrap' conversion functions. */
42 #include "llvm/Module.h"
43 #include "llvm/PassRegistry.h"
44 #include "llvm/Support/IRBuilder.h"
46 extern "C" {
47 #endif
50 typedef int LLVMBool;
52 /* Opaque types. */
54 /**
55 * The top-level container for all LLVM global data. See the LLVMContext class.
57 typedef struct LLVMOpaqueContext *LLVMContextRef;
59 /**
60 * The top-level container for all other LLVM Intermediate Representation (IR)
61 * objects. See the llvm::Module class.
63 typedef struct LLVMOpaqueModule *LLVMModuleRef;
65 /**
66 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
67 * class.
69 typedef struct LLVMOpaqueType *LLVMTypeRef;
71 /**
72 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
73 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
74 * llvm::AbstractTypeHolder class.
76 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
78 typedef struct LLVMOpaqueValue *LLVMValueRef;
79 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
80 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
82 /* Interface used to provide a module to JIT or interpreter. This is now just a
83 * synonym for llvm::Module, but we have to keep using the different type to
84 * keep binary compatibility.
86 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
88 /* Used to provide a module to JIT or interpreter.
89 * See the llvm::MemoryBuffer class.
91 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
93 /** See the llvm::PassManagerBase class. */
94 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
96 /** See the llvm::PassRegistry class. */
97 typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
99 /** Used to get the users and usees of a Value. See the llvm::Use class. */
100 typedef struct LLVMOpaqueUse *LLVMUseRef;
102 typedef enum {
103 LLVMZExtAttribute = 1<<0,
104 LLVMSExtAttribute = 1<<1,
105 LLVMNoReturnAttribute = 1<<2,
106 LLVMInRegAttribute = 1<<3,
107 LLVMStructRetAttribute = 1<<4,
108 LLVMNoUnwindAttribute = 1<<5,
109 LLVMNoAliasAttribute = 1<<6,
110 LLVMByValAttribute = 1<<7,
111 LLVMNestAttribute = 1<<8,
112 LLVMReadNoneAttribute = 1<<9,
113 LLVMReadOnlyAttribute = 1<<10,
114 LLVMNoInlineAttribute = 1<<11,
115 LLVMAlwaysInlineAttribute = 1<<12,
116 LLVMOptimizeForSizeAttribute = 1<<13,
117 LLVMStackProtectAttribute = 1<<14,
118 LLVMStackProtectReqAttribute = 1<<15,
119 LLVMAlignment = 31<<16,
120 LLVMNoCaptureAttribute = 1<<21,
121 LLVMNoRedZoneAttribute = 1<<22,
122 LLVMNoImplicitFloatAttribute = 1<<23,
123 LLVMNakedAttribute = 1<<24,
124 LLVMInlineHintAttribute = 1<<25,
125 LLVMStackAlignment = 7<<26
126 } LLVMAttribute;
128 typedef enum {
129 /* Terminator Instructions */
130 LLVMRet = 1,
131 LLVMBr = 2,
132 LLVMSwitch = 3,
133 LLVMIndirectBr = 4,
134 LLVMInvoke = 5,
135 LLVMUnwind = 6,
136 LLVMUnreachable = 7,
138 /* Standard Binary Operators */
139 LLVMAdd = 8,
140 LLVMFAdd = 9,
141 LLVMSub = 10,
142 LLVMFSub = 11,
143 LLVMMul = 12,
144 LLVMFMul = 13,
145 LLVMUDiv = 14,
146 LLVMSDiv = 15,
147 LLVMFDiv = 16,
148 LLVMURem = 17,
149 LLVMSRem = 18,
150 LLVMFRem = 19,
152 /* Logical Operators */
153 LLVMShl = 20,
154 LLVMLShr = 21,
155 LLVMAShr = 22,
156 LLVMAnd = 23,
157 LLVMOr = 24,
158 LLVMXor = 25,
160 /* Memory Operators */
161 LLVMAlloca = 26,
162 LLVMLoad = 27,
163 LLVMStore = 28,
164 LLVMGetElementPtr = 29,
166 /* Cast Operators */
167 LLVMTrunc = 30,
168 LLVMZExt = 31,
169 LLVMSExt = 32,
170 LLVMFPToUI = 33,
171 LLVMFPToSI = 34,
172 LLVMUIToFP = 35,
173 LLVMSIToFP = 36,
174 LLVMFPTrunc = 37,
175 LLVMFPExt = 38,
176 LLVMPtrToInt = 39,
177 LLVMIntToPtr = 40,
178 LLVMBitCast = 41,
180 /* Other Operators */
181 LLVMICmp = 42,
182 LLVMFCmp = 43,
183 LLVMPHI = 44,
184 LLVMCall = 45,
185 LLVMSelect = 46,
186 /* UserOp1 */
187 /* UserOp2 */
188 LLVMVAArg = 49,
189 LLVMExtractElement = 50,
190 LLVMInsertElement = 51,
191 LLVMShuffleVector = 52,
192 LLVMExtractValue = 53,
193 LLVMInsertValue = 54
194 } LLVMOpcode;
196 typedef enum {
197 LLVMVoidTypeKind, /**< type with no size */
198 LLVMFloatTypeKind, /**< 32 bit floating point type */
199 LLVMDoubleTypeKind, /**< 64 bit floating point type */
200 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
201 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
202 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
203 LLVMLabelTypeKind, /**< Labels */
204 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
205 LLVMFunctionTypeKind, /**< Functions */
206 LLVMStructTypeKind, /**< Structures */
207 LLVMArrayTypeKind, /**< Arrays */
208 LLVMPointerTypeKind, /**< Pointers */
209 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
210 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
211 LLVMMetadataTypeKind, /**< Metadata */
212 LLVMX86_MMXTypeKind /**< X86 MMX */
213 } LLVMTypeKind;
215 typedef enum {
216 LLVMExternalLinkage, /**< Externally visible function */
217 LLVMAvailableExternallyLinkage,
218 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
219 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
220 equivalent. */
221 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
222 LLVMWeakODRLinkage, /**< Same, but only replaced by something
223 equivalent. */
224 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
225 LLVMInternalLinkage, /**< Rename collisions when linking (static
226 functions) */
227 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
228 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
229 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
230 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
231 LLVMGhostLinkage, /**< Obsolete */
232 LLVMCommonLinkage, /**< Tentative definitions */
233 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
234 LLVMLinkerPrivateWeakLinkage, /**< Like LinkerPrivate, but is weak. */
235 LLVMLinkerPrivateWeakDefAutoLinkage /**< Like LinkerPrivateWeak, but possibly
236 hidden. */
237 } LLVMLinkage;
239 typedef enum {
240 LLVMDefaultVisibility, /**< The GV is visible */
241 LLVMHiddenVisibility, /**< The GV is hidden */
242 LLVMProtectedVisibility /**< The GV is protected */
243 } LLVMVisibility;
245 typedef enum {
246 LLVMCCallConv = 0,
247 LLVMFastCallConv = 8,
248 LLVMColdCallConv = 9,
249 LLVMX86StdcallCallConv = 64,
250 LLVMX86FastcallCallConv = 65
251 } LLVMCallConv;
253 typedef enum {
254 LLVMIntEQ = 32, /**< equal */
255 LLVMIntNE, /**< not equal */
256 LLVMIntUGT, /**< unsigned greater than */
257 LLVMIntUGE, /**< unsigned greater or equal */
258 LLVMIntULT, /**< unsigned less than */
259 LLVMIntULE, /**< unsigned less or equal */
260 LLVMIntSGT, /**< signed greater than */
261 LLVMIntSGE, /**< signed greater or equal */
262 LLVMIntSLT, /**< signed less than */
263 LLVMIntSLE /**< signed less or equal */
264 } LLVMIntPredicate;
266 typedef enum {
267 LLVMRealPredicateFalse, /**< Always false (always folded) */
268 LLVMRealOEQ, /**< True if ordered and equal */
269 LLVMRealOGT, /**< True if ordered and greater than */
270 LLVMRealOGE, /**< True if ordered and greater than or equal */
271 LLVMRealOLT, /**< True if ordered and less than */
272 LLVMRealOLE, /**< True if ordered and less than or equal */
273 LLVMRealONE, /**< True if ordered and operands are unequal */
274 LLVMRealORD, /**< True if ordered (no nans) */
275 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
276 LLVMRealUEQ, /**< True if unordered or equal */
277 LLVMRealUGT, /**< True if unordered or greater than */
278 LLVMRealUGE, /**< True if unordered, greater than, or equal */
279 LLVMRealULT, /**< True if unordered or less than */
280 LLVMRealULE, /**< True if unordered, less than, or equal */
281 LLVMRealUNE, /**< True if unordered or not equal */
282 LLVMRealPredicateTrue /**< Always true (always folded) */
283 } LLVMRealPredicate;
286 /*===-- Error handling ----------------------------------------------------===*/
288 void LLVMDisposeMessage(char *Message);
291 /*===-- Contexts ----------------------------------------------------------===*/
293 /* Create and destroy contexts. */
294 LLVMContextRef LLVMContextCreate(void);
295 LLVMContextRef LLVMGetGlobalContext(void);
296 void LLVMContextDispose(LLVMContextRef C);
298 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
299 unsigned SLen);
300 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
302 /*===-- Modules -----------------------------------------------------------===*/
304 /* Create and destroy modules. */
305 /** See llvm::Module::Module. */
306 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
307 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
308 LLVMContextRef C);
310 /** See llvm::Module::~Module. */
311 void LLVMDisposeModule(LLVMModuleRef M);
313 /** Data layout. See Module::getDataLayout. */
314 const char *LLVMGetDataLayout(LLVMModuleRef M);
315 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
317 /** Target triple. See Module::getTargetTriple. */
318 const char *LLVMGetTarget(LLVMModuleRef M);
319 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
321 /** See Module::addTypeName. */
322 LLVMBool LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
323 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
324 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
326 /** See Module::dump. */
327 void LLVMDumpModule(LLVMModuleRef M);
329 /** See Module::setModuleInlineAsm. */
330 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
332 /*===-- Types -------------------------------------------------------------===*/
334 /* LLVM types conform to the following hierarchy:
336 * types:
337 * integer type
338 * real type
339 * function type
340 * sequence types:
341 * array type
342 * pointer type
343 * vector type
344 * void type
345 * label type
346 * opaque type
349 /** See llvm::LLVMTypeKind::getTypeID. */
350 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
352 /** See llvm::LLVMType::getContext. */
353 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
355 /* Operations on integer types */
356 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
357 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
358 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
359 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
360 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
361 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
363 LLVMTypeRef LLVMInt1Type(void);
364 LLVMTypeRef LLVMInt8Type(void);
365 LLVMTypeRef LLVMInt16Type(void);
366 LLVMTypeRef LLVMInt32Type(void);
367 LLVMTypeRef LLVMInt64Type(void);
368 LLVMTypeRef LLVMIntType(unsigned NumBits);
369 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
371 /* Operations on real types */
372 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
373 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
374 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
375 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
376 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
378 LLVMTypeRef LLVMFloatType(void);
379 LLVMTypeRef LLVMDoubleType(void);
380 LLVMTypeRef LLVMX86FP80Type(void);
381 LLVMTypeRef LLVMFP128Type(void);
382 LLVMTypeRef LLVMPPCFP128Type(void);
384 /* Operations on function types */
385 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
386 LLVMTypeRef *ParamTypes, unsigned ParamCount,
387 LLVMBool IsVarArg);
388 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
389 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
390 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
391 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
393 /* Operations on struct types */
394 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
395 unsigned ElementCount, LLVMBool Packed);
396 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
397 LLVMBool Packed);
398 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
399 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
400 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
402 /* Operations on array, pointer, and vector types (sequence types) */
403 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
404 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
405 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
407 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
408 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
409 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
410 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
412 /* Operations on other types */
413 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
414 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
415 LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
416 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
418 LLVMTypeRef LLVMVoidType(void);
419 LLVMTypeRef LLVMLabelType(void);
420 LLVMTypeRef LLVMOpaqueType(void);
421 LLVMTypeRef LLVMX86MMXType(void);
423 /* Operations on type handles */
424 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
425 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
426 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
427 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
430 /*===-- Values ------------------------------------------------------------===*/
432 /* The bulk of LLVM's object model consists of values, which comprise a very
433 * rich type hierarchy.
436 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
437 macro(Argument) \
438 macro(BasicBlock) \
439 macro(InlineAsm) \
440 macro(User) \
441 macro(Constant) \
442 macro(ConstantAggregateZero) \
443 macro(ConstantArray) \
444 macro(ConstantExpr) \
445 macro(ConstantFP) \
446 macro(ConstantInt) \
447 macro(ConstantPointerNull) \
448 macro(ConstantStruct) \
449 macro(ConstantVector) \
450 macro(GlobalValue) \
451 macro(Function) \
452 macro(GlobalAlias) \
453 macro(GlobalVariable) \
454 macro(UndefValue) \
455 macro(Instruction) \
456 macro(BinaryOperator) \
457 macro(CallInst) \
458 macro(IntrinsicInst) \
459 macro(DbgInfoIntrinsic) \
460 macro(DbgDeclareInst) \
461 macro(EHSelectorInst) \
462 macro(MemIntrinsic) \
463 macro(MemCpyInst) \
464 macro(MemMoveInst) \
465 macro(MemSetInst) \
466 macro(CmpInst) \
467 macro(FCmpInst) \
468 macro(ICmpInst) \
469 macro(ExtractElementInst) \
470 macro(GetElementPtrInst) \
471 macro(InsertElementInst) \
472 macro(InsertValueInst) \
473 macro(PHINode) \
474 macro(SelectInst) \
475 macro(ShuffleVectorInst) \
476 macro(StoreInst) \
477 macro(TerminatorInst) \
478 macro(BranchInst) \
479 macro(InvokeInst) \
480 macro(ReturnInst) \
481 macro(SwitchInst) \
482 macro(UnreachableInst) \
483 macro(UnwindInst) \
484 macro(UnaryInstruction) \
485 macro(AllocaInst) \
486 macro(CastInst) \
487 macro(BitCastInst) \
488 macro(FPExtInst) \
489 macro(FPToSIInst) \
490 macro(FPToUIInst) \
491 macro(FPTruncInst) \
492 macro(IntToPtrInst) \
493 macro(PtrToIntInst) \
494 macro(SExtInst) \
495 macro(SIToFPInst) \
496 macro(TruncInst) \
497 macro(UIToFPInst) \
498 macro(ZExtInst) \
499 macro(ExtractValueInst) \
500 macro(LoadInst) \
501 macro(VAArgInst)
503 /* Operations on all values */
504 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
505 const char *LLVMGetValueName(LLVMValueRef Val);
506 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
507 void LLVMDumpValue(LLVMValueRef Val);
508 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
509 int LLVMHasMetadata(LLVMValueRef Val);
510 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
511 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
513 /* Conversion functions. Return the input value if it is an instance of the
514 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
515 #define LLVM_DECLARE_VALUE_CAST(name) \
516 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
517 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
519 /* Operations on Uses */
520 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
521 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
522 LLVMValueRef LLVMGetUser(LLVMUseRef U);
523 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
525 /* Operations on Users */
526 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
527 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
528 int LLVMGetNumOperands(LLVMValueRef Val);
530 /* Operations on constants of any type */
531 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
532 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
533 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
534 LLVMBool LLVMIsConstant(LLVMValueRef Val);
535 LLVMBool LLVMIsNull(LLVMValueRef Val);
536 LLVMBool LLVMIsUndef(LLVMValueRef Val);
537 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
539 /* Operations on metadata */
540 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
541 unsigned SLen);
542 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
543 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
544 unsigned Count);
545 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
547 /* Operations on scalar constants */
548 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
549 LLVMBool SignExtend);
550 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
551 uint8_t Radix);
552 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
553 unsigned SLen, uint8_t Radix);
554 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
555 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
556 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
557 unsigned SLen);
558 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
559 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
562 /* Operations on composite constants */
563 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
564 unsigned Length, LLVMBool DontNullTerminate);
565 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
566 LLVMValueRef *ConstantVals,
567 unsigned Count, LLVMBool Packed);
569 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
570 LLVMBool DontNullTerminate);
571 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
572 LLVMValueRef *ConstantVals, unsigned Length);
573 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
574 LLVMBool Packed);
575 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
577 /* Constant expressions */
578 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
579 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
580 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
581 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
582 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
583 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
584 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
585 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
586 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
587 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
588 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
589 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
590 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
591 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
592 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
593 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
594 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
595 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
596 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
597 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
598 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
599 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
600 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
601 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
602 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
603 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
604 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
605 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
606 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
607 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
608 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
609 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
610 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
611 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
612 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
613 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
614 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
615 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
616 LLVMValueRef *ConstantIndices, unsigned NumIndices);
617 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
618 LLVMValueRef *ConstantIndices,
619 unsigned NumIndices);
620 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
621 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
622 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
623 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
624 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
625 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
626 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
627 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
628 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
629 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
630 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
631 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
632 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
633 LLVMTypeRef ToType);
634 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
635 LLVMTypeRef ToType);
636 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
637 LLVMTypeRef ToType);
638 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
639 LLVMTypeRef ToType);
640 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
641 LLVMBool isSigned);
642 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
643 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
644 LLVMValueRef ConstantIfTrue,
645 LLVMValueRef ConstantIfFalse);
646 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
647 LLVMValueRef IndexConstant);
648 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
649 LLVMValueRef ElementValueConstant,
650 LLVMValueRef IndexConstant);
651 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
652 LLVMValueRef VectorBConstant,
653 LLVMValueRef MaskConstant);
654 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
655 unsigned NumIdx);
656 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
657 LLVMValueRef ElementValueConstant,
658 unsigned *IdxList, unsigned NumIdx);
659 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
660 const char *AsmString, const char *Constraints,
661 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
662 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
664 /* Operations on global variables, functions, and aliases (globals) */
665 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
666 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
667 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
668 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
669 const char *LLVMGetSection(LLVMValueRef Global);
670 void LLVMSetSection(LLVMValueRef Global, const char *Section);
671 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
672 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
673 unsigned LLVMGetAlignment(LLVMValueRef Global);
674 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
676 /* Operations on global variables */
677 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
678 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
679 const char *Name,
680 unsigned AddressSpace);
681 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
682 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
683 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
684 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
685 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
686 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
687 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
688 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
689 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
690 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
691 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
692 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
694 /* Operations on aliases */
695 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
696 const char *Name);
698 /* Operations on functions */
699 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
700 LLVMTypeRef FunctionTy);
701 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
702 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
703 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
704 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
705 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
706 void LLVMDeleteFunction(LLVMValueRef Fn);
707 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
708 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
709 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
710 const char *LLVMGetGC(LLVMValueRef Fn);
711 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
712 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
713 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
714 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
716 /* Operations on parameters */
717 unsigned LLVMCountParams(LLVMValueRef Fn);
718 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
719 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
720 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
721 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
722 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
723 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
724 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
725 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
726 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
727 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
728 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
730 /* Operations on basic blocks */
731 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
732 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
733 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
734 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
735 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
736 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
737 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
738 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
739 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
740 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
741 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
743 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
744 LLVMValueRef Fn,
745 const char *Name);
746 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
747 LLVMBasicBlockRef BB,
748 const char *Name);
750 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
751 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
752 const char *Name);
753 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
755 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
756 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
758 /* Operations on instructions */
759 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
760 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
761 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
762 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
763 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
765 /* Operations on call sites */
766 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
767 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
768 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
769 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
770 LLVMAttribute);
771 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
772 unsigned align);
774 /* Operations on call instructions (only) */
775 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
776 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
778 /* Operations on phi nodes */
779 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
780 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
781 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
782 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
783 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
785 /*===-- Instruction builders ----------------------------------------------===*/
787 /* An instruction builder represents a point within a basic block, and is the
788 * exclusive means of building instructions using the C interface.
791 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
792 LLVMBuilderRef LLVMCreateBuilder(void);
793 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
794 LLVMValueRef Instr);
795 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
796 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
797 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
798 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
799 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
800 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
801 const char *Name);
802 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
804 /* Metadata */
805 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
806 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
807 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
809 /* Terminators */
810 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
811 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
812 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
813 unsigned N);
814 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
815 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
816 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
817 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
818 LLVMBasicBlockRef Else, unsigned NumCases);
819 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
820 unsigned NumDests);
821 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
822 LLVMValueRef *Args, unsigned NumArgs,
823 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
824 const char *Name);
825 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
826 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
828 /* Add a case to the switch instruction */
829 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
830 LLVMBasicBlockRef Dest);
832 /* Add a destination to the indirectbr instruction */
833 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
835 /* Arithmetic */
836 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
837 const char *Name);
838 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
839 const char *Name);
840 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
841 const char *Name);
842 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
843 const char *Name);
844 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
845 const char *Name);
846 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
847 const char *Name);
848 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
849 const char *Name);
850 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
851 const char *Name);
852 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
853 const char *Name);
854 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
855 const char *Name);
856 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
857 const char *Name);
858 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
859 const char *Name);
860 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
861 const char *Name);
862 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
863 const char *Name);
864 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
865 const char *Name);
866 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
867 const char *Name);
868 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
869 const char *Name);
870 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
871 const char *Name);
872 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
873 const char *Name);
874 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
875 const char *Name);
876 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
877 const char *Name);
878 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
879 const char *Name);
880 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
881 const char *Name);
882 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
883 const char *Name);
884 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
885 const char *Name);
886 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
887 LLVMValueRef LHS, LLVMValueRef RHS,
888 const char *Name);
889 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
890 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
891 const char *Name);
892 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
893 const char *Name);
894 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
895 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
897 /* Memory */
898 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
899 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
900 LLVMValueRef Val, const char *Name);
901 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
902 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
903 LLVMValueRef Val, const char *Name);
904 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
905 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
906 const char *Name);
907 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
908 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
909 LLVMValueRef *Indices, unsigned NumIndices,
910 const char *Name);
911 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
912 LLVMValueRef *Indices, unsigned NumIndices,
913 const char *Name);
914 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
915 unsigned Idx, const char *Name);
916 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
917 const char *Name);
918 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
919 const char *Name);
921 /* Casts */
922 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
923 LLVMTypeRef DestTy, const char *Name);
924 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
925 LLVMTypeRef DestTy, const char *Name);
926 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
927 LLVMTypeRef DestTy, const char *Name);
928 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
929 LLVMTypeRef DestTy, const char *Name);
930 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
931 LLVMTypeRef DestTy, const char *Name);
932 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
933 LLVMTypeRef DestTy, const char *Name);
934 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
935 LLVMTypeRef DestTy, const char *Name);
936 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
937 LLVMTypeRef DestTy, const char *Name);
938 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
939 LLVMTypeRef DestTy, const char *Name);
940 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
941 LLVMTypeRef DestTy, const char *Name);
942 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
943 LLVMTypeRef DestTy, const char *Name);
944 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
945 LLVMTypeRef DestTy, const char *Name);
946 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
947 LLVMTypeRef DestTy, const char *Name);
948 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
949 LLVMTypeRef DestTy, const char *Name);
950 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
951 LLVMTypeRef DestTy, const char *Name);
952 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
953 LLVMTypeRef DestTy, const char *Name);
954 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
955 LLVMTypeRef DestTy, const char *Name);
956 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
957 LLVMTypeRef DestTy, const char *Name);
958 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
959 LLVMTypeRef DestTy, const char *Name);
961 /* Comparisons */
962 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
963 LLVMValueRef LHS, LLVMValueRef RHS,
964 const char *Name);
965 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
966 LLVMValueRef LHS, LLVMValueRef RHS,
967 const char *Name);
969 /* Miscellaneous instructions */
970 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
971 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
972 LLVMValueRef *Args, unsigned NumArgs,
973 const char *Name);
974 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
975 LLVMValueRef Then, LLVMValueRef Else,
976 const char *Name);
977 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
978 const char *Name);
979 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
980 LLVMValueRef Index, const char *Name);
981 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
982 LLVMValueRef EltVal, LLVMValueRef Index,
983 const char *Name);
984 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
985 LLVMValueRef V2, LLVMValueRef Mask,
986 const char *Name);
987 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
988 unsigned Index, const char *Name);
989 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
990 LLVMValueRef EltVal, unsigned Index,
991 const char *Name);
993 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
994 const char *Name);
995 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
996 const char *Name);
997 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
998 LLVMValueRef RHS, const char *Name);
1001 /*===-- Module providers --------------------------------------------------===*/
1003 /* Changes the type of M so it can be passed to FunctionPassManagers and the
1004 * JIT. They take ModuleProviders for historical reasons.
1006 LLVMModuleProviderRef
1007 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
1009 /* Destroys the module M.
1011 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
1014 /*===-- Memory buffers ----------------------------------------------------===*/
1016 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
1017 LLVMMemoryBufferRef *OutMemBuf,
1018 char **OutMessage);
1019 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
1020 char **OutMessage);
1021 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
1023 /*===-- Pass Registry -----------------------------------------------------===*/
1025 /** Return the global pass registry, for use with initialization functions.
1026 See llvm::PassRegistry::getPassRegistry. */
1027 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
1029 /*===-- Pass Managers -----------------------------------------------------===*/
1031 /** Constructs a new whole-module pass pipeline. This type of pipeline is
1032 suitable for link-time optimization and whole-module transformations.
1033 See llvm::PassManager::PassManager. */
1034 LLVMPassManagerRef LLVMCreatePassManager(void);
1036 /** Constructs a new function-by-function pass pipeline over the module
1037 provider. It does not take ownership of the module provider. This type of
1038 pipeline is suitable for code generation and JIT compilation tasks.
1039 See llvm::FunctionPassManager::FunctionPassManager. */
1040 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
1042 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
1043 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
1045 /** Initializes, executes on the provided module, and finalizes all of the
1046 passes scheduled in the pass manager. Returns 1 if any of the passes
1047 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
1048 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
1050 /** Initializes all of the function passes scheduled in the function pass
1051 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1052 See llvm::FunctionPassManager::doInitialization. */
1053 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
1055 /** Executes all of the function passes scheduled in the function pass manager
1056 on the provided function. Returns 1 if any of the passes modified the
1057 function, false otherwise.
1058 See llvm::FunctionPassManager::run(Function&). */
1059 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
1061 /** Finalizes all of the function passes scheduled in in the function pass
1062 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1063 See llvm::FunctionPassManager::doFinalization. */
1064 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
1066 /** Frees the memory of a pass pipeline. For function pipelines, does not free
1067 the module provider.
1068 See llvm::PassManagerBase::~PassManagerBase. */
1069 void LLVMDisposePassManager(LLVMPassManagerRef PM);
1072 #ifdef __cplusplus
1075 namespace llvm {
1076 class MemoryBuffer;
1077 class PassManagerBase;
1079 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1080 inline ty *unwrap(ref P) { \
1081 return reinterpret_cast<ty*>(P); \
1084 inline ref wrap(const ty *P) { \
1085 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
1088 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
1089 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1091 template<typename T> \
1092 inline T *unwrap(ref P) { \
1093 return cast<T>(unwrap(P)); \
1096 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
1097 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1099 template<typename T> \
1100 inline T *unwrap(ref P) { \
1101 T *Q = (T*)unwrap(P); \
1102 assert(Q && "Invalid cast!"); \
1103 return Q; \
1106 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
1107 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
1108 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
1109 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
1110 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
1111 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
1112 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
1113 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
1114 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
1115 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
1116 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
1117 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
1118 * Module.
1120 inline Module *unwrap(LLVMModuleProviderRef MP) {
1121 return reinterpret_cast<Module*>(MP);
1124 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
1125 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
1126 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
1128 /* Specialized opaque context conversions.
1130 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
1131 return reinterpret_cast<LLVMContext**>(Tys);
1134 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
1135 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
1138 /* Specialized opaque type conversions.
1140 inline Type **unwrap(LLVMTypeRef* Tys) {
1141 return reinterpret_cast<Type**>(Tys);
1144 inline LLVMTypeRef *wrap(const Type **Tys) {
1145 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
1148 /* Specialized opaque value conversions.
1150 inline Value **unwrap(LLVMValueRef *Vals) {
1151 return reinterpret_cast<Value**>(Vals);
1154 template<typename T>
1155 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
1156 #if DEBUG
1157 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
1158 cast<T>(*I);
1159 #endif
1160 return reinterpret_cast<T**>(Vals);
1163 inline LLVMValueRef *wrap(const Value **Vals) {
1164 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
1168 #endif /* !defined(__cplusplus) */
1170 #endif /* !defined(LLVM_C_CORE_H) */