Structural body domain optimization method and device and related equipment

By inserting sampling instructions in the intermediate representation file, collecting the number of memory access information of the structure domain, determining its memory access mode, and optimizing the structure hot and cold domain, the problem of poor optimization of the structure domain in the existing technology is solved, and more efficient structural domain optimization is achieved.

CN119576341APending Publication Date: 2025-03-07HAIGUANG INTEGRATED CIRCUIT DESIGN (BEIJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411654463.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

Existing compiler optimization technology is difficult to make full use of memory fetching mode information in the structure domain, resulting in missing opportunities for further optimization in the structure domain with the same memory fetching mode, affecting the optimization effect of the structure domain.

Method used

By inserting sampling instructions in the intermediate representation file, the number of memory access information of the structure domain at runtime is collected, the memory access mode of the structure domain is determined, and the structure hot and cold domain optimization process is performed in the same mode.

Benefits of technology

More accurate and sufficient optimization of the structure domain is achieved, the optimization effect of the structure domain is improved, the cache miss rate is reduced, and the cache utilization rate is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576341A_ABST
    Figure CN119576341A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a structural body domain optimization method and device and related equipment.The method comprises the steps that an intermediate representation file of a source program is obtained, the intermediate representation file comprises a sampling instruction inserted based on a structural body domain of the source program, and the sampling instruction is used for collecting a sampling result of the structural body domain when the structural body domain runs; the number of memory access times of memory access operation on the structural body domain; running the intermediate representation file to obtain memory access frequency acquisition information of the structural body domain based on the sampling instruction; carrying out optimization processing on a structural body domain according to the memory access frequency acquisition information; wherein the memory access frequency acquisition information is used for determining an optimizable structural body domain in the structural body domains with the same memory access mode when the memory access modes of the structural body domains are determined to be the same. According to the technical scheme provided by the embodiment of the invention, the structural body domain optimization effect can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a structure domain optimization method, device and related equipment. Background Art

[0002] Compiler optimization technology can reduce cache miss rate and improve cache utilization by analyzing the optimization opportunities of structure domain of structure and realizing optimization of structure domain. Compiler optimization technology has a wide range of applications in program optimization. Therefore, how to provide a technical solution to improve the optimization effect of structure domain has become a technical problem that technicians in this field need to solve urgently. Summary of the invention

[0003] In view of this, an embodiment of the present invention provides a structure domain optimization method, apparatus and related equipment to improve the structure domain optimization effect.

[0004] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions.

[0005] In a first aspect, an embodiment of the present invention provides a structure domain optimization method, comprising:

[0006] Acquire an intermediate representation file of a source program, wherein the intermediate representation file includes a sampling instruction inserted based on a structure field of the source program, wherein the sampling instruction is used to collect the number of memory access operations performed on the structure field when the structure field is running;

[0007] Running the intermediate representation file to obtain memory access times collection information of the structure field based on the sampling instruction;

[0008] Optimizing the structure domain according to the memory access times collection information;

[0009] The memory access times collection information is used to determine the optimizable structure domains among the structure domains with the same memory access mode when it is determined that the memory access modes of the structure domains are the same.

[0010] In a second aspect, an embodiment of the present invention provides a structure domain optimization device, comprising:

[0011] An intermediate representation file acquisition module is used to acquire an intermediate representation file of a source program, wherein the intermediate representation file includes a sampling instruction inserted based on a structure field of the source program, wherein the sampling instruction is used to collect the number of memory access operations performed on the structure field when the structure field is running;

[0012] An intermediate representation file running module, used for running the intermediate representation file to obtain the memory access times collection information of the structure field based on the sampling instruction;

[0013] A structure domain optimization module, used for optimizing the structure domain according to the memory access times collection information;

[0014] The memory access times collection information is used to determine the optimizable structure domains among the structure domains with the same memory access mode when it is determined that the memory access modes of the structure domains are the same.

[0015] In a third aspect, an embodiment of the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a program, and the processor calls the program stored in the memory to execute the structure domain optimization method as described in the first aspect.

[0016] In a fourth aspect, an embodiment of the present invention provides a storage medium, wherein the storage medium stores a program, and when the program is executed, the structure domain optimization method as described in the first aspect is implemented.

[0017] In a fifth aspect, an embodiment of the present invention provides a computer program product, including a computer program, which, when executed by a processor, implements the structure domain optimization method as described in the first aspect.

[0018] A structure domain optimization method provided by an embodiment of the present invention first obtains an intermediate representation file of a source program, wherein the intermediate representation file includes sampling instructions inserted based on the structure domain of the source program, and the sampling instructions are used to collect the number of memory access operations performed on the structure domain when the structure domain is running; then the intermediate representation file is run to obtain memory access number collection information of the structure domain based on the sampling instructions; the structure domain is optimized according to the memory access number collection information; wherein the memory access number collection information is used to determine the optimizable structure domain in the structure domains with the same memory access mode when it is determined that the memory access modes of the structure domains are the same.

[0019] It can be seen that the technical solution provided by the embodiment of the present invention, by using the sampling instructions in the intermediate representation file during the process of running the intermediate representation file, collects the number of memory access operations performed on the structure domain, and obtains the memory access number collection information; thereby, the actual situation of the structure domain being executed with the memory access operation when the structure domain is running can be obtained. On the one hand, based on the memory access number collection information, the memory access mode of the structure domain can be determined, that is, whether the structure domain is a frequently accessed structure domain (hot domain), or a structure domain that is not frequently accessed (cold domain), or a structure domain that is not accessed (dead domain); on the other hand, based on the determination of the memory access mode of the structure domain, the specific value of the number of access operations performed on the structure domain can be clarified, so that in the structure domain with the same memory access mode, according to the number of access operations, the structure domain can be further optimized (i.e., the structure cold and hot domain optimization processing) to achieve full optimization of the structure domain, thereby improving the optimization effect of the structure domain. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0021] Figure 1 It is a schematic diagram of a flow chart of a structure domain optimization method provided by an embodiment of the present invention;

[0022] Figure 2 is another schematic flow chart of the structure domain optimization method provided by an embodiment of the present invention;

[0023] Figure 3 It is a schematic diagram of a process of structural domain optimization provided by an embodiment of the present invention;

[0024] Figure 4 This is a schematic diagram of an implementation process of inserting a sampling instruction using the structure domain optimization method provided by an embodiment of the present invention;

[0025] Figure 5 It is a structural schematic diagram of a structural domain optimization device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0026] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0027] When the compiler optimizes the source program, memory latency and memory bandwidth are always performance factors that deserve attention.

[0028] Multiple functions can be defined in a source program, and multiple structures can be defined and used in each function. A structure is a composite data type that combines members of different data types into a single entity. The individual data type members contained in a structure can be called structure fields.

[0029] Since the content of structures accounts for a large proportion in the overall code of a source program, the optimization of the source program can be mainly aimed at the optimization of the structures in the source program (structure domain optimization). When the source program is running, due to the complex simulation scenario of the structure domain, it often introduces performance issues related to cache utilization, memory bandwidth, memory access latency, etc.

[0030] For example, when running a source program, its hotspot area (i.e., the function that occupies a large amount of CPU time or resources during the execution of the source program) is only defined as: accessing part of the structure field in a structure; or there is an inappropriate structure layout in the source program, which greatly increases the byte size required for the structure when byte alignment occurs; or there is a structure field that has never been accessed in the entire program, i.e., a dead field; all of the above situations will introduce performance issues related to cache utilization, memory bandwidth, memory access latency, etc.

[0031] Structure Data Layout Optimizations is a relatively mature and widely used compiler optimization technology, which aims to reduce cache miss rate and improve cache utilization. The optimization strategies of structure data layout optimization can include: structure peeling, structure splitting, structure reordering, and conversion of structure array to array structure (array of structures -> structure of arrays, AOS -> SOA).

[0032] The optimization of structure fields is related to the memory access mode of the structure fields in the source program, and for structure fields with the same memory access mode, the next step of optimization cannot be performed. The memory access mode includes the structure field being a frequently accessed structure field (Struct Hot Field), or a structure field that is not frequently accessed (Struct Cold Field), or a structure field that is not accessed (Dead Field). For example, when it is determined that the memory access modes of three structure fields are all hot fields, it means that these three structure fields are all frequently accessed structure fields. At this time, when the compiler performs optimization processing, it will not consider further optimization of these three structure fields.

[0033] Therefore, among structure domains with the same memory access mode, some structure domains that can be further optimized will be omitted, thereby missing the local optimization opportunity of the structure domain and affecting the effect of the structure domain optimization.

[0034] Based on this, an embodiment of the present invention provides a structure domain optimization method to improve the structure domain optimization effect.

[0035] Please refer to Figure 1 , Figure 1 It is a flow chart of a structure domain optimization method provided by an embodiment of the present invention.

[0036] like Figure 1 As shown, the process may include the following steps:

[0037] Step S100: obtaining an intermediate representation file of a source program, wherein the intermediate representation file includes a sampling instruction inserted based on a structure field of the source program.

[0038] The sampling instruction is used to collect the number of memory access operations performed on the structure field when the structure field is running.

[0039] The intermediate representation file includes: intermediate representations corresponding to various codes defined in the source program and inserted sampling instructions.

[0040] Among them, the intermediate representation (IR) is obtained by the compiler when analyzing the source program when compiling and optimizing the source program (that is, compiling the source program to generate the intermediate representation). It is an abstract form for representing the source program; the compiler can then optimize the source program based on the intermediate representation.

[0041] The purpose of IR is to provide an easy-to-operate internal representation for the compiler's optimization and target code (computer executable code after optimization) generation stages. It is located between the source program text and the machine code (the intermediate representation can also be called intermediate code or intermediate instructions); that is, IR is a form between high-level language (the language used to write the source program) and assembly language (the machine language run by the computer), which facilitates subsequent optimization and target code generation.

[0042] In the embodiment of the present invention, when the intermediate representation file is run, the number of memory access operations on the structure field needs to be collected. Therefore, the sampling instruction is inserted into the position corresponding to the structure field to form the intermediate representation file.

[0043] Step S101 : running the intermediate representation file to obtain memory access times collection information of the structure field based on the sampling instruction.

[0044] The memory access times collection information corresponds to the memory access times of the structure domain. Therefore, the memory access times collection information, on the one hand, the numerical value of the memory access times represented by it can reflect the frequency of the structure domain being accessed, thereby determining whether the memory access mode of the structure domain is a hot domain, a cold domain, or a dead domain (no memory access operation is performed); on the other hand, the specific numerical value of the memory access times represented by it can further distinguish the memory access modes of structure domains with the same memory access mode, so as to accurately and fully optimize the structure domain. That is, the structure domain optimization referred to in this article is aimed at the optimization of the hot and cold domains of the structure.

[0045] It should be noted that the optimization process does not end after the intermediate representation file is run. Instead, the compiler guides the subsequent optimization process based on the running results of the intermediate representation file. That is, the compiler uses the running results of the intermediate representation file to compress the structure field of the source program to complete the optimization of the source program.

[0046] Step S102: optimizing the structure domain according to the memory access times collection information.

[0047] The memory access times collection information is used to determine the structure domains that can be optimized for hot and cold domains among the structure domains with the same memory access mode when it is determined that the structure domains have the same memory access mode.

[0048] It can be seen that the technical solution provided by the embodiment of the present invention, by using the sampling instructions in the intermediate representation file during the process of running the intermediate representation file, collects the number of memory access operations performed on the structure domain, and obtains the memory access number collection information; thereby, the actual situation of the structure domain being executed with the memory access operation when the structure domain is running can be obtained. On the one hand, based on the memory access number collection information, the memory access mode of the structure domain can be determined, that is, whether the structure domain is a frequently accessed structure domain (hot domain), or a structure domain that is not frequently accessed (cold domain), or a structure domain that is not accessed (dead domain); on the other hand, based on the determination of the memory access mode of the structure domain, the specific value of the number of access operations performed on the structure domain can be clarified, so that in the structure domain with the same memory access mode, according to the number of access operations, the structure domain can be further optimized (i.e., the structure cold and hot domain optimization processing) to achieve full optimization of the structure domain, thereby improving the optimization effect of the structure domain.

[0049] In order to fully optimize the structure domain, in one implementation, step S101 may include:

[0050] Running the intermediate representation file;

[0051] For each structure field, during the operation cycle of the intermediate representation file, the number of memory accesses to the structure field by all functions of the source program is collected to obtain information on the number of memory accesses of each function;

[0052] And, the memory access times collection information of each function is added up to obtain the total memory access times collection information, and the total memory access times collection information is used as the memory access times collection information of the structure domain.

[0053] When optimizing a structure domain, it is possible to analyze whether it can be optimized based on the global information of the structure domain, but for structure domains with the same memory access mode, no further optimization analysis can be performed. Therefore, the optimization of the hot and cold domains of the structure is insufficient; wherein, the global information is: information formed by the number of memory access operations performed on each structure domain in a structure based on a structure when the source program is running; the structure domain with the same memory access mode means that the memory access mode of each structure domain in a structure is the same, and the structure domain in the structure is partially optimized based on the structure, so as to improve the optimization efficiency and reduce the optimization complexity.

[0054] In an embodiment of the present invention, the number of memory accesses is collected according to the memory access operations of each function of the source program on the structure domain, and memory access number collection information is obtained. That is to say, the memory access number collection information in the embodiment of the present invention is the sum of the memory access times of each function; wherein, the memory access times of each function performing memory access operations on the structure domain may include: read times and write times. Therefore, in addition to determining the memory access mode of the structure domain according to the memory access number collection information of the structure domain in the embodiment of the present invention; it is also possible to further determine the corresponding memory access times of each structure domain in the same function (function memory access number collection information) according to the memory access number collection information of the structure domain, thereby achieving full optimization of the hot and cold domains of the structure.

[0055] To facilitate obtaining the memory access count information corresponding to each structure field, in one implementation, before running the intermediate representation file, a global metadata GV.StructName.data may be first created for each structure; wherein the global metadata is used to count the information StructFieldInfo of each structure field of each structure, and the information includes: ReadCounter (the number of reads corresponding to a memory access operation being a read operation) and WriteCounter (the number of writes corresponding to a memory access operation being a write operation).

[0056] Then, traverse the functions one by one and traverse the IR instructions of the functions one by one.

[0057] Next, for the IR of the structure pointer field, if there is a memory access operation on each structure field in the structure pointed to by the structure pointer field, the original collection information of each structure field is counted, the original collection data ProfilingData is bound to the structure pointer field, and local collection data (function memory access count collection information) LV.structName.fieldIndex.data is created.

[0058] Finally, the global metadata GV.StructName.data is updated according to the local collected data, and the data recorded in the updated global metadata is used as the memory access count collection information of each structure field.

[0059] In one implementation, the step of optimizing the structure field according to the memory access times acquisition information includes:

[0060] Determine the memory access mode of the corresponding structure field according to the total memory access times collection information, and judge whether the memory access modes of each structure field are the same;

[0061] If yes, collect information according to the total number of memory accesses corresponding to each structure domain, determine the structure domain that can be optimized, and perform structure cold and hot domain optimization processing on the determined structure domain;

[0062] If not, information is collected according to the number of function memory accesses corresponding to each structure domain, the optimizable structure domain is determined, and the determined structure domain is optimized by performing structure cold and hot domain optimization processing.

[0063] The total number of memory accesses collected information can reflect the memory access situation of each structure domain from a global perspective. For example, according to the value of the total number of memory accesses collected information, it can be determined whether the structure domain is frequently accessed, thereby determining the memory access mode of the structure domain. Therefore, the total number of memory accesses collected information can be used to determine the memory access mode of each structure domain, so as to perform preliminary global structure hot and cold domain optimization processing on the structure domain based on the memory access mode represented by the overall information of the structure domain (the total number of memory accesses collected information).

[0064] Since structure domain optimization (structure cold and hot domain optimization) requires comprehensive consideration of multiple factors, structure cold and hot domain optimization is usually performed on part of the structure domains in a structure, so that the complexity of structure cold and hot domain optimization can be controlled while improving performance.

[0065] Therefore, in one implementation, in order to facilitate fully accurate optimization of the hot and cold domains of the structure domain, the memory access mode of the corresponding structure domain is determined according to the total number of memory access acquisition information, and whether the memory access modes of each structure domain are the same may include:

[0066] Determine the structure field corresponding to the total memory access times collection information, and determine the corresponding structure according to the determined structure field;

[0067] In each structure field belonging to the same structure, determine whether the total number of memory access times collected in each structure field is less than a first threshold;

[0068] If so, determine that the memory access modes of each structure field are the same;

[0069] If not, it is determined that the memory access modes of the various structure fields are different.

[0070] The first threshold may be a value used to indicate that the total number of memory access times collected for each structure field of a structure is not much different. For example, the first threshold may be 10.

[0071] First, the corresponding structure field is determined based on the total number of memory access times of the structure field, and then the structure to which the structure field belongs is determined based on the name defined in the source program, and then the structure fields belonging to the same structure are determined.

[0072] For ease of understanding, the total number of memory accesses is collected to determine that the corresponding structure field is Aq. The structure field named q belongs to a structure named A. Therefore, other structure fields whose structure name is A can be searched in each structure field. For example, the other structure fields of structure A found are Am and AN.

[0073] In a structure, information is collected based on the total number of memory accesses of each structure domain, and the memory access mode of each structure domain is determined, so that the structure domains for which the cold and hot domains of the structure can be optimized can be accurately determined.

[0074] In one implementation, when it is determined that the memory access modes of each structure field are different, collecting information according to the total number of memory accesses corresponding to each structure field, determining an optimizable structure field, and optimizing the determined structure field, includes:

[0075] It is determined that the optimization strategy for the hot and cold domains of the structure is the structural splitting strategy;

[0076] The structure splitting strategy is used to split the structure field corresponding to the memory access statistic collection information with a small value.

[0077] When it is determined that the difference in the total number of memory access times collected by each structure domain belonging to the same structure is not within the first threshold, it means that the total number of memory access times collected by each structure domain is significantly different. Therefore, the structure domain with obvious differences can be determined as the structure domain that can be optimized for the hot and cold domains of the structure (i.e., the optimized structure domain), which facilitates the determination and optimization of the memory access mode of the structure domain.

[0078] For example, the total memory access times collected information corresponding to structure domain a, structure domain b and structure domain c belonging to structure A are 272161, 346172 and 22 respectively. It can be obviously seen that the total memory access times collected information of structure domain c is very different from the total memory access times collected information of structure domain a and structure domain b. At this time, the structure splitting optimization strategy can be directly selected to split structure domain c into structure A.

[0079] Since there are structure domains with the same memory access mode, that is, the total memory access times collected information of each structure domain of a structure is not much different, it is impossible to directly optimize the structure domains for hot and cold domains based on the total memory access times collected information.

[0080] Therefore, in order to ensure that the structure domain can fully perform the structure cold and hot domain optimization, in one implementation, when it is determined that the memory access modes of each structure domain are the same, the information is collected according to the number of memory accesses of the functions corresponding to each structure domain, the structure domain that can be optimized is determined, and the structure cold and hot domain optimization processing is performed on the determined structure domain, including:

[0081] By using the function memory access times of each structure domain to collect information, the optimization strategy of the structure hot and cold domains of the structure domain is determined as the structure splitting strategy;

[0082] By utilizing the structure splitting strategy, the structure fields corresponding to the function memory access times collection information with small values ​​are split.

[0083] When it is determined that the memory access modes of each structure domain are the same, it means that the total memory access times collected by each structure domain are approximately equal. At this time, the function memory access times collected by each structure domain can be further combined to determine the memory access times of each structure domain in the same function, and then perform local structure cold and hot domain optimization on the structure domain.

[0084] For example, the total memory access times collected information corresponding to structure domain a, structure domain b and structure domain c belonging to structure A are 272161, 346172 and 346169 respectively. It can be clearly seen that there is no obvious difference in the total memory access times collected information of structure domain c, structure domain a and structure domain b. At this time, it is impossible to directly select the structure domain for structure cold and hot domain optimization based on the total memory access times collected information.

[0085] Therefore, the structure domains that can be optimized for hot and cold domains of the structure can be determined based on the function memory access times collection information of the structure domain. Exemplarily, the structure pointer domain can be used to determine the function memory access times collection information of each structure domain belonging to the same structure in a certain function. For example, if the structure pointer domain accessed by function F is struct.network*, the structure pointed to is struct.network, so the function memory access times collection information of each structure domain in the structure accessed by function F can be determined based on the structure pointed to by the structure pointer domain.

[0086] For example, the structure pointer field accessed in function F is: %network.field21=getelementptrinbounds%struct.network,%struct.network*%0,i64 0,i32 21,!prof!615.

[0087] Then the collected information about the number of function memory accesses of each structure field can be expressed as:

[0088] ! 615=! {! "VP",i32 2,i64 11,i64 2,i64 9};

[0089] It can be seen that when function F accesses the structure pointed to by the structure pointer field, the third element "i64 11" indicates the total number of samples, that is, the total number of reads and writes is 11, the fourth element "i64 2" indicates the number of memory access reads is 2, and the fifth element "i64 9" indicates the number of memory access writes is 9. Among them, the first two elements "!"VP"" and "i32 2" indicate the acquisition data type.

[0090] At this time, the structure field that collects the function memory access count information of 2 can be split into the structure struct.network.

[0091] To facilitate understanding of the application of the structure domain optimization method provided by the embodiment of the present invention, the implementation process of the structure domain optimization method provided by the embodiment of the present invention is described.

[0092] First, the intermediate representation file including the sample instructions is run.

[0093] After the run is finished, the memory access times collection information of each structure field can be obtained.

[0094] Then, the information on the number of memory accesses in the structure field is collected and analyzed.

[0095] When analyzing the memory access times collection information, it can be done from two aspects:

[0096] First, during the entire operation cycle of the intermediate representation file, the global information of memory access operations on all structure fields within the structure is taken as a whole.

[0097] When analyzing the total memory access times collection information of the structure field, taking LLVM (open source compiler infrastructure project) as an example, for any structure, the total memory access times collection information of each structure field in the structure can be determined based on the global pointer field of the structure (the structure pointer field defined in the structure can be accessed in the global scope of the source program). The total memory access times collection information obtained can be expressed as:

[0098] ! 12782=! {! "struct.sRunData.field",i64 272161,i64 0,i64 346172,i64 0,i64 1,i64 22}.

[0099] Among them, the structure struct.sRunData defines three non-pointer structure fields: uint_32a; uint_32b; int64 c.

[0100] ! 12782 is the collection metadata, which is represented in the structure struct.sRunData. The total number of memory accesses collected for each structure field is: the total number of reads of uint_32a(field0) is 272161, and the total number of writes is 0, so the total number of memory accesses collected for uint_32a(field0) is 272161+0=272161; the total number of reads of uint_32b(field1) is 346172, and the total number of writes is 0, so the total number of memory accesses collected for uint_32b(field1) is 346172+0=346172; the total number of reads of int64 c(field2) is 1, and the total number of writes is 22, so the total number of memory accesses collected for int64 c(field2) is 1+22=23.

[0101] Therefore, based on the total number of memory accesses of each of the above structure fields, it can be determined that the structure fields field0 and filed1 have obvious differences from the structure field field2. Then, a structural splitting strategy can be adopted to split the structure field field2 into the structure struct.sRunData.

[0102] Secondly, during the entire operation cycle of the intermediate representation file, for each structure field, the local information of each structure field is analyzed.

[0103] When analyzing the function memory access times collection information of the structure domain, continue to take LLVM (open source compiler infrastructure project) as an example, for any structure domain, determine the function memory access times collection information of the structure domain:

[0104] %network.field21=getelementptr inbounds%struct.network,%struct.network*%0,i64 0,i32 21,! prof! 615.

[0105] %network.field21 is the address fetch operation for the 21st structure field of the structure struct.network; Prof! 615 indicates that the local collection result (collection information of function memory access times) is bound to %network.field21. In other words, the collection information of function memory access times for the 21st structure field of the structure struct.network is obtained through the %615 metadata.

[0106] The function memory access times collection information of the 21st structure field obtained from the %615 metadata can be expressed as:

[0107] ! 615=! {! "VP",i32 2,i64 11,i64 2,i64 9};

[0108] Among them, the first element "!"VP"" and the second element "i32 2" represent the data type of the collected structure field (for example, the 21st structure field is the integer data type int), which can represent the collected data type in the present invention.

[0109] The third element "i64 11" indicates the total number of memory access sampling information of the 21st structure field, that is, the total number of read and write times is 11 times;

[0110] The fourth element "i64 2" indicates that the total number of reads of the 21st structure field is 2 times;

[0111] The fifth element "i64 9" indicates that the total number of writes to the 21st structure field is 9 times.

[0112] The above-mentioned !615 instruction can collect the function memory access times collection information of each structure field. Therefore, in a structure, if each structure field has the same memory access mode, the !615 instruction can be used to obtain the memory access times of the structure field in each function (the function memory access times collection information of the structure field).

[0113] For example, continuing to take the structure struct.sRunData.field used in the first aspect as an example, when the global information of each structure field is obtained by taking the structure struct.sRunData.field as a whole, the total number of memory accesses collected is obtained as follows:

[0114] ! 12782=! {! "struct.sRunData.field", i64 272161, i64 0, i64 346172, i64 0, i64 346169, i64 22};

[0115] It can be seen that the total number of memory accesses collected for field0 is 272161, the total number of memory accesses collected for field1 is 346172, and the total number of memory accesses collected for field2 is 346169. At this time, the memory access modes of the three structure domains are the same, all are hot domains, and there is no obvious difference. Therefore, it is impossible to directly optimize the structure hot and cold domains of the structure domain based on the global information of each structure domain in the structure collected above.

[0116] At this time, you can use the %615 instruction to traverse each function of the source program for each structure field and collect local information of the structure field (collection information of the number of times each function in the structure field is accessed). For example, in the hotspot function F, the function memory access times of the structure field field0 and the structure field field1 are collected:

[0117] ! 615=! {! "VP",i32 2,i64 272161,i64 272161,i64 0};

[0118] ! 616=! {! "VP", i32 2, i64 346172, i64 346172, i64 0}.

[0119] At this time, inside the hotspot function F, on the premise of satisfying the legality analysis, local Struct Splitting optimization can be performed on the structure field field2 in the structure struct.sRunData.field.

[0120] Please refer to Figure 2 , Figure 2 It is another flowchart of the structure domain optimization method provided by an embodiment of the present invention.

[0121] like Figure 2 As shown, the method comprises the following steps:

[0122] Step S200, obtaining an initial intermediate representation file of a source program, wherein the initial intermediate representation file is obtained based on compiling the source program.

[0123] The initial intermediate representation file is a file generated by the compiler directly compiling the source program, and the initial intermediate representation file includes intermediate representations corresponding to various codes of the source program.

[0124] The compiler compiles and optimizes the structure field of the source program and converts it into computer executable code. Figure 3 , Figure 3 It is a schematic diagram of a process of structural domain optimization provided by an embodiment of the present invention.

[0125] like Figure 3 As shown, the process may include the following main steps:

[0126] Step 1: The compiler performs static analysis on a function-by-function basis for each structure within the source program to determine the structure domains where there are opportunities for static structure hot and cold domain optimization.

[0127] Static analysis refers to analyzing the memory access mode of each structure field of a structure by analyzing the read and write operation mode, loop memory access mode and other information in the source program (or the initial intermediate representation file of the source program) without running the source program;

[0128] Since the declaration and definition of structures are mainly involved in defining functions during the process of writing source programs, the functions can be traversed one by one to analyze the static structure hot and cold domain optimization opportunities of the structure domain.

[0129] Step 2: Determine whether the compiler uses dynamic condition determination; if yes, execute step 3; if no, execute step 4.

[0130] Whether the compiler uses dynamic conditional branching can determine whether to perform dynamic analysis on structure fields to identify structure fields where there are opportunities for dynamic structure hot and cold domain optimization.

[0131] Dynamic analysis refers to analyzing the memory access mode of structure fields in actual scenarios during the running of the source program by inserting or sampling. Static analysis cannot obtain information that can only be determined at runtime, such as the number of loop executions and the execution branches during the program running process. Therefore, it cannot accurately obtain the simulated memory mode of the structure field as a variable during the actual running of the program.

[0132] Whether the compiler uses dynamic conditions depends mainly on the compiler's structure hot and cold domain optimization strategy and the target code execution environment. When the source program execution flow depends on the conditions that can only determine the memory access width at runtime, dynamic conditions are used.

[0133] Methods for determining whether the compiler uses dynamic condition determination may include: viewing compiler documentation, using performance analysis tools, code optimization, and the like.

[0134] Step 3: The compiler analyzes the hot and cold domain optimization opportunities of the dynamic structure.

[0135] Step 4: Traverse each structure.

[0136] Step 5: Determine whether the traversal is completed, if yes, execute step 10, if not, execute step 6.

[0137] Step 6: Perform global legality analysis on the structure.

[0138] Legality analysis is one of the steps in the compiler compiling and optimizing the source program. Legality analysis mainly includes:

[0139] Lexical Analysis:

[0140] The compiler breaks down the source code into a series of tokens, such as keywords, identifiers, operators, etc.

[0141] Syntax Analysis:

[0142] Based on the results of lexical analysis, the compiler constructs an abstract syntax tree (AST) of the source code, which represents the grammatical structure of the source code.

[0143] Semantic Analysis:

[0144] The compiler checks the semantic correctness in the AST, including type checking, scope resolution, etc.

[0145] Step 7: Determine whether the structure has passed the global legality analysis and whether there is an opportunity for global structure cold and hot domain optimization; if yes, proceed to step 8; if not, proceed to step 9.

[0146] Step 8: Select the corresponding structure cold and hot domain optimization strategy to perform global structure cold and hot domain optimization for the structure.

[0147] Step 9: Do not perform cold and hot domain optimization on the structure.

[0148] Step 10: Further optimize the hot and cold domains of the structure.

[0149] The solution provided in the embodiment of the present invention is mainly applied to the process of step 3.

[0150] Please continue to refer to Figure 2 , the method may further include:

[0151] Step S201, traversing the intermediate representation of each function in the initial intermediate representation file, and determining the instruction insertion position corresponding to the structure field.

[0152] Each intermediate representation in the initial intermediate representation file corresponds to each code written in the source program. For example, a function of the source program may have a corresponding intermediate representation (intermediate representation of the function) in the initial intermediate representation file.

[0153] When writing source programs, the most common situation is to access the memory of the structure in the function. Therefore, the intermediate representation of each function can be traversed in the initial intermediate representation file to accurately determine the instruction insertion position.

[0154] Exemplarily, the content of step S201 may be implemented using a dynamic profile-guided optimization (PGO) technique.

[0155] During the data collection process, PGO technology can dynamically adjust data collection strategies and parameters according to real-time data changes and system requirements to improve the efficiency and quality of data collection. Therefore, PGO technology can be used to insert sampling instructions into the initial intermediate representation file to obtain the intermediate representation file; and when running the intermediate representation file, the sampling instructions inserted by PGO technology are used to collect the number of memory access operations on the structure field to obtain memory access number collection information.

[0156] The PGO technology may include: a Profile-generate (performance analysis data generation) process and a Profile-use (performance analysis data application) process.

[0157] The Profile-generate process includes:

[0158] First, the compiler generates an intermediate representation file by inserting sampling instructions into the initial intermediate representation file according to a predetermined instrumentation or sampling rule.

[0159] Then, the compiler runs the intermediate representation file to generate a file profdata containing collected data (e.g., memory access bit width collected data). That is, steps S101 to S102 described in the embodiment of the present invention are the Profile-generate process, and when using the PGO technology to collect, the memory access number collection information is stored in the profdata file.

[0160] The Profile-use process includes:

[0161] The compiler combines the collected data (such as memory access times collected information) provided in the profdata file to guide the compiler to optimize the subsequent structure cold and hot domains of the source program, which is the implementation process of step S103 described in the embodiment of the present invention.

[0162] Step S202: inserting a sampling instruction into the initial intermediate representation file of the source program according to the instruction insertion position to obtain the intermediate representation file of the source program.

[0163] Step S203: obtaining an intermediate representation file of the source program, wherein the intermediate representation file includes a sampling instruction inserted based on a structure field of the source program.

[0164] Step S204: Run the intermediate representation file to obtain memory access times collection information of the structure field based on the sampling instruction.

[0165] Step S205 , performing structure cold and hot domain optimization processing on the structure domain according to the memory access times collection information.

[0166] In one implementation, step S201 includes:

[0167] Traversing the intermediate representations of each function in the initial intermediate representation file; determining the intermediate representation of the index operation in the intermediate representation of each function; the intermediate representation of the index operation is compiled based on the index operation instruction, and the index operation instruction is used to perform a memory access operation on the structure field; determining the instruction position corresponding to the intermediate representation of the index operation as the instruction insertion position corresponding to the structure field.

[0168] In the embodiment of the present invention, the number of memory access operations performed on the structure field is collected. Therefore, in each intermediate representation of the initial intermediate representation file, the intermediate representation corresponding to the instruction (index operation instruction) for performing the memory access operation on the structure field is determined, and the sampling instruction is inserted at the position of the intermediate representation corresponding to the instruction, so as to collect the number of memory accesses.

[0169] It should be noted that, since the structure (struct) of the source program is a data type, multiple variables (structure fields) of different or same types can be combined into a single data type (i.e., structure). Therefore, when performing an index operation on a structure field in a structure, it usually means accessing or modifying a specific element in the structure. Therefore, when determining the instruction insertion position corresponding to the structure field, the index operation instruction for accessing or modifying the structure field can be used as the basis. The index operation instruction in the source program can be represented by the corresponding IR in the initial intermediate representation file, i.e., the IR of the index operation.

[0170] At the intermediate representation (IR) level, the execution process of the above index operation instructions can be understood as the following steps:

[0171] Base address acquisition: determine the starting address of the structure array.

[0172] Offset calculation: Calculate the offset of the desired index. This is usually done by multiplying the index value by the size of the structure element.

[0173] Address calculation: Add the base address and the offset to get the address of a specific element.

[0174] Load or store: Perform a load or store operation on the obtained address to read or write the value of the integer field.

[0175] In one implementation, determining the instruction position corresponding to the intermediate representation of the index operation as the instruction insertion position corresponding to the structure field includes:

[0176] Determine the intermediate representation of the corresponding value-taking instruction based on the intermediate representation of the index operation; determine the intermediate representation of the user instruction using the value-taking result of the intermediate representation of the value-taking instruction; and determine the instruction position corresponding to the intermediate representation of the user instruction for different use methods of the value-taking result as the instruction insertion position corresponding to the structure field.

[0177] Determining the intermediate representation of the corresponding value-taking instruction based on the intermediate representation of the index operation can be understood as: according to the memory access operation mode corresponding to the index operation, determining the instruction that can execute the memory access operation mode, thereby obtaining the value-taking instruction, and then finding the intermediate representation of the value-taking instruction in the intermediate representation file. For example, if the memory access operation mode of the index operation is to read a certain structure field a, then the instruction that can execute the reading of the structure field a is used as the value-taking instruction.

[0178] That is to say, determining the intermediate representation of the corresponding value-taking instruction based on the intermediate representation of the index operation can be understood as finding all value-taking instructions (such as load value-taking instructions or store value-taking instructions) that read or write structure fields in the structure.

[0179] The instruction that uses the result of the value-taking instruction to perform other operations is a user instruction, so the intermediate representation of the user instruction can be determined in the intermediate representation file according to the user instruction. For example, the instruction that uses the result of the value-taking instruction that reads the structure field a to perform the sum of a+b=c can be a user instruction.

[0180] In one implementation, the method of using the value acquisition result includes: reading the value acquisition result, writing the value acquisition result, or indirectly reading and writing the value acquisition result.

[0181] The indirect reading and writing of the value result may refer to the reading or writing of data (value result) by indirect addressing or pointer. Indirect addressing is a memory addressing mode in which the memory address is not given directly but stored in a register or memory location, and the program accesses the data by reading this address.

[0182] Sampling instructions are inserted in correspondence with various types of usage of value-taking results, so as to meet the usage of value-taking results and enhance the reliability of information collected on the number of memory accesses.

[0183] In one embodiment, inserting the sampling instruction into the initial intermediate representation file of the source program according to the instruction insertion position to obtain the intermediate representation file of the source program includes:

[0184] At the instruction position, a sampling instruction is inserted to obtain an intermediate representation file of the source program; the sampling instruction is a counter instruction, which is used to record the number of memory access operations performed on the structure field when the intermediate representation file is running.

[0185] The number of memory access operations of the structure domain is recorded through a counter instruction, so that the number of access operations of the structure domain can be counted, so as to fully optimize the hot and cold domains of the structure according to the specific number of memory accesses.

[0186] Taking the aforementioned PGO technology as an example, the collection of the number of memory access operations on the structure field when the intermediate representation file is running, the implementation process of the PGO technology can be referred to Figure 4 , Figure 4 The present invention is a schematic diagram of an implementation process of inserting a sampling instruction using the structure domain optimization method provided by an embodiment of the present invention.

[0187] like Figure 4 As shown, when PGO is used to collect the number of memory accesses in the structure domain, two processes are included: Profile-generate and Profile-use.

[0188] First, in the Profile-generate process, sampling instructions are inserted into the initial intermediate representation file according to the instrumentation rules to form an intermediate representation file, including:

[0189] Step S30: Designing instrumentation rules on the compiler.

[0190] The instrumentation rules can be determined based on the judgment principle of whether to perform memory access operations on the structure field.

[0191] Step S31: traverse the IRs of each Function one by one, and determine the IR of the index operation for accessing the structure field in the IR of each Function.

[0192] Step S32: traverse the IR of the value-taking instruction, and determine the IR of the User using the value-taking result of the IR of the value-taking instruction.

[0193] The IR of the fetch instruction is determined based on the IR of the index operation.

[0194] Step S33: Determine that the method of using the value result is to read the value result. Then execute step S36 to insert a sampling instruction, that is, a counter instruction.

[0195] Step S34: Determine that the use mode of the value result is to write the value result. Then execute step S36 to insert a counter instruction.

[0196] Step S35: Determine that the use mode of the value result is to read and write the value result indirectly. Then execute step S36 to insert a counter instruction.

[0197] A counter instruction is inserted at the IR position of User corresponding to each use mode of the value result, so that when the intermediate representation file is running, the actual number of memory accesses is determined based on the use mode of the value result at the position.

[0198] Step S36: insert the counter instruction through the Instrument method to establish the connection between the structure field and the counter instruction.

[0199] PGO technology is used to establish the connection between counter instructions and structure fields in the intermediate representation file, so that the values ​​of these counters can be updated when the intermediate representation file is running. In this way, the compiler can make smarter structure hot and cold domain optimization decisions based on the data collected by these counters.

[0200] The embodiment of the present invention further provides a structure domain optimization device to implement the structure domain optimization method described in the above embodiment.

[0201] Please refer to Figure 5 , Figure 5 It is a structural schematic diagram of a structural domain optimization device provided in an embodiment of the present invention.

[0202] like Figure 5 As shown, the device comprises:

[0203] An intermediate representation file acquisition module 51 is used to acquire an intermediate representation file of a source program, wherein the intermediate representation file includes a sampling instruction inserted based on a structure field of the source program, wherein the sampling instruction is used to collect the number of memory access operations performed on the structure field when the structure field is running;

[0204] An intermediate representation file running module 52, used to run the intermediate representation file to obtain the memory access times collection information of the structure field based on the sampling instruction;

[0205] The structure domain optimization module 53 is used to optimize the structure domain according to the memory access times collection information.

[0206] Optionally, the intermediate representation file running module 52 is used to run the intermediate representation file to obtain the memory access times collection information of the structure field based on the sampling instruction, including:

[0207] Running the intermediate representation file;

[0208] For each structure field, during the operation cycle of the intermediate representation file, the number of memory accesses to the structure field by all functions of the source program is collected to obtain information on the number of memory accesses of each function;

[0209] And, the memory access times collection information of each function is added up to obtain the total memory access times collection information, and the total memory access times collection information is used as the memory access times collection information of the structure domain.

[0210] Optionally, the structure domain optimization module 53 is used to optimize the structure domain according to the memory access times collection information, including:

[0211] Determine the memory access mode of the corresponding structure field according to the total memory access times collection information, and judge whether the memory access modes of each structure field are the same;

[0212] If yes, collect information according to the total number of memory accesses corresponding to each structure domain, determine the structure domain that can be optimized, and perform structure cold and hot domain optimization processing on the determined structure domain;

[0213] If not, information is collected according to the number of function memory accesses corresponding to each structure domain, the optimizable structure domain is determined, and the determined structure domain is optimized by performing structure cold and hot domain optimization processing.

[0214] Optionally, the structure domain optimization module 53 is used to determine the memory access mode of the corresponding structure domain according to the total memory access times collection information, and judge whether the memory access modes of each structure domain are the same, including:

[0215] Determine the structure field corresponding to the total memory access times collection information, and determine the corresponding structure according to the determined structure field;

[0216] In each structure field belonging to the same structure, determine whether the total number of memory access times collected in each structure field is less than a first threshold;

[0217] If so, determine that the memory access modes of each structure field are the same;

[0218] If not, it is determined that the memory access modes of the various structure fields are different.

[0219] Optionally, when it is determined that the memory access modes of each structure domain are the same, the structure domain optimization module 53 is used to collect information according to the number of memory accesses of functions corresponding to each structure domain, determine the optimizable structure domain, and perform structure cold and hot domain optimization processing on the determined structure domain, including:

[0220] By using the function memory access times of each structure domain to collect information, the optimization strategy of the structure hot and cold domains of the structure domain is determined as the structure splitting strategy;

[0221] By utilizing the structure splitting strategy, the structure fields corresponding to the function memory access times collection information with small values ​​are split.

[0222] Optionally, when it is determined that the memory access modes of each structure domain are different, the structure domain optimization module 53 is used to collect information according to the total number of memory accesses corresponding to each structure domain, determine the optimizable structure domain, and perform structure cold and hot domain optimization processing on the determined structure domain, including:

[0223] It is determined that the optimization strategy for the hot and cold domains of the structure is the structural splitting strategy;

[0224] The structure splitting strategy is used to split the structure field corresponding to the memory access statistic collection information with a small value.

[0225] Optionally, the device further comprises:

[0226] The intermediate representation file generation module 50 is used to obtain an initial intermediate representation file of the source program, wherein the initial intermediate representation file is obtained based on compiling the source program; traverse the intermediate representation of each function in the initial intermediate representation file to determine the instruction insertion position corresponding to the structure field; and insert a sampling instruction into the initial intermediate representation file of the source program according to the instruction insertion position to obtain the intermediate representation file of the source program.

[0227] Optionally, the intermediate representation file generating module 50 is used to traverse the intermediate representation of each function in the initial intermediate representation file to determine the instruction insertion position corresponding to the structure field, including:

[0228] Traversing the intermediate representation of each function in the initial intermediate representation file;

[0229] In the intermediate representation of each function, an intermediate representation of an index operation is determined; the intermediate representation of the index operation is compiled based on an index operation instruction, and the index operation instruction is used to perform a memory access operation on the structure field;

[0230] The instruction position corresponding to the intermediate representation of the index operation is determined as the instruction insertion position corresponding to the structure field.

[0231] Optionally, the intermediate representation file generating module 50 is used to determine the instruction position corresponding to the intermediate representation of the index operation as the instruction insertion position corresponding to the structure field, including:

[0232] Determine an intermediate representation of a corresponding value fetch instruction based on the intermediate representation of the index operation;

[0233] Determine an intermediate representation of a user instruction using a value-taking result of the intermediate representation of the value-taking instruction;

[0234] The instruction position corresponding to the intermediate representation of the user instruction for different value-taking result usage modes is determined as the instruction insertion position corresponding to the structure field.

[0235] It can be seen that the technical solution provided by the embodiment of the present invention, by using the sampling instructions in the intermediate representation file during the process of running the intermediate representation file, collects the number of memory access operations performed on the structure domain, and obtains the memory access number collection information; thereby, the actual situation of the structure domain being executed with the memory access operation when the structure domain is running can be obtained. On the one hand, based on the memory access number collection information, the memory access mode of the structure domain can be determined, that is, whether the structure domain is a frequently accessed structure domain (hot domain), or a structure domain that is not frequently accessed (cold domain), or a structure domain that is not accessed (dead domain); on the other hand, based on the determination of the memory access mode of the structure domain, the specific value of the number of access operations performed on the structure domain can be clarified, so that in the structure domain with the same memory access mode, according to the number of access operations, the structure domain can be further optimized (i.e., the structure cold and hot domain optimization processing) to achieve full optimization of the structure domain, thereby improving the optimization effect of the structure domain.

[0236] An embodiment of the present invention provides an electronic device, such as a terminal device, a server device, or other computer device, comprising a memory and a processor, wherein the memory stores a program, and the processor calls the program stored in the memory to execute the structure domain optimization method as described in any of the aforementioned embodiments.

[0237] An embodiment of the present invention provides a storage medium storing a program, and when the program is executed, the structure domain optimization method as described in any of the above embodiments is implemented.

[0238] An embodiment of the present invention provides a computer program product, including a computer program, and when the computer program is executed by a processor, the structure domain optimization method as described in any one of the above embodiments is implemented.

[0239] The above describes multiple implementation schemes provided by the embodiments of the present invention. The various optional methods introduced in the implementation schemes can be combined and cross-referenced with each other without conflict, thereby extending a variety of possible implementation schemes, which can all be considered as implementation schemes disclosed and open in the embodiments of the present invention.

[0240] Although the embodiments of the present invention are disclosed above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the scope defined by the claims.

Claims

1. A structural domain optimization method, characterized in that: include: Acquire an intermediate representation file of a source program, wherein the intermediate representation file includes a sampling instruction inserted based on a structure field of the source program, wherein the sampling instruction is used to collect the number of memory access operations performed on the structure field when the structure field is running; Running the intermediate representation file to obtain memory access times collection information of the structure field based on the sampling instruction; Optimizing the structure domain according to the memory access times collection information; The memory access times collection information is used to determine the optimizable structure domains among the structure domains with the same memory access mode when it is determined that the memory access modes of the structure domains are the same.

2. The structural domain optimization method according to claim 1, characterized in that: The step of running the intermediate representation file to obtain the memory access times collection information of the structure field based on the sampling instruction includes: Running the intermediate representation file; For each structure field, during the operation cycle of the intermediate representation file, the number of memory accesses to the structure field by all functions of the source program is collected to obtain information on the number of memory accesses of each function; And, the memory access times collection information of each function is added up to obtain the total memory access times collection information, and the total memory access times collection information is used as the memory access times collection information of the structure domain.

3. The structural domain optimization method according to claim 2, characterized in that: The optimizing process of the structure domain according to the memory access times acquisition information includes: Determine the memory access mode of the corresponding structure field according to the total memory access times collection information, and judge whether the memory access modes of each structure field are the same; If yes, collect information according to the total number of memory accesses corresponding to each structure domain, determine the structure domain that can be optimized, and perform structure cold and hot domain optimization processing on the determined structure domain; If not, information is collected according to the number of function memory accesses corresponding to each structure domain, the optimizable structure domain is determined, and the determined structure domain is optimized by performing structure cold and hot domain optimization processing.

4. The structural domain optimization method according to claim 3, characterized in that: Determining the memory access mode of the corresponding structure field according to the total memory access times collection information, and judging whether the memory access modes of each structure field are the same, includes: Determine the structure field corresponding to the total number of memory access collection information, and determine the corresponding structure according to the determined structure field; In each structure field belonging to the same structure, determine whether the total number of memory access times collected in each structure field is less than a first threshold; If so, determine that the memory access modes of each structure field are the same; If not, it is determined that the memory access modes of the various structure fields are different.

5. The structural domain optimization method according to claim 4, characterized in that: When it is determined that the memory access modes of each structure domain are the same, the information is collected according to the number of memory accesses of the functions corresponding to each structure domain, the structure domain that can be optimized is determined, and the structure cold and hot domain optimization processing is performed on the determined structure domain, including: By using the function memory access times of each structure domain to collect information, the optimization strategy of the structure hot and cold domains of the structure domain is determined as the structure splitting strategy; By utilizing the structure splitting strategy, the structure fields corresponding to the function memory access times collection information with small values ​​are split.

6. The structural domain optimization method according to claim 4, characterized in that: When it is determined that the memory access modes of each structure domain are different, the information is collected according to the total number of memory accesses corresponding to each structure domain, the structure domain that can be optimized is determined, and the structure cold and hot domain optimization processing is performed on the determined structure domain, including: It is determined that the optimization strategy for the hot and cold domains of the structure is the structural splitting strategy; The structure splitting strategy is used to split the structure field corresponding to the memory access statistic collection information with a small value.

7. The structural domain optimization method according to any one of claims 1 to 6, characterized in that: Before the step of obtaining the intermediate representation file of the source program, the method further includes: Obtaining an initial intermediate representation file of a source program, wherein the initial intermediate representation file is obtained based on compiling the source program; Traversing the intermediate representation of each function in the initial intermediate representation file to determine the instruction insertion position corresponding to the structure field; According to the instruction insertion position, a sampling instruction is inserted into the initial intermediate representation file of the source program to obtain the intermediate representation file of the source program.

8. The structural domain optimization method according to claim 7, characterized in that: The traversing the intermediate representation of each function in the initial intermediate representation file to determine the instruction insertion position corresponding to the structure field includes: Traversing the intermediate representation of each function in the initial intermediate representation file; In the intermediate representation of each function, an intermediate representation of an index operation is determined; the intermediate representation of the index operation is compiled based on an index operation instruction, and the index operation instruction is used to perform a memory access operation on the structure field; The instruction position corresponding to the intermediate representation of the index operation is determined as the instruction insertion position corresponding to the structure field.

9. The structural domain optimization method according to claim 8, characterized in that: The step of determining the instruction position corresponding to the intermediate representation of the index operation as the instruction insertion position corresponding to the structure field includes: Determine an intermediate representation of a corresponding value fetch instruction based on the intermediate representation of the index operation; Determine an intermediate representation of a user instruction using a value-taking result of the intermediate representation of the value-taking instruction; The instruction position corresponding to the intermediate representation of the user instruction for different value-taking result usage modes is determined as the instruction insertion position corresponding to the structure field.

10. The structure domain optimization method according to claim 9, characterized in that: The use of the value acquisition result includes: reading the value acquisition result, writing the value acquisition result, or indirectly reading and writing the value acquisition result.

11. A structural domain optimization device, characterized in that: include: An intermediate representation file acquisition module is used to acquire an intermediate representation file of a source program, wherein the intermediate representation file includes a sampling instruction inserted based on a structure field of the source program, wherein the sampling instruction is used to collect the number of memory access operations performed on the structure field when the structure field is running; An intermediate representation file running module, used for running the intermediate representation file to obtain the memory access times collection information of the structure field based on the sampling instruction; The structure domain optimization module is used to optimize the structure domain according to the memory access times collection information.

12. The structure domain optimization device according to claim 11, characterized in that: The intermediate representation file running module is used to run the intermediate representation file to obtain the memory access times collection information of the structure field based on the sampling instruction, including: Running the intermediate representation file; For each structure field, during the operation cycle of the intermediate representation file, the number of memory accesses to the structure field by all functions of the source program is collected to obtain information on the number of memory accesses of each function; And, the memory access times collection information of each function is added up to obtain the total memory access times collection information, and the total memory access times collection information is used as the memory access times collection information of the structure domain.

13. The structure domain optimization device according to claim 12, characterized in that: The structure domain optimization module is used to optimize the structure domain according to the memory access times collection information, including: Determine the memory access mode of the corresponding structure field according to the total memory access times collection information, and judge whether the memory access modes of each structure field are the same; If yes, collect information according to the total number of memory accesses corresponding to each structure domain, determine the structure domain that can be optimized, and perform structure cold and hot domain optimization processing on the determined structure domain; If not, information is collected according to the number of function memory accesses corresponding to each structure domain, the optimizable structure domain is determined, and the determined structure domain is optimized by performing structure cold and hot domain optimization processing.

14. The structure domain optimization device according to claim 13, characterized in that: The structure domain optimization module is used to determine the memory access mode of the corresponding structure domain according to the total memory access times collection information, and judge whether the memory access modes of each structure domain are the same, including: Determine the structure field corresponding to the total number of memory access collection information, and determine the corresponding structure according to the determined structure field; In each structure field belonging to the same structure, determine whether the total number of memory access times collected in each structure field is less than a first threshold; If so, determine that the memory access modes of each structure field are the same; If not, it is determined that the memory access modes of the various structure fields are different.

15. The structure domain optimization device according to claim 14, characterized in that: When it is determined that the memory access modes of each structure domain are the same, the structure domain optimization module is used to collect information according to the number of memory accesses of functions corresponding to each structure domain, determine the optimizable structure domain, and perform structure cold and hot domain optimization processing on the determined structure domain, including: By using the function memory access times of each structure domain to collect information, the optimization strategy of the structure hot and cold domains of the structure domain is determined as the structure splitting strategy; By utilizing the structure splitting strategy, the structure fields corresponding to the function memory access times collection information with small values ​​are split.

16. The structure domain optimization device according to claim 14, characterized in that: When it is determined that the memory access modes of each structure domain are different, the structure domain optimization module is used to collect information according to the total number of memory accesses corresponding to each structure domain, determine the optimizable structure domain, and perform structure cold and hot domain optimization processing on the determined structure domain, including: It is determined that the optimization strategy for the hot and cold domains of the structure is the structural splitting strategy; The structure splitting strategy is used to split the structure field corresponding to the memory access statistic collection information with a small value.

17. The structure domain optimization device according to any one of claims 11 to 16, characterized in that: Also includes: An intermediate representation file generation module, used to obtain an initial intermediate representation file of a source program, wherein the initial intermediate representation file is obtained based on compiling the source program; The intermediate representations of each function in the initial intermediate representation file are traversed to determine the instruction insertion position corresponding to the structure field; according to the instruction insertion position, a sampling instruction is inserted into the initial intermediate representation file of the source program to obtain the intermediate representation file of the source program.

18. The structure domain optimization device according to claim 17, characterized in that: The intermediate representation file generation module is used to traverse the intermediate representation of each function in the initial intermediate representation file to determine the instruction insertion position corresponding to the structure field, including: Traversing the intermediate representation of each function in the initial intermediate representation file; In the intermediate representation of each function, an intermediate representation of an index operation is determined; the intermediate representation of the index operation is compiled based on an index operation instruction, and the index operation instruction is used to perform a memory access operation on the structure field; The instruction position corresponding to the intermediate representation of the index operation is determined as the instruction insertion position corresponding to the structure field.

19. The structure domain optimization device according to claim 18, characterized in that: The intermediate representation file generation module is used to determine the instruction position corresponding to the intermediate representation of the index operation as the instruction insertion position corresponding to the structure field, including: Determine an intermediate representation of a corresponding value fetch instruction based on the intermediate representation of the index operation; Determine an intermediate representation of a user instruction using a value-taking result of the intermediate representation of the value-taking instruction; The instruction position corresponding to the intermediate representation of the user instruction for different value-taking result usage modes is determined as the instruction insertion position corresponding to the structure field.

20. An electronic device, characterized in that: It comprises a memory and a processor, the memory stores a program, and the processor calls the program stored in the memory to execute the structure domain optimization method according to any one of claims 1 to 10.

21. A storage medium, characterized in that: The storage medium stores a program, and when the program is executed, the structure domain optimization method according to any one of claims 1 to 10 is implemented.

22. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the structure domain optimization method according to any one of claims 1 to 10 is implemented.