blob: 151165e704d752063dfb492c60c068e81fff294b [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,
168 LLVMInAllocaAttribute = 1ULL << 36
Nuno Lopesdef4229972012-09-02 14:19:21 +0000169 */
Devang Patel4c758ea2008-09-25 21:00:45 +0000170} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000171
172typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000173 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000174 LLVMRet = 1,
175 LLVMBr = 2,
176 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000177 LLVMIndirectBr = 4,
178 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000179 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000180 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000181
Bill Wendlingda52cec2010-02-15 20:53:17 +0000182 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000183 LLVMAdd = 8,
184 LLVMFAdd = 9,
185 LLVMSub = 10,
186 LLVMFSub = 11,
187 LLVMMul = 12,
188 LLVMFMul = 13,
189 LLVMUDiv = 14,
190 LLVMSDiv = 15,
191 LLVMFDiv = 16,
192 LLVMURem = 17,
193 LLVMSRem = 18,
194 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000195
Bill Wendlingda52cec2010-02-15 20:53:17 +0000196 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000197 LLVMShl = 20,
198 LLVMLShr = 21,
199 LLVMAShr = 22,
200 LLVMAnd = 23,
201 LLVMOr = 24,
202 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000203
Bill Wendlingda52cec2010-02-15 20:53:17 +0000204 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000205 LLVMAlloca = 26,
206 LLVMLoad = 27,
207 LLVMStore = 28,
208 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000209
Bill Wendlingda52cec2010-02-15 20:53:17 +0000210 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000211 LLVMTrunc = 30,
212 LLVMZExt = 31,
213 LLVMSExt = 32,
214 LLVMFPToUI = 33,
215 LLVMFPToSI = 34,
216 LLVMUIToFP = 35,
217 LLVMSIToFP = 36,
218 LLVMFPTrunc = 37,
219 LLVMFPExt = 38,
220 LLVMPtrToInt = 39,
221 LLVMIntToPtr = 40,
222 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000223 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000224
Bill Wendlingda52cec2010-02-15 20:53:17 +0000225 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000226 LLVMICmp = 42,
227 LLVMFCmp = 43,
228 LLVMPHI = 44,
229 LLVMCall = 45,
230 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000231 LLVMUserOp1 = 47,
232 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000233 LLVMVAArg = 49,
234 LLVMExtractElement = 50,
235 LLVMInsertElement = 51,
236 LLVMShuffleVector = 52,
237 LLVMExtractValue = 53,
238 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000239
240 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000241 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000242 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000243 LLVMAtomicRMW = 57,
244
245 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000246 LLVMResume = 58,
Bill Wendling0aef16a2012-02-06 21:44:22 +0000247 LLVMLandingPad = 59
Bill Wendling2641d132011-07-27 21:00:28 +0000248
Chris Lattner40cf28d2009-10-12 04:01:02 +0000249} LLVMOpcode;
250
251typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000252 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000253 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000254 LLVMFloatTypeKind, /**< 32 bit floating point type */
255 LLVMDoubleTypeKind, /**< 64 bit floating point type */
256 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
257 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
258 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
259 LLVMLabelTypeKind, /**< Labels */
260 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
261 LLVMFunctionTypeKind, /**< Functions */
262 LLVMStructTypeKind, /**< Structures */
263 LLVMArrayTypeKind, /**< Arrays */
264 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000265 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000266 LLVMMetadataTypeKind, /**< Metadata */
267 LLVMX86_MMXTypeKind /**< X86 MMX */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000268} LLVMTypeKind;
269
270typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000271 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000272 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000273 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
274 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
275 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000276 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000277 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
278 LLVMWeakODRLinkage, /**< Same, but only replaced by something
279 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000280 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
281 LLVMInternalLinkage, /**< Rename collisions when linking (static
282 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000283 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000284 LLVMDLLImportLinkage, /**< Obsolete */
285 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000286 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000287 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000288 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000289 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000290 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000291} LLVMLinkage;
292
293typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000294 LLVMDefaultVisibility, /**< The GV is visible */
295 LLVMHiddenVisibility, /**< The GV is hidden */
296 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000297} LLVMVisibility;
298
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000299typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000300 LLVMDefaultStorageClass = 0,
301 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
302 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
303} LLVMDLLStorageClass;
304
305typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000306 LLVMCCallConv = 0,
307 LLVMFastCallConv = 8,
308 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000309 LLVMWebKitJSCallConv = 12,
310 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000311 LLVMX86StdcallCallConv = 64,
312 LLVMX86FastcallCallConv = 65
313} LLVMCallConv;
314
315typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000316 LLVMIntEQ = 32, /**< equal */
317 LLVMIntNE, /**< not equal */
318 LLVMIntUGT, /**< unsigned greater than */
319 LLVMIntUGE, /**< unsigned greater or equal */
320 LLVMIntULT, /**< unsigned less than */
321 LLVMIntULE, /**< unsigned less or equal */
322 LLVMIntSGT, /**< signed greater than */
323 LLVMIntSGE, /**< signed greater or equal */
324 LLVMIntSLT, /**< signed less than */
325 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000326} LLVMIntPredicate;
327
328typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000329 LLVMRealPredicateFalse, /**< Always false (always folded) */
330 LLVMRealOEQ, /**< True if ordered and equal */
331 LLVMRealOGT, /**< True if ordered and greater than */
332 LLVMRealOGE, /**< True if ordered and greater than or equal */
333 LLVMRealOLT, /**< True if ordered and less than */
334 LLVMRealOLE, /**< True if ordered and less than or equal */
335 LLVMRealONE, /**< True if ordered and operands are unequal */
336 LLVMRealORD, /**< True if ordered (no nans) */
337 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
338 LLVMRealUEQ, /**< True if unordered or equal */
339 LLVMRealUGT, /**< True if unordered or greater than */
340 LLVMRealUGE, /**< True if unordered, greater than, or equal */
341 LLVMRealULT, /**< True if unordered or less than */
342 LLVMRealULE, /**< True if unordered, less than, or equal */
343 LLVMRealUNE, /**< True if unordered or not equal */
344 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000345} LLVMRealPredicate;
346
Bill Wendlingfae14752011-08-12 20:24:12 +0000347typedef enum {
348 LLVMLandingPadCatch, /**< A catch clause */
349 LLVMLandingPadFilter /**< A filter clause */
350} LLVMLandingPadClauseTy;
351
Hans Wennborg5ff71202013-04-16 08:58:59 +0000352typedef enum {
353 LLVMNotThreadLocal = 0,
354 LLVMGeneralDynamicTLSModel,
355 LLVMLocalDynamicTLSModel,
356 LLVMInitialExecTLSModel,
357 LLVMLocalExecTLSModel
358} LLVMThreadLocalMode;
359
Carlo Kokda0ac722013-04-23 13:45:37 +0000360typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000361 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
362 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
363 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000364 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
365 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000366 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000367 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
368 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000369 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000370 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
371 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000372 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000373 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
374 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000375 operations which both read and write
376 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000377 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
378 for loads and Release
379 semantics for stores.
380 Additionally, it guarantees
381 that a total ordering exists
382 between all
383 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000384 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000385} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000386
Carlo Kokda0ac722013-04-23 13:45:37 +0000387typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000388 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
389 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
390 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
391 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
392 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
393 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
394 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
395 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000396 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000397 the old one */
398 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000399 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000400 the old one */
401 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000402 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000403 the old one */
404 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000405 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000406 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000407} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000408
Tom Stellard1580dc72014-04-16 17:45:04 +0000409typedef enum {
410 LLVMDSError,
411 LLVMDSWarning,
412 LLVMDSRemark,
413 LLVMDSNote
414} LLVMDiagnosticSeverity;
415
Gregory Szorc34c863a2012-03-21 03:54:29 +0000416/**
417 * @}
418 */
419
Nick Lewycky0db26542011-05-15 07:20:34 +0000420void LLVMInitializeCore(LLVMPassRegistryRef R);
421
Duncan Sands1cba0a82013-02-17 16:35:51 +0000422/** Deallocate and destroy all ManagedStatic variables.
423 @see llvm::llvm_shutdown
424 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000425void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000426
Gordon Henriksen76a03742007-09-18 03:18:57 +0000427
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000428/*===-- Error handling ----------------------------------------------------===*/
429
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000430char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000431void LLVMDisposeMessage(char *Message);
432
Filip Pizloa535b142013-10-17 01:38:28 +0000433typedef void (*LLVMFatalErrorHandler)(const char *Reason);
434
435/**
436 * Install a fatal error handler. By default, if LLVM detects a fatal error, it
437 * will call exit(1). This may not be appropriate in many contexts. For example,
438 * doing exit(1) will bypass many crash reporting/tracing system tools. This
439 * function allows you to install a callback that will be invoked prior to the
440 * call to exit(1).
441 */
442void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
443
444/**
445 * Reset the fatal error handler. This resets LLVM's fatal error handling
446 * behavior to the default.
447 */
448void LLVMResetFatalErrorHandler(void);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000449
Gregory Szorc34c863a2012-03-21 03:54:29 +0000450/**
Filip Pizloc10ca902013-11-04 02:22:25 +0000451 * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
452 * signals and prints which component of LLVM you were in at the time if the
453 * crash.
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000454 */
Filip Pizloc10ca902013-11-04 02:22:25 +0000455void LLVMEnablePrettyStackTrace(void);
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000456
457/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000458 * @defgroup LLVMCCoreContext Contexts
459 *
460 * Contexts are execution states for the core LLVM IR system.
461 *
462 * Most types are tied to a context instance. Multiple contexts can
463 * exist simultaneously. A single context is not thread safe. However,
464 * different contexts can execute on different threads simultaneously.
465 *
466 * @{
467 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000468
Tom Stellard1580dc72014-04-16 17:45:04 +0000469typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000470typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000471
Gregory Szorc34c863a2012-03-21 03:54:29 +0000472/**
473 * Create a new context.
474 *
475 * Every call to this function should be paired with a call to
476 * LLVMContextDispose() or the context will leak memory.
477 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000478LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000479
480/**
481 * Obtain the global context instance.
482 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000483LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000484
485/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000486 * Set the diagnostic handler for this context.
487 */
488void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
489 LLVMDiagnosticHandler Handler,
490 void *DiagnosticContext);
491
492/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000493 * Set the yield callback function for this context.
494 *
495 * @see LLVMContext::setYieldCallback()
496 */
497void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
498 void *OpaqueHandle);
499
500/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000501 * Destroy a context instance.
502 *
503 * This should be called for every call to LLVMContextCreate() or memory
504 * will be leaked.
505 */
Owen Anderson6773d382009-07-01 16:58:40 +0000506void LLVMContextDispose(LLVMContextRef C);
507
Tom Stellard1580dc72014-04-16 17:45:04 +0000508/**
509 * Return a string representation of the DiagnosticInfo. Use
510 * LLVMDisposeMessage to free the string.
511 *
512 * @see DiagnosticInfo::print()
513 */
514char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
515
516/**
517 * Return an enum LLVMDiagnosticSeverity.
518 *
519 * @see DiagnosticInfo::getSeverity()
520 */
521LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
522
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000523unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
524 unsigned SLen);
525unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
526
Gregory Szorc34c863a2012-03-21 03:54:29 +0000527/**
528 * @}
529 */
530
Gregory Szorc52d26602012-03-21 07:28:27 +0000531/**
532 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000533 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000534 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000535 * module is effectively a translation unit or a collection of
536 * translation units merged together.
537 *
538 * @{
539 */
540
Gregory Szorc34c863a2012-03-21 03:54:29 +0000541/**
542 * Create a new, empty module in the global context.
543 *
544 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
545 * LLVMGetGlobalContext() as the context parameter.
546 *
547 * Every invocation should be paired with LLVMDisposeModule() or memory
548 * will be leaked.
549 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000550LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000551
552/**
553 * Create a new, empty module in a specific context.
554 *
555 * Every invocation should be paired with LLVMDisposeModule() or memory
556 * will be leaked.
557 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000558LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
559 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000560
Gregory Szorc34c863a2012-03-21 03:54:29 +0000561/**
562 * Destroy a module instance.
563 *
564 * This must be called for every created module or memory will be
565 * leaked.
566 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000567void LLVMDisposeModule(LLVMModuleRef M);
568
Gregory Szorc34c863a2012-03-21 03:54:29 +0000569/**
570 * Obtain the data layout for a module.
571 *
572 * @see Module::getDataLayout()
573 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000574const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000575
576/**
577 * Set the data layout for a module.
578 *
579 * @see Module::setDataLayout()
580 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000581void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
582
Gregory Szorc34c863a2012-03-21 03:54:29 +0000583/**
584 * Obtain the target triple for a module.
585 *
586 * @see Module::getTargetTriple()
587 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000588const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000589
590/**
591 * Set the target triple for a module.
592 *
593 * @see Module::setTargetTriple()
594 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000595void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
596
Gregory Szorc34c863a2012-03-21 03:54:29 +0000597/**
598 * Dump a representation of a module to stderr.
599 *
600 * @see Module::dump()
601 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000602void LLVMDumpModule(LLVMModuleRef M);
603
Gregory Szorc34c863a2012-03-21 03:54:29 +0000604/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000605 * Print a representation of a module to a file. The ErrorMessage needs to be
606 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
607 *
608 * @see Module::print()
609 */
610LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
611 char **ErrorMessage);
612
613/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000614 * Return a string representation of the module. Use
615 * LLVMDisposeMessage to free the string.
616 *
617 * @see Module::print()
618 */
619char *LLVMPrintModuleToString(LLVMModuleRef M);
620
621/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000622 * Set inline assembly for a module.
623 *
624 * @see Module::setModuleInlineAsm()
625 */
Chris Lattner26941452010-04-10 17:52:58 +0000626void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000627
Gregory Szorc34c863a2012-03-21 03:54:29 +0000628/**
629 * Obtain the context to which this module is associated.
630 *
631 * @see Module::getContext()
632 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000633LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
634
Gregory Szorc34c863a2012-03-21 03:54:29 +0000635/**
636 * Obtain a Type from a module by its registered name.
637 */
638LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000639
Gregory Szorc34c863a2012-03-21 03:54:29 +0000640/**
641 * Obtain the number of operands for named metadata in a module.
642 *
643 * @see llvm::Module::getNamedMetadata()
644 */
645unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
646
647/**
648 * Obtain the named metadata operands for a module.
649 *
650 * The passed LLVMValueRef pointer should refer to an array of
651 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
652 * array will be populated with the LLVMValueRef instances. Each
653 * instance corresponds to a llvm::MDNode.
654 *
655 * @see llvm::Module::getNamedMetadata()
656 * @see llvm::MDNode::getOperand()
657 */
658void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
659
660/**
661 * Add an operand to named metadata.
662 *
663 * @see llvm::Module::getNamedMetadata()
664 * @see llvm::MDNode::addOperand()
665 */
666void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
667 LLVMValueRef Val);
668
Gregory Szorc52d26602012-03-21 07:28:27 +0000669/**
670 * Add a function to a module under a specified name.
671 *
672 * @see llvm::Function::Create()
673 */
674LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
675 LLVMTypeRef FunctionTy);
676
677/**
678 * Obtain a Function value from a Module by its name.
679 *
680 * The returned value corresponds to a llvm::Function value.
681 *
682 * @see llvm::Module::getFunction()
683 */
684LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
685
686/**
687 * Obtain an iterator to the first Function in a Module.
688 *
689 * @see llvm::Module::begin()
690 */
691LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
692
693/**
694 * Obtain an iterator to the last Function in a Module.
695 *
696 * @see llvm::Module::end()
697 */
698LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
699
700/**
701 * Advance a Function iterator to the next Function.
702 *
703 * Returns NULL if the iterator was already at the end and there are no more
704 * functions.
705 */
706LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
707
708/**
709 * Decrement a Function iterator to the previous Function.
710 *
711 * Returns NULL if the iterator was already at the beginning and there are
712 * no previous functions.
713 */
714LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000715
716/**
717 * @}
718 */
719
720/**
721 * @defgroup LLVMCCoreType Types
722 *
723 * Types represent the type of a value.
724 *
725 * Types are associated with a context instance. The context internally
726 * deduplicates types so there is only 1 instance of a specific type
727 * alive at a time. In other words, a unique type is shared among all
728 * consumers within a context.
729 *
730 * A Type in the C API corresponds to llvm::Type.
731 *
732 * Types have the following hierarchy:
733 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000734 * types:
735 * integer type
736 * real type
737 * function type
738 * sequence types:
739 * array type
740 * pointer type
741 * vector type
742 * void type
743 * label type
744 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000745 *
746 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000747 */
748
Gregory Szorc34c863a2012-03-21 03:54:29 +0000749/**
750 * Obtain the enumerated type of a Type instance.
751 *
752 * @see llvm::Type:getTypeID()
753 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000754LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000755
756/**
757 * Whether the type has a known size.
758 *
759 * Things that don't have a size are abstract types, labels, and void.a
760 *
761 * @see llvm::Type::isSized()
762 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000763LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000764
Gregory Szorc34c863a2012-03-21 03:54:29 +0000765/**
766 * Obtain the context to which this type instance is associated.
767 *
768 * @see llvm::Type::getContext()
769 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000770LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
771
Gregory Szorc34c863a2012-03-21 03:54:29 +0000772/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000773 * Dump a representation of a type to stderr.
774 *
775 * @see llvm::Type::dump()
776 */
777void LLVMDumpType(LLVMTypeRef Val);
778
779/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000780 * Return a string representation of the type. Use
781 * LLVMDisposeMessage to free the string.
782 *
783 * @see llvm::Type::print()
784 */
785char *LLVMPrintTypeToString(LLVMTypeRef Val);
786
787/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000788 * @defgroup LLVMCCoreTypeInt Integer Types
789 *
790 * Functions in this section operate on integer types.
791 *
792 * @{
793 */
794
795/**
796 * Obtain an integer type from a context with specified bit width.
797 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000798LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
799LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
800LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
801LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
802LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
803LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
804
Gregory Szorc34c863a2012-03-21 03:54:29 +0000805/**
806 * Obtain an integer type from the global context with a specified bit
807 * width.
808 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000809LLVMTypeRef LLVMInt1Type(void);
810LLVMTypeRef LLVMInt8Type(void);
811LLVMTypeRef LLVMInt16Type(void);
812LLVMTypeRef LLVMInt32Type(void);
813LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000814LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000815unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000816
Gregory Szorc34c863a2012-03-21 03:54:29 +0000817/**
818 * @}
819 */
820
821/**
822 * @defgroup LLVMCCoreTypeFloat Floating Point Types
823 *
824 * @{
825 */
826
827/**
828 * Obtain a 16-bit floating point type from a context.
829 */
Dan Gohman518cda42011-12-17 00:04:22 +0000830LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000831
832/**
833 * Obtain a 32-bit floating point type from a context.
834 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000835LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000836
837/**
838 * Obtain a 64-bit floating point type from a context.
839 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000840LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000841
842/**
843 * Obtain a 80-bit floating point type (X87) from a context.
844 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000845LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000846
847/**
848 * Obtain a 128-bit floating point type (112-bit mantissa) from a
849 * context.
850 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000851LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000852
853/**
854 * Obtain a 128-bit floating point type (two 64-bits) from a context.
855 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000856LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
857
Gregory Szorc34c863a2012-03-21 03:54:29 +0000858/**
859 * Obtain a floating point type from the global context.
860 *
861 * These map to the functions in this group of the same name.
862 */
Dan Gohman518cda42011-12-17 00:04:22 +0000863LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000864LLVMTypeRef LLVMFloatType(void);
865LLVMTypeRef LLVMDoubleType(void);
866LLVMTypeRef LLVMX86FP80Type(void);
867LLVMTypeRef LLVMFP128Type(void);
868LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000869
Gregory Szorc34c863a2012-03-21 03:54:29 +0000870/**
871 * @}
872 */
873
874/**
875 * @defgroup LLVMCCoreTypeFunction Function Types
876 *
877 * @{
878 */
879
880/**
881 * Obtain a function type consisting of a specified signature.
882 *
883 * The function is defined as a tuple of a return Type, a list of
884 * parameter types, and whether the function is variadic.
885 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000886LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
887 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000888 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000889
890/**
891 * Returns whether a function type is variadic.
892 */
Chris Lattner25963c62010-01-09 22:27:07 +0000893LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000894
895/**
896 * Obtain the Type this function Type returns.
897 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000898LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000899
900/**
901 * Obtain the number of parameters this function accepts.
902 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000903unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000904
905/**
906 * Obtain the types of a function's parameters.
907 *
908 * The Dest parameter should point to a pre-allocated array of
909 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
910 * first LLVMCountParamTypes() entries in the array will be populated
911 * with LLVMTypeRef instances.
912 *
913 * @param FunctionTy The function type to operate on.
914 * @param Dest Memory address of an array to be filled with result.
915 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000916void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000917
Gregory Szorc34c863a2012-03-21 03:54:29 +0000918/**
919 * @}
920 */
921
922/**
923 * @defgroup LLVMCCoreTypeStruct Structure Types
924 *
925 * These functions relate to LLVMTypeRef instances.
926 *
927 * @see llvm::StructType
928 *
929 * @{
930 */
931
932/**
933 * Create a new structure type in a context.
934 *
935 * A structure is specified by a list of inner elements/types and
936 * whether these can be packed together.
937 *
938 * @see llvm::StructType::create()
939 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000940LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000941 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000942
943/**
944 * Create a new structure type in the global context.
945 *
946 * @see llvm::StructType::create()
947 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000948LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000949 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000950
951/**
952 * Create an empty structure in a context having a specified name.
953 *
954 * @see llvm::StructType::create()
955 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000956LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000957
958/**
959 * Obtain the name of a structure.
960 *
961 * @see llvm::StructType::getName()
962 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000963const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000964
965/**
966 * Set the contents of a structure type.
967 *
968 * @see llvm::StructType::setBody()
969 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000970void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
971 unsigned ElementCount, LLVMBool Packed);
972
Gregory Szorc34c863a2012-03-21 03:54:29 +0000973/**
974 * Get the number of elements defined inside the structure.
975 *
976 * @see llvm::StructType::getNumElements()
977 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000978unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000979
980/**
981 * Get the elements within a structure.
982 *
983 * The function is passed the address of a pre-allocated array of
984 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
985 * invocation, this array will be populated with the structure's
986 * elements. The objects in the destination array will have a lifetime
987 * of the structure type itself, which is the lifetime of the context it
988 * is contained in.
989 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000990void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000991
992/**
993 * Determine whether a structure is packed.
994 *
995 * @see llvm::StructType::isPacked()
996 */
Chris Lattner25963c62010-01-09 22:27:07 +0000997LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000998
999/**
1000 * Determine whether a structure is opaque.
1001 *
1002 * @see llvm::StructType::isOpaque()
1003 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001004LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1005
Gregory Szorc34c863a2012-03-21 03:54:29 +00001006/**
1007 * @}
1008 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001009
Gregory Szorc34c863a2012-03-21 03:54:29 +00001010
1011/**
1012 * @defgroup LLVMCCoreTypeSequential Sequential Types
1013 *
1014 * Sequential types represents "arrays" of types. This is a super class
1015 * for array, vector, and pointer types.
1016 *
1017 * @{
1018 */
1019
1020/**
1021 * Obtain the type of elements within a sequential type.
1022 *
1023 * This works on array, vector, and pointer types.
1024 *
1025 * @see llvm::SequentialType::getElementType()
1026 */
1027LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1028
1029/**
1030 * Create a fixed size array type that refers to a specific type.
1031 *
1032 * The created type will exist in the context that its element type
1033 * exists in.
1034 *
1035 * @see llvm::ArrayType::get()
1036 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001037LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001038
1039/**
1040 * Obtain the length of an array type.
1041 *
1042 * This only works on types that represent arrays.
1043 *
1044 * @see llvm::ArrayType::getNumElements()
1045 */
1046unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1047
1048/**
1049 * Create a pointer type that points to a defined type.
1050 *
1051 * The created type will exist in the context that its pointee type
1052 * exists in.
1053 *
1054 * @see llvm::PointerType::get()
1055 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001056LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001057
1058/**
1059 * Obtain the address space of a pointer type.
1060 *
1061 * This only works on types that represent pointers.
1062 *
1063 * @see llvm::PointerType::getAddressSpace()
1064 */
1065unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1066
1067/**
1068 * Create a vector type that contains a defined type and has a specific
1069 * number of elements.
1070 *
1071 * The created type will exist in the context thats its element type
1072 * exists in.
1073 *
1074 * @see llvm::VectorType::get()
1075 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001076LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001077
Gregory Szorc34c863a2012-03-21 03:54:29 +00001078/**
1079 * Obtain the number of elements in a vector type.
1080 *
1081 * This only works on types that represent vectors.
1082 *
1083 * @see llvm::VectorType::getNumElements()
1084 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001085unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1086
Gregory Szorc34c863a2012-03-21 03:54:29 +00001087/**
1088 * @}
1089 */
1090
1091/**
1092 * @defgroup LLVMCCoreTypeOther Other Types
1093 *
1094 * @{
1095 */
1096
1097/**
1098 * Create a void type in a context.
1099 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001100LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001101
1102/**
1103 * Create a label type in a context.
1104 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001105LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001106
1107/**
1108 * Create a X86 MMX type in a context.
1109 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001110LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001111
Gregory Szorc34c863a2012-03-21 03:54:29 +00001112/**
1113 * These are similar to the above functions except they operate on the
1114 * global context.
1115 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001116LLVMTypeRef LLVMVoidType(void);
1117LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001118LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001119
Gregory Szorc34c863a2012-03-21 03:54:29 +00001120/**
1121 * @}
1122 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001123
Gregory Szorc34c863a2012-03-21 03:54:29 +00001124/**
1125 * @}
1126 */
1127
1128/**
1129 * @defgroup LLVMCCoreValues Values
1130 *
1131 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001132 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001133 *
1134 * LLVMValueRef essentially represents llvm::Value. There is a rich
1135 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001136 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001137 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001138 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001139 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1140 * functions are defined by a macro, so it isn't obvious which are
1141 * available by looking at the Doxygen source code. Instead, look at the
1142 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1143 * of value names given. These value names also correspond to classes in
1144 * the llvm::Value hierarchy.
1145 *
1146 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001147 */
1148
Gordon Henriksen29e38942008-12-19 18:39:45 +00001149#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1150 macro(Argument) \
1151 macro(BasicBlock) \
1152 macro(InlineAsm) \
Torok Edwind09b7572011-10-14 20:37:56 +00001153 macro(MDNode) \
1154 macro(MDString) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001155 macro(User) \
1156 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001157 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001158 macro(ConstantAggregateZero) \
1159 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001160 macro(ConstantDataSequential) \
1161 macro(ConstantDataArray) \
1162 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001163 macro(ConstantExpr) \
1164 macro(ConstantFP) \
1165 macro(ConstantInt) \
1166 macro(ConstantPointerNull) \
1167 macro(ConstantStruct) \
1168 macro(ConstantVector) \
1169 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001170 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001171 macro(GlobalObject) \
1172 macro(Function) \
1173 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001174 macro(UndefValue) \
1175 macro(Instruction) \
1176 macro(BinaryOperator) \
1177 macro(CallInst) \
1178 macro(IntrinsicInst) \
1179 macro(DbgInfoIntrinsic) \
1180 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001181 macro(MemIntrinsic) \
1182 macro(MemCpyInst) \
1183 macro(MemMoveInst) \
1184 macro(MemSetInst) \
1185 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001186 macro(FCmpInst) \
1187 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001188 macro(ExtractElementInst) \
1189 macro(GetElementPtrInst) \
1190 macro(InsertElementInst) \
1191 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001192 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001193 macro(PHINode) \
1194 macro(SelectInst) \
1195 macro(ShuffleVectorInst) \
1196 macro(StoreInst) \
1197 macro(TerminatorInst) \
1198 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001199 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001200 macro(InvokeInst) \
1201 macro(ReturnInst) \
1202 macro(SwitchInst) \
1203 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001204 macro(ResumeInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001205 macro(UnaryInstruction) \
1206 macro(AllocaInst) \
1207 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001208 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001209 macro(BitCastInst) \
1210 macro(FPExtInst) \
1211 macro(FPToSIInst) \
1212 macro(FPToUIInst) \
1213 macro(FPTruncInst) \
1214 macro(IntToPtrInst) \
1215 macro(PtrToIntInst) \
1216 macro(SExtInst) \
1217 macro(SIToFPInst) \
1218 macro(TruncInst) \
1219 macro(UIToFPInst) \
1220 macro(ZExtInst) \
1221 macro(ExtractValueInst) \
1222 macro(LoadInst) \
1223 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001224
Gregory Szorc34c863a2012-03-21 03:54:29 +00001225/**
1226 * @defgroup LLVMCCoreValueGeneral General APIs
1227 *
1228 * Functions in this section work on all LLVMValueRef instances,
1229 * regardless of their sub-type. They correspond to functions available
1230 * on llvm::Value.
1231 *
1232 * @{
1233 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001234
Gregory Szorc34c863a2012-03-21 03:54:29 +00001235/**
1236 * Obtain the type of a value.
1237 *
1238 * @see llvm::Value::getType()
1239 */
1240LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1241
1242/**
1243 * Obtain the string name of a value.
1244 *
1245 * @see llvm::Value::getName()
1246 */
1247const char *LLVMGetValueName(LLVMValueRef Val);
1248
1249/**
1250 * Set the string name of a value.
1251 *
1252 * @see llvm::Value::setName()
1253 */
1254void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1255
1256/**
1257 * Dump a representation of a value to stderr.
1258 *
1259 * @see llvm::Value::dump()
1260 */
1261void LLVMDumpValue(LLVMValueRef Val);
1262
1263/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001264 * Return a string representation of the value. Use
1265 * LLVMDisposeMessage to free the string.
1266 *
1267 * @see llvm::Value::print()
1268 */
1269char *LLVMPrintValueToString(LLVMValueRef Val);
1270
1271/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001272 * Replace all uses of a value with another one.
1273 *
1274 * @see llvm::Value::replaceAllUsesWith()
1275 */
1276void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1277
1278/**
1279 * Determine whether the specified constant instance is constant.
1280 */
1281LLVMBool LLVMIsConstant(LLVMValueRef Val);
1282
1283/**
1284 * Determine whether a value instance is undefined.
1285 */
1286LLVMBool LLVMIsUndef(LLVMValueRef Val);
1287
1288/**
1289 * Convert value instances between types.
1290 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001291 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001292 * series of functions allows you to cast an instance to a specific
1293 * type.
1294 *
1295 * If the cast is not valid for the specified type, NULL is returned.
1296 *
1297 * @see llvm::dyn_cast_or_null<>
1298 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001299#define LLVM_DECLARE_VALUE_CAST(name) \
1300 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1301LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1302
Gregory Szorc34c863a2012-03-21 03:54:29 +00001303/**
1304 * @}
1305 */
1306
1307/**
1308 * @defgroup LLVMCCoreValueUses Usage
1309 *
1310 * This module defines functions that allow you to inspect the uses of a
1311 * LLVMValueRef.
1312 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001313 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001314 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1315 * llvm::User and llvm::Value.
1316 *
1317 * @{
1318 */
1319
1320/**
1321 * Obtain the first use of a value.
1322 *
1323 * Uses are obtained in an iterator fashion. First, call this function
1324 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001325 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001326 * LLVMGetNextUse() returns NULL.
1327 *
1328 * @see llvm::Value::use_begin()
1329 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001330LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001331
1332/**
1333 * Obtain the next use of a value.
1334 *
1335 * This effectively advances the iterator. It returns NULL if you are on
1336 * the final use and no more are available.
1337 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001338LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001339
1340/**
1341 * Obtain the user value for a user.
1342 *
1343 * The returned value corresponds to a llvm::User type.
1344 *
1345 * @see llvm::Use::getUser()
1346 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001347LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001348
1349/**
1350 * Obtain the value this use corresponds to.
1351 *
1352 * @see llvm::Use::get().
1353 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001354LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001355
Gregory Szorc34c863a2012-03-21 03:54:29 +00001356/**
1357 * @}
1358 */
1359
1360/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001361 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001362 *
1363 * Function in this group pertain to LLVMValueRef instances that descent
1364 * from llvm::User. This includes constants, instructions, and
1365 * operators.
1366 *
1367 * @{
1368 */
1369
1370/**
1371 * Obtain an operand at a specific index in a llvm::User value.
1372 *
1373 * @see llvm::User::getOperand()
1374 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001375LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001376
1377/**
1378 * Set an operand at a specific index in a llvm::User value.
1379 *
1380 * @see llvm::User::setOperand()
1381 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001382void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001383
1384/**
1385 * Obtain the number of operands in a llvm::User value.
1386 *
1387 * @see llvm::User::getNumOperands()
1388 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001389int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001390
Gregory Szorc34c863a2012-03-21 03:54:29 +00001391/**
1392 * @}
1393 */
1394
1395/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001396 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001397 *
1398 * This section contains APIs for interacting with LLVMValueRef that
1399 * correspond to llvm::Constant instances.
1400 *
1401 * These functions will work for any LLVMValueRef in the llvm::Constant
1402 * class hierarchy.
1403 *
1404 * @{
1405 */
1406
1407/**
1408 * Obtain a constant value referring to the null instance of a type.
1409 *
1410 * @see llvm::Constant::getNullValue()
1411 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001412LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001413
1414/**
1415 * Obtain a constant value referring to the instance of a type
1416 * consisting of all ones.
1417 *
1418 * This is only valid for integer types.
1419 *
1420 * @see llvm::Constant::getAllOnesValue()
1421 */
1422LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1423
1424/**
1425 * Obtain a constant value referring to an undefined value of a type.
1426 *
1427 * @see llvm::UndefValue::get()
1428 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001429LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001430
1431/**
1432 * Determine whether a value instance is null.
1433 *
1434 * @see llvm::Constant::isNullValue()
1435 */
Chris Lattner25963c62010-01-09 22:27:07 +00001436LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001437
1438/**
1439 * Obtain a constant that is a constant pointer pointing to NULL for a
1440 * specified type.
1441 */
Chris Lattner7f318242009-07-06 17:29:59 +00001442LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001443
Gregory Szorc34c863a2012-03-21 03:54:29 +00001444/**
1445 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1446 *
1447 * Functions in this group model LLVMValueRef instances that correspond
1448 * to constants referring to scalar types.
1449 *
1450 * For integer types, the LLVMTypeRef parameter should correspond to a
1451 * llvm::IntegerType instance and the returned LLVMValueRef will
1452 * correspond to a llvm::ConstantInt.
1453 *
1454 * For floating point types, the LLVMTypeRef returned corresponds to a
1455 * llvm::ConstantFP.
1456 *
1457 * @{
1458 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001459
Gregory Szorc34c863a2012-03-21 03:54:29 +00001460/**
1461 * Obtain a constant value for an integer type.
1462 *
1463 * The returned value corresponds to a llvm::ConstantInt.
1464 *
1465 * @see llvm::ConstantInt::get()
1466 *
1467 * @param IntTy Integer type to obtain value of.
1468 * @param N The value the returned instance should refer to.
1469 * @param SignExtend Whether to sign extend the produced value.
1470 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001471LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001472 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001473
1474/**
1475 * Obtain a constant value for an integer of arbitrary precision.
1476 *
1477 * @see llvm::ConstantInt::get()
1478 */
Chris Lattner4329e072010-11-23 02:47:22 +00001479LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1480 unsigned NumWords,
1481 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001482
1483/**
1484 * Obtain a constant value for an integer parsed from a string.
1485 *
1486 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1487 * string's length is available, it is preferred to call that function
1488 * instead.
1489 *
1490 * @see llvm::ConstantInt::get()
1491 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001492LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1493 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001494
1495/**
1496 * Obtain a constant value for an integer parsed from a string with
1497 * specified length.
1498 *
1499 * @see llvm::ConstantInt::get()
1500 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001501LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1502 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001503
1504/**
1505 * Obtain a constant value referring to a double floating point value.
1506 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001507LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001508
1509/**
1510 * Obtain a constant for a floating point value parsed from a string.
1511 *
1512 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1513 * should be used if the input string's length is known.
1514 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001515LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001516
1517/**
1518 * Obtain a constant for a floating point value parsed from a string.
1519 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001520LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1521 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001522
1523/**
1524 * Obtain the zero extended value for an integer constant value.
1525 *
1526 * @see llvm::ConstantInt::getZExtValue()
1527 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001528unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001529
1530/**
1531 * Obtain the sign extended value for an integer constant value.
1532 *
1533 * @see llvm::ConstantInt::getSExtValue()
1534 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001535long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001536
Gregory Szorc34c863a2012-03-21 03:54:29 +00001537/**
1538 * @}
1539 */
1540
1541/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001542 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1543 *
1544 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001545 *
1546 * @{
1547 */
1548
1549/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001550 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001551 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001552 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001553 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001554LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001555 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001556
1557/**
1558 * Create a ConstantDataSequential with string content in the global context.
1559 *
1560 * This is the same as LLVMConstStringInContext except it operates on the
1561 * global context.
1562 *
1563 * @see LLVMConstStringInContext()
1564 * @see llvm::ConstantDataArray::getString()
1565 */
1566LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1567 LLVMBool DontNullTerminate);
1568
1569/**
1570 * Create an anonymous ConstantStruct with the specified values.
1571 *
1572 * @see llvm::ConstantStruct::getAnon()
1573 */
1574LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001575 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001576 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001577
Gregory Szorc52d26602012-03-21 07:28:27 +00001578/**
1579 * Create a ConstantStruct in the global Context.
1580 *
1581 * This is the same as LLVMConstStructInContext except it operates on the
1582 * global Context.
1583 *
1584 * @see LLVMConstStructInContext()
1585 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001586LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001587 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001588
1589/**
1590 * Create a ConstantArray from values.
1591 *
1592 * @see llvm::ConstantArray::get()
1593 */
1594LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1595 LLVMValueRef *ConstantVals, unsigned Length);
1596
1597/**
1598 * Create a non-anonymous ConstantStruct from values.
1599 *
1600 * @see llvm::ConstantStruct::get()
1601 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001602LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1603 LLVMValueRef *ConstantVals,
1604 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001605
1606/**
1607 * Create a ConstantVector from values.
1608 *
1609 * @see llvm::ConstantVector::get()
1610 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001611LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001612
Gregory Szorc52d26602012-03-21 07:28:27 +00001613/**
1614 * @}
1615 */
1616
1617/**
1618 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1619 *
1620 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1621 *
1622 * @see llvm::ConstantExpr.
1623 *
1624 * @{
1625 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001626LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001627LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001628LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1629LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001630LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1631LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001632LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001633LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1634LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001635LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001636LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001637LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001638LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001639LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1640LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001641LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001642LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001643LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1644LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001645LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001646LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1647LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001648LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001649LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1650LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1651LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1652LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1653LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1654LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1655LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1656LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1657 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1658LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1659 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1660LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1661LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1662LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1663LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1664 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001665LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1666 LLVMValueRef *ConstantIndices,
1667 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001668LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1669LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1670LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1671LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1672LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1673LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1674LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1675LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1676LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1677LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1678LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1679LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001680LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001681LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1682 LLVMTypeRef ToType);
1683LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1684 LLVMTypeRef ToType);
1685LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1686 LLVMTypeRef ToType);
1687LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1688 LLVMTypeRef ToType);
1689LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001690 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001691LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001692LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1693 LLVMValueRef ConstantIfTrue,
1694 LLVMValueRef ConstantIfFalse);
1695LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1696 LLVMValueRef IndexConstant);
1697LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1698 LLVMValueRef ElementValueConstant,
1699 LLVMValueRef IndexConstant);
1700LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1701 LLVMValueRef VectorBConstant,
1702 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001703LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1704 unsigned NumIdx);
1705LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1706 LLVMValueRef ElementValueConstant,
1707 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001708LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001709 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001710 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001711LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001712
Gregory Szorc52d26602012-03-21 07:28:27 +00001713/**
1714 * @}
1715 */
1716
1717/**
1718 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1719 *
1720 * This group contains functions that operate on global values. Functions in
1721 * this group relate to functions in the llvm::GlobalValue class tree.
1722 *
1723 * @see llvm::GlobalValue
1724 *
1725 * @{
1726 */
1727
Gordon Henriksen265f7802008-03-19 01:11:35 +00001728LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001729LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001730LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1731void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1732const char *LLVMGetSection(LLVMValueRef Global);
1733void LLVMSetSection(LLVMValueRef Global, const char *Section);
1734LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1735void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001736LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1737void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001738LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1739void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001740
1741/**
1742 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1743 *
1744 * Functions in this group only apply to values with alignment, i.e.
1745 * global variables, load and store instructions.
1746 */
1747
1748/**
1749 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001750 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001751 * @see llvm::LoadInst::getAlignment()
1752 * @see llvm::StoreInst::getAlignment()
1753 * @see llvm::GlobalValue::getAlignment()
1754 */
1755unsigned LLVMGetAlignment(LLVMValueRef V);
1756
1757/**
1758 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001759 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001760 * @see llvm::LoadInst::setAlignment()
1761 * @see llvm::StoreInst::setAlignment()
1762 * @see llvm::GlobalValue::setAlignment()
1763 */
1764void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1765
1766/**
1767 * @}
1768 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001769
Gregory Szorc52d26602012-03-21 07:28:27 +00001770/**
1771 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1772 *
1773 * This group contains functions that operate on global variable values.
1774 *
1775 * @see llvm::GlobalVariable
1776 *
1777 * @{
1778 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001779LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001780LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1781 const char *Name,
1782 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001783LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001784LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1785LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1786LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1787LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001788void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001789LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1790void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001791LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1792void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1793LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1794void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001795LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1796void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1797LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1798void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001799
Gregory Szorc52d26602012-03-21 07:28:27 +00001800/**
1801 * @}
1802 */
1803
1804/**
1805 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1806 *
1807 * This group contains function that operate on global alias values.
1808 *
1809 * @see llvm::GlobalAlias
1810 *
1811 * @{
1812 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001813LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1814 const char *Name);
1815
Gregory Szorc34c863a2012-03-21 03:54:29 +00001816/**
1817 * @}
1818 */
1819
1820/**
1821 * @defgroup LLVMCCoreValueFunction Function values
1822 *
1823 * Functions in this group operate on LLVMValueRef instances that
1824 * correspond to llvm::Function instances.
1825 *
1826 * @see llvm::Function
1827 *
1828 * @{
1829 */
1830
1831/**
1832 * Remove a function from its containing module and deletes it.
1833 *
1834 * @see llvm::Function::eraseFromParent()
1835 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001836void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001837
1838/**
1839 * Obtain the ID number from a function instance.
1840 *
1841 * @see llvm::Function::getIntrinsicID()
1842 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001843unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001844
1845/**
1846 * Obtain the calling function of a function.
1847 *
1848 * The returned value corresponds to the LLVMCallConv enumeration.
1849 *
1850 * @see llvm::Function::getCallingConv()
1851 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001852unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001853
1854/**
1855 * Set the calling convention of a function.
1856 *
1857 * @see llvm::Function::setCallingConv()
1858 *
1859 * @param Fn Function to operate on
1860 * @param CC LLVMCallConv to set calling convention to
1861 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001862void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001863
1864/**
1865 * Obtain the name of the garbage collector to use during code
1866 * generation.
1867 *
1868 * @see llvm::Function::getGC()
1869 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001870const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001871
1872/**
1873 * Define the garbage collector to use during code generation.
1874 *
1875 * @see llvm::Function::setGC()
1876 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001877void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001878
1879/**
1880 * Add an attribute to a function.
1881 *
1882 * @see llvm::Function::addAttribute()
1883 */
Duncan Sands7374a012009-05-06 12:21:17 +00001884void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001885
1886/**
Tom Stellarde8f35e12013-04-16 23:12:43 +00001887 * Add a target-dependent attribute to a fuction
1888 * @see llvm::AttrBuilder::addAttribute()
1889 */
1890void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1891 const char *V);
1892
1893/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001894 * Obtain an attribute from a function.
1895 *
1896 * @see llvm::Function::getAttributes()
1897 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001898LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001899
1900/**
1901 * Remove an attribute from a function.
1902 */
Duncan Sands7374a012009-05-06 12:21:17 +00001903void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001904
Gregory Szorc34c863a2012-03-21 03:54:29 +00001905/**
1906 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1907 *
1908 * Functions in this group relate to arguments/parameters on functions.
1909 *
1910 * Functions in this group expect LLVMValueRef instances that correspond
1911 * to llvm::Function instances.
1912 *
1913 * @{
1914 */
1915
1916/**
1917 * Obtain the number of parameters in a function.
1918 *
1919 * @see llvm::Function::arg_size()
1920 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001921unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001922
1923/**
1924 * Obtain the parameters in a function.
1925 *
1926 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1927 * at least LLVMCountParams() long. This array will be filled with
1928 * LLVMValueRef instances which correspond to the parameters the
1929 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1930 * instance.
1931 *
1932 * @see llvm::Function::arg_begin()
1933 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001934void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001935
1936/**
1937 * Obtain the parameter at the specified index.
1938 *
1939 * Parameters are indexed from 0.
1940 *
1941 * @see llvm::Function::arg_begin()
1942 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001943LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001944
1945/**
1946 * Obtain the function to which this argument belongs.
1947 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001948 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00001949 * that corresponds to a llvm::Attribute.
1950 *
1951 * The returned LLVMValueRef is the llvm::Function to which this
1952 * argument belongs.
1953 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001954LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001955
1956/**
1957 * Obtain the first parameter to a function.
1958 *
1959 * @see llvm::Function::arg_begin()
1960 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001961LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001962
1963/**
1964 * Obtain the last parameter to a function.
1965 *
1966 * @see llvm::Function::arg_end()
1967 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001968LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001969
1970/**
1971 * Obtain the next parameter to a function.
1972 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001973 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00001974 * actually a wrapped iterator) and obtains the next parameter from the
1975 * underlying iterator.
1976 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001977LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001978
1979/**
1980 * Obtain the previous parameter to a function.
1981 *
1982 * This is the opposite of LLVMGetNextParam().
1983 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001984LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001985
1986/**
1987 * Add an attribute to a function argument.
1988 *
1989 * @see llvm::Argument::addAttr()
1990 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001991void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001992
1993/**
1994 * Remove an attribute from a function argument.
1995 *
1996 * @see llvm::Argument::removeAttr()
1997 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001998void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001999
2000/**
2001 * Get an attribute from a function argument.
2002 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002003LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002004
2005/**
2006 * Set the alignment for a function parameter.
2007 *
2008 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002009 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002010 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002011void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002012
Gregory Szorc34c863a2012-03-21 03:54:29 +00002013/**
2014 * @}
2015 */
2016
2017/**
2018 * @}
2019 */
2020
2021/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002022 * @}
2023 */
2024
2025/**
2026 * @}
2027 */
2028
2029/**
2030 * @defgroup LLVMCCoreValueMetadata Metadata
2031 *
2032 * @{
2033 */
2034
2035/**
2036 * Obtain a MDString value from a context.
2037 *
2038 * The returned instance corresponds to the llvm::MDString class.
2039 *
2040 * The instance is specified by string data of a specified length. The
2041 * string content is copied, so the backing memory can be freed after
2042 * this function returns.
2043 */
2044LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2045 unsigned SLen);
2046
2047/**
2048 * Obtain a MDString value from the global context.
2049 */
2050LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2051
2052/**
2053 * Obtain a MDNode value from a context.
2054 *
2055 * The returned value corresponds to the llvm::MDNode class.
2056 */
2057LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2058 unsigned Count);
2059
2060/**
2061 * Obtain a MDNode value from the global context.
2062 */
2063LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2064
2065/**
2066 * Obtain the underlying string from a MDString value.
2067 *
2068 * @param V Instance to obtain string from.
2069 * @param Len Memory address which will hold length of returned string.
2070 * @return String data in MDString.
2071 */
2072const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2073
2074/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002075 * Obtain the number of operands from an MDNode value.
2076 *
2077 * @param V MDNode to get number of operands from.
2078 * @return Number of operands of the MDNode.
2079 */
2080unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2081
2082/**
2083 * Obtain the given MDNode's operands.
2084 *
2085 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2086 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2087 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2088 * MDNode's operands.
2089 *
2090 * @param V MDNode to get the operands from.
2091 * @param Dest Destination array for operands.
2092 */
2093void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2094
2095/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002096 * @}
2097 */
2098
2099/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002100 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2101 *
2102 * A basic block represents a single entry single exit section of code.
2103 * Basic blocks contain a list of instructions which form the body of
2104 * the block.
2105 *
2106 * Basic blocks belong to functions. They have the type of label.
2107 *
2108 * Basic blocks are themselves values. However, the C API models them as
2109 * LLVMBasicBlockRef.
2110 *
2111 * @see llvm::BasicBlock
2112 *
2113 * @{
2114 */
2115
2116/**
2117 * Convert a basic block instance to a value type.
2118 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002119LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002120
2121/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002122 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002123 */
Chris Lattner25963c62010-01-09 22:27:07 +00002124LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002125
2126/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002127 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002128 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002129LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002130
2131/**
2132 * Obtain the function to which a basic block belongs.
2133 *
2134 * @see llvm::BasicBlock::getParent()
2135 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002136LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002137
2138/**
2139 * Obtain the terminator instruction for a basic block.
2140 *
2141 * If the basic block does not have a terminator (it is not well-formed
2142 * if it doesn't), then NULL is returned.
2143 *
2144 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2145 *
2146 * @see llvm::BasicBlock::getTerminator()
2147 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002148LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002149
2150/**
2151 * Obtain the number of basic blocks in a function.
2152 *
2153 * @param Fn Function value to operate on.
2154 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002155unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002156
2157/**
2158 * Obtain all of the basic blocks in a function.
2159 *
2160 * This operates on a function value. The BasicBlocks parameter is a
2161 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2162 * LLVMCountBasicBlocks() in length. This array is populated with
2163 * LLVMBasicBlockRef instances.
2164 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002165void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002166
2167/**
2168 * Obtain the first basic block in a function.
2169 *
2170 * The returned basic block can be used as an iterator. You will likely
2171 * eventually call into LLVMGetNextBasicBlock() with it.
2172 *
2173 * @see llvm::Function::begin()
2174 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002175LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002176
2177/**
2178 * Obtain the last basic block in a function.
2179 *
2180 * @see llvm::Function::end()
2181 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002182LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002183
2184/**
2185 * Advance a basic block iterator.
2186 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002187LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002188
2189/**
2190 * Go backwards in a basic block iterator.
2191 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002192LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002193
2194/**
2195 * Obtain the basic block that corresponds to the entry point of a
2196 * function.
2197 *
2198 * @see llvm::Function::getEntryBlock()
2199 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002200LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002201
Gregory Szorc34c863a2012-03-21 03:54:29 +00002202/**
2203 * Append a basic block to the end of a function.
2204 *
2205 * @see llvm::BasicBlock::Create()
2206 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002207LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2208 LLVMValueRef Fn,
2209 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002210
2211/**
2212 * Append a basic block to the end of a function using the global
2213 * context.
2214 *
2215 * @see llvm::BasicBlock::Create()
2216 */
2217LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2218
2219/**
2220 * Insert a basic block in a function before another basic block.
2221 *
2222 * The function to add to is determined by the function of the
2223 * passed basic block.
2224 *
2225 * @see llvm::BasicBlock::Create()
2226 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002227LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2228 LLVMBasicBlockRef BB,
2229 const char *Name);
2230
Gregory Szorc34c863a2012-03-21 03:54:29 +00002231/**
2232 * Insert a basic block in a function using the global context.
2233 *
2234 * @see llvm::BasicBlock::Create()
2235 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002236LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2237 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002238
2239/**
2240 * Remove a basic block from a function and delete it.
2241 *
2242 * This deletes the basic block from its containing function and deletes
2243 * the basic block itself.
2244 *
2245 * @see llvm::BasicBlock::eraseFromParent()
2246 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002247void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002248
2249/**
2250 * Remove a basic block from a function.
2251 *
2252 * This deletes the basic block from its containing function but keep
2253 * the basic block alive.
2254 *
2255 * @see llvm::BasicBlock::removeFromParent()
2256 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002257void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002258
Gregory Szorc34c863a2012-03-21 03:54:29 +00002259/**
2260 * Move a basic block to before another one.
2261 *
2262 * @see llvm::BasicBlock::moveBefore()
2263 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002264void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002265
2266/**
2267 * Move a basic block to after another one.
2268 *
2269 * @see llvm::BasicBlock::moveAfter()
2270 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002271void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2272
Gregory Szorc34c863a2012-03-21 03:54:29 +00002273/**
2274 * Obtain the first instruction in a basic block.
2275 *
2276 * The returned LLVMValueRef corresponds to a llvm::Instruction
2277 * instance.
2278 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002279LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002280
2281/**
2282 * Obtain the last instruction in a basic block.
2283 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002284 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002285 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002286LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002287
Gregory Szorc34c863a2012-03-21 03:54:29 +00002288/**
2289 * @}
2290 */
2291
2292/**
2293 * @defgroup LLVMCCoreValueInstruction Instructions
2294 *
2295 * Functions in this group relate to the inspection and manipulation of
2296 * individual instructions.
2297 *
2298 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2299 * class has a large number of descendents. llvm::Instruction is a
2300 * llvm::Value and in the C API, instructions are modeled by
2301 * LLVMValueRef.
2302 *
2303 * This group also contains sub-groups which operate on specific
2304 * llvm::Instruction types, e.g. llvm::CallInst.
2305 *
2306 * @{
2307 */
2308
2309/**
2310 * Determine whether an instruction has any metadata attached.
2311 */
2312int LLVMHasMetadata(LLVMValueRef Val);
2313
2314/**
2315 * Return metadata associated with an instruction value.
2316 */
2317LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2318
2319/**
2320 * Set metadata associated with an instruction value.
2321 */
2322void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2323
2324/**
2325 * Obtain the basic block to which an instruction belongs.
2326 *
2327 * @see llvm::Instruction::getParent()
2328 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002329LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002330
2331/**
2332 * Obtain the instruction that occurs after the one specified.
2333 *
2334 * The next instruction will be from the same basic block.
2335 *
2336 * If this is the last instruction in a basic block, NULL will be
2337 * returned.
2338 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002339LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002340
2341/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002342 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002343 *
2344 * If the instruction is the first instruction in a basic block, NULL
2345 * will be returned.
2346 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002347LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002348
2349/**
2350 * Remove and delete an instruction.
2351 *
2352 * The instruction specified is removed from its containing building
2353 * block and then deleted.
2354 *
2355 * @see llvm::Instruction::eraseFromParent()
2356 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002357void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002358
2359/**
2360 * Obtain the code opcode for an individual instruction.
2361 *
2362 * @see llvm::Instruction::getOpCode()
2363 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002364LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002365
2366/**
2367 * Obtain the predicate of an instruction.
2368 *
2369 * This is only valid for instructions that correspond to llvm::ICmpInst
2370 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2371 *
2372 * @see llvm::ICmpInst::getPredicate()
2373 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002374LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002375
Gregory Szorc34c863a2012-03-21 03:54:29 +00002376/**
2377 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2378 *
2379 * Functions in this group apply to instructions that refer to call
2380 * sites and invocations. These correspond to C++ types in the
2381 * llvm::CallInst class tree.
2382 *
2383 * @{
2384 */
2385
2386/**
2387 * Set the calling convention for a call instruction.
2388 *
2389 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2390 * llvm::InvokeInst.
2391 *
2392 * @see llvm::CallInst::setCallingConv()
2393 * @see llvm::InvokeInst::setCallingConv()
2394 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002395void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002396
2397/**
2398 * Obtain the calling convention for a call instruction.
2399 *
2400 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2401 * usage.
2402 *
2403 * @see LLVMSetInstructionCallConv()
2404 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002405unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002406
2407
Devang Patel4c758ea2008-09-25 21:00:45 +00002408void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002409void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002410 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002411void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002412 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002413
Gregory Szorc34c863a2012-03-21 03:54:29 +00002414/**
2415 * Obtain whether a call instruction is a tail call.
2416 *
2417 * This only works on llvm::CallInst instructions.
2418 *
2419 * @see llvm::CallInst::isTailCall()
2420 */
Chris Lattner25963c62010-01-09 22:27:07 +00002421LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002422
2423/**
2424 * Set whether a call instruction is a tail call.
2425 *
2426 * This only works on llvm::CallInst instructions.
2427 *
2428 * @see llvm::CallInst::setTailCall()
2429 */
Chris Lattner25963c62010-01-09 22:27:07 +00002430void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002431
Gregory Szorc34c863a2012-03-21 03:54:29 +00002432/**
2433 * @}
2434 */
2435
2436/**
2437 * Obtain the default destination basic block of a switch instruction.
2438 *
2439 * This only works on llvm::SwitchInst instructions.
2440 *
2441 * @see llvm::SwitchInst::getDefaultDest()
2442 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002443LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2444
Gregory Szorc34c863a2012-03-21 03:54:29 +00002445/**
2446 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2447 *
2448 * Functions in this group only apply to instructions that map to
2449 * llvm::PHINode instances.
2450 *
2451 * @{
2452 */
2453
2454/**
2455 * Add an incoming value to the end of a PHI list.
2456 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002457void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2458 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002459
2460/**
2461 * Obtain the number of incoming basic blocks to a PHI node.
2462 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002463unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002464
2465/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002466 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002467 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002468LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002469
2470/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002471 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002472 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002473LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002474
Gregory Szorc34c863a2012-03-21 03:54:29 +00002475/**
2476 * @}
2477 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002478
Gregory Szorc34c863a2012-03-21 03:54:29 +00002479/**
2480 * @}
2481 */
2482
2483/**
2484 * @}
2485 */
2486
2487/**
2488 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2489 *
2490 * An instruction builder represents a point within a basic block and is
2491 * the exclusive means of building instructions using the C interface.
2492 *
2493 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002494 */
2495
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002496LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002497LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002498void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2499 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002500void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2501void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002502LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002503void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2504void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002505void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2506 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002507void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2508
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002509/* Metadata */
2510void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2511LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2512void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2513
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002514/* Terminators */
2515LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2516LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002517LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002518 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002519LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2520LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2521 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2522LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2523 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002524LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2525 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002526LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2527 LLVMValueRef *Args, unsigned NumArgs,
2528 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2529 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002530LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2531 LLVMValueRef PersFn, unsigned NumClauses,
2532 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002533LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002534LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2535
Gordon Henriksen097102c2008-01-01 05:50:53 +00002536/* Add a case to the switch instruction */
2537void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2538 LLVMBasicBlockRef Dest);
2539
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002540/* Add a destination to the indirectbr instruction */
2541void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2542
Bill Wendlingfae14752011-08-12 20:24:12 +00002543/* Add a catch or filter clause to the landingpad instruction */
2544void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2545
2546/* Set the 'cleanup' flag in the landingpad instruction */
2547void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2548
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002549/* Arithmetic */
2550LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2551 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002552LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2553 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002554LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2555 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002556LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2557 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002558LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2559 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002560LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2561 const char *Name);
2562LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2563 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002564LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2565 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002566LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2567 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002568LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2569 const char *Name);
2570LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2571 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002572LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2573 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002574LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2575 const char *Name);
2576LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2577 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002578LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2579 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002580LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2581 const char *Name);
2582LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2583 const char *Name);
2584LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2585 const char *Name);
2586LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2587 const char *Name);
2588LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2589 const char *Name);
2590LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2591 const char *Name);
2592LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2593 const char *Name);
2594LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2595 const char *Name);
2596LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2597 const char *Name);
2598LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2599 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002600LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2601 LLVMValueRef LHS, LLVMValueRef RHS,
2602 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002603LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002604LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2605 const char *Name);
2606LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2607 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002608LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002609LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2610
2611/* Memory */
2612LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2613LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2614 LLVMValueRef Val, const char *Name);
2615LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2616LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2617 LLVMValueRef Val, const char *Name);
2618LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2619LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2620 const char *Name);
2621LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2622LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2623 LLVMValueRef *Indices, unsigned NumIndices,
2624 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002625LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2626 LLVMValueRef *Indices, unsigned NumIndices,
2627 const char *Name);
2628LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2629 unsigned Idx, const char *Name);
2630LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2631 const char *Name);
2632LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2633 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002634LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2635void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002636
2637/* Casts */
2638LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2639 LLVMTypeRef DestTy, const char *Name);
2640LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2641 LLVMTypeRef DestTy, const char *Name);
2642LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2643 LLVMTypeRef DestTy, const char *Name);
2644LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2645 LLVMTypeRef DestTy, const char *Name);
2646LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2647 LLVMTypeRef DestTy, const char *Name);
2648LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2649 LLVMTypeRef DestTy, const char *Name);
2650LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2651 LLVMTypeRef DestTy, const char *Name);
2652LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2653 LLVMTypeRef DestTy, const char *Name);
2654LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2655 LLVMTypeRef DestTy, const char *Name);
2656LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2657 LLVMTypeRef DestTy, const char *Name);
2658LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2659 LLVMTypeRef DestTy, const char *Name);
2660LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2661 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002662LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2663 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002664LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2665 LLVMTypeRef DestTy, const char *Name);
2666LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2667 LLVMTypeRef DestTy, const char *Name);
2668LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2669 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002670LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2671 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002672LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2673 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002674LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002675 LLVMTypeRef DestTy, const char *Name);
2676LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2677 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002678
2679/* Comparisons */
2680LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2681 LLVMValueRef LHS, LLVMValueRef RHS,
2682 const char *Name);
2683LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2684 LLVMValueRef LHS, LLVMValueRef RHS,
2685 const char *Name);
2686
2687/* Miscellaneous instructions */
2688LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2689LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2690 LLVMValueRef *Args, unsigned NumArgs,
2691 const char *Name);
2692LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2693 LLVMValueRef Then, LLVMValueRef Else,
2694 const char *Name);
2695LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2696 const char *Name);
2697LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2698 LLVMValueRef Index, const char *Name);
2699LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2700 LLVMValueRef EltVal, LLVMValueRef Index,
2701 const char *Name);
2702LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2703 LLVMValueRef V2, LLVMValueRef Mask,
2704 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002705LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2706 unsigned Index, const char *Name);
2707LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2708 LLVMValueRef EltVal, unsigned Index,
2709 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002710
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002711LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2712 const char *Name);
2713LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2714 const char *Name);
2715LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2716 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00002717LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2718 LLVMBool singleThread, const char *Name);
2719LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00002720 LLVMValueRef PTR, LLVMValueRef Val,
2721 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00002722 LLVMBool singleThread);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002723
Gregory Szorc34c863a2012-03-21 03:54:29 +00002724/**
2725 * @}
2726 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002727
Gregory Szorc34c863a2012-03-21 03:54:29 +00002728/**
2729 * @defgroup LLVMCCoreModuleProvider Module Providers
2730 *
2731 * @{
2732 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002733
Gregory Szorc34c863a2012-03-21 03:54:29 +00002734/**
2735 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002736 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002737 */
2738LLVMModuleProviderRef
2739LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2740
Gregory Szorc34c863a2012-03-21 03:54:29 +00002741/**
2742 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002743 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002744void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002745
Gregory Szorc34c863a2012-03-21 03:54:29 +00002746/**
2747 * @}
2748 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002749
Gregory Szorc34c863a2012-03-21 03:54:29 +00002750/**
2751 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2752 *
2753 * @{
2754 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002755
Chris Lattner25963c62010-01-09 22:27:07 +00002756LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2757 LLVMMemoryBufferRef *OutMemBuf,
2758 char **OutMessage);
2759LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2760 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00002761LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2762 size_t InputDataLength,
2763 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00002764 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00002765LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2766 size_t InputDataLength,
2767 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00002768const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00002769size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002770void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2771
Gregory Szorc34c863a2012-03-21 03:54:29 +00002772/**
2773 * @}
2774 */
2775
2776/**
2777 * @defgroup LLVMCCorePassRegistry Pass Registry
2778 *
2779 * @{
2780 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002781
2782/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002783 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002784LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002785
Gregory Szorc34c863a2012-03-21 03:54:29 +00002786/**
2787 * @}
2788 */
2789
2790/**
2791 * @defgroup LLVMCCorePassManagers Pass Managers
2792 *
2793 * @{
2794 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002795
2796/** Constructs a new whole-module pass pipeline. This type of pipeline is
2797 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002798 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002799LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002800
2801/** Constructs a new function-by-function pass pipeline over the module
2802 provider. It does not take ownership of the module provider. This type of
2803 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002804 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002805LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2806
2807/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002808LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2809
2810/** Initializes, executes on the provided module, and finalizes all of the
2811 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002812 modified the module, 0 otherwise.
2813 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002814LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002815
2816/** Initializes all of the function passes scheduled in the function pass
2817 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002818 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002819LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002820
2821/** Executes all of the function passes scheduled in the function pass manager
2822 on the provided function. Returns 1 if any of the passes modified the
2823 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002824 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002825LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002826
2827/** Finalizes all of the function passes scheduled in in the function pass
2828 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002829 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002830LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002831
2832/** Frees the memory of a pass pipeline. For function pipelines, does not free
2833 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002834 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002835void LLVMDisposePassManager(LLVMPassManagerRef PM);
2836
Gregory Szorc34c863a2012-03-21 03:54:29 +00002837/**
2838 * @}
2839 */
2840
2841/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00002842 * @defgroup LLVMCCoreThreading Threading
2843 *
2844 * Handle the structures needed to make LLVM safe for multithreading.
2845 *
2846 * @{
2847 */
2848
2849/** Allocate and initialize structures needed to make LLVM safe for
2850 multithreading. The return value indicates whether multithreaded
2851 initialization succeeded. Must be executed in isolation from all
2852 other LLVM api calls.
2853 @see llvm::llvm_start_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002854LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002855
2856/** Deallocate structures necessary to make LLVM safe for multithreading.
2857 Must be executed in isolation from all other LLVM api calls.
2858 @see llvm::llvm_stop_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002859void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002860
2861/** Check whether LLVM is executing in thread-safe mode or not.
2862 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002863LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002864
2865/**
2866 * @}
2867 */
2868
2869/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002870 * @}
2871 */
2872
2873/**
2874 * @}
2875 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002876
Gordon Henriksen76a03742007-09-18 03:18:57 +00002877#ifdef __cplusplus
2878}
Evan Cheng2e254d02013-04-04 17:40:53 +00002879#endif /* !defined(__cplusplus) */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002880
Evan Cheng2e254d02013-04-04 17:40:53 +00002881#endif /* !defined(LLVM_C_CORE_H) */