mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
logic for driving AST optimization when requested
This commit is contained in:
parent
77f04935a8
commit
faf1b65ec4
1 changed files with 32 additions and 1 deletions
|
@ -78,10 +78,41 @@ void optimize_func(ScriptFunc* f, std::shared_ptr<ProfileFunc> pf,
|
||||||
f->ReplaceBody(body, new_body);
|
f->ReplaceBody(body, new_body);
|
||||||
body = new_body;
|
body = new_body;
|
||||||
|
|
||||||
// Profile the new body.
|
if ( analysis_options.optimize_AST )
|
||||||
|
{
|
||||||
pf = std::make_shared<ProfileFunc>(false);
|
pf = std::make_shared<ProfileFunc>(false);
|
||||||
body->Traverse(pf.get());
|
body->Traverse(pf.get());
|
||||||
|
|
||||||
|
RD_Decorate reduced_rds(pf);
|
||||||
|
reduced_rds.TraverseFunction(f, scope, body);
|
||||||
|
|
||||||
|
if ( reporter->Errors() > 0 )
|
||||||
|
{
|
||||||
|
pop_scope();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc->SetDefSetsMgr(reduced_rds.GetDefSetsMgr());
|
||||||
|
|
||||||
|
new_body = rc->Reduce(body);
|
||||||
|
|
||||||
|
if ( reporter->Errors() > 0 )
|
||||||
|
{
|
||||||
|
pop_scope();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( analysis_options.only_func || analysis_options.dump_xform )
|
||||||
|
printf("Optimized: %s\n", obj_desc(new_body.get()).c_str());
|
||||||
|
|
||||||
|
f->ReplaceBody(body, new_body);
|
||||||
|
body = new_body;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Profile the new body.
|
||||||
|
pf = std::make_shared<ProfileFunc>();
|
||||||
|
body->Traverse(pf.get());
|
||||||
|
|
||||||
// Compute its reaching definitions.
|
// Compute its reaching definitions.
|
||||||
RD_Decorate reduced_rds(pf);
|
RD_Decorate reduced_rds(pf);
|
||||||
reduced_rds.TraverseFunction(f, scope, body);
|
reduced_rds.TraverseFunction(f, scope, body);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue