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