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