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