diff --git a/crates/rustc_codegen_nvvm/src/back.rs b/crates/rustc_codegen_nvvm/src/back.rs index 51be03ac..102097a1 100644 --- a/crates/rustc_codegen_nvvm/src/back.rs +++ b/crates/rustc_codegen_nvvm/src/back.rs @@ -157,10 +157,12 @@ pub extern "C" fn demangle_callback( /// Compile a single module (in an nvvm context this means getting the llvm bitcode out of it) pub(crate) unsafe fn codegen( cgcx: &CodegenContext, - dcx: DiagCtxtHandle<'_>, module: ModuleCodegen, config: &ModuleConfig, ) -> Result { + let dcx = cgcx.create_dcx(); + let dcx = dcx.handle(); + // For NVVM, all the codegen we need to do is turn the llvm modules // into llvm bitcode and write them to a tempdir. nvvm expects llvm // bitcode as the modules to be added to the program. Then as the last step diff --git a/crates/rustc_codegen_nvvm/src/builder.rs b/crates/rustc_codegen_nvvm/src/builder.rs index 44488c9f..3002a3bd 100644 --- a/crates/rustc_codegen_nvvm/src/builder.rs +++ b/crates/rustc_codegen_nvvm/src/builder.rs @@ -483,17 +483,6 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn dynamic_alloca(&mut self, size: &'ll Value, align: Align) -> &'ll Value { - trace!("Dynamic Alloca `{:?}`", size); - unsafe { - let alloca = - llvm::LLVMBuildArrayAlloca(self.llbuilder, self.cx().type_i8(), size, UNNAMED); - llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint); - // Cast to default addrspace if necessary - llvm::LLVMBuildPointerCast(self.llbuilder, alloca, self.cx().type_ptr(), UNNAMED) - } - } - fn load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value { trace!("Load {ty:?} {:?}", ptr); let ptr = self.pointercast(ptr, self.cx.type_ptr_to(ty)); @@ -901,7 +890,7 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { if kind == llvm::TypeKind::Pointer { let element = self.element_type(ty); let addrspace = llvm::LLVMGetPointerAddressSpace(ty); - let new_ty = self.type_ptr_to_ext(element, AddressSpace::DATA); + let new_ty = self.type_ptr_to_ext(element, AddressSpace::ZERO); if addrspace != 0 { trace!("injecting addrspace cast for `{:?}` to `{:?}`", ty, new_ty); val = llvm::LLVMBuildAddrSpaceCast(self.llbuilder, val, new_ty, UNNAMED); diff --git a/crates/rustc_codegen_nvvm/src/const_ty.rs b/crates/rustc_codegen_nvvm/src/const_ty.rs index 48bdfc31..10b28191 100644 --- a/crates/rustc_codegen_nvvm/src/const_ty.rs +++ b/crates/rustc_codegen_nvvm/src/const_ty.rs @@ -87,7 +87,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { let sc = self.const_bytes(s.as_bytes()); let sym = self.generate_local_symbol_name("str"); let g = self - .define_global(&sym[..], self.val_ty(sc), AddressSpace::DATA) + .define_global(&sym[..], self.val_ty(sc), AddressSpace::ZERO) .unwrap_or_else(|| { bug!("symbol `{}` is already defined", sym); }); @@ -185,7 +185,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { format!("alloc_{hash:032x}").as_bytes(), ); } - (value, AddressSpace::DATA) + (value, AddressSpace::ZERO) } } GlobalAlloc::Function { instance, .. } => ( @@ -204,7 +204,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { .unwrap_memory(); let init = const_alloc_to_llvm(self, alloc, /*static*/ false); let value = self.static_addr_of(init, alloc.inner().align, None); - (value, AddressSpace::DATA) + (value, AddressSpace::ZERO) } GlobalAlloc::Static(def_id) => { assert!(self.tcx.is_static(def_id)); @@ -214,6 +214,11 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { unsafe { llvm::LLVMGetPointerAddressSpace(self.val_ty(val)) }; (val, AddressSpace(addrspace)) } + GlobalAlloc::TypeId { .. } => { + // Drop the provenance, the offset contains the bytes of the hash + let llval = self.const_usize(offset.bytes()); + return unsafe { llvm::LLVMConstIntToPtr(llval, llty) }; + } }; let llval = unsafe { llvm::LLVMConstInBoundsGEP2( @@ -228,7 +233,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { if !matches!(layout.primitive(), Pointer(_)) { unsafe { llvm::LLVMConstPtrToInt(llval, llty) } } else { - if base_addr_space != AddressSpace::DATA { + if base_addr_space != AddressSpace::ZERO { unsafe { let element = llvm::LLVMGetElementType(llty); llty = self.type_ptr_to_ext(element, base_addr_space); diff --git a/crates/rustc_codegen_nvvm/src/consts.rs b/crates/rustc_codegen_nvvm/src/consts.rs index a6b6ca4d..1d904f68 100644 --- a/crates/rustc_codegen_nvvm/src/consts.rs +++ b/crates/rustc_codegen_nvvm/src/consts.rs @@ -60,7 +60,7 @@ pub(crate) fn const_alloc_to_llvm<'ll>( } let mut llvals = Vec::with_capacity(alloc.provenance().ptrs().len() + 1); let dl = cx.data_layout(); - let pointer_size = dl.pointer_size.bytes() as usize; + let pointer_size = dl.pointer_size().bytes() as usize; // Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`, // so `range` must be within the bounds of `alloc` and not contain or overlap a relocation. @@ -253,7 +253,7 @@ impl<'ll> CodegenCx<'ll, '_> { // TODO(RDambrosio016): replace this with latest rustc's handling when we use llvm 13 let name = self.generate_local_symbol_name(kind.unwrap_or("private")); let gv = self - .define_global(&name[..], self.val_ty(cv), AddressSpace::DATA) + .define_global(&name[..], self.val_ty(cv), AddressSpace::ZERO) .unwrap_or_else(|| bug!("symbol `{}` is already defined", name)); llvm::LLVMRustSetLinkage(gv, llvm::Linkage::PrivateLinkage); llvm::LLVMSetInitializer(gv, cv); diff --git a/crates/rustc_codegen_nvvm/src/context.rs b/crates/rustc_codegen_nvvm/src/context.rs index 253bb457..ab89818f 100644 --- a/crates/rustc_codegen_nvvm/src/context.rs +++ b/crates/rustc_codegen_nvvm/src/context.rs @@ -161,6 +161,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { local_gen_sym_counter: Cell::new(0), nvptx_data_layout: TargetDataLayout::parse_from_llvm_datalayout_string( &target::target().data_layout, + AddressSpace::ZERO, ) .unwrap_or_else(|err| tcx.sess.dcx().emit_fatal(err)), nvptx_target: target::target(), @@ -292,7 +293,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { } } } else { - AddressSpace::DATA + AddressSpace::ZERO } } diff --git a/crates/rustc_codegen_nvvm/src/debug_info/metadata.rs b/crates/rustc_codegen_nvvm/src/debug_info/metadata.rs index dbab74e1..7d148d2a 100644 --- a/crates/rustc_codegen_nvvm/src/debug_info/metadata.rs +++ b/crates/rustc_codegen_nvvm/src/debug_info/metadata.rs @@ -167,7 +167,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( None => { // This is a thin pointer. Create a regular pointer type and give it the correct name. assert_eq!( - (data_layout.pointer_size, data_layout.pointer_align.abi), + (data_layout.pointer_size(), data_layout.pointer_align().abi), cx.size_and_align_of(ptr_type), "ptr_type={ptr_type}, pointee_type={pointee_type}", ); @@ -176,8 +176,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( llvm::LLVMRustDIBuilderCreatePointerType( DIB(cx), pointee_type_di_node, - data_layout.pointer_size.bits(), - data_layout.pointer_align.abi.bits() as u32, + data_layout.pointer_size().bits(), + data_layout.pointer_align().abi.bits() as u32, CString::new(ptr_type_debuginfo_name).unwrap().as_ptr(), ) }; @@ -335,8 +335,8 @@ fn build_subroutine_type_di_node<'ll, 'tcx>( let (size, align) = match fn_ty.kind() { ty::FnDef(..) => (0, 1), ty::FnPtr(..) => ( - cx.tcx.data_layout.pointer_size.bits(), - cx.tcx.data_layout.pointer_align.abi.bits() as u32, + cx.tcx.data_layout.pointer_size().bits(), + cx.tcx.data_layout.pointer_align().abi.bits() as u32, ), _ => unreachable!(), }; @@ -527,7 +527,7 @@ fn recursion_marker_type_di_node<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll DIType { DIB(cx), name.as_c_char_ptr(), name.len(), - cx.tcx.data_layout.pointer_size.bits(), + cx.tcx.data_layout.pointer_size().bits(), dwarf_const::DW_ATE_unsigned, ) } diff --git a/crates/rustc_codegen_nvvm/src/intrinsic.rs b/crates/rustc_codegen_nvvm/src/intrinsic.rs index 0a805b89..2bc8db0b 100644 --- a/crates/rustc_codegen_nvvm/src/intrinsic.rs +++ b/crates/rustc_codegen_nvvm/src/intrinsic.rs @@ -528,7 +528,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { // For rusty ABIs, small aggregates are actually passed // as `RegKind::Integer` (see `FnAbi::adjust_for_abi`), // so we re-use that same threshold here. - layout.size <= self.data_layout().pointer_size * 2 + layout.size <= self.data_layout().pointer_size() * 2 } }; diff --git a/crates/rustc_codegen_nvvm/src/lib.rs b/crates/rustc_codegen_nvvm/src/lib.rs index ead012fa..8e5fbd63 100644 --- a/crates/rustc_codegen_nvvm/src/lib.rs +++ b/crates/rustc_codegen_nvvm/src/lib.rs @@ -63,7 +63,7 @@ use rustc_ast::expand::autodiff_attrs::AutoDiffItem; use rustc_codegen_ssa::{ CodegenResults, CompiledModule, ModuleCodegen, TargetConfig, back::{ - lto::{LtoModuleCodegen, SerializedModule, ThinModule}, + lto::{SerializedModule, ThinModule}, write::{CodegenContext, FatLtoInput, ModuleConfig, OngoingCodegen}, }, traits::{CodegenBackend, ExtraBackendMethods, WriteBackendMethods}, @@ -83,6 +83,7 @@ use rustc_session::{ use tracing::debug; use std::ffi::CString; +use std::path::PathBuf; // codegen dylib entrypoint #[unsafe(no_mangle)] @@ -275,19 +276,25 @@ impl WriteBackendMethods for NvvmCodegenBackend { todo!(); } - fn run_fat_lto( - _: &CodegenContext, - _: Vec>, - _: Vec<(SerializedModule, WorkProduct)>, - ) -> Result, FatalError> { + fn run_and_optimize_fat_lto( + _cgcx: &CodegenContext, + _exported_symbols_for_lto: &[String], + _each_linked_rlib_for_lto: &[PathBuf], + _modules: Vec>, + _diff_fncs: Vec, + ) -> Result, FatalError> { todo!() } fn run_thin_lto( cgcx: &CodegenContext, + // FIXME: Limit LTO exports to these symbols + _exported_symbols_for_lto: &[String], + // FIXME: handle these? but only relevant for non-thin LTO? + _each_linked_rlib_for_lto: &[PathBuf], modules: Vec<(String, Self::ThinBuffer)>, cached_modules: Vec<(SerializedModule, WorkProduct)>, - ) -> Result<(Vec>, Vec), FatalError> { + ) -> Result<(Vec>, Vec), FatalError> { lto::run_thin(cgcx, modules, cached_modules) } @@ -317,11 +324,10 @@ impl WriteBackendMethods for NvvmCodegenBackend { fn codegen( cgcx: &CodegenContext, - diag_handler: DiagCtxtHandle<'_>, module: ModuleCodegen, config: &ModuleConfig, ) -> Result { - unsafe { back::codegen(cgcx, diag_handler, module, config) } + unsafe { back::codegen(cgcx, module, config) } } fn prepare_thin( @@ -346,22 +352,6 @@ impl WriteBackendMethods for NvvmCodegenBackend { ) } } - - fn optimize_fat( - _cgcx: &CodegenContext, - _llmod: &mut ModuleCodegen, - ) -> Result<(), FatalError> { - todo!() - } - - fn autodiff( - _cgcx: &CodegenContext, - _module: &ModuleCodegen, - _diff_fncs: Vec, - _config: &ModuleConfig, - ) -> Result<(), FatalError> { - todo!() - } } impl ExtraBackendMethods for NvvmCodegenBackend { diff --git a/crates/rustc_codegen_nvvm/src/lto.rs b/crates/rustc_codegen_nvvm/src/lto.rs index 7d5474ff..197812da 100644 --- a/crates/rustc_codegen_nvvm/src/lto.rs +++ b/crates/rustc_codegen_nvvm/src/lto.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use rustc_codegen_ssa::{ ModuleCodegen, back::{ - lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared}, + lto::{SerializedModule, ThinModule, ThinShared}, write::CodegenContext, }, traits::{ModuleBufferMethods, ThinBufferMethods}, @@ -106,7 +106,7 @@ pub(crate) fn run_thin( _cgcx: &CodegenContext, modules: Vec<(String, ThinBuffer)>, cached_modules: Vec<(SerializedModule, WorkProduct)>, -) -> Result<(Vec>, Vec), FatalError> { +) -> Result<(Vec>, Vec), FatalError> { debug!("Running thin LTO"); let mut thin_buffers = Vec::with_capacity(modules.len()); let mut module_names = Vec::with_capacity(modules.len() + cached_modules.len()); @@ -142,10 +142,10 @@ pub(crate) fn run_thin( let mut opt_jobs = vec![]; for (module_index, _) in shared.module_names.iter().enumerate() { - opt_jobs.push(LtoModuleCodegen::Thin(ThinModule { + opt_jobs.push(ThinModule { shared: shared.clone(), idx: module_index, - })); + }); } Ok((opt_jobs, vec![])) diff --git a/crates/rustc_codegen_nvvm/src/ty.rs b/crates/rustc_codegen_nvvm/src/ty.rs index ca738508..b88a2dea 100644 --- a/crates/rustc_codegen_nvvm/src/ty.rs +++ b/crates/rustc_codegen_nvvm/src/ty.rs @@ -57,7 +57,7 @@ impl<'ll> CodegenCx<'ll, '_> { pub(crate) fn voidp(&self) -> &'ll Type { // llvm uses i8* for void ptrs, void* is invalid let i8_ty = self.type_i8(); - self.type_ptr_to_ext(i8_ty, AddressSpace::DATA) + self.type_ptr_to_ext(i8_ty, AddressSpace::ZERO) } pub(crate) fn type_named_struct(&self, name: &str) -> &'ll Type { @@ -93,7 +93,7 @@ impl<'ll> CodegenCx<'ll, '_> { } pub(crate) fn type_i8p(&self) -> &'ll Type { - self.type_i8p_ext(AddressSpace::DATA) + self.type_i8p_ext(AddressSpace::ZERO) } pub(crate) fn type_i8p_ext(&self, address_space: AddressSpace) -> &'ll Type { @@ -116,7 +116,7 @@ impl<'ll> CodegenCx<'ll, '_> { "don't call ptr_to on function types, use ptr_to_llvm_type on FnAbi instead or explicitly specify an address space if it makes sense" ); - unsafe { llvm::LLVMPointerType(ty, AddressSpace::DATA.0) } + unsafe { llvm::LLVMPointerType(ty, AddressSpace::ZERO.0) } } pub(crate) fn type_ptr_to_ext(&self, ty: &'ll Type, address_space: AddressSpace) -> &'ll Type { @@ -211,7 +211,7 @@ impl<'ll, 'tcx> BaseTypeCodegenMethods for CodegenCx<'ll, 'tcx> { } fn type_ptr(&self) -> Self::Type { - self.type_ptr_ext(AddressSpace::DATA) + self.type_ptr_ext(AddressSpace::ZERO) } fn type_ptr_ext(&self, address_space: AddressSpace) -> Self::Type { @@ -434,7 +434,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { { (cx.type_pointee_for_align(align), address_space) } else { - (cx.type_i8(), AddressSpace::DATA) + (cx.type_i8(), AddressSpace::ZERO) }; cx.type_ptr_to_ext(pointee, address_space) } @@ -651,11 +651,11 @@ impl<'tcx> CodegenCx<'_, 'tcx> { } impl<'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> { - fn add_type_metadata(&self, _function: Self::Function, _typeid: String) {} + fn add_type_metadata(&self, _function: Self::Function, _typeid: &[u8]) {} - fn set_type_metadata(&self, _function: Self::Function, _typeid: String) {} + fn set_type_metadata(&self, _function: Self::Function, _typeid: &[u8]) {} - fn typeid_metadata(&self, _typeid: String) -> Option { + fn typeid_metadata(&self, _typeid: &[u8]) -> Option { None } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index beddb066..09c91de7 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2025-07-07" +channel = "nightly-2025-07-28" components = ["clippy", "llvm-tools-preview", "rust-src", "rustc-dev", "rustfmt", "rust-analyzer"] diff --git a/tests/compiletests/ui/dis/target_feature_base_cc.stderr b/tests/compiletests/ui/dis/target_feature_base_cc.stderr index 8d6ad01b..ad7001d8 100644 --- a/tests/compiletests/ui/dis/target_feature_base_cc.stderr +++ b/tests/compiletests/ui/dis/target_feature_base_cc.stderr @@ -17,7 +17,7 @@ $L__tmp1: .loc 1 38 5 bra.uni $L__tmp2; $L__tmp2: - .loc 2 2180 9 + .loc 2 2198 9 mov.u32 %r1, 1124204544; st.volatile.global.u32 [%rd2], %r1; $L__tmp3: