blob: 815541c65d8cce5d994c8a6611d11afe05f0f5a5 [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 */
Nick Lewyckyf57e9682019-09-26 00:58:55 +0000373 LLVMAtomicRMWBinOpUMin, /**< Sets the value if it's greater than the
374 original using an unsigned comparison and return
375 the old one */
376 LLVMAtomicRMWBinOpFAdd, /**< Add a floating point value and return the
377 old one */
378 LLVMAtomicRMWBinOpFSub /**< Subtract a floating point value and return the
379 old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000380} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000381
Tom Stellard1580dc72014-04-16 17:45:04 +0000382typedef enum {
383 LLVMDSError,
384 LLVMDSWarning,
385 LLVMDSRemark,
386 LLVMDSNote
387} LLVMDiagnosticSeverity;
388
Robert Widmannf108d572018-04-06 02:31:29 +0000389typedef enum {
390 LLVMInlineAsmDialectATT,
391 LLVMInlineAsmDialectIntel
392} LLVMInlineAsmDialect;
393
Robert Widmannbce367702018-05-14 08:09:00 +0000394typedef enum {
395 /**
396 * Emits an error if two values disagree, otherwise the resulting value is
397 * that of the operands.
398 *
399 * @see Module::ModFlagBehavior::Error
400 */
401 LLVMModuleFlagBehaviorError,
402 /**
403 * Emits a warning if two values disagree. The result value will be the
404 * operand for the flag from the first module being linked.
405 *
406 * @see Module::ModFlagBehavior::Warning
407 */
408 LLVMModuleFlagBehaviorWarning,
409 /**
410 * Adds a requirement that another module flag be present and have a
411 * specified value after linking is performed. The value must be a metadata
412 * pair, where the first element of the pair is the ID of the module flag
413 * to be restricted, and the second element of the pair is the value the
414 * module flag should be restricted to. This behavior can be used to
415 * restrict the allowable results (via triggering of an error) of linking
416 * IDs with the **Override** behavior.
417 *
418 * @see Module::ModFlagBehavior::Require
419 */
420 LLVMModuleFlagBehaviorRequire,
421 /**
422 * Uses the specified value, regardless of the behavior or value of the
423 * other module. If both modules specify **Override**, but the values
424 * differ, an error will be emitted.
425 *
426 * @see Module::ModFlagBehavior::Override
427 */
428 LLVMModuleFlagBehaviorOverride,
429 /**
430 * Appends the two values, which are required to be metadata nodes.
431 *
432 * @see Module::ModFlagBehavior::Append
433 */
434 LLVMModuleFlagBehaviorAppend,
435 /**
436 * Appends the two values, which are required to be metadata
437 * nodes. However, duplicate entries in the second list are dropped
438 * during the append operation.
439 *
440 * @see Module::ModFlagBehavior::AppendUnique
441 */
442 LLVMModuleFlagBehaviorAppendUnique,
443} LLVMModuleFlagBehavior;
444
Gregory Szorc34c863a2012-03-21 03:54:29 +0000445/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000446 * Attribute index are either LLVMAttributeReturnIndex,
447 * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
448 */
449enum {
450 LLVMAttributeReturnIndex = 0U,
451 // ISO C restricts enumerator values to range of 'int'
452 // (4294967295 is too large)
453 // LLVMAttributeFunctionIndex = ~0U,
454 LLVMAttributeFunctionIndex = -1,
455};
456
457typedef unsigned LLVMAttributeIndex;
458
459/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000460 * @}
461 */
462
Nick Lewycky0db26542011-05-15 07:20:34 +0000463void LLVMInitializeCore(LLVMPassRegistryRef R);
464
Duncan Sands1cba0a82013-02-17 16:35:51 +0000465/** Deallocate and destroy all ManagedStatic variables.
466 @see llvm::llvm_shutdown
467 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000468void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000469
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000470/*===-- Error handling ----------------------------------------------------===*/
471
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000472char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000473void LLVMDisposeMessage(char *Message);
474
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000475/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000476 * @defgroup LLVMCCoreContext Contexts
477 *
478 * Contexts are execution states for the core LLVM IR system.
479 *
480 * Most types are tied to a context instance. Multiple contexts can
481 * exist simultaneously. A single context is not thread safe. However,
482 * different contexts can execute on different threads simultaneously.
483 *
484 * @{
485 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000486
Tom Stellard1580dc72014-04-16 17:45:04 +0000487typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000488typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000489
Gregory Szorc34c863a2012-03-21 03:54:29 +0000490/**
491 * Create a new context.
492 *
493 * Every call to this function should be paired with a call to
494 * LLVMContextDispose() or the context will leak memory.
495 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000496LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000497
498/**
499 * Obtain the global context instance.
500 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000501LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000502
503/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000504 * Set the diagnostic handler for this context.
505 */
506void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
507 LLVMDiagnosticHandler Handler,
508 void *DiagnosticContext);
509
510/**
Jeroen Ketemaad659c32016-04-08 09:19:02 +0000511 * Get the diagnostic handler of this context.
512 */
513LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
514
515/**
516 * Get the diagnostic context of this context.
517 */
518void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
519
520/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000521 * Set the yield callback function for this context.
522 *
523 * @see LLVMContext::setYieldCallback()
524 */
525void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
526 void *OpaqueHandle);
527
528/**
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000529 * Retrieve whether the given context is set to discard all value names.
530 *
531 * @see LLVMContext::shouldDiscardValueNames()
532 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000533LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000534
535/**
536 * Set whether the given context discards all value names.
537 *
538 * If true, only the names of GlobalValue objects will be available in the IR.
539 * This can be used to save memory and runtime, especially in release mode.
540 *
541 * @see LLVMContext::setDiscardValueNames()
542 */
Robert Widmanndb5b5372019-01-01 19:03:37 +0000543void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard);
Robert Widmann5d1dfa32019-01-01 18:56:51 +0000544
545/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000546 * Destroy a context instance.
547 *
548 * This should be called for every call to LLVMContextCreate() or memory
549 * will be leaked.
550 */
Owen Anderson6773d382009-07-01 16:58:40 +0000551void LLVMContextDispose(LLVMContextRef C);
552
Tom Stellard1580dc72014-04-16 17:45:04 +0000553/**
554 * Return a string representation of the DiagnosticInfo. Use
555 * LLVMDisposeMessage to free the string.
556 *
557 * @see DiagnosticInfo::print()
558 */
559char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
560
561/**
562 * Return an enum LLVMDiagnosticSeverity.
563 *
564 * @see DiagnosticInfo::getSeverity()
565 */
566LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
567
Amaury Sechet56f056c2016-04-04 22:00:25 +0000568unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000569 unsigned SLen);
Amaury Sechet56f056c2016-04-04 22:00:25 +0000570unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000571
Gregory Szorc34c863a2012-03-21 03:54:29 +0000572/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000573 * Return an unique id given the name of a enum attribute,
Amaury Sechet60b31452016-04-20 01:02:12 +0000574 * or 0 if no attribute by that name exists.
575 *
576 * See http://llvm.org/docs/LangRef.html#parameter-attributes
577 * and http://llvm.org/docs/LangRef.html#function-attributes
578 * for the list of available attributes.
579 *
580 * NB: Attribute names and/or id are subject to change without
581 * going through the C API deprecation cycle.
582 */
Amaury Sechet5db224e2016-06-12 06:17:24 +0000583unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
Amaury Sechet48b06652016-06-12 07:56:21 +0000584unsigned LLVMGetLastEnumAttributeKind(void);
Amaury Sechet5db224e2016-06-12 06:17:24 +0000585
586/**
587 * Create an enum attribute.
588 */
589LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
590 uint64_t Val);
591
592/**
593 * Get the unique id corresponding to the enum attribute
594 * passed as argument.
595 */
596unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
597
598/**
599 * Get the enum attribute's value. 0 is returned if none exists.
600 */
601uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
602
603/**
604 * Create a string attribute.
605 */
606LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
607 const char *K, unsigned KLength,
608 const char *V, unsigned VLength);
609
610/**
611 * Get the string attribute's kind.
612 */
613const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
614
615/**
616 * Get the string attribute's value.
617 */
618const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
619
620/**
621 * Check for the different types of attributes.
622 */
623LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
624LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
Amaury Sechet60b31452016-04-20 01:02:12 +0000625
626/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000627 * @}
628 */
629
Gregory Szorc52d26602012-03-21 07:28:27 +0000630/**
631 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000632 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000633 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000634 * module is effectively a translation unit or a collection of
635 * translation units merged together.
636 *
637 * @{
638 */
639
Gregory Szorc34c863a2012-03-21 03:54:29 +0000640/**
641 * Create a new, empty module in the global context.
642 *
643 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
644 * LLVMGetGlobalContext() as the context parameter.
645 *
646 * Every invocation should be paired with LLVMDisposeModule() or memory
647 * will be leaked.
648 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000649LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000650
651/**
652 * Create a new, empty module in a specific context.
653 *
654 * Every invocation should be paired with LLVMDisposeModule() or memory
655 * will be leaked.
656 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000657LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
658 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000659/**
660 * Return an exact copy of the specified module.
661 */
662LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000663
Gregory Szorc34c863a2012-03-21 03:54:29 +0000664/**
665 * Destroy a module instance.
666 *
667 * This must be called for every created module or memory will be
668 * leaked.
669 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000670void LLVMDisposeModule(LLVMModuleRef M);
671
Gregory Szorc34c863a2012-03-21 03:54:29 +0000672/**
Peter Zotov0a2fa0a2016-04-05 13:56:59 +0000673 * Obtain the identifier of a module.
674 *
675 * @param M Module to obtain identifier of
676 * @param Len Out parameter which holds the length of the returned string.
677 * @return The identifier of M.
678 * @see Module::getModuleIdentifier()
679 */
680const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
681
682/**
683 * Set the identifier of a module to a string Ident with length Len.
684 *
685 * @param M The module to set identifier
686 * @param Ident The string to set M's identifier to
687 * @param Len Length of Ident
688 * @see Module::setModuleIdentifier()
689 */
690void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
691
692/**
Robert Widmann490a5802018-01-30 21:34:29 +0000693 * Obtain the module's original source file name.
694 *
695 * @param M Module to obtain the name of
696 * @param Len Out parameter which holds the length of the returned string
697 * @return The original source file name of M
698 * @see Module::getSourceFileName()
699 */
700const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len);
701
702/**
703 * Set the original source file name of a module to a string Name with length
704 * Len.
705 *
706 * @param M The module to set the source file name of
707 * @param Name The string to set M's source file name to
708 * @param Len Length of Name
709 * @see Module::setSourceFileName()
710 */
711void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len);
712
713/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000714 * Obtain the data layout for a module.
715 *
Amaury Sechetf3549c42016-02-16 00:23:52 +0000716 * @see Module::getDataLayoutStr()
717 *
718 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
719 * but match the name of another method on the module. Prefer the use
720 * of LLVMGetDataLayoutStr, which is not ambiguous.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000721 */
Amaury Sechetf3549c42016-02-16 00:23:52 +0000722const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000723const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000724
725/**
726 * Set the data layout for a module.
727 *
728 * @see Module::setDataLayout()
729 */
Amaury Sechet6ada31c2016-02-15 23:40:06 +0000730void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000731
Gregory Szorc34c863a2012-03-21 03:54:29 +0000732/**
733 * Obtain the target triple for a module.
734 *
735 * @see Module::getTargetTriple()
736 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000737const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000738
739/**
740 * Set the target triple for a module.
741 *
742 * @see Module::setTargetTriple()
743 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000744void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
745
Gregory Szorc34c863a2012-03-21 03:54:29 +0000746/**
Robert Widmannbce367702018-05-14 08:09:00 +0000747 * Returns the module flags as an array of flag-key-value triples. The caller
748 * is responsible for freeing this array by calling
749 * \c LLVMDisposeModuleFlagsMetadata.
750 *
751 * @see Module::getModuleFlagsMetadata()
752 */
753LLVMModuleFlagEntry *LLVMCopyModuleFlagsMetadata(LLVMModuleRef M, size_t *Len);
754
755/**
756 * Destroys module flags metadata entries.
757 */
758void LLVMDisposeModuleFlagsMetadata(LLVMModuleFlagEntry *Entries);
759
760/**
761 * Returns the flag behavior for a module flag entry at a specific index.
762 *
763 * @see Module::ModuleFlagEntry::Behavior
764 */
765LLVMModuleFlagBehavior
766LLVMModuleFlagEntriesGetFlagBehavior(LLVMModuleFlagEntry *Entries,
767 unsigned Index);
768
769/**
770 * Returns the key for a module flag entry at a specific index.
771 *
772 * @see Module::ModuleFlagEntry::Key
773 */
774const char *LLVMModuleFlagEntriesGetKey(LLVMModuleFlagEntry *Entries,
775 unsigned Index, size_t *Len);
776
777/**
778 * Returns the metadata for a module flag entry at a specific index.
779 *
780 * @see Module::ModuleFlagEntry::Val
781 */
782LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries,
783 unsigned Index);
784
785/**
786 * Add a module-level flag to the module-level flags metadata if it doesn't
787 * already exist.
788 *
789 * @see Module::getModuleFlag()
790 */
791LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRef M,
792 const char *Key, size_t KeyLen);
793
794/**
795 * Add a module-level flag to the module-level flags metadata if it doesn't
796 * already exist.
797 *
798 * @see Module::addModuleFlag()
799 */
800void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior,
801 const char *Key, size_t KeyLen,
802 LLVMMetadataRef Val);
803
804/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000805 * Dump a representation of a module to stderr.
806 *
807 * @see Module::dump()
808 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000809void LLVMDumpModule(LLVMModuleRef M);
810
Gregory Szorc34c863a2012-03-21 03:54:29 +0000811/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000812 * Print a representation of a module to a file. The ErrorMessage needs to be
813 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
814 *
815 * @see Module::print()
816 */
817LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
818 char **ErrorMessage);
819
820/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000821 * Return a string representation of the module. Use
822 * LLVMDisposeMessage to free the string.
823 *
824 * @see Module::print()
825 */
826char *LLVMPrintModuleToString(LLVMModuleRef M);
827
828/**
Robert Widmannf108d572018-04-06 02:31:29 +0000829 * Get inline assembly for a module.
830 *
831 * @see Module::getModuleInlineAsm()
832 */
833const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len);
834
835/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000836 * Set inline assembly for a module.
837 *
838 * @see Module::setModuleInlineAsm()
839 */
Robert Widmannf108d572018-04-06 02:31:29 +0000840void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len);
841
842/**
843 * Append inline assembly to a module.
844 *
845 * @see Module::appendModuleInlineAsm()
846 */
847void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len);
848
849/**
850 * Create the specified uniqued inline asm string.
851 *
852 * @see InlineAsm::get()
853 */
854LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty,
855 char *AsmString, size_t AsmStringSize,
856 char *Constraints, size_t ConstraintsSize,
857 LLVMBool HasSideEffects, LLVMBool IsAlignStack,
858 LLVMInlineAsmDialect Dialect);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000859
Gregory Szorc34c863a2012-03-21 03:54:29 +0000860/**
861 * Obtain the context to which this module is associated.
862 *
863 * @see Module::getContext()
864 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000865LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
866
Gregory Szorc34c863a2012-03-21 03:54:29 +0000867/**
868 * Obtain a Type from a module by its registered name.
869 */
870LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000871
Gregory Szorc34c863a2012-03-21 03:54:29 +0000872/**
Robert Widmann0a35b762018-08-30 17:09:43 +0000873 * Obtain an iterator to the first NamedMDNode in a Module.
874 *
875 * @see llvm::Module::named_metadata_begin()
876 */
877LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M);
878
879/**
880 * Obtain an iterator to the last NamedMDNode in a Module.
881 *
882 * @see llvm::Module::named_metadata_end()
883 */
884LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M);
885
886/**
887 * Advance a NamedMDNode iterator to the next NamedMDNode.
888 *
889 * Returns NULL if the iterator was already at the end and there are no more
890 * named metadata nodes.
891 */
892LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
893
894/**
895 * Decrement a NamedMDNode iterator to the previous NamedMDNode.
896 *
897 * Returns NULL if the iterator was already at the beginning and there are
898 * no previous named metadata nodes.
899 */
900LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NamedMDNode);
901
902/**
903 * Retrieve a NamedMDNode with the given name, returning NULL if no such
904 * node exists.
905 *
906 * @see llvm::Module::getNamedMetadata()
907 */
908LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M,
909 const char *Name, size_t NameLen);
910
911/**
912 * Retrieve a NamedMDNode with the given name, creating a new node if no such
913 * node exists.
914 *
915 * @see llvm::Module::getOrInsertNamedMetadata()
916 */
917LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M,
918 const char *Name,
919 size_t NameLen);
920
921/**
922 * Retrieve the name of a NamedMDNode.
923 *
924 * @see llvm::NamedMDNode::getName()
925 */
926const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NamedMD,
927 size_t *NameLen);
928
929/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000930 * Obtain the number of operands for named metadata in a module.
931 *
932 * @see llvm::Module::getNamedMetadata()
933 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000934unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000935
936/**
937 * Obtain the named metadata operands for a module.
938 *
939 * The passed LLVMValueRef pointer should refer to an array of
940 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
941 * array will be populated with the LLVMValueRef instances. Each
942 * instance corresponds to a llvm::MDNode.
943 *
944 * @see llvm::Module::getNamedMetadata()
945 * @see llvm::MDNode::getOperand()
946 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000947void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
948 LLVMValueRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000949
950/**
951 * Add an operand to named metadata.
952 *
953 * @see llvm::Module::getNamedMetadata()
954 * @see llvm::MDNode::addOperand()
955 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000956void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
Gregory Szorc34c863a2012-03-21 03:54:29 +0000957 LLVMValueRef Val);
958
Gregory Szorc52d26602012-03-21 07:28:27 +0000959/**
Saleem Abdulrasool0d1cbcc2018-10-10 23:53:12 +0000960 * Return the directory of the debug location for this value, which must be
961 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
962 *
963 * @see llvm::Instruction::getDebugLoc()
964 * @see llvm::GlobalVariable::getDebugInfo()
965 * @see llvm::Function::getSubprogram()
966 */
967const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length);
968
969/**
970 * Return the filename of the debug location for this value, which must be
971 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
972 *
973 * @see llvm::Instruction::getDebugLoc()
974 * @see llvm::GlobalVariable::getDebugInfo()
975 * @see llvm::Function::getSubprogram()
976 */
977const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length);
978
979/**
980 * Return the line number of the debug location for this value, which must be
981 * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
982 *
983 * @see llvm::Instruction::getDebugLoc()
984 * @see llvm::GlobalVariable::getDebugInfo()
985 * @see llvm::Function::getSubprogram()
986 */
987unsigned LLVMGetDebugLocLine(LLVMValueRef Val);
988
989/**
990 * Return the column number of the debug location for this value, which must be
991 * an llvm::Instruction.
992 *
993 * @see llvm::Instruction::getDebugLoc()
994 */
995unsigned LLVMGetDebugLocColumn(LLVMValueRef Val);
996
997/**
Gregory Szorc52d26602012-03-21 07:28:27 +0000998 * Add a function to a module under a specified name.
999 *
1000 * @see llvm::Function::Create()
1001 */
1002LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1003 LLVMTypeRef FunctionTy);
1004
1005/**
1006 * Obtain a Function value from a Module by its name.
1007 *
1008 * The returned value corresponds to a llvm::Function value.
1009 *
1010 * @see llvm::Module::getFunction()
1011 */
1012LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
1013
1014/**
1015 * Obtain an iterator to the first Function in a Module.
1016 *
1017 * @see llvm::Module::begin()
1018 */
1019LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
1020
1021/**
1022 * Obtain an iterator to the last Function in a Module.
1023 *
1024 * @see llvm::Module::end()
1025 */
1026LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
1027
1028/**
1029 * Advance a Function iterator to the next Function.
1030 *
1031 * Returns NULL if the iterator was already at the end and there are no more
1032 * functions.
1033 */
1034LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
1035
1036/**
1037 * Decrement a Function iterator to the previous Function.
1038 *
1039 * Returns NULL if the iterator was already at the beginning and there are
1040 * no previous functions.
1041 */
1042LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001043
Robert Widmannf108d572018-04-06 02:31:29 +00001044/** Deprecated: Use LLVMSetModuleInlineAsm2 instead. */
1045void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
1046
Gregory Szorc34c863a2012-03-21 03:54:29 +00001047/**
1048 * @}
1049 */
1050
1051/**
1052 * @defgroup LLVMCCoreType Types
1053 *
1054 * Types represent the type of a value.
1055 *
1056 * Types are associated with a context instance. The context internally
1057 * deduplicates types so there is only 1 instance of a specific type
1058 * alive at a time. In other words, a unique type is shared among all
1059 * consumers within a context.
1060 *
1061 * A Type in the C API corresponds to llvm::Type.
1062 *
1063 * Types have the following hierarchy:
1064 *
Gordon Henriksen76a03742007-09-18 03:18:57 +00001065 * types:
1066 * integer type
1067 * real type
1068 * function type
1069 * sequence types:
1070 * array type
1071 * pointer type
1072 * vector type
1073 * void type
1074 * label type
1075 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +00001076 *
1077 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001078 */
1079
Gregory Szorc34c863a2012-03-21 03:54:29 +00001080/**
1081 * Obtain the enumerated type of a Type instance.
1082 *
1083 * @see llvm::Type:getTypeID()
1084 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001085LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001086
1087/**
1088 * Whether the type has a known size.
1089 *
1090 * Things that don't have a size are abstract types, labels, and void.a
1091 *
1092 * @see llvm::Type::isSized()
1093 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +00001094LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +00001095
Gregory Szorc34c863a2012-03-21 03:54:29 +00001096/**
1097 * Obtain the context to which this type instance is associated.
1098 *
1099 * @see llvm::Type::getContext()
1100 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001101LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
1102
Gregory Szorc34c863a2012-03-21 03:54:29 +00001103/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +00001104 * Dump a representation of a type to stderr.
1105 *
1106 * @see llvm::Type::dump()
1107 */
1108void LLVMDumpType(LLVMTypeRef Val);
1109
1110/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +00001111 * Return a string representation of the type. Use
1112 * LLVMDisposeMessage to free the string.
1113 *
1114 * @see llvm::Type::print()
1115 */
1116char *LLVMPrintTypeToString(LLVMTypeRef Val);
1117
1118/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001119 * @defgroup LLVMCCoreTypeInt Integer Types
1120 *
1121 * Functions in this section operate on integer types.
1122 *
1123 * @{
1124 */
1125
1126/**
1127 * Obtain an integer type from a context with specified bit width.
1128 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001129LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
1130LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
1131LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
1132LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
1133LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001134LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001135LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
1136
Gregory Szorc34c863a2012-03-21 03:54:29 +00001137/**
1138 * Obtain an integer type from the global context with a specified bit
1139 * width.
1140 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001141LLVMTypeRef LLVMInt1Type(void);
1142LLVMTypeRef LLVMInt8Type(void);
1143LLVMTypeRef LLVMInt16Type(void);
1144LLVMTypeRef LLVMInt32Type(void);
1145LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00001146LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001147LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001148unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001149
Gregory Szorc34c863a2012-03-21 03:54:29 +00001150/**
1151 * @}
1152 */
1153
1154/**
1155 * @defgroup LLVMCCoreTypeFloat Floating Point Types
1156 *
1157 * @{
1158 */
1159
1160/**
1161 * Obtain a 16-bit floating point type from a context.
1162 */
Dan Gohman518cda42011-12-17 00:04:22 +00001163LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001164
1165/**
1166 * Obtain a 32-bit floating point type from a context.
1167 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001168LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001169
1170/**
1171 * Obtain a 64-bit floating point type from a context.
1172 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001173LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001174
1175/**
1176 * Obtain a 80-bit floating point type (X87) from a context.
1177 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001178LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001179
1180/**
1181 * Obtain a 128-bit floating point type (112-bit mantissa) from a
1182 * context.
1183 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001184LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001185
1186/**
1187 * Obtain a 128-bit floating point type (two 64-bits) from a context.
1188 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001189LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
1190
Gregory Szorc34c863a2012-03-21 03:54:29 +00001191/**
1192 * Obtain a floating point type from the global context.
1193 *
1194 * These map to the functions in this group of the same name.
1195 */
Dan Gohman518cda42011-12-17 00:04:22 +00001196LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001197LLVMTypeRef LLVMFloatType(void);
1198LLVMTypeRef LLVMDoubleType(void);
1199LLVMTypeRef LLVMX86FP80Type(void);
1200LLVMTypeRef LLVMFP128Type(void);
1201LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001202
Gregory Szorc34c863a2012-03-21 03:54:29 +00001203/**
1204 * @}
1205 */
1206
1207/**
1208 * @defgroup LLVMCCoreTypeFunction Function Types
1209 *
1210 * @{
1211 */
1212
1213/**
1214 * Obtain a function type consisting of a specified signature.
1215 *
1216 * The function is defined as a tuple of a return Type, a list of
1217 * parameter types, and whether the function is variadic.
1218 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001219LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
1220 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001221 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001222
1223/**
1224 * Returns whether a function type is variadic.
1225 */
Chris Lattner25963c62010-01-09 22:27:07 +00001226LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001227
1228/**
1229 * Obtain the Type this function Type returns.
1230 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001231LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001232
1233/**
1234 * Obtain the number of parameters this function accepts.
1235 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001236unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001237
1238/**
1239 * Obtain the types of a function's parameters.
1240 *
1241 * The Dest parameter should point to a pre-allocated array of
1242 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
1243 * first LLVMCountParamTypes() entries in the array will be populated
1244 * with LLVMTypeRef instances.
1245 *
1246 * @param FunctionTy The function type to operate on.
1247 * @param Dest Memory address of an array to be filled with result.
1248 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001249void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001250
Gregory Szorc34c863a2012-03-21 03:54:29 +00001251/**
1252 * @}
1253 */
1254
1255/**
1256 * @defgroup LLVMCCoreTypeStruct Structure Types
1257 *
1258 * These functions relate to LLVMTypeRef instances.
1259 *
1260 * @see llvm::StructType
1261 *
1262 * @{
1263 */
1264
1265/**
1266 * Create a new structure type in a context.
1267 *
1268 * A structure is specified by a list of inner elements/types and
1269 * whether these can be packed together.
1270 *
1271 * @see llvm::StructType::create()
1272 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001273LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +00001274 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001275
1276/**
1277 * Create a new structure type in the global context.
1278 *
1279 * @see llvm::StructType::create()
1280 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001281LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +00001282 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001283
1284/**
1285 * Create an empty structure in a context having a specified name.
1286 *
1287 * @see llvm::StructType::create()
1288 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001289LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001290
1291/**
1292 * Obtain the name of a structure.
1293 *
1294 * @see llvm::StructType::getName()
1295 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +00001296const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001297
1298/**
1299 * Set the contents of a structure type.
1300 *
1301 * @see llvm::StructType::setBody()
1302 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001303void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
1304 unsigned ElementCount, LLVMBool Packed);
1305
Gregory Szorc34c863a2012-03-21 03:54:29 +00001306/**
1307 * Get the number of elements defined inside the structure.
1308 *
1309 * @see llvm::StructType::getNumElements()
1310 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001311unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001312
1313/**
1314 * Get the elements within a structure.
1315 *
1316 * The function is passed the address of a pre-allocated array of
1317 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
1318 * invocation, this array will be populated with the structure's
1319 * elements. The objects in the destination array will have a lifetime
1320 * of the structure type itself, which is the lifetime of the context it
1321 * is contained in.
1322 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001323void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001324
1325/**
Peter Zotovc164a3f2015-06-04 09:09:53 +00001326 * Get the type of the element at a given index in the structure.
1327 *
1328 * @see llvm::StructType::getTypeAtIndex()
1329 */
1330LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
1331
1332/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001333 * Determine whether a structure is packed.
1334 *
1335 * @see llvm::StructType::isPacked()
1336 */
Chris Lattner25963c62010-01-09 22:27:07 +00001337LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001338
1339/**
1340 * Determine whether a structure is opaque.
1341 *
1342 * @see llvm::StructType::isOpaque()
1343 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001344LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1345
Gregory Szorc34c863a2012-03-21 03:54:29 +00001346/**
whitequarkb4861072018-09-18 01:47:37 +00001347 * Determine whether a structure is literal.
1348 *
1349 * @see llvm::StructType::isLiteral()
1350 */
1351LLVMBool LLVMIsLiteralStruct(LLVMTypeRef StructTy);
1352
1353/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001354 * @}
1355 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001356
Gregory Szorc34c863a2012-03-21 03:54:29 +00001357/**
1358 * @defgroup LLVMCCoreTypeSequential Sequential Types
1359 *
1360 * Sequential types represents "arrays" of types. This is a super class
1361 * for array, vector, and pointer types.
1362 *
1363 * @{
1364 */
1365
1366/**
1367 * Obtain the type of elements within a sequential type.
1368 *
1369 * This works on array, vector, and pointer types.
1370 *
1371 * @see llvm::SequentialType::getElementType()
1372 */
1373LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1374
1375/**
whitequarkf6059fd2017-06-05 11:49:52 +00001376 * Returns type's subtypes
1377 *
1378 * @see llvm::Type::subtypes()
1379 */
1380void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr);
1381
1382/**
1383 * Return the number of types in the derived type.
1384 *
1385 * @see llvm::Type::getNumContainedTypes()
1386 */
1387unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp);
1388
1389/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001390 * Create a fixed size array type that refers to a specific type.
1391 *
1392 * The created type will exist in the context that its element type
1393 * exists in.
1394 *
1395 * @see llvm::ArrayType::get()
1396 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001397LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001398
1399/**
1400 * Obtain the length of an array type.
1401 *
1402 * This only works on types that represent arrays.
1403 *
1404 * @see llvm::ArrayType::getNumElements()
1405 */
1406unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1407
1408/**
1409 * Create a pointer type that points to a defined type.
1410 *
1411 * The created type will exist in the context that its pointee type
1412 * exists in.
1413 *
1414 * @see llvm::PointerType::get()
1415 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001416LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001417
1418/**
1419 * Obtain the address space of a pointer type.
1420 *
1421 * This only works on types that represent pointers.
1422 *
1423 * @see llvm::PointerType::getAddressSpace()
1424 */
1425unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1426
1427/**
1428 * Create a vector type that contains a defined type and has a specific
1429 * number of elements.
1430 *
1431 * The created type will exist in the context thats its element type
1432 * exists in.
1433 *
1434 * @see llvm::VectorType::get()
1435 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001436LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001437
Gregory Szorc34c863a2012-03-21 03:54:29 +00001438/**
1439 * Obtain the number of elements in a vector type.
1440 *
1441 * This only works on types that represent vectors.
1442 *
1443 * @see llvm::VectorType::getNumElements()
1444 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001445unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1446
Gregory Szorc34c863a2012-03-21 03:54:29 +00001447/**
1448 * @}
1449 */
1450
1451/**
1452 * @defgroup LLVMCCoreTypeOther Other Types
1453 *
1454 * @{
1455 */
1456
1457/**
1458 * Create a void type in a context.
1459 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001460LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001461
1462/**
1463 * Create a label type in a context.
1464 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001465LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001466
1467/**
1468 * Create a X86 MMX type in a context.
1469 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001470LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001471
Gregory Szorc34c863a2012-03-21 03:54:29 +00001472/**
whitequark131f98f2017-10-27 11:51:40 +00001473 * Create a token type in a context.
1474 */
1475LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C);
1476
1477/**
1478 * Create a metadata type in a context.
1479 */
1480LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C);
1481
1482/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001483 * These are similar to the above functions except they operate on the
1484 * global context.
1485 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001486LLVMTypeRef LLVMVoidType(void);
1487LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001488LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001489
Gregory Szorc34c863a2012-03-21 03:54:29 +00001490/**
1491 * @}
1492 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001493
Gregory Szorc34c863a2012-03-21 03:54:29 +00001494/**
1495 * @}
1496 */
1497
1498/**
1499 * @defgroup LLVMCCoreValues Values
1500 *
1501 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001502 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001503 *
1504 * LLVMValueRef essentially represents llvm::Value. There is a rich
1505 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001506 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001507 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001508 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001509 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1510 * functions are defined by a macro, so it isn't obvious which are
1511 * available by looking at the Doxygen source code. Instead, look at the
1512 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1513 * of value names given. These value names also correspond to classes in
1514 * the llvm::Value hierarchy.
1515 *
1516 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001517 */
1518
Gordon Henriksen29e38942008-12-19 18:39:45 +00001519#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1520 macro(Argument) \
1521 macro(BasicBlock) \
1522 macro(InlineAsm) \
1523 macro(User) \
1524 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001525 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001526 macro(ConstantAggregateZero) \
1527 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001528 macro(ConstantDataSequential) \
1529 macro(ConstantDataArray) \
1530 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001531 macro(ConstantExpr) \
1532 macro(ConstantFP) \
1533 macro(ConstantInt) \
1534 macro(ConstantPointerNull) \
1535 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001536 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001537 macro(ConstantVector) \
1538 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001539 macro(GlobalAlias) \
whitequarkd299b2c2018-09-18 00:01:12 +00001540 macro(GlobalIFunc) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001541 macro(GlobalObject) \
1542 macro(Function) \
1543 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001544 macro(UndefValue) \
1545 macro(Instruction) \
1546 macro(BinaryOperator) \
1547 macro(CallInst) \
1548 macro(IntrinsicInst) \
1549 macro(DbgInfoIntrinsic) \
Hsiangkai Wangef72e482018-08-06 03:59:47 +00001550 macro(DbgVariableIntrinsic) \
1551 macro(DbgDeclareInst) \
1552 macro(DbgLabelInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001553 macro(MemIntrinsic) \
1554 macro(MemCpyInst) \
1555 macro(MemMoveInst) \
1556 macro(MemSetInst) \
1557 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001558 macro(FCmpInst) \
1559 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001560 macro(ExtractElementInst) \
1561 macro(GetElementPtrInst) \
1562 macro(InsertElementInst) \
1563 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001564 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001565 macro(PHINode) \
1566 macro(SelectInst) \
1567 macro(ShuffleVectorInst) \
1568 macro(StoreInst) \
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00001569 macro(BranchInst) \
1570 macro(IndirectBrInst) \
1571 macro(InvokeInst) \
1572 macro(ReturnInst) \
1573 macro(SwitchInst) \
1574 macro(UnreachableInst) \
1575 macro(ResumeInst) \
1576 macro(CleanupReturnInst) \
1577 macro(CatchReturnInst) \
Nick Lewyckyf57e9682019-09-26 00:58:55 +00001578 macro(CatchSwitchInst) \
1579 macro(CallBrInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001580 macro(FuncletPadInst) \
1581 macro(CatchPadInst) \
1582 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001583 macro(UnaryInstruction) \
1584 macro(AllocaInst) \
1585 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001586 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001587 macro(BitCastInst) \
1588 macro(FPExtInst) \
1589 macro(FPToSIInst) \
1590 macro(FPToUIInst) \
1591 macro(FPTruncInst) \
1592 macro(IntToPtrInst) \
1593 macro(PtrToIntInst) \
1594 macro(SExtInst) \
1595 macro(SIToFPInst) \
1596 macro(TruncInst) \
1597 macro(UIToFPInst) \
1598 macro(ZExtInst) \
1599 macro(ExtractValueInst) \
1600 macro(LoadInst) \
Nick Lewyckyf57e9682019-09-26 00:58:55 +00001601 macro(VAArgInst) \
1602 macro(AtomicCmpXchgInst) \
1603 macro(AtomicRMWInst) \
1604 macro(FenceInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001605
Gregory Szorc34c863a2012-03-21 03:54:29 +00001606/**
1607 * @defgroup LLVMCCoreValueGeneral General APIs
1608 *
1609 * Functions in this section work on all LLVMValueRef instances,
1610 * regardless of their sub-type. They correspond to functions available
1611 * on llvm::Value.
1612 *
1613 * @{
1614 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001615
Gregory Szorc34c863a2012-03-21 03:54:29 +00001616/**
1617 * Obtain the type of a value.
1618 *
1619 * @see llvm::Value::getType()
1620 */
1621LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1622
1623/**
Peter Zotov3e4561c2016-04-06 22:21:29 +00001624 * Obtain the enumerated type of a Value instance.
1625 *
1626 * @see llvm::Value::getValueID()
1627 */
1628LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
1629
1630/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001631 * Obtain the string name of a value.
1632 *
1633 * @see llvm::Value::getName()
1634 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001635const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001636
1637/**
1638 * Set the string name of a value.
1639 *
1640 * @see llvm::Value::setName()
1641 */
Robert Widmann025c78f2018-05-19 15:08:36 +00001642void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001643
1644/**
1645 * Dump a representation of a value to stderr.
1646 *
1647 * @see llvm::Value::dump()
1648 */
1649void LLVMDumpValue(LLVMValueRef Val);
1650
1651/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001652 * Return a string representation of the value. Use
1653 * LLVMDisposeMessage to free the string.
1654 *
1655 * @see llvm::Value::print()
1656 */
1657char *LLVMPrintValueToString(LLVMValueRef Val);
1658
1659/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001660 * Replace all uses of a value with another one.
1661 *
1662 * @see llvm::Value::replaceAllUsesWith()
1663 */
1664void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1665
1666/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001667 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001668 */
1669LLVMBool LLVMIsConstant(LLVMValueRef Val);
1670
1671/**
1672 * Determine whether a value instance is undefined.
1673 */
1674LLVMBool LLVMIsUndef(LLVMValueRef Val);
1675
1676/**
1677 * Convert value instances between types.
1678 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001679 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001680 * series of functions allows you to cast an instance to a specific
1681 * type.
1682 *
1683 * If the cast is not valid for the specified type, NULL is returned.
1684 *
1685 * @see llvm::dyn_cast_or_null<>
1686 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001687#define LLVM_DECLARE_VALUE_CAST(name) \
1688 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1689LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1690
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001691LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1692LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1693
Robert Widmann025c78f2018-05-19 15:08:36 +00001694/** Deprecated: Use LLVMGetValueName2 instead. */
1695const char *LLVMGetValueName(LLVMValueRef Val);
1696/** Deprecated: Use LLVMSetValueName2 instead. */
1697void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1698
Gregory Szorc34c863a2012-03-21 03:54:29 +00001699/**
1700 * @}
1701 */
1702
1703/**
1704 * @defgroup LLVMCCoreValueUses Usage
1705 *
1706 * This module defines functions that allow you to inspect the uses of a
1707 * LLVMValueRef.
1708 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001709 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001710 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1711 * llvm::User and llvm::Value.
1712 *
1713 * @{
1714 */
1715
1716/**
1717 * Obtain the first use of a value.
1718 *
1719 * Uses are obtained in an iterator fashion. First, call this function
1720 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001721 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001722 * LLVMGetNextUse() returns NULL.
1723 *
1724 * @see llvm::Value::use_begin()
1725 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001726LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001727
1728/**
1729 * Obtain the next use of a value.
1730 *
1731 * This effectively advances the iterator. It returns NULL if you are on
1732 * the final use and no more are available.
1733 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001734LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001735
1736/**
1737 * Obtain the user value for a user.
1738 *
1739 * The returned value corresponds to a llvm::User type.
1740 *
1741 * @see llvm::Use::getUser()
1742 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001743LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001744
1745/**
1746 * Obtain the value this use corresponds to.
1747 *
1748 * @see llvm::Use::get().
1749 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001750LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001751
Gregory Szorc34c863a2012-03-21 03:54:29 +00001752/**
1753 * @}
1754 */
1755
1756/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001757 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001758 *
1759 * Function in this group pertain to LLVMValueRef instances that descent
1760 * from llvm::User. This includes constants, instructions, and
1761 * operators.
1762 *
1763 * @{
1764 */
1765
1766/**
1767 * Obtain an operand at a specific index in a llvm::User value.
1768 *
1769 * @see llvm::User::getOperand()
1770 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001771LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001772
1773/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001774 * Obtain the use of an operand at a specific index in a llvm::User value.
1775 *
1776 * @see llvm::User::getOperandUse()
1777 */
1778LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1779
1780/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001781 * Set an operand at a specific index in a llvm::User value.
1782 *
1783 * @see llvm::User::setOperand()
1784 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001785void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001786
1787/**
1788 * Obtain the number of operands in a llvm::User value.
1789 *
1790 * @see llvm::User::getNumOperands()
1791 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001792int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001793
Gregory Szorc34c863a2012-03-21 03:54:29 +00001794/**
1795 * @}
1796 */
1797
1798/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001799 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001800 *
1801 * This section contains APIs for interacting with LLVMValueRef that
1802 * correspond to llvm::Constant instances.
1803 *
1804 * These functions will work for any LLVMValueRef in the llvm::Constant
1805 * class hierarchy.
1806 *
1807 * @{
1808 */
1809
1810/**
1811 * Obtain a constant value referring to the null instance of a type.
1812 *
1813 * @see llvm::Constant::getNullValue()
1814 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001815LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001816
1817/**
1818 * Obtain a constant value referring to the instance of a type
1819 * consisting of all ones.
1820 *
1821 * This is only valid for integer types.
1822 *
1823 * @see llvm::Constant::getAllOnesValue()
1824 */
1825LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1826
1827/**
1828 * Obtain a constant value referring to an undefined value of a type.
1829 *
1830 * @see llvm::UndefValue::get()
1831 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001832LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001833
1834/**
1835 * Determine whether a value instance is null.
1836 *
1837 * @see llvm::Constant::isNullValue()
1838 */
Chris Lattner25963c62010-01-09 22:27:07 +00001839LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001840
1841/**
1842 * Obtain a constant that is a constant pointer pointing to NULL for a
1843 * specified type.
1844 */
Chris Lattner7f318242009-07-06 17:29:59 +00001845LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001846
Gregory Szorc34c863a2012-03-21 03:54:29 +00001847/**
1848 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1849 *
1850 * Functions in this group model LLVMValueRef instances that correspond
1851 * to constants referring to scalar types.
1852 *
1853 * For integer types, the LLVMTypeRef parameter should correspond to a
1854 * llvm::IntegerType instance and the returned LLVMValueRef will
1855 * correspond to a llvm::ConstantInt.
1856 *
1857 * For floating point types, the LLVMTypeRef returned corresponds to a
1858 * llvm::ConstantFP.
1859 *
1860 * @{
1861 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001862
Gregory Szorc34c863a2012-03-21 03:54:29 +00001863/**
1864 * Obtain a constant value for an integer type.
1865 *
1866 * The returned value corresponds to a llvm::ConstantInt.
1867 *
1868 * @see llvm::ConstantInt::get()
1869 *
1870 * @param IntTy Integer type to obtain value of.
1871 * @param N The value the returned instance should refer to.
1872 * @param SignExtend Whether to sign extend the produced value.
1873 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001874LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001875 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001876
1877/**
1878 * Obtain a constant value for an integer of arbitrary precision.
1879 *
1880 * @see llvm::ConstantInt::get()
1881 */
Chris Lattner4329e072010-11-23 02:47:22 +00001882LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1883 unsigned NumWords,
1884 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001885
1886/**
1887 * Obtain a constant value for an integer parsed from a string.
1888 *
1889 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1890 * string's length is available, it is preferred to call that function
1891 * instead.
1892 *
1893 * @see llvm::ConstantInt::get()
1894 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001895LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1896 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001897
1898/**
1899 * Obtain a constant value for an integer parsed from a string with
1900 * specified length.
1901 *
1902 * @see llvm::ConstantInt::get()
1903 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001904LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1905 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001906
1907/**
1908 * Obtain a constant value referring to a double floating point value.
1909 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001910LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001911
1912/**
1913 * Obtain a constant for a floating point value parsed from a string.
1914 *
1915 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1916 * should be used if the input string's length is known.
1917 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001918LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001919
1920/**
1921 * Obtain a constant for a floating point value parsed from a string.
1922 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001923LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1924 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001925
1926/**
1927 * Obtain the zero extended value for an integer constant value.
1928 *
1929 * @see llvm::ConstantInt::getZExtValue()
1930 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001931unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001932
1933/**
1934 * Obtain the sign extended value for an integer constant value.
1935 *
1936 * @see llvm::ConstantInt::getSExtValue()
1937 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001938long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001939
Gregory Szorc34c863a2012-03-21 03:54:29 +00001940/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001941 * Obtain the double value for an floating point constant value.
1942 * losesInfo indicates if some precision was lost in the conversion.
1943 *
1944 * @see llvm::ConstantFP::getDoubleValue
1945 */
1946double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1947
1948/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001949 * @}
1950 */
1951
1952/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001953 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1954 *
1955 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001956 *
1957 * @{
1958 */
1959
1960/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001961 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001962 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001963 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001964 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001965LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001966 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001967
1968/**
1969 * Create a ConstantDataSequential with string content in the global context.
1970 *
1971 * This is the same as LLVMConstStringInContext except it operates on the
1972 * global context.
1973 *
1974 * @see LLVMConstStringInContext()
1975 * @see llvm::ConstantDataArray::getString()
1976 */
1977LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1978 LLVMBool DontNullTerminate);
1979
1980/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001981 * Returns true if the specified constant is an array of i8.
1982 *
1983 * @see ConstantDataSequential::getAsString()
1984 */
1985LLVMBool LLVMIsConstantString(LLVMValueRef c);
1986
1987/**
1988 * Get the given constant data sequential as a string.
1989 *
1990 * @see ConstantDataSequential::getAsString()
1991 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00001992const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001993
1994/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001995 * Create an anonymous ConstantStruct with the specified values.
1996 *
1997 * @see llvm::ConstantStruct::getAnon()
1998 */
1999LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002000 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00002001 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002002
Gregory Szorc52d26602012-03-21 07:28:27 +00002003/**
2004 * Create a ConstantStruct in the global Context.
2005 *
2006 * This is the same as LLVMConstStructInContext except it operates on the
2007 * global Context.
2008 *
2009 * @see LLVMConstStructInContext()
2010 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002011LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00002012 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00002013
2014/**
2015 * Create a ConstantArray from values.
2016 *
2017 * @see llvm::ConstantArray::get()
2018 */
2019LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
2020 LLVMValueRef *ConstantVals, unsigned Length);
2021
2022/**
2023 * Create a non-anonymous ConstantStruct from values.
2024 *
2025 * @see llvm::ConstantStruct::get()
2026 */
Rafael Espindola784ad242011-07-14 19:09:08 +00002027LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
2028 LLVMValueRef *ConstantVals,
2029 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00002030
2031/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00002032 * Get an element at specified index as a constant.
2033 *
2034 * @see ConstantDataSequential::getElementAsConstant()
2035 */
Amaury Sechet006ce632016-03-13 00:54:40 +00002036LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
Peter Zotovf9aa8822014-08-03 23:54:16 +00002037
2038/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002039 * Create a ConstantVector from values.
2040 *
2041 * @see llvm::ConstantVector::get()
2042 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00002043LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002044
Gregory Szorc52d26602012-03-21 07:28:27 +00002045/**
2046 * @}
2047 */
2048
2049/**
2050 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
2051 *
2052 * Functions in this group correspond to APIs on llvm::ConstantExpr.
2053 *
2054 * @see llvm::ConstantExpr.
2055 *
2056 * @{
2057 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002058LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002059LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002060LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
2061LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002062LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
2063LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002064LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002065LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
2066LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002067LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002068LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002069LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002070LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002071LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2072LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002073LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002074LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002075LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2076LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002077LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002078LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Manuel Jacob49fafb12016-10-04 23:32:42 +00002079LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002080LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002081LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002082LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2083LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2084LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2085LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2086LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2087LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2088LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2089LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
2090 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2091LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
2092 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2093LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2094LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2095LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2096LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
2097 LLVMValueRef *ConstantIndices, unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002098LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2099 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00002100LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
2101 LLVMValueRef *ConstantIndices,
2102 unsigned NumIndices);
James Y Knight544fa422019-01-14 21:39:35 +00002103LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2104 LLVMValueRef *ConstantIndices,
2105 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002106LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2107LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2108LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2109LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2110LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2111LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2112LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2113LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2114LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2115LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2116LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2117LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002118LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002119LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
2120 LLVMTypeRef ToType);
2121LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
2122 LLVMTypeRef ToType);
2123LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
2124 LLVMTypeRef ToType);
2125LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
2126 LLVMTypeRef ToType);
2127LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00002128 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00002129LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002130LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
2131 LLVMValueRef ConstantIfTrue,
2132 LLVMValueRef ConstantIfFalse);
2133LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
2134 LLVMValueRef IndexConstant);
2135LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
2136 LLVMValueRef ElementValueConstant,
2137 LLVMValueRef IndexConstant);
2138LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
2139 LLVMValueRef VectorBConstant,
2140 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00002141LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
2142 unsigned NumIdx);
2143LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
2144 LLVMValueRef ElementValueConstant,
2145 unsigned *IdxList, unsigned NumIdx);
Robert Widmannf108d572018-04-06 02:31:29 +00002146LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
2147
2148/** Deprecated: Use LLVMGetInlineAsm instead. */
Chris Lattner25963c62010-01-09 22:27:07 +00002149LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00002150 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00002151 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00002152
Gregory Szorc52d26602012-03-21 07:28:27 +00002153/**
2154 * @}
2155 */
2156
2157/**
2158 * @defgroup LLVMCCoreValueConstantGlobals Global Values
2159 *
2160 * This group contains functions that operate on global values. Functions in
2161 * this group relate to functions in the llvm::GlobalValue class tree.
2162 *
2163 * @see llvm::GlobalValue
2164 *
2165 * @{
2166 */
2167
Gordon Henriksen265f7802008-03-19 01:11:35 +00002168LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00002169LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002170LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
2171void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
2172const char *LLVMGetSection(LLVMValueRef Global);
2173void LLVMSetSection(LLVMValueRef Global, const char *Section);
2174LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
2175void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00002176LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
2177void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002178LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
2179void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
2180
Robert Widmanne63a12c2018-09-28 20:54:29 +00002181/**
2182 * Returns the "value type" of a global value. This differs from the formal
2183 * type of a global value which is always a pointer type.
2184 *
2185 * @see llvm::GlobalValue::getValueType()
2186 */
2187LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
2188
Robert Widmann4bb481b2018-03-14 06:45:51 +00002189/** Deprecated: Use LLVMGetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002190LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
Robert Widmann4bb481b2018-03-14 06:45:51 +00002191/** Deprecated: Use LLVMSetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00002192void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002193
2194/**
2195 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
2196 *
2197 * Functions in this group only apply to values with alignment, i.e.
2198 * global variables, load and store instructions.
2199 */
2200
2201/**
2202 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002203 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002204 * @see llvm::LoadInst::getAlignment()
2205 * @see llvm::StoreInst::getAlignment()
2206 * @see llvm::GlobalValue::getAlignment()
2207 */
2208unsigned LLVMGetAlignment(LLVMValueRef V);
2209
2210/**
2211 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00002212 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00002213 * @see llvm::LoadInst::setAlignment()
2214 * @see llvm::StoreInst::setAlignment()
2215 * @see llvm::GlobalValue::setAlignment()
2216 */
2217void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
2218
2219/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00002220 * Sets a metadata attachment, erasing the existing metadata attachment if
2221 * it already exists for the given kind.
2222 *
2223 * @see llvm::GlobalObject::setMetadata()
2224 */
2225void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind,
2226 LLVMMetadataRef MD);
2227
2228/**
2229 * Erases a metadata attachment of the given kind if it exists.
2230 *
2231 * @see llvm::GlobalObject::eraseMetadata()
2232 */
2233void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind);
2234
2235/**
2236 * Removes all metadata attachments from this value.
2237 *
2238 * @see llvm::GlobalObject::clearMetadata()
2239 */
2240void LLVMGlobalClearMetadata(LLVMValueRef Global);
2241
2242/**
2243 * Retrieves an array of metadata entries representing the metadata attached to
2244 * this value. The caller is responsible for freeing this array by calling
2245 * \c LLVMDisposeValueMetadataEntries.
2246 *
2247 * @see llvm::GlobalObject::getAllMetadata()
2248 */
2249LLVMValueMetadataEntry *LLVMGlobalCopyAllMetadata(LLVMValueRef Value,
2250 size_t *NumEntries);
2251
2252/**
2253 * Destroys value metadata entries.
2254 */
2255void LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries);
2256
2257/**
2258 * Returns the kind of a value metadata entry at a specific index.
2259 */
2260unsigned LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries,
2261 unsigned Index);
2262
2263/**
2264 * Returns the underlying metadata node of a value metadata entry at a
2265 * specific index.
2266 */
2267LLVMMetadataRef
2268LLVMValueMetadataEntriesGetMetadata(LLVMValueMetadataEntry *Entries,
2269 unsigned Index);
2270
2271/**
Amaury Sechet83550102016-02-14 08:58:49 +00002272 * @}
2273 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002274
Gregory Szorc52d26602012-03-21 07:28:27 +00002275/**
2276 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
2277 *
2278 * This group contains functions that operate on global variable values.
2279 *
2280 * @see llvm::GlobalVariable
2281 *
2282 * @{
2283 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00002284LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00002285LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
2286 const char *Name,
2287 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00002288LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002289LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
2290LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
2291LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
2292LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002293void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002294LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
2295void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00002296LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
2297void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
2298LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
2299void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00002300LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
2301void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
2302LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
2303void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002304
Gregory Szorc52d26602012-03-21 07:28:27 +00002305/**
2306 * @}
2307 */
2308
2309/**
2310 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
2311 *
2312 * This group contains function that operate on global alias values.
2313 *
2314 * @see llvm::GlobalAlias
2315 *
2316 * @{
2317 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00002318LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
2319 const char *Name);
2320
Gregory Szorc34c863a2012-03-21 03:54:29 +00002321/**
Robert Widmann360d6e32018-05-20 23:49:08 +00002322 * Obtain a GlobalAlias value from a Module by its name.
2323 *
2324 * The returned value corresponds to a llvm::GlobalAlias value.
2325 *
2326 * @see llvm::Module::getNamedAlias()
2327 */
2328LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M,
2329 const char *Name, size_t NameLen);
2330
2331/**
2332 * Obtain an iterator to the first GlobalAlias in a Module.
2333 *
2334 * @see llvm::Module::alias_begin()
2335 */
2336LLVMValueRef LLVMGetFirstGlobalAlias(LLVMModuleRef M);
2337
2338/**
2339 * Obtain an iterator to the last GlobalAlias in a Module.
2340 *
2341 * @see llvm::Module::alias_end()
2342 */
2343LLVMValueRef LLVMGetLastGlobalAlias(LLVMModuleRef M);
2344
2345/**
2346 * Advance a GlobalAlias iterator to the next GlobalAlias.
2347 *
2348 * Returns NULL if the iterator was already at the end and there are no more
2349 * global aliases.
2350 */
2351LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA);
2352
2353/**
2354 * Decrement a GlobalAlias iterator to the previous GlobalAlias.
2355 *
2356 * Returns NULL if the iterator was already at the beginning and there are
2357 * no previous global aliases.
2358 */
2359LLVMValueRef LLVMGetPreviousGlobalAlias(LLVMValueRef GA);
2360
2361/**
2362 * Retrieve the target value of an alias.
2363 */
2364LLVMValueRef LLVMAliasGetAliasee(LLVMValueRef Alias);
2365
2366/**
2367 * Set the target value of an alias.
2368 */
2369void LLVMAliasSetAliasee(LLVMValueRef Alias, LLVMValueRef Aliasee);
2370
2371/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002372 * @}
2373 */
2374
2375/**
2376 * @defgroup LLVMCCoreValueFunction Function values
2377 *
2378 * Functions in this group operate on LLVMValueRef instances that
2379 * correspond to llvm::Function instances.
2380 *
2381 * @see llvm::Function
2382 *
2383 * @{
2384 */
2385
2386/**
2387 * Remove a function from its containing module and deletes it.
2388 *
2389 * @see llvm::Function::eraseFromParent()
2390 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002391void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002392
2393/**
Amaury Sechete39e8532016-02-18 20:38:32 +00002394 * Check whether the given function has a personality function.
2395 *
2396 * @see llvm::Function::hasPersonalityFn()
2397 */
2398LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
2399
2400/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00002401 * Obtain the personality function attached to the function.
2402 *
2403 * @see llvm::Function::getPersonalityFn()
2404 */
2405LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
2406
2407/**
2408 * Set the personality function attached to the function.
2409 *
2410 * @see llvm::Function::setPersonalityFn()
2411 */
2412void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
2413
2414/**
Robert Widmann9d94a682019-03-25 20:58:58 +00002415 * Obtain the intrinsic ID number which matches the given function name.
2416 *
2417 * @see llvm::Function::lookupIntrinsicID()
2418 */
2419unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen);
2420
2421/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002422 * Obtain the ID number from a function instance.
2423 *
2424 * @see llvm::Function::getIntrinsicID()
2425 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002426unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002427
2428/**
Robert Widmannd36f3b02018-11-06 01:38:14 +00002429 * Create or insert the declaration of an intrinsic. For overloaded intrinsics,
2430 * parameter types must be provided to uniquely identify an overload.
2431 *
2432 * @see llvm::Intrinsic::getDeclaration()
2433 */
2434LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
2435 unsigned ID,
2436 LLVMTypeRef *ParamTypes,
2437 size_t ParamCount);
2438
2439/**
2440 * Retrieves the type of an intrinsic. For overloaded intrinsics, parameter
2441 * types must be provided to uniquely identify an overload.
2442 *
2443 * @see llvm::Intrinsic::getType()
2444 */
2445LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID,
2446 LLVMTypeRef *ParamTypes, size_t ParamCount);
2447
2448/**
2449 * Retrieves the name of an intrinsic.
2450 *
2451 * @see llvm::Intrinsic::getName()
2452 */
2453const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength);
2454
2455/**
2456 * Copies the name of an overloaded intrinsic identified by a given list of
2457 * parameter types.
2458 *
2459 * Unlike LLVMIntrinsicGetName, the caller is responsible for freeing the
2460 * returned string.
2461 *
2462 * @see llvm::Intrinsic::getName()
2463 */
2464const char *LLVMIntrinsicCopyOverloadedName(unsigned ID,
2465 LLVMTypeRef *ParamTypes,
2466 size_t ParamCount,
2467 size_t *NameLength);
2468
2469/**
2470 * Obtain if the intrinsic identified by the given ID is overloaded.
2471 *
2472 * @see llvm::Intrinsic::isOverloaded()
2473 */
2474LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID);
2475
2476/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002477 * Obtain the calling function of a function.
2478 *
2479 * The returned value corresponds to the LLVMCallConv enumeration.
2480 *
2481 * @see llvm::Function::getCallingConv()
2482 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002483unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002484
2485/**
2486 * Set the calling convention of a function.
2487 *
2488 * @see llvm::Function::setCallingConv()
2489 *
2490 * @param Fn Function to operate on
2491 * @param CC LLVMCallConv to set calling convention to
2492 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002493void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002494
2495/**
2496 * Obtain the name of the garbage collector to use during code
2497 * generation.
2498 *
2499 * @see llvm::Function::getGC()
2500 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002501const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002502
2503/**
2504 * Define the garbage collector to use during code generation.
2505 *
2506 * @see llvm::Function::setGC()
2507 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002508void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002509
2510/**
2511 * Add an attribute to a function.
2512 *
2513 * @see llvm::Function::addAttribute()
2514 */
Amaury Sechet5db224e2016-06-12 06:17:24 +00002515void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2516 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00002517unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx);
2518void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2519 LLVMAttributeRef *Attrs);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002520LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
2521 LLVMAttributeIndex Idx,
2522 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002523LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
2524 LLVMAttributeIndex Idx,
2525 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002526void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2527 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002528void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2529 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002530
Gregory Szorc34c863a2012-03-21 03:54:29 +00002531/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00002532 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00002533 * @see llvm::AttrBuilder::addAttribute()
2534 */
2535void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
2536 const char *V);
2537
2538/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002539 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
2540 *
2541 * Functions in this group relate to arguments/parameters on functions.
2542 *
2543 * Functions in this group expect LLVMValueRef instances that correspond
2544 * to llvm::Function instances.
2545 *
2546 * @{
2547 */
2548
2549/**
2550 * Obtain the number of parameters in a function.
2551 *
2552 * @see llvm::Function::arg_size()
2553 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002554unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002555
2556/**
2557 * Obtain the parameters in a function.
2558 *
2559 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
2560 * at least LLVMCountParams() long. This array will be filled with
2561 * LLVMValueRef instances which correspond to the parameters the
2562 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
2563 * instance.
2564 *
2565 * @see llvm::Function::arg_begin()
2566 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002567void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002568
2569/**
2570 * Obtain the parameter at the specified index.
2571 *
2572 * Parameters are indexed from 0.
2573 *
2574 * @see llvm::Function::arg_begin()
2575 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002576LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002577
2578/**
2579 * Obtain the function to which this argument belongs.
2580 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002581 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002582 * that corresponds to a llvm::Attribute.
2583 *
2584 * The returned LLVMValueRef is the llvm::Function to which this
2585 * argument belongs.
2586 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002587LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002588
2589/**
2590 * Obtain the first parameter to a function.
2591 *
2592 * @see llvm::Function::arg_begin()
2593 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002594LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002595
2596/**
2597 * Obtain the last parameter to a function.
2598 *
2599 * @see llvm::Function::arg_end()
2600 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002601LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002602
2603/**
2604 * Obtain the next parameter to a function.
2605 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002606 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002607 * actually a wrapped iterator) and obtains the next parameter from the
2608 * underlying iterator.
2609 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002610LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002611
2612/**
2613 * Obtain the previous parameter to a function.
2614 *
2615 * This is the opposite of LLVMGetNextParam().
2616 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002617LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002618
2619/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002620 * Set the alignment for a function parameter.
2621 *
2622 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002623 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002624 */
Amaury Sechet81243a72016-05-01 01:42:34 +00002625void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002626
Gregory Szorc34c863a2012-03-21 03:54:29 +00002627/**
2628 * @}
2629 */
2630
2631/**
Robert Widmannd5444cc2019-02-05 18:05:44 +00002632 * @defgroup LLVMCCoreValueGlobalIFunc IFuncs
2633 *
2634 * Functions in this group relate to indirect functions.
2635 *
2636 * Functions in this group expect LLVMValueRef instances that correspond
2637 * to llvm::GlobalIFunc instances.
2638 *
2639 * @{
2640 */
2641
2642/**
2643 * Add a global indirect function to a module under a specified name.
2644 *
2645 * @see llvm::GlobalIFunc::create()
2646 */
2647LLVMValueRef LLVMAddGlobalIFunc(LLVMModuleRef M,
2648 const char *Name, size_t NameLen,
2649 LLVMTypeRef Ty, unsigned AddrSpace,
2650 LLVMValueRef Resolver);
2651
2652/**
2653 * Obtain a GlobalIFunc value from a Module by its name.
2654 *
2655 * The returned value corresponds to a llvm::GlobalIFunc value.
2656 *
2657 * @see llvm::Module::getNamedIFunc()
2658 */
2659LLVMValueRef LLVMGetNamedGlobalIFunc(LLVMModuleRef M,
2660 const char *Name, size_t NameLen);
2661
2662/**
2663 * Obtain an iterator to the first GlobalIFunc in a Module.
2664 *
2665 * @see llvm::Module::ifunc_begin()
2666 */
2667LLVMValueRef LLVMGetFirstGlobalIFunc(LLVMModuleRef M);
2668
2669/**
2670 * Obtain an iterator to the last GlobalIFunc in a Module.
2671 *
2672 * @see llvm::Module::ifunc_end()
2673 */
2674LLVMValueRef LLVMGetLastGlobalIFunc(LLVMModuleRef M);
2675
2676/**
2677 * Advance a GlobalIFunc iterator to the next GlobalIFunc.
2678 *
2679 * Returns NULL if the iterator was already at the end and there are no more
2680 * global aliases.
2681 */
2682LLVMValueRef LLVMGetNextGlobalIFunc(LLVMValueRef IFunc);
2683
2684/**
2685 * Decrement a GlobalIFunc iterator to the previous GlobalIFunc.
2686 *
2687 * Returns NULL if the iterator was already at the beginning and there are
2688 * no previous global aliases.
2689 */
2690LLVMValueRef LLVMGetPreviousGlobalIFunc(LLVMValueRef IFunc);
2691
2692/**
2693 * Retrieves the resolver function associated with this indirect function, or
2694 * NULL if it doesn't not exist.
2695 *
2696 * @see llvm::GlobalIFunc::getResolver()
2697 */
2698LLVMValueRef LLVMGetGlobalIFuncResolver(LLVMValueRef IFunc);
2699
2700/**
2701 * Sets the resolver function associated with this indirect function.
2702 *
2703 * @see llvm::GlobalIFunc::setResolver()
2704 */
2705void LLVMSetGlobalIFuncResolver(LLVMValueRef IFunc, LLVMValueRef Resolver);
2706
2707/**
2708 * Remove a global indirect function from its parent module and delete it.
2709 *
2710 * @see llvm::GlobalIFunc::eraseFromParent()
2711 */
2712void LLVMEraseGlobalIFunc(LLVMValueRef IFunc);
2713
2714/**
2715 * Remove a global indirect function from its parent module.
2716 *
2717 * This unlinks the global indirect function from its containing module but
2718 * keeps it alive.
2719 *
2720 * @see llvm::GlobalIFunc::removeFromParent()
2721 */
2722void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc);
2723
2724/**
2725 * @}
2726 */
2727
2728/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002729 * @}
2730 */
2731
2732/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002733 * @}
2734 */
2735
2736/**
2737 * @}
2738 */
2739
2740/**
2741 * @defgroup LLVMCCoreValueMetadata Metadata
2742 *
2743 * @{
2744 */
2745
2746/**
Robert Widmann09c5b882019-04-24 17:05:08 +00002747 * Create an MDString value from a given string value.
Gregory Szorc52d26602012-03-21 07:28:27 +00002748 *
Robert Widmann09c5b882019-04-24 17:05:08 +00002749 * The MDString value does not take ownership of the given string, it remains
2750 * the responsibility of the caller to free it.
Gregory Szorc52d26602012-03-21 07:28:27 +00002751 *
Robert Widmann09c5b882019-04-24 17:05:08 +00002752 * @see llvm::MDString::get()
Gregory Szorc52d26602012-03-21 07:28:27 +00002753 */
Robert Widmann09c5b882019-04-24 17:05:08 +00002754LLVMMetadataRef LLVMMDStringInContext2(LLVMContextRef C, const char *Str,
2755 size_t SLen);
Gregory Szorc52d26602012-03-21 07:28:27 +00002756
2757/**
Robert Widmann09c5b882019-04-24 17:05:08 +00002758 * Create an MDNode value with the given array of operands.
Gregory Szorc52d26602012-03-21 07:28:27 +00002759 *
Robert Widmann09c5b882019-04-24 17:05:08 +00002760 * @see llvm::MDNode::get()
Gregory Szorc52d26602012-03-21 07:28:27 +00002761 */
Robert Widmann09c5b882019-04-24 17:05:08 +00002762LLVMMetadataRef LLVMMDNodeInContext2(LLVMContextRef C, LLVMMetadataRef *MDs,
2763 size_t Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00002764
2765/**
Amaury Sechetf8429752017-04-17 11:52:54 +00002766 * Obtain a Metadata as a Value.
2767 */
2768LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
2769
2770/**
2771 * Obtain a Value as a Metadata.
2772 */
2773LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
2774
2775/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002776 * Obtain the underlying string from a MDString value.
2777 *
2778 * @param V Instance to obtain string from.
NAKAMURA Takumie4a77052016-04-04 11:54:48 +00002779 * @param Length Memory address which will hold length of returned string.
Gregory Szorc52d26602012-03-21 07:28:27 +00002780 * @return String data in MDString.
2781 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002782const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
Gregory Szorc52d26602012-03-21 07:28:27 +00002783
2784/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002785 * Obtain the number of operands from an MDNode value.
2786 *
2787 * @param V MDNode to get number of operands from.
2788 * @return Number of operands of the MDNode.
2789 */
2790unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2791
2792/**
2793 * Obtain the given MDNode's operands.
2794 *
2795 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2796 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2797 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2798 * MDNode's operands.
2799 *
2800 * @param V MDNode to get the operands from.
2801 * @param Dest Destination array for operands.
2802 */
2803void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2804
Robert Widmann09c5b882019-04-24 17:05:08 +00002805/** Deprecated: Use LLVMMDStringInContext2 instead. */
2806LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2807 unsigned SLen);
2808/** Deprecated: Use LLVMMDStringInContext2 instead. */
2809LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2810/** Deprecated: Use LLVMMDNodeInContext2 instead. */
2811LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2812 unsigned Count);
2813/** Deprecated: Use LLVMMDNodeInContext2 instead. */
2814LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2815
Duncan Sands12ccbe72012-09-19 20:29:39 +00002816/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002817 * @}
2818 */
2819
2820/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002821 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2822 *
2823 * A basic block represents a single entry single exit section of code.
2824 * Basic blocks contain a list of instructions which form the body of
2825 * the block.
2826 *
2827 * Basic blocks belong to functions. They have the type of label.
2828 *
2829 * Basic blocks are themselves values. However, the C API models them as
2830 * LLVMBasicBlockRef.
2831 *
2832 * @see llvm::BasicBlock
2833 *
2834 * @{
2835 */
2836
2837/**
2838 * Convert a basic block instance to a value type.
2839 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002840LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002841
2842/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002843 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002844 */
Chris Lattner25963c62010-01-09 22:27:07 +00002845LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002846
2847/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002848 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002849 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002850LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002851
2852/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002853 * Obtain the string name of a basic block.
2854 */
2855const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2856
2857/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002858 * Obtain the function to which a basic block belongs.
2859 *
2860 * @see llvm::BasicBlock::getParent()
2861 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002862LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002863
2864/**
2865 * Obtain the terminator instruction for a basic block.
2866 *
2867 * If the basic block does not have a terminator (it is not well-formed
2868 * if it doesn't), then NULL is returned.
2869 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00002870 * The returned LLVMValueRef corresponds to an llvm::Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002871 *
2872 * @see llvm::BasicBlock::getTerminator()
2873 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002874LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002875
2876/**
2877 * Obtain the number of basic blocks in a function.
2878 *
2879 * @param Fn Function value to operate on.
2880 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002881unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002882
2883/**
2884 * Obtain all of the basic blocks in a function.
2885 *
2886 * This operates on a function value. The BasicBlocks parameter is a
2887 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2888 * LLVMCountBasicBlocks() in length. This array is populated with
2889 * LLVMBasicBlockRef instances.
2890 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002891void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002892
2893/**
2894 * Obtain the first basic block in a function.
2895 *
2896 * The returned basic block can be used as an iterator. You will likely
2897 * eventually call into LLVMGetNextBasicBlock() with it.
2898 *
2899 * @see llvm::Function::begin()
2900 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002901LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002902
2903/**
2904 * Obtain the last basic block in a function.
2905 *
2906 * @see llvm::Function::end()
2907 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002908LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002909
2910/**
2911 * Advance a basic block iterator.
2912 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002913LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002914
2915/**
2916 * Go backwards in a basic block iterator.
2917 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002918LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002919
2920/**
2921 * Obtain the basic block that corresponds to the entry point of a
2922 * function.
2923 *
2924 * @see llvm::Function::getEntryBlock()
2925 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002926LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002927
Gregory Szorc34c863a2012-03-21 03:54:29 +00002928/**
Robert Widmannb4baa562019-04-05 20:32:43 +00002929 * Insert the given basic block after the insertion point of the given builder.
2930 *
2931 * The insertion point must be valid.
2932 *
2933 * @see llvm::Function::BasicBlockListType::insertAfter()
2934 */
2935void LLVMInsertExistingBasicBlockAfterInsertBlock(LLVMBuilderRef Builder,
2936 LLVMBasicBlockRef BB);
2937
2938/**
2939 * Append the given basic block to the basic block list of the given function.
2940 *
2941 * @see llvm::Function::BasicBlockListType::push_back()
2942 */
2943void LLVMAppendExistingBasicBlock(LLVMValueRef Fn,
2944 LLVMBasicBlockRef BB);
2945
2946/**
Robert Widmann616ed172019-01-08 06:24:19 +00002947 * Create a new basic block without inserting it into a function.
2948 *
2949 * @see llvm::BasicBlock::Create()
2950 */
2951LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C,
James Y Knight68729f92019-01-14 17:16:55 +00002952 const char *Name);
Robert Widmann616ed172019-01-08 06:24:19 +00002953
2954/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002955 * Append a basic block to the end of a function.
2956 *
2957 * @see llvm::BasicBlock::Create()
2958 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002959LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2960 LLVMValueRef Fn,
2961 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002962
2963/**
2964 * Append a basic block to the end of a function using the global
2965 * context.
2966 *
2967 * @see llvm::BasicBlock::Create()
2968 */
2969LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2970
2971/**
2972 * Insert a basic block in a function before another basic block.
2973 *
2974 * The function to add to is determined by the function of the
2975 * passed basic block.
2976 *
2977 * @see llvm::BasicBlock::Create()
2978 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002979LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2980 LLVMBasicBlockRef BB,
2981 const char *Name);
2982
Gregory Szorc34c863a2012-03-21 03:54:29 +00002983/**
2984 * Insert a basic block in a function using the global context.
2985 *
2986 * @see llvm::BasicBlock::Create()
2987 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002988LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2989 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002990
2991/**
2992 * Remove a basic block from a function and delete it.
2993 *
2994 * This deletes the basic block from its containing function and deletes
2995 * the basic block itself.
2996 *
2997 * @see llvm::BasicBlock::eraseFromParent()
2998 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002999void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003000
3001/**
3002 * Remove a basic block from a function.
3003 *
3004 * This deletes the basic block from its containing function but keep
3005 * the basic block alive.
3006 *
3007 * @see llvm::BasicBlock::removeFromParent()
3008 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003009void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003010
Gregory Szorc34c863a2012-03-21 03:54:29 +00003011/**
3012 * Move a basic block to before another one.
3013 *
3014 * @see llvm::BasicBlock::moveBefore()
3015 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00003016void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003017
3018/**
3019 * Move a basic block to after another one.
3020 *
3021 * @see llvm::BasicBlock::moveAfter()
3022 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00003023void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
3024
Gregory Szorc34c863a2012-03-21 03:54:29 +00003025/**
3026 * Obtain the first instruction in a basic block.
3027 *
3028 * The returned LLVMValueRef corresponds to a llvm::Instruction
3029 * instance.
3030 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003031LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003032
3033/**
3034 * Obtain the last instruction in a basic block.
3035 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003036 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003037 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003038LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00003039
Gregory Szorc34c863a2012-03-21 03:54:29 +00003040/**
3041 * @}
3042 */
3043
3044/**
3045 * @defgroup LLVMCCoreValueInstruction Instructions
3046 *
3047 * Functions in this group relate to the inspection and manipulation of
3048 * individual instructions.
3049 *
3050 * In the C++ API, an instruction is modeled by llvm::Instruction. This
3051 * class has a large number of descendents. llvm::Instruction is a
3052 * llvm::Value and in the C API, instructions are modeled by
3053 * LLVMValueRef.
3054 *
3055 * This group also contains sub-groups which operate on specific
3056 * llvm::Instruction types, e.g. llvm::CallInst.
3057 *
3058 * @{
3059 */
3060
3061/**
3062 * Determine whether an instruction has any metadata attached.
3063 */
3064int LLVMHasMetadata(LLVMValueRef Val);
3065
3066/**
3067 * Return metadata associated with an instruction value.
3068 */
3069LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
3070
3071/**
3072 * Set metadata associated with an instruction value.
3073 */
3074void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
3075
3076/**
Robert Widmann9cba4ec2018-09-28 15:35:18 +00003077 * Returns the metadata associated with an instruction value, but filters out
3078 * all the debug locations.
3079 *
3080 * @see llvm::Instruction::getAllMetadataOtherThanDebugLoc()
3081 */
3082LLVMValueMetadataEntry *
3083LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Instr,
3084 size_t *NumEntries);
3085
3086/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003087 * Obtain the basic block to which an instruction belongs.
3088 *
3089 * @see llvm::Instruction::getParent()
3090 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003091LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003092
3093/**
3094 * Obtain the instruction that occurs after the one specified.
3095 *
3096 * The next instruction will be from the same basic block.
3097 *
3098 * If this is the last instruction in a basic block, NULL will be
3099 * returned.
3100 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003101LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003102
3103/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00003104 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003105 *
3106 * If the instruction is the first instruction in a basic block, NULL
3107 * will be returned.
3108 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00003109LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003110
3111/**
3112 * Remove and delete an instruction.
3113 *
3114 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00003115 * block but is kept alive.
3116 *
3117 * @see llvm::Instruction::removeFromParent()
3118 */
3119void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
3120
3121/**
3122 * Remove and delete an instruction.
3123 *
3124 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00003125 * block and then deleted.
3126 *
3127 * @see llvm::Instruction::eraseFromParent()
3128 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00003129void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003130
3131/**
3132 * Obtain the code opcode for an individual instruction.
3133 *
3134 * @see llvm::Instruction::getOpCode()
3135 */
Eric Christophera6b96002015-12-18 01:46:52 +00003136LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003137
3138/**
3139 * Obtain the predicate of an instruction.
3140 *
3141 * This is only valid for instructions that correspond to llvm::ICmpInst
3142 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
3143 *
3144 * @see llvm::ICmpInst::getPredicate()
3145 */
Torok Edwin60c40de2011-10-06 12:13:20 +00003146LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003147
Gregory Szorc34c863a2012-03-21 03:54:29 +00003148/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00003149 * Obtain the float predicate of an instruction.
3150 *
3151 * This is only valid for instructions that correspond to llvm::FCmpInst
3152 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
3153 *
3154 * @see llvm::FCmpInst::getPredicate()
3155 */
3156LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
3157
3158/**
Peter Zotovaff492c2014-10-17 01:02:34 +00003159 * Create a copy of 'this' instruction that is identical in all ways
3160 * except the following:
3161 * * The instruction has no parent
3162 * * The instruction has no name
3163 *
3164 * @see llvm::Instruction::clone()
3165 */
3166LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
3167
3168/**
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003169 * Determine whether an instruction is a terminator. This routine is named to
3170 * be compatible with historical functions that did this by querying the
3171 * underlying C++ type.
3172 *
3173 * @see llvm::Instruction::isTerminator()
3174 */
3175LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst);
3176
3177/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003178 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
3179 *
3180 * Functions in this group apply to instructions that refer to call
3181 * sites and invocations. These correspond to C++ types in the
3182 * llvm::CallInst class tree.
3183 *
3184 * @{
3185 */
3186
3187/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003188 * Obtain the argument count for a call instruction.
3189 *
Robert Widmann478fce92018-03-30 17:49:53 +00003190 * This expects an LLVMValueRef that corresponds to a llvm::CallInst,
3191 * llvm::InvokeInst, or llvm:FuncletPadInst.
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003192 *
3193 * @see llvm::CallInst::getNumArgOperands()
3194 * @see llvm::InvokeInst::getNumArgOperands()
Robert Widmann478fce92018-03-30 17:49:53 +00003195 * @see llvm::FuncletPadInst::getNumArgOperands()
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003196 */
3197unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
3198
3199/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003200 * Set the calling convention for a call instruction.
3201 *
3202 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3203 * llvm::InvokeInst.
3204 *
3205 * @see llvm::CallInst::setCallingConv()
3206 * @see llvm::InvokeInst::setCallingConv()
3207 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003208void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003209
3210/**
3211 * Obtain the calling convention for a call instruction.
3212 *
3213 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
3214 * usage.
3215 *
3216 * @see LLVMSetInstructionCallConv()
3217 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00003218unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003219
Gregory Szorc34c863a2012-03-21 03:54:29 +00003220void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Amaury Sechet81243a72016-05-01 01:42:34 +00003221 unsigned Align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00003222
Amaury Secheta65a2372016-06-15 05:14:29 +00003223void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3224 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00003225unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx);
3226void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
3227 LLVMAttributeRef *Attrs);
Amaury Secheta65a2372016-06-15 05:14:29 +00003228LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
3229 LLVMAttributeIndex Idx,
3230 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003231LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
3232 LLVMAttributeIndex Idx,
3233 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003234void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3235 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00003236void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
3237 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00003238
Gregory Szorc34c863a2012-03-21 03:54:29 +00003239/**
James Y Knightf9563902019-01-14 21:37:42 +00003240 * Obtain the function type called by this instruction.
3241 *
3242 * @see llvm::CallBase::getFunctionType()
3243 */
3244LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef C);
3245
3246/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00003247 * Obtain the pointer to the function invoked by this instruction.
3248 *
3249 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
3250 * llvm::InvokeInst.
3251 *
3252 * @see llvm::CallInst::getCalledValue()
3253 * @see llvm::InvokeInst::getCalledValue()
3254 */
3255LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
3256
3257/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003258 * Obtain whether a call instruction is a tail call.
3259 *
3260 * This only works on llvm::CallInst instructions.
3261 *
3262 * @see llvm::CallInst::isTailCall()
3263 */
Chris Lattner25963c62010-01-09 22:27:07 +00003264LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003265
3266/**
3267 * Set whether a call instruction is a tail call.
3268 *
3269 * This only works on llvm::CallInst instructions.
3270 *
3271 * @see llvm::CallInst::setTailCall()
3272 */
Chris Lattner25963c62010-01-09 22:27:07 +00003273void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00003274
Gregory Szorc34c863a2012-03-21 03:54:29 +00003275/**
Amaury Sechete39e8532016-02-18 20:38:32 +00003276 * Return the normal destination basic block.
3277 *
3278 * This only works on llvm::InvokeInst instructions.
3279 *
3280 * @see llvm::InvokeInst::getNormalDest()
3281 */
3282LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
3283
3284/**
3285 * Return the unwind destination basic block.
3286 *
Robert Widmann478fce92018-03-30 17:49:53 +00003287 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3288 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003289 *
3290 * @see llvm::InvokeInst::getUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003291 * @see llvm::CleanupReturnInst::getUnwindDest()
3292 * @see llvm::CatchSwitchInst::getUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003293 */
3294LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
3295
3296/**
3297 * Set the normal destination basic block.
3298 *
3299 * This only works on llvm::InvokeInst instructions.
3300 *
3301 * @see llvm::InvokeInst::setNormalDest()
3302 */
3303void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3304
3305/**
3306 * Set the unwind destination basic block.
3307 *
Robert Widmann478fce92018-03-30 17:49:53 +00003308 * Works on llvm::InvokeInst, llvm::CleanupReturnInst, and
3309 * llvm::CatchSwitchInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00003310 *
3311 * @see llvm::InvokeInst::setUnwindDest()
Robert Widmann478fce92018-03-30 17:49:53 +00003312 * @see llvm::CleanupReturnInst::setUnwindDest()
3313 * @see llvm::CatchSwitchInst::setUnwindDest()
Amaury Sechete39e8532016-02-18 20:38:32 +00003314 */
3315void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
3316
3317/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003318 * @}
3319 */
3320
3321/**
Peter Zotov2481c752014-10-28 19:46:56 +00003322 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
3323 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003324 * Functions in this group only apply to instructions for which
3325 * LLVMIsATerminatorInst returns true.
Peter Zotov2481c752014-10-28 19:46:56 +00003326 *
3327 * @{
3328 */
3329
3330/**
3331 * Return the number of successors that this terminator has.
3332 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003333 * @see llvm::Instruction::getNumSuccessors
Peter Zotov2481c752014-10-28 19:46:56 +00003334 */
3335unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
3336
3337/**
3338 * Return the specified successor.
3339 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003340 * @see llvm::Instruction::getSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003341 */
3342LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
3343
3344/**
3345 * Update the specified successor to point at the provided block.
3346 *
Chandler Carruth7c80c3a2018-10-18 23:03:55 +00003347 * @see llvm::Instruction::setSuccessor
Peter Zotov2481c752014-10-28 19:46:56 +00003348 */
3349void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
3350
3351/**
3352 * Return if a branch is conditional.
3353 *
3354 * This only works on llvm::BranchInst instructions.
3355 *
3356 * @see llvm::BranchInst::isConditional
3357 */
3358LLVMBool LLVMIsConditional(LLVMValueRef Branch);
3359
3360/**
3361 * Return the condition of a branch instruction.
3362 *
3363 * This only works on llvm::BranchInst instructions.
3364 *
3365 * @see llvm::BranchInst::getCondition
3366 */
3367LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
3368
3369/**
3370 * Set the condition of a branch instruction.
3371 *
3372 * This only works on llvm::BranchInst instructions.
3373 *
3374 * @see llvm::BranchInst::setCondition
3375 */
3376void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
3377
3378/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003379 * Obtain the default destination basic block of a switch instruction.
3380 *
3381 * This only works on llvm::SwitchInst instructions.
3382 *
3383 * @see llvm::SwitchInst::getDefaultDest()
3384 */
Nate Begeman43c322b2011-08-23 20:27:46 +00003385LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
3386
Gregory Szorc34c863a2012-03-21 03:54:29 +00003387/**
Peter Zotov2481c752014-10-28 19:46:56 +00003388 * @}
3389 */
3390
3391/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00003392 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
3393 *
3394 * Functions in this group only apply to instructions that map to
3395 * llvm::AllocaInst instances.
3396 *
3397 * @{
3398 */
3399
3400/**
3401 * Obtain the type that is being allocated by the alloca instruction.
3402 */
3403LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
3404
3405/**
3406 * @}
3407 */
3408
3409/**
Amaury Sechet053ac452016-02-17 22:51:03 +00003410 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
3411 *
3412 * Functions in this group only apply to instructions that map to
3413 * llvm::GetElementPtrInst instances.
3414 *
3415 * @{
3416 */
3417
3418/**
3419 * Check whether the given GEP instruction is inbounds.
3420 */
3421LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
3422
3423/**
3424 * Set the given GEP instruction to be inbounds or not.
3425 */
Amaury Sechet8a367d42016-05-01 02:23:14 +00003426void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
Amaury Sechet053ac452016-02-17 22:51:03 +00003427
3428/**
3429 * @}
3430 */
3431
3432/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003433 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
3434 *
3435 * Functions in this group only apply to instructions that map to
3436 * llvm::PHINode instances.
3437 *
3438 * @{
3439 */
3440
3441/**
3442 * Add an incoming value to the end of a PHI list.
3443 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003444void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
3445 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003446
3447/**
3448 * Obtain the number of incoming basic blocks to a PHI node.
3449 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003450unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003451
3452/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003453 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003454 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003455LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00003456
3457/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00003458 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003459 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00003460LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003461
Gregory Szorc34c863a2012-03-21 03:54:29 +00003462/**
3463 * @}
3464 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003465
Gregory Szorc34c863a2012-03-21 03:54:29 +00003466/**
Amaury Sechetaad93532016-02-10 00:38:50 +00003467 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
3468 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
3469 *
3470 * Functions in this group only apply to instructions that map to
3471 * llvm::ExtractValue and llvm::InsertValue instances.
3472 *
3473 * @{
3474 */
3475
3476/**
3477 * Obtain the number of indices.
Amaury Sechet053ac452016-02-17 22:51:03 +00003478 * NB: This also works on GEP.
Amaury Sechetaad93532016-02-10 00:38:50 +00003479 */
3480unsigned LLVMGetNumIndices(LLVMValueRef Inst);
3481
3482/**
3483 * Obtain the indices as an array.
3484 */
3485const unsigned *LLVMGetIndices(LLVMValueRef Inst);
3486
3487/**
3488 * @}
3489 */
3490
3491/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003492 * @}
3493 */
3494
3495/**
3496 * @}
3497 */
3498
3499/**
3500 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
3501 *
3502 * An instruction builder represents a point within a basic block and is
3503 * the exclusive means of building instructions using the C interface.
3504 *
3505 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003506 */
3507
Erick Tryzelaar262332f2009-08-14 00:01:31 +00003508LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003509LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00003510void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
3511 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003512void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
3513void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00003514LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00003515void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
3516void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00003517void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
3518 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003519void LLVMDisposeBuilder(LLVMBuilderRef Builder);
3520
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00003521/* Metadata */
Robert Widmanncce47412019-04-10 14:19:05 +00003522
3523/**
3524 * Get location information used by debugging information.
3525 *
3526 * @see llvm::IRBuilder::getCurrentDebugLocation()
3527 */
3528LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder);
3529
3530/**
3531 * Set location information used by debugging information.
3532 *
3533 * To clear the location metadata of the given instruction, pass NULL to \p Loc.
3534 *
3535 * @see llvm::IRBuilder::SetCurrentDebugLocation()
3536 */
3537void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc);
3538
3539/**
3540 * Attempts to set the debug location for the given instruction using the
3541 * current debug location for the given builder. If the builder has no current
3542 * debug location, this function is a no-op.
3543 *
3544 * @see llvm::IRBuilder::SetInstDebugLocation()
3545 */
Sam McCall71660b02019-04-10 13:29:37 +00003546void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
Robert Widmannff8febc2019-04-22 13:13:22 +00003547
3548/**
3549 * Get the dafult floating-point math metadata for a given builder.
3550 *
3551 * @see llvm::IRBuilder::getDefaultFPMathTag()
3552 */
3553LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder);
3554
3555/**
3556 * Set the default floating-point math metadata for the given builder.
3557 *
3558 * To clear the metadata, pass NULL to \p FPMathTag.
3559 *
3560 * @see llvm::IRBuilder::setDefaultFPMathTag()
3561 */
3562void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder,
3563 LLVMMetadataRef FPMathTag);
3564
Robert Widmanncce47412019-04-10 14:19:05 +00003565/**
3566 * Deprecated: Passing the NULL location will crash.
3567 * Use LLVMGetCurrentDebugLocation2 instead.
3568 */
3569void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
3570/**
3571 * Deprecated: Returning the NULL location will crash.
3572 * Use LLVMGetCurrentDebugLocation2 instead.
3573 */
3574LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00003575
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003576/* Terminators */
3577LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
3578LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00003579LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003580 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003581LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
3582LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
3583 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
3584LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
3585 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003586LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
3587 unsigned NumDests);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003588// LLVMBuildInvoke is deprecated in favor of LLVMBuildInvoke2, in preparation
3589// for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003590LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
3591 LLVMValueRef *Args, unsigned NumArgs,
3592 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3593 const char *Name);
James Y Knighteb2c4af2019-01-14 21:37:48 +00003594LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
3595 LLVMValueRef *Args, unsigned NumArgs,
3596 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3597 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003598LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
3599
3600/* Exception Handling */
3601LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00003602LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00003603 LLVMValueRef PersFn, unsigned NumClauses,
3604 const char *Name);
Robert Widmann478fce92018-03-30 17:49:53 +00003605LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3606 LLVMBasicBlockRef BB);
3607LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B, LLVMValueRef CatchPad,
3608 LLVMBasicBlockRef BB);
3609LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3610 LLVMValueRef *Args, unsigned NumArgs,
3611 const char *Name);
3612LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
3613 LLVMValueRef *Args, unsigned NumArgs,
3614 const char *Name);
3615LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B, LLVMValueRef ParentPad,
3616 LLVMBasicBlockRef UnwindBB,
3617 unsigned NumHandlers, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003618
Gordon Henriksen097102c2008-01-01 05:50:53 +00003619/* Add a case to the switch instruction */
3620void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
3621 LLVMBasicBlockRef Dest);
3622
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00003623/* Add a destination to the indirectbr instruction */
3624void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
3625
Amaury Sechete39e8532016-02-18 20:38:32 +00003626/* Get the number of clauses on the landingpad instruction */
3627unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
3628
3629/* Get the value of the clause at idnex Idx on the landingpad instruction */
3630LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
3631
Bill Wendlingfae14752011-08-12 20:24:12 +00003632/* Add a catch or filter clause to the landingpad instruction */
3633void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
3634
Amaury Sechete39e8532016-02-18 20:38:32 +00003635/* Get the 'cleanup' flag in the landingpad instruction */
3636LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
3637
Bill Wendlingfae14752011-08-12 20:24:12 +00003638/* Set the 'cleanup' flag in the landingpad instruction */
3639void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
3640
Robert Widmann478fce92018-03-30 17:49:53 +00003641/* Add a destination to the catchswitch instruction */
3642void LLVMAddHandler(LLVMValueRef CatchSwitch, LLVMBasicBlockRef Dest);
3643
3644/* Get the number of handlers on the catchswitch instruction */
3645unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch);
3646
3647/**
3648 * Obtain the basic blocks acting as handlers for a catchswitch instruction.
3649 *
3650 * The Handlers parameter should point to a pre-allocated array of
3651 * LLVMBasicBlockRefs at least LLVMGetNumHandlers() large. On return, the
3652 * first LLVMGetNumHandlers() entries in the array will be populated
3653 * with LLVMBasicBlockRef instances.
3654 *
3655 * @param CatchSwitch The catchswitch instruction to operate on.
3656 * @param Handlers Memory address of an array to be filled with basic blocks.
3657 */
3658void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers);
3659
3660/* Funclets */
3661
3662/* Get the number of funcletpad arguments. */
3663LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i);
3664
3665/* Set a funcletpad argument at the given index. */
3666void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value);
3667
3668/**
3669 * Get the parent catchswitch instruction of a catchpad instruction.
3670 *
3671 * This only works on llvm::CatchPadInst instructions.
3672 *
3673 * @see llvm::CatchPadInst::getCatchSwitch()
3674 */
3675LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad);
3676
3677/**
3678 * Set the parent catchswitch instruction of a catchpad instruction.
3679 *
3680 * This only works on llvm::CatchPadInst instructions.
3681 *
3682 * @see llvm::CatchPadInst::setCatchSwitch()
3683 */
3684void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad, LLVMValueRef CatchSwitch);
3685
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003686/* Arithmetic */
3687LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3688 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003689LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3690 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003691LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3692 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003693LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3694 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003695LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3696 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003697LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3698 const char *Name);
3699LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3700 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003701LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3702 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003703LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3704 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003705LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3706 const char *Name);
3707LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3708 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003709LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3710 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003711LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3712 const char *Name);
Manuel Jacob49fafb12016-10-04 23:32:42 +00003713LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3714 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003715LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3716 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003717LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3718 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003719LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3720 const char *Name);
3721LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3722 const char *Name);
3723LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3724 const char *Name);
3725LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3726 const char *Name);
3727LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3728 const char *Name);
3729LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3730 const char *Name);
3731LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3732 const char *Name);
3733LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3734 const char *Name);
3735LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3736 const char *Name);
3737LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
3738 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003739LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
3740 LLVMValueRef LHS, LLVMValueRef RHS,
3741 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003742LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00003743LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
3744 const char *Name);
3745LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
3746 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00003747LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003748LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
3749
3750/* Memory */
3751LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3752LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
3753 LLVMValueRef Val, const char *Name);
Robert Widmann98640f82018-10-29 15:31:40 +00003754
3755/**
3756 * Creates and inserts a memset to the specified pointer and the
3757 * specified value.
3758 *
3759 * @see llvm::IRRBuilder::CreateMemSet()
3760 */
3761LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
3762 LLVMValueRef Val, LLVMValueRef Len,
3763 unsigned Align);
3764/**
3765 * Creates and inserts a memcpy between the specified pointers.
3766 *
3767 * @see llvm::IRRBuilder::CreateMemCpy()
3768 */
3769LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,
3770 LLVMValueRef Dst, unsigned DstAlign,
3771 LLVMValueRef Src, unsigned SrcAlign,
3772 LLVMValueRef Size);
3773/**
3774 * Creates and inserts a memmove between the specified pointers.
3775 *
3776 * @see llvm::IRRBuilder::CreateMemMove()
3777 */
3778LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B,
3779 LLVMValueRef Dst, unsigned DstAlign,
3780 LLVMValueRef Src, unsigned SrcAlign,
3781 LLVMValueRef Size);
3782
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003783LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3784LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
3785 LLVMValueRef Val, const char *Name);
3786LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003787// LLVMBuildLoad is deprecated in favor of LLVMBuildLoad2, in preparation for
3788// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003789LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
3790 const char *Name);
James Y Knight84c1dbd2019-01-14 21:37:53 +00003791LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty,
3792 LLVMValueRef PointerVal, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003793LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
James Y Knight544fa422019-01-14 21:39:35 +00003794// LLVMBuildGEP, LLVMBuildInBoundsGEP, and LLVMBuildStructGEP are deprecated in
3795// favor of LLVMBuild*GEP2, in preparation for opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003796LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3797 LLVMValueRef *Indices, unsigned NumIndices,
3798 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003799LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3800 LLVMValueRef *Indices, unsigned NumIndices,
3801 const char *Name);
3802LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3803 unsigned Idx, const char *Name);
James Y Knight544fa422019-01-14 21:39:35 +00003804LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3805 LLVMValueRef Pointer, LLVMValueRef *Indices,
3806 unsigned NumIndices, const char *Name);
3807LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3808 LLVMValueRef Pointer, LLVMValueRef *Indices,
3809 unsigned NumIndices, const char *Name);
3810LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3811 LLVMValueRef Pointer, unsigned Idx,
3812 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003813LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
3814 const char *Name);
3815LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
3816 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00003817LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
3818void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Nick Lewyckyf57e9682019-09-26 00:58:55 +00003819LLVMBool LLVMGetWeak(LLVMValueRef CmpXchgInst);
3820void LLVMSetWeak(LLVMValueRef CmpXchgInst, LLVMBool IsWeak);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00003821LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
3822void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Nick Lewyckyf57e9682019-09-26 00:58:55 +00003823LLVMAtomicRMWBinOp LLVMGetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst);
3824void LLVMSetAtomicRMWBinOp(LLVMValueRef AtomicRMWInst, LLVMAtomicRMWBinOp BinOp);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003825
3826/* Casts */
3827LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
3828 LLVMTypeRef DestTy, const char *Name);
3829LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
3830 LLVMTypeRef DestTy, const char *Name);
3831LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
3832 LLVMTypeRef DestTy, const char *Name);
3833LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
3834 LLVMTypeRef DestTy, const char *Name);
3835LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
3836 LLVMTypeRef DestTy, const char *Name);
3837LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
3838 LLVMTypeRef DestTy, const char *Name);
3839LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
3840 LLVMTypeRef DestTy, const char *Name);
3841LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
3842 LLVMTypeRef DestTy, const char *Name);
3843LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
3844 LLVMTypeRef DestTy, const char *Name);
3845LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
3846 LLVMTypeRef DestTy, const char *Name);
3847LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
3848 LLVMTypeRef DestTy, const char *Name);
3849LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
3850 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003851LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
3852 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003853LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3854 LLVMTypeRef DestTy, const char *Name);
3855LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3856 LLVMTypeRef DestTy, const char *Name);
3857LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3858 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003859LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
3860 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003861LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
3862 LLVMTypeRef DestTy, const char *Name);
Robert Widmann40dc48be2019-01-08 06:23:22 +00003863LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef, LLVMValueRef Val,
3864 LLVMTypeRef DestTy, LLVMBool IsSigned,
James Y Knight68729f92019-01-14 17:16:55 +00003865 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003866LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
3867 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003868
Robert Widmann40dc48be2019-01-08 06:23:22 +00003869/** Deprecated: This cast is always signed. Use LLVMBuildIntCast2 instead. */
3870LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
3871 LLVMTypeRef DestTy, const char *Name);
3872
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003873/* Comparisons */
3874LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
3875 LLVMValueRef LHS, LLVMValueRef RHS,
3876 const char *Name);
3877LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
3878 LLVMValueRef LHS, LLVMValueRef RHS,
3879 const char *Name);
3880
3881/* Miscellaneous instructions */
3882LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003883// LLVMBuildCall is deprecated in favor of LLVMBuildCall2, in preparation for
3884// opaque pointer types.
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003885LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
3886 LLVMValueRef *Args, unsigned NumArgs,
3887 const char *Name);
James Y Knightf9563902019-01-14 21:37:42 +00003888LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn,
3889 LLVMValueRef *Args, unsigned NumArgs,
3890 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003891LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
3892 LLVMValueRef Then, LLVMValueRef Else,
3893 const char *Name);
3894LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
3895 const char *Name);
3896LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
3897 LLVMValueRef Index, const char *Name);
3898LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
3899 LLVMValueRef EltVal, LLVMValueRef Index,
3900 const char *Name);
3901LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
3902 LLVMValueRef V2, LLVMValueRef Mask,
3903 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00003904LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
3905 unsigned Index, const char *Name);
3906LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
3907 LLVMValueRef EltVal, unsigned Index,
3908 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00003909
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003910LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
3911 const char *Name);
3912LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
3913 const char *Name);
3914LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
3915 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00003916LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
3917 LLVMBool singleThread, const char *Name);
3918LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00003919 LLVMValueRef PTR, LLVMValueRef Val,
3920 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00003921 LLVMBool singleThread);
Mehdi Amini43165d92016-03-19 21:28:28 +00003922LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
3923 LLVMValueRef Cmp, LLVMValueRef New,
3924 LLVMAtomicOrdering SuccessOrdering,
3925 LLVMAtomicOrdering FailureOrdering,
3926 LLVMBool SingleThread);
3927
3928LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
3929void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
3930
3931LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
3932void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
3933 LLVMAtomicOrdering Ordering);
3934LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
3935void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
3936 LLVMAtomicOrdering Ordering);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003937
Gregory Szorc34c863a2012-03-21 03:54:29 +00003938/**
3939 * @}
3940 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003941
Gregory Szorc34c863a2012-03-21 03:54:29 +00003942/**
3943 * @defgroup LLVMCCoreModuleProvider Module Providers
3944 *
3945 * @{
3946 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003947
Gregory Szorc34c863a2012-03-21 03:54:29 +00003948/**
3949 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003950 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003951 */
3952LLVMModuleProviderRef
3953LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
3954
Gregory Szorc34c863a2012-03-21 03:54:29 +00003955/**
3956 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003957 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003958void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003959
Gregory Szorc34c863a2012-03-21 03:54:29 +00003960/**
3961 * @}
3962 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003963
Gregory Szorc34c863a2012-03-21 03:54:29 +00003964/**
3965 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
3966 *
3967 * @{
3968 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003969
Chris Lattner25963c62010-01-09 22:27:07 +00003970LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
3971 LLVMMemoryBufferRef *OutMemBuf,
3972 char **OutMessage);
3973LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
3974 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00003975LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
3976 size_t InputDataLength,
3977 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00003978 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00003979LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
3980 size_t InputDataLength,
3981 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00003982const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00003983size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003984void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
3985
Gregory Szorc34c863a2012-03-21 03:54:29 +00003986/**
3987 * @}
3988 */
3989
3990/**
3991 * @defgroup LLVMCCorePassRegistry Pass Registry
3992 *
3993 * @{
3994 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003995
3996/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003997 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003998LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003999
Gregory Szorc34c863a2012-03-21 03:54:29 +00004000/**
4001 * @}
4002 */
4003
4004/**
4005 * @defgroup LLVMCCorePassManagers Pass Managers
4006 *
4007 * @{
4008 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004009
4010/** Constructs a new whole-module pass pipeline. This type of pipeline is
4011 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004012 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00004013LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004014
4015/** Constructs a new function-by-function pass pipeline over the module
4016 provider. It does not take ownership of the module provider. This type of
4017 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004018 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00004019LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
4020
4021/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004022LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
4023
4024/** Initializes, executes on the provided module, and finalizes all of the
4025 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00004026 modified the module, 0 otherwise.
4027 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00004028LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004029
4030/** Initializes all of the function passes scheduled in the function pass
4031 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004032 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00004033LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004034
4035/** Executes all of the function passes scheduled in the function pass manager
4036 on the provided function. Returns 1 if any of the passes modified the
4037 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004038 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00004039LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004040
Hiroshi Inoue0909ca12018-01-26 08:15:29 +00004041/** Finalizes all of the function passes scheduled in the function pass
Gordon Henriksen878114b2008-03-16 04:20:44 +00004042 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004043 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00004044LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00004045
4046/** Frees the memory of a pass pipeline. For function pipelines, does not free
4047 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00004048 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004049void LLVMDisposePassManager(LLVMPassManagerRef PM);
4050
Gregory Szorc34c863a2012-03-21 03:54:29 +00004051/**
4052 * @}
4053 */
4054
4055/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00004056 * @defgroup LLVMCCoreThreading Threading
4057 *
4058 * Handle the structures needed to make LLVM safe for multithreading.
4059 *
4060 * @{
4061 */
4062
Chandler Carruth39cd2162014-06-27 15:13:01 +00004063/** Deprecated: Multi-threading can only be enabled/disabled with the compile
4064 time define LLVM_ENABLE_THREADS. This function always returns
4065 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00004066LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00004067
Chandler Carruth39cd2162014-06-27 15:13:01 +00004068/** Deprecated: Multi-threading can only be enabled/disabled with the compile
4069 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00004070void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00004071
4072/** Check whether LLVM is executing in thread-safe mode or not.
4073 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00004074LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00004075
4076/**
4077 * @}
4078 */
4079
4080/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00004081 * @}
4082 */
4083
4084/**
4085 * @}
4086 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00004087
Gordon Henriksen76a03742007-09-18 03:18:57 +00004088#ifdef __cplusplus
4089}
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00004090#endif
Gordon Henriksen7330acd2007-10-05 23:59:36 +00004091
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00004092#endif /* LLVM_C_CORE_H */