blob: df2de2441a24f51a4436a2b3abbf7a7da337a499 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000013\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_C_CORE_H
16#define LLVM_C_CORE_H
17
Chandler Carruth3c57aa42014-03-06 04:13:12 +000018#include "llvm-c/Support.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000019
Evan Cheng2e254d02013-04-04 17:40:53 +000020#ifdef __cplusplus
Gordon Henriksen76a03742007-09-18 03:18:57 +000021extern "C" {
22#endif
23
Gregory Szorc34c863a2012-03-21 03:54:29 +000024/**
25 * @defgroup LLVMC LLVM-C: C interface to LLVM
26 *
27 * This module exposes parts of the LLVM library as a C API.
28 *
29 * @{
30 */
31
32/**
33 * @defgroup LLVMCTransforms Transforms
34 */
35
36/**
37 * @defgroup LLVMCCore Core
38 *
39 * This modules provide an interface to libLLVMCore, which implements
40 * the LLVM intermediate representation as well as other related types
41 * and utilities.
42 *
43 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
44 * parameters must be passed as base types. Despite the declared types, most
45 * of the functions provided operate only on branches of the type hierarchy.
46 * The declared parameter names are descriptive and specify which type is
47 * required. Additionally, each type hierarchy is documented along with the
48 * functions that operate upon it. For more detail, refer to LLVM's C++ code.
Eli Bendersky870d0572012-08-10 18:26:20 +000049 * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
Gregory Szorc34c863a2012-03-21 03:54:29 +000050 * form unwrap<RequiredType>(Param).
51 *
52 * Many exotic languages can interoperate with C code but have a harder time
53 * with C++ due to name mangling. So in addition to C, this interface enables
54 * tools written in such languages.
55 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000056 * @{
57 */
58
59/**
60 * @defgroup LLVMCCoreTypes Types and Enumerations
61 *
62 * @{
63 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000064
65/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000066
67/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000068 * The top-level container for all LLVM global data. See the LLVMContext class.
Owen Anderson6773d382009-07-01 16:58:40 +000069 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000070typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000071
72/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000073 * The top-level container for all other LLVM Intermediate Representation (IR)
Gregory Szorc34c863a2012-03-21 03:54:29 +000074 * objects.
75 *
76 * @see llvm::Module
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000077 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000078typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000079
80/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000081 * Each value in the LLVM IR has a type, an LLVMTypeRef.
82 *
83 * @see llvm::Type
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000084 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000085typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000086
Gregory Szorc34c863a2012-03-21 03:54:29 +000087/**
88 * Represents an individual value in LLVM IR.
89 *
90 * This models llvm::Value.
91 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000092typedef struct LLVMOpaqueValue *LLVMValueRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +000093
94/**
Eli Bendersky870d0572012-08-10 18:26:20 +000095 * Represents a basic block of instructions in LLVM IR.
Gregory Szorc34c863a2012-03-21 03:54:29 +000096 *
97 * This models llvm::BasicBlock.
98 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000099typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +0000100
101/**
102 * Represents an LLVM basic block builder.
103 *
104 * This models llvm::IRBuilder.
105 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000106typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000107
Gregory Szorc34c863a2012-03-21 03:54:29 +0000108/**
109 * Interface used to provide a module to JIT or interpreter.
110 * This is now just a synonym for llvm::Module, but we have to keep using the
111 * different type to keep binary compatibility.
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000112 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000113typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +0000114
Gregory Szorc34c863a2012-03-21 03:54:29 +0000115/** @see llvm::PassManagerBase */
Gordon Henriksen878114b2008-03-16 04:20:44 +0000116typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
117
Gregory Szorc34c863a2012-03-21 03:54:29 +0000118/** @see llvm::PassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +0000119typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
120
Gregory Szorc34c863a2012-03-21 03:54:29 +0000121/**
122 * Used to get the users and usees of a Value.
123 *
124 * @see llvm::Use */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +0000125typedef struct LLVMOpaqueUse *LLVMUseRef;
Chris Lattner40cf28d2009-10-12 04:01:02 +0000126
Tom Stellard1580dc72014-04-16 17:45:04 +0000127
128/**
129 * @see llvm::DiagnosticInfo
130 */
131typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
132
Gordon Henriksen76a03742007-09-18 03:18:57 +0000133typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +0000134 LLVMZExtAttribute = 1<<0,
135 LLVMSExtAttribute = 1<<1,
136 LLVMNoReturnAttribute = 1<<2,
137 LLVMInRegAttribute = 1<<3,
138 LLVMStructRetAttribute = 1<<4,
139 LLVMNoUnwindAttribute = 1<<5,
140 LLVMNoAliasAttribute = 1<<6,
141 LLVMByValAttribute = 1<<7,
142 LLVMNestAttribute = 1<<8,
143 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000144 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000145 LLVMNoInlineAttribute = 1<<11,
146 LLVMAlwaysInlineAttribute = 1<<12,
147 LLVMOptimizeForSizeAttribute = 1<<13,
148 LLVMStackProtectAttribute = 1<<14,
149 LLVMStackProtectReqAttribute = 1<<15,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000150 LLVMAlignment = 31<<16,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000151 LLVMNoCaptureAttribute = 1<<21,
152 LLVMNoRedZoneAttribute = 1<<22,
153 LLVMNoImplicitFloatAttribute = 1<<23,
Jakob Stoklund Olesen74bb06c2010-02-06 01:16:28 +0000154 LLVMNakedAttribute = 1<<24,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000155 LLVMInlineHintAttribute = 1<<25,
Torok Edwin1db48c02011-10-06 12:13:32 +0000156 LLVMStackAlignment = 7<<26,
157 LLVMReturnsTwice = 1 << 29,
158 LLVMUWTable = 1 << 30,
Chandler Carruth44d69d92012-01-25 07:40:15 +0000159 LLVMNonLazyBind = 1 << 31
160
Bill Wendlingd154e2832013-01-23 06:41:41 +0000161 /* FIXME: These attributes are currently not included in the C API as
Nuno Lopesdef4229972012-09-02 14:19:21 +0000162 a temporary measure until the API/ABI impact to the C API is understood
163 and the path forward agreed upon.
Bill Wendlingd154e2832013-01-23 06:41:41 +0000164 LLVMAddressSafety = 1ULL << 32,
Andrea Di Biagio377496b2013-08-23 11:53:55 +0000165 LLVMStackProtectStrongAttribute = 1ULL<<33,
166 LLVMCold = 1ULL << 34,
Reid Klecknera534a382013-12-19 02:14:12 +0000167 LLVMOptimizeNone = 1ULL << 35,
168 LLVMInAllocaAttribute = 1ULL << 36
Nuno Lopesdef4229972012-09-02 14:19:21 +0000169 */
Devang Patel4c758ea2008-09-25 21:00:45 +0000170} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000171
172typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000173 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000174 LLVMRet = 1,
175 LLVMBr = 2,
176 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000177 LLVMIndirectBr = 4,
178 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000179 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000180 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000181
Bill Wendlingda52cec2010-02-15 20:53:17 +0000182 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000183 LLVMAdd = 8,
184 LLVMFAdd = 9,
185 LLVMSub = 10,
186 LLVMFSub = 11,
187 LLVMMul = 12,
188 LLVMFMul = 13,
189 LLVMUDiv = 14,
190 LLVMSDiv = 15,
191 LLVMFDiv = 16,
192 LLVMURem = 17,
193 LLVMSRem = 18,
194 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000195
Bill Wendlingda52cec2010-02-15 20:53:17 +0000196 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000197 LLVMShl = 20,
198 LLVMLShr = 21,
199 LLVMAShr = 22,
200 LLVMAnd = 23,
201 LLVMOr = 24,
202 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000203
Bill Wendlingda52cec2010-02-15 20:53:17 +0000204 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000205 LLVMAlloca = 26,
206 LLVMLoad = 27,
207 LLVMStore = 28,
208 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000209
Bill Wendlingda52cec2010-02-15 20:53:17 +0000210 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000211 LLVMTrunc = 30,
212 LLVMZExt = 31,
213 LLVMSExt = 32,
214 LLVMFPToUI = 33,
215 LLVMFPToSI = 34,
216 LLVMUIToFP = 35,
217 LLVMSIToFP = 36,
218 LLVMFPTrunc = 37,
219 LLVMFPExt = 38,
220 LLVMPtrToInt = 39,
221 LLVMIntToPtr = 40,
222 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000223 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000224
Bill Wendlingda52cec2010-02-15 20:53:17 +0000225 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000226 LLVMICmp = 42,
227 LLVMFCmp = 43,
228 LLVMPHI = 44,
229 LLVMCall = 45,
230 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000231 LLVMUserOp1 = 47,
232 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000233 LLVMVAArg = 49,
234 LLVMExtractElement = 50,
235 LLVMInsertElement = 51,
236 LLVMShuffleVector = 52,
237 LLVMExtractValue = 53,
238 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000239
240 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000241 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000242 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000243 LLVMAtomicRMW = 57,
244
245 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000246 LLVMResume = 58,
Bill Wendling0aef16a2012-02-06 21:44:22 +0000247 LLVMLandingPad = 59
Bill Wendling2641d132011-07-27 21:00:28 +0000248
Chris Lattner40cf28d2009-10-12 04:01:02 +0000249} LLVMOpcode;
250
251typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000252 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000253 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000254 LLVMFloatTypeKind, /**< 32 bit floating point type */
255 LLVMDoubleTypeKind, /**< 64 bit floating point type */
256 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
257 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
258 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
259 LLVMLabelTypeKind, /**< Labels */
260 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
261 LLVMFunctionTypeKind, /**< Functions */
262 LLVMStructTypeKind, /**< Structures */
263 LLVMArrayTypeKind, /**< Arrays */
264 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000265 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000266 LLVMMetadataTypeKind, /**< Metadata */
267 LLVMX86_MMXTypeKind /**< X86 MMX */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000268} LLVMTypeKind;
269
270typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000271 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000272 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000273 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
274 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
275 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000276 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000277 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
278 LLVMWeakODRLinkage, /**< Same, but only replaced by something
279 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000280 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
281 LLVMInternalLinkage, /**< Rename collisions when linking (static
282 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000283 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000284 LLVMDLLImportLinkage, /**< Obsolete */
285 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000286 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000287 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000288 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000289 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000290 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000291} LLVMLinkage;
292
293typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000294 LLVMDefaultVisibility, /**< The GV is visible */
295 LLVMHiddenVisibility, /**< The GV is hidden */
296 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000297} LLVMVisibility;
298
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000299typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000300 LLVMDefaultStorageClass = 0,
301 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
302 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
303} LLVMDLLStorageClass;
304
305typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000306 LLVMCCallConv = 0,
307 LLVMFastCallConv = 8,
308 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000309 LLVMWebKitJSCallConv = 12,
310 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000311 LLVMX86StdcallCallConv = 64,
312 LLVMX86FastcallCallConv = 65
313} LLVMCallConv;
314
315typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000316 LLVMIntEQ = 32, /**< equal */
317 LLVMIntNE, /**< not equal */
318 LLVMIntUGT, /**< unsigned greater than */
319 LLVMIntUGE, /**< unsigned greater or equal */
320 LLVMIntULT, /**< unsigned less than */
321 LLVMIntULE, /**< unsigned less or equal */
322 LLVMIntSGT, /**< signed greater than */
323 LLVMIntSGE, /**< signed greater or equal */
324 LLVMIntSLT, /**< signed less than */
325 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000326} LLVMIntPredicate;
327
328typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000329 LLVMRealPredicateFalse, /**< Always false (always folded) */
330 LLVMRealOEQ, /**< True if ordered and equal */
331 LLVMRealOGT, /**< True if ordered and greater than */
332 LLVMRealOGE, /**< True if ordered and greater than or equal */
333 LLVMRealOLT, /**< True if ordered and less than */
334 LLVMRealOLE, /**< True if ordered and less than or equal */
335 LLVMRealONE, /**< True if ordered and operands are unequal */
336 LLVMRealORD, /**< True if ordered (no nans) */
337 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
338 LLVMRealUEQ, /**< True if unordered or equal */
339 LLVMRealUGT, /**< True if unordered or greater than */
340 LLVMRealUGE, /**< True if unordered, greater than, or equal */
341 LLVMRealULT, /**< True if unordered or less than */
342 LLVMRealULE, /**< True if unordered, less than, or equal */
343 LLVMRealUNE, /**< True if unordered or not equal */
344 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000345} LLVMRealPredicate;
346
Bill Wendlingfae14752011-08-12 20:24:12 +0000347typedef enum {
348 LLVMLandingPadCatch, /**< A catch clause */
349 LLVMLandingPadFilter /**< A filter clause */
350} LLVMLandingPadClauseTy;
351
Hans Wennborg5ff71202013-04-16 08:58:59 +0000352typedef enum {
353 LLVMNotThreadLocal = 0,
354 LLVMGeneralDynamicTLSModel,
355 LLVMLocalDynamicTLSModel,
356 LLVMInitialExecTLSModel,
357 LLVMLocalExecTLSModel
358} LLVMThreadLocalMode;
359
Carlo Kokda0ac722013-04-23 13:45:37 +0000360typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000361 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
362 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
363 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000364 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
365 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000366 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000367 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
368 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000369 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000370 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
371 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000372 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000373 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
374 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000375 operations which both read and write
376 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000377 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
378 for loads and Release
379 semantics for stores.
380 Additionally, it guarantees
381 that a total ordering exists
382 between all
383 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000384 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000385} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000386
Carlo Kokda0ac722013-04-23 13:45:37 +0000387typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000388 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
389 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
390 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
391 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
392 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
393 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
394 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
395 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000396 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000397 the old one */
398 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000399 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000400 the old one */
401 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000402 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000403 the old one */
404 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000405 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000406 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000407} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000408
Tom Stellard1580dc72014-04-16 17:45:04 +0000409typedef enum {
410 LLVMDSError,
411 LLVMDSWarning,
412 LLVMDSRemark,
413 LLVMDSNote
414} LLVMDiagnosticSeverity;
415
Gregory Szorc34c863a2012-03-21 03:54:29 +0000416/**
417 * @}
418 */
419
Nick Lewycky0db26542011-05-15 07:20:34 +0000420void LLVMInitializeCore(LLVMPassRegistryRef R);
421
Duncan Sands1cba0a82013-02-17 16:35:51 +0000422/** Deallocate and destroy all ManagedStatic variables.
423 @see llvm::llvm_shutdown
424 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000425void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000426
Gordon Henriksen76a03742007-09-18 03:18:57 +0000427
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000428/*===-- Error handling ----------------------------------------------------===*/
429
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000430char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000431void LLVMDisposeMessage(char *Message);
432
Filip Pizloa535b142013-10-17 01:38:28 +0000433typedef void (*LLVMFatalErrorHandler)(const char *Reason);
434
435/**
436 * Install a fatal error handler. By default, if LLVM detects a fatal error, it
437 * will call exit(1). This may not be appropriate in many contexts. For example,
438 * doing exit(1) will bypass many crash reporting/tracing system tools. This
439 * function allows you to install a callback that will be invoked prior to the
440 * call to exit(1).
441 */
442void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
443
444/**
445 * Reset the fatal error handler. This resets LLVM's fatal error handling
446 * behavior to the default.
447 */
448void LLVMResetFatalErrorHandler(void);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000449
Gregory Szorc34c863a2012-03-21 03:54:29 +0000450/**
Filip Pizloc10ca902013-11-04 02:22:25 +0000451 * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
452 * signals and prints which component of LLVM you were in at the time if the
453 * crash.
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000454 */
Filip Pizloc10ca902013-11-04 02:22:25 +0000455void LLVMEnablePrettyStackTrace(void);
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000456
457/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000458 * @defgroup LLVMCCoreContext Contexts
459 *
460 * Contexts are execution states for the core LLVM IR system.
461 *
462 * Most types are tied to a context instance. Multiple contexts can
463 * exist simultaneously. A single context is not thread safe. However,
464 * different contexts can execute on different threads simultaneously.
465 *
466 * @{
467 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000468
Tom Stellard1580dc72014-04-16 17:45:04 +0000469typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
470
Gregory Szorc34c863a2012-03-21 03:54:29 +0000471/**
472 * Create a new context.
473 *
474 * Every call to this function should be paired with a call to
475 * LLVMContextDispose() or the context will leak memory.
476 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000477LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000478
479/**
480 * Obtain the global context instance.
481 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000482LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000483
484/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000485 * Set the diagnostic handler for this context.
486 */
487void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
488 LLVMDiagnosticHandler Handler,
489 void *DiagnosticContext);
490
491/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000492 * Destroy a context instance.
493 *
494 * This should be called for every call to LLVMContextCreate() or memory
495 * will be leaked.
496 */
Owen Anderson6773d382009-07-01 16:58:40 +0000497void LLVMContextDispose(LLVMContextRef C);
498
Tom Stellard1580dc72014-04-16 17:45:04 +0000499/**
500 * Return a string representation of the DiagnosticInfo. Use
501 * LLVMDisposeMessage to free the string.
502 *
503 * @see DiagnosticInfo::print()
504 */
505char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
506
507/**
508 * Return an enum LLVMDiagnosticSeverity.
509 *
510 * @see DiagnosticInfo::getSeverity()
511 */
512LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
513
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000514unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
515 unsigned SLen);
516unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
517
Gregory Szorc34c863a2012-03-21 03:54:29 +0000518/**
519 * @}
520 */
521
Gregory Szorc52d26602012-03-21 07:28:27 +0000522/**
523 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000524 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000525 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000526 * module is effectively a translation unit or a collection of
527 * translation units merged together.
528 *
529 * @{
530 */
531
Gregory Szorc34c863a2012-03-21 03:54:29 +0000532/**
533 * Create a new, empty module in the global context.
534 *
535 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
536 * LLVMGetGlobalContext() as the context parameter.
537 *
538 * Every invocation should be paired with LLVMDisposeModule() or memory
539 * will be leaked.
540 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000541LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000542
543/**
544 * Create a new, empty module in a specific context.
545 *
546 * Every invocation should be paired with LLVMDisposeModule() or memory
547 * will be leaked.
548 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000549LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
550 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000551
Gregory Szorc34c863a2012-03-21 03:54:29 +0000552/**
553 * Destroy a module instance.
554 *
555 * This must be called for every created module or memory will be
556 * leaked.
557 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000558void LLVMDisposeModule(LLVMModuleRef M);
559
Gregory Szorc34c863a2012-03-21 03:54:29 +0000560/**
561 * Obtain the data layout for a module.
562 *
563 * @see Module::getDataLayout()
564 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000565const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000566
567/**
568 * Set the data layout for a module.
569 *
570 * @see Module::setDataLayout()
571 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000572void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
573
Gregory Szorc34c863a2012-03-21 03:54:29 +0000574/**
575 * Obtain the target triple for a module.
576 *
577 * @see Module::getTargetTriple()
578 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000579const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000580
581/**
582 * Set the target triple for a module.
583 *
584 * @see Module::setTargetTriple()
585 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000586void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
587
Gregory Szorc34c863a2012-03-21 03:54:29 +0000588/**
589 * Dump a representation of a module to stderr.
590 *
591 * @see Module::dump()
592 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000593void LLVMDumpModule(LLVMModuleRef M);
594
Gregory Szorc34c863a2012-03-21 03:54:29 +0000595/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000596 * Print a representation of a module to a file. The ErrorMessage needs to be
597 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
598 *
599 * @see Module::print()
600 */
601LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
602 char **ErrorMessage);
603
604/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000605 * Return a string representation of the module. Use
606 * LLVMDisposeMessage to free the string.
607 *
608 * @see Module::print()
609 */
610char *LLVMPrintModuleToString(LLVMModuleRef M);
611
612/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000613 * Set inline assembly for a module.
614 *
615 * @see Module::setModuleInlineAsm()
616 */
Chris Lattner26941452010-04-10 17:52:58 +0000617void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000618
Gregory Szorc34c863a2012-03-21 03:54:29 +0000619/**
620 * Obtain the context to which this module is associated.
621 *
622 * @see Module::getContext()
623 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000624LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
625
Gregory Szorc34c863a2012-03-21 03:54:29 +0000626/**
627 * Obtain a Type from a module by its registered name.
628 */
629LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000630
Gregory Szorc34c863a2012-03-21 03:54:29 +0000631/**
632 * Obtain the number of operands for named metadata in a module.
633 *
634 * @see llvm::Module::getNamedMetadata()
635 */
636unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
637
638/**
639 * Obtain the named metadata operands for a module.
640 *
641 * The passed LLVMValueRef pointer should refer to an array of
642 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
643 * array will be populated with the LLVMValueRef instances. Each
644 * instance corresponds to a llvm::MDNode.
645 *
646 * @see llvm::Module::getNamedMetadata()
647 * @see llvm::MDNode::getOperand()
648 */
649void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
650
651/**
652 * Add an operand to named metadata.
653 *
654 * @see llvm::Module::getNamedMetadata()
655 * @see llvm::MDNode::addOperand()
656 */
657void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
658 LLVMValueRef Val);
659
Gregory Szorc52d26602012-03-21 07:28:27 +0000660/**
661 * Add a function to a module under a specified name.
662 *
663 * @see llvm::Function::Create()
664 */
665LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
666 LLVMTypeRef FunctionTy);
667
668/**
669 * Obtain a Function value from a Module by its name.
670 *
671 * The returned value corresponds to a llvm::Function value.
672 *
673 * @see llvm::Module::getFunction()
674 */
675LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
676
677/**
678 * Obtain an iterator to the first Function in a Module.
679 *
680 * @see llvm::Module::begin()
681 */
682LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
683
684/**
685 * Obtain an iterator to the last Function in a Module.
686 *
687 * @see llvm::Module::end()
688 */
689LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
690
691/**
692 * Advance a Function iterator to the next Function.
693 *
694 * Returns NULL if the iterator was already at the end and there are no more
695 * functions.
696 */
697LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
698
699/**
700 * Decrement a Function iterator to the previous Function.
701 *
702 * Returns NULL if the iterator was already at the beginning and there are
703 * no previous functions.
704 */
705LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000706
707/**
708 * @}
709 */
710
711/**
712 * @defgroup LLVMCCoreType Types
713 *
714 * Types represent the type of a value.
715 *
716 * Types are associated with a context instance. The context internally
717 * deduplicates types so there is only 1 instance of a specific type
718 * alive at a time. In other words, a unique type is shared among all
719 * consumers within a context.
720 *
721 * A Type in the C API corresponds to llvm::Type.
722 *
723 * Types have the following hierarchy:
724 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000725 * types:
726 * integer type
727 * real type
728 * function type
729 * sequence types:
730 * array type
731 * pointer type
732 * vector type
733 * void type
734 * label type
735 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000736 *
737 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000738 */
739
Gregory Szorc34c863a2012-03-21 03:54:29 +0000740/**
741 * Obtain the enumerated type of a Type instance.
742 *
743 * @see llvm::Type:getTypeID()
744 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000745LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000746
747/**
748 * Whether the type has a known size.
749 *
750 * Things that don't have a size are abstract types, labels, and void.a
751 *
752 * @see llvm::Type::isSized()
753 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000754LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000755
Gregory Szorc34c863a2012-03-21 03:54:29 +0000756/**
757 * Obtain the context to which this type instance is associated.
758 *
759 * @see llvm::Type::getContext()
760 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000761LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
762
Gregory Szorc34c863a2012-03-21 03:54:29 +0000763/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000764 * Dump a representation of a type to stderr.
765 *
766 * @see llvm::Type::dump()
767 */
768void LLVMDumpType(LLVMTypeRef Val);
769
770/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000771 * Return a string representation of the type. Use
772 * LLVMDisposeMessage to free the string.
773 *
774 * @see llvm::Type::print()
775 */
776char *LLVMPrintTypeToString(LLVMTypeRef Val);
777
778/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000779 * @defgroup LLVMCCoreTypeInt Integer Types
780 *
781 * Functions in this section operate on integer types.
782 *
783 * @{
784 */
785
786/**
787 * Obtain an integer type from a context with specified bit width.
788 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000789LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
790LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
791LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
792LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
793LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
794LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
795
Gregory Szorc34c863a2012-03-21 03:54:29 +0000796/**
797 * Obtain an integer type from the global context with a specified bit
798 * width.
799 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000800LLVMTypeRef LLVMInt1Type(void);
801LLVMTypeRef LLVMInt8Type(void);
802LLVMTypeRef LLVMInt16Type(void);
803LLVMTypeRef LLVMInt32Type(void);
804LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000805LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000806unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000807
Gregory Szorc34c863a2012-03-21 03:54:29 +0000808/**
809 * @}
810 */
811
812/**
813 * @defgroup LLVMCCoreTypeFloat Floating Point Types
814 *
815 * @{
816 */
817
818/**
819 * Obtain a 16-bit floating point type from a context.
820 */
Dan Gohman518cda42011-12-17 00:04:22 +0000821LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000822
823/**
824 * Obtain a 32-bit floating point type from a context.
825 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000826LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000827
828/**
829 * Obtain a 64-bit floating point type from a context.
830 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000831LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000832
833/**
834 * Obtain a 80-bit floating point type (X87) from a context.
835 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000836LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000837
838/**
839 * Obtain a 128-bit floating point type (112-bit mantissa) from a
840 * context.
841 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000842LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000843
844/**
845 * Obtain a 128-bit floating point type (two 64-bits) from a context.
846 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000847LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
848
Gregory Szorc34c863a2012-03-21 03:54:29 +0000849/**
850 * Obtain a floating point type from the global context.
851 *
852 * These map to the functions in this group of the same name.
853 */
Dan Gohman518cda42011-12-17 00:04:22 +0000854LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000855LLVMTypeRef LLVMFloatType(void);
856LLVMTypeRef LLVMDoubleType(void);
857LLVMTypeRef LLVMX86FP80Type(void);
858LLVMTypeRef LLVMFP128Type(void);
859LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000860
Gregory Szorc34c863a2012-03-21 03:54:29 +0000861/**
862 * @}
863 */
864
865/**
866 * @defgroup LLVMCCoreTypeFunction Function Types
867 *
868 * @{
869 */
870
871/**
872 * Obtain a function type consisting of a specified signature.
873 *
874 * The function is defined as a tuple of a return Type, a list of
875 * parameter types, and whether the function is variadic.
876 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000877LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
878 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000879 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000880
881/**
882 * Returns whether a function type is variadic.
883 */
Chris Lattner25963c62010-01-09 22:27:07 +0000884LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000885
886/**
887 * Obtain the Type this function Type returns.
888 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000889LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000890
891/**
892 * Obtain the number of parameters this function accepts.
893 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000894unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000895
896/**
897 * Obtain the types of a function's parameters.
898 *
899 * The Dest parameter should point to a pre-allocated array of
900 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
901 * first LLVMCountParamTypes() entries in the array will be populated
902 * with LLVMTypeRef instances.
903 *
904 * @param FunctionTy The function type to operate on.
905 * @param Dest Memory address of an array to be filled with result.
906 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000907void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000908
Gregory Szorc34c863a2012-03-21 03:54:29 +0000909/**
910 * @}
911 */
912
913/**
914 * @defgroup LLVMCCoreTypeStruct Structure Types
915 *
916 * These functions relate to LLVMTypeRef instances.
917 *
918 * @see llvm::StructType
919 *
920 * @{
921 */
922
923/**
924 * Create a new structure type in a context.
925 *
926 * A structure is specified by a list of inner elements/types and
927 * whether these can be packed together.
928 *
929 * @see llvm::StructType::create()
930 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000931LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000932 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000933
934/**
935 * Create a new structure type in the global context.
936 *
937 * @see llvm::StructType::create()
938 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000939LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000940 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000941
942/**
943 * Create an empty structure in a context having a specified name.
944 *
945 * @see llvm::StructType::create()
946 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000947LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000948
949/**
950 * Obtain the name of a structure.
951 *
952 * @see llvm::StructType::getName()
953 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000954const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000955
956/**
957 * Set the contents of a structure type.
958 *
959 * @see llvm::StructType::setBody()
960 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000961void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
962 unsigned ElementCount, LLVMBool Packed);
963
Gregory Szorc34c863a2012-03-21 03:54:29 +0000964/**
965 * Get the number of elements defined inside the structure.
966 *
967 * @see llvm::StructType::getNumElements()
968 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000969unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000970
971/**
972 * Get the elements within a structure.
973 *
974 * The function is passed the address of a pre-allocated array of
975 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
976 * invocation, this array will be populated with the structure's
977 * elements. The objects in the destination array will have a lifetime
978 * of the structure type itself, which is the lifetime of the context it
979 * is contained in.
980 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000981void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000982
983/**
984 * Determine whether a structure is packed.
985 *
986 * @see llvm::StructType::isPacked()
987 */
Chris Lattner25963c62010-01-09 22:27:07 +0000988LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000989
990/**
991 * Determine whether a structure is opaque.
992 *
993 * @see llvm::StructType::isOpaque()
994 */
Chris Lattner17cf05b2011-07-14 16:20:28 +0000995LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
996
Gregory Szorc34c863a2012-03-21 03:54:29 +0000997/**
998 * @}
999 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001000
Gregory Szorc34c863a2012-03-21 03:54:29 +00001001
1002/**
1003 * @defgroup LLVMCCoreTypeSequential Sequential Types
1004 *
1005 * Sequential types represents "arrays" of types. This is a super class
1006 * for array, vector, and pointer types.
1007 *
1008 * @{
1009 */
1010
1011/**
1012 * Obtain the type of elements within a sequential type.
1013 *
1014 * This works on array, vector, and pointer types.
1015 *
1016 * @see llvm::SequentialType::getElementType()
1017 */
1018LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1019
1020/**
1021 * Create a fixed size array type that refers to a specific type.
1022 *
1023 * The created type will exist in the context that its element type
1024 * exists in.
1025 *
1026 * @see llvm::ArrayType::get()
1027 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001028LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001029
1030/**
1031 * Obtain the length of an array type.
1032 *
1033 * This only works on types that represent arrays.
1034 *
1035 * @see llvm::ArrayType::getNumElements()
1036 */
1037unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1038
1039/**
1040 * Create a pointer type that points to a defined type.
1041 *
1042 * The created type will exist in the context that its pointee type
1043 * exists in.
1044 *
1045 * @see llvm::PointerType::get()
1046 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001047LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001048
1049/**
1050 * Obtain the address space of a pointer type.
1051 *
1052 * This only works on types that represent pointers.
1053 *
1054 * @see llvm::PointerType::getAddressSpace()
1055 */
1056unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1057
1058/**
1059 * Create a vector type that contains a defined type and has a specific
1060 * number of elements.
1061 *
1062 * The created type will exist in the context thats its element type
1063 * exists in.
1064 *
1065 * @see llvm::VectorType::get()
1066 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001067LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001068
Gregory Szorc34c863a2012-03-21 03:54:29 +00001069/**
1070 * Obtain the number of elements in a vector type.
1071 *
1072 * This only works on types that represent vectors.
1073 *
1074 * @see llvm::VectorType::getNumElements()
1075 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001076unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1077
Gregory Szorc34c863a2012-03-21 03:54:29 +00001078/**
1079 * @}
1080 */
1081
1082/**
1083 * @defgroup LLVMCCoreTypeOther Other Types
1084 *
1085 * @{
1086 */
1087
1088/**
1089 * Create a void type in a context.
1090 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001091LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001092
1093/**
1094 * Create a label type in a context.
1095 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001096LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001097
1098/**
1099 * Create a X86 MMX type in a context.
1100 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001101LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001102
Gregory Szorc34c863a2012-03-21 03:54:29 +00001103/**
1104 * These are similar to the above functions except they operate on the
1105 * global context.
1106 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001107LLVMTypeRef LLVMVoidType(void);
1108LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001109LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001110
Gregory Szorc34c863a2012-03-21 03:54:29 +00001111/**
1112 * @}
1113 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001114
Gregory Szorc34c863a2012-03-21 03:54:29 +00001115/**
1116 * @}
1117 */
1118
1119/**
1120 * @defgroup LLVMCCoreValues Values
1121 *
1122 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001123 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001124 *
1125 * LLVMValueRef essentially represents llvm::Value. There is a rich
1126 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001127 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001128 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001129 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001130 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1131 * functions are defined by a macro, so it isn't obvious which are
1132 * available by looking at the Doxygen source code. Instead, look at the
1133 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1134 * of value names given. These value names also correspond to classes in
1135 * the llvm::Value hierarchy.
1136 *
1137 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001138 */
1139
Gordon Henriksen29e38942008-12-19 18:39:45 +00001140#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1141 macro(Argument) \
1142 macro(BasicBlock) \
1143 macro(InlineAsm) \
Torok Edwind09b7572011-10-14 20:37:56 +00001144 macro(MDNode) \
1145 macro(MDString) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001146 macro(User) \
1147 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001148 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001149 macro(ConstantAggregateZero) \
1150 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001151 macro(ConstantDataSequential) \
1152 macro(ConstantDataArray) \
1153 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001154 macro(ConstantExpr) \
1155 macro(ConstantFP) \
1156 macro(ConstantInt) \
1157 macro(ConstantPointerNull) \
1158 macro(ConstantStruct) \
1159 macro(ConstantVector) \
1160 macro(GlobalValue) \
1161 macro(Function) \
1162 macro(GlobalAlias) \
1163 macro(GlobalVariable) \
1164 macro(UndefValue) \
1165 macro(Instruction) \
1166 macro(BinaryOperator) \
1167 macro(CallInst) \
1168 macro(IntrinsicInst) \
1169 macro(DbgInfoIntrinsic) \
1170 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001171 macro(MemIntrinsic) \
1172 macro(MemCpyInst) \
1173 macro(MemMoveInst) \
1174 macro(MemSetInst) \
1175 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001176 macro(FCmpInst) \
1177 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001178 macro(ExtractElementInst) \
1179 macro(GetElementPtrInst) \
1180 macro(InsertElementInst) \
1181 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001182 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001183 macro(PHINode) \
1184 macro(SelectInst) \
1185 macro(ShuffleVectorInst) \
1186 macro(StoreInst) \
1187 macro(TerminatorInst) \
1188 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001189 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001190 macro(InvokeInst) \
1191 macro(ReturnInst) \
1192 macro(SwitchInst) \
1193 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001194 macro(ResumeInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001195 macro(UnaryInstruction) \
1196 macro(AllocaInst) \
1197 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001198 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001199 macro(BitCastInst) \
1200 macro(FPExtInst) \
1201 macro(FPToSIInst) \
1202 macro(FPToUIInst) \
1203 macro(FPTruncInst) \
1204 macro(IntToPtrInst) \
1205 macro(PtrToIntInst) \
1206 macro(SExtInst) \
1207 macro(SIToFPInst) \
1208 macro(TruncInst) \
1209 macro(UIToFPInst) \
1210 macro(ZExtInst) \
1211 macro(ExtractValueInst) \
1212 macro(LoadInst) \
1213 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001214
Gregory Szorc34c863a2012-03-21 03:54:29 +00001215/**
1216 * @defgroup LLVMCCoreValueGeneral General APIs
1217 *
1218 * Functions in this section work on all LLVMValueRef instances,
1219 * regardless of their sub-type. They correspond to functions available
1220 * on llvm::Value.
1221 *
1222 * @{
1223 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001224
Gregory Szorc34c863a2012-03-21 03:54:29 +00001225/**
1226 * Obtain the type of a value.
1227 *
1228 * @see llvm::Value::getType()
1229 */
1230LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1231
1232/**
1233 * Obtain the string name of a value.
1234 *
1235 * @see llvm::Value::getName()
1236 */
1237const char *LLVMGetValueName(LLVMValueRef Val);
1238
1239/**
1240 * Set the string name of a value.
1241 *
1242 * @see llvm::Value::setName()
1243 */
1244void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1245
1246/**
1247 * Dump a representation of a value to stderr.
1248 *
1249 * @see llvm::Value::dump()
1250 */
1251void LLVMDumpValue(LLVMValueRef Val);
1252
1253/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001254 * Return a string representation of the value. Use
1255 * LLVMDisposeMessage to free the string.
1256 *
1257 * @see llvm::Value::print()
1258 */
1259char *LLVMPrintValueToString(LLVMValueRef Val);
1260
1261/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001262 * Replace all uses of a value with another one.
1263 *
1264 * @see llvm::Value::replaceAllUsesWith()
1265 */
1266void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1267
1268/**
1269 * Determine whether the specified constant instance is constant.
1270 */
1271LLVMBool LLVMIsConstant(LLVMValueRef Val);
1272
1273/**
1274 * Determine whether a value instance is undefined.
1275 */
1276LLVMBool LLVMIsUndef(LLVMValueRef Val);
1277
1278/**
1279 * Convert value instances between types.
1280 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001281 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001282 * series of functions allows you to cast an instance to a specific
1283 * type.
1284 *
1285 * If the cast is not valid for the specified type, NULL is returned.
1286 *
1287 * @see llvm::dyn_cast_or_null<>
1288 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001289#define LLVM_DECLARE_VALUE_CAST(name) \
1290 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1291LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1292
Gregory Szorc34c863a2012-03-21 03:54:29 +00001293/**
1294 * @}
1295 */
1296
1297/**
1298 * @defgroup LLVMCCoreValueUses Usage
1299 *
1300 * This module defines functions that allow you to inspect the uses of a
1301 * LLVMValueRef.
1302 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001303 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001304 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1305 * llvm::User and llvm::Value.
1306 *
1307 * @{
1308 */
1309
1310/**
1311 * Obtain the first use of a value.
1312 *
1313 * Uses are obtained in an iterator fashion. First, call this function
1314 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001315 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001316 * LLVMGetNextUse() returns NULL.
1317 *
1318 * @see llvm::Value::use_begin()
1319 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001320LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001321
1322/**
1323 * Obtain the next use of a value.
1324 *
1325 * This effectively advances the iterator. It returns NULL if you are on
1326 * the final use and no more are available.
1327 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001328LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001329
1330/**
1331 * Obtain the user value for a user.
1332 *
1333 * The returned value corresponds to a llvm::User type.
1334 *
1335 * @see llvm::Use::getUser()
1336 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001337LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001338
1339/**
1340 * Obtain the value this use corresponds to.
1341 *
1342 * @see llvm::Use::get().
1343 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001344LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001345
Gregory Szorc34c863a2012-03-21 03:54:29 +00001346/**
1347 * @}
1348 */
1349
1350/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001351 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001352 *
1353 * Function in this group pertain to LLVMValueRef instances that descent
1354 * from llvm::User. This includes constants, instructions, and
1355 * operators.
1356 *
1357 * @{
1358 */
1359
1360/**
1361 * Obtain an operand at a specific index in a llvm::User value.
1362 *
1363 * @see llvm::User::getOperand()
1364 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001365LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001366
1367/**
1368 * Set an operand at a specific index in a llvm::User value.
1369 *
1370 * @see llvm::User::setOperand()
1371 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001372void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001373
1374/**
1375 * Obtain the number of operands in a llvm::User value.
1376 *
1377 * @see llvm::User::getNumOperands()
1378 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001379int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001380
Gregory Szorc34c863a2012-03-21 03:54:29 +00001381/**
1382 * @}
1383 */
1384
1385/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001386 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001387 *
1388 * This section contains APIs for interacting with LLVMValueRef that
1389 * correspond to llvm::Constant instances.
1390 *
1391 * These functions will work for any LLVMValueRef in the llvm::Constant
1392 * class hierarchy.
1393 *
1394 * @{
1395 */
1396
1397/**
1398 * Obtain a constant value referring to the null instance of a type.
1399 *
1400 * @see llvm::Constant::getNullValue()
1401 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001402LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001403
1404/**
1405 * Obtain a constant value referring to the instance of a type
1406 * consisting of all ones.
1407 *
1408 * This is only valid for integer types.
1409 *
1410 * @see llvm::Constant::getAllOnesValue()
1411 */
1412LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1413
1414/**
1415 * Obtain a constant value referring to an undefined value of a type.
1416 *
1417 * @see llvm::UndefValue::get()
1418 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001419LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001420
1421/**
1422 * Determine whether a value instance is null.
1423 *
1424 * @see llvm::Constant::isNullValue()
1425 */
Chris Lattner25963c62010-01-09 22:27:07 +00001426LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001427
1428/**
1429 * Obtain a constant that is a constant pointer pointing to NULL for a
1430 * specified type.
1431 */
Chris Lattner7f318242009-07-06 17:29:59 +00001432LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001433
Gregory Szorc34c863a2012-03-21 03:54:29 +00001434/**
1435 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1436 *
1437 * Functions in this group model LLVMValueRef instances that correspond
1438 * to constants referring to scalar types.
1439 *
1440 * For integer types, the LLVMTypeRef parameter should correspond to a
1441 * llvm::IntegerType instance and the returned LLVMValueRef will
1442 * correspond to a llvm::ConstantInt.
1443 *
1444 * For floating point types, the LLVMTypeRef returned corresponds to a
1445 * llvm::ConstantFP.
1446 *
1447 * @{
1448 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001449
Gregory Szorc34c863a2012-03-21 03:54:29 +00001450/**
1451 * Obtain a constant value for an integer type.
1452 *
1453 * The returned value corresponds to a llvm::ConstantInt.
1454 *
1455 * @see llvm::ConstantInt::get()
1456 *
1457 * @param IntTy Integer type to obtain value of.
1458 * @param N The value the returned instance should refer to.
1459 * @param SignExtend Whether to sign extend the produced value.
1460 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001461LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001462 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001463
1464/**
1465 * Obtain a constant value for an integer of arbitrary precision.
1466 *
1467 * @see llvm::ConstantInt::get()
1468 */
Chris Lattner4329e072010-11-23 02:47:22 +00001469LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1470 unsigned NumWords,
1471 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001472
1473/**
1474 * Obtain a constant value for an integer parsed from a string.
1475 *
1476 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1477 * string's length is available, it is preferred to call that function
1478 * instead.
1479 *
1480 * @see llvm::ConstantInt::get()
1481 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001482LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1483 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001484
1485/**
1486 * Obtain a constant value for an integer parsed from a string with
1487 * specified length.
1488 *
1489 * @see llvm::ConstantInt::get()
1490 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001491LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1492 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001493
1494/**
1495 * Obtain a constant value referring to a double floating point value.
1496 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001497LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001498
1499/**
1500 * Obtain a constant for a floating point value parsed from a string.
1501 *
1502 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1503 * should be used if the input string's length is known.
1504 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001505LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001506
1507/**
1508 * Obtain a constant for a floating point value parsed from a string.
1509 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001510LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1511 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001512
1513/**
1514 * Obtain the zero extended value for an integer constant value.
1515 *
1516 * @see llvm::ConstantInt::getZExtValue()
1517 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001518unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001519
1520/**
1521 * Obtain the sign extended value for an integer constant value.
1522 *
1523 * @see llvm::ConstantInt::getSExtValue()
1524 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001525long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001526
Gregory Szorc34c863a2012-03-21 03:54:29 +00001527/**
1528 * @}
1529 */
1530
1531/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001532 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1533 *
1534 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001535 *
1536 * @{
1537 */
1538
1539/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001540 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001541 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001542 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001543 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001544LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001545 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001546
1547/**
1548 * Create a ConstantDataSequential with string content in the global context.
1549 *
1550 * This is the same as LLVMConstStringInContext except it operates on the
1551 * global context.
1552 *
1553 * @see LLVMConstStringInContext()
1554 * @see llvm::ConstantDataArray::getString()
1555 */
1556LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1557 LLVMBool DontNullTerminate);
1558
1559/**
1560 * Create an anonymous ConstantStruct with the specified values.
1561 *
1562 * @see llvm::ConstantStruct::getAnon()
1563 */
1564LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001565 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001566 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001567
Gregory Szorc52d26602012-03-21 07:28:27 +00001568/**
1569 * Create a ConstantStruct in the global Context.
1570 *
1571 * This is the same as LLVMConstStructInContext except it operates on the
1572 * global Context.
1573 *
1574 * @see LLVMConstStructInContext()
1575 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001576LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001577 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001578
1579/**
1580 * Create a ConstantArray from values.
1581 *
1582 * @see llvm::ConstantArray::get()
1583 */
1584LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1585 LLVMValueRef *ConstantVals, unsigned Length);
1586
1587/**
1588 * Create a non-anonymous ConstantStruct from values.
1589 *
1590 * @see llvm::ConstantStruct::get()
1591 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001592LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1593 LLVMValueRef *ConstantVals,
1594 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001595
1596/**
1597 * Create a ConstantVector from values.
1598 *
1599 * @see llvm::ConstantVector::get()
1600 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001601LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001602
Gregory Szorc52d26602012-03-21 07:28:27 +00001603/**
1604 * @}
1605 */
1606
1607/**
1608 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1609 *
1610 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1611 *
1612 * @see llvm::ConstantExpr.
1613 *
1614 * @{
1615 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001616LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001617LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001618LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1619LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001620LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1621LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001622LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001623LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1624LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001625LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001626LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001627LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001628LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001629LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1630LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001631LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001632LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001633LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1634LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001635LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001636LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1637LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001638LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001639LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1640LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1641LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1642LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1643LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1644LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1645LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1646LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1647 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1648LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1649 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1650LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1651LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1652LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1653LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1654 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001655LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1656 LLVMValueRef *ConstantIndices,
1657 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001658LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1659LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1660LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1661LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1662LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1663LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1664LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1665LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1666LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1667LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1668LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1669LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001670LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001671LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1672 LLVMTypeRef ToType);
1673LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1674 LLVMTypeRef ToType);
1675LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1676 LLVMTypeRef ToType);
1677LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1678 LLVMTypeRef ToType);
1679LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001680 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001681LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001682LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1683 LLVMValueRef ConstantIfTrue,
1684 LLVMValueRef ConstantIfFalse);
1685LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1686 LLVMValueRef IndexConstant);
1687LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1688 LLVMValueRef ElementValueConstant,
1689 LLVMValueRef IndexConstant);
1690LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1691 LLVMValueRef VectorBConstant,
1692 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001693LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1694 unsigned NumIdx);
1695LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1696 LLVMValueRef ElementValueConstant,
1697 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001698LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001699 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001700 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001701LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001702
Gregory Szorc52d26602012-03-21 07:28:27 +00001703/**
1704 * @}
1705 */
1706
1707/**
1708 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1709 *
1710 * This group contains functions that operate on global values. Functions in
1711 * this group relate to functions in the llvm::GlobalValue class tree.
1712 *
1713 * @see llvm::GlobalValue
1714 *
1715 * @{
1716 */
1717
Gordon Henriksen265f7802008-03-19 01:11:35 +00001718LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001719LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001720LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1721void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1722const char *LLVMGetSection(LLVMValueRef Global);
1723void LLVMSetSection(LLVMValueRef Global, const char *Section);
1724LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1725void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001726LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1727void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001728LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1729void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001730
1731/**
1732 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1733 *
1734 * Functions in this group only apply to values with alignment, i.e.
1735 * global variables, load and store instructions.
1736 */
1737
1738/**
1739 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001740 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001741 * @see llvm::LoadInst::getAlignment()
1742 * @see llvm::StoreInst::getAlignment()
1743 * @see llvm::GlobalValue::getAlignment()
1744 */
1745unsigned LLVMGetAlignment(LLVMValueRef V);
1746
1747/**
1748 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001749 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001750 * @see llvm::LoadInst::setAlignment()
1751 * @see llvm::StoreInst::setAlignment()
1752 * @see llvm::GlobalValue::setAlignment()
1753 */
1754void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1755
1756/**
1757 * @}
1758 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001759
Gregory Szorc52d26602012-03-21 07:28:27 +00001760/**
1761 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1762 *
1763 * This group contains functions that operate on global variable values.
1764 *
1765 * @see llvm::GlobalVariable
1766 *
1767 * @{
1768 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001769LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001770LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1771 const char *Name,
1772 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001773LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001774LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1775LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1776LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1777LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001778void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001779LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1780void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001781LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1782void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1783LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1784void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001785LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1786void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1787LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1788void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001789
Gregory Szorc52d26602012-03-21 07:28:27 +00001790/**
1791 * @}
1792 */
1793
1794/**
1795 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1796 *
1797 * This group contains function that operate on global alias values.
1798 *
1799 * @see llvm::GlobalAlias
1800 *
1801 * @{
1802 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001803LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1804 const char *Name);
1805
Gregory Szorc34c863a2012-03-21 03:54:29 +00001806/**
1807 * @}
1808 */
1809
1810/**
1811 * @defgroup LLVMCCoreValueFunction Function values
1812 *
1813 * Functions in this group operate on LLVMValueRef instances that
1814 * correspond to llvm::Function instances.
1815 *
1816 * @see llvm::Function
1817 *
1818 * @{
1819 */
1820
1821/**
1822 * Remove a function from its containing module and deletes it.
1823 *
1824 * @see llvm::Function::eraseFromParent()
1825 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001826void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001827
1828/**
1829 * Obtain the ID number from a function instance.
1830 *
1831 * @see llvm::Function::getIntrinsicID()
1832 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001833unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001834
1835/**
1836 * Obtain the calling function of a function.
1837 *
1838 * The returned value corresponds to the LLVMCallConv enumeration.
1839 *
1840 * @see llvm::Function::getCallingConv()
1841 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001842unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001843
1844/**
1845 * Set the calling convention of a function.
1846 *
1847 * @see llvm::Function::setCallingConv()
1848 *
1849 * @param Fn Function to operate on
1850 * @param CC LLVMCallConv to set calling convention to
1851 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001852void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001853
1854/**
1855 * Obtain the name of the garbage collector to use during code
1856 * generation.
1857 *
1858 * @see llvm::Function::getGC()
1859 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001860const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001861
1862/**
1863 * Define the garbage collector to use during code generation.
1864 *
1865 * @see llvm::Function::setGC()
1866 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001867void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001868
1869/**
1870 * Add an attribute to a function.
1871 *
1872 * @see llvm::Function::addAttribute()
1873 */
Duncan Sands7374a012009-05-06 12:21:17 +00001874void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001875
1876/**
Tom Stellarde8f35e12013-04-16 23:12:43 +00001877 * Add a target-dependent attribute to a fuction
1878 * @see llvm::AttrBuilder::addAttribute()
1879 */
1880void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1881 const char *V);
1882
1883/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001884 * Obtain an attribute from a function.
1885 *
1886 * @see llvm::Function::getAttributes()
1887 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001888LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001889
1890/**
1891 * Remove an attribute from a function.
1892 */
Duncan Sands7374a012009-05-06 12:21:17 +00001893void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001894
Gregory Szorc34c863a2012-03-21 03:54:29 +00001895/**
1896 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1897 *
1898 * Functions in this group relate to arguments/parameters on functions.
1899 *
1900 * Functions in this group expect LLVMValueRef instances that correspond
1901 * to llvm::Function instances.
1902 *
1903 * @{
1904 */
1905
1906/**
1907 * Obtain the number of parameters in a function.
1908 *
1909 * @see llvm::Function::arg_size()
1910 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001911unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001912
1913/**
1914 * Obtain the parameters in a function.
1915 *
1916 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1917 * at least LLVMCountParams() long. This array will be filled with
1918 * LLVMValueRef instances which correspond to the parameters the
1919 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1920 * instance.
1921 *
1922 * @see llvm::Function::arg_begin()
1923 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001924void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001925
1926/**
1927 * Obtain the parameter at the specified index.
1928 *
1929 * Parameters are indexed from 0.
1930 *
1931 * @see llvm::Function::arg_begin()
1932 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001933LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001934
1935/**
1936 * Obtain the function to which this argument belongs.
1937 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001938 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00001939 * that corresponds to a llvm::Attribute.
1940 *
1941 * The returned LLVMValueRef is the llvm::Function to which this
1942 * argument belongs.
1943 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001944LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001945
1946/**
1947 * Obtain the first parameter to a function.
1948 *
1949 * @see llvm::Function::arg_begin()
1950 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001951LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001952
1953/**
1954 * Obtain the last parameter to a function.
1955 *
1956 * @see llvm::Function::arg_end()
1957 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001958LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001959
1960/**
1961 * Obtain the next parameter to a function.
1962 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001963 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00001964 * actually a wrapped iterator) and obtains the next parameter from the
1965 * underlying iterator.
1966 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001967LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001968
1969/**
1970 * Obtain the previous parameter to a function.
1971 *
1972 * This is the opposite of LLVMGetNextParam().
1973 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001974LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001975
1976/**
1977 * Add an attribute to a function argument.
1978 *
1979 * @see llvm::Argument::addAttr()
1980 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001981void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001982
1983/**
1984 * Remove an attribute from a function argument.
1985 *
1986 * @see llvm::Argument::removeAttr()
1987 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001988void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001989
1990/**
1991 * Get an attribute from a function argument.
1992 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001993LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001994
1995/**
1996 * Set the alignment for a function parameter.
1997 *
1998 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00001999 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002000 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002001void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002002
Gregory Szorc34c863a2012-03-21 03:54:29 +00002003/**
2004 * @}
2005 */
2006
2007/**
2008 * @}
2009 */
2010
2011/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002012 * @}
2013 */
2014
2015/**
2016 * @}
2017 */
2018
2019/**
2020 * @defgroup LLVMCCoreValueMetadata Metadata
2021 *
2022 * @{
2023 */
2024
2025/**
2026 * Obtain a MDString value from a context.
2027 *
2028 * The returned instance corresponds to the llvm::MDString class.
2029 *
2030 * The instance is specified by string data of a specified length. The
2031 * string content is copied, so the backing memory can be freed after
2032 * this function returns.
2033 */
2034LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2035 unsigned SLen);
2036
2037/**
2038 * Obtain a MDString value from the global context.
2039 */
2040LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2041
2042/**
2043 * Obtain a MDNode value from a context.
2044 *
2045 * The returned value corresponds to the llvm::MDNode class.
2046 */
2047LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2048 unsigned Count);
2049
2050/**
2051 * Obtain a MDNode value from the global context.
2052 */
2053LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2054
2055/**
2056 * Obtain the underlying string from a MDString value.
2057 *
2058 * @param V Instance to obtain string from.
2059 * @param Len Memory address which will hold length of returned string.
2060 * @return String data in MDString.
2061 */
2062const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2063
2064/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002065 * Obtain the number of operands from an MDNode value.
2066 *
2067 * @param V MDNode to get number of operands from.
2068 * @return Number of operands of the MDNode.
2069 */
2070unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2071
2072/**
2073 * Obtain the given MDNode's operands.
2074 *
2075 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2076 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2077 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2078 * MDNode's operands.
2079 *
2080 * @param V MDNode to get the operands from.
2081 * @param Dest Destination array for operands.
2082 */
2083void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2084
2085/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002086 * @}
2087 */
2088
2089/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002090 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2091 *
2092 * A basic block represents a single entry single exit section of code.
2093 * Basic blocks contain a list of instructions which form the body of
2094 * the block.
2095 *
2096 * Basic blocks belong to functions. They have the type of label.
2097 *
2098 * Basic blocks are themselves values. However, the C API models them as
2099 * LLVMBasicBlockRef.
2100 *
2101 * @see llvm::BasicBlock
2102 *
2103 * @{
2104 */
2105
2106/**
2107 * Convert a basic block instance to a value type.
2108 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002109LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002110
2111/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002112 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002113 */
Chris Lattner25963c62010-01-09 22:27:07 +00002114LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002115
2116/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002117 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002118 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002119LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002120
2121/**
2122 * Obtain the function to which a basic block belongs.
2123 *
2124 * @see llvm::BasicBlock::getParent()
2125 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002126LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002127
2128/**
2129 * Obtain the terminator instruction for a basic block.
2130 *
2131 * If the basic block does not have a terminator (it is not well-formed
2132 * if it doesn't), then NULL is returned.
2133 *
2134 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2135 *
2136 * @see llvm::BasicBlock::getTerminator()
2137 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002138LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002139
2140/**
2141 * Obtain the number of basic blocks in a function.
2142 *
2143 * @param Fn Function value to operate on.
2144 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002145unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002146
2147/**
2148 * Obtain all of the basic blocks in a function.
2149 *
2150 * This operates on a function value. The BasicBlocks parameter is a
2151 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2152 * LLVMCountBasicBlocks() in length. This array is populated with
2153 * LLVMBasicBlockRef instances.
2154 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002155void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002156
2157/**
2158 * Obtain the first basic block in a function.
2159 *
2160 * The returned basic block can be used as an iterator. You will likely
2161 * eventually call into LLVMGetNextBasicBlock() with it.
2162 *
2163 * @see llvm::Function::begin()
2164 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002165LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002166
2167/**
2168 * Obtain the last basic block in a function.
2169 *
2170 * @see llvm::Function::end()
2171 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002172LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002173
2174/**
2175 * Advance a basic block iterator.
2176 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002177LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002178
2179/**
2180 * Go backwards in a basic block iterator.
2181 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002182LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002183
2184/**
2185 * Obtain the basic block that corresponds to the entry point of a
2186 * function.
2187 *
2188 * @see llvm::Function::getEntryBlock()
2189 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002190LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002191
Gregory Szorc34c863a2012-03-21 03:54:29 +00002192/**
2193 * Append a basic block to the end of a function.
2194 *
2195 * @see llvm::BasicBlock::Create()
2196 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002197LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2198 LLVMValueRef Fn,
2199 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002200
2201/**
2202 * Append a basic block to the end of a function using the global
2203 * context.
2204 *
2205 * @see llvm::BasicBlock::Create()
2206 */
2207LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2208
2209/**
2210 * Insert a basic block in a function before another basic block.
2211 *
2212 * The function to add to is determined by the function of the
2213 * passed basic block.
2214 *
2215 * @see llvm::BasicBlock::Create()
2216 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002217LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2218 LLVMBasicBlockRef BB,
2219 const char *Name);
2220
Gregory Szorc34c863a2012-03-21 03:54:29 +00002221/**
2222 * Insert a basic block in a function using the global context.
2223 *
2224 * @see llvm::BasicBlock::Create()
2225 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002226LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2227 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002228
2229/**
2230 * Remove a basic block from a function and delete it.
2231 *
2232 * This deletes the basic block from its containing function and deletes
2233 * the basic block itself.
2234 *
2235 * @see llvm::BasicBlock::eraseFromParent()
2236 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002237void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002238
2239/**
2240 * Remove a basic block from a function.
2241 *
2242 * This deletes the basic block from its containing function but keep
2243 * the basic block alive.
2244 *
2245 * @see llvm::BasicBlock::removeFromParent()
2246 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002247void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002248
Gregory Szorc34c863a2012-03-21 03:54:29 +00002249/**
2250 * Move a basic block to before another one.
2251 *
2252 * @see llvm::BasicBlock::moveBefore()
2253 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002254void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002255
2256/**
2257 * Move a basic block to after another one.
2258 *
2259 * @see llvm::BasicBlock::moveAfter()
2260 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002261void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2262
Gregory Szorc34c863a2012-03-21 03:54:29 +00002263/**
2264 * Obtain the first instruction in a basic block.
2265 *
2266 * The returned LLVMValueRef corresponds to a llvm::Instruction
2267 * instance.
2268 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002269LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002270
2271/**
2272 * Obtain the last instruction in a basic block.
2273 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002274 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002275 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002276LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002277
Gregory Szorc34c863a2012-03-21 03:54:29 +00002278/**
2279 * @}
2280 */
2281
2282/**
2283 * @defgroup LLVMCCoreValueInstruction Instructions
2284 *
2285 * Functions in this group relate to the inspection and manipulation of
2286 * individual instructions.
2287 *
2288 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2289 * class has a large number of descendents. llvm::Instruction is a
2290 * llvm::Value and in the C API, instructions are modeled by
2291 * LLVMValueRef.
2292 *
2293 * This group also contains sub-groups which operate on specific
2294 * llvm::Instruction types, e.g. llvm::CallInst.
2295 *
2296 * @{
2297 */
2298
2299/**
2300 * Determine whether an instruction has any metadata attached.
2301 */
2302int LLVMHasMetadata(LLVMValueRef Val);
2303
2304/**
2305 * Return metadata associated with an instruction value.
2306 */
2307LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2308
2309/**
2310 * Set metadata associated with an instruction value.
2311 */
2312void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2313
2314/**
2315 * Obtain the basic block to which an instruction belongs.
2316 *
2317 * @see llvm::Instruction::getParent()
2318 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002319LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002320
2321/**
2322 * Obtain the instruction that occurs after the one specified.
2323 *
2324 * The next instruction will be from the same basic block.
2325 *
2326 * If this is the last instruction in a basic block, NULL will be
2327 * returned.
2328 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002329LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002330
2331/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002332 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002333 *
2334 * If the instruction is the first instruction in a basic block, NULL
2335 * will be returned.
2336 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002337LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002338
2339/**
2340 * Remove and delete an instruction.
2341 *
2342 * The instruction specified is removed from its containing building
2343 * block and then deleted.
2344 *
2345 * @see llvm::Instruction::eraseFromParent()
2346 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002347void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002348
2349/**
2350 * Obtain the code opcode for an individual instruction.
2351 *
2352 * @see llvm::Instruction::getOpCode()
2353 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002354LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002355
2356/**
2357 * Obtain the predicate of an instruction.
2358 *
2359 * This is only valid for instructions that correspond to llvm::ICmpInst
2360 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2361 *
2362 * @see llvm::ICmpInst::getPredicate()
2363 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002364LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002365
Gregory Szorc34c863a2012-03-21 03:54:29 +00002366/**
2367 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2368 *
2369 * Functions in this group apply to instructions that refer to call
2370 * sites and invocations. These correspond to C++ types in the
2371 * llvm::CallInst class tree.
2372 *
2373 * @{
2374 */
2375
2376/**
2377 * Set the calling convention for a call instruction.
2378 *
2379 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2380 * llvm::InvokeInst.
2381 *
2382 * @see llvm::CallInst::setCallingConv()
2383 * @see llvm::InvokeInst::setCallingConv()
2384 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002385void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002386
2387/**
2388 * Obtain the calling convention for a call instruction.
2389 *
2390 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2391 * usage.
2392 *
2393 * @see LLVMSetInstructionCallConv()
2394 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002395unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002396
2397
Devang Patel4c758ea2008-09-25 21:00:45 +00002398void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002399void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002400 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002401void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002402 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002403
Gregory Szorc34c863a2012-03-21 03:54:29 +00002404/**
2405 * Obtain whether a call instruction is a tail call.
2406 *
2407 * This only works on llvm::CallInst instructions.
2408 *
2409 * @see llvm::CallInst::isTailCall()
2410 */
Chris Lattner25963c62010-01-09 22:27:07 +00002411LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002412
2413/**
2414 * Set whether a call instruction is a tail call.
2415 *
2416 * This only works on llvm::CallInst instructions.
2417 *
2418 * @see llvm::CallInst::setTailCall()
2419 */
Chris Lattner25963c62010-01-09 22:27:07 +00002420void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002421
Gregory Szorc34c863a2012-03-21 03:54:29 +00002422/**
2423 * @}
2424 */
2425
2426/**
2427 * Obtain the default destination basic block of a switch instruction.
2428 *
2429 * This only works on llvm::SwitchInst instructions.
2430 *
2431 * @see llvm::SwitchInst::getDefaultDest()
2432 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002433LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2434
Gregory Szorc34c863a2012-03-21 03:54:29 +00002435/**
2436 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2437 *
2438 * Functions in this group only apply to instructions that map to
2439 * llvm::PHINode instances.
2440 *
2441 * @{
2442 */
2443
2444/**
2445 * Add an incoming value to the end of a PHI list.
2446 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002447void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2448 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002449
2450/**
2451 * Obtain the number of incoming basic blocks to a PHI node.
2452 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002453unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002454
2455/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002456 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002457 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002458LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002459
2460/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002461 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002462 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002463LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002464
Gregory Szorc34c863a2012-03-21 03:54:29 +00002465/**
2466 * @}
2467 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002468
Gregory Szorc34c863a2012-03-21 03:54:29 +00002469/**
2470 * @}
2471 */
2472
2473/**
2474 * @}
2475 */
2476
2477/**
2478 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2479 *
2480 * An instruction builder represents a point within a basic block and is
2481 * the exclusive means of building instructions using the C interface.
2482 *
2483 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002484 */
2485
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002486LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002487LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002488void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2489 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002490void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2491void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002492LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002493void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2494void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002495void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2496 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002497void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2498
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002499/* Metadata */
2500void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2501LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2502void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2503
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002504/* Terminators */
2505LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2506LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002507LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002508 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002509LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2510LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2511 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2512LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2513 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002514LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2515 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002516LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2517 LLVMValueRef *Args, unsigned NumArgs,
2518 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2519 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002520LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2521 LLVMValueRef PersFn, unsigned NumClauses,
2522 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002523LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002524LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2525
Gordon Henriksen097102c2008-01-01 05:50:53 +00002526/* Add a case to the switch instruction */
2527void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2528 LLVMBasicBlockRef Dest);
2529
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002530/* Add a destination to the indirectbr instruction */
2531void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2532
Bill Wendlingfae14752011-08-12 20:24:12 +00002533/* Add a catch or filter clause to the landingpad instruction */
2534void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2535
2536/* Set the 'cleanup' flag in the landingpad instruction */
2537void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2538
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002539/* Arithmetic */
2540LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2541 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002542LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2543 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002544LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2545 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002546LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2547 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002548LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2549 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002550LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2551 const char *Name);
2552LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2553 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002554LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2555 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002556LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2557 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002558LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2559 const char *Name);
2560LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2561 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002562LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2563 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002564LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2565 const char *Name);
2566LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2567 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002568LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2569 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002570LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2571 const char *Name);
2572LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2573 const char *Name);
2574LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2575 const char *Name);
2576LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2577 const char *Name);
2578LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2579 const char *Name);
2580LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2581 const char *Name);
2582LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2583 const char *Name);
2584LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2585 const char *Name);
2586LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2587 const char *Name);
2588LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2589 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002590LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2591 LLVMValueRef LHS, LLVMValueRef RHS,
2592 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002593LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002594LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2595 const char *Name);
2596LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2597 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002598LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002599LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2600
2601/* Memory */
2602LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2603LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2604 LLVMValueRef Val, const char *Name);
2605LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2606LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2607 LLVMValueRef Val, const char *Name);
2608LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2609LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2610 const char *Name);
2611LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2612LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2613 LLVMValueRef *Indices, unsigned NumIndices,
2614 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002615LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2616 LLVMValueRef *Indices, unsigned NumIndices,
2617 const char *Name);
2618LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2619 unsigned Idx, const char *Name);
2620LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2621 const char *Name);
2622LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2623 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002624LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2625void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002626
2627/* Casts */
2628LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2629 LLVMTypeRef DestTy, const char *Name);
2630LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2631 LLVMTypeRef DestTy, const char *Name);
2632LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2633 LLVMTypeRef DestTy, const char *Name);
2634LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2635 LLVMTypeRef DestTy, const char *Name);
2636LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2637 LLVMTypeRef DestTy, const char *Name);
2638LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2639 LLVMTypeRef DestTy, const char *Name);
2640LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2641 LLVMTypeRef DestTy, const char *Name);
2642LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2643 LLVMTypeRef DestTy, const char *Name);
2644LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2645 LLVMTypeRef DestTy, const char *Name);
2646LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2647 LLVMTypeRef DestTy, const char *Name);
2648LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2649 LLVMTypeRef DestTy, const char *Name);
2650LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2651 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002652LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2653 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002654LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2655 LLVMTypeRef DestTy, const char *Name);
2656LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2657 LLVMTypeRef DestTy, const char *Name);
2658LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2659 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002660LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2661 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002662LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2663 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002664LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002665 LLVMTypeRef DestTy, const char *Name);
2666LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2667 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002668
2669/* Comparisons */
2670LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2671 LLVMValueRef LHS, LLVMValueRef RHS,
2672 const char *Name);
2673LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2674 LLVMValueRef LHS, LLVMValueRef RHS,
2675 const char *Name);
2676
2677/* Miscellaneous instructions */
2678LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2679LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2680 LLVMValueRef *Args, unsigned NumArgs,
2681 const char *Name);
2682LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2683 LLVMValueRef Then, LLVMValueRef Else,
2684 const char *Name);
2685LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2686 const char *Name);
2687LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2688 LLVMValueRef Index, const char *Name);
2689LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2690 LLVMValueRef EltVal, LLVMValueRef Index,
2691 const char *Name);
2692LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2693 LLVMValueRef V2, LLVMValueRef Mask,
2694 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002695LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2696 unsigned Index, const char *Name);
2697LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2698 LLVMValueRef EltVal, unsigned Index,
2699 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002700
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002701LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2702 const char *Name);
2703LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2704 const char *Name);
2705LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2706 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00002707LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2708 LLVMBool singleThread, const char *Name);
2709LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00002710 LLVMValueRef PTR, LLVMValueRef Val,
2711 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00002712 LLVMBool singleThread);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002713
Gregory Szorc34c863a2012-03-21 03:54:29 +00002714/**
2715 * @}
2716 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002717
Gregory Szorc34c863a2012-03-21 03:54:29 +00002718/**
2719 * @defgroup LLVMCCoreModuleProvider Module Providers
2720 *
2721 * @{
2722 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002723
Gregory Szorc34c863a2012-03-21 03:54:29 +00002724/**
2725 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002726 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002727 */
2728LLVMModuleProviderRef
2729LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2730
Gregory Szorc34c863a2012-03-21 03:54:29 +00002731/**
2732 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002733 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002734void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002735
Gregory Szorc34c863a2012-03-21 03:54:29 +00002736/**
2737 * @}
2738 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002739
Gregory Szorc34c863a2012-03-21 03:54:29 +00002740/**
2741 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2742 *
2743 * @{
2744 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002745
Chris Lattner25963c62010-01-09 22:27:07 +00002746LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2747 LLVMMemoryBufferRef *OutMemBuf,
2748 char **OutMessage);
2749LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2750 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00002751LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2752 size_t InputDataLength,
2753 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00002754 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00002755LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2756 size_t InputDataLength,
2757 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00002758const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00002759size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002760void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2761
Gregory Szorc34c863a2012-03-21 03:54:29 +00002762/**
2763 * @}
2764 */
2765
2766/**
2767 * @defgroup LLVMCCorePassRegistry Pass Registry
2768 *
2769 * @{
2770 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002771
2772/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002773 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002774LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002775
Gregory Szorc34c863a2012-03-21 03:54:29 +00002776/**
2777 * @}
2778 */
2779
2780/**
2781 * @defgroup LLVMCCorePassManagers Pass Managers
2782 *
2783 * @{
2784 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002785
2786/** Constructs a new whole-module pass pipeline. This type of pipeline is
2787 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002788 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002789LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002790
2791/** Constructs a new function-by-function pass pipeline over the module
2792 provider. It does not take ownership of the module provider. This type of
2793 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002794 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002795LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2796
2797/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002798LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2799
2800/** Initializes, executes on the provided module, and finalizes all of the
2801 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002802 modified the module, 0 otherwise.
2803 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002804LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002805
2806/** Initializes all of the function passes scheduled in the function pass
2807 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002808 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002809LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002810
2811/** Executes all of the function passes scheduled in the function pass manager
2812 on the provided function. Returns 1 if any of the passes modified the
2813 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002814 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002815LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002816
2817/** Finalizes all of the function passes scheduled in in the function pass
2818 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002819 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002820LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002821
2822/** Frees the memory of a pass pipeline. For function pipelines, does not free
2823 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002824 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002825void LLVMDisposePassManager(LLVMPassManagerRef PM);
2826
Gregory Szorc34c863a2012-03-21 03:54:29 +00002827/**
2828 * @}
2829 */
2830
2831/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00002832 * @defgroup LLVMCCoreThreading Threading
2833 *
2834 * Handle the structures needed to make LLVM safe for multithreading.
2835 *
2836 * @{
2837 */
2838
2839/** Allocate and initialize structures needed to make LLVM safe for
2840 multithreading. The return value indicates whether multithreaded
2841 initialization succeeded. Must be executed in isolation from all
2842 other LLVM api calls.
2843 @see llvm::llvm_start_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002844LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002845
2846/** Deallocate structures necessary to make LLVM safe for multithreading.
2847 Must be executed in isolation from all other LLVM api calls.
2848 @see llvm::llvm_stop_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002849void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002850
2851/** Check whether LLVM is executing in thread-safe mode or not.
2852 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002853LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002854
2855/**
2856 * @}
2857 */
2858
2859/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002860 * @}
2861 */
2862
2863/**
2864 * @}
2865 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002866
Gordon Henriksen76a03742007-09-18 03:18:57 +00002867#ifdef __cplusplus
2868}
Evan Cheng2e254d02013-04-04 17:40:53 +00002869#endif /* !defined(__cplusplus) */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002870
Evan Cheng2e254d02013-04-04 17:40:53 +00002871#endif /* !defined(LLVM_C_CORE_H) */