Skip to content

Commit 8533456

Browse files
committed
Move mono_item_placement construction.
It's currently created in `place_inlined_mono_items` and then used in `internalize_symbols`. This commit moves the creation to `internalize_symbols`.
1 parent 1defd30 commit 8533456

File tree

1 file changed

+35
-45
lines changed

1 file changed

+35
-45
lines changed

compiler/rustc_monomorphize/src/partitioning.rs

+35-45
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ where
173173
// monomorphizations have to go into each codegen unit. These additional
174174
// monomorphizations can be drop-glue, functions from external crates, and
175175
// local functions the definition of which is marked with `#[inline]`.
176-
let mono_item_placements = {
176+
{
177177
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_inline_items");
178178
place_inlined_mono_items(cx, &mut codegen_units)
179179
};
@@ -188,12 +188,7 @@ where
188188
// more freedom to optimize.
189189
if !tcx.sess.link_dead_code() {
190190
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
191-
internalize_symbols(
192-
cx,
193-
&mut codegen_units,
194-
mono_item_placements,
195-
internalization_candidates,
196-
);
191+
internalize_symbols(cx, &mut codegen_units, internalization_candidates);
197192
}
198193

199194
let instrument_dead_code =
@@ -401,19 +396,10 @@ fn merge_codegen_units<'tcx>(
401396
codegen_units.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
402397
}
403398

404-
/// For symbol internalization, we need to know whether a symbol/mono-item is
405-
/// used from outside the codegen unit it is defined in. This type is used
406-
/// to keep track of that.
407-
#[derive(Clone, PartialEq, Eq, Debug)]
408-
enum MonoItemPlacement {
409-
SingleCgu { cgu_name: Symbol },
410-
MultipleCgus,
411-
}
412-
413399
fn place_inlined_mono_items<'tcx>(
414400
cx: &PartitioningCx<'_, 'tcx>,
415401
codegen_units: &mut [CodegenUnit<'tcx>],
416-
) -> FxHashMap<MonoItem<'tcx>, MonoItemPlacement> {
402+
) {
417403
for cgu in codegen_units.iter_mut() {
418404
// Collect all inlined items that need to be available in this codegen unit.
419405
let mut reachable_inlined_items = FxHashSet::default();
@@ -432,33 +418,6 @@ fn place_inlined_mono_items<'tcx>(
432418
}
433419
}
434420

435-
let mut mono_item_placements = FxHashMap::default();
436-
let single_codegen_unit = codegen_units.len() == 1;
437-
438-
for cgu in codegen_units.iter_mut() {
439-
for item in cgu.items().keys() {
440-
if !single_codegen_unit {
441-
// If there is more than one codegen unit, we need to keep track
442-
// in which codegen units each monomorphization is placed.
443-
match mono_item_placements.entry(*item) {
444-
Entry::Occupied(e) => {
445-
let placement = e.into_mut();
446-
debug_assert!(match *placement {
447-
MonoItemPlacement::SingleCgu { cgu_name } => cgu_name != cgu.name(),
448-
MonoItemPlacement::MultipleCgus => true,
449-
});
450-
*placement = MonoItemPlacement::MultipleCgus;
451-
}
452-
Entry::Vacant(e) => {
453-
e.insert(MonoItemPlacement::SingleCgu { cgu_name: cgu.name() });
454-
}
455-
}
456-
}
457-
}
458-
}
459-
460-
return mono_item_placements;
461-
462421
fn get_reachable_inlined_items<'tcx>(
463422
tcx: TyCtxt<'tcx>,
464423
item: MonoItem<'tcx>,
@@ -477,11 +436,42 @@ fn place_inlined_mono_items<'tcx>(
477436
fn internalize_symbols<'tcx>(
478437
cx: &PartitioningCx<'_, 'tcx>,
479438
codegen_units: &mut [CodegenUnit<'tcx>],
480-
mono_item_placements: FxHashMap<MonoItem<'tcx>, MonoItemPlacement>,
481439
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
482440
) {
441+
/// For symbol internalization, we need to know whether a symbol/mono-item
442+
/// is used from outside the codegen unit it is defined in. This type is
443+
/// used to keep track of that.
444+
#[derive(Clone, PartialEq, Eq, Debug)]
445+
enum MonoItemPlacement {
446+
SingleCgu { cgu_name: Symbol },
447+
MultipleCgus,
448+
}
449+
450+
let mut mono_item_placements = FxHashMap::default();
483451
let single_codegen_unit = codegen_units.len() == 1;
484452

453+
if !single_codegen_unit {
454+
for cgu in codegen_units.iter_mut() {
455+
for item in cgu.items().keys() {
456+
// If there is more than one codegen unit, we need to keep track
457+
// in which codegen units each monomorphization is placed.
458+
match mono_item_placements.entry(*item) {
459+
Entry::Occupied(e) => {
460+
let placement = e.into_mut();
461+
debug_assert!(match *placement {
462+
MonoItemPlacement::SingleCgu { cgu_name } => cgu_name != cgu.name(),
463+
MonoItemPlacement::MultipleCgus => true,
464+
});
465+
*placement = MonoItemPlacement::MultipleCgus;
466+
}
467+
Entry::Vacant(e) => {
468+
e.insert(MonoItemPlacement::SingleCgu { cgu_name: cgu.name() });
469+
}
470+
}
471+
}
472+
}
473+
}
474+
485475
// For each internalization candidates in each codegen unit, check if it is
486476
// used from outside its defining codegen unit.
487477
for cgu in codegen_units {

0 commit comments

Comments
 (0)