[llvm] [Support] Store dominator tree nodes in a vector (PR #101705)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 2 11:32:01 PDT 2024
================
@@ -786,17 +837,54 @@ class DominatorTreeBase {
DFSInfoValid = true;
}
+private:
+ template <class T_ = NodeT>
+ std::enable_if_t<is_detected<has_number_t, T_>::value, void>
+ updateBlockNumberEpoch() {
+ BlockNumberEpoch = GraphTraits<ParentPtr>::getNumberEpoch(Parent);
+ }
+
+ template <class T_ = NodeT>
+ std::enable_if_t<!is_detected<has_number_t, T_>::value, void>
+ updateBlockNumberEpoch() {
+ // Nothing to do for graphs that don't number their blocks.
+ }
+
+public:
/// recalculate - compute a dominator tree for the given function
void recalculate(ParentType &Func) {
Parent = &Func;
+ updateBlockNumberEpoch();
DomTreeBuilder::Calculate(*this);
}
void recalculate(ParentType &Func, ArrayRef<UpdateType> Updates) {
Parent = &Func;
+ updateBlockNumberEpoch();
DomTreeBuilder::CalculateWithUpdates(*this, Updates);
}
+ /// Update dominator tree after renumbering blocks
+ template <class T_ = NodeT>
+ std::enable_if_t<is_detected<has_number_t, T_>::value, void>
+ updateBlockNumbers() {
+ updateBlockNumberEpoch();
+
+ unsigned MaxNumber = GraphTraits<ParentPtr>::getMaxNumber(Parent);
+ DomTreeNodeStorageTy NewVector;
+ NewVector.resize(MaxNumber + 1); // +1, because index 0 is for nullptr
+ for (auto &Node : DomTreeNodes) {
+ if (!Node)
+ continue;
+ unsigned Idx = *getNodeIndex(Node->getBlock());
+ // getMaxNumber is not necssarily supported
----------------
nikic wrote:
```suggestion
// getMaxNumber is not necessarily supported
```
https://github.com/llvm/llvm-project/pull/101705
More information about the llvm-commits
mailing list