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