Skip to content

Commit 4d62686

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 6f06667 + 6f1b56c commit 4d62686

File tree

280 files changed

+3266
-2828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+3266
-2828
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -874,25 +874,32 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
874874
/// name resolver owing to lifetime elision; this also populates the resolver's node-id->def-id
875875
/// map, so that later calls to `opt_node_id_to_def_id` that refer to these extra lifetime
876876
/// parameters will be successful.
877-
#[instrument(level = "debug", skip(self))]
877+
#[instrument(level = "debug", skip(self), ret)]
878878
#[inline]
879879
fn lower_lifetime_binder(
880880
&mut self,
881881
binder: NodeId,
882882
generic_params: &[GenericParam],
883883
) -> &'hir [hir::GenericParam<'hir>] {
884-
let mut generic_params: Vec<_> = self
885-
.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder)
886-
.collect();
884+
// Start by creating params for extra lifetimes params, as this creates the definitions
885+
// that may be referred to by the AST inside `generic_params`.
887886
let extra_lifetimes = self.resolver.extra_lifetime_params(binder);
888887
debug!(?extra_lifetimes);
889-
generic_params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
890-
self.lifetime_res_to_generic_param(ident, node_id, res, hir::GenericParamSource::Binder)
891-
}));
892-
let generic_params = self.arena.alloc_from_iter(generic_params);
893-
debug!(?generic_params);
894-
895-
generic_params
888+
let extra_lifetimes: Vec<_> = extra_lifetimes
889+
.into_iter()
890+
.filter_map(|(ident, node_id, res)| {
891+
self.lifetime_res_to_generic_param(
892+
ident,
893+
node_id,
894+
res,
895+
hir::GenericParamSource::Binder,
896+
)
897+
})
898+
.collect();
899+
let arena = self.arena;
900+
let explicit_generic_params =
901+
self.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder);
902+
arena.alloc_from_iter(explicit_generic_params.chain(extra_lifetimes.into_iter()))
896903
}
897904

898905
fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ pub enum CfgEntry {
234234
pub enum AttributeKind {
235235
// tidy-alphabetical-start
236236
/// Represents `#[align(N)]`.
237+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
237238
Align { align: Align, span: Span },
238239

239240
/// Represents `#[rustc_allow_const_fn_unstable]`.

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ impl<S: Stage> AttributeParser<S> for NakedParser {
177177
sym::instruction_set,
178178
sym::repr,
179179
sym::rustc_std_internal_symbol,
180-
sym::align,
180+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
181+
sym::rustc_align,
181182
// obviously compatible with self
182183
sym::naked,
183184
// documentation

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn parse_alignment(node: &LitKind) -> Result<Align, &'static str> {
274274
pub(crate) struct AlignParser(Option<(Align, Span)>);
275275

276276
impl AlignParser {
277-
const PATH: &'static [Symbol] = &[sym::align];
277+
const PATH: &'static [Symbol] = &[sym::rustc_align];
278278
const TEMPLATE: AttributeTemplate = template!(List: "<alignment in bytes>");
279279

280280
fn parse<'c, S: Stage>(

compiler/rustc_codegen_cranelift/example/float-minmax-pass.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#[derive(Copy, Clone, PartialEq, Debug)]
1212
struct f32x4(pub [f32; 4]);
1313

14+
impl f32x4 {
15+
fn into_array(self) -> [f32; 4] {
16+
unsafe { std::mem::transmute(self) }
17+
}
18+
}
19+
1420
use std::intrinsics::simd::*;
1521

1622
fn main() {
@@ -29,22 +35,22 @@ fn main() {
2935
unsafe {
3036
let min0 = simd_fmin(x, y);
3137
let min1 = simd_fmin(y, x);
32-
assert_eq!(min0, min1);
38+
assert_eq!(min0.into_array(), min1.into_array());
3339
let e = f32x4([1.0, 1.0, 3.0, 3.0]);
34-
assert_eq!(min0, e);
40+
assert_eq!(min0.into_array(), e.into_array());
3541
let minn = simd_fmin(x, n);
36-
assert_eq!(minn, x);
42+
assert_eq!(minn.into_array(), x.into_array());
3743
let minn = simd_fmin(y, n);
38-
assert_eq!(minn, y);
44+
assert_eq!(minn.into_array(), y.into_array());
3945

4046
let max0 = simd_fmax(x, y);
4147
let max1 = simd_fmax(y, x);
42-
assert_eq!(max0, max1);
48+
assert_eq!(max0.into_array(), max1.into_array());
4349
let e = f32x4([2.0, 2.0, 4.0, 4.0]);
44-
assert_eq!(max0, e);
50+
assert_eq!(max0.into_array(), e.into_array());
4551
let maxn = simd_fmax(x, n);
46-
assert_eq!(maxn, x);
52+
assert_eq!(maxn.into_array(), x.into_array());
4753
let maxn = simd_fmax(y, n);
48-
assert_eq!(maxn, y);
54+
assert_eq!(maxn.into_array(), y.into_array());
4955
}
5056
}

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ fn main() {
348348
struct V([f64; 2]);
349349

350350
let f = V([0.0, 1.0]);
351-
let _a = f.0[0];
351+
let fp = (&raw const f) as *const [f64; 2];
352+
let _a = (unsafe { &*fp })[0];
352353

353354
stack_val_align();
354355
}

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ pub(crate) fn run_pass_manager(
654654
// We then run the llvm_optimize function a second time, to optimize the code which we generated
655655
// in the enzyme differentiation pass.
656656
let enable_ad = config.autodiff.contains(&config::AutoDiff::Enable);
657+
let enable_gpu = config.offload.contains(&config::Offload::Enable);
657658
let stage = if thin {
658659
write::AutodiffStage::PreAD
659660
} else {
@@ -668,6 +669,12 @@ pub(crate) fn run_pass_manager(
668669
write::llvm_optimize(cgcx, dcx, module, None, config, opt_level, opt_stage, stage)?;
669670
}
670671

672+
if enable_gpu && !thin {
673+
let cx =
674+
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);
675+
crate::builder::gpu_offload::handle_gpu_code(cgcx, &cx);
676+
}
677+
671678
if cfg!(llvm_enzyme) && enable_ad && !thin {
672679
let cx =
673680
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::ops::Deref;
33
use std::{iter, ptr};
44

55
pub(crate) mod autodiff;
6+
pub(crate) mod gpu_offload;
67

78
use libc::{c_char, c_uint, size_t};
89
use rustc_abi as abi;
@@ -117,6 +118,74 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
117118
}
118119
bx
119120
}
121+
122+
// The generic builder has less functionality and thus (unlike the other alloca) we can not
123+
// easily jump to the beginning of the function to place our allocas there. We trust the user
124+
// to manually do that. FIXME(offload): improve the genericCx and add more llvm wrappers to
125+
// handle this.
126+
pub(crate) fn direct_alloca(&mut self, ty: &'ll Type, align: Align, name: &str) -> &'ll Value {
127+
let val = unsafe {
128+
let alloca = llvm::LLVMBuildAlloca(self.llbuilder, ty, UNNAMED);
129+
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint);
130+
// Cast to default addrspace if necessary
131+
llvm::LLVMBuildPointerCast(self.llbuilder, alloca, self.cx.type_ptr(), UNNAMED)
132+
};
133+
if name != "" {
134+
let name = std::ffi::CString::new(name).unwrap();
135+
llvm::set_value_name(val, &name.as_bytes());
136+
}
137+
val
138+
}
139+
140+
pub(crate) fn inbounds_gep(
141+
&mut self,
142+
ty: &'ll Type,
143+
ptr: &'ll Value,
144+
indices: &[&'ll Value],
145+
) -> &'ll Value {
146+
unsafe {
147+
llvm::LLVMBuildGEPWithNoWrapFlags(
148+
self.llbuilder,
149+
ty,
150+
ptr,
151+
indices.as_ptr(),
152+
indices.len() as c_uint,
153+
UNNAMED,
154+
GEPNoWrapFlags::InBounds,
155+
)
156+
}
157+
}
158+
159+
pub(crate) fn store(&mut self, val: &'ll Value, ptr: &'ll Value, align: Align) -> &'ll Value {
160+
debug!("Store {:?} -> {:?}", val, ptr);
161+
assert_eq!(self.cx.type_kind(self.cx.val_ty(ptr)), TypeKind::Pointer);
162+
unsafe {
163+
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
164+
llvm::LLVMSetAlignment(store, align.bytes() as c_uint);
165+
store
166+
}
167+
}
168+
169+
pub(crate) fn load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value {
170+
unsafe {
171+
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);
172+
llvm::LLVMSetAlignment(load, align.bytes() as c_uint);
173+
load
174+
}
175+
}
176+
177+
fn memset(&mut self, ptr: &'ll Value, fill_byte: &'ll Value, size: &'ll Value, align: Align) {
178+
unsafe {
179+
llvm::LLVMRustBuildMemSet(
180+
self.llbuilder,
181+
ptr,
182+
align.bytes() as c_uint,
183+
fill_byte,
184+
size,
185+
false,
186+
);
187+
}
188+
}
120189
}
121190

122191
/// Empty string, to be used where LLVM expects an instruction name, indicating

0 commit comments

Comments
 (0)