mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 01:54:01 +02:00
Internals: Make the constant pool a regular package (#8512)
The constant pool is now an ordinary package, created with the netlist and instantiated under $root like any other package, and most special handling has been removed, including AstConstPool. Lookups go through V3ConstPool, which has a singleton instance owned by V3Global. Static methods on V3Common form the public interfce to add/find constant pool entries. With that, the constant pool is usable at any stage during compilation, so enum and dimension tables created by V3Width, and enum value tables created by V3Randomize now also live in the constant pool instead of $unit, so identical tables are shared. Associative array constants are handled separately from unpacked tables, which used to be broken but unused. Emitted constant pool variables use direct initialization, and `constinit` with C++20 where the type allows it. This ensures we don't change a run-time in a way that would result in unintended code size increase. -fno-merge-const-pool, which was introduced years ago but never prompted a bug report is deprecated and has no effect. This is also prep for future work.
This commit is contained in:
+6
-7
@@ -37,6 +37,7 @@
|
||||
|
||||
#include "V3Dead.h"
|
||||
|
||||
#include "V3ConstPool.h"
|
||||
#include "V3Graph.h"
|
||||
#include "V3Stats.h"
|
||||
|
||||
@@ -371,6 +372,8 @@ class DeadVisitor final : public VNVisitor {
|
||||
// Class packages might have no children, but need to remain as
|
||||
// long as the class they refer to is needed
|
||||
if (VN_IS(m_modp, Class) || VN_IS(m_modp, ClassPackage)) nodep->user1Inc();
|
||||
// The constant pool scope must remain for entries created later
|
||||
if (m_modp->isConstPool()) nodep->user1Inc();
|
||||
if (!nodep->isTop() && !nodep->varsp() && !nodep->blocksp()) {
|
||||
m_scopesp.push_back(nodep);
|
||||
}
|
||||
@@ -464,11 +467,6 @@ class DeadVisitor final : public VNVisitor {
|
||||
checkDType(nodep);
|
||||
checkAll(nodep);
|
||||
}
|
||||
void visit(AstEnumDType* nodep) override {
|
||||
// Widthing during parameter evaluation may have populated the cache.
|
||||
nodep->tableMap().clear();
|
||||
visit(static_cast<AstNodeDType*>(nodep));
|
||||
}
|
||||
void visit(AstEnumItemRef* nodep) override {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
@@ -670,7 +668,8 @@ class DeadVisitor final : public VNVisitor {
|
||||
nextmodp = VN_AS(modp->nextp(), NodeModule);
|
||||
// Keep $unit until m_elimCells stages. Note v3Global.opt.serializeOnly()
|
||||
// won't reach this stage, and will always have an empty $unit. That's ok.
|
||||
const bool keep = !m_elimCells && modp->isDollarUnit();
|
||||
// The constant pool is always kept, entries might be created later.
|
||||
const bool keep = (!m_elimCells && modp->isDollarUnit()) || modp->isConstPool();
|
||||
if (modp->dead() || (!modp->isTop() && modp->user1() == 0 && !keep)) {
|
||||
// > 2 because L1 is the wrapper, L2 is the top user module
|
||||
UINFO(4, " Dead module " << modp);
|
||||
@@ -842,7 +841,7 @@ public:
|
||||
// We may have removed some datatypes, cleanup
|
||||
nodep->typeTablep()->repairCache();
|
||||
VIsCached::clearCacheTree(); // Removing assignments may affect isPure
|
||||
nodep->constPoolp()->rebuildVarScopesAndCache();
|
||||
V3ConstPool::invalidateCache(); // Might have deleted constant pool entries
|
||||
}
|
||||
~DeadVisitor() override {
|
||||
V3Stats::addStatSum("Optimizations, FTasks, virtual-to-nonvirtual demotion",
|
||||
|
||||
Reference in New Issue
Block a user