mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
DomTree: Remove getChildren() accessor
Summary: Avoid exposing details about how children are stored. This will enable subsequent type-erasure changes. New methods are introduced to cover common access patterns. Change-Id: Idb5f4b1b9c84e4cc71ddb39bb52a388682f5674f Reviewers: arsenm, RKSimon, mehdi_amini, courbet Subscribers: qcolombet, sdardis, wdng, hiraditya, jrtc27, zzheng, atanasyan, asbirlea, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D83083
This commit is contained in:
parent
850662dafb
commit
d4eb4d6675
@ -77,18 +77,25 @@ template <class NodeT> class DomTreeNodeBase {
|
||||
const_iterator begin() const { return Children.begin(); }
|
||||
const_iterator end() const { return Children.end(); }
|
||||
|
||||
DomTreeNodeBase *const &back() const { return Children.back(); }
|
||||
DomTreeNodeBase *&back() { return Children.back(); }
|
||||
|
||||
iterator_range<iterator> children() { return make_range(begin(), end()); }
|
||||
iterator_range<const_iterator> children() const {
|
||||
return make_range(begin(), end());
|
||||
}
|
||||
|
||||
NodeT *getBlock() const { return TheBB; }
|
||||
DomTreeNodeBase *getIDom() const { return IDom; }
|
||||
unsigned getLevel() const { return Level; }
|
||||
|
||||
const std::vector<DomTreeNodeBase *> &getChildren() const { return Children; }
|
||||
|
||||
std::unique_ptr<DomTreeNodeBase> addChild(
|
||||
std::unique_ptr<DomTreeNodeBase> C) {
|
||||
Children.push_back(C.get());
|
||||
return C;
|
||||
}
|
||||
|
||||
bool isLeaf() const { return Children.empty(); }
|
||||
size_t getNumChildren() const { return Children.size(); }
|
||||
|
||||
void clearAllChildren() { Children.clear(); }
|
||||
@ -619,7 +626,7 @@ protected:
|
||||
void eraseNode(NodeT *BB) {
|
||||
DomTreeNodeBase<NodeT> *Node = getNode(BB);
|
||||
assert(Node && "Removing node that isn't in dominator tree.");
|
||||
assert(Node->getChildren().empty() && "Node is not a leaf node.");
|
||||
assert(Node->isLeaf() && "Node is not a leaf node.");
|
||||
|
||||
DFSInfoValid = false;
|
||||
|
||||
|
@ -1396,7 +1396,7 @@ struct SemiNCAInfo {
|
||||
const TreeNodePtr Node = NodeToTN.second.get();
|
||||
|
||||
// Handle tree leaves.
|
||||
if (Node->getChildren().empty()) {
|
||||
if (Node->isLeaf()) {
|
||||
if (Node->getDFSNumIn() + 1 != Node->getDFSNumOut()) {
|
||||
errs() << "Tree leaf should have DFSOut = DFSIn + 1:\n\t";
|
||||
PrintNodeAndDFSNums(Node);
|
||||
@ -1508,7 +1508,8 @@ struct SemiNCAInfo {
|
||||
for (auto &NodeToTN : DT.DomTreeNodes) {
|
||||
const TreeNodePtr TN = NodeToTN.second.get();
|
||||
const NodePtr BB = TN->getBlock();
|
||||
if (!BB || TN->getChildren().empty()) continue;
|
||||
if (!BB || TN->isLeaf())
|
||||
continue;
|
||||
|
||||
LLVM_DEBUG(dbgs() << "Verifying parent property of node "
|
||||
<< BlockNamePrinter(TN) << "\n");
|
||||
@ -1517,7 +1518,7 @@ struct SemiNCAInfo {
|
||||
return From != BB && To != BB;
|
||||
});
|
||||
|
||||
for (TreeNodePtr Child : TN->getChildren())
|
||||
for (TreeNodePtr Child : TN->children())
|
||||
if (NodeToInfo.count(Child->getBlock()) != 0) {
|
||||
errs() << "Child " << BlockNamePrinter(Child)
|
||||
<< " reachable after its parent " << BlockNamePrinter(BB)
|
||||
@ -1541,17 +1542,17 @@ struct SemiNCAInfo {
|
||||
for (auto &NodeToTN : DT.DomTreeNodes) {
|
||||
const TreeNodePtr TN = NodeToTN.second.get();
|
||||
const NodePtr BB = TN->getBlock();
|
||||
if (!BB || TN->getChildren().empty()) continue;
|
||||
if (!BB || TN->isLeaf())
|
||||
continue;
|
||||
|
||||
const auto &Siblings = TN->getChildren();
|
||||
for (const TreeNodePtr N : Siblings) {
|
||||
for (const TreeNodePtr N : TN->children()) {
|
||||
clear();
|
||||
NodePtr BBN = N->getBlock();
|
||||
doFullDFSWalk(DT, [BBN](NodePtr From, NodePtr To) {
|
||||
return From != BBN && To != BBN;
|
||||
});
|
||||
|
||||
for (const TreeNodePtr S : Siblings) {
|
||||
for (const TreeNodePtr S : TN->children()) {
|
||||
if (S == N) continue;
|
||||
|
||||
if (NodeToInfo.count(S->getBlock()) == 0) {
|
||||
|
@ -759,7 +759,7 @@ void updateDomTree(MachineDominatorTree *DomTree, const SSAIfConv &IfConv,
|
||||
assert(Node != HeadNode && "Cannot erase the head node");
|
||||
while (Node->getNumChildren()) {
|
||||
assert(Node->getBlock() == IfConv.Tail && "Unexpected children");
|
||||
DomTree->changeImmediateDominator(Node->getChildren().back(), HeadNode);
|
||||
DomTree->changeImmediateDominator(Node->back(), HeadNode);
|
||||
}
|
||||
DomTree->eraseNode(B);
|
||||
}
|
||||
|
@ -1306,10 +1306,7 @@ void HoistSpillHelper::getVisitOrders(
|
||||
Orders.push_back(MDT.getBase().getNode(Root));
|
||||
do {
|
||||
MachineDomTreeNode *Node = Orders[idx++];
|
||||
const std::vector<MachineDomTreeNode *> &Children = Node->getChildren();
|
||||
unsigned NumChildren = Children.size();
|
||||
for (unsigned i = 0; i != NumChildren; ++i) {
|
||||
MachineDomTreeNode *Child = Children[i];
|
||||
for (MachineDomTreeNode *Child : Node->children()) {
|
||||
if (WorkSet.count(Child))
|
||||
Orders.push_back(Child);
|
||||
}
|
||||
@ -1377,10 +1374,7 @@ void HoistSpillHelper::runHoistSpills(
|
||||
|
||||
// Collect spills in subtree of current node (*RIt) to
|
||||
// SpillsInSubTreeMap[*RIt].first.
|
||||
const std::vector<MachineDomTreeNode *> &Children = (*RIt)->getChildren();
|
||||
unsigned NumChildren = Children.size();
|
||||
for (unsigned i = 0; i != NumChildren; ++i) {
|
||||
MachineDomTreeNode *Child = Children[i];
|
||||
for (MachineDomTreeNode *Child : (*RIt)->children()) {
|
||||
if (SpillsInSubTreeMap.find(Child) == SpillsInSubTreeMap.end())
|
||||
continue;
|
||||
// The stmt "SpillsInSubTree = SpillsInSubTreeMap[*RIt].first" below
|
||||
|
@ -747,9 +747,8 @@ bool MachineCSE::PerformCSE(MachineDomTreeNode *Node) {
|
||||
do {
|
||||
Node = WorkList.pop_back_val();
|
||||
Scopes.push_back(Node);
|
||||
const std::vector<MachineDomTreeNode*> &Children = Node->getChildren();
|
||||
OpenChildren[Node] = Children.size();
|
||||
for (MachineDomTreeNode *Child : Children)
|
||||
OpenChildren[Node] = Node->getNumChildren();
|
||||
for (MachineDomTreeNode *Child : Node->children())
|
||||
WorkList.push_back(Child);
|
||||
} while (!WorkList.empty());
|
||||
|
||||
@ -862,8 +861,7 @@ bool MachineCSE::PerformSimplePRE(MachineDominatorTree *DT) {
|
||||
BBs.push_back(DT->getRootNode());
|
||||
do {
|
||||
auto Node = BBs.pop_back_val();
|
||||
const std::vector<MachineDomTreeNode *> &Children = Node->getChildren();
|
||||
for (MachineDomTreeNode *Child : Children)
|
||||
for (MachineDomTreeNode *Child : Node->children())
|
||||
BBs.push_back(Child);
|
||||
|
||||
MachineBasicBlock *MBB = Node->getBlock();
|
||||
|
@ -737,8 +737,7 @@ void MachineLICMBase::HoistOutOfLoop(MachineDomTreeNode *HeaderN) {
|
||||
continue;
|
||||
|
||||
Scopes.push_back(Node);
|
||||
const std::vector<MachineDomTreeNode*> &Children = Node->getChildren();
|
||||
unsigned NumChildren = Children.size();
|
||||
unsigned NumChildren = Node->getNumChildren();
|
||||
|
||||
// Don't hoist things out of a large switch statement. This often causes
|
||||
// code to be hoisted that wasn't going to be executed, and increases
|
||||
@ -747,15 +746,16 @@ void MachineLICMBase::HoistOutOfLoop(MachineDomTreeNode *HeaderN) {
|
||||
NumChildren = 0;
|
||||
|
||||
OpenChildren[Node] = NumChildren;
|
||||
if (NumChildren) {
|
||||
// Add children in reverse order as then the next popped worklist node is
|
||||
// the first child of this node. This means we ultimately traverse the
|
||||
// DOM tree in exactly the same order as if we'd recursed.
|
||||
for (int i = (int)NumChildren-1; i >= 0; --i) {
|
||||
MachineDomTreeNode *Child = Children[i];
|
||||
for (MachineDomTreeNode *Child : reverse(Node->children())) {
|
||||
ParentMap[Child] = Node;
|
||||
WorkList.push_back(Child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Scopes.size() == 0)
|
||||
return;
|
||||
|
@ -623,14 +623,13 @@ MachineSinking::GetAllSortedSuccessors(MachineInstr &MI, MachineBasicBlock *MBB,
|
||||
// if () {} else {}
|
||||
// use x
|
||||
//
|
||||
const std::vector<MachineDomTreeNode *> &Children =
|
||||
DT->getNode(MBB)->getChildren();
|
||||
for (const auto &DTChild : Children)
|
||||
for (MachineDomTreeNode *DTChild : DT->getNode(MBB)->children()) {
|
||||
// DomTree children of MBB that have MBB as immediate dominator are added.
|
||||
if (DTChild->getIDom()->getBlock() == MI.getParent() &&
|
||||
// Skip MBBs already added to the AllSuccs vector above.
|
||||
!MBB->isSuccessor(DTChild->getBlock()))
|
||||
AllSuccs.push_back(DTChild->getBlock());
|
||||
}
|
||||
|
||||
// Sort Successors according to their loop depth or block frequency info.
|
||||
llvm::stable_sort(
|
||||
|
@ -828,7 +828,7 @@ void AArch64ConditionalCompares::updateDomTree(
|
||||
assert(Node != HeadNode && "Cannot erase the head node");
|
||||
assert(Node->getIDom() == HeadNode && "CmpBB should be dominated by Head");
|
||||
while (Node->getNumChildren())
|
||||
DomTree->changeImmediateDominator(Node->getChildren().back(), HeadNode);
|
||||
DomTree->changeImmediateDominator(Node->back(), HeadNode);
|
||||
DomTree->eraseNode(RemovedMBB);
|
||||
}
|
||||
}
|
||||
|
@ -218,8 +218,7 @@ bool OptimizePICCall::runOnMachineFunction(MachineFunction &F) {
|
||||
MBBI.preVisit(ScopedHT);
|
||||
Changed |= visitNode(MBBI);
|
||||
const MachineDomTreeNode *Node = MBBI.getNode();
|
||||
const std::vector<MachineDomTreeNode *> &Children = Node->getChildren();
|
||||
WorkList.append(Children.begin(), Children.end());
|
||||
WorkList.append(Node->begin(), Node->end());
|
||||
}
|
||||
|
||||
return Changed;
|
||||
|
@ -250,7 +250,7 @@ static void findBestInsertionSet(DominatorTree &DT, BlockFrequencyInfo &BFI,
|
||||
Orders.push_back(Entry);
|
||||
while (Idx != Orders.size()) {
|
||||
BasicBlock *Node = Orders[Idx++];
|
||||
for (auto ChildDomNode : DT.getNode(Node)->getChildren()) {
|
||||
for (auto ChildDomNode : DT.getNode(Node)->children()) {
|
||||
if (Candidates.count(ChildDomNode->getBlock()))
|
||||
Orders.push_back(ChildDomNode->getBlock());
|
||||
}
|
||||
|
@ -3436,7 +3436,7 @@ bool NewGVN::runGVN() {
|
||||
// Sort dominator tree children arrays into RPO.
|
||||
for (auto &B : RPOT) {
|
||||
auto *Node = DT->getNode(B);
|
||||
if (Node->getChildren().size() > 1)
|
||||
if (Node->getNumChildren() > 1)
|
||||
llvm::sort(Node->begin(), Node->end(),
|
||||
[&](const DomTreeNode *A, const DomTreeNode *B) {
|
||||
return RPOOrdering[A] < RPOOrdering[B];
|
||||
|
@ -696,10 +696,8 @@ ReprocessLoop:
|
||||
LI->removeBlock(ExitingBlock);
|
||||
|
||||
DomTreeNode *Node = DT->getNode(ExitingBlock);
|
||||
const std::vector<DomTreeNodeBase<BasicBlock> *> &Children =
|
||||
Node->getChildren();
|
||||
while (!Children.empty()) {
|
||||
DomTreeNode *Child = Children.front();
|
||||
while (!Node->isLeaf()) {
|
||||
DomTreeNode *Child = Node->back();
|
||||
DT->changeImmediateDominator(Child, Node->getIDom());
|
||||
}
|
||||
DT->eraseNode(ExitingBlock);
|
||||
|
@ -809,7 +809,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
|
||||
for (auto *BB : OriginalLoopBlocks) {
|
||||
auto *BBDomNode = DT->getNode(BB);
|
||||
SmallVector<BasicBlock *, 16> ChildrenToUpdate;
|
||||
for (auto *ChildDomNode : BBDomNode->getChildren()) {
|
||||
for (auto *ChildDomNode : BBDomNode->children()) {
|
||||
auto *ChildBB = ChildDomNode->getBlock();
|
||||
if (!L->contains(ChildBB))
|
||||
ChildrenToUpdate.push_back(ChildBB);
|
||||
|
@ -848,7 +848,7 @@ bool llvm::UnrollRuntimeLoopRemainder(
|
||||
// dominator of the exit blocks.
|
||||
for (auto *BB : L->blocks()) {
|
||||
auto *DomNodeBB = DT->getNode(BB);
|
||||
for (auto *DomChild : DomNodeBB->getChildren()) {
|
||||
for (auto *DomChild : DomNodeBB->children()) {
|
||||
auto *DomChildBB = DomChild->getBlock();
|
||||
if (!L->contains(LI->getLoopFor(DomChildBB)))
|
||||
ChildrenToUpdate.push_back(DomChildBB);
|
||||
|
@ -512,9 +512,10 @@ llvm::collectChildrenInLoop(DomTreeNode *N, const Loop *CurLoop) {
|
||||
|
||||
AddRegionToWorklist(N);
|
||||
|
||||
for (size_t I = 0; I < Worklist.size(); I++)
|
||||
for (DomTreeNode *Child : Worklist[I]->getChildren())
|
||||
for (size_t I = 0; I < Worklist.size(); I++) {
|
||||
for (DomTreeNode *Child : Worklist[I]->children())
|
||||
AddRegionToWorklist(Child);
|
||||
}
|
||||
|
||||
return Worklist;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user