blob: 0e78ed71fa9afaf7593a2205c0db3fdc993a2af4 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000013\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_C_CORE_H
16#define LLVM_C_CORE_H
17
Chandler Carruth3c57aa42014-03-06 04:13:12 +000018#include "llvm-c/Support.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000019
Evan Cheng2e254d02013-04-04 17:40:53 +000020#ifdef __cplusplus
Gordon Henriksen76a03742007-09-18 03:18:57 +000021extern "C" {
22#endif
23
Gregory Szorc34c863a2012-03-21 03:54:29 +000024/**
25 * @defgroup LLVMC LLVM-C: C interface to LLVM
26 *
27 * This module exposes parts of the LLVM library as a C API.
28 *
29 * @{
30 */
31
32/**
33 * @defgroup LLVMCTransforms Transforms
34 */
35
36/**
37 * @defgroup LLVMCCore Core
38 *
39 * This modules provide an interface to libLLVMCore, which implements
40 * the LLVM intermediate representation as well as other related types
41 * and utilities.
42 *
43 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
44 * parameters must be passed as base types. Despite the declared types, most
45 * of the functions provided operate only on branches of the type hierarchy.
46 * The declared parameter names are descriptive and specify which type is
47 * required. Additionally, each type hierarchy is documented along with the
48 * functions that operate upon it. For more detail, refer to LLVM's C++ code.
Eli Bendersky870d0572012-08-10 18:26:20 +000049 * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
Gregory Szorc34c863a2012-03-21 03:54:29 +000050 * form unwrap<RequiredType>(Param).
51 *
52 * Many exotic languages can interoperate with C code but have a harder time
53 * with C++ due to name mangling. So in addition to C, this interface enables
54 * tools written in such languages.
55 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000056 * @{
57 */
58
59/**
60 * @defgroup LLVMCCoreTypes Types and Enumerations
61 *
62 * @{
63 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000064
65/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000066
67/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000068 * The top-level container for all LLVM global data. See the LLVMContext class.
Owen Anderson6773d382009-07-01 16:58:40 +000069 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000070typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000071
72/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000073 * The top-level container for all other LLVM Intermediate Representation (IR)
Gregory Szorc34c863a2012-03-21 03:54:29 +000074 * objects.
75 *
76 * @see llvm::Module
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000077 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000078typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000079
80/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000081 * Each value in the LLVM IR has a type, an LLVMTypeRef.
82 *
83 * @see llvm::Type
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000084 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000085typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000086
Gregory Szorc34c863a2012-03-21 03:54:29 +000087/**
88 * Represents an individual value in LLVM IR.
89 *
90 * This models llvm::Value.
91 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000092typedef struct LLVMOpaqueValue *LLVMValueRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +000093
94/**
Eli Bendersky870d0572012-08-10 18:26:20 +000095 * Represents a basic block of instructions in LLVM IR.
Gregory Szorc34c863a2012-03-21 03:54:29 +000096 *
97 * This models llvm::BasicBlock.
98 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000099typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +0000100
101/**
102 * Represents an LLVM basic block builder.
103 *
104 * This models llvm::IRBuilder.
105 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000106typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000107
Gregory Szorc34c863a2012-03-21 03:54:29 +0000108/**
109 * Interface used to provide a module to JIT or interpreter.
110 * This is now just a synonym for llvm::Module, but we have to keep using the
111 * different type to keep binary compatibility.
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000112 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000113typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +0000114
Gregory Szorc34c863a2012-03-21 03:54:29 +0000115/** @see llvm::PassManagerBase */
Gordon Henriksen878114b2008-03-16 04:20:44 +0000116typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
117
Gregory Szorc34c863a2012-03-21 03:54:29 +0000118/** @see llvm::PassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +0000119typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
120
Gregory Szorc34c863a2012-03-21 03:54:29 +0000121/**
122 * Used to get the users and usees of a Value.
123 *
124 * @see llvm::Use */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +0000125typedef struct LLVMOpaqueUse *LLVMUseRef;
Chris Lattner40cf28d2009-10-12 04:01:02 +0000126
Tom Stellard1580dc72014-04-16 17:45:04 +0000127
128/**
129 * @see llvm::DiagnosticInfo
130 */
131typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
132
Gordon Henriksen76a03742007-09-18 03:18:57 +0000133typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +0000134 LLVMZExtAttribute = 1<<0,
135 LLVMSExtAttribute = 1<<1,
136 LLVMNoReturnAttribute = 1<<2,
137 LLVMInRegAttribute = 1<<3,
138 LLVMStructRetAttribute = 1<<4,
139 LLVMNoUnwindAttribute = 1<<5,
140 LLVMNoAliasAttribute = 1<<6,
141 LLVMByValAttribute = 1<<7,
142 LLVMNestAttribute = 1<<8,
143 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000144 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000145 LLVMNoInlineAttribute = 1<<11,
146 LLVMAlwaysInlineAttribute = 1<<12,
147 LLVMOptimizeForSizeAttribute = 1<<13,
148 LLVMStackProtectAttribute = 1<<14,
149 LLVMStackProtectReqAttribute = 1<<15,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000150 LLVMAlignment = 31<<16,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000151 LLVMNoCaptureAttribute = 1<<21,
152 LLVMNoRedZoneAttribute = 1<<22,
153 LLVMNoImplicitFloatAttribute = 1<<23,
Jakob Stoklund Olesen74bb06c2010-02-06 01:16:28 +0000154 LLVMNakedAttribute = 1<<24,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000155 LLVMInlineHintAttribute = 1<<25,
Torok Edwin1db48c02011-10-06 12:13:32 +0000156 LLVMStackAlignment = 7<<26,
157 LLVMReturnsTwice = 1 << 29,
158 LLVMUWTable = 1 << 30,
Chandler Carruth44d69d92012-01-25 07:40:15 +0000159 LLVMNonLazyBind = 1 << 31
160
Bill Wendlingd154e2832013-01-23 06:41:41 +0000161 /* FIXME: These attributes are currently not included in the C API as
Nuno Lopesdef4229972012-09-02 14:19:21 +0000162 a temporary measure until the API/ABI impact to the C API is understood
163 and the path forward agreed upon.
Bill Wendlingd154e2832013-01-23 06:41:41 +0000164 LLVMAddressSafety = 1ULL << 32,
Andrea Di Biagio377496b2013-08-23 11:53:55 +0000165 LLVMStackProtectStrongAttribute = 1ULL<<33,
166 LLVMCold = 1ULL << 34,
Reid Klecknera534a382013-12-19 02:14:12 +0000167 LLVMOptimizeNone = 1ULL << 35,
Nick Lewyckyd52b1522014-05-20 01:23:40 +0000168 LLVMInAllocaAttribute = 1ULL << 36,
Tom Roeder44cb65f2014-06-05 19:29:43 +0000169 LLVMNonNullAttribute = 1ULL << 37,
170 LLVMJumpTableAttribute = 1ULL << 38,
Nuno Lopesdef4229972012-09-02 14:19:21 +0000171 */
Devang Patel4c758ea2008-09-25 21:00:45 +0000172} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000173
174typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000175 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000176 LLVMRet = 1,
177 LLVMBr = 2,
178 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000179 LLVMIndirectBr = 4,
180 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000181 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000182 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000183
Bill Wendlingda52cec2010-02-15 20:53:17 +0000184 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000185 LLVMAdd = 8,
186 LLVMFAdd = 9,
187 LLVMSub = 10,
188 LLVMFSub = 11,
189 LLVMMul = 12,
190 LLVMFMul = 13,
191 LLVMUDiv = 14,
192 LLVMSDiv = 15,
193 LLVMFDiv = 16,
194 LLVMURem = 17,
195 LLVMSRem = 18,
196 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000197
Bill Wendlingda52cec2010-02-15 20:53:17 +0000198 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000199 LLVMShl = 20,
200 LLVMLShr = 21,
201 LLVMAShr = 22,
202 LLVMAnd = 23,
203 LLVMOr = 24,
204 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000205
Bill Wendlingda52cec2010-02-15 20:53:17 +0000206 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000207 LLVMAlloca = 26,
208 LLVMLoad = 27,
209 LLVMStore = 28,
210 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000211
Bill Wendlingda52cec2010-02-15 20:53:17 +0000212 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000213 LLVMTrunc = 30,
214 LLVMZExt = 31,
215 LLVMSExt = 32,
216 LLVMFPToUI = 33,
217 LLVMFPToSI = 34,
218 LLVMUIToFP = 35,
219 LLVMSIToFP = 36,
220 LLVMFPTrunc = 37,
221 LLVMFPExt = 38,
222 LLVMPtrToInt = 39,
223 LLVMIntToPtr = 40,
224 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000225 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000226
Bill Wendlingda52cec2010-02-15 20:53:17 +0000227 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000228 LLVMICmp = 42,
229 LLVMFCmp = 43,
230 LLVMPHI = 44,
231 LLVMCall = 45,
232 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000233 LLVMUserOp1 = 47,
234 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000235 LLVMVAArg = 49,
236 LLVMExtractElement = 50,
237 LLVMInsertElement = 51,
238 LLVMShuffleVector = 52,
239 LLVMExtractValue = 53,
240 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000241
242 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000243 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000244 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000245 LLVMAtomicRMW = 57,
246
247 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000248 LLVMResume = 58,
Bill Wendling0aef16a2012-02-06 21:44:22 +0000249 LLVMLandingPad = 59
Bill Wendling2641d132011-07-27 21:00:28 +0000250
Chris Lattner40cf28d2009-10-12 04:01:02 +0000251} LLVMOpcode;
252
253typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000254 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000255 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000256 LLVMFloatTypeKind, /**< 32 bit floating point type */
257 LLVMDoubleTypeKind, /**< 64 bit floating point type */
258 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
259 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
260 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
261 LLVMLabelTypeKind, /**< Labels */
262 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
263 LLVMFunctionTypeKind, /**< Functions */
264 LLVMStructTypeKind, /**< Structures */
265 LLVMArrayTypeKind, /**< Arrays */
266 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000267 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000268 LLVMMetadataTypeKind, /**< Metadata */
269 LLVMX86_MMXTypeKind /**< X86 MMX */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000270} LLVMTypeKind;
271
272typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000273 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000274 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000275 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
276 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
277 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000278 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000279 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
280 LLVMWeakODRLinkage, /**< Same, but only replaced by something
281 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000282 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
283 LLVMInternalLinkage, /**< Rename collisions when linking (static
284 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000285 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000286 LLVMDLLImportLinkage, /**< Obsolete */
287 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000288 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000289 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000290 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000291 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000292 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000293} LLVMLinkage;
294
295typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000296 LLVMDefaultVisibility, /**< The GV is visible */
297 LLVMHiddenVisibility, /**< The GV is hidden */
298 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000299} LLVMVisibility;
300
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000301typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000302 LLVMDefaultStorageClass = 0,
303 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
304 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
305} LLVMDLLStorageClass;
306
307typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000308 LLVMCCallConv = 0,
309 LLVMFastCallConv = 8,
310 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000311 LLVMWebKitJSCallConv = 12,
312 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000313 LLVMX86StdcallCallConv = 64,
314 LLVMX86FastcallCallConv = 65
315} LLVMCallConv;
316
317typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000318 LLVMIntEQ = 32, /**< equal */
319 LLVMIntNE, /**< not equal */
320 LLVMIntUGT, /**< unsigned greater than */
321 LLVMIntUGE, /**< unsigned greater or equal */
322 LLVMIntULT, /**< unsigned less than */
323 LLVMIntULE, /**< unsigned less or equal */
324 LLVMIntSGT, /**< signed greater than */
325 LLVMIntSGE, /**< signed greater or equal */
326 LLVMIntSLT, /**< signed less than */
327 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000328} LLVMIntPredicate;
329
330typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000331 LLVMRealPredicateFalse, /**< Always false (always folded) */
332 LLVMRealOEQ, /**< True if ordered and equal */
333 LLVMRealOGT, /**< True if ordered and greater than */
334 LLVMRealOGE, /**< True if ordered and greater than or equal */
335 LLVMRealOLT, /**< True if ordered and less than */
336 LLVMRealOLE, /**< True if ordered and less than or equal */
337 LLVMRealONE, /**< True if ordered and operands are unequal */
338 LLVMRealORD, /**< True if ordered (no nans) */
339 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
340 LLVMRealUEQ, /**< True if unordered or equal */
341 LLVMRealUGT, /**< True if unordered or greater than */
342 LLVMRealUGE, /**< True if unordered, greater than, or equal */
343 LLVMRealULT, /**< True if unordered or less than */
344 LLVMRealULE, /**< True if unordered, less than, or equal */
345 LLVMRealUNE, /**< True if unordered or not equal */
346 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000347} LLVMRealPredicate;
348
Bill Wendlingfae14752011-08-12 20:24:12 +0000349typedef enum {
350 LLVMLandingPadCatch, /**< A catch clause */
351 LLVMLandingPadFilter /**< A filter clause */
352} LLVMLandingPadClauseTy;
353
Hans Wennborg5ff71202013-04-16 08:58:59 +0000354typedef enum {
355 LLVMNotThreadLocal = 0,
356 LLVMGeneralDynamicTLSModel,
357 LLVMLocalDynamicTLSModel,
358 LLVMInitialExecTLSModel,
359 LLVMLocalExecTLSModel
360} LLVMThreadLocalMode;
361
Carlo Kokda0ac722013-04-23 13:45:37 +0000362typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000363 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
364 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
365 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000366 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
367 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000368 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000369 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
370 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000371 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000372 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
373 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000374 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000375 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
376 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000377 operations which both read and write
378 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000379 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
380 for loads and Release
381 semantics for stores.
382 Additionally, it guarantees
383 that a total ordering exists
384 between all
385 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000386 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000387} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000388
Carlo Kokda0ac722013-04-23 13:45:37 +0000389typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000390 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
391 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
392 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
393 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
394 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
395 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
396 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
397 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000398 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000399 the old one */
400 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000401 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000402 the old one */
403 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000404 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000405 the old one */
406 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000407 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000408 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000409} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000410
Tom Stellard1580dc72014-04-16 17:45:04 +0000411typedef enum {
412 LLVMDSError,
413 LLVMDSWarning,
414 LLVMDSRemark,
415 LLVMDSNote
416} LLVMDiagnosticSeverity;
417
Gregory Szorc34c863a2012-03-21 03:54:29 +0000418/**
419 * @}
420 */
421
Nick Lewycky0db26542011-05-15 07:20:34 +0000422void LLVMInitializeCore(LLVMPassRegistryRef R);
423
Duncan Sands1cba0a82013-02-17 16:35:51 +0000424/** Deallocate and destroy all ManagedStatic variables.
425 @see llvm::llvm_shutdown
426 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000427void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000428
Gordon Henriksen76a03742007-09-18 03:18:57 +0000429
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000430/*===-- Error handling ----------------------------------------------------===*/
431
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000432char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000433void LLVMDisposeMessage(char *Message);
434
Filip Pizloa535b142013-10-17 01:38:28 +0000435typedef void (*LLVMFatalErrorHandler)(const char *Reason);
436
437/**
438 * Install a fatal error handler. By default, if LLVM detects a fatal error, it
439 * will call exit(1). This may not be appropriate in many contexts. For example,
440 * doing exit(1) will bypass many crash reporting/tracing system tools. This
441 * function allows you to install a callback that will be invoked prior to the
442 * call to exit(1).
443 */
444void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
445
446/**
447 * Reset the fatal error handler. This resets LLVM's fatal error handling
448 * behavior to the default.
449 */
450void LLVMResetFatalErrorHandler(void);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000451
Gregory Szorc34c863a2012-03-21 03:54:29 +0000452/**
Filip Pizloc10ca902013-11-04 02:22:25 +0000453 * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
454 * signals and prints which component of LLVM you were in at the time if the
455 * crash.
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000456 */
Filip Pizloc10ca902013-11-04 02:22:25 +0000457void LLVMEnablePrettyStackTrace(void);
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000458
459/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000460 * @defgroup LLVMCCoreContext Contexts
461 *
462 * Contexts are execution states for the core LLVM IR system.
463 *
464 * Most types are tied to a context instance. Multiple contexts can
465 * exist simultaneously. A single context is not thread safe. However,
466 * different contexts can execute on different threads simultaneously.
467 *
468 * @{
469 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000470
Tom Stellard1580dc72014-04-16 17:45:04 +0000471typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000472typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000473
Gregory Szorc34c863a2012-03-21 03:54:29 +0000474/**
475 * Create a new context.
476 *
477 * Every call to this function should be paired with a call to
478 * LLVMContextDispose() or the context will leak memory.
479 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000480LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000481
482/**
483 * Obtain the global context instance.
484 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000485LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000486
487/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000488 * Set the diagnostic handler for this context.
489 */
490void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
491 LLVMDiagnosticHandler Handler,
492 void *DiagnosticContext);
493
494/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000495 * Set the yield callback function for this context.
496 *
497 * @see LLVMContext::setYieldCallback()
498 */
499void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
500 void *OpaqueHandle);
501
502/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000503 * Destroy a context instance.
504 *
505 * This should be called for every call to LLVMContextCreate() or memory
506 * will be leaked.
507 */
Owen Anderson6773d382009-07-01 16:58:40 +0000508void LLVMContextDispose(LLVMContextRef C);
509
Tom Stellard1580dc72014-04-16 17:45:04 +0000510/**
511 * Return a string representation of the DiagnosticInfo. Use
512 * LLVMDisposeMessage to free the string.
513 *
514 * @see DiagnosticInfo::print()
515 */
516char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
517
518/**
519 * Return an enum LLVMDiagnosticSeverity.
520 *
521 * @see DiagnosticInfo::getSeverity()
522 */
523LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
524
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000525unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
526 unsigned SLen);
527unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
528
Gregory Szorc34c863a2012-03-21 03:54:29 +0000529/**
530 * @}
531 */
532
Gregory Szorc52d26602012-03-21 07:28:27 +0000533/**
534 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000535 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000536 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000537 * module is effectively a translation unit or a collection of
538 * translation units merged together.
539 *
540 * @{
541 */
542
Gregory Szorc34c863a2012-03-21 03:54:29 +0000543/**
544 * Create a new, empty module in the global context.
545 *
546 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
547 * LLVMGetGlobalContext() as the context parameter.
548 *
549 * Every invocation should be paired with LLVMDisposeModule() or memory
550 * will be leaked.
551 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000552LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000553
554/**
555 * Create a new, empty module in a specific context.
556 *
557 * Every invocation should be paired with LLVMDisposeModule() or memory
558 * will be leaked.
559 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000560LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
561 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000562
Gregory Szorc34c863a2012-03-21 03:54:29 +0000563/**
564 * Destroy a module instance.
565 *
566 * This must be called for every created module or memory will be
567 * leaked.
568 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000569void LLVMDisposeModule(LLVMModuleRef M);
570
Gregory Szorc34c863a2012-03-21 03:54:29 +0000571/**
572 * Obtain the data layout for a module.
573 *
574 * @see Module::getDataLayout()
575 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000576const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000577
578/**
579 * Set the data layout for a module.
580 *
581 * @see Module::setDataLayout()
582 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000583void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
584
Gregory Szorc34c863a2012-03-21 03:54:29 +0000585/**
586 * Obtain the target triple for a module.
587 *
588 * @see Module::getTargetTriple()
589 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000590const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000591
592/**
593 * Set the target triple for a module.
594 *
595 * @see Module::setTargetTriple()
596 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000597void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
598
Gregory Szorc34c863a2012-03-21 03:54:29 +0000599/**
600 * Dump a representation of a module to stderr.
601 *
602 * @see Module::dump()
603 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000604void LLVMDumpModule(LLVMModuleRef M);
605
Gregory Szorc34c863a2012-03-21 03:54:29 +0000606/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000607 * Print a representation of a module to a file. The ErrorMessage needs to be
608 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
609 *
610 * @see Module::print()
611 */
612LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
613 char **ErrorMessage);
614
615/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000616 * Return a string representation of the module. Use
617 * LLVMDisposeMessage to free the string.
618 *
619 * @see Module::print()
620 */
621char *LLVMPrintModuleToString(LLVMModuleRef M);
622
623/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000624 * Set inline assembly for a module.
625 *
626 * @see Module::setModuleInlineAsm()
627 */
Chris Lattner26941452010-04-10 17:52:58 +0000628void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000629
Gregory Szorc34c863a2012-03-21 03:54:29 +0000630/**
631 * Obtain the context to which this module is associated.
632 *
633 * @see Module::getContext()
634 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000635LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
636
Gregory Szorc34c863a2012-03-21 03:54:29 +0000637/**
638 * Obtain a Type from a module by its registered name.
639 */
640LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000641
Gregory Szorc34c863a2012-03-21 03:54:29 +0000642/**
643 * Obtain the number of operands for named metadata in a module.
644 *
645 * @see llvm::Module::getNamedMetadata()
646 */
647unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
648
649/**
650 * Obtain the named metadata operands for a module.
651 *
652 * The passed LLVMValueRef pointer should refer to an array of
653 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
654 * array will be populated with the LLVMValueRef instances. Each
655 * instance corresponds to a llvm::MDNode.
656 *
657 * @see llvm::Module::getNamedMetadata()
658 * @see llvm::MDNode::getOperand()
659 */
660void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
661
662/**
663 * Add an operand to named metadata.
664 *
665 * @see llvm::Module::getNamedMetadata()
666 * @see llvm::MDNode::addOperand()
667 */
668void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
669 LLVMValueRef Val);
670
Gregory Szorc52d26602012-03-21 07:28:27 +0000671/**
672 * Add a function to a module under a specified name.
673 *
674 * @see llvm::Function::Create()
675 */
676LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
677 LLVMTypeRef FunctionTy);
678
679/**
680 * Obtain a Function value from a Module by its name.
681 *
682 * The returned value corresponds to a llvm::Function value.
683 *
684 * @see llvm::Module::getFunction()
685 */
686LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
687
688/**
689 * Obtain an iterator to the first Function in a Module.
690 *
691 * @see llvm::Module::begin()
692 */
693LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
694
695/**
696 * Obtain an iterator to the last Function in a Module.
697 *
698 * @see llvm::Module::end()
699 */
700LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
701
702/**
703 * Advance a Function iterator to the next Function.
704 *
705 * Returns NULL if the iterator was already at the end and there are no more
706 * functions.
707 */
708LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
709
710/**
711 * Decrement a Function iterator to the previous Function.
712 *
713 * Returns NULL if the iterator was already at the beginning and there are
714 * no previous functions.
715 */
716LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000717
718/**
719 * @}
720 */
721
722/**
723 * @defgroup LLVMCCoreType Types
724 *
725 * Types represent the type of a value.
726 *
727 * Types are associated with a context instance. The context internally
728 * deduplicates types so there is only 1 instance of a specific type
729 * alive at a time. In other words, a unique type is shared among all
730 * consumers within a context.
731 *
732 * A Type in the C API corresponds to llvm::Type.
733 *
734 * Types have the following hierarchy:
735 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000736 * types:
737 * integer type
738 * real type
739 * function type
740 * sequence types:
741 * array type
742 * pointer type
743 * vector type
744 * void type
745 * label type
746 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000747 *
748 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000749 */
750
Gregory Szorc34c863a2012-03-21 03:54:29 +0000751/**
752 * Obtain the enumerated type of a Type instance.
753 *
754 * @see llvm::Type:getTypeID()
755 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000756LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000757
758/**
759 * Whether the type has a known size.
760 *
761 * Things that don't have a size are abstract types, labels, and void.a
762 *
763 * @see llvm::Type::isSized()
764 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000765LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000766
Gregory Szorc34c863a2012-03-21 03:54:29 +0000767/**
768 * Obtain the context to which this type instance is associated.
769 *
770 * @see llvm::Type::getContext()
771 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000772LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
773
Gregory Szorc34c863a2012-03-21 03:54:29 +0000774/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000775 * Dump a representation of a type to stderr.
776 *
777 * @see llvm::Type::dump()
778 */
779void LLVMDumpType(LLVMTypeRef Val);
780
781/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000782 * Return a string representation of the type. Use
783 * LLVMDisposeMessage to free the string.
784 *
785 * @see llvm::Type::print()
786 */
787char *LLVMPrintTypeToString(LLVMTypeRef Val);
788
789/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000790 * @defgroup LLVMCCoreTypeInt Integer Types
791 *
792 * Functions in this section operate on integer types.
793 *
794 * @{
795 */
796
797/**
798 * Obtain an integer type from a context with specified bit width.
799 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000800LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
801LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
802LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
803LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
804LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
805LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
806
Gregory Szorc34c863a2012-03-21 03:54:29 +0000807/**
808 * Obtain an integer type from the global context with a specified bit
809 * width.
810 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000811LLVMTypeRef LLVMInt1Type(void);
812LLVMTypeRef LLVMInt8Type(void);
813LLVMTypeRef LLVMInt16Type(void);
814LLVMTypeRef LLVMInt32Type(void);
815LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000816LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000817unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000818
Gregory Szorc34c863a2012-03-21 03:54:29 +0000819/**
820 * @}
821 */
822
823/**
824 * @defgroup LLVMCCoreTypeFloat Floating Point Types
825 *
826 * @{
827 */
828
829/**
830 * Obtain a 16-bit floating point type from a context.
831 */
Dan Gohman518cda42011-12-17 00:04:22 +0000832LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000833
834/**
835 * Obtain a 32-bit floating point type from a context.
836 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000837LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000838
839/**
840 * Obtain a 64-bit floating point type from a context.
841 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000842LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000843
844/**
845 * Obtain a 80-bit floating point type (X87) from a context.
846 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000847LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000848
849/**
850 * Obtain a 128-bit floating point type (112-bit mantissa) from a
851 * context.
852 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000853LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000854
855/**
856 * Obtain a 128-bit floating point type (two 64-bits) from a context.
857 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000858LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
859
Gregory Szorc34c863a2012-03-21 03:54:29 +0000860/**
861 * Obtain a floating point type from the global context.
862 *
863 * These map to the functions in this group of the same name.
864 */
Dan Gohman518cda42011-12-17 00:04:22 +0000865LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000866LLVMTypeRef LLVMFloatType(void);
867LLVMTypeRef LLVMDoubleType(void);
868LLVMTypeRef LLVMX86FP80Type(void);
869LLVMTypeRef LLVMFP128Type(void);
870LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000871
Gregory Szorc34c863a2012-03-21 03:54:29 +0000872/**
873 * @}
874 */
875
876/**
877 * @defgroup LLVMCCoreTypeFunction Function Types
878 *
879 * @{
880 */
881
882/**
883 * Obtain a function type consisting of a specified signature.
884 *
885 * The function is defined as a tuple of a return Type, a list of
886 * parameter types, and whether the function is variadic.
887 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000888LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
889 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000890 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000891
892/**
893 * Returns whether a function type is variadic.
894 */
Chris Lattner25963c62010-01-09 22:27:07 +0000895LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000896
897/**
898 * Obtain the Type this function Type returns.
899 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000900LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000901
902/**
903 * Obtain the number of parameters this function accepts.
904 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000905unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000906
907/**
908 * Obtain the types of a function's parameters.
909 *
910 * The Dest parameter should point to a pre-allocated array of
911 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
912 * first LLVMCountParamTypes() entries in the array will be populated
913 * with LLVMTypeRef instances.
914 *
915 * @param FunctionTy The function type to operate on.
916 * @param Dest Memory address of an array to be filled with result.
917 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000918void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000919
Gregory Szorc34c863a2012-03-21 03:54:29 +0000920/**
921 * @}
922 */
923
924/**
925 * @defgroup LLVMCCoreTypeStruct Structure Types
926 *
927 * These functions relate to LLVMTypeRef instances.
928 *
929 * @see llvm::StructType
930 *
931 * @{
932 */
933
934/**
935 * Create a new structure type in a context.
936 *
937 * A structure is specified by a list of inner elements/types and
938 * whether these can be packed together.
939 *
940 * @see llvm::StructType::create()
941 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000942LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000943 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000944
945/**
946 * Create a new structure type in the global context.
947 *
948 * @see llvm::StructType::create()
949 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000950LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000951 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000952
953/**
954 * Create an empty structure in a context having a specified name.
955 *
956 * @see llvm::StructType::create()
957 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000958LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000959
960/**
961 * Obtain the name of a structure.
962 *
963 * @see llvm::StructType::getName()
964 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000965const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000966
967/**
968 * Set the contents of a structure type.
969 *
970 * @see llvm::StructType::setBody()
971 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000972void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
973 unsigned ElementCount, LLVMBool Packed);
974
Gregory Szorc34c863a2012-03-21 03:54:29 +0000975/**
976 * Get the number of elements defined inside the structure.
977 *
978 * @see llvm::StructType::getNumElements()
979 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000980unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000981
982/**
983 * Get the elements within a structure.
984 *
985 * The function is passed the address of a pre-allocated array of
986 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
987 * invocation, this array will be populated with the structure's
988 * elements. The objects in the destination array will have a lifetime
989 * of the structure type itself, which is the lifetime of the context it
990 * is contained in.
991 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000992void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000993
994/**
995 * Determine whether a structure is packed.
996 *
997 * @see llvm::StructType::isPacked()
998 */
Chris Lattner25963c62010-01-09 22:27:07 +0000999LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001000
1001/**
1002 * Determine whether a structure is opaque.
1003 *
1004 * @see llvm::StructType::isOpaque()
1005 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001006LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1007
Gregory Szorc34c863a2012-03-21 03:54:29 +00001008/**
1009 * @}
1010 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001011
Gregory Szorc34c863a2012-03-21 03:54:29 +00001012
1013/**
1014 * @defgroup LLVMCCoreTypeSequential Sequential Types
1015 *
1016 * Sequential types represents "arrays" of types. This is a super class
1017 * for array, vector, and pointer types.
1018 *
1019 * @{
1020 */
1021
1022/**
1023 * Obtain the type of elements within a sequential type.
1024 *
1025 * This works on array, vector, and pointer types.
1026 *
1027 * @see llvm::SequentialType::getElementType()
1028 */
1029LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1030
1031/**
1032 * Create a fixed size array type that refers to a specific type.
1033 *
1034 * The created type will exist in the context that its element type
1035 * exists in.
1036 *
1037 * @see llvm::ArrayType::get()
1038 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001039LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001040
1041/**
1042 * Obtain the length of an array type.
1043 *
1044 * This only works on types that represent arrays.
1045 *
1046 * @see llvm::ArrayType::getNumElements()
1047 */
1048unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1049
1050/**
1051 * Create a pointer type that points to a defined type.
1052 *
1053 * The created type will exist in the context that its pointee type
1054 * exists in.
1055 *
1056 * @see llvm::PointerType::get()
1057 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001058LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001059
1060/**
1061 * Obtain the address space of a pointer type.
1062 *
1063 * This only works on types that represent pointers.
1064 *
1065 * @see llvm::PointerType::getAddressSpace()
1066 */
1067unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1068
1069/**
1070 * Create a vector type that contains a defined type and has a specific
1071 * number of elements.
1072 *
1073 * The created type will exist in the context thats its element type
1074 * exists in.
1075 *
1076 * @see llvm::VectorType::get()
1077 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001078LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001079
Gregory Szorc34c863a2012-03-21 03:54:29 +00001080/**
1081 * Obtain the number of elements in a vector type.
1082 *
1083 * This only works on types that represent vectors.
1084 *
1085 * @see llvm::VectorType::getNumElements()
1086 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001087unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1088
Gregory Szorc34c863a2012-03-21 03:54:29 +00001089/**
1090 * @}
1091 */
1092
1093/**
1094 * @defgroup LLVMCCoreTypeOther Other Types
1095 *
1096 * @{
1097 */
1098
1099/**
1100 * Create a void type in a context.
1101 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001102LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001103
1104/**
1105 * Create a label type in a context.
1106 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001107LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001108
1109/**
1110 * Create a X86 MMX type in a context.
1111 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001112LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001113
Gregory Szorc34c863a2012-03-21 03:54:29 +00001114/**
1115 * These are similar to the above functions except they operate on the
1116 * global context.
1117 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001118LLVMTypeRef LLVMVoidType(void);
1119LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001120LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001121
Gregory Szorc34c863a2012-03-21 03:54:29 +00001122/**
1123 * @}
1124 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001125
Gregory Szorc34c863a2012-03-21 03:54:29 +00001126/**
1127 * @}
1128 */
1129
1130/**
1131 * @defgroup LLVMCCoreValues Values
1132 *
1133 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001134 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001135 *
1136 * LLVMValueRef essentially represents llvm::Value. There is a rich
1137 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001138 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001139 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001140 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001141 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1142 * functions are defined by a macro, so it isn't obvious which are
1143 * available by looking at the Doxygen source code. Instead, look at the
1144 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1145 * of value names given. These value names also correspond to classes in
1146 * the llvm::Value hierarchy.
1147 *
1148 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001149 */
1150
Gordon Henriksen29e38942008-12-19 18:39:45 +00001151#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1152 macro(Argument) \
1153 macro(BasicBlock) \
1154 macro(InlineAsm) \
Torok Edwind09b7572011-10-14 20:37:56 +00001155 macro(MDNode) \
1156 macro(MDString) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001157 macro(User) \
1158 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001159 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001160 macro(ConstantAggregateZero) \
1161 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001162 macro(ConstantDataSequential) \
1163 macro(ConstantDataArray) \
1164 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001165 macro(ConstantExpr) \
1166 macro(ConstantFP) \
1167 macro(ConstantInt) \
1168 macro(ConstantPointerNull) \
1169 macro(ConstantStruct) \
1170 macro(ConstantVector) \
1171 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001172 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001173 macro(GlobalObject) \
1174 macro(Function) \
1175 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001176 macro(UndefValue) \
1177 macro(Instruction) \
1178 macro(BinaryOperator) \
1179 macro(CallInst) \
1180 macro(IntrinsicInst) \
1181 macro(DbgInfoIntrinsic) \
1182 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001183 macro(MemIntrinsic) \
1184 macro(MemCpyInst) \
1185 macro(MemMoveInst) \
1186 macro(MemSetInst) \
1187 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001188 macro(FCmpInst) \
1189 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001190 macro(ExtractElementInst) \
1191 macro(GetElementPtrInst) \
1192 macro(InsertElementInst) \
1193 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001194 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001195 macro(PHINode) \
1196 macro(SelectInst) \
1197 macro(ShuffleVectorInst) \
1198 macro(StoreInst) \
1199 macro(TerminatorInst) \
1200 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001201 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001202 macro(InvokeInst) \
1203 macro(ReturnInst) \
1204 macro(SwitchInst) \
1205 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001206 macro(ResumeInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001207 macro(UnaryInstruction) \
1208 macro(AllocaInst) \
1209 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001210 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001211 macro(BitCastInst) \
1212 macro(FPExtInst) \
1213 macro(FPToSIInst) \
1214 macro(FPToUIInst) \
1215 macro(FPTruncInst) \
1216 macro(IntToPtrInst) \
1217 macro(PtrToIntInst) \
1218 macro(SExtInst) \
1219 macro(SIToFPInst) \
1220 macro(TruncInst) \
1221 macro(UIToFPInst) \
1222 macro(ZExtInst) \
1223 macro(ExtractValueInst) \
1224 macro(LoadInst) \
1225 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001226
Gregory Szorc34c863a2012-03-21 03:54:29 +00001227/**
1228 * @defgroup LLVMCCoreValueGeneral General APIs
1229 *
1230 * Functions in this section work on all LLVMValueRef instances,
1231 * regardless of their sub-type. They correspond to functions available
1232 * on llvm::Value.
1233 *
1234 * @{
1235 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001236
Gregory Szorc34c863a2012-03-21 03:54:29 +00001237/**
1238 * Obtain the type of a value.
1239 *
1240 * @see llvm::Value::getType()
1241 */
1242LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1243
1244/**
1245 * Obtain the string name of a value.
1246 *
1247 * @see llvm::Value::getName()
1248 */
1249const char *LLVMGetValueName(LLVMValueRef Val);
1250
1251/**
1252 * Set the string name of a value.
1253 *
1254 * @see llvm::Value::setName()
1255 */
1256void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1257
1258/**
1259 * Dump a representation of a value to stderr.
1260 *
1261 * @see llvm::Value::dump()
1262 */
1263void LLVMDumpValue(LLVMValueRef Val);
1264
1265/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001266 * Return a string representation of the value. Use
1267 * LLVMDisposeMessage to free the string.
1268 *
1269 * @see llvm::Value::print()
1270 */
1271char *LLVMPrintValueToString(LLVMValueRef Val);
1272
1273/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001274 * Replace all uses of a value with another one.
1275 *
1276 * @see llvm::Value::replaceAllUsesWith()
1277 */
1278void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1279
1280/**
1281 * Determine whether the specified constant instance is constant.
1282 */
1283LLVMBool LLVMIsConstant(LLVMValueRef Val);
1284
1285/**
1286 * Determine whether a value instance is undefined.
1287 */
1288LLVMBool LLVMIsUndef(LLVMValueRef Val);
1289
1290/**
1291 * Convert value instances between types.
1292 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001293 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001294 * series of functions allows you to cast an instance to a specific
1295 * type.
1296 *
1297 * If the cast is not valid for the specified type, NULL is returned.
1298 *
1299 * @see llvm::dyn_cast_or_null<>
1300 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001301#define LLVM_DECLARE_VALUE_CAST(name) \
1302 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1303LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1304
Gregory Szorc34c863a2012-03-21 03:54:29 +00001305/**
1306 * @}
1307 */
1308
1309/**
1310 * @defgroup LLVMCCoreValueUses Usage
1311 *
1312 * This module defines functions that allow you to inspect the uses of a
1313 * LLVMValueRef.
1314 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001315 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001316 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1317 * llvm::User and llvm::Value.
1318 *
1319 * @{
1320 */
1321
1322/**
1323 * Obtain the first use of a value.
1324 *
1325 * Uses are obtained in an iterator fashion. First, call this function
1326 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001327 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001328 * LLVMGetNextUse() returns NULL.
1329 *
1330 * @see llvm::Value::use_begin()
1331 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001332LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001333
1334/**
1335 * Obtain the next use of a value.
1336 *
1337 * This effectively advances the iterator. It returns NULL if you are on
1338 * the final use and no more are available.
1339 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001340LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001341
1342/**
1343 * Obtain the user value for a user.
1344 *
1345 * The returned value corresponds to a llvm::User type.
1346 *
1347 * @see llvm::Use::getUser()
1348 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001349LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001350
1351/**
1352 * Obtain the value this use corresponds to.
1353 *
1354 * @see llvm::Use::get().
1355 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001356LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001357
Gregory Szorc34c863a2012-03-21 03:54:29 +00001358/**
1359 * @}
1360 */
1361
1362/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001363 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001364 *
1365 * Function in this group pertain to LLVMValueRef instances that descent
1366 * from llvm::User. This includes constants, instructions, and
1367 * operators.
1368 *
1369 * @{
1370 */
1371
1372/**
1373 * Obtain an operand at a specific index in a llvm::User value.
1374 *
1375 * @see llvm::User::getOperand()
1376 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001377LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001378
1379/**
1380 * Set an operand at a specific index in a llvm::User value.
1381 *
1382 * @see llvm::User::setOperand()
1383 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001384void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001385
1386/**
1387 * Obtain the number of operands in a llvm::User value.
1388 *
1389 * @see llvm::User::getNumOperands()
1390 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001391int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001392
Gregory Szorc34c863a2012-03-21 03:54:29 +00001393/**
1394 * @}
1395 */
1396
1397/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001398 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001399 *
1400 * This section contains APIs for interacting with LLVMValueRef that
1401 * correspond to llvm::Constant instances.
1402 *
1403 * These functions will work for any LLVMValueRef in the llvm::Constant
1404 * class hierarchy.
1405 *
1406 * @{
1407 */
1408
1409/**
1410 * Obtain a constant value referring to the null instance of a type.
1411 *
1412 * @see llvm::Constant::getNullValue()
1413 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001414LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001415
1416/**
1417 * Obtain a constant value referring to the instance of a type
1418 * consisting of all ones.
1419 *
1420 * This is only valid for integer types.
1421 *
1422 * @see llvm::Constant::getAllOnesValue()
1423 */
1424LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1425
1426/**
1427 * Obtain a constant value referring to an undefined value of a type.
1428 *
1429 * @see llvm::UndefValue::get()
1430 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001431LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001432
1433/**
1434 * Determine whether a value instance is null.
1435 *
1436 * @see llvm::Constant::isNullValue()
1437 */
Chris Lattner25963c62010-01-09 22:27:07 +00001438LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001439
1440/**
1441 * Obtain a constant that is a constant pointer pointing to NULL for a
1442 * specified type.
1443 */
Chris Lattner7f318242009-07-06 17:29:59 +00001444LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001445
Gregory Szorc34c863a2012-03-21 03:54:29 +00001446/**
1447 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1448 *
1449 * Functions in this group model LLVMValueRef instances that correspond
1450 * to constants referring to scalar types.
1451 *
1452 * For integer types, the LLVMTypeRef parameter should correspond to a
1453 * llvm::IntegerType instance and the returned LLVMValueRef will
1454 * correspond to a llvm::ConstantInt.
1455 *
1456 * For floating point types, the LLVMTypeRef returned corresponds to a
1457 * llvm::ConstantFP.
1458 *
1459 * @{
1460 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001461
Gregory Szorc34c863a2012-03-21 03:54:29 +00001462/**
1463 * Obtain a constant value for an integer type.
1464 *
1465 * The returned value corresponds to a llvm::ConstantInt.
1466 *
1467 * @see llvm::ConstantInt::get()
1468 *
1469 * @param IntTy Integer type to obtain value of.
1470 * @param N The value the returned instance should refer to.
1471 * @param SignExtend Whether to sign extend the produced value.
1472 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001473LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001474 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001475
1476/**
1477 * Obtain a constant value for an integer of arbitrary precision.
1478 *
1479 * @see llvm::ConstantInt::get()
1480 */
Chris Lattner4329e072010-11-23 02:47:22 +00001481LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1482 unsigned NumWords,
1483 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001484
1485/**
1486 * Obtain a constant value for an integer parsed from a string.
1487 *
1488 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1489 * string's length is available, it is preferred to call that function
1490 * instead.
1491 *
1492 * @see llvm::ConstantInt::get()
1493 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001494LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1495 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001496
1497/**
1498 * Obtain a constant value for an integer parsed from a string with
1499 * specified length.
1500 *
1501 * @see llvm::ConstantInt::get()
1502 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001503LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1504 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001505
1506/**
1507 * Obtain a constant value referring to a double floating point value.
1508 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001509LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001510
1511/**
1512 * Obtain a constant for a floating point value parsed from a string.
1513 *
1514 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1515 * should be used if the input string's length is known.
1516 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001517LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001518
1519/**
1520 * Obtain a constant for a floating point value parsed from a string.
1521 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001522LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1523 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001524
1525/**
1526 * Obtain the zero extended value for an integer constant value.
1527 *
1528 * @see llvm::ConstantInt::getZExtValue()
1529 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001530unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001531
1532/**
1533 * Obtain the sign extended value for an integer constant value.
1534 *
1535 * @see llvm::ConstantInt::getSExtValue()
1536 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001537long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001538
Gregory Szorc34c863a2012-03-21 03:54:29 +00001539/**
1540 * @}
1541 */
1542
1543/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001544 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1545 *
1546 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001547 *
1548 * @{
1549 */
1550
1551/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001552 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001553 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001554 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001555 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001556LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001557 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001558
1559/**
1560 * Create a ConstantDataSequential with string content in the global context.
1561 *
1562 * This is the same as LLVMConstStringInContext except it operates on the
1563 * global context.
1564 *
1565 * @see LLVMConstStringInContext()
1566 * @see llvm::ConstantDataArray::getString()
1567 */
1568LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1569 LLVMBool DontNullTerminate);
1570
1571/**
1572 * Create an anonymous ConstantStruct with the specified values.
1573 *
1574 * @see llvm::ConstantStruct::getAnon()
1575 */
1576LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001577 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001578 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001579
Gregory Szorc52d26602012-03-21 07:28:27 +00001580/**
1581 * Create a ConstantStruct in the global Context.
1582 *
1583 * This is the same as LLVMConstStructInContext except it operates on the
1584 * global Context.
1585 *
1586 * @see LLVMConstStructInContext()
1587 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001588LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001589 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001590
1591/**
1592 * Create a ConstantArray from values.
1593 *
1594 * @see llvm::ConstantArray::get()
1595 */
1596LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1597 LLVMValueRef *ConstantVals, unsigned Length);
1598
1599/**
1600 * Create a non-anonymous ConstantStruct from values.
1601 *
1602 * @see llvm::ConstantStruct::get()
1603 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001604LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1605 LLVMValueRef *ConstantVals,
1606 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001607
1608/**
1609 * Create a ConstantVector from values.
1610 *
1611 * @see llvm::ConstantVector::get()
1612 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001613LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001614
Gregory Szorc52d26602012-03-21 07:28:27 +00001615/**
1616 * @}
1617 */
1618
1619/**
1620 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1621 *
1622 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1623 *
1624 * @see llvm::ConstantExpr.
1625 *
1626 * @{
1627 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001628LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001629LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001630LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1631LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001632LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1633LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001634LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001635LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1636LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001637LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001638LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001639LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001640LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001641LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1642LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001643LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001644LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001645LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1646LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001647LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001648LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1649LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001650LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001651LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1652LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1653LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1654LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1655LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1656LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1657LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1658LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1659 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1660LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1661 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1662LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1663LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1664LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1665LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1666 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001667LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1668 LLVMValueRef *ConstantIndices,
1669 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001670LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1671LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1672LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1673LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1674LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1675LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1676LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1677LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1678LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1679LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1680LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1681LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001682LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001683LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1684 LLVMTypeRef ToType);
1685LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1686 LLVMTypeRef ToType);
1687LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1688 LLVMTypeRef ToType);
1689LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1690 LLVMTypeRef ToType);
1691LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001692 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001693LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001694LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1695 LLVMValueRef ConstantIfTrue,
1696 LLVMValueRef ConstantIfFalse);
1697LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1698 LLVMValueRef IndexConstant);
1699LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1700 LLVMValueRef ElementValueConstant,
1701 LLVMValueRef IndexConstant);
1702LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1703 LLVMValueRef VectorBConstant,
1704 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001705LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1706 unsigned NumIdx);
1707LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1708 LLVMValueRef ElementValueConstant,
1709 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001710LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001711 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001712 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001713LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001714
Gregory Szorc52d26602012-03-21 07:28:27 +00001715/**
1716 * @}
1717 */
1718
1719/**
1720 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1721 *
1722 * This group contains functions that operate on global values. Functions in
1723 * this group relate to functions in the llvm::GlobalValue class tree.
1724 *
1725 * @see llvm::GlobalValue
1726 *
1727 * @{
1728 */
1729
Gordon Henriksen265f7802008-03-19 01:11:35 +00001730LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001731LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001732LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1733void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1734const char *LLVMGetSection(LLVMValueRef Global);
1735void LLVMSetSection(LLVMValueRef Global, const char *Section);
1736LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1737void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001738LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1739void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001740LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1741void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001742
1743/**
1744 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1745 *
1746 * Functions in this group only apply to values with alignment, i.e.
1747 * global variables, load and store instructions.
1748 */
1749
1750/**
1751 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001752 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001753 * @see llvm::LoadInst::getAlignment()
1754 * @see llvm::StoreInst::getAlignment()
1755 * @see llvm::GlobalValue::getAlignment()
1756 */
1757unsigned LLVMGetAlignment(LLVMValueRef V);
1758
1759/**
1760 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001761 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001762 * @see llvm::LoadInst::setAlignment()
1763 * @see llvm::StoreInst::setAlignment()
1764 * @see llvm::GlobalValue::setAlignment()
1765 */
1766void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1767
1768/**
1769 * @}
1770 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001771
Gregory Szorc52d26602012-03-21 07:28:27 +00001772/**
1773 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1774 *
1775 * This group contains functions that operate on global variable values.
1776 *
1777 * @see llvm::GlobalVariable
1778 *
1779 * @{
1780 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001781LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001782LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1783 const char *Name,
1784 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001785LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001786LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1787LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1788LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1789LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001790void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001791LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1792void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001793LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1794void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1795LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1796void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001797LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1798void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1799LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1800void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001801
Gregory Szorc52d26602012-03-21 07:28:27 +00001802/**
1803 * @}
1804 */
1805
1806/**
1807 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1808 *
1809 * This group contains function that operate on global alias values.
1810 *
1811 * @see llvm::GlobalAlias
1812 *
1813 * @{
1814 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001815LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1816 const char *Name);
1817
Gregory Szorc34c863a2012-03-21 03:54:29 +00001818/**
1819 * @}
1820 */
1821
1822/**
1823 * @defgroup LLVMCCoreValueFunction Function values
1824 *
1825 * Functions in this group operate on LLVMValueRef instances that
1826 * correspond to llvm::Function instances.
1827 *
1828 * @see llvm::Function
1829 *
1830 * @{
1831 */
1832
1833/**
1834 * Remove a function from its containing module and deletes it.
1835 *
1836 * @see llvm::Function::eraseFromParent()
1837 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001838void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001839
1840/**
1841 * Obtain the ID number from a function instance.
1842 *
1843 * @see llvm::Function::getIntrinsicID()
1844 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001845unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001846
1847/**
1848 * Obtain the calling function of a function.
1849 *
1850 * The returned value corresponds to the LLVMCallConv enumeration.
1851 *
1852 * @see llvm::Function::getCallingConv()
1853 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001854unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001855
1856/**
1857 * Set the calling convention of a function.
1858 *
1859 * @see llvm::Function::setCallingConv()
1860 *
1861 * @param Fn Function to operate on
1862 * @param CC LLVMCallConv to set calling convention to
1863 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001864void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001865
1866/**
1867 * Obtain the name of the garbage collector to use during code
1868 * generation.
1869 *
1870 * @see llvm::Function::getGC()
1871 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001872const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001873
1874/**
1875 * Define the garbage collector to use during code generation.
1876 *
1877 * @see llvm::Function::setGC()
1878 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001879void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001880
1881/**
1882 * Add an attribute to a function.
1883 *
1884 * @see llvm::Function::addAttribute()
1885 */
Duncan Sands7374a012009-05-06 12:21:17 +00001886void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001887
1888/**
Tom Stellarde8f35e12013-04-16 23:12:43 +00001889 * Add a target-dependent attribute to a fuction
1890 * @see llvm::AttrBuilder::addAttribute()
1891 */
1892void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1893 const char *V);
1894
1895/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001896 * Obtain an attribute from a function.
1897 *
1898 * @see llvm::Function::getAttributes()
1899 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001900LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001901
1902/**
1903 * Remove an attribute from a function.
1904 */
Duncan Sands7374a012009-05-06 12:21:17 +00001905void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001906
Gregory Szorc34c863a2012-03-21 03:54:29 +00001907/**
1908 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1909 *
1910 * Functions in this group relate to arguments/parameters on functions.
1911 *
1912 * Functions in this group expect LLVMValueRef instances that correspond
1913 * to llvm::Function instances.
1914 *
1915 * @{
1916 */
1917
1918/**
1919 * Obtain the number of parameters in a function.
1920 *
1921 * @see llvm::Function::arg_size()
1922 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001923unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001924
1925/**
1926 * Obtain the parameters in a function.
1927 *
1928 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1929 * at least LLVMCountParams() long. This array will be filled with
1930 * LLVMValueRef instances which correspond to the parameters the
1931 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1932 * instance.
1933 *
1934 * @see llvm::Function::arg_begin()
1935 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001936void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001937
1938/**
1939 * Obtain the parameter at the specified index.
1940 *
1941 * Parameters are indexed from 0.
1942 *
1943 * @see llvm::Function::arg_begin()
1944 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001945LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001946
1947/**
1948 * Obtain the function to which this argument belongs.
1949 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001950 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00001951 * that corresponds to a llvm::Attribute.
1952 *
1953 * The returned LLVMValueRef is the llvm::Function to which this
1954 * argument belongs.
1955 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001956LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001957
1958/**
1959 * Obtain the first parameter to a function.
1960 *
1961 * @see llvm::Function::arg_begin()
1962 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001963LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001964
1965/**
1966 * Obtain the last parameter to a function.
1967 *
1968 * @see llvm::Function::arg_end()
1969 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001970LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001971
1972/**
1973 * Obtain the next parameter to a function.
1974 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001975 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00001976 * actually a wrapped iterator) and obtains the next parameter from the
1977 * underlying iterator.
1978 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001979LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001980
1981/**
1982 * Obtain the previous parameter to a function.
1983 *
1984 * This is the opposite of LLVMGetNextParam().
1985 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001986LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001987
1988/**
1989 * Add an attribute to a function argument.
1990 *
1991 * @see llvm::Argument::addAttr()
1992 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001993void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001994
1995/**
1996 * Remove an attribute from a function argument.
1997 *
1998 * @see llvm::Argument::removeAttr()
1999 */
Devang Patel4c758ea2008-09-25 21:00:45 +00002000void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002001
2002/**
2003 * Get an attribute from a function argument.
2004 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002005LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002006
2007/**
2008 * Set the alignment for a function parameter.
2009 *
2010 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002011 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002012 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002013void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002014
Gregory Szorc34c863a2012-03-21 03:54:29 +00002015/**
2016 * @}
2017 */
2018
2019/**
2020 * @}
2021 */
2022
2023/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002024 * @}
2025 */
2026
2027/**
2028 * @}
2029 */
2030
2031/**
2032 * @defgroup LLVMCCoreValueMetadata Metadata
2033 *
2034 * @{
2035 */
2036
2037/**
2038 * Obtain a MDString value from a context.
2039 *
2040 * The returned instance corresponds to the llvm::MDString class.
2041 *
2042 * The instance is specified by string data of a specified length. The
2043 * string content is copied, so the backing memory can be freed after
2044 * this function returns.
2045 */
2046LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2047 unsigned SLen);
2048
2049/**
2050 * Obtain a MDString value from the global context.
2051 */
2052LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2053
2054/**
2055 * Obtain a MDNode value from a context.
2056 *
2057 * The returned value corresponds to the llvm::MDNode class.
2058 */
2059LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2060 unsigned Count);
2061
2062/**
2063 * Obtain a MDNode value from the global context.
2064 */
2065LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2066
2067/**
2068 * Obtain the underlying string from a MDString value.
2069 *
2070 * @param V Instance to obtain string from.
2071 * @param Len Memory address which will hold length of returned string.
2072 * @return String data in MDString.
2073 */
2074const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2075
2076/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002077 * Obtain the number of operands from an MDNode value.
2078 *
2079 * @param V MDNode to get number of operands from.
2080 * @return Number of operands of the MDNode.
2081 */
2082unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2083
2084/**
2085 * Obtain the given MDNode's operands.
2086 *
2087 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2088 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2089 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2090 * MDNode's operands.
2091 *
2092 * @param V MDNode to get the operands from.
2093 * @param Dest Destination array for operands.
2094 */
2095void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2096
2097/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002098 * @}
2099 */
2100
2101/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002102 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2103 *
2104 * A basic block represents a single entry single exit section of code.
2105 * Basic blocks contain a list of instructions which form the body of
2106 * the block.
2107 *
2108 * Basic blocks belong to functions. They have the type of label.
2109 *
2110 * Basic blocks are themselves values. However, the C API models them as
2111 * LLVMBasicBlockRef.
2112 *
2113 * @see llvm::BasicBlock
2114 *
2115 * @{
2116 */
2117
2118/**
2119 * Convert a basic block instance to a value type.
2120 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002121LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002122
2123/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002124 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002125 */
Chris Lattner25963c62010-01-09 22:27:07 +00002126LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002127
2128/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002129 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002130 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002131LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002132
2133/**
2134 * Obtain the function to which a basic block belongs.
2135 *
2136 * @see llvm::BasicBlock::getParent()
2137 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002138LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002139
2140/**
2141 * Obtain the terminator instruction for a basic block.
2142 *
2143 * If the basic block does not have a terminator (it is not well-formed
2144 * if it doesn't), then NULL is returned.
2145 *
2146 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2147 *
2148 * @see llvm::BasicBlock::getTerminator()
2149 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002150LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002151
2152/**
2153 * Obtain the number of basic blocks in a function.
2154 *
2155 * @param Fn Function value to operate on.
2156 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002157unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002158
2159/**
2160 * Obtain all of the basic blocks in a function.
2161 *
2162 * This operates on a function value. The BasicBlocks parameter is a
2163 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2164 * LLVMCountBasicBlocks() in length. This array is populated with
2165 * LLVMBasicBlockRef instances.
2166 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002167void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002168
2169/**
2170 * Obtain the first basic block in a function.
2171 *
2172 * The returned basic block can be used as an iterator. You will likely
2173 * eventually call into LLVMGetNextBasicBlock() with it.
2174 *
2175 * @see llvm::Function::begin()
2176 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002177LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002178
2179/**
2180 * Obtain the last basic block in a function.
2181 *
2182 * @see llvm::Function::end()
2183 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002184LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002185
2186/**
2187 * Advance a basic block iterator.
2188 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002189LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002190
2191/**
2192 * Go backwards in a basic block iterator.
2193 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002194LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002195
2196/**
2197 * Obtain the basic block that corresponds to the entry point of a
2198 * function.
2199 *
2200 * @see llvm::Function::getEntryBlock()
2201 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002202LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002203
Gregory Szorc34c863a2012-03-21 03:54:29 +00002204/**
2205 * Append a basic block to the end of a function.
2206 *
2207 * @see llvm::BasicBlock::Create()
2208 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002209LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2210 LLVMValueRef Fn,
2211 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002212
2213/**
2214 * Append a basic block to the end of a function using the global
2215 * context.
2216 *
2217 * @see llvm::BasicBlock::Create()
2218 */
2219LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2220
2221/**
2222 * Insert a basic block in a function before another basic block.
2223 *
2224 * The function to add to is determined by the function of the
2225 * passed basic block.
2226 *
2227 * @see llvm::BasicBlock::Create()
2228 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002229LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2230 LLVMBasicBlockRef BB,
2231 const char *Name);
2232
Gregory Szorc34c863a2012-03-21 03:54:29 +00002233/**
2234 * Insert a basic block in a function using the global context.
2235 *
2236 * @see llvm::BasicBlock::Create()
2237 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002238LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2239 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002240
2241/**
2242 * Remove a basic block from a function and delete it.
2243 *
2244 * This deletes the basic block from its containing function and deletes
2245 * the basic block itself.
2246 *
2247 * @see llvm::BasicBlock::eraseFromParent()
2248 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002249void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002250
2251/**
2252 * Remove a basic block from a function.
2253 *
2254 * This deletes the basic block from its containing function but keep
2255 * the basic block alive.
2256 *
2257 * @see llvm::BasicBlock::removeFromParent()
2258 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002259void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002260
Gregory Szorc34c863a2012-03-21 03:54:29 +00002261/**
2262 * Move a basic block to before another one.
2263 *
2264 * @see llvm::BasicBlock::moveBefore()
2265 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002266void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002267
2268/**
2269 * Move a basic block to after another one.
2270 *
2271 * @see llvm::BasicBlock::moveAfter()
2272 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002273void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2274
Gregory Szorc34c863a2012-03-21 03:54:29 +00002275/**
2276 * Obtain the first instruction in a basic block.
2277 *
2278 * The returned LLVMValueRef corresponds to a llvm::Instruction
2279 * instance.
2280 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002281LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002282
2283/**
2284 * Obtain the last instruction in a basic block.
2285 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002286 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002287 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002288LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002289
Gregory Szorc34c863a2012-03-21 03:54:29 +00002290/**
2291 * @}
2292 */
2293
2294/**
2295 * @defgroup LLVMCCoreValueInstruction Instructions
2296 *
2297 * Functions in this group relate to the inspection and manipulation of
2298 * individual instructions.
2299 *
2300 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2301 * class has a large number of descendents. llvm::Instruction is a
2302 * llvm::Value and in the C API, instructions are modeled by
2303 * LLVMValueRef.
2304 *
2305 * This group also contains sub-groups which operate on specific
2306 * llvm::Instruction types, e.g. llvm::CallInst.
2307 *
2308 * @{
2309 */
2310
2311/**
2312 * Determine whether an instruction has any metadata attached.
2313 */
2314int LLVMHasMetadata(LLVMValueRef Val);
2315
2316/**
2317 * Return metadata associated with an instruction value.
2318 */
2319LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2320
2321/**
2322 * Set metadata associated with an instruction value.
2323 */
2324void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2325
2326/**
2327 * Obtain the basic block to which an instruction belongs.
2328 *
2329 * @see llvm::Instruction::getParent()
2330 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002331LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002332
2333/**
2334 * Obtain the instruction that occurs after the one specified.
2335 *
2336 * The next instruction will be from the same basic block.
2337 *
2338 * If this is the last instruction in a basic block, NULL will be
2339 * returned.
2340 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002341LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002342
2343/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002344 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002345 *
2346 * If the instruction is the first instruction in a basic block, NULL
2347 * will be returned.
2348 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002349LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002350
2351/**
2352 * Remove and delete an instruction.
2353 *
2354 * The instruction specified is removed from its containing building
2355 * block and then deleted.
2356 *
2357 * @see llvm::Instruction::eraseFromParent()
2358 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002359void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002360
2361/**
2362 * Obtain the code opcode for an individual instruction.
2363 *
2364 * @see llvm::Instruction::getOpCode()
2365 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002366LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002367
2368/**
2369 * Obtain the predicate of an instruction.
2370 *
2371 * This is only valid for instructions that correspond to llvm::ICmpInst
2372 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2373 *
2374 * @see llvm::ICmpInst::getPredicate()
2375 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002376LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002377
Gregory Szorc34c863a2012-03-21 03:54:29 +00002378/**
2379 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2380 *
2381 * Functions in this group apply to instructions that refer to call
2382 * sites and invocations. These correspond to C++ types in the
2383 * llvm::CallInst class tree.
2384 *
2385 * @{
2386 */
2387
2388/**
2389 * Set the calling convention for a call instruction.
2390 *
2391 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2392 * llvm::InvokeInst.
2393 *
2394 * @see llvm::CallInst::setCallingConv()
2395 * @see llvm::InvokeInst::setCallingConv()
2396 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002397void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002398
2399/**
2400 * Obtain the calling convention for a call instruction.
2401 *
2402 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2403 * usage.
2404 *
2405 * @see LLVMSetInstructionCallConv()
2406 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002407unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002408
2409
Devang Patel4c758ea2008-09-25 21:00:45 +00002410void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002411void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002412 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002413void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002414 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002415
Gregory Szorc34c863a2012-03-21 03:54:29 +00002416/**
2417 * Obtain whether a call instruction is a tail call.
2418 *
2419 * This only works on llvm::CallInst instructions.
2420 *
2421 * @see llvm::CallInst::isTailCall()
2422 */
Chris Lattner25963c62010-01-09 22:27:07 +00002423LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002424
2425/**
2426 * Set whether a call instruction is a tail call.
2427 *
2428 * This only works on llvm::CallInst instructions.
2429 *
2430 * @see llvm::CallInst::setTailCall()
2431 */
Chris Lattner25963c62010-01-09 22:27:07 +00002432void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002433
Gregory Szorc34c863a2012-03-21 03:54:29 +00002434/**
2435 * @}
2436 */
2437
2438/**
2439 * Obtain the default destination basic block of a switch instruction.
2440 *
2441 * This only works on llvm::SwitchInst instructions.
2442 *
2443 * @see llvm::SwitchInst::getDefaultDest()
2444 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002445LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2446
Gregory Szorc34c863a2012-03-21 03:54:29 +00002447/**
2448 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2449 *
2450 * Functions in this group only apply to instructions that map to
2451 * llvm::PHINode instances.
2452 *
2453 * @{
2454 */
2455
2456/**
2457 * Add an incoming value to the end of a PHI list.
2458 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002459void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2460 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002461
2462/**
2463 * Obtain the number of incoming basic blocks to a PHI node.
2464 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002465unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002466
2467/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002468 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002469 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002470LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002471
2472/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002473 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002474 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002475LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002476
Gregory Szorc34c863a2012-03-21 03:54:29 +00002477/**
2478 * @}
2479 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002480
Gregory Szorc34c863a2012-03-21 03:54:29 +00002481/**
2482 * @}
2483 */
2484
2485/**
2486 * @}
2487 */
2488
2489/**
2490 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2491 *
2492 * An instruction builder represents a point within a basic block and is
2493 * the exclusive means of building instructions using the C interface.
2494 *
2495 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002496 */
2497
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002498LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002499LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002500void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2501 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002502void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2503void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002504LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002505void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2506void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002507void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2508 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002509void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2510
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002511/* Metadata */
2512void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2513LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2514void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2515
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002516/* Terminators */
2517LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2518LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002519LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002520 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002521LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2522LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2523 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2524LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2525 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002526LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2527 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002528LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2529 LLVMValueRef *Args, unsigned NumArgs,
2530 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2531 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002532LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2533 LLVMValueRef PersFn, unsigned NumClauses,
2534 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002535LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002536LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2537
Gordon Henriksen097102c2008-01-01 05:50:53 +00002538/* Add a case to the switch instruction */
2539void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2540 LLVMBasicBlockRef Dest);
2541
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002542/* Add a destination to the indirectbr instruction */
2543void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2544
Bill Wendlingfae14752011-08-12 20:24:12 +00002545/* Add a catch or filter clause to the landingpad instruction */
2546void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2547
2548/* Set the 'cleanup' flag in the landingpad instruction */
2549void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2550
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002551/* Arithmetic */
2552LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2553 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002554LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2555 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002556LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2557 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002558LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2559 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002560LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2561 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002562LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2563 const char *Name);
2564LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2565 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002566LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2567 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002568LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2569 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002570LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2571 const char *Name);
2572LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2573 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002574LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2575 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002576LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2577 const char *Name);
2578LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2579 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002580LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2581 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002582LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2583 const char *Name);
2584LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2585 const char *Name);
2586LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2587 const char *Name);
2588LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2589 const char *Name);
2590LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2591 const char *Name);
2592LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2593 const char *Name);
2594LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2595 const char *Name);
2596LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2597 const char *Name);
2598LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2599 const char *Name);
2600LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2601 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002602LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2603 LLVMValueRef LHS, LLVMValueRef RHS,
2604 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002605LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002606LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2607 const char *Name);
2608LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2609 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002610LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002611LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2612
2613/* Memory */
2614LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2615LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2616 LLVMValueRef Val, const char *Name);
2617LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2618LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2619 LLVMValueRef Val, const char *Name);
2620LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2621LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2622 const char *Name);
2623LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2624LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2625 LLVMValueRef *Indices, unsigned NumIndices,
2626 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002627LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2628 LLVMValueRef *Indices, unsigned NumIndices,
2629 const char *Name);
2630LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2631 unsigned Idx, const char *Name);
2632LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2633 const char *Name);
2634LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2635 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002636LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2637void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002638
2639/* Casts */
2640LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2641 LLVMTypeRef DestTy, const char *Name);
2642LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2643 LLVMTypeRef DestTy, const char *Name);
2644LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2645 LLVMTypeRef DestTy, const char *Name);
2646LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2647 LLVMTypeRef DestTy, const char *Name);
2648LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2649 LLVMTypeRef DestTy, const char *Name);
2650LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2651 LLVMTypeRef DestTy, const char *Name);
2652LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2653 LLVMTypeRef DestTy, const char *Name);
2654LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2655 LLVMTypeRef DestTy, const char *Name);
2656LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2657 LLVMTypeRef DestTy, const char *Name);
2658LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2659 LLVMTypeRef DestTy, const char *Name);
2660LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2661 LLVMTypeRef DestTy, const char *Name);
2662LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2663 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002664LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2665 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002666LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2667 LLVMTypeRef DestTy, const char *Name);
2668LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2669 LLVMTypeRef DestTy, const char *Name);
2670LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2671 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002672LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2673 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002674LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2675 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002676LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002677 LLVMTypeRef DestTy, const char *Name);
2678LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2679 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002680
2681/* Comparisons */
2682LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2683 LLVMValueRef LHS, LLVMValueRef RHS,
2684 const char *Name);
2685LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2686 LLVMValueRef LHS, LLVMValueRef RHS,
2687 const char *Name);
2688
2689/* Miscellaneous instructions */
2690LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2691LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2692 LLVMValueRef *Args, unsigned NumArgs,
2693 const char *Name);
2694LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2695 LLVMValueRef Then, LLVMValueRef Else,
2696 const char *Name);
2697LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2698 const char *Name);
2699LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2700 LLVMValueRef Index, const char *Name);
2701LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2702 LLVMValueRef EltVal, LLVMValueRef Index,
2703 const char *Name);
2704LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2705 LLVMValueRef V2, LLVMValueRef Mask,
2706 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002707LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2708 unsigned Index, const char *Name);
2709LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2710 LLVMValueRef EltVal, unsigned Index,
2711 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002712
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002713LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2714 const char *Name);
2715LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2716 const char *Name);
2717LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2718 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00002719LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2720 LLVMBool singleThread, const char *Name);
2721LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00002722 LLVMValueRef PTR, LLVMValueRef Val,
2723 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00002724 LLVMBool singleThread);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002725
Gregory Szorc34c863a2012-03-21 03:54:29 +00002726/**
2727 * @}
2728 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002729
Gregory Szorc34c863a2012-03-21 03:54:29 +00002730/**
2731 * @defgroup LLVMCCoreModuleProvider Module Providers
2732 *
2733 * @{
2734 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002735
Gregory Szorc34c863a2012-03-21 03:54:29 +00002736/**
2737 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002738 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002739 */
2740LLVMModuleProviderRef
2741LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2742
Gregory Szorc34c863a2012-03-21 03:54:29 +00002743/**
2744 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002745 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002746void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002747
Gregory Szorc34c863a2012-03-21 03:54:29 +00002748/**
2749 * @}
2750 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002751
Gregory Szorc34c863a2012-03-21 03:54:29 +00002752/**
2753 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2754 *
2755 * @{
2756 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002757
Chris Lattner25963c62010-01-09 22:27:07 +00002758LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2759 LLVMMemoryBufferRef *OutMemBuf,
2760 char **OutMessage);
2761LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2762 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00002763LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2764 size_t InputDataLength,
2765 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00002766 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00002767LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2768 size_t InputDataLength,
2769 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00002770const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00002771size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002772void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2773
Gregory Szorc34c863a2012-03-21 03:54:29 +00002774/**
2775 * @}
2776 */
2777
2778/**
2779 * @defgroup LLVMCCorePassRegistry Pass Registry
2780 *
2781 * @{
2782 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002783
2784/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002785 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002786LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002787
Gregory Szorc34c863a2012-03-21 03:54:29 +00002788/**
2789 * @}
2790 */
2791
2792/**
2793 * @defgroup LLVMCCorePassManagers Pass Managers
2794 *
2795 * @{
2796 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002797
2798/** Constructs a new whole-module pass pipeline. This type of pipeline is
2799 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002800 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002801LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002802
2803/** Constructs a new function-by-function pass pipeline over the module
2804 provider. It does not take ownership of the module provider. This type of
2805 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002806 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002807LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2808
2809/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002810LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2811
2812/** Initializes, executes on the provided module, and finalizes all of the
2813 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002814 modified the module, 0 otherwise.
2815 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002816LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002817
2818/** Initializes all of the function passes scheduled in the function pass
2819 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002820 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002821LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002822
2823/** Executes all of the function passes scheduled in the function pass manager
2824 on the provided function. Returns 1 if any of the passes modified the
2825 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002826 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002827LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002828
2829/** Finalizes all of the function passes scheduled in in the function pass
2830 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002831 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002832LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002833
2834/** Frees the memory of a pass pipeline. For function pipelines, does not free
2835 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002836 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002837void LLVMDisposePassManager(LLVMPassManagerRef PM);
2838
Gregory Szorc34c863a2012-03-21 03:54:29 +00002839/**
2840 * @}
2841 */
2842
2843/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00002844 * @defgroup LLVMCCoreThreading Threading
2845 *
2846 * Handle the structures needed to make LLVM safe for multithreading.
2847 *
2848 * @{
2849 */
2850
NAKAMURA Takumi104e5f62014-06-24 13:36:31 +00002851/** Allocate and initialize structures needed to make LLVM safe for
2852 multithreading. The return value indicates whether multithreaded
2853 initialization succeeded. Must be executed in isolation from all
2854 other LLVM api calls.
2855 @see llvm::llvm_start_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002856LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002857
NAKAMURA Takumi104e5f62014-06-24 13:36:31 +00002858/** Deallocate structures necessary to make LLVM safe for multithreading.
2859 Must be executed in isolation from all other LLVM api calls.
2860 @see llvm::llvm_stop_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002861void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002862
2863/** Check whether LLVM is executing in thread-safe mode or not.
2864 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002865LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002866
2867/**
2868 * @}
2869 */
2870
2871/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002872 * @}
2873 */
2874
2875/**
2876 * @}
2877 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002878
Gordon Henriksen76a03742007-09-18 03:18:57 +00002879#ifdef __cplusplus
2880}
Evan Cheng2e254d02013-04-04 17:40:53 +00002881#endif /* !defined(__cplusplus) */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002882
Evan Cheng2e254d02013-04-04 17:40:53 +00002883#endif /* !defined(LLVM_C_CORE_H) */