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