mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[NFC] Add API for edge domination check in dom tree
This commit is contained in:
parent
2dda30c1fe
commit
fbe3876c2c
@ -172,6 +172,8 @@ class DominatorTree : public DominatorTreeBase<BasicBlock, false> {
|
||||
/// never dominate the use.
|
||||
bool dominates(const BasicBlockEdge &BBE, const Use &U) const;
|
||||
bool dominates(const BasicBlockEdge &BBE, const BasicBlock *BB) const;
|
||||
/// Returns true if edge \p BBE1 dominates edge \p BBE2.
|
||||
bool dominates(const BasicBlockEdge &BBE1, const BasicBlockEdge &BBE2) const;
|
||||
|
||||
// Ensure base class overloads are visible.
|
||||
using Base::isReachableFromEntry;
|
||||
|
@ -316,6 +316,14 @@ bool DominatorTree::isReachableFromEntry(const Use &U) const {
|
||||
return isReachableFromEntry(I->getParent());
|
||||
}
|
||||
|
||||
// Edge BBE1 dominates edge BBE2 if they match or BBE1 dominates start of BBE2.
|
||||
bool DominatorTree::dominates(const BasicBlockEdge &BBE1,
|
||||
const BasicBlockEdge &BBE2) const {
|
||||
if (BBE1.getStart() == BBE2.getStart() && BBE1.getEnd() == BBE2.getEnd())
|
||||
return true;
|
||||
return dominates(BBE1, BBE2.getStart());
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// DominatorTreeAnalysis and related pass implementations
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -1020,3 +1020,54 @@ TEST(DominatorTree, InsertIntoIrreducible) {
|
||||
EXPECT_TRUE(DT.verify());
|
||||
}
|
||||
|
||||
TEST(DominatorTree, EdgeDomination) {
|
||||
StringRef ModuleString = "define i32 @f(i1 %cond) {\n"
|
||||
" bb0:\n"
|
||||
" br i1 %cond, label %bb1, label %bb2\n"
|
||||
" bb1:\n"
|
||||
" br label %bb3\n"
|
||||
" bb2:\n"
|
||||
" br label %bb3\n"
|
||||
" bb3:\n"
|
||||
" ret i32 4"
|
||||
"}\n";
|
||||
|
||||
// Parse the module.
|
||||
LLVMContext Context;
|
||||
std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
|
||||
|
||||
runWithDomTree(*M, "f",
|
||||
[&](Function &F, DominatorTree *DT, PostDominatorTree *PDT) {
|
||||
Function::iterator FI = F.begin();
|
||||
|
||||
BasicBlock *BB0 = &*FI++;
|
||||
BasicBlock *BB1 = &*FI++;
|
||||
BasicBlock *BB2 = &*FI++;
|
||||
BasicBlock *BB3 = &*FI++;
|
||||
|
||||
BasicBlockEdge E01(BB0, BB1);
|
||||
BasicBlockEdge E02(BB0, BB2);
|
||||
BasicBlockEdge E13(BB1, BB3);
|
||||
BasicBlockEdge E23(BB2, BB3);
|
||||
|
||||
EXPECT_TRUE(DT->dominates(E01, E01));
|
||||
EXPECT_FALSE(DT->dominates(E01, E02));
|
||||
EXPECT_TRUE(DT->dominates(E01, E13));
|
||||
EXPECT_FALSE(DT->dominates(E01, E23));
|
||||
|
||||
EXPECT_FALSE(DT->dominates(E02, E01));
|
||||
EXPECT_TRUE(DT->dominates(E02, E02));
|
||||
EXPECT_FALSE(DT->dominates(E02, E13));
|
||||
EXPECT_TRUE(DT->dominates(E02, E23));
|
||||
|
||||
EXPECT_FALSE(DT->dominates(E13, E01));
|
||||
EXPECT_FALSE(DT->dominates(E13, E02));
|
||||
EXPECT_TRUE(DT->dominates(E13, E13));
|
||||
EXPECT_FALSE(DT->dominates(E13, E23));
|
||||
|
||||
EXPECT_FALSE(DT->dominates(E23, E01));
|
||||
EXPECT_FALSE(DT->dominates(E23, E02));
|
||||
EXPECT_FALSE(DT->dominates(E23, E13));
|
||||
EXPECT_TRUE(DT->dominates(E23, E23));
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user