about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorHans Kratz <hans@appfour.com>2021-08-09 12:25:33 +0000
committerHans Kratz <hans@appfour.com>2021-08-09 12:25:33 +0000
commitc1d0f0a65c36e73ebf7a1ac899b13fb82e3f6483 (patch)
treec236b47acdbcf8f57c18eb60cb23254bbe579161 /compiler
parentc627c0d88ba8bf73793d9fb9bf1f1452c497f26a (diff)
downloadrust-c1d0f0a65c36e73ebf7a1ac899b13fb82e3f6483.tar.gz
rust-c1d0f0a65c36e73ebf7a1ac899b13fb82e3f6483.zip
TEST: Use SmallVec<[u32; 4]> for field projection.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_codegen_llvm/src/context.rs3
-rw-r--r--compiler/rustc_codegen_llvm/src/type_of.rs9
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs
index d28a579ff10..225514ea863 100644
--- a/compiler/rustc_codegen_llvm/src/context.rs
+++ b/compiler/rustc_codegen_llvm/src/context.rs
@@ -24,6 +24,7 @@ use rustc_span::source_map::{Span, DUMMY_SP};
 use rustc_span::symbol::Symbol;
 use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx};
 use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
+use smallvec::SmallVec;
 
 use std::cell::{Cell, RefCell};
 use std::ffi::CStr;
@@ -102,7 +103,7 @@ pub struct TypeLowering<'ll> {
 
     /// If padding is used the slice maps fields from source order
     /// to llvm order.
-    pub field_remapping: Option<Box<[u32]>>,
+    pub field_remapping: Option<Box<SmallVec<[u32; 4]>>>,
 }
 
 fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode {
diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs
index 46e824d879f..225044c8488 100644
--- a/compiler/rustc_codegen_llvm/src/type_of.rs
+++ b/compiler/rustc_codegen_llvm/src/type_of.rs
@@ -10,6 +10,7 @@ use rustc_middle::ty::{self, Ty, TypeFoldable};
 use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape};
 use rustc_target::abi::{Int, Pointer, F32, F64};
 use rustc_target::abi::{LayoutOf, PointeeInfo, Scalar, Size, TyAndLayoutMethods, Variants};
+use smallvec::{smallvec, SmallVec};
 use tracing::debug;
 
 use std::fmt::Write;
@@ -18,7 +19,7 @@ fn uncached_llvm_type<'a, 'tcx>(
     cx: &CodegenCx<'a, 'tcx>,
     layout: TyAndLayout<'tcx>,
     defer: &mut Option<(&'a Type, TyAndLayout<'tcx>)>,
-    field_remapping: &mut Option<Box<[u32]>>,
+    field_remapping: &mut Option<Box<SmallVec<[u32; 4]>>>,
 ) -> &'a Type {
     match layout.abi {
         Abi::Scalar(_) => bug!("handled elsewhere"),
@@ -93,7 +94,7 @@ fn uncached_llvm_type<'a, 'tcx>(
 fn struct_llfields<'a, 'tcx>(
     cx: &CodegenCx<'a, 'tcx>,
     layout: TyAndLayout<'tcx>,
-) -> (Vec<&'a Type>, bool, Option<Box<[u32]>>) {
+) -> (Vec<&'a Type>, bool, Option<Box<SmallVec<[u32; 4]>>>) {
     debug!("struct_llfields: {:#?}", layout);
     let field_count = layout.fields.count();
 
@@ -101,7 +102,7 @@ fn struct_llfields<'a, 'tcx>(
     let mut offset = Size::ZERO;
     let mut prev_effective_align = layout.align.abi;
     let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
-    let mut field_remapping = vec![0; field_count];
+    let mut field_remapping = smallvec![0; field_count];
     for i in layout.fields.index_by_increasing_offset() {
         let target_offset = layout.fields.offset(i as usize);
         let field = layout.field(cx, i);
@@ -150,7 +151,7 @@ fn struct_llfields<'a, 'tcx>(
         debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size);
     }
 
-    (result, packed, padding_used.then_some(field_remapping.into_boxed_slice()))
+    (result, packed, padding_used.then_some(Box::new(field_remapping)))
 }
 
 impl<'a, 'tcx> CodegenCx<'a, 'tcx> {