CFG: force the creation of a predecessor entry for all basic block.

This ensure that all basic blocks in a function have a valid entry the CFG object.

The entry block has no predecessors but remains a valid basic block
for which we might want to query the number of predecessors.
Some unreachable basic blocks may not have predecessors as well.
This commit is contained in:
Victor Lomuller 2018-01-18 08:51:12 +00:00 committed by David Neto
parent 3604c0b71d
commit 0b1372a8ca

View File

@ -37,6 +37,9 @@ CFG::CFG(ir::Module* module)
for (auto& blk : fn) {
uint32_t blkId = blk.id();
id2block_[blkId] = &blk;
// Force the creation of an entry, not all basic block have predecessors
// (such as the entry block and some unreachables)
label2preds_[blkId];
blk.ForEachSuccessorLabel([&blkId, this](uint32_t sbid) {
label2preds_[sbid].push_back(blkId);
});