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