Optimizer - Updated logging

This commit is contained in:
Emmanuel BENOîT 2017-12-14 18:51:14 +01:00
parent 312392d405
commit 8d95f4d1c7

View file

@ -141,10 +141,6 @@ uint32_t T_OptData::indexOf(
/*= T_OptData - CONTROL FLOW GRAPH CONSTRUCTION ==============================*/ /*= T_OptData - CONTROL FLOW GRAPH CONSTRUCTION ==============================*/
namespace { namespace {
#warning Remove this later
#define LL1 2
#define LL2 2
// CFG type shortcuts // CFG type shortcuts
using T_CFN_ = T_OptData::T_CtrlFlowNode; using T_CFN_ = T_OptData::T_CtrlFlowNode;
using P_CFN_ = T_OptData::P_CtrlFlowNode; using P_CFN_ = T_OptData::P_CtrlFlowNode;
@ -191,7 +187,7 @@ inline void BCFGFuncEnter_(
sb << "Starting function '" << fn << "' at " sb << "Starting function '" << fn << "' at "
<< ctrlFlowGraph.size( ); << ctrlFlowGraph.size( );
return sb; return sb;
} , LL1 ); } , 5 );
cfgFunctions.add( fn , T_OptData::T_BasicBlock{ cfgFunctions.add( fn , T_OptData::T_BasicBlock{
ctrlFlowGraph.size( ) } ); ctrlFlowGraph.size( ) } );
cNode = M_ADDNEW_( ); cNode = M_ADDNEW_( );
@ -215,7 +211,7 @@ inline void BCFGFuncExit_(
: 0 ) : 0 )
<< " instructions"; << " instructions";
return sb; return sb;
} , LL1 ); } , 5 );
auto* frec{ cfgFunctions.get( fn ) }; auto* frec{ cfgFunctions.get( fn ) };
assert( frec ); assert( frec );
frec->count = ctrlFlowGraph.size( ) - frec->first; frec->count = ctrlFlowGraph.size( ) - frec->first;
@ -251,7 +247,7 @@ inline void BCFGCondEnter_(
: 0 ) : 0 )
<< " instructions"; << " instructions";
return sb; return sb;
} , LL2 ); } , 6 );
} }
inline void BCFGCondExit_( inline void BCFGCondExit_(
@ -286,7 +282,7 @@ inline void BCFGCondExit_(
sb << "Exiting conditional instruction, stack size " sb << "Exiting conditional instruction, stack size "
<< stack.size( ); << stack.size( );
return sb; return sb;
} , LL2 ); } , 6 );
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -354,7 +350,7 @@ inline bool BCFGVisitor_(
: 0 ) : 0 )
<< " instructions"; << " instructions";
return sb; return sb;
} , LL2 ); } , 6 );
auto& cs{ data.callSites.addNew( ) }; auto& cs{ data.callSites.addNew( ) };
cs.name = ci.id( ); cs.name = ci.id( );
@ -375,7 +371,7 @@ inline bool BCFGVisitor_(
: 0 ) : 0 )
<< " instructions)"; << " instructions)";
return sb; return sb;
} , LL2 ); } , 6 );
cNode.clear( ); cNode.clear( );
} else { } else {
stack.last( ).hasDefault = stack.last( ).hasDefault stack.last( ).hasDefault = stack.last( ).hasDefault
@ -491,7 +487,7 @@ void T_OptData::buildControlFlowGraph(
{ {
// Keep the old array, we'll reuse its contents // Keep the old array, we'll reuse its contents
T_Array< P_CtrlFlowNode > old{ std::move( ctrlFlowGraph ) }; T_Array< P_CtrlFlowNode > old{ std::move( ctrlFlowGraph ) };
M_LOGSTR_( "Building control flow graph" , LL1 ); M_LOGSTR_( "Building control flow graph" , 4 );
// Create special nodes // Create special nodes
M_ADDNEW_( ); M_ADDNEW_( );
@ -514,7 +510,7 @@ void T_OptData::buildControlFlowGraph(
BCFGHandleCalls_( *this ); BCFGHandleCalls_( *this );
logger( [this](){ logger( [this](){
return BCFGDumpAll_( *this ); return BCFGDumpAll_( *this );
} , LL2 ); } , 6 );
} }
#undef M_ADDNEW_ #undef M_ADDNEW_
@ -525,12 +521,6 @@ void T_OptData::buildControlFlowGraph(
/*= T_OptData - USE/DEFINE CHAINS ============================================*/ /*= T_OptData - USE/DEFINE CHAINS ============================================*/
namespace { namespace {
#warning Remove this later
#undef LL1
#undef LL2
#define LL1 1
#define LL2 1
void BUDCAddRecord_( void BUDCAddRecord_(
A_Node& n , A_Node& n ,
T_String const& id , T_String const& id ,
@ -599,7 +589,7 @@ void BUDCAddRecord_(
} }
sb << "), instr #" << *instrId; sb << "), instr #" << *instrId;
return sb; return sb;
} , LL2 ); } , 6 );
} }
void BUDCVisitor_( void BUDCVisitor_(
@ -758,7 +748,7 @@ void BUDCLink_(
sb << " USE " << use; sb << " USE " << use;
return sb; return sb;
} , LL2 ); } , 6 );
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -837,7 +827,7 @@ void BUDCWalkGraph_(
} }
sb << ')'; sb << ')';
return sb; return sb;
} , LL1 ); } , 5 );
auto const* const fn{ fnIndex auto const* const fn{ fnIndex
? &data.cfgFunctions[ *fnIndex ] ? &data.cfgFunctions[ *fnIndex ]
@ -845,13 +835,11 @@ void BUDCWalkGraph_(
auto const nFirst{ fn ? fn->first : 0u }; auto const nFirst{ fn ? fn->first : 0u };
auto const nEnd{ fn ? ( fn->first + fn->count ) auto const nEnd{ fn ? ( fn->first + fn->count )
: data.ctrlFlowGraph.size( ) }; : data.ctrlFlowGraph.size( ) };
#if 0
data.logger( [=](){ data.logger( [=](){
T_StringBuilder sb{ "Nodes " }; T_StringBuilder sb{ "Nodes " };
sb << nFirst << " ... " << ( nEnd - 1 );; sb << nFirst << " ... " << ( nEnd - 1 );;
return sb; return sb;
} , LL2 ); } , 8 );
#endif
changed.add( nFirst ); changed.add( nFirst );
for ( auto i = nEnd ; i > nFirst + 1 ; i -- ) { for ( auto i = nEnd ; i > nFirst + 1 ; i -- ) {
changed.add( i - 1 ); changed.add( i - 1 );
@ -859,13 +847,11 @@ void BUDCWalkGraph_(
while ( changed.size( ) ) { while ( changed.size( ) ) {
const auto node{ changed[ 0 ] }; const auto node{ changed[ 0 ] };
#if 0
data.logger( [=](){ data.logger( [=](){
T_StringBuilder sb{ "Checking node " }; T_StringBuilder sb{ "Checking node " };
sb << node; sb << node;
return sb; return sb;
} , LL2 ); } , 8 );
#endif
assert( node >= nFirst && node < nEnd ); assert( node >= nFirst && node < nEnd );
auto const& cn{ *data.ctrlFlowGraph[ node ] }; auto const& cn{ *data.ctrlFlowGraph[ node ] };
changed.remove( node ); changed.remove( node );
@ -919,7 +905,6 @@ void BUDCWalkGraph_(
if ( sOut == sInput ) { if ( sOut == sInput ) {
continue; continue;
} }
#if 0
data.logger( [&](){ data.logger( [&](){
T_StringBuilder sb; T_StringBuilder sb;
sb << "Node " << node << ", setting output to {"; sb << "Node " << node << ", setting output to {";
@ -931,8 +916,7 @@ void BUDCWalkGraph_(
} }
sb << " }"; sb << " }";
return sb; return sb;
} , LL2 ); } , 7 );
#endif
sOut = sInput; sOut = sInput;
// Add the node's successors into the changed set // Add the node's successors into the changed set
@ -1028,7 +1012,7 @@ void BUDCWalkGraph_(
void T_OptData::buildUseDefineChains( void T_OptData::buildUseDefineChains(
T_OpsParserOutput& program ) noexcept T_OpsParserOutput& program ) noexcept
{ {
M_LOGSTR_( "Building use/define chains" , LL1 ); M_LOGSTR_( "Building use/define chains" , 4 );
varUDChains.clear( ); varUDChains.clear( );
// Find all definitions and uses, add them to the table // Find all definitions and uses, add them to the table
@ -1468,11 +1452,11 @@ void CPReplaceWithConstant_(
p.replace( eid , replacement ); p.replace( eid , replacement );
oData.logger( [&]() { oData.logger( [&]() {
T_StringBuilder sb; T_StringBuilder sb;
sb << "Propagated constant from " << var.name sb << "...... Propagated constant from " << var.name
<< " at " << instruction.location( ) << " at " << instruction.location( )
<< " (value " << value << ")"; << " (value " << value << ")";
return sb; return sb;
} , LL2 ); } , 3 );
return true; return true;
} ); } );
} }