Skip to content

Commit

Permalink
Add extra triggers for virtual interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Bieganski <[email protected]>
  • Loading branch information
kbieganski committed Nov 21, 2023
1 parent ead27db commit 4fd9fea
Show file tree
Hide file tree
Showing 32 changed files with 756 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ set(COMMON_SOURCES
V3SchedPartition.cpp
V3SchedReplicate.cpp
V3SchedTiming.cpp
V3SchedVirtIface.cpp
V3Scope.cpp
V3Scoreboard.cpp
V3Slice.cpp
Expand Down
1 change: 1 addition & 0 deletions src/Makefile_obj.in
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ RAW_OBJS_PCH_ASTNOMT = \
V3SchedPartition.o \
V3SchedReplicate.o \
V3SchedTiming.o \
V3SchedVirtIface.o \
V3Scope.o \
V3Scoreboard.o \
V3Slice.o \
Expand Down
6 changes: 6 additions & 0 deletions src/V3AstNodeDType.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ class AstEnumDType final : public AstNodeDType {
class AstIfaceRefDType final : public AstNodeDType {
// Reference to an interface, either for a port, or inside parent cell
// @astgen op1 := paramsp : List[AstPin]
bool m_virtual = false; // True if virtual interface
FileLine* m_modportFileline; // Where modport token was
string m_cellName; // "" = no cell, such as when connects to 'input' iface
string m_ifaceName; // Interface name
Expand Down Expand Up @@ -876,6 +877,11 @@ class AstIfaceRefDType final : public AstNodeDType {
bool similarDType(const AstNodeDType* samep) const override { return this == samep; }
int widthAlignBytes() const override { return 1; }
int widthTotalBytes() const override { return 1; }
void isVirtual(bool flag) {
m_virtual = flag;
if (flag) v3Global.setHasVirtIfaces();
}
bool isVirtual() const { return m_virtual; }
FileLine* modportFileline() const { return m_modportFileline; }
string cellName() const { return m_cellName; }
void cellName(const string& name) { m_cellName = name; }
Expand Down
8 changes: 4 additions & 4 deletions src/V3AstNodeOther.h
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,7 @@ class AstVar final : public AstNode {
VLifetime m_lifetime; // Lifetime
VVarAttrClocker m_attrClocker;
MTaskIdSet m_mtaskIds; // MTaskID's that read or write this var
AstIface* m_sensIfacep = nullptr; // Interface type to which reads from this var are sensitive
int m_pinNum = 0; // For XML, if non-zero the connection pin number
bool m_ansi : 1; // Params or pins declared in the module header, rather than the body
bool m_declTyped : 1; // Declared as type (for dedup check)
Expand All @@ -1742,7 +1743,6 @@ class AstVar final : public AstNode {
bool m_usedClock : 1; // Signal used as a clock
bool m_usedParam : 1; // Parameter is referenced (on link; later signals not setup)
bool m_usedLoopIdx : 1; // Variable subject of for unrolling
bool m_usedVirtIface : 1; // Signal used through a virtual interface
bool m_funcLocal : 1; // Local variable for a function
bool m_funcLocalSticky : 1; // As m_funcLocal but remains set if var is moved to a static
bool m_funcReturn : 1; // Return variable for a function
Expand Down Expand Up @@ -1784,7 +1784,6 @@ class AstVar final : public AstNode {
m_usedClock = false;
m_usedParam = false;
m_usedLoopIdx = false;
m_usedVirtIface = false;
m_sigPublic = false;
m_sigModPublic = false;
m_sigUserRdPublic = false;
Expand Down Expand Up @@ -1866,6 +1865,7 @@ class AstVar final : public AstNode {
dtypeFrom(examplep);
}
ASTGEN_MEMBERS_AstVar;
void cloneRelink() override;
void dump(std::ostream& str) const override;
bool same(const AstNode* samep) const override;
string name() const override VL_MT_STABLE VL_MT_SAFE { return m_name; } // * = Var name
Expand Down Expand Up @@ -1913,6 +1913,7 @@ class AstVar final : public AstNode {
}
void ansi(bool flag) { m_ansi = flag; }
void declTyped(bool flag) { m_declTyped = flag; }
void sensIfacep(AstIface* nodep) { m_sensIfacep = nodep; }
void attrClocker(VVarAttrClocker flag) { m_attrClocker = flag; }
void attrFileDescr(bool flag) { m_fileDescr = flag; }
void attrScClocked(bool flag) { m_scClocked = flag; }
Expand All @@ -1923,7 +1924,6 @@ class AstVar final : public AstNode {
void usedClock(bool flag) { m_usedClock = flag; }
void usedParam(bool flag) { m_usedParam = flag; }
void usedLoopIdx(bool flag) { m_usedLoopIdx = flag; }
void usedVirtIface(bool flag) { m_usedVirtIface = flag; }
void sigPublic(bool flag) { m_sigPublic = flag; }
void sigModPublic(bool flag) { m_sigModPublic = flag; }
void sigUserRdPublic(bool flag) {
Expand Down Expand Up @@ -2016,7 +2016,6 @@ class AstVar final : public AstNode {
bool isUsedClock() const { return m_usedClock; }
bool isUsedParam() const { return m_usedParam; }
bool isUsedLoopIdx() const { return m_usedLoopIdx; }
bool isUsedVirtIface() const { return m_usedVirtIface; }
bool isSc() const VL_MT_SAFE { return m_sc; }
bool isScQuad() const;
bool isScBv() const;
Expand Down Expand Up @@ -2044,6 +2043,7 @@ class AstVar final : public AstNode {
bool attrSFormat() const { return m_attrSFormat; }
bool attrSplitVar() const { return m_attrSplitVar; }
bool attrIsolateAssign() const { return m_attrIsolateAssign; }
AstIface* sensIfacep() const { return m_sensIfacep; }
VVarAttrClocker attrClocker() const { return m_attrClocker; }
string verilogKwd() const override;
void lifetime(const VLifetime& flag) { m_lifetime = flag; }
Expand Down
3 changes: 3 additions & 0 deletions src/V3AstNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,9 @@ int AstVarRef::instrCount() const {
// Otherwise as a load/store
return widthInstrs() * (access().isReadOrRW() ? INSTR_COUNT_LD : 1);
}
void AstVar::cloneRelink() {
if (m_sensIfacep && m_sensIfacep->clonep()) m_sensIfacep = m_sensIfacep->clonep();
}
void AstVar::dump(std::ostream& str) const {
this->AstNode::dump(str);
if (isSc()) str << " [SC]";
Expand Down
2 changes: 1 addition & 1 deletion src/V3Const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2691,7 +2691,7 @@ class ConstVisitor final : public VNVisitor {
&& m_doNConst
&& v3Global.opt.fConst()
// Default value, not a "known" constant for this usage
&& !nodep->varp()->isClassMember() && !nodep->varp()->isUsedVirtIface()
&& !nodep->varp()->isClassMember() && !nodep->varp()->sensIfacep()
&& !(nodep->varp()->isFuncLocal() && nodep->varp()->isNonOutput())
&& !nodep->varp()->noSubst() && !nodep->varp()->isSigPublic())
|| nodep->varp()->isParam())) {
Expand Down
2 changes: 1 addition & 1 deletion src/V3Dead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class DeadVisitor final : public VNVisitor {
}
bool mightElimVar(AstVar* nodep) const {
if (nodep->isSigPublic()) return false; // Can't elim publics!
if (nodep->isIO() || nodep->isClassMember() || nodep->isUsedVirtIface()) return false;
if (nodep->isIO() || nodep->isClassMember() || nodep->sensIfacep()) return false;
if (nodep->isTemp() && !nodep->isTrace()) return true;
return m_elimUserVars; // Post-Trace can kill most anything
}
Expand Down
42 changes: 42 additions & 0 deletions src/V3ExtraTriggerBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// -*- mode: C++; c-file-style: "cc-mode" -*-
//*************************************************************************
// DESCRIPTION: Verilator: Builder for sensitivity checking expressions.
//
// Code available from: https://verilator.org
//
//*************************************************************************
//
// Copyright 2003-2023 by Wilson Snyder. This program is free software; you
// can redistribute it and/or modify it under the terms of either the GNU
// Lesser General Public License Version 3 or the Perl Artistic License
// Version 2.0.
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
//
//*************************************************************************

#ifndef VERILATOR_V3EXTRATRIGGERBUILDER_H_
#define VERILATOR_V3EXTRATRIGGERBUILDER_H_

#include "config_build.h"
#include "verilatedos.h"

#include "V3Ast.h"
#include "V3UniqueNames.h"

//######################################################################
class ExtraTriggerBuilder final {
std::vector<string> m_descriptions; // Human readable description of extra triggers

public:
ExtraTriggerBuilder() = default;

size_t allocate(const string& description) {
const size_t index = m_descriptions.size();
m_descriptions.push_back(description);
return index;
}
size_t size() const { return m_descriptions.size(); }
const string& description(size_t index) const { return m_descriptions[index]; }
};

#endif // Guard
2 changes: 1 addition & 1 deletion src/V3Gate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class GateGraph final : public V3Graph {
UINFO(6, "New vertex " << vscp << endl);
vVtxp = new GateVarVertex{this, vscp};
vscp->user1p(vVtxp);
if (vscp->varp()->isUsedVirtIface()) {
if (vscp->varp()->sensIfacep()) {
// Can be used in a class method, which cannot be tracked statically
vVtxp->clearReducibleAndDedupable("VirtIface");
vVtxp->setConsumed("VirtIface");
Expand Down
3 changes: 3 additions & 0 deletions src/V3Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class V3Global final {
bool m_dpi = false; // Need __Dpi include files
bool m_hasEvents = false; // Design uses SystemVerilog named events
bool m_hasClasses = false; // Design uses SystemVerilog classes
bool m_hasVirtIfaces = false; // Design uses virtual interfaces
bool m_usesProbDist = false; // Uses $dist_*
bool m_usesStdPackage = false; // Design uses the std package
bool m_usesTiming = false; // Design uses timing constructs
Expand Down Expand Up @@ -162,6 +163,8 @@ class V3Global final {
void setHasEvents() { m_hasEvents = true; }
bool hasClasses() const { return m_hasClasses; }
void setHasClasses() { m_hasClasses = true; }
bool hasVirtIfaces() const { return m_hasVirtIfaces; }
void setHasVirtIfaces() { m_hasVirtIfaces = true; }
bool usesProbDist() const { return m_usesProbDist; }
void setUsesProbDist() { m_usesProbDist = true; }
bool usesStdPackage() const { return m_usesStdPackage; }
Expand Down
4 changes: 2 additions & 2 deletions src/V3Life.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class LifeBlock final {
void checkRemoveAssign(const LifeMap::iterator& it) {
const AstVar* const varp = it->first->varp();
LifeVarEntry* const entp = &(it->second);
if (!varp->isSigPublic() && !varp->isUsedVirtIface()) {
if (!varp->isSigPublic() && !varp->sensIfacep()) {
// Rather than track what sigs AstUCFunc/AstUCStmt may change,
// we just don't optimize any public sigs
// Check the var entry, and remove if appropriate
Expand Down Expand Up @@ -178,7 +178,7 @@ class LifeBlock final {
const auto pair = m_map.emplace(nodep, LifeVarEntry::CONSUMED{});
if (!pair.second) {
if (AstConst* const constp = pair.first->second.constNodep()) {
if (!varrefp->varp()->isSigPublic() && !varrefp->varp()->isUsedVirtIface()) {
if (!varrefp->varp()->isSigPublic() && !varrefp->varp()->sensIfacep()) {
// Aha, variable is constant; substitute in.
// We'll later constant propagate
UINFO(4, " replaceconst: " << varrefp << endl);
Expand Down
2 changes: 1 addition & 1 deletion src/V3Localize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class LocalizeVisitor final : public VNVisitor {
&& !nodep->varp()->isFuncLocal() // Not already a function local (e.g.: argument)
&& !nodep->varp()->isStatic() // Not a static variable
&& !nodep->varp()->isClassMember() // Statically exists in design hierarchy
&& !nodep->varp()->isUsedVirtIface() // Not used through a virtual interface
&& !nodep->varp()->sensIfacep() // Not sensitive to an interface
&& !nodep->varp()->valuep() // Does not have an initializer
) {
UINFO(4, "Consider for localization: " << nodep << endl);
Expand Down
5 changes: 5 additions & 0 deletions src/V3Order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ class OrderBuildVisitor final : public VNVisitor {
void visit(AstNodeVarRef* nodep) override {
// As we explicitly not visit (see ignored nodes below) any subtree that is not relevant
// for ordering, we should be able to assert this:
if (!m_logicVxp) {
std::cout << nodep << endl;
nodep->backp()->dumpTree(cout);
nodep->backp()->backp()->dumpTree(cout);
}
UASSERT_OBJ(m_scopep, nodep, "AstVarRef not under scope");
UASSERT_OBJ(m_logicVxp, nodep, "AstVarRef not under logic");
AstVarScope* const varscp = nodep->varScopep();
Expand Down
Loading

0 comments on commit 4fd9fea

Please sign in to comment.