mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
regularized (some) types of pointers used in script optimization
This commit is contained in:
parent
dd389c0380
commit
709d410fcd
18 changed files with 85 additions and 93 deletions
|
@ -16,7 +16,7 @@ shared_ptr<CPP_InitInfo> 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*>(attributes.GetRep(attrs));
|
||||
|
|
|
@ -124,8 +124,8 @@ namespace zeek::detail {
|
|||
|
||||
class CPPCompile {
|
||||
public:
|
||||
CPPCompile(std::vector<FuncInfo>& _funcs, ProfileFuncs& pfs, const std::string& gen_name, bool _standalone,
|
||||
bool report_uncompilable);
|
||||
CPPCompile(std::vector<FuncInfo>& _funcs, std::shared_ptr<ProfileFuncs> 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<FuncInfo>& funcs;
|
||||
|
||||
// The global profile of all of the functions.
|
||||
ProfileFuncs& pfs;
|
||||
std::shared_ptr<ProfileFuncs> 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.
|
||||
|
|
|
@ -13,9 +13,9 @@ namespace zeek::detail {
|
|||
|
||||
using namespace std;
|
||||
|
||||
CPPCompile::CPPCompile(vector<FuncInfo>& _funcs, ProfileFuncs& _pfs, const string& gen_name, bool _standalone,
|
||||
bool report_uncompilable)
|
||||
: funcs(_funcs), pfs(_pfs), standalone(_standalone) {
|
||||
CPPCompile::CPPCompile(vector<FuncInfo>& _funcs, std::shared_ptr<ProfileFuncs> _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<string, const Stmt*> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
CSE_ValidityChecker::CSE_ValidityChecker(ProfileFuncs& _pfs, const std::vector<const ID*>& _ids,
|
||||
CSE_ValidityChecker::CSE_ValidityChecker(std::shared_ptr<ProfileFuncs> _pfs, const std::vector<const ID*>& _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);
|
||||
|
|
|
@ -17,7 +17,7 @@ class TempVar;
|
|||
|
||||
class CSE_ValidityChecker : public TraversalCallback {
|
||||
public:
|
||||
CSE_ValidityChecker(ProfileFuncs& pfs, const std::vector<const ID*>& ids, const Expr* start_e,
|
||||
CSE_ValidityChecker(std::shared_ptr<ProfileFuncs> pfs, const std::vector<const ID*>& 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<ProfileFuncs> pfs;
|
||||
|
||||
// The list of identifiers for which an assignment to one of them
|
||||
// renders the CSE unsafe.
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
GenIDDefs::GenIDDefs(std::shared_ptr<ProfileFunc> _pf, const Func* f, ScopePtr scope, StmtPtr body)
|
||||
GenIDDefs::GenIDDefs(std::shared_ptr<ProfileFunc> _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.
|
||||
|
|
|
@ -12,12 +12,12 @@ namespace zeek::detail {
|
|||
|
||||
class GenIDDefs : public TraversalCallback {
|
||||
public:
|
||||
GenIDDefs(std::shared_ptr<ProfileFunc> _pf, const Func* f, ScopePtr scope, StmtPtr body);
|
||||
GenIDDefs(std::shared_ptr<ProfileFunc> _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);
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include <zeek/Obj.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "zeek/IntrusivePtr.h"
|
||||
|
||||
namespace zeek::detail {
|
||||
|
||||
// A class that keeps a const Obj* pointer live - used to isolate instances
|
||||
|
|
|
@ -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<ProfileFunc> _pf, ProfileFuncs& _pfs)
|
||||
: pf(std::move(_pf)), pfs(_pfs) {
|
||||
Reducer::Reducer(const ScriptFuncPtr& func, std::shared_ptr<ProfileFunc> _pf, std::shared_ptr<ProfileFuncs> _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);
|
||||
}
|
||||
|
|
|
@ -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<ProfileFunc> pf, ProfileFuncs& pfs);
|
||||
Reducer(const ScriptFuncPtr& func, std::shared_ptr<ProfileFunc> pf, std::shared_ptr<ProfileFuncs> pfs);
|
||||
|
||||
StmtPtr Reduce(StmtPtr s);
|
||||
|
||||
|
@ -237,7 +232,7 @@ protected:
|
|||
std::shared_ptr<ProfileFunc> pf;
|
||||
|
||||
// Profile across all script functions - used for optimization decisions.
|
||||
ProfileFuncs& pfs;
|
||||
std::shared_ptr<ProfileFuncs> pfs;
|
||||
|
||||
// Tracks the temporary variables created during the reduction/
|
||||
// optimization process.
|
||||
|
|
|
@ -122,9 +122,9 @@ bool should_analyze(const ScriptFuncPtr& f, const StmtPtr& body) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool optimize_AST(ScriptFunc* f, std::shared_ptr<ProfileFunc>& pf, std::shared_ptr<Reducer>& rc, ScopePtr scope,
|
||||
StmtPtr& body) {
|
||||
pf = std::make_shared<ProfileFunc>(f, body, true);
|
||||
static bool optimize_AST(ScriptFuncPtr f, std::shared_ptr<ProfileFunc>& pf, std::shared_ptr<Reducer>& rc,
|
||||
ScopePtr scope, StmtPtr& body) {
|
||||
pf = std::make_shared<ProfileFunc>(f.get(), body, true);
|
||||
|
||||
GenIDDefs ID_defs(pf, f, scope, body);
|
||||
|
||||
|
@ -147,8 +147,8 @@ static bool optimize_AST(ScriptFunc* f, std::shared_ptr<ProfileFunc>& pf, std::s
|
|||
return true;
|
||||
}
|
||||
|
||||
static void optimize_func(ScriptFunc* f, std::shared_ptr<ProfileFunc> pf, ProfileFuncs& pfs, ScopePtr scope,
|
||||
StmtPtr& body) {
|
||||
static void optimize_func(ScriptFuncPtr f, std::shared_ptr<ProfileFunc> pf, std::shared_ptr<ProfileFuncs> pfs,
|
||||
ScopePtr scope, StmtPtr& body) {
|
||||
if ( reporter->Errors() > 0 )
|
||||
return;
|
||||
|
||||
|
@ -201,7 +201,7 @@ static void optimize_func(ScriptFunc* f, std::shared_ptr<ProfileFunc> pf, Profil
|
|||
}
|
||||
|
||||
// Profile the new body.
|
||||
pf = std::make_shared<ProfileFunc>(f, body, true);
|
||||
pf = std::make_shared<ProfileFunc>(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<ProfileFuncs>(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<ProfileFuncs>(funcs, is_CPP_compilable, false);
|
||||
auto pfs = std::make_shared<ProfileFuncs>(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<ProfileFuncs>(funcs, nullptr, true);
|
||||
auto pfs = std::make_shared<ProfileFuncs>(funcs, nullptr, true);
|
||||
|
||||
bool report_recursive = analysis_options.report_recursive;
|
||||
std::unique_ptr<Inliner> 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 )
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -52,8 +52,8 @@ public:
|
|||
|
||||
class ZAMCompiler {
|
||||
public:
|
||||
ZAMCompiler(ScriptFunc* f, ProfileFuncs& pfs, std::shared_ptr<ProfileFunc> pf, ScopePtr scope, StmtPtr body,
|
||||
std::shared_ptr<UseDefs> ud, std::shared_ptr<Reducer> rd);
|
||||
ZAMCompiler(ScriptFuncPtr f, std::shared_ptr<ProfileFuncs> pfs, std::shared_ptr<ProfileFunc> pf, ScopePtr scope,
|
||||
StmtPtr body, std::shared_ptr<UseDefs> ud, std::shared_ptr<Reducer> rd);
|
||||
~ZAMCompiler();
|
||||
|
||||
StmtPtr CompileBody();
|
||||
|
@ -501,8 +501,8 @@ private:
|
|||
// (and/or no return value generated).
|
||||
std::vector<const NameExpr*> retvars;
|
||||
|
||||
ScriptFunc* func;
|
||||
ProfileFuncs& pfs;
|
||||
ScriptFuncPtr func;
|
||||
std::shared_ptr<ProfileFuncs> pfs;
|
||||
std::shared_ptr<ProfileFunc> pf;
|
||||
ScopePtr scope;
|
||||
StmtPtr body;
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
ZAMCompiler::ZAMCompiler(ScriptFunc* f, ProfileFuncs& _pfs, std::shared_ptr<ProfileFunc> _pf, ScopePtr _scope,
|
||||
StmtPtr _body, std::shared_ptr<UseDefs> _ud, std::shared_ptr<Reducer> _rd)
|
||||
: pfs(_pfs) {
|
||||
func = f;
|
||||
ZAMCompiler::ZAMCompiler(ScriptFuncPtr f, std::shared_ptr<ProfileFuncs> _pfs, std::shared_ptr<ProfileFunc> _pf,
|
||||
ScopePtr _scope, StmtPtr _body, std::shared_ptr<UseDefs> _ud, std::shared_ptr<Reducer> _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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue