mirror of
https://github.com/verilator/verilator.git
synced 2026-10-07 02:23:19 +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:
+7
-5
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "V3Premit.h"
|
||||
|
||||
#include "V3ConstPool.h"
|
||||
#include "V3Stats.h"
|
||||
#include "V3UniqueNames.h"
|
||||
|
||||
@@ -117,10 +118,12 @@ class PremitVisitor final : public VNVisitor {
|
||||
|
||||
if (useConstPool) {
|
||||
// Extract into constant pool.
|
||||
const bool merge = v3Global.opt.fMergeConstPool();
|
||||
varp = v3Global.rootp()->constPoolp()->findConst(constp, merge)->varp();
|
||||
AstVarRef* const refp = V3ConstPool::findConst(constp);
|
||||
varp = refp->varp();
|
||||
VL_DO_DANGLING(nodep->deleteTree(), nodep);
|
||||
++m_extractedToConstPool;
|
||||
// Replace node with reference to the constant pool entry
|
||||
relinker.relink(refp);
|
||||
} else {
|
||||
// Keep as local temporary.
|
||||
varp = newTmpFor(nodep);
|
||||
@@ -129,11 +132,10 @@ class PremitVisitor final : public VNVisitor {
|
||||
AstAssign* const assignp = new AstAssign{flp, refp, nodep};
|
||||
// Insert before the statement
|
||||
m_stmtp->addHereThisAsNext(assignp);
|
||||
// Replace node with VarRef to new Var
|
||||
relinker.relink(new AstVarRef{flp, varp, VAccess::READ});
|
||||
}
|
||||
|
||||
// Replace node with VarRef to new Var
|
||||
relinker.relink(new AstVarRef{flp, varp, VAccess::READ});
|
||||
|
||||
// Return the temporary variable
|
||||
return varp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user