]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Auto merge of #99283 - RalfJung:miri, r=RalfJung
[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::Unordered => AtomicOrdering::Unordered,
385             rustc_codegen_ssa::common::AtomicOrdering::Relaxed => AtomicOrdering::Monotonic,
386             rustc_codegen_ssa::common::AtomicOrdering::Acquire => AtomicOrdering::Acquire,
387             rustc_codegen_ssa::common::AtomicOrdering::Release => AtomicOrdering::Release,
388             rustc_codegen_ssa::common::AtomicOrdering::AcquireRelease => {
389                 AtomicOrdering::AcquireRelease
390             }
391             rustc_codegen_ssa::common::AtomicOrdering::SequentiallyConsistent => {
392                 AtomicOrdering::SequentiallyConsistent
393             }
394         }
395     }
396 }
397
398 /// LLVMRustSynchronizationScope
399 #[derive(Copy, Clone)]
400 #[repr(C)]
401 pub enum SynchronizationScope {
402     SingleThread,
403     CrossThread,
404 }
405
406 impl SynchronizationScope {
407     pub fn from_generic(sc: rustc_codegen_ssa::common::SynchronizationScope) -> Self {
408         match sc {
409             rustc_codegen_ssa::common::SynchronizationScope::SingleThread => {
410                 SynchronizationScope::SingleThread
411             }
412             rustc_codegen_ssa::common::SynchronizationScope::CrossThread => {
413                 SynchronizationScope::CrossThread
414             }
415         }
416     }
417 }
418
419 /// LLVMRustFileType
420 #[derive(Copy, Clone)]
421 #[repr(C)]
422 pub enum FileType {
423     AssemblyFile,
424     ObjectFile,
425 }
426
427 /// LLVMMetadataType
428 #[derive(Copy, Clone)]
429 #[repr(C)]
430 pub enum MetadataType {
431     MD_dbg = 0,
432     MD_tbaa = 1,
433     MD_prof = 2,
434     MD_fpmath = 3,
435     MD_range = 4,
436     MD_tbaa_struct = 5,
437     MD_invariant_load = 6,
438     MD_alias_scope = 7,
439     MD_noalias = 8,
440     MD_nontemporal = 9,
441     MD_mem_parallel_loop_access = 10,
442     MD_nonnull = 11,
443     MD_align = 17,
444     MD_type = 19,
445     MD_vcall_visibility = 28,
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         pub(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         pub(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         pub(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         pub(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         pub(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 LLVMRustGlobalAddMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
1072     pub fn LLVMValueAsMetadata(Node: &Value) -> &Metadata;
1073
1074     // Operations on constants of any type
1075     pub fn LLVMConstNull(Ty: &Type) -> &Value;
1076     pub fn LLVMGetUndef(Ty: &Type) -> &Value;
1077
1078     // Operations on metadata
1079     pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
1080     pub fn LLVMMDNodeInContext<'a>(
1081         C: &'a Context,
1082         Vals: *const &'a Value,
1083         Count: c_uint,
1084     ) -> &'a Value;
1085     pub fn LLVMMDNodeInContext2<'a>(
1086         C: &'a Context,
1087         Vals: *const &'a Metadata,
1088         Count: size_t,
1089     ) -> &'a Metadata;
1090     pub fn LLVMAddNamedMetadataOperand<'a>(M: &'a Module, Name: *const c_char, Val: &'a Value);
1091
1092     // Operations on scalar constants
1093     pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
1094     pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
1095     pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
1096     pub fn LLVMConstIntGetZExtValue(ConstantVal: &ConstantInt) -> c_ulonglong;
1097     pub fn LLVMRustConstInt128Get(
1098         ConstantVal: &ConstantInt,
1099         SExt: bool,
1100         high: &mut u64,
1101         low: &mut u64,
1102     ) -> bool;
1103
1104     // Operations on composite constants
1105     pub fn LLVMConstStringInContext(
1106         C: &Context,
1107         Str: *const c_char,
1108         Length: c_uint,
1109         DontNullTerminate: Bool,
1110     ) -> &Value;
1111     pub fn LLVMConstStructInContext<'a>(
1112         C: &'a Context,
1113         ConstantVals: *const &'a Value,
1114         Count: c_uint,
1115         Packed: Bool,
1116     ) -> &'a Value;
1117
1118     pub fn LLVMConstArray<'a>(
1119         ElementTy: &'a Type,
1120         ConstantVals: *const &'a Value,
1121         Length: c_uint,
1122     ) -> &'a Value;
1123     pub fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
1124
1125     // Constant expressions
1126     pub fn LLVMRustConstInBoundsGEP2<'a>(
1127         ty: &'a Type,
1128         ConstantVal: &'a Value,
1129         ConstantIndices: *const &'a Value,
1130         NumIndices: c_uint,
1131     ) -> &'a Value;
1132     pub fn LLVMConstZExt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1133     pub fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1134     pub fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1135     pub fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1136     pub fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1137     pub fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>;
1138
1139     // Operations on global variables, functions, and aliases (globals)
1140     pub fn LLVMIsDeclaration(Global: &Value) -> Bool;
1141     pub fn LLVMRustGetLinkage(Global: &Value) -> Linkage;
1142     pub fn LLVMRustSetLinkage(Global: &Value, RustLinkage: Linkage);
1143     pub fn LLVMSetSection(Global: &Value, Section: *const c_char);
1144     pub fn LLVMRustGetVisibility(Global: &Value) -> Visibility;
1145     pub fn LLVMRustSetVisibility(Global: &Value, Viz: Visibility);
1146     pub fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);
1147     pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
1148     pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
1149     pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
1150
1151     // Operations on global variables
1152     pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
1153     pub fn LLVMAddGlobal<'a>(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1154     pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
1155     pub fn LLVMRustGetOrInsertGlobal<'a>(
1156         M: &'a Module,
1157         Name: *const c_char,
1158         NameLen: size_t,
1159         T: &'a Type,
1160     ) -> &'a Value;
1161     pub fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
1162     pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
1163     pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
1164     pub fn LLVMDeleteGlobal(GlobalVar: &Value);
1165     pub fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;
1166     pub fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value);
1167     pub fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool;
1168     pub fn LLVMSetThreadLocal(GlobalVar: &Value, IsThreadLocal: Bool);
1169     pub fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
1170     pub fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
1171     pub fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
1172     pub fn LLVMRustGetNamedValue(
1173         M: &Module,
1174         Name: *const c_char,
1175         NameLen: size_t,
1176     ) -> Option<&Value>;
1177     pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
1178
1179     // Operations on attributes
1180     pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;
1181     pub fn LLVMCreateStringAttribute(
1182         C: &Context,
1183         Name: *const c_char,
1184         NameLen: c_uint,
1185         Value: *const c_char,
1186         ValueLen: c_uint,
1187     ) -> &Attribute;
1188     pub fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute;
1189     pub fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute;
1190     pub fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute;
1191     pub fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1192     pub fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1193     pub fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute;
1194
1195     // Operations on functions
1196     pub fn LLVMRustGetOrInsertFunction<'a>(
1197         M: &'a Module,
1198         Name: *const c_char,
1199         NameLen: size_t,
1200         FunctionTy: &'a Type,
1201     ) -> &'a Value;
1202     pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
1203     pub fn LLVMRustAddFunctionAttributes<'a>(
1204         Fn: &'a Value,
1205         index: c_uint,
1206         Attrs: *const &'a Attribute,
1207         AttrsLen: size_t,
1208     );
1209
1210     // Operations on parameters
1211     pub fn LLVMIsAArgument(Val: &Value) -> Option<&Value>;
1212     pub fn LLVMCountParams(Fn: &Value) -> c_uint;
1213     pub fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
1214
1215     // Operations on basic blocks
1216     pub fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
1217     pub fn LLVMAppendBasicBlockInContext<'a>(
1218         C: &'a Context,
1219         Fn: &'a Value,
1220         Name: *const c_char,
1221     ) -> &'a BasicBlock;
1222
1223     // Operations on instructions
1224     pub fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>;
1225     pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
1226
1227     // Operations on call sites
1228     pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
1229     pub fn LLVMRustAddCallSiteAttributes<'a>(
1230         Instr: &'a Value,
1231         index: c_uint,
1232         Attrs: *const &'a Attribute,
1233         AttrsLen: size_t,
1234     );
1235
1236     // Operations on load/store instructions (only)
1237     pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
1238
1239     // Operations on phi nodes
1240     pub fn LLVMAddIncoming<'a>(
1241         PhiNode: &'a Value,
1242         IncomingValues: *const &'a Value,
1243         IncomingBlocks: *const &'a BasicBlock,
1244         Count: c_uint,
1245     );
1246
1247     // Instruction builders
1248     pub fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;
1249     pub fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock);
1250     pub fn LLVMGetInsertBlock<'a>(Builder: &Builder<'a>) -> &'a BasicBlock;
1251     pub fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
1252
1253     // Metadata
1254     pub fn LLVMSetCurrentDebugLocation<'a>(Builder: &Builder<'a>, L: &'a Value);
1255
1256     // Terminators
1257     pub fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;
1258     pub fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value;
1259     pub fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;
1260     pub fn LLVMBuildCondBr<'a>(
1261         B: &Builder<'a>,
1262         If: &'a Value,
1263         Then: &'a BasicBlock,
1264         Else: &'a BasicBlock,
1265     ) -> &'a Value;
1266     pub fn LLVMBuildSwitch<'a>(
1267         B: &Builder<'a>,
1268         V: &'a Value,
1269         Else: &'a BasicBlock,
1270         NumCases: c_uint,
1271     ) -> &'a Value;
1272     pub fn LLVMRustBuildInvoke<'a>(
1273         B: &Builder<'a>,
1274         Ty: &'a Type,
1275         Fn: &'a Value,
1276         Args: *const &'a Value,
1277         NumArgs: c_uint,
1278         Then: &'a BasicBlock,
1279         Catch: &'a BasicBlock,
1280         Bundle: Option<&OperandBundleDef<'a>>,
1281         Name: *const c_char,
1282     ) -> &'a Value;
1283     pub fn LLVMBuildLandingPad<'a>(
1284         B: &Builder<'a>,
1285         Ty: &'a Type,
1286         PersFn: Option<&'a Value>,
1287         NumClauses: c_uint,
1288         Name: *const c_char,
1289     ) -> &'a Value;
1290     pub fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
1291     pub fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value;
1292
1293     pub fn LLVMRustBuildCleanupPad<'a>(
1294         B: &Builder<'a>,
1295         ParentPad: Option<&'a Value>,
1296         ArgCnt: c_uint,
1297         Args: *const &'a Value,
1298         Name: *const c_char,
1299     ) -> Option<&'a Value>;
1300     pub fn LLVMRustBuildCleanupRet<'a>(
1301         B: &Builder<'a>,
1302         CleanupPad: &'a Value,
1303         UnwindBB: Option<&'a BasicBlock>,
1304     ) -> Option<&'a Value>;
1305     pub fn LLVMRustBuildCatchPad<'a>(
1306         B: &Builder<'a>,
1307         ParentPad: &'a Value,
1308         ArgCnt: c_uint,
1309         Args: *const &'a Value,
1310         Name: *const c_char,
1311     ) -> Option<&'a Value>;
1312     pub fn LLVMRustBuildCatchRet<'a>(
1313         B: &Builder<'a>,
1314         Pad: &'a Value,
1315         BB: &'a BasicBlock,
1316     ) -> Option<&'a Value>;
1317     pub fn LLVMRustBuildCatchSwitch<'a>(
1318         Builder: &Builder<'a>,
1319         ParentPad: Option<&'a Value>,
1320         BB: Option<&'a BasicBlock>,
1321         NumHandlers: c_uint,
1322         Name: *const c_char,
1323     ) -> Option<&'a Value>;
1324     pub fn LLVMRustAddHandler<'a>(CatchSwitch: &'a Value, Handler: &'a BasicBlock);
1325     pub fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value);
1326
1327     // Add a case to the switch instruction
1328     pub fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
1329
1330     // Add a clause to the landing pad instruction
1331     pub fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value);
1332
1333     // Set the cleanup on a landing pad instruction
1334     pub fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);
1335
1336     // Arithmetic
1337     pub fn LLVMBuildAdd<'a>(
1338         B: &Builder<'a>,
1339         LHS: &'a Value,
1340         RHS: &'a Value,
1341         Name: *const c_char,
1342     ) -> &'a Value;
1343     pub fn LLVMBuildFAdd<'a>(
1344         B: &Builder<'a>,
1345         LHS: &'a Value,
1346         RHS: &'a Value,
1347         Name: *const c_char,
1348     ) -> &'a Value;
1349     pub fn LLVMBuildSub<'a>(
1350         B: &Builder<'a>,
1351         LHS: &'a Value,
1352         RHS: &'a Value,
1353         Name: *const c_char,
1354     ) -> &'a Value;
1355     pub fn LLVMBuildFSub<'a>(
1356         B: &Builder<'a>,
1357         LHS: &'a Value,
1358         RHS: &'a Value,
1359         Name: *const c_char,
1360     ) -> &'a Value;
1361     pub fn LLVMBuildMul<'a>(
1362         B: &Builder<'a>,
1363         LHS: &'a Value,
1364         RHS: &'a Value,
1365         Name: *const c_char,
1366     ) -> &'a Value;
1367     pub fn LLVMBuildFMul<'a>(
1368         B: &Builder<'a>,
1369         LHS: &'a Value,
1370         RHS: &'a Value,
1371         Name: *const c_char,
1372     ) -> &'a Value;
1373     pub fn LLVMBuildUDiv<'a>(
1374         B: &Builder<'a>,
1375         LHS: &'a Value,
1376         RHS: &'a Value,
1377         Name: *const c_char,
1378     ) -> &'a Value;
1379     pub fn LLVMBuildExactUDiv<'a>(
1380         B: &Builder<'a>,
1381         LHS: &'a Value,
1382         RHS: &'a Value,
1383         Name: *const c_char,
1384     ) -> &'a Value;
1385     pub fn LLVMBuildSDiv<'a>(
1386         B: &Builder<'a>,
1387         LHS: &'a Value,
1388         RHS: &'a Value,
1389         Name: *const c_char,
1390     ) -> &'a Value;
1391     pub fn LLVMBuildExactSDiv<'a>(
1392         B: &Builder<'a>,
1393         LHS: &'a Value,
1394         RHS: &'a Value,
1395         Name: *const c_char,
1396     ) -> &'a Value;
1397     pub fn LLVMBuildFDiv<'a>(
1398         B: &Builder<'a>,
1399         LHS: &'a Value,
1400         RHS: &'a Value,
1401         Name: *const c_char,
1402     ) -> &'a Value;
1403     pub fn LLVMBuildURem<'a>(
1404         B: &Builder<'a>,
1405         LHS: &'a Value,
1406         RHS: &'a Value,
1407         Name: *const c_char,
1408     ) -> &'a Value;
1409     pub fn LLVMBuildSRem<'a>(
1410         B: &Builder<'a>,
1411         LHS: &'a Value,
1412         RHS: &'a Value,
1413         Name: *const c_char,
1414     ) -> &'a Value;
1415     pub fn LLVMBuildFRem<'a>(
1416         B: &Builder<'a>,
1417         LHS: &'a Value,
1418         RHS: &'a Value,
1419         Name: *const c_char,
1420     ) -> &'a Value;
1421     pub fn LLVMBuildShl<'a>(
1422         B: &Builder<'a>,
1423         LHS: &'a Value,
1424         RHS: &'a Value,
1425         Name: *const c_char,
1426     ) -> &'a Value;
1427     pub fn LLVMBuildLShr<'a>(
1428         B: &Builder<'a>,
1429         LHS: &'a Value,
1430         RHS: &'a Value,
1431         Name: *const c_char,
1432     ) -> &'a Value;
1433     pub fn LLVMBuildAShr<'a>(
1434         B: &Builder<'a>,
1435         LHS: &'a Value,
1436         RHS: &'a Value,
1437         Name: *const c_char,
1438     ) -> &'a Value;
1439     pub fn LLVMBuildNSWAdd<'a>(
1440         B: &Builder<'a>,
1441         LHS: &'a Value,
1442         RHS: &'a Value,
1443         Name: *const c_char,
1444     ) -> &'a Value;
1445     pub fn LLVMBuildNUWAdd<'a>(
1446         B: &Builder<'a>,
1447         LHS: &'a Value,
1448         RHS: &'a Value,
1449         Name: *const c_char,
1450     ) -> &'a Value;
1451     pub fn LLVMBuildNSWSub<'a>(
1452         B: &Builder<'a>,
1453         LHS: &'a Value,
1454         RHS: &'a Value,
1455         Name: *const c_char,
1456     ) -> &'a Value;
1457     pub fn LLVMBuildNUWSub<'a>(
1458         B: &Builder<'a>,
1459         LHS: &'a Value,
1460         RHS: &'a Value,
1461         Name: *const c_char,
1462     ) -> &'a Value;
1463     pub fn LLVMBuildNSWMul<'a>(
1464         B: &Builder<'a>,
1465         LHS: &'a Value,
1466         RHS: &'a Value,
1467         Name: *const c_char,
1468     ) -> &'a Value;
1469     pub fn LLVMBuildNUWMul<'a>(
1470         B: &Builder<'a>,
1471         LHS: &'a Value,
1472         RHS: &'a Value,
1473         Name: *const c_char,
1474     ) -> &'a Value;
1475     pub fn LLVMBuildAnd<'a>(
1476         B: &Builder<'a>,
1477         LHS: &'a Value,
1478         RHS: &'a Value,
1479         Name: *const c_char,
1480     ) -> &'a Value;
1481     pub fn LLVMBuildOr<'a>(
1482         B: &Builder<'a>,
1483         LHS: &'a Value,
1484         RHS: &'a Value,
1485         Name: *const c_char,
1486     ) -> &'a Value;
1487     pub fn LLVMBuildXor<'a>(
1488         B: &Builder<'a>,
1489         LHS: &'a Value,
1490         RHS: &'a Value,
1491         Name: *const c_char,
1492     ) -> &'a Value;
1493     pub fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1494     pub fn LLVMBuildFNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1495     pub fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1496     pub fn LLVMRustSetFastMath(Instr: &Value);
1497
1498     // Memory
1499     pub fn LLVMBuildAlloca<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1500     pub fn LLVMBuildArrayAlloca<'a>(
1501         B: &Builder<'a>,
1502         Ty: &'a Type,
1503         Val: &'a Value,
1504         Name: *const c_char,
1505     ) -> &'a Value;
1506     pub fn LLVMBuildLoad2<'a>(
1507         B: &Builder<'a>,
1508         Ty: &'a Type,
1509         PointerVal: &'a Value,
1510         Name: *const c_char,
1511     ) -> &'a Value;
1512
1513     pub fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
1514
1515     pub fn LLVMBuildGEP2<'a>(
1516         B: &Builder<'a>,
1517         Ty: &'a Type,
1518         Pointer: &'a Value,
1519         Indices: *const &'a Value,
1520         NumIndices: c_uint,
1521         Name: *const c_char,
1522     ) -> &'a Value;
1523     pub fn LLVMBuildInBoundsGEP2<'a>(
1524         B: &Builder<'a>,
1525         Ty: &'a Type,
1526         Pointer: &'a Value,
1527         Indices: *const &'a Value,
1528         NumIndices: c_uint,
1529         Name: *const c_char,
1530     ) -> &'a Value;
1531     pub fn LLVMBuildStructGEP2<'a>(
1532         B: &Builder<'a>,
1533         Ty: &'a Type,
1534         Pointer: &'a Value,
1535         Idx: c_uint,
1536         Name: *const c_char,
1537     ) -> &'a Value;
1538
1539     // Casts
1540     pub fn LLVMBuildTrunc<'a>(
1541         B: &Builder<'a>,
1542         Val: &'a Value,
1543         DestTy: &'a Type,
1544         Name: *const c_char,
1545     ) -> &'a Value;
1546     pub fn LLVMBuildZExt<'a>(
1547         B: &Builder<'a>,
1548         Val: &'a Value,
1549         DestTy: &'a Type,
1550         Name: *const c_char,
1551     ) -> &'a Value;
1552     pub fn LLVMBuildSExt<'a>(
1553         B: &Builder<'a>,
1554         Val: &'a Value,
1555         DestTy: &'a Type,
1556         Name: *const c_char,
1557     ) -> &'a Value;
1558     pub fn LLVMBuildFPToUI<'a>(
1559         B: &Builder<'a>,
1560         Val: &'a Value,
1561         DestTy: &'a Type,
1562         Name: *const c_char,
1563     ) -> &'a Value;
1564     pub fn LLVMBuildFPToSI<'a>(
1565         B: &Builder<'a>,
1566         Val: &'a Value,
1567         DestTy: &'a Type,
1568         Name: *const c_char,
1569     ) -> &'a Value;
1570     pub fn LLVMBuildUIToFP<'a>(
1571         B: &Builder<'a>,
1572         Val: &'a Value,
1573         DestTy: &'a Type,
1574         Name: *const c_char,
1575     ) -> &'a Value;
1576     pub fn LLVMBuildSIToFP<'a>(
1577         B: &Builder<'a>,
1578         Val: &'a Value,
1579         DestTy: &'a Type,
1580         Name: *const c_char,
1581     ) -> &'a Value;
1582     pub fn LLVMBuildFPTrunc<'a>(
1583         B: &Builder<'a>,
1584         Val: &'a Value,
1585         DestTy: &'a Type,
1586         Name: *const c_char,
1587     ) -> &'a Value;
1588     pub fn LLVMBuildFPExt<'a>(
1589         B: &Builder<'a>,
1590         Val: &'a Value,
1591         DestTy: &'a Type,
1592         Name: *const c_char,
1593     ) -> &'a Value;
1594     pub fn LLVMBuildPtrToInt<'a>(
1595         B: &Builder<'a>,
1596         Val: &'a Value,
1597         DestTy: &'a Type,
1598         Name: *const c_char,
1599     ) -> &'a Value;
1600     pub fn LLVMBuildIntToPtr<'a>(
1601         B: &Builder<'a>,
1602         Val: &'a Value,
1603         DestTy: &'a Type,
1604         Name: *const c_char,
1605     ) -> &'a Value;
1606     pub fn LLVMBuildBitCast<'a>(
1607         B: &Builder<'a>,
1608         Val: &'a Value,
1609         DestTy: &'a Type,
1610         Name: *const c_char,
1611     ) -> &'a Value;
1612     pub fn LLVMBuildPointerCast<'a>(
1613         B: &Builder<'a>,
1614         Val: &'a Value,
1615         DestTy: &'a Type,
1616         Name: *const c_char,
1617     ) -> &'a Value;
1618     pub fn LLVMRustBuildIntCast<'a>(
1619         B: &Builder<'a>,
1620         Val: &'a Value,
1621         DestTy: &'a Type,
1622         IsSigned: bool,
1623     ) -> &'a Value;
1624
1625     // Comparisons
1626     pub fn LLVMBuildICmp<'a>(
1627         B: &Builder<'a>,
1628         Op: c_uint,
1629         LHS: &'a Value,
1630         RHS: &'a Value,
1631         Name: *const c_char,
1632     ) -> &'a Value;
1633     pub fn LLVMBuildFCmp<'a>(
1634         B: &Builder<'a>,
1635         Op: c_uint,
1636         LHS: &'a Value,
1637         RHS: &'a Value,
1638         Name: *const c_char,
1639     ) -> &'a Value;
1640
1641     // Miscellaneous instructions
1642     pub fn LLVMBuildPhi<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1643     pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &Value;
1644     pub fn LLVMRustBuildCall<'a>(
1645         B: &Builder<'a>,
1646         Ty: &'a Type,
1647         Fn: &'a Value,
1648         Args: *const &'a Value,
1649         NumArgs: c_uint,
1650         Bundle: Option<&OperandBundleDef<'a>>,
1651     ) -> &'a Value;
1652     pub fn LLVMRustBuildMemCpy<'a>(
1653         B: &Builder<'a>,
1654         Dst: &'a Value,
1655         DstAlign: c_uint,
1656         Src: &'a Value,
1657         SrcAlign: c_uint,
1658         Size: &'a Value,
1659         IsVolatile: bool,
1660     ) -> &'a Value;
1661     pub fn LLVMRustBuildMemMove<'a>(
1662         B: &Builder<'a>,
1663         Dst: &'a Value,
1664         DstAlign: c_uint,
1665         Src: &'a Value,
1666         SrcAlign: c_uint,
1667         Size: &'a Value,
1668         IsVolatile: bool,
1669     ) -> &'a Value;
1670     pub fn LLVMRustBuildMemSet<'a>(
1671         B: &Builder<'a>,
1672         Dst: &'a Value,
1673         DstAlign: c_uint,
1674         Val: &'a Value,
1675         Size: &'a Value,
1676         IsVolatile: bool,
1677     ) -> &'a Value;
1678     pub fn LLVMBuildSelect<'a>(
1679         B: &Builder<'a>,
1680         If: &'a Value,
1681         Then: &'a Value,
1682         Else: &'a Value,
1683         Name: *const c_char,
1684     ) -> &'a Value;
1685     pub fn LLVMBuildVAArg<'a>(
1686         B: &Builder<'a>,
1687         list: &'a Value,
1688         Ty: &'a Type,
1689         Name: *const c_char,
1690     ) -> &'a Value;
1691     pub fn LLVMBuildExtractElement<'a>(
1692         B: &Builder<'a>,
1693         VecVal: &'a Value,
1694         Index: &'a Value,
1695         Name: *const c_char,
1696     ) -> &'a Value;
1697     pub fn LLVMBuildInsertElement<'a>(
1698         B: &Builder<'a>,
1699         VecVal: &'a Value,
1700         EltVal: &'a Value,
1701         Index: &'a Value,
1702         Name: *const c_char,
1703     ) -> &'a Value;
1704     pub fn LLVMBuildShuffleVector<'a>(
1705         B: &Builder<'a>,
1706         V1: &'a Value,
1707         V2: &'a Value,
1708         Mask: &'a Value,
1709         Name: *const c_char,
1710     ) -> &'a Value;
1711     pub fn LLVMBuildExtractValue<'a>(
1712         B: &Builder<'a>,
1713         AggVal: &'a Value,
1714         Index: c_uint,
1715         Name: *const c_char,
1716     ) -> &'a Value;
1717     pub fn LLVMBuildInsertValue<'a>(
1718         B: &Builder<'a>,
1719         AggVal: &'a Value,
1720         EltVal: &'a Value,
1721         Index: c_uint,
1722         Name: *const c_char,
1723     ) -> &'a Value;
1724
1725     pub fn LLVMRustBuildVectorReduceFAdd<'a>(
1726         B: &Builder<'a>,
1727         Acc: &'a Value,
1728         Src: &'a Value,
1729     ) -> &'a Value;
1730     pub fn LLVMRustBuildVectorReduceFMul<'a>(
1731         B: &Builder<'a>,
1732         Acc: &'a Value,
1733         Src: &'a Value,
1734     ) -> &'a Value;
1735     pub fn LLVMRustBuildVectorReduceAdd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1736     pub fn LLVMRustBuildVectorReduceMul<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1737     pub fn LLVMRustBuildVectorReduceAnd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1738     pub fn LLVMRustBuildVectorReduceOr<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1739     pub fn LLVMRustBuildVectorReduceXor<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1740     pub fn LLVMRustBuildVectorReduceMin<'a>(
1741         B: &Builder<'a>,
1742         Src: &'a Value,
1743         IsSigned: bool,
1744     ) -> &'a Value;
1745     pub fn LLVMRustBuildVectorReduceMax<'a>(
1746         B: &Builder<'a>,
1747         Src: &'a Value,
1748         IsSigned: bool,
1749     ) -> &'a Value;
1750     pub fn LLVMRustBuildVectorReduceFMin<'a>(
1751         B: &Builder<'a>,
1752         Src: &'a Value,
1753         IsNaN: bool,
1754     ) -> &'a Value;
1755     pub fn LLVMRustBuildVectorReduceFMax<'a>(
1756         B: &Builder<'a>,
1757         Src: &'a Value,
1758         IsNaN: bool,
1759     ) -> &'a Value;
1760
1761     pub fn LLVMRustBuildMinNum<'a>(B: &Builder<'a>, LHS: &'a Value, LHS: &'a Value) -> &'a Value;
1762     pub fn LLVMRustBuildMaxNum<'a>(B: &Builder<'a>, LHS: &'a Value, LHS: &'a Value) -> &'a Value;
1763
1764     // Atomic Operations
1765     pub fn LLVMRustBuildAtomicLoad<'a>(
1766         B: &Builder<'a>,
1767         ElementType: &'a Type,
1768         PointerVal: &'a Value,
1769         Name: *const c_char,
1770         Order: AtomicOrdering,
1771     ) -> &'a Value;
1772
1773     pub fn LLVMRustBuildAtomicStore<'a>(
1774         B: &Builder<'a>,
1775         Val: &'a Value,
1776         Ptr: &'a Value,
1777         Order: AtomicOrdering,
1778     ) -> &'a Value;
1779
1780     pub fn LLVMRustBuildAtomicCmpXchg<'a>(
1781         B: &Builder<'a>,
1782         LHS: &'a Value,
1783         CMP: &'a Value,
1784         RHS: &'a Value,
1785         Order: AtomicOrdering,
1786         FailureOrder: AtomicOrdering,
1787         Weak: Bool,
1788     ) -> &'a Value;
1789
1790     pub fn LLVMBuildAtomicRMW<'a>(
1791         B: &Builder<'a>,
1792         Op: AtomicRmwBinOp,
1793         LHS: &'a Value,
1794         RHS: &'a Value,
1795         Order: AtomicOrdering,
1796         SingleThreaded: Bool,
1797     ) -> &'a Value;
1798
1799     pub fn LLVMRustBuildAtomicFence(
1800         B: &Builder<'_>,
1801         Order: AtomicOrdering,
1802         Scope: SynchronizationScope,
1803     );
1804
1805     /// Writes a module to the specified path. Returns 0 on success.
1806     pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
1807
1808     /// Creates a pass manager.
1809     pub fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>;
1810
1811     /// Creates a function-by-function pass manager
1812     pub fn LLVMCreateFunctionPassManagerForModule(M: &Module) -> &mut PassManager<'_>;
1813
1814     /// Disposes a pass manager.
1815     pub fn LLVMDisposePassManager<'a>(PM: &'a mut PassManager<'a>);
1816
1817     /// Runs a pass manager on a module.
1818     pub fn LLVMRunPassManager<'a>(PM: &PassManager<'a>, M: &'a Module) -> Bool;
1819
1820     pub fn LLVMInitializePasses();
1821
1822     pub fn LLVMTimeTraceProfilerInitialize();
1823
1824     pub fn LLVMTimeTraceProfilerFinishThread();
1825
1826     pub fn LLVMTimeTraceProfilerFinish(FileName: *const c_char);
1827
1828     pub fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);
1829
1830     pub fn LLVMRustPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
1831     pub fn LLVMRustPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
1832     pub fn LLVMRustPassManagerBuilderUseInlinerWithThreshold(
1833         PMB: &PassManagerBuilder,
1834         threshold: c_uint,
1835     );
1836     pub fn LLVMRustPassManagerBuilderPopulateModulePassManager(
1837         PMB: &PassManagerBuilder,
1838         PM: &PassManager<'_>,
1839     );
1840
1841     pub fn LLVMRustPassManagerBuilderPopulateFunctionPassManager(
1842         PMB: &PassManagerBuilder,
1843         PM: &PassManager<'_>,
1844     );
1845     pub fn LLVMRustPassManagerBuilderPopulateLTOPassManager(
1846         PMB: &PassManagerBuilder,
1847         PM: &PassManager<'_>,
1848         Internalize: Bool,
1849         RunInliner: Bool,
1850     );
1851     pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
1852         PMB: &PassManagerBuilder,
1853         PM: &PassManager<'_>,
1854     );
1855
1856     pub fn LLVMGetHostCPUFeatures() -> *mut c_char;
1857
1858     pub fn LLVMDisposeMessage(message: *mut c_char);
1859
1860     pub fn LLVMIsMultithreaded() -> Bool;
1861
1862     /// Returns a string describing the last error caused by an LLVMRust* call.
1863     pub fn LLVMRustGetLastError() -> *const c_char;
1864
1865     /// Print the pass timings since static dtors aren't picking them up.
1866     pub fn LLVMRustPrintPassTimings();
1867
1868     pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
1869
1870     pub fn LLVMStructSetBody<'a>(
1871         StructTy: &'a Type,
1872         ElementTypes: *const &'a Type,
1873         ElementCount: c_uint,
1874         Packed: Bool,
1875     );
1876
1877     /// Prepares inline assembly.
1878     pub fn LLVMRustInlineAsm(
1879         Ty: &Type,
1880         AsmString: *const c_char,
1881         AsmStringLen: size_t,
1882         Constraints: *const c_char,
1883         ConstraintsLen: size_t,
1884         SideEffects: Bool,
1885         AlignStack: Bool,
1886         Dialect: AsmDialect,
1887         CanThrow: Bool,
1888     ) -> &Value;
1889     pub fn LLVMRustInlineAsmVerify(
1890         Ty: &Type,
1891         Constraints: *const c_char,
1892         ConstraintsLen: size_t,
1893     ) -> bool;
1894
1895     #[allow(improper_ctypes)]
1896     pub fn LLVMRustCoverageWriteFilenamesSectionToBuffer(
1897         Filenames: *const *const c_char,
1898         FilenamesLen: size_t,
1899         BufferOut: &RustString,
1900     );
1901
1902     #[allow(improper_ctypes)]
1903     pub fn LLVMRustCoverageWriteMappingToBuffer(
1904         VirtualFileMappingIDs: *const c_uint,
1905         NumVirtualFileMappingIDs: c_uint,
1906         Expressions: *const coverage_map::CounterExpression,
1907         NumExpressions: c_uint,
1908         MappingRegions: *const coverageinfo::CounterMappingRegion,
1909         NumMappingRegions: c_uint,
1910         BufferOut: &RustString,
1911     );
1912
1913     pub fn LLVMRustCoverageCreatePGOFuncNameVar(F: &Value, FuncName: *const c_char) -> &Value;
1914     pub fn LLVMRustCoverageHashCString(StrVal: *const c_char) -> u64;
1915     pub fn LLVMRustCoverageHashByteArray(Bytes: *const c_char, NumBytes: size_t) -> u64;
1916
1917     #[allow(improper_ctypes)]
1918     pub fn LLVMRustCoverageWriteMapSectionNameToString(M: &Module, Str: &RustString);
1919
1920     #[allow(improper_ctypes)]
1921     pub fn LLVMRustCoverageWriteFuncSectionNameToString(M: &Module, Str: &RustString);
1922
1923     #[allow(improper_ctypes)]
1924     pub fn LLVMRustCoverageWriteMappingVarNameToString(Str: &RustString);
1925
1926     pub fn LLVMRustCoverageMappingVersion() -> u32;
1927     pub fn LLVMRustDebugMetadataVersion() -> u32;
1928     pub fn LLVMRustVersionMajor() -> u32;
1929     pub fn LLVMRustVersionMinor() -> u32;
1930     pub fn LLVMRustVersionPatch() -> u32;
1931
1932     /// Add LLVM module flags.
1933     ///
1934     /// In order for Rust-C LTO to work, module flags must be compatible with Clang. What
1935     /// "compatible" means depends on the merge behaviors involved.
1936     pub fn LLVMRustAddModuleFlag(
1937         M: &Module,
1938         merge_behavior: LLVMModFlagBehavior,
1939         name: *const c_char,
1940         value: u32,
1941     );
1942     pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool;
1943
1944     pub fn LLVMRustMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
1945
1946     pub fn LLVMRustDIBuilderCreate(M: &Module) -> &mut DIBuilder<'_>;
1947
1948     pub fn LLVMRustDIBuilderDispose<'a>(Builder: &'a mut DIBuilder<'a>);
1949
1950     pub fn LLVMRustDIBuilderFinalize(Builder: &DIBuilder<'_>);
1951
1952     pub fn LLVMRustDIBuilderCreateCompileUnit<'a>(
1953         Builder: &DIBuilder<'a>,
1954         Lang: c_uint,
1955         File: &'a DIFile,
1956         Producer: *const c_char,
1957         ProducerLen: size_t,
1958         isOptimized: bool,
1959         Flags: *const c_char,
1960         RuntimeVer: c_uint,
1961         SplitName: *const c_char,
1962         SplitNameLen: size_t,
1963         kind: DebugEmissionKind,
1964         DWOId: u64,
1965         SplitDebugInlining: bool,
1966     ) -> &'a DIDescriptor;
1967
1968     pub fn LLVMRustDIBuilderCreateFile<'a>(
1969         Builder: &DIBuilder<'a>,
1970         Filename: *const c_char,
1971         FilenameLen: size_t,
1972         Directory: *const c_char,
1973         DirectoryLen: size_t,
1974         CSKind: ChecksumKind,
1975         Checksum: *const c_char,
1976         ChecksumLen: size_t,
1977     ) -> &'a DIFile;
1978
1979     pub fn LLVMRustDIBuilderCreateSubroutineType<'a>(
1980         Builder: &DIBuilder<'a>,
1981         ParameterTypes: &'a DIArray,
1982     ) -> &'a DICompositeType;
1983
1984     pub fn LLVMRustDIBuilderCreateFunction<'a>(
1985         Builder: &DIBuilder<'a>,
1986         Scope: &'a DIDescriptor,
1987         Name: *const c_char,
1988         NameLen: size_t,
1989         LinkageName: *const c_char,
1990         LinkageNameLen: size_t,
1991         File: &'a DIFile,
1992         LineNo: c_uint,
1993         Ty: &'a DIType,
1994         ScopeLine: c_uint,
1995         Flags: DIFlags,
1996         SPFlags: DISPFlags,
1997         MaybeFn: Option<&'a Value>,
1998         TParam: &'a DIArray,
1999         Decl: Option<&'a DIDescriptor>,
2000     ) -> &'a DISubprogram;
2001
2002     pub fn LLVMRustDIBuilderCreateBasicType<'a>(
2003         Builder: &DIBuilder<'a>,
2004         Name: *const c_char,
2005         NameLen: size_t,
2006         SizeInBits: u64,
2007         Encoding: c_uint,
2008     ) -> &'a DIBasicType;
2009
2010     pub fn LLVMRustDIBuilderCreateTypedef<'a>(
2011         Builder: &DIBuilder<'a>,
2012         Type: &'a DIBasicType,
2013         Name: *const c_char,
2014         NameLen: size_t,
2015         File: &'a DIFile,
2016         LineNo: c_uint,
2017         Scope: Option<&'a DIScope>,
2018     ) -> &'a DIDerivedType;
2019
2020     pub fn LLVMRustDIBuilderCreatePointerType<'a>(
2021         Builder: &DIBuilder<'a>,
2022         PointeeTy: &'a DIType,
2023         SizeInBits: u64,
2024         AlignInBits: u32,
2025         AddressSpace: c_uint,
2026         Name: *const c_char,
2027         NameLen: size_t,
2028     ) -> &'a DIDerivedType;
2029
2030     pub fn LLVMRustDIBuilderCreateStructType<'a>(
2031         Builder: &DIBuilder<'a>,
2032         Scope: Option<&'a DIDescriptor>,
2033         Name: *const c_char,
2034         NameLen: size_t,
2035         File: &'a DIFile,
2036         LineNumber: c_uint,
2037         SizeInBits: u64,
2038         AlignInBits: u32,
2039         Flags: DIFlags,
2040         DerivedFrom: Option<&'a DIType>,
2041         Elements: &'a DIArray,
2042         RunTimeLang: c_uint,
2043         VTableHolder: Option<&'a DIType>,
2044         UniqueId: *const c_char,
2045         UniqueIdLen: size_t,
2046     ) -> &'a DICompositeType;
2047
2048     pub fn LLVMRustDIBuilderCreateMemberType<'a>(
2049         Builder: &DIBuilder<'a>,
2050         Scope: &'a DIDescriptor,
2051         Name: *const c_char,
2052         NameLen: size_t,
2053         File: &'a DIFile,
2054         LineNo: c_uint,
2055         SizeInBits: u64,
2056         AlignInBits: u32,
2057         OffsetInBits: u64,
2058         Flags: DIFlags,
2059         Ty: &'a DIType,
2060     ) -> &'a DIDerivedType;
2061
2062     pub fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
2063         Builder: &DIBuilder<'a>,
2064         Scope: &'a DIScope,
2065         Name: *const c_char,
2066         NameLen: size_t,
2067         File: &'a DIFile,
2068         LineNumber: c_uint,
2069         SizeInBits: u64,
2070         AlignInBits: u32,
2071         OffsetInBits: u64,
2072         Discriminant: Option<&'a Value>,
2073         Flags: DIFlags,
2074         Ty: &'a DIType,
2075     ) -> &'a DIType;
2076
2077     pub fn LLVMRustDIBuilderCreateLexicalBlock<'a>(
2078         Builder: &DIBuilder<'a>,
2079         Scope: &'a DIScope,
2080         File: &'a DIFile,
2081         Line: c_uint,
2082         Col: c_uint,
2083     ) -> &'a DILexicalBlock;
2084
2085     pub fn LLVMRustDIBuilderCreateLexicalBlockFile<'a>(
2086         Builder: &DIBuilder<'a>,
2087         Scope: &'a DIScope,
2088         File: &'a DIFile,
2089     ) -> &'a DILexicalBlock;
2090
2091     pub fn LLVMRustDIBuilderCreateStaticVariable<'a>(
2092         Builder: &DIBuilder<'a>,
2093         Context: Option<&'a DIScope>,
2094         Name: *const c_char,
2095         NameLen: size_t,
2096         LinkageName: *const c_char,
2097         LinkageNameLen: size_t,
2098         File: &'a DIFile,
2099         LineNo: c_uint,
2100         Ty: &'a DIType,
2101         isLocalToUnit: bool,
2102         Val: &'a Value,
2103         Decl: Option<&'a DIDescriptor>,
2104         AlignInBits: u32,
2105     ) -> &'a DIGlobalVariableExpression;
2106
2107     pub fn LLVMRustDIBuilderCreateVariable<'a>(
2108         Builder: &DIBuilder<'a>,
2109         Tag: c_uint,
2110         Scope: &'a DIDescriptor,
2111         Name: *const c_char,
2112         NameLen: size_t,
2113         File: &'a DIFile,
2114         LineNo: c_uint,
2115         Ty: &'a DIType,
2116         AlwaysPreserve: bool,
2117         Flags: DIFlags,
2118         ArgNo: c_uint,
2119         AlignInBits: u32,
2120     ) -> &'a DIVariable;
2121
2122     pub fn LLVMRustDIBuilderCreateArrayType<'a>(
2123         Builder: &DIBuilder<'a>,
2124         Size: u64,
2125         AlignInBits: u32,
2126         Ty: &'a DIType,
2127         Subscripts: &'a DIArray,
2128     ) -> &'a DIType;
2129
2130     pub fn LLVMRustDIBuilderGetOrCreateSubrange<'a>(
2131         Builder: &DIBuilder<'a>,
2132         Lo: i64,
2133         Count: i64,
2134     ) -> &'a DISubrange;
2135
2136     pub fn LLVMRustDIBuilderGetOrCreateArray<'a>(
2137         Builder: &DIBuilder<'a>,
2138         Ptr: *const Option<&'a DIDescriptor>,
2139         Count: c_uint,
2140     ) -> &'a DIArray;
2141
2142     pub fn LLVMRustDIBuilderInsertDeclareAtEnd<'a>(
2143         Builder: &DIBuilder<'a>,
2144         Val: &'a Value,
2145         VarInfo: &'a DIVariable,
2146         AddrOps: *const u64,
2147         AddrOpsCount: c_uint,
2148         DL: &'a DILocation,
2149         InsertAtEnd: &'a BasicBlock,
2150     ) -> &'a Value;
2151
2152     pub fn LLVMRustDIBuilderCreateEnumerator<'a>(
2153         Builder: &DIBuilder<'a>,
2154         Name: *const c_char,
2155         NameLen: size_t,
2156         Value: i64,
2157         IsUnsigned: bool,
2158     ) -> &'a DIEnumerator;
2159
2160     pub fn LLVMRustDIBuilderCreateEnumerationType<'a>(
2161         Builder: &DIBuilder<'a>,
2162         Scope: &'a DIScope,
2163         Name: *const c_char,
2164         NameLen: size_t,
2165         File: &'a DIFile,
2166         LineNumber: c_uint,
2167         SizeInBits: u64,
2168         AlignInBits: u32,
2169         Elements: &'a DIArray,
2170         ClassType: &'a DIType,
2171         IsScoped: bool,
2172     ) -> &'a DIType;
2173
2174     pub fn LLVMRustDIBuilderCreateUnionType<'a>(
2175         Builder: &DIBuilder<'a>,
2176         Scope: Option<&'a DIScope>,
2177         Name: *const c_char,
2178         NameLen: size_t,
2179         File: &'a DIFile,
2180         LineNumber: c_uint,
2181         SizeInBits: u64,
2182         AlignInBits: u32,
2183         Flags: DIFlags,
2184         Elements: Option<&'a DIArray>,
2185         RunTimeLang: c_uint,
2186         UniqueId: *const c_char,
2187         UniqueIdLen: size_t,
2188     ) -> &'a DIType;
2189
2190     pub fn LLVMRustDIBuilderCreateVariantPart<'a>(
2191         Builder: &DIBuilder<'a>,
2192         Scope: &'a DIScope,
2193         Name: *const c_char,
2194         NameLen: size_t,
2195         File: &'a DIFile,
2196         LineNo: c_uint,
2197         SizeInBits: u64,
2198         AlignInBits: u32,
2199         Flags: DIFlags,
2200         Discriminator: Option<&'a DIDerivedType>,
2201         Elements: &'a DIArray,
2202         UniqueId: *const c_char,
2203         UniqueIdLen: size_t,
2204     ) -> &'a DIDerivedType;
2205
2206     pub fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
2207
2208     pub fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>(
2209         Builder: &DIBuilder<'a>,
2210         Scope: Option<&'a DIScope>,
2211         Name: *const c_char,
2212         NameLen: size_t,
2213         Ty: &'a DIType,
2214     ) -> &'a DITemplateTypeParameter;
2215
2216     pub fn LLVMRustDIBuilderCreateNameSpace<'a>(
2217         Builder: &DIBuilder<'a>,
2218         Scope: Option<&'a DIScope>,
2219         Name: *const c_char,
2220         NameLen: size_t,
2221         ExportSymbols: bool,
2222     ) -> &'a DINameSpace;
2223
2224     pub fn LLVMRustDICompositeTypeReplaceArrays<'a>(
2225         Builder: &DIBuilder<'a>,
2226         CompositeType: &'a DIType,
2227         Elements: Option<&'a DIArray>,
2228         Params: Option<&'a DIArray>,
2229     );
2230
2231     pub fn LLVMRustDIBuilderCreateDebugLocation<'a>(
2232         Line: c_uint,
2233         Column: c_uint,
2234         Scope: &'a DIScope,
2235         InlinedAt: Option<&'a DILocation>,
2236     ) -> &'a DILocation;
2237     pub fn LLVMRustDIBuilderCreateOpDeref() -> u64;
2238     pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> u64;
2239
2240     #[allow(improper_ctypes)]
2241     pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
2242     #[allow(improper_ctypes)]
2243     pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
2244
2245     pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
2246
2247     pub fn LLVMRustPassKind(Pass: &Pass) -> PassKind;
2248     pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> Option<&'static mut Pass>;
2249     pub fn LLVMRustCreateAddressSanitizerFunctionPass(Recover: bool) -> &'static mut Pass;
2250     pub fn LLVMRustCreateModuleAddressSanitizerPass(Recover: bool) -> &'static mut Pass;
2251     pub fn LLVMRustCreateMemorySanitizerPass(
2252         TrackOrigins: c_int,
2253         Recover: bool,
2254     ) -> &'static mut Pass;
2255     pub fn LLVMRustCreateThreadSanitizerPass() -> &'static mut Pass;
2256     pub fn LLVMRustCreateHWAddressSanitizerPass(Recover: bool) -> &'static mut Pass;
2257     pub fn LLVMRustAddPass(PM: &PassManager<'_>, Pass: &'static mut Pass);
2258     pub fn LLVMRustAddLastExtensionPasses(
2259         PMB: &PassManagerBuilder,
2260         Passes: *const &'static mut Pass,
2261         NumPasses: size_t,
2262     );
2263
2264     pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
2265
2266     pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine);
2267     pub fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t;
2268     pub fn LLVMRustGetTargetFeature(
2269         T: &TargetMachine,
2270         Index: size_t,
2271         Feature: &mut *const c_char,
2272         Desc: &mut *const c_char,
2273     );
2274
2275     pub fn LLVMRustGetHostCPUName(len: *mut usize) -> *const c_char;
2276     pub fn LLVMRustCreateTargetMachine(
2277         Triple: *const c_char,
2278         CPU: *const c_char,
2279         Features: *const c_char,
2280         Abi: *const c_char,
2281         Model: CodeModel,
2282         Reloc: RelocModel,
2283         Level: CodeGenOptLevel,
2284         UseSoftFP: bool,
2285         FunctionSections: bool,
2286         DataSections: bool,
2287         UniqueSectionNames: bool,
2288         TrapUnreachable: bool,
2289         Singlethread: bool,
2290         AsmComments: bool,
2291         EmitStackSizeSection: bool,
2292         RelaxELFRelocations: bool,
2293         UseInitArray: bool,
2294         SplitDwarfFile: *const c_char,
2295     ) -> Option<&'static mut TargetMachine>;
2296     pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
2297     pub fn LLVMRustAddBuilderLibraryInfo<'a>(
2298         PMB: &'a PassManagerBuilder,
2299         M: &'a Module,
2300         DisableSimplifyLibCalls: bool,
2301     );
2302     pub fn LLVMRustConfigurePassManagerBuilder(
2303         PMB: &PassManagerBuilder,
2304         OptLevel: CodeGenOptLevel,
2305         MergeFunctions: bool,
2306         SLPVectorize: bool,
2307         LoopVectorize: bool,
2308         PrepareForThinLTO: bool,
2309         PGOGenPath: *const c_char,
2310         PGOUsePath: *const c_char,
2311         PGOSampleUsePath: *const c_char,
2312         SizeLevel: c_int,
2313     );
2314     pub fn LLVMRustAddLibraryInfo<'a>(
2315         PM: &PassManager<'a>,
2316         M: &'a Module,
2317         DisableSimplifyLibCalls: bool,
2318     );
2319     pub fn LLVMRustRunFunctionPassManager<'a>(PM: &PassManager<'a>, M: &'a Module);
2320     pub fn LLVMRustWriteOutputFile<'a>(
2321         T: &'a TargetMachine,
2322         PM: &PassManager<'a>,
2323         M: &'a Module,
2324         Output: *const c_char,
2325         DwoOutput: *const c_char,
2326         FileType: FileType,
2327     ) -> LLVMRustResult;
2328     pub fn LLVMRustOptimizeWithNewPassManager<'a>(
2329         M: &'a Module,
2330         TM: &'a TargetMachine,
2331         OptLevel: PassBuilderOptLevel,
2332         OptStage: OptStage,
2333         NoPrepopulatePasses: bool,
2334         VerifyIR: bool,
2335         UseThinLTOBuffers: bool,
2336         MergeFunctions: bool,
2337         UnrollLoops: bool,
2338         SLPVectorize: bool,
2339         LoopVectorize: bool,
2340         DisableSimplifyLibCalls: bool,
2341         EmitLifetimeMarkers: bool,
2342         SanitizerOptions: Option<&SanitizerOptions>,
2343         PGOGenPath: *const c_char,
2344         PGOUsePath: *const c_char,
2345         InstrumentCoverage: bool,
2346         InstrumentGCOV: bool,
2347         PGOSampleUsePath: *const c_char,
2348         DebugInfoForProfiling: bool,
2349         llvm_selfprofiler: *mut c_void,
2350         begin_callback: SelfProfileBeforePassCallback,
2351         end_callback: SelfProfileAfterPassCallback,
2352         ExtraPasses: *const c_char,
2353         ExtraPassesLen: size_t,
2354         LLVMPlugins: *const c_char,
2355         LLVMPluginsLen: size_t,
2356     ) -> LLVMRustResult;
2357     pub fn LLVMRustPrintModule(
2358         M: &Module,
2359         Output: *const c_char,
2360         Demangle: extern "C" fn(*const c_char, size_t, *mut c_char, size_t) -> size_t,
2361     ) -> LLVMRustResult;
2362     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2363     pub fn LLVMRustPrintPasses();
2364     pub fn LLVMRustGetInstructionCount(M: &Module) -> u32;
2365     pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
2366     pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
2367     pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
2368
2369     pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
2370     pub fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
2371     pub fn LLVMRustArchiveIteratorNext<'a>(
2372         AIR: &ArchiveIterator<'a>,
2373     ) -> Option<&'a mut ArchiveChild<'a>>;
2374     pub fn LLVMRustArchiveChildName(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
2375     pub fn LLVMRustArchiveChildData(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
2376     pub fn LLVMRustArchiveChildFree<'a>(ACR: &'a mut ArchiveChild<'a>);
2377     pub fn LLVMRustArchiveIteratorFree<'a>(AIR: &'a mut ArchiveIterator<'a>);
2378     pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
2379
2380     #[allow(improper_ctypes)]
2381     pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
2382
2383     #[allow(improper_ctypes)]
2384     pub fn LLVMRustUnpackOptimizationDiagnostic<'a>(
2385         DI: &'a DiagnosticInfo,
2386         pass_name_out: &RustString,
2387         function_out: &mut Option<&'a Value>,
2388         loc_line_out: &mut c_uint,
2389         loc_column_out: &mut c_uint,
2390         loc_filename_out: &RustString,
2391         message_out: &RustString,
2392     );
2393
2394     pub fn LLVMRustUnpackInlineAsmDiagnostic<'a>(
2395         DI: &'a DiagnosticInfo,
2396         level_out: &mut DiagnosticLevel,
2397         cookie_out: &mut c_uint,
2398         message_out: &mut Option<&'a Twine>,
2399     );
2400
2401     #[allow(improper_ctypes)]
2402     pub fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
2403     pub fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
2404
2405     pub fn LLVMRustGetSMDiagnostic<'a>(
2406         DI: &'a DiagnosticInfo,
2407         cookie_out: &mut c_uint,
2408     ) -> &'a SMDiagnostic;
2409
2410     pub fn LLVMRustSetInlineAsmDiagnosticHandler(
2411         C: &Context,
2412         H: InlineAsmDiagHandlerTy,
2413         CX: *mut c_void,
2414     );
2415
2416     #[allow(improper_ctypes)]
2417     pub fn LLVMRustUnpackSMDiagnostic(
2418         d: &SMDiagnostic,
2419         message_out: &RustString,
2420         buffer_out: &RustString,
2421         level_out: &mut DiagnosticLevel,
2422         loc_out: &mut c_uint,
2423         ranges_out: *mut c_uint,
2424         num_ranges: &mut usize,
2425     ) -> bool;
2426
2427     pub fn LLVMRustWriteArchive(
2428         Dst: *const c_char,
2429         NumMembers: size_t,
2430         Members: *const &RustArchiveMember<'_>,
2431         WriteSymbtab: bool,
2432         Kind: ArchiveKind,
2433     ) -> LLVMRustResult;
2434     pub fn LLVMRustArchiveMemberNew<'a>(
2435         Filename: *const c_char,
2436         Name: *const c_char,
2437         Child: Option<&ArchiveChild<'a>>,
2438     ) -> &'a mut RustArchiveMember<'a>;
2439     pub fn LLVMRustArchiveMemberFree<'a>(Member: &'a mut RustArchiveMember<'a>);
2440
2441     pub fn LLVMRustWriteImportLibrary(
2442         ImportName: *const c_char,
2443         Path: *const c_char,
2444         Exports: *const LLVMRustCOFFShortExport,
2445         NumExports: usize,
2446         Machine: u16,
2447         MinGW: bool,
2448     ) -> LLVMRustResult;
2449
2450     pub fn LLVMRustSetDataLayoutFromTargetMachine<'a>(M: &'a Module, TM: &'a TargetMachine);
2451
2452     pub fn LLVMRustBuildOperandBundleDef<'a>(
2453         Name: *const c_char,
2454         Inputs: *const &'a Value,
2455         NumInputs: c_uint,
2456     ) -> &'a mut OperandBundleDef<'a>;
2457     pub fn LLVMRustFreeOperandBundleDef<'a>(Bundle: &'a mut OperandBundleDef<'a>);
2458
2459     pub fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock);
2460
2461     pub fn LLVMRustSetComdat<'a>(M: &'a Module, V: &'a Value, Name: *const c_char, NameLen: size_t);
2462     pub fn LLVMRustUnsetComdat(V: &Value);
2463     pub fn LLVMRustSetModulePICLevel(M: &Module);
2464     pub fn LLVMRustSetModulePIELevel(M: &Module);
2465     pub fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel);
2466     pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
2467     pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
2468     pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
2469     pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
2470     pub fn LLVMRustModuleCost(M: &Module) -> u64;
2471
2472     pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> &'static mut ThinLTOBuffer;
2473     pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
2474     pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
2475     pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
2476     pub fn LLVMRustCreateThinLTOData(
2477         Modules: *const ThinLTOModule,
2478         NumModules: c_uint,
2479         PreservedSymbols: *const *const c_char,
2480         PreservedSymbolsLen: c_uint,
2481     ) -> Option<&'static mut ThinLTOData>;
2482     pub fn LLVMRustPrepareThinLTORename(
2483         Data: &ThinLTOData,
2484         Module: &Module,
2485         Target: &TargetMachine,
2486     ) -> bool;
2487     pub fn LLVMRustPrepareThinLTOResolveWeak(Data: &ThinLTOData, Module: &Module) -> bool;
2488     pub fn LLVMRustPrepareThinLTOInternalize(Data: &ThinLTOData, Module: &Module) -> bool;
2489     pub fn LLVMRustPrepareThinLTOImport(
2490         Data: &ThinLTOData,
2491         Module: &Module,
2492         Target: &TargetMachine,
2493     ) -> bool;
2494     pub fn LLVMRustGetThinLTOModuleImports(
2495         Data: *const ThinLTOData,
2496         ModuleNameCallback: ThinLTOModuleNameCallback,
2497         CallbackPayload: *mut c_void,
2498     );
2499     pub fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
2500     pub fn LLVMRustParseBitcodeForLTO(
2501         Context: &Context,
2502         Data: *const u8,
2503         len: usize,
2504         Identifier: *const c_char,
2505     ) -> Option<&Module>;
2506     pub fn LLVMRustGetBitcodeSliceFromObjectData(
2507         Data: *const u8,
2508         len: usize,
2509         out_len: &mut usize,
2510     ) -> *const u8;
2511     pub fn LLVMRustThinLTOGetDICompileUnit(
2512         M: &Module,
2513         CU1: &mut *mut c_void,
2514         CU2: &mut *mut c_void,
2515     );
2516     pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
2517
2518     pub fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
2519     pub fn LLVMRustLinkerAdd(
2520         linker: &Linker<'_>,
2521         bytecode: *const c_char,
2522         bytecode_len: usize,
2523     ) -> bool;
2524     pub fn LLVMRustLinkerFree<'a>(linker: &'a mut Linker<'a>);
2525     #[allow(improper_ctypes)]
2526     pub fn LLVMRustComputeLTOCacheKey(
2527         key_out: &RustString,
2528         mod_id: *const c_char,
2529         data: &ThinLTOData,
2530     );
2531
2532     pub fn LLVMRustContextGetDiagnosticHandler(Context: &Context) -> Option<&DiagnosticHandler>;
2533     pub fn LLVMRustContextSetDiagnosticHandler(
2534         context: &Context,
2535         diagnostic_handler: Option<&DiagnosticHandler>,
2536     );
2537     pub fn LLVMRustContextConfigureDiagnosticHandler(
2538         context: &Context,
2539         diagnostic_handler_callback: DiagnosticHandlerTy,
2540         diagnostic_handler_context: *mut c_void,
2541         remark_all_passes: bool,
2542         remark_passes: *const *const c_char,
2543         remark_passes_len: usize,
2544     );
2545
2546     #[allow(improper_ctypes)]
2547     pub fn LLVMRustGetMangledName(V: &Value, out: &RustString);
2548 }