blob: f9fbfc8f3ba669c382a0724fe717715d0c0e1e4a [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
Michael J. Spencerab425d82010-11-29 18:47:54 +000018#include "llvm/Support/DataTypes.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000019
Gordon Henriksen76a03742007-09-18 03:18:57 +000020#ifdef __cplusplus
Gordon Henriksen7330acd2007-10-05 23:59:36 +000021
22/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
23 and 'unwrap' conversion functions. */
24#include "llvm/Module.h"
Owen Anderson4698c5d2010-10-07 17:55:47 +000025#include "llvm/PassRegistry.h"
Duncan Sandsa07136e2008-04-13 06:22:09 +000026#include "llvm/Support/IRBuilder.h"
Gordon Henriksen7330acd2007-10-05 23:59:36 +000027
Gordon Henriksen76a03742007-09-18 03:18:57 +000028extern "C" {
29#endif
30
Gregory Szorc34c863a2012-03-21 03:54:29 +000031/**
32 * @defgroup LLVMC LLVM-C: C interface to LLVM
33 *
34 * This module exposes parts of the LLVM library as a C API.
35 *
36 * @{
37 */
38
39/**
40 * @defgroup LLVMCTransforms Transforms
41 */
42
43/**
44 * @defgroup LLVMCCore Core
45 *
46 * This modules provide an interface to libLLVMCore, which implements
47 * the LLVM intermediate representation as well as other related types
48 * and utilities.
49 *
50 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
51 * parameters must be passed as base types. Despite the declared types, most
52 * of the functions provided operate only on branches of the type hierarchy.
53 * The declared parameter names are descriptive and specify which type is
54 * required. Additionally, each type hierarchy is documented along with the
55 * functions that operate upon it. For more detail, refer to LLVM's C++ code.
56 * If in doubt, refer to Core.cpp, which performs paramter downcasts in the
57 * form unwrap<RequiredType>(Param).
58 *
59 * Many exotic languages can interoperate with C code but have a harder time
60 * with C++ due to name mangling. So in addition to C, this interface enables
61 * tools written in such languages.
62 *
63 * When included into a C++ source file, also declares 'wrap' and 'unwrap'
64 * helpers to perform opaque reference<-->pointer conversions. These helpers
65 * are shorter and more tightly typed than writing the casts by hand when
66 * authoring bindings. In assert builds, they will do runtime type checking.
67 *
68 * @{
69 */
70
71/**
72 * @defgroup LLVMCCoreTypes Types and Enumerations
73 *
74 * @{
75 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000076
Chris Lattner25963c62010-01-09 22:27:07 +000077typedef int LLVMBool;
78
Gordon Henriksen76a03742007-09-18 03:18:57 +000079/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000080
81/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000082 * The top-level container for all LLVM global data. See the LLVMContext class.
Owen Anderson6773d382009-07-01 16:58:40 +000083 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000084typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000085
86/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000087 * The top-level container for all other LLVM Intermediate Representation (IR)
Gregory Szorc34c863a2012-03-21 03:54:29 +000088 * objects.
89 *
90 * @see llvm::Module
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000091 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000092typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000093
94/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000095 * Each value in the LLVM IR has a type, an LLVMTypeRef.
96 *
97 * @see llvm::Type
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000098 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000099typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000100
Gregory Szorc34c863a2012-03-21 03:54:29 +0000101/**
102 * Represents an individual value in LLVM IR.
103 *
104 * This models llvm::Value.
105 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000106typedef struct LLVMOpaqueValue *LLVMValueRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +0000107
108/**
109 * Represents a basic block of instruction in LLVM IR.
110 *
111 * This models llvm::BasicBlock.
112 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000113typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +0000114
115/**
116 * Represents an LLVM basic block builder.
117 *
118 * This models llvm::IRBuilder.
119 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000120typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000121
Gregory Szorc34c863a2012-03-21 03:54:29 +0000122/**
123 * Interface used to provide a module to JIT or interpreter.
124 * This is now just a synonym for llvm::Module, but we have to keep using the
125 * different type to keep binary compatibility.
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000126 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000127typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +0000128
Gregory Szorc34c863a2012-03-21 03:54:29 +0000129/**
130 * Used to provide a module to JIT or interpreter.
131 *
132 * @see llvm::MemoryBuffer
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000133 */
134typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
135
Gregory Szorc34c863a2012-03-21 03:54:29 +0000136/** @see llvm::PassManagerBase */
Gordon Henriksen878114b2008-03-16 04:20:44 +0000137typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
138
Gregory Szorc34c863a2012-03-21 03:54:29 +0000139/** @see llvm::PassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +0000140typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
141
Gregory Szorc34c863a2012-03-21 03:54:29 +0000142/**
143 * Used to get the users and usees of a Value.
144 *
145 * @see llvm::Use */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +0000146typedef struct LLVMOpaqueUse *LLVMUseRef;
Chris Lattner40cf28d2009-10-12 04:01:02 +0000147
Gordon Henriksen76a03742007-09-18 03:18:57 +0000148typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +0000149 LLVMZExtAttribute = 1<<0,
150 LLVMSExtAttribute = 1<<1,
151 LLVMNoReturnAttribute = 1<<2,
152 LLVMInRegAttribute = 1<<3,
153 LLVMStructRetAttribute = 1<<4,
154 LLVMNoUnwindAttribute = 1<<5,
155 LLVMNoAliasAttribute = 1<<6,
156 LLVMByValAttribute = 1<<7,
157 LLVMNestAttribute = 1<<8,
158 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000159 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000160 LLVMNoInlineAttribute = 1<<11,
161 LLVMAlwaysInlineAttribute = 1<<12,
162 LLVMOptimizeForSizeAttribute = 1<<13,
163 LLVMStackProtectAttribute = 1<<14,
164 LLVMStackProtectReqAttribute = 1<<15,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000165 LLVMAlignment = 31<<16,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000166 LLVMNoCaptureAttribute = 1<<21,
167 LLVMNoRedZoneAttribute = 1<<22,
168 LLVMNoImplicitFloatAttribute = 1<<23,
Jakob Stoklund Olesen74bb06c2010-02-06 01:16:28 +0000169 LLVMNakedAttribute = 1<<24,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000170 LLVMInlineHintAttribute = 1<<25,
Torok Edwin1db48c02011-10-06 12:13:32 +0000171 LLVMStackAlignment = 7<<26,
172 LLVMReturnsTwice = 1 << 29,
173 LLVMUWTable = 1 << 30,
Chandler Carruth44d69d92012-01-25 07:40:15 +0000174 LLVMNonLazyBind = 1 << 31
175
176 // FIXME: This attribute is currently not included in the C API as
177 // a temporary measure until the API/ABI impact to the C API is understood
178 // and the path forward agreed upon.
179 //LLVMAddressSafety = 1ULL << 32
Devang Patel4c758ea2008-09-25 21:00:45 +0000180} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000181
182typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000183 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000184 LLVMRet = 1,
185 LLVMBr = 2,
186 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000187 LLVMIndirectBr = 4,
188 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000189 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000190 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000191
Bill Wendlingda52cec2010-02-15 20:53:17 +0000192 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000193 LLVMAdd = 8,
194 LLVMFAdd = 9,
195 LLVMSub = 10,
196 LLVMFSub = 11,
197 LLVMMul = 12,
198 LLVMFMul = 13,
199 LLVMUDiv = 14,
200 LLVMSDiv = 15,
201 LLVMFDiv = 16,
202 LLVMURem = 17,
203 LLVMSRem = 18,
204 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000205
Bill Wendlingda52cec2010-02-15 20:53:17 +0000206 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000207 LLVMShl = 20,
208 LLVMLShr = 21,
209 LLVMAShr = 22,
210 LLVMAnd = 23,
211 LLVMOr = 24,
212 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000213
Bill Wendlingda52cec2010-02-15 20:53:17 +0000214 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000215 LLVMAlloca = 26,
216 LLVMLoad = 27,
217 LLVMStore = 28,
218 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000219
Bill Wendlingda52cec2010-02-15 20:53:17 +0000220 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000221 LLVMTrunc = 30,
222 LLVMZExt = 31,
223 LLVMSExt = 32,
224 LLVMFPToUI = 33,
225 LLVMFPToSI = 34,
226 LLVMUIToFP = 35,
227 LLVMSIToFP = 36,
228 LLVMFPTrunc = 37,
229 LLVMFPExt = 38,
230 LLVMPtrToInt = 39,
231 LLVMIntToPtr = 40,
232 LLVMBitCast = 41,
Bill Wendling07d6d762010-02-15 20:50:51 +0000233
Bill Wendlingda52cec2010-02-15 20:53:17 +0000234 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000235 LLVMICmp = 42,
236 LLVMFCmp = 43,
237 LLVMPHI = 44,
238 LLVMCall = 45,
239 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000240 LLVMUserOp1 = 47,
241 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000242 LLVMVAArg = 49,
243 LLVMExtractElement = 50,
244 LLVMInsertElement = 51,
245 LLVMShuffleVector = 52,
246 LLVMExtractValue = 53,
247 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000248
249 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000250 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000251 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000252 LLVMAtomicRMW = 57,
253
254 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000255 LLVMResume = 58,
Bill Wendling0aef16a2012-02-06 21:44:22 +0000256 LLVMLandingPad = 59
Bill Wendling2641d132011-07-27 21:00:28 +0000257
Chris Lattner40cf28d2009-10-12 04:01:02 +0000258} LLVMOpcode;
259
260typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000261 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000262 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000263 LLVMFloatTypeKind, /**< 32 bit floating point type */
264 LLVMDoubleTypeKind, /**< 64 bit floating point type */
265 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
266 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
267 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
268 LLVMLabelTypeKind, /**< Labels */
269 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
270 LLVMFunctionTypeKind, /**< Functions */
271 LLVMStructTypeKind, /**< Structures */
272 LLVMArrayTypeKind, /**< Arrays */
273 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000274 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000275 LLVMMetadataTypeKind, /**< Metadata */
276 LLVMX86_MMXTypeKind /**< X86 MMX */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000277} LLVMTypeKind;
278
279typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000280 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000281 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000282 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
283 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
284 equivalent. */
285 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
286 LLVMWeakODRLinkage, /**< Same, but only replaced by something
287 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000288 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
289 LLVMInternalLinkage, /**< Rename collisions when linking (static
290 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000291 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000292 LLVMDLLImportLinkage, /**< Function to be imported from DLL */
293 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
Duncan Sandse2881052009-03-11 08:08:06 +0000294 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000295 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000296 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000297 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling578ee402010-08-20 22:05:50 +0000298 LLVMLinkerPrivateWeakLinkage, /**< Like LinkerPrivate, but is weak. */
299 LLVMLinkerPrivateWeakDefAutoLinkage /**< Like LinkerPrivateWeak, but possibly
300 hidden. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000301} LLVMLinkage;
302
303typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000304 LLVMDefaultVisibility, /**< The GV is visible */
305 LLVMHiddenVisibility, /**< The GV is hidden */
306 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000307} LLVMVisibility;
308
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000309typedef enum {
310 LLVMCCallConv = 0,
311 LLVMFastCallConv = 8,
312 LLVMColdCallConv = 9,
313 LLVMX86StdcallCallConv = 64,
314 LLVMX86FastcallCallConv = 65
315} LLVMCallConv;
316
317typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000318 LLVMIntEQ = 32, /**< equal */
319 LLVMIntNE, /**< not equal */
320 LLVMIntUGT, /**< unsigned greater than */
321 LLVMIntUGE, /**< unsigned greater or equal */
322 LLVMIntULT, /**< unsigned less than */
323 LLVMIntULE, /**< unsigned less or equal */
324 LLVMIntSGT, /**< signed greater than */
325 LLVMIntSGE, /**< signed greater or equal */
326 LLVMIntSLT, /**< signed less than */
327 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000328} LLVMIntPredicate;
329
330typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000331 LLVMRealPredicateFalse, /**< Always false (always folded) */
332 LLVMRealOEQ, /**< True if ordered and equal */
333 LLVMRealOGT, /**< True if ordered and greater than */
334 LLVMRealOGE, /**< True if ordered and greater than or equal */
335 LLVMRealOLT, /**< True if ordered and less than */
336 LLVMRealOLE, /**< True if ordered and less than or equal */
337 LLVMRealONE, /**< True if ordered and operands are unequal */
338 LLVMRealORD, /**< True if ordered (no nans) */
339 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
340 LLVMRealUEQ, /**< True if unordered or equal */
341 LLVMRealUGT, /**< True if unordered or greater than */
342 LLVMRealUGE, /**< True if unordered, greater than, or equal */
343 LLVMRealULT, /**< True if unordered or less than */
344 LLVMRealULE, /**< True if unordered, less than, or equal */
345 LLVMRealUNE, /**< True if unordered or not equal */
346 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000347} LLVMRealPredicate;
348
Bill Wendlingfae14752011-08-12 20:24:12 +0000349typedef enum {
350 LLVMLandingPadCatch, /**< A catch clause */
351 LLVMLandingPadFilter /**< A filter clause */
352} LLVMLandingPadClauseTy;
353
Gregory Szorc34c863a2012-03-21 03:54:29 +0000354/**
355 * @}
356 */
357
Nick Lewycky0db26542011-05-15 07:20:34 +0000358void LLVMInitializeCore(LLVMPassRegistryRef R);
359
Gordon Henriksen76a03742007-09-18 03:18:57 +0000360
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000361/*===-- Error handling ----------------------------------------------------===*/
362
363void LLVMDisposeMessage(char *Message);
364
365
Gregory Szorc34c863a2012-03-21 03:54:29 +0000366/**
367 * @defgroup LLVMCCoreContext Contexts
368 *
369 * Contexts are execution states for the core LLVM IR system.
370 *
371 * Most types are tied to a context instance. Multiple contexts can
372 * exist simultaneously. A single context is not thread safe. However,
373 * different contexts can execute on different threads simultaneously.
374 *
375 * @{
376 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000377
Gregory Szorc34c863a2012-03-21 03:54:29 +0000378/**
379 * Create a new context.
380 *
381 * Every call to this function should be paired with a call to
382 * LLVMContextDispose() or the context will leak memory.
383 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000384LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000385
386/**
387 * Obtain the global context instance.
388 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000389LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000390
391/**
392 * Destroy a context instance.
393 *
394 * This should be called for every call to LLVMContextCreate() or memory
395 * will be leaked.
396 */
Owen Anderson6773d382009-07-01 16:58:40 +0000397void LLVMContextDispose(LLVMContextRef C);
398
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000399unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
400 unsigned SLen);
401unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
402
Gregory Szorc34c863a2012-03-21 03:54:29 +0000403/**
404 * @}
405 */
406
407/** @defgroup LLVMCCoreModule Modules
408 *
409 * Modules represent the top-level structure in a LLVM program. An LLVM
410 * module is effectively a translation unit or a collection of
411 * translation units merged together.
412 *
413 * @{
414 */
415
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000416/*===-- Modules -----------------------------------------------------------===*/
417
Gregory Szorc34c863a2012-03-21 03:54:29 +0000418/* Create and destroy modules. */
419/** @see llvm::Module::Module */
420
421/**
422 * Create a new, empty module in the global context.
423 *
424 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
425 * LLVMGetGlobalContext() as the context parameter.
426 *
427 * Every invocation should be paired with LLVMDisposeModule() or memory
428 * will be leaked.
429 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000430LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000431
432/**
433 * Create a new, empty module in a specific context.
434 *
435 * Every invocation should be paired with LLVMDisposeModule() or memory
436 * will be leaked.
437 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000438LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
439 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000440
Gregory Szorc34c863a2012-03-21 03:54:29 +0000441/**
442 * Destroy a module instance.
443 *
444 * This must be called for every created module or memory will be
445 * leaked.
446 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000447void LLVMDisposeModule(LLVMModuleRef M);
448
Gregory Szorc34c863a2012-03-21 03:54:29 +0000449/**
450 * Obtain the data layout for a module.
451 *
452 * @see Module::getDataLayout()
453 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000454const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000455
456/**
457 * Set the data layout for a module.
458 *
459 * @see Module::setDataLayout()
460 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000461void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
462
Gregory Szorc34c863a2012-03-21 03:54:29 +0000463/**
464 * Obtain the target triple for a module.
465 *
466 * @see Module::getTargetTriple()
467 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000468const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000469
470/**
471 * Set the target triple for a module.
472 *
473 * @see Module::setTargetTriple()
474 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000475void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
476
Gregory Szorc34c863a2012-03-21 03:54:29 +0000477/**
478 * Dump a representation of a module to stderr.
479 *
480 * @see Module::dump()
481 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000482void LLVMDumpModule(LLVMModuleRef M);
483
Gregory Szorc34c863a2012-03-21 03:54:29 +0000484/**
485 * Set inline assembly for a module.
486 *
487 * @see Module::setModuleInlineAsm()
488 */
Chris Lattner26941452010-04-10 17:52:58 +0000489void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000490
Gregory Szorc34c863a2012-03-21 03:54:29 +0000491/**
492 * Obtain the context to which this module is associated.
493 *
494 * @see Module::getContext()
495 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000496LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
497
Gregory Szorc34c863a2012-03-21 03:54:29 +0000498/**
499 * Obtain a Type from a module by its registered name.
500 */
501LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000502
Gregory Szorc34c863a2012-03-21 03:54:29 +0000503/**
504 * Obtain the number of operands for named metadata in a module.
505 *
506 * @see llvm::Module::getNamedMetadata()
507 */
508unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
509
510/**
511 * Obtain the named metadata operands for a module.
512 *
513 * The passed LLVMValueRef pointer should refer to an array of
514 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
515 * array will be populated with the LLVMValueRef instances. Each
516 * instance corresponds to a llvm::MDNode.
517 *
518 * @see llvm::Module::getNamedMetadata()
519 * @see llvm::MDNode::getOperand()
520 */
521void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
522
523/**
524 * Add an operand to named metadata.
525 *
526 * @see llvm::Module::getNamedMetadata()
527 * @see llvm::MDNode::addOperand()
528 */
529void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
530 LLVMValueRef Val);
531
532
533/**
534 * @}
535 */
536
537/**
538 * @defgroup LLVMCCoreType Types
539 *
540 * Types represent the type of a value.
541 *
542 * Types are associated with a context instance. The context internally
543 * deduplicates types so there is only 1 instance of a specific type
544 * alive at a time. In other words, a unique type is shared among all
545 * consumers within a context.
546 *
547 * A Type in the C API corresponds to llvm::Type.
548 *
549 * Types have the following hierarchy:
550 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000551 * types:
552 * integer type
553 * real type
554 * function type
555 * sequence types:
556 * array type
557 * pointer type
558 * vector type
559 * void type
560 * label type
561 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000562 *
563 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000564 */
565
Gregory Szorc34c863a2012-03-21 03:54:29 +0000566/**
567 * Obtain the enumerated type of a Type instance.
568 *
569 * @see llvm::Type:getTypeID()
570 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000571LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000572
573/**
574 * Whether the type has a known size.
575 *
576 * Things that don't have a size are abstract types, labels, and void.a
577 *
578 * @see llvm::Type::isSized()
579 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000580LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000581
Gregory Szorc34c863a2012-03-21 03:54:29 +0000582/**
583 * Obtain the context to which this type instance is associated.
584 *
585 * @see llvm::Type::getContext()
586 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000587LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
588
Gregory Szorc34c863a2012-03-21 03:54:29 +0000589/**
590 * @defgroup LLVMCCoreTypeInt Integer Types
591 *
592 * Functions in this section operate on integer types.
593 *
594 * @{
595 */
596
597/**
598 * Obtain an integer type from a context with specified bit width.
599 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000600LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
601LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
602LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
603LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
604LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
605LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
606
Gregory Szorc34c863a2012-03-21 03:54:29 +0000607/**
608 * Obtain an integer type from the global context with a specified bit
609 * width.
610 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000611LLVMTypeRef LLVMInt1Type(void);
612LLVMTypeRef LLVMInt8Type(void);
613LLVMTypeRef LLVMInt16Type(void);
614LLVMTypeRef LLVMInt32Type(void);
615LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000616LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000617unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000618
Gregory Szorc34c863a2012-03-21 03:54:29 +0000619/**
620 * @}
621 */
622
623/**
624 * @defgroup LLVMCCoreTypeFloat Floating Point Types
625 *
626 * @{
627 */
628
629/**
630 * Obtain a 16-bit floating point type from a context.
631 */
Dan Gohman518cda42011-12-17 00:04:22 +0000632LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000633
634/**
635 * Obtain a 32-bit floating point type from a context.
636 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000637LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000638
639/**
640 * Obtain a 64-bit floating point type from a context.
641 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000642LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000643
644/**
645 * Obtain a 80-bit floating point type (X87) from a context.
646 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000647LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000648
649/**
650 * Obtain a 128-bit floating point type (112-bit mantissa) from a
651 * context.
652 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000653LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000654
655/**
656 * Obtain a 128-bit floating point type (two 64-bits) from a context.
657 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000658LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
659
Gregory Szorc34c863a2012-03-21 03:54:29 +0000660/**
661 * Obtain a floating point type from the global context.
662 *
663 * These map to the functions in this group of the same name.
664 */
Dan Gohman518cda42011-12-17 00:04:22 +0000665LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000666LLVMTypeRef LLVMFloatType(void);
667LLVMTypeRef LLVMDoubleType(void);
668LLVMTypeRef LLVMX86FP80Type(void);
669LLVMTypeRef LLVMFP128Type(void);
670LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000671
Gregory Szorc34c863a2012-03-21 03:54:29 +0000672/**
673 * @}
674 */
675
676/**
677 * @defgroup LLVMCCoreTypeFunction Function Types
678 *
679 * @{
680 */
681
682/**
683 * Obtain a function type consisting of a specified signature.
684 *
685 * The function is defined as a tuple of a return Type, a list of
686 * parameter types, and whether the function is variadic.
687 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000688LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
689 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000690 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000691
692/**
693 * Returns whether a function type is variadic.
694 */
Chris Lattner25963c62010-01-09 22:27:07 +0000695LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000696
697/**
698 * Obtain the Type this function Type returns.
699 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000700LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000701
702/**
703 * Obtain the number of parameters this function accepts.
704 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000705unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000706
707/**
708 * Obtain the types of a function's parameters.
709 *
710 * The Dest parameter should point to a pre-allocated array of
711 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
712 * first LLVMCountParamTypes() entries in the array will be populated
713 * with LLVMTypeRef instances.
714 *
715 * @param FunctionTy The function type to operate on.
716 * @param Dest Memory address of an array to be filled with result.
717 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000718void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000719
Gregory Szorc34c863a2012-03-21 03:54:29 +0000720/**
721 * @}
722 */
723
724/**
725 * @defgroup LLVMCCoreTypeStruct Structure Types
726 *
727 * These functions relate to LLVMTypeRef instances.
728 *
729 * @see llvm::StructType
730 *
731 * @{
732 */
733
734/**
735 * Create a new structure type in a context.
736 *
737 * A structure is specified by a list of inner elements/types and
738 * whether these can be packed together.
739 *
740 * @see llvm::StructType::create()
741 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000742LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000743 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000744
745/**
746 * Create a new structure type in the global context.
747 *
748 * @see llvm::StructType::create()
749 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000750LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000751 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000752
753/**
754 * Create an empty structure in a context having a specified name.
755 *
756 * @see llvm::StructType::create()
757 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000758LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000759
760/**
761 * Obtain the name of a structure.
762 *
763 * @see llvm::StructType::getName()
764 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000765const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000766
767/**
768 * Set the contents of a structure type.
769 *
770 * @see llvm::StructType::setBody()
771 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000772void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
773 unsigned ElementCount, LLVMBool Packed);
774
Gregory Szorc34c863a2012-03-21 03:54:29 +0000775/**
776 * Get the number of elements defined inside the structure.
777 *
778 * @see llvm::StructType::getNumElements()
779 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000780unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000781
782/**
783 * Get the elements within a structure.
784 *
785 * The function is passed the address of a pre-allocated array of
786 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
787 * invocation, this array will be populated with the structure's
788 * elements. The objects in the destination array will have a lifetime
789 * of the structure type itself, which is the lifetime of the context it
790 * is contained in.
791 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000792void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000793
794/**
795 * Determine whether a structure is packed.
796 *
797 * @see llvm::StructType::isPacked()
798 */
Chris Lattner25963c62010-01-09 22:27:07 +0000799LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000800
801/**
802 * Determine whether a structure is opaque.
803 *
804 * @see llvm::StructType::isOpaque()
805 */
Chris Lattner17cf05b2011-07-14 16:20:28 +0000806LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
807
Gregory Szorc34c863a2012-03-21 03:54:29 +0000808/**
809 * @}
810 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000811
Gregory Szorc34c863a2012-03-21 03:54:29 +0000812
813/**
814 * @defgroup LLVMCCoreTypeSequential Sequential Types
815 *
816 * Sequential types represents "arrays" of types. This is a super class
817 * for array, vector, and pointer types.
818 *
819 * @{
820 */
821
822/**
823 * Obtain the type of elements within a sequential type.
824 *
825 * This works on array, vector, and pointer types.
826 *
827 * @see llvm::SequentialType::getElementType()
828 */
829LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
830
831/**
832 * Create a fixed size array type that refers to a specific type.
833 *
834 * The created type will exist in the context that its element type
835 * exists in.
836 *
837 * @see llvm::ArrayType::get()
838 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000839LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000840
841/**
842 * Obtain the length of an array type.
843 *
844 * This only works on types that represent arrays.
845 *
846 * @see llvm::ArrayType::getNumElements()
847 */
848unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
849
850/**
851 * Create a pointer type that points to a defined type.
852 *
853 * The created type will exist in the context that its pointee type
854 * exists in.
855 *
856 * @see llvm::PointerType::get()
857 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +0000858LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000859
860/**
861 * Obtain the address space of a pointer type.
862 *
863 * This only works on types that represent pointers.
864 *
865 * @see llvm::PointerType::getAddressSpace()
866 */
867unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
868
869/**
870 * Create a vector type that contains a defined type and has a specific
871 * number of elements.
872 *
873 * The created type will exist in the context thats its element type
874 * exists in.
875 *
876 * @see llvm::VectorType::get()
877 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000878LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000879
Gregory Szorc34c863a2012-03-21 03:54:29 +0000880/**
881 * Obtain the number of elements in a vector type.
882 *
883 * This only works on types that represent vectors.
884 *
885 * @see llvm::VectorType::getNumElements()
886 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000887unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
888
Gregory Szorc34c863a2012-03-21 03:54:29 +0000889/**
890 * @}
891 */
892
893/**
894 * @defgroup LLVMCCoreTypeOther Other Types
895 *
896 * @{
897 */
898
899/**
900 * Create a void type in a context.
901 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000902LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000903
904/**
905 * Create a label type in a context.
906 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000907LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000908
909/**
910 * Create a X86 MMX type in a context.
911 */
Dale Johannesen95b67af2010-09-10 21:58:02 +0000912LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000913
Gregory Szorc34c863a2012-03-21 03:54:29 +0000914/**
915 * These are similar to the above functions except they operate on the
916 * global context.
917 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000918LLVMTypeRef LLVMVoidType(void);
919LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +0000920LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000921
Gregory Szorc34c863a2012-03-21 03:54:29 +0000922/**
923 * @}
924 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000925
Gregory Szorc34c863a2012-03-21 03:54:29 +0000926/**
927 * @}
928 */
929
930/**
931 * @defgroup LLVMCCoreValues Values
932 *
933 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +0000934 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +0000935 *
936 * LLVMValueRef essentially represents llvm::Value. There is a rich
937 * hierarchy of classes within this type. Depending on the instance
938 * obtain, not all APIs are available.
939 *
940 * Callers can determine the type of a LLVMValueRef by calling the
941 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
942 * functions are defined by a macro, so it isn't obvious which are
943 * available by looking at the Doxygen source code. Instead, look at the
944 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
945 * of value names given. These value names also correspond to classes in
946 * the llvm::Value hierarchy.
947 *
948 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000949 */
950
Gordon Henriksen29e38942008-12-19 18:39:45 +0000951#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
952 macro(Argument) \
953 macro(BasicBlock) \
954 macro(InlineAsm) \
Torok Edwind09b7572011-10-14 20:37:56 +0000955 macro(MDNode) \
956 macro(MDString) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000957 macro(User) \
958 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +0000959 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000960 macro(ConstantAggregateZero) \
961 macro(ConstantArray) \
962 macro(ConstantExpr) \
963 macro(ConstantFP) \
964 macro(ConstantInt) \
965 macro(ConstantPointerNull) \
966 macro(ConstantStruct) \
967 macro(ConstantVector) \
968 macro(GlobalValue) \
969 macro(Function) \
970 macro(GlobalAlias) \
971 macro(GlobalVariable) \
972 macro(UndefValue) \
973 macro(Instruction) \
974 macro(BinaryOperator) \
975 macro(CallInst) \
976 macro(IntrinsicInst) \
977 macro(DbgInfoIntrinsic) \
978 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000979 macro(MemIntrinsic) \
980 macro(MemCpyInst) \
981 macro(MemMoveInst) \
982 macro(MemSetInst) \
983 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +0000984 macro(FCmpInst) \
985 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000986 macro(ExtractElementInst) \
987 macro(GetElementPtrInst) \
988 macro(InsertElementInst) \
989 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +0000990 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000991 macro(PHINode) \
992 macro(SelectInst) \
993 macro(ShuffleVectorInst) \
994 macro(StoreInst) \
995 macro(TerminatorInst) \
996 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +0000997 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +0000998 macro(InvokeInst) \
999 macro(ReturnInst) \
1000 macro(SwitchInst) \
1001 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001002 macro(ResumeInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001003 macro(UnaryInstruction) \
Victor Hernandez8acf2952009-10-23 21:09:37 +00001004 macro(AllocaInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001005 macro(CastInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +00001006 macro(BitCastInst) \
1007 macro(FPExtInst) \
1008 macro(FPToSIInst) \
1009 macro(FPToUIInst) \
1010 macro(FPTruncInst) \
1011 macro(IntToPtrInst) \
1012 macro(PtrToIntInst) \
1013 macro(SExtInst) \
1014 macro(SIToFPInst) \
1015 macro(TruncInst) \
1016 macro(UIToFPInst) \
1017 macro(ZExtInst) \
1018 macro(ExtractValueInst) \
Gordon Henriksen05a868f2008-12-19 18:51:17 +00001019 macro(LoadInst) \
1020 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001021
Gregory Szorc34c863a2012-03-21 03:54:29 +00001022/**
1023 * @defgroup LLVMCCoreValueGeneral General APIs
1024 *
1025 * Functions in this section work on all LLVMValueRef instances,
1026 * regardless of their sub-type. They correspond to functions available
1027 * on llvm::Value.
1028 *
1029 * @{
1030 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001031
Gregory Szorc34c863a2012-03-21 03:54:29 +00001032/**
1033 * Obtain the type of a value.
1034 *
1035 * @see llvm::Value::getType()
1036 */
1037LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1038
1039/**
1040 * Obtain the string name of a value.
1041 *
1042 * @see llvm::Value::getName()
1043 */
1044const char *LLVMGetValueName(LLVMValueRef Val);
1045
1046/**
1047 * Set the string name of a value.
1048 *
1049 * @see llvm::Value::setName()
1050 */
1051void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1052
1053/**
1054 * Dump a representation of a value to stderr.
1055 *
1056 * @see llvm::Value::dump()
1057 */
1058void LLVMDumpValue(LLVMValueRef Val);
1059
1060/**
1061 * Replace all uses of a value with another one.
1062 *
1063 * @see llvm::Value::replaceAllUsesWith()
1064 */
1065void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1066
1067/**
1068 * Determine whether the specified constant instance is constant.
1069 */
1070LLVMBool LLVMIsConstant(LLVMValueRef Val);
1071
1072/**
1073 * Determine whether a value instance is undefined.
1074 */
1075LLVMBool LLVMIsUndef(LLVMValueRef Val);
1076
1077/**
1078 * Convert value instances between types.
1079 *
1080 * Internally, a LLVMValueRef is "pinned" to a specific type. This
1081 * series of functions allows you to cast an instance to a specific
1082 * type.
1083 *
1084 * If the cast is not valid for the specified type, NULL is returned.
1085 *
1086 * @see llvm::dyn_cast_or_null<>
1087 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001088#define LLVM_DECLARE_VALUE_CAST(name) \
1089 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1090LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1091
Gregory Szorc34c863a2012-03-21 03:54:29 +00001092/**
1093 * @}
1094 */
1095
1096/**
1097 * @defgroup LLVMCCoreValueUses Usage
1098 *
1099 * This module defines functions that allow you to inspect the uses of a
1100 * LLVMValueRef.
1101 *
1102 * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1103 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1104 * llvm::User and llvm::Value.
1105 *
1106 * @{
1107 */
1108
1109/**
1110 * Obtain the first use of a value.
1111 *
1112 * Uses are obtained in an iterator fashion. First, call this function
1113 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1114 * on that instance and all subsequently obtained instances untl
1115 * LLVMGetNextUse() returns NULL.
1116 *
1117 * @see llvm::Value::use_begin()
1118 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001119LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001120
1121/**
1122 * Obtain the next use of a value.
1123 *
1124 * This effectively advances the iterator. It returns NULL if you are on
1125 * the final use and no more are available.
1126 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001127LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001128
1129/**
1130 * Obtain the user value for a user.
1131 *
1132 * The returned value corresponds to a llvm::User type.
1133 *
1134 * @see llvm::Use::getUser()
1135 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001136LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001137
1138/**
1139 * Obtain the value this use corresponds to.
1140 *
1141 * @see llvm::Use::get().
1142 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001143LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001144
Gregory Szorc34c863a2012-03-21 03:54:29 +00001145/**
1146 * @}
1147 */
1148
1149/**
1150 * @defgroup LLVMCValueUser User value
1151 *
1152 * Function in this group pertain to LLVMValueRef instances that descent
1153 * from llvm::User. This includes constants, instructions, and
1154 * operators.
1155 *
1156 * @{
1157 */
1158
1159/**
1160 * Obtain an operand at a specific index in a llvm::User value.
1161 *
1162 * @see llvm::User::getOperand()
1163 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001164LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001165
1166/**
1167 * Set an operand at a specific index in a llvm::User value.
1168 *
1169 * @see llvm::User::setOperand()
1170 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001171void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001172
1173/**
1174 * Obtain the number of operands in a llvm::User value.
1175 *
1176 * @see llvm::User::getNumOperands()
1177 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001178int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001179
Gregory Szorc34c863a2012-03-21 03:54:29 +00001180/**
1181 * @}
1182 */
1183
1184/**
1185 * @defgroup LLVMCoreValueConstant Constant values
1186 *
1187 * This section contains APIs for interacting with LLVMValueRef that
1188 * correspond to llvm::Constant instances.
1189 *
1190 * These functions will work for any LLVMValueRef in the llvm::Constant
1191 * class hierarchy.
1192 *
1193 * @{
1194 */
1195
1196/**
1197 * Obtain a constant value referring to the null instance of a type.
1198 *
1199 * @see llvm::Constant::getNullValue()
1200 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001201LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001202
1203/**
1204 * Obtain a constant value referring to the instance of a type
1205 * consisting of all ones.
1206 *
1207 * This is only valid for integer types.
1208 *
1209 * @see llvm::Constant::getAllOnesValue()
1210 */
1211LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1212
1213/**
1214 * Obtain a constant value referring to an undefined value of a type.
1215 *
1216 * @see llvm::UndefValue::get()
1217 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001218LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001219
1220/**
1221 * Determine whether a value instance is null.
1222 *
1223 * @see llvm::Constant::isNullValue()
1224 */
Chris Lattner25963c62010-01-09 22:27:07 +00001225LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001226
1227/**
1228 * Obtain a constant that is a constant pointer pointing to NULL for a
1229 * specified type.
1230 */
Chris Lattner7f318242009-07-06 17:29:59 +00001231LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001232
Gregory Szorc34c863a2012-03-21 03:54:29 +00001233/**
1234 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1235 *
1236 * Functions in this group model LLVMValueRef instances that correspond
1237 * to constants referring to scalar types.
1238 *
1239 * For integer types, the LLVMTypeRef parameter should correspond to a
1240 * llvm::IntegerType instance and the returned LLVMValueRef will
1241 * correspond to a llvm::ConstantInt.
1242 *
1243 * For floating point types, the LLVMTypeRef returned corresponds to a
1244 * llvm::ConstantFP.
1245 *
1246 * @{
1247 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001248
Gregory Szorc34c863a2012-03-21 03:54:29 +00001249/**
1250 * Obtain a constant value for an integer type.
1251 *
1252 * The returned value corresponds to a llvm::ConstantInt.
1253 *
1254 * @see llvm::ConstantInt::get()
1255 *
1256 * @param IntTy Integer type to obtain value of.
1257 * @param N The value the returned instance should refer to.
1258 * @param SignExtend Whether to sign extend the produced value.
1259 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001260LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001261 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001262
1263/**
1264 * Obtain a constant value for an integer of arbitrary precision.
1265 *
1266 * @see llvm::ConstantInt::get()
1267 */
Chris Lattner4329e072010-11-23 02:47:22 +00001268LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1269 unsigned NumWords,
1270 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001271
1272/**
1273 * Obtain a constant value for an integer parsed from a string.
1274 *
1275 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1276 * string's length is available, it is preferred to call that function
1277 * instead.
1278 *
1279 * @see llvm::ConstantInt::get()
1280 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001281LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1282 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001283
1284/**
1285 * Obtain a constant value for an integer parsed from a string with
1286 * specified length.
1287 *
1288 * @see llvm::ConstantInt::get()
1289 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001290LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1291 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001292
1293/**
1294 * Obtain a constant value referring to a double floating point value.
1295 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001296LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001297
1298/**
1299 * Obtain a constant for a floating point value parsed from a string.
1300 *
1301 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1302 * should be used if the input string's length is known.
1303 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001304LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001305
1306/**
1307 * Obtain a constant for a floating point value parsed from a string.
1308 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001309LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1310 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001311
1312/**
1313 * Obtain the zero extended value for an integer constant value.
1314 *
1315 * @see llvm::ConstantInt::getZExtValue()
1316 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001317unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001318
1319/**
1320 * Obtain the sign extended value for an integer constant value.
1321 *
1322 * @see llvm::ConstantInt::getSExtValue()
1323 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001324long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001325
Gregory Szorc34c863a2012-03-21 03:54:29 +00001326/**
1327 * @}
1328 */
1329
1330/**
1331 * @}
1332 */
1333
1334/**
1335 * @defgroup LLVMCCoreValueMetadata Metadata
1336 *
1337 * @{
1338 */
1339
1340/**
1341 * Obtain a MDString value from a context.
1342 *
1343 * The returned instance corresponds to the llvm::MDString class.
1344 *
1345 * The instance is specified by string data of a specified length. The
1346 * string content is copied, so the backing memory can be freed after
1347 * this function returns.
1348 */
1349LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1350 unsigned SLen);
1351
1352/**
1353 * Obtain a MDString value from the global context.
1354 */
1355LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1356
1357/**
1358 * Obtain a MDNode value from a context.
1359 *
1360 * The returned value corresponds to the llvm::MDNode class.
1361 */
1362LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1363 unsigned Count);
1364
1365/**
1366 * Obtain a MDNode value from the global context.
1367 */
1368LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1369
1370/**
1371 * Obtain the underlying string from a MDString value.
1372 *
1373 * @param V Instance to obtain string from.
1374 * @param Len Memory address which will hold length of returned string.
1375 * @return String data in MDString.
1376 */
1377const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1378
1379/**
1380 * @}
1381 */
1382
1383/**
1384 * @defgroup LLVMCCoreValueUNCATEGORIZED UNCATEGORIZED
1385 *
1386 * Functions in this group are not yet categorized. They belong
1387 * somewhere else and will be organized there in the future. Perhaps you
1388 * can help by submitting a patch to the documentation.
1389 *
1390 * @{
1391 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001392
1393/* Operations on composite constants */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001394LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001395 unsigned Length, LLVMBool DontNullTerminate);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001396LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1397 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001398 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001399
Gordon Henriksen1046c732007-10-06 15:11:06 +00001400LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
Chris Lattner25963c62010-01-09 22:27:07 +00001401 LLVMBool DontNullTerminate);
Gordon Henriksen2ad5aef2008-04-25 03:21:19 +00001402LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Gordon Henriksen1046c732007-10-06 15:11:06 +00001403 LLVMValueRef *ConstantVals, unsigned Length);
1404LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001405 LLVMBool Packed);
Rafael Espindola784ad242011-07-14 19:09:08 +00001406LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1407 LLVMValueRef *ConstantVals,
1408 unsigned Count);
Gordon Henriksen1046c732007-10-06 15:11:06 +00001409LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001410
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001411/* Constant expressions */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001412LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001413LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001414LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1415LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001416LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1417LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001418LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001419LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1420LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001421LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001422LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001423LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001424LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001425LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1426LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001427LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001428LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001429LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1430LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001431LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001432LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1433LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001434LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001435LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1436LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1437LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1438LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1439LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1440LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1441LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1442LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1443 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1444LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1445 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1446LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1447LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1448LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1449LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1450 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001451LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1452 LLVMValueRef *ConstantIndices,
1453 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001454LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1455LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1456LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1457LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1458LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1459LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1460LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1461LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1462LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1463LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1464LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1465LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001466LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1467 LLVMTypeRef ToType);
1468LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1469 LLVMTypeRef ToType);
1470LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1471 LLVMTypeRef ToType);
1472LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1473 LLVMTypeRef ToType);
1474LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001475 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001476LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001477LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1478 LLVMValueRef ConstantIfTrue,
1479 LLVMValueRef ConstantIfFalse);
1480LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1481 LLVMValueRef IndexConstant);
1482LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1483 LLVMValueRef ElementValueConstant,
1484 LLVMValueRef IndexConstant);
1485LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1486 LLVMValueRef VectorBConstant,
1487 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001488LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1489 unsigned NumIdx);
1490LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1491 LLVMValueRef ElementValueConstant,
1492 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001493LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001494 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001495 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001496LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001497
Gordon Henriksen76a03742007-09-18 03:18:57 +00001498/* Operations on global variables, functions, and aliases (globals) */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001499LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001500LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001501LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1502void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1503const char *LLVMGetSection(LLVMValueRef Global);
1504void LLVMSetSection(LLVMValueRef Global, const char *Section);
1505LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1506void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1507unsigned LLVMGetAlignment(LLVMValueRef Global);
1508void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1509
1510/* Operations on global variables */
1511LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001512LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1513 const char *Name,
1514 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001515LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001516LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1517LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1518LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1519LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001520void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001521LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1522void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001523LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1524void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1525LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1526void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001527
Chris Lattner3d1f5522008-12-17 21:39:50 +00001528/* Operations on aliases */
1529LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1530 const char *Name);
1531
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001532/* Operations on functions */
1533LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1534 LLVMTypeRef FunctionTy);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001535LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
Gordon Henriksen054817c2008-03-19 03:47:18 +00001536LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
1537LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
1538LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
1539LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001540
1541/**
1542 * @}
1543 */
1544
1545/**
1546 * @defgroup LLVMCCoreValueFunction Function values
1547 *
1548 * Functions in this group operate on LLVMValueRef instances that
1549 * correspond to llvm::Function instances.
1550 *
1551 * @see llvm::Function
1552 *
1553 * @{
1554 */
1555
1556/**
1557 * Remove a function from its containing module and deletes it.
1558 *
1559 * @see llvm::Function::eraseFromParent()
1560 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001561void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001562
1563/**
1564 * Obtain the ID number from a function instance.
1565 *
1566 * @see llvm::Function::getIntrinsicID()
1567 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001568unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001569
1570/**
1571 * Obtain the calling function of a function.
1572 *
1573 * The returned value corresponds to the LLVMCallConv enumeration.
1574 *
1575 * @see llvm::Function::getCallingConv()
1576 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001577unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001578
1579/**
1580 * Set the calling convention of a function.
1581 *
1582 * @see llvm::Function::setCallingConv()
1583 *
1584 * @param Fn Function to operate on
1585 * @param CC LLVMCallConv to set calling convention to
1586 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001587void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001588
1589/**
1590 * Obtain the name of the garbage collector to use during code
1591 * generation.
1592 *
1593 * @see llvm::Function::getGC()
1594 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001595const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001596
1597/**
1598 * Define the garbage collector to use during code generation.
1599 *
1600 * @see llvm::Function::setGC()
1601 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001602void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001603
1604/**
1605 * Add an attribute to a function.
1606 *
1607 * @see llvm::Function::addAttribute()
1608 */
Duncan Sands7374a012009-05-06 12:21:17 +00001609void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001610
1611/**
1612 * Obtain an attribute from a function.
1613 *
1614 * @see llvm::Function::getAttributes()
1615 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001616LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001617
1618/**
1619 * Remove an attribute from a function.
1620 */
Duncan Sands7374a012009-05-06 12:21:17 +00001621void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001622
Gregory Szorc34c863a2012-03-21 03:54:29 +00001623/**
1624 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1625 *
1626 * Functions in this group relate to arguments/parameters on functions.
1627 *
1628 * Functions in this group expect LLVMValueRef instances that correspond
1629 * to llvm::Function instances.
1630 *
1631 * @{
1632 */
1633
1634/**
1635 * Obtain the number of parameters in a function.
1636 *
1637 * @see llvm::Function::arg_size()
1638 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001639unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001640
1641/**
1642 * Obtain the parameters in a function.
1643 *
1644 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1645 * at least LLVMCountParams() long. This array will be filled with
1646 * LLVMValueRef instances which correspond to the parameters the
1647 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1648 * instance.
1649 *
1650 * @see llvm::Function::arg_begin()
1651 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001652void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001653
1654/**
1655 * Obtain the parameter at the specified index.
1656 *
1657 * Parameters are indexed from 0.
1658 *
1659 * @see llvm::Function::arg_begin()
1660 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001661LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001662
1663/**
1664 * Obtain the function to which this argument belongs.
1665 *
1666 * Unlike other functions in this group, this one takes a LLVMValueRef
1667 * that corresponds to a llvm::Attribute.
1668 *
1669 * The returned LLVMValueRef is the llvm::Function to which this
1670 * argument belongs.
1671 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001672LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001673
1674/**
1675 * Obtain the first parameter to a function.
1676 *
1677 * @see llvm::Function::arg_begin()
1678 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001679LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001680
1681/**
1682 * Obtain the last parameter to a function.
1683 *
1684 * @see llvm::Function::arg_end()
1685 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001686LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001687
1688/**
1689 * Obtain the next parameter to a function.
1690 *
1691 * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1692 * actually a wrapped iterator) and obtains the next parameter from the
1693 * underlying iterator.
1694 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001695LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001696
1697/**
1698 * Obtain the previous parameter to a function.
1699 *
1700 * This is the opposite of LLVMGetNextParam().
1701 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001702LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001703
1704/**
1705 * Add an attribute to a function argument.
1706 *
1707 * @see llvm::Argument::addAttr()
1708 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001709void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001710
1711/**
1712 * Remove an attribute from a function argument.
1713 *
1714 * @see llvm::Argument::removeAttr()
1715 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001716void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001717
1718/**
1719 * Get an attribute from a function argument.
1720 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001721LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001722
1723/**
1724 * Set the alignment for a function parameter.
1725 *
1726 * @see llvm::Argument::addAttr()
1727 * @see llvm::Attribute::constructAlignmentFromInt()
1728 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00001729void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00001730
Gregory Szorc34c863a2012-03-21 03:54:29 +00001731/**
1732 * @}
1733 */
1734
1735/**
1736 * @}
1737 */
1738
1739/**
1740 * @defgroup LLVMCCoreValueBasicBlock Basic Block
1741 *
1742 * A basic block represents a single entry single exit section of code.
1743 * Basic blocks contain a list of instructions which form the body of
1744 * the block.
1745 *
1746 * Basic blocks belong to functions. They have the type of label.
1747 *
1748 * Basic blocks are themselves values. However, the C API models them as
1749 * LLVMBasicBlockRef.
1750 *
1751 * @see llvm::BasicBlock
1752 *
1753 * @{
1754 */
1755
1756/**
1757 * Convert a basic block instance to a value type.
1758 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001759LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001760
1761/**
1762 * Determine whether a LLVMValueRef is itself a basic block.
1763 */
Chris Lattner25963c62010-01-09 22:27:07 +00001764LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001765
1766/**
1767 * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1768 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001769LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001770
1771/**
1772 * Obtain the function to which a basic block belongs.
1773 *
1774 * @see llvm::BasicBlock::getParent()
1775 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001776LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001777
1778/**
1779 * Obtain the terminator instruction for a basic block.
1780 *
1781 * If the basic block does not have a terminator (it is not well-formed
1782 * if it doesn't), then NULL is returned.
1783 *
1784 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1785 *
1786 * @see llvm::BasicBlock::getTerminator()
1787 */
Nate Begeman43c322b2011-08-23 20:27:46 +00001788LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001789
1790/**
1791 * Obtain the number of basic blocks in a function.
1792 *
1793 * @param Fn Function value to operate on.
1794 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001795unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001796
1797/**
1798 * Obtain all of the basic blocks in a function.
1799 *
1800 * This operates on a function value. The BasicBlocks parameter is a
1801 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1802 * LLVMCountBasicBlocks() in length. This array is populated with
1803 * LLVMBasicBlockRef instances.
1804 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001805void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001806
1807/**
1808 * Obtain the first basic block in a function.
1809 *
1810 * The returned basic block can be used as an iterator. You will likely
1811 * eventually call into LLVMGetNextBasicBlock() with it.
1812 *
1813 * @see llvm::Function::begin()
1814 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001815LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001816
1817/**
1818 * Obtain the last basic block in a function.
1819 *
1820 * @see llvm::Function::end()
1821 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001822LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001823
1824/**
1825 * Advance a basic block iterator.
1826 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001827LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001828
1829/**
1830 * Go backwards in a basic block iterator.
1831 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001832LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001833
1834/**
1835 * Obtain the basic block that corresponds to the entry point of a
1836 * function.
1837 *
1838 * @see llvm::Function::getEntryBlock()
1839 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001840LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001841
Gregory Szorc34c863a2012-03-21 03:54:29 +00001842/**
1843 * Append a basic block to the end of a function.
1844 *
1845 * @see llvm::BasicBlock::Create()
1846 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001847LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1848 LLVMValueRef Fn,
1849 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001850
1851/**
1852 * Append a basic block to the end of a function using the global
1853 * context.
1854 *
1855 * @see llvm::BasicBlock::Create()
1856 */
1857LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
1858
1859/**
1860 * Insert a basic block in a function before another basic block.
1861 *
1862 * The function to add to is determined by the function of the
1863 * passed basic block.
1864 *
1865 * @see llvm::BasicBlock::Create()
1866 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001867LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1868 LLVMBasicBlockRef BB,
1869 const char *Name);
1870
Gregory Szorc34c863a2012-03-21 03:54:29 +00001871/**
1872 * Insert a basic block in a function using the global context.
1873 *
1874 * @see llvm::BasicBlock::Create()
1875 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001876LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
1877 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001878
1879/**
1880 * Remove a basic block from a function and delete it.
1881 *
1882 * This deletes the basic block from its containing function and deletes
1883 * the basic block itself.
1884 *
1885 * @see llvm::BasicBlock::eraseFromParent()
1886 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001887void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001888
1889/**
1890 * Remove a basic block from a function.
1891 *
1892 * This deletes the basic block from its containing function but keep
1893 * the basic block alive.
1894 *
1895 * @see llvm::BasicBlock::removeFromParent()
1896 */
Nate Begeman43c322b2011-08-23 20:27:46 +00001897void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001898
Gregory Szorc34c863a2012-03-21 03:54:29 +00001899/**
1900 * Move a basic block to before another one.
1901 *
1902 * @see llvm::BasicBlock::moveBefore()
1903 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00001904void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001905
1906/**
1907 * Move a basic block to after another one.
1908 *
1909 * @see llvm::BasicBlock::moveAfter()
1910 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00001911void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
1912
Gregory Szorc34c863a2012-03-21 03:54:29 +00001913/**
1914 * Obtain the first instruction in a basic block.
1915 *
1916 * The returned LLVMValueRef corresponds to a llvm::Instruction
1917 * instance.
1918 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001919LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001920
1921/**
1922 * Obtain the last instruction in a basic block.
1923 *
1924 * The returned LLVMValueRef corresponds to a LLVM:Instruction.
1925 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001926LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00001927
Gregory Szorc34c863a2012-03-21 03:54:29 +00001928/**
1929 * @}
1930 */
1931
1932/**
1933 * @defgroup LLVMCCoreValueInstruction Instructions
1934 *
1935 * Functions in this group relate to the inspection and manipulation of
1936 * individual instructions.
1937 *
1938 * In the C++ API, an instruction is modeled by llvm::Instruction. This
1939 * class has a large number of descendents. llvm::Instruction is a
1940 * llvm::Value and in the C API, instructions are modeled by
1941 * LLVMValueRef.
1942 *
1943 * This group also contains sub-groups which operate on specific
1944 * llvm::Instruction types, e.g. llvm::CallInst.
1945 *
1946 * @{
1947 */
1948
1949/**
1950 * Determine whether an instruction has any metadata attached.
1951 */
1952int LLVMHasMetadata(LLVMValueRef Val);
1953
1954/**
1955 * Return metadata associated with an instruction value.
1956 */
1957LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
1958
1959/**
1960 * Set metadata associated with an instruction value.
1961 */
1962void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
1963
1964/**
1965 * Obtain the basic block to which an instruction belongs.
1966 *
1967 * @see llvm::Instruction::getParent()
1968 */
Nate Begeman43c322b2011-08-23 20:27:46 +00001969LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001970
1971/**
1972 * Obtain the instruction that occurs after the one specified.
1973 *
1974 * The next instruction will be from the same basic block.
1975 *
1976 * If this is the last instruction in a basic block, NULL will be
1977 * returned.
1978 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001979LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001980
1981/**
1982 * Obtain the instruction that occured before this one.
1983 *
1984 * If the instruction is the first instruction in a basic block, NULL
1985 * will be returned.
1986 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00001987LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001988
1989/**
1990 * Remove and delete an instruction.
1991 *
1992 * The instruction specified is removed from its containing building
1993 * block and then deleted.
1994 *
1995 * @see llvm::Instruction::eraseFromParent()
1996 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00001997void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001998
1999/**
2000 * Obtain the code opcode for an individual instruction.
2001 *
2002 * @see llvm::Instruction::getOpCode()
2003 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002004LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002005
2006/**
2007 * Obtain the predicate of an instruction.
2008 *
2009 * This is only valid for instructions that correspond to llvm::ICmpInst
2010 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2011 *
2012 * @see llvm::ICmpInst::getPredicate()
2013 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002014LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002015
Gregory Szorc34c863a2012-03-21 03:54:29 +00002016/**
2017 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2018 *
2019 * Functions in this group apply to instructions that refer to call
2020 * sites and invocations. These correspond to C++ types in the
2021 * llvm::CallInst class tree.
2022 *
2023 * @{
2024 */
2025
2026/**
2027 * Set the calling convention for a call instruction.
2028 *
2029 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2030 * llvm::InvokeInst.
2031 *
2032 * @see llvm::CallInst::setCallingConv()
2033 * @see llvm::InvokeInst::setCallingConv()
2034 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002035void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002036
2037/**
2038 * Obtain the calling convention for a call instruction.
2039 *
2040 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2041 * usage.
2042 *
2043 * @see LLVMSetInstructionCallConv()
2044 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002045unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002046
2047
Devang Patel4c758ea2008-09-25 21:00:45 +00002048void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002049void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002050 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002051void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002052 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002053
Gregory Szorc34c863a2012-03-21 03:54:29 +00002054/**
2055 * Obtain whether a call instruction is a tail call.
2056 *
2057 * This only works on llvm::CallInst instructions.
2058 *
2059 * @see llvm::CallInst::isTailCall()
2060 */
Chris Lattner25963c62010-01-09 22:27:07 +00002061LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002062
2063/**
2064 * Set whether a call instruction is a tail call.
2065 *
2066 * This only works on llvm::CallInst instructions.
2067 *
2068 * @see llvm::CallInst::setTailCall()
2069 */
Chris Lattner25963c62010-01-09 22:27:07 +00002070void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002071
Gregory Szorc34c863a2012-03-21 03:54:29 +00002072/**
2073 * @}
2074 */
2075
2076/**
2077 * Obtain the default destination basic block of a switch instruction.
2078 *
2079 * This only works on llvm::SwitchInst instructions.
2080 *
2081 * @see llvm::SwitchInst::getDefaultDest()
2082 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002083LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2084
Gregory Szorc34c863a2012-03-21 03:54:29 +00002085/**
2086 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2087 *
2088 * Functions in this group only apply to instructions that map to
2089 * llvm::PHINode instances.
2090 *
2091 * @{
2092 */
2093
2094/**
2095 * Add an incoming value to the end of a PHI list.
2096 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002097void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2098 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002099
2100/**
2101 * Obtain the number of incoming basic blocks to a PHI node.
2102 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002103unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002104
2105/**
2106 * Obtain an incoming value to a PHI node as a LLVMValueRef.
2107 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002108LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002109
2110/**
2111 * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2112 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002113LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002114
Gregory Szorc34c863a2012-03-21 03:54:29 +00002115/**
2116 * @}
2117 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002118
Gregory Szorc34c863a2012-03-21 03:54:29 +00002119/**
2120 * @}
2121 */
2122
2123/**
2124 * @}
2125 */
2126
2127/**
2128 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2129 *
2130 * An instruction builder represents a point within a basic block and is
2131 * the exclusive means of building instructions using the C interface.
2132 *
2133 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002134 */
2135
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002136LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002137LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002138void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2139 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002140void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2141void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002142LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002143void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2144void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002145void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2146 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002147void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2148
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002149/* Metadata */
2150void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2151LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2152void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2153
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002154/* Terminators */
2155LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2156LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002157LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002158 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002159LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2160LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2161 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2162LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2163 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002164LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2165 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002166LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2167 LLVMValueRef *Args, unsigned NumArgs,
2168 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2169 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002170LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2171 LLVMValueRef PersFn, unsigned NumClauses,
2172 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002173LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002174LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2175
Gordon Henriksen097102c2008-01-01 05:50:53 +00002176/* Add a case to the switch instruction */
2177void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2178 LLVMBasicBlockRef Dest);
2179
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002180/* Add a destination to the indirectbr instruction */
2181void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2182
Bill Wendlingfae14752011-08-12 20:24:12 +00002183/* Add a catch or filter clause to the landingpad instruction */
2184void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2185
2186/* Set the 'cleanup' flag in the landingpad instruction */
2187void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2188
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002189/* Arithmetic */
2190LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2191 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002192LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2193 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002194LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2195 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002196LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2197 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002198LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2199 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002200LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2201 const char *Name);
2202LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2203 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002204LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2205 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002206LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2207 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002208LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2209 const char *Name);
2210LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2211 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002212LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2213 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002214LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2215 const char *Name);
2216LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2217 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002218LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2219 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002220LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2221 const char *Name);
2222LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2223 const char *Name);
2224LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2225 const char *Name);
2226LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2227 const char *Name);
2228LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2229 const char *Name);
2230LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2231 const char *Name);
2232LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2233 const char *Name);
2234LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2235 const char *Name);
2236LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2237 const char *Name);
2238LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2239 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002240LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2241 LLVMValueRef LHS, LLVMValueRef RHS,
2242 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002243LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002244LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2245 const char *Name);
2246LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2247 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002248LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002249LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2250
2251/* Memory */
2252LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2253LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2254 LLVMValueRef Val, const char *Name);
2255LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2256LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2257 LLVMValueRef Val, const char *Name);
2258LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2259LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2260 const char *Name);
2261LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2262LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2263 LLVMValueRef *Indices, unsigned NumIndices,
2264 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002265LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2266 LLVMValueRef *Indices, unsigned NumIndices,
2267 const char *Name);
2268LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2269 unsigned Idx, const char *Name);
2270LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2271 const char *Name);
2272LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2273 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002274
2275/* Casts */
2276LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2277 LLVMTypeRef DestTy, const char *Name);
2278LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2279 LLVMTypeRef DestTy, const char *Name);
2280LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2281 LLVMTypeRef DestTy, const char *Name);
2282LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2283 LLVMTypeRef DestTy, const char *Name);
2284LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2285 LLVMTypeRef DestTy, const char *Name);
2286LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2287 LLVMTypeRef DestTy, const char *Name);
2288LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2289 LLVMTypeRef DestTy, const char *Name);
2290LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2291 LLVMTypeRef DestTy, const char *Name);
2292LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2293 LLVMTypeRef DestTy, const char *Name);
2294LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2295 LLVMTypeRef DestTy, const char *Name);
2296LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2297 LLVMTypeRef DestTy, const char *Name);
2298LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2299 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002300LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2301 LLVMTypeRef DestTy, const char *Name);
2302LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2303 LLVMTypeRef DestTy, const char *Name);
2304LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2305 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002306LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2307 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002308LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2309 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002310LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002311 LLVMTypeRef DestTy, const char *Name);
2312LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2313 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002314
2315/* Comparisons */
2316LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2317 LLVMValueRef LHS, LLVMValueRef RHS,
2318 const char *Name);
2319LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2320 LLVMValueRef LHS, LLVMValueRef RHS,
2321 const char *Name);
2322
2323/* Miscellaneous instructions */
2324LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2325LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2326 LLVMValueRef *Args, unsigned NumArgs,
2327 const char *Name);
2328LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2329 LLVMValueRef Then, LLVMValueRef Else,
2330 const char *Name);
2331LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2332 const char *Name);
2333LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2334 LLVMValueRef Index, const char *Name);
2335LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2336 LLVMValueRef EltVal, LLVMValueRef Index,
2337 const char *Name);
2338LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2339 LLVMValueRef V2, LLVMValueRef Mask,
2340 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002341LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2342 unsigned Index, const char *Name);
2343LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2344 LLVMValueRef EltVal, unsigned Index,
2345 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002346
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002347LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2348 const char *Name);
2349LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2350 const char *Name);
2351LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2352 LLVMValueRef RHS, const char *Name);
2353
Gregory Szorc34c863a2012-03-21 03:54:29 +00002354/**
2355 * @}
2356 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002357
Gregory Szorc34c863a2012-03-21 03:54:29 +00002358/**
2359 * @defgroup LLVMCCoreModuleProvider Module Providers
2360 *
2361 * @{
2362 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002363
Gregory Szorc34c863a2012-03-21 03:54:29 +00002364/**
2365 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002366 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002367 */
2368LLVMModuleProviderRef
2369LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2370
Gregory Szorc34c863a2012-03-21 03:54:29 +00002371/**
2372 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002373 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002374void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002375
Gregory Szorc34c863a2012-03-21 03:54:29 +00002376/**
2377 * @}
2378 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002379
Gregory Szorc34c863a2012-03-21 03:54:29 +00002380/**
2381 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2382 *
2383 * @{
2384 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002385
Chris Lattner25963c62010-01-09 22:27:07 +00002386LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2387 LLVMMemoryBufferRef *OutMemBuf,
2388 char **OutMessage);
2389LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2390 char **OutMessage);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002391void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2392
Gregory Szorc34c863a2012-03-21 03:54:29 +00002393/**
2394 * @}
2395 */
2396
2397/**
2398 * @defgroup LLVMCCorePassRegistry Pass Registry
2399 *
2400 * @{
2401 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002402
2403/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002404 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002405LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002406
Gregory Szorc34c863a2012-03-21 03:54:29 +00002407/**
2408 * @}
2409 */
2410
2411/**
2412 * @defgroup LLVMCCorePassManagers Pass Managers
2413 *
2414 * @{
2415 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002416
2417/** Constructs a new whole-module pass pipeline. This type of pipeline is
2418 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002419 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002420LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002421
2422/** Constructs a new function-by-function pass pipeline over the module
2423 provider. It does not take ownership of the module provider. This type of
2424 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002425 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002426LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2427
2428/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002429LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2430
2431/** Initializes, executes on the provided module, and finalizes all of the
2432 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002433 modified the module, 0 otherwise.
2434 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002435LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002436
2437/** Initializes all of the function passes scheduled in the function pass
2438 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002439 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002440LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002441
2442/** Executes all of the function passes scheduled in the function pass manager
2443 on the provided function. Returns 1 if any of the passes modified the
2444 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002445 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002446LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002447
2448/** Finalizes all of the function passes scheduled in in the function pass
2449 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002450 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002451LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002452
2453/** Frees the memory of a pass pipeline. For function pipelines, does not free
2454 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002455 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002456void LLVMDisposePassManager(LLVMPassManagerRef PM);
2457
Gregory Szorc34c863a2012-03-21 03:54:29 +00002458/**
2459 * @}
2460 */
2461
2462/**
2463 * @}
2464 */
2465
2466/**
2467 * @}
2468 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002469
Gordon Henriksen76a03742007-09-18 03:18:57 +00002470#ifdef __cplusplus
2471}
Gordon Henriksen76a03742007-09-18 03:18:57 +00002472
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002473namespace llvm {
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002474 class MemoryBuffer;
Gordon Henriksen96571492008-03-16 15:55:43 +00002475 class PassManagerBase;
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002476
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002477 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2478 inline ty *unwrap(ref P) { \
2479 return reinterpret_cast<ty*>(P); \
2480 } \
2481 \
2482 inline ref wrap(const ty *P) { \
2483 return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2484 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002485
Gordon Henriksen878114b2008-03-16 04:20:44 +00002486 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \
2487 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2488 \
2489 template<typename T> \
2490 inline T *unwrap(ref P) { \
2491 return cast<T>(unwrap(P)); \
2492 }
2493
2494 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
2495 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
2496 \
2497 template<typename T> \
2498 inline T *unwrap(ref P) { \
Chris Lattner7ba06612010-01-22 06:49:46 +00002499 T *Q = (T*)unwrap(P); \
Gordon Henriksen878114b2008-03-16 04:20:44 +00002500 assert(Q && "Invalid cast!"); \
2501 return Q; \
2502 }
2503
2504 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef )
2505 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +00002506 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
2507 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
Eric Christopher59278832008-08-08 19:39:37 +00002508 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
Gordon Henriksen823f9732007-12-27 18:25:59 +00002509 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
Owen Anderson6773d382009-07-01 16:58:40 +00002510 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00002511 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
Gordon Henriksen878114b2008-03-16 04:20:44 +00002512 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef )
Owen Anderson4698c5d2010-10-07 17:55:47 +00002513 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef )
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002514 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2515 * Module.
2516 */
2517 inline Module *unwrap(LLVMModuleProviderRef MP) {
2518 return reinterpret_cast<Module*>(MP);
2519 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002520
Gordon Henriksen878114b2008-03-16 04:20:44 +00002521 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2522 #undef DEFINE_ISA_CONVERSION_FUNCTIONS
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002523 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002524
2525 /* Specialized opaque context conversions.
2526 */
2527 inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2528 return reinterpret_cast<LLVMContext**>(Tys);
2529 }
2530
2531 inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2532 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2533 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002534
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002535 /* Specialized opaque type conversions.
2536 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002537 inline Type **unwrap(LLVMTypeRef* Tys) {
2538 return reinterpret_cast<Type**>(Tys);
2539 }
2540
Chris Lattner229907c2011-07-18 04:54:35 +00002541 inline LLVMTypeRef *wrap(Type **Tys) {
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002542 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2543 }
2544
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002545 /* Specialized opaque value conversions.
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002546 */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002547 inline Value **unwrap(LLVMValueRef *Vals) {
2548 return reinterpret_cast<Value**>(Vals);
2549 }
2550
2551 template<typename T>
2552 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2553 #if DEBUG
Chris Lattnerb7971152009-07-10 18:28:19 +00002554 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002555 cast<T>(*I);
2556 #endif
Hans Wennborg8f7edbf2011-06-04 16:00:19 +00002557 (void)Length;
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002558 return reinterpret_cast<T**>(Vals);
2559 }
2560
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002561 inline LLVMValueRef *wrap(const Value **Vals) {
2562 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2563 }
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002564}
2565
2566#endif /* !defined(__cplusplus) */
2567
2568#endif /* !defined(LLVM_C_CORE_H) */