Optimizer - UD chains: all uses and defs are added to the list
This commit is contained in:
parent
ffdd3d0a63
commit
3d500d4976
1 changed files with 55 additions and 24 deletions
79
c-opopt.cc
79
c-opopt.cc
|
@ -364,11 +364,13 @@ namespace {
|
|||
#define LL1 1
|
||||
#define LL2 1
|
||||
|
||||
void BUDCAddUseRecord_(
|
||||
void BUDCAddRecord_(
|
||||
A_Node& n ,
|
||||
T_String const& id ,
|
||||
const bool use ,
|
||||
T_OptData& od ,
|
||||
T_RootNode& root ) noexcept
|
||||
T_RootNode& root ,
|
||||
T_OptData::T_VarId const* extVarId = nullptr ) noexcept
|
||||
{
|
||||
|
||||
// Find instruction and function index
|
||||
|
@ -388,7 +390,7 @@ void BUDCAddUseRecord_(
|
|||
assert( func && instrId );
|
||||
|
||||
// Generate the identifier
|
||||
const T_OptData::T_VarId varId{ [&]() {
|
||||
const T_OptData::T_VarId varId{ extVarId ? *extVarId : [&]() {
|
||||
auto const& n{ id };
|
||||
if ( func->hasLocal( id ) ) {
|
||||
return T_OptData::T_VarId{ n , func->name( ) ,
|
||||
|
@ -408,14 +410,15 @@ void BUDCAddUseRecord_(
|
|||
} () };
|
||||
assert( varRec );
|
||||
|
||||
// Add use record
|
||||
auto& useRec{ varRec->uses.addNew( ) };
|
||||
useRec.node = *instrId;
|
||||
useRec.fnIndex = root.functionIndex( func->name( ) );
|
||||
// Add use/define record
|
||||
auto& udRec{ use ? varRec->uses.addNew( ) : varRec->defines.addNew( ) };
|
||||
udRec.node = *instrId;
|
||||
udRec.fnIndex = root.functionIndex( func->name( ) );
|
||||
|
||||
od.logger( [&](){
|
||||
T_StringBuilder sb;
|
||||
sb << "use " << varId.name << " at " << n.location( ) << " (";
|
||||
sb << ( use ? "use " : "def " ) << varId.name << " at "
|
||||
<< n.location( ) << " (";
|
||||
if ( varId.type == T_OptData::E_UDVarType::GLOBAL ) {
|
||||
sb << "global";
|
||||
} else {
|
||||
|
@ -426,7 +429,7 @@ void BUDCAddUseRecord_(
|
|||
}
|
||||
sb << " of " << varId.owner;
|
||||
}
|
||||
sb << ')';
|
||||
sb << "), instr #" << *instrId;
|
||||
return sb;
|
||||
} , LL2 );
|
||||
}
|
||||
|
@ -468,45 +471,73 @@ void T_OptData::buildUseDefineChains(
|
|||
default: break;
|
||||
|
||||
case A_Node::EXPR_ID:
|
||||
BUDCAddUseRecord_( n ,
|
||||
BUDCAddRecord_( n ,
|
||||
dynamic_cast< T_IdentifierExprNode& >( n ).id( ) ,
|
||||
*this , program.root );
|
||||
true , *this , program.root );
|
||||
break;
|
||||
|
||||
case A_Node::OP_UNIFORMS:
|
||||
BUDCAddUseRecord_( n ,
|
||||
BUDCAddRecord_( n ,
|
||||
dynamic_cast< T_UniformsInstrNode& >( n ).progId( ) ,
|
||||
*this , program.root );
|
||||
true , *this , program.root );
|
||||
break;
|
||||
|
||||
case A_Node::OP_USE_TEXTURE:
|
||||
BUDCAddUseRecord_( n ,
|
||||
BUDCAddRecord_( n ,
|
||||
dynamic_cast< T_UseTextureInstrNode& >( n ).samplerId( ) ,
|
||||
*this , program.root );
|
||||
true , *this , program.root );
|
||||
// fallthrough
|
||||
case A_Node::OP_USE_PROGRAM:
|
||||
case A_Node::OP_USE_PIPELINE:
|
||||
case A_Node::OP_USE_FRAMEBUFFER:
|
||||
BUDCAddUseRecord_( n ,
|
||||
BUDCAddRecord_( n ,
|
||||
dynamic_cast< T_UseInstrNode& >( n ).id( ) ,
|
||||
*this , program.root );
|
||||
true , *this , program.root );
|
||||
break;
|
||||
|
||||
case A_Node::OP_PIPELINE: {
|
||||
auto& pln{ dynamic_cast< T_PipelineInstrNode& >( n ) };
|
||||
// XXX decl
|
||||
BUDCAddRecord_( n , pln.id( ) , false , *this , program.root );
|
||||
const auto np{ pln.size( ) };
|
||||
for ( auto i = 0u ; i < np ; i ++ ) {
|
||||
BUDCAddUseRecord_( n , pln.program( i ) ,
|
||||
*this , program.root );
|
||||
BUDCAddRecord_( n , pln.program( i ) ,
|
||||
true , *this , program.root );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case A_Node::TN_FBATT: {
|
||||
auto& fbn{ dynamic_cast< T_FramebufferInstrNode::T_Attachment& >( n ) };
|
||||
BUDCAddUseRecord_( n , fbn.id( ) ,
|
||||
*this , program.root );
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue