1 // Copyright 2012-2015 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 // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
12 #![cfg_attr(stage0, feature(custom_attribute))]
13 #![allow(non_upper_case_globals)]
14 #![allow(non_camel_case_types)]
15 #![allow(non_snake_case)]
17 #![allow(trivial_casts)]
19 #![crate_name = "rustc_llvm"]
20 #![unstable(feature = "rustc_private")]
22 #![crate_type = "dylib"]
23 #![crate_type = "rlib"]
24 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
25 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
26 html_root_url = "http://doc.rust-lang.org/nightly/")]
28 #![feature(associated_consts)]
29 #![feature(box_syntax)]
31 #![feature(link_args)]
32 #![feature(staged_api)]
33 #![feature(vec_push_all)]
36 #[macro_use] #[no_link] extern crate rustc_bitflags;
38 pub use self::OtherAttribute::*;
39 pub use self::SpecialAttribute::*;
40 pub use self::AttributeSet::*;
41 pub use self::IntPredicate::*;
42 pub use self::RealPredicate::*;
43 pub use self::TypeKind::*;
44 pub use self::AtomicBinOp::*;
45 pub use self::AtomicOrdering::*;
46 pub use self::SynchronizationScope::*;
47 pub use self::FileType::*;
48 pub use self::MetadataType::*;
49 pub use self::AsmDialect::*;
50 pub use self::CodeGenOptLevel::*;
51 pub use self::RelocMode::*;
52 pub use self::CodeGenModel::*;
53 pub use self::DiagnosticKind::*;
54 pub use self::CallConv::*;
55 pub use self::Visibility::*;
56 pub use self::DiagnosticSeverity::*;
57 pub use self::Linkage::*;
58 pub use self::DLLStorageClassTypes::*;
60 use std::ffi::CString;
61 use std::cell::RefCell;
62 use std::{slice, mem};
63 use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
64 use libc::{c_longlong, c_ulonglong, c_void};
65 use debuginfo::{DIBuilderRef, DIDescriptor,
66 DIFile, DILexicalBlock, DISubprogram, DIType,
67 DIBasicType, DIDerivedType, DICompositeType, DIScope,
68 DIVariable, DIGlobalVariable, DIArray, DISubrange,
69 DITemplateTypeParameter, DIEnumerator, DINameSpace};
74 pub type Opcode = u32;
75 pub type Bool = c_uint;
77 pub const True: Bool = 1 as Bool;
78 pub const False: Bool = 0 as Bool;
80 // Consts for the LLVM CallConv type, pre-cast to usize.
82 #[derive(Copy, Clone, PartialEq)]
87 X86StdcallCallConv = 64,
88 X86FastcallCallConv = 65,
92 #[derive(Copy, Clone)]
94 LLVMDefaultVisibility = 0,
96 ProtectedVisibility = 2,
99 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
100 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
101 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
102 // they've been removed in upstream LLVM commit r203866.
103 #[derive(Copy, Clone)]
106 AvailableExternallyLinkage = 1,
107 LinkOnceAnyLinkage = 2,
108 LinkOnceODRLinkage = 3,
111 AppendingLinkage = 7,
114 ExternalWeakLinkage = 12,
119 #[derive(Copy, Clone, Debug)]
120 pub enum DiagnosticSeverity {
129 #[derive(Copy, Clone)]
130 pub enum DLLStorageClassTypes {
131 DefaultStorageClass = 0,
132 DLLImportStorageClass = 1,
133 DLLExportStorageClass = 2,
137 flags Attribute : u64 {
140 const NoReturn = 1 << 2,
141 const InReg = 1 << 3,
142 const StructRet = 1 << 4,
143 const NoUnwind = 1 << 5,
144 const NoAlias = 1 << 6,
145 const ByVal = 1 << 7,
147 const ReadNone = 1 << 9,
148 const ReadOnly = 1 << 10,
149 const NoInline = 1 << 11,
150 const AlwaysInline = 1 << 12,
151 const OptimizeForSize = 1 << 13,
152 const StackProtect = 1 << 14,
153 const StackProtectReq = 1 << 15,
154 const Alignment = 1 << 16,
155 const NoCapture = 1 << 21,
156 const NoRedZone = 1 << 22,
157 const NoImplicitFloat = 1 << 23,
158 const Naked = 1 << 24,
159 const InlineHint = 1 << 25,
160 const Stack = 7 << 26,
161 const ReturnsTwice = 1 << 29,
162 const UWTable = 1 << 30,
163 const NonLazyBind = 1 << 31,
164 const OptimizeNone = 1 << 42,
170 #[derive(Copy, Clone)]
171 pub enum OtherAttribute {
172 // The following are not really exposed in
173 // the LLVM C api so instead to add these
174 // we call a wrapper function in RustWrapper
175 // that uses the C++ api.
176 SanitizeAddressAttribute = 1 << 32,
177 MinSizeAttribute = 1 << 33,
178 NoDuplicateAttribute = 1 << 34,
179 StackProtectStrongAttribute = 1 << 35,
180 SanitizeThreadAttribute = 1 << 36,
181 SanitizeMemoryAttribute = 1 << 37,
182 NoBuiltinAttribute = 1 << 38,
183 ReturnedAttribute = 1 << 39,
184 ColdAttribute = 1 << 40,
185 BuiltinAttribute = 1 << 41,
186 OptimizeNoneAttribute = 1 << 42,
187 InAllocaAttribute = 1 << 43,
188 NonNullAttribute = 1 << 44,
191 #[derive(Copy, Clone)]
192 pub enum SpecialAttribute {
193 DereferenceableAttribute(u64)
197 #[derive(Copy, Clone)]
198 pub enum AttributeSet {
203 pub trait AttrHelper {
204 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
205 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
208 impl AttrHelper for Attribute {
209 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
211 LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
215 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
217 LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
222 impl AttrHelper for OtherAttribute {
223 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
225 LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
229 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
231 LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
236 impl AttrHelper for SpecialAttribute {
237 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
239 DereferenceableAttribute(bytes) => unsafe {
240 LLVMAddDereferenceableAttr(llfn, idx, bytes as uint64_t);
245 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
247 DereferenceableAttribute(bytes) => unsafe {
248 LLVMAddDereferenceableCallSiteAttr(callsite, idx, bytes as uint64_t);
254 pub struct AttrBuilder {
255 attrs: Vec<(usize, Box<AttrHelper+'static>)>
259 pub fn new() -> AttrBuilder {
265 pub fn arg<'a, T: AttrHelper + 'static>(&'a mut self, idx: usize, a: T) -> &'a mut AttrBuilder {
266 self.attrs.push((idx, box a as Box<AttrHelper+'static>));
270 pub fn ret<'a, T: AttrHelper + 'static>(&'a mut self, a: T) -> &'a mut AttrBuilder {
271 self.attrs.push((ReturnIndex as usize, box a as Box<AttrHelper+'static>));
275 pub fn apply_llfn(&self, llfn: ValueRef) {
276 for &(idx, ref attr) in &self.attrs {
277 attr.apply_llfn(idx as c_uint, llfn);
281 pub fn apply_callsite(&self, callsite: ValueRef) {
282 for &(idx, ref attr) in &self.attrs {
283 attr.apply_callsite(idx as c_uint, callsite);
288 // enum for the LLVM IntPredicate type
289 #[derive(Copy, Clone)]
290 pub enum IntPredicate {
303 // enum for the LLVM RealPredicate type
304 #[derive(Copy, Clone)]
305 pub enum RealPredicate {
306 RealPredicateFalse = 0,
321 RealPredicateTrue = 15,
324 // The LLVM TypeKind type - must stay in sync with the def of
325 // LLVMTypeKind in llvm/include/llvm-c/Core.h
326 #[derive(Copy, Clone, PartialEq, Debug)]
348 #[derive(Copy, Clone)]
349 pub enum AtomicBinOp {
364 #[derive(Copy, Clone)]
365 pub enum AtomicOrdering {
369 // Consume = 3, // Not specified yet.
373 SequentiallyConsistent = 7
377 #[derive(Copy, Clone)]
378 pub enum SynchronizationScope {
383 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
385 #[derive(Copy, Clone)]
387 AssemblyFileType = 0,
391 #[derive(Copy, Clone)]
392 pub enum MetadataType {
399 MD_invariant_load = 6,
403 MD_mem_parallel_loop_access = 10,
407 // Inline Asm Dialect
408 #[derive(Copy, Clone)]
409 pub enum AsmDialect {
414 #[derive(Copy, Clone, PartialEq)]
416 pub enum CodeGenOptLevel {
417 CodeGenLevelNone = 0,
418 CodeGenLevelLess = 1,
419 CodeGenLevelDefault = 2,
420 CodeGenLevelAggressive = 3,
423 #[derive(Copy, Clone, PartialEq)]
429 RelocDynamicNoPic = 3,
433 #[derive(Copy, Clone)]
434 pub enum CodeGenModel {
435 CodeModelDefault = 0,
436 CodeModelJITDefault = 1,
444 #[derive(Copy, Clone)]
445 pub enum DiagnosticKind {
448 DK_DebugMetadataVersion,
450 DK_OptimizationRemark,
451 DK_OptimizationRemarkMissed,
452 DK_OptimizationRemarkAnalysis,
453 DK_OptimizationFailure,
457 #[derive(Copy, Clone)]
458 pub enum ArchiveKind {
465 // Opaque pointer types
466 #[allow(missing_copy_implementations)]
467 pub enum Module_opaque {}
468 pub type ModuleRef = *mut Module_opaque;
469 #[allow(missing_copy_implementations)]
470 pub enum Context_opaque {}
471 pub type ContextRef = *mut Context_opaque;
472 #[allow(missing_copy_implementations)]
473 pub enum Type_opaque {}
474 pub type TypeRef = *mut Type_opaque;
475 #[allow(missing_copy_implementations)]
476 pub enum Value_opaque {}
477 pub type ValueRef = *mut Value_opaque;
478 #[allow(missing_copy_implementations)]
479 pub enum Metadata_opaque {}
480 pub type MetadataRef = *mut Metadata_opaque;
481 #[allow(missing_copy_implementations)]
482 pub enum BasicBlock_opaque {}
483 pub type BasicBlockRef = *mut BasicBlock_opaque;
484 #[allow(missing_copy_implementations)]
485 pub enum Builder_opaque {}
486 pub type BuilderRef = *mut Builder_opaque;
487 #[allow(missing_copy_implementations)]
488 pub enum ExecutionEngine_opaque {}
489 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
490 #[allow(missing_copy_implementations)]
491 pub enum MemoryBuffer_opaque {}
492 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
493 #[allow(missing_copy_implementations)]
494 pub enum PassManager_opaque {}
495 pub type PassManagerRef = *mut PassManager_opaque;
496 #[allow(missing_copy_implementations)]
497 pub enum PassManagerBuilder_opaque {}
498 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
499 #[allow(missing_copy_implementations)]
500 pub enum Use_opaque {}
501 pub type UseRef = *mut Use_opaque;
502 #[allow(missing_copy_implementations)]
503 pub enum TargetData_opaque {}
504 pub type TargetDataRef = *mut TargetData_opaque;
505 #[allow(missing_copy_implementations)]
506 pub enum ObjectFile_opaque {}
507 pub type ObjectFileRef = *mut ObjectFile_opaque;
508 #[allow(missing_copy_implementations)]
509 pub enum SectionIterator_opaque {}
510 pub type SectionIteratorRef = *mut SectionIterator_opaque;
511 #[allow(missing_copy_implementations)]
512 pub enum Pass_opaque {}
513 pub type PassRef = *mut Pass_opaque;
514 #[allow(missing_copy_implementations)]
515 pub enum TargetMachine_opaque {}
516 pub type TargetMachineRef = *mut TargetMachine_opaque;
517 pub enum Archive_opaque {}
518 pub type ArchiveRef = *mut Archive_opaque;
519 pub enum ArchiveIterator_opaque {}
520 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
521 pub enum ArchiveChild_opaque {}
522 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
523 #[allow(missing_copy_implementations)]
524 pub enum Twine_opaque {}
525 pub type TwineRef = *mut Twine_opaque;
526 #[allow(missing_copy_implementations)]
527 pub enum DiagnosticInfo_opaque {}
528 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
529 #[allow(missing_copy_implementations)]
530 pub enum DebugLoc_opaque {}
531 pub type DebugLocRef = *mut DebugLoc_opaque;
532 #[allow(missing_copy_implementations)]
533 pub enum SMDiagnostic_opaque {}
534 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
535 #[allow(missing_copy_implementations)]
536 pub enum RustArchiveMember_opaque {}
537 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
539 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
540 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
543 pub use self::DIDescriptorFlags::*;
544 use super::{MetadataRef};
546 #[allow(missing_copy_implementations)]
547 pub enum DIBuilder_opaque {}
548 pub type DIBuilderRef = *mut DIBuilder_opaque;
550 pub type DIDescriptor = MetadataRef;
551 pub type DIScope = DIDescriptor;
552 pub type DILocation = DIDescriptor;
553 pub type DIFile = DIScope;
554 pub type DILexicalBlock = DIScope;
555 pub type DISubprogram = DIScope;
556 pub type DINameSpace = DIScope;
557 pub type DIType = DIDescriptor;
558 pub type DIBasicType = DIType;
559 pub type DIDerivedType = DIType;
560 pub type DICompositeType = DIDerivedType;
561 pub type DIVariable = DIDescriptor;
562 pub type DIGlobalVariable = DIDescriptor;
563 pub type DIArray = DIDescriptor;
564 pub type DISubrange = DIDescriptor;
565 pub type DIEnumerator = DIDescriptor;
566 pub type DITemplateTypeParameter = DIDescriptor;
568 #[derive(Copy, Clone)]
569 pub enum DIDescriptorFlags {
570 FlagPrivate = 1 << 0,
571 FlagProtected = 1 << 1,
572 FlagFwdDecl = 1 << 2,
573 FlagAppleBlock = 1 << 3,
574 FlagBlockByrefStruct = 1 << 4,
575 FlagVirtual = 1 << 5,
576 FlagArtificial = 1 << 6,
577 FlagExplicit = 1 << 7,
578 FlagPrototyped = 1 << 8,
579 FlagObjcClassComplete = 1 << 9,
580 FlagObjectPointer = 1 << 10,
581 FlagVector = 1 << 11,
582 FlagStaticMember = 1 << 12,
583 FlagIndirectVariable = 1 << 13,
584 FlagLValueReference = 1 << 14,
585 FlagRValueReference = 1 << 15
590 // Link to our native llvm bindings (things that we need to use the C++ api
591 // for) and because llvm is written in C++ we need to link against libstdc++
593 // You'll probably notice that there is an omission of all LLVM libraries
594 // from this location. This is because the set of LLVM libraries that we
595 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
596 // figure out the exact set of libraries. To do this, the build system
597 // generates an llvmdeps.rs file next to this one which will be
598 // automatically updated whenever LLVM is updated to include an up-to-date
599 // set of the libraries we need to link to LLVM for.
600 #[link(name = "rustllvm", kind = "static")]
602 /* Create and destroy contexts. */
603 pub fn LLVMContextCreate() -> ContextRef;
604 pub fn LLVMContextDispose(C: ContextRef);
605 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
610 /* Create and destroy modules. */
611 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
614 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
615 pub fn LLVMDisposeModule(M: ModuleRef);
617 /// Data layout. See Module::getDataLayout.
618 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
619 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
621 /// Target triple. See Module::getTargetTriple.
622 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
623 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
625 /// See Module::dump.
626 pub fn LLVMDumpModule(M: ModuleRef);
628 /// See Module::setModuleInlineAsm.
629 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
631 /// See llvm::LLVMTypeKind::getTypeID.
632 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
634 /// See llvm::LLVMType::getContext.
635 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
637 /* Operations on integer types */
638 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
639 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
640 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
641 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
642 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
643 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
646 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
648 /* Operations on real types */
649 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
650 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
651 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
652 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
653 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
655 /* Operations on function types */
656 pub fn LLVMFunctionType(ReturnType: TypeRef,
657 ParamTypes: *const TypeRef,
661 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
662 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
663 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
664 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
666 /* Operations on struct types */
667 pub fn LLVMStructTypeInContext(C: ContextRef,
668 ElementTypes: *const TypeRef,
669 ElementCount: c_uint,
672 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
673 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
675 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
677 /* Operations on array, pointer, and vector types (sequence types) */
678 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
679 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
681 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
684 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
685 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
686 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
687 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
689 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
691 /* Operations on other types */
692 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
693 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
694 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
696 /* Operations on all values */
697 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
698 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
699 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
700 pub fn LLVMDumpValue(Val: ValueRef);
701 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
702 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
703 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
704 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
706 /* Operations on Uses */
707 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
708 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
709 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
710 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
712 /* Operations on Users */
713 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
714 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
715 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
717 /* Operations on constants of any type */
718 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
720 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
721 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
723 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
725 /* only for isize/vector */
726 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
727 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
728 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
729 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
730 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
732 /* Operations on metadata */
733 pub fn LLVMMDStringInContext(C: ContextRef,
737 pub fn LLVMMDNodeInContext(C: ContextRef,
738 Vals: *const ValueRef,
741 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
745 /* Operations on scalar constants */
746 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
748 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
750 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
755 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
756 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
758 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
762 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
763 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
766 /* Operations on composite constants */
767 pub fn LLVMConstStringInContext(C: ContextRef,
770 DontNullTerminate: Bool)
772 pub fn LLVMConstStructInContext(C: ContextRef,
773 ConstantVals: *const ValueRef,
778 pub fn LLVMConstArray(ElementTy: TypeRef,
779 ConstantVals: *const ValueRef,
782 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
785 /* Constant expressions */
786 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
787 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
788 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
789 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
790 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
791 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
792 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
793 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
795 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
797 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
799 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
801 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
803 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
805 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
807 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
809 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
811 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
813 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
815 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
817 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
819 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
821 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
822 RHSConstant: ValueRef)
824 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
826 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
828 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
830 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
832 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
834 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
836 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
838 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
840 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
842 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
844 pub fn LLVMConstGEP(ConstantVal: ValueRef,
845 ConstantIndices: *const ValueRef,
848 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
849 ConstantIndices: *const ValueRef,
852 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
854 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
856 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
858 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
860 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
862 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
864 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
866 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
868 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
870 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
872 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
874 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
876 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
878 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
880 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
882 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
884 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
888 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
890 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
891 ConstantIfTrue: ValueRef,
892 ConstantIfFalse: ValueRef)
894 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
895 IndexConstant: ValueRef)
897 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
898 ElementValueConstant: ValueRef,
899 IndexConstant: ValueRef)
901 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
902 VectorBConstant: ValueRef,
903 MaskConstant: ValueRef)
905 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
906 IdxList: *const c_uint,
909 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
910 ElementValueConstant: ValueRef,
911 IdxList: *const c_uint,
914 pub fn LLVMConstInlineAsm(Ty: TypeRef,
915 AsmString: *const c_char,
916 Constraints: *const c_char,
917 HasSideEffects: Bool,
920 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
924 /* Operations on global variables, functions, and aliases (globals) */
925 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
926 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
927 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
928 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
929 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
930 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
931 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
932 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
933 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
934 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
937 /* Operations on global variables */
938 pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
939 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
941 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
944 AddressSpace: c_uint)
946 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
947 pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
948 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
949 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
950 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
951 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
952 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
953 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
954 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
955 ConstantVal: ValueRef);
956 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
957 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
958 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
959 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
960 pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
962 /* Operations on aliases */
963 pub fn LLVMAddAlias(M: ModuleRef,
969 /* Operations on functions */
970 pub fn LLVMAddFunction(M: ModuleRef,
974 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
975 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
976 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
977 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
978 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
979 pub fn LLVMDeleteFunction(Fn: ValueRef);
980 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
984 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
985 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
986 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
987 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
988 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
989 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
990 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
991 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
992 pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
994 Value: *const c_char);
995 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
996 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
997 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
999 /* Operations on parameters */
1000 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
1001 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
1002 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
1003 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
1004 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
1005 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
1006 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
1007 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
1008 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
1009 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1010 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1011 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1013 /* Operations on basic blocks */
1014 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1015 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1016 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1017 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1018 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1019 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1020 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1021 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1022 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1023 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1024 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1026 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1028 Name: *const c_char)
1030 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1032 Name: *const c_char)
1034 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1036 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1037 MoveAfter: BasicBlockRef);
1039 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1040 MoveBefore: BasicBlockRef);
1042 /* Operations on instructions */
1043 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1044 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1045 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1046 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1047 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1048 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1050 /* Operations on call sites */
1051 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1052 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1053 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1056 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1059 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1062 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1065 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1069 /* Operations on call instructions (only) */
1070 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1071 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1073 /* Operations on load/store instructions (only) */
1074 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1075 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1077 /* Operations on phi nodes */
1078 pub fn LLVMAddIncoming(PhiNode: ValueRef,
1079 IncomingValues: *const ValueRef,
1080 IncomingBlocks: *const BasicBlockRef,
1082 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1083 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1085 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1088 /* Instruction builders */
1089 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1090 pub fn LLVMPositionBuilder(Builder: BuilderRef,
1091 Block: BasicBlockRef,
1093 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1095 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1096 Block: BasicBlockRef);
1097 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1098 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1099 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1100 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1102 Name: *const c_char);
1103 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1105 /* Execution engine */
1106 pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1107 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1108 pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1109 pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1110 pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1111 pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1115 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1116 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1117 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1120 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1121 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1122 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1123 RetVals: *const ValueRef,
1126 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1127 pub fn LLVMBuildCondBr(B: BuilderRef,
1129 Then: BasicBlockRef,
1130 Else: BasicBlockRef)
1132 pub fn LLVMBuildSwitch(B: BuilderRef,
1134 Else: BasicBlockRef,
1137 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1141 pub fn LLVMBuildInvoke(B: BuilderRef,
1143 Args: *const ValueRef,
1145 Then: BasicBlockRef,
1146 Catch: BasicBlockRef,
1147 Name: *const c_char)
1149 pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1153 Name: *const c_char,
1156 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1157 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1159 /* Add a case to the switch instruction */
1160 pub fn LLVMAddCase(Switch: ValueRef,
1162 Dest: BasicBlockRef);
1164 /* Add a destination to the indirectbr instruction */
1165 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1167 /* Add a clause to the landing pad instruction */
1168 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1170 /* Set the cleanup on a landing pad instruction */
1171 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1174 pub fn LLVMBuildAdd(B: BuilderRef,
1177 Name: *const c_char)
1179 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1182 Name: *const c_char)
1184 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1187 Name: *const c_char)
1189 pub fn LLVMBuildFAdd(B: BuilderRef,
1192 Name: *const c_char)
1194 pub fn LLVMBuildSub(B: BuilderRef,
1197 Name: *const c_char)
1199 pub fn LLVMBuildNSWSub(B: BuilderRef,
1202 Name: *const c_char)
1204 pub fn LLVMBuildNUWSub(B: BuilderRef,
1207 Name: *const c_char)
1209 pub fn LLVMBuildFSub(B: BuilderRef,
1212 Name: *const c_char)
1214 pub fn LLVMBuildMul(B: BuilderRef,
1217 Name: *const c_char)
1219 pub fn LLVMBuildNSWMul(B: BuilderRef,
1222 Name: *const c_char)
1224 pub fn LLVMBuildNUWMul(B: BuilderRef,
1227 Name: *const c_char)
1229 pub fn LLVMBuildFMul(B: BuilderRef,
1232 Name: *const c_char)
1234 pub fn LLVMBuildUDiv(B: BuilderRef,
1237 Name: *const c_char)
1239 pub fn LLVMBuildSDiv(B: BuilderRef,
1242 Name: *const c_char)
1244 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1247 Name: *const c_char)
1249 pub fn LLVMBuildFDiv(B: BuilderRef,
1252 Name: *const c_char)
1254 pub fn LLVMBuildURem(B: BuilderRef,
1257 Name: *const c_char)
1259 pub fn LLVMBuildSRem(B: BuilderRef,
1262 Name: *const c_char)
1264 pub fn LLVMBuildFRem(B: BuilderRef,
1267 Name: *const c_char)
1269 pub fn LLVMBuildShl(B: BuilderRef,
1272 Name: *const c_char)
1274 pub fn LLVMBuildLShr(B: BuilderRef,
1277 Name: *const c_char)
1279 pub fn LLVMBuildAShr(B: BuilderRef,
1282 Name: *const c_char)
1284 pub fn LLVMBuildAnd(B: BuilderRef,
1287 Name: *const c_char)
1289 pub fn LLVMBuildOr(B: BuilderRef,
1292 Name: *const c_char)
1294 pub fn LLVMBuildXor(B: BuilderRef,
1297 Name: *const c_char)
1299 pub fn LLVMBuildBinOp(B: BuilderRef,
1303 Name: *const c_char)
1305 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1307 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1309 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1311 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1313 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1317 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1319 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1320 pub fn LLVMBuildLoad(B: BuilderRef,
1321 PointerVal: ValueRef,
1322 Name: *const c_char)
1325 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1328 pub fn LLVMBuildGEP(B: BuilderRef,
1330 Indices: *const ValueRef,
1332 Name: *const c_char)
1334 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1336 Indices: *const ValueRef,
1338 Name: *const c_char)
1340 pub fn LLVMBuildStructGEP(B: BuilderRef,
1343 Name: *const c_char)
1345 pub fn LLVMBuildGlobalString(B: BuilderRef,
1347 Name: *const c_char)
1349 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1351 Name: *const c_char)
1355 pub fn LLVMBuildTrunc(B: BuilderRef,
1358 Name: *const c_char)
1360 pub fn LLVMBuildZExt(B: BuilderRef,
1363 Name: *const c_char)
1365 pub fn LLVMBuildSExt(B: BuilderRef,
1368 Name: *const c_char)
1370 pub fn LLVMBuildFPToUI(B: BuilderRef,
1373 Name: *const c_char)
1375 pub fn LLVMBuildFPToSI(B: BuilderRef,
1378 Name: *const c_char)
1380 pub fn LLVMBuildUIToFP(B: BuilderRef,
1383 Name: *const c_char)
1385 pub fn LLVMBuildSIToFP(B: BuilderRef,
1388 Name: *const c_char)
1390 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1393 Name: *const c_char)
1395 pub fn LLVMBuildFPExt(B: BuilderRef,
1398 Name: *const c_char)
1400 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1403 Name: *const c_char)
1405 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1408 Name: *const c_char)
1410 pub fn LLVMBuildBitCast(B: BuilderRef,
1413 Name: *const c_char)
1415 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1418 Name: *const c_char)
1420 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1423 Name: *const c_char)
1425 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1428 Name: *const c_char)
1430 pub fn LLVMBuildCast(B: BuilderRef,
1434 Name: *const c_char) -> ValueRef;
1435 pub fn LLVMBuildPointerCast(B: BuilderRef,
1438 Name: *const c_char)
1440 pub fn LLVMBuildIntCast(B: BuilderRef,
1443 Name: *const c_char)
1445 pub fn LLVMBuildFPCast(B: BuilderRef,
1448 Name: *const c_char)
1452 pub fn LLVMBuildICmp(B: BuilderRef,
1456 Name: *const c_char)
1458 pub fn LLVMBuildFCmp(B: BuilderRef,
1462 Name: *const c_char)
1465 /* Miscellaneous instructions */
1466 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1468 pub fn LLVMBuildCall(B: BuilderRef,
1470 Args: *const ValueRef,
1472 Name: *const c_char)
1474 pub fn LLVMBuildSelect(B: BuilderRef,
1478 Name: *const c_char)
1480 pub fn LLVMBuildVAArg(B: BuilderRef,
1483 Name: *const c_char)
1485 pub fn LLVMBuildExtractElement(B: BuilderRef,
1488 Name: *const c_char)
1490 pub fn LLVMBuildInsertElement(B: BuilderRef,
1494 Name: *const c_char)
1496 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1500 Name: *const c_char)
1502 pub fn LLVMBuildExtractValue(B: BuilderRef,
1505 Name: *const c_char)
1507 pub fn LLVMBuildInsertValue(B: BuilderRef,
1511 Name: *const c_char)
1514 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1516 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1518 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1521 Name: *const c_char)
1524 /* Atomic Operations */
1525 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1526 PointerVal: ValueRef,
1527 Name: *const c_char,
1528 Order: AtomicOrdering,
1532 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1535 Order: AtomicOrdering,
1539 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1543 Order: AtomicOrdering,
1544 FailureOrder: AtomicOrdering)
1546 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1550 Order: AtomicOrdering,
1551 SingleThreaded: Bool)
1554 pub fn LLVMBuildAtomicFence(B: BuilderRef,
1555 Order: AtomicOrdering,
1556 Scope: SynchronizationScope);
1559 /* Selected entries from the downcasts. */
1560 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1561 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1563 /// Writes a module to the specified path. Returns 0 on success.
1564 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1566 /// Creates target data from a target layout string.
1567 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1568 /// Adds the target data to the given pass manager. The pass manager
1569 /// references the target data only weakly.
1570 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1571 /// Number of bytes clobbered when doing a Store to *T.
1572 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1575 /// Number of bytes clobbered when doing a Store to *T.
1576 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1579 /// Distance between successive elements in an array of T. Includes ABI padding.
1580 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1582 /// Returns the preferred alignment of a type.
1583 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1585 /// Returns the minimum alignment of a type.
1586 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1589 /// Computes the byte offset of the indexed struct element for a
1591 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1596 /// Returns the minimum alignment of a type when part of a call frame.
1597 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1600 /// Disposes target data.
1601 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1603 /// Creates a pass manager.
1604 pub fn LLVMCreatePassManager() -> PassManagerRef;
1606 /// Creates a function-by-function pass manager
1607 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1610 /// Disposes a pass manager.
1611 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1613 /// Runs a pass manager on a module.
1614 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1616 /// Runs the function passes on the provided function.
1617 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1620 /// Initializes all the function passes scheduled in the manager
1621 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1623 /// Finalizes all the function passes scheduled in the manager
1624 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1626 pub fn LLVMInitializePasses();
1628 /// Adds a verification pass.
1629 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1631 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1632 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1633 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1634 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1635 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1636 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1637 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1638 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1639 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1640 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1641 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1642 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1643 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1644 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1645 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1646 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1647 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1648 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1649 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1650 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1651 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1652 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1653 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1654 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1655 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1656 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1657 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1658 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1659 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1660 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1661 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1662 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1663 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1664 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1665 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1667 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1668 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1669 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1670 OptimizationLevel: c_uint);
1671 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1673 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1674 PMB: PassManagerBuilderRef,
1676 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1677 PMB: PassManagerBuilderRef,
1679 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1680 PMB: PassManagerBuilderRef,
1682 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1683 PMB: PassManagerBuilderRef,
1685 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1686 PMB: PassManagerBuilderRef,
1687 PM: PassManagerRef);
1689 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1690 PMB: PassManagerBuilderRef,
1691 PM: PassManagerRef);
1692 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1693 PMB: PassManagerBuilderRef,
1698 /// Destroys a memory buffer.
1699 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1702 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1704 /// Opens an object file.
1705 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1706 /// Closes an object file.
1707 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1709 /// Enumerates the sections in an object file.
1710 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1711 /// Destroys a section iterator.
1712 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1713 /// Returns true if the section iterator is at the end of the section
1715 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1716 SI: SectionIteratorRef)
1718 /// Moves the section iterator to point to the next section.
1719 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1720 /// Returns the current section size.
1721 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1722 /// Returns the current section contents as a string buffer.
1723 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1725 /// Reads the given file and returns it as a memory buffer. Use
1726 /// LLVMDisposeMemoryBuffer() to get rid of it.
1727 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1729 /// Borrows the contents of the memory buffer (doesn't copy it)
1730 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1731 InputDataLength: size_t,
1732 BufferName: *const c_char,
1735 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1736 InputDataLength: size_t,
1737 BufferName: *const c_char)
1740 pub fn LLVMIsMultithreaded() -> Bool;
1741 pub fn LLVMStartMultithreaded() -> Bool;
1743 /// Returns a string describing the last error caused by an LLVMRust* call.
1744 pub fn LLVMRustGetLastError() -> *const c_char;
1746 /// Print the pass timings since static dtors aren't picking them up.
1747 pub fn LLVMRustPrintPassTimings();
1749 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1751 pub fn LLVMStructSetBody(StructTy: TypeRef,
1752 ElementTypes: *const TypeRef,
1753 ElementCount: c_uint,
1756 pub fn LLVMConstNamedStruct(S: TypeRef,
1757 ConstantVals: *const ValueRef,
1761 /// Enables LLVM debug output.
1762 pub fn LLVMSetDebug(Enabled: c_int);
1764 /// Prepares inline assembly.
1765 pub fn LLVMInlineAsm(Ty: TypeRef,
1766 AsmString: *const c_char,
1767 Constraints: *const c_char,
1773 pub fn LLVMRustDebugMetadataVersion() -> u32;
1774 pub fn LLVMVersionMajor() -> u32;
1775 pub fn LLVMVersionMinor() -> u32;
1777 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1778 name: *const c_char,
1781 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1783 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1785 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1787 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1789 File: *const c_char,
1791 Producer: *const c_char,
1793 Flags: *const c_char,
1795 SplitName: *const c_char)
1798 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1799 Filename: *const c_char,
1800 Directory: *const c_char)
1803 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1805 ParameterTypes: DIArray)
1808 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1809 Scope: DIDescriptor,
1810 Name: *const c_char,
1811 LinkageName: *const c_char,
1815 isLocalToUnit: bool,
1825 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1826 Name: *const c_char,
1827 SizeInBits: c_ulonglong,
1828 AlignInBits: c_ulonglong,
1832 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1834 SizeInBits: c_ulonglong,
1835 AlignInBits: c_ulonglong,
1836 Name: *const c_char)
1839 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1840 Scope: DIDescriptor,
1841 Name: *const c_char,
1844 SizeInBits: c_ulonglong,
1845 AlignInBits: c_ulonglong,
1847 DerivedFrom: DIType,
1849 RunTimeLang: c_uint,
1850 VTableHolder: DIType,
1851 UniqueId: *const c_char)
1854 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1855 Scope: DIDescriptor,
1856 Name: *const c_char,
1859 SizeInBits: c_ulonglong,
1860 AlignInBits: c_ulonglong,
1861 OffsetInBits: c_ulonglong,
1866 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1873 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1875 Name: *const c_char,
1876 LinkageName: *const c_char,
1880 isLocalToUnit: bool,
1883 -> DIGlobalVariable;
1885 pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1887 Scope: DIDescriptor,
1888 Name: *const c_char,
1892 AlwaysPreserve: bool,
1894 AddrOps: *const i64,
1895 AddrOpsCount: c_uint,
1899 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1901 AlignInBits: c_ulonglong,
1903 Subscripts: DIArray)
1906 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1908 AlignInBits: c_ulonglong,
1910 Subscripts: DIArray)
1913 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1918 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1919 Ptr: *const DIDescriptor,
1923 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1925 VarInfo: DIVariable,
1926 AddrOps: *const i64,
1927 AddrOpsCount: c_uint,
1929 InsertAtEnd: BasicBlockRef)
1932 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1934 VarInfo: DIVariable,
1935 AddrOps: *const i64,
1936 AddrOpsCount: c_uint,
1938 InsertBefore: ValueRef)
1941 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1942 Name: *const c_char,
1946 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1948 Name: *const c_char,
1951 SizeInBits: c_ulonglong,
1952 AlignInBits: c_ulonglong,
1957 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1959 Name: *const c_char,
1962 SizeInBits: c_ulonglong,
1963 AlignInBits: c_ulonglong,
1966 RunTimeLang: c_uint,
1967 UniqueId: *const c_char)
1970 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1972 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1974 Name: *const c_char,
1979 -> DITemplateTypeParameter;
1981 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1983 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1985 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1987 Name: *const c_char,
1992 pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
1996 InlinedAt: MetadataRef)
1999 pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
2000 CompositeType: DIType,
2001 TypeArray: DIArray);
2002 pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
2003 pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2005 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
2007 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2008 pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2010 pub fn LLVMInitializeX86TargetInfo();
2011 pub fn LLVMInitializeX86Target();
2012 pub fn LLVMInitializeX86TargetMC();
2013 pub fn LLVMInitializeX86AsmPrinter();
2014 pub fn LLVMInitializeX86AsmParser();
2015 pub fn LLVMInitializeARMTargetInfo();
2016 pub fn LLVMInitializeARMTarget();
2017 pub fn LLVMInitializeARMTargetMC();
2018 pub fn LLVMInitializeARMAsmPrinter();
2019 pub fn LLVMInitializeARMAsmParser();
2020 pub fn LLVMInitializeAArch64TargetInfo();
2021 pub fn LLVMInitializeAArch64Target();
2022 pub fn LLVMInitializeAArch64TargetMC();
2023 pub fn LLVMInitializeAArch64AsmPrinter();
2024 pub fn LLVMInitializeAArch64AsmParser();
2025 pub fn LLVMInitializeMipsTargetInfo();
2026 pub fn LLVMInitializeMipsTarget();
2027 pub fn LLVMInitializeMipsTargetMC();
2028 pub fn LLVMInitializeMipsAsmPrinter();
2029 pub fn LLVMInitializeMipsAsmParser();
2030 pub fn LLVMInitializePowerPCTargetInfo();
2031 pub fn LLVMInitializePowerPCTarget();
2032 pub fn LLVMInitializePowerPCTargetMC();
2033 pub fn LLVMInitializePowerPCAsmPrinter();
2034 pub fn LLVMInitializePowerPCAsmParser();
2036 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool;
2037 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2039 Features: *const c_char,
2040 Model: CodeGenModel,
2042 Level: CodeGenOptLevel,
2045 PositionIndependentExecutable: bool,
2046 FunctionSections: bool,
2047 DataSections: bool) -> TargetMachineRef;
2048 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2049 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2052 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2054 DisableSimplifyLibCalls: bool);
2055 pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2056 OptLevel: CodeGenOptLevel,
2057 MergeFunctions: bool,
2059 LoopVectorize: bool);
2060 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2061 DisableSimplifyLibCalls: bool);
2062 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2063 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2066 Output: *const c_char,
2067 FileType: FileType) -> bool;
2068 pub fn LLVMRustPrintModule(PM: PassManagerRef,
2070 Output: *const c_char);
2071 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2072 pub fn LLVMRustPrintPasses();
2073 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2074 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2075 AddLifetimes: bool);
2076 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2078 len: size_t) -> bool;
2079 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2080 syms: *const *const c_char,
2082 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2084 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2085 pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2086 pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2087 pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2088 size: *mut size_t) -> *const c_char;
2089 pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2090 size: *mut size_t) -> *const c_char;
2091 pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2092 pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2093 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2095 pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2096 C: DLLStorageClassTypes);
2098 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2099 data: *mut *const c_char) -> c_int;
2101 pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2103 pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2104 Handler: DiagnosticHandler,
2105 DiagnosticContext: *mut c_void);
2107 pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2108 pass_name_out: *mut *const c_char,
2109 function_out: *mut ValueRef,
2110 debugloc_out: *mut DebugLocRef,
2111 message_out: *mut TwineRef);
2112 pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2113 cookie_out: *mut c_uint,
2114 message_out: *mut TwineRef,
2115 instruction_out: *mut ValueRef);
2117 pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2118 pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2119 pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2121 pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2123 pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2124 H: InlineAsmDiagHandler,
2127 pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2129 pub fn LLVMRustWriteArchive(Dst: *const c_char,
2131 Members: *const RustArchiveMemberRef,
2133 Kind: ArchiveKind) -> c_int;
2134 pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2135 Name: *const c_char,
2136 Child: ArchiveChildRef) -> RustArchiveMemberRef;
2137 pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2139 pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
2140 TM: TargetMachineRef);
2141 pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2144 // LLVM requires symbols from this library, but apparently they're not printed
2145 // during llvm-config?
2147 #[link(name = "ole32")]
2150 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2152 LLVMSetInstructionCallConv(instr, cc as c_uint);
2155 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2157 LLVMSetFunctionCallConv(fn_, cc as c_uint);
2160 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2162 LLVMSetLinkage(global, link as c_uint);
2166 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2168 LLVMRustSetDLLStorageClass(global, class);
2172 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2174 LLVMSetUnnamedAddr(global, unnamed as Bool);
2178 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2180 LLVMSetThreadLocal(global, is_thread_local as Bool);
2184 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2186 LLVMConstICmp(pred as c_ushort, v1, v2)
2189 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2191 LLVMConstFCmp(pred as c_ushort, v1, v2)
2195 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2197 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
2198 attr.bits() as uint64_t)
2202 /* Memory-managed interface to target data. */
2204 pub struct TargetData {
2205 pub lltd: TargetDataRef
2208 impl Drop for TargetData {
2209 fn drop(&mut self) {
2211 LLVMDisposeTargetData(self.lltd);
2216 pub fn mk_target_data(string_rep: &str) -> TargetData {
2217 let string_rep = CString::new(string_rep).unwrap();
2219 lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2223 /* Memory-managed interface to object files. */
2225 pub struct ObjectFile {
2226 pub llof: ObjectFileRef,
2230 // This will take ownership of llmb
2231 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2233 let llof = LLVMCreateObjectFile(llmb);
2234 if llof as isize == 0 {
2235 // LLVMCreateObjectFile took ownership of llmb
2246 impl Drop for ObjectFile {
2247 fn drop(&mut self) {
2249 LLVMDisposeObjectFile(self.llof);
2254 /* Memory-managed interface to section iterators. */
2256 pub struct SectionIter {
2257 pub llsi: SectionIteratorRef
2260 impl Drop for SectionIter {
2261 fn drop(&mut self) {
2263 LLVMDisposeSectionIterator(self.llsi);
2268 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2271 llsi: LLVMGetSections(llof)
2276 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2277 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2279 assert!(index < LLVMCountParams(llfn));
2280 LLVMGetParam(llfn, index)
2284 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2286 let num_params = LLVMCountParams(llfn);
2287 let mut params = Vec::with_capacity(num_params as usize);
2288 for idx in 0..num_params {
2289 params.push(LLVMGetParam(llfn, idx));
2296 #[allow(missing_copy_implementations)]
2297 pub enum RustString_opaque {}
2298 pub type RustStringRef = *mut RustString_opaque;
2299 type RustStringRepr = *mut RefCell<Vec<u8>>;
2301 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2303 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2306 let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2308 let sr: RustStringRepr = mem::transmute(sr);
2309 (*sr).borrow_mut().push_all(slice);
2312 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2313 let mut buf = RefCell::new(Vec::new());
2314 f(&mut buf as RustStringRepr as RustStringRef);
2315 String::from_utf8(buf.into_inner()).ok()
2318 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2319 build_string(|s| LLVMWriteTwineToString(tr, s))
2320 .expect("got a non-UTF8 Twine from LLVM")
2323 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2324 build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2325 .expect("got a non-UTF8 DebugLoc from LLVM")
2328 // The module containing the native LLVM dependencies, generated by the build system
2329 // Note that this must come after the rustllvm extern declaration so that
2330 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2331 // Works to the above fix for #15460 to ensure LLVM dependencies that
2332 // are only used by rustllvm don't get stripped by the linker.
2334 include! { env!("CFG_LLVM_LINKAGE_FILE") }