Add CreateLifetimeStart and CreateLifetimeEnd to the IRBuilder, with plans to
[llvm/stm8.git] / include / llvm-c / Core.h
blob70fc6999530b7d905b7c39231e719194a198b320
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/Support/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;
285 void LLVMInitializeCore(LLVMPassRegistryRef R);
288 /*===-- Error handling ----------------------------------------------------===*/
290 void LLVMDisposeMessage(char *Message);
293 /*===-- Contexts ----------------------------------------------------------===*/
295 /* Create and destroy contexts. */
296 LLVMContextRef LLVMContextCreate(void);
297 LLVMContextRef LLVMGetGlobalContext(void);
298 void LLVMContextDispose(LLVMContextRef C);
300 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
301 unsigned SLen);
302 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
304 /*===-- Modules -----------------------------------------------------------===*/
306 /* Create and destroy modules. */
307 /** See llvm::Module::Module. */
308 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
309 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
310 LLVMContextRef C);
312 /** See llvm::Module::~Module. */
313 void LLVMDisposeModule(LLVMModuleRef M);
315 /** Data layout. See Module::getDataLayout. */
316 const char *LLVMGetDataLayout(LLVMModuleRef M);
317 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
319 /** Target triple. See Module::getTargetTriple. */
320 const char *LLVMGetTarget(LLVMModuleRef M);
321 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
323 /** See Module::addTypeName. */
324 LLVMBool LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
325 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
326 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
327 const char *LLVMGetTypeName(LLVMModuleRef M, LLVMTypeRef Ty);
329 /** See Module::dump. */
330 void LLVMDumpModule(LLVMModuleRef M);
332 /** See Module::setModuleInlineAsm. */
333 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
335 /** See Module::getContext. */
336 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
338 /*===-- Types -------------------------------------------------------------===*/
340 /* LLVM types conform to the following hierarchy:
342 * types:
343 * integer type
344 * real type
345 * function type
346 * sequence types:
347 * array type
348 * pointer type
349 * vector type
350 * void type
351 * label type
352 * opaque type
355 /** See llvm::LLVMTypeKind::getTypeID. */
356 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
358 /** See llvm::LLVMType::getContext. */
359 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
361 /* Operations on integer types */
362 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
363 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
364 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
365 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
366 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
367 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
369 LLVMTypeRef LLVMInt1Type(void);
370 LLVMTypeRef LLVMInt8Type(void);
371 LLVMTypeRef LLVMInt16Type(void);
372 LLVMTypeRef LLVMInt32Type(void);
373 LLVMTypeRef LLVMInt64Type(void);
374 LLVMTypeRef LLVMIntType(unsigned NumBits);
375 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
377 /* Operations on real types */
378 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
379 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
380 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
381 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
382 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
384 LLVMTypeRef LLVMFloatType(void);
385 LLVMTypeRef LLVMDoubleType(void);
386 LLVMTypeRef LLVMX86FP80Type(void);
387 LLVMTypeRef LLVMFP128Type(void);
388 LLVMTypeRef LLVMPPCFP128Type(void);
390 /* Operations on function types */
391 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
392 LLVMTypeRef *ParamTypes, unsigned ParamCount,
393 LLVMBool IsVarArg);
394 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
395 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
396 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
397 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
399 /* Operations on struct types */
400 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
401 unsigned ElementCount, LLVMBool Packed);
402 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
403 LLVMBool Packed);
404 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
405 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
406 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
408 /* Operations on array, pointer, and vector types (sequence types) */
409 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
410 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
411 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
413 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
414 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
415 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
416 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
418 /* Operations on other types */
419 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
420 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
421 LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
422 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
424 LLVMTypeRef LLVMVoidType(void);
425 LLVMTypeRef LLVMLabelType(void);
426 LLVMTypeRef LLVMOpaqueType(void);
427 LLVMTypeRef LLVMX86MMXType(void);
429 /* Operations on type handles */
430 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
431 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
432 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
433 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
436 /*===-- Values ------------------------------------------------------------===*/
438 /* The bulk of LLVM's object model consists of values, which comprise a very
439 * rich type hierarchy.
442 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
443 macro(Argument) \
444 macro(BasicBlock) \
445 macro(InlineAsm) \
446 macro(User) \
447 macro(Constant) \
448 macro(ConstantAggregateZero) \
449 macro(ConstantArray) \
450 macro(ConstantExpr) \
451 macro(ConstantFP) \
452 macro(ConstantInt) \
453 macro(ConstantPointerNull) \
454 macro(ConstantStruct) \
455 macro(ConstantVector) \
456 macro(GlobalValue) \
457 macro(Function) \
458 macro(GlobalAlias) \
459 macro(GlobalVariable) \
460 macro(UndefValue) \
461 macro(Instruction) \
462 macro(BinaryOperator) \
463 macro(CallInst) \
464 macro(IntrinsicInst) \
465 macro(DbgInfoIntrinsic) \
466 macro(DbgDeclareInst) \
467 macro(EHSelectorInst) \
468 macro(MemIntrinsic) \
469 macro(MemCpyInst) \
470 macro(MemMoveInst) \
471 macro(MemSetInst) \
472 macro(CmpInst) \
473 macro(FCmpInst) \
474 macro(ICmpInst) \
475 macro(ExtractElementInst) \
476 macro(GetElementPtrInst) \
477 macro(InsertElementInst) \
478 macro(InsertValueInst) \
479 macro(PHINode) \
480 macro(SelectInst) \
481 macro(ShuffleVectorInst) \
482 macro(StoreInst) \
483 macro(TerminatorInst) \
484 macro(BranchInst) \
485 macro(InvokeInst) \
486 macro(ReturnInst) \
487 macro(SwitchInst) \
488 macro(UnreachableInst) \
489 macro(UnwindInst) \
490 macro(UnaryInstruction) \
491 macro(AllocaInst) \
492 macro(CastInst) \
493 macro(BitCastInst) \
494 macro(FPExtInst) \
495 macro(FPToSIInst) \
496 macro(FPToUIInst) \
497 macro(FPTruncInst) \
498 macro(IntToPtrInst) \
499 macro(PtrToIntInst) \
500 macro(SExtInst) \
501 macro(SIToFPInst) \
502 macro(TruncInst) \
503 macro(UIToFPInst) \
504 macro(ZExtInst) \
505 macro(ExtractValueInst) \
506 macro(LoadInst) \
507 macro(VAArgInst)
509 /* Operations on all values */
510 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
511 const char *LLVMGetValueName(LLVMValueRef Val);
512 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
513 void LLVMDumpValue(LLVMValueRef Val);
514 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
515 int LLVMHasMetadata(LLVMValueRef Val);
516 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
517 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
519 /* Conversion functions. Return the input value if it is an instance of the
520 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
521 #define LLVM_DECLARE_VALUE_CAST(name) \
522 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
523 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
525 /* Operations on Uses */
526 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
527 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
528 LLVMValueRef LLVMGetUser(LLVMUseRef U);
529 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
531 /* Operations on Users */
532 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
533 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
534 int LLVMGetNumOperands(LLVMValueRef Val);
536 /* Operations on constants of any type */
537 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
538 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
539 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
540 LLVMBool LLVMIsConstant(LLVMValueRef Val);
541 LLVMBool LLVMIsNull(LLVMValueRef Val);
542 LLVMBool LLVMIsUndef(LLVMValueRef Val);
543 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
545 /* Operations on metadata */
546 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
547 unsigned SLen);
548 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
549 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
550 unsigned Count);
551 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
553 /* Operations on scalar constants */
554 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
555 LLVMBool SignExtend);
556 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
557 unsigned NumWords,
558 const uint64_t Words[]);
559 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
560 uint8_t Radix);
561 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
562 unsigned SLen, uint8_t Radix);
563 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
564 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
565 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
566 unsigned SLen);
567 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
568 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
571 /* Operations on composite constants */
572 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
573 unsigned Length, LLVMBool DontNullTerminate);
574 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
575 LLVMValueRef *ConstantVals,
576 unsigned Count, LLVMBool Packed);
578 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
579 LLVMBool DontNullTerminate);
580 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
581 LLVMValueRef *ConstantVals, unsigned Length);
582 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
583 LLVMBool Packed);
584 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
586 /* Constant expressions */
587 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
588 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
589 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
590 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
591 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
592 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
593 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
594 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
595 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
596 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
597 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
598 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
599 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
600 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
601 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
602 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
603 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
604 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
605 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
606 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
607 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
608 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
609 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
610 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
611 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
612 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
613 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
614 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
615 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
616 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
617 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
618 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
619 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
620 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
621 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
622 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
623 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
624 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
625 LLVMValueRef *ConstantIndices, unsigned NumIndices);
626 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
627 LLVMValueRef *ConstantIndices,
628 unsigned NumIndices);
629 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
630 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
631 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
632 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
633 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
634 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
635 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
636 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
637 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
638 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
639 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
640 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
641 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
642 LLVMTypeRef ToType);
643 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
644 LLVMTypeRef ToType);
645 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
646 LLVMTypeRef ToType);
647 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
648 LLVMTypeRef ToType);
649 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
650 LLVMBool isSigned);
651 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
652 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
653 LLVMValueRef ConstantIfTrue,
654 LLVMValueRef ConstantIfFalse);
655 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
656 LLVMValueRef IndexConstant);
657 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
658 LLVMValueRef ElementValueConstant,
659 LLVMValueRef IndexConstant);
660 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
661 LLVMValueRef VectorBConstant,
662 LLVMValueRef MaskConstant);
663 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
664 unsigned NumIdx);
665 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
666 LLVMValueRef ElementValueConstant,
667 unsigned *IdxList, unsigned NumIdx);
668 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
669 const char *AsmString, const char *Constraints,
670 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
671 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
673 /* Operations on global variables, functions, and aliases (globals) */
674 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
675 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
676 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
677 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
678 const char *LLVMGetSection(LLVMValueRef Global);
679 void LLVMSetSection(LLVMValueRef Global, const char *Section);
680 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
681 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
682 unsigned LLVMGetAlignment(LLVMValueRef Global);
683 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
685 /* Operations on global variables */
686 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
687 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
688 const char *Name,
689 unsigned AddressSpace);
690 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
691 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
692 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
693 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
694 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
695 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
696 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
697 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
698 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
699 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
700 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
701 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
703 /* Operations on aliases */
704 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
705 const char *Name);
707 /* Operations on functions */
708 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
709 LLVMTypeRef FunctionTy);
710 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
711 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
712 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
713 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
714 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
715 void LLVMDeleteFunction(LLVMValueRef Fn);
716 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
717 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
718 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
719 const char *LLVMGetGC(LLVMValueRef Fn);
720 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
721 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
722 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
723 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
725 /* Operations on parameters */
726 unsigned LLVMCountParams(LLVMValueRef Fn);
727 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
728 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
729 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
730 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
731 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
732 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
733 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
734 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
735 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
736 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
737 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
739 /* Operations on basic blocks */
740 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
741 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
742 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
743 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
744 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
745 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
746 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
747 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
748 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
749 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
750 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
752 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
753 LLVMValueRef Fn,
754 const char *Name);
755 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
756 LLVMBasicBlockRef BB,
757 const char *Name);
759 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
760 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
761 const char *Name);
762 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
764 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
765 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
767 /* Operations on instructions */
768 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
769 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
770 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
771 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
772 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
774 /* Operations on call sites */
775 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
776 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
777 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
778 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
779 LLVMAttribute);
780 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
781 unsigned align);
783 /* Operations on call instructions (only) */
784 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
785 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
787 /* Operations on phi nodes */
788 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
789 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
790 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
791 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
792 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
794 /*===-- Instruction builders ----------------------------------------------===*/
796 /* An instruction builder represents a point within a basic block, and is the
797 * exclusive means of building instructions using the C interface.
800 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
801 LLVMBuilderRef LLVMCreateBuilder(void);
802 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
803 LLVMValueRef Instr);
804 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
805 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
806 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
807 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
808 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
809 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
810 const char *Name);
811 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
813 /* Metadata */
814 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
815 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
816 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
818 /* Terminators */
819 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
820 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
821 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
822 unsigned N);
823 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
824 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
825 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
826 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
827 LLVMBasicBlockRef Else, unsigned NumCases);
828 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
829 unsigned NumDests);
830 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
831 LLVMValueRef *Args, unsigned NumArgs,
832 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
833 const char *Name);
834 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
835 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
837 /* Add a case to the switch instruction */
838 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
839 LLVMBasicBlockRef Dest);
841 /* Add a destination to the indirectbr instruction */
842 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
844 /* Arithmetic */
845 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
846 const char *Name);
847 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
848 const char *Name);
849 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
850 const char *Name);
851 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
852 const char *Name);
853 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
854 const char *Name);
855 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
856 const char *Name);
857 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
858 const char *Name);
859 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
860 const char *Name);
861 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
862 const char *Name);
863 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
864 const char *Name);
865 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
866 const char *Name);
867 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
868 const char *Name);
869 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
870 const char *Name);
871 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
872 const char *Name);
873 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
874 const char *Name);
875 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
876 const char *Name);
877 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
878 const char *Name);
879 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
880 const char *Name);
881 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
882 const char *Name);
883 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
884 const char *Name);
885 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
886 const char *Name);
887 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
888 const char *Name);
889 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
890 const char *Name);
891 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
892 const char *Name);
893 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
894 const char *Name);
895 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
896 LLVMValueRef LHS, LLVMValueRef RHS,
897 const char *Name);
898 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
899 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
900 const char *Name);
901 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
902 const char *Name);
903 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
904 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
906 /* Memory */
907 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
908 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
909 LLVMValueRef Val, const char *Name);
910 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
911 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
912 LLVMValueRef Val, const char *Name);
913 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
914 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
915 const char *Name);
916 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
917 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
918 LLVMValueRef *Indices, unsigned NumIndices,
919 const char *Name);
920 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
921 LLVMValueRef *Indices, unsigned NumIndices,
922 const char *Name);
923 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
924 unsigned Idx, const char *Name);
925 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
926 const char *Name);
927 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
928 const char *Name);
930 /* Casts */
931 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
932 LLVMTypeRef DestTy, const char *Name);
933 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
934 LLVMTypeRef DestTy, const char *Name);
935 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
936 LLVMTypeRef DestTy, const char *Name);
937 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
938 LLVMTypeRef DestTy, const char *Name);
939 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
940 LLVMTypeRef DestTy, const char *Name);
941 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
942 LLVMTypeRef DestTy, const char *Name);
943 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
944 LLVMTypeRef DestTy, const char *Name);
945 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
946 LLVMTypeRef DestTy, const char *Name);
947 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
948 LLVMTypeRef DestTy, const char *Name);
949 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
950 LLVMTypeRef DestTy, const char *Name);
951 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
952 LLVMTypeRef DestTy, const char *Name);
953 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
954 LLVMTypeRef DestTy, const char *Name);
955 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
956 LLVMTypeRef DestTy, const char *Name);
957 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
958 LLVMTypeRef DestTy, const char *Name);
959 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
960 LLVMTypeRef DestTy, const char *Name);
961 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
962 LLVMTypeRef DestTy, const char *Name);
963 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
964 LLVMTypeRef DestTy, const char *Name);
965 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
966 LLVMTypeRef DestTy, const char *Name);
967 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
968 LLVMTypeRef DestTy, const char *Name);
970 /* Comparisons */
971 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
972 LLVMValueRef LHS, LLVMValueRef RHS,
973 const char *Name);
974 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
975 LLVMValueRef LHS, LLVMValueRef RHS,
976 const char *Name);
978 /* Miscellaneous instructions */
979 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
980 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
981 LLVMValueRef *Args, unsigned NumArgs,
982 const char *Name);
983 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
984 LLVMValueRef Then, LLVMValueRef Else,
985 const char *Name);
986 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
987 const char *Name);
988 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
989 LLVMValueRef Index, const char *Name);
990 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
991 LLVMValueRef EltVal, LLVMValueRef Index,
992 const char *Name);
993 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
994 LLVMValueRef V2, LLVMValueRef Mask,
995 const char *Name);
996 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
997 unsigned Index, const char *Name);
998 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
999 LLVMValueRef EltVal, unsigned Index,
1000 const char *Name);
1002 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
1003 const char *Name);
1004 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
1005 const char *Name);
1006 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
1007 LLVMValueRef RHS, const char *Name);
1010 /*===-- Module providers --------------------------------------------------===*/
1012 /* Changes the type of M so it can be passed to FunctionPassManagers and the
1013 * JIT. They take ModuleProviders for historical reasons.
1015 LLVMModuleProviderRef
1016 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
1018 /* Destroys the module M.
1020 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
1023 /*===-- Memory buffers ----------------------------------------------------===*/
1025 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
1026 LLVMMemoryBufferRef *OutMemBuf,
1027 char **OutMessage);
1028 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
1029 char **OutMessage);
1030 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
1032 /*===-- Pass Registry -----------------------------------------------------===*/
1034 /** Return the global pass registry, for use with initialization functions.
1035 See llvm::PassRegistry::getPassRegistry. */
1036 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
1038 /*===-- Pass Managers -----------------------------------------------------===*/
1040 /** Constructs a new whole-module pass pipeline. This type of pipeline is
1041 suitable for link-time optimization and whole-module transformations.
1042 See llvm::PassManager::PassManager. */
1043 LLVMPassManagerRef LLVMCreatePassManager(void);
1045 /** Constructs a new function-by-function pass pipeline over the module
1046 provider. It does not take ownership of the module provider. This type of
1047 pipeline is suitable for code generation and JIT compilation tasks.
1048 See llvm::FunctionPassManager::FunctionPassManager. */
1049 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
1051 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
1052 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
1054 /** Initializes, executes on the provided module, and finalizes all of the
1055 passes scheduled in the pass manager. Returns 1 if any of the passes
1056 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
1057 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
1059 /** Initializes all of the function passes scheduled in the function pass
1060 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1061 See llvm::FunctionPassManager::doInitialization. */
1062 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
1064 /** Executes all of the function passes scheduled in the function pass manager
1065 on the provided function. Returns 1 if any of the passes modified the
1066 function, false otherwise.
1067 See llvm::FunctionPassManager::run(Function&). */
1068 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
1070 /** Finalizes all of the function passes scheduled in in the function pass
1071 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1072 See llvm::FunctionPassManager::doFinalization. */
1073 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
1075 /** Frees the memory of a pass pipeline. For function pipelines, does not free
1076 the module provider.
1077 See llvm::PassManagerBase::~PassManagerBase. */
1078 void LLVMDisposePassManager(LLVMPassManagerRef PM);
1081 #ifdef __cplusplus
1084 namespace llvm {
1085 class MemoryBuffer;
1086 class PassManagerBase;
1088 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1089 inline ty *unwrap(ref P) { \
1090 return reinterpret_cast<ty*>(P); \
1093 inline ref wrap(const ty *P) { \
1094 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
1097 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
1098 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1100 template<typename T> \
1101 inline T *unwrap(ref P) { \
1102 return cast<T>(unwrap(P)); \
1105 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
1106 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
1108 template<typename T> \
1109 inline T *unwrap(ref P) { \
1110 T *Q = (T*)unwrap(P); \
1111 assert(Q && "Invalid cast!"); \
1112 return Q; \
1115 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
1116 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
1117 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
1118 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
1119 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
1120 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
1121 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
1122 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
1123 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
1124 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
1125 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
1126 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
1127 * Module.
1129 inline Module *unwrap(LLVMModuleProviderRef MP) {
1130 return reinterpret_cast<Module*>(MP);
1133 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
1134 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
1135 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
1137 /* Specialized opaque context conversions.
1139 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
1140 return reinterpret_cast<LLVMContext**>(Tys);
1143 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
1144 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
1147 /* Specialized opaque type conversions.
1149 inline Type **unwrap(LLVMTypeRef* Tys) {
1150 return reinterpret_cast<Type**>(Tys);
1153 inline LLVMTypeRef *wrap(const Type **Tys) {
1154 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
1157 /* Specialized opaque value conversions.
1159 inline Value **unwrap(LLVMValueRef *Vals) {
1160 return reinterpret_cast<Value**>(Vals);
1163 template<typename T>
1164 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
1165 #if DEBUG
1166 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
1167 cast<T>(*I);
1168 #endif
1169 return reinterpret_cast<T**>(Vals);
1172 inline LLVMValueRef *wrap(const Value **Vals) {
1173 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
1177 #endif /* !defined(__cplusplus) */
1179 #endif /* !defined(LLVM_C_CORE_H) */