Core.h revision 234353
1193323Sed/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2193323Sed|*                                                                            *|
3193323Sed|*                     The LLVM Compiler Infrastructure                       *|
4193323Sed|*                                                                            *|
5193323Sed|* This file is distributed under the University of Illinois Open Source      *|
6193323Sed|* License. See LICENSE.TXT for details.                                      *|
7193323Sed|*                                                                            *|
8193323Sed|*===----------------------------------------------------------------------===*|
9193323Sed|*                                                                            *|
10193323Sed|* This header declares the C interface to libLLVMCore.a, which implements    *|
11193323Sed|* the LLVM intermediate representation.                                      *|
12193323Sed|*                                                                            *|
13193323Sed\*===----------------------------------------------------------------------===*/
14193323Sed
15193323Sed#ifndef LLVM_C_CORE_H
16193323Sed#define LLVM_C_CORE_H
17193323Sed
18218893Sdim#include "llvm/Support/DataTypes.h"
19198090Srdivacky
20193323Sed#ifdef __cplusplus
21193323Sed
22193323Sed/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
23193323Sed   and 'unwrap' conversion functions. */
24193323Sed#include "llvm/Module.h"
25218893Sdim#include "llvm/PassRegistry.h"
26193323Sed#include "llvm/Support/IRBuilder.h"
27193323Sed
28193323Sedextern "C" {
29193323Sed#endif
30193323Sed
31234353Sdim/**
32234353Sdim * @defgroup LLVMC LLVM-C: C interface to LLVM
33234353Sdim *
34234353Sdim * This module exposes parts of the LLVM library as a C API.
35234353Sdim *
36234353Sdim * @{
37234353Sdim */
38193323Sed
39234353Sdim/**
40234353Sdim * @defgroup LLVMCTransforms Transforms
41234353Sdim */
42234353Sdim
43234353Sdim/**
44234353Sdim * @defgroup LLVMCCore Core
45234353Sdim *
46234353Sdim * This modules provide an interface to libLLVMCore, which implements
47234353Sdim * the LLVM intermediate representation as well as other related types
48234353Sdim * and utilities.
49234353Sdim *
50234353Sdim * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
51234353Sdim * parameters must be passed as base types. Despite the declared types, most
52234353Sdim * of the functions provided operate only on branches of the type hierarchy.
53234353Sdim * The declared parameter names are descriptive and specify which type is
54234353Sdim * required. Additionally, each type hierarchy is documented along with the
55234353Sdim * functions that operate upon it. For more detail, refer to LLVM's C++ code.
56234353Sdim * If in doubt, refer to Core.cpp, which performs paramter downcasts in the
57234353Sdim * form unwrap<RequiredType>(Param).
58234353Sdim *
59234353Sdim * Many exotic languages can interoperate with C code but have a harder time
60234353Sdim * with C++ due to name mangling. So in addition to C, this interface enables
61234353Sdim * tools written in such languages.
62234353Sdim *
63234353Sdim * When included into a C++ source file, also declares 'wrap' and 'unwrap'
64234353Sdim * helpers to perform opaque reference<-->pointer conversions. These helpers
65234353Sdim * are shorter and more tightly typed than writing the casts by hand when
66234353Sdim * authoring bindings. In assert builds, they will do runtime type checking.
67234353Sdim *
68234353Sdim * @{
69234353Sdim */
70234353Sdim
71234353Sdim/**
72234353Sdim * @defgroup LLVMCCoreTypes Types and Enumerations
73234353Sdim *
74234353Sdim * @{
75234353Sdim */
76234353Sdim
77202375Srdivackytypedef int LLVMBool;
78202375Srdivacky
79193323Sed/* Opaque types. */
80193323Sed
81193323Sed/**
82234353Sdim * The top-level container for all LLVM global data. See the LLVMContext class.
83195340Sed */
84198090Srdivackytypedef struct LLVMOpaqueContext *LLVMContextRef;
85195340Sed
86195340Sed/**
87193323Sed * The top-level container for all other LLVM Intermediate Representation (IR)
88234353Sdim * objects.
89234353Sdim *
90234353Sdim * @see llvm::Module
91193323Sed */
92193323Sedtypedef struct LLVMOpaqueModule *LLVMModuleRef;
93193323Sed
94193323Sed/**
95234353Sdim * Each value in the LLVM IR has a type, an LLVMTypeRef.
96234353Sdim *
97234353Sdim * @see llvm::Type
98193323Sed */
99193323Sedtypedef struct LLVMOpaqueType *LLVMTypeRef;
100193323Sed
101234353Sdim/**
102234353Sdim * Represents an individual value in LLVM IR.
103234353Sdim *
104234353Sdim * This models llvm::Value.
105234353Sdim */
106193323Sedtypedef struct LLVMOpaqueValue *LLVMValueRef;
107234353Sdim
108234353Sdim/**
109234353Sdim * Represents a basic block of instruction in LLVM IR.
110234353Sdim *
111234353Sdim * This models llvm::BasicBlock.
112234353Sdim */
113193323Sedtypedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
114234353Sdim
115234353Sdim/**
116234353Sdim * Represents an LLVM basic block builder.
117234353Sdim *
118234353Sdim * This models llvm::IRBuilder.
119234353Sdim */
120193323Sedtypedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
121193323Sed
122234353Sdim/**
123234353Sdim * Interface used to provide a module to JIT or interpreter.
124234353Sdim * This is now just a synonym for llvm::Module, but we have to keep using the
125234353Sdim * different type to keep binary compatibility.
126193323Sed */
127193323Sedtypedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
128193323Sed
129234353Sdim/**
130234353Sdim * Used to provide a module to JIT or interpreter.
131234353Sdim *
132234353Sdim * @see llvm::MemoryBuffer
133193323Sed */
134193323Sedtypedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
135193323Sed
136234353Sdim/** @see llvm::PassManagerBase */
137193323Sedtypedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
138193323Sed
139234353Sdim/** @see llvm::PassRegistry */
140218893Sdimtypedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef;
141218893Sdim
142234353Sdim/**
143234353Sdim * Used to get the users and usees of a Value.
144234353Sdim *
145234353Sdim * @see llvm::Use */
146204642Srdivackytypedef struct LLVMOpaqueUse *LLVMUseRef;
147198090Srdivacky
148193323Sedtypedef enum {
149193323Sed    LLVMZExtAttribute       = 1<<0,
150193323Sed    LLVMSExtAttribute       = 1<<1,
151193323Sed    LLVMNoReturnAttribute   = 1<<2,
152193323Sed    LLVMInRegAttribute      = 1<<3,
153193323Sed    LLVMStructRetAttribute  = 1<<4,
154193323Sed    LLVMNoUnwindAttribute   = 1<<5,
155193323Sed    LLVMNoAliasAttribute    = 1<<6,
156193323Sed    LLVMByValAttribute      = 1<<7,
157193323Sed    LLVMNestAttribute       = 1<<8,
158193323Sed    LLVMReadNoneAttribute   = 1<<9,
159198090Srdivacky    LLVMReadOnlyAttribute   = 1<<10,
160198090Srdivacky    LLVMNoInlineAttribute   = 1<<11,
161198090Srdivacky    LLVMAlwaysInlineAttribute    = 1<<12,
162198090Srdivacky    LLVMOptimizeForSizeAttribute = 1<<13,
163198090Srdivacky    LLVMStackProtectAttribute    = 1<<14,
164198090Srdivacky    LLVMStackProtectReqAttribute = 1<<15,
165204792Srdivacky    LLVMAlignment = 31<<16,
166198090Srdivacky    LLVMNoCaptureAttribute  = 1<<21,
167198090Srdivacky    LLVMNoRedZoneAttribute  = 1<<22,
168198090Srdivacky    LLVMNoImplicitFloatAttribute = 1<<23,
169203954Srdivacky    LLVMNakedAttribute      = 1<<24,
170204792Srdivacky    LLVMInlineHintAttribute = 1<<25,
171226633Sdim    LLVMStackAlignment = 7<<26,
172226633Sdim    LLVMReturnsTwice = 1 << 29,
173226633Sdim    LLVMUWTable = 1 << 30,
174226633Sdim    LLVMNonLazyBind = 1 << 31
175234353Sdim
176234353Sdim    // FIXME: This attribute is currently not included in the C API as
177234353Sdim    // a temporary measure until the API/ABI impact to the C API is understood
178234353Sdim    // and the path forward agreed upon.
179234353Sdim    //LLVMAddressSafety = 1ULL << 32
180193323Sed} LLVMAttribute;
181193323Sed
182193323Sedtypedef enum {
183203954Srdivacky  /* Terminator Instructions */
184198090Srdivacky  LLVMRet            = 1,
185198090Srdivacky  LLVMBr             = 2,
186198090Srdivacky  LLVMSwitch         = 3,
187203954Srdivacky  LLVMIndirectBr     = 4,
188203954Srdivacky  LLVMInvoke         = 5,
189226633Sdim  /* removed 6 due to API changes */
190203954Srdivacky  LLVMUnreachable    = 7,
191203954Srdivacky
192203954Srdivacky  /* Standard Binary Operators */
193203954Srdivacky  LLVMAdd            = 8,
194203954Srdivacky  LLVMFAdd           = 9,
195203954Srdivacky  LLVMSub            = 10,
196203954Srdivacky  LLVMFSub           = 11,
197203954Srdivacky  LLVMMul            = 12,
198203954Srdivacky  LLVMFMul           = 13,
199203954Srdivacky  LLVMUDiv           = 14,
200203954Srdivacky  LLVMSDiv           = 15,
201203954Srdivacky  LLVMFDiv           = 16,
202203954Srdivacky  LLVMURem           = 17,
203203954Srdivacky  LLVMSRem           = 18,
204203954Srdivacky  LLVMFRem           = 19,
205203954Srdivacky
206203954Srdivacky  /* Logical Operators */
207203954Srdivacky  LLVMShl            = 20,
208203954Srdivacky  LLVMLShr           = 21,
209203954Srdivacky  LLVMAShr           = 22,
210203954Srdivacky  LLVMAnd            = 23,
211203954Srdivacky  LLVMOr             = 24,
212203954Srdivacky  LLVMXor            = 25,
213203954Srdivacky
214203954Srdivacky  /* Memory Operators */
215203954Srdivacky  LLVMAlloca         = 26,
216203954Srdivacky  LLVMLoad           = 27,
217203954Srdivacky  LLVMStore          = 28,
218203954Srdivacky  LLVMGetElementPtr  = 29,
219203954Srdivacky
220203954Srdivacky  /* Cast Operators */
221203954Srdivacky  LLVMTrunc          = 30,
222203954Srdivacky  LLVMZExt           = 31,
223203954Srdivacky  LLVMSExt           = 32,
224203954Srdivacky  LLVMFPToUI         = 33,
225203954Srdivacky  LLVMFPToSI         = 34,
226203954Srdivacky  LLVMUIToFP         = 35,
227203954Srdivacky  LLVMSIToFP         = 36,
228203954Srdivacky  LLVMFPTrunc        = 37,
229203954Srdivacky  LLVMFPExt          = 38,
230203954Srdivacky  LLVMPtrToInt       = 39,
231203954Srdivacky  LLVMIntToPtr       = 40,
232203954Srdivacky  LLVMBitCast        = 41,
233203954Srdivacky
234203954Srdivacky  /* Other Operators */
235203954Srdivacky  LLVMICmp           = 42,
236203954Srdivacky  LLVMFCmp           = 43,
237203954Srdivacky  LLVMPHI            = 44,
238203954Srdivacky  LLVMCall           = 45,
239203954Srdivacky  LLVMSelect         = 46,
240226633Sdim  LLVMUserOp1        = 47,
241226633Sdim  LLVMUserOp2        = 48,
242203954Srdivacky  LLVMVAArg          = 49,
243203954Srdivacky  LLVMExtractElement = 50,
244203954Srdivacky  LLVMInsertElement  = 51,
245203954Srdivacky  LLVMShuffleVector  = 52,
246203954Srdivacky  LLVMExtractValue   = 53,
247226633Sdim  LLVMInsertValue    = 54,
248226633Sdim
249226633Sdim  /* Atomic operators */
250226633Sdim  LLVMFence          = 55,
251226633Sdim  LLVMAtomicCmpXchg  = 56,
252226633Sdim  LLVMAtomicRMW      = 57,
253226633Sdim
254226633Sdim  /* Exception Handling Operators */
255226633Sdim  LLVMResume         = 58,
256234353Sdim  LLVMLandingPad     = 59
257226633Sdim
258198090Srdivacky} LLVMOpcode;
259198090Srdivacky
260198090Srdivackytypedef enum {
261193323Sed  LLVMVoidTypeKind,        /**< type with no size */
262234353Sdim  LLVMHalfTypeKind,        /**< 16 bit floating point type */
263193323Sed  LLVMFloatTypeKind,       /**< 32 bit floating point type */
264193323Sed  LLVMDoubleTypeKind,      /**< 64 bit floating point type */
265193323Sed  LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
266193323Sed  LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
267193323Sed  LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
268193323Sed  LLVMLabelTypeKind,       /**< Labels */
269193323Sed  LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
270193323Sed  LLVMFunctionTypeKind,    /**< Functions */
271193323Sed  LLVMStructTypeKind,      /**< Structures */
272193323Sed  LLVMArrayTypeKind,       /**< Arrays */
273193323Sed  LLVMPointerTypeKind,     /**< Pointers */
274198090Srdivacky  LLVMVectorTypeKind,      /**< SIMD 'packed' format, or other vector type */
275218893Sdim  LLVMMetadataTypeKind,    /**< Metadata */
276218893Sdim  LLVMX86_MMXTypeKind      /**< X86 MMX */
277193323Sed} LLVMTypeKind;
278193323Sed
279193323Sedtypedef enum {
280193323Sed  LLVMExternalLinkage,    /**< Externally visible function */
281193323Sed  LLVMAvailableExternallyLinkage,
282193323Sed  LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
283193323Sed  LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
284193323Sed                            equivalent. */
285193323Sed  LLVMWeakAnyLinkage,     /**< Keep one copy of function when linking (weak) */
286193323Sed  LLVMWeakODRLinkage,     /**< Same, but only replaced by something
287193323Sed                            equivalent. */
288193323Sed  LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
289193323Sed  LLVMInternalLinkage,    /**< Rename collisions when linking (static
290193323Sed                               functions) */
291193323Sed  LLVMPrivateLinkage,     /**< Like Internal, but omit from symbol table */
292193323Sed  LLVMDLLImportLinkage,   /**< Function to be imported from DLL */
293193323Sed  LLVMDLLExportLinkage,   /**< Function to be accessible from DLL */
294193323Sed  LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
295203954Srdivacky  LLVMGhostLinkage,       /**< Obsolete */
296198090Srdivacky  LLVMCommonLinkage,      /**< Tentative definitions */
297210299Sed  LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
298212904Sdim  LLVMLinkerPrivateWeakLinkage, /**< Like LinkerPrivate, but is weak. */
299212904Sdim  LLVMLinkerPrivateWeakDefAutoLinkage /**< Like LinkerPrivateWeak, but possibly
300212904Sdim                                           hidden. */
301193323Sed} LLVMLinkage;
302193323Sed
303193323Sedtypedef enum {
304193323Sed  LLVMDefaultVisibility,  /**< The GV is visible */
305193323Sed  LLVMHiddenVisibility,   /**< The GV is hidden */
306193323Sed  LLVMProtectedVisibility /**< The GV is protected */
307193323Sed} LLVMVisibility;
308193323Sed
309193323Sedtypedef enum {
310193323Sed  LLVMCCallConv           = 0,
311193323Sed  LLVMFastCallConv        = 8,
312193323Sed  LLVMColdCallConv        = 9,
313193323Sed  LLVMX86StdcallCallConv  = 64,
314193323Sed  LLVMX86FastcallCallConv = 65
315193323Sed} LLVMCallConv;
316193323Sed
317193323Sedtypedef enum {
318193323Sed  LLVMIntEQ = 32, /**< equal */
319193323Sed  LLVMIntNE,      /**< not equal */
320193323Sed  LLVMIntUGT,     /**< unsigned greater than */
321193323Sed  LLVMIntUGE,     /**< unsigned greater or equal */
322193323Sed  LLVMIntULT,     /**< unsigned less than */
323193323Sed  LLVMIntULE,     /**< unsigned less or equal */
324193323Sed  LLVMIntSGT,     /**< signed greater than */
325193323Sed  LLVMIntSGE,     /**< signed greater or equal */
326193323Sed  LLVMIntSLT,     /**< signed less than */
327193323Sed  LLVMIntSLE      /**< signed less or equal */
328193323Sed} LLVMIntPredicate;
329193323Sed
330193323Sedtypedef enum {
331193323Sed  LLVMRealPredicateFalse, /**< Always false (always folded) */
332193323Sed  LLVMRealOEQ,            /**< True if ordered and equal */
333193323Sed  LLVMRealOGT,            /**< True if ordered and greater than */
334193323Sed  LLVMRealOGE,            /**< True if ordered and greater than or equal */
335193323Sed  LLVMRealOLT,            /**< True if ordered and less than */
336193323Sed  LLVMRealOLE,            /**< True if ordered and less than or equal */
337193323Sed  LLVMRealONE,            /**< True if ordered and operands are unequal */
338193323Sed  LLVMRealORD,            /**< True if ordered (no nans) */
339193323Sed  LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
340193323Sed  LLVMRealUEQ,            /**< True if unordered or equal */
341193323Sed  LLVMRealUGT,            /**< True if unordered or greater than */
342193323Sed  LLVMRealUGE,            /**< True if unordered, greater than, or equal */
343193323Sed  LLVMRealULT,            /**< True if unordered or less than */
344193323Sed  LLVMRealULE,            /**< True if unordered, less than, or equal */
345193323Sed  LLVMRealUNE,            /**< True if unordered or not equal */
346193323Sed  LLVMRealPredicateTrue   /**< Always true (always folded) */
347193323Sed} LLVMRealPredicate;
348193323Sed
349226633Sdimtypedef enum {
350226633Sdim  LLVMLandingPadCatch,    /**< A catch clause   */
351226633Sdim  LLVMLandingPadFilter    /**< A filter clause  */
352226633Sdim} LLVMLandingPadClauseTy;
353226633Sdim
354234353Sdim/**
355234353Sdim * @}
356234353Sdim */
357234353Sdim
358223017Sdimvoid LLVMInitializeCore(LLVMPassRegistryRef R);
359193323Sed
360223017Sdim
361193323Sed/*===-- Error handling ----------------------------------------------------===*/
362193323Sed
363193323Sedvoid LLVMDisposeMessage(char *Message);
364193323Sed
365193323Sed
366234353Sdim/**
367234353Sdim * @defgroup LLVMCCoreContext Contexts
368234353Sdim *
369234353Sdim * Contexts are execution states for the core LLVM IR system.
370234353Sdim *
371234353Sdim * Most types are tied to a context instance. Multiple contexts can
372234353Sdim * exist simultaneously. A single context is not thread safe. However,
373234353Sdim * different contexts can execute on different threads simultaneously.
374234353Sdim *
375234353Sdim * @{
376234353Sdim */
377193323Sed
378234353Sdim/**
379234353Sdim * Create a new context.
380234353Sdim *
381234353Sdim * Every call to this function should be paired with a call to
382234353Sdim * LLVMContextDispose() or the context will leak memory.
383234353Sdim */
384198090SrdivackyLLVMContextRef LLVMContextCreate(void);
385234353Sdim
386234353Sdim/**
387234353Sdim * Obtain the global context instance.
388234353Sdim */
389198090SrdivackyLLVMContextRef LLVMGetGlobalContext(void);
390234353Sdim
391234353Sdim/**
392234353Sdim * Destroy a context instance.
393234353Sdim *
394234353Sdim * This should be called for every call to LLVMContextCreate() or memory
395234353Sdim * will be leaked.
396234353Sdim */
397195340Sedvoid LLVMContextDispose(LLVMContextRef C);
398195340Sed
399204642Srdivackyunsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
400204642Srdivacky                                  unsigned SLen);
401204642Srdivackyunsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
402204642Srdivacky
403234353Sdim/**
404234353Sdim * @}
405234353Sdim */
406204642Srdivacky
407234353Sdim/**
408234353Sdim * @defgroup LLVMCCoreModule Modules
409234353Sdim *
410234353Sdim * Modules represent the top-level structure in a LLVM program. An LLVM
411234353Sdim * module is effectively a translation unit or a collection of
412234353Sdim * translation units merged together.
413234353Sdim *
414234353Sdim * @{
415234353Sdim */
416234353Sdim
417234353Sdim/**
418234353Sdim * Create a new, empty module in the global context.
419234353Sdim *
420234353Sdim * This is equivalent to calling LLVMModuleCreateWithNameInContext with
421234353Sdim * LLVMGetGlobalContext() as the context parameter.
422234353Sdim *
423234353Sdim * Every invocation should be paired with LLVMDisposeModule() or memory
424234353Sdim * will be leaked.
425234353Sdim */
426193323SedLLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
427234353Sdim
428234353Sdim/**
429234353Sdim * Create a new, empty module in a specific context.
430234353Sdim *
431234353Sdim * Every invocation should be paired with LLVMDisposeModule() or memory
432234353Sdim * will be leaked.
433234353Sdim */
434195340SedLLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
435195340Sed                                                LLVMContextRef C);
436193323Sed
437234353Sdim/**
438234353Sdim * Destroy a module instance.
439234353Sdim *
440234353Sdim * This must be called for every created module or memory will be
441234353Sdim * leaked.
442234353Sdim */
443193323Sedvoid LLVMDisposeModule(LLVMModuleRef M);
444193323Sed
445234353Sdim/**
446234353Sdim * Obtain the data layout for a module.
447234353Sdim *
448234353Sdim * @see Module::getDataLayout()
449234353Sdim */
450193323Sedconst char *LLVMGetDataLayout(LLVMModuleRef M);
451234353Sdim
452234353Sdim/**
453234353Sdim * Set the data layout for a module.
454234353Sdim *
455234353Sdim * @see Module::setDataLayout()
456234353Sdim */
457193323Sedvoid LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
458193323Sed
459234353Sdim/**
460234353Sdim * Obtain the target triple for a module.
461234353Sdim *
462234353Sdim * @see Module::getTargetTriple()
463234353Sdim */
464193323Sedconst char *LLVMGetTarget(LLVMModuleRef M);
465234353Sdim
466234353Sdim/**
467234353Sdim * Set the target triple for a module.
468234353Sdim *
469234353Sdim * @see Module::setTargetTriple()
470234353Sdim */
471193323Sedvoid LLVMSetTarget(LLVMModuleRef M, const char *Triple);
472193323Sed
473234353Sdim/**
474234353Sdim * Dump a representation of a module to stderr.
475234353Sdim *
476234353Sdim * @see Module::dump()
477234353Sdim */
478193323Sedvoid LLVMDumpModule(LLVMModuleRef M);
479193323Sed
480234353Sdim/**
481234353Sdim * Set inline assembly for a module.
482234353Sdim *
483234353Sdim * @see Module::setModuleInlineAsm()
484234353Sdim */
485207618Srdivackyvoid LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
486193323Sed
487234353Sdim/**
488234353Sdim * Obtain the context to which this module is associated.
489234353Sdim *
490234353Sdim * @see Module::getContext()
491234353Sdim */
492218893SdimLLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
493218893Sdim
494234353Sdim/**
495234353Sdim * Obtain a Type from a module by its registered name.
496234353Sdim */
497234353SdimLLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
498193323Sed
499234353Sdim/**
500234353Sdim * Obtain the number of operands for named metadata in a module.
501234353Sdim *
502234353Sdim * @see llvm::Module::getNamedMetadata()
503234353Sdim */
504234353Sdimunsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
505234353Sdim
506234353Sdim/**
507234353Sdim * Obtain the named metadata operands for a module.
508234353Sdim *
509234353Sdim * The passed LLVMValueRef pointer should refer to an array of
510234353Sdim * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
511234353Sdim * array will be populated with the LLVMValueRef instances. Each
512234353Sdim * instance corresponds to a llvm::MDNode.
513234353Sdim *
514234353Sdim * @see llvm::Module::getNamedMetadata()
515234353Sdim * @see llvm::MDNode::getOperand()
516234353Sdim */
517234353Sdimvoid LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
518234353Sdim
519234353Sdim/**
520234353Sdim * Add an operand to named metadata.
521234353Sdim *
522234353Sdim * @see llvm::Module::getNamedMetadata()
523234353Sdim * @see llvm::MDNode::addOperand()
524234353Sdim */
525234353Sdimvoid LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
526234353Sdim                                 LLVMValueRef Val);
527234353Sdim
528234353Sdim/**
529234353Sdim * Add a function to a module under a specified name.
530234353Sdim *
531234353Sdim * @see llvm::Function::Create()
532234353Sdim */
533234353SdimLLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
534234353Sdim                             LLVMTypeRef FunctionTy);
535234353Sdim
536234353Sdim/**
537234353Sdim * Obtain a Function value from a Module by its name.
538234353Sdim *
539234353Sdim * The returned value corresponds to a llvm::Function value.
540234353Sdim *
541234353Sdim * @see llvm::Module::getFunction()
542234353Sdim */
543234353SdimLLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
544234353Sdim
545234353Sdim/**
546234353Sdim * Obtain an iterator to the first Function in a Module.
547234353Sdim *
548234353Sdim * @see llvm::Module::begin()
549234353Sdim */
550234353SdimLLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
551234353Sdim
552234353Sdim/**
553234353Sdim * Obtain an iterator to the last Function in a Module.
554234353Sdim *
555234353Sdim * @see llvm::Module::end()
556234353Sdim */
557234353SdimLLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
558234353Sdim
559234353Sdim/**
560234353Sdim * Advance a Function iterator to the next Function.
561234353Sdim *
562234353Sdim * Returns NULL if the iterator was already at the end and there are no more
563234353Sdim * functions.
564234353Sdim */
565234353SdimLLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
566234353Sdim
567234353Sdim/**
568234353Sdim * Decrement a Function iterator to the previous Function.
569234353Sdim *
570234353Sdim * Returns NULL if the iterator was already at the beginning and there are
571234353Sdim * no previous functions.
572234353Sdim */
573234353SdimLLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
574234353Sdim
575234353Sdim/**
576234353Sdim * @}
577234353Sdim */
578234353Sdim
579234353Sdim/**
580234353Sdim * @defgroup LLVMCCoreType Types
581234353Sdim *
582234353Sdim * Types represent the type of a value.
583234353Sdim *
584234353Sdim * Types are associated with a context instance. The context internally
585234353Sdim * deduplicates types so there is only 1 instance of a specific type
586234353Sdim * alive at a time. In other words, a unique type is shared among all
587234353Sdim * consumers within a context.
588234353Sdim *
589234353Sdim * A Type in the C API corresponds to llvm::Type.
590234353Sdim *
591234353Sdim * Types have the following hierarchy:
592234353Sdim *
593193323Sed *   types:
594193323Sed *     integer type
595193323Sed *     real type
596193323Sed *     function type
597193323Sed *     sequence types:
598193323Sed *       array type
599193323Sed *       pointer type
600193323Sed *       vector type
601193323Sed *     void type
602193323Sed *     label type
603193323Sed *     opaque type
604234353Sdim *
605234353Sdim * @{
606193323Sed */
607193323Sed
608234353Sdim/**
609234353Sdim * Obtain the enumerated type of a Type instance.
610234353Sdim *
611234353Sdim * @see llvm::Type:getTypeID()
612234353Sdim */
613193323SedLLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
614234353Sdim
615234353Sdim/**
616234353Sdim * Whether the type has a known size.
617234353Sdim *
618234353Sdim * Things that don't have a size are abstract types, labels, and void.a
619234353Sdim *
620234353Sdim * @see llvm::Type::isSized()
621234353Sdim */
622226633SdimLLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
623193323Sed
624234353Sdim/**
625234353Sdim * Obtain the context to which this type instance is associated.
626234353Sdim *
627234353Sdim * @see llvm::Type::getContext()
628234353Sdim */
629198090SrdivackyLLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
630198090Srdivacky
631234353Sdim/**
632234353Sdim * @defgroup LLVMCCoreTypeInt Integer Types
633234353Sdim *
634234353Sdim * Functions in this section operate on integer types.
635234353Sdim *
636234353Sdim * @{
637234353Sdim */
638234353Sdim
639234353Sdim/**
640234353Sdim * Obtain an integer type from a context with specified bit width.
641234353Sdim */
642198090SrdivackyLLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
643198090SrdivackyLLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
644198090SrdivackyLLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
645198090SrdivackyLLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
646198090SrdivackyLLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
647198090SrdivackyLLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
648198090Srdivacky
649234353Sdim/**
650234353Sdim * Obtain an integer type from the global context with a specified bit
651234353Sdim * width.
652234353Sdim */
653193323SedLLVMTypeRef LLVMInt1Type(void);
654193323SedLLVMTypeRef LLVMInt8Type(void);
655193323SedLLVMTypeRef LLVMInt16Type(void);
656193323SedLLVMTypeRef LLVMInt32Type(void);
657193323SedLLVMTypeRef LLVMInt64Type(void);
658193323SedLLVMTypeRef LLVMIntType(unsigned NumBits);
659193323Sedunsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
660193323Sed
661234353Sdim/**
662234353Sdim * @}
663234353Sdim */
664234353Sdim
665234353Sdim/**
666234353Sdim * @defgroup LLVMCCoreTypeFloat Floating Point Types
667234353Sdim *
668234353Sdim * @{
669234353Sdim */
670234353Sdim
671234353Sdim/**
672234353Sdim * Obtain a 16-bit floating point type from a context.
673234353Sdim */
674234353SdimLLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
675234353Sdim
676234353Sdim/**
677234353Sdim * Obtain a 32-bit floating point type from a context.
678234353Sdim */
679198090SrdivackyLLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
680234353Sdim
681234353Sdim/**
682234353Sdim * Obtain a 64-bit floating point type from a context.
683234353Sdim */
684198090SrdivackyLLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
685234353Sdim
686234353Sdim/**
687234353Sdim * Obtain a 80-bit floating point type (X87) from a context.
688234353Sdim */
689198090SrdivackyLLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
690234353Sdim
691234353Sdim/**
692234353Sdim * Obtain a 128-bit floating point type (112-bit mantissa) from a
693234353Sdim * context.
694234353Sdim */
695198090SrdivackyLLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
696234353Sdim
697234353Sdim/**
698234353Sdim * Obtain a 128-bit floating point type (two 64-bits) from a context.
699234353Sdim */
700198090SrdivackyLLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
701198090Srdivacky
702234353Sdim/**
703234353Sdim * Obtain a floating point type from the global context.
704234353Sdim *
705234353Sdim * These map to the functions in this group of the same name.
706234353Sdim */
707234353SdimLLVMTypeRef LLVMHalfType(void);
708193323SedLLVMTypeRef LLVMFloatType(void);
709193323SedLLVMTypeRef LLVMDoubleType(void);
710193323SedLLVMTypeRef LLVMX86FP80Type(void);
711193323SedLLVMTypeRef LLVMFP128Type(void);
712193323SedLLVMTypeRef LLVMPPCFP128Type(void);
713193323Sed
714234353Sdim/**
715234353Sdim * @}
716234353Sdim */
717234353Sdim
718234353Sdim/**
719234353Sdim * @defgroup LLVMCCoreTypeFunction Function Types
720234353Sdim *
721234353Sdim * @{
722234353Sdim */
723234353Sdim
724234353Sdim/**
725234353Sdim * Obtain a function type consisting of a specified signature.
726234353Sdim *
727234353Sdim * The function is defined as a tuple of a return Type, a list of
728234353Sdim * parameter types, and whether the function is variadic.
729234353Sdim */
730193323SedLLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
731193323Sed                             LLVMTypeRef *ParamTypes, unsigned ParamCount,
732202375Srdivacky                             LLVMBool IsVarArg);
733234353Sdim
734234353Sdim/**
735234353Sdim * Returns whether a function type is variadic.
736234353Sdim */
737202375SrdivackyLLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
738234353Sdim
739234353Sdim/**
740234353Sdim * Obtain the Type this function Type returns.
741234353Sdim */
742193323SedLLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
743234353Sdim
744234353Sdim/**
745234353Sdim * Obtain the number of parameters this function accepts.
746234353Sdim */
747193323Sedunsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
748234353Sdim
749234353Sdim/**
750234353Sdim * Obtain the types of a function's parameters.
751234353Sdim *
752234353Sdim * The Dest parameter should point to a pre-allocated array of
753234353Sdim * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
754234353Sdim * first LLVMCountParamTypes() entries in the array will be populated
755234353Sdim * with LLVMTypeRef instances.
756234353Sdim *
757234353Sdim * @param FunctionTy The function type to operate on.
758234353Sdim * @param Dest Memory address of an array to be filled with result.
759234353Sdim */
760193323Sedvoid LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
761193323Sed
762234353Sdim/**
763234353Sdim * @}
764234353Sdim */
765234353Sdim
766234353Sdim/**
767234353Sdim * @defgroup LLVMCCoreTypeStruct Structure Types
768234353Sdim *
769234353Sdim * These functions relate to LLVMTypeRef instances.
770234353Sdim *
771234353Sdim * @see llvm::StructType
772234353Sdim *
773234353Sdim * @{
774234353Sdim */
775234353Sdim
776234353Sdim/**
777234353Sdim * Create a new structure type in a context.
778234353Sdim *
779234353Sdim * A structure is specified by a list of inner elements/types and
780234353Sdim * whether these can be packed together.
781234353Sdim *
782234353Sdim * @see llvm::StructType::create()
783234353Sdim */
784198090SrdivackyLLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
785202375Srdivacky                                    unsigned ElementCount, LLVMBool Packed);
786234353Sdim
787234353Sdim/**
788234353Sdim * Create a new structure type in the global context.
789234353Sdim *
790234353Sdim * @see llvm::StructType::create()
791234353Sdim */
792193323SedLLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
793202375Srdivacky                           LLVMBool Packed);
794234353Sdim
795234353Sdim/**
796234353Sdim * Create an empty structure in a context having a specified name.
797234353Sdim *
798234353Sdim * @see llvm::StructType::create()
799234353Sdim */
800224145SdimLLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
801234353Sdim
802234353Sdim/**
803234353Sdim * Obtain the name of a structure.
804234353Sdim *
805234353Sdim * @see llvm::StructType::getName()
806234353Sdim */
807226633Sdimconst char *LLVMGetStructName(LLVMTypeRef Ty);
808234353Sdim
809234353Sdim/**
810234353Sdim * Set the contents of a structure type.
811234353Sdim *
812234353Sdim * @see llvm::StructType::setBody()
813234353Sdim */
814224145Sdimvoid LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
815224145Sdim                       unsigned ElementCount, LLVMBool Packed);
816224145Sdim
817234353Sdim/**
818234353Sdim * Get the number of elements defined inside the structure.
819234353Sdim *
820234353Sdim * @see llvm::StructType::getNumElements()
821234353Sdim */
822193323Sedunsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
823234353Sdim
824234353Sdim/**
825234353Sdim * Get the elements within a structure.
826234353Sdim *
827234353Sdim * The function is passed the address of a pre-allocated array of
828234353Sdim * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
829234353Sdim * invocation, this array will be populated with the structure's
830234353Sdim * elements. The objects in the destination array will have a lifetime
831234353Sdim * of the structure type itself, which is the lifetime of the context it
832234353Sdim * is contained in.
833234353Sdim */
834193323Sedvoid LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
835234353Sdim
836234353Sdim/**
837234353Sdim * Determine whether a structure is packed.
838234353Sdim *
839234353Sdim * @see llvm::StructType::isPacked()
840234353Sdim */
841202375SrdivackyLLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
842234353Sdim
843234353Sdim/**
844234353Sdim * Determine whether a structure is opaque.
845234353Sdim *
846234353Sdim * @see llvm::StructType::isOpaque()
847234353Sdim */
848224145SdimLLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
849193323Sed
850234353Sdim/**
851234353Sdim * @}
852234353Sdim */
853224145Sdim
854234353Sdim
855234353Sdim/**
856234353Sdim * @defgroup LLVMCCoreTypeSequential Sequential Types
857234353Sdim *
858234353Sdim * Sequential types represents "arrays" of types. This is a super class
859234353Sdim * for array, vector, and pointer types.
860234353Sdim *
861234353Sdim * @{
862234353Sdim */
863234353Sdim
864234353Sdim/**
865234353Sdim * Obtain the type of elements within a sequential type.
866234353Sdim *
867234353Sdim * This works on array, vector, and pointer types.
868234353Sdim *
869234353Sdim * @see llvm::SequentialType::getElementType()
870234353Sdim */
871234353SdimLLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
872234353Sdim
873234353Sdim/**
874234353Sdim * Create a fixed size array type that refers to a specific type.
875234353Sdim *
876234353Sdim * The created type will exist in the context that its element type
877234353Sdim * exists in.
878234353Sdim *
879234353Sdim * @see llvm::ArrayType::get()
880234353Sdim */
881193323SedLLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
882234353Sdim
883234353Sdim/**
884234353Sdim * Obtain the length of an array type.
885234353Sdim *
886234353Sdim * This only works on types that represent arrays.
887234353Sdim *
888234353Sdim * @see llvm::ArrayType::getNumElements()
889234353Sdim */
890234353Sdimunsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
891234353Sdim
892234353Sdim/**
893234353Sdim * Create a pointer type that points to a defined type.
894234353Sdim *
895234353Sdim * The created type will exist in the context that its pointee type
896234353Sdim * exists in.
897234353Sdim *
898234353Sdim * @see llvm::PointerType::get()
899234353Sdim */
900193323SedLLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
901234353Sdim
902234353Sdim/**
903234353Sdim * Obtain the address space of a pointer type.
904234353Sdim *
905234353Sdim * This only works on types that represent pointers.
906234353Sdim *
907234353Sdim * @see llvm::PointerType::getAddressSpace()
908234353Sdim */
909234353Sdimunsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
910234353Sdim
911234353Sdim/**
912234353Sdim * Create a vector type that contains a defined type and has a specific
913234353Sdim * number of elements.
914234353Sdim *
915234353Sdim * The created type will exist in the context thats its element type
916234353Sdim * exists in.
917234353Sdim *
918234353Sdim * @see llvm::VectorType::get()
919234353Sdim */
920193323SedLLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
921193323Sed
922234353Sdim/**
923234353Sdim * Obtain the number of elements in a vector type.
924234353Sdim *
925234353Sdim * This only works on types that represent vectors.
926234353Sdim *
927234353Sdim * @see llvm::VectorType::getNumElements()
928234353Sdim */
929193323Sedunsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
930193323Sed
931234353Sdim/**
932234353Sdim * @}
933234353Sdim */
934234353Sdim
935234353Sdim/**
936234353Sdim * @defgroup LLVMCCoreTypeOther Other Types
937234353Sdim *
938234353Sdim * @{
939234353Sdim */
940234353Sdim
941234353Sdim/**
942234353Sdim * Create a void type in a context.
943234353Sdim */
944198090SrdivackyLLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
945234353Sdim
946234353Sdim/**
947234353Sdim * Create a label type in a context.
948234353Sdim */
949198090SrdivackyLLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
950234353Sdim
951234353Sdim/**
952234353Sdim * Create a X86 MMX type in a context.
953234353Sdim */
954218893SdimLLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
955198090Srdivacky
956234353Sdim/**
957234353Sdim * These are similar to the above functions except they operate on the
958234353Sdim * global context.
959234353Sdim */
960193323SedLLVMTypeRef LLVMVoidType(void);
961193323SedLLVMTypeRef LLVMLabelType(void);
962218893SdimLLVMTypeRef LLVMX86MMXType(void);
963193323Sed
964234353Sdim/**
965234353Sdim * @}
966234353Sdim */
967193323Sed
968234353Sdim/**
969234353Sdim * @}
970234353Sdim */
971234353Sdim
972234353Sdim/**
973234353Sdim * @defgroup LLVMCCoreValues Values
974234353Sdim *
975234353Sdim * The bulk of LLVM's object model consists of values, which comprise a very
976193323Sed * rich type hierarchy.
977234353Sdim *
978234353Sdim * LLVMValueRef essentially represents llvm::Value. There is a rich
979234353Sdim * hierarchy of classes within this type. Depending on the instance
980234353Sdim * obtain, not all APIs are available.
981234353Sdim *
982234353Sdim * Callers can determine the type of a LLVMValueRef by calling the
983234353Sdim * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
984234353Sdim * functions are defined by a macro, so it isn't obvious which are
985234353Sdim * available by looking at the Doxygen source code. Instead, look at the
986234353Sdim * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
987234353Sdim * of value names given. These value names also correspond to classes in
988234353Sdim * the llvm::Value hierarchy.
989234353Sdim *
990234353Sdim * @{
991193323Sed */
992193323Sed
993193323Sed#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
994193323Sed  macro(Argument)                           \
995193323Sed  macro(BasicBlock)                         \
996193323Sed  macro(InlineAsm)                          \
997226633Sdim  macro(MDNode)                             \
998226633Sdim  macro(MDString)                           \
999193323Sed  macro(User)                               \
1000193323Sed    macro(Constant)                         \
1001226633Sdim      macro(BlockAddress)                   \
1002193323Sed      macro(ConstantAggregateZero)          \
1003193323Sed      macro(ConstantArray)                  \
1004193323Sed      macro(ConstantExpr)                   \
1005193323Sed      macro(ConstantFP)                     \
1006193323Sed      macro(ConstantInt)                    \
1007193323Sed      macro(ConstantPointerNull)            \
1008193323Sed      macro(ConstantStruct)                 \
1009193323Sed      macro(ConstantVector)                 \
1010193323Sed      macro(GlobalValue)                    \
1011193323Sed        macro(Function)                     \
1012193323Sed        macro(GlobalAlias)                  \
1013193323Sed        macro(GlobalVariable)               \
1014193323Sed      macro(UndefValue)                     \
1015193323Sed    macro(Instruction)                      \
1016193323Sed      macro(BinaryOperator)                 \
1017193323Sed      macro(CallInst)                       \
1018193323Sed        macro(IntrinsicInst)                \
1019193323Sed          macro(DbgInfoIntrinsic)           \
1020193323Sed            macro(DbgDeclareInst)           \
1021193323Sed          macro(MemIntrinsic)               \
1022193323Sed            macro(MemCpyInst)               \
1023193323Sed            macro(MemMoveInst)              \
1024193323Sed            macro(MemSetInst)               \
1025193323Sed      macro(CmpInst)                        \
1026226633Sdim        macro(FCmpInst)                     \
1027226633Sdim        macro(ICmpInst)                     \
1028193323Sed      macro(ExtractElementInst)             \
1029193323Sed      macro(GetElementPtrInst)              \
1030193323Sed      macro(InsertElementInst)              \
1031193323Sed      macro(InsertValueInst)                \
1032226633Sdim      macro(LandingPadInst)                 \
1033193323Sed      macro(PHINode)                        \
1034193323Sed      macro(SelectInst)                     \
1035193323Sed      macro(ShuffleVectorInst)              \
1036193323Sed      macro(StoreInst)                      \
1037193323Sed      macro(TerminatorInst)                 \
1038193323Sed        macro(BranchInst)                   \
1039226633Sdim        macro(IndirectBrInst)               \
1040193323Sed        macro(InvokeInst)                   \
1041193323Sed        macro(ReturnInst)                   \
1042193323Sed        macro(SwitchInst)                   \
1043193323Sed        macro(UnreachableInst)              \
1044226633Sdim        macro(ResumeInst)                   \
1045193323Sed    macro(UnaryInstruction)                 \
1046198892Srdivacky      macro(AllocaInst)                     \
1047193323Sed      macro(CastInst)                       \
1048193323Sed        macro(BitCastInst)                  \
1049193323Sed        macro(FPExtInst)                    \
1050193323Sed        macro(FPToSIInst)                   \
1051193323Sed        macro(FPToUIInst)                   \
1052193323Sed        macro(FPTruncInst)                  \
1053193323Sed        macro(IntToPtrInst)                 \
1054193323Sed        macro(PtrToIntInst)                 \
1055193323Sed        macro(SExtInst)                     \
1056193323Sed        macro(SIToFPInst)                   \
1057193323Sed        macro(TruncInst)                    \
1058193323Sed        macro(UIToFPInst)                   \
1059193323Sed        macro(ZExtInst)                     \
1060193323Sed      macro(ExtractValueInst)               \
1061193323Sed      macro(LoadInst)                       \
1062193323Sed      macro(VAArgInst)
1063193323Sed
1064234353Sdim/**
1065234353Sdim * @defgroup LLVMCCoreValueGeneral General APIs
1066234353Sdim *
1067234353Sdim * Functions in this section work on all LLVMValueRef instances,
1068234353Sdim * regardless of their sub-type. They correspond to functions available
1069234353Sdim * on llvm::Value.
1070234353Sdim *
1071234353Sdim * @{
1072234353Sdim */
1073234353Sdim
1074234353Sdim/**
1075234353Sdim * Obtain the type of a value.
1076234353Sdim *
1077234353Sdim * @see llvm::Value::getType()
1078234353Sdim */
1079193323SedLLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1080234353Sdim
1081234353Sdim/**
1082234353Sdim * Obtain the string name of a value.
1083234353Sdim *
1084234353Sdim * @see llvm::Value::getName()
1085234353Sdim */
1086193323Sedconst char *LLVMGetValueName(LLVMValueRef Val);
1087234353Sdim
1088234353Sdim/**
1089234353Sdim * Set the string name of a value.
1090234353Sdim *
1091234353Sdim * @see llvm::Value::setName()
1092234353Sdim */
1093193323Sedvoid LLVMSetValueName(LLVMValueRef Val, const char *Name);
1094234353Sdim
1095234353Sdim/**
1096234353Sdim * Dump a representation of a value to stderr.
1097234353Sdim *
1098234353Sdim * @see llvm::Value::dump()
1099234353Sdim */
1100193323Sedvoid LLVMDumpValue(LLVMValueRef Val);
1101234353Sdim
1102234353Sdim/**
1103234353Sdim * Replace all uses of a value with another one.
1104234353Sdim *
1105234353Sdim * @see llvm::Value::replaceAllUsesWith()
1106234353Sdim */
1107198090Srdivackyvoid LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1108193323Sed
1109234353Sdim/**
1110234353Sdim * Determine whether the specified constant instance is constant.
1111234353Sdim */
1112234353SdimLLVMBool LLVMIsConstant(LLVMValueRef Val);
1113234353Sdim
1114234353Sdim/**
1115234353Sdim * Determine whether a value instance is undefined.
1116234353Sdim */
1117234353SdimLLVMBool LLVMIsUndef(LLVMValueRef Val);
1118234353Sdim
1119234353Sdim/**
1120234353Sdim * Convert value instances between types.
1121234353Sdim *
1122234353Sdim * Internally, a LLVMValueRef is "pinned" to a specific type. This
1123234353Sdim * series of functions allows you to cast an instance to a specific
1124234353Sdim * type.
1125234353Sdim *
1126234353Sdim * If the cast is not valid for the specified type, NULL is returned.
1127234353Sdim *
1128234353Sdim * @see llvm::dyn_cast_or_null<>
1129234353Sdim */
1130193323Sed#define LLVM_DECLARE_VALUE_CAST(name) \
1131193323Sed  LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1132193323SedLLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1133193323Sed
1134234353Sdim/**
1135234353Sdim * @}
1136234353Sdim */
1137234353Sdim
1138234353Sdim/**
1139234353Sdim * @defgroup LLVMCCoreValueUses Usage
1140234353Sdim *
1141234353Sdim * This module defines functions that allow you to inspect the uses of a
1142234353Sdim * LLVMValueRef.
1143234353Sdim *
1144234353Sdim * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
1145234353Sdim * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1146234353Sdim * llvm::User and llvm::Value.
1147234353Sdim *
1148234353Sdim * @{
1149234353Sdim */
1150234353Sdim
1151234353Sdim/**
1152234353Sdim * Obtain the first use of a value.
1153234353Sdim *
1154234353Sdim * Uses are obtained in an iterator fashion. First, call this function
1155234353Sdim * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1156234353Sdim * on that instance and all subsequently obtained instances untl
1157234353Sdim * LLVMGetNextUse() returns NULL.
1158234353Sdim *
1159234353Sdim * @see llvm::Value::use_begin()
1160234353Sdim */
1161204642SrdivackyLLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1162234353Sdim
1163234353Sdim/**
1164234353Sdim * Obtain the next use of a value.
1165234353Sdim *
1166234353Sdim * This effectively advances the iterator. It returns NULL if you are on
1167234353Sdim * the final use and no more are available.
1168234353Sdim */
1169204642SrdivackyLLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1170234353Sdim
1171234353Sdim/**
1172234353Sdim * Obtain the user value for a user.
1173234353Sdim *
1174234353Sdim * The returned value corresponds to a llvm::User type.
1175234353Sdim *
1176234353Sdim * @see llvm::Use::getUser()
1177234353Sdim */
1178204642SrdivackyLLVMValueRef LLVMGetUser(LLVMUseRef U);
1179234353Sdim
1180234353Sdim/**
1181234353Sdim * Obtain the value this use corresponds to.
1182234353Sdim *
1183234353Sdim * @see llvm::Use::get().
1184234353Sdim */
1185204642SrdivackyLLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1186198090Srdivacky
1187234353Sdim/**
1188234353Sdim * @}
1189234353Sdim */
1190234353Sdim
1191234353Sdim/**
1192234353Sdim * @defgroup LLVMCCoreValueUser User value
1193234353Sdim *
1194234353Sdim * Function in this group pertain to LLVMValueRef instances that descent
1195234353Sdim * from llvm::User. This includes constants, instructions, and
1196234353Sdim * operators.
1197234353Sdim *
1198234353Sdim * @{
1199234353Sdim */
1200234353Sdim
1201234353Sdim/**
1202234353Sdim * Obtain an operand at a specific index in a llvm::User value.
1203234353Sdim *
1204234353Sdim * @see llvm::User::getOperand()
1205234353Sdim */
1206198090SrdivackyLLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1207234353Sdim
1208234353Sdim/**
1209234353Sdim * Set an operand at a specific index in a llvm::User value.
1210234353Sdim *
1211234353Sdim * @see llvm::User::setOperand()
1212234353Sdim */
1213212904Sdimvoid LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1214234353Sdim
1215234353Sdim/**
1216234353Sdim * Obtain the number of operands in a llvm::User value.
1217234353Sdim *
1218234353Sdim * @see llvm::User::getNumOperands()
1219234353Sdim */
1220212904Sdimint LLVMGetNumOperands(LLVMValueRef Val);
1221198090Srdivacky
1222234353Sdim/**
1223234353Sdim * @}
1224234353Sdim */
1225234353Sdim
1226234353Sdim/**
1227234353Sdim * @defgroup LLVMCCoreValueConstant Constants
1228234353Sdim *
1229234353Sdim * This section contains APIs for interacting with LLVMValueRef that
1230234353Sdim * correspond to llvm::Constant instances.
1231234353Sdim *
1232234353Sdim * These functions will work for any LLVMValueRef in the llvm::Constant
1233234353Sdim * class hierarchy.
1234234353Sdim *
1235234353Sdim * @{
1236234353Sdim */
1237234353Sdim
1238234353Sdim/**
1239234353Sdim * Obtain a constant value referring to the null instance of a type.
1240234353Sdim *
1241234353Sdim * @see llvm::Constant::getNullValue()
1242234353Sdim */
1243193323SedLLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1244234353Sdim
1245234353Sdim/**
1246234353Sdim * Obtain a constant value referring to the instance of a type
1247234353Sdim * consisting of all ones.
1248234353Sdim *
1249234353Sdim * This is only valid for integer types.
1250234353Sdim *
1251234353Sdim * @see llvm::Constant::getAllOnesValue()
1252234353Sdim */
1253234353SdimLLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1254234353Sdim
1255234353Sdim/**
1256234353Sdim * Obtain a constant value referring to an undefined value of a type.
1257234353Sdim *
1258234353Sdim * @see llvm::UndefValue::get()
1259234353Sdim */
1260193323SedLLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1261234353Sdim
1262234353Sdim/**
1263234353Sdim * Determine whether a value instance is null.
1264234353Sdim *
1265234353Sdim * @see llvm::Constant::isNullValue()
1266234353Sdim */
1267202375SrdivackyLLVMBool LLVMIsNull(LLVMValueRef Val);
1268234353Sdim
1269234353Sdim/**
1270234353Sdim * Obtain a constant that is a constant pointer pointing to NULL for a
1271234353Sdim * specified type.
1272234353Sdim */
1273198090SrdivackyLLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1274193323Sed
1275234353Sdim/**
1276234353Sdim * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1277234353Sdim *
1278234353Sdim * Functions in this group model LLVMValueRef instances that correspond
1279234353Sdim * to constants referring to scalar types.
1280234353Sdim *
1281234353Sdim * For integer types, the LLVMTypeRef parameter should correspond to a
1282234353Sdim * llvm::IntegerType instance and the returned LLVMValueRef will
1283234353Sdim * correspond to a llvm::ConstantInt.
1284234353Sdim *
1285234353Sdim * For floating point types, the LLVMTypeRef returned corresponds to a
1286234353Sdim * llvm::ConstantFP.
1287234353Sdim *
1288234353Sdim * @{
1289234353Sdim */
1290204642Srdivacky
1291234353Sdim/**
1292234353Sdim * Obtain a constant value for an integer type.
1293234353Sdim *
1294234353Sdim * The returned value corresponds to a llvm::ConstantInt.
1295234353Sdim *
1296234353Sdim * @see llvm::ConstantInt::get()
1297234353Sdim *
1298234353Sdim * @param IntTy Integer type to obtain value of.
1299234353Sdim * @param N The value the returned instance should refer to.
1300234353Sdim * @param SignExtend Whether to sign extend the produced value.
1301234353Sdim */
1302193323SedLLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1303202375Srdivacky                          LLVMBool SignExtend);
1304234353Sdim
1305234353Sdim/**
1306234353Sdim * Obtain a constant value for an integer of arbitrary precision.
1307234353Sdim *
1308234353Sdim * @see llvm::ConstantInt::get()
1309234353Sdim */
1310218893SdimLLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1311218893Sdim                                              unsigned NumWords,
1312218893Sdim                                              const uint64_t Words[]);
1313234353Sdim
1314234353Sdim/**
1315234353Sdim * Obtain a constant value for an integer parsed from a string.
1316234353Sdim *
1317234353Sdim * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1318234353Sdim * string's length is available, it is preferred to call that function
1319234353Sdim * instead.
1320234353Sdim *
1321234353Sdim * @see llvm::ConstantInt::get()
1322234353Sdim */
1323198090SrdivackyLLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1324198090Srdivacky                                  uint8_t Radix);
1325234353Sdim
1326234353Sdim/**
1327234353Sdim * Obtain a constant value for an integer parsed from a string with
1328234353Sdim * specified length.
1329234353Sdim *
1330234353Sdim * @see llvm::ConstantInt::get()
1331234353Sdim */
1332198090SrdivackyLLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1333198090Srdivacky                                         unsigned SLen, uint8_t Radix);
1334234353Sdim
1335234353Sdim/**
1336234353Sdim * Obtain a constant value referring to a double floating point value.
1337234353Sdim */
1338193323SedLLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1339234353Sdim
1340234353Sdim/**
1341234353Sdim * Obtain a constant for a floating point value parsed from a string.
1342234353Sdim *
1343234353Sdim * A similar API, LLVMConstRealOfStringAndSize is also available. It
1344234353Sdim * should be used if the input string's length is known.
1345234353Sdim */
1346193323SedLLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1347234353Sdim
1348234353Sdim/**
1349234353Sdim * Obtain a constant for a floating point value parsed from a string.
1350234353Sdim */
1351198090SrdivackyLLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1352198090Srdivacky                                          unsigned SLen);
1353234353Sdim
1354234353Sdim/**
1355234353Sdim * Obtain the zero extended value for an integer constant value.
1356234353Sdim *
1357234353Sdim * @see llvm::ConstantInt::getZExtValue()
1358234353Sdim */
1359198090Srdivackyunsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1360234353Sdim
1361234353Sdim/**
1362234353Sdim * Obtain the sign extended value for an integer constant value.
1363234353Sdim *
1364234353Sdim * @see llvm::ConstantInt::getSExtValue()
1365234353Sdim */
1366198090Srdivackylong long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1367193323Sed
1368234353Sdim/**
1369234353Sdim * @}
1370234353Sdim */
1371198090Srdivacky
1372234353Sdim/**
1373234353Sdim * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1374234353Sdim *
1375234353Sdim * Functions in this group operate on composite constants.
1376234353Sdim *
1377234353Sdim * @{
1378234353Sdim */
1379234353Sdim
1380234353Sdim/**
1381234353Sdim * Create a ConstantDataSequential and initialize it with a string.
1382234353Sdim *
1383234353Sdim * @see llvm::ConstantDataArray::getString()
1384234353Sdim */
1385198090SrdivackyLLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1386202375Srdivacky                                      unsigned Length, LLVMBool DontNullTerminate);
1387234353Sdim
1388234353Sdim/**
1389234353Sdim * Create a ConstantDataSequential with string content in the global context.
1390234353Sdim *
1391234353Sdim * This is the same as LLVMConstStringInContext except it operates on the
1392234353Sdim * global context.
1393234353Sdim *
1394234353Sdim * @see LLVMConstStringInContext()
1395234353Sdim * @see llvm::ConstantDataArray::getString()
1396234353Sdim */
1397234353SdimLLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1398234353Sdim                             LLVMBool DontNullTerminate);
1399234353Sdim
1400234353Sdim/**
1401234353Sdim * Create an anonymous ConstantStruct with the specified values.
1402234353Sdim *
1403234353Sdim * @see llvm::ConstantStruct::getAnon()
1404234353Sdim */
1405234353SdimLLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1406198090Srdivacky                                      LLVMValueRef *ConstantVals,
1407202375Srdivacky                                      unsigned Count, LLVMBool Packed);
1408198090Srdivacky
1409234353Sdim/**
1410234353Sdim * Create a ConstantStruct in the global Context.
1411234353Sdim *
1412234353Sdim * This is the same as LLVMConstStructInContext except it operates on the
1413234353Sdim * global Context.
1414234353Sdim *
1415234353Sdim * @see LLVMConstStructInContext()
1416234353Sdim */
1417234353SdimLLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1418234353Sdim                             LLVMBool Packed);
1419234353Sdim
1420234353Sdim/**
1421234353Sdim * Create a ConstantArray from values.
1422234353Sdim *
1423234353Sdim * @see llvm::ConstantArray::get()
1424234353Sdim */
1425193323SedLLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1426193323Sed                            LLVMValueRef *ConstantVals, unsigned Length);
1427234353Sdim
1428234353Sdim/**
1429234353Sdim * Create a non-anonymous ConstantStruct from values.
1430234353Sdim *
1431234353Sdim * @see llvm::ConstantStruct::get()
1432234353Sdim */
1433224145SdimLLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1434224145Sdim                                  LLVMValueRef *ConstantVals,
1435224145Sdim                                  unsigned Count);
1436234353Sdim
1437234353Sdim/**
1438234353Sdim * Create a ConstantVector from values.
1439234353Sdim *
1440234353Sdim * @see llvm::ConstantVector::get()
1441234353Sdim */
1442193323SedLLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1443193323Sed
1444234353Sdim/**
1445234353Sdim * @}
1446234353Sdim */
1447234353Sdim
1448234353Sdim/**
1449234353Sdim * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1450234353Sdim *
1451234353Sdim * Functions in this group correspond to APIs on llvm::ConstantExpr.
1452234353Sdim *
1453234353Sdim * @see llvm::ConstantExpr.
1454234353Sdim *
1455234353Sdim * @{
1456234353Sdim */
1457198090SrdivackyLLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1458198090SrdivackyLLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1459193323SedLLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1460193323SedLLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1461204642SrdivackyLLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1462204642SrdivackyLLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1463198090SrdivackyLLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1464193323SedLLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1465193323SedLLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1466198090SrdivackyLLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1467204642SrdivackyLLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1468198090SrdivackyLLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1469193323SedLLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1470204642SrdivackyLLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1471204642SrdivackyLLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1472198090SrdivackyLLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1473193323SedLLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1474204642SrdivackyLLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1475204642SrdivackyLLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1476198090SrdivackyLLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1477193323SedLLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1478193323SedLLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1479198090SrdivackyLLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1480193323SedLLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1481193323SedLLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1482193323SedLLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1483193323SedLLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1484193323SedLLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1485193323SedLLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1486193323SedLLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1487193323SedLLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1488193323Sed                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1489193323SedLLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1490193323Sed                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1491193323SedLLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1492193323SedLLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1493193323SedLLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1494193323SedLLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1495193323Sed                          LLVMValueRef *ConstantIndices, unsigned NumIndices);
1496198090SrdivackyLLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1497198090Srdivacky                                  LLVMValueRef *ConstantIndices,
1498198090Srdivacky                                  unsigned NumIndices);
1499193323SedLLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1500193323SedLLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1501193323SedLLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1502193323SedLLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1503193323SedLLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1504193323SedLLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1505193323SedLLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1506193323SedLLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1507193323SedLLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1508193323SedLLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1509193323SedLLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1510193323SedLLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1511198090SrdivackyLLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1512198090Srdivacky                                    LLVMTypeRef ToType);
1513198090SrdivackyLLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1514198090Srdivacky                                    LLVMTypeRef ToType);
1515198090SrdivackyLLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1516198090Srdivacky                                     LLVMTypeRef ToType);
1517198090SrdivackyLLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1518198090Srdivacky                                  LLVMTypeRef ToType);
1519198090SrdivackyLLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1520202375Srdivacky                              LLVMBool isSigned);
1521198090SrdivackyLLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1522193323SedLLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1523193323Sed                             LLVMValueRef ConstantIfTrue,
1524193323Sed                             LLVMValueRef ConstantIfFalse);
1525193323SedLLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1526193323Sed                                     LLVMValueRef IndexConstant);
1527193323SedLLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1528193323Sed                                    LLVMValueRef ElementValueConstant,
1529193323Sed                                    LLVMValueRef IndexConstant);
1530193323SedLLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1531193323Sed                                    LLVMValueRef VectorBConstant,
1532193323Sed                                    LLVMValueRef MaskConstant);
1533193323SedLLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1534193323Sed                                   unsigned NumIdx);
1535193323SedLLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1536193323Sed                                  LLVMValueRef ElementValueConstant,
1537193323Sed                                  unsigned *IdxList, unsigned NumIdx);
1538202375SrdivackyLLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1539193323Sed                                const char *AsmString, const char *Constraints,
1540202375Srdivacky                                LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1541204642SrdivackyLLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1542193323Sed
1543234353Sdim/**
1544234353Sdim * @}
1545234353Sdim */
1546234353Sdim
1547234353Sdim/**
1548234353Sdim * @defgroup LLVMCCoreValueConstantGlobals Global Values
1549234353Sdim *
1550234353Sdim * This group contains functions that operate on global values. Functions in
1551234353Sdim * this group relate to functions in the llvm::GlobalValue class tree.
1552234353Sdim *
1553234353Sdim * @see llvm::GlobalValue
1554234353Sdim *
1555234353Sdim * @{
1556234353Sdim */
1557234353Sdim
1558193323SedLLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1559202375SrdivackyLLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1560193323SedLLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1561193323Sedvoid LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1562193323Sedconst char *LLVMGetSection(LLVMValueRef Global);
1563193323Sedvoid LLVMSetSection(LLVMValueRef Global, const char *Section);
1564193323SedLLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1565193323Sedvoid LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1566193323Sedunsigned LLVMGetAlignment(LLVMValueRef Global);
1567193323Sedvoid LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
1568193323Sed
1569234353Sdim/**
1570234353Sdim * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1571234353Sdim *
1572234353Sdim * This group contains functions that operate on global variable values.
1573234353Sdim *
1574234353Sdim * @see llvm::GlobalVariable
1575234353Sdim *
1576234353Sdim * @{
1577234353Sdim */
1578193323SedLLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1579204642SrdivackyLLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1580204642Srdivacky                                         const char *Name,
1581204642Srdivacky                                         unsigned AddressSpace);
1582193323SedLLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1583193323SedLLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1584193323SedLLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1585193323SedLLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1586193323SedLLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1587193323Sedvoid LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1588193323SedLLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1589193323Sedvoid LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1590202375SrdivackyLLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1591202375Srdivackyvoid LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1592202375SrdivackyLLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1593202375Srdivackyvoid LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1594193323Sed
1595234353Sdim/**
1596234353Sdim * @}
1597234353Sdim */
1598234353Sdim
1599234353Sdim/**
1600234353Sdim * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1601234353Sdim *
1602234353Sdim * This group contains function that operate on global alias values.
1603234353Sdim *
1604234353Sdim * @see llvm::GlobalAlias
1605234353Sdim *
1606234353Sdim * @{
1607234353Sdim */
1608193323SedLLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1609193323Sed                          const char *Name);
1610193323Sed
1611234353Sdim/**
1612234353Sdim * @}
1613234353Sdim */
1614234353Sdim
1615234353Sdim/**
1616234353Sdim * @defgroup LLVMCCoreValueFunction Function values
1617234353Sdim *
1618234353Sdim * Functions in this group operate on LLVMValueRef instances that
1619234353Sdim * correspond to llvm::Function instances.
1620234353Sdim *
1621234353Sdim * @see llvm::Function
1622234353Sdim *
1623234353Sdim * @{
1624234353Sdim */
1625234353Sdim
1626234353Sdim/**
1627234353Sdim * Remove a function from its containing module and deletes it.
1628234353Sdim *
1629234353Sdim * @see llvm::Function::eraseFromParent()
1630234353Sdim */
1631193323Sedvoid LLVMDeleteFunction(LLVMValueRef Fn);
1632234353Sdim
1633234353Sdim/**
1634234353Sdim * Obtain the ID number from a function instance.
1635234353Sdim *
1636234353Sdim * @see llvm::Function::getIntrinsicID()
1637234353Sdim */
1638193323Sedunsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1639234353Sdim
1640234353Sdim/**
1641234353Sdim * Obtain the calling function of a function.
1642234353Sdim *
1643234353Sdim * The returned value corresponds to the LLVMCallConv enumeration.
1644234353Sdim *
1645234353Sdim * @see llvm::Function::getCallingConv()
1646234353Sdim */
1647193323Sedunsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1648234353Sdim
1649234353Sdim/**
1650234353Sdim * Set the calling convention of a function.
1651234353Sdim *
1652234353Sdim * @see llvm::Function::setCallingConv()
1653234353Sdim *
1654234353Sdim * @param Fn Function to operate on
1655234353Sdim * @param CC LLVMCallConv to set calling convention to
1656234353Sdim */
1657193323Sedvoid LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1658234353Sdim
1659234353Sdim/**
1660234353Sdim * Obtain the name of the garbage collector to use during code
1661234353Sdim * generation.
1662234353Sdim *
1663234353Sdim * @see llvm::Function::getGC()
1664234353Sdim */
1665193323Sedconst char *LLVMGetGC(LLVMValueRef Fn);
1666234353Sdim
1667234353Sdim/**
1668234353Sdim * Define the garbage collector to use during code generation.
1669234353Sdim *
1670234353Sdim * @see llvm::Function::setGC()
1671234353Sdim */
1672193323Sedvoid LLVMSetGC(LLVMValueRef Fn, const char *Name);
1673234353Sdim
1674234353Sdim/**
1675234353Sdim * Add an attribute to a function.
1676234353Sdim *
1677234353Sdim * @see llvm::Function::addAttribute()
1678234353Sdim */
1679193323Sedvoid LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1680234353Sdim
1681234353Sdim/**
1682234353Sdim * Obtain an attribute from a function.
1683234353Sdim *
1684234353Sdim * @see llvm::Function::getAttributes()
1685234353Sdim */
1686198090SrdivackyLLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1687234353Sdim
1688234353Sdim/**
1689234353Sdim * Remove an attribute from a function.
1690234353Sdim */
1691193323Sedvoid LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1692193323Sed
1693234353Sdim/**
1694234353Sdim * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1695234353Sdim *
1696234353Sdim * Functions in this group relate to arguments/parameters on functions.
1697234353Sdim *
1698234353Sdim * Functions in this group expect LLVMValueRef instances that correspond
1699234353Sdim * to llvm::Function instances.
1700234353Sdim *
1701234353Sdim * @{
1702234353Sdim */
1703234353Sdim
1704234353Sdim/**
1705234353Sdim * Obtain the number of parameters in a function.
1706234353Sdim *
1707234353Sdim * @see llvm::Function::arg_size()
1708234353Sdim */
1709193323Sedunsigned LLVMCountParams(LLVMValueRef Fn);
1710234353Sdim
1711234353Sdim/**
1712234353Sdim * Obtain the parameters in a function.
1713234353Sdim *
1714234353Sdim * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1715234353Sdim * at least LLVMCountParams() long. This array will be filled with
1716234353Sdim * LLVMValueRef instances which correspond to the parameters the
1717234353Sdim * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1718234353Sdim * instance.
1719234353Sdim *
1720234353Sdim * @see llvm::Function::arg_begin()
1721234353Sdim */
1722193323Sedvoid LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1723234353Sdim
1724234353Sdim/**
1725234353Sdim * Obtain the parameter at the specified index.
1726234353Sdim *
1727234353Sdim * Parameters are indexed from 0.
1728234353Sdim *
1729234353Sdim * @see llvm::Function::arg_begin()
1730234353Sdim */
1731193323SedLLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1732234353Sdim
1733234353Sdim/**
1734234353Sdim * Obtain the function to which this argument belongs.
1735234353Sdim *
1736234353Sdim * Unlike other functions in this group, this one takes a LLVMValueRef
1737234353Sdim * that corresponds to a llvm::Attribute.
1738234353Sdim *
1739234353Sdim * The returned LLVMValueRef is the llvm::Function to which this
1740234353Sdim * argument belongs.
1741234353Sdim */
1742193323SedLLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1743234353Sdim
1744234353Sdim/**
1745234353Sdim * Obtain the first parameter to a function.
1746234353Sdim *
1747234353Sdim * @see llvm::Function::arg_begin()
1748234353Sdim */
1749193323SedLLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1750234353Sdim
1751234353Sdim/**
1752234353Sdim * Obtain the last parameter to a function.
1753234353Sdim *
1754234353Sdim * @see llvm::Function::arg_end()
1755234353Sdim */
1756193323SedLLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1757234353Sdim
1758234353Sdim/**
1759234353Sdim * Obtain the next parameter to a function.
1760234353Sdim *
1761234353Sdim * This takes a LLVMValueRef obtained from LLVMGetFirstParam() (which is
1762234353Sdim * actually a wrapped iterator) and obtains the next parameter from the
1763234353Sdim * underlying iterator.
1764234353Sdim */
1765193323SedLLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1766234353Sdim
1767234353Sdim/**
1768234353Sdim * Obtain the previous parameter to a function.
1769234353Sdim *
1770234353Sdim * This is the opposite of LLVMGetNextParam().
1771234353Sdim */
1772193323SedLLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1773234353Sdim
1774234353Sdim/**
1775234353Sdim * Add an attribute to a function argument.
1776234353Sdim *
1777234353Sdim * @see llvm::Argument::addAttr()
1778234353Sdim */
1779193323Sedvoid LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1780234353Sdim
1781234353Sdim/**
1782234353Sdim * Remove an attribute from a function argument.
1783234353Sdim *
1784234353Sdim * @see llvm::Argument::removeAttr()
1785234353Sdim */
1786193323Sedvoid LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1787234353Sdim
1788234353Sdim/**
1789234353Sdim * Get an attribute from a function argument.
1790234353Sdim */
1791198090SrdivackyLLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1792234353Sdim
1793234353Sdim/**
1794234353Sdim * Set the alignment for a function parameter.
1795234353Sdim *
1796234353Sdim * @see llvm::Argument::addAttr()
1797234353Sdim * @see llvm::Attribute::constructAlignmentFromInt()
1798234353Sdim */
1799193323Sedvoid LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
1800193323Sed
1801234353Sdim/**
1802234353Sdim * @}
1803234353Sdim */
1804234353Sdim
1805234353Sdim/**
1806234353Sdim * @}
1807234353Sdim */
1808234353Sdim
1809234353Sdim/**
1810234353Sdim * @}
1811234353Sdim */
1812234353Sdim
1813234353Sdim/**
1814234353Sdim * @}
1815234353Sdim */
1816234353Sdim
1817234353Sdim/**
1818234353Sdim * @defgroup LLVMCCoreValueMetadata Metadata
1819234353Sdim *
1820234353Sdim * @{
1821234353Sdim */
1822234353Sdim
1823234353Sdim/**
1824234353Sdim * Obtain a MDString value from a context.
1825234353Sdim *
1826234353Sdim * The returned instance corresponds to the llvm::MDString class.
1827234353Sdim *
1828234353Sdim * The instance is specified by string data of a specified length. The
1829234353Sdim * string content is copied, so the backing memory can be freed after
1830234353Sdim * this function returns.
1831234353Sdim */
1832234353SdimLLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
1833234353Sdim                                   unsigned SLen);
1834234353Sdim
1835234353Sdim/**
1836234353Sdim * Obtain a MDString value from the global context.
1837234353Sdim */
1838234353SdimLLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
1839234353Sdim
1840234353Sdim/**
1841234353Sdim * Obtain a MDNode value from a context.
1842234353Sdim *
1843234353Sdim * The returned value corresponds to the llvm::MDNode class.
1844234353Sdim */
1845234353SdimLLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
1846234353Sdim                                 unsigned Count);
1847234353Sdim
1848234353Sdim/**
1849234353Sdim * Obtain a MDNode value from the global context.
1850234353Sdim */
1851234353SdimLLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
1852234353Sdim
1853234353Sdim/**
1854234353Sdim * Obtain the underlying string from a MDString value.
1855234353Sdim *
1856234353Sdim * @param V Instance to obtain string from.
1857234353Sdim * @param Len Memory address which will hold length of returned string.
1858234353Sdim * @return String data in MDString.
1859234353Sdim */
1860234353Sdimconst char  *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
1861234353Sdim
1862234353Sdim/**
1863234353Sdim * @}
1864234353Sdim */
1865234353Sdim
1866234353Sdim/**
1867234353Sdim * @defgroup LLVMCCoreValueBasicBlock Basic Block
1868234353Sdim *
1869234353Sdim * A basic block represents a single entry single exit section of code.
1870234353Sdim * Basic blocks contain a list of instructions which form the body of
1871234353Sdim * the block.
1872234353Sdim *
1873234353Sdim * Basic blocks belong to functions. They have the type of label.
1874234353Sdim *
1875234353Sdim * Basic blocks are themselves values. However, the C API models them as
1876234353Sdim * LLVMBasicBlockRef.
1877234353Sdim *
1878234353Sdim * @see llvm::BasicBlock
1879234353Sdim *
1880234353Sdim * @{
1881234353Sdim */
1882234353Sdim
1883234353Sdim/**
1884234353Sdim * Convert a basic block instance to a value type.
1885234353Sdim */
1886193323SedLLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
1887234353Sdim
1888234353Sdim/**
1889234353Sdim * Determine whether a LLVMValueRef is itself a basic block.
1890234353Sdim */
1891202375SrdivackyLLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
1892234353Sdim
1893234353Sdim/**
1894234353Sdim * Convert a LLVMValueRef to a LLVMBasicBlockRef instance.
1895234353Sdim */
1896193323SedLLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
1897234353Sdim
1898234353Sdim/**
1899234353Sdim * Obtain the function to which a basic block belongs.
1900234353Sdim *
1901234353Sdim * @see llvm::BasicBlock::getParent()
1902234353Sdim */
1903193323SedLLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
1904234353Sdim
1905234353Sdim/**
1906234353Sdim * Obtain the terminator instruction for a basic block.
1907234353Sdim *
1908234353Sdim * If the basic block does not have a terminator (it is not well-formed
1909234353Sdim * if it doesn't), then NULL is returned.
1910234353Sdim *
1911234353Sdim * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
1912234353Sdim *
1913234353Sdim * @see llvm::BasicBlock::getTerminator()
1914234353Sdim */
1915226633SdimLLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
1916234353Sdim
1917234353Sdim/**
1918234353Sdim * Obtain the number of basic blocks in a function.
1919234353Sdim *
1920234353Sdim * @param Fn Function value to operate on.
1921234353Sdim */
1922193323Sedunsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
1923234353Sdim
1924234353Sdim/**
1925234353Sdim * Obtain all of the basic blocks in a function.
1926234353Sdim *
1927234353Sdim * This operates on a function value. The BasicBlocks parameter is a
1928234353Sdim * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
1929234353Sdim * LLVMCountBasicBlocks() in length. This array is populated with
1930234353Sdim * LLVMBasicBlockRef instances.
1931234353Sdim */
1932193323Sedvoid LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
1933234353Sdim
1934234353Sdim/**
1935234353Sdim * Obtain the first basic block in a function.
1936234353Sdim *
1937234353Sdim * The returned basic block can be used as an iterator. You will likely
1938234353Sdim * eventually call into LLVMGetNextBasicBlock() with it.
1939234353Sdim *
1940234353Sdim * @see llvm::Function::begin()
1941234353Sdim */
1942193323SedLLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
1943234353Sdim
1944234353Sdim/**
1945234353Sdim * Obtain the last basic block in a function.
1946234353Sdim *
1947234353Sdim * @see llvm::Function::end()
1948234353Sdim */
1949193323SedLLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
1950234353Sdim
1951234353Sdim/**
1952234353Sdim * Advance a basic block iterator.
1953234353Sdim */
1954193323SedLLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
1955234353Sdim
1956234353Sdim/**
1957234353Sdim * Go backwards in a basic block iterator.
1958234353Sdim */
1959193323SedLLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
1960234353Sdim
1961234353Sdim/**
1962234353Sdim * Obtain the basic block that corresponds to the entry point of a
1963234353Sdim * function.
1964234353Sdim *
1965234353Sdim * @see llvm::Function::getEntryBlock()
1966234353Sdim */
1967193323SedLLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
1968198090Srdivacky
1969234353Sdim/**
1970234353Sdim * Append a basic block to the end of a function.
1971234353Sdim *
1972234353Sdim * @see llvm::BasicBlock::Create()
1973234353Sdim */
1974198090SrdivackyLLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1975198090Srdivacky                                                LLVMValueRef Fn,
1976198090Srdivacky                                                const char *Name);
1977234353Sdim
1978234353Sdim/**
1979234353Sdim * Append a basic block to the end of a function using the global
1980234353Sdim * context.
1981234353Sdim *
1982234353Sdim * @see llvm::BasicBlock::Create()
1983234353Sdim */
1984234353SdimLLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
1985234353Sdim
1986234353Sdim/**
1987234353Sdim * Insert a basic block in a function before another basic block.
1988234353Sdim *
1989234353Sdim * The function to add to is determined by the function of the
1990234353Sdim * passed basic block.
1991234353Sdim *
1992234353Sdim * @see llvm::BasicBlock::Create()
1993234353Sdim */
1994198090SrdivackyLLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1995198090Srdivacky                                                LLVMBasicBlockRef BB,
1996198090Srdivacky                                                const char *Name);
1997198090Srdivacky
1998234353Sdim/**
1999234353Sdim * Insert a basic block in a function using the global context.
2000234353Sdim *
2001234353Sdim * @see llvm::BasicBlock::Create()
2002234353Sdim */
2003193323SedLLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2004193323Sed                                       const char *Name);
2005234353Sdim
2006234353Sdim/**
2007234353Sdim * Remove a basic block from a function and delete it.
2008234353Sdim *
2009234353Sdim * This deletes the basic block from its containing function and deletes
2010234353Sdim * the basic block itself.
2011234353Sdim *
2012234353Sdim * @see llvm::BasicBlock::eraseFromParent()
2013234353Sdim */
2014193323Sedvoid LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2015234353Sdim
2016234353Sdim/**
2017234353Sdim * Remove a basic block from a function.
2018234353Sdim *
2019234353Sdim * This deletes the basic block from its containing function but keep
2020234353Sdim * the basic block alive.
2021234353Sdim *
2022234353Sdim * @see llvm::BasicBlock::removeFromParent()
2023234353Sdim */
2024226633Sdimvoid LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2025193323Sed
2026234353Sdim/**
2027234353Sdim * Move a basic block to before another one.
2028234353Sdim *
2029234353Sdim * @see llvm::BasicBlock::moveBefore()
2030234353Sdim */
2031212904Sdimvoid LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2032234353Sdim
2033234353Sdim/**
2034234353Sdim * Move a basic block to after another one.
2035234353Sdim *
2036234353Sdim * @see llvm::BasicBlock::moveAfter()
2037234353Sdim */
2038212904Sdimvoid LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2039212904Sdim
2040234353Sdim/**
2041234353Sdim * Obtain the first instruction in a basic block.
2042234353Sdim *
2043234353Sdim * The returned LLVMValueRef corresponds to a llvm::Instruction
2044234353Sdim * instance.
2045234353Sdim */
2046226633SdimLLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2047234353Sdim
2048234353Sdim/**
2049234353Sdim * Obtain the last instruction in a basic block.
2050234353Sdim *
2051234353Sdim * The returned LLVMValueRef corresponds to a LLVM:Instruction.
2052234353Sdim */
2053226633SdimLLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2054226633Sdim
2055234353Sdim/**
2056234353Sdim * @}
2057234353Sdim */
2058234353Sdim
2059234353Sdim/**
2060234353Sdim * @defgroup LLVMCCoreValueInstruction Instructions
2061234353Sdim *
2062234353Sdim * Functions in this group relate to the inspection and manipulation of
2063234353Sdim * individual instructions.
2064234353Sdim *
2065234353Sdim * In the C++ API, an instruction is modeled by llvm::Instruction. This
2066234353Sdim * class has a large number of descendents. llvm::Instruction is a
2067234353Sdim * llvm::Value and in the C API, instructions are modeled by
2068234353Sdim * LLVMValueRef.
2069234353Sdim *
2070234353Sdim * This group also contains sub-groups which operate on specific
2071234353Sdim * llvm::Instruction types, e.g. llvm::CallInst.
2072234353Sdim *
2073234353Sdim * @{
2074234353Sdim */
2075234353Sdim
2076234353Sdim/**
2077234353Sdim * Determine whether an instruction has any metadata attached.
2078234353Sdim */
2079234353Sdimint LLVMHasMetadata(LLVMValueRef Val);
2080234353Sdim
2081234353Sdim/**
2082234353Sdim * Return metadata associated with an instruction value.
2083234353Sdim */
2084234353SdimLLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2085234353Sdim
2086234353Sdim/**
2087234353Sdim * Set metadata associated with an instruction value.
2088234353Sdim */
2089234353Sdimvoid LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2090234353Sdim
2091234353Sdim/**
2092234353Sdim * Obtain the basic block to which an instruction belongs.
2093234353Sdim *
2094234353Sdim * @see llvm::Instruction::getParent()
2095234353Sdim */
2096193323SedLLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2097234353Sdim
2098234353Sdim/**
2099234353Sdim * Obtain the instruction that occurs after the one specified.
2100234353Sdim *
2101234353Sdim * The next instruction will be from the same basic block.
2102234353Sdim *
2103234353Sdim * If this is the last instruction in a basic block, NULL will be
2104234353Sdim * returned.
2105234353Sdim */
2106193323SedLLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2107234353Sdim
2108234353Sdim/**
2109234353Sdim * Obtain the instruction that occured before this one.
2110234353Sdim *
2111234353Sdim * If the instruction is the first instruction in a basic block, NULL
2112234353Sdim * will be returned.
2113234353Sdim */
2114193323SedLLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2115234353Sdim
2116234353Sdim/**
2117234353Sdim * Remove and delete an instruction.
2118234353Sdim *
2119234353Sdim * The instruction specified is removed from its containing building
2120234353Sdim * block and then deleted.
2121234353Sdim *
2122234353Sdim * @see llvm::Instruction::eraseFromParent()
2123234353Sdim */
2124226633Sdimvoid LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2125234353Sdim
2126234353Sdim/**
2127234353Sdim * Obtain the code opcode for an individual instruction.
2128234353Sdim *
2129234353Sdim * @see llvm::Instruction::getOpCode()
2130234353Sdim */
2131226633SdimLLVMOpcode   LLVMGetInstructionOpcode(LLVMValueRef Inst);
2132234353Sdim
2133234353Sdim/**
2134234353Sdim * Obtain the predicate of an instruction.
2135234353Sdim *
2136234353Sdim * This is only valid for instructions that correspond to llvm::ICmpInst
2137234353Sdim * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2138234353Sdim *
2139234353Sdim * @see llvm::ICmpInst::getPredicate()
2140234353Sdim */
2141226633SdimLLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2142193323Sed
2143234353Sdim/**
2144234353Sdim * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2145234353Sdim *
2146234353Sdim * Functions in this group apply to instructions that refer to call
2147234353Sdim * sites and invocations. These correspond to C++ types in the
2148234353Sdim * llvm::CallInst class tree.
2149234353Sdim *
2150234353Sdim * @{
2151234353Sdim */
2152234353Sdim
2153234353Sdim/**
2154234353Sdim * Set the calling convention for a call instruction.
2155234353Sdim *
2156234353Sdim * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2157234353Sdim * llvm::InvokeInst.
2158234353Sdim *
2159234353Sdim * @see llvm::CallInst::setCallingConv()
2160234353Sdim * @see llvm::InvokeInst::setCallingConv()
2161234353Sdim */
2162193323Sedvoid LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2163234353Sdim
2164234353Sdim/**
2165234353Sdim * Obtain the calling convention for a call instruction.
2166234353Sdim *
2167234353Sdim * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2168234353Sdim * usage.
2169234353Sdim *
2170234353Sdim * @see LLVMSetInstructionCallConv()
2171234353Sdim */
2172193323Sedunsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2173234353Sdim
2174234353Sdim
2175193323Sedvoid LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2176234353Sdimvoid LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2177193323Sed                              LLVMAttribute);
2178234353Sdimvoid LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2179193323Sed                                unsigned align);
2180193323Sed
2181234353Sdim/**
2182234353Sdim * Obtain whether a call instruction is a tail call.
2183234353Sdim *
2184234353Sdim * This only works on llvm::CallInst instructions.
2185234353Sdim *
2186234353Sdim * @see llvm::CallInst::isTailCall()
2187234353Sdim */
2188202375SrdivackyLLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2189234353Sdim
2190234353Sdim/**
2191234353Sdim * Set whether a call instruction is a tail call.
2192234353Sdim *
2193234353Sdim * This only works on llvm::CallInst instructions.
2194234353Sdim *
2195234353Sdim * @see llvm::CallInst::setTailCall()
2196234353Sdim */
2197202375Srdivackyvoid LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2198193323Sed
2199234353Sdim/**
2200234353Sdim * @}
2201234353Sdim */
2202234353Sdim
2203234353Sdim/**
2204234353Sdim * Obtain the default destination basic block of a switch instruction.
2205234353Sdim *
2206234353Sdim * This only works on llvm::SwitchInst instructions.
2207234353Sdim *
2208234353Sdim * @see llvm::SwitchInst::getDefaultDest()
2209234353Sdim */
2210226633SdimLLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2211226633Sdim
2212234353Sdim/**
2213234353Sdim * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2214234353Sdim *
2215234353Sdim * Functions in this group only apply to instructions that map to
2216234353Sdim * llvm::PHINode instances.
2217234353Sdim *
2218234353Sdim * @{
2219234353Sdim */
2220234353Sdim
2221234353Sdim/**
2222234353Sdim * Add an incoming value to the end of a PHI list.
2223234353Sdim */
2224193323Sedvoid LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2225193323Sed                     LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2226234353Sdim
2227234353Sdim/**
2228234353Sdim * Obtain the number of incoming basic blocks to a PHI node.
2229234353Sdim */
2230193323Sedunsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2231234353Sdim
2232234353Sdim/**
2233234353Sdim * Obtain an incoming value to a PHI node as a LLVMValueRef.
2234234353Sdim */
2235193323SedLLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2236234353Sdim
2237234353Sdim/**
2238234353Sdim * Obtain an incoming value to a PHI node as a LLVMBasicBlockRef.
2239234353Sdim */
2240193323SedLLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2241193323Sed
2242234353Sdim/**
2243234353Sdim * @}
2244234353Sdim */
2245193323Sed
2246234353Sdim/**
2247234353Sdim * @}
2248193323Sed */
2249193323Sed
2250234353Sdim/**
2251234353Sdim * @}
2252234353Sdim */
2253234353Sdim
2254234353Sdim/**
2255234353Sdim * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2256234353Sdim *
2257234353Sdim * An instruction builder represents a point within a basic block and is
2258234353Sdim * the exclusive means of building instructions using the C interface.
2259234353Sdim *
2260234353Sdim * @{
2261234353Sdim */
2262234353Sdim
2263198090SrdivackyLLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2264193323SedLLVMBuilderRef LLVMCreateBuilder(void);
2265193323Sedvoid LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2266193323Sed                         LLVMValueRef Instr);
2267193323Sedvoid LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2268193323Sedvoid LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2269193323SedLLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2270193323Sedvoid LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2271193323Sedvoid LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2272198090Srdivackyvoid LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2273198090Srdivacky                                   const char *Name);
2274193323Sedvoid LLVMDisposeBuilder(LLVMBuilderRef Builder);
2275193323Sed
2276204642Srdivacky/* Metadata */
2277204642Srdivackyvoid LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2278204642SrdivackyLLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2279204642Srdivackyvoid LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2280204642Srdivacky
2281193323Sed/* Terminators */
2282193323SedLLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2283193323SedLLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2284198090SrdivackyLLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2285198090Srdivacky                                   unsigned N);
2286193323SedLLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2287193323SedLLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2288193323Sed                             LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2289193323SedLLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2290193323Sed                             LLVMBasicBlockRef Else, unsigned NumCases);
2291204642SrdivackyLLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2292204642Srdivacky                                 unsigned NumDests);
2293193323SedLLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2294193323Sed                             LLVMValueRef *Args, unsigned NumArgs,
2295193323Sed                             LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2296193323Sed                             const char *Name);
2297226633SdimLLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2298226633Sdim                                 LLVMValueRef PersFn, unsigned NumClauses,
2299226633Sdim                                 const char *Name);
2300226633SdimLLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2301193323SedLLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2302193323Sed
2303193323Sed/* Add a case to the switch instruction */
2304193323Sedvoid LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2305193323Sed                 LLVMBasicBlockRef Dest);
2306193323Sed
2307204642Srdivacky/* Add a destination to the indirectbr instruction */
2308204642Srdivackyvoid LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2309204642Srdivacky
2310226633Sdim/* Add a catch or filter clause to the landingpad instruction */
2311226633Sdimvoid LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2312226633Sdim
2313226633Sdim/* Set the 'cleanup' flag in the landingpad instruction */
2314226633Sdimvoid LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2315226633Sdim
2316193323Sed/* Arithmetic */
2317193323SedLLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2318193323Sed                          const char *Name);
2319198090SrdivackyLLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2320198090Srdivacky                             const char *Name);
2321204642SrdivackyLLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2322204642Srdivacky                             const char *Name);
2323198090SrdivackyLLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2324198090Srdivacky                           const char *Name);
2325193323SedLLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2326193323Sed                          const char *Name);
2327204642SrdivackyLLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2328204642Srdivacky                             const char *Name);
2329204642SrdivackyLLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2330204642Srdivacky                             const char *Name);
2331198090SrdivackyLLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2332198090Srdivacky                           const char *Name);
2333193323SedLLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2334193323Sed                          const char *Name);
2335204642SrdivackyLLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2336204642Srdivacky                             const char *Name);
2337204642SrdivackyLLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2338204642Srdivacky                             const char *Name);
2339198090SrdivackyLLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2340198090Srdivacky                           const char *Name);
2341193323SedLLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2342193323Sed                           const char *Name);
2343193323SedLLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2344193323Sed                           const char *Name);
2345198090SrdivackyLLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2346198090Srdivacky                                const char *Name);
2347193323SedLLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2348193323Sed                           const char *Name);
2349193323SedLLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2350193323Sed                           const char *Name);
2351193323SedLLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2352193323Sed                           const char *Name);
2353193323SedLLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2354193323Sed                           const char *Name);
2355193323SedLLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2356193323Sed                           const char *Name);
2357193323SedLLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2358193323Sed                           const char *Name);
2359193323SedLLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2360193323Sed                           const char *Name);
2361193323SedLLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2362193323Sed                          const char *Name);
2363193323SedLLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2364193323Sed                          const char *Name);
2365193323SedLLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2366193323Sed                          const char *Name);
2367204642SrdivackyLLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2368204642Srdivacky                            LLVMValueRef LHS, LLVMValueRef RHS,
2369204642Srdivacky                            const char *Name);
2370193323SedLLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2371204642SrdivackyLLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2372204642Srdivacky                             const char *Name);
2373204642SrdivackyLLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2374204642Srdivacky                             const char *Name);
2375198090SrdivackyLLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2376193323SedLLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2377193323Sed
2378193323Sed/* Memory */
2379193323SedLLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2380193323SedLLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2381193323Sed                                  LLVMValueRef Val, const char *Name);
2382193323SedLLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2383193323SedLLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2384193323Sed                                  LLVMValueRef Val, const char *Name);
2385193323SedLLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2386193323SedLLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2387193323Sed                           const char *Name);
2388193323SedLLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2389193323SedLLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2390193323Sed                          LLVMValueRef *Indices, unsigned NumIndices,
2391193323Sed                          const char *Name);
2392198090SrdivackyLLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2393198090Srdivacky                                  LLVMValueRef *Indices, unsigned NumIndices,
2394198090Srdivacky                                  const char *Name);
2395198090SrdivackyLLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2396198090Srdivacky                                unsigned Idx, const char *Name);
2397198090SrdivackyLLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2398198090Srdivacky                                   const char *Name);
2399198090SrdivackyLLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2400198090Srdivacky                                      const char *Name);
2401234353SdimLLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2402234353Sdimvoid LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2403193323Sed
2404193323Sed/* Casts */
2405193323SedLLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2406193323Sed                            LLVMTypeRef DestTy, const char *Name);
2407193323SedLLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2408193323Sed                           LLVMTypeRef DestTy, const char *Name);
2409193323SedLLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2410193323Sed                           LLVMTypeRef DestTy, const char *Name);
2411193323SedLLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2412193323Sed                             LLVMTypeRef DestTy, const char *Name);
2413193323SedLLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2414193323Sed                             LLVMTypeRef DestTy, const char *Name);
2415193323SedLLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2416193323Sed                             LLVMTypeRef DestTy, const char *Name);
2417193323SedLLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2418193323Sed                             LLVMTypeRef DestTy, const char *Name);
2419193323SedLLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2420193323Sed                              LLVMTypeRef DestTy, const char *Name);
2421193323SedLLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2422193323Sed                            LLVMTypeRef DestTy, const char *Name);
2423193323SedLLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2424193323Sed                               LLVMTypeRef DestTy, const char *Name);
2425193323SedLLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2426193323Sed                               LLVMTypeRef DestTy, const char *Name);
2427193323SedLLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2428193323Sed                              LLVMTypeRef DestTy, const char *Name);
2429198090SrdivackyLLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2430198090Srdivacky                                    LLVMTypeRef DestTy, const char *Name);
2431198090SrdivackyLLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2432198090Srdivacky                                    LLVMTypeRef DestTy, const char *Name);
2433198090SrdivackyLLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2434198090Srdivacky                                     LLVMTypeRef DestTy, const char *Name);
2435204642SrdivackyLLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2436204642Srdivacky                           LLVMTypeRef DestTy, const char *Name);
2437198090SrdivackyLLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2438198090Srdivacky                                  LLVMTypeRef DestTy, const char *Name);
2439199989SrdivackyLLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2440198090Srdivacky                              LLVMTypeRef DestTy, const char *Name);
2441198090SrdivackyLLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2442198090Srdivacky                             LLVMTypeRef DestTy, const char *Name);
2443193323Sed
2444193323Sed/* Comparisons */
2445193323SedLLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2446193323Sed                           LLVMValueRef LHS, LLVMValueRef RHS,
2447193323Sed                           const char *Name);
2448193323SedLLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2449193323Sed                           LLVMValueRef LHS, LLVMValueRef RHS,
2450193323Sed                           const char *Name);
2451193323Sed
2452193323Sed/* Miscellaneous instructions */
2453193323SedLLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2454193323SedLLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2455193323Sed                           LLVMValueRef *Args, unsigned NumArgs,
2456193323Sed                           const char *Name);
2457193323SedLLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2458193323Sed                             LLVMValueRef Then, LLVMValueRef Else,
2459193323Sed                             const char *Name);
2460193323SedLLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2461193323Sed                            const char *Name);
2462193323SedLLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2463193323Sed                                     LLVMValueRef Index, const char *Name);
2464193323SedLLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2465193323Sed                                    LLVMValueRef EltVal, LLVMValueRef Index,
2466193323Sed                                    const char *Name);
2467193323SedLLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2468193323Sed                                    LLVMValueRef V2, LLVMValueRef Mask,
2469193323Sed                                    const char *Name);
2470193323SedLLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2471193323Sed                                   unsigned Index, const char *Name);
2472193323SedLLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2473193323Sed                                  LLVMValueRef EltVal, unsigned Index,
2474193323Sed                                  const char *Name);
2475193323Sed
2476198090SrdivackyLLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2477198090Srdivacky                             const char *Name);
2478198090SrdivackyLLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2479198090Srdivacky                                const char *Name);
2480198090SrdivackyLLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2481198090Srdivacky                              LLVMValueRef RHS, const char *Name);
2482193323Sed
2483234353Sdim/**
2484234353Sdim * @}
2485234353Sdim */
2486198090Srdivacky
2487234353Sdim/**
2488234353Sdim * @defgroup LLVMCCoreModuleProvider Module Providers
2489234353Sdim *
2490234353Sdim * @{
2491234353Sdim */
2492193323Sed
2493234353Sdim/**
2494234353Sdim * Changes the type of M so it can be passed to FunctionPassManagers and the
2495203954Srdivacky * JIT.  They take ModuleProviders for historical reasons.
2496193323Sed */
2497193323SedLLVMModuleProviderRef
2498193323SedLLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2499193323Sed
2500234353Sdim/**
2501234353Sdim * Destroys the module M.
2502193323Sed */
2503203954Srdivackyvoid LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2504193323Sed
2505234353Sdim/**
2506234353Sdim * @}
2507234353Sdim */
2508193323Sed
2509234353Sdim/**
2510234353Sdim * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2511234353Sdim *
2512234353Sdim * @{
2513234353Sdim */
2514193323Sed
2515202375SrdivackyLLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2516202375Srdivacky                                                  LLVMMemoryBufferRef *OutMemBuf,
2517202375Srdivacky                                                  char **OutMessage);
2518202375SrdivackyLLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2519202375Srdivacky                                         char **OutMessage);
2520193323Sedvoid LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2521193323Sed
2522234353Sdim/**
2523234353Sdim * @}
2524234353Sdim */
2525193323Sed
2526234353Sdim/**
2527234353Sdim * @defgroup LLVMCCorePassRegistry Pass Registry
2528234353Sdim *
2529234353Sdim * @{
2530234353Sdim */
2531234353Sdim
2532218893Sdim/** Return the global pass registry, for use with initialization functions.
2533234353Sdim    @see llvm::PassRegistry::getPassRegistry */
2534218893SdimLLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2535218893Sdim
2536234353Sdim/**
2537234353Sdim * @}
2538234353Sdim */
2539193323Sed
2540234353Sdim/**
2541234353Sdim * @defgroup LLVMCCorePassManagers Pass Managers
2542234353Sdim *
2543234353Sdim * @{
2544234353Sdim */
2545234353Sdim
2546193323Sed/** Constructs a new whole-module pass pipeline. This type of pipeline is
2547193323Sed    suitable for link-time optimization and whole-module transformations.
2548234353Sdim    @see llvm::PassManager::PassManager */
2549193323SedLLVMPassManagerRef LLVMCreatePassManager(void);
2550193323Sed
2551193323Sed/** Constructs a new function-by-function pass pipeline over the module
2552193323Sed    provider. It does not take ownership of the module provider. This type of
2553193323Sed    pipeline is suitable for code generation and JIT compilation tasks.
2554234353Sdim    @see llvm::FunctionPassManager::FunctionPassManager */
2555204642SrdivackyLLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2556204642Srdivacky
2557204642Srdivacky/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2558193323SedLLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2559193323Sed
2560193323Sed/** Initializes, executes on the provided module, and finalizes all of the
2561193323Sed    passes scheduled in the pass manager. Returns 1 if any of the passes
2562234353Sdim    modified the module, 0 otherwise.
2563234353Sdim    @see llvm::PassManager::run(Module&) */
2564202375SrdivackyLLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2565193323Sed
2566193323Sed/** Initializes all of the function passes scheduled in the function pass
2567193323Sed    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2568234353Sdim    @see llvm::FunctionPassManager::doInitialization */
2569202375SrdivackyLLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2570193323Sed
2571193323Sed/** Executes all of the function passes scheduled in the function pass manager
2572193323Sed    on the provided function. Returns 1 if any of the passes modified the
2573193323Sed    function, false otherwise.
2574234353Sdim    @see llvm::FunctionPassManager::run(Function&) */
2575202375SrdivackyLLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2576193323Sed
2577193323Sed/** Finalizes all of the function passes scheduled in in the function pass
2578193323Sed    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2579234353Sdim    @see llvm::FunctionPassManager::doFinalization */
2580202375SrdivackyLLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2581193323Sed
2582193323Sed/** Frees the memory of a pass pipeline. For function pipelines, does not free
2583193323Sed    the module provider.
2584234353Sdim    @see llvm::PassManagerBase::~PassManagerBase. */
2585193323Sedvoid LLVMDisposePassManager(LLVMPassManagerRef PM);
2586193323Sed
2587234353Sdim/**
2588234353Sdim * @}
2589234353Sdim */
2590193323Sed
2591234353Sdim/**
2592234353Sdim * @}
2593234353Sdim */
2594234353Sdim
2595234353Sdim/**
2596234353Sdim * @}
2597234353Sdim */
2598234353Sdim
2599193323Sed#ifdef __cplusplus
2600193323Sed}
2601193323Sed
2602193323Sednamespace llvm {
2603193323Sed  class MemoryBuffer;
2604193323Sed  class PassManagerBase;
2605193323Sed
2606193323Sed  #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
2607193323Sed    inline ty *unwrap(ref P) {                          \
2608193323Sed      return reinterpret_cast<ty*>(P);                  \
2609193323Sed    }                                                   \
2610193323Sed                                                        \
2611193323Sed    inline ref wrap(const ty *P) {                      \
2612193323Sed      return reinterpret_cast<ref>(const_cast<ty*>(P)); \
2613193323Sed    }
2614193323Sed
2615193323Sed  #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
2616193323Sed    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
2617193323Sed                                                        \
2618193323Sed    template<typename T>                                \
2619193323Sed    inline T *unwrap(ref P) {                           \
2620193323Sed      return cast<T>(unwrap(P));                        \
2621193323Sed    }
2622193323Sed
2623193323Sed  #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
2624193323Sed    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
2625193323Sed                                                        \
2626193323Sed    template<typename T>                                \
2627193323Sed    inline T *unwrap(ref P) {                           \
2628202878Srdivacky      T *Q = (T*)unwrap(P);                             \
2629193323Sed      assert(Q && "Invalid cast!");                     \
2630193323Sed      return Q;                                         \
2631193323Sed    }
2632193323Sed
2633193323Sed  DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
2634193323Sed  DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
2635193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
2636193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
2637193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
2638193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
2639195340Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
2640204642Srdivacky  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use,                LLVMUseRef           )
2641193323Sed  DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
2642218893Sdim  DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry,       LLVMPassRegistryRef  )
2643203954Srdivacky  /* LLVMModuleProviderRef exists for historical reasons, but now just holds a
2644203954Srdivacky   * Module.
2645203954Srdivacky   */
2646203954Srdivacky  inline Module *unwrap(LLVMModuleProviderRef MP) {
2647203954Srdivacky    return reinterpret_cast<Module*>(MP);
2648203954Srdivacky  }
2649193323Sed
2650193323Sed  #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
2651193323Sed  #undef DEFINE_ISA_CONVERSION_FUNCTIONS
2652193323Sed  #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
2653198090Srdivacky
2654198090Srdivacky  /* Specialized opaque context conversions.
2655198090Srdivacky   */
2656198090Srdivacky  inline LLVMContext **unwrap(LLVMContextRef* Tys) {
2657198090Srdivacky    return reinterpret_cast<LLVMContext**>(Tys);
2658198090Srdivacky  }
2659193323Sed
2660198090Srdivacky  inline LLVMContextRef *wrap(const LLVMContext **Tys) {
2661198090Srdivacky    return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
2662198090Srdivacky  }
2663198090Srdivacky
2664193323Sed  /* Specialized opaque type conversions.
2665193323Sed   */
2666193323Sed  inline Type **unwrap(LLVMTypeRef* Tys) {
2667193323Sed    return reinterpret_cast<Type**>(Tys);
2668193323Sed  }
2669193323Sed
2670226633Sdim  inline LLVMTypeRef *wrap(Type **Tys) {
2671193323Sed    return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
2672193323Sed  }
2673193323Sed
2674193323Sed  /* Specialized opaque value conversions.
2675193323Sed   */
2676193323Sed  inline Value **unwrap(LLVMValueRef *Vals) {
2677193323Sed    return reinterpret_cast<Value**>(Vals);
2678193323Sed  }
2679193323Sed
2680193323Sed  template<typename T>
2681193323Sed  inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
2682193323Sed    #if DEBUG
2683198090Srdivacky    for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
2684193323Sed      cast<T>(*I);
2685193323Sed    #endif
2686223017Sdim    (void)Length;
2687193323Sed    return reinterpret_cast<T**>(Vals);
2688193323Sed  }
2689193323Sed
2690193323Sed  inline LLVMValueRef *wrap(const Value **Vals) {
2691193323Sed    return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
2692193323Sed  }
2693193323Sed}
2694193323Sed
2695193323Sed#endif /* !defined(__cplusplus) */
2696193323Sed
2697193323Sed#endif /* !defined(LLVM_C_CORE_H) */
2698