blob: 1991dd98a76bf8718f48319bf1069cc96f8d0851 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
Chandler Carruth2946cd72019-01-19 08:50:56 +00003|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4|* Exceptions. *|
5|* See https://llvm.org/LICENSE.txt for license information. *|
6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000013\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_C_CORE_H
16#define LLVM_C_CORE_H
17
Eric Christophera6b96002015-12-18 01:46:52 +000018#include "llvm-c/ErrorHandling.h"
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080019#include "llvm-c/ExternC.h"
Eric Christophera6b96002015-12-18 01:46:52 +000020#include "llvm-c/Types.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000021
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -080022LLVM_C_EXTERN_C_BEGIN
Gordon Henriksen76a03742007-09-18 03:18:57 +000023
Gregory Szorc34c863a2012-03-21 03:54:29 +000024/**
25 * @defgroup LLVMC LLVM-C: C interface to LLVM
26 *
27 * This module exposes parts of the LLVM library as a C API.
28 *
29 * @{
30 */
31
32/**
33 * @defgroup LLVMCTransforms Transforms
34 */
35
36/**
37 * @defgroup LLVMCCore Core
38 *
39 * This modules provide an interface to libLLVMCore, which implements
40 * the LLVM intermediate representation as well as other related types
41 * and utilities.
42 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000043 * Many exotic languages can interoperate with C code but have a harder time
44 * with C++ due to name mangling. So in addition to C, this interface enables
45 * tools written in such languages.
46 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000047 * @{
48 */
49
50/**
51 * @defgroup LLVMCCoreTypes Types and Enumerations
52 *
53 * @{
54 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000055
Cameron McInallycbde0d92018-11-13 18:15:47 +000056/// External users depend on the following values being stable. It is not safe
57/// to reorder them.
Gordon Henriksen76a03742007-09-18 03:18:57 +000058typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +000059 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +000060 LLVMRet = 1,
61 LLVMBr = 2,
62 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +000063 LLVMIndirectBr = 4,
64 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +000065 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +000066 LLVMUnreachable = 7,
Craig Topper784929d2019-02-08 20:48:56 +000067 LLVMCallBr = 67,
Bill Wendling07d6d762010-02-15 20:50:51 +000068
Cameron McInallycbde0d92018-11-13 18:15:47 +000069 /* Standard Unary Operators */
70 LLVMFNeg = 66,
71
Bill Wendlingda52cec2010-02-15 20:53:17 +000072 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000073 LLVMAdd = 8,
74 LLVMFAdd = 9,
75 LLVMSub = 10,
76 LLVMFSub = 11,
77 LLVMMul = 12,
78 LLVMFMul = 13,
79 LLVMUDiv = 14,
80 LLVMSDiv = 15,
81 LLVMFDiv = 16,
82 LLVMURem = 17,
83 LLVMSRem = 18,
84 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +000085
Bill Wendlingda52cec2010-02-15 20:53:17 +000086 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000087 LLVMShl = 20,
88 LLVMLShr = 21,
89 LLVMAShr = 22,
90 LLVMAnd = 23,
91 LLVMOr = 24,
92 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +000093
Bill Wendlingda52cec2010-02-15 20:53:17 +000094 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000095 LLVMAlloca = 26,
96 LLVMLoad = 27,
97 LLVMStore = 28,
98 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +000099
Bill Wendlingda52cec2010-02-15 20:53:17 +0000100 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000101 LLVMTrunc = 30,
102 LLVMZExt = 31,
103 LLVMSExt = 32,
104 LLVMFPToUI = 33,
105 LLVMFPToSI = 34,
106 LLVMUIToFP = 35,
107 LLVMSIToFP = 36,
108 LLVMFPTrunc = 37,
109 LLVMFPExt = 38,
110 LLVMPtrToInt = 39,
111 LLVMIntToPtr = 40,
112 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000113 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000114
Bill Wendlingda52cec2010-02-15 20:53:17 +0000115 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000116 LLVMICmp = 42,
117 LLVMFCmp = 43,
118 LLVMPHI = 44,
119 LLVMCall = 45,
120 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000121 LLVMUserOp1 = 47,
122 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000123 LLVMVAArg = 49,
124 LLVMExtractElement = 50,
125 LLVMInsertElement = 51,
126 LLVMShuffleVector = 52,
127 LLVMExtractValue = 53,
128 LLVMInsertValue = 54,
aqjunee87d7162019-11-07 01:17:49 +0900129 LLVMFreeze = 68,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000130
131 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000132 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000133 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000134 LLVMAtomicRMW = 57,
135
136 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000137 LLVMResume = 58,
David Majnemer654e1302015-07-31 17:58:14 +0000138 LLVMLandingPad = 59,
139 LLVMCleanupRet = 61,
140 LLVMCatchRet = 62,
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +0000141 LLVMCatchPad = 63,
David Majnemerbbfc7212015-12-14 18:34:23 +0000142 LLVMCleanupPad = 64,
143 LLVMCatchSwitch = 65
Chris Lattner40cf28d2009-10-12 04:01:02 +0000144} LLVMOpcode;
145
146typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000147 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000148 LLVMHalfTypeKind, /**< 16 bit floating point type */
Ties Stuij8c24f332020-03-31 23:49:38 +0100149 LLVMBFloatTypeKind, /**< 16 bit brain floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000150 LLVMFloatTypeKind, /**< 32 bit floating point type */
151 LLVMDoubleTypeKind, /**< 64 bit floating point type */
152 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
153 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
154 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
155 LLVMLabelTypeKind, /**< Labels */
156 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
157 LLVMFunctionTypeKind, /**< Functions */
158 LLVMStructTypeKind, /**< Structures */
159 LLVMArrayTypeKind, /**< Arrays */
160 LLVMPointerTypeKind, /**< Pointers */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000161 LLVMMetadataTypeKind, /**< Metadata */
David Majnemerb611e3f2015-08-14 05:09:07 +0000162 LLVMX86_MMXTypeKind, /**< X86 MMX */
Christopher Tetreault2dea3f12020-04-22 08:02:02 -0700163 LLVMTokenTypeKind, /**< Tokens */
164 LLVMFixedVectorTypeKind, /**< Fixed width SIMD vector type */
165 LLVMScalableVectorTypeKind /**< Scalable SIMD vector type */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000166} LLVMTypeKind;
167
168typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000169 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000170 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000171 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
172 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
173 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000174 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000175 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
176 LLVMWeakODRLinkage, /**< Same, but only replaced by something
177 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000178 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
179 LLVMInternalLinkage, /**< Rename collisions when linking (static
180 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000181 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000182 LLVMDLLImportLinkage, /**< Obsolete */
183 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000184 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000185 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000186 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000187 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000188 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000189} LLVMLinkage;
190
191typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000192 LLVMDefaultVisibility, /**< The GV is visible */
193 LLVMHiddenVisibility, /**< The GV is hidden */
194 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000195} LLVMVisibility;
196
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000197typedef enum {
Robert Widmann4bb481b2018-03-14 06:45:51 +0000198 LLVMNoUnnamedAddr, /**< Address of the GV is significant. */
199 LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */
200 LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */
201} LLVMUnnamedAddr;
202
203typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000204 LLVMDefaultStorageClass = 0,
205 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
206 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
207} LLVMDLLStorageClass;
208
209typedef enum {
Robert Widmann1e989de2018-04-06 04:02:39 +0000210 LLVMCCallConv = 0,
211 LLVMFastCallConv = 8,
212 LLVMColdCallConv = 9,
213 LLVMGHCCallConv = 10,
214 LLVMHiPECallConv = 11,
215 LLVMWebKitJSCallConv = 12,
216 LLVMAnyRegCallConv = 13,
217 LLVMPreserveMostCallConv = 14,
218 LLVMPreserveAllCallConv = 15,
219 LLVMSwiftCallConv = 16,
220 LLVMCXXFASTTLSCallConv = 17,
221 LLVMX86StdcallCallConv = 64,
222 LLVMX86FastcallCallConv = 65,
223 LLVMARMAPCSCallConv = 66,
224 LLVMARMAAPCSCallConv = 67,
225 LLVMARMAAPCSVFPCallConv = 68,
226 LLVMMSP430INTRCallConv = 69,
227 LLVMX86ThisCallCallConv = 70,
228 LLVMPTXKernelCallConv = 71,
229 LLVMPTXDeviceCallConv = 72,
230 LLVMSPIRFUNCCallConv = 75,
231 LLVMSPIRKERNELCallConv = 76,
232 LLVMIntelOCLBICallConv = 77,
233 LLVMX8664SysVCallConv = 78,
234 LLVMWin64CallConv = 79,
235 LLVMX86VectorCallCallConv = 80,
236 LLVMHHVMCallConv = 81,
237 LLVMHHVMCCallConv = 82,
238 LLVMX86INTRCallConv = 83,
239 LLVMAVRINTRCallConv = 84,
240 LLVMAVRSIGNALCallConv = 85,
241 LLVMAVRBUILTINCallConv = 86,
242 LLVMAMDGPUVSCallConv = 87,
243 LLVMAMDGPUGSCallConv = 88,
244 LLVMAMDGPUPSCallConv = 89,
245 LLVMAMDGPUCSCallConv = 90,
246 LLVMAMDGPUKERNELCallConv = 91,
247 LLVMX86RegCallCallConv = 92,
248 LLVMAMDGPUHSCallConv = 93,
249 LLVMMSP430BUILTINCallConv = 94,
250 LLVMAMDGPULSCallConv = 95,
251 LLVMAMDGPUESCallConv = 96
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000252} LLVMCallConv;
253
254typedef enum {
Peter Zotov3e4561c2016-04-06 22:21:29 +0000255 LLVMArgumentValueKind,
256 LLVMBasicBlockValueKind,
257 LLVMMemoryUseValueKind,
258 LLVMMemoryDefValueKind,
259 LLVMMemoryPhiValueKind,
260
261 LLVMFunctionValueKind,
262 LLVMGlobalAliasValueKind,
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000263 LLVMGlobalIFuncValueKind,
Peter Zotov3e4561c2016-04-06 22:21:29 +0000264 LLVMGlobalVariableValueKind,
265 LLVMBlockAddressValueKind,
266 LLVMConstantExprValueKind,
267 LLVMConstantArrayValueKind,
268 LLVMConstantStructValueKind,
269 LLVMConstantVectorValueKind,
270
271 LLVMUndefValueValueKind,
272 LLVMConstantAggregateZeroValueKind,
273 LLVMConstantDataArrayValueKind,
274 LLVMConstantDataVectorValueKind,
275 LLVMConstantIntValueKind,
276 LLVMConstantFPValueKind,
277 LLVMConstantPointerNullValueKind,
278 LLVMConstantTokenNoneValueKind,
279
280 LLVMMetadataAsValueValueKind,
281 LLVMInlineAsmValueKind,
282
283 LLVMInstructionValueKind,
284} LLVMValueKind;
285
286typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000287 LLVMIntEQ = 32, /**< equal */
288 LLVMIntNE, /**< not equal */
289 LLVMIntUGT, /**< unsigned greater than */
290 LLVMIntUGE, /**< unsigned greater or equal */
291 LLVMIntULT, /**< unsigned less than */
292 LLVMIntULE, /**< unsigned less or equal */
293 LLVMIntSGT, /**< signed greater than */
294 LLVMIntSGE, /**< signed greater or equal */
295 LLVMIntSLT, /**< signed less than */
296 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000297} LLVMIntPredicate;
298
299typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000300 LLVMRealPredicateFalse, /**< Always false (always folded) */
301 LLVMRealOEQ, /**< True if ordered and equal */
302 LLVMRealOGT, /**< True if ordered and greater than */
303 LLVMRealOGE, /**< True if ordered and greater than or equal */
304 LLVMRealOLT, /**< True if ordered and less than */
305 LLVMRealOLE, /**< True if ordered and less than or equal */
306 LLVMRealONE, /**< True if ordered and operands are unequal */
307 LLVMRealORD, /**< True if ordered (no nans) */
308 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
309 LLVMRealUEQ, /**< True if unordered or equal */
310 LLVMRealUGT, /**< True if unordered or greater than */
311 LLVMRealUGE, /**< True if unordered, greater than, or equal */
312 LLVMRealULT, /**< True if unordered or less than */
313 LLVMRealULE, /**< True if unordered, less than, or equal */
314 LLVMRealUNE, /**< True if unordered or not equal */
315 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000316} LLVMRealPredicate;
317
Bill Wendlingfae14752011-08-12 20:24:12 +0000318typedef enum {
319 LLVMLandingPadCatch, /**< A catch clause */
320 LLVMLandingPadFilter /**< A filter clause */
321} LLVMLandingPadClauseTy;
322
Hans Wennborg5ff71202013-04-16 08:58:59 +0000323typedef enum {
324 LLVMNotThreadLocal = 0,
325 LLVMGeneralDynamicTLSModel,
326 LLVMLocalDynamicTLSModel,
327 LLVMInitialExecTLSModel,
328 LLVMLocalExecTLSModel
329} LLVMThreadLocalMode;
330
Carlo Kokda0ac722013-04-23 13:45:37 +0000331typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000332 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
333 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
334 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000335 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
336 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000337 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000338 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
339 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000340 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000341 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
342 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000343 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000344 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
345 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000346 operations which both read and write
347 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000348 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
349 for loads and Release
350 semantics for stores.
351 Additionally, it guarantees
352 that a total ordering exists
353 between all
354 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000355 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000356} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000357
Carlo Kokda0ac722013-04-23 13:45:37 +0000358typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000359 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
360 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
361 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
362 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
363 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
364 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
365 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
366 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater 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 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000370 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000371 the old one */
372 LLVMAtomicRMWBinOpUMax, /**< 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 */
Nick Lewyckyf57e9682019-09-26 00:58:55 +0000375 LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the
376 original using an unsigned comparison and return
377 the old one */
378 LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the
379 old one */
380 LLVMAtomicRMWBinOpFSub /**< Subtract a floating point value and return the
381 old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000382} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000383
Tom Stellard1580dc72014-04-16 17:45:04 +0000384typedef enum {
385 LLVMDSError,
386 LLVMDSWarning,
387 LLVMDSRemark,
388 LLVMDSNote
389} LLVMDiagnosticSeverity;
390
Robert Widmannf108d572018-04-06 02:31:29 +0000391typedef enum {
392 LLVMInlineAsmDialectATT,
393 LLVMInlineAsmDialectIntel
394} LLVMInlineAsmDialect;
395
Robert Widmannbce367702018-05-14 08:09:00 +0000396typedef enum {
397 /**
398 * Emits an error if two values disagree, otherwise the resulting value is
399 * that of the operands.
400 *
401 * @see Module::ModFlagBehavior::Error
402 */
403 LLVMModuleFlagBehaviorError,
404 /**
405 * Emits a warning if two values disagree. The result value will be the
406 * operand for the flag from the first module being linked.
407 *
408 * @see Module::ModFlagBehavior::Warning
409 */
410 LLVMModuleFlagBehaviorWarning,
411 /**
412 * Adds a requirement that another module flag be present and have a
413 * specified value after linking is performed. The value must be a metadata
414 * pair, where the first element of the pair is the ID of the module flag
415 * to be restricted, and the second element of the pair is the value the
416 * module flag should be restricted to. This behavior can be used to
417 * restrict the allowable results (via triggering of an error) of linking
418 * IDs with the **Override** behavior.
419 *
420 * @see Module::ModFlagBehavior::Require
421 */
422 LLVMModuleFlagBehaviorRequire,
423 /**
424 * Uses the specified value, regardless of the behavior or value of the
425 * other module. If both modules specify **Override**, but the values
426 * differ, an error will be emitted.
427 *
428 * @see Module::ModFlagBehavior::Override
429 */
430 LLVMModuleFlagBehaviorOverride,
431 /**
432 * Appends the two values, which are required to be metadata nodes.
433 *
434 * @see Module::ModFlagBehavior::Append
435 */
436 LLVMModuleFlagBehaviorAppend,
437 /**
438 * Appends the two values, which are required to be metadata
439 * nodes. However, duplicate entries in the second list are dropped
440 * during the append operation.
441 *
442 * @see Module::ModFlagBehavior::AppendUnique
443 */
444 LLVMModuleFlagBehaviorAppendUnique,
445} LLVMModuleFlagBehavior;
446
Gregory Szorc34c863a2012-03-21 03:54:29 +0000447/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000448 * Attribute index are either LLVMAttributeReturnIndex,
449 * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
450 */
451enum {
452 LLVMAttributeReturnIndex = 0U,
453 // ISO C restricts enumerator values to range of 'int'
454 // (4294967295 is too large)
455 // LLVMAttributeFunctionIndex = ~0U,
456 LLVMAttributeFunctionIndex = -1,
457};
458
459typedef unsigned LLVMAttributeIndex;
460
461/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000462 * @}
463 */
464
Nick Lewycky0db26542011-05-15 07:20:34 +0000465void LLVMInitializeCore(LLVMPassRegistryRef R);
466
Duncan Sands1cba0a82013-02-17 16:35:51 +0000467/** Deallocate and destroy all ManagedStatic variables.
468 @see llvm::llvm_shutdown
469 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000470void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000471
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000472/*===-- Error handling ----------------------------------------------------===*/
473
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000474char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000475void LLVMDisposeMessage(char *Message);
476
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000477/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000478 * @defgroup LLVMCCoreContext Contexts
479 *
480 * Contexts are execution states for the core LLVM IR system.
481 *
482 * Most types are tied to a context instance. Multiple contexts can
483 * exist simultaneously. A single context is not thread safe. However,
484 * different contexts can execute on different threads simultaneously.
485 *
486 * @{
487 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000488
Tom Stellard1580dc72014-04-16 17:45:04 +0000489typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000490typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000491
Gregory Szorc34c863a2012-03-21 03:54:29 +0000492/**
493 * Create a new context.
494 *
495 * Every call to this function should be paired with a call to
496 * LLVMContextDispose() or the context will leak memory.
497 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000498LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000499
500/**
501 * Obtain the global context instance.
502 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000503LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000504
505/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000506 * Set the diagnostic handler for this context.
507 */
508void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
509 LLVMDiagnosticHandler Handler,
510 void *DiagnosticContext);
511
512/**
Jeroen Ketemaad659c32016-04-08 09:19:02 +0000513 * Get the diagnostic handler of this context.
514 */
515LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
516
517/**
518 * Get the diagnostic context of this context.
519 */
520void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
521
522/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000523 * Set the yield callback function for this context.
524 *
525 * @see LLVMContext::setYieldCallback()
526 */
527void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
528 void *OpaqueHandle);
529
530/**
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000531 * Retrieve whether the given context is set to discard all value names.
532 *
533 * @see LLVMContext::shouldDiscardValueNames()
534 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000535LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000536
537/**
538 * Set whether the given context discards all value names.
539 *
540 * If true, only the names of GlobalValue objects will be available in the IR.
541 * This can be used to save memory and runtime, especially in release mode.
542 *
543 * @see LLVMContext::setDiscardValueNames()
544 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000545void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000546
547/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000548 * Destroy a context instance.
549 *
550 * This should be called for every call to LLVMContextCreate() or memory
551 * will be leaked.
552 */
Owen Anderson6773d382009-07-01 16:58:40 +0000553void LLVMContextDispose(LLVMContextRef C);
554
Tom Stellard1580dc72014-04-16 17:45:04 +0000555/**
556 * Return a string representation of the DiagnosticInfo. Use
557 * LLVMDisposeMessage to free the string.
558 *
559 * @see DiagnosticInfo::print()
560 */
561char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
562
563/**
564 * Return an enum LLVMDiagnosticSeverity.
565 *
566 * @see DiagnosticInfo::getSeverity()
567 */
568LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
569
Amaury Sechet56f056c2016-04-04 22:00:25 +0000570unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000571 unsigned SLen);
Amaury Sechet56f056c2016-04-04 22:00:25 +0000572unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000573
Gregory Szorc34c863a2012-03-21 03:54:29 +0000574/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000575 * Return an unique id given the name of a enum attribute,
Amaury Sechet60b31452016-04-20 01:02:12 +0000576 * or 0 if no attribute by that name exists.
577 *
578 * See http://llvm.org/docs/LangRef.html#parameter-attributes
579 * and http://llvm.org/docs/LangRef.html#function-attributes
580 * for the list of available attributes.
581 *
582 * NB: Attribute names and/or id are subject to change without
583 * going through the C API deprecation cycle.
584 */
Amaury Sechet5db224e2016-06-12 06:17:24 +0000585unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
Amaury Sechet48b06652016-06-12 07:56:21 +0000586unsigned LLVMGetLastEnumAttributeKind(void);
Amaury Sechet5db224e2016-06-12 06:17:24 +0000587
588/**
589 * Create an enum attribute.
590 */
591LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
592 uint64_t Val);
593
594/**
595 * Get the unique id corresponding to the enum attribute
596 * passed as argument.
597 */
598unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
599
600/**
601 * Get the enum attribute's value. 0 is returned if none exists.
602 */
603uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
604
605/**
606 * Create a string attribute.
607 */
608LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
609 const char *K, unsigned KLength,
610 const char *V, unsigned VLength);
611
612/**
613 * Get the string attribute's kind.
614 */
615const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
616
617/**
618 * Get the string attribute's value.
619 */
620const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
621
622/**
623 * Check for the different types of attributes.
624 */
625LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
626LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
Amaury Sechet60b31452016-04-20 01:02:12 +0000627
628/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000629 * @}
630 */
631
Gregory Szorc52d26602012-03-21 07:28:27 +0000632/**
633 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000634 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000635 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000636 * module is effectively a translation unit or a collection of
637 * translation units merged together.
638 *
639 * @{
640 */
641
Gregory Szorc34c863a2012-03-21 03:54:29 +0000642/**
643 * Create a new, empty module in the global context.
644 *
645 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
646 * LLVMGetGlobalContext() as the context parameter.
647 *
648 * Every invocation should be paired with LLVMDisposeModule() or memory
649 * will be leaked.
650 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000651LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000652
653/**
654 * Create a new, empty module in a specific context.
655 *
656 * Every invocation should be paired with LLVMDisposeModule() or memory
657 * will be leaked.
658 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000659LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
660 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000661/**
662 * Return an exact copy of the specified module.
663 */
664LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000665
Gregory Szorc34c863a2012-03-21 03:54:29 +0000666/**
667 * Destroy a module instance.
668 *
669 * This must be called for every created module or memory will be
670 * leaked.
671 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000672void LLVMDisposeModule(LLVMModuleRef M);
673
Gregory Szorc34c863a2012-03-21 03:54:29 +0000674/**
Peter Zotov0a2fa0a2016-04-05 13:56:59 +0000675 * Obtain the identifier of a module.
676 *
677 * @param M Module to obtain identifier of
678 * @param Len Out parameter which holds the length of the returned string.
679 * @return The identifier of M.
680 * @see Module::getModuleIdentifier()
681 */
682const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
683
684/**
685 * Set the identifier of a module to a string Ident with length Len.
686 *
687 * @param M The module to set identifier
688 * @param Ident The string to set M's identifier to
689 * @param Len Length of Ident
690 * @see Module::setModuleIdentifier()
691 */
692void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
693
694/**
Robert Widmann490a5802018-01-30 21:34:29 +0000695 * Obtain the module's original source file name.
696 *
697 * @param M Module to obtain the name of
698 * @param Len Out parameter which holds the length of the returned string
699 * @return The original source file name of M
700 * @see Module::getSourceFileName()
701 */
702const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len);
703
704/**
705 * Set the original source file name of a module to a string Name with length
706 * Len.
707 *
708 * @param M The module to set the source file name of
709 * @param Name The string to set M's source file name to
710 * @param Len Length of Name
711 * @see Module::setSourceFileName()
712 */
713void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len);
714
715/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000716 * Obtain the data layout for a module.
717 *
Amaury Sechetf3549c42016-02-16 00:23:52 +0000718 * @see Module::getDataLayoutStr()
719 *
720 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
721 * but match the name of another method on the module. Prefer the use
722 * of LLVMGetDataLayoutStr, which is not ambiguous.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000723 */
Amaury Sechetf3549c42016-02-16 00:23:52 +0000724const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000725const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000726
727/**
728 * Set the data layout for a module.
729 *
730 * @see Module::setDataLayout()
731 */
Amaury Sechet6ada31c2016-02-15 23:40:06 +0000732void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000733
Gregory Szorc34c863a2012-03-21 03:54:29 +0000734/**
735 * Obtain the target triple for a module.
736 *
737 * @see Module::getTargetTriple()
738 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000739const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000740
741/**
742 * Set the target triple for a module.
743 *
744 * @see Module::setTargetTriple()
745 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000746void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
747
Gregory Szorc34c863a2012-03-21 03:54:29 +0000748/**
Robert Widmannbce367702018-05-14 08:09:00 +0000749 * Returns the module flags as an array of flag-key-value triples. The caller
750 * is responsible for freeing this array by calling
751 * \c LLVMDisposeModuleFlagsMetadata.
752 *
753 * @see Module::getModuleFlagsMetadata()
754 */
755LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(LLVMModuleRef M, size_t *Len);
756
757/**
758 * Destroys module flags metadata entries.
759 */
760void LLVMDisposeModuleFlagsMetadata(LLVMModuleFlagEntry *Entries);
761
762/**
763 * Returns the flag behavior for a module flag entry at a specific index.
764 *
765 * @see Module::ModuleFlagEntry::Behavior
766 */
767LLVMModuleFlagBehavior
768LLVMModuleFlagEntriesGetFlagBehavior(LLVMModuleFlagEntry *Entries,
769 unsigned Index);
770
771/**
772 * Returns the key for a module flag entry at a specific index.
773 *
774 * @see Module::ModuleFlagEntry::Key
775 */
776const char *LLVMModuleFlagEntriesGetKey(LLVMModuleFlagEntry *Entries,
777 unsigned Index, size_t *Len);
778
779/**
780 * Returns the metadata for a module flag entry at a specific index.
781 *
782 * @see Module::ModuleFlagEntry::Val
783 */
784LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries,
785 unsigned Index);
786
787/**
788 * Add a module-level flag to the module-level flags metadata if it doesn't
789 * already exist.
790 *
791 * @see Module::getModuleFlag()
792 */
793LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRef M,
794 const char *Key, size_t KeyLen);
795
796/**
797 * Add a module-level flag to the module-level flags metadata if it doesn't
798 * already exist.
799 *
800 * @see Module::addModuleFlag()
801 */
802void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior,
803 const char *Key, size_t KeyLen,
804 LLVMMetadataRef Val);
805
806/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000807 * Dump a representation of a module to stderr.
808 *
809 * @see Module::dump()
810 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000811void LLVMDumpModule(LLVMModuleRef M);
812
Gregory Szorc34c863a2012-03-21 03:54:29 +0000813/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000814 * Print a representation of a module to a file. The ErrorMessage needs to be
815 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
816 *
817 * @see Module::print()
818 */
819LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
820 char **ErrorMessage);
821
822/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000823 * Return a string representation of the module. Use
824 * LLVMDisposeMessage to free the string.
825 *
826 * @see Module::print()
827 */
828char *LLVMPrintModuleToString(LLVMModuleRef M);
829
830/**
Robert Widmannf108d572018-04-06 02:31:29 +0000831 * Get inline assembly for a module.
832 *
833 * @see Module::getModuleInlineAsm()
834 */
835const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len);
836
837/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000838 * Set inline assembly for a module.
839 *
840 * @see Module::setModuleInlineAsm()
841 */
Robert Widmannf108d572018-04-06 02:31:29 +0000842void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len);
843
844/**
845 * Append inline assembly to a module.
846 *
847 * @see Module::appendModuleInlineAsm()
848 */
849void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len);
850
851/**
852 * Create the specified uniqued inline asm string.
853 *
854 * @see InlineAsm::get()
855 */
856LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty,
857 char *AsmString, size_t AsmStringSize,
858 char *Constraints, size_t ConstraintsSize,
859 LLVMBool HasSideEffects, LLVMBool IsAlignStack,
860 LLVMInlineAsmDialect Dialect);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000861
Gregory Szorc34c863a2012-03-21 03:54:29 +0000862/**
863 * Obtain the context to which this module is associated.
864 *
865 * @see Module::getContext()
866 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000867LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
868
Gregory Szorc34c863a2012-03-21 03:54:29 +0000869/**
870 * Obtain a Type from a module by its registered name.
871 */
872LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000873
Gregory Szorc34c863a2012-03-21 03:54:29 +0000874/**
Robert Widmann0a35b762018-08-30 17:09:43 +0000875 * Obtain an iterator to the first NamedMDNode in a Module.
876 *
877 * @see llvm::Module::named_metadata_begin()
878 */
879LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M);
880
881/**
882 * Obtain an iterator to the last NamedMDNode in a Module.
883 *
884 * @see llvm::Module::named_metadata_end()
885 */
886LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M);
887
888/**
889 * Advance a NamedMDNode iterator to the next NamedMDNode.
890 *
891 * Returns NULL if the iterator was already at the end and there are no more
892 * named metadata nodes.
893 */
894LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
895
896/**
897 * Decrement a NamedMDNode iterator to the previous NamedMDNode.
898 *
899 * Returns NULL if the iterator was already at the beginning and there are
900 * no previous named metadata nodes.
901 */
902LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
903
904/**
905 * Retrieve a NamedMDNode with the given name, returning NULL if no such
906 * node exists.
907 *
908 * @see llvm::Module::getNamedMetadata()
909 */
910LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M,
911 const char *Name, size_t NameLen);
912
913/**
914 * Retrieve a NamedMDNode with the given name, creating a new node if no such
915 * node exists.
916 *
917 * @see llvm::Module::getOrInsertNamedMetadata()
918 */
919LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M,
920 const char *Name,
921 size_t NameLen);
922
923/**
924 * Retrieve the name of a NamedMDNode.
925 *
926 * @see llvm::NamedMDNode::getName()
927 */
928const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NamedMD,
929 size_t *NameLen);
930
931/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000932 * Obtain the number of operands for named metadata in a module.
933 *
934 * @see llvm::Module::getNamedMetadata()
935 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000936unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000937
938/**
939 * Obtain the named metadata operands for a module.
940 *
941 * The passed LLVMValueRef pointer should refer to an array of
942 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
943 * array will be populated with the LLVMValueRef instances. Each
944 * instance corresponds to a llvm::MDNode.
945 *
946 * @see llvm::Module::getNamedMetadata()
947 * @see llvm::MDNode::getOperand()
948 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000949void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
950 LLVMValueRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000951
952/**
953 * Add an operand to named metadata.
954 *
955 * @see llvm::Module::getNamedMetadata()
956 * @see llvm::MDNode::addOperand()
957 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000958void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
Gregory Szorc34c863a2012-03-21 03:54:29 +0000959 LLVMValueRef Val);
960
Gregory Szorc52d26602012-03-21 07:28:27 +0000961/**
Saleem Abdulrasool0d1cbcc2018-10-10 23:53:12 +0000962 * Return the directory of the debug location for this value, which must be
963 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
964 *
965 * @see llvm::Instruction::getDebugLoc()
966 * @see llvm::GlobalVariable::getDebugInfo()
967 * @see llvm::Function::getSubprogram()
968 */
969const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length);
970
971/**
972 * Return the filename of the debug location for this value, which must be
973 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
974 *
975 * @see llvm::Instruction::getDebugLoc()
976 * @see llvm::GlobalVariable::getDebugInfo()
977 * @see llvm::Function::getSubprogram()
978 */
979const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length);
980
981/**
982 * Return the line number of the debug location for this value, which must be
983 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
984 *
985 * @see llvm::Instruction::getDebugLoc()
986 * @see llvm::GlobalVariable::getDebugInfo()
987 * @see llvm::Function::getSubprogram()
988 */
989unsigned LLVMGetDebugLocLine(LLVMValueRef Val);
990
991/**
992 * Return the column number of the debug location for this value, which must be
993 * an llvm::Instruction.
994 *
995 * @see llvm::Instruction::getDebugLoc()
996 */
997unsigned LLVMGetDebugLocColumn(LLVMValueRef Val);
998
999/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001000 * Add a function to a module under a specified name.
1001 *
1002 * @see llvm::Function::Create()
1003 */
1004LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1005 LLVMTypeRef FunctionTy);
1006
1007/**
1008 * Obtain a Function value from a Module by its name.
1009 *
1010 * The returned value corresponds to a llvm::Function value.
1011 *
1012 * @see llvm::Module::getFunction()
1013 */
1014LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
1015
1016/**
1017 * Obtain an iterator to the first Function in a Module.
1018 *
1019 * @see llvm::Module::begin()
1020 */
1021LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
1022
1023/**
1024 * Obtain an iterator to the last Function in a Module.
1025 *
1026 * @see llvm::Module::end()
1027 */
1028LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
1029
1030/**
1031 * Advance a Function iterator to the next Function.
1032 *
1033 * Returns NULL if the iterator was already at the end and there are no more
1034 * functions.
1035 */
1036LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
1037
1038/**
1039 * Decrement a Function iterator to the previous Function.
1040 *
1041 * Returns NULL if the iterator was already at the beginning and there are
1042 * no previous functions.
1043 */
1044LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001045
Robert Widmannf108d572018-04-06 02:31:29 +00001046/** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */
1047void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
1048
Gregory Szorc34c863a2012-03-21 03:54:29 +00001049/**
1050 * @}
1051 */
1052
1053/**
1054 * @defgroup LLVMCCoreType Types
1055 *
1056 * Types represent the type of a value.
1057 *
1058 * Types are associated with a context instance. The context internally
1059 * deduplicates types so there is only 1 instance of a specific type
1060 * alive at a time. In other words, a unique type is shared among all
1061 * consumers within a context.
1062 *
1063 * A Type in the C API corresponds to llvm::Type.
1064 *
1065 * Types have the following hierarchy:
1066 *
Gordon Henriksen76a03742007-09-18 03:18:57 +00001067 * types:
1068 * integer type
1069 * real type
1070 * function type
1071 * sequence types:
1072 * array type
1073 * pointer type
1074 * vector type
1075 * void type
1076 * label type
1077 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +00001078 *
1079 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001080 */
1081
Gregory Szorc34c863a2012-03-21 03:54:29 +00001082/**
1083 * Obtain the enumerated type of a Type instance.
1084 *
1085 * @see llvm::Type:getTypeID()
1086 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001087LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001088
1089/**
1090 * Whether the type has a known size.
1091 *
1092 * Things that don't have a size are abstract types, labels, and void.a
1093 *
1094 * @see llvm::Type::isSized()
1095 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +00001096LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +00001097
Gregory Szorc34c863a2012-03-21 03:54:29 +00001098/**
1099 * Obtain the context to which this type instance is associated.
1100 *
1101 * @see llvm::Type::getContext()
1102 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001103LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
1104
Gregory Szorc34c863a2012-03-21 03:54:29 +00001105/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +00001106 * Dump a representation of a type to stderr.
1107 *
1108 * @see llvm::Type::dump()
1109 */
1110void LLVMDumpType(LLVMTypeRef Val);
1111
1112/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +00001113 * Return a string representation of the type. Use
1114 * LLVMDisposeMessage to free the string.
1115 *
1116 * @see llvm::Type::print()
1117 */
1118char *LLVMPrintTypeToString(LLVMTypeRef Val);
1119
1120/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001121 * @defgroup LLVMCCoreTypeInt Integer Types
1122 *
1123 * Functions in this section operate on integer types.
1124 *
1125 * @{
1126 */
1127
1128/**
1129 * Obtain an integer type from a context with specified bit width.
1130 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001131LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
1132LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
1133LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
1134LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
1135LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001136LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001137LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
1138
Gregory Szorc34c863a2012-03-21 03:54:29 +00001139/**
1140 * Obtain an integer type from the global context with a specified bit
1141 * width.
1142 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001143LLVMTypeRef LLVMInt1Type(void);
1144LLVMTypeRef LLVMInt8Type(void);
1145LLVMTypeRef LLVMInt16Type(void);
1146LLVMTypeRef LLVMInt32Type(void);
1147LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001148LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001149LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001150unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001151
Gregory Szorc34c863a2012-03-21 03:54:29 +00001152/**
1153 * @}
1154 */
1155
1156/**
1157 * @defgroup LLVMCCoreTypeFloat Floating Point Types
1158 *
1159 * @{
1160 */
1161
1162/**
1163 * Obtain a 16-bit floating point type from a context.
1164 */
Dan Gohman518cda42011-12-17 00:04:22 +00001165LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001166
1167/**
Ties Stuij8c24f332020-03-31 23:49:38 +01001168 * Obtain a 16-bit brain floating point type from a context.
1169 */
1170LLVMTypeRef LLVMBFloatTypeInContext(LLVMContextRef C);
1171
1172/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001173 * Obtain a 32-bit floating point type from a context.
1174 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001175LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001176
1177/**
1178 * Obtain a 64-bit floating point type from a context.
1179 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001180LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001181
1182/**
1183 * Obtain a 80-bit floating point type (X87) from a context.
1184 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001185LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001186
1187/**
1188 * Obtain a 128-bit floating point type (112-bit mantissa) from a
1189 * context.
1190 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001191LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001192
1193/**
1194 * Obtain a 128-bit floating point type (two 64-bits) from a context.
1195 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001196LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
1197
Gregory Szorc34c863a2012-03-21 03:54:29 +00001198/**
1199 * Obtain a floating point type from the global context.
1200 *
1201 * These map to the functions in this group of the same name.
1202 */
Dan Gohman518cda42011-12-17 00:04:22 +00001203LLVMTypeRef LLVMHalfType(void);
Ties Stuij8c24f332020-03-31 23:49:38 +01001204LLVMTypeRef LLVMBFloatType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001205LLVMTypeRef LLVMFloatType(void);
1206LLVMTypeRef LLVMDoubleType(void);
1207LLVMTypeRef LLVMX86FP80Type(void);
1208LLVMTypeRef LLVMFP128Type(void);
1209LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001210
Gregory Szorc34c863a2012-03-21 03:54:29 +00001211/**
1212 * @}
1213 */
1214
1215/**
1216 * @defgroup LLVMCCoreTypeFunction Function Types
1217 *
1218 * @{
1219 */
1220
1221/**
1222 * Obtain a function type consisting of a specified signature.
1223 *
1224 * The function is defined as a tuple of a return Type, a list of
1225 * parameter types, and whether the function is variadic.
1226 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001227LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
1228 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001229 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001230
1231/**
1232 * Returns whether a function type is variadic.
1233 */
Chris Lattner25963c62010-01-09 22:27:07 +00001234LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001235
1236/**
1237 * Obtain the Type this function Type returns.
1238 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001239LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001240
1241/**
1242 * Obtain the number of parameters this function accepts.
1243 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001244unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001245
1246/**
1247 * Obtain the types of a function's parameters.
1248 *
1249 * The Dest parameter should point to a pre-allocated array of
1250 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
1251 * first LLVMCountParamTypes() entries in the array will be populated
1252 * with LLVMTypeRef instances.
1253 *
1254 * @param FunctionTy The function type to operate on.
1255 * @param Dest Memory address of an array to be filled with result.
1256 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001257void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001258
Gregory Szorc34c863a2012-03-21 03:54:29 +00001259/**
1260 * @}
1261 */
1262
1263/**
1264 * @defgroup LLVMCCoreTypeStruct Structure Types
1265 *
1266 * These functions relate to LLVMTypeRef instances.
1267 *
1268 * @see llvm::StructType
1269 *
1270 * @{
1271 */
1272
1273/**
1274 * Create a new structure type in a context.
1275 *
1276 * A structure is specified by a list of inner elements/types and
1277 * whether these can be packed together.
1278 *
1279 * @see llvm::StructType::create()
1280 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001281LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +00001282 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001283
1284/**
1285 * Create a new structure type in the global context.
1286 *
1287 * @see llvm::StructType::create()
1288 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001289LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001290 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001291
1292/**
1293 * Create an empty structure in a context having a specified name.
1294 *
1295 * @see llvm::StructType::create()
1296 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001297LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001298
1299/**
1300 * Obtain the name of a structure.
1301 *
1302 * @see llvm::StructType::getName()
1303 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +00001304const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001305
1306/**
1307 * Set the contents of a structure type.
1308 *
1309 * @see llvm::StructType::setBody()
1310 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001311void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
1312 unsigned ElementCount, LLVMBool Packed);
1313
Gregory Szorc34c863a2012-03-21 03:54:29 +00001314/**
1315 * Get the number of elements defined inside the structure.
1316 *
1317 * @see llvm::StructType::getNumElements()
1318 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001319unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001320
1321/**
1322 * Get the elements within a structure.
1323 *
1324 * The function is passed the address of a pre-allocated array of
1325 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
1326 * invocation, this array will be populated with the structure's
1327 * elements. The objects in the destination array will have a lifetime
1328 * of the structure type itself, which is the lifetime of the context it
1329 * is contained in.
1330 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001331void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001332
1333/**
Peter Zotovc164a3f2015-06-04 09:09:53 +00001334 * Get the type of the element at a given index in the structure.
1335 *
1336 * @see llvm::StructType::getTypeAtIndex()
1337 */
1338LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
1339
1340/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001341 * Determine whether a structure is packed.
1342 *
1343 * @see llvm::StructType::isPacked()
1344 */
Chris Lattner25963c62010-01-09 22:27:07 +00001345LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001346
1347/**
1348 * Determine whether a structure is opaque.
1349 *
1350 * @see llvm::StructType::isOpaque()
1351 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001352LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1353
Gregory Szorc34c863a2012-03-21 03:54:29 +00001354/**
whitequarkb4861072018-09-18 01:47:37 +00001355 * Determine whether a structure is literal.
1356 *
1357 * @see llvm::StructType::isLiteral()
1358 */
1359LLVMBool LLVMIsLiteralStruct(LLVMTypeRef StructTy);
1360
1361/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001362 * @}
1363 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001364
Gregory Szorc34c863a2012-03-21 03:54:29 +00001365/**
1366 * @defgroup LLVMCCoreTypeSequential Sequential Types
1367 *
1368 * Sequential types represents "arrays" of types. This is a super class
1369 * for array, vector, and pointer types.
1370 *
1371 * @{
1372 */
1373
1374/**
1375 * Obtain the type of elements within a sequential type.
1376 *
1377 * This works on array, vector, and pointer types.
1378 *
1379 * @see llvm::SequentialType::getElementType()
1380 */
1381LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1382
1383/**
whitequarkf6059fd2017-06-05 11:49:52 +00001384 * Returns type's subtypes
1385 *
1386 * @see llvm::Type::subtypes()
1387 */
1388void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr);
1389
1390/**
1391 * Return the number of types in the derived type.
1392 *
1393 * @see llvm::Type::getNumContainedTypes()
1394 */
1395unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp);
1396
1397/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001398 * Create a fixed size array type that refers to a specific type.
1399 *
1400 * The created type will exist in the context that its element type
1401 * exists in.
1402 *
1403 * @see llvm::ArrayType::get()
1404 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001405LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001406
1407/**
1408 * Obtain the length of an array type.
1409 *
1410 * This only works on types that represent arrays.
1411 *
1412 * @see llvm::ArrayType::getNumElements()
1413 */
1414unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1415
1416/**
1417 * Create a pointer type that points to a defined type.
1418 *
1419 * The created type will exist in the context that its pointee type
1420 * exists in.
1421 *
1422 * @see llvm::PointerType::get()
1423 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001424LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001425
1426/**
1427 * Obtain the address space of a pointer type.
1428 *
1429 * This only works on types that represent pointers.
1430 *
1431 * @see llvm::PointerType::getAddressSpace()
1432 */
1433unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1434
1435/**
1436 * Create a vector type that contains a defined type and has a specific
1437 * number of elements.
1438 *
1439 * The created type will exist in the context thats its element type
1440 * exists in.
1441 *
1442 * @see llvm::VectorType::get()
1443 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001444LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001445
Gregory Szorc34c863a2012-03-21 03:54:29 +00001446/**
1447 * Obtain the number of elements in a vector type.
1448 *
1449 * This only works on types that represent vectors.
1450 *
1451 * @see llvm::VectorType::getNumElements()
1452 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001453unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1454
Gregory Szorc34c863a2012-03-21 03:54:29 +00001455/**
1456 * @}
1457 */
1458
1459/**
1460 * @defgroup LLVMCCoreTypeOther Other Types
1461 *
1462 * @{
1463 */
1464
1465/**
1466 * Create a void type in a context.
1467 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001468LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001469
1470/**
1471 * Create a label type in a context.
1472 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001473LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001474
1475/**
1476 * Create a X86 MMX type in a context.
1477 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001478LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001479
Gregory Szorc34c863a2012-03-21 03:54:29 +00001480/**
whitequark131f98f2017-10-27 11:51:40 +00001481 * Create a token type in a context.
1482 */
1483LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C);
1484
1485/**
1486 * Create a metadata type in a context.
1487 */
1488LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C);
1489
1490/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001491 * These are similar to the above functions except they operate on the
1492 * global context.
1493 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001494LLVMTypeRef LLVMVoidType(void);
1495LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001496LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001497
Gregory Szorc34c863a2012-03-21 03:54:29 +00001498/**
1499 * @}
1500 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001501
Gregory Szorc34c863a2012-03-21 03:54:29 +00001502/**
1503 * @}
1504 */
1505
1506/**
1507 * @defgroup LLVMCCoreValues Values
1508 *
1509 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001510 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001511 *
1512 * LLVMValueRef essentially represents llvm::Value. There is a rich
1513 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001514 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001515 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001516 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001517 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1518 * functions are defined by a macro, so it isn't obvious which are
1519 * available by looking at the Doxygen source code. Instead, look at the
1520 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1521 * of value names given. These value names also correspond to classes in
1522 * the llvm::Value hierarchy.
1523 *
1524 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001525 */
1526
Gordon Henriksen29e38942008-12-19 18:39:45 +00001527#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1528 macro(Argument) \
1529 macro(BasicBlock) \
1530 macro(InlineAsm) \
1531 macro(User) \
1532 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001533 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001534 macro(ConstantAggregateZero) \
1535 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001536 macro(ConstantDataSequential) \
1537 macro(ConstantDataArray) \
1538 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001539 macro(ConstantExpr) \
1540 macro(ConstantFP) \
1541 macro(ConstantInt) \
1542 macro(ConstantPointerNull) \
1543 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001544 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001545 macro(ConstantVector) \
1546 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001547 macro(GlobalAlias) \
whitequarkd299b2c2018-09-18 00:01:12 +00001548 macro(GlobalIFunc) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001549 macro(GlobalObject) \
1550 macro(Function) \
1551 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001552 macro(UndefValue) \
1553 macro(Instruction) \
Cameron McInally60786f92019-10-07 21:33:39 +00001554 macro(UnaryOperator) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001555 macro(BinaryOperator) \
1556 macro(CallInst) \
1557 macro(IntrinsicInst) \
1558 macro(DbgInfoIntrinsic) \
Hsiangkai Wangef72e482018-08-06 03:59:47 +00001559 macro(DbgVariableIntrinsic) \
1560 macro(DbgDeclareInst) \
1561 macro(DbgLabelInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001562 macro(MemIntrinsic) \
1563 macro(MemCpyInst) \
1564 macro(MemMoveInst) \
1565 macro(MemSetInst) \
1566 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001567 macro(FCmpInst) \
1568 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001569 macro(ExtractElementInst) \
1570 macro(GetElementPtrInst) \
1571 macro(InsertElementInst) \
1572 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001573 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001574 macro(PHINode) \
1575 macro(SelectInst) \
1576 macro(ShuffleVectorInst) \
1577 macro(StoreInst) \
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00001578 macro(BranchInst) \
1579 macro(IndirectBrInst) \
1580 macro(InvokeInst) \
1581 macro(ReturnInst) \
1582 macro(SwitchInst) \
1583 macro(UnreachableInst) \
1584 macro(ResumeInst) \
1585 macro(CleanupReturnInst) \
1586 macro(CatchReturnInst) \
Nick Lewyckyf57e9682019-09-26 00:58:55 +00001587 macro(CatchSwitchInst) \
1588 macro(CallBrInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001589 macro(FuncletPadInst) \
1590 macro(CatchPadInst) \
1591 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001592 macro(UnaryInstruction) \
1593 macro(AllocaInst) \
1594 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001595 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001596 macro(BitCastInst) \
1597 macro(FPExtInst) \
1598 macro(FPToSIInst) \
1599 macro(FPToUIInst) \
1600 macro(FPTruncInst) \
1601 macro(IntToPtrInst) \
1602 macro(PtrToIntInst) \
1603 macro(SExtInst) \
1604 macro(SIToFPInst) \
1605 macro(TruncInst) \
1606 macro(UIToFPInst) \
1607 macro(ZExtInst) \
1608 macro(ExtractValueInst) \
1609 macro(LoadInst) \
Nick Lewyckyf57e9682019-09-26 00:58:55 +00001610 macro(VAArgInst) \
aqjunee87d7162019-11-07 01:17:49 +09001611 macro(FreezeInst) \
Nick Lewyckyf57e9682019-09-26 00:58:55 +00001612 macro(AtomicCmpXchgInst) \
1613 macro(AtomicRMWInst) \
1614 macro(FenceInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001615
Gregory Szorc34c863a2012-03-21 03:54:29 +00001616/**
1617 * @defgroup LLVMCCoreValueGeneral General APIs
1618 *
1619 * Functions in this section work on all LLVMValueRef instances,
1620 * regardless of their sub-type. They correspond to functions available
1621 * on llvm::Value.
1622 *
1623 * @{
1624 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001625
Gregory Szorc34c863a2012-03-21 03:54:29 +00001626/**
1627 * Obtain the type of a value.
1628 *
1629 * @see llvm::Value::getType()
1630 */
1631LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1632
1633/**
Peter Zotov3e4561c2016-04-06 22:21:29 +00001634 * Obtain the enumerated type of a Value instance.
1635 *
1636 * @see llvm::Value::getValueID()
1637 */
1638LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
1639
1640/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001641 * Obtain the string name of a value.
1642 *
1643 * @see llvm::Value::getName()
1644 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001645const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001646
1647/**
1648 * Set the string name of a value.
1649 *
1650 * @see llvm::Value::setName()
1651 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001652void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001653
1654/**
1655 * Dump a representation of a value to stderr.
1656 *
1657 * @see llvm::Value::dump()
1658 */
1659void LLVMDumpValue(LLVMValueRef Val);
1660
1661/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001662 * Return a string representation of the value. Use
1663 * LLVMDisposeMessage to free the string.
1664 *
1665 * @see llvm::Value::print()
1666 */
1667char *LLVMPrintValueToString(LLVMValueRef Val);
1668
1669/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001670 * Replace all uses of a value with another one.
1671 *
1672 * @see llvm::Value::replaceAllUsesWith()
1673 */
1674void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1675
1676/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001677 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001678 */
1679LLVMBool LLVMIsConstant(LLVMValueRef Val);
1680
1681/**
1682 * Determine whether a value instance is undefined.
1683 */
1684LLVMBool LLVMIsUndef(LLVMValueRef Val);
1685
1686/**
1687 * Convert value instances between types.
1688 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001689 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001690 * series of functions allows you to cast an instance to a specific
1691 * type.
1692 *
1693 * If the cast is not valid for the specified type, NULL is returned.
1694 *
1695 * @see llvm::dyn_cast_or_null<>
1696 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001697#define LLVM_DECLARE_VALUE_CAST(name) \
1698 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1699LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1700
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001701LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1702LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1703
Robert Widmann025c78f2018-05-19 15:08:36 +00001704/** Deprecated: Use LLVMGetValueName2 instead. */
1705const char *LLVMGetValueName(LLVMValueRef Val);
1706/** Deprecated: Use LLVMSetValueName2 instead. */
1707void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1708
Gregory Szorc34c863a2012-03-21 03:54:29 +00001709/**
1710 * @}
1711 */
1712
1713/**
1714 * @defgroup LLVMCCoreValueUses Usage
1715 *
1716 * This module defines functions that allow you to inspect the uses of a
1717 * LLVMValueRef.
1718 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001719 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001720 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1721 * llvm::User and llvm::Value.
1722 *
1723 * @{
1724 */
1725
1726/**
1727 * Obtain the first use of a value.
1728 *
1729 * Uses are obtained in an iterator fashion. First, call this function
1730 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001731 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001732 * LLVMGetNextUse() returns NULL.
1733 *
1734 * @see llvm::Value::use_begin()
1735 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001736LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001737
1738/**
1739 * Obtain the next use of a value.
1740 *
1741 * This effectively advances the iterator. It returns NULL if you are on
1742 * the final use and no more are available.
1743 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001744LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001745
1746/**
1747 * Obtain the user value for a user.
1748 *
1749 * The returned value corresponds to a llvm::User type.
1750 *
1751 * @see llvm::Use::getUser()
1752 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001753LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001754
1755/**
1756 * Obtain the value this use corresponds to.
1757 *
1758 * @see llvm::Use::get().
1759 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001760LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001761
Gregory Szorc34c863a2012-03-21 03:54:29 +00001762/**
1763 * @}
1764 */
1765
1766/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001767 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001768 *
1769 * Function in this group pertain to LLVMValueRef instances that descent
1770 * from llvm::User. This includes constants, instructions, and
1771 * operators.
1772 *
1773 * @{
1774 */
1775
1776/**
1777 * Obtain an operand at a specific index in a llvm::User value.
1778 *
1779 * @see llvm::User::getOperand()
1780 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001781LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001782
1783/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001784 * Obtain the use of an operand at a specific index in a llvm::User value.
1785 *
1786 * @see llvm::User::getOperandUse()
1787 */
1788LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1789
1790/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001791 * Set an operand at a specific index in a llvm::User value.
1792 *
1793 * @see llvm::User::setOperand()
1794 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001795void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001796
1797/**
1798 * Obtain the number of operands in a llvm::User value.
1799 *
1800 * @see llvm::User::getNumOperands()
1801 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001802int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001803
Gregory Szorc34c863a2012-03-21 03:54:29 +00001804/**
1805 * @}
1806 */
1807
1808/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001809 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001810 *
1811 * This section contains APIs for interacting with LLVMValueRef that
1812 * correspond to llvm::Constant instances.
1813 *
1814 * These functions will work for any LLVMValueRef in the llvm::Constant
1815 * class hierarchy.
1816 *
1817 * @{
1818 */
1819
1820/**
1821 * Obtain a constant value referring to the null instance of a type.
1822 *
1823 * @see llvm::Constant::getNullValue()
1824 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001825LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001826
1827/**
1828 * Obtain a constant value referring to the instance of a type
1829 * consisting of all ones.
1830 *
1831 * This is only valid for integer types.
1832 *
1833 * @see llvm::Constant::getAllOnesValue()
1834 */
1835LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1836
1837/**
1838 * Obtain a constant value referring to an undefined value of a type.
1839 *
1840 * @see llvm::UndefValue::get()
1841 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001842LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001843
1844/**
1845 * Determine whether a value instance is null.
1846 *
1847 * @see llvm::Constant::isNullValue()
1848 */
Chris Lattner25963c62010-01-09 22:27:07 +00001849LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001850
1851/**
1852 * Obtain a constant that is a constant pointer pointing to NULL for a
1853 * specified type.
1854 */
Chris Lattner7f318242009-07-06 17:29:59 +00001855LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001856
Gregory Szorc34c863a2012-03-21 03:54:29 +00001857/**
1858 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1859 *
1860 * Functions in this group model LLVMValueRef instances that correspond
1861 * to constants referring to scalar types.
1862 *
1863 * For integer types, the LLVMTypeRef parameter should correspond to a
1864 * llvm::IntegerType instance and the returned LLVMValueRef will
1865 * correspond to a llvm::ConstantInt.
1866 *
1867 * For floating point types, the LLVMTypeRef returned corresponds to a
1868 * llvm::ConstantFP.
1869 *
1870 * @{
1871 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001872
Gregory Szorc34c863a2012-03-21 03:54:29 +00001873/**
1874 * Obtain a constant value for an integer type.
1875 *
1876 * The returned value corresponds to a llvm::ConstantInt.
1877 *
1878 * @see llvm::ConstantInt::get()
1879 *
1880 * @param IntTy Integer type to obtain value of.
1881 * @param N The value the returned instance should refer to.
1882 * @param SignExtend Whether to sign extend the produced value.
1883 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001884LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001885 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001886
1887/**
1888 * Obtain a constant value for an integer of arbitrary precision.
1889 *
1890 * @see llvm::ConstantInt::get()
1891 */
Chris Lattner4329e072010-11-23 02:47:22 +00001892LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1893 unsigned NumWords,
1894 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001895
1896/**
1897 * Obtain a constant value for an integer parsed from a string.
1898 *
1899 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1900 * string's length is available, it is preferred to call that function
1901 * instead.
1902 *
1903 * @see llvm::ConstantInt::get()
1904 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001905LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1906 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001907
1908/**
1909 * Obtain a constant value for an integer parsed from a string with
1910 * specified length.
1911 *
1912 * @see llvm::ConstantInt::get()
1913 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001914LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1915 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001916
1917/**
1918 * Obtain a constant value referring to a double floating point value.
1919 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001920LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001921
1922/**
1923 * Obtain a constant for a floating point value parsed from a string.
1924 *
1925 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1926 * should be used if the input string's length is known.
1927 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001928LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001929
1930/**
1931 * Obtain a constant for a floating point value parsed from a string.
1932 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001933LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1934 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001935
1936/**
1937 * Obtain the zero extended value for an integer constant value.
1938 *
1939 * @see llvm::ConstantInt::getZExtValue()
1940 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001941unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001942
1943/**
1944 * Obtain the sign extended value for an integer constant value.
1945 *
1946 * @see llvm::ConstantInt::getSExtValue()
1947 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001948long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001949
Gregory Szorc34c863a2012-03-21 03:54:29 +00001950/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001951 * Obtain the double value for an floating point constant value.
1952 * losesInfo indicates if some precision was lost in the conversion.
1953 *
1954 * @see llvm::ConstantFP::getDoubleValue
1955 */
1956double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1957
1958/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001959 * @}
1960 */
1961
1962/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001963 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1964 *
1965 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001966 *
1967 * @{
1968 */
1969
1970/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001971 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001972 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001973 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001974 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001975LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001976 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001977
1978/**
1979 * Create a ConstantDataSequential with string content in the global context.
1980 *
1981 * This is the same as LLVMConstStringInContext except it operates on the
1982 * global context.
1983 *
1984 * @see LLVMConstStringInContext()
1985 * @see llvm::ConstantDataArray::getString()
1986 */
1987LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1988 LLVMBool DontNullTerminate);
1989
1990/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001991 * Returns true if the specified constant is an array of i8.
1992 *
1993 * @see ConstantDataSequential::getAsString()
1994 */
1995LLVMBool LLVMIsConstantString(LLVMValueRef c);
1996
1997/**
1998 * Get the given constant data sequential as a string.
1999 *
2000 * @see ConstantDataSequential::getAsString()
2001 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002002const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
Peter Zotovf9aa8822014-08-03 23:54:16 +00002003
2004/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002005 * Create an anonymous ConstantStruct with the specified values.
2006 *
2007 * @see llvm::ConstantStruct::getAnon()
2008 */
2009LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002010 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00002011 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002012
Gregory Szorc52d26602012-03-21 07:28:27 +00002013/**
2014 * Create a ConstantStruct in the global Context.
2015 *
2016 * This is the same as LLVMConstStructInContext except it operates on the
2017 * global Context.
2018 *
2019 * @see LLVMConstStructInContext()
2020 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002021LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00002022 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00002023
2024/**
2025 * Create a ConstantArray from values.
2026 *
2027 * @see llvm::ConstantArray::get()
2028 */
2029LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
2030 LLVMValueRef *ConstantVals, unsigned Length);
2031
2032/**
2033 * Create a non-anonymous ConstantStruct from values.
2034 *
2035 * @see llvm::ConstantStruct::get()
2036 */
Rafael Espindola784ad242011-07-14 19:09:08 +00002037LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
2038 LLVMValueRef *ConstantVals,
2039 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00002040
2041/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00002042 * Get an element at specified index as a constant.
2043 *
2044 * @see ConstantDataSequential::getElementAsConstant()
2045 */
Amaury Sechet006ce632016-03-13 00:54:40 +00002046LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
Peter Zotovf9aa8822014-08-03 23:54:16 +00002047
2048/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002049 * Create a ConstantVector from values.
2050 *
2051 * @see llvm::ConstantVector::get()
2052 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002053LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002054
Gregory Szorc52d26602012-03-21 07:28:27 +00002055/**
2056 * @}
2057 */
2058
2059/**
2060 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
2061 *
2062 * Functions in this group correspond to APIs on llvm::ConstantExpr.
2063 *
2064 * @see llvm::ConstantExpr.
2065 *
2066 * @{
2067 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002068LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002069LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002070LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
2071LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002072LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
2073LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002074LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002075LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
2076LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002077LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002078LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002079LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002080LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002081LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2082LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002083LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002084LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002085LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2086LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002087LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002088LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Manuel Jacob49fafb12016-10-04 23:32:42 +00002089LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002090LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002091LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002092LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2093LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2094LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2095LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2096LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2097LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2098LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2099LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
2100 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2101LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
2102 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2103LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2104LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2105LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2106LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
2107 LLVMValueRef *ConstantIndices, unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002108LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2109 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002110LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
2111 LLVMValueRef *ConstantIndices,
2112 unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002113LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2114 LLVMValueRef *ConstantIndices,
2115 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002116LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2117LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2118LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2119LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2120LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2121LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2122LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2123LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2124LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2125LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2126LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2127LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002128LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002129LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
2130 LLVMTypeRef ToType);
2131LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
2132 LLVMTypeRef ToType);
2133LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
2134 LLVMTypeRef ToType);
2135LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
2136 LLVMTypeRef ToType);
2137LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00002138 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002139LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002140LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
2141 LLVMValueRef ConstantIfTrue,
2142 LLVMValueRef ConstantIfFalse);
2143LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
2144 LLVMValueRef IndexConstant);
2145LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
2146 LLVMValueRef ElementValueConstant,
2147 LLVMValueRef IndexConstant);
2148LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
2149 LLVMValueRef VectorBConstant,
2150 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00002151LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
2152 unsigned NumIdx);
2153LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
2154 LLVMValueRef ElementValueConstant,
2155 unsigned *IdxList, unsigned NumIdx);
Robert Widmannf108d572018-04-06 02:31:29 +00002156LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
2157
2158/** Deprecated: Use LLVMGetInlineAsm instead. */
Chris Lattner25963c62010-01-09 22:27:07 +00002159LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00002160 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00002161 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002162
Gregory Szorc52d26602012-03-21 07:28:27 +00002163/**
2164 * @}
2165 */
2166
2167/**
2168 * @defgroup LLVMCCoreValueConstantGlobals Global Values
2169 *
2170 * This group contains functions that operate on global values. Functions in
2171 * this group relate to functions in the llvm::GlobalValue class tree.
2172 *
2173 * @see llvm::GlobalValue
2174 *
2175 * @{
2176 */
2177
Gordon Henriksen265f7802008-03-19 01:11:35 +00002178LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00002179LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002180LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
2181void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
2182const char *LLVMGetSection(LLVMValueRef Global);
2183void LLVMSetSection(LLVMValueRef Global, const char *Section);
2184LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
2185void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00002186LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
2187void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002188LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
2189void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
2190
Robert Widmanne63a12c2018-09-28 20:54:29 +00002191/**
2192 * Returns the "value type" of a global value. This differs from the formal
2193 * type of a global value which is always a pointer type.
2194 *
2195 * @see llvm::GlobalValue::getValueType()
2196 */
2197LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
2198
Robert Widmann4bb481b2018-03-14 06:45:51 +00002199/** Deprecated: Use LLVMGetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002200LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002201/** Deprecated: Use LLVMSetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002202void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002203
2204/**
2205 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
2206 *
2207 * Functions in this group only apply to values with alignment, i.e.
2208 * global variables, load and store instructions.
2209 */
2210
2211/**
2212 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002213 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002214 * @see llvm::LoadInst::getAlignment()
2215 * @see llvm::StoreInst::getAlignment()
2216 * @see llvm::GlobalValue::getAlignment()
2217 */
2218unsigned LLVMGetAlignment(LLVMValueRef V);
2219
2220/**
2221 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002222 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002223 * @see llvm::LoadInst::setAlignment()
2224 * @see llvm::StoreInst::setAlignment()
2225 * @see llvm::GlobalValue::setAlignment()
2226 */
2227void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
2228
2229/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00002230 * Sets a metadata attachment, erasing the existing metadata attachment if
2231 * it already exists for the given kind.
2232 *
2233 * @see llvm::GlobalObject::setMetadata()
2234 */
2235void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind,
2236 LLVMMetadataRef MD);
2237
2238/**
2239 * Erases a metadata attachment of the given kind if it exists.
2240 *
2241 * @see llvm::GlobalObject::eraseMetadata()
2242 */
2243void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind);
2244
2245/**
2246 * Removes all metadata attachments from this value.
2247 *
2248 * @see llvm::GlobalObject::clearMetadata()
2249 */
2250void LLVMGlobalClearMetadata(LLVMValueRef Global);
2251
2252/**
2253 * Retrieves an array of metadata entries representing the metadata attached to
2254 * this value. The caller is responsible for freeing this array by calling
2255 * \c LLVMDisposeValueMetadataEntries.
2256 *
2257 * @see llvm::GlobalObject::getAllMetadata()
2258 */
2259LLVMValueMetadataEntry *LLVMGlobalCopyAllMetadata(LLVMValueRef Value,
2260 size_t *NumEntries);
2261
2262/**
2263 * Destroys value metadata entries.
2264 */
2265void LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries);
2266
2267/**
2268 * Returns the kind of a value metadata entry at a specific index.
2269 */
2270unsigned LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries,
2271 unsigned Index);
2272
2273/**
2274 * Returns the underlying metadata node of a value metadata entry at a
2275 * specific index.
2276 */
2277LLVMMetadataRef
2278LLVMValueMetadataEntriesGetMetadata(LLVMValueMetadataEntry *Entries,
2279 unsigned Index);
2280
2281/**
Amaury Sechet83550102016-02-14 08:58:49 +00002282 * @}
2283 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002284
Gregory Szorc52d26602012-03-21 07:28:27 +00002285/**
2286 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
2287 *
2288 * This group contains functions that operate on global variable values.
2289 *
2290 * @see llvm::GlobalVariable
2291 *
2292 * @{
2293 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002294LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00002295LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
2296 const char *Name,
2297 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00002298LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002299LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
2300LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
2301LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
2302LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002303void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002304LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
2305void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00002306LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
2307void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
2308LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
2309void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00002310LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
2311void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
2312LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
2313void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002314
Gregory Szorc52d26602012-03-21 07:28:27 +00002315/**
2316 * @}
2317 */
2318
2319/**
2320 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
2321 *
2322 * This group contains function that operate on global alias values.
2323 *
2324 * @see llvm::GlobalAlias
2325 *
2326 * @{
2327 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00002328LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
2329 const char *Name);
2330
Gregory Szorc34c863a2012-03-21 03:54:29 +00002331/**
Robert Widmann360d6e32018-05-20 23:49:08 +00002332 * Obtain a GlobalAlias value from a Module by its name.
2333 *
2334 * The returned value corresponds to a llvm::GlobalAlias value.
2335 *
2336 * @see llvm::Module::getNamedAlias()
2337 */
2338LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M,
2339 const char *Name, size_t NameLen);
2340
2341/**
2342 * Obtain an iterator to the first GlobalAlias in a Module.
2343 *
2344 * @see llvm::Module::alias_begin()
2345 */
2346LLVMValueRef LLVMGetFirstGlobalAlias(LLVMModuleRef M);
2347
2348/**
2349 * Obtain an iterator to the last GlobalAlias in a Module.
2350 *
2351 * @see llvm::Module::alias_end()
2352 */
2353LLVMValueRef LLVMGetLastGlobalAlias(LLVMModuleRef M);
2354
2355/**
2356 * Advance a GlobalAlias iterator to the next GlobalAlias.
2357 *
2358 * Returns NULL if the iterator was already at the end and there are no more
2359 * global aliases.
2360 */
2361LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA);
2362
2363/**
2364 * Decrement a GlobalAlias iterator to the previous GlobalAlias.
2365 *
2366 * Returns NULL if the iterator was already at the beginning and there are
2367 * no previous global aliases.
2368 */
2369LLVMValueRef LLVMGetPreviousGlobalAlias(LLVMValueRef GA);
2370
2371/**
2372 * Retrieve the target value of an alias.
2373 */
2374LLVMValueRef LLVMAliasGetAliasee(LLVMValueRef Alias);
2375
2376/**
2377 * Set the target value of an alias.
2378 */
2379void LLVMAliasSetAliasee(LLVMValueRef Alias, LLVMValueRef Aliasee);
2380
2381/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002382 * @}
2383 */
2384
2385/**
2386 * @defgroup LLVMCCoreValueFunction Function values
2387 *
2388 * Functions in this group operate on LLVMValueRef instances that
2389 * correspond to llvm::Function instances.
2390 *
2391 * @see llvm::Function
2392 *
2393 * @{
2394 */
2395
2396/**
2397 * Remove a function from its containing module and deletes it.
2398 *
2399 * @see llvm::Function::eraseFromParent()
2400 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002401void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002402
2403/**
Amaury Sechete39e8532016-02-18 20:38:32 +00002404 * Check whether the given function has a personality function.
2405 *
2406 * @see llvm::Function::hasPersonalityFn()
2407 */
2408LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
2409
2410/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00002411 * Obtain the personality function attached to the function.
2412 *
2413 * @see llvm::Function::getPersonalityFn()
2414 */
2415LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
2416
2417/**
2418 * Set the personality function attached to the function.
2419 *
2420 * @see llvm::Function::setPersonalityFn()
2421 */
2422void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
2423
2424/**
Robert Widmann9d94a682019-03-25 20:58:58 +00002425 * Obtain the intrinsic ID number which matches the given function name.
2426 *
2427 * @see llvm::Function::lookupIntrinsicID()
2428 */
2429unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen);
2430
2431/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002432 * Obtain the ID number from a function instance.
2433 *
2434 * @see llvm::Function::getIntrinsicID()
2435 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002436unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002437
2438/**
Robert Widmannd36f3b02018-11-06 01:38:14 +00002439 * Create or insert the declaration of an intrinsic. For overloaded intrinsics,
2440 * parameter types must be provided to uniquely identify an overload.
2441 *
2442 * @see llvm::Intrinsic::getDeclaration()
2443 */
2444LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
2445 unsigned ID,
2446 LLVMTypeRef *ParamTypes,
2447 size_t ParamCount);
2448
2449/**
2450 * Retrieves the type of an intrinsic. For overloaded intrinsics, parameter
2451 * types must be provided to uniquely identify an overload.
2452 *
2453 * @see llvm::Intrinsic::getType()
2454 */
2455LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID,
2456 LLVMTypeRef *ParamTypes, size_t ParamCount);
2457
2458/**
2459 * Retrieves the name of an intrinsic.
2460 *
2461 * @see llvm::Intrinsic::getName()
2462 */
2463const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength);
2464
2465/**
2466 * Copies the name of an overloaded intrinsic identified by a given list of
2467 * parameter types.
2468 *
2469 * Unlike LLVMIntrinsicGetName, the caller is responsible for freeing the
2470 * returned string.
2471 *
2472 * @see llvm::Intrinsic::getName()
2473 */
2474const char *LLVMIntrinsicCopyOverloadedName(unsigned ID,
2475 LLVMTypeRef *ParamTypes,
2476 size_t ParamCount,
2477 size_t *NameLength);
2478
2479/**
2480 * Obtain if the intrinsic identified by the given ID is overloaded.
2481 *
2482 * @see llvm::Intrinsic::isOverloaded()
2483 */
2484LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID);
2485
2486/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002487 * Obtain the calling function of a function.
2488 *
2489 * The returned value corresponds to the LLVMCallConv enumeration.
2490 *
2491 * @see llvm::Function::getCallingConv()
2492 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002493unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002494
2495/**
2496 * Set the calling convention of a function.
2497 *
2498 * @see llvm::Function::setCallingConv()
2499 *
2500 * @param Fn Function to operate on
2501 * @param CC LLVMCallConv to set calling convention to
2502 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002503void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002504
2505/**
2506 * Obtain the name of the garbage collector to use during code
2507 * generation.
2508 *
2509 * @see llvm::Function::getGC()
2510 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002511const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002512
2513/**
2514 * Define the garbage collector to use during code generation.
2515 *
2516 * @see llvm::Function::setGC()
2517 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002518void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002519
2520/**
2521 * Add an attribute to a function.
2522 *
2523 * @see llvm::Function::addAttribute()
2524 */
Amaury Sechet5db224e2016-06-12 06:17:24 +00002525void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2526 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00002527unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx);
2528void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2529 LLVMAttributeRef *Attrs);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002530LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
2531 LLVMAttributeIndex Idx,
2532 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002533LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
2534 LLVMAttributeIndex Idx,
2535 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002536void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2537 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002538void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2539 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002540
Gregory Szorc34c863a2012-03-21 03:54:29 +00002541/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00002542 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00002543 * @see llvm::AttrBuilder::addAttribute()
2544 */
2545void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
2546 const char *V);
2547
2548/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002549 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
2550 *
2551 * Functions in this group relate to arguments/parameters on functions.
2552 *
2553 * Functions in this group expect LLVMValueRef instances that correspond
2554 * to llvm::Function instances.
2555 *
2556 * @{
2557 */
2558
2559/**
2560 * Obtain the number of parameters in a function.
2561 *
2562 * @see llvm::Function::arg_size()
2563 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002564unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002565
2566/**
2567 * Obtain the parameters in a function.
2568 *
2569 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
2570 * at least LLVMCountParams() long. This array will be filled with
2571 * LLVMValueRef instances which correspond to the parameters the
2572 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
2573 * instance.
2574 *
2575 * @see llvm::Function::arg_begin()
2576 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002577void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002578
2579/**
2580 * Obtain the parameter at the specified index.
2581 *
2582 * Parameters are indexed from 0.
2583 *
2584 * @see llvm::Function::arg_begin()
2585 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002586LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002587
2588/**
2589 * Obtain the function to which this argument belongs.
2590 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002591 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002592 * that corresponds to a llvm::Attribute.
2593 *
2594 * The returned LLVMValueRef is the llvm::Function to which this
2595 * argument belongs.
2596 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002597LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002598
2599/**
2600 * Obtain the first parameter to a function.
2601 *
2602 * @see llvm::Function::arg_begin()
2603 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002604LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002605
2606/**
2607 * Obtain the last parameter to a function.
2608 *
2609 * @see llvm::Function::arg_end()
2610 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002611LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002612
2613/**
2614 * Obtain the next parameter to a function.
2615 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002616 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002617 * actually a wrapped iterator) and obtains the next parameter from the
2618 * underlying iterator.
2619 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002620LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002621
2622/**
2623 * Obtain the previous parameter to a function.
2624 *
2625 * This is the opposite of LLVMGetNextParam().
2626 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002627LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002628
2629/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002630 * Set the alignment for a function parameter.
2631 *
2632 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002633 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002634 */
Amaury Sechet81243a72016-05-01 01:42:34 +00002635void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002636
Gregory Szorc34c863a2012-03-21 03:54:29 +00002637/**
2638 * @}
2639 */
2640
2641/**
Robert Widmannd5444cc2019-02-05 18:05:44 +00002642 * @defgroup LLVMCCoreValueGlobalIFunc IFuncs
2643 *
2644 * Functions in this group relate to indirect functions.
2645 *
2646 * Functions in this group expect LLVMValueRef instances that correspond
2647 * to llvm::GlobalIFunc instances.
2648 *
2649 * @{
2650 */
2651
2652/**
2653 * Add a global indirect function to a module under a specified name.
2654 *
2655 * @see llvm::GlobalIFunc::create()
2656 */
2657LLVMValueRef LLVMAddGlobalIFunc(LLVMModuleRef M,
2658 const char *Name, size_t NameLen,
2659 LLVMTypeRef Ty, unsigned AddrSpace,
2660 LLVMValueRef Resolver);
2661
2662/**
2663 * Obtain a GlobalIFunc value from a Module by its name.
2664 *
2665 * The returned value corresponds to a llvm::GlobalIFunc value.
2666 *
2667 * @see llvm::Module::getNamedIFunc()
2668 */
2669LLVMValueRef LLVMGetNamedGlobalIFunc(LLVMModuleRef M,
2670 const char *Name, size_t NameLen);
2671
2672/**
2673 * Obtain an iterator to the first GlobalIFunc in a Module.
2674 *
2675 * @see llvm::Module::ifunc_begin()
2676 */
2677LLVMValueRef LLVMGetFirstGlobalIFunc(LLVMModuleRef M);
2678
2679/**
2680 * Obtain an iterator to the last GlobalIFunc in a Module.
2681 *
2682 * @see llvm::Module::ifunc_end()
2683 */
2684LLVMValueRef LLVMGetLastGlobalIFunc(LLVMModuleRef M);
2685
2686/**
2687 * Advance a GlobalIFunc iterator to the next GlobalIFunc.
2688 *
2689 * Returns NULL if the iterator was already at the end and there are no more
2690 * global aliases.
2691 */
2692LLVMValueRef LLVMGetNextGlobalIFunc(LLVMValueRef IFunc);
2693
2694/**
2695 * Decrement a GlobalIFunc iterator to the previous GlobalIFunc.
2696 *
2697 * Returns NULL if the iterator was already at the beginning and there are
2698 * no previous global aliases.
2699 */
2700LLVMValueRef LLVMGetPreviousGlobalIFunc(LLVMValueRef IFunc);
Jim Lin466f8842020-02-18 10:48:38 +08002701
Robert Widmannd5444cc2019-02-05 18:05:44 +00002702/**
2703 * Retrieves the resolver function associated with this indirect function, or
2704 * NULL if it doesn't not exist.
2705 *
2706 * @see llvm::GlobalIFunc::getResolver()
2707 */
2708LLVMValueRef LLVMGetGlobalIFuncResolver(LLVMValueRef IFunc);
2709
2710/**
2711 * Sets the resolver function associated with this indirect function.
2712 *
2713 * @see llvm::GlobalIFunc::setResolver()
2714 */
2715void LLVMSetGlobalIFuncResolver(LLVMValueRef IFunc, LLVMValueRef Resolver);
2716
2717/**
2718 * Remove a global indirect function from its parent module and delete it.
2719 *
2720 * @see llvm::GlobalIFunc::eraseFromParent()
2721 */
2722void LLVMEraseGlobalIFunc(LLVMValueRef IFunc);
2723
2724/**
2725 * Remove a global indirect function from its parent module.
2726 *
2727 * This unlinks the global indirect function from its containing module but
2728 * keeps it alive.
2729 *
2730 * @see llvm::GlobalIFunc::removeFromParent()
2731 */
2732void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc);
2733
2734/**
2735 * @}
2736 */
2737
2738/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002739 * @}
2740 */
2741
2742/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002743 * @}
2744 */
2745
2746/**
2747 * @}
2748 */
2749
2750/**
2751 * @defgroup LLVMCCoreValueMetadata Metadata
2752 *
2753 * @{
2754 */
2755
2756/**
Robert Widmann09c5b882019-04-24 17:05:08 +00002757 * Create an MDString value from a given string value.
Gregory Szorc52d26602012-03-21 07:28:27 +00002758 *
Robert Widmann09c5b882019-04-24 17:05:08 +00002759 * The MDString value does not take ownership of the given string, it remains
2760 * the responsibility of the caller to free it.
Gregory Szorc52d26602012-03-21 07:28:27 +00002761 *
Robert Widmann09c5b882019-04-24 17:05:08 +00002762 * @see llvm::MDString::get()
Gregory Szorc52d26602012-03-21 07:28:27 +00002763 */
Robert Widmann09c5b882019-04-24 17:05:08 +00002764LLVMMetadataRef LLVMMDStringInContext2(LLVMContextRef C, const char *Str,
2765 size_t SLen);
Gregory Szorc52d26602012-03-21 07:28:27 +00002766
2767/**
Robert Widmann09c5b882019-04-24 17:05:08 +00002768 * Create an MDNode value with the given array of operands.
Gregory Szorc52d26602012-03-21 07:28:27 +00002769 *
Robert Widmann09c5b882019-04-24 17:05:08 +00002770 * @see llvm::MDNode::get()
Gregory Szorc52d26602012-03-21 07:28:27 +00002771 */
Robert Widmann09c5b882019-04-24 17:05:08 +00002772LLVMMetadataRef LLVMMDNodeInContext2(LLVMContextRef C, LLVMMetadataRef *MDs,
2773 size_t Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00002774
2775/**
Amaury Sechetf8429752017-04-17 11:52:54 +00002776 * Obtain a Metadata as a Value.
2777 */
2778LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
2779
2780/**
2781 * Obtain a Value as a Metadata.
2782 */
2783LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
2784
2785/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002786 * Obtain the underlying string from a MDString value.
2787 *
2788 * @param V Instance to obtain string from.
NAKAMURA Takumie4a77052016-04-04 11:54:48 +00002789 * @param Length Memory address which will hold length of returned string.
Gregory Szorc52d26602012-03-21 07:28:27 +00002790 * @return String data in MDString.
2791 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002792const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
Gregory Szorc52d26602012-03-21 07:28:27 +00002793
2794/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002795 * Obtain the number of operands from an MDNode value.
2796 *
2797 * @param V MDNode to get number of operands from.
2798 * @return Number of operands of the MDNode.
2799 */
2800unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2801
2802/**
2803 * Obtain the given MDNode's operands.
2804 *
2805 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2806 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2807 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2808 * MDNode's operands.
2809 *
2810 * @param V MDNode to get the operands from.
2811 * @param Dest Destination array for operands.
2812 */
2813void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2814
Robert Widmann09c5b882019-04-24 17:05:08 +00002815/** Deprecated: Use LLVMMDStringInContext2 instead. */
2816LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2817 unsigned SLen);
2818/** Deprecated: Use LLVMMDStringInContext2 instead. */
2819LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2820/** Deprecated: Use LLVMMDNodeInContext2 instead. */
2821LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2822 unsigned Count);
2823/** Deprecated: Use LLVMMDNodeInContext2 instead. */
2824LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2825
Duncan Sands12ccbe72012-09-19 20:29:39 +00002826/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002827 * @}
2828 */
2829
2830/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002831 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2832 *
2833 * A basic block represents a single entry single exit section of code.
2834 * Basic blocks contain a list of instructions which form the body of
2835 * the block.
2836 *
2837 * Basic blocks belong to functions. They have the type of label.
2838 *
2839 * Basic blocks are themselves values. However, the C API models them as
2840 * LLVMBasicBlockRef.
2841 *
2842 * @see llvm::BasicBlock
2843 *
2844 * @{
2845 */
2846
2847/**
2848 * Convert a basic block instance to a value type.
2849 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002850LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002851
2852/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002853 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002854 */
Chris Lattner25963c62010-01-09 22:27:07 +00002855LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002856
2857/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002858 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002859 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002860LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002861
2862/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002863 * Obtain the string name of a basic block.
2864 */
2865const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2866
2867/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002868 * Obtain the function to which a basic block belongs.
2869 *
2870 * @see llvm::BasicBlock::getParent()
2871 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002872LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002873
2874/**
2875 * Obtain the terminator instruction for a basic block.
2876 *
2877 * If the basic block does not have a terminator (it is not well-formed
2878 * if it doesn't), then NULL is returned.
2879 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00002880 * The returned LLVMValueRef corresponds to an llvm::Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002881 *
2882 * @see llvm::BasicBlock::getTerminator()
2883 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002884LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002885
2886/**
2887 * Obtain the number of basic blocks in a function.
2888 *
2889 * @param Fn Function value to operate on.
2890 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002891unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002892
2893/**
2894 * Obtain all of the basic blocks in a function.
2895 *
2896 * This operates on a function value. The BasicBlocks parameter is a
2897 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2898 * LLVMCountBasicBlocks() in length. This array is populated with
2899 * LLVMBasicBlockRef instances.
2900 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002901void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002902
2903/**
2904 * Obtain the first basic block in a function.
2905 *
2906 * The returned basic block can be used as an iterator. You will likely
2907 * eventually call into LLVMGetNextBasicBlock() with it.
2908 *
2909 * @see llvm::Function::begin()
2910 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002911LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002912
2913/**
2914 * Obtain the last basic block in a function.
2915 *
2916 * @see llvm::Function::end()
2917 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002918LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002919
2920/**
2921 * Advance a basic block iterator.
2922 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002923LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002924
2925/**
2926 * Go backwards in a basic block iterator.
2927 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002928LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002929
2930/**
2931 * Obtain the basic block that corresponds to the entry point of a
2932 * function.
2933 *
2934 * @see llvm::Function::getEntryBlock()
2935 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002936LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002937
Gregory Szorc34c863a2012-03-21 03:54:29 +00002938/**
Robert Widmannb4baa562019-04-05 20:32:43 +00002939 * Insert the given basic block after the insertion point of the given builder.
2940 *
2941 * The insertion point must be valid.
2942 *
2943 * @see llvm::Function::BasicBlockListType::insertAfter()
2944 */
2945void LLVMInsertExistingBasicBlockAfterInsertBlock(LLVMBuilderRef Builder,
2946 LLVMBasicBlockRef BB);
2947
2948/**
2949 * Append the given basic block to the basic block list of the given function.
2950 *
2951 * @see llvm::Function::BasicBlockListType::push_back()
2952 */
2953void LLVMAppendExistingBasicBlock(LLVMValueRef Fn,
2954 LLVMBasicBlockRef BB);
Jim Lin466f8842020-02-18 10:48:38 +08002955
Robert Widmannb4baa562019-04-05 20:32:43 +00002956/**
Robert Widmann616ed172019-01-08 06:24:19 +00002957 * Create a new basic block without inserting it into a function.
2958 *
2959 * @see llvm::BasicBlock::Create()
2960 */
2961LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C,
James Y Knight68729f92019-01-14 17:16:55 +00002962 const char *Name);
Robert Widmann616ed172019-01-08 06:24:19 +00002963
2964/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002965 * Append a basic block to the end of a function.
2966 *
2967 * @see llvm::BasicBlock::Create()
2968 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002969LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2970 LLVMValueRef Fn,
2971 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002972
2973/**
2974 * Append a basic block to the end of a function using the global
2975 * context.
2976 *
2977 * @see llvm::BasicBlock::Create()
2978 */
2979LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2980
2981/**
2982 * Insert a basic block in a function before another basic block.
2983 *
2984 * The function to add to is determined by the function of the
2985 * passed basic block.
2986 *
2987 * @see llvm::BasicBlock::Create()
2988 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002989LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2990 LLVMBasicBlockRef BB,
2991 const char *Name);
2992
Gregory Szorc34c863a2012-03-21 03:54:29 +00002993/**
2994 * Insert a basic block in a function using the global context.
2995 *
2996 * @see llvm::BasicBlock::Create()
2997 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002998LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2999 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003000
3001/**
3002 * Remove a basic block from a function and delete it.
3003 *
3004 * This deletes the basic block from its containing function and deletes
3005 * the basic block itself.
3006 *
3007 * @see llvm::BasicBlock::eraseFromParent()
3008 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003009void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003010
3011/**
3012 * Remove a basic block from a function.
3013 *
3014 * This deletes the basic block from its containing function but keep
3015 * the basic block alive.
3016 *
3017 * @see llvm::BasicBlock::removeFromParent()
3018 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003019void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003020
Gregory Szorc34c863a2012-03-21 03:54:29 +00003021/**
3022 * Move a basic block to before another one.
3023 *
3024 * @see llvm::BasicBlock::moveBefore()
3025 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00003026void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003027
3028/**
3029 * Move a basic block to after another one.
3030 *
3031 * @see llvm::BasicBlock::moveAfter()
3032 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00003033void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
3034
Gregory Szorc34c863a2012-03-21 03:54:29 +00003035/**
3036 * Obtain the first instruction in a basic block.
3037 *
3038 * The returned LLVMValueRef corresponds to a llvm::Instruction
3039 * instance.
3040 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003041LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003042
3043/**
3044 * Obtain the last instruction in a basic block.
3045 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003046 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003047 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003048LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00003049
Gregory Szorc34c863a2012-03-21 03:54:29 +00003050/**
3051 * @}
3052 */
3053
3054/**
3055 * @defgroup LLVMCCoreValueInstruction Instructions
3056 *
3057 * Functions in this group relate to the inspection and manipulation of
3058 * individual instructions.
3059 *
3060 * In the C++ API, an instruction is modeled by llvm::Instruction. This
3061 * class has a large number of descendents. llvm::Instruction is a
3062 * llvm::Value and in the C API, instructions are modeled by
3063 * LLVMValueRef.
3064 *
3065 * This group also contains sub-groups which operate on specific
3066 * llvm::Instruction types, e.g. llvm::CallInst.
3067 *
3068 * @{
3069 */
3070
3071/**
3072 * Determine whether an instruction has any metadata attached.
3073 */
3074int LLVMHasMetadata(LLVMValueRef Val);
3075
3076/**
3077 * Return metadata associated with an instruction value.
3078 */
3079LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
3080
3081/**
3082 * Set metadata associated with an instruction value.
3083 */
3084void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
3085
3086/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00003087 * Returns the metadata associated with an instruction value, but filters out
3088 * all the debug locations.
3089 *
3090 * @see llvm::Instruction::getAllMetadataOtherThanDebugLoc()
3091 */
3092LLVMValueMetadataEntry *
3093LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Instr,
3094 size_t *NumEntries);
3095
3096/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003097 * Obtain the basic block to which an instruction belongs.
3098 *
3099 * @see llvm::Instruction::getParent()
3100 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003101LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003102
3103/**
3104 * Obtain the instruction that occurs after the one specified.
3105 *
3106 * The next instruction will be from the same basic block.
3107 *
3108 * If this is the last instruction in a basic block, NULL will be
3109 * returned.
3110 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003111LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003112
3113/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00003114 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003115 *
3116 * If the instruction is the first instruction in a basic block, NULL
3117 * will be returned.
3118 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003119LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003120
3121/**
3122 * Remove and delete an instruction.
3123 *
3124 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00003125 * block but is kept alive.
3126 *
3127 * @see llvm::Instruction::removeFromParent()
3128 */
3129void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
3130
3131/**
3132 * Remove and delete an instruction.
3133 *
3134 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00003135 * block and then deleted.
3136 *
3137 * @see llvm::Instruction::eraseFromParent()
3138 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00003139void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003140
3141/**
3142 * Obtain the code opcode for an individual instruction.
3143 *
3144 * @see llvm::Instruction::getOpCode()
3145 */
Eric Christophera6b96002015-12-18 01:46:52 +00003146LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003147
3148/**
3149 * Obtain the predicate of an instruction.
3150 *
3151 * This is only valid for instructions that correspond to llvm::ICmpInst
3152 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
3153 *
3154 * @see llvm::ICmpInst::getPredicate()
3155 */
Torok Edwin60c40de2011-10-06 12:13:20 +00003156LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003157
Gregory Szorc34c863a2012-03-21 03:54:29 +00003158/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00003159 * Obtain the float predicate of an instruction.
3160 *
3161 * This is only valid for instructions that correspond to llvm::FCmpInst
3162 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
3163 *
3164 * @see llvm::FCmpInst::getPredicate()
3165 */
3166LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
3167
3168/**
Peter Zotovaff492c2014-10-17 01:02:34 +00003169 * Create a copy of 'this' instruction that is identical in all ways
3170 * except the following:
3171 * * The instruction has no parent
3172 * * The instruction has no name
3173 *
3174 * @see llvm::Instruction::clone()
3175 */
3176LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
3177
3178/**
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003179 * Determine whether an instruction is a terminator. This routine is named to
3180 * be compatible with historical functions that did this by querying the
3181 * underlying C++ type.
3182 *
3183 * @see llvm::Instruction::isTerminator()
3184 */
3185LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst);
3186
3187/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003188 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
3189 *
3190 * Functions in this group apply to instructions that refer to call
3191 * sites and invocations. These correspond to C++ types in the
3192 * llvm::CallInst class tree.
3193 *
3194 * @{
3195 */
3196
3197/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003198 * Obtain the argument count for a call instruction.
3199 *
Robert Widmann478fce92018-03-30 17:49:53 +00003200 * This expects an LLVMValueRef that corresponds to a llvm::CallInst,
3201 * llvm::InvokeInst, or llvm:FuncletPadInst.
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003202 *
3203 * @see llvm::CallInst::getNumArgOperands()
3204 * @see llvm::InvokeInst::getNumArgOperands()
Robert Widmann478fce92018-03-30 17:49:53 +00003205 * @see llvm::FuncletPadInst::getNumArgOperands()
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003206 */
3207unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
3208
3209/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003210 * Set the calling convention for a call instruction.
3211 *
3212 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3213 * llvm::InvokeInst.
3214 *
3215 * @see llvm::CallInst::setCallingConv()
3216 * @see llvm::InvokeInst::setCallingConv()
3217 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003218void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003219
3220/**
3221 * Obtain the calling convention for a call instruction.
3222 *
3223 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
3224 * usage.
3225 *
3226 * @see LLVMSetInstructionCallConv()
3227 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003228unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003229
Gregory Szorc34c863a2012-03-21 03:54:29 +00003230void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Amaury Sechet81243a72016-05-01 01:42:34 +00003231 unsigned Align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00003232
Amaury Secheta65a2372016-06-15 05:14:29 +00003233void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3234 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00003235unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx);
3236void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
3237 LLVMAttributeRef *Attrs);
Amaury Secheta65a2372016-06-15 05:14:29 +00003238LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
3239 LLVMAttributeIndex Idx,
3240 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003241LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
3242 LLVMAttributeIndex Idx,
3243 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003244void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3245 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003246void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3247 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003248
Gregory Szorc34c863a2012-03-21 03:54:29 +00003249/**
James Y Knightf9563902019-01-14 21:37:42 +00003250 * Obtain the function type called by this instruction.
3251 *
3252 * @see llvm::CallBase::getFunctionType()
3253 */
3254LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef C);
3255
3256/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003257 * Obtain the pointer to the function invoked by this instruction.
3258 *
3259 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3260 * llvm::InvokeInst.
3261 *
Craig Toppera58b62b2020-04-27 20:15:59 -07003262 * @see llvm::CallInst::getCalledOperand()
3263 * @see llvm::InvokeInst::getCalledOperand()
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003264 */
3265LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
3266
3267/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003268 * Obtain whether a call instruction is a tail call.
3269 *
3270 * This only works on llvm::CallInst instructions.
3271 *
3272 * @see llvm::CallInst::isTailCall()
3273 */
Chris Lattner25963c62010-01-09 22:27:07 +00003274LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003275
3276/**
3277 * Set whether a call instruction is a tail call.
3278 *
3279 * This only works on llvm::CallInst instructions.
3280 *
3281 * @see llvm::CallInst::setTailCall()
3282 */
Chris Lattner25963c62010-01-09 22:27:07 +00003283void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00003284
Gregory Szorc34c863a2012-03-21 03:54:29 +00003285/**
Amaury Sechete39e8532016-02-18 20:38:32 +00003286 * Return the normal destination basic block.
3287 *
3288 * This only works on llvm::InvokeInst instructions.
3289 *
3290 * @see llvm::InvokeInst::getNormalDest()
3291 */
3292LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
3293
3294/**
3295 * Return the unwind destination basic block.
3296 *
Robert Widmann478fce92018-03-30 17:49:53 +00003297 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3298 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003299 *
3300 * @see llvm::InvokeInst::getUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003301 * @see llvm::CleanupReturnInst::getUnwindDest()
3302 * @see llvm::CatchSwitchInst::getUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003303 */
3304LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
3305
3306/**
3307 * Set the normal destination basic block.
3308 *
3309 * This only works on llvm::InvokeInst instructions.
3310 *
3311 * @see llvm::InvokeInst::setNormalDest()
3312 */
3313void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3314
3315/**
3316 * Set the unwind destination basic block.
3317 *
Robert Widmann478fce92018-03-30 17:49:53 +00003318 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3319 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003320 *
3321 * @see llvm::InvokeInst::setUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003322 * @see llvm::CleanupReturnInst::setUnwindDest()
3323 * @see llvm::CatchSwitchInst::setUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003324 */
3325void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3326
3327/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003328 * @}
3329 */
3330
3331/**
Peter Zotov2481c752014-10-28 19:46:56 +00003332 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
3333 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003334 * Functions in this group only apply to instructions for which
3335 * LLVMIsATerminatorInst returns true.
Peter Zotov2481c752014-10-28 19:46:56 +00003336 *
3337 * @{
3338 */
3339
3340/**
3341 * Return the number of successors that this terminator has.
3342 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003343 * @see llvm::Instruction::getNumSuccessors
Peter Zotov2481c752014-10-28 19:46:56 +00003344 */
3345unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
3346
3347/**
3348 * Return the specified successor.
3349 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003350 * @see llvm::Instruction::getSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003351 */
3352LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
3353
3354/**
3355 * Update the specified successor to point at the provided block.
3356 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003357 * @see llvm::Instruction::setSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003358 */
3359void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
3360
3361/**
3362 * Return if a branch is conditional.
3363 *
3364 * This only works on llvm::BranchInst instructions.
3365 *
3366 * @see llvm::BranchInst::isConditional
3367 */
3368LLVMBool LLVMIsConditional(LLVMValueRef Branch);
3369
3370/**
3371 * Return the condition of a branch instruction.
3372 *
3373 * This only works on llvm::BranchInst instructions.
3374 *
3375 * @see llvm::BranchInst::getCondition
3376 */
3377LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
3378
3379/**
3380 * Set the condition of a branch instruction.
3381 *
3382 * This only works on llvm::BranchInst instructions.
3383 *
3384 * @see llvm::BranchInst::setCondition
3385 */
3386void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
3387
3388/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003389 * Obtain the default destination basic block of a switch instruction.
3390 *
3391 * This only works on llvm::SwitchInst instructions.
3392 *
3393 * @see llvm::SwitchInst::getDefaultDest()
3394 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003395LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
3396
Gregory Szorc34c863a2012-03-21 03:54:29 +00003397/**
Peter Zotov2481c752014-10-28 19:46:56 +00003398 * @}
3399 */
3400
3401/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00003402 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
3403 *
3404 * Functions in this group only apply to instructions that map to
3405 * llvm::AllocaInst instances.
3406 *
3407 * @{
3408 */
3409
3410/**
3411 * Obtain the type that is being allocated by the alloca instruction.
3412 */
3413LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
3414
3415/**
3416 * @}
3417 */
3418
3419/**
Amaury Sechet053ac452016-02-17 22:51:03 +00003420 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
3421 *
3422 * Functions in this group only apply to instructions that map to
3423 * llvm::GetElementPtrInst instances.
3424 *
3425 * @{
3426 */
3427
3428/**
3429 * Check whether the given GEP instruction is inbounds.
3430 */
3431LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
3432
3433/**
3434 * Set the given GEP instruction to be inbounds or not.
3435 */
Amaury Sechet8a367d42016-05-01 02:23:14 +00003436void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
Amaury Sechet053ac452016-02-17 22:51:03 +00003437
3438/**
3439 * @}
3440 */
3441
3442/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003443 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
3444 *
3445 * Functions in this group only apply to instructions that map to
3446 * llvm::PHINode instances.
3447 *
3448 * @{
3449 */
3450
3451/**
3452 * Add an incoming value to the end of a PHI list.
3453 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003454void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
3455 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003456
3457/**
3458 * Obtain the number of incoming basic blocks to a PHI node.
3459 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003460unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003461
3462/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003463 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003464 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003465LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003466
3467/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003468 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003469 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003470LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003471
Gregory Szorc34c863a2012-03-21 03:54:29 +00003472/**
3473 * @}
3474 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003475
Gregory Szorc34c863a2012-03-21 03:54:29 +00003476/**
Amaury Sechetaad93532016-02-10 00:38:50 +00003477 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
3478 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
3479 *
3480 * Functions in this group only apply to instructions that map to
3481 * llvm::ExtractValue and llvm::InsertValue instances.
3482 *
3483 * @{
3484 */
3485
3486/**
3487 * Obtain the number of indices.
Amaury Sechet053ac452016-02-17 22:51:03 +00003488 * NB: This also works on GEP.
Amaury Sechetaad93532016-02-10 00:38:50 +00003489 */
3490unsigned LLVMGetNumIndices(LLVMValueRef Inst);
3491
3492/**
3493 * Obtain the indices as an array.
3494 */
3495const unsigned *LLVMGetIndices(LLVMValueRef Inst);
3496
3497/**
3498 * @}
3499 */
3500
3501/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003502 * @}
3503 */
3504
3505/**
3506 * @}
3507 */
3508
3509/**
3510 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
3511 *
3512 * An instruction builder represents a point within a basic block and is
3513 * the exclusive means of building instructions using the C interface.
3514 *
3515 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003516 */
3517
Erick Tryzelaar262332f2009-08-14 00:01:31 +00003518LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003519LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00003520void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
3521 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003522void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
3523void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003524LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00003525void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
3526void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00003527void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
3528 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003529void LLVMDisposeBuilder(LLVMBuilderRef Builder);
3530
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00003531/* Metadata */
Robert Widmanncce47412019-04-10 14:19:05 +00003532
3533/**
3534 * Get location information used by debugging information.
3535 *
3536 * @see llvm::IRBuilder::getCurrentDebugLocation()
3537 */
3538LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder);
3539
3540/**
3541 * Set location information used by debugging information.
3542 *
3543 * To clear the location metadata of the given instruction, pass NULL to \p Loc.
3544 *
3545 * @see llvm::IRBuilder::SetCurrentDebugLocation()
3546 */
3547void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc);
3548
3549/**
3550 * Attempts to set the debug location for the given instruction using the
3551 * current debug location for the given builder. If the builder has no current
3552 * debug location, this function is a no-op.
3553 *
3554 * @see llvm::IRBuilder::SetInstDebugLocation()
3555 */
Sam McCall71660b02019-04-10 13:29:37 +00003556void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
Robert Widmannff8febc2019-04-22 13:13:22 +00003557
3558/**
3559 * Get the dafult floating-point math metadata for a given builder.
3560 *
3561 * @see llvm::IRBuilder::getDefaultFPMathTag()
3562 */
3563LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder);
3564
3565/**
3566 * Set the default floating-point math metadata for the given builder.
3567 *
3568 * To clear the metadata, pass NULL to \p FPMathTag.
3569 *
3570 * @see llvm::IRBuilder::setDefaultFPMathTag()
3571 */
3572void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
3573 LLVMMetadataRef FPMathTag);
3574
Robert Widmanncce47412019-04-10 14:19:05 +00003575/**
3576 * Deprecated: Passing the NULL location will crash.
3577 * Use LLVMGetCurrentDebugLocation2 instead.
3578 */
3579void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
3580/**
3581 * Deprecated: Returning the NULL location will crash.
3582 * Use LLVMGetCurrentDebugLocation2 instead.
3583 */
3584LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00003585
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003586/* Terminators */
3587LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
3588LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00003589LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003590 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003591LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
3592LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
3593 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
3594LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
3595 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003596LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
3597 unsigned NumDests);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003598// LLVMBuildInvoke is deprecated in favor of LLVMBuildInvoke2, in preparation
3599// for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003600LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
3601 LLVMValueRef *Args, unsigned NumArgs,
3602 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3603 const char *Name);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003604LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
3605 LLVMValueRef *Args, unsigned NumArgs,
3606 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3607 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003608LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
3609
3610/* Exception Handling */
3611LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00003612LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00003613 LLVMValueRef PersFn, unsigned NumClauses,
3614 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003615LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3616 LLVMBasicBlockRef BB);
3617LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3618 LLVMBasicBlockRef BB);
3619LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3620 LLVMValueRef *Args, unsigned NumArgs,
3621 const char *Name);
3622LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3623 LLVMValueRef *Args, unsigned NumArgs,
3624 const char *Name);
3625LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B, LLVMValueRef ParentPad,
3626 LLVMBasicBlockRef UnwindBB,
3627 unsigned NumHandlers, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003628
Gordon Henriksen097102c2008-01-01 05:50:53 +00003629/* Add a case to the switch instruction */
3630void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
3631 LLVMBasicBlockRef Dest);
3632
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003633/* Add a destination to the indirectbr instruction */
3634void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
3635
Amaury Sechete39e8532016-02-18 20:38:32 +00003636/* Get the number of clauses on the landingpad instruction */
3637unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
3638
3639/* Get the value of the clause at idnex Idx on the landingpad instruction */
3640LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
3641
Bill Wendlingfae14752011-08-12 20:24:12 +00003642/* Add a catch or filter clause to the landingpad instruction */
3643void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
3644
Amaury Sechete39e8532016-02-18 20:38:32 +00003645/* Get the 'cleanup' flag in the landingpad instruction */
3646LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
3647
Bill Wendlingfae14752011-08-12 20:24:12 +00003648/* Set the 'cleanup' flag in the landingpad instruction */
3649void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
3650
Robert Widmann478fce92018-03-30 17:49:53 +00003651/* Add a destination to the catchswitch instruction */
3652void LLVMAddHandler(LLVMValueRef CatchSwitch, LLVMBasicBlockRef Dest);
3653
3654/* Get the number of handlers on the catchswitch instruction */
3655unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch);
3656
3657/**
3658 * Obtain the basic blocks acting as handlers for a catchswitch instruction.
3659 *
3660 * The Handlers parameter should point to a pre-allocated array of
3661 * LLVMBasicBlockRefs at least LLVMGetNumHandlers() large. On return, the
3662 * first LLVMGetNumHandlers() entries in the array will be populated
3663 * with LLVMBasicBlockRef instances.
3664 *
3665 * @param CatchSwitch The catchswitch instruction to operate on.
3666 * @param Handlers Memory address of an array to be filled with basic blocks.
3667 */
3668void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers);
3669
3670/* Funclets */
3671
3672/* Get the number of funcletpad arguments. */
3673LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i);
3674
3675/* Set a funcletpad argument at the given index. */
3676void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value);
3677
3678/**
3679 * Get the parent catchswitch instruction of a catchpad instruction.
3680 *
3681 * This only works on llvm::CatchPadInst instructions.
3682 *
3683 * @see llvm::CatchPadInst::getCatchSwitch()
3684 */
3685LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad);
3686
3687/**
3688 * Set the parent catchswitch instruction of a catchpad instruction.
3689 *
3690 * This only works on llvm::CatchPadInst instructions.
3691 *
3692 * @see llvm::CatchPadInst::setCatchSwitch()
3693 */
3694void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad, LLVMValueRef CatchSwitch);
3695
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003696/* Arithmetic */
3697LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3698 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003699LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3700 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003701LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3702 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003703LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3704 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003705LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3706 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003707LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3708 const char *Name);
3709LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3710 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003711LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3712 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003713LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3714 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003715LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3716 const char *Name);
3717LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3718 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003719LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3720 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003721LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3722 const char *Name);
Manuel Jacob49fafb12016-10-04 23:32:42 +00003723LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3724 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003725LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3726 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003727LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3728 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003729LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3730 const char *Name);
3731LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3732 const char *Name);
3733LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3734 const char *Name);
3735LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3736 const char *Name);
3737LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3738 const char *Name);
3739LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3740 const char *Name);
3741LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3742 const char *Name);
3743LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3744 const char *Name);
3745LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3746 const char *Name);
3747LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3748 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003749LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
3750 LLVMValueRef LHS, LLVMValueRef RHS,
3751 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003752LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003753LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
3754 const char *Name);
3755LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
3756 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00003757LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003758LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
3759
3760/* Memory */
3761LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3762LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
3763 LLVMValueRef Val, const char *Name);
Robert Widmann98640f82018-10-29 15:31:40 +00003764
3765/**
Jim Lin466f8842020-02-18 10:48:38 +08003766 * Creates and inserts a memset to the specified pointer and the
Robert Widmann98640f82018-10-29 15:31:40 +00003767 * specified value.
3768 *
3769 * @see llvm::IRRBuilder::CreateMemSet()
3770 */
3771LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
3772 LLVMValueRef Val, LLVMValueRef Len,
3773 unsigned Align);
3774/**
3775 * Creates and inserts a memcpy between the specified pointers.
3776 *
3777 * @see llvm::IRRBuilder::CreateMemCpy()
3778 */
Jim Lin466f8842020-02-18 10:48:38 +08003779LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,
Robert Widmann98640f82018-10-29 15:31:40 +00003780 LLVMValueRef Dst, unsigned DstAlign,
3781 LLVMValueRef Src, unsigned SrcAlign,
3782 LLVMValueRef Size);
3783/**
3784 * Creates and inserts a memmove between the specified pointers.
3785 *
3786 * @see llvm::IRRBuilder::CreateMemMove()
3787 */
Jim Lin466f8842020-02-18 10:48:38 +08003788LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B,
Robert Widmann98640f82018-10-29 15:31:40 +00003789 LLVMValueRef Dst, unsigned DstAlign,
3790 LLVMValueRef Src, unsigned SrcAlign,
3791 LLVMValueRef Size);
3792
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003793LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3794LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
3795 LLVMValueRef Val, const char *Name);
3796LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003797// LLVMBuildLoad is deprecated in favor of LLVMBuildLoad2, in preparation for
3798// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003799LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
3800 const char *Name);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003801LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty,
3802 LLVMValueRef PointerVal, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003803LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
James Y Knight544fa422019-01-14 21:39:35 +00003804// LLVMBuildGEP, LLVMBuildInBoundsGEP, and LLVMBuildStructGEP are deprecated in
3805// favor of LLVMBuild*GEP2, in preparation for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003806LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3807 LLVMValueRef *Indices, unsigned NumIndices,
3808 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003809LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3810 LLVMValueRef *Indices, unsigned NumIndices,
3811 const char *Name);
3812LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3813 unsigned Idx, const char *Name);
James Y Knight544fa422019-01-14 21:39:35 +00003814LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3815 LLVMValueRef Pointer, LLVMValueRef *Indices,
3816 unsigned NumIndices, const char *Name);
3817LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3818 LLVMValueRef Pointer, LLVMValueRef *Indices,
3819 unsigned NumIndices, const char *Name);
3820LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3821 LLVMValueRef Pointer, unsigned Idx,
3822 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003823LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
3824 const char *Name);
3825LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
3826 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00003827LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
3828void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Nick Lewyckyf57e9682019-09-26 00:58:55 +00003829LLVMBool LLVMGetWeak(LLVMValueRef CmpXchgInst);
3830void LLVMSetWeak(LLVMValueRef CmpXchgInst, LLVMBool IsWeak);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00003831LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
3832void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Nick Lewyckyf57e9682019-09-26 00:58:55 +00003833LLVMAtomicRMWBinOp LLVMGetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst);
3834void LLVMSetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst, LLVMAtomicRMWBinOp BinOp);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003835
3836/* Casts */
3837LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
3838 LLVMTypeRef DestTy, const char *Name);
3839LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
3840 LLVMTypeRef DestTy, const char *Name);
3841LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
3842 LLVMTypeRef DestTy, const char *Name);
3843LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
3844 LLVMTypeRef DestTy, const char *Name);
3845LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
3846 LLVMTypeRef DestTy, const char *Name);
3847LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
3848 LLVMTypeRef DestTy, const char *Name);
3849LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
3850 LLVMTypeRef DestTy, const char *Name);
3851LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
3852 LLVMTypeRef DestTy, const char *Name);
3853LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
3854 LLVMTypeRef DestTy, const char *Name);
3855LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
3856 LLVMTypeRef DestTy, const char *Name);
3857LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
3858 LLVMTypeRef DestTy, const char *Name);
3859LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
3860 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003861LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
3862 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003863LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3864 LLVMTypeRef DestTy, const char *Name);
3865LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3866 LLVMTypeRef DestTy, const char *Name);
3867LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3868 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003869LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
3870 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003871LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
3872 LLVMTypeRef DestTy, const char *Name);
Robert Widmann40dc48be2019-01-08 06:23:22 +00003873LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef, LLVMValueRef Val,
3874 LLVMTypeRef DestTy, LLVMBool IsSigned,
James Y Knight68729f92019-01-14 17:16:55 +00003875 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003876LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
3877 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003878
Robert Widmann40dc48be2019-01-08 06:23:22 +00003879/** Deprecated: This cast is always signed. Use LLVMBuildIntCast2 instead. */
3880LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
3881 LLVMTypeRef DestTy, const char *Name);
3882
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003883/* Comparisons */
3884LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
3885 LLVMValueRef LHS, LLVMValueRef RHS,
3886 const char *Name);
3887LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
3888 LLVMValueRef LHS, LLVMValueRef RHS,
3889 const char *Name);
3890
3891/* Miscellaneous instructions */
3892LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003893// LLVMBuildCall is deprecated in favor of LLVMBuildCall2, in preparation for
3894// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003895LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
3896 LLVMValueRef *Args, unsigned NumArgs,
3897 const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003898LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn,
3899 LLVMValueRef *Args, unsigned NumArgs,
3900 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003901LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
3902 LLVMValueRef Then, LLVMValueRef Else,
3903 const char *Name);
3904LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
3905 const char *Name);
3906LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
3907 LLVMValueRef Index, const char *Name);
3908LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
3909 LLVMValueRef EltVal, LLVMValueRef Index,
3910 const char *Name);
3911LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
3912 LLVMValueRef V2, LLVMValueRef Mask,
3913 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00003914LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
3915 unsigned Index, const char *Name);
3916LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
3917 LLVMValueRef EltVal, unsigned Index,
3918 const char *Name);
aqjunee87d7162019-11-07 01:17:49 +09003919LLVMValueRef LLVMBuildFreeze(LLVMBuilderRef, LLVMValueRef Val,
3920 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00003921
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003922LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
3923 const char *Name);
3924LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
3925 const char *Name);
3926LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
3927 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00003928LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
3929 LLVMBool singleThread, const char *Name);
3930LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00003931 LLVMValueRef PTR, LLVMValueRef Val,
3932 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00003933 LLVMBool singleThread);
Mehdi Amini43165d92016-03-19 21:28:28 +00003934LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
3935 LLVMValueRef Cmp, LLVMValueRef New,
3936 LLVMAtomicOrdering SuccessOrdering,
3937 LLVMAtomicOrdering FailureOrdering,
3938 LLVMBool SingleThread);
3939
3940LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
3941void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
3942
3943LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
3944void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
3945 LLVMAtomicOrdering Ordering);
3946LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
3947void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
3948 LLVMAtomicOrdering Ordering);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003949
Gregory Szorc34c863a2012-03-21 03:54:29 +00003950/**
3951 * @}
3952 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003953
Gregory Szorc34c863a2012-03-21 03:54:29 +00003954/**
3955 * @defgroup LLVMCCoreModuleProvider Module Providers
3956 *
3957 * @{
3958 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003959
Gregory Szorc34c863a2012-03-21 03:54:29 +00003960/**
3961 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003962 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003963 */
3964LLVMModuleProviderRef
3965LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
3966
Gregory Szorc34c863a2012-03-21 03:54:29 +00003967/**
3968 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003969 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003970void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003971
Gregory Szorc34c863a2012-03-21 03:54:29 +00003972/**
3973 * @}
3974 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003975
Gregory Szorc34c863a2012-03-21 03:54:29 +00003976/**
3977 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
3978 *
3979 * @{
3980 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003981
Chris Lattner25963c62010-01-09 22:27:07 +00003982LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
3983 LLVMMemoryBufferRef *OutMemBuf,
3984 char **OutMessage);
3985LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
3986 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00003987LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
3988 size_t InputDataLength,
3989 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00003990 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00003991LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
3992 size_t InputDataLength,
3993 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00003994const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00003995size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003996void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
3997
Gregory Szorc34c863a2012-03-21 03:54:29 +00003998/**
3999 * @}
4000 */
4001
4002/**
4003 * @defgroup LLVMCCorePassRegistry Pass Registry
4004 *
4005 * @{
4006 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00004007
4008/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004009 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00004010LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004011
Gregory Szorc34c863a2012-03-21 03:54:29 +00004012/**
4013 * @}
4014 */
4015
4016/**
4017 * @defgroup LLVMCCorePassManagers Pass Managers
4018 *
4019 * @{
4020 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004021
4022/** Constructs a new whole-module pass pipeline. This type of pipeline is
4023 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004024 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00004025LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004026
4027/** Constructs a new function-by-function pass pipeline over the module
4028 provider. It does not take ownership of the module provider. This type of
4029 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004030 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00004031LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
4032
4033/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004034LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
4035
4036/** Initializes, executes on the provided module, and finalizes all of the
4037 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00004038 modified the module, 0 otherwise.
4039 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00004040LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004041
4042/** Initializes all of the function passes scheduled in the function pass
4043 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004044 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00004045LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004046
4047/** Executes all of the function passes scheduled in the function pass manager
4048 on the provided function. Returns 1 if any of the passes modified the
4049 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004050 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00004051LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004052
Hiroshi Inoue0909ca12018-01-26 08:15:29 +00004053/** Finalizes all of the function passes scheduled in the function pass
Gordon Henriksen878114b2008-03-16 04:20:44 +00004054 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004055 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00004056LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004057
4058/** Frees the memory of a pass pipeline. For function pipelines, does not free
4059 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004060 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004061void LLVMDisposePassManager(LLVMPassManagerRef PM);
4062
Gregory Szorc34c863a2012-03-21 03:54:29 +00004063/**
4064 * @}
4065 */
4066
4067/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00004068 * @defgroup LLVMCCoreThreading Threading
4069 *
4070 * Handle the structures needed to make LLVM safe for multithreading.
4071 *
4072 * @{
4073 */
4074
Chandler Carruth39cd2162014-06-27 15:13:01 +00004075/** Deprecated: Multi-threading can only be enabled/disabled with the compile
4076 time define LLVM_ENABLE_THREADS. This function always returns
4077 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00004078LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00004079
Chandler Carruth39cd2162014-06-27 15:13:01 +00004080/** Deprecated: Multi-threading can only be enabled/disabled with the compile
4081 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00004082void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00004083
4084/** Check whether LLVM is executing in thread-safe mode or not.
4085 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00004086LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00004087
4088/**
4089 * @}
4090 */
4091
4092/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00004093 * @}
4094 */
4095
4096/**
4097 * @}
4098 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004099
Duncan P. N. Exon Smith8c484052019-11-14 13:57:57 -08004100LLVM_C_EXTERN_C_END
Gordon Henriksen7330acd2007-10-05 23:59:36 +00004101
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00004102#endif /* LLVM_C_CORE_H */