Skip to content

Commit aefca74

Browse files
authored
[DomTree] Store ReverseChildren as indices (NFC) (#73505)
Store the ReverseChildren using node indices instead of node pointers. This avoids some more hash table lookups. I've also increased the size of the SmallVector from 2 to 4. As the indices are half as large as the pointers (on 64bit) this keeps memory usage the same as before. I've found the larger SmallVector to perform a bit better.
1 parent 4cf4c52 commit aefca74

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

llvm/include/llvm/Support/GenericDomTreeConstruction.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct SemiNCAInfo {
6767
unsigned Semi = 0;
6868
unsigned Label = 0;
6969
NodePtr IDom = nullptr;
70-
SmallVector<NodePtr, 2> ReverseChildren;
70+
SmallVector<unsigned, 4> ReverseChildren;
7171
};
7272

7373
// Number to node mapping is 1-based. Initialize the mapping to start with
@@ -205,7 +205,7 @@ struct SemiNCAInfo {
205205
// Don't visit nodes more than once but remember to collect
206206
// ReverseChildren.
207207
if (SIT != NodeToInfo.end() && SIT->second.DFSNum != 0) {
208-
if (Succ != BB) SIT->second.ReverseChildren.push_back(BB);
208+
if (Succ != BB) SIT->second.ReverseChildren.push_back(LastNum);
209209
continue;
210210
}
211211

@@ -216,7 +216,7 @@ struct SemiNCAInfo {
216216
auto &SuccInfo = NodeToInfo[Succ];
217217
WorkList.push_back(Succ);
218218
SuccInfo.Parent = LastNum;
219-
SuccInfo.ReverseChildren.push_back(BB);
219+
SuccInfo.ReverseChildren.push_back(LastNum);
220220
}
221221
}
222222

@@ -236,10 +236,10 @@ struct SemiNCAInfo {
236236
//
237237
// For each vertex V, its Label points to the vertex with the minimal sdom(U)
238238
// (Semi) in its path from V (included) to NodeToInfo[V].Parent (excluded).
239-
unsigned eval(NodePtr V, unsigned LastLinked,
239+
unsigned eval(unsigned V, unsigned LastLinked,
240240
SmallVectorImpl<InfoRec *> &Stack,
241241
ArrayRef<InfoRec *> NumToInfo) {
242-
InfoRec *VInfo = &NodeToInfo[V];
242+
InfoRec *VInfo = NumToInfo[V];
243243
if (VInfo->Parent < LastLinked)
244244
return VInfo->Label;
245245

@@ -287,10 +287,7 @@ struct SemiNCAInfo {
287287

288288
// Initialize the semi dominator to point to the parent node.
289289
WInfo.Semi = WInfo.Parent;
290-
for (const auto &N : WInfo.ReverseChildren) {
291-
assert(NodeToInfo.contains(N) &&
292-
"ReverseChildren should not contain unreachable predecessors");
293-
290+
for (unsigned N : WInfo.ReverseChildren) {
294291
unsigned SemiU = NumToInfo[eval(N, i + 1, EvalStack, NumToInfo)]->Semi;
295292
if (SemiU < WInfo.Semi) WInfo.Semi = SemiU;
296293
}

0 commit comments

Comments
 (0)