Compiler Copy Constructor Optimization via Member Variable Access Analysis
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
In object-oriented languages like C++, the copy process involving copy constructors and assignment operators leads to pointless memory access due to inefficient copying of variables, where values are read and written in bytes, resulting in increased memory access times.
Innovation Solution
An information processing device and method that analyze the source code to identify calls to copy constructors and assignment operators, calculate access times to member variables, and generate intermediate code for optimized copying in units of member variables, reducing memory access by reusing data and minimizing unnecessary reads.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of manufacture
If a default copy process is executed that copies values in bytes, then the copy process is simple to implement, but the number of memory accesses increases due to reading and writing individual byte values
Solution Approach 1:
The invention segments the copy process into two levels: byte-level copying for individual member variables and word-level copying for the entire variable. By analyzing the relationship between variables a and b, the compiler determines whether to use byte-level copy (when members are accessed individually) or word-level copy (when the entire variable is copied at once), thus resolving the contradiction between implementation simplicity and memory access efficiency.
Solution Approach 2:
The invention changes the copy granularity parameter from fixed byte-level to variable-level based on usage analysis. The compiler modifies the copy process parameters by selecting between byte-level and word-level copying strategies according to whether member variables are accessed individually or as a whole, thereby optimizing memory access time while maintaining ease of implementation through automated analysis.
2Ease of manufacture
If values are copied in bytes using default copy process, then the copy operation is straightforward, but compilation performance and runtime efficiency deteriorate due to redundant memory accesses
Solution Approach 1:
The invention performs preliminary analysis during compilation to determine the optimal copy strategy before code generation. The compiler analyzes the source code to identify relationships between variables a and b, determines whether byte-level or word-level copying is appropriate, and generates corresponding optimized code. This preliminary action eliminates redundant memory accesses while maintaining simple copy operations through automated decision-making.
Solution Approach 2:
The invention replaces the mechanical byte-by-byte copying process with an intelligent compilation-time decision system. Instead of always using fixed byte-level copying, the compiler substitutes a analysis-based approach that automatically selects between byte-level and word-level copying strategies, thereby improving compilation performance and runtime efficiency without requiring manual intervention.
3Measurement precision
If byte-level copying is used for all member variables, then the copy process handles individual members precisely, but the number of memory accesses increases when entire variables need to be copied
Solution Approach 1:
The invention makes the copy process dynamic by selecting between byte-level and word-level copying based on runtime usage patterns. The compiler analyzes whether member variables are accessed individually or as a whole and dynamically adjusts the copy granularity accordingly. This dynamic approach maintains precision when needed while reducing memory access time when entire variables are copied, resolving the contradiction between precision and speed.
Data Source
AI summary
An apparatus includes a processor coupled to a memory and configured to extract a class in which a constructor or an assignment operator included in source code or a combination of the constructor and the operator is used, identify a call to the constructor or operator or the combination, calculate the number of times of access to member variables, indicated in the call identified and a periphery of the call; compare the number, calculated, of times of the access with the number of times of memory access, and generate intermediate code having, added thereto, information to be used to execute a process for copying the constructor or the operator or the combination in units of member variables, and generate intermediate code having information added thereto based on the call when the number, calculated, of times of the access is smaller than the number of times of the memory access.


