diff --git a/visa/LocalScheduler/SWSB_G4IR.cpp b/visa/LocalScheduler/SWSB_G4IR.cpp index 050a2b7e6239..2ea1b96d8136 100644 --- a/visa/LocalScheduler/SWSB_G4IR.cpp +++ b/visa/LocalScheduler/SWSB_G4IR.cpp @@ -1465,6 +1465,35 @@ void SWSB::handleFuncCall() { } } +void SWSB::SWSBInitializeGlobalSends( + SparseBitVector &allDstGlobalIDs, // node global ID bit vector in buckets + // touched by dst operands + SparseBitVector &allSrcGlobalIDs, // node global ID bit vector in buckets + // touched by src operands + LiveGRFBuckets &globalSendsLB) { // live buckets of global sends + + + // Scan the global send LB to set the node bit in dst or src bit set of each + // bucket that node touches. + for (unsigned curBucket = 0; + curBucket < + kernel.getNumRegTotal() + fg.builder->getNumScalarRegisters(); + curBucket++) { + + for (LiveGRFBuckets::BN_iterator bn_it = globalSendsLB.begin(curBucket); + bn_it != globalSendsLB.end(curBucket); ++bn_it) { + SBBucketNode *liveBN = (*bn_it); + SBNode *curLiveNode = liveBN->node; + + if (liveBN->opndNum == Opnd_dst) { + allDstGlobalIDs.set(curLiveNode->globalID); + } else { + allSrcGlobalIDs.set(curLiveNode->globalID); + } + } + } +} + // // Set the global ID bit vector of each bucket touched by corresponding // operands @@ -1533,6 +1562,12 @@ void SWSB::SWSBGlobalTokenGenerator(PointsToAnalysis &p, LiveGRFBuckets &LB, std::vector dstGlobalIDs; std::vector srcGlobalIDs; + SparseBitVector allDstGlobalIDs; + SparseBitVector allSrcGlobalIDs; + + //Get all the global sends bitvector + SWSBInitializeGlobalSends(allDstGlobalIDs, allSrcGlobalIDs, globalSendsLB); + if (!fg.builder->hasReadSuppressionOrSharedLocalMemoryWAs()) { // Initialilze for setSendGlobalIDMayKilledByCurrentBB only SWSBInitializeGlobalNodesInBuckets(dstGlobalIDs, srcGlobalIDs, @@ -1579,7 +1614,9 @@ void SWSB::SWSBGlobalTokenGenerator(PointsToAnalysis &p, LiveGRFBuckets &LB, bb->setSendOpndMayKilled(&globalSendsLB, SBNodes, p); } } else { - bb->setSendOpndMayKilled(&globalSendsLB, SBNodes, p); + if (!bb->handleCallForMayKilled(&allDstGlobalIDs, &allSrcGlobalIDs)) { + bb->setSendOpndMayKilled(&globalSendsLB, SBNodes, p); + } } #ifdef DEBUG_VERBOSE_ON @@ -4408,6 +4445,23 @@ void SWSB::insertTokenSync() { continue; } + if (inst->isCall() || inst->isFCall() || inst->isReturn() || + inst->isFReturn()) { + G4_INST *synAllInst = insertSyncAllWRInstruction(bb, 0, inst_it); + // In case previous inst need force A@1 in following inst + synAllInst->setDistance(1); + if (kernel.fg.builder->hasThreeALUPipes() || + kernel.fg.builder->hasFourALUPipes()) { + synAllInst->setDistanceTypeXe(G4_INST::DistanceType::DISTALL); + } + synAllInst->setLexicalId(newInstID); + synAllInst = insertSyncAllRDInstruction(bb, 0, inst_it); + synAllInst->setLexicalId(newInstID); + newInstID++; + node_it++; + continue; + } + auto jitInfo = kernel.fg.builder->getJitInfo(); if (inst->getDistance() == 1) { if (kernel.fg.builder->hasThreeALUPipes() || @@ -5385,6 +5439,26 @@ void G4_BB_SB::getLiveOutToken(unsigned allSendNum, } } +// All global dependencies will be resolved in function call +bool G4_BB_SB::handleCallForMayKilled(SparseBitVector *allDstGlobalIDs, + SparseBitVector *allSrcGlobalIDs) { + if (!bb->size()) { + return false; + } + + G4_INST *lastInst = bb->back(); + if (!lastInst->isReturn() && !lastInst->isCall() && !lastInst->isFReturn() && + !lastInst->isFCall()) { + return false; + } + + send_may_kill.dst = *allDstGlobalIDs; + send_may_kill.src = *allSrcGlobalIDs; + send_WAW_may_kill = *allDstGlobalIDs; + + return true; +} + // // Scan to check which global send operand for sends will be killed by current // BB. Note that there is no guarantee the send operand will in the live in set diff --git a/visa/LocalScheduler/SWSB_G4IR.h b/visa/LocalScheduler/SWSB_G4IR.h index 611918c0afca..ce29148031af 100644 --- a/visa/LocalScheduler/SWSB_G4IR.h +++ b/visa/LocalScheduler/SWSB_G4IR.h @@ -784,6 +784,9 @@ class G4_BB_SB { bool &sameDstSrc); // Global SBID dependence analysis + bool handleCallForMayKilled(SparseBitVector *allDstGlobalIDs, + SparseBitVector *allSrcGlobalIDs); + void setSendOpndMayKilled(LiveGRFBuckets *globalSendsLB, SBNODE_VECT &SBNodes, PointsToAnalysis &p); void @@ -1079,6 +1082,10 @@ class SWSB { INST_LIST_ITER inst_it, int newInstID, BitSet *dstTokens, BitSet *srcTokens, bool &keepDst, bool removeAllToken); + void SWSBInitializeGlobalSends(SparseBitVector &allDstGlobalIDs, + SparseBitVector &allSrcGlobalIDs, + LiveGRFBuckets &globalSendsLB); + void SWSBInitializeGlobalNodesInBuckets(std::vector &dstGlobalIDs, std::vector &srcGlobalIDs,