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