Promote the BasicBlock tuple to a real struct;

It makes reading code that uses it easier to understand.
This commit is contained in:
Benjamin Bouvier
2018-07-19 15:29:29 +02:00
committed by Dan Gohman
parent ce177d643e
commit f72ff791b4
12 changed files with 127 additions and 50 deletions

View File

@@ -9,7 +9,7 @@ use cursor::{Cursor, EncCursor};
#[cfg(feature = "std")]
use dbg::DisplayList;
use dominator_tree::{DominatorTree, DominatorTreePreorder};
use flowgraph::ControlFlowGraph;
use flowgraph::{BasicBlock, ControlFlowGraph};
use fx::FxHashMap;
use ir::{self, InstBuilder, ProgramOrder};
use ir::{Ebb, ExpandedProgramPoint, Function, Inst, Value};
@@ -174,7 +174,11 @@ impl<'a> Context<'a> {
debug_assert_eq!(num_params, self.func.dfg.num_ebb_params(ebb));
// The only way a parameter value can interfere with a predecessor branch is if the EBB is
// dominating the predecessor branch. That is, we are looking for loop back-edges.
for (pred_ebb, pred_inst) in self.cfg.pred_iter(ebb) {
for BasicBlock {
ebb: pred_ebb,
inst: pred_inst,
} in self.cfg.pred_iter(ebb)
{
// The quick pre-order dominance check is accurate because the EBB parameter is defined
// at the top of the EBB before any branches.
if !self.preorder.dominates(ebb, pred_ebb) {
@@ -211,7 +215,11 @@ impl<'a> Context<'a> {
fn union_pred_args(&mut self, ebb: Ebb, argnum: usize) {
let param = self.func.dfg.ebb_params(ebb)[argnum];
for (pred_ebb, pred_inst) in self.cfg.pred_iter(ebb) {
for BasicBlock {
ebb: pred_ebb,
inst: pred_inst,
} in self.cfg.pred_iter(ebb)
{
let arg = self.func.dfg.inst_variable_args(pred_inst)[argnum];
// Never coalesce incoming function parameters on the stack. These parameters are
@@ -484,7 +492,11 @@ impl<'a> Context<'a> {
// not loop backedges.
debug_assert!(self.predecessors.is_empty());
debug_assert!(self.backedges.is_empty());
for (pred_ebb, pred_inst) in self.cfg.pred_iter(ebb) {
for BasicBlock {
ebb: pred_ebb,
inst: pred_inst,
} in self.cfg.pred_iter(ebb)
{
if self.preorder.dominates(ebb, pred_ebb) {
self.backedges.push(pred_inst);
} else {
@@ -915,7 +927,10 @@ impl VirtualCopies {
}
// This EBB hasn't been seen before.
for (_, pred_inst) in cfg.pred_iter(ebb) {
for BasicBlock {
inst: pred_inst, ..
} in cfg.pred_iter(ebb)
{
self.branches.push((pred_inst, ebb));
}
last_ebb = Some(ebb);

View File

@@ -176,7 +176,7 @@
//! There is some room for improvement.
use entity::SparseMap;
use flowgraph::ControlFlowGraph;
use flowgraph::{BasicBlock, ControlFlowGraph};
use ir::dfg::ValueDef;
use ir::{Ebb, Function, Inst, Layout, ProgramPoint, Value};
use isa::{EncInfo, OperandConstraint, TargetIsa};
@@ -272,7 +272,11 @@ fn extend_to_use(
while let Some(livein) = worklist.pop() {
// We've learned that the value needs to be live-in to the `livein` EBB.
// Make sure it is also live at all predecessor branches to `livein`.
for (pred, branch) in cfg.pred_iter(livein) {
for BasicBlock {
ebb: pred,
inst: branch,
} in cfg.pred_iter(livein)
{
if lr.extend_in_ebb(pred, branch, &func.layout, forest) {
// This predecessor EBB also became live-in. We need to process it later.
worklist.push(pred);