diff options
| author | Max Kazantsev <max.kazantsev@azul.com> | 2018-09-06 09:29:42 +0000 |
|---|---|---|
| committer | Max Kazantsev <max.kazantsev@azul.com> | 2018-09-06 09:29:42 +0000 |
| commit | 6afebe1d30721b3383d9808012cafb033eb70714 (patch) | |
| tree | 292b4ef91297cf636213fa586e79a1918cfb9b24 /llvm/lib/Analysis | |
| parent | 1a10ae0def03d6083f8cc7f512201a76aa8324ef (diff) | |
| download | bcm5719-llvm-6afebe1d30721b3383d9808012cafb033eb70714.tar.gz bcm5719-llvm-6afebe1d30721b3383d9808012cafb033eb70714.zip | |
[NFC] Simplify inner structure of InstructionPrecedenceTracking
Currently it has a set KnownBlocks that marks blocks as having cached
answers and a map FirstSpecialInsts that maps these blocks to first
special instructions in them. The value in the map is always non-null,
and for blocks that are known to have no special instructions the map
does not have an instance.
This patch removes KnownBlocks as obsolete. Instead, for blocks that
are known to have no special instructions, we just put a nullptr value.
This makes the code much easier to read.
llvm-svn: 341531
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/InstructionPrecedenceTracking.cpp | 49 |
1 files changed, 17 insertions, 32 deletions
diff --git a/llvm/lib/Analysis/InstructionPrecedenceTracking.cpp b/llvm/lib/Analysis/InstructionPrecedenceTracking.cpp index c020c325873..9443097355f 100644 --- a/llvm/lib/Analysis/InstructionPrecedenceTracking.cpp +++ b/llvm/lib/Analysis/InstructionPrecedenceTracking.cpp @@ -42,11 +42,11 @@ const Instruction *InstructionPrecedenceTracking::getFirstSpecialInstruction( validate(BB); #endif - if (!KnownBlocks.count(BB)) + if (FirstSpecialInsts.find(BB) == FirstSpecialInsts.end()) { fill(BB); - auto *FirstICF = FirstSpecialInsts.lookup(BB); - assert((!FirstICF || FirstICF->getParent() == BB) && "Inconsistent cache!"); - return FirstICF; + assert(FirstSpecialInsts.find(BB) != FirstSpecialInsts.end() && "Must be!"); + } + return FirstSpecialInsts[BB]; } bool InstructionPrecedenceTracking::hasSpecialInstructions( @@ -66,63 +66,48 @@ void InstructionPrecedenceTracking::fill(const BasicBlock *BB) { for (auto &I : *BB) if (isSpecialInstruction(&I)) { FirstSpecialInsts[BB] = &I; - break; + return; } - // Mark this block as having a known result. - KnownBlocks.insert(BB); + // Mark this block as having no special instructions. + FirstSpecialInsts[BB] = nullptr; } #ifndef NDEBUG void InstructionPrecedenceTracking::validate(const BasicBlock *BB) const { - // If we don't know anything about this block, make sure we don't store - // a bucket for it in FirstSpecialInsts map. - if (!KnownBlocks.count(BB)) { - assert(FirstSpecialInsts.find(BB) == FirstSpecialInsts.end() && "Must be!"); + auto It = FirstSpecialInsts.find(BB); + // Bail if we don't have anything cached for this block. + if (It == FirstSpecialInsts.end()) return; - } - auto It = FirstSpecialInsts.find(BB); - bool BlockHasSpecialInsns = false; - for (const Instruction &Insn : *BB) { + for (const Instruction &Insn : *BB) if (isSpecialInstruction(&Insn)) { - assert(It != FirstSpecialInsts.end() && - "Blocked marked as known but we have no cached value for it!"); assert(It->second == &Insn && "Cached first special instruction is wrong!"); - BlockHasSpecialInsns = true; - break; + return; } - } - if (!BlockHasSpecialInsns) - assert(It == FirstSpecialInsts.end() && - "Block is marked as having special instructions but in fact it " - "has none!"); + + assert(It->second == nullptr && + "Block is marked as having special instructions but in fact it has " + "none!"); } void InstructionPrecedenceTracking::validateAll() const { // Check that for every known block the cached value is correct. - for (auto *BB : KnownBlocks) - validate(BB); - - // Check that all blocks with cached values are marked as known. for (auto &It : FirstSpecialInsts) - assert(KnownBlocks.count(It.first) && - "We have a cached value but the block is not marked as known?"); + validate(It.first); } #endif void InstructionPrecedenceTracking::invalidateBlock(const BasicBlock *BB) { OI.invalidateBlock(BB); FirstSpecialInsts.erase(BB); - KnownBlocks.erase(BB); } void InstructionPrecedenceTracking::clear() { for (auto It : FirstSpecialInsts) OI.invalidateBlock(It.first); FirstSpecialInsts.clear(); - KnownBlocks.clear(); #ifndef NDEBUG // The map should be valid after clearing (at least empty). validateAll(); |

