]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_llvm/src/llvm/ffi.rs
ed0825e124c456b804b3c0294b0ad5b5d8390697
[rust.git] / compiler / rustc_codegen_llvm / src / llvm / ffi.rs
1 #![allow(non_camel_case_types)]
2 #![allow(non_upper_case_globals)]
3
4 use rustc_codegen_ssa::coverageinfo::map as coverage_map;
5
6 use super::debuginfo::{
7     DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
8     DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace,
9     DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable,
10     DebugEmissionKind,
11 };
12
13 use libc::{c_char, c_int, c_uint, size_t};
14 use libc::{c_ulonglong, c_void};
15
16 use std::marker::PhantomData;
17
18 use super::RustString;
19
20 pub type Bool = c_uint;
21
22 pub const True: Bool = 1 as Bool;
23 pub const False: Bool = 0 as Bool;
24
25 #[derive(Copy, Clone, PartialEq)]
26 #[repr(C)]
27 #[allow(dead_code)] // Variants constructed by C++.
28 pub enum LLVMRustResult {
29     Success,
30     Failure,
31 }
32
33 // Rust version of the C struct with the same name in rustc_llvm/llvm-wrapper/RustWrapper.cpp.
34 #[repr(C)]
35 pub struct LLVMRustCOFFShortExport {
36     pub name: *const c_char,
37     pub ordinal_present: bool,
38     // value of `ordinal` only important when `ordinal_present` is true
39     pub ordinal: u16,
40 }
41
42 impl LLVMRustCOFFShortExport {
43     pub fn new(name: *const c_char, ordinal: Option<u16>) -> LLVMRustCOFFShortExport {
44         LLVMRustCOFFShortExport {
45             name,
46             ordinal_present: ordinal.is_some(),
47             ordinal: ordinal.unwrap_or(0),
48         }
49     }
50 }
51
52 /// Translation of LLVM's MachineTypes enum, defined in llvm\include\llvm\BinaryFormat\COFF.h.
53 ///
54 /// We include only architectures supported on Windows.
55 #[derive(Copy, Clone, PartialEq)]
56 #[repr(C)]
57 pub enum LLVMMachineType {
58     AMD64 = 0x8664,
59     I386 = 0x14c,
60     ARM64 = 0xaa64,
61     ARM = 0x01c0,
62 }
63
64 /// LLVM's Module::ModFlagBehavior, defined in llvm/include/llvm/IR/Module.h.
65 ///
66 /// When merging modules (e.g. during LTO), their metadata flags are combined. Conflicts are
67 /// resolved according to the merge behaviors specified here. Flags differing only in merge
68 /// behavior are still considered to be in conflict.
69 ///
70 /// In order for Rust-C LTO to work, we must specify behaviors compatible with Clang. Notably,
71 /// 'Error' and 'Warning' cannot be mixed for a given flag.
72 #[derive(Copy, Clone, PartialEq)]
73 #[repr(C)]
74 pub enum LLVMModFlagBehavior {
75     Error = 1,
76     Warning = 2,
77     Require = 3,
78     Override = 4,
79     Append = 5,
80     AppendUnique = 6,
81     Max = 7,
82 }
83
84 // Consts for the LLVM CallConv type, pre-cast to usize.
85
86 /// LLVM CallingConv::ID. Should we wrap this?
87 #[derive(Copy, Clone, PartialEq, Debug)]
88 #[repr(C)]
89 pub enum CallConv {
90     CCallConv = 0,
91     FastCallConv = 8,
92     ColdCallConv = 9,
93     X86StdcallCallConv = 64,
94     X86FastcallCallConv = 65,
95     ArmAapcsCallConv = 67,
96     Msp430Intr = 69,
97     X86_ThisCall = 70,
98     PtxKernel = 71,
99     X86_64_SysV = 78,
100     X86_64_Win64 = 79,
101     X86_VectorCall = 80,
102     X86_Intr = 83,
103     AvrNonBlockingInterrupt = 84,
104     AvrInterrupt = 85,
105     AmdGpuKernel = 91,
106 }
107
108 /// LLVMRustLinkage
109 #[derive(Copy, Clone, PartialEq)]
110 #[repr(C)]
111 pub enum Linkage {
112     ExternalLinkage = 0,
113     AvailableExternallyLinkage = 1,
114     LinkOnceAnyLinkage = 2,
115     LinkOnceODRLinkage = 3,
116     WeakAnyLinkage = 4,
117     WeakODRLinkage = 5,
118     AppendingLinkage = 6,
119     InternalLinkage = 7,
120     PrivateLinkage = 8,
121     ExternalWeakLinkage = 9,
122     CommonLinkage = 10,
123 }
124
125 // LLVMRustVisibility
126 #[repr(C)]
127 #[derive(Copy, Clone, PartialEq)]
128 pub enum Visibility {
129     Default = 0,
130     Hidden = 1,
131     Protected = 2,
132 }
133
134 /// LLVMUnnamedAddr
135 #[repr(C)]
136 pub enum UnnamedAddr {
137     No,
138     Local,
139     Global,
140 }
141
142 /// LLVMDLLStorageClass
143 #[derive(Copy, Clone)]
144 #[repr(C)]
145 pub enum DLLStorageClass {
146     #[allow(dead_code)]
147     Default = 0,
148     DllImport = 1, // Function to be imported from DLL.
149     #[allow(dead_code)]
150     DllExport = 2, // Function to be accessible from DLL.
151 }
152
153 /// Matches LLVMRustAttribute in LLVMWrapper.h
154 /// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
155 /// though it is not ABI compatible (since it's a C++ enum)
156 #[repr(C)]
157 #[derive(Copy, Clone, Debug)]
158 pub enum AttributeKind {
159     AlwaysInline = 0,
160     ByVal = 1,
161     Cold = 2,
162     InlineHint = 3,
163     MinSize = 4,
164     Naked = 5,
165     NoAlias = 6,
166     NoCapture = 7,
167     NoInline = 8,
168     NonNull = 9,
169     NoRedZone = 10,
170     NoReturn = 11,
171     NoUnwind = 12,
172     OptimizeForSize = 13,
173     ReadOnly = 14,
174     SExt = 15,
175     StructRet = 16,
176     UWTable = 17,
177     ZExt = 18,
178     InReg = 19,
179     SanitizeThread = 20,
180     SanitizeAddress = 21,
181     SanitizeMemory = 22,
182     NonLazyBind = 23,
183     OptimizeNone = 24,
184     ReturnsTwice = 25,
185     ReadNone = 26,
186     InaccessibleMemOnly = 27,
187     SanitizeHWAddress = 28,
188     WillReturn = 29,
189     StackProtectReq = 30,
190     StackProtectStrong = 31,
191     StackProtect = 32,
192     NoUndef = 33,
193     SanitizeMemTag = 34,
194 }
195
196 /// LLVMIntPredicate
197 #[derive(Copy, Clone)]
198 #[repr(C)]
199 pub enum IntPredicate {
200     IntEQ = 32,
201     IntNE = 33,
202     IntUGT = 34,
203     IntUGE = 35,
204     IntULT = 36,
205     IntULE = 37,
206     IntSGT = 38,
207     IntSGE = 39,
208     IntSLT = 40,
209     IntSLE = 41,
210 }
211
212 impl IntPredicate {
213     pub fn from_generic(intpre: rustc_codegen_ssa::common::IntPredicate) -> Self {
214         match intpre {
215             rustc_codegen_ssa::common::IntPredicate::IntEQ => IntPredicate::IntEQ,
216             rustc_codegen_ssa::common::IntPredicate::IntNE => IntPredicate::IntNE,
217             rustc_codegen_ssa::common::IntPredicate::IntUGT => IntPredicate::IntUGT,
218             rustc_codegen_ssa::common::IntPredicate::IntUGE => IntPredicate::IntUGE,
219             rustc_codegen_ssa::common::IntPredicate::IntULT => IntPredicate::IntULT,
220             rustc_codegen_ssa::common::IntPredicate::IntULE => IntPredicate::IntULE,
221             rustc_codegen_ssa::common::IntPredicate::IntSGT => IntPredicate::IntSGT,
222             rustc_codegen_ssa::common::IntPredicate::IntSGE => IntPredicate::IntSGE,
223             rustc_codegen_ssa::common::IntPredicate::IntSLT => IntPredicate::IntSLT,
224             rustc_codegen_ssa::common::IntPredicate::IntSLE => IntPredicate::IntSLE,
225         }
226     }
227 }
228
229 /// LLVMRealPredicate
230 #[derive(Copy, Clone)]
231 #[repr(C)]
232 pub enum RealPredicate {
233     RealPredicateFalse = 0,
234     RealOEQ = 1,
235     RealOGT = 2,
236     RealOGE = 3,
237     RealOLT = 4,
238     RealOLE = 5,
239     RealONE = 6,
240     RealORD = 7,
241     RealUNO = 8,
242     RealUEQ = 9,
243     RealUGT = 10,
244     RealUGE = 11,
245     RealULT = 12,
246     RealULE = 13,
247     RealUNE = 14,
248     RealPredicateTrue = 15,
249 }
250
251 impl RealPredicate {
252     pub fn from_generic(realp: rustc_codegen_ssa::common::RealPredicate) -> Self {
253         match realp {
254             rustc_codegen_ssa::common::RealPredicate::RealPredicateFalse => {
255                 RealPredicate::RealPredicateFalse
256             }
257             rustc_codegen_ssa::common::RealPredicate::RealOEQ => RealPredicate::RealOEQ,
258             rustc_codegen_ssa::common::RealPredicate::RealOGT => RealPredicate::RealOGT,
259             rustc_codegen_ssa::common::RealPredicate::RealOGE => RealPredicate::RealOGE,
260             rustc_codegen_ssa::common::RealPredicate::RealOLT => RealPredicate::RealOLT,
261             rustc_codegen_ssa::common::RealPredicate::RealOLE => RealPredicate::RealOLE,
262             rustc_codegen_ssa::common::RealPredicate::RealONE => RealPredicate::RealONE,
263             rustc_codegen_ssa::common::RealPredicate::RealORD => RealPredicate::RealORD,
264             rustc_codegen_ssa::common::RealPredicate::RealUNO => RealPredicate::RealUNO,
265             rustc_codegen_ssa::common::RealPredicate::RealUEQ => RealPredicate::RealUEQ,
266             rustc_codegen_ssa::common::RealPredicate::RealUGT => RealPredicate::RealUGT,
267             rustc_codegen_ssa::common::RealPredicate::RealUGE => RealPredicate::RealUGE,
268             rustc_codegen_ssa::common::RealPredicate::RealULT => RealPredicate::RealULT,
269             rustc_codegen_ssa::common::RealPredicate::RealULE => RealPredicate::RealULE,
270             rustc_codegen_ssa::common::RealPredicate::RealUNE => RealPredicate::RealUNE,
271             rustc_codegen_ssa::common::RealPredicate::RealPredicateTrue => {
272                 RealPredicate::RealPredicateTrue
273             }
274         }
275     }
276 }
277
278 /// LLVMTypeKind
279 #[derive(Copy, Clone, PartialEq, Debug)]
280 #[repr(C)]
281 pub enum TypeKind {
282     Void = 0,
283     Half = 1,
284     Float = 2,
285     Double = 3,
286     X86_FP80 = 4,
287     FP128 = 5,
288     PPC_FP128 = 6,
289     Label = 7,
290     Integer = 8,
291     Function = 9,
292     Struct = 10,
293     Array = 11,
294     Pointer = 12,
295     Vector = 13,
296     Metadata = 14,
297     X86_MMX = 15,
298     Token = 16,
299     ScalableVector = 17,
300     BFloat = 18,
301     X86_AMX = 19,
302 }
303
304 impl TypeKind {
305     pub fn to_generic(self) -> rustc_codegen_ssa::common::TypeKind {
306         match self {
307             TypeKind::Void => rustc_codegen_ssa::common::TypeKind::Void,
308             TypeKind::Half => rustc_codegen_ssa::common::TypeKind::Half,
309             TypeKind::Float => rustc_codegen_ssa::common::TypeKind::Float,
310             TypeKind::Double => rustc_codegen_ssa::common::TypeKind::Double,
311             TypeKind::X86_FP80 => rustc_codegen_ssa::common::TypeKind::X86_FP80,
312             TypeKind::FP128 => rustc_codegen_ssa::common::TypeKind::FP128,
313             TypeKind::PPC_FP128 => rustc_codegen_ssa::common::TypeKind::PPC_FP128,
314             TypeKind::Label => rustc_codegen_ssa::common::TypeKind::Label,
315             TypeKind::Integer => rustc_codegen_ssa::common::TypeKind::Integer,
316             TypeKind::Function => rustc_codegen_ssa::common::TypeKind::Function,
317             TypeKind::Struct => rustc_codegen_ssa::common::TypeKind::Struct,
318             TypeKind::Array => rustc_codegen_ssa::common::TypeKind::Array,
319             TypeKind::Pointer => rustc_codegen_ssa::common::TypeKind::Pointer,
320             TypeKind::Vector => rustc_codegen_ssa::common::TypeKind::Vector,
321             TypeKind::Metadata => rustc_codegen_ssa::common::TypeKind::Metadata,
322             TypeKind::X86_MMX => rustc_codegen_ssa::common::TypeKind::X86_MMX,
323             TypeKind::Token => rustc_codegen_ssa::common::TypeKind::Token,
324             TypeKind::ScalableVector => rustc_codegen_ssa::common::TypeKind::ScalableVector,
325             TypeKind::BFloat => rustc_codegen_ssa::common::TypeKind::BFloat,
326             TypeKind::X86_AMX => rustc_codegen_ssa::common::TypeKind::X86_AMX,
327         }
328     }
329 }
330
331 /// LLVMAtomicRmwBinOp
332 #[derive(Copy, Clone)]
333 #[repr(C)]
334 pub enum AtomicRmwBinOp {
335     AtomicXchg = 0,
336     AtomicAdd = 1,
337     AtomicSub = 2,
338     AtomicAnd = 3,
339     AtomicNand = 4,
340     AtomicOr = 5,
341     AtomicXor = 6,
342     AtomicMax = 7,
343     AtomicMin = 8,
344     AtomicUMax = 9,
345     AtomicUMin = 10,
346 }
347
348 impl AtomicRmwBinOp {
349     pub fn from_generic(op: rustc_codegen_ssa::common::AtomicRmwBinOp) -> Self {
350         match op {
351             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg => AtomicRmwBinOp::AtomicXchg,
352             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAdd => AtomicRmwBinOp::AtomicAdd,
353             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicSub => AtomicRmwBinOp::AtomicSub,
354             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAnd => AtomicRmwBinOp::AtomicAnd,
355             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicNand => AtomicRmwBinOp::AtomicNand,
356             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicOr => AtomicRmwBinOp::AtomicOr,
357             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXor => AtomicRmwBinOp::AtomicXor,
358             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMax => AtomicRmwBinOp::AtomicMax,
359             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMin => AtomicRmwBinOp::AtomicMin,
360             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMax => AtomicRmwBinOp::AtomicUMax,
361             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMin => AtomicRmwBinOp::AtomicUMin,
362         }
363     }
364 }
365
366 /// LLVMAtomicOrdering
367 #[derive(Copy, Clone)]
368 #[repr(C)]
369 pub enum AtomicOrdering {
370     #[allow(dead_code)]
371     NotAtomic = 0,
372     Unordered = 1,
373     Monotonic = 2,
374     // Consume = 3,  // Not specified yet.
375     Acquire = 4,
376     Release = 5,
377     AcquireRelease = 6,
378     SequentiallyConsistent = 7,
379 }
380
381 impl AtomicOrdering {
382     pub fn from_generic(ao: rustc_codegen_ssa::common::AtomicOrdering) -> Self {
383         match ao {
384             rustc_codegen_ssa::common::AtomicOrdering::NotAtomic => AtomicOrdering::NotAtomic,
385             rustc_codegen_ssa::common::AtomicOrdering::Unordered => AtomicOrdering::Unordered,
386             rustc_codegen_ssa::common::AtomicOrdering::Monotonic => AtomicOrdering::Monotonic,
387             rustc_codegen_ssa::common::AtomicOrdering::Acquire => AtomicOrdering::Acquire,
388             rustc_codegen_ssa::common::AtomicOrdering::Release => AtomicOrdering::Release,
389             rustc_codegen_ssa::common::AtomicOrdering::AcquireRelease => {
390                 AtomicOrdering::AcquireRelease
391             }
392             rustc_codegen_ssa::common::AtomicOrdering::SequentiallyConsistent => {
393                 AtomicOrdering::SequentiallyConsistent
394             }
395         }
396     }
397 }
398
399 /// LLVMRustSynchronizationScope
400 #[derive(Copy, Clone)]
401 #[repr(C)]
402 pub enum SynchronizationScope {
403     SingleThread,
404     CrossThread,
405 }
406
407 impl SynchronizationScope {
408     pub fn from_generic(sc: rustc_codegen_ssa::common::SynchronizationScope) -> Self {
409         match sc {
410             rustc_codegen_ssa::common::SynchronizationScope::SingleThread => {
411                 SynchronizationScope::SingleThread
412             }
413             rustc_codegen_ssa::common::SynchronizationScope::CrossThread => {
414                 SynchronizationScope::CrossThread
415             }
416         }
417     }
418 }
419
420 /// LLVMRustFileType
421 #[derive(Copy, Clone)]
422 #[repr(C)]
423 pub enum FileType {
424     AssemblyFile,
425     ObjectFile,
426 }
427
428 /// LLVMMetadataType
429 #[derive(Copy, Clone)]
430 #[repr(C)]
431 pub enum MetadataType {
432     MD_dbg = 0,
433     MD_tbaa = 1,
434     MD_prof = 2,
435     MD_fpmath = 3,
436     MD_range = 4,
437     MD_tbaa_struct = 5,
438     MD_invariant_load = 6,
439     MD_alias_scope = 7,
440     MD_noalias = 8,
441     MD_nontemporal = 9,
442     MD_mem_parallel_loop_access = 10,
443     MD_nonnull = 11,
444     MD_align = 17,
445     MD_type = 19,
446     MD_noundef = 29,
447 }
448
449 /// LLVMRustAsmDialect
450 #[derive(Copy, Clone, PartialEq)]
451 #[repr(C)]
452 pub enum AsmDialect {
453     Att,
454     Intel,
455 }
456
457 /// LLVMRustCodeGenOptLevel
458 #[derive(Copy, Clone, PartialEq)]
459 #[repr(C)]
460 pub enum CodeGenOptLevel {
461     None,
462     Less,
463     Default,
464     Aggressive,
465 }
466
467 /// LLVMRustPassBuilderOptLevel
468 #[repr(C)]
469 pub enum PassBuilderOptLevel {
470     O0,
471     O1,
472     O2,
473     O3,
474     Os,
475     Oz,
476 }
477
478 /// LLVMRustOptStage
479 #[derive(PartialEq)]
480 #[repr(C)]
481 pub enum OptStage {
482     PreLinkNoLTO,
483     PreLinkThinLTO,
484     PreLinkFatLTO,
485     ThinLTO,
486     FatLTO,
487 }
488
489 /// LLVMRustSanitizerOptions
490 #[repr(C)]
491 pub struct SanitizerOptions {
492     pub sanitize_address: bool,
493     pub sanitize_address_recover: bool,
494     pub sanitize_memory: bool,
495     pub sanitize_memory_recover: bool,
496     pub sanitize_memory_track_origins: c_int,
497     pub sanitize_thread: bool,
498     pub sanitize_hwaddress: bool,
499     pub sanitize_hwaddress_recover: bool,
500 }
501
502 /// LLVMRelocMode
503 #[derive(Copy, Clone, PartialEq)]
504 #[repr(C)]
505 pub enum RelocModel {
506     Static,
507     PIC,
508     DynamicNoPic,
509     ROPI,
510     RWPI,
511     ROPI_RWPI,
512 }
513
514 /// LLVMRustCodeModel
515 #[derive(Copy, Clone)]
516 #[repr(C)]
517 pub enum CodeModel {
518     Tiny,
519     Small,
520     Kernel,
521     Medium,
522     Large,
523     None,
524 }
525
526 /// LLVMRustDiagnosticKind
527 #[derive(Copy, Clone)]
528 #[repr(C)]
529 #[allow(dead_code)] // Variants constructed by C++.
530 pub enum DiagnosticKind {
531     Other,
532     InlineAsm,
533     StackSize,
534     DebugMetadataVersion,
535     SampleProfile,
536     OptimizationRemark,
537     OptimizationRemarkMissed,
538     OptimizationRemarkAnalysis,
539     OptimizationRemarkAnalysisFPCommute,
540     OptimizationRemarkAnalysisAliasing,
541     OptimizationRemarkOther,
542     OptimizationFailure,
543     PGOProfile,
544     Linker,
545     Unsupported,
546     SrcMgr,
547 }
548
549 /// LLVMRustDiagnosticLevel
550 #[derive(Copy, Clone)]
551 #[repr(C)]
552 #[allow(dead_code)] // Variants constructed by C++.
553 pub enum DiagnosticLevel {
554     Error,
555     Warning,
556     Note,
557     Remark,
558 }
559
560 /// LLVMRustArchiveKind
561 #[derive(Copy, Clone)]
562 #[repr(C)]
563 pub enum ArchiveKind {
564     K_GNU,
565     K_BSD,
566     K_DARWIN,
567     K_COFF,
568 }
569
570 /// LLVMRustPassKind
571 #[derive(Copy, Clone, PartialEq, Debug)]
572 #[repr(C)]
573 #[allow(dead_code)] // Variants constructed by C++.
574 pub enum PassKind {
575     Other,
576     Function,
577     Module,
578 }
579
580 /// LLVMRustThinLTOData
581 extern "C" {
582     pub type ThinLTOData;
583 }
584
585 /// LLVMRustThinLTOBuffer
586 extern "C" {
587     pub type ThinLTOBuffer;
588 }
589
590 // LLVMRustModuleNameCallback
591 pub type ThinLTOModuleNameCallback =
592     unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);
593
594 /// LLVMRustThinLTOModule
595 #[repr(C)]
596 pub struct ThinLTOModule {
597     pub identifier: *const c_char,
598     pub data: *const u8,
599     pub len: usize,
600 }
601
602 /// LLVMThreadLocalMode
603 #[derive(Copy, Clone)]
604 #[repr(C)]
605 pub enum ThreadLocalMode {
606     NotThreadLocal,
607     GeneralDynamic,
608     LocalDynamic,
609     InitialExec,
610     LocalExec,
611 }
612
613 /// LLVMRustChecksumKind
614 #[derive(Copy, Clone)]
615 #[repr(C)]
616 pub enum ChecksumKind {
617     None,
618     MD5,
619     SHA1,
620     SHA256,
621 }
622
623 extern "C" {
624     type Opaque;
625 }
626 #[repr(C)]
627 struct InvariantOpaque<'a> {
628     _marker: PhantomData<&'a mut &'a ()>,
629     _opaque: Opaque,
630 }
631
632 // Opaque pointer types
633 extern "C" {
634     pub type Module;
635 }
636 extern "C" {
637     pub type Context;
638 }
639 extern "C" {
640     pub type Type;
641 }
642 extern "C" {
643     pub type Value;
644 }
645 extern "C" {
646     pub type ConstantInt;
647 }
648 extern "C" {
649     pub type Attribute;
650 }
651 extern "C" {
652     pub type Metadata;
653 }
654 extern "C" {
655     pub type BasicBlock;
656 }
657 #[repr(C)]
658 pub struct Builder<'a>(InvariantOpaque<'a>);
659 extern "C" {
660     pub type MemoryBuffer;
661 }
662 #[repr(C)]
663 pub struct PassManager<'a>(InvariantOpaque<'a>);
664 extern "C" {
665     pub type PassManagerBuilder;
666 }
667 extern "C" {
668     pub type Pass;
669 }
670 extern "C" {
671     pub type TargetMachine;
672 }
673 extern "C" {
674     pub type Archive;
675 }
676 #[repr(C)]
677 pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
678 #[repr(C)]
679 pub struct ArchiveChild<'a>(InvariantOpaque<'a>);
680 extern "C" {
681     pub type Twine;
682 }
683 extern "C" {
684     pub type DiagnosticInfo;
685 }
686 extern "C" {
687     pub type SMDiagnostic;
688 }
689 #[repr(C)]
690 pub struct RustArchiveMember<'a>(InvariantOpaque<'a>);
691 #[repr(C)]
692 pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
693 #[repr(C)]
694 pub struct Linker<'a>(InvariantOpaque<'a>);
695
696 extern "C" {
697     pub type DiagnosticHandler;
698 }
699
700 pub type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
701 pub type InlineAsmDiagHandlerTy = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
702
703 pub mod coverageinfo {
704     use super::coverage_map;
705
706     /// Aligns with [llvm::coverage::CounterMappingRegion::RegionKind](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L209-L230)
707     #[derive(Copy, Clone, Debug)]
708     #[repr(C)]
709     pub enum RegionKind {
710         /// A CodeRegion associates some code with a counter
711         CodeRegion = 0,
712
713         /// An ExpansionRegion represents a file expansion region that associates
714         /// a source range with the expansion of a virtual source file, such as
715         /// for a macro instantiation or #include file.
716         ExpansionRegion = 1,
717
718         /// A SkippedRegion represents a source range with code that was skipped
719         /// by a preprocessor or similar means.
720         SkippedRegion = 2,
721
722         /// A GapRegion is like a CodeRegion, but its count is only set as the
723         /// line execution count when its the only region in the line.
724         GapRegion = 3,
725
726         /// A BranchRegion represents leaf-level boolean expressions and is
727         /// associated with two counters, each representing the number of times the
728         /// expression evaluates to true or false.
729         BranchRegion = 4,
730     }
731
732     /// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the
733     /// coverage map, in accordance with the
734     /// [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#llvm-code-coverage-mapping-format).
735     /// The struct composes fields representing the `Counter` type and value(s) (injected counter
736     /// ID, or expression type and operands), the source file (an indirect index into a "filenames
737     /// array", encoded separately), and source location (start and end positions of the represented
738     /// code region).
739     ///
740     /// Matches LLVMRustCounterMappingRegion.
741     #[derive(Copy, Clone, Debug)]
742     #[repr(C)]
743     pub struct CounterMappingRegion {
744         /// The counter type and type-dependent counter data, if any.
745         counter: coverage_map::Counter,
746
747         /// If the `RegionKind` is a `BranchRegion`, this represents the counter
748         /// for the false branch of the region.
749         false_counter: coverage_map::Counter,
750
751         /// An indirect reference to the source filename. In the LLVM Coverage Mapping Format, the
752         /// file_id is an index into a function-specific `virtual_file_mapping` array of indexes
753         /// that, in turn, are used to look up the filename for this region.
754         file_id: u32,
755
756         /// If the `RegionKind` is an `ExpansionRegion`, the `expanded_file_id` can be used to find
757         /// the mapping regions created as a result of macro expansion, by checking if their file id
758         /// matches the expanded file id.
759         expanded_file_id: u32,
760
761         /// 1-based starting line of the mapping region.
762         start_line: u32,
763
764         /// 1-based starting column of the mapping region.
765         start_col: u32,
766
767         /// 1-based ending line of the mapping region.
768         end_line: u32,
769
770         /// 1-based ending column of the mapping region. If the high bit is set, the current
771         /// mapping region is a gap area.
772         end_col: u32,
773
774         kind: RegionKind,
775     }
776
777     impl CounterMappingRegion {
778         crate fn code_region(
779             counter: coverage_map::Counter,
780             file_id: u32,
781             start_line: u32,
782             start_col: u32,
783             end_line: u32,
784             end_col: u32,
785         ) -> Self {
786             Self {
787                 counter,
788                 false_counter: coverage_map::Counter::zero(),
789                 file_id,
790                 expanded_file_id: 0,
791                 start_line,
792                 start_col,
793                 end_line,
794                 end_col,
795                 kind: RegionKind::CodeRegion,
796             }
797         }
798
799         // This function might be used in the future; the LLVM API is still evolving, as is coverage
800         // support.
801         #[allow(dead_code)]
802         crate fn branch_region(
803             counter: coverage_map::Counter,
804             false_counter: coverage_map::Counter,
805             file_id: u32,
806             start_line: u32,
807             start_col: u32,
808             end_line: u32,
809             end_col: u32,
810         ) -> Self {
811             Self {
812                 counter,
813                 false_counter,
814                 file_id,
815                 expanded_file_id: 0,
816                 start_line,
817                 start_col,
818                 end_line,
819                 end_col,
820                 kind: RegionKind::BranchRegion,
821             }
822         }
823
824         // This function might be used in the future; the LLVM API is still evolving, as is coverage
825         // support.
826         #[allow(dead_code)]
827         crate fn expansion_region(
828             file_id: u32,
829             expanded_file_id: u32,
830             start_line: u32,
831             start_col: u32,
832             end_line: u32,
833             end_col: u32,
834         ) -> Self {
835             Self {
836                 counter: coverage_map::Counter::zero(),
837                 false_counter: coverage_map::Counter::zero(),
838                 file_id,
839                 expanded_file_id,
840                 start_line,
841                 start_col,
842                 end_line,
843                 end_col,
844                 kind: RegionKind::ExpansionRegion,
845             }
846         }
847
848         // This function might be used in the future; the LLVM API is still evolving, as is coverage
849         // support.
850         #[allow(dead_code)]
851         crate fn skipped_region(
852             file_id: u32,
853             start_line: u32,
854             start_col: u32,
855             end_line: u32,
856             end_col: u32,
857         ) -> Self {
858             Self {
859                 counter: coverage_map::Counter::zero(),
860                 false_counter: coverage_map::Counter::zero(),
861                 file_id,
862                 expanded_file_id: 0,
863                 start_line,
864                 start_col,
865                 end_line,
866                 end_col,
867                 kind: RegionKind::SkippedRegion,
868             }
869         }
870
871         // This function might be used in the future; the LLVM API is still evolving, as is coverage
872         // support.
873         #[allow(dead_code)]
874         crate fn gap_region(
875             counter: coverage_map::Counter,
876             file_id: u32,
877             start_line: u32,
878             start_col: u32,
879             end_line: u32,
880             end_col: u32,
881         ) -> Self {
882             Self {
883                 counter,
884                 false_counter: coverage_map::Counter::zero(),
885                 file_id,
886                 expanded_file_id: 0,
887                 start_line,
888                 start_col,
889                 end_line,
890                 end_col: (1_u32 << 31) | end_col,
891                 kind: RegionKind::GapRegion,
892             }
893         }
894     }
895 }
896
897 pub mod debuginfo {
898     use super::{InvariantOpaque, Metadata};
899     use bitflags::bitflags;
900
901     #[repr(C)]
902     pub struct DIBuilder<'a>(InvariantOpaque<'a>);
903
904     pub type DIDescriptor = Metadata;
905     pub type DILocation = Metadata;
906     pub type DIScope = DIDescriptor;
907     pub type DIFile = DIScope;
908     pub type DILexicalBlock = DIScope;
909     pub type DISubprogram = DIScope;
910     pub type DINameSpace = DIScope;
911     pub type DIType = DIDescriptor;
912     pub type DIBasicType = DIType;
913     pub type DIDerivedType = DIType;
914     pub type DICompositeType = DIDerivedType;
915     pub type DIVariable = DIDescriptor;
916     pub type DIGlobalVariableExpression = DIDescriptor;
917     pub type DIArray = DIDescriptor;
918     pub type DISubrange = DIDescriptor;
919     pub type DIEnumerator = DIDescriptor;
920     pub type DITemplateTypeParameter = DIDescriptor;
921
922     // These values **must** match with LLVMRustDIFlags!!
923     bitflags! {
924         #[repr(transparent)]
925         #[derive(Default)]
926         pub struct DIFlags: u32 {
927             const FlagZero                = 0;
928             const FlagPrivate             = 1;
929             const FlagProtected           = 2;
930             const FlagPublic              = 3;
931             const FlagFwdDecl             = (1 << 2);
932             const FlagAppleBlock          = (1 << 3);
933             const FlagBlockByrefStruct    = (1 << 4);
934             const FlagVirtual             = (1 << 5);
935             const FlagArtificial          = (1 << 6);
936             const FlagExplicit            = (1 << 7);
937             const FlagPrototyped          = (1 << 8);
938             const FlagObjcClassComplete   = (1 << 9);
939             const FlagObjectPointer       = (1 << 10);
940             const FlagVector              = (1 << 11);
941             const FlagStaticMember        = (1 << 12);
942             const FlagLValueReference     = (1 << 13);
943             const FlagRValueReference     = (1 << 14);
944             const FlagExternalTypeRef     = (1 << 15);
945             const FlagIntroducedVirtual   = (1 << 18);
946             const FlagBitField            = (1 << 19);
947             const FlagNoReturn            = (1 << 20);
948         }
949     }
950
951     // These values **must** match with LLVMRustDISPFlags!!
952     bitflags! {
953         #[repr(transparent)]
954         #[derive(Default)]
955         pub struct DISPFlags: u32 {
956             const SPFlagZero              = 0;
957             const SPFlagVirtual           = 1;
958             const SPFlagPureVirtual       = 2;
959             const SPFlagLocalToUnit       = (1 << 2);
960             const SPFlagDefinition        = (1 << 3);
961             const SPFlagOptimized         = (1 << 4);
962             const SPFlagMainSubprogram    = (1 << 5);
963         }
964     }
965
966     /// LLVMRustDebugEmissionKind
967     #[derive(Copy, Clone)]
968     #[repr(C)]
969     pub enum DebugEmissionKind {
970         NoDebug,
971         FullDebug,
972         LineTablesOnly,
973     }
974
975     impl DebugEmissionKind {
976         pub fn from_generic(kind: rustc_session::config::DebugInfo) -> Self {
977             use rustc_session::config::DebugInfo;
978             match kind {
979                 DebugInfo::None => DebugEmissionKind::NoDebug,
980                 DebugInfo::Limited => DebugEmissionKind::LineTablesOnly,
981                 DebugInfo::Full => DebugEmissionKind::FullDebug,
982             }
983         }
984     }
985 }
986
987 extern "C" {
988     pub type ModuleBuffer;
989 }
990
991 pub type SelfProfileBeforePassCallback =
992     unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);
993 pub type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void);
994
995 extern "C" {
996     pub fn LLVMRustInstallFatalErrorHandler();
997     pub fn LLVMRustDisableSystemDialogsOnCrash();
998
999     // Create and destroy contexts.
1000     pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
1001     pub fn LLVMContextDispose(C: &'static mut Context);
1002     pub fn LLVMGetMDKindIDInContext(C: &Context, Name: *const c_char, SLen: c_uint) -> c_uint;
1003
1004     // Create modules.
1005     pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char, C: &Context) -> &Module;
1006     pub fn LLVMGetModuleContext(M: &Module) -> &Context;
1007     pub fn LLVMCloneModule(M: &Module) -> &Module;
1008
1009     /// Data layout. See Module::getDataLayout.
1010     pub fn LLVMGetDataLayoutStr(M: &Module) -> *const c_char;
1011     pub fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);
1012
1013     /// See Module::setModuleInlineAsm.
1014     pub fn LLVMSetModuleInlineAsm2(M: &Module, Asm: *const c_char, AsmLen: size_t);
1015     pub fn LLVMRustAppendModuleInlineAsm(M: &Module, Asm: *const c_char, AsmLen: size_t);
1016
1017     /// See llvm::LLVMTypeKind::getTypeID.
1018     pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
1019
1020     // Operations on integer types
1021     pub fn LLVMInt1TypeInContext(C: &Context) -> &Type;
1022     pub fn LLVMInt8TypeInContext(C: &Context) -> &Type;
1023     pub fn LLVMInt16TypeInContext(C: &Context) -> &Type;
1024     pub fn LLVMInt32TypeInContext(C: &Context) -> &Type;
1025     pub fn LLVMInt64TypeInContext(C: &Context) -> &Type;
1026     pub fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type;
1027
1028     pub fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint;
1029
1030     // Operations on real types
1031     pub fn LLVMFloatTypeInContext(C: &Context) -> &Type;
1032     pub fn LLVMDoubleTypeInContext(C: &Context) -> &Type;
1033
1034     // Operations on function types
1035     pub fn LLVMFunctionType<'a>(
1036         ReturnType: &'a Type,
1037         ParamTypes: *const &'a Type,
1038         ParamCount: c_uint,
1039         IsVarArg: Bool,
1040     ) -> &'a Type;
1041     pub fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint;
1042     pub fn LLVMGetParamTypes<'a>(FunctionTy: &'a Type, Dest: *mut &'a Type);
1043
1044     // Operations on struct types
1045     pub fn LLVMStructTypeInContext<'a>(
1046         C: &'a Context,
1047         ElementTypes: *const &'a Type,
1048         ElementCount: c_uint,
1049         Packed: Bool,
1050     ) -> &'a Type;
1051
1052     // Operations on array, pointer, and vector types (sequence types)
1053     pub fn LLVMRustArrayType(ElementType: &Type, ElementCount: u64) -> &Type;
1054     pub fn LLVMPointerType(ElementType: &Type, AddressSpace: c_uint) -> &Type;
1055     pub fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;
1056
1057     pub fn LLVMGetElementType(Ty: &Type) -> &Type;
1058     pub fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint;
1059
1060     // Operations on other types
1061     pub fn LLVMVoidTypeInContext(C: &Context) -> &Type;
1062     pub fn LLVMRustMetadataTypeInContext(C: &Context) -> &Type;
1063
1064     // Operations on all values
1065     pub fn LLVMTypeOf(Val: &Value) -> &Type;
1066     pub fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char;
1067     pub fn LLVMSetValueName2(Val: &Value, Name: *const c_char, NameLen: size_t);
1068     pub fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value);
1069     pub fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Node: &'a Value);
1070     pub fn LLVMGlobalSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
1071     pub fn LLVMValueAsMetadata(Node: &Value) -> &Metadata;
1072
1073     // Operations on constants of any type
1074     pub fn LLVMConstNull(Ty: &Type) -> &Value;
1075     pub fn LLVMGetUndef(Ty: &Type) -> &Value;
1076
1077     // Operations on metadata
1078     pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
1079     pub fn LLVMMDNodeInContext<'a>(
1080         C: &'a Context,
1081         Vals: *const &'a Value,
1082         Count: c_uint,
1083     ) -> &'a Value;
1084     pub fn LLVMAddNamedMetadataOperand<'a>(M: &'a Module, Name: *const c_char, Val: &'a Value);
1085
1086     // Operations on scalar constants
1087     pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
1088     pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
1089     pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
1090     pub fn LLVMConstIntGetZExtValue(ConstantVal: &ConstantInt) -> c_ulonglong;
1091     pub fn LLVMRustConstInt128Get(
1092         ConstantVal: &ConstantInt,
1093         SExt: bool,
1094         high: &mut u64,
1095         low: &mut u64,
1096     ) -> bool;
1097
1098     // Operations on composite constants
1099     pub fn LLVMConstStringInContext(
1100         C: &Context,
1101         Str: *const c_char,
1102         Length: c_uint,
1103         DontNullTerminate: Bool,
1104     ) -> &Value;
1105     pub fn LLVMConstStructInContext<'a>(
1106         C: &'a Context,
1107         ConstantVals: *const &'a Value,
1108         Count: c_uint,
1109         Packed: Bool,
1110     ) -> &'a Value;
1111
1112     pub fn LLVMConstArray<'a>(
1113         ElementTy: &'a Type,
1114         ConstantVals: *const &'a Value,
1115         Length: c_uint,
1116     ) -> &'a Value;
1117     pub fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
1118
1119     // Constant expressions
1120     pub fn LLVMRustConstInBoundsGEP2<'a>(
1121         ty: &'a Type,
1122         ConstantVal: &'a Value,
1123         ConstantIndices: *const &'a Value,
1124         NumIndices: c_uint,
1125     ) -> &'a Value;
1126     pub fn LLVMConstZExt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1127     pub fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1128     pub fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1129     pub fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1130     pub fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1131     pub fn LLVMConstExtractValue(
1132         AggConstant: &Value,
1133         IdxList: *const c_uint,
1134         NumIdx: c_uint,
1135     ) -> &Value;
1136
1137     // Operations on global variables, functions, and aliases (globals)
1138     pub fn LLVMIsDeclaration(Global: &Value) -> Bool;
1139     pub fn LLVMRustGetLinkage(Global: &Value) -> Linkage;
1140     pub fn LLVMRustSetLinkage(Global: &Value, RustLinkage: Linkage);
1141     pub fn LLVMSetSection(Global: &Value, Section: *const c_char);
1142     pub fn LLVMRustGetVisibility(Global: &Value) -> Visibility;
1143     pub fn LLVMRustSetVisibility(Global: &Value, Viz: Visibility);
1144     pub fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);
1145     pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
1146     pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
1147     pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
1148
1149     // Operations on global variables
1150     pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
1151     pub fn LLVMAddGlobal<'a>(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1152     pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
1153     pub fn LLVMRustGetOrInsertGlobal<'a>(
1154         M: &'a Module,
1155         Name: *const c_char,
1156         NameLen: size_t,
1157         T: &'a Type,
1158     ) -> &'a Value;
1159     pub fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
1160     pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
1161     pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
1162     pub fn LLVMDeleteGlobal(GlobalVar: &Value);
1163     pub fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;
1164     pub fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value);
1165     pub fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool;
1166     pub fn LLVMSetThreadLocal(GlobalVar: &Value, IsThreadLocal: Bool);
1167     pub fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
1168     pub fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
1169     pub fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
1170     pub fn LLVMRustGetNamedValue(
1171         M: &Module,
1172         Name: *const c_char,
1173         NameLen: size_t,
1174     ) -> Option<&Value>;
1175     pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
1176
1177     // Operations on attributes
1178     pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;
1179     pub fn LLVMRustCreateAttrString(C: &Context, Name: *const c_char) -> &Attribute;
1180     pub fn LLVMRustCreateAttrStringValue(
1181         C: &Context,
1182         Name: *const c_char,
1183         Value: *const c_char,
1184     ) -> &Attribute;
1185     pub fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute;
1186     pub fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute;
1187     pub fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute;
1188     pub fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1189     pub fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1190     pub fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute;
1191
1192     // Operations on functions
1193     pub fn LLVMRustGetOrInsertFunction<'a>(
1194         M: &'a Module,
1195         Name: *const c_char,
1196         NameLen: size_t,
1197         FunctionTy: &'a Type,
1198     ) -> &'a Value;
1199     pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
1200     pub fn LLVMRustAddFunctionAttributes<'a>(
1201         Fn: &'a Value,
1202         index: c_uint,
1203         Attrs: *const &'a Attribute,
1204         AttrsLen: size_t,
1205     );
1206     pub fn LLVMRustRemoveFunctionAttributes(
1207         Fn: &Value,
1208         index: c_uint,
1209         Attrs: *const AttributeKind,
1210         AttrsLen: size_t,
1211     );
1212
1213     // Operations on parameters
1214     pub fn LLVMIsAArgument(Val: &Value) -> Option<&Value>;
1215     pub fn LLVMCountParams(Fn: &Value) -> c_uint;
1216     pub fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
1217
1218     // Operations on basic blocks
1219     pub fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
1220     pub fn LLVMAppendBasicBlockInContext<'a>(
1221         C: &'a Context,
1222         Fn: &'a Value,
1223         Name: *const c_char,
1224     ) -> &'a BasicBlock;
1225
1226     // Operations on instructions
1227     pub fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>;
1228     pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
1229
1230     // Operations on call sites
1231     pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
1232     pub fn LLVMRustAddCallSiteAttributes<'a>(
1233         Instr: &'a Value,
1234         index: c_uint,
1235         Attrs: *const &'a Attribute,
1236         AttrsLen: size_t,
1237     );
1238
1239     // Operations on load/store instructions (only)
1240     pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
1241
1242     // Operations on phi nodes
1243     pub fn LLVMAddIncoming<'a>(
1244         PhiNode: &'a Value,
1245         IncomingValues: *const &'a Value,
1246         IncomingBlocks: *const &'a BasicBlock,
1247         Count: c_uint,
1248     );
1249
1250     // Instruction builders
1251     pub fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;
1252     pub fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock);
1253     pub fn LLVMGetInsertBlock<'a>(Builder: &Builder<'a>) -> &'a BasicBlock;
1254     pub fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
1255
1256     // Metadata
1257     pub fn LLVMSetCurrentDebugLocation<'a>(Builder: &Builder<'a>, L: &'a Value);
1258
1259     // Terminators
1260     pub fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;
1261     pub fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value;
1262     pub fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;
1263     pub fn LLVMBuildCondBr<'a>(
1264         B: &Builder<'a>,
1265         If: &'a Value,
1266         Then: &'a BasicBlock,
1267         Else: &'a BasicBlock,
1268     ) -> &'a Value;
1269     pub fn LLVMBuildSwitch<'a>(
1270         B: &Builder<'a>,
1271         V: &'a Value,
1272         Else: &'a BasicBlock,
1273         NumCases: c_uint,
1274     ) -> &'a Value;
1275     pub fn LLVMRustBuildInvoke<'a>(
1276         B: &Builder<'a>,
1277         Ty: &'a Type,
1278         Fn: &'a Value,
1279         Args: *const &'a Value,
1280         NumArgs: c_uint,
1281         Then: &'a BasicBlock,
1282         Catch: &'a BasicBlock,
1283         Bundle: Option<&OperandBundleDef<'a>>,
1284         Name: *const c_char,
1285     ) -> &'a Value;
1286     pub fn LLVMBuildLandingPad<'a>(
1287         B: &Builder<'a>,
1288         Ty: &'a Type,
1289         PersFn: Option<&'a Value>,
1290         NumClauses: c_uint,
1291         Name: *const c_char,
1292     ) -> &'a Value;
1293     pub fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
1294     pub fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value;
1295
1296     pub fn LLVMRustBuildCleanupPad<'a>(
1297         B: &Builder<'a>,
1298         ParentPad: Option<&'a Value>,
1299         ArgCnt: c_uint,
1300         Args: *const &'a Value,
1301         Name: *const c_char,
1302     ) -> Option<&'a Value>;
1303     pub fn LLVMRustBuildCleanupRet<'a>(
1304         B: &Builder<'a>,
1305         CleanupPad: &'a Value,
1306         UnwindBB: Option<&'a BasicBlock>,
1307     ) -> Option<&'a Value>;
1308     pub fn LLVMRustBuildCatchPad<'a>(
1309         B: &Builder<'a>,
1310         ParentPad: &'a Value,
1311         ArgCnt: c_uint,
1312         Args: *const &'a Value,
1313         Name: *const c_char,
1314     ) -> Option<&'a Value>;
1315     pub fn LLVMRustBuildCatchRet<'a>(
1316         B: &Builder<'a>,
1317         Pad: &'a Value,
1318         BB: &'a BasicBlock,
1319     ) -> Option<&'a Value>;
1320     pub fn LLVMRustBuildCatchSwitch<'a>(
1321         Builder: &Builder<'a>,
1322         ParentPad: Option<&'a Value>,
1323         BB: Option<&'a BasicBlock>,
1324         NumHandlers: c_uint,
1325         Name: *const c_char,
1326     ) -> Option<&'a Value>;
1327     pub fn LLVMRustAddHandler<'a>(CatchSwitch: &'a Value, Handler: &'a BasicBlock);
1328     pub fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value);
1329
1330     // Add a case to the switch instruction
1331     pub fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
1332
1333     // Add a clause to the landing pad instruction
1334     pub fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value);
1335
1336     // Set the cleanup on a landing pad instruction
1337     pub fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);
1338
1339     // Arithmetic
1340     pub fn LLVMBuildAdd<'a>(
1341         B: &Builder<'a>,
1342         LHS: &'a Value,
1343         RHS: &'a Value,
1344         Name: *const c_char,
1345     ) -> &'a Value;
1346     pub fn LLVMBuildFAdd<'a>(
1347         B: &Builder<'a>,
1348         LHS: &'a Value,
1349         RHS: &'a Value,
1350         Name: *const c_char,
1351     ) -> &'a Value;
1352     pub fn LLVMBuildSub<'a>(
1353         B: &Builder<'a>,
1354         LHS: &'a Value,
1355         RHS: &'a Value,
1356         Name: *const c_char,
1357     ) -> &'a Value;
1358     pub fn LLVMBuildFSub<'a>(
1359         B: &Builder<'a>,
1360         LHS: &'a Value,
1361         RHS: &'a Value,
1362         Name: *const c_char,
1363     ) -> &'a Value;
1364     pub fn LLVMBuildMul<'a>(
1365         B: &Builder<'a>,
1366         LHS: &'a Value,
1367         RHS: &'a Value,
1368         Name: *const c_char,
1369     ) -> &'a Value;
1370     pub fn LLVMBuildFMul<'a>(
1371         B: &Builder<'a>,
1372         LHS: &'a Value,
1373         RHS: &'a Value,
1374         Name: *const c_char,
1375     ) -> &'a Value;
1376     pub fn LLVMBuildUDiv<'a>(
1377         B: &Builder<'a>,
1378         LHS: &'a Value,
1379         RHS: &'a Value,
1380         Name: *const c_char,
1381     ) -> &'a Value;
1382     pub fn LLVMBuildExactUDiv<'a>(
1383         B: &Builder<'a>,
1384         LHS: &'a Value,
1385         RHS: &'a Value,
1386         Name: *const c_char,
1387     ) -> &'a Value;
1388     pub fn LLVMBuildSDiv<'a>(
1389         B: &Builder<'a>,
1390         LHS: &'a Value,
1391         RHS: &'a Value,
1392         Name: *const c_char,
1393     ) -> &'a Value;
1394     pub fn LLVMBuildExactSDiv<'a>(
1395         B: &Builder<'a>,
1396         LHS: &'a Value,
1397         RHS: &'a Value,
1398         Name: *const c_char,
1399     ) -> &'a Value;
1400     pub fn LLVMBuildFDiv<'a>(
1401         B: &Builder<'a>,
1402         LHS: &'a Value,
1403         RHS: &'a Value,
1404         Name: *const c_char,
1405     ) -> &'a Value;
1406     pub fn LLVMBuildURem<'a>(
1407         B: &Builder<'a>,
1408         LHS: &'a Value,
1409         RHS: &'a Value,
1410         Name: *const c_char,
1411     ) -> &'a Value;
1412     pub fn LLVMBuildSRem<'a>(
1413         B: &Builder<'a>,
1414         LHS: &'a Value,
1415         RHS: &'a Value,
1416         Name: *const c_char,
1417     ) -> &'a Value;
1418     pub fn LLVMBuildFRem<'a>(
1419         B: &Builder<'a>,
1420         LHS: &'a Value,
1421         RHS: &'a Value,
1422         Name: *const c_char,
1423     ) -> &'a Value;
1424     pub fn LLVMBuildShl<'a>(
1425         B: &Builder<'a>,
1426         LHS: &'a Value,
1427         RHS: &'a Value,
1428         Name: *const c_char,
1429     ) -> &'a Value;
1430     pub fn LLVMBuildLShr<'a>(
1431         B: &Builder<'a>,
1432         LHS: &'a Value,
1433         RHS: &'a Value,
1434         Name: *const c_char,
1435     ) -> &'a Value;
1436     pub fn LLVMBuildAShr<'a>(
1437         B: &Builder<'a>,
1438         LHS: &'a Value,
1439         RHS: &'a Value,
1440         Name: *const c_char,
1441     ) -> &'a Value;
1442     pub fn LLVMBuildNSWAdd<'a>(
1443         B: &Builder<'a>,
1444         LHS: &'a Value,
1445         RHS: &'a Value,
1446         Name: *const c_char,
1447     ) -> &'a Value;
1448     pub fn LLVMBuildNUWAdd<'a>(
1449         B: &Builder<'a>,
1450         LHS: &'a Value,
1451         RHS: &'a Value,
1452         Name: *const c_char,
1453     ) -> &'a Value;
1454     pub fn LLVMBuildNSWSub<'a>(
1455         B: &Builder<'a>,
1456         LHS: &'a Value,
1457         RHS: &'a Value,
1458         Name: *const c_char,
1459     ) -> &'a Value;
1460     pub fn LLVMBuildNUWSub<'a>(
1461         B: &Builder<'a>,
1462         LHS: &'a Value,
1463         RHS: &'a Value,
1464         Name: *const c_char,
1465     ) -> &'a Value;
1466     pub fn LLVMBuildNSWMul<'a>(
1467         B: &Builder<'a>,
1468         LHS: &'a Value,
1469         RHS: &'a Value,
1470         Name: *const c_char,
1471     ) -> &'a Value;
1472     pub fn LLVMBuildNUWMul<'a>(
1473         B: &Builder<'a>,
1474         LHS: &'a Value,
1475         RHS: &'a Value,
1476         Name: *const c_char,
1477     ) -> &'a Value;
1478     pub fn LLVMBuildAnd<'a>(
1479         B: &Builder<'a>,
1480         LHS: &'a Value,
1481         RHS: &'a Value,
1482         Name: *const c_char,
1483     ) -> &'a Value;
1484     pub fn LLVMBuildOr<'a>(
1485         B: &Builder<'a>,
1486         LHS: &'a Value,
1487         RHS: &'a Value,
1488         Name: *const c_char,
1489     ) -> &'a Value;
1490     pub fn LLVMBuildXor<'a>(
1491         B: &Builder<'a>,
1492         LHS: &'a Value,
1493         RHS: &'a Value,
1494         Name: *const c_char,
1495     ) -> &'a Value;
1496     pub fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1497     pub fn LLVMBuildFNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1498     pub fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1499     pub fn LLVMRustSetFastMath(Instr: &Value);
1500
1501     // Memory
1502     pub fn LLVMBuildAlloca<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1503     pub fn LLVMBuildArrayAlloca<'a>(
1504         B: &Builder<'a>,
1505         Ty: &'a Type,
1506         Val: &'a Value,
1507         Name: *const c_char,
1508     ) -> &'a Value;
1509     pub fn LLVMBuildLoad2<'a>(
1510         B: &Builder<'a>,
1511         Ty: &'a Type,
1512         PointerVal: &'a Value,
1513         Name: *const c_char,
1514     ) -> &'a Value;
1515
1516     pub fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
1517
1518     pub fn LLVMBuildGEP2<'a>(
1519         B: &Builder<'a>,
1520         Ty: &'a Type,
1521         Pointer: &'a Value,
1522         Indices: *const &'a Value,
1523         NumIndices: c_uint,
1524         Name: *const c_char,
1525     ) -> &'a Value;
1526     pub fn LLVMBuildInBoundsGEP2<'a>(
1527         B: &Builder<'a>,
1528         Ty: &'a Type,
1529         Pointer: &'a Value,
1530         Indices: *const &'a Value,
1531         NumIndices: c_uint,
1532         Name: *const c_char,
1533     ) -> &'a Value;
1534     pub fn LLVMBuildStructGEP2<'a>(
1535         B: &Builder<'a>,
1536         Ty: &'a Type,
1537         Pointer: &'a Value,
1538         Idx: c_uint,
1539         Name: *const c_char,
1540     ) -> &'a Value;
1541
1542     // Casts
1543     pub fn LLVMBuildTrunc<'a>(
1544         B: &Builder<'a>,
1545         Val: &'a Value,
1546         DestTy: &'a Type,
1547         Name: *const c_char,
1548     ) -> &'a Value;
1549     pub fn LLVMBuildZExt<'a>(
1550         B: &Builder<'a>,
1551         Val: &'a Value,
1552         DestTy: &'a Type,
1553         Name: *const c_char,
1554     ) -> &'a Value;
1555     pub fn LLVMBuildSExt<'a>(
1556         B: &Builder<'a>,
1557         Val: &'a Value,
1558         DestTy: &'a Type,
1559         Name: *const c_char,
1560     ) -> &'a Value;
1561     pub fn LLVMBuildFPToUI<'a>(
1562         B: &Builder<'a>,
1563         Val: &'a Value,
1564         DestTy: &'a Type,
1565         Name: *const c_char,
1566     ) -> &'a Value;
1567     pub fn LLVMBuildFPToSI<'a>(
1568         B: &Builder<'a>,
1569         Val: &'a Value,
1570         DestTy: &'a Type,
1571         Name: *const c_char,
1572     ) -> &'a Value;
1573     pub fn LLVMBuildUIToFP<'a>(
1574         B: &Builder<'a>,
1575         Val: &'a Value,
1576         DestTy: &'a Type,
1577         Name: *const c_char,
1578     ) -> &'a Value;
1579     pub fn LLVMBuildSIToFP<'a>(
1580         B: &Builder<'a>,
1581         Val: &'a Value,
1582         DestTy: &'a Type,
1583         Name: *const c_char,
1584     ) -> &'a Value;
1585     pub fn LLVMBuildFPTrunc<'a>(
1586         B: &Builder<'a>,
1587         Val: &'a Value,
1588         DestTy: &'a Type,
1589         Name: *const c_char,
1590     ) -> &'a Value;
1591     pub fn LLVMBuildFPExt<'a>(
1592         B: &Builder<'a>,
1593         Val: &'a Value,
1594         DestTy: &'a Type,
1595         Name: *const c_char,
1596     ) -> &'a Value;
1597     pub fn LLVMBuildPtrToInt<'a>(
1598         B: &Builder<'a>,
1599         Val: &'a Value,
1600         DestTy: &'a Type,
1601         Name: *const c_char,
1602     ) -> &'a Value;
1603     pub fn LLVMBuildIntToPtr<'a>(
1604         B: &Builder<'a>,
1605         Val: &'a Value,
1606         DestTy: &'a Type,
1607         Name: *const c_char,
1608     ) -> &'a Value;
1609     pub fn LLVMBuildBitCast<'a>(
1610         B: &Builder<'a>,
1611         Val: &'a Value,
1612         DestTy: &'a Type,
1613         Name: *const c_char,
1614     ) -> &'a Value;
1615     pub fn LLVMBuildPointerCast<'a>(
1616         B: &Builder<'a>,
1617         Val: &'a Value,
1618         DestTy: &'a Type,
1619         Name: *const c_char,
1620     ) -> &'a Value;
1621     pub fn LLVMRustBuildIntCast<'a>(
1622         B: &Builder<'a>,
1623         Val: &'a Value,
1624         DestTy: &'a Type,
1625         IsSized: bool,
1626     ) -> &'a Value;
1627
1628     // Comparisons
1629     pub fn LLVMBuildICmp<'a>(
1630         B: &Builder<'a>,
1631         Op: c_uint,
1632         LHS: &'a Value,
1633         RHS: &'a Value,
1634         Name: *const c_char,
1635     ) -> &'a Value;
1636     pub fn LLVMBuildFCmp<'a>(
1637         B: &Builder<'a>,
1638         Op: c_uint,
1639         LHS: &'a Value,
1640         RHS: &'a Value,
1641         Name: *const c_char,
1642     ) -> &'a Value;
1643
1644     // Miscellaneous instructions
1645     pub fn LLVMBuildPhi<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1646     pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &Value;
1647     pub fn LLVMRustBuildCall<'a>(
1648         B: &Builder<'a>,
1649         Ty: &'a Type,
1650         Fn: &'a Value,
1651         Args: *const &'a Value,
1652         NumArgs: c_uint,
1653         Bundle: Option<&OperandBundleDef<'a>>,
1654     ) -> &'a Value;
1655     pub fn LLVMRustBuildMemCpy<'a>(
1656         B: &Builder<'a>,
1657         Dst: &'a Value,
1658         DstAlign: c_uint,
1659         Src: &'a Value,
1660         SrcAlign: c_uint,
1661         Size: &'a Value,
1662         IsVolatile: bool,
1663     ) -> &'a Value;
1664     pub fn LLVMRustBuildMemMove<'a>(
1665         B: &Builder<'a>,
1666         Dst: &'a Value,
1667         DstAlign: c_uint,
1668         Src: &'a Value,
1669         SrcAlign: c_uint,
1670         Size: &'a Value,
1671         IsVolatile: bool,
1672     ) -> &'a Value;
1673     pub fn LLVMRustBuildMemSet<'a>(
1674         B: &Builder<'a>,
1675         Dst: &'a Value,
1676         DstAlign: c_uint,
1677         Val: &'a Value,
1678         Size: &'a Value,
1679         IsVolatile: bool,
1680     ) -> &'a Value;
1681     pub fn LLVMBuildSelect<'a>(
1682         B: &Builder<'a>,
1683         If: &'a Value,
1684         Then: &'a Value,
1685         Else: &'a Value,
1686         Name: *const c_char,
1687     ) -> &'a Value;
1688     pub fn LLVMBuildVAArg<'a>(
1689         B: &Builder<'a>,
1690         list: &'a Value,
1691         Ty: &'a Type,
1692         Name: *const c_char,
1693     ) -> &'a Value;
1694     pub fn LLVMBuildExtractElement<'a>(
1695         B: &Builder<'a>,
1696         VecVal: &'a Value,
1697         Index: &'a Value,
1698         Name: *const c_char,
1699     ) -> &'a Value;
1700     pub fn LLVMBuildInsertElement<'a>(
1701         B: &Builder<'a>,
1702         VecVal: &'a Value,
1703         EltVal: &'a Value,
1704         Index: &'a Value,
1705         Name: *const c_char,
1706     ) -> &'a Value;
1707     pub fn LLVMBuildShuffleVector<'a>(
1708         B: &Builder<'a>,
1709         V1: &'a Value,
1710         V2: &'a Value,
1711         Mask: &'a Value,
1712         Name: *const c_char,
1713     ) -> &'a Value;
1714     pub fn LLVMBuildExtractValue<'a>(
1715         B: &Builder<'a>,
1716         AggVal: &'a Value,
1717         Index: c_uint,
1718         Name: *const c_char,
1719     ) -> &'a Value;
1720     pub fn LLVMBuildInsertValue<'a>(
1721         B: &Builder<'a>,
1722         AggVal: &'a Value,
1723         EltVal: &'a Value,
1724         Index: c_uint,
1725         Name: *const c_char,
1726     ) -> &'a Value;
1727
1728     pub fn LLVMRustBuildVectorReduceFAdd<'a>(
1729         B: &Builder<'a>,
1730         Acc: &'a Value,
1731         Src: &'a Value,
1732     ) -> &'a Value;
1733     pub fn LLVMRustBuildVectorReduceFMul<'a>(
1734         B: &Builder<'a>,
1735         Acc: &'a Value,
1736         Src: &'a Value,
1737     ) -> &'a Value;
1738     pub fn LLVMRustBuildVectorReduceAdd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1739     pub fn LLVMRustBuildVectorReduceMul<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1740     pub fn LLVMRustBuildVectorReduceAnd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1741     pub fn LLVMRustBuildVectorReduceOr<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1742     pub fn LLVMRustBuildVectorReduceXor<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1743     pub fn LLVMRustBuildVectorReduceMin<'a>(
1744         B: &Builder<'a>,
1745         Src: &'a Value,
1746         IsSigned: bool,
1747     ) -> &'a Value;
1748     pub fn LLVMRustBuildVectorReduceMax<'a>(
1749         B: &Builder<'a>,
1750         Src: &'a Value,
1751         IsSigned: bool,
1752     ) -> &'a Value;
1753     pub fn LLVMRustBuildVectorReduceFMin<'a>(
1754         B: &Builder<'a>,
1755         Src: &'a Value,
1756         IsNaN: bool,
1757     ) -> &'a Value;
1758     pub fn LLVMRustBuildVectorReduceFMax<'a>(
1759         B: &Builder<'a>,
1760         Src: &'a Value,
1761         IsNaN: bool,
1762     ) -> &'a Value;
1763
1764     pub fn LLVMRustBuildMinNum<'a>(B: &Builder<'a>, LHS: &'a Value, LHS: &'a Value) -> &'a Value;
1765     pub fn LLVMRustBuildMaxNum<'a>(B: &Builder<'a>, LHS: &'a Value, LHS: &'a Value) -> &'a Value;
1766
1767     // Atomic Operations
1768     pub fn LLVMRustBuildAtomicLoad<'a>(
1769         B: &Builder<'a>,
1770         ElementType: &'a Type,
1771         PointerVal: &'a Value,
1772         Name: *const c_char,
1773         Order: AtomicOrdering,
1774     ) -> &'a Value;
1775
1776     pub fn LLVMRustBuildAtomicStore<'a>(
1777         B: &Builder<'a>,
1778         Val: &'a Value,
1779         Ptr: &'a Value,
1780         Order: AtomicOrdering,
1781     ) -> &'a Value;
1782
1783     pub fn LLVMRustBuildAtomicCmpXchg<'a>(
1784         B: &Builder<'a>,
1785         LHS: &'a Value,
1786         CMP: &'a Value,
1787         RHS: &'a Value,
1788         Order: AtomicOrdering,
1789         FailureOrder: AtomicOrdering,
1790         Weak: Bool,
1791     ) -> &'a Value;
1792
1793     pub fn LLVMBuildAtomicRMW<'a>(
1794         B: &Builder<'a>,
1795         Op: AtomicRmwBinOp,
1796         LHS: &'a Value,
1797         RHS: &'a Value,
1798         Order: AtomicOrdering,
1799         SingleThreaded: Bool,
1800     ) -> &'a Value;
1801
1802     pub fn LLVMRustBuildAtomicFence(
1803         B: &Builder<'_>,
1804         Order: AtomicOrdering,
1805         Scope: SynchronizationScope,
1806     );
1807
1808     /// Writes a module to the specified path. Returns 0 on success.
1809     pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
1810
1811     /// Creates a pass manager.
1812     pub fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>;
1813
1814     /// Creates a function-by-function pass manager
1815     pub fn LLVMCreateFunctionPassManagerForModule(M: &Module) -> &mut PassManager<'_>;
1816
1817     /// Disposes a pass manager.
1818     pub fn LLVMDisposePassManager<'a>(PM: &'a mut PassManager<'a>);
1819
1820     /// Runs a pass manager on a module.
1821     pub fn LLVMRunPassManager<'a>(PM: &PassManager<'a>, M: &'a Module) -> Bool;
1822
1823     pub fn LLVMInitializePasses();
1824
1825     pub fn LLVMTimeTraceProfilerInitialize();
1826
1827     pub fn LLVMTimeTraceProfilerFinishThread();
1828
1829     pub fn LLVMTimeTraceProfilerFinish(FileName: *const c_char);
1830
1831     pub fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);
1832
1833     pub fn LLVMPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
1834     pub fn LLVMPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
1835     pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: &PassManagerBuilder, Value: Bool);
1836     pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: &PassManagerBuilder, Value: Bool);
1837     pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1838         PMB: &PassManagerBuilder,
1839         threshold: c_uint,
1840     );
1841     pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1842         PMB: &PassManagerBuilder,
1843         PM: &PassManager<'_>,
1844     );
1845
1846     pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1847         PMB: &PassManagerBuilder,
1848         PM: &PassManager<'_>,
1849     );
1850     pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1851         PMB: &PassManagerBuilder,
1852         PM: &PassManager<'_>,
1853         Internalize: Bool,
1854         RunInliner: Bool,
1855     );
1856     pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
1857         PMB: &PassManagerBuilder,
1858         PM: &PassManager<'_>,
1859     );
1860
1861     pub fn LLVMGetHostCPUFeatures() -> *mut c_char;
1862
1863     pub fn LLVMDisposeMessage(message: *mut c_char);
1864
1865     pub fn LLVMIsMultithreaded() -> Bool;
1866
1867     /// Returns a string describing the last error caused by an LLVMRust* call.
1868     pub fn LLVMRustGetLastError() -> *const c_char;
1869
1870     /// Print the pass timings since static dtors aren't picking them up.
1871     pub fn LLVMRustPrintPassTimings();
1872
1873     pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
1874
1875     pub fn LLVMStructSetBody<'a>(
1876         StructTy: &'a Type,
1877         ElementTypes: *const &'a Type,
1878         ElementCount: c_uint,
1879         Packed: Bool,
1880     );
1881
1882     /// Prepares inline assembly.
1883     pub fn LLVMRustInlineAsm(
1884         Ty: &Type,
1885         AsmString: *const c_char,
1886         AsmStringLen: size_t,
1887         Constraints: *const c_char,
1888         ConstraintsLen: size_t,
1889         SideEffects: Bool,
1890         AlignStack: Bool,
1891         Dialect: AsmDialect,
1892         CanThrow: Bool,
1893     ) -> &Value;
1894     pub fn LLVMRustInlineAsmVerify(
1895         Ty: &Type,
1896         Constraints: *const c_char,
1897         ConstraintsLen: size_t,
1898     ) -> bool;
1899
1900     #[allow(improper_ctypes)]
1901     pub fn LLVMRustCoverageWriteFilenamesSectionToBuffer(
1902         Filenames: *const *const c_char,
1903         FilenamesLen: size_t,
1904         BufferOut: &RustString,
1905     );
1906
1907     #[allow(improper_ctypes)]
1908     pub fn LLVMRustCoverageWriteMappingToBuffer(
1909         VirtualFileMappingIDs: *const c_uint,
1910         NumVirtualFileMappingIDs: c_uint,
1911         Expressions: *const coverage_map::CounterExpression,
1912         NumExpressions: c_uint,
1913         MappingRegions: *const coverageinfo::CounterMappingRegion,
1914         NumMappingRegions: c_uint,
1915         BufferOut: &RustString,
1916     );
1917
1918     pub fn LLVMRustCoverageCreatePGOFuncNameVar(F: &Value, FuncName: *const c_char) -> &Value;
1919     pub fn LLVMRustCoverageHashCString(StrVal: *const c_char) -> u64;
1920     pub fn LLVMRustCoverageHashByteArray(Bytes: *const c_char, NumBytes: size_t) -> u64;
1921
1922     #[allow(improper_ctypes)]
1923     pub fn LLVMRustCoverageWriteMapSectionNameToString(M: &Module, Str: &RustString);
1924
1925     #[allow(improper_ctypes)]
1926     pub fn LLVMRustCoverageWriteFuncSectionNameToString(M: &Module, Str: &RustString);
1927
1928     #[allow(improper_ctypes)]
1929     pub fn LLVMRustCoverageWriteMappingVarNameToString(Str: &RustString);
1930
1931     pub fn LLVMRustCoverageMappingVersion() -> u32;
1932     pub fn LLVMRustDebugMetadataVersion() -> u32;
1933     pub fn LLVMRustVersionMajor() -> u32;
1934     pub fn LLVMRustVersionMinor() -> u32;
1935     pub fn LLVMRustVersionPatch() -> u32;
1936
1937     pub fn LLVMRustIsRustLLVM() -> bool;
1938
1939     /// Add LLVM module flags.
1940     ///
1941     /// In order for Rust-C LTO to work, module flags must be compatible with Clang. What
1942     /// "compatible" means depends on the merge behaviors involved.
1943     pub fn LLVMRustAddModuleFlag(
1944         M: &Module,
1945         merge_behavior: LLVMModFlagBehavior,
1946         name: *const c_char,
1947         value: u32,
1948     );
1949
1950     pub fn LLVMRustMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
1951
1952     pub fn LLVMRustDIBuilderCreate(M: &Module) -> &mut DIBuilder<'_>;
1953
1954     pub fn LLVMRustDIBuilderDispose<'a>(Builder: &'a mut DIBuilder<'a>);
1955
1956     pub fn LLVMRustDIBuilderFinalize(Builder: &DIBuilder<'_>);
1957
1958     pub fn LLVMRustDIBuilderCreateCompileUnit<'a>(
1959         Builder: &DIBuilder<'a>,
1960         Lang: c_uint,
1961         File: &'a DIFile,
1962         Producer: *const c_char,
1963         ProducerLen: size_t,
1964         isOptimized: bool,
1965         Flags: *const c_char,
1966         RuntimeVer: c_uint,
1967         SplitName: *const c_char,
1968         SplitNameLen: size_t,
1969         kind: DebugEmissionKind,
1970         DWOId: u64,
1971         SplitDebugInlining: bool,
1972     ) -> &'a DIDescriptor;
1973
1974     pub fn LLVMRustDIBuilderCreateFile<'a>(
1975         Builder: &DIBuilder<'a>,
1976         Filename: *const c_char,
1977         FilenameLen: size_t,
1978         Directory: *const c_char,
1979         DirectoryLen: size_t,
1980         CSKind: ChecksumKind,
1981         Checksum: *const c_char,
1982         ChecksumLen: size_t,
1983     ) -> &'a DIFile;
1984
1985     pub fn LLVMRustDIBuilderCreateSubroutineType<'a>(
1986         Builder: &DIBuilder<'a>,
1987         ParameterTypes: &'a DIArray,
1988     ) -> &'a DICompositeType;
1989
1990     pub fn LLVMRustDIBuilderCreateFunction<'a>(
1991         Builder: &DIBuilder<'a>,
1992         Scope: &'a DIDescriptor,
1993         Name: *const c_char,
1994         NameLen: size_t,
1995         LinkageName: *const c_char,
1996         LinkageNameLen: size_t,
1997         File: &'a DIFile,
1998         LineNo: c_uint,
1999         Ty: &'a DIType,
2000         ScopeLine: c_uint,
2001         Flags: DIFlags,
2002         SPFlags: DISPFlags,
2003         MaybeFn: Option<&'a Value>,
2004         TParam: &'a DIArray,
2005         Decl: Option<&'a DIDescriptor>,
2006     ) -> &'a DISubprogram;
2007
2008     pub fn LLVMRustDIBuilderCreateBasicType<'a>(
2009         Builder: &DIBuilder<'a>,
2010         Name: *const c_char,
2011         NameLen: size_t,
2012         SizeInBits: u64,
2013         Encoding: c_uint,
2014     ) -> &'a DIBasicType;
2015
2016     pub fn LLVMRustDIBuilderCreateTypedef<'a>(
2017         Builder: &DIBuilder<'a>,
2018         Type: &'a DIBasicType,
2019         Name: *const c_char,
2020         NameLen: size_t,
2021         File: &'a DIFile,
2022         LineNo: c_uint,
2023         Scope: Option<&'a DIScope>,
2024     ) -> &'a DIDerivedType;
2025
2026     pub fn LLVMRustDIBuilderCreatePointerType<'a>(
2027         Builder: &DIBuilder<'a>,
2028         PointeeTy: &'a DIType,
2029         SizeInBits: u64,
2030         AlignInBits: u32,
2031         AddressSpace: c_uint,
2032         Name: *const c_char,
2033         NameLen: size_t,
2034     ) -> &'a DIDerivedType;
2035
2036     pub fn LLVMRustDIBuilderCreateStructType<'a>(
2037         Builder: &DIBuilder<'a>,
2038         Scope: Option<&'a DIDescriptor>,
2039         Name: *const c_char,
2040         NameLen: size_t,
2041         File: &'a DIFile,
2042         LineNumber: c_uint,
2043         SizeInBits: u64,
2044         AlignInBits: u32,
2045         Flags: DIFlags,
2046         DerivedFrom: Option<&'a DIType>,
2047         Elements: &'a DIArray,
2048         RunTimeLang: c_uint,
2049         VTableHolder: Option<&'a DIType>,
2050         UniqueId: *const c_char,
2051         UniqueIdLen: size_t,
2052     ) -> &'a DICompositeType;
2053
2054     pub fn LLVMRustDIBuilderCreateMemberType<'a>(
2055         Builder: &DIBuilder<'a>,
2056         Scope: &'a DIDescriptor,
2057         Name: *const c_char,
2058         NameLen: size_t,
2059         File: &'a DIFile,
2060         LineNo: c_uint,
2061         SizeInBits: u64,
2062         AlignInBits: u32,
2063         OffsetInBits: u64,
2064         Flags: DIFlags,
2065         Ty: &'a DIType,
2066     ) -> &'a DIDerivedType;
2067
2068     pub fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
2069         Builder: &DIBuilder<'a>,
2070         Scope: &'a DIScope,
2071         Name: *const c_char,
2072         NameLen: size_t,
2073         File: &'a DIFile,
2074         LineNumber: c_uint,
2075         SizeInBits: u64,
2076         AlignInBits: u32,
2077         OffsetInBits: u64,
2078         Discriminant: Option<&'a Value>,
2079         Flags: DIFlags,
2080         Ty: &'a DIType,
2081     ) -> &'a DIType;
2082
2083     pub fn LLVMRustDIBuilderCreateLexicalBlock<'a>(
2084         Builder: &DIBuilder<'a>,
2085         Scope: &'a DIScope,
2086         File: &'a DIFile,
2087         Line: c_uint,
2088         Col: c_uint,
2089     ) -> &'a DILexicalBlock;
2090
2091     pub fn LLVMRustDIBuilderCreateLexicalBlockFile<'a>(
2092         Builder: &DIBuilder<'a>,
2093         Scope: &'a DIScope,
2094         File: &'a DIFile,
2095     ) -> &'a DILexicalBlock;
2096
2097     pub fn LLVMRustDIBuilderCreateStaticVariable<'a>(
2098         Builder: &DIBuilder<'a>,
2099         Context: Option<&'a DIScope>,
2100         Name: *const c_char,
2101         NameLen: size_t,
2102         LinkageName: *const c_char,
2103         LinkageNameLen: size_t,
2104         File: &'a DIFile,
2105         LineNo: c_uint,
2106         Ty: &'a DIType,
2107         isLocalToUnit: bool,
2108         Val: &'a Value,
2109         Decl: Option<&'a DIDescriptor>,
2110         AlignInBits: u32,
2111     ) -> &'a DIGlobalVariableExpression;
2112
2113     pub fn LLVMRustDIBuilderCreateVariable<'a>(
2114         Builder: &DIBuilder<'a>,
2115         Tag: c_uint,
2116         Scope: &'a DIDescriptor,
2117         Name: *const c_char,
2118         NameLen: size_t,
2119         File: &'a DIFile,
2120         LineNo: c_uint,
2121         Ty: &'a DIType,
2122         AlwaysPreserve: bool,
2123         Flags: DIFlags,
2124         ArgNo: c_uint,
2125         AlignInBits: u32,
2126     ) -> &'a DIVariable;
2127
2128     pub fn LLVMRustDIBuilderCreateArrayType<'a>(
2129         Builder: &DIBuilder<'a>,
2130         Size: u64,
2131         AlignInBits: u32,
2132         Ty: &'a DIType,
2133         Subscripts: &'a DIArray,
2134     ) -> &'a DIType;
2135
2136     pub fn LLVMRustDIBuilderGetOrCreateSubrange<'a>(
2137         Builder: &DIBuilder<'a>,
2138         Lo: i64,
2139         Count: i64,
2140     ) -> &'a DISubrange;
2141
2142     pub fn LLVMRustDIBuilderGetOrCreateArray<'a>(
2143         Builder: &DIBuilder<'a>,
2144         Ptr: *const Option<&'a DIDescriptor>,
2145         Count: c_uint,
2146     ) -> &'a DIArray;
2147
2148     pub fn LLVMRustDIBuilderInsertDeclareAtEnd<'a>(
2149         Builder: &DIBuilder<'a>,
2150         Val: &'a Value,
2151         VarInfo: &'a DIVariable,
2152         AddrOps: *const u64,
2153         AddrOpsCount: c_uint,
2154         DL: &'a DILocation,
2155         InsertAtEnd: &'a BasicBlock,
2156     ) -> &'a Value;
2157
2158     pub fn LLVMRustDIBuilderCreateEnumerator<'a>(
2159         Builder: &DIBuilder<'a>,
2160         Name: *const c_char,
2161         NameLen: size_t,
2162         Value: i64,
2163         IsUnsigned: bool,
2164     ) -> &'a DIEnumerator;
2165
2166     pub fn LLVMRustDIBuilderCreateEnumerationType<'a>(
2167         Builder: &DIBuilder<'a>,
2168         Scope: &'a DIScope,
2169         Name: *const c_char,
2170         NameLen: size_t,
2171         File: &'a DIFile,
2172         LineNumber: c_uint,
2173         SizeInBits: u64,
2174         AlignInBits: u32,
2175         Elements: &'a DIArray,
2176         ClassType: &'a DIType,
2177         IsScoped: bool,
2178     ) -> &'a DIType;
2179
2180     pub fn LLVMRustDIBuilderCreateUnionType<'a>(
2181         Builder: &DIBuilder<'a>,
2182         Scope: Option<&'a DIScope>,
2183         Name: *const c_char,
2184         NameLen: size_t,
2185         File: &'a DIFile,
2186         LineNumber: c_uint,
2187         SizeInBits: u64,
2188         AlignInBits: u32,
2189         Flags: DIFlags,
2190         Elements: Option<&'a DIArray>,
2191         RunTimeLang: c_uint,
2192         UniqueId: *const c_char,
2193         UniqueIdLen: size_t,
2194     ) -> &'a DIType;
2195
2196     pub fn LLVMRustDIBuilderCreateVariantPart<'a>(
2197         Builder: &DIBuilder<'a>,
2198         Scope: &'a DIScope,
2199         Name: *const c_char,
2200         NameLen: size_t,
2201         File: &'a DIFile,
2202         LineNo: c_uint,
2203         SizeInBits: u64,
2204         AlignInBits: u32,
2205         Flags: DIFlags,
2206         Discriminator: Option<&'a DIDerivedType>,
2207         Elements: &'a DIArray,
2208         UniqueId: *const c_char,
2209         UniqueIdLen: size_t,
2210     ) -> &'a DIDerivedType;
2211
2212     pub fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
2213
2214     pub fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>(
2215         Builder: &DIBuilder<'a>,
2216         Scope: Option<&'a DIScope>,
2217         Name: *const c_char,
2218         NameLen: size_t,
2219         Ty: &'a DIType,
2220     ) -> &'a DITemplateTypeParameter;
2221
2222     pub fn LLVMRustDIBuilderCreateNameSpace<'a>(
2223         Builder: &DIBuilder<'a>,
2224         Scope: Option<&'a DIScope>,
2225         Name: *const c_char,
2226         NameLen: size_t,
2227         ExportSymbols: bool,
2228     ) -> &'a DINameSpace;
2229
2230     pub fn LLVMRustDICompositeTypeReplaceArrays<'a>(
2231         Builder: &DIBuilder<'a>,
2232         CompositeType: &'a DIType,
2233         Elements: Option<&'a DIArray>,
2234         Params: Option<&'a DIArray>,
2235     );
2236
2237     pub fn LLVMRustDIBuilderCreateDebugLocation<'a>(
2238         Line: c_uint,
2239         Column: c_uint,
2240         Scope: &'a DIScope,
2241         InlinedAt: Option<&'a DILocation>,
2242     ) -> &'a DILocation;
2243     pub fn LLVMRustDIBuilderCreateOpDeref() -> u64;
2244     pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> u64;
2245
2246     #[allow(improper_ctypes)]
2247     pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
2248     #[allow(improper_ctypes)]
2249     pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
2250
2251     pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
2252
2253     pub fn LLVMRustPassKind(Pass: &Pass) -> PassKind;
2254     pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> Option<&'static mut Pass>;
2255     pub fn LLVMRustCreateAddressSanitizerFunctionPass(Recover: bool) -> &'static mut Pass;
2256     pub fn LLVMRustCreateModuleAddressSanitizerPass(Recover: bool) -> &'static mut Pass;
2257     pub fn LLVMRustCreateMemorySanitizerPass(
2258         TrackOrigins: c_int,
2259         Recover: bool,
2260     ) -> &'static mut Pass;
2261     pub fn LLVMRustCreateThreadSanitizerPass() -> &'static mut Pass;
2262     pub fn LLVMRustCreateHWAddressSanitizerPass(Recover: bool) -> &'static mut Pass;
2263     pub fn LLVMRustAddPass(PM: &PassManager<'_>, Pass: &'static mut Pass);
2264     pub fn LLVMRustAddLastExtensionPasses(
2265         PMB: &PassManagerBuilder,
2266         Passes: *const &'static mut Pass,
2267         NumPasses: size_t,
2268     );
2269
2270     pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
2271
2272     pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine);
2273     pub fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t;
2274     pub fn LLVMRustGetTargetFeature(
2275         T: &TargetMachine,
2276         Index: size_t,
2277         Feature: &mut *const c_char,
2278         Desc: &mut *const c_char,
2279     );
2280
2281     pub fn LLVMRustGetHostCPUName(len: *mut usize) -> *const c_char;
2282     pub fn LLVMRustCreateTargetMachine(
2283         Triple: *const c_char,
2284         CPU: *const c_char,
2285         Features: *const c_char,
2286         Abi: *const c_char,
2287         Model: CodeModel,
2288         Reloc: RelocModel,
2289         Level: CodeGenOptLevel,
2290         UseSoftFP: bool,
2291         FunctionSections: bool,
2292         DataSections: bool,
2293         UniqueSectionNames: bool,
2294         TrapUnreachable: bool,
2295         Singlethread: bool,
2296         AsmComments: bool,
2297         EmitStackSizeSection: bool,
2298         RelaxELFRelocations: bool,
2299         UseInitArray: bool,
2300         SplitDwarfFile: *const c_char,
2301     ) -> Option<&'static mut TargetMachine>;
2302     pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
2303     pub fn LLVMRustAddBuilderLibraryInfo<'a>(
2304         PMB: &'a PassManagerBuilder,
2305         M: &'a Module,
2306         DisableSimplifyLibCalls: bool,
2307     );
2308     pub fn LLVMRustConfigurePassManagerBuilder(
2309         PMB: &PassManagerBuilder,
2310         OptLevel: CodeGenOptLevel,
2311         MergeFunctions: bool,
2312         SLPVectorize: bool,
2313         LoopVectorize: bool,
2314         PrepareForThinLTO: bool,
2315         PGOGenPath: *const c_char,
2316         PGOUsePath: *const c_char,
2317         PGOSampleUsePath: *const c_char,
2318     );
2319     pub fn LLVMRustAddLibraryInfo<'a>(
2320         PM: &PassManager<'a>,
2321         M: &'a Module,
2322         DisableSimplifyLibCalls: bool,
2323     );
2324     pub fn LLVMRustRunFunctionPassManager<'a>(PM: &PassManager<'a>, M: &'a Module);
2325     pub fn LLVMRustWriteOutputFile<'a>(
2326         T: &'a TargetMachine,
2327         PM: &PassManager<'a>,
2328         M: &'a Module,
2329         Output: *const c_char,
2330         DwoOutput: *const c_char,
2331         FileType: FileType,
2332     ) -> LLVMRustResult;
2333     pub fn LLVMRustOptimizeWithNewPassManager<'a>(
2334         M: &'a Module,
2335         TM: &'a TargetMachine,
2336         OptLevel: PassBuilderOptLevel,
2337         OptStage: OptStage,
2338         NoPrepopulatePasses: bool,
2339         VerifyIR: bool,
2340         UseThinLTOBuffers: bool,
2341         MergeFunctions: bool,
2342         UnrollLoops: bool,
2343         SLPVectorize: bool,
2344         LoopVectorize: bool,
2345         DisableSimplifyLibCalls: bool,
2346         EmitLifetimeMarkers: bool,
2347         SanitizerOptions: Option<&SanitizerOptions>,
2348         PGOGenPath: *const c_char,
2349         PGOUsePath: *const c_char,
2350         InstrumentCoverage: bool,
2351         InstrumentGCOV: bool,
2352         PGOSampleUsePath: *const c_char,
2353         DebugInfoForProfiling: bool,
2354         llvm_selfprofiler: *mut c_void,
2355         begin_callback: SelfProfileBeforePassCallback,
2356         end_callback: SelfProfileAfterPassCallback,
2357         ExtraPasses: *const c_char,
2358         ExtraPassesLen: size_t,
2359         LLVMPlugins: *const c_char,
2360         LLVMPluginsLen: size_t,
2361     ) -> LLVMRustResult;
2362     pub fn LLVMRustPrintModule(
2363         M: &Module,
2364         Output: *const c_char,
2365         Demangle: extern "C" fn(*const c_char, size_t, *mut c_char, size_t) -> size_t,
2366     ) -> LLVMRustResult;
2367     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2368     pub fn LLVMRustPrintPasses();
2369     pub fn LLVMRustGetInstructionCount(M: &Module) -> u32;
2370     pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
2371     pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
2372     pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
2373
2374     pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
2375     pub fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
2376     pub fn LLVMRustArchiveIteratorNext<'a>(
2377         AIR: &ArchiveIterator<'a>,
2378     ) -> Option<&'a mut ArchiveChild<'a>>;
2379     pub fn LLVMRustArchiveChildName(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
2380     pub fn LLVMRustArchiveChildData(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
2381     pub fn LLVMRustArchiveChildFree<'a>(ACR: &'a mut ArchiveChild<'a>);
2382     pub fn LLVMRustArchiveIteratorFree<'a>(AIR: &'a mut ArchiveIterator<'a>);
2383     pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
2384
2385     #[allow(improper_ctypes)]
2386     pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
2387
2388     #[allow(improper_ctypes)]
2389     pub fn LLVMRustUnpackOptimizationDiagnostic<'a>(
2390         DI: &'a DiagnosticInfo,
2391         pass_name_out: &RustString,
2392         function_out: &mut Option<&'a Value>,
2393         loc_line_out: &mut c_uint,
2394         loc_column_out: &mut c_uint,
2395         loc_filename_out: &RustString,
2396         message_out: &RustString,
2397     );
2398
2399     pub fn LLVMRustUnpackInlineAsmDiagnostic<'a>(
2400         DI: &'a DiagnosticInfo,
2401         level_out: &mut DiagnosticLevel,
2402         cookie_out: &mut c_uint,
2403         message_out: &mut Option<&'a Twine>,
2404     );
2405
2406     #[allow(improper_ctypes)]
2407     pub fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
2408     pub fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
2409
2410     pub fn LLVMRustGetSMDiagnostic<'a>(
2411         DI: &'a DiagnosticInfo,
2412         cookie_out: &mut c_uint,
2413     ) -> &'a SMDiagnostic;
2414
2415     pub fn LLVMRustSetInlineAsmDiagnosticHandler(
2416         C: &Context,
2417         H: InlineAsmDiagHandlerTy,
2418         CX: *mut c_void,
2419     );
2420
2421     #[allow(improper_ctypes)]
2422     pub fn LLVMRustUnpackSMDiagnostic(
2423         d: &SMDiagnostic,
2424         message_out: &RustString,
2425         buffer_out: &RustString,
2426         level_out: &mut DiagnosticLevel,
2427         loc_out: &mut c_uint,
2428         ranges_out: *mut c_uint,
2429         num_ranges: &mut usize,
2430     ) -> bool;
2431
2432     pub fn LLVMRustWriteArchive(
2433         Dst: *const c_char,
2434         NumMembers: size_t,
2435         Members: *const &RustArchiveMember<'_>,
2436         WriteSymbtab: bool,
2437         Kind: ArchiveKind,
2438     ) -> LLVMRustResult;
2439     pub fn LLVMRustArchiveMemberNew<'a>(
2440         Filename: *const c_char,
2441         Name: *const c_char,
2442         Child: Option<&ArchiveChild<'a>>,
2443     ) -> &'a mut RustArchiveMember<'a>;
2444     pub fn LLVMRustArchiveMemberFree<'a>(Member: &'a mut RustArchiveMember<'a>);
2445
2446     pub fn LLVMRustWriteImportLibrary(
2447         ImportName: *const c_char,
2448         Path: *const c_char,
2449         Exports: *const LLVMRustCOFFShortExport,
2450         NumExports: usize,
2451         Machine: u16,
2452         MinGW: bool,
2453     ) -> LLVMRustResult;
2454
2455     pub fn LLVMRustSetDataLayoutFromTargetMachine<'a>(M: &'a Module, TM: &'a TargetMachine);
2456
2457     pub fn LLVMRustBuildOperandBundleDef<'a>(
2458         Name: *const c_char,
2459         Inputs: *const &'a Value,
2460         NumInputs: c_uint,
2461     ) -> &'a mut OperandBundleDef<'a>;
2462     pub fn LLVMRustFreeOperandBundleDef<'a>(Bundle: &'a mut OperandBundleDef<'a>);
2463
2464     pub fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock);
2465
2466     pub fn LLVMRustSetComdat<'a>(M: &'a Module, V: &'a Value, Name: *const c_char, NameLen: size_t);
2467     pub fn LLVMRustUnsetComdat(V: &Value);
2468     pub fn LLVMRustSetModulePICLevel(M: &Module);
2469     pub fn LLVMRustSetModulePIELevel(M: &Module);
2470     pub fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel);
2471     pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
2472     pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
2473     pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
2474     pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
2475     pub fn LLVMRustModuleCost(M: &Module) -> u64;
2476
2477     pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> &'static mut ThinLTOBuffer;
2478     pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
2479     pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
2480     pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
2481     pub fn LLVMRustCreateThinLTOData(
2482         Modules: *const ThinLTOModule,
2483         NumModules: c_uint,
2484         PreservedSymbols: *const *const c_char,
2485         PreservedSymbolsLen: c_uint,
2486     ) -> Option<&'static mut ThinLTOData>;
2487     pub fn LLVMRustPrepareThinLTORename(
2488         Data: &ThinLTOData,
2489         Module: &Module,
2490         Target: &TargetMachine,
2491     ) -> bool;
2492     pub fn LLVMRustPrepareThinLTOResolveWeak(Data: &ThinLTOData, Module: &Module) -> bool;
2493     pub fn LLVMRustPrepareThinLTOInternalize(Data: &ThinLTOData, Module: &Module) -> bool;
2494     pub fn LLVMRustPrepareThinLTOImport(
2495         Data: &ThinLTOData,
2496         Module: &Module,
2497         Target: &TargetMachine,
2498     ) -> bool;
2499     pub fn LLVMRustGetThinLTOModuleImports(
2500         Data: *const ThinLTOData,
2501         ModuleNameCallback: ThinLTOModuleNameCallback,
2502         CallbackPayload: *mut c_void,
2503     );
2504     pub fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
2505     pub fn LLVMRustParseBitcodeForLTO(
2506         Context: &Context,
2507         Data: *const u8,
2508         len: usize,
2509         Identifier: *const c_char,
2510     ) -> Option<&Module>;
2511     pub fn LLVMRustGetBitcodeSliceFromObjectData(
2512         Data: *const u8,
2513         len: usize,
2514         out_len: &mut usize,
2515     ) -> *const u8;
2516     pub fn LLVMRustLTOGetDICompileUnit(M: &Module, CU1: &mut *mut c_void, CU2: &mut *mut c_void);
2517     pub fn LLVMRustLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
2518
2519     pub fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
2520     pub fn LLVMRustLinkerAdd(
2521         linker: &Linker<'_>,
2522         bytecode: *const c_char,
2523         bytecode_len: usize,
2524     ) -> bool;
2525     pub fn LLVMRustLinkerFree<'a>(linker: &'a mut Linker<'a>);
2526     #[allow(improper_ctypes)]
2527     pub fn LLVMRustComputeLTOCacheKey(
2528         key_out: &RustString,
2529         mod_id: *const c_char,
2530         data: &ThinLTOData,
2531     );
2532
2533     pub fn LLVMRustContextGetDiagnosticHandler(Context: &Context) -> Option<&DiagnosticHandler>;
2534     pub fn LLVMRustContextSetDiagnosticHandler(
2535         context: &Context,
2536         diagnostic_handler: Option<&DiagnosticHandler>,
2537     );
2538     pub fn LLVMRustContextConfigureDiagnosticHandler(
2539         context: &Context,
2540         diagnostic_handler_callback: DiagnosticHandlerTy,
2541         diagnostic_handler_context: *mut c_void,
2542         remark_all_passes: bool,
2543         remark_passes: *const *const c_char,
2544         remark_passes_len: usize,
2545     );
2546
2547 }