OSDN Git Service

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