blob: 73bff0b7ec4903b88c902986b0d33b47d2cde99c [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
Chandler Carruth3c57aa42014-03-06 04:13:12 +000018#include "llvm-c/Support.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000019
Evan Cheng2e254d02013-04-04 17:40:53 +000020#ifdef __cplusplus
Gordon Henriksen76a03742007-09-18 03:18:57 +000021extern "C" {
22#endif
23
Gregory Szorc34c863a2012-03-21 03:54:29 +000024/**
25 * @defgroup LLVMC LLVM-C: C interface to LLVM
26 *
27 * This module exposes parts of the LLVM library as a C API.
28 *
29 * @{
30 */
31
32/**
33 * @defgroup LLVMCTransforms Transforms
34 */
35
36/**
37 * @defgroup LLVMCCore Core
38 *
39 * This modules provide an interface to libLLVMCore, which implements
40 * the LLVM intermediate representation as well as other related types
41 * and utilities.
42 *
43 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
44 * parameters must be passed as base types. Despite the declared types, most
45 * of the functions provided operate only on branches of the type hierarchy.
46 * The declared parameter names are descriptive and specify which type is
47 * required. Additionally, each type hierarchy is documented along with the
48 * functions that operate upon it. For more detail, refer to LLVM's C++ code.
Eli Bendersky870d0572012-08-10 18:26:20 +000049 * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
Gregory Szorc34c863a2012-03-21 03:54:29 +000050 * form unwrap<RequiredType>(Param).
51 *
52 * Many exotic languages can interoperate with C code but have a harder time
53 * with C++ due to name mangling. So in addition to C, this interface enables
54 * tools written in such languages.
55 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000056 * @{
57 */
58
59/**
60 * @defgroup LLVMCCoreTypes Types and Enumerations
61 *
62 * @{
63 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000064
65/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000066
67/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000068 * The top-level container for all LLVM global data. See the LLVMContext class.
Owen Anderson6773d382009-07-01 16:58:40 +000069 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000070typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000071
72/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000073 * The top-level container for all other LLVM Intermediate Representation (IR)
Gregory Szorc34c863a2012-03-21 03:54:29 +000074 * objects.
75 *
76 * @see llvm::Module
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000077 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000078typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000079
80/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000081 * Each value in the LLVM IR has a type, an LLVMTypeRef.
82 *
83 * @see llvm::Type
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000084 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000085typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000086
Gregory Szorc34c863a2012-03-21 03:54:29 +000087/**
88 * Represents an individual value in LLVM IR.
89 *
90 * This models llvm::Value.
91 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000092typedef struct LLVMOpaqueValue *LLVMValueRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +000093
94/**
Eli Bendersky870d0572012-08-10 18:26:20 +000095 * Represents a basic block of instructions in LLVM IR.
Gregory Szorc34c863a2012-03-21 03:54:29 +000096 *
97 * This models llvm::BasicBlock.
98 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000099typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +0000100
101/**
102 * Represents an LLVM basic block builder.
103 *
104 * This models llvm::IRBuilder.
105 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000106typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000107
Gregory Szorc34c863a2012-03-21 03:54:29 +0000108/**
109 * Interface used to provide a module to JIT or interpreter.
110 * This is now just a synonym for llvm::Module, but we have to keep using the
111 * different type to keep binary compatibility.
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000112 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000113typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +0000114
Gregory Szorc34c863a2012-03-21 03:54:29 +0000115/** @see llvm::PassManagerBase */
Gordon Henriksen878114b2008-03-16 04:20:44 +0000116typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
117
Gregory Szorc34c863a2012-03-21 03:54:29 +0000118/** @see llvm::PassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +0000119typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
120
Gregory Szorc34c863a2012-03-21 03:54:29 +0000121/**
122 * Used to get the users and usees of a Value.
123 *
124 * @see llvm::Use */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +0000125typedef struct LLVMOpaqueUse *LLVMUseRef;
Chris Lattner40cf28d2009-10-12 04:01:02 +0000126
Tom Stellard1580dc72014-04-16 17:45:04 +0000127
128/**
129 * @see llvm::DiagnosticInfo
130 */
131typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
132
Gordon Henriksen76a03742007-09-18 03:18:57 +0000133typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +0000134 LLVMZExtAttribute = 1<<0,
135 LLVMSExtAttribute = 1<<1,
136 LLVMNoReturnAttribute = 1<<2,
137 LLVMInRegAttribute = 1<<3,
138 LLVMStructRetAttribute = 1<<4,
139 LLVMNoUnwindAttribute = 1<<5,
140 LLVMNoAliasAttribute = 1<<6,
141 LLVMByValAttribute = 1<<7,
142 LLVMNestAttribute = 1<<8,
143 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000144 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000145 LLVMNoInlineAttribute = 1<<11,
146 LLVMAlwaysInlineAttribute = 1<<12,
147 LLVMOptimizeForSizeAttribute = 1<<13,
148 LLVMStackProtectAttribute = 1<<14,
149 LLVMStackProtectReqAttribute = 1<<15,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000150 LLVMAlignment = 31<<16,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000151 LLVMNoCaptureAttribute = 1<<21,
152 LLVMNoRedZoneAttribute = 1<<22,
153 LLVMNoImplicitFloatAttribute = 1<<23,
Jakob Stoklund Olesen74bb06c2010-02-06 01:16:28 +0000154 LLVMNakedAttribute = 1<<24,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000155 LLVMInlineHintAttribute = 1<<25,
Torok Edwin1db48c02011-10-06 12:13:32 +0000156 LLVMStackAlignment = 7<<26,
157 LLVMReturnsTwice = 1 << 29,
158 LLVMUWTable = 1 << 30,
Chandler Carruth44d69d92012-01-25 07:40:15 +0000159 LLVMNonLazyBind = 1 << 31
160
Bill Wendlingd154e2832013-01-23 06:41:41 +0000161 /* FIXME: These attributes are currently not included in the C API as
Nuno Lopesdef4229972012-09-02 14:19:21 +0000162 a temporary measure until the API/ABI impact to the C API is understood
163 and the path forward agreed upon.
Bill Wendlingd154e2832013-01-23 06:41:41 +0000164 LLVMAddressSafety = 1ULL << 32,
Andrea Di Biagio377496b2013-08-23 11:53:55 +0000165 LLVMStackProtectStrongAttribute = 1ULL<<33,
166 LLVMCold = 1ULL << 34,
Reid Klecknera534a382013-12-19 02:14:12 +0000167 LLVMOptimizeNone = 1ULL << 35,
Nick Lewyckyd52b1522014-05-20 01:23:40 +0000168 LLVMInAllocaAttribute = 1ULL << 36,
Tom Roeder44cb65f2014-06-05 19:29:43 +0000169 LLVMNonNullAttribute = 1ULL << 37,
170 LLVMJumpTableAttribute = 1ULL << 38,
Hal Finkelb0407ba2014-07-18 15:51:28 +0000171 LLVMDereferenceableAttribute = 1ULL << 39,
Sanjoy Das31ea6d12015-04-16 20:29:50 +0000172 LLVMDereferenceableOrNullAttribute = 1ULL << 40,
Nuno Lopesdef4229972012-09-02 14:19:21 +0000173 */
Devang Patel4c758ea2008-09-25 21:00:45 +0000174} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000175
176typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000177 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000178 LLVMRet = 1,
179 LLVMBr = 2,
180 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000181 LLVMIndirectBr = 4,
182 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000183 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000184 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000185
Bill Wendlingda52cec2010-02-15 20:53:17 +0000186 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000187 LLVMAdd = 8,
188 LLVMFAdd = 9,
189 LLVMSub = 10,
190 LLVMFSub = 11,
191 LLVMMul = 12,
192 LLVMFMul = 13,
193 LLVMUDiv = 14,
194 LLVMSDiv = 15,
195 LLVMFDiv = 16,
196 LLVMURem = 17,
197 LLVMSRem = 18,
198 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000199
Bill Wendlingda52cec2010-02-15 20:53:17 +0000200 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000201 LLVMShl = 20,
202 LLVMLShr = 21,
203 LLVMAShr = 22,
204 LLVMAnd = 23,
205 LLVMOr = 24,
206 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000207
Bill Wendlingda52cec2010-02-15 20:53:17 +0000208 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000209 LLVMAlloca = 26,
210 LLVMLoad = 27,
211 LLVMStore = 28,
212 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000213
Bill Wendlingda52cec2010-02-15 20:53:17 +0000214 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000215 LLVMTrunc = 30,
216 LLVMZExt = 31,
217 LLVMSExt = 32,
218 LLVMFPToUI = 33,
219 LLVMFPToSI = 34,
220 LLVMUIToFP = 35,
221 LLVMSIToFP = 36,
222 LLVMFPTrunc = 37,
223 LLVMFPExt = 38,
224 LLVMPtrToInt = 39,
225 LLVMIntToPtr = 40,
226 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000227 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000228
Bill Wendlingda52cec2010-02-15 20:53:17 +0000229 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000230 LLVMICmp = 42,
231 LLVMFCmp = 43,
232 LLVMPHI = 44,
233 LLVMCall = 45,
234 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000235 LLVMUserOp1 = 47,
236 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000237 LLVMVAArg = 49,
238 LLVMExtractElement = 50,
239 LLVMInsertElement = 51,
240 LLVMShuffleVector = 52,
241 LLVMExtractValue = 53,
242 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000243
244 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000245 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000246 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000247 LLVMAtomicRMW = 57,
248
249 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000250 LLVMResume = 58,
Bill Wendling0aef16a2012-02-06 21:44:22 +0000251 LLVMLandingPad = 59
Bill Wendling2641d132011-07-27 21:00:28 +0000252
Chris Lattner40cf28d2009-10-12 04:01:02 +0000253} LLVMOpcode;
254
255typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000256 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000257 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000258 LLVMFloatTypeKind, /**< 32 bit floating point type */
259 LLVMDoubleTypeKind, /**< 64 bit floating point type */
260 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
261 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
262 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
263 LLVMLabelTypeKind, /**< Labels */
264 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
265 LLVMFunctionTypeKind, /**< Functions */
266 LLVMStructTypeKind, /**< Structures */
267 LLVMArrayTypeKind, /**< Arrays */
268 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000269 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000270 LLVMMetadataTypeKind, /**< Metadata */
271 LLVMX86_MMXTypeKind /**< X86 MMX */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000272} LLVMTypeKind;
273
274typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000275 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000276 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000277 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
278 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
279 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000280 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000281 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
282 LLVMWeakODRLinkage, /**< Same, but only replaced by something
283 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000284 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
285 LLVMInternalLinkage, /**< Rename collisions when linking (static
286 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000287 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000288 LLVMDLLImportLinkage, /**< Obsolete */
289 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000290 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000291 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000292 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000293 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000294 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000295} LLVMLinkage;
296
297typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000298 LLVMDefaultVisibility, /**< The GV is visible */
299 LLVMHiddenVisibility, /**< The GV is hidden */
300 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000301} LLVMVisibility;
302
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000303typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000304 LLVMDefaultStorageClass = 0,
305 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
306 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
307} LLVMDLLStorageClass;
308
309typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000310 LLVMCCallConv = 0,
311 LLVMFastCallConv = 8,
312 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000313 LLVMWebKitJSCallConv = 12,
314 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000315 LLVMX86StdcallCallConv = 64,
316 LLVMX86FastcallCallConv = 65
317} LLVMCallConv;
318
319typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000320 LLVMIntEQ = 32, /**< equal */
321 LLVMIntNE, /**< not equal */
322 LLVMIntUGT, /**< unsigned greater than */
323 LLVMIntUGE, /**< unsigned greater or equal */
324 LLVMIntULT, /**< unsigned less than */
325 LLVMIntULE, /**< unsigned less or equal */
326 LLVMIntSGT, /**< signed greater than */
327 LLVMIntSGE, /**< signed greater or equal */
328 LLVMIntSLT, /**< signed less than */
329 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000330} LLVMIntPredicate;
331
332typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000333 LLVMRealPredicateFalse, /**< Always false (always folded) */
334 LLVMRealOEQ, /**< True if ordered and equal */
335 LLVMRealOGT, /**< True if ordered and greater than */
336 LLVMRealOGE, /**< True if ordered and greater than or equal */
337 LLVMRealOLT, /**< True if ordered and less than */
338 LLVMRealOLE, /**< True if ordered and less than or equal */
339 LLVMRealONE, /**< True if ordered and operands are unequal */
340 LLVMRealORD, /**< True if ordered (no nans) */
341 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
342 LLVMRealUEQ, /**< True if unordered or equal */
343 LLVMRealUGT, /**< True if unordered or greater than */
344 LLVMRealUGE, /**< True if unordered, greater than, or equal */
345 LLVMRealULT, /**< True if unordered or less than */
346 LLVMRealULE, /**< True if unordered, less than, or equal */
347 LLVMRealUNE, /**< True if unordered or not equal */
348 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000349} LLVMRealPredicate;
350
Bill Wendlingfae14752011-08-12 20:24:12 +0000351typedef enum {
352 LLVMLandingPadCatch, /**< A catch clause */
353 LLVMLandingPadFilter /**< A filter clause */
354} LLVMLandingPadClauseTy;
355
Hans Wennborg5ff71202013-04-16 08:58:59 +0000356typedef enum {
357 LLVMNotThreadLocal = 0,
358 LLVMGeneralDynamicTLSModel,
359 LLVMLocalDynamicTLSModel,
360 LLVMInitialExecTLSModel,
361 LLVMLocalExecTLSModel
362} LLVMThreadLocalMode;
363
Carlo Kokda0ac722013-04-23 13:45:37 +0000364typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000365 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
366 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
367 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000368 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
369 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000370 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000371 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
372 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000373 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000374 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
375 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000376 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000377 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
378 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000379 operations which both read and write
380 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000381 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
382 for loads and Release
383 semantics for stores.
384 Additionally, it guarantees
385 that a total ordering exists
386 between all
387 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000388 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000389} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000390
Carlo Kokda0ac722013-04-23 13:45:37 +0000391typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000392 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
393 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
394 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
395 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
396 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
397 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
398 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
399 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000400 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000401 the old one */
402 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000403 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000404 the old one */
405 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000406 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000407 the old one */
408 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000409 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000410 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000411} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000412
Tom Stellard1580dc72014-04-16 17:45:04 +0000413typedef enum {
414 LLVMDSError,
415 LLVMDSWarning,
416 LLVMDSRemark,
417 LLVMDSNote
418} LLVMDiagnosticSeverity;
419
Gregory Szorc34c863a2012-03-21 03:54:29 +0000420/**
421 * @}
422 */
423
Nick Lewycky0db26542011-05-15 07:20:34 +0000424void LLVMInitializeCore(LLVMPassRegistryRef R);
425
Duncan Sands1cba0a82013-02-17 16:35:51 +0000426/** Deallocate and destroy all ManagedStatic variables.
427 @see llvm::llvm_shutdown
428 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000429void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000430
Gordon Henriksen76a03742007-09-18 03:18:57 +0000431
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000432/*===-- Error handling ----------------------------------------------------===*/
433
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000434char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000435void LLVMDisposeMessage(char *Message);
436
Filip Pizloa535b142013-10-17 01:38:28 +0000437typedef void (*LLVMFatalErrorHandler)(const char *Reason);
438
439/**
440 * Install a fatal error handler. By default, if LLVM detects a fatal error, it
441 * will call exit(1). This may not be appropriate in many contexts. For example,
442 * doing exit(1) will bypass many crash reporting/tracing system tools. This
443 * function allows you to install a callback that will be invoked prior to the
444 * call to exit(1).
445 */
446void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
447
448/**
449 * Reset the fatal error handler. This resets LLVM's fatal error handling
450 * behavior to the default.
451 */
452void LLVMResetFatalErrorHandler(void);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000453
Gregory Szorc34c863a2012-03-21 03:54:29 +0000454/**
Filip Pizloc10ca902013-11-04 02:22:25 +0000455 * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
456 * signals and prints which component of LLVM you were in at the time if the
457 * crash.
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000458 */
Filip Pizloc10ca902013-11-04 02:22:25 +0000459void LLVMEnablePrettyStackTrace(void);
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000460
461/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000462 * @defgroup LLVMCCoreContext Contexts
463 *
464 * Contexts are execution states for the core LLVM IR system.
465 *
466 * Most types are tied to a context instance. Multiple contexts can
467 * exist simultaneously. A single context is not thread safe. However,
468 * different contexts can execute on different threads simultaneously.
469 *
470 * @{
471 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000472
Tom Stellard1580dc72014-04-16 17:45:04 +0000473typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000474typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000475
Gregory Szorc34c863a2012-03-21 03:54:29 +0000476/**
477 * Create a new context.
478 *
479 * Every call to this function should be paired with a call to
480 * LLVMContextDispose() or the context will leak memory.
481 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000482LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000483
484/**
485 * Obtain the global context instance.
486 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000487LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000488
489/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000490 * Set the diagnostic handler for this context.
491 */
492void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
493 LLVMDiagnosticHandler Handler,
494 void *DiagnosticContext);
495
496/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000497 * Set the yield callback function for this context.
498 *
499 * @see LLVMContext::setYieldCallback()
500 */
501void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
502 void *OpaqueHandle);
503
504/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000505 * Destroy a context instance.
506 *
507 * This should be called for every call to LLVMContextCreate() or memory
508 * will be leaked.
509 */
Owen Anderson6773d382009-07-01 16:58:40 +0000510void LLVMContextDispose(LLVMContextRef C);
511
Tom Stellard1580dc72014-04-16 17:45:04 +0000512/**
513 * Return a string representation of the DiagnosticInfo. Use
514 * LLVMDisposeMessage to free the string.
515 *
516 * @see DiagnosticInfo::print()
517 */
518char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
519
520/**
521 * Return an enum LLVMDiagnosticSeverity.
522 *
523 * @see DiagnosticInfo::getSeverity()
524 */
525LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
526
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000527unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
528 unsigned SLen);
529unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
530
Gregory Szorc34c863a2012-03-21 03:54:29 +0000531/**
532 * @}
533 */
534
Gregory Szorc52d26602012-03-21 07:28:27 +0000535/**
536 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000537 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000538 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000539 * module is effectively a translation unit or a collection of
540 * translation units merged together.
541 *
542 * @{
543 */
544
Gregory Szorc34c863a2012-03-21 03:54:29 +0000545/**
546 * Create a new, empty module in the global context.
547 *
548 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
549 * LLVMGetGlobalContext() as the context parameter.
550 *
551 * Every invocation should be paired with LLVMDisposeModule() or memory
552 * will be leaked.
553 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000554LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000555
556/**
557 * Create a new, empty module in a specific context.
558 *
559 * Every invocation should be paired with LLVMDisposeModule() or memory
560 * will be leaked.
561 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000562LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
563 LLVMContextRef C);
Tom Stellard0a4e9a32014-10-01 17:14:57 +0000564/**
565 * Return an exact copy of the specified module.
566 */
567LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000568
Gregory Szorc34c863a2012-03-21 03:54:29 +0000569/**
570 * Destroy a module instance.
571 *
572 * This must be called for every created module or memory will be
573 * leaked.
574 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000575void LLVMDisposeModule(LLVMModuleRef M);
576
Gregory Szorc34c863a2012-03-21 03:54:29 +0000577/**
578 * Obtain the data layout for a module.
579 *
580 * @see Module::getDataLayout()
581 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000582const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000583
584/**
585 * Set the data layout for a module.
586 *
587 * @see Module::setDataLayout()
588 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000589void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
590
Gregory Szorc34c863a2012-03-21 03:54:29 +0000591/**
592 * Obtain the target triple for a module.
593 *
594 * @see Module::getTargetTriple()
595 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000596const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000597
598/**
599 * Set the target triple for a module.
600 *
601 * @see Module::setTargetTriple()
602 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000603void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
604
Gregory Szorc34c863a2012-03-21 03:54:29 +0000605/**
606 * Dump a representation of a module to stderr.
607 *
608 * @see Module::dump()
609 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000610void LLVMDumpModule(LLVMModuleRef M);
611
Gregory Szorc34c863a2012-03-21 03:54:29 +0000612/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000613 * Print a representation of a module to a file. The ErrorMessage needs to be
614 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
615 *
616 * @see Module::print()
617 */
618LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
619 char **ErrorMessage);
620
621/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000622 * Return a string representation of the module. Use
623 * LLVMDisposeMessage to free the string.
624 *
625 * @see Module::print()
626 */
627char *LLVMPrintModuleToString(LLVMModuleRef M);
628
629/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000630 * Set inline assembly for a module.
631 *
632 * @see Module::setModuleInlineAsm()
633 */
Chris Lattner26941452010-04-10 17:52:58 +0000634void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000635
Gregory Szorc34c863a2012-03-21 03:54:29 +0000636/**
637 * Obtain the context to which this module is associated.
638 *
639 * @see Module::getContext()
640 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000641LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
642
Gregory Szorc34c863a2012-03-21 03:54:29 +0000643/**
644 * Obtain a Type from a module by its registered name.
645 */
646LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000647
Gregory Szorc34c863a2012-03-21 03:54:29 +0000648/**
649 * Obtain the number of operands for named metadata in a module.
650 *
651 * @see llvm::Module::getNamedMetadata()
652 */
653unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
654
655/**
656 * Obtain the named metadata operands for a module.
657 *
658 * The passed LLVMValueRef pointer should refer to an array of
659 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
660 * array will be populated with the LLVMValueRef instances. Each
661 * instance corresponds to a llvm::MDNode.
662 *
663 * @see llvm::Module::getNamedMetadata()
664 * @see llvm::MDNode::getOperand()
665 */
666void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
667
668/**
669 * Add an operand to named metadata.
670 *
671 * @see llvm::Module::getNamedMetadata()
672 * @see llvm::MDNode::addOperand()
673 */
674void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
675 LLVMValueRef Val);
676
Gregory Szorc52d26602012-03-21 07:28:27 +0000677/**
678 * Add a function to a module under a specified name.
679 *
680 * @see llvm::Function::Create()
681 */
682LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
683 LLVMTypeRef FunctionTy);
684
685/**
686 * Obtain a Function value from a Module by its name.
687 *
688 * The returned value corresponds to a llvm::Function value.
689 *
690 * @see llvm::Module::getFunction()
691 */
692LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
693
694/**
695 * Obtain an iterator to the first Function in a Module.
696 *
697 * @see llvm::Module::begin()
698 */
699LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
700
701/**
702 * Obtain an iterator to the last Function in a Module.
703 *
704 * @see llvm::Module::end()
705 */
706LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
707
708/**
709 * Advance a Function iterator to the next Function.
710 *
711 * Returns NULL if the iterator was already at the end and there are no more
712 * functions.
713 */
714LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
715
716/**
717 * Decrement a Function iterator to the previous Function.
718 *
719 * Returns NULL if the iterator was already at the beginning and there are
720 * no previous functions.
721 */
722LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000723
724/**
725 * @}
726 */
727
728/**
729 * @defgroup LLVMCCoreType Types
730 *
731 * Types represent the type of a value.
732 *
733 * Types are associated with a context instance. The context internally
734 * deduplicates types so there is only 1 instance of a specific type
735 * alive at a time. In other words, a unique type is shared among all
736 * consumers within a context.
737 *
738 * A Type in the C API corresponds to llvm::Type.
739 *
740 * Types have the following hierarchy:
741 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000742 * types:
743 * integer type
744 * real type
745 * function type
746 * sequence types:
747 * array type
748 * pointer type
749 * vector type
750 * void type
751 * label type
752 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000753 *
754 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000755 */
756
Gregory Szorc34c863a2012-03-21 03:54:29 +0000757/**
758 * Obtain the enumerated type of a Type instance.
759 *
760 * @see llvm::Type:getTypeID()
761 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000762LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000763
764/**
765 * Whether the type has a known size.
766 *
767 * Things that don't have a size are abstract types, labels, and void.a
768 *
769 * @see llvm::Type::isSized()
770 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000771LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000772
Gregory Szorc34c863a2012-03-21 03:54:29 +0000773/**
774 * Obtain the context to which this type instance is associated.
775 *
776 * @see llvm::Type::getContext()
777 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000778LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
779
Gregory Szorc34c863a2012-03-21 03:54:29 +0000780/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000781 * Dump a representation of a type to stderr.
782 *
783 * @see llvm::Type::dump()
784 */
785void LLVMDumpType(LLVMTypeRef Val);
786
787/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000788 * Return a string representation of the type. Use
789 * LLVMDisposeMessage to free the string.
790 *
791 * @see llvm::Type::print()
792 */
793char *LLVMPrintTypeToString(LLVMTypeRef Val);
794
795/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000796 * @defgroup LLVMCCoreTypeInt Integer Types
797 *
798 * Functions in this section operate on integer types.
799 *
800 * @{
801 */
802
803/**
804 * Obtain an integer type from a context with specified bit width.
805 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000806LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
807LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
808LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
809LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
810LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
811LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
812
Gregory Szorc34c863a2012-03-21 03:54:29 +0000813/**
814 * Obtain an integer type from the global context with a specified bit
815 * width.
816 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000817LLVMTypeRef LLVMInt1Type(void);
818LLVMTypeRef LLVMInt8Type(void);
819LLVMTypeRef LLVMInt16Type(void);
820LLVMTypeRef LLVMInt32Type(void);
821LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000822LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000823unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000824
Gregory Szorc34c863a2012-03-21 03:54:29 +0000825/**
826 * @}
827 */
828
829/**
830 * @defgroup LLVMCCoreTypeFloat Floating Point Types
831 *
832 * @{
833 */
834
835/**
836 * Obtain a 16-bit floating point type from a context.
837 */
Dan Gohman518cda42011-12-17 00:04:22 +0000838LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000839
840/**
841 * Obtain a 32-bit floating point type from a context.
842 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000843LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000844
845/**
846 * Obtain a 64-bit floating point type from a context.
847 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000848LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000849
850/**
851 * Obtain a 80-bit floating point type (X87) from a context.
852 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000853LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000854
855/**
856 * Obtain a 128-bit floating point type (112-bit mantissa) from a
857 * context.
858 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000859LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000860
861/**
862 * Obtain a 128-bit floating point type (two 64-bits) from a context.
863 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000864LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
865
Gregory Szorc34c863a2012-03-21 03:54:29 +0000866/**
867 * Obtain a floating point type from the global context.
868 *
869 * These map to the functions in this group of the same name.
870 */
Dan Gohman518cda42011-12-17 00:04:22 +0000871LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000872LLVMTypeRef LLVMFloatType(void);
873LLVMTypeRef LLVMDoubleType(void);
874LLVMTypeRef LLVMX86FP80Type(void);
875LLVMTypeRef LLVMFP128Type(void);
876LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000877
Gregory Szorc34c863a2012-03-21 03:54:29 +0000878/**
879 * @}
880 */
881
882/**
883 * @defgroup LLVMCCoreTypeFunction Function Types
884 *
885 * @{
886 */
887
888/**
889 * Obtain a function type consisting of a specified signature.
890 *
891 * The function is defined as a tuple of a return Type, a list of
892 * parameter types, and whether the function is variadic.
893 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000894LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
895 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000896 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000897
898/**
899 * Returns whether a function type is variadic.
900 */
Chris Lattner25963c62010-01-09 22:27:07 +0000901LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000902
903/**
904 * Obtain the Type this function Type returns.
905 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000906LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000907
908/**
909 * Obtain the number of parameters this function accepts.
910 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000911unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000912
913/**
914 * Obtain the types of a function's parameters.
915 *
916 * The Dest parameter should point to a pre-allocated array of
917 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
918 * first LLVMCountParamTypes() entries in the array will be populated
919 * with LLVMTypeRef instances.
920 *
921 * @param FunctionTy The function type to operate on.
922 * @param Dest Memory address of an array to be filled with result.
923 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000924void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000925
Gregory Szorc34c863a2012-03-21 03:54:29 +0000926/**
927 * @}
928 */
929
930/**
931 * @defgroup LLVMCCoreTypeStruct Structure Types
932 *
933 * These functions relate to LLVMTypeRef instances.
934 *
935 * @see llvm::StructType
936 *
937 * @{
938 */
939
940/**
941 * Create a new structure type in a context.
942 *
943 * A structure is specified by a list of inner elements/types and
944 * whether these can be packed together.
945 *
946 * @see llvm::StructType::create()
947 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000948LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000949 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000950
951/**
952 * Create a new structure type in the global context.
953 *
954 * @see llvm::StructType::create()
955 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000956LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000957 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000958
959/**
960 * Create an empty structure in a context having a specified name.
961 *
962 * @see llvm::StructType::create()
963 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000964LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000965
966/**
967 * Obtain the name of a structure.
968 *
969 * @see llvm::StructType::getName()
970 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000971const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000972
973/**
974 * Set the contents of a structure type.
975 *
976 * @see llvm::StructType::setBody()
977 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000978void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
979 unsigned ElementCount, LLVMBool Packed);
980
Gregory Szorc34c863a2012-03-21 03:54:29 +0000981/**
982 * Get the number of elements defined inside the structure.
983 *
984 * @see llvm::StructType::getNumElements()
985 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000986unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000987
988/**
989 * Get the elements within a structure.
990 *
991 * The function is passed the address of a pre-allocated array of
992 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
993 * invocation, this array will be populated with the structure's
994 * elements. The objects in the destination array will have a lifetime
995 * of the structure type itself, which is the lifetime of the context it
996 * is contained in.
997 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000998void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000999
1000/**
Peter Zotovc164a3f2015-06-04 09:09:53 +00001001 * Get the type of the element at a given index in the structure.
1002 *
1003 * @see llvm::StructType::getTypeAtIndex()
1004 */
1005LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
1006
1007/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001008 * Determine whether a structure is packed.
1009 *
1010 * @see llvm::StructType::isPacked()
1011 */
Chris Lattner25963c62010-01-09 22:27:07 +00001012LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001013
1014/**
1015 * Determine whether a structure is opaque.
1016 *
1017 * @see llvm::StructType::isOpaque()
1018 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001019LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1020
Gregory Szorc34c863a2012-03-21 03:54:29 +00001021/**
1022 * @}
1023 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001024
Gregory Szorc34c863a2012-03-21 03:54:29 +00001025
1026/**
1027 * @defgroup LLVMCCoreTypeSequential Sequential Types
1028 *
1029 * Sequential types represents "arrays" of types. This is a super class
1030 * for array, vector, and pointer types.
1031 *
1032 * @{
1033 */
1034
1035/**
1036 * Obtain the type of elements within a sequential type.
1037 *
1038 * This works on array, vector, and pointer types.
1039 *
1040 * @see llvm::SequentialType::getElementType()
1041 */
1042LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1043
1044/**
1045 * Create a fixed size array type that refers to a specific type.
1046 *
1047 * The created type will exist in the context that its element type
1048 * exists in.
1049 *
1050 * @see llvm::ArrayType::get()
1051 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001052LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001053
1054/**
1055 * Obtain the length of an array type.
1056 *
1057 * This only works on types that represent arrays.
1058 *
1059 * @see llvm::ArrayType::getNumElements()
1060 */
1061unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1062
1063/**
1064 * Create a pointer type that points to a defined type.
1065 *
1066 * The created type will exist in the context that its pointee type
1067 * exists in.
1068 *
1069 * @see llvm::PointerType::get()
1070 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001071LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001072
1073/**
1074 * Obtain the address space of a pointer type.
1075 *
1076 * This only works on types that represent pointers.
1077 *
1078 * @see llvm::PointerType::getAddressSpace()
1079 */
1080unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1081
1082/**
1083 * Create a vector type that contains a defined type and has a specific
1084 * number of elements.
1085 *
1086 * The created type will exist in the context thats its element type
1087 * exists in.
1088 *
1089 * @see llvm::VectorType::get()
1090 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001091LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001092
Gregory Szorc34c863a2012-03-21 03:54:29 +00001093/**
1094 * Obtain the number of elements in a vector type.
1095 *
1096 * This only works on types that represent vectors.
1097 *
1098 * @see llvm::VectorType::getNumElements()
1099 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001100unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1101
Gregory Szorc34c863a2012-03-21 03:54:29 +00001102/**
1103 * @}
1104 */
1105
1106/**
1107 * @defgroup LLVMCCoreTypeOther Other Types
1108 *
1109 * @{
1110 */
1111
1112/**
1113 * Create a void type in a context.
1114 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001115LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001116
1117/**
1118 * Create a label type in a context.
1119 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001120LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001121
1122/**
1123 * Create a X86 MMX type in a context.
1124 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001125LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001126
Gregory Szorc34c863a2012-03-21 03:54:29 +00001127/**
1128 * These are similar to the above functions except they operate on the
1129 * global context.
1130 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001131LLVMTypeRef LLVMVoidType(void);
1132LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001133LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001134
Gregory Szorc34c863a2012-03-21 03:54:29 +00001135/**
1136 * @}
1137 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001138
Gregory Szorc34c863a2012-03-21 03:54:29 +00001139/**
1140 * @}
1141 */
1142
1143/**
1144 * @defgroup LLVMCCoreValues Values
1145 *
1146 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001147 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001148 *
1149 * LLVMValueRef essentially represents llvm::Value. There is a rich
1150 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001151 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001152 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001153 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001154 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1155 * functions are defined by a macro, so it isn't obvious which are
1156 * available by looking at the Doxygen source code. Instead, look at the
1157 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1158 * of value names given. These value names also correspond to classes in
1159 * the llvm::Value hierarchy.
1160 *
1161 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001162 */
1163
Gordon Henriksen29e38942008-12-19 18:39:45 +00001164#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1165 macro(Argument) \
1166 macro(BasicBlock) \
1167 macro(InlineAsm) \
1168 macro(User) \
1169 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001170 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001171 macro(ConstantAggregateZero) \
1172 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001173 macro(ConstantDataSequential) \
1174 macro(ConstantDataArray) \
1175 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001176 macro(ConstantExpr) \
1177 macro(ConstantFP) \
1178 macro(ConstantInt) \
1179 macro(ConstantPointerNull) \
1180 macro(ConstantStruct) \
1181 macro(ConstantVector) \
1182 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001183 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001184 macro(GlobalObject) \
1185 macro(Function) \
1186 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001187 macro(UndefValue) \
1188 macro(Instruction) \
1189 macro(BinaryOperator) \
1190 macro(CallInst) \
1191 macro(IntrinsicInst) \
1192 macro(DbgInfoIntrinsic) \
1193 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001194 macro(MemIntrinsic) \
1195 macro(MemCpyInst) \
1196 macro(MemMoveInst) \
1197 macro(MemSetInst) \
1198 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001199 macro(FCmpInst) \
1200 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001201 macro(ExtractElementInst) \
1202 macro(GetElementPtrInst) \
1203 macro(InsertElementInst) \
1204 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001205 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001206 macro(PHINode) \
1207 macro(SelectInst) \
1208 macro(ShuffleVectorInst) \
1209 macro(StoreInst) \
1210 macro(TerminatorInst) \
1211 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001212 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001213 macro(InvokeInst) \
1214 macro(ReturnInst) \
1215 macro(SwitchInst) \
1216 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001217 macro(ResumeInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001218 macro(UnaryInstruction) \
1219 macro(AllocaInst) \
1220 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001221 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001222 macro(BitCastInst) \
1223 macro(FPExtInst) \
1224 macro(FPToSIInst) \
1225 macro(FPToUIInst) \
1226 macro(FPTruncInst) \
1227 macro(IntToPtrInst) \
1228 macro(PtrToIntInst) \
1229 macro(SExtInst) \
1230 macro(SIToFPInst) \
1231 macro(TruncInst) \
1232 macro(UIToFPInst) \
1233 macro(ZExtInst) \
1234 macro(ExtractValueInst) \
1235 macro(LoadInst) \
1236 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001237
Gregory Szorc34c863a2012-03-21 03:54:29 +00001238/**
1239 * @defgroup LLVMCCoreValueGeneral General APIs
1240 *
1241 * Functions in this section work on all LLVMValueRef instances,
1242 * regardless of their sub-type. They correspond to functions available
1243 * on llvm::Value.
1244 *
1245 * @{
1246 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001247
Gregory Szorc34c863a2012-03-21 03:54:29 +00001248/**
1249 * Obtain the type of a value.
1250 *
1251 * @see llvm::Value::getType()
1252 */
1253LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1254
1255/**
1256 * Obtain the string name of a value.
1257 *
1258 * @see llvm::Value::getName()
1259 */
1260const char *LLVMGetValueName(LLVMValueRef Val);
1261
1262/**
1263 * Set the string name of a value.
1264 *
1265 * @see llvm::Value::setName()
1266 */
1267void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1268
1269/**
1270 * Dump a representation of a value to stderr.
1271 *
1272 * @see llvm::Value::dump()
1273 */
1274void LLVMDumpValue(LLVMValueRef Val);
1275
1276/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001277 * Return a string representation of the value. Use
1278 * LLVMDisposeMessage to free the string.
1279 *
1280 * @see llvm::Value::print()
1281 */
1282char *LLVMPrintValueToString(LLVMValueRef Val);
1283
1284/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001285 * Replace all uses of a value with another one.
1286 *
1287 * @see llvm::Value::replaceAllUsesWith()
1288 */
1289void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1290
1291/**
1292 * Determine whether the specified constant instance is constant.
1293 */
1294LLVMBool LLVMIsConstant(LLVMValueRef Val);
1295
1296/**
1297 * Determine whether a value instance is undefined.
1298 */
1299LLVMBool LLVMIsUndef(LLVMValueRef Val);
1300
1301/**
1302 * Convert value instances between types.
1303 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001304 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001305 * series of functions allows you to cast an instance to a specific
1306 * type.
1307 *
1308 * If the cast is not valid for the specified type, NULL is returned.
1309 *
1310 * @see llvm::dyn_cast_or_null<>
1311 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001312#define LLVM_DECLARE_VALUE_CAST(name) \
1313 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1314LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1315
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001316LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1317LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1318
Gregory Szorc34c863a2012-03-21 03:54:29 +00001319/**
1320 * @}
1321 */
1322
1323/**
1324 * @defgroup LLVMCCoreValueUses Usage
1325 *
1326 * This module defines functions that allow you to inspect the uses of a
1327 * LLVMValueRef.
1328 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001329 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001330 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1331 * llvm::User and llvm::Value.
1332 *
1333 * @{
1334 */
1335
1336/**
1337 * Obtain the first use of a value.
1338 *
1339 * Uses are obtained in an iterator fashion. First, call this function
1340 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001341 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001342 * LLVMGetNextUse() returns NULL.
1343 *
1344 * @see llvm::Value::use_begin()
1345 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001346LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001347
1348/**
1349 * Obtain the next use of a value.
1350 *
1351 * This effectively advances the iterator. It returns NULL if you are on
1352 * the final use and no more are available.
1353 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001354LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001355
1356/**
1357 * Obtain the user value for a user.
1358 *
1359 * The returned value corresponds to a llvm::User type.
1360 *
1361 * @see llvm::Use::getUser()
1362 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001363LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001364
1365/**
1366 * Obtain the value this use corresponds to.
1367 *
1368 * @see llvm::Use::get().
1369 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001370LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001371
Gregory Szorc34c863a2012-03-21 03:54:29 +00001372/**
1373 * @}
1374 */
1375
1376/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001377 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001378 *
1379 * Function in this group pertain to LLVMValueRef instances that descent
1380 * from llvm::User. This includes constants, instructions, and
1381 * operators.
1382 *
1383 * @{
1384 */
1385
1386/**
1387 * Obtain an operand at a specific index in a llvm::User value.
1388 *
1389 * @see llvm::User::getOperand()
1390 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001391LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001392
1393/**
Peter Zotovb19f78f2014-08-12 02:55:40 +00001394 * Obtain the use of an operand at a specific index in a llvm::User value.
1395 *
1396 * @see llvm::User::getOperandUse()
1397 */
1398LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1399
1400/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001401 * Set an operand at a specific index in a llvm::User value.
1402 *
1403 * @see llvm::User::setOperand()
1404 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001405void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001406
1407/**
1408 * Obtain the number of operands in a llvm::User value.
1409 *
1410 * @see llvm::User::getNumOperands()
1411 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001412int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001413
Gregory Szorc34c863a2012-03-21 03:54:29 +00001414/**
1415 * @}
1416 */
1417
1418/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001419 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001420 *
1421 * This section contains APIs for interacting with LLVMValueRef that
1422 * correspond to llvm::Constant instances.
1423 *
1424 * These functions will work for any LLVMValueRef in the llvm::Constant
1425 * class hierarchy.
1426 *
1427 * @{
1428 */
1429
1430/**
1431 * Obtain a constant value referring to the null instance of a type.
1432 *
1433 * @see llvm::Constant::getNullValue()
1434 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001435LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001436
1437/**
1438 * Obtain a constant value referring to the instance of a type
1439 * consisting of all ones.
1440 *
1441 * This is only valid for integer types.
1442 *
1443 * @see llvm::Constant::getAllOnesValue()
1444 */
1445LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1446
1447/**
1448 * Obtain a constant value referring to an undefined value of a type.
1449 *
1450 * @see llvm::UndefValue::get()
1451 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001452LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001453
1454/**
1455 * Determine whether a value instance is null.
1456 *
1457 * @see llvm::Constant::isNullValue()
1458 */
Chris Lattner25963c62010-01-09 22:27:07 +00001459LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001460
1461/**
1462 * Obtain a constant that is a constant pointer pointing to NULL for a
1463 * specified type.
1464 */
Chris Lattner7f318242009-07-06 17:29:59 +00001465LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001466
Gregory Szorc34c863a2012-03-21 03:54:29 +00001467/**
1468 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1469 *
1470 * Functions in this group model LLVMValueRef instances that correspond
1471 * to constants referring to scalar types.
1472 *
1473 * For integer types, the LLVMTypeRef parameter should correspond to a
1474 * llvm::IntegerType instance and the returned LLVMValueRef will
1475 * correspond to a llvm::ConstantInt.
1476 *
1477 * For floating point types, the LLVMTypeRef returned corresponds to a
1478 * llvm::ConstantFP.
1479 *
1480 * @{
1481 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001482
Gregory Szorc34c863a2012-03-21 03:54:29 +00001483/**
1484 * Obtain a constant value for an integer type.
1485 *
1486 * The returned value corresponds to a llvm::ConstantInt.
1487 *
1488 * @see llvm::ConstantInt::get()
1489 *
1490 * @param IntTy Integer type to obtain value of.
1491 * @param N The value the returned instance should refer to.
1492 * @param SignExtend Whether to sign extend the produced value.
1493 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001494LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001495 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001496
1497/**
1498 * Obtain a constant value for an integer of arbitrary precision.
1499 *
1500 * @see llvm::ConstantInt::get()
1501 */
Chris Lattner4329e072010-11-23 02:47:22 +00001502LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1503 unsigned NumWords,
1504 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001505
1506/**
1507 * Obtain a constant value for an integer parsed from a string.
1508 *
1509 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1510 * string's length is available, it is preferred to call that function
1511 * instead.
1512 *
1513 * @see llvm::ConstantInt::get()
1514 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001515LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1516 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001517
1518/**
1519 * Obtain a constant value for an integer parsed from a string with
1520 * specified length.
1521 *
1522 * @see llvm::ConstantInt::get()
1523 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001524LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1525 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001526
1527/**
1528 * Obtain a constant value referring to a double floating point value.
1529 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001530LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001531
1532/**
1533 * Obtain a constant for a floating point value parsed from a string.
1534 *
1535 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1536 * should be used if the input string's length is known.
1537 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001538LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001539
1540/**
1541 * Obtain a constant for a floating point value parsed from a string.
1542 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001543LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1544 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001545
1546/**
1547 * Obtain the zero extended value for an integer constant value.
1548 *
1549 * @see llvm::ConstantInt::getZExtValue()
1550 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001551unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001552
1553/**
1554 * Obtain the sign extended value for an integer constant value.
1555 *
1556 * @see llvm::ConstantInt::getSExtValue()
1557 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001558long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001559
Gregory Szorc34c863a2012-03-21 03:54:29 +00001560/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00001561 * Obtain the double value for an floating point constant value.
1562 * losesInfo indicates if some precision was lost in the conversion.
1563 *
1564 * @see llvm::ConstantFP::getDoubleValue
1565 */
1566double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1567
1568/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001569 * @}
1570 */
1571
1572/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001573 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1574 *
1575 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001576 *
1577 * @{
1578 */
1579
1580/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001581 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001582 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001583 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001584 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001585LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001586 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001587
1588/**
1589 * Create a ConstantDataSequential with string content in the global context.
1590 *
1591 * This is the same as LLVMConstStringInContext except it operates on the
1592 * global context.
1593 *
1594 * @see LLVMConstStringInContext()
1595 * @see llvm::ConstantDataArray::getString()
1596 */
1597LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1598 LLVMBool DontNullTerminate);
1599
1600/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001601 * Returns true if the specified constant is an array of i8.
1602 *
1603 * @see ConstantDataSequential::getAsString()
1604 */
1605LLVMBool LLVMIsConstantString(LLVMValueRef c);
1606
1607/**
1608 * Get the given constant data sequential as a string.
1609 *
1610 * @see ConstantDataSequential::getAsString()
1611 */
1612const char *LLVMGetAsString(LLVMValueRef c, size_t* out);
1613
1614/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001615 * Create an anonymous ConstantStruct with the specified values.
1616 *
1617 * @see llvm::ConstantStruct::getAnon()
1618 */
1619LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001620 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001621 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001622
Gregory Szorc52d26602012-03-21 07:28:27 +00001623/**
1624 * Create a ConstantStruct in the global Context.
1625 *
1626 * This is the same as LLVMConstStructInContext except it operates on the
1627 * global Context.
1628 *
1629 * @see LLVMConstStructInContext()
1630 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001631LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001632 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001633
1634/**
1635 * Create a ConstantArray from values.
1636 *
1637 * @see llvm::ConstantArray::get()
1638 */
1639LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1640 LLVMValueRef *ConstantVals, unsigned Length);
1641
1642/**
1643 * Create a non-anonymous ConstantStruct from values.
1644 *
1645 * @see llvm::ConstantStruct::get()
1646 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001647LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1648 LLVMValueRef *ConstantVals,
1649 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001650
1651/**
Peter Zotovf9aa8822014-08-03 23:54:16 +00001652 * Get an element at specified index as a constant.
1653 *
1654 * @see ConstantDataSequential::getElementAsConstant()
1655 */
1656LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx);
1657
1658/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001659 * Create a ConstantVector from values.
1660 *
1661 * @see llvm::ConstantVector::get()
1662 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001663LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001664
Gregory Szorc52d26602012-03-21 07:28:27 +00001665/**
1666 * @}
1667 */
1668
1669/**
1670 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1671 *
1672 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1673 *
1674 * @see llvm::ConstantExpr.
1675 *
1676 * @{
1677 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001678LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001679LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001680LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1681LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001682LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1683LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001684LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001685LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1686LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001687LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001688LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001689LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001690LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001691LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1692LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001693LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001694LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001695LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1696LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001697LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001698LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1699LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001700LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001701LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1702LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1703LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1704LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1705LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1706LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1707LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1708LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1709 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1710LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1711 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1712LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1713LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1714LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1715LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1716 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001717LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1718 LLVMValueRef *ConstantIndices,
1719 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001720LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1721LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1722LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1723LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1724LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1725LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1726LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1727LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1728LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1729LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1730LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1731LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001732LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001733LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1734 LLVMTypeRef ToType);
1735LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1736 LLVMTypeRef ToType);
1737LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1738 LLVMTypeRef ToType);
1739LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1740 LLVMTypeRef ToType);
1741LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001742 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001743LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001744LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1745 LLVMValueRef ConstantIfTrue,
1746 LLVMValueRef ConstantIfFalse);
1747LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1748 LLVMValueRef IndexConstant);
1749LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1750 LLVMValueRef ElementValueConstant,
1751 LLVMValueRef IndexConstant);
1752LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1753 LLVMValueRef VectorBConstant,
1754 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001755LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1756 unsigned NumIdx);
1757LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1758 LLVMValueRef ElementValueConstant,
1759 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001760LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001761 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001762 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001763LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001764
Gregory Szorc52d26602012-03-21 07:28:27 +00001765/**
1766 * @}
1767 */
1768
1769/**
1770 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1771 *
1772 * This group contains functions that operate on global values. Functions in
1773 * this group relate to functions in the llvm::GlobalValue class tree.
1774 *
1775 * @see llvm::GlobalValue
1776 *
1777 * @{
1778 */
1779
Gordon Henriksen265f7802008-03-19 01:11:35 +00001780LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001781LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001782LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1783void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1784const char *LLVMGetSection(LLVMValueRef Global);
1785void LLVMSetSection(LLVMValueRef Global, const char *Section);
1786LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1787void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001788LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1789void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001790LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1791void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001792
1793/**
1794 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1795 *
1796 * Functions in this group only apply to values with alignment, i.e.
1797 * global variables, load and store instructions.
1798 */
1799
1800/**
1801 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001802 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001803 * @see llvm::LoadInst::getAlignment()
1804 * @see llvm::StoreInst::getAlignment()
1805 * @see llvm::GlobalValue::getAlignment()
1806 */
1807unsigned LLVMGetAlignment(LLVMValueRef V);
1808
1809/**
1810 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001811 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001812 * @see llvm::LoadInst::setAlignment()
1813 * @see llvm::StoreInst::setAlignment()
1814 * @see llvm::GlobalValue::setAlignment()
1815 */
1816void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1817
1818/**
1819 * @}
1820 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001821
Gregory Szorc52d26602012-03-21 07:28:27 +00001822/**
1823 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1824 *
1825 * This group contains functions that operate on global variable values.
1826 *
1827 * @see llvm::GlobalVariable
1828 *
1829 * @{
1830 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001831LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001832LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1833 const char *Name,
1834 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001835LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001836LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1837LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1838LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1839LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001840void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001841LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1842void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001843LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1844void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1845LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1846void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001847LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1848void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1849LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1850void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001851
Gregory Szorc52d26602012-03-21 07:28:27 +00001852/**
1853 * @}
1854 */
1855
1856/**
1857 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1858 *
1859 * This group contains function that operate on global alias values.
1860 *
1861 * @see llvm::GlobalAlias
1862 *
1863 * @{
1864 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001865LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1866 const char *Name);
1867
Gregory Szorc34c863a2012-03-21 03:54:29 +00001868/**
1869 * @}
1870 */
1871
1872/**
1873 * @defgroup LLVMCCoreValueFunction Function values
1874 *
1875 * Functions in this group operate on LLVMValueRef instances that
1876 * correspond to llvm::Function instances.
1877 *
1878 * @see llvm::Function
1879 *
1880 * @{
1881 */
1882
1883/**
1884 * Remove a function from its containing module and deletes it.
1885 *
1886 * @see llvm::Function::eraseFromParent()
1887 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001888void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001889
1890/**
1891 * Obtain the ID number from a function instance.
1892 *
1893 * @see llvm::Function::getIntrinsicID()
1894 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001895unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001896
1897/**
1898 * Obtain the calling function of a function.
1899 *
1900 * The returned value corresponds to the LLVMCallConv enumeration.
1901 *
1902 * @see llvm::Function::getCallingConv()
1903 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001904unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001905
1906/**
1907 * Set the calling convention of a function.
1908 *
1909 * @see llvm::Function::setCallingConv()
1910 *
1911 * @param Fn Function to operate on
1912 * @param CC LLVMCallConv to set calling convention to
1913 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001914void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001915
1916/**
1917 * Obtain the name of the garbage collector to use during code
1918 * generation.
1919 *
1920 * @see llvm::Function::getGC()
1921 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001922const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001923
1924/**
1925 * Define the garbage collector to use during code generation.
1926 *
1927 * @see llvm::Function::setGC()
1928 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001929void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001930
1931/**
1932 * Add an attribute to a function.
1933 *
1934 * @see llvm::Function::addAttribute()
1935 */
Duncan Sands7374a012009-05-06 12:21:17 +00001936void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001937
1938/**
Tom Stellarde8f35e12013-04-16 23:12:43 +00001939 * Add a target-dependent attribute to a fuction
1940 * @see llvm::AttrBuilder::addAttribute()
1941 */
1942void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1943 const char *V);
1944
1945/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001946 * Obtain an attribute from a function.
1947 *
1948 * @see llvm::Function::getAttributes()
1949 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001950LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001951
1952/**
1953 * Remove an attribute from a function.
1954 */
Duncan Sands7374a012009-05-06 12:21:17 +00001955void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001956
Gregory Szorc34c863a2012-03-21 03:54:29 +00001957/**
1958 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1959 *
1960 * Functions in this group relate to arguments/parameters on functions.
1961 *
1962 * Functions in this group expect LLVMValueRef instances that correspond
1963 * to llvm::Function instances.
1964 *
1965 * @{
1966 */
1967
1968/**
1969 * Obtain the number of parameters in a function.
1970 *
1971 * @see llvm::Function::arg_size()
1972 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001973unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001974
1975/**
1976 * Obtain the parameters in a function.
1977 *
1978 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1979 * at least LLVMCountParams() long. This array will be filled with
1980 * LLVMValueRef instances which correspond to the parameters the
1981 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1982 * instance.
1983 *
1984 * @see llvm::Function::arg_begin()
1985 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001986void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001987
1988/**
1989 * Obtain the parameter at the specified index.
1990 *
1991 * Parameters are indexed from 0.
1992 *
1993 * @see llvm::Function::arg_begin()
1994 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001995LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001996
1997/**
1998 * Obtain the function to which this argument belongs.
1999 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002000 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00002001 * that corresponds to a llvm::Attribute.
2002 *
2003 * The returned LLVMValueRef is the llvm::Function to which this
2004 * argument belongs.
2005 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00002006LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002007
2008/**
2009 * Obtain the first parameter to a function.
2010 *
2011 * @see llvm::Function::arg_begin()
2012 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002013LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002014
2015/**
2016 * Obtain the last parameter to a function.
2017 *
2018 * @see llvm::Function::arg_end()
2019 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002020LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002021
2022/**
2023 * Obtain the next parameter to a function.
2024 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002025 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00002026 * actually a wrapped iterator) and obtains the next parameter from the
2027 * underlying iterator.
2028 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002029LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002030
2031/**
2032 * Obtain the previous parameter to a function.
2033 *
2034 * This is the opposite of LLVMGetNextParam().
2035 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002036LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002037
2038/**
2039 * Add an attribute to a function argument.
2040 *
2041 * @see llvm::Argument::addAttr()
2042 */
Devang Patel4c758ea2008-09-25 21:00:45 +00002043void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002044
2045/**
2046 * Remove an attribute from a function argument.
2047 *
2048 * @see llvm::Argument::removeAttr()
2049 */
Devang Patel4c758ea2008-09-25 21:00:45 +00002050void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002051
2052/**
2053 * Get an attribute from a function argument.
2054 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002055LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002056
2057/**
2058 * Set the alignment for a function parameter.
2059 *
2060 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002061 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002062 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002063void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002064
Gregory Szorc34c863a2012-03-21 03:54:29 +00002065/**
2066 * @}
2067 */
2068
2069/**
2070 * @}
2071 */
2072
2073/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002074 * @}
2075 */
2076
2077/**
2078 * @}
2079 */
2080
2081/**
2082 * @defgroup LLVMCCoreValueMetadata Metadata
2083 *
2084 * @{
2085 */
2086
2087/**
2088 * Obtain a MDString value from a context.
2089 *
2090 * The returned instance corresponds to the llvm::MDString class.
2091 *
2092 * The instance is specified by string data of a specified length. The
2093 * string content is copied, so the backing memory can be freed after
2094 * this function returns.
2095 */
2096LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2097 unsigned SLen);
2098
2099/**
2100 * Obtain a MDString value from the global context.
2101 */
2102LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2103
2104/**
2105 * Obtain a MDNode value from a context.
2106 *
2107 * The returned value corresponds to the llvm::MDNode class.
2108 */
2109LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2110 unsigned Count);
2111
2112/**
2113 * Obtain a MDNode value from the global context.
2114 */
2115LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2116
2117/**
2118 * Obtain the underlying string from a MDString value.
2119 *
2120 * @param V Instance to obtain string from.
2121 * @param Len Memory address which will hold length of returned string.
2122 * @return String data in MDString.
2123 */
2124const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2125
2126/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002127 * Obtain the number of operands from an MDNode value.
2128 *
2129 * @param V MDNode to get number of operands from.
2130 * @return Number of operands of the MDNode.
2131 */
2132unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2133
2134/**
2135 * Obtain the given MDNode's operands.
2136 *
2137 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2138 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2139 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2140 * MDNode's operands.
2141 *
2142 * @param V MDNode to get the operands from.
2143 * @param Dest Destination array for operands.
2144 */
2145void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2146
2147/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002148 * @}
2149 */
2150
2151/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002152 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2153 *
2154 * A basic block represents a single entry single exit section of code.
2155 * Basic blocks contain a list of instructions which form the body of
2156 * the block.
2157 *
2158 * Basic blocks belong to functions. They have the type of label.
2159 *
2160 * Basic blocks are themselves values. However, the C API models them as
2161 * LLVMBasicBlockRef.
2162 *
2163 * @see llvm::BasicBlock
2164 *
2165 * @{
2166 */
2167
2168/**
2169 * Convert a basic block instance to a value type.
2170 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002171LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002172
2173/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002174 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002175 */
Chris Lattner25963c62010-01-09 22:27:07 +00002176LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002177
2178/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002179 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002180 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002181LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002182
2183/**
2184 * Obtain the function to which a basic block belongs.
2185 *
2186 * @see llvm::BasicBlock::getParent()
2187 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002188LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002189
2190/**
2191 * Obtain the terminator instruction for a basic block.
2192 *
2193 * If the basic block does not have a terminator (it is not well-formed
2194 * if it doesn't), then NULL is returned.
2195 *
2196 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2197 *
2198 * @see llvm::BasicBlock::getTerminator()
2199 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002200LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002201
2202/**
2203 * Obtain the number of basic blocks in a function.
2204 *
2205 * @param Fn Function value to operate on.
2206 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002207unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002208
2209/**
2210 * Obtain all of the basic blocks in a function.
2211 *
2212 * This operates on a function value. The BasicBlocks parameter is a
2213 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2214 * LLVMCountBasicBlocks() in length. This array is populated with
2215 * LLVMBasicBlockRef instances.
2216 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002217void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002218
2219/**
2220 * Obtain the first basic block in a function.
2221 *
2222 * The returned basic block can be used as an iterator. You will likely
2223 * eventually call into LLVMGetNextBasicBlock() with it.
2224 *
2225 * @see llvm::Function::begin()
2226 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002227LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002228
2229/**
2230 * Obtain the last basic block in a function.
2231 *
2232 * @see llvm::Function::end()
2233 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002234LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002235
2236/**
2237 * Advance a basic block iterator.
2238 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002239LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002240
2241/**
2242 * Go backwards in a basic block iterator.
2243 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002244LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002245
2246/**
2247 * Obtain the basic block that corresponds to the entry point of a
2248 * function.
2249 *
2250 * @see llvm::Function::getEntryBlock()
2251 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002252LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002253
Gregory Szorc34c863a2012-03-21 03:54:29 +00002254/**
2255 * Append a basic block to the end of a function.
2256 *
2257 * @see llvm::BasicBlock::Create()
2258 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002259LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2260 LLVMValueRef Fn,
2261 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002262
2263/**
2264 * Append a basic block to the end of a function using the global
2265 * context.
2266 *
2267 * @see llvm::BasicBlock::Create()
2268 */
2269LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2270
2271/**
2272 * Insert a basic block in a function before another basic block.
2273 *
2274 * The function to add to is determined by the function of the
2275 * passed basic block.
2276 *
2277 * @see llvm::BasicBlock::Create()
2278 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002279LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2280 LLVMBasicBlockRef BB,
2281 const char *Name);
2282
Gregory Szorc34c863a2012-03-21 03:54:29 +00002283/**
2284 * Insert a basic block in a function using the global context.
2285 *
2286 * @see llvm::BasicBlock::Create()
2287 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002288LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2289 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002290
2291/**
2292 * Remove a basic block from a function and delete it.
2293 *
2294 * This deletes the basic block from its containing function and deletes
2295 * the basic block itself.
2296 *
2297 * @see llvm::BasicBlock::eraseFromParent()
2298 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002299void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002300
2301/**
2302 * Remove a basic block from a function.
2303 *
2304 * This deletes the basic block from its containing function but keep
2305 * the basic block alive.
2306 *
2307 * @see llvm::BasicBlock::removeFromParent()
2308 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002309void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002310
Gregory Szorc34c863a2012-03-21 03:54:29 +00002311/**
2312 * Move a basic block to before another one.
2313 *
2314 * @see llvm::BasicBlock::moveBefore()
2315 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002316void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002317
2318/**
2319 * Move a basic block to after another one.
2320 *
2321 * @see llvm::BasicBlock::moveAfter()
2322 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002323void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2324
Gregory Szorc34c863a2012-03-21 03:54:29 +00002325/**
2326 * Obtain the first instruction in a basic block.
2327 *
2328 * The returned LLVMValueRef corresponds to a llvm::Instruction
2329 * instance.
2330 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002331LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002332
2333/**
2334 * Obtain the last instruction in a basic block.
2335 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002336 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002337 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002338LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002339
Gregory Szorc34c863a2012-03-21 03:54:29 +00002340/**
2341 * @}
2342 */
2343
2344/**
2345 * @defgroup LLVMCCoreValueInstruction Instructions
2346 *
2347 * Functions in this group relate to the inspection and manipulation of
2348 * individual instructions.
2349 *
2350 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2351 * class has a large number of descendents. llvm::Instruction is a
2352 * llvm::Value and in the C API, instructions are modeled by
2353 * LLVMValueRef.
2354 *
2355 * This group also contains sub-groups which operate on specific
2356 * llvm::Instruction types, e.g. llvm::CallInst.
2357 *
2358 * @{
2359 */
2360
2361/**
2362 * Determine whether an instruction has any metadata attached.
2363 */
2364int LLVMHasMetadata(LLVMValueRef Val);
2365
2366/**
2367 * Return metadata associated with an instruction value.
2368 */
2369LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2370
2371/**
2372 * Set metadata associated with an instruction value.
2373 */
2374void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2375
2376/**
2377 * Obtain the basic block to which an instruction belongs.
2378 *
2379 * @see llvm::Instruction::getParent()
2380 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002381LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002382
2383/**
2384 * Obtain the instruction that occurs after the one specified.
2385 *
2386 * The next instruction will be from the same basic block.
2387 *
2388 * If this is the last instruction in a basic block, NULL will be
2389 * returned.
2390 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002391LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002392
2393/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002394 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002395 *
2396 * If the instruction is the first instruction in a basic block, NULL
2397 * will be returned.
2398 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002399LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002400
2401/**
2402 * Remove and delete an instruction.
2403 *
2404 * The instruction specified is removed from its containing building
2405 * block and then deleted.
2406 *
2407 * @see llvm::Instruction::eraseFromParent()
2408 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002409void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002410
2411/**
2412 * Obtain the code opcode for an individual instruction.
2413 *
2414 * @see llvm::Instruction::getOpCode()
2415 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002416LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002417
2418/**
2419 * Obtain the predicate of an instruction.
2420 *
2421 * This is only valid for instructions that correspond to llvm::ICmpInst
2422 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2423 *
2424 * @see llvm::ICmpInst::getPredicate()
2425 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002426LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002427
Gregory Szorc34c863a2012-03-21 03:54:29 +00002428/**
Peter Zotov1d98e6d2014-10-28 19:46:44 +00002429 * Obtain the float predicate of an instruction.
2430 *
2431 * This is only valid for instructions that correspond to llvm::FCmpInst
2432 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
2433 *
2434 * @see llvm::FCmpInst::getPredicate()
2435 */
2436LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
2437
2438/**
Peter Zotovaff492c2014-10-17 01:02:34 +00002439 * Create a copy of 'this' instruction that is identical in all ways
2440 * except the following:
2441 * * The instruction has no parent
2442 * * The instruction has no name
2443 *
2444 * @see llvm::Instruction::clone()
2445 */
2446LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
2447
2448/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002449 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2450 *
2451 * Functions in this group apply to instructions that refer to call
2452 * sites and invocations. These correspond to C++ types in the
2453 * llvm::CallInst class tree.
2454 *
2455 * @{
2456 */
2457
2458/**
2459 * Set the calling convention for a call instruction.
2460 *
2461 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2462 * llvm::InvokeInst.
2463 *
2464 * @see llvm::CallInst::setCallingConv()
2465 * @see llvm::InvokeInst::setCallingConv()
2466 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002467void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002468
2469/**
2470 * Obtain the calling convention for a call instruction.
2471 *
2472 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2473 * usage.
2474 *
2475 * @see LLVMSetInstructionCallConv()
2476 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002477unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002478
2479
Devang Patel4c758ea2008-09-25 21:00:45 +00002480void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002481void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002482 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002483void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002484 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002485
Gregory Szorc34c863a2012-03-21 03:54:29 +00002486/**
2487 * Obtain whether a call instruction is a tail call.
2488 *
2489 * This only works on llvm::CallInst instructions.
2490 *
2491 * @see llvm::CallInst::isTailCall()
2492 */
Chris Lattner25963c62010-01-09 22:27:07 +00002493LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002494
2495/**
2496 * Set whether a call instruction is a tail call.
2497 *
2498 * This only works on llvm::CallInst instructions.
2499 *
2500 * @see llvm::CallInst::setTailCall()
2501 */
Chris Lattner25963c62010-01-09 22:27:07 +00002502void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002503
Gregory Szorc34c863a2012-03-21 03:54:29 +00002504/**
2505 * @}
2506 */
2507
2508/**
Peter Zotov2481c752014-10-28 19:46:56 +00002509 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
2510 *
2511 * Functions in this group only apply to instructions that map to
2512 * llvm::TerminatorInst instances.
2513 *
2514 * @{
2515 */
2516
2517/**
2518 * Return the number of successors that this terminator has.
2519 *
2520 * @see llvm::TerminatorInst::getNumSuccessors
2521 */
2522unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
2523
2524/**
2525 * Return the specified successor.
2526 *
2527 * @see llvm::TerminatorInst::getSuccessor
2528 */
2529LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
2530
2531/**
2532 * Update the specified successor to point at the provided block.
2533 *
2534 * @see llvm::TerminatorInst::setSuccessor
2535 */
2536void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
2537
2538/**
2539 * Return if a branch is conditional.
2540 *
2541 * This only works on llvm::BranchInst instructions.
2542 *
2543 * @see llvm::BranchInst::isConditional
2544 */
2545LLVMBool LLVMIsConditional(LLVMValueRef Branch);
2546
2547/**
2548 * Return the condition of a branch instruction.
2549 *
2550 * This only works on llvm::BranchInst instructions.
2551 *
2552 * @see llvm::BranchInst::getCondition
2553 */
2554LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
2555
2556/**
2557 * Set the condition of a branch instruction.
2558 *
2559 * This only works on llvm::BranchInst instructions.
2560 *
2561 * @see llvm::BranchInst::setCondition
2562 */
2563void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
2564
2565/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002566 * Obtain the default destination basic block of a switch instruction.
2567 *
2568 * This only works on llvm::SwitchInst instructions.
2569 *
2570 * @see llvm::SwitchInst::getDefaultDest()
2571 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002572LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2573
Gregory Szorc34c863a2012-03-21 03:54:29 +00002574/**
Peter Zotov2481c752014-10-28 19:46:56 +00002575 * @}
2576 */
2577
2578/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002579 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2580 *
2581 * Functions in this group only apply to instructions that map to
2582 * llvm::PHINode instances.
2583 *
2584 * @{
2585 */
2586
2587/**
2588 * Add an incoming value to the end of a PHI list.
2589 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002590void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2591 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002592
2593/**
2594 * Obtain the number of incoming basic blocks to a PHI node.
2595 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002596unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002597
2598/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002599 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002600 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002601LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002602
2603/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002604 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002605 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002606LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002607
Gregory Szorc34c863a2012-03-21 03:54:29 +00002608/**
2609 * @}
2610 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002611
Gregory Szorc34c863a2012-03-21 03:54:29 +00002612/**
2613 * @}
2614 */
2615
2616/**
2617 * @}
2618 */
2619
2620/**
2621 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2622 *
2623 * An instruction builder represents a point within a basic block and is
2624 * the exclusive means of building instructions using the C interface.
2625 *
2626 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002627 */
2628
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002629LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002630LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002631void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2632 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002633void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2634void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002635LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002636void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2637void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002638void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2639 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002640void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2641
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002642/* Metadata */
2643void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2644LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2645void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2646
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002647/* Terminators */
2648LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2649LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002650LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002651 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002652LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2653LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2654 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2655LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2656 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002657LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2658 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002659LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2660 LLVMValueRef *Args, unsigned NumArgs,
2661 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2662 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002663LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2664 LLVMValueRef PersFn, unsigned NumClauses,
2665 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002666LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002667LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2668
Gordon Henriksen097102c2008-01-01 05:50:53 +00002669/* Add a case to the switch instruction */
2670void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2671 LLVMBasicBlockRef Dest);
2672
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002673/* Add a destination to the indirectbr instruction */
2674void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2675
Bill Wendlingfae14752011-08-12 20:24:12 +00002676/* Add a catch or filter clause to the landingpad instruction */
2677void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2678
2679/* Set the 'cleanup' flag in the landingpad instruction */
2680void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2681
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002682/* Arithmetic */
2683LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2684 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002685LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2686 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002687LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2688 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002689LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2690 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002691LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2692 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002693LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2694 const char *Name);
2695LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2696 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002697LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2698 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002699LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2700 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002701LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2702 const char *Name);
2703LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2704 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002705LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2706 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002707LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2708 const char *Name);
2709LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2710 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002711LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2712 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002713LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2714 const char *Name);
2715LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2716 const char *Name);
2717LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2718 const char *Name);
2719LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2720 const char *Name);
2721LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2722 const char *Name);
2723LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2724 const char *Name);
2725LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2726 const char *Name);
2727LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2728 const char *Name);
2729LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2730 const char *Name);
2731LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2732 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002733LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2734 LLVMValueRef LHS, LLVMValueRef RHS,
2735 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002736LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002737LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2738 const char *Name);
2739LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2740 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002741LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002742LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2743
2744/* Memory */
2745LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2746LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2747 LLVMValueRef Val, const char *Name);
2748LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2749LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2750 LLVMValueRef Val, const char *Name);
2751LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2752LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2753 const char *Name);
2754LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2755LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2756 LLVMValueRef *Indices, unsigned NumIndices,
2757 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002758LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2759 LLVMValueRef *Indices, unsigned NumIndices,
2760 const char *Name);
2761LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2762 unsigned Idx, const char *Name);
2763LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2764 const char *Name);
2765LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2766 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002767LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2768void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002769
2770/* Casts */
2771LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2772 LLVMTypeRef DestTy, const char *Name);
2773LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2774 LLVMTypeRef DestTy, const char *Name);
2775LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2776 LLVMTypeRef DestTy, const char *Name);
2777LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2778 LLVMTypeRef DestTy, const char *Name);
2779LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2780 LLVMTypeRef DestTy, const char *Name);
2781LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2782 LLVMTypeRef DestTy, const char *Name);
2783LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2784 LLVMTypeRef DestTy, const char *Name);
2785LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2786 LLVMTypeRef DestTy, const char *Name);
2787LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2788 LLVMTypeRef DestTy, const char *Name);
2789LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2790 LLVMTypeRef DestTy, const char *Name);
2791LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2792 LLVMTypeRef DestTy, const char *Name);
2793LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2794 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002795LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2796 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002797LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2798 LLVMTypeRef DestTy, const char *Name);
2799LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2800 LLVMTypeRef DestTy, const char *Name);
2801LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2802 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002803LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2804 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002805LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2806 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002807LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002808 LLVMTypeRef DestTy, const char *Name);
2809LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2810 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002811
2812/* Comparisons */
2813LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2814 LLVMValueRef LHS, LLVMValueRef RHS,
2815 const char *Name);
2816LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2817 LLVMValueRef LHS, LLVMValueRef RHS,
2818 const char *Name);
2819
2820/* Miscellaneous instructions */
2821LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2822LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2823 LLVMValueRef *Args, unsigned NumArgs,
2824 const char *Name);
2825LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2826 LLVMValueRef Then, LLVMValueRef Else,
2827 const char *Name);
2828LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2829 const char *Name);
2830LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2831 LLVMValueRef Index, const char *Name);
2832LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2833 LLVMValueRef EltVal, LLVMValueRef Index,
2834 const char *Name);
2835LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2836 LLVMValueRef V2, LLVMValueRef Mask,
2837 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002838LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2839 unsigned Index, const char *Name);
2840LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2841 LLVMValueRef EltVal, unsigned Index,
2842 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002843
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002844LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2845 const char *Name);
2846LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2847 const char *Name);
2848LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2849 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00002850LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2851 LLVMBool singleThread, const char *Name);
2852LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00002853 LLVMValueRef PTR, LLVMValueRef Val,
2854 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00002855 LLVMBool singleThread);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002856
Gregory Szorc34c863a2012-03-21 03:54:29 +00002857/**
2858 * @}
2859 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002860
Gregory Szorc34c863a2012-03-21 03:54:29 +00002861/**
2862 * @defgroup LLVMCCoreModuleProvider Module Providers
2863 *
2864 * @{
2865 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002866
Gregory Szorc34c863a2012-03-21 03:54:29 +00002867/**
2868 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002869 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002870 */
2871LLVMModuleProviderRef
2872LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2873
Gregory Szorc34c863a2012-03-21 03:54:29 +00002874/**
2875 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002876 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002877void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002878
Gregory Szorc34c863a2012-03-21 03:54:29 +00002879/**
2880 * @}
2881 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002882
Gregory Szorc34c863a2012-03-21 03:54:29 +00002883/**
2884 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2885 *
2886 * @{
2887 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002888
Chris Lattner25963c62010-01-09 22:27:07 +00002889LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2890 LLVMMemoryBufferRef *OutMemBuf,
2891 char **OutMessage);
2892LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2893 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00002894LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2895 size_t InputDataLength,
2896 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00002897 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00002898LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2899 size_t InputDataLength,
2900 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00002901const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00002902size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002903void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2904
Gregory Szorc34c863a2012-03-21 03:54:29 +00002905/**
2906 * @}
2907 */
2908
2909/**
2910 * @defgroup LLVMCCorePassRegistry Pass Registry
2911 *
2912 * @{
2913 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002914
2915/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002916 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002917LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002918
Gregory Szorc34c863a2012-03-21 03:54:29 +00002919/**
2920 * @}
2921 */
2922
2923/**
2924 * @defgroup LLVMCCorePassManagers Pass Managers
2925 *
2926 * @{
2927 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002928
2929/** Constructs a new whole-module pass pipeline. This type of pipeline is
2930 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002931 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002932LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002933
2934/** Constructs a new function-by-function pass pipeline over the module
2935 provider. It does not take ownership of the module provider. This type of
2936 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002937 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002938LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2939
2940/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002941LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2942
2943/** Initializes, executes on the provided module, and finalizes all of the
2944 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002945 modified the module, 0 otherwise.
2946 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002947LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002948
2949/** Initializes all of the function passes scheduled in the function pass
2950 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002951 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002952LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002953
2954/** Executes all of the function passes scheduled in the function pass manager
2955 on the provided function. Returns 1 if any of the passes modified the
2956 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002957 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002958LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002959
2960/** Finalizes all of the function passes scheduled in in the function pass
2961 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002962 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002963LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002964
2965/** Frees the memory of a pass pipeline. For function pipelines, does not free
2966 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002967 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002968void LLVMDisposePassManager(LLVMPassManagerRef PM);
2969
Gregory Szorc34c863a2012-03-21 03:54:29 +00002970/**
2971 * @}
2972 */
2973
2974/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00002975 * @defgroup LLVMCCoreThreading Threading
2976 *
2977 * Handle the structures needed to make LLVM safe for multithreading.
2978 *
2979 * @{
2980 */
2981
Chandler Carruth39cd2162014-06-27 15:13:01 +00002982/** Deprecated: Multi-threading can only be enabled/disabled with the compile
2983 time define LLVM_ENABLE_THREADS. This function always returns
2984 LLVMIsMultithreaded(). */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002985LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002986
Chandler Carruth39cd2162014-06-27 15:13:01 +00002987/** Deprecated: Multi-threading can only be enabled/disabled with the compile
2988 time define LLVM_ENABLE_THREADS. */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002989void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002990
2991/** Check whether LLVM is executing in thread-safe mode or not.
2992 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002993LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002994
2995/**
2996 * @}
2997 */
2998
2999/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00003000 * @}
3001 */
3002
3003/**
3004 * @}
3005 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00003006
Gordon Henriksen76a03742007-09-18 03:18:57 +00003007#ifdef __cplusplus
3008}
Evan Cheng2e254d02013-04-04 17:40:53 +00003009#endif /* !defined(__cplusplus) */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00003010
Evan Cheng2e254d02013-04-04 17:40:53 +00003011#endif /* !defined(LLVM_C_CORE_H) */