1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![allow(non_uppercase_pattern_statics)]
12 #![allow(non_camel_case_types)]
13 #![allow(non_snake_case_functions)]
16 #![crate_name = "rustc_llvm"]
18 #![license = "MIT/ASL2"]
19 #![crate_type = "dylib"]
20 #![crate_type = "rlib"]
21 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
22 html_favicon_url = "http://www.rust-lang.org/favicon.ico",
23 html_root_url = "http://doc.rust-lang.org/")]
26 #![feature(link_args)]
30 use std::c_str::ToCStr;
31 use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
32 use libc::{c_longlong, c_ulonglong};
33 use debuginfo::{DIBuilderRef, DIDescriptor,
34 DIFile, DILexicalBlock, DISubprogram, DIType,
35 DIBasicType, DIDerivedType, DICompositeType,
36 DIVariable, DIGlobalVariable, DIArray, DISubrange};
40 pub type Opcode = u32;
41 pub type Bool = c_uint;
43 pub static True: Bool = 1 as Bool;
44 pub static False: Bool = 0 as Bool;
46 // Consts for the LLVM CallConv type, pre-cast to uint.
48 #[deriving(PartialEq)]
53 X86StdcallCallConv = 64,
54 X86FastcallCallConv = 65,
59 LLVMDefaultVisibility = 0,
61 ProtectedVisibility = 2,
64 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
65 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
66 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
67 // they've been removed in upstream LLVM commit r203866.
70 AvailableExternallyLinkage = 1,
71 LinkOnceAnyLinkage = 2,
72 LinkOnceODRLinkage = 3,
78 ExternalWeakLinkage = 12,
84 ZExtAttribute = 1 << 0,
85 SExtAttribute = 1 << 1,
86 NoReturnAttribute = 1 << 2,
87 InRegAttribute = 1 << 3,
88 StructRetAttribute = 1 << 4,
89 NoUnwindAttribute = 1 << 5,
90 NoAliasAttribute = 1 << 6,
91 ByValAttribute = 1 << 7,
92 NestAttribute = 1 << 8,
93 ReadNoneAttribute = 1 << 9,
94 ReadOnlyAttribute = 1 << 10,
95 NoInlineAttribute = 1 << 11,
96 AlwaysInlineAttribute = 1 << 12,
97 OptimizeForSizeAttribute = 1 << 13,
98 StackProtectAttribute = 1 << 14,
99 StackProtectReqAttribute = 1 << 15,
100 AlignmentAttribute = 31 << 16,
101 NoCaptureAttribute = 1 << 21,
102 NoRedZoneAttribute = 1 << 22,
103 NoImplicitFloatAttribute = 1 << 23,
104 NakedAttribute = 1 << 24,
105 InlineHintAttribute = 1 << 25,
106 StackAttribute = 7 << 26,
107 ReturnsTwiceAttribute = 1 << 29,
108 UWTableAttribute = 1 << 30,
109 NonLazyBindAttribute = 1 << 31,
113 pub enum OtherAttribute {
114 // The following are not really exposed in
115 // the LLVM c api so instead to add these
116 // we call a wrapper function in RustWrapper
117 // that uses the C++ api.
118 SanitizeAddressAttribute = 1 << 32,
119 MinSizeAttribute = 1 << 33,
120 NoDuplicateAttribute = 1 << 34,
121 StackProtectStrongAttribute = 1 << 35,
122 SanitizeThreadAttribute = 1 << 36,
123 SanitizeMemoryAttribute = 1 << 37,
124 NoBuiltinAttribute = 1 << 38,
125 ReturnedAttribute = 1 << 39,
126 ColdAttribute = 1 << 40,
127 BuiltinAttribute = 1 << 41,
128 OptimizeNoneAttribute = 1 << 42,
129 InAllocaAttribute = 1 << 43,
130 NonNullAttribute = 1 << 44,
133 pub enum SpecialAttribute {
134 DereferenceableAttribute(u64)
138 pub enum AttributeSet {
144 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
145 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
148 impl AttrHelper for Attribute {
149 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
151 LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
155 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
157 LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
162 impl AttrHelper for OtherAttribute {
163 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
165 LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
169 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
171 LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
176 impl AttrHelper for SpecialAttribute {
177 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
179 DereferenceableAttribute(bytes) => unsafe {
180 LLVMAddDereferenceableAttr(llfn, idx, bytes as uint64_t);
185 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
187 DereferenceableAttribute(bytes) => unsafe {
188 LLVMAddDereferenceableCallSiteAttr(callsite, idx, bytes as uint64_t);
194 pub struct AttrBuilder {
195 attrs: Vec<(uint, Box<AttrHelper+'static>)>
199 pub fn new() -> AttrBuilder {
205 pub fn arg<'a, T: AttrHelper + 'static>(&'a mut self, idx: uint, a: T) -> &'a mut AttrBuilder {
206 self.attrs.push((idx, box a as Box<AttrHelper+'static>));
210 pub fn ret<'a, T: AttrHelper + 'static>(&'a mut self, a: T) -> &'a mut AttrBuilder {
211 self.attrs.push((ReturnIndex as uint, box a as Box<AttrHelper+'static>));
215 pub fn apply_llfn(&self, llfn: ValueRef) {
216 for &(idx, ref attr) in self.attrs.iter() {
217 attr.apply_llfn(idx as c_uint, llfn);
221 pub fn apply_callsite(&self, callsite: ValueRef) {
222 for &(idx, ref attr) in self.attrs.iter() {
223 attr.apply_callsite(idx as c_uint, callsite);
228 // enum for the LLVM IntPredicate type
229 pub enum IntPredicate {
242 // enum for the LLVM RealPredicate type
243 pub enum RealPredicate {
244 RealPredicateFalse = 0,
259 RealPredicateTrue = 15,
262 // The LLVM TypeKind type - must stay in sync with the def of
263 // LLVMTypeKind in llvm/include/llvm-c/Core.h
264 #[deriving(PartialEq)]
286 pub enum AtomicBinOp {
301 pub enum AtomicOrdering {
305 // Consume = 3, // Not specified yet.
309 SequentiallyConsistent = 7
312 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
328 // Inline Asm Dialect
329 pub enum AsmDialect {
334 #[deriving(PartialEq)]
336 pub enum CodeGenOptLevel {
337 CodeGenLevelNone = 0,
338 CodeGenLevelLess = 1,
339 CodeGenLevelDefault = 2,
340 CodeGenLevelAggressive = 3,
348 RelocDynamicNoPic = 3,
352 pub enum CodeGenModel {
353 CodeModelDefault = 0,
354 CodeModelJITDefault = 1,
361 // Opaque pointer types
362 pub enum Module_opaque {}
363 pub type ModuleRef = *mut Module_opaque;
364 pub enum Context_opaque {}
365 pub type ContextRef = *mut Context_opaque;
366 pub enum Type_opaque {}
367 pub type TypeRef = *mut Type_opaque;
368 pub enum Value_opaque {}
369 pub type ValueRef = *mut Value_opaque;
370 pub enum BasicBlock_opaque {}
371 pub type BasicBlockRef = *mut BasicBlock_opaque;
372 pub enum Builder_opaque {}
373 pub type BuilderRef = *mut Builder_opaque;
374 pub enum ExecutionEngine_opaque {}
375 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
376 pub enum MemoryBuffer_opaque {}
377 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
378 pub enum PassManager_opaque {}
379 pub type PassManagerRef = *mut PassManager_opaque;
380 pub enum PassManagerBuilder_opaque {}
381 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
382 pub enum Use_opaque {}
383 pub type UseRef = *mut Use_opaque;
384 pub enum TargetData_opaque {}
385 pub type TargetDataRef = *mut TargetData_opaque;
386 pub enum ObjectFile_opaque {}
387 pub type ObjectFileRef = *mut ObjectFile_opaque;
388 pub enum SectionIterator_opaque {}
389 pub type SectionIteratorRef = *mut SectionIterator_opaque;
390 pub enum Pass_opaque {}
391 pub type PassRef = *mut Pass_opaque;
392 pub enum TargetMachine_opaque {}
393 pub type TargetMachineRef = *mut TargetMachine_opaque;
394 pub enum Archive_opaque {}
395 pub type ArchiveRef = *mut Archive_opaque;
398 use super::{ValueRef};
400 pub enum DIBuilder_opaque {}
401 pub type DIBuilderRef = *mut DIBuilder_opaque;
403 pub type DIDescriptor = ValueRef;
404 pub type DIScope = DIDescriptor;
405 pub type DILocation = DIDescriptor;
406 pub type DIFile = DIScope;
407 pub type DILexicalBlock = DIScope;
408 pub type DISubprogram = DIScope;
409 pub type DIType = DIDescriptor;
410 pub type DIBasicType = DIType;
411 pub type DIDerivedType = DIType;
412 pub type DICompositeType = DIDerivedType;
413 pub type DIVariable = DIDescriptor;
414 pub type DIGlobalVariable = DIDescriptor;
415 pub type DIArray = DIDescriptor;
416 pub type DISubrange = DIDescriptor;
418 pub enum DIDescriptorFlags {
419 FlagPrivate = 1 << 0,
420 FlagProtected = 1 << 1,
421 FlagFwdDecl = 1 << 2,
422 FlagAppleBlock = 1 << 3,
423 FlagBlockByrefStruct = 1 << 4,
424 FlagVirtual = 1 << 5,
425 FlagArtificial = 1 << 6,
426 FlagExplicit = 1 << 7,
427 FlagPrototyped = 1 << 8,
428 FlagObjcClassComplete = 1 << 9,
429 FlagObjectPointer = 1 << 10,
430 FlagVector = 1 << 11,
431 FlagStaticMember = 1 << 12
436 // Link to our native llvm bindings (things that we need to use the C++ api
437 // for) and because llvm is written in C++ we need to link against libstdc++
439 // You'll probably notice that there is an omission of all LLVM libraries
440 // from this location. This is because the set of LLVM libraries that we
441 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
442 // figure out the exact set of libraries. To do this, the build system
443 // generates an llvmdeps.rs file next to this one which will be
444 // automatically updated whenever LLVM is updated to include an up-to-date
445 // set of the libraries we need to link to LLVM for.
446 #[link(name = "rustllvm", kind = "static")]
448 /* Create and destroy contexts. */
449 pub fn LLVMContextCreate() -> ContextRef;
450 pub fn LLVMContextDispose(C: ContextRef);
451 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
456 /* Create and destroy modules. */
457 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
460 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
461 pub fn LLVMDisposeModule(M: ModuleRef);
463 /** Data layout. See Module::getDataLayout. */
464 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
465 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
467 /** Target triple. See Module::getTargetTriple. */
468 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
469 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
471 /** See Module::dump. */
472 pub fn LLVMDumpModule(M: ModuleRef);
474 /** See Module::setModuleInlineAsm. */
475 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
477 /** See llvm::LLVMTypeKind::getTypeID. */
478 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
480 /** See llvm::LLVMType::getContext. */
481 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
483 /* Operations on integer types */
484 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
485 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
486 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
487 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
488 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
489 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
492 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
494 /* Operations on real types */
495 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
496 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
497 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
498 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
499 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
501 /* Operations on function types */
502 pub fn LLVMFunctionType(ReturnType: TypeRef,
503 ParamTypes: *const TypeRef,
507 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
508 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
509 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
510 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *const TypeRef);
512 /* Operations on struct types */
513 pub fn LLVMStructTypeInContext(C: ContextRef,
514 ElementTypes: *const TypeRef,
515 ElementCount: c_uint,
518 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
519 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
521 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
523 /* Operations on array, pointer, and vector types (sequence types) */
524 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
525 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
527 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
530 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
531 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
532 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
533 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
535 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
537 /* Operations on other types */
538 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
539 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
540 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
542 /* Operations on all values */
543 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
544 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
545 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
546 pub fn LLVMDumpValue(Val: ValueRef);
547 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
548 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
549 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
550 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
552 /* Operations on Uses */
553 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
554 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
555 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
556 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
558 /* Operations on Users */
559 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
560 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
561 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
563 /* Operations on constants of any type */
564 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
566 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
567 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
569 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
571 /* only for int/vector */
572 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
573 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
574 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
575 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
576 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
578 /* Operations on metadata */
579 pub fn LLVMMDStringInContext(C: ContextRef,
583 pub fn LLVMMDNodeInContext(C: ContextRef,
584 Vals: *const ValueRef,
587 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
591 /* Operations on scalar constants */
592 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
594 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
596 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
601 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
602 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
604 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
608 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
609 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
612 /* Operations on composite constants */
613 pub fn LLVMConstStringInContext(C: ContextRef,
616 DontNullTerminate: Bool)
618 pub fn LLVMConstStructInContext(C: ContextRef,
619 ConstantVals: *const ValueRef,
624 pub fn LLVMConstArray(ElementTy: TypeRef,
625 ConstantVals: *const ValueRef,
628 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
631 /* Constant expressions */
632 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
633 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
634 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
635 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
636 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
637 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
638 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
639 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
641 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
643 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
645 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
647 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
649 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
651 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
653 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
655 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
657 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
659 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
661 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
663 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
665 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
667 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
668 RHSConstant: ValueRef)
670 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
672 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
674 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
676 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
678 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
680 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
682 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
684 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
686 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
688 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
690 pub fn LLVMConstGEP(ConstantVal: ValueRef,
691 ConstantIndices: *const ValueRef,
694 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
695 ConstantIndices: *const ValueRef,
698 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
700 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
702 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
704 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
706 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
708 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
710 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
712 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
714 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
716 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
718 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
720 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
722 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
724 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
726 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
728 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
730 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
734 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
736 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
737 ConstantIfTrue: ValueRef,
738 ConstantIfFalse: ValueRef)
740 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
741 IndexConstant: ValueRef)
743 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
744 ElementValueConstant: ValueRef,
745 IndexConstant: ValueRef)
747 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
748 VectorBConstant: ValueRef,
749 MaskConstant: ValueRef)
751 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
752 IdxList: *const c_uint,
755 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
756 ElementValueConstant: ValueRef,
757 IdxList: *const c_uint,
760 pub fn LLVMConstInlineAsm(Ty: TypeRef,
761 AsmString: *const c_char,
762 Constraints: *const c_char,
763 HasSideEffects: Bool,
766 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
770 /* Operations on global variables, functions, and aliases (globals) */
771 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
772 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
773 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
774 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
775 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
776 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
777 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
778 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
779 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
780 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
783 /* Operations on global variables */
784 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
786 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
789 AddressSpace: c_uint)
791 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
792 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
793 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
794 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
795 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
796 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
797 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
798 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
799 ConstantVal: ValueRef);
800 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
801 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
802 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
803 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
805 /* Operations on aliases */
806 pub fn LLVMAddAlias(M: ModuleRef,
812 /* Operations on functions */
813 pub fn LLVMAddFunction(M: ModuleRef,
817 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
818 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
819 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
820 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
821 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
822 pub fn LLVMDeleteFunction(Fn: ValueRef);
823 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
827 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
828 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
829 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
830 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
831 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
832 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
833 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
834 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
835 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
836 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
838 /* Operations on parameters */
839 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
840 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
841 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
842 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
843 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
844 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
845 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
846 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
847 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
848 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
849 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
850 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
852 /* Operations on basic blocks */
853 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
854 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
855 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
856 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
857 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
858 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
859 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
860 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
861 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
862 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
863 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
865 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
869 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
873 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
875 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
876 MoveAfter: BasicBlockRef);
878 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
879 MoveBefore: BasicBlockRef);
881 /* Operations on instructions */
882 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
883 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
884 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
885 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
886 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
887 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
889 /* Operations on call sites */
890 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
891 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
892 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
895 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
898 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
901 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
904 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
908 /* Operations on call instructions (only) */
909 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
910 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
912 /* Operations on load/store instructions (only) */
913 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
914 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
916 /* Operations on phi nodes */
917 pub fn LLVMAddIncoming(PhiNode: ValueRef,
918 IncomingValues: *const ValueRef,
919 IncomingBlocks: *const BasicBlockRef,
921 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
922 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
924 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
927 /* Instruction builders */
928 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
929 pub fn LLVMPositionBuilder(Builder: BuilderRef,
930 Block: BasicBlockRef,
932 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
934 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
935 Block: BasicBlockRef);
936 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
937 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
938 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
939 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
941 Name: *const c_char);
942 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
943 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
946 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
947 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
948 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
951 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
952 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
953 pub fn LLVMBuildAggregateRet(B: BuilderRef,
954 RetVals: *const ValueRef,
957 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
958 pub fn LLVMBuildCondBr(B: BuilderRef,
963 pub fn LLVMBuildSwitch(B: BuilderRef,
968 pub fn LLVMBuildIndirectBr(B: BuilderRef,
972 pub fn LLVMBuildInvoke(B: BuilderRef,
974 Args: *const ValueRef,
977 Catch: BasicBlockRef,
980 pub fn LLVMBuildLandingPad(B: BuilderRef,
986 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
987 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
989 /* Add a case to the switch instruction */
990 pub fn LLVMAddCase(Switch: ValueRef,
992 Dest: BasicBlockRef);
994 /* Add a destination to the indirectbr instruction */
995 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
997 /* Add a clause to the landing pad instruction */
998 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1000 /* Set the cleanup on a landing pad instruction */
1001 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1004 pub fn LLVMBuildAdd(B: BuilderRef,
1007 Name: *const c_char)
1009 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1012 Name: *const c_char)
1014 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1017 Name: *const c_char)
1019 pub fn LLVMBuildFAdd(B: BuilderRef,
1022 Name: *const c_char)
1024 pub fn LLVMBuildSub(B: BuilderRef,
1027 Name: *const c_char)
1029 pub fn LLVMBuildNSWSub(B: BuilderRef,
1032 Name: *const c_char)
1034 pub fn LLVMBuildNUWSub(B: BuilderRef,
1037 Name: *const c_char)
1039 pub fn LLVMBuildFSub(B: BuilderRef,
1042 Name: *const c_char)
1044 pub fn LLVMBuildMul(B: BuilderRef,
1047 Name: *const c_char)
1049 pub fn LLVMBuildNSWMul(B: BuilderRef,
1052 Name: *const c_char)
1054 pub fn LLVMBuildNUWMul(B: BuilderRef,
1057 Name: *const c_char)
1059 pub fn LLVMBuildFMul(B: BuilderRef,
1062 Name: *const c_char)
1064 pub fn LLVMBuildUDiv(B: BuilderRef,
1067 Name: *const c_char)
1069 pub fn LLVMBuildSDiv(B: BuilderRef,
1072 Name: *const c_char)
1074 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1077 Name: *const c_char)
1079 pub fn LLVMBuildFDiv(B: BuilderRef,
1082 Name: *const c_char)
1084 pub fn LLVMBuildURem(B: BuilderRef,
1087 Name: *const c_char)
1089 pub fn LLVMBuildSRem(B: BuilderRef,
1092 Name: *const c_char)
1094 pub fn LLVMBuildFRem(B: BuilderRef,
1097 Name: *const c_char)
1099 pub fn LLVMBuildShl(B: BuilderRef,
1102 Name: *const c_char)
1104 pub fn LLVMBuildLShr(B: BuilderRef,
1107 Name: *const c_char)
1109 pub fn LLVMBuildAShr(B: BuilderRef,
1112 Name: *const c_char)
1114 pub fn LLVMBuildAnd(B: BuilderRef,
1117 Name: *const c_char)
1119 pub fn LLVMBuildOr(B: BuilderRef,
1122 Name: *const c_char)
1124 pub fn LLVMBuildXor(B: BuilderRef,
1127 Name: *const c_char)
1129 pub fn LLVMBuildBinOp(B: BuilderRef,
1133 Name: *const c_char)
1135 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1137 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1139 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1141 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1143 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1147 pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1149 pub fn LLVMBuildArrayMalloc(B: BuilderRef,
1152 Name: *const c_char)
1154 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1156 pub fn LLVMBuildArrayAlloca(B: BuilderRef,
1159 Name: *const c_char)
1161 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1162 pub fn LLVMBuildLoad(B: BuilderRef,
1163 PointerVal: ValueRef,
1164 Name: *const c_char)
1167 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1170 pub fn LLVMBuildGEP(B: BuilderRef,
1172 Indices: *const ValueRef,
1174 Name: *const c_char)
1176 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1178 Indices: *const ValueRef,
1180 Name: *const c_char)
1182 pub fn LLVMBuildStructGEP(B: BuilderRef,
1185 Name: *const c_char)
1187 pub fn LLVMBuildGlobalString(B: BuilderRef,
1189 Name: *const c_char)
1191 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1193 Name: *const c_char)
1197 pub fn LLVMBuildTrunc(B: BuilderRef,
1200 Name: *const c_char)
1202 pub fn LLVMBuildZExt(B: BuilderRef,
1205 Name: *const c_char)
1207 pub fn LLVMBuildSExt(B: BuilderRef,
1210 Name: *const c_char)
1212 pub fn LLVMBuildFPToUI(B: BuilderRef,
1215 Name: *const c_char)
1217 pub fn LLVMBuildFPToSI(B: BuilderRef,
1220 Name: *const c_char)
1222 pub fn LLVMBuildUIToFP(B: BuilderRef,
1225 Name: *const c_char)
1227 pub fn LLVMBuildSIToFP(B: BuilderRef,
1230 Name: *const c_char)
1232 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1235 Name: *const c_char)
1237 pub fn LLVMBuildFPExt(B: BuilderRef,
1240 Name: *const c_char)
1242 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1245 Name: *const c_char)
1247 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1250 Name: *const c_char)
1252 pub fn LLVMBuildBitCast(B: BuilderRef,
1255 Name: *const c_char)
1257 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1260 Name: *const c_char)
1262 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1265 Name: *const c_char)
1267 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1270 Name: *const c_char)
1272 pub fn LLVMBuildCast(B: BuilderRef,
1276 Name: *const c_char) -> ValueRef;
1277 pub fn LLVMBuildPointerCast(B: BuilderRef,
1280 Name: *const c_char)
1282 pub fn LLVMBuildIntCast(B: BuilderRef,
1285 Name: *const c_char)
1287 pub fn LLVMBuildFPCast(B: BuilderRef,
1290 Name: *const c_char)
1294 pub fn LLVMBuildICmp(B: BuilderRef,
1298 Name: *const c_char)
1300 pub fn LLVMBuildFCmp(B: BuilderRef,
1304 Name: *const c_char)
1307 /* Miscellaneous instructions */
1308 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1310 pub fn LLVMBuildCall(B: BuilderRef,
1312 Args: *const ValueRef,
1314 Name: *const c_char)
1316 pub fn LLVMBuildSelect(B: BuilderRef,
1320 Name: *const c_char)
1322 pub fn LLVMBuildVAArg(B: BuilderRef,
1325 Name: *const c_char)
1327 pub fn LLVMBuildExtractElement(B: BuilderRef,
1330 Name: *const c_char)
1332 pub fn LLVMBuildInsertElement(B: BuilderRef,
1336 Name: *const c_char)
1338 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1342 Name: *const c_char)
1344 pub fn LLVMBuildExtractValue(B: BuilderRef,
1347 Name: *const c_char)
1349 pub fn LLVMBuildInsertValue(B: BuilderRef,
1353 Name: *const c_char)
1356 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1358 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1360 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1363 Name: *const c_char)
1366 /* Atomic Operations */
1367 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1368 PointerVal: ValueRef,
1369 Name: *const c_char,
1370 Order: AtomicOrdering,
1374 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1377 Order: AtomicOrdering,
1381 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1385 Order: AtomicOrdering,
1386 FailureOrder: AtomicOrdering)
1388 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1392 Order: AtomicOrdering,
1393 SingleThreaded: Bool)
1396 pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1399 /* Selected entries from the downcasts. */
1400 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1401 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1403 /** Writes a module to the specified path. Returns 0 on success. */
1404 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1406 /** Creates target data from a target layout string. */
1407 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1408 /// Adds the target data to the given pass manager. The pass manager
1409 /// references the target data only weakly.
1410 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1411 /** Number of bytes clobbered when doing a Store to *T. */
1412 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1415 /** Number of bytes clobbered when doing a Store to *T. */
1416 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1419 /** Distance between successive elements in an array of T.
1420 Includes ABI padding. */
1421 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1423 /** Returns the preferred alignment of a type. */
1424 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1426 /** Returns the minimum alignment of a type. */
1427 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1430 /// Computes the byte offset of the indexed struct element for a
1432 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1438 * Returns the minimum alignment of a type when part of a call frame.
1440 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1443 /** Disposes target data. */
1444 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1446 /** Creates a pass manager. */
1447 pub fn LLVMCreatePassManager() -> PassManagerRef;
1449 /** Creates a function-by-function pass manager */
1450 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1453 /** Disposes a pass manager. */
1454 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1456 /** Runs a pass manager on a module. */
1457 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1459 /** Runs the function passes on the provided function. */
1460 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1463 /** Initializes all the function passes scheduled in the manager */
1464 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1466 /** Finalizes all the function passes scheduled in the manager */
1467 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1469 pub fn LLVMInitializePasses();
1471 /** Adds a verification pass. */
1472 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1474 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1475 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1476 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1477 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1478 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1479 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1480 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1481 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1482 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1483 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1484 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1485 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1486 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1487 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1488 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1489 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1490 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1491 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1492 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1493 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1494 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1495 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1496 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1497 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1498 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1499 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1500 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1501 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1502 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1503 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1504 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1505 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1506 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1507 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1508 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1510 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1511 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1512 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1513 OptimizationLevel: c_uint);
1514 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1516 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1517 PMB: PassManagerBuilderRef,
1519 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1520 PMB: PassManagerBuilderRef,
1522 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1523 PMB: PassManagerBuilderRef,
1525 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1526 PMB: PassManagerBuilderRef,
1528 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1529 PMB: PassManagerBuilderRef,
1530 PM: PassManagerRef);
1532 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1533 PMB: PassManagerBuilderRef,
1534 PM: PassManagerRef);
1535 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1536 PMB: PassManagerBuilderRef,
1541 /** Destroys a memory buffer. */
1542 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1545 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1547 /** Opens an object file. */
1548 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1549 /** Closes an object file. */
1550 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1552 /** Enumerates the sections in an object file. */
1553 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1554 /** Destroys a section iterator. */
1555 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1556 /** Returns true if the section iterator is at the end of the section
1558 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1559 SI: SectionIteratorRef)
1561 /** Moves the section iterator to point to the next section. */
1562 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1563 /** Returns the current section size. */
1564 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1565 /** Returns the current section contents as a string buffer. */
1566 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1568 /** Reads the given file and returns it as a memory buffer. Use
1569 LLVMDisposeMemoryBuffer() to get rid of it. */
1570 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1572 /** Borrows the contents of the memory buffer (doesn't copy it) */
1573 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1574 InputDataLength: size_t,
1575 BufferName: *const c_char,
1578 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1579 InputDataLength: size_t,
1580 BufferName: *const c_char)
1583 pub fn LLVMIsMultithreaded() -> Bool;
1584 pub fn LLVMStartMultithreaded() -> Bool;
1586 /** Returns a string describing the last error caused by an LLVMRust*
1588 pub fn LLVMRustGetLastError() -> *const c_char;
1590 /// Print the pass timings since static dtors aren't picking them up.
1591 pub fn LLVMRustPrintPassTimings();
1593 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1595 pub fn LLVMStructSetBody(StructTy: TypeRef,
1596 ElementTypes: *const TypeRef,
1597 ElementCount: c_uint,
1600 pub fn LLVMConstNamedStruct(S: TypeRef,
1601 ConstantVals: *const ValueRef,
1605 /** Enables LLVM debug output. */
1606 pub fn LLVMSetDebug(Enabled: c_int);
1608 /** Prepares inline assembly. */
1609 pub fn LLVMInlineAsm(Ty: TypeRef,
1610 AsmString: *const c_char,
1611 Constraints: *const c_char,
1617 pub static LLVMRustDebugMetadataVersion: u32;
1619 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1620 name: *const c_char,
1623 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1625 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1627 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1629 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1631 File: *const c_char,
1633 Producer: *const c_char,
1635 Flags: *const c_char,
1637 SplitName: *const c_char);
1639 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1640 Filename: *const c_char,
1641 Directory: *const c_char)
1644 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1646 ParameterTypes: DIArray)
1649 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1650 Scope: DIDescriptor,
1651 Name: *const c_char,
1652 LinkageName: *const c_char,
1656 isLocalToUnit: bool,
1666 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1667 Name: *const c_char,
1668 SizeInBits: c_ulonglong,
1669 AlignInBits: c_ulonglong,
1673 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1675 SizeInBits: c_ulonglong,
1676 AlignInBits: c_ulonglong,
1677 Name: *const c_char)
1680 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1681 Scope: DIDescriptor,
1682 Name: *const c_char,
1685 SizeInBits: c_ulonglong,
1686 AlignInBits: c_ulonglong,
1688 DerivedFrom: DIType,
1690 RunTimeLang: c_uint,
1691 VTableHolder: ValueRef,
1692 UniqueId: *const c_char)
1695 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1696 Scope: DIDescriptor,
1697 Name: *const c_char,
1700 SizeInBits: c_ulonglong,
1701 AlignInBits: c_ulonglong,
1702 OffsetInBits: c_ulonglong,
1707 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1708 Scope: DIDescriptor,
1712 Discriminator: c_uint)
1715 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1716 Context: DIDescriptor,
1717 Name: *const c_char,
1718 LinkageName: *const c_char,
1722 isLocalToUnit: bool,
1725 -> DIGlobalVariable;
1727 pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef,
1729 Scope: DIDescriptor,
1730 Name: *const c_char,
1734 AlwaysPreserve: bool,
1739 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1741 AlignInBits: c_ulonglong,
1743 Subscripts: DIArray)
1746 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1748 AlignInBits: c_ulonglong,
1750 Subscripts: DIArray)
1753 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1758 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1759 Ptr: *const DIDescriptor,
1763 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1765 VarInfo: DIVariable,
1766 InsertAtEnd: BasicBlockRef)
1769 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1771 VarInfo: DIVariable,
1772 InsertBefore: ValueRef)
1775 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1776 Name: *const c_char,
1780 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1782 Name: *const c_char,
1785 SizeInBits: c_ulonglong,
1786 AlignInBits: c_ulonglong,
1788 ClassType: ValueRef)
1791 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1793 Name: *const c_char,
1796 SizeInBits: c_ulonglong,
1797 AlignInBits: c_ulonglong,
1800 RunTimeLang: c_uint,
1801 UniqueId: *const c_char)
1804 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1806 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1808 Name: *const c_char,
1815 pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef;
1817 pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef;
1819 pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef,
1822 Name: *const c_char,
1826 AddrOps: *const ValueRef,
1827 AddrOpsCount: c_uint,
1831 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1833 Name: *const c_char,
1838 pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1839 pub fn LLVMTypeToString(Type: TypeRef) -> *const c_char;
1840 pub fn LLVMValueToString(value_ref: ValueRef) -> *const c_char;
1842 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1844 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1846 pub fn LLVMInitializeX86TargetInfo();
1847 pub fn LLVMInitializeX86Target();
1848 pub fn LLVMInitializeX86TargetMC();
1849 pub fn LLVMInitializeX86AsmPrinter();
1850 pub fn LLVMInitializeX86AsmParser();
1851 pub fn LLVMInitializeARMTargetInfo();
1852 pub fn LLVMInitializeARMTarget();
1853 pub fn LLVMInitializeARMTargetMC();
1854 pub fn LLVMInitializeARMAsmPrinter();
1855 pub fn LLVMInitializeARMAsmParser();
1856 pub fn LLVMInitializeMipsTargetInfo();
1857 pub fn LLVMInitializeMipsTarget();
1858 pub fn LLVMInitializeMipsTargetMC();
1859 pub fn LLVMInitializeMipsAsmPrinter();
1860 pub fn LLVMInitializeMipsAsmParser();
1862 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool;
1863 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
1865 Features: *const c_char,
1866 Model: CodeGenModel,
1868 Level: CodeGenOptLevel,
1871 NoFramePointerElim: bool,
1872 FunctionSections: bool,
1873 DataSections: bool) -> TargetMachineRef;
1874 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
1875 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
1878 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
1880 DisableSimplifyLibCalls: bool);
1881 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
1882 DisableSimplifyLibCalls: bool);
1883 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
1884 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
1887 Output: *const c_char,
1888 FileType: FileType) -> bool;
1889 pub fn LLVMRustPrintModule(PM: PassManagerRef,
1891 Output: *const c_char);
1892 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
1893 pub fn LLVMRustPrintPasses();
1894 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
1895 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
1896 AddLifetimes: bool);
1897 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
1899 len: size_t) -> bool;
1900 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
1901 syms: *const *const c_char,
1903 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
1905 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
1906 pub fn LLVMRustArchiveReadSection(AR: ArchiveRef, name: *const c_char,
1907 out_len: *mut size_t) -> *const c_char;
1908 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
1910 pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef);
1911 pub fn LLVMVersionMajor() -> c_int;
1912 pub fn LLVMVersionMinor() -> c_int;
1914 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
1915 data: *mut *const c_char) -> c_int;
1918 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
1920 LLVMSetInstructionCallConv(instr, cc as c_uint);
1923 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
1925 LLVMSetFunctionCallConv(fn_, cc as c_uint);
1928 pub fn SetLinkage(global: ValueRef, link: Linkage) {
1930 LLVMSetLinkage(global, link as c_uint);
1934 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
1936 LLVMSetUnnamedAddr(global, unnamed as Bool);
1940 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
1942 LLVMSetThreadLocal(global, is_thread_local as Bool);
1946 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
1948 LLVMConstICmp(pred as c_ushort, v1, v2)
1951 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
1953 LLVMConstFCmp(pred as c_ushort, v1, v2)
1957 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
1959 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t)
1963 /* Memory-managed interface to target data. */
1965 pub struct TargetData {
1966 pub lltd: TargetDataRef
1969 impl Drop for TargetData {
1970 fn drop(&mut self) {
1972 LLVMDisposeTargetData(self.lltd);
1977 pub fn mk_target_data(string_rep: &str) -> TargetData {
1979 lltd: string_rep.with_c_str(|buf| {
1980 unsafe { LLVMCreateTargetData(buf) }
1985 /* Memory-managed interface to object files. */
1987 pub struct ObjectFile {
1988 pub llof: ObjectFileRef,
1992 // This will take ownership of llmb
1993 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
1995 let llof = LLVMCreateObjectFile(llmb);
1996 if llof as int == 0 {
1997 // LLVMCreateObjectFile took ownership of llmb
2008 impl Drop for ObjectFile {
2009 fn drop(&mut self) {
2011 LLVMDisposeObjectFile(self.llof);
2016 /* Memory-managed interface to section iterators. */
2018 pub struct SectionIter {
2019 pub llsi: SectionIteratorRef
2022 impl Drop for SectionIter {
2023 fn drop(&mut self) {
2025 LLVMDisposeSectionIterator(self.llsi);
2030 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2033 llsi: LLVMGetSections(llof)
2038 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2039 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2041 assert!(index < LLVMCountParams(llfn));
2042 LLVMGetParam(llfn, index)
2046 // FIXME #15460 - create a public function that actually calls our
2047 // static LLVM symbols. Otherwise the linker will just throw llvm
2048 // away. We're just calling lots of stuff until we transitively get
2049 // all of LLVM. This is worse than anything.
2050 pub unsafe fn static_link_hack_this_sucks() {
2051 LLVMInitializePasses();
2053 LLVMInitializeX86TargetInfo();
2054 LLVMInitializeX86Target();
2055 LLVMInitializeX86TargetMC();
2056 LLVMInitializeX86AsmPrinter();
2057 LLVMInitializeX86AsmParser();
2059 LLVMInitializeARMTargetInfo();
2060 LLVMInitializeARMTarget();
2061 LLVMInitializeARMTargetMC();
2062 LLVMInitializeARMAsmPrinter();
2063 LLVMInitializeARMAsmParser();
2065 LLVMInitializeMipsTargetInfo();
2066 LLVMInitializeMipsTarget();
2067 LLVMInitializeMipsTargetMC();
2068 LLVMInitializeMipsAsmPrinter();
2069 LLVMInitializeMipsAsmParser();
2071 LLVMRustSetLLVMOptions(0 as c_int,
2074 LLVMPassManagerBuilderPopulateModulePassManager(0 as *mut _, 0 as *mut _);
2075 LLVMPassManagerBuilderPopulateLTOPassManager(0 as *mut _, 0 as *mut _, False, False);
2076 LLVMPassManagerBuilderPopulateFunctionPassManager(0 as *mut _, 0 as *mut _);
2077 LLVMPassManagerBuilderSetOptLevel(0 as *mut _, 0 as c_uint);
2078 LLVMPassManagerBuilderUseInlinerWithThreshold(0 as *mut _, 0 as c_uint);
2079 LLVMWriteBitcodeToFile(0 as *mut _, 0 as *const _);
2080 LLVMPassManagerBuilderCreate();
2081 LLVMPassManagerBuilderDispose(0 as *mut _);
2083 LLVMRustLinkInExternalBitcode(0 as *mut _, 0 as *const _, 0 as size_t);
2087 LLVMLinkInInterpreter();
2091 fn LLVMLinkInMCJIT();
2092 fn LLVMLinkInInterpreter();
2096 // The module containing the native LLVM dependencies, generated by the build system
2097 // Note that this must come after the rustllvm extern declaration so that
2098 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2099 // Works to the above fix for #15460 to ensure LLVM dependencies that
2100 // are only used by rustllvm don't get stripped by the linker.