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