2024-04-29 03:56:41 +00:00
|
|
|
use rustc_middle::mir::{self, NonDivergingIntrinsic};
|
|
|
|
use rustc_middle::span_bug;
|
2024-02-07 15:23:52 +00:00
|
|
|
use rustc_session::config::OptLevel;
|
2024-05-22 05:08:26 +00:00
|
|
|
use tracing::instrument;
|
2016-06-07 14:28:36 +00:00
|
|
|
|
2018-01-05 05:34:28 +00:00
|
|
|
use super::FunctionCx;
|
2016-06-20 20:55:14 +00:00
|
|
|
use super::LocalRef;
|
2019-02-09 14:31:47 +00:00
|
|
|
use crate::traits::*;
|
2015-10-21 21:42:25 +00:00
|
|
|
|
2019-06-14 16:39:39 +00:00
|
|
|
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
2022-06-29 09:56:30 +00:00
|
|
|
#[instrument(level = "debug", skip(self, bx))]
|
2022-11-09 00:04:10 +00:00
|
|
|
pub fn codegen_statement(&mut self, bx: &mut Bx, statement: &mir::Statement<'tcx>) {
|
|
|
|
self.set_debug_loc(bx, statement.source_info);
|
2015-10-21 21:42:25 +00:00
|
|
|
match statement.kind {
|
2019-09-11 19:05:45 +00:00
|
|
|
mir::StatementKind::Assign(box (ref place, ref rvalue)) => {
|
2019-10-20 20:09:36 +00:00
|
|
|
if let Some(index) = place.as_local() {
|
|
|
|
match self.locals[index] {
|
2018-05-08 13:10:16 +00:00
|
|
|
LocalRef::Place(cg_dest) => self.codegen_rvalue(bx, cg_dest, rvalue),
|
2018-05-28 15:12:55 +00:00
|
|
|
LocalRef::UnsizedPlace(cg_indirect_dest) => {
|
|
|
|
self.codegen_rvalue_unsized(bx, cg_indirect_dest, rvalue)
|
|
|
|
}
|
2023-03-25 03:36:59 +00:00
|
|
|
LocalRef::PendingOperand => {
|
2022-11-09 00:04:10 +00:00
|
|
|
let operand = self.codegen_rvalue_operand(bx, rvalue);
|
2023-06-09 11:13:31 +00:00
|
|
|
self.overwrite_local(index, LocalRef::Operand(operand));
|
2022-11-09 00:04:10 +00:00
|
|
|
self.debug_introduce_local(bx, index);
|
2016-06-20 20:55:14 +00:00
|
|
|
}
|
2023-03-25 03:36:59 +00:00
|
|
|
LocalRef::Operand(op) => {
|
2017-09-20 15:17:23 +00:00
|
|
|
if !op.layout.is_zst() {
|
2016-06-20 20:55:14 +00:00
|
|
|
span_bug!(
|
|
|
|
statement.source_info.span,
|
|
|
|
"operand {:?} already assigned",
|
|
|
|
rvalue
|
|
|
|
);
|
2015-11-02 14:39:59 +00:00
|
|
|
}
|
2017-09-20 15:17:23 +00:00
|
|
|
|
|
|
|
// If the type is zero-sized, it's already been set here,
|
2018-05-08 13:10:16 +00:00
|
|
|
// but we still need to make sure we codegen the operand
|
2022-11-09 00:04:10 +00:00
|
|
|
self.codegen_rvalue_operand(bx, rvalue);
|
2015-11-02 14:39:59 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-20 20:55:14 +00:00
|
|
|
} else {
|
2022-11-09 00:04:10 +00:00
|
|
|
let cg_dest = self.codegen_place(bx, place.as_ref());
|
|
|
|
self.codegen_rvalue(bx, cg_dest, rvalue);
|
2015-11-02 14:39:59 +00:00
|
|
|
}
|
2015-10-21 21:42:25 +00:00
|
|
|
}
|
2019-09-11 19:05:45 +00:00
|
|
|
mir::StatementKind::SetDiscriminant { box ref place, variant_index } => {
|
2022-11-09 00:04:10 +00:00
|
|
|
self.codegen_place(bx, place.as_ref()).codegen_set_discr(bx, variant_index);
|
2016-08-04 23:14:33 +00:00
|
|
|
}
|
2022-04-05 21:14:59 +00:00
|
|
|
mir::StatementKind::Deinit(..) => {
|
|
|
|
// For now, don't codegen this to anything. In the future it may be worth
|
|
|
|
// experimenting with what kind of information we can emit to LLVM without hurting
|
|
|
|
// perf here
|
|
|
|
}
|
2017-09-04 05:01:46 +00:00
|
|
|
mir::StatementKind::StorageLive(local) => {
|
2018-05-08 13:10:16 +00:00
|
|
|
if let LocalRef::Place(cg_place) = self.locals[local] {
|
2022-11-09 00:04:10 +00:00
|
|
|
cg_place.storage_live(bx);
|
2018-05-28 15:12:55 +00:00
|
|
|
} else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] {
|
2022-11-09 00:04:10 +00:00
|
|
|
cg_indirect_place.storage_live(bx);
|
2017-06-01 18:50:53 +00:00
|
|
|
}
|
2016-08-14 03:34:14 +00:00
|
|
|
}
|
2017-09-04 05:01:46 +00:00
|
|
|
mir::StatementKind::StorageDead(local) => {
|
2018-05-08 13:10:16 +00:00
|
|
|
if let LocalRef::Place(cg_place) = self.locals[local] {
|
2022-11-09 00:04:10 +00:00
|
|
|
cg_place.storage_dead(bx);
|
2018-05-28 15:12:55 +00:00
|
|
|
} else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] {
|
2022-11-09 00:04:10 +00:00
|
|
|
cg_indirect_place.storage_dead(bx);
|
2017-06-01 18:50:53 +00:00
|
|
|
}
|
2016-08-14 03:34:14 +00:00
|
|
|
}
|
2024-03-23 08:13:52 +00:00
|
|
|
mir::StatementKind::Coverage(ref kind) => {
|
|
|
|
self.codegen_coverage(bx, kind, statement.source_info.scope);
|
2020-08-15 11:42:13 +00:00
|
|
|
}
|
2022-07-12 10:05:00 +00:00
|
|
|
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(ref op)) => {
|
2024-02-07 15:23:52 +00:00
|
|
|
if !matches!(bx.tcx().sess.opts.optimize, OptLevel::No | OptLevel::Less) {
|
|
|
|
let op_val = self.codegen_operand(bx, op);
|
|
|
|
bx.assume(op_val.immediate());
|
|
|
|
}
|
2022-07-12 10:05:00 +00:00
|
|
|
}
|
|
|
|
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(
|
|
|
|
mir::CopyNonOverlapping { ref count, ref src, ref dst },
|
|
|
|
)) => {
|
2022-11-09 00:04:10 +00:00
|
|
|
let dst_val = self.codegen_operand(bx, dst);
|
|
|
|
let src_val = self.codegen_operand(bx, src);
|
|
|
|
let count = self.codegen_operand(bx, count).immediate();
|
2021-01-23 02:28:08 +00:00
|
|
|
let pointee_layout = dst_val
|
|
|
|
.layout
|
2022-11-09 00:04:10 +00:00
|
|
|
.pointee_info_at(bx, rustc_target::abi::Size::ZERO)
|
2021-01-23 02:28:08 +00:00
|
|
|
.expect("Expected pointer");
|
2021-01-23 03:55:41 +00:00
|
|
|
let bytes = bx.mul(count, bx.const_usize(pointee_layout.size.bytes()));
|
2021-01-23 02:28:08 +00:00
|
|
|
|
2021-01-23 03:55:41 +00:00
|
|
|
let align = pointee_layout.align;
|
|
|
|
let dst = dst_val.immediate();
|
|
|
|
let src = src_val.immediate();
|
|
|
|
bx.memcpy(dst, align, src, align, bytes, crate::MemFlags::empty());
|
2020-10-03 20:57:47 +00:00
|
|
|
}
|
2018-09-14 19:05:31 +00:00
|
|
|
mir::StatementKind::FakeRead(..)
|
2018-10-24 09:47:17 +00:00
|
|
|
| mir::StatementKind::Retag { .. }
|
2018-08-31 22:59:35 +00:00
|
|
|
| mir::StatementKind::AscribeUserType(..)
|
2022-12-20 00:51:17 +00:00
|
|
|
| mir::StatementKind::ConstEvalCounter
|
2022-09-06 16:41:01 +00:00
|
|
|
| mir::StatementKind::PlaceMention(..)
|
2022-11-09 00:04:10 +00:00
|
|
|
| mir::StatementKind::Nop => {}
|
2016-08-14 03:34:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-21 21:42:25 +00:00
|
|
|
}
|