minor simplifying

This commit is contained in:
Vern Paxson 2023-11-30 13:43:28 -08:00
parent f8478def21
commit 3a2fe7f98c
7 changed files with 37 additions and 37 deletions

View file

@ -1019,7 +1019,7 @@ void ProfileFuncs::ComputeSideEffects() {
for ( auto c : candidates ) {
IDSet non_local_ids;
std::unordered_set<const Type*> aggrs;
TypeSet aggrs;
bool is_unknown = false;
curr_candidate = c;
@ -1036,7 +1036,7 @@ void ProfileFuncs::ComputeSideEffects() {
if ( made_decision.empty() ) {
// ###
IDSet non_local_ids;
std::unordered_set<const Type*> aggrs;
TypeSet aggrs;
bool is_unknown = true;
for ( auto c : candidates ) {
// printf("jackpot for %s\n", obj_desc(c).c_str());
@ -1050,7 +1050,7 @@ void ProfileFuncs::ComputeSideEffects() {
}
}
void ProfileFuncs::SetSideEffects(const Attr* a, IDSet& non_local_ids, std::unordered_set<const Type*>& aggrs,
void ProfileFuncs::SetSideEffects(const Attr* a, IDSet& non_local_ids, TypeSet& aggrs,
bool& is_unknown) {
auto seo_vec = std::vector<std::shared_ptr<SideEffectsOp>>{};
bool is_rec = expr_attrs[a][0]->Tag() == TYPE_RECORD;
@ -1133,7 +1133,7 @@ std::vector<const Attr*> ProfileFuncs::AssociatedAttrs(const Type* t) {
return assoc_attrs;
}
bool ProfileFuncs::AssessSideEffects(const ExprPtr& e, IDSet& non_local_ids, std::unordered_set<const Type*>& aggrs,
bool ProfileFuncs::AssessSideEffects(const ExprPtr& e, IDSet& non_local_ids, TypeSet& aggrs,
bool& is_unknown) {
std::shared_ptr<ProfileFunc> pf;
@ -1147,7 +1147,7 @@ bool ProfileFuncs::AssessSideEffects(const ExprPtr& e, IDSet& non_local_ids, std
}
bool ProfileFuncs::AssessSideEffects(const ProfileFunc* pf, IDSet& non_local_ids,
std::unordered_set<const Type*>& aggrs, bool& is_unknown) {
TypeSet& aggrs, bool& is_unknown) {
if ( pf->DoesIndirectCalls() )
is_unknown = true;
@ -1158,7 +1158,7 @@ bool ProfileFuncs::AssessSideEffects(const ProfileFunc* pf, IDSet& non_local_ids
}
IDSet nla;
std::unordered_set<const Type*> mod_aggrs;
TypeSet mod_aggrs;
for ( auto& a : pf->NonLocalAssignees() )
nla.insert(a);
@ -1210,7 +1210,7 @@ bool ProfileFuncs::AssessSideEffects(const ProfileFunc* pf, IDSet& non_local_ids
}
bool ProfileFuncs::AssessAggrEffects(SideEffectsOp::AccessType access, const Type* t, IDSet& non_local_ids,
std::unordered_set<const Type*>& aggrs, bool& is_unknown) {
TypeSet& aggrs, bool& is_unknown) {
auto assoc_attrs = AssociatedAttrs(t);
for ( auto a : assoc_attrs ) {
@ -1236,7 +1236,7 @@ bool ProfileFuncs::AssessAggrEffects(SideEffectsOp::AccessType access, const Typ
}
bool ProfileFuncs::AssessSideEffects(const SideEffectsOp* se, SideEffectsOp::AccessType access, const Type* t,
IDSet& non_local_ids, std::unordered_set<const Type*>& aggrs) const {
IDSet& non_local_ids, TypeSet& aggrs) const {
if ( se->GetAccessType() != access )
return false;
@ -1273,7 +1273,7 @@ bool ProfileFuncs::IsTableWithDefaultAggr(const Type* t) {
bool ProfileFuncs::GetSideEffects(SideEffectsOp::AccessType access, const Type* t) const {
IDSet nli;
std::unordered_set<const Type*> aggrs;
TypeSet aggrs;
if ( GetSideEffects(access, t, nli, aggrs) )
return true;
@ -1282,7 +1282,7 @@ bool ProfileFuncs::GetSideEffects(SideEffectsOp::AccessType access, const Type*
}
bool ProfileFuncs::GetSideEffects(SideEffectsOp::AccessType access, const Type* t, IDSet& non_local_ids,
std::unordered_set<const Type*>& aggrs) const {
TypeSet& aggrs) const {
for ( auto se : side_effects_ops )
if ( AssessSideEffects(se.get(), access, t, non_local_ids, aggrs) )
return true;
@ -1299,7 +1299,7 @@ std::shared_ptr<SideEffectsOp> ProfileFuncs::GetCallSideEffects(const ScriptFunc
bool is_unknown = false;
IDSet nla;
std::unordered_set<const Type*> mod_aggrs;
TypeSet mod_aggrs;
ASSERT(func_profs.count(sf) != 0);
auto pf = func_profs[sf];
@ -1320,7 +1320,7 @@ std::shared_ptr<SideEffectsOp> ProfileFuncs::GetCallSideEffects(const ScriptFunc
return seo;
}
bool ProfileFuncs::GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, std::unordered_set<const Type*>& aggrs,
bool ProfileFuncs::GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, TypeSet& aggrs,
bool& is_unknown) {
// This occurs when the expression is itself a function name, and
// in an attribute context indicates an implicit call.

View file

@ -94,7 +94,7 @@ public:
const IDSet& WhenLocals() const { return when_locals; }
const IDSet& Params() const { return params; }
const std::unordered_map<const ID*, int>& Assignees() const { return assignees; }
const std::unordered_set<const ID*>& NonLocalAssignees() const { return non_local_assignees; }
const IDSet& NonLocalAssignees() const { return non_local_assignees; }
const auto& TableRefs() const { return tbl_refs; }
const auto& AggrMods() const { return aggr_mods; }
const IDSet& Inits() const { return inits; }
@ -104,7 +104,7 @@ public:
const std::vector<const ConstExpr*>& Constants() const { return constants; }
const IDSet& UnorderedIdentifiers() const { return ids; }
const std::vector<const ID*>& OrderedIdentifiers() const { return ordered_ids; }
const std::unordered_set<const Type*>& UnorderedTypes() const { return types; }
const TypeSet& UnorderedTypes() const { return types; }
const std::vector<const Type*>& OrderedTypes() const { return ordered_types; }
const auto& TypeAliases() const { return type_aliases; }
const std::unordered_set<ScriptFunc*>& ScriptCalls() const { return script_calls; }
@ -187,10 +187,10 @@ protected:
std::unordered_map<const ID*, int> assignees;
// ###
std::unordered_set<const ID*> non_local_assignees;
IDSet non_local_assignees;
std::unordered_set<const Type*> tbl_refs;
std::unordered_set<const Type*> aggr_mods;
TypeSet tbl_refs;
TypeSet aggr_mods;
// Same for locals seen in initializations, so we can find,
// for example, unused aggregates.
@ -226,7 +226,7 @@ protected:
// Types seen in the function. A set rather than a vector because
// the same type can be seen numerous times.
std::unordered_set<const Type*> types;
TypeSet types;
// The same, but in a deterministic order, with duplicates removed.
std::vector<const Type*> ordered_types;
@ -326,12 +326,12 @@ public:
// true = unknown
bool GetSideEffects(SideEffectsOp::AccessType access, const Type* t) const;
bool GetSideEffects(SideEffectsOp::AccessType access, const Type* t, IDSet& non_local_ids,
std::unordered_set<const Type*>& aggrs) const;
TypeSet& aggrs) const;
// Returns nil if side effects are not available. That should never be
// the case after we've done our initial analysis, but is provided
// as a signal so that this method can also be used during that analysis.
bool GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, std::unordered_set<const Type*>& aggrs,
bool GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, TypeSet& aggrs,
bool& is_unknown);
std::shared_ptr<SideEffectsOp> GetCallSideEffects(const ScriptFunc* f);
@ -384,24 +384,24 @@ protected:
void ComputeSideEffects();
void SetSideEffects(const Attr* a, IDSet& non_local_ids, std::unordered_set<const Type*>& aggrs, bool& is_unknown);
void SetSideEffects(const Attr* a, IDSet& non_local_ids, TypeSet& aggrs, bool& is_unknown);
bool DefinitelyHasNoSideEffects(const ExprPtr& e) const;
std::vector<const Attr*> AssociatedAttrs(const Type* t);
// ### False on can't-make-decision-yet
bool AssessSideEffects(const ExprPtr& e, IDSet& non_local_ids, std::unordered_set<const Type*>& types,
bool AssessSideEffects(const ExprPtr& e, IDSet& non_local_ids, TypeSet& types,
bool& is_unknown);
bool AssessSideEffects(const ProfileFunc* e, IDSet& non_local_ids, std::unordered_set<const Type*>& types,
bool AssessSideEffects(const ProfileFunc* e, IDSet& non_local_ids, TypeSet& types,
bool& is_unknown);
bool AssessAggrEffects(SideEffectsOp::AccessType access, const Type* t, IDSet& non_local_ids,
std::unordered_set<const Type*>& aggrs, bool& is_unknown);
TypeSet& aggrs, bool& is_unknown);
// true = is unknown
bool AssessSideEffects(const SideEffectsOp* se, SideEffectsOp::AccessType access, const Type* t,
IDSet& non_local_ids, std::unordered_set<const Type*>& aggrs) const;
IDSet& non_local_ids, TypeSet& aggrs) const;
// Globals seen across the functions, other than those solely seen
// as the function being called in a call.

View file

@ -1069,7 +1069,7 @@ bool CSE_ValidityChecker::CheckCall(const CallExpr* c) const {
return true;
IDSet non_local_ids;
std::unordered_set<const Type*> aggrs;
TypeSet aggrs;
bool is_unknown = false;
auto resolved = pfs.GetCallSideEffects(func->AsNameExpr(), non_local_ids, aggrs, is_unknown);
@ -1080,7 +1080,7 @@ bool CSE_ValidityChecker::CheckCall(const CallExpr* c) const {
bool CSE_ValidityChecker::CheckSideEffects(SideEffectsOp::AccessType access, const TypePtr& t) const {
IDSet non_local_ids;
std::unordered_set<const Type*> aggrs;
TypeSet aggrs;
if ( pfs.GetSideEffects(access, t.get(), non_local_ids, aggrs) )
return true;
@ -1089,7 +1089,7 @@ bool CSE_ValidityChecker::CheckSideEffects(SideEffectsOp::AccessType access, con
}
bool CSE_ValidityChecker::CheckSideEffects(const IDSet& non_local_ids,
const std::unordered_set<const Type*>& aggrs) const {
const TypeSet& aggrs) const {
if ( non_local_ids.empty() && aggrs.empty() )
// This is far and away the most common case.
return false;

View file

@ -357,7 +357,7 @@ protected:
bool CheckTableRef(const TypePtr& t) const;
bool CheckCall(const CallExpr* c) const;
bool CheckSideEffects(SideEffectsOp::AccessType access, const TypePtr& t) const;
bool CheckSideEffects(const IDSet& non_local_ids, const std::unordered_set<const Type*>& aggrs) const;
bool CheckSideEffects(const IDSet& non_local_ids, const TypeSet& aggrs) const;
// Profile across all script functions.
ProfileFuncs& pfs;

View file

@ -18,6 +18,8 @@ struct Options;
namespace zeek::detail {
using TypeSet = std::unordered_set<const Type*>;
// Flags controlling what sorts of analysis to do.
struct AnalyOpt {

View file

@ -25,8 +25,8 @@ public:
void SetUnknownChanges() { has_unknown_changes = true; }
bool HasUnknownChanges() const { return has_unknown_changes; }
void AddModNonGlobal(std::unordered_set<const ID*> ids) { mod_non_locals.insert(ids.begin(), ids.end()); }
void AddModAggrs(std::unordered_set<const Type*> types) { mod_aggrs.insert(types.begin(), types.end()); }
void AddModNonGlobal(IDSet ids) { mod_non_locals.insert(ids.begin(), ids.end()); }
void AddModAggrs(TypeSet types) { mod_aggrs.insert(types.begin(), types.end()); }
const auto& ModNonLocals() const { return mod_non_locals; }
const auto& ModAggrs() const { return mod_aggrs; }
@ -35,8 +35,8 @@ private:
AccessType access;
const Type* type; // type for which some operations alter state
std::unordered_set<const ID*> mod_non_locals;
std::unordered_set<const Type*> mod_aggrs;
IDSet mod_non_locals;
TypeSet mod_aggrs;
bool has_unknown_changes = false;
};

View file

@ -16,8 +16,6 @@ public:
UsageAnalyzer(std::vector<FuncInfo>& funcs);
private:
using IDSet = std::unordered_set<const ID*>;
// Finds the set of identifiers that serve as a starting point of
// what's-known-to-be-used. An identifier qualifies as such if it is
// (1) an event that was newly introduced by scripting (so, known to
@ -67,10 +65,10 @@ private:
// of why the first needs to be per-traversal.
// All of the identifiers we've analyzed during the current traversal.
std::unordered_set<const ID*> analyzed_IDs;
IDSet analyzed_IDs;
// All of the types we've analyzed to date.
std::unordered_set<const Type*> analyzed_types;
TypeSet analyzed_types;
};
// Marks a given identifier as referring to a script-level event (one