Skip to content

Commit 643fefd

Browse files
petechouigcbot
authored andcommitted
SWSB: Cache the footprint in SBBucketDesc and SBBucketNode directly.
Doing so can save the cost to use inst to get the corresponding footprint, and we can still get the inst via footprint when needed.
1 parent 707ef15 commit 643fefd

File tree

2 files changed

+53
-65
lines changed

2 files changed

+53
-65
lines changed

visa/LocalScheduler/SWSB_G4IR.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4679,7 +4679,7 @@ void G4_BB_SB::setSendOpndMayKilled(LiveGRFBuckets* globalSendsLB,
46794679
SBNODE_VECT* SBNodes,
46804680
PointsToAnalysis& p)
46814681
{
4682-
std::vector<SBBucketDescr> BDvec;
4682+
std::vector<SBBucketDesc> BDvec;
46834683
if (first_node == -1)
46844684
{
46854685
return;
@@ -4697,26 +4697,26 @@ void G4_BB_SB::setSendOpndMayKilled(LiveGRFBuckets* globalSendsLB,
46974697
}
46984698

46994699
BDvec.clear();
4700-
getGRFBucketDescrs(node, BDvec, true);
4700+
getGRFBucketDescs(node, BDvec, true);
47014701
if (!BDvec.size())
47024702
{
47034703
continue;
47044704
}
47054705

47064706
// For all bucket descriptors of curInst
4707-
for (const SBBucketDescr& BD : BDvec) {
4707+
for (const SBBucketDesc& BD : BDvec) {
47084708
const int& curBucket = BD.bucket;
47094709
const Gen4_Operand_Number& curOpnd = BD.opndNum;
4710-
const SBFootprint* curFootprint = BD.node->getFootprint(BD.opndNum, BD.inst);
4710+
const SBFootprint* curFootprint = BD.footprint;
47114711

47124712
for (LiveGRFBuckets::BN_iterator bn_it = globalSendsLB->begin(curBucket);
47134713
bn_it != globalSendsLB->end(curBucket);)
47144714
{
47154715
SBBucketNode* liveBN = (*bn_it);
47164716
SBNode* curLiveNode = liveBN->node;
47174717
Gen4_Operand_Number liveOpnd = liveBN->opndNum;
4718-
G4_INST* liveInst = liveBN->inst;
4719-
const SBFootprint* liveFootprint = curLiveNode->getFootprint(liveBN->opndNum,liveInst);
4718+
const SBFootprint* liveFootprint = liveBN->footprint;
4719+
G4_INST* liveInst = liveFootprint->inst;
47204720

47214721
//Send operands are all GRF aligned, there is no overlap checking required.
47224722
//Fix me, this is not right, for math instruction, less than 1 GRF may happen.
@@ -4743,7 +4743,7 @@ void G4_BB_SB::setSendOpndMayKilled(LiveGRFBuckets* globalSendsLB,
47434743
}
47444744

47454745
if (dep == WAR &&
4746-
WARDepRequired(liveInst, BD.inst))
4746+
WARDepRequired(liveInst, curFootprint->inst))
47474747
{
47484748
send_may_kill.setSrc(curLiveNode->globalID, true);
47494749
}
@@ -4779,7 +4779,7 @@ void G4_BB_SB::setSendOpndMayKilled(LiveGRFBuckets* globalSendsLB,
47794779
{
47804780
SBBucketNode* liveBN = (*bn_it);
47814781
SBNode* curLiveNode = liveBN->node;
4782-
G4_INST* liveInst = liveBN->inst;
4782+
G4_INST* liveInst = liveBN->footprint->inst;
47834783

47844784
if (liveInst->isSend() &&
47854785
isSLMMsg(liveInst) && liveInst->getDst() != nullptr && !liveInst->getDst()->isNullReg())
@@ -4964,7 +4964,7 @@ void G4_BB_SB::getGRFFootprintForIndirect(SBNode* node,
49644964
void G4_BB_SB::getGRFBuckets(SBNode* node,
49654965
const SBFootprint* footprint,
49664966
Gen4_Operand_Number opndNum,
4967-
std::vector<SBBucketDescr>& BDvec,
4967+
std::vector<SBBucketDesc>& BDvec,
49684968
bool GRFOnly)
49694969
{
49704970
for (const SBFootprint* curFootprint = footprint; curFootprint != nullptr; curFootprint = curFootprint->next)
@@ -4986,7 +4986,7 @@ void G4_BB_SB::getGRFBuckets(SBNode* node,
49864986
for (int j = startingBucket;
49874987
j < (startingBucket + numBuckets); j++)
49884988
{
4989-
BDvec.push_back(SBBucketDescr(j, opndNum, node, curFootprint->inst));
4989+
BDvec.push_back(SBBucketDesc(j, opndNum, node, curFootprint));
49904990
}
49914991
}
49924992
}
@@ -5029,7 +5029,7 @@ bool G4_BB_SB::getGRFFootPrintOperands(SBNode* node,
50295029
void G4_BB_SB::getGRFBucketsForOperands(SBNode* node,
50305030
Gen4_Operand_Number first_opnd,
50315031
Gen4_Operand_Number last_opnd,
5032-
std::vector<SBBucketDescr>& BDvec,
5032+
std::vector<SBBucketDesc>& BDvec,
50335033
bool GRFOnly)
50345034
{
50355035
for (Gen4_Operand_Number opndNum = first_opnd; opndNum <= last_opnd; opndNum = (Gen4_Operand_Number)(opndNum + 1))
@@ -5059,7 +5059,7 @@ bool G4_BB_SB::getGRFFootPrint(SBNode* node, PointsToAnalysis& p)
50595059
return hasDistOneAReg;
50605060
}
50615061

5062-
void G4_BB_SB::getGRFBucketDescrs(SBNode* node, std::vector<SBBucketDescr>& BDvec, bool GRFOnly)
5062+
void G4_BB_SB::getGRFBucketDescs(SBNode* node, std::vector<SBBucketDesc>& BDvec, bool GRFOnly)
50635063
{
50645064
//We get the description for source first, so for current instruction, the scan order is src0, src1, src2, src3, dst
50655065
getGRFBucketsForOperands(node, Opnd_src0, Opnd_src3, BDvec, GRFOnly);
@@ -5169,7 +5169,7 @@ void G4_BB_SB::clearSLMWARWAissue(SBNode* curNode, LiveGRFBuckets* LB)
51695169
{
51705170
SBBucketNode* liveBN = (*it);
51715171
SBNode* curLiveNode = liveBN->node;
5172-
G4_INST* liveInst = liveBN->inst;
5172+
G4_INST* liveInst = liveBN->footprint->inst;
51735173

51745174
if (liveInst->isSend() &&
51755175
isSLMMsg(liveInst) && liveInst->getDst() != nullptr && !liveInst->getDst()->isNullReg())
@@ -5848,15 +5848,15 @@ void G4_BB_SB::SBDDD(G4_BB* bb,
58485848
}
58495849

58505850
//Get buckets for all GRF registers which are used in curInst
5851-
std::vector<SBBucketDescr> BDvec;
5852-
std::vector<SBBucketDescr> liveBDvec;
5851+
std::vector<SBBucketDesc> BDvec;
5852+
std::vector<SBBucketDesc> liveBDvec;
58535853
BDvec.clear();
58545854
liveBDvec.clear();
58555855

5856-
getGRFBucketDescrs(node, BDvec, false);
5856+
getGRFBucketDescs(node, BDvec, false);
58575857
if (node->instVec.size() > 1)
58585858
{
5859-
getGRFBucketDescrs(node, liveBDvec, false);
5859+
getGRFBucketDescs(node, liveBDvec, false);
58605860
}
58615861

58625862
if (builder.hasThreeALUPipes() || builder.hasFourALUPipes())
@@ -5936,10 +5936,10 @@ void G4_BB_SB::SBDDD(G4_BB* bb,
59365936
bool instKill = false;
59375937

59385938
// For all bucket descriptors of curInst
5939-
for (const SBBucketDescr& BD : BDvec) {
5939+
for (const SBBucketDesc& BD : BDvec) {
59405940
const int& curBucket = BD.bucket;
59415941
const Gen4_Operand_Number& curOpnd = BD.opndNum;
5942-
const SBFootprint* curFootprint = BD.node->getFootprint(BD.opndNum, BD.inst);
5942+
const SBFootprint* curFootprint = BD.footprint;
59435943

59445944
// Check liveness for each live curBucket node.
59455945
// Add explicit dependence if liveness is killed and there is no implicit dependence
@@ -5960,8 +5960,8 @@ void G4_BB_SB::SBDDD(G4_BB* bb,
59605960

59615961
unsigned short internalOffset = 0;
59625962
Gen4_Operand_Number liveOpnd = liveBN->opndNum;
5963-
G4_INST* liveInst = liveBN->inst;
5964-
const SBFootprint* liveFootprint = liveNode->getFootprint(liveBN->opndNum, liveInst);
5963+
const SBFootprint* liveFootprint = liveBN->footprint;
5964+
G4_INST* liveInst = liveFootprint->inst;
59655965

59665966
bool hasOverlap = curFootprint->hasOverlap(liveFootprint, internalOffset);
59675967
bool hasRMWOverlap = false;
@@ -6290,33 +6290,33 @@ void G4_BB_SB::SBDDD(G4_BB* bb,
62906290
// Add buckets of current instruction to bucket list
62916291
if (node->instVec.size() > 1)
62926292
{
6293-
std::map<G4_INST*, std::vector<SBBucketNode*>> bucketNodes;
6294-
for (const SBBucketDescr& BD : liveBDvec)
6293+
std::map<const SBFootprint*, std::vector<SBBucketNode*>> bucketNodes;
6294+
for (const SBBucketDesc& BD : liveBDvec)
62956295
{
6296-
auto iter = std::find_if(bucketNodes[BD.inst].begin(), bucketNodes[BD.inst].end(),
6296+
auto iter = std::find_if(bucketNodes[BD.footprint].begin(), bucketNodes[BD.footprint].end(),
62976297
[&BD](SBBucketNode* node) {return BD.opndNum == node->opndNum; });
6298-
if (iter != bucketNodes[BD.inst].end())
6298+
if (iter != bucketNodes[BD.footprint].end())
62996299
{
63006300
LB->add((*iter), BD.bucket);
63016301
}
63026302
else
63036303
{
63046304
void* allocedMem = mem.alloc(sizeof(SBBucketNode));
6305-
SBBucketNode* newNode = new (allocedMem)SBBucketNode(node, BD.opndNum, BD.inst);
6306-
bucketNodes[BD.inst].push_back(newNode);
6305+
SBBucketNode* newNode = new (allocedMem)SBBucketNode(node, BD.opndNum, BD.footprint);
6306+
bucketNodes[BD.footprint].push_back(newNode);
63076307
LB->add(newNode, BD.bucket);
63086308
}
63096309
}
63106310
}
63116311
else
63126312
{
63136313
std::vector<SBBucketNode*> bucketNodes(Opnd_total_num, nullptr); //The coarse grained footprint of operands
6314-
for (const SBBucketDescr& BD : BDvec)
6314+
for (const SBBucketDesc& BD : BDvec)
63156315
{
63166316
if (bucketNodes[BD.opndNum] == nullptr)
63176317
{
63186318
void* allocedMem = mem.alloc(sizeof(SBBucketNode));
6319-
SBBucketNode* newNode = new (allocedMem)SBBucketNode(node, BD.opndNum, BD.inst);
6319+
SBBucketNode* newNode = new (allocedMem)SBBucketNode(node, BD.opndNum, BD.footprint);
63206320
bucketNodes[BD.opndNum] = newNode;
63216321
}
63226322

@@ -6786,35 +6786,35 @@ void SWSB::addGlobalDependence(unsigned globalSendNum, SBBUCKET_VECTOR* globalSe
67866786
}
67876787

67886788
//Scan BB again to figure out the dependence caused by global send operands
6789-
std::vector<SBBucketDescr> BDvec;
6789+
std::vector<SBBucketDesc> BDvec;
67906790
for (int j = BBVector[i]->first_node; j <= BBVector[i]->last_node; j++)
67916791
{
67926792
SBNode* node = (*SBNodes)[j];
67936793
G4_INST* curInst = node->getLastInstruction();
67946794

67956795
BDvec.clear();
6796-
BBVector[i]->getGRFBucketDescrs(node, BDvec, true);
6796+
BBVector[i]->getGRFBucketDescs(node, BDvec, true);
67976797
if (!BDvec.size())
67986798
{
67996799
continue;
68006800
}
68016801

68026802
bool instKill = false;
68036803
// For all bucket descriptors of curInst
6804-
for (const SBBucketDescr& BD : BDvec)
6804+
for (const SBBucketDesc& BD : BDvec)
68056805
{
68066806
const int& curBucket = BD.bucket;
68076807
const Gen4_Operand_Number& curOpnd = BD.opndNum;
6808-
const SBFootprint* curFootprint = BD.node->getFootprint(BD.opndNum, BD.inst);
6808+
const SBFootprint* curFootprint = BD.footprint;
68096809

68106810
for (LiveGRFBuckets::BN_iterator bn_it = send_use_kills.begin(curBucket);
68116811
bn_it != send_use_kills.end(curBucket);)
68126812
{
68136813
SBBucketNode* liveBN = (*bn_it);
68146814
SBNode* curLiveNode = liveBN->node;
68156815
Gen4_Operand_Number liveOpnd = liveBN->opndNum;
6816-
G4_INST* liveInst = liveBN->inst;
6817-
const SBFootprint* liveFootprint = curLiveNode->getFootprint(liveBN->opndNum, liveInst);
6816+
const SBFootprint* liveFootprint = liveBN->footprint;
6817+
G4_INST* liveInst = liveFootprint->inst;
68186818
unsigned short internalOffset = 0;
68196819
bool hasOverlap = curFootprint->hasOverlap(liveFootprint, internalOffset);
68206820

@@ -7144,14 +7144,14 @@ void SWSB::addGlobalDependenceWithReachingDef(unsigned globalSendNum, SBBUCKET_V
71447144
localTokenUsage.clear(); //Add to the live node
71457145

71467146
//Scan BB again to figure out the dependence caused by global send operands
7147-
std::vector<SBBucketDescr> BDvec;
7147+
std::vector<SBBucketDesc> BDvec;
71487148
for (int j = BBVector[i]->first_node; j <= BBVector[i]->last_node; j++)
71497149
{
71507150
SBNode* node = (*SBNodes)[j];
71517151
G4_INST* curInst = (*SBNodes)[j]->getLastInstruction();
71527152

71537153
BDvec.clear();
7154-
BBVector[i]->getGRFBucketDescrs(node, BDvec, true);
7154+
BBVector[i]->getGRFBucketDescs(node, BDvec, true);
71557155
if (!BDvec.size())
71567156
{
71577157
continue;
@@ -7178,20 +7178,20 @@ void SWSB::addGlobalDependenceWithReachingDef(unsigned globalSendNum, SBBUCKET_V
71787178

71797179
bool instKill = false;
71807180
// For all bucket descriptors of curInst
7181-
for (const SBBucketDescr& BD : BDvec)
7181+
for (const SBBucketDesc& BD : BDvec)
71827182
{
71837183
const int& curBucket = BD.bucket;
71847184
const Gen4_Operand_Number& curOpnd = BD.opndNum;
7185-
const SBFootprint* curFootprint = BD.node->getFootprint(BD.opndNum, BD.inst);
7185+
const SBFootprint* curFootprint = BD.footprint;
71867186

71877187
for (LiveGRFBuckets::BN_iterator bn_it = send_use_kills.begin(curBucket);
71887188
bn_it != send_use_kills.end(curBucket);)
71897189
{
71907190
SBBucketNode* liveBN = (*bn_it);
71917191
SBNode* curLiveNode = liveBN->node;
71927192
Gen4_Operand_Number liveOpnd = liveBN->opndNum;
7193-
G4_INST* liveInst = liveBN->inst;
7194-
const SBFootprint* liveFootprint = curLiveNode->getFootprint(liveBN->opndNum, liveInst);
7193+
const SBFootprint* liveFootprint = liveBN->footprint;
7194+
G4_INST* liveInst = liveFootprint->inst;
71957195
unsigned short internalOffset = 0;
71967196
bool hasOverlap = curFootprint->hasOverlap(liveFootprint, internalOffset);
71977197

visa/LocalScheduler/SWSB_G4IR.h

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -638,18 +638,6 @@ namespace vISA
638638
return footprints[opndNum];
639639
}
640640

641-
const SBFootprint *getFootprint(Gen4_Operand_Number opndNum, const G4_INST *inst) const
642-
{
643-
for (const SBFootprint *sbFp = footprints[opndNum]; ; sbFp = sbFp->next)
644-
{
645-
assert((sbFp != nullptr) && "footprint not found");
646-
if (sbFp->inst == inst)
647-
{
648-
return sbFp;
649-
}
650-
}
651-
}
652-
653641
void setDistance(unsigned distance)
654642
{
655643
distance = std::min(distance, SWSB_MAX_ALU_DEPENDENCE_DISTANCE_VALUE);
@@ -1131,14 +1119,14 @@ typedef std::list<vISA::SBNode*>::iterator SBNODE_LIST_ITER;
11311119
namespace vISA
11321120
{
11331121
//Similar as SBBucketNode, but it's used for the bucket descriptions got from each operands.
1134-
struct SBBucketDescr {
1122+
struct SBBucketDesc {
11351123
const int bucket;
11361124
const Gen4_Operand_Number opndNum;
11371125
SBNode* const node;
1138-
G4_INST* const inst;
1126+
const SBFootprint* footprint;
11391127

1140-
SBBucketDescr(int Bucket, Gen4_Operand_Number opnd_num, SBNode *sNode, G4_INST *i)
1141-
: bucket(Bucket), opndNum(opnd_num), inst(i), node(sNode) {
1128+
SBBucketDesc(int Bucket, Gen4_Operand_Number opnd_num, SBNode *sNode, const SBFootprint *f)
1129+
: bucket(Bucket), opndNum(opnd_num), node(sNode), footprint(f) {
11421130
;
11431131
}
11441132
};
@@ -1149,10 +1137,10 @@ namespace vISA
11491137
SBNode* node;
11501138
Gen4_Operand_Number opndNum;
11511139
int sendID = -1;
1152-
G4_INST* inst;
1140+
const SBFootprint* footprint;
11531141

1154-
SBBucketNode(SBNode *node1, Gen4_Operand_Number opndNum1, G4_INST *i)
1155-
: node(node1), opndNum(opndNum1), inst(i)
1142+
SBBucketNode(SBNode *node1, Gen4_Operand_Number opndNum1, const SBFootprint *f)
1143+
: node(node1), opndNum(opndNum1), footprint(f)
11561144
{
11571145
}
11581146

@@ -1331,7 +1319,7 @@ namespace vISA
13311319
endBucket = endBucket + aregOffset;
13321320
}
13331321

1334-
if (footprint->inst == bucketNode->inst)
1322+
if (footprint->inst == bucketNode->footprint->inst)
13351323
{
13361324
for (unsigned int i = startBucket; (i < endBucket + 1) && (i < nodeBucketsArray.size()); i++)
13371325
{
@@ -1516,7 +1504,7 @@ namespace vISA
15161504
G4_INST *inst,
15171505
G4_Operand* opnd,
15181506
Gen4_Operand_Number opnd_num);
1519-
void getGRFBuckets(SBNode* node, const SBFootprint* footprint, Gen4_Operand_Number opndNum, std::vector<SBBucketDescr>& BDvec, bool GRFOnly);
1507+
void getGRFBuckets(SBNode* node, const SBFootprint* footprint, Gen4_Operand_Number opndNum, std::vector<SBBucketDesc>& BDvec, bool GRFOnly);
15201508
bool getGRFFootPrintOperands(SBNode *node,
15211509
G4_INST *inst,
15221510
Gen4_Operand_Number first_opnd,
@@ -1529,14 +1517,14 @@ namespace vISA
15291517
void getGRFBucketsForOperands(SBNode *node,
15301518
Gen4_Operand_Number first_opnd,
15311519
Gen4_Operand_Number last_opnd,
1532-
std::vector<SBBucketDescr>& BDvec,
1520+
std::vector<SBBucketDesc>& BDvec,
15331521
bool GRFOnly);
15341522

15351523
bool getGRFFootPrint(SBNode *node,
15361524
PointsToAnalysis &p);
15371525

1538-
void getGRFBucketDescrs(SBNode *node,
1539-
std::vector<SBBucketDescr>& BDvec,
1526+
void getGRFBucketDescs(SBNode *node,
1527+
std::vector<SBBucketDesc>& BDvec,
15401528
bool GRFOnly);
15411529

15421530
void clearSLMWARWAissue(SBNode* curNode, LiveGRFBuckets* LB);

0 commit comments

Comments
 (0)