Skip to content

Commit 06cc1e3

Browse files
committed
Auto merge of #151562 - jhpratt:rollup-dt81FeK, r=jhpratt
Rollup of 8 pull requests Successful merges: - #150556 (Add Tier 3 Thumb-mode targets for Armv7-A, Armv7-R and Armv8-R) - #151346 (add `simd_splat` intrinsic) - #151500 (hexagon: Add HVX target features) - #151505 (Various refactors to the proc_macro bridge) - #151517 (Enable reproducible binary builds with debuginfo on Linux) - #151482 (Add "Skip to main content" link for keyboard navigation in rustdoc) - #151489 (constify boolean methods) - #151551 (Don't use default build-script fingerprinting in `test`) r? @ghost
2 parents d222ddc + a32b322 commit 06cc1e3

53 files changed

Lines changed: 950 additions & 682 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_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,31 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
348348
ret.write_cvalue(fx, ret_lane);
349349
}
350350

351+
sym::simd_splat => {
352+
intrinsic_args!(fx, args => (value); intrinsic);
353+
354+
if !ret.layout().ty.is_simd() {
355+
report_simd_type_validation_error(fx, intrinsic, span, ret.layout().ty);
356+
return;
357+
}
358+
let (lane_count, lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
359+
360+
if value.layout().ty != lane_ty {
361+
fx.tcx.dcx().span_fatal(
362+
span,
363+
format!(
364+
"[simd_splat] expected element type {lane_ty:?}, got {got:?}",
365+
got = value.layout().ty
366+
),
367+
);
368+
}
369+
370+
for i in 0..lane_count {
371+
let ret_lane = ret.place_lane(fx, i.into());
372+
ret_lane.write_cvalue(fx, value);
373+
}
374+
}
375+
351376
sym::simd_neg
352377
| sym::simd_bswap
353378
| sym::simd_bitreverse

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,42 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
121121
return Ok(bx.vector_select(vector_mask, arg1, args[2].immediate()));
122122
}
123123

124+
#[cfg(feature = "master")]
125+
if name == sym::simd_splat {
126+
let (out_len, out_ty) = require_simd2!(ret_ty, SimdReturn);
127+
128+
require!(
129+
args[0].layout.ty == out_ty,
130+
InvalidMonomorphization::ExpectedVectorElementType {
131+
span,
132+
name,
133+
expected_element: out_ty,
134+
vector_type: ret_ty,
135+
}
136+
);
137+
138+
let vec_ty = llret_ty.unqualified().dyncast_vector().expect("vector return type");
139+
let elem_ty = vec_ty.get_element_type();
140+
141+
// Cast pointer type to usize (GCC does not support pointer SIMD vectors).
142+
let value = args[0];
143+
let scalar = if value.layout.ty.is_numeric() {
144+
value.immediate()
145+
} else if value.layout.ty.is_raw_ptr() {
146+
bx.ptrtoint(value.immediate(), elem_ty)
147+
} else {
148+
return_error!(InvalidMonomorphization::UnsupportedOperation {
149+
span,
150+
name,
151+
in_ty: ret_ty,
152+
in_elem: value.layout.ty
153+
});
154+
};
155+
156+
let elements = vec![scalar; out_len as usize];
157+
return Ok(bx.context.new_rvalue_from_vector(bx.location, llret_ty, &elements));
158+
}
159+
124160
// every intrinsic below takes a SIMD vector as its first argument
125161
require_simd!(
126162
args[0].layout.ty,

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,31 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15811581
return Ok(bx.select(m_i1s, args[1].immediate(), args[2].immediate()));
15821582
}
15831583

1584+
if name == sym::simd_splat {
1585+
let (_out_len, out_ty) = require_simd!(ret_ty, SimdReturn);
1586+
1587+
require!(
1588+
args[0].layout.ty == out_ty,
1589+
InvalidMonomorphization::ExpectedVectorElementType {
1590+
span,
1591+
name,
1592+
expected_element: out_ty,
1593+
vector_type: ret_ty,
1594+
}
1595+
);
1596+
1597+
// `insertelement <N x elem> poison, elem %x, i32 0`
1598+
let poison_vec = bx.const_poison(llret_ty);
1599+
let idx0 = bx.const_i32(0);
1600+
let v0 = bx.insert_element(poison_vec, args[0].immediate(), idx0);
1601+
1602+
// `shufflevector <N x elem> v0, <N x elem> poison, <N x i32> zeroinitializer`
1603+
// The masks is all zeros, so this splats lane 0 (which has our element in it).
1604+
let splat = bx.shuffle_vector(v0, poison_vec, bx.const_null(llret_ty));
1605+
1606+
return Ok(splat);
1607+
}
1608+
15841609
// every intrinsic below takes a SIMD vector as its first argument
15851610
let (in_len, in_elem) = require_simd!(args[0].layout.ty, SimdInput);
15861611
let in_ty = args[0].layout.ty;

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10741074
if constant_ty.is_simd() {
10751075
// However, some SIMD types do not actually use the vector ABI
10761076
// (in particular, packed SIMD types do not). Ensure we exclude those.
1077+
//
1078+
// We also have to exclude vectors of pointers because `immediate_const_vector`
1079+
// does not work for those.
10771080
let layout = bx.layout_of(constant_ty);
1078-
if let BackendRepr::SimdVector { .. } = layout.backend_repr {
1081+
let (_, element_ty) = constant_ty.simd_size_and_type(bx.tcx());
1082+
if let BackendRepr::SimdVector { .. } = layout.backend_repr
1083+
&& element_ty.is_numeric()
1084+
{
10791085
let (llval, ty) = self.immediate_const_vector(bx, constant);
10801086
return OperandRef {
10811087
val: OperandValue::Immediate(llval),

compiler/rustc_const_eval/src/interpret/intrinsics/simd.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
6161
}
6262
self.copy_op(&self.project_index(&input, index)?, &dest)?;
6363
}
64+
sym::simd_splat => {
65+
let elem = &args[0];
66+
let (dest, dest_len) = self.project_to_simd(&dest)?;
67+
68+
for i in 0..dest_len {
69+
let place = self.project_index(&dest, i)?;
70+
self.copy_op(elem, &place)?;
71+
}
72+
}
6473
sym::simd_neg
6574
| sym::simd_fabs
6675
| sym::simd_ceil

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ impl ToInternal<rustc_errors::Level> for Level {
431431
}
432432
}
433433

434-
pub(crate) struct FreeFunctions;
435-
436434
pub(crate) struct Rustc<'a, 'b> {
437435
ecx: &'a mut ExtCtxt<'b>,
438436
def_site: Span,
@@ -461,13 +459,28 @@ impl<'a, 'b> Rustc<'a, 'b> {
461459
}
462460

463461
impl server::Types for Rustc<'_, '_> {
464-
type FreeFunctions = FreeFunctions;
465462
type TokenStream = TokenStream;
466463
type Span = Span;
467464
type Symbol = Symbol;
468465
}
469466

470-
impl server::FreeFunctions for Rustc<'_, '_> {
467+
impl server::Server for Rustc<'_, '_> {
468+
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
469+
ExpnGlobals {
470+
def_site: self.def_site,
471+
call_site: self.call_site,
472+
mixed_site: self.mixed_site,
473+
}
474+
}
475+
476+
fn intern_symbol(string: &str) -> Self::Symbol {
477+
Symbol::intern(string)
478+
}
479+
480+
fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str)) {
481+
f(symbol.as_str())
482+
}
483+
471484
fn injected_env_var(&mut self, var: &str) -> Option<String> {
472485
self.ecx.sess.opts.logical_env.get(var).cloned()
473486
}
@@ -552,14 +565,20 @@ impl server::FreeFunctions for Rustc<'_, '_> {
552565
}
553566
diag.emit();
554567
}
555-
}
556568

557-
impl server::TokenStream for Rustc<'_, '_> {
558-
fn is_empty(&mut self, stream: &Self::TokenStream) -> bool {
569+
fn ts_drop(&mut self, stream: Self::TokenStream) {
570+
drop(stream);
571+
}
572+
573+
fn ts_clone(&mut self, stream: &Self::TokenStream) -> Self::TokenStream {
574+
stream.clone()
575+
}
576+
577+
fn ts_is_empty(&mut self, stream: &Self::TokenStream) -> bool {
559578
stream.is_empty()
560579
}
561580

562-
fn from_str(&mut self, src: &str) -> Self::TokenStream {
581+
fn ts_from_str(&mut self, src: &str) -> Self::TokenStream {
563582
unwrap_or_emit_fatal(source_str_to_stream(
564583
self.psess(),
565584
FileName::proc_macro_source_code(src),
@@ -568,11 +587,11 @@ impl server::TokenStream for Rustc<'_, '_> {
568587
))
569588
}
570589

571-
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
590+
fn ts_to_string(&mut self, stream: &Self::TokenStream) -> String {
572591
pprust::tts_to_string(stream)
573592
}
574593

575-
fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
594+
fn ts_expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
576595
// Parse the expression from our tokenstream.
577596
let expr: PResult<'_, _> = try {
578597
let mut p = Parser::new(self.psess(), stream.clone(), Some("proc_macro expand expr"));
@@ -633,14 +652,14 @@ impl server::TokenStream for Rustc<'_, '_> {
633652
}
634653
}
635654

636-
fn from_token_tree(
655+
fn ts_from_token_tree(
637656
&mut self,
638657
tree: TokenTree<Self::TokenStream, Self::Span, Self::Symbol>,
639658
) -> Self::TokenStream {
640659
Self::TokenStream::new((tree, &mut *self).to_internal().into_iter().collect::<Vec<_>>())
641660
}
642661

643-
fn concat_trees(
662+
fn ts_concat_trees(
644663
&mut self,
645664
base: Option<Self::TokenStream>,
646665
trees: Vec<TokenTree<Self::TokenStream, Self::Span, Self::Symbol>>,
@@ -654,7 +673,7 @@ impl server::TokenStream for Rustc<'_, '_> {
654673
stream
655674
}
656675

657-
fn concat_streams(
676+
fn ts_concat_streams(
658677
&mut self,
659678
base: Option<Self::TokenStream>,
660679
streams: Vec<Self::TokenStream>,
@@ -666,24 +685,22 @@ impl server::TokenStream for Rustc<'_, '_> {
666685
stream
667686
}
668687

669-
fn into_trees(
688+
fn ts_into_trees(
670689
&mut self,
671690
stream: Self::TokenStream,
672691
) -> Vec<TokenTree<Self::TokenStream, Self::Span, Self::Symbol>> {
673692
FromInternal::from_internal((stream, self))
674693
}
675-
}
676694

677-
impl server::Span for Rustc<'_, '_> {
678-
fn debug(&mut self, span: Self::Span) -> String {
695+
fn span_debug(&mut self, span: Self::Span) -> String {
679696
if self.ecx.ecfg.span_debug {
680697
format!("{span:?}")
681698
} else {
682699
format!("{:?} bytes({}..{})", span.ctxt(), span.lo().0, span.hi().0)
683700
}
684701
}
685702

686-
fn file(&mut self, span: Self::Span) -> String {
703+
fn span_file(&mut self, span: Self::Span) -> String {
687704
self.psess()
688705
.source_map()
689706
.lookup_char_pos(span.lo())
@@ -693,7 +710,7 @@ impl server::Span for Rustc<'_, '_> {
693710
.to_string()
694711
}
695712

696-
fn local_file(&mut self, span: Self::Span) -> Option<String> {
713+
fn span_local_file(&mut self, span: Self::Span) -> Option<String> {
697714
self.psess()
698715
.source_map()
699716
.lookup_char_pos(span.lo())
@@ -708,41 +725,41 @@ impl server::Span for Rustc<'_, '_> {
708725
})
709726
}
710727

711-
fn parent(&mut self, span: Self::Span) -> Option<Self::Span> {
728+
fn span_parent(&mut self, span: Self::Span) -> Option<Self::Span> {
712729
span.parent_callsite()
713730
}
714731

715-
fn source(&mut self, span: Self::Span) -> Self::Span {
732+
fn span_source(&mut self, span: Self::Span) -> Self::Span {
716733
span.source_callsite()
717734
}
718735

719-
fn byte_range(&mut self, span: Self::Span) -> Range<usize> {
736+
fn span_byte_range(&mut self, span: Self::Span) -> Range<usize> {
720737
let source_map = self.psess().source_map();
721738

722739
let relative_start_pos = source_map.lookup_byte_offset(span.lo()).pos;
723740
let relative_end_pos = source_map.lookup_byte_offset(span.hi()).pos;
724741

725742
Range { start: relative_start_pos.0 as usize, end: relative_end_pos.0 as usize }
726743
}
727-
fn start(&mut self, span: Self::Span) -> Self::Span {
744+
fn span_start(&mut self, span: Self::Span) -> Self::Span {
728745
span.shrink_to_lo()
729746
}
730747

731-
fn end(&mut self, span: Self::Span) -> Self::Span {
748+
fn span_end(&mut self, span: Self::Span) -> Self::Span {
732749
span.shrink_to_hi()
733750
}
734751

735-
fn line(&mut self, span: Self::Span) -> usize {
752+
fn span_line(&mut self, span: Self::Span) -> usize {
736753
let loc = self.psess().source_map().lookup_char_pos(span.lo());
737754
loc.line
738755
}
739756

740-
fn column(&mut self, span: Self::Span) -> usize {
757+
fn span_column(&mut self, span: Self::Span) -> usize {
741758
let loc = self.psess().source_map().lookup_char_pos(span.lo());
742759
loc.col.to_usize() + 1
743760
}
744761

745-
fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
762+
fn span_join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
746763
let self_loc = self.psess().source_map().lookup_char_pos(first.lo());
747764
let other_loc = self.psess().source_map().lookup_char_pos(second.lo());
748765

@@ -753,7 +770,7 @@ impl server::Span for Rustc<'_, '_> {
753770
Some(first.to(second))
754771
}
755772

756-
fn subspan(
773+
fn span_subspan(
757774
&mut self,
758775
span: Self::Span,
759776
start: Bound<usize>,
@@ -789,11 +806,11 @@ impl server::Span for Rustc<'_, '_> {
789806
Some(span.with_lo(new_lo).with_hi(new_hi))
790807
}
791808

792-
fn resolved_at(&mut self, span: Self::Span, at: Self::Span) -> Self::Span {
809+
fn span_resolved_at(&mut self, span: Self::Span, at: Self::Span) -> Self::Span {
793810
span.with_ctxt(at.ctxt())
794811
}
795812

796-
fn source_text(&mut self, span: Self::Span) -> Option<String> {
813+
fn span_source_text(&mut self, span: Self::Span) -> Option<String> {
797814
self.psess().source_map().span_to_snippet(span).ok()
798815
}
799816

@@ -821,41 +838,21 @@ impl server::Span for Rustc<'_, '_> {
821838
/// span from the metadata of `my_proc_macro` (which we have access to,
822839
/// since we've loaded `my_proc_macro` from disk in order to execute it).
823840
/// In this way, we have obtained a span pointing into `my_proc_macro`
824-
fn save_span(&mut self, span: Self::Span) -> usize {
841+
fn span_save_span(&mut self, span: Self::Span) -> usize {
825842
self.psess().save_proc_macro_span(span)
826843
}
827844

828-
fn recover_proc_macro_span(&mut self, id: usize) -> Self::Span {
845+
fn span_recover_proc_macro_span(&mut self, id: usize) -> Self::Span {
829846
let (resolver, krate, def_site) = (&*self.ecx.resolver, self.krate, self.def_site);
830847
*self.rebased_spans.entry(id).or_insert_with(|| {
831848
// FIXME: `SyntaxContext` for spans from proc macro crates is lost during encoding,
832849
// replace it with a def-site context until we are encoding it properly.
833850
resolver.get_proc_macro_quoted_span(krate, id).with_ctxt(def_site.ctxt())
834851
})
835852
}
836-
}
837853

838-
impl server::Symbol for Rustc<'_, '_> {
839-
fn normalize_and_validate_ident(&mut self, string: &str) -> Result<Self::Symbol, ()> {
854+
fn symbol_normalize_and_validate_ident(&mut self, string: &str) -> Result<Self::Symbol, ()> {
840855
let sym = nfc_normalize(string);
841856
if rustc_lexer::is_ident(sym.as_str()) { Ok(sym) } else { Err(()) }
842857
}
843858
}
844-
845-
impl server::Server for Rustc<'_, '_> {
846-
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
847-
ExpnGlobals {
848-
def_site: self.def_site,
849-
call_site: self.call_site,
850-
mixed_site: self.mixed_site,
851-
}
852-
}
853-
854-
fn intern_symbol(string: &str) -> Self::Symbol {
855-
Symbol::intern(string)
856-
}
857-
858-
fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str)) {
859-
f(symbol.as_str())
860-
}
861-
}

0 commit comments

Comments
 (0)