Make all expressions derive from AstNodeExpr (#3721).

Apart from the representational changes below, this patch renames
AstNodeMath to AstNodeExpr, and AstCMath to AstCExpr.

Now every expression (i.e.: those AstNodes that represent a [possibly
void] value, with value being interpreted in a very general sense) has
AstNodeExpr as a super class. This necessitates the introduction of an
AstStmtExpr, which represents an expression in statement position, e.g :
'foo();' would be represented as AstStmtExpr(AstCCall(foo)). In exchange
we can get rid of isStatement() in AstNodeStmt, which now really always
represent a statement

Peak memory consumption and verilation speed are not measurably changed.

Partial step towards #3420
This commit is contained in:
Geza Lore
2022-11-03 16:02:16 +00:00
parent cf4c00e3b4
commit 65e08f4dbf
66 changed files with 2005 additions and 1968 deletions
+6 -6
View File
@@ -47,7 +47,7 @@ class DataflowExtractVisitor final : public VNVisitor {
// Expressions considered for extraction as separate assignment to gain more opportunities for
// optimization, together with the list of variables they read.
using Candidates = std::vector<std::pair<AstNodeMath*, std::vector<const AstVar*>>>;
using Candidates = std::vector<std::pair<AstNodeExpr*, std::vector<const AstVar*>>>;
// Expressions considered for extraction. All the candidates are pure expressions.
AstUser4Allocator<AstNodeModule, Candidates> m_extractionCandidates;
@@ -65,7 +65,7 @@ class DataflowExtractVisitor final : public VNVisitor {
// Node considered for extraction as a combinational equation. Trace variable usage/purity.
void iterateExtractionCandidate(AstNode* nodep) {
UASSERT_OBJ(!VN_IS(nodep->backp(), NodeMath), nodep,
UASSERT_OBJ(!VN_IS(nodep->backp(), NodeExpr), nodep,
"Should not try to extract nested expressions (only root expressions)");
// Simple VarRefs should not be extracted, as they only yield trivial assignments.
@@ -93,7 +93,7 @@ class DataflowExtractVisitor final : public VNVisitor {
if (m_readVars.empty()) return;
// Add to candidate list
m_candidatesp->emplace_back(VN_AS(nodep, NodeMath), std::move(m_readVars));
m_candidatesp->emplace_back(VN_AS(nodep, NodeExpr), std::move(m_readVars));
}
// VISIT methods
@@ -110,7 +110,7 @@ class DataflowExtractVisitor final : public VNVisitor {
if (!VN_IS(modp, Module)) continue;
for (const auto& pair : m_extractionCandidates(modp)) {
AstNodeMath* const nodep = pair.first;
AstNodeExpr* const nodep = pair.first;
// Do not extract expressions without any variable references
if (pair.second.empty()) continue;
@@ -204,7 +204,7 @@ class DataflowExtractVisitor final : public VNVisitor {
m_inForceReleaseLhs = false;
}
void visit(AstNodeMath* nodep) override { iterateChildrenConst(nodep); }
void visit(AstNodeExpr* nodep) override { iterateChildrenConst(nodep); }
void visit(AstNodeVarRef* nodep) override {
if (nodep->access().isWriteOrRW()) {
@@ -220,7 +220,7 @@ class DataflowExtractVisitor final : public VNVisitor {
void visit(AstNode* nodep) override {
// Conservatively assume unhandled nodes are impure. This covers all AstNodeFTaskRef
// as AstNodeFTaskRef are sadly not AstNodeMath.
// as AstNodeFTaskRef are sadly not AstNodeExpr.
m_impure = true;
// Still need to gather all references/force/release, etc.
iterateChildrenConst(nodep);