From 7500c5641e2e9ddbe1eb45f9f0e3ea6c00ea3e2b Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Sat, 1 Apr 2017 08:59:45 +0000 Subject: [PATCH] MemorySSA: Kill the WalkTargetCache now that we have getBlockDefs. llvm-svn: 299294 --- llvm/lib/Transforms/Utils/MemorySSA.cpp | 45 +++++---------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/llvm/lib/Transforms/Utils/MemorySSA.cpp b/llvm/lib/Transforms/Utils/MemorySSA.cpp index 62d9e97..42119f4 100644 --- a/llvm/lib/Transforms/Utils/MemorySSA.cpp +++ b/llvm/lib/Transforms/Utils/MemorySSA.cpp @@ -519,7 +519,6 @@ class ClobberWalker { // Phi optimization bookkeeping SmallVector Paths; DenseSet VisitedPhis; - DenseMap WalkTargetCache; void setUseCache(bool Use) { UseCache = Use; } bool shouldIgnoreCache() const { @@ -557,46 +556,17 @@ class ClobberWalker { } /// Find the nearest def or phi that `From` can legally be optimized to. - /// - /// FIXME: Deduplicate this with MSSA::findDominatingDef. Ideally, MSSA should - /// keep track of this information for us, and allow us O(1) lookups of this - /// info. - MemoryAccess *getWalkTarget(const MemoryPhi *From) { + MemoryAccess *getWalkTarget(const MemoryPhi *From) const { assert(From->getNumOperands() && "Phi with no operands?"); BasicBlock *BB = From->getBlock(); - auto At = WalkTargetCache.find(BB); - if (At != WalkTargetCache.end()) - return At->second; - - SmallVector ToCache; - ToCache.push_back(BB); - MemoryAccess *Result = MSSA.getLiveOnEntryDef(); DomTreeNode *Node = DT.getNode(BB); while ((Node = Node->getIDom())) { - auto At = WalkTargetCache.find(BB); - if (At != WalkTargetCache.end()) { - Result = At->second; - break; - } - - auto *Accesses = MSSA.getBlockAccesses(Node->getBlock()); - if (Accesses) { - auto Iter = find_if(reverse(*Accesses), [](const MemoryAccess &MA) { - return !isa(MA); - }); - if (Iter != Accesses->rend()) { - Result = const_cast(&*Iter); - break; - } - } - - ToCache.push_back(Node->getBlock()); + auto *Defs = MSSA.getBlockDefs(Node->getBlock()); + if (Defs) + return const_cast(&*Defs->rbegin()); } - - for (const BasicBlock *BB : ToCache) - WalkTargetCache.insert({BB, Result}); return Result; } @@ -991,7 +961,7 @@ public: WalkerCache &WC) : MSSA(MSSA), AA(AA), DT(DT), WC(WC), UseCache(true) {} - void reset() { WalkTargetCache.clear(); } + void reset() {} /// Finds the nearest clobber for the given query, optimizing phis if /// possible. @@ -1104,10 +1074,7 @@ public: /// answer a clobber query. void setAutoResetWalker(bool AutoReset) { AutoResetWalker = AutoReset; } - /// Drop the walker's persistent data structures. At the moment, this means - /// "drop the walker's cache of BasicBlocks -> - /// earliest-MemoryAccess-we-can-optimize-to". This is necessary if we're - /// going to have DT updates, if we remove MemoryAccesses, etc. + /// Drop the walker's persistent data structures. void resetClobberWalker() { Walker.reset(); } void verify(const MemorySSA *MSSA) override { -- 2.7.4