Skip to content

Commit

Permalink
Move Concat balancing from DFG to FuncOpt
Browse files Browse the repository at this point in the history
This means it applies more widely, e.g. inside sequential logic.
  • Loading branch information
gezalore committed Nov 10, 2024
1 parent fd35f3f commit a57d2f4
Show file tree
Hide file tree
Showing 17 changed files with 174 additions and 248 deletions.
2 changes: 2 additions & 0 deletions docs/guide/exe_verilator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ Summary:

.. option:: -fno-func-opt

.. option:: -fno-func-opt-balance-cat

.. option:: -fno-func-opt-split-cat

.. option:: -fno-gate
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ set(COMMON_SOURCES
V3Descope.cpp
V3Dfg.cpp
V3DfgAstToDfg.cpp
V3DfgBalanceTrees.cpp
V3DfgCache.cpp
V3DfgDecomposition.cpp
V3DfgDfgToAst.cpp
Expand Down
1 change: 0 additions & 1 deletion src/Makefile_obj.in
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ RAW_OBJS_PCH_ASTNOMT = \
V3Descope.o \
V3Dfg.o \
V3DfgAstToDfg.o \
V3DfgBalanceTrees.o \
V3DfgCache.o \
V3DfgDecomposition.o \
V3DfgDfgToAst.o \
Expand Down
3 changes: 0 additions & 3 deletions src/V3Dfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ class DfgVertex VL_NOT_FINAL {
// Predicate: has 1 or more sinks
bool hasSinks() const { return m_sinksp != nullptr; }

// Predicate: has precisely 1 sink
bool hasSingleSink() const { return m_sinksp && !m_sinksp->m_nextp; }

// Predicate: has 2 or more sinks
bool hasMultipleSinks() const { return m_sinksp && m_sinksp->m_nextp; }

Expand Down
197 changes: 0 additions & 197 deletions src/V3DfgBalanceTrees.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions src/V3DfgOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void V3DfgOptimizer::extract(AstNetlist* netlistp) {
V3Global::dumpCheckGlobalTree("dfg-extract", 0, dumpTreeEitherLevel() >= 3);
}

void V3DfgOptimizer::optimize(AstNetlist* netlistp, const string& label, bool lastInvocation) {
void V3DfgOptimizer::optimize(AstNetlist* netlistp, const string& label) {
UINFO(2, __FUNCTION__ << ": " << endl);

// NODE STATE
Expand Down Expand Up @@ -282,7 +282,7 @@ void V3DfgOptimizer::optimize(AstNetlist* netlistp, const string& label, bool la
for (auto& component : acyclicComponents) {
if (dumpDfgLevel() >= 7) component->dumpDotFilePrefixed(ctx.prefix() + "source");
// Optimize the component
V3DfgPasses::optimize(*component, ctx, lastInvocation);
V3DfgPasses::optimize(*component, ctx);
// Add back under the main DFG (we will convert everything back in one go)
dfg->addGraph(*component);
}
Expand Down
2 changes: 1 addition & 1 deletion src/V3DfgOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace V3DfgOptimizer {
void extract(AstNetlist*) VL_MT_DISABLED;

// Optimize the design
void optimize(AstNetlist*, const string& label, bool lastInvocation) VL_MT_DISABLED;
void optimize(AstNetlist*, const string& label) VL_MT_DISABLED;
} // namespace V3DfgOptimizer

#endif // Guard
11 changes: 1 addition & 10 deletions src/V3DfgPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ V3DfgEliminateVarsContext::~V3DfgEliminateVarsContext() {
m_varsRemoved);
}

V3DfgBalanceTreesContext::~V3DfgBalanceTreesContext() {
V3Stats::addStat("Optimizations, DFG " + m_label + " BalanceTrees, concat trees balanced",
m_balancedConcats);
}

static std::string getPrefix(const std::string& label) {
if (label.empty()) return "";
std::string str = VString::removeWhitespace(label);
Expand Down Expand Up @@ -337,7 +332,7 @@ void V3DfgPasses::eliminateVars(DfgGraph& dfg, V3DfgEliminateVarsContext& ctx) {
for (AstVar* const varp : replacedVariables) varp->unlinkFrBack()->deleteTree();
}

void V3DfgPasses::optimize(DfgGraph& dfg, V3DfgOptimizationContext& ctx, bool lastInvocation) {
void V3DfgPasses::optimize(DfgGraph& dfg, V3DfgOptimizationContext& ctx) {
// There is absolutely nothing useful we can do with a graph of size 2 or less
if (dfg.size() <= 2) return;

Expand Down Expand Up @@ -365,10 +360,6 @@ void V3DfgPasses::optimize(DfgGraph& dfg, V3DfgOptimizationContext& ctx, bool la
}
// Accumulate patterns for reporting
if (v3Global.opt.stats()) ctx.m_patternStats.accumulate(dfg);
// The peephole pass covnerts all trees to right leaning, so only do this on the last DFG run.
if (lastInvocation) {
apply(4, "balanceTrees", [&]() { balanceTrees(dfg, ctx.m_balanceTreesContext); });
}
apply(4, "regularize", [&]() { regularize(dfg, ctx.m_regularizeContext); });
if (dumpDfgLevel() >= 8) dfg.dumpDotAllVarConesPrefixed(ctx.prefix() + "optimized");
}
16 changes: 1 addition & 15 deletions src/V3DfgPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ class V3DfgEliminateVarsContext final {
~V3DfgEliminateVarsContext() VL_MT_DISABLED;
};

class V3DfgBalanceTreesContext final {
const std::string m_label; // Label to apply to stats

public:
VDouble0 m_balancedConcats; // Number of temporaries introduced

explicit V3DfgBalanceTreesContext(const std::string& label)
: m_label{label} {}
~V3DfgBalanceTreesContext() VL_MT_DISABLED;
};

class V3DfgOptimizationContext final {
const std::string m_label; // Label to add to stats, etc.
const std::string m_prefix; // Prefix to add to file dumps (derived from label)
Expand All @@ -103,7 +92,6 @@ class V3DfgOptimizationContext final {
V3DfgPeepholeContext m_peepholeContext{m_label};
V3DfgRegularizeContext m_regularizeContext{m_label};
V3DfgEliminateVarsContext m_eliminateVarsContext{m_label};
V3DfgBalanceTreesContext m_balanceTreesContext{m_label};

V3DfgPatternStats m_patternStats;

Expand All @@ -124,7 +112,7 @@ namespace V3DfgPasses {
DfgGraph* astToDfg(AstModule&, V3DfgOptimizationContext&) VL_MT_DISABLED;

// Optimize the given DfgGraph
void optimize(DfgGraph&, V3DfgOptimizationContext&, bool lastInvocation) VL_MT_DISABLED;
void optimize(DfgGraph&, V3DfgOptimizationContext&) VL_MT_DISABLED;

// Convert DfgGraph back into Ast, and insert converted graph back into its parent module.
// Returns the parent module.
Expand All @@ -146,8 +134,6 @@ void regularize(DfgGraph&, V3DfgRegularizeContext&) VL_MT_DISABLED;
void removeUnused(DfgGraph&) VL_MT_DISABLED;
// Eliminate (remove or replace) redundant variables. Also removes resulting unused logic.
void eliminateVars(DfgGraph&, V3DfgEliminateVarsContext&) VL_MT_DISABLED;
// Make computation trees balanced
void balanceTrees(DfgGraph&, V3DfgBalanceTreesContext&) VL_MT_DISABLED;

} // namespace V3DfgPasses

Expand Down
Loading

0 comments on commit a57d2f4

Please sign in to comment.