Remove -Zcgu-partitioning-strategy
.
This option was introduced three years ago, but it's never been meaningfully used, and `default` is the only acceptable value. Also, I think the `Partition` trait presents an interface that is too closely tied to the existing strategy and would probably be wrong for other strategies. (My rule of thumb is to not make something generic until there are at least two instances of it, to avoid this kind of problem.) Also, I don't think providing multiple partitioning strategies to the user is a good idea, because the compiler already has enough obscure knobs. This commit removes the option, along with the `Partition` trait, and the `Partitioner` and `DefaultPartitioning` types. I left the existing code in `compiler/rustc_monomorphize/src/partitioning/default.rs`, though I could be persuaded that moving it into `compiler/rustc_monomorphize/src/partitioning/mod.rs` is better.
This commit is contained in:
parent
1c53407e8c
commit
97d4a38de9
3 changed files with 279 additions and 399 deletions
|
@ -15,19 +15,17 @@ use rustc_span::symbol::Symbol;
|
|||
|
||||
use super::PartitioningCx;
|
||||
use crate::collector::InliningMap;
|
||||
use crate::partitioning::{MonoItemPlacement, Partition, PlacedRootMonoItems};
|
||||
use crate::partitioning::{MonoItemPlacement, PlacedRootMonoItems};
|
||||
|
||||
pub struct DefaultPartitioning;
|
||||
// This modules implements the default (and only) partitioning strategy.
|
||||
|
||||
impl<'tcx> Partition<'tcx> for DefaultPartitioning {
|
||||
fn place_root_mono_items<I>(
|
||||
&mut self,
|
||||
pub(super) fn place_root_mono_items<'tcx, I>(
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
mono_items: &mut I,
|
||||
) -> PlacedRootMonoItems<'tcx>
|
||||
where
|
||||
) -> PlacedRootMonoItems<'tcx>
|
||||
where
|
||||
I: Iterator<Item = MonoItem<'tcx>>,
|
||||
{
|
||||
{
|
||||
let mut roots = FxHashSet::default();
|
||||
let mut codegen_units = FxHashMap::default();
|
||||
let is_incremental_build = cx.tcx.sess.opts.incremental.is_some();
|
||||
|
@ -91,13 +89,12 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning {
|
|||
|
||||
let codegen_units = codegen_units.into_values().collect();
|
||||
PlacedRootMonoItems { codegen_units, roots, internalization_candidates }
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_codegen_units(
|
||||
&mut self,
|
||||
pub(super) fn merge_codegen_units<'tcx>(
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
codegen_units: &mut Vec<CodegenUnit<'tcx>>,
|
||||
) {
|
||||
) {
|
||||
assert!(cx.target_cgu_count >= 1);
|
||||
|
||||
// Note that at this point in time the `codegen_units` here may not be
|
||||
|
@ -156,8 +153,7 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning {
|
|||
// were actually modified by merging.
|
||||
.filter(|(_, cgu_contents)| cgu_contents.len() > 1)
|
||||
.map(|(current_cgu_name, cgu_contents)| {
|
||||
let mut cgu_contents: Vec<&str> =
|
||||
cgu_contents.iter().map(|s| s.as_str()).collect();
|
||||
let mut cgu_contents: Vec<&str> = cgu_contents.iter().map(|s| s.as_str()).collect();
|
||||
|
||||
// Sort the names, so things are deterministic and easy to
|
||||
// predict. We are sorting primitive `&str`s here so we can
|
||||
|
@ -190,14 +186,13 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning {
|
|||
cgu.set_name(numbered_codegen_unit_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn place_inlined_mono_items(
|
||||
&mut self,
|
||||
pub(super) fn place_inlined_mono_items<'tcx>(
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
codegen_units: &mut [CodegenUnit<'tcx>],
|
||||
roots: FxHashSet<MonoItem<'tcx>>,
|
||||
) -> FxHashMap<MonoItem<'tcx>, MonoItemPlacement> {
|
||||
) -> FxHashMap<MonoItem<'tcx>, MonoItemPlacement> {
|
||||
let mut mono_item_placements = FxHashMap::default();
|
||||
|
||||
let single_codegen_unit = codegen_units.len() == 1;
|
||||
|
@ -272,15 +267,14 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning {
|
|||
follow_inlining(target, inlining_map, visited);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn internalize_symbols(
|
||||
&mut self,
|
||||
pub(super) fn internalize_symbols<'tcx>(
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
codegen_units: &mut [CodegenUnit<'tcx>],
|
||||
mono_item_placements: FxHashMap<MonoItem<'tcx>, MonoItemPlacement>,
|
||||
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
|
||||
) {
|
||||
) {
|
||||
if codegen_units.len() == 1 {
|
||||
// Fast path for when there is only one codegen unit. In this case we
|
||||
// can internalize all candidates, since there is nowhere else they
|
||||
|
@ -336,7 +330,6 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning {
|
|||
*linkage_and_visibility = (Linkage::Internal, Visibility::Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn characteristic_def_id_of_mono_item<'tcx>(
|
||||
|
|
|
@ -113,74 +113,7 @@ use rustc_span::symbol::Symbol;
|
|||
|
||||
use crate::collector::InliningMap;
|
||||
use crate::collector::{self, MonoItemCollectionMode};
|
||||
use crate::errors::{
|
||||
CouldntDumpMonoStats, SymbolAlreadyDefined, UnknownCguCollectionMode, UnknownPartitionStrategy,
|
||||
};
|
||||
|
||||
enum Partitioner {
|
||||
Default(default::DefaultPartitioning),
|
||||
// Other partitioning strategies can go here.
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl<'tcx> Partition<'tcx> for Partitioner {
|
||||
fn place_root_mono_items<I>(
|
||||
&mut self,
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
mono_items: &mut I,
|
||||
) -> PlacedRootMonoItems<'tcx>
|
||||
where
|
||||
I: Iterator<Item = MonoItem<'tcx>>,
|
||||
{
|
||||
match self {
|
||||
Partitioner::Default(partitioner) => partitioner.place_root_mono_items(cx, mono_items),
|
||||
Partitioner::Unknown => cx.tcx.sess.emit_fatal(UnknownPartitionStrategy),
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_codegen_units(
|
||||
&mut self,
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
codegen_units: &mut Vec<CodegenUnit<'tcx>>,
|
||||
) {
|
||||
match self {
|
||||
Partitioner::Default(partitioner) => partitioner.merge_codegen_units(cx, codegen_units),
|
||||
Partitioner::Unknown => cx.tcx.sess.emit_fatal(UnknownPartitionStrategy),
|
||||
}
|
||||
}
|
||||
|
||||
fn place_inlined_mono_items(
|
||||
&mut self,
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
codegen_units: &mut [CodegenUnit<'tcx>],
|
||||
roots: FxHashSet<MonoItem<'tcx>>,
|
||||
) -> FxHashMap<MonoItem<'tcx>, MonoItemPlacement> {
|
||||
match self {
|
||||
Partitioner::Default(partitioner) => {
|
||||
partitioner.place_inlined_mono_items(cx, codegen_units, roots)
|
||||
}
|
||||
Partitioner::Unknown => cx.tcx.sess.emit_fatal(UnknownPartitionStrategy),
|
||||
}
|
||||
}
|
||||
|
||||
fn internalize_symbols(
|
||||
&mut self,
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
codegen_units: &mut [CodegenUnit<'tcx>],
|
||||
mono_item_placements: FxHashMap<MonoItem<'tcx>, MonoItemPlacement>,
|
||||
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
|
||||
) {
|
||||
match self {
|
||||
Partitioner::Default(partitioner) => partitioner.internalize_symbols(
|
||||
cx,
|
||||
codegen_units,
|
||||
mono_item_placements,
|
||||
internalization_candidates,
|
||||
),
|
||||
Partitioner::Unknown => cx.tcx.sess.emit_fatal(UnknownPartitionStrategy),
|
||||
}
|
||||
}
|
||||
}
|
||||
use crate::errors::{CouldntDumpMonoStats, SymbolAlreadyDefined, UnknownCguCollectionMode};
|
||||
|
||||
struct PartitioningCx<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
|
@ -194,49 +127,6 @@ pub struct PlacedRootMonoItems<'tcx> {
|
|||
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
|
||||
}
|
||||
|
||||
trait Partition<'tcx> {
|
||||
fn place_root_mono_items<I>(
|
||||
&mut self,
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
mono_items: &mut I,
|
||||
) -> PlacedRootMonoItems<'tcx>
|
||||
where
|
||||
I: Iterator<Item = MonoItem<'tcx>>;
|
||||
|
||||
fn merge_codegen_units(
|
||||
&mut self,
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
codegen_units: &mut Vec<CodegenUnit<'tcx>>,
|
||||
);
|
||||
|
||||
fn place_inlined_mono_items(
|
||||
&mut self,
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
codegen_units: &mut [CodegenUnit<'tcx>],
|
||||
roots: FxHashSet<MonoItem<'tcx>>,
|
||||
) -> FxHashMap<MonoItem<'tcx>, MonoItemPlacement>;
|
||||
|
||||
fn internalize_symbols(
|
||||
&mut self,
|
||||
cx: &PartitioningCx<'_, 'tcx>,
|
||||
codegen_units: &mut [CodegenUnit<'tcx>],
|
||||
mono_item_placements: FxHashMap<MonoItem<'tcx>, MonoItemPlacement>,
|
||||
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
|
||||
);
|
||||
}
|
||||
|
||||
fn get_partitioner(tcx: TyCtxt<'_>) -> Partitioner {
|
||||
let strategy = match &tcx.sess.opts.unstable_opts.cgu_partitioning_strategy {
|
||||
None => "default",
|
||||
Some(s) => &s[..],
|
||||
};
|
||||
|
||||
match strategy {
|
||||
"default" => Partitioner::Default(default::DefaultPartitioning),
|
||||
_ => Partitioner::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
fn partition<'tcx, I>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
mono_items: &mut I,
|
||||
|
@ -248,14 +138,13 @@ where
|
|||
{
|
||||
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning");
|
||||
|
||||
let mut partitioner = get_partitioner(tcx);
|
||||
let cx = &PartitioningCx { tcx, target_cgu_count: max_cgu_count, inlining_map };
|
||||
// In the first step, we place all regular monomorphizations into their
|
||||
// respective 'home' codegen unit. Regular monomorphizations are all
|
||||
// functions and statics defined in the local crate.
|
||||
let PlacedRootMonoItems { mut codegen_units, roots, internalization_candidates } = {
|
||||
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_roots");
|
||||
partitioner.place_root_mono_items(cx, mono_items)
|
||||
default::place_root_mono_items(cx, mono_items)
|
||||
};
|
||||
|
||||
for cgu in &mut codegen_units {
|
||||
|
@ -269,7 +158,7 @@ where
|
|||
// estimates.
|
||||
{
|
||||
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
|
||||
partitioner.merge_codegen_units(cx, &mut codegen_units);
|
||||
default::merge_codegen_units(cx, &mut codegen_units);
|
||||
debug_dump(tcx, "POST MERGING", &codegen_units);
|
||||
}
|
||||
|
||||
|
@ -279,7 +168,7 @@ where
|
|||
// local functions the definition of which is marked with `#[inline]`.
|
||||
let mono_item_placements = {
|
||||
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_inline_items");
|
||||
partitioner.place_inlined_mono_items(cx, &mut codegen_units, roots)
|
||||
default::place_inlined_mono_items(cx, &mut codegen_units, roots)
|
||||
};
|
||||
|
||||
for cgu in &mut codegen_units {
|
||||
|
@ -292,7 +181,7 @@ where
|
|||
// more freedom to optimize.
|
||||
if !tcx.sess.link_dead_code() {
|
||||
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
|
||||
partitioner.internalize_symbols(
|
||||
default::internalize_symbols(
|
||||
cx,
|
||||
&mut codegen_units,
|
||||
mono_item_placements,
|
||||
|
|
|
@ -1372,8 +1372,6 @@ options! {
|
|||
"set options for branch target identification and pointer authentication on AArch64"),
|
||||
cf_protection: CFProtection = (CFProtection::None, parse_cfprotection, [TRACKED],
|
||||
"instrument control-flow architecture protection"),
|
||||
cgu_partitioning_strategy: Option<String> = (None, parse_opt_string, [TRACKED],
|
||||
"the codegen unit partitioning strategy to use"),
|
||||
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
|
||||
"the backend to use"),
|
||||
combine_cgu: bool = (false, parse_bool, [TRACKED],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue