@@ -113,8 +113,6 @@ static cl::opt<bool>
113113GVNEnableSplitBackedgeInLoadPRE (" enable-split-backedge-in-load-pre" ,
114114 cl::init (false ));
115115static cl::opt<bool > GVNEnableMemDep (" enable-gvn-memdep" , cl::init(true ));
116- static cl::opt<bool > GVNEnableMemorySSA (" enable-gvn-memoryssa" ,
117- cl::init (false ));
118116
119117static cl::opt<uint32_t > MaxNumDeps (
120118 " gvn-max-num-deps" , cl::Hidden, cl::init(100 ),
@@ -822,10 +820,6 @@ bool GVNPass::isMemDepEnabled() const {
822820 return Options.AllowMemDep .value_or (GVNEnableMemDep);
823821}
824822
825- bool GVNPass::isMemorySSAEnabled () const {
826- return Options.AllowMemorySSA .value_or (GVNEnableMemorySSA);
827- }
828-
829823PreservedAnalyses GVNPass::run (Function &F, FunctionAnalysisManager &AM) {
830824 // FIXME: The order of evaluation of these 'getResult' calls is very
831825 // significant! Re-ordering these variables will cause GVN when run alone to
@@ -838,10 +832,7 @@ PreservedAnalyses GVNPass::run(Function &F, FunctionAnalysisManager &AM) {
838832 auto *MemDep =
839833 isMemDepEnabled () ? &AM.getResult <MemoryDependenceAnalysis>(F) : nullptr ;
840834 auto &LI = AM.getResult <LoopAnalysis>(F);
841- auto *MSSA =
842- isMemorySSAEnabled () ? &AM.getResult <MemorySSAAnalysis>(F) : nullptr ;
843- assert (!(MemDep && MSSA) &&
844- " Should not use both MemDep and MemorySSA simultaneously!" );
835+ auto *MSSA = AM.getCachedResult <MemorySSAAnalysis>(F);
845836 auto &ORE = AM.getResult <OptimizationRemarkEmitterAnalysis>(F);
846837 bool Changed = runImpl (F, AC, DT, TLI, AA, MemDep, LI, &ORE,
847838 MSSA ? &MSSA->getMSSA () : nullptr );
@@ -870,9 +861,7 @@ void GVNPass::printPipeline(
870861 OS << (*Options.AllowLoadPRESplitBackedge ? " " : " no-" )
871862 << " split-backedge-load-pre;" ;
872863 if (Options.AllowMemDep != std::nullopt )
873- OS << (*Options.AllowMemDep ? " " : " no-" ) << " memdep;" ;
874- if (Options.AllowMemorySSA != std::nullopt )
875- OS << (*Options.AllowMemorySSA ? " " : " no-" ) << " memoryssa" ;
864+ OS << (*Options.AllowMemDep ? " " : " no-" ) << " memdep" ;
876865 OS << ' >' ;
877866}
878867
@@ -3304,18 +3293,16 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
33043293public:
33053294 static char ID; // Pass identification, replacement for typeid
33063295
3307- explicit GVNLegacyPass (bool MemDepAnalysis = GVNEnableMemDep,
3308- bool MemSSAAnalysis = GVNEnableMemorySSA)
3309- : FunctionPass(ID), Impl(GVNOptions()
3310- .setMemDep(MemDepAnalysis)
3311- .setMemorySSA(MemSSAAnalysis)) {
3296+ explicit GVNLegacyPass (bool NoMemDepAnalysis = !GVNEnableMemDep)
3297+ : FunctionPass(ID), Impl(GVNOptions().setMemDep(!NoMemDepAnalysis)) {
33123298 initializeGVNLegacyPassPass (*PassRegistry::getPassRegistry ());
33133299 }
33143300
33153301 bool runOnFunction (Function &F) override {
33163302 if (skipFunction (F))
33173303 return false ;
33183304
3305+ auto *MSSAWP = getAnalysisIfAvailable<MemorySSAWrapperPass>();
33193306 return Impl.runImpl (
33203307 F, getAnalysis<AssumptionCacheTracker>().getAssumptionCache (F),
33213308 getAnalysis<DominatorTreeWrapperPass>().getDomTree (),
@@ -3326,9 +3313,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
33263313 : nullptr ,
33273314 getAnalysis<LoopInfoWrapperPass>().getLoopInfo (),
33283315 &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE (),
3329- Impl.isMemorySSAEnabled ()
3330- ? &getAnalysis<MemorySSAWrapperPass>().getMSSA ()
3331- : nullptr );
3316+ MSSAWP ? &MSSAWP->getMSSA () : nullptr );
33323317 }
33333318
33343319 void getAnalysisUsage (AnalysisUsage &AU) const override {
@@ -3344,8 +3329,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
33443329 AU.addPreserved <TargetLibraryInfoWrapperPass>();
33453330 AU.addPreserved <LoopInfoWrapperPass>();
33463331 AU.addRequired <OptimizationRemarkEmitterWrapperPass>();
3347- if (Impl.isMemorySSAEnabled ())
3348- AU.addRequired <MemorySSAWrapperPass>();
3332+ AU.addPreserved <MemorySSAWrapperPass>();
33493333 }
33503334
33513335private:
@@ -3357,7 +3341,6 @@ char GVNLegacyPass::ID = 0;
33573341INITIALIZE_PASS_BEGIN (GVNLegacyPass, " gvn" , " Global Value Numbering" , false , false )
33583342INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
33593343INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
3360- INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass)
33613344INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
33623345INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
33633346INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
@@ -3366,4 +3349,6 @@ INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
33663349INITIALIZE_PASS_END(GVNLegacyPass, " gvn" , " Global Value Numbering" , false , false )
33673350
33683351// The public interface to this file...
3369- FunctionPass *llvm::createGVNPass() { return new GVNLegacyPass (); }
3352+ FunctionPass *llvm::createGVNPass(bool NoMemDepAnalysis) {
3353+ return new GVNLegacyPass (NoMemDepAnalysis);
3354+ }
0 commit comments