Skip to content

Commit 77b053a

Browse files
committed
Add MonoItemData::inlined.
1 parent 299179e commit 77b053a

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

compiler/rustc_middle/src/mir/mono.rs

+6
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,14 @@ pub struct CodegenUnit<'tcx> {
248248
/// Auxiliary info about a `MonoItem`.
249249
#[derive(Copy, Clone, PartialEq, Debug, HashStable)]
250250
pub struct MonoItemData {
251+
/// A cached copy of the result of `MonoItem::instantiation_mode`, where
252+
/// `GloballyShared` maps to `false` and `LocalCopy` maps to `true`.
253+
pub inlined: bool,
254+
251255
pub linkage: Linkage,
252256
pub visibility: Visibility,
257+
258+
/// A cached copy of the result of `MonoItem::size_estimate`.
253259
pub size_estimate: usize,
254260
}
255261

compiler/rustc_monomorphize/src/partitioning.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ where
248248
}
249249
let size_estimate = mono_item.size_estimate(cx.tcx);
250250

251-
cgu.items_mut().insert(mono_item, MonoItemData { linkage, visibility, size_estimate });
251+
cgu.items_mut()
252+
.insert(mono_item, MonoItemData { inlined: false, linkage, visibility, size_estimate });
252253

253254
// Get all inlined items that are reachable from `mono_item` without
254255
// going via another root item. This includes drop-glue, functions from
@@ -263,6 +264,7 @@ where
263264
for inlined_item in reachable_inlined_items {
264265
// This is a CGU-private copy.
265266
cgu.items_mut().entry(inlined_item).or_insert_with(|| MonoItemData {
267+
inlined: true,
266268
linkage: Linkage::Internal,
267269
visibility: Visibility::Default,
268270
size_estimate: inlined_item.size_estimate(cx.tcx),
@@ -870,19 +872,16 @@ fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<
870872
all_cgu_sizes.push(cgu.size_estimate());
871873

872874
for (item, data) in cgu.items() {
873-
match item.instantiation_mode(tcx) {
874-
InstantiationMode::GloballyShared { .. } => {
875-
root_items += 1;
876-
root_size += data.size_estimate;
877-
}
878-
InstantiationMode::LocalCopy => {
879-
if inlined_items.insert(item) {
880-
unique_inlined_items += 1;
881-
unique_inlined_size += data.size_estimate;
882-
}
883-
placed_inlined_items += 1;
884-
placed_inlined_size += data.size_estimate;
875+
if !data.inlined {
876+
root_items += 1;
877+
root_size += data.size_estimate;
878+
} else {
879+
if inlined_items.insert(item) {
880+
unique_inlined_items += 1;
881+
unique_inlined_size += data.size_estimate;
885882
}
883+
placed_inlined_items += 1;
884+
placed_inlined_size += data.size_estimate;
886885
}
887886
}
888887
}
@@ -937,10 +936,7 @@ fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<
937936
let symbol_name = item.symbol_name(tcx).name;
938937
let symbol_hash_start = symbol_name.rfind('h');
939938
let symbol_hash = symbol_hash_start.map_or("<no hash>", |i| &symbol_name[i..]);
940-
let kind = match item.instantiation_mode(tcx) {
941-
InstantiationMode::GloballyShared { .. } => "root",
942-
InstantiationMode::LocalCopy => "inlined",
943-
};
939+
let kind = if !data.inlined { "root" } else { "inlined" };
944940
let size = data.size_estimate;
945941
let _ = with_no_trimmed_paths!(writeln!(
946942
s,

0 commit comments

Comments
 (0)