Skip to content

Commit 2d11db1

Browse files
jgu222gfxbot
authored andcommitted
This is the second and final step to get rid of Node's flags.
A isolated node is the one with a single value, thus checking its parent will be enough to know if it is single-value congruent class. Remove Node's flags enum and several dead code. This commit should have no function change Change-Id: Ia8e1658fd08b18d67a9a4c565e4ec4d81acc9006
1 parent b25f082 commit 2d11db1

File tree

5 files changed

+58
-92
lines changed

5 files changed

+58
-92
lines changed

IGC/Compiler/CISACodeGen/BlockCoalescing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ bool BlockCoalescing::runOnFunction(Function& F)
121121
{
122122
break;
123123
}
124-
if(deSSA->isPHIIsolated(phi))
124+
if(deSSA->isIsolated(phi))
125125
{
126126
m_emptyBlocks.erase(bb);
127127
for(pred_iterator PI = pred_begin(bb), PE = pred_end(bb); PI != PE; PI++)

IGC/Compiler/CISACodeGen/CShader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2512,7 +2512,7 @@ CVariable* CShader::GetPhiTemp(llvm::PHINode* node)
25122512
}
25132513
// 1) simple de-ssa, always return a new temp
25142514
// 2) Or, phi is isolated, return a new temp
2515-
if (!m_deSSA || m_deSSA->isPHIIsolated(node))
2515+
if (!m_deSSA || m_deSSA->isIsolated(node))
25162516
{
25172517
var = GetNewVector(node);
25182518
}

IGC/Compiler/CISACodeGen/DeSSA.cpp

Lines changed: 50 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,40 @@ DeSSA::DeSSA() : FunctionPass( ID )
112112
void 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 << "\nPHI 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
328341
DeSSA::Node*
329342
DeSSA::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() {
344357
Value* 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
404416
void DeSSA::isolateReg(Value* Val) {
405417
Node *Node = RegNodeMap[Val];
406418
splitNode(Node);
407-
Node->parent.setInt(Node->parent.getInt() | Node::kRegisterIsolatedFlag);
408419
}
409420

410421
Value* 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);

IGC/Compiler/CISACodeGen/DeSSA.hpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ class DeSSA : public llvm::FunctionPass {
110110
/// return 0 if reg is isolated, and not in any insert-element union
111111
llvm::Value* getRootValue(llvm::Value*, e_alignment *pAlign = 0) const;
112112

113-
/// Get the union-root of the PHI dst-value. The root of a PHI-dst is 0 if
114-
/// the PHI has been isolated, or the phi-dst has been reg-isolated
115-
llvm::Value* getPHIRoot(llvm::Instruction*) const;
116-
117-
bool isPHIIsolated(llvm::Instruction*) const;
113+
bool isIsolated(llvm::Value*) const;
118114

119115
bool isUniform(llvm::Value *v) const {
120116
return (WIA->whichDepend(v) == WIAnalysis::UNIFORM);
@@ -142,20 +138,15 @@ class DeSSA : public llvm::FunctionPass {
142138
/// congruence class may no longer logically be a member, due to being
143139
/// isolated.
144140
struct Node {
145-
enum Flags {
146-
kRegisterIsolatedFlag = 1,
147-
kPHIIsolatedFlag = 1
148-
};
149141
Node(llvm::Value *v, int c, e_alignment align)
150-
: next(this), prev(this), value(v)
142+
: parent(this), next(this), prev(this), value(v)
151143
, rank(0), alignment(align), color(c)
152144
{
153-
parent.setPointer(this);
154145
}
155146

156147
Node *getLeader();
157148

158-
llvm::PointerIntPair<Node*, 2> parent;
149+
Node* parent;
159150
// double-linked circular list. All values are in the same congruent class
160151
// except those that have been isolated.
161152
Node *next;
@@ -197,8 +188,8 @@ class DeSSA : public llvm::FunctionPass {
197188
// Isolate a register.
198189
void isolateReg(llvm::Value*);
199190

200-
/// Isolate a PHI.
201-
void isolatePHI(llvm::Instruction*);
191+
/// Is it isolated (single-valued congruent class)
192+
bool isIsolated(Node* N) const { return (N == N->next); }
202193

203194
// Split node from its existing congurent class, and
204195
// node itself becomes a new single-value congruent class

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ void EmitPass::MovPhiSources(llvm::BasicBlock* aBB)
10391039
}
10401040
dstVTyMap.insert(std::pair<CVariable*, unsigned int>(dst, numElt));
10411041

1042-
if (IGC_IS_FLAG_DISABLED(DisablePHIDstCopy) && m_deSSA->isPHIIsolated(PN))
1042+
if (IGC_IS_FLAG_DISABLED(DisablePHIDstCopy) && m_deSSA->isIsolated(PN))
10431043
emitList.push_back(std::pair<CVariable*, CVariable*>(src, dst));
10441044
else
10451045
phiSrcDstList.push_back(std::pair<CVariable*, CVariable*>(src, dst));

0 commit comments

Comments
 (0)