@@ -112,40 +112,27 @@ DeSSA::DeSSA() : FunctionPass( ID )
112112void DeSSA::print (raw_ostream &OS, const Module* ) const
113113{
114114 Banner (OS, " Phi-Var Isolations" );
115- DenseMap<Node*, int > LeaderVisited;
116115 for (auto I = RegNodeMap.begin (),
117116 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 ());
128123 }
129- LeaderVisited[Leader] = 1 ;
130- Value *VL;
131- if (isIsolated (N)) {
132- VL = N->value ;
124+ else {
133125 OS << " Var isolated : " ;
134126 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 : " ;
144132 VL->print (IGC::Debug::ods ());
145- OS << " \n " ;
146- N = N->next ;
147133 }
148134 }
135+ OS << " \n " ;
149136 }
150137}
151138
@@ -301,7 +288,7 @@ bool DeSSA::runOnFunction(Function &MF)
301288 // isolate complex type that IGC does not handle
302289 if (PHI->getType ()->isStructTy () ||
303290 PHI->getType ()->isArrayTy ()) {
304- isolateReg (PHI);
291+ isolatePHI (PHI);
305292 }
306293 }
307294 }
@@ -341,14 +328,14 @@ void DeSSA::MapAddReg(MapVector<Value*, Node*> &Map, Value *Val, e_alignment Ali
341328DeSSA::Node*
342329DeSSA::Node::getLeader () {
343330 Node *N = this ;
344- Node *Parent = parent;
345- Node *Grandparent = Parent->parent ;
331+ Node *Parent = parent. getPointer () ;
332+ Node *Grandparent = Parent->parent . getPointer () ;
346333
347334 while (Parent != Grandparent) {
348- N->parent = Grandparent;
335+ N->parent . setPointer ( Grandparent) ;
349336 N = Grandparent;
350- Parent = N->parent ;
351- Grandparent = Parent->parent ;
337+ Parent = N->parent . getPointer () ;
338+ Grandparent = Parent->parent . getPointer () ;
352339 }
353340
354341 return Parent;
@@ -357,10 +344,10 @@ DeSSA::Node::getLeader() {
357344Value* DeSSA::getRegRoot (Value* Val, e_alignment *pAlign) const {
358345 auto RI = RegNodeMap.find (Val);
359346 if (RI == RegNodeMap.end ())
360- return nullptr ;
347+ return 0 ;
361348 Node *TheNode = RI->second ;
362- if (isIsolated ( TheNode) )
363- return nullptr ;
349+ if (TheNode-> parent . getInt () & Node:: kRegisterIsolatedFlag )
350+ return 0x0 ;
364351 Node *TheLeader = TheNode->getLeader ();
365352 if (pAlign)
366353 *pAlign = TheLeader->alignment ;
@@ -373,7 +360,8 @@ int DeSSA::getRootColor(Value* V)
373360 if (RI == RegNodeMap.end ())
374361 return 0 ;
375362 Node *TheNode = RI->second ;
376- if (isIsolated (TheNode))
363+ if (TheNode->parent .getInt () &
364+ (Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag ))
377365 return 0 ;
378366 Node *TheLeader = TheNode->getLeader ();
379367 return TheLeader->color ;
@@ -388,15 +376,15 @@ void DeSSA::MapUnionRegs(MapVector<Value*, Node*> &Map, Value* Val1, Value* Val2
388376 if (Node1->rank > Node2->rank ) {
389377 NewLeader = Node1->getLeader ();
390378 Leadee = Node2;
391- Node2->parent = NewLeader;
379+ Node2->parent . setPointer ( NewLeader) ;
392380 } else if (Node1->rank < Node2->rank ) {
393381 NewLeader = Node2->getLeader ();
394382 Leadee = Node1;
395- Node1->parent = NewLeader;
383+ Node1->parent . setPointer ( NewLeader) ;
396384 } else if (Node1 != Node2) {
397385 NewLeader = Node1->getLeader ();
398386 Leadee = Node2;
399- Node2->parent = NewLeader;
387+ Node2->parent . setPointer ( NewLeader) ;
400388 Node1->rank ++;
401389 }
402390
@@ -416,6 +404,7 @@ void DeSSA::MapUnionRegs(MapVector<Value*, Node*> &Map, Value* Val1, Value* Val2
416404void DeSSA::isolateReg (Value* Val) {
417405 Node *Node = RegNodeMap[Val];
418406 splitNode (Node);
407+ Node->parent .setInt (Node->parent .getInt () | Node::kRegisterIsolatedFlag );
419408}
420409
421410Value* DeSSA::getOrigRoot (Instruction *PHI) const {
@@ -426,13 +415,30 @@ Value* DeSSA::getOrigRoot(Instruction *PHI) const {
426415 return DestNode->getLeader ()->value ;
427416}
428417
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 ());
434440 Node *DestNode = RI->second ;
435- return isIsolated ( DestNode);
441+ return (( DestNode-> parent . getInt () & Node:: kPHIIsolatedFlag ) > 0 ? true : false );
436442}
437443
438444// Split node ND from its existing congurent class, and the
@@ -453,7 +459,7 @@ void DeSSA::splitNode(Node* ND)
453459 P->next = N;
454460
455461 // ND : a new single-value congruent class
456- ND->parent = ND ;
462+ ND->parent . setPointer (ND) ;
457463 ND->next = ND;
458464 ND->prev = ND;
459465 ND->rank = 0 ;
@@ -477,11 +483,11 @@ void DeSSA::splitNode(Node* ND)
477483 // always to set "Leader' as the new leader, so that all nodes
478484 // within a same congruent class remains in the same rooted tree.
479485 N = Leader->next ;
480- Leader->parent = Leader;
486+ Leader->parent . setPointer ( Leader) ;
481487 Leader->rank = (Leader == N) ? 0 : 1 ;
482488 while (N != Leader)
483489 {
484- N->parent = Leader;
490+ N->parent . setPointer ( Leader) ;
485491 N->rank = 0 ;
486492 N = N->next ;
487493 }
@@ -647,7 +653,7 @@ DeSSA::SplitInterferencesForBasicBlock(
647653 // could possibly be improved, e.g. we could isolate the PHI with the
648654 // fewest operands.
649655 if (CurrentPHI.first && CurrentPHI.second != PredValue) {
650- isolateReg (PHI);
656+ isolatePHI (PHI);
651657 continue ;
652658 }
653659 else {
@@ -723,7 +729,7 @@ void DeSSA::SplitInterferencesForAlignment()
723729 {
724730 // Find a root Node
725731 Node *rootNode = I->second ;
726- if (rootNode->parent != rootNode) {
732+ if (rootNode->parent . getPointer () != rootNode) {
727733 continue ;
728734 }
729735
@@ -734,6 +740,13 @@ void DeSSA::SplitInterferencesForAlignment()
734740 do {
735741 Curr = N;
736742 N = Curr->next ;
743+
744+ // Skip isolated reg.
745+ if (Curr->parent .getInt () &
746+ (Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag )) {
747+ continue ;
748+ }
749+
737750 if (Curr->alignment == EALIGN_GRF) {
738751 Align = EALIGN_GRF;
739752 break ;
@@ -752,6 +765,13 @@ void DeSSA::SplitInterferencesForAlignment()
752765 do {
753766 Curr = N;
754767 N = N->next ;
768+
769+ // Skip isolated reg.
770+ if (Curr->parent .getInt () &
771+ (Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag )) {
772+ continue ;
773+ }
774+
755775 if (Curr->alignment != EALIGN_AUTO && Curr->alignment != EALIGN_GRF)
756776 {
757777 assert (Curr != Head && " Head Node cannot be isolated, something wrong!" );
@@ -867,6 +887,11 @@ void DeSSA::getAllValuesInCongruentClass(
867887 Node* First = RI->second ;
868888 Node* N = First->next ;
869889 do {
890+ if (N->parent .getInt () &
891+ (Node::kPHIIsolatedFlag | Node::kRegisterIsolatedFlag )) {
892+ N = N->next ;
893+ continue ;
894+ }
870895 if (rootV != N->value ) {
871896 // No duplicate Value in ValsInCC
872897 ValsInCC.push_back (N->value );
0 commit comments