Skip to content

Commit e49a0cc

Browse files
nnethercoteLegNeato
authored andcommitted
Update to nightly-2025-07-14.
- `BuilderMethods::dynamic_alloca` was removed. - `AddressSpace::DATA` was renamed `AddressSpace::ZERO`. - `GlobalAlloc` has a new variant `TypeId` which must be handled in `scalar_to_backend`; I just copied what the llvm backend does. - `TargetDataLayout::pointer_{size,align}` were changed from fields to methods. - `TargetDataLayout::parse_from_llvm_datalayout_string` gained a second argument.
1 parent 1b253fd commit e49a0cc

File tree

8 files changed

+27
-32
lines changed

8 files changed

+27
-32
lines changed

crates/rustc_codegen_nvvm/src/builder.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -483,17 +483,6 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
483483
}
484484
}
485485

486-
fn dynamic_alloca(&mut self, size: &'ll Value, align: Align) -> &'ll Value {
487-
trace!("Dynamic Alloca `{:?}`", size);
488-
unsafe {
489-
let alloca =
490-
llvm::LLVMBuildArrayAlloca(self.llbuilder, self.cx().type_i8(), size, UNNAMED);
491-
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint);
492-
// Cast to default addrspace if necessary
493-
llvm::LLVMBuildPointerCast(self.llbuilder, alloca, self.cx().type_ptr(), UNNAMED)
494-
}
495-
}
496-
497486
fn load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value {
498487
trace!("Load {ty:?} {:?}", ptr);
499488
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> {
901890
if kind == llvm::TypeKind::Pointer {
902891
let element = self.element_type(ty);
903892
let addrspace = llvm::LLVMGetPointerAddressSpace(ty);
904-
let new_ty = self.type_ptr_to_ext(element, AddressSpace::DATA);
893+
let new_ty = self.type_ptr_to_ext(element, AddressSpace::ZERO);
905894
if addrspace != 0 {
906895
trace!("injecting addrspace cast for `{:?}` to `{:?}`", ty, new_ty);
907896
val = llvm::LLVMBuildAddrSpaceCast(self.llbuilder, val, new_ty, UNNAMED);

crates/rustc_codegen_nvvm/src/const_ty.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
8787
let sc = self.const_bytes(s.as_bytes());
8888
let sym = self.generate_local_symbol_name("str");
8989
let g = self
90-
.define_global(&sym[..], self.val_ty(sc), AddressSpace::DATA)
90+
.define_global(&sym[..], self.val_ty(sc), AddressSpace::ZERO)
9191
.unwrap_or_else(|| {
9292
bug!("symbol `{}` is already defined", sym);
9393
});
@@ -185,7 +185,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
185185
format!("alloc_{hash:032x}").as_bytes(),
186186
);
187187
}
188-
(value, AddressSpace::DATA)
188+
(value, AddressSpace::ZERO)
189189
}
190190
}
191191
GlobalAlloc::Function { instance, .. } => (
@@ -204,7 +204,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
204204
.unwrap_memory();
205205
let init = const_alloc_to_llvm(self, alloc, /*static*/ false);
206206
let value = self.static_addr_of(init, alloc.inner().align, None);
207-
(value, AddressSpace::DATA)
207+
(value, AddressSpace::ZERO)
208208
}
209209
GlobalAlloc::Static(def_id) => {
210210
assert!(self.tcx.is_static(def_id));
@@ -214,6 +214,11 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
214214
unsafe { llvm::LLVMGetPointerAddressSpace(self.val_ty(val)) };
215215
(val, AddressSpace(addrspace))
216216
}
217+
GlobalAlloc::TypeId { .. } => {
218+
// Drop the provenance, the offset contains the bytes of the hash
219+
let llval = self.const_usize(offset.bytes());
220+
return unsafe { llvm::LLVMConstIntToPtr(llval, llty) };
221+
}
217222
};
218223
let llval = unsafe {
219224
llvm::LLVMConstInBoundsGEP2(
@@ -228,7 +233,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
228233
if !matches!(layout.primitive(), Pointer(_)) {
229234
unsafe { llvm::LLVMConstPtrToInt(llval, llty) }
230235
} else {
231-
if base_addr_space != AddressSpace::DATA {
236+
if base_addr_space != AddressSpace::ZERO {
232237
unsafe {
233238
let element = llvm::LLVMGetElementType(llty);
234239
llty = self.type_ptr_to_ext(element, base_addr_space);

crates/rustc_codegen_nvvm/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(crate) fn const_alloc_to_llvm<'ll>(
6060
}
6161
let mut llvals = Vec::with_capacity(alloc.provenance().ptrs().len() + 1);
6262
let dl = cx.data_layout();
63-
let pointer_size = dl.pointer_size.bytes() as usize;
63+
let pointer_size = dl.pointer_size().bytes() as usize;
6464

6565
// Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`,
6666
// so `range` must be within the bounds of `alloc` and not contain or overlap a relocation.
@@ -253,7 +253,7 @@ impl<'ll> CodegenCx<'ll, '_> {
253253
// TODO(RDambrosio016): replace this with latest rustc's handling when we use llvm 13
254254
let name = self.generate_local_symbol_name(kind.unwrap_or("private"));
255255
let gv = self
256-
.define_global(&name[..], self.val_ty(cv), AddressSpace::DATA)
256+
.define_global(&name[..], self.val_ty(cv), AddressSpace::ZERO)
257257
.unwrap_or_else(|| bug!("symbol `{}` is already defined", name));
258258
llvm::LLVMRustSetLinkage(gv, llvm::Linkage::PrivateLinkage);
259259
llvm::LLVMSetInitializer(gv, cv);

crates/rustc_codegen_nvvm/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
161161
local_gen_sym_counter: Cell::new(0),
162162
nvptx_data_layout: TargetDataLayout::parse_from_llvm_datalayout_string(
163163
&target::target().data_layout,
164+
AddressSpace::ZERO,
164165
)
165166
.unwrap_or_else(|err| tcx.sess.dcx().emit_fatal(err)),
166167
nvptx_target: target::target(),
@@ -292,7 +293,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
292293
}
293294
}
294295
} else {
295-
AddressSpace::DATA
296+
AddressSpace::ZERO
296297
}
297298
}
298299

crates/rustc_codegen_nvvm/src/debug_info/metadata.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
167167
None => {
168168
// This is a thin pointer. Create a regular pointer type and give it the correct name.
169169
assert_eq!(
170-
(data_layout.pointer_size, data_layout.pointer_align.abi),
170+
(data_layout.pointer_size(), data_layout.pointer_align().abi),
171171
cx.size_and_align_of(ptr_type),
172172
"ptr_type={ptr_type}, pointee_type={pointee_type}",
173173
);
@@ -176,8 +176,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
176176
llvm::LLVMRustDIBuilderCreatePointerType(
177177
DIB(cx),
178178
pointee_type_di_node,
179-
data_layout.pointer_size.bits(),
180-
data_layout.pointer_align.abi.bits() as u32,
179+
data_layout.pointer_size().bits(),
180+
data_layout.pointer_align().abi.bits() as u32,
181181
CString::new(ptr_type_debuginfo_name).unwrap().as_ptr(),
182182
)
183183
};
@@ -335,8 +335,8 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
335335
let (size, align) = match fn_ty.kind() {
336336
ty::FnDef(..) => (0, 1),
337337
ty::FnPtr(..) => (
338-
cx.tcx.data_layout.pointer_size.bits(),
339-
cx.tcx.data_layout.pointer_align.abi.bits() as u32,
338+
cx.tcx.data_layout.pointer_size().bits(),
339+
cx.tcx.data_layout.pointer_align().abi.bits() as u32,
340340
),
341341
_ => unreachable!(),
342342
};
@@ -527,7 +527,7 @@ fn recursion_marker_type_di_node<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll DIType {
527527
DIB(cx),
528528
name.as_c_char_ptr(),
529529
name.len(),
530-
cx.tcx.data_layout.pointer_size.bits(),
530+
cx.tcx.data_layout.pointer_size().bits(),
531531
dwarf_const::DW_ATE_unsigned,
532532
)
533533
}

crates/rustc_codegen_nvvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
528528
// For rusty ABIs, small aggregates are actually passed
529529
// as `RegKind::Integer` (see `FnAbi::adjust_for_abi`),
530530
// so we re-use that same threshold here.
531-
layout.size <= self.data_layout().pointer_size * 2
531+
layout.size <= self.data_layout().pointer_size() * 2
532532
}
533533
};
534534

crates/rustc_codegen_nvvm/src/ty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'ll> CodegenCx<'ll, '_> {
5757
pub(crate) fn voidp(&self) -> &'ll Type {
5858
// llvm uses i8* for void ptrs, void* is invalid
5959
let i8_ty = self.type_i8();
60-
self.type_ptr_to_ext(i8_ty, AddressSpace::DATA)
60+
self.type_ptr_to_ext(i8_ty, AddressSpace::ZERO)
6161
}
6262

6363
pub(crate) fn type_named_struct(&self, name: &str) -> &'ll Type {
@@ -93,7 +93,7 @@ impl<'ll> CodegenCx<'ll, '_> {
9393
}
9494

9595
pub(crate) fn type_i8p(&self) -> &'ll Type {
96-
self.type_i8p_ext(AddressSpace::DATA)
96+
self.type_i8p_ext(AddressSpace::ZERO)
9797
}
9898

9999
pub(crate) fn type_i8p_ext(&self, address_space: AddressSpace) -> &'ll Type {
@@ -116,7 +116,7 @@ impl<'ll> CodegenCx<'ll, '_> {
116116
"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"
117117
);
118118

119-
unsafe { llvm::LLVMPointerType(ty, AddressSpace::DATA.0) }
119+
unsafe { llvm::LLVMPointerType(ty, AddressSpace::ZERO.0) }
120120
}
121121

122122
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> {
211211
}
212212

213213
fn type_ptr(&self) -> Self::Type {
214-
self.type_ptr_ext(AddressSpace::DATA)
214+
self.type_ptr_ext(AddressSpace::ZERO)
215215
}
216216

217217
fn type_ptr_ext(&self, address_space: AddressSpace) -> Self::Type {
@@ -434,7 +434,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
434434
{
435435
(cx.type_pointee_for_align(align), address_space)
436436
} else {
437-
(cx.type_i8(), AddressSpace::DATA)
437+
(cx.type_i8(), AddressSpace::ZERO)
438438
};
439439
cx.type_ptr_to_ext(pointee, address_space)
440440
}

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2025-07-07"
2+
channel = "nightly-2025-07-14"
33
components = ["clippy", "llvm-tools-preview", "rust-src", "rustc-dev", "rustfmt", "rust-analyzer"]

0 commit comments

Comments
 (0)