WO2009098739A1 - プログラム最適化装置およびプログラム最適化方法 - Google Patents

プログラム最適化装置およびプログラム最適化方法 Download PDF

Info

Publication number
WO2009098739A1
WO2009098739A1 PCT/JP2008/002843 JP2008002843W WO2009098739A1 WO 2009098739 A1 WO2009098739 A1 WO 2009098739A1 JP 2008002843 W JP2008002843 W JP 2008002843W WO 2009098739 A1 WO2009098739 A1 WO 2009098739A1
Authority
WO
WIPO (PCT)
Prior art keywords
intermediate code
program
variable
node
value
Prior art date
Application number
PCT/JP2008/002843
Other languages
English (en)
French (fr)
Inventor
Dai Hattori
Tomoo Hamada
Original Assignee
Panasonic Corporation
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Panasonic Corporation filed Critical Panasonic Corporation
Priority to JP2009535722A priority Critical patent/JPWO2009098739A1/ja
Priority to US12/668,967 priority patent/US20100199269A1/en
Publication of WO2009098739A1 publication Critical patent/WO2009098739A1/ja

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation

Definitions

  • the present invention relates to an optimization device and an optimization method for optimizing a computer program, and more particularly to an optimization device and an optimization method for optimizing a computer program based on the properties of data at the time of execution.
  • Non-Patent Document 1 the analysis range for the source program is expanded, and constant propagation between procedures (interprocedural constant propagation) based on the analysis results of interprocedural analysis is possible. There is a method of improving the processing time at the time of execution by performing calculation processing at the time of compilation as much as possible.
  • the frequency of occurrence of a variable can be obtained by executing a program, a specialized program is generated when the variable is a specific value, and the variable appears There is a method of improving the processing time at the time of execution at a specific value having a high frequency.
  • JP 2002-259135 A Paul R. Carini, M. Hind, "Flow-Sensitive Interprocedural Constant Propagation", The ACM SIGPLAN Conference on Programming Language Design and Implementation, 1995
  • the optimization method as described above is an optimization based on the analysis result of the source program. For this reason, the optimization depending on the characteristics of the data processed by the execution of the program cannot be performed. Even when optimization is performed depending on data characteristics, it is necessary to execute a program before optimization.
  • the present invention has been made to solve the above-described problems, and does not require execution of a program before optimization, and allows program optimization that enables optimization depending on the characteristics of data processed by execution of the program.
  • An object of the present invention is to provide a device.
  • a program optimization device is a program optimization device that optimizes an input program described in a programming language, and is used in the intermediate code conversion unit that converts the input program into intermediate code, and the input program
  • a variable value setting unit that obtains a possible value of the variable to be obtained from information given from the outside, and sets the possible value of the acquired variable in the intermediate code; and based on the possible value of the set variable
  • possible values of variables used in the input program are acquired in advance, and the intermediate code can be optimized based on the values.
  • the characteristics of data processed by the execution of the program as possible values of the variables, optimization depending on the characteristics of the data processed by the execution of the program can be performed.
  • variable value setting unit acquires a value that can be used by the variable used in the input program by an input from a user, and sets the value that can be acquired by the acquired variable in the intermediate code.
  • variable value setting unit obtains a value that can be taken by a variable used in the input program from an indicator described in the input program, and uses the obtained value that the variable can take as the intermediate code. It may be set.
  • variable value setting unit may acquire a possible value of a variable used in the input program from a predetermined file, and set the possible value of the acquired variable in the intermediate code.
  • the intermediate code optimizing unit may convert a node having only one possible value among a plurality of nodes included in the intermediate code when the intermediate code is represented in a tree structure to a node indicating a constant. It may be replaced.
  • the intermediate code optimization unit for the node expressing the conditional branch when the intermediate code is represented by a tree structure, branches that depend on a value that is not included in the values that the node can take. You may delete more.
  • the intermediate code optimization unit includes a plurality of variable nodes that branch a node including a variable node indicating a variable that can take a plurality of values when the intermediate code is expressed in a tree structure according to the possible values.
  • the variable node included in each of the plurality of nodes after conversion may be replaced with a constant node indicating a possible value as a branch condition.
  • the number of substitutions to constants can be increased using the value calculated from the possible values of the variables, while the number of branches is small. It can also increase the possibility of improvement.
  • the intermediate code optimization unit calculates a value that a node can take when the intermediate code is represented in a tree structure from a value that the variable can take, and based on the value that the node can take,
  • the code may be optimized.
  • a program optimization device is a program optimization device that optimizes an input program described in a programming language, and is used in the intermediate code conversion unit that converts the input program into intermediate code, and the input program
  • a variable value setting unit that obtains a possible value of the variable to be obtained from information given from outside, sets the possible value of the acquired variable to a node when the intermediate code is represented in a tree structure, and
  • An intermediate code optimization unit that optimizes the intermediate code based on possible values, and an output program that converts the intermediate code optimized by the intermediate code optimization unit into an output program described in a predetermined format You may provide a conversion part.
  • possible values of variables used in the input program are acquired in advance, and the intermediate code can be optimized based on the values.
  • the characteristics of data processed by the execution of the program as possible values of the variables, optimization depending on the characteristics of the data processed by the execution of the program can be performed.
  • the intermediate code optimizing unit may convert a node having only one possible value among a plurality of nodes included in the intermediate code when the intermediate code is represented in a tree structure to a node indicating a constant. It may be replaced.
  • the intermediate code optimization unit for the node expressing the conditional branch when the intermediate code is represented by a tree structure, branches that depend on a value that is not included in the values that the node can take. You may delete more.
  • the intermediate code optimization unit includes a plurality of variable nodes that branch a node including a variable node indicating a variable that can take a plurality of values when the intermediate code is expressed in a tree structure according to the possible values.
  • the variable node included in each of the plurality of nodes after conversion may be replaced with a constant node indicating a possible value as a branch condition.
  • the number of substitutions to constants can be increased using the value calculated from the possible values of the variables, while the number of branches is small. It can also increase the possibility of improvement.
  • the variable value setting unit is configured to obtain a value that can be taken by a variable used in the input program by an input from a user, and set the obtained value that the variable can take in a node of the intermediate code. There may be.
  • variable value setting unit obtains a value that can be taken by a variable used in the input program from an indicator described in the input program, and obtains the value that can be taken by the obtained variable in the intermediate code. It may be set in a node.
  • variable value setting unit acquires a value that can be taken by a variable used in the input program from a predetermined file, and sets the value that can be taken by the obtained variable to a node of the intermediate code. May be.
  • a program optimization method is a program optimization method for optimizing an input program described in a programming language, wherein the input program is converted into an intermediate code, and variables used in the input program are collected. The obtained value is acquired from information given from the outside, the obtained value of the variable is set to a node when the intermediate code is represented by a tree structure, and the intermediate code is set based on the possible value of the node. And the intermediate code optimized by the intermediate code optimization unit is converted into an output program described in a predetermined format.
  • the present invention can be realized not only as a program optimization apparatus having such a characteristic processing unit or a program optimization method including characteristic steps, but also by including characteristic steps included in the program optimization method. It can also be realized as a program executed by a computer. It goes without saying that such a program can be distributed via a recording medium such as a CD-ROM (Compact Disc-Read Only Memory) or a communication network such as the Internet.
  • a recording medium such as a CD-ROM (Compact Disc-Read Only Memory) or a communication network such as the Internet.
  • the value calculated from the possible values of the variables is used to increase the number of substitutions to constants while the number of branches is small. The possibility of speed improvement can also be increased.
  • FIG. 1 is a diagram showing a program optimization apparatus according to an embodiment of the present invention.
  • FIG. 2 is a flowchart of processing executed by the program optimization apparatus of the present invention.
  • FIG. 3 is a diagram illustrating an example of the input program.
  • FIG. 4 is a diagram illustrating an example of the intermediate code.
  • FIG. 5 is a diagram showing the intermediate code shown in FIG. 4 and the values that can be taken by each node included in the intermediate code.
  • FIG. 6 is a diagram illustrating an example of data chain information.
  • FIG. 7 is a diagram illustrating a set of constants that are calculation results of the node value calculation unit.
  • FIG. 8 is a diagram for explaining an example of the first conversion of the intermediate code optimization unit.
  • FIG. 1 is a diagram showing a program optimization apparatus according to an embodiment of the present invention.
  • FIG. 2 is a flowchart of processing executed by the program optimization apparatus of the present invention.
  • FIG. 3 is a diagram illustrating an example of the input program.
  • FIG. 9 is a diagram for explaining an example of the third conversion of the intermediate code optimization unit.
  • FIG. 10 is a diagram showing an output program converted from the input program shown in FIG. 3 according to the present invention.
  • FIG. 11 is a diagram showing an output program converted from the input program shown in FIG. 3 according to the prior art.
  • FIG. 12 is a diagram illustrating a modification of the program optimization device.
  • FIG. 13 is a diagram illustrating an example of an input program.
  • FIG. 14 is a diagram illustrating an example of a specified file.
  • FIG. 15 is a diagram illustrating a modification of the program optimization device.
  • FIG. 16 is a diagram illustrating an example of a GUI.
  • FIG. 17 is a diagram illustrating an example of a GUI.
  • the program optimization apparatus 101 is an apparatus that converts an input program 111 describing a program to be optimized into an output program 112 that is an optimized program.
  • the program optimization apparatus 101 includes an intermediate code conversion unit 121 and a variable value setting unit 122.
  • the program optimization apparatus 101 is realized by executing a program for realizing each processing unit on a normal computer including a processor and a memory. Note that programs, codes, data, and the like used in the processing of the program optimization apparatus 101 are temporarily stored in a computer memory or the like.
  • the intermediate code conversion unit 121 converts the input program 111 into the intermediate code 131.
  • the input program 111 is described in an existing programming language such as C language, for example.
  • the intermediate code 131 expresses the contents of the input program 111 in an existing program expression format such as an abstract syntax tree.
  • the variable value setting unit 122 sets the possible value of the variable as a set of constants in the intermediate code 131 for the variable described in the input program 111.
  • Possible values of variables can be specified by describing an indicator such as pragma in the input program 111. It can also be specified by describing information indicating possible values of variables in a file separate from the input program. Furthermore, it is possible to specify an input program by a user input using GUI (Graphical User Interface). Note that the user input does not necessarily need to use the GUI, and the user input may be received using another interface.
  • GUI Graphic User Interface
  • the node value calculation unit 123 calculates values that each node can take when the intermediate code 131 is represented in a tree structure based on a set of constants for the variables set by the variable value setting unit 122.
  • the intermediate code optimization unit 124 converts the intermediate code according to one of the following three conversion methods based on the value that each node of the intermediate code 131 calculated by the node value calculation unit 123 can take. .
  • the first conversion method is a method of replacing a node with a constant node representing a value that can be taken by the node when the value that the node can take is one.
  • the second conversion method is a method in which, when a node is a node expressing a conditional branch, a conditional branch with a value that is not included in the values that the node can take is deleted from the intermediate code.
  • the third conversion method is a method of generating branches as many as the number of elements of a set of constants and replacing the nodes with constant nodes in each branch as in the first conversion.
  • the output program conversion unit 125 converts the optimized intermediate code 131 into the output program 112 described in a predetermined format.
  • the format of the output program 112 is, for example, C language, assembly language, machine language, etc., when the program optimization apparatus 101 is used as a C compiler, and Verilog language, etc. when used as a high-level synthesis tool. .
  • FIG. 2 is a flowchart of processing executed by the program optimization device.
  • the intermediate code conversion unit 121 converts the input program 111 into the intermediate code 131 (S211).
  • FIG. 3 is a diagram illustrating an example of the input program.
  • FIG. 4 is a diagram illustrating an example of the intermediate code 131. This figure shows an intermediate code obtained as a result of converting the sentence S5 on the 13th line of the input program 301 shown in FIG.
  • This intermediate code is expressed by a tree structure including nodes S5_a and S5_r indicating variable references, a node S5_1 indicating a constant, and a node S5_add indicating an operation.
  • variable value setting unit 122 sets a set of constants indicating possible values of the variable for the node indicating the variable reference (variable reference node) (S212).
  • the values that the variable a can take are ⁇ 0, 1 ⁇ and the values that the variable c can take are ⁇ 0, 2, 4 ⁇ , respectively. It is a description that specifies that there is.
  • the variable value setting unit 122 acquires possible values of the variable from the program description of the input program 111, and sets a set of constants ⁇ 0, 1 ⁇ for the node that references the variable a.
  • a set of constants ⁇ 0, 2, 4 ⁇ is set for the node that refers to the variable c.
  • the node value calculation unit 123 calculates, for each node included in the intermediate code 131, a set of constants indicating values that the node can take (S213).
  • a set of constants ⁇ 0, 1 ⁇ is already set in the node S5_a indicating the reference of the variable a as described in the pragma description in the third line of the input program 301 shown in FIG.
  • the constant node S5_1 has only “1” as a possible value.
  • the node value calculation unit 123 calculates a set of constants ⁇ 1 ⁇ as values that the constant node S5_1 can take.
  • addition node S5_add addition of the value of the node S5_a which is an operand and the value of the node S5_1 is performed. Therefore, the node value calculation unit 123 takes the value of the addition node S5_add from the set of constants ⁇ 0, 1 ⁇ indicating the values that the node S5_a can take and the set of constants ⁇ 1 ⁇ that can indicate the values that the node S5_1 can take.
  • ⁇ 1,2 ⁇ is calculated as a set of constants indicating the obtained values. Further, the node value calculation unit 123 calculates the same set of constants ⁇ 1, 2 ⁇ as the set of constants indicating the possible values of the addition node S5_add for the node S5_r indicating the reference of the variable r.
  • the node value calculation unit 123 propagates a set of constants based on the chain information of data, similarly to constant propagation which is a general optimization method.
  • the variable r defined on the 10th to 14th lines of the input program 301 shown in FIG. 3 is used in the sentence on the 17th line.
  • the data chain information of the sentence nodes S2 to S6 corresponding to the 10th to 14th lines and the sentence node S7 corresponding to the 17th line is expressed as a graph indicating the chain destination from the chain source as shown in FIG. it can. That is, the sentence nodes S2 to S6 that define the variable r indicate the chain source, and the statement node S7 that refers to the variable r is expressed as the chain destination.
  • the node value calculation unit 123 calculates a set of constants for the sentence node S7 based on the set of constants for the sentence nodes S2 to S6 based on the chain information of the data. That is, the node value calculation unit 123 calculates a set of chained constants as a union of a set of chained constants based on data chain information. As a result, a set of constants of the reference node S7_r of the variable r in the sentence node S7 is calculated.
  • FIG. 7 is a diagram illustrating a part of a set of constants set in a node included in the intermediate code 131.
  • the set of constants set in the node is a set indicating values that can be taken by each node included in the intermediate code 131.
  • An empty set ⁇ is set for a node for which a set of constants could not be calculated, which indicates that an arbitrary value can be taken.
  • the intermediate code optimization unit 124 converts the intermediate code 131 using the calculated set of node constants (S214). There are the following three conversion methods for the conversion of the intermediate code 131.
  • the first conversion is a conversion in which, when the number of elements in a set of node constants is one, the corresponding node is replaced with a constant node that represents an element of the set.
  • FIG. 8A shows an intermediate code before conversion in the sentence node S9 of the input program 301.
  • FIG. 8B is a diagram showing the converted intermediate code in the sentence node S9.
  • the set of constants in the reference node S9_n of the variable n calculated by the node value calculation unit 123 is ⁇ 1 ⁇ as shown in FIG. 7, and the number of elements is one. Therefore, the intermediate code optimization unit 124 replaces the reference node S9_n of the variable n with a constant node S9_1 that expresses the numerical value “1” that is the element.
  • the sentence node S8 becomes an unnecessary code. Therefore, the intermediate code optimization unit 124 deletes the sentence node S8 by optimization of unnecessary code deletion, which is a general optimization method. As a result, the program size can be reduced.
  • the second conversion is a conversion in which a branch that depends on a value not included in the set of constants of the node is deleted from the intermediate code.
  • a set of constants of the node S1_s indicating the branch condition in the branch statement node S1 of the input program 301 is ⁇ 1, 3, 5 ⁇ as shown in FIG.
  • the branch “case0” indicated by the sentence node S2 is a conditional branch when the value of the node S1_s is “0”.
  • the node S1_s does not include the element “0”. For this reason, statement S2 is not executed at the time of program execution. Therefore, the intermediate code optimization unit 124 deletes the branch “case0” indicated by the statement node S2.
  • the intermediate code optimization unit 124 also deletes the branch “case2” indicated by the sentence node S4. Thereby, the branch is reduced to a branch of only the sentence nodes S3, S5, and S6 as shown in the output program 401. It is obvious that the program size is reduced as a result of this replacement.
  • the third transformation is a transformation in which branches corresponding to the number of elements in the set of constants are generated, and nodes are replaced with constant nodes in the same manner as the first transformation in each branch.
  • FIG. 9A shows an intermediate code before conversion in the sentence node S7 of the input program 301 shown in FIG.
  • FIG. 9B shows the intermediate code after conversion in the sentence node S7.
  • the set of constants of the reference node S7_r of the variable r is ⁇ 0, 1, 2 ⁇ .
  • the intermediate code optimization unit 124 generates branches corresponding to 0, 1, and 2 as shown in FIG. 9B.
  • the intermediate code optimization unit 124 converts the intermediate code by replacing the reference node S7_r of the variable r with a constant node.
  • the branch is indicated by sentence nodes S72, S74, S76.
  • the sentence nodes S72, S74, and S76 are generated by duplicating the sentence node S7 and replacing the node corresponding to the reference node S7_r of the variable r with the constant nodes S72_0, S74_1, and S76_2 indicating the constants 0, 1, and 2, respectively. Is done.
  • optimization such as constant folding, which is the optimization method of the prior art, or reduction of the operation intensity becomes possible.
  • the multiplication included in the sentence node S7 is converted into another operation and optimized to the sentence nodes S72 ', S74', S76 'in the output program 401 shown in FIG. If the shift operation can be executed faster than multiplication at the time of execution of the program, the execution time of the program can be improved by the third conversion. Further, when hardware is generated using an output program, the multiplier itself is not necessary. For this reason, the scale of hardware can be reduced.
  • the third conversion new branches corresponding to the number of elements are generated. For this reason, you may restrict
  • the third conversion may be performed only for elements that can be convolved with a constant by the conversion. Further, the third conversion may be performed only when the calculation includes a calculation such as multiplication or division that can reduce the calculation intensity.
  • the program optimization apparatus 101 determines whether or not intermediate code conversion has been performed (S215). If intermediate code conversion has been performed (YES in S215), the node value calculation process (S213) is performed again. ) Try further optimization by performing the following processing.
  • the output program conversion unit 125 When the conversion of the intermediate code is not performed (NO in S215), the output program conversion unit 125 outputs the output program described in a predetermined format from the intermediate code 131 optimized by the intermediate code optimization unit 124. 112 is generated (S216).
  • FIG. 10 shows an output program optimized by the program optimization apparatus 101 with respect to the input program 301.
  • FIG. 11 shows an example of an output program optimized for the input program 301 by the prior art. In FIG. 11, optimization specializing when a variable takes a specific value is performed. From FIG. 10 and FIG. 11, it is clear that the output program generated by the program optimization apparatus 101 has a smaller program size than the output program generated by the conventional technique.
  • possible values of variables used in the input program are acquired in advance, and the intermediate code is optimized based on the values. For this reason, the optimization depending on the characteristics of the data processed by the execution of the program is possible without executing the program before the optimization. Furthermore, unnecessary code can be reduced by performing optimization using information on values that cannot be obtained by variables. For this reason, it is possible to generate a code having a smaller program size than the optimization according to the prior art.
  • the value calculated from the possible values of the variables is used to increase the number of substitutions to constants while the number of branches is small. The possibility of speed improvement can also be increased.
  • the method has been described in which the input program 111 is described in the C language, and the values that the variable can take are specified by the program.
  • the value that the variable can take may be specified by describing the same information as the information specified by pragma in a separate file from the input program.
  • FIG. 12 is a diagram showing a configuration of a program optimization apparatus according to this method.
  • the program optimizing device 101a is obtained by changing the variable value setting unit 122 to the variable value setting unit 122a in the configuration of the program optimizing device 101 shown in FIG. Other configurations are the same as those of the program optimization apparatus 101.
  • the variable value setting unit 122a acquires possible values of the variable from the specification file 113, and sets the possible values of the variable as a set of constants in the intermediate code 131.
  • FIG. 13 is a diagram illustrating an example of an input program.
  • FIG. 14 is a diagram illustrating an example of a specified file. For example, when the values that can be taken by the variables a and c described in the input program 1101 are designated, information for specifying the variables a and c in the designation file 1102 and the values that the variables a and c can take. As described in the pragma description, the values that the variables a and c can take can be specified.
  • the input program can be displayed on the screen using a GUI, and the variable can be taken for a variable designated by the user with a pointer.
  • a value may be input.
  • FIG. 15 is a diagram showing a configuration of a program optimization apparatus according to this method.
  • the program optimizing device 101b is obtained by changing the variable value setting unit 122 to the variable value setting unit 122b in the configuration of the program optimizing device 101 shown in FIG. Other configurations are the same as those of the program optimization apparatus 101.
  • the variable value setting unit 122b displays the input program 111 on the display terminal 114, acquires values that can be taken by the variable by user input, and sets the values that can be taken by the variable as a set of variables in the intermediate code 131.
  • FIG. 16 is a diagram illustrating an example of an input program display window including an input program displayed on the display terminal 114.
  • FIG. 17 is a diagram illustrating an example of a variable attribute dialog. For example, consider a case in which a possible value of a variable is designated for a variable a described in the input program displayed in the input program display window 1201. The user selects the variable a with a pointer on the input program display window 1201. Next, the user causes the variable attribute dialog 1202 to be displayed on the display terminal 114 by selecting a menu for opening the variable attribute dialog 1202 from the pull-down menu. The user inputs “0, 1” as a possible value of the variable a in the variable attribute dialog 1202. Similarly, by inputting possible values for the variable c, the possible values of the variables a and c can be specified in the same manner as the pragma description.
  • the program optimization apparatus can be applied to a compiler that generates object code from a program source code and a high-level synthesis tool that generates hardware RTL (Register Transfer Level) description from a sequential processing program. This is useful when generating object code and RTL description that have been optimized depending on the data to be processed.

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

 プログラムを最適化する場合に、最適化前にプログラムの実行を必要とせずに、プログラムが処理するデータの特徴に依存した最適化を行うプログラム最適化装置は、最適化対象となる入力プログラム(111)を中間コード(131)に変換する中間コード変換部(121)と、入力プログラム(111)中の変数の取り得る値を、外部から与えられた情報に基づいて設定する変数値設定部(122)と、変数値設定部(122)で設定された値に基づき、中間コード(131)に含まれるノードの取り得る値を算出するノード値算出部(123)と、ノード値算出部(123)で算出された値に基づき、中間コードの最適化を行う中間コード最適化部(124)と、中間コード最適化部(124)で最適化された中間コード(131)を出力プログラム(112)に変換する出力プログラム変換部(125)とを備える。

Description

プログラム最適化装置およびプログラム最適化方法
 本発明は、コンピュータプログラムを最適化する最適化装置および最適化方法に関し、特に、実行時のデータの性質に基づき、コンピュータプログラムを最適化する最適化装置および最適化方法に関する。
 通常、プログラミング言語で記述されたソースプログラムをコンパイルする際に、ソースプログラムの動作を解析し、ソースプログラムの最適化処理を行う。
 例えば、一般的に知られている最適化方法として、定数の畳み込み、または不要コード削除等がある。これらの最適化方法では、コンパイル時に計算可能な演算を演算結果に置換したり、プログラム実行時に到達し得ないコード等をコンパイル後のプログラムから削除したりする。このような方法により、従来、プログラムの最適化を行っている。
 さらに、非特許文献1で開示されているように、ソースプログラムに対する解析範囲を拡大し、手続き間解析(interprocedural analysis)の解析結果に基づいて手続き間の定数伝播(interprocedural constant propagation)を行い、可能な限りコンパイル時に計算処理を行うことで、実行時の処理時間の改善を行う方法がある。
 また、特許文献1で開示されているように、プログラムを実行することにより変数の取り得る値の出現頻度を求め、変数が特定の値の場合に特殊化されたプログラムを生成し、変数が出現頻度の多い特定の値のときに実行時の処理時間の改善を行う方法がある。
特開2002-259135号公報 Paul R. Carini, M. Hind, "Flow-Sensitive Interprocedural Constant Propagation", The ACM SIGPLAN Conference on Programming Language Design and Implementation, 1995
 しかしながら、上述のような最適化手法は、ソースプログラムの解析結果に基づく最適化である。このため、プログラムの実行により処理されるデータの特徴に依存した最適化が行えない。また、データの特徴に依存した最適化を行う場合でも、最適化の前にプログラムを実行する必要がある。
 本発明は上述の課題を解決するためになされたもので、最適化の前にプログラムの実行を必要とせず、プログラムの実行により処理されるデータの特徴に依存した最適化を可能とするプログラム最適化装置を提供することを目的とする。
 本発明にかかるプログラム最適化装置は、プログラミング言語で記述された入力プログラムを最適化するプログラム最適化装置であって、前記入力プログラムを中間コードに変換する中間コード変換部と、前記入力プログラムで使用される変数の取り得る値を、外部から与えられる情報より取得し、取得した前記変数の取り得る値を前記中間コードに設定する変数値設定部と、設定された前記変数の取り得る値に基づいて、前記中間コードを最適化する中間コード最適化部と、前記中間コード最適化部により最適化された中間コードを、所定の書式で記述された出力プログラムに変換する出力プログラム変換部とを備える。
 この構成によると、入力プログラムで使用される変数の取り得る値を、予め取得し、その値に基づいて、中間コードの最適化を行うことができる。このように、プログラムの実行により処理されるデータの特徴を、変数の取り得る値として設定することにより、プログラムの実行により処理されるデータの特徴に依存した最適化を行うことができる。
 具体的には、前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、ユーザからの入力により取得し、取得した前記変数の取り得る値を前記中間コードに設定する。
 また、前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、前記入力プログラム中に記載された指示子から取得し、取得した前記変数の取り得る値を前記中間コードに設定してもよい。
 さらに、前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、所定のファイルから取得し、取得した前記変数の取り得る値を前記中間コードに設定してもよい。
 また、前記中間コード最適化部は、前記中間コードを木構造で表した際の、当該中間コードに含まれる複数のノードのうち、取り得る値が1つのみのノードを、定数を示すノードに置換してもよい。
 さらに、前記中間コード最適化部は、前記中間コードを木構造で表した際の、条件分岐を表現するノードについて、当該ノードが取り得る値に含まれない値に依存する分岐を、前記中間コードより削除してもよい。
 入力プログラム中の変数の取り得る値を指定しているため、変数の取り得る値から算出された値を利用して、算出結果が常に固定された値の場合は定数に置換したり、冗長な分岐を削除したりすることで、プログラムサイズの小さい出力プログラムを生成することもできる。
 さらに、前記中間コード最適化部は、前記中間コードを木構造で表した際の、複数の値を取り得る変数を示す変数ノードを含むノードを、取り得る値に従い分岐する前記変数ノードを含む複数のノードに変換し、変換後の前記複数のノードの各々に含まれる前記変数ノードを、分岐条件とされた取り得る値を示す定数ノードに置換してもよい。
 入力プログラム中の変数の取り得る値を指定しているため、変数の取り得る値から算出された値を利用して、少ない分岐数でありながら、定数への置換数を増やせるため、実行速度の改善の可能性を高めることもできる。
 また、前記中間コード最適化部は、前記変数の取り得る値から、前記中間コードを木構造で表した際のノードの取り得る値を算出し、前記ノードの取り得る値に基づいて、前記中間コードを最適化してもよい。
 本発明にかかるプログラム最適化装置は、プログラミング言語で記述された入力プログラムを最適化するプログラム最適化装置であって、前記入力プログラムを中間コードに変換する中間コード変換部と、前記入力プログラムで使用される変数の取り得る値を外部から与えられる情報より取得し、取得した前記変数の取り得る値を前記中間コードを木構造で表した際のノードに設定する変数値設定部と、前記ノードの取り得る値に基づいて、前記中間コードを最適化する中間コード最適化部と、前記中間コード最適化部により最適化された中間コードを、所定の書式で記述された出力プログラムに変換する出力プログラム変換部とを備えるものであってもよい。
 この構成によると、入力プログラムで使用される変数の取り得る値を、予め取得し、その値に基づいて、中間コードの最適化を行うことができる。このように、プログラムの実行により処理されるデータの特徴を、変数の取り得る値として設定することにより、プログラムの実行により処理されるデータの特徴に依存した最適化を行うことができる。
 また、前記中間コード最適化部は、前記中間コードを木構造で表した際の、当該中間コードに含まれる複数のノードのうち、取り得る値が1つのみのノードを、定数を示すノードに置換するものであってもよい。
 さらに、前記中間コード最適化部は、前記中間コードを木構造で表した際の、条件分岐を表現するノードについて、当該ノードが取り得る値に含まれない値に依存する分岐を、前記中間コードより削除するものであってもよい。
 入力プログラム中の変数の取り得る値を指定しているため、変数の取り得る値から算出された値を利用して、算出結果が常に固定された値の場合は定数に置換したり、冗長な分岐を削除したりすることで、プログラムサイズの小さい出力プログラムを生成することもできる。
 さらに、前記中間コード最適化部は、前記中間コードを木構造で表した際の、複数の値を取り得る変数を示す変数ノードを含むノードを、取り得る値に従い分岐する前記変数ノードを含む複数のノードに変換し、変換後の前記複数のノードの各々に含まれる前記変数ノードを、分岐条件とされた取り得る値を示す定数ノードに置換するものであってもよい。
 入力プログラム中の変数の取り得る値を指定しているため、変数の取り得る値から算出された値を利用して、少ない分岐数でありながら、定数への置換数を増やせるため、実行速度の改善の可能性を高めることもできる。
 また、前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、ユーザからの入力により取得し、取得した前記変数の取り得る値を前記中間コードのノードに設定するものであってもよい。
 さらに、前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、前記入力プログラム中に記載された指示子から取得し、取得した前記変数の取り得る値を前記中間コードのノードに設定するものであってもよい。
 さらに、前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、所定のファイルから取得し、取得した前記変数の取り得る値を前記中間コードのノードに設定するものであってもよい。
 本発明にかかるプログラム最適化方法は、プログラミング言語で記述された入力プログラムを最適化するプログラム最適化方法であって、前記入力プログラムを中間コードに変換し、前記入力プログラムで使用される変数の取り得る値を外部から与えられる情報より取得し、取得した前記変数の取り得る値を前記中間コードを木構造で表した際のノードに設定し、前記ノードの取り得る値に基づいて、前記中間コードを最適化し、前記中間コード最適化部により最適化された中間コードを、所定の書式で記述された出力プログラムに変換する。
 なお、本発明は、このような特徴的な処理部を備えるプログラム最適化装置、または特徴的なステップを含むプログラム最適化方法として実現できるだけでなく、プログラム最適化方法に含まれる特徴的なステップをコンピュータに実行させるプログラムとして実現したりすることもできる。そして、そのようなプログラムは、CD-ROM(Compact Disc-Read Only Memory)等の記録媒体やインターネット等の通信ネットワークを介して流通させることができるのは言うまでもない。
 本発明によると、プログラムの実行により処理されるデータの特徴に依存した最適化を行い、かつ、最適化の前のプログラムの実行を必要としないプログラム最適化装置を提供することができる。
 また、入力プログラム中の変数の取り得る値を指定しているため、変数の取り得る値から算出された値を利用して、算出結果が常に固定された値の場合は定数に置換したり、冗長な分岐を削除したりすることで、プログラムサイズの小さい出力プログラムを生成することもできる。
 さらに、入力プログラム中の変数の取り得る値を指定しているため、変数の取り得る値から算出された値を利用して、少ない分岐数でありながら、定数への置換数を増やせるため、実行速度の改善の可能性を高めることもできる。
図1は、本発明の実施の形態に係るプログラム最適化装置を示す図である。 図2は、本発明のプログラム最適化装置が実行する処理のフローチャートである。 図3は、入力プログラムの一例を示す図である。 図4は、中間コードの一例を示す図である。 図5は、図4に示す中間コードと、当該中間コードに含まれる各ノードが取り得る値とを示す図である。 図6は、データの連鎖情報の一例を示す図である。 図7は、ノード値算出部の算出結果である定数の集合を示す図である。 図8は、中間コード最適化部の第1の変換の一例を説明するための図である。 図9は、中間コード最適化部の第3の変換の一例を説明するための図である。 図10は、本発明により図3に示した入力プログラムから変換した出力プログラムを示す図である。 図11は、従来技術により図3に示した入力プログラムから変換した出力プログラムを示す図である。 図12は、プログラム最適化装置の変形例を示す図である。 図13は、入力プログラムの一例を示す図である。 図14は、指定ファイルの一例を示す図である。 図15は、プログラム最適化装置の変形例を示す図である。 図16は、GUIの一例を示す図である。 図17は、GUIの一例を示す図である。
符号の説明
 101、101a、101b プログラム最適化装置
 111 入力プログラム
 112 出力プログラム
 113 指定ファイル
 114 表示端末
 121 中間コード変換部
 122、122a、122b 変数値設定部
 123 ノード値算出部
 124 中間コード最適化部
 125 出力プログラム変換部
 131 中間コード
 以下、本発明の実施の形態に係るプログラム最適化装置について図面を参照しながら説明する。
 まず、プログラム最適化装置の構成について図1を参照して説明する。
 プログラム最適化装置101は、最適化対象のプログラムを記述した入力プログラム111を、最適化を施したプログラムである出力プログラム112に変換する装置であり、中間コード変換部121と、変数値設定部122と、ノード値算出部123と、中間コード最適化部124と、出力プログラム変換部125とを含む。プログラム最適化装置101は、プロセッサとメモリとを備える通常のコンピュータ上で、各処理部を実現するためのプログラムを実行することにより実現される。なお、プログラム最適化装置101の処理で用いられる、プログラム、コード、データ等は、コンピュータのメモリ等に一時的に記憶される。
 中間コード変換部121は、入力プログラム111を中間コード131に変換する。
 入力プログラム111は、例えば、C言語といった既存のプログラミング言語で記述されている。中間コード131は、例えば、抽象構文木といった、既存のプログラムの表現形式で、入力プログラム111の内容を表現している。
 変数値設定部122は、入力プログラム111に記述されている変数に対して、変数の取り得る値を定数の集合として、中間コード131に設定する。変数の取り得る値は、入力プログラム111に、例えばpragmaのような指示子を記述することにより指定することができる。また、入力プログラムとは別のファイルに変数の取り得る値を示す情報を記述することにより指定することもできる。さらに、GUI(Graphical User Interface)を用いたユーザ入力により入力プログラムに対して指定することもできる。なお、ユーザ入力は必ずしもGUIを用いる必要はなく、他のインタフェースを用いてユーザ入力を受け付けるようにしても良い。
 ノード値算出部123は、変数値設定部122によって設定された変数に対する定数の集合に基づいて、中間コード131を木構造で表した際の各ノードが取り得る値を算出する。
 中間コード最適化部124は、ノード値算出部123によって算出された中間コード131の各ノードが取り得る値に基づいて、以下の3つの変換方法のいずれかの方法に従い、中間コードの変換を行う。
 第1の変換方法は、ノードが取り得る値が1つである場合に、当該ノードをノードが取り得る値を表現する定数ノードに置換する方法である。
 第2の変換方法は、ノードが条件分岐を表現するノードである場合に、ノードが取り得る値に含まれない値による条件分岐を、中間コードより削除する方法である。
 第3の変換方法は、定数の集合の要素数分の分岐を生成し、各分岐において第1の変換と同様に、ノードを定数ノードに置換する方法である。
 出力プログラム変換部125は、最適化された中間コード131を所定の書式で記述された出力プログラム112に変換する。
 出力プログラム112の書式は、例えば、プログラム最適化装置101を、Cコンパイラとして利用する場合は、C言語、アセンブリ言語、機械語等であり、高位合成ツールとして利用する場合は、Verilog言語等である。
 次に、プログラム最適化装置101が実行する処理について説明する。
 図2は、プログラム最適化装置が実行する処理のフローチャートである。
 中間コード変換部121は、入力プログラム111を中間コード131に変換する(S211)。図3は、入力プログラムの一例を示す図である。図4は、中間コード131の一例を示す図である。同図は、図3に示す入力プログラム301の13行目の文S5を変換した結果得られる中間コードを示す。この中間コードは、変数の参照を示すノードS5_aおよびS5_rと、定数を示すノードS5_1と、演算を示すノードS5_addとを含む木構造で表現されている。
 次に、変数値設定部122は、変数の参照を示すノード(変数の参照ノード)に対し、変数の取り得る値を示す定数の集合を設定する(S212)。図3に示す入力プログラム301の3行目および4行目のpragma記述は、それぞれ、変数aの取り得る値が{0,1}、変数cの取り得る値が{0,2,4}であることを指定する記述である。この場合、変数値設定部122は、入力プログラム111のpragma記述から変数の取り得る値を取得し、変数aを参照するノードに対し、定数の集合{0,1}を設定する。変数cを参照するノードに対しても同様に、定数の集合{0,2,4}を設定する。
 次に、ノード値算出部123は、中間コード131に含まれる各ノードに対し、ノードが取り得る値を示す定数の集合を算出する(S213)。例えば、図4に示す中間コードについて検討する。図5は、図4に示す中間コードと、当該中間コードに含まれる各ノードが取り得る値とを示す図である。同図に示すように、変数aの参照を示すノードS5_aには、図3に示す入力プログラム301の3行目のpragma記述の通り、定数の集合{0,1}が設定済みである。また、定数ノードS5_1は、取り得る値が“1”のみである。このため、ノード値算出部123は、定数ノードS5_1が取り得る値として、定数の集合{1}を算出する。加算ノードS5_addでは、オペランドであるノードS5_aの値とノードS5_1の値との加算が行われる。このため、ノード値算出部123は、ノードS5_aの取り得る値を示す定数の集合{0,1}と、ノードS5_1の取り得る値を示す定数の集合{1}とから、加算ノードS5_addの取り得る値を示す定数の集合として{1,2}を算出する。さらに、ノード値算出部123は、変数rの参照を示すノードS5_rについても、加算ノードS5_addの取り得る値を示す定数の集合と同じ定数の集合{1,2}を算出する。
 また、ノード値算出部123は、一般的な最適化方法である定数伝播と同様に、データの連鎖情報を元に定数の集合を伝播させる。例えば、図3に示す入力プログラム301の10~14行目で定義された変数rが、17行目の文で使用されている。この場合、10~14行目に対応する文ノードS2~S6と17行目に対応する文ノードS7とのデータの連鎖情報は、図6に示すように連鎖元から連鎖先を示すグラフとして表現できる。つまり、変数rの定義を行う文ノードS2~S6が連鎖元を示し、変数rを参照する文ノードS7が連鎖先として表現される。ノード値算出部123は、データの連鎖情報を元に、文ノードS2~S6の定数の集合に基づいて文ノードS7の定数の集合の算出を行う。つまり、ノード値算出部123は、データの連鎖情報を元に、連鎖先の定数の集合を、連鎖元の定数の集合の和集合として算出する。結果として、文ノードS7における変数rの参照ノードS7_rの定数の集合が算出される。
 同様に、全てのノードに対して、ノードの取り得る値を示す定数の集合が算出されることにより、図7に示すようにノード毎に定数の集合が算出される。図7は、中間コード131に含まれるノードに設定されている定数の集合の一部を示す図である。ノードに設定された定数の集合は、中間コード131に含まれる各ノードが取り得る値を示す集合である。定数の集合が算出できなかったノードには、空集合φが設定され、この場合は任意の値を取り得ることを示している。
 次に、中間コード最適化部124は、算出されたノードの定数の集合を使用した中間コード131の変換を行う(S214)。中間コード131の変換方法には以下の3つの変換方法がある。
 第1の変換は、ノードの定数の集合の要素数が1つの場合に、当該ノードを、当該集合の要素を表現する定数ノードに置換する変換である。図8(a)は、入力プログラム301の文ノードS9における変換前の中間コードを示す図である。図8(b)は、文ノードS9における変換後の中間コードを示す図である。ノード値算出部123によって算出された変数nの参照ノードS9_nにおける定数の集合は、図7に示す通り{1}であり、要素数が1つである。このため、中間コード最適化部124は、変数nの参照ノードS9_nを、その要素である数値“1”を表現する定数ノードS9_1に置換する。この置換の結果、文ノードS8は不要コードとなる。このため、中間コード最適化部124は、一般的な最適化方法である不要コード削除の最適化により、文ノードS8を削除する。これにより、プログラムサイズを小さくすることが可能となる。
 第2の変換は、ノードが有する定数の集合に含まれない値に依存する分岐を、中間コードより削除する変換である。入力プログラム301の分岐文ノードS1における分岐条件を示すノードS1_sが有する定数の集合は、図7が示す通り{1,3,5}である。文ノードS2が示す分岐“case0”は、ノードS1_sの値が“0”の場合の条件分岐である。図7で示されるノード値算出結果において、ノードS1_sは要素“0”を含まない。このため、プログラム実行時に文S2は実行されない。よって、中間コード最適化部124は、文ノードS2が示す分岐“case0”を削除する。同様に、中間コード最適化部124は、文ノードS4が示す分岐“case2”も削除する。これにより、分岐は、出力プログラム401に示されるように文ノードS3,S5,S6のみの分岐に削減される。この置換の結果、プログラムサイズが小さくなることは自明である。
 第3の変換は、定数の集合の要素数分の分岐を生成し、各分岐において第1の変換と同様に、ノードを定数ノードに置換する変換である。図9(a)は、図3に示す入力プログラム301の文ノードS7における変換前の中間コードを示す図である。図9(b)は、文ノードS7における変換後の中間コードを示す図である。文ノードS7において、変数rの参照ノードS7_rの定数の集合は{0,1,2}である。このため、中間コード最適化部124は、図9(b)に示すように0,1,2にそれぞれに対応する分岐を生成する。中間コード最適化部124は、各分岐において、変数rの参照ノードS7_rを定数ノードに置換することにより、中間コードを変換する。分岐は、文ノードS72,S74,S76で示される。文ノードS72,S74,S76は、文ノードS7を複製し、変数rの参照ノードS7_rに該当するノードを、定数0,1,2をそれぞれ示す定数ノードS72_0,S74_1,S76_2に置換することで生成される。この変換の結果、従来技術の最適化方法である定数の畳み込み(constant folding)、あるいは、演算強度の削減といった最適化が可能になる。最終的に、文ノードS7に含まれる乗算が別の演算に変換され、図10に示す出力プログラム401における文ノードS72’,S74’,S76’に最適化される。プログラムの実行時にシフト演算が乗算より高速に実行できる場合には、この第3の変換により、プログラムの実行時間を改善することができる。また、出力プログラムを用いてハードウェアを生成するような場合においては、乗算器自体が不要となる。このため、ハードウェアの規模を小さくすることが可能になる。
 第3の変換においては、要素数分の分岐が新たに生成される。このため、第3の変換の実施を制限してもよい。例えば、変換により定数の畳み込みが可能になる要素についてのみ第3の変換を実施するようにしてもよい。また、変換により演算強度の削減が可能になる乗算や除算等の演算を含む場合に限定して第3の変換を実施するようにしてもよい。
 次に、プログラム最適化装置101は、中間コードの変換を実施したか否かを判定し(S215)、中間コードの変換を実施した場合は(S215でYES)、再度、ノード値算出処理(S213)以降の処理を実行することにより、さらなる最適化を試みる。
 中間コードの変換が実施されなかった場合には(S215でNO)、出力プログラム変換部125は、中間コード最適化部124によって最適化された中間コード131から、所定の書式で記述された出力プログラム112を生成する(S216)。
 図10は、入力プログラム301に対してプログラム最適化装置101により最適化された出力プログラムを示している。図11は、入力プログラム301に対して従来技術により最適化された出力プログラムの一例を示している。図11では、変数が特定の値を取る場合に特化した最適化を行っている。図10および図11より、プログラム最適化装置101により生成された出力プログラムは、従来技術により生成された出力プログラムと比べて、プログラムサイズが小さいことは明らかである。
 以上説明したように、本発明の実施の形態によれば、入力プログラムで使用される変数の取り得る値を、予め取得し、その値に基づいて、中間コードの最適化を行っている。このため、最適化の前にプログラムを実行することなく、プログラムの実行により処理されるデータの特徴に依存した最適化を可能としている。さらに、変数の取り得ない値の情報を利用した最適化を行うことで、不要なコードの削減が可能となる。このため、従来技術による最適化よりもプログラムサイズの小さいコードを生成することが可能となる。
 また、入力プログラム中の変数の取り得る値を指定しているため、変数の取り得る値から算出された値を利用して、算出結果が常に固定された値の場合は定数に置換したり、冗長な分岐を削除したりすることで、プログラムサイズの小さい出力プログラムを生成することもできる。
 さらに、入力プログラム中の変数の取り得る値を指定しているため、変数の取り得る値から算出された値を利用して、少ない分岐数でありながら、定数への置換数を増やせるため、実行速度の改善の可能性を高めることもできる。
 以上、本発明の実施の形態に係るプログラム最適化装置101について説明したが、本発明は、この実施の形態に限定されるものではない。
 例えば、上述の実施の形態では、入力プログラム111がC言語で記述され、変数の取り得る値をpragmaにより指定する方法について説明した。しかし、pragmaで指定する情報と同じ情報を入力プログラムとは別のファイルに記述することにより、変数の取り得る値を指定してもよい。
 図12~図14を用いて、入力プログラムとは別の指定ファイルを用いて変数の取り得る値を指定する方法について説明する。
 図12は、この方法に係るプログラム最適化装置の構成を示す図である。プログラム最適化装置101aは、図1に示したプログラム最適化装置101の構成において、変数値設定部122を変数値設定部122aに変更したものである。それ以外の構成は、プログラム最適化装置101と同様である。変数値設定部122aは、変数の取り得る値を指定ファイル113から取得し、変数の取り得る値を定数の集合として、中間コード131に設定する。
 図13は、入力プログラムの一例を示す図である。図14は、指定ファイルの一例を示す図である。例えば、入力プログラム1101に記述されている変数aおよびcに対して、変数の取り得る値を指定する場合、指定ファイル1102に変数aおよびcを特定する情報と、変数aおよびcが取り得る値とを記述することにより、pragma記述と同様に、変数aおよびcの取り得る値を指定することができる。
 なお、pragmaまたは指定ファイルを用いて変数の取り得る値を指定する以外にも、GUIを用いて、入力プログラムを画面に表示し、ユーザがポインタで指定した変数に対して、当該変数の取り得る値を入力するようにしてもよい。
 図15~図17を用いて、GUIを用いて変数の取り得る値を指定する方法について説明する。
 図15は、この方法に係るプログラム最適化装置の構成を示す図である。プログラム最適化装置101bは、図1に示したプログラム最適化装置101の構成において、変数値設定部122を変数値設定部122bに変更したものである。それ以外の構成は、プログラム最適化装置101と同様である。変数値設定部122bは、入力プログラム111を表示端末114に表示させ、ユーザによる入力により変数の取り得る値を取得し、変数の取り得る値を変数の集合として、中間コード131に設定する。
 図16は、表示端末114に表示される、入力プログラムを含む入力プログラム表示ウィンドウの一例を示す図である。図17は、変数属性ダイアログの一例を示す図である。例えば、入力プログラム表示ウィンドウ1201に表示されている入力プログラムに記述されている変数aに対して、変数の取り得る値を指定する場合を考える。ユーザは、入力プログラム表示ウィンドウ1201上で、変数aをポインタにより選択する。次に、ユーザは、プルダウンメニューから変数属性ダイアログ1202を開くためのメニューを選択することにより、変数属性ダイアログ1202を表示端末114上に表示させる。ユーザは、変数属性ダイアログ1202において、変数aの取り得る値として“0,1”を入力する。同様に変数cに対しても取り得る値を入力することで、pragma記述と同様に、変数aおよびcの取り得る値を指定することができる。
 なお、GUIを用いずとも、例えば、CUI(Character User Interface)を用いて、ユーザが変数の取り得る値を入力するような構成であってもよい。
 今回開示された実施の形態はすべての点で例示であって制限的なものではないと考えられるべきである。本発明の範囲は上記した説明ではなくて請求の範囲によって示され、請求の範囲と均等の意味及び範囲内でのすべての変更が含まれることが意図される
 本発明にかかるプログラム最適化装置は、プログラムのソースコードからオブジェクトコードを生成するコンパイラや、逐次処理プログラムからハードウェアのRTL(Register Transfer Level)記述を生成する高位合成ツールに適用でき、特に、プログラムの処理するデータに依存した最適化を施したオブジェクトコードやRTL記述を生成する場合に有用である。

Claims (16)

  1.  プログラミング言語で記述された入力プログラムを最適化するプログラム最適化装置であって、
     前記入力プログラムを中間コードに変換する中間コード変換部と、
     前記入力プログラムで使用される変数の取り得る値を、外部から与えられる情報より取得し、取得した前記変数の取り得る値を前記中間コードに設定する変数値設定部と、
     設定された前記変数の取り得る値に基づいて、前記中間コードを最適化する中間コード最適化部と、
     前記中間コード最適化部により最適化された中間コードを、所定の書式で記述された出力プログラムに変換する出力プログラム変換部と
     を備えるプログラム最適化装置。
  2.  前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、ユーザからの入力により取得し、取得した前記変数の取り得る値を前記中間コードに設定する
     請求項1に記載のプログラム最適化装置。
  3.  前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、前記入力プログラム中に記載された指示子から取得し、取得した前記変数の取り得る値を前記中間コードに設定する
     請求項1に記載のプログラム最適化装置。
  4.  前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、所定のファイルから取得し、取得した前記変数の取り得る値を前記中間コードに設定する
     請求項1に記載のプログラム最適化装置。
  5.  前記中間コード最適化部は、前記中間コードを木構造で表した際の、当該中間コードに含まれる複数のノードのうち、取り得る値が1つのみのノードを、定数を示すノードに置換する
     請求項1に記載のプログラム最適化装置。
  6.  前記中間コード最適化部は、前記中間コードを木構造で表した際の、条件分岐を表現するノードについて、当該ノードが取り得る値に含まれない値に依存する分岐を、前記中間コードより削除する
     請求項1に記載のプログラム最適化装置。
  7.  前記中間コード最適化部は、前記中間コードを木構造で表した際の、複数の値を取り得る変数を示す変数ノードを含むノードを、取り得る値に従い分岐する前記変数ノードを含む複数のノードに変換し、変換後の前記複数のノードの各々に含まれる前記変数ノードを、分岐条件とされた取り得る値を示す定数ノードに置換する
     請求項1に記載のプログラム最適化装置。
  8.  前記中間コード最適化部は、前記変数の取り得る値から、前記中間コードを木構造で表した際のノードの取り得る値を算出し、前記ノードの取り得る値に基づいて、前記中間コードを最適化する
     請求項1に記載のプログラム最適化装置。
  9.  プログラミング言語で記述された入力プログラムを最適化するプログラム最適化装置であって、
     前記入力プログラムを中間コードに変換する中間コード変換部と、
     前記入力プログラムで使用される変数の取り得る値を外部から与えられる情報より取得し、取得した前記変数の取り得る値を前記中間コードを木構造で表した際のノードに設定する変数値設定部と、
     前記ノードの取り得る値に基づいて、前記中間コードを最適化する中間コード最適化部と、
     前記中間コード最適化部により最適化された中間コードを、所定の書式で記述された出力プログラムに変換する出力プログラム変換部と
     を備えるプログラム最適化装置。
  10.  前記中間コード最適化部は、前記中間コードを木構造で表した際の、当該中間コードに含まれる複数のノードのうち、取り得る値が1つのみのノードを、定数を示すノードに置換する
     請求項9に記載のプログラム最適化装置。
  11.  前記中間コード最適化部は、前記中間コードを木構造で表した際の、条件分岐を表現するノードについて、当該ノードが取り得る値に含まれない値に依存する分岐を、前記中間コードより削除する
     請求項9に記載のプログラム最適化装置。
  12.  前記中間コード最適化部は、前記中間コードを木構造で表した際の、複数の値を取り得る変数を示す変数ノードを含むノードを、取り得る値に従い分岐する前記変数ノードを含む複数のノードに変換し、変換後の前記複数のノードの各々に含まれる前記変数ノードを、分岐条件とされた取り得る値を示す定数ノードに置換する
     請求項9に記載のプログラム最適化装置。
  13.  前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、ユーザからの入力により取得し、取得した前記変数の取り得る値を前記中間コードのノードに設定する
     請求項9に記載のプログラム最適化装置。
  14.  前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、前記入力プログラム中に記載された指示子から取得し、取得した前記変数の取り得る値を前記中間コードのノードに設定する
     請求項9に記載のプログラム最適化装置。
  15.  前記変数値設定部は、前記入力プログラムで使用される変数の取り得る値を、所定のファイルから取得し、取得した前記変数の取り得る値を前記中間コードのノードに設定する
     請求項9に記載のプログラム最適化装置。
  16.  プログラミング言語で記述された入力プログラムを最適化するプログラム最適化方法であって、
     前記入力プログラムを中間コードに変換し、
     前記入力プログラムで使用される変数の取り得る値を外部から与えられる情報より取得し、取得した前記変数の取り得る値を前記中間コードを木構造で表した際のノードに設定し、
     前記ノードの取り得る値に基づいて、前記中間コードを最適化し、
     前記中間コード最適化部により最適化された中間コードを、所定の書式で記述された出力プログラムに変換する
     プログラム最適化方法。
PCT/JP2008/002843 2008-02-05 2008-10-08 プログラム最適化装置およびプログラム最適化方法 WO2009098739A1 (ja)

Priority Applications (2)

Application Number Priority Date Filing Date Title
JP2009535722A JPWO2009098739A1 (ja) 2008-02-05 2008-10-08 プログラム最適化装置およびプログラム最適化方法
US12/668,967 US20100199269A1 (en) 2008-02-05 2008-10-08 Program optimization device and program optimization method

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
JP2008-024680 2008-02-05
JP2008024680 2008-02-05

Publications (1)

Publication Number Publication Date
WO2009098739A1 true WO2009098739A1 (ja) 2009-08-13

Family

ID=40951828

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/JP2008/002843 WO2009098739A1 (ja) 2008-02-05 2008-10-08 プログラム最適化装置およびプログラム最適化方法

Country Status (3)

Country Link
US (1) US20100199269A1 (ja)
JP (1) JPWO2009098739A1 (ja)
WO (1) WO2009098739A1 (ja)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116185379A (zh) * 2022-11-17 2023-05-30 北京东方通科技股份有限公司 一种对代码托管平台进行优化的方法

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9037961B1 (en) * 2006-09-18 2015-05-19 Credit Suisse Securities (Usa) Llc System and method for storing a series of calculations as a function for implementation in a spreadsheet application
US20120079245A1 (en) * 2010-09-25 2012-03-29 Cheng Wang Dynamic optimization for conditional commit
US8549504B2 (en) 2010-09-25 2013-10-01 Intel Corporation Apparatus, method, and system for providing a decision mechanism for conditional commits in an atomic region
JP2013003664A (ja) * 2011-06-13 2013-01-07 Sony Corp 情報処理装置および方法
US8893094B2 (en) * 2011-12-30 2014-11-18 Intel Corporation Hardware compilation and/or translation with fault detection and roll back functionality
US8726255B2 (en) * 2012-05-01 2014-05-13 Concurix Corporation Recompiling with generic to specific replacement
US9116714B2 (en) * 2013-07-10 2015-08-25 Tencent Technology (Shenzhen) Company Limited Methods and systems for file processing
KR20160070965A (ko) * 2014-12-11 2016-06-21 삼성전자주식회사 컴파일러
EP3931685A4 (en) * 2019-02-26 2022-10-12 INTEL Corporation CONSTANT PROPAGATION, WORKLOAD ORIENTED, FOR A COMPILER
CN112540899B (zh) * 2019-09-20 2022-10-04 无锡江南计算技术研究所 基于性能数据时空特性的分析装置
EP3812886A1 (de) * 2019-10-24 2021-04-28 Eberhard Karls Universität Tübingen System und verfahren zur optimierung von programmiercode

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH02118732A (ja) * 1988-10-28 1990-05-07 Toshiba Corp プログラム処理方式
JPH0395631A (ja) * 1989-09-08 1991-04-22 Nec Corp 条件文の目的プログラムの削減方式
JPH0546404A (ja) * 1991-08-09 1993-02-26 Fujitsu Ltd 分岐命令削除最適化方式
JPH096627A (ja) * 1995-06-16 1997-01-10 Matsushita Electric Ind Co Ltd 最適化装置
JPH09265402A (ja) * 1996-03-28 1997-10-07 Hitachi Software Eng Co Ltd プログラム変換支援方法および装置
JPH10187458A (ja) * 1996-12-19 1998-07-21 Nagano Nippon Denki Software Kk コンピュータプログラム生成装置及び方法
JP2006107339A (ja) * 2004-10-08 2006-04-20 Matsushita Electric Ind Co Ltd プログラム処理装置
JP2008004082A (ja) * 2006-05-26 2008-01-10 Matsushita Electric Ind Co Ltd コンパイラ装置、コンパイル方法およびコンパイラプログラム

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH06314203A (ja) * 1993-04-28 1994-11-08 Fujitsu Ltd コンパイラの最適化方法および装置
JP2002259135A (ja) * 2001-02-28 2002-09-13 Internatl Business Mach Corp <Ibm> プログラムの最適化方法及びこれを用いたコンパイラ
JP3867013B2 (ja) * 2002-05-17 2007-01-10 東芝テック株式会社 プログラミング支援プログラム
US8060870B2 (en) * 2007-09-26 2011-11-15 International Business Machines Corporation System and method for advanced polyhedral loop transformations of source code in a compiler
JP2009187285A (ja) * 2008-02-06 2009-08-20 Panasonic Corp プログラム変換方法、プログラム変換装置およびプログラム

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH02118732A (ja) * 1988-10-28 1990-05-07 Toshiba Corp プログラム処理方式
JPH0395631A (ja) * 1989-09-08 1991-04-22 Nec Corp 条件文の目的プログラムの削減方式
JPH0546404A (ja) * 1991-08-09 1993-02-26 Fujitsu Ltd 分岐命令削除最適化方式
JPH096627A (ja) * 1995-06-16 1997-01-10 Matsushita Electric Ind Co Ltd 最適化装置
JPH09265402A (ja) * 1996-03-28 1997-10-07 Hitachi Software Eng Co Ltd プログラム変換支援方法および装置
JPH10187458A (ja) * 1996-12-19 1998-07-21 Nagano Nippon Denki Software Kk コンピュータプログラム生成装置及び方法
JP2006107339A (ja) * 2004-10-08 2006-04-20 Matsushita Electric Ind Co Ltd プログラム処理装置
JP2008004082A (ja) * 2006-05-26 2008-01-10 Matsushita Electric Ind Co Ltd コンパイラ装置、コンパイル方法およびコンパイラプログラム

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116185379A (zh) * 2022-11-17 2023-05-30 北京东方通科技股份有限公司 一种对代码托管平台进行优化的方法
CN116185379B (zh) * 2022-11-17 2023-09-22 北京东方通科技股份有限公司 一种对代码托管平台进行优化的方法

Also Published As

Publication number Publication date
JPWO2009098739A1 (ja) 2011-05-26
US20100199269A1 (en) 2010-08-05

Similar Documents

Publication Publication Date Title
WO2009098739A1 (ja) プログラム最適化装置およびプログラム最適化方法
JP4822817B2 (ja) コンパイルシステム
US8006229B2 (en) Program maintenance support device and program for the same
CN109086215B (zh) 一种嵌入式软件单元测试用例生成方法及系统
US7275026B2 (en) Implicit frame-based processing for block-diagram simulation
JP2001166949A (ja) シンボリック実行を用いてソースコードをコンパイルするための方法及び装置
JP2003067185A (ja) アプリケーション編集装置、データ処理方法及びプログラム
JP4951416B2 (ja) プログラム検証方法、プログラム検証装置
JP2009187285A (ja) プログラム変換方法、プログラム変換装置およびプログラム
US7458071B2 (en) Compilation method, compiler apparatus and compiler
JP2006301989A (ja) 計算機言語によるプログラムをブロック図から自動生成する方法と装置とプログラム
JP4768984B2 (ja) コンパイル方法、コンパイルプログラムおよびコンパイル装置
KR20050030896A (ko) 프로그램 자동 변환 방법 및 프로그램 자동 변환 장치
JP4553246B2 (ja) ウェブ画面作成方法、プログラム及びサーバ
JP2017204080A (ja) 情報処理装置、コンパイル方法及びコンパイラプログラム
JP6790921B2 (ja) プログラム分析装置、プログラム分析方法及びプログラム分析プログラム
JP2009163662A (ja) 情報処理装置、情報処理装置の制御方法、および情報処理装置の制御プログラム
JP7260150B2 (ja) Webサイト設計支援装置、Webサイト設計支援方法、及びプログラム
JP5399601B2 (ja) 実装コード開発システム、及び実装コード開発プログラム
WO2020048416A1 (zh) 领域专用语言dsl的图形化处理方法和设备
JP5932707B2 (ja) 計算機、プログラム及びデータ生成方法
JP2005063121A (ja) ソースコード変換装置、及びソースコード変換方法、ソースコード変換プログラム、記憶媒体
JP2019139675A (ja) ソースコード最適化装置、プログラムおよび方法
WO2009101934A1 (ja) Lsi設計検証システム、lsi設計検証方法およびそのプログラム
JP4354514B2 (ja) プログラム自動変換方法、プログラム自動変換装置、およびプログラム

Legal Events

Date Code Title Description
WWE Wipo information: entry into national phase

Ref document number: 2009535722

Country of ref document: JP

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 08872136

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 12668967

Country of ref document: US

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 08872136

Country of ref document: EP

Kind code of ref document: A1