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