A virtual table sparsity generation and dynamic filling method for EDA simulation

CN122655653BActive Publication Date: 2026-10-09成都融见软件科技有限公司 +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611165150.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-08-03
Publication Date
2026-10-09
Estimated Expiration
2046-08-03

AI Technical Summary

Technical Problem

[0005]然而,在EDA仿真场景中,由于仿真器的实例巨大、类层次复杂,往往涉及数万个类和数百万个虚函数,对于一个包含m个虚函数的类,即使子类仅覆写了其中极少数虚函数,通用编译器生成的代码仍然会强制链接器处理所有m个重定位条目,逐一进行符号查找和地址回填,从而导致链接阶段的工作量与虚函数总数呈线性关系,而非与实际覆写数相关,进而造成链接时间随着仿真模型规模急剧膨胀,成为了制约大规模仿真模型构建效率的瓶颈

Benefits of technology

本发明中,子类的稀疏虚表中仅为本类覆写的虚函数生成实际的重定位条目和符号引用,对于从父类继承而来的大量虚函数,仅用轻量级的继承标记和继承占位符代替,避免了在编译阶段就为所有子类生成庞大的重复函数指针条目,从而大幅减少了编译时间,而且,由于稀疏虚表中仅包含少量覆写函数的重定位条目,链接器需要处理和解析的重定位信息量大幅减少,同时,虚表的填充过程是在父类虚表已经初始化后,通过简单的复制操作完成,从而进一步缩短了编译时间,提高了编译效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122655653B_ABST
    Figure CN122655653B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of EDA simulation, in particular to a virtual table sparsity generation and dynamic filling method for EDA simulation, in which only actual relocation entries and symbolic references of virtual functions overwritten by the subclass are generated in the sparse virtual table of the subclass, a large number of virtual functions inherited from the parent class are replaced by light-weight inheritance marks and inheritance placeholders, the generation of huge repeated function pointer entries for all subclasses in the compiling stage is avoided, the compiling time is greatly reduced, and because the sparse virtual table only contains a small amount of relocation entries of overwritten functions, the amount of relocation information to be processed and analyzed by a linker is greatly reduced; in addition, the filling process of the virtual table is completed through simple copying operation after the parent class virtual table is initialized, the compiling time is further shortened, and the compiling efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electronic design automation technology, and in particular to a method for generating and dynamically filling virtual tables for EDA simulation. Background Technology

[0002] In the field of high-performance EDA simulator technology, converting hardware description languages ​​into C++ object models is a mainstream implementation path. Existing technologies typically rely directly on general-purpose C++ compilers (such as GCC and Clang) to generate virtual tables. These technologies usually employ a full generation strategy, meaning that a separate relocation entry is generated for each function pointer slot in the virtual table, so that the linker can determine the actual address of the virtual function in the final stage.

[0003] A virtual table is a static data structure generated by the C++ compiler during the compilation phase to implement runtime polymorphism. Essentially, a virtual table is an array of function pointers that stores the entry addresses (physical memory addresses) of all virtual functions in the class in sequence. In standard C++ implementations, the virtual table header usually also contains auxiliary metadata, such as the offset to the top and a pointer to runtime type information (RTTI).

[0004] Each virtual function declared in a class has a fixed index position in the virtual table. When the program calls a virtual function through the base class pointer, the CPU will not jump directly to the function address. Instead, it will first find the virtual table through the object's virtual table pointer (vptr), and then retrieve the corresponding function pointer according to the fixed index of the virtual function in the virtual table for jumping.

[0005] However, in EDA simulation scenarios, due to the huge number of simulator instances and the complex class hierarchy, which often involve tens of thousands of classes and millions of virtual functions, for a class containing m virtual functions, even if the subclasses only override a very small number of virtual functions, the code generated by the general compiler will still force the linker to process all m relocation entries, performing symbol lookups and address backfilling one by one. This results in the workload of the linking stage being linearly related to the total number of virtual functions, rather than to the actual number of overridden functions. Consequently, the linking time expands dramatically with the size of the simulation model, becoming a bottleneck restricting the efficiency of building large-scale simulation models.

[0006] Therefore, how to reduce compilation time and improve compilation efficiency has become an urgent problem to be solved. Summary of the Invention

[0007] To address the aforementioned technical problems, the technical solution adopted by this invention is as follows: A method for sparse generation and dynamic filling of virtual tables for EDA simulation, the method comprising the following steps: S1, During the compilation phase, if the current class is a subclass, the compiler generates a sparse virtual table for the current class based on each virtual function in the current class. This generation of the sparse virtual table includes: Determine the number M of virtual functions contained in the current class, where M is a positive integer; Traverse the M virtual functions. If the m-th virtual function is an overriding function, then form the m-th virtual table entry using the symbolic reference and relocation placeholder of the m-th virtual function, and generate the relocation entry for the m-th virtual function. If the m-th virtual function is an inherited function, then no relocation entry for the m-th virtual function is generated. Instead, the m-th virtual table entry is formed by the preset inheritance flag value and the preset inheritance placeholder, where m is an integer in the range [1, M]. The number M of virtual functions contained in the current class and the address of the virtual table of the parent class corresponding to the current class are used as metadata. The sparse virtual table of the current class is formed by the metadata and the virtual table entries corresponding to the M virtual functions respectively. S2, during the simulator startup phase, after the complete virtual table of the parent class corresponding to the current class is initialized, the sparse virtual table of the current class is filled according to the complete virtual table of the parent class corresponding to the current class to obtain the filled virtual table of the current class.

[0008] Compared with existing technologies, this invention has significant advantages. Through the above technical solution, the virtual surface sparse generation and dynamic filling method for EDA simulation provided by this invention achieves considerable technological advancement and practicality, and has broad industrial application value. It has at least the following advantages: In this invention, the sparse virtual table of a subclass only generates actual relocation entries and symbolic references for virtual functions overridden by the subclass. For a large number of virtual functions inherited from the parent class, only lightweight inheritance markers and inheritance placeholders are used instead, avoiding the generation of a large number of duplicate function pointer entries for all subclasses during the compilation phase, thereby significantly reducing compilation time. Moreover, since the sparse virtual table contains only a small number of relocation entries for overridden functions, the amount of relocation information that the linker needs to process and parse is greatly reduced. At the same time, the virtual table filling process is completed through a simple copy operation after the parent class virtual table has been initialized, thereby further shortening the compilation time and improving compilation efficiency. Attached Figure Description

[0009] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0010] Figure 1 This is a flowchart illustrating a method for generating and dynamically filling virtual tables for EDA simulation, provided in an embodiment of the present invention. Detailed Implementation

[0011] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0012] This embodiment provides a method for virtual table sparse generation and dynamic filling for EDA simulation. See [link to documentation]. Figure 1 This is a flowchart illustrating a method for generating and dynamically filling virtual tables for EDA simulation, provided by an embodiment of the present invention. The method includes the following steps: S1, During the compilation phase, if the current class is a subclass, the compiler generates a sparse virtual table for the current class based on each virtual function in the current class. This generation of the sparse virtual table includes: Determine the number M of virtual functions contained in the current class, where M is a positive integer; Traverse the M virtual functions. If the m-th virtual function is an overriding function, then form the m-th virtual table entry using the symbolic reference and relocation placeholder of the m-th virtual function, and generate the relocation entry for the m-th virtual function. If the m-th virtual function is an inherited function, then no relocation entry for the m-th virtual function is generated. Instead, the m-th virtual table entry is formed by the preset inheritance flag value and the preset inheritance placeholder, where m is an integer in the range [1, M]. The number M of virtual functions contained in the current class and the address of the virtual table of the parent class corresponding to the current class are used as metadata. The sparse virtual table of the current class is formed by the metadata and the virtual table entries corresponding to the M virtual functions respectively. S2, during the simulator startup phase, after the complete virtual table of the parent class corresponding to the current class is initialized, the sparse virtual table of the current class is filled according to the complete virtual table of the parent class corresponding to the current class to obtain the filled virtual table of the current class.

[0013] A virtual function is a member function declared using the keyword virtual in a C++ base class. Virtual functions allow subclasses to redefine the functionality of the function as needed. Virtual functions enable the program to dynamically call the specific implementation in the derived class at runtime through a pointer reference to the base class, thereby achieving polymorphism.

[0014] Sparse virtual tables generate virtual table entries containing symbolic references and relocation placeholders only for virtual functions overridden in subclasses, as well as generating relocation entries.

[0015] An overriding function is a virtual function that is redefined in a derived class. When a derived class defines a function with the same name, parameter list, and return type as a virtual function in the base class, the function overrides the corresponding version in the base class. In the context of virtual tables, overriding means that in the virtual table of the derived class, the virtual table entry corresponding to the function will be filled with the address of the function implemented by the derived class itself, overwriting the address of the original function in the base class.

[0016] Symbolic references are references to functions or variables in the compiled object file, usually existing as symbolic names rather than direct memory addresses. This symbolic name is the symbolic reference, which will be resolved into a specific memory address during the linking or loading phase.

[0017] When generating object files, the compiler reserves a blank space (inheritance placeholder) for symbolic references whose final address is not yet known, and generates a corresponding relocation entry. This relocation entry informs the linker, after determining the final load address of the symbolic reference during the linking phase, to return to the corresponding offset and modify the relocation placeholder to the correct actual address.

[0018] An inherited function is a virtual function that a derived class does not override but directly uses the implementation of the base class. In the context of virtual tables, this means that in the virtual table of the derived class, the virtual table entry corresponding to the function still stores the address of the function in the base class (or a higher-level ancestor class). When the function is called, the program will jump to execute the logic defined in the base class.

[0019] The inheritance flag is a predefined constant, such as NULL or 0, used to indicate in a virtual table entry that this virtual table entry needs to be inherited from the parent class's virtual table. The inheritance placeholder is blank data that works in conjunction with the inheritance flag. Together, they constitute the corresponding lightweight virtual table entry.

[0020] Specifically, in general usage, the metadata of a virtual table needs to include the offset to top and a pointer to runtime type information (RTTI). However, in EDA simulation scenarios, the type of the simulated C++ model is usually determined at compile time, and there is no multiple inheritance. Therefore, in this embodiment, the number M of virtual functions contained in the current class and the address of the virtual table of the parent class corresponding to the current class are used as metadata.

[0021] During the dynamic filling process at the simulation startup phase, the address of the parent virtual table in the metadata is used to replace the virtual table entries that need to be inherited in the sparse virtual table with the corresponding virtual table entries in the parent virtual table, thereby making the sparse virtual table fill into a usable and complete filled virtual table.

[0022] In one specific implementation, the method further includes the following steps: During the compilation phase, if the current class is not a subclass, the compiler generates a complete virtual table for the current class based on the virtual functions in the current class.

[0023] The metadata of the complete virtual table may include the number of virtual functions contained in the current class and a preset identifier, which is empty in this embodiment.

[0024] In one specific implementation, the step of generating a complete virtual table for the current class by the compiler based on the various virtual functions in the current class includes: Determine the number N of virtual functions contained in the current class, where N is a positive integer; Traverse N virtual functions to generate a relocation entry for the nth virtual function. The nth virtual table entry is formed by the symbol reference and relocation placeholder of the nth virtual function, where n is an integer in the range [1, N]. The complete virtual table of the current class is formed by the virtual table entries corresponding to the N virtual functions.

[0025] If the current class is not a subclass, it means that the current class has no parent class. All virtual table entries included in the complete virtual table need to be relocated.

[0026] Specifically, during the compilation phase, all virtual table entries included in the complete virtual table generate corresponding relocation entries.

[0027] In one specific implementation, after determining the number M of virtual functions contained in the current class, the method further includes: Write the virtual table of the current class into the object file. Based on the number M of virtual functions contained in the current class, reserve virtual table space in the readable and writable data segment of the object file. The virtual table space includes a metadata area and a function pointer area.

[0028] Object files are intermediate files generated by the compiler after compiling the source code. They typically contain machine code, data, and information required for linking and relocation. Multiple object files are combined by the linker into an executable file or a dynamic library.

[0029] The data segment is typically used to store global and static variables. The readable and writable portion is usually called the .data segment. Placing the virtual table space here indicates that the contents of the virtual table can be modified during program runtime.

[0030] The metadata area is a portion of the virtual table space used to store metadata. Located before the function pointer area, the metadata area provides necessary guidance for the population process.

[0031] The function pointer area refers to the main part of the virtual table space, which is used to store M virtual table entries.

[0032] In one specific implementation, the step of using the number M of virtual functions contained in the current class and the virtual table address of the parent class corresponding to the current class as metadata, and forming a sparse virtual table for the current class using the metadata and the virtual table entries corresponding to the M virtual functions respectively, includes: The number M of virtual functions contained in the current class and the virtual table address of the parent class corresponding to the current class are used as metadata and filled into the metadata area of ​​the virtual table space corresponding to the current class. The virtual table entries corresponding to the M virtual functions are filled into the function pointer area in the virtual table space corresponding to the current class to obtain the sparse virtual table of the current class, wherein the virtual table pointer of the current class points to the starting position of the function pointer area.

[0033] The virtual table address of the parent class corresponding to the current class is also unknown at compile time. Therefore, in the metadata, a placeholder will be filled in the position of the virtual table address of the parent class corresponding to the current class, and a corresponding relocation entry will be generated.

[0034] Specifically, the virtual table pointer initially points to the base address of the function pointer area. When a virtual function is called, the program finds the function pointer area through the object's virtual table pointer, calculates the offset according to the declaration order of the functions in the class, locates the corresponding virtual table entry, and retrieves the function address from that entry for calling.

[0035] At runtime, the address of the metadata area can be calculated by offsetting backwards using a known virtual table pointer, and the address of the parent class virtual table can be read to obtain the filling source.

[0036] As can be seen, the sparse virtual table and the complete virtual table in this embodiment are fully compatible with the C++ virtual table in terms of local memory. The virtual table pointer of the object still points to the contiguous function pointer area. Therefore, during the simulation run, the virtual function call instructions are completely consistent with the traditional method, without any additional runtime performance overhead.

[0037] In one specific implementation, the method further includes: During the simulator startup phase, if the complete virtual table of the parent class corresponding to the current class has not been initialized, the initialization logic is recursively called to initialize the complete virtual table of the parent class corresponding to the current class.

[0038] In this case, the complete virtual table of the parent class corresponding to the current class has not been initialized, that is, the complete virtual table of the parent class corresponding to the current class is not ready. Since the sparse virtual table of the current class may need to be dynamically filled by copying the complete virtual table of the parent class, the initialization logic needs to be recursively called first to initialize the complete virtual table of the parent class corresponding to the current class.

[0039] In one specific implementation, the current class does not have multiple parent classes.

[0040] In this case, the current class does not have multiple parent classes, that is, there is no multiple inheritance, which is consistent with the characteristics of the C++ simulation model in the EDA simulation scenario.

[0041] In one specific implementation, the step of filling the sparse virtual table of the current class with the complete virtual table of the parent class corresponding to the current class to obtain the filled virtual table of the current class includes: For any virtual table entry containing an inheritance identifier value in the sparse virtual table of the current class, copy the virtual table entry corresponding to the same index position in the virtual table of the parent class corresponding to the current class, based on the index position of the virtual table entry. Traverse all virtual table entries containing inheritance identifier values ​​in the sparse virtual table of the current class to obtain the filled virtual table of the current class.

[0042] In general, the sparse virtual table of a subclass does not add any virtual table entries compared to the complete virtual table of its parent class. Therefore, for ease of processing, this embodiment directly copies the virtual table entries corresponding to the same index positions in the virtual table of the parent class corresponding to the current class, based on the index positions corresponding to the virtual table entries.

[0043] Specifically, when a new virtual table item is added to a subclass, that is, when the subclass defines a new virtual function that does not exist in the parent class, the new virtual function can be handled in the same way as an overridden virtual function.

[0044] In this embodiment, the sparse virtual table of the subclass only generates actual relocation entries and symbolic references for virtual functions overridden by this class. For a large number of virtual functions inherited from the parent class, only lightweight inheritance markers and inheritance placeholders are used instead, avoiding the generation of a large number of duplicate function pointer entries for all subclasses during the compilation phase, thereby significantly reducing compilation time. Moreover, since the sparse virtual table contains only a small number of relocation entries for overridden functions, the amount of relocation information that the linker needs to process and parse is greatly reduced. At the same time, the virtual table filling process is completed through a simple copy operation after the parent class virtual table has been initialized, thereby further shortening the compilation time and improving compilation efficiency.

[0045] While specific embodiments of the invention have been described in detail by way of example, those skilled in the art should understand that the examples are for illustrative purposes only and not intended to limit the scope of the invention. Those skilled in the art should also understand that various modifications can be made to the embodiments without departing from the scope and spirit of the invention. The scope of this invention is defined by the appended claims.

Claims

1. A method for sparse generation and dynamic filling of virtual tables for EDA simulation, characterized in that, The method includes the following steps: S1, During the compilation phase, if the current class is a subclass, the compiler generates a sparse virtual table for the current class based on each virtual function in the current class. This generation of the sparse virtual table includes: Determine the number M of virtual functions contained in the current class, where M is a positive integer; Traverse the M virtual functions. If the m-th virtual function is an overriding function, then form the m-th virtual table entry using the symbolic reference and relocation placeholder of the m-th virtual function, and generate the relocation entry for the m-th virtual function. If the m-th virtual function is an inherited function, then no relocation entry for the m-th virtual function is generated. Instead, the m-th virtual table entry is formed by the preset inheritance flag value and the preset inheritance placeholder, where m is an integer in the range [1, M]. The number M of virtual functions contained in the current class and the address of the virtual table of the parent class corresponding to the current class are used as metadata. The sparse virtual table of the current class is formed by the metadata and the virtual table entries corresponding to the M virtual functions respectively. S2, during the simulator startup phase, after the complete virtual table of the parent class corresponding to the current class is initialized, the sparse virtual table of the current class is filled according to the complete virtual table of the parent class corresponding to the current class to obtain the filled virtual table of the current class.

2. The method for virtual table sparse generation and dynamic filling for EDA simulation according to claim 1, characterized in that, The method further includes the following steps: During the compilation phase, if the current class is not a subclass, the compiler generates a complete virtual table for the current class based on the virtual functions in the current class.

3. The method for virtual table sparse generation and dynamic filling for EDA simulation according to claim 2, characterized in that, The process of generating a complete virtual table for the current class by the compiler based on the various virtual functions in the current class includes: Determine the number N of virtual functions contained in the current class, where N is a positive integer; Traverse N virtual functions to generate a relocation entry for the nth virtual function. The nth virtual table entry is formed by the symbol reference and relocation placeholder of the nth virtual function, where n is an integer in the range [1, N]. The complete virtual table of the current class is formed by the virtual table entries corresponding to the N virtual functions.

4. The method for virtual table sparse generation and dynamic filling for EDA simulation according to claim 1, characterized in that, After determining the number M of virtual functions contained in the current class, the method further includes: Write the virtual table corresponding to the current class into the object file. Based on the number M of virtual functions contained in the current class, reserve virtual table space in the readable and writable data segment of the object file. The virtual table space includes a metadata area and a function pointer area.

5. The method for virtual table sparse generation and dynamic filling for EDA simulation according to claim 4, characterized in that, The sparse virtual table of the current class is formed by using the number M of virtual functions contained in the current class and the virtual table address of the parent class corresponding to the current class as metadata, and the virtual table entries corresponding to the M virtual functions respectively. This includes: The number M of virtual functions contained in the current class and the virtual table address of the parent class corresponding to the current class are used as metadata and filled into the metadata area of ​​the virtual table space corresponding to the current class. The virtual table entries corresponding to the M virtual functions are filled into the function pointer area in the virtual table space corresponding to the current class to obtain the sparse virtual table of the current class, wherein the virtual table pointer of the current class points to the starting position of the function pointer area.

6. The method for virtual table sparse generation and dynamic filling for EDA simulation according to claim 1, characterized in that, The method further includes: During the simulator startup phase, if the complete virtual table of the parent class corresponding to the current class has not been initialized, the initialization logic is recursively called to initialize the complete virtual table of the parent class corresponding to the current class.

7. The method for sparse generation and dynamic filling of virtual tables for EDA simulation according to claim 1, characterized in that, The current class does not have multiple parent classes.

8. The method for sparse generation and dynamic filling of virtual tables for EDA simulation according to claim 1, characterized in that, The step of filling the sparse virtual table of the current class with the complete virtual table of the parent class corresponding to the current class to obtain the filled virtual table of the current class includes: For any virtual table entry containing an inheritance identifier value in the sparse virtual table of the current class, copy the virtual table entry corresponding to the same index position in the virtual table of the parent class corresponding to the current class, based on the index position of the virtual table entry. Traverse all virtual table entries containing inheritance identifier values ​​in the sparse virtual table of the current class to obtain the filled virtual table of the current class.

Citation Information

Patent Citations

  • Method for implementing virtual function tables in a compiler for an object-oriented programming language

    US5327562A

  • Method and system for constructing hybrid virtual function tables

    US6182282B1