]>
Commit | Line | Data |
---|---|---|
ba9703b0 | 1 | use rustc_middle::mir; |
f2b60f7d | 2 | use rustc_middle::mir::NonDivergingIntrinsic; |
3157f602 | 3 | |
2c00a5a8 | 4 | use super::FunctionCx; |
3157f602 | 5 | use super::LocalRef; |
dfeec247 | 6 | use crate::traits::BuilderMethods; |
9fa01778 | 7 | use crate::traits::*; |
92a42be0 | 8 | |
dc9dc135 | 9 | impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { |
064997fb | 10 | #[instrument(level = "debug", skip(self, bx))] |
487cf647 FG |
11 | pub fn codegen_statement(&mut self, bx: &mut Bx, statement: &mir::Statement<'tcx>) { |
12 | self.set_debug_loc(bx, statement.source_info); | |
92a42be0 | 13 | match statement.kind { |
dfeec247 | 14 | mir::StatementKind::Assign(box (ref place, ref rvalue)) => { |
e74abb32 XL |
15 | if let Some(index) = place.as_local() { |
16 | match self.locals[index] { | |
dfeec247 | 17 | LocalRef::Place(cg_dest) => self.codegen_rvalue(bx, cg_dest, rvalue), |
b7449926 XL |
18 | LocalRef::UnsizedPlace(cg_indirect_dest) => { |
19 | self.codegen_rvalue_unsized(bx, cg_indirect_dest, rvalue) | |
20 | } | |
3157f602 | 21 | LocalRef::Operand(None) => { |
487cf647 | 22 | let operand = self.codegen_rvalue_operand(bx, rvalue); |
e74abb32 | 23 | self.locals[index] = LocalRef::Operand(Some(operand)); |
487cf647 | 24 | self.debug_introduce_local(bx, index); |
3157f602 | 25 | } |
ff7c6d11 XL |
26 | LocalRef::Operand(Some(op)) => { |
27 | if !op.layout.is_zst() { | |
dfeec247 XL |
28 | span_bug!( |
29 | statement.source_info.span, | |
30 | "operand {:?} already assigned", | |
31 | rvalue | |
32 | ); | |
92a42be0 | 33 | } |
ff7c6d11 XL |
34 | |
35 | // If the type is zero-sized, it's already been set here, | |
94b46f34 | 36 | // but we still need to make sure we codegen the operand |
487cf647 | 37 | self.codegen_rvalue_operand(bx, rvalue); |
92a42be0 SL |
38 | } |
39 | } | |
3157f602 | 40 | } else { |
487cf647 FG |
41 | let cg_dest = self.codegen_place(bx, place.as_ref()); |
42 | self.codegen_rvalue(bx, cg_dest, rvalue); | |
92a42be0 SL |
43 | } |
44 | } | |
dfeec247 | 45 | mir::StatementKind::SetDiscriminant { box ref place, variant_index } => { |
487cf647 | 46 | self.codegen_place(bx, place.as_ref()).codegen_set_discr(bx, variant_index); |
5bcae85e | 47 | } |
04454e1e FG |
48 | mir::StatementKind::Deinit(..) => { |
49 | // For now, don't codegen this to anything. In the future it may be worth | |
50 | // experimenting with what kind of information we can emit to LLVM without hurting | |
51 | // perf here | |
04454e1e | 52 | } |
ea8adc8c | 53 | mir::StatementKind::StorageLive(local) => { |
94b46f34 | 54 | if let LocalRef::Place(cg_place) = self.locals[local] { |
487cf647 | 55 | cg_place.storage_live(bx); |
b7449926 | 56 | } else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] { |
487cf647 | 57 | cg_indirect_place.storage_live(bx); |
ff7c6d11 | 58 | } |
5bcae85e | 59 | } |
ea8adc8c | 60 | mir::StatementKind::StorageDead(local) => { |
94b46f34 | 61 | if let LocalRef::Place(cg_place) = self.locals[local] { |
487cf647 | 62 | cg_place.storage_dead(bx); |
b7449926 | 63 | } else if let LocalRef::UnsizedPlace(cg_indirect_place) = self.locals[local] { |
487cf647 | 64 | cg_indirect_place.storage_dead(bx); |
ff7c6d11 | 65 | } |
5bcae85e | 66 | } |
3dfed10e | 67 | mir::StatementKind::Coverage(box ref coverage) => { |
487cf647 | 68 | self.codegen_coverage(bx, coverage.clone(), statement.source_info.scope); |
6a06907d | 69 | } |
f2b60f7d | 70 | mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(ref op)) => { |
487cf647 | 71 | let op_val = self.codegen_operand(bx, op); |
f2b60f7d | 72 | bx.assume(op_val.immediate()); |
f2b60f7d FG |
73 | } |
74 | mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping( | |
75 | mir::CopyNonOverlapping { ref count, ref src, ref dst }, | |
76 | )) => { | |
487cf647 FG |
77 | let dst_val = self.codegen_operand(bx, dst); |
78 | let src_val = self.codegen_operand(bx, src); | |
79 | let count = self.codegen_operand(bx, count).immediate(); | |
6a06907d XL |
80 | let pointee_layout = dst_val |
81 | .layout | |
487cf647 | 82 | .pointee_info_at(bx, rustc_target::abi::Size::ZERO) |
6a06907d XL |
83 | .expect("Expected pointer"); |
84 | let bytes = bx.mul(count, bx.const_usize(pointee_layout.size.bytes())); | |
85 | ||
86 | let align = pointee_layout.align; | |
87 | let dst = dst_val.immediate(); | |
88 | let src = src_val.immediate(); | |
89 | bx.memcpy(dst, align, src, align, bytes, crate::MemFlags::empty()); | |
3dfed10e | 90 | } |
dfeec247 XL |
91 | mir::StatementKind::FakeRead(..) |
92 | | mir::StatementKind::Retag { .. } | |
93 | | mir::StatementKind::AscribeUserType(..) | |
9ffffee4 | 94 | | mir::StatementKind::ConstEvalCounter |
487cf647 | 95 | | mir::StatementKind::Nop => {} |
5bcae85e SL |
96 | } |
97 | } | |
92a42be0 | 98 | } |