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