Skip to content

[llvm] Add NCD search on Array of basic blocks (NFC) #119355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions llvm/include/llvm/Support/GenericDomTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,22 @@ class DominatorTreeBase {
return isPostDominator() && !A->getBlock();
}

template <typename IteratorTy>
NodeT *findNearestCommonDominator(iterator_range<IteratorTy> Nodes) const {
assert(!Nodes.empty() && "Nodes list is empty!");

NodeT *NCD = *Nodes.begin();
for (NodeT *Node : llvm::drop_begin(Nodes)) {
NCD = findNearestCommonDominator(NCD, Node);

// Stop when the root is reached.
if (isVirtualRoot(getNode(NCD)))
return nullptr;
}

return NCD;
}

//===--------------------------------------------------------------------===//
// API to update (Post)DominatorTree information based on modifications to
// the CFG...
Expand Down
7 changes: 1 addition & 6 deletions llvm/lib/CodeGen/ShrinkWrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,7 @@ bool ShrinkWrap::useOrDefCSROrFI(const MachineInstr &MI, RegScavenger *RS,
template <typename ListOfBBs, typename DominanceAnalysis>
static MachineBasicBlock *FindIDom(MachineBasicBlock &Block, ListOfBBs BBs,
DominanceAnalysis &Dom, bool Strict = true) {
MachineBasicBlock *IDom = &Block;
for (MachineBasicBlock *BB : BBs) {
IDom = Dom.findNearestCommonDominator(IDom, BB);
if (!IDom)
break;
}
MachineBasicBlock *IDom = Dom.findNearestCommonDominator(iterator_range(BBs));
if (Strict && IDom == &Block)
return nullptr;
return IDom;
Expand Down
Loading