DFG: Remove unconneced variables early
This commit is contained in:
parent
c9d6344f2f
commit
cc51966ad1
|
@ -410,12 +410,18 @@ class ExtractCyclicComponents final {
|
||||||
static void packSources(DfgGraph& dfg) {
|
static void packSources(DfgGraph& dfg) {
|
||||||
// Remove undriven variable sources
|
// Remove undriven variable sources
|
||||||
dfg.forEachVertex([&](DfgVertex& vtx) {
|
dfg.forEachVertex([&](DfgVertex& vtx) {
|
||||||
if (DfgVarPacked* const vtxp = vtx.cast<DfgVarPacked>()) {
|
if (DfgVarPacked* const varp = vtx.cast<DfgVarPacked>()) {
|
||||||
vtxp->packSources();
|
varp->packSources();
|
||||||
|
if (!varp->hasSinks() && varp->arity() == 0) {
|
||||||
|
VL_DO_DANGLING(varp->unlinkDelete(dfg), varp);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DfgVarArray* const vtxp = vtx.cast<DfgVarArray>()) {
|
if (DfgVarArray* const varp = vtx.cast<DfgVarArray>()) {
|
||||||
vtxp->packSources();
|
varp->packSources();
|
||||||
|
if (!varp->hasSinks() && varp->arity() == 0) {
|
||||||
|
VL_DO_DANGLING(varp->unlinkDelete(dfg), varp);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -110,8 +110,7 @@ class AstToDfgVisitor final : public VNVisitor {
|
||||||
// Note DfgVertexLValue vertices are not added to m_uncommittedVertices, because we
|
// Note DfgVertexLValue vertices are not added to m_uncommittedVertices, because we
|
||||||
// want to hold onto them via AstVar::user1p, and the AstVar might be referenced via
|
// want to hold onto them via AstVar::user1p, and the AstVar might be referenced via
|
||||||
// multiple AstVarRef instances, so we will never revert a DfgVertexLValue once
|
// multiple AstVarRef instances, so we will never revert a DfgVertexLValue once
|
||||||
// created. This means we can end up with DfgVertexLValue vertices in the graph which
|
// created. We will delete unconnected variable vertices at the end.
|
||||||
// have no connections at all (which is fine for later processing).
|
|
||||||
if (VN_IS(varp->dtypep()->skipRefp(), UnpackArrayDType)) {
|
if (VN_IS(varp->dtypep()->skipRefp(), UnpackArrayDType)) {
|
||||||
DfgVarArray* const vtxp = new DfgVarArray{*m_dfgp, varp};
|
DfgVarArray* const vtxp = new DfgVarArray{*m_dfgp, varp};
|
||||||
varp->user1p();
|
varp->user1p();
|
||||||
|
@ -264,6 +263,13 @@ class AstToDfgVisitor final : public VNVisitor {
|
||||||
// Canonicalize packed variables
|
// Canonicalize packed variables
|
||||||
void canonicalizePacked() {
|
void canonicalizePacked() {
|
||||||
for (DfgVarPacked* const varp : m_varPackedps) {
|
for (DfgVarPacked* const varp : m_varPackedps) {
|
||||||
|
// Delete variables with no sinks nor sources (this can happen due to reverting
|
||||||
|
// uncommitted vertices, which does not remove variables)
|
||||||
|
if (!varp->hasSinks() && varp->arity() == 0) {
|
||||||
|
VL_DO_DANGLING(varp->unlinkDelete(*m_dfgp), varp);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Gather (and unlink) all drivers
|
// Gather (and unlink) all drivers
|
||||||
struct Driver {
|
struct Driver {
|
||||||
FileLine* flp;
|
FileLine* flp;
|
||||||
|
@ -328,6 +334,17 @@ class AstToDfgVisitor final : public VNVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Canonicalize array variables
|
||||||
|
void canonicalizeArray() {
|
||||||
|
for (DfgVarArray* const varp : m_varArrayps) {
|
||||||
|
// Delete variables with no sinks nor sources (this can happen due to reverting
|
||||||
|
// uncommitted vertices, which does not remove variables)
|
||||||
|
if (!varp->hasSinks() && varp->arity() == 0) {
|
||||||
|
VL_DO_DANGLING(varp->unlinkDelete(*m_dfgp), varp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// VISITORS
|
// VISITORS
|
||||||
void visit(AstNode* nodep) override {
|
void visit(AstNode* nodep) override {
|
||||||
// Conservatively treat this node as unhandled
|
// Conservatively treat this node as unhandled
|
||||||
|
@ -406,6 +423,7 @@ class AstToDfgVisitor final : public VNVisitor {
|
||||||
|
|
||||||
// Canonicalize variables
|
// Canonicalize variables
|
||||||
canonicalizePacked();
|
canonicalizePacked();
|
||||||
|
canonicalizeArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue