Skip to content

Commit c250010

Browse files
committed
Auto merge of #53499 - alexcrichton:rc-codegen, r=<try>
Make `codegen_fn_attrs` query cheap to clone This is an attempt to recover a perf loss observed in #52993 by making the result of the `codegen_fn_attrs` query cheap to clone as more and more parts of the compiler start to use this query.
2 parents b355906 + d8db15c commit c250010

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/librustc/middle/reachable.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn generics_require_inlining(generics: &ty::Generics) -> bool {
5151
// true for functions.
5252
fn item_might_be_inlined(tcx: TyCtxt<'a, 'tcx, 'tcx>,
5353
item: &hir::Item,
54-
attrs: CodegenFnAttrs) -> bool {
54+
attrs: &CodegenFnAttrs) -> bool {
5555
if attrs.requests_inline() {
5656
return true
5757
}
@@ -77,7 +77,7 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7777
if let Some(impl_node_id) = tcx.hir.as_local_node_id(impl_src) {
7878
match tcx.hir.find(impl_node_id) {
7979
Some(hir_map::NodeItem(item)) =>
80-
item_might_be_inlined(tcx, &item, codegen_fn_attrs),
80+
item_might_be_inlined(tcx, &item, &codegen_fn_attrs),
8181
Some(..) | None =>
8282
span_bug!(impl_item.span, "impl did is not an item")
8383
}
@@ -171,7 +171,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
171171
Some(hir_map::NodeItem(item)) => {
172172
match item.node {
173173
hir::ItemKind::Fn(..) =>
174-
item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id)),
174+
item_might_be_inlined(self.tcx, &item, &self.tcx.codegen_fn_attrs(def_id)),
175175
_ => false,
176176
}
177177
}
@@ -264,7 +264,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
264264
let def_id = self.tcx.hir.local_def_id(item.id);
265265
if item_might_be_inlined(self.tcx,
266266
&item,
267-
self.tcx.codegen_fn_attrs(def_id)) {
267+
&self.tcx.codegen_fn_attrs(def_id)) {
268268
self.visit_nested_body(body);
269269
}
270270
}

src/librustc/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ define_queries! { <'tcx>
321321
},
322322

323323
Codegen {
324-
[] fn codegen_fn_attrs: codegen_fn_attrs(DefId) -> CodegenFnAttrs,
324+
[] fn codegen_fn_attrs: codegen_fn_attrs(DefId) -> Lrc<CodegenFnAttrs>,
325325
},
326326

327327
Other {

src/librustc_codegen_llvm/attributes.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ pub fn from_fn_attrs(
139139
llfn: &'ll Value,
140140
id: Option<DefId>,
141141
) {
142-
let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
143-
.unwrap_or(CodegenFnAttrs::new());
142+
let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id));
143+
let default = CodegenFnAttrs::new();
144+
let codegen_fn_attrs = codegen_fn_attrs
145+
.as_ref()
146+
.map(|s| &**s)
147+
.unwrap_or(&default);
144148

145149
inline(llfn, codegen_fn_attrs.inline);
146150

src/librustc_typeck/collect.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use rustc::ty::util::Discr;
3939
use rustc::util::captures::Captures;
4040
use rustc::util::nodemap::FxHashMap;
4141
use rustc_target::spec::abi;
42+
use rustc_data_structures::sync::Lrc;
4243

4344
use syntax::ast;
4445
use syntax::ast::MetaItemKind;
@@ -1979,7 +1980,7 @@ fn linkage_by_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, name: &
19791980
}
19801981
}
19811982

1982-
fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> CodegenFnAttrs {
1983+
fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Lrc<CodegenFnAttrs> {
19831984
let attrs = tcx.get_attrs(id);
19841985

19851986
let mut codegen_fn_attrs = CodegenFnAttrs::new();
@@ -2096,5 +2097,5 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen
20962097
}
20972098
}
20982099

2099-
codegen_fn_attrs
2100+
Lrc::new(codegen_fn_attrs)
21002101
}

0 commit comments

Comments
 (0)