Skip to content

Commit d12d145

Browse files
jgu222igcbot
authored andcommitted
[Autobackout][FuncReg]Revert of change: d73d912
Try to merge unnecessary bb, specially for while BB that is generated by visa structurizer. pred: <last inst is non-control-flow inst> bb: If bb is sole succ of pred and pred is sole succ of bb, and pred does not end with a control-flow inst, and bb's label isn't used at all (checking bream if bb ends with while), then merge bb into pred. Note that bb's label is removed. 2nd try: after fixing a WA (EOT using flag) exposed by the 1st try. 3rd try: after fixing a visa logic optim bug.
1 parent c0b068e commit d12d145

File tree

1 file changed

+14
-89
lines changed

1 file changed

+14
-89
lines changed

visa/FlowGraph.cpp

Lines changed: 14 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,6 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
962962
{
963963
doCFGStructurize(this);
964964
pKernel->dumpToFile("after.CFGStructurizer");
965-
966-
removeRedundantLabels();
967-
pKernel->dumpToFile("after.PostStructurizerRedundantLabels");
968965
}
969966
else
970967
{
@@ -1864,13 +1861,13 @@ void FlowGraph::removeRedundantLabels()
18641861
}
18651862
}
18661863

1867-
for (BB_LIST_ITER nextit = BBs.begin(), ite = BBs.end(); nextit != ite; )
1864+
1865+
for (BB_LIST_ITER it = BBs.begin(); it != BBs.end();)
18681866
{
1869-
BB_LIST_ITER it = nextit++;
18701867
G4_BB* bb = *it;
1871-
18721868
if (bb == getEntryBB())
18731869
{
1870+
it++;
18741871
continue;
18751872
}
18761873
if (bb->Succs.size() == 0 && bb->Preds.size() == 0) {
@@ -1879,41 +1876,31 @@ void FlowGraph::removeRedundantLabels()
18791876
//for example return after infinite loop.
18801877
if (bb->isEndWithFRet() || (bb->size() > 0 && ((G4_INST*)bb->back())->isReturn()))
18811878
{
1879+
it++;
18821880
continue;
18831881
}
18841882

18851883
bb->clear();
1886-
erase(it);
1884+
BB_LIST_ITER rt = it++;
1885+
erase(rt);
18871886

18881887
continue;
18891888
}
18901889

1891-
assert(bb->size() > 0 && bb->front()->isLabel() &&
1892-
"Every BB should at least have a label inst!");
1893-
1894-
// Possible kernel's entry, don't delete.
1895-
if (strcmp(bb->front()->getLabelStr(), "per-thread-prolog") == 0)
1896-
{
1897-
continue;
1898-
}
1899-
1900-
if (bb->getBBType() &
1901-
(G4_BB_CALL_TYPE | G4_BB_EXIT_TYPE | G4_BB_INIT_TYPE | G4_BB_RETURN_TYPE))
1902-
{
1903-
// Keep those BBs
1904-
continue;
1905-
}
1890+
assert(bb->size() > 0 && "Every BB should at least have a label inst!");
19061891

19071892
//
19081893
// The removal candidates will have a single successor and a single inst
19091894
//
19101895
if (bb->Succs.size() == 1 && bb->size() == 1)
19111896
{
19121897
G4_INST* removedBlockInst = bb->front();
1913-
if (removedBlockInst->getLabel()->isFuncLabel() ||
1898+
if (removedBlockInst->isLabel() == false ||
1899+
removedBlockInst->getLabel()->isFuncLabel() ||
19141900
strncmp(removedBlockInst->getLabelStr(), "LABEL__EMPTYBB", 14) == 0 ||
19151901
strncmp(removedBlockInst->getLabelStr(), "__AUTO_GENERATED_DUMMY_LAST_BB", 30) == 0)
19161902
{
1903+
++it;
19171904
continue;
19181905
}
19191906

@@ -2071,74 +2058,12 @@ void FlowGraph::removeRedundantLabels()
20712058
bb->Preds.clear();
20722059
bb->clear();
20732060

2074-
erase(it);
2061+
BB_LIST_ITER rt = it++;
2062+
erase(rt);
20752063
}
2076-
else if (bb->Preds.size() == 1 && bb->Preds.front()->Succs.size() == 1)
2064+
else
20772065
{
2078-
// Merge bb into singlePred and delete bb if all the following are true:
2079-
// 1. singlePred has no control-flow inst (at the end),
2080-
// 2. bb's label is not used at all.
2081-
//
2082-
// singlePred:
2083-
// ....
2084-
// bb:
2085-
// ....
2086-
//
2087-
// If singlePred does not end with a control-flow inst, bb's label is not used except
2088-
// bb ends with while. For while bb, we need further to check if any break uses label.
2089-
// As break should jump to while bb's fall-thru (not while bb), we need to follow all
2090-
// preds of while's fall-thru BB to see if any pred has a break.
2091-
//
2092-
G4_BB* singlePred = bb->Preds.front();
2093-
G4_INST* labelInst = bb->front();
2094-
assert(labelInst->isLabel());
2095-
if (!singlePred->back()->isFlowControl() &&
2096-
singlePred->getPhysicalSucc() == bb /* sanity */ &&
2097-
!labelInst->getLabel()->isFuncLabel() /* skip special bb */ &&
2098-
bb != singlePred /* [special] skip dead single-BB loop */)
2099-
{
2100-
bool doMerging = true;
2101-
G4_INST* whileInst = bb->back();
2102-
if (whileInst->opcode() == G4_while)
2103-
{
2104-
// If there is any break inst for this while, the break uses the label. No merging.
2105-
// Note that any break inst of this while will jump to the BB right after while BB
2106-
// (this BB is the fall-thru BB of while if while BB has fall-thru, or just its physical
2107-
// succ if it has no fall-thru).
2108-
G4_BB* whilePhySucc = bb->getPhysicalSucc();
2109-
if (whilePhySucc)
2110-
{
2111-
for (auto breakPred : whilePhySucc->Preds)
2112-
{
2113-
if (breakPred->getLastOpcode() == G4_break) {
2114-
doMerging = false;
2115-
break;
2116-
}
2117-
}
2118-
}
2119-
}
2120-
2121-
if (doMerging)
2122-
{
2123-
removePredSuccEdges(singlePred, bb);
2124-
assert(singlePred->Succs.size() == 0);
2125-
std::vector<G4_BB*> allSuccBBs(bb->Succs.begin(), bb->Succs.end());
2126-
for (auto S : allSuccBBs)
2127-
{
2128-
removePredSuccEdges(bb, S);
2129-
addPredSuccEdges(singlePred, S, false);
2130-
}
2131-
2132-
// remove bb's label before splice
2133-
bb->remove(labelInst);
2134-
singlePred->getInstList().splice(singlePred->end(), bb->getInstList());
2135-
2136-
bb->Succs.clear();
2137-
bb->Preds.clear();
2138-
2139-
erase(it);
2140-
}
2141-
}
2066+
++it;
21422067
}
21432068
}
21442069

0 commit comments

Comments
 (0)