MIR: Refactor mir::Terminator to use tuples instead of a fixed-size arrays.
This commit is contained in:
parent
d62de4c066
commit
33d29700b3
@ -13,6 +13,7 @@ use middle::def_id::DefId;
|
||||
use middle::subst::Substs;
|
||||
use middle::ty::{AdtDef, ClosureSubsts, FnOutput, Region, Ty};
|
||||
use rustc_back::slice;
|
||||
use rustc_data_structures::tuple_slice::TupleSlice;
|
||||
use rustc_front::hir::InlineAsm;
|
||||
use syntax::ast::Name;
|
||||
use syntax::codemap::Span;
|
||||
@ -206,7 +207,7 @@ pub enum Terminator<'tcx> {
|
||||
/// jump to branch 0 if this lvalue evaluates to true
|
||||
If {
|
||||
cond: Operand<'tcx>,
|
||||
targets: [BasicBlock; 2],
|
||||
targets: (BasicBlock, BasicBlock),
|
||||
},
|
||||
|
||||
/// lvalue evaluates to some enum; jump depending on the branch
|
||||
@ -254,7 +255,7 @@ pub enum Terminator<'tcx> {
|
||||
/// unwinding.
|
||||
Call {
|
||||
data: CallData<'tcx>,
|
||||
targets: [BasicBlock; 2],
|
||||
targets: (BasicBlock, BasicBlock),
|
||||
},
|
||||
}
|
||||
|
||||
@ -264,12 +265,12 @@ impl<'tcx> Terminator<'tcx> {
|
||||
match *self {
|
||||
Goto { target: ref b } => slice::ref_slice(b),
|
||||
Panic { target: ref b } => slice::ref_slice(b),
|
||||
If { cond: _, targets: ref b } => b,
|
||||
If { cond: _, targets: ref b } => b.as_slice(),
|
||||
Switch { targets: ref b, .. } => b,
|
||||
SwitchInt { targets: ref b, .. } => b,
|
||||
Diverge => &[],
|
||||
Return => &[],
|
||||
Call { data: _, targets: ref b } => b,
|
||||
Call { data: _, targets: ref b } => b.as_slice(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,12 +279,12 @@ impl<'tcx> Terminator<'tcx> {
|
||||
match *self {
|
||||
Goto { target: ref mut b } => slice::mut_ref_slice(b),
|
||||
Panic { target: ref mut b } => slice::mut_ref_slice(b),
|
||||
If { cond: _, targets: ref mut b } => b,
|
||||
If { cond: _, targets: ref mut b } => b.as_mut_slice(),
|
||||
Switch { targets: ref mut b, .. } => b,
|
||||
SwitchInt { targets: ref mut b, .. } => b,
|
||||
Diverge => &mut [],
|
||||
Return => &mut [],
|
||||
Call { data: _, targets: ref mut b } => b,
|
||||
Call { data: _, targets: ref mut b } => b.as_mut_slice(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
use middle::ty::Region;
|
||||
use mir::repr::*;
|
||||
use rustc_data_structures::tuple_slice::TupleSlice;
|
||||
|
||||
pub trait Visitor<'tcx> {
|
||||
// Override these, and call `self.super_xxx` to revert back to the
|
||||
@ -97,7 +98,7 @@ pub trait Visitor<'tcx> {
|
||||
|
||||
Terminator::If { ref cond, ref targets } => {
|
||||
self.visit_operand(cond);
|
||||
for &target in &targets[..] {
|
||||
for &target in targets.as_slice() {
|
||||
self.visit_branch(block, target);
|
||||
}
|
||||
}
|
||||
@ -126,7 +127,7 @@ pub trait Visitor<'tcx> {
|
||||
for arg in &data.args {
|
||||
self.visit_operand(arg);
|
||||
}
|
||||
for &target in &targets[..] {
|
||||
for &target in targets.as_slice() {
|
||||
self.visit_branch(block, target);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
||||
this.cfg.terminate(block,
|
||||
Terminator::If {
|
||||
cond: Operand::Consume(lt),
|
||||
targets: [success, failure],
|
||||
targets: (success, failure),
|
||||
});
|
||||
this.panic(failure);
|
||||
success.and(slice.index(idx))
|
||||
|
@ -53,7 +53,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
||||
let mut else_block = this.cfg.start_new_block();
|
||||
this.cfg.terminate(block, Terminator::If {
|
||||
cond: operand,
|
||||
targets: [then_block, else_block]
|
||||
targets: (then_block, else_block)
|
||||
});
|
||||
|
||||
unpack!(then_block = this.into(destination, then_block, then_expr));
|
||||
@ -84,15 +84,15 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
||||
|
||||
let lhs = unpack!(block = this.as_operand(block, lhs));
|
||||
let blocks = match op {
|
||||
LogicalOp::And => [else_block, false_block],
|
||||
LogicalOp::Or => [true_block, else_block],
|
||||
LogicalOp::And => (else_block, false_block),
|
||||
LogicalOp::Or => (true_block, else_block),
|
||||
};
|
||||
this.cfg.terminate(block, Terminator::If { cond: lhs, targets: blocks });
|
||||
|
||||
let rhs = unpack!(else_block = this.as_operand(else_block, rhs));
|
||||
this.cfg.terminate(else_block, Terminator::If {
|
||||
cond: rhs,
|
||||
targets: [true_block, false_block]
|
||||
targets: (true_block, false_block)
|
||||
});
|
||||
|
||||
this.cfg.push_assign_constant(
|
||||
@ -149,7 +149,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
||||
this.cfg.terminate(loop_block_end,
|
||||
Terminator::If {
|
||||
cond: cond,
|
||||
targets: [body_block, exit_block]
|
||||
targets: (body_block, exit_block)
|
||||
});
|
||||
} else {
|
||||
body_block = loop_block;
|
||||
@ -225,7 +225,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
||||
func: fun,
|
||||
args: args,
|
||||
},
|
||||
targets: [success, panic],
|
||||
targets: (success, panic),
|
||||
});
|
||||
success.unit()
|
||||
}
|
||||
|
@ -555,7 +555,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
||||
let cond = unpack!(block = self.as_operand(block, guard));
|
||||
let otherwise = self.cfg.start_new_block();
|
||||
self.cfg.terminate(block, Terminator::If { cond: cond,
|
||||
targets: [arm_block, otherwise]});
|
||||
targets: (arm_block, otherwise)});
|
||||
Some(otherwise)
|
||||
} else {
|
||||
self.cfg.terminate(block, Terminator::Goto { target: arm_block });
|
||||
|
@ -232,7 +232,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
||||
self.cfg.start_new_block()];
|
||||
self.cfg.terminate(block, Terminator::If {
|
||||
cond: Operand::Consume(result),
|
||||
targets: [target_blocks[0], target_blocks[1]]
|
||||
targets: (target_blocks[0], target_blocks[1])
|
||||
});
|
||||
|
||||
target_blocks
|
||||
@ -252,7 +252,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
||||
let bool_ty = self.hir.bool_ty();
|
||||
let eq_result = self.temp(bool_ty);
|
||||
let func = self.item_ref_operand(span, item_ref);
|
||||
let call_blocks = [self.cfg.start_new_block(), self.diverge_cleanup()];
|
||||
let call_blocks = (self.cfg.start_new_block(), self.diverge_cleanup());
|
||||
self.cfg.terminate(block,
|
||||
Terminator::Call {
|
||||
data: CallData {
|
||||
@ -264,10 +264,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
||||
});
|
||||
|
||||
// check the result
|
||||
self.cfg.terminate(call_blocks[0],
|
||||
self.cfg.terminate(call_blocks.0,
|
||||
Terminator::If {
|
||||
cond: Operand::Consume(eq_result),
|
||||
targets: [target_blocks[0], target_blocks[1]],
|
||||
targets: (target_blocks[0], target_blocks[1]),
|
||||
});
|
||||
|
||||
target_blocks
|
||||
|
@ -96,9 +96,9 @@ impl SimplifyCfg {
|
||||
mem::swap(&mut terminator, &mut mir.basic_block_data_mut(bb).terminator);
|
||||
|
||||
mir.basic_block_data_mut(bb).terminator = match terminator {
|
||||
Terminator::If { ref targets, .. } if targets[0] == targets[1] => {
|
||||
Terminator::If { ref targets, .. } if targets.0 == targets.1 => {
|
||||
changed = true;
|
||||
Terminator::Goto { target: targets[0] }
|
||||
Terminator::Goto { target: targets.0 }
|
||||
}
|
||||
Terminator::If { ref targets, cond: Operand::Constant(Constant {
|
||||
literal: Literal::Value {
|
||||
@ -106,8 +106,11 @@ impl SimplifyCfg {
|
||||
}, ..
|
||||
}) } => {
|
||||
changed = true;
|
||||
let target_idx = if cond { 0 } else { 1 };
|
||||
Terminator::Goto { target: targets[target_idx] }
|
||||
if cond {
|
||||
Terminator::Goto { target: targets.0 }
|
||||
} else {
|
||||
Terminator::Goto { target: targets.1 }
|
||||
}
|
||||
}
|
||||
Terminator::SwitchInt { ref targets, .. } if targets.len() == 1 => {
|
||||
Terminator::Goto { target: targets[0] }
|
||||
|
@ -39,7 +39,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
mir::Terminator::If { ref cond, targets: [true_bb, false_bb] } => {
|
||||
mir::Terminator::If { ref cond, targets: (true_bb, false_bb) } => {
|
||||
let cond = self.trans_operand(bcx, cond);
|
||||
let lltrue = self.llblock(true_bb);
|
||||
let llfalse = self.llblock(false_bb);
|
||||
|
Loading…
x
Reference in New Issue
Block a user