mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[Dominators] Add PDT constructor from Function
Summary: This patch adds a PDT constructor from Function and lets codes previously using a local class to do this use PostDominatorTree class directly. Reviewers: davide, kuhar, grosser, dberlin Reviewed By: kuhar Author: NutshellySima Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D46709 llvm-svn: 333102
This commit is contained in:
parent
55d8089213
commit
e57b782abf
@ -30,6 +30,8 @@ class PostDominatorTree : public PostDomTreeBase<BasicBlock> {
|
||||
public:
|
||||
using Base = PostDomTreeBase<BasicBlock>;
|
||||
|
||||
PostDominatorTree() = default;
|
||||
explicit PostDominatorTree(Function &F) { recalculate(F); }
|
||||
/// Handle invalidation explicitly.
|
||||
bool invalidate(Function &F, const PreservedAnalyses &PA,
|
||||
FunctionAnalysisManager::Invalidator &);
|
||||
|
@ -69,8 +69,7 @@ AnalysisKey PostDominatorTreeAnalysis::Key;
|
||||
|
||||
PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
|
||||
FunctionAnalysisManager &) {
|
||||
PostDominatorTree PDT;
|
||||
PDT.recalculate(F);
|
||||
PostDominatorTree PDT(F);
|
||||
return PDT;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "llvm/Analysis/InlineCost.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
|
||||
#include "llvm/Analysis/PostDominators.h"
|
||||
#include "llvm/Analysis/ProfileSummaryInfo.h"
|
||||
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||
#include "llvm/IR/BasicBlock.h"
|
||||
@ -253,7 +254,7 @@ protected:
|
||||
|
||||
/// Dominance, post-dominance and loop information.
|
||||
std::unique_ptr<DominatorTree> DT;
|
||||
std::unique_ptr<PostDomTreeBase<BasicBlock>> PDT;
|
||||
std::unique_ptr<PostDominatorTree> PDT;
|
||||
std::unique_ptr<LoopInfo> LI;
|
||||
|
||||
std::function<AssumptionCache &(Function &)> GetAC;
|
||||
@ -1365,8 +1366,7 @@ void SampleProfileLoader::computeDominanceAndLoopInfo(Function &F) {
|
||||
DT.reset(new DominatorTree);
|
||||
DT->recalculate(F);
|
||||
|
||||
PDT.reset(new PostDomTreeBase<BasicBlock>());
|
||||
PDT->recalculate(F);
|
||||
PDT.reset(new PostDominatorTree(F));
|
||||
|
||||
LI.reset(new LoopInfo);
|
||||
LI->analyze(*DT);
|
||||
|
@ -22,13 +22,10 @@ namespace {
|
||||
const auto CFGInsert = CFGBuilder::ActionKind::Insert;
|
||||
const auto CFGDelete = CFGBuilder::ActionKind::Delete;
|
||||
|
||||
struct PostDomTree : PostDomTreeBase<BasicBlock> {
|
||||
PostDomTree(Function &F) { recalculate(F); }
|
||||
};
|
||||
|
||||
using DomUpdate = DominatorTree::UpdateType;
|
||||
static_assert(
|
||||
std::is_same<DomUpdate, PostDomTree::UpdateType>::value,
|
||||
std::is_same<DomUpdate, PostDominatorTree::UpdateType>::value,
|
||||
"Trees differing only in IsPostDom should have the same update types");
|
||||
using DomSNCA = DomTreeBuilder::SemiNCAInfo<DomTreeBuilder::BBDomTree>;
|
||||
using PostDomSNCA = DomTreeBuilder::SemiNCAInfo<DomTreeBuilder::BBPostDomTree>;
|
||||
@ -100,7 +97,7 @@ TEST(DominatorTreeBatchUpdates, SingleInsertion) {
|
||||
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
BasicBlock *B = Builder.getOrAddBlock("B");
|
||||
@ -122,7 +119,7 @@ TEST(DominatorTreeBatchUpdates, SingleDeletion) {
|
||||
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
BasicBlock *B = Builder.getOrAddBlock("B");
|
||||
@ -148,7 +145,7 @@ TEST(DominatorTreeBatchUpdates, FewInsertion) {
|
||||
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
BasicBlock *B = Builder.getOrAddBlock("B");
|
||||
@ -181,7 +178,7 @@ TEST(DominatorTreeBatchUpdates, FewDeletions) {
|
||||
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
auto Updates = ToDomUpdates(Builder, CFGUpdates);
|
||||
@ -212,7 +209,7 @@ TEST(DominatorTreeBatchUpdates, InsertDelete) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
while (B.applyUpdate())
|
||||
@ -245,7 +242,7 @@ TEST(DominatorTreeBatchUpdates, InsertDeleteExhaustive) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
while (B.applyUpdate())
|
||||
@ -278,7 +275,7 @@ TEST(DominatorTreeBatchUpdates, InfiniteLoop) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
while (B.applyUpdate())
|
||||
@ -311,7 +308,7 @@ TEST(DominatorTreeBatchUpdates, DeadBlocks) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
while (B.applyUpdate())
|
||||
@ -341,7 +338,7 @@ TEST(DominatorTreeBatchUpdates, InfiniteLoop2) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
while (B.applyUpdate())
|
||||
|
@ -22,19 +22,17 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
struct PostDomTree : PostDomTreeBase<BasicBlock> {
|
||||
PostDomTree(Function &F) { recalculate(F); }
|
||||
};
|
||||
|
||||
/// Build the dominator tree for the function and run the Test.
|
||||
static void runWithDomTree(
|
||||
Module &M, StringRef FuncName,
|
||||
function_ref<void(Function &F, DominatorTree *DT, PostDomTree *PDT)> Test) {
|
||||
function_ref<void(Function &F, DominatorTree *DT, PostDominatorTree *PDT)>
|
||||
Test) {
|
||||
auto *F = M.getFunction(FuncName);
|
||||
ASSERT_NE(F, nullptr) << "Could not find " << FuncName;
|
||||
// Compute the dominator tree for the function.
|
||||
DominatorTree DT(*F);
|
||||
PostDomTree PDT(*F);
|
||||
PostDominatorTree PDT(*F);
|
||||
Test(*F, &DT, &PDT);
|
||||
}
|
||||
|
||||
@ -76,7 +74,7 @@ TEST(DominatorTree, Unreachable) {
|
||||
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
|
||||
|
||||
runWithDomTree(
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) {
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDominatorTree *PDT) {
|
||||
Function::iterator FI = F.begin();
|
||||
|
||||
BasicBlock *BB0 = &*FI++;
|
||||
@ -296,7 +294,7 @@ TEST(DominatorTree, NonUniqueEdges) {
|
||||
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
|
||||
|
||||
runWithDomTree(
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) {
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDominatorTree *PDT) {
|
||||
Function::iterator FI = F.begin();
|
||||
|
||||
BasicBlock *BB0 = &*FI++;
|
||||
@ -360,7 +358,7 @@ TEST(DominatorTree, NonUniqueEdges) {
|
||||
// unreachable Exit
|
||||
//
|
||||
// Both the blocks that end with ret and with unreachable become trivial
|
||||
// PostDomTree roots, as they have no successors.
|
||||
// PostDominatorTree roots, as they have no successors.
|
||||
//
|
||||
TEST(DominatorTree, DeletingEdgesIntroducesUnreachables) {
|
||||
StringRef ModuleString =
|
||||
@ -380,7 +378,7 @@ TEST(DominatorTree, DeletingEdgesIntroducesUnreachables) {
|
||||
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
|
||||
|
||||
runWithDomTree(
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) {
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDominatorTree *PDT) {
|
||||
Function::iterator FI = F.begin();
|
||||
|
||||
FI++;
|
||||
@ -407,7 +405,7 @@ TEST(DominatorTree, DeletingEdgesIntroducesUnreachables) {
|
||||
DominatorTree NDT(F);
|
||||
EXPECT_EQ(DT->compare(NDT), 0);
|
||||
|
||||
PostDomTree NPDT(F);
|
||||
PostDominatorTree NPDT(F);
|
||||
EXPECT_EQ(PDT->compare(NPDT), 0);
|
||||
});
|
||||
}
|
||||
@ -474,7 +472,7 @@ TEST(DominatorTree, DeletingEdgesIntroducesInfiniteLoop) {
|
||||
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
|
||||
|
||||
runWithDomTree(
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) {
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDominatorTree *PDT) {
|
||||
Function::iterator FI = F.begin();
|
||||
|
||||
FI++;
|
||||
@ -499,7 +497,7 @@ TEST(DominatorTree, DeletingEdgesIntroducesInfiniteLoop) {
|
||||
DominatorTree NDT(F);
|
||||
EXPECT_EQ(DT->compare(NDT), 0);
|
||||
|
||||
PostDomTree NPDT(F);
|
||||
PostDominatorTree NPDT(F);
|
||||
EXPECT_EQ(PDT->compare(NPDT), 0);
|
||||
});
|
||||
}
|
||||
@ -563,7 +561,7 @@ TEST(DominatorTree, DeletingEdgesIntroducesInfiniteLoop2) {
|
||||
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
|
||||
|
||||
runWithDomTree(
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) {
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDominatorTree *PDT) {
|
||||
Function::iterator FI = F.begin();
|
||||
|
||||
FI++;
|
||||
@ -594,7 +592,7 @@ TEST(DominatorTree, DeletingEdgesIntroducesInfiniteLoop2) {
|
||||
DominatorTree NDT(F);
|
||||
EXPECT_EQ(DT->compare(NDT), 0);
|
||||
|
||||
PostDomTree NPDT(F);
|
||||
PostDominatorTree NPDT(F);
|
||||
EXPECT_EQ(PDT->compare(NPDT), 0);
|
||||
});
|
||||
}
|
||||
@ -637,7 +635,7 @@ TEST(DominatorTree, IDFDeterminismTest) {
|
||||
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
|
||||
|
||||
runWithDomTree(
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) {
|
||||
*M, "f", [&](Function &F, DominatorTree *DT, PostDominatorTree *PDT) {
|
||||
Function::iterator FI = F.begin();
|
||||
|
||||
BasicBlock *A = &*FI++;
|
||||
@ -691,7 +689,7 @@ TEST(DominatorTree, InsertReachable) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate;
|
||||
@ -717,7 +715,7 @@ TEST(DominatorTree, InsertReachable2) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate = B.applyUpdate();
|
||||
@ -745,7 +743,7 @@ TEST(DominatorTree, InsertUnreachable) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate;
|
||||
@ -766,7 +764,7 @@ TEST(DominatorTree, InsertFromUnreachable) {
|
||||
|
||||
std::vector<CFGBuilder::Update> Updates = {{Insert, {"3", "5"}}};
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate = B.applyUpdate();
|
||||
@ -794,7 +792,7 @@ TEST(DominatorTree, InsertMixed) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate;
|
||||
@ -824,7 +822,7 @@ TEST(DominatorTree, InsertPermut) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate;
|
||||
@ -851,7 +849,7 @@ TEST(DominatorTree, DeleteReachable) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate;
|
||||
@ -877,7 +875,7 @@ TEST(DominatorTree, DeleteUnreachable) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate;
|
||||
@ -907,7 +905,7 @@ TEST(DominatorTree, InsertDelete) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate;
|
||||
@ -945,7 +943,7 @@ TEST(DominatorTree, InsertDeleteExhaustive) {
|
||||
CFGBuilder B(Holder.F, Arcs, Updates);
|
||||
DominatorTree DT(*Holder.F);
|
||||
EXPECT_TRUE(DT.verify());
|
||||
PostDomTree PDT(*Holder.F);
|
||||
PostDominatorTree PDT(*Holder.F);
|
||||
EXPECT_TRUE(PDT.verify());
|
||||
|
||||
Optional<CFGBuilder::Update> LastUpdate;
|
||||
|
Loading…
x
Reference in New Issue
Block a user