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