@@ -65,7 +65,7 @@ struct SemiNCAInfo {
65
65
unsigned DFSNum = 0 ;
66
66
unsigned Parent = 0 ;
67
67
unsigned Semi = 0 ;
68
- NodePtr Label = nullptr ;
68
+ unsigned Label = 0 ;
69
69
NodePtr IDom = nullptr ;
70
70
SmallVector<NodePtr, 2 > ReverseChildren;
71
71
};
@@ -189,8 +189,7 @@ struct SemiNCAInfo {
189
189
190
190
// Visited nodes always have positive DFS numbers.
191
191
if (BBInfo.DFSNum != 0 ) continue ;
192
- BBInfo.DFSNum = BBInfo.Semi = ++LastNum;
193
- BBInfo.Label = BB;
192
+ BBInfo.DFSNum = BBInfo.Semi = BBInfo.Label = ++LastNum;
194
193
NumToNode.push_back (BB);
195
194
196
195
constexpr bool Direction = IsReverse != IsPostDom; // XOR.
@@ -237,8 +236,9 @@ struct SemiNCAInfo {
237
236
//
238
237
// For each vertex V, its Label points to the vertex with the minimal sdom(U)
239
238
// (Semi) in its path from V (included) to NodeToInfo[V].Parent (excluded).
240
- NodePtr eval (NodePtr V, unsigned LastLinked,
241
- SmallVectorImpl<InfoRec *> &Stack) {
239
+ unsigned eval (NodePtr V, unsigned LastLinked,
240
+ SmallVectorImpl<InfoRec *> &Stack,
241
+ ArrayRef<InfoRec *> NumToInfo) {
242
242
InfoRec *VInfo = &NodeToInfo[V];
243
243
if (VInfo->Parent < LastLinked)
244
244
return VInfo->Label ;
@@ -247,17 +247,17 @@ struct SemiNCAInfo {
247
247
assert (Stack.empty ());
248
248
do {
249
249
Stack.push_back (VInfo);
250
- VInfo = &NodeToInfo[NumToNode[ VInfo->Parent ] ];
250
+ VInfo = NumToInfo[ VInfo->Parent ];
251
251
} while (VInfo->Parent >= LastLinked);
252
252
253
253
// Path compression. Point each vertex's Parent to the root and update its
254
254
// Label if any of its ancestors (PInfo->Label) has a smaller Semi.
255
255
const InfoRec *PInfo = VInfo;
256
- const InfoRec *PLabelInfo = &NodeToInfo [PInfo->Label ];
256
+ const InfoRec *PLabelInfo = NumToInfo [PInfo->Label ];
257
257
do {
258
258
VInfo = Stack.pop_back_val ();
259
259
VInfo->Parent = PInfo->Parent ;
260
- const InfoRec *VLabelInfo = &NodeToInfo [VInfo->Label ];
260
+ const InfoRec *VLabelInfo = NumToInfo [VInfo->Label ];
261
261
if (PLabelInfo->Semi < VLabelInfo->Semi )
262
262
VInfo->Label = PInfo->Label ;
263
263
else
@@ -270,18 +270,20 @@ struct SemiNCAInfo {
270
270
// This function requires DFS to be run before calling it.
271
271
void runSemiNCA (DomTreeT &DT, const unsigned MinLevel = 0 ) {
272
272
const unsigned NextDFSNum (NumToNode.size ());
273
+ SmallVector<InfoRec *, 8 > NumToInfo = {nullptr };
274
+ NumToInfo.reserve (NextDFSNum);
273
275
// Initialize IDoms to spanning tree parents.
274
276
for (unsigned i = 1 ; i < NextDFSNum; ++i) {
275
277
const NodePtr V = NumToNode[i];
276
278
auto &VInfo = NodeToInfo[V];
277
279
VInfo.IDom = NumToNode[VInfo.Parent ];
280
+ NumToInfo.push_back (&VInfo);
278
281
}
279
282
280
283
// Step #1: Calculate the semidominators of all vertices.
281
284
SmallVector<InfoRec *, 32 > EvalStack;
282
285
for (unsigned i = NextDFSNum - 1 ; i >= 2 ; --i) {
283
- NodePtr W = NumToNode[i];
284
- auto &WInfo = NodeToInfo[W];
286
+ auto &WInfo = *NumToInfo[i];
285
287
286
288
// Initialize the semi dominator to point to the parent node.
287
289
WInfo.Semi = WInfo.Parent ;
@@ -294,7 +296,7 @@ struct SemiNCAInfo {
294
296
if (TN && TN->getLevel () < MinLevel)
295
297
continue ;
296
298
297
- unsigned SemiU = NodeToInfo [eval (N, i + 1 , EvalStack)]. Semi ;
299
+ unsigned SemiU = NumToInfo [eval (N, i + 1 , EvalStack, NumToInfo)]-> Semi ;
298
300
if (SemiU < WInfo.Semi ) WInfo.Semi = SemiU;
299
301
}
300
302
}
@@ -304,8 +306,7 @@ struct SemiNCAInfo {
304
306
// Note that the parents were stored in IDoms and later got invalidated
305
307
// during path compression in Eval.
306
308
for (unsigned i = 2 ; i < NextDFSNum; ++i) {
307
- const NodePtr W = NumToNode[i];
308
- auto &WInfo = NodeToInfo[W];
309
+ auto &WInfo = *NumToInfo[i];
309
310
const unsigned SDomNum = NodeToInfo[NumToNode[WInfo.Semi ]].DFSNum ;
310
311
NodePtr WIDomCandidate = WInfo.IDom ;
311
312
while (NodeToInfo[WIDomCandidate].DFSNum > SDomNum)
@@ -325,8 +326,7 @@ struct SemiNCAInfo {
325
326
assert (NumToNode.size () == 1 && " SNCAInfo must be freshly constructed" );
326
327
327
328
auto &BBInfo = NodeToInfo[nullptr ];
328
- BBInfo.DFSNum = BBInfo.Semi = 1 ;
329
- BBInfo.Label = nullptr ;
329
+ BBInfo.DFSNum = BBInfo.Semi = BBInfo.Label = 1 ;
330
330
331
331
NumToNode.push_back (nullptr ); // NumToNode[1] = nullptr;
332
332
}
0 commit comments