From d57d93c9de39187ec2298463b539ce617012c8ce Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Wed, 12 Oct 2016 03:08:40 +0000 Subject: [PATCH] Memory-SSA cleanup of clobbers interface, NFC This implements the cleanup that Danny asked to commit separately from the previous fix to GVN-hoist in https://reviews.llvm.org/D25476#inline-219818 Tested with ninja check on x86_64-linux. llvm-svn: 283967 --- llvm/include/llvm/Transforms/Utils/MemorySSA.h | 8 +++---- llvm/lib/Transforms/Scalar/GVNHoist.cpp | 31 +++++++++++++------------- llvm/lib/Transforms/Utils/MemorySSA.cpp | 14 ++++++++---- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/llvm/include/llvm/Transforms/Utils/MemorySSA.h b/llvm/include/llvm/Transforms/Utils/MemorySSA.h index 11fab52..e9979c0 100644 --- a/llvm/include/llvm/Transforms/Utils/MemorySSA.h +++ b/llvm/include/llvm/Transforms/Utils/MemorySSA.h @@ -974,10 +974,10 @@ inline upward_defs_iterator upward_defs_begin(const MemoryAccessPair &Pair) { inline upward_defs_iterator upward_defs_end() { return upward_defs_iterator(); } -bool instructionClobbersQuery(MemoryDef *MD, - const MemoryLocation &UseLoc, - const Instruction *UseInst, - AliasAnalysis &AA); +// Return true when MD may alias MU, return false otherwise. +bool defClobbersUseOrDef(MemoryDef *MD, const MemoryUseOrDef *MU, + AliasAnalysis &AA); + } // end namespace llvm #endif // LLVM_TRANSFORMS_UTILS_MEMORYSSA_H diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp index 92b7e35..4328afe 100644 --- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp +++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp @@ -19,12 +19,12 @@ // 2. geps when corresponding load/store cannot be hoisted. //===----------------------------------------------------------------------===// +#include "llvm/Transforms/Scalar/GVN.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Transforms/Scalar.h" -#include "llvm/Transforms/Scalar/GVN.h" #include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/MemorySSA.h" @@ -55,10 +55,10 @@ static cl::opt MaxDepthInBB( cl::desc("Hoist instructions from the beginning of the BB up to the " "maximum specified depth (default = 100, unlimited = -1)")); -static cl::opt MaxChainLength( - "gvn-hoist-max-chain-length", cl::Hidden, cl::init(10), - cl::desc("Maximum length of dependent chains to hoist " - "(default = 10, unlimited = -1)")); +static cl::opt + MaxChainLength("gvn-hoist-max-chain-length", cl::Hidden, cl::init(10), + cl::desc("Maximum length of dependent chains to hoist " + "(default = 10, unlimited = -1)")); namespace { @@ -89,7 +89,7 @@ public: ADFS = DFSNumber.lookup(BA); BDFS = DFSNumber.lookup(BB); } - assert (ADFS && BDFS); + assert(ADFS && BDFS); return ADFS < BDFS; } }; @@ -213,7 +213,7 @@ public: for (const BasicBlock *BB : depth_first(&F.getEntryBlock())) { DFSNumber[BB] = ++BBI; unsigned I = 0; - for (auto &Inst: *BB) + for (auto &Inst : *BB) DFSNumber[&Inst] = ++I; } @@ -239,6 +239,7 @@ public: return Res; } + private: GVN::ValueTable VN; DominatorTree *DT; @@ -322,10 +323,10 @@ private: /* Return true when I1 appears before I2 in the instructions of BB. */ bool firstInBB(const Instruction *I1, const Instruction *I2) { - assert (I1->getParent() == I2->getParent()); + assert(I1->getParent() == I2->getParent()); unsigned I1DFS = DFSNumber.lookup(I1); unsigned I2DFS = DFSNumber.lookup(I2); - assert (I1DFS && I2DFS); + assert(I1DFS && I2DFS); return I1DFS < I2DFS; } @@ -357,8 +358,7 @@ private: ReachedNewPt = true; } } - if (instructionClobbersQuery(Def, MemoryLocation::get(Insn), Insn, - *AA)) + if (defClobbersUseOrDef(Def, MU, *AA)) return true; } @@ -653,7 +653,8 @@ private: for (const Use &Op : I->operands()) if (const auto *Inst = dyn_cast(&Op)) if (!DT->dominates(Inst->getParent(), HoistPt)) { - if (const GetElementPtrInst *GepOp = dyn_cast(Inst)) { + if (const GetElementPtrInst *GepOp = + dyn_cast(Inst)) { if (!allGepOperandsAvailable(GepOp, HoistPt)) return false; // Gep is available if all operands of GepOp are available. @@ -670,7 +671,8 @@ private: void makeGepsAvailable(Instruction *Repl, BasicBlock *HoistPt, const SmallVecInsn &InstructionsToHoist, Instruction *Gep) const { - assert(allGepOperandsAvailable(Gep, HoistPt) && "GEP operands not available"); + assert(allGepOperandsAvailable(Gep, HoistPt) && + "GEP operands not available"); Instruction *ClonedGep = Gep->clone(); for (unsigned i = 0, e = Gep->getNumOperands(); i != e; ++i) @@ -974,8 +976,7 @@ public: }; } // namespace -PreservedAnalyses GVNHoistPass::run(Function &F, - FunctionAnalysisManager &AM) { +PreservedAnalyses GVNHoistPass::run(Function &F, FunctionAnalysisManager &AM) { DominatorTree &DT = AM.getResult(F); AliasAnalysis &AA = AM.getResult(F); MemoryDependenceResults &MD = AM.getResult(F); diff --git a/llvm/lib/Transforms/Utils/MemorySSA.cpp b/llvm/lib/Transforms/Utils/MemorySSA.cpp index d549f6a..ed2208e 100644 --- a/llvm/lib/Transforms/Utils/MemorySSA.cpp +++ b/llvm/lib/Transforms/Utils/MemorySSA.cpp @@ -210,10 +210,10 @@ static Reorderability getLoadReorderability(const LoadInst *Use, return Result; } -bool instructionClobbersQuery(MemoryDef *MD, - const MemoryLocation &UseLoc, - const Instruction *UseInst, - AliasAnalysis &AA) { +static bool instructionClobbersQuery(MemoryDef *MD, + const MemoryLocation &UseLoc, + const Instruction *UseInst, + AliasAnalysis &AA) { Instruction *DefInst = MD->getMemoryInst(); assert(DefInst && "Defining instruction not actually an instruction"); @@ -254,6 +254,12 @@ bool instructionClobbersQuery(MemoryDef *MD, return AA.getModRefInfo(DefInst, UseLoc) & MRI_Mod; } +// Return true when MD may alias MU, return false otherwise. +bool defClobbersUseOrDef(MemoryDef *MD, const MemoryUseOrDef *MU, + AliasAnalysis &AA) { + Instruction *Insn = MU->getMemoryInst(); + return instructionClobbersQuery(MD, MemoryLocation::get(Insn), Insn, AA); +} } namespace { -- 2.7.4