AST profiles track the associated function/body/expression

This commit is contained in:
Vern Paxson 2021-11-24 15:18:40 -08:00
parent 8e1d770966
commit f865897cac
2 changed files with 23 additions and 6 deletions

View file

@ -60,12 +60,23 @@ p_hash_type script_specific_hash(const StmtPtr& body, p_hash_type generic_hash)
ProfileFunc::ProfileFunc(const Func* func, const StmtPtr& body, bool _abs_rec_fields) ProfileFunc::ProfileFunc(const Func* func, const StmtPtr& body, bool _abs_rec_fields)
{ {
profiled_func = func;
profiled_body = body.get();
abs_rec_fields = _abs_rec_fields; abs_rec_fields = _abs_rec_fields;
Profile(func->GetType().get(), body); Profile(func->GetType().get(), body);
} }
ProfileFunc::ProfileFunc(const Stmt* s, bool _abs_rec_fields)
{
profiled_body = s;
abs_rec_fields = _abs_rec_fields;
s->Traverse(this);
}
ProfileFunc::ProfileFunc(const Expr* e, bool _abs_rec_fields) ProfileFunc::ProfileFunc(const Expr* e, bool _abs_rec_fields)
{ {
profiled_expr = e;
abs_rec_fields = _abs_rec_fields; abs_rec_fields = _abs_rec_fields;
if ( e->Tag() == EXPR_LAMBDA ) if ( e->Tag() == EXPR_LAMBDA )
@ -84,12 +95,6 @@ ProfileFunc::ProfileFunc(const Expr* e, bool _abs_rec_fields)
e->Traverse(this); e->Traverse(this);
} }
ProfileFunc::ProfileFunc(const Stmt* s, bool _abs_rec_fields)
{
abs_rec_fields = _abs_rec_fields;
s->Traverse(this);
}
void ProfileFunc::Profile(const FuncType* ft, const StmtPtr& body) void ProfileFunc::Profile(const FuncType* ft, const StmtPtr& body)
{ {
num_params = ft->Params()->NumFields(); num_params = ft->Params()->NumFields();

View file

@ -100,6 +100,12 @@ public:
ProfileFunc(const Stmt* body, bool abs_rec_fields = false); ProfileFunc(const Stmt* body, bool abs_rec_fields = false);
ProfileFunc(const Expr* func, bool abs_rec_fields = false); ProfileFunc(const Expr* func, bool abs_rec_fields = false);
// Returns the function, body, or expression profiled. Each can be
// null depending on the constructor used.
const Func* ProfiledFunc() const { return profiled_func; }
const Stmt* ProfiledBody() const { return profiled_body; }
const Expr* ProfiledExpr() const { return profiled_expr; }
// See the comments for the associated member variables for each // See the comments for the associated member variables for each
// of these accessors. // of these accessors.
const std::unordered_set<const ID*>& Globals() const { return globals; } const std::unordered_set<const ID*>& Globals() const { return globals; }
@ -157,6 +163,12 @@ protected:
// Take note of an assignment to an identifier. // Take note of an assignment to an identifier.
void TrackAssignment(const ID* id); void TrackAssignment(const ID* id);
// The function, body, or expression profiled. Can be null
// depending on which constructor was used.
const Func* profiled_func = nullptr;
const Stmt* profiled_body = nullptr;
const Expr* profiled_expr = nullptr;
// Globals seen in the function. // Globals seen in the function.
// //
// Does *not* include globals solely seen as the function being // Does *not* include globals solely seen as the function being