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 the "value type" of a global value. This differs from the formal
2895 * type of a global value which is always a pointer type.
2896 *
2897 * @see llvm::GlobalValue::getValueType()
2898 * @see llvm::Function::getFunctionType()
2899 */
2900LLVM_C_ABI LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
2901
2902/** Deprecated: Use LLVMGetUnnamedAddress instead. */
2903LLVM_C_ABI LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
2904/** Deprecated: Use LLVMSetUnnamedAddress instead. */
2905LLVM_C_ABI void LLVMSetUnnamedAddr(LLVMValueRef Global,
2906 LLVMBool HasUnnamedAddr);
2907
2908/**
2909 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
2910 *
2911 * Functions in this group only apply to values with alignment, i.e.
2912 * global variables, load and store instructions.
2913 */
2914
2915/**
2916 * Obtain the preferred alignment of the value.
2917 * @see llvm::AllocaInst::getAlignment()
2918 * @see llvm::LoadInst::getAlignment()
2919 * @see llvm::StoreInst::getAlignment()
2920 * @see llvm::AtomicRMWInst::setAlignment()
2921 * @see llvm::AtomicCmpXchgInst::setAlignment()
2922 * @see llvm::GlobalValue::getAlignment()
2923 */
2924LLVM_C_ABI unsigned LLVMGetAlignment(LLVMValueRef V);
2925
2926/**
2927 * Set the preferred alignment of the value.
2928 * @see llvm::AllocaInst::setAlignment()
2929 * @see llvm::LoadInst::setAlignment()
2930 * @see llvm::StoreInst::setAlignment()
2931 * @see llvm::AtomicRMWInst::setAlignment()
2932 * @see llvm::AtomicCmpXchgInst::setAlignment()
2933 * @see llvm::GlobalValue::setAlignment()
2934 */
2935LLVM_C_ABI void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
2936
2937/**
2938 * Sets a metadata attachment, erasing the existing metadata attachment if
2939 * it already exists for the given kind.
2940 *
2941 * @see llvm::GlobalObject::setMetadata()
2942 */
2943LLVM_C_ABI void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind,
2944 LLVMMetadataRef MD);
2945
2946/**
2947 * Adds a metadata attachment.
2948 *
2949 * @see llvm::GlobalObject::addMetadata()
2950 */
2951LLVM_C_ABI void LLVMGlobalAddMetadata(LLVMValueRef Global, unsigned Kind,
2952 LLVMMetadataRef MD);
2953
2954/**
2955 * Erases a metadata attachment of the given kind if it exists.
2956 *
2957 * @see llvm::GlobalObject::eraseMetadata()
2958 */
2959LLVM_C_ABI void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind);
2960
2961/**
2962 * Removes all metadata attachments from this value.
2963 *
2964 * @see llvm::GlobalObject::clearMetadata()
2965 */
2966LLVM_C_ABI void LLVMGlobalClearMetadata(LLVMValueRef Global);
2967
2968/**
2969 * Add debuginfo metadata to this global.
2970 *
2971 * @see llvm::GlobalVariable::addDebugInfo()
2972 */
2973LLVM_C_ABI void LLVMGlobalAddDebugInfo(LLVMValueRef Global,
2974 LLVMMetadataRef GVE);
2975
2976/**
2977 * Retrieves an array of metadata entries representing the metadata attached to
2978 * this value. The caller is responsible for freeing this array by calling
2979 * \c LLVMDisposeValueMetadataEntries.
2980 *
2981 * @see llvm::GlobalObject::getAllMetadata()
2982 */
2983LLVM_C_ABI LLVMValueMetadataEntry *
2984LLVMGlobalCopyAllMetadata(LLVMValueRef Value, size_t *NumEntries);
2985
2986/**
2987 * Destroys value metadata entries.
2988 */
2989LLVM_C_ABI void
2990LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries);
2991
2992/**
2993 * Returns the kind of a value metadata entry at a specific index.
2994 */
2995LLVM_C_ABI unsigned
2996LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries,
2997 unsigned Index);
2998
2999/**
3000 * Returns the underlying metadata node of a value metadata entry at a
3001 * specific index.
3002 */
3003LLVM_C_ABI LLVMMetadataRef LLVMValueMetadataEntriesGetMetadata(
3004 LLVMValueMetadataEntry *Entries, unsigned Index);
3005
3006/**
3007 * @}
3008 */
3009
3010/**
3011 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
3012 *
3013 * This group contains functions that operate on global variable values.
3014 *
3015 * @see llvm::GlobalVariable
3016 *
3017 * @{
3018 */
3019LLVM_C_ABI LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty,
3020 const char *Name);
3021LLVM_C_ABI LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M,
3022 LLVMTypeRef Ty,
3023 const char *Name,
3024 unsigned AddressSpace);
3025LLVM_C_ABI LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
3026LLVM_C_ABI LLVMValueRef LLVMGetNamedGlobalWithLength(LLVMModuleRef M,
3027 const char *Name,
3028 size_t Length);
3029LLVM_C_ABI LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
3030LLVM_C_ABI LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
3031LLVM_C_ABI LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
3032LLVM_C_ABI LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
3033LLVM_C_ABI void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
3034LLVM_C_ABI LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
3035LLVM_C_ABI void LLVMSetInitializer(LLVMValueRef GlobalVar,
3036 LLVMValueRef ConstantVal);
3037LLVM_C_ABI LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
3038LLVM_C_ABI void LLVMSetThreadLocal(LLVMValueRef GlobalVar,
3039 LLVMBool IsThreadLocal);
3040LLVM_C_ABI LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
3041LLVM_C_ABI void LLVMSetGlobalConstant(LLVMValueRef GlobalVar,
3042 LLVMBool IsConstant);
3043LLVM_C_ABI LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
3044LLVM_C_ABI void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar,
3045 LLVMThreadLocalMode Mode);
3046LLVM_C_ABI LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
3047LLVM_C_ABI void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar,
3048 LLVMBool IsExtInit);
3049
3050/**
3051 * @}
3052 */
3053
3054/**
3055 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
3056 *
3057 * This group contains function that operate on global alias values.
3058 *
3059 * @see llvm::GlobalAlias
3060 *
3061 * @{
3062 */
3063
3064/**
3065 * Add a GlobalAlias with the given value type, address space and aliasee.
3066 *
3067 * @see llvm::GlobalAlias::create()
3068 */
3069LLVM_C_ABI LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy,
3070 unsigned AddrSpace, LLVMValueRef Aliasee,
3071 const char *Name);
3072
3073/**
3074 * Obtain a GlobalAlias value from a Module by its name.
3075 *
3076 * The returned value corresponds to a llvm::GlobalAlias value.
3077 *
3078 * @see llvm::Module::getNamedAlias()
3079 */
3080LLVM_C_ABI LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M,
3081 const char *Name,
3082 size_t NameLen);
3083
3084/**
3085 * Obtain an iterator to the first GlobalAlias in a Module.
3086 *
3087 * @see llvm::Module::alias_begin()
3088 */
3089LLVM_C_ABI LLVMValueRef LLVMGetFirstGlobalAlias(LLVMModuleRef M);
3090
3091/**
3092 * Obtain an iterator to the last GlobalAlias in a Module.
3093 *
3094 * @see llvm::Module::alias_end()
3095 */
3096LLVM_C_ABI LLVMValueRef LLVMGetLastGlobalAlias(LLVMModuleRef M);
3097
3098/**
3099 * Advance a GlobalAlias iterator to the next GlobalAlias.
3100 *
3101 * Returns NULL if the iterator was already at the end and there are no more
3102 * global aliases.
3103 */
3104LLVM_C_ABI LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA);
3105
3106/**
3107 * Decrement a GlobalAlias iterator to the previous GlobalAlias.
3108 *
3109 * Returns NULL if the iterator was already at the beginning and there are
3110 * no previous global aliases.
3111 */
3112LLVM_C_ABI LLVMValueRef LLVMGetPreviousGlobalAlias(LLVMValueRef GA);
3113
3114/**
3115 * Retrieve the target value of an alias.
3116 */
3117LLVM_C_ABI LLVMValueRef LLVMAliasGetAliasee(LLVMValueRef Alias);
3118
3119/**
3120 * Set the target value of an alias.
3121 */
3122LLVM_C_ABI void LLVMAliasSetAliasee(LLVMValueRef Alias, LLVMValueRef Aliasee);
3123
3124/**
3125 * @}
3126 */
3127
3128/**
3129 * @defgroup LLVMCCoreValueFunction Function values
3130 *
3131 * Functions in this group operate on LLVMValueRef instances that
3132 * correspond to llvm::Function instances.
3133 *
3134 * @see llvm::Function
3135 *
3136 * @{
3137 */
3138
3139/**
3140 * Remove a function from its containing module and deletes it.
3141 *
3142 * @see llvm::Function::eraseFromParent()
3143 */
3144LLVM_C_ABI void LLVMDeleteFunction(LLVMValueRef Fn);
3145
3146/**
3147 * Check whether the given function has a personality function.
3148 *
3149 * @see llvm::Function::hasPersonalityFn()
3150 */
3151LLVM_C_ABI LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
3152
3153/**
3154 * Obtain the personality function attached to the function.
3155 *
3156 * @see llvm::Function::getPersonalityFn()
3157 */
3158LLVM_C_ABI LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
3159
3160/**
3161 * Set the personality function attached to the function.
3162 *
3163 * @see llvm::Function::setPersonalityFn()
3164 */
3165LLVM_C_ABI void LLVMSetPersonalityFn(LLVMValueRef Fn,
3166 LLVMValueRef PersonalityFn);
3167
3168/**
3169 * Obtain the intrinsic ID number which matches the given function name.
3170 *
3171 * @see llvm::Intrinsic::lookupIntrinsicID()
3172 */
3173LLVM_C_ABI unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen);
3174
3175/**
3176 * Obtain the ID number from a function instance.
3177 *
3178 * @see llvm::Function::getIntrinsicID()
3179 */
3180LLVM_C_ABI unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
3181
3182/**
3183 * Get or insert the declaration of an intrinsic. For overloaded intrinsics,
3184 * overload types must be provided to uniquely identify an overload.
3185 *
3186 * @see llvm::Intrinsic::getOrInsertDeclaration()
3187 */
3188LLVM_C_ABI LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
3189 unsigned ID,
3190 LLVMTypeRef *OverloadTypes,
3191 size_t OverloadCount);
3192
3193/**
3194 * Retrieves the type of an intrinsic. For overloaded intrinsics, overload
3195 * types must be provided to uniquely identify an overload.
3196 *
3197 * @see llvm::Intrinsic::getType()
3198 */
3199LLVM_C_ABI LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID,
3200 LLVMTypeRef *OverloadTypes,
3201 size_t OverloadCount);
3202
3203/**
3204 * Retrieves the name of an intrinsic.
3205 *
3206 * @see llvm::Intrinsic::getName()
3207 */
3208LLVM_C_ABI const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength);
3209
3210/** Deprecated: Use LLVMIntrinsicCopyOverloadedName2 instead. */
3211LLVM_C_ABI char *LLVMIntrinsicCopyOverloadedName(unsigned ID,
3212 LLVMTypeRef *OverloadTypes,
3213 size_t OverloadCount,
3214 size_t *NameLength);
3215
3216/**
3217 * Copies the name of an overloaded intrinsic identified by a given list of
3218 * overload types.
3219 *
3220 * Unlike LLVMIntrinsicGetName, the caller is responsible for freeing the
3221 * returned string.
3222 *
3223 * This version also supports unnamed types.
3224 *
3225 * @see llvm::Intrinsic::getName()
3226 */
3227LLVM_C_ABI char *LLVMIntrinsicCopyOverloadedName2(LLVMModuleRef Mod,
3228 unsigned ID,
3229 LLVMTypeRef *OverloadTypes,
3230 size_t OverloadCount,
3231 size_t *NameLength);
3232
3233/**
3234 * Obtain if the intrinsic identified by the given ID is overloaded.
3235 *
3236 * @see llvm::Intrinsic::isOverloaded()
3237 */
3238LLVM_C_ABI LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID);
3239
3240/**
3241 * Obtain the calling function of a function.
3242 *
3243 * The returned value corresponds to the LLVMCallConv enumeration.
3244 *
3245 * @see llvm::Function::getCallingConv()
3246 */
3247LLVM_C_ABI unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
3248
3249/**
3250 * Set the calling convention of a function.
3251 *
3252 * @see llvm::Function::setCallingConv()
3253 *
3254 * @param Fn Function to operate on
3255 * @param CC LLVMCallConv to set calling convention to
3256 */
3257LLVM_C_ABI void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
3258
3259/**
3260 * Obtain the name of the garbage collector to use during code
3261 * generation.
3262 *
3263 * @see llvm::Function::getGC()
3264 */
3265LLVM_C_ABI const char *LLVMGetGC(LLVMValueRef Fn);
3266
3267/**
3268 * Define the garbage collector to use during code generation.
3269 *
3270 * @see llvm::Function::setGC()
3271 */
3272LLVM_C_ABI void LLVMSetGC(LLVMValueRef Fn, const char *Name);
3273
3274/**
3275 * Gets the prefix data associated with a function. Only valid on functions, and
3276 * only if LLVMHasPrefixData returns true.
3277 * See https://llvm.org/docs/LangRef.html#prefix-data
3278 */
3279LLVM_C_ABI LLVMValueRef LLVMGetPrefixData(LLVMValueRef Fn);
3280
3281/**
3282 * Check if a given function has prefix data. Only valid on functions.
3283 * See https://llvm.org/docs/LangRef.html#prefix-data
3284 */
3285LLVM_C_ABI LLVMBool LLVMHasPrefixData(LLVMValueRef Fn);
3286
3287/**
3288 * Sets the prefix data for the function. Only valid on functions.
3289 * See https://llvm.org/docs/LangRef.html#prefix-data
3290 */
3291LLVM_C_ABI void LLVMSetPrefixData(LLVMValueRef Fn, LLVMValueRef prefixData);
3292
3293/**
3294 * Gets the prologue data associated with a function. Only valid on functions,
3295 * and only if LLVMHasPrologueData returns true.
3296 * See https://llvm.org/docs/LangRef.html#prologue-data
3297 */
3298LLVM_C_ABI LLVMValueRef LLVMGetPrologueData(LLVMValueRef Fn);
3299
3300/**
3301 * Check if a given function has prologue data. Only valid on functions.
3302 * See https://llvm.org/docs/LangRef.html#prologue-data
3303 */
3304LLVM_C_ABI LLVMBool LLVMHasPrologueData(LLVMValueRef Fn);
3305
3306/**
3307 * Sets the prologue data for the function. Only valid on functions.
3308 * See https://llvm.org/docs/LangRef.html#prologue-data
3309 */
3310LLVM_C_ABI void LLVMSetPrologueData(LLVMValueRef Fn, LLVMValueRef prologueData);
3311
3312/**
3313 * Add an attribute to a function.
3314 *
3315 * @see llvm::Function::addAttribute()
3316 */
3317LLVM_C_ABI void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
3318 LLVMAttributeRef A);
3319LLVM_C_ABI unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F,
3320 LLVMAttributeIndex Idx);
3321LLVM_C_ABI void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
3322 LLVMAttributeRef *Attrs);
3323LLVM_C_ABI LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
3324 LLVMAttributeIndex Idx,
3325 unsigned KindID);
3326LLVM_C_ABI LLVMAttributeRef LLVMGetStringAttributeAtIndex(
3327 LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen);
3328LLVM_C_ABI void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F,
3329 LLVMAttributeIndex Idx,
3330 unsigned KindID);
3331LLVM_C_ABI void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F,
3332 LLVMAttributeIndex Idx,
3333 const char *K, unsigned KLen);
3334
3335/**
3336 * Add a target-dependent attribute to a function
3337 * @see llvm::AttrBuilder::addAttribute()
3338 */
3339LLVM_C_ABI void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn,
3340 const char *A,
3341 const char *V);
3342
3343/**
3344 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
3345 *
3346 * Functions in this group relate to arguments/parameters on functions.
3347 *
3348 * Functions in this group expect LLVMValueRef instances that correspond
3349 * to llvm::Function instances.
3350 *
3351 * @{
3352 */
3353
3354/**
3355 * Obtain the number of parameters in a function.
3356 *
3357 * @see llvm::Function::arg_size()
3358 */
3359LLVM_C_ABI unsigned LLVMCountParams(LLVMValueRef Fn);
3360
3361/**
3362 * Obtain the parameters in a function.
3363 *
3364 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
3365 * at least LLVMCountParams() long. This array will be filled with
3366 * LLVMValueRef instances which correspond to the parameters the
3367 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
3368 * instance.
3369 *
3370 * @see llvm::Function::arg_begin()
3371 */
3372LLVM_C_ABI void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
3373
3374/**
3375 * Obtain the parameter at the specified index.
3376 *
3377 * Parameters are indexed from 0.
3378 *
3379 * @see llvm::Function::arg_begin()
3380 */
3381LLVM_C_ABI LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
3382
3383/**
3384 * Obtain the function to which this argument belongs.
3385 *
3386 * Unlike other functions in this group, this one takes an LLVMValueRef
3387 * that corresponds to a llvm::Attribute.
3388 *
3389 * The returned LLVMValueRef is the llvm::Function to which this
3390 * argument belongs.
3391 */
3392LLVM_C_ABI LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
3393
3394/**
3395 * Obtain the first parameter to a function.
3396 *
3397 * @see llvm::Function::arg_begin()
3398 */
3399LLVM_C_ABI LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
3400
3401/**
3402 * Obtain the last parameter to a function.
3403 *
3404 * @see llvm::Function::arg_end()
3405 */
3406LLVM_C_ABI LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
3407
3408/**
3409 * Obtain the next parameter to a function.
3410 *
3411 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
3412 * actually a wrapped iterator) and obtains the next parameter from the
3413 * underlying iterator.
3414 */
3415LLVM_C_ABI LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
3416
3417/**
3418 * Obtain the previous parameter to a function.
3419 *
3420 * This is the opposite of LLVMGetNextParam().
3421 */
3422LLVM_C_ABI LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
3423
3424/**
3425 * Set the alignment for a function parameter.
3426 *
3427 * @see llvm::Argument::addAttr()
3428 * @see llvm::AttrBuilder::addAlignmentAttr()
3429 */
3430LLVM_C_ABI void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
3431
3432/**
3433 * @}
3434 */
3435
3436/**
3437 * @defgroup LLVMCCoreValueGlobalIFunc IFuncs
3438 *
3439 * Functions in this group relate to indirect functions.
3440 *
3441 * Functions in this group expect LLVMValueRef instances that correspond
3442 * to llvm::GlobalIFunc instances.
3443 *
3444 * @{
3445 */
3446
3447/**
3448 * Add a global indirect function to a module under a specified name.
3449 *
3450 * @see llvm::GlobalIFunc::create()
3451 */
3452LLVM_C_ABI LLVMValueRef LLVMAddGlobalIFunc(LLVMModuleRef M, const char *Name,
3453 size_t NameLen, LLVMTypeRef Ty,
3454 unsigned AddrSpace,
3455 LLVMValueRef Resolver);
3456
3457/**
3458 * Obtain a GlobalIFunc value from a Module by its name.
3459 *
3460 * The returned value corresponds to a llvm::GlobalIFunc value.
3461 *
3462 * @see llvm::Module::getNamedIFunc()
3463 */
3464LLVM_C_ABI LLVMValueRef LLVMGetNamedGlobalIFunc(LLVMModuleRef M,
3465 const char *Name,
3466 size_t NameLen);
3467
3468/**
3469 * Obtain an iterator to the first GlobalIFunc in a Module.
3470 *
3471 * @see llvm::Module::ifunc_begin()
3472 */
3473LLVM_C_ABI LLVMValueRef LLVMGetFirstGlobalIFunc(LLVMModuleRef M);
3474
3475/**
3476 * Obtain an iterator to the last GlobalIFunc in a Module.
3477 *
3478 * @see llvm::Module::ifunc_end()
3479 */
3480LLVM_C_ABI LLVMValueRef LLVMGetLastGlobalIFunc(LLVMModuleRef M);
3481
3482/**
3483 * Advance a GlobalIFunc iterator to the next GlobalIFunc.
3484 *
3485 * Returns NULL if the iterator was already at the end and there are no more
3486 * global aliases.
3487 */
3488LLVM_C_ABI LLVMValueRef LLVMGetNextGlobalIFunc(LLVMValueRef IFunc);
3489
3490/**
3491 * Decrement a GlobalIFunc iterator to the previous GlobalIFunc.
3492 *
3493 * Returns NULL if the iterator was already at the beginning and there are
3494 * no previous global aliases.
3495 */
3496LLVM_C_ABI LLVMValueRef LLVMGetPreviousGlobalIFunc(LLVMValueRef IFunc);
3497
3498/**
3499 * Retrieves the resolver function associated with this indirect function, or
3500 * NULL if it doesn't not exist.
3501 *
3502 * @see llvm::GlobalIFunc::getResolver()
3503 */
3504LLVM_C_ABI LLVMValueRef LLVMGetGlobalIFuncResolver(LLVMValueRef IFunc);
3505
3506/**
3507 * Sets the resolver function associated with this indirect function.
3508 *
3509 * @see llvm::GlobalIFunc::setResolver()
3510 */
3511LLVM_C_ABI void LLVMSetGlobalIFuncResolver(LLVMValueRef IFunc,
3512 LLVMValueRef Resolver);
3513
3514/**
3515 * Remove a global indirect function from its parent module and delete it.
3516 *
3517 * @see llvm::GlobalIFunc::eraseFromParent()
3518 */
3519LLVM_C_ABI void LLVMEraseGlobalIFunc(LLVMValueRef IFunc);
3520
3521/**
3522 * Remove a global indirect function from its parent module.
3523 *
3524 * This unlinks the global indirect function from its containing module but
3525 * keeps it alive.
3526 *
3527 * @see llvm::GlobalIFunc::removeFromParent()
3528 */
3529LLVM_C_ABI void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc);
3530
3531/**
3532 * @}
3533 */
3534
3535/**
3536 * @}
3537 */
3538
3539/**
3540 * @}
3541 */
3542
3543/**
3544 * @}
3545 */
3546
3547/**
3548 * @defgroup LLVMCCoreValueMetadata Metadata
3549 *
3550 * @{
3551 */
3552
3553/**
3554 * Create an MDString value from a given string value.
3555 *
3556 * The MDString value does not take ownership of the given string, it remains
3557 * the responsibility of the caller to free it.
3558 *
3559 * @see llvm::MDString::get()
3560 */
3561LLVM_C_ABI LLVMMetadataRef LLVMMDStringInContext2(LLVMContextRef C,
3562 const char *Str, size_t SLen);
3563
3564/**
3565 * Create an MDNode value with the given array of operands.
3566 *
3567 * @see llvm::MDNode::get()
3568 */
3569LLVM_C_ABI LLVMMetadataRef LLVMMDNodeInContext2(LLVMContextRef C,
3570 LLVMMetadataRef *MDs,
3571 size_t Count);
3572
3573/**
3574 * Obtain a Metadata as a Value.
3575 */
3576LLVM_C_ABI LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C,
3577 LLVMMetadataRef MD);
3578
3579/**
3580 * Obtain a Value as a Metadata.
3581 */
3582LLVM_C_ABI LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
3583
3584/**
3585 * Obtain the underlying string from a MDString value.
3586 *
3587 * @param V Instance to obtain string from.
3588 * @param Length Memory address which will hold length of returned string.
3589 * @return String data in MDString.
3590 */
3591LLVM_C_ABI const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
3592
3593/**
3594 * Obtain the number of operands from an MDNode value.
3595 *
3596 * @param V MDNode to get number of operands from.
3597 * @return Number of operands of the MDNode.
3598 */
3599LLVM_C_ABI unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
3600
3601/**
3602 * Obtain the given MDNode's operands.
3603 *
3604 * The passed LLVMValueRef pointer should point to enough memory to hold all of
3605 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
3606 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
3607 * MDNode's operands.
3608 *
3609 * @param V MDNode to get the operands from.
3610 * @param Dest Destination array for operands.
3611 */
3612LLVM_C_ABI void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
3613
3614/**
3615 * Replace an operand at a specific index in a llvm::MDNode value.
3616 *
3617 * @see llvm::MDNode::replaceOperandWith()
3618 */
3619LLVM_C_ABI void LLVMReplaceMDNodeOperandWith(LLVMValueRef V, unsigned Index,
3620 LLVMMetadataRef Replacement);
3621
3622/** Deprecated: Use LLVMMDStringInContext2 instead. */
3623LLVM_C_ABI LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
3624 unsigned SLen);
3625/** Deprecated: Use LLVMMDStringInContext2 instead. */
3626LLVM_C_ABI LLVM_ATTRIBUTE_C_DEPRECATED(
3627 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen),
3628 "Use of the global context is deprecated, use LLVMMDStringInContext2 "
3629 "instead");
3630/** Deprecated: Use LLVMMDNodeInContext2 instead. */
3631LLVM_C_ABI LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C,
3632 LLVMValueRef *Vals, unsigned Count);
3633/** Deprecated: Use LLVMMDNodeInContext2 instead. */
3634LLVM_C_ABI LLVM_ATTRIBUTE_C_DEPRECATED(
3635 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count),
3636 "Use of the global context is deprecated, use LLVMMDNodeInContext2 "
3637 "instead");
3638
3639/**
3640 * @}
3641 */
3642
3643/**
3644 * @defgroup LLVMCCoreOperandBundle Operand Bundles
3645 *
3646 * Functions in this group operate on LLVMOperandBundleRef instances that
3647 * correspond to llvm::OperandBundleDef instances.
3648 *
3649 * @see llvm::OperandBundleDef
3650 *
3651 * @{
3652 */
3653
3654/**
3655 * Create a new operand bundle.
3656 *
3657 * Every invocation should be paired with LLVMDisposeOperandBundle() or memory
3658 * will be leaked.
3659 *
3660 * @param Tag Tag name of the operand bundle
3661 * @param TagLen Length of Tag
3662 * @param Args Memory address of an array of bundle operands
3663 * @param NumArgs Length of Args
3664 */
3665LLVM_C_ABI LLVMOperandBundleRef LLVMCreateOperandBundle(const char *Tag,
3666 size_t TagLen,
3667 LLVMValueRef *Args,
3668 unsigned NumArgs);
3669
3670/**
3671 * Destroy an operand bundle.
3672 *
3673 * This must be called for every created operand bundle or memory will be
3674 * leaked.
3675 */
3676LLVM_C_ABI void LLVMDisposeOperandBundle(LLVMOperandBundleRef Bundle);
3677
3678/**
3679 * Obtain the tag of an operand bundle as a string.
3680 *
3681 * @param Bundle Operand bundle to obtain tag of.
3682 * @param Len Out parameter which holds the length of the returned string.
3683 * @return The tag name of Bundle.
3684 * @see OperandBundleDef::getTag()
3685 */
3686LLVM_C_ABI const char *LLVMGetOperandBundleTag(LLVMOperandBundleRef Bundle,
3687 size_t *Len);
3688
3689/**
3690 * Obtain the number of operands for an operand bundle.
3691 *
3692 * @param Bundle Operand bundle to obtain operand count of.
3693 * @return The number of operands.
3694 * @see OperandBundleDef::input_size()
3695 */
3696LLVM_C_ABI unsigned LLVMGetNumOperandBundleArgs(LLVMOperandBundleRef Bundle);
3697
3698/**
3699 * Obtain the operand for an operand bundle at the given index.
3700 *
3701 * @param Bundle Operand bundle to obtain operand of.
3702 * @param Index An operand index, must be less than
3703 * LLVMGetNumOperandBundleArgs().
3704 * @return The operand.
3705 */
3706LLVM_C_ABI LLVMValueRef
3707LLVMGetOperandBundleArgAtIndex(LLVMOperandBundleRef Bundle, unsigned Index);
3708
3709/**
3710 * @}
3711 */
3712
3713/**
3714 * @defgroup LLVMCCoreValueBasicBlock Basic Block
3715 *
3716 * A basic block represents a single entry single exit section of code.
3717 * Basic blocks contain a list of instructions which form the body of
3718 * the block.
3719 *
3720 * Basic blocks belong to functions. They have the type of label.
3721 *
3722 * Basic blocks are themselves values. However, the C API models them as
3723 * LLVMBasicBlockRef.
3724 *
3725 * @see llvm::BasicBlock
3726 *
3727 * @{
3728 */
3729
3730/**
3731 * Convert a basic block instance to a value type.
3732 */
3733LLVM_C_ABI LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
3734
3735/**
3736 * Determine whether an LLVMValueRef is itself a basic block.
3737 */
3738LLVM_C_ABI LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
3739
3740/**
3741 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
3742 */
3743LLVM_C_ABI LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
3744
3745/**
3746 * Obtain the string name of a basic block.
3747 */
3748LLVM_C_ABI const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
3749
3750/**
3751 * Obtain the function to which a basic block belongs.
3752 *
3753 * @see llvm::BasicBlock::getParent()
3754 */
3755LLVM_C_ABI LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
3756
3757/**
3758 * Obtain the terminator instruction for a basic block.
3759 *
3760 * If the basic block does not have a terminator (it is not well-formed
3761 * if it doesn't), then NULL is returned.
3762 *
3763 * The returned LLVMValueRef corresponds to an llvm::Instruction.
3764 *
3765 * @see llvm::BasicBlock::getTerminator()
3766 */
3767LLVM_C_ABI LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
3768
3769/**
3770 * Obtain the number of basic blocks in a function.
3771 *
3772 * @param Fn Function value to operate on.
3773 */
3774LLVM_C_ABI unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
3775
3776/**
3777 * Obtain all of the basic blocks in a function.
3778 *
3779 * This operates on a function value. The BasicBlocks parameter is a
3780 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
3781 * LLVMCountBasicBlocks() in length. This array is populated with
3782 * LLVMBasicBlockRef instances.
3783 */
3784LLVM_C_ABI void LLVMGetBasicBlocks(LLVMValueRef Fn,
3785 LLVMBasicBlockRef *BasicBlocks);
3786
3787/**
3788 * Obtain the first basic block in a function.
3789 *
3790 * The returned basic block can be used as an iterator. You will likely
3791 * eventually call into LLVMGetNextBasicBlock() with it.
3792 *
3793 * @see llvm::Function::begin()
3794 */
3795LLVM_C_ABI LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
3796
3797/**
3798 * Obtain the last basic block in a function.
3799 *
3800 * @see llvm::Function::end()
3801 */
3802LLVM_C_ABI LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
3803
3804/**
3805 * Advance a basic block iterator.
3806 */
3807LLVM_C_ABI LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
3808
3809/**
3810 * Go backwards in a basic block iterator.
3811 */
3812LLVM_C_ABI LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
3813
3814/**
3815 * Obtain the basic block that corresponds to the entry point of a
3816 * function.
3817 *
3818 * @see llvm::Function::getEntryBlock()
3819 */
3820LLVM_C_ABI LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
3821
3822/**
3823 * Insert the given basic block after the insertion point of the given builder.
3824 *
3825 * The insertion point must be valid.
3826 *
3827 * @see llvm::Function::BasicBlockListType::insertAfter()
3828 */
3829LLVM_C_ABI void
3830LLVMInsertExistingBasicBlockAfterInsertBlock(LLVMBuilderRef Builder,
3831 LLVMBasicBlockRef BB);
3832
3833/**
3834 * Append the given basic block to the basic block list of the given function.
3835 *
3836 * @see llvm::Function::BasicBlockListType::push_back()
3837 */
3838LLVM_C_ABI void LLVMAppendExistingBasicBlock(LLVMValueRef Fn,
3839 LLVMBasicBlockRef BB);
3840
3841/**
3842 * Create a new basic block without inserting it into a function.
3843 *
3844 * @see llvm::BasicBlock::Create()
3845 */
3846LLVM_C_ABI LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C,
3847 const char *Name);
3848
3849/**
3850 * Append a basic block to the end of a function.
3851 *
3852 * @see llvm::BasicBlock::Create()
3853 */
3854LLVM_C_ABI LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
3855 LLVMValueRef Fn,
3856 const char *Name);
3857
3858/**
3859 * Append a basic block to the end of a function using the global
3860 * context.
3861 *
3862 * @see llvm::BasicBlock::Create()
3863 */
3864LLVM_C_ABI LLVM_ATTRIBUTE_C_DEPRECATED(
3865 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name),
3866 "Use of the global context is deprecated, use "
3867 "LLVMAppendBasicBlockInContext instead");
3868
3869/**
3870 * Insert a basic block in a function before another basic block.
3871 *
3872 * The function to add to is determined by the function of the
3873 * passed basic block.
3874 *
3875 * @see llvm::BasicBlock::Create()
3876 */
3877LLVM_C_ABI LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
3878 LLVMBasicBlockRef BB,
3879 const char *Name);
3880
3881/**
3882 * Insert a basic block in a function using the global context.
3883 *
3884 * @see llvm::BasicBlock::Create()
3885 */
3886LLVM_C_ABI LLVM_ATTRIBUTE_C_DEPRECATED(
3887 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
3888 const char *Name),
3889 "Use of the global context is deprecated, use "
3890 "LLVMInsertBasicBlockInContext instead");
3891
3892/**
3893 * Remove a basic block from a function and delete it.
3894 *
3895 * This deletes the basic block from its containing function and deletes
3896 * the basic block itself.
3897 *
3898 * @see llvm::BasicBlock::eraseFromParent()
3899 */
3900LLVM_C_ABI void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
3901
3902/**
3903 * Remove a basic block from a function.
3904 *
3905 * This deletes the basic block from its containing function but keep
3906 * the basic block alive.
3907 *
3908 * @see llvm::BasicBlock::removeFromParent()
3909 */
3910LLVM_C_ABI void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
3911
3912/**
3913 * Move a basic block to before another one.
3914 *
3915 * @see llvm::BasicBlock::moveBefore()
3916 */
3917LLVM_C_ABI void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB,
3918 LLVMBasicBlockRef MovePos);
3919
3920/**
3921 * Move a basic block to after another one.
3922 *
3923 * @see llvm::BasicBlock::moveAfter()
3924 */
3925LLVM_C_ABI void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB,
3926 LLVMBasicBlockRef MovePos);
3927
3928/**
3929 * Obtain the first instruction in a basic block.
3930 *
3931 * The returned LLVMValueRef corresponds to a llvm::Instruction
3932 * instance.
3933 */
3934LLVM_C_ABI LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
3935
3936/**
3937 * Obtain the last instruction in a basic block.
3938 *
3939 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
3940 */
3941LLVM_C_ABI LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
3942
3943/**
3944 * @}
3945 */
3946
3947/**
3948 * @defgroup LLVMCCoreValueInstruction Instructions
3949 *
3950 * Functions in this group relate to the inspection and manipulation of
3951 * individual instructions.
3952 *
3953 * In the C++ API, an instruction is modeled by llvm::Instruction. This
3954 * class has a large number of descendents. llvm::Instruction is a
3955 * llvm::Value and in the C API, instructions are modeled by
3956 * LLVMValueRef.
3957 *
3958 * This group also contains sub-groups which operate on specific
3959 * llvm::Instruction types, e.g. llvm::CallInst.
3960 *
3961 * @{
3962 */
3963
3964/**
3965 * Determine whether an instruction has any metadata attached.
3966 */
3967LLVM_C_ABI int LLVMHasMetadata(LLVMValueRef Val);
3968
3969/**
3970 * Return metadata associated with an instruction value.
3971 */
3972LLVM_C_ABI LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
3973
3974/**
3975 * Set metadata associated with an instruction value.
3976 */
3977LLVM_C_ABI void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID,
3978 LLVMValueRef Node);
3979
3980/**
3981 * Returns the metadata associated with an instruction value, but filters out
3982 * all the debug locations.
3983 *
3984 * @see llvm::Instruction::getAllMetadataOtherThanDebugLoc()
3985 */
3986LLVM_C_ABI LLVMValueMetadataEntry *
3987LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Instr,
3988 size_t *NumEntries);
3989
3990/**
3991 * Obtain the basic block to which an instruction belongs.
3992 *
3993 * @see llvm::Instruction::getParent()
3994 */
3995LLVM_C_ABI LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
3996
3997/**
3998 * Obtain the instruction that occurs after the one specified.
3999 *
4000 * The next instruction will be from the same basic block.
4001 *
4002 * If this is the last instruction in a basic block, NULL will be
4003 * returned.
4004 */
4005LLVM_C_ABI LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
4006
4007/**
4008 * Obtain the instruction that occurred before this one.
4009 *
4010 * If the instruction is the first instruction in a basic block, NULL
4011 * will be returned.
4012 */
4013LLVM_C_ABI LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
4014
4015/**
4016 * Remove an instruction.
4017 *
4018 * The instruction specified is removed from its containing building
4019 * block but is kept alive.
4020 *
4021 * @see llvm::Instruction::removeFromParent()
4022 */
4023LLVM_C_ABI void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
4024
4025/**
4026 * Remove and delete an instruction.
4027 *
4028 * The instruction specified is removed from its containing building
4029 * block and then deleted.
4030 *
4031 * @see llvm::Instruction::eraseFromParent()
4032 */
4033LLVM_C_ABI void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
4034
4035/**
4036 * Delete an instruction.
4037 *
4038 * The instruction specified is deleted. It must have previously been
4039 * removed from its containing building block.
4040 *
4041 * @see llvm::Value::deleteValue()
4042 */
4043LLVM_C_ABI void LLVMDeleteInstruction(LLVMValueRef Inst);
4044
4045/**
4046 * Obtain the code opcode for an individual instruction.
4047 *
4048 * @see llvm::Instruction::getOpCode()
4049 */
4050LLVM_C_ABI LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
4051
4052/**
4053 * Obtain the predicate of an instruction.
4054 *
4055 * This is only valid for instructions that correspond to llvm::ICmpInst.
4056 *
4057 * @see llvm::ICmpInst::getPredicate()
4058 */
4059LLVM_C_ABI LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
4060
4061/**
4062 * Get whether or not an icmp instruction has the samesign flag.
4063 *
4064 * This is only valid for instructions that correspond to llvm::ICmpInst.
4065 *
4066 * @see llvm::ICmpInst::hasSameSign()
4067 */
4068LLVM_C_ABI LLVMBool LLVMGetICmpSameSign(LLVMValueRef Inst);
4069
4070/**
4071 * Set the samesign flag on an icmp instruction.
4072 *
4073 * This is only valid for instructions that correspond to llvm::ICmpInst.
4074 *
4075 * @see llvm::ICmpInst::setSameSign()
4076 */
4077LLVM_C_ABI void LLVMSetICmpSameSign(LLVMValueRef Inst, LLVMBool SameSign);
4078
4079/**
4080 * Obtain the float predicate of an instruction.
4081 *
4082 * This is only valid for instructions that correspond to llvm::FCmpInst.
4083 *
4084 * @see llvm::FCmpInst::getPredicate()
4085 */
4086LLVM_C_ABI LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
4087
4088/**
4089 * Create a copy of 'this' instruction that is identical in all ways
4090 * except the following:
4091 * * The instruction has no parent
4092 * * The instruction has no name
4093 *
4094 * @see llvm::Instruction::clone()
4095 */
4096LLVM_C_ABI LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
4097
4098/**
4099 * Determine whether an instruction is a terminator. This routine is named to
4100 * be compatible with historical functions that did this by querying the
4101 * underlying C++ type.
4102 *
4103 * @see llvm::Instruction::isTerminator()
4104 */
4105LLVM_C_ABI LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst);
4106
4107/**
4108 * Obtain the first debug record attached to an instruction.
4109 *
4110 * Use LLVMGetNextDbgRecord() and LLVMGetPreviousDbgRecord() to traverse the
4111 * sequence of DbgRecords.
4112 *
4113 * Return the first DbgRecord attached to Inst or NULL if there are none.
4114 *
4115 * @see llvm::Instruction::getDbgRecordRange()
4116 */
4117LLVM_C_ABI LLVMDbgRecordRef LLVMGetFirstDbgRecord(LLVMValueRef Inst);
4118
4119/**
4120 * Obtain the last debug record attached to an instruction.
4121 *
4122 * Return the last DbgRecord attached to Inst or NULL if there are none.
4123 *
4124 * @see llvm::Instruction::getDbgRecordRange()
4125 */
4126LLVM_C_ABI LLVMDbgRecordRef LLVMGetLastDbgRecord(LLVMValueRef Inst);
4127
4128/**
4129 * Obtain the next DbgRecord in the sequence or NULL if there are no more.
4130 *
4131 * @see llvm::Instruction::getDbgRecordRange()
4132 */
4133LLVM_C_ABI LLVMDbgRecordRef LLVMGetNextDbgRecord(LLVMDbgRecordRef DbgRecord);
4134
4135/**
4136 * Obtain the previous DbgRecord in the sequence or NULL if there are no more.
4137 *
4138 * @see llvm::Instruction::getDbgRecordRange()
4139 */
4140LLVM_C_ABI LLVMDbgRecordRef
4141LLVMGetPreviousDbgRecord(LLVMDbgRecordRef DbgRecord);
4142
4143/**
4144 * Get the debug location attached to the debug record.
4145 *
4146 * @see llvm::DbgRecord::getDebugLoc()
4147 */
4148LLVM_C_ABI LLVMMetadataRef LLVMDbgRecordGetDebugLoc(LLVMDbgRecordRef Rec);
4149
4150LLVM_C_ABI LLVMDbgRecordKind LLVMDbgRecordGetKind(LLVMDbgRecordRef Rec);
4151
4152/**
4153 * Get the value of the DbgVariableRecord.
4154 *
4155 * @see llvm::DbgVariableRecord::getValue()
4156 */
4157LLVM_C_ABI LLVMValueRef LLVMDbgVariableRecordGetValue(LLVMDbgRecordRef Rec,
4158 unsigned OpIdx);
4159
4160/**
4161 * Get the debug info variable of the DbgVariableRecord.
4162 *
4163 * @see llvm::DbgVariableRecord::getVariable()
4164 */
4165LLVM_C_ABI LLVMMetadataRef
4166LLVMDbgVariableRecordGetVariable(LLVMDbgRecordRef Rec);
4167
4168/**
4169 * Get the debug info expression of the DbgVariableRecord.
4170 *
4171 * @see llvm::DbgVariableRecord::getExpression()
4172 */
4173LLVM_C_ABI LLVMMetadataRef
4174LLVMDbgVariableRecordGetExpression(LLVMDbgRecordRef Rec);
4175
4176/**
4177 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
4178 *
4179 * Functions in this group apply to instructions that refer to call
4180 * sites and invocations. These correspond to C++ types in the
4181 * llvm::CallInst class tree.
4182 *
4183 * @{
4184 */
4185
4186/**
4187 * Obtain the argument count for a call instruction.
4188 *
4189 * This expects an LLVMValueRef that corresponds to a llvm::CallInst,
4190 * llvm::InvokeInst, or llvm:FuncletPadInst.
4191 *
4192 * @see llvm::CallInst::getNumArgOperands()
4193 * @see llvm::InvokeInst::getNumArgOperands()
4194 * @see llvm::FuncletPadInst::getNumArgOperands()
4195 */
4196LLVM_C_ABI unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
4197
4198/**
4199 * Set the calling convention for a call instruction.
4200 *
4201 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
4202 * llvm::InvokeInst.
4203 *
4204 * @see llvm::CallInst::setCallingConv()
4205 * @see llvm::InvokeInst::setCallingConv()
4206 */
4207LLVM_C_ABI void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
4208
4209/**
4210 * Obtain the calling convention for a call instruction.
4211 *
4212 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
4213 * usage.
4214 *
4215 * @see LLVMSetInstructionCallConv()
4216 */
4217LLVM_C_ABI unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
4218
4219LLVM_C_ABI void LLVMSetInstrParamAlignment(LLVMValueRef Instr,
4220 LLVMAttributeIndex Idx,
4221 unsigned Align);
4222
4223LLVM_C_ABI void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
4224 LLVMAttributeRef A);
4225LLVM_C_ABI unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C,
4226 LLVMAttributeIndex Idx);
4227LLVM_C_ABI void LLVMGetCallSiteAttributes(LLVMValueRef C,
4228 LLVMAttributeIndex Idx,
4229 LLVMAttributeRef *Attrs);
4230LLVM_C_ABI LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
4231 LLVMAttributeIndex Idx,
4232 unsigned KindID);
4233LLVM_C_ABI LLVMAttributeRef LLVMGetCallSiteStringAttribute(
4234 LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen);
4235LLVM_C_ABI void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C,
4236 LLVMAttributeIndex Idx,
4237 unsigned KindID);
4238LLVM_C_ABI void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C,
4239 LLVMAttributeIndex Idx,
4240 const char *K, unsigned KLen);
4241
4242/**
4243 * Obtain the function type called by this instruction.
4244 *
4245 * @see llvm::CallBase::getFunctionType()
4246 */
4247LLVM_C_ABI LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef C);
4248
4249/**
4250 * Obtain the pointer to the function invoked by this instruction.
4251 *
4252 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
4253 * llvm::InvokeInst.
4254 *
4255 * @see llvm::CallInst::getCalledOperand()
4256 * @see llvm::InvokeInst::getCalledOperand()
4257 */
4258LLVM_C_ABI LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
4259
4260/**
4261 * Obtain the number of operand bundles attached to this instruction.
4262 *
4263 * This only works on llvm::CallInst and llvm::InvokeInst instructions.
4264 *
4265 * @see llvm::CallBase::getNumOperandBundles()
4266 */
4267LLVM_C_ABI unsigned LLVMGetNumOperandBundles(LLVMValueRef C);
4268
4269/**
4270 * Obtain the operand bundle attached to this instruction at the given index.
4271 * Use LLVMDisposeOperandBundle to free the operand bundle.
4272 *
4273 * This only works on llvm::CallInst and llvm::InvokeInst instructions.
4274 */
4275LLVM_C_ABI LLVMOperandBundleRef LLVMGetOperandBundleAtIndex(LLVMValueRef C,
4276 unsigned Index);
4277
4278/**
4279 * Obtain whether a call instruction is a tail call.
4280 *
4281 * This only works on llvm::CallInst instructions.
4282 *
4283 * @see llvm::CallInst::isTailCall()
4284 */
4285LLVM_C_ABI LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
4286
4287/**
4288 * Set whether a call instruction is a tail call.
4289 *
4290 * This only works on llvm::CallInst instructions.
4291 *
4292 * @see llvm::CallInst::setTailCall()
4293 */
4294LLVM_C_ABI void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
4295
4296/**
4297 * Obtain a tail call kind of the call instruction.
4298 *
4299 * @see llvm::CallInst::setTailCallKind()
4300 */
4301LLVM_C_ABI LLVMTailCallKind LLVMGetTailCallKind(LLVMValueRef CallInst);
4302
4303/**
4304 * Set the call kind of the call instruction.
4305 *
4306 * @see llvm::CallInst::getTailCallKind()
4307 */
4308LLVM_C_ABI void LLVMSetTailCallKind(LLVMValueRef CallInst,
4309 LLVMTailCallKind kind);
4310
4311/**
4312 * Return the normal destination basic block.
4313 *
4314 * This only works on llvm::InvokeInst instructions.
4315 *
4316 * @see llvm::InvokeInst::getNormalDest()
4317 */
4318LLVM_C_ABI LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
4319
4320/**
4321 * Return the unwind destination basic block.
4322 *
4323 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
4324 * llvm::CatchSwitchInst instructions.
4325 *
4326 * @see llvm::InvokeInst::getUnwindDest()
4327 * @see llvm::CleanupReturnInst::getUnwindDest()
4328 * @see llvm::CatchSwitchInst::getUnwindDest()
4329 */
4330LLVM_C_ABI LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
4331
4332/**
4333 * Set the normal destination basic block.
4334 *
4335 * This only works on llvm::InvokeInst instructions.
4336 *
4337 * @see llvm::InvokeInst::setNormalDest()
4338 */
4339LLVM_C_ABI void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
4340
4341/**
4342 * Set the unwind destination basic block.
4343 *
4344 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
4345 * llvm::CatchSwitchInst instructions.
4346 *
4347 * @see llvm::InvokeInst::setUnwindDest()
4348 * @see llvm::CleanupReturnInst::setUnwindDest()
4349 * @see llvm::CatchSwitchInst::setUnwindDest()
4350 */
4351LLVM_C_ABI void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
4352
4353/**
4354 * Get the default destination of a CallBr instruction.
4355 *
4356 * @see llvm::CallBrInst::getDefaultDest()
4357 */
4358LLVM_C_ABI LLVMBasicBlockRef LLVMGetCallBrDefaultDest(LLVMValueRef CallBr);
4359
4360/**
4361 * Get the number of indirect destinations of a CallBr instruction.
4362 *
4363 * @see llvm::CallBrInst::getNumIndirectDests()
4364
4365 */
4366LLVM_C_ABI unsigned LLVMGetCallBrNumIndirectDests(LLVMValueRef CallBr);
4367
4368/**
4369 * Get the indirect destination of a CallBr instruction at the given index.
4370 *
4371 * @see llvm::CallBrInst::getIndirectDest()
4372 */
4373LLVM_C_ABI LLVMBasicBlockRef LLVMGetCallBrIndirectDest(LLVMValueRef CallBr,
4374 unsigned Idx);
4375
4376/**
4377 * @}
4378 */
4379
4380/**
4381 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
4382 *
4383 * Functions in this group only apply to instructions for which
4384 * LLVMIsATerminatorInst returns true.
4385 *
4386 * @{
4387 */
4388
4389/**
4390 * Return the number of successors that this terminator has.
4391 *
4392 * @see llvm::Instruction::getNumSuccessors
4393 */
4394LLVM_C_ABI unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
4395
4396/**
4397 * Return the specified successor.
4398 *
4399 * @see llvm::Instruction::getSuccessor
4400 */
4401LLVM_C_ABI LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
4402
4403/**
4404 * Update the specified successor to point at the provided block.
4405 *
4406 * @see llvm::Instruction::setSuccessor
4407 */
4408LLVM_C_ABI void LLVMSetSuccessor(LLVMValueRef Term, unsigned i,
4409 LLVMBasicBlockRef block);
4410
4411/**
4412 * Return if an instruction is a conditional branch.
4413 *
4414 * Deprecated: Use LLVMIsACondBrInst instead.
4415 */
4416LLVM_C_ABI LLVMBool LLVMIsConditional(LLVMValueRef Branch);
4417
4418/**
4419 * Return the condition of a branch instruction.
4420 *
4421 * This only works on llvm::CondBrInst instructions.
4422 *
4423 * @see llvm::CondBrInst::getCondition
4424 */
4425LLVM_C_ABI LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
4426
4427/**
4428 * Set the condition of a branch instruction.
4429 *
4430 * This only works on llvm::CondBrInst instructions.
4431 *
4432 * @see llvm::CondBrInst::setCondition
4433 */
4434LLVM_C_ABI void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
4435
4436/**
4437 * Obtain the default destination basic block of a switch instruction.
4438 *
4439 * This only works on llvm::SwitchInst instructions.
4440 *
4441 * @see llvm::SwitchInst::getDefaultDest()
4442 */
4443LLVM_C_ABI LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
4444
4445/**
4446 * Obtain the case value for a successor of a switch instruction. i corresponds
4447 * to the successor index. The first successor is the default destination, so i
4448 * must be greater than zero.
4449 *
4450 * This only works on llvm::SwitchInst instructions.
4451 *
4452 * @see llvm::SwitchInst::CaseHandle::getCaseValue()
4453 */
4454LLVM_C_ABI LLVMValueRef LLVMGetSwitchCaseValue(LLVMValueRef SwitchInstr,
4455 unsigned i);
4456
4457/**
4458 * Set the case value for a successor of a switch instruction. i corresponds to
4459 * the successor index. The first successor is the default destination, so i
4460 * must be greater than zero.
4461 *
4462 * This only works on llvm::SwitchInst instructions.
4463 *
4464 * @see llvm::SwitchInst::CaseHandle::setValue()
4465 */
4466LLVM_C_ABI void LLVMSetSwitchCaseValue(LLVMValueRef SwitchInstr, unsigned i,
4467 LLVMValueRef CaseValue);
4468
4469/**
4470 * @}
4471 */
4472
4473/**
4474 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
4475 *
4476 * Functions in this group only apply to instructions that map to
4477 * llvm::AllocaInst instances.
4478 *
4479 * @{
4480 */
4481
4482/**
4483 * Obtain the type that is being allocated by the alloca instruction.
4484 */
4485LLVM_C_ABI LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
4486
4487/**
4488 * @}
4489 */
4490
4491/**
4492 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
4493 *
4494 * Functions in this group only apply to instructions that map to
4495 * llvm::GetElementPtrInst instances.
4496 *
4497 * @{
4498 */
4499
4500/**
4501 * Check whether the given GEP operator is inbounds.
4502 */
4503LLVM_C_ABI LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
4504
4505/**
4506 * Set the given GEP instruction to be inbounds or not.
4507 */
4508LLVM_C_ABI void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
4509
4510/**
4511 * Get the source element type of the given GEP operator.
4512 */
4513LLVM_C_ABI LLVMTypeRef LLVMGetGEPSourceElementType(LLVMValueRef GEP);
4514
4515/**
4516 * Get the no-wrap related flags for the given GEP instruction.
4517 *
4518 * @see llvm::GetElementPtrInst::getNoWrapFlags
4519 */
4520LLVM_C_ABI LLVMGEPNoWrapFlags LLVMGEPGetNoWrapFlags(LLVMValueRef GEP);
4521
4522/**
4523 * Set the no-wrap related flags for the given GEP instruction.
4524 *
4525 * @see llvm::GetElementPtrInst::setNoWrapFlags
4526 */
4527LLVM_C_ABI void LLVMGEPSetNoWrapFlags(LLVMValueRef GEP,
4528 LLVMGEPNoWrapFlags NoWrapFlags);
4529
4530/**
4531 * @}
4532 */
4533
4534/**
4535 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
4536 *
4537 * Functions in this group only apply to instructions that map to
4538 * llvm::PHINode instances.
4539 *
4540 * @{
4541 */
4542
4543/**
4544 * Add an incoming value to the end of a PHI list.
4545 */
4546LLVM_C_ABI void LLVMAddIncoming(LLVMValueRef PhiNode,
4547 LLVMValueRef *IncomingValues,
4548 LLVMBasicBlockRef *IncomingBlocks,
4549 unsigned Count);
4550
4551/**
4552 * Obtain the number of incoming basic blocks to a PHI node.
4553 */
4554LLVM_C_ABI unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
4555
4556/**
4557 * Obtain an incoming value to a PHI node as an LLVMValueRef.
4558 */
4559LLVM_C_ABI LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode,
4560 unsigned Index);
4561
4562/**
4563 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
4564 */
4565LLVM_C_ABI LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode,
4566 unsigned Index);
4567
4568/**
4569 * @}
4570 */
4571
4572/**
4573 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
4574 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
4575 *
4576 * Functions in this group only apply to instructions that map to
4577 * llvm::ExtractValue and llvm::InsertValue instances.
4578 *
4579 * @{
4580 */
4581
4582/**
4583 * Obtain the number of indices.
4584 * NB: This also works on GEP operators.
4585 */
4586LLVM_C_ABI unsigned LLVMGetNumIndices(LLVMValueRef Inst);
4587
4588/**
4589 * Obtain the indices as an array.
4590 */
4591LLVM_C_ABI const unsigned *LLVMGetIndices(LLVMValueRef Inst);
4592
4593/**
4594 * @}
4595 */
4596
4597/**
4598 * @}
4599 */
4600
4601/**
4602 * @}
4603 */
4604
4605/**
4606 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
4607 *
4608 * An instruction builder represents a point within a basic block and is
4609 * the exclusive means of building instructions using the C interface.
4610 *
4611 * @{
4612 */
4613
4614LLVM_C_ABI LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
4615LLVM_C_ABI
4616LLVM_ATTRIBUTE_C_DEPRECATED(LLVMBuilderRef LLVMCreateBuilder(void),
4617 "Use of the global context is deprecated, use "
4618 "LLVMCreateBuilderInContext instead");
4619/**
4620 * Set the builder position before Instr but after any attached debug records,
4621 * or if Instr is null set the position to the end of Block.
4622 */
4623LLVM_C_ABI void LLVMPositionBuilder(LLVMBuilderRef Builder,
4624 LLVMBasicBlockRef Block,
4625 LLVMValueRef Instr);
4626/**
4627 * Set the builder position before Instr and any attached debug records,
4628 * or if Instr is null set the position to the end of Block.
4629 */
4630LLVM_C_ABI void LLVMPositionBuilderBeforeDbgRecords(LLVMBuilderRef Builder,
4631 LLVMBasicBlockRef Block,
4632 LLVMValueRef Inst);
4633/**
4634 * Set the builder position before Instr but after any attached debug records.
4635 */
4636LLVM_C_ABI void LLVMPositionBuilderBefore(LLVMBuilderRef Builder,
4637 LLVMValueRef Instr);
4638/**
4639 * Set the builder position before Instr and any attached debug records.
4640 */
4641LLVM_C_ABI void
4642LLVMPositionBuilderBeforeInstrAndDbgRecords(LLVMBuilderRef Builder,
4643 LLVMValueRef Instr);
4644LLVM_C_ABI void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder,
4645 LLVMBasicBlockRef Block);
4646LLVM_C_ABI LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
4647LLVM_C_ABI void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
4648LLVM_C_ABI void LLVMInsertIntoBuilder(LLVMBuilderRef Builder,
4649 LLVMValueRef Instr);
4650LLVM_C_ABI void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder,
4651 LLVMValueRef Instr,
4652 const char *Name);
4653LLVM_C_ABI void LLVMDisposeBuilder(LLVMBuilderRef Builder);
4654
4655/* Metadata */
4656
4657/**
4658 * Get location information used by debugging information.
4659 *
4660 * @see llvm::IRBuilder::getCurrentDebugLocation()
4661 */
4662LLVM_C_ABI LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder);
4663
4664/**
4665 * Set location information used by debugging information.
4666 *
4667 * To clear the location metadata of the given instruction, pass NULL to \p Loc.
4668 *
4669 * @see llvm::IRBuilder::SetCurrentDebugLocation()
4670 */
4671LLVM_C_ABI void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder,
4672 LLVMMetadataRef Loc);
4673
4674/**
4675 * Attempts to set the debug location for the given instruction using the
4676 * current debug location for the given builder. If the builder has no current
4677 * debug location, this function is a no-op.
4678 *
4679 * @see llvm::IRBuilder::SetInstDebugLocation()
4680 */
4681LLVM_C_ABI void LLVMSetInstDebugLocation(LLVMBuilderRef Builder,
4682 LLVMValueRef Inst);
4683
4684/**
4685 * Same as LLVMSetInstDebugLocation.
4686 *
4687 * @deprecated Use the identical LLVMSetInstDebugLocation.
4688 *
4689 * @see llvm::IRBuilder::SetInstDebugLocation()
4690 */
4691LLVM_C_ABI void LLVMAddMetadataToInst(LLVMBuilderRef Builder,
4692 LLVMValueRef Inst);
4693
4694/**
4695 * Get the dafult floating-point math metadata for a given builder.
4696 *
4697 * @see llvm::IRBuilder::getDefaultFPMathTag()
4698 */
4699LLVM_C_ABI LLVMMetadataRef
4700LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder);
4701
4702/**
4703 * Set the default floating-point math metadata for the given builder.
4704 *
4705 * To clear the metadata, pass NULL to \p FPMathTag.
4706 *
4707 * @see llvm::IRBuilder::setDefaultFPMathTag()
4708 */
4709LLVM_C_ABI void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
4710 LLVMMetadataRef FPMathTag);
4711
4712/**
4713 * Obtain the context to which this builder is associated.
4714 *
4715 * @see llvm::IRBuilder::getContext()
4716 */
4717LLVM_C_ABI LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef Builder);
4718
4719/**
4720 * Deprecated: Passing the NULL location will crash.
4721 * Use LLVMGetCurrentDebugLocation2 instead.
4722 */
4723LLVM_C_ABI void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder,
4724 LLVMValueRef L);
4725/**
4726 * Deprecated: Returning the NULL location will crash.
4727 * Use LLVMGetCurrentDebugLocation2 instead.
4728 */
4729LLVM_C_ABI LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
4730
4731/* Terminators */
4732LLVM_C_ABI LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
4733LLVM_C_ABI LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
4734LLVM_C_ABI LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef,
4735 LLVMValueRef *RetVals,
4736 unsigned N);
4737LLVM_C_ABI LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
4738LLVM_C_ABI LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
4739 LLVMBasicBlockRef Then,
4740 LLVMBasicBlockRef Else);
4741LLVM_C_ABI LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
4742 LLVMBasicBlockRef Else,
4743 unsigned NumCases);
4744LLVM_C_ABI LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
4745 unsigned NumDests);
4746LLVM_C_ABI LLVMValueRef LLVMBuildCallBr(
4747 LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
4748 LLVMBasicBlockRef DefaultDest, LLVMBasicBlockRef *IndirectDests,
4749 unsigned NumIndirectDests, LLVMValueRef *Args, unsigned NumArgs,
4750 LLVMOperandBundleRef *Bundles, unsigned NumBundles, const char *Name);
4751LLVM_C_ABI LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty,
4752 LLVMValueRef Fn, LLVMValueRef *Args,
4753 unsigned NumArgs,
4754 LLVMBasicBlockRef Then,
4755 LLVMBasicBlockRef Catch,
4756 const char *Name);
4757LLVM_C_ABI LLVMValueRef LLVMBuildInvokeWithOperandBundles(
4758 LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef *Args,
4759 unsigned NumArgs, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
4760 LLVMOperandBundleRef *Bundles, unsigned NumBundles, const char *Name);
4761LLVM_C_ABI LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
4762
4763/* Exception Handling */
4764LLVM_C_ABI LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
4765LLVM_C_ABI LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
4766 LLVMValueRef PersFn,
4767 unsigned NumClauses,
4768 const char *Name);
4769LLVM_C_ABI LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B,
4770 LLVMValueRef CatchPad,
4771 LLVMBasicBlockRef BB);
4772LLVM_C_ABI LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B,
4773 LLVMValueRef CatchPad,
4774 LLVMBasicBlockRef BB);
4775LLVM_C_ABI LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B,
4776 LLVMValueRef ParentPad,
4777 LLVMValueRef *Args, unsigned NumArgs,
4778 const char *Name);
4779LLVM_C_ABI LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B,
4780 LLVMValueRef ParentPad,
4781 LLVMValueRef *Args,
4782 unsigned NumArgs, const char *Name);
4783LLVM_C_ABI LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B,
4784 LLVMValueRef ParentPad,
4785 LLVMBasicBlockRef UnwindBB,
4786 unsigned NumHandlers,
4787 const char *Name);
4788
4789/* Add a case to the switch instruction */
4790LLVM_C_ABI void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
4791 LLVMBasicBlockRef Dest);
4792
4793/* Add a destination to the indirectbr instruction */
4794LLVM_C_ABI void LLVMAddDestination(LLVMValueRef IndirectBr,
4795 LLVMBasicBlockRef Dest);
4796
4797/* Get the number of clauses on the landingpad instruction */
4798LLVM_C_ABI unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
4799
4800/* Get the value of the clause at index Idx on the landingpad instruction */
4801LLVM_C_ABI LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
4802
4803/* Add a catch or filter clause to the landingpad instruction */
4804LLVM_C_ABI void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
4805
4806/* Get the 'cleanup' flag in the landingpad instruction */
4807LLVM_C_ABI LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
4808
4809/* Set the 'cleanup' flag in the landingpad instruction */
4810LLVM_C_ABI void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
4811
4812/* Add a destination to the catchswitch instruction */
4813LLVM_C_ABI void LLVMAddHandler(LLVMValueRef CatchSwitch,
4814 LLVMBasicBlockRef Dest);
4815
4816/* Get the number of handlers on the catchswitch instruction */
4817LLVM_C_ABI unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch);
4818
4819/**
4820 * Obtain the basic blocks acting as handlers for a catchswitch instruction.
4821 *
4822 * The Handlers parameter should point to a pre-allocated array of
4823 * LLVMBasicBlockRefs at least LLVMGetNumHandlers() large. On return, the
4824 * first LLVMGetNumHandlers() entries in the array will be populated
4825 * with LLVMBasicBlockRef instances.
4826 *
4827 * @param CatchSwitch The catchswitch instruction to operate on.
4828 * @param Handlers Memory address of an array to be filled with basic blocks.
4829 */
4830LLVM_C_ABI void LLVMGetHandlers(LLVMValueRef CatchSwitch,
4831 LLVMBasicBlockRef *Handlers);
4832
4833/* Funclets */
4834
4835/* Get the number of funcletpad arguments. */
4836LLVM_C_ABI LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i);
4837
4838/* Set a funcletpad argument at the given index. */
4839LLVM_C_ABI void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i,
4840 LLVMValueRef value);
4841
4842/**
4843 * Get the parent catchswitch instruction of a catchpad instruction.
4844 *
4845 * This only works on llvm::CatchPadInst instructions.
4846 *
4847 * @see llvm::CatchPadInst::getCatchSwitch()
4848 */
4849LLVM_C_ABI LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad);
4850
4851/**
4852 * Set the parent catchswitch instruction of a catchpad instruction.
4853 *
4854 * This only works on llvm::CatchPadInst instructions.
4855 *
4856 * @see llvm::CatchPadInst::setCatchSwitch()
4857 */
4858LLVM_C_ABI void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad,
4859 LLVMValueRef CatchSwitch);
4860
4861/* Arithmetic */
4862LLVM_C_ABI LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS,
4863 LLVMValueRef RHS, const char *Name);
4864LLVM_C_ABI LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS,
4865 LLVMValueRef RHS, const char *Name);
4866LLVM_C_ABI LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS,
4867 LLVMValueRef RHS, const char *Name);
4868LLVM_C_ABI LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS,
4869 LLVMValueRef RHS, const char *Name);
4870LLVM_C_ABI LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS,
4871 LLVMValueRef RHS, const char *Name);
4872LLVM_C_ABI LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS,
4873 LLVMValueRef RHS, const char *Name);
4874LLVM_C_ABI LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS,
4875 LLVMValueRef RHS, const char *Name);
4876LLVM_C_ABI LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS,
4877 LLVMValueRef RHS, const char *Name);
4878LLVM_C_ABI LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS,
4879 LLVMValueRef RHS, const char *Name);
4880LLVM_C_ABI LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS,
4881 LLVMValueRef RHS, const char *Name);
4882LLVM_C_ABI LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS,
4883 LLVMValueRef RHS, const char *Name);
4884LLVM_C_ABI LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS,
4885 LLVMValueRef RHS, const char *Name);
4886LLVM_C_ABI LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS,
4887 LLVMValueRef RHS, const char *Name);
4888LLVM_C_ABI LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS,
4889 LLVMValueRef RHS, const char *Name);
4890LLVM_C_ABI LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS,
4891 LLVMValueRef RHS, const char *Name);
4892LLVM_C_ABI LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS,
4893 LLVMValueRef RHS, const char *Name);
4894LLVM_C_ABI LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS,
4895 LLVMValueRef RHS, const char *Name);
4896LLVM_C_ABI LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS,
4897 LLVMValueRef RHS, const char *Name);
4898LLVM_C_ABI LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS,
4899 LLVMValueRef RHS, const char *Name);
4900LLVM_C_ABI LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS,
4901 LLVMValueRef RHS, const char *Name);
4902LLVM_C_ABI LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS,
4903 LLVMValueRef RHS, const char *Name);
4904LLVM_C_ABI LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS,
4905 LLVMValueRef RHS, const char *Name);
4906LLVM_C_ABI LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS,
4907 LLVMValueRef RHS, const char *Name);
4908LLVM_C_ABI LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS,
4909 LLVMValueRef RHS, const char *Name);
4910LLVM_C_ABI LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS,
4911 LLVMValueRef RHS, const char *Name);
4912LLVM_C_ABI LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS,
4913 LLVMValueRef RHS, const char *Name);
4914LLVM_C_ABI LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
4915 LLVMValueRef LHS, LLVMValueRef RHS,
4916 const char *Name);
4917LLVM_C_ABI LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V,
4918 const char *Name);
4919LLVM_C_ABI LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
4920 const char *Name);
4921LLVM_C_ABI LLVM_ATTRIBUTE_C_DEPRECATED(
4922 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
4923 const char *Name),
4924 "Use LLVMBuildNeg + LLVMSetNUW instead.");
4925LLVM_C_ABI LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V,
4926 const char *Name);
4927LLVM_C_ABI LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V,
4928 const char *Name);
4929
4930LLVM_C_ABI LLVMBool LLVMGetNUW(LLVMValueRef ArithInst);
4931LLVM_C_ABI void LLVMSetNUW(LLVMValueRef ArithInst, LLVMBool HasNUW);
4932LLVM_C_ABI LLVMBool LLVMGetNSW(LLVMValueRef ArithInst);
4933LLVM_C_ABI void LLVMSetNSW(LLVMValueRef ArithInst, LLVMBool HasNSW);
4934LLVM_C_ABI LLVMBool LLVMGetExact(LLVMValueRef DivOrShrInst);
4935LLVM_C_ABI void LLVMSetExact(LLVMValueRef DivOrShrInst, LLVMBool IsExact);
4936
4937/**
4938 * Gets if the instruction has the non-negative flag set.
4939 * Only valid for zext instructions.
4940 */
4941LLVM_C_ABI LLVMBool LLVMGetNNeg(LLVMValueRef NonNegInst);
4942/**
4943 * Sets the non-negative flag for the instruction.
4944 * Only valid for zext instructions.
4945 */
4946LLVM_C_ABI void LLVMSetNNeg(LLVMValueRef NonNegInst, LLVMBool IsNonNeg);
4947
4948/**
4949 * Get the flags for which fast-math-style optimizations are allowed for this
4950 * value.
4951 *
4952 * Only valid on floating point instructions.
4953 * @see LLVMCanValueUseFastMathFlags
4954 */
4955LLVM_C_ABI LLVMFastMathFlags LLVMGetFastMathFlags(LLVMValueRef FPMathInst);
4956
4957/**
4958 * Sets the flags for which fast-math-style optimizations are allowed for this
4959 * value.
4960 *
4961 * Only valid on floating point instructions.
4962 * @see LLVMCanValueUseFastMathFlags
4963 */
4964LLVM_C_ABI void LLVMSetFastMathFlags(LLVMValueRef FPMathInst,
4965 LLVMFastMathFlags FMF);
4966
4967/**
4968 * Check if a given value can potentially have fast math flags.
4969 *
4970 * Will return true for floating point arithmetic instructions, and for select,
4971 * phi, and call instructions whose type is a floating point type, or a vector
4972 * or array thereof. See https://llvm.org/docs/LangRef.html#fast-math-flags
4973 */
4974LLVM_C_ABI LLVMBool LLVMCanValueUseFastMathFlags(LLVMValueRef Inst);
4975
4976/**
4977 * Gets whether the instruction has the disjoint flag set.
4978 * Only valid for or instructions.
4979 */
4980LLVM_C_ABI LLVMBool LLVMGetIsDisjoint(LLVMValueRef Inst);
4981/**
4982 * Sets the disjoint flag for the instruction.
4983 * Only valid for or instructions.
4984 */
4985LLVM_C_ABI void LLVMSetIsDisjoint(LLVMValueRef Inst, LLVMBool IsDisjoint);
4986
4987/* Memory */
4988LLVM_C_ABI LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
4989 const char *Name);
4990LLVM_C_ABI LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
4991 LLVMValueRef Val,
4992 const char *Name);
4993
4994/**
4995 * Creates and inserts a memset to the specified pointer and the
4996 * specified value.
4997 *
4998 * @see llvm::IRRBuilder::CreateMemSet()
4999 */
5000LLVM_C_ABI LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
5001 LLVMValueRef Val, LLVMValueRef Len,
5002 unsigned Align);
5003/**
5004 * Creates and inserts a memcpy between the specified pointers.
5005 *
5006 * @see llvm::IRRBuilder::CreateMemCpy()
5007 */
5008LLVM_C_ABI LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst,
5009 unsigned DstAlign, LLVMValueRef Src,
5010 unsigned SrcAlign, LLVMValueRef Size);
5011/**
5012 * Creates and inserts a memmove between the specified pointers.
5013 *
5014 * @see llvm::IRRBuilder::CreateMemMove()
5015 */
5016LLVM_C_ABI LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B, LLVMValueRef Dst,
5017 unsigned DstAlign, LLVMValueRef Src,
5018 unsigned SrcAlign, LLVMValueRef Size);
5019
5020LLVM_C_ABI LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
5021 const char *Name);
5022LLVM_C_ABI LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
5023 LLVMValueRef Val,
5024 const char *Name);
5025LLVM_C_ABI LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
5026LLVM_C_ABI LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty,
5027 LLVMValueRef PointerVal,
5028 const char *Name);
5029LLVM_C_ABI LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val,
5030 LLVMValueRef Ptr);
5031LLVM_C_ABI LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
5032 LLVMValueRef Pointer,
5033 LLVMValueRef *Indices,
5034 unsigned NumIndices, const char *Name);
5035LLVM_C_ABI LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
5036 LLVMValueRef Pointer,
5037 LLVMValueRef *Indices,
5038 unsigned NumIndices,
5039 const char *Name);
5040/**
5041 * Creates a GetElementPtr instruction. Similar to LLVMBuildGEP2, but allows
5042 * specifying the no-wrap flags.
5043 *
5044 * @see llvm::IRBuilder::CreateGEP()
5045 */
5046LLVM_C_ABI LLVMValueRef LLVMBuildGEPWithNoWrapFlags(
5047 LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Pointer,
5048 LLVMValueRef *Indices, unsigned NumIndices, const char *Name,
5049 LLVMGEPNoWrapFlags NoWrapFlags);
5050LLVM_C_ABI LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
5051 LLVMValueRef Pointer, unsigned Idx,
5052 const char *Name);
5053LLVM_C_ABI LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
5054 const char *Name);
5055/**
5056 * Deprecated: Use LLVMBuildGlobalString instead, which has identical behavior.
5057 */
5058LLVM_C_ABI LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B,
5059 const char *Str,
5060 const char *Name);
5061LLVM_C_ABI LLVMBool LLVMGetVolatile(LLVMValueRef Inst);
5062LLVM_C_ABI void LLVMSetVolatile(LLVMValueRef MemoryAccessInst,
5063 LLVMBool IsVolatile);
5064LLVM_C_ABI LLVMBool LLVMGetWeak(LLVMValueRef CmpXchgInst);
5065LLVM_C_ABI void LLVMSetWeak(LLVMValueRef CmpXchgInst, LLVMBool IsWeak);
5066LLVM_C_ABI LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
5067LLVM_C_ABI void LLVMSetOrdering(LLVMValueRef MemoryAccessInst,
5068 LLVMAtomicOrdering Ordering);
5069LLVM_C_ABI LLVMAtomicRMWBinOp LLVMGetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst);
5070LLVM_C_ABI void LLVMSetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst,
5071 LLVMAtomicRMWBinOp BinOp);
5072
5073/* Casts */
5074LLVM_C_ABI LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
5075 LLVMTypeRef DestTy, const char *Name);
5076LLVM_C_ABI LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
5077 LLVMTypeRef DestTy, const char *Name);
5078LLVM_C_ABI LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
5079 LLVMTypeRef DestTy, const char *Name);
5080LLVM_C_ABI LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
5081 LLVMTypeRef DestTy, const char *Name);
5082LLVM_C_ABI LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
5083 LLVMTypeRef DestTy, const char *Name);
5084LLVM_C_ABI LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
5085 LLVMTypeRef DestTy, const char *Name);
5086LLVM_C_ABI LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
5087 LLVMTypeRef DestTy, const char *Name);
5088LLVM_C_ABI LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
5089 LLVMTypeRef DestTy, const char *Name);
5090LLVM_C_ABI LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
5091 LLVMTypeRef DestTy, const char *Name);
5092LLVM_C_ABI LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
5093 LLVMTypeRef DestTy, const char *Name);
5094LLVM_C_ABI LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
5095 LLVMTypeRef DestTy, const char *Name);
5096LLVM_C_ABI LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
5097 LLVMTypeRef DestTy, const char *Name);
5098LLVM_C_ABI LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
5099 LLVMTypeRef DestTy,
5100 const char *Name);
5101LLVM_C_ABI LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
5102 LLVMTypeRef DestTy,
5103 const char *Name);
5104LLVM_C_ABI LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
5105 LLVMTypeRef DestTy,
5106 const char *Name);
5107LLVM_C_ABI LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef,
5108 LLVMValueRef Val,
5109 LLVMTypeRef DestTy,
5110 const char *Name);
5111LLVM_C_ABI LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op,
5112 LLVMValueRef Val, LLVMTypeRef DestTy,
5113 const char *Name);
5114LLVM_C_ABI LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
5115 LLVMTypeRef DestTy,
5116 const char *Name);
5117LLVM_C_ABI LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef, LLVMValueRef Val,
5118 LLVMTypeRef DestTy, LLVMBool IsSigned,
5119 const char *Name);
5120LLVM_C_ABI LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
5121 LLVMTypeRef DestTy, const char *Name);
5122
5123/** Deprecated: This cast is always signed. Use LLVMBuildIntCast2 instead. */
5124LLVM_C_ABI LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef,
5125 LLVMValueRef Val, /*Signed cast!*/
5126 LLVMTypeRef DestTy, const char *Name);
5127
5128LLVM_C_ABI LLVMOpcode LLVMGetCastOpcode(LLVMValueRef Src, LLVMBool SrcIsSigned,
5129 LLVMTypeRef DestTy,
5130 LLVMBool DestIsSigned);
5131
5132/* Comparisons */
5133LLVM_C_ABI LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
5134 LLVMValueRef LHS, LLVMValueRef RHS,
5135 const char *Name);
5136LLVM_C_ABI LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
5137 LLVMValueRef LHS, LLVMValueRef RHS,
5138 const char *Name);
5139
5140/* Miscellaneous instructions */
5141LLVM_C_ABI LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty,
5142 const char *Name);
5143LLVM_C_ABI LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef,
5144 LLVMValueRef Fn, LLVMValueRef *Args,
5145 unsigned NumArgs, const char *Name);
5146LLVM_C_ABI LLVMValueRef LLVMBuildCallWithOperandBundles(
5147 LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn, LLVMValueRef *Args,
5148 unsigned NumArgs, LLVMOperandBundleRef *Bundles, unsigned NumBundles,
5149 const char *Name);
5150LLVM_C_ABI LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
5151 LLVMValueRef Then, LLVMValueRef Else,
5152 const char *Name);
5153LLVM_C_ABI LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List,
5154 LLVMTypeRef Ty, const char *Name);
5155LLVM_C_ABI LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef,
5156 LLVMValueRef VecVal,
5157 LLVMValueRef Index,
5158 const char *Name);
5159LLVM_C_ABI LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef,
5160 LLVMValueRef VecVal,
5161 LLVMValueRef EltVal,
5162 LLVMValueRef Index,
5163 const char *Name);
5164LLVM_C_ABI LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
5165 LLVMValueRef V2,
5166 LLVMValueRef Mask,
5167 const char *Name);
5168LLVM_C_ABI LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef,
5169 LLVMValueRef AggVal,
5170 unsigned Index, const char *Name);
5171LLVM_C_ABI LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef,
5172 LLVMValueRef AggVal,
5173 LLVMValueRef EltVal,
5174 unsigned Index, const char *Name);
5175LLVM_C_ABI LLVMValueRef LLVMBuildFreeze(LLVMBuilderRef, LLVMValueRef Val,
5176 const char *Name);
5177LLVM_C_ABI LLVMValueRef LLVMBuildBitExtract(LLVMBuilderRef, LLVMTypeRef Type,
5178 LLVMValueRef Src,
5179 LLVMValueRef Offset,
5180 const char *Name);
5181LLVM_C_ABI LLVMValueRef LLVMBuildBitInsert(LLVMBuilderRef, LLVMValueRef Base,
5182 LLVMValueRef Val,
5183 LLVMValueRef Offset,
5184 const char *Name);
5185
5186LLVM_C_ABI LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
5187 const char *Name);
5188LLVM_C_ABI LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
5189 const char *Name);
5190LLVM_C_ABI LLVMValueRef LLVMBuildPtrDiff2(LLVMBuilderRef, LLVMTypeRef ElemTy,
5191 LLVMValueRef LHS, LLVMValueRef RHS,
5192 const char *Name);
5193LLVM_C_ABI LLVMValueRef LLVMBuildFence(LLVMBuilderRef B,
5194 LLVMAtomicOrdering ordering,
5195 LLVMBool singleThread, const char *Name);
5196LLVM_C_ABI LLVMValueRef LLVMBuildFenceSyncScope(LLVMBuilderRef B,
5197 LLVMAtomicOrdering ordering,
5198 unsigned SSID,
5199 const char *Name);
5200LLVM_C_ABI LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B,
5201 LLVMAtomicRMWBinOp op,
5202 LLVMValueRef PTR, LLVMValueRef Val,
5203 LLVMAtomicOrdering ordering,
5204 LLVMBool singleThread);
5205LLVM_C_ABI LLVMValueRef LLVMBuildAtomicRMWSyncScope(
5206 LLVMBuilderRef B, LLVMAtomicRMWBinOp op, LLVMValueRef PTR, LLVMValueRef Val,
5207 LLVMAtomicOrdering ordering, unsigned SSID);
5208LLVM_C_ABI LLVMValueRef LLVMBuildAtomicCmpXchg(
5209 LLVMBuilderRef B, LLVMValueRef Ptr, LLVMValueRef Cmp, LLVMValueRef New,
5210 LLVMAtomicOrdering SuccessOrdering, LLVMAtomicOrdering FailureOrdering,
5211 LLVMBool SingleThread);
5212LLVM_C_ABI LLVMValueRef LLVMBuildAtomicCmpXchgSyncScope(
5213 LLVMBuilderRef B, LLVMValueRef Ptr, LLVMValueRef Cmp, LLVMValueRef New,
5214 LLVMAtomicOrdering SuccessOrdering, LLVMAtomicOrdering FailureOrdering,
5215 unsigned SSID);
5216
5217/**
5218 * Get the number of elements in the mask of a ShuffleVector instruction.
5219 */
5220LLVM_C_ABI unsigned LLVMGetNumMaskElements(LLVMValueRef ShuffleVectorInst);
5221
5222/**
5223 * \returns a constant that specifies that the result of a \c ShuffleVectorInst
5224 * is undefined.
5225 */
5226LLVM_C_ABI int LLVMGetUndefMaskElem(void);
5227
5228/**
5229 * Get the mask value at position Elt in the mask of a ShuffleVector
5230 * instruction.
5231 *
5232 * \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is
5233 * poison at that position.
5234 */
5235LLVM_C_ABI int LLVMGetMaskValue(LLVMValueRef ShuffleVectorInst, unsigned Elt);
5236
5237LLVM_C_ABI LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
5238LLVM_C_ABI void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst,
5239 LLVMBool SingleThread);
5240
5241/**
5242 * Returns whether an instruction is an atomic instruction, e.g., atomicrmw,
5243 * cmpxchg, fence, or loads and stores with atomic ordering.
5244 */
5245LLVM_C_ABI LLVMBool LLVMIsAtomic(LLVMValueRef Inst);
5246
5247/**
5248 * Returns the synchronization scope ID of an atomic instruction.
5249 */
5250LLVM_C_ABI unsigned LLVMGetAtomicSyncScopeID(LLVMValueRef AtomicInst);
5251
5252/**
5253 * Sets the synchronization scope ID of an atomic instruction.
5254 */
5255LLVM_C_ABI void LLVMSetAtomicSyncScopeID(LLVMValueRef AtomicInst,
5256 unsigned SSID);
5257
5258LLVM_C_ABI LLVMAtomicOrdering
5259LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
5260LLVM_C_ABI void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
5261 LLVMAtomicOrdering Ordering);
5262LLVM_C_ABI LLVMAtomicOrdering
5263LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
5264LLVM_C_ABI void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
5265 LLVMAtomicOrdering Ordering);
5266
5267/**
5268 * @}
5269 */
5270
5271/**
5272 * @defgroup LLVMCCoreModuleProvider Module Providers
5273 *
5274 * @{
5275 */
5276
5277/**
5278 * Changes the type of M so it can be passed to FunctionPassManagers and the
5279 * JIT. They take ModuleProviders for historical reasons.
5280 */
5281LLVM_C_ABI LLVMModuleProviderRef
5282LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
5283
5284/**
5285 * Destroys the module M.
5286 */
5287LLVM_C_ABI void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
5288
5289/**
5290 * @}
5291 */
5292
5293/**
5294 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
5295 *
5296 * @{
5297 */
5298
5299LLVM_C_ABI LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(
5300 const char *Path, LLVMMemoryBufferRef *OutMemBuf, char **OutMessage);
5301LLVM_C_ABI LLVMBool LLVMCreateMemoryBufferWithSTDIN(
5302 LLVMMemoryBufferRef *OutMemBuf, char **OutMessage);
5303LLVM_C_ABI LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(
5304 const char *InputData, size_t InputDataLength, const char *BufferName,
5305 LLVMBool RequiresNullTerminator);
5306LLVM_C_ABI LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(
5307 const char *InputData, size_t InputDataLength, const char *BufferName);
5308LLVM_C_ABI const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
5309LLVM_C_ABI size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
5310LLVM_C_ABI void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
5311
5312/**
5313 * @}
5314 */
5315
5316/**
5317 * @defgroup LLVMCCorePassManagers Pass Managers
5318 * @ingroup LLVMCCore
5319 *
5320 * @{
5321 */
5322
5323/** Constructs a new whole-module pass pipeline. This type of pipeline is
5324 suitable for link-time optimization and whole-module transformations.
5325 @see llvm::PassManager::PassManager */
5326LLVM_C_ABI LLVMPassManagerRef LLVMCreatePassManager(void);
5327
5328/** Constructs a new function-by-function pass pipeline over the module
5329 provider. It does not take ownership of the module provider. This type of
5330 pipeline is suitable for code generation and JIT compilation tasks.
5331 @see llvm::FunctionPassManager::FunctionPassManager */
5332LLVM_C_ABI LLVMPassManagerRef
5333LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
5334
5335/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
5336LLVM_C_ABI LLVMPassManagerRef
5337LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
5338
5339/** Initializes, executes on the provided module, and finalizes all of the
5340 passes scheduled in the pass manager. Returns 1 if any of the passes
5341 modified the module, 0 otherwise.
5342 @see llvm::PassManager::run(Module&) */
5343LLVM_C_ABI LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
5344
5345/** Initializes all of the function passes scheduled in the function pass
5346 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
5347 @see llvm::FunctionPassManager::doInitialization */
5348LLVM_C_ABI LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
5349
5350/** Executes all of the function passes scheduled in the function pass manager
5351 on the provided function. Returns 1 if any of the passes modified the
5352 function, false otherwise.
5353 @see llvm::FunctionPassManager::run(Function&) */
5354LLVM_C_ABI LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM,
5355 LLVMValueRef F);
5356
5357/** Finalizes all of the function passes scheduled in the function pass
5358 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
5359 @see llvm::FunctionPassManager::doFinalization */
5360LLVM_C_ABI LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
5361
5362/** Frees the memory of a pass pipeline. For function pipelines, does not free
5363 the module provider.
5364 @see llvm::PassManagerBase::~PassManagerBase. */
5365LLVM_C_ABI void LLVMDisposePassManager(LLVMPassManagerRef PM);
5366
5367/**
5368 * @}
5369 */
5370
5371/**
5372 * @defgroup LLVMCCoreThreading Threading
5373 *
5374 * Handle the structures needed to make LLVM safe for multithreading.
5375 *
5376 * @{
5377 */
5378
5379/** Deprecated: Multi-threading can only be enabled/disabled with the compile
5380 time define LLVM_ENABLE_THREADS. This function always returns
5381 LLVMIsMultithreaded(). */
5382LLVM_C_ABI LLVMBool LLVMStartMultithreaded(void);
5383
5384/** Deprecated: Multi-threading can only be enabled/disabled with the compile
5385 time define LLVM_ENABLE_THREADS. */
5386LLVM_C_ABI void LLVMStopMultithreaded(void);
5387
5388/** Check whether LLVM is executing in thread-safe mode or not.
5389 @see llvm::llvm_is_multithreaded */
5390LLVM_C_ABI LLVMBool LLVMIsMultithreaded(void);
5391
5392/**
5393 * @}
5394 */
5395
5396/**
5397 * @defgroup LLVMCCoreDataLayout Data Layout
5398 *
5399 * @{
5400 */
5401
5402enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
5403
5404/**
5405 * Obtain the data layout for a module.
5406 *
5407 * @see Module::getDataLayout()
5408 */
5409LLVM_C_ABI LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
5410
5411/**
5412 * Set the data layout for a module.
5413 *
5414 * @see Module::setDataLayout()
5415 */
5416LLVM_C_ABI void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
5417
5418/** Creates target data from a target layout string.
5419 See the constructor llvm::DataLayout::DataLayout. */
5420LLVM_C_ABI LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
5421
5422/** Deallocates a TargetData.
5423 See the destructor llvm::DataLayout::~DataLayout. */
5424LLVM_C_ABI void LLVMDisposeTargetData(LLVMTargetDataRef TD);
5425
5426/** Converts target data to a target layout string. The string must be disposed
5427 with LLVMDisposeMessage.
5428 See the constructor llvm::DataLayout::DataLayout. */
5429LLVM_C_ABI char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
5430
5431/** Returns the byte order of a target, either LLVMBigEndian or
5432 LLVMLittleEndian.
5433 See the method llvm::DataLayout::isLittleEndian. */
5434LLVM_C_ABI enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
5435
5436/** Returns the pointer size in bytes for a target.
5437 See the method llvm::DataLayout::getPointerSize. */
5438LLVM_C_ABI unsigned LLVMPointerSize(LLVMTargetDataRef TD);
5439
5440/** Returns the pointer size in bytes for a target for a specified
5441 address space.
5442 See the method llvm::DataLayout::getPointerSize. */
5443LLVM_C_ABI unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
5444
5445/** Returns the integer type that is the same size as a pointer on a target.
5446 See the method llvm::DataLayout::getIntPtrType. */
5447LLVM_C_ABI
5448LLVM_ATTRIBUTE_C_DEPRECATED(LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD),
5449 "Use of the global context is deprecated, use "
5450 "LLVMIntPtrTypeInContext instead");
5451
5452/** Returns the integer type that is the same size as a pointer on a target.
5453 This version allows the address space to be specified.
5454 See the method llvm::DataLayout::getIntPtrType. */
5455LLVM_C_ABI LLVM_ATTRIBUTE_C_DEPRECATED(
5456 LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS),
5457 "Use of the global context is deprecated, use LLVMIntPtrTypeForASInContext "
5458 "instead");
5459
5460/** Returns the integer type that is the same size as a pointer on a target.
5461 See the method llvm::DataLayout::getIntPtrType. */
5462LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C,
5463 LLVMTargetDataRef TD);
5464
5465/** Returns the integer type that is the same size as a pointer on a target.
5466 This version allows the address space to be specified.
5467 See the method llvm::DataLayout::getIntPtrType. */
5468LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C,
5469 LLVMTargetDataRef TD,
5470 unsigned AS);
5471
5472/** Computes the size of a type in bits for a target.
5473 See the method llvm::DataLayout::getTypeSizeInBits. */
5474LLVM_C_ABI unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD,
5475 LLVMTypeRef Ty);
5476
5477/** Computes the storage size of a type in bytes for a target.
5478 See the method llvm::DataLayout::getTypeStoreSize. */
5479LLVM_C_ABI unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD,
5480 LLVMTypeRef Ty);
5481
5482/** Computes the ABI size of a type in bytes for a target.
5483 See the method llvm::DataLayout::getTypeAllocSize. */
5484LLVM_C_ABI unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD,
5485 LLVMTypeRef Ty);
5486
5487/** Computes the ABI alignment of a type in bytes for a target.
5488 See the method llvm::DataLayout::getTypeABISize. */
5489LLVM_C_ABI unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD,
5490 LLVMTypeRef Ty);
5491
5492/** Computes the call frame alignment of a type in bytes for a target.
5493 See the method llvm::DataLayout::getTypeABISize. */
5494LLVM_C_ABI unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD,
5495 LLVMTypeRef Ty);
5496
5497/** Computes the preferred alignment of a type in bytes for a target.
5498 See the method llvm::DataLayout::getTypeABISize. */
5499LLVM_C_ABI unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD,
5500 LLVMTypeRef Ty);
5501
5502/** Computes the preferred alignment of a global variable in bytes for a target.
5503 See the method llvm::DataLayout::getPreferredAlignment. */
5504LLVM_C_ABI unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
5505 LLVMValueRef GlobalVar);
5506
5507/** Computes the structure element that contains the byte offset for a target.
5508 See the method llvm::StructLayout::getElementContainingOffset. */
5509LLVM_C_ABI unsigned LLVMElementAtOffset(LLVMTargetDataRef TD,
5510 LLVMTypeRef StructTy,
5511 unsigned long long Offset);
5512
5513/** Computes the byte offset of the indexed struct element for a target.
5514 See the method llvm::StructLayout::getElementContainingOffset. */
5515LLVM_C_ABI unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
5516 LLVMTypeRef StructTy,
5517 unsigned Element);
5518
5519/**
5520 * @}
5521 */
5522
5523/**
5524 * @}
5525 */
5526
5527/**
5528 * @}
5529 */
5530
5531LLVM_C_EXTERN_C_END
5532
5533#endif /* LLVM_C_CORE_H */
5534