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