Core.h revision 296417
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
22extern "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
57typedef 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
100typedef 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
183typedef 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
203typedef 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
226typedef enum {
227  LLVMDefaultVisibility,  /**< The GV is visible */
228  LLVMHiddenVisibility,   /**< The GV is hidden */
229  LLVMProtectedVisibility /**< The GV is protected */
230} LLVMVisibility;
231
232typedef 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
238typedef 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
248typedef 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
261typedef 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
280typedef enum {
281  LLVMLandingPadCatch,    /**< A catch clause   */
282  LLVMLandingPadFilter    /**< A filter clause  */
283} LLVMLandingPadClauseTy;
284
285typedef enum {
286  LLVMNotThreadLocal = 0,
287  LLVMGeneralDynamicTLSModel,
288  LLVMLocalDynamicTLSModel,
289  LLVMInitialExecTLSModel,
290  LLVMLocalExecTLSModel
291} LLVMThreadLocalMode;
292
293typedef 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
320typedef 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
342typedef enum {
343    LLVMDSError,
344    LLVMDSWarning,
345    LLVMDSRemark,
346    LLVMDSNote
347} LLVMDiagnosticSeverity;
348
349/**
350 * @}
351 */
352
353void LLVMInitializeCore(LLVMPassRegistryRef R);
354
355/** Deallocate and destroy all ManagedStatic variables.
356    @see llvm::llvm_shutdown
357    @see ManagedStatic */
358void LLVMShutdown(void);
359
360/*===-- Error handling ----------------------------------------------------===*/
361
362char *LLVMCreateMessage(const char *Message);
363void 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
377typedef void (*LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *);
378typedef 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 */
386LLVMContextRef LLVMContextCreate(void);
387
388/**
389 * Obtain the global context instance.
390 */
391LLVMContextRef LLVMGetGlobalContext(void);
392
393/**
394 * Set the diagnostic handler for this context.
395 */
396void 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 */
405void 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 */
414void 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 */
422char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI);
423
424/**
425 * Return an enum LLVMDiagnosticSeverity.
426 *
427 * @see DiagnosticInfo::getSeverity()
428 */
429LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI);
430
431unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
432                                  unsigned SLen);
433unsigned 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 */
458LLVMModuleRef 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 */
466LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
467                                                LLVMContextRef C);
468/**
469 * Return an exact copy of the specified module.
470 */
471LLVMModuleRef 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 */
479void LLVMDisposeModule(LLVMModuleRef M);
480
481/**
482 * Obtain the data layout for a module.
483 *
484 * @see Module::getDataLayout()
485 */
486const char *LLVMGetDataLayout(LLVMModuleRef M);
487
488/**
489 * Set the data layout for a module.
490 *
491 * @see Module::setDataLayout()
492 */
493void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
494
495/**
496 * Obtain the target triple for a module.
497 *
498 * @see Module::getTargetTriple()
499 */
500const char *LLVMGetTarget(LLVMModuleRef M);
501
502/**
503 * Set the target triple for a module.
504 *
505 * @see Module::setTargetTriple()
506 */
507void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
508
509/**
510 * Dump a representation of a module to stderr.
511 *
512 * @see Module::dump()
513 */
514void LLVMDumpModule(LLVMModuleRef M);
515
516/**
517 * Print a representation of a module to a file. The ErrorMessage needs to be
518 * disposed with LLVMDisposeMessage. Returns 0 on success, 1 otherwise.
519 *
520 * @see Module::print()
521 */
522LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
523                               char **ErrorMessage);
524
525/**
526 * Return a string representation of the module. Use
527 * LLVMDisposeMessage to free the string.
528 *
529 * @see Module::print()
530 */
531char *LLVMPrintModuleToString(LLVMModuleRef M);
532
533/**
534 * Set inline assembly for a module.
535 *
536 * @see Module::setModuleInlineAsm()
537 */
538void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm);
539
540/**
541 * Obtain the context to which this module is associated.
542 *
543 * @see Module::getContext()
544 */
545LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
546
547/**
548 * Obtain a Type from a module by its registered name.
549 */
550LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
551
552/**
553 * Obtain the number of operands for named metadata in a module.
554 *
555 * @see llvm::Module::getNamedMetadata()
556 */
557unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
558
559/**
560 * Obtain the named metadata operands for a module.
561 *
562 * The passed LLVMValueRef pointer should refer to an array of
563 * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
564 * array will be populated with the LLVMValueRef instances. Each
565 * instance corresponds to a llvm::MDNode.
566 *
567 * @see llvm::Module::getNamedMetadata()
568 * @see llvm::MDNode::getOperand()
569 */
570void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
571
572/**
573 * Add an operand to named metadata.
574 *
575 * @see llvm::Module::getNamedMetadata()
576 * @see llvm::MDNode::addOperand()
577 */
578void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
579                                 LLVMValueRef Val);
580
581/**
582 * Add a function to a module under a specified name.
583 *
584 * @see llvm::Function::Create()
585 */
586LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
587                             LLVMTypeRef FunctionTy);
588
589/**
590 * Obtain a Function value from a Module by its name.
591 *
592 * The returned value corresponds to a llvm::Function value.
593 *
594 * @see llvm::Module::getFunction()
595 */
596LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
597
598/**
599 * Obtain an iterator to the first Function in a Module.
600 *
601 * @see llvm::Module::begin()
602 */
603LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
604
605/**
606 * Obtain an iterator to the last Function in a Module.
607 *
608 * @see llvm::Module::end()
609 */
610LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
611
612/**
613 * Advance a Function iterator to the next Function.
614 *
615 * Returns NULL if the iterator was already at the end and there are no more
616 * functions.
617 */
618LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
619
620/**
621 * Decrement a Function iterator to the previous Function.
622 *
623 * Returns NULL if the iterator was already at the beginning and there are
624 * no previous functions.
625 */
626LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
627
628/**
629 * @}
630 */
631
632/**
633 * @defgroup LLVMCCoreType Types
634 *
635 * Types represent the type of a value.
636 *
637 * Types are associated with a context instance. The context internally
638 * deduplicates types so there is only 1 instance of a specific type
639 * alive at a time. In other words, a unique type is shared among all
640 * consumers within a context.
641 *
642 * A Type in the C API corresponds to llvm::Type.
643 *
644 * Types have the following hierarchy:
645 *
646 *   types:
647 *     integer type
648 *     real type
649 *     function type
650 *     sequence types:
651 *       array type
652 *       pointer type
653 *       vector type
654 *     void type
655 *     label type
656 *     opaque type
657 *
658 * @{
659 */
660
661/**
662 * Obtain the enumerated type of a Type instance.
663 *
664 * @see llvm::Type:getTypeID()
665 */
666LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
667
668/**
669 * Whether the type has a known size.
670 *
671 * Things that don't have a size are abstract types, labels, and void.a
672 *
673 * @see llvm::Type::isSized()
674 */
675LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
676
677/**
678 * Obtain the context to which this type instance is associated.
679 *
680 * @see llvm::Type::getContext()
681 */
682LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
683
684/**
685 * Dump a representation of a type to stderr.
686 *
687 * @see llvm::Type::dump()
688 */
689void LLVMDumpType(LLVMTypeRef Val);
690
691/**
692 * Return a string representation of the type. Use
693 * LLVMDisposeMessage to free the string.
694 *
695 * @see llvm::Type::print()
696 */
697char *LLVMPrintTypeToString(LLVMTypeRef Val);
698
699/**
700 * @defgroup LLVMCCoreTypeInt Integer Types
701 *
702 * Functions in this section operate on integer types.
703 *
704 * @{
705 */
706
707/**
708 * Obtain an integer type from a context with specified bit width.
709 */
710LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
711LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
712LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
713LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
714LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
715LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C);
716LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
717
718/**
719 * Obtain an integer type from the global context with a specified bit
720 * width.
721 */
722LLVMTypeRef LLVMInt1Type(void);
723LLVMTypeRef LLVMInt8Type(void);
724LLVMTypeRef LLVMInt16Type(void);
725LLVMTypeRef LLVMInt32Type(void);
726LLVMTypeRef LLVMInt64Type(void);
727LLVMTypeRef LLVMInt128Type(void);
728LLVMTypeRef LLVMIntType(unsigned NumBits);
729unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
730
731/**
732 * @}
733 */
734
735/**
736 * @defgroup LLVMCCoreTypeFloat Floating Point Types
737 *
738 * @{
739 */
740
741/**
742 * Obtain a 16-bit floating point type from a context.
743 */
744LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
745
746/**
747 * Obtain a 32-bit floating point type from a context.
748 */
749LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
750
751/**
752 * Obtain a 64-bit floating point type from a context.
753 */
754LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
755
756/**
757 * Obtain a 80-bit floating point type (X87) from a context.
758 */
759LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
760
761/**
762 * Obtain a 128-bit floating point type (112-bit mantissa) from a
763 * context.
764 */
765LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
766
767/**
768 * Obtain a 128-bit floating point type (two 64-bits) from a context.
769 */
770LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
771
772/**
773 * Obtain a floating point type from the global context.
774 *
775 * These map to the functions in this group of the same name.
776 */
777LLVMTypeRef LLVMHalfType(void);
778LLVMTypeRef LLVMFloatType(void);
779LLVMTypeRef LLVMDoubleType(void);
780LLVMTypeRef LLVMX86FP80Type(void);
781LLVMTypeRef LLVMFP128Type(void);
782LLVMTypeRef LLVMPPCFP128Type(void);
783
784/**
785 * @}
786 */
787
788/**
789 * @defgroup LLVMCCoreTypeFunction Function Types
790 *
791 * @{
792 */
793
794/**
795 * Obtain a function type consisting of a specified signature.
796 *
797 * The function is defined as a tuple of a return Type, a list of
798 * parameter types, and whether the function is variadic.
799 */
800LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
801                             LLVMTypeRef *ParamTypes, unsigned ParamCount,
802                             LLVMBool IsVarArg);
803
804/**
805 * Returns whether a function type is variadic.
806 */
807LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
808
809/**
810 * Obtain the Type this function Type returns.
811 */
812LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
813
814/**
815 * Obtain the number of parameters this function accepts.
816 */
817unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
818
819/**
820 * Obtain the types of a function's parameters.
821 *
822 * The Dest parameter should point to a pre-allocated array of
823 * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
824 * first LLVMCountParamTypes() entries in the array will be populated
825 * with LLVMTypeRef instances.
826 *
827 * @param FunctionTy The function type to operate on.
828 * @param Dest Memory address of an array to be filled with result.
829 */
830void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
831
832/**
833 * @}
834 */
835
836/**
837 * @defgroup LLVMCCoreTypeStruct Structure Types
838 *
839 * These functions relate to LLVMTypeRef instances.
840 *
841 * @see llvm::StructType
842 *
843 * @{
844 */
845
846/**
847 * Create a new structure type in a context.
848 *
849 * A structure is specified by a list of inner elements/types and
850 * whether these can be packed together.
851 *
852 * @see llvm::StructType::create()
853 */
854LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
855                                    unsigned ElementCount, LLVMBool Packed);
856
857/**
858 * Create a new structure type in the global context.
859 *
860 * @see llvm::StructType::create()
861 */
862LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
863                           LLVMBool Packed);
864
865/**
866 * Create an empty structure in a context having a specified name.
867 *
868 * @see llvm::StructType::create()
869 */
870LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
871
872/**
873 * Obtain the name of a structure.
874 *
875 * @see llvm::StructType::getName()
876 */
877const char *LLVMGetStructName(LLVMTypeRef Ty);
878
879/**
880 * Set the contents of a structure type.
881 *
882 * @see llvm::StructType::setBody()
883 */
884void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
885                       unsigned ElementCount, LLVMBool Packed);
886
887/**
888 * Get the number of elements defined inside the structure.
889 *
890 * @see llvm::StructType::getNumElements()
891 */
892unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
893
894/**
895 * Get the elements within a structure.
896 *
897 * The function is passed the address of a pre-allocated array of
898 * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
899 * invocation, this array will be populated with the structure's
900 * elements. The objects in the destination array will have a lifetime
901 * of the structure type itself, which is the lifetime of the context it
902 * is contained in.
903 */
904void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
905
906/**
907 * Get the type of the element at a given index in the structure.
908 *
909 * @see llvm::StructType::getTypeAtIndex()
910 */
911LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i);
912
913/**
914 * Determine whether a structure is packed.
915 *
916 * @see llvm::StructType::isPacked()
917 */
918LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
919
920/**
921 * Determine whether a structure is opaque.
922 *
923 * @see llvm::StructType::isOpaque()
924 */
925LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
926
927/**
928 * @}
929 */
930
931/**
932 * @defgroup LLVMCCoreTypeSequential Sequential Types
933 *
934 * Sequential types represents "arrays" of types. This is a super class
935 * for array, vector, and pointer types.
936 *
937 * @{
938 */
939
940/**
941 * Obtain the type of elements within a sequential type.
942 *
943 * This works on array, vector, and pointer types.
944 *
945 * @see llvm::SequentialType::getElementType()
946 */
947LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
948
949/**
950 * Create a fixed size array type that refers to a specific type.
951 *
952 * The created type will exist in the context that its element type
953 * exists in.
954 *
955 * @see llvm::ArrayType::get()
956 */
957LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
958
959/**
960 * Obtain the length of an array type.
961 *
962 * This only works on types that represent arrays.
963 *
964 * @see llvm::ArrayType::getNumElements()
965 */
966unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
967
968/**
969 * Create a pointer type that points to a defined type.
970 *
971 * The created type will exist in the context that its pointee type
972 * exists in.
973 *
974 * @see llvm::PointerType::get()
975 */
976LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
977
978/**
979 * Obtain the address space of a pointer type.
980 *
981 * This only works on types that represent pointers.
982 *
983 * @see llvm::PointerType::getAddressSpace()
984 */
985unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
986
987/**
988 * Create a vector type that contains a defined type and has a specific
989 * number of elements.
990 *
991 * The created type will exist in the context thats its element type
992 * exists in.
993 *
994 * @see llvm::VectorType::get()
995 */
996LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
997
998/**
999 * Obtain the number of elements in a vector type.
1000 *
1001 * This only works on types that represent vectors.
1002 *
1003 * @see llvm::VectorType::getNumElements()
1004 */
1005unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
1006
1007/**
1008 * @}
1009 */
1010
1011/**
1012 * @defgroup LLVMCCoreTypeOther Other Types
1013 *
1014 * @{
1015 */
1016
1017/**
1018 * Create a void type in a context.
1019 */
1020LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
1021
1022/**
1023 * Create a label type in a context.
1024 */
1025LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
1026
1027/**
1028 * Create a X86 MMX type in a context.
1029 */
1030LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
1031
1032/**
1033 * These are similar to the above functions except they operate on the
1034 * global context.
1035 */
1036LLVMTypeRef LLVMVoidType(void);
1037LLVMTypeRef LLVMLabelType(void);
1038LLVMTypeRef LLVMX86MMXType(void);
1039
1040/**
1041 * @}
1042 */
1043
1044/**
1045 * @}
1046 */
1047
1048/**
1049 * @defgroup LLVMCCoreValues Values
1050 *
1051 * The bulk of LLVM's object model consists of values, which comprise a very
1052 * rich type hierarchy.
1053 *
1054 * LLVMValueRef essentially represents llvm::Value. There is a rich
1055 * hierarchy of classes within this type. Depending on the instance
1056 * obtained, not all APIs are available.
1057 *
1058 * Callers can determine the type of an LLVMValueRef by calling the
1059 * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
1060 * functions are defined by a macro, so it isn't obvious which are
1061 * available by looking at the Doxygen source code. Instead, look at the
1062 * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
1063 * of value names given. These value names also correspond to classes in
1064 * the llvm::Value hierarchy.
1065 *
1066 * @{
1067 */
1068
1069#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
1070  macro(Argument)                           \
1071  macro(BasicBlock)                         \
1072  macro(InlineAsm)                          \
1073  macro(User)                               \
1074    macro(Constant)                         \
1075      macro(BlockAddress)                   \
1076      macro(ConstantAggregateZero)          \
1077      macro(ConstantArray)                  \
1078      macro(ConstantDataSequential)         \
1079        macro(ConstantDataArray)            \
1080        macro(ConstantDataVector)           \
1081      macro(ConstantExpr)                   \
1082      macro(ConstantFP)                     \
1083      macro(ConstantInt)                    \
1084      macro(ConstantPointerNull)            \
1085      macro(ConstantStruct)                 \
1086      macro(ConstantTokenNone)              \
1087      macro(ConstantVector)                 \
1088      macro(GlobalValue)                    \
1089        macro(GlobalAlias)                  \
1090        macro(GlobalObject)                 \
1091          macro(Function)                   \
1092          macro(GlobalVariable)             \
1093      macro(UndefValue)                     \
1094    macro(Instruction)                      \
1095      macro(BinaryOperator)                 \
1096      macro(CallInst)                       \
1097        macro(IntrinsicInst)                \
1098          macro(DbgInfoIntrinsic)           \
1099            macro(DbgDeclareInst)           \
1100          macro(MemIntrinsic)               \
1101            macro(MemCpyInst)               \
1102            macro(MemMoveInst)              \
1103            macro(MemSetInst)               \
1104      macro(CmpInst)                        \
1105        macro(FCmpInst)                     \
1106        macro(ICmpInst)                     \
1107      macro(ExtractElementInst)             \
1108      macro(GetElementPtrInst)              \
1109      macro(InsertElementInst)              \
1110      macro(InsertValueInst)                \
1111      macro(LandingPadInst)                 \
1112      macro(PHINode)                        \
1113      macro(SelectInst)                     \
1114      macro(ShuffleVectorInst)              \
1115      macro(StoreInst)                      \
1116      macro(TerminatorInst)                 \
1117        macro(BranchInst)                   \
1118        macro(IndirectBrInst)               \
1119        macro(InvokeInst)                   \
1120        macro(ReturnInst)                   \
1121        macro(SwitchInst)                   \
1122        macro(UnreachableInst)              \
1123        macro(ResumeInst)                   \
1124        macro(CleanupReturnInst)            \
1125        macro(CatchReturnInst)              \
1126      macro(FuncletPadInst)                 \
1127        macro(CatchPadInst)                 \
1128        macro(CleanupPadInst)               \
1129      macro(UnaryInstruction)               \
1130        macro(AllocaInst)                   \
1131        macro(CastInst)                     \
1132          macro(AddrSpaceCastInst)          \
1133          macro(BitCastInst)                \
1134          macro(FPExtInst)                  \
1135          macro(FPToSIInst)                 \
1136          macro(FPToUIInst)                 \
1137          macro(FPTruncInst)                \
1138          macro(IntToPtrInst)               \
1139          macro(PtrToIntInst)               \
1140          macro(SExtInst)                   \
1141          macro(SIToFPInst)                 \
1142          macro(TruncInst)                  \
1143          macro(UIToFPInst)                 \
1144          macro(ZExtInst)                   \
1145        macro(ExtractValueInst)             \
1146        macro(LoadInst)                     \
1147        macro(VAArgInst)
1148
1149/**
1150 * @defgroup LLVMCCoreValueGeneral General APIs
1151 *
1152 * Functions in this section work on all LLVMValueRef instances,
1153 * regardless of their sub-type. They correspond to functions available
1154 * on llvm::Value.
1155 *
1156 * @{
1157 */
1158
1159/**
1160 * Obtain the type of a value.
1161 *
1162 * @see llvm::Value::getType()
1163 */
1164LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
1165
1166/**
1167 * Obtain the string name of a value.
1168 *
1169 * @see llvm::Value::getName()
1170 */
1171const char *LLVMGetValueName(LLVMValueRef Val);
1172
1173/**
1174 * Set the string name of a value.
1175 *
1176 * @see llvm::Value::setName()
1177 */
1178void LLVMSetValueName(LLVMValueRef Val, const char *Name);
1179
1180/**
1181 * Dump a representation of a value to stderr.
1182 *
1183 * @see llvm::Value::dump()
1184 */
1185void LLVMDumpValue(LLVMValueRef Val);
1186
1187/**
1188 * Return a string representation of the value. Use
1189 * LLVMDisposeMessage to free the string.
1190 *
1191 * @see llvm::Value::print()
1192 */
1193char *LLVMPrintValueToString(LLVMValueRef Val);
1194
1195/**
1196 * Replace all uses of a value with another one.
1197 *
1198 * @see llvm::Value::replaceAllUsesWith()
1199 */
1200void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
1201
1202/**
1203 * Determine whether the specified constant instance is constant.
1204 */
1205LLVMBool LLVMIsConstant(LLVMValueRef Val);
1206
1207/**
1208 * Determine whether a value instance is undefined.
1209 */
1210LLVMBool LLVMIsUndef(LLVMValueRef Val);
1211
1212/**
1213 * Convert value instances between types.
1214 *
1215 * Internally, an LLVMValueRef is "pinned" to a specific type. This
1216 * series of functions allows you to cast an instance to a specific
1217 * type.
1218 *
1219 * If the cast is not valid for the specified type, NULL is returned.
1220 *
1221 * @see llvm::dyn_cast_or_null<>
1222 */
1223#define LLVM_DECLARE_VALUE_CAST(name) \
1224  LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
1225LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
1226
1227LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val);
1228LLVMValueRef LLVMIsAMDString(LLVMValueRef Val);
1229
1230/**
1231 * @}
1232 */
1233
1234/**
1235 * @defgroup LLVMCCoreValueUses Usage
1236 *
1237 * This module defines functions that allow you to inspect the uses of a
1238 * LLVMValueRef.
1239 *
1240 * It is possible to obtain an LLVMUseRef for any LLVMValueRef instance.
1241 * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
1242 * llvm::User and llvm::Value.
1243 *
1244 * @{
1245 */
1246
1247/**
1248 * Obtain the first use of a value.
1249 *
1250 * Uses are obtained in an iterator fashion. First, call this function
1251 * to obtain a reference to the first use. Then, call LLVMGetNextUse()
1252 * on that instance and all subsequently obtained instances until
1253 * LLVMGetNextUse() returns NULL.
1254 *
1255 * @see llvm::Value::use_begin()
1256 */
1257LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
1258
1259/**
1260 * Obtain the next use of a value.
1261 *
1262 * This effectively advances the iterator. It returns NULL if you are on
1263 * the final use and no more are available.
1264 */
1265LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
1266
1267/**
1268 * Obtain the user value for a user.
1269 *
1270 * The returned value corresponds to a llvm::User type.
1271 *
1272 * @see llvm::Use::getUser()
1273 */
1274LLVMValueRef LLVMGetUser(LLVMUseRef U);
1275
1276/**
1277 * Obtain the value this use corresponds to.
1278 *
1279 * @see llvm::Use::get().
1280 */
1281LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
1282
1283/**
1284 * @}
1285 */
1286
1287/**
1288 * @defgroup LLVMCCoreValueUser User value
1289 *
1290 * Function in this group pertain to LLVMValueRef instances that descent
1291 * from llvm::User. This includes constants, instructions, and
1292 * operators.
1293 *
1294 * @{
1295 */
1296
1297/**
1298 * Obtain an operand at a specific index in a llvm::User value.
1299 *
1300 * @see llvm::User::getOperand()
1301 */
1302LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
1303
1304/**
1305 * Obtain the use of an operand at a specific index in a llvm::User value.
1306 *
1307 * @see llvm::User::getOperandUse()
1308 */
1309LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index);
1310
1311/**
1312 * Set an operand at a specific index in a llvm::User value.
1313 *
1314 * @see llvm::User::setOperand()
1315 */
1316void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
1317
1318/**
1319 * Obtain the number of operands in a llvm::User value.
1320 *
1321 * @see llvm::User::getNumOperands()
1322 */
1323int LLVMGetNumOperands(LLVMValueRef Val);
1324
1325/**
1326 * @}
1327 */
1328
1329/**
1330 * @defgroup LLVMCCoreValueConstant Constants
1331 *
1332 * This section contains APIs for interacting with LLVMValueRef that
1333 * correspond to llvm::Constant instances.
1334 *
1335 * These functions will work for any LLVMValueRef in the llvm::Constant
1336 * class hierarchy.
1337 *
1338 * @{
1339 */
1340
1341/**
1342 * Obtain a constant value referring to the null instance of a type.
1343 *
1344 * @see llvm::Constant::getNullValue()
1345 */
1346LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
1347
1348/**
1349 * Obtain a constant value referring to the instance of a type
1350 * consisting of all ones.
1351 *
1352 * This is only valid for integer types.
1353 *
1354 * @see llvm::Constant::getAllOnesValue()
1355 */
1356LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
1357
1358/**
1359 * Obtain a constant value referring to an undefined value of a type.
1360 *
1361 * @see llvm::UndefValue::get()
1362 */
1363LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
1364
1365/**
1366 * Determine whether a value instance is null.
1367 *
1368 * @see llvm::Constant::isNullValue()
1369 */
1370LLVMBool LLVMIsNull(LLVMValueRef Val);
1371
1372/**
1373 * Obtain a constant that is a constant pointer pointing to NULL for a
1374 * specified type.
1375 */
1376LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
1377
1378/**
1379 * @defgroup LLVMCCoreValueConstantScalar Scalar constants
1380 *
1381 * Functions in this group model LLVMValueRef instances that correspond
1382 * to constants referring to scalar types.
1383 *
1384 * For integer types, the LLVMTypeRef parameter should correspond to a
1385 * llvm::IntegerType instance and the returned LLVMValueRef will
1386 * correspond to a llvm::ConstantInt.
1387 *
1388 * For floating point types, the LLVMTypeRef returned corresponds to a
1389 * llvm::ConstantFP.
1390 *
1391 * @{
1392 */
1393
1394/**
1395 * Obtain a constant value for an integer type.
1396 *
1397 * The returned value corresponds to a llvm::ConstantInt.
1398 *
1399 * @see llvm::ConstantInt::get()
1400 *
1401 * @param IntTy Integer type to obtain value of.
1402 * @param N The value the returned instance should refer to.
1403 * @param SignExtend Whether to sign extend the produced value.
1404 */
1405LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1406                          LLVMBool SignExtend);
1407
1408/**
1409 * Obtain a constant value for an integer of arbitrary precision.
1410 *
1411 * @see llvm::ConstantInt::get()
1412 */
1413LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
1414                                              unsigned NumWords,
1415                                              const uint64_t Words[]);
1416
1417/**
1418 * Obtain a constant value for an integer parsed from a string.
1419 *
1420 * A similar API, LLVMConstIntOfStringAndSize is also available. If the
1421 * string's length is available, it is preferred to call that function
1422 * instead.
1423 *
1424 * @see llvm::ConstantInt::get()
1425 */
1426LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
1427                                  uint8_t Radix);
1428
1429/**
1430 * Obtain a constant value for an integer parsed from a string with
1431 * specified length.
1432 *
1433 * @see llvm::ConstantInt::get()
1434 */
1435LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
1436                                         unsigned SLen, uint8_t Radix);
1437
1438/**
1439 * Obtain a constant value referring to a double floating point value.
1440 */
1441LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
1442
1443/**
1444 * Obtain a constant for a floating point value parsed from a string.
1445 *
1446 * A similar API, LLVMConstRealOfStringAndSize is also available. It
1447 * should be used if the input string's length is known.
1448 */
1449LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
1450
1451/**
1452 * Obtain a constant for a floating point value parsed from a string.
1453 */
1454LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
1455                                          unsigned SLen);
1456
1457/**
1458 * Obtain the zero extended value for an integer constant value.
1459 *
1460 * @see llvm::ConstantInt::getZExtValue()
1461 */
1462unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
1463
1464/**
1465 * Obtain the sign extended value for an integer constant value.
1466 *
1467 * @see llvm::ConstantInt::getSExtValue()
1468 */
1469long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
1470
1471/**
1472 * Obtain the double value for an floating point constant value.
1473 * losesInfo indicates if some precision was lost in the conversion.
1474 *
1475 * @see llvm::ConstantFP::getDoubleValue
1476 */
1477double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *losesInfo);
1478
1479/**
1480 * @}
1481 */
1482
1483/**
1484 * @defgroup LLVMCCoreValueConstantComposite Composite Constants
1485 *
1486 * Functions in this group operate on composite constants.
1487 *
1488 * @{
1489 */
1490
1491/**
1492 * Create a ConstantDataSequential and initialize it with a string.
1493 *
1494 * @see llvm::ConstantDataArray::getString()
1495 */
1496LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
1497                                      unsigned Length, LLVMBool DontNullTerminate);
1498
1499/**
1500 * Create a ConstantDataSequential with string content in the global context.
1501 *
1502 * This is the same as LLVMConstStringInContext except it operates on the
1503 * global context.
1504 *
1505 * @see LLVMConstStringInContext()
1506 * @see llvm::ConstantDataArray::getString()
1507 */
1508LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1509                             LLVMBool DontNullTerminate);
1510
1511/**
1512 * Returns true if the specified constant is an array of i8.
1513 *
1514 * @see ConstantDataSequential::getAsString()
1515 */
1516LLVMBool LLVMIsConstantString(LLVMValueRef c);
1517
1518/**
1519 * Get the given constant data sequential as a string.
1520 *
1521 * @see ConstantDataSequential::getAsString()
1522 */
1523const char *LLVMGetAsString(LLVMValueRef c, size_t* out);
1524
1525/**
1526 * Create an anonymous ConstantStruct with the specified values.
1527 *
1528 * @see llvm::ConstantStruct::getAnon()
1529 */
1530LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
1531                                      LLVMValueRef *ConstantVals,
1532                                      unsigned Count, LLVMBool Packed);
1533
1534/**
1535 * Create a ConstantStruct in the global Context.
1536 *
1537 * This is the same as LLVMConstStructInContext except it operates on the
1538 * global Context.
1539 *
1540 * @see LLVMConstStructInContext()
1541 */
1542LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1543                             LLVMBool Packed);
1544
1545/**
1546 * Create a ConstantArray from values.
1547 *
1548 * @see llvm::ConstantArray::get()
1549 */
1550LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
1551                            LLVMValueRef *ConstantVals, unsigned Length);
1552
1553/**
1554 * Create a non-anonymous ConstantStruct from values.
1555 *
1556 * @see llvm::ConstantStruct::get()
1557 */
1558LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
1559                                  LLVMValueRef *ConstantVals,
1560                                  unsigned Count);
1561
1562/**
1563 * Get an element at specified index as a constant.
1564 *
1565 * @see ConstantDataSequential::getElementAsConstant()
1566 */
1567LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx);
1568
1569/**
1570 * Create a ConstantVector from values.
1571 *
1572 * @see llvm::ConstantVector::get()
1573 */
1574LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
1575
1576/**
1577 * @}
1578 */
1579
1580/**
1581 * @defgroup LLVMCCoreValueConstantExpressions Constant Expressions
1582 *
1583 * Functions in this group correspond to APIs on llvm::ConstantExpr.
1584 *
1585 * @see llvm::ConstantExpr.
1586 *
1587 * @{
1588 */
1589LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
1590LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
1591LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
1592LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
1593LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal);
1594LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal);
1595LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
1596LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
1597LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1598LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1599LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1600LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1601LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1602LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1603LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1604LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1605LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1606LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1607LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1608LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1609LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1610LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1611LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1612LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1613LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1614LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1615LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1616LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1617LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1618LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1619LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1620                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1621LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1622                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1623LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1624LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1625LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
1626LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1627                          LLVMValueRef *ConstantIndices, unsigned NumIndices);
1628LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1629                                  LLVMValueRef *ConstantIndices,
1630                                  unsigned NumIndices);
1631LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1632LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1633LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1634LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1635LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1636LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1637LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1638LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1639LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1640LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1641LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1642LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1643LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1644LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1645                                    LLVMTypeRef ToType);
1646LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1647                                    LLVMTypeRef ToType);
1648LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1649                                     LLVMTypeRef ToType);
1650LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1651                                  LLVMTypeRef ToType);
1652LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1653                              LLVMBool isSigned);
1654LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1655LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1656                             LLVMValueRef ConstantIfTrue,
1657                             LLVMValueRef ConstantIfFalse);
1658LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1659                                     LLVMValueRef IndexConstant);
1660LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1661                                    LLVMValueRef ElementValueConstant,
1662                                    LLVMValueRef IndexConstant);
1663LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1664                                    LLVMValueRef VectorBConstant,
1665                                    LLVMValueRef MaskConstant);
1666LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1667                                   unsigned NumIdx);
1668LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1669                                  LLVMValueRef ElementValueConstant,
1670                                  unsigned *IdxList, unsigned NumIdx);
1671LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
1672                                const char *AsmString, const char *Constraints,
1673                                LLVMBool HasSideEffects, LLVMBool IsAlignStack);
1674LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB);
1675
1676/**
1677 * @}
1678 */
1679
1680/**
1681 * @defgroup LLVMCCoreValueConstantGlobals Global Values
1682 *
1683 * This group contains functions that operate on global values. Functions in
1684 * this group relate to functions in the llvm::GlobalValue class tree.
1685 *
1686 * @see llvm::GlobalValue
1687 *
1688 * @{
1689 */
1690
1691LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
1692LLVMBool LLVMIsDeclaration(LLVMValueRef Global);
1693LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
1694void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
1695const char *LLVMGetSection(LLVMValueRef Global);
1696void LLVMSetSection(LLVMValueRef Global, const char *Section);
1697LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
1698void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
1699LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global);
1700void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class);
1701LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global);
1702void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr);
1703
1704/**
1705 * @defgroup LLVMCCoreValueWithAlignment Values with alignment
1706 *
1707 * Functions in this group only apply to values with alignment, i.e.
1708 * global variables, load and store instructions.
1709 */
1710
1711/**
1712 * Obtain the preferred alignment of the value.
1713 * @see llvm::AllocaInst::getAlignment()
1714 * @see llvm::LoadInst::getAlignment()
1715 * @see llvm::StoreInst::getAlignment()
1716 * @see llvm::GlobalValue::getAlignment()
1717 */
1718unsigned LLVMGetAlignment(LLVMValueRef V);
1719
1720/**
1721 * Set the preferred alignment of the value.
1722 * @see llvm::AllocaInst::setAlignment()
1723 * @see llvm::LoadInst::setAlignment()
1724 * @see llvm::StoreInst::setAlignment()
1725 * @see llvm::GlobalValue::setAlignment()
1726 */
1727void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes);
1728
1729/**
1730  * @}
1731  */
1732
1733/**
1734 * @defgroup LLVMCoreValueConstantGlobalVariable Global Variables
1735 *
1736 * This group contains functions that operate on global variable values.
1737 *
1738 * @see llvm::GlobalVariable
1739 *
1740 * @{
1741 */
1742LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
1743LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1744                                         const char *Name,
1745                                         unsigned AddressSpace);
1746LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
1747LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
1748LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
1749LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
1750LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
1751void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
1752LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
1753void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
1754LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
1755void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
1756LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
1757void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
1758LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar);
1759void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode);
1760LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar);
1761void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit);
1762
1763/**
1764 * @}
1765 */
1766
1767/**
1768 * @defgroup LLVMCoreValueConstantGlobalAlias Global Aliases
1769 *
1770 * This group contains function that operate on global alias values.
1771 *
1772 * @see llvm::GlobalAlias
1773 *
1774 * @{
1775 */
1776LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1777                          const char *Name);
1778
1779/**
1780 * @}
1781 */
1782
1783/**
1784 * @defgroup LLVMCCoreValueFunction Function values
1785 *
1786 * Functions in this group operate on LLVMValueRef instances that
1787 * correspond to llvm::Function instances.
1788 *
1789 * @see llvm::Function
1790 *
1791 * @{
1792 */
1793
1794/**
1795 * Remove a function from its containing module and deletes it.
1796 *
1797 * @see llvm::Function::eraseFromParent()
1798 */
1799void LLVMDeleteFunction(LLVMValueRef Fn);
1800
1801/**
1802 * Obtain the personality function attached to the function.
1803 *
1804 * @see llvm::Function::getPersonalityFn()
1805 */
1806LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn);
1807
1808/**
1809 * Set the personality function attached to the function.
1810 *
1811 * @see llvm::Function::setPersonalityFn()
1812 */
1813void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn);
1814
1815/**
1816 * Obtain the ID number from a function instance.
1817 *
1818 * @see llvm::Function::getIntrinsicID()
1819 */
1820unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
1821
1822/**
1823 * Obtain the calling function of a function.
1824 *
1825 * The returned value corresponds to the LLVMCallConv enumeration.
1826 *
1827 * @see llvm::Function::getCallingConv()
1828 */
1829unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
1830
1831/**
1832 * Set the calling convention of a function.
1833 *
1834 * @see llvm::Function::setCallingConv()
1835 *
1836 * @param Fn Function to operate on
1837 * @param CC LLVMCallConv to set calling convention to
1838 */
1839void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
1840
1841/**
1842 * Obtain the name of the garbage collector to use during code
1843 * generation.
1844 *
1845 * @see llvm::Function::getGC()
1846 */
1847const char *LLVMGetGC(LLVMValueRef Fn);
1848
1849/**
1850 * Define the garbage collector to use during code generation.
1851 *
1852 * @see llvm::Function::setGC()
1853 */
1854void LLVMSetGC(LLVMValueRef Fn, const char *Name);
1855
1856/**
1857 * Add an attribute to a function.
1858 *
1859 * @see llvm::Function::addAttribute()
1860 */
1861void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1862
1863/**
1864 * Add a target-dependent attribute to a function
1865 * @see llvm::AttrBuilder::addAttribute()
1866 */
1867void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1868                                        const char *V);
1869
1870/**
1871 * Obtain an attribute from a function.
1872 *
1873 * @see llvm::Function::getAttributes()
1874 */
1875LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
1876
1877/**
1878 * Remove an attribute from a function.
1879 */
1880void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
1881
1882/**
1883 * @defgroup LLVMCCoreValueFunctionParameters Function Parameters
1884 *
1885 * Functions in this group relate to arguments/parameters on functions.
1886 *
1887 * Functions in this group expect LLVMValueRef instances that correspond
1888 * to llvm::Function instances.
1889 *
1890 * @{
1891 */
1892
1893/**
1894 * Obtain the number of parameters in a function.
1895 *
1896 * @see llvm::Function::arg_size()
1897 */
1898unsigned LLVMCountParams(LLVMValueRef Fn);
1899
1900/**
1901 * Obtain the parameters in a function.
1902 *
1903 * The takes a pointer to a pre-allocated array of LLVMValueRef that is
1904 * at least LLVMCountParams() long. This array will be filled with
1905 * LLVMValueRef instances which correspond to the parameters the
1906 * function receives. Each LLVMValueRef corresponds to a llvm::Argument
1907 * instance.
1908 *
1909 * @see llvm::Function::arg_begin()
1910 */
1911void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
1912
1913/**
1914 * Obtain the parameter at the specified index.
1915 *
1916 * Parameters are indexed from 0.
1917 *
1918 * @see llvm::Function::arg_begin()
1919 */
1920LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
1921
1922/**
1923 * Obtain the function to which this argument belongs.
1924 *
1925 * Unlike other functions in this group, this one takes an LLVMValueRef
1926 * that corresponds to a llvm::Attribute.
1927 *
1928 * The returned LLVMValueRef is the llvm::Function to which this
1929 * argument belongs.
1930 */
1931LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
1932
1933/**
1934 * Obtain the first parameter to a function.
1935 *
1936 * @see llvm::Function::arg_begin()
1937 */
1938LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
1939
1940/**
1941 * Obtain the last parameter to a function.
1942 *
1943 * @see llvm::Function::arg_end()
1944 */
1945LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
1946
1947/**
1948 * Obtain the next parameter to a function.
1949 *
1950 * This takes an LLVMValueRef obtained from LLVMGetFirstParam() (which is
1951 * actually a wrapped iterator) and obtains the next parameter from the
1952 * underlying iterator.
1953 */
1954LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
1955
1956/**
1957 * Obtain the previous parameter to a function.
1958 *
1959 * This is the opposite of LLVMGetNextParam().
1960 */
1961LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
1962
1963/**
1964 * Add an attribute to a function argument.
1965 *
1966 * @see llvm::Argument::addAttr()
1967 */
1968void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1969
1970/**
1971 * Remove an attribute from a function argument.
1972 *
1973 * @see llvm::Argument::removeAttr()
1974 */
1975void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
1976
1977/**
1978 * Get an attribute from a function argument.
1979 */
1980LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
1981
1982/**
1983 * Set the alignment for a function parameter.
1984 *
1985 * @see llvm::Argument::addAttr()
1986 * @see llvm::AttrBuilder::addAlignmentAttr()
1987 */
1988void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
1989
1990/**
1991 * @}
1992 */
1993
1994/**
1995 * @}
1996 */
1997
1998/**
1999 * @}
2000 */
2001
2002/**
2003 * @}
2004 */
2005
2006/**
2007 * @defgroup LLVMCCoreValueMetadata Metadata
2008 *
2009 * @{
2010 */
2011
2012/**
2013 * Obtain a MDString value from a context.
2014 *
2015 * The returned instance corresponds to the llvm::MDString class.
2016 *
2017 * The instance is specified by string data of a specified length. The
2018 * string content is copied, so the backing memory can be freed after
2019 * this function returns.
2020 */
2021LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
2022                                   unsigned SLen);
2023
2024/**
2025 * Obtain a MDString value from the global context.
2026 */
2027LLVMValueRef LLVMMDString(const char *Str, unsigned SLen);
2028
2029/**
2030 * Obtain a MDNode value from a context.
2031 *
2032 * The returned value corresponds to the llvm::MDNode class.
2033 */
2034LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
2035                                 unsigned Count);
2036
2037/**
2038 * Obtain a MDNode value from the global context.
2039 */
2040LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
2041
2042/**
2043 * Obtain the underlying string from a MDString value.
2044 *
2045 * @param V Instance to obtain string from.
2046 * @param Len Memory address which will hold length of returned string.
2047 * @return String data in MDString.
2048 */
2049const char  *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
2050
2051/**
2052 * Obtain the number of operands from an MDNode value.
2053 *
2054 * @param V MDNode to get number of operands from.
2055 * @return Number of operands of the MDNode.
2056 */
2057unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);
2058
2059/**
2060 * Obtain the given MDNode's operands.
2061 *
2062 * The passed LLVMValueRef pointer should point to enough memory to hold all of
2063 * the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
2064 * LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
2065 * MDNode's operands.
2066 *
2067 * @param V MDNode to get the operands from.
2068 * @param Dest Destination array for operands.
2069 */
2070void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);
2071
2072/**
2073 * @}
2074 */
2075
2076/**
2077 * @defgroup LLVMCCoreValueBasicBlock Basic Block
2078 *
2079 * A basic block represents a single entry single exit section of code.
2080 * Basic blocks contain a list of instructions which form the body of
2081 * the block.
2082 *
2083 * Basic blocks belong to functions. They have the type of label.
2084 *
2085 * Basic blocks are themselves values. However, the C API models them as
2086 * LLVMBasicBlockRef.
2087 *
2088 * @see llvm::BasicBlock
2089 *
2090 * @{
2091 */
2092
2093/**
2094 * Convert a basic block instance to a value type.
2095 */
2096LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
2097
2098/**
2099 * Determine whether an LLVMValueRef is itself a basic block.
2100 */
2101LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
2102
2103/**
2104 * Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
2105 */
2106LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
2107
2108/**
2109 * Obtain the function to which a basic block belongs.
2110 *
2111 * @see llvm::BasicBlock::getParent()
2112 */
2113LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
2114
2115/**
2116 * Obtain the terminator instruction for a basic block.
2117 *
2118 * If the basic block does not have a terminator (it is not well-formed
2119 * if it doesn't), then NULL is returned.
2120 *
2121 * The returned LLVMValueRef corresponds to a llvm::TerminatorInst.
2122 *
2123 * @see llvm::BasicBlock::getTerminator()
2124 */
2125LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB);
2126
2127/**
2128 * Obtain the number of basic blocks in a function.
2129 *
2130 * @param Fn Function value to operate on.
2131 */
2132unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
2133
2134/**
2135 * Obtain all of the basic blocks in a function.
2136 *
2137 * This operates on a function value. The BasicBlocks parameter is a
2138 * pointer to a pre-allocated array of LLVMBasicBlockRef of at least
2139 * LLVMCountBasicBlocks() in length. This array is populated with
2140 * LLVMBasicBlockRef instances.
2141 */
2142void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
2143
2144/**
2145 * Obtain the first basic block in a function.
2146 *
2147 * The returned basic block can be used as an iterator. You will likely
2148 * eventually call into LLVMGetNextBasicBlock() with it.
2149 *
2150 * @see llvm::Function::begin()
2151 */
2152LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
2153
2154/**
2155 * Obtain the last basic block in a function.
2156 *
2157 * @see llvm::Function::end()
2158 */
2159LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
2160
2161/**
2162 * Advance a basic block iterator.
2163 */
2164LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
2165
2166/**
2167 * Go backwards in a basic block iterator.
2168 */
2169LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
2170
2171/**
2172 * Obtain the basic block that corresponds to the entry point of a
2173 * function.
2174 *
2175 * @see llvm::Function::getEntryBlock()
2176 */
2177LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
2178
2179/**
2180 * Append a basic block to the end of a function.
2181 *
2182 * @see llvm::BasicBlock::Create()
2183 */
2184LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
2185                                                LLVMValueRef Fn,
2186                                                const char *Name);
2187
2188/**
2189 * Append a basic block to the end of a function using the global
2190 * context.
2191 *
2192 * @see llvm::BasicBlock::Create()
2193 */
2194LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
2195
2196/**
2197 * Insert a basic block in a function before another basic block.
2198 *
2199 * The function to add to is determined by the function of the
2200 * passed basic block.
2201 *
2202 * @see llvm::BasicBlock::Create()
2203 */
2204LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
2205                                                LLVMBasicBlockRef BB,
2206                                                const char *Name);
2207
2208/**
2209 * Insert a basic block in a function using the global context.
2210 *
2211 * @see llvm::BasicBlock::Create()
2212 */
2213LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
2214                                       const char *Name);
2215
2216/**
2217 * Remove a basic block from a function and delete it.
2218 *
2219 * This deletes the basic block from its containing function and deletes
2220 * the basic block itself.
2221 *
2222 * @see llvm::BasicBlock::eraseFromParent()
2223 */
2224void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
2225
2226/**
2227 * Remove a basic block from a function.
2228 *
2229 * This deletes the basic block from its containing function but keep
2230 * the basic block alive.
2231 *
2232 * @see llvm::BasicBlock::removeFromParent()
2233 */
2234void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BB);
2235
2236/**
2237 * Move a basic block to before another one.
2238 *
2239 * @see llvm::BasicBlock::moveBefore()
2240 */
2241void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2242
2243/**
2244 * Move a basic block to after another one.
2245 *
2246 * @see llvm::BasicBlock::moveAfter()
2247 */
2248void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos);
2249
2250/**
2251 * Obtain the first instruction in a basic block.
2252 *
2253 * The returned LLVMValueRef corresponds to a llvm::Instruction
2254 * instance.
2255 */
2256LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
2257
2258/**
2259 * Obtain the last instruction in a basic block.
2260 *
2261 * The returned LLVMValueRef corresponds to an LLVM:Instruction.
2262 */
2263LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
2264
2265/**
2266 * @}
2267 */
2268
2269/**
2270 * @defgroup LLVMCCoreValueInstruction Instructions
2271 *
2272 * Functions in this group relate to the inspection and manipulation of
2273 * individual instructions.
2274 *
2275 * In the C++ API, an instruction is modeled by llvm::Instruction. This
2276 * class has a large number of descendents. llvm::Instruction is a
2277 * llvm::Value and in the C API, instructions are modeled by
2278 * LLVMValueRef.
2279 *
2280 * This group also contains sub-groups which operate on specific
2281 * llvm::Instruction types, e.g. llvm::CallInst.
2282 *
2283 * @{
2284 */
2285
2286/**
2287 * Determine whether an instruction has any metadata attached.
2288 */
2289int LLVMHasMetadata(LLVMValueRef Val);
2290
2291/**
2292 * Return metadata associated with an instruction value.
2293 */
2294LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID);
2295
2296/**
2297 * Set metadata associated with an instruction value.
2298 */
2299void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node);
2300
2301/**
2302 * Obtain the basic block to which an instruction belongs.
2303 *
2304 * @see llvm::Instruction::getParent()
2305 */
2306LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
2307
2308/**
2309 * Obtain the instruction that occurs after the one specified.
2310 *
2311 * The next instruction will be from the same basic block.
2312 *
2313 * If this is the last instruction in a basic block, NULL will be
2314 * returned.
2315 */
2316LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
2317
2318/**
2319 * Obtain the instruction that occurred before this one.
2320 *
2321 * If the instruction is the first instruction in a basic block, NULL
2322 * will be returned.
2323 */
2324LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
2325
2326/**
2327 * Remove and delete an instruction.
2328 *
2329 * The instruction specified is removed from its containing building
2330 * block and then deleted.
2331 *
2332 * @see llvm::Instruction::eraseFromParent()
2333 */
2334void LLVMInstructionEraseFromParent(LLVMValueRef Inst);
2335
2336/**
2337 * Obtain the code opcode for an individual instruction.
2338 *
2339 * @see llvm::Instruction::getOpCode()
2340 */
2341LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
2342
2343/**
2344 * Obtain the predicate of an instruction.
2345 *
2346 * This is only valid for instructions that correspond to llvm::ICmpInst
2347 * or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
2348 *
2349 * @see llvm::ICmpInst::getPredicate()
2350 */
2351LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
2352
2353/**
2354 * Obtain the float predicate of an instruction.
2355 *
2356 * This is only valid for instructions that correspond to llvm::FCmpInst
2357 * or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
2358 *
2359 * @see llvm::FCmpInst::getPredicate()
2360 */
2361LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst);
2362
2363/**
2364 * Create a copy of 'this' instruction that is identical in all ways
2365 * except the following:
2366 *   * The instruction has no parent
2367 *   * The instruction has no name
2368 *
2369 * @see llvm::Instruction::clone()
2370 */
2371LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst);
2372
2373/**
2374 * @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
2375 *
2376 * Functions in this group apply to instructions that refer to call
2377 * sites and invocations. These correspond to C++ types in the
2378 * llvm::CallInst class tree.
2379 *
2380 * @{
2381 */
2382
2383/**
2384 * Set the calling convention for a call instruction.
2385 *
2386 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
2387 * llvm::InvokeInst.
2388 *
2389 * @see llvm::CallInst::setCallingConv()
2390 * @see llvm::InvokeInst::setCallingConv()
2391 */
2392void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
2393
2394/**
2395 * Obtain the calling convention for a call instruction.
2396 *
2397 * This is the opposite of LLVMSetInstructionCallConv(). Reads its
2398 * usage.
2399 *
2400 * @see LLVMSetInstructionCallConv()
2401 */
2402unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
2403
2404
2405void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
2406void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2407                              LLVMAttribute);
2408void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2409                                unsigned align);
2410
2411/**
2412 * Obtain whether a call instruction is a tail call.
2413 *
2414 * This only works on llvm::CallInst instructions.
2415 *
2416 * @see llvm::CallInst::isTailCall()
2417 */
2418LLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
2419
2420/**
2421 * Set whether a call instruction is a tail call.
2422 *
2423 * This only works on llvm::CallInst instructions.
2424 *
2425 * @see llvm::CallInst::setTailCall()
2426 */
2427void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
2428
2429/**
2430 * @}
2431 */
2432
2433/**
2434 * @defgroup LLVMCCoreValueInstructionTerminator Terminators
2435 *
2436 * Functions in this group only apply to instructions that map to
2437 * llvm::TerminatorInst instances.
2438 *
2439 * @{
2440 */
2441
2442/**
2443 * Return the number of successors that this terminator has.
2444 *
2445 * @see llvm::TerminatorInst::getNumSuccessors
2446 */
2447unsigned LLVMGetNumSuccessors(LLVMValueRef Term);
2448
2449/**
2450 * Return the specified successor.
2451 *
2452 * @see llvm::TerminatorInst::getSuccessor
2453 */
2454LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i);
2455
2456/**
2457 * Update the specified successor to point at the provided block.
2458 *
2459 * @see llvm::TerminatorInst::setSuccessor
2460 */
2461void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block);
2462
2463/**
2464 * Return if a branch is conditional.
2465 *
2466 * This only works on llvm::BranchInst instructions.
2467 *
2468 * @see llvm::BranchInst::isConditional
2469 */
2470LLVMBool LLVMIsConditional(LLVMValueRef Branch);
2471
2472/**
2473 * Return the condition of a branch instruction.
2474 *
2475 * This only works on llvm::BranchInst instructions.
2476 *
2477 * @see llvm::BranchInst::getCondition
2478 */
2479LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
2480
2481/**
2482 * Set the condition of a branch instruction.
2483 *
2484 * This only works on llvm::BranchInst instructions.
2485 *
2486 * @see llvm::BranchInst::setCondition
2487 */
2488void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
2489
2490/**
2491 * Obtain the default destination basic block of a switch instruction.
2492 *
2493 * This only works on llvm::SwitchInst instructions.
2494 *
2495 * @see llvm::SwitchInst::getDefaultDest()
2496 */
2497LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
2498
2499/**
2500 * @}
2501 */
2502
2503/**
2504 * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
2505 *
2506 * Functions in this group only apply to instructions that map to
2507 * llvm::PHINode instances.
2508 *
2509 * @{
2510 */
2511
2512/**
2513 * Add an incoming value to the end of a PHI list.
2514 */
2515void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2516                     LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
2517
2518/**
2519 * Obtain the number of incoming basic blocks to a PHI node.
2520 */
2521unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
2522
2523/**
2524 * Obtain an incoming value to a PHI node as an LLVMValueRef.
2525 */
2526LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
2527
2528/**
2529 * Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
2530 */
2531LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
2532
2533/**
2534 * @}
2535 */
2536
2537/**
2538 * @}
2539 */
2540
2541/**
2542 * @}
2543 */
2544
2545/**
2546 * @defgroup LLVMCCoreInstructionBuilder Instruction Builders
2547 *
2548 * An instruction builder represents a point within a basic block and is
2549 * the exclusive means of building instructions using the C interface.
2550 *
2551 * @{
2552 */
2553
2554LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
2555LLVMBuilderRef LLVMCreateBuilder(void);
2556void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2557                         LLVMValueRef Instr);
2558void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
2559void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
2560LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
2561void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
2562void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
2563void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2564                                   const char *Name);
2565void LLVMDisposeBuilder(LLVMBuilderRef Builder);
2566
2567/* Metadata */
2568void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
2569LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
2570void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
2571
2572/* Terminators */
2573LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
2574LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
2575LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
2576                                   unsigned N);
2577LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
2578LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
2579                             LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
2580LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
2581                             LLVMBasicBlockRef Else, unsigned NumCases);
2582LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2583                                 unsigned NumDests);
2584LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
2585                             LLVMValueRef *Args, unsigned NumArgs,
2586                             LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2587                             const char *Name);
2588LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2589                                 LLVMValueRef PersFn, unsigned NumClauses,
2590                                 const char *Name);
2591LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn);
2592LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
2593
2594/* Add a case to the switch instruction */
2595void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2596                 LLVMBasicBlockRef Dest);
2597
2598/* Add a destination to the indirectbr instruction */
2599void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest);
2600
2601/* Add a catch or filter clause to the landingpad instruction */
2602void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal);
2603
2604/* Set the 'cleanup' flag in the landingpad instruction */
2605void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val);
2606
2607/* Arithmetic */
2608LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2609                          const char *Name);
2610LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2611                             const char *Name);
2612LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2613                             const char *Name);
2614LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2615                           const char *Name);
2616LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2617                          const char *Name);
2618LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2619                             const char *Name);
2620LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2621                             const char *Name);
2622LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2623                           const char *Name);
2624LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2625                          const char *Name);
2626LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2627                             const char *Name);
2628LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2629                             const char *Name);
2630LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2631                           const char *Name);
2632LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2633                           const char *Name);
2634LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2635                           const char *Name);
2636LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2637                                const char *Name);
2638LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2639                           const char *Name);
2640LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2641                           const char *Name);
2642LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2643                           const char *Name);
2644LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2645                           const char *Name);
2646LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2647                           const char *Name);
2648LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2649                           const char *Name);
2650LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2651                           const char *Name);
2652LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2653                          const char *Name);
2654LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2655                          const char *Name);
2656LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
2657                          const char *Name);
2658LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2659                            LLVMValueRef LHS, LLVMValueRef RHS,
2660                            const char *Name);
2661LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2662LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2663                             const char *Name);
2664LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2665                             const char *Name);
2666LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2667LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
2668
2669/* Memory */
2670LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2671LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
2672                                  LLVMValueRef Val, const char *Name);
2673LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2674LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
2675                                  LLVMValueRef Val, const char *Name);
2676LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
2677LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
2678                           const char *Name);
2679LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
2680LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2681                          LLVMValueRef *Indices, unsigned NumIndices,
2682                          const char *Name);
2683LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2684                                  LLVMValueRef *Indices, unsigned NumIndices,
2685                                  const char *Name);
2686LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2687                                unsigned Idx, const char *Name);
2688LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2689                                   const char *Name);
2690LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2691                                      const char *Name);
2692LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);
2693void LLVMSetVolatile(LLVMValueRef MemoryAccessInst, LLVMBool IsVolatile);
2694LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemoryAccessInst);
2695void LLVMSetOrdering(LLVMValueRef MemoryAccessInst, LLVMAtomicOrdering Ordering);
2696
2697/* Casts */
2698LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
2699                            LLVMTypeRef DestTy, const char *Name);
2700LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
2701                           LLVMTypeRef DestTy, const char *Name);
2702LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
2703                           LLVMTypeRef DestTy, const char *Name);
2704LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
2705                             LLVMTypeRef DestTy, const char *Name);
2706LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
2707                             LLVMTypeRef DestTy, const char *Name);
2708LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
2709                             LLVMTypeRef DestTy, const char *Name);
2710LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
2711                             LLVMTypeRef DestTy, const char *Name);
2712LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
2713                              LLVMTypeRef DestTy, const char *Name);
2714LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
2715                            LLVMTypeRef DestTy, const char *Name);
2716LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
2717                               LLVMTypeRef DestTy, const char *Name);
2718LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
2719                               LLVMTypeRef DestTy, const char *Name);
2720LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
2721                              LLVMTypeRef DestTy, const char *Name);
2722LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2723                                    LLVMTypeRef DestTy, const char *Name);
2724LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2725                                    LLVMTypeRef DestTy, const char *Name);
2726LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2727                                    LLVMTypeRef DestTy, const char *Name);
2728LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
2729                                     LLVMTypeRef DestTy, const char *Name);
2730LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2731                           LLVMTypeRef DestTy, const char *Name);
2732LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
2733                                  LLVMTypeRef DestTy, const char *Name);
2734LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
2735                              LLVMTypeRef DestTy, const char *Name);
2736LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
2737                             LLVMTypeRef DestTy, const char *Name);
2738
2739/* Comparisons */
2740LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
2741                           LLVMValueRef LHS, LLVMValueRef RHS,
2742                           const char *Name);
2743LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
2744                           LLVMValueRef LHS, LLVMValueRef RHS,
2745                           const char *Name);
2746
2747/* Miscellaneous instructions */
2748LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
2749LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
2750                           LLVMValueRef *Args, unsigned NumArgs,
2751                           const char *Name);
2752LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
2753                             LLVMValueRef Then, LLVMValueRef Else,
2754                             const char *Name);
2755LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
2756                            const char *Name);
2757LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
2758                                     LLVMValueRef Index, const char *Name);
2759LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
2760                                    LLVMValueRef EltVal, LLVMValueRef Index,
2761                                    const char *Name);
2762LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
2763                                    LLVMValueRef V2, LLVMValueRef Mask,
2764                                    const char *Name);
2765LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
2766                                   unsigned Index, const char *Name);
2767LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
2768                                  LLVMValueRef EltVal, unsigned Index,
2769                                  const char *Name);
2770
2771LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
2772                             const char *Name);
2773LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
2774                                const char *Name);
2775LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
2776                              LLVMValueRef RHS, const char *Name);
2777LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering ordering,
2778                            LLVMBool singleThread, const char *Name);
2779LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op,
2780                                LLVMValueRef PTR, LLVMValueRef Val,
2781                                LLVMAtomicOrdering ordering,
2782                                LLVMBool singleThread);
2783
2784/**
2785 * @}
2786 */
2787
2788/**
2789 * @defgroup LLVMCCoreModuleProvider Module Providers
2790 *
2791 * @{
2792 */
2793
2794/**
2795 * Changes the type of M so it can be passed to FunctionPassManagers and the
2796 * JIT.  They take ModuleProviders for historical reasons.
2797 */
2798LLVMModuleProviderRef
2799LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
2800
2801/**
2802 * Destroys the module M.
2803 */
2804void LLVMDisposeModuleProvider(LLVMModuleProviderRef M);
2805
2806/**
2807 * @}
2808 */
2809
2810/**
2811 * @defgroup LLVMCCoreMemoryBuffers Memory Buffers
2812 *
2813 * @{
2814 */
2815
2816LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
2817                                                  LLVMMemoryBufferRef *OutMemBuf,
2818                                                  char **OutMessage);
2819LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2820                                         char **OutMessage);
2821LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
2822                                                          size_t InputDataLength,
2823                                                          const char *BufferName,
2824                                                          LLVMBool RequiresNullTerminator);
2825LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
2826                                                              size_t InputDataLength,
2827                                                              const char *BufferName);
2828const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf);
2829size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf);
2830void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
2831
2832/**
2833 * @}
2834 */
2835
2836/**
2837 * @defgroup LLVMCCorePassRegistry Pass Registry
2838 *
2839 * @{
2840 */
2841
2842/** Return the global pass registry, for use with initialization functions.
2843    @see llvm::PassRegistry::getPassRegistry */
2844LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void);
2845
2846/**
2847 * @}
2848 */
2849
2850/**
2851 * @defgroup LLVMCCorePassManagers Pass Managers
2852 *
2853 * @{
2854 */
2855
2856/** Constructs a new whole-module pass pipeline. This type of pipeline is
2857    suitable for link-time optimization and whole-module transformations.
2858    @see llvm::PassManager::PassManager */
2859LLVMPassManagerRef LLVMCreatePassManager(void);
2860
2861/** Constructs a new function-by-function pass pipeline over the module
2862    provider. It does not take ownership of the module provider. This type of
2863    pipeline is suitable for code generation and JIT compilation tasks.
2864    @see llvm::FunctionPassManager::FunctionPassManager */
2865LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M);
2866
2867/** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */
2868LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
2869
2870/** Initializes, executes on the provided module, and finalizes all of the
2871    passes scheduled in the pass manager. Returns 1 if any of the passes
2872    modified the module, 0 otherwise.
2873    @see llvm::PassManager::run(Module&) */
2874LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
2875
2876/** Initializes all of the function passes scheduled in the function pass
2877    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2878    @see llvm::FunctionPassManager::doInitialization */
2879LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
2880
2881/** Executes all of the function passes scheduled in the function pass manager
2882    on the provided function. Returns 1 if any of the passes modified the
2883    function, false otherwise.
2884    @see llvm::FunctionPassManager::run(Function&) */
2885LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
2886
2887/** Finalizes all of the function passes scheduled in in the function pass
2888    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
2889    @see llvm::FunctionPassManager::doFinalization */
2890LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
2891
2892/** Frees the memory of a pass pipeline. For function pipelines, does not free
2893    the module provider.
2894    @see llvm::PassManagerBase::~PassManagerBase. */
2895void LLVMDisposePassManager(LLVMPassManagerRef PM);
2896
2897/**
2898 * @}
2899 */
2900
2901/**
2902 * @defgroup LLVMCCoreThreading Threading
2903 *
2904 * Handle the structures needed to make LLVM safe for multithreading.
2905 *
2906 * @{
2907 */
2908
2909/** Deprecated: Multi-threading can only be enabled/disabled with the compile
2910    time define LLVM_ENABLE_THREADS.  This function always returns
2911    LLVMIsMultithreaded(). */
2912LLVMBool LLVMStartMultithreaded(void);
2913
2914/** Deprecated: Multi-threading can only be enabled/disabled with the compile
2915    time define LLVM_ENABLE_THREADS. */
2916void LLVMStopMultithreaded(void);
2917
2918/** Check whether LLVM is executing in thread-safe mode or not.
2919    @see llvm::llvm_is_multithreaded */
2920LLVMBool LLVMIsMultithreaded(void);
2921
2922/**
2923 * @}
2924 */
2925
2926/**
2927 * @}
2928 */
2929
2930/**
2931 * @}
2932 */
2933
2934#ifdef __cplusplus
2935}
2936#endif
2937
2938#endif /* LLVM_C_CORE_H */
2939