mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Revert "Auto merge of #76896 - spastorino:codegen-inline-fns2, r=davidtwco,wesleywiser"
This reverts commitddf2cc7f8e
, reversing changes made to937f629535
.
This commit is contained in:
parent
6526e5c772
commit
82d0c597bf
@ -1,6 +1,7 @@
|
|||||||
use crate::dep_graph::{dep_constructor, DepNode, WorkProduct, WorkProductId};
|
use crate::dep_graph::{dep_constructor, DepNode, WorkProduct, WorkProductId};
|
||||||
use crate::ich::{NodeIdHashingMode, StableHashingContext};
|
use crate::ich::{NodeIdHashingMode, StableHashingContext};
|
||||||
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
|
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
|
||||||
|
use rustc_attr::InlineAttr;
|
||||||
use rustc_data_structures::base_n;
|
use rustc_data_structures::base_n;
|
||||||
use rustc_data_structures::fingerprint::Fingerprint;
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
@ -78,6 +79,14 @@ impl<'tcx> MonoItem<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx>) -> InstantiationMode {
|
pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx>) -> InstantiationMode {
|
||||||
|
let generate_cgu_internal_copies = tcx
|
||||||
|
.sess
|
||||||
|
.opts
|
||||||
|
.debugging_opts
|
||||||
|
.inline_in_all_cgus
|
||||||
|
.unwrap_or_else(|| tcx.sess.opts.optimize != OptLevel::No)
|
||||||
|
&& !tcx.sess.link_dead_code();
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
MonoItem::Fn(ref instance) => {
|
MonoItem::Fn(ref instance) => {
|
||||||
let entry_def_id = tcx.entry_fn(LOCAL_CRATE).map(|(id, _)| id);
|
let entry_def_id = tcx.entry_fn(LOCAL_CRATE).map(|(id, _)| id);
|
||||||
@ -90,26 +99,21 @@ impl<'tcx> MonoItem<'tcx> {
|
|||||||
return InstantiationMode::GloballyShared { may_conflict: false };
|
return InstantiationMode::GloballyShared { may_conflict: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
let generate_cgu_internal_copies = tcx
|
|
||||||
.sess
|
|
||||||
.opts
|
|
||||||
.debugging_opts
|
|
||||||
.inline_in_all_cgus
|
|
||||||
.unwrap_or_else(|| tcx.sess.opts.optimize != OptLevel::No)
|
|
||||||
&& !tcx.sess.link_dead_code();
|
|
||||||
|
|
||||||
// At this point we don't have explicit linkage and we're an
|
// At this point we don't have explicit linkage and we're an
|
||||||
// inlined function. If we should generate local copies for each CGU,
|
// inlined function. If we're inlining into all CGUs then we'll
|
||||||
// then return `LocalCopy`, otherwise we'll just generate one copy
|
// be creating a local copy per CGU.
|
||||||
// and share it with all CGUs in this crate.
|
|
||||||
if generate_cgu_internal_copies {
|
if generate_cgu_internal_copies {
|
||||||
InstantiationMode::LocalCopy
|
return InstantiationMode::LocalCopy;
|
||||||
} else {
|
}
|
||||||
// Finally, if we've reached this point, then we should optimize for
|
|
||||||
// compilation speed. In that regard, we will ignore any `#[inline]`
|
// Finally, if this is `#[inline(always)]` we're sure to respect
|
||||||
// annotations on the function and simply codegen it as usual. This could
|
// that with an inline copy per CGU, but otherwise we'll be
|
||||||
// conflict with upstream crates as it could be an exported symbol.
|
// creating one copy of this `#[inline]` function which may
|
||||||
InstantiationMode::GloballyShared { may_conflict: true }
|
// conflict with upstream crates as it could be an exported
|
||||||
|
// symbol.
|
||||||
|
match tcx.codegen_fn_attrs(instance.def_id()).inline {
|
||||||
|
InlineAttr::Always => InstantiationMode::LocalCopy,
|
||||||
|
_ => InstantiationMode::GloballyShared { may_conflict: true },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MonoItem::Static(..) | MonoItem::GlobalAsm(..) => {
|
MonoItem::Static(..) | MonoItem::GlobalAsm(..) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// revisions:rpass1 rpass2
|
// revisions:rpass1 rpass2
|
||||||
// compile-flags: -Z query-dep-graph -O
|
// compile-flags: -Z query-dep-graph
|
||||||
// aux-build:cached_hygiene.rs
|
// aux-build:cached_hygiene.rs
|
||||||
|
|
||||||
// This tests the folllowing scenario
|
// This tests the folllowing scenario
|
||||||
@ -19,12 +19,7 @@
|
|||||||
// the metadata. Specifically, we were not resetting `orig_id`
|
// the metadata. Specifically, we were not resetting `orig_id`
|
||||||
// for an `EpxnData` generate in the current crate, which would cause
|
// for an `EpxnData` generate in the current crate, which would cause
|
||||||
// us to serialize the `ExpnId` pointing to a garbage location in
|
// us to serialize the `ExpnId` pointing to a garbage location in
|
||||||
// the metadata.o
|
// the metadata.
|
||||||
|
|
||||||
// NOTE: We're explicitly passing the `-O` optimization flag because if optimizations are not
|
|
||||||
// enabled, then rustc will ignore the `#[inline(always)]` attribute which means we do not load
|
|
||||||
// the optimized mir for the unmodified function to be loaded and so the CGU containing that
|
|
||||||
// function will be reused.
|
|
||||||
|
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
|
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
// revisions:rpass1 rpass2 rpass3
|
// revisions:rpass1 rpass2 rpass3
|
||||||
// compile-flags: -Z query-dep-graph -g -O
|
// compile-flags: -Z query-dep-graph -g
|
||||||
// aux-build:extern_crate.rs
|
// aux-build:extern_crate.rs
|
||||||
|
|
||||||
// ignore-asmjs wasm2js does not support source maps yet
|
// ignore-asmjs wasm2js does not support source maps yet
|
||||||
|
|
||||||
// This test case makes sure that we detect if paths emitted into debuginfo
|
// This test case makes sure that we detect if paths emitted into debuginfo
|
||||||
// are changed, even when the change happens in an external crate.
|
// are changed, even when the change happens in an external crate.
|
||||||
|
|
||||||
// NOTE: We're explicitly passing the `-O` optimization flag because if no optimizations are
|
|
||||||
// requested, rustc will ignore the `#[inline]` attribute. This is a performance optimization for
|
|
||||||
// non-optimized builds which causes us to generate fewer copies of inlined functions when
|
|
||||||
// runtime performance doesn't matter. Without this flag, the function will go into a different
|
|
||||||
// CGU which can be reused by this crate.
|
|
||||||
|
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
|
|
||||||
#![rustc_partition_reused(module="main", cfg="rpass2")]
|
#![rustc_partition_reused(module="main", cfg="rpass2")]
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
-include ../tools.mk
|
-include ../tools.mk
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2 -C opt-level=0
|
$(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2
|
||||||
if ![cat $(TMPDIR)/*.ll | $(CGREP) -e '\bcall\b']; then \
|
|
||||||
echo "not found call instruction when one was expected"; \
|
|
||||||
exit 1; \
|
|
||||||
fi
|
|
||||||
$(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2 -C opt-level=1
|
|
||||||
if cat $(TMPDIR)/*.ll | $(CGREP) -e '\bcall\b'; then \
|
if cat $(TMPDIR)/*.ll | $(CGREP) -e '\bcall\b'; then \
|
||||||
echo "found call instruction when one wasn't expected"; \
|
echo "found call instruction when one wasn't expected"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
|
Loading…
Reference in New Issue
Block a user