1
Fork 0

Set mir-opt-level = 0 on some codegen tests

Since we're changing a bunch of stuff, necessary to remove some codegen tests
which look for specific things. Also attempting to restart a test which timed out, maybe due to
fastly failing?
This commit is contained in:
kadmin 2021-06-07 08:37:41 +00:00
parent f7cbf2eb41
commit 3e97cef7e5
3 changed files with 36 additions and 30 deletions

View file

@ -4,7 +4,8 @@ use rustc_middle::mir::*;
use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::{self, Const, Ty, TyCtxt}; use rustc_middle::ty::{self, Const, Ty, TyCtxt};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_target::abi::{Size, TagEncoding, Variants}; use rustc_target::abi::{HasDataLayout, Size, TagEncoding, Variants};
use std::array::IntoIter;
/// A pass that seeks to optimize unnecessary moves of large enum types, if there is a large /// A pass that seeks to optimize unnecessary moves of large enum types, if there is a large
/// enough discrepanc between them /// enough discrepanc between them
@ -21,11 +22,10 @@ impl<const D: u64> EnumSizeOpt<D> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>, ty: Ty<'tcx>,
body_did: DefId, body_did: DefId,
) -> Option<(Size, u64, Vec<Size>)> { ) -> Option<(u64, Vec<Size>)> {
match ty.kind() { match ty.kind() {
ty::Adt(adt_def, _substs) if adt_def.is_enum() => { ty::Adt(adt_def, _substs) if adt_def.is_enum() => {
let p_e = tcx.param_env(body_did); let p_e = tcx.param_env(body_did);
// FIXME(jknodt) handle error better below
let layout = let layout =
if let Ok(layout) = tcx.layout_of(p_e.and(ty)) { layout } else { return None }; if let Ok(layout) = tcx.layout_of(p_e.and(ty)) { layout } else { return None };
let variants = &layout.variants; let variants = &layout.variants;
@ -50,7 +50,7 @@ impl<const D: u64> EnumSizeOpt<D> {
assert_eq!(discr_sizes[disc_idx], Size::ZERO); assert_eq!(discr_sizes[disc_idx], Size::ZERO);
discr_sizes[disc_idx] = layout.size; discr_sizes[disc_idx] = layout.size;
} }
Some((layout.size, variants.len() as u64, discr_sizes)) Some((variants.len() as u64, discr_sizes))
} }
} }
} }
@ -73,29 +73,45 @@ impl<const D: u64> EnumSizeOpt<D> {
let source_info = st.source_info; let source_info = st.source_info;
let span = source_info.span; let span = source_info.span;
let (total_size, num_variants, sizes) = let (num_variants, sizes) =
if let Some(cand) = Self::candidate(tcx, ty, body_did) { if let Some(cand) = Self::candidate(tcx, ty, body_did) {
cand cand
} else { } else {
return None; return None;
}; };
let adt_def = ty.ty_adt_def().unwrap(); let adt_def = ty.ty_adt_def().unwrap();
let alloc = if let Some(alloc) = alloc_cache.get(ty) { let alloc = if let Some(alloc) = alloc_cache.get(ty) {
alloc alloc
} else { } else {
let mut data = let data_layout = tcx.data_layout();
vec![0; std::mem::size_of::<usize>() * num_variants as usize]; let ptr_sized_int = data_layout.ptr_sized_integer();
let target_bytes = ptr_sized_int.size().bytes() as usize;
let mut data = vec![0; target_bytes * num_variants as usize];
let mut curr = 0; let mut curr = 0;
for byte in sizes macro_rules! encode_store {
.iter() ($endian: expr, $bytes: expr) => {
.flat_map(|sz| sz.bytes().to_ne_bytes()) let bytes = match $endian {
.take(data.len()) rustc_target::abi::Endian::Little => $bytes.to_le_bytes(),
{ rustc_target::abi::Endian::Big => $bytes.to_be_bytes(),
data[curr] = byte; };
for b in bytes {
data[curr] = b;
curr += 1; curr += 1;
} }
};
}
for sz in sizes {
match ptr_sized_int {
rustc_target::abi::Integer::I32 => {
encode_store!(data_layout.endian, sz.bytes() as u32);
}
rustc_target::abi::Integer::I64 => {
encode_store!(data_layout.endian, sz.bytes());
}
_ => unreachable!(),
};
}
let alloc = interpret::Allocation::from_bytes( let alloc = interpret::Allocation::from_bytes(
data, data,
tcx.data_layout.ptr_sized_integer().align(&tcx.data_layout).abi, tcx.data_layout.ptr_sized_integer().align(&tcx.data_layout).abi,
@ -162,7 +178,6 @@ impl<const D: u64> EnumSizeOpt<D> {
)), )),
}; };
// FIXME(jknodt) do I need to add a storage live here for this place?
let size_place = let size_place =
Place::from(local_decls.push(LocalDecl::new(tcx.types.usize, span))); Place::from(local_decls.push(LocalDecl::new(tcx.types.usize, span)));
@ -230,16 +245,7 @@ impl<const D: u64> EnumSizeOpt<D> {
kind: StatementKind::CopyNonOverlapping(box CopyNonOverlapping { kind: StatementKind::CopyNonOverlapping(box CopyNonOverlapping {
src: Operand::Copy(src_cast_place), src: Operand::Copy(src_cast_place),
dst: Operand::Copy(dst_cast_place), dst: Operand::Copy(dst_cast_place),
count: Operand::Constant( count: Operand::Copy(size_place),
box (Constant {
span,
user_ty: None,
literal: ConstantKind::Val(
interpret::ConstValue::from_u64(total_size.bytes()),
tcx.types.usize,
),
}),
),
}), }),
}; };
@ -247,7 +253,7 @@ impl<const D: u64> EnumSizeOpt<D> {
source_info, source_info,
kind: StatementKind::StorageDead(size_array_local), kind: StatementKind::StorageDead(size_array_local),
}; };
let iter = std::array::IntoIter::new([ let iter = IntoIter::new([
store_live, store_live,
const_assign, const_assign,
store_discr, store_discr,

View file

@ -1,4 +1,4 @@
// compile-flags: -C no-prepopulate-passes // compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
// min-llvm-version: 14.0 // min-llvm-version: 14.0
#![crate_type = "lib"] #![crate_type = "lib"]

View file

@ -1,4 +1,4 @@
// compile-flags: -O -C no-prepopulate-passes // compile-flags: -O -C no-prepopulate-passes -Zmir-opt-level=0
#![crate_type = "lib"] #![crate_type = "lib"]