summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Passes/PassBuilder.cpp1
-rw-r--r--llvm/lib/Passes/PassRegistry.def3
-rw-r--r--llvm/lib/Transforms/Utils/MemorySSA.cpp120
-rw-r--r--llvm/lib/Transforms/Utils/Utils.cpp3
4 files changed, 60 insertions, 67 deletions
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index fdf8c6982d5..5076fefbf7b 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -80,6 +80,7 @@
#include "llvm/Transforms/Scalar/SROA.h"
#include "llvm/Transforms/Scalar/SimplifyCFG.h"
#include "llvm/Transforms/Scalar/Sink.h"
+#include "llvm/Transforms/Utils/MemorySSA.h"
#include <type_traits>
using namespace llvm;
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 9aaf17779da..ffd3bcbcf7e 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -86,6 +86,7 @@ FUNCTION_ANALYSIS("domfrontier", DominanceFrontierAnalysis())
FUNCTION_ANALYSIS("loops", LoopAnalysis())
FUNCTION_ANALYSIS("da", DependenceAnalysis())
FUNCTION_ANALYSIS("memdep", MemoryDependenceAnalysis())
+FUNCTION_ANALYSIS("memoryssa", MemorySSAAnalysis())
FUNCTION_ANALYSIS("regions", RegionInfoAnalysis())
FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
@@ -132,6 +133,7 @@ FUNCTION_PASS("print<postdomtree>", PostDominatorTreePrinterPass(dbgs()))
FUNCTION_PASS("print<demanded-bits>", DemandedBitsPrinterPass(dbgs()))
FUNCTION_PASS("print<domfrontier>", DominanceFrontierPrinterPass(dbgs()))
FUNCTION_PASS("print<loops>", LoopPrinterPass(dbgs()))
+FUNCTION_PASS("print<memoryssa>", MemorySSAPrinterPass(dbgs()))
FUNCTION_PASS("print<regions>", RegionInfoPrinterPass(dbgs()))
FUNCTION_PASS("print<scalar-evolution>", ScalarEvolutionPrinterPass(dbgs()))
FUNCTION_PASS("reassociate", ReassociatePass())
@@ -141,6 +143,7 @@ FUNCTION_PASS("sink", SinkingPass())
FUNCTION_PASS("sroa", SROA())
FUNCTION_PASS("verify", VerifierPass())
FUNCTION_PASS("verify<domtree>", DominatorTreeVerifierPass())
+FUNCTION_PASS("verify<memoryssa>", MemorySSAVerifierPass())
FUNCTION_PASS("verify<regions>", RegionInfoVerifierPass())
#undef FUNCTION_PASS
diff --git a/llvm/lib/Transforms/Utils/MemorySSA.cpp b/llvm/lib/Transforms/Utils/MemorySSA.cpp
index 9d8c0884fdb..5946b99d146 100644
--- a/llvm/lib/Transforms/Utils/MemorySSA.cpp
+++ b/llvm/lib/Transforms/Utils/MemorySSA.cpp
@@ -46,14 +46,12 @@ using namespace llvm;
STATISTIC(NumClobberCacheLookups, "Number of Memory SSA version cache lookups");
STATISTIC(NumClobberCacheHits, "Number of Memory SSA version cache hits");
STATISTIC(NumClobberCacheInserts, "Number of MemorySSA version cache inserts");
-INITIALIZE_PASS_WITH_OPTIONS_BEGIN(MemorySSAPrinterPass, "print-memoryssa",
- "Memory SSA", true, true)
+
+INITIALIZE_PASS_BEGIN(MemorySSAWrapperPass, "memoryssa", "Memory SSA", true,
+ true)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
-INITIALIZE_PASS_END(MemorySSAPrinterPass, "print-memoryssa", "Memory SSA", true,
- true)
-INITIALIZE_PASS(MemorySSALazy, "memoryssalazy", "Memory SSA", true, true)
+INITIALIZE_PASS_END(MemorySSAWrapperPass, "memoryssa", "Memory SSA", true, true)
namespace llvm {
@@ -203,9 +201,22 @@ void MemorySSA::markUnreachableAsLiveOnEntry(BasicBlock *BB) {
}
}
-MemorySSA::MemorySSA(Function &Func)
- : AA(nullptr), DT(nullptr), F(Func), LiveOnEntryDef(nullptr),
- Walker(nullptr), NextID(0) {}
+MemorySSA::MemorySSA(Function &Func, AliasAnalysis *AA, DominatorTree *DT)
+ : AA(AA), DT(DT), F(Func), LiveOnEntryDef(nullptr), Walker(nullptr),
+ NextID(0) {
+ getWalker(); // Ensure MemorySSA has been built.
+}
+
+MemorySSA::MemorySSA(MemorySSA &&MSSA)
+ : AA(MSSA.AA), DT(MSSA.DT), F(MSSA.F),
+ ValueToMemoryAccess(std::move(MSSA.ValueToMemoryAccess)),
+ PerBlockAccesses(std::move(MSSA.PerBlockAccesses)),
+ LiveOnEntryDef(std::move(MSSA.LiveOnEntryDef)),
+ Walker(std::move(MSSA.Walker)), NextID(MSSA.NextID) {
+ // Update the Walker MSSA pointer so it doesn't point to the moved-from MSSA
+ // object any more.
+ Walker->MSSA = this;
+}
MemorySSA::~MemorySSA() {
// Drop all our references
@@ -222,17 +233,11 @@ MemorySSA::AccessListType *MemorySSA::getOrCreateAccessList(BasicBlock *BB) {
return Res.first->second.get();
}
-MemorySSAWalker *MemorySSA::buildMemorySSA(AliasAnalysis *AA,
- DominatorTree *DT) {
+MemorySSAWalker *MemorySSA::getWalker() {
if (Walker)
- return Walker;
-
- assert(!this->AA && !this->DT &&
- "MemorySSA without a walker already has AA or DT?");
+ return Walker.get();
- Walker = new CachingMemorySSAWalker(this, AA, DT);
- this->AA = AA;
- this->DT = DT;
+ Walker = make_unique<CachingMemorySSAWalker>(this, AA, DT);
// We create an access to represent "live on entry", for things like
// arguments or users of globals, where the memory they use is defined before
@@ -349,7 +354,7 @@ MemorySSAWalker *MemorySSA::buildMemorySSA(AliasAnalysis *AA,
if (!Visited.count(&BB))
markUnreachableAsLiveOnEntry(&BB);
- return Walker;
+ return Walker.get();
}
/// \brief Helper function to create new memory accesses
@@ -684,69 +689,54 @@ void MemoryAccess::dump() const {
dbgs() << "\n";
}
-char MemorySSAPrinterPass::ID = 0;
+char MemorySSAAnalysis::PassID;
-MemorySSAPrinterPass::MemorySSAPrinterPass() : FunctionPass(ID) {
- initializeMemorySSAPrinterPassPass(*PassRegistry::getPassRegistry());
+MemorySSA MemorySSAAnalysis::run(Function &F, AnalysisManager<Function> &AM) {
+ auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
+ auto &AA = AM.getResult<AAManager>(F);
+ return MemorySSA(F, &AA, &DT);
}
-void MemorySSAPrinterPass::releaseMemory() {
- // Subtlety: Be sure to delete the walker before MSSA, because the walker's
- // dtor may try to access MemorySSA.
- Walker.reset();
- MSSA.reset();
-}
+PreservedAnalyses MemorySSAPrinterPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ OS << "MemorySSA for function: " << F.getName() << "\n";
+ AM.getResult<MemorySSAAnalysis>(F).print(OS);
-void MemorySSAPrinterPass::getAnalysisUsage(AnalysisUsage &AU) const {
- AU.setPreservesAll();
- AU.addRequired<AAResultsWrapperPass>();
- AU.addRequired<DominatorTreeWrapperPass>();
- AU.addPreserved<DominatorTreeWrapperPass>();
- AU.addPreserved<GlobalsAAWrapperPass>();
+ return PreservedAnalyses::all();
}
-bool MemorySSAPrinterPass::doInitialization(Module &M) {
- VerifyMemorySSA = M.getContext()
- .getOption<bool, MemorySSAPrinterPass,
- &MemorySSAPrinterPass::VerifyMemorySSA>();
- return false;
-}
+PreservedAnalyses MemorySSAVerifierPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ AM.getResult<MemorySSAAnalysis>(F).verifyMemorySSA();
-void MemorySSAPrinterPass::registerOptions() {
- OptionRegistry::registerOption<bool, MemorySSAPrinterPass,
- &MemorySSAPrinterPass::VerifyMemorySSA>(
- "verify-memoryssa", "Run the Memory SSA verifier", false);
+ return PreservedAnalyses::all();
}
-void MemorySSAPrinterPass::print(raw_ostream &OS, const Module *M) const {
- MSSA->print(OS);
-}
+char MemorySSAWrapperPass::ID = 0;
-bool MemorySSAPrinterPass::runOnFunction(Function &F) {
- this->F = &F;
- MSSA.reset(new MemorySSA(F));
- AliasAnalysis *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
- DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
- Walker.reset(MSSA->buildMemorySSA(AA, DT));
+MemorySSAWrapperPass::MemorySSAWrapperPass() : FunctionPass(ID) {
+ initializeMemorySSAWrapperPassPass(*PassRegistry::getPassRegistry());
+}
- if (VerifyMemorySSA) {
- MSSA->verifyMemorySSA();
- }
+void MemorySSAWrapperPass::releaseMemory() { MSSA.reset(); }
- return false;
+void MemorySSAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+ AU.addRequiredTransitive<DominatorTreeWrapperPass>();
+ AU.addRequiredTransitive<AAResultsWrapperPass>();
}
-char MemorySSALazy::ID = 0;
-
-MemorySSALazy::MemorySSALazy() : FunctionPass(ID) {
- initializeMemorySSALazyPass(*PassRegistry::getPassRegistry());
+bool MemorySSAWrapperPass::runOnFunction(Function &F) {
+ auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+ auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
+ MSSA.reset(new MemorySSA(F, &AA, &DT));
+ return false;
}
-void MemorySSALazy::releaseMemory() { MSSA.reset(); }
+void MemorySSAWrapperPass::verifyAnalysis() const { MSSA->verifyMemorySSA(); }
-bool MemorySSALazy::runOnFunction(Function &F) {
- MSSA.reset(new MemorySSA(F));
- return false;
+void MemorySSAWrapperPass::print(raw_ostream &OS, const Module *M) const {
+ MSSA->print(OS);
}
MemorySSAWalker::MemorySSAWalker(MemorySSA *M) : MSSA(M) {}
diff --git a/llvm/lib/Transforms/Utils/Utils.cpp b/llvm/lib/Transforms/Utils/Utils.cpp
index 7e129c44ccd..ee321d37138 100644
--- a/llvm/lib/Transforms/Utils/Utils.cpp
+++ b/llvm/lib/Transforms/Utils/Utils.cpp
@@ -33,8 +33,7 @@ void llvm::initializeTransformUtils(PassRegistry &Registry) {
initializeUnifyFunctionExitNodesPass(Registry);
initializeInstSimplifierPass(Registry);
initializeMetaRenamerPass(Registry);
- initializeMemorySSALazyPass(Registry);
- initializeMemorySSAPrinterPassPass(Registry);
+ initializeMemorySSAWrapperPassPass(Registry);
}
/// LLVMInitializeTransformUtils - C binding for initializeTransformUtilsPasses.
OpenPOWER on IntegriCloud