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 #![allow(non_upper_case_globals)]
12 #![allow(non_camel_case_types)]
13 #![allow(non_snake_case)]
16 #![crate_name = "rustc_llvm"]
17 #![unstable(feature = "rustc_private", issue = "27812")]
18 #![crate_type = "dylib"]
19 #![crate_type = "rlib"]
20 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
21 html_favicon_url
= "https://doc.rust-lang.org/favicon.ico",
22 html_root_url
= "https://doc.rust-lang.org/nightly/")]
23 #![cfg_attr(not(stage0), deny(warnings))]
25 #![feature(associated_consts)]
26 #![feature(box_syntax)]
28 #![feature(link_args)]
29 #![feature(staged_api)]
30 #![feature(linked_from)]
31 #![feature(concat_idents)]
34 #[macro_use] #[no_link] extern crate rustc_bitflags;
36 pub use self::AttributeSet
::*;
37 pub use self::IntPredicate
::*;
38 pub use self::RealPredicate
::*;
39 pub use self::TypeKind
::*;
40 pub use self::AtomicBinOp
::*;
41 pub use self::AtomicOrdering
::*;
42 pub use self::SynchronizationScope
::*;
43 pub use self::FileType
::*;
44 pub use self::MetadataType
::*;
45 pub use self::AsmDialect
::*;
46 pub use self::CodeGenOptLevel
::*;
47 pub use self::RelocMode
::*;
48 pub use self::CodeGenModel
::*;
49 pub use self::DiagnosticKind
::*;
50 pub use self::CallConv
::*;
51 pub use self::Visibility
::*;
52 pub use self::DiagnosticSeverity
::*;
53 pub use self::Linkage
::*;
54 pub use self::DLLStorageClassTypes
::*;
56 use std
::ffi
::{CString, CStr}
;
57 use std
::cell
::RefCell
;
59 use libc
::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char}
;
60 use libc
::{c_longlong, c_ulonglong, c_void}
;
61 use debuginfo
::{DIBuilderRef
, DIDescriptor
,
62 DIFile
, DILexicalBlock
, DISubprogram
, DIType
,
63 DIBasicType
, DIDerivedType
, DICompositeType
, DIScope
,
64 DIVariable
, DIGlobalVariable
, DIArray
, DISubrange
,
65 DITemplateTypeParameter
, DIEnumerator
, DINameSpace
};
70 pub type Opcode
= u32;
71 pub type Bool
= c_uint
;
73 pub const True
: Bool
= 1 as Bool
;
74 pub const False
: Bool
= 0 as Bool
;
76 // Consts for the LLVM CallConv type, pre-cast to usize.
78 #[derive(Copy, Clone, PartialEq)]
83 X86StdcallCallConv
= 64,
84 X86FastcallCallConv
= 65,
89 #[derive(Copy, Clone)]
91 LLVMDefaultVisibility
= 0,
93 ProtectedVisibility
= 2,
96 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
97 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
98 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
99 // they've been removed in upstream LLVM commit r203866.
100 #[derive(Copy, Clone)]
103 AvailableExternallyLinkage
= 1,
104 LinkOnceAnyLinkage
= 2,
105 LinkOnceODRLinkage
= 3,
108 AppendingLinkage
= 7,
111 ExternalWeakLinkage
= 12,
116 #[derive(Copy, Clone, Debug)]
117 pub enum DiagnosticSeverity
{
126 #[derive(Copy, Clone)]
127 pub enum DLLStorageClassTypes
{
128 DefaultStorageClass
= 0,
129 DLLImportStorageClass
= 1,
130 DLLExportStorageClass
= 2,
134 #[derive(Default, Debug)]
135 flags Attribute
: u64 {
138 const NoReturn
= 1 << 2,
139 const InReg
= 1 << 3,
140 const StructRet
= 1 << 4,
141 const NoUnwind
= 1 << 5,
142 const NoAlias
= 1 << 6,
143 const ByVal
= 1 << 7,
145 const ReadNone
= 1 << 9,
146 const ReadOnly
= 1 << 10,
147 const NoInline
= 1 << 11,
148 const AlwaysInline
= 1 << 12,
149 const OptimizeForSize
= 1 << 13,
150 const StackProtect
= 1 << 14,
151 const StackProtectReq
= 1 << 15,
152 const NoCapture
= 1 << 21,
153 const NoRedZone
= 1 << 22,
154 const NoImplicitFloat
= 1 << 23,
155 const Naked
= 1 << 24,
156 const InlineHint
= 1 << 25,
157 const ReturnsTwice
= 1 << 29,
158 const UWTable
= 1 << 30,
159 const NonLazyBind
= 1 << 31,
161 // Some of these are missing from the LLVM C API, the rest are
162 // present, but commented out, and preceded by the following warning:
163 // FIXME: These attributes are currently not included in the C API as
164 // a temporary measure until the API/ABI impact to the C API is understood
165 // and the path forward agreed upon.
166 const SanitizeAddress
= 1 << 32,
167 const MinSize
= 1 << 33,
168 const NoDuplicate
= 1 << 34,
169 const StackProtectStrong
= 1 << 35,
170 const SanitizeThread
= 1 << 36,
171 const SanitizeMemory
= 1 << 37,
172 const NoBuiltin
= 1 << 38,
173 const Returned
= 1 << 39,
174 const Cold
= 1 << 40,
175 const Builtin
= 1 << 41,
176 const OptimizeNone
= 1 << 42,
177 const InAlloca
= 1 << 43,
178 const NonNull
= 1 << 44,
179 const JumpTable
= 1 << 45,
180 const Convergent
= 1 << 46,
181 const SafeStack
= 1 << 47,
182 const NoRecurse
= 1 << 48,
183 const InaccessibleMemOnly
= 1 << 49,
184 const InaccessibleMemOrArgMemOnly
= 1 << 50,
188 #[derive(Copy, Clone, Default, Debug)]
189 pub struct Attributes
{
191 dereferenceable_bytes
: u64
195 pub fn set(&mut self, attr
: Attribute
) -> &mut Self {
196 self.regular
= self.regular
| attr
;
200 pub fn unset(&mut self, attr
: Attribute
) -> &mut Self {
201 self.regular
= self.regular
- attr
;
205 pub fn set_dereferenceable(&mut self, bytes
: u64) -> &mut Self {
206 self.dereferenceable_bytes
= bytes
;
210 pub fn unset_dereferenceable(&mut self) -> &mut Self {
211 self.dereferenceable_bytes
= 0;
215 pub fn apply_llfn(&self, idx
: usize, llfn
: ValueRef
) {
217 LLVMAddFunctionAttribute(llfn
, idx
as c_uint
, self.regular
.bits());
218 if self.dereferenceable_bytes
!= 0 {
219 LLVMAddDereferenceableAttr(llfn
, idx
as c_uint
,
220 self.dereferenceable_bytes
);
225 pub fn apply_callsite(&self, idx
: usize, callsite
: ValueRef
) {
227 LLVMAddCallSiteAttribute(callsite
, idx
as c_uint
, self.regular
.bits());
228 if self.dereferenceable_bytes
!= 0 {
229 LLVMAddDereferenceableCallSiteAttr(callsite
, idx
as c_uint
,
230 self.dereferenceable_bytes
);
237 #[derive(Copy, Clone)]
238 pub enum AttributeSet
{
243 // enum for the LLVM IntPredicate type
244 #[derive(Copy, Clone)]
245 pub enum IntPredicate
{
258 // enum for the LLVM RealPredicate type
259 #[derive(Copy, Clone)]
260 pub enum RealPredicate
{
261 RealPredicateFalse
= 0,
276 RealPredicateTrue
= 15,
279 // The LLVM TypeKind type - must stay in sync with the def of
280 // LLVMTypeKind in llvm/include/llvm-c/Core.h
281 #[derive(Copy, Clone, PartialEq, Debug)]
303 #[derive(Copy, Clone)]
304 pub enum AtomicBinOp
{
319 #[derive(Copy, Clone)]
320 pub enum AtomicOrdering
{
324 // Consume = 3, // Not specified yet.
328 SequentiallyConsistent
= 7
332 #[derive(Copy, Clone)]
333 pub enum SynchronizationScope
{
338 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
340 #[derive(Copy, Clone)]
342 AssemblyFileType
= 0,
346 #[derive(Copy, Clone)]
347 pub enum MetadataType
{
354 MD_invariant_load
= 6,
358 MD_mem_parallel_loop_access
= 10,
362 // Inline Asm Dialect
363 #[derive(Copy, Clone)]
364 pub enum AsmDialect
{
369 #[derive(Copy, Clone, PartialEq)]
371 pub enum CodeGenOptLevel
{
372 CodeGenLevelNone
= 0,
373 CodeGenLevelLess
= 1,
374 CodeGenLevelDefault
= 2,
375 CodeGenLevelAggressive
= 3,
378 #[derive(Copy, Clone, PartialEq)]
384 RelocDynamicNoPic
= 3,
388 #[derive(Copy, Clone)]
389 pub enum CodeGenModel
{
390 CodeModelDefault
= 0,
391 CodeModelJITDefault
= 1,
399 #[derive(Copy, Clone)]
400 pub enum DiagnosticKind
{
403 DK_DebugMetadataVersion
,
405 DK_OptimizationRemark
,
406 DK_OptimizationRemarkMissed
,
407 DK_OptimizationRemarkAnalysis
,
408 DK_OptimizationFailure
,
412 #[derive(Copy, Clone)]
413 pub enum ArchiveKind
{
420 /// Represents the different LLVM passes Rust supports
421 #[derive(Copy, Clone, PartialEq, Debug)]
423 pub enum SupportedPassKind
{
429 // Opaque pointer types
430 #[allow(missing_copy_implementations)]
431 pub enum Module_opaque {}
432 pub type ModuleRef
= *mut Module_opaque
;
433 #[allow(missing_copy_implementations)]
434 pub enum Context_opaque {}
435 pub type ContextRef
= *mut Context_opaque
;
436 #[allow(missing_copy_implementations)]
437 pub enum Type_opaque {}
438 pub type TypeRef
= *mut Type_opaque
;
439 #[allow(missing_copy_implementations)]
440 pub enum Value_opaque {}
441 pub type ValueRef
= *mut Value_opaque
;
442 #[allow(missing_copy_implementations)]
443 pub enum Metadata_opaque {}
444 pub type MetadataRef
= *mut Metadata_opaque
;
445 #[allow(missing_copy_implementations)]
446 pub enum BasicBlock_opaque {}
447 pub type BasicBlockRef
= *mut BasicBlock_opaque
;
448 #[allow(missing_copy_implementations)]
449 pub enum Builder_opaque {}
450 pub type BuilderRef
= *mut Builder_opaque
;
451 #[allow(missing_copy_implementations)]
452 pub enum ExecutionEngine_opaque {}
453 pub type ExecutionEngineRef
= *mut ExecutionEngine_opaque
;
454 #[allow(missing_copy_implementations)]
455 pub enum MemoryBuffer_opaque {}
456 pub type MemoryBufferRef
= *mut MemoryBuffer_opaque
;
457 #[allow(missing_copy_implementations)]
458 pub enum PassManager_opaque {}
459 pub type PassManagerRef
= *mut PassManager_opaque
;
460 #[allow(missing_copy_implementations)]
461 pub enum PassManagerBuilder_opaque {}
462 pub type PassManagerBuilderRef
= *mut PassManagerBuilder_opaque
;
463 #[allow(missing_copy_implementations)]
464 pub enum Use_opaque {}
465 pub type UseRef
= *mut Use_opaque
;
466 #[allow(missing_copy_implementations)]
467 pub enum TargetData_opaque {}
468 pub type TargetDataRef
= *mut TargetData_opaque
;
469 #[allow(missing_copy_implementations)]
470 pub enum ObjectFile_opaque {}
471 pub type ObjectFileRef
= *mut ObjectFile_opaque
;
472 #[allow(missing_copy_implementations)]
473 pub enum SectionIterator_opaque {}
474 pub type SectionIteratorRef
= *mut SectionIterator_opaque
;
475 #[allow(missing_copy_implementations)]
476 pub enum Pass_opaque {}
477 pub type PassRef
= *mut Pass_opaque
;
478 #[allow(missing_copy_implementations)]
479 pub enum TargetMachine_opaque {}
480 pub type TargetMachineRef
= *mut TargetMachine_opaque
;
481 pub enum Archive_opaque {}
482 pub type ArchiveRef
= *mut Archive_opaque
;
483 pub enum ArchiveIterator_opaque {}
484 pub type ArchiveIteratorRef
= *mut ArchiveIterator_opaque
;
485 pub enum ArchiveChild_opaque {}
486 pub type ArchiveChildRef
= *mut ArchiveChild_opaque
;
487 #[allow(missing_copy_implementations)]
488 pub enum Twine_opaque {}
489 pub type TwineRef
= *mut Twine_opaque
;
490 #[allow(missing_copy_implementations)]
491 pub enum DiagnosticInfo_opaque {}
492 pub type DiagnosticInfoRef
= *mut DiagnosticInfo_opaque
;
493 #[allow(missing_copy_implementations)]
494 pub enum DebugLoc_opaque {}
495 pub type DebugLocRef
= *mut DebugLoc_opaque
;
496 #[allow(missing_copy_implementations)]
497 pub enum SMDiagnostic_opaque {}
498 pub type SMDiagnosticRef
= *mut SMDiagnostic_opaque
;
499 #[allow(missing_copy_implementations)]
500 pub enum RustArchiveMember_opaque {}
501 pub type RustArchiveMemberRef
= *mut RustArchiveMember_opaque
;
502 #[allow(missing_copy_implementations)]
503 pub enum OperandBundleDef_opaque {}
504 pub type OperandBundleDefRef
= *mut OperandBundleDef_opaque
;
506 pub type DiagnosticHandler
= unsafe extern "C" fn(DiagnosticInfoRef
, *mut c_void
);
507 pub type InlineAsmDiagHandler
= unsafe extern "C" fn(SMDiagnosticRef
, *const c_void
, c_uint
);
510 pub use self::DIDescriptorFlags
::*;
511 use super::{MetadataRef}
;
513 #[allow(missing_copy_implementations)]
514 pub enum DIBuilder_opaque {}
515 pub type DIBuilderRef
= *mut DIBuilder_opaque
;
517 pub type DIDescriptor
= MetadataRef
;
518 pub type DIScope
= DIDescriptor
;
519 pub type DILocation
= DIDescriptor
;
520 pub type DIFile
= DIScope
;
521 pub type DILexicalBlock
= DIScope
;
522 pub type DISubprogram
= DIScope
;
523 pub type DINameSpace
= DIScope
;
524 pub type DIType
= DIDescriptor
;
525 pub type DIBasicType
= DIType
;
526 pub type DIDerivedType
= DIType
;
527 pub type DICompositeType
= DIDerivedType
;
528 pub type DIVariable
= DIDescriptor
;
529 pub type DIGlobalVariable
= DIDescriptor
;
530 pub type DIArray
= DIDescriptor
;
531 pub type DISubrange
= DIDescriptor
;
532 pub type DIEnumerator
= DIDescriptor
;
533 pub type DITemplateTypeParameter
= DIDescriptor
;
535 #[derive(Copy, Clone)]
536 pub enum DIDescriptorFlags
{
537 FlagPrivate
= 1 << 0,
538 FlagProtected
= 1 << 1,
539 FlagFwdDecl
= 1 << 2,
540 FlagAppleBlock
= 1 << 3,
541 FlagBlockByrefStruct
= 1 << 4,
542 FlagVirtual
= 1 << 5,
543 FlagArtificial
= 1 << 6,
544 FlagExplicit
= 1 << 7,
545 FlagPrototyped
= 1 << 8,
546 FlagObjcClassComplete
= 1 << 9,
547 FlagObjectPointer
= 1 << 10,
548 FlagVector
= 1 << 11,
549 FlagStaticMember
= 1 << 12,
550 FlagIndirectVariable
= 1 << 13,
551 FlagLValueReference
= 1 << 14,
552 FlagRValueReference
= 1 << 15
557 // Link to our native llvm bindings (things that we need to use the C++ api
558 // for) and because llvm is written in C++ we need to link against libstdc++
560 // You'll probably notice that there is an omission of all LLVM libraries
561 // from this location. This is because the set of LLVM libraries that we
562 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
563 // figure out the exact set of libraries. To do this, the build system
564 // generates an llvmdeps.rs file next to this one which will be
565 // automatically updated whenever LLVM is updated to include an up-to-date
566 // set of the libraries we need to link to LLVM for.
567 #[link(name = "rustllvm", kind = "static")]
568 #[cfg(not(cargobuild))]
571 #[linked_from = "rustllvm"] // not quite true but good enough
573 /* Create and destroy contexts. */
574 pub fn LLVMContextCreate() -> ContextRef
;
575 pub fn LLVMContextDispose(C
: ContextRef
);
576 pub fn LLVMGetMDKindIDInContext(C
: ContextRef
,
581 /* Create and destroy modules. */
582 pub fn LLVMModuleCreateWithNameInContext(ModuleID
: *const c_char
,
585 pub fn LLVMGetModuleContext(M
: ModuleRef
) -> ContextRef
;
586 pub fn LLVMCloneModule(M
: ModuleRef
) -> ModuleRef
;
587 pub fn LLVMDisposeModule(M
: ModuleRef
);
589 /// Data layout. See Module::getDataLayout.
590 pub fn LLVMGetDataLayout(M
: ModuleRef
) -> *const c_char
;
591 pub fn LLVMSetDataLayout(M
: ModuleRef
, Triple
: *const c_char
);
593 /// Target triple. See Module::getTargetTriple.
594 pub fn LLVMGetTarget(M
: ModuleRef
) -> *const c_char
;
595 pub fn LLVMSetTarget(M
: ModuleRef
, Triple
: *const c_char
);
597 /// See Module::dump.
598 pub fn LLVMDumpModule(M
: ModuleRef
);
600 /// See Module::setModuleInlineAsm.
601 pub fn LLVMSetModuleInlineAsm(M
: ModuleRef
, Asm
: *const c_char
);
603 /// See llvm::LLVMTypeKind::getTypeID.
604 pub fn LLVMGetTypeKind(Ty
: TypeRef
) -> TypeKind
;
606 /// See llvm::LLVMType::getContext.
607 pub fn LLVMGetTypeContext(Ty
: TypeRef
) -> ContextRef
;
609 /* Operations on integer types */
610 pub fn LLVMInt1TypeInContext(C
: ContextRef
) -> TypeRef
;
611 pub fn LLVMInt8TypeInContext(C
: ContextRef
) -> TypeRef
;
612 pub fn LLVMInt16TypeInContext(C
: ContextRef
) -> TypeRef
;
613 pub fn LLVMInt32TypeInContext(C
: ContextRef
) -> TypeRef
;
614 pub fn LLVMInt64TypeInContext(C
: ContextRef
) -> TypeRef
;
615 pub fn LLVMIntTypeInContext(C
: ContextRef
, NumBits
: c_uint
)
618 pub fn LLVMGetIntTypeWidth(IntegerTy
: TypeRef
) -> c_uint
;
620 /* Operations on real types */
621 pub fn LLVMFloatTypeInContext(C
: ContextRef
) -> TypeRef
;
622 pub fn LLVMDoubleTypeInContext(C
: ContextRef
) -> TypeRef
;
623 pub fn LLVMX86FP80TypeInContext(C
: ContextRef
) -> TypeRef
;
624 pub fn LLVMFP128TypeInContext(C
: ContextRef
) -> TypeRef
;
625 pub fn LLVMPPCFP128TypeInContext(C
: ContextRef
) -> TypeRef
;
627 /* Operations on function types */
628 pub fn LLVMFunctionType(ReturnType
: TypeRef
,
629 ParamTypes
: *const TypeRef
,
633 pub fn LLVMIsFunctionVarArg(FunctionTy
: TypeRef
) -> Bool
;
634 pub fn LLVMGetReturnType(FunctionTy
: TypeRef
) -> TypeRef
;
635 pub fn LLVMCountParamTypes(FunctionTy
: TypeRef
) -> c_uint
;
636 pub fn LLVMGetParamTypes(FunctionTy
: TypeRef
, Dest
: *mut TypeRef
);
638 /* Operations on struct types */
639 pub fn LLVMStructTypeInContext(C
: ContextRef
,
640 ElementTypes
: *const TypeRef
,
641 ElementCount
: c_uint
,
644 pub fn LLVMCountStructElementTypes(StructTy
: TypeRef
) -> c_uint
;
645 pub fn LLVMGetStructElementTypes(StructTy
: TypeRef
,
647 pub fn LLVMIsPackedStruct(StructTy
: TypeRef
) -> Bool
;
649 /* Operations on array, pointer, and vector types (sequence types) */
650 pub fn LLVMRustArrayType(ElementType
: TypeRef
, ElementCount
: u64) -> TypeRef
;
651 pub fn LLVMPointerType(ElementType
: TypeRef
, AddressSpace
: c_uint
)
653 pub fn LLVMVectorType(ElementType
: TypeRef
, ElementCount
: c_uint
)
656 pub fn LLVMGetElementType(Ty
: TypeRef
) -> TypeRef
;
657 pub fn LLVMGetArrayLength(ArrayTy
: TypeRef
) -> c_uint
;
658 pub fn LLVMGetPointerAddressSpace(PointerTy
: TypeRef
) -> c_uint
;
659 pub fn LLVMGetPointerToGlobal(EE
: ExecutionEngineRef
, V
: ValueRef
)
661 pub fn LLVMGetVectorSize(VectorTy
: TypeRef
) -> c_uint
;
663 /* Operations on other types */
664 pub fn LLVMVoidTypeInContext(C
: ContextRef
) -> TypeRef
;
665 pub fn LLVMLabelTypeInContext(C
: ContextRef
) -> TypeRef
;
666 pub fn LLVMMetadataTypeInContext(C
: ContextRef
) -> TypeRef
;
668 /* Operations on all values */
669 pub fn LLVMTypeOf(Val
: ValueRef
) -> TypeRef
;
670 pub fn LLVMGetValueName(Val
: ValueRef
) -> *const c_char
;
671 pub fn LLVMSetValueName(Val
: ValueRef
, Name
: *const c_char
);
672 pub fn LLVMDumpValue(Val
: ValueRef
);
673 pub fn LLVMReplaceAllUsesWith(OldVal
: ValueRef
, NewVal
: ValueRef
);
674 pub fn LLVMHasMetadata(Val
: ValueRef
) -> c_int
;
675 pub fn LLVMGetMetadata(Val
: ValueRef
, KindID
: c_uint
) -> ValueRef
;
676 pub fn LLVMSetMetadata(Val
: ValueRef
, KindID
: c_uint
, Node
: ValueRef
);
678 /* Operations on Uses */
679 pub fn LLVMGetFirstUse(Val
: ValueRef
) -> UseRef
;
680 pub fn LLVMGetNextUse(U
: UseRef
) -> UseRef
;
681 pub fn LLVMGetUser(U
: UseRef
) -> ValueRef
;
682 pub fn LLVMGetUsedValue(U
: UseRef
) -> ValueRef
;
684 /* Operations on Users */
685 pub fn LLVMGetNumOperands(Val
: ValueRef
) -> c_int
;
686 pub fn LLVMGetOperand(Val
: ValueRef
, Index
: c_uint
) -> ValueRef
;
687 pub fn LLVMSetOperand(Val
: ValueRef
, Index
: c_uint
, Op
: ValueRef
);
689 /* Operations on constants of any type */
690 pub fn LLVMConstNull(Ty
: TypeRef
) -> ValueRef
;
692 pub fn LLVMConstAllOnes(Ty
: TypeRef
) -> ValueRef
;
693 pub fn LLVMConstICmp(Pred
: c_ushort
, V1
: ValueRef
, V2
: ValueRef
)
695 pub fn LLVMConstFCmp(Pred
: c_ushort
, V1
: ValueRef
, V2
: ValueRef
)
697 /* only for isize/vector */
698 pub fn LLVMGetUndef(Ty
: TypeRef
) -> ValueRef
;
699 pub fn LLVMIsConstant(Val
: ValueRef
) -> Bool
;
700 pub fn LLVMIsNull(Val
: ValueRef
) -> Bool
;
701 pub fn LLVMIsUndef(Val
: ValueRef
) -> Bool
;
702 pub fn LLVMConstPointerNull(Ty
: TypeRef
) -> ValueRef
;
704 /* Operations on metadata */
705 pub fn LLVMMDStringInContext(C
: ContextRef
,
709 pub fn LLVMMDNodeInContext(C
: ContextRef
,
710 Vals
: *const ValueRef
,
713 pub fn LLVMAddNamedMetadataOperand(M
: ModuleRef
,
717 /* Operations on scalar constants */
718 pub fn LLVMConstInt(IntTy
: TypeRef
, N
: c_ulonglong
, SignExtend
: Bool
)
720 pub fn LLVMConstIntOfString(IntTy
: TypeRef
, Text
: *const c_char
, Radix
: u8)
722 pub fn LLVMConstIntOfStringAndSize(IntTy
: TypeRef
,
727 pub fn LLVMConstReal(RealTy
: TypeRef
, N
: f64) -> ValueRef
;
728 pub fn LLVMConstRealOfString(RealTy
: TypeRef
, Text
: *const c_char
)
730 pub fn LLVMConstRealOfStringAndSize(RealTy
: TypeRef
,
734 pub fn LLVMConstIntGetZExtValue(ConstantVal
: ValueRef
) -> c_ulonglong
;
735 pub fn LLVMConstIntGetSExtValue(ConstantVal
: ValueRef
) -> c_longlong
;
738 /* Operations on composite constants */
739 pub fn LLVMConstStringInContext(C
: ContextRef
,
742 DontNullTerminate
: Bool
)
744 pub fn LLVMConstStructInContext(C
: ContextRef
,
745 ConstantVals
: *const ValueRef
,
750 pub fn LLVMConstArray(ElementTy
: TypeRef
,
751 ConstantVals
: *const ValueRef
,
754 pub fn LLVMConstVector(ScalarConstantVals
: *const ValueRef
, Size
: c_uint
)
757 /* Constant expressions */
758 pub fn LLVMAlignOf(Ty
: TypeRef
) -> ValueRef
;
759 pub fn LLVMSizeOf(Ty
: TypeRef
) -> ValueRef
;
760 pub fn LLVMConstNeg(ConstantVal
: ValueRef
) -> ValueRef
;
761 pub fn LLVMConstNSWNeg(ConstantVal
: ValueRef
) -> ValueRef
;
762 pub fn LLVMConstNUWNeg(ConstantVal
: ValueRef
) -> ValueRef
;
763 pub fn LLVMConstFNeg(ConstantVal
: ValueRef
) -> ValueRef
;
764 pub fn LLVMConstNot(ConstantVal
: ValueRef
) -> ValueRef
;
765 pub fn LLVMConstAdd(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
767 pub fn LLVMConstNSWAdd(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
769 pub fn LLVMConstNUWAdd(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
771 pub fn LLVMConstFAdd(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
773 pub fn LLVMConstSub(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
775 pub fn LLVMConstNSWSub(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
777 pub fn LLVMConstNUWSub(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
779 pub fn LLVMConstFSub(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
781 pub fn LLVMConstMul(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
783 pub fn LLVMConstNSWMul(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
785 pub fn LLVMConstNUWMul(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
787 pub fn LLVMConstFMul(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
789 pub fn LLVMConstUDiv(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
791 pub fn LLVMConstSDiv(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
793 pub fn LLVMConstExactSDiv(LHSConstant
: ValueRef
,
794 RHSConstant
: ValueRef
)
796 pub fn LLVMConstFDiv(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
798 pub fn LLVMConstURem(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
800 pub fn LLVMConstSRem(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
802 pub fn LLVMConstFRem(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
804 pub fn LLVMConstAnd(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
806 pub fn LLVMConstOr(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
808 pub fn LLVMConstXor(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
810 pub fn LLVMConstShl(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
812 pub fn LLVMConstLShr(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
814 pub fn LLVMConstAShr(LHSConstant
: ValueRef
, RHSConstant
: ValueRef
)
816 pub fn LLVMConstGEP(ConstantVal
: ValueRef
,
817 ConstantIndices
: *const ValueRef
,
820 pub fn LLVMConstInBoundsGEP(ConstantVal
: ValueRef
,
821 ConstantIndices
: *const ValueRef
,
824 pub fn LLVMConstTrunc(ConstantVal
: ValueRef
, ToType
: TypeRef
)
826 pub fn LLVMConstSExt(ConstantVal
: ValueRef
, ToType
: TypeRef
)
828 pub fn LLVMConstZExt(ConstantVal
: ValueRef
, ToType
: TypeRef
)
830 pub fn LLVMConstFPTrunc(ConstantVal
: ValueRef
, ToType
: TypeRef
)
832 pub fn LLVMConstFPExt(ConstantVal
: ValueRef
, ToType
: TypeRef
)
834 pub fn LLVMConstUIToFP(ConstantVal
: ValueRef
, ToType
: TypeRef
)
836 pub fn LLVMConstSIToFP(ConstantVal
: ValueRef
, ToType
: TypeRef
)
838 pub fn LLVMConstFPToUI(ConstantVal
: ValueRef
, ToType
: TypeRef
)
840 pub fn LLVMConstFPToSI(ConstantVal
: ValueRef
, ToType
: TypeRef
)
842 pub fn LLVMConstPtrToInt(ConstantVal
: ValueRef
, ToType
: TypeRef
)
844 pub fn LLVMConstIntToPtr(ConstantVal
: ValueRef
, ToType
: TypeRef
)
846 pub fn LLVMConstBitCast(ConstantVal
: ValueRef
, ToType
: TypeRef
)
848 pub fn LLVMConstZExtOrBitCast(ConstantVal
: ValueRef
, ToType
: TypeRef
)
850 pub fn LLVMConstSExtOrBitCast(ConstantVal
: ValueRef
, ToType
: TypeRef
)
852 pub fn LLVMConstTruncOrBitCast(ConstantVal
: ValueRef
, ToType
: TypeRef
)
854 pub fn LLVMConstPointerCast(ConstantVal
: ValueRef
, ToType
: TypeRef
)
856 pub fn LLVMConstIntCast(ConstantVal
: ValueRef
,
860 pub fn LLVMConstFPCast(ConstantVal
: ValueRef
, ToType
: TypeRef
)
862 pub fn LLVMConstSelect(ConstantCondition
: ValueRef
,
863 ConstantIfTrue
: ValueRef
,
864 ConstantIfFalse
: ValueRef
)
866 pub fn LLVMConstExtractElement(VectorConstant
: ValueRef
,
867 IndexConstant
: ValueRef
)
869 pub fn LLVMConstInsertElement(VectorConstant
: ValueRef
,
870 ElementValueConstant
: ValueRef
,
871 IndexConstant
: ValueRef
)
873 pub fn LLVMConstShuffleVector(VectorAConstant
: ValueRef
,
874 VectorBConstant
: ValueRef
,
875 MaskConstant
: ValueRef
)
877 pub fn LLVMConstExtractValue(AggConstant
: ValueRef
,
878 IdxList
: *const c_uint
,
881 pub fn LLVMConstInsertValue(AggConstant
: ValueRef
,
882 ElementValueConstant
: ValueRef
,
883 IdxList
: *const c_uint
,
886 pub fn LLVMConstInlineAsm(Ty
: TypeRef
,
887 AsmString
: *const c_char
,
888 Constraints
: *const c_char
,
889 HasSideEffects
: Bool
,
892 pub fn LLVMBlockAddress(F
: ValueRef
, BB
: BasicBlockRef
) -> ValueRef
;
896 /* Operations on global variables, functions, and aliases (globals) */
897 pub fn LLVMGetGlobalParent(Global
: ValueRef
) -> ModuleRef
;
898 pub fn LLVMIsDeclaration(Global
: ValueRef
) -> Bool
;
899 pub fn LLVMGetLinkage(Global
: ValueRef
) -> c_uint
;
900 pub fn LLVMSetLinkage(Global
: ValueRef
, Link
: c_uint
);
901 pub fn LLVMGetSection(Global
: ValueRef
) -> *const c_char
;
902 pub fn LLVMSetSection(Global
: ValueRef
, Section
: *const c_char
);
903 pub fn LLVMGetVisibility(Global
: ValueRef
) -> c_uint
;
904 pub fn LLVMSetVisibility(Global
: ValueRef
, Viz
: c_uint
);
905 pub fn LLVMGetAlignment(Global
: ValueRef
) -> c_uint
;
906 pub fn LLVMSetAlignment(Global
: ValueRef
, Bytes
: c_uint
);
909 /* Operations on global variables */
910 pub fn LLVMIsAGlobalVariable(GlobalVar
: ValueRef
) -> ValueRef
;
911 pub fn LLVMAddGlobal(M
: ModuleRef
, Ty
: TypeRef
, Name
: *const c_char
)
913 pub fn LLVMAddGlobalInAddressSpace(M
: ModuleRef
,
916 AddressSpace
: c_uint
)
918 pub fn LLVMGetNamedGlobal(M
: ModuleRef
, Name
: *const c_char
) -> ValueRef
;
919 pub fn LLVMGetOrInsertGlobal(M
: ModuleRef
, Name
: *const c_char
, T
: TypeRef
) -> ValueRef
;
920 pub fn LLVMGetFirstGlobal(M
: ModuleRef
) -> ValueRef
;
921 pub fn LLVMGetLastGlobal(M
: ModuleRef
) -> ValueRef
;
922 pub fn LLVMGetNextGlobal(GlobalVar
: ValueRef
) -> ValueRef
;
923 pub fn LLVMGetPreviousGlobal(GlobalVar
: ValueRef
) -> ValueRef
;
924 pub fn LLVMDeleteGlobal(GlobalVar
: ValueRef
);
925 pub fn LLVMGetInitializer(GlobalVar
: ValueRef
) -> ValueRef
;
926 pub fn LLVMSetInitializer(GlobalVar
: ValueRef
,
927 ConstantVal
: ValueRef
);
928 pub fn LLVMIsThreadLocal(GlobalVar
: ValueRef
) -> Bool
;
929 pub fn LLVMSetThreadLocal(GlobalVar
: ValueRef
, IsThreadLocal
: Bool
);
930 pub fn LLVMIsGlobalConstant(GlobalVar
: ValueRef
) -> Bool
;
931 pub fn LLVMSetGlobalConstant(GlobalVar
: ValueRef
, IsConstant
: Bool
);
932 pub fn LLVMGetNamedValue(M
: ModuleRef
, Name
: *const c_char
) -> ValueRef
;
934 /* Operations on aliases */
935 pub fn LLVMAddAlias(M
: ModuleRef
,
941 /* Operations on functions */
942 pub fn LLVMAddFunction(M
: ModuleRef
,
946 pub fn LLVMGetNamedFunction(M
: ModuleRef
, Name
: *const c_char
) -> ValueRef
;
947 pub fn LLVMGetFirstFunction(M
: ModuleRef
) -> ValueRef
;
948 pub fn LLVMGetLastFunction(M
: ModuleRef
) -> ValueRef
;
949 pub fn LLVMGetNextFunction(Fn
: ValueRef
) -> ValueRef
;
950 pub fn LLVMGetPreviousFunction(Fn
: ValueRef
) -> ValueRef
;
951 pub fn LLVMDeleteFunction(Fn
: ValueRef
);
952 pub fn LLVMGetOrInsertFunction(M
: ModuleRef
,
956 pub fn LLVMGetIntrinsicID(Fn
: ValueRef
) -> c_uint
;
957 pub fn LLVMGetFunctionCallConv(Fn
: ValueRef
) -> c_uint
;
958 pub fn LLVMSetFunctionCallConv(Fn
: ValueRef
, CC
: c_uint
);
959 pub fn LLVMGetGC(Fn
: ValueRef
) -> *const c_char
;
960 pub fn LLVMSetGC(Fn
: ValueRef
, Name
: *const c_char
);
961 pub fn LLVMAddDereferenceableAttr(Fn
: ValueRef
, index
: c_uint
, bytes
: uint64_t
);
962 pub fn LLVMAddFunctionAttribute(Fn
: ValueRef
, index
: c_uint
, PA
: uint64_t
);
963 pub fn LLVMAddFunctionAttrString(Fn
: ValueRef
, index
: c_uint
, Name
: *const c_char
);
964 pub fn LLVMAddFunctionAttrStringValue(Fn
: ValueRef
, index
: c_uint
,
966 Value
: *const c_char
);
967 pub fn LLVMRemoveFunctionAttributes(Fn
: ValueRef
, index
: c_uint
, attr
: uint64_t
);
968 pub fn LLVMRemoveFunctionAttrString(Fn
: ValueRef
, index
: c_uint
, Name
: *const c_char
);
969 pub fn LLVMGetFunctionAttr(Fn
: ValueRef
) -> c_uint
;
970 pub fn LLVMRemoveFunctionAttr(Fn
: ValueRef
, val
: c_uint
);
972 /* Operations on parameters */
973 pub fn LLVMCountParams(Fn
: ValueRef
) -> c_uint
;
974 pub fn LLVMGetParams(Fn
: ValueRef
, Params
: *const ValueRef
);
975 pub fn LLVMGetParam(Fn
: ValueRef
, Index
: c_uint
) -> ValueRef
;
976 pub fn LLVMGetParamParent(Inst
: ValueRef
) -> ValueRef
;
977 pub fn LLVMGetFirstParam(Fn
: ValueRef
) -> ValueRef
;
978 pub fn LLVMGetLastParam(Fn
: ValueRef
) -> ValueRef
;
979 pub fn LLVMGetNextParam(Arg
: ValueRef
) -> ValueRef
;
980 pub fn LLVMGetPreviousParam(Arg
: ValueRef
) -> ValueRef
;
981 pub fn LLVMAddAttribute(Arg
: ValueRef
, PA
: c_uint
);
982 pub fn LLVMRemoveAttribute(Arg
: ValueRef
, PA
: c_uint
);
983 pub fn LLVMGetAttribute(Arg
: ValueRef
) -> c_uint
;
984 pub fn LLVMSetParamAlignment(Arg
: ValueRef
, align
: c_uint
);
986 /* Operations on basic blocks */
987 pub fn LLVMBasicBlockAsValue(BB
: BasicBlockRef
) -> ValueRef
;
988 pub fn LLVMValueIsBasicBlock(Val
: ValueRef
) -> Bool
;
989 pub fn LLVMValueAsBasicBlock(Val
: ValueRef
) -> BasicBlockRef
;
990 pub fn LLVMGetBasicBlockParent(BB
: BasicBlockRef
) -> ValueRef
;
991 pub fn LLVMCountBasicBlocks(Fn
: ValueRef
) -> c_uint
;
992 pub fn LLVMGetBasicBlocks(Fn
: ValueRef
, BasicBlocks
: *const ValueRef
);
993 pub fn LLVMGetFirstBasicBlock(Fn
: ValueRef
) -> BasicBlockRef
;
994 pub fn LLVMGetLastBasicBlock(Fn
: ValueRef
) -> BasicBlockRef
;
995 pub fn LLVMGetNextBasicBlock(BB
: BasicBlockRef
) -> BasicBlockRef
;
996 pub fn LLVMGetPreviousBasicBlock(BB
: BasicBlockRef
) -> BasicBlockRef
;
997 pub fn LLVMGetEntryBasicBlock(Fn
: ValueRef
) -> BasicBlockRef
;
999 pub fn LLVMAppendBasicBlockInContext(C
: ContextRef
,
1001 Name
: *const c_char
)
1003 pub fn LLVMInsertBasicBlockInContext(C
: ContextRef
,
1005 Name
: *const c_char
)
1007 pub fn LLVMDeleteBasicBlock(BB
: BasicBlockRef
);
1009 pub fn LLVMMoveBasicBlockAfter(BB
: BasicBlockRef
,
1010 MoveAfter
: BasicBlockRef
);
1012 pub fn LLVMMoveBasicBlockBefore(BB
: BasicBlockRef
,
1013 MoveBefore
: BasicBlockRef
);
1015 /* Operations on instructions */
1016 pub fn LLVMGetInstructionParent(Inst
: ValueRef
) -> BasicBlockRef
;
1017 pub fn LLVMGetFirstInstruction(BB
: BasicBlockRef
) -> ValueRef
;
1018 pub fn LLVMGetLastInstruction(BB
: BasicBlockRef
) -> ValueRef
;
1019 pub fn LLVMGetNextInstruction(Inst
: ValueRef
) -> ValueRef
;
1020 pub fn LLVMGetPreviousInstruction(Inst
: ValueRef
) -> ValueRef
;
1021 pub fn LLVMInstructionEraseFromParent(Inst
: ValueRef
);
1023 /* Operations on call sites */
1024 pub fn LLVMSetInstructionCallConv(Instr
: ValueRef
, CC
: c_uint
);
1025 pub fn LLVMGetInstructionCallConv(Instr
: ValueRef
) -> c_uint
;
1026 pub fn LLVMAddInstrAttribute(Instr
: ValueRef
,
1029 pub fn LLVMRemoveInstrAttribute(Instr
: ValueRef
,
1032 pub fn LLVMSetInstrParamAlignment(Instr
: ValueRef
,
1035 pub fn LLVMAddCallSiteAttribute(Instr
: ValueRef
,
1038 pub fn LLVMAddDereferenceableCallSiteAttr(Instr
: ValueRef
,
1042 /* Operations on call instructions (only) */
1043 pub fn LLVMIsTailCall(CallInst
: ValueRef
) -> Bool
;
1044 pub fn LLVMSetTailCall(CallInst
: ValueRef
, IsTailCall
: Bool
);
1046 /* Operations on load/store instructions (only) */
1047 pub fn LLVMGetVolatile(MemoryAccessInst
: ValueRef
) -> Bool
;
1048 pub fn LLVMSetVolatile(MemoryAccessInst
: ValueRef
, volatile
: Bool
);
1050 /* Operations on phi nodes */
1051 pub fn LLVMAddIncoming(PhiNode
: ValueRef
,
1052 IncomingValues
: *const ValueRef
,
1053 IncomingBlocks
: *const BasicBlockRef
,
1055 pub fn LLVMCountIncoming(PhiNode
: ValueRef
) -> c_uint
;
1056 pub fn LLVMGetIncomingValue(PhiNode
: ValueRef
, Index
: c_uint
)
1058 pub fn LLVMGetIncomingBlock(PhiNode
: ValueRef
, Index
: c_uint
)
1061 /* Instruction builders */
1062 pub fn LLVMCreateBuilderInContext(C
: ContextRef
) -> BuilderRef
;
1063 pub fn LLVMPositionBuilder(Builder
: BuilderRef
,
1064 Block
: BasicBlockRef
,
1066 pub fn LLVMPositionBuilderBefore(Builder
: BuilderRef
,
1068 pub fn LLVMPositionBuilderAtEnd(Builder
: BuilderRef
,
1069 Block
: BasicBlockRef
);
1070 pub fn LLVMGetInsertBlock(Builder
: BuilderRef
) -> BasicBlockRef
;
1071 pub fn LLVMClearInsertionPosition(Builder
: BuilderRef
);
1072 pub fn LLVMInsertIntoBuilder(Builder
: BuilderRef
, Instr
: ValueRef
);
1073 pub fn LLVMInsertIntoBuilderWithName(Builder
: BuilderRef
,
1075 Name
: *const c_char
);
1076 pub fn LLVMDisposeBuilder(Builder
: BuilderRef
);
1078 /* Execution engine */
1079 pub fn LLVMBuildExecutionEngine(Mod
: ModuleRef
) -> ExecutionEngineRef
;
1080 pub fn LLVMDisposeExecutionEngine(EE
: ExecutionEngineRef
);
1081 pub fn LLVMExecutionEngineFinalizeObject(EE
: ExecutionEngineRef
);
1082 pub fn LLVMRustLoadDynamicLibrary(path
: *const c_char
) -> Bool
;
1083 pub fn LLVMExecutionEngineAddModule(EE
: ExecutionEngineRef
, M
: ModuleRef
);
1084 pub fn LLVMExecutionEngineRemoveModule(EE
: ExecutionEngineRef
, M
: ModuleRef
)
1088 pub fn LLVMSetCurrentDebugLocation(Builder
: BuilderRef
, L
: ValueRef
);
1089 pub fn LLVMGetCurrentDebugLocation(Builder
: BuilderRef
) -> ValueRef
;
1090 pub fn LLVMSetInstDebugLocation(Builder
: BuilderRef
, Inst
: ValueRef
);
1093 pub fn LLVMBuildRetVoid(B
: BuilderRef
) -> ValueRef
;
1094 pub fn LLVMBuildRet(B
: BuilderRef
, V
: ValueRef
) -> ValueRef
;
1095 pub fn LLVMBuildAggregateRet(B
: BuilderRef
,
1096 RetVals
: *const ValueRef
,
1099 pub fn LLVMBuildBr(B
: BuilderRef
, Dest
: BasicBlockRef
) -> ValueRef
;
1100 pub fn LLVMBuildCondBr(B
: BuilderRef
,
1102 Then
: BasicBlockRef
,
1103 Else
: BasicBlockRef
)
1105 pub fn LLVMBuildSwitch(B
: BuilderRef
,
1107 Else
: BasicBlockRef
,
1110 pub fn LLVMBuildIndirectBr(B
: BuilderRef
,
1114 pub fn LLVMRustBuildInvoke(B
: BuilderRef
,
1116 Args
: *const ValueRef
,
1118 Then
: BasicBlockRef
,
1119 Catch
: BasicBlockRef
,
1120 Bundle
: OperandBundleDefRef
,
1121 Name
: *const c_char
)
1123 pub fn LLVMRustBuildLandingPad(B
: BuilderRef
,
1127 Name
: *const c_char
,
1130 pub fn LLVMBuildResume(B
: BuilderRef
, Exn
: ValueRef
) -> ValueRef
;
1131 pub fn LLVMBuildUnreachable(B
: BuilderRef
) -> ValueRef
;
1133 pub fn LLVMRustBuildCleanupPad(B
: BuilderRef
,
1134 ParentPad
: ValueRef
,
1136 Args
: *const ValueRef
,
1137 Name
: *const c_char
) -> ValueRef
;
1138 pub fn LLVMRustBuildCleanupRet(B
: BuilderRef
,
1139 CleanupPad
: ValueRef
,
1140 UnwindBB
: BasicBlockRef
) -> ValueRef
;
1141 pub fn LLVMRustBuildCatchPad(B
: BuilderRef
,
1142 ParentPad
: ValueRef
,
1144 Args
: *const ValueRef
,
1145 Name
: *const c_char
) -> ValueRef
;
1146 pub fn LLVMRustBuildCatchRet(B
: BuilderRef
,
1148 BB
: BasicBlockRef
) -> ValueRef
;
1149 pub fn LLVMRustBuildCatchSwitch(Builder
: BuilderRef
,
1150 ParentPad
: ValueRef
,
1152 NumHandlers
: c_uint
,
1153 Name
: *const c_char
) -> ValueRef
;
1154 pub fn LLVMRustAddHandler(CatchSwitch
: ValueRef
,
1155 Handler
: BasicBlockRef
);
1156 pub fn LLVMRustSetPersonalityFn(B
: BuilderRef
, Pers
: ValueRef
);
1158 /* Add a case to the switch instruction */
1159 pub fn LLVMAddCase(Switch
: ValueRef
,
1161 Dest
: BasicBlockRef
);
1163 /* Add a destination to the indirectbr instruction */
1164 pub fn LLVMAddDestination(IndirectBr
: ValueRef
, Dest
: BasicBlockRef
);
1166 /* Add a clause to the landing pad instruction */
1167 pub fn LLVMAddClause(LandingPad
: ValueRef
, ClauseVal
: ValueRef
);
1169 /* Set the cleanup on a landing pad instruction */
1170 pub fn LLVMSetCleanup(LandingPad
: ValueRef
, Val
: Bool
);
1173 pub fn LLVMBuildAdd(B
: BuilderRef
,
1176 Name
: *const c_char
)
1178 pub fn LLVMBuildNSWAdd(B
: BuilderRef
,
1181 Name
: *const c_char
)
1183 pub fn LLVMBuildNUWAdd(B
: BuilderRef
,
1186 Name
: *const c_char
)
1188 pub fn LLVMBuildFAdd(B
: BuilderRef
,
1191 Name
: *const c_char
)
1193 pub fn LLVMBuildSub(B
: BuilderRef
,
1196 Name
: *const c_char
)
1198 pub fn LLVMBuildNSWSub(B
: BuilderRef
,
1201 Name
: *const c_char
)
1203 pub fn LLVMBuildNUWSub(B
: BuilderRef
,
1206 Name
: *const c_char
)
1208 pub fn LLVMBuildFSub(B
: BuilderRef
,
1211 Name
: *const c_char
)
1213 pub fn LLVMBuildMul(B
: BuilderRef
,
1216 Name
: *const c_char
)
1218 pub fn LLVMBuildNSWMul(B
: BuilderRef
,
1221 Name
: *const c_char
)
1223 pub fn LLVMBuildNUWMul(B
: BuilderRef
,
1226 Name
: *const c_char
)
1228 pub fn LLVMBuildFMul(B
: BuilderRef
,
1231 Name
: *const c_char
)
1233 pub fn LLVMBuildUDiv(B
: BuilderRef
,
1236 Name
: *const c_char
)
1238 pub fn LLVMBuildSDiv(B
: BuilderRef
,
1241 Name
: *const c_char
)
1243 pub fn LLVMBuildExactSDiv(B
: BuilderRef
,
1246 Name
: *const c_char
)
1248 pub fn LLVMBuildFDiv(B
: BuilderRef
,
1251 Name
: *const c_char
)
1253 pub fn LLVMBuildURem(B
: BuilderRef
,
1256 Name
: *const c_char
)
1258 pub fn LLVMBuildSRem(B
: BuilderRef
,
1261 Name
: *const c_char
)
1263 pub fn LLVMBuildFRem(B
: BuilderRef
,
1266 Name
: *const c_char
)
1268 pub fn LLVMBuildShl(B
: BuilderRef
,
1271 Name
: *const c_char
)
1273 pub fn LLVMBuildLShr(B
: BuilderRef
,
1276 Name
: *const c_char
)
1278 pub fn LLVMBuildAShr(B
: BuilderRef
,
1281 Name
: *const c_char
)
1283 pub fn LLVMBuildAnd(B
: BuilderRef
,
1286 Name
: *const c_char
)
1288 pub fn LLVMBuildOr(B
: BuilderRef
,
1291 Name
: *const c_char
)
1293 pub fn LLVMBuildXor(B
: BuilderRef
,
1296 Name
: *const c_char
)
1298 pub fn LLVMBuildBinOp(B
: BuilderRef
,
1302 Name
: *const c_char
)
1304 pub fn LLVMBuildNeg(B
: BuilderRef
, V
: ValueRef
, Name
: *const c_char
)
1306 pub fn LLVMBuildNSWNeg(B
: BuilderRef
, V
: ValueRef
, Name
: *const c_char
)
1308 pub fn LLVMBuildNUWNeg(B
: BuilderRef
, V
: ValueRef
, Name
: *const c_char
)
1310 pub fn LLVMBuildFNeg(B
: BuilderRef
, V
: ValueRef
, Name
: *const c_char
)
1312 pub fn LLVMBuildNot(B
: BuilderRef
, V
: ValueRef
, Name
: *const c_char
)
1314 pub fn LLVMRustSetHasUnsafeAlgebra(Instr
: ValueRef
);
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 LLVMRustBuildCall(B
: BuilderRef
,
1470 Args
: *const ValueRef
,
1472 Bundle
: OperandBundleDefRef
,
1473 Name
: *const c_char
)
1475 pub fn LLVMBuildSelect(B
: BuilderRef
,
1479 Name
: *const c_char
)
1481 pub fn LLVMBuildVAArg(B
: BuilderRef
,
1484 Name
: *const c_char
)
1486 pub fn LLVMBuildExtractElement(B
: BuilderRef
,
1489 Name
: *const c_char
)
1491 pub fn LLVMBuildInsertElement(B
: BuilderRef
,
1495 Name
: *const c_char
)
1497 pub fn LLVMBuildShuffleVector(B
: BuilderRef
,
1501 Name
: *const c_char
)
1503 pub fn LLVMBuildExtractValue(B
: BuilderRef
,
1506 Name
: *const c_char
)
1508 pub fn LLVMBuildInsertValue(B
: BuilderRef
,
1512 Name
: *const c_char
)
1515 pub fn LLVMBuildIsNull(B
: BuilderRef
, Val
: ValueRef
, Name
: *const c_char
)
1517 pub fn LLVMBuildIsNotNull(B
: BuilderRef
, Val
: ValueRef
, Name
: *const c_char
)
1519 pub fn LLVMBuildPtrDiff(B
: BuilderRef
,
1522 Name
: *const c_char
)
1525 /* Atomic Operations */
1526 pub fn LLVMBuildAtomicLoad(B
: BuilderRef
,
1527 PointerVal
: ValueRef
,
1528 Name
: *const c_char
,
1529 Order
: AtomicOrdering
,
1533 pub fn LLVMBuildAtomicStore(B
: BuilderRef
,
1536 Order
: AtomicOrdering
,
1540 pub fn LLVMBuildAtomicCmpXchg(B
: BuilderRef
,
1544 Order
: AtomicOrdering
,
1545 FailureOrder
: AtomicOrdering
,
1548 pub fn LLVMBuildAtomicRMW(B
: BuilderRef
,
1552 Order
: AtomicOrdering
,
1553 SingleThreaded
: Bool
)
1556 pub fn LLVMBuildAtomicFence(B
: BuilderRef
,
1557 Order
: AtomicOrdering
,
1558 Scope
: SynchronizationScope
);
1561 /* Selected entries from the downcasts. */
1562 pub fn LLVMIsATerminatorInst(Inst
: ValueRef
) -> ValueRef
;
1563 pub fn LLVMIsAStoreInst(Inst
: ValueRef
) -> ValueRef
;
1565 /// Writes a module to the specified path. Returns 0 on success.
1566 pub fn LLVMWriteBitcodeToFile(M
: ModuleRef
, Path
: *const c_char
) -> c_int
;
1568 /// Creates target data from a target layout string.
1569 pub fn LLVMCreateTargetData(StringRep
: *const c_char
) -> TargetDataRef
;
1570 /// Adds the target data to the given pass manager. The pass manager
1571 /// references the target data only weakly.
1572 pub fn LLVMAddTargetData(TD
: TargetDataRef
, PM
: PassManagerRef
);
1573 /// Number of bytes clobbered when doing a Store to *T.
1574 pub fn LLVMStoreSizeOfType(TD
: TargetDataRef
, Ty
: TypeRef
)
1577 /// Number of bytes clobbered when doing a Store to *T.
1578 pub fn LLVMSizeOfTypeInBits(TD
: TargetDataRef
, Ty
: TypeRef
)
1581 /// Distance between successive elements in an array of T. Includes ABI padding.
1582 pub fn LLVMABISizeOfType(TD
: TargetDataRef
, Ty
: TypeRef
) -> c_ulonglong
;
1584 /// Returns the preferred alignment of a type.
1585 pub fn LLVMPreferredAlignmentOfType(TD
: TargetDataRef
, Ty
: TypeRef
)
1587 /// Returns the minimum alignment of a type.
1588 pub fn LLVMABIAlignmentOfType(TD
: TargetDataRef
, Ty
: TypeRef
)
1591 /// Computes the byte offset of the indexed struct element for a
1593 pub fn LLVMOffsetOfElement(TD
: TargetDataRef
,
1598 /// Returns the minimum alignment of a type when part of a call frame.
1599 pub fn LLVMCallFrameAlignmentOfType(TD
: TargetDataRef
, Ty
: TypeRef
)
1602 /// Disposes target data.
1603 pub fn LLVMDisposeTargetData(TD
: TargetDataRef
);
1605 /// Creates a pass manager.
1606 pub fn LLVMCreatePassManager() -> PassManagerRef
;
1608 /// Creates a function-by-function pass manager
1609 pub fn LLVMCreateFunctionPassManagerForModule(M
: ModuleRef
)
1612 /// Disposes a pass manager.
1613 pub fn LLVMDisposePassManager(PM
: PassManagerRef
);
1615 /// Runs a pass manager on a module.
1616 pub fn LLVMRunPassManager(PM
: PassManagerRef
, M
: ModuleRef
) -> Bool
;
1618 /// Runs the function passes on the provided function.
1619 pub fn LLVMRunFunctionPassManager(FPM
: PassManagerRef
, F
: ValueRef
)
1622 /// Initializes all the function passes scheduled in the manager
1623 pub fn LLVMInitializeFunctionPassManager(FPM
: PassManagerRef
) -> Bool
;
1625 /// Finalizes all the function passes scheduled in the manager
1626 pub fn LLVMFinalizeFunctionPassManager(FPM
: PassManagerRef
) -> Bool
;
1628 pub fn LLVMInitializePasses();
1630 /// Adds a verification pass.
1631 pub fn LLVMAddVerifierPass(PM
: PassManagerRef
);
1633 pub fn LLVMAddGlobalOptimizerPass(PM
: PassManagerRef
);
1634 pub fn LLVMAddIPSCCPPass(PM
: PassManagerRef
);
1635 pub fn LLVMAddDeadArgEliminationPass(PM
: PassManagerRef
);
1636 pub fn LLVMAddInstructionCombiningPass(PM
: PassManagerRef
);
1637 pub fn LLVMAddCFGSimplificationPass(PM
: PassManagerRef
);
1638 pub fn LLVMAddFunctionInliningPass(PM
: PassManagerRef
);
1639 pub fn LLVMAddFunctionAttrsPass(PM
: PassManagerRef
);
1640 pub fn LLVMAddScalarReplAggregatesPass(PM
: PassManagerRef
);
1641 pub fn LLVMAddScalarReplAggregatesPassSSA(PM
: PassManagerRef
);
1642 pub fn LLVMAddJumpThreadingPass(PM
: PassManagerRef
);
1643 pub fn LLVMAddConstantPropagationPass(PM
: PassManagerRef
);
1644 pub fn LLVMAddReassociatePass(PM
: PassManagerRef
);
1645 pub fn LLVMAddLoopRotatePass(PM
: PassManagerRef
);
1646 pub fn LLVMAddLICMPass(PM
: PassManagerRef
);
1647 pub fn LLVMAddLoopUnswitchPass(PM
: PassManagerRef
);
1648 pub fn LLVMAddLoopDeletionPass(PM
: PassManagerRef
);
1649 pub fn LLVMAddLoopUnrollPass(PM
: PassManagerRef
);
1650 pub fn LLVMAddGVNPass(PM
: PassManagerRef
);
1651 pub fn LLVMAddMemCpyOptPass(PM
: PassManagerRef
);
1652 pub fn LLVMAddSCCPPass(PM
: PassManagerRef
);
1653 pub fn LLVMAddDeadStoreEliminationPass(PM
: PassManagerRef
);
1654 pub fn LLVMAddStripDeadPrototypesPass(PM
: PassManagerRef
);
1655 pub fn LLVMAddConstantMergePass(PM
: PassManagerRef
);
1656 pub fn LLVMAddArgumentPromotionPass(PM
: PassManagerRef
);
1657 pub fn LLVMAddTailCallEliminationPass(PM
: PassManagerRef
);
1658 pub fn LLVMAddIndVarSimplifyPass(PM
: PassManagerRef
);
1659 pub fn LLVMAddAggressiveDCEPass(PM
: PassManagerRef
);
1660 pub fn LLVMAddGlobalDCEPass(PM
: PassManagerRef
);
1661 pub fn LLVMAddCorrelatedValuePropagationPass(PM
: PassManagerRef
);
1662 pub fn LLVMAddPruneEHPass(PM
: PassManagerRef
);
1663 pub fn LLVMAddSimplifyLibCallsPass(PM
: PassManagerRef
);
1664 pub fn LLVMAddLoopIdiomPass(PM
: PassManagerRef
);
1665 pub fn LLVMAddEarlyCSEPass(PM
: PassManagerRef
);
1666 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM
: PassManagerRef
);
1667 pub fn LLVMAddBasicAliasAnalysisPass(PM
: PassManagerRef
);
1669 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef
;
1670 pub fn LLVMPassManagerBuilderDispose(PMB
: PassManagerBuilderRef
);
1671 pub fn LLVMPassManagerBuilderSetOptLevel(PMB
: PassManagerBuilderRef
,
1672 OptimizationLevel
: c_uint
);
1673 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB
: PassManagerBuilderRef
,
1675 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1676 PMB
: PassManagerBuilderRef
,
1678 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1679 PMB
: PassManagerBuilderRef
,
1681 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1682 PMB
: PassManagerBuilderRef
,
1684 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1685 PMB
: PassManagerBuilderRef
,
1687 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1688 PMB
: PassManagerBuilderRef
,
1689 PM
: PassManagerRef
);
1691 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1692 PMB
: PassManagerBuilderRef
,
1693 PM
: PassManagerRef
);
1694 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1695 PMB
: PassManagerBuilderRef
,
1700 /// Destroys a memory buffer.
1701 pub fn LLVMDisposeMemoryBuffer(MemBuf
: MemoryBufferRef
);
1704 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1706 /// Opens an object file.
1707 pub fn LLVMCreateObjectFile(MemBuf
: MemoryBufferRef
) -> ObjectFileRef
;
1708 /// Closes an object file.
1709 pub fn LLVMDisposeObjectFile(ObjFile
: ObjectFileRef
);
1711 /// Enumerates the sections in an object file.
1712 pub fn LLVMGetSections(ObjFile
: ObjectFileRef
) -> SectionIteratorRef
;
1713 /// Destroys a section iterator.
1714 pub fn LLVMDisposeSectionIterator(SI
: SectionIteratorRef
);
1715 /// Returns true if the section iterator is at the end of the section
1717 pub fn LLVMIsSectionIteratorAtEnd(ObjFile
: ObjectFileRef
,
1718 SI
: SectionIteratorRef
)
1720 /// Moves the section iterator to point to the next section.
1721 pub fn LLVMMoveToNextSection(SI
: SectionIteratorRef
);
1722 /// Returns the current section size.
1723 pub fn LLVMGetSectionSize(SI
: SectionIteratorRef
) -> c_ulonglong
;
1724 /// Returns the current section contents as a string buffer.
1725 pub fn LLVMGetSectionContents(SI
: SectionIteratorRef
) -> *const c_char
;
1727 /// Reads the given file and returns it as a memory buffer. Use
1728 /// LLVMDisposeMemoryBuffer() to get rid of it.
1729 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path
: *const c_char
)
1731 /// Borrows the contents of the memory buffer (doesn't copy it)
1732 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData
: *const c_char
,
1733 InputDataLength
: size_t
,
1734 BufferName
: *const c_char
,
1737 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData
: *const c_char
,
1738 InputDataLength
: size_t
,
1739 BufferName
: *const c_char
)
1742 pub fn LLVMIsMultithreaded() -> Bool
;
1743 pub fn LLVMStartMultithreaded() -> Bool
;
1745 /// Returns a string describing the last error caused by an LLVMRust* call.
1746 pub fn LLVMRustGetLastError() -> *const c_char
;
1748 /// Print the pass timings since static dtors aren't picking them up.
1749 pub fn LLVMRustPrintPassTimings();
1751 pub fn LLVMStructCreateNamed(C
: ContextRef
, Name
: *const c_char
) -> TypeRef
;
1753 pub fn LLVMStructSetBody(StructTy
: TypeRef
,
1754 ElementTypes
: *const TypeRef
,
1755 ElementCount
: c_uint
,
1758 pub fn LLVMConstNamedStruct(S
: TypeRef
,
1759 ConstantVals
: *const ValueRef
,
1763 /// Enables LLVM debug output.
1764 pub fn LLVMSetDebug(Enabled
: c_int
);
1766 /// Prepares inline assembly.
1767 pub fn LLVMInlineAsm(Ty
: TypeRef
,
1768 AsmString
: *const c_char
,
1769 Constraints
: *const c_char
,
1775 pub fn LLVMRustDebugMetadataVersion() -> u32;
1776 pub fn LLVMVersionMajor() -> u32;
1777 pub fn LLVMVersionMinor() -> u32;
1779 pub fn LLVMRustAddModuleFlag(M
: ModuleRef
,
1780 name
: *const c_char
,
1783 pub fn LLVMDIBuilderCreate(M
: ModuleRef
) -> DIBuilderRef
;
1785 pub fn LLVMDIBuilderDispose(Builder
: DIBuilderRef
);
1787 pub fn LLVMDIBuilderFinalize(Builder
: DIBuilderRef
);
1789 pub fn LLVMDIBuilderCreateCompileUnit(Builder
: DIBuilderRef
,
1791 File
: *const c_char
,
1793 Producer
: *const c_char
,
1795 Flags
: *const c_char
,
1797 SplitName
: *const c_char
)
1800 pub fn LLVMDIBuilderCreateFile(Builder
: DIBuilderRef
,
1801 Filename
: *const c_char
,
1802 Directory
: *const c_char
)
1805 pub fn LLVMDIBuilderCreateSubroutineType(Builder
: DIBuilderRef
,
1807 ParameterTypes
: DIArray
)
1810 pub fn LLVMDIBuilderCreateFunction(Builder
: DIBuilderRef
,
1811 Scope
: DIDescriptor
,
1812 Name
: *const c_char
,
1813 LinkageName
: *const c_char
,
1817 isLocalToUnit
: bool
,
1827 pub fn LLVMDIBuilderCreateBasicType(Builder
: DIBuilderRef
,
1828 Name
: *const c_char
,
1829 SizeInBits
: c_ulonglong
,
1830 AlignInBits
: c_ulonglong
,
1834 pub fn LLVMDIBuilderCreatePointerType(Builder
: DIBuilderRef
,
1836 SizeInBits
: c_ulonglong
,
1837 AlignInBits
: c_ulonglong
,
1838 Name
: *const c_char
)
1841 pub fn LLVMDIBuilderCreateStructType(Builder
: DIBuilderRef
,
1842 Scope
: DIDescriptor
,
1843 Name
: *const c_char
,
1846 SizeInBits
: c_ulonglong
,
1847 AlignInBits
: c_ulonglong
,
1849 DerivedFrom
: DIType
,
1851 RunTimeLang
: c_uint
,
1852 VTableHolder
: DIType
,
1853 UniqueId
: *const c_char
)
1856 pub fn LLVMDIBuilderCreateMemberType(Builder
: DIBuilderRef
,
1857 Scope
: DIDescriptor
,
1858 Name
: *const c_char
,
1861 SizeInBits
: c_ulonglong
,
1862 AlignInBits
: c_ulonglong
,
1863 OffsetInBits
: c_ulonglong
,
1868 pub fn LLVMDIBuilderCreateLexicalBlock(Builder
: DIBuilderRef
,
1875 pub fn LLVMDIBuilderCreateStaticVariable(Builder
: DIBuilderRef
,
1877 Name
: *const c_char
,
1878 LinkageName
: *const c_char
,
1882 isLocalToUnit
: bool
,
1885 -> DIGlobalVariable
;
1887 pub fn LLVMDIBuilderCreateVariable(Builder
: DIBuilderRef
,
1889 Scope
: DIDescriptor
,
1890 Name
: *const c_char
,
1894 AlwaysPreserve
: bool
,
1896 AddrOps
: *const i64,
1897 AddrOpsCount
: c_uint
,
1901 pub fn LLVMDIBuilderCreateArrayType(Builder
: DIBuilderRef
,
1903 AlignInBits
: c_ulonglong
,
1905 Subscripts
: DIArray
)
1908 pub fn LLVMDIBuilderCreateVectorType(Builder
: DIBuilderRef
,
1910 AlignInBits
: c_ulonglong
,
1912 Subscripts
: DIArray
)
1915 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder
: DIBuilderRef
,
1920 pub fn LLVMDIBuilderGetOrCreateArray(Builder
: DIBuilderRef
,
1921 Ptr
: *const DIDescriptor
,
1925 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder
: DIBuilderRef
,
1927 VarInfo
: DIVariable
,
1928 AddrOps
: *const i64,
1929 AddrOpsCount
: c_uint
,
1931 InsertAtEnd
: BasicBlockRef
)
1934 pub fn LLVMDIBuilderInsertDeclareBefore(Builder
: DIBuilderRef
,
1936 VarInfo
: DIVariable
,
1937 AddrOps
: *const i64,
1938 AddrOpsCount
: c_uint
,
1940 InsertBefore
: ValueRef
)
1943 pub fn LLVMDIBuilderCreateEnumerator(Builder
: DIBuilderRef
,
1944 Name
: *const c_char
,
1948 pub fn LLVMDIBuilderCreateEnumerationType(Builder
: DIBuilderRef
,
1950 Name
: *const c_char
,
1953 SizeInBits
: c_ulonglong
,
1954 AlignInBits
: c_ulonglong
,
1959 pub fn LLVMDIBuilderCreateUnionType(Builder
: DIBuilderRef
,
1961 Name
: *const c_char
,
1964 SizeInBits
: c_ulonglong
,
1965 AlignInBits
: c_ulonglong
,
1968 RunTimeLang
: c_uint
,
1969 UniqueId
: *const c_char
)
1972 pub fn LLVMSetUnnamedAddr(GlobalVar
: ValueRef
, UnnamedAddr
: Bool
);
1974 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder
: DIBuilderRef
,
1976 Name
: *const c_char
,
1981 -> DITemplateTypeParameter
;
1983 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1985 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1987 pub fn LLVMDIBuilderCreateNameSpace(Builder
: DIBuilderRef
,
1989 Name
: *const c_char
,
1994 pub fn LLVMDIBuilderCreateDebugLocation(Context
: ContextRef
,
1998 InlinedAt
: MetadataRef
)
2001 pub fn LLVMDICompositeTypeSetTypeArray(Builder
: DIBuilderRef
,
2002 CompositeType
: DIType
,
2003 TypeArray
: DIArray
);
2004 pub fn LLVMWriteTypeToString(Type
: TypeRef
, s
: RustStringRef
);
2005 pub fn LLVMWriteValueToString(value_ref
: ValueRef
, s
: RustStringRef
);
2007 pub fn LLVMIsAArgument(value_ref
: ValueRef
) -> ValueRef
;
2009 pub fn LLVMIsAAllocaInst(value_ref
: ValueRef
) -> ValueRef
;
2010 pub fn LLVMIsAConstantInt(value_ref
: ValueRef
) -> ValueRef
;
2012 pub fn LLVMRustPassKind(Pass
: PassRef
) -> SupportedPassKind
;
2013 pub fn LLVMRustFindAndCreatePass(Pass
: *const c_char
) -> PassRef
;
2014 pub fn LLVMRustAddPass(PM
: PassManagerRef
, Pass
: PassRef
);
2016 pub fn LLVMRustCreateTargetMachine(Triple
: *const c_char
,
2018 Features
: *const c_char
,
2019 Model
: CodeGenModel
,
2021 Level
: CodeGenOptLevel
,
2023 PositionIndependentExecutable
: bool
,
2024 FunctionSections
: bool
,
2025 DataSections
: bool
) -> TargetMachineRef
;
2026 pub fn LLVMRustDisposeTargetMachine(T
: TargetMachineRef
);
2027 pub fn LLVMRustAddAnalysisPasses(T
: TargetMachineRef
,
2030 pub fn LLVMRustAddBuilderLibraryInfo(PMB
: PassManagerBuilderRef
,
2032 DisableSimplifyLibCalls
: bool
);
2033 pub fn LLVMRustConfigurePassManagerBuilder(PMB
: PassManagerBuilderRef
,
2034 OptLevel
: CodeGenOptLevel
,
2035 MergeFunctions
: bool
,
2037 LoopVectorize
: bool
);
2038 pub fn LLVMRustAddLibraryInfo(PM
: PassManagerRef
, M
: ModuleRef
,
2039 DisableSimplifyLibCalls
: bool
);
2040 pub fn LLVMRustRunFunctionPassManager(PM
: PassManagerRef
, M
: ModuleRef
);
2041 pub fn LLVMRustWriteOutputFile(T
: TargetMachineRef
,
2044 Output
: *const c_char
,
2045 FileType
: FileType
) -> bool
;
2046 pub fn LLVMRustPrintModule(PM
: PassManagerRef
,
2048 Output
: *const c_char
);
2049 pub fn LLVMRustSetLLVMOptions(Argc
: c_int
, Argv
: *const *const c_char
);
2050 pub fn LLVMRustPrintPasses();
2051 pub fn LLVMRustSetNormalizedTarget(M
: ModuleRef
, triple
: *const c_char
);
2052 pub fn LLVMRustAddAlwaysInlinePass(P
: PassManagerBuilderRef
,
2053 AddLifetimes
: bool
);
2054 pub fn LLVMRustLinkInExternalBitcode(M
: ModuleRef
,
2056 len
: size_t
) -> bool
;
2057 pub fn LLVMRustRunRestrictionPass(M
: ModuleRef
,
2058 syms
: *const *const c_char
,
2060 pub fn LLVMRustMarkAllFunctionsNounwind(M
: ModuleRef
);
2062 pub fn LLVMRustOpenArchive(path
: *const c_char
) -> ArchiveRef
;
2063 pub fn LLVMRustArchiveIteratorNew(AR
: ArchiveRef
) -> ArchiveIteratorRef
;
2064 pub fn LLVMRustArchiveIteratorNext(AIR
: ArchiveIteratorRef
) -> ArchiveChildRef
;
2065 pub fn LLVMRustArchiveChildName(ACR
: ArchiveChildRef
,
2066 size
: *mut size_t
) -> *const c_char
;
2067 pub fn LLVMRustArchiveChildData(ACR
: ArchiveChildRef
,
2068 size
: *mut size_t
) -> *const c_char
;
2069 pub fn LLVMRustArchiveChildFree(ACR
: ArchiveChildRef
);
2070 pub fn LLVMRustArchiveIteratorFree(AIR
: ArchiveIteratorRef
);
2071 pub fn LLVMRustDestroyArchive(AR
: ArchiveRef
);
2073 pub fn LLVMRustSetDLLStorageClass(V
: ValueRef
,
2074 C
: DLLStorageClassTypes
);
2076 pub fn LLVMRustGetSectionName(SI
: SectionIteratorRef
,
2077 data
: *mut *const c_char
) -> c_int
;
2079 pub fn LLVMWriteTwineToString(T
: TwineRef
, s
: RustStringRef
);
2081 pub fn LLVMContextSetDiagnosticHandler(C
: ContextRef
,
2082 Handler
: DiagnosticHandler
,
2083 DiagnosticContext
: *mut c_void
);
2085 pub fn LLVMUnpackOptimizationDiagnostic(DI
: DiagnosticInfoRef
,
2086 pass_name_out
: *mut *const c_char
,
2087 function_out
: *mut ValueRef
,
2088 debugloc_out
: *mut DebugLocRef
,
2089 message_out
: *mut TwineRef
);
2090 pub fn LLVMUnpackInlineAsmDiagnostic(DI
: DiagnosticInfoRef
,
2091 cookie_out
: *mut c_uint
,
2092 message_out
: *mut TwineRef
,
2093 instruction_out
: *mut ValueRef
);
2095 pub fn LLVMWriteDiagnosticInfoToString(DI
: DiagnosticInfoRef
, s
: RustStringRef
);
2096 pub fn LLVMGetDiagInfoSeverity(DI
: DiagnosticInfoRef
) -> DiagnosticSeverity
;
2097 pub fn LLVMGetDiagInfoKind(DI
: DiagnosticInfoRef
) -> DiagnosticKind
;
2099 pub fn LLVMWriteDebugLocToString(C
: ContextRef
, DL
: DebugLocRef
, s
: RustStringRef
);
2101 pub fn LLVMSetInlineAsmDiagnosticHandler(C
: ContextRef
,
2102 H
: InlineAsmDiagHandler
,
2105 pub fn LLVMWriteSMDiagnosticToString(d
: SMDiagnosticRef
, s
: RustStringRef
);
2107 pub fn LLVMRustWriteArchive(Dst
: *const c_char
,
2109 Members
: *const RustArchiveMemberRef
,
2111 Kind
: ArchiveKind
) -> c_int
;
2112 pub fn LLVMRustArchiveMemberNew(Filename
: *const c_char
,
2113 Name
: *const c_char
,
2114 Child
: ArchiveChildRef
) -> RustArchiveMemberRef
;
2115 pub fn LLVMRustArchiveMemberFree(Member
: RustArchiveMemberRef
);
2117 pub fn LLVMRustSetDataLayoutFromTargetMachine(M
: ModuleRef
,
2118 TM
: TargetMachineRef
);
2119 pub fn LLVMRustGetModuleDataLayout(M
: ModuleRef
) -> TargetDataRef
;
2121 pub fn LLVMRustBuildOperandBundleDef(Name
: *const c_char
,
2122 Inputs
: *const ValueRef
,
2124 -> OperandBundleDefRef
;
2125 pub fn LLVMRustFreeOperandBundleDef(Bundle
: OperandBundleDefRef
);
2127 pub fn LLVMRustPositionBuilderAtStart(B
: BuilderRef
, BB
: BasicBlockRef
);
2129 pub fn LLVMRustSetComdat(M
: ModuleRef
, V
: ValueRef
, Name
: *const c_char
);
2130 pub fn LLVMRustUnsetComdat(V
: ValueRef
);
2133 // LLVM requires symbols from this library, but apparently they're not printed
2134 // during llvm-config?
2136 #[link(name = "ole32")]
2139 pub fn SetInstructionCallConv(instr
: ValueRef
, cc
: CallConv
) {
2141 LLVMSetInstructionCallConv(instr
, cc
as c_uint
);
2144 pub fn SetFunctionCallConv(fn_
: ValueRef
, cc
: CallConv
) {
2146 LLVMSetFunctionCallConv(fn_
, cc
as c_uint
);
2149 pub fn SetLinkage(global
: ValueRef
, link
: Linkage
) {
2151 LLVMSetLinkage(global
, link
as c_uint
);
2155 // Externally visible symbols that might appear in multiple translation units need to appear in
2156 // their own comdat section so that the duplicates can be discarded at link time. This can for
2157 // example happen for generics when using multiple codegen units. This function simply uses the
2158 // value's name as the comdat value to make sure that it is in a 1-to-1 relationship to the
2160 // For more details on COMDAT sections see e.g. http://www.airs.com/blog/archives/52
2161 pub fn SetUniqueComdat(llmod
: ModuleRef
, val
: ValueRef
) {
2163 LLVMRustSetComdat(llmod
, val
, LLVMGetValueName(val
));
2167 pub fn UnsetComdat(val
: ValueRef
) {
2169 LLVMRustUnsetComdat(val
);
2173 pub fn SetDLLStorageClass(global
: ValueRef
, class
: DLLStorageClassTypes
) {
2175 LLVMRustSetDLLStorageClass(global
, class
);
2179 pub fn SetUnnamedAddr(global
: ValueRef
, unnamed
: bool
) {
2181 LLVMSetUnnamedAddr(global
, unnamed
as Bool
);
2185 pub fn set_thread_local(global
: ValueRef
, is_thread_local
: bool
) {
2187 LLVMSetThreadLocal(global
, is_thread_local
as Bool
);
2191 pub fn ConstICmp(pred
: IntPredicate
, v1
: ValueRef
, v2
: ValueRef
) -> ValueRef
{
2193 LLVMConstICmp(pred
as c_ushort
, v1
, v2
)
2196 pub fn ConstFCmp(pred
: RealPredicate
, v1
: ValueRef
, v2
: ValueRef
) -> ValueRef
{
2198 LLVMConstFCmp(pred
as c_ushort
, v1
, v2
)
2202 pub fn SetFunctionAttribute(fn_
: ValueRef
, attr
: Attribute
) {
2204 LLVMAddFunctionAttribute(fn_
, FunctionIndex
as c_uint
,
2205 attr
.bits() as uint64_t
)
2209 pub fn RemoveFunctionAttributes(fn_
: ValueRef
, attr
: Attribute
) {
2211 LLVMRemoveFunctionAttributes(fn_
, FunctionIndex
as c_uint
,
2212 attr
.bits() as uint64_t
)
2216 /* Memory-managed interface to target data. */
2218 pub struct TargetData
{
2219 pub lltd
: TargetDataRef
2222 impl Drop
for TargetData
{
2223 fn drop(&mut self) {
2225 LLVMDisposeTargetData(self.lltd
);
2230 pub fn mk_target_data(string_rep
: &str) -> TargetData
{
2231 let string_rep
= CString
::new(string_rep
).unwrap();
2233 lltd
: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2237 /* Memory-managed interface to object files. */
2239 pub struct ObjectFile
{
2240 pub llof
: ObjectFileRef
,
2244 // This will take ownership of llmb
2245 pub fn new(llmb
: MemoryBufferRef
) -> Option
<ObjectFile
> {
2247 let llof
= LLVMCreateObjectFile(llmb
);
2248 if llof
as isize == 0 {
2249 // LLVMCreateObjectFile took ownership of llmb
2260 impl Drop
for ObjectFile
{
2261 fn drop(&mut self) {
2263 LLVMDisposeObjectFile(self.llof
);
2268 /* Memory-managed interface to section iterators. */
2270 pub struct SectionIter
{
2271 pub llsi
: SectionIteratorRef
2274 impl Drop
for SectionIter
{
2275 fn drop(&mut self) {
2277 LLVMDisposeSectionIterator(self.llsi
);
2282 pub fn mk_section_iter(llof
: ObjectFileRef
) -> SectionIter
{
2285 llsi
: LLVMGetSections(llof
)
2290 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2291 pub fn get_param(llfn
: ValueRef
, index
: c_uint
) -> ValueRef
{
2293 assert
!(index
< LLVMCountParams(llfn
));
2294 LLVMGetParam(llfn
, index
)
2298 pub fn get_params(llfn
: ValueRef
) -> Vec
<ValueRef
> {
2300 let num_params
= LLVMCountParams(llfn
);
2301 let mut params
= Vec
::with_capacity(num_params
as usize);
2302 for idx
in 0..num_params
{
2303 params
.push(LLVMGetParam(llfn
, idx
));
2310 #[allow(missing_copy_implementations)]
2311 pub enum RustString_opaque {}
2312 pub type RustStringRef
= *mut RustString_opaque
;
2313 type RustStringRepr
= *mut RefCell
<Vec
<u8>>;
2315 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2317 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr
: RustStringRef
,
2320 let slice
= slice
::from_raw_parts(ptr
as *const u8, size
as usize);
2322 let sr
= sr
as RustStringRepr
;
2323 (*sr
).borrow_mut().extend_from_slice(slice
);
2326 pub fn build_string
<F
>(f
: F
) -> Option
<String
> where F
: FnOnce(RustStringRef
){
2327 let mut buf
= RefCell
::new(Vec
::new());
2328 f(&mut buf
as RustStringRepr
as RustStringRef
);
2329 String
::from_utf8(buf
.into_inner()).ok()
2332 pub unsafe fn twine_to_string(tr
: TwineRef
) -> String
{
2333 build_string(|s
| LLVMWriteTwineToString(tr
, s
))
2334 .expect("got a non-UTF8 Twine from LLVM")
2337 pub unsafe fn debug_loc_to_string(c
: ContextRef
, tr
: DebugLocRef
) -> String
{
2338 build_string(|s
| LLVMWriteDebugLocToString(c
, tr
, s
))
2339 .expect("got a non-UTF8 DebugLoc from LLVM")
2342 pub fn initialize_available_targets() {
2343 macro_rules
! init_target(
2344 ($cfg
:meta
, $
($method
:ident
),*) => { {
2359 init_target
!(llvm_component
= "x86",
2360 LLVMInitializeX86TargetInfo
,
2361 LLVMInitializeX86Target
,
2362 LLVMInitializeX86TargetMC
,
2363 LLVMInitializeX86AsmPrinter
,
2364 LLVMInitializeX86AsmParser
);
2365 init_target
!(llvm_component
= "arm",
2366 LLVMInitializeARMTargetInfo
,
2367 LLVMInitializeARMTarget
,
2368 LLVMInitializeARMTargetMC
,
2369 LLVMInitializeARMAsmPrinter
,
2370 LLVMInitializeARMAsmParser
);
2371 init_target
!(llvm_component
= "aarch64",
2372 LLVMInitializeAArch64TargetInfo
,
2373 LLVMInitializeAArch64Target
,
2374 LLVMInitializeAArch64TargetMC
,
2375 LLVMInitializeAArch64AsmPrinter
,
2376 LLVMInitializeAArch64AsmParser
);
2377 init_target
!(llvm_component
= "mips",
2378 LLVMInitializeMipsTargetInfo
,
2379 LLVMInitializeMipsTarget
,
2380 LLVMInitializeMipsTargetMC
,
2381 LLVMInitializeMipsAsmPrinter
,
2382 LLVMInitializeMipsAsmParser
);
2383 init_target
!(llvm_component
= "powerpc",
2384 LLVMInitializePowerPCTargetInfo
,
2385 LLVMInitializePowerPCTarget
,
2386 LLVMInitializePowerPCTargetMC
,
2387 LLVMInitializePowerPCAsmPrinter
,
2388 LLVMInitializePowerPCAsmParser
);
2389 init_target
!(llvm_component
= "pnacl",
2390 LLVMInitializePNaClTargetInfo
,
2391 LLVMInitializePNaClTarget
,
2392 LLVMInitializePNaClTargetMC
);
2395 pub fn last_error() -> Option
<String
> {
2397 let cstr
= LLVMRustGetLastError();
2401 let err
= CStr
::from_ptr(cstr
).to_bytes();
2402 let err
= String
::from_utf8_lossy(err
).to_string();
2403 libc
::free(cstr
as *mut _
);
2409 pub struct OperandBundleDef
{
2410 inner
: OperandBundleDefRef
,
2413 impl OperandBundleDef
{
2414 pub fn new(name
: &str, vals
: &[ValueRef
]) -> OperandBundleDef
{
2415 let name
= CString
::new(name
).unwrap();
2417 LLVMRustBuildOperandBundleDef(name
.as_ptr(),
2419 vals
.len() as c_uint
)
2421 OperandBundleDef { inner: def }
2424 pub fn raw(&self) -> OperandBundleDefRef
{
2429 impl Drop
for OperandBundleDef
{
2430 fn drop(&mut self) {
2432 LLVMRustFreeOperandBundleDef(self.inner
);
2437 // The module containing the native LLVM dependencies, generated by the build system
2438 // Note that this must come after the rustllvm extern declaration so that
2439 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2440 // Works to the above fix for #15460 to ensure LLVM dependencies that
2441 // are only used by rustllvm don't get stripped by the linker.
2442 #[cfg(not(cargobuild))]
2444 include
! { env!("CFG_LLVM_LINKAGE_FILE") }