Dramatically improve NetScope child lookup.
In physical models, there are often very many child scopes in any given scope. The lookup for child scope needs to be optimized.
This commit is contained in:
parent
26ab32ac3b
commit
b1d9d1bda2
22
HName.cc
22
HName.cc
|
|
@ -58,25 +58,6 @@ hname_t& hname_t::operator = (const hname_t&that)
|
|||
return *this;
|
||||
}
|
||||
|
||||
hname_t::~hname_t()
|
||||
{
|
||||
}
|
||||
|
||||
perm_string hname_t::peek_name(void) const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
bool hname_t::has_number() const
|
||||
{
|
||||
return number_ != INT_MIN;
|
||||
}
|
||||
|
||||
int hname_t::peek_number() const
|
||||
{
|
||||
return number_;
|
||||
}
|
||||
|
||||
bool operator < (const hname_t&l, const hname_t&r)
|
||||
{
|
||||
int cmp = strcmp(l.peek_name(), r.peek_name());
|
||||
|
|
@ -100,9 +81,6 @@ bool operator == (const hname_t&l, const hname_t&r)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool operator != (const hname_t&l, const hname_t&r)
|
||||
{ return ! (l==r); }
|
||||
|
||||
ostream& operator<< (ostream&out, const hname_t&that)
|
||||
{
|
||||
if (that.peek_name() == 0) {
|
||||
|
|
|
|||
23
HName.h
23
HName.h
|
|
@ -63,11 +63,32 @@ class hname_t {
|
|||
private: // not implemented
|
||||
};
|
||||
|
||||
inline hname_t::~hname_t()
|
||||
{
|
||||
}
|
||||
|
||||
inline perm_string hname_t::peek_name(void) const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
inline int hname_t::peek_number() const
|
||||
{
|
||||
return number_;
|
||||
}
|
||||
|
||||
inline bool hname_t::has_number() const
|
||||
{
|
||||
return number_ != INT_MIN;
|
||||
}
|
||||
|
||||
extern bool operator < (const hname_t&, const hname_t&);
|
||||
extern bool operator == (const hname_t&, const hname_t&);
|
||||
extern bool operator != (const hname_t&, const hname_t&);
|
||||
extern ostream& operator<< (ostream&, const hname_t&);
|
||||
|
||||
inline bool operator != (const hname_t&l, const hname_t&r)
|
||||
{ return ! (l == r); }
|
||||
|
||||
inline ostream& operator<< (ostream&out, const list<hname_t>&ll)
|
||||
{
|
||||
list<hname_t>::const_iterator cur = ll.begin();
|
||||
|
|
|
|||
|
|
@ -1222,8 +1222,9 @@ void NetScope::dump(ostream&o) const
|
|||
}
|
||||
|
||||
/* Dump any sub-scopes. */
|
||||
for (NetScope*cur = sub_ ; cur ; cur = cur->sib_)
|
||||
cur->dump(o);
|
||||
for (map<hname_t,NetScope*>::const_iterator cur = children_.begin()
|
||||
; cur != children_.end() ; cur ++)
|
||||
cur->second->dump(o);
|
||||
}
|
||||
|
||||
void NetSTask::dump(ostream&o, unsigned ind) const
|
||||
|
|
|
|||
15
emit.cc
15
emit.cc
|
|
@ -380,8 +380,9 @@ void NetScope::emit_scope(struct target_t*tgt) const
|
|||
for (NetEvent*cur = events_ ; cur ; cur = cur->snext_)
|
||||
tgt->event(cur);
|
||||
|
||||
for (NetScope*cur = sub_ ; cur ; cur = cur->sib_)
|
||||
cur->emit_scope(tgt);
|
||||
for (map<hname_t,NetScope*>::const_iterator cur = children_.begin()
|
||||
; cur != children_.end() ; cur ++)
|
||||
cur->second->emit_scope(tgt);
|
||||
|
||||
for (signals_map_iter_t cur = signals_map_.begin()
|
||||
; cur != signals_map_.end() ; cur ++) {
|
||||
|
|
@ -407,8 +408,9 @@ bool NetScope::emit_defs(struct target_t*tgt) const
|
|||
|
||||
switch (type_) {
|
||||
case MODULE:
|
||||
for (NetScope*cur = sub_ ; cur ; cur = cur->sib_)
|
||||
flag &= cur->emit_defs(tgt);
|
||||
for (map<hname_t,NetScope*>::const_iterator cur = children_.begin()
|
||||
; cur != children_.end() ; cur ++)
|
||||
flag &= cur->second->emit_defs(tgt);
|
||||
break;
|
||||
|
||||
case FUNC:
|
||||
|
|
@ -418,8 +420,9 @@ bool NetScope::emit_defs(struct target_t*tgt) const
|
|||
tgt->task_def(this);
|
||||
break;
|
||||
default: /* BEGIN_END and FORK_JOIN, GENERATE... */
|
||||
for (NetScope*cur = sub_ ; cur ; cur = cur->sib_)
|
||||
flag &= cur->emit_defs(tgt);
|
||||
for (map<hname_t,NetScope*>::const_iterator cur = children_.begin()
|
||||
; cur != children_.end() ; cur ++)
|
||||
flag &= cur->second->emit_defs(tgt);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,9 +99,9 @@ void functor_t::lpm_ureduce(class Design*, class NetUReduce*)
|
|||
|
||||
void NetScope::run_functor(Design*des, functor_t*fun)
|
||||
{
|
||||
for (NetScope*cur = sub_ ; cur ; cur = cur->sib_) {
|
||||
cur->run_functor(des, fun);
|
||||
}
|
||||
for (map<hname_t,NetScope*>::const_iterator cur = children_.begin()
|
||||
; cur != children_.end() ; cur ++)
|
||||
cur->second->run_functor(des, fun);
|
||||
|
||||
for (NetEvent*cur = events_ ; cur ; /* */) {
|
||||
NetEvent*tmp = cur;
|
||||
|
|
|
|||
|
|
@ -194,12 +194,9 @@ void Design::run_defparams()
|
|||
|
||||
void NetScope::run_defparams(Design*des)
|
||||
{
|
||||
{ NetScope*cur = sub_;
|
||||
while (cur) {
|
||||
cur->run_defparams(des);
|
||||
cur = cur->sib_;
|
||||
}
|
||||
}
|
||||
for (map<hname_t,NetScope*>::const_iterator cur = children_.begin()
|
||||
; cur != children_.end() ; cur ++)
|
||||
cur->second->run_defparams(des);
|
||||
|
||||
while (! defparams.empty()) {
|
||||
pair<pform_name_t,NetExpr*> pp = defparams.front();
|
||||
|
|
@ -572,11 +569,9 @@ void NetScope::evaluate_parameter_real_(Design*des, param_ref_t cur)
|
|||
|
||||
void NetScope::evaluate_parameters(Design*des)
|
||||
{
|
||||
NetScope*curs = sub_;
|
||||
while (curs) {
|
||||
curs->evaluate_parameters(des);
|
||||
curs = curs->sib_;
|
||||
}
|
||||
for (map<hname_t,NetScope*>::const_iterator cur = children_.begin()
|
||||
; cur != children_.end() ; cur ++)
|
||||
cur->second->evaluate_parameters(des);
|
||||
|
||||
if (debug_scopes)
|
||||
cerr << ":0" << ": debug: "
|
||||
|
|
@ -640,11 +635,9 @@ void NetScope::residual_defparams(Design*des)
|
|||
<< "Scope of " << cur.first << " not found." << endl;
|
||||
}
|
||||
|
||||
NetScope*cur = sub_;
|
||||
while (cur) {
|
||||
cur->residual_defparams(des);
|
||||
cur = cur->sib_;
|
||||
}
|
||||
for (map<hname_t,NetScope*>::const_iterator cur = children_.begin()
|
||||
; cur != children_.end() ; cur ++)
|
||||
cur->second->residual_defparams(des);
|
||||
}
|
||||
|
||||
const char* Design::get_flag(const string&key) const
|
||||
|
|
|
|||
67
net_scope.cc
67
net_scope.cc
|
|
@ -36,7 +36,7 @@
|
|||
*/
|
||||
|
||||
NetScope::NetScope(NetScope*up, const hname_t&n, NetScope::TYPE t)
|
||||
: type_(t), up_(up), sib_(0), sub_(0)
|
||||
: type_(t), name_(n), up_(up)
|
||||
{
|
||||
events_ = 0;
|
||||
lcounter_ = 0;
|
||||
|
|
@ -48,8 +48,8 @@ NetScope::NetScope(NetScope*up, const hname_t&n, NetScope::TYPE t)
|
|||
time_unit_ = up->time_unit();
|
||||
time_prec_ = up->time_precision();
|
||||
time_from_timescale_ = up->time_from_timescale();
|
||||
sib_ = up_->sub_;
|
||||
up_->sub_ = this;
|
||||
// Need to check for duplicate names?
|
||||
up_->children_[name_] = this;
|
||||
} else {
|
||||
default_nettype_ = NetNet::NONE;
|
||||
time_unit_ = 0;
|
||||
|
|
@ -71,13 +71,10 @@ NetScope::NetScope(NetScope*up, const hname_t&n, NetScope::TYPE t)
|
|||
default: /* BEGIN_END and FORK_JOIN, do nothing */
|
||||
break;
|
||||
}
|
||||
name_ = n;
|
||||
}
|
||||
|
||||
NetScope::~NetScope()
|
||||
{
|
||||
assert(sib_ == 0);
|
||||
assert(sub_ == 0);
|
||||
lcounter_ = 0;
|
||||
|
||||
/* name_ and module_name_ are perm-allocated. */
|
||||
|
|
@ -132,15 +129,29 @@ NetExpr* NetScope::set_parameter(perm_string key, NetExpr*expr,
|
|||
|
||||
bool NetScope::auto_name(const char*prefix, char pad, const char* suffix)
|
||||
{
|
||||
// Find the current reference to myself in the parent scope.
|
||||
map<hname_t,NetScope*>::iterator self = up_->children_.find(name_);
|
||||
assert(self != up_->children_.end());
|
||||
assert(self->second == this);
|
||||
|
||||
char tmp[32];
|
||||
int pad_pos = strlen(prefix);
|
||||
int max_pos = sizeof(tmp) - strlen(suffix) - 1;
|
||||
strncpy(tmp, prefix, sizeof(tmp));
|
||||
|
||||
// Try a variety of potential new names. Make sure the new
|
||||
// name is not in the parent scope. Keep looking until we are
|
||||
// sure we have a unique name, or we run out of names to try.
|
||||
while (pad_pos <= max_pos) {
|
||||
// Try this name...
|
||||
strcat(tmp + pad_pos, suffix);
|
||||
hname_t new_name(lex_strings.make(tmp));
|
||||
if (!up_->child(new_name)) {
|
||||
// Ah, this name is unique. Rename myself, and
|
||||
// change my name in the parent scope.
|
||||
name_ = new_name;
|
||||
up_->children_.erase(self);
|
||||
up_->children_[name_] = this;
|
||||
return true;
|
||||
}
|
||||
tmp[pad_pos++] = pad;
|
||||
|
|
@ -439,38 +450,20 @@ NetNet* NetScope::find_signal(perm_string key)
|
|||
*/
|
||||
NetScope* NetScope::child(const hname_t&name)
|
||||
{
|
||||
if (sub_ == 0) return 0;
|
||||
|
||||
NetScope*cur = sub_;
|
||||
while (cur->name_ != name) {
|
||||
if (cur->sib_ == 0) return 0;
|
||||
cur = cur->sib_;
|
||||
}
|
||||
|
||||
return cur;
|
||||
map<hname_t,NetScope*>::iterator cur = children_.find(name);
|
||||
if (cur == children_.end())
|
||||
return 0;
|
||||
else
|
||||
return cur->second;
|
||||
}
|
||||
|
||||
const NetScope* NetScope::child(const hname_t&name) const
|
||||
{
|
||||
if (sub_ == 0) return 0;
|
||||
|
||||
NetScope*cur = sub_;
|
||||
while (cur->name_ != name) {
|
||||
if (cur->sib_ == 0) return 0;
|
||||
cur = cur->sib_;
|
||||
}
|
||||
|
||||
return cur;
|
||||
}
|
||||
|
||||
NetScope* NetScope::parent()
|
||||
{
|
||||
return up_;
|
||||
}
|
||||
|
||||
const NetScope* NetScope::parent() const
|
||||
{
|
||||
return up_;
|
||||
map<hname_t,NetScope*>::const_iterator cur = children_.find(name);
|
||||
if (cur == children_.end())
|
||||
return 0;
|
||||
else
|
||||
return cur->second;
|
||||
}
|
||||
|
||||
perm_string NetScope::local_symbol()
|
||||
|
|
@ -479,9 +472,3 @@ perm_string NetScope::local_symbol()
|
|||
res << "_s" << (lcounter_++);
|
||||
return lex_strings.make(res.str());
|
||||
}
|
||||
#if 0
|
||||
string NetScope::local_hsymbol()
|
||||
{
|
||||
return string(name()) + "." + string(local_symbol());
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -740,9 +740,9 @@ class NetScope : public Attrib {
|
|||
|
||||
/* The parent and child() methods allow users of NetScope
|
||||
objects to locate nearby scopes. */
|
||||
NetScope* parent();
|
||||
NetScope* parent() { return up_; }
|
||||
NetScope* child(const hname_t&name);
|
||||
const NetScope* parent() const;
|
||||
const NetScope* parent() const { return up_; }
|
||||
const NetScope* child(const hname_t&name) const;
|
||||
|
||||
TYPE type() const;
|
||||
|
|
@ -918,8 +918,7 @@ class NetScope : public Attrib {
|
|||
};
|
||||
|
||||
NetScope*up_;
|
||||
NetScope*sib_;
|
||||
NetScope*sub_;
|
||||
map<hname_t,NetScope*> children_;
|
||||
|
||||
unsigned lcounter_;
|
||||
bool is_auto_, is_cell_;
|
||||
|
|
|
|||
Loading…
Reference in New Issue