blob: f37e3f89ca3e118f3d477108d6173c9932a09ba6 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
Chris Lattnere9cc7422007-12-29 19:59:42 +00005|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
Gordon Henriksen76a03742007-09-18 03:18:57 +00007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header declares the C interface to libLLVMCore.a, which implements *|
11|* the LLVM intermediate representation. *|
12|* *|
Gordon Henriksen76a03742007-09-18 03:18:57 +000013\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_C_CORE_H
16#define LLVM_C_CORE_H
17
Chandler Carruth3c57aa42014-03-06 04:13:12 +000018#include "llvm-c/Support.h"
Erick Tryzelaardd991352009-08-16 23:36:46 +000019
Evan Cheng2e254d02013-04-04 17:40:53 +000020#ifdef __cplusplus
Gordon Henriksen76a03742007-09-18 03:18:57 +000021extern "C" {
22#endif
23
Gregory Szorc34c863a2012-03-21 03:54:29 +000024/**
25 * @defgroup LLVMC LLVM-C: C interface to LLVM
26 *
27 * This module exposes parts of the LLVM library as a C API.
28 *
29 * @{
30 */
31
32/**
33 * @defgroup LLVMCTransforms Transforms
34 */
35
36/**
37 * @defgroup LLVMCCore Core
38 *
39 * This modules provide an interface to libLLVMCore, which implements
40 * the LLVM intermediate representation as well as other related types
41 * and utilities.
42 *
43 * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
44 * parameters must be passed as base types. Despite the declared types, most
45 * of the functions provided operate only on branches of the type hierarchy.
46 * The declared parameter names are descriptive and specify which type is
47 * required. Additionally, each type hierarchy is documented along with the
48 * functions that operate upon it. For more detail, refer to LLVM's C++ code.
Eli Bendersky870d0572012-08-10 18:26:20 +000049 * If in doubt, refer to Core.cpp, which performs parameter downcasts in the
Gregory Szorc34c863a2012-03-21 03:54:29 +000050 * form unwrap<RequiredType>(Param).
51 *
52 * Many exotic languages can interoperate with C code but have a harder time
53 * with C++ due to name mangling. So in addition to C, this interface enables
54 * tools written in such languages.
55 *
Gregory Szorc34c863a2012-03-21 03:54:29 +000056 * @{
57 */
58
59/**
60 * @defgroup LLVMCCoreTypes Types and Enumerations
61 *
62 * @{
63 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000064
65/* Opaque types. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000066
67/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000068 * The top-level container for all LLVM global data. See the LLVMContext class.
Owen Anderson6773d382009-07-01 16:58:40 +000069 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +000070typedef struct LLVMOpaqueContext *LLVMContextRef;
Owen Anderson6773d382009-07-01 16:58:40 +000071
72/**
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000073 * The top-level container for all other LLVM Intermediate Representation (IR)
Gregory Szorc34c863a2012-03-21 03:54:29 +000074 * objects.
75 *
76 * @see llvm::Module
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000077 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000078typedef struct LLVMOpaqueModule *LLVMModuleRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000079
80/**
Gregory Szorc34c863a2012-03-21 03:54:29 +000081 * Each value in the LLVM IR has a type, an LLVMTypeRef.
82 *
83 * @see llvm::Type
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000084 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000085typedef struct LLVMOpaqueType *LLVMTypeRef;
Gordon Henriksen4a4d7352007-12-30 17:46:33 +000086
Gregory Szorc34c863a2012-03-21 03:54:29 +000087/**
88 * Represents an individual value in LLVM IR.
89 *
90 * This models llvm::Value.
91 */
Gordon Henriksen76a03742007-09-18 03:18:57 +000092typedef struct LLVMOpaqueValue *LLVMValueRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +000093
94/**
Eli Bendersky870d0572012-08-10 18:26:20 +000095 * Represents a basic block of instructions in LLVM IR.
Gregory Szorc34c863a2012-03-21 03:54:29 +000096 *
97 * This models llvm::BasicBlock.
98 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +000099typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
Gregory Szorc34c863a2012-03-21 03:54:29 +0000100
101/**
102 * Represents an LLVM basic block builder.
103 *
104 * This models llvm::IRBuilder.
105 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000106typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000107
Gregory Szorc34c863a2012-03-21 03:54:29 +0000108/**
109 * Interface used to provide a module to JIT or interpreter.
110 * This is now just a synonym for llvm::Module, but we have to keep using the
111 * different type to keep binary compatibility.
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000112 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +0000113typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
Gordon Henriksen76a03742007-09-18 03:18:57 +0000114
Gregory Szorc34c863a2012-03-21 03:54:29 +0000115/** @see llvm::PassManagerBase */
Gordon Henriksen878114b2008-03-16 04:20:44 +0000116typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
117
Gregory Szorc34c863a2012-03-21 03:54:29 +0000118/** @see llvm::PassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +0000119typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
120
Gregory Szorc34c863a2012-03-21 03:54:29 +0000121/**
122 * Used to get the users and usees of a Value.
123 *
124 * @see llvm::Use */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +0000125typedef struct LLVMOpaqueUse *LLVMUseRef;
Chris Lattner40cf28d2009-10-12 04:01:02 +0000126
Tom Stellard1580dc72014-04-16 17:45:04 +0000127
128/**
129 * @see llvm::DiagnosticInfo
130 */
131typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
132
Gordon Henriksen76a03742007-09-18 03:18:57 +0000133typedef enum {
Devang Patel4c758ea2008-09-25 21:00:45 +0000134 LLVMZExtAttribute = 1<<0,
135 LLVMSExtAttribute = 1<<1,
136 LLVMNoReturnAttribute = 1<<2,
137 LLVMInRegAttribute = 1<<3,
138 LLVMStructRetAttribute = 1<<4,
139 LLVMNoUnwindAttribute = 1<<5,
140 LLVMNoAliasAttribute = 1<<6,
141 LLVMByValAttribute = 1<<7,
142 LLVMNestAttribute = 1<<8,
143 LLVMReadNoneAttribute = 1<<9,
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +0000144 LLVMReadOnlyAttribute = 1<<10,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000145 LLVMNoInlineAttribute = 1<<11,
146 LLVMAlwaysInlineAttribute = 1<<12,
147 LLVMOptimizeForSizeAttribute = 1<<13,
148 LLVMStackProtectAttribute = 1<<14,
149 LLVMStackProtectReqAttribute = 1<<15,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000150 LLVMAlignment = 31<<16,
Anton Korobeynikov9750be92009-07-17 18:57:16 +0000151 LLVMNoCaptureAttribute = 1<<21,
152 LLVMNoRedZoneAttribute = 1<<22,
153 LLVMNoImplicitFloatAttribute = 1<<23,
Jakob Stoklund Olesen74bb06c2010-02-06 01:16:28 +0000154 LLVMNakedAttribute = 1<<24,
Erick Tryzelaar8f69fea2010-03-03 23:51:25 +0000155 LLVMInlineHintAttribute = 1<<25,
Torok Edwin1db48c02011-10-06 12:13:32 +0000156 LLVMStackAlignment = 7<<26,
157 LLVMReturnsTwice = 1 << 29,
158 LLVMUWTable = 1 << 30,
Chandler Carruth44d69d92012-01-25 07:40:15 +0000159 LLVMNonLazyBind = 1 << 31
160
Bill Wendlingd154e2832013-01-23 06:41:41 +0000161 /* FIXME: These attributes are currently not included in the C API as
Nuno Lopesdef4229972012-09-02 14:19:21 +0000162 a temporary measure until the API/ABI impact to the C API is understood
163 and the path forward agreed upon.
Bill Wendlingd154e2832013-01-23 06:41:41 +0000164 LLVMAddressSafety = 1ULL << 32,
Andrea Di Biagio377496b2013-08-23 11:53:55 +0000165 LLVMStackProtectStrongAttribute = 1ULL<<33,
166 LLVMCold = 1ULL << 34,
Reid Klecknera534a382013-12-19 02:14:12 +0000167 LLVMOptimizeNone = 1ULL << 35,
Nick Lewyckyd52b1522014-05-20 01:23:40 +0000168 LLVMInAllocaAttribute = 1ULL << 36,
169 LLVMNonNullAttribute = 1ULL << 37
Nuno Lopesdef4229972012-09-02 14:19:21 +0000170 */
Devang Patel4c758ea2008-09-25 21:00:45 +0000171} LLVMAttribute;
Gordon Henriksen2d9cc212008-04-28 17:37:06 +0000172
173typedef enum {
Bill Wendlingda52cec2010-02-15 20:53:17 +0000174 /* Terminator Instructions */
Chris Lattner40cf28d2009-10-12 04:01:02 +0000175 LLVMRet = 1,
176 LLVMBr = 2,
177 LLVMSwitch = 3,
Bill Wendling07d6d762010-02-15 20:50:51 +0000178 LLVMIndirectBr = 4,
179 LLVMInvoke = 5,
Bill Wendling46ffaa92011-08-02 06:20:17 +0000180 /* removed 6 due to API changes */
Bill Wendling2641d132011-07-27 21:00:28 +0000181 LLVMUnreachable = 7,
Bill Wendling07d6d762010-02-15 20:50:51 +0000182
Bill Wendlingda52cec2010-02-15 20:53:17 +0000183 /* Standard Binary Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000184 LLVMAdd = 8,
185 LLVMFAdd = 9,
186 LLVMSub = 10,
187 LLVMFSub = 11,
188 LLVMMul = 12,
189 LLVMFMul = 13,
190 LLVMUDiv = 14,
191 LLVMSDiv = 15,
192 LLVMFDiv = 16,
193 LLVMURem = 17,
194 LLVMSRem = 18,
195 LLVMFRem = 19,
Bill Wendling07d6d762010-02-15 20:50:51 +0000196
Bill Wendlingda52cec2010-02-15 20:53:17 +0000197 /* Logical Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000198 LLVMShl = 20,
199 LLVMLShr = 21,
200 LLVMAShr = 22,
201 LLVMAnd = 23,
202 LLVMOr = 24,
203 LLVMXor = 25,
Bill Wendling07d6d762010-02-15 20:50:51 +0000204
Bill Wendlingda52cec2010-02-15 20:53:17 +0000205 /* Memory Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000206 LLVMAlloca = 26,
207 LLVMLoad = 27,
208 LLVMStore = 28,
209 LLVMGetElementPtr = 29,
Bill Wendling07d6d762010-02-15 20:50:51 +0000210
Bill Wendlingda52cec2010-02-15 20:53:17 +0000211 /* Cast Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000212 LLVMTrunc = 30,
213 LLVMZExt = 31,
214 LLVMSExt = 32,
215 LLVMFPToUI = 33,
216 LLVMFPToSI = 34,
217 LLVMUIToFP = 35,
218 LLVMSIToFP = 36,
219 LLVMFPTrunc = 37,
220 LLVMFPExt = 38,
221 LLVMPtrToInt = 39,
222 LLVMIntToPtr = 40,
223 LLVMBitCast = 41,
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000224 LLVMAddrSpaceCast = 60,
Bill Wendling07d6d762010-02-15 20:50:51 +0000225
Bill Wendlingda52cec2010-02-15 20:53:17 +0000226 /* Other Operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000227 LLVMICmp = 42,
228 LLVMFCmp = 43,
229 LLVMPHI = 44,
230 LLVMCall = 45,
231 LLVMSelect = 46,
Torok Edwin05dc9d62011-10-06 12:39:34 +0000232 LLVMUserOp1 = 47,
233 LLVMUserOp2 = 48,
Bill Wendling2641d132011-07-27 21:00:28 +0000234 LLVMVAArg = 49,
235 LLVMExtractElement = 50,
236 LLVMInsertElement = 51,
237 LLVMShuffleVector = 52,
238 LLVMExtractValue = 53,
239 LLVMInsertValue = 54,
Eli Friedman4fc946c2011-07-27 18:59:19 +0000240
241 /* Atomic operators */
Bill Wendling2641d132011-07-27 21:00:28 +0000242 LLVMFence = 55,
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000243 LLVMAtomicCmpXchg = 56,
Bill Wendlingf891bf82011-07-31 06:30:59 +0000244 LLVMAtomicRMW = 57,
245
246 /* Exception Handling Operators */
Bill Wendlingfae14752011-08-12 20:24:12 +0000247 LLVMResume = 58,
Bill Wendling0aef16a2012-02-06 21:44:22 +0000248 LLVMLandingPad = 59
Bill Wendling2641d132011-07-27 21:00:28 +0000249
Chris Lattner40cf28d2009-10-12 04:01:02 +0000250} LLVMOpcode;
251
252typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000253 LLVMVoidTypeKind, /**< type with no size */
Dan Gohman518cda42011-12-17 00:04:22 +0000254 LLVMHalfTypeKind, /**< 16 bit floating point type */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000255 LLVMFloatTypeKind, /**< 32 bit floating point type */
256 LLVMDoubleTypeKind, /**< 64 bit floating point type */
257 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
258 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
259 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
260 LLVMLabelTypeKind, /**< Labels */
261 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
262 LLVMFunctionTypeKind, /**< Functions */
263 LLVMStructTypeKind, /**< Structures */
264 LLVMArrayTypeKind, /**< Arrays */
265 LLVMPointerTypeKind, /**< Pointers */
Chris Lattnerdac44ec2009-07-15 22:00:31 +0000266 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
Dale Johannesenbaa5d042010-09-10 20:55:01 +0000267 LLVMMetadataTypeKind, /**< Metadata */
268 LLVMX86_MMXTypeKind /**< X86 MMX */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000269} LLVMTypeKind;
270
271typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000272 LLVMExternalLinkage, /**< Externally visible function */
Chris Lattner2dba0f02009-04-13 06:25:37 +0000273 LLVMAvailableExternallyLinkage,
Duncan Sands12da8ce2009-03-07 15:45:40 +0000274 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
275 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
276 equivalent. */
Rafael Espindola716e7402013-11-01 17:09:14 +0000277 LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000278 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
279 LLVMWeakODRLinkage, /**< Same, but only replaced by something
280 equivalent. */
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000281 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
282 LLVMInternalLinkage, /**< Rename collisions when linking (static
283 functions) */
Duncan Sands12da8ce2009-03-07 15:45:40 +0000284 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
Nico Rieck7157bb72014-01-14 15:22:47 +0000285 LLVMDLLImportLinkage, /**< Obsolete */
286 LLVMDLLExportLinkage, /**< Obsolete */
Duncan Sandse2881052009-03-11 08:08:06 +0000287 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000288 LLVMGhostLinkage, /**< Obsolete */
Bill Wendling002b1672009-07-20 18:22:52 +0000289 LLVMCommonLinkage, /**< Tentative definitions */
Bill Wendling03bcd6e2010-07-01 21:55:59 +0000290 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
Bill Wendling34bc34e2012-08-17 18:33:14 +0000291 LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000292} LLVMLinkage;
293
294typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000295 LLVMDefaultVisibility, /**< The GV is visible */
296 LLVMHiddenVisibility, /**< The GV is hidden */
297 LLVMProtectedVisibility /**< The GV is protected */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000298} LLVMVisibility;
299
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000300typedef enum {
Reid Kleckner2fae26f2014-03-05 02:34:23 +0000301 LLVMDefaultStorageClass = 0,
302 LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
303 LLVMDLLExportStorageClass = 2 /**< Function to be accessible from DLL. */
304} LLVMDLLStorageClass;
305
306typedef enum {
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000307 LLVMCCallConv = 0,
308 LLVMFastCallConv = 8,
309 LLVMColdCallConv = 9,
Filip Pizlodfc9b582013-11-09 06:00:03 +0000310 LLVMWebKitJSCallConv = 12,
311 LLVMAnyRegCallConv = 13,
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000312 LLVMX86StdcallCallConv = 64,
313 LLVMX86FastcallCallConv = 65
314} LLVMCallConv;
315
316typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000317 LLVMIntEQ = 32, /**< equal */
318 LLVMIntNE, /**< not equal */
319 LLVMIntUGT, /**< unsigned greater than */
320 LLVMIntUGE, /**< unsigned greater or equal */
321 LLVMIntULT, /**< unsigned less than */
322 LLVMIntULE, /**< unsigned less or equal */
323 LLVMIntSGT, /**< signed greater than */
324 LLVMIntSGE, /**< signed greater or equal */
325 LLVMIntSLT, /**< signed less than */
326 LLVMIntSLE /**< signed less or equal */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000327} LLVMIntPredicate;
328
329typedef enum {
Gordon Henriksen4a4d7352007-12-30 17:46:33 +0000330 LLVMRealPredicateFalse, /**< Always false (always folded) */
331 LLVMRealOEQ, /**< True if ordered and equal */
332 LLVMRealOGT, /**< True if ordered and greater than */
333 LLVMRealOGE, /**< True if ordered and greater than or equal */
334 LLVMRealOLT, /**< True if ordered and less than */
335 LLVMRealOLE, /**< True if ordered and less than or equal */
336 LLVMRealONE, /**< True if ordered and operands are unequal */
337 LLVMRealORD, /**< True if ordered (no nans) */
338 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
339 LLVMRealUEQ, /**< True if unordered or equal */
340 LLVMRealUGT, /**< True if unordered or greater than */
341 LLVMRealUGE, /**< True if unordered, greater than, or equal */
342 LLVMRealULT, /**< True if unordered or less than */
343 LLVMRealULE, /**< True if unordered, less than, or equal */
344 LLVMRealUNE, /**< True if unordered or not equal */
345 LLVMRealPredicateTrue /**< Always true (always folded) */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000346} LLVMRealPredicate;
347
Bill Wendlingfae14752011-08-12 20:24:12 +0000348typedef enum {
349 LLVMLandingPadCatch, /**< A catch clause */
350 LLVMLandingPadFilter /**< A filter clause */
351} LLVMLandingPadClauseTy;
352
Hans Wennborg5ff71202013-04-16 08:58:59 +0000353typedef enum {
354 LLVMNotThreadLocal = 0,
355 LLVMGeneralDynamicTLSModel,
356 LLVMLocalDynamicTLSModel,
357 LLVMInitialExecTLSModel,
358 LLVMLocalExecTLSModel
359} LLVMThreadLocalMode;
360
Carlo Kokda0ac722013-04-23 13:45:37 +0000361typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000362 LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
363 LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
364 somewhat sane results, lock free. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000365 LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
366 operations affecting a specific address,
Carlo Kok8c6719b2013-04-23 13:21:19 +0000367 a consistent ordering exists */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000368 LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
369 necessary to acquire a lock to access other
Carlo Kok8c6719b2013-04-23 13:21:19 +0000370 memory with normal loads and stores. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000371 LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
372 a barrier of the sort necessary to release
Carlo Kok8c6719b2013-04-23 13:21:19 +0000373 a lock. */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000374 LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
375 Release barrier (for fences and
Carlo Kok8c6719b2013-04-23 13:21:19 +0000376 operations which both read and write
377 memory). */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000378 LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
379 for loads and Release
380 semantics for stores.
381 Additionally, it guarantees
382 that a total ordering exists
383 between all
384 SequentiallyConsistent
Carlo Kok8c6719b2013-04-23 13:21:19 +0000385 operations. */
Carlo Kokda0ac722013-04-23 13:45:37 +0000386} LLVMAtomicOrdering;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000387
Carlo Kokda0ac722013-04-23 13:45:37 +0000388typedef enum {
Carlo Kok8c6719b2013-04-23 13:21:19 +0000389 LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
390 LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
391 LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
392 LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
393 LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
394 LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
395 LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
396 LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000397 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000398 the old one */
399 LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000400 original using a signed comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000401 the old one */
402 LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000403 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000404 the old one */
405 LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000406 original using an unsigned comparison and return
Carlo Kok8c6719b2013-04-23 13:21:19 +0000407 the old one */
Carlo Kokda0ac722013-04-23 13:45:37 +0000408} LLVMAtomicRMWBinOp;
Carlo Kok8c6719b2013-04-23 13:21:19 +0000409
Tom Stellard1580dc72014-04-16 17:45:04 +0000410typedef enum {
411 LLVMDSError,
412 LLVMDSWarning,
413 LLVMDSRemark,
414 LLVMDSNote
415} LLVMDiagnosticSeverity;
416
Gregory Szorc34c863a2012-03-21 03:54:29 +0000417/**
418 * @}
419 */
420
Nick Lewycky0db26542011-05-15 07:20:34 +0000421void LLVMInitializeCore(LLVMPassRegistryRef R);
422
Duncan Sands1cba0a82013-02-17 16:35:51 +0000423/** Deallocate and destroy all ManagedStatic variables.
424 @see llvm::llvm_shutdown
425 @see ManagedStatic */
Benjamin Kramer325ec892013-10-23 16:57:34 +0000426void LLVMShutdown(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +0000427
Gordon Henriksen76a03742007-09-18 03:18:57 +0000428
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000429/*===-- Error handling ----------------------------------------------------===*/
430
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000431char *LLVMCreateMessage(const char *Message);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000432void LLVMDisposeMessage(char *Message);
433
Filip Pizloa535b142013-10-17 01:38:28 +0000434typedef void (*LLVMFatalErrorHandler)(const char *Reason);
435
436/**
437 * Install a fatal error handler. By default, if LLVM detects a fatal error, it
438 * will call exit(1). This may not be appropriate in many contexts. For example,
439 * doing exit(1) will bypass many crash reporting/tracing system tools. This
440 * function allows you to install a callback that will be invoked prior to the
441 * call to exit(1).
442 */
443void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
444
445/**
446 * Reset the fatal error handler. This resets LLVM's fatal error handling
447 * behavior to the default.
448 */
449void LLVMResetFatalErrorHandler(void);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +0000450
Gregory Szorc34c863a2012-03-21 03:54:29 +0000451/**
Filip Pizloc10ca902013-11-04 02:22:25 +0000452 * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
453 * signals and prints which component of LLVM you were in at the time if the
454 * crash.
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000455 */
Filip Pizloc10ca902013-11-04 02:22:25 +0000456void LLVMEnablePrettyStackTrace(void);
Filip Pizlo9f50ccd2013-11-03 00:29:47 +0000457
458/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000459 * @defgroup LLVMCCoreContext Contexts
460 *
461 * Contexts are execution states for the core LLVM IR system.
462 *
463 * Most types are tied to a context instance. Multiple contexts can
464 * exist simultaneously. A single context is not thread safe. However,
465 * different contexts can execute on different threads simultaneously.
466 *
467 * @{
468 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000469
Tom Stellard1580dc72014-04-16 17:45:04 +0000470typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
Juergen Ributzka34390c72014-05-16 02:33:15 +0000471typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
Tom Stellard1580dc72014-04-16 17:45:04 +0000472
Gregory Szorc34c863a2012-03-21 03:54:29 +0000473/**
474 * Create a new context.
475 *
476 * Every call to this function should be paired with a call to
477 * LLVMContextDispose() or the context will leak memory.
478 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000479LLVMContextRef LLVMContextCreate(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000480
481/**
482 * Obtain the global context instance.
483 */
Erick Tryzelaarf34cb0c2009-08-30 23:38:06 +0000484LLVMContextRef LLVMGetGlobalContext(void);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000485
486/**
Tom Stellard1580dc72014-04-16 17:45:04 +0000487 * Set the diagnostic handler for this context.
488 */
489void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
490 LLVMDiagnosticHandler Handler,
491 void *DiagnosticContext);
492
493/**
Juergen Ributzka34390c72014-05-16 02:33:15 +0000494 * Set the yield callback function for this context.
495 *
496 * @see LLVMContext::setYieldCallback()
497 */
498void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
499 void *OpaqueHandle);
500
501/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000502 * Destroy a context instance.
503 *
504 * This should be called for every call to LLVMContextCreate() or memory
505 * will be leaked.
506 */
Owen Anderson6773d382009-07-01 16:58:40 +0000507void LLVMContextDispose(LLVMContextRef C);
508
Tom Stellard1580dc72014-04-16 17:45:04 +0000509/**
510 * Return a string representation of the DiagnosticInfo. Use
511 * LLVMDisposeMessage to free the string.
512 *
513 * @see DiagnosticInfo::print()
514 */
515char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
516
517/**
518 * Return an enum LLVMDiagnosticSeverity.
519 *
520 * @see DiagnosticInfo::getSeverity()
521 */
522LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
523
Erick Tryzelaard8531fa2010-02-28 09:45:59 +0000524unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
525 unsigned SLen);
526unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
527
Gregory Szorc34c863a2012-03-21 03:54:29 +0000528/**
529 * @}
530 */
531
Gregory Szorc52d26602012-03-21 07:28:27 +0000532/**
533 * @defgroup LLVMCCoreModule Modules
Gregory Szorc34c863a2012-03-21 03:54:29 +0000534 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +0000535 * Modules represent the top-level structure in an LLVM program. An LLVM
Gregory Szorc34c863a2012-03-21 03:54:29 +0000536 * module is effectively a translation unit or a collection of
537 * translation units merged together.
538 *
539 * @{
540 */
541
Gregory Szorc34c863a2012-03-21 03:54:29 +0000542/**
543 * Create a new, empty module in the global context.
544 *
545 * This is equivalent to calling LLVMModuleCreateWithNameInContext with
546 * LLVMGetGlobalContext() as the context parameter.
547 *
548 * Every invocation should be paired with LLVMDisposeModule() or memory
549 * will be leaked.
550 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000551LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000552
553/**
554 * Create a new, empty module in a specific context.
555 *
556 * Every invocation should be paired with LLVMDisposeModule() or memory
557 * will be leaked.
558 */
Owen Anderson31d44e42009-07-02 07:17:57 +0000559LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
560 LLVMContextRef C);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000561
Gregory Szorc34c863a2012-03-21 03:54:29 +0000562/**
563 * Destroy a module instance.
564 *
565 * This must be called for every created module or memory will be
566 * leaked.
567 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000568void LLVMDisposeModule(LLVMModuleRef M);
569
Gregory Szorc34c863a2012-03-21 03:54:29 +0000570/**
571 * Obtain the data layout for a module.
572 *
573 * @see Module::getDataLayout()
574 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000575const char *LLVMGetDataLayout(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000576
577/**
578 * Set the data layout for a module.
579 *
580 * @see Module::setDataLayout()
581 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000582void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
583
Gregory Szorc34c863a2012-03-21 03:54:29 +0000584/**
585 * Obtain the target triple for a module.
586 *
587 * @see Module::getTargetTriple()
588 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000589const char *LLVMGetTarget(LLVMModuleRef M);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000590
591/**
592 * Set the target triple for a module.
593 *
594 * @see Module::setTargetTriple()
595 */
Gordon Henriksen05568bb2007-12-27 20:13:47 +0000596void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
597
Gregory Szorc34c863a2012-03-21 03:54:29 +0000598/**
599 * Dump a representation of a module to stderr.
600 *
601 * @see Module::dump()
602 */
Gordon Henriksen6c6075e2008-03-14 23:58:56 +0000603void LLVMDumpModule(LLVMModuleRef M);
604
Gregory Szorc34c863a2012-03-21 03:54:29 +0000605/**
Hans Wennborgb7ef2fe2012-05-09 16:54:17 +0000606 * Print a representation of a module to a file. The ErrorMessage needs to be
607 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
608 *
609 * @see Module::print()
610 */
611LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
612 char **ErrorMessage);
613
614/**
Anders Waldenborg84355db2013-10-16 18:00:54 +0000615 * Return a string representation of the module. Use
616 * LLVMDisposeMessage to free the string.
617 *
618 * @see Module::print()
619 */
620char *LLVMPrintModuleToString(LLVMModuleRef M);
621
622/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000623 * Set inline assembly for a module.
624 *
625 * @see Module::setModuleInlineAsm()
626 */
Chris Lattner26941452010-04-10 17:52:58 +0000627void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000628
Gregory Szorc34c863a2012-03-21 03:54:29 +0000629/**
630 * Obtain the context to which this module is associated.
631 *
632 * @see Module::getContext()
633 */
Chris Lattnera7e04b02010-11-28 20:03:44 +0000634LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
635
Gregory Szorc34c863a2012-03-21 03:54:29 +0000636/**
637 * Obtain a Type from a module by its registered name.
638 */
639LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000640
Gregory Szorc34c863a2012-03-21 03:54:29 +0000641/**
642 * Obtain the number of operands for named metadata in a module.
643 *
644 * @see llvm::Module::getNamedMetadata()
645 */
646unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
647
648/**
649 * Obtain the named metadata operands for a module.
650 *
651 * The passed LLVMValueRef pointer should refer to an array of
652 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
653 * array will be populated with the LLVMValueRef instances. Each
654 * instance corresponds to a llvm::MDNode.
655 *
656 * @see llvm::Module::getNamedMetadata()
657 * @see llvm::MDNode::getOperand()
658 */
659void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
660
661/**
662 * Add an operand to named metadata.
663 *
664 * @see llvm::Module::getNamedMetadata()
665 * @see llvm::MDNode::addOperand()
666 */
667void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
668 LLVMValueRef Val);
669
Gregory Szorc52d26602012-03-21 07:28:27 +0000670/**
671 * Add a function to a module under a specified name.
672 *
673 * @see llvm::Function::Create()
674 */
675LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
676 LLVMTypeRef FunctionTy);
677
678/**
679 * Obtain a Function value from a Module by its name.
680 *
681 * The returned value corresponds to a llvm::Function value.
682 *
683 * @see llvm::Module::getFunction()
684 */
685LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
686
687/**
688 * Obtain an iterator to the first Function in a Module.
689 *
690 * @see llvm::Module::begin()
691 */
692LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
693
694/**
695 * Obtain an iterator to the last Function in a Module.
696 *
697 * @see llvm::Module::end()
698 */
699LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
700
701/**
702 * Advance a Function iterator to the next Function.
703 *
704 * Returns NULL if the iterator was already at the end and there are no more
705 * functions.
706 */
707LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
708
709/**
710 * Decrement a Function iterator to the previous Function.
711 *
712 * Returns NULL if the iterator was already at the beginning and there are
713 * no previous functions.
714 */
715LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000716
717/**
718 * @}
719 */
720
721/**
722 * @defgroup LLVMCCoreType Types
723 *
724 * Types represent the type of a value.
725 *
726 * Types are associated with a context instance. The context internally
727 * deduplicates types so there is only 1 instance of a specific type
728 * alive at a time. In other words, a unique type is shared among all
729 * consumers within a context.
730 *
731 * A Type in the C API corresponds to llvm::Type.
732 *
733 * Types have the following hierarchy:
734 *
Gordon Henriksen76a03742007-09-18 03:18:57 +0000735 * types:
736 * integer type
737 * real type
738 * function type
739 * sequence types:
740 * array type
741 * pointer type
742 * vector type
743 * void type
744 * label type
745 * opaque type
Gregory Szorc34c863a2012-03-21 03:54:29 +0000746 *
747 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +0000748 */
749
Gregory Szorc34c863a2012-03-21 03:54:29 +0000750/**
751 * Obtain the enumerated type of a Type instance.
752 *
753 * @see llvm::Type:getTypeID()
754 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000755LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000756
757/**
758 * Whether the type has a known size.
759 *
760 * Things that don't have a size are abstract types, labels, and void.a
761 *
762 * @see llvm::Type::isSized()
763 */
Torok Edwin1cd9ade2011-10-06 12:13:28 +0000764LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
Gordon Henriksena49d4352008-03-07 19:13:06 +0000765
Gregory Szorc34c863a2012-03-21 03:54:29 +0000766/**
767 * Obtain the context to which this type instance is associated.
768 *
769 * @see llvm::Type::getContext()
770 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000771LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
772
Gregory Szorc34c863a2012-03-21 03:54:29 +0000773/**
Anders Waldenborgb822cff2013-10-16 21:30:25 +0000774 * Dump a representation of a type to stderr.
775 *
776 * @see llvm::Type::dump()
777 */
778void LLVMDumpType(LLVMTypeRef Val);
779
780/**
Anders Waldenborg47b3bd32013-10-22 06:58:34 +0000781 * Return a string representation of the type. Use
782 * LLVMDisposeMessage to free the string.
783 *
784 * @see llvm::Type::print()
785 */
786char *LLVMPrintTypeToString(LLVMTypeRef Val);
787
788/**
Gregory Szorc34c863a2012-03-21 03:54:29 +0000789 * @defgroup LLVMCCoreTypeInt Integer Types
790 *
791 * Functions in this section operate on integer types.
792 *
793 * @{
794 */
795
796/**
797 * Obtain an integer type from a context with specified bit width.
798 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000799LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
800LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
801LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
802LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
803LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
804LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
805
Gregory Szorc34c863a2012-03-21 03:54:29 +0000806/**
807 * Obtain an integer type from the global context with a specified bit
808 * width.
809 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000810LLVMTypeRef LLVMInt1Type(void);
811LLVMTypeRef LLVMInt8Type(void);
812LLVMTypeRef LLVMInt16Type(void);
813LLVMTypeRef LLVMInt32Type(void);
814LLVMTypeRef LLVMInt64Type(void);
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000815LLVMTypeRef LLVMIntType(unsigned NumBits);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000816unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000817
Gregory Szorc34c863a2012-03-21 03:54:29 +0000818/**
819 * @}
820 */
821
822/**
823 * @defgroup LLVMCCoreTypeFloat Floating Point Types
824 *
825 * @{
826 */
827
828/**
829 * Obtain a 16-bit floating point type from a context.
830 */
Dan Gohman518cda42011-12-17 00:04:22 +0000831LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000832
833/**
834 * Obtain a 32-bit floating point type from a context.
835 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000836LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000837
838/**
839 * Obtain a 64-bit floating point type from a context.
840 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000841LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000842
843/**
844 * Obtain a 80-bit floating point type (X87) from a context.
845 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000846LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000847
848/**
849 * Obtain a 128-bit floating point type (112-bit mantissa) from a
850 * context.
851 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000852LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000853
854/**
855 * Obtain a 128-bit floating point type (two 64-bits) from a context.
856 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000857LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
858
Gregory Szorc34c863a2012-03-21 03:54:29 +0000859/**
860 * Obtain a floating point type from the global context.
861 *
862 * These map to the functions in this group of the same name.
863 */
Dan Gohman518cda42011-12-17 00:04:22 +0000864LLVMTypeRef LLVMHalfType(void);
Gordon Henriksena735a9c2008-05-04 12:55:34 +0000865LLVMTypeRef LLVMFloatType(void);
866LLVMTypeRef LLVMDoubleType(void);
867LLVMTypeRef LLVMX86FP80Type(void);
868LLVMTypeRef LLVMFP128Type(void);
869LLVMTypeRef LLVMPPCFP128Type(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000870
Gregory Szorc34c863a2012-03-21 03:54:29 +0000871/**
872 * @}
873 */
874
875/**
876 * @defgroup LLVMCCoreTypeFunction Function Types
877 *
878 * @{
879 */
880
881/**
882 * Obtain a function type consisting of a specified signature.
883 *
884 * The function is defined as a tuple of a return Type, a list of
885 * parameter types, and whether the function is variadic.
886 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000887LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
888 LLVMTypeRef *ParamTypes, unsigned ParamCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000889 LLVMBool IsVarArg);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000890
891/**
892 * Returns whether a function type is variadic.
893 */
Chris Lattner25963c62010-01-09 22:27:07 +0000894LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000895
896/**
897 * Obtain the Type this function Type returns.
898 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000899LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000900
901/**
902 * Obtain the number of parameters this function accepts.
903 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000904unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000905
906/**
907 * Obtain the types of a function's parameters.
908 *
909 * The Dest parameter should point to a pre-allocated array of
910 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
911 * first LLVMCountParamTypes() entries in the array will be populated
912 * with LLVMTypeRef instances.
913 *
914 * @param FunctionTy The function type to operate on.
915 * @param Dest Memory address of an array to be filled with result.
916 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000917void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
Gordon Henriksen76a03742007-09-18 03:18:57 +0000918
Gregory Szorc34c863a2012-03-21 03:54:29 +0000919/**
920 * @}
921 */
922
923/**
924 * @defgroup LLVMCCoreTypeStruct Structure Types
925 *
926 * These functions relate to LLVMTypeRef instances.
927 *
928 * @see llvm::StructType
929 *
930 * @{
931 */
932
933/**
934 * Create a new structure type in a context.
935 *
936 * A structure is specified by a list of inner elements/types and
937 * whether these can be packed together.
938 *
939 * @see llvm::StructType::create()
940 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +0000941LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
Chris Lattner25963c62010-01-09 22:27:07 +0000942 unsigned ElementCount, LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000943
944/**
945 * Create a new structure type in the global context.
946 *
947 * @see llvm::StructType::create()
948 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +0000949LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
Chris Lattner25963c62010-01-09 22:27:07 +0000950 LLVMBool Packed);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000951
952/**
953 * Create an empty structure in a context having a specified name.
954 *
955 * @see llvm::StructType::create()
956 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000957LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000958
959/**
960 * Obtain the name of a structure.
961 *
962 * @see llvm::StructType::getName()
963 */
Torok Edwin0d5f6ae2011-10-06 12:12:50 +0000964const char *LLVMGetStructName(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000965
966/**
967 * Set the contents of a structure type.
968 *
969 * @see llvm::StructType::setBody()
970 */
Chris Lattnere71ccde2011-07-14 05:53:17 +0000971void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
972 unsigned ElementCount, LLVMBool Packed);
973
Gregory Szorc34c863a2012-03-21 03:54:29 +0000974/**
975 * Get the number of elements defined inside the structure.
976 *
977 * @see llvm::StructType::getNumElements()
978 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +0000979unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000980
981/**
982 * Get the elements within a structure.
983 *
984 * The function is passed the address of a pre-allocated array of
985 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
986 * invocation, this array will be populated with the structure's
987 * elements. The objects in the destination array will have a lifetime
988 * of the structure type itself, which is the lifetime of the context it
989 * is contained in.
990 */
Gordon Henriksen76a03742007-09-18 03:18:57 +0000991void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000992
993/**
994 * Determine whether a structure is packed.
995 *
996 * @see llvm::StructType::isPacked()
997 */
Chris Lattner25963c62010-01-09 22:27:07 +0000998LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
Gregory Szorc34c863a2012-03-21 03:54:29 +0000999
1000/**
1001 * Determine whether a structure is opaque.
1002 *
1003 * @see llvm::StructType::isOpaque()
1004 */
Chris Lattner17cf05b2011-07-14 16:20:28 +00001005LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
1006
Gregory Szorc34c863a2012-03-21 03:54:29 +00001007/**
1008 * @}
1009 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001010
Gregory Szorc34c863a2012-03-21 03:54:29 +00001011
1012/**
1013 * @defgroup LLVMCCoreTypeSequential Sequential Types
1014 *
1015 * Sequential types represents "arrays" of types. This is a super class
1016 * for array, vector, and pointer types.
1017 *
1018 * @{
1019 */
1020
1021/**
1022 * Obtain the type of elements within a sequential type.
1023 *
1024 * This works on array, vector, and pointer types.
1025 *
1026 * @see llvm::SequentialType::getElementType()
1027 */
1028LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
1029
1030/**
1031 * Create a fixed size array type that refers to a specific type.
1032 *
1033 * The created type will exist in the context that its element type
1034 * exists in.
1035 *
1036 * @see llvm::ArrayType::get()
1037 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001038LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001039
1040/**
1041 * Obtain the length of an array type.
1042 *
1043 * This only works on types that represent arrays.
1044 *
1045 * @see llvm::ArrayType::getNumElements()
1046 */
1047unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
1048
1049/**
1050 * Create a pointer type that points to a defined type.
1051 *
1052 * The created type will exist in the context that its pointee type
1053 * exists in.
1054 *
1055 * @see llvm::PointerType::get()
1056 */
Gordon Henriksen5a3fe032007-12-17 16:08:32 +00001057LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001058
1059/**
1060 * Obtain the address space of a pointer type.
1061 *
1062 * This only works on types that represent pointers.
1063 *
1064 * @see llvm::PointerType::getAddressSpace()
1065 */
1066unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
1067
1068/**
1069 * Create a vector type that contains a defined type and has a specific
1070 * number of elements.
1071 *
1072 * The created type will exist in the context thats its element type
1073 * exists in.
1074 *
1075 * @see llvm::VectorType::get()
1076 */
Gordon Henriksened7beaa2007-10-06 16:05:20 +00001077LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001078
Gregory Szorc34c863a2012-03-21 03:54:29 +00001079/**
1080 * Obtain the number of elements in a vector type.
1081 *
1082 * This only works on types that represent vectors.
1083 *
1084 * @see llvm::VectorType::getNumElements()
1085 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001086unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1087
Gregory Szorc34c863a2012-03-21 03:54:29 +00001088/**
1089 * @}
1090 */
1091
1092/**
1093 * @defgroup LLVMCCoreTypeOther Other Types
1094 *
1095 * @{
1096 */
1097
1098/**
1099 * Create a void type in a context.
1100 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001101LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001102
1103/**
1104 * Create a label type in a context.
1105 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001106LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001107
1108/**
1109 * Create a X86 MMX type in a context.
1110 */
Dale Johannesen95b67af2010-09-10 21:58:02 +00001111LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001112
Gregory Szorc34c863a2012-03-21 03:54:29 +00001113/**
1114 * These are similar to the above functions except they operate on the
1115 * global context.
1116 */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00001117LLVMTypeRef LLVMVoidType(void);
1118LLVMTypeRef LLVMLabelType(void);
Dale Johannesen95b67af2010-09-10 21:58:02 +00001119LLVMTypeRef LLVMX86MMXType(void);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001120
Gregory Szorc34c863a2012-03-21 03:54:29 +00001121/**
1122 * @}
1123 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001124
Gregory Szorc34c863a2012-03-21 03:54:29 +00001125/**
1126 * @}
1127 */
1128
1129/**
1130 * @defgroup LLVMCCoreValues Values
1131 *
1132 * The bulk of LLVM's object model consists of values, which comprise a very
Gordon Henriksen76a03742007-09-18 03:18:57 +00001133 * rich type hierarchy.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001134 *
1135 * LLVMValueRef essentially represents llvm::Value. There is a rich
1136 * hierarchy of classes within this type. Depending on the instance
Eli Benderskyc52863c2012-08-10 18:30:44 +00001137 * obtained, not all APIs are available.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001138 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001139 * Callers can determine the type of an LLVMValueRef by calling the
Gregory Szorc34c863a2012-03-21 03:54:29 +00001140 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1141 * functions are defined by a macro, so it isn't obvious which are
1142 * available by looking at the Doxygen source code. Instead, look at the
1143 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1144 * of value names given. These value names also correspond to classes in
1145 * the llvm::Value hierarchy.
1146 *
1147 * @{
Gordon Henriksen76a03742007-09-18 03:18:57 +00001148 */
1149
Gordon Henriksen29e38942008-12-19 18:39:45 +00001150#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1151 macro(Argument) \
1152 macro(BasicBlock) \
1153 macro(InlineAsm) \
Torok Edwind09b7572011-10-14 20:37:56 +00001154 macro(MDNode) \
1155 macro(MDString) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001156 macro(User) \
1157 macro(Constant) \
Torok Edwind09b7572011-10-14 20:37:56 +00001158 macro(BlockAddress) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001159 macro(ConstantAggregateZero) \
1160 macro(ConstantArray) \
Peter Zotovae0344b2013-11-05 12:55:37 +00001161 macro(ConstantDataSequential) \
1162 macro(ConstantDataArray) \
1163 macro(ConstantDataVector) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001164 macro(ConstantExpr) \
1165 macro(ConstantFP) \
1166 macro(ConstantInt) \
1167 macro(ConstantPointerNull) \
1168 macro(ConstantStruct) \
1169 macro(ConstantVector) \
1170 macro(GlobalValue) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001171 macro(GlobalAlias) \
Rafael Espindola99e05cf2014-05-13 18:45:48 +00001172 macro(GlobalObject) \
1173 macro(Function) \
1174 macro(GlobalVariable) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001175 macro(UndefValue) \
1176 macro(Instruction) \
1177 macro(BinaryOperator) \
1178 macro(CallInst) \
1179 macro(IntrinsicInst) \
1180 macro(DbgInfoIntrinsic) \
1181 macro(DbgDeclareInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001182 macro(MemIntrinsic) \
1183 macro(MemCpyInst) \
1184 macro(MemMoveInst) \
1185 macro(MemSetInst) \
1186 macro(CmpInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001187 macro(FCmpInst) \
1188 macro(ICmpInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001189 macro(ExtractElementInst) \
1190 macro(GetElementPtrInst) \
1191 macro(InsertElementInst) \
1192 macro(InsertValueInst) \
Bill Wendlingfae14752011-08-12 20:24:12 +00001193 macro(LandingPadInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001194 macro(PHINode) \
1195 macro(SelectInst) \
1196 macro(ShuffleVectorInst) \
1197 macro(StoreInst) \
1198 macro(TerminatorInst) \
1199 macro(BranchInst) \
Torok Edwind09b7572011-10-14 20:37:56 +00001200 macro(IndirectBrInst) \
Gordon Henriksen29e38942008-12-19 18:39:45 +00001201 macro(InvokeInst) \
1202 macro(ReturnInst) \
1203 macro(SwitchInst) \
1204 macro(UnreachableInst) \
Bill Wendlingf891bf82011-07-31 06:30:59 +00001205 macro(ResumeInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001206 macro(UnaryInstruction) \
1207 macro(AllocaInst) \
1208 macro(CastInst) \
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001209 macro(AddrSpaceCastInst) \
Duncan Sands5e37e992013-05-06 08:55:45 +00001210 macro(BitCastInst) \
1211 macro(FPExtInst) \
1212 macro(FPToSIInst) \
1213 macro(FPToUIInst) \
1214 macro(FPTruncInst) \
1215 macro(IntToPtrInst) \
1216 macro(PtrToIntInst) \
1217 macro(SExtInst) \
1218 macro(SIToFPInst) \
1219 macro(TruncInst) \
1220 macro(UIToFPInst) \
1221 macro(ZExtInst) \
1222 macro(ExtractValueInst) \
1223 macro(LoadInst) \
1224 macro(VAArgInst)
Gordon Henriksen29e38942008-12-19 18:39:45 +00001225
Gregory Szorc34c863a2012-03-21 03:54:29 +00001226/**
1227 * @defgroup LLVMCCoreValueGeneral General APIs
1228 *
1229 * Functions in this section work on all LLVMValueRef instances,
1230 * regardless of their sub-type. They correspond to functions available
1231 * on llvm::Value.
1232 *
1233 * @{
1234 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001235
Gregory Szorc34c863a2012-03-21 03:54:29 +00001236/**
1237 * Obtain the type of a value.
1238 *
1239 * @see llvm::Value::getType()
1240 */
1241LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1242
1243/**
1244 * Obtain the string name of a value.
1245 *
1246 * @see llvm::Value::getName()
1247 */
1248const char *LLVMGetValueName(LLVMValueRef Val);
1249
1250/**
1251 * Set the string name of a value.
1252 *
1253 * @see llvm::Value::setName()
1254 */
1255void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1256
1257/**
1258 * Dump a representation of a value to stderr.
1259 *
1260 * @see llvm::Value::dump()
1261 */
1262void LLVMDumpValue(LLVMValueRef Val);
1263
1264/**
Peter Zotovcd93b372013-11-06 09:21:01 +00001265 * Return a string representation of the value. Use
1266 * LLVMDisposeMessage to free the string.
1267 *
1268 * @see llvm::Value::print()
1269 */
1270char *LLVMPrintValueToString(LLVMValueRef Val);
1271
1272/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001273 * Replace all uses of a value with another one.
1274 *
1275 * @see llvm::Value::replaceAllUsesWith()
1276 */
1277void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1278
1279/**
1280 * Determine whether the specified constant instance is constant.
1281 */
1282LLVMBool LLVMIsConstant(LLVMValueRef Val);
1283
1284/**
1285 * Determine whether a value instance is undefined.
1286 */
1287LLVMBool LLVMIsUndef(LLVMValueRef Val);
1288
1289/**
1290 * Convert value instances between types.
1291 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001292 * Internally, an LLVMValueRef is "pinned" to a specific type. This
Gregory Szorc34c863a2012-03-21 03:54:29 +00001293 * series of functions allows you to cast an instance to a specific
1294 * type.
1295 *
1296 * If the cast is not valid for the specified type, NULL is returned.
1297 *
1298 * @see llvm::dyn_cast_or_null<>
1299 */
Gordon Henriksen29e38942008-12-19 18:39:45 +00001300#define LLVM_DECLARE_VALUE_CAST(name) \
1301 LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1302LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1303
Gregory Szorc34c863a2012-03-21 03:54:29 +00001304/**
1305 * @}
1306 */
1307
1308/**
1309 * @defgroup LLVMCCoreValueUses Usage
1310 *
1311 * This module defines functions that allow you to inspect the uses of a
1312 * LLVMValueRef.
1313 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001314 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001315 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1316 * llvm::User and llvm::Value.
1317 *
1318 * @{
1319 */
1320
1321/**
1322 * Obtain the first use of a value.
1323 *
1324 * Uses are obtained in an iterator fashion. First, call this function
1325 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
Eli Benderskyc52863c2012-08-10 18:30:44 +00001326 * on that instance and all subsequently obtained instances until
Gregory Szorc34c863a2012-03-21 03:54:29 +00001327 * LLVMGetNextUse() returns NULL.
1328 *
1329 * @see llvm::Value::use_begin()
1330 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001331LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001332
1333/**
1334 * Obtain the next use of a value.
1335 *
1336 * This effectively advances the iterator. It returns NULL if you are on
1337 * the final use and no more are available.
1338 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001339LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001340
1341/**
1342 * Obtain the user value for a user.
1343 *
1344 * The returned value corresponds to a llvm::User type.
1345 *
1346 * @see llvm::Use::getUser()
1347 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001348LLVMValueRef LLVMGetUser(LLVMUseRef U);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001349
1350/**
1351 * Obtain the value this use corresponds to.
1352 *
1353 * @see llvm::Use::get().
1354 */
Erick Tryzelaar9f9857e2010-03-02 20:32:28 +00001355LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001356
Gregory Szorc34c863a2012-03-21 03:54:29 +00001357/**
1358 * @}
1359 */
1360
1361/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001362 * @defgroup LLVMCCoreValueUser User value
Gregory Szorc34c863a2012-03-21 03:54:29 +00001363 *
1364 * Function in this group pertain to LLVMValueRef instances that descent
1365 * from llvm::User. This includes constants, instructions, and
1366 * operators.
1367 *
1368 * @{
1369 */
1370
1371/**
1372 * Obtain an operand at a specific index in a llvm::User value.
1373 *
1374 * @see llvm::User::getOperand()
1375 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001376LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001377
1378/**
1379 * Set an operand at a specific index in a llvm::User value.
1380 *
1381 * @see llvm::User::setOperand()
1382 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001383void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001384
1385/**
1386 * Obtain the number of operands in a llvm::User value.
1387 *
1388 * @see llvm::User::getNumOperands()
1389 */
Erick Tryzelaarb4d48702010-08-20 14:51:22 +00001390int LLVMGetNumOperands(LLVMValueRef Val);
Chris Lattner40cf28d2009-10-12 04:01:02 +00001391
Gregory Szorc34c863a2012-03-21 03:54:29 +00001392/**
1393 * @}
1394 */
1395
1396/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001397 * @defgroup LLVMCCoreValueConstant Constants
Gregory Szorc34c863a2012-03-21 03:54:29 +00001398 *
1399 * This section contains APIs for interacting with LLVMValueRef that
1400 * correspond to llvm::Constant instances.
1401 *
1402 * These functions will work for any LLVMValueRef in the llvm::Constant
1403 * class hierarchy.
1404 *
1405 * @{
1406 */
1407
1408/**
1409 * Obtain a constant value referring to the null instance of a type.
1410 *
1411 * @see llvm::Constant::getNullValue()
1412 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001413LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
Gregory Szorc34c863a2012-03-21 03:54:29 +00001414
1415/**
1416 * Obtain a constant value referring to the instance of a type
1417 * consisting of all ones.
1418 *
1419 * This is only valid for integer types.
1420 *
1421 * @see llvm::Constant::getAllOnesValue()
1422 */
1423LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1424
1425/**
1426 * Obtain a constant value referring to an undefined value of a type.
1427 *
1428 * @see llvm::UndefValue::get()
1429 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001430LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001431
1432/**
1433 * Determine whether a value instance is null.
1434 *
1435 * @see llvm::Constant::isNullValue()
1436 */
Chris Lattner25963c62010-01-09 22:27:07 +00001437LLVMBool LLVMIsNull(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001438
1439/**
1440 * Obtain a constant that is a constant pointer pointing to NULL for a
1441 * specified type.
1442 */
Chris Lattner7f318242009-07-06 17:29:59 +00001443LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001444
Gregory Szorc34c863a2012-03-21 03:54:29 +00001445/**
1446 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1447 *
1448 * Functions in this group model LLVMValueRef instances that correspond
1449 * to constants referring to scalar types.
1450 *
1451 * For integer types, the LLVMTypeRef parameter should correspond to a
1452 * llvm::IntegerType instance and the returned LLVMValueRef will
1453 * correspond to a llvm::ConstantInt.
1454 *
1455 * For floating point types, the LLVMTypeRef returned corresponds to a
1456 * llvm::ConstantFP.
1457 *
1458 * @{
1459 */
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00001460
Gregory Szorc34c863a2012-03-21 03:54:29 +00001461/**
1462 * Obtain a constant value for an integer type.
1463 *
1464 * The returned value corresponds to a llvm::ConstantInt.
1465 *
1466 * @see llvm::ConstantInt::get()
1467 *
1468 * @param IntTy Integer type to obtain value of.
1469 * @param N The value the returned instance should refer to.
1470 * @param SignExtend Whether to sign extend the produced value.
1471 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001472LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +00001473 LLVMBool SignExtend);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001474
1475/**
1476 * Obtain a constant value for an integer of arbitrary precision.
1477 *
1478 * @see llvm::ConstantInt::get()
1479 */
Chris Lattner4329e072010-11-23 02:47:22 +00001480LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1481 unsigned NumWords,
1482 const uint64_t Words[]);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001483
1484/**
1485 * Obtain a constant value for an integer parsed from a string.
1486 *
1487 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1488 * string's length is available, it is preferred to call that function
1489 * instead.
1490 *
1491 * @see llvm::ConstantInt::get()
1492 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001493LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1494 uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001495
1496/**
1497 * Obtain a constant value for an integer parsed from a string with
1498 * specified length.
1499 *
1500 * @see llvm::ConstantInt::get()
1501 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001502LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1503 unsigned SLen, uint8_t Radix);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001504
1505/**
1506 * Obtain a constant value referring to a double floating point value.
1507 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001508LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001509
1510/**
1511 * Obtain a constant for a floating point value parsed from a string.
1512 *
1513 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1514 * should be used if the input string's length is known.
1515 */
Gordon Henriksen931e1212008-02-02 01:07:50 +00001516LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001517
1518/**
1519 * Obtain a constant for a floating point value parsed from a string.
1520 */
Erick Tryzelaardd991352009-08-16 23:36:46 +00001521LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1522 unsigned SLen);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001523
1524/**
1525 * Obtain the zero extended value for an integer constant value.
1526 *
1527 * @see llvm::ConstantInt::getZExtValue()
1528 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001529unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001530
1531/**
1532 * Obtain the sign extended value for an integer constant value.
1533 *
1534 * @see llvm::ConstantInt::getSExtValue()
1535 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001536long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
Erick Tryzelaardd991352009-08-16 23:36:46 +00001537
Gregory Szorc34c863a2012-03-21 03:54:29 +00001538/**
1539 * @}
1540 */
1541
1542/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001543 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1544 *
1545 * Functions in this group operate on composite constants.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001546 *
1547 * @{
1548 */
1549
1550/**
Gregory Szorc52d26602012-03-21 07:28:27 +00001551 * Create a ConstantDataSequential and initialize it with a string.
Gregory Szorc34c863a2012-03-21 03:54:29 +00001552 *
Gregory Szorc52d26602012-03-21 07:28:27 +00001553 * @see llvm::ConstantDataArray::getString()
Gregory Szorc34c863a2012-03-21 03:54:29 +00001554 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001555LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
Chris Lattner25963c62010-01-09 22:27:07 +00001556 unsigned Length, LLVMBool DontNullTerminate);
Gregory Szorc52d26602012-03-21 07:28:27 +00001557
1558/**
1559 * Create a ConstantDataSequential with string content in the global context.
1560 *
1561 * This is the same as LLVMConstStringInContext except it operates on the
1562 * global context.
1563 *
1564 * @see LLVMConstStringInContext()
1565 * @see llvm::ConstantDataArray::getString()
1566 */
1567LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1568 LLVMBool DontNullTerminate);
1569
1570/**
1571 * Create an anonymous ConstantStruct with the specified values.
1572 *
1573 * @see llvm::ConstantStruct::getAnon()
1574 */
1575LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001576 LLVMValueRef *ConstantVals,
Chris Lattner25963c62010-01-09 22:27:07 +00001577 unsigned Count, LLVMBool Packed);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00001578
Gregory Szorc52d26602012-03-21 07:28:27 +00001579/**
1580 * Create a ConstantStruct in the global Context.
1581 *
1582 * This is the same as LLVMConstStructInContext except it operates on the
1583 * global Context.
1584 *
1585 * @see LLVMConstStructInContext()
1586 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001587LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
Chris Lattner25963c62010-01-09 22:27:07 +00001588 LLVMBool Packed);
Gregory Szorc52d26602012-03-21 07:28:27 +00001589
1590/**
1591 * Create a ConstantArray from values.
1592 *
1593 * @see llvm::ConstantArray::get()
1594 */
1595LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1596 LLVMValueRef *ConstantVals, unsigned Length);
1597
1598/**
1599 * Create a non-anonymous ConstantStruct from values.
1600 *
1601 * @see llvm::ConstantStruct::get()
1602 */
Rafael Espindola784ad242011-07-14 19:09:08 +00001603LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1604 LLVMValueRef *ConstantVals,
1605 unsigned Count);
Gregory Szorc52d26602012-03-21 07:28:27 +00001606
1607/**
1608 * Create a ConstantVector from values.
1609 *
1610 * @see llvm::ConstantVector::get()
1611 */
Gordon Henriksen1046c732007-10-06 15:11:06 +00001612LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001613
Gregory Szorc52d26602012-03-21 07:28:27 +00001614/**
1615 * @}
1616 */
1617
1618/**
1619 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1620 *
1621 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1622 *
1623 * @see llvm::ConstantExpr.
1624 *
1625 * @{
1626 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001627LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00001628LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001629LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1630LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001631LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1632LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001633LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001634LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1635LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001636LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001637LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001638LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001639LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001640LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1641LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001642LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001643LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00001644LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1645LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001646LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001647LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1648LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001649LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001650LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1651LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1652LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1653LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1654LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1655LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1656LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1657LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1658 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1659LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1660 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1661LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1662LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1663LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1664LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1665 LLVMValueRef *ConstantIndices, unsigned NumIndices);
Dan Gohmane4ca02d2009-09-03 23:34:49 +00001666LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1667 LLVMValueRef *ConstantIndices,
1668 unsigned NumIndices);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001669LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1670LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1671LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1672LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1673LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1674LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1675LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1676LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1677LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1678LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1679LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1680LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00001681LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001682LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1683 LLVMTypeRef ToType);
1684LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1685 LLVMTypeRef ToType);
1686LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1687 LLVMTypeRef ToType);
1688LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1689 LLVMTypeRef ToType);
1690LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
Chris Lattner25963c62010-01-09 22:27:07 +00001691 LLVMBool isSigned);
Erick Tryzelaar4cc690c2009-08-16 02:20:12 +00001692LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001693LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1694 LLVMValueRef ConstantIfTrue,
1695 LLVMValueRef ConstantIfFalse);
1696LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1697 LLVMValueRef IndexConstant);
1698LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1699 LLVMValueRef ElementValueConstant,
1700 LLVMValueRef IndexConstant);
1701LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1702 LLVMValueRef VectorBConstant,
1703 LLVMValueRef MaskConstant);
Dan Gohmand5104a52008-11-03 22:55:43 +00001704LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1705 unsigned NumIdx);
1706LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1707 LLVMValueRef ElementValueConstant,
1708 unsigned *IdxList, unsigned NumIdx);
Chris Lattner25963c62010-01-09 22:27:07 +00001709LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
Chris Lattner3d1f5522008-12-17 21:39:50 +00001710 const char *AsmString, const char *Constraints,
Chris Lattner25963c62010-01-09 22:27:07 +00001711 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00001712LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
Gordon Henriksen7ce31762007-10-06 14:29:36 +00001713
Gregory Szorc52d26602012-03-21 07:28:27 +00001714/**
1715 * @}
1716 */
1717
1718/**
1719 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1720 *
1721 * This group contains functions that operate on global values. Functions in
1722 * this group relate to functions in the llvm::GlobalValue class tree.
1723 *
1724 * @see llvm::GlobalValue
1725 *
1726 * @{
1727 */
1728
Gordon Henriksen265f7802008-03-19 01:11:35 +00001729LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
Chris Lattner25963c62010-01-09 22:27:07 +00001730LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001731LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1732void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1733const char *LLVMGetSection(LLVMValueRef Global);
1734void LLVMSetSection(LLVMValueRef Global, const char *Section);
1735LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1736void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
Reid Kleckner2fae26f2014-03-05 02:34:23 +00001737LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1738void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
Tim Northoverad96d012014-03-10 19:24:35 +00001739LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1740void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001741
1742/**
1743 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1744 *
1745 * Functions in this group only apply to values with alignment, i.e.
1746 * global variables, load and store instructions.
1747 */
1748
1749/**
1750 * Obtain the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001751 * @see llvm::AllocaInst::getAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001752 * @see llvm::LoadInst::getAlignment()
1753 * @see llvm::StoreInst::getAlignment()
1754 * @see llvm::GlobalValue::getAlignment()
1755 */
1756unsigned LLVMGetAlignment(LLVMValueRef V);
1757
1758/**
1759 * Set the preferred alignment of the value.
Peter Zotov9f584e62014-03-05 05:05:34 +00001760 * @see llvm::AllocaInst::setAlignment()
Anders Waldenborg213a63f2013-10-29 09:02:02 +00001761 * @see llvm::LoadInst::setAlignment()
1762 * @see llvm::StoreInst::setAlignment()
1763 * @see llvm::GlobalValue::setAlignment()
1764 */
1765void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1766
1767/**
1768 * @}
1769 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001770
Gregory Szorc52d26602012-03-21 07:28:27 +00001771/**
1772 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1773 *
1774 * This group contains functions that operate on global variable values.
1775 *
1776 * @see llvm::GlobalVariable
1777 *
1778 * @{
1779 */
Gordon Henriksen76a03742007-09-18 03:18:57 +00001780LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
Erick Tryzelaar06894b32010-02-28 09:46:13 +00001781LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1782 const char *Name,
1783 unsigned AddressSpace);
Gordon Henriksen783f7bb2007-10-08 03:45:09 +00001784LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001785LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1786LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1787LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1788LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001789void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001790LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1791void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
Chris Lattner25963c62010-01-09 22:27:07 +00001792LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1793void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1794LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1795void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
Hans Wennborg5ff71202013-04-16 08:58:59 +00001796LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1797void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1798LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1799void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
Gordon Henriksen76a03742007-09-18 03:18:57 +00001800
Gregory Szorc52d26602012-03-21 07:28:27 +00001801/**
1802 * @}
1803 */
1804
1805/**
1806 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1807 *
1808 * This group contains function that operate on global alias values.
1809 *
1810 * @see llvm::GlobalAlias
1811 *
1812 * @{
1813 */
Chris Lattner3d1f5522008-12-17 21:39:50 +00001814LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1815 const char *Name);
1816
Gregory Szorc34c863a2012-03-21 03:54:29 +00001817/**
1818 * @}
1819 */
1820
1821/**
1822 * @defgroup LLVMCCoreValueFunction Function values
1823 *
1824 * Functions in this group operate on LLVMValueRef instances that
1825 * correspond to llvm::Function instances.
1826 *
1827 * @see llvm::Function
1828 *
1829 * @{
1830 */
1831
1832/**
1833 * Remove a function from its containing module and deletes it.
1834 *
1835 * @see llvm::Function::eraseFromParent()
1836 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001837void LLVMDeleteFunction(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001838
1839/**
1840 * Obtain the ID number from a function instance.
1841 *
1842 * @see llvm::Function::getIntrinsicID()
1843 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001844unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001845
1846/**
1847 * Obtain the calling function of a function.
1848 *
1849 * The returned value corresponds to the LLVMCallConv enumeration.
1850 *
1851 * @see llvm::Function::getCallingConv()
1852 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001853unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001854
1855/**
1856 * Set the calling convention of a function.
1857 *
1858 * @see llvm::Function::setCallingConv()
1859 *
1860 * @param Fn Function to operate on
1861 * @param CC LLVMCallConv to set calling convention to
1862 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001863void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001864
1865/**
1866 * Obtain the name of the garbage collector to use during code
1867 * generation.
1868 *
1869 * @see llvm::Function::getGC()
1870 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001871const char *LLVMGetGC(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001872
1873/**
1874 * Define the garbage collector to use during code generation.
1875 *
1876 * @see llvm::Function::setGC()
1877 */
Gordon Henriksend930f912008-08-17 18:44:35 +00001878void LLVMSetGC(LLVMValueRef Fn, const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001879
1880/**
1881 * Add an attribute to a function.
1882 *
1883 * @see llvm::Function::addAttribute()
1884 */
Duncan Sands7374a012009-05-06 12:21:17 +00001885void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001886
1887/**
Tom Stellarde8f35e12013-04-16 23:12:43 +00001888 * Add a target-dependent attribute to a fuction
1889 * @see llvm::AttrBuilder::addAttribute()
1890 */
1891void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1892 const char *V);
1893
1894/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00001895 * Obtain an attribute from a function.
1896 *
1897 * @see llvm::Function::getAttributes()
1898 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00001899LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001900
1901/**
1902 * Remove an attribute from a function.
1903 */
Duncan Sands7374a012009-05-06 12:21:17 +00001904void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00001905
Gregory Szorc34c863a2012-03-21 03:54:29 +00001906/**
1907 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1908 *
1909 * Functions in this group relate to arguments/parameters on functions.
1910 *
1911 * Functions in this group expect LLVMValueRef instances that correspond
1912 * to llvm::Function instances.
1913 *
1914 * @{
1915 */
1916
1917/**
1918 * Obtain the number of parameters in a function.
1919 *
1920 * @see llvm::Function::arg_size()
1921 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001922unsigned LLVMCountParams(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001923
1924/**
1925 * Obtain the parameters in a function.
1926 *
1927 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1928 * at least LLVMCountParams() long. This array will be filled with
1929 * LLVMValueRef instances which correspond to the parameters the
1930 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1931 * instance.
1932 *
1933 * @see llvm::Function::arg_begin()
1934 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001935void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001936
1937/**
1938 * Obtain the parameter at the specified index.
1939 *
1940 * Parameters are indexed from 0.
1941 *
1942 * @see llvm::Function::arg_begin()
1943 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001944LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001945
1946/**
1947 * Obtain the function to which this argument belongs.
1948 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001949 * Unlike other functions in this group, this one takes an LLVMValueRef
Gregory Szorc34c863a2012-03-21 03:54:29 +00001950 * that corresponds to a llvm::Attribute.
1951 *
1952 * The returned LLVMValueRef is the llvm::Function to which this
1953 * argument belongs.
1954 */
Gordon Henriksen265f7802008-03-19 01:11:35 +00001955LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001956
1957/**
1958 * Obtain the first parameter to a function.
1959 *
1960 * @see llvm::Function::arg_begin()
1961 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001962LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001963
1964/**
1965 * Obtain the last parameter to a function.
1966 *
1967 * @see llvm::Function::arg_end()
1968 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001969LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001970
1971/**
1972 * Obtain the next parameter to a function.
1973 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00001974 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
Gregory Szorc34c863a2012-03-21 03:54:29 +00001975 * actually a wrapped iterator) and obtains the next parameter from the
1976 * underlying iterator.
1977 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001978LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001979
1980/**
1981 * Obtain the previous parameter to a function.
1982 *
1983 * This is the opposite of LLVMGetNextParam().
1984 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00001985LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001986
1987/**
1988 * Add an attribute to a function argument.
1989 *
1990 * @see llvm::Argument::addAttr()
1991 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001992void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00001993
1994/**
1995 * Remove an attribute from a function argument.
1996 *
1997 * @see llvm::Argument::removeAttr()
1998 */
Devang Patel4c758ea2008-09-25 21:00:45 +00001999void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002000
2001/**
2002 * Get an attribute from a function argument.
2003 */
Chris Lattner40cf28d2009-10-12 04:01:02 +00002004LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002005
2006/**
2007 * Set the alignment for a function parameter.
2008 *
2009 * @see llvm::Argument::addAttr()
Bill Wendling50d27842012-10-15 20:35:56 +00002010 * @see llvm::AttrBuilder::addAlignmentAttr()
Gregory Szorc34c863a2012-03-21 03:54:29 +00002011 */
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002012void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002013
Gregory Szorc34c863a2012-03-21 03:54:29 +00002014/**
2015 * @}
2016 */
2017
2018/**
2019 * @}
2020 */
2021
2022/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002023 * @}
2024 */
2025
2026/**
2027 * @}
2028 */
2029
2030/**
2031 * @defgroup LLVMCCoreValueMetadata Metadata
2032 *
2033 * @{
2034 */
2035
2036/**
2037 * Obtain a MDString value from a context.
2038 *
2039 * The returned instance corresponds to the llvm::MDString class.
2040 *
2041 * The instance is specified by string data of a specified length. The
2042 * string content is copied, so the backing memory can be freed after
2043 * this function returns.
2044 */
2045LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2046 unsigned SLen);
2047
2048/**
2049 * Obtain a MDString value from the global context.
2050 */
2051LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2052
2053/**
2054 * Obtain a MDNode value from a context.
2055 *
2056 * The returned value corresponds to the llvm::MDNode class.
2057 */
2058LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2059 unsigned Count);
2060
2061/**
2062 * Obtain a MDNode value from the global context.
2063 */
2064LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2065
2066/**
2067 * Obtain the underlying string from a MDString value.
2068 *
2069 * @param V Instance to obtain string from.
2070 * @param Len Memory address which will hold length of returned string.
2071 * @return String data in MDString.
2072 */
2073const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2074
2075/**
Duncan Sands12ccbe72012-09-19 20:29:39 +00002076 * Obtain the number of operands from an MDNode value.
2077 *
2078 * @param V MDNode to get number of operands from.
2079 * @return Number of operands of the MDNode.
2080 */
2081unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2082
2083/**
2084 * Obtain the given MDNode's operands.
2085 *
2086 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2087 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2088 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2089 * MDNode's operands.
2090 *
2091 * @param V MDNode to get the operands from.
2092 * @param Dest Destination array for operands.
2093 */
2094void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2095
2096/**
Gregory Szorc52d26602012-03-21 07:28:27 +00002097 * @}
2098 */
2099
2100/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002101 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2102 *
2103 * A basic block represents a single entry single exit section of code.
2104 * Basic blocks contain a list of instructions which form the body of
2105 * the block.
2106 *
2107 * Basic blocks belong to functions. They have the type of label.
2108 *
2109 * Basic blocks are themselves values. However, the C API models them as
2110 * LLVMBasicBlockRef.
2111 *
2112 * @see llvm::BasicBlock
2113 *
2114 * @{
2115 */
2116
2117/**
2118 * Convert a basic block instance to a value type.
2119 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002120LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002121
2122/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002123 * Determine whether an LLVMValueRef is itself a basic block.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002124 */
Chris Lattner25963c62010-01-09 22:27:07 +00002125LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002126
2127/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002128 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002129 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002130LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002131
2132/**
2133 * Obtain the function to which a basic block belongs.
2134 *
2135 * @see llvm::BasicBlock::getParent()
2136 */
Gordon Henriksen07a45f42008-03-23 22:21:29 +00002137LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002138
2139/**
2140 * Obtain the terminator instruction for a basic block.
2141 *
2142 * If the basic block does not have a terminator (it is not well-formed
2143 * if it doesn't), then NULL is returned.
2144 *
2145 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2146 *
2147 * @see llvm::BasicBlock::getTerminator()
2148 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002149LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002150
2151/**
2152 * Obtain the number of basic blocks in a function.
2153 *
2154 * @param Fn Function value to operate on.
2155 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002156unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002157
2158/**
2159 * Obtain all of the basic blocks in a function.
2160 *
2161 * This operates on a function value. The BasicBlocks parameter is a
2162 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2163 * LLVMCountBasicBlocks() in length. This array is populated with
2164 * LLVMBasicBlockRef instances.
2165 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002166void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002167
2168/**
2169 * Obtain the first basic block in a function.
2170 *
2171 * The returned basic block can be used as an iterator. You will likely
2172 * eventually call into LLVMGetNextBasicBlock() with it.
2173 *
2174 * @see llvm::Function::begin()
2175 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002176LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002177
2178/**
2179 * Obtain the last basic block in a function.
2180 *
2181 * @see llvm::Function::end()
2182 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002183LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002184
2185/**
2186 * Advance a basic block iterator.
2187 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002188LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002189
2190/**
2191 * Go backwards in a basic block iterator.
2192 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002193LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002194
2195/**
2196 * Obtain the basic block that corresponds to the entry point of a
2197 * function.
2198 *
2199 * @see llvm::Function::getEntryBlock()
2200 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002201LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002202
Gregory Szorc34c863a2012-03-21 03:54:29 +00002203/**
2204 * Append a basic block to the end of a function.
2205 *
2206 * @see llvm::BasicBlock::Create()
2207 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002208LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2209 LLVMValueRef Fn,
2210 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002211
2212/**
2213 * Append a basic block to the end of a function using the global
2214 * context.
2215 *
2216 * @see llvm::BasicBlock::Create()
2217 */
2218LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2219
2220/**
2221 * Insert a basic block in a function before another basic block.
2222 *
2223 * The function to add to is determined by the function of the
2224 * passed basic block.
2225 *
2226 * @see llvm::BasicBlock::Create()
2227 */
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002228LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2229 LLVMBasicBlockRef BB,
2230 const char *Name);
2231
Gregory Szorc34c863a2012-03-21 03:54:29 +00002232/**
2233 * Insert a basic block in a function using the global context.
2234 *
2235 * @see llvm::BasicBlock::Create()
2236 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002237LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2238 const char *Name);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002239
2240/**
2241 * Remove a basic block from a function and delete it.
2242 *
2243 * This deletes the basic block from its containing function and deletes
2244 * the basic block itself.
2245 *
2246 * @see llvm::BasicBlock::eraseFromParent()
2247 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002248void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002249
2250/**
2251 * Remove a basic block from a function.
2252 *
2253 * This deletes the basic block from its containing function but keep
2254 * the basic block alive.
2255 *
2256 * @see llvm::BasicBlock::removeFromParent()
2257 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002258void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002259
Gregory Szorc34c863a2012-03-21 03:54:29 +00002260/**
2261 * Move a basic block to before another one.
2262 *
2263 * @see llvm::BasicBlock::moveBefore()
2264 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002265void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002266
2267/**
2268 * Move a basic block to after another one.
2269 *
2270 * @see llvm::BasicBlock::moveAfter()
2271 */
Duncan Sandsb1d61aa2010-07-19 15:31:07 +00002272void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2273
Gregory Szorc34c863a2012-03-21 03:54:29 +00002274/**
2275 * Obtain the first instruction in a basic block.
2276 *
2277 * The returned LLVMValueRef corresponds to a llvm::Instruction
2278 * instance.
2279 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002280LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002281
2282/**
2283 * Obtain the last instruction in a basic block.
2284 *
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002285 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002286 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002287LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
Nate Begeman43c322b2011-08-23 20:27:46 +00002288
Gregory Szorc34c863a2012-03-21 03:54:29 +00002289/**
2290 * @}
2291 */
2292
2293/**
2294 * @defgroup LLVMCCoreValueInstruction Instructions
2295 *
2296 * Functions in this group relate to the inspection and manipulation of
2297 * individual instructions.
2298 *
2299 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2300 * class has a large number of descendents. llvm::Instruction is a
2301 * llvm::Value and in the C API, instructions are modeled by
2302 * LLVMValueRef.
2303 *
2304 * This group also contains sub-groups which operate on specific
2305 * llvm::Instruction types, e.g. llvm::CallInst.
2306 *
2307 * @{
2308 */
2309
2310/**
2311 * Determine whether an instruction has any metadata attached.
2312 */
2313int LLVMHasMetadata(LLVMValueRef Val);
2314
2315/**
2316 * Return metadata associated with an instruction value.
2317 */
2318LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2319
2320/**
2321 * Set metadata associated with an instruction value.
2322 */
2323void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2324
2325/**
2326 * Obtain the basic block to which an instruction belongs.
2327 *
2328 * @see llvm::Instruction::getParent()
2329 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002330LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002331
2332/**
2333 * Obtain the instruction that occurs after the one specified.
2334 *
2335 * The next instruction will be from the same basic block.
2336 *
2337 * If this is the last instruction in a basic block, NULL will be
2338 * returned.
2339 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002340LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002341
2342/**
Benjamin Kramerbde91762012-06-02 10:20:22 +00002343 * Obtain the instruction that occurred before this one.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002344 *
2345 * If the instruction is the first instruction in a basic block, NULL
2346 * will be returned.
2347 */
Gordon Henriksen054817c2008-03-19 03:47:18 +00002348LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002349
2350/**
2351 * Remove and delete an instruction.
2352 *
2353 * The instruction specified is removed from its containing building
2354 * block and then deleted.
2355 *
2356 * @see llvm::Instruction::eraseFromParent()
2357 */
Devang Pateldbebc6f2011-10-03 20:59:18 +00002358void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002359
2360/**
2361 * Obtain the code opcode for an individual instruction.
2362 *
2363 * @see llvm::Instruction::getOpCode()
2364 */
Torok Edwinab6158e2011-10-14 20:37:49 +00002365LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002366
2367/**
2368 * Obtain the predicate of an instruction.
2369 *
2370 * This is only valid for instructions that correspond to llvm::ICmpInst
2371 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2372 *
2373 * @see llvm::ICmpInst::getPredicate()
2374 */
Torok Edwin60c40de2011-10-06 12:13:20 +00002375LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002376
Gregory Szorc34c863a2012-03-21 03:54:29 +00002377/**
2378 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2379 *
2380 * Functions in this group apply to instructions that refer to call
2381 * sites and invocations. These correspond to C++ types in the
2382 * llvm::CallInst class tree.
2383 *
2384 * @{
2385 */
2386
2387/**
2388 * Set the calling convention for a call instruction.
2389 *
2390 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2391 * llvm::InvokeInst.
2392 *
2393 * @see llvm::CallInst::setCallingConv()
2394 * @see llvm::InvokeInst::setCallingConv()
2395 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002396void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002397
2398/**
2399 * Obtain the calling convention for a call instruction.
2400 *
2401 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2402 * usage.
2403 *
2404 * @see LLVMSetInstructionCallConv()
2405 */
Gordon Henriksen1158c532007-12-29 20:45:00 +00002406unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002407
2408
Devang Patel4c758ea2008-09-25 21:00:45 +00002409void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002410void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
Devang Patel4c758ea2008-09-25 21:00:45 +00002411 LLVMAttribute);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002412void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
Gordon Henriksen2d9cc212008-04-28 17:37:06 +00002413 unsigned align);
Gordon Henriksen1158c532007-12-29 20:45:00 +00002414
Gregory Szorc34c863a2012-03-21 03:54:29 +00002415/**
2416 * Obtain whether a call instruction is a tail call.
2417 *
2418 * This only works on llvm::CallInst instructions.
2419 *
2420 * @see llvm::CallInst::isTailCall()
2421 */
Chris Lattner25963c62010-01-09 22:27:07 +00002422LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002423
2424/**
2425 * Set whether a call instruction is a tail call.
2426 *
2427 * This only works on llvm::CallInst instructions.
2428 *
2429 * @see llvm::CallInst::setTailCall()
2430 */
Chris Lattner25963c62010-01-09 22:27:07 +00002431void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
Gordon Henrikseneeb65372008-08-30 16:34:54 +00002432
Gregory Szorc34c863a2012-03-21 03:54:29 +00002433/**
2434 * @}
2435 */
2436
2437/**
2438 * Obtain the default destination basic block of a switch instruction.
2439 *
2440 * This only works on llvm::SwitchInst instructions.
2441 *
2442 * @see llvm::SwitchInst::getDefaultDest()
2443 */
Nate Begeman43c322b2011-08-23 20:27:46 +00002444LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2445
Gregory Szorc34c863a2012-03-21 03:54:29 +00002446/**
2447 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2448 *
2449 * Functions in this group only apply to instructions that map to
2450 * llvm::PHINode instances.
2451 *
2452 * @{
2453 */
2454
2455/**
2456 * Add an incoming value to the end of a PHI list.
2457 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002458void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2459 LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002460
2461/**
2462 * Obtain the number of incoming basic blocks to a PHI node.
2463 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002464unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002465
2466/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002467 * Obtain an incoming value to a PHI node as an LLVMValueRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002468 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002469LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
Gregory Szorc34c863a2012-03-21 03:54:29 +00002470
2471/**
Daniel Dunbar06b9f9e2013-08-16 23:30:19 +00002472 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002473 */
Gordon Henriksen44dd8fb2007-10-08 18:14:39 +00002474LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002475
Gregory Szorc34c863a2012-03-21 03:54:29 +00002476/**
2477 * @}
2478 */
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002479
Gregory Szorc34c863a2012-03-21 03:54:29 +00002480/**
2481 * @}
2482 */
2483
2484/**
2485 * @}
2486 */
2487
2488/**
2489 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2490 *
2491 * An instruction builder represents a point within a basic block and is
2492 * the exclusive means of building instructions using the C interface.
2493 *
2494 * @{
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002495 */
2496
Erick Tryzelaar262332f2009-08-14 00:01:31 +00002497LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002498LLVMBuilderRef LLVMCreateBuilder(void);
Gordon Henriksen054817c2008-03-19 03:47:18 +00002499void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2500 LLVMValueRef Instr);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002501void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2502void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
Gordon Henriksen265f7802008-03-19 01:11:35 +00002503LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
Chris Lattner3d1f5522008-12-17 21:39:50 +00002504void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2505void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
Erick Tryzelaar9813bea2009-08-16 02:20:57 +00002506void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2507 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002508void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2509
Erick Tryzelaard8531fa2010-02-28 09:45:59 +00002510/* Metadata */
2511void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2512LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2513void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2514
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002515/* Terminators */
2516LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2517LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
Erick Tryzelaarfd529d72009-08-19 08:36:49 +00002518LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002519 unsigned N);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002520LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2521LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2522 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2523LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2524 LLVMBasicBlockRef Else, unsigned NumCases);
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002525LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2526 unsigned NumDests);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002527LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2528 LLVMValueRef *Args, unsigned NumArgs,
2529 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2530 const char *Name);
Benjamin Kramer5a6568832011-08-19 01:36:54 +00002531LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2532 LLVMValueRef PersFn, unsigned NumClauses,
2533 const char *Name);
Bill Wendlingf891bf82011-07-31 06:30:59 +00002534LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002535LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2536
Gordon Henriksen097102c2008-01-01 05:50:53 +00002537/* Add a case to the switch instruction */
2538void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2539 LLVMBasicBlockRef Dest);
2540
Erick Tryzelaar0fb26ef2010-02-28 09:46:06 +00002541/* Add a destination to the indirectbr instruction */
2542void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2543
Bill Wendlingfae14752011-08-12 20:24:12 +00002544/* Add a catch or filter clause to the landingpad instruction */
2545void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2546
2547/* Set the 'cleanup' flag in the landingpad instruction */
2548void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2549
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002550/* Arithmetic */
2551LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2552 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002553LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2554 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002555LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2556 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002557LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2558 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002559LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2560 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002561LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2562 const char *Name);
2563LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2564 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002565LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2566 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002567LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2568 const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002569LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2570 const char *Name);
2571LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2572 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002573LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2574 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002575LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2576 const char *Name);
2577LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2578 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002579LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2580 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002581LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2582 const char *Name);
2583LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2584 const char *Name);
2585LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2586 const char *Name);
2587LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2588 const char *Name);
2589LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2590 const char *Name);
2591LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2592 const char *Name);
2593LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2594 const char *Name);
2595LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2596 const char *Name);
2597LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2598 const char *Name);
2599LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2600 const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002601LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2602 LLVMValueRef LHS, LLVMValueRef RHS,
2603 const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002604LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Erick Tryzelaar4c340c72010-02-28 05:51:43 +00002605LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2606 const char *Name);
2607LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2608 const char *Name);
Dan Gohmanf919bd62009-09-28 21:51:41 +00002609LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002610LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2611
2612/* Memory */
2613LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2614LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2615 LLVMValueRef Val, const char *Name);
2616LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2617LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2618 LLVMValueRef Val, const char *Name);
2619LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2620LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2621 const char *Name);
2622LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2623LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2624 LLVMValueRef *Indices, unsigned NumIndices,
2625 const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002626LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2627 LLVMValueRef *Indices, unsigned NumIndices,
2628 const char *Name);
2629LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2630 unsigned Idx, const char *Name);
2631LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2632 const char *Name);
2633LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2634 const char *Name);
Chris Lattner2cc6f9d2012-03-22 03:54:15 +00002635LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2636void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002637
2638/* Casts */
2639LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2640 LLVMTypeRef DestTy, const char *Name);
2641LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2642 LLVMTypeRef DestTy, const char *Name);
2643LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2644 LLVMTypeRef DestTy, const char *Name);
2645LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2646 LLVMTypeRef DestTy, const char *Name);
2647LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2648 LLVMTypeRef DestTy, const char *Name);
2649LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2650 LLVMTypeRef DestTy, const char *Name);
2651LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2652 LLVMTypeRef DestTy, const char *Name);
2653LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2654 LLVMTypeRef DestTy, const char *Name);
2655LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2656 LLVMTypeRef DestTy, const char *Name);
2657LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2658 LLVMTypeRef DestTy, const char *Name);
2659LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2660 LLVMTypeRef DestTy, const char *Name);
2661LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2662 LLVMTypeRef DestTy, const char *Name);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +00002663LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2664 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002665LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2666 LLVMTypeRef DestTy, const char *Name);
2667LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2668 LLVMTypeRef DestTy, const char *Name);
2669LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2670 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar31831792010-02-28 05:51:27 +00002671LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2672 LLVMTypeRef DestTy, const char *Name);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002673LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2674 LLVMTypeRef DestTy, const char *Name);
Duncan Sands9d786d72009-11-23 10:49:03 +00002675LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002676 LLVMTypeRef DestTy, const char *Name);
2677LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2678 LLVMTypeRef DestTy, const char *Name);
Gordon Henriksenc23b66c2007-09-26 20:56:12 +00002679
2680/* Comparisons */
2681LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2682 LLVMValueRef LHS, LLVMValueRef RHS,
2683 const char *Name);
2684LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2685 LLVMValueRef LHS, LLVMValueRef RHS,
2686 const char *Name);
2687
2688/* Miscellaneous instructions */
2689LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2690LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2691 LLVMValueRef *Args, unsigned NumArgs,
2692 const char *Name);
2693LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2694 LLVMValueRef Then, LLVMValueRef Else,
2695 const char *Name);
2696LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2697 const char *Name);
2698LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2699 LLVMValueRef Index, const char *Name);
2700LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2701 LLVMValueRef EltVal, LLVMValueRef Index,
2702 const char *Name);
2703LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2704 LLVMValueRef V2, LLVMValueRef Mask,
2705 const char *Name);
Dan Gohmand5104a52008-11-03 22:55:43 +00002706LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2707 unsigned Index, const char *Name);
2708LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2709 LLVMValueRef EltVal, unsigned Index,
2710 const char *Name);
Gordon Henriksen76a03742007-09-18 03:18:57 +00002711
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002712LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2713 const char *Name);
2714LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2715 const char *Name);
2716LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2717 LLVMValueRef RHS, const char *Name);
Filip Pizlo0d3f7ec2013-11-20 00:07:49 +00002718LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2719 LLVMBool singleThread, const char *Name);
2720LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
NAKAMURA Takumia3a81352013-10-23 17:56:29 +00002721 LLVMValueRef PTR, LLVMValueRef Val,
2722 LLVMAtomicOrdering ordering,
Carlo Kok8c6719b2013-04-23 13:21:19 +00002723 LLVMBool singleThread);
Erick Tryzelaar3045b8b2009-08-16 02:19:59 +00002724
Gregory Szorc34c863a2012-03-21 03:54:29 +00002725/**
2726 * @}
2727 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002728
Gregory Szorc34c863a2012-03-21 03:54:29 +00002729/**
2730 * @defgroup LLVMCCoreModuleProvider Module Providers
2731 *
2732 * @{
2733 */
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002734
Gregory Szorc34c863a2012-03-21 03:54:29 +00002735/**
2736 * Changes the type of M so it can be passed to FunctionPassManagers and the
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002737 * JIT. They take ModuleProviders for historical reasons.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002738 */
2739LLVMModuleProviderRef
2740LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2741
Gregory Szorc34c863a2012-03-21 03:54:29 +00002742/**
2743 * Destroys the module M.
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002744 */
Jeffrey Yasskin091217b2010-01-27 20:34:15 +00002745void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
Gordon Henriksen0a68fe22007-12-12 01:04:30 +00002746
Gregory Szorc34c863a2012-03-21 03:54:29 +00002747/**
2748 * @}
2749 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002750
Gregory Szorc34c863a2012-03-21 03:54:29 +00002751/**
2752 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2753 *
2754 * @{
2755 */
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002756
Chris Lattner25963c62010-01-09 22:27:07 +00002757LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2758 LLVMMemoryBufferRef *OutMemBuf,
2759 char **OutMessage);
2760LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2761 char **OutMessage);
Bill Wendling526276a2013-02-14 19:11:28 +00002762LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2763 size_t InputDataLength,
2764 const char *BufferName,
Bill Wendlingc9baa962013-02-14 19:39:14 +00002765 LLVMBool RequiresNullTerminator);
Bill Wendling526276a2013-02-14 19:11:28 +00002766LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2767 size_t InputDataLength,
2768 const char *BufferName);
Tom Stellard62c03202013-04-18 19:50:53 +00002769const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
Tom Stellardb7fb7242013-04-16 23:12:51 +00002770size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
Gordon Henriksen34eb6d82007-12-19 22:30:40 +00002771void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2772
Gregory Szorc34c863a2012-03-21 03:54:29 +00002773/**
2774 * @}
2775 */
2776
2777/**
2778 * @defgroup LLVMCCorePassRegistry Pass Registry
2779 *
2780 * @{
2781 */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002782
2783/** Return the global pass registry, for use with initialization functions.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002784 @see llvm::PassRegistry::getPassRegistry */
Owen Anderson4698c5d2010-10-07 17:55:47 +00002785LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002786
Gregory Szorc34c863a2012-03-21 03:54:29 +00002787/**
2788 * @}
2789 */
2790
2791/**
2792 * @defgroup LLVMCCorePassManagers Pass Managers
2793 *
2794 * @{
2795 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002796
2797/** Constructs a new whole-module pass pipeline. This type of pipeline is
2798 suitable for link-time optimization and whole-module transformations.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002799 @see llvm::PassManager::PassManager */
Gordon Henriksena735a9c2008-05-04 12:55:34 +00002800LLVMPassManagerRef LLVMCreatePassManager(void);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002801
2802/** Constructs a new function-by-function pass pipeline over the module
2803 provider. It does not take ownership of the module provider. This type of
2804 pipeline is suitable for code generation and JIT compilation tasks.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002805 @see llvm::FunctionPassManager::FunctionPassManager */
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +00002806LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2807
2808/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002809LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2810
2811/** Initializes, executes on the provided module, and finalizes all of the
2812 passes scheduled in the pass manager. Returns 1 if any of the passes
Gregory Szorc34c863a2012-03-21 03:54:29 +00002813 modified the module, 0 otherwise.
2814 @see llvm::PassManager::run(Module&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002815LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002816
2817/** Initializes all of the function passes scheduled in the function pass
2818 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002819 @see llvm::FunctionPassManager::doInitialization */
Chris Lattner25963c62010-01-09 22:27:07 +00002820LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002821
2822/** Executes all of the function passes scheduled in the function pass manager
2823 on the provided function. Returns 1 if any of the passes modified the
2824 function, false otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002825 @see llvm::FunctionPassManager::run(Function&) */
Chris Lattner25963c62010-01-09 22:27:07 +00002826LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002827
2828/** Finalizes all of the function passes scheduled in in the function pass
2829 manager. Returns 1 if any of the passes modified the module, 0 otherwise.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002830 @see llvm::FunctionPassManager::doFinalization */
Chris Lattner25963c62010-01-09 22:27:07 +00002831LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
Gordon Henriksen878114b2008-03-16 04:20:44 +00002832
2833/** Frees the memory of a pass pipeline. For function pipelines, does not free
2834 the module provider.
Gregory Szorc34c863a2012-03-21 03:54:29 +00002835 @see llvm::PassManagerBase::~PassManagerBase. */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002836void LLVMDisposePassManager(LLVMPassManagerRef PM);
2837
Gregory Szorc34c863a2012-03-21 03:54:29 +00002838/**
2839 * @}
2840 */
2841
2842/**
Duncan Sands1cba0a82013-02-17 16:35:51 +00002843 * @defgroup LLVMCCoreThreading Threading
2844 *
2845 * Handle the structures needed to make LLVM safe for multithreading.
2846 *
2847 * @{
2848 */
2849
2850/** Allocate and initialize structures needed to make LLVM safe for
2851 multithreading. The return value indicates whether multithreaded
2852 initialization succeeded. Must be executed in isolation from all
2853 other LLVM api calls.
2854 @see llvm::llvm_start_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002855LLVMBool LLVMStartMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002856
2857/** Deallocate structures necessary to make LLVM safe for multithreading.
2858 Must be executed in isolation from all other LLVM api calls.
2859 @see llvm::llvm_stop_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002860void LLVMStopMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002861
2862/** Check whether LLVM is executing in thread-safe mode or not.
2863 @see llvm::llvm_is_multithreaded */
Benjamin Kramer325ec892013-10-23 16:57:34 +00002864LLVMBool LLVMIsMultithreaded(void);
Duncan Sands1cba0a82013-02-17 16:35:51 +00002865
2866/**
2867 * @}
2868 */
2869
2870/**
Gregory Szorc34c863a2012-03-21 03:54:29 +00002871 * @}
2872 */
2873
2874/**
2875 * @}
2876 */
Gordon Henriksen878114b2008-03-16 04:20:44 +00002877
Gordon Henriksen76a03742007-09-18 03:18:57 +00002878#ifdef __cplusplus
2879}
Evan Cheng2e254d02013-04-04 17:40:53 +00002880#endif /* !defined(__cplusplus) */
Gordon Henriksen7330acd2007-10-05 23:59:36 +00002881
Evan Cheng2e254d02013-04-04 17:40:53 +00002882#endif /* !defined(LLVM_C_CORE_H) */