diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 377f8b8c7..7b77b1073 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -23,10 +23,6 @@ #include #include -#ifdef VL_ALLOC_RANDOM_CHECKS -#include "V3Ast__gen_sizeof.h" -#endif - VL_DEFINE_DEBUG_FUNCTIONS; //====================================================================== @@ -998,6 +994,15 @@ void AstNode::operator delete(void* objp, size_t size) { #ifdef VL_ALLOC_RANDOM_CHECKS void* AstNode::operator new(size_t size) { // VL_MT_SAFE + // Compute the maximum node size once and cache it + static const size_t ASTGEN_MAX_NODE_SIZE = []() { + size_t maxSize = 0; + for (size_t t = 0; t < VNType::NUM_TYPES(); ++t) { + maxSize = std::max(maxSize, VNType::typeInfo(static_cast(t)).m_sizeof); + } + return maxSize; + }(); + // Make the following small to debug this routine, larger for performance and better random constexpr size_t POOL_SIZE = 65536; // Ideally large enough to fit all nodes used in tests // Randomly select from a large pool (POOL_SIZE) of max-node sized (MAX_NODE_SIZE) pointers diff --git a/src/astgen b/src/astgen index 1865f51f6..3d26c0474 100755 --- a/src/astgen +++ b/src/astgen @@ -935,16 +935,6 @@ def write_ast_type_info(filename): )) -def write_ast_sizeof(filename): - with open_file(filename) as fh: - fh.write("static constexpr size_t ASTGEN_MAX_NODE_SIZE =\n") - paren = "" - for node in AstNodeList: - fh.write(" std::max(sizeof(Ast{n}),\n".format(n=node.name)) - paren += ")" - fh.write(" static_cast(0)" + paren + ";\n") - - def write_ast_impl(filename): with open_file(filename) as fh: @@ -1594,7 +1584,6 @@ if Args.classes: write_ast_impl("V3Ast__gen_impl.h") write_ast_macros("V3Ast__gen_macros.h") write_ast_yystype("V3Ast__gen_yystype.h") - write_ast_sizeof("V3Ast__gen_sizeof.h") # Write Dfg code write_forward_class_decls("Dfg", DfgVertexList) write_visitor_decls("Dfg", DfgVertexList)