Skip to content

Commit

Permalink
Reduce compilation time with subroutine call
Browse files Browse the repository at this point in the history
Sync all the token dependences before callsites and return, so that
there is no dependence will cross them.
  • Loading branch information
bcheng0127 authored and igcbot committed Sep 19, 2024
1 parent dd07ef6 commit 4caeedf
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
76 changes: 75 additions & 1 deletion visa/LocalScheduler/SWSB_G4IR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1533,6 +1562,12 @@ void SWSB::SWSBGlobalTokenGenerator(PointsToAnalysis &p, LiveGRFBuckets &LB,

std::vector<SparseBitVector> dstGlobalIDs;
std::vector<SparseBitVector> 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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() ||
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions visa/LocalScheduler/SWSB_G4IR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<SparseBitVector> &dstGlobalIDs,
std::vector<SparseBitVector> &srcGlobalIDs,
Expand Down

0 comments on commit 4caeedf

Please sign in to comment.