From 3a2fe7f98c6ebe6ee6c140f87b3c9cac1c58c463 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Thu, 30 Nov 2023 13:43:28 -0800 Subject: [PATCH] minor simplifying --- src/script_opt/ProfileFunc.cc | 24 ++++++++++++------------ src/script_opt/ProfileFunc.h | 26 +++++++++++++------------- src/script_opt/Reduce.cc | 6 +++--- src/script_opt/Reduce.h | 2 +- src/script_opt/ScriptOpt.h | 2 ++ src/script_opt/SideEffects.h | 8 ++++---- src/script_opt/UsageAnalyzer.h | 6 ++---- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/script_opt/ProfileFunc.cc b/src/script_opt/ProfileFunc.cc index e3818d3c25..925b62b767 100644 --- a/src/script_opt/ProfileFunc.cc +++ b/src/script_opt/ProfileFunc.cc @@ -1019,7 +1019,7 @@ void ProfileFuncs::ComputeSideEffects() { for ( auto c : candidates ) { IDSet non_local_ids; - std::unordered_set 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 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& aggrs, +void ProfileFuncs::SetSideEffects(const Attr* a, IDSet& non_local_ids, TypeSet& aggrs, bool& is_unknown) { auto seo_vec = std::vector>{}; bool is_rec = expr_attrs[a][0]->Tag() == TYPE_RECORD; @@ -1133,7 +1133,7 @@ std::vector ProfileFuncs::AssociatedAttrs(const Type* t) { return assoc_attrs; } -bool ProfileFuncs::AssessSideEffects(const ExprPtr& e, IDSet& non_local_ids, std::unordered_set& aggrs, +bool ProfileFuncs::AssessSideEffects(const ExprPtr& e, IDSet& non_local_ids, TypeSet& aggrs, bool& is_unknown) { std::shared_ptr 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& 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 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& 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& 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 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& 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 ProfileFuncs::GetCallSideEffects(const ScriptFunc bool is_unknown = false; IDSet nla; - std::unordered_set mod_aggrs; + TypeSet mod_aggrs; ASSERT(func_profs.count(sf) != 0); auto pf = func_profs[sf]; @@ -1320,7 +1320,7 @@ std::shared_ptr ProfileFuncs::GetCallSideEffects(const ScriptFunc return seo; } -bool ProfileFuncs::GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, std::unordered_set& 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. diff --git a/src/script_opt/ProfileFunc.h b/src/script_opt/ProfileFunc.h index 2ae051711c..b551b2d787 100644 --- a/src/script_opt/ProfileFunc.h +++ b/src/script_opt/ProfileFunc.h @@ -94,7 +94,7 @@ public: const IDSet& WhenLocals() const { return when_locals; } const IDSet& Params() const { return params; } const std::unordered_map& Assignees() const { return assignees; } - const std::unordered_set& 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& Constants() const { return constants; } const IDSet& UnorderedIdentifiers() const { return ids; } const std::vector& OrderedIdentifiers() const { return ordered_ids; } - const std::unordered_set& UnorderedTypes() const { return types; } + const TypeSet& UnorderedTypes() const { return types; } const std::vector& OrderedTypes() const { return ordered_types; } const auto& TypeAliases() const { return type_aliases; } const std::unordered_set& ScriptCalls() const { return script_calls; } @@ -187,10 +187,10 @@ protected: std::unordered_map assignees; // ### - std::unordered_set non_local_assignees; + IDSet non_local_assignees; - std::unordered_set tbl_refs; - std::unordered_set 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 types; + TypeSet types; // The same, but in a deterministic order, with duplicates removed. std::vector 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& 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& aggrs, + bool GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, TypeSet& aggrs, bool& is_unknown); std::shared_ptr GetCallSideEffects(const ScriptFunc* f); @@ -384,24 +384,24 @@ protected: void ComputeSideEffects(); - void SetSideEffects(const Attr* a, IDSet& non_local_ids, std::unordered_set& 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 AssociatedAttrs(const Type* t); // ### False on can't-make-decision-yet - bool AssessSideEffects(const ExprPtr& e, IDSet& non_local_ids, std::unordered_set& 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& 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& 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& 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. diff --git a/src/script_opt/Reduce.cc b/src/script_opt/Reduce.cc index 2f186c3ac3..1503f62edc 100644 --- a/src/script_opt/Reduce.cc +++ b/src/script_opt/Reduce.cc @@ -1069,7 +1069,7 @@ bool CSE_ValidityChecker::CheckCall(const CallExpr* c) const { return true; IDSet non_local_ids; - std::unordered_set 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 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& aggrs) const { + const TypeSet& aggrs) const { if ( non_local_ids.empty() && aggrs.empty() ) // This is far and away the most common case. return false; diff --git a/src/script_opt/Reduce.h b/src/script_opt/Reduce.h index 7748d7e953..741ca794d5 100644 --- a/src/script_opt/Reduce.h +++ b/src/script_opt/Reduce.h @@ -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& aggrs) const; + bool CheckSideEffects(const IDSet& non_local_ids, const TypeSet& aggrs) const; // Profile across all script functions. ProfileFuncs& pfs; diff --git a/src/script_opt/ScriptOpt.h b/src/script_opt/ScriptOpt.h index 1176990da2..add769cc40 100644 --- a/src/script_opt/ScriptOpt.h +++ b/src/script_opt/ScriptOpt.h @@ -18,6 +18,8 @@ struct Options; namespace zeek::detail { +using TypeSet = std::unordered_set; + // Flags controlling what sorts of analysis to do. struct AnalyOpt { diff --git a/src/script_opt/SideEffects.h b/src/script_opt/SideEffects.h index d37bdd91fd..bf5cd28bfa 100644 --- a/src/script_opt/SideEffects.h +++ b/src/script_opt/SideEffects.h @@ -25,8 +25,8 @@ public: void SetUnknownChanges() { has_unknown_changes = true; } bool HasUnknownChanges() const { return has_unknown_changes; } - void AddModNonGlobal(std::unordered_set ids) { mod_non_locals.insert(ids.begin(), ids.end()); } - void AddModAggrs(std::unordered_set 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 mod_non_locals; - std::unordered_set mod_aggrs; + IDSet mod_non_locals; + TypeSet mod_aggrs; bool has_unknown_changes = false; }; diff --git a/src/script_opt/UsageAnalyzer.h b/src/script_opt/UsageAnalyzer.h index 2c74595a47..d02e112c52 100644 --- a/src/script_opt/UsageAnalyzer.h +++ b/src/script_opt/UsageAnalyzer.h @@ -16,8 +16,6 @@ public: UsageAnalyzer(std::vector& funcs); private: - using IDSet = std::unordered_set; - // 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 analyzed_IDs; + IDSet analyzed_IDs; // All of the types we've analyzed to date. - std::unordered_set analyzed_types; + TypeSet analyzed_types; }; // Marks a given identifier as referring to a script-level event (one