Skip to content

Commit d41a04d

Browse files
committed
Introduce optimized_mir_summary.
1 parent 3172dfa commit d41a04d

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
lines changed

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
201201
const_param_default => { table }
202202
thir_abstract_const => { table }
203203
optimized_mir => { table }
204+
optimized_mir_summary => { table }
204205
mir_for_ctfe => { table }
205206
promoted_mir => { table }
206207
def_span => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13521352
debug!("EntryBuilder::encode_mir({:?})", def_id);
13531353
if encode_opt {
13541354
record!(self.tables.optimized_mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
1355+
record!(self.tables.optimized_mir_summary[def_id.to_def_id()] <- self.tcx.optimized_mir_summary(def_id));
13551356
}
13561357
if encode_const {
13571358
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- self.tcx.mir_for_ctfe(def_id));

compiler/rustc_metadata/src/rmeta/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ define_tables! {
360360
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,
361361
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
362362
promoted_mir: Table<DefIndex, LazyValue<IndexVec<mir::Promoted, mir::Body<'static>>>>,
363+
optimized_mir_summary: Table<DefIndex, LazyValue<mir::Summary>>,
363364
// FIXME(compiler-errors): Why isn't this a LazyArray?
364365
thir_abstract_const: Table<DefIndex, LazyValue<&'static [ty::abstract_const::Node<'static>]>>,
365366
impl_parent: Table<DefIndex, RawDefId>,

compiler/rustc_middle/src/mir/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2900,3 +2900,10 @@ impl Location {
29002900
}
29012901
}
29022902
}
2903+
2904+
#[derive(Debug, Copy, Clone, HashStable, Encodable, Decodable)]
2905+
pub struct Summary {
2906+
pub inlining_cost: usize,
2907+
pub bbcount: usize,
2908+
pub diverges: bool,
2909+
}

compiler/rustc_middle/src/query/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,13 @@ rustc_queries! {
431431
separate_provide_extern
432432
}
433433

434+
/// Summary of `optimized_mir` to avoid decoding it when we are not planning to use it.
435+
query optimized_mir_summary(key: DefId) -> mir::Summary {
436+
desc { |tcx| "summarizing MIR for `{}`", tcx.def_path_str(key) }
437+
cache_on_disk_if { key.is_local() }
438+
separate_provide_extern
439+
}
440+
434441
/// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
435442
/// MIR pass (assuming the -Cinstrument-coverage option is enabled).
436443
query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {

compiler/rustc_middle/src/ty/parameterized.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ trivially_parameterized_over_tcx! {
5454
crate::middle::codegen_fn_attrs::CodegenFnAttrs,
5555
crate::middle::exported_symbols::SymbolExportInfo,
5656
crate::mir::ConstQualifs,
57+
crate::mir::Summary,
5758
ty::Generics,
5859
ty::ImplPolarity,
5960
ty::ReprOptions,

compiler/rustc_mir_transform/src/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
2626
use rustc_hir::intravisit::{self, Visitor};
2727
use rustc_index::vec::IndexVec;
2828
use rustc_middle::mir::visit::Visitor as _;
29-
use rustc_middle::mir::{traversal, Body, ConstQualifs, MirPass, MirPhase, Promoted};
29+
use rustc_middle::mir::{traversal, Body, ConstQualifs, MirPass, MirPhase, Promoted, Summary};
3030
use rustc_middle::ty::query::Providers;
3131
use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
3232
use rustc_span::{Span, Symbol};
@@ -120,6 +120,7 @@ pub fn provide(providers: &mut Providers) {
120120
mir_for_ctfe,
121121
mir_for_ctfe_of_const_arg,
122122
optimized_mir,
123+
optimized_mir_summary,
123124
is_mir_available,
124125
is_ctfe_mir_available: |tcx, did| is_mir_available(tcx, did),
125126
mir_callgraph_reachable: inline::cycle::mir_callgraph_reachable,
@@ -573,3 +574,11 @@ fn promoted_mir<'tcx>(
573574

574575
tcx.arena.alloc(promoted)
575576
}
577+
578+
fn optimized_mir_summary<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> Summary {
579+
let body = tcx.optimized_mir(did);
580+
let param_env = tcx.param_env_reveal_all_normalized(did);
581+
let cost_info = inline::body_cost(tcx, param_env, body, |ty| ty);
582+
let inline::InlineCostInfo { cost, bbcount, diverges } = cost_info;
583+
Summary { inlining_cost: cost, bbcount, diverges }
584+
}

0 commit comments

Comments
 (0)