]> git.lizzy.rs Git - rust.git/commitdiff
TEST: Use SmallVec<[u32; 4]> for field projection.
authorHans Kratz <hans@appfour.com>
Mon, 9 Aug 2021 12:25:33 +0000 (12:25 +0000)
committerHans Kratz <hans@appfour.com>
Mon, 9 Aug 2021 12:25:33 +0000 (12:25 +0000)
compiler/rustc_codegen_llvm/src/context.rs
compiler/rustc_codegen_llvm/src/type_of.rs

index d28a579ff1059a130bb53b932d3848b445664837..225514ea863cb7cdb952dfbe2b6596cccb54db15 100644 (file)
@@ -24,6 +24,7 @@
 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 {
index 46e824d879fec93d28d6f7e4439fc9018b2c183a..225044c84885703101dd428e8ee37bb4344fdf45 100644 (file)
@@ -10,6 +10,7 @@
 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> {