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