From b22c87703cc555a320f5b7511822fd8ac0085d2f Mon Sep 17 00:00:00 2001 From: Diggory Blake Date: Sun, 22 Jun 2025 21:37:00 +0100 Subject: [PATCH] Move all LLVM externs into the rustc_llvm crate in preparation for ctest --- Cargo.lock | 3 +- compiler/rustc_codegen_llvm/Cargo.toml | 3 +- compiler/rustc_codegen_llvm/src/abi.rs | 11 +- compiler/rustc_codegen_llvm/src/allocator.rs | 4 +- compiler/rustc_codegen_llvm/src/asm.rs | 2 +- compiler/rustc_codegen_llvm/src/attributes.rs | 5 +- .../rustc_codegen_llvm/src/back/archive.rs | 5 +- compiler/rustc_codegen_llvm/src/back/write.rs | 4 +- compiler/rustc_codegen_llvm/src/base.rs | 2 +- compiler/rustc_codegen_llvm/src/builder.rs | 23 +- .../src/builder/autodiff.rs | 3 +- compiler/rustc_codegen_llvm/src/callee.rs | 2 +- compiler/rustc_codegen_llvm/src/common.rs | 3 +- compiler/rustc_codegen_llvm/src/consts.rs | 3 +- compiler/rustc_codegen_llvm/src/context.rs | 8 +- .../src/coverageinfo/llvm_cov.rs | 3 +- .../src/coverageinfo/mapgen/covfun.rs | 17 +- .../src/coverageinfo/mapgen/spans.rs | 2 +- .../src/coverageinfo/mod.rs | 1 - .../rustc_codegen_llvm/src/debuginfo/gdb.rs | 2 +- .../src/debuginfo/metadata.rs | 29 +- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 2 +- compiler/rustc_codegen_llvm/src/declare.rs | 5 +- compiler/rustc_codegen_llvm/src/intrinsic.rs | 3 +- compiler/rustc_codegen_llvm/src/lib.rs | 1 - .../src/llvm/conversions.rs | 182 +++ .../rustc_codegen_llvm/src/llvm/diagnostic.rs | 2 +- .../rustc_codegen_llvm/src/llvm/enzyme_ffi.rs | 163 --- compiler/rustc_codegen_llvm/src/llvm/mod.rs | 52 +- compiler/rustc_codegen_llvm/src/type_.rs | 46 +- compiler/rustc_codegen_llvm/src/va_arg.rs | 2 +- compiler/rustc_codegen_llvm/src/value.rs | 30 - compiler/rustc_llvm/Cargo.toml | 2 + .../src/ffi/coverageinfo.rs} | 140 +- compiler/rustc_llvm/src/ffi/enzyme.rs | 152 +++ .../llvm/ffi.rs => rustc_llvm/src/ffi/mod.rs} | 1208 +++++++---------- compiler/rustc_llvm/src/impls.rs | 77 ++ compiler/rustc_llvm/src/lib.rs | 3 + triagebot.toml | 4 +- 39 files changed, 1068 insertions(+), 1141 deletions(-) create mode 100644 compiler/rustc_codegen_llvm/src/llvm/conversions.rs delete mode 100644 compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs delete mode 100644 compiler/rustc_codegen_llvm/src/value.rs rename compiler/{rustc_codegen_llvm/src/coverageinfo/ffi.rs => rustc_llvm/src/ffi/coverageinfo.rs} (51%) create mode 100644 compiler/rustc_llvm/src/ffi/enzyme.rs rename compiler/{rustc_codegen_llvm/src/llvm/ffi.rs => rustc_llvm/src/ffi/mod.rs} (57%) create mode 100644 compiler/rustc_llvm/src/impls.rs diff --git a/Cargo.lock b/Cargo.lock index 271a2f7962cac..23aefc314abc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3521,7 +3521,6 @@ dependencies = [ name = "rustc_codegen_llvm" version = "0.0.0" dependencies = [ - "bitflags", "gimli 0.31.1", "itertools", "libc", @@ -4101,8 +4100,10 @@ dependencies = [ name = "rustc_llvm" version = "0.0.0" dependencies = [ + "bitflags", "cc", "libc", + "rustc_macros", ] [[package]] diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index 88efc8ac96b57..25e64da05b43a 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -8,7 +8,6 @@ test = false [dependencies] # tidy-alphabetical-start -bitflags = "2.4.1" # To avoid duplicate dependencies, this should match the version of gimli used # by `rustc_codegen_ssa` via its `thorin-dwp` dependency. gimli = "0.31" @@ -38,7 +37,7 @@ rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } rustc_target = { path = "../rustc_target" } -serde = { version = "1", features = [ "derive" ]} +serde = { version = "1", features = ["derive"] } serde_json = "1" smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } tracing = "0.1" diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index 009e7e2487b66..520a369c2af5f 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -23,10 +23,9 @@ use smallvec::SmallVec; use crate::attributes::{self, llfn_attrs_from_instance}; use crate::builder::Builder; use crate::context::CodegenCx; -use crate::llvm::{self, Attribute, AttributePlace}; +use crate::llvm::{self, Attribute, AttributePlace, Value}; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; -use crate::value::Value; trait ArgAttributesExt { fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value); @@ -644,8 +643,12 @@ impl AbiBuilderMethods for Builder<'_, '_, '_> { } } -impl llvm::CallConv { - pub(crate) fn from_conv(conv: CanonAbi, arch: &str) -> Self { +pub(crate) trait CallConvExt { + fn from_conv(conv: CanonAbi, arch: &str) -> llvm::CallConv; +} + +impl CallConvExt for llvm::CallConv { + fn from_conv(conv: CanonAbi, arch: &str) -> Self { match conv { CanonAbi::C | CanonAbi::Rust => llvm::CCallConv, CanonAbi::RustCold => llvm::PreserveMost, diff --git a/compiler/rustc_codegen_llvm/src/allocator.rs b/compiler/rustc_codegen_llvm/src/allocator.rs index 2b5090ed6dbab..6baa5053d4ef9 100644 --- a/compiler/rustc_codegen_llvm/src/allocator.rs +++ b/compiler/rustc_codegen_llvm/src/allocator.rs @@ -114,7 +114,7 @@ fn create_const_value_function( name, llvm::CallConv::CCallConv, llvm::UnnamedAddr::Global, - llvm::Visibility::from_generic(tcx.sess.default_visibility()), + llvm::visibility_from_generic(tcx.sess.default_visibility()), ty, ); @@ -144,7 +144,7 @@ fn create_wrapper_function( from_name, llvm::CallConv::CCallConv, llvm::UnnamedAddr::Global, - llvm::Visibility::from_generic(tcx.sess.default_visibility()), + llvm::visibility_from_generic(tcx.sess.default_visibility()), ty, ); let no_return = if no_return { diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index a643a91141e19..497c928777c2e 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -16,9 +16,9 @@ use tracing::debug; use crate::builder::Builder; use crate::common::Funclet; use crate::context::CodegenCx; +use crate::llvm::Value; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; -use crate::value::Value; use crate::{attributes, llvm}; impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 1ea5a062254a3..a7af694a29868 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -12,8 +12,9 @@ use smallvec::SmallVec; use crate::context::CodegenCx; use crate::errors::SanitizerMemtagRequiresMte; use crate::llvm::AttributePlace::Function; -use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects}; -use crate::value::Value; +use crate::llvm::{ + self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects, Value, +}; use crate::{attributes, llvm_util}; pub(crate) fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) { diff --git a/compiler/rustc_codegen_llvm/src/back/archive.rs b/compiler/rustc_codegen_llvm/src/back/archive.rs index 0a161442933ab..2ca6c9a6a9839 100644 --- a/compiler/rustc_codegen_llvm/src/back/archive.rs +++ b/compiler/rustc_codegen_llvm/src/back/archive.rs @@ -11,7 +11,7 @@ use rustc_codegen_ssa::back::archive::{ use rustc_session::Session; use crate::llvm::archive_ro::{ArchiveRO, Child}; -use crate::llvm::{self, ArchiveKind, last_error}; +use crate::llvm::{self, last_error, parse_archive_kind}; /// Helper for adding many files to an archive. #[must_use = "must call build() to finish building the archive"] @@ -182,8 +182,7 @@ fn llvm_is_ec_object_file(buf: &[u8]) -> bool { impl<'a> LlvmArchiveBuilder<'a> { fn build_with_llvm(&mut self, output: &Path) -> io::Result { let kind = &*self.sess.target.archive_format; - let kind = kind - .parse::() + let kind = parse_archive_kind(kind) .map_err(|_| kind) .unwrap_or_else(|kind| self.sess.dcx().emit_fatal(UnknownArchiveKind { kind })); diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 506286fc2559b..264d30d9078ff 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -42,7 +42,7 @@ use crate::errors::{ }; use crate::llvm::diagnostic::OptimizationDiagnosticKind::*; use crate::llvm::{self, DiagnosticInfo}; -use crate::type_::Type; +use crate::type_::type_ptr_llcx; use crate::{LlvmCodegenBackend, ModuleLlvm, base, common, llvm_util}; pub(crate) fn llvm_err<'a>(dcx: DiagCtxtHandle<'_>, err: LlvmError<'a>) -> FatalError { @@ -1174,7 +1174,7 @@ fn create_msvc_imps( // underscores added in front). let prefix = if cgcx.target_arch == "x86" { "\x01__imp__" } else { "\x01__imp_" }; - let ptr_ty = Type::ptr_llcx(llcx); + let ptr_ty = type_ptr_llcx(llcx); let globals = base::iter_globals(llmod) .filter(|&val| { llvm::get_linkage(val) == llvm::Linkage::ExternalLinkage && !llvm::is_declaration(val) diff --git a/compiler/rustc_codegen_llvm/src/base.rs b/compiler/rustc_codegen_llvm/src/base.rs index 5dda836988c81..6bf6ba32bd964 100644 --- a/compiler/rustc_codegen_llvm/src/base.rs +++ b/compiler/rustc_codegen_llvm/src/base.rs @@ -29,7 +29,7 @@ use rustc_target::spec::SanitizerSet; use super::ModuleLlvm; use crate::builder::Builder; use crate::context::CodegenCx; -use crate::value::Value; +use crate::llvm::Value; use crate::{attributes, llvm}; pub(crate) struct ValueIter<'ll> { diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 9c3b866aa3c6f..fb5836f61c1c7 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -32,12 +32,9 @@ use crate::abi::FnAbiLlvmExt; use crate::attributes; use crate::common::Funclet; use crate::context::{CodegenCx, FullCx, GenericCx, SCx}; -use crate::llvm::{ - self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, GEPNoWrapFlags, Metadata, True, -}; +use crate::llvm::{self, BasicBlock, False, GEPNoWrapFlags, Metadata, True, Value}; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; -use crate::value::Value; #[must_use] pub(crate) struct GenericBuilder<'a, 'll, CX: Borrow>> { @@ -568,7 +565,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { ty, ptr, UNNAMED, - AtomicOrdering::from_generic(order), + llvm::atomic_ordering_from_generic(order), ); // LLVM requires the alignment of atomic loads to be at least the size of the type. llvm::LLVMSetAlignment(load, size.bytes() as c_uint); @@ -808,7 +805,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { self.llbuilder, val, ptr, - AtomicOrdering::from_generic(order), + llvm::atomic_ordering_from_generic(order), ); // LLVM requires the alignment of atomic stores to be at least the size of the type. llvm::LLVMSetAlignment(store, size.bytes() as c_uint); @@ -1005,12 +1002,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { /* Comparisons */ fn icmp(&mut self, op: IntPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { - let op = llvm::IntPredicate::from_generic(op); + let op = llvm::int_predicate_from_generic(op); unsafe { llvm::LLVMBuildICmp(self.llbuilder, op as c_uint, lhs, rhs, UNNAMED) } } fn fcmp(&mut self, op: RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { - let op = llvm::RealPredicate::from_generic(op); + let op = llvm::real_predicate_from_generic(op); unsafe { llvm::LLVMBuildFCmp(self.llbuilder, op as c_uint, lhs, rhs, UNNAMED) } } @@ -1246,8 +1243,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { dst, cmp, src, - AtomicOrdering::from_generic(order), - AtomicOrdering::from_generic(failure_order), + llvm::atomic_ordering_from_generic(order), + llvm::atomic_ordering_from_generic(failure_order), llvm::False, // SingleThreaded ); llvm::LLVMSetWeak(value, weak); @@ -1273,10 +1270,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { let mut res = unsafe { llvm::LLVMBuildAtomicRMW( self.llbuilder, - AtomicRmwBinOp::from_generic(op), + llvm::atomic_rmw_bin_op_from_generic(op), dst, src, - AtomicOrdering::from_generic(order), + llvm::atomic_ordering_from_generic(order), llvm::False, // SingleThreaded ) }; @@ -1298,7 +1295,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { unsafe { llvm::LLVMBuildFence( self.llbuilder, - AtomicOrdering::from_generic(order), + llvm::atomic_ordering_from_generic(order), single_threaded, UNNAMED, ); diff --git a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs index 5afb9a60d4241..cfbbb610ed260 100644 --- a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs +++ b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs @@ -15,8 +15,7 @@ use crate::context::SimpleCx; use crate::declare::declare_simple_fn; use crate::errors::{AutoDiffWithoutEnable, LlvmError}; use crate::llvm::AttributePlace::Function; -use crate::llvm::{Metadata, True}; -use crate::value::Value; +use crate::llvm::{Metadata, True, Value}; use crate::{CodegenContext, LlvmCodegenBackend, ModuleLlvm, attributes, llvm}; fn get_params(fnc: &Value) -> Vec<&Value> { diff --git a/compiler/rustc_codegen_llvm/src/callee.rs b/compiler/rustc_codegen_llvm/src/callee.rs index 6d68eca60afc1..719770365b875 100644 --- a/compiler/rustc_codegen_llvm/src/callee.rs +++ b/compiler/rustc_codegen_llvm/src/callee.rs @@ -11,7 +11,7 @@ use tracing::debug; use crate::context::CodegenCx; use crate::llvm; -use crate::value::Value; +use crate::llvm::Value; /// Codegens a reference to a fn/method item, monomorphizing and /// inlining as it goes. diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index b9b5c776d86aa..ec3525e1e1d82 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -20,9 +20,8 @@ use tracing::debug; use crate::consts::const_alloc_to_llvm; pub(crate) use crate::context::CodegenCx; use crate::context::{GenericCx, SCx}; -use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, Metadata, True}; +use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, Metadata, True, Value}; use crate::type_::Type; -use crate::value::Value; /* * A note on nomenclature of linking: "extern", "foreign", and "upcall". diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 5deddb3ed9819..e65a98835f572 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -19,10 +19,9 @@ use tracing::{debug, instrument, trace}; use crate::common::{AsCCharPtr, CodegenCx}; use crate::errors::SymbolAlreadyDefined; -use crate::llvm::{self, True}; +use crate::llvm::{self, True, Value}; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; -use crate::value::Value; use crate::{base, debuginfo}; pub(crate) fn const_alloc_to_llvm<'ll>( diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 90582e23b04cf..b2674816e7bec 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -32,13 +32,13 @@ use rustc_symbol_mangling::mangle_internal_symbol; use rustc_target::spec::{HasTargetSpec, RelocModel, SmallDataThresholdSupport, Target, TlsModel}; use smallvec::SmallVec; +use crate::abi::CallConvExt as _; use crate::back::write::to_llvm_code_model; use crate::callee::get_fn; use crate::common::AsCCharPtr; use crate::debuginfo::metadata::apply_vcall_visibility_metadata; -use crate::llvm::Metadata; -use crate::type_::Type; -use crate::value::Value; +use crate::llvm::{Metadata, Value}; +use crate::type_::{Type, type_ix_llcx}; use crate::{attributes, common, coverageinfo, debuginfo, llvm, llvm_util}; /// `TyCtxt` (and related cache datastructures) can't be move between threads. @@ -669,7 +669,7 @@ impl<'ll> SimpleCx<'ll> { llcx: &'ll llvm::Context, pointer_size: Size, ) -> Self { - let isize_ty = llvm::Type::ix_llcx(llcx, pointer_size.bits()); + let isize_ty = type_ix_llcx(llcx, pointer_size.bits()); Self(SCx { llmod, llcx, isize_ty }, PhantomData) } } diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs index 907d6d41a1fb5..90182fc13851d 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs @@ -2,8 +2,9 @@ use std::ffi::CString; +use rustc_llvm::ffi; + use crate::common::AsCCharPtr; -use crate::coverageinfo::ffi; use crate::llvm; pub(crate) fn covmap_var_name() -> CString { diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs index b704cf2b1cd46..d1baf8717c7d6 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs @@ -9,6 +9,7 @@ use std::sync::Arc; use rustc_abi::Align; use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods as _, ConstCodegenMethods}; +use rustc_llvm::ffi; use rustc_middle::mir::coverage::{ BasicCoverageBlock, CovTerm, CoverageIdsInfo, Expression, FunctionCoverageInfo, Mapping, MappingKind, Op, @@ -19,8 +20,8 @@ use rustc_target::spec::HasTargetSpec; use tracing::debug; use crate::common::CodegenCx; +use crate::coverageinfo::llvm_cov; use crate::coverageinfo::mapgen::{GlobalFileTable, VirtualFileMapping, spans}; -use crate::coverageinfo::{ffi, llvm_cov}; use crate::llvm; /// Intermediate coverage metadata for a single function, used to help build @@ -75,8 +76,6 @@ pub(crate) fn prepare_covfun_record<'tcx>( /// Convert the function's coverage-counter expressions into a form suitable for FFI. fn prepare_expressions(ids_info: &CoverageIdsInfo) -> Vec { - let counter_for_term = ffi::Counter::from_term; - // We know that LLVM will optimize out any unused expressions before // producing the final coverage map, so there's no need to do the same // thing on the Rust side unless we're confident we can do much better. @@ -85,12 +84,12 @@ fn prepare_expressions(ids_info: &CoverageIdsInfo) -> Vec ffi::ExprKind::Add, Op::Subtract => ffi::ExprKind::Subtract, }, - rhs: counter_for_term(rhs), + rhs: llvm::counter_from_term(rhs), }) .collect::>() } @@ -140,7 +139,7 @@ fn fill_region_tables<'tcx>( } else { CovTerm::Zero }; - ffi::Counter::from_term(term) + llvm::counter_from_term(term) }; let Some(coords) = make_coords(span) else { continue }; @@ -162,13 +161,15 @@ fn fill_region_tables<'tcx>( cov_span, true_counter: counter_for_bcb(true_bcb), false_counter: counter_for_bcb(false_bcb), - mcdc_branch_params: ffi::mcdc::BranchParameters::from(mcdc_params), + mcdc_branch_params: llvm::branch_parameters_from_condition_info(mcdc_params), }); } MappingKind::MCDCDecision(mcdc_decision_params) => { mcdc_decision_regions.push(ffi::MCDCDecisionRegion { cov_span, - mcdc_decision_params: ffi::mcdc::DecisionParameters::from(mcdc_decision_params), + mcdc_decision_params: llvm::decision_parameters_from_decision_info( + mcdc_decision_params, + ), }); } } diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs index 39a59560c9d3e..16d54c83689c6 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs @@ -1,8 +1,8 @@ +use rustc_llvm::ffi; use rustc_span::source_map::SourceMap; use rustc_span::{BytePos, Pos, SourceFile, Span}; use tracing::debug; -use crate::coverageinfo::ffi; use crate::coverageinfo::mapgen::LocalFileId; /// Line and byte-column coordinates of a source code span within some file. diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index eefbd7cf6c48b..1fc13619d17ea 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -14,7 +14,6 @@ use crate::builder::Builder; use crate::common::CodegenCx; use crate::llvm; -pub(crate) mod ffi; mod llvm_cov; mod mapgen; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs index 8f0948b8183bf..3118834b22d21 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs @@ -12,7 +12,7 @@ use rustc_span::sym; use crate::builder::Builder; use crate::common::CodegenCx; use crate::llvm; -use crate::value::Value; +use crate::llvm::Value; /// Inserts a side-effect free instruction sequence that makes sure that the /// .debug_gdb_scripts global is referenced, so it isn't removed by the linker. diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 9b4736e50e6c3..795e825543192 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1,6 +1,5 @@ use std::borrow::Cow; -use std::fmt::{self, Write}; -use std::hash::{Hash, Hasher}; +use std::fmt::Write; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::{iter, ptr}; @@ -38,31 +37,11 @@ use crate::debuginfo::dwarf_const; use crate::debuginfo::metadata::type_map::build_type_with_children; use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind}; use crate::llvm; +use crate::llvm::Value; use crate::llvm::debuginfo::{ DIBasicType, DIBuilder, DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock, - DIScope, DIType, DebugEmissionKind, DebugNameTableKind, + DIScope, DIType, DebugNameTableKind, }; -use crate::value::Value; - -impl PartialEq for llvm::Metadata { - fn eq(&self, other: &Self) -> bool { - ptr::eq(self, other) - } -} - -impl Eq for llvm::Metadata {} - -impl Hash for llvm::Metadata { - fn hash(&self, hasher: &mut H) { - (self as *const Self).hash(hasher); - } -} - -impl fmt::Debug for llvm::Metadata { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - (self as *const Self).fmt(f) - } -} pub(super) const UNKNOWN_LINE_NUMBER: c_uint = 0; pub(super) const UNKNOWN_COLUMN_NUMBER: c_uint = 0; @@ -926,7 +905,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>( .as_ref() .map(|f| f.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO).to_string_lossy()) .unwrap_or_default(); - let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo); + let kind = llvm::debug_emission_kind_from_generic(tcx.sess.opts.debuginfo); let dwarf_version = tcx.sess.dwarf_version(); let is_dwarf_kind = diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 5ca2505cec43b..19c892ebc6d45 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -34,11 +34,11 @@ use self::utils::{DIB, create_DIArray, is_node_local_to_unit}; use crate::builder::Builder; use crate::common::{AsCCharPtr, CodegenCx}; use crate::llvm; +use crate::llvm::Value; use crate::llvm::debuginfo::{ DIArray, DIBuilderBox, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope, DITemplateTypeParameter, DIType, DIVariable, }; -use crate::value::Value; mod create_scope_map; mod dwarf_const; diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index 2419ec1f88854..eef613744f5b8 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -26,9 +26,8 @@ use crate::abi::FnAbiLlvmExt; use crate::common::AsCCharPtr; use crate::context::{CodegenCx, GenericCx, SCx, SimpleCx}; use crate::llvm::AttributePlace::Function; -use crate::llvm::Visibility; +use crate::llvm::{Value, Visibility}; use crate::type_::Type; -use crate::value::Value; use crate::{attributes, llvm}; /// Declare a function with a SimpleCx. @@ -134,7 +133,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { unnamed: llvm::UnnamedAddr, fn_type: &'ll Type, ) -> &'ll Value { - let visibility = Visibility::from_generic(self.tcx.sess.default_visibility()); + let visibility = llvm::visibility_from_generic(self.tcx.sess.default_visibility()); declare_raw_fn(self, name, callconv, unnamed, visibility, fn_type) } diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index fcc0d378f0686..919dce2019ce2 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -21,11 +21,10 @@ use tracing::debug; use crate::abi::FnAbiLlvmExt; use crate::builder::Builder; use crate::context::CodegenCx; -use crate::llvm::{self, Metadata}; +use crate::llvm::{self, Metadata, Value}; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::va_arg::emit_va_arg; -use crate::value::Value; fn call_simple_intrinsic<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 63ca51b006d3e..3aece42bcab8d 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -75,7 +75,6 @@ mod mono_item; mod type_; mod type_of; mod va_arg; -mod value; rustc_fluent_macro::fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_codegen_llvm/src/llvm/conversions.rs b/compiler/rustc_codegen_llvm/src/llvm/conversions.rs new file mode 100644 index 0000000000000..27076d02719f5 --- /dev/null +++ b/compiler/rustc_codegen_llvm/src/llvm/conversions.rs @@ -0,0 +1,182 @@ +//! Simple conversions between generic and LLVM-specific types. +use rustc_llvm::ffi; + +pub(crate) fn int_predicate_from_generic( + intpre: rustc_codegen_ssa::common::IntPredicate, +) -> ffi::IntPredicate { + use rustc_codegen_ssa::common::IntPredicate as Common; + match intpre { + Common::IntEQ => ffi::IntPredicate::IntEQ, + Common::IntNE => ffi::IntPredicate::IntNE, + Common::IntUGT => ffi::IntPredicate::IntUGT, + Common::IntUGE => ffi::IntPredicate::IntUGE, + Common::IntULT => ffi::IntPredicate::IntULT, + Common::IntULE => ffi::IntPredicate::IntULE, + Common::IntSGT => ffi::IntPredicate::IntSGT, + Common::IntSGE => ffi::IntPredicate::IntSGE, + Common::IntSLT => ffi::IntPredicate::IntSLT, + Common::IntSLE => ffi::IntPredicate::IntSLE, + } +} + +pub(crate) fn real_predicate_from_generic( + realp: rustc_codegen_ssa::common::RealPredicate, +) -> ffi::RealPredicate { + use rustc_codegen_ssa::common::RealPredicate as Common; + match realp { + Common::RealPredicateFalse => ffi::RealPredicate::RealPredicateFalse, + Common::RealOEQ => ffi::RealPredicate::RealOEQ, + Common::RealOGT => ffi::RealPredicate::RealOGT, + Common::RealOGE => ffi::RealPredicate::RealOGE, + Common::RealOLT => ffi::RealPredicate::RealOLT, + Common::RealOLE => ffi::RealPredicate::RealOLE, + Common::RealONE => ffi::RealPredicate::RealONE, + Common::RealORD => ffi::RealPredicate::RealORD, + Common::RealUNO => ffi::RealPredicate::RealUNO, + Common::RealUEQ => ffi::RealPredicate::RealUEQ, + Common::RealUGT => ffi::RealPredicate::RealUGT, + Common::RealUGE => ffi::RealPredicate::RealUGE, + Common::RealULT => ffi::RealPredicate::RealULT, + Common::RealULE => ffi::RealPredicate::RealULE, + Common::RealUNE => ffi::RealPredicate::RealUNE, + Common::RealPredicateTrue => ffi::RealPredicate::RealPredicateTrue, + } +} + +pub(crate) fn type_kind_to_generic( + type_kind: ffi::TypeKind, +) -> rustc_codegen_ssa::common::TypeKind { + use rustc_codegen_ssa::common::TypeKind as Common; + match type_kind { + ffi::TypeKind::Void => Common::Void, + ffi::TypeKind::Half => Common::Half, + ffi::TypeKind::Float => Common::Float, + ffi::TypeKind::Double => Common::Double, + ffi::TypeKind::X86_FP80 => Common::X86_FP80, + ffi::TypeKind::FP128 => Common::FP128, + ffi::TypeKind::PPC_FP128 => Common::PPC_FP128, + ffi::TypeKind::Label => Common::Label, + ffi::TypeKind::Integer => Common::Integer, + ffi::TypeKind::Function => Common::Function, + ffi::TypeKind::Struct => Common::Struct, + ffi::TypeKind::Array => Common::Array, + ffi::TypeKind::Pointer => Common::Pointer, + ffi::TypeKind::Vector => Common::Vector, + ffi::TypeKind::Metadata => Common::Metadata, + ffi::TypeKind::Token => Common::Token, + ffi::TypeKind::ScalableVector => Common::ScalableVector, + ffi::TypeKind::BFloat => Common::BFloat, + ffi::TypeKind::X86_AMX => Common::X86_AMX, + } +} + +pub(crate) fn visibility_from_generic( + visibility: rustc_target::spec::SymbolVisibility, +) -> ffi::Visibility { + use rustc_target::spec::SymbolVisibility; + match visibility { + SymbolVisibility::Hidden => ffi::Visibility::Hidden, + SymbolVisibility::Protected => ffi::Visibility::Protected, + SymbolVisibility::Interposable => ffi::Visibility::Default, + } +} + +pub(crate) fn atomic_rmw_bin_op_from_generic( + op: rustc_codegen_ssa::common::AtomicRmwBinOp, +) -> ffi::AtomicRmwBinOp { + use rustc_codegen_ssa::common::AtomicRmwBinOp as Common; + match op { + Common::AtomicXchg => ffi::AtomicRmwBinOp::AtomicXchg, + Common::AtomicAdd => ffi::AtomicRmwBinOp::AtomicAdd, + Common::AtomicSub => ffi::AtomicRmwBinOp::AtomicSub, + Common::AtomicAnd => ffi::AtomicRmwBinOp::AtomicAnd, + Common::AtomicNand => ffi::AtomicRmwBinOp::AtomicNand, + Common::AtomicOr => ffi::AtomicRmwBinOp::AtomicOr, + Common::AtomicXor => ffi::AtomicRmwBinOp::AtomicXor, + Common::AtomicMax => ffi::AtomicRmwBinOp::AtomicMax, + Common::AtomicMin => ffi::AtomicRmwBinOp::AtomicMin, + Common::AtomicUMax => ffi::AtomicRmwBinOp::AtomicUMax, + Common::AtomicUMin => ffi::AtomicRmwBinOp::AtomicUMin, + } +} + +pub(crate) fn atomic_ordering_from_generic( + ao: rustc_middle::ty::AtomicOrdering, +) -> ffi::AtomicOrdering { + use rustc_middle::ty::AtomicOrdering as Common; + match ao { + Common::Relaxed => ffi::AtomicOrdering::Monotonic, + Common::Acquire => ffi::AtomicOrdering::Acquire, + Common::Release => ffi::AtomicOrdering::Release, + Common::AcqRel => ffi::AtomicOrdering::AcquireRelease, + Common::SeqCst => ffi::AtomicOrdering::SequentiallyConsistent, + } +} + +pub(crate) fn debug_emission_kind_from_generic( + kind: rustc_session::config::DebugInfo, +) -> ffi::debuginfo::DebugEmissionKind { + // We should be setting LLVM's emission kind to `LineTablesOnly` if + // we are compiling with "limited" debuginfo. However, some of the + // existing tools relied on slightly more debuginfo being generated than + // would be the case with `LineTablesOnly`, and we did not want to break + // these tools in a "drive-by fix", without a good idea or plan about + // what limited debuginfo should exactly look like. So for now we are + // instead adding a new debuginfo option "line-tables-only" so as to + // not break anything and to allow users to have 'limited' debug info. + // + // See https://github.com/rust-lang/rust/issues/60020 for details. + use rustc_session::config::DebugInfo; + match kind { + DebugInfo::None => ffi::debuginfo::DebugEmissionKind::NoDebug, + DebugInfo::LineDirectivesOnly => ffi::debuginfo::DebugEmissionKind::DebugDirectivesOnly, + DebugInfo::LineTablesOnly => ffi::debuginfo::DebugEmissionKind::LineTablesOnly, + DebugInfo::Limited | DebugInfo::Full => ffi::debuginfo::DebugEmissionKind::FullDebug, + } +} + +/// Constructs a new `Counter` of kind `CounterValueReference`. +pub(crate) fn counter_from_counter_value_reference( + counter_id: rustc_middle::mir::coverage::CounterId, +) -> ffi::Counter { + ffi::Counter { kind: ffi::CounterKind::CounterValueReference, id: counter_id.as_u32() } +} + +/// Constructs a new `Counter` of kind `Expression`. +pub(crate) fn counter_from_expression( + expression_id: rustc_middle::mir::coverage::ExpressionId, +) -> ffi::Counter { + ffi::Counter { kind: ffi::CounterKind::Expression, id: expression_id.as_u32() } +} + +pub(crate) fn counter_from_term(term: rustc_middle::mir::coverage::CovTerm) -> ffi::Counter { + use rustc_middle::mir::coverage::CovTerm; + match term { + CovTerm::Zero => ffi::Counter::ZERO, + CovTerm::Counter(id) => counter_from_counter_value_reference(id), + CovTerm::Expression(id) => counter_from_expression(id), + } +} + +pub(crate) fn branch_parameters_from_condition_info( + value: rustc_middle::mir::coverage::ConditionInfo, +) -> ffi::mcdc::BranchParameters { + let to_llvm_cond_id = |cond_id: Option| { + cond_id + .and_then(|id| ffi::mcdc::LLVMConditionId::try_from(id.as_usize()).ok()) + .unwrap_or(-1) + }; + let rustc_middle::mir::coverage::ConditionInfo { condition_id, true_next_id, false_next_id } = + value; + ffi::mcdc::BranchParameters { + condition_id: to_llvm_cond_id(Some(condition_id)), + condition_ids: [to_llvm_cond_id(false_next_id), to_llvm_cond_id(true_next_id)], + } +} + +pub(crate) fn decision_parameters_from_decision_info( + info: rustc_middle::mir::coverage::DecisionInfo, +) -> ffi::mcdc::DecisionParameters { + let rustc_middle::mir::coverage::DecisionInfo { bitmap_idx, num_conditions } = info; + ffi::mcdc::DecisionParameters { bitmap_idx, num_conditions } +} diff --git a/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs b/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs index 0e0f2b0eab016..59b2cd329ae76 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs @@ -6,7 +6,7 @@ use rustc_span::InnerSpan; pub(crate) use self::Diagnostic::*; use self::OptimizationDiagnosticKind::*; use super::{DiagnosticInfo, SMDiagnostic}; -use crate::value::Value; +use crate::llvm::Value; #[derive(Copy, Clone, Debug)] pub(crate) enum OptimizationDiagnosticKind { diff --git a/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs deleted file mode 100644 index c696b8d8ff25f..0000000000000 --- a/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs +++ /dev/null @@ -1,163 +0,0 @@ -#![expect(dead_code)] - -use libc::{c_char, c_uint}; - -use super::MetadataKindId; -use super::ffi::{AttributeKind, BasicBlock, Metadata, Module, Type, Value}; -use crate::llvm::Bool; - -#[link(name = "llvm-wrapper", kind = "static")] -unsafe extern "C" { - // Enzyme - pub(crate) safe fn LLVMRustHasMetadata(I: &Value, KindID: MetadataKindId) -> bool; - pub(crate) fn LLVMRustEraseInstUntilInclusive(BB: &BasicBlock, I: &Value); - pub(crate) fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>; - pub(crate) fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>; - pub(crate) fn LLVMRustEraseInstFromParent(V: &Value); - pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value; - pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool; - pub(crate) fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool; - pub(crate) fn LLVMRustGetArrayNumElements(Ty: &Type) -> u64; - pub(crate) fn LLVMRustHasFnAttribute( - F: &Value, - Name: *const c_char, - NameLen: libc::size_t, - ) -> bool; - pub(crate) fn LLVMRustRemoveFnAttribute(F: &Value, Name: *const c_char, NameLen: libc::size_t); - pub(crate) fn LLVMGetFirstFunction(M: &Module) -> Option<&Value>; - pub(crate) fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>; - pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex( - Fn: &Value, - index: c_uint, - kind: AttributeKind, - ); -} - -unsafe extern "C" { - // Enzyme - pub(crate) fn LLVMDumpModule(M: &Module); - pub(crate) fn LLVMDumpValue(V: &Value); - pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint; - pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type; - pub(crate) fn LLVMGetParams(Fnc: &Value, params: *mut &Value); - pub(crate) fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>; -} - -#[repr(C)] -#[derive(Copy, Clone, PartialEq)] -pub(crate) enum LLVMRustVerifierFailureAction { - LLVMAbortProcessAction = 0, - LLVMPrintMessageAction = 1, - LLVMReturnStatusAction = 2, -} - -#[cfg(llvm_enzyme)] -pub(crate) use self::Enzyme_AD::*; - -#[cfg(llvm_enzyme)] -pub(crate) mod Enzyme_AD { - use std::ffi::{CString, c_char}; - - use libc::c_void; - - unsafe extern "C" { - pub(crate) fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8); - pub(crate) fn EnzymeSetCLString(arg1: *mut ::std::os::raw::c_void, arg2: *const c_char); - } - unsafe extern "C" { - static mut EnzymePrintPerf: c_void; - static mut EnzymePrintActivity: c_void; - static mut EnzymePrintType: c_void; - static mut EnzymeFunctionToAnalyze: c_void; - static mut EnzymePrint: c_void; - static mut EnzymeStrictAliasing: c_void; - static mut looseTypeAnalysis: c_void; - static mut EnzymeInline: c_void; - static mut RustTypeRules: c_void; - } - pub(crate) fn set_print_perf(print: bool) { - unsafe { - EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintPerf), print as u8); - } - } - pub(crate) fn set_print_activity(print: bool) { - unsafe { - EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintActivity), print as u8); - } - } - pub(crate) fn set_print_type(print: bool) { - unsafe { - EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintType), print as u8); - } - } - pub(crate) fn set_print_type_fun(fun_name: &str) { - let c_fun_name = CString::new(fun_name).unwrap(); - unsafe { - EnzymeSetCLString( - std::ptr::addr_of_mut!(EnzymeFunctionToAnalyze), - c_fun_name.as_ptr() as *const c_char, - ); - } - } - pub(crate) fn set_print(print: bool) { - unsafe { - EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrint), print as u8); - } - } - pub(crate) fn set_strict_aliasing(strict: bool) { - unsafe { - EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeStrictAliasing), strict as u8); - } - } - pub(crate) fn set_loose_types(loose: bool) { - unsafe { - EnzymeSetCLBool(std::ptr::addr_of_mut!(looseTypeAnalysis), loose as u8); - } - } - pub(crate) fn set_inline(val: bool) { - unsafe { - EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeInline), val as u8); - } - } - pub(crate) fn set_rust_rules(val: bool) { - unsafe { - EnzymeSetCLBool(std::ptr::addr_of_mut!(RustTypeRules), val as u8); - } - } -} - -#[cfg(not(llvm_enzyme))] -pub(crate) use self::Fallback_AD::*; - -#[cfg(not(llvm_enzyme))] -pub(crate) mod Fallback_AD { - #![allow(unused_variables)] - - pub(crate) fn set_inline(val: bool) { - unimplemented!() - } - pub(crate) fn set_print_perf(print: bool) { - unimplemented!() - } - pub(crate) fn set_print_activity(print: bool) { - unimplemented!() - } - pub(crate) fn set_print_type(print: bool) { - unimplemented!() - } - pub(crate) fn set_print_type_fun(fun_name: &str) { - unimplemented!() - } - pub(crate) fn set_print(print: bool) { - unimplemented!() - } - pub(crate) fn set_strict_aliasing(strict: bool) { - unimplemented!() - } - pub(crate) fn set_loose_types(loose: bool) { - unimplemented!() - } - pub(crate) fn set_rust_rules(val: bool) { - unimplemented!() - } -} diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index 3fc83fca352a8..2b7ab7cdfde93 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -3,12 +3,11 @@ use std::ffi::{CStr, CString}; use std::num::NonZero; use std::ptr; -use std::str::FromStr; use std::string::FromUtf8Error; use libc::c_uint; use rustc_abi::{Align, Size, WrappingRange}; -use rustc_llvm::RustString; +use rustc_llvm::{RustString, ffi}; pub(crate) use self::CallConv::*; pub(crate) use self::CodeGenOptSize::*; @@ -17,20 +16,9 @@ pub(crate) use self::ffi::*; use crate::common::AsCCharPtr; pub(crate) mod archive_ro; +mod conversions; pub(crate) mod diagnostic; -pub(crate) mod enzyme_ffi; -mod ffi; - -pub(crate) use self::enzyme_ffi::*; - -impl LLVMRustResult { - pub(crate) fn into_result(self) -> Result<(), ()> { - match self { - LLVMRustResult::Success => Ok(()), - LLVMRustResult::Failure => Err(()), - } - } -} +pub(crate) use conversions::*; pub(crate) fn AddFunctionAttributes<'ll>( llfn: &'ll Value, @@ -178,18 +166,14 @@ pub(crate) enum CodeGenOptSize { CodeGenOptSizeAggressive = 2, } -impl FromStr for ArchiveKind { - type Err = (); - - fn from_str(s: &str) -> Result { - match s { - "gnu" => Ok(ArchiveKind::K_GNU), - "bsd" => Ok(ArchiveKind::K_BSD), - "darwin" => Ok(ArchiveKind::K_DARWIN), - "coff" => Ok(ArchiveKind::K_COFF), - "aix_big" => Ok(ArchiveKind::K_AIXBIG), - _ => Err(()), - } +pub(crate) fn parse_archive_kind(s: &str) -> Result { + match s { + "gnu" => Ok(ArchiveKind::K_GNU), + "bsd" => Ok(ArchiveKind::K_BSD), + "darwin" => Ok(ArchiveKind::K_DARWIN), + "coff" => Ok(ArchiveKind::K_COFF), + "aix_big" => Ok(ArchiveKind::K_AIXBIG), + _ => Err(()), } } @@ -229,20 +213,6 @@ pub(crate) fn set_thread_local_mode(global: &Value, mode: ThreadLocalMode) { } } -impl AttributeKind { - /// Create an LLVM Attribute with no associated value. - pub(crate) fn create_attr(self, llcx: &Context) -> &Attribute { - unsafe { LLVMRustCreateAttrNoValue(llcx, self) } - } -} - -impl MemoryEffects { - /// Create an LLVM Attribute with these memory effects. - pub(crate) fn create_attr(self, llcx: &Context) -> &Attribute { - unsafe { LLVMRustCreateMemoryEffectsAttr(llcx, self) } - } -} - pub(crate) fn set_section(llglobal: &Value, section_name: &CStr) { unsafe { LLVMSetSection(llglobal, section_name.as_ptr()); diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs index ee472e75ed41e..31a560ce8a578 100644 --- a/compiler/rustc_codegen_llvm/src/type_.rs +++ b/compiler/rustc_codegen_llvm/src/type_.rs @@ -1,6 +1,4 @@ use std::borrow::Borrow; -use std::hash::{Hash, Hasher}; -use std::{fmt, ptr}; use libc::{c_char, c_uint}; use rustc_abi::{AddressSpace, Align, Integer, Reg, Size}; @@ -15,36 +13,10 @@ use rustc_target::callconv::{CastTarget, FnAbi}; use crate::abi::{FnAbiLlvmExt, LlvmType}; use crate::context::{CodegenCx, GenericCx, SCx}; pub(crate) use crate::llvm::Type; -use crate::llvm::{Bool, False, Metadata, True}; +use crate::llvm::{Bool, False, Metadata, True, Value}; use crate::type_of::LayoutLlvmExt; -use crate::value::Value; use crate::{common, llvm}; -impl PartialEq for Type { - fn eq(&self, other: &Self) -> bool { - ptr::eq(self, other) - } -} - -impl Eq for Type {} - -impl Hash for Type { - fn hash(&self, state: &mut H) { - ptr::hash(self, state); - } -} - -impl fmt::Debug for Type { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str( - &llvm::build_string(|s| unsafe { - llvm::LLVMRustWriteTypeToString(self, s); - }) - .expect("non-UTF8 type description from LLVM"), - ) - } -} - impl<'ll> CodegenCx<'ll, '_> {} impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { pub(crate) fn type_named_struct(&self, name: &str) -> &'ll Type { @@ -204,7 +176,7 @@ impl<'ll, CX: Borrow>> BaseTypeCodegenMethods for GenericCx<'ll, CX> { } fn type_kind(&self, ty: &'ll Type) -> TypeKind { - unsafe { llvm::LLVMRustGetTypeKind(ty).to_generic() } + unsafe { llvm::type_kind_to_generic(llvm::LLVMRustGetTypeKind(ty)) } } fn type_ptr(&self) -> &'ll Type { @@ -251,15 +223,13 @@ impl<'ll, CX: Borrow>> BaseTypeCodegenMethods for GenericCx<'ll, CX> { } } -impl Type { - /// Creates an integer type with the given number of bits, e.g., i24 - pub(crate) fn ix_llcx(llcx: &llvm::Context, num_bits: u64) -> &Type { - unsafe { llvm::LLVMIntTypeInContext(llcx, num_bits as c_uint) } - } +/// Creates an integer type with the given number of bits, e.g., i24 +pub(crate) fn type_ix_llcx(llcx: &llvm::Context, num_bits: u64) -> &Type { + unsafe { llvm::LLVMIntTypeInContext(llcx, num_bits as c_uint) } +} - pub(crate) fn ptr_llcx(llcx: &llvm::Context) -> &Type { - unsafe { llvm::LLVMPointerTypeInContext(llcx, AddressSpace::ZERO.0) } - } +pub(crate) fn type_ptr_llcx(llcx: &llvm::Context) -> &Type { + unsafe { llvm::LLVMPointerTypeInContext(llcx, AddressSpace::ZERO.0) } } impl<'ll, 'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs index ce079f3cb0af1..c866e3571c701 100644 --- a/compiler/rustc_codegen_llvm/src/va_arg.rs +++ b/compiler/rustc_codegen_llvm/src/va_arg.rs @@ -9,9 +9,9 @@ use rustc_middle::ty::Ty; use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf}; use crate::builder::Builder; +use crate::llvm::Value; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; -use crate::value::Value; fn round_up_to_alignment<'ll>( bx: &mut Builder<'_, 'll, '_>, diff --git a/compiler/rustc_codegen_llvm/src/value.rs b/compiler/rustc_codegen_llvm/src/value.rs deleted file mode 100644 index 2eabac3be8c56..0000000000000 --- a/compiler/rustc_codegen_llvm/src/value.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::hash::{Hash, Hasher}; -use std::{fmt, ptr}; - -use crate::llvm; -pub(crate) use crate::llvm::Value; - -impl PartialEq for Value { - fn eq(&self, other: &Self) -> bool { - ptr::eq(self, other) - } -} - -impl Eq for Value {} - -impl Hash for Value { - fn hash(&self, hasher: &mut H) { - (self as *const Self).hash(hasher); - } -} - -impl fmt::Debug for Value { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str( - &llvm::build_string(|s| unsafe { - llvm::LLVMRustWriteValueToString(self, s); - }) - .expect("non-UTF8 value description from LLVM"), - ) - } -} diff --git a/compiler/rustc_llvm/Cargo.toml b/compiler/rustc_llvm/Cargo.toml index 061562b2ec5ed..3d8c57590a27d 100644 --- a/compiler/rustc_llvm/Cargo.toml +++ b/compiler/rustc_llvm/Cargo.toml @@ -5,7 +5,9 @@ edition = "2024" [dependencies] # tidy-alphabetical-start +bitflags = "2.4.1" libc = "0.2.73" +rustc_macros = { path = "../rustc_macros" } # tidy-alphabetical-end [build-dependencies] diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs b/compiler/rustc_llvm/src/ffi/coverageinfo.rs similarity index 51% rename from compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs rename to compiler/rustc_llvm/src/ffi/coverageinfo.rs index f6000e7284002..22892c14bdc50 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs +++ b/compiler/rustc_llvm/src/ffi/coverageinfo.rs @@ -1,9 +1,7 @@ -use rustc_middle::mir::coverage::{CounterId, CovTerm, ExpressionId}; - /// Must match the layout of `LLVMRustCounterKind`. #[derive(Copy, Clone, Debug)] #[repr(C)] -pub(crate) enum CounterKind { +pub enum CounterKind { Zero = 0, CounterValueReference = 1, Expression = 2, @@ -23,33 +21,15 @@ pub(crate) enum CounterKind { /// Must match the layout of `LLVMRustCounter`. #[derive(Copy, Clone, Debug)] #[repr(C)] -pub(crate) struct Counter { +pub struct Counter { // Important: The layout (order and types of fields) must match its C++ counterpart. - pub(crate) kind: CounterKind, - id: u32, + pub kind: CounterKind, + pub id: u32, } impl Counter { /// A `Counter` of kind `Zero`. For this counter kind, the `id` is not used. - pub(crate) const ZERO: Self = Self { kind: CounterKind::Zero, id: 0 }; - - /// Constructs a new `Counter` of kind `CounterValueReference`. - pub(crate) fn counter_value_reference(counter_id: CounterId) -> Self { - Self { kind: CounterKind::CounterValueReference, id: counter_id.as_u32() } - } - - /// Constructs a new `Counter` of kind `Expression`. - pub(crate) fn expression(expression_id: ExpressionId) -> Self { - Self { kind: CounterKind::Expression, id: expression_id.as_u32() } - } - - pub(crate) fn from_term(term: CovTerm) -> Self { - match term { - CovTerm::Zero => Self::ZERO, - CovTerm::Counter(id) => Self::counter_value_reference(id), - CovTerm::Expression(id) => Self::expression(id), - } - } + pub const ZERO: Self = Self { kind: CounterKind::Zero, id: 0 }; } /// Corresponds to enum `llvm::coverage::CounterExpression::ExprKind`. @@ -57,7 +37,7 @@ impl Counter { /// Must match the layout of `LLVMRustCounterExprKind`. #[derive(Copy, Clone, Debug)] #[repr(C)] -pub(crate) enum ExprKind { +pub enum ExprKind { Subtract = 0, Add = 1, } @@ -67,51 +47,29 @@ pub(crate) enum ExprKind { /// Must match the layout of `LLVMRustCounterExpression`. #[derive(Copy, Clone, Debug)] #[repr(C)] -pub(crate) struct CounterExpression { - pub(crate) kind: ExprKind, - pub(crate) lhs: Counter, - pub(crate) rhs: Counter, +pub struct CounterExpression { + pub kind: ExprKind, + pub lhs: Counter, + pub rhs: Counter, } -pub(crate) mod mcdc { - use rustc_middle::mir::coverage::{ConditionId, ConditionInfo, DecisionInfo}; - +pub mod mcdc { /// Must match the layout of `LLVMRustMCDCDecisionParameters`. #[repr(C)] #[derive(Clone, Copy, Debug, Default)] - pub(crate) struct DecisionParameters { - bitmap_idx: u32, - num_conditions: u16, + pub struct DecisionParameters { + pub bitmap_idx: u32, + pub num_conditions: u16, } - type LLVMConditionId = i16; + pub type LLVMConditionId = i16; /// Must match the layout of `LLVMRustMCDCBranchParameters`. #[repr(C)] #[derive(Clone, Copy, Debug, Default)] - pub(crate) struct BranchParameters { - condition_id: LLVMConditionId, - condition_ids: [LLVMConditionId; 2], - } - - impl From for BranchParameters { - fn from(value: ConditionInfo) -> Self { - let to_llvm_cond_id = |cond_id: Option| { - cond_id.and_then(|id| LLVMConditionId::try_from(id.as_usize()).ok()).unwrap_or(-1) - }; - let ConditionInfo { condition_id, true_next_id, false_next_id } = value; - Self { - condition_id: to_llvm_cond_id(Some(condition_id)), - condition_ids: [to_llvm_cond_id(false_next_id), to_llvm_cond_id(true_next_id)], - } - } - } - - impl From for DecisionParameters { - fn from(info: DecisionInfo) -> Self { - let DecisionInfo { bitmap_idx, num_conditions } = info; - Self { bitmap_idx, num_conditions } - } + pub struct BranchParameters { + pub condition_id: LLVMConditionId, + pub condition_ids: [LLVMConditionId; 2], } } @@ -120,20 +78,20 @@ pub(crate) mod mcdc { /// Must match the layout of `LLVMRustCoverageSpan`. #[derive(Clone, Debug)] #[repr(C)] -pub(crate) struct CoverageSpan { +pub struct CoverageSpan { /// Local index into the function's local-to-global file ID table. /// The value at that index is itself an index into the coverage filename /// table in the CGU's `__llvm_covmap` section. - pub(crate) file_id: u32, + pub file_id: u32, /// 1-based starting line of the source code span. - pub(crate) start_line: u32, + pub start_line: u32, /// 1-based starting column of the source code span. - pub(crate) start_col: u32, + pub start_col: u32, /// 1-based ending line of the source code span. - pub(crate) end_line: u32, + pub end_line: u32, /// 1-based ending column of the source code span. High bit must be unset. - pub(crate) end_col: u32, + pub end_col: u32, } /// Holds tables of the various region types in one struct. @@ -144,17 +102,17 @@ pub(crate) struct CoverageSpan { /// Each field name has a `_regions` suffix for improved readability after /// exhaustive destructing, which ensures that all region types are handled. #[derive(Clone, Debug, Default)] -pub(crate) struct Regions { - pub(crate) code_regions: Vec, - pub(crate) expansion_regions: Vec, - pub(crate) branch_regions: Vec, - pub(crate) mcdc_branch_regions: Vec, - pub(crate) mcdc_decision_regions: Vec, +pub struct Regions { + pub code_regions: Vec, + pub expansion_regions: Vec, + pub branch_regions: Vec, + pub mcdc_branch_regions: Vec, + pub mcdc_decision_regions: Vec, } impl Regions { /// Returns true if none of this structure's tables contain any regions. - pub(crate) fn has_no_regions(&self) -> bool { + pub fn has_no_regions(&self) -> bool { let Self { code_regions, expansion_regions, @@ -174,42 +132,42 @@ impl Regions { /// Must match the layout of `LLVMRustCoverageCodeRegion`. #[derive(Clone, Debug)] #[repr(C)] -pub(crate) struct CodeRegion { - pub(crate) cov_span: CoverageSpan, - pub(crate) counter: Counter, +pub struct CodeRegion { + pub cov_span: CoverageSpan, + pub counter: Counter, } /// Must match the layout of `LLVMRustCoverageExpansionRegion`. #[derive(Clone, Debug)] #[repr(C)] -pub(crate) struct ExpansionRegion { - pub(crate) cov_span: CoverageSpan, - pub(crate) expanded_file_id: u32, +pub struct ExpansionRegion { + pub cov_span: CoverageSpan, + pub expanded_file_id: u32, } /// Must match the layout of `LLVMRustCoverageBranchRegion`. #[derive(Clone, Debug)] #[repr(C)] -pub(crate) struct BranchRegion { - pub(crate) cov_span: CoverageSpan, - pub(crate) true_counter: Counter, - pub(crate) false_counter: Counter, +pub struct BranchRegion { + pub cov_span: CoverageSpan, + pub true_counter: Counter, + pub false_counter: Counter, } /// Must match the layout of `LLVMRustCoverageMCDCBranchRegion`. #[derive(Clone, Debug)] #[repr(C)] -pub(crate) struct MCDCBranchRegion { - pub(crate) cov_span: CoverageSpan, - pub(crate) true_counter: Counter, - pub(crate) false_counter: Counter, - pub(crate) mcdc_branch_params: mcdc::BranchParameters, +pub struct MCDCBranchRegion { + pub cov_span: CoverageSpan, + pub true_counter: Counter, + pub false_counter: Counter, + pub mcdc_branch_params: mcdc::BranchParameters, } /// Must match the layout of `LLVMRustCoverageMCDCDecisionRegion`. #[derive(Clone, Debug)] #[repr(C)] -pub(crate) struct MCDCDecisionRegion { - pub(crate) cov_span: CoverageSpan, - pub(crate) mcdc_decision_params: mcdc::DecisionParameters, +pub struct MCDCDecisionRegion { + pub cov_span: CoverageSpan, + pub mcdc_decision_params: mcdc::DecisionParameters, } diff --git a/compiler/rustc_llvm/src/ffi/enzyme.rs b/compiler/rustc_llvm/src/ffi/enzyme.rs new file mode 100644 index 0000000000000..998d72d30c438 --- /dev/null +++ b/compiler/rustc_llvm/src/ffi/enzyme.rs @@ -0,0 +1,152 @@ +#![allow(non_camel_case_types)] + +use libc::{c_char, c_uint}; + +use super::{AttributeKind, BasicBlock, Bool, Metadata, MetadataKindId, Module, Type, Value}; + +#[link(name = "llvm-wrapper", kind = "static")] +unsafe extern "C" { + // Enzyme + pub safe fn LLVMRustHasMetadata(I: &Value, KindID: MetadataKindId) -> bool; + pub fn LLVMRustEraseInstUntilInclusive(BB: &BasicBlock, I: &Value); + pub fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>; + pub fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>; + pub fn LLVMRustEraseInstFromParent(V: &Value); + pub fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value; + pub fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool; + pub fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool; + pub fn LLVMRustGetArrayNumElements(Ty: &Type) -> u64; + pub fn LLVMRustHasFnAttribute(F: &Value, Name: *const c_char, NameLen: libc::size_t) -> bool; + pub fn LLVMRustRemoveFnAttribute(F: &Value, Name: *const c_char, NameLen: libc::size_t); + pub fn LLVMRustRemoveEnumAttributeAtIndex(Fn: &Value, index: c_uint, kind: AttributeKind); +} + +unsafe extern "C" { + // Enzyme + pub fn LLVMDumpModule(M: &Module); + pub fn LLVMDumpValue(V: &Value); + pub fn LLVMGetFunctionCallConv(F: &Value) -> c_uint; + pub fn LLVMGetReturnType(T: &Type) -> &Type; + pub fn LLVMGetParams(Fnc: &Value, params: *mut &Value); + pub fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>; + pub fn LLVMGetFirstFunction(M: &Module) -> Option<&Value>; + pub fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>; +} + +#[repr(C)] +#[derive(Copy, Clone, PartialEq)] +pub enum LLVMRustVerifierFailureAction { + LLVMAbortProcessAction = 0, + LLVMPrintMessageAction = 1, + LLVMReturnStatusAction = 2, +} + +#[cfg(llvm_enzyme)] +pub use self::enzyme_ad::*; + +#[cfg(llvm_enzyme)] +pub mod enzyme_ad { + use std::ffi::{CString, c_char}; + + use libc::c_void; + unsafe extern "C" { + pub fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8); + pub fn EnzymeSetCLString(arg1: *mut ::std::os::raw::c_void, arg2: *const c_char); + } + unsafe extern "C" { + static mut EnzymePrintPerf: c_void; + static mut EnzymePrintActivity: c_void; + static mut EnzymePrintType: c_void; + static mut EnzymeFunctionToAnalyze: c_void; + static mut EnzymePrint: c_void; + static mut EnzymeStrictAliasing: c_void; + static mut looseTypeAnalysis: c_void; + static mut EnzymeInline: c_void; + static mut RustTypeRules: c_void; + } + pub fn set_print_perf(print: bool) { + unsafe { + EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintPerf), print as u8); + } + } + pub fn set_print_activity(print: bool) { + unsafe { + EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintActivity), print as u8); + } + } + pub fn set_print_type(print: bool) { + unsafe { + EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintType), print as u8); + } + } + pub fn set_print_type_fun(fun_name: &str) { + let c_fun_name = CString::new(fun_name).unwrap(); + unsafe { + EnzymeSetCLString( + std::ptr::addr_of_mut!(EnzymeFunctionToAnalyze), + c_fun_name.as_ptr() as *const c_char, + ); + } + } + pub fn set_print(print: bool) { + unsafe { + EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrint), print as u8); + } + } + pub fn set_strict_aliasing(strict: bool) { + unsafe { + EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeStrictAliasing), strict as u8); + } + } + pub fn set_loose_types(loose: bool) { + unsafe { + EnzymeSetCLBool(std::ptr::addr_of_mut!(looseTypeAnalysis), loose as u8); + } + } + pub fn set_inline(val: bool) { + unsafe { + EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeInline), val as u8); + } + } + pub fn set_rust_rules(val: bool) { + unsafe { + EnzymeSetCLBool(std::ptr::addr_of_mut!(RustTypeRules), val as u8); + } + } +} + +#[cfg(not(llvm_enzyme))] +pub use self::fallback_ad::*; + +#[cfg(not(llvm_enzyme))] +pub mod fallback_ad { + #![allow(unused_variables)] + + pub fn set_inline(val: bool) { + unimplemented!() + } + pub fn set_print_perf(print: bool) { + unimplemented!() + } + pub fn set_print_activity(print: bool) { + unimplemented!() + } + pub fn set_print_type(print: bool) { + unimplemented!() + } + pub fn set_print_type_fun(fun_name: &str) { + unimplemented!() + } + pub fn set_print(print: bool) { + unimplemented!() + } + pub fn set_strict_aliasing(strict: bool) { + unimplemented!() + } + pub fn set_loose_types(loose: bool) { + unimplemented!() + } + pub fn set_rust_rules(val: bool) { + unimplemented!() + } +} diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_llvm/src/ffi/mod.rs similarity index 57% rename from compiler/rustc_codegen_llvm/src/llvm/ffi.rs rename to compiler/rustc_llvm/src/ffi/mod.rs index 5c34ab2e3040d..9782dcc3b7fb7 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_llvm/src/ffi/mod.rs @@ -19,24 +19,28 @@ use std::num::NonZero; use std::ptr; use bitflags::bitflags; -use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t}; -use rustc_macros::TryFromU32; -use rustc_target::spec::SymbolVisibility; - -use super::RustString; -use super::debuginfo::{ +use debuginfo::{ DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, DebugNameTableKind, }; -use crate::llvm; +use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t}; +use rustc_macros::TryFromU32; + +use super::RustString; + +mod coverageinfo; +mod enzyme; + +pub use coverageinfo::*; +pub use enzyme::*; /// In the LLVM-C API, boolean values are passed as `typedef int LLVMBool`, /// which has a different ABI from Rust or C++ `bool`. -pub(crate) type Bool = c_int; +pub type Bool = c_int; -pub(crate) const True: Bool = 1 as Bool; -pub(crate) const False: Bool = 0 as Bool; +pub const True: Bool = 1 as Bool; +pub const False: Bool = 0 as Bool; /// Wrapper for a raw enum value returned from LLVM's C APIs. /// @@ -45,7 +49,7 @@ pub(crate) const False: Bool = 0 as Bool; /// value and returns it. Instead, return this raw wrapper, then convert to the /// Rust-side enum explicitly. #[repr(transparent)] -pub(crate) struct RawEnum { +pub struct RawEnum { value: u32, /// We don't own or consume a `T`, but we can produce one. _rust_side_type: PhantomData T>, @@ -53,7 +57,7 @@ pub(crate) struct RawEnum { impl> RawEnum { #[track_caller] - pub(crate) fn to_rust(self) -> T + pub fn to_rust(self) -> T where T::Error: Debug, { @@ -64,12 +68,20 @@ impl> RawEnum { #[derive(Copy, Clone, PartialEq)] #[repr(C)] -#[allow(dead_code)] // Variants constructed by C++. -pub(crate) enum LLVMRustResult { +pub enum LLVMRustResult { Success, Failure, } +impl LLVMRustResult { + pub fn into_result(self) -> Result<(), ()> { + match self { + LLVMRustResult::Success => Ok(()), + LLVMRustResult::Failure => Err(()), + } + } +} + /// Must match the layout of `LLVMRustModuleFlagMergeBehavior`. /// /// When merging modules (e.g. during LTO), their metadata flags are combined. Conflicts are @@ -84,7 +96,7 @@ pub(crate) enum LLVMRustResult { /// C++ API. #[derive(Copy, Clone, PartialEq)] #[repr(C)] -pub(crate) enum ModuleFlagMergeBehavior { +pub enum ModuleFlagMergeBehavior { Error = 1, Warning = 2, Require = 3, @@ -102,7 +114,7 @@ pub(crate) enum ModuleFlagMergeBehavior { /// See #[derive(Copy, Clone, PartialEq, Debug, TryFromU32)] #[repr(C)] -pub(crate) enum CallConv { +pub enum CallConv { CCallConv = 0, FastCallConv = 8, ColdCallConv = 9, @@ -127,7 +139,7 @@ pub(crate) enum CallConv { /// Must match the layout of `LLVMLinkage`. #[derive(Copy, Clone, PartialEq, TryFromU32)] #[repr(C)] -pub(crate) enum Linkage { +pub enum Linkage { ExternalLinkage = 0, AvailableExternallyLinkage = 1, LinkOnceAnyLinkage = 2, @@ -154,27 +166,16 @@ pub(crate) enum Linkage { /// Must match the layout of `LLVMVisibility`. #[repr(C)] #[derive(Copy, Clone, PartialEq, TryFromU32)] -pub(crate) enum Visibility { +pub enum Visibility { Default = 0, Hidden = 1, Protected = 2, } -impl Visibility { - pub(crate) fn from_generic(visibility: SymbolVisibility) -> Self { - match visibility { - SymbolVisibility::Hidden => Visibility::Hidden, - SymbolVisibility::Protected => Visibility::Protected, - SymbolVisibility::Interposable => Visibility::Default, - } - } -} - /// LLVMUnnamedAddr #[repr(C)] -pub(crate) enum UnnamedAddr { +pub enum UnnamedAddr { No, - #[expect(dead_code)] Local, Global, } @@ -182,21 +183,18 @@ pub(crate) enum UnnamedAddr { /// LLVMDLLStorageClass #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum DLLStorageClass { - #[allow(dead_code)] +pub enum DLLStorageClass { Default = 0, DllImport = 1, // Function to be imported from DLL. - #[allow(dead_code)] DllExport = 2, // Function to be accessible from DLL. } /// Must match the layout of `LLVMRustAttributeKind`. -/// Semantically a subset of the C++ enum llvm::Attribute::AttrKind, +/// Semantically a subset of the C++ enum super::Attribute::AttrKind, /// though it is not ABI compatible (since it's a C++ enum) #[repr(C)] #[derive(Copy, Clone, Debug)] -#[expect(dead_code, reason = "Some variants are unused, but are kept to match the C++")] -pub(crate) enum AttributeKind { +pub enum AttributeKind { AlwaysInline = 0, ByVal = 1, Cold = 2, @@ -241,10 +239,17 @@ pub(crate) enum AttributeKind { DeadOnUnwind = 43, } +impl AttributeKind { + /// Create an LLVM Attribute with no associated value. + pub fn create_attr(self, llcx: &Context) -> &Attribute { + unsafe { LLVMRustCreateAttrNoValue(llcx, self) } + } +} + /// LLVMIntPredicate #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum IntPredicate { +pub enum IntPredicate { IntEQ = 32, IntNE = 33, IntUGT = 34, @@ -257,28 +262,10 @@ pub(crate) enum IntPredicate { IntSLE = 41, } -impl IntPredicate { - pub(crate) fn from_generic(intpre: rustc_codegen_ssa::common::IntPredicate) -> Self { - use rustc_codegen_ssa::common::IntPredicate as Common; - match intpre { - Common::IntEQ => Self::IntEQ, - Common::IntNE => Self::IntNE, - Common::IntUGT => Self::IntUGT, - Common::IntUGE => Self::IntUGE, - Common::IntULT => Self::IntULT, - Common::IntULE => Self::IntULE, - Common::IntSGT => Self::IntSGT, - Common::IntSGE => Self::IntSGE, - Common::IntSLT => Self::IntSLT, - Common::IntSLE => Self::IntSLE, - } - } -} - /// LLVMRealPredicate #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum RealPredicate { +pub enum RealPredicate { RealPredicateFalse = 0, RealOEQ = 1, RealOGT = 2, @@ -297,35 +284,10 @@ pub(crate) enum RealPredicate { RealPredicateTrue = 15, } -impl RealPredicate { - pub(crate) fn from_generic(realp: rustc_codegen_ssa::common::RealPredicate) -> Self { - use rustc_codegen_ssa::common::RealPredicate as Common; - match realp { - Common::RealPredicateFalse => Self::RealPredicateFalse, - Common::RealOEQ => Self::RealOEQ, - Common::RealOGT => Self::RealOGT, - Common::RealOGE => Self::RealOGE, - Common::RealOLT => Self::RealOLT, - Common::RealOLE => Self::RealOLE, - Common::RealONE => Self::RealONE, - Common::RealORD => Self::RealORD, - Common::RealUNO => Self::RealUNO, - Common::RealUEQ => Self::RealUEQ, - Common::RealUGT => Self::RealUGT, - Common::RealUGE => Self::RealUGE, - Common::RealULT => Self::RealULT, - Common::RealULE => Self::RealULE, - Common::RealUNE => Self::RealUNE, - Common::RealPredicateTrue => Self::RealPredicateTrue, - } - } -} - /// LLVMTypeKind #[derive(Copy, Clone, PartialEq, Debug)] #[repr(C)] -#[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")] -pub(crate) enum TypeKind { +pub enum TypeKind { Void = 0, Half = 1, Float = 2, @@ -347,37 +309,10 @@ pub(crate) enum TypeKind { X86_AMX = 19, } -impl TypeKind { - pub(crate) fn to_generic(self) -> rustc_codegen_ssa::common::TypeKind { - use rustc_codegen_ssa::common::TypeKind as Common; - match self { - Self::Void => Common::Void, - Self::Half => Common::Half, - Self::Float => Common::Float, - Self::Double => Common::Double, - Self::X86_FP80 => Common::X86_FP80, - Self::FP128 => Common::FP128, - Self::PPC_FP128 => Common::PPC_FP128, - Self::Label => Common::Label, - Self::Integer => Common::Integer, - Self::Function => Common::Function, - Self::Struct => Common::Struct, - Self::Array => Common::Array, - Self::Pointer => Common::Pointer, - Self::Vector => Common::Vector, - Self::Metadata => Common::Metadata, - Self::Token => Common::Token, - Self::ScalableVector => Common::ScalableVector, - Self::BFloat => Common::BFloat, - Self::X86_AMX => Common::X86_AMX, - } - } -} - /// LLVMAtomicRmwBinOp #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum AtomicRmwBinOp { +pub enum AtomicRmwBinOp { AtomicXchg = 0, AtomicAdd = 1, AtomicSub = 2, @@ -391,32 +326,11 @@ pub(crate) enum AtomicRmwBinOp { AtomicUMin = 10, } -impl AtomicRmwBinOp { - pub(crate) fn from_generic(op: rustc_codegen_ssa::common::AtomicRmwBinOp) -> Self { - use rustc_codegen_ssa::common::AtomicRmwBinOp as Common; - match op { - Common::AtomicXchg => Self::AtomicXchg, - Common::AtomicAdd => Self::AtomicAdd, - Common::AtomicSub => Self::AtomicSub, - Common::AtomicAnd => Self::AtomicAnd, - Common::AtomicNand => Self::AtomicNand, - Common::AtomicOr => Self::AtomicOr, - Common::AtomicXor => Self::AtomicXor, - Common::AtomicMax => Self::AtomicMax, - Common::AtomicMin => Self::AtomicMin, - Common::AtomicUMax => Self::AtomicUMax, - Common::AtomicUMin => Self::AtomicUMin, - } - } -} - /// LLVMAtomicOrdering #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum AtomicOrdering { - #[allow(dead_code)] +pub enum AtomicOrdering { NotAtomic = 0, - #[allow(dead_code)] Unordered = 1, Monotonic = 2, // Consume = 3, // Not specified yet. @@ -426,23 +340,10 @@ pub(crate) enum AtomicOrdering { SequentiallyConsistent = 7, } -impl AtomicOrdering { - pub(crate) fn from_generic(ao: rustc_middle::ty::AtomicOrdering) -> Self { - use rustc_middle::ty::AtomicOrdering as Common; - match ao { - Common::Relaxed => Self::Monotonic, - Common::Acquire => Self::Acquire, - Common::Release => Self::Release, - Common::AcqRel => Self::AcquireRelease, - Common::SeqCst => Self::SequentiallyConsistent, - } - } -} - /// LLVMRustFileType #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum FileType { +pub enum FileType { AssemblyFile, ObjectFile, } @@ -450,8 +351,7 @@ pub(crate) enum FileType { /// LLVMMetadataType #[derive(Copy, Clone)] #[repr(C)] -#[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")] -pub(crate) enum MetadataType { +pub enum MetadataType { MD_dbg = 0, MD_tbaa = 1, MD_prof = 2, @@ -475,7 +375,7 @@ pub(crate) enum MetadataType { /// Must match the layout of `LLVMInlineAsmDialect`. #[derive(Copy, Clone, PartialEq)] #[repr(C)] -pub(crate) enum AsmDialect { +pub enum AsmDialect { Att, Intel, } @@ -483,7 +383,7 @@ pub(crate) enum AsmDialect { /// LLVMRustCodeGenOptLevel #[derive(Copy, Clone, PartialEq)] #[repr(C)] -pub(crate) enum CodeGenOptLevel { +pub enum CodeGenOptLevel { None, Less, Default, @@ -492,7 +392,7 @@ pub(crate) enum CodeGenOptLevel { /// LLVMRustPassBuilderOptLevel #[repr(C)] -pub(crate) enum PassBuilderOptLevel { +pub enum PassBuilderOptLevel { O0, O1, O2, @@ -504,7 +404,7 @@ pub(crate) enum PassBuilderOptLevel { /// LLVMRustOptStage #[derive(PartialEq)] #[repr(C)] -pub(crate) enum OptStage { +pub enum OptStage { PreLinkNoLTO, PreLinkThinLTO, PreLinkFatLTO, @@ -514,7 +414,7 @@ pub(crate) enum OptStage { /// LLVMRustSanitizerOptions #[repr(C)] -pub(crate) struct SanitizerOptions { +pub struct SanitizerOptions { pub sanitize_address: bool, pub sanitize_address_recover: bool, pub sanitize_cfi: bool, @@ -535,7 +435,7 @@ pub(crate) struct SanitizerOptions { /// LLVMRustRelocModel #[derive(Copy, Clone, PartialEq)] #[repr(C)] -pub(crate) enum RelocModel { +pub enum RelocModel { Static, PIC, DynamicNoPic, @@ -547,7 +447,7 @@ pub(crate) enum RelocModel { /// LLVMRustFloatABI #[derive(Copy, Clone, PartialEq)] #[repr(C)] -pub(crate) enum FloatAbi { +pub enum FloatAbi { Default, Soft, Hard, @@ -556,7 +456,7 @@ pub(crate) enum FloatAbi { /// LLVMRustCodeModel #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum CodeModel { +pub enum CodeModel { Tiny, Small, Kernel, @@ -568,8 +468,7 @@ pub(crate) enum CodeModel { /// LLVMRustDiagnosticKind #[derive(Copy, Clone)] #[repr(C)] -#[allow(dead_code)] // Variants constructed by C++. -pub(crate) enum DiagnosticKind { +pub enum DiagnosticKind { Other, InlineAsm, StackSize, @@ -591,8 +490,7 @@ pub(crate) enum DiagnosticKind { /// LLVMRustDiagnosticLevel #[derive(Copy, Clone)] #[repr(C)] -#[allow(dead_code)] // Variants constructed by C++. -pub(crate) enum DiagnosticLevel { +pub enum DiagnosticLevel { Error, Warning, Note, @@ -602,7 +500,7 @@ pub(crate) enum DiagnosticLevel { /// LLVMRustArchiveKind #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum ArchiveKind { +pub enum ArchiveKind { K_GNU, K_BSD, K_DARWIN, @@ -612,15 +510,15 @@ pub(crate) enum ArchiveKind { unsafe extern "C" { // LLVMRustThinLTOData - pub(crate) type ThinLTOData; + pub type ThinLTOData; // LLVMRustThinLTOBuffer - pub(crate) type ThinLTOBuffer; + pub type ThinLTOBuffer; } /// LLVMRustThinLTOModule #[repr(C)] -pub(crate) struct ThinLTOModule { +pub struct ThinLTOModule { pub identifier: *const c_char, pub data: *const u8, pub len: usize, @@ -629,8 +527,7 @@ pub(crate) struct ThinLTOModule { /// LLVMThreadLocalMode #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum ThreadLocalMode { - #[expect(dead_code)] +pub enum ThreadLocalMode { NotThreadLocal, GeneralDynamic, LocalDynamic, @@ -641,7 +538,7 @@ pub(crate) enum ThreadLocalMode { /// LLVMRustChecksumKind #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum ChecksumKind { +pub enum ChecksumKind { None, MD5, SHA1, @@ -651,17 +548,23 @@ pub(crate) enum ChecksumKind { /// LLVMRustMemoryEffects #[derive(Copy, Clone)] #[repr(C)] -pub(crate) enum MemoryEffects { +pub enum MemoryEffects { None, ReadOnly, InaccessibleMemOnly, } +impl MemoryEffects { + /// Create an LLVM Attribute with these memory effects. + pub fn create_attr(self, llcx: &Context) -> &Attribute { + unsafe { LLVMRustCreateMemoryEffectsAttr(llcx, self) } + } +} + /// LLVMOpcode #[derive(Copy, Clone, PartialEq, Eq)] #[repr(C)] -#[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")] -pub(crate) enum Opcode { +pub enum Opcode { Ret = 1, Br = 2, Switch = 3, @@ -742,54 +645,53 @@ struct InvariantOpaque<'a> { // Opaque pointer types unsafe extern "C" { - pub(crate) type Module; - pub(crate) type Context; - pub(crate) type Type; - pub(crate) type Value; - pub(crate) type ConstantInt; - pub(crate) type Attribute; - pub(crate) type Metadata; - pub(crate) type BasicBlock; - pub(crate) type Comdat; + pub type Module; + pub type Context; + pub type Type; + pub type Value; + pub type ConstantInt; + pub type Attribute; + pub type Metadata; + pub type BasicBlock; + pub type Comdat; } #[repr(C)] -pub(crate) struct Builder<'a>(InvariantOpaque<'a>); +pub struct Builder<'a>(InvariantOpaque<'a>); #[repr(C)] -pub(crate) struct PassManager<'a>(InvariantOpaque<'a>); +pub struct PassManager<'a>(InvariantOpaque<'a>); unsafe extern "C" { pub type TargetMachine; - pub(crate) type Archive; + pub type Archive; } #[repr(C)] -pub(crate) struct ArchiveIterator<'a>(InvariantOpaque<'a>); +pub struct ArchiveIterator<'a>(InvariantOpaque<'a>); #[repr(C)] -pub(crate) struct ArchiveChild<'a>(InvariantOpaque<'a>); +pub struct ArchiveChild<'a>(InvariantOpaque<'a>); unsafe extern "C" { - pub(crate) type Twine; - pub(crate) type DiagnosticInfo; - pub(crate) type SMDiagnostic; + pub type Twine; + pub type DiagnosticInfo; + pub type SMDiagnostic; } #[repr(C)] -pub(crate) struct RustArchiveMember<'a>(InvariantOpaque<'a>); +pub struct RustArchiveMember<'a>(InvariantOpaque<'a>); /// Opaque pointee of `LLVMOperandBundleRef`. #[repr(C)] -pub(crate) struct OperandBundle<'a>(InvariantOpaque<'a>); +pub struct OperandBundle<'a>(InvariantOpaque<'a>); #[repr(C)] -pub(crate) struct Linker<'a>(InvariantOpaque<'a>); +pub struct Linker<'a>(InvariantOpaque<'a>); unsafe extern "C" { - pub(crate) type DiagnosticHandler; + pub type DiagnosticHandler; } -pub(crate) type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void); +pub type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void); -pub(crate) mod debuginfo { +pub mod debuginfo { use std::ptr; use bitflags::bitflags; - use super::{InvariantOpaque, Metadata}; - use crate::llvm::{self, Module}; + use super::{InvariantOpaque, Metadata, Module}; /// Opaque target type for references to an LLVM debuginfo builder. /// @@ -800,23 +702,23 @@ pub(crate) mod debuginfo { /// builder reference typically has a shorter lifetime than the LLVM /// session (`'ll`) that it participates in. #[repr(C)] - pub(crate) struct DIBuilder<'ll>(InvariantOpaque<'ll>); + pub struct DIBuilder<'ll>(InvariantOpaque<'ll>); /// Owning pointer to a `DIBuilder<'ll>` that will dispose of the builder /// when dropped. Use `.as_ref()` to get the underlying `&DIBuilder` /// needed for debuginfo FFI calls. - pub(crate) struct DIBuilderBox<'ll> { + pub struct DIBuilderBox<'ll> { raw: ptr::NonNull>, } impl<'ll> DIBuilderBox<'ll> { - pub(crate) fn new(llmod: &'ll Module) -> Self { - let raw = unsafe { llvm::LLVMCreateDIBuilder(llmod) }; + pub fn new(llmod: &'ll Module) -> Self { + let raw = unsafe { super::LLVMCreateDIBuilder(llmod) }; let raw = ptr::NonNull::new(raw).unwrap(); Self { raw } } - pub(crate) fn as_ref(&self) -> &DIBuilder<'ll> { + pub fn as_ref(&self) -> &DIBuilder<'ll> { // SAFETY: This is an owning pointer, so `&DIBuilder` is valid // for as long as `&self` is. unsafe { self.raw.as_ref() } @@ -825,26 +727,26 @@ pub(crate) mod debuginfo { impl<'ll> Drop for DIBuilderBox<'ll> { fn drop(&mut self) { - unsafe { llvm::LLVMDisposeDIBuilder(self.raw) }; + unsafe { super::LLVMDisposeDIBuilder(self.raw) }; } } - pub(crate) type DIDescriptor = Metadata; - pub(crate) type DILocation = Metadata; - pub(crate) type DIScope = DIDescriptor; - pub(crate) type DIFile = DIScope; - pub(crate) type DILexicalBlock = DIScope; - pub(crate) type DISubprogram = DIScope; - pub(crate) type DIType = DIDescriptor; - pub(crate) type DIBasicType = DIType; - pub(crate) type DIDerivedType = DIType; - pub(crate) type DICompositeType = DIDerivedType; - pub(crate) type DIVariable = DIDescriptor; - pub(crate) type DIGlobalVariableExpression = DIDescriptor; - pub(crate) type DIArray = DIDescriptor; - pub(crate) type DISubrange = DIDescriptor; - pub(crate) type DIEnumerator = DIDescriptor; - pub(crate) type DITemplateTypeParameter = DIDescriptor; + pub type DIDescriptor = Metadata; + pub type DILocation = Metadata; + pub type DIScope = DIDescriptor; + pub type DIFile = DIScope; + pub type DILexicalBlock = DIScope; + pub type DISubprogram = DIScope; + pub type DIType = DIDescriptor; + pub type DIBasicType = DIType; + pub type DIDerivedType = DIType; + pub type DICompositeType = DIDerivedType; + pub type DIVariable = DIDescriptor; + pub type DIGlobalVariableExpression = DIDescriptor; + pub type DIArray = DIDescriptor; + pub type DISubrange = DIDescriptor; + pub type DIEnumerator = DIDescriptor; + pub type DITemplateTypeParameter = DIDescriptor; bitflags! { /// Must match the layout of `LLVMDIFlags` in the LLVM-C API. @@ -853,7 +755,7 @@ pub(crate) mod debuginfo { /// assertions in `RustWrapper.cpp` used by `fromRust(LLVMDIFlags)`. #[repr(transparent)] #[derive(Clone, Copy, Default)] - pub(crate) struct DIFlags: u32 { + pub struct DIFlags: u32 { const FlagZero = 0; const FlagPrivate = 1; const FlagProtected = 2; @@ -893,7 +795,7 @@ pub(crate) mod debuginfo { bitflags! { #[repr(transparent)] #[derive(Clone, Copy, Default)] - pub(crate) struct DISPFlags: u32 { + pub struct DISPFlags: u32 { const SPFlagZero = 0; const SPFlagVirtual = 1; const SPFlagPureVirtual = 2; @@ -907,41 +809,18 @@ pub(crate) mod debuginfo { /// LLVMRustDebugEmissionKind #[derive(Copy, Clone)] #[repr(C)] - pub(crate) enum DebugEmissionKind { + pub enum DebugEmissionKind { NoDebug, FullDebug, LineTablesOnly, DebugDirectivesOnly, } - impl DebugEmissionKind { - pub(crate) fn from_generic(kind: rustc_session::config::DebugInfo) -> Self { - // We should be setting LLVM's emission kind to `LineTablesOnly` if - // we are compiling with "limited" debuginfo. However, some of the - // existing tools relied on slightly more debuginfo being generated than - // would be the case with `LineTablesOnly`, and we did not want to break - // these tools in a "drive-by fix", without a good idea or plan about - // what limited debuginfo should exactly look like. So for now we are - // instead adding a new debuginfo option "line-tables-only" so as to - // not break anything and to allow users to have 'limited' debug info. - // - // See https://github.com/rust-lang/rust/issues/60020 for details. - use rustc_session::config::DebugInfo; - match kind { - DebugInfo::None => DebugEmissionKind::NoDebug, - DebugInfo::LineDirectivesOnly => DebugEmissionKind::DebugDirectivesOnly, - DebugInfo::LineTablesOnly => DebugEmissionKind::LineTablesOnly, - DebugInfo::Limited | DebugInfo::Full => DebugEmissionKind::FullDebug, - } - } - } - /// LLVMRustDebugNameTableKind #[derive(Clone, Copy)] #[repr(C)] - pub(crate) enum DebugNameTableKind { + pub enum DebugNameTableKind { Default, - #[expect(dead_code)] Gnu, None, } @@ -951,7 +830,7 @@ pub(crate) mod debuginfo { bitflags! { #[repr(transparent)] #[derive(Default)] - pub(crate) struct AllocKindFlags : u64 { + pub struct AllocKindFlags : u64 { const Unknown = 0; const Alloc = 1; const Realloc = 1 << 1; @@ -974,20 +853,19 @@ bitflags! { } unsafe extern "C" { - pub(crate) type ModuleBuffer; + pub type ModuleBuffer; } -pub(crate) type SelfProfileBeforePassCallback = +pub type SelfProfileBeforePassCallback = unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char); -pub(crate) type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void); +pub type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void); -pub(crate) type GetSymbolsCallback = - unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void; -pub(crate) type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void; +pub type GetSymbolsCallback = unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void; +pub type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void; #[derive(Copy, Clone)] #[repr(transparent)] -pub(crate) struct MetadataKindId(c_uint); +pub struct MetadataKindId(c_uint); impl From for MetadataKindId { fn from(value: MetadataType) -> Self { @@ -997,72 +875,69 @@ impl From for MetadataKindId { unsafe extern "C" { // Create and destroy contexts. - pub(crate) fn LLVMContextDispose(C: &'static mut Context); - pub(crate) fn LLVMGetMDKindIDInContext( + pub fn LLVMContextDispose(C: &'static mut Context); + pub fn LLVMGetMDKindIDInContext( C: &Context, Name: *const c_char, SLen: c_uint, ) -> MetadataKindId; // Create modules. - pub(crate) fn LLVMModuleCreateWithNameInContext( - ModuleID: *const c_char, - C: &Context, - ) -> &Module; - pub(crate) fn LLVMCloneModule(M: &Module) -> &Module; + pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char, C: &Context) -> &Module; + pub fn LLVMCloneModule(M: &Module) -> &Module; /// Data layout. See Module::getDataLayout. - pub(crate) fn LLVMGetDataLayoutStr(M: &Module) -> *const c_char; - pub(crate) fn LLVMSetDataLayout(M: &Module, Triple: *const c_char); + pub fn LLVMGetDataLayoutStr(M: &Module) -> *const c_char; + pub fn LLVMSetDataLayout(M: &Module, Triple: *const c_char); /// Append inline assembly to a module. See `Module::appendModuleInlineAsm`. - pub(crate) fn LLVMAppendModuleInlineAsm( + pub fn LLVMAppendModuleInlineAsm( M: &Module, Asm: *const c_uchar, // See "PTR_LEN_STR". Len: size_t, ); /// Create the specified uniqued inline asm string. See `InlineAsm::get()`. - pub(crate) fn LLVMGetInlineAsm<'ll>( + pub fn LLVMGetInlineAsm<'ll>( Ty: &'ll Type, AsmString: *const c_uchar, // See "PTR_LEN_STR". AsmStringSize: size_t, Constraints: *const c_uchar, // See "PTR_LEN_STR". ConstraintsSize: size_t, - HasSideEffects: llvm::Bool, - IsAlignStack: llvm::Bool, + HasSideEffects: Bool, + IsAlignStack: Bool, Dialect: AsmDialect, - CanThrow: llvm::Bool, + CanThrow: Bool, ) -> &'ll Value; // Operations on integer types - pub(crate) fn LLVMInt1TypeInContext(C: &Context) -> &Type; - pub(crate) fn LLVMInt8TypeInContext(C: &Context) -> &Type; - pub(crate) fn LLVMInt16TypeInContext(C: &Context) -> &Type; - pub(crate) fn LLVMInt32TypeInContext(C: &Context) -> &Type; - pub(crate) fn LLVMInt64TypeInContext(C: &Context) -> &Type; - pub(crate) fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type; + pub fn LLVMInt1TypeInContext(C: &Context) -> &Type; + pub fn LLVMInt8TypeInContext(C: &Context) -> &Type; + pub fn LLVMInt16TypeInContext(C: &Context) -> &Type; + pub fn LLVMInt32TypeInContext(C: &Context) -> &Type; + pub fn LLVMInt64TypeInContext(C: &Context) -> &Type; + pub fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type; - pub(crate) fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint; + pub fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint; // Operations on real types - pub(crate) fn LLVMHalfTypeInContext(C: &Context) -> &Type; - pub(crate) fn LLVMFloatTypeInContext(C: &Context) -> &Type; - pub(crate) fn LLVMDoubleTypeInContext(C: &Context) -> &Type; - pub(crate) fn LLVMFP128TypeInContext(C: &Context) -> &Type; + pub fn LLVMHalfTypeInContext(C: &Context) -> &Type; + pub fn LLVMFloatTypeInContext(C: &Context) -> &Type; + pub fn LLVMDoubleTypeInContext(C: &Context) -> &Type; + pub fn LLVMFP128TypeInContext(C: &Context) -> &Type; // Operations on function types - pub(crate) fn LLVMFunctionType<'a>( + pub fn LLVMFunctionType<'a>( ReturnType: &'a Type, ParamTypes: *const &'a Type, ParamCount: c_uint, IsVarArg: Bool, ) -> &'a Type; - pub(crate) fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint; - pub(crate) fn LLVMGetParamTypes<'a>(FunctionTy: &'a Type, Dest: *mut &'a Type); + pub fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint; + pub fn LLVMGetParamTypes<'a>(FunctionTy: &'a Type, Dest: *mut &'a Type); // Operations on struct types - pub(crate) fn LLVMStructTypeInContext<'a>( + pub fn LLVMStructTypeInContext<'a>( C: &'a Context, ElementTypes: *const &'a Type, ElementCount: c_uint, @@ -1070,120 +945,108 @@ unsafe extern "C" { ) -> &'a Type; // Operations on array, pointer, and vector types (sequence types) - pub(crate) fn LLVMPointerTypeInContext(C: &Context, AddressSpace: c_uint) -> &Type; - pub(crate) fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type; + pub fn LLVMPointerTypeInContext(C: &Context, AddressSpace: c_uint) -> &Type; + pub fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type; - pub(crate) fn LLVMGetElementType(Ty: &Type) -> &Type; - pub(crate) fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint; + pub fn LLVMGetElementType(Ty: &Type) -> &Type; + pub fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint; // Operations on other types - pub(crate) fn LLVMVoidTypeInContext(C: &Context) -> &Type; + pub fn LLVMVoidTypeInContext(C: &Context) -> &Type; // Operations on all values - pub(crate) fn LLVMTypeOf(Val: &Value) -> &Type; - pub(crate) fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char; - pub(crate) fn LLVMSetValueName2(Val: &Value, Name: *const c_char, NameLen: size_t); - pub(crate) fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value); - pub(crate) safe fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: MetadataKindId, Node: &'a Value); - pub(crate) fn LLVMGlobalSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata); - pub(crate) safe fn LLVMValueAsMetadata(Node: &Value) -> &Metadata; + pub fn LLVMTypeOf(Val: &Value) -> &Type; + pub fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char; + pub fn LLVMSetValueName2(Val: &Value, Name: *const c_char, NameLen: size_t); + pub fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value); + pub safe fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: MetadataKindId, Node: &'a Value); + pub fn LLVMGlobalSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata); + pub safe fn LLVMValueAsMetadata(Node: &Value) -> &Metadata; // Operations on constants of any type - pub(crate) fn LLVMConstNull(Ty: &Type) -> &Value; - pub(crate) fn LLVMGetUndef(Ty: &Type) -> &Value; - pub(crate) fn LLVMGetPoison(Ty: &Type) -> &Value; + pub fn LLVMConstNull(Ty: &Type) -> &Value; + pub fn LLVMGetUndef(Ty: &Type) -> &Value; + pub fn LLVMGetPoison(Ty: &Type) -> &Value; // Operations on metadata - pub(crate) fn LLVMMDStringInContext2( - C: &Context, - Str: *const c_char, - SLen: size_t, - ) -> &Metadata; - pub(crate) fn LLVMMDNodeInContext2<'a>( + pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata; + pub fn LLVMMDNodeInContext2<'a>( C: &'a Context, Vals: *const &'a Metadata, Count: size_t, ) -> &'a Metadata; - pub(crate) fn LLVMAddNamedMetadataOperand<'a>( - M: &'a Module, - Name: *const c_char, - Val: &'a Value, - ); + pub fn LLVMAddNamedMetadataOperand<'a>(M: &'a Module, Name: *const c_char, Val: &'a Value); // Operations on scalar constants - pub(crate) fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value; - pub(crate) fn LLVMConstIntOfArbitraryPrecision( - IntTy: &Type, - Wn: c_uint, - Ws: *const u64, - ) -> &Value; - pub(crate) fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value; + pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value; + pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value; + pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value; // Operations on composite constants - pub(crate) fn LLVMConstArray2<'a>( + pub fn LLVMConstArray2<'a>( ElementTy: &'a Type, ConstantVals: *const &'a Value, Length: u64, ) -> &'a Value; - pub(crate) fn LLVMArrayType2(ElementType: &Type, ElementCount: u64) -> &Type; - pub(crate) fn LLVMConstStringInContext2( + pub fn LLVMArrayType2(ElementType: &Type, ElementCount: u64) -> &Type; + pub fn LLVMConstStringInContext2( C: &Context, Str: *const c_char, Length: size_t, DontNullTerminate: Bool, ) -> &Value; - pub(crate) fn LLVMConstStructInContext<'a>( + pub fn LLVMConstStructInContext<'a>( C: &'a Context, ConstantVals: *const &'a Value, Count: c_uint, Packed: Bool, ) -> &'a Value; - pub(crate) fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value; + pub fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value; // Constant expressions - pub(crate) fn LLVMConstInBoundsGEP2<'a>( + pub fn LLVMConstInBoundsGEP2<'a>( ty: &'a Type, ConstantVal: &'a Value, ConstantIndices: *const &'a Value, NumIndices: c_uint, ) -> &'a Value; - pub(crate) fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value; - pub(crate) fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value; - pub(crate) fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value; - pub(crate) fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value; - pub(crate) fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>; - pub(crate) fn LLVMGetConstOpcode(ConstantVal: &Value) -> Opcode; - pub(crate) fn LLVMIsAConstantExpr(Val: &Value) -> Option<&Value>; + pub fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value; + pub fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value; + pub fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value; + pub fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value; + pub fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>; + pub fn LLVMGetConstOpcode(ConstantVal: &Value) -> Opcode; + pub fn LLVMIsAConstantExpr(Val: &Value) -> Option<&Value>; // Operations on global variables, functions, and aliases (globals) - pub(crate) fn LLVMIsDeclaration(Global: &Value) -> Bool; - pub(crate) fn LLVMGetLinkage(Global: &Value) -> RawEnum; - pub(crate) fn LLVMSetLinkage(Global: &Value, RustLinkage: Linkage); - pub(crate) fn LLVMSetSection(Global: &Value, Section: *const c_char); - pub(crate) fn LLVMGetVisibility(Global: &Value) -> RawEnum; - pub(crate) fn LLVMSetVisibility(Global: &Value, Viz: Visibility); - pub(crate) fn LLVMGetAlignment(Global: &Value) -> c_uint; - pub(crate) fn LLVMSetAlignment(Global: &Value, Bytes: c_uint); - pub(crate) fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass); - pub(crate) fn LLVMGlobalGetValueType(Global: &Value) -> &Type; + pub fn LLVMIsDeclaration(Global: &Value) -> Bool; + pub fn LLVMGetLinkage(Global: &Value) -> RawEnum; + pub fn LLVMSetLinkage(Global: &Value, RustLinkage: Linkage); + pub fn LLVMSetSection(Global: &Value, Section: *const c_char); + pub fn LLVMGetVisibility(Global: &Value) -> RawEnum; + pub fn LLVMSetVisibility(Global: &Value, Viz: Visibility); + pub fn LLVMGetAlignment(Global: &Value) -> c_uint; + pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint); + pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass); + pub fn LLVMGlobalGetValueType(Global: &Value) -> &Type; // Operations on global variables - pub(crate) fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>; - pub(crate) fn LLVMAddGlobal<'a>(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value; - pub(crate) fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>; - pub(crate) fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>; - pub(crate) fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>; - pub(crate) fn LLVMDeleteGlobal(GlobalVar: &Value); - pub(crate) fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>; - pub(crate) fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value); - pub(crate) fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool; - pub(crate) fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode); - pub(crate) fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool; - pub(crate) fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool); - pub(crate) safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool); + pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>; + pub fn LLVMAddGlobal<'a>(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value; + pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>; + pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>; + pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>; + pub fn LLVMDeleteGlobal(GlobalVar: &Value); + pub fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>; + pub fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value); + pub fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool; + pub fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode); + pub fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool; + pub fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool); + pub safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool); // Operations on attributes - pub(crate) fn LLVMCreateStringAttribute( + pub fn LLVMCreateStringAttribute( C: &Context, Name: *const c_char, NameLen: c_uint, @@ -1192,11 +1055,11 @@ unsafe extern "C" { ) -> &Attribute; // Operations on functions - pub(crate) fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint); + pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint); // Operations about llvm intrinsics - pub(crate) fn LLVMLookupIntrinsicID(Name: *const c_char, NameLen: size_t) -> c_uint; - pub(crate) fn LLVMGetIntrinsicDeclaration<'a>( + pub fn LLVMLookupIntrinsicID(Name: *const c_char, NameLen: size_t) -> c_uint; + pub fn LLVMGetIntrinsicDeclaration<'a>( Mod: &'a Module, ID: NonZero, ParamTypes: *const &'a Type, @@ -1204,31 +1067,31 @@ unsafe extern "C" { ) -> &'a Value; // Operations on parameters - pub(crate) fn LLVMIsAArgument(Val: &Value) -> Option<&Value>; - pub(crate) safe fn LLVMCountParams(Fn: &Value) -> c_uint; - pub(crate) fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value; + pub fn LLVMIsAArgument(Val: &Value) -> Option<&Value>; + pub safe fn LLVMCountParams(Fn: &Value) -> c_uint; + pub fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value; // Operations on basic blocks - pub(crate) fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value; - pub(crate) fn LLVMAppendBasicBlockInContext<'a>( + pub fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value; + pub fn LLVMAppendBasicBlockInContext<'a>( C: &'a Context, Fn: &'a Value, Name: *const c_char, ) -> &'a BasicBlock; // Operations on instructions - pub(crate) fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>; - pub(crate) fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock; - pub(crate) fn LLVMGetOperand(Val: &Value, Index: c_uint) -> Option<&Value>; + pub fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>; + pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock; + pub fn LLVMGetOperand(Val: &Value, Index: c_uint) -> Option<&Value>; // Operations on call sites - pub(crate) fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint); + pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint); // Operations on load/store instructions (only) - pub(crate) fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool); + pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool); // Operations on phi nodes - pub(crate) fn LLVMAddIncoming<'a>( + pub fn LLVMAddIncoming<'a>( PhiNode: &'a Value, IncomingValues: *const &'a Value, IncomingBlocks: *const &'a BasicBlock, @@ -1236,272 +1099,262 @@ unsafe extern "C" { ); // Instruction builders - pub(crate) fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>; - pub(crate) fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock); - pub(crate) fn LLVMGetInsertBlock<'a>(Builder: &Builder<'a>) -> &'a BasicBlock; - pub(crate) fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>); + pub fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>; + pub fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock); + pub fn LLVMGetInsertBlock<'a>(Builder: &Builder<'a>) -> &'a BasicBlock; + pub fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>); // Metadata - pub(crate) fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: *const Metadata); - pub(crate) fn LLVMGetCurrentDebugLocation2<'a>(Builder: &Builder<'a>) -> Option<&'a Metadata>; + pub fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: *const Metadata); + pub fn LLVMGetCurrentDebugLocation2<'a>(Builder: &Builder<'a>) -> Option<&'a Metadata>; // Terminators - pub(crate) safe fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value; - pub(crate) fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value; - pub(crate) fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value; - pub(crate) fn LLVMBuildCondBr<'a>( + pub safe fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value; + pub fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value; + pub fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value; + pub fn LLVMBuildCondBr<'a>( B: &Builder<'a>, If: &'a Value, Then: &'a BasicBlock, Else: &'a BasicBlock, ) -> &'a Value; - pub(crate) fn LLVMBuildSwitch<'a>( + pub fn LLVMBuildSwitch<'a>( B: &Builder<'a>, V: &'a Value, Else: &'a BasicBlock, NumCases: c_uint, ) -> &'a Value; - pub(crate) fn LLVMBuildLandingPad<'a>( + pub fn LLVMBuildLandingPad<'a>( B: &Builder<'a>, Ty: &'a Type, PersFn: Option<&'a Value>, NumClauses: c_uint, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value; - pub(crate) fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value; + pub fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value; + pub fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value; - pub(crate) fn LLVMBuildCleanupPad<'a>( + pub fn LLVMBuildCleanupPad<'a>( B: &Builder<'a>, ParentPad: Option<&'a Value>, Args: *const &'a Value, NumArgs: c_uint, Name: *const c_char, ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCleanupRet<'a>( + pub fn LLVMBuildCleanupRet<'a>( B: &Builder<'a>, CleanupPad: &'a Value, BB: Option<&'a BasicBlock>, ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCatchPad<'a>( + pub fn LLVMBuildCatchPad<'a>( B: &Builder<'a>, ParentPad: &'a Value, Args: *const &'a Value, NumArgs: c_uint, Name: *const c_char, ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCatchRet<'a>( + pub fn LLVMBuildCatchRet<'a>( B: &Builder<'a>, CatchPad: &'a Value, BB: &'a BasicBlock, ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCatchSwitch<'a>( + pub fn LLVMBuildCatchSwitch<'a>( Builder: &Builder<'a>, ParentPad: Option<&'a Value>, UnwindBB: Option<&'a BasicBlock>, NumHandlers: c_uint, Name: *const c_char, ) -> Option<&'a Value>; - pub(crate) fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock); - pub(crate) fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value); + pub fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock); + pub fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value); // Add a case to the switch instruction - pub(crate) fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock); + pub fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock); // Add a clause to the landing pad instruction - pub(crate) fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value); + pub fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value); // Set the cleanup on a landing pad instruction - pub(crate) fn LLVMSetCleanup(LandingPad: &Value, Val: Bool); + pub fn LLVMSetCleanup(LandingPad: &Value, Val: Bool); // Arithmetic - pub(crate) fn LLVMBuildAdd<'a>( + pub fn LLVMBuildAdd<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFAdd<'a>( + pub fn LLVMBuildFAdd<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildSub<'a>( + pub fn LLVMBuildSub<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFSub<'a>( + pub fn LLVMBuildFSub<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildMul<'a>( + pub fn LLVMBuildMul<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFMul<'a>( + pub fn LLVMBuildFMul<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildUDiv<'a>( + pub fn LLVMBuildUDiv<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildExactUDiv<'a>( + pub fn LLVMBuildExactUDiv<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildSDiv<'a>( + pub fn LLVMBuildSDiv<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildExactSDiv<'a>( + pub fn LLVMBuildExactSDiv<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFDiv<'a>( + pub fn LLVMBuildFDiv<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildURem<'a>( + pub fn LLVMBuildURem<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildSRem<'a>( + pub fn LLVMBuildSRem<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFRem<'a>( + pub fn LLVMBuildFRem<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildShl<'a>( + pub fn LLVMBuildShl<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildLShr<'a>( + pub fn LLVMBuildLShr<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildAShr<'a>( + pub fn LLVMBuildAShr<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildNSWAdd<'a>( + pub fn LLVMBuildNSWAdd<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildNUWAdd<'a>( + pub fn LLVMBuildNUWAdd<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildNSWSub<'a>( + pub fn LLVMBuildNSWSub<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildNUWSub<'a>( + pub fn LLVMBuildNUWSub<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildNSWMul<'a>( + pub fn LLVMBuildNSWMul<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildNUWMul<'a>( + pub fn LLVMBuildNUWMul<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildAnd<'a>( + pub fn LLVMBuildAnd<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildOr<'a>( + pub fn LLVMBuildOr<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildXor<'a>( + pub fn LLVMBuildXor<'a>( B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) - -> &'a Value; - pub(crate) fn LLVMBuildFNeg<'a>( - B: &Builder<'a>, - V: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) - -> &'a Value; + pub fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value; + pub fn LLVMBuildFNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value; + pub fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value; // Extra flags on arithmetic - pub(crate) fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool); - pub(crate) fn LLVMSetNUW(ArithInst: &Value, HasNUW: Bool); - pub(crate) fn LLVMSetNSW(ArithInst: &Value, HasNSW: Bool); + pub fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool); + pub fn LLVMSetNUW(ArithInst: &Value, HasNUW: Bool); + pub fn LLVMSetNSW(ArithInst: &Value, HasNSW: Bool); // Memory - pub(crate) fn LLVMBuildAlloca<'a>( - B: &Builder<'a>, - Ty: &'a Type, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildLoad2<'a>( + pub fn LLVMBuildAlloca<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value; + pub fn LLVMBuildLoad2<'a>( B: &Builder<'a>, Ty: &'a Type, PointerVal: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value; + pub fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value; - pub(crate) fn LLVMBuildGEPWithNoWrapFlags<'a>( + pub fn LLVMBuildGEPWithNoWrapFlags<'a>( B: &Builder<'a>, Ty: &'a Type, Pointer: &'a Value, @@ -1512,85 +1365,85 @@ unsafe extern "C" { ) -> &'a Value; // Casts - pub(crate) fn LLVMBuildTrunc<'a>( + pub fn LLVMBuildTrunc<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildZExt<'a>( + pub fn LLVMBuildZExt<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildSExt<'a>( + pub fn LLVMBuildSExt<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFPToUI<'a>( + pub fn LLVMBuildFPToUI<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFPToSI<'a>( + pub fn LLVMBuildFPToSI<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildUIToFP<'a>( + pub fn LLVMBuildUIToFP<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildSIToFP<'a>( + pub fn LLVMBuildSIToFP<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFPTrunc<'a>( + pub fn LLVMBuildFPTrunc<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFPExt<'a>( + pub fn LLVMBuildFPExt<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildPtrToInt<'a>( + pub fn LLVMBuildPtrToInt<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildIntToPtr<'a>( + pub fn LLVMBuildIntToPtr<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildBitCast<'a>( + pub fn LLVMBuildBitCast<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildPointerCast<'a>( + pub fn LLVMBuildPointerCast<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildIntCast2<'a>( + pub fn LLVMBuildIntCast2<'a>( B: &Builder<'a>, Val: &'a Value, DestTy: &'a Type, @@ -1599,14 +1452,14 @@ unsafe extern "C" { ) -> &'a Value; // Comparisons - pub(crate) fn LLVMBuildICmp<'a>( + pub fn LLVMBuildICmp<'a>( B: &Builder<'a>, Op: c_uint, LHS: &'a Value, RHS: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildFCmp<'a>( + pub fn LLVMBuildFCmp<'a>( B: &Builder<'a>, Op: c_uint, LHS: &'a Value, @@ -1615,48 +1468,47 @@ unsafe extern "C" { ) -> &'a Value; // Miscellaneous instructions - pub(crate) fn LLVMBuildPhi<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) - -> &'a Value; - pub(crate) fn LLVMBuildSelect<'a>( + pub fn LLVMBuildPhi<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value; + pub fn LLVMBuildSelect<'a>( B: &Builder<'a>, If: &'a Value, Then: &'a Value, Else: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildVAArg<'a>( + pub fn LLVMBuildVAArg<'a>( B: &Builder<'a>, list: &'a Value, Ty: &'a Type, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildExtractElement<'a>( + pub fn LLVMBuildExtractElement<'a>( B: &Builder<'a>, VecVal: &'a Value, Index: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildInsertElement<'a>( + pub fn LLVMBuildInsertElement<'a>( B: &Builder<'a>, VecVal: &'a Value, EltVal: &'a Value, Index: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildShuffleVector<'a>( + pub fn LLVMBuildShuffleVector<'a>( B: &Builder<'a>, V1: &'a Value, V2: &'a Value, Mask: &'a Value, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildExtractValue<'a>( + pub fn LLVMBuildExtractValue<'a>( B: &Builder<'a>, AggVal: &'a Value, Index: c_uint, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildInsertValue<'a>( + pub fn LLVMBuildInsertValue<'a>( B: &Builder<'a>, AggVal: &'a Value, EltVal: &'a Value, @@ -1665,7 +1517,7 @@ unsafe extern "C" { ) -> &'a Value; // Atomic Operations - pub(crate) fn LLVMBuildAtomicCmpXchg<'a>( + pub fn LLVMBuildAtomicCmpXchg<'a>( B: &Builder<'a>, LHS: &'a Value, CMP: &'a Value, @@ -1675,9 +1527,9 @@ unsafe extern "C" { SingleThreaded: Bool, ) -> &'a Value; - pub(crate) fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool); + pub fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool); - pub(crate) fn LLVMBuildAtomicRMW<'a>( + pub fn LLVMBuildAtomicRMW<'a>( B: &Builder<'a>, Op: AtomicRmwBinOp, LHS: &'a Value, @@ -1686,7 +1538,7 @@ unsafe extern "C" { SingleThreaded: Bool, ) -> &'a Value; - pub(crate) fn LLVMBuildFence<'a>( + pub fn LLVMBuildFence<'a>( B: &Builder<'a>, Order: AtomicOrdering, SingleThreaded: Bool, @@ -1694,46 +1546,46 @@ unsafe extern "C" { ) -> &'a Value; /// Writes a module to the specified path. Returns 0 on success. - pub(crate) fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int; + pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int; /// Creates a legacy pass manager -- only used for final codegen. - pub(crate) fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>; + pub fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>; - pub(crate) fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>); + pub fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>); - pub(crate) fn LLVMGetHostCPUFeatures() -> *mut c_char; + pub fn LLVMGetHostCPUFeatures() -> *mut c_char; - pub(crate) fn LLVMDisposeMessage(message: *mut c_char); + pub fn LLVMDisposeMessage(message: *mut c_char); - pub(crate) fn LLVMIsMultithreaded() -> Bool; + pub fn LLVMIsMultithreaded() -> Bool; - pub(crate) fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type; + pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type; - pub(crate) fn LLVMStructSetBody<'a>( + pub fn LLVMStructSetBody<'a>( StructTy: &'a Type, ElementTypes: *const &'a Type, ElementCount: c_uint, Packed: Bool, ); - pub(crate) safe fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value; + pub safe fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value; - pub(crate) fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr); + pub fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr); - pub(crate) fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>; + pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>; - pub(crate) fn LLVMGetOrInsertComdat(M: &Module, Name: *const c_char) -> &Comdat; - pub(crate) fn LLVMSetComdat(V: &Value, C: &Comdat); + pub fn LLVMGetOrInsertComdat(M: &Module, Name: *const c_char) -> &Comdat; + pub fn LLVMSetComdat(V: &Value, C: &Comdat); - pub(crate) fn LLVMCreateOperandBundle( + pub fn LLVMCreateOperandBundle( Tag: *const c_char, TagLen: size_t, Args: *const &'_ Value, NumArgs: c_uint, ) -> *mut OperandBundle<'_>; - pub(crate) fn LLVMDisposeOperandBundle(Bundle: ptr::NonNull>); + pub fn LLVMDisposeOperandBundle(Bundle: ptr::NonNull>); - pub(crate) fn LLVMBuildCallWithOperandBundles<'a>( + pub fn LLVMBuildCallWithOperandBundles<'a>( B: &Builder<'a>, Ty: &'a Type, Fn: &'a Value, @@ -1743,7 +1595,7 @@ unsafe extern "C" { NumBundles: c_uint, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildInvokeWithOperandBundles<'a>( + pub fn LLVMBuildInvokeWithOperandBundles<'a>( B: &Builder<'a>, Ty: &'a Type, Fn: &'a Value, @@ -1755,7 +1607,7 @@ unsafe extern "C" { NumBundles: c_uint, Name: *const c_char, ) -> &'a Value; - pub(crate) fn LLVMBuildCallBr<'a>( + pub fn LLVMBuildCallBr<'a>( B: &Builder<'a>, Ty: &'a Type, Fn: &'a Value, @@ -1777,20 +1629,20 @@ unsafe extern "C" { // that they really are nullable on the C/C++ side. LLVM doesn't appear to // actually document which ones are nullable. unsafe extern "C" { - pub(crate) fn LLVMCreateDIBuilder<'ll>(M: &'ll Module) -> *mut DIBuilder<'ll>; - pub(crate) fn LLVMDisposeDIBuilder<'ll>(Builder: ptr::NonNull>); + pub fn LLVMCreateDIBuilder<'ll>(M: &'ll Module) -> *mut DIBuilder<'ll>; + pub fn LLVMDisposeDIBuilder<'ll>(Builder: ptr::NonNull>); - pub(crate) fn LLVMDIBuilderFinalize<'ll>(Builder: &DIBuilder<'ll>); + pub fn LLVMDIBuilderFinalize<'ll>(Builder: &DIBuilder<'ll>); - pub(crate) fn LLVMDIBuilderCreateNameSpace<'ll>( + pub fn LLVMDIBuilderCreateNameSpace<'ll>( Builder: &DIBuilder<'ll>, ParentScope: Option<&'ll Metadata>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, - ExportSymbols: llvm::Bool, + ExportSymbols: Bool, ) -> &'ll Metadata; - pub(crate) fn LLVMDIBuilderCreateLexicalBlock<'ll>( + pub fn LLVMDIBuilderCreateLexicalBlock<'ll>( Builder: &DIBuilder<'ll>, Scope: &'ll Metadata, File: &'ll Metadata, @@ -1798,14 +1650,14 @@ unsafe extern "C" { Column: c_uint, ) -> &'ll Metadata; - pub(crate) fn LLVMDIBuilderCreateLexicalBlockFile<'ll>( + pub fn LLVMDIBuilderCreateLexicalBlockFile<'ll>( Builder: &DIBuilder<'ll>, Scope: &'ll Metadata, File: &'ll Metadata, Discriminator: c_uint, // (optional "DWARF path discriminator"; default is 0) ) -> &'ll Metadata; - pub(crate) fn LLVMDIBuilderCreateDebugLocation<'ll>( + pub fn LLVMDIBuilderCreateDebugLocation<'ll>( Ctx: &'ll Context, Line: c_uint, Column: c_uint, @@ -1816,26 +1668,22 @@ unsafe extern "C" { #[link(name = "llvm-wrapper", kind = "static")] unsafe extern "C" { - pub(crate) fn LLVMRustInstallErrorHandlers(); - pub(crate) fn LLVMRustDisableSystemDialogsOnCrash(); + pub fn LLVMRustInstallErrorHandlers(); + pub fn LLVMRustDisableSystemDialogsOnCrash(); // Create and destroy contexts. - pub(crate) fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context; + pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context; - /// See llvm::LLVMTypeKind::getTypeID. - pub(crate) fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind; + /// See super::LLVMTypeKind::getTypeID. + pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind; // Operations on all values - pub(crate) fn LLVMRustGlobalAddMetadata<'a>( - Val: &'a Value, - KindID: c_uint, - Metadata: &'a Metadata, - ); - pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool; + pub fn LLVMRustGlobalAddMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata); + pub fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool; // Operations on scalar constants - pub(crate) fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool; - pub(crate) fn LLVMRustConstInt128Get( + pub fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool; + pub fn LLVMRustConstInt128Get( ConstantVal: &ConstantInt, SExt: bool, high: &mut u64, @@ -1843,38 +1691,35 @@ unsafe extern "C" { ) -> bool; // Operations on global variables, functions, and aliases (globals) - pub(crate) fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool); + pub fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool); // Operations on global variables - pub(crate) fn LLVMRustGetOrInsertGlobal<'a>( + pub fn LLVMRustGetOrInsertGlobal<'a>( M: &'a Module, Name: *const c_char, NameLen: size_t, T: &'a Type, ) -> &'a Value; - pub(crate) fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value; - pub(crate) fn LLVMRustGetNamedValue( + pub fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value; + pub fn LLVMRustGetNamedValue( M: &Module, Name: *const c_char, NameLen: size_t, ) -> Option<&Value>; // Operations on attributes - pub(crate) fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute; - pub(crate) fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute; - pub(crate) fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute; - pub(crate) fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute; - pub(crate) fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; - pub(crate) fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; - pub(crate) fn LLVMRustCreateElementTypeAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; - pub(crate) fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute; - pub(crate) fn LLVMRustCreateAllocSizeAttr(C: &Context, size_arg: u32) -> &Attribute; - pub(crate) fn LLVMRustCreateAllocKindAttr(C: &Context, size_arg: u64) -> &Attribute; - pub(crate) fn LLVMRustCreateMemoryEffectsAttr( - C: &Context, - effects: MemoryEffects, - ) -> &Attribute; - pub(crate) fn LLVMRustCreateRangeAttribute( + pub fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute; + pub fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute; + pub fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute; + pub fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute; + pub fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; + pub fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; + pub fn LLVMRustCreateElementTypeAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; + pub fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute; + pub fn LLVMRustCreateAllocSizeAttr(C: &Context, size_arg: u32) -> &Attribute; + pub fn LLVMRustCreateAllocKindAttr(C: &Context, size_arg: u64) -> &Attribute; + pub fn LLVMRustCreateMemoryEffectsAttr(C: &Context, effects: MemoryEffects) -> &Attribute; + pub fn LLVMRustCreateRangeAttribute( C: &Context, num_bits: c_uint, lower_words: *const u64, @@ -1882,13 +1727,13 @@ unsafe extern "C" { ) -> &Attribute; // Operations on functions - pub(crate) fn LLVMRustGetOrInsertFunction<'a>( + pub fn LLVMRustGetOrInsertFunction<'a>( M: &'a Module, Name: *const c_char, NameLen: size_t, FunctionTy: &'a Type, ) -> &'a Value; - pub(crate) fn LLVMRustAddFunctionAttributes<'a>( + pub fn LLVMRustAddFunctionAttributes<'a>( Fn: &'a Value, index: c_uint, Attrs: *const &'a Attribute, @@ -1896,19 +1741,19 @@ unsafe extern "C" { ); // Operations on call sites - pub(crate) fn LLVMRustAddCallSiteAttributes<'a>( + pub fn LLVMRustAddCallSiteAttributes<'a>( Instr: &'a Value, index: c_uint, Attrs: *const &'a Attribute, AttrsLen: size_t, ); - pub(crate) fn LLVMRustSetFastMath(Instr: &Value); - pub(crate) fn LLVMRustSetAlgebraicMath(Instr: &Value); - pub(crate) fn LLVMRustSetAllowReassoc(Instr: &Value); + pub fn LLVMRustSetFastMath(Instr: &Value); + pub fn LLVMRustSetAlgebraicMath(Instr: &Value); + pub fn LLVMRustSetAllowReassoc(Instr: &Value); // Miscellaneous instructions - pub(crate) fn LLVMRustBuildMemCpy<'a>( + pub fn LLVMRustBuildMemCpy<'a>( B: &Builder<'a>, Dst: &'a Value, DstAlign: c_uint, @@ -1917,7 +1762,7 @@ unsafe extern "C" { Size: &'a Value, IsVolatile: bool, ) -> &'a Value; - pub(crate) fn LLVMRustBuildMemMove<'a>( + pub fn LLVMRustBuildMemMove<'a>( B: &Builder<'a>, Dst: &'a Value, DstAlign: c_uint, @@ -1926,7 +1771,7 @@ unsafe extern "C" { Size: &'a Value, IsVolatile: bool, ) -> &'a Value; - pub(crate) fn LLVMRustBuildMemSet<'a>( + pub fn LLVMRustBuildMemSet<'a>( B: &Builder<'a>, Dst: &'a Value, DstAlign: c_uint, @@ -1935,55 +1780,47 @@ unsafe extern "C" { IsVolatile: bool, ) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceFAdd<'a>( + pub fn LLVMRustBuildVectorReduceFAdd<'a>( B: &Builder<'a>, Acc: &'a Value, Src: &'a Value, ) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceFMul<'a>( + pub fn LLVMRustBuildVectorReduceFMul<'a>( B: &Builder<'a>, Acc: &'a Value, Src: &'a Value, ) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceAdd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceMul<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceAnd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceOr<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceXor<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceMin<'a>( + pub fn LLVMRustBuildVectorReduceAdd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; + pub fn LLVMRustBuildVectorReduceMul<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; + pub fn LLVMRustBuildVectorReduceAnd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; + pub fn LLVMRustBuildVectorReduceOr<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; + pub fn LLVMRustBuildVectorReduceXor<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value; + pub fn LLVMRustBuildVectorReduceMin<'a>( B: &Builder<'a>, Src: &'a Value, IsSigned: bool, ) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceMax<'a>( + pub fn LLVMRustBuildVectorReduceMax<'a>( B: &Builder<'a>, Src: &'a Value, IsSigned: bool, ) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceFMin<'a>( + pub fn LLVMRustBuildVectorReduceFMin<'a>( B: &Builder<'a>, Src: &'a Value, IsNaN: bool, ) -> &'a Value; - pub(crate) fn LLVMRustBuildVectorReduceFMax<'a>( + pub fn LLVMRustBuildVectorReduceFMax<'a>( B: &Builder<'a>, Src: &'a Value, IsNaN: bool, ) -> &'a Value; - pub(crate) fn LLVMRustBuildMinNum<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - ) -> &'a Value; - pub(crate) fn LLVMRustBuildMaxNum<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - ) -> &'a Value; + pub fn LLVMRustBuildMinNum<'a>(B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value) -> &'a Value; + pub fn LLVMRustBuildMaxNum<'a>(B: &Builder<'a>, LHS: &'a Value, RHS: &'a Value) -> &'a Value; // Atomic Operations - pub(crate) fn LLVMRustBuildAtomicLoad<'a>( + pub fn LLVMRustBuildAtomicLoad<'a>( B: &Builder<'a>, ElementType: &'a Type, PointerVal: &'a Value, @@ -1991,35 +1828,35 @@ unsafe extern "C" { Order: AtomicOrdering, ) -> &'a Value; - pub(crate) fn LLVMRustBuildAtomicStore<'a>( + pub fn LLVMRustBuildAtomicStore<'a>( B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value, Order: AtomicOrdering, ) -> &'a Value; - pub(crate) fn LLVMRustTimeTraceProfilerInitialize(); + pub fn LLVMRustTimeTraceProfilerInitialize(); - pub(crate) fn LLVMRustTimeTraceProfilerFinishThread(); + pub fn LLVMRustTimeTraceProfilerFinishThread(); - pub(crate) fn LLVMRustTimeTraceProfilerFinish(FileName: *const c_char); + pub fn LLVMRustTimeTraceProfilerFinish(FileName: *const c_char); /// Returns a string describing the last error caused by an LLVMRust* call. - pub(crate) fn LLVMRustGetLastError() -> *const c_char; + pub fn LLVMRustGetLastError() -> *const c_char; /// Prints the timing information collected by `-Ztime-llvm-passes`. - pub(crate) fn LLVMRustPrintPassTimings(OutStr: &RustString); + pub fn LLVMRustPrintPassTimings(OutStr: &RustString); /// Prints the statistics collected by `-Zprint-codegen-stats`. - pub(crate) fn LLVMRustPrintStatistics(OutStr: &RustString); + pub fn LLVMRustPrintStatistics(OutStr: &RustString); - pub(crate) fn LLVMRustInlineAsmVerify( + pub fn LLVMRustInlineAsmVerify( Ty: &Type, Constraints: *const c_uchar, // See "PTR_LEN_STR". ConstraintsLen: size_t, ) -> bool; - pub(crate) fn LLVMRustCoverageWriteFilenamesToBuffer( + pub fn LLVMRustCoverageWriteFilenamesToBuffer( Filenames: *const *const c_char, FilenamesLen: size_t, Lengths: *const size_t, @@ -2027,48 +1864,48 @@ unsafe extern "C" { BufferOut: &RustString, ); - pub(crate) fn LLVMRustCoverageWriteFunctionMappingsToBuffer( + pub fn LLVMRustCoverageWriteFunctionMappingsToBuffer( VirtualFileMappingIDs: *const c_uint, NumVirtualFileMappingIDs: size_t, - Expressions: *const crate::coverageinfo::ffi::CounterExpression, + Expressions: *const coverageinfo::CounterExpression, NumExpressions: size_t, - CodeRegions: *const crate::coverageinfo::ffi::CodeRegion, + CodeRegions: *const coverageinfo::CodeRegion, NumCodeRegions: size_t, - ExpansionRegions: *const crate::coverageinfo::ffi::ExpansionRegion, + ExpansionRegions: *const coverageinfo::ExpansionRegion, NumExpansionRegions: size_t, - BranchRegions: *const crate::coverageinfo::ffi::BranchRegion, + BranchRegions: *const coverageinfo::BranchRegion, NumBranchRegions: size_t, - MCDCBranchRegions: *const crate::coverageinfo::ffi::MCDCBranchRegion, + MCDCBranchRegions: *const coverageinfo::MCDCBranchRegion, NumMCDCBranchRegions: size_t, - MCDCDecisionRegions: *const crate::coverageinfo::ffi::MCDCDecisionRegion, + MCDCDecisionRegions: *const coverageinfo::MCDCDecisionRegion, NumMCDCDecisionRegions: size_t, BufferOut: &RustString, ); - pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar( + pub fn LLVMRustCoverageCreatePGOFuncNameVar( F: &Value, FuncName: *const c_char, FuncNameLen: size_t, ) -> &Value; - pub(crate) fn LLVMRustCoverageHashBytes(Bytes: *const c_char, NumBytes: size_t) -> u64; + pub fn LLVMRustCoverageHashBytes(Bytes: *const c_char, NumBytes: size_t) -> u64; - pub(crate) fn LLVMRustCoverageWriteCovmapSectionNameToString(M: &Module, OutStr: &RustString); + pub fn LLVMRustCoverageWriteCovmapSectionNameToString(M: &Module, OutStr: &RustString); - pub(crate) fn LLVMRustCoverageWriteCovfunSectionNameToString(M: &Module, OutStr: &RustString); + pub fn LLVMRustCoverageWriteCovfunSectionNameToString(M: &Module, OutStr: &RustString); - pub(crate) fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString); + pub fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString); - pub(crate) fn LLVMRustCoverageMappingVersion() -> u32; - pub(crate) fn LLVMRustDebugMetadataVersion() -> u32; - pub(crate) fn LLVMRustVersionMajor() -> u32; - pub(crate) fn LLVMRustVersionMinor() -> u32; - pub(crate) fn LLVMRustVersionPatch() -> u32; + pub fn LLVMRustCoverageMappingVersion() -> u32; + pub fn LLVMRustDebugMetadataVersion() -> u32; + pub fn LLVMRustVersionMajor() -> u32; + pub fn LLVMRustVersionMinor() -> u32; + pub fn LLVMRustVersionPatch() -> u32; /// Add LLVM module flags. /// /// In order for Rust-C LTO to work, module flags must be compatible with Clang. What /// "compatible" means depends on the merge behaviors involved. - pub(crate) fn LLVMRustAddModuleFlagU32( + pub fn LLVMRustAddModuleFlagU32( M: &Module, MergeBehavior: ModuleFlagMergeBehavior, Name: *const c_char, @@ -2076,7 +1913,7 @@ unsafe extern "C" { Value: u32, ); - pub(crate) fn LLVMRustAddModuleFlagString( + pub fn LLVMRustAddModuleFlagString( M: &Module, MergeBehavior: ModuleFlagMergeBehavior, Name: *const c_char, @@ -2085,7 +1922,7 @@ unsafe extern "C" { ValueLen: size_t, ); - pub(crate) fn LLVMRustDIBuilderCreateCompileUnit<'a>( + pub fn LLVMRustDIBuilderCreateCompileUnit<'a>( Builder: &DIBuilder<'a>, Lang: c_uint, File: &'a DIFile, @@ -2102,7 +1939,7 @@ unsafe extern "C" { DebugNameTableKind: DebugNameTableKind, ) -> &'a DIDescriptor; - pub(crate) fn LLVMRustDIBuilderCreateFile<'a>( + pub fn LLVMRustDIBuilderCreateFile<'a>( Builder: &DIBuilder<'a>, Filename: *const c_char, FilenameLen: size_t, @@ -2115,12 +1952,12 @@ unsafe extern "C" { SourceLen: size_t, ) -> &'a DIFile; - pub(crate) fn LLVMRustDIBuilderCreateSubroutineType<'a>( + pub fn LLVMRustDIBuilderCreateSubroutineType<'a>( Builder: &DIBuilder<'a>, ParameterTypes: &'a DIArray, ) -> &'a DICompositeType; - pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>( + pub fn LLVMRustDIBuilderCreateFunction<'a>( Builder: &DIBuilder<'a>, Scope: &'a DIDescriptor, Name: *const c_char, @@ -2138,7 +1975,7 @@ unsafe extern "C" { Decl: Option<&'a DIDescriptor>, ) -> &'a DISubprogram; - pub(crate) fn LLVMRustDIBuilderCreateMethod<'a>( + pub fn LLVMRustDIBuilderCreateMethod<'a>( Builder: &DIBuilder<'a>, Scope: &'a DIDescriptor, Name: *const c_char, @@ -2153,7 +1990,7 @@ unsafe extern "C" { TParam: &'a DIArray, ) -> &'a DISubprogram; - pub(crate) fn LLVMRustDIBuilderCreateBasicType<'a>( + pub fn LLVMRustDIBuilderCreateBasicType<'a>( Builder: &DIBuilder<'a>, Name: *const c_char, NameLen: size_t, @@ -2161,7 +1998,7 @@ unsafe extern "C" { Encoding: c_uint, ) -> &'a DIBasicType; - pub(crate) fn LLVMRustDIBuilderCreateTypedef<'a>( + pub fn LLVMRustDIBuilderCreateTypedef<'a>( Builder: &DIBuilder<'a>, Type: &'a DIBasicType, Name: *const c_char, @@ -2171,7 +2008,7 @@ unsafe extern "C" { Scope: Option<&'a DIScope>, ) -> &'a DIDerivedType; - pub(crate) fn LLVMRustDIBuilderCreatePointerType<'a>( + pub fn LLVMRustDIBuilderCreatePointerType<'a>( Builder: &DIBuilder<'a>, PointeeTy: &'a DIType, SizeInBits: u64, @@ -2181,7 +2018,7 @@ unsafe extern "C" { NameLen: size_t, ) -> &'a DIDerivedType; - pub(crate) fn LLVMRustDIBuilderCreateStructType<'a>( + pub fn LLVMRustDIBuilderCreateStructType<'a>( Builder: &DIBuilder<'a>, Scope: Option<&'a DIDescriptor>, Name: *const c_char, @@ -2199,7 +2036,7 @@ unsafe extern "C" { UniqueIdLen: size_t, ) -> &'a DICompositeType; - pub(crate) fn LLVMRustDIBuilderCreateMemberType<'a>( + pub fn LLVMRustDIBuilderCreateMemberType<'a>( Builder: &DIBuilder<'a>, Scope: &'a DIDescriptor, Name: *const c_char, @@ -2213,7 +2050,7 @@ unsafe extern "C" { Ty: &'a DIType, ) -> &'a DIDerivedType; - pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>( + pub fn LLVMRustDIBuilderCreateVariantMemberType<'a>( Builder: &DIBuilder<'a>, Scope: &'a DIScope, Name: *const c_char, @@ -2228,7 +2065,7 @@ unsafe extern "C" { Ty: &'a DIType, ) -> &'a DIType; - pub(crate) fn LLVMRustDIBuilderCreateStaticMemberType<'a>( + pub fn LLVMRustDIBuilderCreateStaticMemberType<'a>( Builder: &DIBuilder<'a>, Scope: &'a DIDescriptor, Name: *const c_char, @@ -2241,13 +2078,13 @@ unsafe extern "C" { AlignInBits: u32, ) -> &'a DIDerivedType; - pub(crate) fn LLVMRustDIBuilderCreateQualifiedType<'a>( + pub fn LLVMRustDIBuilderCreateQualifiedType<'a>( Builder: &DIBuilder<'a>, Tag: c_uint, Type: &'a DIType, ) -> &'a DIDerivedType; - pub(crate) fn LLVMRustDIBuilderCreateStaticVariable<'a>( + pub fn LLVMRustDIBuilderCreateStaticVariable<'a>( Builder: &DIBuilder<'a>, Context: Option<&'a DIScope>, Name: *const c_char, @@ -2263,7 +2100,7 @@ unsafe extern "C" { AlignInBits: u32, ) -> &'a DIGlobalVariableExpression; - pub(crate) fn LLVMRustDIBuilderCreateVariable<'a>( + pub fn LLVMRustDIBuilderCreateVariable<'a>( Builder: &DIBuilder<'a>, Tag: c_uint, Scope: &'a DIDescriptor, @@ -2278,7 +2115,7 @@ unsafe extern "C" { AlignInBits: u32, ) -> &'a DIVariable; - pub(crate) fn LLVMRustDIBuilderCreateArrayType<'a>( + pub fn LLVMRustDIBuilderCreateArrayType<'a>( Builder: &DIBuilder<'a>, Size: u64, AlignInBits: u32, @@ -2286,19 +2123,19 @@ unsafe extern "C" { Subscripts: &'a DIArray, ) -> &'a DIType; - pub(crate) fn LLVMRustDIBuilderGetOrCreateSubrange<'a>( + pub fn LLVMRustDIBuilderGetOrCreateSubrange<'a>( Builder: &DIBuilder<'a>, Lo: i64, Count: i64, ) -> &'a DISubrange; - pub(crate) fn LLVMRustDIBuilderGetOrCreateArray<'a>( + pub fn LLVMRustDIBuilderGetOrCreateArray<'a>( Builder: &DIBuilder<'a>, Ptr: *const Option<&'a DIDescriptor>, Count: c_uint, ) -> &'a DIArray; - pub(crate) fn LLVMRustDIBuilderInsertDeclareAtEnd<'a>( + pub fn LLVMRustDIBuilderInsertDeclareAtEnd<'a>( Builder: &DIBuilder<'a>, Val: &'a Value, VarInfo: &'a DIVariable, @@ -2308,7 +2145,7 @@ unsafe extern "C" { InsertAtEnd: &'a BasicBlock, ); - pub(crate) fn LLVMRustDIBuilderCreateEnumerator<'a>( + pub fn LLVMRustDIBuilderCreateEnumerator<'a>( Builder: &DIBuilder<'a>, Name: *const c_char, NameLen: size_t, @@ -2317,7 +2154,7 @@ unsafe extern "C" { IsUnsigned: bool, ) -> &'a DIEnumerator; - pub(crate) fn LLVMRustDIBuilderCreateEnumerationType<'a>( + pub fn LLVMRustDIBuilderCreateEnumerationType<'a>( Builder: &DIBuilder<'a>, Scope: &'a DIScope, Name: *const c_char, @@ -2331,7 +2168,7 @@ unsafe extern "C" { IsScoped: bool, ) -> &'a DIType; - pub(crate) fn LLVMRustDIBuilderCreateUnionType<'a>( + pub fn LLVMRustDIBuilderCreateUnionType<'a>( Builder: &DIBuilder<'a>, Scope: Option<&'a DIScope>, Name: *const c_char, @@ -2347,7 +2184,7 @@ unsafe extern "C" { UniqueIdLen: size_t, ) -> &'a DIType; - pub(crate) fn LLVMRustDIBuilderCreateVariantPart<'a>( + pub fn LLVMRustDIBuilderCreateVariantPart<'a>( Builder: &DIBuilder<'a>, Scope: &'a DIScope, Name: *const c_char, @@ -2363,7 +2200,7 @@ unsafe extern "C" { UniqueIdLen: size_t, ) -> &'a DIDerivedType; - pub(crate) fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>( + pub fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>( Builder: &DIBuilder<'a>, Scope: Option<&'a DIScope>, Name: *const c_char, @@ -2371,37 +2208,37 @@ unsafe extern "C" { Ty: &'a DIType, ) -> &'a DITemplateTypeParameter; - pub(crate) fn LLVMRustDICompositeTypeReplaceArrays<'a>( + pub fn LLVMRustDICompositeTypeReplaceArrays<'a>( Builder: &DIBuilder<'a>, CompositeType: &'a DIType, Elements: Option<&'a DIArray>, Params: Option<&'a DIArray>, ); - pub(crate) fn LLVMRustDILocationCloneWithBaseDiscriminator<'a>( + pub fn LLVMRustDILocationCloneWithBaseDiscriminator<'a>( Location: &'a DILocation, BD: c_uint, ) -> Option<&'a DILocation>; - pub(crate) fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString); - pub(crate) fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString); + pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString); + pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString); - pub(crate) fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool; + pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool; - pub(crate) fn LLVMRustPrintTargetCPUs(TM: &TargetMachine, OutStr: &RustString); - pub(crate) fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t; - pub(crate) fn LLVMRustGetTargetFeature( + pub fn LLVMRustPrintTargetCPUs(TM: &TargetMachine, OutStr: &RustString); + pub fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t; + pub fn LLVMRustGetTargetFeature( T: &TargetMachine, Index: size_t, Feature: &mut *const c_char, Desc: &mut *const c_char, ); - pub(crate) fn LLVMRustGetHostCPUName(LenOut: &mut size_t) -> *const u8; + pub fn LLVMRustGetHostCPUName(LenOut: &mut size_t) -> *const u8; // This function makes copies of pointed to data, so the data's lifetime may end after this // function returns. - pub(crate) fn LLVMRustCreateTargetMachine( + pub fn LLVMRustCreateTargetMachine( Triple: *const c_char, CPU: *const c_char, Features: *const c_char, @@ -2427,13 +2264,13 @@ unsafe extern "C" { ArgsCstrBuffLen: usize, ) -> *mut TargetMachine; - pub(crate) fn LLVMRustDisposeTargetMachine(T: *mut TargetMachine); - pub(crate) fn LLVMRustAddLibraryInfo<'a>( + pub fn LLVMRustDisposeTargetMachine(T: *mut TargetMachine); + pub fn LLVMRustAddLibraryInfo<'a>( PM: &PassManager<'a>, M: &'a Module, DisableSimplifyLibCalls: bool, ); - pub(crate) fn LLVMRustWriteOutputFile<'a>( + pub fn LLVMRustWriteOutputFile<'a>( T: &'a TargetMachine, PM: *mut PassManager<'a>, M: &'a Module, @@ -2442,7 +2279,7 @@ unsafe extern "C" { FileType: FileType, VerifyIR: bool, ) -> LLVMRustResult; - pub(crate) fn LLVMRustOptimize<'a>( + pub fn LLVMRustOptimize<'a>( M: &'a Module, TM: &'a TargetMachine, OptLevel: PassBuilderOptLevel, @@ -2479,32 +2316,29 @@ unsafe extern "C" { LLVMPlugins: *const c_char, LLVMPluginsLen: size_t, ) -> LLVMRustResult; - pub(crate) fn LLVMRustPrintModule( + pub fn LLVMRustPrintModule( M: &Module, Output: *const c_char, Demangle: extern "C" fn(*const c_char, size_t, *mut c_char, size_t) -> size_t, ) -> LLVMRustResult; - pub(crate) fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char); - pub(crate) fn LLVMRustPrintPasses(); - pub(crate) fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char); - pub(crate) fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t); - - pub(crate) fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>; - pub(crate) fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>; - pub(crate) fn LLVMRustArchiveIteratorNext<'a>( + pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char); + pub fn LLVMRustPrintPasses(); + pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char); + pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t); + + pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>; + pub fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>; + pub fn LLVMRustArchiveIteratorNext<'a>( AIR: &ArchiveIterator<'a>, ) -> Option<&'a mut ArchiveChild<'a>>; - pub(crate) fn LLVMRustArchiveChildName( - ACR: &ArchiveChild<'_>, - size: &mut size_t, - ) -> *const c_char; - pub(crate) fn LLVMRustArchiveChildFree<'a>(ACR: &'a mut ArchiveChild<'a>); - pub(crate) fn LLVMRustArchiveIteratorFree<'a>(AIR: &'a mut ArchiveIterator<'a>); - pub(crate) fn LLVMRustDestroyArchive(AR: &'static mut Archive); + pub fn LLVMRustArchiveChildName(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char; + pub fn LLVMRustArchiveChildFree<'a>(ACR: &'a mut ArchiveChild<'a>); + pub fn LLVMRustArchiveIteratorFree<'a>(AIR: &'a mut ArchiveIterator<'a>); + pub fn LLVMRustDestroyArchive(AR: &'static mut Archive); - pub(crate) fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString); + pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString); - pub(crate) fn LLVMRustUnpackOptimizationDiagnostic<'a>( + pub fn LLVMRustUnpackOptimizationDiagnostic<'a>( DI: &'a DiagnosticInfo, pass_name_out: &RustString, function_out: &mut Option<&'a Value>, @@ -2514,22 +2348,22 @@ unsafe extern "C" { message_out: &RustString, ); - pub(crate) fn LLVMRustUnpackInlineAsmDiagnostic<'a>( + pub fn LLVMRustUnpackInlineAsmDiagnostic<'a>( DI: &'a DiagnosticInfo, level_out: &mut DiagnosticLevel, cookie_out: &mut u64, message_out: &mut Option<&'a Twine>, ); - pub(crate) fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString); - pub(crate) fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind; + pub fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString); + pub fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind; - pub(crate) fn LLVMRustGetSMDiagnostic<'a>( + pub fn LLVMRustGetSMDiagnostic<'a>( DI: &'a DiagnosticInfo, cookie_out: &mut u64, ) -> &'a SMDiagnostic; - pub(crate) fn LLVMRustUnpackSMDiagnostic( + pub fn LLVMRustUnpackSMDiagnostic( d: &SMDiagnostic, message_out: &RustString, buffer_out: &RustString, @@ -2539,7 +2373,7 @@ unsafe extern "C" { num_ranges: &mut usize, ) -> bool; - pub(crate) fn LLVMRustWriteArchive( + pub fn LLVMRustWriteArchive( Dst: *const c_char, NumMembers: size_t, Members: *const &RustArchiveMember<'_>, @@ -2547,63 +2381,63 @@ unsafe extern "C" { Kind: ArchiveKind, isEC: bool, ) -> LLVMRustResult; - pub(crate) fn LLVMRustArchiveMemberNew<'a>( + pub fn LLVMRustArchiveMemberNew<'a>( Filename: *const c_char, Name: *const c_char, Child: Option<&ArchiveChild<'a>>, ) -> &'a mut RustArchiveMember<'a>; - pub(crate) fn LLVMRustArchiveMemberFree<'a>(Member: &'a mut RustArchiveMember<'a>); + pub fn LLVMRustArchiveMemberFree<'a>(Member: &'a mut RustArchiveMember<'a>); - pub(crate) fn LLVMRustSetDataLayoutFromTargetMachine<'a>(M: &'a Module, TM: &'a TargetMachine); + pub fn LLVMRustSetDataLayoutFromTargetMachine<'a>(M: &'a Module, TM: &'a TargetMachine); - pub(crate) fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock); + pub fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock); - pub(crate) fn LLVMRustSetModulePICLevel(M: &Module); - pub(crate) fn LLVMRustSetModulePIELevel(M: &Module); - pub(crate) fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel); - pub(crate) fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer; - pub(crate) fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8; - pub(crate) fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize; - pub(crate) fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer); - pub(crate) fn LLVMRustModuleCost(M: &Module) -> u64; - pub(crate) fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString); + pub fn LLVMRustSetModulePICLevel(M: &Module); + pub fn LLVMRustSetModulePIELevel(M: &Module); + pub fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel); + pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer; + pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8; + pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize; + pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer); + pub fn LLVMRustModuleCost(M: &Module) -> u64; + pub fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString); - pub(crate) fn LLVMRustThinLTOBufferCreate( + pub fn LLVMRustThinLTOBufferCreate( M: &Module, is_thin: bool, emit_summary: bool, ) -> &'static mut ThinLTOBuffer; - pub(crate) fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer); - pub(crate) fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char; - pub(crate) fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t; - pub(crate) fn LLVMRustThinLTOBufferThinLinkDataPtr(M: &ThinLTOBuffer) -> *const c_char; - pub(crate) fn LLVMRustThinLTOBufferThinLinkDataLen(M: &ThinLTOBuffer) -> size_t; - pub(crate) fn LLVMRustCreateThinLTOData( + pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer); + pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char; + pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t; + pub fn LLVMRustThinLTOBufferThinLinkDataPtr(M: &ThinLTOBuffer) -> *const c_char; + pub fn LLVMRustThinLTOBufferThinLinkDataLen(M: &ThinLTOBuffer) -> size_t; + pub fn LLVMRustCreateThinLTOData( Modules: *const ThinLTOModule, NumModules: size_t, PreservedSymbols: *const *const c_char, PreservedSymbolsLen: size_t, ) -> Option<&'static mut ThinLTOData>; - pub(crate) fn LLVMRustPrepareThinLTORename( + pub fn LLVMRustPrepareThinLTORename( Data: &ThinLTOData, Module: &Module, Target: &TargetMachine, ); - pub(crate) fn LLVMRustPrepareThinLTOResolveWeak(Data: &ThinLTOData, Module: &Module) -> bool; - pub(crate) fn LLVMRustPrepareThinLTOInternalize(Data: &ThinLTOData, Module: &Module) -> bool; - pub(crate) fn LLVMRustPrepareThinLTOImport( + pub fn LLVMRustPrepareThinLTOResolveWeak(Data: &ThinLTOData, Module: &Module) -> bool; + pub fn LLVMRustPrepareThinLTOInternalize(Data: &ThinLTOData, Module: &Module) -> bool; + pub fn LLVMRustPrepareThinLTOImport( Data: &ThinLTOData, Module: &Module, Target: &TargetMachine, ) -> bool; - pub(crate) fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData); - pub(crate) fn LLVMRustParseBitcodeForLTO( + pub fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData); + pub fn LLVMRustParseBitcodeForLTO( Context: &Context, Data: *const u8, len: usize, Identifier: *const c_char, ) -> Option<&Module>; - pub(crate) fn LLVMRustGetSliceFromObjectDataByName( + pub fn LLVMRustGetSliceFromObjectDataByName( data: *const u8, len: usize, name: *const u8, @@ -2611,27 +2445,25 @@ unsafe extern "C" { out_len: &mut usize, ) -> *const u8; - pub(crate) fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>; - pub(crate) fn LLVMRustLinkerAdd( + pub fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>; + pub fn LLVMRustLinkerAdd( linker: &Linker<'_>, bytecode: *const c_char, bytecode_len: usize, ) -> bool; - pub(crate) fn LLVMRustLinkerFree<'a>(linker: &'a mut Linker<'a>); - pub(crate) fn LLVMRustComputeLTOCacheKey( + pub fn LLVMRustLinkerFree<'a>(linker: &'a mut Linker<'a>); + pub fn LLVMRustComputeLTOCacheKey( key_out: &RustString, mod_id: *const c_char, data: &ThinLTOData, ); - pub(crate) fn LLVMRustContextGetDiagnosticHandler( - Context: &Context, - ) -> Option<&DiagnosticHandler>; - pub(crate) fn LLVMRustContextSetDiagnosticHandler( + pub fn LLVMRustContextGetDiagnosticHandler(Context: &Context) -> Option<&DiagnosticHandler>; + pub fn LLVMRustContextSetDiagnosticHandler( context: &Context, diagnostic_handler: Option<&DiagnosticHandler>, ); - pub(crate) fn LLVMRustContextConfigureDiagnosticHandler( + pub fn LLVMRustContextConfigureDiagnosticHandler( context: &Context, diagnostic_handler_callback: DiagnosticHandlerTy, diagnostic_handler_context: *mut c_void, @@ -2642,15 +2474,15 @@ unsafe extern "C" { pgo_available: bool, ); - pub(crate) fn LLVMRustGetMangledName(V: &Value, out: &RustString); + pub fn LLVMRustGetMangledName(V: &Value, out: &RustString); - pub(crate) fn LLVMRustGetElementTypeArgIndex(CallSite: &Value) -> i32; + pub fn LLVMRustGetElementTypeArgIndex(CallSite: &Value) -> i32; - pub(crate) fn LLVMRustLLVMHasZlibCompressionForDebugSymbols() -> bool; + pub fn LLVMRustLLVMHasZlibCompressionForDebugSymbols() -> bool; - pub(crate) fn LLVMRustLLVMHasZstdCompressionForDebugSymbols() -> bool; + pub fn LLVMRustLLVMHasZstdCompressionForDebugSymbols() -> bool; - pub(crate) fn LLVMRustGetSymbols( + pub fn LLVMRustGetSymbols( buf_ptr: *const u8, buf_len: usize, state: *mut c_void, @@ -2658,10 +2490,10 @@ unsafe extern "C" { error_callback: GetSymbolsErrorCallback, ) -> *mut c_void; - pub(crate) fn LLVMRustIs64BitSymbolicFile(buf_ptr: *const u8, buf_len: usize) -> bool; + pub fn LLVMRustIs64BitSymbolicFile(buf_ptr: *const u8, buf_len: usize) -> bool; - pub(crate) fn LLVMRustIsECObject(buf_ptr: *const u8, buf_len: usize) -> bool; + pub fn LLVMRustIsECObject(buf_ptr: *const u8, buf_len: usize) -> bool; - pub(crate) fn LLVMRustSetNoSanitizeAddress(Global: &Value); - pub(crate) fn LLVMRustSetNoSanitizeHWAddress(Global: &Value); + pub fn LLVMRustSetNoSanitizeAddress(Global: &Value); + pub fn LLVMRustSetNoSanitizeHWAddress(Global: &Value); } diff --git a/compiler/rustc_llvm/src/impls.rs b/compiler/rustc_llvm/src/impls.rs new file mode 100644 index 0000000000000..1c80cd231f35b --- /dev/null +++ b/compiler/rustc_llvm/src/impls.rs @@ -0,0 +1,77 @@ +use std::hash::{Hash, Hasher}; +use std::string::FromUtf8Error; +use std::{fmt, ptr}; + +fn build_string(f: impl FnOnce(&crate::RustString)) -> Result { + String::from_utf8(crate::RustString::build_byte_buffer(f)) +} + +impl PartialEq for crate::ffi::Metadata { + fn eq(&self, other: &Self) -> bool { + ptr::eq(self, other) + } +} + +impl Eq for crate::ffi::Metadata {} + +impl Hash for crate::ffi::Metadata { + fn hash(&self, hasher: &mut H) { + (self as *const Self).hash(hasher); + } +} + +impl fmt::Debug for crate::ffi::Metadata { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + (self as *const Self).fmt(f) + } +} + +impl PartialEq for crate::ffi::Type { + fn eq(&self, other: &Self) -> bool { + ptr::eq(self, other) + } +} + +impl Eq for crate::ffi::Type {} + +impl Hash for crate::ffi::Type { + fn hash(&self, state: &mut H) { + ptr::hash(self, state); + } +} + +impl fmt::Debug for crate::ffi::Type { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str( + &build_string(|s| unsafe { + crate::ffi::LLVMRustWriteTypeToString(self, s); + }) + .expect("non-UTF8 type description from LLVM"), + ) + } +} + +impl PartialEq for crate::ffi::Value { + fn eq(&self, other: &Self) -> bool { + ptr::eq(self, other) + } +} + +impl Eq for crate::ffi::Value {} + +impl Hash for crate::ffi::Value { + fn hash(&self, hasher: &mut H) { + (self as *const Self).hash(hasher); + } +} + +impl fmt::Debug for crate::ffi::Value { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str( + &build_string(|s| unsafe { + crate::ffi::LLVMRustWriteValueToString(self, s); + }) + .expect("non-UTF8 value description from LLVM"), + ) + } +} diff --git a/compiler/rustc_llvm/src/lib.rs b/compiler/rustc_llvm/src/lib.rs index ed5edeef1617d..a89da2fb52f19 100644 --- a/compiler/rustc_llvm/src/lib.rs +++ b/compiler/rustc_llvm/src/lib.rs @@ -11,6 +11,9 @@ use std::{ptr, slice}; use libc::size_t; +pub mod ffi; +mod impls; + unsafe extern "C" { /// Opaque type that allows C++ code to write bytes to a Rust-side buffer, /// in conjunction with `RawRustStringOstream`. Use this as `&RustString` diff --git a/triagebot.toml b/triagebot.toml index 9f8ea2dad52fe..011cda091576c 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -256,7 +256,7 @@ trigger_files = [ "compiler/rustc_ast/src/expand/autodiff_attrs.rs", "compiler/rustc_monomorphize/src/partitioning/autodiff.rs", "compiler/rustc_codegen_llvm/src/builder/autodiff.rs", - "compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs", + "compiler/rustc_llvm/src/ffi/enzyme.rs", ] [autolabel."T-rustdoc-frontend"] @@ -1258,7 +1258,7 @@ cc = ["@ZuseZ4"] cc = ["@ZuseZ4"] [mentions."compiler/rustc_codegen_llvm/src/builder/autodiff.rs"] cc = ["@ZuseZ4"] -[mentions."compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs"] +[mentions."compiler/rustc_llvm/src/ffi/enzyme.rs"] cc = ["@ZuseZ4"] [mentions."library/core/src/fmt/rt.rs"]