@@ -2081,7 +2081,7 @@ G4_INST* SWSB::insertSyncAllWRInstruction(G4_BB* bb, unsigned int SBIDs, INST_LI
20812081 return syncInst;
20822082}
20832083
2084- void SWSB::insertSyncToken (G4_BB* bb, SBNode* node, G4_INST* inst, INST_LIST_ITER inst_it, int newInstID, BitSet* dstTokens, BitSet* srcTokens, bool removeAllToken)
2084+ bool SWSB::insertSyncToken (G4_BB * bb, SBNode * node, G4_INST * inst, INST_LIST_ITER inst_it, int newInstID, BitSet * dstTokens, BitSet * srcTokens, bool removeAllToken)
20852085{
20862086 // Non-test instruction can only have
20872087 // 1. non-send: one Dst Token with distance, or
@@ -2097,6 +2097,8 @@ void SWSB::insertSyncToken(G4_BB* bb, SBNode* node, G4_INST* inst, INST_LIST_ITE
20972097 unsigned short dstToken = (unsigned short )-1 ;
20982098 unsigned short srcToken = (unsigned short )-1 ;
20992099 SWSBTokenType type = G4_INST::SWSBTokenType::TOKEN_NONE;
2100+ bool insertedSync = false ;
2101+
21002102 for (unsigned int i = 0 ; i < node->GetInstruction ()->getDepTokenNum ();)
21012103 {
21022104 G4_INST* synAllInst = nullptr ;
@@ -2212,6 +2214,7 @@ void SWSB::insertSyncToken(G4_BB* bb, SBNode* node, G4_INST* inst, INST_LIST_ITE
22122214 synInst->setDepToken (dstToken, SWSBTokenType::AFTER_WRITE);
22132215 }
22142216 synInst->setLexicalId (newInstID);
2217+ insertedSync = true ;
22152218 }
22162219
22172220 if (src)
@@ -2230,23 +2233,31 @@ void SWSB::insertSyncToken(G4_BB* bb, SBNode* node, G4_INST* inst, INST_LIST_ITE
22302233 synInst->setDepToken (srcToken, SWSBTokenType::AFTER_READ);
22312234 }
22322235 synInst->setLexicalId (newInstID);
2236+ insertedSync = true ;
22332237 }
22342238
2235- return ;
2239+ return insertedSync ;
22362240}
22372241
22382242
22392243void SWSB::insertSync (G4_BB* bb, SBNode* node, G4_INST* inst, INST_LIST_ITER inst_it, int newInstID, BitSet* dstTokens, BitSet* srcTokens, bool hasDistOneAreg)
22402244{
2241- G4_INST* syncInst = nullptr ;
2245+ bool insertedSync = false ;
2246+ INST_LIST_ITER prevIt = inst_it;
22422247 if (hasDistOneAreg)
22432248 {
2244- syncInst = insertSyncInstructionAfter (bb, inst_it, inst->getCISAOff (), inst->getLineNo ());
2245- syncInst->setDistance (1 );
2249+ prevIt--;
2250+ }
2251+
2252+ {
2253+ insertedSync = insertSyncToken (bb, node, inst, inst_it, newInstID, dstTokens, srcTokens, false );
22462254 }
22472255
2256+ if (hasDistOneAreg && insertedSync)
22482257 {
2249- insertSyncToken (bb, node, inst, inst_it, newInstID, dstTokens, srcTokens, false );
2258+ G4_INST* syncInst = nullptr ;
2259+ syncInst = insertSyncInstructionAfter (bb, prevIt, inst->getCISAOff (), inst->getLineNo ());
2260+ syncInst->setDistance (1 );
22502261 }
22512262}
22522263
@@ -3348,6 +3359,7 @@ void G4_BB_SB::SBDDD(G4_BB* bb,
33483359 if (hasFollowDistOneAReg)
33493360 {
33503361 node->setDistance (1 );
3362+ node->setDistOneAReg ();
33513363 hasFollowDistOneAReg = false ;
33523364 }
33533365
@@ -3357,8 +3369,6 @@ void G4_BB_SB::SBDDD(G4_BB* bb,
33573369 if (hasFollowDistOneAReg)
33583370 {
33593371 node->setDistance (1 );
3360- node->setDistOneAReg ();
3361-
33623372 }
33633373
33643374
0 commit comments