mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 01:28:20 +00:00
track implicit assignments when profiling, associate counts with assignees
This commit is contained in:
parent
dbb509448f
commit
fb101f7b0e
2 changed files with 22 additions and 6 deletions
|
@ -261,13 +261,17 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EXPR_INCR:
|
||||||
|
case EXPR_DECR:
|
||||||
|
case EXPR_ADD_TO:
|
||||||
|
case EXPR_REMOVE_FROM:
|
||||||
case EXPR_ASSIGN:
|
case EXPR_ASSIGN:
|
||||||
{
|
{
|
||||||
if ( e->GetOp1()->Tag() == EXPR_REF )
|
if ( e->GetOp1()->Tag() == EXPR_REF )
|
||||||
{
|
{
|
||||||
auto lhs = e->GetOp1()->GetOp1();
|
auto lhs = e->GetOp1()->GetOp1();
|
||||||
if ( lhs->Tag() == EXPR_NAME )
|
if ( lhs->Tag() == EXPR_NAME )
|
||||||
assignees.insert(lhs->AsNameExpr()->Id());
|
TrackAssignment(lhs->AsNameExpr()->Id());
|
||||||
}
|
}
|
||||||
// else this isn't a direct assignment.
|
// else this isn't a direct assignment.
|
||||||
break;
|
break;
|
||||||
|
@ -432,6 +436,14 @@ void ProfileFunc::TrackID(const ID* id)
|
||||||
ordered_ids.push_back(id);
|
ordered_ids.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProfileFunc::TrackAssignment(const ID* id)
|
||||||
|
{
|
||||||
|
if ( assignees.count(id) > 0 )
|
||||||
|
++assignees[id];
|
||||||
|
else
|
||||||
|
assignees[id] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ProfileFuncs::ProfileFuncs(std::vector<FuncInfo>& funcs,
|
ProfileFuncs::ProfileFuncs(std::vector<FuncInfo>& funcs,
|
||||||
is_compilable_pred pred, bool _full_record_hashes)
|
is_compilable_pred pred, bool _full_record_hashes)
|
||||||
|
|
|
@ -103,7 +103,7 @@ public:
|
||||||
{ return locals; }
|
{ return locals; }
|
||||||
const std::unordered_set<const ID*>& Params() const
|
const std::unordered_set<const ID*>& Params() const
|
||||||
{ return params; }
|
{ return params; }
|
||||||
const std::unordered_set<const ID*>& Assignees() const
|
const std::unordered_map<const ID*, int>& Assignees() const
|
||||||
{ return assignees; }
|
{ return assignees; }
|
||||||
const std::unordered_set<const ID*>& Inits() const
|
const std::unordered_set<const ID*>& Inits() const
|
||||||
{ return inits; }
|
{ return inits; }
|
||||||
|
@ -166,6 +166,9 @@ protected:
|
||||||
// Take note of the presence of an identifier.
|
// Take note of the presence of an identifier.
|
||||||
void TrackID(const ID* id);
|
void TrackID(const ID* id);
|
||||||
|
|
||||||
|
// Take note of an assignment to an identifier.
|
||||||
|
void TrackAssignment(const ID* id);
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -187,10 +190,11 @@ protected:
|
||||||
// function.
|
// function.
|
||||||
int num_params = -1;
|
int num_params = -1;
|
||||||
|
|
||||||
// Identifiers (globals, locals, parameters) that are assigned to.
|
// Maps identifiers (globals, locals, parameters) to how often
|
||||||
// Does not include implicit assignments due to initializations,
|
// they are assigned to (no entry if never). Does not include
|
||||||
// which are instead captured in "inits".
|
// implicit assignments due to initializations, which are instead
|
||||||
std::unordered_set<const ID*> assignees;
|
// captured in "inits".
|
||||||
|
std::unordered_map<const ID*, int> assignees;
|
||||||
|
|
||||||
// Same for locals seen in initializations, so we can find,
|
// Same for locals seen in initializations, so we can find,
|
||||||
// for example, unused aggregates.
|
// for example, unused aggregates.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue