FuncInfo now tracks priority; some tidying/widening of its accessors

This commit is contained in:
Vern Paxson 2021-04-19 16:19:22 -07:00
parent 8d2bb28f03
commit 72f62f398a
3 changed files with 19 additions and 13 deletions

View file

@ -433,7 +433,7 @@ ProfileFuncs::ProfileFuncs(std::vector<FuncInfo>& funcs,
f.SetSkip(true); f.SetSkip(true);
f.SetProfile(std::move(pf)); f.SetProfile(std::move(pf));
func_profs[f.Func()] = f.Profile(); func_profs[f.Func()] = f.ProfilePtr();
} }
// We now have the main (starting) types used by all of the // We now have the main (starting) types used by all of the
@ -524,7 +524,7 @@ void ProfileFuncs::ComputeBodyHashes(std::vector<FuncInfo>& funcs)
{ {
for ( auto& f : funcs ) for ( auto& f : funcs )
if ( ! f.ShouldSkip() ) if ( ! f.ShouldSkip() )
ComputeProfileHash(f.Profile()); ComputeProfileHash(f.ProfilePtr());
for ( auto& l : lambdas ) for ( auto& l : lambdas )
ComputeProfileHash(ExprProf(l)); ComputeProfileHash(ExprProf(l));

View file

@ -138,8 +138,10 @@ void optimize_func(ScriptFunc* f, std::shared_ptr<ProfileFunc> pf,
} }
FuncInfo::FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body) FuncInfo::FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body,
: func(std::move(_func)), scope(std::move(_scope)), body(std::move(_body)) int _priority)
: func(std::move(_func)), scope(std::move(_scope)),
body(std::move(_body)), priority(_priority)
{} {}
void FuncInfo::SetProfile(std::shared_ptr<ProfileFunc> _pf) void FuncInfo::SetProfile(std::shared_ptr<ProfileFunc> _pf)
@ -151,7 +153,8 @@ void analyze_func(ScriptFuncPtr f)
*analysis_options.only_func != f->Name() ) *analysis_options.only_func != f->Name() )
return; return;
funcs.emplace_back(f, ScopePtr{NewRef{}, f->GetScope()}, f->CurrentBody()); funcs.emplace_back(f, ScopePtr{NewRef{}, f->GetScope()},
f->CurrentBody(), f->CurrentPriority());
} }
const FuncInfo* analyze_global_stmts(Stmt* stmts) const FuncInfo* analyze_global_stmts(Stmt* stmts)
@ -170,7 +173,7 @@ const FuncInfo* analyze_global_stmts(Stmt* stmts)
StmtPtr stmts_p{NewRef{}, stmts}; StmtPtr stmts_p{NewRef{}, stmts};
auto sf = make_intrusive<ScriptFunc>(id, stmts_p, empty_inits, sc->Length(), 0); auto sf = make_intrusive<ScriptFunc>(id, stmts_p, empty_inits, sc->Length(), 0);
funcs.emplace_back(sf, ScopePtr{NewRef{}, sc}, stmts_p); funcs.emplace_back(sf, ScopePtr{NewRef{}, sc}, stmts_p, 0);
return &funcs.back(); return &funcs.back();
} }
@ -301,7 +304,7 @@ void analyze_scripts()
continue; continue;
auto new_body = f.Body(); auto new_body = f.Body();
optimize_func(f.Func(), f.Profile(), f.Scope(), optimize_func(f.Func(), f.ProfilePtr(), f.Scope(),
new_body, analysis_options); new_body, analysis_options);
f.SetBody(new_body); f.SetBody(new_body);
} }

View file

@ -62,13 +62,15 @@ using ScriptFuncPtr = IntrusivePtr<ScriptFunc>;
// Info we need for tracking an instance of a function. // Info we need for tracking an instance of a function.
class FuncInfo { class FuncInfo {
public: public:
FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body); FuncInfo(ScriptFuncPtr func, ScopePtr scope, StmtPtr body, int priority);
ScriptFunc* Func() const { return func.get(); } ScriptFunc* Func() const { return func.get(); }
ScriptFuncPtr FuncPtr() const { return func; } const ScriptFuncPtr& FuncPtr() const { return func; }
ScopePtr Scope() const { return scope; } const ScopePtr& Scope() const { return scope; }
StmtPtr Body() const { return body; } const StmtPtr& Body() const { return body; }
std::shared_ptr<ProfileFunc> Profile() const { return pf; } int Priority() const { return priority; }
const ProfileFunc* Profile() const { return pf.get(); }
std::shared_ptr<ProfileFunc> ProfilePtr() const { return pf; }
const std::string& SaveFile() const { return save_file; } const std::string& SaveFile() const { return save_file; }
void SetBody(StmtPtr new_body) { body = std::move(new_body); } void SetBody(StmtPtr new_body) { body = std::move(new_body); }
@ -87,6 +89,7 @@ protected:
ScopePtr scope; ScopePtr scope;
StmtPtr body; StmtPtr body;
std::shared_ptr<ProfileFunc> pf; std::shared_ptr<ProfileFunc> pf;
int priority;
// If we're saving this function in a file, this is the name // If we're saving this function in a file, this is the name
// of the file to use. // of the file to use.