For performance, use unordered_set/map where possible. No functional change intended.

This commit is contained in:
Wilson Snyder 2020-11-25 20:57:30 -05:00
parent 085ef5fc05
commit f2d8e45d72
22 changed files with 34 additions and 28 deletions

View File

@ -32,6 +32,7 @@
#include <memory>
#include <set>
#include <string>
#include <unordered_set>
//===================================================================
// String formatters (required by below containers)
@ -267,7 +268,7 @@ public:
void shuffle() { std::shuffle(m_deque.begin(), m_deque.end(), VlURNG()); }
VlQueue unique() const {
VlQueue out;
std::set<T_Value> saw;
std::unordered_set<T_Value> saw;
for (const auto& i : m_deque) {
auto it = saw.find(i);
if (it == saw.end()) {
@ -280,7 +281,7 @@ public:
VlQueue<IData> unique_index() const {
VlQueue<IData> out;
IData index = 0;
std::set<T_Value> saw;
std::unordered_set<T_Value> saw;
for (const auto& i : m_deque) {
auto it = saw.find(i);
if (it == saw.end()) {

View File

@ -31,6 +31,7 @@
#include "verilated_sym_props.h"
#include <map>
#include <unordered_map>
#include <vector>
//======================================================================
@ -58,7 +59,8 @@ public:
typedef std::vector<const VerilatedScope*> VerilatedScopeVector;
class VerilatedHierarchyMap final : public std::map<const VerilatedScope*, VerilatedScopeVector> {
class VerilatedHierarchyMap final
: public std::unordered_map<const VerilatedScope*, VerilatedScopeVector> {
public:
VerilatedHierarchyMap() = default;
~VerilatedHierarchyMap() = default;

View File

@ -497,7 +497,7 @@ public:
assertOneCheck();
VpioCbList& cbObjList = s_s.m_cbObjLists[cbValueChange];
bool called = false;
typedef std::set<VerilatedVpioVar*> VpioVarSet;
typedef std::unordered_set<VerilatedVpioVar*> VpioVarSet;
VpioVarSet update; // set of objects to update after callbacks
if (cbObjList.empty()) return called;
const auto last = std::prev(cbObjList.end()); // prevent looping over newly added elements

View File

@ -98,7 +98,7 @@ private:
typedef std::map<const std::pair<AstNodeModule*, string>, AstVar*> VarMap;
VarMap m_modVarMap; // Table of new var names created under module
VDouble0 m_statSharedSet; // Statistic tracking
typedef std::map<const AstVarScope*, int> ScopeVecMap;
typedef std::unordered_map<const AstVarScope*, int> ScopeVecMap;
ScopeVecMap m_scopeVecMap; // Next var number for each scope
// METHODS

View File

@ -109,7 +109,7 @@ class EmitCSyms final : EmitCBaseVisitor {
int m_numStmts = 0; // Number of statements output
int m_funcNum = 0; // CFunc split function number
V3OutCFile* m_ofpBase = nullptr; // Base (not split) C file
std::map<int, bool> m_usesVfinal; // Split method uses __Vfinal
std::unordered_map<int, bool> m_usesVfinal; // Split method uses __Vfinal
// METHODS
void emitSymHdr();

View File

@ -906,7 +906,7 @@ void GateVisitor::optimizeElimVar(AstVarScope* varscp, AstNode* substp, AstNode*
class GateDedupeHash final : public V3HashedUserSame {
public:
// TYPES
typedef std::set<AstNode*> NodeSet;
typedef std::unordered_set<AstNode*> NodeSet;
private:
// NODE STATE

View File

@ -335,7 +335,7 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const {
// We use a map here, as we don't want to corrupt anything (userp) in the graph,
// and we don't care if this is slow.
std::map<const V3GraphVertex*, int> numMap;
std::unordered_map<const V3GraphVertex*, int> numMap;
// Print vertices
int n = 0;

View File

@ -294,7 +294,7 @@ private:
UINFO(9, " On dfaState " << dfaStatep << endl);
// From this dfaState, what corresponding nfaStates have what inputs?
std::set<int> inputs;
std::unordered_set<int> inputs;
// Foreach NFA state (this DFA state was formed from)
for (V3GraphEdge* dfaEdgep = dfaStatep->outBeginp(); dfaEdgep;
dfaEdgep = dfaEdgep->outNextp()) {

View File

@ -81,7 +81,7 @@ private:
};
typedef std::set<VxHolder, VxHolderCmp&> ReadyVertices;
typedef std::unordered_map<const V3GraphVertex*, VxHolder> WaitingVertices;
typedef std::map<const V3GraphVertex*, VxHolder> WaitingVertices;
// MEMBERS
VxHolderCmp m_vxHolderCmp; // Vertext comparison functor

View File

@ -153,7 +153,7 @@ void V3Hashed::dumpFile(const string& filename, bool tree) {
const std::unique_ptr<std::ofstream> logp(V3File::new_ofstream(filename));
if (logp->fail()) v3fatal("Can't write " << filename);
std::map<int, int> dist;
std::unordered_map<int, int> dist;
V3Hash lasthash;
int num_in_bucket = 0;

View File

@ -240,7 +240,7 @@ class HierBlockUsageCollectVisitor final : public AstNVisitor {
AstUser1InUse m_inuser1;
// STATE
typedef std::set<const AstModule*> ModuleSet;
typedef std::unordered_set<const AstModule*> ModuleSet;
V3HierBlockPlan* const m_planp;
AstModule* m_modp = nullptr; // The current module
AstModule* m_hierBlockp = nullptr; // The nearest parent module that is a hierarchical block
@ -355,7 +355,8 @@ void V3HierBlockPlan::createPlan(AstNetlist* nodep) {
}
V3HierBlockPlan::HierVector V3HierBlockPlan::hierBlocksSorted() const {
typedef std::map<const V3HierBlock*, std::set<const V3HierBlock*>> ChildrenMap;
typedef std::unordered_map<const V3HierBlock*, std::unordered_set<const V3HierBlock*>>
ChildrenMap;
ChildrenMap childrenOfHierBlock;
HierVector sorted;

View File

@ -29,6 +29,7 @@
#include <set>
#include <string>
#include <utility>
#include <unordered_set>
#include <vector>
class AstNodeModule;
@ -40,8 +41,8 @@ class AstVar;
class V3HierBlock final {
public:
typedef std::vector<AstVar*> GParams;
typedef std::set<V3HierBlock*> HierBlockSet;
typedef std::set<const AstNodeModule*> NodeModuleSet;
typedef std::unordered_set<V3HierBlock*> HierBlockSet;
typedef std::unordered_set<const AstNodeModule*> NodeModuleSet;
private:
// TYPES
@ -96,7 +97,7 @@ public:
// Holds relashonship between AstNodeModule and V3HierBlock
class V3HierBlockPlan final {
typedef std::map<const AstNodeModule*, V3HierBlock*> HierMap;
typedef std::unordered_map<const AstNodeModule*, V3HierBlock*> HierMap;
HierMap m_blocks;
V3HierBlockPlan() = default;

View File

@ -74,10 +74,10 @@ private:
// Within the context of a given module, LocalInstanceMap maps
// from child modules to the count of each child's local instantiations.
typedef std::map<AstNodeModule*, int> LocalInstanceMap;
typedef std::unordered_map<AstNodeModule*, int> LocalInstanceMap;
// We keep a LocalInstanceMap for each module in the design
std::map<AstNodeModule*, LocalInstanceMap> m_instances;
std::unordered_map<AstNodeModule*, LocalInstanceMap> m_instances;
// METHODS
VL_DEBUG_FUNC; // Declare debug()

View File

@ -123,7 +123,7 @@ class LifeBlock final {
// LIFE MAP
// For each basic block, we'll make a new map of what variables that if/else is changing
typedef std::map<AstVarScope*, LifeVarEntry> LifeMap;
typedef std::unordered_map<AstVarScope*, LifeVarEntry> LifeMap;
LifeMap m_map; // Current active lifetime map for current scope
LifeBlock* m_aboveLifep; // Upper life, or nullptr
LifeState* m_statep; // Current global state
@ -278,7 +278,7 @@ private:
// LIFE MAP
// For each basic block, we'll make a new map of what variables that if/else is changing
typedef std::map<AstVarScope*, LifeVarEntry> LifeMap;
typedef std::unordered_map<AstVarScope*, LifeVarEntry> LifeMap;
// cppcheck-suppress memleak // cppcheck bug - it is deleted
LifeBlock* m_lifep; // Current active lifetime map for current scope

View File

@ -141,7 +141,7 @@ public:
private:
// TYPES
typedef std::multimap<string, VSymEnt*> NameScopeSymMap;
typedef std::map<VSymEnt*, VSymEnt*> ScopeAliasMap;
typedef std::unordered_map<VSymEnt*, VSymEnt*> ScopeAliasMap;
typedef std::set<std::pair<AstNodeModule*, string>> ImplicitNameSet;
typedef std::vector<VSymEnt*> IfaceVarSyms;
typedef std::vector<std::pair<AstIface*, VSymEnt*>> IfaceModSyms;

View File

@ -45,7 +45,7 @@ private:
// TYPES
typedef std::map<const std::pair<void*, string>, AstTypedef*> ImplTypedefMap;
typedef std::set<FileLine*> FileLineSet;
typedef std::unordered_set<FileLine*> FileLineSet;
// STATE
AstVar* m_varp = nullptr; // Variable we're under

View File

@ -216,7 +216,7 @@ private:
typedef std::deque<std::pair<AstIfaceRefDType*, AstIfaceRefDType*>> IfaceRefRefs;
// STATE
typedef std::map<const AstNode*, AstNode*> CloneMap;
typedef std::unordered_map<const AstNode*, AstNode*> CloneMap;
struct ModInfo {
AstNodeModule* m_modp; // Module with specified name
CloneMap m_cloneMap; // Map of old-varp -> new cloned varp

View File

@ -61,7 +61,7 @@ public:
};
typedef std::deque<AstConst*> ConstDeque;
typedef std::map<const AstNodeDType*, ConstDeque> ConstPile;
typedef std::unordered_map<const AstNodeDType*, ConstDeque> ConstPile;
class SimulateVisitor VL_NOT_FINAL : public AstNVisitor {
// Simulate a node tree, returning value of variables

View File

@ -23,8 +23,9 @@
// No V3 headers here - this is a base class for Vlc etc
#include <map>
#include <string>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
//######################################################################

View File

@ -36,7 +36,7 @@ class VSymEnt;
//######################################################################
// Symbol table
typedef std::set<const VSymEnt*> VSymConstMap;
typedef std::unordered_set<const VSymEnt*> VSymConstMap;
class VSymEnt final {
// Symbol table that can have a "superior" table for resolving upper references

View File

@ -104,7 +104,7 @@ private:
// TYPES
typedef std::map<std::pair<AstScope*, AstVar*>, AstVarScope*> VarToScopeMap;
typedef std::map<const AstNodeFTask*, AstClass*> FuncToClassMap;
typedef std::unordered_map<const AstNodeFTask*, AstClass*> FuncToClassMap;
typedef std::vector<AstInitial*> Initials;
// MEMBERS
VarToScopeMap m_varToScopeMap; // Map for Var -> VarScope mappings

View File

@ -329,7 +329,7 @@ class TristateVisitor final : public TristateBaseVisitor {
// TYPES
typedef std::vector<AstVarRef*> RefVec;
typedef std::map<AstVar*, RefVec*> VarMap;
typedef std::unordered_map<AstVar*, RefVec*> VarMap;
enum : uint8_t {
U2_GRAPHING = 1, // bit[0] if did m_graphing visit
U2_NONGRAPH = 2, // bit[1] if did !m_graphing visit