diff --git a/include/sta/Debug.hh b/include/sta/Debug.hh index dfa975aa..fc042c7d 100644 --- a/include/sta/Debug.hh +++ b/include/sta/Debug.hh @@ -27,11 +27,6 @@ namespace sta { class Report; class Pin; -// Flag that is set when any debug mode is enabled. -// Debug macros bypass Debug::check map lookup unless some debug mode -// is enabled. -extern bool debug_on; - typedef Map DebugMap; class Debug @@ -52,6 +47,7 @@ public: protected: Report *report_; + bool debug_on_; DebugMap *debug_map_; int stats_level_; @@ -59,22 +55,13 @@ private: DISALLOW_COPY_AND_ASSIGN(Debug); }; -// Low overhead predicate. -inline bool -debugCheck(const Debug *debug, - const char *what, - int level) -{ - return debug_on && debug->check(what, level); -} - // Inlining a varargs function would eval the args, which can // be expensive, so use a macro. // Note that "##__VA_ARGS__" is a gcc extension to support zero arguments (no comma). // clang -Wno-gnu-zero-variadic-macro-arguments suppresses the warning. // c++20 has "__VA_OPT__" to deal with the zero arg case so this is temporary. -#define debugPrint(debug, what, level, msg, ...) \ - if (sta::debug_on && debug->check(what, level)) { \ +#define debugPrint(debug, what, level, msg, ...) \ + if (debug->check(what, level)) { \ debug->reportLine(what, msg, ##__VA_ARGS__); \ } diff --git a/util/Debug.cc b/util/Debug.cc index daf47bba..b5f841a2 100644 --- a/util/Debug.cc +++ b/util/Debug.cc @@ -24,6 +24,7 @@ bool debug_on = false; Debug::Debug(Report *report) : report_(report), + debug_on_(false), debug_map_(nullptr), stats_level_(0) { @@ -48,7 +49,8 @@ bool Debug::check(const char *what, int level) const { - if (debug_map_) { + if (debug_on_ + && debug_map_) { int dbg_level; bool exists; debug_map_->findKey(what, dbg_level, exists); @@ -88,8 +90,7 @@ Debug::setLevel(const char *what, debug_map_->erase(what); delete [] key; } - // debugCheck map lookup bypass - debug_on = (debug_map_->size() != 0); + debug_on_ = !debug_map_->empty(); } } else { @@ -98,7 +99,7 @@ Debug::setLevel(const char *what, if (debug_map_ == nullptr) debug_map_ = new DebugMap; (*debug_map_)[what_cpy] = level; - debug_on = true; + debug_on_ = true; } } diff --git a/verilog/VerilogReader.cc b/verilog/VerilogReader.cc index 34a45cfb..d4823dd3 100644 --- a/verilog/VerilogReader.cc +++ b/verilog/VerilogReader.cc @@ -206,7 +206,7 @@ VerilogReader::init(const char *filename) if (library_ == nullptr) library_ = network_->makeLibrary("verilog", nullptr); - report_stmt_stats_ = debugCheck(debug_, "verilog", 1); + report_stmt_stats_ = debug_->check("verilog", 1); module_count_ = 0; inst_mod_count_ = 0; inst_lib_count_ = 0; @@ -694,7 +694,7 @@ VerilogReader::incrLine() void VerilogReader::reportStmtCounts() { - if (debugCheck(debug_, "verilog", 1)) { + if (debug_->check("verilog", 1)) { report_->reportLine("Verilog stats"); printClassMemory("modules", VerilogModule, module_count_); printClassMemory("module insts", VerilogModuleInst, inst_mod_count_);