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