Add four new functions and one new enum to the C API:
[oota-llvm.git] / include / llvm-c / Core.h
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 \*===----------------------------------------------------------------------===*/
14
15 #ifndef LLVM_C_CORE_H
16 #define LLVM_C_CORE_H
17
18 #include "llvm/Support/DataTypes.h"
19
20 #ifdef __cplusplus
21
22 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap' 
23    and 'unwrap' conversion functions. */
24 #include "llvm/IR/IRBuilder.h"
25 #include "llvm/IR/Module.h"
26 #include "llvm/PassRegistry.h"
27
28 extern "C" {
29 #endif
30
31 /**
32  * @defgroup LLVMC LLVM-C: C interface to LLVM
33  *
34  * This module exposes parts of the LLVM library as a C API.
35  *
36  * @{
37  */
38
39 /**
40  * @defgroup LLVMCTransforms Transforms
41  */
42
43 /**
44  * @defgroup LLVMCCore Core
45  *
46  * This modules provide an interface to libLLVMCore, which implements
47  * the LLVM intermediate representation as well as other related types
48  * and utilities.
49  *
50  * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
51  * parameters must be passed as base types. Despite the declared types, most
52  * of the functions provided operate only on branches of the type hierarchy.
53  * The declared parameter names are descriptive and specify which type is
54  * required. Additionally, each type hierarchy is documented along with the
55  * functions that operate upon it. For more detail, refer to LLVM's C++ code.
56  * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
57  * form unwrap<RequiredType>(Param).
58  *
59  * Many exotic languages can interoperate with C code but have a harder time
60  * with C++ due to name mangling. So in addition to C, this interface enables
61  * tools written in such languages.
62  *
63  * When included into a C++ source file, also declares 'wrap' and 'unwrap'
64  * helpers to perform opaque reference<-->pointer conversions. These helpers
65  * are shorter and more tightly typed than writing the casts by hand when
66  * authoring bindings. In assert builds, they will do runtime type checking.
67  *
68  * @{
69  */
70
71 /**
72  * @defgroup LLVMCCoreTypes Types and Enumerations
73  *
74  * @{
75  */
76
77 typedef int LLVMBool;
78
79 /* Opaque types. */
80
81 /**
82  * The top-level container for all LLVM global data. See the LLVMContext class.
83  */
84 typedef struct LLVMOpaqueContext *LLVMContextRef;
85
86 /**
87  * The top-level container for all other LLVM Intermediate Representation (IR)
88  * objects.
89  *
90  * @see llvm::Module
91  */
92 typedef struct LLVMOpaqueModule *LLVMModuleRef;
93
94 /**
95  * Each value in the LLVM IR has a type, an LLVMTypeRef.
96  *
97  * @see llvm::Type
98  */
99 typedef struct LLVMOpaqueType *LLVMTypeRef;
100
101 /**
102  * Represents an individual value in LLVM IR.
103  *
104  * This models llvm::Value.
105  */
106 typedef struct LLVMOpaqueValue *LLVMValueRef;
107
108 /**
109  * Represents a basic block of instructions in LLVM IR.
110  *
111  * This models llvm::BasicBlock.
112  */
113 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
114
115 /**
116  * Represents an LLVM basic block builder.
117  *
118  * This models llvm::IRBuilder.
119  */
120 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
121
122 /**
123  * Interface used to provide a module to JIT or interpreter.
124  * This is now just a synonym for llvm::Module, but we have to keep using the
125  * different type to keep binary compatibility.
126  */
127 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
128
129 /**
130  * Used to provide a module to JIT or interpreter.
131  *
132  * @see llvm::MemoryBuffer
133  */
134 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
135
136 /** @see llvm::PassManagerBase */
137 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
138
139 /** @see llvm::PassRegistry */
140 typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
141
142 /**
143  * Used to get the users and usees of a Value.
144  *
145  * @see llvm::Use */
146 typedef struct LLVMOpaqueUse *LLVMUseRef;
147
148 typedef enum {
149     LLVMZExtAttribute       = 1<<0,
150     LLVMSExtAttribute       = 1<<1,
151     LLVMNoReturnAttribute   = 1<<2,
152     LLVMInRegAttribute      = 1<<3,
153     LLVMStructRetAttribute  = 1<<4,
154     LLVMNoUnwindAttribute   = 1<<5,
155     LLVMNoAliasAttribute    = 1<<6,
156     LLVMByValAttribute      = 1<<7,
157     LLVMNestAttribute       = 1<<8,
158     LLVMReadNoneAttribute   = 1<<9,
159     LLVMReadOnlyAttribute   = 1<<10,
160     LLVMNoInlineAttribute   = 1<<11,
161     LLVMAlwaysInlineAttribute    = 1<<12,
162     LLVMOptimizeForSizeAttribute = 1<<13,
163     LLVMStackProtectAttribute    = 1<<14,
164     LLVMStackProtectReqAttribute = 1<<15,
165     LLVMAlignment = 31<<16,
166     LLVMNoCaptureAttribute  = 1<<21,
167     LLVMNoRedZoneAttribute  = 1<<22,
168     LLVMNoImplicitFloatAttribute = 1<<23,
169     LLVMNakedAttribute      = 1<<24,
170     LLVMInlineHintAttribute = 1<<25,
171     LLVMStackAlignment = 7<<26,
172     LLVMReturnsTwice = 1 << 29,
173     LLVMUWTable = 1 << 30,
174     LLVMNonLazyBind = 1 << 31
175
176     /* FIXME: These attributes are currently not included in the C API as
177        a temporary measure until the API/ABI impact to the C API is understood
178        and the path forward agreed upon.
179     LLVMAddressSafety = 1ULL << 32,
180     LLVMStackProtectStrongAttribute = 1ULL<<33
181     */
182 } LLVMAttribute;
183
184 typedef enum {
185   /* Terminator Instructions */
186   LLVMRet            = 1,
187   LLVMBr             = 2,
188   LLVMSwitch         = 3,
189   LLVMIndirectBr     = 4,
190   LLVMInvoke         = 5,
191   /* removed 6 due to API changes */
192   LLVMUnreachable    = 7,
193
194   /* Standard Binary Operators */
195   LLVMAdd            = 8,
196   LLVMFAdd           = 9,
197   LLVMSub            = 10,
198   LLVMFSub           = 11,
199   LLVMMul            = 12,
200   LLVMFMul           = 13,
201   LLVMUDiv           = 14,
202   LLVMSDiv           = 15,
203   LLVMFDiv           = 16,
204   LLVMURem           = 17,
205   LLVMSRem           = 18,
206   LLVMFRem           = 19,
207
208   /* Logical Operators */
209   LLVMShl            = 20,
210   LLVMLShr           = 21,
211   LLVMAShr           = 22,
212   LLVMAnd            = 23,
213   LLVMOr             = 24,
214   LLVMXor            = 25,
215
216   /* Memory Operators */
217   LLVMAlloca         = 26,
218   LLVMLoad           = 27,
219   LLVMStore          = 28,
220   LLVMGetElementPtr  = 29,
221
222   /* Cast Operators */
223   LLVMTrunc          = 30,
224   LLVMZExt           = 31,
225   LLVMSExt           = 32,
226   LLVMFPToUI         = 33,
227   LLVMFPToSI         = 34,
228   LLVMUIToFP         = 35,
229   LLVMSIToFP         = 36,
230   LLVMFPTrunc        = 37,
231   LLVMFPExt          = 38,
232   LLVMPtrToInt       = 39,
233   LLVMIntToPtr       = 40,
234   LLVMBitCast        = 41,
235
236   /* Other Operators */
237   LLVMICmp           = 42,
238   LLVMFCmp           = 43,
239   LLVMPHI            = 44,
240   LLVMCall           = 45,
241   LLVMSelect         = 46,
242   LLVMUserOp1        = 47,
243   LLVMUserOp2        = 48,
244   LLVMVAArg          = 49,
245   LLVMExtractElement = 50,
246   LLVMInsertElement  = 51,
247   LLVMShuffleVector  = 52,
248   LLVMExtractValue   = 53,
249   LLVMInsertValue    = 54,
250
251   /* Atomic operators */
252   LLVMFence          = 55,
253   LLVMAtomicCmpXchg  = 56,
254   LLVMAtomicRMW      = 57,
255
256   /* Exception Handling Operators */
257   LLVMResume         = 58,
258   LLVMLandingPad     = 59
259
260 } LLVMOpcode;
261
262 typedef enum {
263   LLVMVoidTypeKind,        /**< type with no size */
264   LLVMHalfTypeKind,        /**< 16 bit floating point type */
265   LLVMFloatTypeKind,       /**< 32 bit floating point type */
266   LLVMDoubleTypeKind,      /**< 64 bit floating point type */
267   LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
268   LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
269   LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
270   LLVMLabelTypeKind,       /**< Labels */
271   LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
272   LLVMFunctionTypeKind,    /**< Functions */
273   LLVMStructTypeKind,      /**< Structures */
274   LLVMArrayTypeKind,       /**< Arrays */
275   LLVMPointerTypeKind,     /**< Pointers */
276   LLVMVectorTypeKind,      /**< SIMD 'packed' format, or other vector type */
277   LLVMMetadataTypeKind,    /**< Metadata */
278   LLVMX86_MMXTypeKind      /**< X86 MMX */
279 } LLVMTypeKind;
280
281 typedef enum {
282   LLVMExternalLinkage,    /**< Externally visible function */
283   LLVMAvailableExternallyLinkage,
284   LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
285   LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
286                             equivalent. */
287   LLVMLinkOnceODRAutoHideLinkage, /**< Like LinkOnceODR, but possibly hidden. */
288   LLVMWeakAnyLinkage,     /**< Keep one copy of function when linking (weak) */
289   LLVMWeakODRLinkage,     /**< Same, but only replaced by something
290                             equivalent. */
291   LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
292   LLVMInternalLinkage,    /**< Rename collisions when linking (static
293                                functions) */
294   LLVMPrivateLinkage,     /**< Like Internal, but omit from symbol table */
295   LLVMDLLImportLinkage,   /**< Function to be imported from DLL */
296   LLVMDLLExportLinkage,   /**< Function to be accessible from DLL */
297   LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
298   LLVMGhostLinkage,       /**< Obsolete */
299   LLVMCommonLinkage,      /**< Tentative definitions */
300   LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
301   LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
302 } LLVMLinkage;
303
304 typedef enum {
305   LLVMDefaultVisibility,  /**< The GV is visible */
306   LLVMHiddenVisibility,   /**< The GV is hidden */
307   LLVMProtectedVisibility /**< The GV is protected */
308 } LLVMVisibility;
309
310 typedef enum {
311   LLVMCCallConv           = 0,
312   LLVMFastCallConv        = 8,
313   LLVMColdCallConv        = 9,
314   LLVMX86StdcallCallConv  = 64,
315   LLVMX86FastcallCallConv = 65
316 } LLVMCallConv;
317
318 typedef enum {
319   LLVMIntEQ = 32, /**< equal */
320   LLVMIntNE,      /**< not equal */
321   LLVMIntUGT,     /**< unsigned greater than */
322   LLVMIntUGE,     /**< unsigned greater or equal */
323   LLVMIntULT,     /**< unsigned less than */
324   LLVMIntULE,     /**< unsigned less or equal */
325   LLVMIntSGT,     /**< signed greater than */
326   LLVMIntSGE,     /**< signed greater or equal */
327   LLVMIntSLT,     /**< signed less than */
328   LLVMIntSLE      /**< signed less or equal */
329 } LLVMIntPredicate;
330
331 typedef enum {
332   LLVMRealPredicateFalse, /**< Always false (always folded) */
333   LLVMRealOEQ,            /**< True if ordered and equal */
334   LLVMRealOGT,            /**< True if ordered and greater than */
335   LLVMRealOGE,            /**< True if ordered and greater than or equal */
336   LLVMRealOLT,            /**< True if ordered and less than */
337   LLVMRealOLE,            /**< True if ordered and less than or equal */
338   LLVMRealONE,            /**< True if ordered and operands are unequal */
339   LLVMRealORD,            /**< True if ordered (no nans) */
340   LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
341   LLVMRealUEQ,            /**< True if unordered or equal */
342   LLVMRealUGT,            /**< True if unordered or greater than */
343   LLVMRealUGE,            /**< True if unordered, greater than, or equal */
344   LLVMRealULT,            /**< True if unordered or less than */
345   LLVMRealULE,            /**< True if unordered, less than, or equal */
346   LLVMRealUNE,            /**< True if unordered or not equal */
347   LLVMRealPredicateTrue   /**< Always true (always folded) */
348 } LLVMRealPredicate;
349
350 typedef enum {
351   LLVMLandingPadCatch,    /**< A catch clause   */
352   LLVMLandingPadFilter    /**< A filter clause  */
353 } LLVMLandingPadClauseTy;
354
355 typedef enum {
356   LLVMNotThreadLocal = 0,
357   LLVMGeneralDynamicTLSModel,
358   LLVMLocalDynamicTLSModel,
359   LLVMInitialExecTLSModel,
360   LLVMLocalExecTLSModel
361 } LLVMThreadLocalMode;
362
363 /**
364  * @}
365  */
366
367 void LLVMInitializeCore(LLVMPassRegistryRef R);
368
369 /** Deallocate and destroy all ManagedStatic variables.
370     @see llvm::llvm_shutdown
371     @see ManagedStatic */
372 void LLVMShutdown();
373
374
375 /*===-- Error handling ----------------------------------------------------===*/
376
377 void LLVMDisposeMessage(char *Message);
378
379
380 /**
381  * @defgroup LLVMCCoreContext Contexts
382  *
383  * Contexts are execution states for the core LLVM IR system.
384  *
385  * Most types are tied to a context instance. Multiple contexts can
386  * exist simultaneously. A single context is not thread safe. However,
387  * different contexts can execute on different threads simultaneously.
388  *
389  * @{
390  */
391
392 /**
393  * Create a new context.
394  *
395  * Every call to this function should be paired with a call to
396  * LLVMContextDispose() or the context will leak memory.
397  */
398 LLVMContextRef LLVMContextCreate(void);
399
400 /**
401  * Obtain the global context instance.
402  */
403 LLVMContextRef LLVMGetGlobalContext(void);
404
405 /**
406  * Destroy a context instance.
407  *
408  * This should be called for every call to LLVMContextCreate() or memory
409  * will be leaked.
410  */
411 void LLVMContextDispose(LLVMContextRef C);
412
413 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
414                                   unsigned SLen);
415 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
416
417 /**
418  * @}
419  */
420
421 /**
422  * @defgroup LLVMCCoreModule Modules
423  *
424  * Modules represent the top-level structure in a LLVM program. An LLVM
425  * module is effectively a translation unit or a collection of
426  * translation units merged together.
427  *
428  * @{
429  */
430
431 /**
432  * Create a new, empty module in the global context.
433  *
434  * This is equivalent to calling LLVMModuleCreateWithNameInContext with
435  * LLVMGetGlobalContext() as the context parameter.
436  *
437  * Every invocation should be paired with LLVMDisposeModule() or memory
438  * will be leaked.
439  */
440 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
441
442 /**
443  * Create a new, empty module in a specific context.
444  *
445  * Every invocation should be paired with LLVMDisposeModule() or memory
446  * will be leaked.
447  */
448 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
449                                                 LLVMContextRef C);
450
451 /**
452  * Destroy a module instance.
453  *
454  * This must be called for every created module or memory will be
455  * leaked.
456  */
457 void LLVMDisposeModule(LLVMModuleRef M);
458
459 /**
460  * Obtain the data layout for a module.
461  *
462  * @see Module::getDataLayout()
463  */
464 const char *LLVMGetDataLayout(LLVMModuleRef M);
465
466 /**
467  * Set the data layout for a module.
468  *
469  * @see Module::setDataLayout()
470  */
471 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
472
473 /**
474  * Obtain the target triple for a module.
475  *
476  * @see Module::getTargetTriple()
477  */
478 const char *LLVMGetTarget(LLVMModuleRef M);
479
480 /**
481  * Set the target triple for a module.
482  *
483  * @see Module::setTargetTriple()
484  */
485 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
486
487 /**
488  * Dump a representation of a module to stderr.
489  *
490  * @see Module::dump()
491  */
492 void LLVMDumpModule(LLVMModuleRef M);
493
494 /**
495  * Print a representation of a module to a file. The ErrorMessage needs to be
496  * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
497  *
498  * @see Module::print()
499  */
500 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
501                                char **ErrorMessage);
502
503 /**
504  * Set inline assembly for a module.
505  *
506  * @see Module::setModuleInlineAsm()
507  */
508 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
509
510 /**
511  * Obtain the context to which this module is associated.
512  *
513  * @see Module::getContext()
514  */
515 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
516
517 /**
518  * Obtain a Type from a module by its registered name.
519  */
520 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
521
522 /**
523  * Obtain the number of operands for named metadata in a module.
524  *
525  * @see llvm::Module::getNamedMetadata()
526  */
527 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
528
529 /**
530  * Obtain the named metadata operands for a module.
531  *
532  * The passed LLVMValueRef pointer should refer to an array of
533  * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
534  * array will be populated with the LLVMValueRef instances. Each
535  * instance corresponds to a llvm::MDNode.
536  *
537  * @see llvm::Module::getNamedMetadata()
538  * @see llvm::MDNode::getOperand()
539  */
540 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
541
542 /**
543  * Add an operand to named metadata.
544  *
545  * @see llvm::Module::getNamedMetadata()
546  * @see llvm::MDNode::addOperand()
547  */
548 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
549                                  LLVMValueRef Val);
550
551 /**
552  * Add a function to a module under a specified name.
553  *
554  * @see llvm::Function::Create()
555  */
556 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
557                              LLVMTypeRef FunctionTy);
558
559 /**
560  * Obtain a Function value from a Module by its name.
561  *
562  * The returned value corresponds to a llvm::Function value.
563  *
564  * @see llvm::Module::getFunction()
565  */
566 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
567
568 /**
569  * Obtain an iterator to the first Function in a Module.
570  *
571  * @see llvm::Module::begin()
572  */
573 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
574
575 /**
576  * Obtain an iterator to the last Function in a Module.
577  *
578  * @see llvm::Module::end()
579  */
580 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
581
582 /**
583  * Advance a Function iterator to the next Function.
584  *
585  * Returns NULL if the iterator was already at the end and there are no more
586  * functions.
587  */
588 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
589
590 /**
591  * Decrement a Function iterator to the previous Function.
592  *
593  * Returns NULL if the iterator was already at the beginning and there are
594  * no previous functions.
595  */
596 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
597
598 /**
599  * @}
600  */
601
602 /**
603  * @defgroup LLVMCCoreType Types
604  *
605  * Types represent the type of a value.
606  *
607  * Types are associated with a context instance. The context internally
608  * deduplicates types so there is only 1 instance of a specific type
609  * alive at a time. In other words, a unique type is shared among all
610  * consumers within a context.
611  *
612  * A Type in the C API corresponds to llvm::Type.
613  *
614  * Types have the following hierarchy:
615  *
616  *   types:
617  *     integer type
618  *     real type
619  *     function type
620  *     sequence types:
621  *       array type
622  *       pointer type
623  *       vector type
624  *     void type
625  *     label type
626  *     opaque type
627  *
628  * @{
629  */
630
631 /**
632  * Obtain the enumerated type of a Type instance.
633  *
634  * @see llvm::Type:getTypeID()
635  */
636 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
637
638 /**
639  * Whether the type has a known size.
640  *
641  * Things that don't have a size are abstract types, labels, and void.a
642  *
643  * @see llvm::Type::isSized()
644  */
645 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
646
647 /**
648  * Obtain the context to which this type instance is associated.
649  *
650  * @see llvm::Type::getContext()
651  */
652 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
653
654 /**
655  * @defgroup LLVMCCoreTypeInt Integer Types
656  *
657  * Functions in this section operate on integer types.
658  *
659  * @{
660  */
661
662 /**
663  * Obtain an integer type from a context with specified bit width.
664  */
665 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
666 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
667 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
668 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
669 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
670 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
671
672 /**
673  * Obtain an integer type from the global context with a specified bit
674  * width.
675  */
676 LLVMTypeRef LLVMInt1Type(void);
677 LLVMTypeRef LLVMInt8Type(void);
678 LLVMTypeRef LLVMInt16Type(void);
679 LLVMTypeRef LLVMInt32Type(void);
680 LLVMTypeRef LLVMInt64Type(void);
681 LLVMTypeRef LLVMIntType(unsigned NumBits);
682 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
683
684 /**
685  * @}
686  */
687
688 /**
689  * @defgroup LLVMCCoreTypeFloat Floating Point Types
690  *
691  * @{
692  */
693
694 /**
695  * Obtain a 16-bit floating point type from a context.
696  */
697 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
698
699 /**
700  * Obtain a 32-bit floating point type from a context.
701  */
702 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
703
704 /**
705  * Obtain a 64-bit floating point type from a context.
706  */
707 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
708
709 /**
710  * Obtain a 80-bit floating point type (X87) from a context.
711  */
712 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
713
714 /**
715  * Obtain a 128-bit floating point type (112-bit mantissa) from a
716  * context.
717  */
718 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
719
720 /**
721  * Obtain a 128-bit floating point type (two 64-bits) from a context.
722  */
723 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
724
725 /**
726  * Obtain a floating point type from the global context.
727  *
728  * These map to the functions in this group of the same name.
729  */
730 LLVMTypeRef LLVMHalfType(void);
731 LLVMTypeRef LLVMFloatType(void);
732 LLVMTypeRef LLVMDoubleType(void);
733 LLVMTypeRef LLVMX86FP80Type(void);
734 LLVMTypeRef LLVMFP128Type(void);
735 LLVMTypeRef LLVMPPCFP128Type(void);
736
737 /**
738  * @}
739  */
740
741 /**
742  * @defgroup LLVMCCoreTypeFunction Function Types
743  *
744  * @{
745  */
746
747 /**
748  * Obtain a function type consisting of a specified signature.
749  *
750  * The function is defined as a tuple of a return Type, a list of
751  * parameter types, and whether the function is variadic.
752  */
753 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
754                              LLVMTypeRef *ParamTypes, unsigned ParamCount,
755                              LLVMBool IsVarArg);
756
757 /**
758  * Returns whether a function type is variadic.
759  */
760 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
761
762 /**
763  * Obtain the Type this function Type returns.
764  */
765 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
766
767 /**
768  * Obtain the number of parameters this function accepts.
769  */
770 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
771
772 /**
773  * Obtain the types of a function's parameters.
774  *
775  * The Dest parameter should point to a pre-allocated array of
776  * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
777  * first LLVMCountParamTypes() entries in the array will be populated
778  * with LLVMTypeRef instances.
779  *
780  * @param FunctionTy The function type to operate on.
781  * @param Dest Memory address of an array to be filled with result.
782  */
783 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
784
785 /**
786  * @}
787  */
788
789 /**
790  * @defgroup LLVMCCoreTypeStruct Structure Types
791  *
792  * These functions relate to LLVMTypeRef instances.
793  *
794  * @see llvm::StructType
795  *
796  * @{
797  */
798
799 /**
800  * Create a new structure type in a context.
801  *
802  * A structure is specified by a list of inner elements/types and
803  * whether these can be packed together.
804  *
805  * @see llvm::StructType::create()
806  */
807 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
808                                     unsigned ElementCount, LLVMBool Packed);
809
810 /**
811  * Create a new structure type in the global context.
812  *
813  * @see llvm::StructType::create()
814  */
815 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
816                            LLVMBool Packed);
817
818 /**
819  * Create an empty structure in a context having a specified name.
820  *
821  * @see llvm::StructType::create()
822  */
823 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
824
825 /**
826  * Obtain the name of a structure.
827  *
828  * @see llvm::StructType::getName()
829  */
830 const char *LLVMGetStructName(LLVMTypeRef Ty);
831
832 /**
833  * Set the contents of a structure type.
834  *
835  * @see llvm::StructType::setBody()
836  */
837 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
838                        unsigned ElementCount, LLVMBool Packed);
839
840 /**
841  * Get the number of elements defined inside the structure.
842  *
843  * @see llvm::StructType::getNumElements()
844  */
845 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
846
847 /**
848  * Get the elements within a structure.
849  *
850  * The function is passed the address of a pre-allocated array of
851  * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
852  * invocation, this array will be populated with the structure's
853  * elements. The objects in the destination array will have a lifetime
854  * of the structure type itself, which is the lifetime of the context it
855  * is contained in.
856  */
857 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
858
859 /**
860  * Determine whether a structure is packed.
861  *
862  * @see llvm::StructType::isPacked()
863  */
864 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
865
866 /**
867  * Determine whether a structure is opaque.
868  *
869  * @see llvm::StructType::isOpaque()
870  */
871 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
872
873 /**
874  * @}
875  */
876
877
878 /**
879  * @defgroup LLVMCCoreTypeSequential Sequential Types
880  *
881  * Sequential types represents "arrays" of types. This is a super class
882  * for array, vector, and pointer types.
883  *
884  * @{
885  */
886
887 /**
888  * Obtain the type of elements within a sequential type.
889  *
890  * This works on array, vector, and pointer types.
891  *
892  * @see llvm::SequentialType::getElementType()
893  */
894 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
895
896 /**
897  * Create a fixed size array type that refers to a specific type.
898  *
899  * The created type will exist in the context that its element type
900  * exists in.
901  *
902  * @see llvm::ArrayType::get()
903  */
904 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
905
906 /**
907  * Obtain the length of an array type.
908  *
909  * This only works on types that represent arrays.
910  *
911  * @see llvm::ArrayType::getNumElements()
912  */
913 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
914
915 /**
916  * Create a pointer type that points to a defined type.
917  *
918  * The created type will exist in the context that its pointee type
919  * exists in.
920  *
921  * @see llvm::PointerType::get()
922  */
923 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
924
925 /**
926  * Obtain the address space of a pointer type.
927  *
928  * This only works on types that represent pointers.
929  *
930  * @see llvm::PointerType::getAddressSpace()
931  */
932 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
933
934 /**
935  * Create a vector type that contains a defined type and has a specific
936  * number of elements.
937  *
938  * The created type will exist in the context thats its element type
939  * exists in.
940  *
941  * @see llvm::VectorType::get()
942  */
943 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
944
945 /**
946  * Obtain the number of elements in a vector type.
947  *
948  * This only works on types that represent vectors.
949  *
950  * @see llvm::VectorType::getNumElements()
951  */
952 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
953
954 /**
955  * @}
956  */
957
958 /**
959  * @defgroup LLVMCCoreTypeOther Other Types
960  *
961  * @{
962  */
963
964 /**
965  * Create a void type in a context.
966  */
967 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
968
969 /**
970  * Create a label type in a context.
971  */
972 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
973
974 /**
975  * Create a X86 MMX type in a context.
976  */
977 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
978
979 /**
980  * These are similar to the above functions except they operate on the
981  * global context.
982  */
983 LLVMTypeRef LLVMVoidType(void);
984 LLVMTypeRef LLVMLabelType(void);
985 LLVMTypeRef LLVMX86MMXType(void);
986
987 /**
988  * @}
989  */
990
991 /**
992  * @}
993  */
994
995 /**
996  * @defgroup LLVMCCoreValues Values
997  *
998  * The bulk of LLVM's object model consists of values, which comprise a very
999  * rich type hierarchy.
1000  *
1001  * LLVMValueRef essentially represents llvm::Value. There is a rich
1002  * hierarchy of classes within this type. Depending on the instance
1003  * obtained, not all APIs are available.
1004  *
1005  * Callers can determine the type of a LLVMValueRef by calling the
1006  * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1007  * functions are defined by a macro, so it isn't obvious which are
1008  * available by looking at the Doxygen source code. Instead, look at the
1009  * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1010  * of value names given. These value names also correspond to classes in
1011  * the llvm::Value hierarchy.
1012  *
1013  * @{
1014  */
1015
1016 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1017   macro(Argument)                           \
1018   macro(BasicBlock)                         \
1019   macro(InlineAsm)                          \
1020   macro(MDNode)                             \
1021   macro(MDString)                           \
1022   macro(User)                               \
1023     macro(Constant)                         \
1024       macro(BlockAddress)                   \
1025       macro(ConstantAggregateZero)          \
1026       macro(ConstantArray)                  \
1027       macro(ConstantExpr)                   \
1028       macro(ConstantFP)                     \
1029       macro(ConstantInt)                    \
1030       macro(ConstantPointerNull)            \
1031       macro(ConstantStruct)                 \
1032       macro(ConstantVector)                 \
1033       macro(GlobalValue)                    \
1034         macro(Function)                     \
1035         macro(GlobalAlias)                  \
1036         macro(GlobalVariable)               \
1037       macro(UndefValue)                     \
1038     macro(Instruction)                      \
1039       macro(BinaryOperator)                 \
1040       macro(CallInst)                       \
1041         macro(IntrinsicInst)                \
1042           macro(DbgInfoIntrinsic)           \
1043             macro(DbgDeclareInst)           \
1044           macro(MemIntrinsic)               \
1045             macro(MemCpyInst)               \
1046             macro(MemMoveInst)              \
1047             macro(MemSetInst)               \
1048       macro(CmpInst)                        \
1049         macro(FCmpInst)                     \
1050         macro(ICmpInst)                     \
1051       macro(ExtractElementInst)             \
1052       macro(GetElementPtrInst)              \
1053       macro(InsertElementInst)              \
1054       macro(InsertValueInst)                \
1055       macro(LandingPadInst)                 \
1056       macro(PHINode)                        \
1057       macro(SelectInst)                     \
1058       macro(ShuffleVectorInst)              \
1059       macro(StoreInst)                      \
1060       macro(TerminatorInst)                 \
1061         macro(BranchInst)                   \
1062         macro(IndirectBrInst)               \
1063         macro(InvokeInst)                   \
1064         macro(ReturnInst)                   \
1065         macro(SwitchInst)                   \
1066         macro(UnreachableInst)              \
1067         macro(ResumeInst)                   \
1068     macro(UnaryInstruction)                 \
1069       macro(AllocaInst)                     \
1070       macro(CastInst)                       \
1071         macro(BitCastInst)                  \
1072         macro(FPExtInst)                    \
1073         macro(FPToSIInst)                   \
1074         macro(FPToUIInst)                   \
1075         macro(FPTruncInst)                  \
1076         macro(IntToPtrInst)                 \
1077         macro(PtrToIntInst)                 \
1078         macro(SExtInst)                     \
1079         macro(SIToFPInst)                   \
1080         macro(TruncInst)                    \
1081         macro(UIToFPInst)                   \
1082         macro(ZExtInst)                     \
1083       macro(ExtractValueInst)               \
1084       macro(LoadInst)                       \
1085       macro(VAArgInst)
1086
1087 /**
1088  * @defgroup LLVMCCoreValueGeneral General APIs
1089  *
1090  * Functions in this section work on all LLVMValueRef instances,
1091  * regardless of their sub-type. They correspond to functions available
1092  * on llvm::Value.
1093  *
1094  * @{
1095  */
1096
1097 /**
1098  * Obtain the type of a value.
1099  *
1100  * @see llvm::Value::getType()
1101  */
1102 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1103
1104 /**
1105  * Obtain the string name of a value.
1106  *
1107  * @see llvm::Value::getName()
1108  */
1109 const char *LLVMGetValueName(LLVMValueRef Val);
1110
1111 /**
1112  * Set the string name of a value.
1113  *
1114  * @see llvm::Value::setName()
1115  */
1116 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1117
1118 /**
1119  * Dump a representation of a value to stderr.
1120  *
1121  * @see llvm::Value::dump()
1122  */
1123 void LLVMDumpValue(LLVMValueRef Val);
1124
1125 /**
1126  * Replace all uses of a value with another one.
1127  *
1128  * @see llvm::Value::replaceAllUsesWith()
1129  */
1130 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1131
1132 /**
1133  * Determine whether the specified constant instance is constant.
1134  */
1135 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1136
1137 /**
1138  * Determine whether a value instance is undefined.
1139  */
1140 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1141
1142 /**
1143  * Convert value instances between types.
1144  *
1145  * Internally, a LLVMValueRef is "pinned" to a specific type. This
1146  * series of functions allows you to cast an instance to a specific
1147  * type.
1148  *
1149  * If the cast is not valid for the specified type, NULL is returned.
1150  *
1151  * @see llvm::dyn_cast_or_null<>
1152  */
1153 #define LLVM_DECLARE_VALUE_CAST(name) \
1154   LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1155 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1156
1157 /**
1158  * @}
1159  */
1160
1161 /**
1162  * @defgroup LLVMCCoreValueUses Usage
1163  *
1164  * This module defines functions that allow you to inspect the uses of a
1165  * LLVMValueRef.
1166  *
1167  * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1168  * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1169  * llvm::User and llvm::Value.
1170  *
1171  * @{
1172  */
1173
1174 /**
1175  * Obtain the first use of a value.
1176  *
1177  * Uses are obtained in an iterator fashion. First, call this function
1178  * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1179  * on that instance and all subsequently obtained instances until
1180  * LLVMGetNextUse() returns NULL.
1181  *
1182  * @see llvm::Value::use_begin()
1183  */
1184 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1185
1186 /**
1187  * Obtain the next use of a value.
1188  *
1189  * This effectively advances the iterator. It returns NULL if you are on
1190  * the final use and no more are available.
1191  */
1192 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1193
1194 /**
1195  * Obtain the user value for a user.
1196  *
1197  * The returned value corresponds to a llvm::User type.
1198  *
1199  * @see llvm::Use::getUser()
1200  */
1201 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1202
1203 /**
1204  * Obtain the value this use corresponds to.
1205  *
1206  * @see llvm::Use::get().
1207  */
1208 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1209
1210 /**
1211  * @}
1212  */
1213
1214 /**
1215  * @defgroup LLVMCCoreValueUser User value
1216  *
1217  * Function in this group pertain to LLVMValueRef instances that descent
1218  * from llvm::User. This includes constants, instructions, and
1219  * operators.
1220  *
1221  * @{
1222  */
1223
1224 /**
1225  * Obtain an operand at a specific index in a llvm::User value.
1226  *
1227  * @see llvm::User::getOperand()
1228  */
1229 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1230
1231 /**
1232  * Set an operand at a specific index in a llvm::User value.
1233  *
1234  * @see llvm::User::setOperand()
1235  */
1236 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1237
1238 /**
1239  * Obtain the number of operands in a llvm::User value.
1240  *
1241  * @see llvm::User::getNumOperands()
1242  */
1243 int LLVMGetNumOperands(LLVMValueRef Val);
1244
1245 /**
1246  * @}
1247  */
1248
1249 /**
1250  * @defgroup LLVMCCoreValueConstant Constants
1251  *
1252  * This section contains APIs for interacting with LLVMValueRef that
1253  * correspond to llvm::Constant instances.
1254  *
1255  * These functions will work for any LLVMValueRef in the llvm::Constant
1256  * class hierarchy.
1257  *
1258  * @{
1259  */
1260
1261 /**
1262  * Obtain a constant value referring to the null instance of a type.
1263  *
1264  * @see llvm::Constant::getNullValue()
1265  */
1266 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1267
1268 /**
1269  * Obtain a constant value referring to the instance of a type
1270  * consisting of all ones.
1271  *
1272  * This is only valid for integer types.
1273  *
1274  * @see llvm::Constant::getAllOnesValue()
1275  */
1276 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1277
1278 /**
1279  * Obtain a constant value referring to an undefined value of a type.
1280  *
1281  * @see llvm::UndefValue::get()
1282  */
1283 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1284
1285 /**
1286  * Determine whether a value instance is null.
1287  *
1288  * @see llvm::Constant::isNullValue()
1289  */
1290 LLVMBool LLVMIsNull(LLVMValueRef Val);
1291
1292 /**
1293  * Obtain a constant that is a constant pointer pointing to NULL for a
1294  * specified type.
1295  */
1296 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1297
1298 /**
1299  * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1300  *
1301  * Functions in this group model LLVMValueRef instances that correspond
1302  * to constants referring to scalar types.
1303  *
1304  * For integer types, the LLVMTypeRef parameter should correspond to a
1305  * llvm::IntegerType instance and the returned LLVMValueRef will
1306  * correspond to a llvm::ConstantInt.
1307  *
1308  * For floating point types, the LLVMTypeRef returned corresponds to a
1309  * llvm::ConstantFP.
1310  *
1311  * @{
1312  */
1313
1314 /**
1315  * Obtain a constant value for an integer type.
1316  *
1317  * The returned value corresponds to a llvm::ConstantInt.
1318  *
1319  * @see llvm::ConstantInt::get()
1320  *
1321  * @param IntTy Integer type to obtain value of.
1322  * @param N The value the returned instance should refer to.
1323  * @param SignExtend Whether to sign extend the produced value.
1324  */
1325 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1326                           LLVMBool SignExtend);
1327
1328 /**
1329  * Obtain a constant value for an integer of arbitrary precision.
1330  *
1331  * @see llvm::ConstantInt::get()
1332  */
1333 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1334                                               unsigned NumWords,
1335                                               const uint64_t Words[]);
1336
1337 /**
1338  * Obtain a constant value for an integer parsed from a string.
1339  *
1340  * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1341  * string's length is available, it is preferred to call that function
1342  * instead.
1343  *
1344  * @see llvm::ConstantInt::get()
1345  */
1346 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1347                                   uint8_t Radix);
1348
1349 /**
1350  * Obtain a constant value for an integer parsed from a string with
1351  * specified length.
1352  *
1353  * @see llvm::ConstantInt::get()
1354  */
1355 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1356                                          unsigned SLen, uint8_t Radix);
1357
1358 /**
1359  * Obtain a constant value referring to a double floating point value.
1360  */
1361 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1362
1363 /**
1364  * Obtain a constant for a floating point value parsed from a string.
1365  *
1366  * A similar API, LLVMConstRealOfStringAndSize is also available. It
1367  * should be used if the input string's length is known.
1368  */
1369 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1370
1371 /**
1372  * Obtain a constant for a floating point value parsed from a string.
1373  */
1374 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1375                                           unsigned SLen);
1376
1377 /**
1378  * Obtain the zero extended value for an integer constant value.
1379  *
1380  * @see llvm::ConstantInt::getZExtValue()
1381  */
1382 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1383
1384 /**
1385  * Obtain the sign extended value for an integer constant value.
1386  *
1387  * @see llvm::ConstantInt::getSExtValue()
1388  */
1389 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1390
1391 /**
1392  * @}
1393  */
1394
1395 /**
1396  * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1397  *
1398  * Functions in this group operate on composite constants.
1399  *
1400  * @{
1401  */
1402
1403 /**
1404  * Create a ConstantDataSequential and initialize it with a string.
1405  *
1406  * @see llvm::ConstantDataArray::getString()
1407  */
1408 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1409                                       unsigned Length, LLVMBool DontNullTerminate);
1410
1411 /**
1412  * Create a ConstantDataSequential with string content in the global context.
1413  *
1414  * This is the same as LLVMConstStringInContext except it operates on the
1415  * global context.
1416  *
1417  * @see LLVMConstStringInContext()
1418  * @see llvm::ConstantDataArray::getString()
1419  */
1420 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1421                              LLVMBool DontNullTerminate);
1422
1423 /**
1424  * Create an anonymous ConstantStruct with the specified values.
1425  *
1426  * @see llvm::ConstantStruct::getAnon()
1427  */
1428 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1429                                       LLVMValueRef *ConstantVals,
1430                                       unsigned Count, LLVMBool Packed);
1431
1432 /**
1433  * Create a ConstantStruct in the global Context.
1434  *
1435  * This is the same as LLVMConstStructInContext except it operates on the
1436  * global Context.
1437  *
1438  * @see LLVMConstStructInContext()
1439  */
1440 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1441                              LLVMBool Packed);
1442
1443 /**
1444  * Create a ConstantArray from values.
1445  *
1446  * @see llvm::ConstantArray::get()
1447  */
1448 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1449                             LLVMValueRef *ConstantVals, unsigned Length);
1450
1451 /**
1452  * Create a non-anonymous ConstantStruct from values.
1453  *
1454  * @see llvm::ConstantStruct::get()
1455  */
1456 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1457                                   LLVMValueRef *ConstantVals,
1458                                   unsigned Count);
1459
1460 /**
1461  * Create a ConstantVector from values.
1462  *
1463  * @see llvm::ConstantVector::get()
1464  */
1465 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1466
1467 /**
1468  * @}
1469  */
1470
1471 /**
1472  * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1473  *
1474  * Functions in this group correspond to APIs on llvm::ConstantExpr.
1475  *
1476  * @see llvm::ConstantExpr.
1477  *
1478  * @{
1479  */
1480 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1481 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1482 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1483 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1484 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1485 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1486 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1487 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1488 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1489 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1490 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1491 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1492 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1494 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1495 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1496 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1497 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1498 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1499 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1500 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1501 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1502 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1503 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1504 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1505 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1506 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1507 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1508 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1509 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1510 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1511                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1512 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1513                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1514 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1515 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1516 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1517 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1518                           LLVMValueRef *ConstantIndices, unsigned NumIndices);
1519 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1520                                   LLVMValueRef *ConstantIndices,
1521                                   unsigned NumIndices);
1522 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1523 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1524 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1525 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1526 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1527 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1528 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1529 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1530 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1531 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1532 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1533 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1534 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1535                                     LLVMTypeRef ToType);
1536 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1537                                     LLVMTypeRef ToType);
1538 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1539                                      LLVMTypeRef ToType);
1540 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1541                                   LLVMTypeRef ToType);
1542 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1543                               LLVMBool isSigned);
1544 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1545 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1546                              LLVMValueRef ConstantIfTrue,
1547                              LLVMValueRef ConstantIfFalse);
1548 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1549                                      LLVMValueRef IndexConstant);
1550 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1551                                     LLVMValueRef ElementValueConstant,
1552                                     LLVMValueRef IndexConstant);
1553 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1554                                     LLVMValueRef VectorBConstant,
1555                                     LLVMValueRef MaskConstant);
1556 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1557                                    unsigned NumIdx);
1558 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1559                                   LLVMValueRef ElementValueConstant,
1560                                   unsigned *IdxList, unsigned NumIdx);
1561 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1562                                 const char *AsmString, const char *Constraints,
1563                                 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1564 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1565
1566 /**
1567  * @}
1568  */
1569
1570 /**
1571  * @defgroup LLVMCCoreValueConstantGlobals Global Values
1572  *
1573  * This group contains functions that operate on global values. Functions in
1574  * this group relate to functions in the llvm::GlobalValue class tree.
1575  *
1576  * @see llvm::GlobalValue
1577  *
1578  * @{
1579  */
1580
1581 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1582 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1583 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1584 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1585 const char *LLVMGetSection(LLVMValueRef Global);
1586 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1587 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1588 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1589 unsigned LLVMGetAlignment(LLVMValueRef Global);
1590 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1591
1592 /**
1593  * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1594  *
1595  * This group contains functions that operate on global variable values.
1596  *
1597  * @see llvm::GlobalVariable
1598  *
1599  * @{
1600  */
1601 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1602 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1603                                          const char *Name,
1604                                          unsigned AddressSpace);
1605 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1606 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1607 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1608 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1609 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1610 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1611 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1612 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1613 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1614 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1615 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1616 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1617 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1618 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1619 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1620 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
1621
1622 /**
1623  * @}
1624  */
1625
1626 /**
1627  * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1628  *
1629  * This group contains function that operate on global alias values.
1630  *
1631  * @see llvm::GlobalAlias
1632  *
1633  * @{
1634  */
1635 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1636                           const char *Name);
1637
1638 /**
1639  * @}
1640  */
1641
1642 /**
1643  * @defgroup LLVMCCoreValueFunction Function values
1644  *
1645  * Functions in this group operate on LLVMValueRef instances that
1646  * correspond to llvm::Function instances.
1647  *
1648  * @see llvm::Function
1649  *
1650  * @{
1651  */
1652
1653 /**
1654  * Remove a function from its containing module and deletes it.
1655  *
1656  * @see llvm::Function::eraseFromParent()
1657  */
1658 void LLVMDeleteFunction(LLVMValueRef Fn);
1659
1660 /**
1661  * Obtain the ID number from a function instance.
1662  *
1663  * @see llvm::Function::getIntrinsicID()
1664  */
1665 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1666
1667 /**
1668  * Obtain the calling function of a function.
1669  *
1670  * The returned value corresponds to the LLVMCallConv enumeration.
1671  *
1672  * @see llvm::Function::getCallingConv()
1673  */
1674 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1675
1676 /**
1677  * Set the calling convention of a function.
1678  *
1679  * @see llvm::Function::setCallingConv()
1680  *
1681  * @param Fn Function to operate on
1682  * @param CC LLVMCallConv to set calling convention to
1683  */
1684 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1685
1686 /**
1687  * Obtain the name of the garbage collector to use during code
1688  * generation.
1689  *
1690  * @see llvm::Function::getGC()
1691  */
1692 const char *LLVMGetGC(LLVMValueRef Fn);
1693
1694 /**
1695  * Define the garbage collector to use during code generation.
1696  *
1697  * @see llvm::Function::setGC()
1698  */
1699 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1700
1701 /**
1702  * Add an attribute to a function.
1703  *
1704  * @see llvm::Function::addAttribute()
1705  */
1706 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1707
1708 /**
1709  * Obtain an attribute from a function.
1710  *
1711  * @see llvm::Function::getAttributes()
1712  */
1713 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1714
1715 /**
1716  * Remove an attribute from a function.
1717  */
1718 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1719
1720 /**
1721  * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1722  *
1723  * Functions in this group relate to arguments/parameters on functions.
1724  *
1725  * Functions in this group expect LLVMValueRef instances that correspond
1726  * to llvm::Function instances.
1727  *
1728  * @{
1729  */
1730
1731 /**
1732  * Obtain the number of parameters in a function.
1733  *
1734  * @see llvm::Function::arg_size()
1735  */
1736 unsigned LLVMCountParams(LLVMValueRef Fn);
1737
1738 /**
1739  * Obtain the parameters in a function.
1740  *
1741  * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1742  * at least LLVMCountParams() long. This array will be filled with
1743  * LLVMValueRef instances which correspond to the parameters the
1744  * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1745  * instance.
1746  *
1747  * @see llvm::Function::arg_begin()
1748  */
1749 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1750
1751 /**
1752  * Obtain the parameter at the specified index.
1753  *
1754  * Parameters are indexed from 0.
1755  *
1756  * @see llvm::Function::arg_begin()
1757  */
1758 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1759
1760 /**
1761  * Obtain the function to which this argument belongs.
1762  *
1763  * Unlike other functions in this group, this one takes a LLVMValueRef
1764  * that corresponds to a llvm::Attribute.
1765  *
1766  * The returned LLVMValueRef is the llvm::Function to which this
1767  * argument belongs.
1768  */
1769 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1770
1771 /**
1772  * Obtain the first parameter to a function.
1773  *
1774  * @see llvm::Function::arg_begin()
1775  */
1776 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1777
1778 /**
1779  * Obtain the last parameter to a function.
1780  *
1781  * @see llvm::Function::arg_end()
1782  */
1783 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1784
1785 /**
1786  * Obtain the next parameter to a function.
1787  *
1788  * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1789  * actually a wrapped iterator) and obtains the next parameter from the
1790  * underlying iterator.
1791  */
1792 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1793
1794 /**
1795  * Obtain the previous parameter to a function.
1796  *
1797  * This is the opposite of LLVMGetNextParam().
1798  */
1799 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1800
1801 /**
1802  * Add an attribute to a function argument.
1803  *
1804  * @see llvm::Argument::addAttr()
1805  */
1806 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1807
1808 /**
1809  * Remove an attribute from a function argument.
1810  *
1811  * @see llvm::Argument::removeAttr()
1812  */
1813 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1814
1815 /**
1816  * Get an attribute from a function argument.
1817  */
1818 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1819
1820 /**
1821  * Set the alignment for a function parameter.
1822  *
1823  * @see llvm::Argument::addAttr()
1824  * @see llvm::AttrBuilder::addAlignmentAttr()
1825  */
1826 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
1827
1828 /**
1829  * @}
1830  */
1831
1832 /**
1833  * @}
1834  */
1835
1836 /**
1837  * @}
1838  */
1839
1840 /**
1841  * @}
1842  */
1843
1844 /**
1845  * @defgroup LLVMCCoreValueMetadata Metadata
1846  *
1847  * @{
1848  */
1849
1850 /**
1851  * Obtain a MDString value from a context.
1852  *
1853  * The returned instance corresponds to the llvm::MDString class.
1854  *
1855  * The instance is specified by string data of a specified length. The
1856  * string content is copied, so the backing memory can be freed after
1857  * this function returns.
1858  */
1859 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1860                                    unsigned SLen);
1861
1862 /**
1863  * Obtain a MDString value from the global context.
1864  */
1865 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1866
1867 /**
1868  * Obtain a MDNode value from a context.
1869  *
1870  * The returned value corresponds to the llvm::MDNode class.
1871  */
1872 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1873                                  unsigned Count);
1874
1875 /**
1876  * Obtain a MDNode value from the global context.
1877  */
1878 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1879
1880 /**
1881  * Obtain the underlying string from a MDString value.
1882  *
1883  * @param V Instance to obtain string from.
1884  * @param Len Memory address which will hold length of returned string.
1885  * @return String data in MDString.
1886  */
1887 const char  *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1888
1889 /**
1890  * Obtain the number of operands from an MDNode value.
1891  *
1892  * @param V MDNode to get number of operands from.
1893  * @return Number of operands of the MDNode.
1894  */
1895 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
1896
1897 /**
1898  * Obtain the given MDNode's operands.
1899  *
1900  * The passed LLVMValueRef pointer should point to enough memory to hold all of
1901  * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
1902  * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
1903  * MDNode's operands.
1904  *
1905  * @param V MDNode to get the operands from.
1906  * @param Dest Destination array for operands.
1907  */
1908 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
1909
1910 /**
1911  * @}
1912  */
1913
1914 /**
1915  * @defgroup LLVMCCoreValueBasicBlock Basic Block
1916  *
1917  * A basic block represents a single entry single exit section of code.
1918  * Basic blocks contain a list of instructions which form the body of
1919  * the block.
1920  *
1921  * Basic blocks belong to functions. They have the type of label.
1922  *
1923  * Basic blocks are themselves values. However, the C API models them as
1924  * LLVMBasicBlockRef.
1925  *
1926  * @see llvm::BasicBlock
1927  *
1928  * @{
1929  */
1930
1931 /**
1932  * Convert a basic block instance to a value type.
1933  */
1934 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
1935
1936 /**
1937  * Determine whether a LLVMValueRef is itself a basic block.
1938  */
1939 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
1940
1941 /**
1942  * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1943  */
1944 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
1945
1946 /**
1947  * Obtain the function to which a basic block belongs.
1948  *
1949  * @see llvm::BasicBlock::getParent()
1950  */
1951 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
1952
1953 /**
1954  * Obtain the terminator instruction for a basic block.
1955  *
1956  * If the basic block does not have a terminator (it is not well-formed
1957  * if it doesn't), then NULL is returned.
1958  *
1959  * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1960  *
1961  * @see llvm::BasicBlock::getTerminator()
1962  */
1963 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
1964
1965 /**
1966  * Obtain the number of basic blocks in a function.
1967  *
1968  * @param Fn Function value to operate on.
1969  */
1970 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
1971
1972 /**
1973  * Obtain all of the basic blocks in a function.
1974  *
1975  * This operates on a function value. The BasicBlocks parameter is a
1976  * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1977  * LLVMCountBasicBlocks() in length. This array is populated with
1978  * LLVMBasicBlockRef instances.
1979  */
1980 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
1981
1982 /**
1983  * Obtain the first basic block in a function.
1984  *
1985  * The returned basic block can be used as an iterator. You will likely
1986  * eventually call into LLVMGetNextBasicBlock() with it.
1987  *
1988  * @see llvm::Function::begin()
1989  */
1990 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
1991
1992 /**
1993  * Obtain the last basic block in a function.
1994  *
1995  * @see llvm::Function::end()
1996  */
1997 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
1998
1999 /**
2000  * Advance a basic block iterator.
2001  */
2002 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
2003
2004 /**
2005  * Go backwards in a basic block iterator.
2006  */
2007 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
2008
2009 /**
2010  * Obtain the basic block that corresponds to the entry point of a
2011  * function.
2012  *
2013  * @see llvm::Function::getEntryBlock()
2014  */
2015 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
2016
2017 /**
2018  * Append a basic block to the end of a function.
2019  *
2020  * @see llvm::BasicBlock::Create()
2021  */
2022 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2023                                                 LLVMValueRef Fn,
2024                                                 const char *Name);
2025
2026 /**
2027  * Append a basic block to the end of a function using the global
2028  * context.
2029  *
2030  * @see llvm::BasicBlock::Create()
2031  */
2032 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2033
2034 /**
2035  * Insert a basic block in a function before another basic block.
2036  *
2037  * The function to add to is determined by the function of the
2038  * passed basic block.
2039  *
2040  * @see llvm::BasicBlock::Create()
2041  */
2042 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2043                                                 LLVMBasicBlockRef BB,
2044                                                 const char *Name);
2045
2046 /**
2047  * Insert a basic block in a function using the global context.
2048  *
2049  * @see llvm::BasicBlock::Create()
2050  */
2051 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2052                                        const char *Name);
2053
2054 /**
2055  * Remove a basic block from a function and delete it.
2056  *
2057  * This deletes the basic block from its containing function and deletes
2058  * the basic block itself.
2059  *
2060  * @see llvm::BasicBlock::eraseFromParent()
2061  */
2062 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2063
2064 /**
2065  * Remove a basic block from a function.
2066  *
2067  * This deletes the basic block from its containing function but keep
2068  * the basic block alive.
2069  *
2070  * @see llvm::BasicBlock::removeFromParent()
2071  */
2072 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2073
2074 /**
2075  * Move a basic block to before another one.
2076  *
2077  * @see llvm::BasicBlock::moveBefore()
2078  */
2079 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2080
2081 /**
2082  * Move a basic block to after another one.
2083  *
2084  * @see llvm::BasicBlock::moveAfter()
2085  */
2086 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2087
2088 /**
2089  * Obtain the first instruction in a basic block.
2090  *
2091  * The returned LLVMValueRef corresponds to a llvm::Instruction
2092  * instance.
2093  */
2094 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2095
2096 /**
2097  * Obtain the last instruction in a basic block.
2098  *
2099  * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2100  */
2101 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2102
2103 /**
2104  * @}
2105  */
2106
2107 /**
2108  * @defgroup LLVMCCoreValueInstruction Instructions
2109  *
2110  * Functions in this group relate to the inspection and manipulation of
2111  * individual instructions.
2112  *
2113  * In the C++ API, an instruction is modeled by llvm::Instruction. This
2114  * class has a large number of descendents. llvm::Instruction is a
2115  * llvm::Value and in the C API, instructions are modeled by
2116  * LLVMValueRef.
2117  *
2118  * This group also contains sub-groups which operate on specific
2119  * llvm::Instruction types, e.g. llvm::CallInst.
2120  *
2121  * @{
2122  */
2123
2124 /**
2125  * Determine whether an instruction has any metadata attached.
2126  */
2127 int LLVMHasMetadata(LLVMValueRef Val);
2128
2129 /**
2130  * Return metadata associated with an instruction value.
2131  */
2132 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2133
2134 /**
2135  * Set metadata associated with an instruction value.
2136  */
2137 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2138
2139 /**
2140  * Obtain the basic block to which an instruction belongs.
2141  *
2142  * @see llvm::Instruction::getParent()
2143  */
2144 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2145
2146 /**
2147  * Obtain the instruction that occurs after the one specified.
2148  *
2149  * The next instruction will be from the same basic block.
2150  *
2151  * If this is the last instruction in a basic block, NULL will be
2152  * returned.
2153  */
2154 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2155
2156 /**
2157  * Obtain the instruction that occurred before this one.
2158  *
2159  * If the instruction is the first instruction in a basic block, NULL
2160  * will be returned.
2161  */
2162 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2163
2164 /**
2165  * Remove and delete an instruction.
2166  *
2167  * The instruction specified is removed from its containing building
2168  * block and then deleted.
2169  *
2170  * @see llvm::Instruction::eraseFromParent()
2171  */
2172 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2173
2174 /**
2175  * Obtain the code opcode for an individual instruction.
2176  *
2177  * @see llvm::Instruction::getOpCode()
2178  */
2179 LLVMOpcode   LLVMGetInstructionOpcode(LLVMValueRef Inst);
2180
2181 /**
2182  * Obtain the predicate of an instruction.
2183  *
2184  * This is only valid for instructions that correspond to llvm::ICmpInst
2185  * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2186  *
2187  * @see llvm::ICmpInst::getPredicate()
2188  */
2189 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2190
2191 /**
2192  * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2193  *
2194  * Functions in this group apply to instructions that refer to call
2195  * sites and invocations. These correspond to C++ types in the
2196  * llvm::CallInst class tree.
2197  *
2198  * @{
2199  */
2200
2201 /**
2202  * Set the calling convention for a call instruction.
2203  *
2204  * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2205  * llvm::InvokeInst.
2206  *
2207  * @see llvm::CallInst::setCallingConv()
2208  * @see llvm::InvokeInst::setCallingConv()
2209  */
2210 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2211
2212 /**
2213  * Obtain the calling convention for a call instruction.
2214  *
2215  * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2216  * usage.
2217  *
2218  * @see LLVMSetInstructionCallConv()
2219  */
2220 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2221
2222
2223 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2224 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2225                               LLVMAttribute);
2226 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2227                                 unsigned align);
2228
2229 /**
2230  * Obtain whether a call instruction is a tail call.
2231  *
2232  * This only works on llvm::CallInst instructions.
2233  *
2234  * @see llvm::CallInst::isTailCall()
2235  */
2236 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2237
2238 /**
2239  * Set whether a call instruction is a tail call.
2240  *
2241  * This only works on llvm::CallInst instructions.
2242  *
2243  * @see llvm::CallInst::setTailCall()
2244  */
2245 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2246
2247 /**
2248  * @}
2249  */
2250
2251 /**
2252  * Obtain the default destination basic block of a switch instruction.
2253  *
2254  * This only works on llvm::SwitchInst instructions.
2255  *
2256  * @see llvm::SwitchInst::getDefaultDest()
2257  */
2258 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2259
2260 /**
2261  * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2262  *
2263  * Functions in this group only apply to instructions that map to
2264  * llvm::PHINode instances.
2265  *
2266  * @{
2267  */
2268
2269 /**
2270  * Add an incoming value to the end of a PHI list.
2271  */
2272 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2273                      LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2274
2275 /**
2276  * Obtain the number of incoming basic blocks to a PHI node.
2277  */
2278 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2279
2280 /**
2281  * Obtain an incoming value to a PHI node as a LLVMValueRef.
2282  */
2283 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2284
2285 /**
2286  * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2287  */
2288 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2289
2290 /**
2291  * @}
2292  */
2293
2294 /**
2295  * @}
2296  */
2297
2298 /**
2299  * @}
2300  */
2301
2302 /**
2303  * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2304  *
2305  * An instruction builder represents a point within a basic block and is
2306  * the exclusive means of building instructions using the C interface.
2307  *
2308  * @{
2309  */
2310
2311 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2312 LLVMBuilderRef LLVMCreateBuilder(void);
2313 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2314                          LLVMValueRef Instr);
2315 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2316 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2317 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2318 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2319 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2320 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2321                                    const char *Name);
2322 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2323
2324 /* Metadata */
2325 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2326 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2327 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2328
2329 /* Terminators */
2330 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2331 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2332 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2333                                    unsigned N);
2334 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2335 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2336                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2337 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2338                              LLVMBasicBlockRef Else, unsigned NumCases);
2339 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2340                                  unsigned NumDests);
2341 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2342                              LLVMValueRef *Args, unsigned NumArgs,
2343                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2344                              const char *Name);
2345 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2346                                  LLVMValueRef PersFn, unsigned NumClauses,
2347                                  const char *Name);
2348 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2349 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2350
2351 /* Add a case to the switch instruction */
2352 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2353                  LLVMBasicBlockRef Dest);
2354
2355 /* Add a destination to the indirectbr instruction */
2356 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2357
2358 /* Add a catch or filter clause to the landingpad instruction */
2359 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2360
2361 /* Set the 'cleanup' flag in the landingpad instruction */
2362 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2363
2364 /* Arithmetic */
2365 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2366                           const char *Name);
2367 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2368                              const char *Name);
2369 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2370                              const char *Name);
2371 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2372                            const char *Name);
2373 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2374                           const char *Name);
2375 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2376                              const char *Name);
2377 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2378                              const char *Name);
2379 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2380                            const char *Name);
2381 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2382                           const char *Name);
2383 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2384                              const char *Name);
2385 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2386                              const char *Name);
2387 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2388                            const char *Name);
2389 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2390                            const char *Name);
2391 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2392                            const char *Name);
2393 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2394                                 const char *Name);
2395 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2396                            const char *Name);
2397 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2398                            const char *Name);
2399 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2400                            const char *Name);
2401 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2402                            const char *Name);
2403 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2404                            const char *Name);
2405 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2406                            const char *Name);
2407 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2408                            const char *Name);
2409 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2410                           const char *Name);
2411 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2412                           const char *Name);
2413 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2414                           const char *Name);
2415 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2416                             LLVMValueRef LHS, LLVMValueRef RHS,
2417                             const char *Name);
2418 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2419 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2420                              const char *Name);
2421 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2422                              const char *Name);
2423 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2424 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2425
2426 /* Memory */
2427 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2428 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2429                                   LLVMValueRef Val, const char *Name);
2430 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2431 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2432                                   LLVMValueRef Val, const char *Name);
2433 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2434 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2435                            const char *Name);
2436 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2437 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2438                           LLVMValueRef *Indices, unsigned NumIndices,
2439                           const char *Name);
2440 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2441                                   LLVMValueRef *Indices, unsigned NumIndices,
2442                                   const char *Name);
2443 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2444                                 unsigned Idx, const char *Name);
2445 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2446                                    const char *Name);
2447 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2448                                       const char *Name);
2449 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2450 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2451
2452 /* Casts */
2453 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2454                             LLVMTypeRef DestTy, const char *Name);
2455 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2456                            LLVMTypeRef DestTy, const char *Name);
2457 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2458                            LLVMTypeRef DestTy, const char *Name);
2459 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2460                              LLVMTypeRef DestTy, const char *Name);
2461 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2462                              LLVMTypeRef DestTy, const char *Name);
2463 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2464                              LLVMTypeRef DestTy, const char *Name);
2465 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2466                              LLVMTypeRef DestTy, const char *Name);
2467 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2468                               LLVMTypeRef DestTy, const char *Name);
2469 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2470                             LLVMTypeRef DestTy, const char *Name);
2471 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2472                                LLVMTypeRef DestTy, const char *Name);
2473 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2474                                LLVMTypeRef DestTy, const char *Name);
2475 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2476                               LLVMTypeRef DestTy, const char *Name);
2477 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2478                                     LLVMTypeRef DestTy, const char *Name);
2479 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2480                                     LLVMTypeRef DestTy, const char *Name);
2481 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2482                                      LLVMTypeRef DestTy, const char *Name);
2483 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2484                            LLVMTypeRef DestTy, const char *Name);
2485 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2486                                   LLVMTypeRef DestTy, const char *Name);
2487 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2488                               LLVMTypeRef DestTy, const char *Name);
2489 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2490                              LLVMTypeRef DestTy, const char *Name);
2491
2492 /* Comparisons */
2493 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2494                            LLVMValueRef LHS, LLVMValueRef RHS,
2495                            const char *Name);
2496 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2497                            LLVMValueRef LHS, LLVMValueRef RHS,
2498                            const char *Name);
2499
2500 /* Miscellaneous instructions */
2501 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2502 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2503                            LLVMValueRef *Args, unsigned NumArgs,
2504                            const char *Name);
2505 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2506                              LLVMValueRef Then, LLVMValueRef Else,
2507                              const char *Name);
2508 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2509                             const char *Name);
2510 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2511                                      LLVMValueRef Index, const char *Name);
2512 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2513                                     LLVMValueRef EltVal, LLVMValueRef Index,
2514                                     const char *Name);
2515 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2516                                     LLVMValueRef V2, LLVMValueRef Mask,
2517                                     const char *Name);
2518 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2519                                    unsigned Index, const char *Name);
2520 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2521                                   LLVMValueRef EltVal, unsigned Index,
2522                                   const char *Name);
2523
2524 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2525                              const char *Name);
2526 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2527                                 const char *Name);
2528 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2529                               LLVMValueRef RHS, const char *Name);
2530
2531 /**
2532  * @}
2533  */
2534
2535 /**
2536  * @defgroup LLVMCCoreModuleProvider Module Providers
2537  *
2538  * @{
2539  */
2540
2541 /**
2542  * Changes the type of M so it can be passed to FunctionPassManagers and the
2543  * JIT.  They take ModuleProviders for historical reasons.
2544  */
2545 LLVMModuleProviderRef
2546 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2547
2548 /**
2549  * Destroys the module M.
2550  */
2551 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2552
2553 /**
2554  * @}
2555  */
2556
2557 /**
2558  * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2559  *
2560  * @{
2561  */
2562
2563 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2564                                                   LLVMMemoryBufferRef *OutMemBuf,
2565                                                   char **OutMessage);
2566 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2567                                          char **OutMessage);
2568 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2569                                                           size_t InputDataLength,
2570                                                           const char *BufferName,
2571                                                           LLVMBool RequiresNullTerminator);
2572 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2573                                                               size_t InputDataLength,
2574                                                               const char *BufferName);
2575 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2576
2577 /**
2578  * @}
2579  */
2580
2581 /**
2582  * @defgroup LLVMCCorePassRegistry Pass Registry
2583  *
2584  * @{
2585  */
2586
2587 /** Return the global pass registry, for use with initialization functions.
2588     @see llvm::PassRegistry::getPassRegistry */
2589 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2590
2591 /**
2592  * @}
2593  */
2594
2595 /**
2596  * @defgroup LLVMCCorePassManagers Pass Managers
2597  *
2598  * @{
2599  */
2600
2601 /** Constructs a new whole-module pass pipeline. This type of pipeline is
2602     suitable for link-time optimization and whole-module transformations.
2603     @see llvm::PassManager::PassManager */
2604 LLVMPassManagerRef LLVMCreatePassManager(void);
2605
2606 /** Constructs a new function-by-function pass pipeline over the module
2607     provider. It does not take ownership of the module provider. This type of
2608     pipeline is suitable for code generation and JIT compilation tasks.
2609     @see llvm::FunctionPassManager::FunctionPassManager */
2610 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2611
2612 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2613 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2614
2615 /** Initializes, executes on the provided module, and finalizes all of the
2616     passes scheduled in the pass manager. Returns 1 if any of the passes
2617     modified the module, 0 otherwise.
2618     @see llvm::PassManager::run(Module&) */
2619 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2620
2621 /** Initializes all of the function passes scheduled in the function pass
2622     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2623     @see llvm::FunctionPassManager::doInitialization */
2624 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2625
2626 /** Executes all of the function passes scheduled in the function pass manager
2627     on the provided function. Returns 1 if any of the passes modified the
2628     function, false otherwise.
2629     @see llvm::FunctionPassManager::run(Function&) */
2630 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2631
2632 /** Finalizes all of the function passes scheduled in in the function pass
2633     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2634     @see llvm::FunctionPassManager::doFinalization */
2635 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2636
2637 /** Frees the memory of a pass pipeline. For function pipelines, does not free
2638     the module provider.
2639     @see llvm::PassManagerBase::~PassManagerBase. */
2640 void LLVMDisposePassManager(LLVMPassManagerRef PM);
2641
2642 /**
2643  * @}
2644  */
2645
2646 /**
2647  * @defgroup LLVMCCoreThreading Threading
2648  *
2649  * Handle the structures needed to make LLVM safe for multithreading.
2650  *
2651  * @{
2652  */
2653
2654 /** Allocate and initialize structures needed to make LLVM safe for
2655     multithreading. The return value indicates whether multithreaded
2656     initialization succeeded. Must be executed in isolation from all
2657     other LLVM api calls.
2658     @see llvm::llvm_start_multithreaded */
2659 LLVMBool LLVMStartMultithreaded();
2660
2661 /** Deallocate structures necessary to make LLVM safe for multithreading.
2662     Must be executed in isolation from all other LLVM api calls.
2663     @see llvm::llvm_stop_multithreaded */
2664 void LLVMStopMultithreaded();
2665
2666 /** Check whether LLVM is executing in thread-safe mode or not.
2667     @see llvm::llvm_is_multithreaded */
2668 LLVMBool LLVMIsMultithreaded();
2669
2670 /**
2671  * @}
2672  */
2673
2674 /**
2675  * @}
2676  */
2677
2678 /**
2679  * @}
2680  */
2681
2682 #ifdef __cplusplus
2683 }
2684
2685 namespace llvm {
2686   class MemoryBuffer;
2687   class PassManagerBase;
2688   
2689   #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
2690     inline ty *unwrap(ref P) {                          \
2691       return reinterpret_cast<ty*>(P);                  \
2692     }                                                   \
2693                                                         \
2694     inline ref wrap(const ty *P) {                      \
2695       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2696     }
2697   
2698   #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
2699     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
2700                                                         \
2701     template<typename T>                                \
2702     inline T *unwrap(ref P) {                           \
2703       return cast<T>(unwrap(P));                        \
2704     }
2705   
2706   #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
2707     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
2708                                                         \
2709     template<typename T>                                \
2710     inline T *unwrap(ref P) {                           \
2711       T *Q = (T*)unwrap(P);                             \
2712       assert(Q && "Invalid cast!");                     \
2713       return Q;                                         \
2714     }
2715   
2716   DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
2717   DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
2718   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
2719   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
2720   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
2721   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
2722   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
2723   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use,                LLVMUseRef           )
2724   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
2725   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry,       LLVMPassRegistryRef  )
2726   /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2727    * Module.
2728    */
2729   inline Module *unwrap(LLVMModuleProviderRef MP) {
2730     return reinterpret_cast<Module*>(MP);
2731   }
2732   
2733   #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2734   #undef DEFINE_ISA_CONVERSION_FUNCTIONS
2735   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
2736
2737   /* Specialized opaque context conversions.
2738    */
2739   inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2740     return reinterpret_cast<LLVMContext**>(Tys);
2741   }
2742   
2743   inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2744     return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2745   }
2746   
2747   /* Specialized opaque type conversions.
2748    */
2749   inline Type **unwrap(LLVMTypeRef* Tys) {
2750     return reinterpret_cast<Type**>(Tys);
2751   }
2752   
2753   inline LLVMTypeRef *wrap(Type **Tys) {
2754     return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2755   }
2756   
2757   /* Specialized opaque value conversions.
2758    */ 
2759   inline Value **unwrap(LLVMValueRef *Vals) {
2760     return reinterpret_cast<Value**>(Vals);
2761   }
2762   
2763   template<typename T>
2764   inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2765     #ifdef DEBUG
2766     for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
2767       cast<T>(*I);
2768     #endif
2769     (void)Length;
2770     return reinterpret_cast<T**>(Vals);
2771   }
2772   
2773   inline LLVMValueRef *wrap(const Value **Vals) {
2774     return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2775   }
2776 }
2777
2778 #endif /* !defined(__cplusplus) */
2779
2780 #endif /* !defined(LLVM_C_CORE_H) */