Commit b21aca87 authored by Junjie Gu's avatar Junjie Gu Committed by gbsbuild

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
parent 3b9bed75
......@@ -121,7 +121,7 @@ bool BlockCoalescing::runOnFunction(Function& F)
{
break;
}
if(deSSA->isIsolated(phi))
if(deSSA->isPHIIsolated(phi))
{
m_emptyBlocks.erase(bb);
for(pred_iterator PI = pred_begin(bb), PE = pred_end(bb); PI != PE; PI++)
......
......@@ -2511,7 +2511,7 @@ CVariable* CShader::GetPhiTemp(llvm::PHINode* node)
}
// 1) simple de-ssa, always return a new temp
// 2) Or, phi is isolated, return a new temp
if (!m_deSSA || m_deSSA->isIsolated(node))
if (!m_deSSA || m_deSSA->isPHIIsolated(node))
{
var = GetNewVector(node);
}
......
......@@ -112,40 +112,27 @@ DeSSA::DeSSA() : FunctionPass( ID )
void DeSSA::print(raw_ostream &OS, const Module* ) const
{
Banner(OS, "Phi-Var Isolations");
DenseMap<Node*, int> LeaderVisited;
for (auto I = RegNodeMap.begin(),
E = RegNodeMap.end(); I != E; ++I) {
Node* N = I->second;
// We don't want to change behavior of DeSSA by invoking
// dumping/printing functions. Thus, don't use getLeader()
// as it has side-effect (doing path halving).
Node* Leader = N->parent;
while (Leader != Leader->parent) {
Leader = Leader->parent;
}
if (LeaderVisited.count(Leader)) {
continue;
Value *VL = I->first;
Value *RootV = getRegRoot(VL);
if (RootV) {
VL->print(IGC::Debug::ods());
OS << " : ";
RootV->print(IGC::Debug::ods());
}
LeaderVisited[Leader] = 1;
Value *VL;
if (isIsolated(N)) {
VL = N->value;
else {
OS << "Var isolated : ";
VL->print(IGC::Debug::ods());
OS << "\n";
} else {
OS << "Leader : ";
Leader->value->print(IGC::Debug::ods());
OS << "\n";
N = Leader->next;
while (N != Leader) {
VL = N->value;
OS << " ";
}
PHINode *PHI = dyn_cast<PHINode>(VL);
if (PHI) {
if (isPHIIsolated(PHI)) {
OS << "\nPHI isolated : ";
VL->print(IGC::Debug::ods());
OS << "\n";
N = N->next;
}
}
OS << "\n";
}
}
......@@ -301,7 +288,7 @@ bool DeSSA::runOnFunction(Function &MF)
// isolate complex type that IGC does not handle
if (PHI->getType()->isStructTy() ||
PHI->getType()->isArrayTy()) {
isolateReg(PHI);
isolatePHI(PHI);
}
}
}
......@@ -341,14 +328,14 @@ void DeSSA::MapAddReg(MapVector<Value*, Node*> &Map, Value *Val, e_alignment Ali
DeSSA::Node*
DeSSA::Node::getLeader() {
Node *N = this;
Node *Parent = parent;
Node *Grandparent = Parent->parent;
Node *Parent = parent.getPointer();
Node *Grandparent = Parent->parent.getPointer();
while (Parent != Grandparent) {
N->parent = Grandparent;
N->parent.setPointer(Grandparent);
N = Grandparent;
Parent = N->parent;
Grandparent = Parent->parent;
Parent = N->parent.getPointer();
Grandparent = Parent->parent.getPointer();
}
return Parent;
......@@ -357,10 +344,10 @@ DeSSA::Node::getLeader() {
Value* DeSSA::getRegRoot(Value* Val, e_alignment *pAlign) const {
auto RI = RegNodeMap.find(Val);
if (RI == RegNodeMap.end())
return nullptr;
return 0;
Node *TheNode = RI->second;
if (isIsolated(TheNode))
return nullptr;
if (TheNode->parent.getInt() & Node::kRegisterIsolatedFlag)
return 0x0;
Node *TheLeader = TheNode->getLeader();
if (pAlign)
*pAlign = TheLeader->alignment;
......@@ -373,7 +360,8 @@ int DeSSA::getRootColor(Value* V)
if (RI == RegNodeMap.end())
return 0;
Node *TheNode = RI->second;
if (isIsolated(TheNode))
if (TheNode->parent.getInt() &
(Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag))
return 0;
Node *TheLeader = TheNode->getLeader();
return TheLeader->color;
......@@ -388,15 +376,15 @@ void DeSSA::MapUnionRegs(MapVector<Value*, Node*> &Map, Value* Val1, Value* Val2
if (Node1->rank > Node2->rank) {
NewLeader = Node1->getLeader();
Leadee = Node2;
Node2->parent = NewLeader;
Node2->parent.setPointer(NewLeader);
} else if (Node1->rank < Node2->rank) {
NewLeader = Node2->getLeader();
Leadee = Node1;
Node1->parent = NewLeader;
Node1->parent.setPointer(NewLeader);
} else if (Node1 != Node2) {
NewLeader = Node1->getLeader();
Leadee = Node2;
Node2->parent = NewLeader;
Node2->parent.setPointer(NewLeader);
Node1->rank++;
}
......@@ -416,6 +404,7 @@ void DeSSA::MapUnionRegs(MapVector<Value*, Node*> &Map, Value* Val1, Value* Val2
void DeSSA::isolateReg(Value* Val) {
Node *Node = RegNodeMap[Val];
splitNode(Node);
Node->parent.setInt(Node->parent.getInt() | Node::kRegisterIsolatedFlag);
}
Value* DeSSA::getOrigRoot(Instruction *PHI) const {
......@@ -426,13 +415,30 @@ Value* DeSSA::getOrigRoot(Instruction *PHI) const {
return DestNode->getLeader()->value;
}
bool DeSSA::isIsolated(Value *V) const {
auto RI = RegNodeMap.find(V);
if (RI == RegNodeMap.end()) {
return true;
}
Value* DeSSA::getPHIRoot(Instruction *PHI) const {
assert(dyn_cast<PHINode>(PHI));
auto RI = RegNodeMap.find(PHI);
assert (RI != RegNodeMap.end());
Node *DestNode = RI->second;
if (DestNode->parent.getInt() & Node::kPHIIsolatedFlag)
return 0x0;
if (DestNode->parent.getInt() & Node::kRegisterIsolatedFlag)
return 0x0;
return DestNode->getLeader()->value;
}
void DeSSA::isolatePHI(Instruction *PHI) {
assert(isa<PHINode>(PHI));
Node *Node = RegNodeMap[PHI];
splitNode(Node);
Node->parent.setInt(Node->parent.getInt() | Node::kPHIIsolatedFlag);
}
bool DeSSA::isPHIIsolated(Instruction *PHI) const {
auto RI = RegNodeMap.find(PHI);
assert (RI != RegNodeMap.end());
Node *DestNode = RI->second;
return isIsolated(DestNode);
return ((DestNode->parent.getInt() & Node::kPHIIsolatedFlag) > 0 ? true : false);
}
// Split node ND from its existing congurent class, and the
......@@ -453,7 +459,7 @@ void DeSSA::splitNode(Node* ND)
P->next = N;
// ND : a new single-value congruent class
ND->parent = ND;
ND->parent.setPointer(ND);
ND->next = ND;
ND->prev = ND;
ND->rank = 0;
......@@ -477,11 +483,11 @@ void DeSSA::splitNode(Node* ND)
// always to set "Leader' as the new leader, so that all nodes
// within a same congruent class remains in the same rooted tree.
N = Leader->next;
Leader->parent = Leader;
Leader->parent.setPointer(Leader);
Leader->rank = (Leader == N) ? 0 : 1;
while (N != Leader)
{
N->parent = Leader;
N->parent.setPointer(Leader);
N->rank = 0;
N = N->next;
}
......@@ -647,7 +653,7 @@ DeSSA::SplitInterferencesForBasicBlock(
// could possibly be improved, e.g. we could isolate the PHI with the
// fewest operands.
if (CurrentPHI.first && CurrentPHI.second != PredValue) {
isolateReg(PHI);
isolatePHI(PHI);
continue;
}
else {
......@@ -723,7 +729,7 @@ void DeSSA::SplitInterferencesForAlignment()
{
// Find a root Node
Node *rootNode = I->second;
if (rootNode->parent != rootNode) {
if (rootNode->parent.getPointer() != rootNode) {
continue;
}
......@@ -734,6 +740,13 @@ void DeSSA::SplitInterferencesForAlignment()
do {
Curr = N;
N = Curr->next;
// Skip isolated reg.
if (Curr->parent.getInt() &
(Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag)) {
continue;
}
if (Curr->alignment == EALIGN_GRF) {
Align = EALIGN_GRF;
break;
......@@ -752,6 +765,13 @@ void DeSSA::SplitInterferencesForAlignment()
do {
Curr = N;
N = N->next;
// Skip isolated reg.
if (Curr->parent.getInt() &
(Node::kRegisterIsolatedFlag | Node::kPHIIsolatedFlag)) {
continue;
}
if (Curr->alignment != EALIGN_AUTO && Curr->alignment != EALIGN_GRF)
{
assert(Curr != Head && "Head Node cannot be isolated, something wrong!");
......@@ -867,6 +887,11 @@ void DeSSA::getAllValuesInCongruentClass(
Node* First = RI->second;
Node* N = First->next;
do {
if (N->parent.getInt() &
(Node::kPHIIsolatedFlag | Node::kRegisterIsolatedFlag)) {
N = N->next;
continue;
}
if (rootV != N->value) {
// No duplicate Value in ValsInCC
ValsInCC.push_back(N->value);
......
......@@ -110,7 +110,11 @@ class DeSSA : public llvm::FunctionPass {
/// return 0 if reg is isolated, and not in any insert-element union
llvm::Value* getRootValue(llvm::Value*, e_alignment *pAlign = 0) const;
bool isIsolated(llvm::Value*) const;
/// Get the union-root of the PHI dst-value. The root of a PHI-dst is 0 if
/// the PHI has been isolated, or the phi-dst has been reg-isolated
llvm::Value* getPHIRoot(llvm::Instruction*) const;
bool isPHIIsolated(llvm::Instruction*) const;
bool isUniform(llvm::Value *v) const {
return (WIA->whichDepend(v) == WIAnalysis::UNIFORM);
......@@ -138,15 +142,20 @@ class DeSSA : public llvm::FunctionPass {
/// congruence class may no longer logically be a member, due to being
/// isolated.
struct Node {
enum Flags {
kRegisterIsolatedFlag = 1,
kPHIIsolatedFlag = 1
};
Node(llvm::Value *v, int c, e_alignment align)
: parent(this), next(this), prev(this), value(v)
: next(this), prev(this), value(v)
, rank(0), alignment(align), color(c)
{
parent.setPointer(this);
}
Node *getLeader();
Node* parent;
llvm::PointerIntPair<Node*, 2> parent;
// double-linked circular list. All values are in the same congruent class
// except those that have been isolated.
Node *next;
......@@ -188,8 +197,8 @@ class DeSSA : public llvm::FunctionPass {
// Isolate a register.
void isolateReg(llvm::Value*);
/// Is it isolated (single-valued congruent class)
bool isIsolated(Node* N) const { return (N == N->next); }
/// Isolate a PHI.
void isolatePHI(llvm::Instruction*);
// Split node from its existing congurent class, and
// node itself becomes a new single-value congruent class
......
......@@ -1039,7 +1039,7 @@ void EmitPass::MovPhiSources(llvm::BasicBlock* aBB)
}
dstVTyMap.insert(std::pair<CVariable*, unsigned int>(dst, numElt));
if (IGC_IS_FLAG_DISABLED(DisablePHIDstCopy) && m_deSSA->isIsolated(PN))
if (IGC_IS_FLAG_DISABLED(DisablePHIDstCopy) && m_deSSA->isPHIIsolated(PN))
emitList.push_back(std::pair<CVariable*, CVariable*>(src, dst));
else
phiSrcDstList.push_back(std::pair<CVariable*, CVariable*>(src, dst));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment