@@ -113,6 +113,8 @@ static cl::opt<bool>
113
113
GVNEnableSplitBackedgeInLoadPRE (" enable-split-backedge-in-load-pre" ,
114
114
cl::init (false ));
115
115
static cl::opt<bool > GVNEnableMemDep (" enable-gvn-memdep" , cl::init(true ));
116
+ static cl::opt<bool > GVNEnableMemorySSA (" enable-gvn-memoryssa" ,
117
+ cl::init (false ));
116
118
117
119
static cl::opt<uint32_t > MaxNumDeps (
118
120
" gvn-max-num-deps" , cl::Hidden, cl::init(100 ),
@@ -820,6 +822,10 @@ bool GVNPass::isMemDepEnabled() const {
820
822
return Options.AllowMemDep .value_or (GVNEnableMemDep);
821
823
}
822
824
825
+ bool GVNPass::isMemorySSAEnabled () const {
826
+ return Options.AllowMemorySSA .value_or (GVNEnableMemorySSA);
827
+ }
828
+
823
829
PreservedAnalyses GVNPass::run (Function &F, FunctionAnalysisManager &AM) {
824
830
// FIXME: The order of evaluation of these 'getResult' calls is very
825
831
// significant! Re-ordering these variables will cause GVN when run alone to
@@ -832,7 +838,10 @@ PreservedAnalyses GVNPass::run(Function &F, FunctionAnalysisManager &AM) {
832
838
auto *MemDep =
833
839
isMemDepEnabled () ? &AM.getResult <MemoryDependenceAnalysis>(F) : nullptr ;
834
840
auto &LI = AM.getResult <LoopAnalysis>(F);
835
- auto *MSSA = AM.getCachedResult <MemorySSAAnalysis>(F);
841
+ auto *MSSA =
842
+ isMemorySSAEnabled () ? &AM.getResult <MemorySSAAnalysis>(F) : nullptr ;
843
+ assert (!(MemDep && MSSA) &&
844
+ " Should not use both MemDep and MemorySSA simultaneously!" );
836
845
auto &ORE = AM.getResult <OptimizationRemarkEmitterAnalysis>(F);
837
846
bool Changed = runImpl (F, AC, DT, TLI, AA, MemDep, LI, &ORE,
838
847
MSSA ? &MSSA->getMSSA () : nullptr );
@@ -861,7 +870,9 @@ void GVNPass::printPipeline(
861
870
OS << (*Options.AllowLoadPRESplitBackedge ? " " : " no-" )
862
871
<< " split-backedge-load-pre;" ;
863
872
if (Options.AllowMemDep != std::nullopt)
864
- OS << (*Options.AllowMemDep ? " " : " no-" ) << " memdep" ;
873
+ OS << (*Options.AllowMemDep ? " " : " no-" ) << " memdep;" ;
874
+ if (Options.AllowMemorySSA != std::nullopt)
875
+ OS << (*Options.AllowMemorySSA ? " " : " no-" ) << " memoryssa" ;
865
876
OS << ' >' ;
866
877
}
867
878
@@ -3293,16 +3304,18 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
3293
3304
public:
3294
3305
static char ID; // Pass identification, replacement for typeid
3295
3306
3296
- explicit GVNLegacyPass (bool NoMemDepAnalysis = !GVNEnableMemDep)
3297
- : FunctionPass(ID), Impl(GVNOptions().setMemDep(!NoMemDepAnalysis)) {
3307
+ explicit GVNLegacyPass (bool MemDepAnalysis = GVNEnableMemDep,
3308
+ bool MemSSAAnalysis = GVNEnableMemorySSA)
3309
+ : FunctionPass(ID), Impl(GVNOptions()
3310
+ .setMemDep(MemDepAnalysis)
3311
+ .setMemorySSA(MemSSAAnalysis)) {
3298
3312
initializeGVNLegacyPassPass (*PassRegistry::getPassRegistry ());
3299
3313
}
3300
3314
3301
3315
bool runOnFunction (Function &F) override {
3302
3316
if (skipFunction (F))
3303
3317
return false ;
3304
3318
3305
- auto *MSSAWP = getAnalysisIfAvailable<MemorySSAWrapperPass>();
3306
3319
return Impl.runImpl (
3307
3320
F, getAnalysis<AssumptionCacheTracker>().getAssumptionCache (F),
3308
3321
getAnalysis<DominatorTreeWrapperPass>().getDomTree (),
@@ -3313,7 +3326,9 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
3313
3326
: nullptr ,
3314
3327
getAnalysis<LoopInfoWrapperPass>().getLoopInfo (),
3315
3328
&getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE (),
3316
- MSSAWP ? &MSSAWP->getMSSA () : nullptr );
3329
+ Impl.isMemorySSAEnabled ()
3330
+ ? &getAnalysis<MemorySSAWrapperPass>().getMSSA ()
3331
+ : nullptr );
3317
3332
}
3318
3333
3319
3334
void getAnalysisUsage (AnalysisUsage &AU) const override {
@@ -3329,7 +3344,8 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
3329
3344
AU.addPreserved <TargetLibraryInfoWrapperPass>();
3330
3345
AU.addPreserved <LoopInfoWrapperPass>();
3331
3346
AU.addRequired <OptimizationRemarkEmitterWrapperPass>();
3332
- AU.addPreserved <MemorySSAWrapperPass>();
3347
+ if (Impl.isMemorySSAEnabled ())
3348
+ AU.addRequired <MemorySSAWrapperPass>();
3333
3349
}
3334
3350
3335
3351
private:
@@ -3341,6 +3357,7 @@ char GVNLegacyPass::ID = 0;
3341
3357
INITIALIZE_PASS_BEGIN (GVNLegacyPass, " gvn" , " Global Value Numbering" , false , false )
3342
3358
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
3343
3359
INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
3360
+ INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass)
3344
3361
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
3345
3362
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
3346
3363
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
@@ -3349,6 +3366,4 @@ INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
3349
3366
INITIALIZE_PASS_END(GVNLegacyPass, " gvn" , " Global Value Numbering" , false , false )
3350
3367
3351
3368
// The public interface to this file...
3352
- FunctionPass *llvm::createGVNPass(bool NoMemDepAnalysis) {
3353
- return new GVNLegacyPass (NoMemDepAnalysis);
3354
- }
3369
+ FunctionPass *llvm::createGVNPass() { return new GVNLegacyPass (); }
0 commit comments