Skip to content

Commit dfcc68c

Browse files
committed
DomTree: Remove getRoots() accessor
Summary: Avoid exposing details about how roots are stored. This enables subsequent type-erasure changes. v5: - cleanup a unit test by using EXPECT_EQ instead of EXPECT_TRUE Change-Id: I532b774cc71f2224e543bc7d79131d97f63f093d Reviewers: arsenm, RKSimon, mehdi_amini, courbet Subscribers: jvesely, wdng, hiraditya, kuhar, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D83085
1 parent 723a44c commit dfcc68c

File tree

8 files changed

+26
-24
lines changed

8 files changed

+26
-24
lines changed

llvm/include/llvm/Analysis/DominanceFrontier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class ForwardDominanceFrontierBase
130130
using DomSetType = typename DominanceFrontierBase<BlockT, false>::DomSetType;
131131

132132
void analyze(DomTreeT &DT) {
133-
assert(DT.getRoots().size() == 1 &&
133+
assert(DT.root_size() == 1 &&
134134
"Only one entry block for forward domfronts!");
135135
this->Roots = {DT.getRoot()};
136136
calculate(DT, DT[this->Roots[0]]);

llvm/include/llvm/CodeGen/MachineDominators.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,6 @@ class MachineDominatorTree : public MachineFunctionPass {
9393

9494
void getAnalysisUsage(AnalysisUsage &AU) const override;
9595

96-
/// getRoots - Return the root blocks of the current CFG. This may include
97-
/// multiple blocks if we are computing post dominators. For forward
98-
/// dominators, this will always be a single block (the entry node).
99-
///
100-
const SmallVectorImpl<MachineBasicBlock*> &getRoots() const {
101-
applySplitCriticalEdges();
102-
return DT->getRoots();
103-
}
104-
10596
MachineBasicBlock *getRoot() const {
10697
applySplitCriticalEdges();
10798
return DT->getRoot();

llvm/include/llvm/CodeGen/MachinePostDominators.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ class MachinePostDominatorTree : public MachineFunctionPass {
4141

4242
FunctionPass *createMachinePostDominatorTreePass();
4343

44-
const SmallVectorImpl<MachineBasicBlock *> &getRoots() const {
45-
return PDT->getRoots();
46-
}
47-
4844
MachineDomTreeNode *getRootNode() const { return PDT->getRootNode(); }
4945

5046
MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {

llvm/include/llvm/Support/GenericDomTree.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,27 @@ class DominatorTreeBase {
283283
DominatorTreeBase(const DominatorTreeBase &) = delete;
284284
DominatorTreeBase &operator=(const DominatorTreeBase &) = delete;
285285

286-
/// getRoots - Return the root blocks of the current CFG. This may include
287-
/// multiple blocks if we are computing post dominators. For forward
288-
/// dominators, this will always be a single block (the entry node).
286+
/// Iteration over roots.
289287
///
290-
const SmallVectorImpl<NodeT *> &getRoots() const { return Roots; }
288+
/// This may include multiple blocks if we are computing post dominators.
289+
/// For forward dominators, this will always be a single block (the entry
290+
/// block).
291+
using root_iterator = typename SmallVectorImpl<NodeT *>::iterator;
292+
using const_root_iterator = typename SmallVectorImpl<NodeT *>::const_iterator;
293+
294+
root_iterator root_begin() { return Roots.begin(); }
295+
const_root_iterator root_begin() const { return Roots.begin(); }
296+
root_iterator root_end() { return Roots.end(); }
297+
const_root_iterator root_end() const { return Roots.end(); }
298+
299+
size_t root_size() const { return Roots.size(); }
300+
301+
iterator_range<root_iterator> roots() {
302+
return make_range(root_begin(), root_end());
303+
}
304+
iterator_range<const_root_iterator> roots() const {
305+
return make_range(root_begin(), root_end());
306+
}
291307

292308
/// isPostDominator - Returns true if analysis based of postdoms
293309
///

llvm/include/llvm/Support/GenericDomTreeConstruction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ struct SemiNCAInfo {
13721372
if (!DT.DFSInfoValid || !DT.Parent)
13731373
return true;
13741374

1375-
const NodePtr RootBB = IsPostDom ? nullptr : DT.getRoots()[0];
1375+
const NodePtr RootBB = IsPostDom ? nullptr : *DT.root_begin();
13761376
const TreeNodePtr Root = DT.getNode(RootBB);
13771377

13781378
auto PrintNodeAndDFSNums = [](const TreeNodePtr TN) {

llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ bool AMDGPUUnifyDivergentExitNodes::runOnFunction(Function &F) {
199199
// If there's only one exit, we don't need to do anything, unless this is a
200200
// pixel shader and that exit is an infinite loop, since we still have to
201201
// insert an export in that case.
202-
if (PDT.getRoots().size() <= 1 &&
203-
F.getCallingConv() != CallingConv::AMDGPU_PS)
202+
if (PDT.root_size() <= 1 && F.getCallingConv() != CallingConv::AMDGPU_PS)
204203
return false;
205204

206205
LegacyDivergenceAnalysis &DA = getAnalysis<LegacyDivergenceAnalysis>();
@@ -217,7 +216,7 @@ bool AMDGPUUnifyDivergentExitNodes::runOnFunction(Function &F) {
217216
bool InsertExport = false;
218217

219218
bool Changed = false;
220-
for (BasicBlock *BB : PDT.getRoots()) {
219+
for (BasicBlock *BB : PDT.roots()) {
221220
if (isa<ReturnInst>(BB->getTerminator())) {
222221
if (!isUniformlyReached(DA, *BB))
223222
ReturningBlocks.push_back(BB);

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ struct DSEState {
18531853
if (CommonPred)
18541854
WorkList.insert(CommonPred);
18551855
else
1856-
for (BasicBlock *R : PDT.getRoots())
1856+
for (BasicBlock *R : PDT.roots())
18571857
WorkList.insert(R);
18581858

18591859
NumCFGTries++;

llvm/unittests/IR/DominatorTreeTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ TEST(DominatorTree, InsertFromUnreachable) {
805805
BasicBlock *To = B.getOrAddBlock(LastUpdate->Edge.To);
806806
PDT.insertEdge(From, To);
807807
EXPECT_TRUE(PDT.verify());
808-
EXPECT_TRUE(PDT.getRoots().size() == 2);
808+
EXPECT_EQ(PDT.root_size(), 2);
809809
// Make sure we can use a const pointer with getNode.
810810
const BasicBlock *BB5 = B.getOrAddBlock("5");
811811
EXPECT_NE(PDT.getNode(BB5), nullptr);

0 commit comments

Comments
 (0)