-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[GVN] MemorySSA for GVN: add optional AllowMemorySSA
#120982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
antoniofrighetto
merged 1 commit into
llvm:main
from
antoniofrighetto:feature/enable-memssa-gvn
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,8 @@ static cl::opt<bool> | |
| GVNEnableSplitBackedgeInLoadPRE("enable-split-backedge-in-load-pre", | ||
| cl::init(false)); | ||
| static cl::opt<bool> GVNEnableMemDep("enable-gvn-memdep", cl::init(true)); | ||
| static cl::opt<bool> GVNEnableMemorySSA("enable-gvn-memoryssa", | ||
| cl::init(false)); | ||
|
|
||
| static cl::opt<uint32_t> MaxNumDeps( | ||
| "gvn-max-num-deps", cl::Hidden, cl::init(100), | ||
|
|
@@ -820,6 +822,10 @@ bool GVNPass::isMemDepEnabled() const { | |
| return Options.AllowMemDep.value_or(GVNEnableMemDep); | ||
| } | ||
|
|
||
| bool GVNPass::isMemorySSAEnabled() const { | ||
| return Options.AllowMemorySSA.value_or(GVNEnableMemorySSA); | ||
| } | ||
|
|
||
| PreservedAnalyses GVNPass::run(Function &F, FunctionAnalysisManager &AM) { | ||
| // FIXME: The order of evaluation of these 'getResult' calls is very | ||
| // significant! Re-ordering these variables will cause GVN when run alone to | ||
|
|
@@ -832,7 +838,10 @@ PreservedAnalyses GVNPass::run(Function &F, FunctionAnalysisManager &AM) { | |
| auto *MemDep = | ||
| isMemDepEnabled() ? &AM.getResult<MemoryDependenceAnalysis>(F) : nullptr; | ||
| auto &LI = AM.getResult<LoopAnalysis>(F); | ||
| auto *MSSA = AM.getCachedResult<MemorySSAAnalysis>(F); | ||
| auto *MSSA = | ||
| isMemorySSAEnabled() ? &AM.getResult<MemorySSAAnalysis>(F) : nullptr; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change here means that we no longer try to update and preserve an already computed MSSA instance. I've reverted this patch for now. |
||
| assert(!(MemDep && MSSA) && | ||
| "Should not use both MemDep and MemorySSA simultaneously!"); | ||
| auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F); | ||
| bool Changed = runImpl(F, AC, DT, TLI, AA, MemDep, LI, &ORE, | ||
| MSSA ? &MSSA->getMSSA() : nullptr); | ||
|
|
@@ -861,7 +870,9 @@ void GVNPass::printPipeline( | |
| OS << (*Options.AllowLoadPRESplitBackedge ? "" : "no-") | ||
| << "split-backedge-load-pre;"; | ||
| if (Options.AllowMemDep != std::nullopt) | ||
| OS << (*Options.AllowMemDep ? "" : "no-") << "memdep"; | ||
| OS << (*Options.AllowMemDep ? "" : "no-") << "memdep;"; | ||
| if (Options.AllowMemorySSA != std::nullopt) | ||
| OS << (*Options.AllowMemorySSA ? "" : "no-") << "memoryssa"; | ||
| OS << '>'; | ||
| } | ||
|
|
||
|
|
@@ -3293,16 +3304,18 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass { | |
| public: | ||
| static char ID; // Pass identification, replacement for typeid | ||
|
|
||
| explicit GVNLegacyPass(bool NoMemDepAnalysis = !GVNEnableMemDep) | ||
| : FunctionPass(ID), Impl(GVNOptions().setMemDep(!NoMemDepAnalysis)) { | ||
| explicit GVNLegacyPass(bool MemDepAnalysis = GVNEnableMemDep, | ||
| bool MemSSAAnalysis = GVNEnableMemorySSA) | ||
| : FunctionPass(ID), Impl(GVNOptions() | ||
| .setMemDep(MemDepAnalysis) | ||
| .setMemorySSA(MemSSAAnalysis)) { | ||
| initializeGVNLegacyPassPass(*PassRegistry::getPassRegistry()); | ||
| } | ||
|
|
||
| bool runOnFunction(Function &F) override { | ||
| if (skipFunction(F)) | ||
| return false; | ||
|
|
||
| auto *MSSAWP = getAnalysisIfAvailable<MemorySSAWrapperPass>(); | ||
| return Impl.runImpl( | ||
| F, getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F), | ||
| getAnalysis<DominatorTreeWrapperPass>().getDomTree(), | ||
|
|
@@ -3313,7 +3326,9 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass { | |
| : nullptr, | ||
| getAnalysis<LoopInfoWrapperPass>().getLoopInfo(), | ||
| &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE(), | ||
| MSSAWP ? &MSSAWP->getMSSA() : nullptr); | ||
| Impl.isMemorySSAEnabled() | ||
| ? &getAnalysis<MemorySSAWrapperPass>().getMSSA() | ||
| : nullptr); | ||
| } | ||
|
|
||
| void getAnalysisUsage(AnalysisUsage &AU) const override { | ||
|
|
@@ -3329,7 +3344,8 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass { | |
| AU.addPreserved<TargetLibraryInfoWrapperPass>(); | ||
| AU.addPreserved<LoopInfoWrapperPass>(); | ||
| AU.addRequired<OptimizationRemarkEmitterWrapperPass>(); | ||
| AU.addPreserved<MemorySSAWrapperPass>(); | ||
| if (Impl.isMemorySSAEnabled()) | ||
| AU.addRequired<MemorySSAWrapperPass>(); | ||
| } | ||
|
|
||
| private: | ||
|
|
@@ -3341,6 +3357,7 @@ char GVNLegacyPass::ID = 0; | |
| INITIALIZE_PASS_BEGIN(GVNLegacyPass, "gvn", "Global Value Numbering", false, false) | ||
| INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) | ||
| INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass) | ||
| INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass) | ||
| INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) | ||
| INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) | ||
| INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) | ||
|
|
@@ -3349,6 +3366,4 @@ INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass) | |
| INITIALIZE_PASS_END(GVNLegacyPass, "gvn", "Global Value Numbering", false, false) | ||
|
|
||
| // The public interface to this file... | ||
| FunctionPass *llvm::createGVNPass(bool NoMemDepAnalysis) { | ||
| return new GVNLegacyPass(NoMemDepAnalysis); | ||
| } | ||
| FunctionPass *llvm::createGVNPass() { return new GVNLegacyPass(); } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.