Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errors
Rename `rustc_abi::Abi` to `BackendRepr` Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights. Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
This commit is contained in:
commit
847b6fe6b0
98 changed files with 873 additions and 643 deletions
|
@ -2,6 +2,7 @@
|
|||
//!
|
||||
//! Currently, this pass only propagates scalar values.
|
||||
|
||||
use rustc_abi::{BackendRepr, FIRST_VARIANT, FieldIdx, Size, VariantIdx};
|
||||
use rustc_const_eval::const_eval::{DummyMachine, throw_machine_stop_str};
|
||||
use rustc_const_eval::interpret::{
|
||||
ImmTy, Immediate, InterpCx, OpTy, PlaceTy, Projectable, interp_ok,
|
||||
|
@ -20,7 +21,6 @@ use rustc_mir_dataflow::value_analysis::{
|
|||
};
|
||||
use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_target::abi::{Abi, FIRST_VARIANT, FieldIdx, Size, VariantIdx};
|
||||
use tracing::{debug, debug_span, instrument};
|
||||
|
||||
// These constants are somewhat random guesses and have not been optimized.
|
||||
|
@ -457,7 +457,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
|
|||
// a pair and sometimes not. But as a hack we always return a pair
|
||||
// and just make the 2nd component `Bottom` when it does not exist.
|
||||
Some(val) => {
|
||||
if matches!(val.layout.abi, Abi::ScalarPair(..)) {
|
||||
if matches!(val.layout.backend_repr, BackendRepr::ScalarPair(..)) {
|
||||
let (val, overflow) = val.to_scalar_pair();
|
||||
(FlatSet::Elem(val), FlatSet::Elem(overflow))
|
||||
} else {
|
||||
|
@ -470,7 +470,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
|
|||
// Exactly one side is known, attempt some algebraic simplifications.
|
||||
(FlatSet::Elem(const_arg), _) | (_, FlatSet::Elem(const_arg)) => {
|
||||
let layout = const_arg.layout;
|
||||
if !matches!(layout.abi, rustc_target::abi::Abi::Scalar(..)) {
|
||||
if !matches!(layout.backend_repr, rustc_target::abi::BackendRepr::Scalar(..)) {
|
||||
return (FlatSet::Top, FlatSet::Top);
|
||||
}
|
||||
|
||||
|
@ -589,13 +589,13 @@ impl<'a, 'tcx> Collector<'a, 'tcx> {
|
|||
}
|
||||
|
||||
let place = map.find(place.as_ref())?;
|
||||
if layout.abi.is_scalar()
|
||||
if layout.backend_repr.is_scalar()
|
||||
&& let Some(value) = propagatable_scalar(place, state, map)
|
||||
{
|
||||
return Some(Const::Val(ConstValue::Scalar(value), ty));
|
||||
}
|
||||
|
||||
if matches!(layout.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
|
||||
if matches!(layout.backend_repr, BackendRepr::Scalar(..) | BackendRepr::ScalarPair(..)) {
|
||||
let alloc_id = ecx
|
||||
.intern_with_temp_alloc(layout, |ecx, dest| {
|
||||
try_write_constant(ecx, dest, place, ty, state, map)
|
||||
|
@ -641,7 +641,7 @@ fn try_write_constant<'tcx>(
|
|||
}
|
||||
|
||||
// Fast path for scalars.
|
||||
if layout.abi.is_scalar()
|
||||
if layout.backend_repr.is_scalar()
|
||||
&& let Some(value) = propagatable_scalar(place, state, map)
|
||||
{
|
||||
return ecx.write_immediate(Immediate::Scalar(value), dest);
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use either::Either;
|
||||
use rustc_abi::{self as abi, BackendRepr, FIRST_VARIANT, FieldIdx, Primitive, Size, VariantIdx};
|
||||
use rustc_const_eval::const_eval::DummyMachine;
|
||||
use rustc_const_eval::interpret::{
|
||||
ImmTy, Immediate, InterpCx, MemPlaceMeta, MemoryKind, OpTy, Projectable, Scalar,
|
||||
|
@ -103,7 +104,6 @@ use rustc_middle::ty::layout::{HasParamEnv, LayoutOf};
|
|||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_target::abi::{self, Abi, FIRST_VARIANT, FieldIdx, Primitive, Size, VariantIdx};
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
|
@ -427,7 +427,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
};
|
||||
let ptr_imm = Immediate::new_pointer_with_meta(data, meta, &self.ecx);
|
||||
ImmTy::from_immediate(ptr_imm, ty).into()
|
||||
} else if matches!(ty.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
|
||||
} else if matches!(
|
||||
ty.backend_repr,
|
||||
BackendRepr::Scalar(..) | BackendRepr::ScalarPair(..)
|
||||
) {
|
||||
let dest = self.ecx.allocate(ty, MemoryKind::Stack).discard_err()?;
|
||||
let variant_dest = if let Some(variant) = variant {
|
||||
self.ecx.project_downcast(&dest, variant).discard_err()?
|
||||
|
@ -573,12 +576,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
// limited transmutes: it only works between types with the same layout, and
|
||||
// cannot transmute pointers to integers.
|
||||
if value.as_mplace_or_imm().is_right() {
|
||||
let can_transmute = match (value.layout.abi, to.abi) {
|
||||
(Abi::Scalar(s1), Abi::Scalar(s2)) => {
|
||||
let can_transmute = match (value.layout.backend_repr, to.backend_repr) {
|
||||
(BackendRepr::Scalar(s1), BackendRepr::Scalar(s2)) => {
|
||||
s1.size(&self.ecx) == s2.size(&self.ecx)
|
||||
&& !matches!(s1.primitive(), Primitive::Pointer(..))
|
||||
}
|
||||
(Abi::ScalarPair(a1, b1), Abi::ScalarPair(a2, b2)) => {
|
||||
(BackendRepr::ScalarPair(a1, b1), BackendRepr::ScalarPair(a2, b2)) => {
|
||||
a1.size(&self.ecx) == a2.size(&self.ecx) &&
|
||||
b1.size(&self.ecx) == b2.size(&self.ecx) &&
|
||||
// The alignment of the second component determines its offset, so that also needs to match.
|
||||
|
@ -1241,7 +1244,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
|
||||
let as_bits = |value| {
|
||||
let constant = self.evaluated[value].as_ref()?;
|
||||
if layout.abi.is_scalar() {
|
||||
if layout.backend_repr.is_scalar() {
|
||||
let scalar = self.ecx.read_scalar(constant).discard_err()?;
|
||||
scalar.to_bits(constant.layout.size).discard_err()
|
||||
} else {
|
||||
|
@ -1497,12 +1500,12 @@ fn op_to_prop_const<'tcx>(
|
|||
|
||||
// Do not synthetize too large constants. Codegen will just memcpy them, which we'd like to
|
||||
// avoid.
|
||||
if !matches!(op.layout.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
|
||||
if !matches!(op.layout.backend_repr, BackendRepr::Scalar(..) | BackendRepr::ScalarPair(..)) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// If this constant has scalar ABI, return it as a `ConstValue::Scalar`.
|
||||
if let Abi::Scalar(abi::Scalar::Initialized { .. }) = op.layout.abi
|
||||
if let BackendRepr::Scalar(abi::Scalar::Initialized { .. }) = op.layout.backend_repr
|
||||
&& let Some(scalar) = ecx.read_scalar(op).discard_err()
|
||||
{
|
||||
if !scalar.try_to_scalar_int().is_ok() {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use rustc_abi::{BackendRepr, FieldIdx, HasDataLayout, Size, TargetDataLayout, VariantIdx};
|
||||
use rustc_const_eval::const_eval::DummyMachine;
|
||||
use rustc_const_eval::interpret::{
|
||||
ImmTy, InterpCx, InterpResult, Projectable, Scalar, format_interp_error, interp_ok,
|
||||
|
@ -19,7 +20,6 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
|
||||
use rustc_middle::ty::{self, ConstInt, ParamEnv, ScalarInt, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::{Abi, FieldIdx, HasDataLayout, Size, TargetDataLayout, VariantIdx};
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use crate::errors::{AssertLint, AssertLintKind};
|
||||
|
@ -557,7 +557,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
let right = self.use_ecx(|this| this.ecx.read_immediate(&right))?;
|
||||
|
||||
let val = self.use_ecx(|this| this.ecx.binary_op(bin_op, &left, &right))?;
|
||||
if matches!(val.layout.abi, Abi::ScalarPair(..)) {
|
||||
if matches!(val.layout.backend_repr, BackendRepr::ScalarPair(..)) {
|
||||
// FIXME `Value` should properly support pairs in `Immediate`... but currently
|
||||
// it does not.
|
||||
let (val, overflow) = val.to_pair(&self.ecx);
|
||||
|
@ -651,9 +651,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
let to = self.ecx.layout_of(to).ok()?;
|
||||
// `offset` for immediates only supports scalar/scalar-pair ABIs,
|
||||
// so bail out if the target is not one.
|
||||
match (value.layout.abi, to.abi) {
|
||||
(Abi::Scalar(..), Abi::Scalar(..)) => {}
|
||||
(Abi::ScalarPair(..), Abi::ScalarPair(..)) => {}
|
||||
match (value.layout.backend_repr, to.backend_repr) {
|
||||
(BackendRepr::Scalar(..), BackendRepr::Scalar(..)) => {}
|
||||
(BackendRepr::ScalarPair(..), BackendRepr::ScalarPair(..)) => {}
|
||||
_ => return None,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue