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