Merge pull request #886 from antiagainst/unordered-set
Use unordered_set in ReadableOrderTraverser.
This commit is contained in:
commit
c48c8e76e1
@ -51,7 +51,7 @@
|
|||||||
#include "spvIR.h"
|
#include "spvIR.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <unordered_map>
|
#include <unordered_set>
|
||||||
|
|
||||||
using spv::Block;
|
using spv::Block;
|
||||||
using spv::Id;
|
using spv::Id;
|
||||||
@ -69,33 +69,33 @@ public:
|
|||||||
void visit(Block* block)
|
void visit(Block* block)
|
||||||
{
|
{
|
||||||
assert(block);
|
assert(block);
|
||||||
if (visited_[block] || delayed_[block])
|
if (visited_.count(block) || delayed_.count(block))
|
||||||
return;
|
return;
|
||||||
callback_(block);
|
callback_(block);
|
||||||
visited_[block] = true;
|
visited_.insert(block);
|
||||||
Block* mergeBlock = nullptr;
|
Block* mergeBlock = nullptr;
|
||||||
Block* continueBlock = nullptr;
|
Block* continueBlock = nullptr;
|
||||||
auto mergeInst = block->getMergeInstruction();
|
auto mergeInst = block->getMergeInstruction();
|
||||||
if (mergeInst) {
|
if (mergeInst) {
|
||||||
Id mergeId = mergeInst->getIdOperand(0);
|
Id mergeId = mergeInst->getIdOperand(0);
|
||||||
mergeBlock = block->getParent().getParent().getInstruction(mergeId)->getBlock();
|
mergeBlock = block->getParent().getParent().getInstruction(mergeId)->getBlock();
|
||||||
delayed_[mergeBlock] = true;
|
delayed_.insert(mergeBlock);
|
||||||
if (mergeInst->getOpCode() == spv::OpLoopMerge) {
|
if (mergeInst->getOpCode() == spv::OpLoopMerge) {
|
||||||
Id continueId = mergeInst->getIdOperand(1);
|
Id continueId = mergeInst->getIdOperand(1);
|
||||||
continueBlock =
|
continueBlock =
|
||||||
block->getParent().getParent().getInstruction(continueId)->getBlock();
|
block->getParent().getParent().getInstruction(continueId)->getBlock();
|
||||||
delayed_[continueBlock] = true;
|
delayed_.insert(continueBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const auto successors = block->getSuccessors();
|
const auto successors = block->getSuccessors();
|
||||||
for (auto it = successors.cbegin(); it != successors.cend(); ++it)
|
for (auto it = successors.cbegin(); it != successors.cend(); ++it)
|
||||||
visit(*it);
|
visit(*it);
|
||||||
if (continueBlock) {
|
if (continueBlock) {
|
||||||
delayed_[continueBlock] = false;
|
delayed_.erase(continueBlock);
|
||||||
visit(continueBlock);
|
visit(continueBlock);
|
||||||
}
|
}
|
||||||
if (mergeBlock) {
|
if (mergeBlock) {
|
||||||
delayed_[mergeBlock] = false;
|
delayed_.erase(mergeBlock);
|
||||||
visit(mergeBlock);
|
visit(mergeBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::function<void(Block*)> callback_;
|
std::function<void(Block*)> callback_;
|
||||||
// Whether a block has already been visited or is being delayed.
|
// Whether a block has already been visited or is being delayed.
|
||||||
std::unordered_map<Block *, bool> visited_, delayed_;
|
std::unordered_set<Block *> visited_, delayed_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user