Reformat to better match existing style.

This commit is contained in:
Dejan Mircevski 2016-01-19 14:52:31 -05:00
parent cce6a8acaf
commit 159b59faa7

View File

@ -64,40 +64,41 @@ namespace {
// Traverses CFG in a readable order, invoking a pre-set callback on each block.
// Use by calling visit() on the root block.
class ReadableOrderTraverser {
public:
explicit ReadableOrderTraverser(std::function<void(Block*)> callback)
: callback_(callback) {}
// Visits the block if it hasn't been visited already and isn't currently
// being delayed. Invokes callback(block), then descends into its successors.
// Delays merge-block processing until all the branches have been completed.
void visit(Block* block) {
assert(block);
if (visited_[block] || delayed_[block]) return;
callback_(block);
visited_[block] = true;
Block* mergeBlock = nullptr;
auto mergeInst = block->getMergeInstruction();
if (mergeInst) {
Id mergeId = mergeInst->getIdOperand(0);
mergeBlock =
block->getParent().getParent().getInstruction(mergeId)->getBlock();
delayed_[mergeBlock] = true;
public:
explicit ReadableOrderTraverser(std::function<void(Block*)> callback) : callback_(callback) {}
// Visits the block if it hasn't been visited already and isn't currently
// being delayed. Invokes callback(block), then descends into its successors.
// Delays merge-block processing until all the branches have been completed.
void visit(Block* block)
{
assert(block);
if (visited_[block] || delayed_[block])
return;
callback_(block);
visited_[block] = true;
Block* mergeBlock = nullptr;
auto mergeInst = block->getMergeInstruction();
if (mergeInst) {
Id mergeId = mergeInst->getIdOperand(0);
mergeBlock = block->getParent().getParent().getInstruction(mergeId)->getBlock();
delayed_[mergeBlock] = true;
}
for (const auto succ : block->getSuccessors())
visit(succ);
if (mergeBlock) {
delayed_[mergeBlock] = false;
visit(mergeBlock);
}
}
for (const auto succ : block->getSuccessors()) visit(succ);
if (mergeBlock) {
delayed_[mergeBlock] = false;
visit(mergeBlock);
}
}
private:
std::function<void(Block*)> callback_;
// Whether a block has already been visited or is being delayed.
std::unordered_map<Block*, bool> visited_, delayed_;
private:
std::function<void(Block*)> callback_;
// Whether a block has already been visited or is being delayed.
std::unordered_map<Block *, bool> visited_, delayed_;
};
}
void spv::inReadableOrder(Block* root, std::function<void(Block*)> callback) {
ReadableOrderTraverser(callback).visit(root);
void spv::inReadableOrder(Block* root, std::function<void(Block*)> callback)
{
ReadableOrderTraverser(callback).visit(root);
}