Skip to content

Commit d147928

Browse files
weiyu-chenZuul
authored andcommitted
Fix a bug where we have duplicate pred/succ BBs due to a goto having the same target BB as its fall-through block.
Change-Id: I49ce3bbb5d3faba8873a295f563eb8b4489960e4
1 parent cda06a3 commit d147928

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

visa/FlowGraph.cpp

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,10 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
690690
//
691691
addPredSuccEdges(curr_BB, next_BB);
692692
}
693-
else if (i->getPredicate() != NULL) // pred means conditional branch
693+
else if (i->getPredicate())
694694
{
695695
// add fall through edge
696-
addPredSuccEdges(curr_BB, next_BB);
696+
addUniquePredSuccEdges(curr_BB, next_BB);
697697
}
698698
} // if (i->opcode()
699699
else if (i->opcode() == G4_if || i->opcode() == G4_while ||
@@ -743,7 +743,7 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
743743
//
744744
// pred means conditional branch
745745
//
746-
if (i->getPredicate() != NULL) // need to add fall through edge
746+
if (i->getPredicate() != NULL)
747747
{
748748
// add fall through edge
749749
addPredSuccEdges(curr_BB, next_BB);
@@ -753,7 +753,7 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
753753
{
754754
// does nothing for unconditional return;
755755
// 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)
757757
{
758758
// add fall through edge
759759
addPredSuccEdges(curr_BB, next_BB);
@@ -765,7 +765,7 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
765765
}
766766
else if (i->opcode() == G4_pseudo_fret || i->opcode() == G4_pseudo_fc_ret)
767767
{
768-
if (i->getPredicate() != NULL)
768+
if (i->getPredicate())
769769
{
770770
// need to add fall through edge
771771
addPredSuccEdges(curr_BB, next_BB);
@@ -777,10 +777,11 @@ void FlowGraph::constructFlowGraph(INST_LIST& instlist)
777777
hasSIMDCF = true;
778778
addPredSuccEdges(curr_BB, getLabelBB(labelMap, i->asCFInst()->getUipLabelStr()));
779779

780-
if (i->getPredicate() != NULL)
780+
if (i->getPredicate())
781781
{
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);
784785
}
785786
}
786787
else
@@ -1938,25 +1939,23 @@ void FlowGraph::removeRedundantLabels()
19381939

19391940
// check if the label is a function label
19401941
unsigned int numNonCallerPreds = 0;
1941-
BB_LIST_ITER lt = bb->Preds.begin();
1942-
BB_LIST_ITER ltEnd = bb->Preds.end();
19431942
bool isFuncLabel = true;
19441943
G4_BB* pred_bb = NULL;
1945-
for (; lt != ltEnd; ++lt)
1944+
for (auto pred : bb->Preds)
19461945
{
1947-
if (!((*lt)->isEndWithCall()))
1946+
if (!pred->isEndWithCall())
19481947
{
19491948
if (numNonCallerPreds > 0)
19501949
{
19511950
isFuncLabel = false;
19521951
break;
19531952
}
19541953
numNonCallerPreds++;
1955-
pred_bb = (*lt);
1954+
pred_bb = pred;
19561955
}
19571956
else
19581957
{
1959-
G4_INST *i = (*lt)->back();
1958+
G4_INST *i = pred->back();
19601959
if (i->getSrc(0)->isLabel())
19611960
{
19621961
if (i->getSrc(0) != removedBlockInst->getLabel())
@@ -1967,7 +1966,7 @@ void FlowGraph::removeRedundantLabels()
19671966
break;
19681967
}
19691968
numNonCallerPreds++;
1970-
pred_bb = (*lt);
1969+
pred_bb = pred;
19711970
}
19721971
}
19731972
}
@@ -1989,18 +1988,11 @@ void FlowGraph::removeRedundantLabels()
19891988
G4_Label *succ_label = bb->Succs.front()->front()->getLabel();
19901989

19911990
// 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)
19941992
{
1995-
BB_LIST_ITER jt = (*lt)->Succs.begin();
1993+
auto jt = std::find(pred->Succs.begin(), pred->Succs.end(), bb);
19961994

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();
20041996
// replace label in instructions
20051997
if (i->isFlowControl())
20061998
{
@@ -2009,8 +2001,8 @@ void FlowGraph::removeRedundantLabels()
20092001
// due to the switchjmp we may have multiple jmpi
20102002
// at the end of a block.
20112003
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)
20142006
{
20152007
i = *iter;
20162008
if (i->opcode() == G4_jmpi)
@@ -2096,8 +2088,8 @@ void FlowGraph::removeRedundantLabels()
20962088
}
20972089
}
20982090

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);
21012093

21022094
// [Bug1915]: In rare case the precessor may have more than one Succ edge pointing
21032095
// to the same BB, due to empty block being eliminated. For example, with
@@ -2114,16 +2106,16 @@ void FlowGraph::removeRedundantLabels()
21142106
// elsewhere there may be assumptions that if a BB ends with a jump it must have
21152107
// two successors
21162108
{
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();
21192111
while (succs != end)
21202112
{
21212113
BB_LIST_ITER iter = succs;
21222114
++succs;
21232115
if ((*iter) == bb)
21242116
{
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);
21272119
}
21282120
}
21292121
}

0 commit comments

Comments
 (0)