From 47fca931a033d3f4821a6f3ad294b0d8504de38e Mon Sep 17 00:00:00 2001 From: Daniil Fukalov Date: Wed, 12 May 2021 22:43:16 +0300 Subject: [PATCH] [NFC] MemoryDependenceAnalysis cleanup. 1. Removed redundant includes, 2. Removed never defined and used `releaseMemory()`. 3. Fixed member functions names first letter case. 4. Renamed duplicate (in nested struct `NonLocalPointerInfo`) name `NonLocalDeps` to `NonLocalDepsMap`. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D102358 --- .../llvm/Analysis/MemoryDependenceAnalysis.h | 19 ++---------- include/llvm/Transforms/Scalar/GVN.h | 4 ++- lib/Analysis/MemoryDependenceAnalysis.cpp | 31 +++++++++---------- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/include/llvm/Analysis/MemoryDependenceAnalysis.h b/include/llvm/Analysis/MemoryDependenceAnalysis.h index ee91fa1c413..cb522cf731d 100644 --- a/include/llvm/Analysis/MemoryDependenceAnalysis.h +++ b/include/llvm/Analysis/MemoryDependenceAnalysis.h @@ -20,17 +20,9 @@ #include "llvm/ADT/PointerSumType.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Analysis/MemoryLocation.h" -#include "llvm/IR/BasicBlock.h" -#include "llvm/IR/Metadata.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/PredIteratorCache.h" #include "llvm/IR/ValueHandle.h" -#include "llvm/Pass.h" -#include "llvm/Support/ErrorHandling.h" -#include -#include -#include -#include namespace llvm { @@ -38,13 +30,8 @@ class AAResults; class AssumptionCache; class BatchAAResults; class DominatorTree; -class Function; -class Instruction; -class LoadInst; class PHITransAddr; -class TargetLibraryInfo; class PhiValues; -class Value; /// A memory dependence query can return one of three different answers. class MemDepResult { @@ -344,7 +331,7 @@ private: // A map from instructions to their non-local dependencies. using NonLocalDepMapType = DenseMap; - NonLocalDepMapType NonLocalDeps; + NonLocalDepMapType NonLocalDepsMap; // A reverse mapping from dependencies to the dependees. This is // used when removing instructions to keep the cache coherent. @@ -501,13 +488,13 @@ private: DenseMap &Visited, bool SkipFirstBlock = false, bool IsIncomplete = false); - MemDepResult GetNonLocalInfoForBlock(Instruction *QueryInst, + MemDepResult getNonLocalInfoForBlock(Instruction *QueryInst, const MemoryLocation &Loc, bool isLoad, BasicBlock *BB, NonLocalDepInfo *Cache, unsigned NumSortedEntries, BatchAAResults &BatchAA); - void RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair P); + void removeCachedNonLocalPointerDependencies(ValueIsLoadPair P); void verifyRemoved(Instruction *Inst) const; }; diff --git a/include/llvm/Transforms/Scalar/GVN.h b/include/llvm/Transforms/Scalar/GVN.h index 70662ca213c..5c29b289d15 100644 --- a/include/llvm/Transforms/Scalar/GVN.h +++ b/include/llvm/Transforms/Scalar/GVN.h @@ -21,7 +21,6 @@ #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/InstructionPrecedenceTracking.h" -#include "llvm/Analysis/MemoryDependenceAnalysis.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/PassManager.h" @@ -47,8 +46,11 @@ class FunctionPass; class IntrinsicInst; class LoadInst; class LoopInfo; +class MemDepResult; +class MemoryDependenceResults; class MemorySSA; class MemorySSAUpdater; +class NonLocalDepResult; class OptimizationRemarkEmitter; class PHINode; class TargetLibraryInfo; diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index 312f67e6f83..b44d15e7155 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -717,7 +717,7 @@ MemoryDependenceResults::getNonLocalCallDependency(CallBase *QueryCall) { assert(getDependency(QueryCall).isNonLocal() && "getNonLocalCallDependency should only be used on calls with " "non-local deps!"); - PerInstNLInfo &CacheP = NonLocalDeps[QueryCall]; + PerInstNLInfo &CacheP = NonLocalDepsMap[QueryCall]; NonLocalDepInfo &Cache = CacheP.first; // This is the set of blocks that need to be recomputed. In the cached case, @@ -902,7 +902,7 @@ void MemoryDependenceResults::getNonLocalPointerDependency( /// info if available). /// /// If we do a lookup, add the result to the cache. -MemDepResult MemoryDependenceResults::GetNonLocalInfoForBlock( +MemDepResult MemoryDependenceResults::getNonLocalInfoForBlock( Instruction *QueryInst, const MemoryLocation &Loc, bool isLoad, BasicBlock *BB, NonLocalDepInfo *Cache, unsigned NumSortedEntries, BatchAAResults &BatchAA) { @@ -1228,9 +1228,8 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB( // Get the dependency info for Pointer in BB. If we have cached // information, we will use it, otherwise we compute it. LLVM_DEBUG(AssertSorted(*Cache, NumSortedEntries)); - MemDepResult Dep = GetNonLocalInfoForBlock(QueryInst, Loc, isLoad, BB, - Cache, NumSortedEntries, - BatchAA); + MemDepResult Dep = getNonLocalInfoForBlock( + QueryInst, Loc, isLoad, BB, Cache, NumSortedEntries, BatchAA); // If we got a Def or Clobber, add this to the list of results. if (!Dep.isNonLocal()) { @@ -1452,7 +1451,7 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB( } /// If P exists in CachedNonLocalPointerInfo or NonLocalDefsCache, remove it. -void MemoryDependenceResults::RemoveCachedNonLocalPointerDependencies( +void MemoryDependenceResults::removeCachedNonLocalPointerDependencies( ValueIsLoadPair P) { // Most of the time this cache is empty. @@ -1501,9 +1500,9 @@ void MemoryDependenceResults::invalidateCachedPointerInfo(Value *Ptr) { if (!Ptr->getType()->isPointerTy()) return; // Flush store info for the pointer. - RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, false)); + removeCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, false)); // Flush load info for the pointer. - RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, true)); + removeCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, true)); // Invalidate phis that use the pointer. PV.invalidateValue(Ptr); } @@ -1515,13 +1514,13 @@ void MemoryDependenceResults::invalidateCachedPredecessors() { void MemoryDependenceResults::removeInstruction(Instruction *RemInst) { // Walk through the Non-local dependencies, removing this one as the value // for any cached queries. - NonLocalDepMapType::iterator NLDI = NonLocalDeps.find(RemInst); - if (NLDI != NonLocalDeps.end()) { + NonLocalDepMapType::iterator NLDI = NonLocalDepsMap.find(RemInst); + if (NLDI != NonLocalDepsMap.end()) { NonLocalDepInfo &BlockMap = NLDI->second.first; for (auto &Entry : BlockMap) if (Instruction *Inst = Entry.getResult().getInst()) RemoveFromReverseMap(ReverseNonLocalDeps, Inst, RemInst); - NonLocalDeps.erase(NLDI); + NonLocalDepsMap.erase(NLDI); } // If we have a cached local dependence query for this instruction, remove it. @@ -1541,8 +1540,8 @@ void MemoryDependenceResults::removeInstruction(Instruction *RemInst) { // If the instruction is a pointer, remove it from both the load info and the // store info. if (RemInst->getType()->isPointerTy()) { - RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, false)); - RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, true)); + removeCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, false)); + removeCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, true)); } else { // Otherwise, if the instructions is in the map directly, it must be a load. // Remove it. @@ -1605,7 +1604,7 @@ void MemoryDependenceResults::removeInstruction(Instruction *RemInst) { for (Instruction *I : ReverseDepIt->second) { assert(I != RemInst && "Already removed NonLocalDep info for RemInst"); - PerInstNLInfo &INLD = NonLocalDeps[I]; + PerInstNLInfo &INLD = NonLocalDepsMap[I]; // The information is now dirty! INLD.second = true; @@ -1677,7 +1676,7 @@ void MemoryDependenceResults::removeInstruction(Instruction *RemInst) { // Invalidate phis that use the removed instruction. PV.invalidateValue(RemInst); - assert(!NonLocalDeps.count(RemInst) && "RemInst got reinserted?"); + assert(!NonLocalDepsMap.count(RemInst) && "RemInst got reinserted?"); LLVM_DEBUG(verifyRemoved(RemInst)); } @@ -1698,7 +1697,7 @@ void MemoryDependenceResults::verifyRemoved(Instruction *D) const { assert(Entry.getResult().getInst() != D && "Inst occurs as NLPD value"); } - for (const auto &DepKV : NonLocalDeps) { + for (const auto &DepKV : NonLocalDepsMap) { assert(DepKV.first != D && "Inst occurs in data structures"); const PerInstNLInfo &INLD = DepKV.second; for (const auto &Entry : INLD.first)