Internals: More use of unordered_map/set. No functional change intended.

This commit is contained in:
Wilson Snyder 2017-10-18 18:22:58 -04:00
parent fbbbe4ec87
commit cc0b780412
18 changed files with 36 additions and 29 deletions

View File

@ -112,15 +112,15 @@
# define VL_HAS_UNIQUE_PTR # define VL_HAS_UNIQUE_PTR
# define VL_HAS_UNORDERED_MAP # define VL_HAS_UNORDERED_MAP
# define VL_HAS_UNORDERED_SET # define VL_HAS_UNORDERED_SET
# define VL_UNIQUE_PTR std::unique_ptr # define vl_unique_ptr std::unique_ptr
# define VL_UNORDERED_MAP std::unordered_map # define vl_unordered_map std::unordered_map
# define VL_UNORDERED_SET std::unordered_set # define vl_unordered_set std::unordered_set
# define VL_INCLUDE_UNORDERED_MAP <unordered_map> # define VL_INCLUDE_UNORDERED_MAP <unordered_map>
# define VL_INCLUDE_UNORDERED_SET <unordered_set> # define VL_INCLUDE_UNORDERED_SET <unordered_set>
#else #else
# define VL_UNIQUE_PTR std::auto_ptr # define vl_unique_ptr std::auto_ptr
# define VL_UNORDERED_MAP std::map # define vl_unordered_map std::map
# define VL_UNORDERED_SET std::set # define vl_unordered_set std::set
# define VL_INCLUDE_UNORDERED_MAP <map> # define VL_INCLUDE_UNORDERED_MAP <map>
# define VL_INCLUDE_UNORDERED_SET <set> # define VL_INCLUDE_UNORDERED_SET <set>
#endif #endif

View File

@ -1037,7 +1037,7 @@ void AstNode::dumpTreeFile(const string& filename, bool append, bool doDump) {
if (doDump) { if (doDump) {
{ // Write log & close { // Write log & close
UINFO(2,"Dumping "<<filename<<endl); UINFO(2,"Dumping "<<filename<<endl);
const VL_UNIQUE_PTR<ofstream> logsp (V3File::new_ofstream(filename, append)); const vl_unique_ptr<ofstream> logsp (V3File::new_ofstream(filename, append));
if (logsp->fail()) v3fatalSrc("Can't write "<<filename); if (logsp->fail()) v3fatalSrc("Can't write "<<filename);
*logsp<<"Verilator Tree Dump (format 0x3900) from <e"<<dec<<editCountLast()<<">"; *logsp<<"Verilator Tree Dump (format 0x3900) from <e"<<dec<<editCountLast()<<">";
*logsp<<" to <e"<<dec<<editCountGbl()<<">"<<endl; *logsp<<" to <e"<<dec<<editCountGbl()<<">"<<endl;

View File

@ -26,6 +26,7 @@
#include <iomanip> #include <iomanip>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include VL_INCLUDE_UNORDERED_SET
#include "V3Ast.h" #include "V3Ast.h"
#include "V3File.h" #include "V3File.h"
@ -69,7 +70,7 @@ void AstNodeClassDType::repairMemberCache() {
} }
const char* AstNodeClassDType::broken() const { const char* AstNodeClassDType::broken() const {
set<AstMemberDType*> exists; vl_unordered_set<AstMemberDType*> exists;
for (AstMemberDType* itemp = membersp(); itemp; itemp=itemp->nextp()->castMemberDType()) { for (AstMemberDType* itemp = membersp(); itemp; itemp=itemp->nextp()->castMemberDType()) {
exists.insert(itemp); exists.insert(itemp);
} }

View File

@ -47,7 +47,7 @@ class BrokenTable : public AstNVisitor {
private: private:
// MEMBERS // MEMBERS
// For each node, we keep if it exists or not. // For each node, we keep if it exists or not.
typedef VL_UNORDERED_MAP<const AstNode*,int> NodeMap; // Performance matters (when --debug) typedef vl_unordered_map<const AstNode*,int> NodeMap; // Performance matters (when --debug)
static NodeMap s_nodes; // Set of all nodes that exist static NodeMap s_nodes; // Set of all nodes that exist
// BITMASK // BITMASK
enum { FLAG_ALLOCATED = 0x01 }; // new() and not delete()ed enum { FLAG_ALLOCATED = 0x01 }; // new() and not delete()ed

View File

@ -496,7 +496,7 @@ private:
} }
string filename = v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"__cdc_edges.txt"; string filename = v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"__cdc_edges.txt";
const VL_UNIQUE_PTR<ofstream> ofp (V3File::new_ofstream(filename)); const vl_unique_ptr<ofstream> ofp (V3File::new_ofstream(filename));
if (ofp->fail()) v3fatalSrc("Can't write "<<filename); if (ofp->fail()) v3fatalSrc("Can't write "<<filename);
*ofp<<"Edge Report for "<<v3Global.opt.prefix()<<endl; *ofp<<"Edge Report for "<<v3Global.opt.prefix()<<endl;

View File

@ -1882,7 +1882,7 @@ void EmitCImp::emitInt(AstNodeModule* modp) {
// Declare foreign instances up front to make C++ happy // Declare foreign instances up front to make C++ happy
puts("class "+symClassName()+";\n"); puts("class "+symClassName()+";\n");
VL_UNORDERED_SET<string> didClassName; vl_unordered_set<string> didClassName;
for (AstNode* nodep=modp->stmtsp(); nodep; nodep = nodep->nextp()) { for (AstNode* nodep=modp->stmtsp(); nodep; nodep = nodep->nextp()) {
if (AstCell* cellp=nodep->castCell()) { if (AstCell* cellp=nodep->castCell()) {
string className = modClassName(cellp->modp()); string className = modClassName(cellp->modp());

View File

@ -134,7 +134,7 @@ V3FileDependImp dependImp; // Depend implementation class
// V3FileDependImp // V3FileDependImp
inline void V3FileDependImp::writeDepend(const string& filename) { inline void V3FileDependImp::writeDepend(const string& filename) {
const VL_UNIQUE_PTR<ofstream> ofp (V3File::new_ofstream(filename)); const vl_unique_ptr<ofstream> ofp (V3File::new_ofstream(filename));
if (ofp->fail()) v3fatalSrc("Can't write "<<filename); if (ofp->fail()) v3fatalSrc("Can't write "<<filename);
for (set<DependFile>::iterator iter=m_filenameList.begin(); for (set<DependFile>::iterator iter=m_filenameList.begin();
@ -170,7 +170,7 @@ inline void V3FileDependImp::writeDepend(const string& filename) {
} }
inline void V3FileDependImp::writeTimes(const string& filename, const string& cmdlineIn) { inline void V3FileDependImp::writeTimes(const string& filename, const string& cmdlineIn) {
const VL_UNIQUE_PTR<ofstream> ofp (V3File::new_ofstream(filename)); const vl_unique_ptr<ofstream> ofp (V3File::new_ofstream(filename));
if (ofp->fail()) v3fatalSrc("Can't write "<<filename); if (ofp->fail()) v3fatalSrc("Can't write "<<filename);
string cmdline = stripQuotes(cmdlineIn); string cmdline = stripQuotes(cmdlineIn);
@ -200,7 +200,7 @@ inline void V3FileDependImp::writeTimes(const string& filename, const string& cm
} }
inline bool V3FileDependImp::checkTimes(const string& filename, const string& cmdlineIn) { inline bool V3FileDependImp::checkTimes(const string& filename, const string& cmdlineIn) {
const VL_UNIQUE_PTR<ifstream> ifp (V3File::new_ifstream_nodepend(filename)); const vl_unique_ptr<ifstream> ifp (V3File::new_ifstream_nodepend(filename));
if (ifp->fail()) { if (ifp->fail()) {
UINFO(2," --check-times failed: no input "<<filename<<endl); UINFO(2," --check-times failed: no input "<<filename<<endl);
return false; return false;

View File

@ -18,10 +18,13 @@
// //
//************************************************************************* //*************************************************************************
#include "config_build.h"
#include "verilatedos.h"
#include <cstdio> #include <cstdio>
#include <cstdarg> #include <cstdarg>
#include <cstring> #include <cstring>
#include <set> #include VL_INCLUDE_UNORDERED_SET
#include "V3Error.h" #include "V3Error.h"
#include "V3FileLine.h" #include "V3FileLine.h"
#ifndef _V3ERROR_NO_GLOBAL_ #ifndef _V3ERROR_NO_GLOBAL_
@ -254,7 +257,7 @@ string FileLine::warnMore() const {
} }
#ifdef VL_LEAK_CHECKS #ifdef VL_LEAK_CHECKS
typedef set<FileLine*> FileLineCheckSet; typedef vl_unordered_set<FileLine*> FileLineCheckSet;
FileLineCheckSet fileLineLeakChecks; FileLineCheckSet fileLineLeakChecks;
void* FileLine::operator new(size_t size) { void* FileLine::operator new(size_t size) {

View File

@ -35,6 +35,7 @@
#include <vector> #include <vector>
#include <list> #include <list>
#include <map> #include <map>
#include VL_INCLUDE_UNORDERED_SET
#include "V3Global.h" #include "V3Global.h"
#include "V3Gate.h" #include "V3Gate.h"
@ -668,7 +669,7 @@ void GateVisitor::optimizeSignals(bool allowMultiIn) {
bool GateVisitor::elimLogicOkOutputs(GateLogicVertex* consumeVertexp, const GateOkVisitor& okVisitor) { bool GateVisitor::elimLogicOkOutputs(GateLogicVertex* consumeVertexp, const GateOkVisitor& okVisitor) {
// Return true if can optimize // Return true if can optimize
// Return false if the consuming logic has an output signal that the replacement logic has as an input // Return false if the consuming logic has an output signal that the replacement logic has as an input
typedef set<AstVarScope*> VarScopeSet; typedef vl_unordered_set<AstVarScope*> VarScopeSet;
// Use map to find duplicates between two lists // Use map to find duplicates between two lists
VarScopeSet varscopes; VarScopeSet varscopes;
// Replacement logic usually has shorter input list, so faster to build list based on it // Replacement logic usually has shorter input list, so faster to build list based on it

View File

@ -288,7 +288,7 @@ void V3Graph::dumpDotFilePrefixedAlways(const string& nameComment, bool colorAsS
void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) { void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) {
// This generates a file used by graphviz, http://www.graphviz.org // This generates a file used by graphviz, http://www.graphviz.org
// "hardcoded" parameters: // "hardcoded" parameters:
const VL_UNIQUE_PTR<ofstream> logp (V3File::new_ofstream(filename)); const vl_unique_ptr<ofstream> logp (V3File::new_ofstream(filename));
if (logp->fail()) v3fatalSrc("Can't write "<<filename); if (logp->fail()) v3fatalSrc("Can't write "<<filename);
// Header // Header

View File

@ -141,7 +141,7 @@ void V3Hashed::dumpFilePrefixed(const string& nameComment, bool tree) {
} }
void V3Hashed::dumpFile(const string& filename, bool tree) { void V3Hashed::dumpFile(const string& filename, bool tree) {
const VL_UNIQUE_PTR<ofstream> logp (V3File::new_ofstream(filename)); const vl_unique_ptr<ofstream> logp (V3File::new_ofstream(filename));
if (logp->fail()) v3fatalSrc("Can't write "<<filename); if (logp->fail()) v3fatalSrc("Can't write "<<filename);
map<int,int> dist; map<int,int> dist;

View File

@ -35,6 +35,7 @@
#include <map> #include <map>
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include VL_INCLUDE_UNORDERED_SET
#include "V3Global.h" #include "V3Global.h"
#include "V3LinkCells.h" #include "V3LinkCells.h"
@ -105,7 +106,7 @@ private:
LinkCellsGraph m_graph; // Linked graph of all cell interconnects LinkCellsGraph m_graph; // Linked graph of all cell interconnects
LibraryVertex* m_libVertexp; // Vertex at root of all libraries LibraryVertex* m_libVertexp; // Vertex at root of all libraries
V3GraphVertex* m_topVertexp; // Vertex of top module V3GraphVertex* m_topVertexp; // Vertex of top module
set<string> m_declfnWarned; // Files we issued DECLFILENAME on vl_unordered_set<string> m_declfnWarned; // Files we issued DECLFILENAME on
static int debug() { static int debug() {
static int level = -1; static int level = -1;
@ -311,7 +312,7 @@ private:
} }
if (nodep->modp()) { if (nodep->modp()) {
// Note what pins exist // Note what pins exist
set<string> ports; // Symbol table of all connected port names vl_unordered_set<string> ports; // Symbol table of all connected port names
for (AstPin* pinp = nodep->pinsp(); pinp; pinp=pinp->nextp()->castPin()) { for (AstPin* pinp = nodep->pinsp(); pinp; pinp=pinp->nextp()->castPin()) {
if (pinp->name()=="") pinp->v3error("Connect by position is illegal in .* connected cells"); if (pinp->name()=="") pinp->v3error("Connect by position is illegal in .* connected cells");
if (!pinp->exprp()) { if (!pinp->exprp()) {

View File

@ -134,7 +134,7 @@ public:
void dump(const string& nameComment="linkdot", bool force=false) { void dump(const string& nameComment="linkdot", bool force=false) {
if (debug()>=6 || force) { if (debug()>=6 || force) {
string filename = v3Global.debugFilename(nameComment)+".txt"; string filename = v3Global.debugFilename(nameComment)+".txt";
const VL_UNIQUE_PTR<ofstream> logp (V3File::new_ofstream(filename)); const vl_unique_ptr<ofstream> logp (V3File::new_ofstream(filename));
if (logp->fail()) v3fatalSrc("Can't write "<<filename); if (logp->fail()) v3fatalSrc("Can't write "<<filename);
ostream& os = *logp; ostream& os = *logp;
m_syms.dump(os); m_syms.dump(os);

View File

@ -1047,7 +1047,7 @@ void V3Options::parseOptsFile(FileLine* fl, const string& filename, bool rel) {
// Read the specified -f filename and process as arguments // Read the specified -f filename and process as arguments
UINFO(1,"Reading Options File "<<filename<<endl); UINFO(1,"Reading Options File "<<filename<<endl);
const VL_UNIQUE_PTR<ifstream> ifp (V3File::new_ifstream(filename)); const vl_unique_ptr<ifstream> ifp (V3File::new_ifstream(filename));
if (ifp->fail()) { if (ifp->fail()) {
fl->v3error("Cannot open -f command file: "+filename); fl->v3error("Cannot open -f command file: "+filename);
return; return;

View File

@ -1286,7 +1286,7 @@ void OrderVisitor::processDomainsIterate(OrderEitherVertex* vertexp) {
void OrderVisitor::processEdgeReport() { void OrderVisitor::processEdgeReport() {
// Make report of all signal names and what clock edges they have // Make report of all signal names and what clock edges they have
string filename = v3Global.debugFilename("order_edges.txt"); string filename = v3Global.debugFilename("order_edges.txt");
const VL_UNIQUE_PTR<ofstream> logp (V3File::new_ofstream(filename)); const vl_unique_ptr<ofstream> logp (V3File::new_ofstream(filename));
if (logp->fail()) v3fatalSrc("Can't write "<<filename); if (logp->fail()) v3fatalSrc("Can't write "<<filename);
//Testing emitter: V3EmitV::verilogForTree(v3Global.rootp(), *logp); //Testing emitter: V3EmitV::verilogForTree(v3Global.rootp(), *logp);
@ -1605,7 +1605,7 @@ void OrderVisitor::process() {
m_graph.dumpDotFilePrefixed("orderg_done"); m_graph.dumpDotFilePrefixed("orderg_done");
if (0 && debug()) { if (0 && debug()) {
string dfilename = v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"_INT_order"; string dfilename = v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"_INT_order";
const VL_UNIQUE_PTR<ofstream> logp (V3File::new_ofstream(dfilename)); const vl_unique_ptr<ofstream> logp (V3File::new_ofstream(dfilename));
if (logp->fail()) v3fatalSrc("Can't write "<<dfilename); if (logp->fail()) v3fatalSrc("Can't write "<<dfilename);
m_graph.dump(*logp); m_graph.dump(*logp);
} }

View File

@ -25,6 +25,7 @@
#include <unistd.h> #include <unistd.h>
#include <map> #include <map>
#include <iomanip> #include <iomanip>
#include VL_INCLUDE_UNORDERED_MAP
#include "V3Global.h" #include "V3Global.h"
#include "V3Stats.h" #include "V3Stats.h"
@ -122,7 +123,7 @@ class StatsReport {
size_t maxWidth = 0; size_t maxWidth = 0;
typedef vector<string> Stages; typedef vector<string> Stages;
Stages stages; Stages stages;
map<string,int> stageInt; vl_unordered_map<string,int> stageInt;
typedef multimap<string,const V3Statistic*> ByName; typedef multimap<string,const V3Statistic*> ByName;
ByName byName; ByName byName;
// * is always first // * is always first

View File

@ -275,7 +275,7 @@ public:
if (v3Global.opt.dumpTree()) { if (v3Global.opt.dumpTree()) {
string filename = v3Global.debugFilename(nameComment)+".txt"; string filename = v3Global.debugFilename(nameComment)+".txt";
UINFO(2,"Dumping "<<filename<<endl); UINFO(2,"Dumping "<<filename<<endl);
const VL_UNIQUE_PTR<ofstream> logp (V3File::new_ofstream(filename)); const vl_unique_ptr<ofstream> logp (V3File::new_ofstream(filename));
if (logp->fail()) v3fatalSrc("Can't write "<<filename); if (logp->fail()) v3fatalSrc("Can't write "<<filename);
dump(*logp, ""); dump(*logp, "");
} }

View File

@ -24,9 +24,9 @@
#include "config_build.h" #include "config_build.h"
#include "verilatedos.h" #include "verilatedos.h"
#include "verilated_cov_key.h" #include "verilated_cov_key.h"
#include <map>
#include <vector> #include <vector>
#include <iomanip> #include <iomanip>
#include VL_INCLUDE_UNORDERED_MAP
//******************************************************************** //********************************************************************
// VlcPoint - A coverage point (across all tests) // VlcPoint - A coverage point (across all tests)
@ -98,7 +98,7 @@ public:
class VlcPoints { class VlcPoints {
private: private:
// MEMBERS // MEMBERS
typedef std::map<string,vluint64_t> NameMap; typedef vl_unordered_map<string,vluint64_t> NameMap;
NameMap m_nameMap; //< Name to point-number NameMap m_nameMap; //< Name to point-number
vector<VlcPoint> m_points; //< List of all points vector<VlcPoint> m_points; //< List of all points
vluint64_t m_numPoints; //< Total unique points vluint64_t m_numPoints; //< Total unique points