@@ -962,9 +962,6 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
962
962
{
963
963
doCFGStructurize (this );
964
964
pKernel->dumpToFile (" after.CFGStructurizer" );
965
-
966
- removeRedundantLabels ();
967
- pKernel->dumpToFile (" after.PostStructurizerRedundantLabels" );
968
965
}
969
966
else
970
967
{
@@ -1864,13 +1861,13 @@ void FlowGraph::removeRedundantLabels()
1864
1861
}
1865
1862
}
1866
1863
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 ();)
1868
1866
{
1869
- BB_LIST_ITER it = nextit++;
1870
1867
G4_BB* bb = *it;
1871
-
1872
1868
if (bb == getEntryBB ())
1873
1869
{
1870
+ it++;
1874
1871
continue ;
1875
1872
}
1876
1873
if (bb->Succs .size () == 0 && bb->Preds .size () == 0 ) {
@@ -1879,41 +1876,31 @@ void FlowGraph::removeRedundantLabels()
1879
1876
// for example return after infinite loop.
1880
1877
if (bb->isEndWithFRet () || (bb->size () > 0 && ((G4_INST*)bb->back ())->isReturn ()))
1881
1878
{
1879
+ it++;
1882
1880
continue ;
1883
1881
}
1884
1882
1885
1883
bb->clear ();
1886
- erase (it);
1884
+ BB_LIST_ITER rt = it++;
1885
+ erase (rt);
1887
1886
1888
1887
continue ;
1889
1888
}
1890
1889
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!" );
1906
1891
1907
1892
//
1908
1893
// The removal candidates will have a single successor and a single inst
1909
1894
//
1910
1895
if (bb->Succs .size () == 1 && bb->size () == 1 )
1911
1896
{
1912
1897
G4_INST* removedBlockInst = bb->front ();
1913
- if (removedBlockInst->getLabel ()->isFuncLabel () ||
1898
+ if (removedBlockInst->isLabel () == false ||
1899
+ removedBlockInst->getLabel ()->isFuncLabel () ||
1914
1900
strncmp (removedBlockInst->getLabelStr (), " LABEL__EMPTYBB" , 14 ) == 0 ||
1915
1901
strncmp (removedBlockInst->getLabelStr (), " __AUTO_GENERATED_DUMMY_LAST_BB" , 30 ) == 0 )
1916
1902
{
1903
+ ++it;
1917
1904
continue ;
1918
1905
}
1919
1906
@@ -2071,74 +2058,12 @@ void FlowGraph::removeRedundantLabels()
2071
2058
bb->Preds .clear ();
2072
2059
bb->clear ();
2073
2060
2074
- erase (it);
2061
+ BB_LIST_ITER rt = it++;
2062
+ erase (rt);
2075
2063
}
2076
- else if (bb-> Preds . size () == 1 && bb-> Preds . front ()-> Succs . size () == 1 )
2064
+ else
2077
2065
{
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;
2142
2067
}
2143
2068
}
2144
2069
0 commit comments