@@ -112,40 +112,27 @@ DeSSA::DeSSA() : FunctionPass( ID )
112
112
void DeSSA::print (raw_ostream &OS, const Module* ) const
113
113
{
114
114
Banner (OS, " Phi-Var Isolations" );
115
- DenseMap<Node*, int > LeaderVisited;
116
115
for (auto I = RegNodeMap.begin (),
117
116
E = RegNodeMap.end (); I != E; ++I) {
118
- Node* N = I->second ;
119
- // We don't want to change behavior of DeSSA by invoking
120
- // dumping/printing functions. Thus, don't use getLeader()
121
- // as it has side-effect (doing path halving).
122
- Node* Leader = N->parent ;
123
- while (Leader != Leader->parent ) {
124
- Leader = Leader->parent ;
125
- }
126
- if (LeaderVisited.count (Leader)) {
127
- continue ;
117
+ Value *VL = I->first ;
118
+ Value *RootV = getRegRoot (VL);
119
+ if (RootV) {
120
+ VL->print (IGC::Debug::ods ());
121
+ OS << " : " ;
122
+ RootV->print (IGC::Debug::ods ());
128
123
}
129
- LeaderVisited[Leader] = 1 ;
130
- Value *VL;
131
- if (isIsolated (N)) {
132
- VL = N->value ;
124
+ else {
133
125
OS << " Var isolated : " ;
134
126
VL->print (IGC::Debug::ods ());
135
- OS << " \n " ;
136
- } else {
137
- OS << " Leader : " ;
138
- Leader->value ->print (IGC::Debug::ods ());
139
- OS << " \n " ;
140
- N = Leader->next ;
141
- while (N != Leader) {
142
- VL = N->value ;
143
- OS << " " ;
127
+ }
128
+ PHINode *PHI = dyn_cast<PHINode>(VL);
129
+ if (PHI) {
130
+ if (isPHIIsolated (PHI)) {
131
+ OS << " \n PHI isolated : " ;
144
132
VL->print (IGC::Debug::ods ());
145
- OS << " \n " ;
146
- N = N->next ;
147
133
}
148
134
}
135
+ OS << " \n " ;
149
136
}
150
137
}
151
138
@@ -301,7 +288,7 @@ bool DeSSA::runOnFunction(Function &MF)
301
288
// isolate complex type that IGC does not handle
302
289
if (PHI->getType ()->isStructTy () ||
303
290
PHI->getType ()->isArrayTy ()) {
304
- isolateReg (PHI);
291
+ isolatePHI (PHI);
305
292
}
306
293
}
307
294
}
@@ -341,14 +328,14 @@ void DeSSA::MapAddReg(MapVector<Value*, Node*> &Map, Value *Val, e_alignment Ali
341
328
DeSSA::Node*
342
329
DeSSA::Node::getLeader () {
343
330
Node *N = this ;
344
- Node *Parent = parent;
345
- Node *Grandparent = Parent->parent ;
331
+ Node *Parent = parent. getPointer () ;
332
+ Node *Grandparent = Parent->parent . getPointer () ;
346
333
347
334
while (Parent != Grandparent) {
348
- N->parent = Grandparent;
335
+ N->parent . setPointer ( Grandparent) ;
349
336
N = Grandparent;
350
- Parent = N->parent ;
351
- Grandparent = Parent->parent ;
337
+ Parent = N->parent . getPointer () ;
338
+ Grandparent = Parent->parent . getPointer () ;
352
339
}
353
340
354
341
return Parent;
@@ -357,10 +344,10 @@ DeSSA::Node::getLeader() {
357
344
Value* DeSSA::getRegRoot (Value* Val, e_alignment *pAlign) const {
358
345
auto RI = RegNodeMap.find (Val);
359
346
if (RI == RegNodeMap.end ())
360
- return nullptr ;
347
+ return 0 ;
361
348
Node *TheNode = RI->second ;
362
- if (isIsolated ( TheNode) )
363
- return nullptr ;
349
+ if (TheNode-> parent . getInt () & Node:: kRegisterIsolatedFlag )
350
+ return 0x0 ;
364
351
Node *TheLeader = TheNode->getLeader ();
365
352
if (pAlign)
366
353
*pAlign = TheLeader->alignment ;
@@ -373,7 +360,8 @@ int DeSSA::getRootColor(Value* V)
373
360
if (RI == RegNodeMap.end ())
374
361
return 0 ;
375
362
Node *TheNode = RI->second ;
376
- if (isIsolated (TheNode))
363
+ if (TheNode->parent .getInt () &
364
+ (Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag ))
377
365
return 0 ;
378
366
Node *TheLeader = TheNode->getLeader ();
379
367
return TheLeader->color ;
@@ -388,15 +376,15 @@ void DeSSA::MapUnionRegs(MapVector<Value*, Node*> &Map, Value* Val1, Value* Val2
388
376
if (Node1->rank > Node2->rank ) {
389
377
NewLeader = Node1->getLeader ();
390
378
Leadee = Node2;
391
- Node2->parent = NewLeader;
379
+ Node2->parent . setPointer ( NewLeader) ;
392
380
} else if (Node1->rank < Node2->rank ) {
393
381
NewLeader = Node2->getLeader ();
394
382
Leadee = Node1;
395
- Node1->parent = NewLeader;
383
+ Node1->parent . setPointer ( NewLeader) ;
396
384
} else if (Node1 != Node2) {
397
385
NewLeader = Node1->getLeader ();
398
386
Leadee = Node2;
399
- Node2->parent = NewLeader;
387
+ Node2->parent . setPointer ( NewLeader) ;
400
388
Node1->rank ++;
401
389
}
402
390
@@ -416,6 +404,7 @@ void DeSSA::MapUnionRegs(MapVector<Value*, Node*> &Map, Value* Val1, Value* Val2
416
404
void DeSSA::isolateReg (Value* Val) {
417
405
Node *Node = RegNodeMap[Val];
418
406
splitNode (Node);
407
+ Node->parent .setInt (Node->parent .getInt () | Node::kRegisterIsolatedFlag );
419
408
}
420
409
421
410
Value* DeSSA::getOrigRoot (Instruction *PHI) const {
@@ -426,13 +415,30 @@ Value* DeSSA::getOrigRoot(Instruction *PHI) const {
426
415
return DestNode->getLeader ()->value ;
427
416
}
428
417
429
- bool DeSSA::isIsolated (Value *V) const {
430
- auto RI = RegNodeMap.find (V);
431
- if (RI == RegNodeMap.end ()) {
432
- return true ;
433
- }
418
+ Value* DeSSA::getPHIRoot (Instruction *PHI) const {
419
+ assert (dyn_cast<PHINode>(PHI));
420
+ auto RI = RegNodeMap.find (PHI);
421
+ assert (RI != RegNodeMap.end ());
422
+ Node *DestNode = RI->second ;
423
+ if (DestNode->parent .getInt () & Node::kPHIIsolatedFlag )
424
+ return 0x0 ;
425
+ if (DestNode->parent .getInt () & Node::kRegisterIsolatedFlag )
426
+ return 0x0 ;
427
+ return DestNode->getLeader ()->value ;
428
+ }
429
+
430
+ void DeSSA::isolatePHI (Instruction *PHI) {
431
+ assert (isa<PHINode>(PHI));
432
+ Node *Node = RegNodeMap[PHI];
433
+ splitNode (Node);
434
+ Node->parent .setInt (Node->parent .getInt () | Node::kPHIIsolatedFlag );
435
+ }
436
+
437
+ bool DeSSA::isPHIIsolated (Instruction *PHI) const {
438
+ auto RI = RegNodeMap.find (PHI);
439
+ assert (RI != RegNodeMap.end ());
434
440
Node *DestNode = RI->second ;
435
- return isIsolated ( DestNode);
441
+ return (( DestNode-> parent . getInt () & Node:: kPHIIsolatedFlag ) > 0 ? true : false );
436
442
}
437
443
438
444
// Split node ND from its existing congurent class, and the
@@ -453,7 +459,7 @@ void DeSSA::splitNode(Node* ND)
453
459
P->next = N;
454
460
455
461
// ND : a new single-value congruent class
456
- ND->parent = ND ;
462
+ ND->parent . setPointer (ND) ;
457
463
ND->next = ND;
458
464
ND->prev = ND;
459
465
ND->rank = 0 ;
@@ -477,11 +483,11 @@ void DeSSA::splitNode(Node* ND)
477
483
// always to set "Leader' as the new leader, so that all nodes
478
484
// within a same congruent class remains in the same rooted tree.
479
485
N = Leader->next ;
480
- Leader->parent = Leader;
486
+ Leader->parent . setPointer ( Leader) ;
481
487
Leader->rank = (Leader == N) ? 0 : 1 ;
482
488
while (N != Leader)
483
489
{
484
- N->parent = Leader;
490
+ N->parent . setPointer ( Leader) ;
485
491
N->rank = 0 ;
486
492
N = N->next ;
487
493
}
@@ -647,7 +653,7 @@ DeSSA::SplitInterferencesForBasicBlock(
647
653
// could possibly be improved, e.g. we could isolate the PHI with the
648
654
// fewest operands.
649
655
if (CurrentPHI.first && CurrentPHI.second != PredValue) {
650
- isolateReg (PHI);
656
+ isolatePHI (PHI);
651
657
continue ;
652
658
}
653
659
else {
@@ -723,7 +729,7 @@ void DeSSA::SplitInterferencesForAlignment()
723
729
{
724
730
// Find a root Node
725
731
Node *rootNode = I->second ;
726
- if (rootNode->parent != rootNode) {
732
+ if (rootNode->parent . getPointer () != rootNode) {
727
733
continue ;
728
734
}
729
735
@@ -734,6 +740,13 @@ void DeSSA::SplitInterferencesForAlignment()
734
740
do {
735
741
Curr = N;
736
742
N = Curr->next ;
743
+
744
+ // Skip isolated reg.
745
+ if (Curr->parent .getInt () &
746
+ (Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag )) {
747
+ continue ;
748
+ }
749
+
737
750
if (Curr->alignment == EALIGN_GRF) {
738
751
Align = EALIGN_GRF;
739
752
break ;
@@ -752,6 +765,13 @@ void DeSSA::SplitInterferencesForAlignment()
752
765
do {
753
766
Curr = N;
754
767
N = N->next ;
768
+
769
+ // Skip isolated reg.
770
+ if (Curr->parent .getInt () &
771
+ (Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag )) {
772
+ continue ;
773
+ }
774
+
755
775
if (Curr->alignment != EALIGN_AUTO && Curr->alignment != EALIGN_GRF)
756
776
{
757
777
assert (Curr != Head && " Head Node cannot be isolated, something wrong!" );
@@ -867,6 +887,11 @@ void DeSSA::getAllValuesInCongruentClass(
867
887
Node* First = RI->second ;
868
888
Node* N = First->next ;
869
889
do {
890
+ if (N->parent .getInt () &
891
+ (Node::kPHIIsolatedFlag | Node::kRegisterIsolatedFlag )) {
892
+ N = N->next ;
893
+ continue ;
894
+ }
870
895
if (rootV != N->value ) {
871
896
// No duplicate Value in ValsInCC
872
897
ValsInCC.push_back (N->value );
0 commit comments