blob: 9c521899c95bc6be4a048854ee66c2dd9fe67916 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
Chandler Carruth2946cd72019-01-19 08:50:56 +00003|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4|* Exceptions. *|
5|* See https://llvm.org/LICENSE.txt for license information. *|
6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000013\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_C_CORE_H
16#define LLVM_C_CORE_H
17
Eric Christophera6b96002015-12-18 01:46:52 +000018#include "llvm-c/ErrorHandling.h"
19#include "llvm-c/Types.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000020
Evan Cheng2e254d02013-04-04 17:40:53 +000021#ifdef __cplusplus
Gordon Henriksen76a03742007-09-18 03:18:57 +000022extern "C" {
23#endif
24
Gregory Szorc34c863a2012-03-21 03:54:29 +000025/**
26 * @defgroup LLVMC LLVM-C: C interface to LLVM
27 *
28 * This module exposes parts of the LLVM library as a C API.
29 *
30 * @{
31 */
32
33/**
34 * @defgroup LLVMCTransforms Transforms
35 */
36
37/**
38 * @defgroup LLVMCCore Core
39 *
40 * This modules provide an interface to libLLVMCore, which implements
41 * the LLVM intermediate representation as well as other related types
42 * and utilities.
43 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000044 * Many exotic languages can interoperate with C code but have a harder time
45 * with C++ due to name mangling. So in addition to C, this interface enables
46 * tools written in such languages.
47 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000048 * @{
49 */
50
51/**
52 * @defgroup LLVMCCoreTypes Types and Enumerations
53 *
54 * @{
55 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000056
Cameron McInallycbde0d92018-11-13 18:15:47 +000057/// External users depend on the following values being stable. It is not safe
58/// to reorder them.
Gordon Henriksen76a03742007-09-18 03:18:57 +000059typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +000060 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +000061 LLVMRet = 1,
62 LLVMBr = 2,
63 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +000064 LLVMIndirectBr = 4,
65 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +000066 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +000067 LLVMUnreachable = 7,
Craig Topper784929d2019-02-08 20:48:56 +000068 LLVMCallBr = 67,
Bill Wendling07d6d762010-02-15 20:50:51 +000069
Cameron McInallycbde0d92018-11-13 18:15:47 +000070 /* Standard Unary Operators */
71 LLVMFNeg = 66,
72
Bill Wendlingda52cec2010-02-15 20:53:17 +000073 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000074 LLVMAdd = 8,
75 LLVMFAdd = 9,
76 LLVMSub = 10,
77 LLVMFSub = 11,
78 LLVMMul = 12,
79 LLVMFMul = 13,
80 LLVMUDiv = 14,
81 LLVMSDiv = 15,
82 LLVMFDiv = 16,
83 LLVMURem = 17,
84 LLVMSRem = 18,
85 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +000086
Bill Wendlingda52cec2010-02-15 20:53:17 +000087 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000088 LLVMShl = 20,
89 LLVMLShr = 21,
90 LLVMAShr = 22,
91 LLVMAnd = 23,
92 LLVMOr = 24,
93 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +000094
Bill Wendlingda52cec2010-02-15 20:53:17 +000095 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000096 LLVMAlloca = 26,
97 LLVMLoad = 27,
98 LLVMStore = 28,
99 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000100
Bill Wendlingda52cec2010-02-15 20:53:17 +0000101 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000102 LLVMTrunc = 30,
103 LLVMZExt = 31,
104 LLVMSExt = 32,
105 LLVMFPToUI = 33,
106 LLVMFPToSI = 34,
107 LLVMUIToFP = 35,
108 LLVMSIToFP = 36,
109 LLVMFPTrunc = 37,
110 LLVMFPExt = 38,
111 LLVMPtrToInt = 39,
112 LLVMIntToPtr = 40,
113 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000114 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000115
Bill Wendlingda52cec2010-02-15 20:53:17 +0000116 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000117 LLVMICmp = 42,
118 LLVMFCmp = 43,
119 LLVMPHI = 44,
120 LLVMCall = 45,
121 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000122 LLVMUserOp1 = 47,
123 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000124 LLVMVAArg = 49,
125 LLVMExtractElement = 50,
126 LLVMInsertElement = 51,
127 LLVMShuffleVector = 52,
128 LLVMExtractValue = 53,
129 LLVMInsertValue = 54,
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 */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000149 LLVMFloatTypeKind, /**< 32 bit floating point type */
150 LLVMDoubleTypeKind, /**< 64 bit floating point type */
151 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
152 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
153 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
154 LLVMLabelTypeKind, /**< Labels */
155 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
156 LLVMFunctionTypeKind, /**< Functions */
157 LLVMStructTypeKind, /**< Structures */
158 LLVMArrayTypeKind, /**< Arrays */
159 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000160 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000161 LLVMMetadataTypeKind, /**< Metadata */
David Majnemerb611e3f2015-08-14 05:09:07 +0000162 LLVMX86_MMXTypeKind, /**< X86 MMX */
163 LLVMTokenTypeKind /**< Tokens */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000164} LLVMTypeKind;
165
166typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000167 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000168 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000169 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
170 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
171 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000172 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000173 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
174 LLVMWeakODRLinkage, /**< Same, but only replaced by something
175 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000176 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
177 LLVMInternalLinkage, /**< Rename collisions when linking (static
178 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000179 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000180 LLVMDLLImportLinkage, /**< Obsolete */
181 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000182 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000183 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000184 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000185 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000186 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000187} LLVMLinkage;
188
189typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000190 LLVMDefaultVisibility, /**< The GV is visible */
191 LLVMHiddenVisibility, /**< The GV is hidden */
192 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000193} LLVMVisibility;
194
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000195typedef enum {
Robert Widmann4bb481b2018-03-14 06:45:51 +0000196 LLVMNoUnnamedAddr, /**< Address of the GV is significant. */
197 LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */
198 LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */
199} LLVMUnnamedAddr;
200
201typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000202 LLVMDefaultStorageClass = 0,
203 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
204 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
205} LLVMDLLStorageClass;
206
207typedef enum {
Robert Widmann1e989de2018-04-06 04:02:39 +0000208 LLVMCCallConv = 0,
209 LLVMFastCallConv = 8,
210 LLVMColdCallConv = 9,
211 LLVMGHCCallConv = 10,
212 LLVMHiPECallConv = 11,
213 LLVMWebKitJSCallConv = 12,
214 LLVMAnyRegCallConv = 13,
215 LLVMPreserveMostCallConv = 14,
216 LLVMPreserveAllCallConv = 15,
217 LLVMSwiftCallConv = 16,
218 LLVMCXXFASTTLSCallConv = 17,
219 LLVMX86StdcallCallConv = 64,
220 LLVMX86FastcallCallConv = 65,
221 LLVMARMAPCSCallConv = 66,
222 LLVMARMAAPCSCallConv = 67,
223 LLVMARMAAPCSVFPCallConv = 68,
224 LLVMMSP430INTRCallConv = 69,
225 LLVMX86ThisCallCallConv = 70,
226 LLVMPTXKernelCallConv = 71,
227 LLVMPTXDeviceCallConv = 72,
228 LLVMSPIRFUNCCallConv = 75,
229 LLVMSPIRKERNELCallConv = 76,
230 LLVMIntelOCLBICallConv = 77,
231 LLVMX8664SysVCallConv = 78,
232 LLVMWin64CallConv = 79,
233 LLVMX86VectorCallCallConv = 80,
234 LLVMHHVMCallConv = 81,
235 LLVMHHVMCCallConv = 82,
236 LLVMX86INTRCallConv = 83,
237 LLVMAVRINTRCallConv = 84,
238 LLVMAVRSIGNALCallConv = 85,
239 LLVMAVRBUILTINCallConv = 86,
240 LLVMAMDGPUVSCallConv = 87,
241 LLVMAMDGPUGSCallConv = 88,
242 LLVMAMDGPUPSCallConv = 89,
243 LLVMAMDGPUCSCallConv = 90,
244 LLVMAMDGPUKERNELCallConv = 91,
245 LLVMX86RegCallCallConv = 92,
246 LLVMAMDGPUHSCallConv = 93,
247 LLVMMSP430BUILTINCallConv = 94,
248 LLVMAMDGPULSCallConv = 95,
249 LLVMAMDGPUESCallConv = 96
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000250} LLVMCallConv;
251
252typedef enum {
Peter Zotov3e4561c2016-04-06 22:21:29 +0000253 LLVMArgumentValueKind,
254 LLVMBasicBlockValueKind,
255 LLVMMemoryUseValueKind,
256 LLVMMemoryDefValueKind,
257 LLVMMemoryPhiValueKind,
258
259 LLVMFunctionValueKind,
260 LLVMGlobalAliasValueKind,
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000261 LLVMGlobalIFuncValueKind,
Peter Zotov3e4561c2016-04-06 22:21:29 +0000262 LLVMGlobalVariableValueKind,
263 LLVMBlockAddressValueKind,
264 LLVMConstantExprValueKind,
265 LLVMConstantArrayValueKind,
266 LLVMConstantStructValueKind,
267 LLVMConstantVectorValueKind,
268
269 LLVMUndefValueValueKind,
270 LLVMConstantAggregateZeroValueKind,
271 LLVMConstantDataArrayValueKind,
272 LLVMConstantDataVectorValueKind,
273 LLVMConstantIntValueKind,
274 LLVMConstantFPValueKind,
275 LLVMConstantPointerNullValueKind,
276 LLVMConstantTokenNoneValueKind,
277
278 LLVMMetadataAsValueValueKind,
279 LLVMInlineAsmValueKind,
280
281 LLVMInstructionValueKind,
282} LLVMValueKind;
283
284typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000285 LLVMIntEQ = 32, /**< equal */
286 LLVMIntNE, /**< not equal */
287 LLVMIntUGT, /**< unsigned greater than */
288 LLVMIntUGE, /**< unsigned greater or equal */
289 LLVMIntULT, /**< unsigned less than */
290 LLVMIntULE, /**< unsigned less or equal */
291 LLVMIntSGT, /**< signed greater than */
292 LLVMIntSGE, /**< signed greater or equal */
293 LLVMIntSLT, /**< signed less than */
294 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000295} LLVMIntPredicate;
296
297typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000298 LLVMRealPredicateFalse, /**< Always false (always folded) */
299 LLVMRealOEQ, /**< True if ordered and equal */
300 LLVMRealOGT, /**< True if ordered and greater than */
301 LLVMRealOGE, /**< True if ordered and greater than or equal */
302 LLVMRealOLT, /**< True if ordered and less than */
303 LLVMRealOLE, /**< True if ordered and less than or equal */
304 LLVMRealONE, /**< True if ordered and operands are unequal */
305 LLVMRealORD, /**< True if ordered (no nans) */
306 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
307 LLVMRealUEQ, /**< True if unordered or equal */
308 LLVMRealUGT, /**< True if unordered or greater than */
309 LLVMRealUGE, /**< True if unordered, greater than, or equal */
310 LLVMRealULT, /**< True if unordered or less than */
311 LLVMRealULE, /**< True if unordered, less than, or equal */
312 LLVMRealUNE, /**< True if unordered or not equal */
313 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000314} LLVMRealPredicate;
315
Bill Wendlingfae14752011-08-12 20:24:12 +0000316typedef enum {
317 LLVMLandingPadCatch, /**< A catch clause */
318 LLVMLandingPadFilter /**< A filter clause */
319} LLVMLandingPadClauseTy;
320
Hans Wennborg5ff71202013-04-16 08:58:59 +0000321typedef enum {
322 LLVMNotThreadLocal = 0,
323 LLVMGeneralDynamicTLSModel,
324 LLVMLocalDynamicTLSModel,
325 LLVMInitialExecTLSModel,
326 LLVMLocalExecTLSModel
327} LLVMThreadLocalMode;
328
Carlo Kokda0ac722013-04-23 13:45:37 +0000329typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000330 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
331 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
332 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000333 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
334 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000335 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000336 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
337 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000338 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000339 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
340 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000341 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000342 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
343 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000344 operations which both read and write
345 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000346 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
347 for loads and Release
348 semantics for stores.
349 Additionally, it guarantees
350 that a total ordering exists
351 between all
352 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000353 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000354} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000355
Carlo Kokda0ac722013-04-23 13:45:37 +0000356typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000357 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
358 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
359 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
360 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
361 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
362 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
363 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
364 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000365 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000366 the old one */
367 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000368 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000369 the old one */
370 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000371 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000372 the old one */
373 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000374 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000375 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000376} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000377
Tom Stellard1580dc72014-04-16 17:45:04 +0000378typedef enum {
379 LLVMDSError,
380 LLVMDSWarning,
381 LLVMDSRemark,
382 LLVMDSNote
383} LLVMDiagnosticSeverity;
384
Robert Widmannf108d572018-04-06 02:31:29 +0000385typedef enum {
386 LLVMInlineAsmDialectATT,
387 LLVMInlineAsmDialectIntel
388} LLVMInlineAsmDialect;
389
Robert Widmannbce367702018-05-14 08:09:00 +0000390typedef enum {
391 /**
392 * Emits an error if two values disagree, otherwise the resulting value is
393 * that of the operands.
394 *
395 * @see Module::ModFlagBehavior::Error
396 */
397 LLVMModuleFlagBehaviorError,
398 /**
399 * Emits a warning if two values disagree. The result value will be the
400 * operand for the flag from the first module being linked.
401 *
402 * @see Module::ModFlagBehavior::Warning
403 */
404 LLVMModuleFlagBehaviorWarning,
405 /**
406 * Adds a requirement that another module flag be present and have a
407 * specified value after linking is performed. The value must be a metadata
408 * pair, where the first element of the pair is the ID of the module flag
409 * to be restricted, and the second element of the pair is the value the
410 * module flag should be restricted to. This behavior can be used to
411 * restrict the allowable results (via triggering of an error) of linking
412 * IDs with the **Override** behavior.
413 *
414 * @see Module::ModFlagBehavior::Require
415 */
416 LLVMModuleFlagBehaviorRequire,
417 /**
418 * Uses the specified value, regardless of the behavior or value of the
419 * other module. If both modules specify **Override**, but the values
420 * differ, an error will be emitted.
421 *
422 * @see Module::ModFlagBehavior::Override
423 */
424 LLVMModuleFlagBehaviorOverride,
425 /**
426 * Appends the two values, which are required to be metadata nodes.
427 *
428 * @see Module::ModFlagBehavior::Append
429 */
430 LLVMModuleFlagBehaviorAppend,
431 /**
432 * Appends the two values, which are required to be metadata
433 * nodes. However, duplicate entries in the second list are dropped
434 * during the append operation.
435 *
436 * @see Module::ModFlagBehavior::AppendUnique
437 */
438 LLVMModuleFlagBehaviorAppendUnique,
439} LLVMModuleFlagBehavior;
440
Gregory Szorc34c863a2012-03-21 03:54:29 +0000441/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000442 * Attribute index are either LLVMAttributeReturnIndex,
443 * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
444 */
445enum {
446 LLVMAttributeReturnIndex = 0U,
447 // ISO C restricts enumerator values to range of 'int'
448 // (4294967295 is too large)
449 // LLVMAttributeFunctionIndex = ~0U,
450 LLVMAttributeFunctionIndex = -1,
451};
452
453typedef unsigned LLVMAttributeIndex;
454
455/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000456 * @}
457 */
458
Nick Lewycky0db26542011-05-15 07:20:34 +0000459void LLVMInitializeCore(LLVMPassRegistryRef R);
460
Duncan Sands1cba0a82013-02-17 16:35:51 +0000461/** Deallocate and destroy all ManagedStatic variables.
462 @see llvm::llvm_shutdown
463 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000464void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000465
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000466/*===-- Error handling ----------------------------------------------------===*/
467
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000468char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000469void LLVMDisposeMessage(char *Message);
470
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000471/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000472 * @defgroup LLVMCCoreContext Contexts
473 *
474 * Contexts are execution states for the core LLVM IR system.
475 *
476 * Most types are tied to a context instance. Multiple contexts can
477 * exist simultaneously. A single context is not thread safe. However,
478 * different contexts can execute on different threads simultaneously.
479 *
480 * @{
481 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000482
Tom Stellard1580dc72014-04-16 17:45:04 +0000483typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000484typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000485
Gregory Szorc34c863a2012-03-21 03:54:29 +0000486/**
487 * Create a new context.
488 *
489 * Every call to this function should be paired with a call to
490 * LLVMContextDispose() or the context will leak memory.
491 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000492LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000493
494/**
495 * Obtain the global context instance.
496 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000497LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000498
499/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000500 * Set the diagnostic handler for this context.
501 */
502void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
503 LLVMDiagnosticHandler Handler,
504 void *DiagnosticContext);
505
506/**
Jeroen Ketemaad659c32016-04-08 09:19:02 +0000507 * Get the diagnostic handler of this context.
508 */
509LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
510
511/**
512 * Get the diagnostic context of this context.
513 */
514void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
515
516/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000517 * Set the yield callback function for this context.
518 *
519 * @see LLVMContext::setYieldCallback()
520 */
521void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
522 void *OpaqueHandle);
523
524/**
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000525 * Retrieve whether the given context is set to discard all value names.
526 *
527 * @see LLVMContext::shouldDiscardValueNames()
528 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000529LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000530
531/**
532 * Set whether the given context discards all value names.
533 *
534 * If true, only the names of GlobalValue objects will be available in the IR.
535 * This can be used to save memory and runtime, especially in release mode.
536 *
537 * @see LLVMContext::setDiscardValueNames()
538 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000539void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000540
541/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000542 * Destroy a context instance.
543 *
544 * This should be called for every call to LLVMContextCreate() or memory
545 * will be leaked.
546 */
Owen Anderson6773d382009-07-01 16:58:40 +0000547void LLVMContextDispose(LLVMContextRef C);
548
Tom Stellard1580dc72014-04-16 17:45:04 +0000549/**
550 * Return a string representation of the DiagnosticInfo. Use
551 * LLVMDisposeMessage to free the string.
552 *
553 * @see DiagnosticInfo::print()
554 */
555char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
556
557/**
558 * Return an enum LLVMDiagnosticSeverity.
559 *
560 * @see DiagnosticInfo::getSeverity()
561 */
562LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
563
Amaury Sechet56f056c2016-04-04 22:00:25 +0000564unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000565 unsigned SLen);
Amaury Sechet56f056c2016-04-04 22:00:25 +0000566unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000567
Gregory Szorc34c863a2012-03-21 03:54:29 +0000568/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000569 * Return an unique id given the name of a enum attribute,
Amaury Sechet60b31452016-04-20 01:02:12 +0000570 * or 0 if no attribute by that name exists.
571 *
572 * See http://llvm.org/docs/LangRef.html#parameter-attributes
573 * and http://llvm.org/docs/LangRef.html#function-attributes
574 * for the list of available attributes.
575 *
576 * NB: Attribute names and/or id are subject to change without
577 * going through the C API deprecation cycle.
578 */
Amaury Sechet5db224e2016-06-12 06:17:24 +0000579unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
Amaury Sechet48b06652016-06-12 07:56:21 +0000580unsigned LLVMGetLastEnumAttributeKind(void);
Amaury Sechet5db224e2016-06-12 06:17:24 +0000581
582/**
583 * Create an enum attribute.
584 */
585LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
586 uint64_t Val);
587
588/**
589 * Get the unique id corresponding to the enum attribute
590 * passed as argument.
591 */
592unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
593
594/**
595 * Get the enum attribute's value. 0 is returned if none exists.
596 */
597uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
598
599/**
600 * Create a string attribute.
601 */
602LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
603 const char *K, unsigned KLength,
604 const char *V, unsigned VLength);
605
606/**
607 * Get the string attribute's kind.
608 */
609const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
610
611/**
612 * Get the string attribute's value.
613 */
614const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
615
616/**
617 * Check for the different types of attributes.
618 */
619LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
620LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
Amaury Sechet60b31452016-04-20 01:02:12 +0000621
622/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000623 * @}
624 */
625
Gregory Szorc52d26602012-03-21 07:28:27 +0000626/**
627 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000628 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000629 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000630 * module is effectively a translation unit or a collection of
631 * translation units merged together.
632 *
633 * @{
634 */
635
Gregory Szorc34c863a2012-03-21 03:54:29 +0000636/**
637 * Create a new, empty module in the global context.
638 *
639 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
640 * LLVMGetGlobalContext() as the context parameter.
641 *
642 * Every invocation should be paired with LLVMDisposeModule() or memory
643 * will be leaked.
644 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000645LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000646
647/**
648 * Create a new, empty module in a specific context.
649 *
650 * Every invocation should be paired with LLVMDisposeModule() or memory
651 * will be leaked.
652 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000653LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
654 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000655/**
656 * Return an exact copy of the specified module.
657 */
658LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000659
Gregory Szorc34c863a2012-03-21 03:54:29 +0000660/**
661 * Destroy a module instance.
662 *
663 * This must be called for every created module or memory will be
664 * leaked.
665 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000666void LLVMDisposeModule(LLVMModuleRef M);
667
Gregory Szorc34c863a2012-03-21 03:54:29 +0000668/**
Peter Zotov0a2fa0a2016-04-05 13:56:59 +0000669 * Obtain the identifier of a module.
670 *
671 * @param M Module to obtain identifier of
672 * @param Len Out parameter which holds the length of the returned string.
673 * @return The identifier of M.
674 * @see Module::getModuleIdentifier()
675 */
676const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
677
678/**
679 * Set the identifier of a module to a string Ident with length Len.
680 *
681 * @param M The module to set identifier
682 * @param Ident The string to set M's identifier to
683 * @param Len Length of Ident
684 * @see Module::setModuleIdentifier()
685 */
686void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
687
688/**
Robert Widmann490a5802018-01-30 21:34:29 +0000689 * Obtain the module's original source file name.
690 *
691 * @param M Module to obtain the name of
692 * @param Len Out parameter which holds the length of the returned string
693 * @return The original source file name of M
694 * @see Module::getSourceFileName()
695 */
696const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len);
697
698/**
699 * Set the original source file name of a module to a string Name with length
700 * Len.
701 *
702 * @param M The module to set the source file name of
703 * @param Name The string to set M's source file name to
704 * @param Len Length of Name
705 * @see Module::setSourceFileName()
706 */
707void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len);
708
709/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000710 * Obtain the data layout for a module.
711 *
Amaury Sechetf3549c42016-02-16 00:23:52 +0000712 * @see Module::getDataLayoutStr()
713 *
714 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
715 * but match the name of another method on the module. Prefer the use
716 * of LLVMGetDataLayoutStr, which is not ambiguous.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000717 */
Amaury Sechetf3549c42016-02-16 00:23:52 +0000718const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000719const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000720
721/**
722 * Set the data layout for a module.
723 *
724 * @see Module::setDataLayout()
725 */
Amaury Sechet6ada31c2016-02-15 23:40:06 +0000726void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000727
Gregory Szorc34c863a2012-03-21 03:54:29 +0000728/**
729 * Obtain the target triple for a module.
730 *
731 * @see Module::getTargetTriple()
732 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000733const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000734
735/**
736 * Set the target triple for a module.
737 *
738 * @see Module::setTargetTriple()
739 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000740void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
741
Gregory Szorc34c863a2012-03-21 03:54:29 +0000742/**
Robert Widmannbce367702018-05-14 08:09:00 +0000743 * Returns the module flags as an array of flag-key-value triples. The caller
744 * is responsible for freeing this array by calling
745 * \c LLVMDisposeModuleFlagsMetadata.
746 *
747 * @see Module::getModuleFlagsMetadata()
748 */
749LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(LLVMModuleRef M, size_t *Len);
750
751/**
752 * Destroys module flags metadata entries.
753 */
754void LLVMDisposeModuleFlagsMetadata(LLVMModuleFlagEntry *Entries);
755
756/**
757 * Returns the flag behavior for a module flag entry at a specific index.
758 *
759 * @see Module::ModuleFlagEntry::Behavior
760 */
761LLVMModuleFlagBehavior
762LLVMModuleFlagEntriesGetFlagBehavior(LLVMModuleFlagEntry *Entries,
763 unsigned Index);
764
765/**
766 * Returns the key for a module flag entry at a specific index.
767 *
768 * @see Module::ModuleFlagEntry::Key
769 */
770const char *LLVMModuleFlagEntriesGetKey(LLVMModuleFlagEntry *Entries,
771 unsigned Index, size_t *Len);
772
773/**
774 * Returns the metadata for a module flag entry at a specific index.
775 *
776 * @see Module::ModuleFlagEntry::Val
777 */
778LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries,
779 unsigned Index);
780
781/**
782 * Add a module-level flag to the module-level flags metadata if it doesn't
783 * already exist.
784 *
785 * @see Module::getModuleFlag()
786 */
787LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRef M,
788 const char *Key, size_t KeyLen);
789
790/**
791 * Add a module-level flag to the module-level flags metadata if it doesn't
792 * already exist.
793 *
794 * @see Module::addModuleFlag()
795 */
796void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior,
797 const char *Key, size_t KeyLen,
798 LLVMMetadataRef Val);
799
800/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000801 * Dump a representation of a module to stderr.
802 *
803 * @see Module::dump()
804 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000805void LLVMDumpModule(LLVMModuleRef M);
806
Gregory Szorc34c863a2012-03-21 03:54:29 +0000807/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000808 * Print a representation of a module to a file. The ErrorMessage needs to be
809 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
810 *
811 * @see Module::print()
812 */
813LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
814 char **ErrorMessage);
815
816/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000817 * Return a string representation of the module. Use
818 * LLVMDisposeMessage to free the string.
819 *
820 * @see Module::print()
821 */
822char *LLVMPrintModuleToString(LLVMModuleRef M);
823
824/**
Robert Widmannf108d572018-04-06 02:31:29 +0000825 * Get inline assembly for a module.
826 *
827 * @see Module::getModuleInlineAsm()
828 */
829const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len);
830
831/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000832 * Set inline assembly for a module.
833 *
834 * @see Module::setModuleInlineAsm()
835 */
Robert Widmannf108d572018-04-06 02:31:29 +0000836void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len);
837
838/**
839 * Append inline assembly to a module.
840 *
841 * @see Module::appendModuleInlineAsm()
842 */
843void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len);
844
845/**
846 * Create the specified uniqued inline asm string.
847 *
848 * @see InlineAsm::get()
849 */
850LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty,
851 char *AsmString, size_t AsmStringSize,
852 char *Constraints, size_t ConstraintsSize,
853 LLVMBool HasSideEffects, LLVMBool IsAlignStack,
854 LLVMInlineAsmDialect Dialect);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000855
Gregory Szorc34c863a2012-03-21 03:54:29 +0000856/**
857 * Obtain the context to which this module is associated.
858 *
859 * @see Module::getContext()
860 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000861LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
862
Gregory Szorc34c863a2012-03-21 03:54:29 +0000863/**
864 * Obtain a Type from a module by its registered name.
865 */
866LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000867
Gregory Szorc34c863a2012-03-21 03:54:29 +0000868/**
Robert Widmann0a35b762018-08-30 17:09:43 +0000869 * Obtain an iterator to the first NamedMDNode in a Module.
870 *
871 * @see llvm::Module::named_metadata_begin()
872 */
873LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M);
874
875/**
876 * Obtain an iterator to the last NamedMDNode in a Module.
877 *
878 * @see llvm::Module::named_metadata_end()
879 */
880LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M);
881
882/**
883 * Advance a NamedMDNode iterator to the next NamedMDNode.
884 *
885 * Returns NULL if the iterator was already at the end and there are no more
886 * named metadata nodes.
887 */
888LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
889
890/**
891 * Decrement a NamedMDNode iterator to the previous NamedMDNode.
892 *
893 * Returns NULL if the iterator was already at the beginning and there are
894 * no previous named metadata nodes.
895 */
896LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
897
898/**
899 * Retrieve a NamedMDNode with the given name, returning NULL if no such
900 * node exists.
901 *
902 * @see llvm::Module::getNamedMetadata()
903 */
904LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M,
905 const char *Name, size_t NameLen);
906
907/**
908 * Retrieve a NamedMDNode with the given name, creating a new node if no such
909 * node exists.
910 *
911 * @see llvm::Module::getOrInsertNamedMetadata()
912 */
913LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M,
914 const char *Name,
915 size_t NameLen);
916
917/**
918 * Retrieve the name of a NamedMDNode.
919 *
920 * @see llvm::NamedMDNode::getName()
921 */
922const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NamedMD,
923 size_t *NameLen);
924
925/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000926 * Obtain the number of operands for named metadata in a module.
927 *
928 * @see llvm::Module::getNamedMetadata()
929 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000930unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000931
932/**
933 * Obtain the named metadata operands for a module.
934 *
935 * The passed LLVMValueRef pointer should refer to an array of
936 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
937 * array will be populated with the LLVMValueRef instances. Each
938 * instance corresponds to a llvm::MDNode.
939 *
940 * @see llvm::Module::getNamedMetadata()
941 * @see llvm::MDNode::getOperand()
942 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000943void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
944 LLVMValueRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000945
946/**
947 * Add an operand to named metadata.
948 *
949 * @see llvm::Module::getNamedMetadata()
950 * @see llvm::MDNode::addOperand()
951 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000952void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
Gregory Szorc34c863a2012-03-21 03:54:29 +0000953 LLVMValueRef Val);
954
Gregory Szorc52d26602012-03-21 07:28:27 +0000955/**
Saleem Abdulrasool0d1cbcc2018-10-10 23:53:12 +0000956 * Return the directory of the debug location for this value, which must be
957 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
958 *
959 * @see llvm::Instruction::getDebugLoc()
960 * @see llvm::GlobalVariable::getDebugInfo()
961 * @see llvm::Function::getSubprogram()
962 */
963const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length);
964
965/**
966 * Return the filename of the debug location for this value, which must be
967 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
968 *
969 * @see llvm::Instruction::getDebugLoc()
970 * @see llvm::GlobalVariable::getDebugInfo()
971 * @see llvm::Function::getSubprogram()
972 */
973const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length);
974
975/**
976 * Return the line number of the debug location for this value, which must be
977 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
978 *
979 * @see llvm::Instruction::getDebugLoc()
980 * @see llvm::GlobalVariable::getDebugInfo()
981 * @see llvm::Function::getSubprogram()
982 */
983unsigned LLVMGetDebugLocLine(LLVMValueRef Val);
984
985/**
986 * Return the column number of the debug location for this value, which must be
987 * an llvm::Instruction.
988 *
989 * @see llvm::Instruction::getDebugLoc()
990 */
991unsigned LLVMGetDebugLocColumn(LLVMValueRef Val);
992
993/**
Gregory Szorc52d26602012-03-21 07:28:27 +0000994 * Add a function to a module under a specified name.
995 *
996 * @see llvm::Function::Create()
997 */
998LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
999 LLVMTypeRef FunctionTy);
1000
1001/**
1002 * Obtain a Function value from a Module by its name.
1003 *
1004 * The returned value corresponds to a llvm::Function value.
1005 *
1006 * @see llvm::Module::getFunction()
1007 */
1008LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
1009
1010/**
1011 * Obtain an iterator to the first Function in a Module.
1012 *
1013 * @see llvm::Module::begin()
1014 */
1015LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
1016
1017/**
1018 * Obtain an iterator to the last Function in a Module.
1019 *
1020 * @see llvm::Module::end()
1021 */
1022LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
1023
1024/**
1025 * Advance a Function iterator to the next Function.
1026 *
1027 * Returns NULL if the iterator was already at the end and there are no more
1028 * functions.
1029 */
1030LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
1031
1032/**
1033 * Decrement a Function iterator to the previous Function.
1034 *
1035 * Returns NULL if the iterator was already at the beginning and there are
1036 * no previous functions.
1037 */
1038LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001039
Robert Widmannf108d572018-04-06 02:31:29 +00001040/** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */
1041void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
1042
Gregory Szorc34c863a2012-03-21 03:54:29 +00001043/**
1044 * @}
1045 */
1046
1047/**
1048 * @defgroup LLVMCCoreType Types
1049 *
1050 * Types represent the type of a value.
1051 *
1052 * Types are associated with a context instance. The context internally
1053 * deduplicates types so there is only 1 instance of a specific type
1054 * alive at a time. In other words, a unique type is shared among all
1055 * consumers within a context.
1056 *
1057 * A Type in the C API corresponds to llvm::Type.
1058 *
1059 * Types have the following hierarchy:
1060 *
Gordon Henriksen76a03742007-09-18 03:18:57 +00001061 * types:
1062 * integer type
1063 * real type
1064 * function type
1065 * sequence types:
1066 * array type
1067 * pointer type
1068 * vector type
1069 * void type
1070 * label type
1071 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +00001072 *
1073 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001074 */
1075
Gregory Szorc34c863a2012-03-21 03:54:29 +00001076/**
1077 * Obtain the enumerated type of a Type instance.
1078 *
1079 * @see llvm::Type:getTypeID()
1080 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001081LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001082
1083/**
1084 * Whether the type has a known size.
1085 *
1086 * Things that don't have a size are abstract types, labels, and void.a
1087 *
1088 * @see llvm::Type::isSized()
1089 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +00001090LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +00001091
Gregory Szorc34c863a2012-03-21 03:54:29 +00001092/**
1093 * Obtain the context to which this type instance is associated.
1094 *
1095 * @see llvm::Type::getContext()
1096 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001097LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
1098
Gregory Szorc34c863a2012-03-21 03:54:29 +00001099/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +00001100 * Dump a representation of a type to stderr.
1101 *
1102 * @see llvm::Type::dump()
1103 */
1104void LLVMDumpType(LLVMTypeRef Val);
1105
1106/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +00001107 * Return a string representation of the type. Use
1108 * LLVMDisposeMessage to free the string.
1109 *
1110 * @see llvm::Type::print()
1111 */
1112char *LLVMPrintTypeToString(LLVMTypeRef Val);
1113
1114/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001115 * @defgroup LLVMCCoreTypeInt Integer Types
1116 *
1117 * Functions in this section operate on integer types.
1118 *
1119 * @{
1120 */
1121
1122/**
1123 * Obtain an integer type from a context with specified bit width.
1124 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001125LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
1126LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
1127LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
1128LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
1129LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001130LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001131LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
1132
Gregory Szorc34c863a2012-03-21 03:54:29 +00001133/**
1134 * Obtain an integer type from the global context with a specified bit
1135 * width.
1136 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001137LLVMTypeRef LLVMInt1Type(void);
1138LLVMTypeRef LLVMInt8Type(void);
1139LLVMTypeRef LLVMInt16Type(void);
1140LLVMTypeRef LLVMInt32Type(void);
1141LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001142LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001143LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001144unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001145
Gregory Szorc34c863a2012-03-21 03:54:29 +00001146/**
1147 * @}
1148 */
1149
1150/**
1151 * @defgroup LLVMCCoreTypeFloat Floating Point Types
1152 *
1153 * @{
1154 */
1155
1156/**
1157 * Obtain a 16-bit floating point type from a context.
1158 */
Dan Gohman518cda42011-12-17 00:04:22 +00001159LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001160
1161/**
1162 * Obtain a 32-bit floating point type from a context.
1163 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001164LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001165
1166/**
1167 * Obtain a 64-bit floating point type from a context.
1168 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001169LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001170
1171/**
1172 * Obtain a 80-bit floating point type (X87) from a context.
1173 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001174LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001175
1176/**
1177 * Obtain a 128-bit floating point type (112-bit mantissa) from a
1178 * context.
1179 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001180LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001181
1182/**
1183 * Obtain a 128-bit floating point type (two 64-bits) from a context.
1184 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001185LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
1186
Gregory Szorc34c863a2012-03-21 03:54:29 +00001187/**
1188 * Obtain a floating point type from the global context.
1189 *
1190 * These map to the functions in this group of the same name.
1191 */
Dan Gohman518cda42011-12-17 00:04:22 +00001192LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001193LLVMTypeRef LLVMFloatType(void);
1194LLVMTypeRef LLVMDoubleType(void);
1195LLVMTypeRef LLVMX86FP80Type(void);
1196LLVMTypeRef LLVMFP128Type(void);
1197LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001198
Gregory Szorc34c863a2012-03-21 03:54:29 +00001199/**
1200 * @}
1201 */
1202
1203/**
1204 * @defgroup LLVMCCoreTypeFunction Function Types
1205 *
1206 * @{
1207 */
1208
1209/**
1210 * Obtain a function type consisting of a specified signature.
1211 *
1212 * The function is defined as a tuple of a return Type, a list of
1213 * parameter types, and whether the function is variadic.
1214 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001215LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
1216 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001217 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001218
1219/**
1220 * Returns whether a function type is variadic.
1221 */
Chris Lattner25963c62010-01-09 22:27:07 +00001222LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001223
1224/**
1225 * Obtain the Type this function Type returns.
1226 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001227LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001228
1229/**
1230 * Obtain the number of parameters this function accepts.
1231 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001232unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001233
1234/**
1235 * Obtain the types of a function's parameters.
1236 *
1237 * The Dest parameter should point to a pre-allocated array of
1238 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
1239 * first LLVMCountParamTypes() entries in the array will be populated
1240 * with LLVMTypeRef instances.
1241 *
1242 * @param FunctionTy The function type to operate on.
1243 * @param Dest Memory address of an array to be filled with result.
1244 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001245void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001246
Gregory Szorc34c863a2012-03-21 03:54:29 +00001247/**
1248 * @}
1249 */
1250
1251/**
1252 * @defgroup LLVMCCoreTypeStruct Structure Types
1253 *
1254 * These functions relate to LLVMTypeRef instances.
1255 *
1256 * @see llvm::StructType
1257 *
1258 * @{
1259 */
1260
1261/**
1262 * Create a new structure type in a context.
1263 *
1264 * A structure is specified by a list of inner elements/types and
1265 * whether these can be packed together.
1266 *
1267 * @see llvm::StructType::create()
1268 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001269LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +00001270 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001271
1272/**
1273 * Create a new structure type in the global context.
1274 *
1275 * @see llvm::StructType::create()
1276 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001277LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001278 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001279
1280/**
1281 * Create an empty structure in a context having a specified name.
1282 *
1283 * @see llvm::StructType::create()
1284 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001285LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001286
1287/**
1288 * Obtain the name of a structure.
1289 *
1290 * @see llvm::StructType::getName()
1291 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +00001292const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001293
1294/**
1295 * Set the contents of a structure type.
1296 *
1297 * @see llvm::StructType::setBody()
1298 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001299void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
1300 unsigned ElementCount, LLVMBool Packed);
1301
Gregory Szorc34c863a2012-03-21 03:54:29 +00001302/**
1303 * Get the number of elements defined inside the structure.
1304 *
1305 * @see llvm::StructType::getNumElements()
1306 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001307unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001308
1309/**
1310 * Get the elements within a structure.
1311 *
1312 * The function is passed the address of a pre-allocated array of
1313 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
1314 * invocation, this array will be populated with the structure's
1315 * elements. The objects in the destination array will have a lifetime
1316 * of the structure type itself, which is the lifetime of the context it
1317 * is contained in.
1318 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001319void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001320
1321/**
Peter Zotovc164a3f2015-06-04 09:09:53 +00001322 * Get the type of the element at a given index in the structure.
1323 *
1324 * @see llvm::StructType::getTypeAtIndex()
1325 */
1326LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
1327
1328/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001329 * Determine whether a structure is packed.
1330 *
1331 * @see llvm::StructType::isPacked()
1332 */
Chris Lattner25963c62010-01-09 22:27:07 +00001333LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001334
1335/**
1336 * Determine whether a structure is opaque.
1337 *
1338 * @see llvm::StructType::isOpaque()
1339 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001340LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1341
Gregory Szorc34c863a2012-03-21 03:54:29 +00001342/**
whitequarkb4861072018-09-18 01:47:37 +00001343 * Determine whether a structure is literal.
1344 *
1345 * @see llvm::StructType::isLiteral()
1346 */
1347LLVMBool LLVMIsLiteralStruct(LLVMTypeRef StructTy);
1348
1349/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001350 * @}
1351 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001352
Gregory Szorc34c863a2012-03-21 03:54:29 +00001353/**
1354 * @defgroup LLVMCCoreTypeSequential Sequential Types
1355 *
1356 * Sequential types represents "arrays" of types. This is a super class
1357 * for array, vector, and pointer types.
1358 *
1359 * @{
1360 */
1361
1362/**
1363 * Obtain the type of elements within a sequential type.
1364 *
1365 * This works on array, vector, and pointer types.
1366 *
1367 * @see llvm::SequentialType::getElementType()
1368 */
1369LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1370
1371/**
whitequarkf6059fd2017-06-05 11:49:52 +00001372 * Returns type's subtypes
1373 *
1374 * @see llvm::Type::subtypes()
1375 */
1376void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr);
1377
1378/**
1379 * Return the number of types in the derived type.
1380 *
1381 * @see llvm::Type::getNumContainedTypes()
1382 */
1383unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp);
1384
1385/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001386 * Create a fixed size array type that refers to a specific type.
1387 *
1388 * The created type will exist in the context that its element type
1389 * exists in.
1390 *
1391 * @see llvm::ArrayType::get()
1392 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001393LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001394
1395/**
1396 * Obtain the length of an array type.
1397 *
1398 * This only works on types that represent arrays.
1399 *
1400 * @see llvm::ArrayType::getNumElements()
1401 */
1402unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1403
1404/**
1405 * Create a pointer type that points to a defined type.
1406 *
1407 * The created type will exist in the context that its pointee type
1408 * exists in.
1409 *
1410 * @see llvm::PointerType::get()
1411 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001412LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001413
1414/**
1415 * Obtain the address space of a pointer type.
1416 *
1417 * This only works on types that represent pointers.
1418 *
1419 * @see llvm::PointerType::getAddressSpace()
1420 */
1421unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1422
1423/**
1424 * Create a vector type that contains a defined type and has a specific
1425 * number of elements.
1426 *
1427 * The created type will exist in the context thats its element type
1428 * exists in.
1429 *
1430 * @see llvm::VectorType::get()
1431 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001432LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001433
Gregory Szorc34c863a2012-03-21 03:54:29 +00001434/**
1435 * Obtain the number of elements in a vector type.
1436 *
1437 * This only works on types that represent vectors.
1438 *
1439 * @see llvm::VectorType::getNumElements()
1440 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001441unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1442
Gregory Szorc34c863a2012-03-21 03:54:29 +00001443/**
1444 * @}
1445 */
1446
1447/**
1448 * @defgroup LLVMCCoreTypeOther Other Types
1449 *
1450 * @{
1451 */
1452
1453/**
1454 * Create a void type in a context.
1455 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001456LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001457
1458/**
1459 * Create a label type in a context.
1460 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001461LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001462
1463/**
1464 * Create a X86 MMX type in a context.
1465 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001466LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001467
Gregory Szorc34c863a2012-03-21 03:54:29 +00001468/**
whitequark131f98f2017-10-27 11:51:40 +00001469 * Create a token type in a context.
1470 */
1471LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C);
1472
1473/**
1474 * Create a metadata type in a context.
1475 */
1476LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C);
1477
1478/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001479 * These are similar to the above functions except they operate on the
1480 * global context.
1481 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001482LLVMTypeRef LLVMVoidType(void);
1483LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001484LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001485
Gregory Szorc34c863a2012-03-21 03:54:29 +00001486/**
1487 * @}
1488 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001489
Gregory Szorc34c863a2012-03-21 03:54:29 +00001490/**
1491 * @}
1492 */
1493
1494/**
1495 * @defgroup LLVMCCoreValues Values
1496 *
1497 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001498 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001499 *
1500 * LLVMValueRef essentially represents llvm::Value. There is a rich
1501 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001502 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001503 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001504 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001505 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1506 * functions are defined by a macro, so it isn't obvious which are
1507 * available by looking at the Doxygen source code. Instead, look at the
1508 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1509 * of value names given. These value names also correspond to classes in
1510 * the llvm::Value hierarchy.
1511 *
1512 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001513 */
1514
Gordon Henriksen29e38942008-12-19 18:39:45 +00001515#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1516 macro(Argument) \
1517 macro(BasicBlock) \
1518 macro(InlineAsm) \
1519 macro(User) \
1520 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001521 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001522 macro(ConstantAggregateZero) \
1523 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001524 macro(ConstantDataSequential) \
1525 macro(ConstantDataArray) \
1526 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001527 macro(ConstantExpr) \
1528 macro(ConstantFP) \
1529 macro(ConstantInt) \
1530 macro(ConstantPointerNull) \
1531 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001532 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001533 macro(ConstantVector) \
1534 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001535 macro(GlobalAlias) \
whitequarkd299b2c2018-09-18 00:01:12 +00001536 macro(GlobalIFunc) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001537 macro(GlobalObject) \
1538 macro(Function) \
1539 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001540 macro(UndefValue) \
1541 macro(Instruction) \
1542 macro(BinaryOperator) \
1543 macro(CallInst) \
1544 macro(IntrinsicInst) \
1545 macro(DbgInfoIntrinsic) \
Hsiangkai Wangef72e482018-08-06 03:59:47 +00001546 macro(DbgVariableIntrinsic) \
1547 macro(DbgDeclareInst) \
1548 macro(DbgLabelInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001549 macro(MemIntrinsic) \
1550 macro(MemCpyInst) \
1551 macro(MemMoveInst) \
1552 macro(MemSetInst) \
1553 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001554 macro(FCmpInst) \
1555 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001556 macro(ExtractElementInst) \
1557 macro(GetElementPtrInst) \
1558 macro(InsertElementInst) \
1559 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001560 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001561 macro(PHINode) \
1562 macro(SelectInst) \
1563 macro(ShuffleVectorInst) \
1564 macro(StoreInst) \
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00001565 macro(BranchInst) \
1566 macro(IndirectBrInst) \
1567 macro(InvokeInst) \
1568 macro(ReturnInst) \
1569 macro(SwitchInst) \
1570 macro(UnreachableInst) \
1571 macro(ResumeInst) \
1572 macro(CleanupReturnInst) \
1573 macro(CatchReturnInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001574 macro(FuncletPadInst) \
1575 macro(CatchPadInst) \
1576 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001577 macro(UnaryInstruction) \
1578 macro(AllocaInst) \
1579 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001580 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001581 macro(BitCastInst) \
1582 macro(FPExtInst) \
1583 macro(FPToSIInst) \
1584 macro(FPToUIInst) \
1585 macro(FPTruncInst) \
1586 macro(IntToPtrInst) \
1587 macro(PtrToIntInst) \
1588 macro(SExtInst) \
1589 macro(SIToFPInst) \
1590 macro(TruncInst) \
1591 macro(UIToFPInst) \
1592 macro(ZExtInst) \
1593 macro(ExtractValueInst) \
1594 macro(LoadInst) \
1595 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001596
Gregory Szorc34c863a2012-03-21 03:54:29 +00001597/**
1598 * @defgroup LLVMCCoreValueGeneral General APIs
1599 *
1600 * Functions in this section work on all LLVMValueRef instances,
1601 * regardless of their sub-type. They correspond to functions available
1602 * on llvm::Value.
1603 *
1604 * @{
1605 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001606
Gregory Szorc34c863a2012-03-21 03:54:29 +00001607/**
1608 * Obtain the type of a value.
1609 *
1610 * @see llvm::Value::getType()
1611 */
1612LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1613
1614/**
Peter Zotov3e4561c2016-04-06 22:21:29 +00001615 * Obtain the enumerated type of a Value instance.
1616 *
1617 * @see llvm::Value::getValueID()
1618 */
1619LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
1620
1621/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001622 * Obtain the string name of a value.
1623 *
1624 * @see llvm::Value::getName()
1625 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001626const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001627
1628/**
1629 * Set the string name of a value.
1630 *
1631 * @see llvm::Value::setName()
1632 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001633void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001634
1635/**
1636 * Dump a representation of a value to stderr.
1637 *
1638 * @see llvm::Value::dump()
1639 */
1640void LLVMDumpValue(LLVMValueRef Val);
1641
1642/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001643 * Return a string representation of the value. Use
1644 * LLVMDisposeMessage to free the string.
1645 *
1646 * @see llvm::Value::print()
1647 */
1648char *LLVMPrintValueToString(LLVMValueRef Val);
1649
1650/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001651 * Replace all uses of a value with another one.
1652 *
1653 * @see llvm::Value::replaceAllUsesWith()
1654 */
1655void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1656
1657/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001658 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001659 */
1660LLVMBool LLVMIsConstant(LLVMValueRef Val);
1661
1662/**
1663 * Determine whether a value instance is undefined.
1664 */
1665LLVMBool LLVMIsUndef(LLVMValueRef Val);
1666
1667/**
1668 * Convert value instances between types.
1669 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001670 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001671 * series of functions allows you to cast an instance to a specific
1672 * type.
1673 *
1674 * If the cast is not valid for the specified type, NULL is returned.
1675 *
1676 * @see llvm::dyn_cast_or_null<>
1677 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001678#define LLVM_DECLARE_VALUE_CAST(name) \
1679 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1680LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1681
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001682LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1683LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1684
Robert Widmann025c78f2018-05-19 15:08:36 +00001685/** Deprecated: Use LLVMGetValueName2 instead. */
1686const char *LLVMGetValueName(LLVMValueRef Val);
1687/** Deprecated: Use LLVMSetValueName2 instead. */
1688void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1689
Gregory Szorc34c863a2012-03-21 03:54:29 +00001690/**
1691 * @}
1692 */
1693
1694/**
1695 * @defgroup LLVMCCoreValueUses Usage
1696 *
1697 * This module defines functions that allow you to inspect the uses of a
1698 * LLVMValueRef.
1699 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001700 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001701 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1702 * llvm::User and llvm::Value.
1703 *
1704 * @{
1705 */
1706
1707/**
1708 * Obtain the first use of a value.
1709 *
1710 * Uses are obtained in an iterator fashion. First, call this function
1711 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001712 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001713 * LLVMGetNextUse() returns NULL.
1714 *
1715 * @see llvm::Value::use_begin()
1716 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001717LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001718
1719/**
1720 * Obtain the next use of a value.
1721 *
1722 * This effectively advances the iterator. It returns NULL if you are on
1723 * the final use and no more are available.
1724 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001725LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001726
1727/**
1728 * Obtain the user value for a user.
1729 *
1730 * The returned value corresponds to a llvm::User type.
1731 *
1732 * @see llvm::Use::getUser()
1733 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001734LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001735
1736/**
1737 * Obtain the value this use corresponds to.
1738 *
1739 * @see llvm::Use::get().
1740 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001741LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001742
Gregory Szorc34c863a2012-03-21 03:54:29 +00001743/**
1744 * @}
1745 */
1746
1747/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001748 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001749 *
1750 * Function in this group pertain to LLVMValueRef instances that descent
1751 * from llvm::User. This includes constants, instructions, and
1752 * operators.
1753 *
1754 * @{
1755 */
1756
1757/**
1758 * Obtain an operand at a specific index in a llvm::User value.
1759 *
1760 * @see llvm::User::getOperand()
1761 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001762LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001763
1764/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001765 * Obtain the use of an operand at a specific index in a llvm::User value.
1766 *
1767 * @see llvm::User::getOperandUse()
1768 */
1769LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1770
1771/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001772 * Set an operand at a specific index in a llvm::User value.
1773 *
1774 * @see llvm::User::setOperand()
1775 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001776void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001777
1778/**
1779 * Obtain the number of operands in a llvm::User value.
1780 *
1781 * @see llvm::User::getNumOperands()
1782 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001783int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001784
Gregory Szorc34c863a2012-03-21 03:54:29 +00001785/**
1786 * @}
1787 */
1788
1789/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001790 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001791 *
1792 * This section contains APIs for interacting with LLVMValueRef that
1793 * correspond to llvm::Constant instances.
1794 *
1795 * These functions will work for any LLVMValueRef in the llvm::Constant
1796 * class hierarchy.
1797 *
1798 * @{
1799 */
1800
1801/**
1802 * Obtain a constant value referring to the null instance of a type.
1803 *
1804 * @see llvm::Constant::getNullValue()
1805 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001806LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001807
1808/**
1809 * Obtain a constant value referring to the instance of a type
1810 * consisting of all ones.
1811 *
1812 * This is only valid for integer types.
1813 *
1814 * @see llvm::Constant::getAllOnesValue()
1815 */
1816LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1817
1818/**
1819 * Obtain a constant value referring to an undefined value of a type.
1820 *
1821 * @see llvm::UndefValue::get()
1822 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001823LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001824
1825/**
1826 * Determine whether a value instance is null.
1827 *
1828 * @see llvm::Constant::isNullValue()
1829 */
Chris Lattner25963c62010-01-09 22:27:07 +00001830LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001831
1832/**
1833 * Obtain a constant that is a constant pointer pointing to NULL for a
1834 * specified type.
1835 */
Chris Lattner7f318242009-07-06 17:29:59 +00001836LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001837
Gregory Szorc34c863a2012-03-21 03:54:29 +00001838/**
1839 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1840 *
1841 * Functions in this group model LLVMValueRef instances that correspond
1842 * to constants referring to scalar types.
1843 *
1844 * For integer types, the LLVMTypeRef parameter should correspond to a
1845 * llvm::IntegerType instance and the returned LLVMValueRef will
1846 * correspond to a llvm::ConstantInt.
1847 *
1848 * For floating point types, the LLVMTypeRef returned corresponds to a
1849 * llvm::ConstantFP.
1850 *
1851 * @{
1852 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001853
Gregory Szorc34c863a2012-03-21 03:54:29 +00001854/**
1855 * Obtain a constant value for an integer type.
1856 *
1857 * The returned value corresponds to a llvm::ConstantInt.
1858 *
1859 * @see llvm::ConstantInt::get()
1860 *
1861 * @param IntTy Integer type to obtain value of.
1862 * @param N The value the returned instance should refer to.
1863 * @param SignExtend Whether to sign extend the produced value.
1864 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001865LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001866 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001867
1868/**
1869 * Obtain a constant value for an integer of arbitrary precision.
1870 *
1871 * @see llvm::ConstantInt::get()
1872 */
Chris Lattner4329e072010-11-23 02:47:22 +00001873LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1874 unsigned NumWords,
1875 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001876
1877/**
1878 * Obtain a constant value for an integer parsed from a string.
1879 *
1880 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1881 * string's length is available, it is preferred to call that function
1882 * instead.
1883 *
1884 * @see llvm::ConstantInt::get()
1885 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001886LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1887 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001888
1889/**
1890 * Obtain a constant value for an integer parsed from a string with
1891 * specified length.
1892 *
1893 * @see llvm::ConstantInt::get()
1894 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001895LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1896 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001897
1898/**
1899 * Obtain a constant value referring to a double floating point value.
1900 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001901LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001902
1903/**
1904 * Obtain a constant for a floating point value parsed from a string.
1905 *
1906 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1907 * should be used if the input string's length is known.
1908 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001909LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001910
1911/**
1912 * Obtain a constant for a floating point value parsed from a string.
1913 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001914LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1915 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001916
1917/**
1918 * Obtain the zero extended value for an integer constant value.
1919 *
1920 * @see llvm::ConstantInt::getZExtValue()
1921 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001922unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001923
1924/**
1925 * Obtain the sign extended value for an integer constant value.
1926 *
1927 * @see llvm::ConstantInt::getSExtValue()
1928 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001929long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001930
Gregory Szorc34c863a2012-03-21 03:54:29 +00001931/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001932 * Obtain the double value for an floating point constant value.
1933 * losesInfo indicates if some precision was lost in the conversion.
1934 *
1935 * @see llvm::ConstantFP::getDoubleValue
1936 */
1937double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1938
1939/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001940 * @}
1941 */
1942
1943/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001944 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1945 *
1946 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001947 *
1948 * @{
1949 */
1950
1951/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001952 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001953 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001954 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001955 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001956LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001957 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001958
1959/**
1960 * Create a ConstantDataSequential with string content in the global context.
1961 *
1962 * This is the same as LLVMConstStringInContext except it operates on the
1963 * global context.
1964 *
1965 * @see LLVMConstStringInContext()
1966 * @see llvm::ConstantDataArray::getString()
1967 */
1968LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1969 LLVMBool DontNullTerminate);
1970
1971/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001972 * Returns true if the specified constant is an array of i8.
1973 *
1974 * @see ConstantDataSequential::getAsString()
1975 */
1976LLVMBool LLVMIsConstantString(LLVMValueRef c);
1977
1978/**
1979 * Get the given constant data sequential as a string.
1980 *
1981 * @see ConstantDataSequential::getAsString()
1982 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00001983const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001984
1985/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001986 * Create an anonymous ConstantStruct with the specified values.
1987 *
1988 * @see llvm::ConstantStruct::getAnon()
1989 */
1990LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001991 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001992 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001993
Gregory Szorc52d26602012-03-21 07:28:27 +00001994/**
1995 * Create a ConstantStruct in the global Context.
1996 *
1997 * This is the same as LLVMConstStructInContext except it operates on the
1998 * global Context.
1999 *
2000 * @see LLVMConstStructInContext()
2001 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002002LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00002003 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00002004
2005/**
2006 * Create a ConstantArray from values.
2007 *
2008 * @see llvm::ConstantArray::get()
2009 */
2010LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
2011 LLVMValueRef *ConstantVals, unsigned Length);
2012
2013/**
2014 * Create a non-anonymous ConstantStruct from values.
2015 *
2016 * @see llvm::ConstantStruct::get()
2017 */
Rafael Espindola784ad242011-07-14 19:09:08 +00002018LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
2019 LLVMValueRef *ConstantVals,
2020 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00002021
2022/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00002023 * Get an element at specified index as a constant.
2024 *
2025 * @see ConstantDataSequential::getElementAsConstant()
2026 */
Amaury Sechet006ce632016-03-13 00:54:40 +00002027LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
Peter Zotovf9aa8822014-08-03 23:54:16 +00002028
2029/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002030 * Create a ConstantVector from values.
2031 *
2032 * @see llvm::ConstantVector::get()
2033 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002034LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002035
Gregory Szorc52d26602012-03-21 07:28:27 +00002036/**
2037 * @}
2038 */
2039
2040/**
2041 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
2042 *
2043 * Functions in this group correspond to APIs on llvm::ConstantExpr.
2044 *
2045 * @see llvm::ConstantExpr.
2046 *
2047 * @{
2048 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002049LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002050LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002051LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
2052LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002053LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
2054LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002055LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002056LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
2057LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002058LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002059LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002060LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002061LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002062LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2063LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002064LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002065LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002066LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2067LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002068LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002069LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Manuel Jacob49fafb12016-10-04 23:32:42 +00002070LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002071LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002072LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002073LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2074LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2075LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2076LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2077LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2078LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2079LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2080LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
2081 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2082LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
2083 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2084LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2085LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2086LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2087LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
2088 LLVMValueRef *ConstantIndices, unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002089LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2090 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002091LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
2092 LLVMValueRef *ConstantIndices,
2093 unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002094LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2095 LLVMValueRef *ConstantIndices,
2096 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002097LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2098LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2099LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2100LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2101LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2102LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2103LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2104LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2105LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2106LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2107LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2108LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002109LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002110LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
2111 LLVMTypeRef ToType);
2112LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
2113 LLVMTypeRef ToType);
2114LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
2115 LLVMTypeRef ToType);
2116LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
2117 LLVMTypeRef ToType);
2118LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00002119 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002120LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002121LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
2122 LLVMValueRef ConstantIfTrue,
2123 LLVMValueRef ConstantIfFalse);
2124LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
2125 LLVMValueRef IndexConstant);
2126LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
2127 LLVMValueRef ElementValueConstant,
2128 LLVMValueRef IndexConstant);
2129LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
2130 LLVMValueRef VectorBConstant,
2131 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00002132LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
2133 unsigned NumIdx);
2134LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
2135 LLVMValueRef ElementValueConstant,
2136 unsigned *IdxList, unsigned NumIdx);
Robert Widmannf108d572018-04-06 02:31:29 +00002137LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
2138
2139/** Deprecated: Use LLVMGetInlineAsm instead. */
Chris Lattner25963c62010-01-09 22:27:07 +00002140LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00002141 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00002142 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002143
Gregory Szorc52d26602012-03-21 07:28:27 +00002144/**
2145 * @}
2146 */
2147
2148/**
2149 * @defgroup LLVMCCoreValueConstantGlobals Global Values
2150 *
2151 * This group contains functions that operate on global values. Functions in
2152 * this group relate to functions in the llvm::GlobalValue class tree.
2153 *
2154 * @see llvm::GlobalValue
2155 *
2156 * @{
2157 */
2158
Gordon Henriksen265f7802008-03-19 01:11:35 +00002159LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00002160LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002161LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
2162void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
2163const char *LLVMGetSection(LLVMValueRef Global);
2164void LLVMSetSection(LLVMValueRef Global, const char *Section);
2165LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
2166void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00002167LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
2168void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002169LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
2170void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
2171
Robert Widmanne63a12c2018-09-28 20:54:29 +00002172/**
2173 * Returns the "value type" of a global value. This differs from the formal
2174 * type of a global value which is always a pointer type.
2175 *
2176 * @see llvm::GlobalValue::getValueType()
2177 */
2178LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
2179
Robert Widmann4bb481b2018-03-14 06:45:51 +00002180/** Deprecated: Use LLVMGetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002181LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002182/** Deprecated: Use LLVMSetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002183void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002184
2185/**
2186 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
2187 *
2188 * Functions in this group only apply to values with alignment, i.e.
2189 * global variables, load and store instructions.
2190 */
2191
2192/**
2193 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002194 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002195 * @see llvm::LoadInst::getAlignment()
2196 * @see llvm::StoreInst::getAlignment()
2197 * @see llvm::GlobalValue::getAlignment()
2198 */
2199unsigned LLVMGetAlignment(LLVMValueRef V);
2200
2201/**
2202 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002203 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002204 * @see llvm::LoadInst::setAlignment()
2205 * @see llvm::StoreInst::setAlignment()
2206 * @see llvm::GlobalValue::setAlignment()
2207 */
2208void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
2209
2210/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00002211 * Sets a metadata attachment, erasing the existing metadata attachment if
2212 * it already exists for the given kind.
2213 *
2214 * @see llvm::GlobalObject::setMetadata()
2215 */
2216void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind,
2217 LLVMMetadataRef MD);
2218
2219/**
2220 * Erases a metadata attachment of the given kind if it exists.
2221 *
2222 * @see llvm::GlobalObject::eraseMetadata()
2223 */
2224void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind);
2225
2226/**
2227 * Removes all metadata attachments from this value.
2228 *
2229 * @see llvm::GlobalObject::clearMetadata()
2230 */
2231void LLVMGlobalClearMetadata(LLVMValueRef Global);
2232
2233/**
2234 * Retrieves an array of metadata entries representing the metadata attached to
2235 * this value. The caller is responsible for freeing this array by calling
2236 * \c LLVMDisposeValueMetadataEntries.
2237 *
2238 * @see llvm::GlobalObject::getAllMetadata()
2239 */
2240LLVMValueMetadataEntry *LLVMGlobalCopyAllMetadata(LLVMValueRef Value,
2241 size_t *NumEntries);
2242
2243/**
2244 * Destroys value metadata entries.
2245 */
2246void LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries);
2247
2248/**
2249 * Returns the kind of a value metadata entry at a specific index.
2250 */
2251unsigned LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries,
2252 unsigned Index);
2253
2254/**
2255 * Returns the underlying metadata node of a value metadata entry at a
2256 * specific index.
2257 */
2258LLVMMetadataRef
2259LLVMValueMetadataEntriesGetMetadata(LLVMValueMetadataEntry *Entries,
2260 unsigned Index);
2261
2262/**
Amaury Sechet83550102016-02-14 08:58:49 +00002263 * @}
2264 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002265
Gregory Szorc52d26602012-03-21 07:28:27 +00002266/**
2267 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
2268 *
2269 * This group contains functions that operate on global variable values.
2270 *
2271 * @see llvm::GlobalVariable
2272 *
2273 * @{
2274 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002275LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00002276LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
2277 const char *Name,
2278 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00002279LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002280LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
2281LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
2282LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
2283LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002284void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002285LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
2286void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00002287LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
2288void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
2289LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
2290void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00002291LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
2292void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
2293LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
2294void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002295
Gregory Szorc52d26602012-03-21 07:28:27 +00002296/**
2297 * @}
2298 */
2299
2300/**
2301 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
2302 *
2303 * This group contains function that operate on global alias values.
2304 *
2305 * @see llvm::GlobalAlias
2306 *
2307 * @{
2308 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00002309LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
2310 const char *Name);
2311
Gregory Szorc34c863a2012-03-21 03:54:29 +00002312/**
Robert Widmann360d6e32018-05-20 23:49:08 +00002313 * Obtain a GlobalAlias value from a Module by its name.
2314 *
2315 * The returned value corresponds to a llvm::GlobalAlias value.
2316 *
2317 * @see llvm::Module::getNamedAlias()
2318 */
2319LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M,
2320 const char *Name, size_t NameLen);
2321
2322/**
2323 * Obtain an iterator to the first GlobalAlias in a Module.
2324 *
2325 * @see llvm::Module::alias_begin()
2326 */
2327LLVMValueRef LLVMGetFirstGlobalAlias(LLVMModuleRef M);
2328
2329/**
2330 * Obtain an iterator to the last GlobalAlias in a Module.
2331 *
2332 * @see llvm::Module::alias_end()
2333 */
2334LLVMValueRef LLVMGetLastGlobalAlias(LLVMModuleRef M);
2335
2336/**
2337 * Advance a GlobalAlias iterator to the next GlobalAlias.
2338 *
2339 * Returns NULL if the iterator was already at the end and there are no more
2340 * global aliases.
2341 */
2342LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA);
2343
2344/**
2345 * Decrement a GlobalAlias iterator to the previous GlobalAlias.
2346 *
2347 * Returns NULL if the iterator was already at the beginning and there are
2348 * no previous global aliases.
2349 */
2350LLVMValueRef LLVMGetPreviousGlobalAlias(LLVMValueRef GA);
2351
2352/**
2353 * Retrieve the target value of an alias.
2354 */
2355LLVMValueRef LLVMAliasGetAliasee(LLVMValueRef Alias);
2356
2357/**
2358 * Set the target value of an alias.
2359 */
2360void LLVMAliasSetAliasee(LLVMValueRef Alias, LLVMValueRef Aliasee);
2361
2362/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002363 * @}
2364 */
2365
2366/**
2367 * @defgroup LLVMCCoreValueFunction Function values
2368 *
2369 * Functions in this group operate on LLVMValueRef instances that
2370 * correspond to llvm::Function instances.
2371 *
2372 * @see llvm::Function
2373 *
2374 * @{
2375 */
2376
2377/**
2378 * Remove a function from its containing module and deletes it.
2379 *
2380 * @see llvm::Function::eraseFromParent()
2381 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002382void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002383
2384/**
Amaury Sechete39e8532016-02-18 20:38:32 +00002385 * Check whether the given function has a personality function.
2386 *
2387 * @see llvm::Function::hasPersonalityFn()
2388 */
2389LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
2390
2391/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00002392 * Obtain the personality function attached to the function.
2393 *
2394 * @see llvm::Function::getPersonalityFn()
2395 */
2396LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
2397
2398/**
2399 * Set the personality function attached to the function.
2400 *
2401 * @see llvm::Function::setPersonalityFn()
2402 */
2403void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
2404
2405/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002406 * Obtain the ID number from a function instance.
2407 *
2408 * @see llvm::Function::getIntrinsicID()
2409 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002410unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002411
2412/**
Robert Widmannd36f3b02018-11-06 01:38:14 +00002413 * Create or insert the declaration of an intrinsic. For overloaded intrinsics,
2414 * parameter types must be provided to uniquely identify an overload.
2415 *
2416 * @see llvm::Intrinsic::getDeclaration()
2417 */
2418LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
2419 unsigned ID,
2420 LLVMTypeRef *ParamTypes,
2421 size_t ParamCount);
2422
2423/**
2424 * Retrieves the type of an intrinsic. For overloaded intrinsics, parameter
2425 * types must be provided to uniquely identify an overload.
2426 *
2427 * @see llvm::Intrinsic::getType()
2428 */
2429LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID,
2430 LLVMTypeRef *ParamTypes, size_t ParamCount);
2431
2432/**
2433 * Retrieves the name of an intrinsic.
2434 *
2435 * @see llvm::Intrinsic::getName()
2436 */
2437const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength);
2438
2439/**
2440 * Copies the name of an overloaded intrinsic identified by a given list of
2441 * parameter types.
2442 *
2443 * Unlike LLVMIntrinsicGetName, the caller is responsible for freeing the
2444 * returned string.
2445 *
2446 * @see llvm::Intrinsic::getName()
2447 */
2448const char *LLVMIntrinsicCopyOverloadedName(unsigned ID,
2449 LLVMTypeRef *ParamTypes,
2450 size_t ParamCount,
2451 size_t *NameLength);
2452
2453/**
2454 * Obtain if the intrinsic identified by the given ID is overloaded.
2455 *
2456 * @see llvm::Intrinsic::isOverloaded()
2457 */
2458LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID);
2459
2460/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002461 * Obtain the calling function of a function.
2462 *
2463 * The returned value corresponds to the LLVMCallConv enumeration.
2464 *
2465 * @see llvm::Function::getCallingConv()
2466 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002467unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002468
2469/**
2470 * Set the calling convention of a function.
2471 *
2472 * @see llvm::Function::setCallingConv()
2473 *
2474 * @param Fn Function to operate on
2475 * @param CC LLVMCallConv to set calling convention to
2476 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002477void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002478
2479/**
2480 * Obtain the name of the garbage collector to use during code
2481 * generation.
2482 *
2483 * @see llvm::Function::getGC()
2484 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002485const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002486
2487/**
2488 * Define the garbage collector to use during code generation.
2489 *
2490 * @see llvm::Function::setGC()
2491 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002492void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002493
2494/**
2495 * Add an attribute to a function.
2496 *
2497 * @see llvm::Function::addAttribute()
2498 */
Amaury Sechet5db224e2016-06-12 06:17:24 +00002499void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2500 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00002501unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx);
2502void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2503 LLVMAttributeRef *Attrs);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002504LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
2505 LLVMAttributeIndex Idx,
2506 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002507LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
2508 LLVMAttributeIndex Idx,
2509 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002510void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2511 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002512void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2513 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002514
Gregory Szorc34c863a2012-03-21 03:54:29 +00002515/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00002516 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00002517 * @see llvm::AttrBuilder::addAttribute()
2518 */
2519void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
2520 const char *V);
2521
2522/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002523 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
2524 *
2525 * Functions in this group relate to arguments/parameters on functions.
2526 *
2527 * Functions in this group expect LLVMValueRef instances that correspond
2528 * to llvm::Function instances.
2529 *
2530 * @{
2531 */
2532
2533/**
2534 * Obtain the number of parameters in a function.
2535 *
2536 * @see llvm::Function::arg_size()
2537 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002538unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002539
2540/**
2541 * Obtain the parameters in a function.
2542 *
2543 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
2544 * at least LLVMCountParams() long. This array will be filled with
2545 * LLVMValueRef instances which correspond to the parameters the
2546 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
2547 * instance.
2548 *
2549 * @see llvm::Function::arg_begin()
2550 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002551void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002552
2553/**
2554 * Obtain the parameter at the specified index.
2555 *
2556 * Parameters are indexed from 0.
2557 *
2558 * @see llvm::Function::arg_begin()
2559 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002560LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002561
2562/**
2563 * Obtain the function to which this argument belongs.
2564 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002565 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002566 * that corresponds to a llvm::Attribute.
2567 *
2568 * The returned LLVMValueRef is the llvm::Function to which this
2569 * argument belongs.
2570 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002571LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002572
2573/**
2574 * Obtain the first parameter to a function.
2575 *
2576 * @see llvm::Function::arg_begin()
2577 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002578LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002579
2580/**
2581 * Obtain the last parameter to a function.
2582 *
2583 * @see llvm::Function::arg_end()
2584 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002585LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002586
2587/**
2588 * Obtain the next parameter to a function.
2589 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002590 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002591 * actually a wrapped iterator) and obtains the next parameter from the
2592 * underlying iterator.
2593 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002594LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002595
2596/**
2597 * Obtain the previous parameter to a function.
2598 *
2599 * This is the opposite of LLVMGetNextParam().
2600 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002601LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002602
2603/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002604 * Set the alignment for a function parameter.
2605 *
2606 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002607 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002608 */
Amaury Sechet81243a72016-05-01 01:42:34 +00002609void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002610
Gregory Szorc34c863a2012-03-21 03:54:29 +00002611/**
2612 * @}
2613 */
2614
2615/**
Robert Widmannd5444cc2019-02-05 18:05:44 +00002616 * @defgroup LLVMCCoreValueGlobalIFunc IFuncs
2617 *
2618 * Functions in this group relate to indirect functions.
2619 *
2620 * Functions in this group expect LLVMValueRef instances that correspond
2621 * to llvm::GlobalIFunc instances.
2622 *
2623 * @{
2624 */
2625
2626/**
2627 * Add a global indirect function to a module under a specified name.
2628 *
2629 * @see llvm::GlobalIFunc::create()
2630 */
2631LLVMValueRef LLVMAddGlobalIFunc(LLVMModuleRef M,
2632 const char *Name, size_t NameLen,
2633 LLVMTypeRef Ty, unsigned AddrSpace,
2634 LLVMValueRef Resolver);
2635
2636/**
2637 * Obtain a GlobalIFunc value from a Module by its name.
2638 *
2639 * The returned value corresponds to a llvm::GlobalIFunc value.
2640 *
2641 * @see llvm::Module::getNamedIFunc()
2642 */
2643LLVMValueRef LLVMGetNamedGlobalIFunc(LLVMModuleRef M,
2644 const char *Name, size_t NameLen);
2645
2646/**
2647 * Obtain an iterator to the first GlobalIFunc in a Module.
2648 *
2649 * @see llvm::Module::ifunc_begin()
2650 */
2651LLVMValueRef LLVMGetFirstGlobalIFunc(LLVMModuleRef M);
2652
2653/**
2654 * Obtain an iterator to the last GlobalIFunc in a Module.
2655 *
2656 * @see llvm::Module::ifunc_end()
2657 */
2658LLVMValueRef LLVMGetLastGlobalIFunc(LLVMModuleRef M);
2659
2660/**
2661 * Advance a GlobalIFunc iterator to the next GlobalIFunc.
2662 *
2663 * Returns NULL if the iterator was already at the end and there are no more
2664 * global aliases.
2665 */
2666LLVMValueRef LLVMGetNextGlobalIFunc(LLVMValueRef IFunc);
2667
2668/**
2669 * Decrement a GlobalIFunc iterator to the previous GlobalIFunc.
2670 *
2671 * Returns NULL if the iterator was already at the beginning and there are
2672 * no previous global aliases.
2673 */
2674LLVMValueRef LLVMGetPreviousGlobalIFunc(LLVMValueRef IFunc);
2675
2676/**
2677 * Retrieves the resolver function associated with this indirect function, or
2678 * NULL if it doesn't not exist.
2679 *
2680 * @see llvm::GlobalIFunc::getResolver()
2681 */
2682LLVMValueRef LLVMGetGlobalIFuncResolver(LLVMValueRef IFunc);
2683
2684/**
2685 * Sets the resolver function associated with this indirect function.
2686 *
2687 * @see llvm::GlobalIFunc::setResolver()
2688 */
2689void LLVMSetGlobalIFuncResolver(LLVMValueRef IFunc, LLVMValueRef Resolver);
2690
2691/**
2692 * Remove a global indirect function from its parent module and delete it.
2693 *
2694 * @see llvm::GlobalIFunc::eraseFromParent()
2695 */
2696void LLVMEraseGlobalIFunc(LLVMValueRef IFunc);
2697
2698/**
2699 * Remove a global indirect function from its parent module.
2700 *
2701 * This unlinks the global indirect function from its containing module but
2702 * keeps it alive.
2703 *
2704 * @see llvm::GlobalIFunc::removeFromParent()
2705 */
2706void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc);
2707
2708/**
2709 * @}
2710 */
2711
2712/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002713 * @}
2714 */
2715
2716/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002717 * @}
2718 */
2719
2720/**
2721 * @}
2722 */
2723
2724/**
2725 * @defgroup LLVMCCoreValueMetadata Metadata
2726 *
2727 * @{
2728 */
2729
2730/**
2731 * Obtain a MDString value from a context.
2732 *
2733 * The returned instance corresponds to the llvm::MDString class.
2734 *
2735 * The instance is specified by string data of a specified length. The
2736 * string content is copied, so the backing memory can be freed after
2737 * this function returns.
2738 */
2739LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2740 unsigned SLen);
2741
2742/**
2743 * Obtain a MDString value from the global context.
2744 */
2745LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2746
2747/**
2748 * Obtain a MDNode value from a context.
2749 *
2750 * The returned value corresponds to the llvm::MDNode class.
2751 */
2752LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2753 unsigned Count);
2754
2755/**
2756 * Obtain a MDNode value from the global context.
2757 */
2758LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2759
2760/**
Amaury Sechetf8429752017-04-17 11:52:54 +00002761 * Obtain a Metadata as a Value.
2762 */
2763LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
2764
2765/**
2766 * Obtain a Value as a Metadata.
2767 */
2768LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
2769
2770/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002771 * Obtain the underlying string from a MDString value.
2772 *
2773 * @param V Instance to obtain string from.
NAKAMURA Takumie4a77052016-04-04 11:54:48 +00002774 * @param Length Memory address which will hold length of returned string.
Gregory Szorc52d26602012-03-21 07:28:27 +00002775 * @return String data in MDString.
2776 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002777const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
Gregory Szorc52d26602012-03-21 07:28:27 +00002778
2779/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002780 * Obtain the number of operands from an MDNode value.
2781 *
2782 * @param V MDNode to get number of operands from.
2783 * @return Number of operands of the MDNode.
2784 */
2785unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2786
2787/**
2788 * Obtain the given MDNode's operands.
2789 *
2790 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2791 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2792 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2793 * MDNode's operands.
2794 *
2795 * @param V MDNode to get the operands from.
2796 * @param Dest Destination array for operands.
2797 */
2798void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2799
2800/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002801 * @}
2802 */
2803
2804/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002805 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2806 *
2807 * A basic block represents a single entry single exit section of code.
2808 * Basic blocks contain a list of instructions which form the body of
2809 * the block.
2810 *
2811 * Basic blocks belong to functions. They have the type of label.
2812 *
2813 * Basic blocks are themselves values. However, the C API models them as
2814 * LLVMBasicBlockRef.
2815 *
2816 * @see llvm::BasicBlock
2817 *
2818 * @{
2819 */
2820
2821/**
2822 * Convert a basic block instance to a value type.
2823 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002824LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002825
2826/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002827 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002828 */
Chris Lattner25963c62010-01-09 22:27:07 +00002829LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002830
2831/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002832 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002833 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002834LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002835
2836/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002837 * Obtain the string name of a basic block.
2838 */
2839const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2840
2841/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002842 * Obtain the function to which a basic block belongs.
2843 *
2844 * @see llvm::BasicBlock::getParent()
2845 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002846LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002847
2848/**
2849 * Obtain the terminator instruction for a basic block.
2850 *
2851 * If the basic block does not have a terminator (it is not well-formed
2852 * if it doesn't), then NULL is returned.
2853 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00002854 * The returned LLVMValueRef corresponds to an llvm::Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002855 *
2856 * @see llvm::BasicBlock::getTerminator()
2857 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002858LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002859
2860/**
2861 * Obtain the number of basic blocks in a function.
2862 *
2863 * @param Fn Function value to operate on.
2864 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002865unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002866
2867/**
2868 * Obtain all of the basic blocks in a function.
2869 *
2870 * This operates on a function value. The BasicBlocks parameter is a
2871 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2872 * LLVMCountBasicBlocks() in length. This array is populated with
2873 * LLVMBasicBlockRef instances.
2874 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002875void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002876
2877/**
2878 * Obtain the first basic block in a function.
2879 *
2880 * The returned basic block can be used as an iterator. You will likely
2881 * eventually call into LLVMGetNextBasicBlock() with it.
2882 *
2883 * @see llvm::Function::begin()
2884 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002885LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002886
2887/**
2888 * Obtain the last basic block in a function.
2889 *
2890 * @see llvm::Function::end()
2891 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002892LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002893
2894/**
2895 * Advance a basic block iterator.
2896 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002897LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002898
2899/**
2900 * Go backwards in a basic block iterator.
2901 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002902LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002903
2904/**
2905 * Obtain the basic block that corresponds to the entry point of a
2906 * function.
2907 *
2908 * @see llvm::Function::getEntryBlock()
2909 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002910LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002911
Gregory Szorc34c863a2012-03-21 03:54:29 +00002912/**
Robert Widmann616ed172019-01-08 06:24:19 +00002913 * Create a new basic block without inserting it into a function.
2914 *
2915 * @see llvm::BasicBlock::Create()
2916 */
2917LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C,
James Y Knight68729f92019-01-14 17:16:55 +00002918 const char *Name);
Robert Widmann616ed172019-01-08 06:24:19 +00002919
2920/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002921 * Append a basic block to the end of a function.
2922 *
2923 * @see llvm::BasicBlock::Create()
2924 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002925LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2926 LLVMValueRef Fn,
2927 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002928
2929/**
2930 * Append a basic block to the end of a function using the global
2931 * context.
2932 *
2933 * @see llvm::BasicBlock::Create()
2934 */
2935LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2936
2937/**
2938 * Insert a basic block in a function before another basic block.
2939 *
2940 * The function to add to is determined by the function of the
2941 * passed basic block.
2942 *
2943 * @see llvm::BasicBlock::Create()
2944 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002945LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2946 LLVMBasicBlockRef BB,
2947 const char *Name);
2948
Gregory Szorc34c863a2012-03-21 03:54:29 +00002949/**
2950 * Insert a basic block in a function using the global context.
2951 *
2952 * @see llvm::BasicBlock::Create()
2953 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002954LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2955 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002956
2957/**
2958 * Remove a basic block from a function and delete it.
2959 *
2960 * This deletes the basic block from its containing function and deletes
2961 * the basic block itself.
2962 *
2963 * @see llvm::BasicBlock::eraseFromParent()
2964 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002965void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002966
2967/**
2968 * Remove a basic block from a function.
2969 *
2970 * This deletes the basic block from its containing function but keep
2971 * the basic block alive.
2972 *
2973 * @see llvm::BasicBlock::removeFromParent()
2974 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002975void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002976
Gregory Szorc34c863a2012-03-21 03:54:29 +00002977/**
2978 * Move a basic block to before another one.
2979 *
2980 * @see llvm::BasicBlock::moveBefore()
2981 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002982void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002983
2984/**
2985 * Move a basic block to after another one.
2986 *
2987 * @see llvm::BasicBlock::moveAfter()
2988 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002989void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2990
Gregory Szorc34c863a2012-03-21 03:54:29 +00002991/**
2992 * Obtain the first instruction in a basic block.
2993 *
2994 * The returned LLVMValueRef corresponds to a llvm::Instruction
2995 * instance.
2996 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002997LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002998
2999/**
3000 * Obtain the last instruction in a basic block.
3001 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003002 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003003 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003004LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00003005
Gregory Szorc34c863a2012-03-21 03:54:29 +00003006/**
3007 * @}
3008 */
3009
3010/**
3011 * @defgroup LLVMCCoreValueInstruction Instructions
3012 *
3013 * Functions in this group relate to the inspection and manipulation of
3014 * individual instructions.
3015 *
3016 * In the C++ API, an instruction is modeled by llvm::Instruction. This
3017 * class has a large number of descendents. llvm::Instruction is a
3018 * llvm::Value and in the C API, instructions are modeled by
3019 * LLVMValueRef.
3020 *
3021 * This group also contains sub-groups which operate on specific
3022 * llvm::Instruction types, e.g. llvm::CallInst.
3023 *
3024 * @{
3025 */
3026
3027/**
3028 * Determine whether an instruction has any metadata attached.
3029 */
3030int LLVMHasMetadata(LLVMValueRef Val);
3031
3032/**
3033 * Return metadata associated with an instruction value.
3034 */
3035LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
3036
3037/**
3038 * Set metadata associated with an instruction value.
3039 */
3040void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
3041
3042/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00003043 * Returns the metadata associated with an instruction value, but filters out
3044 * all the debug locations.
3045 *
3046 * @see llvm::Instruction::getAllMetadataOtherThanDebugLoc()
3047 */
3048LLVMValueMetadataEntry *
3049LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Instr,
3050 size_t *NumEntries);
3051
3052/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003053 * Obtain the basic block to which an instruction belongs.
3054 *
3055 * @see llvm::Instruction::getParent()
3056 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003057LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003058
3059/**
3060 * Obtain the instruction that occurs after the one specified.
3061 *
3062 * The next instruction will be from the same basic block.
3063 *
3064 * If this is the last instruction in a basic block, NULL will be
3065 * returned.
3066 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003067LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003068
3069/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00003070 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003071 *
3072 * If the instruction is the first instruction in a basic block, NULL
3073 * will be returned.
3074 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003075LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003076
3077/**
3078 * Remove and delete an instruction.
3079 *
3080 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00003081 * block but is kept alive.
3082 *
3083 * @see llvm::Instruction::removeFromParent()
3084 */
3085void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
3086
3087/**
3088 * Remove and delete an instruction.
3089 *
3090 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00003091 * block and then deleted.
3092 *
3093 * @see llvm::Instruction::eraseFromParent()
3094 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00003095void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003096
3097/**
3098 * Obtain the code opcode for an individual instruction.
3099 *
3100 * @see llvm::Instruction::getOpCode()
3101 */
Eric Christophera6b96002015-12-18 01:46:52 +00003102LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003103
3104/**
3105 * Obtain the predicate of an instruction.
3106 *
3107 * This is only valid for instructions that correspond to llvm::ICmpInst
3108 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
3109 *
3110 * @see llvm::ICmpInst::getPredicate()
3111 */
Torok Edwin60c40de2011-10-06 12:13:20 +00003112LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003113
Gregory Szorc34c863a2012-03-21 03:54:29 +00003114/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00003115 * Obtain the float predicate of an instruction.
3116 *
3117 * This is only valid for instructions that correspond to llvm::FCmpInst
3118 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
3119 *
3120 * @see llvm::FCmpInst::getPredicate()
3121 */
3122LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
3123
3124/**
Peter Zotovaff492c2014-10-17 01:02:34 +00003125 * Create a copy of 'this' instruction that is identical in all ways
3126 * except the following:
3127 * * The instruction has no parent
3128 * * The instruction has no name
3129 *
3130 * @see llvm::Instruction::clone()
3131 */
3132LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
3133
3134/**
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003135 * Determine whether an instruction is a terminator. This routine is named to
3136 * be compatible with historical functions that did this by querying the
3137 * underlying C++ type.
3138 *
3139 * @see llvm::Instruction::isTerminator()
3140 */
3141LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst);
3142
3143/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003144 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
3145 *
3146 * Functions in this group apply to instructions that refer to call
3147 * sites and invocations. These correspond to C++ types in the
3148 * llvm::CallInst class tree.
3149 *
3150 * @{
3151 */
3152
3153/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003154 * Obtain the argument count for a call instruction.
3155 *
Robert Widmann478fce92018-03-30 17:49:53 +00003156 * This expects an LLVMValueRef that corresponds to a llvm::CallInst,
3157 * llvm::InvokeInst, or llvm:FuncletPadInst.
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003158 *
3159 * @see llvm::CallInst::getNumArgOperands()
3160 * @see llvm::InvokeInst::getNumArgOperands()
Robert Widmann478fce92018-03-30 17:49:53 +00003161 * @see llvm::FuncletPadInst::getNumArgOperands()
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003162 */
3163unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
3164
3165/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003166 * Set the calling convention for a call instruction.
3167 *
3168 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3169 * llvm::InvokeInst.
3170 *
3171 * @see llvm::CallInst::setCallingConv()
3172 * @see llvm::InvokeInst::setCallingConv()
3173 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003174void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003175
3176/**
3177 * Obtain the calling convention for a call instruction.
3178 *
3179 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
3180 * usage.
3181 *
3182 * @see LLVMSetInstructionCallConv()
3183 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003184unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003185
Gregory Szorc34c863a2012-03-21 03:54:29 +00003186void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Amaury Sechet81243a72016-05-01 01:42:34 +00003187 unsigned Align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00003188
Amaury Secheta65a2372016-06-15 05:14:29 +00003189void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3190 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00003191unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx);
3192void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
3193 LLVMAttributeRef *Attrs);
Amaury Secheta65a2372016-06-15 05:14:29 +00003194LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
3195 LLVMAttributeIndex Idx,
3196 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003197LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
3198 LLVMAttributeIndex Idx,
3199 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003200void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3201 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003202void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3203 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003204
Gregory Szorc34c863a2012-03-21 03:54:29 +00003205/**
James Y Knightf9563902019-01-14 21:37:42 +00003206 * Obtain the function type called by this instruction.
3207 *
3208 * @see llvm::CallBase::getFunctionType()
3209 */
3210LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef C);
3211
3212/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003213 * Obtain the pointer to the function invoked by this instruction.
3214 *
3215 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3216 * llvm::InvokeInst.
3217 *
3218 * @see llvm::CallInst::getCalledValue()
3219 * @see llvm::InvokeInst::getCalledValue()
3220 */
3221LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
3222
3223/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003224 * Obtain whether a call instruction is a tail call.
3225 *
3226 * This only works on llvm::CallInst instructions.
3227 *
3228 * @see llvm::CallInst::isTailCall()
3229 */
Chris Lattner25963c62010-01-09 22:27:07 +00003230LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003231
3232/**
3233 * Set whether a call instruction is a tail call.
3234 *
3235 * This only works on llvm::CallInst instructions.
3236 *
3237 * @see llvm::CallInst::setTailCall()
3238 */
Chris Lattner25963c62010-01-09 22:27:07 +00003239void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00003240
Gregory Szorc34c863a2012-03-21 03:54:29 +00003241/**
Amaury Sechete39e8532016-02-18 20:38:32 +00003242 * Return the normal destination basic block.
3243 *
3244 * This only works on llvm::InvokeInst instructions.
3245 *
3246 * @see llvm::InvokeInst::getNormalDest()
3247 */
3248LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
3249
3250/**
3251 * Return the unwind destination basic block.
3252 *
Robert Widmann478fce92018-03-30 17:49:53 +00003253 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3254 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003255 *
3256 * @see llvm::InvokeInst::getUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003257 * @see llvm::CleanupReturnInst::getUnwindDest()
3258 * @see llvm::CatchSwitchInst::getUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003259 */
3260LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
3261
3262/**
3263 * Set the normal destination basic block.
3264 *
3265 * This only works on llvm::InvokeInst instructions.
3266 *
3267 * @see llvm::InvokeInst::setNormalDest()
3268 */
3269void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3270
3271/**
3272 * Set the unwind destination basic block.
3273 *
Robert Widmann478fce92018-03-30 17:49:53 +00003274 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3275 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003276 *
3277 * @see llvm::InvokeInst::setUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003278 * @see llvm::CleanupReturnInst::setUnwindDest()
3279 * @see llvm::CatchSwitchInst::setUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003280 */
3281void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3282
3283/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003284 * @}
3285 */
3286
3287/**
Peter Zotov2481c752014-10-28 19:46:56 +00003288 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
3289 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003290 * Functions in this group only apply to instructions for which
3291 * LLVMIsATerminatorInst returns true.
Peter Zotov2481c752014-10-28 19:46:56 +00003292 *
3293 * @{
3294 */
3295
3296/**
3297 * Return the number of successors that this terminator has.
3298 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003299 * @see llvm::Instruction::getNumSuccessors
Peter Zotov2481c752014-10-28 19:46:56 +00003300 */
3301unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
3302
3303/**
3304 * Return the specified successor.
3305 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003306 * @see llvm::Instruction::getSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003307 */
3308LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
3309
3310/**
3311 * Update the specified successor to point at the provided block.
3312 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003313 * @see llvm::Instruction::setSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003314 */
3315void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
3316
3317/**
3318 * Return if a branch is conditional.
3319 *
3320 * This only works on llvm::BranchInst instructions.
3321 *
3322 * @see llvm::BranchInst::isConditional
3323 */
3324LLVMBool LLVMIsConditional(LLVMValueRef Branch);
3325
3326/**
3327 * Return the condition of a branch instruction.
3328 *
3329 * This only works on llvm::BranchInst instructions.
3330 *
3331 * @see llvm::BranchInst::getCondition
3332 */
3333LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
3334
3335/**
3336 * Set the condition of a branch instruction.
3337 *
3338 * This only works on llvm::BranchInst instructions.
3339 *
3340 * @see llvm::BranchInst::setCondition
3341 */
3342void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
3343
3344/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003345 * Obtain the default destination basic block of a switch instruction.
3346 *
3347 * This only works on llvm::SwitchInst instructions.
3348 *
3349 * @see llvm::SwitchInst::getDefaultDest()
3350 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003351LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
3352
Gregory Szorc34c863a2012-03-21 03:54:29 +00003353/**
Peter Zotov2481c752014-10-28 19:46:56 +00003354 * @}
3355 */
3356
3357/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00003358 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
3359 *
3360 * Functions in this group only apply to instructions that map to
3361 * llvm::AllocaInst instances.
3362 *
3363 * @{
3364 */
3365
3366/**
3367 * Obtain the type that is being allocated by the alloca instruction.
3368 */
3369LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
3370
3371/**
3372 * @}
3373 */
3374
3375/**
Amaury Sechet053ac452016-02-17 22:51:03 +00003376 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
3377 *
3378 * Functions in this group only apply to instructions that map to
3379 * llvm::GetElementPtrInst instances.
3380 *
3381 * @{
3382 */
3383
3384/**
3385 * Check whether the given GEP instruction is inbounds.
3386 */
3387LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
3388
3389/**
3390 * Set the given GEP instruction to be inbounds or not.
3391 */
Amaury Sechet8a367d42016-05-01 02:23:14 +00003392void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
Amaury Sechet053ac452016-02-17 22:51:03 +00003393
3394/**
3395 * @}
3396 */
3397
3398/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003399 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
3400 *
3401 * Functions in this group only apply to instructions that map to
3402 * llvm::PHINode instances.
3403 *
3404 * @{
3405 */
3406
3407/**
3408 * Add an incoming value to the end of a PHI list.
3409 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003410void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
3411 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003412
3413/**
3414 * Obtain the number of incoming basic blocks to a PHI node.
3415 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003416unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003417
3418/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003419 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003420 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003421LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003422
3423/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003424 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003425 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003426LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003427
Gregory Szorc34c863a2012-03-21 03:54:29 +00003428/**
3429 * @}
3430 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003431
Gregory Szorc34c863a2012-03-21 03:54:29 +00003432/**
Amaury Sechetaad93532016-02-10 00:38:50 +00003433 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
3434 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
3435 *
3436 * Functions in this group only apply to instructions that map to
3437 * llvm::ExtractValue and llvm::InsertValue instances.
3438 *
3439 * @{
3440 */
3441
3442/**
3443 * Obtain the number of indices.
Amaury Sechet053ac452016-02-17 22:51:03 +00003444 * NB: This also works on GEP.
Amaury Sechetaad93532016-02-10 00:38:50 +00003445 */
3446unsigned LLVMGetNumIndices(LLVMValueRef Inst);
3447
3448/**
3449 * Obtain the indices as an array.
3450 */
3451const unsigned *LLVMGetIndices(LLVMValueRef Inst);
3452
3453/**
3454 * @}
3455 */
3456
3457/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003458 * @}
3459 */
3460
3461/**
3462 * @}
3463 */
3464
3465/**
3466 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
3467 *
3468 * An instruction builder represents a point within a basic block and is
3469 * the exclusive means of building instructions using the C interface.
3470 *
3471 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003472 */
3473
Erick Tryzelaar262332f2009-08-14 00:01:31 +00003474LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003475LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00003476void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
3477 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003478void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
3479void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003480LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00003481void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
3482void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00003483void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
3484 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003485void LLVMDisposeBuilder(LLVMBuilderRef Builder);
3486
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00003487/* Metadata */
3488void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
3489LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
3490void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
3491
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003492/* Terminators */
3493LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
3494LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00003495LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003496 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003497LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
3498LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
3499 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
3500LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
3501 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003502LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
3503 unsigned NumDests);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003504// LLVMBuildInvoke is deprecated in favor of LLVMBuildInvoke2, in preparation
3505// for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003506LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
3507 LLVMValueRef *Args, unsigned NumArgs,
3508 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3509 const char *Name);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003510LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
3511 LLVMValueRef *Args, unsigned NumArgs,
3512 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3513 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003514LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
3515
3516/* Exception Handling */
3517LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00003518LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00003519 LLVMValueRef PersFn, unsigned NumClauses,
3520 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003521LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3522 LLVMBasicBlockRef BB);
3523LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3524 LLVMBasicBlockRef BB);
3525LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3526 LLVMValueRef *Args, unsigned NumArgs,
3527 const char *Name);
3528LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3529 LLVMValueRef *Args, unsigned NumArgs,
3530 const char *Name);
3531LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B, LLVMValueRef ParentPad,
3532 LLVMBasicBlockRef UnwindBB,
3533 unsigned NumHandlers, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003534
Gordon Henriksen097102c2008-01-01 05:50:53 +00003535/* Add a case to the switch instruction */
3536void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
3537 LLVMBasicBlockRef Dest);
3538
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003539/* Add a destination to the indirectbr instruction */
3540void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
3541
Amaury Sechete39e8532016-02-18 20:38:32 +00003542/* Get the number of clauses on the landingpad instruction */
3543unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
3544
3545/* Get the value of the clause at idnex Idx on the landingpad instruction */
3546LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
3547
Bill Wendlingfae14752011-08-12 20:24:12 +00003548/* Add a catch or filter clause to the landingpad instruction */
3549void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
3550
Amaury Sechete39e8532016-02-18 20:38:32 +00003551/* Get the 'cleanup' flag in the landingpad instruction */
3552LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
3553
Bill Wendlingfae14752011-08-12 20:24:12 +00003554/* Set the 'cleanup' flag in the landingpad instruction */
3555void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
3556
Robert Widmann478fce92018-03-30 17:49:53 +00003557/* Add a destination to the catchswitch instruction */
3558void LLVMAddHandler(LLVMValueRef CatchSwitch, LLVMBasicBlockRef Dest);
3559
3560/* Get the number of handlers on the catchswitch instruction */
3561unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch);
3562
3563/**
3564 * Obtain the basic blocks acting as handlers for a catchswitch instruction.
3565 *
3566 * The Handlers parameter should point to a pre-allocated array of
3567 * LLVMBasicBlockRefs at least LLVMGetNumHandlers() large. On return, the
3568 * first LLVMGetNumHandlers() entries in the array will be populated
3569 * with LLVMBasicBlockRef instances.
3570 *
3571 * @param CatchSwitch The catchswitch instruction to operate on.
3572 * @param Handlers Memory address of an array to be filled with basic blocks.
3573 */
3574void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers);
3575
3576/* Funclets */
3577
3578/* Get the number of funcletpad arguments. */
3579LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i);
3580
3581/* Set a funcletpad argument at the given index. */
3582void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value);
3583
3584/**
3585 * Get the parent catchswitch instruction of a catchpad instruction.
3586 *
3587 * This only works on llvm::CatchPadInst instructions.
3588 *
3589 * @see llvm::CatchPadInst::getCatchSwitch()
3590 */
3591LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad);
3592
3593/**
3594 * Set the parent catchswitch instruction of a catchpad instruction.
3595 *
3596 * This only works on llvm::CatchPadInst instructions.
3597 *
3598 * @see llvm::CatchPadInst::setCatchSwitch()
3599 */
3600void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad, LLVMValueRef CatchSwitch);
3601
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003602/* Arithmetic */
3603LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3604 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003605LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3606 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003607LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3608 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003609LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3610 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003611LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3612 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003613LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3614 const char *Name);
3615LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3616 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003617LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3618 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003619LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3620 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003621LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3622 const char *Name);
3623LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3624 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003625LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3626 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003627LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3628 const char *Name);
Manuel Jacob49fafb12016-10-04 23:32:42 +00003629LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3630 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003631LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3632 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003633LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3634 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003635LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3636 const char *Name);
3637LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3638 const char *Name);
3639LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3640 const char *Name);
3641LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3642 const char *Name);
3643LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3644 const char *Name);
3645LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3646 const char *Name);
3647LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3648 const char *Name);
3649LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3650 const char *Name);
3651LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3652 const char *Name);
3653LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3654 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003655LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
3656 LLVMValueRef LHS, LLVMValueRef RHS,
3657 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003658LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003659LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
3660 const char *Name);
3661LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
3662 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00003663LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003664LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
3665
3666/* Memory */
3667LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3668LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
3669 LLVMValueRef Val, const char *Name);
Robert Widmann98640f82018-10-29 15:31:40 +00003670
3671/**
3672 * Creates and inserts a memset to the specified pointer and the
3673 * specified value.
3674 *
3675 * @see llvm::IRRBuilder::CreateMemSet()
3676 */
3677LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
3678 LLVMValueRef Val, LLVMValueRef Len,
3679 unsigned Align);
3680/**
3681 * Creates and inserts a memcpy between the specified pointers.
3682 *
3683 * @see llvm::IRRBuilder::CreateMemCpy()
3684 */
3685LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,
3686 LLVMValueRef Dst, unsigned DstAlign,
3687 LLVMValueRef Src, unsigned SrcAlign,
3688 LLVMValueRef Size);
3689/**
3690 * Creates and inserts a memmove between the specified pointers.
3691 *
3692 * @see llvm::IRRBuilder::CreateMemMove()
3693 */
3694LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B,
3695 LLVMValueRef Dst, unsigned DstAlign,
3696 LLVMValueRef Src, unsigned SrcAlign,
3697 LLVMValueRef Size);
3698
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003699LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3700LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
3701 LLVMValueRef Val, const char *Name);
3702LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003703// LLVMBuildLoad is deprecated in favor of LLVMBuildLoad2, in preparation for
3704// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003705LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
3706 const char *Name);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003707LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty,
3708 LLVMValueRef PointerVal, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003709LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
James Y Knight544fa422019-01-14 21:39:35 +00003710// LLVMBuildGEP, LLVMBuildInBoundsGEP, and LLVMBuildStructGEP are deprecated in
3711// favor of LLVMBuild*GEP2, in preparation for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003712LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3713 LLVMValueRef *Indices, unsigned NumIndices,
3714 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003715LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3716 LLVMValueRef *Indices, unsigned NumIndices,
3717 const char *Name);
3718LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3719 unsigned Idx, const char *Name);
James Y Knight544fa422019-01-14 21:39:35 +00003720LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3721 LLVMValueRef Pointer, LLVMValueRef *Indices,
3722 unsigned NumIndices, const char *Name);
3723LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3724 LLVMValueRef Pointer, LLVMValueRef *Indices,
3725 unsigned NumIndices, const char *Name);
3726LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3727 LLVMValueRef Pointer, unsigned Idx,
3728 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003729LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
3730 const char *Name);
3731LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
3732 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00003733LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
3734void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00003735LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
3736void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003737
3738/* Casts */
3739LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
3740 LLVMTypeRef DestTy, const char *Name);
3741LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
3742 LLVMTypeRef DestTy, const char *Name);
3743LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
3744 LLVMTypeRef DestTy, const char *Name);
3745LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
3746 LLVMTypeRef DestTy, const char *Name);
3747LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
3748 LLVMTypeRef DestTy, const char *Name);
3749LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
3750 LLVMTypeRef DestTy, const char *Name);
3751LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
3752 LLVMTypeRef DestTy, const char *Name);
3753LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
3754 LLVMTypeRef DestTy, const char *Name);
3755LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
3756 LLVMTypeRef DestTy, const char *Name);
3757LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
3758 LLVMTypeRef DestTy, const char *Name);
3759LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
3760 LLVMTypeRef DestTy, const char *Name);
3761LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
3762 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003763LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
3764 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003765LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3766 LLVMTypeRef DestTy, const char *Name);
3767LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3768 LLVMTypeRef DestTy, const char *Name);
3769LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3770 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003771LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
3772 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003773LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
3774 LLVMTypeRef DestTy, const char *Name);
Robert Widmann40dc48be2019-01-08 06:23:22 +00003775LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef, LLVMValueRef Val,
3776 LLVMTypeRef DestTy, LLVMBool IsSigned,
James Y Knight68729f92019-01-14 17:16:55 +00003777 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003778LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
3779 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003780
Robert Widmann40dc48be2019-01-08 06:23:22 +00003781/** Deprecated: This cast is always signed. Use LLVMBuildIntCast2 instead. */
3782LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
3783 LLVMTypeRef DestTy, const char *Name);
3784
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003785/* Comparisons */
3786LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
3787 LLVMValueRef LHS, LLVMValueRef RHS,
3788 const char *Name);
3789LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
3790 LLVMValueRef LHS, LLVMValueRef RHS,
3791 const char *Name);
3792
3793/* Miscellaneous instructions */
3794LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003795// LLVMBuildCall is deprecated in favor of LLVMBuildCall2, in preparation for
3796// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003797LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
3798 LLVMValueRef *Args, unsigned NumArgs,
3799 const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003800LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn,
3801 LLVMValueRef *Args, unsigned NumArgs,
3802 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003803LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
3804 LLVMValueRef Then, LLVMValueRef Else,
3805 const char *Name);
3806LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
3807 const char *Name);
3808LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
3809 LLVMValueRef Index, const char *Name);
3810LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
3811 LLVMValueRef EltVal, LLVMValueRef Index,
3812 const char *Name);
3813LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
3814 LLVMValueRef V2, LLVMValueRef Mask,
3815 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00003816LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
3817 unsigned Index, const char *Name);
3818LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
3819 LLVMValueRef EltVal, unsigned Index,
3820 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00003821
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003822LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
3823 const char *Name);
3824LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
3825 const char *Name);
3826LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
3827 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00003828LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
3829 LLVMBool singleThread, const char *Name);
3830LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00003831 LLVMValueRef PTR, LLVMValueRef Val,
3832 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00003833 LLVMBool singleThread);
Mehdi Amini43165d92016-03-19 21:28:28 +00003834LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
3835 LLVMValueRef Cmp, LLVMValueRef New,
3836 LLVMAtomicOrdering SuccessOrdering,
3837 LLVMAtomicOrdering FailureOrdering,
3838 LLVMBool SingleThread);
3839
3840LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
3841void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
3842
3843LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
3844void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
3845 LLVMAtomicOrdering Ordering);
3846LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
3847void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
3848 LLVMAtomicOrdering Ordering);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003849
Gregory Szorc34c863a2012-03-21 03:54:29 +00003850/**
3851 * @}
3852 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003853
Gregory Szorc34c863a2012-03-21 03:54:29 +00003854/**
3855 * @defgroup LLVMCCoreModuleProvider Module Providers
3856 *
3857 * @{
3858 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003859
Gregory Szorc34c863a2012-03-21 03:54:29 +00003860/**
3861 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003862 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003863 */
3864LLVMModuleProviderRef
3865LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
3866
Gregory Szorc34c863a2012-03-21 03:54:29 +00003867/**
3868 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003869 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003870void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003871
Gregory Szorc34c863a2012-03-21 03:54:29 +00003872/**
3873 * @}
3874 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003875
Gregory Szorc34c863a2012-03-21 03:54:29 +00003876/**
3877 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
3878 *
3879 * @{
3880 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003881
Chris Lattner25963c62010-01-09 22:27:07 +00003882LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
3883 LLVMMemoryBufferRef *OutMemBuf,
3884 char **OutMessage);
3885LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
3886 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00003887LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
3888 size_t InputDataLength,
3889 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00003890 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00003891LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
3892 size_t InputDataLength,
3893 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00003894const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00003895size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003896void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
3897
Gregory Szorc34c863a2012-03-21 03:54:29 +00003898/**
3899 * @}
3900 */
3901
3902/**
3903 * @defgroup LLVMCCorePassRegistry Pass Registry
3904 *
3905 * @{
3906 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003907
3908/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003909 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003910LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003911
Gregory Szorc34c863a2012-03-21 03:54:29 +00003912/**
3913 * @}
3914 */
3915
3916/**
3917 * @defgroup LLVMCCorePassManagers Pass Managers
3918 *
3919 * @{
3920 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003921
3922/** Constructs a new whole-module pass pipeline. This type of pipeline is
3923 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003924 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003925LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003926
3927/** Constructs a new function-by-function pass pipeline over the module
3928 provider. It does not take ownership of the module provider. This type of
3929 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003930 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00003931LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
3932
3933/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003934LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
3935
3936/** Initializes, executes on the provided module, and finalizes all of the
3937 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00003938 modified the module, 0 otherwise.
3939 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003940LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003941
3942/** Initializes all of the function passes scheduled in the function pass
3943 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003944 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00003945LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003946
3947/** Executes all of the function passes scheduled in the function pass manager
3948 on the provided function. Returns 1 if any of the passes modified the
3949 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003950 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003951LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003952
Hiroshi Inoue0909ca12018-01-26 08:15:29 +00003953/** Finalizes all of the function passes scheduled in the function pass
Gordon Henriksen878114b2008-03-16 04:20:44 +00003954 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003955 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00003956LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003957
3958/** Frees the memory of a pass pipeline. For function pipelines, does not free
3959 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003960 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003961void LLVMDisposePassManager(LLVMPassManagerRef PM);
3962
Gregory Szorc34c863a2012-03-21 03:54:29 +00003963/**
3964 * @}
3965 */
3966
3967/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00003968 * @defgroup LLVMCCoreThreading Threading
3969 *
3970 * Handle the structures needed to make LLVM safe for multithreading.
3971 *
3972 * @{
3973 */
3974
Chandler Carruth39cd2162014-06-27 15:13:01 +00003975/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3976 time define LLVM_ENABLE_THREADS. This function always returns
3977 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003978LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003979
Chandler Carruth39cd2162014-06-27 15:13:01 +00003980/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3981 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003982void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003983
3984/** Check whether LLVM is executing in thread-safe mode or not.
3985 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003986LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003987
3988/**
3989 * @}
3990 */
3991
3992/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003993 * @}
3994 */
3995
3996/**
3997 * @}
3998 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003999
Gordon Henriksen76a03742007-09-18 03:18:57 +00004000#ifdef __cplusplus
4001}
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00004002#endif
Gordon Henriksen7330acd2007-10-05 23:59:36 +00004003
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00004004#endif /* LLVM_C_CORE_H */