@@ -690,10 +690,10 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
690
690
//
691
691
addPredSuccEdges (curr_BB, next_BB);
692
692
}
693
- else if (i->getPredicate () != NULL ) // pred means conditional branch
693
+ else if (i->getPredicate ())
694
694
{
695
695
// add fall through edge
696
- addPredSuccEdges (curr_BB, next_BB);
696
+ addUniquePredSuccEdges (curr_BB, next_BB);
697
697
}
698
698
} // if (i->opcode()
699
699
else if (i->opcode () == G4_if || i->opcode () == G4_while ||
@@ -743,7 +743,7 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
743
743
//
744
744
// pred means conditional branch
745
745
//
746
- if (i->getPredicate () != NULL ) // need to add fall through edge
746
+ if (i->getPredicate () != NULL )
747
747
{
748
748
// add fall through edge
749
749
addPredSuccEdges (curr_BB, next_BB);
@@ -753,7 +753,7 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
753
753
{
754
754
// does nothing for unconditional return;
755
755
// later phase will link the return and the return address
756
- if (i->getPredicate () != NULL ) // need to add fall through edge
756
+ if (i->getPredicate () != NULL )
757
757
{
758
758
// add fall through edge
759
759
addPredSuccEdges (curr_BB, next_BB);
@@ -765,7 +765,7 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
765
765
}
766
766
else if (i->opcode () == G4_pseudo_fret || i->opcode () == G4_pseudo_fc_ret)
767
767
{
768
- if (i->getPredicate () != NULL )
768
+ if (i->getPredicate ())
769
769
{
770
770
// need to add fall through edge
771
771
addPredSuccEdges (curr_BB, next_BB);
@@ -777,10 +777,11 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
777
777
hasSIMDCF = true ;
778
778
addPredSuccEdges (curr_BB, getLabelBB (labelMap, i->asCFInst ()->getUipLabelStr ()));
779
779
780
- if (i->getPredicate () != NULL )
780
+ if (i->getPredicate ())
781
781
{
782
- // fall through
783
- addPredSuccEdges (curr_BB, next_BB);
782
+ // fall through, but check if goto target is same as fall-thru
783
+ // FIXME: replace all addPredSuccEdges with addUniquePredSuccEdges?
784
+ addUniquePredSuccEdges (curr_BB, next_BB);
784
785
}
785
786
}
786
787
else
@@ -1938,25 +1939,23 @@ void FlowGraph::removeRedundantLabels()
1938
1939
1939
1940
// check if the label is a function label
1940
1941
unsigned int numNonCallerPreds = 0 ;
1941
- BB_LIST_ITER lt = bb->Preds .begin ();
1942
- BB_LIST_ITER ltEnd = bb->Preds .end ();
1943
1942
bool isFuncLabel = true ;
1944
1943
G4_BB* pred_bb = NULL ;
1945
- for (; lt != ltEnd; ++lt )
1944
+ for (auto pred : bb-> Preds )
1946
1945
{
1947
- if (!((*lt) ->isEndWithCall () ))
1946
+ if (!pred ->isEndWithCall ())
1948
1947
{
1949
1948
if (numNonCallerPreds > 0 )
1950
1949
{
1951
1950
isFuncLabel = false ;
1952
1951
break ;
1953
1952
}
1954
1953
numNonCallerPreds++;
1955
- pred_bb = (*lt) ;
1954
+ pred_bb = pred ;
1956
1955
}
1957
1956
else
1958
1957
{
1959
- G4_INST *i = (*lt) ->back ();
1958
+ G4_INST *i = pred ->back ();
1960
1959
if (i->getSrc (0 )->isLabel ())
1961
1960
{
1962
1961
if (i->getSrc (0 ) != removedBlockInst->getLabel ())
@@ -1967,7 +1966,7 @@ void FlowGraph::removeRedundantLabels()
1967
1966
break ;
1968
1967
}
1969
1968
numNonCallerPreds++;
1970
- pred_bb = (*lt) ;
1969
+ pred_bb = pred ;
1971
1970
}
1972
1971
}
1973
1972
}
@@ -1989,18 +1988,11 @@ void FlowGraph::removeRedundantLabels()
1989
1988
G4_Label *succ_label = bb->Succs .front ()->front ()->getLabel ();
1990
1989
1991
1990
// check if the last inst of pred is a control flow inst
1992
- lt = bb->Preds .begin ();
1993
- for (; lt != bb->Preds .end (); ++lt)
1991
+ for (auto pred : bb->Preds )
1994
1992
{
1995
- BB_LIST_ITER jt = (*lt) ->Succs .begin ();
1993
+ auto jt = std::find (pred ->Succs .begin (), pred-> Succs . end (), bb );
1996
1994
1997
- for (; jt != (*lt)->Succs .end (); ++jt)
1998
- {
1999
- if ((*jt) == bb) {
2000
- break ;
2001
- }
2002
- }
2003
- G4_INST *i = (*lt)->back ();
1995
+ G4_INST *i = pred->back ();
2004
1996
// replace label in instructions
2005
1997
if (i->isFlowControl ())
2006
1998
{
@@ -2009,8 +2001,8 @@ void FlowGraph::removeRedundantLabels()
2009
2001
// due to the switchjmp we may have multiple jmpi
2010
2002
// at the end of a block.
2011
2003
bool foundMatchingJmp = false ;
2012
- for (INST_LIST::iterator iter = --(*lt) ->end ();
2013
- iter != (*lt) ->begin (); --iter)
2004
+ for (INST_LIST::iterator iter = --pred ->end ();
2005
+ iter != pred ->begin (); --iter)
2014
2006
{
2015
2007
i = *iter;
2016
2008
if (i->opcode () == G4_jmpi)
@@ -2096,8 +2088,8 @@ void FlowGraph::removeRedundantLabels()
2096
2088
}
2097
2089
}
2098
2090
2099
- (*lt) ->Succs .insert (jt, bb->Succs .front ());
2100
- (*lt) ->Succs .erase (jt);
2091
+ pred ->Succs .insert (jt, bb->Succs .front ());
2092
+ pred ->Succs .erase (jt);
2101
2093
2102
2094
// [Bug1915]: In rare case the precessor may have more than one Succ edge pointing
2103
2095
// to the same BB, due to empty block being eliminated. For example, with
@@ -2114,16 +2106,16 @@ void FlowGraph::removeRedundantLabels()
2114
2106
// elsewhere there may be assumptions that if a BB ends with a jump it must have
2115
2107
// two successors
2116
2108
{
2117
- BB_LIST_ITER succs = (*lt) ->Succs .begin ();
2118
- BB_LIST_ITER end = (*lt) ->Succs .end ();
2109
+ BB_LIST_ITER succs = pred ->Succs .begin ();
2110
+ BB_LIST_ITER end = pred ->Succs .end ();
2119
2111
while (succs != end)
2120
2112
{
2121
2113
BB_LIST_ITER iter = succs;
2122
2114
++succs;
2123
2115
if ((*iter) == bb)
2124
2116
{
2125
- (*lt) ->Succs .insert (iter, bb->Succs .front ());
2126
- (*lt) ->Succs .erase (iter);
2117
+ pred ->Succs .insert (iter, bb->Succs .front ());
2118
+ pred ->Succs .erase (iter);
2127
2119
}
2128
2120
}
2129
2121
}
0 commit comments