summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_ssa/src/mir
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_codegen_ssa/src/mir
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/mir')
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/analyze.rs19
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/block.rs63
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/constant.rs2
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/intrinsic.rs69
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/mod.rs15
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/rvalue.rs26
6 files changed, 90 insertions, 104 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs
index d9419dbc9..2285e7f4e 100644
--- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs
@@ -8,7 +8,7 @@ use rustc_index::bit_set::BitSet;
use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
-use rustc_middle::mir::{self, Location, TerminatorKind};
+use rustc_middle::mir::{self, DefLocation, Location, TerminatorKind};
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
@@ -67,21 +67,6 @@ enum LocalKind {
SSA(DefLocation),
}
-#[derive(Copy, Clone, PartialEq, Eq)]
-enum DefLocation {
- Argument,
- Body(Location),
-}
-
-impl DefLocation {
- fn dominates(self, location: Location, dominators: &Dominators<mir::BasicBlock>) -> bool {
- match self {
- DefLocation::Argument => true,
- DefLocation::Body(def) => def.successor_within_block().dominates(location, dominators),
- }
- }
-}
-
struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
fx: &'mir FunctionCx<'a, 'tcx, Bx>,
dominators: &'mir Dominators<mir::BasicBlock>,
@@ -287,7 +272,7 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
| TerminatorKind::UnwindResume
| TerminatorKind::UnwindTerminate(_)
| TerminatorKind::Return
- | TerminatorKind::GeneratorDrop
+ | TerminatorKind::CoroutineDrop
| TerminatorKind::Unreachable
| TerminatorKind::SwitchInt { .. }
| TerminatorKind::Yield { .. }
diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs
index bd0707edf..3d2d8f8b5 100644
--- a/compiler/rustc_codegen_ssa/src/mir/block.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/block.rs
@@ -17,8 +17,7 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
use rustc_middle::ty::{self, Instance, Ty};
use rustc_session::config::OptLevel;
-use rustc_span::source_map::Span;
-use rustc_span::{sym, Symbol};
+use rustc_span::{sym, Span, Symbol};
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode, Reg};
use rustc_target::abi::{self, HasDataLayout, WrappingRange};
use rustc_target::spec::abi::Abi;
@@ -213,7 +212,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
self.funclet(fx),
);
if fx.mir[self.bb].is_cleanup {
- bx.do_not_inline(invokeret);
+ bx.apply_attrs_to_cleanup_callsite(invokeret);
}
if let Some((ret_dest, target)) = destination {
@@ -228,11 +227,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
} else {
let llret = bx.call(fn_ty, fn_attrs, Some(&fn_abi), fn_ptr, &llargs, self.funclet(fx));
if fx.mir[self.bb].is_cleanup {
- // Cleanup is always the cold path. Don't inline
- // drop glue. Also, when there is a deeply-nested
- // struct, there are "symmetry" issues that cause
- // exponential inlining - see issue #41696.
- bx.do_not_inline(llret);
+ bx.apply_attrs_to_cleanup_callsite(llret);
}
if let Some((ret_dest, target)) = destination {
@@ -1269,8 +1264,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
fn_span,
mergeable_succ(),
),
- mir::TerminatorKind::GeneratorDrop | mir::TerminatorKind::Yield { .. } => {
- bug!("generator ops in codegen")
+ mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => {
+ bug!("coroutine ops in codegen")
}
mir::TerminatorKind::FalseEdge { .. } | mir::TerminatorKind::FalseUnwind { .. } => {
bug!("borrowck false edges in codegen")
@@ -1453,46 +1448,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
fn get_caller_location(
&mut self,
bx: &mut Bx,
- mut source_info: mir::SourceInfo,
+ source_info: mir::SourceInfo,
) -> OperandRef<'tcx, Bx::Value> {
- let tcx = bx.tcx();
-
- let mut span_to_caller_location = |span: Span| {
- let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
- let caller = tcx.sess.source_map().lookup_char_pos(topmost.lo());
- let const_loc = tcx.const_caller_location((
- Symbol::intern(&caller.file.name.prefer_remapped().to_string_lossy()),
- caller.line as u32,
- caller.col_display as u32 + 1,
- ));
+ self.mir.caller_location_span(source_info, self.caller_location, bx.tcx(), |span: Span| {
+ let const_loc = bx.tcx().span_as_caller_location(span);
OperandRef::from_const(bx, const_loc, bx.tcx().caller_location_ty())
- };
-
- // Walk up the `SourceScope`s, in case some of them are from MIR inlining.
- // If so, the starting `source_info.span` is in the innermost inlined
- // function, and will be replaced with outer callsite spans as long
- // as the inlined functions were `#[track_caller]`.
- loop {
- let scope_data = &self.mir.source_scopes[source_info.scope];
-
- if let Some((callee, callsite_span)) = scope_data.inlined {
- // Stop inside the most nested non-`#[track_caller]` function,
- // before ever reaching its caller (which is irrelevant).
- if !callee.def.requires_caller_location(tcx) {
- return span_to_caller_location(source_info.span);
- }
- source_info.span = callsite_span;
- }
-
- // Skip past all of the parents with `inlined: None`.
- match scope_data.inlined_parent_scope {
- Some(parent) => source_info.scope = parent,
- None => break,
- }
- }
-
- // No inlined `SourceScope`s, or all of them were `#[track_caller]`.
- self.caller_location.unwrap_or_else(|| span_to_caller_location(source_info.span))
+ })
}
fn get_personality_slot(&mut self, bx: &mut Bx) -> PlaceRef<'tcx, Bx::Value> {
@@ -1559,7 +1520,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
fn terminate_block(&mut self, reason: UnwindTerminateReason) -> Bx::BasicBlock {
- if let Some((cached_bb, cached_reason)) = self.terminate_block && reason == cached_reason {
+ if let Some((cached_bb, cached_reason)) = self.terminate_block
+ && reason == cached_reason
+ {
return cached_bb;
}
@@ -1627,7 +1590,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let fn_ty = bx.fn_decl_backend_type(&fn_abi);
let llret = bx.call(fn_ty, None, Some(&fn_abi), fn_ptr, &[], funclet.as_ref());
- bx.do_not_inline(llret);
+ bx.apply_attrs_to_cleanup_callsite(llret);
bx.unreachable();
diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs
index fde4e85f9..558f64fff 100644
--- a/compiler/rustc_codegen_ssa/src/mir/constant.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs
@@ -21,6 +21,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
pub fn eval_mir_constant(&self, constant: &mir::ConstOperand<'tcx>) -> mir::ConstValue<'tcx> {
+ // `MirUsedCollector` visited all constants before codegen began, so if we got here there
+ // can be no more constants that fail to evaluate.
self.monomorphize(constant.const_)
.eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), Some(constant.span))
.expect("erroneous constant not captured by required_consts")
diff --git a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs
index 8efef4405..136d06d56 100644
--- a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs
@@ -117,9 +117,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
sym::vtable_size => {
let size_bound = bx.data_layout().ptr_sized_integer().signed_max() as u128;
bx.range_metadata(value, WrappingRange { start: 0, end: size_bound });
- },
+ }
// Alignment is always nonzero.
- sym::vtable_align => bx.range_metadata(value, WrappingRange { start: 1, end: !0 }),
+ sym::vtable_align => {
+ bx.range_metadata(value, WrappingRange { start: 1, end: !0 })
+ }
_ => {}
}
value
@@ -220,9 +222,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} else {
bx.exactudiv(args[0].immediate(), args[1].immediate())
}
- },
+ }
None => {
- bx.tcx().sess.emit_err(InvalidMonomorphization::BasicIntegerType { span, name, ty });
+ bx.tcx().sess.emit_err(InvalidMonomorphization::BasicIntegerType {
+ span,
+ name,
+ ty,
+ });
return;
}
}
@@ -238,7 +244,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
_ => bug!(),
},
None => {
- bx.tcx().sess.emit_err(InvalidMonomorphization::BasicFloatType { span, name, ty: arg_tys[0] });
+ bx.tcx().sess.emit_err(InvalidMonomorphization::BasicFloatType {
+ span,
+ name,
+ ty: arg_tys[0],
+ });
return;
}
}
@@ -246,11 +256,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
sym::float_to_int_unchecked => {
if float_type_width(arg_tys[0]).is_none() {
- bx.tcx().sess.emit_err(InvalidMonomorphization::FloatToIntUnchecked { span, ty: arg_tys[0] });
+ bx.tcx().sess.emit_err(InvalidMonomorphization::FloatToIntUnchecked {
+ span,
+ ty: arg_tys[0],
+ });
return;
}
let Some((_width, signed)) = int_type_width_signed(ret_ty, bx.tcx()) else {
- bx.tcx().sess.emit_err(InvalidMonomorphization::FloatToIntUnchecked { span, ty: ret_ty });
+ bx.tcx().sess.emit_err(InvalidMonomorphization::FloatToIntUnchecked {
+ span,
+ ty: ret_ty,
+ });
return;
};
if signed {
@@ -299,7 +315,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
};
let invalid_monomorphization = |ty| {
- bx.tcx().sess.emit_err(InvalidMonomorphization::BasicIntegerType { span, name, ty });
+ bx.tcx().sess.emit_err(InvalidMonomorphization::BasicIntegerType {
+ span,
+ name,
+ ty,
+ });
};
match instruction {
@@ -319,7 +339,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
cmp = bx.ptrtoint(cmp, bx.type_isize());
src = bx.ptrtoint(src, bx.type_isize());
}
- let pair = bx.atomic_cmpxchg(dst, cmp, src, parse_ordering(bx, success), parse_ordering(bx, failure), weak);
+ let pair = bx.atomic_cmpxchg(
+ dst,
+ cmp,
+ src,
+ parse_ordering(bx, success),
+ parse_ordering(bx, failure),
+ weak,
+ );
let val = bx.extract_value(pair, 0);
let success = bx.extract_value(pair, 1);
let val = bx.from_immediate(val);
@@ -345,11 +372,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// Some platforms do not support atomic operations on pointers,
// so we cast to integer first...
let llty = bx.type_isize();
- let result = bx.atomic_load(llty, source, parse_ordering(bx, ordering), size);
+ let result = bx.atomic_load(
+ llty,
+ source,
+ parse_ordering(bx, ordering),
+ size,
+ );
// ... and then cast the result back to a pointer
bx.inttoptr(result, bx.backend_type(layout))
} else {
- bx.atomic_load(bx.backend_type(layout), source, parse_ordering(bx, ordering), size)
+ bx.atomic_load(
+ bx.backend_type(layout),
+ source,
+ parse_ordering(bx, ordering),
+ size,
+ )
}
} else {
return invalid_monomorphization(ty);
@@ -375,12 +412,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
"fence" => {
- bx.atomic_fence(parse_ordering(bx, ordering), SynchronizationScope::CrossThread);
+ bx.atomic_fence(
+ parse_ordering(bx, ordering),
+ SynchronizationScope::CrossThread,
+ );
return;
}
"singlethreadfence" => {
- bx.atomic_fence(parse_ordering(bx, ordering), SynchronizationScope::SingleThread);
+ bx.atomic_fence(
+ parse_ordering(bx, ordering),
+ SynchronizationScope::SingleThread,
+ );
return;
}
diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs
index a61018f98..d0b799e08 100644
--- a/compiler/rustc_codegen_ssa/src/mir/mod.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs
@@ -209,18 +209,11 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
caller_location: None,
};
- fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut start_bx);
+ // It may seem like we should iterate over `required_consts` to ensure they all successfully
+ // evaluate; however, the `MirUsedCollector` already did that during the collection phase of
+ // monomorphization so we don't have to do it again.
- // Rust post-monomorphization checks; we later rely on them.
- if let Err(err) =
- mir.post_mono_checks(cx.tcx(), ty::ParamEnv::reveal_all(), |c| Ok(fx.monomorphize(c)))
- {
- err.emit_err(cx.tcx());
- // This IR shouldn't ever be emitted, but let's try to guard against any of this code
- // ever running.
- start_bx.abort();
- return;
- }
+ fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut start_bx);
let memory_locals = analyze::non_ssa_locals(&fx);
diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
index fc8d33891..8e5019967 100644
--- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
@@ -13,7 +13,7 @@ use rustc_middle::ty::cast::{CastTy, IntTy};
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, adjustment::PointerCoercion, Instance, Ty, TyCtxt};
use rustc_session::config::OptLevel;
-use rustc_span::source_map::{Span, DUMMY_SP};
+use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{self, FIRST_VARIANT};
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
@@ -239,17 +239,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
};
if let OperandValueKind::Immediate(out_scalar) = cast_kind
&& in_scalar.size(self.cx) == out_scalar.size(self.cx)
- {
- let operand_bty = bx.backend_type(operand.layout);
- let cast_bty = bx.backend_type(cast);
- Some(OperandValue::Immediate(self.transmute_immediate(
- bx,
- imm,
- in_scalar,
- operand_bty,
- out_scalar,
- cast_bty,
- )))
+ {
+ let operand_bty = bx.backend_type(operand.layout);
+ let cast_bty = bx.backend_type(cast);
+ Some(OperandValue::Immediate(self.transmute_immediate(
+ bx,
+ imm,
+ in_scalar,
+ operand_bty,
+ out_scalar,
+ cast_bty,
+ )))
} else {
None
}
@@ -680,7 +680,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
layout.align.abi.bytes()
}
mir::NullOp::OffsetOf(fields) => {
- layout.offset_of_subfield(bx.cx(), fields.iter().map(|f| f.index())).bytes()
+ layout.offset_of_subfield(bx.cx(), fields.iter()).bytes()
}
};
let val = bx.cx().const_usize(val);