Skip to content

Commit bda005b

Browse files
weiyu-chensys_zuul
authored andcommitted
Use pointer instead of string name to index LabelMap in legacy encoder.
Change-Id: Ib4aaa9b81dadbbecd384b835b628945d3d5fc079
1 parent 0aace4a commit bda005b

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

visa/BinaryEncoding.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,17 +3055,16 @@ bool BinaryEncoding::EncodeConditionalBranches(G4_INST *inst,
30553055
op == G4_endif ||
30563056
op == G4_join )
30573057
{
3058-
G4_Operand *jip = inst->asCFInst()->getJip();
3059-
if (jip && jip->isLabel())
3058+
G4_Label* jip = inst->asCFInst()->getJip();
3059+
if (jip)
30603060
{
3061-
jipLabel = inst->asCFInst()->getJipLabelStr();
3062-
int32_t info = GetLabelInfo(this->LabelMap, jipLabel);
3061+
int32_t info = GetLabelInfo(jip);
30633062
if (info == -1)
30643063
{
30653064
return false;
30663065
}
30673066
jipOffset = info - insOffset;
3068-
if ( !isValidIPOffset(jipOffset) )
3067+
if (!isValidIPOffset(jipOffset))
30693068
{
30703069
MUST_BE_TRUE(false, "invalid IP offset");
30713070
}
@@ -3092,17 +3091,16 @@ bool BinaryEncoding::EncodeConditionalBranches(G4_INST *inst,
30923091
op == G4_else ||
30933092
op == G4_goto )
30943093
{
3095-
G4_Operand *uip = inst->asCFInst()->getUip();
3096-
if ( uip && uip->isLabel() )
3094+
G4_Label* uip = inst->asCFInst()->getUip();
3095+
if (uip)
30973096
{
3098-
uipLabel = inst->asCFInst()->getUipLabelStr();
3099-
int32_t info = GetLabelInfo(this->LabelMap, uipLabel);
3097+
int32_t info = GetLabelInfo(uip);
31003098
if (info == -1)
31013099
{
31023100
return false;
31033101
}
31043102
uipOffset = info - insOffset;
3105-
if ( !isValidIPOffset(uipOffset) )
3103+
if (!isValidIPOffset(uipOffset))
31063104
{
31073105
MUST_BE_TRUE(false, "invalid IP offset");
31083106
}
@@ -3125,13 +3123,12 @@ bool BinaryEncoding::EncodeConditionalBranches(G4_INST *inst,
31253123
inst->getSrc(0)->isLabel() )
31263124
{
31273125
// find the label's IP count
3128-
G4_Operand *opnd = inst->getSrc(0);
3129-
std::string jmpLabel = opnd->asLabel()->getLabel();
3126+
G4_Label *opnd = inst->getSrc(0)->asLabel();
31303127
BinInst * mybin = inst->getBinInst();
31313128
// Calculate the address offset
31323129
// Label has the same IP count as the following instruction,
31333130
// "break 1" is to the fall through instruction
3134-
int32_t info = GetLabelInfo(this->LabelMap, jmpLabel);
3131+
int32_t info = GetLabelInfo(opnd);
31353132
if (info == -1)
31363133
{
31373134
return false;
@@ -3175,9 +3172,8 @@ bool BinaryEncoding::EncodeConditionalBranches(G4_INST *inst,
31753172

31763173
if (inst->getSrc(0)->isLabel())
31773174
{
3178-
G4_Operand *opnd = inst->getSrc(0);
3179-
std::string jmpLabel = opnd->asLabel()->getLabel();
3180-
int32_t info = GetLabelInfo(this->LabelMap, jmpLabel);
3175+
G4_Label *opnd = inst->getSrc(0)->asLabel();
3176+
int32_t info = GetLabelInfo(opnd);
31813177
if (info == -1)
31823178
{
31833179
return false;

visa/BinaryEncodingCNL.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,11 +1648,10 @@ bool BinaryEncodingCNL::EncodeConditionalBranches(G4_INST *inst,
16481648
op == G4_goto ||
16491649
op == G4_join )
16501650
{
1651-
G4_Operand *jip = inst->asCFInst()->getJip();
1652-
if (jip && jip->isLabel())
1651+
G4_Label *jip = inst->asCFInst()->getJip();
1652+
if (jip)
16531653
{
1654-
jipLabel = inst->asCFInst()->getJipLabelStr();
1655-
int32_t info = GetLabelInfo(this->LabelMap, jipLabel);
1654+
int32_t info = GetLabelInfo(jip);
16561655
if (info == -1)
16571656
{
16581657
return false;
@@ -1684,11 +1683,10 @@ bool BinaryEncodingCNL::EncodeConditionalBranches(G4_INST *inst,
16841683
op == G4_else ||
16851684
op == G4_goto )
16861685
{
1687-
G4_Operand *uip = inst->asCFInst()->getUip();
1688-
if ( uip && uip->isLabel() )
1686+
G4_Label* uip = inst->asCFInst()->getUip();
1687+
if (uip)
16891688
{
1690-
uipLabel = inst->asCFInst()->getUipLabelStr();
1691-
int32_t info = GetLabelInfo(this->LabelMap, uipLabel);
1689+
int32_t info = GetLabelInfo(uip);
16921690
if (info == -1)
16931691
{
16941692
return false;
@@ -1714,12 +1712,11 @@ bool BinaryEncodingCNL::EncodeConditionalBranches(G4_INST *inst,
17141712
{
17151713
// find the label's IP count
17161714
G4_Operand *opnd = inst->getSrc(0);
1717-
std::string jmpLabel = opnd->asLabel()->getLabel();
17181715
BinInst * mybin = inst->getBinInst();
17191716
// Calculate the address offset
17201717
// Label has the same IP count as the following instruction,
17211718
// "break 1" is to the fall through instruction
1722-
int32_t info = GetLabelInfo(this->LabelMap, jmpLabel);
1719+
int32_t info = GetLabelInfo(opnd->asLabel());
17231720
if (info == -1)
17241721
{
17251722
return false;
@@ -1755,8 +1752,7 @@ bool BinaryEncodingCNL::EncodeConditionalBranches(G4_INST *inst,
17551752
inst->getSrc(0)->isLabel() )
17561753
{
17571754
G4_Operand *opnd = inst->getSrc(0);
1758-
std::string jmpLabel = opnd->asLabel()->getLabel();
1759-
int32_t info = GetLabelInfo(this->LabelMap, jmpLabel);
1755+
int32_t info = GetLabelInfo(opnd->asLabel());
17601756
if (info == -1)
17611757
{
17621758
return false;

visa/Common_BinaryEncoding.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,8 +1489,7 @@ namespace vISA
14891489
protected:
14901490

14911491
// returns the offset for label in # of half instructions (kernel entry is 0), or -1 if the label is not present
1492-
inline uint32_t GetLabelInfo(std::map<std::string, uint32_t>& LabelMap,
1493-
std::string& label)
1492+
inline uint32_t GetLabelInfo(G4_Label* label)
14941493
{
14951494
auto iter = LabelMap.find(label);
14961495
if (iter == LabelMap.end())
@@ -1504,7 +1503,7 @@ namespace vISA
15041503
std::string fileName; ///< Name of the binary file
15051504
G4_Kernel& kernel;
15061505
BinInstList binInstList; ///< Reference to the binary instructions
1507-
std::map<std::string, uint32_t> LabelMap;
1506+
std::map<G4_Label*, uint32_t> LabelMap;
15081507

15091508
uint32_t instCounts;
15101509

@@ -1564,7 +1563,7 @@ namespace vISA
15641563
{
15651564
if (inst->isLabel())
15661565
{
1567-
this->LabelMap[inst->getLabelStr()] = globalHalfInstNum;
1566+
this->LabelMap[inst->getLabel()] = globalHalfInstNum;
15681567
}
15691568
else
15701569
{

0 commit comments

Comments
 (0)