A Method for Indirect Prefetch Address Out-of-Bounds Check Based on GCC Compiler
By inserting GIMPLE statements into the GCC compiler to load the index array value and selecting an appropriate out-of-bounds checking method according to the memory reference type, the traditional manual indirect prefetching problem is solved, the workload, cost and lack of flexibility of traditional manual indirect prefetching during boundary address checking is achieved, and more efficient and flexible indirect prefetching address out-of-bounds checking is achieved.
Patent Information
- Application Number
- CN202210779449.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-04
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2042-07-04
AI Technical Summary
When performing boundary address checking, traditional manual indirect prefetching has a high workload, high cost and lacks flexibility, and it is impossible to use different address out-of-bounds checking methods according to the array memory space allocation method, resulting in unnecessary judgment instruction overhead.
In the GCC compiler, by inserting multiple GIMPLE statements in the indirect prefetch insertion stage, loading the index array value, and converting it into two memory reference types according to the array memory allocation method, different out-of-bounds checking methods are used to obtain the maximum value of the inductive variable, select the appropriate address out-of-bounds avoidance method, and finally obtain the indirect prefetch address.
It effectively reduces the work burden and difficulty of programmers, reduces the performance overhead caused by instruction jumps, and provides a more flexible method of cross-border checking to avoid unnecessary instruction overhead.
Smart Images

Figure CN115237417B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of compilers, and in particular, to a method for indirect prefetch address out-of-bounds check based on the GCC compiler. Background Art
[0002] For indirect memory access that severely restricts program execution performance, an effective solution is to adopt software data prefetch technology. The indirect prefetch technology designed and implemented based on the GCC compiler can effectively identify the indirect memory access patterns in the program and insert appropriate prefetch instructions for them. When calculating the indirect prefetch address, if the index value of the index array exceeds its upper bound value, then the dereference operation of the indexed memory reference will generate an illegal load address. Different from the prefetch operation, the load instruction acting on an illegal address will cause the program to crash.
[0003] The traditional manual indirect prefetch mainly has the following disadvantages when performing boundary address checks: 1. The workload is large, and programmers need to manually add conditional judgment statements for the source code of different high-level programming languages; 2. The cost is high, and the manually added conditional judgment statements will generate program jump instructions at the backend of the compiler; 3. It lacks flexibility. Manually inserting cannot adopt different address out-of-bounds check methods according to the array memory space allocation method, which will increase unnecessary judgment instruction overhead.
[0004] Therefore, it is necessary to provide a new method for indirect prefetch address out-of-bounds check based on the GCC compiler to solve the above technical problems. Summary of the Invention
[0005] To solve the above technical problems, the present invention provides a method for indirect prefetch address out-of-bounds check based on the GCC compiler, which can effectively reduce the workload and difficulty of programmers. In particular, it reduces the huge performance overhead caused by instruction jumps.
[0006] The method for indirect prefetch address out-of-bounds check based on the GCC compiler provided by the present invention includes: S1: In the indirect prefetch insertion stage, insert multiple GIMPLE statements to load the index array values. If the load instruction acts on an incorrect index array address, a memory exception error will occur, and then perform an index out-of-bounds check;
[0007] S2: According to different array memory allocation methods in the source program, the GCC compilation will be converted into two different memory reference types in the GIMPLE intermediate representation stage;
[0008] S3: Adopt different out-of-bounds check methods for different memory reference types to obtain the maximum value of the induction variable, that is, the maximum index value of the index array;
[0009] S4: Select different address out-of-bounds avoidance methods according to the index array memory reference type;
[0010] S5: After the above address out-of-bounds check and loading the index array value, convert the index value to the number of bytes in the indirect array element, and finally add it to the starting address of the indirect array to obtain the indirect prefetch address.
[0011] Preferably, the GIMPLE intermediate representation stage in step S2 can be converted into two different memory reference types, mem_ref and array_ref. The memory reference type of statically allocated arrays is array_ref, and the memory reference type of dynamically allocated arrays is mem_ref.
[0012] Preferably, for statically allocated arrays, the array element stride and the array initial address are implicitly represented in a form similar to the source program, while for dynamically allocated arrays, the above information is explicitly represented and can be directly observed from the GIMPLE intermediate representation.
[0013] Preferably, when it is determined that the memory reference type of the index array is mem_ref after obtaining the induction variable, the induction variable is converted by the corresponding number of bytes, then the offset bytes of the induction variable and the offset bytes of the prefetch distance are added, and then the GIMPLE ternary operation statement is used to detect whether the current induction variable value is out of bounds. After that, the starting address of the array is retrieved and added to the current induction variable value, and finally, a mem_ref memory reference is inserted to load the index array value to obtain the indirect prefetch address.
[0014] Preferably, when it is determined that the memory reference type of the index array is array_ref after obtaining the induction variable, the induction variable is added to the prefetch forward distance, and then an array_ref memory reference is inserted to load the index array value to obtain the indirect prefetch address.
[0015] Compared with the related art, the method for checking the out-of-bounds of the indirect prefetch address provided by the present invention based on the GCC compiler has the following beneficial effects:
[0016] The present invention provides a method for checking the out-of-bounds of the indirect prefetch address based on the GCC compiler. Compared with the existing method of manually inserting prefetch for out-of-bounds check, this solution can effectively reduce the workload and difficulty of programmers, especially reducing the huge performance overhead caused by instruction jumps. In addition, a more flexible out-of-bounds check method is designed for the complex intermediate representation of GCC. For example, for the array_ref type memory reference, the original check instructions of the index array can be utilized without inserting additional address check instructions at the GIMPLE stage, avoiding unnecessary instruction overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a schematic structural diagram of the array_ref memory reference type provided by the present invention;
[0018] Figure 2 Schematic diagram of the mem_ref memory reference type structure provided by the present invention;
[0019] Figure 3 Schematic diagram of the out-of-bounds detection method provided by the present invention. Specific implementation manners
[0020] In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0021] The following describes the specific implementation of the present invention in detail with reference to specific embodiments.
[0022] Please refer to Figures 1 to 3 , a method for out-of-bounds check of indirect prefetch addresses based on the GCC compiler provided by an embodiment of the present invention, the method for out-of-bounds check of indirect prefetch addresses based on the GCC compiler includes:
[0023] S1: In the indirect prefetch insertion stage, insert multiple GIMPLE statements to load the index array values. If the load instruction acts on an incorrect index array address, a memory exception error will occur, and then an index out-of-bounds check is performed;
[0024] S2: According to different memory allocation methods of arrays in the source program, the GCC compilation is converted into two different memory reference types in the GIMPLE intermediate representation stage;
[0025] S3: Adopt different out-of-bounds check methods for different memory reference types to obtain the maximum value of the induction variable, that is, the maximum index value of the index array;
[0026] S4: Select different methods to avoid address out-of-bounds according to the memory reference type of the index array;
[0027] S5: After the above address out-of-bounds check and loading of the index array values, convert the index value into the number of bytes in the indirect array element, and finally add it to the starting address of the indirect array to obtain the indirect prefetch address;
[0028] The GIMPLE intermediate representation stage in step S2 can be converted into two different memory reference types, mem_ref and array_ref. The memory reference type of statically allocated arrays is of the array_ref type, and the memory reference type of dynamically allocated arrays is of the mem_ref type;
[0029] For statically allocated arrays, the stride of array elements and the initial address of the array are implicitly represented in a form similar to the source program, while for dynamically allocated arrays, the above information is explicitly represented and can be directly observed from the GIMPLE intermediate representation;
[0030] After obtaining the induction variable, when it is determined that the memory reference type of the index array is of the mem_ref type, the induction variable is converted by the corresponding number of bytes, then the offset bytes of the induction variable are added to the offset bytes of the prefetch distance, and then the GIMPLE ternary operation statement is used to detect whether the value of the current induction variable is out of bounds. After that, the starting address of the array is retrieved and added to the value of the current induction variable, and finally, a mem_ref memory reference is inserted to load the value of the index array to obtain the indirect prefetch address;
[0031] After obtaining the induction variable, when it is determined that the memory reference type of the index array is of the array_ref type, the induction variable is added to the prefetch forward distance, and then an array_ref memory reference is inserted to load the value of the index array to obtain the indirect prefetch address;
[0032] It should be noted that: in the indirect prefetch insertion stage, multiple GIMPLE statements need to be inserted to load the value of the index array. If the load instruction acts on the wrong index array address, a memory exception error will occur. Therefore, index out-of-bounds checking is required; depending on the different memory allocation methods of arrays in the source program, the GCC compilation will be converted into two different memory reference types, mem_ref and array_ref, in the GIMPLE intermediate representation stage, as shown in the appendix Figure 1 for the GIMPLE intermediate representation forms under different memory allocation modes in the C language program; for statically allocated arrays, the stride of array elements and the initial address of the array are implicitly represented in a form similar to the source program, while for dynamically allocated arrays, the above information is explicitly represented and can be directly observed from the GIMPLE intermediate representation; due to the complex intermediate representation form of the GCC compiler, after obtaining the induction variable, when it is determined that the memory reference type of the index array is of the mem_ref type, the induction variable is converted by the corresponding number of bytes, then the offset bytes of the induction variable are added to the offset bytes of the prefetch distance, and then the GIMPLE ternary operation statement is used to detect whether the value of the current induction variable is out of bounds. After that, the starting address of the array is retrieved and added to the value of the current induction variable, and finally, a mem_ref memory reference is inserted to load the value of the index array to obtain the indirect prefetch address. If the memory reference type of the index array is of the array_ref type after obtaining the induction variable, the induction variable is added to the prefetch forward distance, and then an array_ref memory reference is inserted to load the value of the index array to obtain the indirect prefetch address.
[0033] The circuits and controls involved in the present invention are all prior arts and will not be elaborated here.
[0034] The above are only embodiments of the present invention, and do not limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in other related technical fields, shall similarly be included within the patent protection scope of the present invention.
Claims
1. A method for indirect prefetch address out-of-bounds check based on the GCC compiler, characterized in that, it includes the following steps: S1: In the indirect prefetch insertion stage, insert multiple GIMPLE statements to load the index array values. If the load instruction acts on an incorrect index array address, a memory exception error will occur, and then perform an index out-of-bounds check; S2: The GCC compilation converts to two different memory reference types in the GIMPLE intermediate representation stage according to the different memory allocation methods of arrays in the source program; S3: Adopt different out-of-bounds check methods for different memory reference types to obtain the maximum value of the induction variable, that is, the maximum index value of the index array; S4: Select different address out-of-bounds avoidance methods according to the memory reference type of the index array; S5: After the above address out-of-bounds check and loading the index array values, convert the index value to the number of bytes in the indirect array element, and finally add it to the starting address of the indirect array to obtain the indirect prefetch address.
2. The method for indirect prefetch address out-of-bounds check based on the GCC compiler according to claim 1, characterized in that, the GIMPLE intermediate representation stage in step S2 can be converted into two different memory reference types, mem_ref and array_ref. The memory reference type of statically allocated arrays is array_ref, and the memory reference type of dynamically allocated arrays is mem_ref.
3. The method for indirect prefetch address out-of-bounds check based on the GCC compiler according to claim 2, characterized in that, For statically allocated arrays, the array element step size and the array initial address are implicitly represented in a form similar to the source program, while for dynamically allocated arrays, the above information is explicitly represented and can be directly observed from the GIMPLE intermediate representation.
4. The method for indirect prefetch address out-of-bounds check based on the GCC compiler according to claim 1, characterized in that, When it is determined that the memory reference type of the index array is mem_ref after obtaining the induction variable, the induction variable is converted into the corresponding number of bytes, then the offset bytes of the induction variable and the offset bytes of the prefetch distance are added, and then the GIMPLE ternary operation statement is used to detect whether the current induction variable value is out of bounds. After that, the starting address of the array is retrieved and added to the current induction variable value, and finally, the mem_ref memory reference is inserted to load the index array value to obtain the indirect prefetch address.
5. The method for indirect prefetch address out-of-bounds check based on the GCC compiler according to claim 1, characterized in that, When it is determined that the memory reference type of the index array is array_ref after obtaining the induction variable, the induction variable is added to the prefetch forward distance, and then the array_ref memory reference is inserted to load the index array value to obtain the indirect prefetch address.