JP3225940B2 - Program optimization method and apparatus - Google Patents

Program optimization method and apparatus

Info

Publication number
JP3225940B2
JP3225940B2 JP36631198A JP36631198A JP3225940B2 JP 3225940 B2 JP3225940 B2 JP 3225940B2 JP 36631198 A JP36631198 A JP 36631198A JP 36631198 A JP36631198 A JP 36631198A JP 3225940 B2 JP3225940 B2 JP 3225940B2
Authority
JP
Japan
Prior art keywords
loop
variable
program
value
invariant
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 - Fee Related
Application number
JP36631198A
Other languages
Japanese (ja)
Other versions
JP2000187596A (en
Inventor
さおり 佐藤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
NEC Corp
Original Assignee
NEC Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by NEC Corp filed Critical NEC Corp
Priority to JP36631198A priority Critical patent/JP3225940B2/en
Publication of JP2000187596A publication Critical patent/JP2000187596A/en
Application granted granted Critical
Publication of JP3225940B2 publication Critical patent/JP3225940B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Description

【発明の詳細な説明】DETAILED DESCRIPTION OF THE INVENTION

【0001】[0001]

【発明の属する技術分野】本発明は、プログラム最適化
方法および装置に関し、特に、ソース・プログラムから
目的プログラムを生成するコンパイラにおいて、ループ
不変変数を持つループを含むプログラムの最適化方法お
よび装置に関する。
The present invention relates to a method and an apparatus for optimizing a program, and more particularly, to a method and an apparatus for optimizing a program including a loop having a loop invariant in a compiler for generating a target program from a source program.

【0002】[0002]

【従来の技術】従来のコンパイラにおけるループで不変
な式の最適化の一例を図8に示す。従来のコンパイラで
は、ループ不変式の検出ステップ72により、ループ不
変式、すなわちループ不変変数と定数からなる式を検出
し、ループ不変式の移動ステップ73により、そのよう
な式の計算をループの前へ移動する。その場合、計算結
果を一時的な変数に代入し、ループ中の元の式の計算を
その一時的な変数の参照で置き換える。
2. Description of the Related Art FIG. 8 shows an example of optimization of a loop-invariant expression in a conventional compiler. In the conventional compiler, a loop invariant expression detecting step 72 detects a loop invariant expression, that is, an expression composed of a loop invariant variable and a constant, and a loop invariant expression moving step 73 causes such an expression to be calculated before the loop. Move to. In that case, the result of the calculation is assigned to a temporary variable, and the calculation of the original expression in the loop is replaced with a reference to the temporary variable.

【0003】ここで、ループ不変変数とは、ループの中
で値が変更されない変数のことである。例えば図9の例
で、ループの中には変数xに対する代入がない。したが
って、仮にループの直前でxの値が1であるとすると、
ループの実行が終了するまでxの値は1のままである。
すなわちxはループ不変変数である。これに対して、変
数yにはループ内で文y=iにより代入が行われ、ルー
プの実行の間に値が変更されるため、yはループ不変変
数ではない。
[0003] Here, a loop invariant variable is a variable whose value is not changed in a loop. For example, in the example of FIG. 9, there is no assignment for the variable x in the loop. Therefore, if the value of x is 1 immediately before the loop,
The value of x remains at 1 until the execution of the loop ends.
That is, x is a loop invariant variable. On the other hand, the variable y is substituted by the statement y = i in the loop, and the value is changed during the execution of the loop. Therefore, y is not a loop invariant variable.

【0004】なお、プログラムに与えられる入力が変わ
ると、ループの直前でxに保持されている値が変わる可
能性があるためループ不変“変数”と呼ばれ、どのよう
な入力に対しても値が変わらない場合とは区別される。
例えば、ループの直前でxに定数が代入される場合に
は、どのような入力に対しても常に値が一定であるが、
そのような場合には従来の最適化方法により容易に最適
化可能である。
When the input given to the program changes, the value held in x may change immediately before the loop, so it is called a loop-invariant "variable". Is not changed.
For example, if a constant is substituted for x just before the loop, the value is always constant for any input,
In such a case, optimization can be easily performed by a conventional optimization method.

【0005】すなわち、ループ不変変数とは、ループの
実行の間に限って値が変更されないことが保証されてい
る変数である。
That is, a loop invariant variable is a variable whose value is guaranteed not to change only during the execution of a loop.

【0006】一例として、図10に示すループについて
考える。このループでは、xが不変変数であり、行2
2,23に示される式がループ不変式である。
As an example, consider the loop shown in FIG. In this loop, x is an invariant variable and line 2
The equations shown in 2 and 23 are loop invariant equations.

【0007】図10のループに従来のプログラム最適化
方法を適用すると、図11に43で示すループおよび4
4で示す行が生成される。行44は、ループ43の前へ
移動された不変式を示している。計算結果は、一時的な
変数t1,t2に代入されている。
When the conventional program optimization method is applied to the loop shown in FIG. 10, the loop shown in FIG.
The row indicated by 4 is generated. Line 44 shows the invariant moved before loop 43. The calculation result is assigned to temporary variables t1 and t2.

【0008】このようなプログラムの最適化によれば、
図10のループを実行する場合には、ループが実行され
る毎に不変式22,23の計算を行わなければならない
が、図11の最適化されたプログラムでは、不変式44
の計算は1回だけであり、したがって実行時間が短くな
る。
According to such program optimization,
When the loop of FIG. 10 is executed, the calculations of the invariant expressions 22 and 23 must be performed each time the loop is executed. However, in the optimized program of FIG.
Is calculated only once, thus shortening the execution time.

【0009】一方、プログラムの最適化においてプロフ
ァイル情報を利用する例としては、特開昭63−546
46号公報に記載のものがあり、これはループの実行回
数および条件式の成立割合をプロファイル情報として利
用してベクトル化のような最適化を行うものである。
On the other hand, Japanese Patent Application Laid-Open No. 63-546 discloses an example of using profile information in program optimization.
Japanese Patent Application Publication No. 46-46, which discloses an optimization such as vectorization using the number of times of execution of a loop and the satisfaction ratio of a conditional expression as profile information.

【0010】[0010]

【発明が解決しようとする課題】図8で説明した従来の
プログラム情報最適化方法では、ループ中にコンパイラ
時に値が確定していない変数が含まれる場合には、その
変数を含む式の計算をループ前に移動することは可能で
あるが、それ以上により効率的なループを生成すること
はできない。
In the conventional method for optimizing program information described with reference to FIG. 8, when a variable including a variable whose value is not determined at the time of compiler is included in a loop, calculation of an expression including the variable is performed. It is possible to move before the loop, but it cannot create a more efficient loop.

【0011】また、ループの実行回数のようなプロファ
イル情報だけでは、効率の良い最適化を行うことはでき
ない。
Further, efficient optimization cannot be performed only with profile information such as the number of times of execution of a loop.

【0012】本発明の目的は、ループ不変変数を持つル
ープを含むプログラムの最適化において、今まで以上に
効率的に目的プログラムを得ることのできる方法および
装置を提供することにある。
An object of the present invention is to provide a method and an apparatus which can obtain a target program more efficiently than ever in optimizing a program including a loop having a loop invariant variable.

【0013】本発明の他の目的は、コンパイラを実現す
るプログラム(ソフトウェア)を記録した記録媒体を提
供することにある。
Another object of the present invention is to provide a recording medium on which a program (software) for realizing a compiler is recorded.

【0014】[0014]

【課題を解決するための手段】本発明の第1の態様によ
れば、本発明は、ソース・プログラムから目的プログラ
ムを生成する言語処理プログラム(コンパイラ)におい
て、目的プログラムを最適化する方法であって、ループ
中で値の変わらない変数を含むループ不変式を有するル
ープに対してのみ、前記変数を検出するステップと、前
記変数の実行時の値と、前記ループの実行回数とを少な
くとも含むプロファイル情報を収集する動的情報計測ス
テップと、前記プロファイル情報中で前記変数の前記実
行時の値が特定の定数である場合の前記実行回数が多
く、かつ、ループのサイズが特定のサイズ以下の場合に
は、ループを複製すると判断するステップと、複製する
と判断された場合には、前記ループ中の前記変数の使用
個所を前記定数で置き換えたループを生成し、同時に、
前記変数の値が前記定数である場合には前記生成された
ループを、それ以外の場合には元のループを実行するよ
うな制御文を挿入するループの複製ステップと、前記複
製されたループに対して各種の最適化を行う各種最適化
ステップとを含んでいる。
According to a first aspect of the present invention, there is provided a method for optimizing a target program in a language processing program (compiler) for generating a target program from a source program. Detecting a variable only for a loop having a loop invariant including a variable whose value does not change in the loop; a profile including at least a value at the time of execution of the variable and the number of times of execution of the loop. and dynamic information measurement step of collecting information, the fruit of the variables in the profile information
When the number of executions when the value at the time of execution is a specific constant is large and the size of the loop is equal to or smaller than the specific size, a step of determining to duplicate the loop; and Generating a loop in which the use places of the variables in the loop are replaced by the constants,
When the value of the variable is the constant, the generated loop; otherwise, a loop replication step of inserting a control statement that executes the original loop; and And various optimization steps for performing various optimizations.

【0015】また本発明の他の態様によれば、本発明
は、ソース・プログラムから目的プログラムを生成する
コンパイラの目的プログラム最適化装置であって、ルー
プ中で値の変わらない変数を含むループ不変式を有する
ループに対してのみ、前記変数を検出するループ不変変
数検出手段と、前記変数の実行時の値と、前記ループの
実行回数とを少なくとも含むプロファイル情報を収集す
る動的情報計測手段と、前記プロファイル情報中で前記
変数の前記実行時の値が特定の定数である場合の前記実
行回数が多く、かつ、ループのサイズが特定のサイズ以
下の場合には、ループを複製すると判断する複製可否判
定手段と、複製すると判断された場合には、前記ループ
中の前記変数の使用個所を前記定数で置き換えたループ
を生成し、同時に、前記変数の値が前記定数である場合
には前記生成されたループを、それ以外の場合には元の
ループを実行するような制御文を挿入するループ複製手
段と、前記複製されたループに対して各種の最適化を行
う各種最適化手段とを備えている。
According to another aspect of the present invention, there is provided an object program optimizing apparatus for a compiler for generating an object program from a source program, the apparatus comprising a loop invariant including a variable whose value does not change in a loop. Only for a loop having an expression, a loop invariant variable detecting means for detecting the variable, a dynamic information measuring means for collecting profile information including at least a value at the time of execution of the variable and the number of times of execution of the loop, The case where the runtime value of the variable in the profile information is a specific constant.
When the number of lines is large and the size of the loop is equal to or smaller than a specific size, a copy permission / non-permission determining unit that determines that the loop is to be replicated, and when it is determined that the loop is to be replicated, a use location of the variable in the loop. Is generated, and a control statement that executes the generated loop when the value of the variable is the constant, and otherwise executes the original loop is inserted. Loop optimizing means for performing various optimizations on the duplicated loop.

【0016】また本発明のさらに他の態様によれば、本
発明は、前記プログラム最適化方法の各ステップを実行
するプログラムを記録した記録媒体である。
According to still another aspect of the present invention, there is provided a recording medium recording a program for executing each step of the program optimizing method.

【0017】[0017]

【発明の実施の形態】図1は、本発明のプログラム最適
化装置の機能ブロック図である。このプログラム最適化
装置は、ループ不変変数検出手段1と、動的情報計測手
段2と、複製可否判定手段3と、ループ複製手段4と各
種最適化手段5とから構成されている。各手段の機能
は、プログラム最適化方法の説明と共に記述する。
FIG. 1 is a functional block diagram of a program optimizing device according to the present invention. This program optimizing device includes a loop invariant variable detecting means 1, a dynamic information measuring means 2, a duplication determining means 3, a loop duplicating means 4, and various optimizing means 5. The function of each means will be described together with the description of the program optimization method.

【0018】図2は、プログラム最適化方法を説明する
ためのフローチャートである。このフローチャートにお
ける各ステップ12,13,15,16,17は、図1
の各手段1,2,3,4,5の機能に対応している。
FIG. 2 is a flowchart for explaining the program optimizing method. Steps 12, 13, 15, 16, and 17 in this flowchart are shown in FIG.
Correspond to the functions of the means 1, 2, 3, 4, and 5.

【0019】図3は、C言語で書かれた本発明による最
適化対象のループの例である。図10で示した例と同じ
ものである。
FIG. 3 is an example of a loop to be optimized according to the present invention written in C language. This is the same as the example shown in FIG.

【0020】ソース・プログラム11から目的プログラ
ム18を生成するコンパイラにおいて、ループ不変変数
の検出ステップ12により、ループの中で値が変更され
ない変数を検出し、動的情報計測ステップ13により、
このプログラムの実行時にその変数に実際に設定されて
いる値およびループの実行回数等の情報(プロファイル
情報14)を収集する。次に、このプロファイル情報を
用いて判断ステップ15において、ループを複製するか
否かの判断を行う。ループの複製によりプログラムのサ
イズが増加してしまうという問題点があるため、複製す
るか否かの判断の際には、プロファイル情報を考慮し、
効果の大きいもののみを本発明の最適化の対象とする。
In a compiler for generating a target program 18 from a source program 11, a loop invariant variable detection step 12 detects a variable whose value is not changed in a loop, and a dynamic information measurement step 13
When the program is executed, information (profile information 14) such as the value actually set to the variable and the number of times of execution of the loop is collected. Next, it is determined whether or not the loop is to be duplicated in the determination step 15 using the profile information. Since there is a problem that the size of the program increases due to the duplication of the loop, when determining whether to duplicate, consider the profile information,
Only those with a large effect are targeted for optimization in the present invention.

【0021】ループ不変変数が特定の値であることが多
いならば、ループ複製ステップ16によって、ループ中
のその変数の使用個所を前記定数で置き換えたループを
生成し、同時に、前記変数の値が前記特定の値である場
合には複製されたループを、それ以外の場合には元のル
ープを実行するような制御文を同時に追加する。その
後、各種最適化ステップ17により最適化が適用され、
目的プログラム18が得られる。
If the loop invariant variable is often a specific value, a loop duplication step 16 creates a loop in which the use of the variable in the loop is replaced by the constant, and at the same time, the value of the variable is When the value is the specific value, a duplicated loop is added, and otherwise, a control statement for executing the original loop is added at the same time. Then, optimization is applied by various optimization steps 17,
The target program 18 is obtained.

【0022】ステップ13における動的情報計測につい
て詳しく説明する。動的情報計測の方法は、種々ある
が、代表的な2つの方法について説明する。
The dynamic information measurement in step 13 will be described in detail. Although there are various methods for measuring dynamic information, two representative methods will be described.

【0023】まず、第1の動的情報計測方法は、ループ
不変変数の検出のステップ12において検出されたルー
プ不変変数に対して、図4に示すように、ループの直前
または直後にその変数の値をファイルに逐次書き出して
いくコードを追加し、そのコードが追加されたプログラ
ムをコンパイルし実行する(これは最終的な目的プログ
ラム18とは別のものである)。その結果、例えば図3
のループを含む部分が12回(ループ自体の繰り返し回
数ではないことに注意)実行され、そのファイルには1
0,9,10,10,2,10,10,10,10,1
0,1,10と書かれていたとすると、その実行におい
ては、この変数に代入された値は10の場合が9回、
9,2,1の場合が各々1回ずつであったことが分か
る。
First, in the first dynamic information measurement method, as shown in FIG. 4, the loop invariant variable detected in step 12 of detecting the loop invariant variable is immediately before or immediately after the loop as shown in FIG. Add code that writes values sequentially to a file, compile and execute the program to which the code was added (this is different from the final target program 18). As a result, for example, FIG.
Is executed 12 times (note that this is not the number of iterations of the loop itself), and the file contains 1
0,9,10,10,2,10,10,10,10,1
Assuming that 0, 1, and 10 are written, the value assigned to this variable is 9 in the case of 10 in the execution,
It can be seen that the cases of 9, 2, and 1 were each performed once.

【0024】第2の動的情報計測方法は、第1の方法と
は異なり、ループ不変変数の検出のステップにおいては
ループ不変変数を検出するだけで、そのままコンパイル
し目的プログラムを生成する(これも最終的な目的プロ
グラム18とは別のものである)。その目的プログラム
中で、ループ不変変数に対して、メモリ上で割り当てら
れた領域のアドレスを検出する。この後で、指定したア
ドレス(ループ不変変数のアドレス)のメモリ領域に格
納される値を、指定したタイミング(ループの実行の直
前)でチェックして統計をとるような機能をもつCPU
シミュレータを用いて、この目的プログラムを実行する
ことにより、前記メモリ領域に格納される値の統計情報
(プロファイル情報)を得る。
The second dynamic information measurement method differs from the first method in that the loop invariant variable detection step detects the loop invariant variable and compiles the program as it is to generate a target program. This is different from the final objective program 18). In the target program, an address of an area allocated on a memory is detected for a loop invariant variable. Thereafter, a CPU having a function of checking a value stored in a memory area of a specified address (address of a loop invariable variable) at a specified timing (immediately before execution of a loop) and collecting statistics.
By executing the target program using a simulator, statistical information (profile information) of values stored in the memory area is obtained.

【0025】上記の第1および第2の方法により得られ
たプロファイル情報を用いて、ステップ16でループを
複製するか否かの判断を行うが、その判断基準の設定方
法の代表的なものを説明する。
Using the profile information obtained by the first and second methods, it is determined in step 16 whether or not the loop is to be duplicated. A typical method for setting the criterion is as follows. explain.

【0026】まず第1の方法は、判断基準を利用者に指
定させる方法である。本発明を実装したコンパイラとし
ては、利用者にループ不変変数とその値の分布(全体が
何回で、そのうちどの値が何回あったかという情報)お
よびループのサイズ(複製により最終的な実行プログラ
ムのサイズが増加してしまうというデメリットがあるた
め)を提示するのみで、判断は利用者に委ねて、利用者
から指示があった場合にのみループの複製を行うように
する。
First, a first method is a method of allowing a user to specify a criterion. The compiler that implements the present invention provides the user with the distribution of the loop invariant variables and their values (information about how many times the whole is, and which value was there and how many times) and the size of the loop (the final execution program (Since there is a disadvantage that the size increases), the decision is left to the user, and the loop is copied only when instructed by the user.

【0027】第2の方法として、ループ不変変数の値
が、全体の回数のうちの一定の閾値(例えば90%)以
上の場合に特定の値であり、かつループのサイズが特定
のサイズ以内のときのみループの複製を行うような設定
とする方法である。
As a second method, when the value of the loop invariant variable is equal to or more than a certain threshold value (for example, 90%) of the total number of times, the value of the loop invariable variable is a specific value, and the size of the loop is within the specific size. This is a method in which the setting is made so that the loop is duplicated only when it is.

【0028】次に、各種最適化ステップ17について説
明する。各種最適化のステップで実行されるのは、一般
的なコンパイラの最適化であるが、本発明を効果的に実
施するためには少なくとも次のような最適化項目が含ま
れるものとする。 (1)定数計算 定数同士の計算のようにコンパイル時に結果が確定する
ループ不変式は、計算結果の値で置き換える。 (2)ループ不変式の移動 ループ不変変数と定数のみから構成されるループ不変式
は、ループの実行の間のどの時点で計算しても値が変わ
らない。そのままではループの繰り返しの都度計算され
ることになり冗長であるため、式の計算はループの直前
に1回だけ行い結果を一時変数に格納しておいて、ルー
プ中ではその一時変数を参照するように変更する。これ
はループ不変式の移動と呼ばれ、広く普及している最適
化手法である。
Next, various optimization steps 17 will be described. What is executed in the various optimization steps is optimization of a general compiler, but in order to effectively implement the present invention, it is assumed that at least the following optimization items are included. (1) Constant calculation A loop invariant whose result is determined at compile time, such as a calculation between constants, is replaced with the value of the calculation result. (2) Movement of loop invariant expression The value of a loop invariant expression consisting of only a loop invariant variable and a constant does not change even if it is calculated at any point during the execution of the loop. As it is redundant as it is calculated each time the loop is repeated, the calculation of the expression is performed only once immediately before the loop, the result is stored in a temporary variable, and the temporary variable is referenced in the loop. To change. This is called loop-invariant movement and is a widely used optimization method.

【0029】次に、図3のループを最適化する処理を、
図2のフローチャートを参照しながら具体的に説明す
る。
Next, the processing for optimizing the loop in FIG.
This will be specifically described with reference to the flowchart of FIG.

【0030】図3のループにおいて、変数xはループ内
で値が変更されないループ不変変数であり、行22,2
3はループ不変式である。このようなループ不変変数x
は、ステップ12で検出される。
In the loop shown in FIG. 3, the variable x is a loop invariant whose value is not changed in the loop.
3 is a loop invariant. Such a loop invariant variable x
Is detected in step 12.

【0031】動的情報計測ステップ13で、このループ
を含むプログラムを実行してプロファイル情報14を収
集したところ、ほとんどの場合にxの値が15であった
と仮定する。そして判断ステップ15で、複製すると判
断されたとする。
In the dynamic information measurement step 13, it is assumed that the value of x is 15 in most cases when the program including this loop is executed to collect the profile information 14. Then, it is assumed that it is determined in the determination step 15 that copying is to be performed.

【0032】ループの複製のステップ16により、図5
に示すようなプログラムに変更される。前半のループ4
2はxが15の場合に実行される部分であり、後半のル
ープ43はそれ以外の場合に実行される部分である。こ
こで前半のループ42が実行される場合にはxが15で
あることが確定しているので、前半のループ中のxは1
5として置き換えられる。
By the step 16 of duplicating the loop, FIG.
The program is changed as shown in First half loop 4
2 is a part executed when x is 15, and the latter half of the loop 43 is a part executed in other cases. Here, when the first half of the loop 42 is executed, it is determined that x is 15; therefore, x in the first half of the loop is 1
Replaced as 5.

【0033】次に、各種最適化のステップ17におい
て、前述の定数計算およびループ不変式の移動が適用さ
れる。定数計算により、前半のループ42中のif(1
5>10)は常に成立するため条件が削除され、また1
5*2,15/5は各々30,3となる。また、ループ
不変式の移動により、後半のループ43中の不変式x*
2,x/5が、t1=x*2,t2=x/5としてルー
プの前に移動される。そして、これら不変式の計算は、
一時的な変数t1,t2の参照で置き換えられる。この
結果、図6に示す目的プログラムが得られる。
Next, in step 17 of various optimizations, the above-described constant calculation and movement of the loop invariant are applied. By the constant calculation, if (1) in the first half loop 42 is obtained.
5> 10) is always satisfied, so the condition is deleted.
5 * 2 and 15/5 are 30, 3 respectively. In addition, the movement of the loop invariant causes the invariant x *
2, x / 5 are moved before the loop as t1 = x * 2, t2 = x / 5. And the calculation of these invariants is
It is replaced by a temporary reference to variables t1 and t2. As a result, the target program shown in FIG. 6 is obtained.

【0034】この目的プログラムは、効率化された前半
のループ32と、ループ不変式が移動された後半のルー
プ33とからなる。このような目的プログラムによれ
ば、多くの場合に、効率化された方のループ32が実行
されるため、全体としてプログラムの実行速度が向上す
る。
This objective program comprises a first half loop 32 in which the efficiency is improved and a second half loop 33 in which the loop invariant is moved. According to such a target program, in many cases, the more efficient loop 32 is executed, so that the overall program execution speed is improved.

【0035】[0035]

【実施例】図7は、本発明の実施例を示すフローチャー
トである。
FIG. 7 is a flowchart showing an embodiment of the present invention.

【0036】ステップ51では、ソース・プログラム1
1を読み込んで、コンパイラで扱える内部表現に変え
る。
In step 51, the source program 1
1 is read and changed to an internal representation that can be handled by the compiler.

【0037】次に、ステップ52で、ループ不変変数が
xであることを検出する。
Next, at step 52, it is detected that the loop invariant variable is x.

【0038】ステップ53で、検出されたループ不変変
数に対して、図4で説明したように、ループの直前にそ
の変数の値をファイルに逐次書き出していくコードを挿
入する。
In step 53, as described with reference to FIG. 4, a code for sequentially writing the value of the variable to a file is inserted immediately before the loop into the detected loop invariant variable.

【0039】ステップ54で、コードが追加されたプロ
グラムをコンパイルし、内部表現から動的情報計測用目
的プログラム19を作成する。
In step 54, the program to which the code has been added is compiled, and the dynamic information measurement purpose program 19 is created from the internal representation.

【0040】ステップ55で、この目的プログラムをシ
ミュレータで実行して、プロファイル情報14を得る。
In step 55, the target program is executed by the simulator to obtain the profile information 14.

【0041】ステップ56において、得られた動的情報
計測から、ループ不変変数の値Cが全体の回数のうちの
N%以上、かつループのサイズがSバイト以下であるか
を判断する。
In step 56, it is determined from the obtained dynamic information measurement whether the value C of the loop invariant variable is equal to or more than N% of the total number of times and the loop size is equal to or less than S bytes.

【0042】ステップ56で“Yes”であれば、ステ
ップ57でループを複製する。複製されたループに対
し、前述した定数計算(ステップ58),ループ不変式
の移動(ステップ59),およびその他の最適化(ステ
ップ60)を含む各種最適化を行う。その他の最適化の
一例として、メモリ上におかれている変数を高速にアク
セス可能なレジスト上に割付ける処理が含まれる。
If "Yes" in the step 56, the loop is duplicated in a step 57. Various optimizations including the above-described constant calculation (step 58), movement of the loop invariant expression (step 59), and other optimization (step 60) are performed on the duplicated loop. As another example of the optimization, a process of allocating variables stored in a memory to a resist that can be accessed at high speed is included.

【0043】最後にステップ61において、内部表現か
ら最終の目的プログラム18を作成する。
Finally, in step 61, the final target program 18 is created from the internal representation.

【0044】ステップ56において、“No”の場合に
は、ループの複製を行うことなく、ステップ59に進
み、ループ不変式の移動が行われて、従来の方法と同様
の図11に示した目的プログラムが得られる。
In the case of "No" in step 56, the process proceeds to step 59 without duplicating the loop, the loop invariant expression is moved, and the object shown in FIG. The program is obtained.

【0045】以上説明した実施の形態および実施例のプ
ログラム最適化装置および方法は、実際には記録媒体に
記録されたプログラムによっても実行される。
The program optimizing apparatus and method of the above-described embodiments and examples are actually executed also by a program recorded on a recording medium.

【0046】[0046]

【発明の効果】本発明によれば、元のループと比べて効
率的なループが生成され、多くの場合にその効率化され
た方のループが実行されるため、全体としてプログラム
の実行速度が向上する。これは、プロファイル情報を利
用することにより、コンパイル時に値が確定していない
変数を含むループに対しても、その変数を適切な定数で
置き換えた効率的なループを生成することが可能となる
ためである。
According to the present invention, a loop that is more efficient than the original loop is generated, and the more efficient loop is executed in many cases. improves. This is because by using profile information, even for a loop that includes a variable whose value is not determined at compile time, it is possible to generate an efficient loop in which the variable is replaced with an appropriate constant. It is.

【0047】また、変数のプロファイル情報(実行値の
値の情報)の収集は、一般的にデータ量および収集時間
がともに膨大となりがちであるが、本発明のプロファイ
ル情報はデータ量および収集時間とも実用的な範囲で収
集可能である。これは、変数のプロファイル情報の収集
の対象がループ不変変数のループ内での値に限定され、
それらの変数の各々についてループの直前(あるいは直
後)でただ1度その値を収集すればよいためである。
In general, the collection of variable profile information (information of the values of execution values) tends to be enormous in both the data amount and the collection time. However, the profile information of the present invention has both the data amount and the collection time. It can be collected in a practical range. This means that the collection of variable profile information is limited to loop-invariant variable values within the loop,
This is because the value of each of those variables need only be collected once immediately before (or immediately after) the loop.

【図面の簡単な説明】[Brief description of the drawings]

【図1】本発明のプログラム最適化装置の機能ブロック
図である。
FIG. 1 is a functional block diagram of a program optimization device of the present invention.

【図2】プログラム最適化方法を説明するためのフロー
チャートである。
FIG. 2 is a flowchart for explaining a program optimization method.

【図3】C言語で書かれた本発明による最適化対象のル
ープの例である。
FIG. 3 is an example of a loop to be optimized according to the present invention written in C language.

【図4】ループの直前にその変数の値をファイルに逐次
書き出していくコードを追加した例を示す図である。
FIG. 4 is a diagram illustrating an example in which a code for sequentially writing the value of a variable to a file immediately before a loop is added.

【図5】複製されたプログラムを示す図である。FIG. 5 is a diagram showing a copied program.

【図6】得られた目的プログラムを示す図である。FIG. 6 is a diagram showing an obtained target program.

【図7】実施例を示すフローチャートである。FIG. 7 is a flowchart showing an embodiment.

【図8】従来のコンパイラにおけるループで不変な式の
最適化の一例を示す図である。
FIG. 8 is a diagram illustrating an example of optimization of a loop-invariant expression in a conventional compiler.

【図9】ループ不変変数を説明するための図である。FIG. 9 is a diagram for explaining a loop invariant variable.

【図10】ループの一例を示す図である。FIG. 10 is a diagram illustrating an example of a loop.

【図11】従来のプログラム最適化方法により生成され
たプログラムを示す図である。
FIG. 11 is a diagram showing a program generated by a conventional program optimization method.

【符号の説明】[Explanation of symbols]

1 ループ不変変数検出手段 2 動的情報計測手段 3 複製可否判定手段 4 ループ複製手段 5 各種最適化手段 DESCRIPTION OF SYMBOLS 1 Loop invariant variable detection means 2 Dynamic information measurement means 3 Duplication possibility determination means 4 Loop duplication means 5 Various optimization means

───────────────────────────────────────────────────── フロントページの続き (56)参考文献 特開 平10−40112(JP,A) 特開 平8−87417(JP,A) 特開 平9−319587(JP,A) 特開 平9−330233(JP,A) 特開 平2−176938(JP,A) P.P.Chang他,”Using Profile Informati on to Assist Class ic Code Opitimizat ions”,Software−Pra ctice and Experien ce,1991,Vol.21,No.12, p.1301−1321 (58)調査した分野(Int.Cl.7,DB名) G06F 9/45 ────────────────────────────────────────────────── ─── Continuation of the front page (56) References JP-A-10-40112 (JP, A) JP-A-8-87417 (JP, A) JP-A-9-319587 (JP, A) JP-A-9-99 330233 (JP, A) JP-A-2-176938 (JP, A) P. Chang et al., "Using Profile Information to Assist Class Code Optimizedions", Software-Practice and Experience, 1991, Vol. 21, No. 12, p. 1301-1321 (58) Field surveyed (Int.Cl. 7 , DB name) G06F 9/45

Claims (6)

(57)【特許請求の範囲】(57) [Claims] 【請求項1】ソース・プログラムから目的プログラムを
生成する言語処理プログラムにおいて、目的プログラム
を最適化する方法であって、 ループ中で値の変わらない変数を含むループ不変式を有
するループに対してのみ、前記変数を検出するステップ
と、 前記変数の実行時の値と、前記ループの実行回数とを少
なくとも含むプロファイル情報を収集する動的情報計測
ステップと、 前記プロファイル情報中で前記変数の前記実行時の値が
特定の定数である場合の前記実行回数が多く、かつ、ル
ープのサイズが特定のサイズ以下の場合には、ループを
複製すると判断するステップと、 複製すると判断された場合には、前記ループ中の前記変
数の使用個所を前記定数で置き換えたループを生成し、
同時に、前記変数の値が前記定数である場合には前記生
成されたループを、それ以外の場合には元のループを実
行するような制御文を挿入するループの複製ステップ
と、 前記複製されたループに対して各種の最適化を行う各種
最適化ステップと、 を含むことを特徴とするプログラム最適化方法。
1. A method for optimizing a target program in a language processing program for generating a target program from a source program, the method comprising only a loop having a loop invariant including a variable whose value does not change in the loop. a step of detecting the variable, and the value of the execution time of the variables, and dynamic information measurement step of collecting at least contains profile information and execution count of the loop, the run-time of said variable in said profile information If the value of is a specific constant, the number of executions is large, and if the size of the loop is equal to or smaller than a specific size, a step of determining to duplicate the loop; and Generating a loop in which the use places of the variables in the loop are replaced with the constants,
At the same time, when the value of the variable is the constant, the generated loop, otherwise, a loop copying step of inserting a control statement to execute the original loop, the copied step, A program optimization method, comprising: various optimization steps for performing various optimizations on a loop.
【請求項2】前記プロファイル情報の収集は、ループの
直前またはループ直後に前記変数の値をファイルに逐次
書き出していくコードを追加し、そのコードが追加され
たプログラムをコンパイルし実行することにより行うこ
とを特徴とする請求項1記載のプログラム最適化方法。
2. Collection of the profile information is performed by adding a code for sequentially writing the value of the variable to a file immediately before or immediately after the loop, and compiling and executing the program to which the code is added. 2. The method according to claim 1, further comprising the steps of:
【請求項3】前記プロファイル情報の収集は、前記変数
が検出されたソース・プログラムをそのままコンパイル
して目的プログラムを生成し、この目的プログラム中
で、前記変数に対して、メモリ上で割り当てられた領域
のアドレスを検出し、指定したアドレスのメモリ領域に
格納される値を、指定したタイミングでチェックして統
計をとる機能をもつシミュレータを用いて、この目的プ
ログラムを実行することにより、前記メモリ領域に格納
される値のプロファイル情報を得ることにより行うこと
を特徴とする請求項1記載のプログラム最適化方法。
3. The method according to claim 1, wherein the profile information is collected by compiling a source program in which the variable is detected as it is to generate a target program, and in the target program, the variable is allocated to the variable in a memory. Executing the target program using a simulator having a function of detecting an address of an area, checking a value stored in a memory area at a specified address at a specified timing, and obtaining statistics, the 2. The method according to claim 1, wherein the method is performed by obtaining profile information of a value stored in the program.
【請求項4】前記各種最適化ステップは、コンパイル時
に結果が確定するループ不変式を、計算結果の値で置き
換える定数計算と、ループ不変式の計算はループの直前
に1回だけ行い結果を一時変数に格納しておいて、ルー
プ中ではその一時変数を参照するように変更する、ルー
プ不変式の移動とを含むことを特徴とする請求項1〜3
のいずれかに記載のプログラム最適化方法。
4. The various optimizing steps include: a constant calculation for replacing a loop invariant whose result is determined at compile time with a value of a calculation result; and a calculation of a loop invariant only once immediately before a loop and temporarily storing the result. 4. The method according to claim 1, further comprising: moving a loop invariant expression stored in a variable and changing the temporary variable in the loop so as to refer to the temporary variable.
The program optimization method according to any one of the above.
【請求項5】ソース・プログラムから目的プログラムを
生成する言語処理プログラムの目的プログラム最適化装
置であって、 ループ中で値の変わらない変数を含むループ不変式を有
するループに対してのみ、前記変数を検出するループ不
変変数検出手段と、 前記変数の実行時の値と、前記ループの実行回数とを少
なくとも含むプロファイル情報を収集する動的情報計測
手段と、 前記プロファイル情報中で前記変数の前記実行時の値が
特定の定数である場合の前記実行回数が多く、かつ、ル
ープのサイズが特定のサイズ以下の場合には、ループを
複製すると判断する複製可否判定手段と、 複製すると判断された場合には、前記ループ中の前記変
数の使用個所を前記定数で置き換えたループを生成し、
同時に、前記変数の値が前記定数である場合には前記生
成されたループを、それ以外の場合には元のループを実
行するような制御文を挿入するループ複製手段と、 前記複製されたループに対して各種の最適化を行う各種
最適化手段と、 を備えることを特徴とするプログラム最適化装置。
5. An object program optimizing apparatus for a language processing program for generating an object program from a source program, wherein the variable is used only for a loop having a loop invariant including a variable whose value does not change in the loop. a loop invariant variable detection means for detecting a value of the execution time of the variables, and dynamic information measuring means for collecting at least contains profile information and execution count of the loop, the execution of the variables in the profile information If the value of the time is a specific constant, the number of executions is large, and if the size of the loop is equal to or smaller than a specific size, a copy permission / non-permission determining unit that determines to copy the loop; and Generates a loop in which the use places of the variables in the loop are replaced with the constants,
At the same time, if the value of the variable is the constant, the generated loop is inserted; otherwise, a loop duplicating unit that inserts a control statement that executes the original loop; and A program optimizing device, comprising: various optimizing means for performing various optimizing operations on a program.
【請求項6】ソース・プログラムから目的プログラムを
生成するときに目的プログラムを最適化するに際し、 ループ中で値の変わらない変数を含むループ不変式を有
するループに対してのみ、前記変数を検出するステップ
と、 前記変数の実行時の値と、前記ループの実行回数とを少
なくとも含むプロファイル情報を収集する動的情報計測
ステップと、 前記プロファイル情報中で前記変数の前記実行時の値が
特定の定数である場合の前記実行回数が多く、かつ、ル
ープのサイズが特定のサイズ以下の場合には、ループを
複製すると判断するステップと、 複製すると判断された場合には、前記ループ中の前記変
数の使用個所を前記定数で置き換えたループを生成し、
同時に、前記変数の値が前記定数である場合には前記生
成されたループを、それ以外の場合には元のループを実
行するような制御文を挿入するループの複製ステップ
と、 前記複製されたループに対して各種の最適化を行う各種
最適化ステップと、 を実行するプログラムを記録した記録媒体。
6. When optimizing a target program when generating a target program from a source program, the variable is detected only for a loop having a loop invariant including a variable whose value does not change in the loop. steps and the value of the execution time of the variables, and dynamic information measurement step of collecting at least contains profile information and execution count of the loop, the runtime value specific constant of the variable in the profile information If the number of executions is large and the size of the loop is equal to or smaller than a specific size, a step of judging to duplicate the loop; and Generate a loop in which the used places are replaced with the constants,
At the same time, when the value of the variable is the constant, the generated loop, otherwise, a loop copying step of inserting a control statement to execute the original loop, the copied step, A recording medium on which is recorded a program for executing various optimization steps for performing various optimizations on the loop, and
JP36631198A 1998-12-24 1998-12-24 Program optimization method and apparatus Expired - Fee Related JP3225940B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP36631198A JP3225940B2 (en) 1998-12-24 1998-12-24 Program optimization method and apparatus

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP36631198A JP3225940B2 (en) 1998-12-24 1998-12-24 Program optimization method and apparatus

Publications (2)

Publication Number Publication Date
JP2000187596A JP2000187596A (en) 2000-07-04
JP3225940B2 true JP3225940B2 (en) 2001-11-05

Family

ID=18486468

Family Applications (1)

Application Number Title Priority Date Filing Date
JP36631198A Expired - Fee Related JP3225940B2 (en) 1998-12-24 1998-12-24 Program optimization method and apparatus

Country Status (1)

Country Link
JP (1) JP3225940B2 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10365900B2 (en) 2011-12-23 2019-07-30 Dataware Ventures, Llc Broadening field specialization
CN107851003A (en) * 2015-04-02 2018-03-27 数据仓库投资有限公司 For improving the field specialization system and method for program feature
US10733099B2 (en) 2015-12-14 2020-08-04 Arizona Board Of Regents On Behalf Of The University Of Arizona Broadening field specialization

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
P.P.Chang他,"Using Profile Information to Assist Classic Code Opitimizations",Software−Practice and Experience,1991,Vol.21,No.12,p.1301−1321

Also Published As

Publication number Publication date
JP2000187596A (en) 2000-07-04

Similar Documents

Publication Publication Date Title
US5805863A (en) Memory pattern analysis tool for use in optimizing computer program code
US6072951A (en) Profile driven optimization of frequently executed paths with inlining of code fragment (one or more lines of code from a child procedure to a parent procedure)
US6922828B1 (en) Method and system for detecting common bytecode sequences
Bik et al. Compilation techniques for sparse matrix computations
JP4181326B2 (en) Method, apparatus and program for code optimization
US5202995A (en) Method for removing invariant branches from instruction loops of a computer program
Davidson et al. Subprogram inlining: A study of its effects on program execution time
JP4812997B2 (en) Method and apparatus for improving locality of reference by memory management
US6519765B1 (en) Method and apparatus for eliminating redundant array range checks in a compiler
US7950005B2 (en) Method and apparatus for performing versioning for loop, method and apparatus for collecting array range check information in basic blocks, method for modifying array range check information, method for optimizing array range checks, method for generating codes for array range checks, method and apparatus for eliminating redundant array range checks, method for selecting array range checks, method for modifying array range checks, method for collecting array range checks, and method for determining handling of array range checks
JPH10269088A (en) Method for optimizing compile of pointer variable
KR100215502B1 (en) Optimizer
US5581762A (en) Compiling apparatus having a function to analyze overlaps of memory addresses of two or more data expressions and a compiling method
US6117185A (en) Skip list data storage during compilation
JPH02217926A (en) Compiler
Tofte et al. Programming with regions in the ML Kit (for version 4)
Collette et al. Enhancing the tractability of rely/guarantee specifications in the development of interfering operations
JP3802058B2 (en) System, method and compiler preprocessor for conditionally compiling software compilation units
Stancu et al. Safe and efficient hybrid memory management for Java
JP6651977B2 (en) Information processing apparatus, compiling method, and compiling program
JP3225940B2 (en) Program optimization method and apparatus
EP1164477A2 (en) A loop optimization method and a compiler
JP3339317B2 (en) Dynamic information utilization type program optimization device
Wolf et al. Associative caches in formal software timing analysis
JPH10320212A (en) Cache optimizing method

Legal Events

Date Code Title Description
FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20070831

Year of fee payment: 6

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20080831

Year of fee payment: 7

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20080831

Year of fee payment: 7

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20090831

Year of fee payment: 8

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20090831

Year of fee payment: 8

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20100831

Year of fee payment: 9

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20100831

Year of fee payment: 9

S533 Written request for registration of change of name

Free format text: JAPANESE INTERMEDIATE CODE: R313533

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20100831

Year of fee payment: 9

R350 Written notification of registration of transfer

Free format text: JAPANESE INTERMEDIATE CODE: R350

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20110831

Year of fee payment: 10

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20110831

Year of fee payment: 10

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20120831

Year of fee payment: 11

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20120831

Year of fee payment: 11

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20130831

Year of fee payment: 12

LAPS Cancellation because of no payment of annual fees