Add instance_def_size_estimate query
This commit is contained in:
parent
c8e9da44a9
commit
5c9a8b5041
6 changed files with 33 additions and 2 deletions
|
|
@ -638,6 +638,7 @@ define_dep_nodes!( <'tcx>
|
|||
[input] TargetFeaturesWhitelist,
|
||||
[] TargetFeaturesEnabled(DefId),
|
||||
|
||||
[] InstanceDefSizeEstimate { instance_def: InstanceDef<'tcx> },
|
||||
);
|
||||
|
||||
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ impl<'tcx> MonoItem<'tcx> {
|
|||
MonoItem::Fn(instance) => {
|
||||
// Estimate the size of a function based on how many statements
|
||||
// it contains.
|
||||
let mir = tcx.instance_mir(instance.def);
|
||||
mir.basic_blocks().iter().map(|bb| bb.statements.len()).sum()
|
||||
tcx.instance_def_size_estimate(instance.def)
|
||||
},
|
||||
// Conservatively estimate the size of a static declaration
|
||||
// or assembly to be 1.
|
||||
|
|
|
|||
|
|
@ -637,6 +637,12 @@ impl<'tcx> QueryDescription<'tcx> for queries::target_features_whitelist<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryDescription<'tcx> for queries::instance_def_size_estimate<'tcx> {
|
||||
fn describe(tcx: TyCtxt, def: ty::InstanceDef<'tcx>) -> String {
|
||||
format!("estimating size for `{}`", tcx.item_path_str(def.def_id()))
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_disk_cacheable_query(
|
||||
($query_name:ident, |$key:tt| $cond:expr) => {
|
||||
impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> {
|
||||
|
|
|
|||
|
|
@ -365,6 +365,9 @@ define_maps! { <'tcx>
|
|||
target_features_whitelist_node(CrateNum) -> Rc<FxHashSet<String>>,
|
||||
[] fn target_features_enabled: TargetFeaturesEnabled(DefId) -> Rc<Vec<String>>,
|
||||
|
||||
// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
|
||||
[] fn instance_def_size_estimate: instance_def_size_estimate_dep_node(ty::InstanceDef<'tcx>)
|
||||
-> usize,
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -514,3 +517,10 @@ fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs
|
|||
fn target_features_whitelist_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
|
||||
DepConstructor::TargetFeaturesWhitelist
|
||||
}
|
||||
|
||||
fn instance_def_size_estimate_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>)
|
||||
-> DepConstructor<'tcx> {
|
||||
DepConstructor::InstanceDefSizeEstimate {
|
||||
instance_def
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -761,6 +761,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
|
|||
DepKind::EraseRegionsTy |
|
||||
DepKind::NormalizeTy |
|
||||
DepKind::SubstituteNormalizeAndTestPredicates |
|
||||
DepKind::InstanceDefSizeEstimate |
|
||||
|
||||
// This one should never occur in this context
|
||||
DepKind::Null => {
|
||||
|
|
|
|||
|
|
@ -2669,6 +2669,19 @@ fn crate_hash<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
tcx.hir.crate_hash
|
||||
}
|
||||
|
||||
fn instance_def_size_estimate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
instance_def: InstanceDef<'tcx>)
|
||||
-> usize {
|
||||
match instance_def {
|
||||
InstanceDef::Item(def_id) => {
|
||||
let mir = tcx.optimized_mir(def_id);
|
||||
mir.basic_blocks().iter().map(|bb| bb.statements.len()).sum()
|
||||
},
|
||||
// Estimate the size of compiler-generated shims to be 1.
|
||||
_ => 1
|
||||
}
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::maps::Providers) {
|
||||
context::provide(providers);
|
||||
erase_regions::provide(providers);
|
||||
|
|
@ -2686,6 +2699,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
|
|||
original_crate_name,
|
||||
crate_hash,
|
||||
trait_impls_of: trait_def::trait_impls_of_provider,
|
||||
instance_def_size_estimate,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue