enable setting "-O optimize-AST" option

This commit is contained in:
Vern Paxson 2021-02-27 10:59:27 -08:00
parent 56ab0ddcf1
commit d38cc04e83
3 changed files with 15 additions and 0 deletions

View file

@ -151,6 +151,7 @@ static void set_analysis_option(const char* opt, Options& opts)
{ {
opts.analysis_options.inliner = true; opts.analysis_options.inliner = true;
opts.analysis_options.activate = true; opts.analysis_options.activate = true;
opts.analysis_options.optimize_AST = true;
return; return;
} }
@ -161,6 +162,7 @@ static void set_analysis_option(const char* opt, Options& opts)
fprintf(stderr, " dump-xform dump transformed scripts to stdout; implies xform\n"); fprintf(stderr, " dump-xform dump transformed scripts to stdout; implies xform\n");
fprintf(stderr, " help print this list\n"); fprintf(stderr, " help print this list\n");
fprintf(stderr, " inline inline function calls\n"); fprintf(stderr, " inline inline function calls\n");
fprintf(stderr, " optimize-AST optimize the (transformed) AST; implies xform\n");
fprintf(stderr, " recursive report on recursive functions and exit\n"); fprintf(stderr, " recursive report on recursive functions and exit\n");
fprintf(stderr, " xform tranform scripts to \"reduced\" form\n"); fprintf(stderr, " xform tranform scripts to \"reduced\" form\n");
exit(0); exit(0);
@ -178,6 +180,8 @@ static void set_analysis_option(const char* opt, Options& opts)
a_o.inliner = a_o.report_recursive = true; a_o.inliner = a_o.report_recursive = true;
else if ( util::streq(opt, "xform") ) else if ( util::streq(opt, "xform") )
a_o.activate = true; a_o.activate = true;
else if ( util::streq(opt, "optimize-AST") )
a_o.activate = a_o.optimize_AST = true;
else else
{ {

View file

@ -133,6 +133,7 @@ void analyze_scripts()
check_env_opt("ZEEK_DUMP_XFORM", analysis_options.dump_xform); check_env_opt("ZEEK_DUMP_XFORM", analysis_options.dump_xform);
check_env_opt("ZEEK_DUMP_UDS", analysis_options.dump_uds); check_env_opt("ZEEK_DUMP_UDS", analysis_options.dump_uds);
check_env_opt("ZEEK_INLINE", analysis_options.inliner); check_env_opt("ZEEK_INLINE", analysis_options.inliner);
check_env_opt("ZEEK_OPT", analysis_options.optimize_AST);
check_env_opt("ZEEK_XFORM", analysis_options.activate); check_env_opt("ZEEK_XFORM", analysis_options.activate);
auto usage = getenv("ZEEK_USAGE_ISSUES"); auto usage = getenv("ZEEK_USAGE_ISSUES");
@ -148,6 +149,7 @@ void analyze_scripts()
} }
if ( analysis_options.only_func || if ( analysis_options.only_func ||
analysis_options.optimize_AST ||
analysis_options.usage_issues > 0 ) analysis_options.usage_issues > 0 )
analysis_options.activate = true; analysis_options.activate = true;
@ -157,6 +159,12 @@ void analyze_scripts()
if ( ! analysis_options.activate && ! analysis_options.inliner ) if ( ! analysis_options.activate && ! analysis_options.inliner )
return; return;
if ( analysis_options.usage_issues > 0 && analysis_options.optimize_AST )
{
fprintf(stderr, "warning: \"-O optimize-AST\" option is incompatible with -u option, deactivating optimization\n");
analysis_options.optimize_AST = false;
}
// Now that everything's parsed and BiF's have been initialized, // Now that everything's parsed and BiF's have been initialized,
// profile the functions. // profile the functions.
std::unordered_map<const ScriptFunc*, std::shared_ptr<ProfileFunc>> std::unordered_map<const ScriptFunc*, std::shared_ptr<ProfileFunc>>

View file

@ -22,6 +22,9 @@ struct AnalyOpt {
// Whether to analyze scripts. // Whether to analyze scripts.
bool activate = false; bool activate = false;
// Whether to optimize the AST.
bool optimize_AST = false;
// If true, dump out transformed code: the results of reducing // If true, dump out transformed code: the results of reducing
// interpreted scripts, and, if optimize is set, of then optimizing // interpreted scripts, and, if optimize is set, of then optimizing
// them. Always done if only_func is set. // them. Always done if only_func is set.