This helps VisualStudio 2013 compile the code.
Contributes to #1262
}
}
+void CFG::AddEdges(ir::BasicBlock* blk) {
+ uint32_t blk_id = blk->id();
+ // Force the creation of an entry, not all basic block have predecessors
+ // (such as the entry blocks and some unreachables).
+ label2preds_[blk_id];
+ const auto* const_blk = blk;
+ const_blk->ForEachSuccessorLabel(
+ [blk_id, this](const uint32_t succ_id) { AddEdge(blk_id, succ_id); });
+}
+
void CFG::RemoveNonExistingEdges(uint32_t blk_id) {
std::vector<uint32_t> updated_pred_list;
for (uint32_t id : preds(blk_id)) {
- ir::BasicBlock* pred_blk = block(id);
+ const ir::BasicBlock* pred_blk = block(id);
bool has_branch = false;
pred_blk->ForEachSuccessorLabel([&has_branch, blk_id](uint32_t succ) {
if (succ == blk_id) has_branch = true;
}
// Add true successors.
- blk.ForEachSuccessorLabel([&blk, this](uint32_t sbid) {
+ const auto& const_blk = blk;
+ const_blk.ForEachSuccessorLabel([&blk, this](const uint32_t sbid) {
block2structured_succs_[&blk].push_back(id2block_[sbid]);
});
}
}
// Registers |blk| to all of its successors.
- void AddEdges(ir::BasicBlock* blk) {
- uint32_t blk_id = blk->id();
- // Force the creation of an entry, not all basic block have predecessors
- // (such as the entry blocks and some unreachables).
- label2preds_[blk_id];
- blk->ForEachSuccessorLabel(
- [blk_id, this](uint32_t succ_id) { AddEdge(blk_id, succ_id); });
- }
+ void AddEdges(ir::BasicBlock* blk);
// Registers the basic block id |pred_blk_id| as being a predecessor of the
// basic block id |succ_blk_id|.
}
}
// add true successors
- blk.ForEachSuccessorLabel([&blk, this](uint32_t sbid) {
+ const auto& const_blk = blk;
+ const_blk.ForEachSuccessorLabel([&blk, this](const uint32_t sbid) {
block2structured_succs_[&blk].push_back(cfg()->block(sbid));
});
}
stack.push_back(GetParentBlock(live_lab_id));
} else {
// All successors are live.
- block->ForEachSuccessorLabel([&stack, this](const uint32_t label) {
+ const auto* const_block = block;
+ const_block->ForEachSuccessorLabel([&stack, this](const uint32_t label) {
stack.push_back(GetParentBlock(label));
});
}
for (BasicBlock& bb : f) {
if (bb.hasSuccessor()) {
BasicBlockListTy& pred_list = predecessors_[&bb];
- bb.ForEachSuccessorLabel(
+ const auto& const_bb = bb;
+ const_bb.ForEachSuccessorLabel(
[this, &pred_list, &bb,
&GetSuccessorBasicBlock](const uint32_t successor_id) {
BasicBlock* succ = GetSuccessorBasicBlock(successor_id);
for (BasicBlock& bb : f) {
BasicBlockListTy& succ_list = successors_[&bb];
- bb.ForEachSuccessorLabel([&](const uint32_t successor_id) {
+ const auto& const_bb = bb;
+ const_bb.ForEachSuccessorLabel([&](const uint32_t successor_id) {
BasicBlock* succ = GetSuccessorBasicBlock(successor_id);
succ_list.push_back(succ);
predecessors_[succ].push_back(&bb);
const auto lastBlk = new_blocks.end() - 1;
const uint32_t firstId = (*firstBlk)->id();
const uint32_t lastId = (*lastBlk)->id();
- (*lastBlk)->ForEachSuccessorLabel([&firstId, &lastId, this](uint32_t succ) {
- ir::BasicBlock* sbp = this->id2block_[succ];
- sbp->ForEachPhiInst([&firstId, &lastId](ir::Instruction* phi) {
- phi->ForEachInId([&firstId, &lastId](uint32_t* id) {
- if (*id == firstId) *id = lastId;
+ const ir::BasicBlock& const_last_block = *lastBlk->get();
+ const_last_block.ForEachSuccessorLabel(
+ [&firstId, &lastId, this](const uint32_t succ) {
+ ir::BasicBlock* sbp = this->id2block_[succ];
+ sbp->ForEachPhiInst([&firstId, &lastId](ir::Instruction* phi) {
+ phi->ForEachInId([&firstId, &lastId](uint32_t* id) {
+ if (*id == firstId) *id = lastId;
+ });
+ });
});
- });
- });
}
bool InlinePass::HasMultipleReturns(ir::Function* func) {
}
// Add true successors.
- blk.ForEachSuccessorLabel([&blk, this](uint32_t sbid) {
+ const auto& const_blk = blk;
+ const_blk.ForEachSuccessorLabel([&blk, this](const uint32_t sbid) {
block2structured_succs_[&blk].push_back(id2block_[sbid]);
});
}
successors_map_.clear();
for (auto& blk : *func) {
ordered_blocks.push_back(&blk);
- blk.ForEachSuccessorLabel([&blk, this](uint32_t sbid) {
+ const auto& const_blk = blk;
+ const_blk.ForEachSuccessorLabel([&blk, this](const uint32_t sbid) {
successors_map_[&blk].push_back(label2block_[sbid]);
predecessors_map_[label2block_[sbid]].push_back(&blk);
});
// preheader.
bool is_preheader = true;
uint32_t loop_header_id = loop_header_->id();
- loop_pred->ForEachSuccessorLabel(
+ const auto* const_loop_pred = loop_pred;
+ const_loop_pred->ForEachSuccessorLabel(
[&is_preheader, loop_header_id](const uint32_t id) {
if (id != loop_header_id) is_preheader = false;
});
#ifndef NDEBUG
assert(latch->GetParent() && "The basic block does not belong to a function");
- latch->ForEachSuccessorLabel([this](uint32_t id) {
+ const auto* const_latch = latch;
+ const_latch->ForEachSuccessorLabel([this](uint32_t id) {
assert((!IsInsideLoop(id) || id == GetHeaderBlock()->id()) &&
"A predecessor of the continue block does not belong to the loop");
});
// Look for successor backedge and patch phis in loop header
// if found.
uint32_t header = 0;
- bp->ForEachSuccessorLabel([&header, this](uint32_t succ) {
+ const auto* const_bp = bp;
+ const_bp->ForEachSuccessorLabel([&header, this](uint32_t succ) {
if (visitedBlocks_.find(succ) == visitedBlocks_.end()) return;
assert(header == 0);
header = succ;
worklist.pop();
// All the successors of a live block are also live.
- block->ForEachSuccessorLabel(mark_reachable);
+ static_cast<const ir::BasicBlock*>(block)->ForEachSuccessorLabel(
+ mark_reachable);
// All the Merge and ContinueTarget blocks of a live block are also live.
block->ForMergeAndContinueLabel(mark_reachable);
Edge(ctx_->cfg()->pseudo_entry_block(), fn->entry().get()));
for (auto& block : *fn) {
- block.ForEachSuccessorLabel([this, &block](uint32_t label_id) {
+ const auto& const_block = block;
+ const_block.ForEachSuccessorLabel([this, &block](const uint32_t label_id) {
ir::BasicBlock* succ_bb =
ctx_->get_instr_block(get_def_use_mgr()->GetDef(label_id));
bb_succs_[&block].push_back(Edge(&block, succ_bb));