blob: d84a3a127ed82c81d2f7a39fedf5b980671257c3 [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"
19#include "llvm-c/Types.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000020
Evan Cheng2e254d02013-04-04 17:40:53 +000021#ifdef __cplusplus
Gordon Henriksen76a03742007-09-18 03:18:57 +000022extern "C" {
23#endif
24
Gregory Szorc34c863a2012-03-21 03:54:29 +000025/**
26 * @defgroup LLVMC LLVM-C: C interface to LLVM
27 *
28 * This module exposes parts of the LLVM library as a C API.
29 *
30 * @{
31 */
32
33/**
34 * @defgroup LLVMCTransforms Transforms
35 */
36
37/**
38 * @defgroup LLVMCCore Core
39 *
40 * This modules provide an interface to libLLVMCore, which implements
41 * the LLVM intermediate representation as well as other related types
42 * and utilities.
43 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000044 * Many exotic languages can interoperate with C code but have a harder time
45 * with C++ due to name mangling. So in addition to C, this interface enables
46 * tools written in such languages.
47 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000048 * @{
49 */
50
51/**
52 * @defgroup LLVMCCoreTypes Types and Enumerations
53 *
54 * @{
55 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000056
Cameron McInallycbde0d92018-11-13 18:15:47 +000057/// External users depend on the following values being stable. It is not safe
58/// to reorder them.
Gordon Henriksen76a03742007-09-18 03:18:57 +000059typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +000060 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +000061 LLVMRet = 1,
62 LLVMBr = 2,
63 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +000064 LLVMIndirectBr = 4,
65 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +000066 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +000067 LLVMUnreachable = 7,
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,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000129
130 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000131 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000132 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000133 LLVMAtomicRMW = 57,
134
135 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000136 LLVMResume = 58,
David Majnemer654e1302015-07-31 17:58:14 +0000137 LLVMLandingPad = 59,
138 LLVMCleanupRet = 61,
139 LLVMCatchRet = 62,
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +0000140 LLVMCatchPad = 63,
David Majnemerbbfc7212015-12-14 18:34:23 +0000141 LLVMCleanupPad = 64,
142 LLVMCatchSwitch = 65
Chris Lattner40cf28d2009-10-12 04:01:02 +0000143} LLVMOpcode;
144
145typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000146 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000147 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000148 LLVMFloatTypeKind, /**< 32 bit floating point type */
149 LLVMDoubleTypeKind, /**< 64 bit floating point type */
150 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
151 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
152 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
153 LLVMLabelTypeKind, /**< Labels */
154 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
155 LLVMFunctionTypeKind, /**< Functions */
156 LLVMStructTypeKind, /**< Structures */
157 LLVMArrayTypeKind, /**< Arrays */
158 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000159 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000160 LLVMMetadataTypeKind, /**< Metadata */
David Majnemerb611e3f2015-08-14 05:09:07 +0000161 LLVMX86_MMXTypeKind, /**< X86 MMX */
162 LLVMTokenTypeKind /**< Tokens */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000163} LLVMTypeKind;
164
165typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000166 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000167 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000168 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
169 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
170 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000171 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000172 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
173 LLVMWeakODRLinkage, /**< Same, but only replaced by something
174 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000175 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
176 LLVMInternalLinkage, /**< Rename collisions when linking (static
177 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000178 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000179 LLVMDLLImportLinkage, /**< Obsolete */
180 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000181 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000182 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000183 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000184 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000185 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000186} LLVMLinkage;
187
188typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000189 LLVMDefaultVisibility, /**< The GV is visible */
190 LLVMHiddenVisibility, /**< The GV is hidden */
191 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000192} LLVMVisibility;
193
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000194typedef enum {
Robert Widmann4bb481b2018-03-14 06:45:51 +0000195 LLVMNoUnnamedAddr, /**< Address of the GV is significant. */
196 LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */
197 LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */
198} LLVMUnnamedAddr;
199
200typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000201 LLVMDefaultStorageClass = 0,
202 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
203 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
204} LLVMDLLStorageClass;
205
206typedef enum {
Robert Widmann1e989de2018-04-06 04:02:39 +0000207 LLVMCCallConv = 0,
208 LLVMFastCallConv = 8,
209 LLVMColdCallConv = 9,
210 LLVMGHCCallConv = 10,
211 LLVMHiPECallConv = 11,
212 LLVMWebKitJSCallConv = 12,
213 LLVMAnyRegCallConv = 13,
214 LLVMPreserveMostCallConv = 14,
215 LLVMPreserveAllCallConv = 15,
216 LLVMSwiftCallConv = 16,
217 LLVMCXXFASTTLSCallConv = 17,
218 LLVMX86StdcallCallConv = 64,
219 LLVMX86FastcallCallConv = 65,
220 LLVMARMAPCSCallConv = 66,
221 LLVMARMAAPCSCallConv = 67,
222 LLVMARMAAPCSVFPCallConv = 68,
223 LLVMMSP430INTRCallConv = 69,
224 LLVMX86ThisCallCallConv = 70,
225 LLVMPTXKernelCallConv = 71,
226 LLVMPTXDeviceCallConv = 72,
227 LLVMSPIRFUNCCallConv = 75,
228 LLVMSPIRKERNELCallConv = 76,
229 LLVMIntelOCLBICallConv = 77,
230 LLVMX8664SysVCallConv = 78,
231 LLVMWin64CallConv = 79,
232 LLVMX86VectorCallCallConv = 80,
233 LLVMHHVMCallConv = 81,
234 LLVMHHVMCCallConv = 82,
235 LLVMX86INTRCallConv = 83,
236 LLVMAVRINTRCallConv = 84,
237 LLVMAVRSIGNALCallConv = 85,
238 LLVMAVRBUILTINCallConv = 86,
239 LLVMAMDGPUVSCallConv = 87,
240 LLVMAMDGPUGSCallConv = 88,
241 LLVMAMDGPUPSCallConv = 89,
242 LLVMAMDGPUCSCallConv = 90,
243 LLVMAMDGPUKERNELCallConv = 91,
244 LLVMX86RegCallCallConv = 92,
245 LLVMAMDGPUHSCallConv = 93,
246 LLVMMSP430BUILTINCallConv = 94,
247 LLVMAMDGPULSCallConv = 95,
248 LLVMAMDGPUESCallConv = 96
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000249} LLVMCallConv;
250
251typedef enum {
Peter Zotov3e4561c2016-04-06 22:21:29 +0000252 LLVMArgumentValueKind,
253 LLVMBasicBlockValueKind,
254 LLVMMemoryUseValueKind,
255 LLVMMemoryDefValueKind,
256 LLVMMemoryPhiValueKind,
257
258 LLVMFunctionValueKind,
259 LLVMGlobalAliasValueKind,
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000260 LLVMGlobalIFuncValueKind,
Peter Zotov3e4561c2016-04-06 22:21:29 +0000261 LLVMGlobalVariableValueKind,
262 LLVMBlockAddressValueKind,
263 LLVMConstantExprValueKind,
264 LLVMConstantArrayValueKind,
265 LLVMConstantStructValueKind,
266 LLVMConstantVectorValueKind,
267
268 LLVMUndefValueValueKind,
269 LLVMConstantAggregateZeroValueKind,
270 LLVMConstantDataArrayValueKind,
271 LLVMConstantDataVectorValueKind,
272 LLVMConstantIntValueKind,
273 LLVMConstantFPValueKind,
274 LLVMConstantPointerNullValueKind,
275 LLVMConstantTokenNoneValueKind,
276
277 LLVMMetadataAsValueValueKind,
278 LLVMInlineAsmValueKind,
279
280 LLVMInstructionValueKind,
281} LLVMValueKind;
282
283typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000284 LLVMIntEQ = 32, /**< equal */
285 LLVMIntNE, /**< not equal */
286 LLVMIntUGT, /**< unsigned greater than */
287 LLVMIntUGE, /**< unsigned greater or equal */
288 LLVMIntULT, /**< unsigned less than */
289 LLVMIntULE, /**< unsigned less or equal */
290 LLVMIntSGT, /**< signed greater than */
291 LLVMIntSGE, /**< signed greater or equal */
292 LLVMIntSLT, /**< signed less than */
293 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000294} LLVMIntPredicate;
295
296typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000297 LLVMRealPredicateFalse, /**< Always false (always folded) */
298 LLVMRealOEQ, /**< True if ordered and equal */
299 LLVMRealOGT, /**< True if ordered and greater than */
300 LLVMRealOGE, /**< True if ordered and greater than or equal */
301 LLVMRealOLT, /**< True if ordered and less than */
302 LLVMRealOLE, /**< True if ordered and less than or equal */
303 LLVMRealONE, /**< True if ordered and operands are unequal */
304 LLVMRealORD, /**< True if ordered (no nans) */
305 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
306 LLVMRealUEQ, /**< True if unordered or equal */
307 LLVMRealUGT, /**< True if unordered or greater than */
308 LLVMRealUGE, /**< True if unordered, greater than, or equal */
309 LLVMRealULT, /**< True if unordered or less than */
310 LLVMRealULE, /**< True if unordered, less than, or equal */
311 LLVMRealUNE, /**< True if unordered or not equal */
312 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000313} LLVMRealPredicate;
314
Bill Wendlingfae14752011-08-12 20:24:12 +0000315typedef enum {
316 LLVMLandingPadCatch, /**< A catch clause */
317 LLVMLandingPadFilter /**< A filter clause */
318} LLVMLandingPadClauseTy;
319
Hans Wennborg5ff71202013-04-16 08:58:59 +0000320typedef enum {
321 LLVMNotThreadLocal = 0,
322 LLVMGeneralDynamicTLSModel,
323 LLVMLocalDynamicTLSModel,
324 LLVMInitialExecTLSModel,
325 LLVMLocalExecTLSModel
326} LLVMThreadLocalMode;
327
Carlo Kokda0ac722013-04-23 13:45:37 +0000328typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000329 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
330 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
331 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000332 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
333 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000334 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000335 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
336 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000337 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000338 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
339 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000340 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000341 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
342 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000343 operations which both read and write
344 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000345 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
346 for loads and Release
347 semantics for stores.
348 Additionally, it guarantees
349 that a total ordering exists
350 between all
351 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000352 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000353} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000354
Carlo Kokda0ac722013-04-23 13:45:37 +0000355typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000356 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
357 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
358 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
359 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
360 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
361 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
362 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
363 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000364 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000365 the old one */
366 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000367 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000368 the old one */
369 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000370 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000371 the old one */
372 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000373 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000374 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000375} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000376
Tom Stellard1580dc72014-04-16 17:45:04 +0000377typedef enum {
378 LLVMDSError,
379 LLVMDSWarning,
380 LLVMDSRemark,
381 LLVMDSNote
382} LLVMDiagnosticSeverity;
383
Robert Widmannf108d572018-04-06 02:31:29 +0000384typedef enum {
385 LLVMInlineAsmDialectATT,
386 LLVMInlineAsmDialectIntel
387} LLVMInlineAsmDialect;
388
Robert Widmannbce367702018-05-14 08:09:00 +0000389typedef enum {
390 /**
391 * Emits an error if two values disagree, otherwise the resulting value is
392 * that of the operands.
393 *
394 * @see Module::ModFlagBehavior::Error
395 */
396 LLVMModuleFlagBehaviorError,
397 /**
398 * Emits a warning if two values disagree. The result value will be the
399 * operand for the flag from the first module being linked.
400 *
401 * @see Module::ModFlagBehavior::Warning
402 */
403 LLVMModuleFlagBehaviorWarning,
404 /**
405 * Adds a requirement that another module flag be present and have a
406 * specified value after linking is performed. The value must be a metadata
407 * pair, where the first element of the pair is the ID of the module flag
408 * to be restricted, and the second element of the pair is the value the
409 * module flag should be restricted to. This behavior can be used to
410 * restrict the allowable results (via triggering of an error) of linking
411 * IDs with the **Override** behavior.
412 *
413 * @see Module::ModFlagBehavior::Require
414 */
415 LLVMModuleFlagBehaviorRequire,
416 /**
417 * Uses the specified value, regardless of the behavior or value of the
418 * other module. If both modules specify **Override**, but the values
419 * differ, an error will be emitted.
420 *
421 * @see Module::ModFlagBehavior::Override
422 */
423 LLVMModuleFlagBehaviorOverride,
424 /**
425 * Appends the two values, which are required to be metadata nodes.
426 *
427 * @see Module::ModFlagBehavior::Append
428 */
429 LLVMModuleFlagBehaviorAppend,
430 /**
431 * Appends the two values, which are required to be metadata
432 * nodes. However, duplicate entries in the second list are dropped
433 * during the append operation.
434 *
435 * @see Module::ModFlagBehavior::AppendUnique
436 */
437 LLVMModuleFlagBehaviorAppendUnique,
438} LLVMModuleFlagBehavior;
439
Gregory Szorc34c863a2012-03-21 03:54:29 +0000440/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000441 * Attribute index are either LLVMAttributeReturnIndex,
442 * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
443 */
444enum {
445 LLVMAttributeReturnIndex = 0U,
446 // ISO C restricts enumerator values to range of 'int'
447 // (4294967295 is too large)
448 // LLVMAttributeFunctionIndex = ~0U,
449 LLVMAttributeFunctionIndex = -1,
450};
451
452typedef unsigned LLVMAttributeIndex;
453
454/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000455 * @}
456 */
457
Nick Lewycky0db26542011-05-15 07:20:34 +0000458void LLVMInitializeCore(LLVMPassRegistryRef R);
459
Duncan Sands1cba0a82013-02-17 16:35:51 +0000460/** Deallocate and destroy all ManagedStatic variables.
461 @see llvm::llvm_shutdown
462 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000463void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000464
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000465/*===-- Error handling ----------------------------------------------------===*/
466
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000467char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000468void LLVMDisposeMessage(char *Message);
469
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000470/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000471 * @defgroup LLVMCCoreContext Contexts
472 *
473 * Contexts are execution states for the core LLVM IR system.
474 *
475 * Most types are tied to a context instance. Multiple contexts can
476 * exist simultaneously. A single context is not thread safe. However,
477 * different contexts can execute on different threads simultaneously.
478 *
479 * @{
480 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000481
Tom Stellard1580dc72014-04-16 17:45:04 +0000482typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000483typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000484
Gregory Szorc34c863a2012-03-21 03:54:29 +0000485/**
486 * Create a new context.
487 *
488 * Every call to this function should be paired with a call to
489 * LLVMContextDispose() or the context will leak memory.
490 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000491LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000492
493/**
494 * Obtain the global context instance.
495 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000496LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000497
498/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000499 * Set the diagnostic handler for this context.
500 */
501void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
502 LLVMDiagnosticHandler Handler,
503 void *DiagnosticContext);
504
505/**
Jeroen Ketemaad659c32016-04-08 09:19:02 +0000506 * Get the diagnostic handler of this context.
507 */
508LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
509
510/**
511 * Get the diagnostic context of this context.
512 */
513void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
514
515/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000516 * Set the yield callback function for this context.
517 *
518 * @see LLVMContext::setYieldCallback()
519 */
520void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
521 void *OpaqueHandle);
522
523/**
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000524 * Retrieve whether the given context is set to discard all value names.
525 *
526 * @see LLVMContext::shouldDiscardValueNames()
527 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000528LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000529
530/**
531 * Set whether the given context discards all value names.
532 *
533 * If true, only the names of GlobalValue objects will be available in the IR.
534 * This can be used to save memory and runtime, especially in release mode.
535 *
536 * @see LLVMContext::setDiscardValueNames()
537 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000538void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000539
540/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000541 * Destroy a context instance.
542 *
543 * This should be called for every call to LLVMContextCreate() or memory
544 * will be leaked.
545 */
Owen Anderson6773d382009-07-01 16:58:40 +0000546void LLVMContextDispose(LLVMContextRef C);
547
Tom Stellard1580dc72014-04-16 17:45:04 +0000548/**
549 * Return a string representation of the DiagnosticInfo. Use
550 * LLVMDisposeMessage to free the string.
551 *
552 * @see DiagnosticInfo::print()
553 */
554char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
555
556/**
557 * Return an enum LLVMDiagnosticSeverity.
558 *
559 * @see DiagnosticInfo::getSeverity()
560 */
561LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
562
Amaury Sechet56f056c2016-04-04 22:00:25 +0000563unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000564 unsigned SLen);
Amaury Sechet56f056c2016-04-04 22:00:25 +0000565unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000566
Gregory Szorc34c863a2012-03-21 03:54:29 +0000567/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000568 * Return an unique id given the name of a enum attribute,
Amaury Sechet60b31452016-04-20 01:02:12 +0000569 * or 0 if no attribute by that name exists.
570 *
571 * See http://llvm.org/docs/LangRef.html#parameter-attributes
572 * and http://llvm.org/docs/LangRef.html#function-attributes
573 * for the list of available attributes.
574 *
575 * NB: Attribute names and/or id are subject to change without
576 * going through the C API deprecation cycle.
577 */
Amaury Sechet5db224e2016-06-12 06:17:24 +0000578unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
Amaury Sechet48b06652016-06-12 07:56:21 +0000579unsigned LLVMGetLastEnumAttributeKind(void);
Amaury Sechet5db224e2016-06-12 06:17:24 +0000580
581/**
582 * Create an enum attribute.
583 */
584LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
585 uint64_t Val);
586
587/**
588 * Get the unique id corresponding to the enum attribute
589 * passed as argument.
590 */
591unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
592
593/**
594 * Get the enum attribute's value. 0 is returned if none exists.
595 */
596uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
597
598/**
599 * Create a string attribute.
600 */
601LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
602 const char *K, unsigned KLength,
603 const char *V, unsigned VLength);
604
605/**
606 * Get the string attribute's kind.
607 */
608const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
609
610/**
611 * Get the string attribute's value.
612 */
613const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
614
615/**
616 * Check for the different types of attributes.
617 */
618LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
619LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
Amaury Sechet60b31452016-04-20 01:02:12 +0000620
621/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000622 * @}
623 */
624
Gregory Szorc52d26602012-03-21 07:28:27 +0000625/**
626 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000627 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000628 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000629 * module is effectively a translation unit or a collection of
630 * translation units merged together.
631 *
632 * @{
633 */
634
Gregory Szorc34c863a2012-03-21 03:54:29 +0000635/**
636 * Create a new, empty module in the global context.
637 *
638 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
639 * LLVMGetGlobalContext() as the context parameter.
640 *
641 * Every invocation should be paired with LLVMDisposeModule() or memory
642 * will be leaked.
643 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000644LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000645
646/**
647 * Create a new, empty module in a specific context.
648 *
649 * Every invocation should be paired with LLVMDisposeModule() or memory
650 * will be leaked.
651 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000652LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
653 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000654/**
655 * Return an exact copy of the specified module.
656 */
657LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000658
Gregory Szorc34c863a2012-03-21 03:54:29 +0000659/**
660 * Destroy a module instance.
661 *
662 * This must be called for every created module or memory will be
663 * leaked.
664 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000665void LLVMDisposeModule(LLVMModuleRef M);
666
Gregory Szorc34c863a2012-03-21 03:54:29 +0000667/**
Peter Zotov0a2fa0a2016-04-05 13:56:59 +0000668 * Obtain the identifier of a module.
669 *
670 * @param M Module to obtain identifier of
671 * @param Len Out parameter which holds the length of the returned string.
672 * @return The identifier of M.
673 * @see Module::getModuleIdentifier()
674 */
675const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
676
677/**
678 * Set the identifier of a module to a string Ident with length Len.
679 *
680 * @param M The module to set identifier
681 * @param Ident The string to set M's identifier to
682 * @param Len Length of Ident
683 * @see Module::setModuleIdentifier()
684 */
685void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
686
687/**
Robert Widmann490a5802018-01-30 21:34:29 +0000688 * Obtain the module's original source file name.
689 *
690 * @param M Module to obtain the name of
691 * @param Len Out parameter which holds the length of the returned string
692 * @return The original source file name of M
693 * @see Module::getSourceFileName()
694 */
695const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len);
696
697/**
698 * Set the original source file name of a module to a string Name with length
699 * Len.
700 *
701 * @param M The module to set the source file name of
702 * @param Name The string to set M's source file name to
703 * @param Len Length of Name
704 * @see Module::setSourceFileName()
705 */
706void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len);
707
708/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000709 * Obtain the data layout for a module.
710 *
Amaury Sechetf3549c42016-02-16 00:23:52 +0000711 * @see Module::getDataLayoutStr()
712 *
713 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
714 * but match the name of another method on the module. Prefer the use
715 * of LLVMGetDataLayoutStr, which is not ambiguous.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000716 */
Amaury Sechetf3549c42016-02-16 00:23:52 +0000717const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000718const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000719
720/**
721 * Set the data layout for a module.
722 *
723 * @see Module::setDataLayout()
724 */
Amaury Sechet6ada31c2016-02-15 23:40:06 +0000725void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000726
Gregory Szorc34c863a2012-03-21 03:54:29 +0000727/**
728 * Obtain the target triple for a module.
729 *
730 * @see Module::getTargetTriple()
731 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000732const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000733
734/**
735 * Set the target triple for a module.
736 *
737 * @see Module::setTargetTriple()
738 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000739void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
740
Gregory Szorc34c863a2012-03-21 03:54:29 +0000741/**
Robert Widmannbce367702018-05-14 08:09:00 +0000742 * Returns the module flags as an array of flag-key-value triples. The caller
743 * is responsible for freeing this array by calling
744 * \c LLVMDisposeModuleFlagsMetadata.
745 *
746 * @see Module::getModuleFlagsMetadata()
747 */
748LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(LLVMModuleRef M, size_t *Len);
749
750/**
751 * Destroys module flags metadata entries.
752 */
753void LLVMDisposeModuleFlagsMetadata(LLVMModuleFlagEntry *Entries);
754
755/**
756 * Returns the flag behavior for a module flag entry at a specific index.
757 *
758 * @see Module::ModuleFlagEntry::Behavior
759 */
760LLVMModuleFlagBehavior
761LLVMModuleFlagEntriesGetFlagBehavior(LLVMModuleFlagEntry *Entries,
762 unsigned Index);
763
764/**
765 * Returns the key for a module flag entry at a specific index.
766 *
767 * @see Module::ModuleFlagEntry::Key
768 */
769const char *LLVMModuleFlagEntriesGetKey(LLVMModuleFlagEntry *Entries,
770 unsigned Index, size_t *Len);
771
772/**
773 * Returns the metadata for a module flag entry at a specific index.
774 *
775 * @see Module::ModuleFlagEntry::Val
776 */
777LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries,
778 unsigned Index);
779
780/**
781 * Add a module-level flag to the module-level flags metadata if it doesn't
782 * already exist.
783 *
784 * @see Module::getModuleFlag()
785 */
786LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRef M,
787 const char *Key, size_t KeyLen);
788
789/**
790 * Add a module-level flag to the module-level flags metadata if it doesn't
791 * already exist.
792 *
793 * @see Module::addModuleFlag()
794 */
795void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior,
796 const char *Key, size_t KeyLen,
797 LLVMMetadataRef Val);
798
799/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000800 * Dump a representation of a module to stderr.
801 *
802 * @see Module::dump()
803 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000804void LLVMDumpModule(LLVMModuleRef M);
805
Gregory Szorc34c863a2012-03-21 03:54:29 +0000806/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000807 * Print a representation of a module to a file. The ErrorMessage needs to be
808 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
809 *
810 * @see Module::print()
811 */
812LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
813 char **ErrorMessage);
814
815/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000816 * Return a string representation of the module. Use
817 * LLVMDisposeMessage to free the string.
818 *
819 * @see Module::print()
820 */
821char *LLVMPrintModuleToString(LLVMModuleRef M);
822
823/**
Robert Widmannf108d572018-04-06 02:31:29 +0000824 * Get inline assembly for a module.
825 *
826 * @see Module::getModuleInlineAsm()
827 */
828const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len);
829
830/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000831 * Set inline assembly for a module.
832 *
833 * @see Module::setModuleInlineAsm()
834 */
Robert Widmannf108d572018-04-06 02:31:29 +0000835void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len);
836
837/**
838 * Append inline assembly to a module.
839 *
840 * @see Module::appendModuleInlineAsm()
841 */
842void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len);
843
844/**
845 * Create the specified uniqued inline asm string.
846 *
847 * @see InlineAsm::get()
848 */
849LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty,
850 char *AsmString, size_t AsmStringSize,
851 char *Constraints, size_t ConstraintsSize,
852 LLVMBool HasSideEffects, LLVMBool IsAlignStack,
853 LLVMInlineAsmDialect Dialect);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000854
Gregory Szorc34c863a2012-03-21 03:54:29 +0000855/**
856 * Obtain the context to which this module is associated.
857 *
858 * @see Module::getContext()
859 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000860LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
861
Gregory Szorc34c863a2012-03-21 03:54:29 +0000862/**
863 * Obtain a Type from a module by its registered name.
864 */
865LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000866
Gregory Szorc34c863a2012-03-21 03:54:29 +0000867/**
Robert Widmann0a35b762018-08-30 17:09:43 +0000868 * Obtain an iterator to the first NamedMDNode in a Module.
869 *
870 * @see llvm::Module::named_metadata_begin()
871 */
872LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M);
873
874/**
875 * Obtain an iterator to the last NamedMDNode in a Module.
876 *
877 * @see llvm::Module::named_metadata_end()
878 */
879LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M);
880
881/**
882 * Advance a NamedMDNode iterator to the next NamedMDNode.
883 *
884 * Returns NULL if the iterator was already at the end and there are no more
885 * named metadata nodes.
886 */
887LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
888
889/**
890 * Decrement a NamedMDNode iterator to the previous NamedMDNode.
891 *
892 * Returns NULL if the iterator was already at the beginning and there are
893 * no previous named metadata nodes.
894 */
895LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
896
897/**
898 * Retrieve a NamedMDNode with the given name, returning NULL if no such
899 * node exists.
900 *
901 * @see llvm::Module::getNamedMetadata()
902 */
903LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M,
904 const char *Name, size_t NameLen);
905
906/**
907 * Retrieve a NamedMDNode with the given name, creating a new node if no such
908 * node exists.
909 *
910 * @see llvm::Module::getOrInsertNamedMetadata()
911 */
912LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M,
913 const char *Name,
914 size_t NameLen);
915
916/**
917 * Retrieve the name of a NamedMDNode.
918 *
919 * @see llvm::NamedMDNode::getName()
920 */
921const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NamedMD,
922 size_t *NameLen);
923
924/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000925 * Obtain the number of operands for named metadata in a module.
926 *
927 * @see llvm::Module::getNamedMetadata()
928 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000929unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000930
931/**
932 * Obtain the named metadata operands for a module.
933 *
934 * The passed LLVMValueRef pointer should refer to an array of
935 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
936 * array will be populated with the LLVMValueRef instances. Each
937 * instance corresponds to a llvm::MDNode.
938 *
939 * @see llvm::Module::getNamedMetadata()
940 * @see llvm::MDNode::getOperand()
941 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000942void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
943 LLVMValueRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000944
945/**
946 * Add an operand to named metadata.
947 *
948 * @see llvm::Module::getNamedMetadata()
949 * @see llvm::MDNode::addOperand()
950 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000951void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
Gregory Szorc34c863a2012-03-21 03:54:29 +0000952 LLVMValueRef Val);
953
Gregory Szorc52d26602012-03-21 07:28:27 +0000954/**
Saleem Abdulrasool0d1cbcc2018-10-10 23:53:12 +0000955 * Return the directory of the debug location for this value, which must be
956 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
957 *
958 * @see llvm::Instruction::getDebugLoc()
959 * @see llvm::GlobalVariable::getDebugInfo()
960 * @see llvm::Function::getSubprogram()
961 */
962const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length);
963
964/**
965 * Return the filename of the debug location for this value, which must be
966 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
967 *
968 * @see llvm::Instruction::getDebugLoc()
969 * @see llvm::GlobalVariable::getDebugInfo()
970 * @see llvm::Function::getSubprogram()
971 */
972const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length);
973
974/**
975 * Return the line number of the debug location for this value, which must be
976 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
977 *
978 * @see llvm::Instruction::getDebugLoc()
979 * @see llvm::GlobalVariable::getDebugInfo()
980 * @see llvm::Function::getSubprogram()
981 */
982unsigned LLVMGetDebugLocLine(LLVMValueRef Val);
983
984/**
985 * Return the column number of the debug location for this value, which must be
986 * an llvm::Instruction.
987 *
988 * @see llvm::Instruction::getDebugLoc()
989 */
990unsigned LLVMGetDebugLocColumn(LLVMValueRef Val);
991
992/**
Gregory Szorc52d26602012-03-21 07:28:27 +0000993 * Add a function to a module under a specified name.
994 *
995 * @see llvm::Function::Create()
996 */
997LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
998 LLVMTypeRef FunctionTy);
999
1000/**
1001 * Obtain a Function value from a Module by its name.
1002 *
1003 * The returned value corresponds to a llvm::Function value.
1004 *
1005 * @see llvm::Module::getFunction()
1006 */
1007LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
1008
1009/**
1010 * Obtain an iterator to the first Function in a Module.
1011 *
1012 * @see llvm::Module::begin()
1013 */
1014LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
1015
1016/**
1017 * Obtain an iterator to the last Function in a Module.
1018 *
1019 * @see llvm::Module::end()
1020 */
1021LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
1022
1023/**
1024 * Advance a Function iterator to the next Function.
1025 *
1026 * Returns NULL if the iterator was already at the end and there are no more
1027 * functions.
1028 */
1029LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
1030
1031/**
1032 * Decrement a Function iterator to the previous Function.
1033 *
1034 * Returns NULL if the iterator was already at the beginning and there are
1035 * no previous functions.
1036 */
1037LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001038
Robert Widmannf108d572018-04-06 02:31:29 +00001039/** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */
1040void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
1041
Gregory Szorc34c863a2012-03-21 03:54:29 +00001042/**
1043 * @}
1044 */
1045
1046/**
1047 * @defgroup LLVMCCoreType Types
1048 *
1049 * Types represent the type of a value.
1050 *
1051 * Types are associated with a context instance. The context internally
1052 * deduplicates types so there is only 1 instance of a specific type
1053 * alive at a time. In other words, a unique type is shared among all
1054 * consumers within a context.
1055 *
1056 * A Type in the C API corresponds to llvm::Type.
1057 *
1058 * Types have the following hierarchy:
1059 *
Gordon Henriksen76a03742007-09-18 03:18:57 +00001060 * types:
1061 * integer type
1062 * real type
1063 * function type
1064 * sequence types:
1065 * array type
1066 * pointer type
1067 * vector type
1068 * void type
1069 * label type
1070 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +00001071 *
1072 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001073 */
1074
Gregory Szorc34c863a2012-03-21 03:54:29 +00001075/**
1076 * Obtain the enumerated type of a Type instance.
1077 *
1078 * @see llvm::Type:getTypeID()
1079 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001080LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001081
1082/**
1083 * Whether the type has a known size.
1084 *
1085 * Things that don't have a size are abstract types, labels, and void.a
1086 *
1087 * @see llvm::Type::isSized()
1088 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +00001089LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +00001090
Gregory Szorc34c863a2012-03-21 03:54:29 +00001091/**
1092 * Obtain the context to which this type instance is associated.
1093 *
1094 * @see llvm::Type::getContext()
1095 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001096LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
1097
Gregory Szorc34c863a2012-03-21 03:54:29 +00001098/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +00001099 * Dump a representation of a type to stderr.
1100 *
1101 * @see llvm::Type::dump()
1102 */
1103void LLVMDumpType(LLVMTypeRef Val);
1104
1105/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +00001106 * Return a string representation of the type. Use
1107 * LLVMDisposeMessage to free the string.
1108 *
1109 * @see llvm::Type::print()
1110 */
1111char *LLVMPrintTypeToString(LLVMTypeRef Val);
1112
1113/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001114 * @defgroup LLVMCCoreTypeInt Integer Types
1115 *
1116 * Functions in this section operate on integer types.
1117 *
1118 * @{
1119 */
1120
1121/**
1122 * Obtain an integer type from a context with specified bit width.
1123 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001124LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
1125LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
1126LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
1127LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
1128LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001129LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001130LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
1131
Gregory Szorc34c863a2012-03-21 03:54:29 +00001132/**
1133 * Obtain an integer type from the global context with a specified bit
1134 * width.
1135 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001136LLVMTypeRef LLVMInt1Type(void);
1137LLVMTypeRef LLVMInt8Type(void);
1138LLVMTypeRef LLVMInt16Type(void);
1139LLVMTypeRef LLVMInt32Type(void);
1140LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001141LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001142LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001143unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001144
Gregory Szorc34c863a2012-03-21 03:54:29 +00001145/**
1146 * @}
1147 */
1148
1149/**
1150 * @defgroup LLVMCCoreTypeFloat Floating Point Types
1151 *
1152 * @{
1153 */
1154
1155/**
1156 * Obtain a 16-bit floating point type from a context.
1157 */
Dan Gohman518cda42011-12-17 00:04:22 +00001158LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001159
1160/**
1161 * Obtain a 32-bit floating point type from a context.
1162 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001163LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001164
1165/**
1166 * Obtain a 64-bit floating point type from a context.
1167 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001168LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001169
1170/**
1171 * Obtain a 80-bit floating point type (X87) from a context.
1172 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001173LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001174
1175/**
1176 * Obtain a 128-bit floating point type (112-bit mantissa) from a
1177 * context.
1178 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001179LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001180
1181/**
1182 * Obtain a 128-bit floating point type (two 64-bits) from a context.
1183 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001184LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
1185
Gregory Szorc34c863a2012-03-21 03:54:29 +00001186/**
1187 * Obtain a floating point type from the global context.
1188 *
1189 * These map to the functions in this group of the same name.
1190 */
Dan Gohman518cda42011-12-17 00:04:22 +00001191LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001192LLVMTypeRef LLVMFloatType(void);
1193LLVMTypeRef LLVMDoubleType(void);
1194LLVMTypeRef LLVMX86FP80Type(void);
1195LLVMTypeRef LLVMFP128Type(void);
1196LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001197
Gregory Szorc34c863a2012-03-21 03:54:29 +00001198/**
1199 * @}
1200 */
1201
1202/**
1203 * @defgroup LLVMCCoreTypeFunction Function Types
1204 *
1205 * @{
1206 */
1207
1208/**
1209 * Obtain a function type consisting of a specified signature.
1210 *
1211 * The function is defined as a tuple of a return Type, a list of
1212 * parameter types, and whether the function is variadic.
1213 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001214LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
1215 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001216 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001217
1218/**
1219 * Returns whether a function type is variadic.
1220 */
Chris Lattner25963c62010-01-09 22:27:07 +00001221LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001222
1223/**
1224 * Obtain the Type this function Type returns.
1225 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001226LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001227
1228/**
1229 * Obtain the number of parameters this function accepts.
1230 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001231unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001232
1233/**
1234 * Obtain the types of a function's parameters.
1235 *
1236 * The Dest parameter should point to a pre-allocated array of
1237 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
1238 * first LLVMCountParamTypes() entries in the array will be populated
1239 * with LLVMTypeRef instances.
1240 *
1241 * @param FunctionTy The function type to operate on.
1242 * @param Dest Memory address of an array to be filled with result.
1243 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001244void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001245
Gregory Szorc34c863a2012-03-21 03:54:29 +00001246/**
1247 * @}
1248 */
1249
1250/**
1251 * @defgroup LLVMCCoreTypeStruct Structure Types
1252 *
1253 * These functions relate to LLVMTypeRef instances.
1254 *
1255 * @see llvm::StructType
1256 *
1257 * @{
1258 */
1259
1260/**
1261 * Create a new structure type in a context.
1262 *
1263 * A structure is specified by a list of inner elements/types and
1264 * whether these can be packed together.
1265 *
1266 * @see llvm::StructType::create()
1267 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001268LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +00001269 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001270
1271/**
1272 * Create a new structure type in the global context.
1273 *
1274 * @see llvm::StructType::create()
1275 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001276LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001277 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001278
1279/**
1280 * Create an empty structure in a context having a specified name.
1281 *
1282 * @see llvm::StructType::create()
1283 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001284LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001285
1286/**
1287 * Obtain the name of a structure.
1288 *
1289 * @see llvm::StructType::getName()
1290 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +00001291const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001292
1293/**
1294 * Set the contents of a structure type.
1295 *
1296 * @see llvm::StructType::setBody()
1297 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001298void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
1299 unsigned ElementCount, LLVMBool Packed);
1300
Gregory Szorc34c863a2012-03-21 03:54:29 +00001301/**
1302 * Get the number of elements defined inside the structure.
1303 *
1304 * @see llvm::StructType::getNumElements()
1305 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001306unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001307
1308/**
1309 * Get the elements within a structure.
1310 *
1311 * The function is passed the address of a pre-allocated array of
1312 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
1313 * invocation, this array will be populated with the structure's
1314 * elements. The objects in the destination array will have a lifetime
1315 * of the structure type itself, which is the lifetime of the context it
1316 * is contained in.
1317 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001318void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001319
1320/**
Peter Zotovc164a3f2015-06-04 09:09:53 +00001321 * Get the type of the element at a given index in the structure.
1322 *
1323 * @see llvm::StructType::getTypeAtIndex()
1324 */
1325LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
1326
1327/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001328 * Determine whether a structure is packed.
1329 *
1330 * @see llvm::StructType::isPacked()
1331 */
Chris Lattner25963c62010-01-09 22:27:07 +00001332LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001333
1334/**
1335 * Determine whether a structure is opaque.
1336 *
1337 * @see llvm::StructType::isOpaque()
1338 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001339LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1340
Gregory Szorc34c863a2012-03-21 03:54:29 +00001341/**
whitequarkb4861072018-09-18 01:47:37 +00001342 * Determine whether a structure is literal.
1343 *
1344 * @see llvm::StructType::isLiteral()
1345 */
1346LLVMBool LLVMIsLiteralStruct(LLVMTypeRef StructTy);
1347
1348/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001349 * @}
1350 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001351
Gregory Szorc34c863a2012-03-21 03:54:29 +00001352/**
1353 * @defgroup LLVMCCoreTypeSequential Sequential Types
1354 *
1355 * Sequential types represents "arrays" of types. This is a super class
1356 * for array, vector, and pointer types.
1357 *
1358 * @{
1359 */
1360
1361/**
1362 * Obtain the type of elements within a sequential type.
1363 *
1364 * This works on array, vector, and pointer types.
1365 *
1366 * @see llvm::SequentialType::getElementType()
1367 */
1368LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1369
1370/**
whitequarkf6059fd2017-06-05 11:49:52 +00001371 * Returns type's subtypes
1372 *
1373 * @see llvm::Type::subtypes()
1374 */
1375void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr);
1376
1377/**
1378 * Return the number of types in the derived type.
1379 *
1380 * @see llvm::Type::getNumContainedTypes()
1381 */
1382unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp);
1383
1384/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001385 * Create a fixed size array type that refers to a specific type.
1386 *
1387 * The created type will exist in the context that its element type
1388 * exists in.
1389 *
1390 * @see llvm::ArrayType::get()
1391 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001392LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001393
1394/**
1395 * Obtain the length of an array type.
1396 *
1397 * This only works on types that represent arrays.
1398 *
1399 * @see llvm::ArrayType::getNumElements()
1400 */
1401unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1402
1403/**
1404 * Create a pointer type that points to a defined type.
1405 *
1406 * The created type will exist in the context that its pointee type
1407 * exists in.
1408 *
1409 * @see llvm::PointerType::get()
1410 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001411LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001412
1413/**
1414 * Obtain the address space of a pointer type.
1415 *
1416 * This only works on types that represent pointers.
1417 *
1418 * @see llvm::PointerType::getAddressSpace()
1419 */
1420unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1421
1422/**
1423 * Create a vector type that contains a defined type and has a specific
1424 * number of elements.
1425 *
1426 * The created type will exist in the context thats its element type
1427 * exists in.
1428 *
1429 * @see llvm::VectorType::get()
1430 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001431LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001432
Gregory Szorc34c863a2012-03-21 03:54:29 +00001433/**
1434 * Obtain the number of elements in a vector type.
1435 *
1436 * This only works on types that represent vectors.
1437 *
1438 * @see llvm::VectorType::getNumElements()
1439 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001440unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1441
Gregory Szorc34c863a2012-03-21 03:54:29 +00001442/**
1443 * @}
1444 */
1445
1446/**
1447 * @defgroup LLVMCCoreTypeOther Other Types
1448 *
1449 * @{
1450 */
1451
1452/**
1453 * Create a void type in a context.
1454 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001455LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001456
1457/**
1458 * Create a label type in a context.
1459 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001460LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001461
1462/**
1463 * Create a X86 MMX type in a context.
1464 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001465LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001466
Gregory Szorc34c863a2012-03-21 03:54:29 +00001467/**
whitequark131f98f2017-10-27 11:51:40 +00001468 * Create a token type in a context.
1469 */
1470LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C);
1471
1472/**
1473 * Create a metadata type in a context.
1474 */
1475LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C);
1476
1477/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001478 * These are similar to the above functions except they operate on the
1479 * global context.
1480 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001481LLVMTypeRef LLVMVoidType(void);
1482LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001483LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001484
Gregory Szorc34c863a2012-03-21 03:54:29 +00001485/**
1486 * @}
1487 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001488
Gregory Szorc34c863a2012-03-21 03:54:29 +00001489/**
1490 * @}
1491 */
1492
1493/**
1494 * @defgroup LLVMCCoreValues Values
1495 *
1496 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001497 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001498 *
1499 * LLVMValueRef essentially represents llvm::Value. There is a rich
1500 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001501 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001502 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001503 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001504 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1505 * functions are defined by a macro, so it isn't obvious which are
1506 * available by looking at the Doxygen source code. Instead, look at the
1507 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1508 * of value names given. These value names also correspond to classes in
1509 * the llvm::Value hierarchy.
1510 *
1511 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001512 */
1513
Gordon Henriksen29e38942008-12-19 18:39:45 +00001514#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1515 macro(Argument) \
1516 macro(BasicBlock) \
1517 macro(InlineAsm) \
1518 macro(User) \
1519 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001520 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001521 macro(ConstantAggregateZero) \
1522 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001523 macro(ConstantDataSequential) \
1524 macro(ConstantDataArray) \
1525 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001526 macro(ConstantExpr) \
1527 macro(ConstantFP) \
1528 macro(ConstantInt) \
1529 macro(ConstantPointerNull) \
1530 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001531 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001532 macro(ConstantVector) \
1533 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001534 macro(GlobalAlias) \
whitequarkd299b2c2018-09-18 00:01:12 +00001535 macro(GlobalIFunc) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001536 macro(GlobalObject) \
1537 macro(Function) \
1538 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001539 macro(UndefValue) \
1540 macro(Instruction) \
1541 macro(BinaryOperator) \
1542 macro(CallInst) \
1543 macro(IntrinsicInst) \
1544 macro(DbgInfoIntrinsic) \
Hsiangkai Wangef72e482018-08-06 03:59:47 +00001545 macro(DbgVariableIntrinsic) \
1546 macro(DbgDeclareInst) \
1547 macro(DbgLabelInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001548 macro(MemIntrinsic) \
1549 macro(MemCpyInst) \
1550 macro(MemMoveInst) \
1551 macro(MemSetInst) \
1552 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001553 macro(FCmpInst) \
1554 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001555 macro(ExtractElementInst) \
1556 macro(GetElementPtrInst) \
1557 macro(InsertElementInst) \
1558 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001559 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001560 macro(PHINode) \
1561 macro(SelectInst) \
1562 macro(ShuffleVectorInst) \
1563 macro(StoreInst) \
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00001564 macro(BranchInst) \
1565 macro(IndirectBrInst) \
1566 macro(InvokeInst) \
1567 macro(ReturnInst) \
1568 macro(SwitchInst) \
1569 macro(UnreachableInst) \
1570 macro(ResumeInst) \
1571 macro(CleanupReturnInst) \
1572 macro(CatchReturnInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001573 macro(FuncletPadInst) \
1574 macro(CatchPadInst) \
1575 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001576 macro(UnaryInstruction) \
1577 macro(AllocaInst) \
1578 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001579 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001580 macro(BitCastInst) \
1581 macro(FPExtInst) \
1582 macro(FPToSIInst) \
1583 macro(FPToUIInst) \
1584 macro(FPTruncInst) \
1585 macro(IntToPtrInst) \
1586 macro(PtrToIntInst) \
1587 macro(SExtInst) \
1588 macro(SIToFPInst) \
1589 macro(TruncInst) \
1590 macro(UIToFPInst) \
1591 macro(ZExtInst) \
1592 macro(ExtractValueInst) \
1593 macro(LoadInst) \
1594 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001595
Gregory Szorc34c863a2012-03-21 03:54:29 +00001596/**
1597 * @defgroup LLVMCCoreValueGeneral General APIs
1598 *
1599 * Functions in this section work on all LLVMValueRef instances,
1600 * regardless of their sub-type. They correspond to functions available
1601 * on llvm::Value.
1602 *
1603 * @{
1604 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001605
Gregory Szorc34c863a2012-03-21 03:54:29 +00001606/**
1607 * Obtain the type of a value.
1608 *
1609 * @see llvm::Value::getType()
1610 */
1611LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1612
1613/**
Peter Zotov3e4561c2016-04-06 22:21:29 +00001614 * Obtain the enumerated type of a Value instance.
1615 *
1616 * @see llvm::Value::getValueID()
1617 */
1618LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
1619
1620/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001621 * Obtain the string name of a value.
1622 *
1623 * @see llvm::Value::getName()
1624 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001625const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001626
1627/**
1628 * Set the string name of a value.
1629 *
1630 * @see llvm::Value::setName()
1631 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001632void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001633
1634/**
1635 * Dump a representation of a value to stderr.
1636 *
1637 * @see llvm::Value::dump()
1638 */
1639void LLVMDumpValue(LLVMValueRef Val);
1640
1641/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001642 * Return a string representation of the value. Use
1643 * LLVMDisposeMessage to free the string.
1644 *
1645 * @see llvm::Value::print()
1646 */
1647char *LLVMPrintValueToString(LLVMValueRef Val);
1648
1649/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001650 * Replace all uses of a value with another one.
1651 *
1652 * @see llvm::Value::replaceAllUsesWith()
1653 */
1654void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1655
1656/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001657 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001658 */
1659LLVMBool LLVMIsConstant(LLVMValueRef Val);
1660
1661/**
1662 * Determine whether a value instance is undefined.
1663 */
1664LLVMBool LLVMIsUndef(LLVMValueRef Val);
1665
1666/**
1667 * Convert value instances between types.
1668 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001669 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001670 * series of functions allows you to cast an instance to a specific
1671 * type.
1672 *
1673 * If the cast is not valid for the specified type, NULL is returned.
1674 *
1675 * @see llvm::dyn_cast_or_null<>
1676 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001677#define LLVM_DECLARE_VALUE_CAST(name) \
1678 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1679LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1680
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001681LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1682LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1683
Robert Widmann025c78f2018-05-19 15:08:36 +00001684/** Deprecated: Use LLVMGetValueName2 instead. */
1685const char *LLVMGetValueName(LLVMValueRef Val);
1686/** Deprecated: Use LLVMSetValueName2 instead. */
1687void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1688
Gregory Szorc34c863a2012-03-21 03:54:29 +00001689/**
1690 * @}
1691 */
1692
1693/**
1694 * @defgroup LLVMCCoreValueUses Usage
1695 *
1696 * This module defines functions that allow you to inspect the uses of a
1697 * LLVMValueRef.
1698 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001699 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001700 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1701 * llvm::User and llvm::Value.
1702 *
1703 * @{
1704 */
1705
1706/**
1707 * Obtain the first use of a value.
1708 *
1709 * Uses are obtained in an iterator fashion. First, call this function
1710 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001711 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001712 * LLVMGetNextUse() returns NULL.
1713 *
1714 * @see llvm::Value::use_begin()
1715 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001716LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001717
1718/**
1719 * Obtain the next use of a value.
1720 *
1721 * This effectively advances the iterator. It returns NULL if you are on
1722 * the final use and no more are available.
1723 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001724LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001725
1726/**
1727 * Obtain the user value for a user.
1728 *
1729 * The returned value corresponds to a llvm::User type.
1730 *
1731 * @see llvm::Use::getUser()
1732 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001733LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001734
1735/**
1736 * Obtain the value this use corresponds to.
1737 *
1738 * @see llvm::Use::get().
1739 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001740LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001741
Gregory Szorc34c863a2012-03-21 03:54:29 +00001742/**
1743 * @}
1744 */
1745
1746/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001747 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001748 *
1749 * Function in this group pertain to LLVMValueRef instances that descent
1750 * from llvm::User. This includes constants, instructions, and
1751 * operators.
1752 *
1753 * @{
1754 */
1755
1756/**
1757 * Obtain an operand at a specific index in a llvm::User value.
1758 *
1759 * @see llvm::User::getOperand()
1760 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001761LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001762
1763/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001764 * Obtain the use of an operand at a specific index in a llvm::User value.
1765 *
1766 * @see llvm::User::getOperandUse()
1767 */
1768LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1769
1770/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001771 * Set an operand at a specific index in a llvm::User value.
1772 *
1773 * @see llvm::User::setOperand()
1774 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001775void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001776
1777/**
1778 * Obtain the number of operands in a llvm::User value.
1779 *
1780 * @see llvm::User::getNumOperands()
1781 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001782int LLVMGetNumOperands(LLVMValueRef Val);
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 LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001790 *
1791 * This section contains APIs for interacting with LLVMValueRef that
1792 * correspond to llvm::Constant instances.
1793 *
1794 * These functions will work for any LLVMValueRef in the llvm::Constant
1795 * class hierarchy.
1796 *
1797 * @{
1798 */
1799
1800/**
1801 * Obtain a constant value referring to the null instance of a type.
1802 *
1803 * @see llvm::Constant::getNullValue()
1804 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001805LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001806
1807/**
1808 * Obtain a constant value referring to the instance of a type
1809 * consisting of all ones.
1810 *
1811 * This is only valid for integer types.
1812 *
1813 * @see llvm::Constant::getAllOnesValue()
1814 */
1815LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1816
1817/**
1818 * Obtain a constant value referring to an undefined value of a type.
1819 *
1820 * @see llvm::UndefValue::get()
1821 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001822LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001823
1824/**
1825 * Determine whether a value instance is null.
1826 *
1827 * @see llvm::Constant::isNullValue()
1828 */
Chris Lattner25963c62010-01-09 22:27:07 +00001829LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001830
1831/**
1832 * Obtain a constant that is a constant pointer pointing to NULL for a
1833 * specified type.
1834 */
Chris Lattner7f318242009-07-06 17:29:59 +00001835LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001836
Gregory Szorc34c863a2012-03-21 03:54:29 +00001837/**
1838 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1839 *
1840 * Functions in this group model LLVMValueRef instances that correspond
1841 * to constants referring to scalar types.
1842 *
1843 * For integer types, the LLVMTypeRef parameter should correspond to a
1844 * llvm::IntegerType instance and the returned LLVMValueRef will
1845 * correspond to a llvm::ConstantInt.
1846 *
1847 * For floating point types, the LLVMTypeRef returned corresponds to a
1848 * llvm::ConstantFP.
1849 *
1850 * @{
1851 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001852
Gregory Szorc34c863a2012-03-21 03:54:29 +00001853/**
1854 * Obtain a constant value for an integer type.
1855 *
1856 * The returned value corresponds to a llvm::ConstantInt.
1857 *
1858 * @see llvm::ConstantInt::get()
1859 *
1860 * @param IntTy Integer type to obtain value of.
1861 * @param N The value the returned instance should refer to.
1862 * @param SignExtend Whether to sign extend the produced value.
1863 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001864LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001865 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001866
1867/**
1868 * Obtain a constant value for an integer of arbitrary precision.
1869 *
1870 * @see llvm::ConstantInt::get()
1871 */
Chris Lattner4329e072010-11-23 02:47:22 +00001872LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1873 unsigned NumWords,
1874 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001875
1876/**
1877 * Obtain a constant value for an integer parsed from a string.
1878 *
1879 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1880 * string's length is available, it is preferred to call that function
1881 * instead.
1882 *
1883 * @see llvm::ConstantInt::get()
1884 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001885LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1886 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001887
1888/**
1889 * Obtain a constant value for an integer parsed from a string with
1890 * specified length.
1891 *
1892 * @see llvm::ConstantInt::get()
1893 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001894LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1895 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001896
1897/**
1898 * Obtain a constant value referring to a double floating point value.
1899 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001900LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001901
1902/**
1903 * Obtain a constant for a floating point value parsed from a string.
1904 *
1905 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1906 * should be used if the input string's length is known.
1907 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001908LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001909
1910/**
1911 * Obtain a constant for a floating point value parsed from a string.
1912 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001913LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1914 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001915
1916/**
1917 * Obtain the zero extended value for an integer constant value.
1918 *
1919 * @see llvm::ConstantInt::getZExtValue()
1920 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001921unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001922
1923/**
1924 * Obtain the sign extended value for an integer constant value.
1925 *
1926 * @see llvm::ConstantInt::getSExtValue()
1927 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001928long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001929
Gregory Szorc34c863a2012-03-21 03:54:29 +00001930/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001931 * Obtain the double value for an floating point constant value.
1932 * losesInfo indicates if some precision was lost in the conversion.
1933 *
1934 * @see llvm::ConstantFP::getDoubleValue
1935 */
1936double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1937
1938/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001939 * @}
1940 */
1941
1942/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001943 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1944 *
1945 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001946 *
1947 * @{
1948 */
1949
1950/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001951 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001952 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001953 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001954 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001955LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001956 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001957
1958/**
1959 * Create a ConstantDataSequential with string content in the global context.
1960 *
1961 * This is the same as LLVMConstStringInContext except it operates on the
1962 * global context.
1963 *
1964 * @see LLVMConstStringInContext()
1965 * @see llvm::ConstantDataArray::getString()
1966 */
1967LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1968 LLVMBool DontNullTerminate);
1969
1970/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001971 * Returns true if the specified constant is an array of i8.
1972 *
1973 * @see ConstantDataSequential::getAsString()
1974 */
1975LLVMBool LLVMIsConstantString(LLVMValueRef c);
1976
1977/**
1978 * Get the given constant data sequential as a string.
1979 *
1980 * @see ConstantDataSequential::getAsString()
1981 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00001982const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001983
1984/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001985 * Create an anonymous ConstantStruct with the specified values.
1986 *
1987 * @see llvm::ConstantStruct::getAnon()
1988 */
1989LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001990 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001991 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001992
Gregory Szorc52d26602012-03-21 07:28:27 +00001993/**
1994 * Create a ConstantStruct in the global Context.
1995 *
1996 * This is the same as LLVMConstStructInContext except it operates on the
1997 * global Context.
1998 *
1999 * @see LLVMConstStructInContext()
2000 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002001LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00002002 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00002003
2004/**
2005 * Create a ConstantArray from values.
2006 *
2007 * @see llvm::ConstantArray::get()
2008 */
2009LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
2010 LLVMValueRef *ConstantVals, unsigned Length);
2011
2012/**
2013 * Create a non-anonymous ConstantStruct from values.
2014 *
2015 * @see llvm::ConstantStruct::get()
2016 */
Rafael Espindola784ad242011-07-14 19:09:08 +00002017LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
2018 LLVMValueRef *ConstantVals,
2019 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00002020
2021/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00002022 * Get an element at specified index as a constant.
2023 *
2024 * @see ConstantDataSequential::getElementAsConstant()
2025 */
Amaury Sechet006ce632016-03-13 00:54:40 +00002026LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
Peter Zotovf9aa8822014-08-03 23:54:16 +00002027
2028/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002029 * Create a ConstantVector from values.
2030 *
2031 * @see llvm::ConstantVector::get()
2032 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002033LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002034
Gregory Szorc52d26602012-03-21 07:28:27 +00002035/**
2036 * @}
2037 */
2038
2039/**
2040 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
2041 *
2042 * Functions in this group correspond to APIs on llvm::ConstantExpr.
2043 *
2044 * @see llvm::ConstantExpr.
2045 *
2046 * @{
2047 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002048LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002049LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002050LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
2051LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002052LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
2053LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002054LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002055LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
2056LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002057LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002058LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002059LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002060LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002061LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2062LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002063LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002064LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002065LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2066LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002067LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002068LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Manuel Jacob49fafb12016-10-04 23:32:42 +00002069LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002070LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002071LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002072LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2073LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2074LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2075LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2076LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2077LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2078LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2079LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
2080 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2081LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
2082 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2083LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2084LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2085LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2086LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
2087 LLVMValueRef *ConstantIndices, unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002088LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2089 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002090LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
2091 LLVMValueRef *ConstantIndices,
2092 unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002093LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2094 LLVMValueRef *ConstantIndices,
2095 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002096LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2097LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2098LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2099LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2100LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2101LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2102LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2103LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2104LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2105LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2106LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2107LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002108LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002109LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
2110 LLVMTypeRef ToType);
2111LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
2112 LLVMTypeRef ToType);
2113LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
2114 LLVMTypeRef ToType);
2115LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
2116 LLVMTypeRef ToType);
2117LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00002118 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002119LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002120LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
2121 LLVMValueRef ConstantIfTrue,
2122 LLVMValueRef ConstantIfFalse);
2123LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
2124 LLVMValueRef IndexConstant);
2125LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
2126 LLVMValueRef ElementValueConstant,
2127 LLVMValueRef IndexConstant);
2128LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
2129 LLVMValueRef VectorBConstant,
2130 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00002131LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
2132 unsigned NumIdx);
2133LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
2134 LLVMValueRef ElementValueConstant,
2135 unsigned *IdxList, unsigned NumIdx);
Robert Widmannf108d572018-04-06 02:31:29 +00002136LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
2137
2138/** Deprecated: Use LLVMGetInlineAsm instead. */
Chris Lattner25963c62010-01-09 22:27:07 +00002139LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00002140 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00002141 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002142
Gregory Szorc52d26602012-03-21 07:28:27 +00002143/**
2144 * @}
2145 */
2146
2147/**
2148 * @defgroup LLVMCCoreValueConstantGlobals Global Values
2149 *
2150 * This group contains functions that operate on global values. Functions in
2151 * this group relate to functions in the llvm::GlobalValue class tree.
2152 *
2153 * @see llvm::GlobalValue
2154 *
2155 * @{
2156 */
2157
Gordon Henriksen265f7802008-03-19 01:11:35 +00002158LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00002159LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002160LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
2161void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
2162const char *LLVMGetSection(LLVMValueRef Global);
2163void LLVMSetSection(LLVMValueRef Global, const char *Section);
2164LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
2165void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00002166LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
2167void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002168LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
2169void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
2170
Robert Widmanne63a12c2018-09-28 20:54:29 +00002171/**
2172 * Returns the "value type" of a global value. This differs from the formal
2173 * type of a global value which is always a pointer type.
2174 *
2175 * @see llvm::GlobalValue::getValueType()
2176 */
2177LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
2178
Robert Widmann4bb481b2018-03-14 06:45:51 +00002179/** Deprecated: Use LLVMGetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002180LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002181/** Deprecated: Use LLVMSetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002182void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002183
2184/**
2185 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
2186 *
2187 * Functions in this group only apply to values with alignment, i.e.
2188 * global variables, load and store instructions.
2189 */
2190
2191/**
2192 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002193 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002194 * @see llvm::LoadInst::getAlignment()
2195 * @see llvm::StoreInst::getAlignment()
2196 * @see llvm::GlobalValue::getAlignment()
2197 */
2198unsigned LLVMGetAlignment(LLVMValueRef V);
2199
2200/**
2201 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002202 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002203 * @see llvm::LoadInst::setAlignment()
2204 * @see llvm::StoreInst::setAlignment()
2205 * @see llvm::GlobalValue::setAlignment()
2206 */
2207void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
2208
2209/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00002210 * Sets a metadata attachment, erasing the existing metadata attachment if
2211 * it already exists for the given kind.
2212 *
2213 * @see llvm::GlobalObject::setMetadata()
2214 */
2215void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind,
2216 LLVMMetadataRef MD);
2217
2218/**
2219 * Erases a metadata attachment of the given kind if it exists.
2220 *
2221 * @see llvm::GlobalObject::eraseMetadata()
2222 */
2223void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind);
2224
2225/**
2226 * Removes all metadata attachments from this value.
2227 *
2228 * @see llvm::GlobalObject::clearMetadata()
2229 */
2230void LLVMGlobalClearMetadata(LLVMValueRef Global);
2231
2232/**
2233 * Retrieves an array of metadata entries representing the metadata attached to
2234 * this value. The caller is responsible for freeing this array by calling
2235 * \c LLVMDisposeValueMetadataEntries.
2236 *
2237 * @see llvm::GlobalObject::getAllMetadata()
2238 */
2239LLVMValueMetadataEntry *LLVMGlobalCopyAllMetadata(LLVMValueRef Value,
2240 size_t *NumEntries);
2241
2242/**
2243 * Destroys value metadata entries.
2244 */
2245void LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries);
2246
2247/**
2248 * Returns the kind of a value metadata entry at a specific index.
2249 */
2250unsigned LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries,
2251 unsigned Index);
2252
2253/**
2254 * Returns the underlying metadata node of a value metadata entry at a
2255 * specific index.
2256 */
2257LLVMMetadataRef
2258LLVMValueMetadataEntriesGetMetadata(LLVMValueMetadataEntry *Entries,
2259 unsigned Index);
2260
2261/**
Amaury Sechet83550102016-02-14 08:58:49 +00002262 * @}
2263 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002264
Gregory Szorc52d26602012-03-21 07:28:27 +00002265/**
2266 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
2267 *
2268 * This group contains functions that operate on global variable values.
2269 *
2270 * @see llvm::GlobalVariable
2271 *
2272 * @{
2273 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002274LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00002275LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
2276 const char *Name,
2277 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00002278LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002279LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
2280LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
2281LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
2282LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002283void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002284LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
2285void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00002286LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
2287void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
2288LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
2289void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00002290LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
2291void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
2292LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
2293void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002294
Gregory Szorc52d26602012-03-21 07:28:27 +00002295/**
2296 * @}
2297 */
2298
2299/**
2300 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
2301 *
2302 * This group contains function that operate on global alias values.
2303 *
2304 * @see llvm::GlobalAlias
2305 *
2306 * @{
2307 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00002308LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
2309 const char *Name);
2310
Gregory Szorc34c863a2012-03-21 03:54:29 +00002311/**
Robert Widmann360d6e32018-05-20 23:49:08 +00002312 * Obtain a GlobalAlias value from a Module by its name.
2313 *
2314 * The returned value corresponds to a llvm::GlobalAlias value.
2315 *
2316 * @see llvm::Module::getNamedAlias()
2317 */
2318LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M,
2319 const char *Name, size_t NameLen);
2320
2321/**
2322 * Obtain an iterator to the first GlobalAlias in a Module.
2323 *
2324 * @see llvm::Module::alias_begin()
2325 */
2326LLVMValueRef LLVMGetFirstGlobalAlias(LLVMModuleRef M);
2327
2328/**
2329 * Obtain an iterator to the last GlobalAlias in a Module.
2330 *
2331 * @see llvm::Module::alias_end()
2332 */
2333LLVMValueRef LLVMGetLastGlobalAlias(LLVMModuleRef M);
2334
2335/**
2336 * Advance a GlobalAlias iterator to the next GlobalAlias.
2337 *
2338 * Returns NULL if the iterator was already at the end and there are no more
2339 * global aliases.
2340 */
2341LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA);
2342
2343/**
2344 * Decrement a GlobalAlias iterator to the previous GlobalAlias.
2345 *
2346 * Returns NULL if the iterator was already at the beginning and there are
2347 * no previous global aliases.
2348 */
2349LLVMValueRef LLVMGetPreviousGlobalAlias(LLVMValueRef GA);
2350
2351/**
2352 * Retrieve the target value of an alias.
2353 */
2354LLVMValueRef LLVMAliasGetAliasee(LLVMValueRef Alias);
2355
2356/**
2357 * Set the target value of an alias.
2358 */
2359void LLVMAliasSetAliasee(LLVMValueRef Alias, LLVMValueRef Aliasee);
2360
2361/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002362 * @}
2363 */
2364
2365/**
2366 * @defgroup LLVMCCoreValueFunction Function values
2367 *
2368 * Functions in this group operate on LLVMValueRef instances that
2369 * correspond to llvm::Function instances.
2370 *
2371 * @see llvm::Function
2372 *
2373 * @{
2374 */
2375
2376/**
2377 * Remove a function from its containing module and deletes it.
2378 *
2379 * @see llvm::Function::eraseFromParent()
2380 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002381void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002382
2383/**
Amaury Sechete39e8532016-02-18 20:38:32 +00002384 * Check whether the given function has a personality function.
2385 *
2386 * @see llvm::Function::hasPersonalityFn()
2387 */
2388LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
2389
2390/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00002391 * Obtain the personality function attached to the function.
2392 *
2393 * @see llvm::Function::getPersonalityFn()
2394 */
2395LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
2396
2397/**
2398 * Set the personality function attached to the function.
2399 *
2400 * @see llvm::Function::setPersonalityFn()
2401 */
2402void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
2403
2404/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002405 * Obtain the ID number from a function instance.
2406 *
2407 * @see llvm::Function::getIntrinsicID()
2408 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002409unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002410
2411/**
Robert Widmannd36f3b02018-11-06 01:38:14 +00002412 * Create or insert the declaration of an intrinsic. For overloaded intrinsics,
2413 * parameter types must be provided to uniquely identify an overload.
2414 *
2415 * @see llvm::Intrinsic::getDeclaration()
2416 */
2417LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
2418 unsigned ID,
2419 LLVMTypeRef *ParamTypes,
2420 size_t ParamCount);
2421
2422/**
2423 * Retrieves the type of an intrinsic. For overloaded intrinsics, parameter
2424 * types must be provided to uniquely identify an overload.
2425 *
2426 * @see llvm::Intrinsic::getType()
2427 */
2428LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID,
2429 LLVMTypeRef *ParamTypes, size_t ParamCount);
2430
2431/**
2432 * Retrieves the name of an intrinsic.
2433 *
2434 * @see llvm::Intrinsic::getName()
2435 */
2436const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength);
2437
2438/**
2439 * Copies the name of an overloaded intrinsic identified by a given list of
2440 * parameter types.
2441 *
2442 * Unlike LLVMIntrinsicGetName, the caller is responsible for freeing the
2443 * returned string.
2444 *
2445 * @see llvm::Intrinsic::getName()
2446 */
2447const char *LLVMIntrinsicCopyOverloadedName(unsigned ID,
2448 LLVMTypeRef *ParamTypes,
2449 size_t ParamCount,
2450 size_t *NameLength);
2451
2452/**
2453 * Obtain if the intrinsic identified by the given ID is overloaded.
2454 *
2455 * @see llvm::Intrinsic::isOverloaded()
2456 */
2457LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID);
2458
2459/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002460 * Obtain the calling function of a function.
2461 *
2462 * The returned value corresponds to the LLVMCallConv enumeration.
2463 *
2464 * @see llvm::Function::getCallingConv()
2465 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002466unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002467
2468/**
2469 * Set the calling convention of a function.
2470 *
2471 * @see llvm::Function::setCallingConv()
2472 *
2473 * @param Fn Function to operate on
2474 * @param CC LLVMCallConv to set calling convention to
2475 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002476void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002477
2478/**
2479 * Obtain the name of the garbage collector to use during code
2480 * generation.
2481 *
2482 * @see llvm::Function::getGC()
2483 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002484const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002485
2486/**
2487 * Define the garbage collector to use during code generation.
2488 *
2489 * @see llvm::Function::setGC()
2490 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002491void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002492
2493/**
2494 * Add an attribute to a function.
2495 *
2496 * @see llvm::Function::addAttribute()
2497 */
Amaury Sechet5db224e2016-06-12 06:17:24 +00002498void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2499 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00002500unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx);
2501void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2502 LLVMAttributeRef *Attrs);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002503LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
2504 LLVMAttributeIndex Idx,
2505 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002506LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
2507 LLVMAttributeIndex Idx,
2508 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002509void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2510 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002511void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2512 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002513
Gregory Szorc34c863a2012-03-21 03:54:29 +00002514/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00002515 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00002516 * @see llvm::AttrBuilder::addAttribute()
2517 */
2518void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
2519 const char *V);
2520
2521/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002522 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
2523 *
2524 * Functions in this group relate to arguments/parameters on functions.
2525 *
2526 * Functions in this group expect LLVMValueRef instances that correspond
2527 * to llvm::Function instances.
2528 *
2529 * @{
2530 */
2531
2532/**
2533 * Obtain the number of parameters in a function.
2534 *
2535 * @see llvm::Function::arg_size()
2536 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002537unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002538
2539/**
2540 * Obtain the parameters in a function.
2541 *
2542 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
2543 * at least LLVMCountParams() long. This array will be filled with
2544 * LLVMValueRef instances which correspond to the parameters the
2545 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
2546 * instance.
2547 *
2548 * @see llvm::Function::arg_begin()
2549 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002550void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002551
2552/**
2553 * Obtain the parameter at the specified index.
2554 *
2555 * Parameters are indexed from 0.
2556 *
2557 * @see llvm::Function::arg_begin()
2558 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002559LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002560
2561/**
2562 * Obtain the function to which this argument belongs.
2563 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002564 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002565 * that corresponds to a llvm::Attribute.
2566 *
2567 * The returned LLVMValueRef is the llvm::Function to which this
2568 * argument belongs.
2569 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002570LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002571
2572/**
2573 * Obtain the first parameter to a function.
2574 *
2575 * @see llvm::Function::arg_begin()
2576 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002577LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002578
2579/**
2580 * Obtain the last parameter to a function.
2581 *
2582 * @see llvm::Function::arg_end()
2583 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002584LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002585
2586/**
2587 * Obtain the next parameter to a function.
2588 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002589 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002590 * actually a wrapped iterator) and obtains the next parameter from the
2591 * underlying iterator.
2592 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002593LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002594
2595/**
2596 * Obtain the previous parameter to a function.
2597 *
2598 * This is the opposite of LLVMGetNextParam().
2599 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002600LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002601
2602/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002603 * Set the alignment for a function parameter.
2604 *
2605 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002606 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002607 */
Amaury Sechet81243a72016-05-01 01:42:34 +00002608void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002609
Gregory Szorc34c863a2012-03-21 03:54:29 +00002610/**
2611 * @}
2612 */
2613
2614/**
Robert Widmannd5444cc2019-02-05 18:05:44 +00002615 * @defgroup LLVMCCoreValueGlobalIFunc IFuncs
2616 *
2617 * Functions in this group relate to indirect functions.
2618 *
2619 * Functions in this group expect LLVMValueRef instances that correspond
2620 * to llvm::GlobalIFunc instances.
2621 *
2622 * @{
2623 */
2624
2625/**
2626 * Add a global indirect function to a module under a specified name.
2627 *
2628 * @see llvm::GlobalIFunc::create()
2629 */
2630LLVMValueRef LLVMAddGlobalIFunc(LLVMModuleRef M,
2631 const char *Name, size_t NameLen,
2632 LLVMTypeRef Ty, unsigned AddrSpace,
2633 LLVMValueRef Resolver);
2634
2635/**
2636 * Obtain a GlobalIFunc value from a Module by its name.
2637 *
2638 * The returned value corresponds to a llvm::GlobalIFunc value.
2639 *
2640 * @see llvm::Module::getNamedIFunc()
2641 */
2642LLVMValueRef LLVMGetNamedGlobalIFunc(LLVMModuleRef M,
2643 const char *Name, size_t NameLen);
2644
2645/**
2646 * Obtain an iterator to the first GlobalIFunc in a Module.
2647 *
2648 * @see llvm::Module::ifunc_begin()
2649 */
2650LLVMValueRef LLVMGetFirstGlobalIFunc(LLVMModuleRef M);
2651
2652/**
2653 * Obtain an iterator to the last GlobalIFunc in a Module.
2654 *
2655 * @see llvm::Module::ifunc_end()
2656 */
2657LLVMValueRef LLVMGetLastGlobalIFunc(LLVMModuleRef M);
2658
2659/**
2660 * Advance a GlobalIFunc iterator to the next GlobalIFunc.
2661 *
2662 * Returns NULL if the iterator was already at the end and there are no more
2663 * global aliases.
2664 */
2665LLVMValueRef LLVMGetNextGlobalIFunc(LLVMValueRef IFunc);
2666
2667/**
2668 * Decrement a GlobalIFunc iterator to the previous GlobalIFunc.
2669 *
2670 * Returns NULL if the iterator was already at the beginning and there are
2671 * no previous global aliases.
2672 */
2673LLVMValueRef LLVMGetPreviousGlobalIFunc(LLVMValueRef IFunc);
2674
2675/**
2676 * Retrieves the resolver function associated with this indirect function, or
2677 * NULL if it doesn't not exist.
2678 *
2679 * @see llvm::GlobalIFunc::getResolver()
2680 */
2681LLVMValueRef LLVMGetGlobalIFuncResolver(LLVMValueRef IFunc);
2682
2683/**
2684 * Sets the resolver function associated with this indirect function.
2685 *
2686 * @see llvm::GlobalIFunc::setResolver()
2687 */
2688void LLVMSetGlobalIFuncResolver(LLVMValueRef IFunc, LLVMValueRef Resolver);
2689
2690/**
2691 * Remove a global indirect function from its parent module and delete it.
2692 *
2693 * @see llvm::GlobalIFunc::eraseFromParent()
2694 */
2695void LLVMEraseGlobalIFunc(LLVMValueRef IFunc);
2696
2697/**
2698 * Remove a global indirect function from its parent module.
2699 *
2700 * This unlinks the global indirect function from its containing module but
2701 * keeps it alive.
2702 *
2703 * @see llvm::GlobalIFunc::removeFromParent()
2704 */
2705void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc);
2706
2707/**
2708 * @}
2709 */
2710
2711/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002712 * @}
2713 */
2714
2715/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002716 * @}
2717 */
2718
2719/**
2720 * @}
2721 */
2722
2723/**
2724 * @defgroup LLVMCCoreValueMetadata Metadata
2725 *
2726 * @{
2727 */
2728
2729/**
2730 * Obtain a MDString value from a context.
2731 *
2732 * The returned instance corresponds to the llvm::MDString class.
2733 *
2734 * The instance is specified by string data of a specified length. The
2735 * string content is copied, so the backing memory can be freed after
2736 * this function returns.
2737 */
2738LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2739 unsigned SLen);
2740
2741/**
2742 * Obtain a MDString value from the global context.
2743 */
2744LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2745
2746/**
2747 * Obtain a MDNode value from a context.
2748 *
2749 * The returned value corresponds to the llvm::MDNode class.
2750 */
2751LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2752 unsigned Count);
2753
2754/**
2755 * Obtain a MDNode value from the global context.
2756 */
2757LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2758
2759/**
Amaury Sechetf8429752017-04-17 11:52:54 +00002760 * Obtain a Metadata as a Value.
2761 */
2762LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
2763
2764/**
2765 * Obtain a Value as a Metadata.
2766 */
2767LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
2768
2769/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002770 * Obtain the underlying string from a MDString value.
2771 *
2772 * @param V Instance to obtain string from.
NAKAMURA Takumie4a77052016-04-04 11:54:48 +00002773 * @param Length Memory address which will hold length of returned string.
Gregory Szorc52d26602012-03-21 07:28:27 +00002774 * @return String data in MDString.
2775 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002776const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
Gregory Szorc52d26602012-03-21 07:28:27 +00002777
2778/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002779 * Obtain the number of operands from an MDNode value.
2780 *
2781 * @param V MDNode to get number of operands from.
2782 * @return Number of operands of the MDNode.
2783 */
2784unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2785
2786/**
2787 * Obtain the given MDNode's operands.
2788 *
2789 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2790 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2791 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2792 * MDNode's operands.
2793 *
2794 * @param V MDNode to get the operands from.
2795 * @param Dest Destination array for operands.
2796 */
2797void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2798
2799/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002800 * @}
2801 */
2802
2803/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002804 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2805 *
2806 * A basic block represents a single entry single exit section of code.
2807 * Basic blocks contain a list of instructions which form the body of
2808 * the block.
2809 *
2810 * Basic blocks belong to functions. They have the type of label.
2811 *
2812 * Basic blocks are themselves values. However, the C API models them as
2813 * LLVMBasicBlockRef.
2814 *
2815 * @see llvm::BasicBlock
2816 *
2817 * @{
2818 */
2819
2820/**
2821 * Convert a basic block instance to a value type.
2822 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002823LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002824
2825/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002826 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002827 */
Chris Lattner25963c62010-01-09 22:27:07 +00002828LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002829
2830/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002831 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002832 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002833LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002834
2835/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002836 * Obtain the string name of a basic block.
2837 */
2838const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2839
2840/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002841 * Obtain the function to which a basic block belongs.
2842 *
2843 * @see llvm::BasicBlock::getParent()
2844 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002845LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002846
2847/**
2848 * Obtain the terminator instruction for a basic block.
2849 *
2850 * If the basic block does not have a terminator (it is not well-formed
2851 * if it doesn't), then NULL is returned.
2852 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00002853 * The returned LLVMValueRef corresponds to an llvm::Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002854 *
2855 * @see llvm::BasicBlock::getTerminator()
2856 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002857LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002858
2859/**
2860 * Obtain the number of basic blocks in a function.
2861 *
2862 * @param Fn Function value to operate on.
2863 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002864unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002865
2866/**
2867 * Obtain all of the basic blocks in a function.
2868 *
2869 * This operates on a function value. The BasicBlocks parameter is a
2870 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2871 * LLVMCountBasicBlocks() in length. This array is populated with
2872 * LLVMBasicBlockRef instances.
2873 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002874void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002875
2876/**
2877 * Obtain the first basic block in a function.
2878 *
2879 * The returned basic block can be used as an iterator. You will likely
2880 * eventually call into LLVMGetNextBasicBlock() with it.
2881 *
2882 * @see llvm::Function::begin()
2883 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002884LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002885
2886/**
2887 * Obtain the last basic block in a function.
2888 *
2889 * @see llvm::Function::end()
2890 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002891LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002892
2893/**
2894 * Advance a basic block iterator.
2895 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002896LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002897
2898/**
2899 * Go backwards in a basic block iterator.
2900 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002901LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002902
2903/**
2904 * Obtain the basic block that corresponds to the entry point of a
2905 * function.
2906 *
2907 * @see llvm::Function::getEntryBlock()
2908 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002909LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002910
Gregory Szorc34c863a2012-03-21 03:54:29 +00002911/**
Robert Widmann616ed172019-01-08 06:24:19 +00002912 * Create a new basic block without inserting it into a function.
2913 *
2914 * @see llvm::BasicBlock::Create()
2915 */
2916LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C,
James Y Knight68729f92019-01-14 17:16:55 +00002917 const char *Name);
Robert Widmann616ed172019-01-08 06:24:19 +00002918
2919/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002920 * Append a basic block to the end of a function.
2921 *
2922 * @see llvm::BasicBlock::Create()
2923 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002924LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2925 LLVMValueRef Fn,
2926 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002927
2928/**
2929 * Append a basic block to the end of a function using the global
2930 * context.
2931 *
2932 * @see llvm::BasicBlock::Create()
2933 */
2934LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2935
2936/**
2937 * Insert a basic block in a function before another basic block.
2938 *
2939 * The function to add to is determined by the function of the
2940 * passed basic block.
2941 *
2942 * @see llvm::BasicBlock::Create()
2943 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002944LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2945 LLVMBasicBlockRef BB,
2946 const char *Name);
2947
Gregory Szorc34c863a2012-03-21 03:54:29 +00002948/**
2949 * Insert a basic block in a function using the global context.
2950 *
2951 * @see llvm::BasicBlock::Create()
2952 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002953LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2954 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002955
2956/**
2957 * Remove a basic block from a function and delete it.
2958 *
2959 * This deletes the basic block from its containing function and deletes
2960 * the basic block itself.
2961 *
2962 * @see llvm::BasicBlock::eraseFromParent()
2963 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002964void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002965
2966/**
2967 * Remove a basic block from a function.
2968 *
2969 * This deletes the basic block from its containing function but keep
2970 * the basic block alive.
2971 *
2972 * @see llvm::BasicBlock::removeFromParent()
2973 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002974void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002975
Gregory Szorc34c863a2012-03-21 03:54:29 +00002976/**
2977 * Move a basic block to before another one.
2978 *
2979 * @see llvm::BasicBlock::moveBefore()
2980 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002981void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002982
2983/**
2984 * Move a basic block to after another one.
2985 *
2986 * @see llvm::BasicBlock::moveAfter()
2987 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002988void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2989
Gregory Szorc34c863a2012-03-21 03:54:29 +00002990/**
2991 * Obtain the first instruction in a basic block.
2992 *
2993 * The returned LLVMValueRef corresponds to a llvm::Instruction
2994 * instance.
2995 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002996LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002997
2998/**
2999 * Obtain the last instruction in a basic block.
3000 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003001 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003002 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003003LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00003004
Gregory Szorc34c863a2012-03-21 03:54:29 +00003005/**
3006 * @}
3007 */
3008
3009/**
3010 * @defgroup LLVMCCoreValueInstruction Instructions
3011 *
3012 * Functions in this group relate to the inspection and manipulation of
3013 * individual instructions.
3014 *
3015 * In the C++ API, an instruction is modeled by llvm::Instruction. This
3016 * class has a large number of descendents. llvm::Instruction is a
3017 * llvm::Value and in the C API, instructions are modeled by
3018 * LLVMValueRef.
3019 *
3020 * This group also contains sub-groups which operate on specific
3021 * llvm::Instruction types, e.g. llvm::CallInst.
3022 *
3023 * @{
3024 */
3025
3026/**
3027 * Determine whether an instruction has any metadata attached.
3028 */
3029int LLVMHasMetadata(LLVMValueRef Val);
3030
3031/**
3032 * Return metadata associated with an instruction value.
3033 */
3034LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
3035
3036/**
3037 * Set metadata associated with an instruction value.
3038 */
3039void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
3040
3041/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00003042 * Returns the metadata associated with an instruction value, but filters out
3043 * all the debug locations.
3044 *
3045 * @see llvm::Instruction::getAllMetadataOtherThanDebugLoc()
3046 */
3047LLVMValueMetadataEntry *
3048LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Instr,
3049 size_t *NumEntries);
3050
3051/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003052 * Obtain the basic block to which an instruction belongs.
3053 *
3054 * @see llvm::Instruction::getParent()
3055 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003056LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003057
3058/**
3059 * Obtain the instruction that occurs after the one specified.
3060 *
3061 * The next instruction will be from the same basic block.
3062 *
3063 * If this is the last instruction in a basic block, NULL will be
3064 * returned.
3065 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003066LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003067
3068/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00003069 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003070 *
3071 * If the instruction is the first instruction in a basic block, NULL
3072 * will be returned.
3073 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003074LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003075
3076/**
3077 * Remove and delete an instruction.
3078 *
3079 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00003080 * block but is kept alive.
3081 *
3082 * @see llvm::Instruction::removeFromParent()
3083 */
3084void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
3085
3086/**
3087 * Remove and delete an instruction.
3088 *
3089 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00003090 * block and then deleted.
3091 *
3092 * @see llvm::Instruction::eraseFromParent()
3093 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00003094void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003095
3096/**
3097 * Obtain the code opcode for an individual instruction.
3098 *
3099 * @see llvm::Instruction::getOpCode()
3100 */
Eric Christophera6b96002015-12-18 01:46:52 +00003101LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003102
3103/**
3104 * Obtain the predicate of an instruction.
3105 *
3106 * This is only valid for instructions that correspond to llvm::ICmpInst
3107 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
3108 *
3109 * @see llvm::ICmpInst::getPredicate()
3110 */
Torok Edwin60c40de2011-10-06 12:13:20 +00003111LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003112
Gregory Szorc34c863a2012-03-21 03:54:29 +00003113/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00003114 * Obtain the float predicate of an instruction.
3115 *
3116 * This is only valid for instructions that correspond to llvm::FCmpInst
3117 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
3118 *
3119 * @see llvm::FCmpInst::getPredicate()
3120 */
3121LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
3122
3123/**
Peter Zotovaff492c2014-10-17 01:02:34 +00003124 * Create a copy of 'this' instruction that is identical in all ways
3125 * except the following:
3126 * * The instruction has no parent
3127 * * The instruction has no name
3128 *
3129 * @see llvm::Instruction::clone()
3130 */
3131LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
3132
3133/**
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003134 * Determine whether an instruction is a terminator. This routine is named to
3135 * be compatible with historical functions that did this by querying the
3136 * underlying C++ type.
3137 *
3138 * @see llvm::Instruction::isTerminator()
3139 */
3140LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst);
3141
3142/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003143 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
3144 *
3145 * Functions in this group apply to instructions that refer to call
3146 * sites and invocations. These correspond to C++ types in the
3147 * llvm::CallInst class tree.
3148 *
3149 * @{
3150 */
3151
3152/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003153 * Obtain the argument count for a call instruction.
3154 *
Robert Widmann478fce92018-03-30 17:49:53 +00003155 * This expects an LLVMValueRef that corresponds to a llvm::CallInst,
3156 * llvm::InvokeInst, or llvm:FuncletPadInst.
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003157 *
3158 * @see llvm::CallInst::getNumArgOperands()
3159 * @see llvm::InvokeInst::getNumArgOperands()
Robert Widmann478fce92018-03-30 17:49:53 +00003160 * @see llvm::FuncletPadInst::getNumArgOperands()
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003161 */
3162unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
3163
3164/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003165 * Set the calling convention for a call instruction.
3166 *
3167 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3168 * llvm::InvokeInst.
3169 *
3170 * @see llvm::CallInst::setCallingConv()
3171 * @see llvm::InvokeInst::setCallingConv()
3172 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003173void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003174
3175/**
3176 * Obtain the calling convention for a call instruction.
3177 *
3178 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
3179 * usage.
3180 *
3181 * @see LLVMSetInstructionCallConv()
3182 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003183unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003184
Gregory Szorc34c863a2012-03-21 03:54:29 +00003185void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Amaury Sechet81243a72016-05-01 01:42:34 +00003186 unsigned Align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00003187
Amaury Secheta65a2372016-06-15 05:14:29 +00003188void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3189 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00003190unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx);
3191void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
3192 LLVMAttributeRef *Attrs);
Amaury Secheta65a2372016-06-15 05:14:29 +00003193LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
3194 LLVMAttributeIndex Idx,
3195 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003196LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
3197 LLVMAttributeIndex Idx,
3198 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003199void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3200 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003201void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3202 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003203
Gregory Szorc34c863a2012-03-21 03:54:29 +00003204/**
James Y Knightf9563902019-01-14 21:37:42 +00003205 * Obtain the function type called by this instruction.
3206 *
3207 * @see llvm::CallBase::getFunctionType()
3208 */
3209LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef C);
3210
3211/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003212 * Obtain the pointer to the function invoked by this instruction.
3213 *
3214 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3215 * llvm::InvokeInst.
3216 *
3217 * @see llvm::CallInst::getCalledValue()
3218 * @see llvm::InvokeInst::getCalledValue()
3219 */
3220LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
3221
3222/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003223 * Obtain whether a call instruction is a tail call.
3224 *
3225 * This only works on llvm::CallInst instructions.
3226 *
3227 * @see llvm::CallInst::isTailCall()
3228 */
Chris Lattner25963c62010-01-09 22:27:07 +00003229LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003230
3231/**
3232 * Set whether a call instruction is a tail call.
3233 *
3234 * This only works on llvm::CallInst instructions.
3235 *
3236 * @see llvm::CallInst::setTailCall()
3237 */
Chris Lattner25963c62010-01-09 22:27:07 +00003238void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00003239
Gregory Szorc34c863a2012-03-21 03:54:29 +00003240/**
Amaury Sechete39e8532016-02-18 20:38:32 +00003241 * Return the normal destination basic block.
3242 *
3243 * This only works on llvm::InvokeInst instructions.
3244 *
3245 * @see llvm::InvokeInst::getNormalDest()
3246 */
3247LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
3248
3249/**
3250 * Return the unwind destination basic block.
3251 *
Robert Widmann478fce92018-03-30 17:49:53 +00003252 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3253 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003254 *
3255 * @see llvm::InvokeInst::getUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003256 * @see llvm::CleanupReturnInst::getUnwindDest()
3257 * @see llvm::CatchSwitchInst::getUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003258 */
3259LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
3260
3261/**
3262 * Set the normal destination basic block.
3263 *
3264 * This only works on llvm::InvokeInst instructions.
3265 *
3266 * @see llvm::InvokeInst::setNormalDest()
3267 */
3268void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3269
3270/**
3271 * Set the unwind destination basic block.
3272 *
Robert Widmann478fce92018-03-30 17:49:53 +00003273 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3274 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003275 *
3276 * @see llvm::InvokeInst::setUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003277 * @see llvm::CleanupReturnInst::setUnwindDest()
3278 * @see llvm::CatchSwitchInst::setUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003279 */
3280void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3281
3282/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003283 * @}
3284 */
3285
3286/**
Peter Zotov2481c752014-10-28 19:46:56 +00003287 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
3288 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003289 * Functions in this group only apply to instructions for which
3290 * LLVMIsATerminatorInst returns true.
Peter Zotov2481c752014-10-28 19:46:56 +00003291 *
3292 * @{
3293 */
3294
3295/**
3296 * Return the number of successors that this terminator has.
3297 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003298 * @see llvm::Instruction::getNumSuccessors
Peter Zotov2481c752014-10-28 19:46:56 +00003299 */
3300unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
3301
3302/**
3303 * Return the specified successor.
3304 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003305 * @see llvm::Instruction::getSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003306 */
3307LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
3308
3309/**
3310 * Update the specified successor to point at the provided block.
3311 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003312 * @see llvm::Instruction::setSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003313 */
3314void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
3315
3316/**
3317 * Return if a branch is conditional.
3318 *
3319 * This only works on llvm::BranchInst instructions.
3320 *
3321 * @see llvm::BranchInst::isConditional
3322 */
3323LLVMBool LLVMIsConditional(LLVMValueRef Branch);
3324
3325/**
3326 * Return the condition of a branch instruction.
3327 *
3328 * This only works on llvm::BranchInst instructions.
3329 *
3330 * @see llvm::BranchInst::getCondition
3331 */
3332LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
3333
3334/**
3335 * Set the condition of a branch instruction.
3336 *
3337 * This only works on llvm::BranchInst instructions.
3338 *
3339 * @see llvm::BranchInst::setCondition
3340 */
3341void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
3342
3343/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003344 * Obtain the default destination basic block of a switch instruction.
3345 *
3346 * This only works on llvm::SwitchInst instructions.
3347 *
3348 * @see llvm::SwitchInst::getDefaultDest()
3349 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003350LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
3351
Gregory Szorc34c863a2012-03-21 03:54:29 +00003352/**
Peter Zotov2481c752014-10-28 19:46:56 +00003353 * @}
3354 */
3355
3356/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00003357 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
3358 *
3359 * Functions in this group only apply to instructions that map to
3360 * llvm::AllocaInst instances.
3361 *
3362 * @{
3363 */
3364
3365/**
3366 * Obtain the type that is being allocated by the alloca instruction.
3367 */
3368LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
3369
3370/**
3371 * @}
3372 */
3373
3374/**
Amaury Sechet053ac452016-02-17 22:51:03 +00003375 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
3376 *
3377 * Functions in this group only apply to instructions that map to
3378 * llvm::GetElementPtrInst instances.
3379 *
3380 * @{
3381 */
3382
3383/**
3384 * Check whether the given GEP instruction is inbounds.
3385 */
3386LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
3387
3388/**
3389 * Set the given GEP instruction to be inbounds or not.
3390 */
Amaury Sechet8a367d42016-05-01 02:23:14 +00003391void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
Amaury Sechet053ac452016-02-17 22:51:03 +00003392
3393/**
3394 * @}
3395 */
3396
3397/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003398 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
3399 *
3400 * Functions in this group only apply to instructions that map to
3401 * llvm::PHINode instances.
3402 *
3403 * @{
3404 */
3405
3406/**
3407 * Add an incoming value to the end of a PHI list.
3408 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003409void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
3410 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003411
3412/**
3413 * Obtain the number of incoming basic blocks to a PHI node.
3414 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003415unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003416
3417/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003418 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003419 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003420LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003421
3422/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003423 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003424 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003425LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003426
Gregory Szorc34c863a2012-03-21 03:54:29 +00003427/**
3428 * @}
3429 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003430
Gregory Szorc34c863a2012-03-21 03:54:29 +00003431/**
Amaury Sechetaad93532016-02-10 00:38:50 +00003432 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
3433 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
3434 *
3435 * Functions in this group only apply to instructions that map to
3436 * llvm::ExtractValue and llvm::InsertValue instances.
3437 *
3438 * @{
3439 */
3440
3441/**
3442 * Obtain the number of indices.
Amaury Sechet053ac452016-02-17 22:51:03 +00003443 * NB: This also works on GEP.
Amaury Sechetaad93532016-02-10 00:38:50 +00003444 */
3445unsigned LLVMGetNumIndices(LLVMValueRef Inst);
3446
3447/**
3448 * Obtain the indices as an array.
3449 */
3450const unsigned *LLVMGetIndices(LLVMValueRef Inst);
3451
3452/**
3453 * @}
3454 */
3455
3456/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003457 * @}
3458 */
3459
3460/**
3461 * @}
3462 */
3463
3464/**
3465 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
3466 *
3467 * An instruction builder represents a point within a basic block and is
3468 * the exclusive means of building instructions using the C interface.
3469 *
3470 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003471 */
3472
Erick Tryzelaar262332f2009-08-14 00:01:31 +00003473LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003474LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00003475void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
3476 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003477void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
3478void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003479LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00003480void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
3481void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00003482void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
3483 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003484void LLVMDisposeBuilder(LLVMBuilderRef Builder);
3485
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00003486/* Metadata */
3487void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
3488LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
3489void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
3490
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003491/* Terminators */
3492LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
3493LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00003494LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003495 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003496LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
3497LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
3498 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
3499LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
3500 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003501LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
3502 unsigned NumDests);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003503// LLVMBuildInvoke is deprecated in favor of LLVMBuildInvoke2, in preparation
3504// for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003505LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
3506 LLVMValueRef *Args, unsigned NumArgs,
3507 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3508 const char *Name);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003509LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
3510 LLVMValueRef *Args, unsigned NumArgs,
3511 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3512 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003513LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
3514
3515/* Exception Handling */
3516LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00003517LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00003518 LLVMValueRef PersFn, unsigned NumClauses,
3519 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003520LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3521 LLVMBasicBlockRef BB);
3522LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3523 LLVMBasicBlockRef BB);
3524LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3525 LLVMValueRef *Args, unsigned NumArgs,
3526 const char *Name);
3527LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3528 LLVMValueRef *Args, unsigned NumArgs,
3529 const char *Name);
3530LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B, LLVMValueRef ParentPad,
3531 LLVMBasicBlockRef UnwindBB,
3532 unsigned NumHandlers, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003533
Gordon Henriksen097102c2008-01-01 05:50:53 +00003534/* Add a case to the switch instruction */
3535void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
3536 LLVMBasicBlockRef Dest);
3537
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003538/* Add a destination to the indirectbr instruction */
3539void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
3540
Amaury Sechete39e8532016-02-18 20:38:32 +00003541/* Get the number of clauses on the landingpad instruction */
3542unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
3543
3544/* Get the value of the clause at idnex Idx on the landingpad instruction */
3545LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
3546
Bill Wendlingfae14752011-08-12 20:24:12 +00003547/* Add a catch or filter clause to the landingpad instruction */
3548void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
3549
Amaury Sechete39e8532016-02-18 20:38:32 +00003550/* Get the 'cleanup' flag in the landingpad instruction */
3551LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
3552
Bill Wendlingfae14752011-08-12 20:24:12 +00003553/* Set the 'cleanup' flag in the landingpad instruction */
3554void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
3555
Robert Widmann478fce92018-03-30 17:49:53 +00003556/* Add a destination to the catchswitch instruction */
3557void LLVMAddHandler(LLVMValueRef CatchSwitch, LLVMBasicBlockRef Dest);
3558
3559/* Get the number of handlers on the catchswitch instruction */
3560unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch);
3561
3562/**
3563 * Obtain the basic blocks acting as handlers for a catchswitch instruction.
3564 *
3565 * The Handlers parameter should point to a pre-allocated array of
3566 * LLVMBasicBlockRefs at least LLVMGetNumHandlers() large. On return, the
3567 * first LLVMGetNumHandlers() entries in the array will be populated
3568 * with LLVMBasicBlockRef instances.
3569 *
3570 * @param CatchSwitch The catchswitch instruction to operate on.
3571 * @param Handlers Memory address of an array to be filled with basic blocks.
3572 */
3573void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers);
3574
3575/* Funclets */
3576
3577/* Get the number of funcletpad arguments. */
3578LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i);
3579
3580/* Set a funcletpad argument at the given index. */
3581void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value);
3582
3583/**
3584 * Get the parent catchswitch instruction of a catchpad instruction.
3585 *
3586 * This only works on llvm::CatchPadInst instructions.
3587 *
3588 * @see llvm::CatchPadInst::getCatchSwitch()
3589 */
3590LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad);
3591
3592/**
3593 * Set the parent catchswitch instruction of a catchpad instruction.
3594 *
3595 * This only works on llvm::CatchPadInst instructions.
3596 *
3597 * @see llvm::CatchPadInst::setCatchSwitch()
3598 */
3599void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad, LLVMValueRef CatchSwitch);
3600
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003601/* Arithmetic */
3602LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3603 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003604LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3605 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003606LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3607 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003608LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3609 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003610LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3611 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003612LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3613 const char *Name);
3614LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3615 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003616LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3617 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003618LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3619 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003620LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3621 const char *Name);
3622LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3623 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003624LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3625 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003626LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3627 const char *Name);
Manuel Jacob49fafb12016-10-04 23:32:42 +00003628LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3629 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003630LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3631 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003632LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3633 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003634LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3635 const char *Name);
3636LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3637 const char *Name);
3638LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3639 const char *Name);
3640LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3641 const char *Name);
3642LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3643 const char *Name);
3644LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3645 const char *Name);
3646LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3647 const char *Name);
3648LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3649 const char *Name);
3650LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3651 const char *Name);
3652LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3653 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003654LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
3655 LLVMValueRef LHS, LLVMValueRef RHS,
3656 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003657LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003658LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
3659 const char *Name);
3660LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
3661 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00003662LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003663LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
3664
3665/* Memory */
3666LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3667LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
3668 LLVMValueRef Val, const char *Name);
Robert Widmann98640f82018-10-29 15:31:40 +00003669
3670/**
3671 * Creates and inserts a memset to the specified pointer and the
3672 * specified value.
3673 *
3674 * @see llvm::IRRBuilder::CreateMemSet()
3675 */
3676LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
3677 LLVMValueRef Val, LLVMValueRef Len,
3678 unsigned Align);
3679/**
3680 * Creates and inserts a memcpy between the specified pointers.
3681 *
3682 * @see llvm::IRRBuilder::CreateMemCpy()
3683 */
3684LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,
3685 LLVMValueRef Dst, unsigned DstAlign,
3686 LLVMValueRef Src, unsigned SrcAlign,
3687 LLVMValueRef Size);
3688/**
3689 * Creates and inserts a memmove between the specified pointers.
3690 *
3691 * @see llvm::IRRBuilder::CreateMemMove()
3692 */
3693LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B,
3694 LLVMValueRef Dst, unsigned DstAlign,
3695 LLVMValueRef Src, unsigned SrcAlign,
3696 LLVMValueRef Size);
3697
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003698LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3699LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
3700 LLVMValueRef Val, const char *Name);
3701LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003702// LLVMBuildLoad is deprecated in favor of LLVMBuildLoad2, in preparation for
3703// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003704LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
3705 const char *Name);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003706LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty,
3707 LLVMValueRef PointerVal, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003708LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
James Y Knight544fa422019-01-14 21:39:35 +00003709// LLVMBuildGEP, LLVMBuildInBoundsGEP, and LLVMBuildStructGEP are deprecated in
3710// favor of LLVMBuild*GEP2, in preparation for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003711LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3712 LLVMValueRef *Indices, unsigned NumIndices,
3713 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003714LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3715 LLVMValueRef *Indices, unsigned NumIndices,
3716 const char *Name);
3717LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3718 unsigned Idx, const char *Name);
James Y Knight544fa422019-01-14 21:39:35 +00003719LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3720 LLVMValueRef Pointer, LLVMValueRef *Indices,
3721 unsigned NumIndices, const char *Name);
3722LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3723 LLVMValueRef Pointer, LLVMValueRef *Indices,
3724 unsigned NumIndices, const char *Name);
3725LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3726 LLVMValueRef Pointer, unsigned Idx,
3727 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003728LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
3729 const char *Name);
3730LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
3731 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00003732LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
3733void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00003734LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
3735void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003736
3737/* Casts */
3738LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
3739 LLVMTypeRef DestTy, const char *Name);
3740LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
3741 LLVMTypeRef DestTy, const char *Name);
3742LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
3743 LLVMTypeRef DestTy, const char *Name);
3744LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
3745 LLVMTypeRef DestTy, const char *Name);
3746LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
3747 LLVMTypeRef DestTy, const char *Name);
3748LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
3749 LLVMTypeRef DestTy, const char *Name);
3750LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
3751 LLVMTypeRef DestTy, const char *Name);
3752LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
3753 LLVMTypeRef DestTy, const char *Name);
3754LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
3755 LLVMTypeRef DestTy, const char *Name);
3756LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
3757 LLVMTypeRef DestTy, const char *Name);
3758LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
3759 LLVMTypeRef DestTy, const char *Name);
3760LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
3761 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003762LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
3763 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003764LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3765 LLVMTypeRef DestTy, const char *Name);
3766LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3767 LLVMTypeRef DestTy, const char *Name);
3768LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3769 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003770LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
3771 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003772LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
3773 LLVMTypeRef DestTy, const char *Name);
Robert Widmann40dc48be2019-01-08 06:23:22 +00003774LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef, LLVMValueRef Val,
3775 LLVMTypeRef DestTy, LLVMBool IsSigned,
James Y Knight68729f92019-01-14 17:16:55 +00003776 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003777LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
3778 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003779
Robert Widmann40dc48be2019-01-08 06:23:22 +00003780/** Deprecated: This cast is always signed. Use LLVMBuildIntCast2 instead. */
3781LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
3782 LLVMTypeRef DestTy, const char *Name);
3783
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003784/* Comparisons */
3785LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
3786 LLVMValueRef LHS, LLVMValueRef RHS,
3787 const char *Name);
3788LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
3789 LLVMValueRef LHS, LLVMValueRef RHS,
3790 const char *Name);
3791
3792/* Miscellaneous instructions */
3793LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003794// LLVMBuildCall is deprecated in favor of LLVMBuildCall2, in preparation for
3795// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003796LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
3797 LLVMValueRef *Args, unsigned NumArgs,
3798 const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003799LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn,
3800 LLVMValueRef *Args, unsigned NumArgs,
3801 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003802LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
3803 LLVMValueRef Then, LLVMValueRef Else,
3804 const char *Name);
3805LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
3806 const char *Name);
3807LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
3808 LLVMValueRef Index, const char *Name);
3809LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
3810 LLVMValueRef EltVal, LLVMValueRef Index,
3811 const char *Name);
3812LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
3813 LLVMValueRef V2, LLVMValueRef Mask,
3814 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00003815LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
3816 unsigned Index, const char *Name);
3817LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
3818 LLVMValueRef EltVal, unsigned Index,
3819 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00003820
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003821LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
3822 const char *Name);
3823LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
3824 const char *Name);
3825LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
3826 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00003827LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
3828 LLVMBool singleThread, const char *Name);
3829LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00003830 LLVMValueRef PTR, LLVMValueRef Val,
3831 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00003832 LLVMBool singleThread);
Mehdi Amini43165d92016-03-19 21:28:28 +00003833LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
3834 LLVMValueRef Cmp, LLVMValueRef New,
3835 LLVMAtomicOrdering SuccessOrdering,
3836 LLVMAtomicOrdering FailureOrdering,
3837 LLVMBool SingleThread);
3838
3839LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
3840void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
3841
3842LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
3843void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
3844 LLVMAtomicOrdering Ordering);
3845LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
3846void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
3847 LLVMAtomicOrdering Ordering);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003848
Gregory Szorc34c863a2012-03-21 03:54:29 +00003849/**
3850 * @}
3851 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003852
Gregory Szorc34c863a2012-03-21 03:54:29 +00003853/**
3854 * @defgroup LLVMCCoreModuleProvider Module Providers
3855 *
3856 * @{
3857 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003858
Gregory Szorc34c863a2012-03-21 03:54:29 +00003859/**
3860 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003861 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003862 */
3863LLVMModuleProviderRef
3864LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
3865
Gregory Szorc34c863a2012-03-21 03:54:29 +00003866/**
3867 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003868 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003869void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003870
Gregory Szorc34c863a2012-03-21 03:54:29 +00003871/**
3872 * @}
3873 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003874
Gregory Szorc34c863a2012-03-21 03:54:29 +00003875/**
3876 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
3877 *
3878 * @{
3879 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003880
Chris Lattner25963c62010-01-09 22:27:07 +00003881LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
3882 LLVMMemoryBufferRef *OutMemBuf,
3883 char **OutMessage);
3884LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
3885 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00003886LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
3887 size_t InputDataLength,
3888 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00003889 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00003890LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
3891 size_t InputDataLength,
3892 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00003893const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00003894size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003895void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
3896
Gregory Szorc34c863a2012-03-21 03:54:29 +00003897/**
3898 * @}
3899 */
3900
3901/**
3902 * @defgroup LLVMCCorePassRegistry Pass Registry
3903 *
3904 * @{
3905 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003906
3907/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003908 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003909LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003910
Gregory Szorc34c863a2012-03-21 03:54:29 +00003911/**
3912 * @}
3913 */
3914
3915/**
3916 * @defgroup LLVMCCorePassManagers Pass Managers
3917 *
3918 * @{
3919 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003920
3921/** Constructs a new whole-module pass pipeline. This type of pipeline is
3922 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003923 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003924LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003925
3926/** Constructs a new function-by-function pass pipeline over the module
3927 provider. It does not take ownership of the module provider. This type of
3928 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003929 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00003930LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
3931
3932/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003933LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
3934
3935/** Initializes, executes on the provided module, and finalizes all of the
3936 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00003937 modified the module, 0 otherwise.
3938 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003939LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003940
3941/** Initializes all of the function passes scheduled in the function pass
3942 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003943 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00003944LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003945
3946/** Executes all of the function passes scheduled in the function pass manager
3947 on the provided function. Returns 1 if any of the passes modified the
3948 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003949 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003950LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003951
Hiroshi Inoue0909ca12018-01-26 08:15:29 +00003952/** Finalizes all of the function passes scheduled in the function pass
Gordon Henriksen878114b2008-03-16 04:20:44 +00003953 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003954 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00003955LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003956
3957/** Frees the memory of a pass pipeline. For function pipelines, does not free
3958 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003959 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003960void LLVMDisposePassManager(LLVMPassManagerRef PM);
3961
Gregory Szorc34c863a2012-03-21 03:54:29 +00003962/**
3963 * @}
3964 */
3965
3966/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00003967 * @defgroup LLVMCCoreThreading Threading
3968 *
3969 * Handle the structures needed to make LLVM safe for multithreading.
3970 *
3971 * @{
3972 */
3973
Chandler Carruth39cd2162014-06-27 15:13:01 +00003974/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3975 time define LLVM_ENABLE_THREADS. This function always returns
3976 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003977LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003978
Chandler Carruth39cd2162014-06-27 15:13:01 +00003979/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3980 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003981void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003982
3983/** Check whether LLVM is executing in thread-safe mode or not.
3984 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003985LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003986
3987/**
3988 * @}
3989 */
3990
3991/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003992 * @}
3993 */
3994
3995/**
3996 * @}
3997 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003998
Gordon Henriksen76a03742007-09-18 03:18:57 +00003999#ifdef __cplusplus
4000}
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00004001#endif
Gordon Henriksen7330acd2007-10-05 23:59:36 +00004002
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00004003#endif /* LLVM_C_CORE_H */