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