Optimizer - Remove unused globals
This commit is contained in:
parent
630dd94ba6
commit
01d9586264
2 changed files with 46 additions and 3 deletions
1
TODO
1
TODO
|
@ -18,6 +18,7 @@ Scripting:
|
||||||
* Unused arguments
|
* Unused arguments
|
||||||
* Dead store: call arguments
|
* Dead store: call arguments
|
||||||
* Unused functions
|
* Unused functions
|
||||||
|
* Unused inputs
|
||||||
* Common subexpressions
|
* Common subexpressions
|
||||||
* Strength reduction
|
* Strength reduction
|
||||||
* Loop-invariant code motion
|
* Loop-invariant code motion
|
||||||
|
|
48
c-opopt.cc
48
c-opopt.cc
|
@ -1710,7 +1710,6 @@ bool RDCUnusedLocals_(
|
||||||
) noexcept
|
) noexcept
|
||||||
{
|
{
|
||||||
M_LOGSTR_( "...... Removing unused locals" , 3 );
|
M_LOGSTR_( "...... Removing unused locals" , 3 );
|
||||||
oData.buildUseDefineChains( program );
|
|
||||||
|
|
||||||
const auto nf{ program.root.nFunctions( ) };
|
const auto nf{ program.root.nFunctions( ) };
|
||||||
bool changed{ false };
|
bool changed{ false };
|
||||||
|
@ -1734,7 +1733,7 @@ bool RDCUnusedLocals_(
|
||||||
}
|
}
|
||||||
oData.logger( [&](){
|
oData.logger( [&](){
|
||||||
T_StringBuilder sb;
|
T_StringBuilder sb;
|
||||||
sb << "Removing used local variable "
|
sb << "Removing unused local variable "
|
||||||
<< ln << " at "
|
<< ln << " at "
|
||||||
<< func.getLocalLocation( l );
|
<< func.getLocalLocation( l );
|
||||||
return sb;
|
return sb;
|
||||||
|
@ -1747,6 +1746,49 @@ bool RDCUnusedLocals_(
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RDCUnusedGlobals_(
|
||||||
|
T_OpsParserOutput& program ,
|
||||||
|
T_OptData& oData
|
||||||
|
) noexcept
|
||||||
|
{
|
||||||
|
M_LOGSTR_( "...... Removing unused globals" , 3 );
|
||||||
|
|
||||||
|
T_AutoArray< T_String , 16 > remove;
|
||||||
|
for ( auto const& gn : program.types.keys( ) ) {
|
||||||
|
const auto gt{ *program.types.get( gn ) };
|
||||||
|
if ( gt == E_DataType::BUILTIN || gt == E_DataType::INPUT ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const T_OptData::T_VarId vid{ gn };
|
||||||
|
if ( !oData.varUDChains.contains( vid ) ) {
|
||||||
|
remove.add( gn );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto nr{ remove.size( ) };
|
||||||
|
for ( auto i = 0u ; i < nr ; i ++ ) {
|
||||||
|
auto const& gn{ remove[ i ] };
|
||||||
|
oData.logger( [&](){
|
||||||
|
T_StringBuilder sb;
|
||||||
|
sb << "Removing unused global " << gn;
|
||||||
|
return sb;
|
||||||
|
} , 4 );
|
||||||
|
program.types.remove( gn );
|
||||||
|
}
|
||||||
|
return remove.size( );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RDCUnused_(
|
||||||
|
T_OpsParserOutput& program ,
|
||||||
|
T_OptData& oData
|
||||||
|
) noexcept
|
||||||
|
{
|
||||||
|
oData.buildUseDefineChains( program );
|
||||||
|
const bool locals{ RDCUnusedLocals_( program , oData ) };
|
||||||
|
const bool globals{ RDCUnusedGlobals_( program , oData ) };
|
||||||
|
return locals || globals;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace <anon>
|
} // namespace <anon>
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -1770,7 +1812,7 @@ bool opopt::RemoveDeadCode(
|
||||||
|
|
||||||
didStuffThisTime = RDCConditionals_( program , oData )
|
didStuffThisTime = RDCConditionals_( program , oData )
|
||||||
|| RDCDeadStores_( program , oData )
|
|| RDCDeadStores_( program , oData )
|
||||||
|| RDCUnusedLocals_( program , oData );
|
|| RDCUnused_( program , oData );
|
||||||
didStuff = didStuff || didStuffThisTime;
|
didStuff = didStuff || didStuffThisTime;
|
||||||
} while ( didStuffThisTime );
|
} while ( didStuffThisTime );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue