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

All nodes of congruent class (CC) are linked. The previous

implementation keeps an isolated node in that link. This change
will remove an isolated node from the link and put it in a
separate congruent class (single-valued, thus isolated).

This change will make it easy doing re-union nodes from different
congruent class later after DeSSA is done. And this change seems
easier to understand as well

Change-Id: I15150ee0bb776a5a22747c700ba5009c0e0ea4ed
parent 6f1ace46
......@@ -402,6 +402,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);
}
......@@ -428,6 +429,7 @@ Value* DeSSA::getPHIRoot(Instruction *PHI) const {
void DeSSA::isolatePHI(Instruction *PHI) {
assert(isa<PHINode>(PHI));
Node *Node = RegNodeMap[PHI];
splitNode(Node);
Node->parent.setInt(Node->parent.getInt() | Node::kPHIIsolatedFlag);
}
......@@ -438,6 +440,54 @@ bool DeSSA::isPHIIsolated(Instruction *PHI) const {
return ((DestNode->parent.getInt() & Node::kPHIIsolatedFlag) > 0 ? true : false);
}
// Split node ND from its existing congurent class, and the
// node ND itself becomes a new single-value congruent class.
void DeSSA::splitNode(Node* ND)
{
Node* N = ND->next;
if (N == ND) {
// ND is already in a single-value congruent class
return;
}
Node* Leader = ND->getLeader();
// Remove ND from the congruent class
Node* P = ND->prev;
N->prev = P;
P->next = N;
// ND : a new single-value congruent class
ND->parent.setPointer(ND);
ND->next = ND;
ND->prev = ND;
ND->rank = 0;
// If leader is removed, need to have a new leader. Here,
// we do path compression with ND's prev as a new leader.
if (Leader == ND) {
// isolate the leader. swap ND's color with P's so that the
// original congruent class still have the original color
// (this is important as Dom traversal assumes that the color
// of any congruent class remains unchanged).
int t = P->color;
P->color = ND->color;
ND->color = t;
// Doing the path compression for the rooted tree of
// the existing congruent class after ND (leader) is
// removed from the congruent class. P is the new leader.
P->parent.setPointer(P);
P->rank = (P == N) ? 0 : 1;
while (N != P)
{
N->parent.setPointer(P);
N->rank = 0;
N = N->next;
}
}
}
/// SplitInterferencesForBasicBlock - traverses a basic block, splitting any
/// interferences found between registers in the same congruence class. It
/// takes two DenseMaps as arguments that it also updates:
......
......@@ -200,6 +200,10 @@ class DeSSA : public llvm::FunctionPass {
/// Isolate a PHI.
void isolatePHI(llvm::Instruction*);
// Split node from its existing congurent class, and
// node itself becomes a new single-value congruent class
void splitNode(Node* ND);
/// Traverses a basic block, splitting any interferences found between
/// registers in the same congruence class. It takes two DenseMaps as
/// arguments that it also updates: CurrentDominatingParent, which maps
......
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