blob: 8238c09f9dd0b0c02a52359a1996f9b16e8e2b15 [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 {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000190 LLVMDefaultStorageClass = 0,
191 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
192 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
193} LLVMDLLStorageClass;
194
195typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000196 LLVMCCallConv = 0,
197 LLVMFastCallConv = 8,
198 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000199 LLVMWebKitJSCallConv = 12,
200 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000201 LLVMX86StdcallCallConv = 64,
202 LLVMX86FastcallCallConv = 65
203} LLVMCallConv;
204
205typedef enum {
Peter Zotov3e4561c2016-04-06 22:21:29 +0000206 LLVMArgumentValueKind,
207 LLVMBasicBlockValueKind,
208 LLVMMemoryUseValueKind,
209 LLVMMemoryDefValueKind,
210 LLVMMemoryPhiValueKind,
211
212 LLVMFunctionValueKind,
213 LLVMGlobalAliasValueKind,
Dmitry Polukhina1feff72016-04-07 12:32:19 +0000214 LLVMGlobalIFuncValueKind,
Peter Zotov3e4561c2016-04-06 22:21:29 +0000215 LLVMGlobalVariableValueKind,
216 LLVMBlockAddressValueKind,
217 LLVMConstantExprValueKind,
218 LLVMConstantArrayValueKind,
219 LLVMConstantStructValueKind,
220 LLVMConstantVectorValueKind,
221
222 LLVMUndefValueValueKind,
223 LLVMConstantAggregateZeroValueKind,
224 LLVMConstantDataArrayValueKind,
225 LLVMConstantDataVectorValueKind,
226 LLVMConstantIntValueKind,
227 LLVMConstantFPValueKind,
228 LLVMConstantPointerNullValueKind,
229 LLVMConstantTokenNoneValueKind,
230
231 LLVMMetadataAsValueValueKind,
232 LLVMInlineAsmValueKind,
233
234 LLVMInstructionValueKind,
235} LLVMValueKind;
236
237typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000238 LLVMIntEQ = 32, /**< equal */
239 LLVMIntNE, /**< not equal */
240 LLVMIntUGT, /**< unsigned greater than */
241 LLVMIntUGE, /**< unsigned greater or equal */
242 LLVMIntULT, /**< unsigned less than */
243 LLVMIntULE, /**< unsigned less or equal */
244 LLVMIntSGT, /**< signed greater than */
245 LLVMIntSGE, /**< signed greater or equal */
246 LLVMIntSLT, /**< signed less than */
247 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000248} LLVMIntPredicate;
249
250typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000251 LLVMRealPredicateFalse, /**< Always false (always folded) */
252 LLVMRealOEQ, /**< True if ordered and equal */
253 LLVMRealOGT, /**< True if ordered and greater than */
254 LLVMRealOGE, /**< True if ordered and greater than or equal */
255 LLVMRealOLT, /**< True if ordered and less than */
256 LLVMRealOLE, /**< True if ordered and less than or equal */
257 LLVMRealONE, /**< True if ordered and operands are unequal */
258 LLVMRealORD, /**< True if ordered (no nans) */
259 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
260 LLVMRealUEQ, /**< True if unordered or equal */
261 LLVMRealUGT, /**< True if unordered or greater than */
262 LLVMRealUGE, /**< True if unordered, greater than, or equal */
263 LLVMRealULT, /**< True if unordered or less than */
264 LLVMRealULE, /**< True if unordered, less than, or equal */
265 LLVMRealUNE, /**< True if unordered or not equal */
266 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000267} LLVMRealPredicate;
268
Bill Wendlingfae14752011-08-12 20:24:12 +0000269typedef enum {
270 LLVMLandingPadCatch, /**< A catch clause */
271 LLVMLandingPadFilter /**< A filter clause */
272} LLVMLandingPadClauseTy;
273
Hans Wennborg5ff71202013-04-16 08:58:59 +0000274typedef enum {
275 LLVMNotThreadLocal = 0,
276 LLVMGeneralDynamicTLSModel,
277 LLVMLocalDynamicTLSModel,
278 LLVMInitialExecTLSModel,
279 LLVMLocalExecTLSModel
280} LLVMThreadLocalMode;
281
Carlo Kokda0ac722013-04-23 13:45:37 +0000282typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000283 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
284 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
285 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000286 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
287 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000288 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000289 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
290 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000291 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000292 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
293 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000294 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000295 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
296 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000297 operations which both read and write
298 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000299 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
300 for loads and Release
301 semantics for stores.
302 Additionally, it guarantees
303 that a total ordering exists
304 between all
305 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000306 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000307} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000308
Carlo Kokda0ac722013-04-23 13:45:37 +0000309typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000310 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
311 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
312 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
313 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
314 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
315 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
316 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
317 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000318 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000319 the old one */
320 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000321 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000322 the old one */
323 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000324 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000325 the old one */
326 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000327 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000328 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000329} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000330
Tom Stellard1580dc72014-04-16 17:45:04 +0000331typedef enum {
332 LLVMDSError,
333 LLVMDSWarning,
334 LLVMDSRemark,
335 LLVMDSNote
336} LLVMDiagnosticSeverity;
337
Gregory Szorc34c863a2012-03-21 03:54:29 +0000338/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000339 * Attribute index are either LLVMAttributeReturnIndex,
340 * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
341 */
342enum {
343 LLVMAttributeReturnIndex = 0U,
344 // ISO C restricts enumerator values to range of 'int'
345 // (4294967295 is too large)
346 // LLVMAttributeFunctionIndex = ~0U,
347 LLVMAttributeFunctionIndex = -1,
348};
349
350typedef unsigned LLVMAttributeIndex;
351
352/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000353 * @}
354 */
355
Nick Lewycky0db26542011-05-15 07:20:34 +0000356void LLVMInitializeCore(LLVMPassRegistryRef R);
357
Duncan Sands1cba0a82013-02-17 16:35:51 +0000358/** Deallocate and destroy all ManagedStatic variables.
359 @see llvm::llvm_shutdown
360 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000361void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000362
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000363/*===-- Error handling ----------------------------------------------------===*/
364
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000365char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000366void LLVMDisposeMessage(char *Message);
367
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000368/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000369 * @defgroup LLVMCCoreContext Contexts
370 *
371 * Contexts are execution states for the core LLVM IR system.
372 *
373 * Most types are tied to a context instance. Multiple contexts can
374 * exist simultaneously. A single context is not thread safe. However,
375 * different contexts can execute on different threads simultaneously.
376 *
377 * @{
378 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000379
Tom Stellard1580dc72014-04-16 17:45:04 +0000380typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000381typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000382
Gregory Szorc34c863a2012-03-21 03:54:29 +0000383/**
384 * Create a new context.
385 *
386 * Every call to this function should be paired with a call to
387 * LLVMContextDispose() or the context will leak memory.
388 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000389LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000390
391/**
392 * Obtain the global context instance.
393 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000394LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000395
396/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000397 * Set the diagnostic handler for this context.
398 */
399void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
400 LLVMDiagnosticHandler Handler,
401 void *DiagnosticContext);
402
403/**
Jeroen Ketemaad659c32016-04-08 09:19:02 +0000404 * Get the diagnostic handler of this context.
405 */
406LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C);
407
408/**
409 * Get the diagnostic context of this context.
410 */
411void *LLVMContextGetDiagnosticContext(LLVMContextRef C);
412
413/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000414 * Set the yield callback function for this context.
415 *
416 * @see LLVMContext::setYieldCallback()
417 */
418void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
419 void *OpaqueHandle);
420
421/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000422 * Destroy a context instance.
423 *
424 * This should be called for every call to LLVMContextCreate() or memory
425 * will be leaked.
426 */
Owen Anderson6773d382009-07-01 16:58:40 +0000427void LLVMContextDispose(LLVMContextRef C);
428
Tom Stellard1580dc72014-04-16 17:45:04 +0000429/**
430 * Return a string representation of the DiagnosticInfo. Use
431 * LLVMDisposeMessage to free the string.
432 *
433 * @see DiagnosticInfo::print()
434 */
435char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
436
437/**
438 * Return an enum LLVMDiagnosticSeverity.
439 *
440 * @see DiagnosticInfo::getSeverity()
441 */
442LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
443
Amaury Sechet56f056c2016-04-04 22:00:25 +0000444unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name,
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000445 unsigned SLen);
Amaury Sechet56f056c2016-04-04 22:00:25 +0000446unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000447
Gregory Szorc34c863a2012-03-21 03:54:29 +0000448/**
Amaury Sechet5db224e2016-06-12 06:17:24 +0000449 * Return an unique id given the name of a enum attribute,
Amaury Sechet60b31452016-04-20 01:02:12 +0000450 * or 0 if no attribute by that name exists.
451 *
452 * See http://llvm.org/docs/LangRef.html#parameter-attributes
453 * and http://llvm.org/docs/LangRef.html#function-attributes
454 * for the list of available attributes.
455 *
456 * NB: Attribute names and/or id are subject to change without
457 * going through the C API deprecation cycle.
458 */
Amaury Sechet5db224e2016-06-12 06:17:24 +0000459unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
Amaury Sechet48b06652016-06-12 07:56:21 +0000460unsigned LLVMGetLastEnumAttributeKind(void);
Amaury Sechet5db224e2016-06-12 06:17:24 +0000461
462/**
463 * Create an enum attribute.
464 */
465LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
466 uint64_t Val);
467
468/**
469 * Get the unique id corresponding to the enum attribute
470 * passed as argument.
471 */
472unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
473
474/**
475 * Get the enum attribute's value. 0 is returned if none exists.
476 */
477uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
478
479/**
480 * Create a string attribute.
481 */
482LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
483 const char *K, unsigned KLength,
484 const char *V, unsigned VLength);
485
486/**
487 * Get the string attribute's kind.
488 */
489const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
490
491/**
492 * Get the string attribute's value.
493 */
494const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
495
496/**
497 * Check for the different types of attributes.
498 */
499LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
500LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
Amaury Sechet60b31452016-04-20 01:02:12 +0000501
502/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000503 * @}
504 */
505
Gregory Szorc52d26602012-03-21 07:28:27 +0000506/**
507 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000508 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000509 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000510 * module is effectively a translation unit or a collection of
511 * translation units merged together.
512 *
513 * @{
514 */
515
Gregory Szorc34c863a2012-03-21 03:54:29 +0000516/**
517 * Create a new, empty module in the global context.
518 *
519 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
520 * LLVMGetGlobalContext() as the context parameter.
521 *
522 * Every invocation should be paired with LLVMDisposeModule() or memory
523 * will be leaked.
524 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000525LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000526
527/**
528 * Create a new, empty module in a specific context.
529 *
530 * Every invocation should be paired with LLVMDisposeModule() or memory
531 * will be leaked.
532 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000533LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
534 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000535/**
536 * Return an exact copy of the specified module.
537 */
538LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000539
Gregory Szorc34c863a2012-03-21 03:54:29 +0000540/**
541 * Destroy a module instance.
542 *
543 * This must be called for every created module or memory will be
544 * leaked.
545 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000546void LLVMDisposeModule(LLVMModuleRef M);
547
Gregory Szorc34c863a2012-03-21 03:54:29 +0000548/**
Peter Zotov0a2fa0a2016-04-05 13:56:59 +0000549 * Obtain the identifier of a module.
550 *
551 * @param M Module to obtain identifier of
552 * @param Len Out parameter which holds the length of the returned string.
553 * @return The identifier of M.
554 * @see Module::getModuleIdentifier()
555 */
556const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len);
557
558/**
559 * Set the identifier of a module to a string Ident with length Len.
560 *
561 * @param M The module to set identifier
562 * @param Ident The string to set M's identifier to
563 * @param Len Length of Ident
564 * @see Module::setModuleIdentifier()
565 */
566void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len);
567
568/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000569 * Obtain the data layout for a module.
570 *
Amaury Sechetf3549c42016-02-16 00:23:52 +0000571 * @see Module::getDataLayoutStr()
572 *
573 * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
574 * but match the name of another method on the module. Prefer the use
575 * of LLVMGetDataLayoutStr, which is not ambiguous.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000576 */
Amaury Sechetf3549c42016-02-16 00:23:52 +0000577const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000578const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000579
580/**
581 * Set the data layout for a module.
582 *
583 * @see Module::setDataLayout()
584 */
Amaury Sechet6ada31c2016-02-15 23:40:06 +0000585void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000586
Gregory Szorc34c863a2012-03-21 03:54:29 +0000587/**
588 * Obtain the target triple for a module.
589 *
590 * @see Module::getTargetTriple()
591 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000592const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000593
594/**
595 * Set the target triple for a module.
596 *
597 * @see Module::setTargetTriple()
598 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000599void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
600
Gregory Szorc34c863a2012-03-21 03:54:29 +0000601/**
602 * Dump a representation of a module to stderr.
603 *
604 * @see Module::dump()
605 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000606void LLVMDumpModule(LLVMModuleRef M);
607
Gregory Szorc34c863a2012-03-21 03:54:29 +0000608/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000609 * Print a representation of a module to a file. The ErrorMessage needs to be
610 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
611 *
612 * @see Module::print()
613 */
614LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
615 char **ErrorMessage);
616
617/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000618 * Return a string representation of the module. Use
619 * LLVMDisposeMessage to free the string.
620 *
621 * @see Module::print()
622 */
623char *LLVMPrintModuleToString(LLVMModuleRef M);
624
625/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000626 * Set inline assembly for a module.
627 *
628 * @see Module::setModuleInlineAsm()
629 */
Chris Lattner26941452010-04-10 17:52:58 +0000630void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000631
Gregory Szorc34c863a2012-03-21 03:54:29 +0000632/**
633 * Obtain the context to which this module is associated.
634 *
635 * @see Module::getContext()
636 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000637LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
638
Gregory Szorc34c863a2012-03-21 03:54:29 +0000639/**
640 * Obtain a Type from a module by its registered name.
641 */
642LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000643
Gregory Szorc34c863a2012-03-21 03:54:29 +0000644/**
645 * Obtain the number of operands for named metadata in a module.
646 *
647 * @see llvm::Module::getNamedMetadata()
648 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000649unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000650
651/**
652 * Obtain the named metadata operands for a module.
653 *
654 * The passed LLVMValueRef pointer should refer to an array of
655 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
656 * array will be populated with the LLVMValueRef instances. Each
657 * instance corresponds to a llvm::MDNode.
658 *
659 * @see llvm::Module::getNamedMetadata()
660 * @see llvm::MDNode::getOperand()
661 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000662void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name,
663 LLVMValueRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000664
665/**
666 * Add an operand to named metadata.
667 *
668 * @see llvm::Module::getNamedMetadata()
669 * @see llvm::MDNode::addOperand()
670 */
Amaury Sechetb130f432016-04-23 00:12:45 +0000671void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,
Gregory Szorc34c863a2012-03-21 03:54:29 +0000672 LLVMValueRef Val);
673
Gregory Szorc52d26602012-03-21 07:28:27 +0000674/**
675 * Add a function to a module under a specified name.
676 *
677 * @see llvm::Function::Create()
678 */
679LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
680 LLVMTypeRef FunctionTy);
681
682/**
683 * Obtain a Function value from a Module by its name.
684 *
685 * The returned value corresponds to a llvm::Function value.
686 *
687 * @see llvm::Module::getFunction()
688 */
689LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
690
691/**
692 * Obtain an iterator to the first Function in a Module.
693 *
694 * @see llvm::Module::begin()
695 */
696LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
697
698/**
699 * Obtain an iterator to the last Function in a Module.
700 *
701 * @see llvm::Module::end()
702 */
703LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
704
705/**
706 * Advance a Function iterator to the next Function.
707 *
708 * Returns NULL if the iterator was already at the end and there are no more
709 * functions.
710 */
711LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
712
713/**
714 * Decrement a Function iterator to the previous Function.
715 *
716 * Returns NULL if the iterator was already at the beginning and there are
717 * no previous functions.
718 */
719LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000720
721/**
722 * @}
723 */
724
725/**
726 * @defgroup LLVMCCoreType Types
727 *
728 * Types represent the type of a value.
729 *
730 * Types are associated with a context instance. The context internally
731 * deduplicates types so there is only 1 instance of a specific type
732 * alive at a time. In other words, a unique type is shared among all
733 * consumers within a context.
734 *
735 * A Type in the C API corresponds to llvm::Type.
736 *
737 * Types have the following hierarchy:
738 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000739 * types:
740 * integer type
741 * real type
742 * function type
743 * sequence types:
744 * array type
745 * pointer type
746 * vector type
747 * void type
748 * label type
749 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000750 *
751 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000752 */
753
Gregory Szorc34c863a2012-03-21 03:54:29 +0000754/**
755 * Obtain the enumerated type of a Type instance.
756 *
757 * @see llvm::Type:getTypeID()
758 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000759LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000760
761/**
762 * Whether the type has a known size.
763 *
764 * Things that don't have a size are abstract types, labels, and void.a
765 *
766 * @see llvm::Type::isSized()
767 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000768LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000769
Gregory Szorc34c863a2012-03-21 03:54:29 +0000770/**
771 * Obtain the context to which this type instance is associated.
772 *
773 * @see llvm::Type::getContext()
774 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000775LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
776
Gregory Szorc34c863a2012-03-21 03:54:29 +0000777/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000778 * Dump a representation of a type to stderr.
779 *
780 * @see llvm::Type::dump()
781 */
782void LLVMDumpType(LLVMTypeRef Val);
783
784/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000785 * Return a string representation of the type. Use
786 * LLVMDisposeMessage to free the string.
787 *
788 * @see llvm::Type::print()
789 */
790char *LLVMPrintTypeToString(LLVMTypeRef Val);
791
792/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000793 * @defgroup LLVMCCoreTypeInt Integer Types
794 *
795 * Functions in this section operate on integer types.
796 *
797 * @{
798 */
799
800/**
801 * Obtain an integer type from a context with specified bit width.
802 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000803LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
804LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
805LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
806LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
807LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000808LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000809LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
810
Gregory Szorc34c863a2012-03-21 03:54:29 +0000811/**
812 * Obtain an integer type from the global context with a specified bit
813 * width.
814 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000815LLVMTypeRef LLVMInt1Type(void);
816LLVMTypeRef LLVMInt8Type(void);
817LLVMTypeRef LLVMInt16Type(void);
818LLVMTypeRef LLVMInt32Type(void);
819LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000820LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000821LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000822unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000823
Gregory Szorc34c863a2012-03-21 03:54:29 +0000824/**
825 * @}
826 */
827
828/**
829 * @defgroup LLVMCCoreTypeFloat Floating Point Types
830 *
831 * @{
832 */
833
834/**
835 * Obtain a 16-bit floating point type from a context.
836 */
Dan Gohman518cda42011-12-17 00:04:22 +0000837LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000838
839/**
840 * Obtain a 32-bit floating point type from a context.
841 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000842LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000843
844/**
845 * Obtain a 64-bit floating point type from a context.
846 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000847LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000848
849/**
850 * Obtain a 80-bit floating point type (X87) from a context.
851 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000852LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000853
854/**
855 * Obtain a 128-bit floating point type (112-bit mantissa) from a
856 * context.
857 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000858LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000859
860/**
861 * Obtain a 128-bit floating point type (two 64-bits) from a context.
862 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000863LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
864
Gregory Szorc34c863a2012-03-21 03:54:29 +0000865/**
866 * Obtain a floating point type from the global context.
867 *
868 * These map to the functions in this group of the same name.
869 */
Dan Gohman518cda42011-12-17 00:04:22 +0000870LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000871LLVMTypeRef LLVMFloatType(void);
872LLVMTypeRef LLVMDoubleType(void);
873LLVMTypeRef LLVMX86FP80Type(void);
874LLVMTypeRef LLVMFP128Type(void);
875LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000876
Gregory Szorc34c863a2012-03-21 03:54:29 +0000877/**
878 * @}
879 */
880
881/**
882 * @defgroup LLVMCCoreTypeFunction Function Types
883 *
884 * @{
885 */
886
887/**
888 * Obtain a function type consisting of a specified signature.
889 *
890 * The function is defined as a tuple of a return Type, a list of
891 * parameter types, and whether the function is variadic.
892 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000893LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
894 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000895 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000896
897/**
898 * Returns whether a function type is variadic.
899 */
Chris Lattner25963c62010-01-09 22:27:07 +0000900LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000901
902/**
903 * Obtain the Type this function Type returns.
904 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000905LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000906
907/**
908 * Obtain the number of parameters this function accepts.
909 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000910unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000911
912/**
913 * Obtain the types of a function's parameters.
914 *
915 * The Dest parameter should point to a pre-allocated array of
916 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
917 * first LLVMCountParamTypes() entries in the array will be populated
918 * with LLVMTypeRef instances.
919 *
920 * @param FunctionTy The function type to operate on.
921 * @param Dest Memory address of an array to be filled with result.
922 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000923void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000924
Gregory Szorc34c863a2012-03-21 03:54:29 +0000925/**
926 * @}
927 */
928
929/**
930 * @defgroup LLVMCCoreTypeStruct Structure Types
931 *
932 * These functions relate to LLVMTypeRef instances.
933 *
934 * @see llvm::StructType
935 *
936 * @{
937 */
938
939/**
940 * Create a new structure type in a context.
941 *
942 * A structure is specified by a list of inner elements/types and
943 * whether these can be packed together.
944 *
945 * @see llvm::StructType::create()
946 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000947LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000948 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000949
950/**
951 * Create a new structure type in the global context.
952 *
953 * @see llvm::StructType::create()
954 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000955LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000956 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000957
958/**
959 * Create an empty structure in a context having a specified name.
960 *
961 * @see llvm::StructType::create()
962 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000963LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000964
965/**
966 * Obtain the name of a structure.
967 *
968 * @see llvm::StructType::getName()
969 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000970const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000971
972/**
973 * Set the contents of a structure type.
974 *
975 * @see llvm::StructType::setBody()
976 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000977void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
978 unsigned ElementCount, LLVMBool Packed);
979
Gregory Szorc34c863a2012-03-21 03:54:29 +0000980/**
981 * Get the number of elements defined inside the structure.
982 *
983 * @see llvm::StructType::getNumElements()
984 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000985unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000986
987/**
988 * Get the elements within a structure.
989 *
990 * The function is passed the address of a pre-allocated array of
991 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
992 * invocation, this array will be populated with the structure's
993 * elements. The objects in the destination array will have a lifetime
994 * of the structure type itself, which is the lifetime of the context it
995 * is contained in.
996 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000997void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000998
999/**
Peter Zotovc164a3f2015-06-04 09:09:53 +00001000 * Get the type of the element at a given index in the structure.
1001 *
1002 * @see llvm::StructType::getTypeAtIndex()
1003 */
1004LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
1005
1006/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001007 * Determine whether a structure is packed.
1008 *
1009 * @see llvm::StructType::isPacked()
1010 */
Chris Lattner25963c62010-01-09 22:27:07 +00001011LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001012
1013/**
1014 * Determine whether a structure is opaque.
1015 *
1016 * @see llvm::StructType::isOpaque()
1017 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001018LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1019
Gregory Szorc34c863a2012-03-21 03:54:29 +00001020/**
1021 * @}
1022 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001023
Gregory Szorc34c863a2012-03-21 03:54:29 +00001024/**
1025 * @defgroup LLVMCCoreTypeSequential Sequential Types
1026 *
1027 * Sequential types represents "arrays" of types. This is a super class
1028 * for array, vector, and pointer types.
1029 *
1030 * @{
1031 */
1032
1033/**
1034 * Obtain the type of elements within a sequential type.
1035 *
1036 * This works on array, vector, and pointer types.
1037 *
1038 * @see llvm::SequentialType::getElementType()
1039 */
1040LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1041
1042/**
whitequarkf6059fd2017-06-05 11:49:52 +00001043 * Returns type's subtypes
1044 *
1045 * @see llvm::Type::subtypes()
1046 */
1047void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr);
1048
1049/**
1050 * Return the number of types in the derived type.
1051 *
1052 * @see llvm::Type::getNumContainedTypes()
1053 */
1054unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp);
1055
1056/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001057 * Create a fixed size array type that refers to a specific type.
1058 *
1059 * The created type will exist in the context that its element type
1060 * exists in.
1061 *
1062 * @see llvm::ArrayType::get()
1063 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001064LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001065
1066/**
1067 * Obtain the length of an array type.
1068 *
1069 * This only works on types that represent arrays.
1070 *
1071 * @see llvm::ArrayType::getNumElements()
1072 */
1073unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1074
1075/**
1076 * Create a pointer type that points to a defined type.
1077 *
1078 * The created type will exist in the context that its pointee type
1079 * exists in.
1080 *
1081 * @see llvm::PointerType::get()
1082 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001083LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001084
1085/**
1086 * Obtain the address space of a pointer type.
1087 *
1088 * This only works on types that represent pointers.
1089 *
1090 * @see llvm::PointerType::getAddressSpace()
1091 */
1092unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1093
1094/**
1095 * Create a vector type that contains a defined type and has a specific
1096 * number of elements.
1097 *
1098 * The created type will exist in the context thats its element type
1099 * exists in.
1100 *
1101 * @see llvm::VectorType::get()
1102 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001103LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001104
Gregory Szorc34c863a2012-03-21 03:54:29 +00001105/**
1106 * Obtain the number of elements in a vector type.
1107 *
1108 * This only works on types that represent vectors.
1109 *
1110 * @see llvm::VectorType::getNumElements()
1111 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001112unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1113
Gregory Szorc34c863a2012-03-21 03:54:29 +00001114/**
1115 * @}
1116 */
1117
1118/**
1119 * @defgroup LLVMCCoreTypeOther Other Types
1120 *
1121 * @{
1122 */
1123
1124/**
1125 * Create a void type in a context.
1126 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001127LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001128
1129/**
1130 * Create a label type in a context.
1131 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001132LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001133
1134/**
1135 * Create a X86 MMX type in a context.
1136 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001137LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001138
Gregory Szorc34c863a2012-03-21 03:54:29 +00001139/**
whitequark131f98f2017-10-27 11:51:40 +00001140 * Create a token type in a context.
1141 */
1142LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C);
1143
1144/**
1145 * Create a metadata type in a context.
1146 */
1147LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C);
1148
1149/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001150 * These are similar to the above functions except they operate on the
1151 * global context.
1152 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001153LLVMTypeRef LLVMVoidType(void);
1154LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001155LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001156
Gregory Szorc34c863a2012-03-21 03:54:29 +00001157/**
1158 * @}
1159 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001160
Gregory Szorc34c863a2012-03-21 03:54:29 +00001161/**
1162 * @}
1163 */
1164
1165/**
1166 * @defgroup LLVMCCoreValues Values
1167 *
1168 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001169 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001170 *
1171 * LLVMValueRef essentially represents llvm::Value. There is a rich
1172 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001173 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001174 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001175 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001176 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1177 * functions are defined by a macro, so it isn't obvious which are
1178 * available by looking at the Doxygen source code. Instead, look at the
1179 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1180 * of value names given. These value names also correspond to classes in
1181 * the llvm::Value hierarchy.
1182 *
1183 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001184 */
1185
Gordon Henriksen29e38942008-12-19 18:39:45 +00001186#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1187 macro(Argument) \
1188 macro(BasicBlock) \
1189 macro(InlineAsm) \
1190 macro(User) \
1191 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001192 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001193 macro(ConstantAggregateZero) \
1194 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001195 macro(ConstantDataSequential) \
1196 macro(ConstantDataArray) \
1197 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001198 macro(ConstantExpr) \
1199 macro(ConstantFP) \
1200 macro(ConstantInt) \
1201 macro(ConstantPointerNull) \
1202 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001203 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001204 macro(ConstantVector) \
1205 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001206 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001207 macro(GlobalObject) \
1208 macro(Function) \
1209 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001210 macro(UndefValue) \
1211 macro(Instruction) \
1212 macro(BinaryOperator) \
1213 macro(CallInst) \
1214 macro(IntrinsicInst) \
1215 macro(DbgInfoIntrinsic) \
1216 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001217 macro(MemIntrinsic) \
1218 macro(MemCpyInst) \
1219 macro(MemMoveInst) \
1220 macro(MemSetInst) \
1221 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001222 macro(FCmpInst) \
1223 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001224 macro(ExtractElementInst) \
1225 macro(GetElementPtrInst) \
1226 macro(InsertElementInst) \
1227 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001228 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001229 macro(PHINode) \
1230 macro(SelectInst) \
1231 macro(ShuffleVectorInst) \
1232 macro(StoreInst) \
1233 macro(TerminatorInst) \
1234 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001235 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001236 macro(InvokeInst) \
1237 macro(ReturnInst) \
1238 macro(SwitchInst) \
1239 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001240 macro(ResumeInst) \
David Majnemer654e1302015-07-31 17:58:14 +00001241 macro(CleanupReturnInst) \
1242 macro(CatchReturnInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001243 macro(FuncletPadInst) \
1244 macro(CatchPadInst) \
1245 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001246 macro(UnaryInstruction) \
1247 macro(AllocaInst) \
1248 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001249 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001250 macro(BitCastInst) \
1251 macro(FPExtInst) \
1252 macro(FPToSIInst) \
1253 macro(FPToUIInst) \
1254 macro(FPTruncInst) \
1255 macro(IntToPtrInst) \
1256 macro(PtrToIntInst) \
1257 macro(SExtInst) \
1258 macro(SIToFPInst) \
1259 macro(TruncInst) \
1260 macro(UIToFPInst) \
1261 macro(ZExtInst) \
1262 macro(ExtractValueInst) \
1263 macro(LoadInst) \
1264 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001265
Gregory Szorc34c863a2012-03-21 03:54:29 +00001266/**
1267 * @defgroup LLVMCCoreValueGeneral General APIs
1268 *
1269 * Functions in this section work on all LLVMValueRef instances,
1270 * regardless of their sub-type. They correspond to functions available
1271 * on llvm::Value.
1272 *
1273 * @{
1274 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001275
Gregory Szorc34c863a2012-03-21 03:54:29 +00001276/**
1277 * Obtain the type of a value.
1278 *
1279 * @see llvm::Value::getType()
1280 */
1281LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1282
1283/**
Peter Zotov3e4561c2016-04-06 22:21:29 +00001284 * Obtain the enumerated type of a Value instance.
1285 *
1286 * @see llvm::Value::getValueID()
1287 */
1288LLVMValueKind LLVMGetValueKind(LLVMValueRef Val);
1289
1290/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001291 * Obtain the string name of a value.
1292 *
1293 * @see llvm::Value::getName()
1294 */
1295const char *LLVMGetValueName(LLVMValueRef Val);
1296
1297/**
1298 * Set the string name of a value.
1299 *
1300 * @see llvm::Value::setName()
1301 */
1302void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1303
1304/**
1305 * Dump a representation of a value to stderr.
1306 *
1307 * @see llvm::Value::dump()
1308 */
1309void LLVMDumpValue(LLVMValueRef Val);
1310
1311/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001312 * Return a string representation of the value. Use
1313 * LLVMDisposeMessage to free the string.
1314 *
1315 * @see llvm::Value::print()
1316 */
1317char *LLVMPrintValueToString(LLVMValueRef Val);
1318
1319/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001320 * Replace all uses of a value with another one.
1321 *
1322 * @see llvm::Value::replaceAllUsesWith()
1323 */
1324void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1325
1326/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001327 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001328 */
1329LLVMBool LLVMIsConstant(LLVMValueRef Val);
1330
1331/**
1332 * Determine whether a value instance is undefined.
1333 */
1334LLVMBool LLVMIsUndef(LLVMValueRef Val);
1335
1336/**
1337 * Convert value instances between types.
1338 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001339 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001340 * series of functions allows you to cast an instance to a specific
1341 * type.
1342 *
1343 * If the cast is not valid for the specified type, NULL is returned.
1344 *
1345 * @see llvm::dyn_cast_or_null<>
1346 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001347#define LLVM_DECLARE_VALUE_CAST(name) \
1348 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1349LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1350
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001351LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1352LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1353
Gregory Szorc34c863a2012-03-21 03:54:29 +00001354/**
1355 * @}
1356 */
1357
1358/**
1359 * @defgroup LLVMCCoreValueUses Usage
1360 *
1361 * This module defines functions that allow you to inspect the uses of a
1362 * LLVMValueRef.
1363 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001364 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001365 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1366 * llvm::User and llvm::Value.
1367 *
1368 * @{
1369 */
1370
1371/**
1372 * Obtain the first use of a value.
1373 *
1374 * Uses are obtained in an iterator fashion. First, call this function
1375 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001376 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001377 * LLVMGetNextUse() returns NULL.
1378 *
1379 * @see llvm::Value::use_begin()
1380 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001381LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001382
1383/**
1384 * Obtain the next use of a value.
1385 *
1386 * This effectively advances the iterator. It returns NULL if you are on
1387 * the final use and no more are available.
1388 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001389LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001390
1391/**
1392 * Obtain the user value for a user.
1393 *
1394 * The returned value corresponds to a llvm::User type.
1395 *
1396 * @see llvm::Use::getUser()
1397 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001398LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001399
1400/**
1401 * Obtain the value this use corresponds to.
1402 *
1403 * @see llvm::Use::get().
1404 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001405LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001406
Gregory Szorc34c863a2012-03-21 03:54:29 +00001407/**
1408 * @}
1409 */
1410
1411/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001412 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001413 *
1414 * Function in this group pertain to LLVMValueRef instances that descent
1415 * from llvm::User. This includes constants, instructions, and
1416 * operators.
1417 *
1418 * @{
1419 */
1420
1421/**
1422 * Obtain an operand at a specific index in a llvm::User value.
1423 *
1424 * @see llvm::User::getOperand()
1425 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001426LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001427
1428/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001429 * Obtain the use of an operand at a specific index in a llvm::User value.
1430 *
1431 * @see llvm::User::getOperandUse()
1432 */
1433LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1434
1435/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001436 * Set an operand at a specific index in a llvm::User value.
1437 *
1438 * @see llvm::User::setOperand()
1439 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001440void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001441
1442/**
1443 * Obtain the number of operands in a llvm::User value.
1444 *
1445 * @see llvm::User::getNumOperands()
1446 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001447int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001448
Gregory Szorc34c863a2012-03-21 03:54:29 +00001449/**
1450 * @}
1451 */
1452
1453/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001454 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001455 *
1456 * This section contains APIs for interacting with LLVMValueRef that
1457 * correspond to llvm::Constant instances.
1458 *
1459 * These functions will work for any LLVMValueRef in the llvm::Constant
1460 * class hierarchy.
1461 *
1462 * @{
1463 */
1464
1465/**
1466 * Obtain a constant value referring to the null instance of a type.
1467 *
1468 * @see llvm::Constant::getNullValue()
1469 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001470LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001471
1472/**
1473 * Obtain a constant value referring to the instance of a type
1474 * consisting of all ones.
1475 *
1476 * This is only valid for integer types.
1477 *
1478 * @see llvm::Constant::getAllOnesValue()
1479 */
1480LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1481
1482/**
1483 * Obtain a constant value referring to an undefined value of a type.
1484 *
1485 * @see llvm::UndefValue::get()
1486 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001487LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001488
1489/**
1490 * Determine whether a value instance is null.
1491 *
1492 * @see llvm::Constant::isNullValue()
1493 */
Chris Lattner25963c62010-01-09 22:27:07 +00001494LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001495
1496/**
1497 * Obtain a constant that is a constant pointer pointing to NULL for a
1498 * specified type.
1499 */
Chris Lattner7f318242009-07-06 17:29:59 +00001500LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001501
Gregory Szorc34c863a2012-03-21 03:54:29 +00001502/**
1503 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1504 *
1505 * Functions in this group model LLVMValueRef instances that correspond
1506 * to constants referring to scalar types.
1507 *
1508 * For integer types, the LLVMTypeRef parameter should correspond to a
1509 * llvm::IntegerType instance and the returned LLVMValueRef will
1510 * correspond to a llvm::ConstantInt.
1511 *
1512 * For floating point types, the LLVMTypeRef returned corresponds to a
1513 * llvm::ConstantFP.
1514 *
1515 * @{
1516 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001517
Gregory Szorc34c863a2012-03-21 03:54:29 +00001518/**
1519 * Obtain a constant value for an integer type.
1520 *
1521 * The returned value corresponds to a llvm::ConstantInt.
1522 *
1523 * @see llvm::ConstantInt::get()
1524 *
1525 * @param IntTy Integer type to obtain value of.
1526 * @param N The value the returned instance should refer to.
1527 * @param SignExtend Whether to sign extend the produced value.
1528 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001529LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001530 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001531
1532/**
1533 * Obtain a constant value for an integer of arbitrary precision.
1534 *
1535 * @see llvm::ConstantInt::get()
1536 */
Chris Lattner4329e072010-11-23 02:47:22 +00001537LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1538 unsigned NumWords,
1539 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001540
1541/**
1542 * Obtain a constant value for an integer parsed from a string.
1543 *
1544 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1545 * string's length is available, it is preferred to call that function
1546 * instead.
1547 *
1548 * @see llvm::ConstantInt::get()
1549 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001550LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1551 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001552
1553/**
1554 * Obtain a constant value for an integer parsed from a string with
1555 * specified length.
1556 *
1557 * @see llvm::ConstantInt::get()
1558 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001559LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1560 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001561
1562/**
1563 * Obtain a constant value referring to a double floating point value.
1564 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001565LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001566
1567/**
1568 * Obtain a constant for a floating point value parsed from a string.
1569 *
1570 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1571 * should be used if the input string's length is known.
1572 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001573LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001574
1575/**
1576 * Obtain a constant for a floating point value parsed from a string.
1577 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001578LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1579 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001580
1581/**
1582 * Obtain the zero extended value for an integer constant value.
1583 *
1584 * @see llvm::ConstantInt::getZExtValue()
1585 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001586unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001587
1588/**
1589 * Obtain the sign extended value for an integer constant value.
1590 *
1591 * @see llvm::ConstantInt::getSExtValue()
1592 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001593long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001594
Gregory Szorc34c863a2012-03-21 03:54:29 +00001595/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001596 * Obtain the double value for an floating point constant value.
1597 * losesInfo indicates if some precision was lost in the conversion.
1598 *
1599 * @see llvm::ConstantFP::getDoubleValue
1600 */
1601double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1602
1603/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001604 * @}
1605 */
1606
1607/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001608 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1609 *
1610 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001611 *
1612 * @{
1613 */
1614
1615/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001616 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001617 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001618 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001619 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001620LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001621 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001622
1623/**
1624 * Create a ConstantDataSequential with string content in the global context.
1625 *
1626 * This is the same as LLVMConstStringInContext except it operates on the
1627 * global context.
1628 *
1629 * @see LLVMConstStringInContext()
1630 * @see llvm::ConstantDataArray::getString()
1631 */
1632LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1633 LLVMBool DontNullTerminate);
1634
1635/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001636 * Returns true if the specified constant is an array of i8.
1637 *
1638 * @see ConstantDataSequential::getAsString()
1639 */
1640LLVMBool LLVMIsConstantString(LLVMValueRef c);
1641
1642/**
1643 * Get the given constant data sequential as a string.
1644 *
1645 * @see ConstantDataSequential::getAsString()
1646 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00001647const char *LLVMGetAsString(LLVMValueRef c, size_t *Length);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001648
1649/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001650 * Create an anonymous ConstantStruct with the specified values.
1651 *
1652 * @see llvm::ConstantStruct::getAnon()
1653 */
1654LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001655 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001656 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001657
Gregory Szorc52d26602012-03-21 07:28:27 +00001658/**
1659 * Create a ConstantStruct in the global Context.
1660 *
1661 * This is the same as LLVMConstStructInContext except it operates on the
1662 * global Context.
1663 *
1664 * @see LLVMConstStructInContext()
1665 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001666LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001667 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001668
1669/**
1670 * Create a ConstantArray from values.
1671 *
1672 * @see llvm::ConstantArray::get()
1673 */
1674LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1675 LLVMValueRef *ConstantVals, unsigned Length);
1676
1677/**
1678 * Create a non-anonymous ConstantStruct from values.
1679 *
1680 * @see llvm::ConstantStruct::get()
1681 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001682LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1683 LLVMValueRef *ConstantVals,
1684 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001685
1686/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001687 * Get an element at specified index as a constant.
1688 *
1689 * @see ConstantDataSequential::getElementAsConstant()
1690 */
Amaury Sechet006ce632016-03-13 00:54:40 +00001691LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
Peter Zotovf9aa8822014-08-03 23:54:16 +00001692
1693/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001694 * Create a ConstantVector from values.
1695 *
1696 * @see llvm::ConstantVector::get()
1697 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001698LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001699
Gregory Szorc52d26602012-03-21 07:28:27 +00001700/**
1701 * @}
1702 */
1703
1704/**
1705 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1706 *
1707 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1708 *
1709 * @see llvm::ConstantExpr.
1710 *
1711 * @{
1712 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001713LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001714LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001715LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1716LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001717LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1718LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001719LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001720LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1721LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001722LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001723LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001724LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001725LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001726LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1727LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001728LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001729LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001730LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1731LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001732LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001733LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Manuel Jacob49fafb12016-10-04 23:32:42 +00001734LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001735LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001736LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001737LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1738LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1739LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1740LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1741LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1742LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1743LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1744LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1745 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1746LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1747 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1748LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1749LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1750LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1751LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1752 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001753LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1754 LLVMValueRef *ConstantIndices,
1755 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001756LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1757LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1758LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1759LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1760LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1761LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1762LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1763LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1764LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1765LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1766LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1767LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001768LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001769LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1770 LLVMTypeRef ToType);
1771LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1772 LLVMTypeRef ToType);
1773LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1774 LLVMTypeRef ToType);
1775LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1776 LLVMTypeRef ToType);
1777LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001778 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001779LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001780LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1781 LLVMValueRef ConstantIfTrue,
1782 LLVMValueRef ConstantIfFalse);
1783LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1784 LLVMValueRef IndexConstant);
1785LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1786 LLVMValueRef ElementValueConstant,
1787 LLVMValueRef IndexConstant);
1788LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1789 LLVMValueRef VectorBConstant,
1790 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001791LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1792 unsigned NumIdx);
1793LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1794 LLVMValueRef ElementValueConstant,
1795 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001796LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001797 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001798 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001799LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001800
Gregory Szorc52d26602012-03-21 07:28:27 +00001801/**
1802 * @}
1803 */
1804
1805/**
1806 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1807 *
1808 * This group contains functions that operate on global values. Functions in
1809 * this group relate to functions in the llvm::GlobalValue class tree.
1810 *
1811 * @see llvm::GlobalValue
1812 *
1813 * @{
1814 */
1815
Gordon Henriksen265f7802008-03-19 01:11:35 +00001816LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001817LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001818LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1819void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1820const char *LLVMGetSection(LLVMValueRef Global);
1821void LLVMSetSection(LLVMValueRef Global, const char *Section);
1822LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1823void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001824LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1825void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001826LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1827void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001828
1829/**
1830 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1831 *
1832 * Functions in this group only apply to values with alignment, i.e.
1833 * global variables, load and store instructions.
1834 */
1835
1836/**
1837 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001838 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001839 * @see llvm::LoadInst::getAlignment()
1840 * @see llvm::StoreInst::getAlignment()
1841 * @see llvm::GlobalValue::getAlignment()
1842 */
1843unsigned LLVMGetAlignment(LLVMValueRef V);
1844
1845/**
1846 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001847 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001848 * @see llvm::LoadInst::setAlignment()
1849 * @see llvm::StoreInst::setAlignment()
1850 * @see llvm::GlobalValue::setAlignment()
1851 */
1852void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1853
1854/**
Amaury Sechet83550102016-02-14 08:58:49 +00001855 * @}
1856 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001857
Gregory Szorc52d26602012-03-21 07:28:27 +00001858/**
1859 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1860 *
1861 * This group contains functions that operate on global variable values.
1862 *
1863 * @see llvm::GlobalVariable
1864 *
1865 * @{
1866 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001867LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001868LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1869 const char *Name,
1870 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001871LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001872LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1873LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1874LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1875LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001876void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001877LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1878void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001879LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1880void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1881LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1882void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001883LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1884void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1885LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1886void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001887
Gregory Szorc52d26602012-03-21 07:28:27 +00001888/**
1889 * @}
1890 */
1891
1892/**
1893 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1894 *
1895 * This group contains function that operate on global alias values.
1896 *
1897 * @see llvm::GlobalAlias
1898 *
1899 * @{
1900 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001901LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1902 const char *Name);
1903
Gregory Szorc34c863a2012-03-21 03:54:29 +00001904/**
1905 * @}
1906 */
1907
1908/**
1909 * @defgroup LLVMCCoreValueFunction Function values
1910 *
1911 * Functions in this group operate on LLVMValueRef instances that
1912 * correspond to llvm::Function instances.
1913 *
1914 * @see llvm::Function
1915 *
1916 * @{
1917 */
1918
1919/**
1920 * Remove a function from its containing module and deletes it.
1921 *
1922 * @see llvm::Function::eraseFromParent()
1923 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001924void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001925
1926/**
Amaury Sechete39e8532016-02-18 20:38:32 +00001927 * Check whether the given function has a personality function.
1928 *
1929 * @see llvm::Function::hasPersonalityFn()
1930 */
1931LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
1932
1933/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00001934 * Obtain the personality function attached to the function.
1935 *
1936 * @see llvm::Function::getPersonalityFn()
1937 */
1938LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
1939
1940/**
1941 * Set the personality function attached to the function.
1942 *
1943 * @see llvm::Function::setPersonalityFn()
1944 */
1945void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
1946
1947/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001948 * Obtain the ID number from a function instance.
1949 *
1950 * @see llvm::Function::getIntrinsicID()
1951 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001952unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001953
1954/**
1955 * Obtain the calling function of a function.
1956 *
1957 * The returned value corresponds to the LLVMCallConv enumeration.
1958 *
1959 * @see llvm::Function::getCallingConv()
1960 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001961unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001962
1963/**
1964 * Set the calling convention of a function.
1965 *
1966 * @see llvm::Function::setCallingConv()
1967 *
1968 * @param Fn Function to operate on
1969 * @param CC LLVMCallConv to set calling convention to
1970 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001971void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001972
1973/**
1974 * Obtain the name of the garbage collector to use during code
1975 * generation.
1976 *
1977 * @see llvm::Function::getGC()
1978 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001979const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001980
1981/**
1982 * Define the garbage collector to use during code generation.
1983 *
1984 * @see llvm::Function::setGC()
1985 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001986void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001987
1988/**
1989 * Add an attribute to a function.
1990 *
1991 * @see llvm::Function::addAttribute()
1992 */
Amaury Sechet5db224e2016-06-12 06:17:24 +00001993void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
1994 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00001995unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx);
1996void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
1997 LLVMAttributeRef *Attrs);
Amaury Sechet5db224e2016-06-12 06:17:24 +00001998LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
1999 LLVMAttributeIndex Idx,
2000 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002001LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
2002 LLVMAttributeIndex Idx,
2003 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002004void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2005 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002006void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2007 const char *K, unsigned KLen);
Amaury Sechet5db224e2016-06-12 06:17:24 +00002008
Gregory Szorc34c863a2012-03-21 03:54:29 +00002009/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00002010 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00002011 * @see llvm::AttrBuilder::addAttribute()
2012 */
2013void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
2014 const char *V);
2015
2016/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002017 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
2018 *
2019 * Functions in this group relate to arguments/parameters on functions.
2020 *
2021 * Functions in this group expect LLVMValueRef instances that correspond
2022 * to llvm::Function instances.
2023 *
2024 * @{
2025 */
2026
2027/**
2028 * Obtain the number of parameters in a function.
2029 *
2030 * @see llvm::Function::arg_size()
2031 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002032unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002033
2034/**
2035 * Obtain the parameters in a function.
2036 *
2037 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
2038 * at least LLVMCountParams() long. This array will be filled with
2039 * LLVMValueRef instances which correspond to the parameters the
2040 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
2041 * instance.
2042 *
2043 * @see llvm::Function::arg_begin()
2044 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002045void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002046
2047/**
2048 * Obtain the parameter at the specified index.
2049 *
2050 * Parameters are indexed from 0.
2051 *
2052 * @see llvm::Function::arg_begin()
2053 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002054LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002055
2056/**
2057 * Obtain the function to which this argument belongs.
2058 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002059 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002060 * that corresponds to a llvm::Attribute.
2061 *
2062 * The returned LLVMValueRef is the llvm::Function to which this
2063 * argument belongs.
2064 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002065LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002066
2067/**
2068 * Obtain the first parameter to a function.
2069 *
2070 * @see llvm::Function::arg_begin()
2071 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002072LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002073
2074/**
2075 * Obtain the last parameter to a function.
2076 *
2077 * @see llvm::Function::arg_end()
2078 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002079LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002080
2081/**
2082 * Obtain the next parameter to a function.
2083 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002084 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002085 * actually a wrapped iterator) and obtains the next parameter from the
2086 * underlying iterator.
2087 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002088LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002089
2090/**
2091 * Obtain the previous parameter to a function.
2092 *
2093 * This is the opposite of LLVMGetNextParam().
2094 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002095LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002096
2097/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002098 * Set the alignment for a function parameter.
2099 *
2100 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002101 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002102 */
Amaury Sechet81243a72016-05-01 01:42:34 +00002103void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned Align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002104
Gregory Szorc34c863a2012-03-21 03:54:29 +00002105/**
2106 * @}
2107 */
2108
2109/**
2110 * @}
2111 */
2112
2113/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002114 * @}
2115 */
2116
2117/**
2118 * @}
2119 */
2120
2121/**
2122 * @defgroup LLVMCCoreValueMetadata Metadata
2123 *
2124 * @{
2125 */
2126
2127/**
2128 * Obtain a MDString value from a context.
2129 *
2130 * The returned instance corresponds to the llvm::MDString class.
2131 *
2132 * The instance is specified by string data of a specified length. The
2133 * string content is copied, so the backing memory can be freed after
2134 * this function returns.
2135 */
2136LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2137 unsigned SLen);
2138
2139/**
2140 * Obtain a MDString value from the global context.
2141 */
2142LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2143
2144/**
2145 * Obtain a MDNode value from a context.
2146 *
2147 * The returned value corresponds to the llvm::MDNode class.
2148 */
2149LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2150 unsigned Count);
2151
2152/**
2153 * Obtain a MDNode value from the global context.
2154 */
2155LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2156
2157/**
Amaury Sechetf8429752017-04-17 11:52:54 +00002158 * Obtain a Metadata as a Value.
2159 */
2160LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD);
2161
2162/**
2163 * Obtain a Value as a Metadata.
2164 */
2165LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val);
2166
2167/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002168 * Obtain the underlying string from a MDString value.
2169 *
2170 * @param V Instance to obtain string from.
NAKAMURA Takumie4a77052016-04-04 11:54:48 +00002171 * @param Length Memory address which will hold length of returned string.
Gregory Szorc52d26602012-03-21 07:28:27 +00002172 * @return String data in MDString.
2173 */
Amaury Sechet7c2883c2016-04-03 21:06:04 +00002174const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length);
Gregory Szorc52d26602012-03-21 07:28:27 +00002175
2176/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002177 * Obtain the number of operands from an MDNode value.
2178 *
2179 * @param V MDNode to get number of operands from.
2180 * @return Number of operands of the MDNode.
2181 */
2182unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2183
2184/**
2185 * Obtain the given MDNode's operands.
2186 *
2187 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2188 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2189 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2190 * MDNode's operands.
2191 *
2192 * @param V MDNode to get the operands from.
2193 * @param Dest Destination array for operands.
2194 */
2195void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2196
2197/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002198 * @}
2199 */
2200
2201/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002202 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2203 *
2204 * A basic block represents a single entry single exit section of code.
2205 * Basic blocks contain a list of instructions which form the body of
2206 * the block.
2207 *
2208 * Basic blocks belong to functions. They have the type of label.
2209 *
2210 * Basic blocks are themselves values. However, the C API models them as
2211 * LLVMBasicBlockRef.
2212 *
2213 * @see llvm::BasicBlock
2214 *
2215 * @{
2216 */
2217
2218/**
2219 * Convert a basic block instance to a value type.
2220 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002221LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002222
2223/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002224 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002225 */
Chris Lattner25963c62010-01-09 22:27:07 +00002226LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002227
2228/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002229 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002230 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002231LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002232
2233/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002234 * Obtain the string name of a basic block.
2235 */
2236const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2237
2238/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002239 * Obtain the function to which a basic block belongs.
2240 *
2241 * @see llvm::BasicBlock::getParent()
2242 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002243LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002244
2245/**
2246 * Obtain the terminator instruction for a basic block.
2247 *
2248 * If the basic block does not have a terminator (it is not well-formed
2249 * if it doesn't), then NULL is returned.
2250 *
2251 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2252 *
2253 * @see llvm::BasicBlock::getTerminator()
2254 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002255LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002256
2257/**
2258 * Obtain the number of basic blocks in a function.
2259 *
2260 * @param Fn Function value to operate on.
2261 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002262unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002263
2264/**
2265 * Obtain all of the basic blocks in a function.
2266 *
2267 * This operates on a function value. The BasicBlocks parameter is a
2268 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2269 * LLVMCountBasicBlocks() in length. This array is populated with
2270 * LLVMBasicBlockRef instances.
2271 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002272void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002273
2274/**
2275 * Obtain the first basic block in a function.
2276 *
2277 * The returned basic block can be used as an iterator. You will likely
2278 * eventually call into LLVMGetNextBasicBlock() with it.
2279 *
2280 * @see llvm::Function::begin()
2281 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002282LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002283
2284/**
2285 * Obtain the last basic block in a function.
2286 *
2287 * @see llvm::Function::end()
2288 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002289LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002290
2291/**
2292 * Advance a basic block iterator.
2293 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002294LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002295
2296/**
2297 * Go backwards in a basic block iterator.
2298 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002299LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002300
2301/**
2302 * Obtain the basic block that corresponds to the entry point of a
2303 * function.
2304 *
2305 * @see llvm::Function::getEntryBlock()
2306 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002307LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002308
Gregory Szorc34c863a2012-03-21 03:54:29 +00002309/**
2310 * Append a basic block to the end of a function.
2311 *
2312 * @see llvm::BasicBlock::Create()
2313 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002314LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2315 LLVMValueRef Fn,
2316 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002317
2318/**
2319 * Append a basic block to the end of a function using the global
2320 * context.
2321 *
2322 * @see llvm::BasicBlock::Create()
2323 */
2324LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2325
2326/**
2327 * Insert a basic block in a function before another basic block.
2328 *
2329 * The function to add to is determined by the function of the
2330 * passed basic block.
2331 *
2332 * @see llvm::BasicBlock::Create()
2333 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002334LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2335 LLVMBasicBlockRef BB,
2336 const char *Name);
2337
Gregory Szorc34c863a2012-03-21 03:54:29 +00002338/**
2339 * Insert a basic block in a function using the global context.
2340 *
2341 * @see llvm::BasicBlock::Create()
2342 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002343LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2344 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002345
2346/**
2347 * Remove a basic block from a function and delete it.
2348 *
2349 * This deletes the basic block from its containing function and deletes
2350 * the basic block itself.
2351 *
2352 * @see llvm::BasicBlock::eraseFromParent()
2353 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002354void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002355
2356/**
2357 * Remove a basic block from a function.
2358 *
2359 * This deletes the basic block from its containing function but keep
2360 * the basic block alive.
2361 *
2362 * @see llvm::BasicBlock::removeFromParent()
2363 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002364void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002365
Gregory Szorc34c863a2012-03-21 03:54:29 +00002366/**
2367 * Move a basic block to before another one.
2368 *
2369 * @see llvm::BasicBlock::moveBefore()
2370 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002371void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002372
2373/**
2374 * Move a basic block to after another one.
2375 *
2376 * @see llvm::BasicBlock::moveAfter()
2377 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002378void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2379
Gregory Szorc34c863a2012-03-21 03:54:29 +00002380/**
2381 * Obtain the first instruction in a basic block.
2382 *
2383 * The returned LLVMValueRef corresponds to a llvm::Instruction
2384 * instance.
2385 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002386LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002387
2388/**
2389 * Obtain the last instruction in a basic block.
2390 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002391 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002392 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002393LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002394
Gregory Szorc34c863a2012-03-21 03:54:29 +00002395/**
2396 * @}
2397 */
2398
2399/**
2400 * @defgroup LLVMCCoreValueInstruction Instructions
2401 *
2402 * Functions in this group relate to the inspection and manipulation of
2403 * individual instructions.
2404 *
2405 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2406 * class has a large number of descendents. llvm::Instruction is a
2407 * llvm::Value and in the C API, instructions are modeled by
2408 * LLVMValueRef.
2409 *
2410 * This group also contains sub-groups which operate on specific
2411 * llvm::Instruction types, e.g. llvm::CallInst.
2412 *
2413 * @{
2414 */
2415
2416/**
2417 * Determine whether an instruction has any metadata attached.
2418 */
2419int LLVMHasMetadata(LLVMValueRef Val);
2420
2421/**
2422 * Return metadata associated with an instruction value.
2423 */
2424LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2425
2426/**
2427 * Set metadata associated with an instruction value.
2428 */
2429void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2430
2431/**
2432 * Obtain the basic block to which an instruction belongs.
2433 *
2434 * @see llvm::Instruction::getParent()
2435 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002436LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002437
2438/**
2439 * Obtain the instruction that occurs after the one specified.
2440 *
2441 * The next instruction will be from the same basic block.
2442 *
2443 * If this is the last instruction in a basic block, NULL will be
2444 * returned.
2445 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002446LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002447
2448/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002449 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002450 *
2451 * If the instruction is the first instruction in a basic block, NULL
2452 * will be returned.
2453 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002454LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002455
2456/**
2457 * Remove and delete an instruction.
2458 *
2459 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00002460 * block but is kept alive.
2461 *
2462 * @see llvm::Instruction::removeFromParent()
2463 */
2464void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
2465
2466/**
2467 * Remove and delete an instruction.
2468 *
2469 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00002470 * block and then deleted.
2471 *
2472 * @see llvm::Instruction::eraseFromParent()
2473 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002474void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002475
2476/**
2477 * Obtain the code opcode for an individual instruction.
2478 *
2479 * @see llvm::Instruction::getOpCode()
2480 */
Eric Christophera6b96002015-12-18 01:46:52 +00002481LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002482
2483/**
2484 * Obtain the predicate of an instruction.
2485 *
2486 * This is only valid for instructions that correspond to llvm::ICmpInst
2487 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2488 *
2489 * @see llvm::ICmpInst::getPredicate()
2490 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002491LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002492
Gregory Szorc34c863a2012-03-21 03:54:29 +00002493/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00002494 * Obtain the float predicate of an instruction.
2495 *
2496 * This is only valid for instructions that correspond to llvm::FCmpInst
2497 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
2498 *
2499 * @see llvm::FCmpInst::getPredicate()
2500 */
2501LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
2502
2503/**
Peter Zotovaff492c2014-10-17 01:02:34 +00002504 * Create a copy of 'this' instruction that is identical in all ways
2505 * except the following:
2506 * * The instruction has no parent
2507 * * The instruction has no name
2508 *
2509 * @see llvm::Instruction::clone()
2510 */
2511LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
2512
2513/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002514 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2515 *
2516 * Functions in this group apply to instructions that refer to call
2517 * sites and invocations. These correspond to C++ types in the
2518 * llvm::CallInst class tree.
2519 *
2520 * @{
2521 */
2522
2523/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002524 * Obtain the argument count for a call instruction.
2525 *
2526 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2527 * llvm::InvokeInst.
2528 *
2529 * @see llvm::CallInst::getNumArgOperands()
2530 * @see llvm::InvokeInst::getNumArgOperands()
2531 */
2532unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
2533
2534/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002535 * Set the calling convention for a call instruction.
2536 *
2537 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2538 * llvm::InvokeInst.
2539 *
2540 * @see llvm::CallInst::setCallingConv()
2541 * @see llvm::InvokeInst::setCallingConv()
2542 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002543void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002544
2545/**
2546 * Obtain the calling convention for a call instruction.
2547 *
2548 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2549 * usage.
2550 *
2551 * @see LLVMSetInstructionCallConv()
2552 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002553unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002554
Gregory Szorc34c863a2012-03-21 03:54:29 +00002555void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Amaury Sechet81243a72016-05-01 01:42:34 +00002556 unsigned Align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002557
Amaury Secheta65a2372016-06-15 05:14:29 +00002558void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2559 LLVMAttributeRef A);
Amaury Sechet17b67cd2016-07-21 04:25:06 +00002560unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx);
2561void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
2562 LLVMAttributeRef *Attrs);
Amaury Secheta65a2372016-06-15 05:14:29 +00002563LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
2564 LLVMAttributeIndex Idx,
2565 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002566LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
2567 LLVMAttributeIndex Idx,
2568 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00002569void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2570 unsigned KindID);
Amaury Sechet6100adf2016-06-15 17:50:39 +00002571void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2572 const char *K, unsigned KLen);
Amaury Secheta65a2372016-06-15 05:14:29 +00002573
Gregory Szorc34c863a2012-03-21 03:54:29 +00002574/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002575 * Obtain the pointer to the function invoked by this instruction.
2576 *
2577 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2578 * llvm::InvokeInst.
2579 *
2580 * @see llvm::CallInst::getCalledValue()
2581 * @see llvm::InvokeInst::getCalledValue()
2582 */
2583LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
2584
2585/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002586 * Obtain whether a call instruction is a tail call.
2587 *
2588 * This only works on llvm::CallInst instructions.
2589 *
2590 * @see llvm::CallInst::isTailCall()
2591 */
Chris Lattner25963c62010-01-09 22:27:07 +00002592LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002593
2594/**
2595 * Set whether a call instruction is a tail call.
2596 *
2597 * This only works on llvm::CallInst instructions.
2598 *
2599 * @see llvm::CallInst::setTailCall()
2600 */
Chris Lattner25963c62010-01-09 22:27:07 +00002601void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002602
Gregory Szorc34c863a2012-03-21 03:54:29 +00002603/**
Amaury Sechete39e8532016-02-18 20:38:32 +00002604 * Return the normal destination basic block.
2605 *
2606 * This only works on llvm::InvokeInst instructions.
2607 *
2608 * @see llvm::InvokeInst::getNormalDest()
2609 */
2610LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
2611
2612/**
2613 * Return the unwind destination basic block.
2614 *
2615 * This only works on llvm::InvokeInst instructions.
2616 *
2617 * @see llvm::InvokeInst::getUnwindDest()
2618 */
2619LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
2620
2621/**
2622 * Set the normal destination basic block.
2623 *
2624 * This only works on llvm::InvokeInst instructions.
2625 *
2626 * @see llvm::InvokeInst::setNormalDest()
2627 */
2628void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2629
2630/**
2631 * Set the unwind destination basic block.
2632 *
2633 * This only works on llvm::InvokeInst instructions.
2634 *
2635 * @see llvm::InvokeInst::setUnwindDest()
2636 */
2637void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2638
2639/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002640 * @}
2641 */
2642
2643/**
Peter Zotov2481c752014-10-28 19:46:56 +00002644 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
2645 *
2646 * Functions in this group only apply to instructions that map to
2647 * llvm::TerminatorInst instances.
2648 *
2649 * @{
2650 */
2651
2652/**
2653 * Return the number of successors that this terminator has.
2654 *
2655 * @see llvm::TerminatorInst::getNumSuccessors
2656 */
2657unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
2658
2659/**
2660 * Return the specified successor.
2661 *
2662 * @see llvm::TerminatorInst::getSuccessor
2663 */
2664LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
2665
2666/**
2667 * Update the specified successor to point at the provided block.
2668 *
2669 * @see llvm::TerminatorInst::setSuccessor
2670 */
2671void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
2672
2673/**
2674 * Return if a branch is conditional.
2675 *
2676 * This only works on llvm::BranchInst instructions.
2677 *
2678 * @see llvm::BranchInst::isConditional
2679 */
2680LLVMBool LLVMIsConditional(LLVMValueRef Branch);
2681
2682/**
2683 * Return the condition of a branch instruction.
2684 *
2685 * This only works on llvm::BranchInst instructions.
2686 *
2687 * @see llvm::BranchInst::getCondition
2688 */
2689LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
2690
2691/**
2692 * Set the condition of a branch instruction.
2693 *
2694 * This only works on llvm::BranchInst instructions.
2695 *
2696 * @see llvm::BranchInst::setCondition
2697 */
2698void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
2699
2700/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002701 * Obtain the default destination basic block of a switch instruction.
2702 *
2703 * This only works on llvm::SwitchInst instructions.
2704 *
2705 * @see llvm::SwitchInst::getDefaultDest()
2706 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002707LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2708
Gregory Szorc34c863a2012-03-21 03:54:29 +00002709/**
Peter Zotov2481c752014-10-28 19:46:56 +00002710 * @}
2711 */
2712
2713/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00002714 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
2715 *
2716 * Functions in this group only apply to instructions that map to
2717 * llvm::AllocaInst instances.
2718 *
2719 * @{
2720 */
2721
2722/**
2723 * Obtain the type that is being allocated by the alloca instruction.
2724 */
2725LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
2726
2727/**
2728 * @}
2729 */
2730
2731/**
Amaury Sechet053ac452016-02-17 22:51:03 +00002732 * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
2733 *
2734 * Functions in this group only apply to instructions that map to
2735 * llvm::GetElementPtrInst instances.
2736 *
2737 * @{
2738 */
2739
2740/**
2741 * Check whether the given GEP instruction is inbounds.
2742 */
2743LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
2744
2745/**
2746 * Set the given GEP instruction to be inbounds or not.
2747 */
Amaury Sechet8a367d42016-05-01 02:23:14 +00002748void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds);
Amaury Sechet053ac452016-02-17 22:51:03 +00002749
2750/**
2751 * @}
2752 */
2753
2754/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002755 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2756 *
2757 * Functions in this group only apply to instructions that map to
2758 * llvm::PHINode instances.
2759 *
2760 * @{
2761 */
2762
2763/**
2764 * Add an incoming value to the end of a PHI list.
2765 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002766void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2767 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002768
2769/**
2770 * Obtain the number of incoming basic blocks to a PHI node.
2771 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002772unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002773
2774/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002775 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002776 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002777LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002778
2779/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002780 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002781 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002782LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002783
Gregory Szorc34c863a2012-03-21 03:54:29 +00002784/**
2785 * @}
2786 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002787
Gregory Szorc34c863a2012-03-21 03:54:29 +00002788/**
Amaury Sechetaad93532016-02-10 00:38:50 +00002789 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
2790 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
2791 *
2792 * Functions in this group only apply to instructions that map to
2793 * llvm::ExtractValue and llvm::InsertValue instances.
2794 *
2795 * @{
2796 */
2797
2798/**
2799 * Obtain the number of indices.
Amaury Sechet053ac452016-02-17 22:51:03 +00002800 * NB: This also works on GEP.
Amaury Sechetaad93532016-02-10 00:38:50 +00002801 */
2802unsigned LLVMGetNumIndices(LLVMValueRef Inst);
2803
2804/**
2805 * Obtain the indices as an array.
2806 */
2807const unsigned *LLVMGetIndices(LLVMValueRef Inst);
2808
2809/**
2810 * @}
2811 */
2812
2813/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002814 * @}
2815 */
2816
2817/**
2818 * @}
2819 */
2820
2821/**
2822 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2823 *
2824 * An instruction builder represents a point within a basic block and is
2825 * the exclusive means of building instructions using the C interface.
2826 *
2827 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002828 */
2829
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002830LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002831LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002832void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2833 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002834void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2835void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002836LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002837void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2838void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002839void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2840 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002841void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2842
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002843/* Metadata */
2844void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2845LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2846void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2847
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002848/* Terminators */
2849LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2850LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002851LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002852 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002853LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2854LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2855 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2856LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2857 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002858LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2859 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002860LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2861 LLVMValueRef *Args, unsigned NumArgs,
2862 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2863 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002864LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00002865 LLVMValueRef PersFn, unsigned NumClauses,
2866 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002867LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002868LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2869
Gordon Henriksen097102c2008-01-01 05:50:53 +00002870/* Add a case to the switch instruction */
2871void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2872 LLVMBasicBlockRef Dest);
2873
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002874/* Add a destination to the indirectbr instruction */
2875void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2876
Amaury Sechete39e8532016-02-18 20:38:32 +00002877/* Get the number of clauses on the landingpad instruction */
2878unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
2879
2880/* Get the value of the clause at idnex Idx on the landingpad instruction */
2881LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
2882
Bill Wendlingfae14752011-08-12 20:24:12 +00002883/* Add a catch or filter clause to the landingpad instruction */
2884void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2885
Amaury Sechete39e8532016-02-18 20:38:32 +00002886/* Get the 'cleanup' flag in the landingpad instruction */
2887LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
2888
Bill Wendlingfae14752011-08-12 20:24:12 +00002889/* Set the 'cleanup' flag in the landingpad instruction */
2890void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2891
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002892/* Arithmetic */
2893LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2894 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002895LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2896 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002897LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2898 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002899LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2900 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002901LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2902 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002903LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2904 const char *Name);
2905LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2906 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002907LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2908 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002909LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2910 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002911LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2912 const char *Name);
2913LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2914 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002915LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2916 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002917LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2918 const char *Name);
Manuel Jacob49fafb12016-10-04 23:32:42 +00002919LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2920 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002921LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2922 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002923LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2924 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002925LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2926 const char *Name);
2927LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2928 const char *Name);
2929LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2930 const char *Name);
2931LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2932 const char *Name);
2933LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2934 const char *Name);
2935LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2936 const char *Name);
2937LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2938 const char *Name);
2939LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2940 const char *Name);
2941LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2942 const char *Name);
2943LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2944 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002945LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2946 LLVMValueRef LHS, LLVMValueRef RHS,
2947 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002948LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002949LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2950 const char *Name);
2951LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2952 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002953LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002954LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2955
2956/* Memory */
2957LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2958LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2959 LLVMValueRef Val, const char *Name);
2960LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2961LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2962 LLVMValueRef Val, const char *Name);
2963LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2964LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2965 const char *Name);
2966LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2967LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2968 LLVMValueRef *Indices, unsigned NumIndices,
2969 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002970LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2971 LLVMValueRef *Indices, unsigned NumIndices,
2972 const char *Name);
2973LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2974 unsigned Idx, const char *Name);
2975LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2976 const char *Name);
2977LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2978 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002979LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2980void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00002981LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
2982void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002983
2984/* Casts */
2985LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2986 LLVMTypeRef DestTy, const char *Name);
2987LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2988 LLVMTypeRef DestTy, const char *Name);
2989LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2990 LLVMTypeRef DestTy, const char *Name);
2991LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2992 LLVMTypeRef DestTy, const char *Name);
2993LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2994 LLVMTypeRef DestTy, const char *Name);
2995LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2996 LLVMTypeRef DestTy, const char *Name);
2997LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2998 LLVMTypeRef DestTy, const char *Name);
2999LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
3000 LLVMTypeRef DestTy, const char *Name);
3001LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
3002 LLVMTypeRef DestTy, const char *Name);
3003LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
3004 LLVMTypeRef DestTy, const char *Name);
3005LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
3006 LLVMTypeRef DestTy, const char *Name);
3007LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
3008 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00003009LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
3010 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003011LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3012 LLVMTypeRef DestTy, const char *Name);
3013LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3014 LLVMTypeRef DestTy, const char *Name);
3015LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
3016 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00003017LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
3018 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003019LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
3020 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00003021LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003022 LLVMTypeRef DestTy, const char *Name);
3023LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
3024 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00003025
3026/* Comparisons */
3027LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
3028 LLVMValueRef LHS, LLVMValueRef RHS,
3029 const char *Name);
3030LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
3031 LLVMValueRef LHS, LLVMValueRef RHS,
3032 const char *Name);
3033
3034/* Miscellaneous instructions */
3035LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3036LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
3037 LLVMValueRef *Args, unsigned NumArgs,
3038 const char *Name);
3039LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
3040 LLVMValueRef Then, LLVMValueRef Else,
3041 const char *Name);
3042LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
3043 const char *Name);
3044LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
3045 LLVMValueRef Index, const char *Name);
3046LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
3047 LLVMValueRef EltVal, LLVMValueRef Index,
3048 const char *Name);
3049LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
3050 LLVMValueRef V2, LLVMValueRef Mask,
3051 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00003052LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
3053 unsigned Index, const char *Name);
3054LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
3055 LLVMValueRef EltVal, unsigned Index,
3056 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00003057
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003058LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
3059 const char *Name);
3060LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
3061 const char *Name);
3062LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
3063 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00003064LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
3065 LLVMBool singleThread, const char *Name);
3066LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00003067 LLVMValueRef PTR, LLVMValueRef Val,
3068 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00003069 LLVMBool singleThread);
Mehdi Amini43165d92016-03-19 21:28:28 +00003070LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
3071 LLVMValueRef Cmp, LLVMValueRef New,
3072 LLVMAtomicOrdering SuccessOrdering,
3073 LLVMAtomicOrdering FailureOrdering,
3074 LLVMBool SingleThread);
3075
3076LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
3077void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
3078
3079LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
3080void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
3081 LLVMAtomicOrdering Ordering);
3082LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
3083void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
3084 LLVMAtomicOrdering Ordering);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00003085
Gregory Szorc34c863a2012-03-21 03:54:29 +00003086/**
3087 * @}
3088 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003089
Gregory Szorc34c863a2012-03-21 03:54:29 +00003090/**
3091 * @defgroup LLVMCCoreModuleProvider Module Providers
3092 *
3093 * @{
3094 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003095
Gregory Szorc34c863a2012-03-21 03:54:29 +00003096/**
3097 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003098 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003099 */
3100LLVMModuleProviderRef
3101LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
3102
Gregory Szorc34c863a2012-03-21 03:54:29 +00003103/**
3104 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003105 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00003106void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00003107
Gregory Szorc34c863a2012-03-21 03:54:29 +00003108/**
3109 * @}
3110 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003111
Gregory Szorc34c863a2012-03-21 03:54:29 +00003112/**
3113 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
3114 *
3115 * @{
3116 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003117
Chris Lattner25963c62010-01-09 22:27:07 +00003118LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
3119 LLVMMemoryBufferRef *OutMemBuf,
3120 char **OutMessage);
3121LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
3122 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00003123LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
3124 size_t InputDataLength,
3125 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00003126 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00003127LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
3128 size_t InputDataLength,
3129 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00003130const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00003131size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00003132void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
3133
Gregory Szorc34c863a2012-03-21 03:54:29 +00003134/**
3135 * @}
3136 */
3137
3138/**
3139 * @defgroup LLVMCCorePassRegistry Pass Registry
3140 *
3141 * @{
3142 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003143
3144/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003145 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00003146LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003147
Gregory Szorc34c863a2012-03-21 03:54:29 +00003148/**
3149 * @}
3150 */
3151
3152/**
3153 * @defgroup LLVMCCorePassManagers Pass Managers
3154 *
3155 * @{
3156 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003157
3158/** Constructs a new whole-module pass pipeline. This type of pipeline is
3159 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003160 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00003161LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003162
3163/** Constructs a new function-by-function pass pipeline over the module
3164 provider. It does not take ownership of the module provider. This type of
3165 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003166 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00003167LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
3168
3169/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003170LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
3171
3172/** Initializes, executes on the provided module, and finalizes all of the
3173 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00003174 modified the module, 0 otherwise.
3175 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003176LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003177
3178/** Initializes all of the function passes scheduled in the function pass
3179 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003180 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00003181LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003182
3183/** Executes all of the function passes scheduled in the function pass manager
3184 on the provided function. Returns 1 if any of the passes modified the
3185 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003186 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00003187LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003188
3189/** Finalizes all of the function passes scheduled in in the function pass
3190 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003191 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00003192LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00003193
3194/** Frees the memory of a pass pipeline. For function pipelines, does not free
3195 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00003196 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003197void LLVMDisposePassManager(LLVMPassManagerRef PM);
3198
Gregory Szorc34c863a2012-03-21 03:54:29 +00003199/**
3200 * @}
3201 */
3202
3203/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00003204 * @defgroup LLVMCCoreThreading Threading
3205 *
3206 * Handle the structures needed to make LLVM safe for multithreading.
3207 *
3208 * @{
3209 */
3210
Chandler Carruth39cd2162014-06-27 15:13:01 +00003211/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3212 time define LLVM_ENABLE_THREADS. This function always returns
3213 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003214LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003215
Chandler Carruth39cd2162014-06-27 15:13:01 +00003216/** Deprecated: Multi-threading can only be enabled/disabled with the compile
3217 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003218void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003219
3220/** Check whether LLVM is executing in thread-safe mode or not.
3221 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00003222LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003223
3224/**
3225 * @}
3226 */
3227
3228/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003229 * @}
3230 */
3231
3232/**
3233 * @}
3234 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003235
Gordon Henriksen76a03742007-09-18 03:18:57 +00003236#ifdef __cplusplus
3237}
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003238#endif
Gordon Henriksen7330acd2007-10-05 23:59:36 +00003239
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003240#endif /* LLVM_C_CORE_H */