1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

Update MemorySSA in LoopSimplifyCFG.

Summary:
Add MemorySSA as a dependency to LoopSimplifyCFG and preserve it.
Disabled by default until all passes preserve MemorySSA.

Reviewers: bogner, chandlerc

Subscribers: sanjoy, jlebar, Prazek, george.burgess.iv, llvm-commits

Differential Revision: https://reviews.llvm.org/D50911

llvm-svn: 340445
This commit is contained in:
Alina Sbirlea 2018-08-22 20:10:21 +00:00
parent 0cb48ba57d
commit facf6eb783
3 changed files with 25 additions and 4 deletions

View File

@ -24,6 +24,8 @@
#include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/MemorySSA.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Analysis/TargetTransformInfo.h"
@ -40,7 +42,7 @@ using namespace llvm;
#define DEBUG_TYPE "loop-simplifycfg" #define DEBUG_TYPE "loop-simplifycfg"
static bool simplifyLoopCFG(Loop &L, DominatorTree &DT, LoopInfo &LI, static bool simplifyLoopCFG(Loop &L, DominatorTree &DT, LoopInfo &LI,
ScalarEvolution &SE) { ScalarEvolution &SE, MemorySSAUpdater *MSSAU) {
bool Changed = false; bool Changed = false;
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager); DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
// Copy blocks into a temporary array to avoid iterator invalidation issues // Copy blocks into a temporary array to avoid iterator invalidation issues
@ -59,7 +61,7 @@ static bool simplifyLoopCFG(Loop &L, DominatorTree &DT, LoopInfo &LI,
continue; continue;
// Merge Succ into Pred and delete it. // Merge Succ into Pred and delete it.
MergeBlockIntoPredecessor(Succ, &DTU, &LI); MergeBlockIntoPredecessor(Succ, &DTU, &LI, MSSAU);
SE.forgetTopmostLoop(&L); SE.forgetTopmostLoop(&L);
@ -72,7 +74,11 @@ static bool simplifyLoopCFG(Loop &L, DominatorTree &DT, LoopInfo &LI,
PreservedAnalyses LoopSimplifyCFGPass::run(Loop &L, LoopAnalysisManager &AM, PreservedAnalyses LoopSimplifyCFGPass::run(Loop &L, LoopAnalysisManager &AM,
LoopStandardAnalysisResults &AR, LoopStandardAnalysisResults &AR,
LPMUpdater &) { LPMUpdater &) {
if (!simplifyLoopCFG(L, AR.DT, AR.LI, AR.SE)) Optional<MemorySSAUpdater> MSSAU;
if (EnableMSSALoopDependency && AR.MSSA)
MSSAU = MemorySSAUpdater(AR.MSSA);
if (!simplifyLoopCFG(L, AR.DT, AR.LI, AR.SE,
MSSAU.hasValue() ? MSSAU.getPointer() : nullptr))
return PreservedAnalyses::all(); return PreservedAnalyses::all();
return getLoopPassPreservedAnalyses(); return getLoopPassPreservedAnalyses();
@ -93,10 +99,22 @@ public:
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE(); ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
return simplifyLoopCFG(*L, DT, LI, SE); Optional<MemorySSAUpdater> MSSAU;
if (EnableMSSALoopDependency) {
MemorySSA *MSSA = &getAnalysis<MemorySSAWrapperPass>().getMSSA();
MSSAU = MemorySSAUpdater(MSSA);
if (VerifyMemorySSA)
MSSA->verifyMemorySSA();
}
return simplifyLoopCFG(*L, DT, LI, SE,
MSSAU.hasValue() ? MSSAU.getPointer() : nullptr);
} }
void getAnalysisUsage(AnalysisUsage &AU) const override { void getAnalysisUsage(AnalysisUsage &AU) const override {
if (EnableMSSALoopDependency) {
AU.addRequired<MemorySSAWrapperPass>();
AU.addPreserved<MemorySSAWrapperPass>();
}
AU.addPreserved<DependenceAnalysisWrapperPass>(); AU.addPreserved<DependenceAnalysisWrapperPass>();
getLoopAnalysisUsage(AU); getLoopAnalysisUsage(AU);
} }
@ -107,6 +125,7 @@ char LoopSimplifyCFGLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(LoopSimplifyCFGLegacyPass, "loop-simplifycfg", INITIALIZE_PASS_BEGIN(LoopSimplifyCFGLegacyPass, "loop-simplifycfg",
"Simplify loop CFG", false, false) "Simplify loop CFG", false, false)
INITIALIZE_PASS_DEPENDENCY(LoopPass) INITIALIZE_PASS_DEPENDENCY(LoopPass)
INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass)
INITIALIZE_PASS_END(LoopSimplifyCFGLegacyPass, "loop-simplifycfg", INITIALIZE_PASS_END(LoopSimplifyCFGLegacyPass, "loop-simplifycfg",
"Simplify loop CFG", false, false) "Simplify loop CFG", false, false)

View File

@ -1,5 +1,6 @@
; RUN: opt -S -loop-simplifycfg < %s | FileCheck %s ; RUN: opt -S -loop-simplifycfg < %s | FileCheck %s
; RUN: opt -S -passes='require<domtree>,loop(simplify-cfg)' < %s | FileCheck %s ; RUN: opt -S -passes='require<domtree>,loop(simplify-cfg)' < %s | FileCheck %s
; RUN: opt -S -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa < %s | FileCheck %s
; CHECK-LABEL: foo ; CHECK-LABEL: foo
; CHECK: entry: ; CHECK: entry:

View File

@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -loop-simplifycfg -verify-scev < %s | FileCheck %s ; RUN: opt -S -loop-simplifycfg -verify-scev < %s | FileCheck %s
; RUN: opt -S -loop-simplifycfg -verify-scev -enable-mssa-loop-dependency=true -verify-memoryssa < %s | FileCheck %s
; Verify that the scev information is still valid. Verification should not fail ; Verify that the scev information is still valid. Verification should not fail