diff --git a/src/V3AstNodeMath.h b/src/V3AstNodeMath.h index 398e57832..ef635a14a 100644 --- a/src/V3AstNodeMath.h +++ b/src/V3AstNodeMath.h @@ -4265,9 +4265,7 @@ public: bool same(const AstNode* samep) const override; inline bool same(const AstVarRef* samep) const; inline bool sameNoLvalue(AstVarRef* samep) const; - int instrCount() const override { - return widthInstrs() * (access().isReadOrRW() ? INSTR_COUNT_LD : 1); - } + int instrCount() const override; string emitVerilog() override { V3ERROR_NA_RETURN(""); } string emitC() override { V3ERROR_NA_RETURN(""); } bool cleanOut() const override { return true; } diff --git a/src/V3AstNodeOther.h b/src/V3AstNodeOther.h index 3e2fd6430..a0b3e991f 100644 --- a/src/V3AstNodeOther.h +++ b/src/V3AstNodeOther.h @@ -2851,6 +2851,7 @@ public: statement(true); dtypeSetVoid(); } + int instrCount() const override; }; class AstCReset final : public AstNodeStmt { // Reset variable at startup diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 92e0b2fce..3487e1814 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -2047,6 +2047,14 @@ void AstVarRef::dump(std::ostream& str) const { bool AstVarRef::same(const AstNode* samep) const { return same(static_cast(samep)); } +int AstVarRef::instrCount() const { + // Account for the target of hard-coded method calls as just an address computation + if (const AstCMethodHard* const callp = VN_CAST(backp(), CMethodHard)) { + if (callp->fromp() == this) return 1; + } + // Otherwise as a load/store + return widthInstrs() * (access().isReadOrRW() ? INSTR_COUNT_LD : 1); +} void AstVar::dump(std::ostream& str) const { this->AstNode::dump(str); if (isSc()) str << " [SC]"; @@ -2247,6 +2255,18 @@ void AstCAwait::dump(std::ostream& str) const { sensesp()->dump(str); } } +int AstCMethodHard::instrCount() const { + if (AstBasicDType* const basicp = fromp()->dtypep()->basicp()) { + // TODO: add a more structured description of library methods, rather than using string + // matching. See #3715. + if (basicp->isTriggerVec() && m_name == "at") { + // This is an important special case for scheduling so we compute it precisely, + // it is simply a load. + return INSTR_COUNT_LD; + } + } + return AstNodeStmt::instrCount(); +} const char* AstCFunc::broken() const { BROKEN_RTN((m_scopep && !m_scopep->brokeExists())); return nullptr;