diff --git a/src/script_opt/ProfileFunc.cc b/src/script_opt/ProfileFunc.cc index 53f71be393..84f8cb16f7 100644 --- a/src/script_opt/ProfileFunc.cc +++ b/src/script_opt/ProfileFunc.cc @@ -487,10 +487,29 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) { TraversalCode ProfileFunc::PreID(const ID* id) { TrackID(id); + if ( id->IsGlobal() ) { + globals.insert(id); + all_globals.insert(id); + + const auto& t = id->GetType(); + TrackType(t); + + if ( t->Tag() == TYPE_FUNC ) + if ( t->AsFuncType()->Flavor() == FUNC_FLAVOR_EVENT ) + events.insert(id->Name()); + } + // There's no need for any further analysis of this ID. return TC_ABORTSTMT; } +TraversalCode ProfileFunc::PreType(const Type* t) { + TrackType(t); + + // There's no need for any further analysis of this type. + return TC_ABORTSTMT; +} + void ProfileFunc::TrackType(const Type* t) { if ( ! t ) return; @@ -514,6 +533,11 @@ void ProfileFunc::TrackID(const ID* id) { // Already tracked. return; + if ( id->IsGlobal() ) { + globals.insert(id); + all_globals.insert(id); + } + ordered_ids.push_back(id); } diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index 99fd8d76df..73399e6dc1 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -607,17 +607,23 @@ void analyze_scripts(bool no_unused_warnings) { if ( analysis_options.use_CPP ) use_CPP(); + std::shared_ptr pfs; + // Note, in the following it's not clear whether the final argument + // for absolute/relative record fields matters any more ... + if ( generating_CPP ) + pfs = std::make_shared(funcs, is_CPP_compilable, true, false); + else + pfs = std::make_shared(funcs, nullptr, true, true); + if ( generating_CPP ) { if ( analysis_options.gen_ZAM ) reporter->FatalError("-O ZAM and -O gen-C++ conflict"); - generate_CPP(); + generate_CPP(pfs); exit(0); } - // At this point we're done with C++ considerations, so instead - // are compiling to ZAM. - analyze_scripts_for_ZAM(); + analyze_scripts_for_ZAM(pfs); if ( reporter->Errors() > 0 ) reporter->FatalError("Optimized script execution aborted due to errors");