blob: cd987c88f56cbe56d89cb73840dfbc8ccd7f1890 [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 {
Devang Patel4c758ea2008-09-25 21:00:45 +000058 LLVMZExtAttribute = 1<<0,
59 LLVMSExtAttribute = 1<<1,
60 LLVMNoReturnAttribute = 1<<2,
61 LLVMInRegAttribute = 1<<3,
62 LLVMStructRetAttribute = 1<<4,
63 LLVMNoUnwindAttribute = 1<<5,
64 LLVMNoAliasAttribute = 1<<6,
65 LLVMByValAttribute = 1<<7,
66 LLVMNestAttribute = 1<<8,
67 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +000068 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +000069 LLVMNoInlineAttribute = 1<<11,
70 LLVMAlwaysInlineAttribute = 1<<12,
71 LLVMOptimizeForSizeAttribute = 1<<13,
72 LLVMStackProtectAttribute = 1<<14,
73 LLVMStackProtectReqAttribute = 1<<15,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +000074 LLVMAlignment = 31<<16,
Anton Korobeynikov9750be92009-07-17 18:57:16 +000075 LLVMNoCaptureAttribute = 1<<21,
76 LLVMNoRedZoneAttribute = 1<<22,
77 LLVMNoImplicitFloatAttribute = 1<<23,
Jakob Stoklund Olesen74bb06c2010-02-06 01:16:28 +000078 LLVMNakedAttribute = 1<<24,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +000079 LLVMInlineHintAttribute = 1<<25,
Torok Edwin1db48c02011-10-06 12:13:32 +000080 LLVMStackAlignment = 7<<26,
81 LLVMReturnsTwice = 1 << 29,
82 LLVMUWTable = 1 << 30,
Chandler Carruth44d69d92012-01-25 07:40:15 +000083 LLVMNonLazyBind = 1 << 31
84
Bill Wendlingd154e2832013-01-23 06:41:41 +000085 /* FIXME: These attributes are currently not included in the C API as
Nuno Lopesdef4229972012-09-02 14:19:21 +000086 a temporary measure until the API/ABI impact to the C API is understood
87 and the path forward agreed upon.
Peter Collingbourne58af6d12015-06-15 22:16:51 +000088 LLVMSanitizeAddressAttribute = 1ULL << 32,
89 LLVMStackProtectStrongAttribute = 1ULL<<35,
90 LLVMColdAttribute = 1ULL << 40,
91 LLVMOptimizeNoneAttribute = 1ULL << 42,
92 LLVMInAllocaAttribute = 1ULL << 43,
93 LLVMNonNullAttribute = 1ULL << 44,
94 LLVMJumpTableAttribute = 1ULL << 45,
95 LLVMConvergentAttribute = 1ULL << 46,
96 LLVMSafeStackAttribute = 1ULL << 47,
Nuno Lopesdef4229972012-09-02 14:19:21 +000097 */
Devang Patel4c758ea2008-09-25 21:00:45 +000098} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +000099
100typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000101 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000102 LLVMRet = 1,
103 LLVMBr = 2,
104 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000105 LLVMIndirectBr = 4,
106 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000107 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000108 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000109
Bill Wendlingda52cec2010-02-15 20:53:17 +0000110 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000111 LLVMAdd = 8,
112 LLVMFAdd = 9,
113 LLVMSub = 10,
114 LLVMFSub = 11,
115 LLVMMul = 12,
116 LLVMFMul = 13,
117 LLVMUDiv = 14,
118 LLVMSDiv = 15,
119 LLVMFDiv = 16,
120 LLVMURem = 17,
121 LLVMSRem = 18,
122 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000123
Bill Wendlingda52cec2010-02-15 20:53:17 +0000124 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000125 LLVMShl = 20,
126 LLVMLShr = 21,
127 LLVMAShr = 22,
128 LLVMAnd = 23,
129 LLVMOr = 24,
130 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000131
Bill Wendlingda52cec2010-02-15 20:53:17 +0000132 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000133 LLVMAlloca = 26,
134 LLVMLoad = 27,
135 LLVMStore = 28,
136 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000137
Bill Wendlingda52cec2010-02-15 20:53:17 +0000138 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000139 LLVMTrunc = 30,
140 LLVMZExt = 31,
141 LLVMSExt = 32,
142 LLVMFPToUI = 33,
143 LLVMFPToSI = 34,
144 LLVMUIToFP = 35,
145 LLVMSIToFP = 36,
146 LLVMFPTrunc = 37,
147 LLVMFPExt = 38,
148 LLVMPtrToInt = 39,
149 LLVMIntToPtr = 40,
150 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000151 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000152
Bill Wendlingda52cec2010-02-15 20:53:17 +0000153 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000154 LLVMICmp = 42,
155 LLVMFCmp = 43,
156 LLVMPHI = 44,
157 LLVMCall = 45,
158 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000159 LLVMUserOp1 = 47,
160 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000161 LLVMVAArg = 49,
162 LLVMExtractElement = 50,
163 LLVMInsertElement = 51,
164 LLVMShuffleVector = 52,
165 LLVMExtractValue = 53,
166 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000167
168 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000169 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000170 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000171 LLVMAtomicRMW = 57,
172
173 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000174 LLVMResume = 58,
David Majnemer654e1302015-07-31 17:58:14 +0000175 LLVMLandingPad = 59,
176 LLVMCleanupRet = 61,
177 LLVMCatchRet = 62,
Joseph Tremoulet9ce71f72015-09-03 09:09:43 +0000178 LLVMCatchPad = 63,
David Majnemerbbfc7212015-12-14 18:34:23 +0000179 LLVMCleanupPad = 64,
180 LLVMCatchSwitch = 65
Chris Lattner40cf28d2009-10-12 04:01:02 +0000181} LLVMOpcode;
182
183typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000184 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000185 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000186 LLVMFloatTypeKind, /**< 32 bit floating point type */
187 LLVMDoubleTypeKind, /**< 64 bit floating point type */
188 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
189 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
190 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
191 LLVMLabelTypeKind, /**< Labels */
192 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
193 LLVMFunctionTypeKind, /**< Functions */
194 LLVMStructTypeKind, /**< Structures */
195 LLVMArrayTypeKind, /**< Arrays */
196 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000197 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000198 LLVMMetadataTypeKind, /**< Metadata */
David Majnemerb611e3f2015-08-14 05:09:07 +0000199 LLVMX86_MMXTypeKind, /**< X86 MMX */
200 LLVMTokenTypeKind /**< Tokens */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000201} LLVMTypeKind;
202
203typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000204 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000205 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000206 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
207 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
208 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000209 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000210 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
211 LLVMWeakODRLinkage, /**< Same, but only replaced by something
212 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000213 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
214 LLVMInternalLinkage, /**< Rename collisions when linking (static
215 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000216 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000217 LLVMDLLImportLinkage, /**< Obsolete */
218 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000219 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000220 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000221 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000222 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000223 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000224} LLVMLinkage;
225
226typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000227 LLVMDefaultVisibility, /**< The GV is visible */
228 LLVMHiddenVisibility, /**< The GV is hidden */
229 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000230} LLVMVisibility;
231
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000232typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000233 LLVMDefaultStorageClass = 0,
234 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
235 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
236} LLVMDLLStorageClass;
237
238typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000239 LLVMCCallConv = 0,
240 LLVMFastCallConv = 8,
241 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000242 LLVMWebKitJSCallConv = 12,
243 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000244 LLVMX86StdcallCallConv = 64,
245 LLVMX86FastcallCallConv = 65
246} LLVMCallConv;
247
248typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000249 LLVMIntEQ = 32, /**< equal */
250 LLVMIntNE, /**< not equal */
251 LLVMIntUGT, /**< unsigned greater than */
252 LLVMIntUGE, /**< unsigned greater or equal */
253 LLVMIntULT, /**< unsigned less than */
254 LLVMIntULE, /**< unsigned less or equal */
255 LLVMIntSGT, /**< signed greater than */
256 LLVMIntSGE, /**< signed greater or equal */
257 LLVMIntSLT, /**< signed less than */
258 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000259} LLVMIntPredicate;
260
261typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000262 LLVMRealPredicateFalse, /**< Always false (always folded) */
263 LLVMRealOEQ, /**< True if ordered and equal */
264 LLVMRealOGT, /**< True if ordered and greater than */
265 LLVMRealOGE, /**< True if ordered and greater than or equal */
266 LLVMRealOLT, /**< True if ordered and less than */
267 LLVMRealOLE, /**< True if ordered and less than or equal */
268 LLVMRealONE, /**< True if ordered and operands are unequal */
269 LLVMRealORD, /**< True if ordered (no nans) */
270 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
271 LLVMRealUEQ, /**< True if unordered or equal */
272 LLVMRealUGT, /**< True if unordered or greater than */
273 LLVMRealUGE, /**< True if unordered, greater than, or equal */
274 LLVMRealULT, /**< True if unordered or less than */
275 LLVMRealULE, /**< True if unordered, less than, or equal */
276 LLVMRealUNE, /**< True if unordered or not equal */
277 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000278} LLVMRealPredicate;
279
Bill Wendlingfae14752011-08-12 20:24:12 +0000280typedef enum {
281 LLVMLandingPadCatch, /**< A catch clause */
282 LLVMLandingPadFilter /**< A filter clause */
283} LLVMLandingPadClauseTy;
284
Hans Wennborg5ff71202013-04-16 08:58:59 +0000285typedef enum {
286 LLVMNotThreadLocal = 0,
287 LLVMGeneralDynamicTLSModel,
288 LLVMLocalDynamicTLSModel,
289 LLVMInitialExecTLSModel,
290 LLVMLocalExecTLSModel
291} LLVMThreadLocalMode;
292
Carlo Kokda0ac722013-04-23 13:45:37 +0000293typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000294 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
295 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
296 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000297 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
298 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000299 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000300 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
301 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000302 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000303 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
304 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000305 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000306 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
307 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000308 operations which both read and write
309 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000310 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
311 for loads and Release
312 semantics for stores.
313 Additionally, it guarantees
314 that a total ordering exists
315 between all
316 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000317 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000318} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000319
Carlo Kokda0ac722013-04-23 13:45:37 +0000320typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000321 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
322 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
323 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
324 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
325 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
326 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
327 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
328 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000329 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000330 the old one */
331 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000332 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000333 the old one */
334 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000335 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000336 the old one */
337 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000338 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000339 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000340} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000341
Tom Stellard1580dc72014-04-16 17:45:04 +0000342typedef enum {
343 LLVMDSError,
344 LLVMDSWarning,
345 LLVMDSRemark,
346 LLVMDSNote
347} LLVMDiagnosticSeverity;
348
Gregory Szorc34c863a2012-03-21 03:54:29 +0000349/**
350 * @}
351 */
352
Nick Lewycky0db26542011-05-15 07:20:34 +0000353void LLVMInitializeCore(LLVMPassRegistryRef R);
354
Duncan Sands1cba0a82013-02-17 16:35:51 +0000355/** Deallocate and destroy all ManagedStatic variables.
356 @see llvm::llvm_shutdown
357 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000358void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000359
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000360/*===-- Error handling ----------------------------------------------------===*/
361
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000362char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000363void LLVMDisposeMessage(char *Message);
364
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000365/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000366 * @defgroup LLVMCCoreContext Contexts
367 *
368 * Contexts are execution states for the core LLVM IR system.
369 *
370 * Most types are tied to a context instance. Multiple contexts can
371 * exist simultaneously. A single context is not thread safe. However,
372 * different contexts can execute on different threads simultaneously.
373 *
374 * @{
375 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000376
Tom Stellard1580dc72014-04-16 17:45:04 +0000377typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000378typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000379
Gregory Szorc34c863a2012-03-21 03:54:29 +0000380/**
381 * Create a new context.
382 *
383 * Every call to this function should be paired with a call to
384 * LLVMContextDispose() or the context will leak memory.
385 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000386LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000387
388/**
389 * Obtain the global context instance.
390 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000391LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000392
393/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000394 * Set the diagnostic handler for this context.
395 */
396void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
397 LLVMDiagnosticHandler Handler,
398 void *DiagnosticContext);
399
400/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000401 * Set the yield callback function for this context.
402 *
403 * @see LLVMContext::setYieldCallback()
404 */
405void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
406 void *OpaqueHandle);
407
408/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000409 * Destroy a context instance.
410 *
411 * This should be called for every call to LLVMContextCreate() or memory
412 * will be leaked.
413 */
Owen Anderson6773d382009-07-01 16:58:40 +0000414void LLVMContextDispose(LLVMContextRef C);
415
Tom Stellard1580dc72014-04-16 17:45:04 +0000416/**
417 * Return a string representation of the DiagnosticInfo. Use
418 * LLVMDisposeMessage to free the string.
419 *
420 * @see DiagnosticInfo::print()
421 */
422char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
423
424/**
425 * Return an enum LLVMDiagnosticSeverity.
426 *
427 * @see DiagnosticInfo::getSeverity()
428 */
429LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
430
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000431unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
432 unsigned SLen);
433unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
434
Gregory Szorc34c863a2012-03-21 03:54:29 +0000435/**
436 * @}
437 */
438
Gregory Szorc52d26602012-03-21 07:28:27 +0000439/**
440 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000441 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000442 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000443 * module is effectively a translation unit or a collection of
444 * translation units merged together.
445 *
446 * @{
447 */
448
Gregory Szorc34c863a2012-03-21 03:54:29 +0000449/**
450 * Create a new, empty module in the global context.
451 *
452 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
453 * LLVMGetGlobalContext() as the context parameter.
454 *
455 * Every invocation should be paired with LLVMDisposeModule() or memory
456 * will be leaked.
457 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000458LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000459
460/**
461 * Create a new, empty module in a specific context.
462 *
463 * Every invocation should be paired with LLVMDisposeModule() or memory
464 * will be leaked.
465 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000466LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
467 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000468/**
469 * Return an exact copy of the specified module.
470 */
471LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000472
Gregory Szorc34c863a2012-03-21 03:54:29 +0000473/**
474 * Destroy a module instance.
475 *
476 * This must be called for every created module or memory will be
477 * leaked.
478 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000479void LLVMDisposeModule(LLVMModuleRef M);
480
Gregory Szorc34c863a2012-03-21 03:54:29 +0000481/**
482 * Obtain the data layout for a module.
483 *
484 * @see Module::getDataLayout()
485 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000486const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000487
488/**
489 * Set the data layout for a module.
490 *
491 * @see Module::setDataLayout()
492 */
Amaury Sechet6ada31c2016-02-15 23:40:06 +0000493void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000494
Gregory Szorc34c863a2012-03-21 03:54:29 +0000495/**
496 * Obtain the target triple for a module.
497 *
498 * @see Module::getTargetTriple()
499 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000500const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000501
502/**
503 * Set the target triple for a module.
504 *
505 * @see Module::setTargetTriple()
506 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000507void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
508
Gregory Szorc34c863a2012-03-21 03:54:29 +0000509/**
510 * Dump a representation of a module to stderr.
511 *
512 * @see Module::dump()
513 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000514void LLVMDumpModule(LLVMModuleRef M);
515
Gregory Szorc34c863a2012-03-21 03:54:29 +0000516/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000517 * Print a representation of a module to a file. The ErrorMessage needs to be
518 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
519 *
520 * @see Module::print()
521 */
522LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
523 char **ErrorMessage);
524
525/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000526 * Return a string representation of the module. Use
527 * LLVMDisposeMessage to free the string.
528 *
529 * @see Module::print()
530 */
531char *LLVMPrintModuleToString(LLVMModuleRef M);
532
533/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000534 * Set inline assembly for a module.
535 *
536 * @see Module::setModuleInlineAsm()
537 */
Chris Lattner26941452010-04-10 17:52:58 +0000538void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000539
Gregory Szorc34c863a2012-03-21 03:54:29 +0000540/**
541 * Obtain the context to which this module is associated.
542 *
543 * @see Module::getContext()
544 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000545LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
546
Gregory Szorc34c863a2012-03-21 03:54:29 +0000547/**
548 * Obtain a Type from a module by its registered name.
549 */
550LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000551
Gregory Szorc34c863a2012-03-21 03:54:29 +0000552/**
553 * Obtain the number of operands for named metadata in a module.
554 *
555 * @see llvm::Module::getNamedMetadata()
556 */
557unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
558
559/**
560 * Obtain the named metadata operands for a module.
561 *
562 * The passed LLVMValueRef pointer should refer to an array of
563 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
564 * array will be populated with the LLVMValueRef instances. Each
565 * instance corresponds to a llvm::MDNode.
566 *
567 * @see llvm::Module::getNamedMetadata()
568 * @see llvm::MDNode::getOperand()
569 */
570void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
571
572/**
573 * Add an operand to named metadata.
574 *
575 * @see llvm::Module::getNamedMetadata()
576 * @see llvm::MDNode::addOperand()
577 */
578void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
579 LLVMValueRef Val);
580
Gregory Szorc52d26602012-03-21 07:28:27 +0000581/**
582 * Add a function to a module under a specified name.
583 *
584 * @see llvm::Function::Create()
585 */
586LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
587 LLVMTypeRef FunctionTy);
588
589/**
590 * Obtain a Function value from a Module by its name.
591 *
592 * The returned value corresponds to a llvm::Function value.
593 *
594 * @see llvm::Module::getFunction()
595 */
596LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
597
598/**
599 * Obtain an iterator to the first Function in a Module.
600 *
601 * @see llvm::Module::begin()
602 */
603LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
604
605/**
606 * Obtain an iterator to the last Function in a Module.
607 *
608 * @see llvm::Module::end()
609 */
610LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
611
612/**
613 * Advance a Function iterator to the next Function.
614 *
615 * Returns NULL if the iterator was already at the end and there are no more
616 * functions.
617 */
618LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
619
620/**
621 * Decrement a Function iterator to the previous Function.
622 *
623 * Returns NULL if the iterator was already at the beginning and there are
624 * no previous functions.
625 */
626LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000627
628/**
629 * @}
630 */
631
632/**
633 * @defgroup LLVMCCoreType Types
634 *
635 * Types represent the type of a value.
636 *
637 * Types are associated with a context instance. The context internally
638 * deduplicates types so there is only 1 instance of a specific type
639 * alive at a time. In other words, a unique type is shared among all
640 * consumers within a context.
641 *
642 * A Type in the C API corresponds to llvm::Type.
643 *
644 * Types have the following hierarchy:
645 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000646 * types:
647 * integer type
648 * real type
649 * function type
650 * sequence types:
651 * array type
652 * pointer type
653 * vector type
654 * void type
655 * label type
656 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000657 *
658 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000659 */
660
Gregory Szorc34c863a2012-03-21 03:54:29 +0000661/**
662 * Obtain the enumerated type of a Type instance.
663 *
664 * @see llvm::Type:getTypeID()
665 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000666LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000667
668/**
669 * Whether the type has a known size.
670 *
671 * Things that don't have a size are abstract types, labels, and void.a
672 *
673 * @see llvm::Type::isSized()
674 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000675LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000676
Gregory Szorc34c863a2012-03-21 03:54:29 +0000677/**
678 * Obtain the context to which this type instance is associated.
679 *
680 * @see llvm::Type::getContext()
681 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000682LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
683
Gregory Szorc34c863a2012-03-21 03:54:29 +0000684/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000685 * Dump a representation of a type to stderr.
686 *
687 * @see llvm::Type::dump()
688 */
689void LLVMDumpType(LLVMTypeRef Val);
690
691/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000692 * Return a string representation of the type. Use
693 * LLVMDisposeMessage to free the string.
694 *
695 * @see llvm::Type::print()
696 */
697char *LLVMPrintTypeToString(LLVMTypeRef Val);
698
699/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000700 * @defgroup LLVMCCoreTypeInt Integer Types
701 *
702 * Functions in this section operate on integer types.
703 *
704 * @{
705 */
706
707/**
708 * Obtain an integer type from a context with specified bit width.
709 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000710LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
711LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
712LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
713LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
714LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000715LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000716LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
717
Gregory Szorc34c863a2012-03-21 03:54:29 +0000718/**
719 * Obtain an integer type from the global context with a specified bit
720 * width.
721 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000722LLVMTypeRef LLVMInt1Type(void);
723LLVMTypeRef LLVMInt8Type(void);
724LLVMTypeRef LLVMInt16Type(void);
725LLVMTypeRef LLVMInt32Type(void);
726LLVMTypeRef LLVMInt64Type(void);
Eugene Zelenkoffec81c2015-11-04 22:32:32 +0000727LLVMTypeRef LLVMInt128Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000728LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000729unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000730
Gregory Szorc34c863a2012-03-21 03:54:29 +0000731/**
732 * @}
733 */
734
735/**
736 * @defgroup LLVMCCoreTypeFloat Floating Point Types
737 *
738 * @{
739 */
740
741/**
742 * Obtain a 16-bit floating point type from a context.
743 */
Dan Gohman518cda42011-12-17 00:04:22 +0000744LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000745
746/**
747 * Obtain a 32-bit floating point type from a context.
748 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000749LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000750
751/**
752 * Obtain a 64-bit floating point type from a context.
753 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000754LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000755
756/**
757 * Obtain a 80-bit floating point type (X87) from a context.
758 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000759LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000760
761/**
762 * Obtain a 128-bit floating point type (112-bit mantissa) from a
763 * context.
764 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000765LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000766
767/**
768 * Obtain a 128-bit floating point type (two 64-bits) from a context.
769 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000770LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
771
Gregory Szorc34c863a2012-03-21 03:54:29 +0000772/**
773 * Obtain a floating point type from the global context.
774 *
775 * These map to the functions in this group of the same name.
776 */
Dan Gohman518cda42011-12-17 00:04:22 +0000777LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000778LLVMTypeRef LLVMFloatType(void);
779LLVMTypeRef LLVMDoubleType(void);
780LLVMTypeRef LLVMX86FP80Type(void);
781LLVMTypeRef LLVMFP128Type(void);
782LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000783
Gregory Szorc34c863a2012-03-21 03:54:29 +0000784/**
785 * @}
786 */
787
788/**
789 * @defgroup LLVMCCoreTypeFunction Function Types
790 *
791 * @{
792 */
793
794/**
795 * Obtain a function type consisting of a specified signature.
796 *
797 * The function is defined as a tuple of a return Type, a list of
798 * parameter types, and whether the function is variadic.
799 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000800LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
801 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000802 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000803
804/**
805 * Returns whether a function type is variadic.
806 */
Chris Lattner25963c62010-01-09 22:27:07 +0000807LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000808
809/**
810 * Obtain the Type this function Type returns.
811 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000812LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000813
814/**
815 * Obtain the number of parameters this function accepts.
816 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000817unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000818
819/**
820 * Obtain the types of a function's parameters.
821 *
822 * The Dest parameter should point to a pre-allocated array of
823 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
824 * first LLVMCountParamTypes() entries in the array will be populated
825 * with LLVMTypeRef instances.
826 *
827 * @param FunctionTy The function type to operate on.
828 * @param Dest Memory address of an array to be filled with result.
829 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000830void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000831
Gregory Szorc34c863a2012-03-21 03:54:29 +0000832/**
833 * @}
834 */
835
836/**
837 * @defgroup LLVMCCoreTypeStruct Structure Types
838 *
839 * These functions relate to LLVMTypeRef instances.
840 *
841 * @see llvm::StructType
842 *
843 * @{
844 */
845
846/**
847 * Create a new structure type in a context.
848 *
849 * A structure is specified by a list of inner elements/types and
850 * whether these can be packed together.
851 *
852 * @see llvm::StructType::create()
853 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000854LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000855 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000856
857/**
858 * Create a new structure type in the global context.
859 *
860 * @see llvm::StructType::create()
861 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000862LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000863 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000864
865/**
866 * Create an empty structure in a context having a specified name.
867 *
868 * @see llvm::StructType::create()
869 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000870LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000871
872/**
873 * Obtain the name of a structure.
874 *
875 * @see llvm::StructType::getName()
876 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000877const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000878
879/**
880 * Set the contents of a structure type.
881 *
882 * @see llvm::StructType::setBody()
883 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000884void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
885 unsigned ElementCount, LLVMBool Packed);
886
Gregory Szorc34c863a2012-03-21 03:54:29 +0000887/**
888 * Get the number of elements defined inside the structure.
889 *
890 * @see llvm::StructType::getNumElements()
891 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000892unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000893
894/**
895 * Get the elements within a structure.
896 *
897 * The function is passed the address of a pre-allocated array of
898 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
899 * invocation, this array will be populated with the structure's
900 * elements. The objects in the destination array will have a lifetime
901 * of the structure type itself, which is the lifetime of the context it
902 * is contained in.
903 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000904void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000905
906/**
Peter Zotovc164a3f2015-06-04 09:09:53 +0000907 * Get the type of the element at a given index in the structure.
908 *
909 * @see llvm::StructType::getTypeAtIndex()
910 */
911LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
912
913/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000914 * Determine whether a structure is packed.
915 *
916 * @see llvm::StructType::isPacked()
917 */
Chris Lattner25963c62010-01-09 22:27:07 +0000918LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000919
920/**
921 * Determine whether a structure is opaque.
922 *
923 * @see llvm::StructType::isOpaque()
924 */
Chris Lattner17cf05b2011-07-14 16:20:28 +0000925LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
926
Gregory Szorc34c863a2012-03-21 03:54:29 +0000927/**
928 * @}
929 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000930
Gregory Szorc34c863a2012-03-21 03:54:29 +0000931/**
932 * @defgroup LLVMCCoreTypeSequential Sequential Types
933 *
934 * Sequential types represents "arrays" of types. This is a super class
935 * for array, vector, and pointer types.
936 *
937 * @{
938 */
939
940/**
941 * Obtain the type of elements within a sequential type.
942 *
943 * This works on array, vector, and pointer types.
944 *
945 * @see llvm::SequentialType::getElementType()
946 */
947LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
948
949/**
950 * Create a fixed size array type that refers to a specific type.
951 *
952 * The created type will exist in the context that its element type
953 * exists in.
954 *
955 * @see llvm::ArrayType::get()
956 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000957LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000958
959/**
960 * Obtain the length of an array type.
961 *
962 * This only works on types that represent arrays.
963 *
964 * @see llvm::ArrayType::getNumElements()
965 */
966unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
967
968/**
969 * Create a pointer type that points to a defined type.
970 *
971 * The created type will exist in the context that its pointee type
972 * exists in.
973 *
974 * @see llvm::PointerType::get()
975 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000976LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000977
978/**
979 * Obtain the address space of a pointer type.
980 *
981 * This only works on types that represent pointers.
982 *
983 * @see llvm::PointerType::getAddressSpace()
984 */
985unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
986
987/**
988 * Create a vector type that contains a defined type and has a specific
989 * number of elements.
990 *
991 * The created type will exist in the context thats its element type
992 * exists in.
993 *
994 * @see llvm::VectorType::get()
995 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000996LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000997
Gregory Szorc34c863a2012-03-21 03:54:29 +0000998/**
999 * Obtain the number of elements in a vector type.
1000 *
1001 * This only works on types that represent vectors.
1002 *
1003 * @see llvm::VectorType::getNumElements()
1004 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001005unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1006
Gregory Szorc34c863a2012-03-21 03:54:29 +00001007/**
1008 * @}
1009 */
1010
1011/**
1012 * @defgroup LLVMCCoreTypeOther Other Types
1013 *
1014 * @{
1015 */
1016
1017/**
1018 * Create a void type in a context.
1019 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001020LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001021
1022/**
1023 * Create a label type in a context.
1024 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001025LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001026
1027/**
1028 * Create a X86 MMX type in a context.
1029 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001030LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001031
Gregory Szorc34c863a2012-03-21 03:54:29 +00001032/**
1033 * These are similar to the above functions except they operate on the
1034 * global context.
1035 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001036LLVMTypeRef LLVMVoidType(void);
1037LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001038LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001039
Gregory Szorc34c863a2012-03-21 03:54:29 +00001040/**
1041 * @}
1042 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001043
Gregory Szorc34c863a2012-03-21 03:54:29 +00001044/**
1045 * @}
1046 */
1047
1048/**
1049 * @defgroup LLVMCCoreValues Values
1050 *
1051 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001052 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001053 *
1054 * LLVMValueRef essentially represents llvm::Value. There is a rich
1055 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001056 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001057 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001058 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001059 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1060 * functions are defined by a macro, so it isn't obvious which are
1061 * available by looking at the Doxygen source code. Instead, look at the
1062 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1063 * of value names given. These value names also correspond to classes in
1064 * the llvm::Value hierarchy.
1065 *
1066 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001067 */
1068
Gordon Henriksen29e38942008-12-19 18:39:45 +00001069#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1070 macro(Argument) \
1071 macro(BasicBlock) \
1072 macro(InlineAsm) \
1073 macro(User) \
1074 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001075 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001076 macro(ConstantAggregateZero) \
1077 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001078 macro(ConstantDataSequential) \
1079 macro(ConstantDataArray) \
1080 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001081 macro(ConstantExpr) \
1082 macro(ConstantFP) \
1083 macro(ConstantInt) \
1084 macro(ConstantPointerNull) \
1085 macro(ConstantStruct) \
David Majnemerf0f224d2015-11-11 21:57:16 +00001086 macro(ConstantTokenNone) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001087 macro(ConstantVector) \
1088 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001089 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001090 macro(GlobalObject) \
1091 macro(Function) \
1092 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001093 macro(UndefValue) \
1094 macro(Instruction) \
1095 macro(BinaryOperator) \
1096 macro(CallInst) \
1097 macro(IntrinsicInst) \
1098 macro(DbgInfoIntrinsic) \
1099 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001100 macro(MemIntrinsic) \
1101 macro(MemCpyInst) \
1102 macro(MemMoveInst) \
1103 macro(MemSetInst) \
1104 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001105 macro(FCmpInst) \
1106 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001107 macro(ExtractElementInst) \
1108 macro(GetElementPtrInst) \
1109 macro(InsertElementInst) \
1110 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001111 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001112 macro(PHINode) \
1113 macro(SelectInst) \
1114 macro(ShuffleVectorInst) \
1115 macro(StoreInst) \
1116 macro(TerminatorInst) \
1117 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001118 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001119 macro(InvokeInst) \
1120 macro(ReturnInst) \
1121 macro(SwitchInst) \
1122 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001123 macro(ResumeInst) \
David Majnemer654e1302015-07-31 17:58:14 +00001124 macro(CleanupReturnInst) \
1125 macro(CatchReturnInst) \
David Majnemer8a1c45d2015-12-12 05:38:55 +00001126 macro(FuncletPadInst) \
1127 macro(CatchPadInst) \
1128 macro(CleanupPadInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001129 macro(UnaryInstruction) \
1130 macro(AllocaInst) \
1131 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001132 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001133 macro(BitCastInst) \
1134 macro(FPExtInst) \
1135 macro(FPToSIInst) \
1136 macro(FPToUIInst) \
1137 macro(FPTruncInst) \
1138 macro(IntToPtrInst) \
1139 macro(PtrToIntInst) \
1140 macro(SExtInst) \
1141 macro(SIToFPInst) \
1142 macro(TruncInst) \
1143 macro(UIToFPInst) \
1144 macro(ZExtInst) \
1145 macro(ExtractValueInst) \
1146 macro(LoadInst) \
1147 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001148
Gregory Szorc34c863a2012-03-21 03:54:29 +00001149/**
1150 * @defgroup LLVMCCoreValueGeneral General APIs
1151 *
1152 * Functions in this section work on all LLVMValueRef instances,
1153 * regardless of their sub-type. They correspond to functions available
1154 * on llvm::Value.
1155 *
1156 * @{
1157 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001158
Gregory Szorc34c863a2012-03-21 03:54:29 +00001159/**
1160 * Obtain the type of a value.
1161 *
1162 * @see llvm::Value::getType()
1163 */
1164LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1165
1166/**
1167 * Obtain the string name of a value.
1168 *
1169 * @see llvm::Value::getName()
1170 */
1171const char *LLVMGetValueName(LLVMValueRef Val);
1172
1173/**
1174 * Set the string name of a value.
1175 *
1176 * @see llvm::Value::setName()
1177 */
1178void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1179
1180/**
1181 * Dump a representation of a value to stderr.
1182 *
1183 * @see llvm::Value::dump()
1184 */
1185void LLVMDumpValue(LLVMValueRef Val);
1186
1187/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001188 * Return a string representation of the value. Use
1189 * LLVMDisposeMessage to free the string.
1190 *
1191 * @see llvm::Value::print()
1192 */
1193char *LLVMPrintValueToString(LLVMValueRef Val);
1194
1195/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001196 * Replace all uses of a value with another one.
1197 *
1198 * @see llvm::Value::replaceAllUsesWith()
1199 */
1200void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1201
1202/**
Amaury Sechet1c395072016-01-18 01:06:52 +00001203 * Determine whether the specified value instance is constant.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001204 */
1205LLVMBool LLVMIsConstant(LLVMValueRef Val);
1206
1207/**
1208 * Determine whether a value instance is undefined.
1209 */
1210LLVMBool LLVMIsUndef(LLVMValueRef Val);
1211
1212/**
1213 * Convert value instances between types.
1214 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001215 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001216 * series of functions allows you to cast an instance to a specific
1217 * type.
1218 *
1219 * If the cast is not valid for the specified type, NULL is returned.
1220 *
1221 * @see llvm::dyn_cast_or_null<>
1222 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001223#define LLVM_DECLARE_VALUE_CAST(name) \
1224 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1225LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1226
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001227LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1228LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1229
Gregory Szorc34c863a2012-03-21 03:54:29 +00001230/**
1231 * @}
1232 */
1233
1234/**
1235 * @defgroup LLVMCCoreValueUses Usage
1236 *
1237 * This module defines functions that allow you to inspect the uses of a
1238 * LLVMValueRef.
1239 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001240 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001241 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1242 * llvm::User and llvm::Value.
1243 *
1244 * @{
1245 */
1246
1247/**
1248 * Obtain the first use of a value.
1249 *
1250 * Uses are obtained in an iterator fashion. First, call this function
1251 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001252 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001253 * LLVMGetNextUse() returns NULL.
1254 *
1255 * @see llvm::Value::use_begin()
1256 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001257LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001258
1259/**
1260 * Obtain the next use of a value.
1261 *
1262 * This effectively advances the iterator. It returns NULL if you are on
1263 * the final use and no more are available.
1264 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001265LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001266
1267/**
1268 * Obtain the user value for a user.
1269 *
1270 * The returned value corresponds to a llvm::User type.
1271 *
1272 * @see llvm::Use::getUser()
1273 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001274LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001275
1276/**
1277 * Obtain the value this use corresponds to.
1278 *
1279 * @see llvm::Use::get().
1280 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001281LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001282
Gregory Szorc34c863a2012-03-21 03:54:29 +00001283/**
1284 * @}
1285 */
1286
1287/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001288 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001289 *
1290 * Function in this group pertain to LLVMValueRef instances that descent
1291 * from llvm::User. This includes constants, instructions, and
1292 * operators.
1293 *
1294 * @{
1295 */
1296
1297/**
1298 * Obtain an operand at a specific index in a llvm::User value.
1299 *
1300 * @see llvm::User::getOperand()
1301 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001302LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001303
1304/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001305 * Obtain the use of an operand at a specific index in a llvm::User value.
1306 *
1307 * @see llvm::User::getOperandUse()
1308 */
1309LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1310
1311/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001312 * Set an operand at a specific index in a llvm::User value.
1313 *
1314 * @see llvm::User::setOperand()
1315 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001316void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001317
1318/**
1319 * Obtain the number of operands in a llvm::User value.
1320 *
1321 * @see llvm::User::getNumOperands()
1322 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001323int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001324
Gregory Szorc34c863a2012-03-21 03:54:29 +00001325/**
1326 * @}
1327 */
1328
1329/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001330 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001331 *
1332 * This section contains APIs for interacting with LLVMValueRef that
1333 * correspond to llvm::Constant instances.
1334 *
1335 * These functions will work for any LLVMValueRef in the llvm::Constant
1336 * class hierarchy.
1337 *
1338 * @{
1339 */
1340
1341/**
1342 * Obtain a constant value referring to the null instance of a type.
1343 *
1344 * @see llvm::Constant::getNullValue()
1345 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001346LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001347
1348/**
1349 * Obtain a constant value referring to the instance of a type
1350 * consisting of all ones.
1351 *
1352 * This is only valid for integer types.
1353 *
1354 * @see llvm::Constant::getAllOnesValue()
1355 */
1356LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1357
1358/**
1359 * Obtain a constant value referring to an undefined value of a type.
1360 *
1361 * @see llvm::UndefValue::get()
1362 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001363LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001364
1365/**
1366 * Determine whether a value instance is null.
1367 *
1368 * @see llvm::Constant::isNullValue()
1369 */
Chris Lattner25963c62010-01-09 22:27:07 +00001370LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001371
1372/**
1373 * Obtain a constant that is a constant pointer pointing to NULL for a
1374 * specified type.
1375 */
Chris Lattner7f318242009-07-06 17:29:59 +00001376LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001377
Gregory Szorc34c863a2012-03-21 03:54:29 +00001378/**
1379 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1380 *
1381 * Functions in this group model LLVMValueRef instances that correspond
1382 * to constants referring to scalar types.
1383 *
1384 * For integer types, the LLVMTypeRef parameter should correspond to a
1385 * llvm::IntegerType instance and the returned LLVMValueRef will
1386 * correspond to a llvm::ConstantInt.
1387 *
1388 * For floating point types, the LLVMTypeRef returned corresponds to a
1389 * llvm::ConstantFP.
1390 *
1391 * @{
1392 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001393
Gregory Szorc34c863a2012-03-21 03:54:29 +00001394/**
1395 * Obtain a constant value for an integer type.
1396 *
1397 * The returned value corresponds to a llvm::ConstantInt.
1398 *
1399 * @see llvm::ConstantInt::get()
1400 *
1401 * @param IntTy Integer type to obtain value of.
1402 * @param N The value the returned instance should refer to.
1403 * @param SignExtend Whether to sign extend the produced value.
1404 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001405LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001406 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001407
1408/**
1409 * Obtain a constant value for an integer of arbitrary precision.
1410 *
1411 * @see llvm::ConstantInt::get()
1412 */
Chris Lattner4329e072010-11-23 02:47:22 +00001413LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1414 unsigned NumWords,
1415 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001416
1417/**
1418 * Obtain a constant value for an integer parsed from a string.
1419 *
1420 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1421 * string's length is available, it is preferred to call that function
1422 * instead.
1423 *
1424 * @see llvm::ConstantInt::get()
1425 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001426LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1427 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001428
1429/**
1430 * Obtain a constant value for an integer parsed from a string with
1431 * specified length.
1432 *
1433 * @see llvm::ConstantInt::get()
1434 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001435LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1436 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001437
1438/**
1439 * Obtain a constant value referring to a double floating point value.
1440 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001441LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001442
1443/**
1444 * Obtain a constant for a floating point value parsed from a string.
1445 *
1446 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1447 * should be used if the input string's length is known.
1448 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001449LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001450
1451/**
1452 * Obtain a constant for a floating point value parsed from a string.
1453 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001454LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1455 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001456
1457/**
1458 * Obtain the zero extended value for an integer constant value.
1459 *
1460 * @see llvm::ConstantInt::getZExtValue()
1461 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001462unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001463
1464/**
1465 * Obtain the sign extended value for an integer constant value.
1466 *
1467 * @see llvm::ConstantInt::getSExtValue()
1468 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001469long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001470
Gregory Szorc34c863a2012-03-21 03:54:29 +00001471/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001472 * Obtain the double value for an floating point constant value.
1473 * losesInfo indicates if some precision was lost in the conversion.
1474 *
1475 * @see llvm::ConstantFP::getDoubleValue
1476 */
1477double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1478
1479/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001480 * @}
1481 */
1482
1483/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001484 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1485 *
1486 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001487 *
1488 * @{
1489 */
1490
1491/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001492 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001493 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001494 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001495 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001496LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001497 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001498
1499/**
1500 * Create a ConstantDataSequential with string content in the global context.
1501 *
1502 * This is the same as LLVMConstStringInContext except it operates on the
1503 * global context.
1504 *
1505 * @see LLVMConstStringInContext()
1506 * @see llvm::ConstantDataArray::getString()
1507 */
1508LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1509 LLVMBool DontNullTerminate);
1510
1511/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001512 * Returns true if the specified constant is an array of i8.
1513 *
1514 * @see ConstantDataSequential::getAsString()
1515 */
1516LLVMBool LLVMIsConstantString(LLVMValueRef c);
1517
1518/**
1519 * Get the given constant data sequential as a string.
1520 *
1521 * @see ConstantDataSequential::getAsString()
1522 */
1523const char *LLVMGetAsString(LLVMValueRef c, size_t* out);
1524
1525/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001526 * Create an anonymous ConstantStruct with the specified values.
1527 *
1528 * @see llvm::ConstantStruct::getAnon()
1529 */
1530LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001531 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001532 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001533
Gregory Szorc52d26602012-03-21 07:28:27 +00001534/**
1535 * Create a ConstantStruct in the global Context.
1536 *
1537 * This is the same as LLVMConstStructInContext except it operates on the
1538 * global Context.
1539 *
1540 * @see LLVMConstStructInContext()
1541 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001542LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001543 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001544
1545/**
1546 * Create a ConstantArray from values.
1547 *
1548 * @see llvm::ConstantArray::get()
1549 */
1550LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1551 LLVMValueRef *ConstantVals, unsigned Length);
1552
1553/**
1554 * Create a non-anonymous ConstantStruct from values.
1555 *
1556 * @see llvm::ConstantStruct::get()
1557 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001558LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1559 LLVMValueRef *ConstantVals,
1560 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001561
1562/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001563 * Get an element at specified index as a constant.
1564 *
1565 * @see ConstantDataSequential::getElementAsConstant()
1566 */
1567LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx);
1568
1569/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001570 * Create a ConstantVector from values.
1571 *
1572 * @see llvm::ConstantVector::get()
1573 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001574LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001575
Gregory Szorc52d26602012-03-21 07:28:27 +00001576/**
1577 * @}
1578 */
1579
1580/**
1581 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1582 *
1583 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1584 *
1585 * @see llvm::ConstantExpr.
1586 *
1587 * @{
1588 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001589LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001590LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001591LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1592LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001593LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1594LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001595LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001596LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1597LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001598LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001599LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001600LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001601LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001602LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1603LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001604LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001605LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001606LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1607LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001608LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001609LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1610LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001611LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001612LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1613LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1614LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1615LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1616LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1617LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1618LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1619LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1620 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1621LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1622 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1623LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1624LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1625LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1626LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1627 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001628LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1629 LLVMValueRef *ConstantIndices,
1630 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001631LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1632LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1633LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1634LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1635LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1636LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1637LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1638LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1639LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1640LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1641LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1642LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001643LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001644LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1645 LLVMTypeRef ToType);
1646LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1647 LLVMTypeRef ToType);
1648LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1649 LLVMTypeRef ToType);
1650LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1651 LLVMTypeRef ToType);
1652LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001653 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001654LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001655LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1656 LLVMValueRef ConstantIfTrue,
1657 LLVMValueRef ConstantIfFalse);
1658LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1659 LLVMValueRef IndexConstant);
1660LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1661 LLVMValueRef ElementValueConstant,
1662 LLVMValueRef IndexConstant);
1663LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1664 LLVMValueRef VectorBConstant,
1665 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001666LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1667 unsigned NumIdx);
1668LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1669 LLVMValueRef ElementValueConstant,
1670 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001671LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001672 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001673 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001674LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001675
Gregory Szorc52d26602012-03-21 07:28:27 +00001676/**
1677 * @}
1678 */
1679
1680/**
1681 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1682 *
1683 * This group contains functions that operate on global values. Functions in
1684 * this group relate to functions in the llvm::GlobalValue class tree.
1685 *
1686 * @see llvm::GlobalValue
1687 *
1688 * @{
1689 */
1690
Gordon Henriksen265f7802008-03-19 01:11:35 +00001691LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001692LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001693LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1694void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1695const char *LLVMGetSection(LLVMValueRef Global);
1696void LLVMSetSection(LLVMValueRef Global, const char *Section);
1697LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1698void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001699LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1700void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001701LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1702void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001703
1704/**
1705 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1706 *
1707 * Functions in this group only apply to values with alignment, i.e.
1708 * global variables, load and store instructions.
1709 */
1710
1711/**
1712 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001713 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001714 * @see llvm::LoadInst::getAlignment()
1715 * @see llvm::StoreInst::getAlignment()
1716 * @see llvm::GlobalValue::getAlignment()
1717 */
1718unsigned LLVMGetAlignment(LLVMValueRef V);
1719
1720/**
1721 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001722 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001723 * @see llvm::LoadInst::setAlignment()
1724 * @see llvm::StoreInst::setAlignment()
1725 * @see llvm::GlobalValue::setAlignment()
1726 */
1727void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1728
1729/**
Amaury Sechet83550102016-02-14 08:58:49 +00001730 * @}
1731 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001732
Gregory Szorc52d26602012-03-21 07:28:27 +00001733/**
1734 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1735 *
1736 * This group contains functions that operate on global variable values.
1737 *
1738 * @see llvm::GlobalVariable
1739 *
1740 * @{
1741 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001742LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001743LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1744 const char *Name,
1745 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001746LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001747LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1748LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1749LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1750LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001751void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001752LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1753void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001754LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1755void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1756LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1757void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001758LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1759void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1760LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1761void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001762
Gregory Szorc52d26602012-03-21 07:28:27 +00001763/**
1764 * @}
1765 */
1766
1767/**
1768 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1769 *
1770 * This group contains function that operate on global alias values.
1771 *
1772 * @see llvm::GlobalAlias
1773 *
1774 * @{
1775 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001776LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1777 const char *Name);
1778
Gregory Szorc34c863a2012-03-21 03:54:29 +00001779/**
1780 * @}
1781 */
1782
1783/**
1784 * @defgroup LLVMCCoreValueFunction Function values
1785 *
1786 * Functions in this group operate on LLVMValueRef instances that
1787 * correspond to llvm::Function instances.
1788 *
1789 * @see llvm::Function
1790 *
1791 * @{
1792 */
1793
1794/**
1795 * Remove a function from its containing module and deletes it.
1796 *
1797 * @see llvm::Function::eraseFromParent()
1798 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001799void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001800
1801/**
Andrew Wilkins3bdfc1c2015-07-14 01:23:06 +00001802 * Obtain the personality function attached to the function.
1803 *
1804 * @see llvm::Function::getPersonalityFn()
1805 */
1806LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
1807
1808/**
1809 * Set the personality function attached to the function.
1810 *
1811 * @see llvm::Function::setPersonalityFn()
1812 */
1813void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
1814
1815/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001816 * Obtain the ID number from a function instance.
1817 *
1818 * @see llvm::Function::getIntrinsicID()
1819 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001820unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001821
1822/**
1823 * Obtain the calling function of a function.
1824 *
1825 * The returned value corresponds to the LLVMCallConv enumeration.
1826 *
1827 * @see llvm::Function::getCallingConv()
1828 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001829unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001830
1831/**
1832 * Set the calling convention of a function.
1833 *
1834 * @see llvm::Function::setCallingConv()
1835 *
1836 * @param Fn Function to operate on
1837 * @param CC LLVMCallConv to set calling convention to
1838 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001839void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001840
1841/**
1842 * Obtain the name of the garbage collector to use during code
1843 * generation.
1844 *
1845 * @see llvm::Function::getGC()
1846 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001847const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001848
1849/**
1850 * Define the garbage collector to use during code generation.
1851 *
1852 * @see llvm::Function::setGC()
1853 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001854void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001855
1856/**
1857 * Add an attribute to a function.
1858 *
1859 * @see llvm::Function::addAttribute()
1860 */
Duncan Sands7374a012009-05-06 12:21:17 +00001861void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001862
1863/**
Nick Lewyckyc3890d22015-07-29 22:32:47 +00001864 * Add a target-dependent attribute to a function
Tom Stellarde8f35e12013-04-16 23:12:43 +00001865 * @see llvm::AttrBuilder::addAttribute()
1866 */
1867void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1868 const char *V);
1869
1870/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001871 * Obtain an attribute from a function.
1872 *
1873 * @see llvm::Function::getAttributes()
1874 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001875LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001876
1877/**
1878 * Remove an attribute from a function.
1879 */
Duncan Sands7374a012009-05-06 12:21:17 +00001880void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001881
Gregory Szorc34c863a2012-03-21 03:54:29 +00001882/**
1883 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1884 *
1885 * Functions in this group relate to arguments/parameters on functions.
1886 *
1887 * Functions in this group expect LLVMValueRef instances that correspond
1888 * to llvm::Function instances.
1889 *
1890 * @{
1891 */
1892
1893/**
1894 * Obtain the number of parameters in a function.
1895 *
1896 * @see llvm::Function::arg_size()
1897 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001898unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001899
1900/**
1901 * Obtain the parameters in a function.
1902 *
1903 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1904 * at least LLVMCountParams() long. This array will be filled with
1905 * LLVMValueRef instances which correspond to the parameters the
1906 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1907 * instance.
1908 *
1909 * @see llvm::Function::arg_begin()
1910 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001911void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001912
1913/**
1914 * Obtain the parameter at the specified index.
1915 *
1916 * Parameters are indexed from 0.
1917 *
1918 * @see llvm::Function::arg_begin()
1919 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001920LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001921
1922/**
1923 * Obtain the function to which this argument belongs.
1924 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001925 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00001926 * that corresponds to a llvm::Attribute.
1927 *
1928 * The returned LLVMValueRef is the llvm::Function to which this
1929 * argument belongs.
1930 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001931LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001932
1933/**
1934 * Obtain the first parameter to a function.
1935 *
1936 * @see llvm::Function::arg_begin()
1937 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001938LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001939
1940/**
1941 * Obtain the last parameter to a function.
1942 *
1943 * @see llvm::Function::arg_end()
1944 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001945LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001946
1947/**
1948 * Obtain the next parameter to a function.
1949 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001950 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00001951 * actually a wrapped iterator) and obtains the next parameter from the
1952 * underlying iterator.
1953 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001954LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001955
1956/**
1957 * Obtain the previous parameter to a function.
1958 *
1959 * This is the opposite of LLVMGetNextParam().
1960 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001961LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001962
1963/**
1964 * Add an attribute to a function argument.
1965 *
1966 * @see llvm::Argument::addAttr()
1967 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001968void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001969
1970/**
1971 * Remove an attribute from a function argument.
1972 *
1973 * @see llvm::Argument::removeAttr()
1974 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001975void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001976
1977/**
1978 * Get an attribute from a function argument.
1979 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001980LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001981
1982/**
1983 * Set the alignment for a function parameter.
1984 *
1985 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00001986 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001987 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00001988void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00001989
Gregory Szorc34c863a2012-03-21 03:54:29 +00001990/**
1991 * @}
1992 */
1993
1994/**
1995 * @}
1996 */
1997
1998/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001999 * @}
2000 */
2001
2002/**
2003 * @}
2004 */
2005
2006/**
2007 * @defgroup LLVMCCoreValueMetadata Metadata
2008 *
2009 * @{
2010 */
2011
2012/**
2013 * Obtain a MDString value from a context.
2014 *
2015 * The returned instance corresponds to the llvm::MDString class.
2016 *
2017 * The instance is specified by string data of a specified length. The
2018 * string content is copied, so the backing memory can be freed after
2019 * this function returns.
2020 */
2021LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2022 unsigned SLen);
2023
2024/**
2025 * Obtain a MDString value from the global context.
2026 */
2027LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2028
2029/**
2030 * Obtain a MDNode value from a context.
2031 *
2032 * The returned value corresponds to the llvm::MDNode class.
2033 */
2034LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2035 unsigned Count);
2036
2037/**
2038 * Obtain a MDNode value from the global context.
2039 */
2040LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2041
2042/**
2043 * Obtain the underlying string from a MDString value.
2044 *
2045 * @param V Instance to obtain string from.
2046 * @param Len Memory address which will hold length of returned string.
2047 * @return String data in MDString.
2048 */
2049const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2050
2051/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002052 * Obtain the number of operands from an MDNode value.
2053 *
2054 * @param V MDNode to get number of operands from.
2055 * @return Number of operands of the MDNode.
2056 */
2057unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2058
2059/**
2060 * Obtain the given MDNode's operands.
2061 *
2062 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2063 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2064 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2065 * MDNode's operands.
2066 *
2067 * @param V MDNode to get the operands from.
2068 * @param Dest Destination array for operands.
2069 */
2070void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2071
2072/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002073 * @}
2074 */
2075
2076/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002077 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2078 *
2079 * A basic block represents a single entry single exit section of code.
2080 * Basic blocks contain a list of instructions which form the body of
2081 * the block.
2082 *
2083 * Basic blocks belong to functions. They have the type of label.
2084 *
2085 * Basic blocks are themselves values. However, the C API models them as
2086 * LLVMBasicBlockRef.
2087 *
2088 * @see llvm::BasicBlock
2089 *
2090 * @{
2091 */
2092
2093/**
2094 * Convert a basic block instance to a value type.
2095 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002096LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002097
2098/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002099 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002100 */
Chris Lattner25963c62010-01-09 22:27:07 +00002101LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002102
2103/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002104 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002105 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002106LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002107
2108/**
Amaury Secheta82042e2016-02-09 22:36:41 +00002109 * Obtain the string name of a basic block.
2110 */
2111const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2112
2113/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002114 * Obtain the function to which a basic block belongs.
2115 *
2116 * @see llvm::BasicBlock::getParent()
2117 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002118LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002119
2120/**
2121 * Obtain the terminator instruction for a basic block.
2122 *
2123 * If the basic block does not have a terminator (it is not well-formed
2124 * if it doesn't), then NULL is returned.
2125 *
2126 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2127 *
2128 * @see llvm::BasicBlock::getTerminator()
2129 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002130LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002131
2132/**
2133 * Obtain the number of basic blocks in a function.
2134 *
2135 * @param Fn Function value to operate on.
2136 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002137unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002138
2139/**
2140 * Obtain all of the basic blocks in a function.
2141 *
2142 * This operates on a function value. The BasicBlocks parameter is a
2143 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2144 * LLVMCountBasicBlocks() in length. This array is populated with
2145 * LLVMBasicBlockRef instances.
2146 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002147void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002148
2149/**
2150 * Obtain the first basic block in a function.
2151 *
2152 * The returned basic block can be used as an iterator. You will likely
2153 * eventually call into LLVMGetNextBasicBlock() with it.
2154 *
2155 * @see llvm::Function::begin()
2156 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002157LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002158
2159/**
2160 * Obtain the last basic block in a function.
2161 *
2162 * @see llvm::Function::end()
2163 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002164LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002165
2166/**
2167 * Advance a basic block iterator.
2168 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002169LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002170
2171/**
2172 * Go backwards in a basic block iterator.
2173 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002174LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002175
2176/**
2177 * Obtain the basic block that corresponds to the entry point of a
2178 * function.
2179 *
2180 * @see llvm::Function::getEntryBlock()
2181 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002182LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002183
Gregory Szorc34c863a2012-03-21 03:54:29 +00002184/**
2185 * Append a basic block to the end of a function.
2186 *
2187 * @see llvm::BasicBlock::Create()
2188 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002189LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2190 LLVMValueRef Fn,
2191 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002192
2193/**
2194 * Append a basic block to the end of a function using the global
2195 * context.
2196 *
2197 * @see llvm::BasicBlock::Create()
2198 */
2199LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2200
2201/**
2202 * Insert a basic block in a function before another basic block.
2203 *
2204 * The function to add to is determined by the function of the
2205 * passed basic block.
2206 *
2207 * @see llvm::BasicBlock::Create()
2208 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002209LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2210 LLVMBasicBlockRef BB,
2211 const char *Name);
2212
Gregory Szorc34c863a2012-03-21 03:54:29 +00002213/**
2214 * Insert a basic block in a function using the global context.
2215 *
2216 * @see llvm::BasicBlock::Create()
2217 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002218LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2219 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002220
2221/**
2222 * Remove a basic block from a function and delete it.
2223 *
2224 * This deletes the basic block from its containing function and deletes
2225 * the basic block itself.
2226 *
2227 * @see llvm::BasicBlock::eraseFromParent()
2228 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002229void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002230
2231/**
2232 * Remove a basic block from a function.
2233 *
2234 * This deletes the basic block from its containing function but keep
2235 * the basic block alive.
2236 *
2237 * @see llvm::BasicBlock::removeFromParent()
2238 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002239void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002240
Gregory Szorc34c863a2012-03-21 03:54:29 +00002241/**
2242 * Move a basic block to before another one.
2243 *
2244 * @see llvm::BasicBlock::moveBefore()
2245 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002246void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002247
2248/**
2249 * Move a basic block to after another one.
2250 *
2251 * @see llvm::BasicBlock::moveAfter()
2252 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002253void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2254
Gregory Szorc34c863a2012-03-21 03:54:29 +00002255/**
2256 * Obtain the first instruction in a basic block.
2257 *
2258 * The returned LLVMValueRef corresponds to a llvm::Instruction
2259 * instance.
2260 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002261LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002262
2263/**
2264 * Obtain the last instruction in a basic block.
2265 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002266 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002267 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002268LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002269
Gregory Szorc34c863a2012-03-21 03:54:29 +00002270/**
2271 * @}
2272 */
2273
2274/**
2275 * @defgroup LLVMCCoreValueInstruction Instructions
2276 *
2277 * Functions in this group relate to the inspection and manipulation of
2278 * individual instructions.
2279 *
2280 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2281 * class has a large number of descendents. llvm::Instruction is a
2282 * llvm::Value and in the C API, instructions are modeled by
2283 * LLVMValueRef.
2284 *
2285 * This group also contains sub-groups which operate on specific
2286 * llvm::Instruction types, e.g. llvm::CallInst.
2287 *
2288 * @{
2289 */
2290
2291/**
2292 * Determine whether an instruction has any metadata attached.
2293 */
2294int LLVMHasMetadata(LLVMValueRef Val);
2295
2296/**
2297 * Return metadata associated with an instruction value.
2298 */
2299LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2300
2301/**
2302 * Set metadata associated with an instruction value.
2303 */
2304void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2305
2306/**
2307 * Obtain the basic block to which an instruction belongs.
2308 *
2309 * @see llvm::Instruction::getParent()
2310 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002311LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002312
2313/**
2314 * Obtain the instruction that occurs after the one specified.
2315 *
2316 * The next instruction will be from the same basic block.
2317 *
2318 * If this is the last instruction in a basic block, NULL will be
2319 * returned.
2320 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002321LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002322
2323/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002324 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002325 *
2326 * If the instruction is the first instruction in a basic block, NULL
2327 * will be returned.
2328 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002329LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002330
2331/**
2332 * Remove and delete an instruction.
2333 *
2334 * The instruction specified is removed from its containing building
Amaury Sechet2f432082016-02-11 21:37:54 +00002335 * block but is kept alive.
2336 *
2337 * @see llvm::Instruction::removeFromParent()
2338 */
2339void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
2340
2341/**
2342 * Remove and delete an instruction.
2343 *
2344 * The instruction specified is removed from its containing building
Gregory Szorc34c863a2012-03-21 03:54:29 +00002345 * block and then deleted.
2346 *
2347 * @see llvm::Instruction::eraseFromParent()
2348 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002349void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002350
2351/**
2352 * Obtain the code opcode for an individual instruction.
2353 *
2354 * @see llvm::Instruction::getOpCode()
2355 */
Eric Christophera6b96002015-12-18 01:46:52 +00002356LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002357
2358/**
2359 * Obtain the predicate of an instruction.
2360 *
2361 * This is only valid for instructions that correspond to llvm::ICmpInst
2362 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2363 *
2364 * @see llvm::ICmpInst::getPredicate()
2365 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002366LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002367
Gregory Szorc34c863a2012-03-21 03:54:29 +00002368/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00002369 * Obtain the float predicate of an instruction.
2370 *
2371 * This is only valid for instructions that correspond to llvm::FCmpInst
2372 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
2373 *
2374 * @see llvm::FCmpInst::getPredicate()
2375 */
2376LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
2377
2378/**
Peter Zotovaff492c2014-10-17 01:02:34 +00002379 * Create a copy of 'this' instruction that is identical in all ways
2380 * except the following:
2381 * * The instruction has no parent
2382 * * The instruction has no name
2383 *
2384 * @see llvm::Instruction::clone()
2385 */
2386LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
2387
2388/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002389 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2390 *
2391 * Functions in this group apply to instructions that refer to call
2392 * sites and invocations. These correspond to C++ types in the
2393 * llvm::CallInst class tree.
2394 *
2395 * @{
2396 */
2397
2398/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002399 * Obtain the argument count for a call instruction.
2400 *
2401 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2402 * llvm::InvokeInst.
2403 *
2404 * @see llvm::CallInst::getNumArgOperands()
2405 * @see llvm::InvokeInst::getNumArgOperands()
2406 */
2407unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
2408
2409/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002410 * Set the calling convention for a call instruction.
2411 *
2412 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2413 * llvm::InvokeInst.
2414 *
2415 * @see llvm::CallInst::setCallingConv()
2416 * @see llvm::InvokeInst::setCallingConv()
2417 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002418void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002419
2420/**
2421 * Obtain the calling convention for a call instruction.
2422 *
2423 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2424 * usage.
2425 *
2426 * @see LLVMSetInstructionCallConv()
2427 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002428unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002429
2430
Devang Patel4c758ea2008-09-25 21:00:45 +00002431void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002432void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002433 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002434void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002435 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002436
Gregory Szorc34c863a2012-03-21 03:54:29 +00002437/**
Amaury Sechet5c7b3af2016-02-10 00:09:37 +00002438 * Obtain the pointer to the function invoked by this instruction.
2439 *
2440 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2441 * llvm::InvokeInst.
2442 *
2443 * @see llvm::CallInst::getCalledValue()
2444 * @see llvm::InvokeInst::getCalledValue()
2445 */
2446LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
2447
2448/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002449 * Obtain whether a call instruction is a tail call.
2450 *
2451 * This only works on llvm::CallInst instructions.
2452 *
2453 * @see llvm::CallInst::isTailCall()
2454 */
Chris Lattner25963c62010-01-09 22:27:07 +00002455LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002456
2457/**
2458 * Set whether a call instruction is a tail call.
2459 *
2460 * This only works on llvm::CallInst instructions.
2461 *
2462 * @see llvm::CallInst::setTailCall()
2463 */
Chris Lattner25963c62010-01-09 22:27:07 +00002464void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002465
Gregory Szorc34c863a2012-03-21 03:54:29 +00002466/**
2467 * @}
2468 */
2469
2470/**
Peter Zotov2481c752014-10-28 19:46:56 +00002471 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
2472 *
2473 * Functions in this group only apply to instructions that map to
2474 * llvm::TerminatorInst instances.
2475 *
2476 * @{
2477 */
2478
2479/**
2480 * Return the number of successors that this terminator has.
2481 *
2482 * @see llvm::TerminatorInst::getNumSuccessors
2483 */
2484unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
2485
2486/**
2487 * Return the specified successor.
2488 *
2489 * @see llvm::TerminatorInst::getSuccessor
2490 */
2491LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
2492
2493/**
2494 * Update the specified successor to point at the provided block.
2495 *
2496 * @see llvm::TerminatorInst::setSuccessor
2497 */
2498void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
2499
2500/**
2501 * Return if a branch is conditional.
2502 *
2503 * This only works on llvm::BranchInst instructions.
2504 *
2505 * @see llvm::BranchInst::isConditional
2506 */
2507LLVMBool LLVMIsConditional(LLVMValueRef Branch);
2508
2509/**
2510 * Return the condition of a branch instruction.
2511 *
2512 * This only works on llvm::BranchInst instructions.
2513 *
2514 * @see llvm::BranchInst::getCondition
2515 */
2516LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
2517
2518/**
2519 * Set the condition of a branch instruction.
2520 *
2521 * This only works on llvm::BranchInst instructions.
2522 *
2523 * @see llvm::BranchInst::setCondition
2524 */
2525void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
2526
2527/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002528 * Obtain the default destination basic block of a switch instruction.
2529 *
2530 * This only works on llvm::SwitchInst instructions.
2531 *
2532 * @see llvm::SwitchInst::getDefaultDest()
2533 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002534LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2535
Gregory Szorc34c863a2012-03-21 03:54:29 +00002536/**
Peter Zotov2481c752014-10-28 19:46:56 +00002537 * @}
2538 */
2539
2540/**
Amaury Sechet1dcf5772016-02-09 22:50:53 +00002541 * @defgroup LLVMCCoreValueInstructionAlloca Allocas
2542 *
2543 * Functions in this group only apply to instructions that map to
2544 * llvm::AllocaInst instances.
2545 *
2546 * @{
2547 */
2548
2549/**
2550 * Obtain the type that is being allocated by the alloca instruction.
2551 */
2552LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
2553
2554/**
2555 * @}
2556 */
2557
2558/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002559 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2560 *
2561 * Functions in this group only apply to instructions that map to
2562 * llvm::PHINode instances.
2563 *
2564 * @{
2565 */
2566
2567/**
2568 * Add an incoming value to the end of a PHI list.
2569 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002570void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2571 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002572
2573/**
2574 * Obtain the number of incoming basic blocks to a PHI node.
2575 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002576unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002577
2578/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002579 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002580 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002581LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002582
2583/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002584 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002585 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002586LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002587
Gregory Szorc34c863a2012-03-21 03:54:29 +00002588/**
2589 * @}
2590 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002591
Gregory Szorc34c863a2012-03-21 03:54:29 +00002592/**
Amaury Sechetaad93532016-02-10 00:38:50 +00002593 * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
2594 * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
2595 *
2596 * Functions in this group only apply to instructions that map to
2597 * llvm::ExtractValue and llvm::InsertValue instances.
2598 *
2599 * @{
2600 */
2601
2602/**
2603 * Obtain the number of indices.
2604 */
2605unsigned LLVMGetNumIndices(LLVMValueRef Inst);
2606
2607/**
2608 * Obtain the indices as an array.
2609 */
2610const unsigned *LLVMGetIndices(LLVMValueRef Inst);
2611
2612/**
2613 * @}
2614 */
2615
2616/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002617 * @}
2618 */
2619
2620/**
2621 * @}
2622 */
2623
2624/**
2625 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2626 *
2627 * An instruction builder represents a point within a basic block and is
2628 * the exclusive means of building instructions using the C interface.
2629 *
2630 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002631 */
2632
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002633LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002634LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002635void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2636 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002637void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2638void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002639LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002640void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2641void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002642void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2643 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002644void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2645
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002646/* Metadata */
2647void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2648LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2649void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2650
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002651/* Terminators */
2652LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2653LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002654LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002655 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002656LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2657LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2658 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2659LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2660 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002661LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2662 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002663LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2664 LLVMValueRef *Args, unsigned NumArgs,
2665 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2666 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002667LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
Reid Kleckneref9828f2015-07-16 01:16:39 +00002668 LLVMValueRef PersFn, unsigned NumClauses,
2669 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002670LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002671LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2672
Gordon Henriksen097102c2008-01-01 05:50:53 +00002673/* Add a case to the switch instruction */
2674void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2675 LLVMBasicBlockRef Dest);
2676
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002677/* Add a destination to the indirectbr instruction */
2678void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2679
Bill Wendlingfae14752011-08-12 20:24:12 +00002680/* Add a catch or filter clause to the landingpad instruction */
2681void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2682
2683/* Set the 'cleanup' flag in the landingpad instruction */
2684void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2685
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002686/* Arithmetic */
2687LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2688 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002689LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2690 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002691LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2692 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002693LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2694 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002695LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2696 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002697LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2698 const char *Name);
2699LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2700 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002701LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2702 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002703LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2704 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002705LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2706 const char *Name);
2707LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2708 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002709LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2710 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002711LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2712 const char *Name);
2713LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2714 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002715LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2716 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002717LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2718 const char *Name);
2719LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2720 const char *Name);
2721LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2722 const char *Name);
2723LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2724 const char *Name);
2725LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2726 const char *Name);
2727LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2728 const char *Name);
2729LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2730 const char *Name);
2731LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2732 const char *Name);
2733LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2734 const char *Name);
2735LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2736 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002737LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2738 LLVMValueRef LHS, LLVMValueRef RHS,
2739 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002740LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002741LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2742 const char *Name);
2743LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2744 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002745LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002746LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2747
2748/* Memory */
2749LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2750LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2751 LLVMValueRef Val, const char *Name);
2752LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2753LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2754 LLVMValueRef Val, const char *Name);
2755LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2756LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2757 const char *Name);
2758LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2759LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2760 LLVMValueRef *Indices, unsigned NumIndices,
2761 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002762LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2763 LLVMValueRef *Indices, unsigned NumIndices,
2764 const char *Name);
2765LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2766 unsigned Idx, const char *Name);
2767LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2768 const char *Name);
2769LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2770 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002771LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2772void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Andrew Wilkinsb7362ce2015-08-02 12:16:57 +00002773LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
2774void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002775
2776/* Casts */
2777LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2778 LLVMTypeRef DestTy, const char *Name);
2779LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2780 LLVMTypeRef DestTy, const char *Name);
2781LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2782 LLVMTypeRef DestTy, const char *Name);
2783LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2784 LLVMTypeRef DestTy, const char *Name);
2785LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2786 LLVMTypeRef DestTy, const char *Name);
2787LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2788 LLVMTypeRef DestTy, const char *Name);
2789LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2790 LLVMTypeRef DestTy, const char *Name);
2791LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2792 LLVMTypeRef DestTy, const char *Name);
2793LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2794 LLVMTypeRef DestTy, const char *Name);
2795LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2796 LLVMTypeRef DestTy, const char *Name);
2797LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2798 LLVMTypeRef DestTy, const char *Name);
2799LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2800 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002801LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2802 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002803LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2804 LLVMTypeRef DestTy, const char *Name);
2805LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2806 LLVMTypeRef DestTy, const char *Name);
2807LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2808 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002809LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2810 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002811LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2812 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002813LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002814 LLVMTypeRef DestTy, const char *Name);
2815LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2816 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002817
2818/* Comparisons */
2819LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2820 LLVMValueRef LHS, LLVMValueRef RHS,
2821 const char *Name);
2822LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2823 LLVMValueRef LHS, LLVMValueRef RHS,
2824 const char *Name);
2825
2826/* Miscellaneous instructions */
2827LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2828LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2829 LLVMValueRef *Args, unsigned NumArgs,
2830 const char *Name);
2831LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2832 LLVMValueRef Then, LLVMValueRef Else,
2833 const char *Name);
2834LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2835 const char *Name);
2836LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2837 LLVMValueRef Index, const char *Name);
2838LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2839 LLVMValueRef EltVal, LLVMValueRef Index,
2840 const char *Name);
2841LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2842 LLVMValueRef V2, LLVMValueRef Mask,
2843 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002844LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2845 unsigned Index, const char *Name);
2846LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2847 LLVMValueRef EltVal, unsigned Index,
2848 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002849
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002850LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2851 const char *Name);
2852LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2853 const char *Name);
2854LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2855 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00002856LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2857 LLVMBool singleThread, const char *Name);
2858LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00002859 LLVMValueRef PTR, LLVMValueRef Val,
2860 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00002861 LLVMBool singleThread);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002862
Gregory Szorc34c863a2012-03-21 03:54:29 +00002863/**
2864 * @}
2865 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002866
Gregory Szorc34c863a2012-03-21 03:54:29 +00002867/**
2868 * @defgroup LLVMCCoreModuleProvider Module Providers
2869 *
2870 * @{
2871 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002872
Gregory Szorc34c863a2012-03-21 03:54:29 +00002873/**
2874 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002875 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002876 */
2877LLVMModuleProviderRef
2878LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2879
Gregory Szorc34c863a2012-03-21 03:54:29 +00002880/**
2881 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002882 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002883void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002884
Gregory Szorc34c863a2012-03-21 03:54:29 +00002885/**
2886 * @}
2887 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002888
Gregory Szorc34c863a2012-03-21 03:54:29 +00002889/**
2890 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2891 *
2892 * @{
2893 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002894
Chris Lattner25963c62010-01-09 22:27:07 +00002895LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2896 LLVMMemoryBufferRef *OutMemBuf,
2897 char **OutMessage);
2898LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2899 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00002900LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2901 size_t InputDataLength,
2902 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00002903 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00002904LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2905 size_t InputDataLength,
2906 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00002907const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00002908size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002909void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2910
Gregory Szorc34c863a2012-03-21 03:54:29 +00002911/**
2912 * @}
2913 */
2914
2915/**
2916 * @defgroup LLVMCCorePassRegistry Pass Registry
2917 *
2918 * @{
2919 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002920
2921/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002922 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002923LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002924
Gregory Szorc34c863a2012-03-21 03:54:29 +00002925/**
2926 * @}
2927 */
2928
2929/**
2930 * @defgroup LLVMCCorePassManagers Pass Managers
2931 *
2932 * @{
2933 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002934
2935/** Constructs a new whole-module pass pipeline. This type of pipeline is
2936 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002937 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002938LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002939
2940/** Constructs a new function-by-function pass pipeline over the module
2941 provider. It does not take ownership of the module provider. This type of
2942 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002943 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002944LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2945
2946/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002947LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2948
2949/** Initializes, executes on the provided module, and finalizes all of the
2950 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002951 modified the module, 0 otherwise.
2952 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002953LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002954
2955/** Initializes all of the function passes scheduled in the function pass
2956 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002957 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002958LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002959
2960/** Executes all of the function passes scheduled in the function pass manager
2961 on the provided function. Returns 1 if any of the passes modified the
2962 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002963 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002964LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002965
2966/** Finalizes all of the function passes scheduled in in the function pass
2967 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002968 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002969LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002970
2971/** Frees the memory of a pass pipeline. For function pipelines, does not free
2972 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002973 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002974void LLVMDisposePassManager(LLVMPassManagerRef PM);
2975
Gregory Szorc34c863a2012-03-21 03:54:29 +00002976/**
2977 * @}
2978 */
2979
2980/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00002981 * @defgroup LLVMCCoreThreading Threading
2982 *
2983 * Handle the structures needed to make LLVM safe for multithreading.
2984 *
2985 * @{
2986 */
2987
Chandler Carruth39cd2162014-06-27 15:13:01 +00002988/** Deprecated: Multi-threading can only be enabled/disabled with the compile
2989 time define LLVM_ENABLE_THREADS. This function always returns
2990 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002991LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002992
Chandler Carruth39cd2162014-06-27 15:13:01 +00002993/** Deprecated: Multi-threading can only be enabled/disabled with the compile
2994 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002995void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002996
2997/** Check whether LLVM is executing in thread-safe mode or not.
2998 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002999LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00003000
3001/**
3002 * @}
3003 */
3004
3005/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003006 * @}
3007 */
3008
3009/**
3010 * @}
3011 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003012
Gordon Henriksen76a03742007-09-18 03:18:57 +00003013#ifdef __cplusplus
3014}
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003015#endif
Gordon Henriksen7330acd2007-10-05 23:59:36 +00003016
Eugene Zelenkoffec81c2015-11-04 22:32:32 +00003017#endif /* LLVM_C_CORE_H */