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