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