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