JP3327634B2 - Program conversion device and program conversion method - Google Patents
Program conversion device and program conversion methodInfo
- Publication number
- JP3327634B2 JP3327634B2 JP18149393A JP18149393A JP3327634B2 JP 3327634 B2 JP3327634 B2 JP 3327634B2 JP 18149393 A JP18149393 A JP 18149393A JP 18149393 A JP18149393 A JP 18149393A JP 3327634 B2 JP3327634 B2 JP 3327634B2
- Authority
- JP
- Japan
- Prior art keywords
- variable
- induction
- value
- code
- conversion
- 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 device 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. It is.
【0002】[0002]
【従来の技術】コンパイラ等によってプログラムのソー
スコードを対象コードに変換する際などには、多くの場
合、対象コードのサイズの低減や実行速度の向上等を目
的として種々の最適化処理が行われ、そのうちのひとつ
として誘導変数の最適化が行われることもある。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.
【0003】上記誘導変数は、例えば「コンパイラII」
(A.Vエイホ R.セシィ J.D.ウルマン共著、原田賢一
訳:サイエンス社)に記載されているように、ループ処
理において、1回のループが繰り返されるごとに値が正
又は負の一定量ずつ増加する変数のことで、その最適化
とは、例えばソースコードにおいてループ処理の制御変
数に所定の数を乗算して値を得る誘導変数が用いられて
いる場合、前回のループ処理における誘導変数の値に上
記所定の数を加算して新たな値を得るコードを生成する
ことなどにより、処理速度の向上やコードサイズの低減
を図ることである。The above-mentioned induction variable is, for example, “Compiler II”
As described in (AV Eiho R. Cessy JD Ullman, Translated by Kenichi Harada: Science), in loop processing, a variable whose value increases by a certain amount of positive or negative each time one loop is repeated The optimization means that, for example, when an induction variable that obtains a value by multiplying a control variable of a loop process by a predetermined number is used in the source code, the value of the induction variable in the previous loop processing is The purpose is to improve the processing speed and reduce the code size by, for example, generating a code that adds a predetermined number to obtain a new value.
【0004】より具体的には、例えば図4(a)に示す
コードにおいては、ラベルLからif文までの間のルー
プ処理における変数a、bは1ループ処理ごとに値が2
または6ずつ増加する誘導変数であるので、図4(b)
に示すようなコードに変換することにより、2つの乗算
を2つの処理時間の短い加算に置き換えることができ
る。More specifically, for example, in the code shown in FIG. 4A, the variables a and b in the loop processing from the label L to the if statement have a value of 2 for each loop processing.
4 or (b)
, The two multiplications can be replaced with two short additions of processing time.
【0005】また、同様に図5(a)に示すコードにお
いては、誘導変数c、d、eに関して図5(b)に示す
ようなコードに変換することにより、やはり乗算の数を
減少させることができる。なお、コンパイラ等における
上記のような誘導変数の最適化は、詳しくは、例えば以
下のようにして行われる。Similarly, in the code shown in FIG. 5A, the number of multiplications can be reduced by converting the induction variables c, d, and e into codes as shown in FIG. 5B. Can be. The above-described optimization of the induced variable in the compiler or the like is performed in detail, for example, as follows.
【0006】まず、ソースコードの構文解析等におい
て、誘導変数を検出するとともに、その誘導変数のルー
プごとの変化量を得る。次に、誘導変数を上記変化量
(正又は負の値)だけ増加させてループごとの誘導変数
の値を求めるコード、および誘導変数の初期値をセット
するコード等を生成し、ソースコードを変換する。First, in a syntax analysis of a source code, an induced variable is detected, and a change amount of the induced variable for each loop is obtained. Next, a code for obtaining the value of the induction variable for each loop by increasing the induction variable by the amount of change (positive or negative value) and a code for setting the initial value of the induction variable are generated, and the source code is converted. I do.
【0007】ここで、従来のコンパイラ等においては、
全ての誘導変数について、上記のような変換を行うよう
になっていた。Here, in a conventional compiler or the like,
The above conversion was performed for all the induced variables.
【0008】[0008]
【発明が解決しようとする課題】しかしながら、上記従
来のコンパイラ等では、無駄な誘導変数の値を求めるコ
ードが生成されたり、かえって処理速度の低下を招くよ
うなコードが生成されたりすることがあるという問題点
を有していた。すなわち、図4の例では、誘導変数a、
b共について上記のような変換を行った結果、どこでも
使用されない(厳密には、その誘導変数自身の新たな値
を求めるため以外には使用されない)値を求める式a=
a+2が生成されてしまう。このような誘導変数aに関
する式a=0やa=a+2は不要であり、処理速度の低
下やコードサイズの増大を招くことになる。However, the above-mentioned conventional compiler or the like may generate a code for obtaining a useless value of an induced variable, or may generate a code for lowering the processing speed. There was a problem that. That is, in the example of FIG.
As a result of performing the above-described conversion on b and b, an expression a = for calculating a value that is not used anywhere (strictly, not used except for obtaining a new value of the induced variable itself)
a + 2 is generated. The expressions a = 0 and a = a + 2 relating to such an induction variable a are unnecessary, resulting in a reduction in processing speed and an increase in code size.
【0009】また、上記のような最適化が行われた誘導
変数は、プロセッサのレジスタに割り付けられる優先順
位が高い、いわゆるループ処理の中で生きる変数とな
る。それゆえ、図5の例のように常に全ての誘導変数に
ついて加算への変換を行うと、例えば誘導変数の数がプ
ロセッサのレジスタ数を超える可能性が高くなり、その
場合、レジスタの退避および復元のためのコードが増加
し、かえってコードサイズの増大や処理速度の低下を招
くことになりがちである。Further, the induced variables that have been optimized as described above are variables that have a high priority assigned to the registers of the processor and that live in a so-called loop process. Therefore, if the conversion to addition is always performed for all the induced variables as in the example of FIG. 5, for example, there is a high possibility that the number of induced variables exceeds the number of registers of the processor. Therefore, the number of codes increases, which tends to increase the code size and decrease the processing speed.
【0010】本発明は上記の点に鑑み、無駄な誘導変数
の値を求めるコードの生成を抑制したり、ループ処理の
中で生きる変数の数を低減したりして、処理速度の向上
やコードサイズの低減を図り得るプログラム変換方法、
およびその装置の提供を目的としている。SUMMARY OF THE INVENTION In view of the above, the present invention suppresses generation of a code for obtaining a value of a useless induced variable, reduces the number of variables that live in a loop process, and improves the processing speed and the code. A program conversion method that can reduce the size,
And its equipment.
【0011】[0011]
【課題を解決するための手段】上記目的を達成するた
め、本発明は、プログラムコードのループ処理中で用い
られる誘導変数を検出する検出手段と、検出された誘導
変数を示す情報を保持する保持手段と、プログラムコー
ドにおける、検出された誘導変数の値を定義するコード
を、ループ処理が行われるごとに誘導変数に所定の値を
加算することにより新たな誘導変数の値を定義するコー
ドに変換する変換手段と、検出手段で検出された誘導変
数が、1つの誘導変数の値を定義するためにのみ用いら
れる誘導変数である場合に、プログラムコードから上記
1つの誘導変数の値を定義するためにのみ用いられる誘
導変数の値を定義するコードを削除する削除手段とを有
することを特徴としている。To achieve the above object, the present invention provides a detecting means for detecting an induced variable used in a loop processing of a program code, and a holding means for holding information indicating the detected induced variable. Means and a code for defining a value of a detected induction variable in a program code are converted into a code for defining a value of a new induction variable by adding a predetermined value to the induction variable every time a loop process is performed. And converting the induced variable detected by the detecting means to the value of the one induced variable from the program code when the induced variable is only used to define the value of the one induced variable. And a deleting means for deleting a code defining the value of the induction variable used only for
【0012】また、プログラムコードのループ処理中で
用いられる誘導変数を検出する検出手段と、検出された
誘導変数を示す情報を保持する保持手段と、プログラム
コードにおける、検出された誘導変数の値を定義するコ
ードを、ループ処理が行われるごとに誘導変数に所定の
値を加算することにより新たな誘導変数の値を定義する
コードに変換する変換手段と、検出手段で検出された複
数の誘導変数が、同一の他の誘導変数を用いて値を定義
される誘導変数である場合に、上記複数の誘導変数につ
いて、変換手段によるコードの変換を抑制する変換抑制
手段とを有することを特徴としている。Further, detecting means for detecting an induced variable used in the loop processing of the program code, holding means for holding information indicating the detected induced variable, and detecting the value of the detected induced variable in the program code. A conversion unit that converts a code to be defined into a code that defines a value of a new induction variable by adding a predetermined value to the induction variable every time a loop process is performed, and a plurality of induction variables detected by the detection unit. Is a derived variable whose value is defined using the same other induced variable, characterized in that it has a conversion suppressing unit that suppresses code conversion by the converting unit for the plurality of induced variables. .
【0013】また、プログラムコードのループ処理中で
用いられる誘導変数を検出する検出ステップと、プログ
ラムコードにおける、検出された誘導変数の値を定義す
るコードを、ループ処理が行われるごとに誘導変数に所
定の値を加算することにより新たな誘導変数の値を定義
するコードに変換する変換ステップと、検出ステップで
検出された誘導変数が、1つの誘導変数の値を定義する
ためにのみ用いられる誘導変数である場合に、プログラ
ムコードから上記1つの誘導変数の値を定義するために
のみ用いられる誘導変数の値を定義するコードを削除す
る削除ステップとを有することを特徴としている。[0013] Further, a detecting step of detecting an induced variable used in the loop processing of the program code, and changing a code defining the value of the detected induced variable in the program code into an induced variable every time the loop processing is performed. A conversion step of adding a predetermined value to convert the code into a code that defines a new induction variable value, and an induction step in which the induction variable detected in the detection step is used only to define the value of one induction variable. If the variable is a variable, a step of deleting a code defining the value of the induced variable used only to define the value of the one induced variable from the program code is provided.
【0014】また、プログラムコードのループ処理中で
用いられる誘導変数を検出する検出ステップと、プログ
ラムコードにおける、検出された誘導変数の値を定義す
るコードを、ループ処理が行われるごとに誘導変数に所
定の値を加算することにより新たな誘導変数の値を定義
するコードに変換する変換ステップと、検出ステップで
検出された複数の誘導変数が、同一の他の誘導変数を用
いて値を定義される誘導変数である場合に、上記複数の
誘導変数について、変換ステップの実行を抑制する変換
抑制ステップとを有することを特徴としている。A detecting step for detecting an induced variable used in the loop processing of the program code, and a code for defining a value of the detected induced variable in the program code is changed to an induced variable every time the loop processing is performed. A conversion step of converting to a code that defines a value of a new induction variable by adding a predetermined value; and a plurality of induction variables detected in the detection step, the value of which is defined using the same other induction variable. A conversion suppression step of suppressing execution of the conversion step for the plurality of induction variables.
【0015】[0015]
【作用】上記の構成により、検出手段は、プログラムコ
ードのループ処理中で用いられる誘導変数を検出し、保
持手段は、検出された誘導変数を示す情報を保持し、変
換手段は、プログラムコードにおける、検出された誘導
変数の値を定義するコードを、ループ処理が行われるご
とに誘導変数に所定の値を加算することにより新たな誘
導変数の値を定義するコードに変換する。With the above arrangement, the detecting means detects the induced variable used in the loop processing of the program code, the holding means holds information indicating the detected induced variable, and the converting means operates the program code in the program code. The code that defines the value of the detected induction variable is converted to a code that defines a new value of the induction variable by adding a predetermined value to the induction variable every time the loop processing is performed.
【0016】さらに、削除手段が、検出手段で検出され
た誘導変数が、1つの誘導変数の値を定義するためにの
み用いられる誘導変数である場合に、プログラムコード
から上記1つの誘導変数の値を定義するためにのみ用い
られる誘導変数の値を定義するコードを削除する。また
は、変換抑制手段が、検出手段で検出された複数の誘導
変数が、同一の他の誘導変数を用いて値を定義される誘
導変数である場合に、上記複数の誘導変数について、変
換手段によるコードの変換を抑制する。[0016] Further, when the induction variable detected by the detection means is an induction variable used only for defining the value of the one induction variable, the deletion means determines the value of the one induction variable from the program code. Remove the code that defines the value of the induction variable that is used only to define Or, when the plurality of induction variables detected by the detection means are induction variables whose values are defined by using the same other induction variables, the conversion suppression means, for the plurality of induction variables, Suppress code conversion.
【0017】また、検出ステップでは、プログラムコー
ドのループ処理中で用いられる誘導変数が検出され、変
換ステップでは、プログラムコードにおける、検出され
た誘導変数の値を定義するコードが、ループ処理が行わ
れるごとに誘導変数に所定の値を加算することにより新
たな誘導変数の値を定義するコードに変換される。さら
に、削除ステップにより、検出ステップで検出された誘
導変数が、1つの誘導変数の値を定義するためにのみ用
いられる誘導変数である場合に、プログラムコードから
上記1つの誘導変数の値を定義するためにのみ用いられ
る誘導変数の値を定義するコードが削除される。In the detecting step, an induced variable used in the loop processing of the program code is detected, and in the converting step, a code defining the value of the detected induced variable in the program code is loop-processed. By adding a predetermined value to the induction variable every time, it is converted into a code defining a new induction variable value. Further, when the induced variable detected in the detecting step is the induced variable used only for defining the value of the one induced variable, the value of the one induced variable is defined from the program code. The code that defines the value of the induction variable, which is used only for that purpose, is removed.
【0018】または、変換抑制ステップにより、検出ス
テップで検出された複数の誘導変数が、同一の他の誘導
変数を用いて値を定義される誘導変数である場合に、上
記複数の誘導変数について、変換ステップの実行が抑制
される。Alternatively, when the plurality of induction variables detected in the detection step by the conversion suppression step are induction variables whose values are defined by using the same other induction variables, Execution of the conversion step is suppressed.
【0019】[0019]
【実施例】以下、本発明の一実施例を図1ないし図3に
基づいて説明する。図1はプログラム変換装置の構成を
示すブロック図である。このプログラム変換装置による
誘導変数の最適化は、例えばコンパイラに与えられるソ
ースコードに対して行われるようにしてもよいし、ま
た、コンパイラによるコンパイル処理の途中で得られる
中間コードなどに対して行われるようにしてもよい。DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS One embodiment of the present invention will be described below with reference to FIGS. FIG. 1 is a block diagram showing the configuration of the 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.
【0020】図1において、最適化前コード記憶手段1
1は、上記ソースコードや中間コード等の最適化前コー
ドを記憶するものである。誘導変数検出手段12は、最
適化前コード記憶手段11に記憶されている最適化前コ
ードに含まれる誘導変数を検出し、検出された誘導変数
に関する情報を後述する誘導変数保持手段13に登録す
るものである。詳しくは、例えば最適化前コードにおけ
るループ処理中で誘導変数の値を定義する誘導変数定義
文を検出し、誘導変数の変数名、1ループ処理ごとの増
分値、および初期値を誘導変数保持手段13に保持させ
る。ここで増分値は、正の値でも負の値でもよい。な
お、上記誘導変数の検出については、従来のプログラム
変換装置と同様の構成が適用できるので、詳細な説明は
省略する。In FIG. 1, code storage means 1 before optimization
Numeral 1 stores a code before optimization such as the above-mentioned source code and intermediate code. The induction variable detection unit 12 detects an induction variable included in the pre-optimization code stored in the pre-optimization code storage unit 11 and registers information on the detected induction variable in an induction variable holding unit 13 described later. Things. More specifically, for example, an induction variable definition statement that defines the value of an induction variable during loop processing in a code before optimization is detected, and a variable name of the induction variable, an increment value for each loop processing, and an initial value are stored as induction variable holding means. 13 is held. Here, the increment value may be a positive value or a negative value. Since the same configuration as that of the conventional program conversion device can be applied to detection of the above-mentioned induction variables, detailed description will be omitted.
【0021】誘導変数保持手段13は、上記誘導変数検
出手段12によって検出された誘導変数の変数名、1ル
ープ処理ごとの増分値、および初期値を保持する。誘導
変数最適化制御手段14は、定義文削除手段14aと、
変換抑制手段14bとを備えて構成されている。定義文
削除手段14aは、誘導変数保持手段13に登録された
各誘導変数について、最適化前コードにおける、誘導変
数(被使用誘導変数)の値が使用される使用文を検出
し、検出された使用文が1つだけであり、かつ、その使
用文で値を定義される変数が誘導変数保持手段13に登
録されている場合、つまり被使用誘導変数を使用して定
義される変数も誘導変数である場合に、被使用誘導変数
の値を定義する定義文を最適化前コードから削除する。
すなわち、上記被使用誘導変数の使用文は後述するコー
ド変換処理によって被使用誘導変数を使用しない文に変
換されるので、被使用誘導変数の定義文は不要なものと
なり、したがってこれを削除することにより、コードサ
イズを低減するとともに処理速度を向上させることがで
きる。定義文削除手段14aは、また、上記被使用誘導
変数についてはコード変換処理を行う必要がないので、
この被使用誘導変数についての登録を誘導変数保持手段
13から削除する。The induced variable holding means 13 holds the variable name of the induced variable detected by the induced variable detecting means 12, the increment value for each loop processing, and the initial value. The induction variable optimization control unit 14 includes a definition sentence deleting unit 14a,
And a conversion suppressing means 14b. The definition sentence deleting unit 14a detects, for each of the induction variables registered in the induction variable holding unit 13, a usage sentence in which the value of the induction variable (used induction variable) is used in the code before optimization. When there is only one usage statement and the variable whose value is defined in the usage statement is registered in the induction variable holding means 13, that is, the variable defined using the used induction variable is also an induction variable. If, the definition statement that defines the value of the used induction variable is deleted from the pre-optimization code.
In other words, since the used sentence of the used induced variable is converted into a statement that does not use the used induced variable by the code conversion process described later, the definition sentence of the used induced variable becomes unnecessary, and therefore, should be deleted. Thus, the code size can be reduced and the processing speed can be improved. Since the definition sentence deleting means 14a does not need to perform the code conversion process on the used induced variables,
The registration of the used induction variable is deleted from the induction variable holding unit 13.
【0022】一方、変換抑制手段14bは、定義文削除
手段14aと同様に被使用誘導変数の値が使用される使
用文を検出した後、検出された使用文が複数あり、か
つ、各使用文で値を定義される変数が全て誘導変数保持
手段13に登録されている場合、つまりそれらの変数も
誘導変数である場合に、それらの複数の誘導変数につい
ての登録を誘導変数保持手段13から削除する。すなわ
ち、削除された誘導変数については後述するコード変換
処理が行われないので、プロセッサのレジスタに割り付
けられる優先順位が高い、いわゆるループ処理の中で生
きる誘導変数の数が少なく抑えられる。なお、上記各使
用文で値を定義される変数が全て誘導変数保持手段13
に登録されている場合に限らず、少なくとも複数の変数
が登録されている場合などに、誘導変数保持手段13か
ら削除するようにしてもよい。On the other hand, the conversion suppression means 14b detects a usage statement in which the value of the used induction variable is used, similarly to the definition statement deletion means 14a, and then detects a plurality of usage statements. In the case where all the variables whose values are defined in are registered in the induced variable holding means 13, that is, when those variables are also induced variables, the registration of the plurality of induced variables is deleted from the induced variable holding means 13. I do. In other words, since the code conversion process described later is not performed on the deleted induction variable, the number of induction variables that have a high priority assigned to the register of the processor and live in a so-called loop process can be reduced. Note that all variables whose values are defined in the above usage statements are all derived variable holding means 13.
Not only in the case where a plurality of variables are registered, but also in a case where at least a plurality of variables are registered, the information may be deleted from the induced variable holding unit 13.
【0023】コード変換手段15は、上記誘導変数最適
化制御手段14の処理が完了した後、誘導変数保持手段
13に登録されている誘導変数の変数名、1ループ処理
ごとの増分値、および初期値に基づいて、最適化前コー
ド記憶手段11に記憶されている最適化前コードにおけ
る上記誘導変数の値を定義する定義文を、元の誘導変数
の値に上記増分値を加算して新たな誘導変数の値を定義
する定義文に変換するとともに、誘導変数の初期値をセ
ットするコードを生成する。After the process of the induction variable optimization control unit 14 is completed, the code conversion unit 15 sets the variable name of the induction variable registered in the induction variable holding unit 13, the increment value for each loop processing, and the initial value. Based on the value, a definition statement defining the value of the induction variable in the pre-optimization code stored in the pre-optimization code storage means 11 is added to the original induction variable value by adding the increment value to a new value. Generates a code that converts the value of the induction variable into a definition statement that defines the value, and sets the initial value of the induction variable.
【0024】最適化後コード記憶手段16は、コード変
換手段15によって得られたコードを記憶する。上記の
構成において、プログラム変換装置の動作を、図2
(a)および図3(a)に示すコードに対して誘導変数
の最適化が行われる場合を例に挙げて説明する。なお、
以下の説明においては、簡単のためにループ処理の制御
変数i、jに関する説明は省略する。 (例1)図2(a)に示すようなコードが最適化前コー
ド記憶手段11に記憶されている場合、誘導変数検出手
段12は、ラベルLからif文までの間のループ処理中
で値を定義され、1ループ処理ごとに値が2または6ず
つ増加する変数a、bを誘導変数として検出し、変数名
「a、b」、1ループ処理ごとの増分値「2、6」、お
よび初期値「0、0」を誘導変数保持手段13に登録す
る。The optimized code storage means 16 stores the code obtained by the code conversion means 15. In the above configuration, the operation of the program conversion device is described in FIG.
A description will be given of an example in which induction variables are optimized for the codes shown in FIG. 3A and FIG. 3A. In addition,
In the following description, the description regarding the control variables i and j of the loop processing will be omitted for simplicity. (Example 1) When a code as shown in FIG. 2A is stored in the pre-optimization code storage unit 11, the induction variable detection unit 12 sets the value during the loop processing from the label L to the if statement. Are defined as variables, a and b whose values increase by 2 or 6 for each loop processing are detected as induction variables, and variable names “a, b”, increment values for each loop processing “2, 6”, and The initial value “0, 0” is registered in the induced variable holding unit 13.
【0025】定義文削除手段14aは、誘導変数aの値
が使用される使用文がb=a*3だけであり、さらに、
この使用文で値を定義される変数bも誘導変数保持手段
13に登録されていることを検出し、図2(b)に示す
ように、誘導変数aの値を定義する定義文a=2*iを
最適化前コード記憶手段11に記憶されている最適化前
コードから削除する。また、誘導変数保持手段13から
誘導変数aについての登録を削除する。The definition sentence deleting means 14a determines that the use sentence in which the value of the induction variable a is used is only b = a * 3,
It is detected that the variable “b” whose value is defined by this usage statement is also registered in the induced variable holding means 13, and as shown in FIG. * I is deleted from the pre-optimization code stored in the pre-optimization code storage means 11. Further, the registration of the induction variable a is deleted from the induction variable holding unit 13.
【0026】コード変換手段15は、誘導変数保持手段
13に登録されている変数名「b」、1ループ処理ごと
の増分値「6」、および初期値「0」に基づいて、図2
(c)に示すように、誘導変数bの値の定義文b=a*
3をb=b+6に変換するとともに、誘導変数bの初期
値をセットする文b=0を追加したコードを生成し、最
適化後コード記憶手段16に記憶させる。ここで、上記
誘導変数bの値の定義文b=b+6はラベルLからif
文までの間のループ処理の後部(bの値を使用する関数
f(b)よりも後)に配置され、初期値をセットする文
b=0はラベルLよりも前に配置される。なお、このよ
うなコードの変換に限らず、例えば誘導変数の初期値を
−6とし、誘導変数bの値の定義文をループ処理の前部
に配置するなど、アルゴリズムの等価な変換であればよ
い。The code conversion unit 15 performs the processing shown in FIG. 2 based on the variable name “b” registered in the induction variable holding unit 13, the increment value “6” for each loop processing, and the initial value “0”.
As shown in (c), the definition sentence b = a * of the value of the induction variable b
3 is converted to b = b + 6, and a code to which a sentence b = 0 for setting the initial value of the induction variable b is generated, and stored in the code storage unit 16 after optimization. Here, the definition sentence b = b + 6 of the value of the induction variable b is obtained from the label L
The statement b = 0, which is placed at the end of the loop processing up to the statement (after the function f (b) using the value of b) and sets the initial value, is placed before the label L. The conversion is not limited to such code conversion. For example, if the conversion of the algorithm is equivalent, for example, the initial value of the induction variable is set to -6, and the definition statement of the value of the induction variable b is arranged at the front of the loop processing. Good.
【0027】このようにして得られた最適化後コード
は、ループ処理の制御変数iを除く誘導変数の定義文を
1つだけ含み、しかもその誘導変数は加算によって値が
求められるので、コードサイズが小さく抑えられるとと
もに、処理速度が向上される。 (例2)図3(a)に示すようなコードが最適化前コー
ド記憶手段11に記憶されている場合、誘導変数検出手
段12は、例1の場合と同様に、ラベルLからif文ま
での間のループ処理中で値を定義され、1ループ処理ご
とに値が2、6、または8ずつ増加する変数c、d、e
を誘導変数として検出し、変数名「c、d、e」、1ル
ープ処理ごとの増分値「2、6、8」、および初期値
「0、0、0」を誘導変数保持手段13に登録する。The post-optimization code thus obtained includes only one definition variable of the induction variable except the control variable i of the loop processing, and the value of the induction variable is obtained by addition. And the processing speed is improved. (Example 2) When a code as shown in FIG. 3 (a) is stored in the pre-optimization code storage means 11, the induction variable detection means 12 performs the processing from the label L to the if sentence as in the case of Example 1. Variables c, d, and e whose values increase by 2, 6, or 8 for each loop processing
Are registered as the induction variables, and the variable name “c, d, e”, the increment value “2, 6, 8” for each loop processing, and the initial value “0, 0, 0” are registered in the induction variable holding unit 13. I do.
【0028】変換抑制手段14bは、誘導変数cの値が
使用される使用文がd=c*3、およびe=c*4の2
つあり、さらに、これらの使用文で値を定義される変数
d、eも共に誘導変数保持手段13に登録されているこ
とを検出し、誘導変数保持手段13から誘導変数d、e
についての登録を削除する。そこで、コード変換手段1
5は、誘導変数保持手段13に削除されずに登録されて
いる変数名「c」、1ループ処理ごとの増分値「2」、
および初期値「0」に基づいて、図3(b)に示すよう
に、誘導変数cの値の定義文c=2*jをc=c+2に
変換するとともに、誘導変数cの初期値をセットする文
c=0を追加する一方、誘導変数d、eに関してはその
ままで、最適化後コード記憶手段16に記憶させる。The conversion suppressing means 14b determines that the usage statement in which the value of the induction variable c is used is d = c * 3 and e = c * 4.
Further, it is detected that the variables d and e, the values of which are defined in these usage statements, are both registered in the induced variable holding means 13, and the induced variables d and e are read from the induced variable holding means 13.
Remove registration for. Therefore, code conversion means 1
5 is a variable name “c” registered without being deleted in the induction variable holding means 13, an increment value “2” for each loop processing,
As shown in FIG. 3B, the definition sentence c = 2 * j of the value of the induction variable c is converted into c = c + 2 based on the initial value “0” and the initial value of the induction variable c is set. While the sentence c = 0 is added, the induced variables d and e are stored as they are in the post-optimization code storage unit 16.
【0029】このようにして得られた最適化後コード
は、ループ処理の制御変数jを除けば、加算によって値
が求められる誘導変数の定義文を1つだけ含むので、い
わゆるループ処理の中で生きる変数の数が1つに抑えら
れ、プロセッサのレジスタに確実に割り付けられる可能
性が高くなり、コードサイズが小さく抑えられるととも
に、処理速度が向上される。The post-optimization code thus obtained, except for the control variable j of the loop processing, contains only one definition statement of the induction variable whose value is obtained by addition. The number of living variables is reduced to one, the possibility of being reliably allocated to the register of the processor is increased, the code size is reduced, and the processing speed is improved.
【0030】なお、上記の例では、定義文削除手段14
aは、被使用誘導変数の値を定義する定義文を最適化前
コード記憶手段11に記憶されている最適化前コードか
ら削除する例を示したが、これに限らずコード変換手段
15による変換が行われる際、または変換後のコードが
最適化後コード記憶手段16に記憶された後に削除する
ようにしてもよい。In the above example, the definition statement deleting means 14
FIG. 4A shows an example in which the definition statement defining the value of the used induction variable is deleted from the pre-optimization code stored in the pre-optimization code storage unit 11. May be deleted, or after the converted code is stored in the post-optimization code storage unit 16.
【0031】また、定義文削除手段14aは、最適化前
コードにおける、誘導変数(被使用誘導変数)の値が使
用される使用文を検出する例を示したが、これに限ら
ず、例えばコード変換手段15による変換が行われた後
のコードに対して使用文の検出をするようにしてもよ
い。この場合には、検出された使用文がその被使用誘導
変数自身の新たな値を定義する文だけである場合に、そ
の文を削除するようにすればよい。Further, the definition sentence deleting means 14a has been described as an example in which the use sentence in which the value of the induction variable (used induction variable) is used in the pre-optimization code is described. The usage sentence may be detected for the code after the conversion by the conversion means 15. In this case, if the detected sentence is only a sentence that defines a new value of the used induced variable itself, the sentence may be deleted.
【0032】また、プログラム変換装置の動作の説明で
は、定義文削除手段14a、または変換抑制手段14b
の何れか一方だけによって誘導変数の登録の削除等が行
われるような最適化前コードの例を示したが、一方の処
理対象となった後に、さらに他方の処理対象となるよう
なコードの場合には、一層最適化されたコードが生成さ
れることになる。In the description of the operation of the program conversion device, the definition sentence deletion means 14a or the conversion suppression means 14b
An example of the pre-optimization code in which the registration of the induction variable is deleted by only one of the above is shown, but in the case of a code that becomes one processing target and then becomes the other processing target Will result in a more optimized code being generated.
【0033】[0033]
【発明の効果】以上説明したように、本発明によれば、
誘導変数が、1つの誘導変数の値を定義するためにのみ
用いられる誘導変数である場合に、プログラムコードか
ら、上記1つの誘導変数の値を定義するためにのみ用い
られる誘導変数の値を定義するコードが削除され、また
は、複数の誘導変数が、同一の他の誘導変数を用いて値
を定義される誘導変数である場合に、上記複数の誘導変
数について、コードの変換が抑制されるので、無駄な誘
導変数の値を求めるコードの生成が抑制され、または、
ループ処理の中で生きる変数の数が低減され、したがっ
て、処理速度の向上やコードサイズの低減が図られると
いう効果を奏する。As described above, according to the present invention,
If the induction variable is an induction variable used only to define the value of one induction variable, the program code defines the value of the induction variable used only to define the value of the one induction variable. If the code to be executed is deleted, or if the plurality of induction variables are induction variables whose values are defined using the same other induction variables, the code conversion is suppressed for the plurality of induction variables. , Suppresses the generation of code that calculates the value of useless induction variables, or
The number of variables alive in the loop processing is reduced, so that the processing speed is improved and the code size is reduced.
【図1】本発明の一実施例におけるプログラム変換装置
の構成を示すブロック図である。FIG. 1 is a block diagram illustrating a configuration of a program conversion device according to an embodiment of the present invention.
【図2】本発明のプログラム変換装置による変換前後の
プログラムコードの例を示す説明図である。FIG. 2 is an explanatory diagram showing examples of program codes before and after conversion by a program conversion device of the present invention.
【図3】本発明のプログラム変換装置による変換前後の
プログラムコードの他の例を示す説明図である。FIG. 3 is an explanatory diagram showing another example of a program code before and after conversion by the program conversion device of the present invention.
【図4】従来のプログラム変換装置による変換前後のプ
ログラムコードの例を示す説明図である。FIG. 4 is an explanatory diagram showing examples of program codes before and after conversion by a conventional program conversion device.
【図5】従来のプログラム変換装置による変換前後のプ
ログラムコードの他の例を示す説明図である。FIG. 5 is an explanatory diagram showing another example of a program code before and after conversion by a conventional program conversion device.
11 最適化前コード記憶手段 12 誘導変数検出手段 13 誘導変数保持手段 14 誘導変数最適化制御手段 14a 定義文削除手段 14b 変換抑制手段 15 コード変換手段 16 最適化後コード記憶手段 11 Code storage unit before optimization 12 Induction variable detection unit 13 Induction variable holding unit 14 Induction variable optimization control unit 14a Definition sentence deletion unit 14b Conversion suppression unit 15 Code conversion unit 16 Code storage unit after optimization
───────────────────────────────────────────────────── フロントページの続き (56)参考文献 中田育男,コンパイラ,産業図書株式 会社,昭和56年,p.221−237 (58)調査した分野(Int.Cl.7,DB名) G06F 9/45 ────────────────────────────────────────────────── ─── Continuation of the front page (56) References Ikuo Nakata, Compiler, Sangyo Tosho Co., Ltd., 1981, p. 221-237 (58) Fields surveyed (Int. Cl. 7 , DB name) G06F 9/45
Claims (6)
られる誘導変数を検出し、その誘導変数を示す情報、そ
の誘導変数の初期値、1ループ処理毎の増分値を出力す
る第1の検出手段と、検出手段の出力 を保持する保持手段と、 プログラムコードにおける、保持手段に保持された情報
が示す誘導変数の値を定義するコードを、ループ処理に
先立って前記初期値をセットするコードと、ループ処理
中において前記増分値を誘導変数の値に加算することに
より新たな誘導変数の値とするコードとに変換する変換
手段と、第1の 検出手段で検出された誘導変数の中で、1つの誘
導変数の値を定義するためにのみ用いられる誘導変数を
検出する第2の検出手段と、 第2の検出手段により検出された 誘導変数の値を定義す
るコードをプログラムコードから削除する削除手段とを
有することを特徴とするプログラム変換装置。 An information processing apparatus detects an induction variable used in a loop processing of a program code, and indicates information indicating the induction variable.
First detecting means for outputting the initial value of the induced variable for each loop, increment value for each loop processing, holding means for holding the output of the detecting means, and holding means for holding the output of the program code . information
The code that defines the value of the induction variable indicated by
Code for setting the initial value in advance, and loop processing
The increment value converting means for converting the code for the value of the new induction variables by adding the value of induction variables, among the detected induction variables in the first detecting means in the middle, the induction of one An induction variable that is used only to define the value of the variable
A program conversion device , comprising: a second detecting means for detecting; and a deleting means for deleting, from a program code, a code defining a value of an induced variable detected by the second detecting means .
られる誘導変数を検出する検出手段と、 検出された誘導変数を示す情報を保持する保持手段と、 プログラムコードにおける、検出された誘導変数の値を
定義するコードを、ループ処理が行われるごとに誘導変
数に所定の値を加算することにより新たな誘導変数の値
を定義するコードに変換する変換手段と、 検出手段で検出された複数の誘導変数が、同一の他の誘
導変数を用いて値を定義される誘導変数である場合に、
上記複数の誘導変数について、変換手段によるコードの
変換を抑制する変換抑制手段とを有し、 上記変換抑制手段は、検出手段で検出された複数の誘導
変数が、同一の他の誘導変数を用いて値を定義される誘
導変数である場合に、上記複数の誘導変数を示す情報を
保持手段から削除するように構成されていることを特徴
とするプ ログラム変換装置。2. A detecting means for detecting an induced variable used in a loop processing of a program code, a holding means for holding information indicating the detected induced variable, and a detecting means for detecting a value of the detected induced variable in the program code. A conversion means for converting a code to be defined into a code for defining a value of a new induction variable by adding a predetermined value to the induction variable every time loop processing is performed; and a plurality of induction variables detected by the detection means. Is an induction variable whose value is defined using the same other induction variable,
For the plurality of induction variables, possess the inhibiting transduction inhibitor means the conversion of the code by converting means, said converting suppression means, a plurality of induction detected by the detection means
The variable is defined to be valued using the same other induction variable
In the case of a derived variable, the information indicating the plurality of induced variables is
Characterized in that it is configured to be deleted from the holding means
Program conversion apparatus according to.
段、変換手段、および削除手段と、請求項2の変換抑制
手段とを有することを特徴とするプログラム変換装置。3. A program conversion apparatus comprising: the first and second detection means, the holding means, the conversion means, and the deletion means according to claim 1; and the conversion suppression means according to claim 2.
られる誘導変数を検出し、その誘導変数を示す情報、誘
導変数の初期値、1ループ処理毎の増分値を出力する第
1のする検出ステップと、 プログラムコードにおける、第1の検出手段により検出
された誘導変数の値を定義するコードを、ループ処理に
先立って前記初期値をセットするコードと、ループ処理
中において前記増分値を誘導変数の値に加算することに
より新たな誘導変数の値を定義するコードに変換する変
換ステップと、第1の 検出手段で検出された誘導変数の中で、1つの誘
導変数の値を定義するためにのみ用いられる誘導変数を
検出する第2の検出ステップと、 第2の検出手段により検出された 誘導変数の値を定義す
るコードをプログラムコードから削除する削除ステップ
とを有することを特徴とするプログラム変換方法。4. An induction variable used in a loop process of a program code is detected, and information indicating the induction variable and an induction variable are detected.
Outputs the initial value of the derived variable and the increment value for each loop processing .
A detection step of the 1, in the program code, a code that defines the value of the detected induction variable by the first detecting means, a loop
Code for setting the initial value in advance, and loop processing
The increment value a conversion step of converting the code that defines the value of the new induction variables by adding the value of induction variables, among the detected induction variables in the first detecting means in the middle, the induction of one An induction variable that is used only to define the value of the variable
A program conversion method comprising: a second detecting step of detecting; and a deleting step of deleting, from the program code, a code defining a value of an induced variable detected by the second detecting means .
られる誘導変数を検出する検出ステップと、 プログラムコードにおける、検出された誘導変数の値を
定義するコードを、ループ処理が行われるごとに誘導変
数に所定の値を加算することにより新たな誘導変数の値
を定義するコードに変換する変換ステップと、 検出ステップで検出された複数の誘導変数が、同一の他
の誘導変数を用いて値を定義される誘導変数である場合
に、上記複数の誘導変数について、変換ステップの実行
を抑制する変換抑制ステップとを有し、 上記変換抑制ステップは、検出ステップで検出された複
数の誘導変数が、同一の他の誘導変数を用いて値を定義
される誘導変数である場合に、上記複数の誘導変数を示
す情報を検出ステップの検出結果から削除するように構
成されていることを特徴と することを特徴とするプログ
ラム変換方法。5. A detecting step of detecting an induced variable used in a loop processing of a program code, and a code defining a value of the detected induced variable in the program code is converted into an induced variable every time the loop processing is performed. A conversion step of adding a predetermined value to convert to a code that defines a value of a new induction variable; and a plurality of induction variables detected in the detection step are defined with a value using the same other induction variable. when an induction variable that, for the plurality of induction variables, possess the inhibiting transduction inhibitor step execution of the conversion steps, double the conversion suppression step, detected by the detection step
A number of induction variables define values using the same induction variable
If the derived variable is
Information from the detection result of the detection step.
Program conversion method which is characterized in that characterized in that it is made.
換ステップ、および削除ステップと、請求項5の変換抑
制ステップとを有することを特徴とするプログラム変換
方法。 First 6. The method of claim 4, the second detection step, the conversion step, and a deletion step, the program conversion method characterized by having a conversion suppression step of claim 5.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP18149393A JP3327634B2 (en) | 1993-07-22 | 1993-07-22 | Program conversion device and program conversion method |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP18149393A JP3327634B2 (en) | 1993-07-22 | 1993-07-22 | Program conversion device and program conversion method |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| JPH0736707A JPH0736707A (en) | 1995-02-07 |
| JP3327634B2 true JP3327634B2 (en) | 2002-09-24 |
Family
ID=16101725
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP18149393A Expired - Lifetime JP3327634B2 (en) | 1993-07-22 | 1993-07-22 | Program conversion device and program conversion method |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JP3327634B2 (en) |
-
1993
- 1993-07-22 JP JP18149393A patent/JP3327634B2/en not_active Expired - Lifetime
Non-Patent Citations (1)
| Title |
|---|
| 中田育男,コンパイラ,産業図書株式会社,昭和56年,p.221−237 |
Also Published As
| Publication number | Publication date |
|---|---|
| JPH0736707A (en) | 1995-02-07 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| JPH1097430A (en) | Method and system for inserting assembly code routines into source code routines for optimization | |
| JP3237693B2 (en) | Language processing apparatus and language processing method | |
| US7624390B2 (en) | Optimizing compiling of object oriented source code | |
| US9208055B2 (en) | Importance-based call graph construction | |
| JP3327634B2 (en) | Program conversion device and program conversion method | |
| JP2879099B1 (en) | Abstract syntax tree processing method, computer readable recording medium recording abstract syntax tree processing program, computer readable recording medium recording abstract syntax tree data, and abstract syntax tree processing device | |
| JP3790707B2 (en) | Program conversion method, computer apparatus and program using the same | |
| TWI881897B (en) | Execution methods of a machine learning model | |
| JP2001325100A (en) | Program analyzer | |
| JP2001125792A (en) | Optimization accelerator | |
| JP3430635B2 (en) | Constant reference optimization processor | |
| CN115640050B (en) | Layout method, device, storage medium and equipment of stack space | |
| US20090199166A1 (en) | Program converting device | |
| US5437035A (en) | Method and apparatus for compiling a program incending a do-statement | |
| JP4327533B2 (en) | Arithmetic processing program, arithmetic processing method, and arithmetic processing apparatus | |
| JP2000339172A (en) | Memory efficiency method | |
| JP2827979B2 (en) | Assembler processing apparatus and assembler processing method | |
| JPH05324344A (en) | Argument processing optimization method at the time of function call | |
| JPH0721031A (en) | Language processing method | |
| JP2835753B2 (en) | Data input method | |
| JPH05165650A (en) | Machine language translation device | |
| JPH01128136A (en) | Compiling process system | |
| JPH11175350A (en) | Source program analyzer | |
| JPH081608B2 (en) | Program execution analysis tool | |
| KR20000032612A (en) | Method for composing execution time using stack frame of chill compiler |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20070712 Year of fee payment: 5 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20080712 Year of fee payment: 6 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20090712 Year of fee payment: 7 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20090712 Year of fee payment: 7 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20100712 Year of fee payment: 8 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20110712 Year of fee payment: 9 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20110712 Year of fee payment: 9 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20120712 Year of fee payment: 10 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20120712 Year of fee payment: 10 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20130712 Year of fee payment: 11 |
|
| EXPY | Cancellation because of completion of term |