Program conversion device, program conversion method, and program
The program conversion device and method transform programs by replacing conditional branches with conditional expressions and calculation units, improving execution efficiency and suitability for parallel processing.
Patent Information
- Application Number
- JP2023564712
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2021-12-03
- Publication Date
- 2025-07-23
- Estimated Expiration
- 2041-12-03
AI Technical Summary
Existing program conversion methods do not effectively improve the efficiency of program execution, particularly in handling conditional branches, which can hinder parallel processing and overall performance.
A program conversion device and method that analyze programs to detect conditional branches, converting them into a form without conditional branches using a combination of conditional expressions and calculation units, where only one expression becomes true, and the value indicated by the calculation unit is used, facilitating parallel processing.
The converted program enhances execution efficiency by eliminating conditional branches, allowing for faster processing times, especially in parallel environments, and simplifies program structure for easier understanding.
Smart Images

Figure 0007711767000001 
Figure 0007711767000002 
Figure 0007711767000003
Abstract
Description
Technical Field
[0001] The present invention relates to a program conversion device, a program conversion method, and Program to.
Background Art
[0002] Program conversion such as program conversion at the source level may be performed. For example, the language conversion device described in Patent Document 1 searches for a location described by the same character string as a reserved word in the source program, and determines whether the searched character string is used as a reserved word and whether it is used as a variable character string. When it is determined that the searched character string is not used as a reserved word and is used as a variable character string, this language conversion device converts the search character string into another character string.
Prior Art Documents
Patent Documents
[0003]
Patent Document 1
Summary of the Invention
Problems to be Solved by the Invention
[0004] It is preferable that the program can be converted so as to improve the efficiency of program execution.
[0005] An example of the object of the present invention is to provide a program conversion device, a program conversion method, and Program to solve the above-described problems.
Means for Solving the Problems
[0006] According to a first aspect of the present invention, a program conversion device includes: an analysis unit that analyzes a program to detect a part that includes a conditional branch and calculates a value according to an execution result of the conditional branch; a conditional expression; and a plurality of combinations of a calculation unit that is configured without including a conditional branch and indicates a value. Only one of the plurality of conditional expressions becomes true, and a value indicated by the calculation unit combined with the true conditional expression is used. A program generation unit that generates a program based on the analysis result.
[0007] According to a second aspect of the present invention, a program conversion method includes: a computer analyzes a program to detect a part that includes a conditional branch and calculates a value according to an execution result of the conditional branch, and a plurality of combinations of a conditional expression and a calculation unit that is configured without including a conditional branch and indicates a value are provided. Only one of the plurality of conditional expressions becomes true, and a value indicated by the calculation unit combined with the true conditional expression is used. Generating a program based on the analysis result.
[0008] According to a third aspect of the present invention, Program is to cause a computer to analyze a program to detect a part that includes a conditional branch and calculates a value according to an execution result of the conditional branch, and a plurality of combinations of a conditional expression and a calculation unit that is configured without including a conditional branch and indicates a value are provided. Only one of the plurality of conditional expressions becomes true, and a value indicated by the calculation unit combined with the true conditional expression is used. Generating a program based on the analysis result. with There is.
Effect of the Invention
[0009] According to the present invention, a program can be converted so as to improve the efficiency of program execution.
Brief Description of the Drawings
[0010]
Figure 1
Figure 2
Figure 3
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
Figure 9
Figure 10
Figure 11
Figure 12
Figure 13
Figure 14
Embodiments for Carrying Out the Invention
[0011] Hereinafter, embodiments of the present invention will be described. However, the following embodiments do not limit the invention according to the claims. Also, not all combinations of features described in the embodiments are essential for the solution means of the invention. FIG. 1 is a diagram showing an example of the configuration of a program conversion device according to an embodiment. In the configuration shown in FIG. 1, the program conversion device 100 includes a communication unit 110, a display unit 120, an operation input unit 130, a storage unit 180, and a control unit 190. The control unit 190 includes an analysis unit 191 and a program generation unit 192.
[0012] The program conversion device 100 converts a program. In particular, the program conversion device 100 converts a program that includes a conditional branch and calculates a value according to the execution result of the conditional branch into a program in which a plurality of combinations of a conditional expression and a calculation unit that does not include a conditional branch and indicates a value are provided, and only one of the plurality of conditional expressions becomes true, and the value indicated by the calculation unit combined with the true conditional expression is used.
[0013] The calculation unit is configured as a calculation formula that does not include a conditional branch. The calculation formula here may be a constant. That is, the calculation formula may be a formula consisting only of constant terms. Therefore, the value indicated by the calculation unit may be the value (calculation value) of the calculation formula or a constant value. The constant value can be regarded as a kind of the value of the calculation formula. The program before conversion and the program after conversion output the same data for the same data input.
[0014] The program after conversion is configured to be suitable for speeding up calculations such as parallel processing in that the calculation unit does not include a conditional branch. According to the program conversion device 100, calculations can be performed relatively quickly. The conversion of the program here may be to rewrite the program to be converted, or may be to generate a program after conversion separately from the program to be converted.
[0015] When rewriting the program to be converted and when generating the converted program separately from the program to be converted, it can be said that both generate the converted program. Rewriting the program to be converted can be said to be generating the converted program using the program to be converted. The program before conversion by the program conversion device 100 (the program to be converted) is also referred to as the pre-conversion program. The program after conversion by the program conversion device 100 is also referred to as the post-conversion program.
[0016] The communication unit 110 communicates with other devices. For example, when a storage device storing the pre-conversion program is included in a device other than the program conversion device 100, the communication unit 110 may receive the pre-conversion program from that device. Also, when the execution environment of the post-conversion program is provided in a device other than the program conversion device 100, the communication unit 110 may transmit the post-conversion program to that device.
[0017] The display unit 120 includes a display screen such as a liquid crystal panel or an LED (Light Emitting Diode) panel, and displays various images. For example, the display unit 120 may display any one or more of the pre-conversion program, data during program conversion, and the post-conversion program.
[0018] The operation input unit 130 includes input devices such as a keyboard and a mouse, and receives user operations. For example, the operation input unit 130 may receive a user operation for instructing program conversion and a user operation indicating the acquisition destination of the pre-conversion program.
[0019] The storage unit 180 stores various data. For example, the storage unit 180 stores the algorithm for analyzing the pre-conversion program and the algorithm for converting the program. The storage unit 180 may store these algorithms in a program.
[0020] In addition, the storage unit 180 stores the pre-conversion program. When the program conversion device 100 acquires the pre-conversion program from another device, the storage unit 180 may temporarily store the obtained pre-conversion program. In addition, the storage unit 180 stores the post-conversion program. When the program conversion device 100 outputs the post-conversion program to another device, the storage unit 180 may temporarily store the post-conversion program.
[0021] The control unit 190 controls each part of the program conversion device 100 to perform various processes. The functions of the control unit 190 are executed, for example, by a CPU (Central Processing Unit) provided in the program conversion device 100 reading and executing a program from the storage unit 180.
[0022] The analysis unit 191 analyzes the pre-conversion program. In particular, the analysis unit 191 detects, through analysis, a part of the pre-conversion program that includes a conditional branch and calculates a value according to the execution result of the conditional branch. The analysis unit 191 corresponds to an example of an analysis means. The part that includes a conditional branch and calculates a value according to the execution result of the conditional branch, which is detected by the analysis unit 191, can be a part to be converted in the conversion of the program.
[0023] The analysis unit 191 may perform program analysis using an abstract syntax tree. For example, when the program conversion device 100 uses an abstract syntax tree in a process other than program conversion, such as a compiler or an interpreter, the abstract syntax tree or the abstract syntax tree generation algorithm may also be used for program conversion by the program conversion device 100. This eliminates the need to separately generate an abstract syntax tree or separately prepare an algorithm for program conversion by the program conversion device 100.
[0024] The program generation unit 192 converts a program based on the analysis result by the analysis unit 191. In particular, the program generation unit 192 replaces an assignment statement with a conditional branch with a conditional assignment statement. The conditional assignment statement is composed of a combination of a conditional expression and a calculation unit that does not include a conditional branch and indicates a value.
[0025] When the pre-conversion program includes an assignment statement with an if-then-else conditional branch or an assignment statement with a nested structure of if-then-else conditional branches, the program generation unit 192 replaces this assignment statement with a plurality of conditional assignment statements. The if-then-else conditional branch may be explicitly indicated using an if-then-else statement, or may be implicitly indicated, for example, by using a return command in a function.
[0026] The program generation unit 192 sets the conditional expressions of the plurality of conditional assignment statements such that only one of the conditional expressions is true exclusively. In the post-conversion program, the value indicated by the calculation unit combined with the true conditional expression is used as the value to be assigned by the assignment statement.
[0027] FIG. 2 is a diagram showing an example of data input to the pre-conversion program or the post-conversion program. As described above, the pre-conversion program and the post-conversion program output the same data for the same data input. In FIG. 2, data in tabular form (table form) is shown, and columns for "date", "open", and "close" are provided. Therefore, each row of the data in FIG. 2 includes columns for the item "date", the item "open", and the item "close". The tabular data can be grasped as matrix data. The rows of the table correspond to the rows of the matrix, and the columns of the table correspond to the columns of the matrix. The columns for each row and each column of the table correspond to the elements of the matrix.
[0028] FIG. 2 shows time-series data of market prices such as the stock price of a certain company. In the example of FIG. 2, the "date" column of each row stores the date on which the data of that row was observed. The "open" column of each row stores the opening price of the day indicated in the "date" column. The "close" column of each row stores the closing price of the day indicated in the "date" column. However, the data handled by the program to be converted by the program conversion device 100 is not limited to data of a specific content. Also, the data handled by the program to be converted by the program conversion device 100 is not limited to data of a specific format.
[0029] FIG. 3 is a diagram showing an example of data output by the pre-conversion program or the post-conversion program. FIG. 3 shows an example of data output by the pre-conversion program or the post-conversion program that has received the input of the data shown in FIG. 2. As described above, the pre-conversion program and the post-conversion program output the same data for the same data input. Here, it is assumed that both the pre-conversion program and the post-conversion program output the data shown in FIG. 3 for the input of the data shown in FIG. 2.
[0030] In the data shown in FIG. 3, a "diff" column is added to the data shown in FIG. 2. The "diff" column of each row stores a value based on the comparison between the value in the "open" column and the value in the "close" column for that row. Specifically, when the value in the "open" column is less than 1200, the value in the "diff" column is "-1".
[0031] On the other hand, when the value in the "open" column is 1200 or more, when the value in the "close" column is equal to or more than the value in the "open" column, the value of the difference obtained by subtracting the value in the "open" column from the value in the "close" column is stored in the "diff" column. When the value in the "open" column is 1200 or more and the value in the "close" column is less than the value in the "open" column, the value in the "diff" column is "0".
[0032] However, the processing performed by the pre-conversion program or the post-conversion program on matrix-form data (tabular data) is not limited to column addition. Furthermore, the data handled by the pre-conversion program or the post-conversion program is not limited to matrix-form data.
[0033] When the pre-conversion program or the post-conversion program handles matrix-form data, processing on columns such as column addition, column deletion, or updating the value of each element in a column may be performed. Alternatively, the pre-conversion program or the post-conversion program may perform processing on rows such as row addition, row deletion, or updating the value of each element in a row. The pre-conversion program or the post-conversion program may perform both processing on rows and processing on columns, or may perform only either one of the processing on rows or the processing on columns.
[0034] Either one of the rows and columns of the matrix is also referred to as the first data series. The one that is different from the first data series among the rows and columns of the matrix is also referred to as the second data series. In the case of processing on columns such as the column addition illustrated in FIGS. 2 and 3, the row corresponds to an example of the first data series, and the column corresponds to an example of the second data series. On the other hand, in the case of processing on rows, the column corresponds to an example of the first data series, and the row corresponds to an example of the second data series.
[0035] FIG. 4 is a diagram showing an example of a pre-conversion program. In the program shown in FIG. 4, from "def func(row):" to "return 0" shows the definition of the user-defined function "func". "tbl['diff'] = tbl.apply(func)" indicates that the user-defined function "func" is called for all rows of the tabular data "tbl", a column consisting of the return value for each row is created, and is assigned to the "diff" column of the tabular data "tbl".
[0036] In the function call "tbl.apply(func)", one row of the tabular data "tbl" is passed as an argument to the user-defined function "func". Among the rows of the tabular data "tbl", the row passed as an argument to the user-defined function "func" is also referred to as the processing target row. In the definition of the user-defined function "func", the processing target row is denoted as "row".
[0037] The computer that executes the user-defined function "func" compares the value in the "open" column of the processing target row "row" with 1200 in "if row['open'] < 1200 return -1". If the value in the "open" column is less than 1200, the computer sets the return value to "-1" and terminates the execution of the user-defined function "func" for one row of data in the data "tbl".
[0038] On the other hand, if the value in the "open" column is 1200 or more, the processing proceeds to "if row['open'] < row['close']...". In this way, "if... return..." implicitly indicates an if-then-else conditional branch. Here, "if row['open'] < 1200 return -1..." corresponds to an example of the implication of an if-then-else conditional branch.
[0039] The computer that executes the user-defined function "func" compares the value in the "open" column with the value in the "close" column of the processing target row in "if row['open'] < row['close'] return row['close'] - row['open']". If the value in the "open" column is less than the value in the "close" column, the computer subtracts the value in the "open" column from the value in the "close" column, sets the difference as the return value, and terminates the execution of the user-defined function "func" for one row of data in the data "tbl".
[0040] On the one hand, when the value in the "open" column is greater than or equal to the value in the "close" column, the process proceeds to "return 0". "if row['open'] < 1200 return -1..." also falls under the example of the implication of if-then-else conditional branching. When the computer executing the user-defined function "func" reaches "return 0", it sets the return value to "0" and terminates the execution of the user-defined function "func" for one row of data in the data "tbl".
[0041] In the following, taking the example in Figure 4 as an example, the case where the pre-conversion program calls a user-defined function will be explained. However, the program to be converted by the program conversion device 100 is not limited to one that calls a user-defined function.
[0042] For example, the pre-conversion program may be configured to call a subroutine defined by the user and assign the return value to a global variable within the subroutine. In this case, in the following explanation, the return value of the user-defined function can be read as the return value assigned to the global variable. The user-defined function and the subroutine defined by the user are collectively referred to as the user-defined module.
[0043] Alternatively, the pre-conversion program may be configured without using the user-defined module. Specifically, in the pre-conversion program, a calculation formula for a desired value such as the calculation of the value of each element in a new column may be embedded in the program text. In this case, in the following explanation, the return value of the user-defined function can be read as the desired value.
[0044] Figure 5 is a diagram showing an example of an abstract syntax tree. Figure 5 shows the abstract syntax tree for the pre-conversion program shown in Figure 4. In the example of Figure 5, the symbols shown in each node are for explanation purposes. It is not necessary for such symbols to be attached to the actual abstract syntax tree.
[0045] As described above, "if... return..." in the pre-conversion program implicitly indicates an if-then-else conditional branch, and in the abstract syntax tree shown in FIG. 5, it is configured as an if-cond-then-else tree structure. The square nodes (nodes n22, n34, and n35) of the abstract syntax tree in FIG. 5 indicate that they are return value notations. For example, the square node n34 surrounded by "-" indicates that the difference obtained by subtracting the value of the "open" column from the value of the "close" column in the processing target row is used as the return value. Thus, the return value may be represented by an expression.
[0046] In the program conversion device 100, the analysis unit 191 generates an abstract syntax tree exemplified in FIG. 5. As a method for the program conversion device 100 to generate an abstract syntax tree, an existing method may be used. Alternatively, as described above, when the program conversion device 100 uses an abstract syntax tree in a process other than program conversion, such as a compiler or an interpreter, the abstract syntax tree or the abstract syntax tree generation algorithm may also be used for the program conversion by the program conversion device 100.
[0047] FIG. 6 is a diagram showing an example of a pair of a return value indicated by an abstract syntax tree and a conditional expression indicating the condition under which the return value is adopted. The analysis unit 191 can generate a pair of a return value and a conditional expression exemplified in FIG. 6 using the abstract syntax tree.
[0048] For example, when the analysis unit 191 traces the tree from the node n34 surrounded by a square with "-" in the abstract syntax tree of FIG. 5 to the parent side, the node n34 is set to then of the if statement tree structure indicated by the node n23. Therefore, the analysis unit 191 refers to the node n33 of cond of this if statement tree structure and its descendant nodes, and obtains a conditional expression of "row['open'] < row['close']".
[0049] When the analysis unit 191 further traces the tree to the parent side, the node n23 of the above if statement is set to the else of the tree structure of the upper if statement (the if statement represented by the node n11). Therefore, the analysis unit 191 refers to the node n21 of the cond of the tree structure of this if statement and its descendant nodes, and obtains the conditional expression "row['open'] < 1200".
[0050] The node n34 from which the analysis unit 191 starts the search is included in the else of the if statement represented by the node n11. Therefore, the analysis unit 191 adds not to the conditional expression "row['open'] < 1200" to obtain "not(row['open'] < 1200)". Then, the analysis unit 191 combines the conditional expression "not(row['open'] < 1200)" and the conditional expression "row['open'] < row['close']" with and to generate the conditional expression "(not(row['open'] < 1200)) and (row['open'] < row['close'])". As shown in FIG. 6, the analysis unit 191 associates the node n34 indicating the return value and the generated conditional expression "(not(row['open'] < 1200)) and (row['open'] < row['close'])" in a one-to-one manner.
[0051] The process in which the analysis unit 191 traces the tree from the node indicating the return value to detect the node indicating the if statement and the branch condition corresponds to an example of the process of detecting, in the pre-conversion program, a part that includes a conditional branch and calculates a value according to the execution result of the conditional branch. For example, the analysis unit 191 traces the abstract syntax tree shown in FIG. 5 from node n34 to the parent side, and detecting the if statement shown by node n23 and the condition shown by node n33 corresponds to an example of detecting the conditional branch "if row['open'] < row['close']" in the pre-transformation program shown in FIG. 4. Further, the analysis unit 191 detecting the if statement shown by node n11 and the condition shown by node n21 corresponds to an example of detecting the conditional branch "if row['open'] < 1200" in the pre-transformation program shown in FIG. 4.
[0052] The combination of these conditional branches "if row['open'] < row['close']" and "if row['open'] < 1200" and the calculation formula "row['close'] - row['open']" of the return value shown by node n34 corresponds to an example of the part in the pre-transformation program that includes a conditional branch and calculates a value according to the execution result of the conditional branch.
[0053] The analysis unit 191 tracing the abstract syntax tree from node n22 to detect a part of the abstract syntax tree and tracing the abstract syntax tree from node n35 to detect a part of the abstract syntax tree also respectively correspond to examples of detecting the part in the pre-transformation program that includes a conditional branch and calculates a value according to the execution result of the conditional branch.
[0054] FIG. 7 is a diagram showing an example of conversion from a conditional expression to a conditional expression naming statement by the program generation unit 192. The conditional expression naming statement is represented as an assignment statement that assigns the value of the conditional expression to a logical variable vector. The name of the logical variable vector is also used as the conditional expression name.
[0055] The logical variable vector mentioned here is a vector having logical variables as elements. When the computer that executes the program after conversion executes the conditional expression naming statement included in the program after conversion, it calculates the conditional expression for each row of the matrix to be processed, calculates a truth value vector for one column, and substitutes it into the logical variable vector. The truth value vector mentioned here is a vector having truth values (that is, values representing true or false) as element values. The value representing true is simply denoted as true, and the value representing false is simply denoted as false. For example, that a logical variable takes a value representing true is also denoted as the logical variable value being true.
[0056] FIG. 7 shows an example when the program generation unit 192 generates the conditional expression naming statement for each of the three conditional expressions shown in FIG. 6. The program generation unit 192 assigns logical variable vectors "cond1", "cond2", and "cond3" with names obtained by combining the character string "cond" and sequential numbers starting from 1 to the three conditional expressions, and generates a conditional expression naming statement for each conditional expression.
[0057] When the program generation unit 192 generates a conditional expression naming statement, it may perform a mechanical conversion from the notation according to the format of the program before conversion to the notation according to the format of the program after conversion. In the example of FIG. 7, the program generation unit 192 converts the character string "row" in the program before conversion to the character string "tbl" and generates a conditional expression naming statement.
[0058] "row[]" in the program before conversion represents an element of the row to be processed and the column whose column name is shown in [] among the elements included in the input data in matrix form. On the other hand, "tbl[]" in the conditional expression naming statement represents the column whose column name is shown in [] among the columns included in the matrix-form data "tbl".
[0059] In the pre-conversion program, the computer that executes the program calls a user-defined function for each row of the input data and performs processing. In contrast, in the post-conversion program, the input data part is specified in column units, and the computer that executes the program performs processing on the specified columns. The processing on the columns in this case may be the processing for each row of the column, or the computer may execute the same processing for all rows in parallel processing.
[0060] In this way, the assumed processing methods of the pre-conversion program and the post-conversion program are different, and even if the notations in the pre-conversion program and the notations in the post-conversion program (here, the notations in the conditional expression naming statement) are different due to the difference in the processing methods, it is acceptable. For example, the program generation unit 192 may perform a mechanical conversion from the notation according to the format of the pre-conversion program to the notation according to the format of the post-conversion program based on a conversion rule such as converting a fixed string to a fixed string.
[0061] The conditional expression naming statement generated by the program generation unit 192 is not limited to the one by the assignment statement of the logical variable as described above. For example, the conditional expression naming statement may be defined as a string conversion rule. Furthermore, for example, the conditional expression naming statement "cond1 = tbl['open'] < 1200" in FIG. 7 may be defined as a string conversion rule that replaces the left-side string "cond1" that appears in the post-conversion program with the right-side string "tbl['open'] < 1200". And before or during the execution of the post-conversion program, the string "cond1" that appears in the post-conversion program may be replaced with the string "tbl['open'] < 1200" that represents the conditional expression.
[0062] When the program generation unit 192 generates a conditional expression naming statement, it may use the conditional expression names defined in other conditional expression naming statements. For example, in the example of FIG. 7, the program generation unit 192 may generate a conditional expression naming statement such as "cond2 = not cond1 and (tbl['open'] < tbl['close'])".
[0063] FIG. 8 is a diagram showing an example of a conditional assignment statement generated by the program generation unit 192. FIG. 8 shows an example in which the program generation unit 192 generates a conditional assignment statement based on the return value shown in FIG. 6 and the conditional expression naming statement shown in FIG. 7.
[0064] In the example of FIG. 8, the program generation unit 192 inserts the conditional expression name into the [] of the string "col[] = ", and inserts the calculation formula of the return value or the constant when the return value is a constant on the right side to generate a conditional assignment statement. For example, the program generation unit 192 inserts the conditional expression name "cond1" into the [] of the string "col[] = ", and inserts the return value "-1" on the right side to generate a conditional assignment statement "col[cond1] = -1".
[0065] The right side of the conditional assignment statement corresponds to an example of the calculation unit. The conditional assignment statement col[cond_var] = ret_var indicates that for each element in one column of the matrix, the value of the element in the row where the value of cond_var is true is set to the value indicated by ret_var.
[0066] FIG. 9 is a diagram showing an example of the converted program generated by the program generation unit 192. FIG. 9 shows an example of the converted program obtained by converting the pre-conversion program shown in FIG. 4 by the program generation unit 192.
[0067] In the example of FIG. 9, "cond1 = tbl['open'] < 1200", "cond2 = (not (tbl['open'] < 1200)) and (tbl['open'] < tbl['close'])", and "cond3 = (not (tbl['open'] < 1200)) and (not (tbl['open'] < tbl['close']))" each describe the conditional expression naming statements shown in FIG. 7. The computer that executes the converted program shown in FIG. 9 calculates the conditional expression on the right side of the conditional expression naming statement for each row of the data "tbl", generates a truth value vector for one column of the data "tbl", and substitutes it into the logical variable vector on the left side of the conditional expression naming statement.
[0068] "col = column(tbl.index)" indicates generating an empty column "col" for one column of the data "tbl". Here, the empty column for one column of the data "tbl" has the same number of elements as one column of the data "tbl", and each element is an empty (unset value) column. In the execution of "col = column(tbl.index)", the column "col" is generated as data for one column, separate from the data "tbl". The column "col" can be treated as a vector. The column "col" is also denoted as the vector "col".
[0069] The elements of the vector "col" are associated one-to-one with the rows of the data "tbl". This is done, for example, by associating the elements of the vector "col" with the same index as the row index of the data "tbl". Here, the row index is identification information for identifying a row. The row index may be provided as data separate from the elements of the data "tbl" as a matrix. Alternatively, when the value of one column among the columns of the data "tbl" is a fixed value (constant) and the values differ for each row, the value of that column may be used as the row index.
[0070] 「col[cond1] = -1」 means assigning the value “-1” to the elements of the vector “col” for the rows where the value of the logical variable vector “cond1” is true. 「col[cond2] = tbl['close'] - tbl['open']」 means assigning, to the elements of the vector “col” for the rows where the value of the logical variable vector “cond2” is true, the difference obtained by subtracting the element value of the “open” column from the element value of the “close” column for that row. 「col[cond3] = 0」 means assigning the value “0” to the elements of the vector “col” for the rows where the value of the logical variable vector “cond3” is true.
[0071] By setting the conditional expressions in the conditional expression naming statements, for each row of the data “tbl”, only the value of exactly one of the logical variables “cond1”, “cond2”, and “cond3” used in the conditional assignment statements becomes true. As a result, for each row of the data “tbl”, assignment is performed by only one of the three conditional assignment statements. Thus, for example, when a computer executing the transformed program shown in FIG. 9 executes the three conditional assignment statements in parallel processing, regardless of the execution order of the three conditional assignment statements, the value of the vector “col” is uniquely determined.
[0072] 「tbl['diff'] = col」 indicates adding the vector “col” as a column named “diff” to the data “tbl”. When the transformed program is executed, execution of “tbl['diff'] = col” adds a new “diff” column to the data “tbl”.
[0073] Comparing the pre-transformation program illustrated in FIG. 4 with the post-transformation program illustrated in FIG. 9, the pre-transformation program includes conditional branches using if statements and return statements, etc., whereas in the post-transformation program, the selection of the return value is indicated by conditional assignment statements and no conditional branches are included. In this regard, it can be said that the post-transformation program is more suitable for parallel processing than the pre-transformation program.
[0074] Also, in the converted program, only the conditional expression of any one of the multiple conditional assignment statements becomes true, and the value indicated by the calculation part included in the conditional assignment statement for which the conditional expression becomes true is used. In this regard, when performing parallel processing, a unique value can be obtained regardless of the execution order of the multiple conditional assignment statements. The converted program can also be said to be a program suitable for parallel processing in this respect.
[0075] In the converted program, since a unique value can be obtained regardless of the execution order of the multiple conditional assignment statements, not only can the multiple conditional assignment statements be executed in parallel, but also when processing each row of matrix-form data, the same processing in the column direction can be performed collectively.
[0076] For example, when the computer executes "cond1 = tbl['open'] < 1200" in the converted program of FIG. 9, it may read all the element values of the "open" column of the data "tbl" collectively. And the computer may perform the comparison of each read element value with 1200 collectively. And the computer may collectively substitute the truth values for each row obtained as the comparison result into the logical variable vector "cond1".
[0077] Also, when the computer executes "col[cond1] = -1", it may read the truth values for each row collectively from the logical variable vector "cond1". And the computer may collectively substitute -1 into the elements of the vector "col" for the rows where the truth value is true.
[0078] In this way, when the computer performs the same processing in the column direction collectively, for all rows, "col[cond1] = -1", "col[cond2] = tbl['close'] - tbl['open']", and "col[cond3] = 0" will be executed in the same order. Since a unique value can be obtained regardless of the execution order of the multiple conditional assignment statements, such processing becomes possible.
[0079] The computer may perform the same processing in the column direction in parallel in a batch. Thereby, the program execution time can be shortened. Alternatively, in an environment where the program is executed in an interpreter manner, a portion of the program that has been converted to the converted program may be executed as a native function executed in binary code. Also in this case, the program execution time can be shortened.
[0080] Also, it is conceivable that a person who composes a program is familiar with the format of the pre-conversion program using conditional branches, but is unfamiliar with the format of the post-conversion program using conditional assignment statements. For example, in the pre-conversion program, a user-defined function can be used, etc., and the degree of freedom is high, while the post-conversion program is libraryized and the degree of freedom is relatively low, and it is conceivable that a person who composes a program does not know well about the library for composing the post-conversion program. In this case, a person who composes a program can create a pre-conversion program and convert it to a post-conversion program using the program conversion device 100, thereby shortening the program execution time.
[0081] FIG. 10 is a flowchart showing an example of a processing procedure in which the analysis unit 191 generates a set of pairs of return values and conditional expressions. The analysis unit 191 performs the processing of FIG. 10 as preprocessing for the processing in which the program generation unit 192 generates a post-conversion program, which is illustrated in FIG. 11.
[0082] In the processing of FIG. 10, the analysis unit 191 acquires the abstract syntax tree of the pre-conversion program (step S111). The analysis unit 191 may generate the abstract syntax tree. Alternatively, if a compiler or interpreter has already generated the abstract syntax tree, such as when there is an already generated abstract syntax tree, the analysis unit 191 may acquire the abstract syntax tree.
[0083] Next, the analysis unit 191 searches the abstract syntax tree to generate a list of return values (step S112). Among the tabular data in FIG. 6, the part of the column of return values corresponds to an example of the list of return values generated by the analysis unit 191 searching the abstract syntax tree in FIG. 5.
[0084] Next, the analysis unit 191 selects one return value from the list of return values (step S113). In the loop from step S113 to S122, the analysis unit 191 generates a pair of each return value included in the list of return values and a conditional expression indicating the condition under which the return value is adopted. In step S313, the analysis unit 191 selects a return value in the list of return values for which a pair of the return value and the conditional expression has not yet been generated.
[0085] Next, the analysis unit 191 performs a process of specifying the condition under which the return value selected in step S113 is adopted (step S114). For example, the analysis unit 191 traces back from the node of the return value specified in step S113 to the parent side in the abstract syntax tree. Then, every time the analysis unit 191 reaches the node of an if statement, it acquires the conditional expression of the branch. When the path traced by the analysis unit 191 corresponds to the else of the if statement, the analysis unit 191 takes the negation (not) of the acquired conditional expression.
[0086] The analysis unit 191 repeats acquiring the conditional expression of the branch and taking the negation of the conditional expression in the case of else until it reaches the root of the abstract syntax tree. When it reaches the abstract syntax tree, the analysis unit 191 combines the obtained conditional expressions (the ones with negation taken in the case of else) with and.
[0087] After step S114, the analysis unit 191 determines whether or not it has succeeded in specifying the condition under which the return value is adopted (step S115). As an example of the case where the analysis unit 191 fails to specify the condition under which the return value is adopted, the case where the branch condition is complex can be cited. Further, for example, as an example of the case where the analysis unit 191 fails to specify the condition under which the return value is adopted, a call to an external function is made in the conditional expression of the branch, and the analysis unit 191 does not perform the analysis of the external function. Examples of the case where the analysis unit 191 does not perform the analysis of the external function include the case where the definition of the external function cannot be referred to in the operating environment of the analysis unit 191, and the case where the analysis unit 191 is set not to perform the analysis of the external function until the external function is analyzed.
[0088] When the analysis unit 191 determines that it has failed to specify the condition under which the return value is adopted (step S115: YES), the program conversion device 100 performs the processing predetermined as the processing at the time of program conversion failure (step S141).
[0089] For example, the display unit 120 may display, according to the control of the control unit 190, a message indicating that the conversion of the program has been interrupted due to an error, and information indicating the cause of the failure such as an error code. Alternatively, when the program conversion device 100 performs the conversion of the program as a part of the execution of the program before conversion, the program before conversion may be executed as it is. After step S141, the program conversion device 100 ends the processing of FIG. 10.
[0090] On the other hand, when it is determined in step S115 that the condition under which the return value is adopted has been successfully specified (step S115: YES), the analysis unit 191 generates a set of the return value selected in step S113 and the condition specified in step S114 (step S121). One line of the tabular data shown in FIG. 6 corresponds to an example of the set of the return value and the conditional expression generated by the analysis unit 191 by analyzing the abstract syntax tree of FIG. 5.
[0091] Next, the analysis unit 191 determines whether there is an unprocessed return value (step S122). Specifically, the analysis unit 191 determines whether there is an unprocessed return value for which a pair of the return value and the conditional expression has not yet been generated. If the analysis unit 191 determines that there is an unprocessed return value, the process returns to step S113.
[0092] On the other hand, if it is determined that there is no unprocessed return value, the analysis unit 191 outputs the set of pairs of the return value and the conditional expression generated in step S121 to the program generation unit 192 (step S131). The tabular data shown in FIG. 6 corresponds to an example of the set of pairs of the return value and the conditional expression. After step S131, the program conversion device 100 ends the process of FIG. 10.
[0093] FIG. 11 is a flowchart showing an example of a procedure of a process in which the program generation unit 192 generates a converted program. In the process of FIG. 11, the program generation unit 192 selects one pair from the set of pairs of the return value and the conditional expression generated by the analysis unit 191 (step S211). In the loop from step S211 to S232, the program generation unit 192 generates a conditional assignment statement for each pair of the return value and the conditional expression. In step S211, the program generation unit 192 selects a pair for which a conditional assignment statement has not yet been generated from the set of pairs of the return value and the conditional expression generated by the analysis unit 191.
[0094] Next, the program generation unit 192 determines whether the condition indicated by the conditional expression included in the selected pair can be described in the format of the updated program (step S212). As an example of the case where the condition indicated by the conditional expression included in the selected pair cannot be described in the format of the updated program, there is a case where the updated program or a part thereof is configured using a library, and the condition indicated by the conditional expression included in the selected pair cannot be described under the constraint conditions of the description of the conditional expression in the library.
[0095] When the program generation unit 192 determines that the condition indicated by the conditional expression included in the selected set cannot be described in the format of the updated program (step S212: NO), the program conversion device 100 performs a process predetermined as a process when program conversion fails (step S251).
[0096] For example, the display unit 120 may display, according to the control of the control unit 190, a message indicating that the conversion of the program has been interrupted due to an error, and information indicating the cause of the failure such as an error code. Alternatively, when the program conversion device 100 performs program conversion as a part of the execution of the pre-conversion program, the pre-conversion program may be executed as it is. After step S251, the program conversion device 100 ends the process of FIG. 11.
[0097] On the other hand, in step S212, when it is determined that the condition indicated by the conditional expression included in the selected set can be described in the format of the updated program (step S212: YES), the program generation unit 192 generates a conditional expression naming statement based on the conditional expression included in the selected set (step S221). As described with reference to FIG. 7, the program generation unit 192 may generate an assignment statement as the conditional expression naming statement. Alternatively, the program generation unit 192 may generate a string conversion rule as the conditional expression naming statement.
[0098] Next, the program generation unit 192 determines whether the return value included in the selected set can be described in the format of the updated program (step S222). Examples of cases where the return value included in the selected set cannot be described in the format of the updated program include cases where the updated program or a part thereof is configured using a library, and the return value included in the selected set cannot be described under the constraint conditions of the calculation formula description in the library.
[0099] When the program generation unit 192 determines that the return value included in the selected set cannot be described in the format of the updated program (step S212: NO), the process proceeds to step S251. After step S251, the program conversion device 100 ends the process of FIG. 11.
[0100] On the other hand, when it is determined in step S222 that the return value included in the selected set can be described in the format of the updated program (step S212: NO), the program generation unit 192 generates a conditional assignment statement based on the return value included in the selected set and the conditional expression naming statement generated in step S221 (step S231). As described with reference to FIG. 8, the program generation unit 192 may generate a conditional assignment statement that substitutes the return value into a variable when the condition is satisfied, using the conditional expression name included in the conditional expression naming statement as the display of the condition.
[0101] Next, the program generation unit 192 determines whether there is an unprocessed set (step S232). Specifically, the program generation unit 192 determines whether there is a set for which a conditional assignment statement has not yet been generated. When the program generation unit 192 determines that there is an unprocessed set (step S232: YES), the process returns to step S211.
[0102] On the other hand, when it is determined that there is no unprocessed set (step S232: NO), the program generation unit 192 generates a converted program using the conditional expression naming statement generated in step S221 and the conditional assignment statement generated in step S231 (step S241).
[0103] For example, the program generation unit 192 may insert the conditional expression naming statement and the conditional assignment statement into a previously prepared template, set names required by the template such as the name "diff" of the new column illustrated in FIG. 3, and generate an updated program as illustrated in FIG. 9. After step S241, the program conversion device 100 ends the process of FIG. 11.
[0104] As described above, the analysis unit 191 analyzes the pre-conversion program and detects, from the pre-conversion program, a portion that includes a conditional branch and calculates a value according to the execution result of the conditional branch. The program generation unit 192 is provided with a plurality of combinations of a conditional expression and a calculation unit that is configured without including a conditional branch and indicates a value, and only one of the plurality of conditional expressions becomes true, and the value indicated by the calculation unit combined with the conditional expression that has become true is used. A post-conversion program is generated based on the analysis result.
[0105] It can be said that the post-conversion program generated by the program conversion device 100 is a program suitable for parallel processing in that it does not include a conditional branch in the combination of the conditional expression and the calculation unit. Further, in the post-conversion program generated by the program conversion device 100, only one of the plurality of conditional expressions becomes true, and the value indicated by the calculation unit combined with the conditional expression that has become true is used. In this regard, when performing parallel processing, a unique value can be obtained regardless of the execution order of the plurality of combinations. It can also be said that the post-conversion program generated by the program conversion device 100 is a program suitable for parallel processing in this respect.
[0106] In this way, according to the program conversion device 100, the program can be converted so as to improve the efficiency of program execution. For example, it is expected that the program execution time is shorter than that of the pre-conversion program when the post-conversion program is parallel processed.
[0107] Further, in that the post-conversion program is not described in a nested structure of conditional branches, but in a form in which a value by any one of a plurality of combinations of a conditional expression and a calculation unit is adopted, it is expected that a person reading the program can easily grasp the structure of the program. For example, when the program conversion device 100 converts a pre-conversion program that does not use a library into a post-conversion program that uses a library, a person who wants to learn the method of describing a program using a library can compare the pre-conversion program and the post-conversion program and use it as a reference for describing a program using a library.
[0108] Also, among the pre-conversion programs, a portion that includes a conditional branch and calculates a value according to the execution result of the conditional branch is configured as a user-defined module. The program generation unit 192 replaces an assignment statement that calculates the value of each element of a first data series, which is either a row or a column of a second data series in matrix format and is different from the second data series in terms of row or column, for each first data series using the user-defined module, with a plurality of conditional assignment statements in which a conditional expression and a calculation unit that does not include a conditional branch and indicates a value are combined. In the replaced program (post-conversion program), only the conditional expression of any one of the plurality of conditional assignment statements becomes true, and the value indicated by the calculation unit of the conditional assignment statement whose conditional expression has become true is substituted as the value of an element of a second data series.
[0109] In this way, when the pre-conversion program and the post-conversion program perform processing on data in matrix format, it is considered that the effect of improving the efficiency of program execution increases in that processing is performed on each of a plurality of rows or each of a plurality of columns. For example, in the processing for a column of data in matrix format, consider the case where, for both the pre-conversion program and the post-conversion program, the processing for each row is performed sequentially. In this case, it is expected that the shortened time by which the program execution time of the post-conversion program is shortened compared to the pre-conversion program for one row of data will be multiplied by the number of rows for the entire matrix format data. When the post-conversion program is described using a library that performs matrix processing in parallel, and the processing for each row is also performed in parallel in the post-conversion program, the execution time of the post-conversion program is further shortened.
[0110] Further, when the program conversion device 100 converts a part in the pre-conversion program executed by calling a user-defined module into a part to be embedded in the program body of the post-conversion program, it is expected that the program execution time will be further shortened by the amount that the module call becomes unnecessary in the post-conversion program.
[0111] In addition, the program generation unit 192 replaces, in the pre-conversion program executed in the interpreter method, a part that includes a conditional branch and calculates a value according to the execution result of the conditional branch with a combination of a conditional expression and a calculation unit that is configured without including a conditional branch and indicates a value, and a plurality of such combinations are provided, only one of the plurality of conditional expressions becomes true, and the value indicated by the calculation unit combined with the true conditional expression is used.
[0112] As described above, it can be said that the post-conversion program is a program suitable for parallel processing. In this regard, it is conceivable that a computer that executes the post-conversion program executes the post-conversion program or a part thereof using an accelerator. In an environment where a program is executed in the interpreter method, the effect of accelerating the processing using an accelerator is considered to be particularly remarkable.
[0113] In addition, the analysis unit 191 analyzes the pre-conversion program using an abstract syntax tree. When an abstract syntax tree of the pre-conversion program has already been generated for purposes other than program conversion, such as for compilation or interpreter execution, the analysis unit 191 can use this abstract syntax tree and does not need to separately generate an abstract syntax tree for program conversion. According to the program conversion device 100, in this regard, it is expected that the processing load can be reduced and the processing time can be shortened.
[0114] Alternatively, when the analysis unit 191 generates an abstract syntax tree for program conversion, if an abstract syntax tree generation algorithm is prepared for purposes other than program conversion, such as for compilation or interpreter execution, the analysis unit 191 can generate an abstract syntax tree using that algorithm. In this case, according to the program conversion apparatus 100, there is no need to separately prepare an abstract syntax tree generation algorithm for program conversion, and the storage capacity of the program conversion apparatus 100 can be relatively small.
[0115] FIG. 12 is a diagram showing an example of the configuration of a program conversion apparatus. In the configuration shown in FIG. 12, the program conversion apparatus 610 includes an analysis unit 611 and a program generation unit 612. With such a configuration, the analysis unit 611 analyzes a program and detects a portion that includes a conditional branch and calculates a value according to the execution result of the conditional branch. The program generation unit 612 is provided with a plurality of combinations of a conditional expression and a calculation unit that is configured without including a conditional branch and indicates a value, and only one of the plurality of conditional expressions becomes true, and a program is generated based on the analysis result, in which the value indicated by the calculation unit combined with the conditional expression that has become true is used. The analysis unit 611 corresponds to an example of analysis means. The program generation unit 612 corresponds to an example of program generation means.
[0116] It can be said that the program generated by the program conversion apparatus 610 is a program suitable for parallel processing in that it does not include a conditional branch in the combination of the conditional expression and the calculation unit. Also, in the program generated by the program conversion apparatus 610, only one of the plurality of conditional expressions becomes true, and the value indicated by the calculation unit combined with the conditional expression that has become true is used. In this regard, when performing parallel processing, a unique value can be obtained regardless of the execution order of the plurality of combinations. It can also be said that the program generated by the program conversion apparatus 610 is a program suitable for parallel processing in this respect.
[0117] In this way, according to the program conversion device 610, the program can be converted so as to improve the efficiency of program execution. For example, it is expected that the program execution time will be shorter than that of the program before conversion when the program generated by the program conversion device 610 is processed in parallel.
[0118] Also, in that the program generated by the program conversion device 610 is described in a form in which a value is adopted by any one of a plurality of combinations of a conditional expression and a calculation unit, rather than in a nested structure of conditional branches, it is expected that a person reading the program can easily grasp the structure of the program.
[0119] For example, when the program conversion device 610 converts a program that does not use a library into a program that uses a library, a person who wants to learn the description method of the program that uses a library can compare the program before conversion and the program after conversion by the program conversion device 610 and use it as a reference for the description of the program that uses a library.
[0120] FIG. 13 is a diagram showing an example of a processing procedure in the program conversion method. The processing shown in FIG. 13 includes performing analysis (step S611) and generating a program (step S612). In performing analysis (step S611), the computer analyzes the program and detects a part that includes a conditional branch and calculates a value according to the execution result of the conditional branch.
[0121] In generating a program (step S612), the computer generates a program based on the analysis result, in which a plurality of combinations of a conditional expression and a calculation unit that does not include a conditional branch and indicates a value are provided, only one of the plurality of conditional expressions becomes true, and the value indicated by the calculation unit combined with the true conditional expression is used.
[0122] The program obtained by the program conversion method shown in FIG. 13 can be said to be a program suitable for parallel processing in that it does not include a conditional branch in the combination of the conditional expression and the calculation section. Also, the program obtained by the program conversion method shown in FIG. 13 is such that only one of the plurality of conditional expressions becomes true, and the value indicated by the calculation section combined with the true conditional expression is used. In this regard, when performing parallel processing, a unique value can be obtained regardless of the execution order of the plurality of combinations. The program obtained by the program conversion method shown in FIG. 13 can also be said to be a program suitable for parallel processing in this respect.
[0123] Thus, according to the program conversion method shown in FIG. 13, the program can be converted so as to improve the efficiency of program execution. For example, it is expected that when the program obtained by the program conversion method shown in FIG. 13 is parallel processed, the program execution time will be shorter than in the case of the program before conversion.
[0124] Also, the program obtained by the program conversion method shown in FIG. 13 is described in a form in which the value by any one of a plurality of combinations of a conditional expression and a calculation section is adopted, rather than in a nested structure of conditional branches. In this regard, it is expected that a person reading the program can easily grasp the structure of the program.
[0125] For example, when a program that does not use a library is converted into a program that uses a library by the program conversion method shown in FIG. 13, a person who wants to learn the description method of the program that uses a library can compare the program before conversion and the program after conversion by the program conversion method shown in FIG. 13 and use it as a reference for the description of the program that uses a library.
[0126] FIG. 14 is a schematic block diagram showing the configuration of a computer according to at least one embodiment. With the configuration shown in FIG. 14, the computer 700 includes a CPU 710, a main memory device 720, an auxiliary storage device 730, an interface 740, and a non-volatile recording medium 750.
[0127] Any one or more or a part of the above program conversion device 100 and the program conversion device 610 may be implemented in the computer 700. In that case, the operations of each of the above-described processing units are stored in the auxiliary storage device 730 in the form of a program. The CPU 710 reads the program from the auxiliary storage device 730, expands it in the main storage device 720, and executes the above processing according to the program. Further, the CPU 710 secures a storage area in the main storage device 720 according to the program. Communication between each device and other devices is executed by the interface 740 having a communication function and performing communication under the control of the CPU 710. Further, the interface 740 has a port for the nonvolatile recording medium 750, and reads information from the nonvolatile recording medium 750 and writes information to the nonvolatile recording medium 750.
[0128] When the program conversion device 100 is implemented in the computer 700, the control unit 190 and the operations of each of its parts are stored in the auxiliary storage device 730 in the form of a program. The CPU 710 reads the program from the auxiliary storage device 730, expands it in the main storage device 720, and executes the above processing according to the program.
[0129] Further, the CPU 710 secures a storage area corresponding to the storage unit 180 in the main storage device 720 according to the program. Communication with other devices by the communication unit 110 is executed by the interface 740 having a communication function and operating under the control of the CPU 710. Display by the display unit 120 is executed by the interface 740 having a display device and displaying various images under the control of the CPU 710. Acceptance of user operations by the operation input unit 130 is executed by the interface 740 having input devices such as a keyboard and a mouse, for example, accepting user operations, and outputting information indicating the accepted user operations to the CPU 710.
[0130] When the program conversion device 610 is implemented in the computer 700, the operations of the analysis unit 611 and the program generation unit 612 are stored in the auxiliary storage device 730 in the form of a program. The CPU 710 reads the program from the auxiliary storage device 730, expands it in the main storage device 720, and executes the above processing according to the program.
[0131] Also, the CPU 710 secures a storage area in the main storage device 720 for the program conversion device 610 to perform processing according to the program. Communication between the program conversion device 610 and other devices is executed by the interface 740 having a communication function and operating according to the control of the CPU 710. The interaction between the program conversion device 610 and the user is executed by the interface 740 having a display device and an input device and operating according to the control of the CPU 710.
[0132] One or more of the above-described programs may be recorded on the non-volatile recording medium 750. In this case, the interface 740 may read the program from the non-volatile recording medium 750. Then, the CPU 710 may directly execute the program read by the interface 740, or may temporarily save it in the main storage device 720 or the auxiliary storage device 730 and then execute it.
[0133] Note that a program for executing all or part of the processing performed by the program conversion device 100 and the program conversion device 610 may be recorded on a computer-readable recording medium, and the program recorded on this recording medium may be read into a computer system and executed to perform the processing of each part. Here, the "computer system" is assumed to include hardware such as an OS and peripheral devices. The "computer-readable recording medium" refers to portable media such as flexible disks, magneto-optical disks, ROM (Read Only Memory), CD-ROM (Compact Disc Read Only Memory), and storage devices such as hard disks built into computer systems. The above program may be for realizing a part of the aforementioned functions, and may also be realized in combination with a program already recorded in the computer system for realizing the aforementioned functions.
[0134] As described above, the embodiments of the present invention have been described in detail with reference to the drawings. However, the specific configuration is not limited to this embodiment, and designs and the like within the scope not departing from the gist of the present invention are also included.
Industrial Applicability
[0135] The present invention may be applied to a program conversion device, a program conversion method, and a recording medium.
Explanation of Reference Numerals
[0136] 100, 610 Program conversion device 110 Communication unit 120 Display unit 130 Operation input unit 180 Storage unit 190 Control unit 191, 611 Analysis unit 192, 612 Program generation unit
Claims
1. analysis means for analyzing a program to detect a portion that includes a conditional branch and calculates a value according to the execution result of the conditional branch; program generation means for generating, based on the analysis result, a program in which a plurality of combinations of a conditional expression and a calculation section that is configured without including a conditional branch and indicates a value are provided, only any one of the plurality of conditional expressions becomes true, and the value indicated by the calculation section combined with the true conditional expression is used; A program conversion device comprising the above.
2. The portion that includes the conditional branch and calculates a value according to the execution result of the conditional branch is configured as a user-defined module, The program generation means replaces, for each element value of a first data series that is different from the second data series in a row or a column of data in matrix form, a substitution statement that calculates, for each first data series, using the user-defined module, with a plurality of conditional substitution statements in which a conditional expression and a calculation section that is configured without including a conditional branch and indicates a value are combined, In the program after replacement, only the conditional expression of any one of the plurality of conditional substitution statements becomes true, and the value indicated by the calculation section of the conditional substitution statement whose conditional expression has become true is substituted as the value of the element of the one second data series, The program conversion device according to Claim 1.
3. The program generation means replaces, in a program executed in an interpreter manner, a portion that includes the conditional branch and calculates a value according to the execution result of the conditional branch with a portion in which a plurality of combinations of a conditional expression and a calculation section that is configured without including a conditional branch and indicates a value are provided, only any one of the plurality of conditional expressions becomes true, and the value indicated by the calculation section combined with the true conditional expression is used. The program conversion device according to Claim 1 or Claim 2.
4. The analysis means performs analysis of the program using an abstract syntax tree. The program conversion device according to any one of Claims 1 to 3.
5. A computer analyzes a program to detect a portion that includes a conditional branch and calculates a value according to the execution result of the conditional branch, A program is generated based on the analysis result, in which a plurality of combinations of a conditional expression and a calculation unit that is configured without including a conditional branch and indicates a value are provided, only any one of the plurality of conditional expressions becomes true, and the value indicated by the calculation unit combined with the true conditional expression is used. A program conversion method including this.
6. For a computer, analyze a program to detect a part that includes a conditional branch and calculates a value according to the execution result of the conditional branch; generate a program based on the analysis result, in which a plurality of combinations of a conditional expression and a calculation unit that is configured without including a conditional branch and indicates a value are provided, only any one of the plurality of conditional expressions becomes true, and the value indicated by the calculation unit combined with the true conditional expression is used; A program for causing it to execute.
Citation Information
Patent Citations
Predication of control flow instructions with associated texture loading instructions for graphics processing units
JP2015509249A
WO2009-251684