This application is based upon and claims the benefit of priority of the prior Japanese Patent Application No. 2015-141293, filed on Jul. 15, 2015, the entire contents of which are incorporated herein by reference.
The embodiments discussed herein are related to an optimization device, an optimization program and a method for generating of an optimized program.
In late years, a size of information system that software (program) works becomes large according to increases of the number of users and functions. According to the large scale of the information system, the performance standard demanded for the software becomes high.
A compiler compiles source program described according to programming languages such as the C language and generates an object code. In addition, the compiler has an optimization function (Option level) that rises the performance of the software. A developer optimizes a source code and the code of assembler using the optimization function, for example. And the performance enhancement of the software is planned by generating the object code based on the source code and the code of assembler which is optimized.
A technique about the optimization of the source code is disclosed in patent documents 1 and 2.
[patent document 1] Japanese Laid-Open Patent Publication No. 6-75987,
[patent document 2] Japanese National Publication of International Patent application No. 2006-505058.
However, a readability of the source code and the code of the assembler that is optimized using the optimization function tends to be low. With a drop of the readability, in case of specifications change or the obstacle correspondence of the software man-hours increase, and the software maintainability decreases.
On the other hand, in order to raise the readability of the source code and the code of the assembler, there is a method to remedy the performance by requesting an election engineer performing a remedy of performance of the software. However, cost and a man-hour produce by requesting the election engineer.
In this way, it is not easy to plan an advance of the performance while considering maintainability of the software.
According to an aspect of the embodiments, an optimization device of a program, the optimization device includes a memory to store a source code, and a processor that detects a structure or an array having a member targeted for access in a loop processing from the source code, inserts a first code declaring a pointer variable and a second code that sets an address of the structure or the array in the pointer variable before the loop processing of the source code, and replaces a code which accesses the member in the loop processing with a third code accessing the member based on the pointer variable.
The object and advantages of the invention will be realized and attained by means of the elements and combinations particularly pointed out in the claims.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory and are not restrictive of the invention.
Hereinafter, embodiments will be described according to figures. But the technical range in the invention are not limited to the embodiments, are extended the subject matters disclosed in claims and its equivalents.
[Optimization of the Source Code]
The optimization processing of source code indicates the processing which revises the source code for minimizing execute time or memory consumption by streamlining of the execute file, for example. By the optimization of the source code, it is realized to decrease the execute time of the program and decrease the quantity of memory to use. For example, the optimization processing includes processing of reduction of the access number of times to an external memory, reduction of the judgment processing in the loop processing, and the reduction of the division arithmetic, for example. The compilation program generates an object code as input with the source file after the optimization.
Firstly, an example of the source code according to the embodiment will be described.
[Source Code]
The code “cd1” depicted in
Each of the structure “members” in the structure array (members [40]) is the structure of the subject type. In the code “cd2”, the structure of the subject type has variable “math” of the char type and variable “eng” of the char type and the reservation domain “reserve [7]” as the member. The variable “math” is a variable to store, for example, a score of the mathematics, and the variable “eng” is a variable to store an English score, for example. In this way, the structure array (members [40]) has, for example, the score information of the mathematics and the English for 40 students.
In addition, the code “cd3” depicted in
In addition, the source code depicted in
The second loop processing “Ip2” is the loop processing which repeats the processing in the curly bracket (“{ }”) eight times until the counter variable “c” which is incremented reaches the value “7” from the value “0”. However the second loop processing “Ip2” is included in the first loop processing “Ip1”. Therefore, for the run time of the program, the CPU carries out the second loop processing “Ip2” in 16 (=2*8) times in total.
The third loop processing “Ip3” is loop processing to repeat 40 times of the processing in the curly bracket (“{ }”) until the counter variable “m” which is incremented by every loop reaches the value “40” from the value “0”. However, the third loop processing “Ip3” is included in the first and the second loop processing “Ip1”, “Ip2”. Therefore, for the run time of the program, the CPU carries out the third loop processing “Ip3” in “640 (=16*40)” times in total.
In addition, the third loop processing “Ip3” includes code “cd4”, “cd5” which set the value “0” in member “math” and member “eng” of the variable “Class [i] [c]. members [m]”. Especially, the “Class [i] [c]. members [m]. math=0;” “cd4” indicates processing to set the value “0” to member “math” of the structure “members” of the m number among the structure array [40] that the structure array “members” of i-th set, c-th unit has. Similarly, the code “cd5” indicates processing to set the value “0” to member “eng” of the structure “members” of the m number among the structure array [40] that the structure array “members” of i-th set, c-th unit has.
[Multidimensional Structure]
In addition, in
An arrow “p0” depicted in
In addition, the arrow “p11” depicted in
An arrow “p21” indicates an address of the first structure “members [0]” among the structure array “members [40]” that the structure “Class [0] [0]” has and indicates the address similar to the arrows “p0” and “p1”. An arrow “p22” indicates an address of the second structure “members [1]” among the structure array “members [40]” that the structure “Class [0] [0]” has.
Similarly, an arrow “p23” indicates an address of the third structure “members [2]” among the structure array “members [40]” that the structure “Class [0] [0]” has, and an arrow “p24” indicates an address of the 40th structure “members [39]”.
The processing to set the value “0” in the member “math” of the variable “Class [i] [c]. members [m]” indicated in the code “cd4” indicates the processing to set the value “0” to member “math” of each structure “members” that the address “p21”-“p24” depicted
The processing depicted in the code “cd4” includes the calculation process of the address of variable “Class [i] [c]. members [m]. math”. The calculation process includes a calculation process of the address “p1”-“p14” of the variable “Class [i] [c]”, a calculation process of a differences from the address “p1”-“p14” to the address “p21”-“p24” of member “math” of members [m] and a process to add the difference address to the address “p1”-“p14”.
In addition, the calculation process of the address “p1”-“p14” includes an acquisition process of address “p0” of the variable “Class [0] [0]”, a calculation process of the differences from the address “p0” to the address “p1”-“p14” of the variable “Class [i] [c]” and a process to add the difference address to the address “p0”. For example, the CPU (Central Processing Unit) acquires an address of the variable “Class [0] [0]” through a memory management unit, etc.
In this way, when accessing a member (in the example of
In addition, the CPU carries out the third loop processing “Ip3” total “640 (=2*8*40) times” when executing the program as mentioned above in
Accordingly, the information processing device (optimization device of the program) according to the embodiment detects a structure or an array having a member targeted for access in loop processing from a source code. In addition, the information processing device inserts the first code declaring a pointer variable and the second code setting an address of the structure or the array in a pointer variable, before the loop processing of the source code. In addition, the information processing device replaces a code accessing the member in the loop processing with the third code accessing a member based on the pointer variable.
In addition, it may be different from the description order of the code in the source code and the execution order of the code at the time of the execution of the program corresponding to the source code. Specifically, on the source code, it may be carried out before a predetermined code for the run time of the program even if it is a code described after the predetermined code. The insertion of the second code before loop processing indicates that the second code is carried out before the execution of the loop processing.
According to the example of
And the information processing device inserts the code “cd11” declaring pointer variable “members_p” and the code “cd12” which sets the address “p1”-“p14” (referring to
The code “cd11” depicted in
The code “cd12” indicates a code setting the address “&Class [i] [c]” p1-p14 of the variable “Class [i] [c]” to the pointer variable “members_p”. Based on the pointer variable “members_p,” the code “cd13”, “cd14” indicate processing of accessing each member of the variable “Class [i] [c]. members [m]”, and setting of value “0”.
The code “cd13”, “cd14” indicate a code accessing a member based on the pointer variable “members_p” having the address “p1”-“p14”. Thereby, for run time of the code “cd13”, and “cd14”, a calculation process of the address p1-p14 in the variable “Class [i] [c]” does not occur. In other words, by replacing it with the access processing based on the pointer variable, it is possible to omit the calculation process of the address of the structure (or array).
In other words, for run time of “cd13”, “cd14”, a process to acquire the address “p0” depicted in
The total loop number of times “16” (=2*8) of the second loop processing “Ip2” is largely little for the total loop number of times “640” (=16*40) of the third loop processing “Ip3”. Therefore, it is possible to largely reduce the number of times of the calculation processing of address “p1”-“p14” by moving the calculation processing of the address “p1”-“p14” outside the third loop processing “Ip3”.
In this way, the information processing device according to the embodiment restrains the calculation process of the address of the structure, by moving the calculation process of the address of the structure, including a member targeted for access in the loop processing, outside the loop processing. Thereby it is possible that the information processing device realizes the reduction of the number for a cycle of the value “address calculation processing X total loop number of times”.
In this way, throughput for the program run time largely decreases by restraining the number of times of calculating of the address in the loop processing to perform repeatedly, thereby it is possible to largely reduce the number of for a cycles needed by the execution of the program. Speedup of the execute time of the program becomes in this way feasible.
In addition, it is possible that the information processing device raise the restraint degree of calculating of the address so that the nest of the loop is deep and the loop number of times of the loop processing including the access processing is a large. In addition, it is possible that the information processing device raise the restraint degree of calculating of the address so that there is much number of codes (code “cd4”, “cd5” of
In addition, according to the optimization processing in the embodiment, it is possible to restrain the number of address registers to use because the number of times of calculating process of the address in the access processing is restrained. Thereby, it is possible to suppress latency of the processing, since frequency of performing the saving by the memory transfer to stack pointer, by lack of the address register, is decreased.
In addition, it is possible that the information processing device according to the embodiment realizes the optimization processing of source code easily without asking an engineer of the election for the optimization processing. Thereby it is possible to reduce the cost and the man-hour that optimization processing costs. In addition, the information processing device does not complicate the source code according to optimization processing. Therefore, it is possible that the information processing device maintain the maintainability of the program without decreasing the readability of the source code.
S11: The information processing device retrieves the source code from the source file “ca” and detects the structure or the array having the member targeted for access in the loop processing. According to the source code in
S12: The information processing device inserts the first code declaring a pointer variable and the second code setting an address of the structure or the array in the pointer variable before the loop processing. According to the example of
S13: The information processing device replaces a code accessing the member in the loop processing with a code accessing the member based on the pointer variable. Thus, the information processing device generates an optimized source file “cb”.
According to the example of
Firstly the instructions of the program corresponding to source file “ca” of
The instructions on 20-27 lines among the instructions on 17-37 lines corresponding to the third loop processing Ip3 indicate the processing (cd4) which sets the value “0” at the variable “Class [i] [c]. members [m]. math”. In addition, the instructions on 28-36 lines indicate the processing (cd5) that sets the value “0” in the variable “Class [i] [c]. members [m]. eng”.
In addition, the instructions on 23-25 lines among the instruction on 20-27 lines corresponding to the code “cd4” indicate the calculation process of the address “p1-p14” of the structure “Class [i] [c]”. Especially, the instruction on 23 line indicate the acquisition processing of the address “p0” of the structure “Class [0] [0]” and the instruction on line 24 indicate the calculation processing of the difference address from the address “p0” to the address “p1”-“p14” of the structure “Class [i] [c]”. In addition, the instruction on 25 line indicate the addition processing with the address “p0” and the difference address.
Similarly, the instructions on 31-33 lines among the instructions on 28-36 lines corresponding to the code “cd5” indicate the calculation process of the address “p1”-“p14” of the structure “Class [i] [c]”. The details of the processing of the instructions on 31-33 lines are similar to the processing of the instructions on 23-25 lines.
Then, the instructions of the program corresponding to the source file “cb” (referring to
According to the example of
In addition, the instruction on 23-27 lines among the instructions on 20-34 lines corresponding to the third loop processing “Ip3” indicate the processing (code cd13) which sets the value “0” in the variable “members_p->members[m]. math”. In addition, the instructions on 28-33 lines indicate the processing (code cd14) to set the value “0” in the variable “members_p->members[m]. eng”. According to the left-hand portion of
(Cycle Number)
Firstly the number of the cycles needed for the execution of the program corresponding to the source file “ca” of
Therefore, the number of the cycles needed the execution of the program corresponding to the source file “ca” of
On the other hand, according to the program corresponding to source file “cb” of
Therefore, for example, the number of cycles needed for the execution of the program corresponding to the optimized source file “ca” is the value “7813 Cycle” which is calculated according to the expression “13+2*{4+{8*(3+(4+(40*12)))}}”. In this way, by the optimization processing of the source code, the number of the cycles becomes “0.673” (≈7813/11605), and the number of cycles decreases to approximately 68%.
In addition, the example of
Then, according to
[Hardware Constitution of Information Processing Device 100]
The CPU 101 is connected to the memory 102 etc. through the bus 106 and controls the whole information processing device 100. The communication interface unit 103 is connected to other devices (not illustrated in
The auxiliary memory 111 includes a domain (not illustrated in
The compile program (below called as the compile program 120) in the compile program storage domain 120 realizes processing of compile program (optimization program) 120 by the execution of the CPU 101. The table group in the table group storage domain 130 (below called as table group 130 as follows) is the table that the compile program 120 produces. Each table included in the table group 130 will be mentioned later according to
The source file (below called as the source file “ca”) in the source file storage domain “ca” is a file becoming the input of compile program 120 and indicates the source file “ca” targeted for the optimization processing. The optimized source file in the optimized source file storage domain “cb” (called as optimized source file “cb”) is a file which is generated by optimized by the compile program 120, and indicates a file targeted for a compile.
The object file (below called as object file “ob”) in the object file storage domain “ob” is a file that the compile program 120 compiles the optimized source file “cb” as input and generates.
[Software Block of Information Processing Device 100]
The optimization module 121 generates the optimized source file “cb” as input in the source file “ca”. In addition, the optimization module 121 generates the table group 130 (referring to
In addition, the table group 130 has a loop statement detection table 131, a structure detection table 132, an optimization structure table 133, and a changed optimization structure table 134.
The loop statement detection table 131 is a table having information of the loop processing in the source code described in the source file “ca”. The details of loop statement detection table 131 will be mentioned later according to
The optimization structure table 133 is a table having information, which indicate the presence or absence of the value change of the address of the structure memorized to the structure detection table 132 for every loop processing, for every hierarchy of the structure. The details of the optimization structure table 133 will be mentioned later according to
The detection module 122 detects a code corresponding to the loop processing among the codes described in the source file “ca” as input in the source file “ca” and memorizes it to the loop statement detection table 131. In addition, the detection module 122 refers with the loop statement detection table 131, analyzes the constitution of the structure, and generates the structure detection table 132 having the information about the constitution of the structure. The structure analysis module 123 refers to the structure detection table 132, analyzes access processing in the loop processing of the structure that is detected, and generates the optimization structure table 133.
The code correction module 124 generate the name of the pointer variable based on the type of the structure to set in the pointer variable with reference to the optimization structure table 133 and memorize it to the changed optimization structure table 134. In addition, the code correction module 124 copies the source file “ca”, generates the optimized source file “cb” and revises a source code in the optimized source file “cb” with reference to the changed optimization structure table 134.
[Flow of Processing of Compile Program 120]
Then, according to a flow chart of
S21: The detection module 122 carries out the processing of detection of the loop statement and the structure as input in the source file “ca”. In addition, the structure analysis module 123 performs analysis processing of constitution of the structure with reference to the structure detection table 132. The details of the processing in the process S21 will be mentioned later according to
Especially, as mentioned above in
S22: The code correction module 124, based on the analysis result of the structure, decides the type of the pointer variable and carries out the correction processing of the code for the optimized source file “cb”. The details of the processing in the process S22 will be mentioned later according to
Especially, the code correction module 124 sets an address of the structure or the array that an address does not change at every loop processing in the pointer variable with reference to the optimization structure table 133. In other words, the code correction module 124, when the address of the structure (or array) having the member is constant outside of the loop processing, moves the set of the address of the structure concerned to outside of the loop processing. Thereby, it is possible that the code correction module 124 detects a structure (or array) that a change of the address does not occur outside of the loop processing appropriately.
In addition, the code correction module 124 decides the name of the pointer variable and memorizes the name of the pointer variable that is decided to the changed optimization structure table 134. In addition, the code correction module 124 performs the insertion and replacement processes of the code for the optimized source file “cb” based on the name of the pointer variable. The code correction module 124 moves the calculation process of the address of the detected structure (or array) outside of the loop processing according to the insertion and replacement of the code.
S23: The compile module 125 performs compile processing of the optimized source file “cb” and generates the object file “ob”. In addition, a linker module, which is not illustrated in
In addition, a user may select the right or wrong of the execution of the optimization processing according to the embodiment. Thereby it is possible to realize the debugging processing that the developer aims at the time of debugging and to raise the performance without reducing development efficiency, by performing the optimization processing after completion of the debugging.
(Processing of Process S21)
S31: The detection module 122 reads one line of code from the source file “ca”.
S32: The detection module 122 determines whether or not the end (End Of File:EOF) of the source file “ca” is detected. When the end of source file “ca” is detected (Yes of S32), the detection module 122 moves to the processing “A1”. The processing “A1” will be mentioned later in a flow chart of
S33: When the end of source file “ca” is not detected (No of S32), the detection module 122 judges whether the code that is read includes “for statement”. When the “for statement” is not included (No of S33), the detection module 122 changes for the processing of process S31 and begins to read one line of code again from the source file “ca”.
S34: On the other hand, when the code which is read includes the “for statement” (Yes of S33), the detection module 122 writes the code which is read into the loop statement detection table 131. The loop statement detection table 131 will be mentioned later according to
S35: The detection module 122 counts up the counter indicating the loop hierarchy (nest) in response to the detection of the “for statement”.
S36: The detection module 122 retrieves one line of code more from the source file “ca”.
S37: The detection module 122 judges whether the code which is read includes the “for statement”. When the code which is read includes the “for statement” (Yes of S37), the detection module 122 moves to the processing of process S34 and writes the code which is read into the loop statement detection table 131.
S38: On the other hand, when the code which is read does not include the “for statement” (No of S37), the detection module 122 judges whether the code which is read includes letter “curly bracket:}” and judges whether the letter “curly bracket:}” corresponding to the number of the loop hierarchies are detected.
S39: When the code which is read does not include the letter “curly bracket:}” (No of S38) or when the letter “curly bracket:}” corresponding to the number of the loop hierarchies are not detected although the letter “curly bracket:}” is included (No of S38), the detection module 122 writes the code which is read into the loop statement detection table 131. And the detection module 122 changes in the process S36 and begins to read one line of code more from the source file “ca”.
On the other hand, the detection module 122 changes in processing “A2” when the code which is read includes the letter “curly bracket:}” and the letter “curly bracket:}” corresponding to the number of the loop hierarchies are detected (Yes of S38). The processing “A2” will be mentioned later in a flow chart of
(Loop Statement Detection Table 131)
The item “loop constitution” indicates the code corresponding to the “for statement” which is read from the source file “ca”. The code corresponding to the “for statement” indicates codes from the “for statement” to the letter “curly bracket:}”. As illustrated in
The item “variable in the loop” indicates the name of the counter variable of the “for statement”, and the item “value” has maximum in the continuation condition expression (for example, “I<2”) of the counter variable. Therefore, the counter variable of the first loop processing “Ip1” is a variable “i”, and a value is “2”. Similarly, the counter variable of the second loop processing “Ip2” is a variable “c”, and a value is “8”, and the counter variable of the third loop processing “Ip3” is a variable “m”, and a value is “40”.
In addition, the item “code counter” indicates the number of the codes that performs the access processing to the member of the structure in a processing of the “for statement”. According to the example of
S41: The detection module 122 reads the loop statement detection table 131 (
S42: The detection module 122 judges whether the letter “period: .” is detected from the item “loop constitution” in the loop statement table 131.
S43: When letter “period: .” is detected (Yes of S42), it indicates that a code, which performs the access processing to the member of the structure, exists within the loop processing. Therefore, the detection module 122 increments the code counter and memorizes it to the loop statement detection table 131. Especially, according to the loop statement detection table 131 in
On the other hand, when the letter “period: .” is not detected (No of S42), it indicates that a code, which performs the access processing to the member of the structure, does not exist within the loop processing. Therefore, the detection module 122 moves in the processing A3 of the flow chart in
S44: Detection module 122 resolves the structure by extracting the letter “period: .” from the code which is detected. And the detection module 122 memorizes the constitution of the structure which is resolved into the structure detection table 132. The details of structure detection table 132 will be mentioned later according to
According to the loop statement detection table 131 in
After resolving the structure, the detection module 122 moves in processing A3 of the flow chart in
S45: In addition, the detection module 122, as processing A1 of the flow chart in
When the loop is the loop of multi hierarchies, in other words, when target loop processing “Ip3” is included in different loop processing “Ip2”, the total loop number of times indicates the product with the first loop number of times of the loop processing “Ip3” and the second loop number of times of different loop processing “Ip2”. For example, according to the example in
S46: When the total loop number of times exceeds the threshold (Yes of S45), the structure analysis module 123 performs the structure analysis processing which is mentioned later in
Because there is not much number of times of the access processing when the total loop number of times does not exceed the threshold (No of S45) even if the loop processing includes the access processing for the member of the structure, there is not much number of times of the calculation processing of the address, too. Therefore, a reduction rate of the number of the cycles may not grow big even if the calculation processing of address of the structure moves outside the loop processing.
Therefore, the detection module 122 according to the embodiment detects a structure or array having the member that is targeted for access in the loop processing that the total loop number of times is more than a predetermined value. In other words, it is possible that the detection module 122 detects the structure or the array that reduces significantly the number of cycles by exempt of optimizing the access process included in the loop processing, of which the total loop number of times does not exceed the threshold.
(Structure Detection Table 132)
The item “loop constitution” in the structure detection table 132 depicted in
As mentioned above in the process S44 of the flow chart in
In addition, the item “multidimensional hierarchy” indicates the hierarchy of the structure. For example, the structure “Class [i] [c]” is a two-dimensional structure. Therefore, a value of the item “multidimensional hierarchy” corresponding to each code is a value “2”.
(S46: Structure Analysis Processing)
S51: The structure analysis module 123 carries out the process S52-S59 for a code counter of the target loop processing included in the loop statement detection table 131. In other words, according to the structure detection table 132 in
S52: The structure analysis module 123 carries out the process S53-S58 of times of the number of the multidimensional hierarchies that the structure detection table 132 has. In other words, according to the structure detection table 132 in
S53: The structure analysis module 123 reads the information of the item “loop constitution” with reference to loop statement detection table 131.
S54: The structure analysis module 123 acquires the subscript of the bottom layer of the structure among the item “loop constitution” (S1-S3) in the structure detection table 132. According to the structure detection table 132 in
S55: The structure analysis module 123 adds the letter “=” to the subscript and searches a letter “subscript=” from the target loop processing of the item “loop constitution” in the loop statement detection table 131. In other words, the structure analysis module 123 searches the letter “m=”. In addition, the letter “m=” includes a letter “m++” or a letter “m−−”.
S56: The structure analysis module 123 judges whether the letter “subscript=” is detected.
S57: When the letter is not detected (No of S56), it indicates that a value of variable “m” does not change in the target loop processing. Therefore, the structure analysis module 123 memorizes a value “0 (Constant: uniformity)” to a pointer flag in the optimization structure table 133. And the structure analysis module 123 moves to the process S53 and reads information of the next high-ranking hierarchy.
S58: On the other hand, when the letter “subscript=” is detected (Yes of S56), it indicates that a value of variable “m” changes in the target loop processing. Therefore, the structure analysis module 123 memorizes a value “1 (Variable: change)” to the pointer flag in the optimization structure table 133.
According to the example of loop statement detection table 131 in
S59: The structure analysis module 123 moves to the process S60 when the loop processing of times of the number of the multidimensional hierarchies are performed.
Therefore, the structure analysis module 123 searches a letter “c=”. The third loop processing “Ip3” does not include the letter “c++”. Similarly, the structure analysis module 123 searches a letter “i=”, but the third loop processing “Ip3” does not include the letter “i++”. Therefore, the structure analysis module 123 memorizes the value “0” to the pointer flag of hierarchy S1 corresponding to value “Class [i] [c]” in the optimization structure table 133.
S60: The structure analysis module 123 finishes the processing when the structure analysis module 123 performs loop processing of times of the value of the code counter. According to the example of structure detection table 132 in
(Optimization Structure Table 133)
The item “pointer flag” is a flag indicating whether the address of the structure of each hierarchy (S1-S3) changes for every target loop processing. When the pointer flag is value “0 (Constant)”, the item “pointer flag” indicates that the address of the structure of the hierarchy concerned does not change at every loop processing. On the other hand, when the pointer flag is value “1 (Variable)”, the item “pointer flag” indicates that the address of the structure of the hierarchy concerned changes at every loop processing.
As mentioned above in the process S58 in
(Process S22)
S101: The code correction module 124 detects the type of the structure which is detected with reference to the optimization structure table 133 and decides the name of the pointer variable. And the code correction module 124 memorizes the name of the pointer variable that is decided to the changed optimization structure table 134. The details of the processing in the process S101 will be mentioned later according to a flow chart in
S102: The code correction module 124 acquires the name of the pointer variable with reference to the changed optimization structure table 134, and inserts a code declaring the pointer variable in the optimized source file “cb”. The details of the processing in the process S102 will be mentioned later according to a flow chart in
S103: The code correction module 124 inserts a code setting the address of the structure in a pointer variable before the target loop processing in the optimized source file “cb”. The details of the processing in the process S103 will be mentioned later according to a flow chart in
S104: The code correction module 124 replaces a code accessing a member in the target loop processing in the optimized source file “cb” with a code to access based on the pointer variable. The details of the processing in the process S104 will be mentioned later according to a flow chart in
(Processing of Process S101)
S61: The code correction module 124 copies the source file “ca” and generates the optimized source file “cb”.
S62: The code correction module 124 carries out the process S63-S67 for the code counter in the loop statement detection table 131. In other words, the code correction module 124 carries out the process S63-S67 for the NO “7” and the NO “8” in the structure detection table 132.
S63: The code correction module 124 reads the structure detection table 132 and the optimization structure table 133.
S64: The code correction module 124 searches whether there is a hierarchy that the pointer flag is value “0 (Constant)” with reference to the optimization structure table 133.
S65: When the hierarchy that the pointer flag is the value “0” is detected (Yes of S64), the code correction module 124 extracts the structure (or array) which is the higher structure in the hierarchy that the pointer flag is the value “1 (Variable)” and is a structure in the hierarchy that the pointer flag is the value “0”.
According to the optimization structure table 133 in
In this way, the code correction module 124 judges whether there is the address of the structure (array) of the hierarchy that the pointer flag is value “0 (Constant)”. Thereby, the code correction module 124 extracts the address of the structure (or array) (in this example an address of the value “Class [i] [c]”) that an address does not change in the loop processing “Ip3”. In other words, it is possible that the code correction module 124 appropriately detects an address of the structure or array that an address does not change at every loop processing “Ip3”.
S66: On the other hand, when a hierarchy that the pointer flag indicates value “0” is not detected (No of S64), it indicates that the address of the structure (or array) that an address does not change does not exist in the loop processing “Ip3”. Therefore, the code correction module 124 does not target the code of the target NO to the optimization.
S67: The code correction module 124 searches the type of the structure which is detected from the source code. The code correction module 124 acquires the type (tag name) of the structure by detecting a code declaring the variable of the structure which is detected from the source code. And the code correction module 124 generates the pointer variable which is added “_p” to the tag name that is acquired and memorizes it to the changed optimization structure table 134.
According to the source code in
S68: The code correction module 124 finishes processing of process S101 when the code correction module 124 performs loop processing for the value of the code counter.
(Changed Optimization Structure Table 134)
The changed optimization structure table 134 depicted in
(Processing of Process S102)
S71: The code correction module 124 carries out the process S72-S74 for a code counter in the loop statement detection table 131.
S72: The code correction module 124 reads the changed optimization structure table 134.
S73: The code correction module 124 acquires the pointer variable name that the changed optimization structure table 134 has. In other words, the code correction module 124 acquires the name “members_p” of the pointer variable.
S74: The code correction module 124 generates a code cd11 declaring the pointer variable based on the pointer variable in the changed optimization structure table 134 and the tag name of the structure and writes it in the optimized source file “cb”.
Especially, the code correction module 124 generates the tag name which is added “_t” to the name “members” of the type that is detected. And the code correction module 124 generates the code “members_t *restrict members_p;” cd11 based on the ““tag name” *restrict “pointer variable”” and write it in the optimized source file “cb”.
S75: The code correction module 124 finishes processing of process S102 when the code correction module 124 performs the loop processing for the value of the code counter.
(Processing of Process S103)
S81: The code correction module 124 generates code cd12 setting a corresponding address of the structure or the array in the structure detection table 132 to the generated pointer variable.
According to the optimization structure table 133 in
S82: The code correction module 124 judges whether the loop processing having the access processing is the loop processing included in the nest loop.
S83: When the loop processing is included in the nest loop (Yes of S82), the code correction module 124 judges whether or not the address that is set into the pointer variable changes in a higher loop processing. In other words, the code correction module 124 judges whether or not the address “& Class [i] [c]” changes in the second loop processing “Ip2”.
S84: When the address changes in the higher loop processing (Yes of S83), the code correction module 124 inserts the code cd12 before the loop processing including the access processing and within high-ranking loop processing.
According to the source code in
S85: On the other hand, when the address does not change in the higher loop processing (No of S83), the code correction module 124 inserts the code cd12 before the loop processing including the access processing and before the high-ranking loop processing.
For example, the code correction module 124 inserts the code cd12 before second and third loop processing “Ip2”, “Ip3” when the address “& Class [i] [c]” does not change in the second loop processing “Ip2”. The detail will be mentioned later according to
There is little loop number of times of the first loop processing “Ip1” for the loop number of times of the second loop processing “Ip2”. Therefore, by moving the code cd12 which performs calculation process of the address outside the second loop processing “Ip2”, it is possible to reduce the number of times of calculation process of the address p1-p14 more.
In this way, the code correction module 124, when the loop processing is included in different loop processing and an address of the structure or the array changes in the different loop processing, inserts the first and second codes “cd11”, “cd12” before the loop processing and within the different loop processing. In addition, the code correction module 124, when the address does not change in the different loop processing, inserts the first and second code “cd11”, “cd12” before the loop processing and the different loop processing. Thereby, it is possible that the code correction module 124 more reduces a number for the cycle of the program corresponding to the source code after the optimization.
S86: On the other hand, when the loop processing is not included in the nest loop (No of S82), the code correction module 124 inserts the code which is generated before the loop processing including the access processing. In other words, the code correction module 124 inserts the code cd12 before third loop processing “Ip3” including the access processing.
(Processing of Process S104)
S91: The code correction module 124 carries out the process S92-S94 for a code counter in the loop statement detection table 131.
S92: The code correction module 124 detects a code accessing the structure or array which set an address in a pointer variable in the target loop processing from the optimized source code. In other words, the code correction module 124 detects a code of the access processing for the replacement target. Especially, the code correction module 124 detects the code “Class [i] [c]. members [m]. math=0;” about the NO “7”. In addition, the code correction module 124 detects the code “Class [i] [c]. members [m]. eng=0;” about the NO “8”.
S93: The code correction module 124 adds a letter “->” to the generated pointer variable. In other words, the code correction module 124 generates the code “p_members->”.
S94: The code correction module 124 replaces a letter ““value of the structure or the array”.” with code “p_members->” about the code which is detected in the optimized source file “cb” in the process S92.
S95: When the code correction module 124 performs loop processing for the value of the code counter, the code correction module 124 moves in the process S96.
S96: The code correction module 124 memorizes the optimized source file “cb” which is revised to the auxiliary memory 111 etc.
[Example 1 of Other Source Code]
In
The code cd33, cd34 are codes accessing the member “members [temp]. math”, “members [temp]. eng” based on the pointer variable “members_p”. As same as an example of
In addition, when the address of the member for the access target does not change every one of the third loop processing Ip3, the information processing device 100 may move the calculation process of the address p21-p24 of the higher subject structure of the member “math”, outside the third loop processing “Ip3”.
In this case, the information processing device 100 inserts the code “subject_p=(subject_t*) & Class [i] [c]. members [temp];” as the code cd32. And the information processing device 100 replaces the code cd22 (referring to
In this case, it is possible to omit a calculation process of the address p21-p24 in the third loop processing Ip3 and to restrain the calculation processing of the address.
(Cycle Number)
As illustrated in
In this way, the number of cycles largely decreases when the address of the structure having a member in the loop processing Ip3 including the access processing does not change.
[Example 2 of the Source Code]
According to the code cd41 of the source code in
According to the example of
The loop number of times of first loop processing Ip1 is smaller than the loop number of times of second loop processing Ip2. Therefore, it is possible to reduce the number of times of calculation process of the address more by moving the code cd52 which performs the calculation process of the address outside the second loop processing Ip2. Thereby, the code correction module 124 reduces a number of the cycles of the program corresponding to the source code after the optimization more.
[Example 3 of the Source Code]
The above embodiments are exemplified a case to omit the address calculation of the structure which has a member. The optimization processing according to the embodiment is applicable for the array which has a plurality of members.
A code cd61 depicted in
The code cd71 indicates processing to declare the pointer variable “plist”, and the code cd72 indicates processing to set an address of value “members [i] [0]” to the pointer variable “plist”. In addition, the code cd73 indicates a code accessing to the member “members [i] [c]” based on the pointer variable “plist”.
According to the source code depicted in
In addition, the “for statement” is exemplified as the loop processing in the embodiment. However, it is not a thing limited to this example. The loop processing may include the different loop processing of “while statement” or “do statement”. The optimization processing according to the embodiment is applicable for the loop processing except the “for statement”.
All examples and conditional language provided herein are intended for the pedagogical purposes of aiding the reader in understanding the invention and the concepts contributed by the inventor to further the art, and are not to be construed as limitations to such specifically recited examples and conditions, nor does the organization of such examples in the specification relate to a showing of the superiority and inferiority of the invention. Although one or more embodiments of the present invention have been described in detail, it should be understood that the various changes, substitutions, and alterations could be made hereto without departing from the spirit and scope of the invention.
Number | Date | Country | Kind |
---|---|---|---|
2015-141293 | Jul 2015 | JP | national |