Merge remote-tracking branch 'origin/topic/vern/CPP-streamlining'

* origin/topic/vern/CPP-streamlining:
  BTest baseline updates for compile-to-C++
  mark ZAM regression BTests as not suitable for compile-to-C++
  fix for -O gen-C++ maintenance helper to skip BTest intermediary files
  introduced simplified initialization for non-standalone -O gen-C++ code tied -O gen-standalone-C++ to use of --optimize-files
  streamline generated -O C++ code by relying on per-function profiles rather than aggregate profile
  when reporting available/unavailble C++ script bodies, flag those that are skipped
  modified AST profiling to mark (and fully skip) non-optimizable functions
  modified merge_types() to skip work if given identical types, which also preserves type names (useful for -O gen-C++)
This commit is contained in:
Tim Wojtulewicz 2024-12-09 12:15:46 -07:00
commit 6e75417032
35 changed files with 334 additions and 143 deletions

View file

@ -109,13 +109,25 @@ bool should_analyze(const ScriptFuncPtr& f, const StmtPtr& body) {
if ( ofiles.empty() && ofuncs.empty() )
return true;
if ( obj_matches_opt_files(body.get()) )
return true;
const auto& fun = f->GetName();
for ( auto& o : ofuncs )
if ( std::regex_match(fun, o) )
return true;
auto fin = util::detail::normalize_path(body->GetLocationInfo()->filename);
return false;
}
bool obj_matches_opt_files(const Obj* obj) {
auto& ofiles = analysis_options.only_files;
if ( ofiles.empty() )
return false;
auto fin = util::detail::normalize_path(obj->GetLocationInfo()->filename);
for ( auto& o : ofiles )
if ( std::regex_match(fin, o) )
@ -287,8 +299,12 @@ static void init_options() {
check_env_opt("ZEEK_USE_CPP", analysis_options.use_CPP);
check_env_opt("ZEEK_ALLOW_COND", analysis_options.allow_cond);
if ( analysis_options.gen_standalone_CPP )
if ( analysis_options.gen_standalone_CPP ) {
if ( analysis_options.only_files.empty() )
reporter->FatalError("-O gen-standalone-C++ requires use of --optimize-files");
analysis_options.gen_CPP = true;
}
if ( analysis_options.gen_CPP )
generating_CPP = true;
@ -368,6 +384,12 @@ static void report_CPP() {
for ( auto& f : funcs ) {
const auto& name = f.Func()->GetName();
if ( f.ShouldSkip() ) {
printf("script function %s: SKIP\n", name.c_str());
continue;
}
auto hash = f.Profile()->HashVal();
bool have = compiled_scripts.count(hash) > 0;
@ -399,6 +421,9 @@ static void use_CPP() {
auto pfs = std::make_unique<ProfileFuncs>(funcs, is_CPP_compilable, true, false);
for ( auto& f : funcs ) {
if ( f.ShouldSkip() )
continue;
auto hash = f.Profile()->HashVal();
auto s = compiled_scripts.find(hash);