rustc_mir: use Local instead of Lvalue in Storage{Live,Dead}.
This commit is contained in:
parent
2f42cd8489
commit
e74f96e43f
13 changed files with 38 additions and 54 deletions
|
@ -901,10 +901,10 @@ pub enum StatementKind<'tcx> {
|
||||||
SetDiscriminant { lvalue: Lvalue<'tcx>, variant_index: usize },
|
SetDiscriminant { lvalue: Lvalue<'tcx>, variant_index: usize },
|
||||||
|
|
||||||
/// Start a live range for the storage of the local.
|
/// Start a live range for the storage of the local.
|
||||||
StorageLive(Lvalue<'tcx>),
|
StorageLive(Local),
|
||||||
|
|
||||||
/// End the current live range for the storage of the local.
|
/// End the current live range for the storage of the local.
|
||||||
StorageDead(Lvalue<'tcx>),
|
StorageDead(Local),
|
||||||
|
|
||||||
/// Execute a piece of inline Assembly.
|
/// Execute a piece of inline Assembly.
|
||||||
InlineAsm {
|
InlineAsm {
|
||||||
|
@ -1701,8 +1701,8 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
|
||||||
lvalue: lvalue.fold_with(folder),
|
lvalue: lvalue.fold_with(folder),
|
||||||
variant_index,
|
variant_index,
|
||||||
},
|
},
|
||||||
StorageLive(ref lval) => StorageLive(lval.fold_with(folder)),
|
StorageLive(ref local) => StorageLive(local.fold_with(folder)),
|
||||||
StorageDead(ref lval) => StorageDead(lval.fold_with(folder)),
|
StorageDead(ref local) => StorageDead(local.fold_with(folder)),
|
||||||
InlineAsm { ref asm, ref outputs, ref inputs } => InlineAsm {
|
InlineAsm { ref asm, ref outputs, ref inputs } => InlineAsm {
|
||||||
asm: asm.clone(),
|
asm: asm.clone(),
|
||||||
outputs: outputs.fold_with(folder),
|
outputs: outputs.fold_with(folder),
|
||||||
|
@ -1732,9 +1732,9 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
|
||||||
|
|
||||||
match self.kind {
|
match self.kind {
|
||||||
Assign(ref lval, ref rval) => { lval.visit_with(visitor) || rval.visit_with(visitor) }
|
Assign(ref lval, ref rval) => { lval.visit_with(visitor) || rval.visit_with(visitor) }
|
||||||
SetDiscriminant { ref lvalue, .. } |
|
SetDiscriminant { ref lvalue, .. } => lvalue.visit_with(visitor),
|
||||||
StorageLive(ref lvalue) |
|
StorageLive(ref local) |
|
||||||
StorageDead(ref lvalue) => lvalue.visit_with(visitor),
|
StorageDead(ref local) => local.visit_with(visitor),
|
||||||
InlineAsm { ref outputs, ref inputs, .. } =>
|
InlineAsm { ref outputs, ref inputs, .. } =>
|
||||||
outputs.visit_with(visitor) || inputs.visit_with(visitor),
|
outputs.visit_with(visitor) || inputs.visit_with(visitor),
|
||||||
|
|
||||||
|
|
|
@ -360,11 +360,11 @@ macro_rules! make_mir_visitor {
|
||||||
StatementKind::SetDiscriminant{ ref $($mutability)* lvalue, .. } => {
|
StatementKind::SetDiscriminant{ ref $($mutability)* lvalue, .. } => {
|
||||||
self.visit_lvalue(lvalue, LvalueContext::Store, location);
|
self.visit_lvalue(lvalue, LvalueContext::Store, location);
|
||||||
}
|
}
|
||||||
StatementKind::StorageLive(ref $($mutability)* lvalue) => {
|
StatementKind::StorageLive(ref $($mutability)* local) => {
|
||||||
self.visit_lvalue(lvalue, LvalueContext::StorageLive, location);
|
self.visit_local(local, LvalueContext::StorageLive, location);
|
||||||
}
|
}
|
||||||
StatementKind::StorageDead(ref $($mutability)* lvalue) => {
|
StatementKind::StorageDead(ref $($mutability)* local) => {
|
||||||
self.visit_lvalue(lvalue, LvalueContext::StorageDead, location);
|
self.visit_local(local, LvalueContext::StorageDead, location);
|
||||||
}
|
}
|
||||||
StatementKind::InlineAsm { ref $($mutability)* outputs,
|
StatementKind::InlineAsm { ref $($mutability)* outputs,
|
||||||
ref $($mutability)* inputs,
|
ref $($mutability)* inputs,
|
||||||
|
|
|
@ -212,11 +212,11 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> DataflowResultsConsumer<'b, 'gcx>
|
||||||
// ignored by borrowck
|
// ignored by borrowck
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementKind::StorageDead(ref lvalue) => {
|
StatementKind::StorageDead(local) => {
|
||||||
// causes non-drop values to be dropped.
|
// causes non-drop values to be dropped.
|
||||||
self.consume_lvalue(ContextKind::StorageDead.new(location),
|
self.consume_lvalue(ContextKind::StorageDead.new(location),
|
||||||
ConsumeKind::Consume,
|
ConsumeKind::Consume,
|
||||||
(lvalue, span),
|
(&Lvalue::Local(local), span),
|
||||||
flow_state)
|
flow_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,23 +96,23 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
ExprKind::Box { value } => {
|
ExprKind::Box { value } => {
|
||||||
let value = this.hir.mirror(value);
|
let value = this.hir.mirror(value);
|
||||||
let result = this.temp(expr.ty, expr_span);
|
let result = this.local_decls.push(LocalDecl::new_temp(expr.ty, expr_span));
|
||||||
this.cfg.push(block, Statement {
|
this.cfg.push(block, Statement {
|
||||||
source_info,
|
source_info,
|
||||||
kind: StatementKind::StorageLive(result.clone())
|
kind: StatementKind::StorageLive(result)
|
||||||
});
|
});
|
||||||
if let Some(scope) = scope {
|
if let Some(scope) = scope {
|
||||||
// schedule a shallow free of that memory, lest we unwind:
|
// schedule a shallow free of that memory, lest we unwind:
|
||||||
this.schedule_drop(expr_span, scope, &result, value.ty);
|
this.schedule_drop(expr_span, scope, &Lvalue::Local(result), value.ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// malloc some memory of suitable type (thus far, uninitialized):
|
// malloc some memory of suitable type (thus far, uninitialized):
|
||||||
let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty);
|
let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty);
|
||||||
this.cfg.push_assign(block, source_info, &result, box_);
|
this.cfg.push_assign(block, source_info, &Lvalue::Local(result), box_);
|
||||||
|
|
||||||
// initialize the box contents:
|
// initialize the box contents:
|
||||||
unpack!(block = this.into(&result.clone().deref(), block, value));
|
unpack!(block = this.into(&Lvalue::Local(result).deref(), block, value));
|
||||||
block.and(Rvalue::Use(Operand::Consume(result)))
|
block.and(Rvalue::Use(Operand::Consume(Lvalue::Local(result))))
|
||||||
}
|
}
|
||||||
ExprKind::Cast { source } => {
|
ExprKind::Cast { source } => {
|
||||||
let source = this.hir.mirror(source);
|
let source = this.hir.mirror(source);
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
if !expr_ty.is_never() {
|
if !expr_ty.is_never() {
|
||||||
this.cfg.push(block, Statement {
|
this.cfg.push(block, Statement {
|
||||||
source_info,
|
source_info,
|
||||||
kind: StatementKind::StorageLive(Lvalue::Local(temp))
|
kind: StatementKind::StorageLive(temp)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
let source_info = self.source_info(span);
|
let source_info = self.source_info(span);
|
||||||
self.cfg.push(block, Statement {
|
self.cfg.push(block, Statement {
|
||||||
source_info,
|
source_info,
|
||||||
kind: StatementKind::StorageLive(Lvalue::Local(local_id))
|
kind: StatementKind::StorageLive(local_id)
|
||||||
});
|
});
|
||||||
Lvalue::Local(local_id)
|
Lvalue::Local(local_id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -822,7 +822,7 @@ fn build_scope_drops<'tcx>(cfg: &mut CFG<'tcx>,
|
||||||
Lvalue::Local(index) if index.index() > arg_count => {
|
Lvalue::Local(index) if index.index() > arg_count => {
|
||||||
cfg.push(block, Statement {
|
cfg.push(block, Statement {
|
||||||
source_info,
|
source_info,
|
||||||
kind: StatementKind::StorageDead(drop_data.location.clone())
|
kind: StatementKind::StorageDead(index)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => continue
|
_ => continue
|
||||||
|
|
|
@ -213,12 +213,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> {
|
||||||
// Remove StorageLive and StorageDead statements for remapped locals
|
// Remove StorageLive and StorageDead statements for remapped locals
|
||||||
data.retain_statements(|s| {
|
data.retain_statements(|s| {
|
||||||
match s.kind {
|
match s.kind {
|
||||||
StatementKind::StorageLive(ref l) | StatementKind::StorageDead(ref l) => {
|
StatementKind::StorageLive(l) | StatementKind::StorageDead(l) => {
|
||||||
if let Lvalue::Local(l) = *l {
|
!self.remap.contains_key(&l)
|
||||||
!self.remap.contains_key(&l)
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => true
|
_ => true
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,8 +406,8 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
|
||||||
block.statements.retain(|statement| {
|
block.statements.retain(|statement| {
|
||||||
match statement.kind {
|
match statement.kind {
|
||||||
StatementKind::Assign(Lvalue::Local(index), _) |
|
StatementKind::Assign(Lvalue::Local(index), _) |
|
||||||
StatementKind::StorageLive(Lvalue::Local(index)) |
|
StatementKind::StorageLive(index) |
|
||||||
StatementKind::StorageDead(Lvalue::Local(index)) => {
|
StatementKind::StorageDead(index) => {
|
||||||
!promoted(index)
|
!promoted(index)
|
||||||
}
|
}
|
||||||
_ => true
|
_ => true
|
||||||
|
|
|
@ -1108,7 +1108,7 @@ impl MirPass for QualifyAndPromoteConstants {
|
||||||
for block in mir.basic_blocks_mut() {
|
for block in mir.basic_blocks_mut() {
|
||||||
block.statements.retain(|statement| {
|
block.statements.retain(|statement| {
|
||||||
match statement.kind {
|
match statement.kind {
|
||||||
StatementKind::StorageDead(Lvalue::Local(index)) => {
|
StatementKind::StorageDead(index) => {
|
||||||
!promoted_temps.contains(&index)
|
!promoted_temps.contains(&index)
|
||||||
}
|
}
|
||||||
_ => true
|
_ => true
|
||||||
|
|
|
@ -369,11 +369,8 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater {
|
||||||
// Remove unnecessary StorageLive and StorageDead annotations.
|
// Remove unnecessary StorageLive and StorageDead annotations.
|
||||||
data.statements.retain(|stmt| {
|
data.statements.retain(|stmt| {
|
||||||
match stmt.kind {
|
match stmt.kind {
|
||||||
StatementKind::StorageLive(ref lval) | StatementKind::StorageDead(ref lval) => {
|
StatementKind::StorageLive(l) | StatementKind::StorageDead(l) => {
|
||||||
match *lval {
|
self.map[l.index()] != !0
|
||||||
Lvalue::Local(l) => self.map[l.index()] != !0,
|
|
||||||
_ => true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => true
|
_ => true
|
||||||
}
|
}
|
||||||
|
|
|
@ -420,15 +420,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
||||||
variant_index);
|
variant_index);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
StatementKind::StorageLive(ref lv) |
|
StatementKind::StorageLive(_) |
|
||||||
StatementKind::StorageDead(ref lv) => {
|
StatementKind::StorageDead(_) |
|
||||||
match *lv {
|
|
||||||
Lvalue::Local(_) => {}
|
|
||||||
_ => {
|
|
||||||
span_mirbug!(self, stmt, "bad lvalue: expected local");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
StatementKind::InlineAsm { .. } |
|
StatementKind::InlineAsm { .. } |
|
||||||
StatementKind::EndRegion(_) |
|
StatementKind::EndRegion(_) |
|
||||||
StatementKind::Validate(..) |
|
StatementKind::Validate(..) |
|
||||||
|
|
|
@ -67,11 +67,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
||||||
variant_index as u64);
|
variant_index as u64);
|
||||||
bcx
|
bcx
|
||||||
}
|
}
|
||||||
mir::StatementKind::StorageLive(ref lvalue) => {
|
mir::StatementKind::StorageLive(local) => {
|
||||||
self.trans_storage_liveness(bcx, lvalue, base::Lifetime::Start)
|
self.trans_storage_liveness(bcx, local, base::Lifetime::Start)
|
||||||
}
|
}
|
||||||
mir::StatementKind::StorageDead(ref lvalue) => {
|
mir::StatementKind::StorageDead(local) => {
|
||||||
self.trans_storage_liveness(bcx, lvalue, base::Lifetime::End)
|
self.trans_storage_liveness(bcx, local, base::Lifetime::End)
|
||||||
}
|
}
|
||||||
mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
|
mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
|
||||||
let outputs = outputs.iter().map(|output| {
|
let outputs = outputs.iter().map(|output| {
|
||||||
|
@ -94,13 +94,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
||||||
|
|
||||||
fn trans_storage_liveness(&self,
|
fn trans_storage_liveness(&self,
|
||||||
bcx: Builder<'a, 'tcx>,
|
bcx: Builder<'a, 'tcx>,
|
||||||
lvalue: &mir::Lvalue<'tcx>,
|
index: mir::Local,
|
||||||
intrinsic: base::Lifetime)
|
intrinsic: base::Lifetime)
|
||||||
-> Builder<'a, 'tcx> {
|
-> Builder<'a, 'tcx> {
|
||||||
if let mir::Lvalue::Local(index) = *lvalue {
|
if let LocalRef::Lvalue(tr_lval) = self.locals[index] {
|
||||||
if let LocalRef::Lvalue(tr_lval) = self.locals[index] {
|
intrinsic.call(&bcx, tr_lval.llval);
|
||||||
intrinsic.call(&bcx, tr_lval.llval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bcx
|
bcx
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue