]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/llvm/ffi.rs
612581c1ac671067cbb4efb219aa93260fed01db
[rust.git] / src / librustc_codegen_llvm / llvm / ffi.rs
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.
4 //
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.
10
11 use super::debuginfo::{
12     DIBuilder, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType,
13     DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable,
14     DIGlobalVariableExpression, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
15     DINameSpace, DIFlags,
16 };
17
18 use libc::{c_uint, c_int, size_t, c_char};
19 use libc::{c_ulonglong, c_void};
20
21 use std::marker::PhantomData;
22
23 use super::RustString;
24
25 pub type Bool = c_uint;
26
27 pub const True: Bool = 1 as Bool;
28 pub const False: Bool = 0 as Bool;
29
30 #[derive(Copy, Clone, PartialEq)]
31 #[repr(C)]
32 #[allow(dead_code)] // Variants constructed by C++.
33 pub enum LLVMRustResult {
34     Success,
35     Failure,
36 }
37 // Consts for the LLVM CallConv type, pre-cast to usize.
38
39 /// LLVM CallingConv::ID. Should we wrap this?
40 #[derive(Copy, Clone, PartialEq, Debug)]
41 #[repr(C)]
42 pub enum CallConv {
43     CCallConv = 0,
44     FastCallConv = 8,
45     ColdCallConv = 9,
46     X86StdcallCallConv = 64,
47     X86FastcallCallConv = 65,
48     ArmAapcsCallConv = 67,
49     Msp430Intr = 69,
50     X86_ThisCall = 70,
51     PtxKernel = 71,
52     X86_64_SysV = 78,
53     X86_64_Win64 = 79,
54     X86_VectorCall = 80,
55     X86_Intr = 83,
56     AmdGpuKernel = 91,
57 }
58
59 /// LLVMRustLinkage
60 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
61 #[repr(C)]
62 pub enum Linkage {
63     ExternalLinkage = 0,
64     AvailableExternallyLinkage = 1,
65     LinkOnceAnyLinkage = 2,
66     LinkOnceODRLinkage = 3,
67     WeakAnyLinkage = 4,
68     WeakODRLinkage = 5,
69     AppendingLinkage = 6,
70     InternalLinkage = 7,
71     PrivateLinkage = 8,
72     ExternalWeakLinkage = 9,
73     CommonLinkage = 10,
74 }
75
76 // LLVMRustVisibility
77 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
78 #[repr(C)]
79 pub enum Visibility {
80     Default = 0,
81     Hidden = 1,
82     Protected = 2,
83 }
84
85 /// LLVMDLLStorageClass
86 #[derive(Copy, Clone)]
87 #[repr(C)]
88 pub enum DLLStorageClass {
89     #[allow(dead_code)]
90     Default = 0,
91     DllImport = 1, // Function to be imported from DLL.
92     #[allow(dead_code)]
93     DllExport = 2, // Function to be accessible from DLL.
94 }
95
96 /// Matches LLVMRustAttribute in rustllvm.h
97 /// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
98 /// though it is not ABI compatible (since it's a C++ enum)
99 #[repr(C)]
100 #[derive(Copy, Clone, Debug)]
101 pub enum Attribute {
102     AlwaysInline    = 0,
103     ByVal           = 1,
104     Cold            = 2,
105     InlineHint      = 3,
106     MinSize         = 4,
107     Naked           = 5,
108     NoAlias         = 6,
109     NoCapture       = 7,
110     NoInline        = 8,
111     NonNull         = 9,
112     NoRedZone       = 10,
113     NoReturn        = 11,
114     NoUnwind        = 12,
115     OptimizeForSize = 13,
116     ReadOnly        = 14,
117     SExt            = 15,
118     StructRet       = 16,
119     UWTable         = 17,
120     ZExt            = 18,
121     InReg           = 19,
122     SanitizeThread  = 20,
123     SanitizeAddress = 21,
124     SanitizeMemory  = 22,
125     NonLazyBind     = 23,
126 }
127
128 /// LLVMIntPredicate
129 #[derive(Copy, Clone)]
130 #[repr(C)]
131 pub enum IntPredicate {
132     IntEQ = 32,
133     IntNE = 33,
134     IntUGT = 34,
135     IntUGE = 35,
136     IntULT = 36,
137     IntULE = 37,
138     IntSGT = 38,
139     IntSGE = 39,
140     IntSLT = 40,
141     IntSLE = 41,
142 }
143
144 /// LLVMRealPredicate
145 #[derive(Copy, Clone)]
146 #[repr(C)]
147 pub enum RealPredicate {
148     RealPredicateFalse = 0,
149     RealOEQ = 1,
150     RealOGT = 2,
151     RealOGE = 3,
152     RealOLT = 4,
153     RealOLE = 5,
154     RealONE = 6,
155     RealORD = 7,
156     RealUNO = 8,
157     RealUEQ = 9,
158     RealUGT = 10,
159     RealUGE = 11,
160     RealULT = 12,
161     RealULE = 13,
162     RealUNE = 14,
163     RealPredicateTrue = 15,
164 }
165
166 /// LLVMTypeKind
167 #[derive(Copy, Clone, PartialEq, Debug)]
168 #[repr(C)]
169 pub enum TypeKind {
170     Void = 0,
171     Half = 1,
172     Float = 2,
173     Double = 3,
174     X86_FP80 = 4,
175     FP128 = 5,
176     PPC_FP128 = 6,
177     Label = 7,
178     Integer = 8,
179     Function = 9,
180     Struct = 10,
181     Array = 11,
182     Pointer = 12,
183     Vector = 13,
184     Metadata = 14,
185     X86_MMX = 15,
186     Token = 16,
187 }
188
189 /// LLVMAtomicRmwBinOp
190 #[derive(Copy, Clone)]
191 #[repr(C)]
192 pub enum AtomicRmwBinOp {
193     AtomicXchg = 0,
194     AtomicAdd = 1,
195     AtomicSub = 2,
196     AtomicAnd = 3,
197     AtomicNand = 4,
198     AtomicOr = 5,
199     AtomicXor = 6,
200     AtomicMax = 7,
201     AtomicMin = 8,
202     AtomicUMax = 9,
203     AtomicUMin = 10,
204 }
205
206 /// LLVMAtomicOrdering
207 #[derive(Copy, Clone)]
208 #[repr(C)]
209 pub enum AtomicOrdering {
210     #[allow(dead_code)]
211     NotAtomic = 0,
212     Unordered = 1,
213     Monotonic = 2,
214     // Consume = 3,  // Not specified yet.
215     Acquire = 4,
216     Release = 5,
217     AcquireRelease = 6,
218     SequentiallyConsistent = 7,
219 }
220
221 /// LLVMRustSynchronizationScope
222 #[derive(Copy, Clone)]
223 #[repr(C)]
224 pub enum SynchronizationScope {
225     // FIXME: figure out if this variant is needed at all.
226     #[allow(dead_code)]
227     Other,
228     SingleThread,
229     CrossThread,
230 }
231
232 /// LLVMRustFileType
233 #[derive(Copy, Clone)]
234 #[repr(C)]
235 pub enum FileType {
236     // FIXME: figure out if this variant is needed at all.
237     #[allow(dead_code)]
238     Other,
239     AssemblyFile,
240     ObjectFile,
241 }
242
243 /// LLVMMetadataType
244 #[derive(Copy, Clone)]
245 #[repr(C)]
246 pub enum MetadataType {
247     MD_dbg = 0,
248     MD_tbaa = 1,
249     MD_prof = 2,
250     MD_fpmath = 3,
251     MD_range = 4,
252     MD_tbaa_struct = 5,
253     MD_invariant_load = 6,
254     MD_alias_scope = 7,
255     MD_noalias = 8,
256     MD_nontemporal = 9,
257     MD_mem_parallel_loop_access = 10,
258     MD_nonnull = 11,
259 }
260
261 /// LLVMRustAsmDialect
262 #[derive(Copy, Clone)]
263 #[repr(C)]
264 pub enum AsmDialect {
265     // FIXME: figure out if this variant is needed at all.
266     #[allow(dead_code)]
267     Other,
268     Att,
269     Intel,
270 }
271
272 /// LLVMRustCodeGenOptLevel
273 #[derive(Copy, Clone, PartialEq)]
274 #[repr(C)]
275 pub enum CodeGenOptLevel {
276     // FIXME: figure out if this variant is needed at all.
277     #[allow(dead_code)]
278     Other,
279     None,
280     Less,
281     Default,
282     Aggressive,
283 }
284
285 /// LLVMRelocMode
286 #[derive(Copy, Clone, PartialEq)]
287 #[repr(C)]
288 pub enum RelocMode {
289     Default,
290     Static,
291     PIC,
292     DynamicNoPic,
293     ROPI,
294     RWPI,
295     ROPI_RWPI,
296 }
297
298 /// LLVMRustCodeModel
299 #[derive(Copy, Clone)]
300 #[repr(C)]
301 pub enum CodeModel {
302     // FIXME: figure out if this variant is needed at all.
303     #[allow(dead_code)]
304     Other,
305     Small,
306     Kernel,
307     Medium,
308     Large,
309     None,
310 }
311
312 /// LLVMRustDiagnosticKind
313 #[derive(Copy, Clone)]
314 #[repr(C)]
315 #[allow(dead_code)] // Variants constructed by C++.
316 pub enum DiagnosticKind {
317     Other,
318     InlineAsm,
319     StackSize,
320     DebugMetadataVersion,
321     SampleProfile,
322     OptimizationRemark,
323     OptimizationRemarkMissed,
324     OptimizationRemarkAnalysis,
325     OptimizationRemarkAnalysisFPCommute,
326     OptimizationRemarkAnalysisAliasing,
327     OptimizationRemarkOther,
328     OptimizationFailure,
329     PGOProfile,
330     Linker,
331 }
332
333 /// LLVMRustArchiveKind
334 #[derive(Copy, Clone)]
335 #[repr(C)]
336 pub enum ArchiveKind {
337     // FIXME: figure out if this variant is needed at all.
338     #[allow(dead_code)]
339     Other,
340     K_GNU,
341     K_BSD,
342     K_COFF,
343 }
344
345 /// LLVMRustPassKind
346 #[derive(Copy, Clone, PartialEq, Debug)]
347 #[repr(C)]
348 #[allow(dead_code)] // Variants constructed by C++.
349 pub enum PassKind {
350     Other,
351     Function,
352     Module,
353 }
354
355 /// LLVMRustThinLTOData
356 extern { pub type ThinLTOData; }
357
358 /// LLVMRustThinLTOBuffer
359 extern { pub type ThinLTOBuffer; }
360
361 // LLVMRustModuleNameCallback
362 pub type ThinLTOModuleNameCallback =
363     unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);
364
365 /// LLVMRustThinLTOModule
366 #[repr(C)]
367 pub struct ThinLTOModule {
368     pub identifier: *const c_char,
369     pub data: *const u8,
370     pub len: usize,
371 }
372
373 /// LLVMThreadLocalMode
374 #[derive(Copy, Clone)]
375 #[repr(C)]
376 pub enum ThreadLocalMode {
377   NotThreadLocal,
378   GeneralDynamic,
379   LocalDynamic,
380   InitialExec,
381   LocalExec
382 }
383
384 extern { type Opaque; }
385 #[repr(C)]
386 struct InvariantOpaque<'a> {
387     _marker: PhantomData<&'a mut &'a ()>,
388     _opaque: Opaque,
389 }
390
391 // Opaque pointer types
392 extern { pub type Module; }
393 extern { pub type Context; }
394 extern { pub type Type; }
395 extern { pub type Value; }
396 extern { pub type Metadata; }
397 extern { pub type BasicBlock; }
398 #[repr(C)]
399 pub struct Builder<'a>(InvariantOpaque<'a>);
400 extern { pub type MemoryBuffer; }
401 #[repr(C)]
402 pub struct PassManager<'a>(InvariantOpaque<'a>);
403 extern { pub type PassManagerBuilder; }
404 extern { pub type ObjectFile; }
405 #[repr(C)]
406 pub struct SectionIterator<'a>(InvariantOpaque<'a>);
407 extern { pub type Pass; }
408 extern { pub type TargetMachine; }
409 extern { pub type Archive; }
410 #[repr(C)]
411 pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
412 #[repr(C)]
413 pub struct ArchiveChild<'a>(InvariantOpaque<'a>);
414 extern { pub type Twine; }
415 extern { pub type DiagnosticInfo; }
416 extern { pub type SMDiagnostic; }
417 #[repr(C)]
418 pub struct RustArchiveMember<'a>(InvariantOpaque<'a>);
419 #[repr(C)]
420 pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
421 #[repr(C)]
422 pub struct Linker<'a>(InvariantOpaque<'a>);
423
424 pub type DiagnosticHandler = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
425 pub type InlineAsmDiagHandler = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
426
427
428 pub mod debuginfo {
429     use super::{InvariantOpaque, Metadata};
430
431     #[repr(C)]
432     pub struct DIBuilder<'a>(InvariantOpaque<'a>);
433
434     pub type DIDescriptor = Metadata;
435     pub type DIScope = DIDescriptor;
436     pub type DIFile = DIScope;
437     pub type DILexicalBlock = DIScope;
438     pub type DISubprogram = DIScope;
439     pub type DINameSpace = DIScope;
440     pub type DIType = DIDescriptor;
441     pub type DIBasicType = DIType;
442     pub type DIDerivedType = DIType;
443     pub type DICompositeType = DIDerivedType;
444     pub type DIVariable = DIDescriptor;
445     pub type DIGlobalVariableExpression = DIDescriptor;
446     pub type DIArray = DIDescriptor;
447     pub type DISubrange = DIDescriptor;
448     pub type DIEnumerator = DIDescriptor;
449     pub type DITemplateTypeParameter = DIDescriptor;
450
451     // These values **must** match with LLVMRustDIFlags!!
452     bitflags! {
453         #[repr(C)]
454         #[derive(Default)]
455         pub struct DIFlags: ::libc::uint32_t {
456             const FlagZero                = 0;
457             const FlagPrivate             = 1;
458             const FlagProtected           = 2;
459             const FlagPublic              = 3;
460             const FlagFwdDecl             = (1 << 2);
461             const FlagAppleBlock          = (1 << 3);
462             const FlagBlockByrefStruct    = (1 << 4);
463             const FlagVirtual             = (1 << 5);
464             const FlagArtificial          = (1 << 6);
465             const FlagExplicit            = (1 << 7);
466             const FlagPrototyped          = (1 << 8);
467             const FlagObjcClassComplete   = (1 << 9);
468             const FlagObjectPointer       = (1 << 10);
469             const FlagVector              = (1 << 11);
470             const FlagStaticMember        = (1 << 12);
471             const FlagLValueReference     = (1 << 13);
472             const FlagRValueReference     = (1 << 14);
473             const FlagExternalTypeRef     = (1 << 15);
474             const FlagIntroducedVirtual   = (1 << 18);
475             const FlagBitField            = (1 << 19);
476             const FlagNoReturn            = (1 << 20);
477             const FlagMainSubprogram      = (1 << 21);
478         }
479     }
480 }
481
482 extern { pub type ModuleBuffer; }
483
484 extern "C" {
485     pub fn LLVMRustInstallFatalErrorHandler();
486
487     // Create and destroy contexts.
488     pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
489     pub fn LLVMContextDispose(C: &'static mut Context);
490     pub fn LLVMGetMDKindIDInContext(C: &Context, Name: *const c_char, SLen: c_uint) -> c_uint;
491
492     // Create modules.
493     pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char, C: &Context) -> &Module;
494     pub fn LLVMGetModuleContext(M: &Module) -> &Context;
495     pub fn LLVMCloneModule(M: &Module) -> &Module;
496
497     /// Data layout. See Module::getDataLayout.
498     pub fn LLVMGetDataLayout(M: &Module) -> *const c_char;
499     pub fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);
500
501     /// See Module::setModuleInlineAsm.
502     pub fn LLVMSetModuleInlineAsm(M: &Module, Asm: *const c_char);
503     pub fn LLVMRustAppendModuleInlineAsm(M: &Module, Asm: *const c_char);
504
505     /// See llvm::LLVMTypeKind::getTypeID.
506     pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
507
508     // Operations on integer types
509     pub fn LLVMInt1TypeInContext(C: &Context) -> &Type;
510     pub fn LLVMInt8TypeInContext(C: &Context) -> &Type;
511     pub fn LLVMInt16TypeInContext(C: &Context) -> &Type;
512     pub fn LLVMInt32TypeInContext(C: &Context) -> &Type;
513     pub fn LLVMInt64TypeInContext(C: &Context) -> &Type;
514     pub fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type;
515
516     pub fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint;
517
518     // Operations on real types
519     pub fn LLVMFloatTypeInContext(C: &Context) -> &Type;
520     pub fn LLVMDoubleTypeInContext(C: &Context) -> &Type;
521
522     // Operations on function types
523     pub fn LLVMFunctionType(ReturnType: &'a Type,
524                             ParamTypes: *const &'a Type,
525                             ParamCount: c_uint,
526                             IsVarArg: Bool)
527                             -> &'a Type;
528     pub fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint;
529     pub fn LLVMGetParamTypes(FunctionTy: &'a Type, Dest: *mut &'a Type);
530
531     // Operations on struct types
532     pub fn LLVMStructTypeInContext(C: &'a Context,
533                                    ElementTypes: *const &'a Type,
534                                    ElementCount: c_uint,
535                                    Packed: Bool)
536                                    -> &'a Type;
537
538     // Operations on array, pointer, and vector types (sequence types)
539     pub fn LLVMRustArrayType(ElementType: &Type, ElementCount: u64) -> &Type;
540     pub fn LLVMPointerType(ElementType: &Type, AddressSpace: c_uint) -> &Type;
541     pub fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;
542
543     pub fn LLVMGetElementType(Ty: &Type) -> &Type;
544     pub fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint;
545
546     // Operations on other types
547     pub fn LLVMVoidTypeInContext(C: &Context) -> &Type;
548     pub fn LLVMX86MMXTypeInContext(C: &Context) -> &Type;
549     pub fn LLVMRustMetadataTypeInContext(C: &Context) -> &Type;
550
551     // Operations on all values
552     pub fn LLVMTypeOf(Val: &Value) -> &Type;
553     pub fn LLVMGetValueName(Val: &Value) -> *const c_char;
554     pub fn LLVMSetValueName(Val: &Value, Name: *const c_char);
555     pub fn LLVMReplaceAllUsesWith(OldVal: &'a Value, NewVal: &'a Value);
556     pub fn LLVMSetMetadata(Val: &'a Value, KindID: c_uint, Node: &'a Value);
557
558     // Operations on constants of any type
559     pub fn LLVMConstNull(Ty: &Type) -> &Value;
560     pub fn LLVMGetUndef(Ty: &Type) -> &Value;
561
562     // Operations on metadata
563     pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
564     pub fn LLVMMDNodeInContext(C: &'a Context, Vals: *const &'a Value, Count: c_uint) -> &'a Value;
565     pub fn LLVMAddNamedMetadataOperand(M: &'a Module, Name: *const c_char, Val: &'a Value);
566
567     // Operations on scalar constants
568     pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
569     pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
570     pub fn LLVMConstIntGetZExtValue(ConstantVal: &Value) -> c_ulonglong;
571     pub fn LLVMRustConstInt128Get(ConstantVal: &Value, SExt: bool,
572                                   high: &mut u64, low: &mut u64) -> bool;
573     pub fn LLVMConstRealGetDouble (ConstantVal: &Value, losesInfo: &mut Bool) -> f64;
574
575
576     // Operations on composite constants
577     pub fn LLVMConstStringInContext(C: &Context,
578                                     Str: *const c_char,
579                                     Length: c_uint,
580                                     DontNullTerminate: Bool)
581                                     -> &Value;
582     pub fn LLVMConstStructInContext(C: &'a Context,
583                                     ConstantVals: *const &'a Value,
584                                     Count: c_uint,
585                                     Packed: Bool)
586                                     -> &'a Value;
587
588     pub fn LLVMConstArray(ElementTy: &'a Type,
589                           ConstantVals: *const &'a Value,
590                           Length: c_uint)
591                           -> &'a Value;
592     pub fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
593
594     // Constant expressions
595     pub fn LLVMConstInBoundsGEP(
596         ConstantVal: &'a Value,
597         ConstantIndices: *const &'a Value,
598         NumIndices: c_uint,
599     ) -> &'a Value;
600     pub fn LLVMConstZExt(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
601     pub fn LLVMConstPtrToInt(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
602     pub fn LLVMConstIntToPtr(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
603     pub fn LLVMConstBitCast(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
604     pub fn LLVMConstPointerCast(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
605     pub fn LLVMConstExtractValue(AggConstant: &Value,
606                                  IdxList: *const c_uint,
607                                  NumIdx: c_uint)
608                                  -> &Value;
609
610     // Operations on global variables, functions, and aliases (globals)
611     pub fn LLVMIsDeclaration(Global: &Value) -> Bool;
612     pub fn LLVMRustGetLinkage(Global: &Value) -> Linkage;
613     pub fn LLVMRustSetLinkage(Global: &Value, RustLinkage: Linkage);
614     pub fn LLVMSetSection(Global: &Value, Section: *const c_char);
615     pub fn LLVMRustGetVisibility(Global: &Value) -> Visibility;
616     pub fn LLVMRustSetVisibility(Global: &Value, Viz: Visibility);
617     pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
618     pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
619     pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
620
621
622     // Operations on global variables
623     pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
624     pub fn LLVMAddGlobal(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
625     pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
626     pub fn LLVMRustGetOrInsertGlobal(M: &'a Module, Name: *const c_char, T: &'a Type) -> &'a Value;
627     pub fn LLVMRustInsertPrivateGlobal(M: &'a Module, T: &'a Type) -> &'a Value;
628     pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
629     pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
630     pub fn LLVMDeleteGlobal(GlobalVar: &Value);
631     pub fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;
632     pub fn LLVMSetInitializer(GlobalVar: &'a Value, ConstantVal: &'a Value);
633     pub fn LLVMSetThreadLocal(GlobalVar: &Value, IsThreadLocal: Bool);
634     pub fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
635     pub fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
636     pub fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
637     pub fn LLVMRustGetNamedValue(M: &Module, Name: *const c_char) -> Option<&Value>;
638     pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
639
640     // Operations on functions
641     pub fn LLVMRustGetOrInsertFunction(M: &'a Module,
642                                        Name: *const c_char,
643                                        FunctionTy: &'a Type)
644                                        -> &'a Value;
645     pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
646     pub fn LLVMRustAddAlignmentAttr(Fn: &Value, index: c_uint, bytes: u32);
647     pub fn LLVMRustAddDereferenceableAttr(Fn: &Value, index: c_uint, bytes: u64);
648     pub fn LLVMRustAddDereferenceableOrNullAttr(Fn: &Value, index: c_uint, bytes: u64);
649     pub fn LLVMRustAddFunctionAttribute(Fn: &Value, index: c_uint, attr: Attribute);
650     pub fn LLVMRustAddFunctionAttrStringValue(Fn: &Value,
651                                               index: c_uint,
652                                               Name: *const c_char,
653                                               Value: *const c_char);
654     pub fn LLVMRustRemoveFunctionAttributes(Fn: &Value, index: c_uint, attr: Attribute);
655
656     // Operations on parameters
657     pub fn LLVMCountParams(Fn: &Value) -> c_uint;
658     pub fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
659
660     // Operations on basic blocks
661     pub fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
662     pub fn LLVMAppendBasicBlockInContext(C: &'a Context,
663                                          Fn: &'a Value,
664                                          Name: *const c_char)
665                                          -> &'a BasicBlock;
666     pub fn LLVMDeleteBasicBlock(BB: &BasicBlock);
667
668     // Operations on instructions
669     pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
670
671     // Operations on call sites
672     pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
673     pub fn LLVMRustAddCallSiteAttribute(Instr: &Value, index: c_uint, attr: Attribute);
674     pub fn LLVMRustAddAlignmentCallSiteAttr(Instr: &Value, index: c_uint, bytes: u32);
675     pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: &Value, index: c_uint, bytes: u64);
676     pub fn LLVMRustAddDereferenceableOrNullCallSiteAttr(Instr: &Value,
677                                                         index: c_uint,
678                                                         bytes: u64);
679
680     // Operations on load/store instructions (only)
681     pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
682
683     // Operations on phi nodes
684     pub fn LLVMAddIncoming(PhiNode: &'a Value,
685                            IncomingValues: *const &'a Value,
686                            IncomingBlocks: *const &'a BasicBlock,
687                            Count: c_uint);
688
689     // Instruction builders
690     pub fn LLVMCreateBuilderInContext(C: &'a Context) -> &'a mut Builder<'a>;
691     pub fn LLVMPositionBuilderAtEnd(Builder: &Builder<'a>, Block: &'a BasicBlock);
692     pub fn LLVMGetInsertBlock(Builder: &Builder<'a>) -> &'a BasicBlock;
693     pub fn LLVMDisposeBuilder(Builder: &'a mut Builder<'a>);
694
695     // Metadata
696     pub fn LLVMSetCurrentDebugLocation(Builder: &Builder<'a>, L: Option<&'a Value>);
697     pub fn LLVMGetCurrentDebugLocation(Builder: &Builder<'a>) -> &'a Value;
698     pub fn LLVMSetInstDebugLocation(Builder: &Builder<'a>, Inst: &'a Value);
699
700     // Terminators
701     pub fn LLVMBuildRetVoid(B: &Builder<'a>) -> &'a Value;
702     pub fn LLVMBuildRet(B: &Builder<'a>, V: &'a Value) -> &'a Value;
703     pub fn LLVMBuildBr(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;
704     pub fn LLVMBuildCondBr(B: &Builder<'a>,
705                            If: &'a Value,
706                            Then: &'a BasicBlock,
707                            Else: &'a BasicBlock)
708                            -> &'a Value;
709     pub fn LLVMBuildSwitch(B: &Builder<'a>,
710                            V: &'a Value,
711                            Else: &'a BasicBlock,
712                            NumCases: c_uint)
713                            -> &'a Value;
714     pub fn LLVMRustBuildInvoke(B: &Builder<'a>,
715                                Fn: &'a Value,
716                                Args: *const &'a Value,
717                                NumArgs: c_uint,
718                                Then: &'a BasicBlock,
719                                Catch: &'a BasicBlock,
720                                Bundle: Option<&OperandBundleDef<'a>>,
721                                Name: *const c_char)
722                                -> &'a Value;
723     pub fn LLVMBuildLandingPad(B: &Builder<'a>,
724                                Ty: &'a Type,
725                                PersFn: &'a Value,
726                                NumClauses: c_uint,
727                                Name: *const c_char)
728                                -> &'a Value;
729     pub fn LLVMBuildResume(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
730     pub fn LLVMBuildUnreachable(B: &Builder<'a>) -> &'a Value;
731
732     pub fn LLVMRustBuildCleanupPad(B: &Builder<'a>,
733                                    ParentPad: Option<&'a Value>,
734                                    ArgCnt: c_uint,
735                                    Args: *const &'a Value,
736                                    Name: *const c_char)
737                                    -> Option<&'a Value>;
738     pub fn LLVMRustBuildCleanupRet(B: &Builder<'a>,
739                                    CleanupPad: &'a Value,
740                                    UnwindBB: Option<&'a BasicBlock>)
741                                    -> Option<&'a Value>;
742     pub fn LLVMRustBuildCatchPad(B: &Builder<'a>,
743                                  ParentPad: &'a Value,
744                                  ArgCnt: c_uint,
745                                  Args: *const &'a Value,
746                                  Name: *const c_char)
747                                  -> Option<&'a Value>;
748     pub fn LLVMRustBuildCatchRet(
749         B: &Builder<'a>,
750         Pad: &'a Value,
751         BB: &'a BasicBlock,
752     ) -> Option<&'a Value>;
753     pub fn LLVMRustBuildCatchSwitch(Builder: &Builder<'a>,
754                                     ParentPad: Option<&'a Value>,
755                                     BB: Option<&'a BasicBlock>,
756                                     NumHandlers: c_uint,
757                                     Name: *const c_char)
758                                     -> Option<&'a Value>;
759     pub fn LLVMRustAddHandler(CatchSwitch: &'a Value, Handler: &'a BasicBlock);
760     pub fn LLVMSetPersonalityFn(Func: &'a Value, Pers: &'a Value);
761
762     // Add a case to the switch instruction
763     pub fn LLVMAddCase(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
764
765     // Add a clause to the landing pad instruction
766     pub fn LLVMAddClause(LandingPad: &'a Value, ClauseVal: &'a Value);
767
768     // Set the cleanup on a landing pad instruction
769     pub fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);
770
771     // Arithmetic
772     pub fn LLVMBuildAdd(B: &Builder<'a>,
773                         LHS: &'a Value,
774                         RHS: &'a Value,
775                         Name: *const c_char)
776                         -> &'a Value;
777     pub fn LLVMBuildFAdd(B: &Builder<'a>,
778                          LHS: &'a Value,
779                          RHS: &'a Value,
780                          Name: *const c_char)
781                          -> &'a Value;
782     pub fn LLVMBuildSub(B: &Builder<'a>,
783                         LHS: &'a Value,
784                         RHS: &'a Value,
785                         Name: *const c_char)
786                         -> &'a Value;
787     pub fn LLVMBuildFSub(B: &Builder<'a>,
788                          LHS: &'a Value,
789                          RHS: &'a Value,
790                          Name: *const c_char)
791                          -> &'a Value;
792     pub fn LLVMBuildMul(B: &Builder<'a>,
793                         LHS: &'a Value,
794                         RHS: &'a Value,
795                         Name: *const c_char)
796                         -> &'a Value;
797     pub fn LLVMBuildFMul(B: &Builder<'a>,
798                          LHS: &'a Value,
799                          RHS: &'a Value,
800                          Name: *const c_char)
801                          -> &'a Value;
802     pub fn LLVMBuildUDiv(B: &Builder<'a>,
803                          LHS: &'a Value,
804                          RHS: &'a Value,
805                          Name: *const c_char)
806                          -> &'a Value;
807     pub fn LLVMBuildExactUDiv(B: &Builder<'a>,
808                               LHS: &'a Value,
809                               RHS: &'a Value,
810                               Name: *const c_char)
811                               -> &'a Value;
812     pub fn LLVMBuildSDiv(B: &Builder<'a>,
813                          LHS: &'a Value,
814                          RHS: &'a Value,
815                          Name: *const c_char)
816                          -> &'a Value;
817     pub fn LLVMBuildExactSDiv(B: &Builder<'a>,
818                               LHS: &'a Value,
819                               RHS: &'a Value,
820                               Name: *const c_char)
821                               -> &'a Value;
822     pub fn LLVMBuildFDiv(B: &Builder<'a>,
823                          LHS: &'a Value,
824                          RHS: &'a Value,
825                          Name: *const c_char)
826                          -> &'a Value;
827     pub fn LLVMBuildURem(B: &Builder<'a>,
828                          LHS: &'a Value,
829                          RHS: &'a Value,
830                          Name: *const c_char)
831                          -> &'a Value;
832     pub fn LLVMBuildSRem(B: &Builder<'a>,
833                          LHS: &'a Value,
834                          RHS: &'a Value,
835                          Name: *const c_char)
836                          -> &'a Value;
837     pub fn LLVMBuildFRem(B: &Builder<'a>,
838                          LHS: &'a Value,
839                          RHS: &'a Value,
840                          Name: *const c_char)
841                          -> &'a Value;
842     pub fn LLVMBuildShl(B: &Builder<'a>,
843                         LHS: &'a Value,
844                         RHS: &'a Value,
845                         Name: *const c_char)
846                         -> &'a Value;
847     pub fn LLVMBuildLShr(B: &Builder<'a>,
848                          LHS: &'a Value,
849                          RHS: &'a Value,
850                          Name: *const c_char)
851                          -> &'a Value;
852     pub fn LLVMBuildAShr(B: &Builder<'a>,
853                          LHS: &'a Value,
854                          RHS: &'a Value,
855                          Name: *const c_char)
856                          -> &'a Value;
857     pub fn LLVMBuildAnd(B: &Builder<'a>,
858                         LHS: &'a Value,
859                         RHS: &'a Value,
860                         Name: *const c_char)
861                         -> &'a Value;
862     pub fn LLVMBuildOr(B: &Builder<'a>,
863                        LHS: &'a Value,
864                        RHS: &'a Value,
865                        Name: *const c_char)
866                        -> &'a Value;
867     pub fn LLVMBuildXor(B: &Builder<'a>,
868                         LHS: &'a Value,
869                         RHS: &'a Value,
870                         Name: *const c_char)
871                         -> &'a Value;
872     pub fn LLVMBuildNeg(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
873     pub fn LLVMBuildFNeg(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
874     pub fn LLVMBuildNot(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
875     pub fn LLVMRustSetHasUnsafeAlgebra(Instr: &Value);
876
877     // Memory
878     pub fn LLVMBuildAlloca(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
879     pub fn LLVMBuildArrayAlloca(B: &Builder<'a>,
880                                 Ty: &'a Type,
881                                 Val: &'a Value,
882                                 Name: *const c_char)
883                                 -> &'a Value;
884     pub fn LLVMBuildLoad(B: &Builder<'a>, PointerVal: &'a Value, Name: *const c_char) -> &'a Value;
885
886     pub fn LLVMBuildStore(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
887
888     pub fn LLVMBuildGEP(B: &Builder<'a>,
889                         Pointer: &'a Value,
890                         Indices: *const &'a Value,
891                         NumIndices: c_uint,
892                         Name: *const c_char)
893                         -> &'a Value;
894     pub fn LLVMBuildInBoundsGEP(B: &Builder<'a>,
895                                 Pointer: &'a Value,
896                                 Indices: *const &'a Value,
897                                 NumIndices: c_uint,
898                                 Name: *const c_char)
899                                 -> &'a Value;
900     pub fn LLVMBuildStructGEP(B: &Builder<'a>,
901                               Pointer: &'a Value,
902                               Idx: c_uint,
903                               Name: *const c_char)
904                               -> &'a Value;
905
906     // Casts
907     pub fn LLVMBuildTrunc(B: &Builder<'a>,
908                           Val: &'a Value,
909                           DestTy: &'a Type,
910                           Name: *const c_char)
911                           -> &'a Value;
912     pub fn LLVMBuildZExt(B: &Builder<'a>,
913                          Val: &'a Value,
914                          DestTy: &'a Type,
915                          Name: *const c_char)
916                          -> &'a Value;
917     pub fn LLVMBuildSExt(B: &Builder<'a>,
918                          Val: &'a Value,
919                          DestTy: &'a Type,
920                          Name: *const c_char)
921                          -> &'a Value;
922     pub fn LLVMBuildFPToUI(B: &Builder<'a>,
923                            Val: &'a Value,
924                            DestTy: &'a Type,
925                            Name: *const c_char)
926                            -> &'a Value;
927     pub fn LLVMBuildFPToSI(B: &Builder<'a>,
928                            Val: &'a Value,
929                            DestTy: &'a Type,
930                            Name: *const c_char)
931                            -> &'a Value;
932     pub fn LLVMBuildUIToFP(B: &Builder<'a>,
933                            Val: &'a Value,
934                            DestTy: &'a Type,
935                            Name: *const c_char)
936                            -> &'a Value;
937     pub fn LLVMBuildSIToFP(B: &Builder<'a>,
938                            Val: &'a Value,
939                            DestTy: &'a Type,
940                            Name: *const c_char)
941                            -> &'a Value;
942     pub fn LLVMBuildFPTrunc(B: &Builder<'a>,
943                             Val: &'a Value,
944                             DestTy: &'a Type,
945                             Name: *const c_char)
946                             -> &'a Value;
947     pub fn LLVMBuildFPExt(B: &Builder<'a>,
948                           Val: &'a Value,
949                           DestTy: &'a Type,
950                           Name: *const c_char)
951                           -> &'a Value;
952     pub fn LLVMBuildPtrToInt(B: &Builder<'a>,
953                              Val: &'a Value,
954                              DestTy: &'a Type,
955                              Name: *const c_char)
956                              -> &'a Value;
957     pub fn LLVMBuildIntToPtr(B: &Builder<'a>,
958                              Val: &'a Value,
959                              DestTy: &'a Type,
960                              Name: *const c_char)
961                              -> &'a Value;
962     pub fn LLVMBuildBitCast(B: &Builder<'a>,
963                             Val: &'a Value,
964                             DestTy: &'a Type,
965                             Name: *const c_char)
966                             -> &'a Value;
967     pub fn LLVMBuildPointerCast(B: &Builder<'a>,
968                                 Val: &'a Value,
969                                 DestTy: &'a Type,
970                                 Name: *const c_char)
971                                 -> &'a Value;
972     pub fn LLVMRustBuildIntCast(B: &Builder<'a>,
973                                 Val: &'a Value,
974                                 DestTy: &'a Type,
975                                 IsSized: bool)
976                                 -> &'a Value;
977
978     // Comparisons
979     pub fn LLVMBuildICmp(B: &Builder<'a>,
980                          Op: c_uint,
981                          LHS: &'a Value,
982                          RHS: &'a Value,
983                          Name: *const c_char)
984                          -> &'a Value;
985     pub fn LLVMBuildFCmp(B: &Builder<'a>,
986                          Op: c_uint,
987                          LHS: &'a Value,
988                          RHS: &'a Value,
989                          Name: *const c_char)
990                          -> &'a Value;
991
992     // Miscellaneous instructions
993     pub fn LLVMBuildPhi(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
994     pub fn LLVMRustBuildCall(B: &Builder<'a>,
995                              Fn: &'a Value,
996                              Args: *const &'a Value,
997                              NumArgs: c_uint,
998                              Bundle: Option<&OperandBundleDef<'a>>,
999                              Name: *const c_char)
1000                              -> &'a Value;
1001     pub fn LLVMRustBuildMemCpy(B: &Builder<'a>,
1002                                Dst: &'a Value,
1003                                DstAlign: c_uint,
1004                                Src: &'a Value,
1005                                SrcAlign: c_uint,
1006                                Size: &'a Value,
1007                                IsVolatile: bool)
1008                                -> &'a Value;
1009     pub fn LLVMRustBuildMemMove(B: &Builder<'a>,
1010                                 Dst: &'a Value,
1011                                 DstAlign: c_uint,
1012                                 Src: &'a Value,
1013                                 SrcAlign: c_uint,
1014                                 Size: &'a Value,
1015                                 IsVolatile: bool)
1016                                 -> &'a Value;
1017     pub fn LLVMBuildSelect(B: &Builder<'a>,
1018                            If: &'a Value,
1019                            Then: &'a Value,
1020                            Else: &'a Value,
1021                            Name: *const c_char)
1022                            -> &'a Value;
1023     pub fn LLVMBuildVAArg(B: &Builder<'a>,
1024                           list: &'a Value,
1025                           Ty: &'a Type,
1026                           Name: *const c_char)
1027                           -> &'a Value;
1028     pub fn LLVMBuildExtractElement(B: &Builder<'a>,
1029                                    VecVal: &'a Value,
1030                                    Index: &'a Value,
1031                                    Name: *const c_char)
1032                                    -> &'a Value;
1033     pub fn LLVMBuildInsertElement(B: &Builder<'a>,
1034                                   VecVal: &'a Value,
1035                                   EltVal: &'a Value,
1036                                   Index: &'a Value,
1037                                   Name: *const c_char)
1038                                   -> &'a Value;
1039     pub fn LLVMBuildShuffleVector(B: &Builder<'a>,
1040                                   V1: &'a Value,
1041                                   V2: &'a Value,
1042                                   Mask: &'a Value,
1043                                   Name: *const c_char)
1044                                   -> &'a Value;
1045     pub fn LLVMBuildExtractValue(B: &Builder<'a>,
1046                                  AggVal: &'a Value,
1047                                  Index: c_uint,
1048                                  Name: *const c_char)
1049                                  -> &'a Value;
1050     pub fn LLVMBuildInsertValue(B: &Builder<'a>,
1051                                 AggVal: &'a Value,
1052                                 EltVal: &'a Value,
1053                                 Index: c_uint,
1054                                 Name: *const c_char)
1055                                 -> &'a Value;
1056
1057     pub fn LLVMRustBuildVectorReduceFAdd(B: &Builder<'a>,
1058                                          Acc: &'a Value,
1059                                          Src: &'a Value)
1060                                          -> &'a Value;
1061     pub fn LLVMRustBuildVectorReduceFMul(B: &Builder<'a>,
1062                                          Acc: &'a Value,
1063                                          Src: &'a Value)
1064                                          -> &'a Value;
1065     pub fn LLVMRustBuildVectorReduceAdd(B: &Builder<'a>,
1066                                         Src: &'a Value)
1067                                         -> &'a Value;
1068     pub fn LLVMRustBuildVectorReduceMul(B: &Builder<'a>,
1069                                         Src: &'a Value)
1070                                         -> &'a Value;
1071     pub fn LLVMRustBuildVectorReduceAnd(B: &Builder<'a>,
1072                                         Src: &'a Value)
1073                                         -> &'a Value;
1074     pub fn LLVMRustBuildVectorReduceOr(B: &Builder<'a>,
1075                                        Src: &'a Value)
1076                                        -> &'a Value;
1077     pub fn LLVMRustBuildVectorReduceXor(B: &Builder<'a>,
1078                                         Src: &'a Value)
1079                                         -> &'a Value;
1080     pub fn LLVMRustBuildVectorReduceMin(B: &Builder<'a>,
1081                                         Src: &'a Value,
1082                                         IsSigned: bool)
1083                                         -> &'a Value;
1084     pub fn LLVMRustBuildVectorReduceMax(B: &Builder<'a>,
1085                                         Src: &'a Value,
1086                                         IsSigned: bool)
1087                                         -> &'a Value;
1088     pub fn LLVMRustBuildVectorReduceFMin(B: &Builder<'a>,
1089                                          Src: &'a Value,
1090                                          IsNaN: bool)
1091                                          -> &'a Value;
1092     pub fn LLVMRustBuildVectorReduceFMax(B: &Builder<'a>,
1093                                          Src: &'a Value,
1094                                          IsNaN: bool)
1095                                          -> &'a Value;
1096
1097     pub fn LLVMRustBuildMinNum(
1098         B: &Builder<'a>,
1099         LHS: &'a Value,
1100         LHS: &'a Value,
1101     ) -> Option<&'a Value>;
1102     pub fn LLVMRustBuildMaxNum(
1103         B: &Builder<'a>,
1104         LHS: &'a Value,
1105         LHS: &'a Value,
1106     ) -> Option<&'a Value>;
1107
1108     // Atomic Operations
1109     pub fn LLVMRustBuildAtomicLoad(B: &Builder<'a>,
1110                                    PointerVal: &'a Value,
1111                                    Name: *const c_char,
1112                                    Order: AtomicOrdering)
1113                                    -> &'a Value;
1114
1115     pub fn LLVMRustBuildAtomicStore(B: &Builder<'a>,
1116                                     Val: &'a Value,
1117                                     Ptr: &'a Value,
1118                                     Order: AtomicOrdering)
1119                                     -> &'a Value;
1120
1121     pub fn LLVMRustBuildAtomicCmpXchg(B: &Builder<'a>,
1122                                       LHS: &'a Value,
1123                                       CMP: &'a Value,
1124                                       RHS: &'a Value,
1125                                       Order: AtomicOrdering,
1126                                       FailureOrder: AtomicOrdering,
1127                                       Weak: Bool)
1128                                       -> &'a Value;
1129
1130     pub fn LLVMBuildAtomicRMW(B: &Builder<'a>,
1131                               Op: AtomicRmwBinOp,
1132                               LHS: &'a Value,
1133                               RHS: &'a Value,
1134                               Order: AtomicOrdering,
1135                               SingleThreaded: Bool)
1136                               -> &'a Value;
1137
1138     pub fn LLVMRustBuildAtomicFence(B: &Builder,
1139                                     Order: AtomicOrdering,
1140                                     Scope: SynchronizationScope);
1141
1142     /// Writes a module to the specified path. Returns 0 on success.
1143     pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
1144
1145     /// Creates a pass manager.
1146     pub fn LLVMCreatePassManager() -> &'a mut PassManager<'a>;
1147
1148     /// Creates a function-by-function pass manager
1149     pub fn LLVMCreateFunctionPassManagerForModule(M: &'a Module) -> &'a mut PassManager<'a>;
1150
1151     /// Disposes a pass manager.
1152     pub fn LLVMDisposePassManager(PM: &'a mut PassManager<'a>);
1153
1154     /// Runs a pass manager on a module.
1155     pub fn LLVMRunPassManager(PM: &PassManager<'a>, M: &'a Module) -> Bool;
1156
1157     pub fn LLVMInitializePasses();
1158
1159     pub fn LLVMPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
1160     pub fn LLVMPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
1161     pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: &PassManagerBuilder, Value: Bool);
1162     pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: &PassManagerBuilder, Value: Bool);
1163     pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(PMB: &PassManagerBuilder,
1164                                                          threshold: c_uint);
1165     pub fn LLVMPassManagerBuilderPopulateModulePassManager(PMB: &PassManagerBuilder,
1166                                                            PM: &PassManager);
1167
1168     pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(PMB: &PassManagerBuilder,
1169                                                              PM: &PassManager);
1170     pub fn LLVMPassManagerBuilderPopulateLTOPassManager(PMB: &PassManagerBuilder,
1171                                                         PM: &PassManager,
1172                                                         Internalize: Bool,
1173                                                         RunInliner: Bool);
1174     pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
1175         PMB: &PassManagerBuilder,
1176         PM: &PassManager);
1177
1178     // Stuff that's in rustllvm/ because it's not upstream yet.
1179
1180     /// Opens an object file.
1181     pub fn LLVMCreateObjectFile(
1182         MemBuf: &'static mut MemoryBuffer,
1183     ) -> Option<&'static mut ObjectFile>;
1184     /// Closes an object file.
1185     pub fn LLVMDisposeObjectFile(ObjFile: &'static mut ObjectFile);
1186
1187     /// Enumerates the sections in an object file.
1188     pub fn LLVMGetSections(ObjFile: &'a ObjectFile) -> &'a mut SectionIterator<'a>;
1189     /// Destroys a section iterator.
1190     pub fn LLVMDisposeSectionIterator(SI: &'a mut SectionIterator<'a>);
1191     /// Returns true if the section iterator is at the end of the section
1192     /// list:
1193     pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &'a ObjectFile, SI: &SectionIterator<'a>) -> Bool;
1194     /// Moves the section iterator to point to the next section.
1195     pub fn LLVMMoveToNextSection(SI: &SectionIterator);
1196     /// Returns the current section size.
1197     pub fn LLVMGetSectionSize(SI: &SectionIterator) -> c_ulonglong;
1198     /// Returns the current section contents as a string buffer.
1199     pub fn LLVMGetSectionContents(SI: &SectionIterator) -> *const c_char;
1200
1201     /// Reads the given file and returns it as a memory buffer. Use
1202     /// LLVMDisposeMemoryBuffer() to get rid of it.
1203     pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(
1204         Path: *const c_char,
1205     ) -> Option<&'static mut MemoryBuffer>;
1206
1207     pub fn LLVMStartMultithreaded() -> Bool;
1208
1209     /// Returns a string describing the last error caused by an LLVMRust* call.
1210     pub fn LLVMRustGetLastError() -> *const c_char;
1211
1212     /// Print the pass timings since static dtors aren't picking them up.
1213     pub fn LLVMRustPrintPassTimings();
1214
1215     pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
1216
1217     pub fn LLVMStructSetBody(StructTy: &'a Type,
1218                              ElementTypes: *const &'a Type,
1219                              ElementCount: c_uint,
1220                              Packed: Bool);
1221
1222     /// Prepares inline assembly.
1223     pub fn LLVMRustInlineAsm(Ty: &Type,
1224                              AsmString: *const c_char,
1225                              Constraints: *const c_char,
1226                              SideEffects: Bool,
1227                              AlignStack: Bool,
1228                              Dialect: AsmDialect)
1229                              -> &Value;
1230     pub fn LLVMRustInlineAsmVerify(Ty: &Type,
1231                                    Constraints: *const c_char)
1232                                    -> bool;
1233
1234     pub fn LLVMRustDebugMetadataVersion() -> u32;
1235     pub fn LLVMRustVersionMajor() -> u32;
1236     pub fn LLVMRustVersionMinor() -> u32;
1237
1238     pub fn LLVMRustAddModuleFlag(M: &Module, name: *const c_char, value: u32);
1239
1240     pub fn LLVMRustMetadataAsValue(C: &'a Context, MD: &'a Metadata) -> &'a Value;
1241
1242     pub fn LLVMRustDIBuilderCreate(M: &'a Module) -> &'a mut DIBuilder<'a>;
1243
1244     pub fn LLVMRustDIBuilderDispose(Builder: &'a mut DIBuilder<'a>);
1245
1246     pub fn LLVMRustDIBuilderFinalize(Builder: &DIBuilder);
1247
1248     pub fn LLVMRustDIBuilderCreateCompileUnit(Builder: &DIBuilder<'a>,
1249                                               Lang: c_uint,
1250                                               File: &'a DIFile,
1251                                               Producer: *const c_char,
1252                                               isOptimized: bool,
1253                                               Flags: *const c_char,
1254                                               RuntimeVer: c_uint,
1255                                               SplitName: *const c_char)
1256                                               -> &'a DIDescriptor;
1257
1258     pub fn LLVMRustDIBuilderCreateFile(Builder: &DIBuilder<'a>,
1259                                        Filename: *const c_char,
1260                                        Directory: *const c_char)
1261                                        -> &'a DIFile;
1262
1263     pub fn LLVMRustDIBuilderCreateSubroutineType(Builder: &DIBuilder<'a>,
1264                                                  File: &'a DIFile,
1265                                                  ParameterTypes: &'a DIArray)
1266                                                  -> &'a DICompositeType;
1267
1268     pub fn LLVMRustDIBuilderCreateFunction(Builder: &DIBuilder<'a>,
1269                                            Scope: &'a DIDescriptor,
1270                                            Name: *const c_char,
1271                                            LinkageName: *const c_char,
1272                                            File: &'a DIFile,
1273                                            LineNo: c_uint,
1274                                            Ty: &'a DIType,
1275                                            isLocalToUnit: bool,
1276                                            isDefinition: bool,
1277                                            ScopeLine: c_uint,
1278                                            Flags: DIFlags,
1279                                            isOptimized: bool,
1280                                            Fn: &'a Value,
1281                                            TParam: &'a DIArray,
1282                                            Decl: Option<&'a DIDescriptor>)
1283                                            -> &'a DISubprogram;
1284
1285     pub fn LLVMRustDIBuilderCreateBasicType(Builder: &DIBuilder<'a>,
1286                                             Name: *const c_char,
1287                                             SizeInBits: u64,
1288                                             AlignInBits: u32,
1289                                             Encoding: c_uint)
1290                                             -> &'a DIBasicType;
1291
1292     pub fn LLVMRustDIBuilderCreatePointerType(Builder: &DIBuilder<'a>,
1293                                               PointeeTy: &'a DIType,
1294                                               SizeInBits: u64,
1295                                               AlignInBits: u32,
1296                                               Name: *const c_char)
1297                                               -> &'a DIDerivedType;
1298
1299     pub fn LLVMRustDIBuilderCreateStructType(Builder: &DIBuilder<'a>,
1300                                              Scope: Option<&'a DIDescriptor>,
1301                                              Name: *const c_char,
1302                                              File: &'a DIFile,
1303                                              LineNumber: c_uint,
1304                                              SizeInBits: u64,
1305                                              AlignInBits: u32,
1306                                              Flags: DIFlags,
1307                                              DerivedFrom: Option<&'a DIType>,
1308                                              Elements: &'a DIArray,
1309                                              RunTimeLang: c_uint,
1310                                              VTableHolder: Option<&'a DIType>,
1311                                              UniqueId: *const c_char)
1312                                              -> &'a DICompositeType;
1313
1314     pub fn LLVMRustDIBuilderCreateMemberType(Builder: &DIBuilder<'a>,
1315                                              Scope: &'a DIDescriptor,
1316                                              Name: *const c_char,
1317                                              File: &'a DIFile,
1318                                              LineNo: c_uint,
1319                                              SizeInBits: u64,
1320                                              AlignInBits: u32,
1321                                              OffsetInBits: u64,
1322                                              Flags: DIFlags,
1323                                              Ty: &'a DIType)
1324                                              -> &'a DIDerivedType;
1325
1326     pub fn LLVMRustDIBuilderCreateVariantMemberType(Builder: &DIBuilder<'a>,
1327                                                     Scope: &'a DIScope,
1328                                                     Name: *const c_char,
1329                                                     File: &'a DIFile,
1330                                                     LineNumber: c_uint,
1331                                                     SizeInBits: u64,
1332                                                     AlignInBits: u32,
1333                                                     OffsetInBits: u64,
1334                                                     Discriminant: Option<&'a Value>,
1335                                                     Flags: DIFlags,
1336                                                     Ty: &'a DIType)
1337                                                     -> &'a DIType;
1338
1339     pub fn LLVMRustDIBuilderCreateLexicalBlock(Builder: &DIBuilder<'a>,
1340                                                Scope: &'a DIScope,
1341                                                File: &'a DIFile,
1342                                                Line: c_uint,
1343                                                Col: c_uint)
1344                                                -> &'a DILexicalBlock;
1345
1346     pub fn LLVMRustDIBuilderCreateLexicalBlockFile(Builder: &DIBuilder<'a>,
1347                                                    Scope: &'a DIScope,
1348                                                    File: &'a DIFile)
1349                                                    -> &'a DILexicalBlock;
1350
1351     pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: &DIBuilder<'a>,
1352                                                  Context: Option<&'a DIScope>,
1353                                                  Name: *const c_char,
1354                                                  LinkageName: *const c_char,
1355                                                  File: &'a DIFile,
1356                                                  LineNo: c_uint,
1357                                                  Ty: &'a DIType,
1358                                                  isLocalToUnit: bool,
1359                                                  Val: &'a Value,
1360                                                  Decl: Option<&'a DIDescriptor>,
1361                                                  AlignInBits: u32)
1362                                                  -> &'a DIGlobalVariableExpression;
1363
1364     pub fn LLVMRustDIBuilderCreateVariable(Builder: &DIBuilder<'a>,
1365                                            Tag: c_uint,
1366                                            Scope: &'a DIDescriptor,
1367                                            Name: *const c_char,
1368                                            File: &'a DIFile,
1369                                            LineNo: c_uint,
1370                                            Ty: &'a DIType,
1371                                            AlwaysPreserve: bool,
1372                                            Flags: DIFlags,
1373                                            ArgNo: c_uint,
1374                                            AlignInBits: u32)
1375                                            -> &'a DIVariable;
1376
1377     pub fn LLVMRustDIBuilderCreateArrayType(Builder: &DIBuilder<'a>,
1378                                             Size: u64,
1379                                             AlignInBits: u32,
1380                                             Ty: &'a DIType,
1381                                             Subscripts: &'a DIArray)
1382                                             -> &'a DIType;
1383
1384     pub fn LLVMRustDIBuilderGetOrCreateSubrange(Builder: &DIBuilder<'a>,
1385                                                 Lo: i64,
1386                                                 Count: i64)
1387                                                 -> &'a DISubrange;
1388
1389     pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: &DIBuilder<'a>,
1390                                              Ptr: *const Option<&'a DIDescriptor>,
1391                                              Count: c_uint)
1392                                              -> &'a DIArray;
1393
1394     pub fn LLVMRustDIBuilderInsertDeclareAtEnd(Builder: &DIBuilder<'a>,
1395                                                Val: &'a Value,
1396                                                VarInfo: &'a DIVariable,
1397                                                AddrOps: *const i64,
1398                                                AddrOpsCount: c_uint,
1399                                                DL: &'a Value,
1400                                                InsertAtEnd: &'a BasicBlock)
1401                                                -> &'a Value;
1402
1403     pub fn LLVMRustDIBuilderCreateEnumerator(Builder: &DIBuilder<'a>,
1404                                              Name: *const c_char,
1405                                              Val: u64)
1406                                              -> &'a DIEnumerator;
1407
1408     pub fn LLVMRustDIBuilderCreateEnumerationType(Builder: &DIBuilder<'a>,
1409                                                   Scope: &'a DIScope,
1410                                                   Name: *const c_char,
1411                                                   File: &'a DIFile,
1412                                                   LineNumber: c_uint,
1413                                                   SizeInBits: u64,
1414                                                   AlignInBits: u32,
1415                                                   Elements: &'a DIArray,
1416                                                   ClassType: &'a DIType,
1417                                                   IsFixed: bool)
1418                                                   -> &'a DIType;
1419
1420     pub fn LLVMRustDIBuilderCreateUnionType(Builder: &DIBuilder<'a>,
1421                                             Scope: &'a DIScope,
1422                                             Name: *const c_char,
1423                                             File: &'a DIFile,
1424                                             LineNumber: c_uint,
1425                                             SizeInBits: u64,
1426                                             AlignInBits: u32,
1427                                             Flags: DIFlags,
1428                                             Elements: Option<&'a DIArray>,
1429                                             RunTimeLang: c_uint,
1430                                             UniqueId: *const c_char)
1431                                             -> &'a DIType;
1432
1433     pub fn LLVMRustDIBuilderCreateVariantPart(Builder: &DIBuilder<'a>,
1434                                               Scope: &'a DIScope,
1435                                               Name: *const c_char,
1436                                               File: &'a DIFile,
1437                                               LineNo: c_uint,
1438                                               SizeInBits: u64,
1439                                               AlignInBits: u32,
1440                                               Flags: DIFlags,
1441                                               Discriminator: Option<&'a DIDerivedType>,
1442                                               Elements: &'a DIArray,
1443                                               UniqueId: *const c_char)
1444                                               -> &'a DIDerivedType;
1445
1446     pub fn LLVMSetUnnamedAddr(GlobalVar: &Value, UnnamedAddr: Bool);
1447
1448     pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: &DIBuilder<'a>,
1449                                                         Scope: Option<&'a DIScope>,
1450                                                         Name: *const c_char,
1451                                                         Ty: &'a DIType,
1452                                                         File: &'a DIFile,
1453                                                         LineNo: c_uint,
1454                                                         ColumnNo: c_uint)
1455                                                         -> &'a DITemplateTypeParameter;
1456
1457
1458     pub fn LLVMRustDIBuilderCreateNameSpace(Builder: &DIBuilder<'a>,
1459                                             Scope: Option<&'a DIScope>,
1460                                             Name: *const c_char,
1461                                             File: &'a DIFile,
1462                                             LineNo: c_uint)
1463                                             -> &'a DINameSpace;
1464
1465     pub fn LLVMRustDICompositeTypeSetTypeArray(Builder: &DIBuilder<'a>,
1466                                                CompositeType: &'a DIType,
1467                                                TypeArray: &'a DIArray);
1468
1469
1470     pub fn LLVMRustDIBuilderCreateDebugLocation(Context: &'a Context,
1471                                                 Line: c_uint,
1472                                                 Column: c_uint,
1473                                                 Scope: &'a DIScope,
1474                                                 InlinedAt: Option<&'a Metadata>)
1475                                                 -> &'a Value;
1476     pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
1477     pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
1478 }
1479
1480 #[allow(improper_ctypes)] // FIXME(#52456) needed for RustString.
1481 extern "C" {
1482     pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
1483     pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
1484 }
1485
1486 extern "C" {
1487     pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&Value>;
1488     pub fn LLVMIsAConstantFP(value_ref: &Value) -> Option<&Value>;
1489
1490     pub fn LLVMRustPassKind(Pass: &Pass) -> PassKind;
1491     pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> Option<&'static mut Pass>;
1492     pub fn LLVMRustAddPass(PM: &PassManager, Pass: &'static mut Pass);
1493
1494     pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
1495
1496     pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine);
1497     pub fn LLVMRustPrintTargetFeatures(T: &TargetMachine);
1498
1499     pub fn LLVMRustGetHostCPUName(len: *mut usize) -> *const c_char;
1500     pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
1501                                        CPU: *const c_char,
1502                                        Features: *const c_char,
1503                                        Model: CodeModel,
1504                                        Reloc: RelocMode,
1505                                        Level: CodeGenOptLevel,
1506                                        UseSoftFP: bool,
1507                                        PositionIndependentExecutable: bool,
1508                                        FunctionSections: bool,
1509                                        DataSections: bool,
1510                                        TrapUnreachable: bool,
1511                                        Singlethread: bool,
1512                                        AsmComments: bool,
1513                                        EmitStackSizeSection: bool)
1514                                        -> Option<&'static mut TargetMachine>;
1515     pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
1516     pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module);
1517     pub fn LLVMRustAddBuilderLibraryInfo(PMB: &'a PassManagerBuilder,
1518                                          M: &'a Module,
1519                                          DisableSimplifyLibCalls: bool);
1520     pub fn LLVMRustConfigurePassManagerBuilder(PMB: &PassManagerBuilder,
1521                                                OptLevel: CodeGenOptLevel,
1522                                                MergeFunctions: bool,
1523                                                SLPVectorize: bool,
1524                                                LoopVectorize: bool,
1525                                                PrepareForThinLTO: bool,
1526                                                PGOGenPath: *const c_char,
1527                                                PGOUsePath: *const c_char);
1528     pub fn LLVMRustAddLibraryInfo(PM: &PassManager<'a>,
1529                                   M: &'a Module,
1530                                   DisableSimplifyLibCalls: bool);
1531     pub fn LLVMRustRunFunctionPassManager(PM: &PassManager<'a>, M: &'a Module);
1532     pub fn LLVMRustWriteOutputFile(T: &'a TargetMachine,
1533                                    PM: &PassManager<'a>,
1534                                    M: &'a Module,
1535                                    Output: *const c_char,
1536                                    FileType: FileType)
1537                                    -> LLVMRustResult;
1538     pub fn LLVMRustPrintModule(PM: &PassManager<'a>,
1539                                M: &'a Module,
1540                                Output: *const c_char,
1541                                Demangle: extern fn(*const c_char,
1542                                                    size_t,
1543                                                    *mut c_char,
1544                                                    size_t) -> size_t);
1545     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
1546     pub fn LLVMRustPrintPasses();
1547     pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
1548     pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
1549     pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
1550     pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);
1551
1552     pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
1553     pub fn LLVMRustArchiveIteratorNew(AR: &'a Archive) -> &'a mut ArchiveIterator<'a>;
1554     pub fn LLVMRustArchiveIteratorNext(
1555         AIR: &ArchiveIterator<'a>,
1556     ) -> Option<&'a mut ArchiveChild<'a>>;
1557     pub fn LLVMRustArchiveChildName(ACR: &ArchiveChild, size: &mut size_t) -> *const c_char;
1558     pub fn LLVMRustArchiveChildData(ACR: &ArchiveChild, size: &mut size_t) -> *const c_char;
1559     pub fn LLVMRustArchiveChildFree(ACR: &'a mut ArchiveChild<'a>);
1560     pub fn LLVMRustArchiveIteratorFree(AIR: &'a mut ArchiveIterator<'a>);
1561     pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
1562
1563     pub fn LLVMRustGetSectionName(SI: &SectionIterator, data: &mut *const c_char) -> size_t;
1564 }
1565
1566 #[allow(improper_ctypes)] // FIXME(#52456) needed for RustString.
1567 extern "C" {
1568     pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
1569 }
1570
1571 extern "C" {
1572     pub fn LLVMContextSetDiagnosticHandler(C: &Context,
1573                                            Handler: DiagnosticHandler,
1574                                            DiagnosticContext: *mut c_void);
1575 }
1576
1577 #[allow(improper_ctypes)] // FIXME(#52456) needed for RustString.
1578 extern "C" {
1579     pub fn LLVMRustUnpackOptimizationDiagnostic(DI: &'a DiagnosticInfo,
1580                                                 pass_name_out: &RustString,
1581                                                 function_out: &mut Option<&'a Value>,
1582                                                 loc_line_out: &mut c_uint,
1583                                                 loc_column_out: &mut c_uint,
1584                                                 loc_filename_out: &RustString,
1585                                                 message_out: &RustString);
1586 }
1587
1588 extern "C" {
1589     pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: &'a DiagnosticInfo,
1590                                              cookie_out: &mut c_uint,
1591                                              message_out: &mut Option<&'a Twine>,
1592                                              instruction_out: &mut Option<&'a Value>);
1593 }
1594
1595 #[allow(improper_ctypes)] // FIXME(#52456) needed for RustString.
1596 extern "C" {
1597     pub fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
1598 }
1599
1600 extern "C" {
1601     pub fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
1602
1603     pub fn LLVMRustSetInlineAsmDiagnosticHandler(C: &Context,
1604                                                  H: InlineAsmDiagHandler,
1605                                                  CX: *mut c_void);
1606 }
1607
1608 #[allow(improper_ctypes)] // FIXME(#52456) needed for RustString.
1609 extern "C" {
1610     pub fn LLVMRustWriteSMDiagnosticToString(d: &SMDiagnostic, s: &RustString);
1611 }
1612
1613 extern "C" {
1614     pub fn LLVMRustWriteArchive(Dst: *const c_char,
1615                                 NumMembers: size_t,
1616                                 Members: *const &RustArchiveMember,
1617                                 WriteSymbtab: bool,
1618                                 Kind: ArchiveKind)
1619                                 -> LLVMRustResult;
1620     pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
1621                                     Name: *const c_char,
1622                                     Child: Option<&ArchiveChild<'a>>)
1623                                     -> &'a mut RustArchiveMember<'a>;
1624     pub fn LLVMRustArchiveMemberFree(Member: &'a mut RustArchiveMember<'a>);
1625
1626     pub fn LLVMRustSetDataLayoutFromTargetMachine(M: &'a Module, TM: &'a TargetMachine);
1627
1628     pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
1629                                          Inputs: *const &'a Value,
1630                                          NumInputs: c_uint)
1631                                          -> &'a mut OperandBundleDef<'a>;
1632     pub fn LLVMRustFreeOperandBundleDef(Bundle: &'a mut OperandBundleDef<'a>);
1633
1634     pub fn LLVMRustPositionBuilderAtStart(B: &Builder<'a>, BB: &'a BasicBlock);
1635
1636     pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char);
1637     pub fn LLVMRustUnsetComdat(V: &Value);
1638     pub fn LLVMRustSetModulePIELevel(M: &Module);
1639     pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
1640     pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
1641     pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
1642     pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
1643     pub fn LLVMRustModuleCost(M: &Module) -> u64;
1644
1645     pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> &'static mut ThinLTOBuffer;
1646     pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
1647     pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
1648     pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
1649     pub fn LLVMRustCreateThinLTOData(
1650         Modules: *const ThinLTOModule,
1651         NumModules: c_uint,
1652         PreservedSymbols: *const *const c_char,
1653         PreservedSymbolsLen: c_uint,
1654     ) -> Option<&'static mut ThinLTOData>;
1655     pub fn LLVMRustPrepareThinLTORename(
1656         Data: &ThinLTOData,
1657         Module: &Module,
1658     ) -> bool;
1659     pub fn LLVMRustPrepareThinLTOResolveWeak(
1660         Data: &ThinLTOData,
1661         Module: &Module,
1662     ) -> bool;
1663     pub fn LLVMRustPrepareThinLTOInternalize(
1664         Data: &ThinLTOData,
1665         Module: &Module,
1666     ) -> bool;
1667     pub fn LLVMRustPrepareThinLTOImport(
1668         Data: &ThinLTOData,
1669         Module: &Module,
1670     ) -> bool;
1671     pub fn LLVMRustGetThinLTOModuleImports(
1672         Data: *const ThinLTOData,
1673         ModuleNameCallback: ThinLTOModuleNameCallback,
1674         CallbackPayload: *mut c_void,
1675     );
1676     pub fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
1677     pub fn LLVMRustParseBitcodeForThinLTO(
1678         Context: &Context,
1679         Data: *const u8,
1680         len: usize,
1681         Identifier: *const c_char,
1682     ) -> Option<&Module>;
1683     pub fn LLVMRustThinLTOGetDICompileUnit(M: &Module,
1684                                            CU1: &mut *mut c_void,
1685                                            CU2: &mut *mut c_void);
1686     pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
1687
1688     pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>;
1689     pub fn LLVMRustLinkerAdd(linker: &Linker,
1690                              bytecode: *const c_char,
1691                              bytecode_len: usize) -> bool;
1692     pub fn LLVMRustLinkerFree(linker: &'a mut Linker<'a>);
1693 }