@@ -112,27 +112,40 @@ 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;
115116 for (auto I = RegNodeMap.begin (),
116117 E = RegNodeMap.end (); I != E; ++I) {
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 ());
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 ;
123128 }
124- else {
129+ LeaderVisited[Leader] = 1 ;
130+ Value *VL;
131+ if (isIsolated (N)) {
132+ VL = N->value ;
125133 OS << " Var isolated : " ;
126134 VL->print (IGC::Debug::ods ());
127- }
128- PHINode *PHI = dyn_cast<PHINode>(VL);
129- if (PHI) {
130- if (isPHIIsolated (PHI)) {
131- OS << " \n PHI isolated : " ;
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 << " " ;
132144 VL->print (IGC::Debug::ods ());
145+ OS << " \n " ;
146+ N = N->next ;
133147 }
134148 }
135- OS << " \n " ;
136149 }
137150}
138151
@@ -288,7 +301,7 @@ bool DeSSA::runOnFunction(Function &MF)
288301 // isolate complex type that IGC does not handle
289302 if (PHI->getType ()->isStructTy () ||
290303 PHI->getType ()->isArrayTy ()) {
291- isolatePHI (PHI);
304+ isolateReg (PHI);
292305 }
293306 }
294307 }
@@ -328,14 +341,14 @@ void DeSSA::MapAddReg(MapVector<Value*, Node*> &Map, Value *Val, e_alignment Ali
328341DeSSA::Node*
329342DeSSA::Node::getLeader () {
330343 Node *N = this ;
331- Node *Parent = parent. getPointer () ;
332- Node *Grandparent = Parent->parent . getPointer () ;
344+ Node *Parent = parent;
345+ Node *Grandparent = Parent->parent ;
333346
334347 while (Parent != Grandparent) {
335- N->parent . setPointer ( Grandparent) ;
348+ N->parent = Grandparent;
336349 N = Grandparent;
337- Parent = N->parent . getPointer () ;
338- Grandparent = Parent->parent . getPointer () ;
350+ Parent = N->parent ;
351+ Grandparent = Parent->parent ;
339352 }
340353
341354 return Parent;
@@ -344,10 +357,10 @@ DeSSA::Node::getLeader() {
344357Value* DeSSA::getRegRoot (Value* Val, e_alignment *pAlign) const {
345358 auto RI = RegNodeMap.find (Val);
346359 if (RI == RegNodeMap.end ())
347- return 0 ;
360+ return nullptr ;
348361 Node *TheNode = RI->second ;
349- if (TheNode-> parent . getInt () & Node:: kRegisterIsolatedFlag )
350- return 0x0 ;
362+ if (isIsolated (TheNode) )
363+ return nullptr ;
351364 Node *TheLeader = TheNode->getLeader ();
352365 if (pAlign)
353366 *pAlign = TheLeader->alignment ;
@@ -360,8 +373,7 @@ int DeSSA::getRootColor(Value* V)
360373 if (RI == RegNodeMap.end ())
361374 return 0 ;
362375 Node *TheNode = RI->second ;
363- if (TheNode->parent .getInt () &
364- (Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag ))
376+ if (isIsolated (TheNode))
365377 return 0 ;
366378 Node *TheLeader = TheNode->getLeader ();
367379 return TheLeader->color ;
@@ -376,15 +388,15 @@ void DeSSA::MapUnionRegs(MapVector<Value*, Node*> &Map, Value* Val1, Value* Val2
376388 if (Node1->rank > Node2->rank ) {
377389 NewLeader = Node1->getLeader ();
378390 Leadee = Node2;
379- Node2->parent . setPointer ( NewLeader) ;
391+ Node2->parent = NewLeader;
380392 } else if (Node1->rank < Node2->rank ) {
381393 NewLeader = Node2->getLeader ();
382394 Leadee = Node1;
383- Node1->parent . setPointer ( NewLeader) ;
395+ Node1->parent = NewLeader;
384396 } else if (Node1 != Node2) {
385397 NewLeader = Node1->getLeader ();
386398 Leadee = Node2;
387- Node2->parent . setPointer ( NewLeader) ;
399+ Node2->parent = NewLeader;
388400 Node1->rank ++;
389401 }
390402
@@ -404,7 +416,6 @@ void DeSSA::MapUnionRegs(MapVector<Value*, Node*> &Map, Value* Val1, Value* Val2
404416void DeSSA::isolateReg (Value* Val) {
405417 Node *Node = RegNodeMap[Val];
406418 splitNode (Node);
407- Node->parent .setInt (Node->parent .getInt () | Node::kRegisterIsolatedFlag );
408419}
409420
410421Value* DeSSA::getOrigRoot (Instruction *PHI) const {
@@ -415,30 +426,13 @@ Value* DeSSA::getOrigRoot(Instruction *PHI) const {
415426 return DestNode->getLeader ()->value ;
416427}
417428
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 ());
429+ bool DeSSA::isIsolated (Value *V) const {
430+ auto RI = RegNodeMap.find (V);
431+ if (RI == RegNodeMap.end ()) {
432+ return true ;
433+ }
440434 Node *DestNode = RI->second ;
441- return (( DestNode-> parent . getInt () & Node:: kPHIIsolatedFlag ) > 0 ? true : false );
435+ return isIsolated ( DestNode);
442436}
443437
444438// Split node ND from its existing congurent class, and the
@@ -459,7 +453,7 @@ void DeSSA::splitNode(Node* ND)
459453 P->next = N;
460454
461455 // ND : a new single-value congruent class
462- ND->parent . setPointer (ND) ;
456+ ND->parent = ND ;
463457 ND->next = ND;
464458 ND->prev = ND;
465459 ND->rank = 0 ;
@@ -483,11 +477,11 @@ void DeSSA::splitNode(Node* ND)
483477 // always to set "Leader' as the new leader, so that all nodes
484478 // within a same congruent class remains in the same rooted tree.
485479 N = Leader->next ;
486- Leader->parent . setPointer ( Leader) ;
480+ Leader->parent = Leader;
487481 Leader->rank = (Leader == N) ? 0 : 1 ;
488482 while (N != Leader)
489483 {
490- N->parent . setPointer ( Leader) ;
484+ N->parent = Leader;
491485 N->rank = 0 ;
492486 N = N->next ;
493487 }
@@ -653,7 +647,7 @@ DeSSA::SplitInterferencesForBasicBlock(
653647 // could possibly be improved, e.g. we could isolate the PHI with the
654648 // fewest operands.
655649 if (CurrentPHI.first && CurrentPHI.second != PredValue) {
656- isolatePHI (PHI);
650+ isolateReg (PHI);
657651 continue ;
658652 }
659653 else {
@@ -729,7 +723,7 @@ void DeSSA::SplitInterferencesForAlignment()
729723 {
730724 // Find a root Node
731725 Node *rootNode = I->second ;
732- if (rootNode->parent . getPointer () != rootNode) {
726+ if (rootNode->parent != rootNode) {
733727 continue ;
734728 }
735729
@@ -740,13 +734,6 @@ void DeSSA::SplitInterferencesForAlignment()
740734 do {
741735 Curr = N;
742736 N = Curr->next ;
743-
744- // Skip isolated reg.
745- if (Curr->parent .getInt () &
746- (Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag )) {
747- continue ;
748- }
749-
750737 if (Curr->alignment == EALIGN_GRF) {
751738 Align = EALIGN_GRF;
752739 break ;
@@ -765,13 +752,6 @@ void DeSSA::SplitInterferencesForAlignment()
765752 do {
766753 Curr = N;
767754 N = N->next ;
768-
769- // Skip isolated reg.
770- if (Curr->parent .getInt () &
771- (Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag )) {
772- continue ;
773- }
774-
775755 if (Curr->alignment != EALIGN_AUTO && Curr->alignment != EALIGN_GRF)
776756 {
777757 assert (Curr != Head && " Head Node cannot be isolated, something wrong!" );
@@ -887,11 +867,6 @@ void DeSSA::getAllValuesInCongruentClass(
887867 Node* First = RI->second ;
888868 Node* N = First->next ;
889869 do {
890- if (N->parent .getInt () &
891- (Node::kPHIIsolatedFlag | Node::kRegisterIsolatedFlag )) {
892- N = N->next ;
893- continue ;
894- }
895870 if (rootV != N->value ) {
896871 // No duplicate Value in ValsInCC
897872 ValsInCC.push_back (N->value );
0 commit comments