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

source code of llvm/include/llvm-c/Core.h