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