diff --git a/src/script_opt/CPP/Attrs.cc b/src/script_opt/CPP/Attrs.cc index dad23eaa6a..0aaf955ef2 100644 --- a/src/script_opt/CPP/Attrs.cc +++ b/src/script_opt/CPP/Attrs.cc @@ -16,7 +16,7 @@ shared_ptr CPPCompile::RegisterAttributes(const AttributesPtr& att if ( pa != processed_attrs.end() ) return pa->second; - attributes.AddKey(attrs, pfs.HashAttrs(attrs)); + attributes.AddKey(attrs, pfs->HashAttrs(attrs)); // The cast is just so we can make an IntrusivePtr. auto a_rep = const_cast(attributes.GetRep(attrs)); diff --git a/src/script_opt/CPP/Compile.h b/src/script_opt/CPP/Compile.h index 2a55ea0fe5..5b05cc07e9 100644 --- a/src/script_opt/CPP/Compile.h +++ b/src/script_opt/CPP/Compile.h @@ -124,8 +124,8 @@ namespace zeek::detail { class CPPCompile { public: - CPPCompile(std::vector& _funcs, ProfileFuncs& pfs, const std::string& gen_name, bool _standalone, - bool report_uncompilable); + CPPCompile(std::vector& _funcs, std::shared_ptr pfs, const std::string& gen_name, + bool _standalone, bool report_uncompilable); ~CPPCompile(); // Constructing a CPPCompile object does all of the compilation. @@ -191,7 +191,7 @@ public: // However, we can't generate that code when first encountering // the attribute, because doing so will need to refer to the names // of types, and initially those are unavailable (because the type's - // representatives, per pfs.RepTypes(), might not have yet been + // representatives, per pfs->RepTypes(), might not have yet been // tracked). So instead we track the associated CallExprInitInfo // objects, and after all types have been tracked, then spin // through them to generate the code. @@ -314,7 +314,7 @@ private: std::vector& funcs; // The global profile of all of the functions. - ProfileFuncs& pfs; + std::shared_ptr pfs; // Script functions that we are able to compile. We compute // these ahead of time so that when compiling script function A @@ -894,7 +894,7 @@ private: // Returns the "representative" for a given type, used to ensure // that we re-use the C++ variable corresponding to a type and // don't instantiate redundant instances. - const Type* TypeRep(const Type* t) { return pfs.TypeRep(t); } + const Type* TypeRep(const Type* t) { return pfs->TypeRep(t); } const Type* TypeRep(const TypePtr& t) { return TypeRep(t.get()); } // Low-level C++ representations for types, of various flavors. diff --git a/src/script_opt/CPP/Driver.cc b/src/script_opt/CPP/Driver.cc index 3dee4fc528..3dc7e991fc 100644 --- a/src/script_opt/CPP/Driver.cc +++ b/src/script_opt/CPP/Driver.cc @@ -13,9 +13,9 @@ namespace zeek::detail { using namespace std; -CPPCompile::CPPCompile(vector& _funcs, ProfileFuncs& _pfs, const string& gen_name, bool _standalone, - bool report_uncompilable) - : funcs(_funcs), pfs(_pfs), standalone(_standalone) { +CPPCompile::CPPCompile(vector& _funcs, std::shared_ptr _pfs, const string& gen_name, + bool _standalone, bool report_uncompilable) + : funcs(_funcs), pfs(std::move(_pfs)), standalone(_standalone) { auto target_name = gen_name.c_str(); write_file = fopen(target_name, "w"); @@ -99,21 +99,21 @@ void CPPCompile::Compile(bool report_uncompilable) { GenProlog(); // Track all of the types we'll be using. - for ( const auto& t : pfs.RepTypes() ) { + for ( const auto& t : pfs->RepTypes() ) { TypePtr tp{NewRef{}, (Type*)(t)}; - types.AddKey(tp, pfs.HashType(t)); + types.AddKey(tp, pfs->HashType(t)); } NL(); - for ( auto& g : pfs.AllGlobals() ) + for ( auto& g : pfs->AllGlobals() ) CreateGlobal(g); - for ( const auto& e : pfs.Events() ) + for ( const auto& e : pfs->Events() ) if ( AddGlobal(e, "gl") ) Emit("EventHandlerPtr %s_ev;", globals[string(e)]); - for ( const auto& t : pfs.RepTypes() ) { + for ( const auto& t : pfs->RepTypes() ) { ASSERT(types.HasKey(t)); TypePtr tp{NewRef{}, (Type*)(t)}; RegisterType(tp); @@ -131,14 +131,14 @@ void CPPCompile::Compile(bool report_uncompilable) { // be identical. In that case, we don't want to generate the lambda // twice, but we do want to map the second one to the same body name. unordered_map lambda_ASTs; - for ( const auto& l : pfs.Lambdas() ) { + for ( const auto& l : pfs->Lambdas() ) { const auto& n = l->Name(); const auto body = l->Ingredients()->Body().get(); if ( lambda_ASTs.count(n) > 0 ) // Reuse previous body. body_names[body] = body_names[lambda_ASTs[n]]; else { - DeclareLambda(l, pfs.ExprProf(l).get()); + DeclareLambda(l, pfs->ExprProf(l).get()); lambda_ASTs[n] = body; } } @@ -151,12 +151,12 @@ void CPPCompile::Compile(bool report_uncompilable) { CompileFunc(func); lambda_ASTs.clear(); - for ( const auto& l : pfs.Lambdas() ) { + for ( const auto& l : pfs->Lambdas() ) { const auto& n = l->Name(); if ( lambda_ASTs.count(n) > 0 ) continue; - CompileLambda(l, pfs.ExprProf(l).get()); + CompileLambda(l, pfs->ExprProf(l).get()); lambda_ASTs[n] = l->Ingredients()->Body().get(); } diff --git a/src/script_opt/CPP/Exprs.cc b/src/script_opt/CPP/Exprs.cc index f798b4f91c..07d651b43f 100644 --- a/src/script_opt/CPP/Exprs.cc +++ b/src/script_opt/CPP/Exprs.cc @@ -151,7 +151,7 @@ string CPPCompile::GenNameExpr(const NameExpr* ne, GenType gt) { if ( t->Tag() == TYPE_FUNC && ! is_global_var ) { auto func = n->Name(); - if ( globals.count(func) > 0 && pfs.BiFGlobals().count(n) == 0 ) + if ( globals.count(func) > 0 && pfs->BiFGlobals().count(n) == 0 ) return GenericValPtrToGT(IDNameStr(n), t, gt); } @@ -202,9 +202,9 @@ string CPPCompile::GenIncrExpr(const Expr* e, GenType gt, bool is_incr, bool top // Make sure any newly created types are known to // the profiler. - (void)pfs.HashType(one_e->GetType()); - (void)pfs.HashType(rhs->GetType()); - (void)pfs.HashType(assign->GetType()); + (void)pfs->HashType(one_e->GetType()); + (void)pfs->HashType(rhs->GetType()); + (void)pfs->HashType(assign->GetType()); auto gen = GenExpr(assign, GEN_DONT_CARE, top_level); @@ -269,10 +269,10 @@ string CPPCompile::GenCallExpr(const CallExpr* c, GenType gt, bool top_level) { // // If it is a BiF *that's also a global variable*, then // we need to look up the BiF version of the global. - if ( pfs.BiFGlobals().count(f_id) == 0 ) + if ( pfs->BiFGlobals().count(f_id) == 0 ) gen += +"->AsFunc()"; - else if ( pfs.Globals().count(f_id) > 0 ) + else if ( pfs->Globals().count(f_id) > 0 ) // The BiF version has an extra "_", per // AddBiF(..., true). gen = globals[string(id_name) + "_"]; @@ -511,8 +511,8 @@ string CPPCompile::GenAddToExpr(const Expr* e, GenType gt, bool top_level) { // Make sure any newly created types are known to // the profiler. - (void)pfs.HashType(rhs->GetType()); - (void)pfs.HashType(assign->GetType()); + (void)pfs->HashType(rhs->GetType()); + (void)pfs->HashType(assign->GetType()); return GenExpr(assign, gt, top_level); } @@ -542,8 +542,8 @@ string CPPCompile::GenRemoveFromExpr(const Expr* e, GenType gt, bool top_level) // Make sure any newly created types are known to // the profiler. - (void)pfs.HashType(rhs->GetType()); - (void)pfs.HashType(assign->GetType()); + (void)pfs->HashType(rhs->GetType()); + (void)pfs->HashType(assign->GetType()); return GenExpr(assign, gt, top_level); } diff --git a/src/script_opt/CPP/Inits.cc b/src/script_opt/CPP/Inits.cc index 2917b8d199..4e7a30b145 100644 --- a/src/script_opt/CPP/Inits.cc +++ b/src/script_opt/CPP/Inits.cc @@ -180,7 +180,7 @@ void CPPCompile::InitializeGlobals() { for ( const auto& ginit : IDOptInfo::GetGlobalInitExprs() ) { auto g = ginit.Id(); - if ( pfs.Globals().count(g) == 0 ) + if ( pfs->Globals().count(g) == 0 ) continue; auto ic = ginit.IC(); diff --git a/src/script_opt/CPP/Vars.cc b/src/script_opt/CPP/Vars.cc index f326d2708b..4aa967c3f8 100644 --- a/src/script_opt/CPP/Vars.cc +++ b/src/script_opt/CPP/Vars.cc @@ -9,9 +9,9 @@ using namespace std; void CPPCompile::CreateGlobal(const ID* g) { auto gn = string(g->Name()); - bool is_bif = pfs.BiFGlobals().count(g) > 0; + bool is_bif = pfs->BiFGlobals().count(g) > 0; - if ( pfs.Globals().count(g) == 0 ) { + if ( pfs->Globals().count(g) == 0 ) { // Only used in the context of calls. If it's compilable, // then we'll call it directly. if ( compilable_funcs.count(gn) > 0 ) { @@ -28,7 +28,7 @@ void CPPCompile::CreateGlobal(const ID* g) { if ( AddGlobal(gn, "gl") ) { // We'll be creating this global. Emit("IDPtr %s;", globals[gn]); - if ( pfs.Events().count(gn) > 0 ) + if ( pfs->Events().count(gn) > 0 ) // This is an event that's also used as a variable. Emit("EventHandlerPtr %s_ev;", globals[gn]); diff --git a/src/script_opt/CSE.cc b/src/script_opt/CSE.cc index 56f3a697e1..3433ed1323 100644 --- a/src/script_opt/CSE.cc +++ b/src/script_opt/CSE.cc @@ -4,9 +4,9 @@ namespace zeek::detail { -CSE_ValidityChecker::CSE_ValidityChecker(ProfileFuncs& _pfs, const std::vector& _ids, +CSE_ValidityChecker::CSE_ValidityChecker(std::shared_ptr _pfs, const std::vector& _ids, const Expr* _start_e, const Expr* _end_e) - : pfs(_pfs), ids(_ids) { + : pfs(std::move(_pfs)), ids(_ids) { start_e = _start_e; end_e = _end_e; @@ -225,7 +225,7 @@ bool CSE_ValidityChecker::CheckCall(const CallExpr* c) { TypeSet aggrs; bool is_unknown = false; - auto resolved = pfs.GetCallSideEffects(func->AsNameExpr(), non_local_ids, aggrs, is_unknown); + auto resolved = pfs->GetCallSideEffects(func->AsNameExpr(), non_local_ids, aggrs, is_unknown); ASSERT(resolved); if ( is_unknown || CheckSideEffects(non_local_ids, aggrs) ) @@ -238,7 +238,7 @@ bool CSE_ValidityChecker::CheckSideEffects(SideEffectsOp::AccessType access, con IDSet non_local_ids; TypeSet aggrs; - if ( pfs.GetSideEffects(access, t.get(), non_local_ids, aggrs) ) + if ( pfs->GetSideEffects(access, t.get(), non_local_ids, aggrs) ) return Invalid(); return CheckSideEffects(non_local_ids, aggrs); diff --git a/src/script_opt/CSE.h b/src/script_opt/CSE.h index 40d600b3ae..9507cd493e 100644 --- a/src/script_opt/CSE.h +++ b/src/script_opt/CSE.h @@ -17,7 +17,7 @@ class TempVar; class CSE_ValidityChecker : public TraversalCallback { public: - CSE_ValidityChecker(ProfileFuncs& pfs, const std::vector& ids, const Expr* start_e, + CSE_ValidityChecker(std::shared_ptr pfs, const std::vector& ids, const Expr* start_e, const Expr* end_e); TraversalCode PreStmt(const Stmt*) override; @@ -71,7 +71,7 @@ protected: } // Profile across all script functions. - ProfileFuncs& pfs; + std::shared_ptr pfs; // The list of identifiers for which an assignment to one of them // renders the CSE unsafe. diff --git a/src/script_opt/GenIDDefs.cc b/src/script_opt/GenIDDefs.cc index 836e99586b..b05f334ea6 100644 --- a/src/script_opt/GenIDDefs.cc +++ b/src/script_opt/GenIDDefs.cc @@ -12,12 +12,12 @@ namespace zeek::detail { -GenIDDefs::GenIDDefs(std::shared_ptr _pf, const Func* f, ScopePtr scope, StmtPtr body) +GenIDDefs::GenIDDefs(std::shared_ptr _pf, const FuncPtr& f, ScopePtr scope, StmtPtr body) : pf(std::move(_pf)) { TraverseFunction(f, scope, body); } -void GenIDDefs::TraverseFunction(const Func* f, ScopePtr scope, StmtPtr body) { +void GenIDDefs::TraverseFunction(const FuncPtr& f, ScopePtr scope, StmtPtr body) { func_flavor = f->Flavor(); // Establish the outermost set of identifiers. diff --git a/src/script_opt/GenIDDefs.h b/src/script_opt/GenIDDefs.h index a8b05864cb..5074415f54 100644 --- a/src/script_opt/GenIDDefs.h +++ b/src/script_opt/GenIDDefs.h @@ -12,12 +12,12 @@ namespace zeek::detail { class GenIDDefs : public TraversalCallback { public: - GenIDDefs(std::shared_ptr _pf, const Func* f, ScopePtr scope, StmtPtr body); + GenIDDefs(std::shared_ptr _pf, const FuncPtr& f, ScopePtr scope, StmtPtr body); private: // Traverses the given function body, using the first two // arguments for context. - void TraverseFunction(const Func* f, ScopePtr scope, StmtPtr body); + void TraverseFunction(const FuncPtr& f, ScopePtr scope, StmtPtr body); TraversalCode PreStmt(const Stmt*) override; void AnalyzeSwitch(const SwitchStmt* sw); diff --git a/src/script_opt/ObjMgr.h b/src/script_opt/ObjMgr.h index 4a8f35695c..93698ef4ae 100644 --- a/src/script_opt/ObjMgr.h +++ b/src/script_opt/ObjMgr.h @@ -18,6 +18,8 @@ #include #include +#include "zeek/IntrusivePtr.h" + namespace zeek::detail { // A class that keeps a const Obj* pointer live - used to isolate instances diff --git a/src/script_opt/Reduce.cc b/src/script_opt/Reduce.cc index fb1478e70e..d45bf0fa1d 100644 --- a/src/script_opt/Reduce.cc +++ b/src/script_opt/Reduce.cc @@ -2,23 +2,15 @@ #include "zeek/script_opt/Reduce.h" -#include "zeek/Desc.h" -#include "zeek/Expr.h" -#include "zeek/Func.h" -#include "zeek/ID.h" -#include "zeek/Reporter.h" -#include "zeek/Scope.h" -#include "zeek/Stmt.h" -#include "zeek/Var.h" +#include "zeek/script_opt/CSE.h" #include "zeek/script_opt/ExprOptInfo.h" -#include "zeek/script_opt/FuncInfo.h" #include "zeek/script_opt/StmtOptInfo.h" #include "zeek/script_opt/TempVar.h" namespace zeek::detail { -Reducer::Reducer(const ScriptFunc* func, std::shared_ptr _pf, ProfileFuncs& _pfs) - : pf(std::move(_pf)), pfs(_pfs) { +Reducer::Reducer(const ScriptFuncPtr& func, std::shared_ptr _pf, std::shared_ptr _pfs) + : pf(std::move(_pf)), pfs(std::move(_pfs)) { auto& ft = func->GetType(); // Track the parameters so we don't remap them. @@ -442,15 +434,15 @@ bool Reducer::ExprValid(const ID* id, const Expr* e1, const Expr* e2) const { auto aggr = e1->GetOp1(); auto aggr_t = aggr->GetType(); - if ( pfs.HasSideEffects(SideEffectsOp::READ, aggr_t) ) + if ( pfs->HasSideEffects(SideEffectsOp::READ, aggr_t) ) has_side_effects = true; - else if ( aggr_t->Tag() == TYPE_TABLE && pfs.IsTableWithDefaultAggr(aggr_t.get()) ) + else if ( aggr_t->Tag() == TYPE_TABLE && pfs->IsTableWithDefaultAggr(aggr_t.get()) ) has_side_effects = true; } else if ( e1->Tag() == EXPR_RECORD_CONSTRUCTOR || e1->Tag() == EXPR_RECORD_COERCE ) - has_side_effects = pfs.HasSideEffects(SideEffectsOp::CONSTRUCTION, e1->GetType()); + has_side_effects = pfs->HasSideEffects(SideEffectsOp::CONSTRUCTION, e1->GetType()); e1_se = ExprSideEffects(has_side_effects); } diff --git a/src/script_opt/Reduce.h b/src/script_opt/Reduce.h index 706ca1f7e8..2bb1036445 100644 --- a/src/script_opt/Reduce.h +++ b/src/script_opt/Reduce.h @@ -2,11 +2,6 @@ #pragma once -#include "zeek/Expr.h" -#include "zeek/Scope.h" -#include "zeek/Stmt.h" -#include "zeek/Traverse.h" -#include "zeek/script_opt/CSE.h" #include "zeek/script_opt/ObjMgr.h" #include "zeek/script_opt/ProfileFunc.h" @@ -17,7 +12,7 @@ class TempVar; class Reducer { public: - Reducer(const ScriptFunc* func, std::shared_ptr pf, ProfileFuncs& pfs); + Reducer(const ScriptFuncPtr& func, std::shared_ptr pf, std::shared_ptr pfs); StmtPtr Reduce(StmtPtr s); @@ -237,7 +232,7 @@ protected: std::shared_ptr pf; // Profile across all script functions - used for optimization decisions. - ProfileFuncs& pfs; + std::shared_ptr pfs; // Tracks the temporary variables created during the reduction/ // optimization process. diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index 1ca1199528..34ffbf4c72 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -122,9 +122,9 @@ bool should_analyze(const ScriptFuncPtr& f, const StmtPtr& body) { return false; } -static bool optimize_AST(ScriptFunc* f, std::shared_ptr& pf, std::shared_ptr& rc, ScopePtr scope, - StmtPtr& body) { - pf = std::make_shared(f, body, true); +static bool optimize_AST(ScriptFuncPtr f, std::shared_ptr& pf, std::shared_ptr& rc, + ScopePtr scope, StmtPtr& body) { + pf = std::make_shared(f.get(), body, true); GenIDDefs ID_defs(pf, f, scope, body); @@ -147,8 +147,8 @@ static bool optimize_AST(ScriptFunc* f, std::shared_ptr& pf, std::s return true; } -static void optimize_func(ScriptFunc* f, std::shared_ptr pf, ProfileFuncs& pfs, ScopePtr scope, - StmtPtr& body) { +static void optimize_func(ScriptFuncPtr f, std::shared_ptr pf, std::shared_ptr pfs, + ScopePtr scope, StmtPtr& body) { if ( reporter->Errors() > 0 ) return; @@ -201,7 +201,7 @@ static void optimize_func(ScriptFunc* f, std::shared_ptr pf, Profil } // Profile the new body. - pf = std::make_shared(f, body, true); + pf = std::make_shared(f.get(), body, true); // Compute its reaching definitions. GenIDDefs ID_defs(pf, f, scope, body); @@ -372,6 +372,8 @@ static void use_CPP() { int num_used = 0; + auto pfs = std::make_unique(funcs, is_CPP_compilable, false); + for ( auto& f : funcs ) { auto hash = f.Profile()->HashVal(); auto s = compiled_scripts.find(hash); @@ -420,9 +422,9 @@ static void generate_CPP() { const bool standalone = analysis_options.gen_standalone_CPP; const bool report = analysis_options.report_uncompilable; - auto pfs = std::make_unique(funcs, is_CPP_compilable, false); + auto pfs = std::make_shared(funcs, is_CPP_compilable, false); - CPPCompile cpp(funcs, *pfs, gen_name, standalone, report); + CPPCompile cpp(funcs, pfs, gen_name, standalone, report); } static void analyze_scripts_for_ZAM() { @@ -433,7 +435,7 @@ static void analyze_scripts_for_ZAM() { analysis_options.optimize_AST = false; } - auto pfs = std::make_unique(funcs, nullptr, true); + auto pfs = std::make_shared(funcs, nullptr, true); bool report_recursive = analysis_options.report_recursive; std::unique_ptr inl; @@ -471,12 +473,12 @@ static void analyze_scripts_for_ZAM() { if ( ! f.ShouldAnalyze() ) continue; - auto func = f.Func(); - auto l = lambdas.find(func); + auto& func = f.FuncPtr(); + auto l = lambdas.find(func.get()); bool is_lambda = l != lambdas.end(); - if ( ! analysis_options.compile_all && ! is_lambda && inl && inl->WasFullyInlined(func) && - func_used_indirectly.count(func) == 0 ) { + if ( ! analysis_options.compile_all && ! is_lambda && inl && inl->WasFullyInlined(func.get()) && + func_used_indirectly.count(func.get()) == 0 ) { // No need to compile as it won't be called directly. // We'd like to zero out the body to recover the // memory, but a *few* such functions do get called, @@ -487,7 +489,7 @@ static void analyze_scripts_for_ZAM() { } auto new_body = f.Body(); - optimize_func(func, f.ProfilePtr(), *pfs, f.Scope(), new_body); + optimize_func(func, f.ProfilePtr(), pfs, f.Scope(), new_body); f.SetBody(new_body); if ( is_lambda ) diff --git a/src/script_opt/ZAM/AM-Opt.cc b/src/script_opt/ZAM/AM-Opt.cc index deb5fbbf69..dbb5804a58 100644 --- a/src/script_opt/ZAM/AM-Opt.cc +++ b/src/script_opt/ZAM/AM-Opt.cc @@ -634,8 +634,9 @@ void ZAMCompiler::ReMapInterpreterFrame() { // Update frame sizes for functions that might have more than // one body. - if ( remapped_intrp_frame_sizes.count(func) == 0 || remapped_intrp_frame_sizes[func] < next_interp_slot ) - remapped_intrp_frame_sizes[func] = next_interp_slot; + auto f = func.get(); + if ( remapped_intrp_frame_sizes.count(f) == 0 || remapped_intrp_frame_sizes[f] < next_interp_slot ) + remapped_intrp_frame_sizes[f] = next_interp_slot; } void ZAMCompiler::ReMapVar(const ID* id, int slot, zeek_uint_t inst) { diff --git a/src/script_opt/ZAM/Compile.h b/src/script_opt/ZAM/Compile.h index e25ac57fcc..686c92d40d 100644 --- a/src/script_opt/ZAM/Compile.h +++ b/src/script_opt/ZAM/Compile.h @@ -52,8 +52,8 @@ public: class ZAMCompiler { public: - ZAMCompiler(ScriptFunc* f, ProfileFuncs& pfs, std::shared_ptr pf, ScopePtr scope, StmtPtr body, - std::shared_ptr ud, std::shared_ptr rd); + ZAMCompiler(ScriptFuncPtr f, std::shared_ptr pfs, std::shared_ptr pf, ScopePtr scope, + StmtPtr body, std::shared_ptr ud, std::shared_ptr rd); ~ZAMCompiler(); StmtPtr CompileBody(); @@ -501,8 +501,8 @@ private: // (and/or no return value generated). std::vector retvars; - ScriptFunc* func; - ProfileFuncs& pfs; + ScriptFuncPtr func; + std::shared_ptr pfs; std::shared_ptr pf; ScopePtr scope; StmtPtr body; diff --git a/src/script_opt/ZAM/Driver.cc b/src/script_opt/ZAM/Driver.cc index be6e165907..614beba6c2 100644 --- a/src/script_opt/ZAM/Driver.cc +++ b/src/script_opt/ZAM/Driver.cc @@ -13,10 +13,10 @@ namespace zeek::detail { -ZAMCompiler::ZAMCompiler(ScriptFunc* f, ProfileFuncs& _pfs, std::shared_ptr _pf, ScopePtr _scope, - StmtPtr _body, std::shared_ptr _ud, std::shared_ptr _rd) - : pfs(_pfs) { - func = f; +ZAMCompiler::ZAMCompiler(ScriptFuncPtr f, std::shared_ptr _pfs, std::shared_ptr _pf, + ScopePtr _scope, StmtPtr _body, std::shared_ptr _ud, std::shared_ptr _rd) { + func = std::move(f); + pfs = std::move(_pfs); pf = std::move(_pf); scope = std::move(_scope); body = std::move(_body); @@ -42,7 +42,7 @@ void ZAMCompiler::Init() { TrackMemoryManagement(); - non_recursive = non_recursive_funcs.count(func) > 0; + non_recursive = non_recursive_funcs.count(func.get()) > 0; } void ZAMCompiler::InitGlobals() { diff --git a/src/script_opt/ZAM/Expr.cc b/src/script_opt/ZAM/Expr.cc index 4bcde31aea..e495a0775d 100644 --- a/src/script_opt/ZAM/Expr.cc +++ b/src/script_opt/ZAM/Expr.cc @@ -666,7 +666,7 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot, const T z = ZInstI(zop, Frame1Slot(n1, zop), n2_slot, c3); } - if ( pfs.HasSideEffects(SideEffectsOp::READ, n2t) ) { + if ( pfs->HasSideEffects(SideEffectsOp::READ, n2t) ) { z.aux = new ZInstAux(0); z.aux->can_change_non_locals = true; } @@ -851,7 +851,7 @@ const ZAMStmt ZAMCompiler::AssignTableElem(const Expr* e) { z.aux = InternalBuildVals(op2); z.t = op3->GetType(); - if ( pfs.HasSideEffects(SideEffectsOp::WRITE, op1->GetType()) ) + if ( pfs->HasSideEffects(SideEffectsOp::WRITE, op1->GetType()) ) z.aux->can_change_non_locals = true; return AddInst(z); @@ -1013,7 +1013,7 @@ const ZAMStmt ZAMCompiler::DoCall(const CallExpr* c, const NameExpr* n) { TypeSet aggrs; bool is_unknown = false; - auto resolved = pfs.GetCallSideEffects(func, non_local_ids, aggrs, is_unknown); + auto resolved = pfs->GetCallSideEffects(func, non_local_ids, aggrs, is_unknown); ASSERT(resolved); if ( is_unknown || ! non_local_ids.empty() || ! aggrs.empty() ) @@ -1103,7 +1103,7 @@ const ZAMStmt ZAMCompiler::ConstructRecord(const NameExpr* n, const Expr* e) { z.t = e->GetType(); - if ( pfs.HasSideEffects(SideEffectsOp::CONSTRUCTION, z.t) ) + if ( pfs->HasSideEffects(SideEffectsOp::CONSTRUCTION, z.t) ) z.aux->can_change_non_locals = true; return AddInst(z); @@ -1202,7 +1202,7 @@ const ZAMStmt ZAMCompiler::RecordCoerce(const NameExpr* n, const Expr* e) { // Mark the integer entries in z.aux as not being frame slots as usual. z.aux->slots = nullptr; - if ( pfs.HasSideEffects(SideEffectsOp::CONSTRUCTION, e->GetType()) ) + if ( pfs->HasSideEffects(SideEffectsOp::CONSTRUCTION, e->GetType()) ) z.aux->can_change_non_locals = true; return AddInst(z);