Optimizer - Fixed control flow graph building

This commit is contained in:
Emmanuel BENOîT 2017-12-08 21:57:41 +01:00
parent 61cd7719f1
commit f58226aa79

View file

@ -247,7 +247,7 @@ void T_OptData::buildControlFlowGraph(
auto& cb{ *M_NODE_( cbi ) }; auto& cb{ *M_NODE_( cbi ) };
cb.inbound.add( se.condBlock ); cb.inbound.add( se.condBlock );
M_NODE_( se.condBlock )->outbound.add( cbi ); M_NODE_( se.condBlock )->outbound.add( cbi );
cb.outbound.add( cNode ); cb.outbound.add( *cNode );
M_NODE_( *cNode )->inbound.add( cbi ); M_NODE_( *cNode )->inbound.add( cbi );
} }
if ( !se.hasDefault ) { if ( !se.hasDefault ) {
@ -296,7 +296,7 @@ void T_OptData::buildControlFlowGraph(
auto& cs{ callSites.addNew( ) }; auto& cs{ callSites.addNew( ) };
cs.name = ci.id( ); cs.name = ci.id( );
cs.callBlock = cNode; cs.callBlock = *cNode;
cNode = cs.retBlock = M_ADDNEW_( ); cNode = cs.retBlock = M_ADDNEW_( );
return true; return true;
} }
@ -318,7 +318,7 @@ void T_OptData::buildControlFlowGraph(
stack.last( ).hasDefault = stack.last( ).hasDefault stack.last( ).hasDefault = stack.last( ).hasDefault
|| ( nt == A_Node::TN_DEFAULT ); || ( nt == A_Node::TN_DEFAULT );
cNode = M_ADDNEW_( ); cNode = M_ADDNEW_( );
stack.last( ).caseBlocks.add( cNode ); stack.last( ).caseBlocks.add( *cNode );
} }
} }
@ -353,9 +353,52 @@ void T_OptData::buildControlFlowGraph(
const auto n{ frec->first + frec->count - 1 }; const auto n{ frec->first + frec->count - 1 };
auto& exit{ ctrlFlowGraph[ n ] }; auto& exit{ ctrlFlowGraph[ n ] };
exit->outbound.add( cs.retBlock ); exit->outbound.add( cs.retBlock );
M_NODE_( cs.retBlock )->outbound.add( n ); M_NODE_( cs.retBlock )->inbound.add( n );
} }
} }
// Dump whole graph
logger( [&](){
T_StringBuilder dump;
int i{ 0 };
dump << "Control flow graph dump\n";
for ( auto const& p : ctrlFlowGraph ) {
auto const& e{ *p };
dump << "\nNode " << i++ << "\n\t";
if ( e.instructions ) {
dump << e.instructions->count
<< " instruction(s) at index "
<< e.instructions->first;
} else {
dump << "No instructions";
}
dump << "\n\tInbound:";
{
const auto ni{ e.inbound.size( ) };
if ( ni == 0 ) {
dump << " NONE";
}
for ( auto idx = 0u ; idx < ni ; idx ++ ) {
dump << ' ' << e.inbound[ idx ];
}
}
dump << "\n\tOutbound:";
{
const auto no{ e.outbound.size( ) };
if ( no == 0 ) {
dump << " NONE";
}
for ( auto idx = 0u ; idx < no ; idx ++ ) {
dump << ' ' << e.outbound[ idx ];
}
}
dump << '\n';
}
dump << '\n';
return dump;
} , LL2 );
} }
#undef M_ADDNEW_ #undef M_ADDNEW_
@ -451,11 +494,13 @@ void BUDCVisitor_(
default: break; default: break;
case A_Node::EXPR_ID: case A_Node::EXPR_ID: {
BUDCAddRecord_( n , auto const& id{ dynamic_cast< T_IdentifierExprNode& >( n ).id( ) };
dynamic_cast< T_IdentifierExprNode& >( n ).id( ) , if ( id != "width" && id != "height" && id != "time" ) {
true , od , root ); BUDCAddRecord_( n , id , true , od , root );
}
break; break;
}
case A_Node::OP_UNIFORMS: case A_Node::OP_UNIFORMS:
BUDCAddRecord_( n , BUDCAddRecord_( n ,