mirror of
https://github.com/verilator/verilator.git
synced 2026-10-07 10:33:13 +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:
+10
-5
@@ -28,6 +28,7 @@
|
||||
#include "V3Task.h"
|
||||
|
||||
#include "V3Const.h"
|
||||
#include "V3ConstPool.h"
|
||||
#include "V3Control.h"
|
||||
#include "V3EmitCBase.h"
|
||||
#include "V3Graph.h"
|
||||
@@ -467,10 +468,16 @@ class TaskVisitor final : public VNVisitor {
|
||||
m_scopep->addVarsp(newvscp);
|
||||
return newvscp;
|
||||
}
|
||||
static AstVarScope* constPoolTable(AstVar* paramp) {
|
||||
// Move array params in functions into constant pool, return the VarScope of the entry
|
||||
AstVarRef* const refp = V3ConstPool::find(VN_AS(paramp->valuep(), InitArray));
|
||||
AstVarScope* const vscp = refp->varScopep();
|
||||
VL_DO_DANGLING(refp->deleteTree(), refp);
|
||||
return vscp;
|
||||
}
|
||||
AstVarScope* createVarScope(AstVar* invarp, const string& name) {
|
||||
if (invarp->isParam() && VN_IS(invarp->valuep(), InitArray)) {
|
||||
// Move array params in functions into constant pool
|
||||
return v3Global.rootp()->constPoolp()->findTable(VN_AS(invarp->valuep(), InitArray));
|
||||
return constPoolTable(invarp);
|
||||
} else {
|
||||
// We could create under either the ref's scope or the ftask's scope.
|
||||
// It shouldn't matter, as they are only local variables.
|
||||
@@ -1424,9 +1431,7 @@ class TaskVisitor final : public VNVisitor {
|
||||
// Move array parameters in functions into constant pool
|
||||
portp->unlinkFrBack();
|
||||
pushDeletep(portp);
|
||||
AstNode* const tablep = v3Global.rootp()->constPoolp()->findTable(
|
||||
VN_AS(portp->valuep(), InitArray));
|
||||
portp->user2p(tablep);
|
||||
portp->user2p(constPoolTable(portp));
|
||||
} else {
|
||||
if (portp->isIO()) {
|
||||
// Move it to new function
|
||||
|
||||
Reference in New Issue
Block a user