Skip to content

Commit 97b6bd5

Browse files
bcheng0127sys_zuul
authored andcommitted
SWSB code refactor
Change-Id: Ibdb121a6d9f8a6fc51ea9125ad36121385ef6e82
1 parent 25ab8b5 commit 97b6bd5

File tree

1 file changed

+103
-60
lines changed

1 file changed

+103
-60
lines changed

visa/LocalScheduler/SWSB_G4IR.cpp

Lines changed: 103 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,10 +1980,15 @@ void SWSB::tokenAllocation()
19801980
dumpTokenLiveInfo();
19811981
#endif
19821982

1983-
for (size_t i = 0; i < BBVector.size(); i++)
1984-
{
1985-
BBVector[i]->tokenEdgePrune(int(SBSendNodes.size()), allTokenNodesMap, &SBNodes);
1986-
}
1983+
unsigned prunedEdgeNum = 0;
1984+
unsigned prunedGlobalEdgeNum = 0;
1985+
unsigned prunedDiffBBEdgeNum = 0;
1986+
unsigned prunedDiffBBSameTokenEdgeNum = 0;
1987+
tokenEdgePrune(prunedEdgeNum, prunedGlobalEdgeNum, prunedDiffBBEdgeNum, prunedDiffBBSameTokenEdgeNum);
1988+
kernel.setPrunedEdgeNum(prunedEdgeNum);
1989+
kernel.setPrunedGlobalEdgeNum(prunedGlobalEdgeNum);
1990+
kernel.setPrunedDiffBBEdgeNum(prunedDiffBBEdgeNum);
1991+
kernel.setPrunedDiffBBSameTokenEdgeNum(prunedDiffBBSameTokenEdgeNum);
19871992
}
19881993

19891994
for (auto node_it = SBSendNodes.begin();
@@ -2735,82 +2740,120 @@ bool SWSB::globalDependenceUseReachAnalysis(G4_BB* bb)
27352740
}
27362741

27372742

2738-
void G4_BB_SB::tokenEdgePrune(int allSendNum,
2739-
BitSet** allTokenNodesMap,
2740-
SBNODE_VECT* SBNodes)
2743+
void SWSB::tokenEdgePrune(unsigned& prunedEdgeNum,
2744+
unsigned& prunedGlobalEdgeNum,
2745+
unsigned& prunedDiffBBEdgeNum,
2746+
unsigned& prunedDiffBBSameTokenEdgeNum)
27412747
{
2742-
if (first_node == -1)
2748+
for (size_t i = 0; i < BBVector.size(); i++)
27432749
{
2744-
return;
2745-
}
2750+
if (BBVector[i]->first_node == -1)
2751+
{
2752+
continue;
2753+
}
27462754

2747-
BitSet activateLiveIn(allSendNum, false);
2748-
activateLiveIn |= *liveInTokenNodes;
2755+
BitSet activateLiveIn(SBSendNodes.size(), false);
2756+
activateLiveIn |= *BBVector[i]->liveInTokenNodes;
27492757

2750-
//Scan the instruction nodes of current BB
2751-
for (int i = first_node; i <= last_node; i++)
2752-
{
2753-
SBNode* node = (*SBNodes)[i];
2754-
2755-
//scan the incoming dependence edges of current node
2756-
for (auto node_it = node->preds.begin();
2757-
node_it != node->preds.end();
2758-
node_it++)
2758+
//Scan the instruction nodes of current BB
2759+
for (int j = BBVector[i]->first_node; j <= BBVector[i]->last_node; j++)
27592760
{
2760-
SBDEP_ITEM& curPred = (*node_it);
2761-
DepType type = curPred.type;
2762-
SBNode* predNode = curPred.node;
2761+
SBNode* node = SBNodes[j];
2762+
BitSet killedToken(totalTokenNum, false); //Track the token killed by current instruction.
27632763

2764-
//If the predecessor node is a token instruction node.
2765-
if (tokenHonourInstruction(predNode->GetInstruction()))
2764+
//scan the incoming dependence edges of current node
2765+
for (auto node_it = node->preds.begin();
2766+
node_it != node->preds.end();
2767+
node_it++)
27662768
{
2767-
if (!activateLiveIn.isSet(predNode->sendID))
2769+
SBDEP_ITEM& curPred = (*node_it);
2770+
DepType type = curPred.type;
2771+
SBNode* predNode = curPred.node;
2772+
2773+
//If the predecessor node is a token instruction node.
2774+
if (tokenHonourInstruction(predNode->GetInstruction()))
27682775
{
2769-
// If not in the live set of current instruction,
2770-
// (The live in set will be changed during instruction scan)
2771-
// remove the dependence from success list of previous node
2772-
// The dependence SBID assignment only depends on the succ nodes.
2773-
for (auto succ_it = predNode->succs.begin();
2774-
succ_it != predNode->succs.end();
2775-
succ_it++)
2776+
if (!activateLiveIn.isSet(predNode->sendID))
27762777
{
2777-
SBDEP_ITEM& currSucc = (*succ_it);
2778-
if (currSucc.node == node)
2778+
// If not in the live set of current instruction,
2779+
// (The live in set will be changed during instruction scan)
2780+
// remove the dependence from success list of previous node
2781+
// The dependence SBID assignment only depends on the succ nodes.
2782+
for (auto succ_it = predNode->succs.begin();
2783+
succ_it != predNode->succs.end();
2784+
succ_it++)
27792785
{
2780-
//Don't do remove previous edge here.
2781-
//1. conflict with outer loop
2782-
//2. There is no preds info required any more in following handling
2783-
predNode->succs.erase(succ_it);
2784-
break;
2786+
SBDEP_ITEM& currSucc = (*succ_it);
2787+
if (currSucc.node == node)
2788+
{
2789+
//Don't do remove previous edge here.
2790+
//1. conflict with outer loop
2791+
//2. There is no preds info required any more in following handling
2792+
predNode->succs.erase(succ_it);
2793+
prunedEdgeNum++;
2794+
if (predNode->globalID != -1)
2795+
{
2796+
if (predNode->getBBID() != node->getBBID() &&
2797+
!killedToken.isSet(predNode->getLastInstruction()->getToken()))
2798+
{
2799+
prunedDiffBBEdgeNum++;
2800+
#ifdef DEBUG_VERBOSE_ON
2801+
std::cerr << "Diff BB Token: " << predNode->getLastInstruction()->getToken() << " <Pred: " << predNode->getNodeID() << ", Succ: " << node->getNodeID() << ">" << std::endl;;
2802+
#endif
2803+
}
2804+
else if (predNode->getBBID() != node->getBBID())
2805+
{
2806+
prunedDiffBBSameTokenEdgeNum++;
2807+
#ifdef DEBUG_VERBOSE_ON
2808+
std::cerr << "Diff BB Same Token: " << predNode->getLastInstruction()->getToken() << " <Pred: " << predNode->getNodeID() << ", Succ: " << node->getNodeID() << ">" << std::endl;;
2809+
#endif
2810+
}
2811+
else
2812+
{
2813+
prunedGlobalEdgeNum++;
2814+
#ifdef DEBUG_VERBOSE_ON
2815+
std::cerr << "Global Token: " << predNode->getLastInstruction()->getToken() << " <Pred: " << predNode->getNodeID() << ", Succ: " << node->getNodeID() << ">" << std::endl;;
2816+
#endif
2817+
}
2818+
}
2819+
#ifdef DEBUG_VERBOSE_ON
2820+
else
2821+
{
2822+
std::cerr << "Local Token: " << predNode->getLastInstruction()->getToken() << " <Pred: " << predNode->getNodeID() << ", Succ: " << node->getNodeID() << ">" << std::endl;;
2823+
}
2824+
#endif
2825+
break;
2826+
}
27852827
}
27862828
}
2787-
}
2788-
else //In live in set
2789-
{
2790-
// Kill the dependence if it's a AW dependence
2791-
// What about WAR?
2792-
if (type == RAW || type == WAW)
2829+
else //In live in set
27932830
{
2794-
int token = predNode->getLastInstruction()->getToken();
2795-
if (token != (unsigned short)UNKNOWN_TOKEN)
2831+
// Kill the dependence if it's a AW dependence
2832+
// What about WAR?
2833+
if (type == RAW || type == WAW)
27962834
{
2797-
activateLiveIn -= *allTokenNodesMap[token];
2835+
int token = predNode->getLastInstruction()->getToken();
2836+
if (token != (unsigned short)UNKNOWN_TOKEN)
2837+
{
2838+
activateLiveIn -= *allTokenNodesMap[token];
2839+
killedToken.set(token, true);
2840+
}
27982841
}
27992842
}
28002843
}
28012844
}
2802-
}
28032845

2804-
// Current instruction is marked as alive
2805-
// How to kill the old one? Especially the WAR?
2806-
// Token reuse will kill all previous nodes with same token? yes
2807-
if (tokenHonourInstruction(node->GetInstruction()) && !node->GetInstruction()->isEOT())
2808-
{
2809-
int token = node->getLastInstruction()->getToken();
2810-
if (token != (unsigned short)UNKNOWN_TOKEN)
2846+
// Current instruction is marked as alive
2847+
// How to kill the old one? Especially the WAR?
2848+
// Token reuse will kill all previous nodes with same token? yes
2849+
if (tokenHonourInstruction(node->GetInstruction()) && !node->GetInstruction()->isEOT())
28112850
{
2812-
activateLiveIn -= *allTokenNodesMap[token];
2813-
activateLiveIn.set(node->sendID, true);
2851+
int token = node->getLastInstruction()->getToken();
2852+
if (token != (unsigned short)UNKNOWN_TOKEN)
2853+
{
2854+
activateLiveIn -= *allTokenNodesMap[token];
2855+
activateLiveIn.set(node->sendID, true);
2856+
}
28142857
}
28152858
}
28162859
}

0 commit comments

Comments
 (0)