mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Don't compute optimized PointerKind for unoptimized builds
This saves us both the Freeze/Unpin queries, and avoids placing noalias attributes, which have a compile-time impact on LLVM even in optnone builds (due to always_inline functions).
This commit is contained in:
parent
39ed64399e
commit
6ac229ca21
@ -11,7 +11,7 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
use rustc_session::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
|
use rustc_session::{config::OptLevel, DataTypeKind, FieldInfo, SizeKind, VariantInfo};
|
||||||
use rustc_span::symbol::{Ident, Symbol};
|
use rustc_span::symbol::{Ident, Symbol};
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
use rustc_target::abi::call::{
|
use rustc_target::abi::call::{
|
||||||
@ -2318,23 +2318,30 @@ where
|
|||||||
ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
|
ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
|
||||||
let address_space = addr_space_of_ty(ty);
|
let address_space = addr_space_of_ty(ty);
|
||||||
let tcx = cx.tcx();
|
let tcx = cx.tcx();
|
||||||
let kind = match mt {
|
let kind = if tcx.sess.opts.optimize == OptLevel::No {
|
||||||
hir::Mutability::Not => {
|
// Use conservative pointer kind if not optimizing. This saves us the
|
||||||
if ty.is_freeze(tcx.at(DUMMY_SP), cx.param_env()) {
|
// Freeze/Unpin queries, and can save time in the codegen backend (noalias
|
||||||
PointerKind::Frozen
|
// attributes in LLVM have compile-time cost even in unoptimized builds).
|
||||||
} else {
|
PointerKind::Shared
|
||||||
PointerKind::Shared
|
} else {
|
||||||
|
match mt {
|
||||||
|
hir::Mutability::Not => {
|
||||||
|
if ty.is_freeze(tcx.at(DUMMY_SP), cx.param_env()) {
|
||||||
|
PointerKind::Frozen
|
||||||
|
} else {
|
||||||
|
PointerKind::Shared
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
hir::Mutability::Mut => {
|
||||||
hir::Mutability::Mut => {
|
// References to self-referential structures should not be considered
|
||||||
// References to self-referential structures should not be considered
|
// noalias, as another pointer to the structure can be obtained, that
|
||||||
// noalias, as another pointer to the structure can be obtained, that
|
// is not based-on the original reference. We consider all !Unpin
|
||||||
// is not based-on the original reference. We consider all !Unpin
|
// types to be potentially self-referential here.
|
||||||
// types to be potentially self-referential here.
|
if ty.is_unpin(tcx.at(DUMMY_SP), cx.param_env()) {
|
||||||
if ty.is_unpin(tcx.at(DUMMY_SP), cx.param_env()) {
|
PointerKind::UniqueBorrowed
|
||||||
PointerKind::UniqueBorrowed
|
} else {
|
||||||
} else {
|
PointerKind::Shared
|
||||||
PointerKind::Shared
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// compile-flags: -C no-prepopulate-passes
|
// compile-flags: -O -C no-prepopulate-passes
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// min-system-llvm-version: 12.0
|
// min-system-llvm-version: 12.0
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// compile-flags: -Z mutable-noalias=yes
|
// compile-flags: -O -Z mutable-noalias=yes
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags: -C no-prepopulate-passes
|
// compile-flags: -O -C no-prepopulate-passes
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user