blob: e1f1191d083efa5461152a647e7c4e326ccb126b [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
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
Gordon Henriksen76a03742007-09-18 03:18:57 +000057typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +000058 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +000059 LLVMRet = 1,
60 LLVMBr = 2,
61 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +000062 LLVMIndirectBr = 4,
63 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +000064 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +000065 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +000066
Bill Wendlingda52cec2010-02-15 20:53:17 +000067 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000068 LLVMAdd = 8,
69 LLVMFAdd = 9,
70 LLVMSub = 10,
71 LLVMFSub = 11,
72 LLVMMul = 12,
73 LLVMFMul = 13,
74 LLVMUDiv = 14,
75 LLVMSDiv = 15,
76 LLVMFDiv = 16,
77 LLVMURem = 17,
78 LLVMSRem = 18,
79 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +000080
Bill Wendlingda52cec2010-02-15 20:53:17 +000081 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000082 LLVMShl = 20,
83 LLVMLShr = 21,
84 LLVMAShr = 22,
85 LLVMAnd = 23,
86 LLVMOr = 24,
87 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +000088
Bill Wendlingda52cec2010-02-15 20:53:17 +000089 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000090 LLVMAlloca = 26,
91 LLVMLoad = 27,
92 LLVMStore = 28,
93 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +000094
Bill Wendlingda52cec2010-02-15 20:53:17 +000095 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +000096 LLVMTrunc = 30,
97 LLVMZExt = 31,
98 LLVMSExt = 32,
99 LLVMFPToUI = 33,
100 LLVMFPToSI = 34,
101 LLVMUIToFP = 35,
102 LLVMSIToFP = 36,
103 LLVMFPTrunc = 37,
104 LLVMFPExt = 38,
105 LLVMPtrToInt = 39,
106 LLVMIntToPtr = 40,
107 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000108 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000109
Bill Wendlingda52cec2010-02-15 20:53:17 +0000110 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000111 LLVMICmp = 42,
112 LLVMFCmp = 43,
113 LLVMPHI = 44,
114 LLVMCall = 45,
115 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000116 LLVMUserOp1 = 47,
117 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000118 LLVMVAArg = 49,
119 LLVMExtractElement = 50,
120 LLVMInsertElement = 51,
121 LLVMShuffleVector = 52,
122 LLVMExtractValue = 53,
123 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000124
125 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000126 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000127 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000128 LLVMAtomicRMW = 57,
129
130 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000131 LLVMResume = 58,
David Majnemer654e1302015-07-31 17:58:14 +0000132 LLVMLandingPad = 59,
133 LLVMCleanupRet = 61,
134 LLVMCatchRet = 62,
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +0000135 LLVMCatchPad = 63,
David Majnemerbbfc7212015-12-14 18:34:23 +0000136 LLVMCleanupPad = 64,
137 LLVMCatchSwitch = 65
Chris Lattner40cf28d2009-10-12 04:01:02 +0000138} LLVMOpcode;
139
140typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000141 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000142 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000143 LLVMFloatTypeKind, /**< 32 bit floating point type */
144 LLVMDoubleTypeKind, /**< 64 bit floating point type */
145 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
146 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
147 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
148 LLVMLabelTypeKind, /**< Labels */
149 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
150 LLVMFunctionTypeKind, /**< Functions */
151 LLVMStructTypeKind, /**< Structures */
152 LLVMArrayTypeKind, /**< Arrays */
153 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000154 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000155 LLVMMetadataTypeKind, /**< Metadata */
David Majnemerb611e3f2015-08-14 05:09:07 +0000156 LLVMX86_MMXTypeKind, /**< X86 MMX */
157 LLVMTokenTypeKind /**< Tokens */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000158} LLVMTypeKind;
159
160typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000161 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000162 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000163 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
164 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
165 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000166 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000167 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
168 LLVMWeakODRLinkage, /**< Same, but only replaced by something
169 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000170 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
171 LLVMInternalLinkage, /**< Rename collisions when linking (static
172 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000173 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000174 LLVMDLLImportLinkage, /**< Obsolete */
175 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000176 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000177 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000178 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000179 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000180 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000181} LLVMLinkage;
182
183typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000184 LLVMDefaultVisibility, /**< The GV is visible */
185 LLVMHiddenVisibility, /**< The GV is hidden */
186 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000187} LLVMVisibility;
188
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000189typedef enum {
Robert Widmann4bb481b2018-03-14 06:45:51 +0000190 LLVMNoUnnamedAddr, /**< Address of the GV is significant. */
191 LLVMLocalUnnamedAddr, /**< Address of the GV is locally insignificant. */
192 LLVMGlobalUnnamedAddr /**< Address of the GV is globally insignificant. */
193} LLVMUnnamedAddr;
194
195typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000196 LLVMDefaultStorageClass = 0,
197 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
198 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
199} LLVMDLLStorageClass;
200
201typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000202 LLVMCCallConv = 0,
203 LLVMFastCallConv = 8,
204 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000205 LLVMWebKitJSCallConv = 12,
206 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000207 LLVMX86StdcallCallConv = 64,
208 LLVMX86FastcallCallConv = 65
209} LLVMCallConv;
210
211typedef enum {
Peter Zotov3e4561c2016-04-06 22:21:29 +0000212 LLVMArgumentValueKind,
213 LLVMBasicBlockValueKind,
214 LLVMMemoryUseValueKind,
215 LLVMMemoryDefValueKind,
216 LLVMMemoryPhiValueKind,
217
218 LLVMFunctionValueKind,
219 LLVMGlobalAliasValueKind,
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000220 LLVMGlobalIFuncValueKind,
Peter Zotov3e4561c2016-04-06 22:21:29 +0000221 LLVMGlobalVariableValueKind,
222 LLVMBlockAddressValueKind,
223 LLVMConstantExprValueKind,
224 LLVMConstantArrayValueKind,
225 LLVMConstantStructValueKind,
226 LLVMConstantVectorValueKind,
227
228 LLVMUndefValueValueKind,
229 LLVMConstantAggregateZeroValueKind,
230 LLVMConstantDataArrayValueKind,
231 LLVMConstantDataVectorValueKind,
232 LLVMConstantIntValueKind,
233 LLVMConstantFPValueKind,
234 LLVMConstantPointerNullValueKind,
235 LLVMConstantTokenNoneValueKind,
236
237 LLVMMetadataAsValueValueKind,
238 LLVMInlineAsmValueKind,
239
240 LLVMInstructionValueKind,
241} LLVMValueKind;
242
243typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000244 LLVMIntEQ = 32, /**< equal */
245 LLVMIntNE, /**< not equal */
246 LLVMIntUGT, /**< unsigned greater than */
247 LLVMIntUGE, /**< unsigned greater or equal */
248 LLVMIntULT, /**< unsigned less than */
249 LLVMIntULE, /**< unsigned less or equal */
250 LLVMIntSGT, /**< signed greater than */
251 LLVMIntSGE, /**< signed greater or equal */
252 LLVMIntSLT, /**< signed less than */
253 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000254} LLVMIntPredicate;
255
256typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000257 LLVMRealPredicateFalse, /**< Always false (always folded) */
258 LLVMRealOEQ, /**< True if ordered and equal */
259 LLVMRealOGT, /**< True if ordered and greater than */
260 LLVMRealOGE, /**< True if ordered and greater than or equal */
261 LLVMRealOLT, /**< True if ordered and less than */
262 LLVMRealOLE, /**< True if ordered and less than or equal */
263 LLVMRealONE, /**< True if ordered and operands are unequal */
264 LLVMRealORD, /**< True if ordered (no nans) */
265 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
266 LLVMRealUEQ, /**< True if unordered or equal */
267 LLVMRealUGT, /**< True if unordered or greater than */
268 LLVMRealUGE, /**< True if unordered, greater than, or equal */
269 LLVMRealULT, /**< True if unordered or less than */
270 LLVMRealULE, /**< True if unordered, less than, or equal */
271 LLVMRealUNE, /**< True if unordered or not equal */
272 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000273} LLVMRealPredicate;
274
Bill Wendlingfae14752011-08-12 20:24:12 +0000275typedef enum {
276 LLVMLandingPadCatch, /**< A catch clause */
277 LLVMLandingPadFilter /**< A filter clause */
278} LLVMLandingPadClauseTy;
279
Hans Wennborg5ff71202013-04-16 08:58:59 +0000280typedef enum {
281 LLVMNotThreadLocal = 0,
282 LLVMGeneralDynamicTLSModel,
283 LLVMLocalDynamicTLSModel,
284 LLVMInitialExecTLSModel,
285 LLVMLocalExecTLSModel
286} LLVMThreadLocalMode;
287
Carlo Kokda0ac722013-04-23 13:45:37 +0000288typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000289 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
290 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
291 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000292 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
293 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000294 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000295 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
296 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000297 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000298 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
299 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000300 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000301 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
302 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000303 operations which both read and write
304 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000305 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
306 for loads and Release
307 semantics for stores.
308 Additionally, it guarantees
309 that a total ordering exists
310 between all
311 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000312 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000313} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000314
Carlo Kokda0ac722013-04-23 13:45:37 +0000315typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000316 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
317 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
318 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
319 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
320 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
321 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
322 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
323 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000324 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000325 the old one */
326 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000327 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000328 the old one */
329 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000330 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000331 the old one */
332 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000333 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000334 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000335} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000336
Tom Stellard1580dc72014-04-16 17:45:04 +0000337typedef enum {
338 LLVMDSError,
339 LLVMDSWarning,
340 LLVMDSRemark,
341 LLVMDSNote
342} LLVMDiagnosticSeverity;
343
Gregory Szorc34c863a2012-03-21 03:54:29 +0000344/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000345 * Attribute index are either LLVMAttributeReturnIndex,
346 * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
347 */
348enum {
349 LLVMAttributeReturnIndex = 0U,
350 // ISO C restricts enumerator values to range of 'int'
351 // (4294967295 is too large)
352 // LLVMAttributeFunctionIndex = ~0U,
353 LLVMAttributeFunctionIndex = -1,
354};
355
356typedef unsigned LLVMAttributeIndex;
357
358/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000359 * @}
360 */
361
Nick Lewycky0db26542011-05-15 07:20:34 +0000362void LLVMInitializeCore(LLVMPassRegistryRef R);
363
Duncan Sands1cba0a82013-02-17 16:35:51 +0000364/** Deallocate and destroy all ManagedStatic variables.
365 @see llvm::llvm_shutdown
366 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000367void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000368
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000369/*===-- Error handling ----------------------------------------------------===*/
370
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000371char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000372void LLVMDisposeMessage(char *Message);
373
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000374/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000375 * @defgroup LLVMCCoreContext Contexts
376 *
377 * Contexts are execution states for the core LLVM IR system.
378 *
379 * Most types are tied to a context instance. Multiple contexts can
380 * exist simultaneously. A single context is not thread safe. However,
381 * different contexts can execute on different threads simultaneously.
382 *
383 * @{
384 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000385
Tom Stellard1580dc72014-04-16 17:45:04 +0000386typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000387typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000388
Gregory Szorc34c863a2012-03-21 03:54:29 +0000389/**
390 * Create a new context.
391 *
392 * Every call to this function should be paired with a call to
393 * LLVMContextDispose() or the context will leak memory.
394 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000395LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000396
397/**
398 * Obtain the global context instance.
399 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000400LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000401
402/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000403 * Set the diagnostic handler for this context.
404 */
405void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
406 LLVMDiagnosticHandler Handler,
407 void *DiagnosticContext);
408
409/**
Jeroen Ketemaad659c32016-04-08 09:19:02 +0000410 * Get the diagnostic handler of this context.
411 */
412LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
413
414/**
415 * Get the diagnostic context of this context.
416 */
417void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
418
419/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000420 * Set the yield callback function for this context.
421 *
422 * @see LLVMContext::setYieldCallback()
423 */
424void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
425 void *OpaqueHandle);
426
427/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000428 * Destroy a context instance.
429 *
430 * This should be called for every call to LLVMContextCreate() or memory
431 * will be leaked.
432 */
Owen Anderson6773d382009-07-01 16:58:40 +0000433void LLVMContextDispose(LLVMContextRef C);
434
Tom Stellard1580dc72014-04-16 17:45:04 +0000435/**
436 * Return a string representation of the DiagnosticInfo. Use
437 * LLVMDisposeMessage to free the string.
438 *
439 * @see DiagnosticInfo::print()
440 */
441char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
442
443/**
444 * Return an enum LLVMDiagnosticSeverity.
445 *
446 * @see DiagnosticInfo::getSeverity()
447 */
448LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
449
Amaury Sechet56f056c2016-04-04 22:00:25 +0000450unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000451 unsigned SLen);
Amaury Sechet56f056c2016-04-04 22:00:25 +0000452unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000453
Gregory Szorc34c863a2012-03-21 03:54:29 +0000454/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000455 * Return an unique id given the name of a enum attribute,
Amaury Sechet60b31452016-04-20 01:02:12 +0000456 * or 0 if no attribute by that name exists.
457 *
458 * See http://llvm.org/docs/LangRef.html#parameter-attributes
459 * and http://llvm.org/docs/LangRef.html#function-attributes
460 * for the list of available attributes.
461 *
462 * NB: Attribute names and/or id are subject to change without
463 * going through the C API deprecation cycle.
464 */
Amaury Sechet5db224e2016-06-12 06:17:24 +0000465unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
Amaury Sechet48b06652016-06-12 07:56:21 +0000466unsigned LLVMGetLastEnumAttributeKind(void);
Amaury Sechet5db224e2016-06-12 06:17:24 +0000467
468/**
469 * Create an enum attribute.
470 */
471LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
472 uint64_t Val);
473
474/**
475 * Get the unique id corresponding to the enum attribute
476 * passed as argument.
477 */
478unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
479
480/**
481 * Get the enum attribute's value. 0 is returned if none exists.
482 */
483uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
484
485/**
486 * Create a string attribute.
487 */
488LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
489 const char *K, unsigned KLength,
490 const char *V, unsigned VLength);
491
492/**
493 * Get the string attribute's kind.
494 */
495const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
496
497/**
498 * Get the string attribute's value.
499 */
500const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
501
502/**
503 * Check for the different types of attributes.
504 */
505LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
506LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
Amaury Sechet60b31452016-04-20 01:02:12 +0000507
508/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000509 * @}
510 */
511
Gregory Szorc52d26602012-03-21 07:28:27 +0000512/**
513 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000514 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000515 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000516 * module is effectively a translation unit or a collection of
517 * translation units merged together.
518 *
519 * @{
520 */
521
Gregory Szorc34c863a2012-03-21 03:54:29 +0000522/**
523 * Create a new, empty module in the global context.
524 *
525 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
526 * LLVMGetGlobalContext() as the context parameter.
527 *
528 * Every invocation should be paired with LLVMDisposeModule() or memory
529 * will be leaked.
530 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000531LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000532
533/**
534 * Create a new, empty module in a specific context.
535 *
536 * Every invocation should be paired with LLVMDisposeModule() or memory
537 * will be leaked.
538 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000539LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
540 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000541/**
542 * Return an exact copy of the specified module.
543 */
544LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000545
Gregory Szorc34c863a2012-03-21 03:54:29 +0000546/**
547 * Destroy a module instance.
548 *
549 * This must be called for every created module or memory will be
550 * leaked.
551 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000552void LLVMDisposeModule(LLVMModuleRef M);
553
Gregory Szorc34c863a2012-03-21 03:54:29 +0000554/**
Peter Zotov0a2fa0a2016-04-05 13:56:59 +0000555 * Obtain the identifier of a module.
556 *
557 * @param M Module to obtain identifier of
558 * @param Len Out parameter which holds the length of the returned string.
559 * @return The identifier of M.
560 * @see Module::getModuleIdentifier()
561 */
562const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
563
564/**
565 * Set the identifier of a module to a string Ident with length Len.
566 *
567 * @param M The module to set identifier
568 * @param Ident The string to set M's identifier to
569 * @param Len Length of Ident
570 * @see Module::setModuleIdentifier()
571 */
572void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
573
574/**
Robert Widmann490a5802018-01-30 21:34:29 +0000575 * Obtain the module's original source file name.
576 *
577 * @param M Module to obtain the name of
578 * @param Len Out parameter which holds the length of the returned string
579 * @return The original source file name of M
580 * @see Module::getSourceFileName()
581 */
582const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len);
583
584/**
585 * Set the original source file name of a module to a string Name with length
586 * Len.
587 *
588 * @param M The module to set the source file name of
589 * @param Name The string to set M's source file name to
590 * @param Len Length of Name
591 * @see Module::setSourceFileName()
592 */
593void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len);
594
595/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000596 * Obtain the data layout for a module.
597 *
Amaury Sechetf3549c42016-02-16 00:23:52 +0000598 * @see Module::getDataLayoutStr()
599 *
600 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
601 * but match the name of another method on the module. Prefer the use
602 * of LLVMGetDataLayoutStr, which is not ambiguous.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000603 */
Amaury Sechetf3549c42016-02-16 00:23:52 +0000604const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000605const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000606
607/**
608 * Set the data layout for a module.
609 *
610 * @see Module::setDataLayout()
611 */
Amaury Sechet6ada31c2016-02-15 23:40:06 +0000612void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000613
Gregory Szorc34c863a2012-03-21 03:54:29 +0000614/**
615 * Obtain the target triple for a module.
616 *
617 * @see Module::getTargetTriple()
618 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000619const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000620
621/**
622 * Set the target triple for a module.
623 *
624 * @see Module::setTargetTriple()
625 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000626void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
627
Gregory Szorc34c863a2012-03-21 03:54:29 +0000628/**
629 * Dump a representation of a module to stderr.
630 *
631 * @see Module::dump()
632 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000633void LLVMDumpModule(LLVMModuleRef M);
634
Gregory Szorc34c863a2012-03-21 03:54:29 +0000635/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000636 * Print a representation of a module to a file. The ErrorMessage needs to be
637 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
638 *
639 * @see Module::print()
640 */
641LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
642 char **ErrorMessage);
643
644/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000645 * Return a string representation of the module. Use
646 * LLVMDisposeMessage to free the string.
647 *
648 * @see Module::print()
649 */
650char *LLVMPrintModuleToString(LLVMModuleRef M);
651
652/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000653 * Set inline assembly for a module.
654 *
655 * @see Module::setModuleInlineAsm()
656 */
Chris Lattner26941452010-04-10 17:52:58 +0000657void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000658
Gregory Szorc34c863a2012-03-21 03:54:29 +0000659/**
660 * Obtain the context to which this module is associated.
661 *
662 * @see Module::getContext()
663 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000664LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
665
Gregory Szorc34c863a2012-03-21 03:54:29 +0000666/**
667 * Obtain a Type from a module by its registered name.
668 */
669LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000670
Gregory Szorc34c863a2012-03-21 03:54:29 +0000671/**
672 * Obtain the number of operands for named metadata in a module.
673 *
674 * @see llvm::Module::getNamedMetadata()
675 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000676unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000677
678/**
679 * Obtain the named metadata operands for a module.
680 *
681 * The passed LLVMValueRef pointer should refer to an array of
682 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
683 * array will be populated with the LLVMValueRef instances. Each
684 * instance corresponds to a llvm::MDNode.
685 *
686 * @see llvm::Module::getNamedMetadata()
687 * @see llvm::MDNode::getOperand()
688 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000689void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
690 LLVMValueRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000691
692/**
693 * Add an operand to named metadata.
694 *
695 * @see llvm::Module::getNamedMetadata()
696 * @see llvm::MDNode::addOperand()
697 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000698void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
Gregory Szorc34c863a2012-03-21 03:54:29 +0000699 LLVMValueRef Val);
700
Gregory Szorc52d26602012-03-21 07:28:27 +0000701/**
702 * Add a function to a module under a specified name.
703 *
704 * @see llvm::Function::Create()
705 */
706LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
707 LLVMTypeRef FunctionTy);
708
709/**
710 * Obtain a Function value from a Module by its name.
711 *
712 * The returned value corresponds to a llvm::Function value.
713 *
714 * @see llvm::Module::getFunction()
715 */
716LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
717
718/**
719 * Obtain an iterator to the first Function in a Module.
720 *
721 * @see llvm::Module::begin()
722 */
723LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
724
725/**
726 * Obtain an iterator to the last Function in a Module.
727 *
728 * @see llvm::Module::end()
729 */
730LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
731
732/**
733 * Advance a Function iterator to the next Function.
734 *
735 * Returns NULL if the iterator was already at the end and there are no more
736 * functions.
737 */
738LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
739
740/**
741 * Decrement a Function iterator to the previous Function.
742 *
743 * Returns NULL if the iterator was already at the beginning and there are
744 * no previous functions.
745 */
746LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000747
748/**
749 * @}
750 */
751
752/**
753 * @defgroup LLVMCCoreType Types
754 *
755 * Types represent the type of a value.
756 *
757 * Types are associated with a context instance. The context internally
758 * deduplicates types so there is only 1 instance of a specific type
759 * alive at a time. In other words, a unique type is shared among all
760 * consumers within a context.
761 *
762 * A Type in the C API corresponds to llvm::Type.
763 *
764 * Types have the following hierarchy:
765 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000766 * types:
767 * integer type
768 * real type
769 * function type
770 * sequence types:
771 * array type
772 * pointer type
773 * vector type
774 * void type
775 * label type
776 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000777 *
778 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000779 */
780
Gregory Szorc34c863a2012-03-21 03:54:29 +0000781/**
782 * Obtain the enumerated type of a Type instance.
783 *
784 * @see llvm::Type:getTypeID()
785 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000786LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000787
788/**
789 * Whether the type has a known size.
790 *
791 * Things that don't have a size are abstract types, labels, and void.a
792 *
793 * @see llvm::Type::isSized()
794 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000795LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000796
Gregory Szorc34c863a2012-03-21 03:54:29 +0000797/**
798 * Obtain the context to which this type instance is associated.
799 *
800 * @see llvm::Type::getContext()
801 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000802LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
803
Gregory Szorc34c863a2012-03-21 03:54:29 +0000804/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000805 * Dump a representation of a type to stderr.
806 *
807 * @see llvm::Type::dump()
808 */
809void LLVMDumpType(LLVMTypeRef Val);
810
811/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000812 * Return a string representation of the type. Use
813 * LLVMDisposeMessage to free the string.
814 *
815 * @see llvm::Type::print()
816 */
817char *LLVMPrintTypeToString(LLVMTypeRef Val);
818
819/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000820 * @defgroup LLVMCCoreTypeInt Integer Types
821 *
822 * Functions in this section operate on integer types.
823 *
824 * @{
825 */
826
827/**
828 * Obtain an integer type from a context with specified bit width.
829 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000830LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
831LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
832LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
833LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
834LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000835LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000836LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
837
Gregory Szorc34c863a2012-03-21 03:54:29 +0000838/**
839 * Obtain an integer type from the global context with a specified bit
840 * width.
841 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000842LLVMTypeRef LLVMInt1Type(void);
843LLVMTypeRef LLVMInt8Type(void);
844LLVMTypeRef LLVMInt16Type(void);
845LLVMTypeRef LLVMInt32Type(void);
846LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000847LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000848LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000849unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000850
Gregory Szorc34c863a2012-03-21 03:54:29 +0000851/**
852 * @}
853 */
854
855/**
856 * @defgroup LLVMCCoreTypeFloat Floating Point Types
857 *
858 * @{
859 */
860
861/**
862 * Obtain a 16-bit floating point type from a context.
863 */
Dan Gohman518cda42011-12-17 00:04:22 +0000864LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000865
866/**
867 * Obtain a 32-bit floating point type from a context.
868 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000869LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000870
871/**
872 * Obtain a 64-bit floating point type from a context.
873 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000874LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000875
876/**
877 * Obtain a 80-bit floating point type (X87) from a context.
878 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000879LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000880
881/**
882 * Obtain a 128-bit floating point type (112-bit mantissa) from a
883 * context.
884 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000885LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000886
887/**
888 * Obtain a 128-bit floating point type (two 64-bits) from a context.
889 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000890LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
891
Gregory Szorc34c863a2012-03-21 03:54:29 +0000892/**
893 * Obtain a floating point type from the global context.
894 *
895 * These map to the functions in this group of the same name.
896 */
Dan Gohman518cda42011-12-17 00:04:22 +0000897LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000898LLVMTypeRef LLVMFloatType(void);
899LLVMTypeRef LLVMDoubleType(void);
900LLVMTypeRef LLVMX86FP80Type(void);
901LLVMTypeRef LLVMFP128Type(void);
902LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000903
Gregory Szorc34c863a2012-03-21 03:54:29 +0000904/**
905 * @}
906 */
907
908/**
909 * @defgroup LLVMCCoreTypeFunction Function Types
910 *
911 * @{
912 */
913
914/**
915 * Obtain a function type consisting of a specified signature.
916 *
917 * The function is defined as a tuple of a return Type, a list of
918 * parameter types, and whether the function is variadic.
919 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000920LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
921 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000922 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000923
924/**
925 * Returns whether a function type is variadic.
926 */
Chris Lattner25963c62010-01-09 22:27:07 +0000927LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000928
929/**
930 * Obtain the Type this function Type returns.
931 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000932LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000933
934/**
935 * Obtain the number of parameters this function accepts.
936 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000937unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000938
939/**
940 * Obtain the types of a function's parameters.
941 *
942 * The Dest parameter should point to a pre-allocated array of
943 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
944 * first LLVMCountParamTypes() entries in the array will be populated
945 * with LLVMTypeRef instances.
946 *
947 * @param FunctionTy The function type to operate on.
948 * @param Dest Memory address of an array to be filled with result.
949 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000950void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000951
Gregory Szorc34c863a2012-03-21 03:54:29 +0000952/**
953 * @}
954 */
955
956/**
957 * @defgroup LLVMCCoreTypeStruct Structure Types
958 *
959 * These functions relate to LLVMTypeRef instances.
960 *
961 * @see llvm::StructType
962 *
963 * @{
964 */
965
966/**
967 * Create a new structure type in a context.
968 *
969 * A structure is specified by a list of inner elements/types and
970 * whether these can be packed together.
971 *
972 * @see llvm::StructType::create()
973 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000974LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000975 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000976
977/**
978 * Create a new structure type in the global context.
979 *
980 * @see llvm::StructType::create()
981 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000982LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000983 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000984
985/**
986 * Create an empty structure in a context having a specified name.
987 *
988 * @see llvm::StructType::create()
989 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000990LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000991
992/**
993 * Obtain the name of a structure.
994 *
995 * @see llvm::StructType::getName()
996 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000997const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000998
999/**
1000 * Set the contents of a structure type.
1001 *
1002 * @see llvm::StructType::setBody()
1003 */
Chris Lattnere71ccde2011-07-14 05:53:17 +00001004void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
1005 unsigned ElementCount, LLVMBool Packed);
1006
Gregory Szorc34c863a2012-03-21 03:54:29 +00001007/**
1008 * Get the number of elements defined inside the structure.
1009 *
1010 * @see llvm::StructType::getNumElements()
1011 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001012unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001013
1014/**
1015 * Get the elements within a structure.
1016 *
1017 * The function is passed the address of a pre-allocated array of
1018 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
1019 * invocation, this array will be populated with the structure's
1020 * elements. The objects in the destination array will have a lifetime
1021 * of the structure type itself, which is the lifetime of the context it
1022 * is contained in.
1023 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001024void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001025
1026/**
Peter Zotovc164a3f2015-06-04 09:09:53 +00001027 * Get the type of the element at a given index in the structure.
1028 *
1029 * @see llvm::StructType::getTypeAtIndex()
1030 */
1031LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
1032
1033/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001034 * Determine whether a structure is packed.
1035 *
1036 * @see llvm::StructType::isPacked()
1037 */
Chris Lattner25963c62010-01-09 22:27:07 +00001038LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001039
1040/**
1041 * Determine whether a structure is opaque.
1042 *
1043 * @see llvm::StructType::isOpaque()
1044 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001045LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1046
Gregory Szorc34c863a2012-03-21 03:54:29 +00001047/**
1048 * @}
1049 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001050
Gregory Szorc34c863a2012-03-21 03:54:29 +00001051/**
1052 * @defgroup LLVMCCoreTypeSequential Sequential Types
1053 *
1054 * Sequential types represents "arrays" of types. This is a super class
1055 * for array, vector, and pointer types.
1056 *
1057 * @{
1058 */
1059
1060/**
1061 * Obtain the type of elements within a sequential type.
1062 *
1063 * This works on array, vector, and pointer types.
1064 *
1065 * @see llvm::SequentialType::getElementType()
1066 */
1067LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1068
1069/**
whitequarkf6059fd2017-06-05 11:49:52 +00001070 * Returns type's subtypes
1071 *
1072 * @see llvm::Type::subtypes()
1073 */
1074void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr);
1075
1076/**
1077 * Return the number of types in the derived type.
1078 *
1079 * @see llvm::Type::getNumContainedTypes()
1080 */
1081unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp);
1082
1083/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001084 * Create a fixed size array type that refers to a specific type.
1085 *
1086 * The created type will exist in the context that its element type
1087 * exists in.
1088 *
1089 * @see llvm::ArrayType::get()
1090 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001091LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001092
1093/**
1094 * Obtain the length of an array type.
1095 *
1096 * This only works on types that represent arrays.
1097 *
1098 * @see llvm::ArrayType::getNumElements()
1099 */
1100unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1101
1102/**
1103 * Create a pointer type that points to a defined type.
1104 *
1105 * The created type will exist in the context that its pointee type
1106 * exists in.
1107 *
1108 * @see llvm::PointerType::get()
1109 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001110LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001111
1112/**
1113 * Obtain the address space of a pointer type.
1114 *
1115 * This only works on types that represent pointers.
1116 *
1117 * @see llvm::PointerType::getAddressSpace()
1118 */
1119unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1120
1121/**
1122 * Create a vector type that contains a defined type and has a specific
1123 * number of elements.
1124 *
1125 * The created type will exist in the context thats its element type
1126 * exists in.
1127 *
1128 * @see llvm::VectorType::get()
1129 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001130LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001131
Gregory Szorc34c863a2012-03-21 03:54:29 +00001132/**
1133 * Obtain the number of elements in a vector type.
1134 *
1135 * This only works on types that represent vectors.
1136 *
1137 * @see llvm::VectorType::getNumElements()
1138 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001139unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1140
Gregory Szorc34c863a2012-03-21 03:54:29 +00001141/**
1142 * @}
1143 */
1144
1145/**
1146 * @defgroup LLVMCCoreTypeOther Other Types
1147 *
1148 * @{
1149 */
1150
1151/**
1152 * Create a void type in a context.
1153 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001154LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001155
1156/**
1157 * Create a label type in a context.
1158 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001159LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001160
1161/**
1162 * Create a X86 MMX type in a context.
1163 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001164LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001165
Gregory Szorc34c863a2012-03-21 03:54:29 +00001166/**
whitequark131f98f2017-10-27 11:51:40 +00001167 * Create a token type in a context.
1168 */
1169LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C);
1170
1171/**
1172 * Create a metadata type in a context.
1173 */
1174LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C);
1175
1176/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001177 * These are similar to the above functions except they operate on the
1178 * global context.
1179 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001180LLVMTypeRef LLVMVoidType(void);
1181LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001182LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001183
Gregory Szorc34c863a2012-03-21 03:54:29 +00001184/**
1185 * @}
1186 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001187
Gregory Szorc34c863a2012-03-21 03:54:29 +00001188/**
1189 * @}
1190 */
1191
1192/**
1193 * @defgroup LLVMCCoreValues Values
1194 *
1195 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001196 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001197 *
1198 * LLVMValueRef essentially represents llvm::Value. There is a rich
1199 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001200 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001201 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001202 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001203 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1204 * functions are defined by a macro, so it isn't obvious which are
1205 * available by looking at the Doxygen source code. Instead, look at the
1206 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1207 * of value names given. These value names also correspond to classes in
1208 * the llvm::Value hierarchy.
1209 *
1210 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001211 */
1212
Gordon Henriksen29e38942008-12-19 18:39:45 +00001213#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1214 macro(Argument) \
1215 macro(BasicBlock) \
1216 macro(InlineAsm) \
1217 macro(User) \
1218 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001219 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001220 macro(ConstantAggregateZero) \
1221 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001222 macro(ConstantDataSequential) \
1223 macro(ConstantDataArray) \
1224 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001225 macro(ConstantExpr) \
1226 macro(ConstantFP) \
1227 macro(ConstantInt) \
1228 macro(ConstantPointerNull) \
1229 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001230 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001231 macro(ConstantVector) \
1232 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001233 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001234 macro(GlobalObject) \
1235 macro(Function) \
1236 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001237 macro(UndefValue) \
1238 macro(Instruction) \
1239 macro(BinaryOperator) \
1240 macro(CallInst) \
1241 macro(IntrinsicInst) \
1242 macro(DbgInfoIntrinsic) \
1243 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001244 macro(MemIntrinsic) \
1245 macro(MemCpyInst) \
1246 macro(MemMoveInst) \
1247 macro(MemSetInst) \
1248 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001249 macro(FCmpInst) \
1250 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001251 macro(ExtractElementInst) \
1252 macro(GetElementPtrInst) \
1253 macro(InsertElementInst) \
1254 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001255 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001256 macro(PHINode) \
1257 macro(SelectInst) \
1258 macro(ShuffleVectorInst) \
1259 macro(StoreInst) \
1260 macro(TerminatorInst) \
1261 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001262 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001263 macro(InvokeInst) \
1264 macro(ReturnInst) \
1265 macro(SwitchInst) \
1266 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001267 macro(ResumeInst) \
David Majnemer654e1302015-07-31 17:58:14 +00001268 macro(CleanupReturnInst) \
1269 macro(CatchReturnInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001270 macro(FuncletPadInst) \
1271 macro(CatchPadInst) \
1272 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001273 macro(UnaryInstruction) \
1274 macro(AllocaInst) \
1275 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001276 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001277 macro(BitCastInst) \
1278 macro(FPExtInst) \
1279 macro(FPToSIInst) \
1280 macro(FPToUIInst) \
1281 macro(FPTruncInst) \
1282 macro(IntToPtrInst) \
1283 macro(PtrToIntInst) \
1284 macro(SExtInst) \
1285 macro(SIToFPInst) \
1286 macro(TruncInst) \
1287 macro(UIToFPInst) \
1288 macro(ZExtInst) \
1289 macro(ExtractValueInst) \
1290 macro(LoadInst) \
1291 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001292
Gregory Szorc34c863a2012-03-21 03:54:29 +00001293/**
1294 * @defgroup LLVMCCoreValueGeneral General APIs
1295 *
1296 * Functions in this section work on all LLVMValueRef instances,
1297 * regardless of their sub-type. They correspond to functions available
1298 * on llvm::Value.
1299 *
1300 * @{
1301 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001302
Gregory Szorc34c863a2012-03-21 03:54:29 +00001303/**
1304 * Obtain the type of a value.
1305 *
1306 * @see llvm::Value::getType()
1307 */
1308LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1309
1310/**
Peter Zotov3e4561c2016-04-06 22:21:29 +00001311 * Obtain the enumerated type of a Value instance.
1312 *
1313 * @see llvm::Value::getValueID()
1314 */
1315LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
1316
1317/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001318 * Obtain the string name of a value.
1319 *
1320 * @see llvm::Value::getName()
1321 */
1322const char *LLVMGetValueName(LLVMValueRef Val);
1323
1324/**
1325 * Set the string name of a value.
1326 *
1327 * @see llvm::Value::setName()
1328 */
1329void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1330
1331/**
1332 * Dump a representation of a value to stderr.
1333 *
1334 * @see llvm::Value::dump()
1335 */
1336void LLVMDumpValue(LLVMValueRef Val);
1337
1338/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001339 * Return a string representation of the value. Use
1340 * LLVMDisposeMessage to free the string.
1341 *
1342 * @see llvm::Value::print()
1343 */
1344char *LLVMPrintValueToString(LLVMValueRef Val);
1345
1346/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001347 * Replace all uses of a value with another one.
1348 *
1349 * @see llvm::Value::replaceAllUsesWith()
1350 */
1351void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1352
1353/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001354 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001355 */
1356LLVMBool LLVMIsConstant(LLVMValueRef Val);
1357
1358/**
1359 * Determine whether a value instance is undefined.
1360 */
1361LLVMBool LLVMIsUndef(LLVMValueRef Val);
1362
1363/**
1364 * Convert value instances between types.
1365 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001366 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001367 * series of functions allows you to cast an instance to a specific
1368 * type.
1369 *
1370 * If the cast is not valid for the specified type, NULL is returned.
1371 *
1372 * @see llvm::dyn_cast_or_null<>
1373 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001374#define LLVM_DECLARE_VALUE_CAST(name) \
1375 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1376LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1377
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001378LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1379LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1380
Gregory Szorc34c863a2012-03-21 03:54:29 +00001381/**
1382 * @}
1383 */
1384
1385/**
1386 * @defgroup LLVMCCoreValueUses Usage
1387 *
1388 * This module defines functions that allow you to inspect the uses of a
1389 * LLVMValueRef.
1390 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001391 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001392 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1393 * llvm::User and llvm::Value.
1394 *
1395 * @{
1396 */
1397
1398/**
1399 * Obtain the first use of a value.
1400 *
1401 * Uses are obtained in an iterator fashion. First, call this function
1402 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001403 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001404 * LLVMGetNextUse() returns NULL.
1405 *
1406 * @see llvm::Value::use_begin()
1407 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001408LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001409
1410/**
1411 * Obtain the next use of a value.
1412 *
1413 * This effectively advances the iterator. It returns NULL if you are on
1414 * the final use and no more are available.
1415 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001416LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001417
1418/**
1419 * Obtain the user value for a user.
1420 *
1421 * The returned value corresponds to a llvm::User type.
1422 *
1423 * @see llvm::Use::getUser()
1424 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001425LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001426
1427/**
1428 * Obtain the value this use corresponds to.
1429 *
1430 * @see llvm::Use::get().
1431 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001432LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001433
Gregory Szorc34c863a2012-03-21 03:54:29 +00001434/**
1435 * @}
1436 */
1437
1438/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001439 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001440 *
1441 * Function in this group pertain to LLVMValueRef instances that descent
1442 * from llvm::User. This includes constants, instructions, and
1443 * operators.
1444 *
1445 * @{
1446 */
1447
1448/**
1449 * Obtain an operand at a specific index in a llvm::User value.
1450 *
1451 * @see llvm::User::getOperand()
1452 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001453LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001454
1455/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001456 * Obtain the use of an operand at a specific index in a llvm::User value.
1457 *
1458 * @see llvm::User::getOperandUse()
1459 */
1460LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1461
1462/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001463 * Set an operand at a specific index in a llvm::User value.
1464 *
1465 * @see llvm::User::setOperand()
1466 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001467void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001468
1469/**
1470 * Obtain the number of operands in a llvm::User value.
1471 *
1472 * @see llvm::User::getNumOperands()
1473 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001474int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001475
Gregory Szorc34c863a2012-03-21 03:54:29 +00001476/**
1477 * @}
1478 */
1479
1480/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001481 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001482 *
1483 * This section contains APIs for interacting with LLVMValueRef that
1484 * correspond to llvm::Constant instances.
1485 *
1486 * These functions will work for any LLVMValueRef in the llvm::Constant
1487 * class hierarchy.
1488 *
1489 * @{
1490 */
1491
1492/**
1493 * Obtain a constant value referring to the null instance of a type.
1494 *
1495 * @see llvm::Constant::getNullValue()
1496 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001497LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001498
1499/**
1500 * Obtain a constant value referring to the instance of a type
1501 * consisting of all ones.
1502 *
1503 * This is only valid for integer types.
1504 *
1505 * @see llvm::Constant::getAllOnesValue()
1506 */
1507LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1508
1509/**
1510 * Obtain a constant value referring to an undefined value of a type.
1511 *
1512 * @see llvm::UndefValue::get()
1513 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001514LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001515
1516/**
1517 * Determine whether a value instance is null.
1518 *
1519 * @see llvm::Constant::isNullValue()
1520 */
Chris Lattner25963c62010-01-09 22:27:07 +00001521LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001522
1523/**
1524 * Obtain a constant that is a constant pointer pointing to NULL for a
1525 * specified type.
1526 */
Chris Lattner7f318242009-07-06 17:29:59 +00001527LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001528
Gregory Szorc34c863a2012-03-21 03:54:29 +00001529/**
1530 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1531 *
1532 * Functions in this group model LLVMValueRef instances that correspond
1533 * to constants referring to scalar types.
1534 *
1535 * For integer types, the LLVMTypeRef parameter should correspond to a
1536 * llvm::IntegerType instance and the returned LLVMValueRef will
1537 * correspond to a llvm::ConstantInt.
1538 *
1539 * For floating point types, the LLVMTypeRef returned corresponds to a
1540 * llvm::ConstantFP.
1541 *
1542 * @{
1543 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001544
Gregory Szorc34c863a2012-03-21 03:54:29 +00001545/**
1546 * Obtain a constant value for an integer type.
1547 *
1548 * The returned value corresponds to a llvm::ConstantInt.
1549 *
1550 * @see llvm::ConstantInt::get()
1551 *
1552 * @param IntTy Integer type to obtain value of.
1553 * @param N The value the returned instance should refer to.
1554 * @param SignExtend Whether to sign extend the produced value.
1555 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001556LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001557 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001558
1559/**
1560 * Obtain a constant value for an integer of arbitrary precision.
1561 *
1562 * @see llvm::ConstantInt::get()
1563 */
Chris Lattner4329e072010-11-23 02:47:22 +00001564LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1565 unsigned NumWords,
1566 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001567
1568/**
1569 * Obtain a constant value for an integer parsed from a string.
1570 *
1571 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1572 * string's length is available, it is preferred to call that function
1573 * instead.
1574 *
1575 * @see llvm::ConstantInt::get()
1576 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001577LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1578 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001579
1580/**
1581 * Obtain a constant value for an integer parsed from a string with
1582 * specified length.
1583 *
1584 * @see llvm::ConstantInt::get()
1585 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001586LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1587 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001588
1589/**
1590 * Obtain a constant value referring to a double floating point value.
1591 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001592LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001593
1594/**
1595 * Obtain a constant for a floating point value parsed from a string.
1596 *
1597 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1598 * should be used if the input string's length is known.
1599 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001600LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001601
1602/**
1603 * Obtain a constant for a floating point value parsed from a string.
1604 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001605LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1606 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001607
1608/**
1609 * Obtain the zero extended value for an integer constant value.
1610 *
1611 * @see llvm::ConstantInt::getZExtValue()
1612 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001613unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001614
1615/**
1616 * Obtain the sign extended value for an integer constant value.
1617 *
1618 * @see llvm::ConstantInt::getSExtValue()
1619 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001620long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001621
Gregory Szorc34c863a2012-03-21 03:54:29 +00001622/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001623 * Obtain the double value for an floating point constant value.
1624 * losesInfo indicates if some precision was lost in the conversion.
1625 *
1626 * @see llvm::ConstantFP::getDoubleValue
1627 */
1628double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1629
1630/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001631 * @}
1632 */
1633
1634/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001635 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1636 *
1637 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001638 *
1639 * @{
1640 */
1641
1642/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001643 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001644 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001645 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001646 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001647LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001648 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001649
1650/**
1651 * Create a ConstantDataSequential with string content in the global context.
1652 *
1653 * This is the same as LLVMConstStringInContext except it operates on the
1654 * global context.
1655 *
1656 * @see LLVMConstStringInContext()
1657 * @see llvm::ConstantDataArray::getString()
1658 */
1659LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1660 LLVMBool DontNullTerminate);
1661
1662/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001663 * Returns true if the specified constant is an array of i8.
1664 *
1665 * @see ConstantDataSequential::getAsString()
1666 */
1667LLVMBool LLVMIsConstantString(LLVMValueRef c);
1668
1669/**
1670 * Get the given constant data sequential as a string.
1671 *
1672 * @see ConstantDataSequential::getAsString()
1673 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00001674const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001675
1676/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001677 * Create an anonymous ConstantStruct with the specified values.
1678 *
1679 * @see llvm::ConstantStruct::getAnon()
1680 */
1681LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001682 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001683 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001684
Gregory Szorc52d26602012-03-21 07:28:27 +00001685/**
1686 * Create a ConstantStruct in the global Context.
1687 *
1688 * This is the same as LLVMConstStructInContext except it operates on the
1689 * global Context.
1690 *
1691 * @see LLVMConstStructInContext()
1692 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001693LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001694 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001695
1696/**
1697 * Create a ConstantArray from values.
1698 *
1699 * @see llvm::ConstantArray::get()
1700 */
1701LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1702 LLVMValueRef *ConstantVals, unsigned Length);
1703
1704/**
1705 * Create a non-anonymous ConstantStruct from values.
1706 *
1707 * @see llvm::ConstantStruct::get()
1708 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001709LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1710 LLVMValueRef *ConstantVals,
1711 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001712
1713/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001714 * Get an element at specified index as a constant.
1715 *
1716 * @see ConstantDataSequential::getElementAsConstant()
1717 */
Amaury Sechet006ce632016-03-13 00:54:40 +00001718LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001719
1720/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001721 * Create a ConstantVector from values.
1722 *
1723 * @see llvm::ConstantVector::get()
1724 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001725LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001726
Gregory Szorc52d26602012-03-21 07:28:27 +00001727/**
1728 * @}
1729 */
1730
1731/**
1732 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1733 *
1734 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1735 *
1736 * @see llvm::ConstantExpr.
1737 *
1738 * @{
1739 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001740LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001741LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001742LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1743LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001744LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1745LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001746LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001747LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1748LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001749LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001750LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001751LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001752LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001753LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1754LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001755LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001756LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001757LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1758LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001759LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001760LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Manuel Jacob49fafb12016-10-04 23:32:42 +00001761LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001762LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001763LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001764LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1765LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1766LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1767LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1768LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1769LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1770LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1771LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1772 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1773LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1774 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1775LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1776LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1777LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1778LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1779 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001780LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1781 LLVMValueRef *ConstantIndices,
1782 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001783LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1784LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1785LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1786LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1787LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1788LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1789LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1790LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1791LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1792LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1793LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1794LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001795LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001796LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1797 LLVMTypeRef ToType);
1798LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1799 LLVMTypeRef ToType);
1800LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1801 LLVMTypeRef ToType);
1802LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1803 LLVMTypeRef ToType);
1804LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001805 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001806LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001807LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1808 LLVMValueRef ConstantIfTrue,
1809 LLVMValueRef ConstantIfFalse);
1810LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1811 LLVMValueRef IndexConstant);
1812LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1813 LLVMValueRef ElementValueConstant,
1814 LLVMValueRef IndexConstant);
1815LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1816 LLVMValueRef VectorBConstant,
1817 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001818LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1819 unsigned NumIdx);
1820LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1821 LLVMValueRef ElementValueConstant,
1822 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001823LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001824 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001825 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001826LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001827
Gregory Szorc52d26602012-03-21 07:28:27 +00001828/**
1829 * @}
1830 */
1831
1832/**
1833 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1834 *
1835 * This group contains functions that operate on global values. Functions in
1836 * this group relate to functions in the llvm::GlobalValue class tree.
1837 *
1838 * @see llvm::GlobalValue
1839 *
1840 * @{
1841 */
1842
Gordon Henriksen265f7802008-03-19 01:11:35 +00001843LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001844LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001845LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1846void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1847const char *LLVMGetSection(LLVMValueRef Global);
1848void LLVMSetSection(LLVMValueRef Global, const char *Section);
1849LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1850void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001851LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1852void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Robert Widmann4bb481b2018-03-14 06:45:51 +00001853LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global);
1854void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr);
1855
1856/** Deprecated: Use LLVMGetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00001857LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
Robert Widmann4bb481b2018-03-14 06:45:51 +00001858/** Deprecated: Use LLVMSetUnnamedAddress instead. */
Tim Northoverad96d012014-03-10 19:24:35 +00001859void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001860
1861/**
1862 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1863 *
1864 * Functions in this group only apply to values with alignment, i.e.
1865 * global variables, load and store instructions.
1866 */
1867
1868/**
1869 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001870 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001871 * @see llvm::LoadInst::getAlignment()
1872 * @see llvm::StoreInst::getAlignment()
1873 * @see llvm::GlobalValue::getAlignment()
1874 */
1875unsigned LLVMGetAlignment(LLVMValueRef V);
1876
1877/**
1878 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001879 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001880 * @see llvm::LoadInst::setAlignment()
1881 * @see llvm::StoreInst::setAlignment()
1882 * @see llvm::GlobalValue::setAlignment()
1883 */
1884void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1885
1886/**
Amaury Sechet83550102016-02-14 08:58:49 +00001887 * @}
1888 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001889
Gregory Szorc52d26602012-03-21 07:28:27 +00001890/**
1891 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1892 *
1893 * This group contains functions that operate on global variable values.
1894 *
1895 * @see llvm::GlobalVariable
1896 *
1897 * @{
1898 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001899LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001900LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1901 const char *Name,
1902 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001903LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001904LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1905LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1906LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1907LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001908void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001909LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1910void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001911LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1912void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1913LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1914void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001915LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1916void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1917LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1918void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001919
Gregory Szorc52d26602012-03-21 07:28:27 +00001920/**
1921 * @}
1922 */
1923
1924/**
1925 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1926 *
1927 * This group contains function that operate on global alias values.
1928 *
1929 * @see llvm::GlobalAlias
1930 *
1931 * @{
1932 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001933LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1934 const char *Name);
1935
Gregory Szorc34c863a2012-03-21 03:54:29 +00001936/**
1937 * @}
1938 */
1939
1940/**
1941 * @defgroup LLVMCCoreValueFunction Function values
1942 *
1943 * Functions in this group operate on LLVMValueRef instances that
1944 * correspond to llvm::Function instances.
1945 *
1946 * @see llvm::Function
1947 *
1948 * @{
1949 */
1950
1951/**
1952 * Remove a function from its containing module and deletes it.
1953 *
1954 * @see llvm::Function::eraseFromParent()
1955 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001956void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001957
1958/**
Amaury Sechete39e8532016-02-18 20:38:32 +00001959 * Check whether the given function has a personality function.
1960 *
1961 * @see llvm::Function::hasPersonalityFn()
1962 */
1963LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
1964
1965/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00001966 * Obtain the personality function attached to the function.
1967 *
1968 * @see llvm::Function::getPersonalityFn()
1969 */
1970LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
1971
1972/**
1973 * Set the personality function attached to the function.
1974 *
1975 * @see llvm::Function::setPersonalityFn()
1976 */
1977void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
1978
1979/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001980 * Obtain the ID number from a function instance.
1981 *
1982 * @see llvm::Function::getIntrinsicID()
1983 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001984unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001985
1986/**
1987 * Obtain the calling function of a function.
1988 *
1989 * The returned value corresponds to the LLVMCallConv enumeration.
1990 *
1991 * @see llvm::Function::getCallingConv()
1992 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001993unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001994
1995/**
1996 * Set the calling convention of a function.
1997 *
1998 * @see llvm::Function::setCallingConv()
1999 *
2000 * @param Fn Function to operate on
2001 * @param CC LLVMCallConv to set calling convention to
2002 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002003void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002004
2005/**
2006 * Obtain the name of the garbage collector to use during code
2007 * generation.
2008 *
2009 * @see llvm::Function::getGC()
2010 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002011const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002012
2013/**
2014 * Define the garbage collector to use during code generation.
2015 *
2016 * @see llvm::Function::setGC()
2017 */
Gordon Henriksend930f912008-08-17 18:44:35 +00002018void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002019
2020/**
2021 * Add an attribute to a function.
2022 *
2023 * @see llvm::Function::addAttribute()
2024 */
Amaury Sechet5db224e2016-06-12 06:17:24 +00002025void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2026 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00002027unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx);
2028void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2029 LLVMAttributeRef *Attrs);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002030LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
2031 LLVMAttributeIndex Idx,
2032 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002033LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
2034 LLVMAttributeIndex Idx,
2035 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002036void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2037 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002038void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2039 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002040
Gregory Szorc34c863a2012-03-21 03:54:29 +00002041/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00002042 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00002043 * @see llvm::AttrBuilder::addAttribute()
2044 */
2045void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
2046 const char *V);
2047
2048/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002049 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
2050 *
2051 * Functions in this group relate to arguments/parameters on functions.
2052 *
2053 * Functions in this group expect LLVMValueRef instances that correspond
2054 * to llvm::Function instances.
2055 *
2056 * @{
2057 */
2058
2059/**
2060 * Obtain the number of parameters in a function.
2061 *
2062 * @see llvm::Function::arg_size()
2063 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002064unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002065
2066/**
2067 * Obtain the parameters in a function.
2068 *
2069 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
2070 * at least LLVMCountParams() long. This array will be filled with
2071 * LLVMValueRef instances which correspond to the parameters the
2072 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
2073 * instance.
2074 *
2075 * @see llvm::Function::arg_begin()
2076 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002077void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002078
2079/**
2080 * Obtain the parameter at the specified index.
2081 *
2082 * Parameters are indexed from 0.
2083 *
2084 * @see llvm::Function::arg_begin()
2085 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002086LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002087
2088/**
2089 * Obtain the function to which this argument belongs.
2090 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002091 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002092 * that corresponds to a llvm::Attribute.
2093 *
2094 * The returned LLVMValueRef is the llvm::Function to which this
2095 * argument belongs.
2096 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002097LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002098
2099/**
2100 * Obtain the first parameter to a function.
2101 *
2102 * @see llvm::Function::arg_begin()
2103 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002104LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002105
2106/**
2107 * Obtain the last parameter to a function.
2108 *
2109 * @see llvm::Function::arg_end()
2110 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002111LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002112
2113/**
2114 * Obtain the next parameter to a function.
2115 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002116 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002117 * actually a wrapped iterator) and obtains the next parameter from the
2118 * underlying iterator.
2119 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002120LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002121
2122/**
2123 * Obtain the previous parameter to a function.
2124 *
2125 * This is the opposite of LLVMGetNextParam().
2126 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002127LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002128
2129/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002130 * Set the alignment for a function parameter.
2131 *
2132 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002133 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002134 */
Amaury Sechet81243a72016-05-01 01:42:34 +00002135void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002136
Gregory Szorc34c863a2012-03-21 03:54:29 +00002137/**
2138 * @}
2139 */
2140
2141/**
2142 * @}
2143 */
2144
2145/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002146 * @}
2147 */
2148
2149/**
2150 * @}
2151 */
2152
2153/**
2154 * @defgroup LLVMCCoreValueMetadata Metadata
2155 *
2156 * @{
2157 */
2158
2159/**
2160 * Obtain a MDString value from a context.
2161 *
2162 * The returned instance corresponds to the llvm::MDString class.
2163 *
2164 * The instance is specified by string data of a specified length. The
2165 * string content is copied, so the backing memory can be freed after
2166 * this function returns.
2167 */
2168LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2169 unsigned SLen);
2170
2171/**
2172 * Obtain a MDString value from the global context.
2173 */
2174LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2175
2176/**
2177 * Obtain a MDNode value from a context.
2178 *
2179 * The returned value corresponds to the llvm::MDNode class.
2180 */
2181LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2182 unsigned Count);
2183
2184/**
2185 * Obtain a MDNode value from the global context.
2186 */
2187LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2188
2189/**
Amaury Sechetf8429752017-04-17 11:52:54 +00002190 * Obtain a Metadata as a Value.
2191 */
2192LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
2193
2194/**
2195 * Obtain a Value as a Metadata.
2196 */
2197LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
2198
2199/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002200 * Obtain the underlying string from a MDString value.
2201 *
2202 * @param V Instance to obtain string from.
NAKAMURA Takumie4a77052016-04-04 11:54:48 +00002203 * @param Length Memory address which will hold length of returned string.
Gregory Szorc52d26602012-03-21 07:28:27 +00002204 * @return String data in MDString.
2205 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002206const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
Gregory Szorc52d26602012-03-21 07:28:27 +00002207
2208/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002209 * Obtain the number of operands from an MDNode value.
2210 *
2211 * @param V MDNode to get number of operands from.
2212 * @return Number of operands of the MDNode.
2213 */
2214unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2215
2216/**
2217 * Obtain the given MDNode's operands.
2218 *
2219 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2220 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2221 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2222 * MDNode's operands.
2223 *
2224 * @param V MDNode to get the operands from.
2225 * @param Dest Destination array for operands.
2226 */
2227void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2228
2229/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002230 * @}
2231 */
2232
2233/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002234 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2235 *
2236 * A basic block represents a single entry single exit section of code.
2237 * Basic blocks contain a list of instructions which form the body of
2238 * the block.
2239 *
2240 * Basic blocks belong to functions. They have the type of label.
2241 *
2242 * Basic blocks are themselves values. However, the C API models them as
2243 * LLVMBasicBlockRef.
2244 *
2245 * @see llvm::BasicBlock
2246 *
2247 * @{
2248 */
2249
2250/**
2251 * Convert a basic block instance to a value type.
2252 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002253LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002254
2255/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002256 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002257 */
Chris Lattner25963c62010-01-09 22:27:07 +00002258LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002259
2260/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002261 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002262 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002263LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002264
2265/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002266 * Obtain the string name of a basic block.
2267 */
2268const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2269
2270/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002271 * Obtain the function to which a basic block belongs.
2272 *
2273 * @see llvm::BasicBlock::getParent()
2274 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002275LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002276
2277/**
2278 * Obtain the terminator instruction for a basic block.
2279 *
2280 * If the basic block does not have a terminator (it is not well-formed
2281 * if it doesn't), then NULL is returned.
2282 *
2283 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2284 *
2285 * @see llvm::BasicBlock::getTerminator()
2286 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002287LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002288
2289/**
2290 * Obtain the number of basic blocks in a function.
2291 *
2292 * @param Fn Function value to operate on.
2293 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002294unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002295
2296/**
2297 * Obtain all of the basic blocks in a function.
2298 *
2299 * This operates on a function value. The BasicBlocks parameter is a
2300 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2301 * LLVMCountBasicBlocks() in length. This array is populated with
2302 * LLVMBasicBlockRef instances.
2303 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002304void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002305
2306/**
2307 * Obtain the first basic block in a function.
2308 *
2309 * The returned basic block can be used as an iterator. You will likely
2310 * eventually call into LLVMGetNextBasicBlock() with it.
2311 *
2312 * @see llvm::Function::begin()
2313 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002314LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002315
2316/**
2317 * Obtain the last basic block in a function.
2318 *
2319 * @see llvm::Function::end()
2320 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002321LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002322
2323/**
2324 * Advance a basic block iterator.
2325 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002326LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002327
2328/**
2329 * Go backwards in a basic block iterator.
2330 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002331LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002332
2333/**
2334 * Obtain the basic block that corresponds to the entry point of a
2335 * function.
2336 *
2337 * @see llvm::Function::getEntryBlock()
2338 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002339LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002340
Gregory Szorc34c863a2012-03-21 03:54:29 +00002341/**
2342 * Append a basic block to the end of a function.
2343 *
2344 * @see llvm::BasicBlock::Create()
2345 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002346LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2347 LLVMValueRef Fn,
2348 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002349
2350/**
2351 * Append a basic block to the end of a function using the global
2352 * context.
2353 *
2354 * @see llvm::BasicBlock::Create()
2355 */
2356LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2357
2358/**
2359 * Insert a basic block in a function before another basic block.
2360 *
2361 * The function to add to is determined by the function of the
2362 * passed basic block.
2363 *
2364 * @see llvm::BasicBlock::Create()
2365 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002366LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2367 LLVMBasicBlockRef BB,
2368 const char *Name);
2369
Gregory Szorc34c863a2012-03-21 03:54:29 +00002370/**
2371 * Insert a basic block in a function using the global context.
2372 *
2373 * @see llvm::BasicBlock::Create()
2374 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002375LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2376 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002377
2378/**
2379 * Remove a basic block from a function and delete it.
2380 *
2381 * This deletes the basic block from its containing function and deletes
2382 * the basic block itself.
2383 *
2384 * @see llvm::BasicBlock::eraseFromParent()
2385 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002386void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002387
2388/**
2389 * Remove a basic block from a function.
2390 *
2391 * This deletes the basic block from its containing function but keep
2392 * the basic block alive.
2393 *
2394 * @see llvm::BasicBlock::removeFromParent()
2395 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002396void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002397
Gregory Szorc34c863a2012-03-21 03:54:29 +00002398/**
2399 * Move a basic block to before another one.
2400 *
2401 * @see llvm::BasicBlock::moveBefore()
2402 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002403void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002404
2405/**
2406 * Move a basic block to after another one.
2407 *
2408 * @see llvm::BasicBlock::moveAfter()
2409 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002410void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2411
Gregory Szorc34c863a2012-03-21 03:54:29 +00002412/**
2413 * Obtain the first instruction in a basic block.
2414 *
2415 * The returned LLVMValueRef corresponds to a llvm::Instruction
2416 * instance.
2417 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002418LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002419
2420/**
2421 * Obtain the last instruction in a basic block.
2422 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002423 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002424 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002425LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002426
Gregory Szorc34c863a2012-03-21 03:54:29 +00002427/**
2428 * @}
2429 */
2430
2431/**
2432 * @defgroup LLVMCCoreValueInstruction Instructions
2433 *
2434 * Functions in this group relate to the inspection and manipulation of
2435 * individual instructions.
2436 *
2437 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2438 * class has a large number of descendents. llvm::Instruction is a
2439 * llvm::Value and in the C API, instructions are modeled by
2440 * LLVMValueRef.
2441 *
2442 * This group also contains sub-groups which operate on specific
2443 * llvm::Instruction types, e.g. llvm::CallInst.
2444 *
2445 * @{
2446 */
2447
2448/**
2449 * Determine whether an instruction has any metadata attached.
2450 */
2451int LLVMHasMetadata(LLVMValueRef Val);
2452
2453/**
2454 * Return metadata associated with an instruction value.
2455 */
2456LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2457
2458/**
2459 * Set metadata associated with an instruction value.
2460 */
2461void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2462
2463/**
2464 * Obtain the basic block to which an instruction belongs.
2465 *
2466 * @see llvm::Instruction::getParent()
2467 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002468LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002469
2470/**
2471 * Obtain the instruction that occurs after the one specified.
2472 *
2473 * The next instruction will be from the same basic block.
2474 *
2475 * If this is the last instruction in a basic block, NULL will be
2476 * returned.
2477 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002478LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002479
2480/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002481 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002482 *
2483 * If the instruction is the first instruction in a basic block, NULL
2484 * will be returned.
2485 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002486LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002487
2488/**
2489 * Remove and delete an instruction.
2490 *
2491 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00002492 * block but is kept alive.
2493 *
2494 * @see llvm::Instruction::removeFromParent()
2495 */
2496void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
2497
2498/**
2499 * Remove and delete an instruction.
2500 *
2501 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00002502 * block and then deleted.
2503 *
2504 * @see llvm::Instruction::eraseFromParent()
2505 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002506void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002507
2508/**
2509 * Obtain the code opcode for an individual instruction.
2510 *
2511 * @see llvm::Instruction::getOpCode()
2512 */
Eric Christophera6b96002015-12-18 01:46:52 +00002513LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002514
2515/**
2516 * Obtain the predicate of an instruction.
2517 *
2518 * This is only valid for instructions that correspond to llvm::ICmpInst
2519 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2520 *
2521 * @see llvm::ICmpInst::getPredicate()
2522 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002523LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002524
Gregory Szorc34c863a2012-03-21 03:54:29 +00002525/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00002526 * Obtain the float predicate of an instruction.
2527 *
2528 * This is only valid for instructions that correspond to llvm::FCmpInst
2529 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
2530 *
2531 * @see llvm::FCmpInst::getPredicate()
2532 */
2533LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
2534
2535/**
Peter Zotovaff492c2014-10-17 01:02:34 +00002536 * Create a copy of 'this' instruction that is identical in all ways
2537 * except the following:
2538 * * The instruction has no parent
2539 * * The instruction has no name
2540 *
2541 * @see llvm::Instruction::clone()
2542 */
2543LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
2544
2545/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002546 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2547 *
2548 * Functions in this group apply to instructions that refer to call
2549 * sites and invocations. These correspond to C++ types in the
2550 * llvm::CallInst class tree.
2551 *
2552 * @{
2553 */
2554
2555/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002556 * Obtain the argument count for a call instruction.
2557 *
Vlad Tsyrklevich894c0282018-03-30 06:21:28 +00002558 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2559 * llvm::InvokeInst.
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002560 *
2561 * @see llvm::CallInst::getNumArgOperands()
2562 * @see llvm::InvokeInst::getNumArgOperands()
2563 */
2564unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
2565
2566/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002567 * Set the calling convention for a call instruction.
2568 *
2569 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2570 * llvm::InvokeInst.
2571 *
2572 * @see llvm::CallInst::setCallingConv()
2573 * @see llvm::InvokeInst::setCallingConv()
2574 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002575void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002576
2577/**
2578 * Obtain the calling convention for a call instruction.
2579 *
2580 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2581 * usage.
2582 *
2583 * @see LLVMSetInstructionCallConv()
2584 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002585unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002586
Gregory Szorc34c863a2012-03-21 03:54:29 +00002587void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Amaury Sechet81243a72016-05-01 01:42:34 +00002588 unsigned Align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002589
Amaury Secheta65a2372016-06-15 05:14:29 +00002590void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2591 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00002592unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx);
2593void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
2594 LLVMAttributeRef *Attrs);
Amaury Secheta65a2372016-06-15 05:14:29 +00002595LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
2596 LLVMAttributeIndex Idx,
2597 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002598LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
2599 LLVMAttributeIndex Idx,
2600 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00002601void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2602 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002603void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2604 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00002605
Gregory Szorc34c863a2012-03-21 03:54:29 +00002606/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002607 * Obtain the pointer to the function invoked by this instruction.
2608 *
2609 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2610 * llvm::InvokeInst.
2611 *
2612 * @see llvm::CallInst::getCalledValue()
2613 * @see llvm::InvokeInst::getCalledValue()
2614 */
2615LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
2616
2617/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002618 * Obtain whether a call instruction is a tail call.
2619 *
2620 * This only works on llvm::CallInst instructions.
2621 *
2622 * @see llvm::CallInst::isTailCall()
2623 */
Chris Lattner25963c62010-01-09 22:27:07 +00002624LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002625
2626/**
2627 * Set whether a call instruction is a tail call.
2628 *
2629 * This only works on llvm::CallInst instructions.
2630 *
2631 * @see llvm::CallInst::setTailCall()
2632 */
Chris Lattner25963c62010-01-09 22:27:07 +00002633void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002634
Gregory Szorc34c863a2012-03-21 03:54:29 +00002635/**
Amaury Sechete39e8532016-02-18 20:38:32 +00002636 * Return the normal destination basic block.
2637 *
2638 * This only works on llvm::InvokeInst instructions.
2639 *
2640 * @see llvm::InvokeInst::getNormalDest()
2641 */
2642LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
2643
2644/**
2645 * Return the unwind destination basic block.
2646 *
Vlad Tsyrklevich894c0282018-03-30 06:21:28 +00002647 * This only works on llvm::InvokeInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00002648 *
2649 * @see llvm::InvokeInst::getUnwindDest()
2650 */
2651LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
2652
2653/**
2654 * Set the normal destination basic block.
2655 *
2656 * This only works on llvm::InvokeInst instructions.
2657 *
2658 * @see llvm::InvokeInst::setNormalDest()
2659 */
2660void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2661
2662/**
2663 * Set the unwind destination basic block.
2664 *
Vlad Tsyrklevich894c0282018-03-30 06:21:28 +00002665 * This only works on llvm::InvokeInst instructions.
Amaury Sechete39e8532016-02-18 20:38:32 +00002666 *
2667 * @see llvm::InvokeInst::setUnwindDest()
2668 */
2669void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2670
2671/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002672 * @}
2673 */
2674
2675/**
Peter Zotov2481c752014-10-28 19:46:56 +00002676 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
2677 *
2678 * Functions in this group only apply to instructions that map to
2679 * llvm::TerminatorInst instances.
2680 *
2681 * @{
2682 */
2683
2684/**
2685 * Return the number of successors that this terminator has.
2686 *
2687 * @see llvm::TerminatorInst::getNumSuccessors
2688 */
2689unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
2690
2691/**
2692 * Return the specified successor.
2693 *
2694 * @see llvm::TerminatorInst::getSuccessor
2695 */
2696LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
2697
2698/**
2699 * Update the specified successor to point at the provided block.
2700 *
2701 * @see llvm::TerminatorInst::setSuccessor
2702 */
2703void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
2704
2705/**
2706 * Return if a branch is conditional.
2707 *
2708 * This only works on llvm::BranchInst instructions.
2709 *
2710 * @see llvm::BranchInst::isConditional
2711 */
2712LLVMBool LLVMIsConditional(LLVMValueRef Branch);
2713
2714/**
2715 * Return the condition of a branch instruction.
2716 *
2717 * This only works on llvm::BranchInst instructions.
2718 *
2719 * @see llvm::BranchInst::getCondition
2720 */
2721LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
2722
2723/**
2724 * Set the condition of a branch instruction.
2725 *
2726 * This only works on llvm::BranchInst instructions.
2727 *
2728 * @see llvm::BranchInst::setCondition
2729 */
2730void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
2731
2732/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002733 * Obtain the default destination basic block of a switch instruction.
2734 *
2735 * This only works on llvm::SwitchInst instructions.
2736 *
2737 * @see llvm::SwitchInst::getDefaultDest()
2738 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002739LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2740
Gregory Szorc34c863a2012-03-21 03:54:29 +00002741/**
Peter Zotov2481c752014-10-28 19:46:56 +00002742 * @}
2743 */
2744
2745/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00002746 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
2747 *
2748 * Functions in this group only apply to instructions that map to
2749 * llvm::AllocaInst instances.
2750 *
2751 * @{
2752 */
2753
2754/**
2755 * Obtain the type that is being allocated by the alloca instruction.
2756 */
2757LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
2758
2759/**
2760 * @}
2761 */
2762
2763/**
Amaury Sechet053ac452016-02-17 22:51:03 +00002764 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
2765 *
2766 * Functions in this group only apply to instructions that map to
2767 * llvm::GetElementPtrInst instances.
2768 *
2769 * @{
2770 */
2771
2772/**
2773 * Check whether the given GEP instruction is inbounds.
2774 */
2775LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
2776
2777/**
2778 * Set the given GEP instruction to be inbounds or not.
2779 */
Amaury Sechet8a367d42016-05-01 02:23:14 +00002780void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
Amaury Sechet053ac452016-02-17 22:51:03 +00002781
2782/**
2783 * @}
2784 */
2785
2786/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002787 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2788 *
2789 * Functions in this group only apply to instructions that map to
2790 * llvm::PHINode instances.
2791 *
2792 * @{
2793 */
2794
2795/**
2796 * Add an incoming value to the end of a PHI list.
2797 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002798void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2799 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002800
2801/**
2802 * Obtain the number of incoming basic blocks to a PHI node.
2803 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002804unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002805
2806/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002807 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002808 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002809LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002810
2811/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002812 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002813 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002814LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002815
Gregory Szorc34c863a2012-03-21 03:54:29 +00002816/**
2817 * @}
2818 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002819
Gregory Szorc34c863a2012-03-21 03:54:29 +00002820/**
Amaury Sechetaad93532016-02-10 00:38:50 +00002821 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
2822 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
2823 *
2824 * Functions in this group only apply to instructions that map to
2825 * llvm::ExtractValue and llvm::InsertValue instances.
2826 *
2827 * @{
2828 */
2829
2830/**
2831 * Obtain the number of indices.
Amaury Sechet053ac452016-02-17 22:51:03 +00002832 * NB: This also works on GEP.
Amaury Sechetaad93532016-02-10 00:38:50 +00002833 */
2834unsigned LLVMGetNumIndices(LLVMValueRef Inst);
2835
2836/**
2837 * Obtain the indices as an array.
2838 */
2839const unsigned *LLVMGetIndices(LLVMValueRef Inst);
2840
2841/**
2842 * @}
2843 */
2844
2845/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002846 * @}
2847 */
2848
2849/**
2850 * @}
2851 */
2852
2853/**
2854 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2855 *
2856 * An instruction builder represents a point within a basic block and is
2857 * the exclusive means of building instructions using the C interface.
2858 *
2859 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002860 */
2861
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002862LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002863LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002864void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2865 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002866void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2867void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002868LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002869void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2870void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002871void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2872 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002873void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2874
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002875/* Metadata */
2876void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2877LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2878void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2879
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002880/* Terminators */
2881LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2882LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002883LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002884 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002885LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2886LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2887 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2888LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2889 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002890LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2891 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002892LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2893 LLVMValueRef *Args, unsigned NumArgs,
2894 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2895 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002896LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00002897 LLVMValueRef PersFn, unsigned NumClauses,
2898 const char *Name);
Vlad Tsyrklevich894c0282018-03-30 06:21:28 +00002899LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2900LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002901
Gordon Henriksen097102c2008-01-01 05:50:53 +00002902/* Add a case to the switch instruction */
2903void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2904 LLVMBasicBlockRef Dest);
2905
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002906/* Add a destination to the indirectbr instruction */
2907void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2908
Amaury Sechete39e8532016-02-18 20:38:32 +00002909/* Get the number of clauses on the landingpad instruction */
2910unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
2911
2912/* Get the value of the clause at idnex Idx on the landingpad instruction */
2913LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
2914
Bill Wendlingfae14752011-08-12 20:24:12 +00002915/* Add a catch or filter clause to the landingpad instruction */
2916void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2917
Amaury Sechete39e8532016-02-18 20:38:32 +00002918/* Get the 'cleanup' flag in the landingpad instruction */
2919LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
2920
Bill Wendlingfae14752011-08-12 20:24:12 +00002921/* Set the 'cleanup' flag in the landingpad instruction */
2922void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2923
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002924/* Arithmetic */
2925LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2926 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002927LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2928 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002929LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2930 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002931LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2932 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002933LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2934 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002935LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2936 const char *Name);
2937LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2938 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002939LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2940 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002941LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2942 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002943LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2944 const char *Name);
2945LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2946 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002947LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2948 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002949LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2950 const char *Name);
Manuel Jacob49fafb12016-10-04 23:32:42 +00002951LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2952 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002953LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2954 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002955LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2956 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002957LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2958 const char *Name);
2959LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2960 const char *Name);
2961LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2962 const char *Name);
2963LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2964 const char *Name);
2965LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2966 const char *Name);
2967LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2968 const char *Name);
2969LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2970 const char *Name);
2971LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2972 const char *Name);
2973LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2974 const char *Name);
2975LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2976 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002977LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2978 LLVMValueRef LHS, LLVMValueRef RHS,
2979 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002980LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002981LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2982 const char *Name);
2983LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2984 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002985LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002986LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2987
2988/* Memory */
2989LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2990LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2991 LLVMValueRef Val, const char *Name);
2992LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2993LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2994 LLVMValueRef Val, const char *Name);
2995LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2996LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2997 const char *Name);
2998LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2999LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3000 LLVMValueRef *Indices, unsigned NumIndices,
3001 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003002LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3003 LLVMValueRef *Indices, unsigned NumIndices,
3004 const char *Name);
3005LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
3006 unsigned Idx, const char *Name);
3007LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
3008 const char *Name);
3009LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
3010 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00003011LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
3012void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00003013LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
3014void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003015
3016/* Casts */
3017LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
3018 LLVMTypeRef DestTy, const char *Name);
3019LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
3020 LLVMTypeRef DestTy, const char *Name);
3021LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
3022 LLVMTypeRef DestTy, const char *Name);
3023LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
3024 LLVMTypeRef DestTy, const char *Name);
3025LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
3026 LLVMTypeRef DestTy, const char *Name);
3027LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
3028 LLVMTypeRef DestTy, const char *Name);
3029LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
3030 LLVMTypeRef DestTy, const char *Name);
3031LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
3032 LLVMTypeRef DestTy, const char *Name);
3033LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
3034 LLVMTypeRef DestTy, const char *Name);
3035LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
3036 LLVMTypeRef DestTy, const char *Name);
3037LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
3038 LLVMTypeRef DestTy, const char *Name);
3039LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
3040 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003041LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
3042 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003043LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3044 LLVMTypeRef DestTy, const char *Name);
3045LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3046 LLVMTypeRef DestTy, const char *Name);
3047LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3048 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003049LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
3050 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003051LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
3052 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00003053LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003054 LLVMTypeRef DestTy, const char *Name);
3055LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
3056 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003057
3058/* Comparisons */
3059LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
3060 LLVMValueRef LHS, LLVMValueRef RHS,
3061 const char *Name);
3062LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
3063 LLVMValueRef LHS, LLVMValueRef RHS,
3064 const char *Name);
3065
3066/* Miscellaneous instructions */
3067LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3068LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
3069 LLVMValueRef *Args, unsigned NumArgs,
3070 const char *Name);
3071LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
3072 LLVMValueRef Then, LLVMValueRef Else,
3073 const char *Name);
3074LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
3075 const char *Name);
3076LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
3077 LLVMValueRef Index, const char *Name);
3078LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
3079 LLVMValueRef EltVal, LLVMValueRef Index,
3080 const char *Name);
3081LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
3082 LLVMValueRef V2, LLVMValueRef Mask,
3083 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00003084LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
3085 unsigned Index, const char *Name);
3086LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
3087 LLVMValueRef EltVal, unsigned Index,
3088 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00003089
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003090LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
3091 const char *Name);
3092LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
3093 const char *Name);
3094LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
3095 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00003096LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
3097 LLVMBool singleThread, const char *Name);
3098LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00003099 LLVMValueRef PTR, LLVMValueRef Val,
3100 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00003101 LLVMBool singleThread);
Mehdi Amini43165d92016-03-19 21:28:28 +00003102LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
3103 LLVMValueRef Cmp, LLVMValueRef New,
3104 LLVMAtomicOrdering SuccessOrdering,
3105 LLVMAtomicOrdering FailureOrdering,
3106 LLVMBool SingleThread);
3107
3108LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
3109void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
3110
3111LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
3112void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
3113 LLVMAtomicOrdering Ordering);
3114LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
3115void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
3116 LLVMAtomicOrdering Ordering);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003117
Gregory Szorc34c863a2012-03-21 03:54:29 +00003118/**
3119 * @}
3120 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003121
Gregory Szorc34c863a2012-03-21 03:54:29 +00003122/**
3123 * @defgroup LLVMCCoreModuleProvider Module Providers
3124 *
3125 * @{
3126 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003127
Gregory Szorc34c863a2012-03-21 03:54:29 +00003128/**
3129 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003130 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003131 */
3132LLVMModuleProviderRef
3133LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
3134
Gregory Szorc34c863a2012-03-21 03:54:29 +00003135/**
3136 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003137 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003138void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003139
Gregory Szorc34c863a2012-03-21 03:54:29 +00003140/**
3141 * @}
3142 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003143
Gregory Szorc34c863a2012-03-21 03:54:29 +00003144/**
3145 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
3146 *
3147 * @{
3148 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003149
Chris Lattner25963c62010-01-09 22:27:07 +00003150LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
3151 LLVMMemoryBufferRef *OutMemBuf,
3152 char **OutMessage);
3153LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
3154 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00003155LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
3156 size_t InputDataLength,
3157 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00003158 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00003159LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
3160 size_t InputDataLength,
3161 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00003162const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00003163size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003164void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
3165
Gregory Szorc34c863a2012-03-21 03:54:29 +00003166/**
3167 * @}
3168 */
3169
3170/**
3171 * @defgroup LLVMCCorePassRegistry Pass Registry
3172 *
3173 * @{
3174 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003175
3176/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003177 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003178LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003179
Gregory Szorc34c863a2012-03-21 03:54:29 +00003180/**
3181 * @}
3182 */
3183
3184/**
3185 * @defgroup LLVMCCorePassManagers Pass Managers
3186 *
3187 * @{
3188 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003189
3190/** Constructs a new whole-module pass pipeline. This type of pipeline is
3191 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003192 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003193LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003194
3195/** Constructs a new function-by-function pass pipeline over the module
3196 provider. It does not take ownership of the module provider. This type of
3197 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003198 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00003199LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
3200
3201/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003202LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
3203
3204/** Initializes, executes on the provided module, and finalizes all of the
3205 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00003206 modified the module, 0 otherwise.
3207 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003208LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003209
3210/** Initializes all of the function passes scheduled in the function pass
3211 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003212 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00003213LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003214
3215/** Executes all of the function passes scheduled in the function pass manager
3216 on the provided function. Returns 1 if any of the passes modified the
3217 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003218 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003219LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003220
Hiroshi Inoue0909ca12018-01-26 08:15:29 +00003221/** Finalizes all of the function passes scheduled in the function pass
Gordon Henriksen878114b2008-03-16 04:20:44 +00003222 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003223 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00003224LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003225
3226/** Frees the memory of a pass pipeline. For function pipelines, does not free
3227 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003228 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003229void LLVMDisposePassManager(LLVMPassManagerRef PM);
3230
Gregory Szorc34c863a2012-03-21 03:54:29 +00003231/**
3232 * @}
3233 */
3234
3235/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00003236 * @defgroup LLVMCCoreThreading Threading
3237 *
3238 * Handle the structures needed to make LLVM safe for multithreading.
3239 *
3240 * @{
3241 */
3242
Chandler Carruth39cd2162014-06-27 15:13:01 +00003243/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3244 time define LLVM_ENABLE_THREADS. This function always returns
3245 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003246LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003247
Chandler Carruth39cd2162014-06-27 15:13:01 +00003248/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3249 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003250void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003251
3252/** Check whether LLVM is executing in thread-safe mode or not.
3253 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003254LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003255
3256/**
3257 * @}
3258 */
3259
3260/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003261 * @}
3262 */
3263
3264/**
3265 * @}
3266 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003267
Gordon Henriksen76a03742007-09-18 03:18:57 +00003268#ifdef __cplusplus
3269}
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003270#endif
Gordon Henriksen7330acd2007-10-05 23:59:36 +00003271
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003272#endif /* LLVM_C_CORE_H */