[llvm] 55669ac - [Support][NFC] Use single predecessor array in DomTreeConstr (#207535)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 5 00:33:45 PDT 2026
Author: Alexis Engelke
Date: 2026-07-05T07:33:40Z
New Revision: 55669ac2f7df5e54561a3c36df6322a6318cb575
URL: https://github.com/llvm/llvm-project/commit/55669ac2f7df5e54561a3c36df6322a6318cb575
DIFF: https://github.com/llvm/llvm-project/commit/55669ac2f7df5e54561a3c36df6322a6318cb575.diff
LOG: [Support][NFC] Use single predecessor array in DomTreeConstr (#207535)
Storing many small vectors of predecessors is bad for performance, as
each of these has to be non-trivially initialized when growing the
NodeInfos vector. Therefore, store all predecessors in a separate
vector, in which predecessors form a linked list.
Added:
Modified:
llvm/include/llvm/Support/GenericDomTreeConstruction.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/GenericDomTreeConstruction.h b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
index 869087cda219a..54595cf27e4b2 100644
--- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h
+++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
@@ -66,7 +66,7 @@ template <typename DomTreeT> struct SemiNCAInfo {
unsigned Semi = 0;
unsigned Label = 0;
NodePtr IDom = nullptr;
- SmallVector<unsigned, 4> ReverseChildren;
+ unsigned ReverseChildrenStart = 0; ///< Index in ReverseChildren vector.
};
// Number to node mapping is 1-based. Initialize the mapping to start with
@@ -78,6 +78,10 @@ template <typename DomTreeT> struct SemiNCAInfo {
DenseMap<NodePtr, InfoRec>>
NodeInfos;
+ /// Reverse children of nodes; pairs of (DFSNum (predecessor), next-or-zero);
+ /// forms a linked list in this vector; first entry is sentinel.
+ SmallVector<std::pair<unsigned, unsigned>, 32> ReverseChildren = {{0, 0}};
+
using UpdateT = typename DomTreeT::UpdateType;
using UpdateKind = typename DomTreeT::UpdateKind;
struct BatchUpdateInfo {
@@ -209,7 +213,8 @@ template <typename DomTreeT> struct SemiNCAInfo {
while (!WorkList.empty()) {
const auto [BB, ParentNum] = WorkList.pop_back_val();
auto &BBInfo = getNodeInfo(BB);
- BBInfo.ReverseChildren.push_back(ParentNum);
+ ReverseChildren.emplace_back(ParentNum, BBInfo.ReverseChildrenStart);
+ BBInfo.ReverseChildrenStart = ReverseChildren.size() - 1;
// Visited nodes always have positive DFS numbers.
if (BBInfo.DFSNum != 0)
@@ -314,8 +319,11 @@ template <typename DomTreeT> struct SemiNCAInfo {
// Initialize the semi dominator to point to the parent node.
WInfo.Semi = WInfo.Parent;
- for (unsigned N : WInfo.ReverseChildren) {
- unsigned SemiU = NumToInfo[eval(N, i + 1, EvalStack, NumToInfo)]->Semi;
+ for (unsigned RCIdx = WInfo.ReverseChildrenStart; RCIdx != 0;) {
+ const auto &Entry = ReverseChildren[RCIdx];
+ RCIdx = Entry.second;
+ unsigned SemiU =
+ NumToInfo[eval(Entry.first, i + 1, EvalStack, NumToInfo)]->Semi;
if (SemiU < WInfo.Semi)
WInfo.Semi = SemiU;
}
More information about the llvm-commits
mailing list