Skip to content

Commit 7ac8751

Browse files
committed
do not count non-codegen statement as estimzed cgu element
1 parent 4596f4f commit 7ac8751

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4848
.codegen_set_discr(&mut bx, variant_index);
4949
bx
5050
}
51-
mir::StatementKind::Deinit(..) => {
52-
// For now, don't codegen this to anything. In the future it may be worth
53-
// experimenting with what kind of information we can emit to LLVM without hurting
54-
// perf here
55-
bx
56-
}
5751
mir::StatementKind::StorageLive(local) => {
5852
if let LocalRef::Place(cg_place) = self.locals[local] {
5953
cg_place.storage_live(&mut bx);
@@ -97,6 +91,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9791
bx.memcpy(dst, align, src, align, bytes, crate::MemFlags::empty());
9892
bx
9993
}
94+
mir::StatementKind::Deinit(..) => {
95+
// For now, don't codegen this to anything. In the future it may be worth
96+
// experimenting with what kind of information we can emit to LLVM without hurting
97+
// perf here
98+
bx
99+
}
100100
mir::StatementKind::FakeRead(..)
101101
| mir::StatementKind::Retag { .. }
102102
| mir::StatementKind::AscribeUserType(..)

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_data_structures::fx::FxIndexSet;
22
use rustc_hir as hir;
33
use rustc_hir::def_id::DefId;
4+
use rustc_middle::mir::StatementKind;
45
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
56
use rustc_trait_selection::traits;
67

@@ -355,7 +356,25 @@ fn instance_def_size_estimate<'tcx>(
355356
match instance_def {
356357
InstanceDef::Item(..) | InstanceDef::DropGlue(..) => {
357358
let mir = tcx.instance_mir(instance_def);
358-
mir.basic_blocks.iter().map(|bb| bb.statements.len() + 1).sum()
359+
mir.basic_blocks
360+
.iter()
361+
.map(|bb| {
362+
bb.statements
363+
.iter()
364+
.filter(|s| {
365+
// do not count non-codegen statement
366+
!matches!(
367+
s.kind,
368+
StatementKind::Deinit(..)
369+
| StatementKind::FakeRead(..)
370+
| StatementKind::Retag { .. }
371+
| StatementKind::AscribeUserType(..)
372+
| StatementKind::Nop
373+
)
374+
})
375+
.count()
376+
})
377+
.sum()
359378
}
360379
// Estimate the size of other compiler-generated shims to be 1.
361380
_ => 1,

0 commit comments

Comments
 (0)