[llvm] r333102 - [Dominators] Add PDT constructor from Function
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Wed May 23 10:29:21 PDT 2018
Author: kuhar
Date: Wed May 23 10:29:21 2018
New Revision: 333102
URL: http://llvm.org/viewvc/llvm-project?rev=333102&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/Analysis/PostDominators.h
llvm/trunk/lib/Analysis/PostDominators.cpp
llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
llvm/trunk/unittests/IR/DominatorTreeBatchUpdatesTest.cpp
llvm/trunk/unittests/IR/DominatorTreeTest.cpp
Modified: llvm/trunk/include/llvm/Analysis/PostDominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/PostDominators.h?rev=333102&r1=333101&r2=333102&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/PostDominators.h (original)
+++ llvm/trunk/include/llvm/Analysis/PostDominators.h Wed May 23 10:29:21 2018
@@ -30,6 +30,8 @@ class PostDominatorTree : public PostDom
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 &);
Modified: llvm/trunk/lib/Analysis/PostDominators.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PostDominators.cpp?rev=333102&r1=333101&r2=333102&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/PostDominators.cpp (original)
+++ llvm/trunk/lib/Analysis/PostDominators.cpp Wed May 23 10:29:21 2018
@@ -69,8 +69,7 @@ AnalysisKey PostDominatorTreeAnalysis::K
PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
FunctionAnalysisManager &) {
- PostDominatorTree PDT;
- PDT.recalculate(F);
+ PostDominatorTree PDT(F);
return PDT;
}
Modified: llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp?rev=333102&r1=333101&r2=333102&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp Wed May 23 10:29:21 2018
@@ -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::computeDominan
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);
Modified: llvm/trunk/unittests/IR/DominatorTreeBatchUpdatesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/DominatorTreeBatchUpdatesTest.cpp?rev=333102&r1=333101&r2=333102&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/DominatorTreeBatchUpdatesTest.cpp (original)
+++ llvm/trunk/unittests/IR/DominatorTreeBatchUpdatesTest.cpp Wed May 23 10:29:21 2018
@@ -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, SingleIn
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, SingleDe
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, FewInser
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, FewDelet
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, InsertDe
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, InsertDe
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, Infinite
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, DeadBloc
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, Infinite
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())
Modified: llvm/trunk/unittests/IR/DominatorTreeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/DominatorTreeTest.cpp?rev=333102&r1=333101&r2=333102&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/DominatorTreeTest.cpp (original)
+++ llvm/trunk/unittests/IR/DominatorTreeTest.cpp Wed May 23 10:29:21 2018
@@ -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, DeletingEdgesIntrodu
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, DeletingEdgesIntrodu
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, DeletingEdgesIntrodu
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, DeletingEdgesIntrodu
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, DeletingEdgesIntrodu
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, DeletingEdgesIntrodu
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, InsertFromUnreachabl
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, InsertDeleteExhausti
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;
More information about the llvm-commits
mailing list