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