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