Skip to content

Commit b21aca8

Browse files
jgu222gfxbot
authored andcommitted
As ifcvt has an issue and was backout, this change should be
backout as well. Otherwise, the some test will fail. Back it out now and will re-commit later after ifcvt issue has been fixed Change-Id: I5508d5d6cd85d78dcdc6be85edcf42aca0bea275
1 parent 3b9bed7 commit b21aca8

File tree

5 files changed

+92
-58
lines changed

5 files changed

+92
-58
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->isIsolated(phi))
124+
if(deSSA->isPHIIsolated(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
@@ -2511,7 +2511,7 @@ CVariable* CShader::GetPhiTemp(llvm::PHINode* node)
25112511
}
25122512
// 1) simple de-ssa, always return a new temp
25132513
// 2) Or, phi is isolated, return a new temp
2514-
if (!m_deSSA || m_deSSA->isIsolated(node))
2514+
if (!m_deSSA || m_deSSA->isPHIIsolated(node))
25152515
{
25162516
var = GetNewVector(node);
25172517
}

IGC/Compiler/CISACodeGen/DeSSA.cpp

Lines changed: 75 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -112,40 +112,27 @@ 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;
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 << "\nPHI 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
341328
DeSSA::Node*
342329
DeSSA::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() {
357344
Value* 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
416404
void DeSSA::isolateReg(Value* Val) {
417405
Node *Node = RegNodeMap[Val];
418406
splitNode(Node);
407+
Node->parent.setInt(Node->parent.getInt() | Node::kRegisterIsolatedFlag);
419408
}
420409

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

IGC/Compiler/CISACodeGen/DeSSA.hpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ 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-
bool isIsolated(llvm::Value*) const;
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;
114118

115119
bool isUniform(llvm::Value *v) const {
116120
return (WIA->whichDepend(v) == WIAnalysis::UNIFORM);
@@ -138,15 +142,20 @@ class DeSSA : public llvm::FunctionPass {
138142
/// congruence class may no longer logically be a member, due to being
139143
/// isolated.
140144
struct Node {
145+
enum Flags {
146+
kRegisterIsolatedFlag = 1,
147+
kPHIIsolatedFlag = 1
148+
};
141149
Node(llvm::Value *v, int c, e_alignment align)
142-
: parent(this), next(this), prev(this), value(v)
150+
: next(this), prev(this), value(v)
143151
, rank(0), alignment(align), color(c)
144152
{
153+
parent.setPointer(this);
145154
}
146155

147156
Node *getLeader();
148157

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

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

194203
// Split node from its existing congurent class, and
195204
// 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->isIsolated(PN))
1042+
if (IGC_IS_FLAG_DISABLED(DisablePHIDstCopy) && m_deSSA->isPHIIsolated(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)