]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_llvm/src/llvm/ffi.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / compiler / rustc_codegen_llvm / src / llvm / ffi.rs
CommitLineData
416331ca
XL
1#![allow(non_camel_case_types)]
2#![allow(non_upper_case_globals)]
3
3dfed10e
XL
4use rustc_codegen_ssa::coverageinfo::map as coverage_map;
5
b7449926 6use super::debuginfo::{
dfeec247 7 DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
29967ef6
XL
8 DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace,
9 DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable,
10 DebugEmissionKind,
b7449926
XL
11};
12
dfeec247 13use libc::{c_char, c_int, c_uint, size_t};
b7449926
XL
14use libc::{c_ulonglong, c_void};
15
16use std::marker::PhantomData;
17
18use super::RustString;
19
20pub type Bool = c_uint;
21
22pub const True: Bool = 1 as Bool;
23pub const False: Bool = 0 as Bool;
24
25#[derive(Copy, Clone, PartialEq)]
26#[repr(C)]
27#[allow(dead_code)] // Variants constructed by C++.
28pub enum LLVMRustResult {
29 Success,
30 Failure,
31}
17df50a5
XL
32
33// Rust version of the C struct with the same name in rustc_llvm/llvm-wrapper/RustWrapper.cpp.
34#[repr(C)]
35pub struct LLVMRustCOFFShortExport {
36 pub name: *const c_char,
c295e0f8 37 pub ordinal_present: bool,
487cf647 38 /// value of `ordinal` only important when `ordinal_present` is true
c295e0f8 39 pub ordinal: u16,
17df50a5
XL
40}
41
42impl LLVMRustCOFFShortExport {
c295e0f8
XL
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 }
17df50a5
XL
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)]
57pub enum LLVMMachineType {
58 AMD64 = 0x8664,
59 I386 = 0x14c,
60 ARM64 = 0xaa64,
61 ARM = 0x01c0,
62}
63
5099ac24
FG
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)]
74pub enum LLVMModFlagBehavior {
75 Error = 1,
76 Warning = 2,
77 Require = 3,
78 Override = 4,
79 Append = 5,
80 AppendUnique = 6,
81 Max = 7,
9c376795 82 Min = 8,
5099ac24
FG
83}
84
b7449926
XL
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)]
90pub 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,
f035d41b
XL
104 AvrNonBlockingInterrupt = 84,
105 AvrInterrupt = 85,
b7449926
XL
106 AmdGpuKernel = 91,
107}
108
109/// LLVMRustLinkage
17df50a5 110#[derive(Copy, Clone, PartialEq)]
b7449926
XL
111#[repr(C)]
112pub 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
b7449926 127#[repr(C)]
17df50a5 128#[derive(Copy, Clone, PartialEq)]
b7449926
XL
129pub enum Visibility {
130 Default = 0,
131 Hidden = 1,
132 Protected = 2,
133}
134
ba9703b0
XL
135/// LLVMUnnamedAddr
136#[repr(C)]
137pub enum UnnamedAddr {
138 No,
139 Local,
140 Global,
141}
142
b7449926
XL
143/// LLVMDLLStorageClass
144#[derive(Copy, Clone)]
145#[repr(C)]
146pub 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
1b1a35ee 154/// Matches LLVMRustAttribute in LLVMWrapper.h
b7449926
XL
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)]
5e7ed085 159pub enum AttributeKind {
dfeec247
XL
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,
b7449926 173 OptimizeForSize = 13,
dfeec247
XL
174 ReadOnly = 14,
175 SExt = 15,
176 StructRet = 16,
177 UWTable = 17,
178 ZExt = 18,
179 InReg = 19,
180 SanitizeThread = 20,
b7449926 181 SanitizeAddress = 21,
dfeec247
XL
182 SanitizeMemory = 22,
183 NonLazyBind = 23,
184 OptimizeNone = 24,
185 ReturnsTwice = 25,
f9f354fc 186 ReadNone = 26,
6a06907d
XL
187 SanitizeHWAddress = 28,
188 WillReturn = 29,
3c0e092e
XL
189 StackProtectReq = 30,
190 StackProtectStrong = 31,
191 StackProtect = 32,
5099ac24
FG
192 NoUndef = 33,
193 SanitizeMemTag = 34,
064997fb
FG
194 NoCfCheck = 35,
195 ShadowCallStack = 36,
196 AllocSize = 37,
197 AllocatedPointer = 38,
198 AllocAlign = 39,
b7449926
XL
199}
200
201/// LLVMIntPredicate
202#[derive(Copy, Clone)]
203#[repr(C)]
204pub 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
a1dfa0c6
XL
217impl 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
b7449926
XL
234/// LLVMRealPredicate
235#[derive(Copy, Clone)]
236#[repr(C)]
237pub 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
c295e0f8
XL
256impl 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
b7449926
XL
283/// LLVMTypeKind
284#[derive(Copy, Clone, PartialEq, Debug)]
285#[repr(C)]
286pub 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,
f035d41b
XL
304 ScalableVector = 17,
305 BFloat = 18,
6a06907d 306 X86_AMX = 19,
b7449926
XL
307}
308
a1dfa0c6
XL
309impl 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,
f035d41b
XL
329 TypeKind::ScalableVector => rustc_codegen_ssa::common::TypeKind::ScalableVector,
330 TypeKind::BFloat => rustc_codegen_ssa::common::TypeKind::BFloat,
6a06907d 331 TypeKind::X86_AMX => rustc_codegen_ssa::common::TypeKind::X86_AMX,
a1dfa0c6
XL
332 }
333 }
334}
335
b7449926
XL
336/// LLVMAtomicRmwBinOp
337#[derive(Copy, Clone)]
338#[repr(C)]
339pub 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
a1dfa0c6
XL
353impl 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,
dfeec247 366 rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMin => AtomicRmwBinOp::AtomicUMin,
a1dfa0c6
XL
367 }
368 }
369}
370
b7449926
XL
371/// LLVMAtomicOrdering
372#[derive(Copy, Clone)]
373#[repr(C)]
374pub 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
a1dfa0c6
XL
386impl AtomicOrdering {
387 pub fn from_generic(ao: rustc_codegen_ssa::common::AtomicOrdering) -> Self {
388 match ao {
a1dfa0c6 389 rustc_codegen_ssa::common::AtomicOrdering::Unordered => AtomicOrdering::Unordered,
923072b8 390 rustc_codegen_ssa::common::AtomicOrdering::Relaxed => AtomicOrdering::Monotonic,
a1dfa0c6
XL
391 rustc_codegen_ssa::common::AtomicOrdering::Acquire => AtomicOrdering::Acquire,
392 rustc_codegen_ssa::common::AtomicOrdering::Release => AtomicOrdering::Release,
dfeec247
XL
393 rustc_codegen_ssa::common::AtomicOrdering::AcquireRelease => {
394 AtomicOrdering::AcquireRelease
395 }
396 rustc_codegen_ssa::common::AtomicOrdering::SequentiallyConsistent => {
a1dfa0c6 397 AtomicOrdering::SequentiallyConsistent
dfeec247 398 }
a1dfa0c6
XL
399 }
400 }
401}
402
b7449926
XL
403/// LLVMRustFileType
404#[derive(Copy, Clone)]
405#[repr(C)]
406pub enum FileType {
b7449926
XL
407 AssemblyFile,
408 ObjectFile,
409}
410
411/// LLVMMetadataType
412#[derive(Copy, Clone)]
413#[repr(C)]
414pub 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,
5e7ed085 427 MD_align = 17,
3c0e092e 428 MD_type = 19,
923072b8 429 MD_vcall_visibility = 28,
5e7ed085 430 MD_noundef = 29,
9c376795 431 MD_kcfi_type = 36,
b7449926
XL
432}
433
434/// LLVMRustAsmDialect
5099ac24 435#[derive(Copy, Clone, PartialEq)]
b7449926
XL
436#[repr(C)]
437pub enum AsmDialect {
b7449926
XL
438 Att,
439 Intel,
440}
441
442/// LLVMRustCodeGenOptLevel
443#[derive(Copy, Clone, PartialEq)]
444#[repr(C)]
445pub enum CodeGenOptLevel {
b7449926
XL
446 None,
447 Less,
448 Default,
449 Aggressive,
450}
451
74b04a01
XL
452/// LLVMRustPassBuilderOptLevel
453#[repr(C)]
454pub enum PassBuilderOptLevel {
455 O0,
456 O1,
457 O2,
458 O3,
459 Os,
460 Oz,
461}
462
463/// LLVMRustOptStage
464#[derive(PartialEq)]
465#[repr(C)]
466pub enum OptStage {
467 PreLinkNoLTO,
468 PreLinkThinLTO,
469 PreLinkFatLTO,
470 ThinLTO,
471 FatLTO,
472}
473
474/// LLVMRustSanitizerOptions
475#[repr(C)]
476pub struct SanitizerOptions {
74b04a01 477 pub sanitize_address: bool,
f035d41b
XL
478 pub sanitize_address_recover: bool,
479 pub sanitize_memory: bool,
480 pub sanitize_memory_recover: bool,
74b04a01 481 pub sanitize_memory_track_origins: c_int,
f035d41b 482 pub sanitize_thread: bool,
6a06907d
XL
483 pub sanitize_hwaddress: bool,
484 pub sanitize_hwaddress_recover: bool,
9ffffee4
FG
485 pub sanitize_kernel_address: bool,
486 pub sanitize_kernel_address_recover: bool,
74b04a01
XL
487}
488
b7449926
XL
489/// LLVMRelocMode
490#[derive(Copy, Clone, PartialEq)]
491#[repr(C)]
f9f354fc 492pub enum RelocModel {
b7449926
XL
493 Static,
494 PIC,
495 DynamicNoPic,
496 ROPI,
497 RWPI,
498 ROPI_RWPI,
499}
500
501/// LLVMRustCodeModel
502#[derive(Copy, Clone)]
503#[repr(C)]
504pub enum CodeModel {
f9f354fc 505 Tiny,
b7449926
XL
506 Small,
507 Kernel,
508 Medium,
509 Large,
510 None,
511}
512
513/// LLVMRustDiagnosticKind
514#[derive(Copy, Clone)]
515#[repr(C)]
516#[allow(dead_code)] // Variants constructed by C++.
517pub enum DiagnosticKind {
518 Other,
519 InlineAsm,
520 StackSize,
521 DebugMetadataVersion,
522 SampleProfile,
523 OptimizationRemark,
524 OptimizationRemarkMissed,
525 OptimizationRemarkAnalysis,
526 OptimizationRemarkAnalysisFPCommute,
527 OptimizationRemarkAnalysisAliasing,
528 OptimizationRemarkOther,
529 OptimizationFailure,
530 PGOProfile,
531 Linker,
1b1a35ee 532 Unsupported,
94222f64 533 SrcMgr,
b7449926
XL
534}
535
f035d41b
XL
536/// LLVMRustDiagnosticLevel
537#[derive(Copy, Clone)]
538#[repr(C)]
539#[allow(dead_code)] // Variants constructed by C++.
540pub enum DiagnosticLevel {
541 Error,
542 Warning,
543 Note,
544 Remark,
545}
546
b7449926
XL
547/// LLVMRustArchiveKind
548#[derive(Copy, Clone)]
549#[repr(C)]
550pub enum ArchiveKind {
b7449926
XL
551 K_GNU,
552 K_BSD,
74b04a01 553 K_DARWIN,
b7449926
XL
554 K_COFF,
555}
556
5e7ed085 557// LLVMRustThinLTOData
dfeec247
XL
558extern "C" {
559 pub type ThinLTOData;
560}
b7449926 561
5e7ed085 562// LLVMRustThinLTOBuffer
dfeec247
XL
563extern "C" {
564 pub type ThinLTOBuffer;
565}
b7449926 566
b7449926
XL
567/// LLVMRustThinLTOModule
568#[repr(C)]
569pub struct ThinLTOModule {
570 pub identifier: *const c_char,
571 pub data: *const u8,
572 pub len: usize,
573}
574
575/// LLVMThreadLocalMode
576#[derive(Copy, Clone)]
577#[repr(C)]
578pub enum ThreadLocalMode {
dfeec247
XL
579 NotThreadLocal,
580 GeneralDynamic,
581 LocalDynamic,
582 InitialExec,
583 LocalExec,
b7449926
XL
584}
585
ba9703b0
XL
586/// LLVMRustChecksumKind
587#[derive(Copy, Clone)]
588#[repr(C)]
589pub enum ChecksumKind {
590 None,
591 MD5,
592 SHA1,
29967ef6 593 SHA256,
ba9703b0
XL
594}
595
487cf647
FG
596/// LLVMRustMemoryEffects
597#[derive(Copy, Clone)]
598#[repr(C)]
599pub enum MemoryEffects {
600 None,
601 ReadOnly,
602 InaccessibleMemOnly,
603}
604
dfeec247
XL
605extern "C" {
606 type Opaque;
607}
b7449926
XL
608#[repr(C)]
609struct InvariantOpaque<'a> {
610 _marker: PhantomData<&'a mut &'a ()>,
611 _opaque: Opaque,
612}
613
614// Opaque pointer types
dfeec247
XL
615extern "C" {
616 pub type Module;
617}
618extern "C" {
619 pub type Context;
620}
621extern "C" {
622 pub type Type;
623}
624extern "C" {
625 pub type Value;
626}
627extern "C" {
628 pub type ConstantInt;
629}
5e7ed085
FG
630extern "C" {
631 pub type Attribute;
632}
dfeec247
XL
633extern "C" {
634 pub type Metadata;
635}
636extern "C" {
637 pub type BasicBlock;
638}
b7449926
XL
639#[repr(C)]
640pub struct Builder<'a>(InvariantOpaque<'a>);
b7449926
XL
641#[repr(C)]
642pub struct PassManager<'a>(InvariantOpaque<'a>);
dfeec247
XL
643extern "C" {
644 pub type Pass;
645}
646extern "C" {
647 pub type TargetMachine;
648}
649extern "C" {
650 pub type Archive;
651}
b7449926
XL
652#[repr(C)]
653pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
654#[repr(C)]
655pub struct ArchiveChild<'a>(InvariantOpaque<'a>);
dfeec247
XL
656extern "C" {
657 pub type Twine;
658}
659extern "C" {
660 pub type DiagnosticInfo;
661}
662extern "C" {
663 pub type SMDiagnostic;
664}
b7449926
XL
665#[repr(C)]
666pub struct RustArchiveMember<'a>(InvariantOpaque<'a>);
667#[repr(C)]
668pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
669#[repr(C)]
670pub struct Linker<'a>(InvariantOpaque<'a>);
671
a2a8927a
XL
672extern "C" {
673 pub type DiagnosticHandler;
674}
675
676pub type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
677pub type InlineAsmDiagHandlerTy = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
b7449926 678
3dfed10e
XL
679pub mod coverageinfo {
680 use super::coverage_map;
681
a2a8927a 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)
3dfed10e
XL
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,
a2a8927a
XL
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,
3dfed10e
XL
706 }
707
708 /// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the
709 /// coverage map, in accordance with the
a2a8927a 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).
3dfed10e
XL
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 ///
6a06907d 716 /// Matches LLVMRustCounterMappingRegion.
3dfed10e
XL
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
a2a8927a
XL
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
3dfed10e
XL
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 {
923072b8 754 pub(crate) fn code_region(
3dfed10e
XL
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,
a2a8927a 764 false_counter: coverage_map::Counter::zero(),
3dfed10e
XL
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
a2a8927a
XL
775 // This function might be used in the future; the LLVM API is still evolving, as is coverage
776 // support.
777 #[allow(dead_code)]
923072b8 778 pub(crate) fn branch_region(
a2a8927a
XL
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
cdc7bbd5
XL
800 // This function might be used in the future; the LLVM API is still evolving, as is coverage
801 // support.
802 #[allow(dead_code)]
923072b8 803 pub(crate) fn expansion_region(
3dfed10e
XL
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(),
a2a8927a 813 false_counter: coverage_map::Counter::zero(),
3dfed10e
XL
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
cdc7bbd5
XL
824 // This function might be used in the future; the LLVM API is still evolving, as is coverage
825 // support.
826 #[allow(dead_code)]
923072b8 827 pub(crate) fn skipped_region(
3dfed10e
XL
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(),
a2a8927a 836 false_counter: coverage_map::Counter::zero(),
3dfed10e
XL
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
cdc7bbd5
XL
847 // This function might be used in the future; the LLVM API is still evolving, as is coverage
848 // support.
849 #[allow(dead_code)]
923072b8 850 pub(crate) fn gap_region(
3dfed10e
XL
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,
a2a8927a 860 false_counter: coverage_map::Counter::zero(),
3dfed10e
XL
861 file_id,
862 expanded_file_id: 0,
863 start_line,
864 start_col,
865 end_line,
c295e0f8 866 end_col: (1_u32 << 31) | end_col,
3dfed10e
XL
867 kind: RegionKind::GapRegion,
868 }
869 }
870 }
871}
872
b7449926
XL
873pub mod debuginfo {
874 use super::{InvariantOpaque, Metadata};
60c5eb7d 875 use bitflags::bitflags;
b7449926
XL
876
877 #[repr(C)]
878 pub struct DIBuilder<'a>(InvariantOpaque<'a>);
879
880 pub type DIDescriptor = Metadata;
29967ef6 881 pub type DILocation = Metadata;
b7449926
XL
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;
0bf4aa26 892 pub type DIGlobalVariableExpression = DIDescriptor;
b7449926
XL
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! {
dc9dc135 900 #[repr(transparent)]
b7449926 901 #[derive(Default)]
416331ca 902 pub struct DIFlags: u32 {
b7449926
XL
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);
b7449926
XL
924 }
925 }
9fa01778
XL
926
927 // These values **must** match with LLVMRustDISPFlags!!
928 bitflags! {
dc9dc135 929 #[repr(transparent)]
9fa01778 930 #[derive(Default)]
416331ca 931 pub struct DISPFlags: u32 {
9fa01778
XL
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);
532ac7d7 938 const SPFlagMainSubprogram = (1 << 5);
9fa01778
XL
939 }
940 }
941
942 /// LLVMRustDebugEmissionKind
943 #[derive(Copy, Clone)]
944 #[repr(C)]
945 pub enum DebugEmissionKind {
946 NoDebug,
947 FullDebug,
948 LineTablesOnly,
353b0b11 949 DebugDirectivesOnly,
9fa01778
XL
950 }
951
952 impl DebugEmissionKind {
ba9703b0 953 pub fn from_generic(kind: rustc_session::config::DebugInfo) -> Self {
353b0b11
FG
954 // We should be setting LLVM's emission kind to `LineTablesOnly` if
955 // we are compiling with "limited" debuginfo. However, some of the
956 // existing tools relied on slightly more debuginfo being generated than
957 // would be the case with `LineTablesOnly`, and we did not want to break
958 // these tools in a "drive-by fix", without a good idea or plan about
959 // what limited debuginfo should exactly look like. So for now we are
960 // instead adding a new debuginfo option "line-tables-only" so as to
961 // not break anything and to allow users to have 'limited' debug info.
962 //
963 // See https://github.com/rust-lang/rust/issues/60020 for details.
ba9703b0 964 use rustc_session::config::DebugInfo;
9fa01778
XL
965 match kind {
966 DebugInfo::None => DebugEmissionKind::NoDebug,
353b0b11
FG
967 DebugInfo::LineDirectivesOnly => DebugEmissionKind::DebugDirectivesOnly,
968 DebugInfo::LineTablesOnly => DebugEmissionKind::LineTablesOnly,
969 DebugInfo::Limited | DebugInfo::Full => DebugEmissionKind::FullDebug,
9fa01778
XL
970 }
971 }
972 }
b7449926
XL
973}
974
064997fb
FG
975use bitflags::bitflags;
976// These values **must** match with LLVMRustAllocKindFlags
977bitflags! {
978 #[repr(transparent)]
979 #[derive(Default)]
980 pub struct AllocKindFlags : u64 {
981 const Unknown = 0;
982 const Alloc = 1;
983 const Realloc = 1 << 1;
984 const Free = 1 << 2;
985 const Uninitialized = 1 << 3;
986 const Zeroed = 1 << 4;
987 const Aligned = 1 << 5;
988 }
989}
990
dfeec247
XL
991extern "C" {
992 pub type ModuleBuffer;
993}
b7449926 994
74b04a01
XL
995pub type SelfProfileBeforePassCallback =
996 unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);
997pub type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void);
998
487cf647
FG
999pub type GetSymbolsCallback = unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void;
1000pub type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void;
1001
b7449926 1002extern "C" {
0bf4aa26 1003 pub fn LLVMRustInstallFatalErrorHandler();
5099ac24 1004 pub fn LLVMRustDisableSystemDialogsOnCrash();
0bf4aa26 1005
b7449926
XL
1006 // Create and destroy contexts.
1007 pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
1008 pub fn LLVMContextDispose(C: &'static mut Context);
1009 pub fn LLVMGetMDKindIDInContext(C: &Context, Name: *const c_char, SLen: c_uint) -> c_uint;
1010
1011 // Create modules.
1012 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char, C: &Context) -> &Module;
1013 pub fn LLVMGetModuleContext(M: &Module) -> &Context;
1014 pub fn LLVMCloneModule(M: &Module) -> &Module;
1015
1016 /// Data layout. See Module::getDataLayout.
ba9703b0 1017 pub fn LLVMGetDataLayoutStr(M: &Module) -> *const c_char;
b7449926
XL
1018 pub fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);
1019
1020 /// See Module::setModuleInlineAsm.
353b0b11 1021 pub fn LLVMAppendModuleInlineAsm(M: &Module, Asm: *const c_char, Len: size_t);
b7449926
XL
1022
1023 /// See llvm::LLVMTypeKind::getTypeID.
1024 pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
1025
1026 // Operations on integer types
1027 pub fn LLVMInt1TypeInContext(C: &Context) -> &Type;
1028 pub fn LLVMInt8TypeInContext(C: &Context) -> &Type;
1029 pub fn LLVMInt16TypeInContext(C: &Context) -> &Type;
1030 pub fn LLVMInt32TypeInContext(C: &Context) -> &Type;
1031 pub fn LLVMInt64TypeInContext(C: &Context) -> &Type;
1032 pub fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type;
1033
1034 pub fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint;
1035
1036 // Operations on real types
1037 pub fn LLVMFloatTypeInContext(C: &Context) -> &Type;
1038 pub fn LLVMDoubleTypeInContext(C: &Context) -> &Type;
1039
1040 // Operations on function types
a2a8927a 1041 pub fn LLVMFunctionType<'a>(
dfeec247
XL
1042 ReturnType: &'a Type,
1043 ParamTypes: *const &'a Type,
1044 ParamCount: c_uint,
1045 IsVarArg: Bool,
1046 ) -> &'a Type;
b7449926 1047 pub fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint;
a2a8927a 1048 pub fn LLVMGetParamTypes<'a>(FunctionTy: &'a Type, Dest: *mut &'a Type);
b7449926
XL
1049
1050 // Operations on struct types
a2a8927a 1051 pub fn LLVMStructTypeInContext<'a>(
dfeec247
XL
1052 C: &'a Context,
1053 ElementTypes: *const &'a Type,
1054 ElementCount: c_uint,
1055 Packed: Bool,
1056 ) -> &'a Type;
b7449926
XL
1057
1058 // Operations on array, pointer, and vector types (sequence types)
1059 pub fn LLVMRustArrayType(ElementType: &Type, ElementCount: u64) -> &Type;
1060 pub fn LLVMPointerType(ElementType: &Type, AddressSpace: c_uint) -> &Type;
1061 pub fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;
1062
1063 pub fn LLVMGetElementType(Ty: &Type) -> &Type;
1064 pub fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint;
1065
1066 // Operations on other types
1067 pub fn LLVMVoidTypeInContext(C: &Context) -> &Type;
353b0b11 1068 pub fn LLVMMetadataTypeInContext(C: &Context) -> &Type;
b7449926
XL
1069
1070 // Operations on all values
1071 pub fn LLVMTypeOf(Val: &Value) -> &Type;
60c5eb7d
XL
1072 pub fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char;
1073 pub fn LLVMSetValueName2(Val: &Value, Name: *const c_char, NameLen: size_t);
a2a8927a
XL
1074 pub fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value);
1075 pub fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Node: &'a Value);
1076 pub fn LLVMGlobalSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
923072b8 1077 pub fn LLVMRustGlobalAddMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
a2a8927a 1078 pub fn LLVMValueAsMetadata(Node: &Value) -> &Metadata;
9c376795 1079 pub fn LLVMIsAFunction(Val: &Value) -> Option<&Value>;
b7449926
XL
1080
1081 // Operations on constants of any type
1082 pub fn LLVMConstNull(Ty: &Type) -> &Value;
1083 pub fn LLVMGetUndef(Ty: &Type) -> &Value;
353b0b11 1084 pub fn LLVMGetPoison(Ty: &Type) -> &Value;
b7449926
XL
1085
1086 // Operations on metadata
353b0b11 1087 // FIXME: deprecated, replace with LLVMMDStringInContext2
b7449926 1088 pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
353b0b11
FG
1089
1090 pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;
1091
1092 // FIXME: deprecated, replace with LLVMMDNodeInContext2
a2a8927a
XL
1093 pub fn LLVMMDNodeInContext<'a>(
1094 C: &'a Context,
1095 Vals: *const &'a Value,
1096 Count: c_uint,
1097 ) -> &'a Value;
923072b8
FG
1098 pub fn LLVMMDNodeInContext2<'a>(
1099 C: &'a Context,
1100 Vals: *const &'a Metadata,
1101 Count: size_t,
1102 ) -> &'a Metadata;
a2a8927a 1103 pub fn LLVMAddNamedMetadataOperand<'a>(M: &'a Module, Name: *const c_char, Val: &'a Value);
b7449926
XL
1104
1105 // Operations on scalar constants
1106 pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
1107 pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
416331ca 1108 pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
f2b60f7d 1109 pub fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;
dfeec247
XL
1110 pub fn LLVMRustConstInt128Get(
1111 ConstantVal: &ConstantInt,
1112 SExt: bool,
1113 high: &mut u64,
1114 low: &mut u64,
1115 ) -> bool;
b7449926
XL
1116
1117 // Operations on composite constants
dfeec247
XL
1118 pub fn LLVMConstStringInContext(
1119 C: &Context,
1120 Str: *const c_char,
1121 Length: c_uint,
1122 DontNullTerminate: Bool,
1123 ) -> &Value;
a2a8927a 1124 pub fn LLVMConstStructInContext<'a>(
dfeec247
XL
1125 C: &'a Context,
1126 ConstantVals: *const &'a Value,
1127 Count: c_uint,
1128 Packed: Bool,
1129 ) -> &'a Value;
1130
353b0b11
FG
1131 // FIXME: replace with LLVMConstArray2 when bumped minimal version to llvm-17
1132 // https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
a2a8927a 1133 pub fn LLVMConstArray<'a>(
dfeec247
XL
1134 ElementTy: &'a Type,
1135 ConstantVals: *const &'a Value,
1136 Length: c_uint,
1137 ) -> &'a Value;
b7449926
XL
1138 pub fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
1139
1140 // Constant expressions
a2a8927a 1141 pub fn LLVMRustConstInBoundsGEP2<'a>(
94222f64 1142 ty: &'a Type,
b7449926
XL
1143 ConstantVal: &'a Value,
1144 ConstantIndices: *const &'a Value,
1145 NumIndices: c_uint,
1146 ) -> &'a Value;
a2a8927a
XL
1147 pub fn LLVMConstZExt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1148 pub fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1149 pub fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1150 pub fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1151 pub fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
064997fb 1152 pub fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>;
b7449926
XL
1153
1154 // Operations on global variables, functions, and aliases (globals)
1155 pub fn LLVMIsDeclaration(Global: &Value) -> Bool;
1156 pub fn LLVMRustGetLinkage(Global: &Value) -> Linkage;
1157 pub fn LLVMRustSetLinkage(Global: &Value, RustLinkage: Linkage);
1158 pub fn LLVMSetSection(Global: &Value, Section: *const c_char);
1159 pub fn LLVMRustGetVisibility(Global: &Value) -> Visibility;
1160 pub fn LLVMRustSetVisibility(Global: &Value, Viz: Visibility);
cdc7bbd5 1161 pub fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);
b7449926
XL
1162 pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
1163 pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
1164 pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
1165
b7449926
XL
1166 // Operations on global variables
1167 pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
a2a8927a 1168 pub fn LLVMAddGlobal<'a>(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
b7449926 1169 pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
a2a8927a 1170 pub fn LLVMRustGetOrInsertGlobal<'a>(
dfeec247
XL
1171 M: &'a Module,
1172 Name: *const c_char,
1173 NameLen: size_t,
1174 T: &'a Type,
1175 ) -> &'a Value;
a2a8927a 1176 pub fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
b7449926
XL
1177 pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
1178 pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
1179 pub fn LLVMDeleteGlobal(GlobalVar: &Value);
1180 pub fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;
a2a8927a 1181 pub fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value);
17df50a5 1182 pub fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool;
b7449926
XL
1183 pub fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
1184 pub fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
1185 pub fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
ba9703b0
XL
1186 pub fn LLVMRustGetNamedValue(
1187 M: &Module,
1188 Name: *const c_char,
1189 NameLen: size_t,
1190 ) -> Option<&Value>;
b7449926
XL
1191 pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
1192
5e7ed085
FG
1193 // Operations on attributes
1194 pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;
1195 pub fn LLVMCreateStringAttribute(
1196 C: &Context,
1197 Name: *const c_char,
1198 NameLen: c_uint,
1199 Value: *const c_char,
1200 ValueLen: c_uint,
1201 ) -> &Attribute;
1202 pub fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute;
1203 pub fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute;
1204 pub fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute;
1205 pub fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1206 pub fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
064997fb 1207 pub fn LLVMRustCreateElementTypeAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
5e7ed085 1208 pub fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute;
064997fb
FG
1209 pub fn LLVMRustCreateAllocSizeAttr(C: &Context, size_arg: u32) -> &Attribute;
1210 pub fn LLVMRustCreateAllocKindAttr(C: &Context, size_arg: u64) -> &Attribute;
487cf647 1211 pub fn LLVMRustCreateMemoryEffectsAttr(C: &Context, effects: MemoryEffects) -> &Attribute;
5e7ed085 1212
b7449926 1213 // Operations on functions
a2a8927a 1214 pub fn LLVMRustGetOrInsertFunction<'a>(
dfeec247
XL
1215 M: &'a Module,
1216 Name: *const c_char,
ba9703b0 1217 NameLen: size_t,
dfeec247
XL
1218 FunctionTy: &'a Type,
1219 ) -> &'a Value;
b7449926 1220 pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
5e7ed085
FG
1221 pub fn LLVMRustAddFunctionAttributes<'a>(
1222 Fn: &'a Value,
dfeec247 1223 index: c_uint,
5e7ed085
FG
1224 Attrs: *const &'a Attribute,
1225 AttrsLen: size_t,
dfeec247 1226 );
b7449926
XL
1227
1228 // Operations on parameters
e1599b0c 1229 pub fn LLVMIsAArgument(Val: &Value) -> Option<&Value>;
b7449926
XL
1230 pub fn LLVMCountParams(Fn: &Value) -> c_uint;
1231 pub fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
1232
1233 // Operations on basic blocks
1234 pub fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
a2a8927a 1235 pub fn LLVMAppendBasicBlockInContext<'a>(
dfeec247
XL
1236 C: &'a Context,
1237 Fn: &'a Value,
1238 Name: *const c_char,
1239 ) -> &'a BasicBlock;
b7449926
XL
1240
1241 // Operations on instructions
e1599b0c 1242 pub fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>;
b7449926
XL
1243 pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
1244
1245 // Operations on call sites
1246 pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
5e7ed085
FG
1247 pub fn LLVMRustAddCallSiteAttributes<'a>(
1248 Instr: &'a Value,
1249 index: c_uint,
1250 Attrs: *const &'a Attribute,
1251 AttrsLen: size_t,
1252 );
b7449926
XL
1253
1254 // Operations on load/store instructions (only)
1255 pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
1256
1257 // Operations on phi nodes
a2a8927a 1258 pub fn LLVMAddIncoming<'a>(
dfeec247
XL
1259 PhiNode: &'a Value,
1260 IncomingValues: *const &'a Value,
1261 IncomingBlocks: *const &'a BasicBlock,
1262 Count: c_uint,
1263 );
b7449926
XL
1264
1265 // Instruction builders
a2a8927a
XL
1266 pub fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;
1267 pub fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock);
1268 pub fn LLVMGetInsertBlock<'a>(Builder: &Builder<'a>) -> &'a BasicBlock;
1269 pub fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
b7449926
XL
1270
1271 // Metadata
353b0b11 1272 pub fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: &'a Metadata);
b7449926
XL
1273
1274 // Terminators
a2a8927a
XL
1275 pub fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;
1276 pub fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value;
1277 pub fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;
1278 pub fn LLVMBuildCondBr<'a>(
dfeec247
XL
1279 B: &Builder<'a>,
1280 If: &'a Value,
1281 Then: &'a BasicBlock,
1282 Else: &'a BasicBlock,
1283 ) -> &'a Value;
a2a8927a 1284 pub fn LLVMBuildSwitch<'a>(
dfeec247
XL
1285 B: &Builder<'a>,
1286 V: &'a Value,
1287 Else: &'a BasicBlock,
1288 NumCases: c_uint,
1289 ) -> &'a Value;
a2a8927a 1290 pub fn LLVMRustBuildInvoke<'a>(
dfeec247 1291 B: &Builder<'a>,
94222f64 1292 Ty: &'a Type,
dfeec247
XL
1293 Fn: &'a Value,
1294 Args: *const &'a Value,
1295 NumArgs: c_uint,
1296 Then: &'a BasicBlock,
1297 Catch: &'a BasicBlock,
9c376795
FG
1298 OpBundles: *const Option<&OperandBundleDef<'a>>,
1299 NumOpBundles: c_uint,
dfeec247
XL
1300 Name: *const c_char,
1301 ) -> &'a Value;
a2a8927a 1302 pub fn LLVMBuildLandingPad<'a>(
dfeec247
XL
1303 B: &Builder<'a>,
1304 Ty: &'a Type,
136023e0 1305 PersFn: Option<&'a Value>,
dfeec247
XL
1306 NumClauses: c_uint,
1307 Name: *const c_char,
1308 ) -> &'a Value;
a2a8927a
XL
1309 pub fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
1310 pub fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value;
b7449926 1311
353b0b11 1312 pub fn LLVMBuildCleanupPad<'a>(
dfeec247
XL
1313 B: &Builder<'a>,
1314 ParentPad: Option<&'a Value>,
dfeec247 1315 Args: *const &'a Value,
353b0b11 1316 NumArgs: c_uint,
dfeec247
XL
1317 Name: *const c_char,
1318 ) -> Option<&'a Value>;
353b0b11 1319 pub fn LLVMBuildCleanupRet<'a>(
dfeec247
XL
1320 B: &Builder<'a>,
1321 CleanupPad: &'a Value,
353b0b11 1322 BB: Option<&'a BasicBlock>,
dfeec247 1323 ) -> Option<&'a Value>;
353b0b11 1324 pub fn LLVMBuildCatchPad<'a>(
dfeec247
XL
1325 B: &Builder<'a>,
1326 ParentPad: &'a Value,
dfeec247 1327 Args: *const &'a Value,
353b0b11 1328 NumArgs: c_uint,
dfeec247
XL
1329 Name: *const c_char,
1330 ) -> Option<&'a Value>;
353b0b11 1331 pub fn LLVMBuildCatchRet<'a>(
b7449926 1332 B: &Builder<'a>,
353b0b11 1333 CatchPad: &'a Value,
b7449926
XL
1334 BB: &'a BasicBlock,
1335 ) -> Option<&'a Value>;
353b0b11 1336 pub fn LLVMBuildCatchSwitch<'a>(
dfeec247
XL
1337 Builder: &Builder<'a>,
1338 ParentPad: Option<&'a Value>,
353b0b11 1339 UnwindBB: Option<&'a BasicBlock>,
dfeec247
XL
1340 NumHandlers: c_uint,
1341 Name: *const c_char,
1342 ) -> Option<&'a Value>;
353b0b11 1343 pub fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock);
a2a8927a 1344 pub fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value);
b7449926
XL
1345
1346 // Add a case to the switch instruction
a2a8927a 1347 pub fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
b7449926
XL
1348
1349 // Add a clause to the landing pad instruction
a2a8927a 1350 pub fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value);
b7449926
XL
1351
1352 // Set the cleanup on a landing pad instruction
1353 pub fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);
1354
1355 // Arithmetic
a2a8927a 1356 pub fn LLVMBuildAdd<'a>(
dfeec247
XL
1357 B: &Builder<'a>,
1358 LHS: &'a Value,
1359 RHS: &'a Value,
1360 Name: *const c_char,
1361 ) -> &'a Value;
a2a8927a 1362 pub fn LLVMBuildFAdd<'a>(
dfeec247
XL
1363 B: &Builder<'a>,
1364 LHS: &'a Value,
1365 RHS: &'a Value,
1366 Name: *const c_char,
1367 ) -> &'a Value;
a2a8927a 1368 pub fn LLVMBuildSub<'a>(
dfeec247
XL
1369 B: &Builder<'a>,
1370 LHS: &'a Value,
1371 RHS: &'a Value,
1372 Name: *const c_char,
1373 ) -> &'a Value;
a2a8927a 1374 pub fn LLVMBuildFSub<'a>(
dfeec247
XL
1375 B: &Builder<'a>,
1376 LHS: &'a Value,
1377 RHS: &'a Value,
1378 Name: *const c_char,
1379 ) -> &'a Value;
a2a8927a 1380 pub fn LLVMBuildMul<'a>(
dfeec247
XL
1381 B: &Builder<'a>,
1382 LHS: &'a Value,
1383 RHS: &'a Value,
1384 Name: *const c_char,
1385 ) -> &'a Value;
a2a8927a 1386 pub fn LLVMBuildFMul<'a>(
dfeec247
XL
1387 B: &Builder<'a>,
1388 LHS: &'a Value,
1389 RHS: &'a Value,
1390 Name: *const c_char,
1391 ) -> &'a Value;
a2a8927a 1392 pub fn LLVMBuildUDiv<'a>(
dfeec247
XL
1393 B: &Builder<'a>,
1394 LHS: &'a Value,
1395 RHS: &'a Value,
1396 Name: *const c_char,
1397 ) -> &'a Value;
a2a8927a 1398 pub fn LLVMBuildExactUDiv<'a>(
dfeec247
XL
1399 B: &Builder<'a>,
1400 LHS: &'a Value,
1401 RHS: &'a Value,
1402 Name: *const c_char,
1403 ) -> &'a Value;
a2a8927a 1404 pub fn LLVMBuildSDiv<'a>(
dfeec247
XL
1405 B: &Builder<'a>,
1406 LHS: &'a Value,
1407 RHS: &'a Value,
1408 Name: *const c_char,
1409 ) -> &'a Value;
a2a8927a 1410 pub fn LLVMBuildExactSDiv<'a>(
dfeec247
XL
1411 B: &Builder<'a>,
1412 LHS: &'a Value,
1413 RHS: &'a Value,
1414 Name: *const c_char,
1415 ) -> &'a Value;
a2a8927a 1416 pub fn LLVMBuildFDiv<'a>(
dfeec247
XL
1417 B: &Builder<'a>,
1418 LHS: &'a Value,
1419 RHS: &'a Value,
1420 Name: *const c_char,
1421 ) -> &'a Value;
a2a8927a 1422 pub fn LLVMBuildURem<'a>(
dfeec247
XL
1423 B: &Builder<'a>,
1424 LHS: &'a Value,
1425 RHS: &'a Value,
1426 Name: *const c_char,
1427 ) -> &'a Value;
a2a8927a 1428 pub fn LLVMBuildSRem<'a>(
dfeec247
XL
1429 B: &Builder<'a>,
1430 LHS: &'a Value,
1431 RHS: &'a Value,
1432 Name: *const c_char,
1433 ) -> &'a Value;
a2a8927a 1434 pub fn LLVMBuildFRem<'a>(
dfeec247
XL
1435 B: &Builder<'a>,
1436 LHS: &'a Value,
1437 RHS: &'a Value,
1438 Name: *const c_char,
1439 ) -> &'a Value;
a2a8927a 1440 pub fn LLVMBuildShl<'a>(
dfeec247
XL
1441 B: &Builder<'a>,
1442 LHS: &'a Value,
1443 RHS: &'a Value,
1444 Name: *const c_char,
1445 ) -> &'a Value;
a2a8927a 1446 pub fn LLVMBuildLShr<'a>(
dfeec247
XL
1447 B: &Builder<'a>,
1448 LHS: &'a Value,
1449 RHS: &'a Value,
1450 Name: *const c_char,
1451 ) -> &'a Value;
a2a8927a 1452 pub fn LLVMBuildAShr<'a>(
dfeec247
XL
1453 B: &Builder<'a>,
1454 LHS: &'a Value,
1455 RHS: &'a Value,
1456 Name: *const c_char,
1457 ) -> &'a Value;
a2a8927a 1458 pub fn LLVMBuildNSWAdd<'a>(
dfeec247
XL
1459 B: &Builder<'a>,
1460 LHS: &'a Value,
1461 RHS: &'a Value,
1462 Name: *const c_char,
1463 ) -> &'a Value;
a2a8927a 1464 pub fn LLVMBuildNUWAdd<'a>(
dfeec247
XL
1465 B: &Builder<'a>,
1466 LHS: &'a Value,
1467 RHS: &'a Value,
1468 Name: *const c_char,
1469 ) -> &'a Value;
a2a8927a 1470 pub fn LLVMBuildNSWSub<'a>(
dfeec247
XL
1471 B: &Builder<'a>,
1472 LHS: &'a Value,
1473 RHS: &'a Value,
1474 Name: *const c_char,
1475 ) -> &'a Value;
a2a8927a 1476 pub fn LLVMBuildNUWSub<'a>(
dfeec247
XL
1477 B: &Builder<'a>,
1478 LHS: &'a Value,
1479 RHS: &'a Value,
1480 Name: *const c_char,
1481 ) -> &'a Value;
a2a8927a 1482 pub fn LLVMBuildNSWMul<'a>(
dfeec247
XL
1483 B: &Builder<'a>,
1484 LHS: &'a Value,
1485 RHS: &'a Value,
1486 Name: *const c_char,
1487 ) -> &'a Value;
a2a8927a 1488 pub fn LLVMBuildNUWMul<'a>(
dfeec247
XL
1489 B: &Builder<'a>,
1490 LHS: &'a Value,
1491 RHS: &'a Value,
1492 Name: *const c_char,
1493 ) -> &'a Value;
a2a8927a 1494 pub fn LLVMBuildAnd<'a>(
dfeec247
XL
1495 B: &Builder<'a>,
1496 LHS: &'a Value,
1497 RHS: &'a Value,
1498 Name: *const c_char,
1499 ) -> &'a Value;
a2a8927a 1500 pub fn LLVMBuildOr<'a>(
dfeec247
XL
1501 B: &Builder<'a>,
1502 LHS: &'a Value,
1503 RHS: &'a Value,
1504 Name: *const c_char,
1505 ) -> &'a Value;
a2a8927a 1506 pub fn LLVMBuildXor<'a>(
dfeec247
XL
1507 B: &Builder<'a>,
1508 LHS: &'a Value,
1509 RHS: &'a Value,
1510 Name: *const c_char,
1511 ) -> &'a Value;
a2a8927a
XL
1512 pub fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1513 pub fn LLVMBuildFNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1514 pub fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
cdc7bbd5 1515 pub fn LLVMRustSetFastMath(Instr: &Value);
b7449926
XL
1516
1517 // Memory
a2a8927a
XL
1518 pub fn LLVMBuildAlloca<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1519 pub fn LLVMBuildArrayAlloca<'a>(
dfeec247
XL
1520 B: &Builder<'a>,
1521 Ty: &'a Type,
1522 Val: &'a Value,
1523 Name: *const c_char,
1524 ) -> &'a Value;
a2a8927a 1525 pub fn LLVMBuildLoad2<'a>(
136023e0
XL
1526 B: &Builder<'a>,
1527 Ty: &'a Type,
1528 PointerVal: &'a Value,
1529 Name: *const c_char,
1530 ) -> &'a Value;
b7449926 1531
a2a8927a 1532 pub fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
b7449926 1533
a2a8927a 1534 pub fn LLVMBuildGEP2<'a>(
dfeec247 1535 B: &Builder<'a>,
94222f64 1536 Ty: &'a Type,
dfeec247
XL
1537 Pointer: &'a Value,
1538 Indices: *const &'a Value,
1539 NumIndices: c_uint,
1540 Name: *const c_char,
1541 ) -> &'a Value;
a2a8927a 1542 pub fn LLVMBuildInBoundsGEP2<'a>(
dfeec247 1543 B: &Builder<'a>,
94222f64 1544 Ty: &'a Type,
dfeec247
XL
1545 Pointer: &'a Value,
1546 Indices: *const &'a Value,
1547 NumIndices: c_uint,
1548 Name: *const c_char,
1549 ) -> &'a Value;
a2a8927a 1550 pub fn LLVMBuildStructGEP2<'a>(
dfeec247 1551 B: &Builder<'a>,
94222f64 1552 Ty: &'a Type,
dfeec247
XL
1553 Pointer: &'a Value,
1554 Idx: c_uint,
1555 Name: *const c_char,
1556 ) -> &'a Value;
b7449926
XL
1557
1558 // Casts
a2a8927a 1559 pub fn LLVMBuildTrunc<'a>(
dfeec247
XL
1560 B: &Builder<'a>,
1561 Val: &'a Value,
1562 DestTy: &'a Type,
1563 Name: *const c_char,
1564 ) -> &'a Value;
a2a8927a 1565 pub fn LLVMBuildZExt<'a>(
dfeec247
XL
1566 B: &Builder<'a>,
1567 Val: &'a Value,
1568 DestTy: &'a Type,
1569 Name: *const c_char,
1570 ) -> &'a Value;
a2a8927a 1571 pub fn LLVMBuildSExt<'a>(
dfeec247
XL
1572 B: &Builder<'a>,
1573 Val: &'a Value,
1574 DestTy: &'a Type,
1575 Name: *const c_char,
1576 ) -> &'a Value;
a2a8927a 1577 pub fn LLVMBuildFPToUI<'a>(
dfeec247
XL
1578 B: &Builder<'a>,
1579 Val: &'a Value,
1580 DestTy: &'a Type,
1581 Name: *const c_char,
1582 ) -> &'a Value;
a2a8927a 1583 pub fn LLVMBuildFPToSI<'a>(
dfeec247
XL
1584 B: &Builder<'a>,
1585 Val: &'a Value,
1586 DestTy: &'a Type,
1587 Name: *const c_char,
1588 ) -> &'a Value;
a2a8927a 1589 pub fn LLVMBuildUIToFP<'a>(
dfeec247
XL
1590 B: &Builder<'a>,
1591 Val: &'a Value,
1592 DestTy: &'a Type,
1593 Name: *const c_char,
1594 ) -> &'a Value;
a2a8927a 1595 pub fn LLVMBuildSIToFP<'a>(
dfeec247
XL
1596 B: &Builder<'a>,
1597 Val: &'a Value,
1598 DestTy: &'a Type,
1599 Name: *const c_char,
1600 ) -> &'a Value;
a2a8927a 1601 pub fn LLVMBuildFPTrunc<'a>(
dfeec247
XL
1602 B: &Builder<'a>,
1603 Val: &'a Value,
1604 DestTy: &'a Type,
1605 Name: *const c_char,
1606 ) -> &'a Value;
a2a8927a 1607 pub fn LLVMBuildFPExt<'a>(
dfeec247
XL
1608 B: &Builder<'a>,
1609 Val: &'a Value,
1610 DestTy: &'a Type,
1611 Name: *const c_char,
1612 ) -> &'a Value;
a2a8927a 1613 pub fn LLVMBuildPtrToInt<'a>(
dfeec247
XL
1614 B: &Builder<'a>,
1615 Val: &'a Value,
1616 DestTy: &'a Type,
1617 Name: *const c_char,
1618 ) -> &'a Value;
a2a8927a 1619 pub fn LLVMBuildIntToPtr<'a>(
dfeec247
XL
1620 B: &Builder<'a>,
1621 Val: &'a Value,
1622 DestTy: &'a Type,
1623 Name: *const c_char,
1624 ) -> &'a Value;
a2a8927a 1625 pub fn LLVMBuildBitCast<'a>(
dfeec247
XL
1626 B: &Builder<'a>,
1627 Val: &'a Value,
1628 DestTy: &'a Type,
1629 Name: *const c_char,
1630 ) -> &'a Value;
a2a8927a 1631 pub fn LLVMBuildPointerCast<'a>(
dfeec247
XL
1632 B: &Builder<'a>,
1633 Val: &'a Value,
1634 DestTy: &'a Type,
1635 Name: *const c_char,
1636 ) -> &'a Value;
353b0b11 1637 pub fn LLVMBuildIntCast2<'a>(
dfeec247
XL
1638 B: &Builder<'a>,
1639 Val: &'a Value,
1640 DestTy: &'a Type,
353b0b11
FG
1641 IsSigned: Bool,
1642 Name: *const c_char,
dfeec247 1643 ) -> &'a Value;
b7449926
XL
1644
1645 // Comparisons
a2a8927a 1646 pub fn LLVMBuildICmp<'a>(
dfeec247
XL
1647 B: &Builder<'a>,
1648 Op: c_uint,
1649 LHS: &'a Value,
1650 RHS: &'a Value,
1651 Name: *const c_char,
1652 ) -> &'a Value;
a2a8927a 1653 pub fn LLVMBuildFCmp<'a>(
dfeec247
XL
1654 B: &Builder<'a>,
1655 Op: c_uint,
1656 LHS: &'a Value,
1657 RHS: &'a Value,
1658 Name: *const c_char,
1659 ) -> &'a Value;
b7449926
XL
1660
1661 // Miscellaneous instructions
a2a8927a
XL
1662 pub fn LLVMBuildPhi<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1663 pub fn LLVMRustGetInstrProfIncrementIntrinsic(M: &Module) -> &Value;
1664 pub fn LLVMRustBuildCall<'a>(
b7449926 1665 B: &Builder<'a>,
94222f64 1666 Ty: &'a Type,
dfeec247
XL
1667 Fn: &'a Value,
1668 Args: *const &'a Value,
1669 NumArgs: c_uint,
9c376795
FG
1670 OpBundles: *const Option<&OperandBundleDef<'a>>,
1671 NumOpBundles: c_uint,
dfeec247 1672 ) -> &'a Value;
a2a8927a 1673 pub fn LLVMRustBuildMemCpy<'a>(
dfeec247
XL
1674 B: &Builder<'a>,
1675 Dst: &'a Value,
1676 DstAlign: c_uint,
1677 Src: &'a Value,
1678 SrcAlign: c_uint,
1679 Size: &'a Value,
1680 IsVolatile: bool,
1681 ) -> &'a Value;
a2a8927a 1682 pub fn LLVMRustBuildMemMove<'a>(
dfeec247
XL
1683 B: &Builder<'a>,
1684 Dst: &'a Value,
1685 DstAlign: c_uint,
1686 Src: &'a Value,
1687 SrcAlign: c_uint,
1688 Size: &'a Value,
1689 IsVolatile: bool,
1690 ) -> &'a Value;
a2a8927a 1691 pub fn LLVMRustBuildMemSet<'a>(
74b04a01
XL
1692 B: &Builder<'a>,
1693 Dst: &'a Value,
1694 DstAlign: c_uint,
1695 Val: &'a Value,
1696 Size: &'a Value,
1697 IsVolatile: bool,
1698 ) -> &'a Value;
a2a8927a 1699 pub fn LLVMBuildSelect<'a>(
dfeec247
XL
1700 B: &Builder<'a>,
1701 If: &'a Value,
1702 Then: &'a Value,
1703 Else: &'a Value,
1704 Name: *const c_char,
0731742a 1705 ) -> &'a Value;
a2a8927a 1706 pub fn LLVMBuildVAArg<'a>(
dfeec247
XL
1707 B: &Builder<'a>,
1708 list: &'a Value,
1709 Ty: &'a Type,
1710 Name: *const c_char,
1711 ) -> &'a Value;
a2a8927a 1712 pub fn LLVMBuildExtractElement<'a>(
dfeec247
XL
1713 B: &Builder<'a>,
1714 VecVal: &'a Value,
1715 Index: &'a Value,
1716 Name: *const c_char,
1717 ) -> &'a Value;
a2a8927a 1718 pub fn LLVMBuildInsertElement<'a>(
dfeec247
XL
1719 B: &Builder<'a>,
1720 VecVal: &'a Value,
1721 EltVal: &'a Value,
1722 Index: &'a Value,
1723 Name: *const c_char,
1724 ) -> &'a Value;
a2a8927a 1725 pub fn LLVMBuildShuffleVector<'a>(
dfeec247
XL
1726 B: &Builder<'a>,
1727 V1: &'a Value,
1728 V2: &'a Value,
1729 Mask: &'a Value,
1730 Name: *const c_char,
1731 ) -> &'a Value;
a2a8927a 1732 pub fn LLVMBuildExtractValue<'a>(
dfeec247
XL
1733 B: &Builder<'a>,
1734 AggVal: &'a Value,
1735 Index: c_uint,
1736 Name: *const c_char,
1737 ) -> &'a Value;
a2a8927a 1738 pub fn LLVMBuildInsertValue<'a>(
dfeec247
XL
1739 B: &Builder<'a>,
1740 AggVal: &'a Value,
1741 EltVal: &'a Value,
1742 Index: c_uint,
1743 Name: *const c_char,
1744 ) -> &'a Value;
1745
a2a8927a 1746 pub fn LLVMRustBuildVectorReduceFAdd<'a>(
dfeec247
XL
1747 B: &Builder<'a>,
1748 Acc: &'a Value,
1749 Src: &'a Value,
1750 ) -> &'a Value;
a2a8927a 1751 pub fn LLVMRustBuildVectorReduceFMul<'a>(
dfeec247
XL
1752 B: &Builder<'a>,
1753 Acc: &'a Value,
1754 Src: &'a Value,
1755 ) -> &'a Value;
a2a8927a
XL
1756 pub fn LLVMRustBuildVectorReduceAdd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1757 pub fn LLVMRustBuildVectorReduceMul<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1758 pub fn LLVMRustBuildVectorReduceAnd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1759 pub fn LLVMRustBuildVectorReduceOr<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1760 pub fn LLVMRustBuildVectorReduceXor<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1761 pub fn LLVMRustBuildVectorReduceMin<'a>(
dfeec247
XL
1762 B: &Builder<'a>,
1763 Src: &'a Value,
1764 IsSigned: bool,
1765 ) -> &'a Value;
a2a8927a 1766 pub fn LLVMRustBuildVectorReduceMax<'a>(
dfeec247
XL
1767 B: &Builder<'a>,
1768 Src: &'a Value,
1769 IsSigned: bool,
1770 ) -> &'a Value;
a2a8927a
XL
1771 pub fn LLVMRustBuildVectorReduceFMin<'a>(
1772 B: &Builder<'a>,
1773 Src: &'a Value,
1774 IsNaN: bool,
1775 ) -> &'a Value;
1776 pub fn LLVMRustBuildVectorReduceFMax<'a>(
1777 B: &Builder<'a>,
1778 Src: &'a Value,
1779 IsNaN: bool,
1780 ) -> &'a Value;
dfeec247 1781
a2a8927a
XL
1782 pub fn LLVMRustBuildMinNum<'a>(B: &Builder<'a>, LHS: &'a Value, LHS: &'a Value) -> &'a Value;
1783 pub fn LLVMRustBuildMaxNum<'a>(B: &Builder<'a>, LHS: &'a Value, LHS: &'a Value) -> &'a Value;
dfeec247
XL
1784
1785 // Atomic Operations
a2a8927a 1786 pub fn LLVMRustBuildAtomicLoad<'a>(
dfeec247 1787 B: &Builder<'a>,
136023e0 1788 ElementType: &'a Type,
dfeec247
XL
1789 PointerVal: &'a Value,
1790 Name: *const c_char,
1791 Order: AtomicOrdering,
1792 ) -> &'a Value;
1793
a2a8927a 1794 pub fn LLVMRustBuildAtomicStore<'a>(
dfeec247
XL
1795 B: &Builder<'a>,
1796 Val: &'a Value,
1797 Ptr: &'a Value,
1798 Order: AtomicOrdering,
1799 ) -> &'a Value;
1800
2b03887a 1801 pub fn LLVMBuildAtomicCmpXchg<'a>(
b7449926
XL
1802 B: &Builder<'a>,
1803 LHS: &'a Value,
dfeec247
XL
1804 CMP: &'a Value,
1805 RHS: &'a Value,
1806 Order: AtomicOrdering,
1807 FailureOrder: AtomicOrdering,
2b03887a 1808 SingleThreaded: Bool,
dfeec247
XL
1809 ) -> &'a Value;
1810
2b03887a
FG
1811 pub fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool);
1812
a2a8927a 1813 pub fn LLVMBuildAtomicRMW<'a>(
dfeec247
XL
1814 B: &Builder<'a>,
1815 Op: AtomicRmwBinOp,
b7449926 1816 LHS: &'a Value,
dfeec247
XL
1817 RHS: &'a Value,
1818 Order: AtomicOrdering,
1819 SingleThreaded: Bool,
0731742a 1820 ) -> &'a Value;
b7449926 1821
2b03887a
FG
1822 pub fn LLVMBuildFence<'a>(
1823 B: &Builder<'a>,
dfeec247 1824 Order: AtomicOrdering,
2b03887a
FG
1825 SingleThreaded: Bool,
1826 Name: *const c_char,
1827 ) -> &'a Value;
b7449926
XL
1828
1829 /// Writes a module to the specified path. Returns 0 on success.
1830 pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
1831
2b03887a 1832 /// Creates a legacy pass manager -- only used for final codegen.
a2a8927a 1833 pub fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>;
b7449926 1834
74b04a01
XL
1835 pub fn LLVMTimeTraceProfilerInitialize();
1836
3c0e092e
XL
1837 pub fn LLVMTimeTraceProfilerFinishThread();
1838
74b04a01
XL
1839 pub fn LLVMTimeTraceProfilerFinish(FileName: *const c_char);
1840
a2a8927a 1841 pub fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);
60c5eb7d 1842
5869c6ff
XL
1843 pub fn LLVMGetHostCPUFeatures() -> *mut c_char;
1844
1845 pub fn LLVMDisposeMessage(message: *mut c_char);
1846
3c0e092e 1847 pub fn LLVMIsMultithreaded() -> Bool;
b7449926
XL
1848
1849 /// Returns a string describing the last error caused by an LLVMRust* call.
1850 pub fn LLVMRustGetLastError() -> *const c_char;
1851
1852 /// Print the pass timings since static dtors aren't picking them up.
1853 pub fn LLVMRustPrintPassTimings();
1854
1855 pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
1856
a2a8927a 1857 pub fn LLVMStructSetBody<'a>(
dfeec247
XL
1858 StructTy: &'a Type,
1859 ElementTypes: *const &'a Type,
1860 ElementCount: c_uint,
1861 Packed: Bool,
1862 );
b7449926
XL
1863
1864 /// Prepares inline assembly.
dfeec247
XL
1865 pub fn LLVMRustInlineAsm(
1866 Ty: &Type,
1867 AsmString: *const c_char,
ba9703b0 1868 AsmStringLen: size_t,
dfeec247 1869 Constraints: *const c_char,
ba9703b0 1870 ConstraintsLen: size_t,
dfeec247
XL
1871 SideEffects: Bool,
1872 AlignStack: Bool,
1873 Dialect: AsmDialect,
a2a8927a 1874 CanThrow: Bool,
dfeec247 1875 ) -> &Value;
ba9703b0
XL
1876 pub fn LLVMRustInlineAsmVerify(
1877 Ty: &Type,
1878 Constraints: *const c_char,
1879 ConstraintsLen: size_t,
1880 ) -> bool;
b7449926 1881
3dfed10e
XL
1882 #[allow(improper_ctypes)]
1883 pub fn LLVMRustCoverageWriteFilenamesSectionToBuffer(
1884 Filenames: *const *const c_char,
1885 FilenamesLen: size_t,
1886 BufferOut: &RustString,
1887 );
1888
1889 #[allow(improper_ctypes)]
1890 pub fn LLVMRustCoverageWriteMappingToBuffer(
1891 VirtualFileMappingIDs: *const c_uint,
1892 NumVirtualFileMappingIDs: c_uint,
1893 Expressions: *const coverage_map::CounterExpression,
1894 NumExpressions: c_uint,
6a06907d 1895 MappingRegions: *const coverageinfo::CounterMappingRegion,
3dfed10e
XL
1896 NumMappingRegions: c_uint,
1897 BufferOut: &RustString,
1898 );
1899
a2a8927a 1900 pub fn LLVMRustCoverageCreatePGOFuncNameVar(F: &Value, FuncName: *const c_char) -> &Value;
fc512014
XL
1901 pub fn LLVMRustCoverageHashCString(StrVal: *const c_char) -> u64;
1902 pub fn LLVMRustCoverageHashByteArray(Bytes: *const c_char, NumBytes: size_t) -> u64;
3dfed10e
XL
1903
1904 #[allow(improper_ctypes)]
fc512014
XL
1905 pub fn LLVMRustCoverageWriteMapSectionNameToString(M: &Module, Str: &RustString);
1906
1907 #[allow(improper_ctypes)]
1908 pub fn LLVMRustCoverageWriteFuncSectionNameToString(M: &Module, Str: &RustString);
3dfed10e
XL
1909
1910 #[allow(improper_ctypes)]
1911 pub fn LLVMRustCoverageWriteMappingVarNameToString(Str: &RustString);
1912
1913 pub fn LLVMRustCoverageMappingVersion() -> u32;
b7449926
XL
1914 pub fn LLVMRustDebugMetadataVersion() -> u32;
1915 pub fn LLVMRustVersionMajor() -> u32;
1916 pub fn LLVMRustVersionMinor() -> u32;
5869c6ff 1917 pub fn LLVMRustVersionPatch() -> u32;
b7449926 1918
5099ac24
FG
1919 /// Add LLVM module flags.
1920 ///
1921 /// In order for Rust-C LTO to work, module flags must be compatible with Clang. What
1922 /// "compatible" means depends on the merge behaviors involved.
1923 pub fn LLVMRustAddModuleFlag(
1924 M: &Module,
1925 merge_behavior: LLVMModFlagBehavior,
1926 name: *const c_char,
1927 value: u32,
1928 );
923072b8 1929 pub fn LLVMRustHasModuleFlag(M: &Module, name: *const c_char, len: size_t) -> bool;
b7449926 1930
353b0b11 1931 pub fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
b7449926 1932
a2a8927a 1933 pub fn LLVMRustDIBuilderCreate(M: &Module) -> &mut DIBuilder<'_>;
b7449926 1934
a2a8927a 1935 pub fn LLVMRustDIBuilderDispose<'a>(Builder: &'a mut DIBuilder<'a>);
b7449926 1936
9fa01778 1937 pub fn LLVMRustDIBuilderFinalize(Builder: &DIBuilder<'_>);
b7449926 1938
a2a8927a 1939 pub fn LLVMRustDIBuilderCreateCompileUnit<'a>(
dfeec247
XL
1940 Builder: &DIBuilder<'a>,
1941 Lang: c_uint,
1942 File: &'a DIFile,
1943 Producer: *const c_char,
74b04a01 1944 ProducerLen: size_t,
dfeec247
XL
1945 isOptimized: bool,
1946 Flags: *const c_char,
1947 RuntimeVer: c_uint,
1948 SplitName: *const c_char,
74b04a01 1949 SplitNameLen: size_t,
dfeec247 1950 kind: DebugEmissionKind,
fc512014
XL
1951 DWOId: u64,
1952 SplitDebugInlining: bool,
dfeec247
XL
1953 ) -> &'a DIDescriptor;
1954
a2a8927a 1955 pub fn LLVMRustDIBuilderCreateFile<'a>(
dfeec247
XL
1956 Builder: &DIBuilder<'a>,
1957 Filename: *const c_char,
74b04a01 1958 FilenameLen: size_t,
dfeec247 1959 Directory: *const c_char,
74b04a01 1960 DirectoryLen: size_t,
ba9703b0
XL
1961 CSKind: ChecksumKind,
1962 Checksum: *const c_char,
1963 ChecksumLen: size_t,
dfeec247
XL
1964 ) -> &'a DIFile;
1965
a2a8927a 1966 pub fn LLVMRustDIBuilderCreateSubroutineType<'a>(
dfeec247 1967 Builder: &DIBuilder<'a>,
dfeec247
XL
1968 ParameterTypes: &'a DIArray,
1969 ) -> &'a DICompositeType;
1970
a2a8927a 1971 pub fn LLVMRustDIBuilderCreateFunction<'a>(
dfeec247
XL
1972 Builder: &DIBuilder<'a>,
1973 Scope: &'a DIDescriptor,
1974 Name: *const c_char,
74b04a01 1975 NameLen: size_t,
dfeec247 1976 LinkageName: *const c_char,
74b04a01 1977 LinkageNameLen: size_t,
dfeec247
XL
1978 File: &'a DIFile,
1979 LineNo: c_uint,
1980 Ty: &'a DIType,
1981 ScopeLine: c_uint,
1982 Flags: DIFlags,
1983 SPFlags: DISPFlags,
29967ef6 1984 MaybeFn: Option<&'a Value>,
dfeec247
XL
1985 TParam: &'a DIArray,
1986 Decl: Option<&'a DIDescriptor>,
1987 ) -> &'a DISubprogram;
1988
353b0b11
FG
1989 pub fn LLVMRustDIBuilderCreateMethod<'a>(
1990 Builder: &DIBuilder<'a>,
1991 Scope: &'a DIDescriptor,
1992 Name: *const c_char,
1993 NameLen: size_t,
1994 LinkageName: *const c_char,
1995 LinkageNameLen: size_t,
1996 File: &'a DIFile,
1997 LineNo: c_uint,
1998 Ty: &'a DIType,
1999 Flags: DIFlags,
2000 SPFlags: DISPFlags,
2001 TParam: &'a DIArray,
2002 ) -> &'a DISubprogram;
2003
a2a8927a 2004 pub fn LLVMRustDIBuilderCreateBasicType<'a>(
dfeec247
XL
2005 Builder: &DIBuilder<'a>,
2006 Name: *const c_char,
74b04a01 2007 NameLen: size_t,
dfeec247 2008 SizeInBits: u64,
dfeec247
XL
2009 Encoding: c_uint,
2010 ) -> &'a DIBasicType;
2011
a2a8927a 2012 pub fn LLVMRustDIBuilderCreateTypedef<'a>(
f035d41b
XL
2013 Builder: &DIBuilder<'a>,
2014 Type: &'a DIBasicType,
2015 Name: *const c_char,
2016 NameLen: size_t,
2017 File: &'a DIFile,
2018 LineNo: c_uint,
2019 Scope: Option<&'a DIScope>,
2020 ) -> &'a DIDerivedType;
2021
a2a8927a 2022 pub fn LLVMRustDIBuilderCreatePointerType<'a>(
dfeec247
XL
2023 Builder: &DIBuilder<'a>,
2024 PointeeTy: &'a DIType,
2025 SizeInBits: u64,
2026 AlignInBits: u32,
74b04a01 2027 AddressSpace: c_uint,
dfeec247 2028 Name: *const c_char,
74b04a01 2029 NameLen: size_t,
dfeec247
XL
2030 ) -> &'a DIDerivedType;
2031
a2a8927a 2032 pub fn LLVMRustDIBuilderCreateStructType<'a>(
dfeec247
XL
2033 Builder: &DIBuilder<'a>,
2034 Scope: Option<&'a DIDescriptor>,
2035 Name: *const c_char,
74b04a01 2036 NameLen: size_t,
dfeec247
XL
2037 File: &'a DIFile,
2038 LineNumber: c_uint,
2039 SizeInBits: u64,
2040 AlignInBits: u32,
2041 Flags: DIFlags,
2042 DerivedFrom: Option<&'a DIType>,
2043 Elements: &'a DIArray,
2044 RunTimeLang: c_uint,
2045 VTableHolder: Option<&'a DIType>,
2046 UniqueId: *const c_char,
74b04a01 2047 UniqueIdLen: size_t,
dfeec247
XL
2048 ) -> &'a DICompositeType;
2049
a2a8927a 2050 pub fn LLVMRustDIBuilderCreateMemberType<'a>(
dfeec247
XL
2051 Builder: &DIBuilder<'a>,
2052 Scope: &'a DIDescriptor,
2053 Name: *const c_char,
74b04a01 2054 NameLen: size_t,
dfeec247
XL
2055 File: &'a DIFile,
2056 LineNo: c_uint,
2057 SizeInBits: u64,
2058 AlignInBits: u32,
2059 OffsetInBits: u64,
2060 Flags: DIFlags,
2061 Ty: &'a DIType,
2062 ) -> &'a DIDerivedType;
2063
a2a8927a 2064 pub fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
dfeec247
XL
2065 Builder: &DIBuilder<'a>,
2066 Scope: &'a DIScope,
2067 Name: *const c_char,
74b04a01 2068 NameLen: size_t,
dfeec247
XL
2069 File: &'a DIFile,
2070 LineNumber: c_uint,
2071 SizeInBits: u64,
2072 AlignInBits: u32,
2073 OffsetInBits: u64,
2074 Discriminant: Option<&'a Value>,
2075 Flags: DIFlags,
2076 Ty: &'a DIType,
2077 ) -> &'a DIType;
2078
f2b60f7d
FG
2079 pub fn LLVMRustDIBuilderCreateStaticMemberType<'a>(
2080 Builder: &DIBuilder<'a>,
2081 Scope: &'a DIDescriptor,
2082 Name: *const c_char,
2083 NameLen: size_t,
2084 File: &'a DIFile,
2085 LineNo: c_uint,
2086 Ty: &'a DIType,
2087 Flags: DIFlags,
2088 val: Option<&'a Value>,
2089 AlignInBits: u32,
2090 ) -> &'a DIDerivedType;
2091
a2a8927a 2092 pub fn LLVMRustDIBuilderCreateLexicalBlock<'a>(
dfeec247
XL
2093 Builder: &DIBuilder<'a>,
2094 Scope: &'a DIScope,
2095 File: &'a DIFile,
2096 Line: c_uint,
2097 Col: c_uint,
2098 ) -> &'a DILexicalBlock;
2099
a2a8927a 2100 pub fn LLVMRustDIBuilderCreateLexicalBlockFile<'a>(
dfeec247
XL
2101 Builder: &DIBuilder<'a>,
2102 Scope: &'a DIScope,
2103 File: &'a DIFile,
2104 ) -> &'a DILexicalBlock;
2105
a2a8927a 2106 pub fn LLVMRustDIBuilderCreateStaticVariable<'a>(
dfeec247
XL
2107 Builder: &DIBuilder<'a>,
2108 Context: Option<&'a DIScope>,
2109 Name: *const c_char,
74b04a01 2110 NameLen: size_t,
dfeec247 2111 LinkageName: *const c_char,
74b04a01 2112 LinkageNameLen: size_t,
dfeec247
XL
2113 File: &'a DIFile,
2114 LineNo: c_uint,
2115 Ty: &'a DIType,
2116 isLocalToUnit: bool,
2117 Val: &'a Value,
2118 Decl: Option<&'a DIDescriptor>,
2119 AlignInBits: u32,
2120 ) -> &'a DIGlobalVariableExpression;
2121
a2a8927a 2122 pub fn LLVMRustDIBuilderCreateVariable<'a>(
dfeec247
XL
2123 Builder: &DIBuilder<'a>,
2124 Tag: c_uint,
2125 Scope: &'a DIDescriptor,
2126 Name: *const c_char,
74b04a01 2127 NameLen: size_t,
dfeec247
XL
2128 File: &'a DIFile,
2129 LineNo: c_uint,
2130 Ty: &'a DIType,
2131 AlwaysPreserve: bool,
2132 Flags: DIFlags,
2133 ArgNo: c_uint,
2134 AlignInBits: u32,
2135 ) -> &'a DIVariable;
2136
a2a8927a 2137 pub fn LLVMRustDIBuilderCreateArrayType<'a>(
dfeec247
XL
2138 Builder: &DIBuilder<'a>,
2139 Size: u64,
2140 AlignInBits: u32,
2141 Ty: &'a DIType,
2142 Subscripts: &'a DIArray,
2143 ) -> &'a DIType;
2144
a2a8927a 2145 pub fn LLVMRustDIBuilderGetOrCreateSubrange<'a>(
dfeec247
XL
2146 Builder: &DIBuilder<'a>,
2147 Lo: i64,
2148 Count: i64,
2149 ) -> &'a DISubrange;
2150
a2a8927a 2151 pub fn LLVMRustDIBuilderGetOrCreateArray<'a>(
dfeec247
XL
2152 Builder: &DIBuilder<'a>,
2153 Ptr: *const Option<&'a DIDescriptor>,
2154 Count: c_uint,
2155 ) -> &'a DIArray;
2156
a2a8927a 2157 pub fn LLVMRustDIBuilderInsertDeclareAtEnd<'a>(
dfeec247
XL
2158 Builder: &DIBuilder<'a>,
2159 Val: &'a Value,
2160 VarInfo: &'a DIVariable,
a2a8927a 2161 AddrOps: *const u64,
dfeec247 2162 AddrOpsCount: c_uint,
29967ef6 2163 DL: &'a DILocation,
dfeec247
XL
2164 InsertAtEnd: &'a BasicBlock,
2165 ) -> &'a Value;
2166
a2a8927a 2167 pub fn LLVMRustDIBuilderCreateEnumerator<'a>(
dfeec247
XL
2168 Builder: &DIBuilder<'a>,
2169 Name: *const c_char,
74b04a01 2170 NameLen: size_t,
487cf647
FG
2171 Value: *const u64,
2172 SizeInBits: c_uint,
74b04a01 2173 IsUnsigned: bool,
dfeec247
XL
2174 ) -> &'a DIEnumerator;
2175
a2a8927a 2176 pub fn LLVMRustDIBuilderCreateEnumerationType<'a>(
dfeec247
XL
2177 Builder: &DIBuilder<'a>,
2178 Scope: &'a DIScope,
2179 Name: *const c_char,
74b04a01 2180 NameLen: size_t,
dfeec247
XL
2181 File: &'a DIFile,
2182 LineNumber: c_uint,
2183 SizeInBits: u64,
2184 AlignInBits: u32,
2185 Elements: &'a DIArray,
2186 ClassType: &'a DIType,
2187 IsScoped: bool,
2188 ) -> &'a DIType;
2189
a2a8927a 2190 pub fn LLVMRustDIBuilderCreateUnionType<'a>(
dfeec247 2191 Builder: &DIBuilder<'a>,
17df50a5 2192 Scope: Option<&'a DIScope>,
dfeec247 2193 Name: *const c_char,
74b04a01 2194 NameLen: size_t,
dfeec247
XL
2195 File: &'a DIFile,
2196 LineNumber: c_uint,
2197 SizeInBits: u64,
2198 AlignInBits: u32,
2199 Flags: DIFlags,
2200 Elements: Option<&'a DIArray>,
2201 RunTimeLang: c_uint,
2202 UniqueId: *const c_char,
74b04a01 2203 UniqueIdLen: size_t,
dfeec247
XL
2204 ) -> &'a DIType;
2205
a2a8927a 2206 pub fn LLVMRustDIBuilderCreateVariantPart<'a>(
dfeec247
XL
2207 Builder: &DIBuilder<'a>,
2208 Scope: &'a DIScope,
2209 Name: *const c_char,
74b04a01 2210 NameLen: size_t,
dfeec247
XL
2211 File: &'a DIFile,
2212 LineNo: c_uint,
2213 SizeInBits: u64,
2214 AlignInBits: u32,
2215 Flags: DIFlags,
2216 Discriminator: Option<&'a DIDerivedType>,
2217 Elements: &'a DIArray,
2218 UniqueId: *const c_char,
74b04a01 2219 UniqueIdLen: size_t,
dfeec247 2220 ) -> &'a DIDerivedType;
a1dfa0c6 2221
ba9703b0 2222 pub fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
b7449926 2223
a2a8927a 2224 pub fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>(
dfeec247
XL
2225 Builder: &DIBuilder<'a>,
2226 Scope: Option<&'a DIScope>,
2227 Name: *const c_char,
74b04a01 2228 NameLen: size_t,
dfeec247 2229 Ty: &'a DIType,
dfeec247
XL
2230 ) -> &'a DITemplateTypeParameter;
2231
a2a8927a 2232 pub fn LLVMRustDIBuilderCreateNameSpace<'a>(
dfeec247
XL
2233 Builder: &DIBuilder<'a>,
2234 Scope: Option<&'a DIScope>,
2235 Name: *const c_char,
74b04a01
XL
2236 NameLen: size_t,
2237 ExportSymbols: bool,
dfeec247
XL
2238 ) -> &'a DINameSpace;
2239
a2a8927a 2240 pub fn LLVMRustDICompositeTypeReplaceArrays<'a>(
dfeec247
XL
2241 Builder: &DIBuilder<'a>,
2242 CompositeType: &'a DIType,
2243 Elements: Option<&'a DIArray>,
2244 Params: Option<&'a DIArray>,
2245 );
2246
a2a8927a 2247 pub fn LLVMRustDIBuilderCreateDebugLocation<'a>(
dfeec247
XL
2248 Line: c_uint,
2249 Column: c_uint,
2250 Scope: &'a DIScope,
29967ef6
XL
2251 InlinedAt: Option<&'a DILocation>,
2252 ) -> &'a DILocation;
a2a8927a
XL
2253 pub fn LLVMRustDIBuilderCreateOpDeref() -> u64;
2254 pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> u64;
487cf647 2255 pub fn LLVMRustDIBuilderCreateOpLLVMFragment() -> u64;
b7449926 2256
0731742a 2257 #[allow(improper_ctypes)]
b7449926 2258 pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
0731742a 2259 #[allow(improper_ctypes)]
b7449926 2260 pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
b7449926 2261
e74abb32 2262 pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
b7449926 2263
b7449926
XL
2264 pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
2265
2266 pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine);
cdc7bbd5
XL
2267 pub fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t;
2268 pub fn LLVMRustGetTargetFeature(
2269 T: &TargetMachine,
2270 Index: size_t,
2271 Feature: &mut *const c_char,
2272 Desc: &mut *const c_char,
2273 );
b7449926
XL
2274
2275 pub fn LLVMRustGetHostCPUName(len: *mut usize) -> *const c_char;
dfeec247
XL
2276 pub fn LLVMRustCreateTargetMachine(
2277 Triple: *const c_char,
2278 CPU: *const c_char,
2279 Features: *const c_char,
2280 Abi: *const c_char,
2281 Model: CodeModel,
f9f354fc 2282 Reloc: RelocModel,
dfeec247
XL
2283 Level: CodeGenOptLevel,
2284 UseSoftFP: bool,
dfeec247
XL
2285 FunctionSections: bool,
2286 DataSections: bool,
3c0e092e 2287 UniqueSectionNames: bool,
dfeec247
XL
2288 TrapUnreachable: bool,
2289 Singlethread: bool,
2290 AsmComments: bool,
2291 EmitStackSizeSection: bool,
2292 RelaxELFRelocations: bool,
f9f354fc 2293 UseInitArray: bool,
fc512014 2294 SplitDwarfFile: *const c_char,
353b0b11 2295 ForceEmulatedTls: bool,
dfeec247 2296 ) -> Option<&'static mut TargetMachine>;
b7449926 2297 pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
a2a8927a 2298 pub fn LLVMRustAddLibraryInfo<'a>(
dfeec247
XL
2299 PM: &PassManager<'a>,
2300 M: &'a Module,
2301 DisableSimplifyLibCalls: bool,
2302 );
a2a8927a 2303 pub fn LLVMRustWriteOutputFile<'a>(
dfeec247
XL
2304 T: &'a TargetMachine,
2305 PM: &PassManager<'a>,
2306 M: &'a Module,
2307 Output: *const c_char,
fc512014 2308 DwoOutput: *const c_char,
dfeec247
XL
2309 FileType: FileType,
2310 ) -> LLVMRustResult;
2b03887a 2311 pub fn LLVMRustOptimize<'a>(
74b04a01
XL
2312 M: &'a Module,
2313 TM: &'a TargetMachine,
2314 OptLevel: PassBuilderOptLevel,
2315 OptStage: OptStage,
2316 NoPrepopulatePasses: bool,
2317 VerifyIR: bool,
2318 UseThinLTOBuffers: bool,
2319 MergeFunctions: bool,
2320 UnrollLoops: bool,
2321 SLPVectorize: bool,
2322 LoopVectorize: bool,
2323 DisableSimplifyLibCalls: bool,
f9f354fc 2324 EmitLifetimeMarkers: bool,
74b04a01
XL
2325 SanitizerOptions: Option<&SanitizerOptions>,
2326 PGOGenPath: *const c_char,
2327 PGOUsePath: *const c_char,
17df50a5 2328 InstrumentCoverage: bool,
f2b60f7d 2329 InstrProfileOutput: *const c_char,
17df50a5 2330 InstrumentGCOV: bool,
c295e0f8
XL
2331 PGOSampleUsePath: *const c_char,
2332 DebugInfoForProfiling: bool,
74b04a01
XL
2333 llvm_selfprofiler: *mut c_void,
2334 begin_callback: SelfProfileBeforePassCallback,
2335 end_callback: SelfProfileAfterPassCallback,
17df50a5
XL
2336 ExtraPasses: *const c_char,
2337 ExtraPassesLen: size_t,
a2a8927a
XL
2338 LLVMPlugins: *const c_char,
2339 LLVMPluginsLen: size_t,
17df50a5 2340 ) -> LLVMRustResult;
dfeec247 2341 pub fn LLVMRustPrintModule(
a2a8927a 2342 M: &Module,
dfeec247
XL
2343 Output: *const c_char,
2344 Demangle: extern "C" fn(*const c_char, size_t, *mut c_char, size_t) -> size_t,
2345 ) -> LLVMRustResult;
b7449926
XL
2346 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2347 pub fn LLVMRustPrintPasses();
2348 pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
b7449926 2349 pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
b7449926
XL
2350
2351 pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
a2a8927a
XL
2352 pub fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
2353 pub fn LLVMRustArchiveIteratorNext<'a>(
b7449926
XL
2354 AIR: &ArchiveIterator<'a>,
2355 ) -> Option<&'a mut ArchiveChild<'a>>;
9fa01778 2356 pub fn LLVMRustArchiveChildName(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
a2a8927a
XL
2357 pub fn LLVMRustArchiveChildFree<'a>(ACR: &'a mut ArchiveChild<'a>);
2358 pub fn LLVMRustArchiveIteratorFree<'a>(AIR: &'a mut ArchiveIterator<'a>);
b7449926
XL
2359 pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
2360
0731742a 2361 #[allow(improper_ctypes)]
b7449926 2362 pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
b7449926 2363
0731742a 2364 #[allow(improper_ctypes)]
a2a8927a 2365 pub fn LLVMRustUnpackOptimizationDiagnostic<'a>(
dfeec247
XL
2366 DI: &'a DiagnosticInfo,
2367 pass_name_out: &RustString,
2368 function_out: &mut Option<&'a Value>,
2369 loc_line_out: &mut c_uint,
2370 loc_column_out: &mut c_uint,
2371 loc_filename_out: &RustString,
2372 message_out: &RustString,
2373 );
2374
a2a8927a 2375 pub fn LLVMRustUnpackInlineAsmDiagnostic<'a>(
dfeec247 2376 DI: &'a DiagnosticInfo,
f035d41b 2377 level_out: &mut DiagnosticLevel,
dfeec247
XL
2378 cookie_out: &mut c_uint,
2379 message_out: &mut Option<&'a Twine>,
dfeec247 2380 );
b7449926 2381
0731742a 2382 #[allow(improper_ctypes)]
b7449926 2383 pub fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
b7449926
XL
2384 pub fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
2385
a2a8927a 2386 pub fn LLVMRustGetSMDiagnostic<'a>(
94222f64
XL
2387 DI: &'a DiagnosticInfo,
2388 cookie_out: &mut c_uint,
2389 ) -> &'a SMDiagnostic;
2390
0731742a 2391 #[allow(improper_ctypes)]
f9f354fc
XL
2392 pub fn LLVMRustUnpackSMDiagnostic(
2393 d: &SMDiagnostic,
2394 message_out: &RustString,
2395 buffer_out: &RustString,
f035d41b 2396 level_out: &mut DiagnosticLevel,
f9f354fc
XL
2397 loc_out: &mut c_uint,
2398 ranges_out: *mut c_uint,
2399 num_ranges: &mut usize,
2400 ) -> bool;
b7449926 2401
dfeec247
XL
2402 pub fn LLVMRustWriteArchive(
2403 Dst: *const c_char,
2404 NumMembers: size_t,
2405 Members: *const &RustArchiveMember<'_>,
2406 WriteSymbtab: bool,
2407 Kind: ArchiveKind,
2408 ) -> LLVMRustResult;
a2a8927a 2409 pub fn LLVMRustArchiveMemberNew<'a>(
dfeec247
XL
2410 Filename: *const c_char,
2411 Name: *const c_char,
2412 Child: Option<&ArchiveChild<'a>>,
2413 ) -> &'a mut RustArchiveMember<'a>;
a2a8927a 2414 pub fn LLVMRustArchiveMemberFree<'a>(Member: &'a mut RustArchiveMember<'a>);
b7449926 2415
17df50a5
XL
2416 pub fn LLVMRustWriteImportLibrary(
2417 ImportName: *const c_char,
2418 Path: *const c_char,
2419 Exports: *const LLVMRustCOFFShortExport,
2420 NumExports: usize,
2421 Machine: u16,
2422 MinGW: bool,
2423 ) -> LLVMRustResult;
2424
a2a8927a 2425 pub fn LLVMRustSetDataLayoutFromTargetMachine<'a>(M: &'a Module, TM: &'a TargetMachine);
b7449926 2426
9c376795 2427 pub fn LLVMRustBuildOperandBundleDef(
dfeec247 2428 Name: *const c_char,
9c376795 2429 Inputs: *const &'_ Value,
dfeec247 2430 NumInputs: c_uint,
9c376795 2431 ) -> &mut OperandBundleDef<'_>;
a2a8927a 2432 pub fn LLVMRustFreeOperandBundleDef<'a>(Bundle: &'a mut OperandBundleDef<'a>);
b7449926 2433
a2a8927a 2434 pub fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock);
b7449926 2435
a2a8927a 2436 pub fn LLVMRustSetComdat<'a>(M: &'a Module, V: &'a Value, Name: *const c_char, NameLen: size_t);
60c5eb7d 2437 pub fn LLVMRustSetModulePICLevel(M: &Module);
b7449926 2438 pub fn LLVMRustSetModulePIELevel(M: &Module);
6a06907d 2439 pub fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel);
b7449926
XL
2440 pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
2441 pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
2442 pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
2443 pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
2444 pub fn LLVMRustModuleCost(M: &Module) -> u64;
9ffffee4
FG
2445 #[allow(improper_ctypes)]
2446 pub fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString);
b7449926 2447
064997fb 2448 pub fn LLVMRustThinLTOBufferCreate(M: &Module, is_thin: bool) -> &'static mut ThinLTOBuffer;
b7449926
XL
2449 pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
2450 pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
2451 pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
2452 pub fn LLVMRustCreateThinLTOData(
2453 Modules: *const ThinLTOModule,
2454 NumModules: c_uint,
2455 PreservedSymbols: *const *const c_char,
2456 PreservedSymbolsLen: c_uint,
2457 ) -> Option<&'static mut ThinLTOData>;
f035d41b
XL
2458 pub fn LLVMRustPrepareThinLTORename(
2459 Data: &ThinLTOData,
2460 Module: &Module,
2461 Target: &TargetMachine,
2462 ) -> bool;
dfeec247
XL
2463 pub fn LLVMRustPrepareThinLTOResolveWeak(Data: &ThinLTOData, Module: &Module) -> bool;
2464 pub fn LLVMRustPrepareThinLTOInternalize(Data: &ThinLTOData, Module: &Module) -> bool;
f035d41b
XL
2465 pub fn LLVMRustPrepareThinLTOImport(
2466 Data: &ThinLTOData,
2467 Module: &Module,
2468 Target: &TargetMachine,
2469 ) -> bool;
b7449926 2470 pub fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
9fa01778 2471 pub fn LLVMRustParseBitcodeForLTO(
b7449926
XL
2472 Context: &Context,
2473 Data: *const u8,
2474 len: usize,
2475 Identifier: *const c_char,
2476 ) -> Option<&Module>;
f9f354fc
XL
2477 pub fn LLVMRustGetBitcodeSliceFromObjectData(
2478 Data: *const u8,
2479 len: usize,
2480 out_len: &mut usize,
2481 ) -> *const u8;
064997fb
FG
2482 pub fn LLVMRustThinLTOGetDICompileUnit(
2483 M: &Module,
2484 CU1: &mut *mut c_void,
2485 CU2: &mut *mut c_void,
2486 );
2487 pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
b7449926 2488
a2a8927a 2489 pub fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
dfeec247
XL
2490 pub fn LLVMRustLinkerAdd(
2491 linker: &Linker<'_>,
2492 bytecode: *const c_char,
2493 bytecode_len: usize,
2494 ) -> bool;
a2a8927a 2495 pub fn LLVMRustLinkerFree<'a>(linker: &'a mut Linker<'a>);
29967ef6
XL
2496 #[allow(improper_ctypes)]
2497 pub fn LLVMRustComputeLTOCacheKey(
2498 key_out: &RustString,
2499 mod_id: *const c_char,
2500 data: &ThinLTOData,
2501 );
a2a8927a
XL
2502
2503 pub fn LLVMRustContextGetDiagnosticHandler(Context: &Context) -> Option<&DiagnosticHandler>;
2504 pub fn LLVMRustContextSetDiagnosticHandler(
2505 context: &Context,
2506 diagnostic_handler: Option<&DiagnosticHandler>,
2507 );
2508 pub fn LLVMRustContextConfigureDiagnosticHandler(
2509 context: &Context,
2510 diagnostic_handler_callback: DiagnosticHandlerTy,
2511 diagnostic_handler_context: *mut c_void,
2512 remark_all_passes: bool,
2513 remark_passes: *const *const c_char,
2514 remark_passes_len: usize,
2515 );
2516
04454e1e
FG
2517 #[allow(improper_ctypes)]
2518 pub fn LLVMRustGetMangledName(V: &Value, out: &RustString);
064997fb
FG
2519
2520 pub fn LLVMRustGetElementTypeArgIndex(CallSite: &Value) -> i32;
487cf647
FG
2521
2522 pub fn LLVMRustIsBitcode(ptr: *const u8, len: usize) -> bool;
2523
2524 pub fn LLVMRustGetSymbols(
2525 buf_ptr: *const u8,
2526 buf_len: usize,
2527 state: *mut c_void,
2528 callback: GetSymbolsCallback,
2529 error_callback: GetSymbolsErrorCallback,
2530 ) -> *mut c_void;
b7449926 2531}