Skip to content

Commit 7e2aeb7

Browse files
jgu222sys_zuul
authored andcommitted
Add a field in InstCF to indicate if an 'if/while/break/goto'
is uniform, meaning that the targets of all active lanes are the same. Change-Id: I1f330dd87a5b0d60719fd75058358a6ca1fd4d00
1 parent 0478267 commit 7e2aeb7

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

visa/CFGStructurizer.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,8 +3099,9 @@ void CFGStructurizer::convertIf(ANodeHG *node, G4_BB *nextJoinBB)
30993099
MUST_BE_TRUE(end->getPhysicalSucc() == exit,
31003100
"Landing BB should have been inserted during construction of hammock graph");
31013101

3102+
bool isUniform = isGotoScalarJmp(gotoInst);
31023103
ANodeKind kind = ANKIND_GOTOJOIN;
3103-
if (doScalarJmp && isGotoScalarJmp(gotoInst))
3104+
if (doScalarJmp && isUniform)
31043105
{
31053106
kind = ANKIND_JMPI;
31063107
}
@@ -3201,6 +3202,10 @@ void CFGStructurizer::convertIf(ANodeHG *node, G4_BB *nextJoinBB)
32013202
gotoInst->getLineNo(), gotoInst->getCISAOff(), gotoInst->getSrcFilename());
32023203
begin->pop_back();
32033204
begin->push_back(ifInst);
3205+
if (isUniform)
3206+
{
3207+
ifInst->asCFInst()->setUniform(true);
3208+
}
32043209

32053210
if (thenNode->isHammock())
32063211
{
@@ -3339,6 +3344,10 @@ void CFGStructurizer::convertIf(ANodeHG *node, G4_BB *nextJoinBB)
33393344
newThenLastBB->pop_back();
33403345
}
33413346
newThenLastBB->push_back(elseInst);
3347+
if (isUniform)
3348+
{
3349+
ifInst->asCFInst()->setUniform(true);
3350+
}
33423351

33433352
(void)convertPST(thenNode, node->getHasBreak() ? newThenLastBB : nullptr);
33443353

@@ -3383,8 +3392,9 @@ void CFGStructurizer::convertDoWhile(ANodeHG *node, G4_BB *nextJoinBB)
33833392
// need to check it out to avoid generating them.
33843393
//
33853394

3395+
bool isUniform = isGotoScalarJmp(gotoInst);
33863396
ANodeKind ndkind = ANKIND_GOTOJOIN;
3387-
if (doScalarJmp && isGotoScalarJmp(gotoInst) &&
3397+
if (doScalarJmp && isUniform &&
33883398
(!doStructCF || !node->getHasBreak()))
33893399
{
33903400
// If loop has break, favor structured CF, not jmpi
@@ -3419,6 +3429,10 @@ void CFGStructurizer::convertDoWhile(ANodeHG *node, G4_BB *nextJoinBB)
34193429
gotoInst->getLineNo(), gotoInst->getCISAOff(), gotoInst->getSrcFilename());
34203430
end->pop_back();
34213431
end->push_back(whileInst);
3432+
if (isUniform)
3433+
{
3434+
whileInst->asCFInst()->setUniform(true);
3435+
}
34223436

34233437
convertChildren(node, node->getHasBreak() ? end : nullptr);
34243438
}
@@ -3451,7 +3465,6 @@ void CFGStructurizer::generateGotoJoin(G4_BB *gotoBB, G4_BB *jibBB, G4_BB *joinB
34513465
uint8_t execSize = gotoInst->getExecSize();
34523466
execSize = execSize > 1 ? execSize : kernelExecSize;
34533467

3454-
34553468
if (gotoInst->getExecSize() == 1)
34563469
{ // For simd1 goto, convert it to a goto with the right execSize.
34573470
gotoInst->setExecSize(execSize);
@@ -3505,6 +3518,7 @@ void CFGStructurizer::convertGoto(ANodeBB *node, G4_BB *nextJoinBB)
35053518
}
35063519
node->setVisited(true);
35073520

3521+
bool isUniform = isGotoScalarJmp(gotoInst);
35083522
G4_BB *exitbb = node->getExitBB();
35093523
ANodeHG *innermostWhile = getInnerMostWhile(node);
35103524
ANodeKind kind = ANKIND_GOTOJOIN;
@@ -3520,7 +3534,7 @@ void CFGStructurizer::convertGoto(ANodeBB *node, G4_BB *nextJoinBB)
35203534
// nextJoinBB, if any, must be after getBeginBB(). So, if nextJoinBB
35213535
// is before exitbb, nextJoinBB is in the middle of [beginbb, exitbb]
35223536
bool hasJoinInMiddle = nextJoinBB && isBefore(nextJoinBB, exitbb);
3523-
if (doScalarJmp && isGotoScalarJmp(gotoInst) &&
3537+
if (doScalarJmp && isUniform &&
35243538
(gotoInst->asCFInst()->isBackward() || !hasJoinInMiddle))
35253539
{
35263540
kind = ANKIND_JMPI;
@@ -3599,6 +3613,10 @@ void CFGStructurizer::convertGoto(ANodeBB *node, G4_BB *nextJoinBB)
35993613
gotoInst->getSrcFilename());
36003614
beginbb->pop_back();
36013615
beginbb->push_back(breakInst);
3616+
if (isUniform)
3617+
{
3618+
breakInst->asCFInst()->setUniform(true);
3619+
}
36023620
return;
36033621
}
36043622

visa/Gen4_IR.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,13 @@ class G4_InstCF : public G4_INST
12351235
// list of labels that this instruction could jump to. Only used for switch jmps
12361236
std::list<G4_Label*> indirectJmpTarget;
12371237

1238-
// Ture if this is a backward branch.
1238+
// True if this is a backward branch.
12391239
bool isBackwardBr;
12401240

1241+
// True if this branch is a uniform (all active lanes goes to the same target)
1242+
// Valid for if/while/break/goto only. This could be encoded in instOpt
1243+
bool isUniformBr;
1244+
12411245
public:
12421246

12431247
static const uint32_t unknownCallee = 0xFFFF;
@@ -1251,9 +1255,9 @@ class G4_InstCF : public G4_INST
12511255
G4_Label* uipLabel,
12521256
uint32_t instOpt) :
12531257
G4_INST(builder, prd, op, nullptr, false, size, nullptr, nullptr, nullptr, instOpt),
1254-
jip(jipLabel), uip(uipLabel), isBackwardBr(false)
1258+
jip(jipLabel), uip(uipLabel), isBackwardBr(false), isUniformBr(false)
12551259
{
1256-
1260+
isUniformBr = (op == G4_goto && (size == 1 || prd == nullptr));
12571261
}
12581262

12591263
// used by jump/call/ret
@@ -1268,7 +1272,7 @@ class G4_InstCF : public G4_INST
12681272
G4_Operand* s0,
12691273
unsigned int opt) :
12701274
G4_INST(builder, prd, o, m, sat, size, d, s0, nullptr, opt),
1271-
jip(NULL), uip(NULL), isBackwardBr(false)
1275+
jip(NULL), uip(NULL), isBackwardBr(false), isUniformBr(false)
12721276
{
12731277
}
12741278

@@ -1299,6 +1303,9 @@ class G4_InstCF : public G4_INST
12991303

13001304
bool isBackward() const {return isBackwardBr;}
13011305

1306+
void setUniform(bool val) { isUniformBr = val; }
1307+
bool isUniform() const { return isUniformBr; }
1308+
13021309
bool isIndirectJmp() const;
13031310

13041311
bool isUniformGoto(unsigned KernelSimdSize) const;

0 commit comments

Comments
 (0)