switch over to tracking current Body's rather than individual components

This commit is contained in:
Vern Paxson 2025-09-12 17:37:34 -07:00
parent 16c46a3462
commit f92acb3a4c
5 changed files with 26 additions and 13 deletions

View file

@ -216,6 +216,16 @@ public:
*/ */
void AddFunc(detail::ScriptFuncPtr f); void AddFunc(detail::ScriptFuncPtr f);
/**
* @return The name associated with the group.
*/
const auto& GetName() const { return name; }
/**
* @return The type of group.
*/
const auto& GetEventGroupKind() const { return kind; }
private: private:
void UpdateFuncBodies(); void UpdateFuncBodies();

View file

@ -265,9 +265,7 @@ public:
*/ */
void ReplaceBody(const detail::StmtPtr& old_body, detail::StmtPtr new_body); void ReplaceBody(const detail::StmtPtr& old_body, detail::StmtPtr new_body);
StmtPtr CurrentBody() const { return current_body.stmts; } auto CurrentBody() const { return current_body; }
int CurrentPriority() const { return current_body.priority; }
auto CurrentEventGroups() const { return current_body.groups; }
/** /**
* Returns the function's frame size. * Returns the function's frame size.

View file

@ -299,7 +299,11 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vector<Func::
PostInline(oi, inlined_func); PostInline(oi, inlined_func);
funcs.emplace_back(inlined_func, new_scope, merged_body, 0); // We don't need to worry about event groups because the CoalescedScriptFunc
// wrapper checks at run-time for whether any handlers have been disabled,
// and if so skips coalesced execution.
Func::Body body{.stmts = merged_body, .priority = 0};
funcs.emplace_back(inlined_func, new_scope, std::move(body));
auto pf = std::make_shared<ProfileFunc>(inlined_func.get(), merged_body, true); auto pf = std::make_shared<ProfileFunc>(inlined_func.get(), merged_body, true);
funcs.back().SetProfile(std::move(pf)); funcs.back().SetProfile(std::move(pf));

View file

@ -41,7 +41,7 @@ void analyze_func(ScriptFuncPtr f) {
// Even if we're analyzing only a subset of the scripts, we still // Even if we're analyzing only a subset of the scripts, we still
// track all functions here because the inliner will need the full list. // track all functions here because the inliner will need the full list.
ASSERT(f->GetScope()); ASSERT(f->GetScope());
funcs.emplace_back(f, f->GetScope(), f->CurrentBody(), f->CurrentPriority()); funcs.emplace_back(f, f->GetScope(), f->CurrentBody());
} }
void analyze_lambda(LambdaExpr* l) { void analyze_lambda(LambdaExpr* l) {
@ -78,7 +78,8 @@ void analyze_global_stmts(Stmt* stmts) {
global_stmts->SetScope(sc); global_stmts->SetScope(sc);
global_stmts_ind = funcs.size(); global_stmts_ind = funcs.size();
funcs.emplace_back(global_stmts, sc, stmts->ThisPtr(), 0); Func::Body body{.stmts = stmts->ThisPtr(), .priority = 0};
funcs.emplace_back(global_stmts, sc, body);
} }
std::pair<StmtPtr, ScopePtr> get_global_stmts() { std::pair<StmtPtr, ScopePtr> get_global_stmts() {

View file

@ -154,19 +154,20 @@ 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, int _priority) FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, Func::Body _body)
: func(std::move(_func)), scope(std::move(_scope)), body(std::move(_body)), priority(_priority) {} : func(std::move(_func)), scope(std::move(_scope)), body(std::move(_body)) {}
ScriptFunc* Func() const { return func.get(); } ScriptFunc* Func() const { return func.get(); }
const ScriptFuncPtr& FuncPtr() const { return func; } const ScriptFuncPtr& FuncPtr() const { return func; }
const ScopePtr& Scope() const { return scope; } const ScopePtr& Scope() const { return scope; }
const StmtPtr& Body() const { return body; } const StmtPtr& Body() const { return body.stmts; }
int Priority() const { return priority; } int Priority() const { return body.priority; }
auto EventGroups() const { return body.groups; }
const ProfileFunc* Profile() const { return pf.get(); } const ProfileFunc* Profile() const { return pf.get(); }
std::shared_ptr<ProfileFunc> ProfilePtr() const { return pf; } std::shared_ptr<ProfileFunc> ProfilePtr() const { return pf; }
void SetScope(ScopePtr new_scope) { scope = std::move(new_scope); } void SetScope(ScopePtr new_scope) { scope = std::move(new_scope); }
void SetBody(StmtPtr new_body) { body = std::move(new_body); } void SetBody(StmtPtr new_body) { body.stmts = std::move(new_body); }
void SetProfile(std::shared_ptr<ProfileFunc> _pf) { pf = std::move(_pf); } void SetProfile(std::shared_ptr<ProfileFunc> _pf) { pf = std::move(_pf); }
bool ShouldAnalyze() const { return should_analyze; } bool ShouldAnalyze() const { return should_analyze; }
@ -183,9 +184,8 @@ public:
protected: protected:
ScriptFuncPtr func; ScriptFuncPtr func;
ScopePtr scope; ScopePtr scope;
StmtPtr body; Func::Body body;
std::shared_ptr<ProfileFunc> pf; std::shared_ptr<ProfileFunc> pf;
int priority;
// Whether to analyze this function at all, per optimization selection // Whether to analyze this function at all, per optimization selection
// via --optimize-file/--optimize-func. If those flags aren't used, // via --optimize-file/--optimize-func. If those flags aren't used,