blob: 86de259ea53e7b9050dff080597c0b53881d41ca [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
Chandler Carruth2946cd72019-01-19 08:50:56 +00003|* 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 *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000013\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_C_CORE_H
16#define LLVM_C_CORE_H
17
Eric Christophera6b96002015-12-18 01:46:52 +000018#include "llvm-c/ErrorHandling.h"
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080019#include "llvm-c/ExternC.h"
Eric Christophera6b96002015-12-18 01:46:52 +000020#include "llvm-c/Types.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000021
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080022LLVM_C_EXTERN_C_BEGIN
Gordon Henriksen76a03742007-09-18 03:18:57 +000023
Gregory Szorc34c863a2012-03-21 03:54:29 +000024/**
25 * @defgroup LLVMC LLVM-C: C interface to LLVM
26 *
27 * This module exposes parts of the LLVM library as a C API.
28 *
29 * @{
30 */
31
32/**
33 * @defgroup LLVMCTransforms Transforms
34 */
35
36/**
37 * @defgroup LLVMCCore Core
38 *
39 * This modules provide an interface to libLLVMCore, which implements
40 * the LLVM intermediate representation as well as other related types
41 * and utilities.
42 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000043 * Many exotic languages can interoperate with C code but have a harder time
44 * with C++ due to name mangling. So in addition to C, this interface enables
45 * tools written in such languages.
46 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000047 * @{
48 */
49
50/**
51 * @defgroup LLVMCCoreTypes Types and Enumerations
52 *
53 * @{
54 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000055
Cameron McInallycbde0d92018-11-13 18:15:47 +000056/// External users depend on the following values being stable. It is not safe
57/// to reorder them.
Gordon Henriksen76a03742007-09-18 03:18:57 +000058typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +000059 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +000060 LLVMRet = 1,
61 LLVMBr = 2,
62 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +000063 LLVMIndirectBr = 4,
64 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +000065 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +000066 LLVMUnreachable = 7,
Craig Topper784929d2019-02-08 20:48:56 +000067 LLVMCallBr = 67,
Bill Wendling07d6d762010-02-15 20:50:51 +000068
Cameron McInallycbde0d92018-11-13 18:15:47 +000069 /* Standard Unary Operators */
70 LLVMFNeg = 66,
71
Bill Wendlingda52cec2010-02-15 20:53:17 +000072 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000073 LLVMAdd = 8,
74 LLVMFAdd = 9,
75 LLVMSub = 10,
76 LLVMFSub = 11,
77 LLVMMul = 12,
78 LLVMFMul = 13,
79 LLVMUDiv = 14,
80 LLVMSDiv = 15,
81 LLVMFDiv = 16,
82 LLVMURem = 17,
83 LLVMSRem = 18,
84 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +000085
Bill Wendlingda52cec2010-02-15 20:53:17 +000086 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000087 LLVMShl = 20,
88 LLVMLShr = 21,
89 LLVMAShr = 22,
90 LLVMAnd = 23,
91 LLVMOr = 24,
92 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +000093
Bill Wendlingda52cec2010-02-15 20:53:17 +000094 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000095 LLVMAlloca = 26,
96 LLVMLoad = 27,
97 LLVMStore = 28,
98 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +000099
Bill Wendlingda52cec2010-02-15 20:53:17 +0000100 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000101 LLVMTrunc = 30,
102 LLVMZExt = 31,
103 LLVMSExt = 32,
104 LLVMFPToUI = 33,
105 LLVMFPToSI = 34,
106 LLVMUIToFP = 35,
107 LLVMSIToFP = 36,
108 LLVMFPTrunc = 37,
109 LLVMFPExt = 38,
110 LLVMPtrToInt = 39,
111 LLVMIntToPtr = 40,
112 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000113 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000114
Bill Wendlingda52cec2010-02-15 20:53:17 +0000115 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000116 LLVMICmp = 42,
117 LLVMFCmp = 43,
118 LLVMPHI = 44,
119 LLVMCall = 45,
120 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000121 LLVMUserOp1 = 47,
122 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000123 LLVMVAArg = 49,
124 LLVMExtractElement = 50,
125 LLVMInsertElement = 51,
126 LLVMShuffleVector = 52,
127 LLVMExtractValue = 53,
128 LLVMInsertValue = 54,
aqjunee87d7162019-11-07 01:17:49 +0900129 LLVMFreeze = 68,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000130
131 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000132 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000133 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000134 LLVMAtomicRMW = 57,
135
136 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000137 LLVMResume = 58,
David Majnemer654e1302015-07-31 17:58:14 +0000138 LLVMLandingPad = 59,
139 LLVMCleanupRet = 61,
140 LLVMCatchRet = 62,
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +0000141 LLVMCatchPad = 63,
David Majnemerbbfc7212015-12-14 18:34:23 +0000142 LLVMCleanupPad = 64,
143 LLVMCatchSwitch = 65
Chris Lattner40cf28d2009-10-12 04:01:02 +0000144} LLVMOpcode;
145
146typedef enum {
Christopher Tetreault015e2972020-05-15 10:45:42 -0700147 LLVMVoidTypeKind, /**< type with no size */
148 LLVMHalfTypeKind, /**< 16 bit floating point type */
Christopher Tetreault015e2972020-05-15 10:45:42 -0700149 LLVMFloatTypeKind, /**< 32 bit floating point type */
150 LLVMDoubleTypeKind, /**< 64 bit floating point type */
151 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
152 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
153 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
154 LLVMLabelTypeKind, /**< Labels */
155 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
156 LLVMFunctionTypeKind, /**< Functions */
157 LLVMStructTypeKind, /**< Structures */
158 LLVMArrayTypeKind, /**< Arrays */
159 LLVMPointerTypeKind, /**< Pointers */
160 LLVMVectorTypeKind, /**< Fixed width SIMD vector type */
161 LLVMMetadataTypeKind, /**< Metadata */
162 LLVMX86_MMXTypeKind, /**< X86 MMX */
163 LLVMTokenTypeKind, /**< Tokens */
Ties Stuij9dda41e2020-06-18 23:57:32 +0100164 LLVMScalableVectorTypeKind, /**< Scalable SIMD vector type */
165 LLVMBFloatTypeKind /**< 16 bit brain floating point type */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000166} LLVMTypeKind;
167
168typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000169 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000170 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000171 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
172 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
173 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000174 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000175 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
176 LLVMWeakODRLinkage, /**< Same, but only replaced by something
177 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000178 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
179 LLVMInternalLinkage, /**< Rename collisions when linking (static
180 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000181 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000182 LLVMDLLImportLinkage, /**< Obsolete */
183 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000184 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000185 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000186 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000187 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000188 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000189} LLVMLinkage;
190
191typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000192 LLVMDefaultVisibility, /**< The GV is visible */
193 LLVMHiddenVisibility, /**< The GV is hidden */
194 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000195} LLVMVisibility;
196
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000197typedef enum {
Robert Widmann4bb481b2018-03-14 06:45:51 +0000198 LLVMNoUnnamedAddr, /**< Address of the GV is significant. */
199 LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */
200 LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */
201} LLVMUnnamedAddr;
202
203typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000204 LLVMDefaultStorageClass = 0,
205 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
206 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
207} LLVMDLLStorageClass;
208
209typedef enum {
Robert Widmann1e989de2018-04-06 04:02:39 +0000210 LLVMCCallConv = 0,
211 LLVMFastCallConv = 8,
212 LLVMColdCallConv = 9,
213 LLVMGHCCallConv = 10,
214 LLVMHiPECallConv = 11,
215 LLVMWebKitJSCallConv = 12,
216 LLVMAnyRegCallConv = 13,
217 LLVMPreserveMostCallConv = 14,
218 LLVMPreserveAllCallConv = 15,
219 LLVMSwiftCallConv = 16,
220 LLVMCXXFASTTLSCallConv = 17,
221 LLVMX86StdcallCallConv = 64,
222 LLVMX86FastcallCallConv = 65,
223 LLVMARMAPCSCallConv = 66,
224 LLVMARMAAPCSCallConv = 67,
225 LLVMARMAAPCSVFPCallConv = 68,
226 LLVMMSP430INTRCallConv = 69,
227 LLVMX86ThisCallCallConv = 70,
228 LLVMPTXKernelCallConv = 71,
229 LLVMPTXDeviceCallConv = 72,
230 LLVMSPIRFUNCCallConv = 75,
231 LLVMSPIRKERNELCallConv = 76,
232 LLVMIntelOCLBICallConv = 77,
233 LLVMX8664SysVCallConv = 78,
234 LLVMWin64CallConv = 79,
235 LLVMX86VectorCallCallConv = 80,
236 LLVMHHVMCallConv = 81,
237 LLVMHHVMCCallConv = 82,
238 LLVMX86INTRCallConv = 83,
239 LLVMAVRINTRCallConv = 84,
240 LLVMAVRSIGNALCallConv = 85,
241 LLVMAVRBUILTINCallConv = 86,
242 LLVMAMDGPUVSCallConv = 87,
243 LLVMAMDGPUGSCallConv = 88,
244 LLVMAMDGPUPSCallConv = 89,
245 LLVMAMDGPUCSCallConv = 90,
246 LLVMAMDGPUKERNELCallConv = 91,
247 LLVMX86RegCallCallConv = 92,
248 LLVMAMDGPUHSCallConv = 93,
249 LLVMMSP430BUILTINCallConv = 94,
250 LLVMAMDGPULSCallConv = 95,
251 LLVMAMDGPUESCallConv = 96
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000252} LLVMCallConv;
253
254typedef enum {
Peter Zotov3e4561c2016-04-06 22:21:29 +0000255 LLVMArgumentValueKind,
256 LLVMBasicBlockValueKind,
257 LLVMMemoryUseValueKind,
258 LLVMMemoryDefValueKind,
259 LLVMMemoryPhiValueKind,
260
261 LLVMFunctionValueKind,
262 LLVMGlobalAliasValueKind,
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000263 LLVMGlobalIFuncValueKind,
Peter Zotov3e4561c2016-04-06 22:21:29 +0000264 LLVMGlobalVariableValueKind,
265 LLVMBlockAddressValueKind,
266 LLVMConstantExprValueKind,
267 LLVMConstantArrayValueKind,
268 LLVMConstantStructValueKind,
269 LLVMConstantVectorValueKind,
270
271 LLVMUndefValueValueKind,
Zhengyang Liu75f50e12020-11-24 14:55:24 -0700272 LLVMPoisonValueValueKind,
Peter Zotov3e4561c2016-04-06 22:21:29 +0000273 LLVMConstantAggregateZeroValueKind,
274 LLVMConstantDataArrayValueKind,
275 LLVMConstantDataVectorValueKind,
276 LLVMConstantIntValueKind,
277 LLVMConstantFPValueKind,
278 LLVMConstantPointerNullValueKind,
279 LLVMConstantTokenNoneValueKind,
280
281 LLVMMetadataAsValueValueKind,
282 LLVMInlineAsmValueKind,
283
284 LLVMInstructionValueKind,
285} LLVMValueKind;
286
287typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000288 LLVMIntEQ = 32, /**< equal */
289 LLVMIntNE, /**< not equal */
290 LLVMIntUGT, /**< unsigned greater than */
291 LLVMIntUGE, /**< unsigned greater or equal */
292 LLVMIntULT, /**< unsigned less than */
293 LLVMIntULE, /**< unsigned less or equal */
294 LLVMIntSGT, /**< signed greater than */
295 LLVMIntSGE, /**< signed greater or equal */
296 LLVMIntSLT, /**< signed less than */
297 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000298} LLVMIntPredicate;
299
300typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000301 LLVMRealPredicateFalse, /**< Always false (always folded) */
302 LLVMRealOEQ, /**< True if ordered and equal */
303 LLVMRealOGT, /**< True if ordered and greater than */
304 LLVMRealOGE, /**< True if ordered and greater than or equal */
305 LLVMRealOLT, /**< True if ordered and less than */
306 LLVMRealOLE, /**< True if ordered and less than or equal */
307 LLVMRealONE, /**< True if ordered and operands are unequal */
308 LLVMRealORD, /**< True if ordered (no nans) */
309 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
310 LLVMRealUEQ, /**< True if unordered or equal */
311 LLVMRealUGT, /**< True if unordered or greater than */
312 LLVMRealUGE, /**< True if unordered, greater than, or equal */
313 LLVMRealULT, /**< True if unordered or less than */
314 LLVMRealULE, /**< True if unordered, less than, or equal */
315 LLVMRealUNE, /**< True if unordered or not equal */
316 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000317} LLVMRealPredicate;
318
Bill Wendlingfae14752011-08-12 20:24:12 +0000319typedef enum {
320 LLVMLandingPadCatch, /**< A catch clause */
321 LLVMLandingPadFilter /**< A filter clause */
322} LLVMLandingPadClauseTy;
323
Hans Wennborg5ff71202013-04-16 08:58:59 +0000324typedef enum {
325 LLVMNotThreadLocal = 0,
326 LLVMGeneralDynamicTLSModel,
327 LLVMLocalDynamicTLSModel,
328 LLVMInitialExecTLSModel,
329 LLVMLocalExecTLSModel
330} LLVMThreadLocalMode;
331
Carlo Kokda0ac722013-04-23 13:45:37 +0000332typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000333 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
334 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
335 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000336 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
337 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000338 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000339 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
340 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000341 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000342 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
343 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000344 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000345 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
346 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000347 operations which both read and write
348 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000349 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
350 for loads and Release
351 semantics for stores.
352 Additionally, it guarantees
353 that a total ordering exists
354 between all
355 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000356 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000357} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000358
Carlo Kokda0ac722013-04-23 13:45:37 +0000359typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000360 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
361 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
362 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
363 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
364 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
365 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
366 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
367 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000368 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000369 the old one */
370 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000371 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000372 the old one */
373 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000374 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000375 the old one */
Nick Lewyckyf57e9682019-09-26 00:58:55 +0000376 LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the
377 original using an unsigned comparison and return
378 the old one */
379 LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the
380 old one */
381 LLVMAtomicRMWBinOpFSub /**< Subtract a floating point value and return the
382 old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000383} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000384
Tom Stellard1580dc72014-04-16 17:45:04 +0000385typedef enum {
386 LLVMDSError,
387 LLVMDSWarning,
388 LLVMDSRemark,
389 LLVMDSNote
390} LLVMDiagnosticSeverity;
391
Robert Widmannf108d572018-04-06 02:31:29 +0000392typedef enum {
393 LLVMInlineAsmDialectATT,
394 LLVMInlineAsmDialectIntel
395} LLVMInlineAsmDialect;
396
Robert Widmannbce367702018-05-14 08:09:00 +0000397typedef enum {
398 /**
399 * Emits an error if two values disagree, otherwise the resulting value is
400 * that of the operands.
401 *
402 * @see Module::ModFlagBehavior::Error
403 */
404 LLVMModuleFlagBehaviorError,
405 /**
406 * Emits a warning if two values disagree. The result value will be the
407 * operand for the flag from the first module being linked.
408 *
409 * @see Module::ModFlagBehavior::Warning
410 */
411 LLVMModuleFlagBehaviorWarning,
412 /**
413 * Adds a requirement that another module flag be present and have a
414 * specified value after linking is performed. The value must be a metadata
415 * pair, where the first element of the pair is the ID of the module flag
416 * to be restricted, and the second element of the pair is the value the
417 * module flag should be restricted to. This behavior can be used to
418 * restrict the allowable results (via triggering of an error) of linking
419 * IDs with the **Override** behavior.
420 *
421 * @see Module::ModFlagBehavior::Require
422 */
423 LLVMModuleFlagBehaviorRequire,
424 /**
425 * Uses the specified value, regardless of the behavior or value of the
426 * other module. If both modules specify **Override**, but the values
427 * differ, an error will be emitted.
428 *
429 * @see Module::ModFlagBehavior::Override
430 */
431 LLVMModuleFlagBehaviorOverride,
432 /**
433 * Appends the two values, which are required to be metadata nodes.
434 *
435 * @see Module::ModFlagBehavior::Append
436 */
437 LLVMModuleFlagBehaviorAppend,
438 /**
439 * Appends the two values, which are required to be metadata
440 * nodes. However, duplicate entries in the second list are dropped
441 * during the append operation.
442 *
443 * @see Module::ModFlagBehavior::AppendUnique
444 */
445 LLVMModuleFlagBehaviorAppendUnique,
446} LLVMModuleFlagBehavior;
447
Gregory Szorc34c863a2012-03-21 03:54:29 +0000448/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000449 * Attribute index are either LLVMAttributeReturnIndex,
450 * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
451 */
452enum {
453 LLVMAttributeReturnIndex = 0U,
454 // ISO C restricts enumerator values to range of 'int'
455 // (4294967295 is too large)
456 // LLVMAttributeFunctionIndex = ~0U,
457 LLVMAttributeFunctionIndex = -1,
458};
459
460typedef unsigned LLVMAttributeIndex;
461
462/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000463 * @}
464 */
465
Nick Lewycky0db26542011-05-15 07:20:34 +0000466void LLVMInitializeCore(LLVMPassRegistryRef R);
467
Duncan Sands1cba0a82013-02-17 16:35:51 +0000468/** Deallocate and destroy all ManagedStatic variables.
469 @see llvm::llvm_shutdown
470 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000471void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000472
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000473/*===-- Error handling ----------------------------------------------------===*/
474
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000475char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000476void LLVMDisposeMessage(char *Message);
477
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000478/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000479 * @defgroup LLVMCCoreContext Contexts
480 *
481 * Contexts are execution states for the core LLVM IR system.
482 *
483 * Most types are tied to a context instance. Multiple contexts can
484 * exist simultaneously. A single context is not thread safe. However,
485 * different contexts can execute on different threads simultaneously.
486 *
487 * @{
488 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000489
Tom Stellard1580dc72014-04-16 17:45:04 +0000490typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000491typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000492
Gregory Szorc34c863a2012-03-21 03:54:29 +0000493/**
494 * Create a new context.
495 *
496 * Every call to this function should be paired with a call to
497 * LLVMContextDispose() or the context will leak memory.
498 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000499LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000500
501/**
502 * Obtain the global context instance.
503 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000504LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000505
506/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000507 * Set the diagnostic handler for this context.
508 */
509void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
510 LLVMDiagnosticHandler Handler,
511 void *DiagnosticContext);
512
513/**
Jeroen Ketemaad659c32016-04-08 09:19:02 +0000514 * Get the diagnostic handler of this context.
515 */
516LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
517
518/**
519 * Get the diagnostic context of this context.
520 */
521void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
522
523/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000524 * Set the yield callback function for this context.
525 *
526 * @see LLVMContext::setYieldCallback()
527 */
528void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
529 void *OpaqueHandle);
530
531/**
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000532 * Retrieve whether the given context is set to discard all value names.
533 *
534 * @see LLVMContext::shouldDiscardValueNames()
535 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000536LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000537
538/**
539 * Set whether the given context discards all value names.
540 *
541 * If true, only the names of GlobalValue objects will be available in the IR.
542 * This can be used to save memory and runtime, especially in release mode.
543 *
544 * @see LLVMContext::setDiscardValueNames()
545 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000546void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000547
548/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000549 * Destroy a context instance.
550 *
551 * This should be called for every call to LLVMContextCreate() or memory
552 * will be leaked.
553 */
Owen Anderson6773d382009-07-01 16:58:40 +0000554void LLVMContextDispose(LLVMContextRef C);
555
Tom Stellard1580dc72014-04-16 17:45:04 +0000556/**
557 * Return a string representation of the DiagnosticInfo. Use
558 * LLVMDisposeMessage to free the string.
559 *
560 * @see DiagnosticInfo::print()
561 */
562char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
563
564/**
565 * Return an enum LLVMDiagnosticSeverity.
566 *
567 * @see DiagnosticInfo::getSeverity()
568 */
569LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
570
Amaury Sechet56f056c2016-04-04 22:00:25 +0000571unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000572 unsigned SLen);
Amaury Sechet56f056c2016-04-04 22:00:25 +0000573unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000574
Gregory Szorc34c863a2012-03-21 03:54:29 +0000575/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000576 * Return an unique id given the name of a enum attribute,
Amaury Sechet60b31452016-04-20 01:02:12 +0000577 * or 0 if no attribute by that name exists.
578 *
579 * See http://llvm.org/docs/LangRef.html#parameter-attributes
580 * and http://llvm.org/docs/LangRef.html#function-attributes
581 * for the list of available attributes.
582 *
583 * NB: Attribute names and/or id are subject to change without
584 * going through the C API deprecation cycle.
585 */
Amaury Sechet5db224e2016-06-12 06:17:24 +0000586unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
Amaury Sechet48b06652016-06-12 07:56:21 +0000587unsigned LLVMGetLastEnumAttributeKind(void);
Amaury Sechet5db224e2016-06-12 06:17:24 +0000588
589/**
590 * Create an enum attribute.
591 */
592LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
593 uint64_t Val);
594
595/**
596 * Get the unique id corresponding to the enum attribute
597 * passed as argument.
598 */
599unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
600
601/**
602 * Get the enum attribute's value. 0 is returned if none exists.
603 */
604uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
605
606/**
607 * Create a string attribute.
608 */
609LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
610 const char *K, unsigned KLength,
611 const char *V, unsigned VLength);
612
613/**
614 * Get the string attribute's kind.
615 */
616const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
617
618/**
619 * Get the string attribute's value.
620 */
621const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
622
623/**
624 * Check for the different types of attributes.
625 */
626LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
627LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
Amaury Sechet60b31452016-04-20 01:02:12 +0000628
629/**
Nick Lewyckyfe431682020-11-30 11:34:12 -0800630 * Obtain a Type from a context by its registered name.
631 */
632LLVMTypeRef LLVMGetTypeByName2(LLVMContextRef C, const char *Name);
633
634/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000635 * @}
636 */
637
Gregory Szorc52d26602012-03-21 07:28:27 +0000638/**
639 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000640 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000641 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000642 * module is effectively a translation unit or a collection of
643 * translation units merged together.
644 *
645 * @{
646 */
647
Gregory Szorc34c863a2012-03-21 03:54:29 +0000648/**
649 * Create a new, empty module in the global context.
650 *
651 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
652 * LLVMGetGlobalContext() as the context parameter.
653 *
654 * Every invocation should be paired with LLVMDisposeModule() or memory
655 * will be leaked.
656 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000657LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000658
659/**
660 * Create a new, empty module in a specific context.
661 *
662 * Every invocation should be paired with LLVMDisposeModule() or memory
663 * will be leaked.
664 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000665LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
666 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000667/**
668 * Return an exact copy of the specified module.
669 */
670LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000671
Gregory Szorc34c863a2012-03-21 03:54:29 +0000672/**
673 * Destroy a module instance.
674 *
675 * This must be called for every created module or memory will be
676 * leaked.
677 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000678void LLVMDisposeModule(LLVMModuleRef M);
679
Gregory Szorc34c863a2012-03-21 03:54:29 +0000680/**
Peter Zotov0a2fa0a2016-04-05 13:56:59 +0000681 * Obtain the identifier of a module.
682 *
683 * @param M Module to obtain identifier of
684 * @param Len Out parameter which holds the length of the returned string.
685 * @return The identifier of M.
686 * @see Module::getModuleIdentifier()
687 */
688const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
689
690/**
691 * Set the identifier of a module to a string Ident with length Len.
692 *
693 * @param M The module to set identifier
694 * @param Ident The string to set M's identifier to
695 * @param Len Length of Ident
696 * @see Module::setModuleIdentifier()
697 */
698void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
699
700/**
Robert Widmann490a5802018-01-30 21:34:29 +0000701 * Obtain the module's original source file name.
702 *
703 * @param M Module to obtain the name of
704 * @param Len Out parameter which holds the length of the returned string
705 * @return The original source file name of M
706 * @see Module::getSourceFileName()
707 */
708const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len);
709
710/**
711 * Set the original source file name of a module to a string Name with length
712 * Len.
713 *
714 * @param M The module to set the source file name of
715 * @param Name The string to set M's source file name to
716 * @param Len Length of Name
717 * @see Module::setSourceFileName()
718 */
719void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len);
720
721/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000722 * Obtain the data layout for a module.
723 *
Amaury Sechetf3549c42016-02-16 00:23:52 +0000724 * @see Module::getDataLayoutStr()
725 *
726 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
727 * but match the name of another method on the module. Prefer the use
728 * of LLVMGetDataLayoutStr, which is not ambiguous.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000729 */
Amaury Sechetf3549c42016-02-16 00:23:52 +0000730const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000731const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000732
733/**
734 * Set the data layout for a module.
735 *
736 * @see Module::setDataLayout()
737 */
Amaury Sechet6ada31c2016-02-15 23:40:06 +0000738void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000739
Gregory Szorc34c863a2012-03-21 03:54:29 +0000740/**
741 * Obtain the target triple for a module.
742 *
743 * @see Module::getTargetTriple()
744 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000745const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000746
747/**
748 * Set the target triple for a module.
749 *
750 * @see Module::setTargetTriple()
751 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000752void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
753
Gregory Szorc34c863a2012-03-21 03:54:29 +0000754/**
Robert Widmannbce367702018-05-14 08:09:00 +0000755 * Returns the module flags as an array of flag-key-value triples. The caller
756 * is responsible for freeing this array by calling
757 * \c LLVMDisposeModuleFlagsMetadata.
758 *
759 * @see Module::getModuleFlagsMetadata()
760 */
761LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(LLVMModuleRef M, size_t *Len);
762
763/**
764 * Destroys module flags metadata entries.
765 */
766void LLVMDisposeModuleFlagsMetadata(LLVMModuleFlagEntry *Entries);
767
768/**
769 * Returns the flag behavior for a module flag entry at a specific index.
770 *
771 * @see Module::ModuleFlagEntry::Behavior
772 */
773LLVMModuleFlagBehavior
774LLVMModuleFlagEntriesGetFlagBehavior(LLVMModuleFlagEntry *Entries,
775 unsigned Index);
776
777/**
778 * Returns the key for a module flag entry at a specific index.
779 *
780 * @see Module::ModuleFlagEntry::Key
781 */
782const char *LLVMModuleFlagEntriesGetKey(LLVMModuleFlagEntry *Entries,
783 unsigned Index, size_t *Len);
784
785/**
786 * Returns the metadata for a module flag entry at a specific index.
787 *
788 * @see Module::ModuleFlagEntry::Val
789 */
790LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries,
791 unsigned Index);
792
793/**
794 * Add a module-level flag to the module-level flags metadata if it doesn't
795 * already exist.
796 *
797 * @see Module::getModuleFlag()
798 */
799LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRef M,
800 const char *Key, size_t KeyLen);
801
802/**
803 * Add a module-level flag to the module-level flags metadata if it doesn't
804 * already exist.
805 *
806 * @see Module::addModuleFlag()
807 */
808void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior,
809 const char *Key, size_t KeyLen,
810 LLVMMetadataRef Val);
811
812/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000813 * Dump a representation of a module to stderr.
814 *
815 * @see Module::dump()
816 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000817void LLVMDumpModule(LLVMModuleRef M);
818
Gregory Szorc34c863a2012-03-21 03:54:29 +0000819/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000820 * Print a representation of a module to a file. The ErrorMessage needs to be
821 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
822 *
823 * @see Module::print()
824 */
825LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
826 char **ErrorMessage);
827
828/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000829 * Return a string representation of the module. Use
830 * LLVMDisposeMessage to free the string.
831 *
832 * @see Module::print()
833 */
834char *LLVMPrintModuleToString(LLVMModuleRef M);
835
836/**
Robert Widmannf108d572018-04-06 02:31:29 +0000837 * Get inline assembly for a module.
838 *
839 * @see Module::getModuleInlineAsm()
840 */
841const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len);
842
843/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000844 * Set inline assembly for a module.
845 *
846 * @see Module::setModuleInlineAsm()
847 */
Robert Widmannf108d572018-04-06 02:31:29 +0000848void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len);
849
850/**
851 * Append inline assembly to a module.
852 *
853 * @see Module::appendModuleInlineAsm()
854 */
855void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len);
856
857/**
858 * Create the specified uniqued inline asm string.
859 *
860 * @see InlineAsm::get()
861 */
862LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty,
863 char *AsmString, size_t AsmStringSize,
864 char *Constraints, size_t ConstraintsSize,
865 LLVMBool HasSideEffects, LLVMBool IsAlignStack,
866 LLVMInlineAsmDialect Dialect);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000867
Gregory Szorc34c863a2012-03-21 03:54:29 +0000868/**
869 * Obtain the context to which this module is associated.
870 *
871 * @see Module::getContext()
872 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000873LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
874
Nick Lewyckyfe431682020-11-30 11:34:12 -0800875/** Deprecated: Use LLVMGetTypeByName2 instead. */
Gregory Szorc34c863a2012-03-21 03:54:29 +0000876LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000877
Gregory Szorc34c863a2012-03-21 03:54:29 +0000878/**
Robert Widmann0a35b762018-08-30 17:09:43 +0000879 * Obtain an iterator to the first NamedMDNode in a Module.
880 *
881 * @see llvm::Module::named_metadata_begin()
882 */
883LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M);
884
885/**
886 * Obtain an iterator to the last NamedMDNode in a Module.
887 *
888 * @see llvm::Module::named_metadata_end()
889 */
890LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M);
891
892/**
893 * Advance a NamedMDNode iterator to the next NamedMDNode.
894 *
895 * Returns NULL if the iterator was already at the end and there are no more
896 * named metadata nodes.
897 */
898LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
899
900/**
901 * Decrement a NamedMDNode iterator to the previous NamedMDNode.
902 *
903 * Returns NULL if the iterator was already at the beginning and there are
904 * no previous named metadata nodes.
905 */
906LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
907
908/**
909 * Retrieve a NamedMDNode with the given name, returning NULL if no such
910 * node exists.
911 *
912 * @see llvm::Module::getNamedMetadata()
913 */
914LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M,
915 const char *Name, size_t NameLen);
916
917/**
918 * Retrieve a NamedMDNode with the given name, creating a new node if no such
919 * node exists.
920 *
921 * @see llvm::Module::getOrInsertNamedMetadata()
922 */
923LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M,
924 const char *Name,
925 size_t NameLen);
926
927/**
928 * Retrieve the name of a NamedMDNode.
929 *
930 * @see llvm::NamedMDNode::getName()
931 */
932const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NamedMD,
933 size_t *NameLen);
934
935/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000936 * Obtain the number of operands for named metadata in a module.
937 *
938 * @see llvm::Module::getNamedMetadata()
939 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000940unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000941
942/**
943 * Obtain the named metadata operands for a module.
944 *
945 * The passed LLVMValueRef pointer should refer to an array of
946 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
947 * array will be populated with the LLVMValueRef instances. Each
948 * instance corresponds to a llvm::MDNode.
949 *
950 * @see llvm::Module::getNamedMetadata()
951 * @see llvm::MDNode::getOperand()
952 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000953void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
954 LLVMValueRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000955
956/**
957 * Add an operand to named metadata.
958 *
959 * @see llvm::Module::getNamedMetadata()
960 * @see llvm::MDNode::addOperand()
961 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000962void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
Gregory Szorc34c863a2012-03-21 03:54:29 +0000963 LLVMValueRef Val);
964
Gregory Szorc52d26602012-03-21 07:28:27 +0000965/**
Saleem Abdulrasool0d1cbcc2018-10-10 23:53:12 +0000966 * Return the directory of the debug location for this value, which must be
967 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
968 *
969 * @see llvm::Instruction::getDebugLoc()
970 * @see llvm::GlobalVariable::getDebugInfo()
971 * @see llvm::Function::getSubprogram()
972 */
973const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length);
974
975/**
976 * Return the filename of the debug location for this value, which must be
977 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
978 *
979 * @see llvm::Instruction::getDebugLoc()
980 * @see llvm::GlobalVariable::getDebugInfo()
981 * @see llvm::Function::getSubprogram()
982 */
983const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length);
984
985/**
986 * Return the line number of the debug location for this value, which must be
987 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
988 *
989 * @see llvm::Instruction::getDebugLoc()
990 * @see llvm::GlobalVariable::getDebugInfo()
991 * @see llvm::Function::getSubprogram()
992 */
993unsigned LLVMGetDebugLocLine(LLVMValueRef Val);
994
995/**
996 * Return the column number of the debug location for this value, which must be
997 * an llvm::Instruction.
998 *
999 * @see llvm::Instruction::getDebugLoc()
1000 */
1001unsigned LLVMGetDebugLocColumn(LLVMValueRef Val);
1002
1003/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001004 * Add a function to a module under a specified name.
1005 *
1006 * @see llvm::Function::Create()
1007 */
1008LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1009 LLVMTypeRef FunctionTy);
1010
1011/**
1012 * Obtain a Function value from a Module by its name.
1013 *
1014 * The returned value corresponds to a llvm::Function value.
1015 *
1016 * @see llvm::Module::getFunction()
1017 */
1018LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
1019
1020/**
1021 * Obtain an iterator to the first Function in a Module.
1022 *
1023 * @see llvm::Module::begin()
1024 */
1025LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
1026
1027/**
1028 * Obtain an iterator to the last Function in a Module.
1029 *
1030 * @see llvm::Module::end()
1031 */
1032LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
1033
1034/**
1035 * Advance a Function iterator to the next Function.
1036 *
1037 * Returns NULL if the iterator was already at the end and there are no more
1038 * functions.
1039 */
1040LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
1041
1042/**
1043 * Decrement a Function iterator to the previous Function.
1044 *
1045 * Returns NULL if the iterator was already at the beginning and there are
1046 * no previous functions.
1047 */
1048LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001049
Robert Widmannf108d572018-04-06 02:31:29 +00001050/** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */
1051void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
1052
Gregory Szorc34c863a2012-03-21 03:54:29 +00001053/**
1054 * @}
1055 */
1056
1057/**
1058 * @defgroup LLVMCCoreType Types
1059 *
1060 * Types represent the type of a value.
1061 *
1062 * Types are associated with a context instance. The context internally
1063 * deduplicates types so there is only 1 instance of a specific type
1064 * alive at a time. In other words, a unique type is shared among all
1065 * consumers within a context.
1066 *
1067 * A Type in the C API corresponds to llvm::Type.
1068 *
1069 * Types have the following hierarchy:
1070 *
Gordon Henriksen76a03742007-09-18 03:18:57 +00001071 * types:
1072 * integer type
1073 * real type
1074 * function type
1075 * sequence types:
1076 * array type
1077 * pointer type
1078 * vector type
1079 * void type
1080 * label type
1081 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +00001082 *
1083 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001084 */
1085
Gregory Szorc34c863a2012-03-21 03:54:29 +00001086/**
1087 * Obtain the enumerated type of a Type instance.
1088 *
1089 * @see llvm::Type:getTypeID()
1090 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001091LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001092
1093/**
1094 * Whether the type has a known size.
1095 *
1096 * Things that don't have a size are abstract types, labels, and void.a
1097 *
1098 * @see llvm::Type::isSized()
1099 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +00001100LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +00001101
Gregory Szorc34c863a2012-03-21 03:54:29 +00001102/**
1103 * Obtain the context to which this type instance is associated.
1104 *
1105 * @see llvm::Type::getContext()
1106 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001107LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
1108
Gregory Szorc34c863a2012-03-21 03:54:29 +00001109/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +00001110 * Dump a representation of a type to stderr.
1111 *
1112 * @see llvm::Type::dump()
1113 */
1114void LLVMDumpType(LLVMTypeRef Val);
1115
1116/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +00001117 * Return a string representation of the type. Use
1118 * LLVMDisposeMessage to free the string.
1119 *
1120 * @see llvm::Type::print()
1121 */
1122char *LLVMPrintTypeToString(LLVMTypeRef Val);
1123
1124/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001125 * @defgroup LLVMCCoreTypeInt Integer Types
1126 *
1127 * Functions in this section operate on integer types.
1128 *
1129 * @{
1130 */
1131
1132/**
1133 * Obtain an integer type from a context with specified bit width.
1134 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001135LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
1136LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
1137LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
1138LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
1139LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001140LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001141LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
1142
Gregory Szorc34c863a2012-03-21 03:54:29 +00001143/**
1144 * Obtain an integer type from the global context with a specified bit
1145 * width.
1146 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001147LLVMTypeRef LLVMInt1Type(void);
1148LLVMTypeRef LLVMInt8Type(void);
1149LLVMTypeRef LLVMInt16Type(void);
1150LLVMTypeRef LLVMInt32Type(void);
1151LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001152LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001153LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001154unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001155
Gregory Szorc34c863a2012-03-21 03:54:29 +00001156/**
1157 * @}
1158 */
1159
1160/**
1161 * @defgroup LLVMCCoreTypeFloat Floating Point Types
1162 *
1163 * @{
1164 */
1165
1166/**
1167 * Obtain a 16-bit floating point type from a context.
1168 */
Dan Gohman518cda42011-12-17 00:04:22 +00001169LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001170
1171/**
Ties Stuij8c24f332020-03-31 23:49:38 +01001172 * Obtain a 16-bit brain floating point type from a context.
1173 */
1174LLVMTypeRef LLVMBFloatTypeInContext(LLVMContextRef C);
1175
1176/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001177 * Obtain a 32-bit floating point type from a context.
1178 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001179LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001180
1181/**
1182 * Obtain a 64-bit floating point type from a context.
1183 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001184LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001185
1186/**
1187 * Obtain a 80-bit floating point type (X87) from a context.
1188 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001189LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001190
1191/**
1192 * Obtain a 128-bit floating point type (112-bit mantissa) from a
1193 * context.
1194 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001195LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001196
1197/**
1198 * Obtain a 128-bit floating point type (two 64-bits) from a context.
1199 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001200LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
1201
Gregory Szorc34c863a2012-03-21 03:54:29 +00001202/**
1203 * Obtain a floating point type from the global context.
1204 *
1205 * These map to the functions in this group of the same name.
1206 */
Dan Gohman518cda42011-12-17 00:04:22 +00001207LLVMTypeRef LLVMHalfType(void);
Ties Stuij8c24f332020-03-31 23:49:38 +01001208LLVMTypeRef LLVMBFloatType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001209LLVMTypeRef LLVMFloatType(void);
1210LLVMTypeRef LLVMDoubleType(void);
1211LLVMTypeRef LLVMX86FP80Type(void);
1212LLVMTypeRef LLVMFP128Type(void);
1213LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001214
Gregory Szorc34c863a2012-03-21 03:54:29 +00001215/**
1216 * @}
1217 */
1218
1219/**
1220 * @defgroup LLVMCCoreTypeFunction Function Types
1221 *
1222 * @{
1223 */
1224
1225/**
1226 * Obtain a function type consisting of a specified signature.
1227 *
1228 * The function is defined as a tuple of a return Type, a list of
1229 * parameter types, and whether the function is variadic.
1230 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001231LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
1232 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001233 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001234
1235/**
1236 * Returns whether a function type is variadic.
1237 */
Chris Lattner25963c62010-01-09 22:27:07 +00001238LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001239
1240/**
1241 * Obtain the Type this function Type returns.
1242 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001243LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001244
1245/**
1246 * Obtain the number of parameters this function accepts.
1247 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001248unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001249
1250/**
1251 * Obtain the types of a function's parameters.
1252 *
1253 * The Dest parameter should point to a pre-allocated array of
1254 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
1255 * first LLVMCountParamTypes() entries in the array will be populated
1256 * with LLVMTypeRef instances.
1257 *
1258 * @param FunctionTy The function type to operate on.
1259 * @param Dest Memory address of an array to be filled with result.
1260 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001261void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001262
Gregory Szorc34c863a2012-03-21 03:54:29 +00001263/**
1264 * @}
1265 */
1266
1267/**
1268 * @defgroup LLVMCCoreTypeStruct Structure Types
1269 *
1270 * These functions relate to LLVMTypeRef instances.
1271 *
1272 * @see llvm::StructType
1273 *
1274 * @{
1275 */
1276
1277/**
1278 * Create a new structure type in a context.
1279 *
1280 * A structure is specified by a list of inner elements/types and
1281 * whether these can be packed together.
1282 *
1283 * @see llvm::StructType::create()
1284 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001285LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +00001286 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001287
1288/**
1289 * Create a new structure type in the global context.
1290 *
1291 * @see llvm::StructType::create()
1292 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001293LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001294 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001295
1296/**
1297 * Create an empty structure in a context having a specified name.
1298 *
1299 * @see llvm::StructType::create()
1300 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001301LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001302
1303/**
1304 * Obtain the name of a structure.
1305 *
1306 * @see llvm::StructType::getName()
1307 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +00001308const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001309
1310/**
1311 * Set the contents of a structure type.
1312 *
1313 * @see llvm::StructType::setBody()
1314 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001315void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
1316 unsigned ElementCount, LLVMBool Packed);
1317
Gregory Szorc34c863a2012-03-21 03:54:29 +00001318/**
1319 * Get the number of elements defined inside the structure.
1320 *
1321 * @see llvm::StructType::getNumElements()
1322 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001323unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001324
1325/**
1326 * Get the elements within a structure.
1327 *
1328 * The function is passed the address of a pre-allocated array of
1329 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
1330 * invocation, this array will be populated with the structure's
1331 * elements. The objects in the destination array will have a lifetime
1332 * of the structure type itself, which is the lifetime of the context it
1333 * is contained in.
1334 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001335void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001336
1337/**
Peter Zotovc164a3f2015-06-04 09:09:53 +00001338 * Get the type of the element at a given index in the structure.
1339 *
1340 * @see llvm::StructType::getTypeAtIndex()
1341 */
1342LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
1343
1344/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001345 * Determine whether a structure is packed.
1346 *
1347 * @see llvm::StructType::isPacked()
1348 */
Chris Lattner25963c62010-01-09 22:27:07 +00001349LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001350
1351/**
1352 * Determine whether a structure is opaque.
1353 *
1354 * @see llvm::StructType::isOpaque()
1355 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001356LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1357
Gregory Szorc34c863a2012-03-21 03:54:29 +00001358/**
whitequarkb4861072018-09-18 01:47:37 +00001359 * Determine whether a structure is literal.
1360 *
1361 * @see llvm::StructType::isLiteral()
1362 */
1363LLVMBool LLVMIsLiteralStruct(LLVMTypeRef StructTy);
1364
1365/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001366 * @}
1367 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001368
Gregory Szorc34c863a2012-03-21 03:54:29 +00001369/**
1370 * @defgroup LLVMCCoreTypeSequential Sequential Types
1371 *
1372 * Sequential types represents "arrays" of types. This is a super class
1373 * for array, vector, and pointer types.
1374 *
1375 * @{
1376 */
1377
1378/**
1379 * Obtain the type of elements within a sequential type.
1380 *
1381 * This works on array, vector, and pointer types.
1382 *
1383 * @see llvm::SequentialType::getElementType()
1384 */
1385LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1386
1387/**
whitequarkf6059fd2017-06-05 11:49:52 +00001388 * Returns type's subtypes
1389 *
1390 * @see llvm::Type::subtypes()
1391 */
1392void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr);
1393
1394/**
1395 * Return the number of types in the derived type.
1396 *
1397 * @see llvm::Type::getNumContainedTypes()
1398 */
1399unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp);
1400
1401/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001402 * Create a fixed size array type that refers to a specific type.
1403 *
1404 * The created type will exist in the context that its element type
1405 * exists in.
1406 *
1407 * @see llvm::ArrayType::get()
1408 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001409LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001410
1411/**
1412 * Obtain the length of an array type.
1413 *
1414 * This only works on types that represent arrays.
1415 *
1416 * @see llvm::ArrayType::getNumElements()
1417 */
1418unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1419
1420/**
1421 * Create a pointer type that points to a defined type.
1422 *
1423 * The created type will exist in the context that its pointee type
1424 * exists in.
1425 *
1426 * @see llvm::PointerType::get()
1427 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001428LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001429
1430/**
1431 * Obtain the address space of a pointer type.
1432 *
1433 * This only works on types that represent pointers.
1434 *
1435 * @see llvm::PointerType::getAddressSpace()
1436 */
1437unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1438
1439/**
1440 * Create a vector type that contains a defined type and has a specific
1441 * number of elements.
1442 *
1443 * The created type will exist in the context thats its element type
1444 * exists in.
1445 *
1446 * @see llvm::VectorType::get()
1447 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001448LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001449
Gregory Szorc34c863a2012-03-21 03:54:29 +00001450/**
Craig Disselkoenc3783842020-10-28 16:48:22 -04001451 * Create a vector type that contains a defined type and has a scalable
1452 * number of elements.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001453 *
Craig Disselkoenc3783842020-10-28 16:48:22 -04001454 * The created type will exist in the context thats its element type
1455 * exists in.
1456 *
1457 * @see llvm::ScalableVectorType::get()
1458 */
1459LLVMTypeRef LLVMScalableVectorType(LLVMTypeRef ElementType,
1460 unsigned ElementCount);
1461
1462/**
1463 * Obtain the (possibly scalable) number of elements in a vector type.
1464 *
1465 * This only works on types that represent vectors (fixed or scalable).
Gregory Szorc34c863a2012-03-21 03:54:29 +00001466 *
1467 * @see llvm::VectorType::getNumElements()
1468 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001469unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1470
Gregory Szorc34c863a2012-03-21 03:54:29 +00001471/**
1472 * @}
1473 */
1474
1475/**
1476 * @defgroup LLVMCCoreTypeOther Other Types
1477 *
1478 * @{
1479 */
1480
1481/**
1482 * Create a void type in a context.
1483 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001484LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001485
1486/**
1487 * Create a label type in a context.
1488 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001489LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001490
1491/**
1492 * Create a X86 MMX type in a context.
1493 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001494LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001495
Gregory Szorc34c863a2012-03-21 03:54:29 +00001496/**
whitequark131f98f2017-10-27 11:51:40 +00001497 * Create a token type in a context.
1498 */
1499LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C);
1500
1501/**
1502 * Create a metadata type in a context.
1503 */
1504LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C);
1505
1506/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001507 * These are similar to the above functions except they operate on the
1508 * global context.
1509 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001510LLVMTypeRef LLVMVoidType(void);
1511LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001512LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001513
Gregory Szorc34c863a2012-03-21 03:54:29 +00001514/**
1515 * @}
1516 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001517
Gregory Szorc34c863a2012-03-21 03:54:29 +00001518/**
1519 * @}
1520 */
1521
1522/**
1523 * @defgroup LLVMCCoreValues Values
1524 *
1525 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001526 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001527 *
1528 * LLVMValueRef essentially represents llvm::Value. There is a rich
1529 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001530 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001531 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001532 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001533 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1534 * functions are defined by a macro, so it isn't obvious which are
1535 * available by looking at the Doxygen source code. Instead, look at the
1536 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1537 * of value names given. These value names also correspond to classes in
1538 * the llvm::Value hierarchy.
1539 *
1540 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001541 */
1542
Gordon Henriksen29e38942008-12-19 18:39:45 +00001543#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1544 macro(Argument) \
1545 macro(BasicBlock) \
1546 macro(InlineAsm) \
1547 macro(User) \
1548 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001549 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001550 macro(ConstantAggregateZero) \
1551 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001552 macro(ConstantDataSequential) \
1553 macro(ConstantDataArray) \
1554 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001555 macro(ConstantExpr) \
1556 macro(ConstantFP) \
1557 macro(ConstantInt) \
1558 macro(ConstantPointerNull) \
1559 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001560 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001561 macro(ConstantVector) \
1562 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001563 macro(GlobalAlias) \
whitequarkd299b2c2018-09-18 00:01:12 +00001564 macro(GlobalIFunc) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001565 macro(GlobalObject) \
1566 macro(Function) \
1567 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001568 macro(UndefValue) \
Zhengyang Liu75f50e12020-11-24 14:55:24 -07001569 macro(PoisonValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001570 macro(Instruction) \
Cameron McInally60786f92019-10-07 21:33:39 +00001571 macro(UnaryOperator) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001572 macro(BinaryOperator) \
1573 macro(CallInst) \
1574 macro(IntrinsicInst) \
1575 macro(DbgInfoIntrinsic) \
Hsiangkai Wangef72e482018-08-06 03:59:47 +00001576 macro(DbgVariableIntrinsic) \
1577 macro(DbgDeclareInst) \
1578 macro(DbgLabelInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001579 macro(MemIntrinsic) \
1580 macro(MemCpyInst) \
1581 macro(MemMoveInst) \
1582 macro(MemSetInst) \
1583 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001584 macro(FCmpInst) \
1585 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001586 macro(ExtractElementInst) \
1587 macro(GetElementPtrInst) \
1588 macro(InsertElementInst) \
1589 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001590 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001591 macro(PHINode) \
1592 macro(SelectInst) \
1593 macro(ShuffleVectorInst) \
1594 macro(StoreInst) \
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00001595 macro(BranchInst) \
1596 macro(IndirectBrInst) \
1597 macro(InvokeInst) \
1598 macro(ReturnInst) \
1599 macro(SwitchInst) \
1600 macro(UnreachableInst) \
1601 macro(ResumeInst) \
1602 macro(CleanupReturnInst) \
1603 macro(CatchReturnInst) \
Nick Lewyckyf57e9682019-09-26 00:58:55 +00001604 macro(CatchSwitchInst) \
1605 macro(CallBrInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001606 macro(FuncletPadInst) \
1607 macro(CatchPadInst) \
1608 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001609 macro(UnaryInstruction) \
1610 macro(AllocaInst) \
1611 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001612 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001613 macro(BitCastInst) \
1614 macro(FPExtInst) \
1615 macro(FPToSIInst) \
1616 macro(FPToUIInst) \
1617 macro(FPTruncInst) \
1618 macro(IntToPtrInst) \
1619 macro(PtrToIntInst) \
1620 macro(SExtInst) \
1621 macro(SIToFPInst) \
1622 macro(TruncInst) \
1623 macro(UIToFPInst) \
1624 macro(ZExtInst) \
1625 macro(ExtractValueInst) \
1626 macro(LoadInst) \
Nick Lewyckyf57e9682019-09-26 00:58:55 +00001627 macro(VAArgInst) \
aqjunee87d7162019-11-07 01:17:49 +09001628 macro(FreezeInst) \
Nick Lewyckyf57e9682019-09-26 00:58:55 +00001629 macro(AtomicCmpXchgInst) \
1630 macro(AtomicRMWInst) \
1631 macro(FenceInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001632
Gregory Szorc34c863a2012-03-21 03:54:29 +00001633/**
1634 * @defgroup LLVMCCoreValueGeneral General APIs
1635 *
1636 * Functions in this section work on all LLVMValueRef instances,
1637 * regardless of their sub-type. They correspond to functions available
1638 * on llvm::Value.
1639 *
1640 * @{
1641 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001642
Gregory Szorc34c863a2012-03-21 03:54:29 +00001643/**
1644 * Obtain the type of a value.
1645 *
1646 * @see llvm::Value::getType()
1647 */
1648LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1649
1650/**
Peter Zotov3e4561c2016-04-06 22:21:29 +00001651 * Obtain the enumerated type of a Value instance.
1652 *
1653 * @see llvm::Value::getValueID()
1654 */
1655LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
1656
1657/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001658 * Obtain the string name of a value.
1659 *
1660 * @see llvm::Value::getName()
1661 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001662const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001663
1664/**
1665 * Set the string name of a value.
1666 *
1667 * @see llvm::Value::setName()
1668 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001669void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001670
1671/**
1672 * Dump a representation of a value to stderr.
1673 *
1674 * @see llvm::Value::dump()
1675 */
1676void LLVMDumpValue(LLVMValueRef Val);
1677
1678/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001679 * Return a string representation of the value. Use
1680 * LLVMDisposeMessage to free the string.
1681 *
1682 * @see llvm::Value::print()
1683 */
1684char *LLVMPrintValueToString(LLVMValueRef Val);
1685
1686/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001687 * Replace all uses of a value with another one.
1688 *
1689 * @see llvm::Value::replaceAllUsesWith()
1690 */
1691void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1692
1693/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001694 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001695 */
1696LLVMBool LLVMIsConstant(LLVMValueRef Val);
1697
1698/**
1699 * Determine whether a value instance is undefined.
1700 */
1701LLVMBool LLVMIsUndef(LLVMValueRef Val);
1702
1703/**
Zhengyang Liu75f50e12020-11-24 14:55:24 -07001704 * Determine whether a value instance is poisonous.
1705 */
1706LLVMBool LLVMIsPoison(LLVMValueRef Val);
1707
1708/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001709 * Convert value instances between types.
1710 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001711 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001712 * series of functions allows you to cast an instance to a specific
1713 * type.
1714 *
1715 * If the cast is not valid for the specified type, NULL is returned.
1716 *
1717 * @see llvm::dyn_cast_or_null<>
1718 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001719#define LLVM_DECLARE_VALUE_CAST(name) \
1720 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1721LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1722
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001723LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1724LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1725
Robert Widmann025c78f2018-05-19 15:08:36 +00001726/** Deprecated: Use LLVMGetValueName2 instead. */
1727const char *LLVMGetValueName(LLVMValueRef Val);
1728/** Deprecated: Use LLVMSetValueName2 instead. */
1729void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1730
Gregory Szorc34c863a2012-03-21 03:54:29 +00001731/**
1732 * @}
1733 */
1734
1735/**
1736 * @defgroup LLVMCCoreValueUses Usage
1737 *
1738 * This module defines functions that allow you to inspect the uses of a
1739 * LLVMValueRef.
1740 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001741 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001742 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1743 * llvm::User and llvm::Value.
1744 *
1745 * @{
1746 */
1747
1748/**
1749 * Obtain the first use of a value.
1750 *
1751 * Uses are obtained in an iterator fashion. First, call this function
1752 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001753 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001754 * LLVMGetNextUse() returns NULL.
1755 *
1756 * @see llvm::Value::use_begin()
1757 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001758LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001759
1760/**
1761 * Obtain the next use of a value.
1762 *
1763 * This effectively advances the iterator. It returns NULL if you are on
1764 * the final use and no more are available.
1765 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001766LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001767
1768/**
1769 * Obtain the user value for a user.
1770 *
1771 * The returned value corresponds to a llvm::User type.
1772 *
1773 * @see llvm::Use::getUser()
1774 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001775LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001776
1777/**
1778 * Obtain the value this use corresponds to.
1779 *
1780 * @see llvm::Use::get().
1781 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001782LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001783
Gregory Szorc34c863a2012-03-21 03:54:29 +00001784/**
1785 * @}
1786 */
1787
1788/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001789 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001790 *
1791 * Function in this group pertain to LLVMValueRef instances that descent
1792 * from llvm::User. This includes constants, instructions, and
1793 * operators.
1794 *
1795 * @{
1796 */
1797
1798/**
1799 * Obtain an operand at a specific index in a llvm::User value.
1800 *
1801 * @see llvm::User::getOperand()
1802 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001803LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001804
1805/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001806 * Obtain the use of an operand at a specific index in a llvm::User value.
1807 *
1808 * @see llvm::User::getOperandUse()
1809 */
1810LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1811
1812/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001813 * Set an operand at a specific index in a llvm::User value.
1814 *
1815 * @see llvm::User::setOperand()
1816 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001817void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001818
1819/**
1820 * Obtain the number of operands in a llvm::User value.
1821 *
1822 * @see llvm::User::getNumOperands()
1823 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001824int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001825
Gregory Szorc34c863a2012-03-21 03:54:29 +00001826/**
1827 * @}
1828 */
1829
1830/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001831 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001832 *
1833 * This section contains APIs for interacting with LLVMValueRef that
1834 * correspond to llvm::Constant instances.
1835 *
1836 * These functions will work for any LLVMValueRef in the llvm::Constant
1837 * class hierarchy.
1838 *
1839 * @{
1840 */
1841
1842/**
1843 * Obtain a constant value referring to the null instance of a type.
1844 *
1845 * @see llvm::Constant::getNullValue()
1846 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001847LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001848
1849/**
1850 * Obtain a constant value referring to the instance of a type
1851 * consisting of all ones.
1852 *
1853 * This is only valid for integer types.
1854 *
1855 * @see llvm::Constant::getAllOnesValue()
1856 */
1857LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1858
1859/**
1860 * Obtain a constant value referring to an undefined value of a type.
1861 *
1862 * @see llvm::UndefValue::get()
1863 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001864LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001865
1866/**
Zhengyang Liu75f50e12020-11-24 14:55:24 -07001867 * Obtain a constant value referring to a poison value of a type.
1868 *
1869 * @see llvm::PoisonValue::get()
1870 */
1871LLVMValueRef LLVMGetPoison(LLVMTypeRef Ty);
1872
1873/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001874 * Determine whether a value instance is null.
1875 *
1876 * @see llvm::Constant::isNullValue()
1877 */
Chris Lattner25963c62010-01-09 22:27:07 +00001878LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001879
1880/**
1881 * Obtain a constant that is a constant pointer pointing to NULL for a
1882 * specified type.
1883 */
Chris Lattner7f318242009-07-06 17:29:59 +00001884LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001885
Gregory Szorc34c863a2012-03-21 03:54:29 +00001886/**
1887 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1888 *
1889 * Functions in this group model LLVMValueRef instances that correspond
1890 * to constants referring to scalar types.
1891 *
1892 * For integer types, the LLVMTypeRef parameter should correspond to a
1893 * llvm::IntegerType instance and the returned LLVMValueRef will
1894 * correspond to a llvm::ConstantInt.
1895 *
1896 * For floating point types, the LLVMTypeRef returned corresponds to a
1897 * llvm::ConstantFP.
1898 *
1899 * @{
1900 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001901
Gregory Szorc34c863a2012-03-21 03:54:29 +00001902/**
1903 * Obtain a constant value for an integer type.
1904 *
1905 * The returned value corresponds to a llvm::ConstantInt.
1906 *
1907 * @see llvm::ConstantInt::get()
1908 *
1909 * @param IntTy Integer type to obtain value of.
1910 * @param N The value the returned instance should refer to.
1911 * @param SignExtend Whether to sign extend the produced value.
1912 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001913LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001914 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001915
1916/**
1917 * Obtain a constant value for an integer of arbitrary precision.
1918 *
1919 * @see llvm::ConstantInt::get()
1920 */
Chris Lattner4329e072010-11-23 02:47:22 +00001921LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1922 unsigned NumWords,
1923 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001924
1925/**
1926 * Obtain a constant value for an integer parsed from a string.
1927 *
1928 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1929 * string's length is available, it is preferred to call that function
1930 * instead.
1931 *
1932 * @see llvm::ConstantInt::get()
1933 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001934LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1935 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001936
1937/**
1938 * Obtain a constant value for an integer parsed from a string with
1939 * specified length.
1940 *
1941 * @see llvm::ConstantInt::get()
1942 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001943LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1944 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001945
1946/**
1947 * Obtain a constant value referring to a double floating point value.
1948 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001949LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001950
1951/**
1952 * Obtain a constant for a floating point value parsed from a string.
1953 *
1954 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1955 * should be used if the input string's length is known.
1956 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001957LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001958
1959/**
1960 * Obtain a constant for a floating point value parsed from a string.
1961 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001962LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1963 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001964
1965/**
1966 * Obtain the zero extended value for an integer constant value.
1967 *
1968 * @see llvm::ConstantInt::getZExtValue()
1969 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001970unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001971
1972/**
1973 * Obtain the sign extended value for an integer constant value.
1974 *
1975 * @see llvm::ConstantInt::getSExtValue()
1976 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001977long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001978
Gregory Szorc34c863a2012-03-21 03:54:29 +00001979/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001980 * Obtain the double value for an floating point constant value.
1981 * losesInfo indicates if some precision was lost in the conversion.
1982 *
1983 * @see llvm::ConstantFP::getDoubleValue
1984 */
1985double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1986
1987/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001988 * @}
1989 */
1990
1991/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001992 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1993 *
1994 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001995 *
1996 * @{
1997 */
1998
1999/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002000 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002001 *
Gregory Szorc52d26602012-03-21 07:28:27 +00002002 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002003 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002004LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00002005 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00002006
2007/**
2008 * Create a ConstantDataSequential with string content in the global context.
2009 *
2010 * This is the same as LLVMConstStringInContext except it operates on the
2011 * global context.
2012 *
2013 * @see LLVMConstStringInContext()
2014 * @see llvm::ConstantDataArray::getString()
2015 */
2016LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
2017 LLVMBool DontNullTerminate);
2018
2019/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00002020 * Returns true if the specified constant is an array of i8.
2021 *
2022 * @see ConstantDataSequential::getAsString()
2023 */
2024LLVMBool LLVMIsConstantString(LLVMValueRef c);
2025
2026/**
2027 * Get the given constant data sequential as a string.
2028 *
2029 * @see ConstantDataSequential::getAsString()
2030 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002031const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
Peter Zotovf9aa8822014-08-03 23:54:16 +00002032
2033/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002034 * Create an anonymous ConstantStruct with the specified values.
2035 *
2036 * @see llvm::ConstantStruct::getAnon()
2037 */
2038LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002039 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00002040 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002041
Gregory Szorc52d26602012-03-21 07:28:27 +00002042/**
2043 * Create a ConstantStruct in the global Context.
2044 *
2045 * This is the same as LLVMConstStructInContext except it operates on the
2046 * global Context.
2047 *
2048 * @see LLVMConstStructInContext()
2049 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002050LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00002051 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00002052
2053/**
2054 * Create a ConstantArray from values.
2055 *
2056 * @see llvm::ConstantArray::get()
2057 */
2058LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
2059 LLVMValueRef *ConstantVals, unsigned Length);
2060
2061/**
2062 * Create a non-anonymous ConstantStruct from values.
2063 *
2064 * @see llvm::ConstantStruct::get()
2065 */
Rafael Espindola784ad242011-07-14 19:09:08 +00002066LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
2067 LLVMValueRef *ConstantVals,
2068 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00002069
2070/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00002071 * Get an element at specified index as a constant.
2072 *
2073 * @see ConstantDataSequential::getElementAsConstant()
2074 */
Amaury Sechet006ce632016-03-13 00:54:40 +00002075LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
Peter Zotovf9aa8822014-08-03 23:54:16 +00002076
2077/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002078 * Create a ConstantVector from values.
2079 *
2080 * @see llvm::ConstantVector::get()
2081 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002082LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002083
Gregory Szorc52d26602012-03-21 07:28:27 +00002084/**
2085 * @}
2086 */
2087
2088/**
2089 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
2090 *
2091 * Functions in this group correspond to APIs on llvm::ConstantExpr.
2092 *
2093 * @see llvm::ConstantExpr.
2094 *
2095 * @{
2096 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002097LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002098LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002099LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
2100LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002101LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
2102LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002103LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002104LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
2105LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002106LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002107LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002108LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002109LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002110LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2111LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002112LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002113LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002114LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2115LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002116LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002117LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Manuel Jacob49fafb12016-10-04 23:32:42 +00002118LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002119LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002120LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002121LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2122LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2123LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2124LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2125LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2126LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2127LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2128LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
2129 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2130LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
2131 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2132LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2133LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2134LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2135LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
2136 LLVMValueRef *ConstantIndices, unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002137LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2138 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002139LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
2140 LLVMValueRef *ConstantIndices,
2141 unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002142LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2143 LLVMValueRef *ConstantIndices,
2144 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002145LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2146LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2147LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2148LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2149LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2150LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2151LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2152LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2153LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2154LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2155LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2156LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002157LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002158LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
2159 LLVMTypeRef ToType);
2160LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
2161 LLVMTypeRef ToType);
2162LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
2163 LLVMTypeRef ToType);
2164LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
2165 LLVMTypeRef ToType);
2166LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00002167 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002168LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002169LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
2170 LLVMValueRef ConstantIfTrue,
2171 LLVMValueRef ConstantIfFalse);
2172LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
2173 LLVMValueRef IndexConstant);
2174LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
2175 LLVMValueRef ElementValueConstant,
2176 LLVMValueRef IndexConstant);
2177LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
2178 LLVMValueRef VectorBConstant,
2179 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00002180LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
2181 unsigned NumIdx);
2182LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
2183 LLVMValueRef ElementValueConstant,
2184 unsigned *IdxList, unsigned NumIdx);
Robert Widmannf108d572018-04-06 02:31:29 +00002185LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
2186
2187/** Deprecated: Use LLVMGetInlineAsm instead. */
Chris Lattner25963c62010-01-09 22:27:07 +00002188LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00002189 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00002190 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002191
Gregory Szorc52d26602012-03-21 07:28:27 +00002192/**
2193 * @}
2194 */
2195
2196/**
2197 * @defgroup LLVMCCoreValueConstantGlobals Global Values
2198 *
2199 * This group contains functions that operate on global values. Functions in
2200 * this group relate to functions in the llvm::GlobalValue class tree.
2201 *
2202 * @see llvm::GlobalValue
2203 *
2204 * @{
2205 */
2206
Gordon Henriksen265f7802008-03-19 01:11:35 +00002207LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00002208LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002209LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
2210void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
2211const char *LLVMGetSection(LLVMValueRef Global);
2212void LLVMSetSection(LLVMValueRef Global, const char *Section);
2213LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
2214void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00002215LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
2216void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002217LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
2218void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
2219
Robert Widmanne63a12c2018-09-28 20:54:29 +00002220/**
2221 * Returns the "value type" of a global value. This differs from the formal
2222 * type of a global value which is always a pointer type.
2223 *
2224 * @see llvm::GlobalValue::getValueType()
2225 */
2226LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
2227
Robert Widmann4bb481b2018-03-14 06:45:51 +00002228/** Deprecated: Use LLVMGetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002229LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002230/** Deprecated: Use LLVMSetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002231void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002232
2233/**
2234 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
2235 *
2236 * Functions in this group only apply to values with alignment, i.e.
2237 * global variables, load and store instructions.
2238 */
2239
2240/**
2241 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002242 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002243 * @see llvm::LoadInst::getAlignment()
2244 * @see llvm::StoreInst::getAlignment()
2245 * @see llvm::GlobalValue::getAlignment()
2246 */
2247unsigned LLVMGetAlignment(LLVMValueRef V);
2248
2249/**
2250 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002251 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002252 * @see llvm::LoadInst::setAlignment()
2253 * @see llvm::StoreInst::setAlignment()
2254 * @see llvm::GlobalValue::setAlignment()
2255 */
2256void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
2257
2258/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00002259 * Sets a metadata attachment, erasing the existing metadata attachment if
2260 * it already exists for the given kind.
2261 *
2262 * @see llvm::GlobalObject::setMetadata()
2263 */
2264void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind,
2265 LLVMMetadataRef MD);
2266
2267/**
2268 * Erases a metadata attachment of the given kind if it exists.
2269 *
2270 * @see llvm::GlobalObject::eraseMetadata()
2271 */
2272void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind);
2273
2274/**
2275 * Removes all metadata attachments from this value.
2276 *
2277 * @see llvm::GlobalObject::clearMetadata()
2278 */
2279void LLVMGlobalClearMetadata(LLVMValueRef Global);
2280
2281/**
2282 * Retrieves an array of metadata entries representing the metadata attached to
2283 * this value. The caller is responsible for freeing this array by calling
2284 * \c LLVMDisposeValueMetadataEntries.
2285 *
2286 * @see llvm::GlobalObject::getAllMetadata()
2287 */
2288LLVMValueMetadataEntry *LLVMGlobalCopyAllMetadata(LLVMValueRef Value,
2289 size_t *NumEntries);
2290
2291/**
2292 * Destroys value metadata entries.
2293 */
2294void LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries);
2295
2296/**
2297 * Returns the kind of a value metadata entry at a specific index.
2298 */
2299unsigned LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries,
2300 unsigned Index);
2301
2302/**
2303 * Returns the underlying metadata node of a value metadata entry at a
2304 * specific index.
2305 */
2306LLVMMetadataRef
2307LLVMValueMetadataEntriesGetMetadata(LLVMValueMetadataEntry *Entries,
2308 unsigned Index);
2309
2310/**
Amaury Sechet83550102016-02-14 08:58:49 +00002311 * @}
2312 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002313
Gregory Szorc52d26602012-03-21 07:28:27 +00002314/**
2315 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
2316 *
2317 * This group contains functions that operate on global variable values.
2318 *
2319 * @see llvm::GlobalVariable
2320 *
2321 * @{
2322 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002323LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00002324LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
2325 const char *Name,
2326 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00002327LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002328LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
2329LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
2330LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
2331LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002332void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002333LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
2334void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00002335LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
2336void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
2337LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
2338void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00002339LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
2340void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
2341LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
2342void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002343
Gregory Szorc52d26602012-03-21 07:28:27 +00002344/**
2345 * @}
2346 */
2347
2348/**
2349 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
2350 *
2351 * This group contains function that operate on global alias values.
2352 *
2353 * @see llvm::GlobalAlias
2354 *
2355 * @{
2356 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00002357LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
2358 const char *Name);
2359
Gregory Szorc34c863a2012-03-21 03:54:29 +00002360/**
Robert Widmann360d6e32018-05-20 23:49:08 +00002361 * Obtain a GlobalAlias value from a Module by its name.
2362 *
2363 * The returned value corresponds to a llvm::GlobalAlias value.
2364 *
2365 * @see llvm::Module::getNamedAlias()
2366 */
2367LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M,
2368 const char *Name, size_t NameLen);
2369
2370/**
2371 * Obtain an iterator to the first GlobalAlias in a Module.
2372 *
2373 * @see llvm::Module::alias_begin()
2374 */
2375LLVMValueRef LLVMGetFirstGlobalAlias(LLVMModuleRef M);
2376
2377/**
2378 * Obtain an iterator to the last GlobalAlias in a Module.
2379 *
2380 * @see llvm::Module::alias_end()
2381 */
2382LLVMValueRef LLVMGetLastGlobalAlias(LLVMModuleRef M);
2383
2384/**
2385 * Advance a GlobalAlias iterator to the next GlobalAlias.
2386 *
2387 * Returns NULL if the iterator was already at the end and there are no more
2388 * global aliases.
2389 */
2390LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA);
2391
2392/**
2393 * Decrement a GlobalAlias iterator to the previous GlobalAlias.
2394 *
2395 * Returns NULL if the iterator was already at the beginning and there are
2396 * no previous global aliases.
2397 */
2398LLVMValueRef LLVMGetPreviousGlobalAlias(LLVMValueRef GA);
2399
2400/**
2401 * Retrieve the target value of an alias.
2402 */
2403LLVMValueRef LLVMAliasGetAliasee(LLVMValueRef Alias);
2404
2405/**
2406 * Set the target value of an alias.
2407 */
2408void LLVMAliasSetAliasee(LLVMValueRef Alias, LLVMValueRef Aliasee);
2409
2410/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002411 * @}
2412 */
2413
2414/**
2415 * @defgroup LLVMCCoreValueFunction Function values
2416 *
2417 * Functions in this group operate on LLVMValueRef instances that
2418 * correspond to llvm::Function instances.
2419 *
2420 * @see llvm::Function
2421 *
2422 * @{
2423 */
2424
2425/**
2426 * Remove a function from its containing module and deletes it.
2427 *
2428 * @see llvm::Function::eraseFromParent()
2429 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002430void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002431
2432/**
Amaury Sechete39e8532016-02-18 20:38:32 +00002433 * Check whether the given function has a personality function.
2434 *
2435 * @see llvm::Function::hasPersonalityFn()
2436 */
2437LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
2438
2439/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00002440 * Obtain the personality function attached to the function.
2441 *
2442 * @see llvm::Function::getPersonalityFn()
2443 */
2444LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
2445
2446/**
2447 * Set the personality function attached to the function.
2448 *
2449 * @see llvm::Function::setPersonalityFn()
2450 */
2451void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
2452
2453/**
Robert Widmann9d94a682019-03-25 20:58:58 +00002454 * Obtain the intrinsic ID number which matches the given function name.
2455 *
2456 * @see llvm::Function::lookupIntrinsicID()
2457 */
2458unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen);
2459
2460/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002461 * Obtain the ID number from a function instance.
2462 *
2463 * @see llvm::Function::getIntrinsicID()
2464 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002465unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002466
2467/**
Robert Widmannd36f3b02018-11-06 01:38:14 +00002468 * Create or insert the declaration of an intrinsic. For overloaded intrinsics,
2469 * parameter types must be provided to uniquely identify an overload.
2470 *
2471 * @see llvm::Intrinsic::getDeclaration()
2472 */
2473LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
2474 unsigned ID,
2475 LLVMTypeRef *ParamTypes,
2476 size_t ParamCount);
2477
2478/**
2479 * Retrieves the type of an intrinsic. For overloaded intrinsics, parameter
2480 * types must be provided to uniquely identify an overload.
2481 *
2482 * @see llvm::Intrinsic::getType()
2483 */
2484LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID,
2485 LLVMTypeRef *ParamTypes, size_t ParamCount);
2486
2487/**
2488 * Retrieves the name of an intrinsic.
2489 *
2490 * @see llvm::Intrinsic::getName()
2491 */
2492const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength);
2493
2494/**
2495 * Copies the name of an overloaded intrinsic identified by a given list of
2496 * parameter types.
2497 *
2498 * Unlike LLVMIntrinsicGetName, the caller is responsible for freeing the
2499 * returned string.
2500 *
2501 * @see llvm::Intrinsic::getName()
2502 */
2503const char *LLVMIntrinsicCopyOverloadedName(unsigned ID,
2504 LLVMTypeRef *ParamTypes,
2505 size_t ParamCount,
2506 size_t *NameLength);
2507
2508/**
2509 * Obtain if the intrinsic identified by the given ID is overloaded.
2510 *
2511 * @see llvm::Intrinsic::isOverloaded()
2512 */
2513LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID);
2514
2515/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002516 * Obtain the calling function of a function.
2517 *
2518 * The returned value corresponds to the LLVMCallConv enumeration.
2519 *
2520 * @see llvm::Function::getCallingConv()
2521 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002522unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002523
2524/**
2525 * Set the calling convention of a function.
2526 *
2527 * @see llvm::Function::setCallingConv()
2528 *
2529 * @param Fn Function to operate on
2530 * @param CC LLVMCallConv to set calling convention to
2531 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002532void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002533
2534/**
2535 * Obtain the name of the garbage collector to use during code
2536 * generation.
2537 *
2538 * @see llvm::Function::getGC()
2539 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002540const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002541
2542/**
2543 * Define the garbage collector to use during code generation.
2544 *
2545 * @see llvm::Function::setGC()
2546 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002547void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002548
2549/**
2550 * Add an attribute to a function.
2551 *
2552 * @see llvm::Function::addAttribute()
2553 */
Amaury Sechet5db224e2016-06-12 06:17:24 +00002554void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2555 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00002556unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx);
2557void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2558 LLVMAttributeRef *Attrs);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002559LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
2560 LLVMAttributeIndex Idx,
2561 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002562LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
2563 LLVMAttributeIndex Idx,
2564 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002565void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2566 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002567void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2568 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002569
Gregory Szorc34c863a2012-03-21 03:54:29 +00002570/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00002571 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00002572 * @see llvm::AttrBuilder::addAttribute()
2573 */
2574void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
2575 const char *V);
2576
2577/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002578 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
2579 *
2580 * Functions in this group relate to arguments/parameters on functions.
2581 *
2582 * Functions in this group expect LLVMValueRef instances that correspond
2583 * to llvm::Function instances.
2584 *
2585 * @{
2586 */
2587
2588/**
2589 * Obtain the number of parameters in a function.
2590 *
2591 * @see llvm::Function::arg_size()
2592 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002593unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002594
2595/**
2596 * Obtain the parameters in a function.
2597 *
2598 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
2599 * at least LLVMCountParams() long. This array will be filled with
2600 * LLVMValueRef instances which correspond to the parameters the
2601 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
2602 * instance.
2603 *
2604 * @see llvm::Function::arg_begin()
2605 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002606void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002607
2608/**
2609 * Obtain the parameter at the specified index.
2610 *
2611 * Parameters are indexed from 0.
2612 *
2613 * @see llvm::Function::arg_begin()
2614 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002615LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002616
2617/**
2618 * Obtain the function to which this argument belongs.
2619 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002620 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002621 * that corresponds to a llvm::Attribute.
2622 *
2623 * The returned LLVMValueRef is the llvm::Function to which this
2624 * argument belongs.
2625 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002626LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002627
2628/**
2629 * Obtain the first parameter to a function.
2630 *
2631 * @see llvm::Function::arg_begin()
2632 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002633LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002634
2635/**
2636 * Obtain the last parameter to a function.
2637 *
2638 * @see llvm::Function::arg_end()
2639 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002640LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002641
2642/**
2643 * Obtain the next parameter to a function.
2644 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002645 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002646 * actually a wrapped iterator) and obtains the next parameter from the
2647 * underlying iterator.
2648 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002649LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002650
2651/**
2652 * Obtain the previous parameter to a function.
2653 *
2654 * This is the opposite of LLVMGetNextParam().
2655 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002656LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002657
2658/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002659 * Set the alignment for a function parameter.
2660 *
2661 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002662 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002663 */
Amaury Sechet81243a72016-05-01 01:42:34 +00002664void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002665
Gregory Szorc34c863a2012-03-21 03:54:29 +00002666/**
2667 * @}
2668 */
2669
2670/**
Robert Widmannd5444cc2019-02-05 18:05:44 +00002671 * @defgroup LLVMCCoreValueGlobalIFunc IFuncs
2672 *
2673 * Functions in this group relate to indirect functions.
2674 *
2675 * Functions in this group expect LLVMValueRef instances that correspond
2676 * to llvm::GlobalIFunc instances.
2677 *
2678 * @{
2679 */
2680
2681/**
2682 * Add a global indirect function to a module under a specified name.
2683 *
2684 * @see llvm::GlobalIFunc::create()
2685 */
2686LLVMValueRef LLVMAddGlobalIFunc(LLVMModuleRef M,
2687 const char *Name, size_t NameLen,
2688 LLVMTypeRef Ty, unsigned AddrSpace,
2689 LLVMValueRef Resolver);
2690
2691/**
2692 * Obtain a GlobalIFunc value from a Module by its name.
2693 *
2694 * The returned value corresponds to a llvm::GlobalIFunc value.
2695 *
2696 * @see llvm::Module::getNamedIFunc()
2697 */
2698LLVMValueRef LLVMGetNamedGlobalIFunc(LLVMModuleRef M,
2699 const char *Name, size_t NameLen);
2700
2701/**
2702 * Obtain an iterator to the first GlobalIFunc in a Module.
2703 *
2704 * @see llvm::Module::ifunc_begin()
2705 */
2706LLVMValueRef LLVMGetFirstGlobalIFunc(LLVMModuleRef M);
2707
2708/**
2709 * Obtain an iterator to the last GlobalIFunc in a Module.
2710 *
2711 * @see llvm::Module::ifunc_end()
2712 */
2713LLVMValueRef LLVMGetLastGlobalIFunc(LLVMModuleRef M);
2714
2715/**
2716 * Advance a GlobalIFunc iterator to the next GlobalIFunc.
2717 *
2718 * Returns NULL if the iterator was already at the end and there are no more
2719 * global aliases.
2720 */
2721LLVMValueRef LLVMGetNextGlobalIFunc(LLVMValueRef IFunc);
2722
2723/**
2724 * Decrement a GlobalIFunc iterator to the previous GlobalIFunc.
2725 *
2726 * Returns NULL if the iterator was already at the beginning and there are
2727 * no previous global aliases.
2728 */
2729LLVMValueRef LLVMGetPreviousGlobalIFunc(LLVMValueRef IFunc);
Jim Lin466f8842020-02-18 10:48:38 +08002730
Robert Widmannd5444cc2019-02-05 18:05:44 +00002731/**
2732 * Retrieves the resolver function associated with this indirect function, or
2733 * NULL if it doesn't not exist.
2734 *
2735 * @see llvm::GlobalIFunc::getResolver()
2736 */
2737LLVMValueRef LLVMGetGlobalIFuncResolver(LLVMValueRef IFunc);
2738
2739/**
2740 * Sets the resolver function associated with this indirect function.
2741 *
2742 * @see llvm::GlobalIFunc::setResolver()
2743 */
2744void LLVMSetGlobalIFuncResolver(LLVMValueRef IFunc, LLVMValueRef Resolver);
2745
2746/**
2747 * Remove a global indirect function from its parent module and delete it.
2748 *
2749 * @see llvm::GlobalIFunc::eraseFromParent()
2750 */
2751void LLVMEraseGlobalIFunc(LLVMValueRef IFunc);
2752
2753/**
2754 * Remove a global indirect function from its parent module.
2755 *
2756 * This unlinks the global indirect function from its containing module but
2757 * keeps it alive.
2758 *
2759 * @see llvm::GlobalIFunc::removeFromParent()
2760 */
2761void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc);
2762
2763/**
2764 * @}
2765 */
2766
2767/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002768 * @}
2769 */
2770
2771/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002772 * @}
2773 */
2774
2775/**
2776 * @}
2777 */
2778
2779/**
2780 * @defgroup LLVMCCoreValueMetadata Metadata
2781 *
2782 * @{
2783 */
2784
2785/**
Robert Widmann09c5b882019-04-24 17:05:08 +00002786 * Create an MDString value from a given string value.
Gregory Szorc52d26602012-03-21 07:28:27 +00002787 *
Robert Widmann09c5b882019-04-24 17:05:08 +00002788 * The MDString value does not take ownership of the given string, it remains
2789 * the responsibility of the caller to free it.
Gregory Szorc52d26602012-03-21 07:28:27 +00002790 *
Robert Widmann09c5b882019-04-24 17:05:08 +00002791 * @see llvm::MDString::get()
Gregory Szorc52d26602012-03-21 07:28:27 +00002792 */
Robert Widmann09c5b882019-04-24 17:05:08 +00002793LLVMMetadataRef LLVMMDStringInContext2(LLVMContextRef C, const char *Str,
2794 size_t SLen);
Gregory Szorc52d26602012-03-21 07:28:27 +00002795
2796/**
Robert Widmann09c5b882019-04-24 17:05:08 +00002797 * Create an MDNode value with the given array of operands.
Gregory Szorc52d26602012-03-21 07:28:27 +00002798 *
Robert Widmann09c5b882019-04-24 17:05:08 +00002799 * @see llvm::MDNode::get()
Gregory Szorc52d26602012-03-21 07:28:27 +00002800 */
Robert Widmann09c5b882019-04-24 17:05:08 +00002801LLVMMetadataRef LLVMMDNodeInContext2(LLVMContextRef C, LLVMMetadataRef *MDs,
2802 size_t Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00002803
2804/**
Amaury Sechetf8429752017-04-17 11:52:54 +00002805 * Obtain a Metadata as a Value.
2806 */
2807LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
2808
2809/**
2810 * Obtain a Value as a Metadata.
2811 */
2812LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
2813
2814/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002815 * Obtain the underlying string from a MDString value.
2816 *
2817 * @param V Instance to obtain string from.
NAKAMURA Takumie4a77052016-04-04 11:54:48 +00002818 * @param Length Memory address which will hold length of returned string.
Gregory Szorc52d26602012-03-21 07:28:27 +00002819 * @return String data in MDString.
2820 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002821const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
Gregory Szorc52d26602012-03-21 07:28:27 +00002822
2823/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002824 * Obtain the number of operands from an MDNode value.
2825 *
2826 * @param V MDNode to get number of operands from.
2827 * @return Number of operands of the MDNode.
2828 */
2829unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2830
2831/**
2832 * Obtain the given MDNode's operands.
2833 *
2834 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2835 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2836 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2837 * MDNode's operands.
2838 *
2839 * @param V MDNode to get the operands from.
2840 * @param Dest Destination array for operands.
2841 */
2842void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2843
Robert Widmann09c5b882019-04-24 17:05:08 +00002844/** Deprecated: Use LLVMMDStringInContext2 instead. */
2845LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2846 unsigned SLen);
2847/** Deprecated: Use LLVMMDStringInContext2 instead. */
2848LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2849/** Deprecated: Use LLVMMDNodeInContext2 instead. */
2850LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2851 unsigned Count);
2852/** Deprecated: Use LLVMMDNodeInContext2 instead. */
2853LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2854
Duncan Sands12ccbe72012-09-19 20:29:39 +00002855/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002856 * @}
2857 */
2858
2859/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002860 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2861 *
2862 * A basic block represents a single entry single exit section of code.
2863 * Basic blocks contain a list of instructions which form the body of
2864 * the block.
2865 *
2866 * Basic blocks belong to functions. They have the type of label.
2867 *
2868 * Basic blocks are themselves values. However, the C API models them as
2869 * LLVMBasicBlockRef.
2870 *
2871 * @see llvm::BasicBlock
2872 *
2873 * @{
2874 */
2875
2876/**
2877 * Convert a basic block instance to a value type.
2878 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002879LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002880
2881/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002882 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002883 */
Chris Lattner25963c62010-01-09 22:27:07 +00002884LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002885
2886/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002887 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002888 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002889LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002890
2891/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002892 * Obtain the string name of a basic block.
2893 */
2894const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2895
2896/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002897 * Obtain the function to which a basic block belongs.
2898 *
2899 * @see llvm::BasicBlock::getParent()
2900 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002901LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002902
2903/**
2904 * Obtain the terminator instruction for a basic block.
2905 *
2906 * If the basic block does not have a terminator (it is not well-formed
2907 * if it doesn't), then NULL is returned.
2908 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00002909 * The returned LLVMValueRef corresponds to an llvm::Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002910 *
2911 * @see llvm::BasicBlock::getTerminator()
2912 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002913LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002914
2915/**
2916 * Obtain the number of basic blocks in a function.
2917 *
2918 * @param Fn Function value to operate on.
2919 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002920unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002921
2922/**
2923 * Obtain all of the basic blocks in a function.
2924 *
2925 * This operates on a function value. The BasicBlocks parameter is a
2926 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2927 * LLVMCountBasicBlocks() in length. This array is populated with
2928 * LLVMBasicBlockRef instances.
2929 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002930void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002931
2932/**
2933 * Obtain the first basic block in a function.
2934 *
2935 * The returned basic block can be used as an iterator. You will likely
2936 * eventually call into LLVMGetNextBasicBlock() with it.
2937 *
2938 * @see llvm::Function::begin()
2939 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002940LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002941
2942/**
2943 * Obtain the last basic block in a function.
2944 *
2945 * @see llvm::Function::end()
2946 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002947LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002948
2949/**
2950 * Advance a basic block iterator.
2951 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002952LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002953
2954/**
2955 * Go backwards in a basic block iterator.
2956 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002957LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002958
2959/**
2960 * Obtain the basic block that corresponds to the entry point of a
2961 * function.
2962 *
2963 * @see llvm::Function::getEntryBlock()
2964 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002965LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002966
Gregory Szorc34c863a2012-03-21 03:54:29 +00002967/**
Robert Widmannb4baa562019-04-05 20:32:43 +00002968 * Insert the given basic block after the insertion point of the given builder.
2969 *
2970 * The insertion point must be valid.
2971 *
2972 * @see llvm::Function::BasicBlockListType::insertAfter()
2973 */
2974void LLVMInsertExistingBasicBlockAfterInsertBlock(LLVMBuilderRef Builder,
2975 LLVMBasicBlockRef BB);
2976
2977/**
2978 * Append the given basic block to the basic block list of the given function.
2979 *
2980 * @see llvm::Function::BasicBlockListType::push_back()
2981 */
2982void LLVMAppendExistingBasicBlock(LLVMValueRef Fn,
2983 LLVMBasicBlockRef BB);
Jim Lin466f8842020-02-18 10:48:38 +08002984
Robert Widmannb4baa562019-04-05 20:32:43 +00002985/**
Robert Widmann616ed172019-01-08 06:24:19 +00002986 * Create a new basic block without inserting it into a function.
2987 *
2988 * @see llvm::BasicBlock::Create()
2989 */
2990LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C,
James Y Knight68729f92019-01-14 17:16:55 +00002991 const char *Name);
Robert Widmann616ed172019-01-08 06:24:19 +00002992
2993/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002994 * Append a basic block to the end of a function.
2995 *
2996 * @see llvm::BasicBlock::Create()
2997 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002998LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2999 LLVMValueRef Fn,
3000 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003001
3002/**
3003 * Append a basic block to the end of a function using the global
3004 * context.
3005 *
3006 * @see llvm::BasicBlock::Create()
3007 */
3008LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
3009
3010/**
3011 * Insert a basic block in a function before another basic block.
3012 *
3013 * The function to add to is determined by the function of the
3014 * passed basic block.
3015 *
3016 * @see llvm::BasicBlock::Create()
3017 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00003018LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
3019 LLVMBasicBlockRef BB,
3020 const char *Name);
3021
Gregory Szorc34c863a2012-03-21 03:54:29 +00003022/**
3023 * Insert a basic block in a function using the global context.
3024 *
3025 * @see llvm::BasicBlock::Create()
3026 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003027LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
3028 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003029
3030/**
3031 * Remove a basic block from a function and delete it.
3032 *
3033 * This deletes the basic block from its containing function and deletes
3034 * the basic block itself.
3035 *
3036 * @see llvm::BasicBlock::eraseFromParent()
3037 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003038void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003039
3040/**
3041 * Remove a basic block from a function.
3042 *
3043 * This deletes the basic block from its containing function but keep
3044 * the basic block alive.
3045 *
3046 * @see llvm::BasicBlock::removeFromParent()
3047 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003048void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003049
Gregory Szorc34c863a2012-03-21 03:54:29 +00003050/**
3051 * Move a basic block to before another one.
3052 *
3053 * @see llvm::BasicBlock::moveBefore()
3054 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00003055void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003056
3057/**
3058 * Move a basic block to after another one.
3059 *
3060 * @see llvm::BasicBlock::moveAfter()
3061 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00003062void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
3063
Gregory Szorc34c863a2012-03-21 03:54:29 +00003064/**
3065 * Obtain the first instruction in a basic block.
3066 *
3067 * The returned LLVMValueRef corresponds to a llvm::Instruction
3068 * instance.
3069 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003070LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003071
3072/**
3073 * Obtain the last instruction in a basic block.
3074 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003075 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003076 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003077LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00003078
Gregory Szorc34c863a2012-03-21 03:54:29 +00003079/**
3080 * @}
3081 */
3082
3083/**
3084 * @defgroup LLVMCCoreValueInstruction Instructions
3085 *
3086 * Functions in this group relate to the inspection and manipulation of
3087 * individual instructions.
3088 *
3089 * In the C++ API, an instruction is modeled by llvm::Instruction. This
3090 * class has a large number of descendents. llvm::Instruction is a
3091 * llvm::Value and in the C API, instructions are modeled by
3092 * LLVMValueRef.
3093 *
3094 * This group also contains sub-groups which operate on specific
3095 * llvm::Instruction types, e.g. llvm::CallInst.
3096 *
3097 * @{
3098 */
3099
3100/**
3101 * Determine whether an instruction has any metadata attached.
3102 */
3103int LLVMHasMetadata(LLVMValueRef Val);
3104
3105/**
3106 * Return metadata associated with an instruction value.
3107 */
3108LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
3109
3110/**
3111 * Set metadata associated with an instruction value.
3112 */
3113void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
3114
3115/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00003116 * Returns the metadata associated with an instruction value, but filters out
3117 * all the debug locations.
3118 *
3119 * @see llvm::Instruction::getAllMetadataOtherThanDebugLoc()
3120 */
3121LLVMValueMetadataEntry *
3122LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Instr,
3123 size_t *NumEntries);
3124
3125/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003126 * Obtain the basic block to which an instruction belongs.
3127 *
3128 * @see llvm::Instruction::getParent()
3129 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003130LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003131
3132/**
3133 * Obtain the instruction that occurs after the one specified.
3134 *
3135 * The next instruction will be from the same basic block.
3136 *
3137 * If this is the last instruction in a basic block, NULL will be
3138 * returned.
3139 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003140LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003141
3142/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00003143 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003144 *
3145 * If the instruction is the first instruction in a basic block, NULL
3146 * will be returned.
3147 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003148LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003149
3150/**
3151 * Remove and delete an instruction.
3152 *
3153 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00003154 * block but is kept alive.
3155 *
3156 * @see llvm::Instruction::removeFromParent()
3157 */
3158void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
3159
3160/**
3161 * Remove and delete an instruction.
3162 *
3163 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00003164 * block and then deleted.
3165 *
3166 * @see llvm::Instruction::eraseFromParent()
3167 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00003168void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003169
3170/**
3171 * Obtain the code opcode for an individual instruction.
3172 *
3173 * @see llvm::Instruction::getOpCode()
3174 */
Eric Christophera6b96002015-12-18 01:46:52 +00003175LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003176
3177/**
3178 * Obtain the predicate of an instruction.
3179 *
3180 * This is only valid for instructions that correspond to llvm::ICmpInst
3181 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
3182 *
3183 * @see llvm::ICmpInst::getPredicate()
3184 */
Torok Edwin60c40de2011-10-06 12:13:20 +00003185LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003186
Gregory Szorc34c863a2012-03-21 03:54:29 +00003187/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00003188 * Obtain the float predicate of an instruction.
3189 *
3190 * This is only valid for instructions that correspond to llvm::FCmpInst
3191 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
3192 *
3193 * @see llvm::FCmpInst::getPredicate()
3194 */
3195LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
3196
3197/**
Peter Zotovaff492c2014-10-17 01:02:34 +00003198 * Create a copy of 'this' instruction that is identical in all ways
3199 * except the following:
3200 * * The instruction has no parent
3201 * * The instruction has no name
3202 *
3203 * @see llvm::Instruction::clone()
3204 */
3205LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
3206
3207/**
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003208 * Determine whether an instruction is a terminator. This routine is named to
3209 * be compatible with historical functions that did this by querying the
3210 * underlying C++ type.
3211 *
3212 * @see llvm::Instruction::isTerminator()
3213 */
3214LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst);
3215
3216/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003217 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
3218 *
3219 * Functions in this group apply to instructions that refer to call
3220 * sites and invocations. These correspond to C++ types in the
3221 * llvm::CallInst class tree.
3222 *
3223 * @{
3224 */
3225
3226/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003227 * Obtain the argument count for a call instruction.
3228 *
Robert Widmann478fce92018-03-30 17:49:53 +00003229 * This expects an LLVMValueRef that corresponds to a llvm::CallInst,
3230 * llvm::InvokeInst, or llvm:FuncletPadInst.
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003231 *
3232 * @see llvm::CallInst::getNumArgOperands()
3233 * @see llvm::InvokeInst::getNumArgOperands()
Robert Widmann478fce92018-03-30 17:49:53 +00003234 * @see llvm::FuncletPadInst::getNumArgOperands()
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003235 */
3236unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
3237
3238/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003239 * Set the calling convention for a call instruction.
3240 *
3241 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3242 * llvm::InvokeInst.
3243 *
3244 * @see llvm::CallInst::setCallingConv()
3245 * @see llvm::InvokeInst::setCallingConv()
3246 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003247void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003248
3249/**
3250 * Obtain the calling convention for a call instruction.
3251 *
3252 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
3253 * usage.
3254 *
3255 * @see LLVMSetInstructionCallConv()
3256 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003257unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003258
Gregory Szorc34c863a2012-03-21 03:54:29 +00003259void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Amaury Sechet81243a72016-05-01 01:42:34 +00003260 unsigned Align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00003261
Amaury Secheta65a2372016-06-15 05:14:29 +00003262void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3263 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00003264unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx);
3265void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
3266 LLVMAttributeRef *Attrs);
Amaury Secheta65a2372016-06-15 05:14:29 +00003267LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
3268 LLVMAttributeIndex Idx,
3269 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003270LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
3271 LLVMAttributeIndex Idx,
3272 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003273void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3274 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003275void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3276 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003277
Gregory Szorc34c863a2012-03-21 03:54:29 +00003278/**
James Y Knightf9563902019-01-14 21:37:42 +00003279 * Obtain the function type called by this instruction.
3280 *
3281 * @see llvm::CallBase::getFunctionType()
3282 */
3283LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef C);
3284
3285/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003286 * Obtain the pointer to the function invoked by this instruction.
3287 *
3288 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3289 * llvm::InvokeInst.
3290 *
Craig Toppera58b62b2020-04-27 20:15:59 -07003291 * @see llvm::CallInst::getCalledOperand()
3292 * @see llvm::InvokeInst::getCalledOperand()
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003293 */
3294LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
3295
3296/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003297 * Obtain whether a call instruction is a tail call.
3298 *
3299 * This only works on llvm::CallInst instructions.
3300 *
3301 * @see llvm::CallInst::isTailCall()
3302 */
Chris Lattner25963c62010-01-09 22:27:07 +00003303LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003304
3305/**
3306 * Set whether a call instruction is a tail call.
3307 *
3308 * This only works on llvm::CallInst instructions.
3309 *
3310 * @see llvm::CallInst::setTailCall()
3311 */
Chris Lattner25963c62010-01-09 22:27:07 +00003312void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00003313
Gregory Szorc34c863a2012-03-21 03:54:29 +00003314/**
Amaury Sechete39e8532016-02-18 20:38:32 +00003315 * Return the normal destination basic block.
3316 *
3317 * This only works on llvm::InvokeInst instructions.
3318 *
3319 * @see llvm::InvokeInst::getNormalDest()
3320 */
3321LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
3322
3323/**
3324 * Return the unwind destination basic block.
3325 *
Robert Widmann478fce92018-03-30 17:49:53 +00003326 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3327 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003328 *
3329 * @see llvm::InvokeInst::getUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003330 * @see llvm::CleanupReturnInst::getUnwindDest()
3331 * @see llvm::CatchSwitchInst::getUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003332 */
3333LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
3334
3335/**
3336 * Set the normal destination basic block.
3337 *
3338 * This only works on llvm::InvokeInst instructions.
3339 *
3340 * @see llvm::InvokeInst::setNormalDest()
3341 */
3342void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3343
3344/**
3345 * Set the unwind destination basic block.
3346 *
Robert Widmann478fce92018-03-30 17:49:53 +00003347 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3348 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003349 *
3350 * @see llvm::InvokeInst::setUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003351 * @see llvm::CleanupReturnInst::setUnwindDest()
3352 * @see llvm::CatchSwitchInst::setUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003353 */
3354void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3355
3356/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003357 * @}
3358 */
3359
3360/**
Peter Zotov2481c752014-10-28 19:46:56 +00003361 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
3362 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003363 * Functions in this group only apply to instructions for which
3364 * LLVMIsATerminatorInst returns true.
Peter Zotov2481c752014-10-28 19:46:56 +00003365 *
3366 * @{
3367 */
3368
3369/**
3370 * Return the number of successors that this terminator has.
3371 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003372 * @see llvm::Instruction::getNumSuccessors
Peter Zotov2481c752014-10-28 19:46:56 +00003373 */
3374unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
3375
3376/**
3377 * Return the specified successor.
3378 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003379 * @see llvm::Instruction::getSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003380 */
3381LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
3382
3383/**
3384 * Update the specified successor to point at the provided block.
3385 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003386 * @see llvm::Instruction::setSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003387 */
3388void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
3389
3390/**
3391 * Return if a branch is conditional.
3392 *
3393 * This only works on llvm::BranchInst instructions.
3394 *
3395 * @see llvm::BranchInst::isConditional
3396 */
3397LLVMBool LLVMIsConditional(LLVMValueRef Branch);
3398
3399/**
3400 * Return the condition of a branch instruction.
3401 *
3402 * This only works on llvm::BranchInst instructions.
3403 *
3404 * @see llvm::BranchInst::getCondition
3405 */
3406LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
3407
3408/**
3409 * Set the condition of a branch instruction.
3410 *
3411 * This only works on llvm::BranchInst instructions.
3412 *
3413 * @see llvm::BranchInst::setCondition
3414 */
3415void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
3416
3417/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003418 * Obtain the default destination basic block of a switch instruction.
3419 *
3420 * This only works on llvm::SwitchInst instructions.
3421 *
3422 * @see llvm::SwitchInst::getDefaultDest()
3423 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003424LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
3425
Gregory Szorc34c863a2012-03-21 03:54:29 +00003426/**
Peter Zotov2481c752014-10-28 19:46:56 +00003427 * @}
3428 */
3429
3430/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00003431 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
3432 *
3433 * Functions in this group only apply to instructions that map to
3434 * llvm::AllocaInst instances.
3435 *
3436 * @{
3437 */
3438
3439/**
3440 * Obtain the type that is being allocated by the alloca instruction.
3441 */
3442LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
3443
3444/**
3445 * @}
3446 */
3447
3448/**
Amaury Sechet053ac452016-02-17 22:51:03 +00003449 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
3450 *
3451 * Functions in this group only apply to instructions that map to
3452 * llvm::GetElementPtrInst instances.
3453 *
3454 * @{
3455 */
3456
3457/**
3458 * Check whether the given GEP instruction is inbounds.
3459 */
3460LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
3461
3462/**
3463 * Set the given GEP instruction to be inbounds or not.
3464 */
Amaury Sechet8a367d42016-05-01 02:23:14 +00003465void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
Amaury Sechet053ac452016-02-17 22:51:03 +00003466
3467/**
3468 * @}
3469 */
3470
3471/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003472 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
3473 *
3474 * Functions in this group only apply to instructions that map to
3475 * llvm::PHINode instances.
3476 *
3477 * @{
3478 */
3479
3480/**
3481 * Add an incoming value to the end of a PHI list.
3482 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003483void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
3484 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003485
3486/**
3487 * Obtain the number of incoming basic blocks to a PHI node.
3488 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003489unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003490
3491/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003492 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003493 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003494LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003495
3496/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003497 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003498 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003499LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003500
Gregory Szorc34c863a2012-03-21 03:54:29 +00003501/**
3502 * @}
3503 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003504
Gregory Szorc34c863a2012-03-21 03:54:29 +00003505/**
Amaury Sechetaad93532016-02-10 00:38:50 +00003506 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
3507 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
3508 *
3509 * Functions in this group only apply to instructions that map to
3510 * llvm::ExtractValue and llvm::InsertValue instances.
3511 *
3512 * @{
3513 */
3514
3515/**
3516 * Obtain the number of indices.
Amaury Sechet053ac452016-02-17 22:51:03 +00003517 * NB: This also works on GEP.
Amaury Sechetaad93532016-02-10 00:38:50 +00003518 */
3519unsigned LLVMGetNumIndices(LLVMValueRef Inst);
3520
3521/**
3522 * Obtain the indices as an array.
3523 */
3524const unsigned *LLVMGetIndices(LLVMValueRef Inst);
3525
3526/**
3527 * @}
3528 */
3529
3530/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003531 * @}
3532 */
3533
3534/**
3535 * @}
3536 */
3537
3538/**
3539 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
3540 *
3541 * An instruction builder represents a point within a basic block and is
3542 * the exclusive means of building instructions using the C interface.
3543 *
3544 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003545 */
3546
Erick Tryzelaar262332f2009-08-14 00:01:31 +00003547LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003548LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00003549void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
3550 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003551void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
3552void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003553LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00003554void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
3555void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00003556void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
3557 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003558void LLVMDisposeBuilder(LLVMBuilderRef Builder);
3559
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00003560/* Metadata */
Robert Widmanncce47412019-04-10 14:19:05 +00003561
3562/**
3563 * Get location information used by debugging information.
3564 *
3565 * @see llvm::IRBuilder::getCurrentDebugLocation()
3566 */
3567LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder);
3568
3569/**
3570 * Set location information used by debugging information.
3571 *
3572 * To clear the location metadata of the given instruction, pass NULL to \p Loc.
3573 *
3574 * @see llvm::IRBuilder::SetCurrentDebugLocation()
3575 */
3576void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc);
3577
3578/**
3579 * Attempts to set the debug location for the given instruction using the
3580 * current debug location for the given builder. If the builder has no current
3581 * debug location, this function is a no-op.
3582 *
3583 * @see llvm::IRBuilder::SetInstDebugLocation()
3584 */
Sam McCall71660b02019-04-10 13:29:37 +00003585void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
Robert Widmannff8febc2019-04-22 13:13:22 +00003586
3587/**
3588 * Get the dafult floating-point math metadata for a given builder.
3589 *
3590 * @see llvm::IRBuilder::getDefaultFPMathTag()
3591 */
3592LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder);
3593
3594/**
3595 * Set the default floating-point math metadata for the given builder.
3596 *
3597 * To clear the metadata, pass NULL to \p FPMathTag.
3598 *
3599 * @see llvm::IRBuilder::setDefaultFPMathTag()
3600 */
3601void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
3602 LLVMMetadataRef FPMathTag);
3603
Robert Widmanncce47412019-04-10 14:19:05 +00003604/**
3605 * Deprecated: Passing the NULL location will crash.
3606 * Use LLVMGetCurrentDebugLocation2 instead.
3607 */
3608void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
3609/**
3610 * Deprecated: Returning the NULL location will crash.
3611 * Use LLVMGetCurrentDebugLocation2 instead.
3612 */
3613LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00003614
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003615/* Terminators */
3616LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
3617LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00003618LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003619 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003620LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
3621LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
3622 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
3623LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
3624 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003625LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
3626 unsigned NumDests);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003627// LLVMBuildInvoke is deprecated in favor of LLVMBuildInvoke2, in preparation
3628// for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003629LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
3630 LLVMValueRef *Args, unsigned NumArgs,
3631 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3632 const char *Name);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003633LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
3634 LLVMValueRef *Args, unsigned NumArgs,
3635 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3636 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003637LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
3638
3639/* Exception Handling */
3640LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00003641LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00003642 LLVMValueRef PersFn, unsigned NumClauses,
3643 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003644LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3645 LLVMBasicBlockRef BB);
3646LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3647 LLVMBasicBlockRef BB);
3648LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3649 LLVMValueRef *Args, unsigned NumArgs,
3650 const char *Name);
3651LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3652 LLVMValueRef *Args, unsigned NumArgs,
3653 const char *Name);
3654LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B, LLVMValueRef ParentPad,
3655 LLVMBasicBlockRef UnwindBB,
3656 unsigned NumHandlers, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003657
Gordon Henriksen097102c2008-01-01 05:50:53 +00003658/* Add a case to the switch instruction */
3659void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
3660 LLVMBasicBlockRef Dest);
3661
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003662/* Add a destination to the indirectbr instruction */
3663void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
3664
Amaury Sechete39e8532016-02-18 20:38:32 +00003665/* Get the number of clauses on the landingpad instruction */
3666unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
3667
Craig Disselkoen51cad042020-09-25 14:34:23 -07003668/* Get the value of the clause at index Idx on the landingpad instruction */
Amaury Sechete39e8532016-02-18 20:38:32 +00003669LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
3670
Bill Wendlingfae14752011-08-12 20:24:12 +00003671/* Add a catch or filter clause to the landingpad instruction */
3672void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
3673
Amaury Sechete39e8532016-02-18 20:38:32 +00003674/* Get the 'cleanup' flag in the landingpad instruction */
3675LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
3676
Bill Wendlingfae14752011-08-12 20:24:12 +00003677/* Set the 'cleanup' flag in the landingpad instruction */
3678void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
3679
Robert Widmann478fce92018-03-30 17:49:53 +00003680/* Add a destination to the catchswitch instruction */
3681void LLVMAddHandler(LLVMValueRef CatchSwitch, LLVMBasicBlockRef Dest);
3682
3683/* Get the number of handlers on the catchswitch instruction */
3684unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch);
3685
3686/**
3687 * Obtain the basic blocks acting as handlers for a catchswitch instruction.
3688 *
3689 * The Handlers parameter should point to a pre-allocated array of
3690 * LLVMBasicBlockRefs at least LLVMGetNumHandlers() large. On return, the
3691 * first LLVMGetNumHandlers() entries in the array will be populated
3692 * with LLVMBasicBlockRef instances.
3693 *
3694 * @param CatchSwitch The catchswitch instruction to operate on.
3695 * @param Handlers Memory address of an array to be filled with basic blocks.
3696 */
3697void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers);
3698
3699/* Funclets */
3700
3701/* Get the number of funcletpad arguments. */
3702LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i);
3703
3704/* Set a funcletpad argument at the given index. */
3705void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value);
3706
3707/**
3708 * Get the parent catchswitch instruction of a catchpad instruction.
3709 *
3710 * This only works on llvm::CatchPadInst instructions.
3711 *
3712 * @see llvm::CatchPadInst::getCatchSwitch()
3713 */
3714LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad);
3715
3716/**
3717 * Set the parent catchswitch instruction of a catchpad instruction.
3718 *
3719 * This only works on llvm::CatchPadInst instructions.
3720 *
3721 * @see llvm::CatchPadInst::setCatchSwitch()
3722 */
3723void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad, LLVMValueRef CatchSwitch);
3724
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003725/* Arithmetic */
3726LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3727 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003728LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3729 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003730LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3731 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003732LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3733 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003734LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3735 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003736LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3737 const char *Name);
3738LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3739 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003740LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3741 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003742LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3743 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003744LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3745 const char *Name);
3746LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3747 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003748LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3749 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003750LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3751 const char *Name);
Manuel Jacob49fafb12016-10-04 23:32:42 +00003752LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3753 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003754LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3755 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003756LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3757 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003758LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3759 const char *Name);
3760LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3761 const char *Name);
3762LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3763 const char *Name);
3764LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3765 const char *Name);
3766LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3767 const char *Name);
3768LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3769 const char *Name);
3770LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3771 const char *Name);
3772LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3773 const char *Name);
3774LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3775 const char *Name);
3776LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3777 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003778LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
3779 LLVMValueRef LHS, LLVMValueRef RHS,
3780 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003781LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003782LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
3783 const char *Name);
3784LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
3785 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00003786LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003787LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
3788
3789/* Memory */
3790LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3791LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
3792 LLVMValueRef Val, const char *Name);
Robert Widmann98640f82018-10-29 15:31:40 +00003793
3794/**
Jim Lin466f8842020-02-18 10:48:38 +08003795 * Creates and inserts a memset to the specified pointer and the
Robert Widmann98640f82018-10-29 15:31:40 +00003796 * specified value.
3797 *
3798 * @see llvm::IRRBuilder::CreateMemSet()
3799 */
3800LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
3801 LLVMValueRef Val, LLVMValueRef Len,
3802 unsigned Align);
3803/**
3804 * Creates and inserts a memcpy between the specified pointers.
3805 *
3806 * @see llvm::IRRBuilder::CreateMemCpy()
3807 */
Jim Lin466f8842020-02-18 10:48:38 +08003808LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,
Robert Widmann98640f82018-10-29 15:31:40 +00003809 LLVMValueRef Dst, unsigned DstAlign,
3810 LLVMValueRef Src, unsigned SrcAlign,
3811 LLVMValueRef Size);
3812/**
3813 * Creates and inserts a memmove between the specified pointers.
3814 *
3815 * @see llvm::IRRBuilder::CreateMemMove()
3816 */
Jim Lin466f8842020-02-18 10:48:38 +08003817LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B,
Robert Widmann98640f82018-10-29 15:31:40 +00003818 LLVMValueRef Dst, unsigned DstAlign,
3819 LLVMValueRef Src, unsigned SrcAlign,
3820 LLVMValueRef Size);
3821
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003822LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3823LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
3824 LLVMValueRef Val, const char *Name);
3825LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003826// LLVMBuildLoad is deprecated in favor of LLVMBuildLoad2, in preparation for
3827// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003828LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
3829 const char *Name);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003830LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty,
3831 LLVMValueRef PointerVal, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003832LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
James Y Knight544fa422019-01-14 21:39:35 +00003833// LLVMBuildGEP, LLVMBuildInBoundsGEP, and LLVMBuildStructGEP are deprecated in
3834// favor of LLVMBuild*GEP2, in preparation for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003835LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3836 LLVMValueRef *Indices, unsigned NumIndices,
3837 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003838LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3839 LLVMValueRef *Indices, unsigned NumIndices,
3840 const char *Name);
3841LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3842 unsigned Idx, const char *Name);
James Y Knight544fa422019-01-14 21:39:35 +00003843LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3844 LLVMValueRef Pointer, LLVMValueRef *Indices,
3845 unsigned NumIndices, const char *Name);
3846LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3847 LLVMValueRef Pointer, LLVMValueRef *Indices,
3848 unsigned NumIndices, const char *Name);
3849LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3850 LLVMValueRef Pointer, unsigned Idx,
3851 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003852LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
3853 const char *Name);
3854LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
3855 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00003856LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
3857void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Nick Lewyckyf57e9682019-09-26 00:58:55 +00003858LLVMBool LLVMGetWeak(LLVMValueRef CmpXchgInst);
3859void LLVMSetWeak(LLVMValueRef CmpXchgInst, LLVMBool IsWeak);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00003860LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
3861void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Nick Lewyckyf57e9682019-09-26 00:58:55 +00003862LLVMAtomicRMWBinOp LLVMGetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst);
3863void LLVMSetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst, LLVMAtomicRMWBinOp BinOp);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003864
3865/* Casts */
3866LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
3867 LLVMTypeRef DestTy, const char *Name);
3868LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
3869 LLVMTypeRef DestTy, const char *Name);
3870LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
3871 LLVMTypeRef DestTy, const char *Name);
3872LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
3873 LLVMTypeRef DestTy, const char *Name);
3874LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
3875 LLVMTypeRef DestTy, const char *Name);
3876LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
3877 LLVMTypeRef DestTy, const char *Name);
3878LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
3879 LLVMTypeRef DestTy, const char *Name);
3880LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
3881 LLVMTypeRef DestTy, const char *Name);
3882LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
3883 LLVMTypeRef DestTy, const char *Name);
3884LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
3885 LLVMTypeRef DestTy, const char *Name);
3886LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
3887 LLVMTypeRef DestTy, const char *Name);
3888LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
3889 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003890LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
3891 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003892LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3893 LLVMTypeRef DestTy, const char *Name);
3894LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3895 LLVMTypeRef DestTy, const char *Name);
3896LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3897 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003898LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
3899 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003900LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
3901 LLVMTypeRef DestTy, const char *Name);
Robert Widmann40dc48be2019-01-08 06:23:22 +00003902LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef, LLVMValueRef Val,
3903 LLVMTypeRef DestTy, LLVMBool IsSigned,
James Y Knight68729f92019-01-14 17:16:55 +00003904 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003905LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
3906 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003907
Robert Widmann40dc48be2019-01-08 06:23:22 +00003908/** Deprecated: This cast is always signed. Use LLVMBuildIntCast2 instead. */
3909LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
3910 LLVMTypeRef DestTy, const char *Name);
3911
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003912/* Comparisons */
3913LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
3914 LLVMValueRef LHS, LLVMValueRef RHS,
3915 const char *Name);
3916LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
3917 LLVMValueRef LHS, LLVMValueRef RHS,
3918 const char *Name);
3919
3920/* Miscellaneous instructions */
3921LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003922// LLVMBuildCall is deprecated in favor of LLVMBuildCall2, in preparation for
3923// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003924LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
3925 LLVMValueRef *Args, unsigned NumArgs,
3926 const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003927LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn,
3928 LLVMValueRef *Args, unsigned NumArgs,
3929 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003930LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
3931 LLVMValueRef Then, LLVMValueRef Else,
3932 const char *Name);
3933LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
3934 const char *Name);
3935LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
3936 LLVMValueRef Index, const char *Name);
3937LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
3938 LLVMValueRef EltVal, LLVMValueRef Index,
3939 const char *Name);
3940LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
3941 LLVMValueRef V2, LLVMValueRef Mask,
3942 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00003943LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
3944 unsigned Index, const char *Name);
3945LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
3946 LLVMValueRef EltVal, unsigned Index,
3947 const char *Name);
aqjunee87d7162019-11-07 01:17:49 +09003948LLVMValueRef LLVMBuildFreeze(LLVMBuilderRef, LLVMValueRef Val,
3949 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00003950
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003951LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
3952 const char *Name);
3953LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
3954 const char *Name);
3955LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
3956 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00003957LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
3958 LLVMBool singleThread, const char *Name);
3959LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00003960 LLVMValueRef PTR, LLVMValueRef Val,
3961 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00003962 LLVMBool singleThread);
Mehdi Amini43165d92016-03-19 21:28:28 +00003963LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
3964 LLVMValueRef Cmp, LLVMValueRef New,
3965 LLVMAtomicOrdering SuccessOrdering,
3966 LLVMAtomicOrdering FailureOrdering,
3967 LLVMBool SingleThread);
3968
Craig Disselkoen51cad042020-09-25 14:34:23 -07003969/**
3970 * Get the number of elements in the mask of a ShuffleVector instruction.
3971 */
3972unsigned LLVMGetNumMaskElements(LLVMValueRef ShuffleVectorInst);
3973
3974/**
Robert Widmann55f72732020-09-26 17:32:38 -06003975 * \returns a constant that specifies that the result of a \c ShuffleVectorInst
3976 * is undefined.
3977 */
3978int LLVMGetUndefMaskElem(void);
3979
3980/**
Craig Disselkoen51cad042020-09-25 14:34:23 -07003981 * Get the mask value at position Elt in the mask of a ShuffleVector
Robert Widmann55f72732020-09-26 17:32:38 -06003982 * instruction.
3983 *
3984 * \Returns the result of \c LLVMGetUndefMaskElem() if the mask value is undef
3985 * at that position.
Craig Disselkoen51cad042020-09-25 14:34:23 -07003986 */
3987int LLVMGetMaskValue(LLVMValueRef ShuffleVectorInst, unsigned Elt);
Craig Disselkoen51cad042020-09-25 14:34:23 -07003988
Mehdi Amini43165d92016-03-19 21:28:28 +00003989LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
3990void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
3991
3992LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
3993void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
3994 LLVMAtomicOrdering Ordering);
3995LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
3996void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
3997 LLVMAtomicOrdering Ordering);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003998
Gregory Szorc34c863a2012-03-21 03:54:29 +00003999/**
4000 * @}
4001 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00004002
Gregory Szorc34c863a2012-03-21 03:54:29 +00004003/**
4004 * @defgroup LLVMCCoreModuleProvider Module Providers
4005 *
4006 * @{
4007 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00004008
Gregory Szorc34c863a2012-03-21 03:54:29 +00004009/**
4010 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00004011 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00004012 */
4013LLVMModuleProviderRef
4014LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
4015
Gregory Szorc34c863a2012-03-21 03:54:29 +00004016/**
4017 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00004018 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00004019void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00004020
Gregory Szorc34c863a2012-03-21 03:54:29 +00004021/**
4022 * @}
4023 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00004024
Gregory Szorc34c863a2012-03-21 03:54:29 +00004025/**
4026 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
4027 *
4028 * @{
4029 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00004030
Chris Lattner25963c62010-01-09 22:27:07 +00004031LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
4032 LLVMMemoryBufferRef *OutMemBuf,
4033 char **OutMessage);
4034LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
4035 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00004036LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
4037 size_t InputDataLength,
4038 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00004039 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00004040LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
4041 size_t InputDataLength,
4042 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00004043const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00004044size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00004045void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
4046
Gregory Szorc34c863a2012-03-21 03:54:29 +00004047/**
4048 * @}
4049 */
4050
4051/**
4052 * @defgroup LLVMCCorePassRegistry Pass Registry
4053 *
4054 * @{
4055 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00004056
4057/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004058 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00004059LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004060
Gregory Szorc34c863a2012-03-21 03:54:29 +00004061/**
4062 * @}
4063 */
4064
4065/**
4066 * @defgroup LLVMCCorePassManagers Pass Managers
4067 *
4068 * @{
4069 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004070
4071/** Constructs a new whole-module pass pipeline. This type of pipeline is
4072 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004073 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00004074LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004075
4076/** Constructs a new function-by-function pass pipeline over the module
4077 provider. It does not take ownership of the module provider. This type of
4078 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004079 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00004080LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
4081
4082/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004083LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
4084
4085/** Initializes, executes on the provided module, and finalizes all of the
4086 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00004087 modified the module, 0 otherwise.
4088 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00004089LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004090
4091/** Initializes all of the function passes scheduled in the function pass
4092 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004093 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00004094LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004095
4096/** Executes all of the function passes scheduled in the function pass manager
4097 on the provided function. Returns 1 if any of the passes modified the
4098 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004099 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00004100LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004101
Hiroshi Inoue0909ca12018-01-26 08:15:29 +00004102/** Finalizes all of the function passes scheduled in the function pass
Gordon Henriksen878114b2008-03-16 04:20:44 +00004103 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004104 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00004105LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004106
4107/** Frees the memory of a pass pipeline. For function pipelines, does not free
4108 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004109 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004110void LLVMDisposePassManager(LLVMPassManagerRef PM);
4111
Gregory Szorc34c863a2012-03-21 03:54:29 +00004112/**
4113 * @}
4114 */
4115
4116/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00004117 * @defgroup LLVMCCoreThreading Threading
4118 *
4119 * Handle the structures needed to make LLVM safe for multithreading.
4120 *
4121 * @{
4122 */
4123
Chandler Carruth39cd2162014-06-27 15:13:01 +00004124/** Deprecated: Multi-threading can only be enabled/disabled with the compile
4125 time define LLVM_ENABLE_THREADS. This function always returns
4126 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00004127LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00004128
Chandler Carruth39cd2162014-06-27 15:13:01 +00004129/** Deprecated: Multi-threading can only be enabled/disabled with the compile
4130 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00004131void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00004132
4133/** Check whether LLVM is executing in thread-safe mode or not.
4134 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00004135LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00004136
4137/**
4138 * @}
4139 */
4140
4141/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00004142 * @}
4143 */
4144
4145/**
4146 * @}
4147 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004148
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -08004149LLVM_C_EXTERN_C_END
Gordon Henriksen7330acd2007-10-05 23:59:36 +00004150
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00004151#endif /* LLVM_C_CORE_H */