1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2 |*                                                                            *|
3 |*                     The LLVM Compiler Infrastructure                       *|
4 |*                                                                            *|
5 |* This file is distributed under the University of Illinois Open Source      *|
6 |* License. See LICENSE.TXT for details.                                      *|
7 |*                                                                            *|
8 |*===----------------------------------------------------------------------===*|
9 |*                                                                            *|
10 |* This header declares the C interface to libLLVMCore.a, which implements    *|
11 |* the LLVM intermediate representation.                                      *|
12 |*                                                                            *|
13 \*===----------------------------------------------------------------------===*/
14 
15 #ifndef LLVM_C_CORE_H
16 #define LLVM_C_CORE_H
17 
18 #include "llvm-c/ErrorHandling.h"
19 #include "llvm-c/Types.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * @defgroup LLVMC LLVM-C: C interface to LLVM
27  *
28  * This module exposes parts of the LLVM library as a C API.
29  *
30  * @{
31  */
32 
33 /**
34  * @defgroup LLVMCTransforms Transforms
35  */
36 
37 /**
38  * @defgroup LLVMCCore Core
39  *
40  * This modules provide an interface to libLLVMCore, which implements
41  * the LLVM intermediate representation as well as other related types
42  * and utilities.
43  *
44  * Many exotic languages can interoperate with C code but have a harder time
45  * with C++ due to name mangling. So in addition to C, this interface enables
46  * tools written in such languages.
47  *
48  * @{
49  */
50 
51 /**
52  * @defgroup LLVMCCoreTypes Types and Enumerations
53  *
54  * @{
55  */
56 
57 typedef enum {
58     LLVMZExtAttribute       = 1<<0,
59     LLVMSExtAttribute       = 1<<1,
60     LLVMNoReturnAttribute   = 1<<2,
61     LLVMInRegAttribute      = 1<<3,
62     LLVMStructRetAttribute  = 1<<4,
63     LLVMNoUnwindAttribute   = 1<<5,
64     LLVMNoAliasAttribute    = 1<<6,
65     LLVMByValAttribute      = 1<<7,
66     LLVMNestAttribute       = 1<<8,
67     LLVMReadNoneAttribute   = 1<<9,
68     LLVMReadOnlyAttribute   = 1<<10,
69     LLVMNoInlineAttribute   = 1<<11,
70     LLVMAlwaysInlineAttribute    = 1<<12,
71     LLVMOptimizeForSizeAttribute = 1<<13,
72     LLVMStackProtectAttribute    = 1<<14,
73     LLVMStackProtectReqAttribute = 1<<15,
74     LLVMAlignment = 31<<16,
75     LLVMNoCaptureAttribute  = 1<<21,
76     LLVMNoRedZoneAttribute  = 1<<22,
77     LLVMNoImplicitFloatAttribute = 1<<23,
78     LLVMNakedAttribute      = 1<<24,
79     LLVMInlineHintAttribute = 1<<25,
80     LLVMStackAlignment = 7<<26,
81     LLVMReturnsTwice = 1 << 29,
82     LLVMUWTable = 1 << 30,
83     LLVMNonLazyBind = 1 << 31
84 
85     /* FIXME: These attributes are currently not included in the C API as
86        a temporary measure until the API/ABI impact to the C API is understood
87        and the path forward agreed upon.
88     LLVMSanitizeAddressAttribute = 1ULL << 32,
89     LLVMStackProtectStrongAttribute = 1ULL<<35,
90     LLVMColdAttribute = 1ULL << 40,
91     LLVMOptimizeNoneAttribute = 1ULL << 42,
92     LLVMInAllocaAttribute = 1ULL << 43,
93     LLVMNonNullAttribute = 1ULL << 44,
94     LLVMJumpTableAttribute = 1ULL << 45,
95     LLVMConvergentAttribute = 1ULL << 46,
96     LLVMSafeStackAttribute = 1ULL << 47,
97     */
98 } LLVMAttribute;
99 
100 typedef enum {
101   /* Terminator Instructions */
102   LLVMRet            = 1,
103   LLVMBr             = 2,
104   LLVMSwitch         = 3,
105   LLVMIndirectBr     = 4,
106   LLVMInvoke         = 5,
107   /* removed 6 due to API changes */
108   LLVMUnreachable    = 7,
109 
110   /* Standard Binary Operators */
111   LLVMAdd            = 8,
112   LLVMFAdd           = 9,
113   LLVMSub            = 10,
114   LLVMFSub           = 11,
115   LLVMMul            = 12,
116   LLVMFMul           = 13,
117   LLVMUDiv           = 14,
118   LLVMSDiv           = 15,
119   LLVMFDiv           = 16,
120   LLVMURem           = 17,
121   LLVMSRem           = 18,
122   LLVMFRem           = 19,
123 
124   /* Logical Operators */
125   LLVMShl            = 20,
126   LLVMLShr           = 21,
127   LLVMAShr           = 22,
128   LLVMAnd            = 23,
129   LLVMOr             = 24,
130   LLVMXor            = 25,
131 
132   /* Memory Operators */
133   LLVMAlloca         = 26,
134   LLVMLoad           = 27,
135   LLVMStore          = 28,
136   LLVMGetElementPtr  = 29,
137 
138   /* Cast Operators */
139   LLVMTrunc          = 30,
140   LLVMZExt           = 31,
141   LLVMSExt           = 32,
142   LLVMFPToUI         = 33,
143   LLVMFPToSI         = 34,
144   LLVMUIToFP         = 35,
145   LLVMSIToFP         = 36,
146   LLVMFPTrunc        = 37,
147   LLVMFPExt          = 38,
148   LLVMPtrToInt       = 39,
149   LLVMIntToPtr       = 40,
150   LLVMBitCast        = 41,
151   LLVMAddrSpaceCast  = 60,
152 
153   /* Other Operators */
154   LLVMICmp           = 42,
155   LLVMFCmp           = 43,
156   LLVMPHI            = 44,
157   LLVMCall           = 45,
158   LLVMSelect         = 46,
159   LLVMUserOp1        = 47,
160   LLVMUserOp2        = 48,
161   LLVMVAArg          = 49,
162   LLVMExtractElement = 50,
163   LLVMInsertElement  = 51,
164   LLVMShuffleVector  = 52,
165   LLVMExtractValue   = 53,
166   LLVMInsertValue    = 54,
167 
168   /* Atomic operators */
169   LLVMFence          = 55,
170   LLVMAtomicCmpXchg  = 56,
171   LLVMAtomicRMW      = 57,
172 
173   /* Exception Handling Operators */
174   LLVMResume         = 58,
175   LLVMLandingPad     = 59,
176   LLVMCleanupRet     = 61,
177   LLVMCatchRet       = 62,
178   LLVMCatchPad       = 63,
179   LLVMCleanupPad     = 64,
180   LLVMCatchSwitch    = 65
181 } LLVMOpcode;
182 
183 typedef enum {
184   LLVMVoidTypeKind,        /**< type with no size */
185   LLVMHalfTypeKind,        /**< 16 bit floating point type */
186   LLVMFloatTypeKind,       /**< 32 bit floating point type */
187   LLVMDoubleTypeKind,      /**< 64 bit floating point type */
188   LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
189   LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
190   LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
191   LLVMLabelTypeKind,       /**< Labels */
192   LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
193   LLVMFunctionTypeKind,    /**< Functions */
194   LLVMStructTypeKind,      /**< Structures */
195   LLVMArrayTypeKind,       /**< Arrays */
196   LLVMPointerTypeKind,     /**< Pointers */
197   LLVMVectorTypeKind,      /**< SIMD 'packed' format, or other vector type */
198   LLVMMetadataTypeKind,    /**< Metadata */
199   LLVMX86_MMXTypeKind,     /**< X86 MMX */
200   LLVMTokenTypeKind        /**< Tokens */
201 } LLVMTypeKind;
202 
203 typedef enum {
204   LLVMExternalLinkage,    /**< Externally visible function */
205   LLVMAvailableExternallyLinkage,
206   LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
207   LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
208                             equivalent. */
209   LLVMLinkOnceODRAutoHideLinkage, /**< Obsolete */
210   LLVMWeakAnyLinkage,     /**< Keep one copy of function when linking (weak) */
211   LLVMWeakODRLinkage,     /**< Same, but only replaced by something
212                             equivalent. */
213   LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
214   LLVMInternalLinkage,    /**< Rename collisions when linking (static
215                                functions) */
216   LLVMPrivateLinkage,     /**< Like Internal, but omit from symbol table */
217   LLVMDLLImportLinkage,   /**< Obsolete */
218   LLVMDLLExportLinkage,   /**< Obsolete */
219   LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
220   LLVMGhostLinkage,       /**< Obsolete */
221   LLVMCommonLinkage,      /**< Tentative definitions */
222   LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
223   LLVMLinkerPrivateWeakLinkage /**< Like LinkerPrivate, but is weak. */
224 } LLVMLinkage;
225 
226 typedef enum {
227   LLVMDefaultVisibility,  /**< The GV is visible */
228   LLVMHiddenVisibility,   /**< The GV is hidden */
229   LLVMProtectedVisibility /**< The GV is protected */
230 } LLVMVisibility;
231 
232 typedef enum {
233   LLVMDefaultStorageClass   = 0,
234   LLVMDLLImportStorageClass = 1, /**< Function to be imported from DLL. */
235   LLVMDLLExportStorageClass = 2  /**< Function to be accessible from DLL. */
236 } LLVMDLLStorageClass;
237 
238 typedef enum {
239   LLVMCCallConv           = 0,
240   LLVMFastCallConv        = 8,
241   LLVMColdCallConv        = 9,
242   LLVMWebKitJSCallConv    = 12,
243   LLVMAnyRegCallConv      = 13,
244   LLVMX86StdcallCallConv  = 64,
245   LLVMX86FastcallCallConv = 65
246 } LLVMCallConv;
247 
248 typedef enum {
249   LLVMIntEQ = 32, /**< equal */
250   LLVMIntNE,      /**< not equal */
251   LLVMIntUGT,     /**< unsigned greater than */
252   LLVMIntUGE,     /**< unsigned greater or equal */
253   LLVMIntULT,     /**< unsigned less than */
254   LLVMIntULE,     /**< unsigned less or equal */
255   LLVMIntSGT,     /**< signed greater than */
256   LLVMIntSGE,     /**< signed greater or equal */
257   LLVMIntSLT,     /**< signed less than */
258   LLVMIntSLE      /**< signed less or equal */
259 } LLVMIntPredicate;
260 
261 typedef enum {
262   LLVMRealPredicateFalse, /**< Always false (always folded) */
263   LLVMRealOEQ,            /**< True if ordered and equal */
264   LLVMRealOGT,            /**< True if ordered and greater than */
265   LLVMRealOGE,            /**< True if ordered and greater than or equal */
266   LLVMRealOLT,            /**< True if ordered and less than */
267   LLVMRealOLE,            /**< True if ordered and less than or equal */
268   LLVMRealONE,            /**< True if ordered and operands are unequal */
269   LLVMRealORD,            /**< True if ordered (no nans) */
270   LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
271   LLVMRealUEQ,            /**< True if unordered or equal */
272   LLVMRealUGT,            /**< True if unordered or greater than */
273   LLVMRealUGE,            /**< True if unordered, greater than, or equal */
274   LLVMRealULT,            /**< True if unordered or less than */
275   LLVMRealULE,            /**< True if unordered, less than, or equal */
276   LLVMRealUNE,            /**< True if unordered or not equal */
277   LLVMRealPredicateTrue   /**< Always true (always folded) */
278 } LLVMRealPredicate;
279 
280 typedef enum {
281   LLVMLandingPadCatch,    /**< A catch clause   */
282   LLVMLandingPadFilter    /**< A filter clause  */
283 } LLVMLandingPadClauseTy;
284 
285 typedef enum {
286   LLVMNotThreadLocal = 0,
287   LLVMGeneralDynamicTLSModel,
288   LLVMLocalDynamicTLSModel,
289   LLVMInitialExecTLSModel,
290   LLVMLocalExecTLSModel
291 } LLVMThreadLocalMode;
292 
293 typedef enum {
294   LLVMAtomicOrderingNotAtomic = 0, /**< A load or store which is not atomic */
295   LLVMAtomicOrderingUnordered = 1, /**< Lowest level of atomicity, guarantees
296                                      somewhat sane results, lock free. */
297   LLVMAtomicOrderingMonotonic = 2, /**< guarantees that if you take all the
298                                      operations affecting a specific address,
299                                      a consistent ordering exists */
300   LLVMAtomicOrderingAcquire = 4, /**< Acquire provides a barrier of the sort
301                                    necessary to acquire a lock to access other
302                                    memory with normal loads and stores. */
303   LLVMAtomicOrderingRelease = 5, /**< Release is similar to Acquire, but with
304                                    a barrier of the sort necessary to release
305                                    a lock. */
306   LLVMAtomicOrderingAcquireRelease = 6, /**< provides both an Acquire and a
307                                           Release barrier (for fences and
308                                           operations which both read and write
309                                            memory). */
310   LLVMAtomicOrderingSequentiallyConsistent = 7 /**< provides Acquire semantics
311                                                  for loads and Release
312                                                  semantics for stores.
313                                                  Additionally, it guarantees
314                                                  that a total ordering exists
315                                                  between all
316                                                  SequentiallyConsistent
317                                                  operations. */
318 } LLVMAtomicOrdering;
319 
320 typedef enum {
321     LLVMAtomicRMWBinOpXchg, /**< Set the new value and return the one old */
322     LLVMAtomicRMWBinOpAdd, /**< Add a value and return the old one */
323     LLVMAtomicRMWBinOpSub, /**< Subtract a value and return the old one */
324     LLVMAtomicRMWBinOpAnd, /**< And a value and return the old one */
325     LLVMAtomicRMWBinOpNand, /**< Not-And a value and return the old one */
326     LLVMAtomicRMWBinOpOr, /**< OR a value and return the old one */
327     LLVMAtomicRMWBinOpXor, /**< Xor a value and return the old one */
328     LLVMAtomicRMWBinOpMax, /**< Sets the value if it's greater than the
329                              original using a signed comparison and return
330                              the old one */
331     LLVMAtomicRMWBinOpMin, /**< Sets the value if it's Smaller than the
332                              original using a signed comparison and return
333                              the old one */
334     LLVMAtomicRMWBinOpUMax, /**< Sets the value if it's greater than the
335                              original using an unsigned comparison and return
336                              the old one */
337     LLVMAtomicRMWBinOpUMin /**< Sets the value if it's greater than the
338                              original using an unsigned comparison  and return
339                              the old one */
340 } LLVMAtomicRMWBinOp;
341 
342 typedef enum {
343     LLVMDSError,
344     LLVMDSWarning,
345     LLVMDSRemark,
346     LLVMDSNote
347 } LLVMDiagnosticSeverity;
348 
349 /**
350  * @}
351  */
352 
353 void LLVMInitializeCore(LLVMPassRegistryRef R);
354 
355 /** Deallocate and destroy all ManagedStatic variables.
356     @see llvm::llvm_shutdown
357     @see ManagedStatic */
358 void LLVMShutdown(void);
359 
360 /*===-- Error handling ----------------------------------------------------===*/
361 
362 char *LLVMCreateMessage(const char *Message);
363 void LLVMDisposeMessage(char *Message);
364 
365 /**
366  * @defgroup LLVMCCoreContext Contexts
367  *
368  * Contexts are execution states for the core LLVM IR system.
369  *
370  * Most types are tied to a context instance. Multiple contexts can
371  * exist simultaneously. A single context is not thread safe. However,
372  * different contexts can execute on different threads simultaneously.
373  *
374  * @{
375  */
376 
377 typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
378 typedef void (*LLVMYieldCallback)(LLVMContextRef, void *);
379 
380 /**
381  * Create a new context.
382  *
383  * Every call to this function should be paired with a call to
384  * LLVMContextDispose() or the context will leak memory.
385  */
386 LLVMContextRef LLVMContextCreate(void);
387 
388 /**
389  * Obtain the global context instance.
390  */
391 LLVMContextRef LLVMGetGlobalContext(void);
392 
393 /**
394  * Set the diagnostic handler for this context.
395  */
396 void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
397                                      LLVMDiagnosticHandler Handler,
398                                      void *DiagnosticContext);
399 
400 /**
401  * Set the yield callback function for this context.
402  *
403  * @see LLVMContext::setYieldCallback()
404  */
405 void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
406                                  void *OpaqueHandle);
407 
408 /**
409  * Destroy a context instance.
410  *
411  * This should be called for every call to LLVMContextCreate() or memory
412  * will be leaked.
413  */
414 void LLVMContextDispose(LLVMContextRef C);
415 
416 /**
417  * Return a string representation of the DiagnosticInfo. Use
418  * LLVMDisposeMessage to free the string.
419  *
420  * @see DiagnosticInfo::print()
421  */
422 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
423 
424 /**
425  * Return an enum LLVMDiagnosticSeverity.
426  *
427  * @see DiagnosticInfo::getSeverity()
428  */
429 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
430 
431 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
432                                   unsigned SLen);
433 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen);
434 
435 /**
436  * @}
437  */
438 
439 /**
440  * @defgroup LLVMCCoreModule Modules
441  *
442  * Modules represent the top-level structure in an LLVM program. An LLVM
443  * module is effectively a translation unit or a collection of
444  * translation units merged together.
445  *
446  * @{
447  */
448 
449 /**
450  * Create a new, empty module in the global context.
451  *
452  * This is equivalent to calling LLVMModuleCreateWithNameInContext with
453  * LLVMGetGlobalContext() as the context parameter.
454  *
455  * Every invocation should be paired with LLVMDisposeModule() or memory
456  * will be leaked.
457  */
458 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
459 
460 /**
461  * Create a new, empty module in a specific context.
462  *
463  * Every invocation should be paired with LLVMDisposeModule() or memory
464  * will be leaked.
465  */
466 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
467                                                 LLVMContextRef C);
468 /**
469  * Return an exact copy of the specified module.
470  */
471 LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
472 
473 /**
474  * Destroy a module instance.
475  *
476  * This must be called for every created module or memory will be
477  * leaked.
478  */
479 void LLVMDisposeModule(LLVMModuleRef M);
480 
481 /**
482  * Obtain the data layout for a module.
483  *
484  * @see Module::getDataLayoutStr()
485  *
486  * LLVMGetDataLayout is DEPRECATED, as the name is not only incorrect,
487  * but match the name of another method on the module. Prefer the use
488  * of LLVMGetDataLayoutStr, which is not ambiguous.
489  */
490 const char *LLVMGetDataLayoutStr(LLVMModuleRef M);
491 const char *LLVMGetDataLayout(LLVMModuleRef M);
492 
493 /**
494  * Set the data layout for a module.
495  *
496  * @see Module::setDataLayout()
497  */
498 void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr);
499 
500 /**
501  * Obtain the target triple for a module.
502  *
503  * @see Module::getTargetTriple()
504  */
505 const char *LLVMGetTarget(LLVMModuleRef M);
506 
507 /**
508  * Set the target triple for a module.
509  *
510  * @see Module::setTargetTriple()
511  */
512 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
513 
514 /**
515  * Dump a representation of a module to stderr.
516  *
517  * @see Module::dump()
518  */
519 void LLVMDumpModule(LLVMModuleRef M);
520 
521 /**
522  * Print a representation of a module to a file. The ErrorMessage needs to be
523  * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
524  *
525  * @see Module::print()
526  */
527 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
528                                char **ErrorMessage);
529 
530 /**
531  * Return a string representation of the module. Use
532  * LLVMDisposeMessage to free the string.
533  *
534  * @see Module::print()
535  */
536 char *LLVMPrintModuleToString(LLVMModuleRef M);
537 
538 /**
539  * Set inline assembly for a module.
540  *
541  * @see Module::setModuleInlineAsm()
542  */
543 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
544 
545 /**
546  * Obtain the context to which this module is associated.
547  *
548  * @see Module::getContext()
549  */
550 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
551 
552 /**
553  * Obtain a Type from a module by its registered name.
554  */
555 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
556 
557 /**
558  * Obtain the number of operands for named metadata in a module.
559  *
560  * @see llvm::Module::getNamedMetadata()
561  */
562 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
563 
564 /**
565  * Obtain the named metadata operands for a module.
566  *
567  * The passed LLVMValueRef pointer should refer to an array of
568  * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
569  * array will be populated with the LLVMValueRef instances. Each
570  * instance corresponds to a llvm::MDNode.
571  *
572  * @see llvm::Module::getNamedMetadata()
573  * @see llvm::MDNode::getOperand()
574  */
575 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
576 
577 /**
578  * Add an operand to named metadata.
579  *
580  * @see llvm::Module::getNamedMetadata()
581  * @see llvm::MDNode::addOperand()
582  */
583 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
584                                  LLVMValueRef Val);
585 
586 /**
587  * Add a function to a module under a specified name.
588  *
589  * @see llvm::Function::Create()
590  */
591 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
592                              LLVMTypeRef FunctionTy);
593 
594 /**
595  * Obtain a Function value from a Module by its name.
596  *
597  * The returned value corresponds to a llvm::Function value.
598  *
599  * @see llvm::Module::getFunction()
600  */
601 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
602 
603 /**
604  * Obtain an iterator to the first Function in a Module.
605  *
606  * @see llvm::Module::begin()
607  */
608 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
609 
610 /**
611  * Obtain an iterator to the last Function in a Module.
612  *
613  * @see llvm::Module::end()
614  */
615 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
616 
617 /**
618  * Advance a Function iterator to the next Function.
619  *
620  * Returns NULL if the iterator was already at the end and there are no more
621  * functions.
622  */
623 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
624 
625 /**
626  * Decrement a Function iterator to the previous Function.
627  *
628  * Returns NULL if the iterator was already at the beginning and there are
629  * no previous functions.
630  */
631 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
632 
633 /**
634  * @}
635  */
636 
637 /**
638  * @defgroup LLVMCCoreType Types
639  *
640  * Types represent the type of a value.
641  *
642  * Types are associated with a context instance. The context internally
643  * deduplicates types so there is only 1 instance of a specific type
644  * alive at a time. In other words, a unique type is shared among all
645  * consumers within a context.
646  *
647  * A Type in the C API corresponds to llvm::Type.
648  *
649  * Types have the following hierarchy:
650  *
651  *   types:
652  *     integer type
653  *     real type
654  *     function type
655  *     sequence types:
656  *       array type
657  *       pointer type
658  *       vector type
659  *     void type
660  *     label type
661  *     opaque type
662  *
663  * @{
664  */
665 
666 /**
667  * Obtain the enumerated type of a Type instance.
668  *
669  * @see llvm::Type:getTypeID()
670  */
671 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
672 
673 /**
674  * Whether the type has a known size.
675  *
676  * Things that don't have a size are abstract types, labels, and void.a
677  *
678  * @see llvm::Type::isSized()
679  */
680 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
681 
682 /**
683  * Obtain the context to which this type instance is associated.
684  *
685  * @see llvm::Type::getContext()
686  */
687 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
688 
689 /**
690  * Dump a representation of a type to stderr.
691  *
692  * @see llvm::Type::dump()
693  */
694 void LLVMDumpType(LLVMTypeRef Val);
695 
696 /**
697  * Return a string representation of the type. Use
698  * LLVMDisposeMessage to free the string.
699  *
700  * @see llvm::Type::print()
701  */
702 char *LLVMPrintTypeToString(LLVMTypeRef Val);
703 
704 /**
705  * @defgroup LLVMCCoreTypeInt Integer Types
706  *
707  * Functions in this section operate on integer types.
708  *
709  * @{
710  */
711 
712 /**
713  * Obtain an integer type from a context with specified bit width.
714  */
715 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
716 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
717 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
718 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
719 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
720 LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
721 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
722 
723 /**
724  * Obtain an integer type from the global context with a specified bit
725  * width.
726  */
727 LLVMTypeRef LLVMInt1Type(void);
728 LLVMTypeRef LLVMInt8Type(void);
729 LLVMTypeRef LLVMInt16Type(void);
730 LLVMTypeRef LLVMInt32Type(void);
731 LLVMTypeRef LLVMInt64Type(void);
732 LLVMTypeRef LLVMInt128Type(void);
733 LLVMTypeRef LLVMIntType(unsigned NumBits);
734 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
735 
736 /**
737  * @}
738  */
739 
740 /**
741  * @defgroup LLVMCCoreTypeFloat Floating Point Types
742  *
743  * @{
744  */
745 
746 /**
747  * Obtain a 16-bit floating point type from a context.
748  */
749 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
750 
751 /**
752  * Obtain a 32-bit floating point type from a context.
753  */
754 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
755 
756 /**
757  * Obtain a 64-bit floating point type from a context.
758  */
759 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
760 
761 /**
762  * Obtain a 80-bit floating point type (X87) from a context.
763  */
764 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
765 
766 /**
767  * Obtain a 128-bit floating point type (112-bit mantissa) from a
768  * context.
769  */
770 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
771 
772 /**
773  * Obtain a 128-bit floating point type (two 64-bits) from a context.
774  */
775 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
776 
777 /**
778  * Obtain a floating point type from the global context.
779  *
780  * These map to the functions in this group of the same name.
781  */
782 LLVMTypeRef LLVMHalfType(void);
783 LLVMTypeRef LLVMFloatType(void);
784 LLVMTypeRef LLVMDoubleType(void);
785 LLVMTypeRef LLVMX86FP80Type(void);
786 LLVMTypeRef LLVMFP128Type(void);
787 LLVMTypeRef LLVMPPCFP128Type(void);
788 
789 /**
790  * @}
791  */
792 
793 /**
794  * @defgroup LLVMCCoreTypeFunction Function Types
795  *
796  * @{
797  */
798 
799 /**
800  * Obtain a function type consisting of a specified signature.
801  *
802  * The function is defined as a tuple of a return Type, a list of
803  * parameter types, and whether the function is variadic.
804  */
805 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
806                              LLVMTypeRef *ParamTypes, unsigned ParamCount,
807                              LLVMBool IsVarArg);
808 
809 /**
810  * Returns whether a function type is variadic.
811  */
812 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
813 
814 /**
815  * Obtain the Type this function Type returns.
816  */
817 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
818 
819 /**
820  * Obtain the number of parameters this function accepts.
821  */
822 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
823 
824 /**
825  * Obtain the types of a function's parameters.
826  *
827  * The Dest parameter should point to a pre-allocated array of
828  * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
829  * first LLVMCountParamTypes() entries in the array will be populated
830  * with LLVMTypeRef instances.
831  *
832  * @param FunctionTy The function type to operate on.
833  * @param Dest Memory address of an array to be filled with result.
834  */
835 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
836 
837 /**
838  * @}
839  */
840 
841 /**
842  * @defgroup LLVMCCoreTypeStruct Structure Types
843  *
844  * These functions relate to LLVMTypeRef instances.
845  *
846  * @see llvm::StructType
847  *
848  * @{
849  */
850 
851 /**
852  * Create a new structure type in a context.
853  *
854  * A structure is specified by a list of inner elements/types and
855  * whether these can be packed together.
856  *
857  * @see llvm::StructType::create()
858  */
859 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
860                                     unsigned ElementCount, LLVMBool Packed);
861 
862 /**
863  * Create a new structure type in the global context.
864  *
865  * @see llvm::StructType::create()
866  */
867 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
868                            LLVMBool Packed);
869 
870 /**
871  * Create an empty structure in a context having a specified name.
872  *
873  * @see llvm::StructType::create()
874  */
875 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
876 
877 /**
878  * Obtain the name of a structure.
879  *
880  * @see llvm::StructType::getName()
881  */
882 const char *LLVMGetStructName(LLVMTypeRef Ty);
883 
884 /**
885  * Set the contents of a structure type.
886  *
887  * @see llvm::StructType::setBody()
888  */
889 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
890                        unsigned ElementCount, LLVMBool Packed);
891 
892 /**
893  * Get the number of elements defined inside the structure.
894  *
895  * @see llvm::StructType::getNumElements()
896  */
897 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
898 
899 /**
900  * Get the elements within a structure.
901  *
902  * The function is passed the address of a pre-allocated array of
903  * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
904  * invocation, this array will be populated with the structure's
905  * elements. The objects in the destination array will have a lifetime
906  * of the structure type itself, which is the lifetime of the context it
907  * is contained in.
908  */
909 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
910 
911 /**
912  * Get the type of the element at a given index in the structure.
913  *
914  * @see llvm::StructType::getTypeAtIndex()
915  */
916 LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
917 
918 /**
919  * Determine whether a structure is packed.
920  *
921  * @see llvm::StructType::isPacked()
922  */
923 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
924 
925 /**
926  * Determine whether a structure is opaque.
927  *
928  * @see llvm::StructType::isOpaque()
929  */
930 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
931 
932 /**
933  * @}
934  */
935 
936 /**
937  * @defgroup LLVMCCoreTypeSequential Sequential Types
938  *
939  * Sequential types represents "arrays" of types. This is a super class
940  * for array, vector, and pointer types.
941  *
942  * @{
943  */
944 
945 /**
946  * Obtain the type of elements within a sequential type.
947  *
948  * This works on array, vector, and pointer types.
949  *
950  * @see llvm::SequentialType::getElementType()
951  */
952 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
953 
954 /**
955  * Create a fixed size array type that refers to a specific type.
956  *
957  * The created type will exist in the context that its element type
958  * exists in.
959  *
960  * @see llvm::ArrayType::get()
961  */
962 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
963 
964 /**
965  * Obtain the length of an array type.
966  *
967  * This only works on types that represent arrays.
968  *
969  * @see llvm::ArrayType::getNumElements()
970  */
971 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
972 
973 /**
974  * Create a pointer type that points to a defined type.
975  *
976  * The created type will exist in the context that its pointee type
977  * exists in.
978  *
979  * @see llvm::PointerType::get()
980  */
981 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
982 
983 /**
984  * Obtain the address space of a pointer type.
985  *
986  * This only works on types that represent pointers.
987  *
988  * @see llvm::PointerType::getAddressSpace()
989  */
990 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
991 
992 /**
993  * Create a vector type that contains a defined type and has a specific
994  * number of elements.
995  *
996  * The created type will exist in the context thats its element type
997  * exists in.
998  *
999  * @see llvm::VectorType::get()
1000  */
1001 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
1002 
1003 /**
1004  * Obtain the number of elements in a vector type.
1005  *
1006  * This only works on types that represent vectors.
1007  *
1008  * @see llvm::VectorType::getNumElements()
1009  */
1010 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1011 
1012 /**
1013  * @}
1014  */
1015 
1016 /**
1017  * @defgroup LLVMCCoreTypeOther Other Types
1018  *
1019  * @{
1020  */
1021 
1022 /**
1023  * Create a void type in a context.
1024  */
1025 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
1026 
1027 /**
1028  * Create a label type in a context.
1029  */
1030 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
1031 
1032 /**
1033  * Create a X86 MMX type in a context.
1034  */
1035 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
1036 
1037 /**
1038  * These are similar to the above functions except they operate on the
1039  * global context.
1040  */
1041 LLVMTypeRef LLVMVoidType(void);
1042 LLVMTypeRef LLVMLabelType(void);
1043 LLVMTypeRef LLVMX86MMXType(void);
1044 
1045 /**
1046  * @}
1047  */
1048 
1049 /**
1050  * @}
1051  */
1052 
1053 /**
1054  * @defgroup LLVMCCoreValues Values
1055  *
1056  * The bulk of LLVM's object model consists of values, which comprise a very
1057  * rich type hierarchy.
1058  *
1059  * LLVMValueRef essentially represents llvm::Value. There is a rich
1060  * hierarchy of classes within this type. Depending on the instance
1061  * obtained, not all APIs are available.
1062  *
1063  * Callers can determine the type of an LLVMValueRef by calling the
1064  * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1065  * functions are defined by a macro, so it isn't obvious which are
1066  * available by looking at the Doxygen source code. Instead, look at the
1067  * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1068  * of value names given. These value names also correspond to classes in
1069  * the llvm::Value hierarchy.
1070  *
1071  * @{
1072  */
1073 
1074 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1075   macro(Argument)                           \
1076   macro(BasicBlock)                         \
1077   macro(InlineAsm)                          \
1078   macro(User)                               \
1079     macro(Constant)                         \
1080       macro(BlockAddress)                   \
1081       macro(ConstantAggregateZero)          \
1082       macro(ConstantArray)                  \
1083       macro(ConstantDataSequential)         \
1084         macro(ConstantDataArray)            \
1085         macro(ConstantDataVector)           \
1086       macro(ConstantExpr)                   \
1087       macro(ConstantFP)                     \
1088       macro(ConstantInt)                    \
1089       macro(ConstantPointerNull)            \
1090       macro(ConstantStruct)                 \
1091       macro(ConstantTokenNone)              \
1092       macro(ConstantVector)                 \
1093       macro(GlobalValue)                    \
1094         macro(GlobalAlias)                  \
1095         macro(GlobalObject)                 \
1096           macro(Function)                   \
1097           macro(GlobalVariable)             \
1098       macro(UndefValue)                     \
1099     macro(Instruction)                      \
1100       macro(BinaryOperator)                 \
1101       macro(CallInst)                       \
1102         macro(IntrinsicInst)                \
1103           macro(DbgInfoIntrinsic)           \
1104             macro(DbgDeclareInst)           \
1105           macro(MemIntrinsic)               \
1106             macro(MemCpyInst)               \
1107             macro(MemMoveInst)              \
1108             macro(MemSetInst)               \
1109       macro(CmpInst)                        \
1110         macro(FCmpInst)                     \
1111         macro(ICmpInst)                     \
1112       macro(ExtractElementInst)             \
1113       macro(GetElementPtrInst)              \
1114       macro(InsertElementInst)              \
1115       macro(InsertValueInst)                \
1116       macro(LandingPadInst)                 \
1117       macro(PHINode)                        \
1118       macro(SelectInst)                     \
1119       macro(ShuffleVectorInst)              \
1120       macro(StoreInst)                      \
1121       macro(TerminatorInst)                 \
1122         macro(BranchInst)                   \
1123         macro(IndirectBrInst)               \
1124         macro(InvokeInst)                   \
1125         macro(ReturnInst)                   \
1126         macro(SwitchInst)                   \
1127         macro(UnreachableInst)              \
1128         macro(ResumeInst)                   \
1129         macro(CleanupReturnInst)            \
1130         macro(CatchReturnInst)              \
1131       macro(FuncletPadInst)                 \
1132         macro(CatchPadInst)                 \
1133         macro(CleanupPadInst)               \
1134       macro(UnaryInstruction)               \
1135         macro(AllocaInst)                   \
1136         macro(CastInst)                     \
1137           macro(AddrSpaceCastInst)          \
1138           macro(BitCastInst)                \
1139           macro(FPExtInst)                  \
1140           macro(FPToSIInst)                 \
1141           macro(FPToUIInst)                 \
1142           macro(FPTruncInst)                \
1143           macro(IntToPtrInst)               \
1144           macro(PtrToIntInst)               \
1145           macro(SExtInst)                   \
1146           macro(SIToFPInst)                 \
1147           macro(TruncInst)                  \
1148           macro(UIToFPInst)                 \
1149           macro(ZExtInst)                   \
1150         macro(ExtractValueInst)             \
1151         macro(LoadInst)                     \
1152         macro(VAArgInst)
1153 
1154 /**
1155  * @defgroup LLVMCCoreValueGeneral General APIs
1156  *
1157  * Functions in this section work on all LLVMValueRef instances,
1158  * regardless of their sub-type. They correspond to functions available
1159  * on llvm::Value.
1160  *
1161  * @{
1162  */
1163 
1164 /**
1165  * Obtain the type of a value.
1166  *
1167  * @see llvm::Value::getType()
1168  */
1169 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1170 
1171 /**
1172  * Obtain the string name of a value.
1173  *
1174  * @see llvm::Value::getName()
1175  */
1176 const char *LLVMGetValueName(LLVMValueRef Val);
1177 
1178 /**
1179  * Set the string name of a value.
1180  *
1181  * @see llvm::Value::setName()
1182  */
1183 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1184 
1185 /**
1186  * Dump a representation of a value to stderr.
1187  *
1188  * @see llvm::Value::dump()
1189  */
1190 void LLVMDumpValue(LLVMValueRef Val);
1191 
1192 /**
1193  * Return a string representation of the value. Use
1194  * LLVMDisposeMessage to free the string.
1195  *
1196  * @see llvm::Value::print()
1197  */
1198 char *LLVMPrintValueToString(LLVMValueRef Val);
1199 
1200 /**
1201  * Replace all uses of a value with another one.
1202  *
1203  * @see llvm::Value::replaceAllUsesWith()
1204  */
1205 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1206 
1207 /**
1208  * Determine whether the specified value instance is constant.
1209  */
1210 LLVMBool LLVMIsConstant(LLVMValueRef Val);
1211 
1212 /**
1213  * Determine whether a value instance is undefined.
1214  */
1215 LLVMBool LLVMIsUndef(LLVMValueRef Val);
1216 
1217 /**
1218  * Convert value instances between types.
1219  *
1220  * Internally, an LLVMValueRef is "pinned" to a specific type. This
1221  * series of functions allows you to cast an instance to a specific
1222  * type.
1223  *
1224  * If the cast is not valid for the specified type, NULL is returned.
1225  *
1226  * @see llvm::dyn_cast_or_null<>
1227  */
1228 #define LLVM_DECLARE_VALUE_CAST(name) \
1229   LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1230 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1231 
1232 LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1233 LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1234 
1235 /**
1236  * @}
1237  */
1238 
1239 /**
1240  * @defgroup LLVMCCoreValueUses Usage
1241  *
1242  * This module defines functions that allow you to inspect the uses of a
1243  * LLVMValueRef.
1244  *
1245  * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
1246  * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1247  * llvm::User and llvm::Value.
1248  *
1249  * @{
1250  */
1251 
1252 /**
1253  * Obtain the first use of a value.
1254  *
1255  * Uses are obtained in an iterator fashion. First, call this function
1256  * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1257  * on that instance and all subsequently obtained instances until
1258  * LLVMGetNextUse() returns NULL.
1259  *
1260  * @see llvm::Value::use_begin()
1261  */
1262 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1263 
1264 /**
1265  * Obtain the next use of a value.
1266  *
1267  * This effectively advances the iterator. It returns NULL if you are on
1268  * the final use and no more are available.
1269  */
1270 LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1271 
1272 /**
1273  * Obtain the user value for a user.
1274  *
1275  * The returned value corresponds to a llvm::User type.
1276  *
1277  * @see llvm::Use::getUser()
1278  */
1279 LLVMValueRef LLVMGetUser(LLVMUseRef U);
1280 
1281 /**
1282  * Obtain the value this use corresponds to.
1283  *
1284  * @see llvm::Use::get().
1285  */
1286 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1287 
1288 /**
1289  * @}
1290  */
1291 
1292 /**
1293  * @defgroup LLVMCCoreValueUser User value
1294  *
1295  * Function in this group pertain to LLVMValueRef instances that descent
1296  * from llvm::User. This includes constants, instructions, and
1297  * operators.
1298  *
1299  * @{
1300  */
1301 
1302 /**
1303  * Obtain an operand at a specific index in a llvm::User value.
1304  *
1305  * @see llvm::User::getOperand()
1306  */
1307 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1308 
1309 /**
1310  * Obtain the use of an operand at a specific index in a llvm::User value.
1311  *
1312  * @see llvm::User::getOperandUse()
1313  */
1314 LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1315 
1316 /**
1317  * Set an operand at a specific index in a llvm::User value.
1318  *
1319  * @see llvm::User::setOperand()
1320  */
1321 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1322 
1323 /**
1324  * Obtain the number of operands in a llvm::User value.
1325  *
1326  * @see llvm::User::getNumOperands()
1327  */
1328 int LLVMGetNumOperands(LLVMValueRef Val);
1329 
1330 /**
1331  * @}
1332  */
1333 
1334 /**
1335  * @defgroup LLVMCCoreValueConstant Constants
1336  *
1337  * This section contains APIs for interacting with LLVMValueRef that
1338  * correspond to llvm::Constant instances.
1339  *
1340  * These functions will work for any LLVMValueRef in the llvm::Constant
1341  * class hierarchy.
1342  *
1343  * @{
1344  */
1345 
1346 /**
1347  * Obtain a constant value referring to the null instance of a type.
1348  *
1349  * @see llvm::Constant::getNullValue()
1350  */
1351 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1352 
1353 /**
1354  * Obtain a constant value referring to the instance of a type
1355  * consisting of all ones.
1356  *
1357  * This is only valid for integer types.
1358  *
1359  * @see llvm::Constant::getAllOnesValue()
1360  */
1361 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1362 
1363 /**
1364  * Obtain a constant value referring to an undefined value of a type.
1365  *
1366  * @see llvm::UndefValue::get()
1367  */
1368 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1369 
1370 /**
1371  * Determine whether a value instance is null.
1372  *
1373  * @see llvm::Constant::isNullValue()
1374  */
1375 LLVMBool LLVMIsNull(LLVMValueRef Val);
1376 
1377 /**
1378  * Obtain a constant that is a constant pointer pointing to NULL for a
1379  * specified type.
1380  */
1381 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1382 
1383 /**
1384  * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1385  *
1386  * Functions in this group model LLVMValueRef instances that correspond
1387  * to constants referring to scalar types.
1388  *
1389  * For integer types, the LLVMTypeRef parameter should correspond to a
1390  * llvm::IntegerType instance and the returned LLVMValueRef will
1391  * correspond to a llvm::ConstantInt.
1392  *
1393  * For floating point types, the LLVMTypeRef returned corresponds to a
1394  * llvm::ConstantFP.
1395  *
1396  * @{
1397  */
1398 
1399 /**
1400  * Obtain a constant value for an integer type.
1401  *
1402  * The returned value corresponds to a llvm::ConstantInt.
1403  *
1404  * @see llvm::ConstantInt::get()
1405  *
1406  * @param IntTy Integer type to obtain value of.
1407  * @param N The value the returned instance should refer to.
1408  * @param SignExtend Whether to sign extend the produced value.
1409  */
1410 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1411                           LLVMBool SignExtend);
1412 
1413 /**
1414  * Obtain a constant value for an integer of arbitrary precision.
1415  *
1416  * @see llvm::ConstantInt::get()
1417  */
1418 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1419                                               unsigned NumWords,
1420                                               const uint64_t Words[]);
1421 
1422 /**
1423  * Obtain a constant value for an integer parsed from a string.
1424  *
1425  * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1426  * string's length is available, it is preferred to call that function
1427  * instead.
1428  *
1429  * @see llvm::ConstantInt::get()
1430  */
1431 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1432                                   uint8_t Radix);
1433 
1434 /**
1435  * Obtain a constant value for an integer parsed from a string with
1436  * specified length.
1437  *
1438  * @see llvm::ConstantInt::get()
1439  */
1440 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1441                                          unsigned SLen, uint8_t Radix);
1442 
1443 /**
1444  * Obtain a constant value referring to a double floating point value.
1445  */
1446 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1447 
1448 /**
1449  * Obtain a constant for a floating point value parsed from a string.
1450  *
1451  * A similar API, LLVMConstRealOfStringAndSize is also available. It
1452  * should be used if the input string's length is known.
1453  */
1454 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1455 
1456 /**
1457  * Obtain a constant for a floating point value parsed from a string.
1458  */
1459 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1460                                           unsigned SLen);
1461 
1462 /**
1463  * Obtain the zero extended value for an integer constant value.
1464  *
1465  * @see llvm::ConstantInt::getZExtValue()
1466  */
1467 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1468 
1469 /**
1470  * Obtain the sign extended value for an integer constant value.
1471  *
1472  * @see llvm::ConstantInt::getSExtValue()
1473  */
1474 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1475 
1476 /**
1477  * Obtain the double value for an floating point constant value.
1478  * losesInfo indicates if some precision was lost in the conversion.
1479  *
1480  * @see llvm::ConstantFP::getDoubleValue
1481  */
1482 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1483 
1484 /**
1485  * @}
1486  */
1487 
1488 /**
1489  * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1490  *
1491  * Functions in this group operate on composite constants.
1492  *
1493  * @{
1494  */
1495 
1496 /**
1497  * Create a ConstantDataSequential and initialize it with a string.
1498  *
1499  * @see llvm::ConstantDataArray::getString()
1500  */
1501 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1502                                       unsigned Length, LLVMBool DontNullTerminate);
1503 
1504 /**
1505  * Create a ConstantDataSequential with string content in the global context.
1506  *
1507  * This is the same as LLVMConstStringInContext except it operates on the
1508  * global context.
1509  *
1510  * @see LLVMConstStringInContext()
1511  * @see llvm::ConstantDataArray::getString()
1512  */
1513 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1514                              LLVMBool DontNullTerminate);
1515 
1516 /**
1517  * Returns true if the specified constant is an array of i8.
1518  *
1519  * @see ConstantDataSequential::getAsString()
1520  */
1521 LLVMBool LLVMIsConstantString(LLVMValueRef c);
1522 
1523 /**
1524  * Get the given constant data sequential as a string.
1525  *
1526  * @see ConstantDataSequential::getAsString()
1527  */
1528 const char *LLVMGetAsString(LLVMValueRef c, size_t* out);
1529 
1530 /**
1531  * Create an anonymous ConstantStruct with the specified values.
1532  *
1533  * @see llvm::ConstantStruct::getAnon()
1534  */
1535 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1536                                       LLVMValueRef *ConstantVals,
1537                                       unsigned Count, LLVMBool Packed);
1538 
1539 /**
1540  * Create a ConstantStruct in the global Context.
1541  *
1542  * This is the same as LLVMConstStructInContext except it operates on the
1543  * global Context.
1544  *
1545  * @see LLVMConstStructInContext()
1546  */
1547 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1548                              LLVMBool Packed);
1549 
1550 /**
1551  * Create a ConstantArray from values.
1552  *
1553  * @see llvm::ConstantArray::get()
1554  */
1555 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1556                             LLVMValueRef *ConstantVals, unsigned Length);
1557 
1558 /**
1559  * Create a non-anonymous ConstantStruct from values.
1560  *
1561  * @see llvm::ConstantStruct::get()
1562  */
1563 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1564                                   LLVMValueRef *ConstantVals,
1565                                   unsigned Count);
1566 
1567 /**
1568  * Get an element at specified index as a constant.
1569  *
1570  * @see ConstantDataSequential::getElementAsConstant()
1571  */
1572 LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx);
1573 
1574 /**
1575  * Create a ConstantVector from values.
1576  *
1577  * @see llvm::ConstantVector::get()
1578  */
1579 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1580 
1581 /**
1582  * @}
1583  */
1584 
1585 /**
1586  * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1587  *
1588  * Functions in this group correspond to APIs on llvm::ConstantExpr.
1589  *
1590  * @see llvm::ConstantExpr.
1591  *
1592  * @{
1593  */
1594 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1595 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1596 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1597 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1598 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1599 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1600 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1601 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1602 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1603 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1604 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1605 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1606 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1607 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1608 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1609 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1610 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1611 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1612 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1613 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1614 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1615 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1616 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1617 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1618 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1619 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1620 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1621 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1622 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1623 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1624 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1625                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1626 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1627                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1628 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1629 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1630 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1631 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1632                           LLVMValueRef *ConstantIndices, unsigned NumIndices);
1633 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1634                                   LLVMValueRef *ConstantIndices,
1635                                   unsigned NumIndices);
1636 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1637 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1638 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1639 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1640 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1641 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1642 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1643 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1644 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1645 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1646 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1647 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1648 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1649 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1650                                     LLVMTypeRef ToType);
1651 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1652                                     LLVMTypeRef ToType);
1653 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1654                                      LLVMTypeRef ToType);
1655 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1656                                   LLVMTypeRef ToType);
1657 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1658                               LLVMBool isSigned);
1659 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1660 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1661                              LLVMValueRef ConstantIfTrue,
1662                              LLVMValueRef ConstantIfFalse);
1663 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1664                                      LLVMValueRef IndexConstant);
1665 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1666                                     LLVMValueRef ElementValueConstant,
1667                                     LLVMValueRef IndexConstant);
1668 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1669                                     LLVMValueRef VectorBConstant,
1670                                     LLVMValueRef MaskConstant);
1671 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1672                                    unsigned NumIdx);
1673 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1674                                   LLVMValueRef ElementValueConstant,
1675                                   unsigned *IdxList, unsigned NumIdx);
1676 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1677                                 const char *AsmString, const char *Constraints,
1678                                 LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1679 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1680 
1681 /**
1682  * @}
1683  */
1684 
1685 /**
1686  * @defgroup LLVMCCoreValueConstantGlobals Global Values
1687  *
1688  * This group contains functions that operate on global values. Functions in
1689  * this group relate to functions in the llvm::GlobalValue class tree.
1690  *
1691  * @see llvm::GlobalValue
1692  *
1693  * @{
1694  */
1695 
1696 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1697 LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1698 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1699 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1700 const char *LLVMGetSection(LLVMValueRef Global);
1701 void LLVMSetSection(LLVMValueRef Global, const char *Section);
1702 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1703 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1704 LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1705 void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
1706 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1707 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
1708 
1709 /**
1710  * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1711  *
1712  * Functions in this group only apply to values with alignment, i.e.
1713  * global variables, load and store instructions.
1714  */
1715 
1716 /**
1717  * Obtain the preferred alignment of the value.
1718  * @see llvm::AllocaInst::getAlignment()
1719  * @see llvm::LoadInst::getAlignment()
1720  * @see llvm::StoreInst::getAlignment()
1721  * @see llvm::GlobalValue::getAlignment()
1722  */
1723 unsigned LLVMGetAlignment(LLVMValueRef V);
1724 
1725 /**
1726  * Set the preferred alignment of the value.
1727  * @see llvm::AllocaInst::setAlignment()
1728  * @see llvm::LoadInst::setAlignment()
1729  * @see llvm::StoreInst::setAlignment()
1730  * @see llvm::GlobalValue::setAlignment()
1731  */
1732 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1733 
1734 /**
1735  * @}
1736  */
1737 
1738 /**
1739  * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1740  *
1741  * This group contains functions that operate on global variable values.
1742  *
1743  * @see llvm::GlobalVariable
1744  *
1745  * @{
1746  */
1747 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1748 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1749                                          const char *Name,
1750                                          unsigned AddressSpace);
1751 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1752 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1753 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1754 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1755 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1756 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1757 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1758 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1759 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1760 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1761 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1762 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1763 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1764 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1765 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1766 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
1767 
1768 /**
1769  * @}
1770  */
1771 
1772 /**
1773  * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1774  *
1775  * This group contains function that operate on global alias values.
1776  *
1777  * @see llvm::GlobalAlias
1778  *
1779  * @{
1780  */
1781 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1782                           const char *Name);
1783 
1784 /**
1785  * @}
1786  */
1787 
1788 /**
1789  * @defgroup LLVMCCoreValueFunction Function values
1790  *
1791  * Functions in this group operate on LLVMValueRef instances that
1792  * correspond to llvm::Function instances.
1793  *
1794  * @see llvm::Function
1795  *
1796  * @{
1797  */
1798 
1799 /**
1800  * Remove a function from its containing module and deletes it.
1801  *
1802  * @see llvm::Function::eraseFromParent()
1803  */
1804 void LLVMDeleteFunction(LLVMValueRef Fn);
1805 
1806 /**
1807  * Check whether the given function has a personality function.
1808  *
1809  * @see llvm::Function::hasPersonalityFn()
1810  */
1811 LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn);
1812 
1813 /**
1814  * Obtain the personality function attached to the function.
1815  *
1816  * @see llvm::Function::getPersonalityFn()
1817  */
1818 LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
1819 
1820 /**
1821  * Set the personality function attached to the function.
1822  *
1823  * @see llvm::Function::setPersonalityFn()
1824  */
1825 void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
1826 
1827 /**
1828  * Obtain the ID number from a function instance.
1829  *
1830  * @see llvm::Function::getIntrinsicID()
1831  */
1832 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1833 
1834 /**
1835  * Obtain the calling function of a function.
1836  *
1837  * The returned value corresponds to the LLVMCallConv enumeration.
1838  *
1839  * @see llvm::Function::getCallingConv()
1840  */
1841 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1842 
1843 /**
1844  * Set the calling convention of a function.
1845  *
1846  * @see llvm::Function::setCallingConv()
1847  *
1848  * @param Fn Function to operate on
1849  * @param CC LLVMCallConv to set calling convention to
1850  */
1851 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1852 
1853 /**
1854  * Obtain the name of the garbage collector to use during code
1855  * generation.
1856  *
1857  * @see llvm::Function::getGC()
1858  */
1859 const char *LLVMGetGC(LLVMValueRef Fn);
1860 
1861 /**
1862  * Define the garbage collector to use during code generation.
1863  *
1864  * @see llvm::Function::setGC()
1865  */
1866 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1867 
1868 /**
1869  * Add an attribute to a function.
1870  *
1871  * @see llvm::Function::addAttribute()
1872  */
1873 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1874 
1875 /**
1876  * Add a target-dependent attribute to a function
1877  * @see llvm::AttrBuilder::addAttribute()
1878  */
1879 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1880                                         const char *V);
1881 
1882 /**
1883  * Obtain an attribute from a function.
1884  *
1885  * @see llvm::Function::getAttributes()
1886  */
1887 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1888 
1889 /**
1890  * Remove an attribute from a function.
1891  */
1892 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1893 
1894 /**
1895  * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1896  *
1897  * Functions in this group relate to arguments/parameters on functions.
1898  *
1899  * Functions in this group expect LLVMValueRef instances that correspond
1900  * to llvm::Function instances.
1901  *
1902  * @{
1903  */
1904 
1905 /**
1906  * Obtain the number of parameters in a function.
1907  *
1908  * @see llvm::Function::arg_size()
1909  */
1910 unsigned LLVMCountParams(LLVMValueRef Fn);
1911 
1912 /**
1913  * Obtain the parameters in a function.
1914  *
1915  * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1916  * at least LLVMCountParams() long. This array will be filled with
1917  * LLVMValueRef instances which correspond to the parameters the
1918  * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1919  * instance.
1920  *
1921  * @see llvm::Function::arg_begin()
1922  */
1923 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1924 
1925 /**
1926  * Obtain the parameter at the specified index.
1927  *
1928  * Parameters are indexed from 0.
1929  *
1930  * @see llvm::Function::arg_begin()
1931  */
1932 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1933 
1934 /**
1935  * Obtain the function to which this argument belongs.
1936  *
1937  * Unlike other functions in this group, this one takes an LLVMValueRef
1938  * that corresponds to a llvm::Attribute.
1939  *
1940  * The returned LLVMValueRef is the llvm::Function to which this
1941  * argument belongs.
1942  */
1943 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1944 
1945 /**
1946  * Obtain the first parameter to a function.
1947  *
1948  * @see llvm::Function::arg_begin()
1949  */
1950 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1951 
1952 /**
1953  * Obtain the last parameter to a function.
1954  *
1955  * @see llvm::Function::arg_end()
1956  */
1957 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1958 
1959 /**
1960  * Obtain the next parameter to a function.
1961  *
1962  * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
1963  * actually a wrapped iterator) and obtains the next parameter from the
1964  * underlying iterator.
1965  */
1966 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1967 
1968 /**
1969  * Obtain the previous parameter to a function.
1970  *
1971  * This is the opposite of LLVMGetNextParam().
1972  */
1973 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1974 
1975 /**
1976  * Add an attribute to a function argument.
1977  *
1978  * @see llvm::Argument::addAttr()
1979  */
1980 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1981 
1982 /**
1983  * Remove an attribute from a function argument.
1984  *
1985  * @see llvm::Argument::removeAttr()
1986  */
1987 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1988 
1989 /**
1990  * Get an attribute from a function argument.
1991  */
1992 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1993 
1994 /**
1995  * Set the alignment for a function parameter.
1996  *
1997  * @see llvm::Argument::addAttr()
1998  * @see llvm::AttrBuilder::addAlignmentAttr()
1999  */
2000 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
2001 
2002 /**
2003  * @}
2004  */
2005 
2006 /**
2007  * @}
2008  */
2009 
2010 /**
2011  * @}
2012  */
2013 
2014 /**
2015  * @}
2016  */
2017 
2018 /**
2019  * @defgroup LLVMCCoreValueMetadata Metadata
2020  *
2021  * @{
2022  */
2023 
2024 /**
2025  * Obtain a MDString value from a context.
2026  *
2027  * The returned instance corresponds to the llvm::MDString class.
2028  *
2029  * The instance is specified by string data of a specified length. The
2030  * string content is copied, so the backing memory can be freed after
2031  * this function returns.
2032  */
2033 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2034                                    unsigned SLen);
2035 
2036 /**
2037  * Obtain a MDString value from the global context.
2038  */
2039 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2040 
2041 /**
2042  * Obtain a MDNode value from a context.
2043  *
2044  * The returned value corresponds to the llvm::MDNode class.
2045  */
2046 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2047                                  unsigned Count);
2048 
2049 /**
2050  * Obtain a MDNode value from the global context.
2051  */
2052 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2053 
2054 /**
2055  * Obtain the underlying string from a MDString value.
2056  *
2057  * @param V Instance to obtain string from.
2058  * @param Len Memory address which will hold length of returned string.
2059  * @return String data in MDString.
2060  */
2061 const char  *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2062 
2063 /**
2064  * Obtain the number of operands from an MDNode value.
2065  *
2066  * @param V MDNode to get number of operands from.
2067  * @return Number of operands of the MDNode.
2068  */
2069 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2070 
2071 /**
2072  * Obtain the given MDNode's operands.
2073  *
2074  * The passed LLVMValueRef pointer should point to enough memory to hold all of
2075  * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2076  * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2077  * MDNode's operands.
2078  *
2079  * @param V MDNode to get the operands from.
2080  * @param Dest Destination array for operands.
2081  */
2082 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2083 
2084 /**
2085  * @}
2086  */
2087 
2088 /**
2089  * @defgroup LLVMCCoreValueBasicBlock Basic Block
2090  *
2091  * A basic block represents a single entry single exit section of code.
2092  * Basic blocks contain a list of instructions which form the body of
2093  * the block.
2094  *
2095  * Basic blocks belong to functions. They have the type of label.
2096  *
2097  * Basic blocks are themselves values. However, the C API models them as
2098  * LLVMBasicBlockRef.
2099  *
2100  * @see llvm::BasicBlock
2101  *
2102  * @{
2103  */
2104 
2105 /**
2106  * Convert a basic block instance to a value type.
2107  */
2108 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
2109 
2110 /**
2111  * Determine whether an LLVMValueRef is itself a basic block.
2112  */
2113 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
2114 
2115 /**
2116  * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
2117  */
2118 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
2119 
2120 /**
2121  * Obtain the string name of a basic block.
2122  */
2123 const char *LLVMGetBasicBlockName(LLVMBasicBlockRef BB);
2124 
2125 /**
2126  * Obtain the function to which a basic block belongs.
2127  *
2128  * @see llvm::BasicBlock::getParent()
2129  */
2130 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
2131 
2132 /**
2133  * Obtain the terminator instruction for a basic block.
2134  *
2135  * If the basic block does not have a terminator (it is not well-formed
2136  * if it doesn't), then NULL is returned.
2137  *
2138  * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2139  *
2140  * @see llvm::BasicBlock::getTerminator()
2141  */
2142 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
2143 
2144 /**
2145  * Obtain the number of basic blocks in a function.
2146  *
2147  * @param Fn Function value to operate on.
2148  */
2149 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
2150 
2151 /**
2152  * Obtain all of the basic blocks in a function.
2153  *
2154  * This operates on a function value. The BasicBlocks parameter is a
2155  * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2156  * LLVMCountBasicBlocks() in length. This array is populated with
2157  * LLVMBasicBlockRef instances.
2158  */
2159 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
2160 
2161 /**
2162  * Obtain the first basic block in a function.
2163  *
2164  * The returned basic block can be used as an iterator. You will likely
2165  * eventually call into LLVMGetNextBasicBlock() with it.
2166  *
2167  * @see llvm::Function::begin()
2168  */
2169 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
2170 
2171 /**
2172  * Obtain the last basic block in a function.
2173  *
2174  * @see llvm::Function::end()
2175  */
2176 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
2177 
2178 /**
2179  * Advance a basic block iterator.
2180  */
2181 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
2182 
2183 /**
2184  * Go backwards in a basic block iterator.
2185  */
2186 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
2187 
2188 /**
2189  * Obtain the basic block that corresponds to the entry point of a
2190  * function.
2191  *
2192  * @see llvm::Function::getEntryBlock()
2193  */
2194 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
2195 
2196 /**
2197  * Append a basic block to the end of a function.
2198  *
2199  * @see llvm::BasicBlock::Create()
2200  */
2201 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2202                                                 LLVMValueRef Fn,
2203                                                 const char *Name);
2204 
2205 /**
2206  * Append a basic block to the end of a function using the global
2207  * context.
2208  *
2209  * @see llvm::BasicBlock::Create()
2210  */
2211 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2212 
2213 /**
2214  * Insert a basic block in a function before another basic block.
2215  *
2216  * The function to add to is determined by the function of the
2217  * passed basic block.
2218  *
2219  * @see llvm::BasicBlock::Create()
2220  */
2221 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2222                                                 LLVMBasicBlockRef BB,
2223                                                 const char *Name);
2224 
2225 /**
2226  * Insert a basic block in a function using the global context.
2227  *
2228  * @see llvm::BasicBlock::Create()
2229  */
2230 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2231                                        const char *Name);
2232 
2233 /**
2234  * Remove a basic block from a function and delete it.
2235  *
2236  * This deletes the basic block from its containing function and deletes
2237  * the basic block itself.
2238  *
2239  * @see llvm::BasicBlock::eraseFromParent()
2240  */
2241 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2242 
2243 /**
2244  * Remove a basic block from a function.
2245  *
2246  * This deletes the basic block from its containing function but keep
2247  * the basic block alive.
2248  *
2249  * @see llvm::BasicBlock::removeFromParent()
2250  */
2251 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2252 
2253 /**
2254  * Move a basic block to before another one.
2255  *
2256  * @see llvm::BasicBlock::moveBefore()
2257  */
2258 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2259 
2260 /**
2261  * Move a basic block to after another one.
2262  *
2263  * @see llvm::BasicBlock::moveAfter()
2264  */
2265 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2266 
2267 /**
2268  * Obtain the first instruction in a basic block.
2269  *
2270  * The returned LLVMValueRef corresponds to a llvm::Instruction
2271  * instance.
2272  */
2273 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2274 
2275 /**
2276  * Obtain the last instruction in a basic block.
2277  *
2278  * The returned LLVMValueRef corresponds to an LLVM:Instruction.
2279  */
2280 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2281 
2282 /**
2283  * @}
2284  */
2285 
2286 /**
2287  * @defgroup LLVMCCoreValueInstruction Instructions
2288  *
2289  * Functions in this group relate to the inspection and manipulation of
2290  * individual instructions.
2291  *
2292  * In the C++ API, an instruction is modeled by llvm::Instruction. This
2293  * class has a large number of descendents. llvm::Instruction is a
2294  * llvm::Value and in the C API, instructions are modeled by
2295  * LLVMValueRef.
2296  *
2297  * This group also contains sub-groups which operate on specific
2298  * llvm::Instruction types, e.g. llvm::CallInst.
2299  *
2300  * @{
2301  */
2302 
2303 /**
2304  * Determine whether an instruction has any metadata attached.
2305  */
2306 int LLVMHasMetadata(LLVMValueRef Val);
2307 
2308 /**
2309  * Return metadata associated with an instruction value.
2310  */
2311 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2312 
2313 /**
2314  * Set metadata associated with an instruction value.
2315  */
2316 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2317 
2318 /**
2319  * Obtain the basic block to which an instruction belongs.
2320  *
2321  * @see llvm::Instruction::getParent()
2322  */
2323 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2324 
2325 /**
2326  * Obtain the instruction that occurs after the one specified.
2327  *
2328  * The next instruction will be from the same basic block.
2329  *
2330  * If this is the last instruction in a basic block, NULL will be
2331  * returned.
2332  */
2333 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2334 
2335 /**
2336  * Obtain the instruction that occurred before this one.
2337  *
2338  * If the instruction is the first instruction in a basic block, NULL
2339  * will be returned.
2340  */
2341 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2342 
2343 /**
2344  * Remove and delete an instruction.
2345  *
2346  * The instruction specified is removed from its containing building
2347  * block but is kept alive.
2348  *
2349  * @see llvm::Instruction::removeFromParent()
2350  */
2351 void LLVMInstructionRemoveFromParent(LLVMValueRef Inst);
2352 
2353 /**
2354  * Remove and delete an instruction.
2355  *
2356  * The instruction specified is removed from its containing building
2357  * block and then deleted.
2358  *
2359  * @see llvm::Instruction::eraseFromParent()
2360  */
2361 void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2362 
2363 /**
2364  * Obtain the code opcode for an individual instruction.
2365  *
2366  * @see llvm::Instruction::getOpCode()
2367  */
2368 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2369 
2370 /**
2371  * Obtain the predicate of an instruction.
2372  *
2373  * This is only valid for instructions that correspond to llvm::ICmpInst
2374  * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2375  *
2376  * @see llvm::ICmpInst::getPredicate()
2377  */
2378 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2379 
2380 /**
2381  * Obtain the float predicate of an instruction.
2382  *
2383  * This is only valid for instructions that correspond to llvm::FCmpInst
2384  * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
2385  *
2386  * @see llvm::FCmpInst::getPredicate()
2387  */
2388 LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
2389 
2390 /**
2391  * Create a copy of 'this' instruction that is identical in all ways
2392  * except the following:
2393  *   * The instruction has no parent
2394  *   * The instruction has no name
2395  *
2396  * @see llvm::Instruction::clone()
2397  */
2398 LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
2399 
2400 /**
2401  * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2402  *
2403  * Functions in this group apply to instructions that refer to call
2404  * sites and invocations. These correspond to C++ types in the
2405  * llvm::CallInst class tree.
2406  *
2407  * @{
2408  */
2409 
2410 /**
2411  * Obtain the argument count for a call instruction.
2412  *
2413  * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2414  * llvm::InvokeInst.
2415  *
2416  * @see llvm::CallInst::getNumArgOperands()
2417  * @see llvm::InvokeInst::getNumArgOperands()
2418  */
2419 unsigned LLVMGetNumArgOperands(LLVMValueRef Instr);
2420 
2421 /**
2422  * Set the calling convention for a call instruction.
2423  *
2424  * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2425  * llvm::InvokeInst.
2426  *
2427  * @see llvm::CallInst::setCallingConv()
2428  * @see llvm::InvokeInst::setCallingConv()
2429  */
2430 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2431 
2432 /**
2433  * Obtain the calling convention for a call instruction.
2434  *
2435  * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2436  * usage.
2437  *
2438  * @see LLVMSetInstructionCallConv()
2439  */
2440 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2441 
2442 
2443 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2444 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2445                               LLVMAttribute);
2446 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2447                                 unsigned align);
2448 
2449 /**
2450  * Obtain the pointer to the function invoked by this instruction.
2451  *
2452  * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2453  * llvm::InvokeInst.
2454  *
2455  * @see llvm::CallInst::getCalledValue()
2456  * @see llvm::InvokeInst::getCalledValue()
2457  */
2458 LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr);
2459 
2460 /**
2461  * Obtain whether a call instruction is a tail call.
2462  *
2463  * This only works on llvm::CallInst instructions.
2464  *
2465  * @see llvm::CallInst::isTailCall()
2466  */
2467 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2468 
2469 /**
2470  * Set whether a call instruction is a tail call.
2471  *
2472  * This only works on llvm::CallInst instructions.
2473  *
2474  * @see llvm::CallInst::setTailCall()
2475  */
2476 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2477 
2478 /**
2479  * Return the normal destination basic block.
2480  *
2481  * This only works on llvm::InvokeInst instructions.
2482  *
2483  * @see llvm::InvokeInst::getNormalDest()
2484  */
2485 LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef InvokeInst);
2486 
2487 /**
2488  * Return the unwind destination basic block.
2489  *
2490  * This only works on llvm::InvokeInst instructions.
2491  *
2492  * @see llvm::InvokeInst::getUnwindDest()
2493  */
2494 LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef InvokeInst);
2495 
2496 /**
2497  * Set the normal destination basic block.
2498  *
2499  * This only works on llvm::InvokeInst instructions.
2500  *
2501  * @see llvm::InvokeInst::setNormalDest()
2502  */
2503 void LLVMSetNormalDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2504 
2505 /**
2506  * Set the unwind destination basic block.
2507  *
2508  * This only works on llvm::InvokeInst instructions.
2509  *
2510  * @see llvm::InvokeInst::setUnwindDest()
2511  */
2512 void LLVMSetUnwindDest(LLVMValueRef InvokeInst, LLVMBasicBlockRef B);
2513 
2514 /**
2515  * @}
2516  */
2517 
2518 /**
2519  * @defgroup LLVMCCoreValueInstructionTerminator Terminators
2520  *
2521  * Functions in this group only apply to instructions that map to
2522  * llvm::TerminatorInst instances.
2523  *
2524  * @{
2525  */
2526 
2527 /**
2528  * Return the number of successors that this terminator has.
2529  *
2530  * @see llvm::TerminatorInst::getNumSuccessors
2531  */
2532 unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
2533 
2534 /**
2535  * Return the specified successor.
2536  *
2537  * @see llvm::TerminatorInst::getSuccessor
2538  */
2539 LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
2540 
2541 /**
2542  * Update the specified successor to point at the provided block.
2543  *
2544  * @see llvm::TerminatorInst::setSuccessor
2545  */
2546 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
2547 
2548 /**
2549  * Return if a branch is conditional.
2550  *
2551  * This only works on llvm::BranchInst instructions.
2552  *
2553  * @see llvm::BranchInst::isConditional
2554  */
2555 LLVMBool LLVMIsConditional(LLVMValueRef Branch);
2556 
2557 /**
2558  * Return the condition of a branch instruction.
2559  *
2560  * This only works on llvm::BranchInst instructions.
2561  *
2562  * @see llvm::BranchInst::getCondition
2563  */
2564 LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
2565 
2566 /**
2567  * Set the condition of a branch instruction.
2568  *
2569  * This only works on llvm::BranchInst instructions.
2570  *
2571  * @see llvm::BranchInst::setCondition
2572  */
2573 void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
2574 
2575 /**
2576  * Obtain the default destination basic block of a switch instruction.
2577  *
2578  * This only works on llvm::SwitchInst instructions.
2579  *
2580  * @see llvm::SwitchInst::getDefaultDest()
2581  */
2582 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2583 
2584 /**
2585  * @}
2586  */
2587 
2588 /**
2589  * @defgroup LLVMCCoreValueInstructionAlloca Allocas
2590  *
2591  * Functions in this group only apply to instructions that map to
2592  * llvm::AllocaInst instances.
2593  *
2594  * @{
2595  */
2596 
2597 /**
2598  * Obtain the type that is being allocated by the alloca instruction.
2599  */
2600 LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
2601 
2602 /**
2603  * @}
2604  */
2605 
2606 /**
2607  * @defgroup LLVMCCoreValueInstructionGetElementPointer GEPs
2608  *
2609  * Functions in this group only apply to instructions that map to
2610  * llvm::GetElementPtrInst instances.
2611  *
2612  * @{
2613  */
2614 
2615 /**
2616  * Check whether the given GEP instruction is inbounds.
2617  */
2618 LLVMBool LLVMIsInBounds(LLVMValueRef GEP);
2619 
2620 /**
2621  * Set the given GEP instruction to be inbounds or not.
2622  */
2623 void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool b);
2624 
2625 /**
2626  * @}
2627  */
2628 
2629 /**
2630  * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2631  *
2632  * Functions in this group only apply to instructions that map to
2633  * llvm::PHINode instances.
2634  *
2635  * @{
2636  */
2637 
2638 /**
2639  * Add an incoming value to the end of a PHI list.
2640  */
2641 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2642                      LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2643 
2644 /**
2645  * Obtain the number of incoming basic blocks to a PHI node.
2646  */
2647 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2648 
2649 /**
2650  * Obtain an incoming value to a PHI node as an LLVMValueRef.
2651  */
2652 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2653 
2654 /**
2655  * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
2656  */
2657 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2658 
2659 /**
2660  * @}
2661  */
2662 
2663 /**
2664  * @defgroup LLVMCCoreValueInstructionExtractValue ExtractValue
2665  * @defgroup LLVMCCoreValueInstructionInsertValue InsertValue
2666  *
2667  * Functions in this group only apply to instructions that map to
2668  * llvm::ExtractValue and llvm::InsertValue instances.
2669  *
2670  * @{
2671  */
2672 
2673 /**
2674  * Obtain the number of indices.
2675  * NB: This also works on GEP.
2676  */
2677 unsigned LLVMGetNumIndices(LLVMValueRef Inst);
2678 
2679 /**
2680  * Obtain the indices as an array.
2681  */
2682 const unsigned *LLVMGetIndices(LLVMValueRef Inst);
2683 
2684 /**
2685  * @}
2686  */
2687 
2688 /**
2689  * @}
2690  */
2691 
2692 /**
2693  * @}
2694  */
2695 
2696 /**
2697  * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2698  *
2699  * An instruction builder represents a point within a basic block and is
2700  * the exclusive means of building instructions using the C interface.
2701  *
2702  * @{
2703  */
2704 
2705 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2706 LLVMBuilderRef LLVMCreateBuilder(void);
2707 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2708                          LLVMValueRef Instr);
2709 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2710 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2711 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2712 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2713 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2714 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2715                                    const char *Name);
2716 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2717 
2718 /* Metadata */
2719 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2720 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2721 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2722 
2723 /* Terminators */
2724 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2725 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2726 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2727                                    unsigned N);
2728 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2729 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2730                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2731 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2732                              LLVMBasicBlockRef Else, unsigned NumCases);
2733 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2734                                  unsigned NumDests);
2735 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2736                              LLVMValueRef *Args, unsigned NumArgs,
2737                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2738                              const char *Name);
2739 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2740                                  LLVMValueRef PersFn, unsigned NumClauses,
2741                                  const char *Name);
2742 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2743 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2744 
2745 /* Add a case to the switch instruction */
2746 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2747                  LLVMBasicBlockRef Dest);
2748 
2749 /* Add a destination to the indirectbr instruction */
2750 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2751 
2752 /* Get the number of clauses on the landingpad instruction */
2753 unsigned LLVMGetNumClauses(LLVMValueRef LandingPad);
2754 
2755 /* Get the value of the clause at idnex Idx on the landingpad instruction */
2756 LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx);
2757 
2758 /* Add a catch or filter clause to the landingpad instruction */
2759 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2760 
2761 /* Get the 'cleanup' flag in the landingpad instruction */
2762 LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad);
2763 
2764 /* Set the 'cleanup' flag in the landingpad instruction */
2765 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2766 
2767 /* Arithmetic */
2768 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2769                           const char *Name);
2770 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2771                              const char *Name);
2772 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2773                              const char *Name);
2774 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2775                            const char *Name);
2776 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2777                           const char *Name);
2778 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2779                              const char *Name);
2780 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2781                              const char *Name);
2782 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2783                            const char *Name);
2784 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2785                           const char *Name);
2786 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2787                              const char *Name);
2788 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2789                              const char *Name);
2790 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2791                            const char *Name);
2792 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2793                            const char *Name);
2794 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2795                            const char *Name);
2796 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2797                                 const char *Name);
2798 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2799                            const char *Name);
2800 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2801                            const char *Name);
2802 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2803                            const char *Name);
2804 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2805                            const char *Name);
2806 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2807                            const char *Name);
2808 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2809                            const char *Name);
2810 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2811                            const char *Name);
2812 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2813                           const char *Name);
2814 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2815                           const char *Name);
2816 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2817                           const char *Name);
2818 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2819                             LLVMValueRef LHS, LLVMValueRef RHS,
2820                             const char *Name);
2821 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2822 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2823                              const char *Name);
2824 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2825                              const char *Name);
2826 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2827 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2828 
2829 /* Memory */
2830 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2831 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2832                                   LLVMValueRef Val, const char *Name);
2833 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2834 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2835                                   LLVMValueRef Val, const char *Name);
2836 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2837 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2838                            const char *Name);
2839 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2840 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2841                           LLVMValueRef *Indices, unsigned NumIndices,
2842                           const char *Name);
2843 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2844                                   LLVMValueRef *Indices, unsigned NumIndices,
2845                                   const char *Name);
2846 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2847                                 unsigned Idx, const char *Name);
2848 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2849                                    const char *Name);
2850 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2851                                       const char *Name);
2852 LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2853 void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2854 LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
2855 void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
2856 
2857 /* Casts */
2858 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2859                             LLVMTypeRef DestTy, const char *Name);
2860 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2861                            LLVMTypeRef DestTy, const char *Name);
2862 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2863                            LLVMTypeRef DestTy, const char *Name);
2864 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2865                              LLVMTypeRef DestTy, const char *Name);
2866 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2867                              LLVMTypeRef DestTy, const char *Name);
2868 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2869                              LLVMTypeRef DestTy, const char *Name);
2870 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2871                              LLVMTypeRef DestTy, const char *Name);
2872 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2873                               LLVMTypeRef DestTy, const char *Name);
2874 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2875                             LLVMTypeRef DestTy, const char *Name);
2876 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2877                                LLVMTypeRef DestTy, const char *Name);
2878 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2879                                LLVMTypeRef DestTy, const char *Name);
2880 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2881                               LLVMTypeRef DestTy, const char *Name);
2882 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2883                                     LLVMTypeRef DestTy, const char *Name);
2884 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2885                                     LLVMTypeRef DestTy, const char *Name);
2886 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2887                                     LLVMTypeRef DestTy, const char *Name);
2888 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2889                                      LLVMTypeRef DestTy, const char *Name);
2890 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2891                            LLVMTypeRef DestTy, const char *Name);
2892 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2893                                   LLVMTypeRef DestTy, const char *Name);
2894 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2895                               LLVMTypeRef DestTy, const char *Name);
2896 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2897                              LLVMTypeRef DestTy, const char *Name);
2898 
2899 /* Comparisons */
2900 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2901                            LLVMValueRef LHS, LLVMValueRef RHS,
2902                            const char *Name);
2903 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2904                            LLVMValueRef LHS, LLVMValueRef RHS,
2905                            const char *Name);
2906 
2907 /* Miscellaneous instructions */
2908 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2909 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2910                            LLVMValueRef *Args, unsigned NumArgs,
2911                            const char *Name);
2912 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2913                              LLVMValueRef Then, LLVMValueRef Else,
2914                              const char *Name);
2915 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2916                             const char *Name);
2917 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2918                                      LLVMValueRef Index, const char *Name);
2919 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2920                                     LLVMValueRef EltVal, LLVMValueRef Index,
2921                                     const char *Name);
2922 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2923                                     LLVMValueRef V2, LLVMValueRef Mask,
2924                                     const char *Name);
2925 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2926                                    unsigned Index, const char *Name);
2927 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2928                                   LLVMValueRef EltVal, unsigned Index,
2929                                   const char *Name);
2930 
2931 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2932                              const char *Name);
2933 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2934                                 const char *Name);
2935 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2936                               LLVMValueRef RHS, const char *Name);
2937 LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2938                             LLVMBool singleThread, const char *Name);
2939 LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
2940                                 LLVMValueRef PTR, LLVMValueRef Val,
2941                                 LLVMAtomicOrdering ordering,
2942                                 LLVMBool singleThread);
2943 LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr,
2944                                     LLVMValueRef Cmp, LLVMValueRef New,
2945                                     LLVMAtomicOrdering SuccessOrdering,
2946                                     LLVMAtomicOrdering FailureOrdering,
2947                                     LLVMBool SingleThread);
2948 
2949 LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst);
2950 void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool SingleThread);
2951 
2952 LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst);
2953 void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst,
2954                                    LLVMAtomicOrdering Ordering);
2955 LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst);
2956 void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst,
2957                                    LLVMAtomicOrdering Ordering);
2958 
2959 /**
2960  * @}
2961  */
2962 
2963 /**
2964  * @defgroup LLVMCCoreModuleProvider Module Providers
2965  *
2966  * @{
2967  */
2968 
2969 /**
2970  * Changes the type of M so it can be passed to FunctionPassManagers and the
2971  * JIT.  They take ModuleProviders for historical reasons.
2972  */
2973 LLVMModuleProviderRef
2974 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2975 
2976 /**
2977  * Destroys the module M.
2978  */
2979 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2980 
2981 /**
2982  * @}
2983  */
2984 
2985 /**
2986  * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2987  *
2988  * @{
2989  */
2990 
2991 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2992                                                   LLVMMemoryBufferRef *OutMemBuf,
2993                                                   char **OutMessage);
2994 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2995                                          char **OutMessage);
2996 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2997                                                           size_t InputDataLength,
2998                                                           const char *BufferName,
2999                                                           LLVMBool RequiresNullTerminator);
3000 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
3001                                                               size_t InputDataLength,
3002                                                               const char *BufferName);
3003 const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
3004 size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
3005 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
3006 
3007 /**
3008  * @}
3009  */
3010 
3011 /**
3012  * @defgroup LLVMCCorePassRegistry Pass Registry
3013  *
3014  * @{
3015  */
3016 
3017 /** Return the global pass registry, for use with initialization functions.
3018     @see llvm::PassRegistry::getPassRegistry */
3019 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
3020 
3021 /**
3022  * @}
3023  */
3024 
3025 /**
3026  * @defgroup LLVMCCorePassManagers Pass Managers
3027  *
3028  * @{
3029  */
3030 
3031 /** Constructs a new whole-module pass pipeline. This type of pipeline is
3032     suitable for link-time optimization and whole-module transformations.
3033     @see llvm::PassManager::PassManager */
3034 LLVMPassManagerRef LLVMCreatePassManager(void);
3035 
3036 /** Constructs a new function-by-function pass pipeline over the module
3037     provider. It does not take ownership of the module provider. This type of
3038     pipeline is suitable for code generation and JIT compilation tasks.
3039     @see llvm::FunctionPassManager::FunctionPassManager */
3040 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
3041 
3042 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
3043 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
3044 
3045 /** Initializes, executes on the provided module, and finalizes all of the
3046     passes scheduled in the pass manager. Returns 1 if any of the passes
3047     modified the module, 0 otherwise.
3048     @see llvm::PassManager::run(Module&) */
3049 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
3050 
3051 /** Initializes all of the function passes scheduled in the function pass
3052     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
3053     @see llvm::FunctionPassManager::doInitialization */
3054 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
3055 
3056 /** Executes all of the function passes scheduled in the function pass manager
3057     on the provided function. Returns 1 if any of the passes modified the
3058     function, false otherwise.
3059     @see llvm::FunctionPassManager::run(Function&) */
3060 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
3061 
3062 /** Finalizes all of the function passes scheduled in in the function pass
3063     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
3064     @see llvm::FunctionPassManager::doFinalization */
3065 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
3066 
3067 /** Frees the memory of a pass pipeline. For function pipelines, does not free
3068     the module provider.
3069     @see llvm::PassManagerBase::~PassManagerBase. */
3070 void LLVMDisposePassManager(LLVMPassManagerRef PM);
3071 
3072 /**
3073  * @}
3074  */
3075 
3076 /**
3077  * @defgroup LLVMCCoreThreading Threading
3078  *
3079  * Handle the structures needed to make LLVM safe for multithreading.
3080  *
3081  * @{
3082  */
3083 
3084 /** Deprecated: Multi-threading can only be enabled/disabled with the compile
3085     time define LLVM_ENABLE_THREADS.  This function always returns
3086     LLVMIsMultithreaded(). */
3087 LLVMBool LLVMStartMultithreaded(void);
3088 
3089 /** Deprecated: Multi-threading can only be enabled/disabled with the compile
3090     time define LLVM_ENABLE_THREADS. */
3091 void LLVMStopMultithreaded(void);
3092 
3093 /** Check whether LLVM is executing in thread-safe mode or not.
3094     @see llvm::llvm_is_multithreaded */
3095 LLVMBool LLVMIsMultithreaded(void);
3096 
3097 /**
3098  * @}
3099  */
3100 
3101 /**
3102  * @}
3103  */
3104 
3105 /**
3106  * @}
3107  */
3108 
3109 #ifdef __cplusplus
3110 }
3111 #endif
3112 
3113 #endif /* LLVM_C_CORE_H */
3114