Optimizer - Some refactoring

This commit is contained in:
Emmanuel BENOîT 2017-12-06 07:05:26 +01:00
parent 9151ceb2c9
commit 5ecc95766a

View file

@ -434,6 +434,89 @@ void BUDCAddRecord_(
} , LL2 ); } , LL2 );
} }
void BUDCVisitor_(
T_RootNode& root ,
T_OptData& od ,
A_Node& n )
{
switch ( n.type( ) ) {
default: break;
case A_Node::EXPR_ID:
BUDCAddRecord_( n ,
dynamic_cast< T_IdentifierExprNode& >( n ).id( ) ,
true , od , root );
break;
case A_Node::OP_UNIFORMS:
BUDCAddRecord_( n ,
dynamic_cast< T_UniformsInstrNode& >( n ).progId( ) ,
true , od , root );
break;
case A_Node::OP_USE_TEXTURE:
BUDCAddRecord_( n ,
dynamic_cast< T_UseTextureInstrNode& >( n ).samplerId( ) ,
true , od , root );
// fallthrough
case A_Node::OP_USE_PROGRAM:
case A_Node::OP_USE_PIPELINE:
case A_Node::OP_USE_FRAMEBUFFER:
BUDCAddRecord_( n ,
dynamic_cast< T_UseInstrNode& >( n ).id( ) ,
true , od , root );
break;
case A_Node::OP_PIPELINE: {
auto& pln{ dynamic_cast< T_PipelineInstrNode& >( n ) };
BUDCAddRecord_( n , pln.id( ) , false , od , root );
const auto np{ pln.size( ) };
for ( auto i = 0u ; i < np ; i ++ ) {
BUDCAddRecord_( n , pln.program( i ) ,
true , od , root );
}
break;
}
case A_Node::TN_FBATT:
BUDCAddRecord_( n , dynamic_cast< T_FramebufferInstrNode::T_Attachment& >( n ).id( ) ,
true , od , root );
break;
case A_Node::OP_FRAMEBUFFER:
case A_Node::OP_TEXTURE:
case A_Node::OP_SAMPLER:
case A_Node::OP_PROGRAM:
BUDCAddRecord_( n , dynamic_cast< A_ResourceDefInstrNode& >( n ).id( ) ,
false , od , root );
break;
case A_Node::OP_SET:
BUDCAddRecord_( n , dynamic_cast< T_SetInstrNode& >( n ).id( ) ,
false , od , root );
break;
case A_Node::OP_CALL: {
auto& cn{ dynamic_cast< T_CallInstrNode& >( n ) };
auto& callee{ root.function(
root.functionIndex( cn.id( ) ) ) };
const auto nlocs{ callee.locals( ) };
for ( auto i = 0u ; i < nlocs ; i ++ ) {
auto const& name{ callee.getLocalName( i ) };
if ( !callee.isArgument( name ) ) {
continue;
}
const T_OptData::T_VarId vid{ name , callee.name( ) , true };
BUDCAddRecord_( n , name , false , od ,
root , &vid );
}
break;
}
}
}
} // namespace <anon> } // namespace <anon>
@ -462,87 +545,9 @@ void T_OptData::buildUseDefineChains(
* looking at the call sites. * looking at the call sites.
*/ */
visitor.visit( program.root , [&]( auto& n , const bool exit ) { visitor.visit( program.root , [&]( auto& n , const bool exit ) {
if ( exit ) { if ( !exit ) {
return true; BUDCVisitor_( program.root , *this , n );
} }
switch ( n.type( ) ) {
default: break;
case A_Node::EXPR_ID:
BUDCAddRecord_( n ,
dynamic_cast< T_IdentifierExprNode& >( n ).id( ) ,
true , *this , program.root );
break;
case A_Node::OP_UNIFORMS:
BUDCAddRecord_( n ,
dynamic_cast< T_UniformsInstrNode& >( n ).progId( ) ,
true , *this , program.root );
break;
case A_Node::OP_USE_TEXTURE:
BUDCAddRecord_( n ,
dynamic_cast< T_UseTextureInstrNode& >( n ).samplerId( ) ,
true , *this , program.root );
// fallthrough
case A_Node::OP_USE_PROGRAM:
case A_Node::OP_USE_PIPELINE:
case A_Node::OP_USE_FRAMEBUFFER:
BUDCAddRecord_( n ,
dynamic_cast< T_UseInstrNode& >( n ).id( ) ,
true , *this , program.root );
break;
case A_Node::OP_PIPELINE: {
auto& pln{ dynamic_cast< T_PipelineInstrNode& >( n ) };
BUDCAddRecord_( n , pln.id( ) , false , *this , program.root );
const auto np{ pln.size( ) };
for ( auto i = 0u ; i < np ; i ++ ) {
BUDCAddRecord_( n , pln.program( i ) ,
true , *this , program.root );
}
break;
}
case A_Node::TN_FBATT:
BUDCAddRecord_( n , dynamic_cast< T_FramebufferInstrNode::T_Attachment& >( n ).id( ) ,
true , *this , program.root );
break;
case A_Node::OP_FRAMEBUFFER:
case A_Node::OP_TEXTURE:
case A_Node::OP_SAMPLER:
case A_Node::OP_PROGRAM:
BUDCAddRecord_( n , dynamic_cast< A_ResourceDefInstrNode& >( n ).id( ) ,
false , *this , program.root );
break;
case A_Node::OP_SET:
BUDCAddRecord_( n , dynamic_cast< T_SetInstrNode& >( n ).id( ) ,
false , *this , program.root );
break;
case A_Node::OP_CALL: {
auto& cn{ dynamic_cast< T_CallInstrNode& >( n ) };
auto& callee{ program.root.function(
program.root.functionIndex( cn.id( ) ) ) };
const auto nlocs{ callee.locals( ) };
for ( auto i = 0u ; i < nlocs ; i ++ ) {
auto const& name{ callee.getLocalName( i ) };
if ( !callee.isArgument( name ) ) {
continue;
}
const T_VarId vid{ name , callee.name( ) , true };
BUDCAddRecord_( n , name , false , *this ,
program.root , &vid );
}
break;
}
}
return true; return true;
} ); } );
} }