JP3236714B2 - Program conversion device and program conversion method - Google Patents
Program conversion device and program conversion methodInfo
- Publication number
- JP3236714B2 JP3236714B2 JP26505093A JP26505093A JP3236714B2 JP 3236714 B2 JP3236714 B2 JP 3236714B2 JP 26505093 A JP26505093 A JP 26505093A JP 26505093 A JP26505093 A JP 26505093A JP 3236714 B2 JP3236714 B2 JP 3236714B2
- Authority
- JP
- Japan
- Prior art keywords
- variable
- arithmetic expression
- loop
- program
- expression
- Prior art date
- Legal status (The legal status 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 status listed.)
- Expired - Lifetime
Links
Landscapes
- Devices For Executing Special Programs (AREA)
Description
【0001】[0001]
【産業上の利用分野】本発明は、ソースコードを対象コ
ードに変換するコンパイラ等に適用され、ループ処理内
で用いられる誘導変数についてコードの最適化を行うプ
ログラム変換装置、およびプログラム変換方法に関す
る。BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a program conversion apparatus and a program conversion method which are applied to a compiler or the like for converting a source code into a target code and optimize a code for an induction variable used in a loop process.
【0002】[0002]
【従来の技術】コンパイラ等によってプログラムのソー
スコードを対象コードに変換する際などには、多くの場
合、対象コードのサイズの低減や実行速度の向上等を目
的として種々の最適化処理が行われ、そのうちのひとつ
として誘導変数の最適化が行われることもある。上記誘
導変数は、例えば「コンパイラII」(A.Vエイホ R.セシ
ィ J.D.ウルマン共著、原田賢一訳:サイエンス社)に
記載されているように、ループ処理において、1回のル
ープが繰り返されるごとに値が正又は負の一定量ずつ増
加する変数のことで、その最適化とは、例えばソースコ
ードにおいてループ処理の制御変数に所定の数を乗算し
て値を得る誘導変数が用いられている場合、前回のルー
プ処理における誘導変数の値に上記所定の数を加算して
新たな値を得るコードを生成することなどにより、処理
速度の向上やコードサイズの低減を図ることである。2. Description of the Related Art When converting a program source code into a target code by a compiler or the like, in many cases, various optimization processes are performed for the purpose of reducing the size of the target code and improving the execution speed. One of them is to optimize the induction variables. As described in, for example, “Compiler II” (authored by AV Eho R. Cessy JD Ullman, translated by Kenichi Harada: Science), the value of the induction variable is changed each time one loop is repeated in loop processing. Optimization is a variable that increases by a fixed amount, positive or negative, and optimization means, for example, when an induction variable that obtains a value by multiplying a control variable for loop processing by a predetermined number is used in the source code, In order to improve the processing speed and reduce the code size, for example, a code for obtaining a new value by adding the predetermined number to the value of the induction variable in the loop processing is generated.
【0003】誘導変数の最適化は、データ処理を行うた
めに記述された、膨大な要素を持つ配列の各要素に数値
を格納するようなループ処理に対して特に有効である。
何故なら配列の各要素にデータを格納するような記述を
機械語プログラムに翻訳する場合、コンパイラは、各要
素のアドレスを計算する必要があり、その各要素のアド
レスの計算には、各要素のサイズの大きさと、それぞれ
の要素の順位を示す制御変数との乗算が行われるからで
ある。一般に機械語命令の乗算命令は加算命令より実行
時間が長いため、このような乗算を加算に置き換える
と、上述のループ処理が機械語に置き換えられたときの
処理速度は一段と向上する。[0003] The optimization of induction variables is particularly effective for loop processing described for performing data processing, in which a numerical value is stored in each element of an array having a large number of elements.
When translating a description that stores data in each element of an array into a machine language program, the compiler needs to calculate the address of each element, and the calculation of the address of each element includes the calculation of the address of each element. This is because the multiplication of the size of the size and a control variable indicating the rank of each element is performed. Generally, the execution time of a multiplication instruction of a machine language instruction is longer than that of an addition instruction. Therefore, when such multiplication is replaced with addition, the processing speed when the above-described loop processing is replaced with a machine language is further improved.
【0004】なお、コンパイラ等における上記のような
誘導変数の最適化はプログラム変換装置を用いて行われ
る。プログラム変換装置について説明する前に、使用す
る用語について以下に説明する。 ・制御変数 ループ処理を続けるか、中止するかの判定を行うために
使用され、ループ処理が一回行われる度に一定の値だけ
増加する変数である。 ・演算式 変数、定数を被演算子とする式である。(例えば、10
0*x+2、x/200+10) ・代入文 等号の左側に変数が存在し、また右側に変数、定数、演
算式が存在して、等号の左側の変数に、等号の右側の内
容を代入する文である。(例えば、y=130、y=1
00*x+2、y=x/200+10) ・線形演算式 変数が被演算子として使用されている演算式で、全ての
変数の次数が1であるものをいう。(例えば、100*
x+2 x/200+10) ・変数の定義 代入文によって、変数の値を設定することである。(例
えば、a=100、s=100*2) ・変数の使用 演算式の被演算子に変数を使用することである。The above optimization of the induced variables in a compiler or the like is performed using a program conversion device. Before describing the program conversion device, terms used will be described below. Control variable This variable is used to determine whether to continue or stop the loop processing, and increases by a certain value each time the loop processing is performed once. • Arithmetic expression An expression that uses variables and constants as operands. (For example, 10
0 * x + 2, x / 200 + 10)-Assignment statement There is a variable on the left side of the equal sign, and there are variables, constants, and arithmetic expressions on the right side. This is the statement to be assigned. (For example, y = 130, y = 1
00 * x + 2, y = x / 200 + 10) Linear operation expression This is an operation expression in which variables are used as operands, and the order of all the variables is 1. (For example, 100 *
x + 2 x / 200 + 10) Definition of variable The value of a variable is set by an assignment statement. (For example, a = 100, s = 100 * 2) Use of a variable The use of a variable as an operand in an arithmetic expression.
【0005】図3はC言語のコンパイラに備えられる従
来のプログラム変換装置の構成を示す図である。プログ
ラム変換装置は、誘導変数保持部21と、ループ内誘導
変数検出部22と、ループ内誘導変数書換部23とで構
成される。誘導変数保持部21は、ループ内の線形演算
式、誘導変数の変数名、1ループ処理ごとの増分値、お
よび初期値を保持する。FIG. 3 is a diagram showing the configuration of a conventional program conversion device provided in a C language compiler. The program conversion device includes an induction variable holding unit 21, an in-loop induction variable detection unit 22, and an in-loop induction variable rewriting unit 23. The induction variable holding unit 21 holds a linear operation expression in a loop, a variable name of an induction variable, an increment value for each loop process, and an initial value.
【0006】ループ内誘導変数検出部22は、プログラ
ム中のループ処理内の演算に対して線形演算式検出動作
を行い、線形演算式検出動作によって検出された演算で
定義されている変数を誘導変数とし、誘導変数と、その
誘導変数に関する情報とを誘導変数保持部21に保持さ
せる。線形演算式検出動作について具体的に述べる。線
形演算式検出部22は、プログラム中のそれぞれのルー
プ処理において、そのループ処理が一回実行される度毎
に実行される演算を検出し、その演算式が、制御変数と
定数とを被演算子とする演算式であるか、あるいは、制
御変数と変数とを被演算子とする演算式であるかを調べ
る(演算式は、制御変数と、変数と、定数とを被演算子
とする演算式であってもよい。)。もし他方の被演算子
が変数であれば、その変数の定義が、ループ処理内に存
在するか否かを調べる。このような調査の結果、一方の
被演算子が制御変数であり、他方の被演算子が定数ある
いはループ処理内で値が不変の変数であれば、誘導変数
検出部22は、その演算式が線形演算式であるか否かを
調べる。もしループ内誘導変数検出部22が線形演算式
を検出すれば、その線形演算式が存在した箇所を記憶
し、その線形演算式によって定義されている変数を誘導
変数とする。このようにしてループ内誘導変数検出部2
2が誘導変数を求め、誘導変数保持部21に保持させた
あと、ループ内誘導変数検出部22は、線形演算式検出
動作によって検出された線形演算式の、1回のループ処
理による演算結果の増分値を算出する。ここで増分値
は、正の値でも負の値でもよい。線形演算式の演算結果
の増分値を求めた後、ループ内誘導変数検出部22は、
誘導変数の初期値を求めて誘導変数保持部21に保持さ
せる。The in-loop induction variable detection unit 22 performs a linear operation expression detection operation for an operation in a loop process in a program, and converts a variable defined by the operation detected by the linear operation expression detection operation into an induction variable. Then, the induced variable and information on the induced variable are held in the induced variable holding unit 21. The linear operation expression detection operation will be specifically described. In each loop process in the program, the linear operation expression detection unit 22 detects an operation to be performed each time the loop process is executed once, and the operation expression determines a control variable and a constant by the operation. Check whether the operation expression is a child operation or an operation expression using a control variable and a variable as operands. (The operation expression is an operation expression using a control variable, a variable, and a constant as operands.) It may be an expression.). If the other operand is a variable, it checks whether the definition of the variable exists in the loop processing. As a result of such an investigation, if one operand is a control variable and the other operand is a constant or a variable whose value is invariable in the loop processing, the induced variable detection unit 22 determines that the operation expression is Check whether it is a linear operation expression. If the in-loop induction variable detection unit 22 detects a linear operation expression, the location where the linear operation expression exists is stored, and a variable defined by the linear operation expression is set as an induction variable. Thus, the in-loop induced variable detection unit 2
2 calculates the induction variable and causes the induction variable holding unit 21 to hold the induction variable. Then, the in-loop induction variable detection unit 22 calculates the calculation result of the linear operation expression detected by the linear operation expression detection operation by one loop processing. Calculate the increment value. Here, the increment value may be a positive value or a negative value. After obtaining the increment value of the operation result of the linear operation expression, the in-loop induction variable detection unit 22
The initial value of the induced variable is determined and held in the induced variable holding unit 21.
【0007】ループ内誘導変数書換部23は、定義書換
部24と、判定条件書換部25とで構成される。定義書
換部24は、ループ処理内の誘導変数の定義を書き換え
る。具体的には、定義書換部24は、検出した線形演算
式に乗算、除算が含まれており、書き換え有効であるか
否かを判定する。もし書き換え有効であると判定する
と、書き換えのために使用できる変数を生成し、その変
数を、ループ内誘導変数検出部22が求めた増分値だけ
増加させる加算式のコードを作成し、新たに生成した変
数が作成した加算式のコードで定義される代入文を、プ
ログラムのループ処理内の所定の位置に書き込む。書き
込み後、定義書換部24は、プログラムの、ループ内誘
導変数検出部22が検出した箇所の線形演算式を、変数
に書き換える。The in-loop induction variable rewriting unit 23 includes a definition rewriting unit 24 and a judgment condition rewriting unit 25. The definition rewriting unit 24 rewrites the definition of the induction variable in the loop processing. Specifically, the definition rewriting unit 24 determines whether the detected linear operation expression includes multiplication and division, and whether the rewriting is valid. If it is determined that rewriting is valid, a variable that can be used for rewriting is generated, and an addition-type code that increases the variable by the increment value obtained by the in-loop induced variable detection unit 22 is created. An assignment statement defined by the addition formula code created by the created variable is written at a predetermined position in the loop processing of the program. After the writing, the definition rewriting unit 24 rewrites, in the program, the linear operation expression at the position detected by the in-loop induction variable detection unit 22 into a variable.
【0008】判定条件書換部25は、制御変数が、ルー
プ処理外で、他の変数を定義するために使用されている
か否かを確認し、もし使用されていなければ、制御変数
によって行われていたループ処理を続けるか終了するか
の判定を、新たな変数が行うようにし、制御変数する初
期化する代入文のコードと、制御変数の内容を増加させ
ている代入文のコードと、制御変数が判定を行っている
代入文のコードとをループ処理から消去する。The judgment condition rewriting unit 25 checks whether or not the control variable is used to define another variable outside the loop processing. If the control variable is not used, it is performed by the control variable. The new variable determines whether to continue or terminate the loop processing, and the code of the assignment statement to initialize the control variable, the code of the assignment statement that increases the content of the control variable, and the control variable Deletes the code of the assignment statement for which the determination is made from the loop processing.
【0009】尚、上述の初期化コードを作成する構成、
判定を書き換える構成の詳細については、本発明の主眼
でないので説明を省略する。以上のように構成されたプ
ログラム変換装置の動作について、説明する。図4
(a)は、各要素の大きさがワード型(2バイト)であ
る配列a〔〕の各要素(aIn addition, a configuration for creating the above-mentioned initialization code,
The details of the configuration for rewriting the determination are not the focus of the present invention, and thus description thereof is omitted. The operation of the program conversion device configured as described above will be described. FIG.
(A) shows each element (a) of an array a [] in which the size of each element is a word type (2 bytes).
〔0〕〜a〔98〕)に、0
が代入されるように、C言語で記述されたプログラムで
ある。[0] to a [98])
Is a program written in C language so that is substituted.
【0010】プログラム変換装置を備えたコンパイラ
は、プログラム中の配列についての記述を書き換える。
書き換えた結果を図4(b)に示す。配列の書き換え
は、本発明の主眼ではないので説明を省略するが、書き
換えられた箇所について説明しておく。変数s1は、配
列の各要素のアドレスを指示するためのポインタ変数で
ある。ポインタ変数s1は、配列のため確保されている
領域のメモリ上の先頭のアドレスから、それぞれの要素
のアドレスへのオフセット値を足して計算される。図中
の「s1=&a+2*i」は、配列の各要素のアドレス
を計算し、計算結果をポインタ変数s1に代入する代入
文である。この代入文において、&aは、上述の配列a
〔〕の先頭のアドレスであり、2は、配列a〔〕の各要
素のバイトサイズを示す。更に変数iは、それぞれの要
素の順位を示す制御変数である。次の行の「*s1=
0」は、ポインタ変数s1が指示するアドレスのメモリ
に0を格納するためのコードである。このように配列の
記述が書き換えられたプログラムに対して、上述のプロ
グラム変換装置が作動する。ループ内誘導変数検出部2
2が線形演算式検出動作を行い、線形演算式のコードで
ある「&a+2*i」を検出して、変数s1を誘導変数
として誘導変数保持部21に保持させる。更にループ内
誘導変数検出部22は、線形演算式「&a+2*i」の
演算結果の増分値を求める。ループ内誘導変数検出部2
2は、制御変数iの内容を増加する代入文のコードであ
る「i=i+1」を参照して、制御変数iの増分値であ
る1を求め、「&a+2*i」の増分値である2を算出
する。次に定義書換部24は、線形演算式の書き換えの
ために使用できる変数である変数tを生成し、変数t
が、2だけ加算されるような加算式のコードである「t
=t+2」を作成して、プログラム中の所定の位置に書
き込み、プログラム中の、線形演算式のコードである
「&a+2*i」が記述されている箇所を、変数tに書
き換える。その結果、代入文「s1=&a+2*i」
は、「s1=t」に書き換えられる。更に定義書換部2
4は、変数tの内容を初期化するコードである「t=&
a」を作成し、これらをプログラム中の所定の位置に書
き込む。判定条件書換部25は、ループ外で、制御変数
iが、他の変数を定義するために使用されているか否か
を確認し、もし使用されていなければ、制御変数iによ
って行われていたループ処理を続けるか終了するかの判
定を、変数tが行うようにし、制御変数iを初期化する
代入文のコードと、制御変数iの内容を増加させる代入
文のコードと、制御変数iがループ処理の判定を行う代
入文のコードとをループ処理から消去する。その結果、
図4(b)に示したプログラムは、図4(c)に示すよ
うに、ループ処理が変数tによって制御されるように書
き換えられる。A compiler having a program conversion device rewrites a description of an array in a program.
The rewritten result is shown in FIG. The description of the rewriting of the array is omitted because it is not the main purpose of the present invention, but the rewritten portion will be described. The variable s1 is a pointer variable for indicating the address of each element of the array. The pointer variable s1 is calculated by adding an offset value to the address of each element from the head address on the memory of the area reserved for the array. "S1 = & a + 2 * i" in the figure is an assignment statement for calculating the address of each element of the array and assigning the calculation result to the pointer variable s1. In this assignment statement, & a is the array a
[] Is the head address, and 2 indicates the byte size of each element of the array a []. Further, the variable i is a control variable indicating the order of each element. "* S1 =
"0" is a code for storing 0 in the memory at the address indicated by the pointer variable s1. The above-described program conversion device operates on the program whose array description has been rewritten in this way. Induction variable detection part 2 in loop
2 performs a linear operation expression detection operation, detects “& a + 2 * i” which is a code of the linear operation expression, and causes the induction variable holding unit 21 to hold the variable s1 as an induction variable. Further, the in-loop induction variable detection unit 22 obtains an increment value of the operation result of the linear operation expression “& a + 2 * i”. Induction variable detection part 2 in loop
2 refers to “i = i + 1”, which is the code of an assignment statement that increases the content of control variable i, obtains 1 which is the increment value of control variable i, and 2 which is the increment value of “& a + 2 * i” Is calculated. Next, the definition rewriting unit 24 generates a variable t that can be used for rewriting the linear operation expression,
Is an addition-type code such that “t” is added by “t”.
= T + 2 ”is written at a predetermined position in the program, and the portion of the program where“ & a + 2 * i ”, which is the code of the linear operation expression, is rewritten to the variable t. As a result, the assignment statement “s1 = & a + 2 * i”
Is rewritten to “s1 = t”. Further, definition rewriting unit 2
4 is a code for initializing the contents of the variable t, "t = &
a "are created, and these are written at predetermined positions in the program. The determination condition rewriting unit 25 checks whether or not the control variable i is used to define another variable outside the loop, and if not used, determines whether the control variable i is The variable t determines whether to continue or terminate the processing, the code of an assignment statement for initializing the control variable i, the code of an assignment statement for increasing the content of the control variable i, and the control variable i are looped. The code of the assignment statement that determines the processing is deleted from the loop processing. as a result,
The program shown in FIG. 4B is rewritten so that the loop processing is controlled by the variable t, as shown in FIG. 4C.
【0011】[0011]
【発明が解決しようとする課題】しかしながら上記従来
技術によれば、ループ処理の外部に存在する演算式にお
いて、そのループ処理の制御変数が被演算子として使用
されている場合、プログラム変換装置は、ループ処理内
の制御変数の内容を増加させている代入文のコードを消
去することができず、ループ処理が機械語に置き換えら
れたときの処理速度の高速化が充分に達成できないとい
う問題点があった。However, according to the above prior art, when a control variable of a loop process is used as an operand in an arithmetic expression existing outside the loop process, the program conversion device is configured as follows. The problem is that the code of the assignment statement that increases the contents of the control variables in the loop processing cannot be erased, and the processing speed cannot be sufficiently increased when the loop processing is replaced with machine language. there were.
【0012】例えば、図5(a)は、ループ処理によっ
て、配列a〔〕のa[0012] For example, FIG. 5A shows that a
〔0〕〜a〔998〕までの要素に
0が代入され、配列の最後の要素であるa0 is assigned to the elements from [0] to a [998], and the last element of the array, a
〔999〕
に、1が代入されるように記述されたプログラムであ
る。このようなプログラムに対してプログラム変換装置
が、上述の書き換えの動作を行う場合、プログラム変換
装置は、a[999]
Is a program written so that 1 is assigned to When the program conversion device performs the above-described rewriting operation on such a program, the program conversion device
〔999〕のアドレスを求めるためにループ
処理終了時に999という数値を格納しているはずの制
御変数iを消去しないで、ループ処理内に、制御変数i
を使用したコードを残したまま処理を終了する。つまり
プログラム変換装置は、図5(b)のようにプログラム
について、線形演算式「s1=&a+2*i」のコード
が行う計算を、加算文「t=t+2」のコードで代用す
るように書き換えておきながらも、制御変数iの内容を
増加させている代入文のコードを消去することができ
ず、図5(c)の状態で処理を終了する。このプログラ
ムは処理を999回繰り返して行うプログラムであるか
ら、プログラム変換装置によるプログラムの書き換え
後、コンパイラによって最終的に生成される機械語プロ
グラムは、その冗長な線形演算式のコードに該当する機
械語命令を999回繰り返して行う。その結果、機械語
命令の実行時間は必要以上に長くなる。In order to obtain the address of [999], the control variable i that should have stored the numerical value of 999 at the end of the loop processing is not deleted.
Terminates processing while leaving the code using. In other words, the program conversion device rewrites the program as shown in FIG. 5B so that the calculation performed by the code of the linear operation expression “s1 = & a + 2 * i” is substituted by the code of the addition statement “t = t + 2”. However, the code of the assignment statement increasing the content of the control variable i cannot be erased, and the process ends in the state of FIG. Since this program is a program that repeats the processing 999 times, the machine language program finally generated by the compiler after rewriting the program by the program conversion device is a machine language program corresponding to the code of the redundant linear operation expression. The instruction is repeated 999 times. As a result, the execution time of the machine language instruction becomes longer than necessary.
【0013】本発明は上記問題点に鑑み、ループ処理外
で他の変数の定義に使用されている誘導変数をも対象と
し、プログラム処理の高速化を実現するプログラム変換
装置を提供することを目的とする。The present invention has been made in consideration of the above problems, and has as its object to provide a program conversion apparatus which targets induction variables used for defining other variables outside loop processing and realizes high-speed program processing. And
【0014】[0014]
【課題を解決するための手段】上記課題を解決するため
に本発明のプログラム変換装置は、プログラム保持部に
保持されている処理対象のプログラムのループ処理内の
制御変数を含む演算式の演算結果の増分値を求め、その
増分値だけ中身が増加する新たな変数を作成し、新たな
変数および増分値を被演算子とする加算式を作成し、そ
の加算式の演算結果が新たな変数に代入される代入文を
作成して、前記演算式を新たな変数に書き換え、更にル
ープ処理外の前記制御変数を含む演算式を新たな変数に
書き換えるプログラム変換装置であって、プログラム保
持部に保持されているプログラムのループ処理内から、
制御変数が被演算子として使用され、他の演算子に、定
数あるいはループ処理内で不変な変数が使用されている
演算式を検出するループ内演算式検出手段と、前記ルー
プ内演算式検出手段が検出した演算式が含まれるループ
処理の外部から、同一の演算式を検出し、更に当該演算
式において被演算子として使用されている変数が、ルー
プ処理からループ処理の外部の演算式までの領域内に定
義されているか否かを判定して、定義されていないと判
定すれば、検出した演算式は書き換え可能であると判定
し、定義されていると判定すれば、検出した演算式は書
き換え不可能であると判定するループ外演算式検出手段
と、前記制御変数の、一回のループ処理における増分値
に基づいて、前記ループ内演算式検出手段が検出した演
算式の、1回の演算の実行による演算結果の増分値を算
出する増分値算出手段と、前記プログラム保持部に保持
されているプログラム中で、使用されてない変数名の変
数を作成する変数作成手段と、前記変数作成手段が作成
した変数と、前記増分値算出手段が算出した増分値とを
加算し、加算した結果を当該変数に代入する代入文を作
成する代入文作成手段と、プログラム中の制御変数の値
を更新する代入文を、前記代入文作成手段が作成した代
入文に書き換え、前記ループ内演算式検出手段が検出し
た箇所の演算式を、前記変数作成手段が作成した変数に
書き換えるループ内演算式書き換え手段とループ外演算
式検出手段が、書き換え可能であると判定した場合、前
記ループ外演算式検出手段が検出した箇所の演算式を、
前記変数作成手段が作成した変数に書き換えるループ外
演算式書き換え手段とを備えている。In order to solve the above-mentioned problems, a program conversion apparatus according to the present invention provides an operation result of an operation expression including a control variable in a loop process of a program to be processed held in a program holding unit. Is calculated, a new variable whose content increases by the increment is created, an addition expression is created using the new variable and the increment as an operand, and the operation result of the addition expression is added to the new variable. A program conversion device that creates an assignment statement to be substituted, rewrites the arithmetic expression with a new variable, and further rewrites an arithmetic expression containing the control variable outside the loop processing with a new variable, the program conversion device holding From within the loop processing of the program
In-loop arithmetic expression detecting means for detecting an arithmetic expression in which a control variable is used as an operand and a constant or an invariable variable is used in loop processing for another operator, and said arithmetic expression in loop detection means Detects the same operation expression from the outside of the loop process that includes the operation expression detected, and furthermore, the variable used as the operand in the operation expression is changed from the loop process to the operation expression outside the loop process. It is determined whether or not it is defined in the area, if it is determined that it is not defined, it is determined that the detected arithmetic expression is rewritable, and if it is determined that it is defined, the detected arithmetic expression is An out-of-loop operation expression detecting means for determining that rewriting is impossible, and an operation expression detected by the in-loop operation expression detecting means based on an increment value of the control variable in one loop processing. Performance Value calculating means for calculating an increment value of a calculation result by executing the above, variable creating means for creating a variable having an unused variable name in a program held in the program holding unit, and the variable creating means Adding the variable created by the above and the increment value calculated by the increment value calculating means, and updating the value of the control variable in the program; In-loop arithmetic expression rewriting means for rewriting the assignment statement to be written into the assignment statement created by the assignment statement creating means, and rewriting the arithmetic expression at the location detected by the in-loop arithmetic expression detecting means to the variable created by the variable creating means. When the arithmetic expression outside the loop is determined to be rewritable, the arithmetic expression at the position detected by the arithmetic expression outside the loop is
And an out-of-loop arithmetic expression rewriting means for rewriting the variable created by the variable creation means.
【0015】また、本発明のプログラム変換方法は、プ
ログラム保持部に保持されている処理対象のプログラム
のループ処理内の制御変数を含む演算式の演算結果の増
分値を求め、その増分値だけ中身が増加する新たな変数
を作成し、新たな変数および増分値を被演算子とする加
算式を作成し、その加算式の演算結果が新たな変数に代
入される代入文を作成して、前記演算式を新たな変数に
書き換え、更にループ処理外の前記制御変数を含む演算
式を新たな変数に書き換えるプログラム変換方法であっ
て、プログラム保持部に保持されているプログラムのル
ープ処理内から、制御変数が被演算子として使用され、
他の演算子に、定数あるいはループ処理内で不変な変数
が使用されている演算式を検出するループ内演算式検出
ステップと、前記ループ内演算式検出ステップが検出し
た演算式が含まれるループ処理の外部から、同一の演算
式を検出し、更に当該演算式において被演算子として使
用されている変数が、ループ処理からループ処理の外部
の演算式までの領域内に定義されているか否かを判定し
て、定義されていないと判定すれば、検出した演算式は
書き換え可能であると判定し、定義されていると判定す
れば、検出した演算式は書き換え不可能であると判定す
るループ外演算式検出ステップと、前記制御変数の、一
回のループ処理における増分値に基づいて、前記ループ
内演算式検出ステップが検出した演算式の、1回の演算
の実行による演算結果の増分値を算出する増分値算出ス
テップと、前記プログラム保持部に保持されているプロ
グラム中で、使用されてない変数名の変数を作成する変
数作成ステップと、前記変数作成ステップが作成した変
数と、前記増分値算出ステップが算出した増分値とを加
算し、加算した結果を当該変数に代入する代入文を作成
する代入文作成ステップと、プログラム中の制御変数の
値を更新する代入文を、前記代入文作成ステップが作成
した代入文に書き換え、前記ループ内演算式検出ステッ
プが検出した箇所の演算式を、前記変数作成ステップが
作成した変数に書き換えるループ内演算式書き換えステ
ップと ループ外演算式検出ステップが、書き換え可能
であると判定した場合、前記ループ外演算式検出ステッ
プが検出した箇所の演算式を、前記変数作成ステップが
作成した変数に書き換えるループ外演算式書き換えステ
ップとからなる。Further, according to the program conversion method of the present invention, an increment value of an operation result of an arithmetic expression including a control variable in a loop process of a program to be processed held in a program holding unit is obtained, and only the content of the increment value is obtained. Creates a new variable that increases, creates an addition expression with the new variable and the increment value as operands, creates an assignment statement in which the operation result of the addition expression is assigned to the new variable, A program conversion method for rewriting an arithmetic expression to a new variable and further rewriting an arithmetic expression including the control variable outside the loop processing to a new variable, wherein a control method is executed from within the loop processing of the program held in the program holding unit. Variables are used as operands,
In another loop, an arithmetic expression detection step for detecting an arithmetic expression in which a constant or an invariable variable is used in the loop processing, and a loop processing including an arithmetic expression detected by the arithmetic expression detection step in the loop From the outside, the same arithmetic expression is detected, and whether the variable used as the operand in the arithmetic expression is defined in the region from the loop processing to the arithmetic expression outside the loop processing is determined. If it is determined that it is not defined, it is determined that the detected arithmetic expression is rewritable, and if it is determined that it is defined, it is determined that the detected arithmetic expression is not rewritable. An arithmetic expression detecting step, and an arithmetic operation performed by a single arithmetic operation of the arithmetic expression detected by the arithmetic expression detecting step in the loop based on an increment value of the control variable in one loop processing. An increment value calculating step of calculating an increment value of a result, a variable creating step of creating a variable having a variable name that is not used in the program held in the program holding unit, and a variable created by the variable creating step. Adding an increment value calculated by the increment value calculating step and an assignment statement creating step of creating an assignment statement for assigning the added result to the variable; and an assignment statement updating a value of a control variable in the program. Rewriting the assignment expression created by the assignment statement creating step, and rewriting the arithmetic expression at the location detected by the in-loop arithmetic expression detection step to the variable created by the variable creating step; If the expression detection step determines that the operation can be rewritten, the expression at the location detected by the out-of-loop operation expression detection step is replaced with the variable. Comprising a loop outside arithmetic expression rewriting step of rewriting the variable creation step creates.
【0016】[0016]
【作用】上記の手段により本発明のプログラム変換装置
(方法)において、ループ内演算式検出手段(ステッ
プ)は、プログラム保持部に保持されているプログラム
のループ処理内から、制御変数が被演算子として使用さ
れている演算式を検出する。検出した演算式が含まれる
ループ処理の外部に対して、ループ外演算式検出手段
(ステップ)が作動し、前記ループ内演算式検出手段
(ステップ)が検出した演算式と、同一の演算式を検出
し、更に当該演算式において被演算子として使用されて
いる変数が、ループ処理からループ処理の外部の演算式
までの領域内に定義されているか否かを判定する。前記
制御変数の、一回のループ処理における増分値に対し
て、増分値算出手段(ステップ)が作動し、前記ループ
内演算式検出手段(ステップ)が検出した演算式の、1
回の演算の実行による演算結果の増分値が算出される。
前記プログラム保持部に保持されているプログラム中に
対して、変数作成手段(ステップ)が作動し、使用され
てない変数名の変数が、使用可能な変数として作成され
る。前記変数作成手段(ステップ)が作成した変数と、
前記増分値算出手段(ステップ)が算出した増分値とに
対して、代入文作成手段(ステップ)が作動し、前記変
数作成手段(ステップ)が作成した変数と、前記増分値
算出手段(ステップ)が算出した増分値とを加算した結
果が当該変数に代入される代入文が作成される。プログ
ラム中の制御変数の値を更新する代入文と、前記代入文
作成手段(ステップ)が作成した代入文とに対して、前
記ループ内演算式検出手段(ステップ)が作動し、検出
した箇所の演算式が、前記変数作成手段(ステップ)が
作成した変数に書き換えられ、前記ループ内演算式検出
手段(ステップ)が検出した箇所の演算式が、前記変数
作成手段(ステップ)が作成した変数に書き換えられ
る。前記ループ外演算式検出手段(ステップ)が書き換
え可能であると判定すると、前記ループ外演算式検出手
段(ステップ)が検出した箇所の演算式に対して、ルー
プ外演算式書き換え手段(ステップ)が作動し、前記ル
ープ外演算式検出手段(ステップ)が検出した箇所の演
算式が前記変数作成手段(ステップ)が作成した変数に
書き換えられる。According to the above-mentioned means, in the program conversion device (method) of the present invention, the in-loop operation expression detecting means (step) converts the control variable from the loop processing of the program held in the program holding section into the operand. Detects the arithmetic expression used as. Outside the loop processing that includes the detected arithmetic expression, the outside-loop arithmetic expression detection means (step) operates, and the same arithmetic expression as the arithmetic expression detected by the in-loop arithmetic expression detection means (step) is output. Then, it is determined whether or not the variable used as the operand in the operation expression is defined in a region from the loop processing to the operation expression outside the loop processing. An increment value calculating means (step) is operated for an increment value of the control variable in one loop processing, and one of the arithmetic expressions detected by the in-loop arithmetic expression detecting means (step) is calculated.
The increment value of the calculation result by performing the calculation twice is calculated.
The variable creating means (step) operates on the program held in the program holding unit, and a variable having an unused variable name is created as a usable variable. A variable created by the variable creating means (step);
The assignment statement creating means (step) operates on the increment value calculated by the increment value calculating means (step), and the variable created by the variable creating means (step) and the increment value calculating means (step) An assignment statement is created in which the result of adding the calculated increment value to the variable is assigned to the variable. The in-loop arithmetic expression detection means (step) operates on the assignment statement for updating the value of the control variable in the program and the assignment statement created by the assignment statement creation means (step), and the The arithmetic expression is rewritten to the variable created by the variable creating means (step), and the arithmetic expression at the position detected by the in-loop arithmetic expression detecting means (step) is replaced by the variable created by the variable creating means (step). Rewritten. If the out-of-loop arithmetic expression detection means (step) determines that the rewrite is possible, the out-of-loop arithmetic expression rewrite means (step) compares the arithmetic expression at the position detected by the out-of-loop arithmetic expression detection means (step). In operation, the arithmetic expression at the position detected by the out-of-loop arithmetic expression detecting means (step) is rewritten to the variable created by the variable creating means (step).
【0017】[0017]
【実施例】図1はプログラム変換装置の構成を示す図で
ある。このプログラム変換装置による誘導変数の最適化
は、例えばコンパイラに与えられるソースコードに対し
て行われるようにしてもよいし、また、コンパイラによ
るコンパイル処理の途中で得られる中間コードなどに対
して行われるようにしてもよい。FIG. 1 is a diagram showing the configuration of a program conversion device. The optimization of the induction variable by the program conversion device may be performed on, for example, a source code given to a compiler, or may be performed on an intermediate code obtained in the middle of a compiling process by the compiler. You may do so.
【0018】プログラム変換装置は、制御部11と、最
適化前コード保持部12と、誘導変数保持部13と、ル
ープ内誘導変数検出部14と、ループ外誘導変数検出部
15と、ループ内誘導変数書換部16と、ループ内誘導
変数書換部16と、ループ外誘導変数書換部19とで構
成される制御部11は、プログラム変換装置はプログラ
ムのプログラム変換処理の全体を制御する。The program conversion device includes a control unit 11, a pre-optimization code holding unit 12, an induction variable holding unit 13, a loop induction variable detection unit 14, an outside loop induction variable detection unit 15, a loop induction The control unit 11 including the variable rewriting unit 16, the in-loop induction variable rewriting unit 16, and the out-of-loop induction variable rewriting unit 19 causes the program conversion device to control the entire program conversion process of the program.
【0019】最適化前コード保持部12は、処理対象で
ある元のプログラムを保持する。誘導変数保持部13
は、最適化前コード保持部12に保持されているプログ
ラム中のループ処理内の線形演算式のコード、誘導変数
の変数名、1ループ処理ごとの増分値、および初期値を
保持する。ループ内誘導変数検出部14は、最適化前コ
ード保持部12に保持されているプログラムの、何れか
のループ処理内に存在する演算に対して線形演算式検出
動作を行い、(線形演算式検出動作は、従来技術として
既に説明しているので詳細な説明は省略する。)線形演
算式検出動作によって検出された演算式で定義されてい
る変数を誘導変数とし、誘導変数と、その誘導変数に関
する情報とを誘導変数保持部13に保持させる。もしル
ープ内誘導変数検出部14が線形演算式を検出すれば、
ループ内誘導変数検出部14は、その線形演算式が存在
していた箇所を記憶し、その線形演算式によって定義さ
れている変数を誘導変数とする。このようにして誘導変
数を求め、誘導変数保持部21に保持させたあと、ルー
プ内誘導変数検出部14は、線形演算式検出動作によっ
て検出された線形演算式の演算結果の増分値を算出す
る。ここで増分値は、正の値でも負の値でもよい。線形
演算式の増分値を算出した後、ループ内誘導変数検出部
14は、誘導変数の初期値を求めて誘導変数保持部21
に保持させる。The pre-optimization code holding unit 12 holds an original program to be processed. Induction variable holding unit 13
Holds the code of the linear operation expression in the loop processing in the program stored in the pre-optimization code storage unit 12, the variable name of the induction variable, the increment value for each loop processing, and the initial value. The in-loop induction variable detection unit 14 performs a linear operation expression detection operation on an operation existing in any of the loop processes of the program stored in the pre-optimization code storage unit 12 (linear operation expression detection). The operation has already been described as the prior art, so a detailed description will be omitted.) A variable defined by an arithmetic expression detected by the linear arithmetic expression detection operation is defined as an induction variable, and the induction variable and the induction variable The information is stored in the induction variable storage unit 13. If the in-loop induction variable detection unit 14 detects a linear operation expression,
The in-loop induction variable detection unit 14 stores the place where the linear operation expression was present, and sets a variable defined by the linear operation expression as an induction variable. After the induction variable is obtained in this way and held in the induction variable holding unit 21, the in-loop induction variable detection unit 14 calculates an increment value of the operation result of the linear operation expression detected by the linear operation expression detecting operation. . Here, the increment value may be a positive value or a negative value. After calculating the increment value of the linear operation expression, the in-loop induction variable detection unit 14 obtains the initial value of the induction variable and calculates the initial value of the induction variable.
To be held.
【0020】ループ外誘導変数検出部15は、最適化前
コード保持部12に保持されているプログラムの、ルー
プ内誘導変数検出部14が演算式を検出したループ処理
の外部から、ループ内誘導変数検出部14が検出した演
算式と同一の演算式を探索し、もし存在すれば、その演
算が存在する箇所を記憶する。記憶後、ループ外誘導変
数検出部15は、プログラム中の、ループ処理から検出
したループ処理の外部の演算式までの領域において、そ
の演算式で被演算子として使用されている変数(制御変
数あるいはループ処理内で不変な変数)が定義されてい
るか否かを判定する。定義されていなければ、ループ外
誘導変数検出部15は、探索した演算式は書き換え可能
であると判定し、定義されていれば、探索した演算式は
書き換え不可能であると判定する。例えば、最適化前コ
ード保持部12に保持されているプログラムのループ処
理内に「s1=i*3」という代入文のコードが存在
し、そのループ処理の外部に「s1=i*3」という代
入文のコードと、「w3=i*3」という代入文のコー
ドとが存在する場合、何れの代入文の演算式のコードを
も、ループ外誘導変数検出部15は検出し、それらの演
算式が存在する箇所を記憶する。また、最適化前コード
保持部12に保持されているプログラムのループ処理内
に「s1=s*i」という代入文のコードが存在し、そ
のループ処理の外部に「s4=s*i」という代入文の
コードが存在して、ループ処理から検出したループ処理
の外部の演算式「s4=s*i」までの領域に、「s=
3」という代入文のコードが存在する場合、ループ外誘
導変数検出部15は、「s4=s*i」というコード
と、「s=3」というコードとを検出する。The induction variable detection unit 15 outside the loop detects the induction variable inside the loop from outside the loop processing of the program stored in the pre-optimization code storage unit 12 where the induction variable detection unit 14 detects the operation formula. The same arithmetic expression as the arithmetic expression detected by the detection unit 14 is searched, and if present, the location where the arithmetic is present is stored. After the storage, in the area from the loop processing to the arithmetic expression external to the detected loop processing, the variable (control variable or control variable or It is determined whether or not a variable (invariant in the loop processing) is defined. If not defined, the out-of-loop induction variable detection unit 15 determines that the searched arithmetic expression is rewritable, and if defined, determines that the searched arithmetic expression is not rewritable. For example, the code of the assignment statement “s1 = i * 3” exists in the loop processing of the program stored in the pre-optimization code storage unit 12, and the code “s1 = i * 3” exists outside the loop processing. When the code of the assignment statement and the code of the assignment statement “w3 = i * 3” are present, the induction variable detection unit 15 outside the loop detects the code of the arithmetic expression of any of the assignment statements, and performs the calculation on them. Remember where the expression exists. In addition, the code of the assignment statement “s1 = s * i” exists in the loop processing of the program stored in the pre-optimization code storage unit 12, and “s4 = s * i” exists outside the loop processing. When the code of the assignment statement exists and the area from the loop processing to the arithmetic expression “s4 = s * i” outside the detected loop processing, “s =
When the code of the assignment statement “3” exists, the induction variable detection unit 15 outside the loop detects the code “s4 = s * i” and the code “s = 3”.
【0021】ループ内誘導変数書換部16は、定義書換
部17と、判定条件書換部18とで構成される。定義書
換部17は、最適化前コード保持部12に保持されてい
るプログラムの、ループ処理内の線形演算式の定義の書
き換えを行う。具体的には、ループ内誘導変数検出部1
4が検出した線形演算式に乗算、除算が含まれており書
き換え有効であるか否かを判定する。もし書き換え有効
であると判定したならば、定義書換部17は、書き換え
のために使用できる変数を生成し、その変数を、ループ
内誘導変数検出部14が算出した、線形演算式の増分値
だけ増加させる加算式のコードを作成して、最適化前コ
ード保持部12に保持されているプログラムの、ループ
処理内の所定の位置に書き込む。書き込み後、定義書換
部17は、最適化前コード保持部12に保持されている
プログラムの、ループ内誘導変数検出部14が検出した
箇所の線形演算式を、変数に書き換える。更に定義書換
部17は、誘導変数保持部13に保持されている誘導変
数の初期値を参照して、加算式コードで使用した変数を
初期化する代入文のコードを作成し、プログラムのルー
プ処理内の所定の位置に書き込む。The in-loop induced variable rewriting unit 16 is composed of a definition rewriting unit 17 and a judgment condition rewriting unit 18. The definition rewriting unit 17 rewrites the definition of the linear operation expression in the loop processing of the program stored in the pre-optimization code storage unit 12. Specifically, the in-loop induced variable detection unit 1
The multiplication and division are included in the linear operation expression detected by No. 4 and it is determined whether rewriting is valid. If it is determined that the rewriting is valid, the definition rewriting unit 17 generates a variable that can be used for the rewriting, and calculates the variable by the increment value of the linear operation expression calculated by the induction variable detection unit 14 in the loop. The addition-type code to be increased is created and written to a predetermined position in the loop processing of the program stored in the pre-optimization code storage unit 12. After the writing, the definition rewriting unit 17 rewrites, in the program stored in the pre-optimization code storage unit 12, the linear operation expression at the location detected by the in-loop induction variable detection unit 14 into a variable. Further, the definition rewriting unit 17 refers to the initial value of the induction variable held in the induction variable holding unit 13 to create a code of an assignment statement for initializing the variable used in the addition expression code, and executes the loop processing of the program. Write to a predetermined position in.
【0022】判定条件書換部18は、新たな変数がルー
プ処理を続けるか終了するかの判定を行うように最適化
前コード保持部12に保持されているプログラムのルー
プ処理を書き換える。更に制御変数の初期化する代入文
のコードと、制御変数の内容を増加させている代入文の
コードと、制御変数が判定を行うコードとを、最適化前
コード保持部12に保持されているプログラムのループ
処理から消去する。The determination condition rewriting unit 18 rewrites the loop processing of the program stored in the pre-optimization code storage unit 12 so as to determine whether a new variable continues or terminates the loop processing. Further, the code of the assignment statement for initializing the control variable, the code of the assignment statement for increasing the content of the control variable, and the code for determining the control variable are held in the pre-optimization code holding unit 12. Erase from the loop processing of the program.
【0023】ループ外誘導変数書換部19は、ループ外
誘導変数検出部15が書き換え可能と判定した場合、最
適化前コード保持部12に保持されているプログラム
の、ループ外誘導変数検出部15が検出した箇所の線形
演算式を、定義書換部17が生成した変数に書き換え
る。例えば、定義書換部17が「s1=3*i」という
代入文のコードを「s1=t」に書き換えており、ルー
プ外誘導変数検出部15が「s2=3*i」という代入
文のコードを検出したとすると、ループ外誘導変数書換
部19は、「s2=3*i」のコードを「s2=t」に
書き換える。When the out-of-loop induction variable detection unit 15 determines that the out-of-loop induction variable detection unit 15 is rewritable, the out-of-loop induction variable detection unit 15 of the program held in the pre-optimization code holding unit 12 The linear operation expression at the detected location is rewritten to a variable generated by the definition rewriting unit 17. For example, the definition rewriting unit 17 rewrites the code of the assignment statement “s1 = 3 * i” to “s1 = t”, and the out-of-loop induction variable detection unit 15 codes the code of the assignment statement “s2 = 3 * i”. Is detected, the out-of-loop induction variable rewriting unit 19 rewrites the code of “s2 = 3 * i” to “s2 = t”.
【0024】尚、上述の初期化コードを作成する構成、
判定を書き換える構成の詳細については、本発明の主眼
でないので説明を省略する。以上のように構成されたプ
ログラム変換装置の動作について、説明する。図3
(a)は、各要素の大きさがワード型(2バイト)であ
る配列a〔〕の各要素(aA configuration for creating the above-mentioned initialization code,
The details of the configuration for rewriting the determination are not the focus of the present invention, and thus description thereof is omitted. The operation of the program conversion device configured as described above will be described. FIG.
(A) shows each element (a) of an array a [] in which the size of each element is a word type (2 bytes).
〔0〕〜a〔98〕)に、0
を代入し、配列の最後の要素であるa[0] to a [98])
And assign the last element of the array, a
〔99〕に、終値
として1が代入されるようにC言語で記述されたプログ
ラムである。[99] is a program written in C language so that 1 is substituted as the closing value.
【0025】プログラム変換装置を備えたコンパイラ
は、プログラム中の配列についての記述を一旦書き換え
る。書き換えた結果を図3(b)に示す。このように配
列の記述が書き換えられたプログラムに対して、上述の
プログラム変換装置が作動する。先ず、制御部11は、
ループ内誘導変数検出部14を起動する。ループ内誘導
変数検出部14は線形演算式検出動作を行い、「&a+
2*i」を検出して、変数s1を誘導変数として最適化
前コード保持部12に保持させる。ループ内誘導変数検
出部14は、これらの線形演算式についての演算結果の
増分値を求める。つまり、ループ内誘導変数検出部14
は、制御変数iの値を増加している代入文のコードであ
る「i=i+1」を参照して、制御変数iの増分値であ
る1を求め、線形演算式が1回実行されることによる線
形演算式「&a+2*i」の増分値である2を算出す
る。次にループ外誘導変数検出部15が、ループ内誘導
変数検出部14が演算式を検出したループ処理の外部か
ら、ループ内誘導変数検出部14が検出した演算式であ
る「&a+2*i」と同一の演算式が等号の右側に存在
する代入文である「s1=&a+2*i」を検出する。
検出後、制御部11は、ループ外誘導変数検出部15を
起動する。ループ外誘導変数検出部15は、最適化前コ
ード保持部12内の、その演算式が存在する箇所を記憶
する。次に制御部11は、定義書換部17を起動する。
定義書換部17は、書き換えのために使用可能な変数で
ある変数tを生成し、変数tが、2だけ加算されるよう
な加算式のコードである「t=t+2」を作成して、プ
ログラム中の所定の位置に書き込み、プログラム中の線
形演算式のコードである「&a+2*i」を、変数tに
書き換える。更に定義書換部17は、変数tの内容を初
期化するコードである「t=&a」を作成し、これらを
プログラム中の所定の位置に書き込む。次に制御部11
は、判定条件書換部18を起動する。判定条件書換部1
8は、制御変数iによって行われていたループ処理を続
けるか終了するかの判定を、変数tが行うようにし、元
の誘導変数iの初期化する代入文のコードと、制御変数
iの内容を増加させている代入文のコードと、制御変数
iが判定を行っている代入文のコードとをループ処理内
から消去する。次に制御部11は、ループ外誘導変数書
換部19を起動する。ループ外誘導変数書換部19は、
ループ外誘導変数検出部15が検出した箇所の線形演算
式「&a+2*i」を、定義書換部17が生成した変数
tに書き換える。その結果、図5(b)に示したプログ
ラムは、ループ処理が変数tによって制御されるように
書き換えられる。書き換えた結果を図5(c)に示す。A compiler provided with a program conversion device once rewrites a description of an array in a program. The rewritten result is shown in FIG. The above-described program conversion device operates on the program whose array description has been rewritten in this way. First, the control unit 11
The in-loop induced variable detection unit 14 is started. The in-loop induction variable detection unit 14 performs a linear operation expression detection operation, and “& a +
2 * i ”is detected, and the variable s1 is held in the pre-optimization code holding unit 12 as an induction variable. The in-loop induction variable detection unit 14 calculates the increment value of the operation result of these linear operation expressions. That is, the in-loop induction variable detection unit 14
Refers to “i = i + 1”, which is the code of an assignment statement that increases the value of control variable i, obtains 1 that is the increment value of control variable i, and executes the linear operation expression once. Is calculated, which is an increment value of the linear operation expression “& a + 2 * i”. Next, the induction variable detection unit 15 outside the loop detects “& a + 2 * i”, which is an arithmetic expression detected by the induction variable detection unit 14 from outside the loop processing in which the induction variable detection unit 14 detects the arithmetic expression. The same arithmetic expression detects "s1 = & a + 2 * i" which is an assignment statement existing on the right side of the equal sign.
After the detection, the control unit 11 activates the out-of-loop induction variable detection unit 15. The out-of-loop induction variable detection unit 15 stores a location in the pre-optimization code holding unit 12 where the operation expression exists. Next, the control unit 11 activates the definition rewriting unit 17.
The definition rewriting unit 17 generates a variable t, which is a variable that can be used for rewriting, creates “t = t + 2”, which is a code of an addition expression in which the variable t is added by 2, and generates a program Then, "& a + 2 * i", which is a code of a linear operation expression in the program, is rewritten to a variable t. Further, the definition rewriting unit 17 creates "t = &a", which is a code for initializing the contents of the variable t, and writes these at a predetermined position in the program. Next, the control unit 11
Activates the judgment condition rewriting unit 18. Judgment condition rewriting unit 1
Reference numeral 8 designates the variable t to determine whether to continue or end the loop processing performed by the control variable i, the code of an assignment statement for initializing the original induction variable i, and the contents of the control variable i. And the code of the assignment statement for which the control variable i is making a determination is deleted from the loop processing. Next, the control unit 11 activates the induction variable rewriting unit 19 outside the loop. The induction variable rewriting unit 19 outside the loop
The linear operation expression “& a + 2 * i” at the location detected by the out-of-loop induction variable detection unit 15 is rewritten to the variable t generated by the definition rewriting unit 17. As a result, the program shown in FIG. 5B is rewritten so that the loop processing is controlled by the variable t. FIG. 5C shows the rewritten result.
【0026】[0026]
【発明の効果】以上説明してきたように本発明のプログ
ラム変換装置によれば、制御変数が、そのループ処理の
外部に存在する演算式において、そのループ処理の制御
変数が被演算子として使用されていても、そのループ処
理の外部に存在する演算式が、ループ内に存在するもの
と同一ならば、その外部の演算式をも書き換えることが
できるので、ループ処理内の制御変数の内容を増加させ
ている代入文のコードを消去することができ、ループ処
理が機械語に置き換えられたときの処理速度の高速化が
充分に達成できるという効果がある。As described above, according to the program conversion apparatus of the present invention, the control variable is used as the operand in the arithmetic expression existing outside the loop processing. However, if the arithmetic expression outside the loop processing is the same as that existing in the loop, the external arithmetic expression can be rewritten, so the contents of the control variables in the loop processing are increased. There is an effect that the code of the assigned assignment statement can be deleted, and the processing speed can be sufficiently increased when the loop processing is replaced with a machine language.
【図1】本発明の一実施例におけるプログラム変換装置
の構成図である。FIG. 1 is a configuration diagram of a program conversion device according to an embodiment of the present invention.
【図2】本発明のプログラム変換装置によるプログラム
の書き換えを示す図である。FIG. 2 is a diagram showing rewriting of a program by the program conversion device of the present invention.
【図3】従来のプログラム変換装置の構成図である。FIG. 3 is a configuration diagram of a conventional program conversion device.
【図4】従来のプログラム変換装置によるプログラムの
書き換えを示す図である。FIG. 4 is a diagram showing rewriting of a program by a conventional program conversion device.
【図5】従来のプログラム変換装置によるプログラムの
書き換えを示す図である。FIG. 5 is a diagram showing rewriting of a program by a conventional program conversion device.
11 制御部 12 最適化前コード保持部 13 誘導変数保持部 14 ループ内誘導変数検出部 15 ループ外誘導変数検出部 16 ループ内誘導変数書換部 17 定義書換部 18 判定条件書換部 19 ループ外誘導変数書換部 DESCRIPTION OF SYMBOLS 11 Control part 12 Code storage part before optimization 13 Induction variable storage part 14 Induction variable detection part in a loop 15 Induction variable detection part outside a loop 16 Induction variable rewriting part in a loop 17 Definition rewriting part 18 Judgment condition rewriting part 19 Induction variable outside a loop Rewriting department
───────────────────────────────────────────────────── フロントページの続き (56)参考文献 特開 平2−50257(JP,A) 特開 昭64−31232(JP,A) インターフェース,CQ出版社,1989 −3,第15巻第3号(no.142),p. 202−203 Wolfe,”Beyond Ind uction Variable”,A CM SIGPLAN Notice s,1992,Vol.27,No.7,p. 162−174 (58)調査した分野(Int.Cl.7,DB名) G06F 9/45 ────────────────────────────────────────────────── ─── Continuation of the front page (56) References JP-A-2-50257 (JP, A) JP-A-64-31232 (JP, A) Interface, CQ Publishing Company, 1989-3, Vol. 15, No. 3, Issue 3 (No. 142), pp. 202-203 Wolfe, "Beyond Induction Variable", ACM SIGGPLAN Notices, 1992, Vol. 27, No. 7, p. 162-174 (58) Fields investigated (Int. Cl. 7 , DB name) G06F 9/45
Claims (2)
象のプログラムのループ処理内の制御変数を含む演算式
の演算結果の増分値を求め、その増分値だけ中身が増加
する新たな変数を作成し、新たな変数および増分値を被
演算子とする加算式を作成し、その加算式の演算結果が
新たな変数に代入される代入文を作成して、前記演算式
を新たな変数に書き換え、更にループ処理外の前記制御
変数を含む演算式を新たな変数に書き換えるプログラム
変換装置であって、 プログラム保持部に保持されているプログラムのループ
処理内から、制御変数が被演算子として使用され、他の
演算子に、定数あるいはループ処理内で不変な変数が使
用されている演算式を検出するループ内演算式検出手段
と、 前記ループ内演算式検出手段が検出した演算式が含まれ
るループ処理の外部から、同一の演算式を検出し、更に
当該演算式において被演算子として使用されている変数
が、ループ処理からループ処理の外部の演算式までの領
域内に定義されているか否かを判定して、定義されてい
ないと判定すれば、検出した演算式は書き換え可能であ
ると判定し、定義されていると判定すれば、検出した演
算式は書き換え不可能であると判定するループ外演算式
検出手段と、 前記制御変数の、一回のループ処理における増分値に基
づいて、前記ループ内演算式検出手段が検出した演算式
の、1回の演算の実行による演算結果の増分値を算出す
る増分値算出手段と、 前記プログラム保持部に保持されているプログラム中
で、使用されてない変数名の変数を作成する変数作成手
段と、 前記変数作成手段が作成した変数と、前記増分値算出手
段が算出した増分値とを加算し、加算した結果を当該変
数に代入する代入文を作成する代入文作成手段と、 プログラム中の制御変数の値を更新する代入文を、前記
代入文作成手段が作成した代入文に書き換え、前記ルー
プ内演算式検出手段が検出した箇所の演算式を、前記変
数作成手段が作成した変数に書き換えるループ内演算式
書き換え手段とループ外演算式検出手段が、書き換え可
能であると判定した場合、前記ループ外演算式検出手段
が検出した箇所の演算式を、前記変数作成手段が作成し
た変数に書き換えるループ外演算式書き換え手段とを備
えることを特徴とするプログラム変換装置。1. An incremental value of an operation result of an arithmetic expression including a control variable in a loop process of a program to be processed held in a program holding unit is calculated, and a new variable whose content increases by the increment value is created. Then, create an addition expression using the new variable and the increment value as operands, create an assignment statement in which the operation result of the addition expression is assigned to the new variable, and rewrite the operation expression with the new variable. A program conversion device for rewriting an arithmetic expression including the control variable outside the loop processing into a new variable, wherein the control variable is used as an operand from within the loop processing of the program held in the program holding unit. , An arithmetic expression in a loop for detecting an arithmetic expression in which a constant or an invariable variable is used in loop processing for another operator, and an arithmetic expression detected by the arithmetic expression in the loop The same arithmetic expression is detected from outside the included loop processing, and the variable used as the operand in the arithmetic expression is defined in the region from the loop processing to the arithmetic expression outside the loop processing. It is determined whether or not the detected arithmetic expression is rewritable. If it is determined that the arithmetic expression is not defined, it is determined that the detected arithmetic expression is rewritable. An arithmetic expression outside the loop to be determined, and an arithmetic result of execution of one arithmetic operation of the arithmetic expression detected by the arithmetic expression inside the loop based on an increment value of the control variable in one loop processing An increment value calculating means for calculating an increment value of the variable; a variable creating means for creating a variable having a variable name that is not used in the program held in the program holding unit; Statement assignment means for creating an assignment statement for adding the calculated variable and the increment value calculated by the increment value calculation means and assigning the addition result to the variable; and assignment for updating the value of the control variable in the program. The statement in the loop is rewritten to the assignment statement created by the assignment statement creating means, and the arithmetic expression at the location detected by the arithmetic expression in the loop detecting means is replaced by the variable created by the variable creating means. When the outer arithmetic expression detecting means determines that the rewriting is possible, the outer arithmetic expression rewriting means for rewriting the arithmetic expression at the location detected by the outer arithmetic expression detecting means to the variable created by the variable creating means is provided. A program conversion device, comprising:
象のプログラムのループ処理内の制御変数を含む演算式
の演算結果の増分値を求め、その増分値だけ中身が増加
する新たな変数を作成し、新たな変数および増分値を被
演算子とする加算式を作成し、その加算式の演算結果が
新たな変数に代入される代入文を作成して、前記演算式
を新たな変数に書き換え、更にループ処理外の前記制御
変数を含む演算式を新たな変数に書き換えるプログラム
変換方法であって、 プログラム保持部に保持されているプログラムのループ
処理内から、制御変数が被演算子として使用され、他の
演算子に、定数あるいはループ処理内で不変な変数が使
用されている演算式を検出するループ内演算式検出ステ
ップと、 前記ループ内演算式検出ステップが検出した演算式が含
まれるループ処理の外部から、同一の演算式を検出し、
更に当該演算式において被演算子として使用されている
変数が、ループ処理からループ処理の外部の演算式まで
の領域内に定義されているか否かを判定して、定義され
ていないと判定すれば、検出した演算式は書き換え可能
であると判定し、定義されていると判定すれば、検出し
た演算式は書き換え不可能であると判定するループ外演
算式検出ステップと、 前記制御変数の、一回のループ処理における増分値に基
づいて、前記ループ内演算式検出ステップが検出した演
算式の、1回の演算の実行による演算結果の増分値を算
出する増分値算出ステップと、 前記プログラム保持部に保持されているプログラム中
で、使用されてない変数名の変数を作成する変数作成ス
テップと、 前記変数作成ステップが作成した変数と、前記増分値算
出ステップが算出した増分値とを加算し、加算した結果
を当該変数に代入する代入文を作成する代入文作成ステ
ップと、 プログラム中の制御変数の値を更新する代入文を、前記
代入文作成ステップが作成した代入文に書き換え、前記
ループ内演算式検出ステップが検出した箇所の演算式
を、前記変数作成ステップが作成した変数に書き換える
ループ内演算式書き換えステップと ループ外演算式検
出ステップが、書き換え可能であると判定した場合、前
記ループ外演算式検出ステップが検出した箇所の演算式
を、前記変数作成ステップが作成した変数に書き換える
ループ外演算式書き換えステップとからなることを特徴
とするプログラム変換方法。2. An incremental value of an operation result of an arithmetic expression including a control variable in a loop process of a program to be processed held in a program holding unit is calculated, and a new variable whose content increases by the increment value is created. Then, create an addition expression using the new variable and the increment value as operands, create an assignment statement in which the operation result of the addition expression is assigned to the new variable, and rewrite the operation expression with the new variable. A program conversion method for rewriting an arithmetic expression including the control variable outside the loop processing into a new variable, wherein the control variable is used as an operand from within the loop processing of the program held in the program holding unit. In the loop, an arithmetic expression detecting step for detecting an arithmetic expression in which a constant or an invariable variable is used in the loop processing is used as another operator. From the outside of the loop process including the arithmetic expression, to detect the same arithmetic expression,
Furthermore, if it is determined whether the variable used as the operand in the arithmetic expression is defined in the area from the loop processing to the arithmetic expression outside the loop processing, if it is determined that the variable is not defined If the detected arithmetic expression is determined to be rewritable, and if it is determined to be defined, the detected arithmetic expression is determined not to be rewritable, an out-of-loop arithmetic expression detection step; An increment value calculating step of calculating an increment value of an operation result of one execution of an arithmetic expression detected by the arithmetic expression detection step in the loop based on an increment value in the first loop processing; A variable creation step of creating a variable having a variable name that is not used in the program held in the program; a variable created by the variable creation step; and a step of calculating the increment value. An assignment statement creating step of creating an assignment statement for adding the increment value calculated by the above and assigning the added result to the variable, and an assignment statement for updating the value of the control variable in the program, Rewriting the created assignment statement and rewriting the arithmetic expression at the location detected by the in-loop arithmetic expression detection step to the variable created by the variable creating step, the in-loop arithmetic expression rewriting step and the out-of-loop arithmetic expression detecting step can be rewritten. A program conversion method for rewriting an arithmetic expression at a location detected by the out-of-loop arithmetic expression detection step to a variable created by the variable creating step. .
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP26505093A JP3236714B2 (en) | 1993-10-22 | 1993-10-22 | Program conversion device and program conversion method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP26505093A JP3236714B2 (en) | 1993-10-22 | 1993-10-22 | Program conversion device and program conversion method |
Publications (2)
Publication Number | Publication Date |
---|---|
JPH07121378A JPH07121378A (en) | 1995-05-12 |
JP3236714B2 true JP3236714B2 (en) | 2001-12-10 |
Family
ID=17411891
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP26505093A Expired - Lifetime JP3236714B2 (en) | 1993-10-22 | 1993-10-22 | Program conversion device and program conversion method |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP3236714B2 (en) |
-
1993
- 1993-10-22 JP JP26505093A patent/JP3236714B2/en not_active Expired - Lifetime
Non-Patent Citations (2)
Title |
---|
Wolfe,"Beyond Induction Variable",ACM SIGPLAN Notices,1992,Vol.27,No.7,p.162−174 |
インターフェース,CQ出版社,1989−3,第15巻第3号(no.142),p.202−203 |
Also Published As
Publication number | Publication date |
---|---|
JPH07121378A (en) | 1995-05-12 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP4640683B2 (en) | Program code conversion method | |
JP3377419B2 (en) | Instruction string generation method and apparatus, conversion method, and computer | |
US6078744A (en) | Method and apparatus for improving compiler performance during subsequent compilations of a source program | |
JP2678183B2 (en) | Digital processor controller and method for runtime memory allocation | |
US7386843B2 (en) | Method and system for register allocation | |
DK0938703T3 (en) | Accelerator for real-time programming language | |
JP2000347872A (en) | Method and device for processing exception as regular control flow | |
KR970002621A (en) | Optimizer | |
Harman | Verifying a simple pipelined microprocessor using Maude | |
JP2856663B2 (en) | Optimization method and apparatus for defining visible boundaries in compiled code | |
JP2817786B2 (en) | Simulation apparatus and simulation method | |
JP3236714B2 (en) | Program conversion device and program conversion method | |
JP3264901B2 (en) | Compiling device and compiling method | |
JP6740607B2 (en) | Simulation program, information processing device, simulation method | |
Koopman et al. | Operational machine specification in a functional programming language | |
JP3313859B2 (en) | Redundant remover | |
JPH02176938A (en) | Machine language instruction optimizing system | |
KR100246465B1 (en) | Apparatus and method for reducing cycle of microprocessor stack order | |
US20180189085A1 (en) | Method for executing a computer program with a parameterised function | |
JPH0666052B2 (en) | A computer that automatically maps memory contents to machine registers | |
JP2004139369A (en) | Analysis method for pointer pointing constant address domain | |
JP2875711B2 (en) | Program conversion device and processor | |
JP3123545B2 (en) | Data processing device | |
JPS6113615B2 (en) | ||
JPH06162067A (en) | Device and method for controlling vector instruction |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20080928 Year of fee payment: 7 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20080928 Year of fee payment: 7 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20090928 Year of fee payment: 8 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20090928 Year of fee payment: 8 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20100928 Year of fee payment: 9 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20110928 Year of fee payment: 10 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20120928 Year of fee payment: 11 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20130928 Year of fee payment: 12 |
|
EXPY | Cancellation because of completion of term |