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