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