Skip to content

Commit 9d69d99

Browse files
committed
Auto merge of #154714 - JonathanBrouwer:rollup-wVuxeJK, r=<try>
Rollup of 8 pull requests try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1
2 parents e6b64a2 + bac466e commit 9d69d99

121 files changed

Lines changed: 1964 additions & 670 deletions

File tree

Some content is hidden

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

compiler/rustc_abi/src/layout.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use tracing::{debug, trace};
1010

1111
use crate::{
1212
AbiAlign, Align, BackendRepr, FieldsShape, HasDataLayout, IndexSlice, IndexVec, Integer,
13-
LayoutData, Niche, NonZeroUsize, Primitive, ReprOptions, Scalar, Size, StructKind, TagEncoding,
14-
TargetDataLayout, Variants, WrappingRange,
13+
LayoutData, Niche, NonZeroUsize, NumScalableVectors, Primitive, ReprOptions, Scalar, Size,
14+
StructKind, TagEncoding, TargetDataLayout, Variants, WrappingRange,
1515
};
1616

1717
mod coroutine;
@@ -204,13 +204,19 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
204204
&self,
205205
element: F,
206206
count: u64,
207+
number_of_vectors: NumScalableVectors,
207208
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F>
208209
where
209210
FieldIdx: Idx,
210211
VariantIdx: Idx,
211212
F: AsRef<LayoutData<FieldIdx, VariantIdx>> + fmt::Debug,
212213
{
213-
vector_type_layout(SimdVectorKind::Scalable, self.cx.data_layout(), element, count)
214+
vector_type_layout(
215+
SimdVectorKind::Scalable(number_of_vectors),
216+
self.cx.data_layout(),
217+
element,
218+
count,
219+
)
214220
}
215221

216222
pub fn simd_type<FieldIdx, VariantIdx, F>(
@@ -1526,7 +1532,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
15261532

15271533
enum SimdVectorKind {
15281534
/// `#[rustc_scalable_vector]`
1529-
Scalable,
1535+
Scalable(NumScalableVectors),
15301536
/// `#[repr(simd, packed)]`
15311537
PackedFixed,
15321538
/// `#[repr(simd)]`
@@ -1559,9 +1565,10 @@ where
15591565
let size =
15601566
elt.size.checked_mul(count, dl).ok_or_else(|| LayoutCalculatorError::SizeOverflow)?;
15611567
let (repr, align) = match kind {
1562-
SimdVectorKind::Scalable => {
1563-
(BackendRepr::SimdScalableVector { element, count }, dl.llvmlike_vector_align(size))
1564-
}
1568+
SimdVectorKind::Scalable(number_of_vectors) => (
1569+
BackendRepr::SimdScalableVector { element, count, number_of_vectors },
1570+
dl.llvmlike_vector_align(size),
1571+
),
15651572
// Non-power-of-two vectors have padding up to the next power-of-two.
15661573
// If we're a packed repr, remove the padding while keeping the alignment as close
15671574
// to a vector as possible.

compiler/rustc_abi/src/lib.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,28 @@ impl AddressSpace {
17021702
pub const ZERO: Self = AddressSpace(0);
17031703
}
17041704

1705+
/// How many scalable vectors are in a `BackendRepr::ScalableVector`?
1706+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1707+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1708+
pub struct NumScalableVectors(pub u8);
1709+
1710+
impl NumScalableVectors {
1711+
/// Returns a `NumScalableVector` for a non-tuple scalable vector (e.g. a single vector).
1712+
pub fn for_non_tuple() -> Self {
1713+
NumScalableVectors(1)
1714+
}
1715+
1716+
// Returns `NumScalableVectors` for values of two through eight, which are a valid number of
1717+
// fields for a tuple of scalable vectors to have. `1` is a valid value of `NumScalableVectors`
1718+
// but not for a tuple which would have a field count.
1719+
pub fn from_field_count(count: usize) -> Option<Self> {
1720+
match count {
1721+
2..8 => Some(NumScalableVectors(count as u8)),
1722+
_ => None,
1723+
}
1724+
}
1725+
}
1726+
17051727
/// The way we represent values to the backend
17061728
///
17071729
/// Previously this was conflated with the "ABI" a type is given, as in the platform-specific ABI.
@@ -1720,6 +1742,7 @@ pub enum BackendRepr {
17201742
SimdScalableVector {
17211743
element: Scalar,
17221744
count: u64,
1745+
number_of_vectors: NumScalableVectors,
17231746
},
17241747
SimdVector {
17251748
element: Scalar,
@@ -1826,8 +1849,12 @@ impl BackendRepr {
18261849
BackendRepr::SimdVector { element: element.to_union(), count }
18271850
}
18281851
BackendRepr::Memory { .. } => BackendRepr::Memory { sized: true },
1829-
BackendRepr::SimdScalableVector { element, count } => {
1830-
BackendRepr::SimdScalableVector { element: element.to_union(), count }
1852+
BackendRepr::SimdScalableVector { element, count, number_of_vectors } => {
1853+
BackendRepr::SimdScalableVector {
1854+
element: element.to_union(),
1855+
count,
1856+
number_of_vectors,
1857+
}
18311858
}
18321859
}
18331860
}
@@ -2167,7 +2194,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
21672194
}
21682195

21692196
/// Returns `true` if the size of the type is only known at runtime.
2170-
pub fn is_runtime_sized(&self) -> bool {
2197+
pub fn is_scalable_vector(&self) -> bool {
21712198
matches!(self.backend_repr, BackendRepr::SimdScalableVector { .. })
21722199
}
21732200

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
26832683
overly_complex_const(self)
26842684
}
26852685
ExprKind::Lit(literal) => {
2686-
let span = expr.span;
2686+
let span = self.lower_span(expr.span);
26872687
let literal = self.lower_lit(literal, span);
26882688

26892689
ConstArg {
@@ -2695,7 +2695,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
26952695
ExprKind::Unary(UnOp::Neg, inner_expr)
26962696
if let ExprKind::Lit(literal) = &inner_expr.kind =>
26972697
{
2698-
let span = expr.span;
2698+
let span = self.lower_span(expr.span);
26992699
let literal = self.lower_lit(literal, span);
27002700

27012701
if !matches!(literal.node, LitKind::Int(..)) {

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use rustc_data_structures::fx::FxHashSet;
2424
use rustc_middle::bug;
2525
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2626
use rustc_middle::ty::layout::{
27-
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers,
27+
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError,
28+
LayoutOfHelpers, TyAndLayout,
2829
};
2930
use rustc_middle::ty::{self, AtomicOrdering, Instance, Ty, TyCtxt};
3031
use rustc_span::Span;
@@ -943,8 +944,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
943944
.get_address(self.location)
944945
}
945946

946-
fn scalable_alloca(&mut self, _elt: u64, _align: Align, _element_ty: Ty<'_>) -> RValue<'gcc> {
947-
todo!()
947+
fn alloca_with_ty(&mut self, ty: TyAndLayout<'tcx>) -> RValue<'gcc> {
948+
self.alloca(ty.layout.size, ty.layout.align.abi)
948949
}
949950

950951
fn load(&mut self, pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {

compiler/rustc_codegen_gcc/src/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
145145
self.const_int(self.type_i32(), i as i64)
146146
}
147147

148+
fn const_i64(&self, i: i64) -> RValue<'gcc> {
149+
self.const_int(self.type_i64(), i)
150+
}
151+
148152
fn const_int(&self, typ: Type<'gcc>, int: i64) -> RValue<'gcc> {
149153
self.gcc_int(typ, int)
150154
}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ pub(crate) mod autodiff;
77
pub(crate) mod gpu_offload;
88

99
use libc::{c_char, c_uint};
10-
use rustc_abi as abi;
11-
use rustc_abi::{Align, Size, WrappingRange};
10+
use rustc_abi::{self as abi, Align, Size, WrappingRange};
1211
use rustc_codegen_ssa::MemFlags;
1312
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, SynchronizationScope, TypeKind};
1413
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
@@ -616,21 +615,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
616615
}
617616
}
618617

619-
fn scalable_alloca(&mut self, elt: u64, align: Align, element_ty: Ty<'_>) -> Self::Value {
618+
fn alloca_with_ty(&mut self, layout: TyAndLayout<'tcx>) -> Self::Value {
620619
let mut bx = Builder::with_cx(self.cx);
621620
bx.position_at_start(unsafe { llvm::LLVMGetFirstBasicBlock(self.llfn()) });
622-
let llvm_ty = match element_ty.kind() {
623-
ty::Bool => bx.type_i1(),
624-
ty::Int(int_ty) => self.cx.type_int_from_ty(*int_ty),
625-
ty::Uint(uint_ty) => self.cx.type_uint_from_ty(*uint_ty),
626-
ty::Float(float_ty) => self.cx.type_float_from_ty(*float_ty),
627-
_ => unreachable!("scalable vectors can only contain a bool, int, uint or float"),
628-
};
621+
let scalable_vector_ty = layout.llvm_type(self.cx);
629622

630623
unsafe {
631-
let ty = llvm::LLVMScalableVectorType(llvm_ty, elt.try_into().unwrap());
632-
let alloca = llvm::LLVMBuildAlloca(&bx.llbuilder, ty, UNNAMED);
633-
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint);
624+
let alloca = llvm::LLVMBuildAlloca(&bx.llbuilder, scalable_vector_ty, UNNAMED);
625+
llvm::LLVMSetAlignment(alloca, layout.align.abi.bytes() as c_uint);
634626
alloca
635627
}
636628
}

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
159159
self.const_int(self.type_i32(), i as i64)
160160
}
161161

162+
fn const_i64(&self, i: i64) -> &'ll Value {
163+
self.const_int(self.type_i64(), i as i64)
164+
}
165+
162166
fn const_int(&self, t: &'ll Type, i: i64) -> &'ll Value {
163167
debug_assert!(
164168
self.type_kind(t) == TypeKind::Integer,

compiler/rustc_codegen_llvm/src/debuginfo/dwarf_const.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ declare_constant!(DW_OP_plus_uconst: u64);
3535
/// Double-checked by a static assertion in `RustWrapper.cpp`.
3636
#[allow(non_upper_case_globals)]
3737
pub(crate) const DW_OP_LLVM_fragment: u64 = 0x1000;
38+
#[allow(non_upper_case_globals)]
39+
pub(crate) const DW_OP_constu: u64 = 0x10;
40+
#[allow(non_upper_case_globals)]
41+
pub(crate) const DW_OP_minus: u64 = 0x1c;
42+
#[allow(non_upper_case_globals)]
43+
pub(crate) const DW_OP_mul: u64 = 0x1e;
44+
#[allow(non_upper_case_globals)]
45+
pub(crate) const DW_OP_bregx: u64 = 0x92;
3846
// It describes the actual value of a source variable which might not exist in registers or in memory.
3947
#[allow(non_upper_case_globals)]
4048
pub(crate) const DW_OP_stack_value: u64 = 0x9f;

0 commit comments

Comments
 (0)