blob: cd9263d49142d497959bb7d9c9239e5cec3782dc [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
Juergen Ributzka49892552014-04-28 18:19:25 +0000115/** @see llvm::Pass */
116typedef struct LLVMOpaquePass *LLVMPassRef;
117
Gregory Szorc34c863a2012-03-21 03:54:29 +0000118/** @see llvm::PassManagerBase */
Gordon Henriksen878114b2008-03-16 04:20:44 +0000119typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
120
Gregory Szorc34c863a2012-03-21 03:54:29 +0000121/** @see llvm::PassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +0000122typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
123
Juergen Ributzka49892552014-04-28 18:19:25 +0000124/** @see llvm::PassRunListener */
125typedef struct LLVMOpaquePassRunListener *LLVMPassRunListenerRef;
126
127/** @see llvm::LLVMPassRunListener */
128typedef void (*LLVMPassRunListenerHandlerTy)(LLVMContextRef, LLVMPassRef,
129 LLVMModuleRef, LLVMValueRef,
130 LLVMBasicBlockRef);
131
Gregory Szorc34c863a2012-03-21 03:54:29 +0000132/**
133 * Used to get the users and usees of a Value.
134 *
135 * @see llvm::Use */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +0000136typedef struct LLVMOpaqueUse *LLVMUseRef;
Chris Lattner40cf28d2009-10-12 04:01:02 +0000137
Tom Stellard1580dc72014-04-16 17:45:04 +0000138
139/**
140 * @see llvm::DiagnosticInfo
141 */
142typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
143
Gordon Henriksen76a03742007-09-18 03:18:57 +0000144typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +0000145 LLVMZExtAttribute = 1<<0,
146 LLVMSExtAttribute = 1<<1,
147 LLVMNoReturnAttribute = 1<<2,
148 LLVMInRegAttribute = 1<<3,
149 LLVMStructRetAttribute = 1<<4,
150 LLVMNoUnwindAttribute = 1<<5,
151 LLVMNoAliasAttribute = 1<<6,
152 LLVMByValAttribute = 1<<7,
153 LLVMNestAttribute = 1<<8,
154 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000155 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000156 LLVMNoInlineAttribute = 1<<11,
157 LLVMAlwaysInlineAttribute = 1<<12,
158 LLVMOptimizeForSizeAttribute = 1<<13,
159 LLVMStackProtectAttribute = 1<<14,
160 LLVMStackProtectReqAttribute = 1<<15,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000161 LLVMAlignment = 31<<16,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000162 LLVMNoCaptureAttribute = 1<<21,
163 LLVMNoRedZoneAttribute = 1<<22,
164 LLVMNoImplicitFloatAttribute = 1<<23,
Jakob Stoklund Olesen74bb06c2010-02-06 01:16:28 +0000165 LLVMNakedAttribute = 1<<24,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000166 LLVMInlineHintAttribute = 1<<25,
Torok Edwin1db48c02011-10-06 12:13:32 +0000167 LLVMStackAlignment = 7<<26,
168 LLVMReturnsTwice = 1 << 29,
169 LLVMUWTable = 1 << 30,
Chandler Carruth44d69d92012-01-25 07:40:15 +0000170 LLVMNonLazyBind = 1 << 31
171
Bill Wendlingd154e2832013-01-23 06:41:41 +0000172 /* FIXME: These attributes are currently not included in the C API as
Nuno Lopesdef4229972012-09-02 14:19:21 +0000173 a temporary measure until the API/ABI impact to the C API is understood
174 and the path forward agreed upon.
Bill Wendlingd154e2832013-01-23 06:41:41 +0000175 LLVMAddressSafety = 1ULL << 32,
Andrea Di Biagio377496b2013-08-23 11:53:55 +0000176 LLVMStackProtectStrongAttribute = 1ULL<<33,
177 LLVMCold = 1ULL << 34,
Reid Klecknera534a382013-12-19 02:14:12 +0000178 LLVMOptimizeNone = 1ULL << 35,
179 LLVMInAllocaAttribute = 1ULL << 36
Nuno Lopesdef4229972012-09-02 14:19:21 +0000180 */
Devang Patel4c758ea2008-09-25 21:00:45 +0000181} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000182
183typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000184 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000185 LLVMRet = 1,
186 LLVMBr = 2,
187 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000188 LLVMIndirectBr = 4,
189 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000190 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000191 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000192
Bill Wendlingda52cec2010-02-15 20:53:17 +0000193 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000194 LLVMAdd = 8,
195 LLVMFAdd = 9,
196 LLVMSub = 10,
197 LLVMFSub = 11,
198 LLVMMul = 12,
199 LLVMFMul = 13,
200 LLVMUDiv = 14,
201 LLVMSDiv = 15,
202 LLVMFDiv = 16,
203 LLVMURem = 17,
204 LLVMSRem = 18,
205 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000206
Bill Wendlingda52cec2010-02-15 20:53:17 +0000207 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000208 LLVMShl = 20,
209 LLVMLShr = 21,
210 LLVMAShr = 22,
211 LLVMAnd = 23,
212 LLVMOr = 24,
213 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000214
Bill Wendlingda52cec2010-02-15 20:53:17 +0000215 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000216 LLVMAlloca = 26,
217 LLVMLoad = 27,
218 LLVMStore = 28,
219 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000220
Bill Wendlingda52cec2010-02-15 20:53:17 +0000221 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000222 LLVMTrunc = 30,
223 LLVMZExt = 31,
224 LLVMSExt = 32,
225 LLVMFPToUI = 33,
226 LLVMFPToSI = 34,
227 LLVMUIToFP = 35,
228 LLVMSIToFP = 36,
229 LLVMFPTrunc = 37,
230 LLVMFPExt = 38,
231 LLVMPtrToInt = 39,
232 LLVMIntToPtr = 40,
233 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000234 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000235
Bill Wendlingda52cec2010-02-15 20:53:17 +0000236 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000237 LLVMICmp = 42,
238 LLVMFCmp = 43,
239 LLVMPHI = 44,
240 LLVMCall = 45,
241 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000242 LLVMUserOp1 = 47,
243 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000244 LLVMVAArg = 49,
245 LLVMExtractElement = 50,
246 LLVMInsertElement = 51,
247 LLVMShuffleVector = 52,
248 LLVMExtractValue = 53,
249 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000250
251 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000252 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000253 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000254 LLVMAtomicRMW = 57,
255
256 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000257 LLVMResume = 58,
Bill Wendling0aef16a2012-02-06 21:44:22 +0000258 LLVMLandingPad = 59
Bill Wendling2641d132011-07-27 21:00:28 +0000259
Chris Lattner40cf28d2009-10-12 04:01:02 +0000260} LLVMOpcode;
261
262typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000263 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000264 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000265 LLVMFloatTypeKind, /**< 32 bit floating point type */
266 LLVMDoubleTypeKind, /**< 64 bit floating point type */
267 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
268 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
269 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
270 LLVMLabelTypeKind, /**< Labels */
271 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
272 LLVMFunctionTypeKind, /**< Functions */
273 LLVMStructTypeKind, /**< Structures */
274 LLVMArrayTypeKind, /**< Arrays */
275 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000276 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000277 LLVMMetadataTypeKind, /**< Metadata */
278 LLVMX86_MMXTypeKind /**< X86 MMX */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000279} LLVMTypeKind;
280
281typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000282 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000283 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000284 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
285 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
286 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000287 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000288 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
289 LLVMWeakODRLinkage, /**< Same, but only replaced by something
290 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000291 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
292 LLVMInternalLinkage, /**< Rename collisions when linking (static
293 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000294 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000295 LLVMDLLImportLinkage, /**< Obsolete */
296 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000297 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000298 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000299 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000300 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000301 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000302} LLVMLinkage;
303
304typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000305 LLVMDefaultVisibility, /**< The GV is visible */
306 LLVMHiddenVisibility, /**< The GV is hidden */
307 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000308} LLVMVisibility;
309
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000310typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000311 LLVMDefaultStorageClass = 0,
312 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
313 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
314} LLVMDLLStorageClass;
315
316typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000317 LLVMCCallConv = 0,
318 LLVMFastCallConv = 8,
319 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000320 LLVMWebKitJSCallConv = 12,
321 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000322 LLVMX86StdcallCallConv = 64,
323 LLVMX86FastcallCallConv = 65
324} LLVMCallConv;
325
326typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000327 LLVMIntEQ = 32, /**< equal */
328 LLVMIntNE, /**< not equal */
329 LLVMIntUGT, /**< unsigned greater than */
330 LLVMIntUGE, /**< unsigned greater or equal */
331 LLVMIntULT, /**< unsigned less than */
332 LLVMIntULE, /**< unsigned less or equal */
333 LLVMIntSGT, /**< signed greater than */
334 LLVMIntSGE, /**< signed greater or equal */
335 LLVMIntSLT, /**< signed less than */
336 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000337} LLVMIntPredicate;
338
339typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000340 LLVMRealPredicateFalse, /**< Always false (always folded) */
341 LLVMRealOEQ, /**< True if ordered and equal */
342 LLVMRealOGT, /**< True if ordered and greater than */
343 LLVMRealOGE, /**< True if ordered and greater than or equal */
344 LLVMRealOLT, /**< True if ordered and less than */
345 LLVMRealOLE, /**< True if ordered and less than or equal */
346 LLVMRealONE, /**< True if ordered and operands are unequal */
347 LLVMRealORD, /**< True if ordered (no nans) */
348 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
349 LLVMRealUEQ, /**< True if unordered or equal */
350 LLVMRealUGT, /**< True if unordered or greater than */
351 LLVMRealUGE, /**< True if unordered, greater than, or equal */
352 LLVMRealULT, /**< True if unordered or less than */
353 LLVMRealULE, /**< True if unordered, less than, or equal */
354 LLVMRealUNE, /**< True if unordered or not equal */
355 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000356} LLVMRealPredicate;
357
Bill Wendlingfae14752011-08-12 20:24:12 +0000358typedef enum {
359 LLVMLandingPadCatch, /**< A catch clause */
360 LLVMLandingPadFilter /**< A filter clause */
361} LLVMLandingPadClauseTy;
362
Hans Wennborg5ff71202013-04-16 08:58:59 +0000363typedef enum {
364 LLVMNotThreadLocal = 0,
365 LLVMGeneralDynamicTLSModel,
366 LLVMLocalDynamicTLSModel,
367 LLVMInitialExecTLSModel,
368 LLVMLocalExecTLSModel
369} LLVMThreadLocalMode;
370
Carlo Kokda0ac722013-04-23 13:45:37 +0000371typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000372 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
373 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
374 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000375 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
376 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000377 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000378 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
379 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000380 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000381 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
382 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000383 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000384 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
385 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000386 operations which both read and write
387 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000388 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
389 for loads and Release
390 semantics for stores.
391 Additionally, it guarantees
392 that a total ordering exists
393 between all
394 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000395 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000396} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000397
Carlo Kokda0ac722013-04-23 13:45:37 +0000398typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000399 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
400 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
401 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
402 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
403 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
404 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
405 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
406 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000407 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000408 the old one */
409 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000410 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000411 the old one */
412 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000413 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000414 the old one */
415 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000416 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000417 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000418} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000419
Tom Stellard1580dc72014-04-16 17:45:04 +0000420typedef enum {
421 LLVMDSError,
422 LLVMDSWarning,
423 LLVMDSRemark,
424 LLVMDSNote
425} LLVMDiagnosticSeverity;
426
Gregory Szorc34c863a2012-03-21 03:54:29 +0000427/**
428 * @}
429 */
430
Nick Lewycky0db26542011-05-15 07:20:34 +0000431void LLVMInitializeCore(LLVMPassRegistryRef R);
432
Duncan Sands1cba0a82013-02-17 16:35:51 +0000433/** Deallocate and destroy all ManagedStatic variables.
434 @see llvm::llvm_shutdown
435 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000436void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000437
Gordon Henriksen76a03742007-09-18 03:18:57 +0000438
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000439/*===-- Error handling ----------------------------------------------------===*/
440
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000441char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000442void LLVMDisposeMessage(char *Message);
443
Filip Pizloa535b142013-10-17 01:38:28 +0000444typedef void (*LLVMFatalErrorHandler)(const char *Reason);
445
446/**
447 * Install a fatal error handler. By default, if LLVM detects a fatal error, it
448 * will call exit(1). This may not be appropriate in many contexts. For example,
449 * doing exit(1) will bypass many crash reporting/tracing system tools. This
450 * function allows you to install a callback that will be invoked prior to the
451 * call to exit(1).
452 */
453void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
454
455/**
456 * Reset the fatal error handler. This resets LLVM's fatal error handling
457 * behavior to the default.
458 */
459void LLVMResetFatalErrorHandler(void);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000460
Gregory Szorc34c863a2012-03-21 03:54:29 +0000461/**
Filip Pizloc10ca902013-11-04 02:22:25 +0000462 * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
463 * signals and prints which component of LLVM you were in at the time if the
464 * crash.
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000465 */
Filip Pizloc10ca902013-11-04 02:22:25 +0000466void LLVMEnablePrettyStackTrace(void);
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000467
468/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000469 * @defgroup LLVMCCoreContext Contexts
470 *
471 * Contexts are execution states for the core LLVM IR system.
472 *
473 * Most types are tied to a context instance. Multiple contexts can
474 * exist simultaneously. A single context is not thread safe. However,
475 * different contexts can execute on different threads simultaneously.
476 *
477 * @{
478 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000479
Tom Stellard1580dc72014-04-16 17:45:04 +0000480typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
481
Gregory Szorc34c863a2012-03-21 03:54:29 +0000482/**
483 * Create a new context.
484 *
485 * Every call to this function should be paired with a call to
486 * LLVMContextDispose() or the context will leak memory.
487 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000488LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000489
490/**
491 * Obtain the global context instance.
492 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000493LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000494
495/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000496 * Set the diagnostic handler for this context.
497 */
498void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
499 LLVMDiagnosticHandler Handler,
500 void *DiagnosticContext);
501
502/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000503 * Destroy a context instance.
504 *
505 * This should be called for every call to LLVMContextCreate() or memory
506 * will be leaked.
507 */
Owen Anderson6773d382009-07-01 16:58:40 +0000508void LLVMContextDispose(LLVMContextRef C);
509
Tom Stellard1580dc72014-04-16 17:45:04 +0000510/**
511 * Return a string representation of the DiagnosticInfo. Use
512 * LLVMDisposeMessage to free the string.
513 *
514 * @see DiagnosticInfo::print()
515 */
516char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
517
518/**
519 * Return an enum LLVMDiagnosticSeverity.
520 *
521 * @see DiagnosticInfo::getSeverity()
522 */
523LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
524
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000525unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
526 unsigned SLen);
527unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
528
Juergen Ributzka49892552014-04-28 18:19:25 +0000529LLVMPassRunListenerRef LLVMAddPassRunListener(LLVMContextRef,
530 LLVMPassRunListenerHandlerTy);
531void LLVMRemovePassRunListener(LLVMContextRef, LLVMPassRunListenerRef);
532
Gregory Szorc34c863a2012-03-21 03:54:29 +0000533/**
534 * @}
535 */
536
Gregory Szorc52d26602012-03-21 07:28:27 +0000537/**
538 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000539 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000540 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000541 * module is effectively a translation unit or a collection of
542 * translation units merged together.
543 *
544 * @{
545 */
546
Gregory Szorc34c863a2012-03-21 03:54:29 +0000547/**
548 * Create a new, empty module in the global context.
549 *
550 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
551 * LLVMGetGlobalContext() as the context parameter.
552 *
553 * Every invocation should be paired with LLVMDisposeModule() or memory
554 * will be leaked.
555 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000556LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000557
558/**
559 * Create a new, empty module in a specific context.
560 *
561 * Every invocation should be paired with LLVMDisposeModule() or memory
562 * will be leaked.
563 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000564LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
565 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000566
Gregory Szorc34c863a2012-03-21 03:54:29 +0000567/**
568 * Destroy a module instance.
569 *
570 * This must be called for every created module or memory will be
571 * leaked.
572 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000573void LLVMDisposeModule(LLVMModuleRef M);
574
Gregory Szorc34c863a2012-03-21 03:54:29 +0000575/**
576 * Obtain the data layout for a module.
577 *
578 * @see Module::getDataLayout()
579 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000580const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000581
582/**
583 * Set the data layout for a module.
584 *
585 * @see Module::setDataLayout()
586 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000587void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
588
Gregory Szorc34c863a2012-03-21 03:54:29 +0000589/**
590 * Obtain the target triple for a module.
591 *
592 * @see Module::getTargetTriple()
593 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000594const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000595
596/**
597 * Set the target triple for a module.
598 *
599 * @see Module::setTargetTriple()
600 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000601void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
602
Gregory Szorc34c863a2012-03-21 03:54:29 +0000603/**
604 * Dump a representation of a module to stderr.
605 *
606 * @see Module::dump()
607 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000608void LLVMDumpModule(LLVMModuleRef M);
609
Gregory Szorc34c863a2012-03-21 03:54:29 +0000610/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000611 * Print a representation of a module to a file. The ErrorMessage needs to be
612 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
613 *
614 * @see Module::print()
615 */
616LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
617 char **ErrorMessage);
618
619/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000620 * Return a string representation of the module. Use
621 * LLVMDisposeMessage to free the string.
622 *
623 * @see Module::print()
624 */
625char *LLVMPrintModuleToString(LLVMModuleRef M);
626
627/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000628 * Set inline assembly for a module.
629 *
630 * @see Module::setModuleInlineAsm()
631 */
Chris Lattner26941452010-04-10 17:52:58 +0000632void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000633
Gregory Szorc34c863a2012-03-21 03:54:29 +0000634/**
635 * Obtain the context to which this module is associated.
636 *
637 * @see Module::getContext()
638 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000639LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
640
Gregory Szorc34c863a2012-03-21 03:54:29 +0000641/**
642 * Obtain a Type from a module by its registered name.
643 */
644LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000645
Gregory Szorc34c863a2012-03-21 03:54:29 +0000646/**
647 * Obtain the number of operands for named metadata in a module.
648 *
649 * @see llvm::Module::getNamedMetadata()
650 */
651unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
652
653/**
654 * Obtain the named metadata operands for a module.
655 *
656 * The passed LLVMValueRef pointer should refer to an array of
657 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
658 * array will be populated with the LLVMValueRef instances. Each
659 * instance corresponds to a llvm::MDNode.
660 *
661 * @see llvm::Module::getNamedMetadata()
662 * @see llvm::MDNode::getOperand()
663 */
664void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
665
666/**
667 * Add an operand to named metadata.
668 *
669 * @see llvm::Module::getNamedMetadata()
670 * @see llvm::MDNode::addOperand()
671 */
672void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
673 LLVMValueRef Val);
674
Gregory Szorc52d26602012-03-21 07:28:27 +0000675/**
676 * Add a function to a module under a specified name.
677 *
678 * @see llvm::Function::Create()
679 */
680LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
681 LLVMTypeRef FunctionTy);
682
683/**
684 * Obtain a Function value from a Module by its name.
685 *
686 * The returned value corresponds to a llvm::Function value.
687 *
688 * @see llvm::Module::getFunction()
689 */
690LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
691
692/**
693 * Obtain an iterator to the first Function in a Module.
694 *
695 * @see llvm::Module::begin()
696 */
697LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
698
699/**
700 * Obtain an iterator to the last Function in a Module.
701 *
702 * @see llvm::Module::end()
703 */
704LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
705
706/**
707 * Advance a Function iterator to the next Function.
708 *
709 * Returns NULL if the iterator was already at the end and there are no more
710 * functions.
711 */
712LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
713
714/**
715 * Decrement a Function iterator to the previous Function.
716 *
717 * Returns NULL if the iterator was already at the beginning and there are
718 * no previous functions.
719 */
720LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000721
722/**
723 * @}
724 */
725
726/**
727 * @defgroup LLVMCCoreType Types
728 *
729 * Types represent the type of a value.
730 *
731 * Types are associated with a context instance. The context internally
732 * deduplicates types so there is only 1 instance of a specific type
733 * alive at a time. In other words, a unique type is shared among all
734 * consumers within a context.
735 *
736 * A Type in the C API corresponds to llvm::Type.
737 *
738 * Types have the following hierarchy:
739 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000740 * types:
741 * integer type
742 * real type
743 * function type
744 * sequence types:
745 * array type
746 * pointer type
747 * vector type
748 * void type
749 * label type
750 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000751 *
752 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000753 */
754
Gregory Szorc34c863a2012-03-21 03:54:29 +0000755/**
756 * Obtain the enumerated type of a Type instance.
757 *
758 * @see llvm::Type:getTypeID()
759 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000760LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000761
762/**
763 * Whether the type has a known size.
764 *
765 * Things that don't have a size are abstract types, labels, and void.a
766 *
767 * @see llvm::Type::isSized()
768 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000769LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000770
Gregory Szorc34c863a2012-03-21 03:54:29 +0000771/**
772 * Obtain the context to which this type instance is associated.
773 *
774 * @see llvm::Type::getContext()
775 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000776LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
777
Gregory Szorc34c863a2012-03-21 03:54:29 +0000778/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000779 * Dump a representation of a type to stderr.
780 *
781 * @see llvm::Type::dump()
782 */
783void LLVMDumpType(LLVMTypeRef Val);
784
785/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000786 * Return a string representation of the type. Use
787 * LLVMDisposeMessage to free the string.
788 *
789 * @see llvm::Type::print()
790 */
791char *LLVMPrintTypeToString(LLVMTypeRef Val);
792
793/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000794 * @defgroup LLVMCCoreTypeInt Integer Types
795 *
796 * Functions in this section operate on integer types.
797 *
798 * @{
799 */
800
801/**
802 * Obtain an integer type from a context with specified bit width.
803 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000804LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
805LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
806LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
807LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
808LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
809LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
810
Gregory Szorc34c863a2012-03-21 03:54:29 +0000811/**
812 * Obtain an integer type from the global context with a specified bit
813 * width.
814 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000815LLVMTypeRef LLVMInt1Type(void);
816LLVMTypeRef LLVMInt8Type(void);
817LLVMTypeRef LLVMInt16Type(void);
818LLVMTypeRef LLVMInt32Type(void);
819LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000820LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000821unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000822
Gregory Szorc34c863a2012-03-21 03:54:29 +0000823/**
824 * @}
825 */
826
827/**
828 * @defgroup LLVMCCoreTypeFloat Floating Point Types
829 *
830 * @{
831 */
832
833/**
834 * Obtain a 16-bit floating point type from a context.
835 */
Dan Gohman518cda42011-12-17 00:04:22 +0000836LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000837
838/**
839 * Obtain a 32-bit floating point type from a context.
840 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000841LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000842
843/**
844 * Obtain a 64-bit floating point type from a context.
845 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000846LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000847
848/**
849 * Obtain a 80-bit floating point type (X87) from a context.
850 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000851LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000852
853/**
854 * Obtain a 128-bit floating point type (112-bit mantissa) from a
855 * context.
856 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000857LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000858
859/**
860 * Obtain a 128-bit floating point type (two 64-bits) from a context.
861 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000862LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
863
Gregory Szorc34c863a2012-03-21 03:54:29 +0000864/**
865 * Obtain a floating point type from the global context.
866 *
867 * These map to the functions in this group of the same name.
868 */
Dan Gohman518cda42011-12-17 00:04:22 +0000869LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000870LLVMTypeRef LLVMFloatType(void);
871LLVMTypeRef LLVMDoubleType(void);
872LLVMTypeRef LLVMX86FP80Type(void);
873LLVMTypeRef LLVMFP128Type(void);
874LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000875
Gregory Szorc34c863a2012-03-21 03:54:29 +0000876/**
877 * @}
878 */
879
880/**
881 * @defgroup LLVMCCoreTypeFunction Function Types
882 *
883 * @{
884 */
885
886/**
887 * Obtain a function type consisting of a specified signature.
888 *
889 * The function is defined as a tuple of a return Type, a list of
890 * parameter types, and whether the function is variadic.
891 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000892LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
893 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000894 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000895
896/**
897 * Returns whether a function type is variadic.
898 */
Chris Lattner25963c62010-01-09 22:27:07 +0000899LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000900
901/**
902 * Obtain the Type this function Type returns.
903 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000904LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000905
906/**
907 * Obtain the number of parameters this function accepts.
908 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000909unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000910
911/**
912 * Obtain the types of a function's parameters.
913 *
914 * The Dest parameter should point to a pre-allocated array of
915 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
916 * first LLVMCountParamTypes() entries in the array will be populated
917 * with LLVMTypeRef instances.
918 *
919 * @param FunctionTy The function type to operate on.
920 * @param Dest Memory address of an array to be filled with result.
921 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000922void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000923
Gregory Szorc34c863a2012-03-21 03:54:29 +0000924/**
925 * @}
926 */
927
928/**
929 * @defgroup LLVMCCoreTypeStruct Structure Types
930 *
931 * These functions relate to LLVMTypeRef instances.
932 *
933 * @see llvm::StructType
934 *
935 * @{
936 */
937
938/**
939 * Create a new structure type in a context.
940 *
941 * A structure is specified by a list of inner elements/types and
942 * whether these can be packed together.
943 *
944 * @see llvm::StructType::create()
945 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000946LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000947 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000948
949/**
950 * Create a new structure type in the global context.
951 *
952 * @see llvm::StructType::create()
953 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000954LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000955 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000956
957/**
958 * Create an empty structure in a context having a specified name.
959 *
960 * @see llvm::StructType::create()
961 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000962LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000963
964/**
965 * Obtain the name of a structure.
966 *
967 * @see llvm::StructType::getName()
968 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000969const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000970
971/**
972 * Set the contents of a structure type.
973 *
974 * @see llvm::StructType::setBody()
975 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000976void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
977 unsigned ElementCount, LLVMBool Packed);
978
Gregory Szorc34c863a2012-03-21 03:54:29 +0000979/**
980 * Get the number of elements defined inside the structure.
981 *
982 * @see llvm::StructType::getNumElements()
983 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000984unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000985
986/**
987 * Get the elements within a structure.
988 *
989 * The function is passed the address of a pre-allocated array of
990 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
991 * invocation, this array will be populated with the structure's
992 * elements. The objects in the destination array will have a lifetime
993 * of the structure type itself, which is the lifetime of the context it
994 * is contained in.
995 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000996void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000997
998/**
999 * Determine whether a structure is packed.
1000 *
1001 * @see llvm::StructType::isPacked()
1002 */
Chris Lattner25963c62010-01-09 22:27:07 +00001003LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001004
1005/**
1006 * Determine whether a structure is opaque.
1007 *
1008 * @see llvm::StructType::isOpaque()
1009 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001010LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1011
Gregory Szorc34c863a2012-03-21 03:54:29 +00001012/**
1013 * @}
1014 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001015
Gregory Szorc34c863a2012-03-21 03:54:29 +00001016
1017/**
1018 * @defgroup LLVMCCoreTypeSequential Sequential Types
1019 *
1020 * Sequential types represents "arrays" of types. This is a super class
1021 * for array, vector, and pointer types.
1022 *
1023 * @{
1024 */
1025
1026/**
1027 * Obtain the type of elements within a sequential type.
1028 *
1029 * This works on array, vector, and pointer types.
1030 *
1031 * @see llvm::SequentialType::getElementType()
1032 */
1033LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1034
1035/**
1036 * Create a fixed size array type that refers to a specific type.
1037 *
1038 * The created type will exist in the context that its element type
1039 * exists in.
1040 *
1041 * @see llvm::ArrayType::get()
1042 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001043LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001044
1045/**
1046 * Obtain the length of an array type.
1047 *
1048 * This only works on types that represent arrays.
1049 *
1050 * @see llvm::ArrayType::getNumElements()
1051 */
1052unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1053
1054/**
1055 * Create a pointer type that points to a defined type.
1056 *
1057 * The created type will exist in the context that its pointee type
1058 * exists in.
1059 *
1060 * @see llvm::PointerType::get()
1061 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001062LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001063
1064/**
1065 * Obtain the address space of a pointer type.
1066 *
1067 * This only works on types that represent pointers.
1068 *
1069 * @see llvm::PointerType::getAddressSpace()
1070 */
1071unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1072
1073/**
1074 * Create a vector type that contains a defined type and has a specific
1075 * number of elements.
1076 *
1077 * The created type will exist in the context thats its element type
1078 * exists in.
1079 *
1080 * @see llvm::VectorType::get()
1081 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001082LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001083
Gregory Szorc34c863a2012-03-21 03:54:29 +00001084/**
1085 * Obtain the number of elements in a vector type.
1086 *
1087 * This only works on types that represent vectors.
1088 *
1089 * @see llvm::VectorType::getNumElements()
1090 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001091unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1092
Gregory Szorc34c863a2012-03-21 03:54:29 +00001093/**
1094 * @}
1095 */
1096
1097/**
1098 * @defgroup LLVMCCoreTypeOther Other Types
1099 *
1100 * @{
1101 */
1102
1103/**
1104 * Create a void type in a context.
1105 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001106LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001107
1108/**
1109 * Create a label type in a context.
1110 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001111LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001112
1113/**
1114 * Create a X86 MMX type in a context.
1115 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001116LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001117
Gregory Szorc34c863a2012-03-21 03:54:29 +00001118/**
1119 * These are similar to the above functions except they operate on the
1120 * global context.
1121 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001122LLVMTypeRef LLVMVoidType(void);
1123LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001124LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001125
Gregory Szorc34c863a2012-03-21 03:54:29 +00001126/**
1127 * @}
1128 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001129
Gregory Szorc34c863a2012-03-21 03:54:29 +00001130/**
1131 * @}
1132 */
1133
1134/**
1135 * @defgroup LLVMCCoreValues Values
1136 *
1137 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001138 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001139 *
1140 * LLVMValueRef essentially represents llvm::Value. There is a rich
1141 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001142 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001143 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001144 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001145 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1146 * functions are defined by a macro, so it isn't obvious which are
1147 * available by looking at the Doxygen source code. Instead, look at the
1148 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1149 * of value names given. These value names also correspond to classes in
1150 * the llvm::Value hierarchy.
1151 *
1152 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001153 */
1154
Gordon Henriksen29e38942008-12-19 18:39:45 +00001155#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1156 macro(Argument) \
1157 macro(BasicBlock) \
1158 macro(InlineAsm) \
Torok Edwind09b7572011-10-14 20:37:56 +00001159 macro(MDNode) \
1160 macro(MDString) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001161 macro(User) \
1162 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001163 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001164 macro(ConstantAggregateZero) \
1165 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001166 macro(ConstantDataSequential) \
1167 macro(ConstantDataArray) \
1168 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001169 macro(ConstantExpr) \
1170 macro(ConstantFP) \
1171 macro(ConstantInt) \
1172 macro(ConstantPointerNull) \
1173 macro(ConstantStruct) \
1174 macro(ConstantVector) \
1175 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001176 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001177 macro(GlobalObject) \
1178 macro(Function) \
1179 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001180 macro(UndefValue) \
1181 macro(Instruction) \
1182 macro(BinaryOperator) \
1183 macro(CallInst) \
1184 macro(IntrinsicInst) \
1185 macro(DbgInfoIntrinsic) \
1186 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001187 macro(MemIntrinsic) \
1188 macro(MemCpyInst) \
1189 macro(MemMoveInst) \
1190 macro(MemSetInst) \
1191 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001192 macro(FCmpInst) \
1193 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001194 macro(ExtractElementInst) \
1195 macro(GetElementPtrInst) \
1196 macro(InsertElementInst) \
1197 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001198 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001199 macro(PHINode) \
1200 macro(SelectInst) \
1201 macro(ShuffleVectorInst) \
1202 macro(StoreInst) \
1203 macro(TerminatorInst) \
1204 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001205 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001206 macro(InvokeInst) \
1207 macro(ReturnInst) \
1208 macro(SwitchInst) \
1209 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001210 macro(ResumeInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001211 macro(UnaryInstruction) \
1212 macro(AllocaInst) \
1213 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001214 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001215 macro(BitCastInst) \
1216 macro(FPExtInst) \
1217 macro(FPToSIInst) \
1218 macro(FPToUIInst) \
1219 macro(FPTruncInst) \
1220 macro(IntToPtrInst) \
1221 macro(PtrToIntInst) \
1222 macro(SExtInst) \
1223 macro(SIToFPInst) \
1224 macro(TruncInst) \
1225 macro(UIToFPInst) \
1226 macro(ZExtInst) \
1227 macro(ExtractValueInst) \
1228 macro(LoadInst) \
1229 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001230
Gregory Szorc34c863a2012-03-21 03:54:29 +00001231/**
1232 * @defgroup LLVMCCoreValueGeneral General APIs
1233 *
1234 * Functions in this section work on all LLVMValueRef instances,
1235 * regardless of their sub-type. They correspond to functions available
1236 * on llvm::Value.
1237 *
1238 * @{
1239 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001240
Gregory Szorc34c863a2012-03-21 03:54:29 +00001241/**
1242 * Obtain the type of a value.
1243 *
1244 * @see llvm::Value::getType()
1245 */
1246LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1247
1248/**
1249 * Obtain the string name of a value.
1250 *
1251 * @see llvm::Value::getName()
1252 */
1253const char *LLVMGetValueName(LLVMValueRef Val);
1254
1255/**
1256 * Set the string name of a value.
1257 *
1258 * @see llvm::Value::setName()
1259 */
1260void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1261
1262/**
1263 * Dump a representation of a value to stderr.
1264 *
1265 * @see llvm::Value::dump()
1266 */
1267void LLVMDumpValue(LLVMValueRef Val);
1268
1269/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001270 * Return a string representation of the value. Use
1271 * LLVMDisposeMessage to free the string.
1272 *
1273 * @see llvm::Value::print()
1274 */
1275char *LLVMPrintValueToString(LLVMValueRef Val);
1276
1277/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001278 * Replace all uses of a value with another one.
1279 *
1280 * @see llvm::Value::replaceAllUsesWith()
1281 */
1282void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1283
1284/**
1285 * Determine whether the specified constant instance is constant.
1286 */
1287LLVMBool LLVMIsConstant(LLVMValueRef Val);
1288
1289/**
1290 * Determine whether a value instance is undefined.
1291 */
1292LLVMBool LLVMIsUndef(LLVMValueRef Val);
1293
1294/**
1295 * Convert value instances between types.
1296 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001297 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001298 * series of functions allows you to cast an instance to a specific
1299 * type.
1300 *
1301 * If the cast is not valid for the specified type, NULL is returned.
1302 *
1303 * @see llvm::dyn_cast_or_null<>
1304 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001305#define LLVM_DECLARE_VALUE_CAST(name) \
1306 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1307LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1308
Gregory Szorc34c863a2012-03-21 03:54:29 +00001309/**
1310 * @}
1311 */
1312
1313/**
1314 * @defgroup LLVMCCoreValueUses Usage
1315 *
1316 * This module defines functions that allow you to inspect the uses of a
1317 * LLVMValueRef.
1318 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001319 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001320 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1321 * llvm::User and llvm::Value.
1322 *
1323 * @{
1324 */
1325
1326/**
1327 * Obtain the first use of a value.
1328 *
1329 * Uses are obtained in an iterator fashion. First, call this function
1330 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001331 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001332 * LLVMGetNextUse() returns NULL.
1333 *
1334 * @see llvm::Value::use_begin()
1335 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001336LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001337
1338/**
1339 * Obtain the next use of a value.
1340 *
1341 * This effectively advances the iterator. It returns NULL if you are on
1342 * the final use and no more are available.
1343 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001344LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001345
1346/**
1347 * Obtain the user value for a user.
1348 *
1349 * The returned value corresponds to a llvm::User type.
1350 *
1351 * @see llvm::Use::getUser()
1352 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001353LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001354
1355/**
1356 * Obtain the value this use corresponds to.
1357 *
1358 * @see llvm::Use::get().
1359 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001360LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001361
Gregory Szorc34c863a2012-03-21 03:54:29 +00001362/**
1363 * @}
1364 */
1365
1366/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001367 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001368 *
1369 * Function in this group pertain to LLVMValueRef instances that descent
1370 * from llvm::User. This includes constants, instructions, and
1371 * operators.
1372 *
1373 * @{
1374 */
1375
1376/**
1377 * Obtain an operand at a specific index in a llvm::User value.
1378 *
1379 * @see llvm::User::getOperand()
1380 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001381LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001382
1383/**
1384 * Set an operand at a specific index in a llvm::User value.
1385 *
1386 * @see llvm::User::setOperand()
1387 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001388void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001389
1390/**
1391 * Obtain the number of operands in a llvm::User value.
1392 *
1393 * @see llvm::User::getNumOperands()
1394 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001395int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001396
Gregory Szorc34c863a2012-03-21 03:54:29 +00001397/**
1398 * @}
1399 */
1400
1401/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001402 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001403 *
1404 * This section contains APIs for interacting with LLVMValueRef that
1405 * correspond to llvm::Constant instances.
1406 *
1407 * These functions will work for any LLVMValueRef in the llvm::Constant
1408 * class hierarchy.
1409 *
1410 * @{
1411 */
1412
1413/**
1414 * Obtain a constant value referring to the null instance of a type.
1415 *
1416 * @see llvm::Constant::getNullValue()
1417 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001418LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001419
1420/**
1421 * Obtain a constant value referring to the instance of a type
1422 * consisting of all ones.
1423 *
1424 * This is only valid for integer types.
1425 *
1426 * @see llvm::Constant::getAllOnesValue()
1427 */
1428LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1429
1430/**
1431 * Obtain a constant value referring to an undefined value of a type.
1432 *
1433 * @see llvm::UndefValue::get()
1434 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001435LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001436
1437/**
1438 * Determine whether a value instance is null.
1439 *
1440 * @see llvm::Constant::isNullValue()
1441 */
Chris Lattner25963c62010-01-09 22:27:07 +00001442LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001443
1444/**
1445 * Obtain a constant that is a constant pointer pointing to NULL for a
1446 * specified type.
1447 */
Chris Lattner7f318242009-07-06 17:29:59 +00001448LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001449
Gregory Szorc34c863a2012-03-21 03:54:29 +00001450/**
1451 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1452 *
1453 * Functions in this group model LLVMValueRef instances that correspond
1454 * to constants referring to scalar types.
1455 *
1456 * For integer types, the LLVMTypeRef parameter should correspond to a
1457 * llvm::IntegerType instance and the returned LLVMValueRef will
1458 * correspond to a llvm::ConstantInt.
1459 *
1460 * For floating point types, the LLVMTypeRef returned corresponds to a
1461 * llvm::ConstantFP.
1462 *
1463 * @{
1464 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001465
Gregory Szorc34c863a2012-03-21 03:54:29 +00001466/**
1467 * Obtain a constant value for an integer type.
1468 *
1469 * The returned value corresponds to a llvm::ConstantInt.
1470 *
1471 * @see llvm::ConstantInt::get()
1472 *
1473 * @param IntTy Integer type to obtain value of.
1474 * @param N The value the returned instance should refer to.
1475 * @param SignExtend Whether to sign extend the produced value.
1476 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001477LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001478 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001479
1480/**
1481 * Obtain a constant value for an integer of arbitrary precision.
1482 *
1483 * @see llvm::ConstantInt::get()
1484 */
Chris Lattner4329e072010-11-23 02:47:22 +00001485LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1486 unsigned NumWords,
1487 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001488
1489/**
1490 * Obtain a constant value for an integer parsed from a string.
1491 *
1492 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1493 * string's length is available, it is preferred to call that function
1494 * instead.
1495 *
1496 * @see llvm::ConstantInt::get()
1497 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001498LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1499 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001500
1501/**
1502 * Obtain a constant value for an integer parsed from a string with
1503 * specified length.
1504 *
1505 * @see llvm::ConstantInt::get()
1506 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001507LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1508 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001509
1510/**
1511 * Obtain a constant value referring to a double floating point value.
1512 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001513LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001514
1515/**
1516 * Obtain a constant for a floating point value parsed from a string.
1517 *
1518 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1519 * should be used if the input string's length is known.
1520 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001521LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001522
1523/**
1524 * Obtain a constant for a floating point value parsed from a string.
1525 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001526LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1527 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001528
1529/**
1530 * Obtain the zero extended value for an integer constant value.
1531 *
1532 * @see llvm::ConstantInt::getZExtValue()
1533 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001534unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001535
1536/**
1537 * Obtain the sign extended value for an integer constant value.
1538 *
1539 * @see llvm::ConstantInt::getSExtValue()
1540 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001541long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001542
Gregory Szorc34c863a2012-03-21 03:54:29 +00001543/**
1544 * @}
1545 */
1546
1547/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001548 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1549 *
1550 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001551 *
1552 * @{
1553 */
1554
1555/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001556 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001557 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001558 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001559 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001560LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001561 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001562
1563/**
1564 * Create a ConstantDataSequential with string content in the global context.
1565 *
1566 * This is the same as LLVMConstStringInContext except it operates on the
1567 * global context.
1568 *
1569 * @see LLVMConstStringInContext()
1570 * @see llvm::ConstantDataArray::getString()
1571 */
1572LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1573 LLVMBool DontNullTerminate);
1574
1575/**
1576 * Create an anonymous ConstantStruct with the specified values.
1577 *
1578 * @see llvm::ConstantStruct::getAnon()
1579 */
1580LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001581 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001582 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001583
Gregory Szorc52d26602012-03-21 07:28:27 +00001584/**
1585 * Create a ConstantStruct in the global Context.
1586 *
1587 * This is the same as LLVMConstStructInContext except it operates on the
1588 * global Context.
1589 *
1590 * @see LLVMConstStructInContext()
1591 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001592LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001593 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001594
1595/**
1596 * Create a ConstantArray from values.
1597 *
1598 * @see llvm::ConstantArray::get()
1599 */
1600LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1601 LLVMValueRef *ConstantVals, unsigned Length);
1602
1603/**
1604 * Create a non-anonymous ConstantStruct from values.
1605 *
1606 * @see llvm::ConstantStruct::get()
1607 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001608LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1609 LLVMValueRef *ConstantVals,
1610 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001611
1612/**
1613 * Create a ConstantVector from values.
1614 *
1615 * @see llvm::ConstantVector::get()
1616 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001617LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001618
Gregory Szorc52d26602012-03-21 07:28:27 +00001619/**
1620 * @}
1621 */
1622
1623/**
1624 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1625 *
1626 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1627 *
1628 * @see llvm::ConstantExpr.
1629 *
1630 * @{
1631 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001632LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001633LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001634LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1635LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001636LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1637LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001638LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001639LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1640LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001641LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001642LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001643LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001644LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001645LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1646LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001647LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001648LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001649LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1650LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001651LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001652LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1653LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001654LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001655LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1656LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1657LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1658LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1659LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1660LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1661LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1662LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1663 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1664LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1665 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1666LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1667LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1668LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1669LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1670 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001671LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1672 LLVMValueRef *ConstantIndices,
1673 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001674LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1675LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1676LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1677LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1678LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1679LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1680LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1681LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1682LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1683LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1684LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1685LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001686LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001687LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1688 LLVMTypeRef ToType);
1689LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1690 LLVMTypeRef ToType);
1691LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1692 LLVMTypeRef ToType);
1693LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1694 LLVMTypeRef ToType);
1695LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001696 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001697LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001698LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1699 LLVMValueRef ConstantIfTrue,
1700 LLVMValueRef ConstantIfFalse);
1701LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1702 LLVMValueRef IndexConstant);
1703LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1704 LLVMValueRef ElementValueConstant,
1705 LLVMValueRef IndexConstant);
1706LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1707 LLVMValueRef VectorBConstant,
1708 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001709LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1710 unsigned NumIdx);
1711LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1712 LLVMValueRef ElementValueConstant,
1713 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001714LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001715 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001716 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001717LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001718
Gregory Szorc52d26602012-03-21 07:28:27 +00001719/**
1720 * @}
1721 */
1722
1723/**
1724 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1725 *
1726 * This group contains functions that operate on global values. Functions in
1727 * this group relate to functions in the llvm::GlobalValue class tree.
1728 *
1729 * @see llvm::GlobalValue
1730 *
1731 * @{
1732 */
1733
Gordon Henriksen265f7802008-03-19 01:11:35 +00001734LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001735LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001736LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1737void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1738const char *LLVMGetSection(LLVMValueRef Global);
1739void LLVMSetSection(LLVMValueRef Global, const char *Section);
1740LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1741void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001742LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1743void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001744LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1745void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001746
1747/**
1748 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1749 *
1750 * Functions in this group only apply to values with alignment, i.e.
1751 * global variables, load and store instructions.
1752 */
1753
1754/**
1755 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001756 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001757 * @see llvm::LoadInst::getAlignment()
1758 * @see llvm::StoreInst::getAlignment()
1759 * @see llvm::GlobalValue::getAlignment()
1760 */
1761unsigned LLVMGetAlignment(LLVMValueRef V);
1762
1763/**
1764 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001765 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001766 * @see llvm::LoadInst::setAlignment()
1767 * @see llvm::StoreInst::setAlignment()
1768 * @see llvm::GlobalValue::setAlignment()
1769 */
1770void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1771
1772/**
1773 * @}
1774 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001775
Gregory Szorc52d26602012-03-21 07:28:27 +00001776/**
1777 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1778 *
1779 * This group contains functions that operate on global variable values.
1780 *
1781 * @see llvm::GlobalVariable
1782 *
1783 * @{
1784 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001785LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001786LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1787 const char *Name,
1788 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001789LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001790LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1791LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1792LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1793LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001794void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001795LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1796void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001797LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1798void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1799LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1800void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001801LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1802void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1803LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1804void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001805
Gregory Szorc52d26602012-03-21 07:28:27 +00001806/**
1807 * @}
1808 */
1809
1810/**
1811 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1812 *
1813 * This group contains function that operate on global alias values.
1814 *
1815 * @see llvm::GlobalAlias
1816 *
1817 * @{
1818 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001819LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1820 const char *Name);
1821
Gregory Szorc34c863a2012-03-21 03:54:29 +00001822/**
1823 * @}
1824 */
1825
1826/**
1827 * @defgroup LLVMCCoreValueFunction Function values
1828 *
1829 * Functions in this group operate on LLVMValueRef instances that
1830 * correspond to llvm::Function instances.
1831 *
1832 * @see llvm::Function
1833 *
1834 * @{
1835 */
1836
1837/**
1838 * Remove a function from its containing module and deletes it.
1839 *
1840 * @see llvm::Function::eraseFromParent()
1841 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001842void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001843
1844/**
1845 * Obtain the ID number from a function instance.
1846 *
1847 * @see llvm::Function::getIntrinsicID()
1848 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001849unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001850
1851/**
1852 * Obtain the calling function of a function.
1853 *
1854 * The returned value corresponds to the LLVMCallConv enumeration.
1855 *
1856 * @see llvm::Function::getCallingConv()
1857 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001858unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001859
1860/**
1861 * Set the calling convention of a function.
1862 *
1863 * @see llvm::Function::setCallingConv()
1864 *
1865 * @param Fn Function to operate on
1866 * @param CC LLVMCallConv to set calling convention to
1867 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001868void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001869
1870/**
1871 * Obtain the name of the garbage collector to use during code
1872 * generation.
1873 *
1874 * @see llvm::Function::getGC()
1875 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001876const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001877
1878/**
1879 * Define the garbage collector to use during code generation.
1880 *
1881 * @see llvm::Function::setGC()
1882 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001883void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001884
1885/**
1886 * Add an attribute to a function.
1887 *
1888 * @see llvm::Function::addAttribute()
1889 */
Duncan Sands7374a012009-05-06 12:21:17 +00001890void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001891
1892/**
Tom Stellarde8f35e12013-04-16 23:12:43 +00001893 * Add a target-dependent attribute to a fuction
1894 * @see llvm::AttrBuilder::addAttribute()
1895 */
1896void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1897 const char *V);
1898
1899/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001900 * Obtain an attribute from a function.
1901 *
1902 * @see llvm::Function::getAttributes()
1903 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001904LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001905
1906/**
1907 * Remove an attribute from a function.
1908 */
Duncan Sands7374a012009-05-06 12:21:17 +00001909void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001910
Gregory Szorc34c863a2012-03-21 03:54:29 +00001911/**
1912 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1913 *
1914 * Functions in this group relate to arguments/parameters on functions.
1915 *
1916 * Functions in this group expect LLVMValueRef instances that correspond
1917 * to llvm::Function instances.
1918 *
1919 * @{
1920 */
1921
1922/**
1923 * Obtain the number of parameters in a function.
1924 *
1925 * @see llvm::Function::arg_size()
1926 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001927unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001928
1929/**
1930 * Obtain the parameters in a function.
1931 *
1932 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1933 * at least LLVMCountParams() long. This array will be filled with
1934 * LLVMValueRef instances which correspond to the parameters the
1935 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1936 * instance.
1937 *
1938 * @see llvm::Function::arg_begin()
1939 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001940void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001941
1942/**
1943 * Obtain the parameter at the specified index.
1944 *
1945 * Parameters are indexed from 0.
1946 *
1947 * @see llvm::Function::arg_begin()
1948 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001949LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001950
1951/**
1952 * Obtain the function to which this argument belongs.
1953 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001954 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00001955 * that corresponds to a llvm::Attribute.
1956 *
1957 * The returned LLVMValueRef is the llvm::Function to which this
1958 * argument belongs.
1959 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001960LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001961
1962/**
1963 * Obtain the first parameter to a function.
1964 *
1965 * @see llvm::Function::arg_begin()
1966 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001967LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001968
1969/**
1970 * Obtain the last parameter to a function.
1971 *
1972 * @see llvm::Function::arg_end()
1973 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001974LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001975
1976/**
1977 * Obtain the next parameter to a function.
1978 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001979 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00001980 * actually a wrapped iterator) and obtains the next parameter from the
1981 * underlying iterator.
1982 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001983LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001984
1985/**
1986 * Obtain the previous parameter to a function.
1987 *
1988 * This is the opposite of LLVMGetNextParam().
1989 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001990LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001991
1992/**
1993 * Add an attribute to a function argument.
1994 *
1995 * @see llvm::Argument::addAttr()
1996 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001997void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001998
1999/**
2000 * Remove an attribute from a function argument.
2001 *
2002 * @see llvm::Argument::removeAttr()
2003 */
Devang Patel4c758ea2008-09-25 21:00:45 +00002004void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002005
2006/**
2007 * Get an attribute from a function argument.
2008 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002009LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002010
2011/**
2012 * Set the alignment for a function parameter.
2013 *
2014 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002015 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002016 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002017void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002018
Gregory Szorc34c863a2012-03-21 03:54:29 +00002019/**
2020 * @}
2021 */
2022
2023/**
2024 * @}
2025 */
2026
2027/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002028 * @}
2029 */
2030
2031/**
2032 * @}
2033 */
2034
2035/**
2036 * @defgroup LLVMCCoreValueMetadata Metadata
2037 *
2038 * @{
2039 */
2040
2041/**
2042 * Obtain a MDString value from a context.
2043 *
2044 * The returned instance corresponds to the llvm::MDString class.
2045 *
2046 * The instance is specified by string data of a specified length. The
2047 * string content is copied, so the backing memory can be freed after
2048 * this function returns.
2049 */
2050LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2051 unsigned SLen);
2052
2053/**
2054 * Obtain a MDString value from the global context.
2055 */
2056LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2057
2058/**
2059 * Obtain a MDNode value from a context.
2060 *
2061 * The returned value corresponds to the llvm::MDNode class.
2062 */
2063LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2064 unsigned Count);
2065
2066/**
2067 * Obtain a MDNode value from the global context.
2068 */
2069LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2070
2071/**
2072 * Obtain the underlying string from a MDString value.
2073 *
2074 * @param V Instance to obtain string from.
2075 * @param Len Memory address which will hold length of returned string.
2076 * @return String data in MDString.
2077 */
2078const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2079
2080/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002081 * Obtain the number of operands from an MDNode value.
2082 *
2083 * @param V MDNode to get number of operands from.
2084 * @return Number of operands of the MDNode.
2085 */
2086unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2087
2088/**
2089 * Obtain the given MDNode's operands.
2090 *
2091 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2092 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2093 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2094 * MDNode's operands.
2095 *
2096 * @param V MDNode to get the operands from.
2097 * @param Dest Destination array for operands.
2098 */
2099void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2100
2101/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002102 * @}
2103 */
2104
2105/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002106 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2107 *
2108 * A basic block represents a single entry single exit section of code.
2109 * Basic blocks contain a list of instructions which form the body of
2110 * the block.
2111 *
2112 * Basic blocks belong to functions. They have the type of label.
2113 *
2114 * Basic blocks are themselves values. However, the C API models them as
2115 * LLVMBasicBlockRef.
2116 *
2117 * @see llvm::BasicBlock
2118 *
2119 * @{
2120 */
2121
2122/**
2123 * Convert a basic block instance to a value type.
2124 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002125LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002126
2127/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002128 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002129 */
Chris Lattner25963c62010-01-09 22:27:07 +00002130LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002131
2132/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002133 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002134 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002135LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002136
2137/**
2138 * Obtain the function to which a basic block belongs.
2139 *
2140 * @see llvm::BasicBlock::getParent()
2141 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002142LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002143
2144/**
2145 * Obtain the terminator instruction for a basic block.
2146 *
2147 * If the basic block does not have a terminator (it is not well-formed
2148 * if it doesn't), then NULL is returned.
2149 *
2150 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2151 *
2152 * @see llvm::BasicBlock::getTerminator()
2153 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002154LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002155
2156/**
2157 * Obtain the number of basic blocks in a function.
2158 *
2159 * @param Fn Function value to operate on.
2160 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002161unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002162
2163/**
2164 * Obtain all of the basic blocks in a function.
2165 *
2166 * This operates on a function value. The BasicBlocks parameter is a
2167 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2168 * LLVMCountBasicBlocks() in length. This array is populated with
2169 * LLVMBasicBlockRef instances.
2170 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002171void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002172
2173/**
2174 * Obtain the first basic block in a function.
2175 *
2176 * The returned basic block can be used as an iterator. You will likely
2177 * eventually call into LLVMGetNextBasicBlock() with it.
2178 *
2179 * @see llvm::Function::begin()
2180 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002181LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002182
2183/**
2184 * Obtain the last basic block in a function.
2185 *
2186 * @see llvm::Function::end()
2187 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002188LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002189
2190/**
2191 * Advance a basic block iterator.
2192 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002193LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002194
2195/**
2196 * Go backwards in a basic block iterator.
2197 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002198LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002199
2200/**
2201 * Obtain the basic block that corresponds to the entry point of a
2202 * function.
2203 *
2204 * @see llvm::Function::getEntryBlock()
2205 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002206LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002207
Gregory Szorc34c863a2012-03-21 03:54:29 +00002208/**
2209 * Append a basic block to the end of a function.
2210 *
2211 * @see llvm::BasicBlock::Create()
2212 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002213LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2214 LLVMValueRef Fn,
2215 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002216
2217/**
2218 * Append a basic block to the end of a function using the global
2219 * context.
2220 *
2221 * @see llvm::BasicBlock::Create()
2222 */
2223LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2224
2225/**
2226 * Insert a basic block in a function before another basic block.
2227 *
2228 * The function to add to is determined by the function of the
2229 * passed basic block.
2230 *
2231 * @see llvm::BasicBlock::Create()
2232 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002233LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2234 LLVMBasicBlockRef BB,
2235 const char *Name);
2236
Gregory Szorc34c863a2012-03-21 03:54:29 +00002237/**
2238 * Insert a basic block in a function using the global context.
2239 *
2240 * @see llvm::BasicBlock::Create()
2241 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002242LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2243 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002244
2245/**
2246 * Remove a basic block from a function and delete it.
2247 *
2248 * This deletes the basic block from its containing function and deletes
2249 * the basic block itself.
2250 *
2251 * @see llvm::BasicBlock::eraseFromParent()
2252 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002253void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002254
2255/**
2256 * Remove a basic block from a function.
2257 *
2258 * This deletes the basic block from its containing function but keep
2259 * the basic block alive.
2260 *
2261 * @see llvm::BasicBlock::removeFromParent()
2262 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002263void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002264
Gregory Szorc34c863a2012-03-21 03:54:29 +00002265/**
2266 * Move a basic block to before another one.
2267 *
2268 * @see llvm::BasicBlock::moveBefore()
2269 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002270void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002271
2272/**
2273 * Move a basic block to after another one.
2274 *
2275 * @see llvm::BasicBlock::moveAfter()
2276 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002277void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2278
Gregory Szorc34c863a2012-03-21 03:54:29 +00002279/**
2280 * Obtain the first instruction in a basic block.
2281 *
2282 * The returned LLVMValueRef corresponds to a llvm::Instruction
2283 * instance.
2284 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002285LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002286
2287/**
2288 * Obtain the last instruction in a basic block.
2289 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002290 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002291 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002292LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002293
Gregory Szorc34c863a2012-03-21 03:54:29 +00002294/**
2295 * @}
2296 */
2297
2298/**
2299 * @defgroup LLVMCCoreValueInstruction Instructions
2300 *
2301 * Functions in this group relate to the inspection and manipulation of
2302 * individual instructions.
2303 *
2304 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2305 * class has a large number of descendents. llvm::Instruction is a
2306 * llvm::Value and in the C API, instructions are modeled by
2307 * LLVMValueRef.
2308 *
2309 * This group also contains sub-groups which operate on specific
2310 * llvm::Instruction types, e.g. llvm::CallInst.
2311 *
2312 * @{
2313 */
2314
2315/**
2316 * Determine whether an instruction has any metadata attached.
2317 */
2318int LLVMHasMetadata(LLVMValueRef Val);
2319
2320/**
2321 * Return metadata associated with an instruction value.
2322 */
2323LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2324
2325/**
2326 * Set metadata associated with an instruction value.
2327 */
2328void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2329
2330/**
2331 * Obtain the basic block to which an instruction belongs.
2332 *
2333 * @see llvm::Instruction::getParent()
2334 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002335LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002336
2337/**
2338 * Obtain the instruction that occurs after the one specified.
2339 *
2340 * The next instruction will be from the same basic block.
2341 *
2342 * If this is the last instruction in a basic block, NULL will be
2343 * returned.
2344 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002345LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002346
2347/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002348 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002349 *
2350 * If the instruction is the first instruction in a basic block, NULL
2351 * will be returned.
2352 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002353LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002354
2355/**
2356 * Remove and delete an instruction.
2357 *
2358 * The instruction specified is removed from its containing building
2359 * block and then deleted.
2360 *
2361 * @see llvm::Instruction::eraseFromParent()
2362 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002363void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002364
2365/**
2366 * Obtain the code opcode for an individual instruction.
2367 *
2368 * @see llvm::Instruction::getOpCode()
2369 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002370LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002371
2372/**
2373 * Obtain the predicate of an instruction.
2374 *
2375 * This is only valid for instructions that correspond to llvm::ICmpInst
2376 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2377 *
2378 * @see llvm::ICmpInst::getPredicate()
2379 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002380LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002381
Gregory Szorc34c863a2012-03-21 03:54:29 +00002382/**
2383 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2384 *
2385 * Functions in this group apply to instructions that refer to call
2386 * sites and invocations. These correspond to C++ types in the
2387 * llvm::CallInst class tree.
2388 *
2389 * @{
2390 */
2391
2392/**
2393 * Set the calling convention for a call instruction.
2394 *
2395 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2396 * llvm::InvokeInst.
2397 *
2398 * @see llvm::CallInst::setCallingConv()
2399 * @see llvm::InvokeInst::setCallingConv()
2400 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002401void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002402
2403/**
2404 * Obtain the calling convention for a call instruction.
2405 *
2406 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2407 * usage.
2408 *
2409 * @see LLVMSetInstructionCallConv()
2410 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002411unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002412
2413
Devang Patel4c758ea2008-09-25 21:00:45 +00002414void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002415void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002416 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002417void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002418 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002419
Gregory Szorc34c863a2012-03-21 03:54:29 +00002420/**
2421 * Obtain whether a call instruction is a tail call.
2422 *
2423 * This only works on llvm::CallInst instructions.
2424 *
2425 * @see llvm::CallInst::isTailCall()
2426 */
Chris Lattner25963c62010-01-09 22:27:07 +00002427LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002428
2429/**
2430 * Set whether a call instruction is a tail call.
2431 *
2432 * This only works on llvm::CallInst instructions.
2433 *
2434 * @see llvm::CallInst::setTailCall()
2435 */
Chris Lattner25963c62010-01-09 22:27:07 +00002436void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002437
Gregory Szorc34c863a2012-03-21 03:54:29 +00002438/**
2439 * @}
2440 */
2441
2442/**
2443 * Obtain the default destination basic block of a switch instruction.
2444 *
2445 * This only works on llvm::SwitchInst instructions.
2446 *
2447 * @see llvm::SwitchInst::getDefaultDest()
2448 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002449LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2450
Gregory Szorc34c863a2012-03-21 03:54:29 +00002451/**
2452 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2453 *
2454 * Functions in this group only apply to instructions that map to
2455 * llvm::PHINode instances.
2456 *
2457 * @{
2458 */
2459
2460/**
2461 * Add an incoming value to the end of a PHI list.
2462 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002463void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2464 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002465
2466/**
2467 * Obtain the number of incoming basic blocks to a PHI node.
2468 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002469unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002470
2471/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002472 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002473 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002474LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002475
2476/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002477 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002478 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002479LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002480
Gregory Szorc34c863a2012-03-21 03:54:29 +00002481/**
2482 * @}
2483 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002484
Gregory Szorc34c863a2012-03-21 03:54:29 +00002485/**
2486 * @}
2487 */
2488
2489/**
2490 * @}
2491 */
2492
2493/**
2494 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2495 *
2496 * An instruction builder represents a point within a basic block and is
2497 * the exclusive means of building instructions using the C interface.
2498 *
2499 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002500 */
2501
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002502LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002503LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002504void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2505 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002506void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2507void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002508LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002509void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2510void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002511void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2512 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002513void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2514
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002515/* Metadata */
2516void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2517LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2518void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2519
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002520/* Terminators */
2521LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2522LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002523LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002524 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002525LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2526LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2527 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2528LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2529 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002530LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2531 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002532LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2533 LLVMValueRef *Args, unsigned NumArgs,
2534 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2535 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002536LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2537 LLVMValueRef PersFn, unsigned NumClauses,
2538 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002539LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002540LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2541
Gordon Henriksen097102c2008-01-01 05:50:53 +00002542/* Add a case to the switch instruction */
2543void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2544 LLVMBasicBlockRef Dest);
2545
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002546/* Add a destination to the indirectbr instruction */
2547void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2548
Bill Wendlingfae14752011-08-12 20:24:12 +00002549/* Add a catch or filter clause to the landingpad instruction */
2550void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2551
2552/* Set the 'cleanup' flag in the landingpad instruction */
2553void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2554
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002555/* Arithmetic */
2556LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2557 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002558LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2559 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002560LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2561 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002562LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2563 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002564LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2565 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002566LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2567 const char *Name);
2568LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2569 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002570LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2571 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002572LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2573 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002574LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2575 const char *Name);
2576LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2577 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002578LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2579 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002580LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2581 const char *Name);
2582LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2583 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002584LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2585 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002586LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2587 const char *Name);
2588LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2589 const char *Name);
2590LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2591 const char *Name);
2592LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2593 const char *Name);
2594LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2595 const char *Name);
2596LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2597 const char *Name);
2598LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2599 const char *Name);
2600LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2601 const char *Name);
2602LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2603 const char *Name);
2604LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2605 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002606LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2607 LLVMValueRef LHS, LLVMValueRef RHS,
2608 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002609LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002610LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2611 const char *Name);
2612LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2613 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002614LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002615LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2616
2617/* Memory */
2618LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2619LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2620 LLVMValueRef Val, const char *Name);
2621LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2622LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2623 LLVMValueRef Val, const char *Name);
2624LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2625LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2626 const char *Name);
2627LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2628LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2629 LLVMValueRef *Indices, unsigned NumIndices,
2630 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002631LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2632 LLVMValueRef *Indices, unsigned NumIndices,
2633 const char *Name);
2634LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2635 unsigned Idx, const char *Name);
2636LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2637 const char *Name);
2638LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2639 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002640LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2641void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002642
2643/* Casts */
2644LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2645 LLVMTypeRef DestTy, const char *Name);
2646LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2647 LLVMTypeRef DestTy, const char *Name);
2648LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2649 LLVMTypeRef DestTy, const char *Name);
2650LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2651 LLVMTypeRef DestTy, const char *Name);
2652LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2653 LLVMTypeRef DestTy, const char *Name);
2654LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2655 LLVMTypeRef DestTy, const char *Name);
2656LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2657 LLVMTypeRef DestTy, const char *Name);
2658LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2659 LLVMTypeRef DestTy, const char *Name);
2660LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2661 LLVMTypeRef DestTy, const char *Name);
2662LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2663 LLVMTypeRef DestTy, const char *Name);
2664LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2665 LLVMTypeRef DestTy, const char *Name);
2666LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2667 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002668LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2669 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002670LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2671 LLVMTypeRef DestTy, const char *Name);
2672LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2673 LLVMTypeRef DestTy, const char *Name);
2674LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2675 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002676LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2677 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002678LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2679 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002680LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002681 LLVMTypeRef DestTy, const char *Name);
2682LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2683 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002684
2685/* Comparisons */
2686LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2687 LLVMValueRef LHS, LLVMValueRef RHS,
2688 const char *Name);
2689LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2690 LLVMValueRef LHS, LLVMValueRef RHS,
2691 const char *Name);
2692
2693/* Miscellaneous instructions */
2694LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2695LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2696 LLVMValueRef *Args, unsigned NumArgs,
2697 const char *Name);
2698LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2699 LLVMValueRef Then, LLVMValueRef Else,
2700 const char *Name);
2701LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2702 const char *Name);
2703LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2704 LLVMValueRef Index, const char *Name);
2705LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2706 LLVMValueRef EltVal, LLVMValueRef Index,
2707 const char *Name);
2708LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2709 LLVMValueRef V2, LLVMValueRef Mask,
2710 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002711LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2712 unsigned Index, const char *Name);
2713LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2714 LLVMValueRef EltVal, unsigned Index,
2715 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002716
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002717LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2718 const char *Name);
2719LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2720 const char *Name);
2721LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2722 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00002723LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2724 LLVMBool singleThread, const char *Name);
2725LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00002726 LLVMValueRef PTR, LLVMValueRef Val,
2727 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00002728 LLVMBool singleThread);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002729
Gregory Szorc34c863a2012-03-21 03:54:29 +00002730/**
2731 * @}
2732 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002733
Gregory Szorc34c863a2012-03-21 03:54:29 +00002734/**
2735 * @defgroup LLVMCCoreModuleProvider Module Providers
2736 *
2737 * @{
2738 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002739
Gregory Szorc34c863a2012-03-21 03:54:29 +00002740/**
2741 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002742 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002743 */
2744LLVMModuleProviderRef
2745LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2746
Gregory Szorc34c863a2012-03-21 03:54:29 +00002747/**
2748 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002749 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002750void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002751
Gregory Szorc34c863a2012-03-21 03:54:29 +00002752/**
2753 * @}
2754 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002755
Gregory Szorc34c863a2012-03-21 03:54:29 +00002756/**
2757 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2758 *
2759 * @{
2760 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002761
Chris Lattner25963c62010-01-09 22:27:07 +00002762LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2763 LLVMMemoryBufferRef *OutMemBuf,
2764 char **OutMessage);
2765LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2766 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00002767LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2768 size_t InputDataLength,
2769 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00002770 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00002771LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2772 size_t InputDataLength,
2773 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00002774const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00002775size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002776void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2777
Gregory Szorc34c863a2012-03-21 03:54:29 +00002778/**
2779 * @}
2780 */
2781
2782/**
Juergen Ributzka49892552014-04-28 18:19:25 +00002783 * @defgroup LLVMCCorePass Pass
2784 *
2785 * @{
2786 */
2787
2788const char *LLVMGetPassName(LLVMPassRef);
2789
2790/**
2791 * @}
2792 */
2793
2794/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002795 * @defgroup LLVMCCorePassRegistry Pass Registry
2796 *
2797 * @{
2798 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002799
2800/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002801 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002802LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002803
Gregory Szorc34c863a2012-03-21 03:54:29 +00002804/**
2805 * @}
2806 */
2807
2808/**
2809 * @defgroup LLVMCCorePassManagers Pass Managers
2810 *
2811 * @{
2812 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002813
2814/** Constructs a new whole-module pass pipeline. This type of pipeline is
2815 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002816 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002817LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002818
2819/** Constructs a new function-by-function pass pipeline over the module
2820 provider. It does not take ownership of the module provider. This type of
2821 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002822 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002823LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2824
2825/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002826LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2827
2828/** Initializes, executes on the provided module, and finalizes all of the
2829 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002830 modified the module, 0 otherwise.
2831 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002832LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002833
2834/** Initializes all of the function passes scheduled in the function pass
2835 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002836 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002837LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002838
2839/** Executes all of the function passes scheduled in the function pass manager
2840 on the provided function. Returns 1 if any of the passes modified the
2841 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002842 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002843LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002844
2845/** Finalizes all of the function passes scheduled in in the function pass
2846 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002847 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002848LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002849
2850/** Frees the memory of a pass pipeline. For function pipelines, does not free
2851 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002852 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002853void LLVMDisposePassManager(LLVMPassManagerRef PM);
2854
Gregory Szorc34c863a2012-03-21 03:54:29 +00002855/**
2856 * @}
2857 */
2858
2859/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00002860 * @defgroup LLVMCCoreThreading Threading
2861 *
2862 * Handle the structures needed to make LLVM safe for multithreading.
2863 *
2864 * @{
2865 */
2866
2867/** Allocate and initialize structures needed to make LLVM safe for
2868 multithreading. The return value indicates whether multithreaded
2869 initialization succeeded. Must be executed in isolation from all
2870 other LLVM api calls.
2871 @see llvm::llvm_start_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002872LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002873
2874/** Deallocate structures necessary to make LLVM safe for multithreading.
2875 Must be executed in isolation from all other LLVM api calls.
2876 @see llvm::llvm_stop_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002877void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002878
2879/** Check whether LLVM is executing in thread-safe mode or not.
2880 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002881LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002882
2883/**
2884 * @}
2885 */
2886
2887/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002888 * @}
2889 */
2890
2891/**
2892 * @}
2893 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002894
Gordon Henriksen76a03742007-09-18 03:18:57 +00002895#ifdef __cplusplus
2896}
Evan Cheng2e254d02013-04-04 17:40:53 +00002897#endif /* !defined(__cplusplus) */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002898
Evan Cheng2e254d02013-04-04 17:40:53 +00002899#endif /* !defined(LLVM_C_CORE_H) */