JP2001075814A - Device and method for compilation - Google Patents

Device and method for compilation

Info

Publication number
JP2001075814A
JP2001075814A JP23253399A JP23253399A JP2001075814A JP 2001075814 A JP2001075814 A JP 2001075814A JP 23253399 A JP23253399 A JP 23253399A JP 23253399 A JP23253399 A JP 23253399A JP 2001075814 A JP2001075814 A JP 2001075814A
Authority
JP
Japan
Prior art keywords
registers
object code
register
vertex
code
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.)
Granted
Application number
JP23253399A
Other languages
Japanese (ja)
Other versions
JP3405696B2 (en
Inventor
Satoshi Koseki
聰 古関
Tatsushi Inagaki
達氏 稲垣
Toshiaki Yasue
俊明 安江
Hideaki Komatsu
秀昭 小松
Mikio Takeuchi
幹雄 竹内
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.)
International Business Machines Corp
Original Assignee
International Business Machines 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 International Business Machines Corp filed Critical International Business Machines Corp
Priority to JP23253399A priority Critical patent/JP3405696B2/en
Publication of JP2001075814A publication Critical patent/JP2001075814A/en
Application granted granted Critical
Publication of JP3405696B2 publication Critical patent/JP3405696B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Abstract

PROBLEM TO BE SOLVED: To effectively optimize an object code in the range satisfying limitation caused by the number of physical registers of a processor. SOLUTION: This compiler device performs code generation from a program represented by a DAG(directed acyclic graph) while evaluating the number of used registers and the number of execution cycles and optimizes a code to be generated. That is, the compiler calculates the number of cycles with which each operation can be executed on the DAG and the number of the currently available registers, performs code generation while preceding an operator on an execution path that takes the most time in the DAG in a part where the number of registers is sufficient, and performs code generation while preceding such an operator as to reduce the number of used registers when the number of registers is not sufficient.

Description

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

【0001】[0001]

【産業上の利用分野】本発明は、ソースコードをコンパ
イルし、最適化したオブジェクトコードを生成するコン
パイル装置およびその方法に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a compiling apparatus and method for compiling source code and generating optimized object code.

【0002】[0002]

【従来の技術】例えば、、"Compilers -Principles, Te
chniques and Tools-A.V. Aho, R. Sethi and J.D. Ull
man", "Principles of Compiler Design A.V. Aho and
J.D. Ullman", "Advanced Compiler Design Implementa
tion, S.S. Muchnick"等の文献に開示されているよう
に、従来から、高級プログラミング言語で記述されたソ
ースコードをコンパイルし、プロセッサが実行可能なオ
ブジェクトコードを生成するコンパイラが一般的に用い
られており、また、このコンパイラに対しては、より高
速実行可能なオブジェクトコードが得られるように、従
来から、様々なオブジェクトコード生成処理の最適化が
なされてきた。
2. Description of the Related Art For example, "Compilers -Principles, Te"
chniques and Tools-AV Aho, R. Sethi and JD Ull
man "," Principles of Compiler Design AV Aho and
JD Ullman "," Advanced Compiler Design Implementa
Conventionally, a compiler that compiles source code described in a high-level programming language and generates object code executable by a processor, as disclosed in literatures such as "Action, SS Muchnick", has been generally used. In addition, various optimizations of the object code generation processing have been conventionally performed on the compiler so that an object code that can be executed at a higher speed can be obtained.

【0003】コンパイラにおいて、オブジェクトコード
生成処理の最適化をしようとすると、多くの場合、最適
化の適用範囲と、オブジェクトコード実行のために使用
可能な物理レジスタの数との間で、トレードオフを行わ
なければならない。
In a compiler, when trying to optimize an object code generation process, a trade-off is often made between the scope of the optimization and the number of physical registers available for executing the object code. It must be made.

【0004】例えば、コードスケジューリングにより最
適化を行うためには、データ依存性がある命令同士の間
隔を離してプロセッサのパイプラインの充填率を上げ、
プロセッサ内の演算器の遅延を隠蔽しなければならな
い。このような場合には、パイプライン処理される複数
の数値を格納するために、一時的なレジスタが必要とさ
れる。また、例えば、共通部分式(Common Subexpressi
ons)を省略して、演算の個数を減らす最適化を行う場
合には、計算された共通部分式の値を格納するレジスタ
が必要とされる。
For example, in order to perform optimization by code scheduling, an interval between instructions having data dependency is increased to increase a filling rate of a pipeline of a processor,
The delay of the arithmetic unit in the processor must be hidden. In such a case, a temporary register is needed to store the plurality of values to be pipelined. Also, for example, a common subexpression (Common Subexpressi
In the case of omitting ons) and performing optimization to reduce the number of operations, a register for storing the calculated value of the common subexpression is required.

【0005】従来のコンパイラにおける最適化では、共
通部分式削除の最適化処理、レジスタ割り付けを最適化
するレジスタアロケーション処理、コードスケジューリ
ングの最適化を行うコードスケジューリング処理は、そ
れぞれ別々のパスとして実現されていた。これらの最適
化処理パスは、それぞれ、前置された他の最適化処理パ
スの処理結果を入力とする。このように、全段階の処理
結果に対して最適化を行う方法には、例えば、前段階の
処理が、かえって、その次の段階の最適化処理を妨げる
方向に働く可能性があるという問題がある。例えば、共
通部分式削除処理の結果、レジスタの使用数が増えたよ
うな場合、次にレジスタアロケーション処理を行うと、
レジスタの値を退避したり復元したりするレジスタスピ
ルのコードが、不要に発生してしまうことがある。
In the conventional optimization by a compiler, the optimization processing for elimination of common subexpressions, the register allocation processing for optimizing register allocation, and the code scheduling processing for optimizing code scheduling are implemented as separate paths. Was. Each of these optimization processing paths receives a processing result of another preceding optimization processing path as an input. As described above, the method of optimizing the processing results of all stages has a problem that, for example, the process of the previous stage may work in a direction that hinders the optimization process of the next stage. is there. For example, in the case where the number of registers used has increased as a result of the common subexpression deletion processing, when register allocation processing is performed next,
Register spill codes for saving and restoring register values may be generated unnecessarily.

【0006】また、次段階の処理が、前段階の処理の結
果に制限されてしまう可能性もある。例えば、使用可能
なレジスタ数に余裕があっても、レジスタアロケーショ
ン処理の後にコードスケジューリング処理を行うと、コ
ードスケジューリング処理において、レジスタをリネー
ミングして演算器の遅延を隠蔽するという最適化を行う
ことは、難しくなる。
There is also a possibility that the processing in the next stage is limited to the result of the processing in the previous stage. For example, even if the number of available registers is sufficient, if code scheduling processing is performed after register allocation processing, in the code scheduling processing, optimization is performed such that registers are renamed to conceal delays of arithmetic units. Gets harder.

【0007】[0007]

【発明が解決しようとする課題】本発明は、上述した従
来技術の問題点に鑑みてなされたものであり、プロセッ
サの物理レジスタ数に起因する制約を満たす範囲におい
て、コードスケジューリングおよび共通部分式削除によ
り、オブジェクトコードを効果的に最適化することがで
きるコンパイル装置およびその方法を提供することを目
的とする。また、本発明は、DAG(directed acyclic
graph)形式で表現されたソースプログラムから、レジス
タ使用数とハードウェアの実行サイクル数を評価しなが
らオブジェクトコードの生成を行い、コードスケジュー
リングによる最適化および共通部分式削除の適用範囲
と、物理レジスタ数の制約とを最適にトレードオフする
ことができるコンパイル装置およびその方法を提供する
ことを目的とする。
SUMMARY OF THE INVENTION The present invention has been made in view of the above-mentioned problems of the prior art, and provides code scheduling and common sub-expression elimination within a range that satisfies a constraint caused by the number of physical registers of a processor. Accordingly, it is an object of the present invention to provide a compiling device and a compiling method capable of effectively optimizing an object code. Further, the present invention provides a DAG (directed acyclic
From the source program expressed in (graph) format, object code is generated while evaluating the number of registers used and the number of hardware execution cycles, the scope of optimization by code scheduling and the elimination of common subexpressions, and the number of physical registers It is an object of the present invention to provide a compiling device and a compiling method that can optimally trade off with the constraints of the above.

【0008】[0008]

【課題を達成するための手段】[コンパイル装置]上記
目的を達成するために、本発明にかかるコンパイル装置
は、プログラムのソースコードをDAG形式に変換する
変換手段と、前記変換されたソースコードに含まれる命
令それぞれに対応するオブジェクトコードを、所定数の
レジスタを用いて実行するプロセッサのパラメータを計
算するパラメータ計算手段と、前記変換されたソースコ
ードを走査し、計算された前記プロセッサのパラメータ
に基づいて、前記ソースコードをコンパイルしてオブジ
ェクトコードを生成するコンパイル手段とを有するコン
パイル装置であって、前記パラメータ計算手段は、前記
命令それぞれに対応するオブジェクトコードが、前記プ
ロセッサにより実行されるタイミングを計算するタイミ
ング計算手段と、前記命令それぞれに対応するオブジェ
クトコードが実行されるときに占有される前記プロセッ
サのレジスタ数の増減を示す数値を計算するレジスタ増
減計算手段とを有する。
To achieve the above object, a compiling apparatus according to the present invention comprises a converting means for converting a source code of a program into a DAG format, and a converting means for converting the source code into a DAG format. Parameter calculating means for calculating a processor parameter for executing an object code corresponding to each of the included instructions by using a predetermined number of registers; and scanning the converted source code, based on the calculated processor parameter. A compiling unit for compiling the source code to generate an object code, wherein the parameter calculating unit calculates a timing at which the object code corresponding to each of the instructions is executed by the processor. Timing calculation means for performing Serial and a register decrease calculation means for calculating a numerical value indicating the register number of increase or decrease of the processor occupied when the object code corresponding to the instruction, respectively, are performed.

【0009】好適には、前記コンパイル手段は、前記変
換されたソースコードにおける前記命令の実行順序に沿
って、前記命令に付与された優先順位に従って、前記命
令それぞれを順次コンパイルし、前記命令それぞれのオ
ブジェクトコードを生成するオブジェクトコード生成手
段と、前記レジスタ数の増減を示す数値に基づいて、次
にコンパイルされる可能性がある前記命令それぞれが実
行されるときに占有される前記プロセッサのレジスタの
数を示す占有レジスタ数を計算する占有レジスタ数計算
手段と、計算された前記開放レジスタ数、および、前記
命令のオブジェクトコードが実行されるタイミングに基
づいて、次にコンパイルされる可能性がある前記命令に
優先順位を付与する優先順位付与手段とを有する。
Preferably, the compiling means sequentially compiles each of the instructions according to the order of execution of the instructions in the converted source code and in accordance with the priority given to the instructions, and Object code generation means for generating an object code, and the number of registers of the processor occupied when each of the instructions which may be compiled next is executed based on a numerical value indicating increase or decrease of the number of registers Occupied register number calculation means for calculating the number of occupied registers indicating the number of open registers, and the instruction that may be compiled next based on the calculated number of open registers and the timing at which the object code of the instruction is executed And a priority assigning means for assigning a priority.

【0010】好適には、前記優先順位付与手段は、計算
された前記占有レジスタ数と所定の閾値とを比較し、前
記計算される占有レジスタ数が所定の閾値より多い場合
には、前記計算される占有レジスタ数をより少なく増や
すか、減らす命令に高い優先順位を付し、これ以外の場
合には、クリティカルパスにある命令に高い優先順位を
付す。
[0010] Preferably, the priority assigning means compares the calculated number of occupied registers with a predetermined threshold value, and when the calculated occupied register number is larger than a predetermined threshold value, Instructions that increase or decrease the number of occupied registers are given higher priority, and otherwise, instructions on the critical path are given higher priority.

【0011】好適には、前記コンパイル手段は、前記命
令における共通部分式を削除してからオブジェクトコー
ドの生成を行うように構成されており、前記計算される
占有レジスタ数が前記所定の閾値よりも多い場合に、前
記削除された共通部分式を元に戻す逆変換を行う逆変換
手段をさらに有する。
Preferably, the compiling means is configured to generate an object code after deleting a common subexpression in the instruction, and the calculated occupied register number is smaller than the predetermined threshold value. In a case where the number of the common sub-expressions is large, an inverse transform unit for performing an inverse transform for restoring the deleted common subexpression is further provided.

【0012】好適には、前記プロセッサのレジスタの用
途を制約する所定の制約条件に基づいて、前記レジスタ
の割り付けを行うデータ割付手段をさらに有する。
Preferably, the apparatus further comprises data allocating means for allocating the register based on a predetermined constraint condition which restricts a use of a register of the processor.

【0013】[コンパイル装置の作用]本発明にかかる
コンパイラ装置は、演算子・命令の依存DAG(directe
d acyclic graph)で表されたプログラムから、レジスタ
使用数とハードウェアの実行サイクル数を評価しながら
コード生成を行い、コードスケジューリング最適化や共
通部分式削除の適用範囲と物理レジスタ数の制約との間
のトレードオフを最適化するように構成されている。
[Operation of Compiler] The compiler according to the present invention provides an operator / instruction dependent DAG (directe
d acyclic graph), the code is generated while evaluating the number of registers used and the number of hardware execution cycles, and the application range of code scheduling optimization and common subexpression elimination and the restriction on the number of physical registers It is configured to optimize the trade-off between.

【0014】本発明にかかるコンパイラ装置は、DAG
上で各演算の実行可能なサイクル数を計算し、DAGか
らのコード生成を行う際に、現在使用可能なレジスタ数
を計算する。レジスタ数に余裕がある部分では、DAG
の中で最も時間のかかる実行パス上の演算子を優先して
コード生成を行い、レジスタ使用数を増やしてハードウ
ェアのパイプライン充填率が高くなるようなコード生成
を行う。使用可能なレジスタ数が少ない部分では、使用
レジスタ数を減らすような演算子を優先してコード生成
を行い、余分なスピルコードが発生しないようにする。
また、コード生成中にDAG上で共通部分式削除の逆変
換を行うことで、最適化によって無駄なスピルコードが
発生することを避ける。
[0014] The compiler device according to the present invention comprises a DAG
The number of executable cycles of each operation is calculated above, and the number of registers that can be currently used when code is generated from the DAG is calculated. In areas where there is room for registers, DAG
, The code generation is performed with priority given to the operator on the execution path which takes the longest time, and the code generation is performed such that the pipeline filling rate of hardware is increased by increasing the number of registers used. In a part where the number of registers that can be used is small, code generation is performed with priority given to an operator that reduces the number of registers used, so that unnecessary spill code is not generated.
In addition, by performing the inverse conversion of the common subexpression deletion on the DAG during the code generation, it is possible to avoid the generation of useless spill codes due to the optimization.

【0015】[コンパイル方法]また、本発明にかかる
コンパイル方法は、プログラムのソースコードをDAG
形式に変換する変換ステップと、前記変換されたソース
コードに含まれる命令それぞれに対応するオブジェクト
コードを、所定数のレジスタを用いて実行するプロセッ
サのパラメータを計算するパラメータ計算ステップと、
前記変換されたソースコードを走査し、計算された前記
プロセッサのパラメータに基づいて、前記ソースコード
をコンパイルしてオブジェクトコードを生成するコンパ
イルステップとを含むコンパイル方法であって、前記パ
ラメータ計算ステップにおいて、前記命令それぞれに対
応するオブジェクトコードが、前記プロセッサにより実
行されるタイミングを計算し、前記命令それぞれに対応
するオブジェクトコードが実行されるときに占有される
前記プロセッサのレジスタ数の増減を示す数値を計算す
る。
[Compile method] The compile method according to the present invention provides a compile method in which a program
A conversion step of converting to a format, an object code corresponding to each of the instructions included in the converted source code, a parameter calculation step of calculating a parameter of a processor that executes using a predetermined number of registers,
Scanning the converted source code and, based on the calculated parameters of the processor, compiling the source code to generate an object code. Calculate the timing at which the object code corresponding to each of the instructions is executed by the processor, and calculate a numerical value indicating an increase or decrease in the number of registers of the processor occupied when the object code corresponding to each of the instructions is executed. I do.

【0016】[媒体]また、本発明にかかる媒体は、プ
ログラムのソースコードをDAG形式に変換する変換ス
テップと、前記変換されたソースコードに含まれる命令
それぞれに対応するオブジェクトコードを、所定数のレ
ジスタを用いて実行するプロセッサのパラメータを計算
するパラメータ計算ステップと、前記変換されたソース
コードを走査し、計算された前記プロセッサのパラメー
タに基づいて、前記ソースコードをコンパイルしてオブ
ジェクトコードを生成するコンパイルステップとをコン
ピュータに実行させるプログラムであって、前記パラメ
ータ計算ステップにおいて、前記命令それぞれに対応す
るオブジェクトコードが、前記プロセッサにより実行さ
れるタイミングを計算する処理と、前記命令それぞれに
対応するオブジェクトコードが実行されるときに占有さ
れる前記プロセッサのレジスタ数の増減を示す数値を計
算する処理とをコンピュータに実行させるプログラムを
媒介する。
[Medium] Further, a medium according to the present invention includes a conversion step of converting a source code of a program into a DAG format, and converting a predetermined number of object codes corresponding to instructions included in the converted source code into a predetermined number. A parameter calculating step of calculating a parameter of a processor to be executed using a register; scanning the converted source code; and compiling the source code based on the calculated parameter of the processor to generate an object code. A program for causing a computer to execute a compiling step, wherein in the parameter calculating step, an object code corresponding to each of the instructions calculates a timing to be executed by the processor; and an object code corresponding to each of the instructions. Mediating program for executing a process of calculating a numerical value indicating the register number of increase or decrease of the processor in the computer occupied when the Tokodo is executed.

【0017】[0017]

【発明の実施の形態】[第1実施形態]以下、本発明の
第1実施形態を説明する。
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS [First Embodiment] A first embodiment of the present invention will be described below.

【0018】[第1の実施形態として示すコンパイラの
概要]本発明に係るコンパイラは、まず、DAG(direc
ted acyclic graph)に含まれる演算それぞれを実行する
ために必要なプロセッサの実行サイクル数を計算し、さ
らに、DAGに含まれる演算それぞれから、オブジェク
トコードを生成するのと同時に、演算それぞれのために
使用するレジスタ数を計算する。
[Summary of Compiler Shown as First Embodiment] A compiler according to the present invention first uses a DAG (direc
Calculates the number of execution cycles of the processor required to execute each operation included in the ted acyclic graph), generates object code from each operation included in the DAG, and uses it for each operation. Calculate the number of registers to perform.

【0019】[コード生成]さらに、上述のように得ら
れたオブジェクトコード実行に必要とされるレジスタの
数が少なく、レジスタの数に余裕がある場合は、本発明
に係るコンパイラは、演算に要する実行時間が長ければ
長いほど処理が行われる順番の優先順位を高くしてDA
G中の演算に対応したオブジェクトコードを生成し、オ
ブジェクトコードを実行するプロセッサのレジスタ使用
数を増やし、かつ、プロセッサのパイプライン充填率を
高くするように最適化を行う。
[Code Generation] Further, when the number of registers required for executing the object code obtained as described above is small and the number of registers has a margin, the compiler according to the present invention requires the operation. The longer the execution time, the higher the priority of the order in which the processing is performed
An object code corresponding to the operation in G is generated, the number of registers used by the processor executing the object code is increased, and optimization is performed to increase the pipeline filling rate of the processor.

【0020】反対に、レジスタの数に余裕がない場合
は、本発明に係るコンパイラは、演算に必要とされるレ
ジスタ数が少なければ少ないほど処理が行われる順番の
優先順位を高くしてDAG中の演算に対応したオブジェ
クトコードを生成して、レジスタの内容がメモリに待避
されるコード(スピルコード)の発生量を少なくし、さ
らに、オブジェクトコード生成の際に、すでに行われた
共通部分式削除の最適化を取り消してコード生成するこ
とにより、無駄なスピルコードが発生しないようにす
る。
Conversely, if the number of registers is not large enough, the compiler according to the present invention increases the priority of the order in which the processing is performed as the number of registers required for the operation is smaller, and sets the priority in the DAG. Generates object code corresponding to the operation of (1), reduces the amount of code (spill code) that saves register contents in memory, and deletes common sub-expressions already generated at the time of object code generation. By canceling the optimization of and generating code, useless spill code is not generated.

【0021】このようなオブジェクトコードの最適化の
ために、本発明に係るコンパイラは、DAGからオブジ
ェクトコードを生成する際に、演算子のレジスタ使用数
と、実行開始が可能なサイクル数を評価してコードの生
成順を決定し、オブジェクトコードを生成する際に、コ
ード生成中に刻々と変化するレジスタの使用数に基づい
て、コード生成方針の変更、すなわち使用レジスタ数を
多くしてパイプライン重点率を高くする方針から使用レ
ジスタ数を少なくしてスピルコードを最小にする方針へ
の変更や共通部分式削除の最適化の取り消しを動的に行
い、ハードウェアの制約と、オブジェクトコードの効率
化とをトレードオフする。
For such optimization of the object code, the compiler according to the present invention evaluates the number of registers used by the operator and the number of cycles at which execution can be started when generating the object code from the DAG. When generating the object code, the code generation policy is changed based on the number of registers that change every time the code is generated. Dynamically changing from a policy of increasing the ratio to a policy of minimizing spill code by reducing the number of registers used and optimizing the elimination of common sub-expressions, restricting hardware and increasing the efficiency of object code And trade off.

【0022】このようにして、本発明に係るコンパイラ
は、オブジェクトコードを最適化する範囲を、DAGに
含まれる演算の内、オブジェクトコードの実行が、プロ
セッサの物理的レジスタ数、つまり、ハードウェア的な
制約を受けない演算のみに限定する。さらに、本発明に
係るコンパイラ方法の処理を、レジスタアロケーション
処理およびコードスケジューリング処理に前置すると、
オブジェクトコードの最適化のためには、これら2つの
処理を協調動作させなければならないような部分の制約
を緩和することができるので、レジスタアロケーション
処理とコードスケジューリング処理とを、分離した処理
パスとして実装しても、オブジェクトコードを最適化す
ることができる。
As described above, the compiler according to the present invention determines the range of optimizing the object code as the number of physical registers of the processor, that is, the number of physical registers of the processor, among the operations included in the DAG. Limited to operations that are not subject to any restrictions. Further, when the processing of the compiler method according to the present invention is prepended to the register allocation processing and the code scheduling processing,
In order to optimize the object code, it is possible to alleviate the restriction on the part where these two processes must cooperate, so that the register allocation process and the code scheduling process are implemented as separate processing paths. Even so, the object code can be optimized.

【0023】[第1の実施形態として示すコンパイラの
実現方法]本発明に係るコンパイラは、これまでに述べ
たオブジェクトコードの最適化のために、以下の3つの
ステップを含んでいる。
[Method of Implementing Compiler Shown as First Embodiment] The compiler according to the present invention includes the following three steps for optimizing the object code described above.

【0024】[第1のステップ]第1のステップにおい
て、本発明に係るコンパイラは、ソースコードを、演算
子のデータ依存と副作用の依存を表すDAGの形式で表
現する。
[First Step] In the first step, the compiler according to the present invention expresses the source code in a DAG format representing the dependence of the operator on the data and the dependence on the side effect.

【0025】[第2のステップ]第2のステップにおい
て、本発明に係るコンパイラは、ソースコードを表現す
るDAGの各頂点について、サイクル数や使用レジスタ
数の増減など、コード生成で使用されるハードウェアの
パラメータを計算する。
[Second Step] In the second step, the compiler according to the present invention uses hardware used for code generation, such as increasing or decreasing the number of cycles or the number of registers used, for each vertex of the DAG representing the source code. Calculate wear parameters.

【0026】[第3のステップ]第3のステップにおい
て、本発明に係るコンパイラは、上述の「コード生成」
に示したように、DAGを走査して、使用レジスタ数、
実行サイクルを考慮したコード生成を行い、最適化され
たオブジェクトコード列を得る。この第3のステップ
で、本発明に係るコンパイラは、コード生成中の使用レ
ジスタ数を計算しながら、オブジェクトコードを生成
し、そのときの使用レジスタ数が、例えば実験や経験に
より求められる所定値(閾値)以下になったときは、そ
れ以後のオブジェクトコード生成の方針の変更、すなわ
ち使用レジスタ数を多くしてパイプライン重点率を高く
する方針から使用レジスタ数を少なくしてスピルコード
を最小にする方針への変更を行い、必要に応じて共通部
分式削除の取り消しを行う。
[Third Step] In the third step, the compiler according to the present invention executes the above-described "code generation".
As shown in, the DAG is scanned to find the number of registers used,
A code is generated in consideration of an execution cycle to obtain an optimized object code sequence. In the third step, the compiler according to the present invention generates an object code while calculating the number of used registers during code generation, and determines the number of used registers at that time by a predetermined value (for example, an experiment or experience). When the number of registers used becomes smaller than the threshold, the number of used registers is reduced to minimize the spill code by changing the object code generation policy thereafter, that is, by increasing the number of registers used and increasing the pipeline priority ratio. Make changes to the policy and undo common subexpression elimination as needed.

【0027】なお、本発明に係るコンパイラは、後述す
るように、実際には、使用されていないレジスタ数、つ
まり、オブジェクトコードの実行のために占有されてい
ないレジスタ数を計算するが、使用レジスタ数と占有さ
れていないレジスタ数とは等価であり、表現の差異に過
ぎない。
As will be described later, the compiler according to the present invention calculates the number of registers that are not actually used, that is, the number of registers that are not occupied for executing the object code. The number and the number of unoccupied registers are equivalent and are merely differences in representation.

【0028】[第1〜第3のステップの詳細]以下、上
述した本発明に係るコンパイラの第1〜第3のステップ
の処理内容を詳細に説明する。
[Details of First to Third Steps] Hereinafter, the processing contents of the first to third steps of the compiler according to the present invention will be described in detail.

【0029】[第1のステップの詳細]図1は、DAG
を例示する図である。下表1に例示するように、ループ
を含むソースプログラムからは、図1に示す依存DAG
(DAGは、図1の頂点と矢印の集合として定義され
る)が得られる。
[Details of First Step] FIG.
FIG. As exemplified in Table 1 below, a source program including a loop is supplied with the dependency DAG shown in FIG.
(DAG is defined as the set of vertices and arrows in FIG. 1).

【0030】[0030]

【表1】 [Table 1]

【0031】まず、上述のように、本発明に係るコンパ
イラは、以下のように、ソースコード(プログラム:表
1)を、オブジェクトコード生成処理の対象となるDA
G(図1)の形式で表現する。本発明に係るコンパイラ
は、プログラム中の演算子(+,*,LOAD)を頂点
v∈V(図1の白ぬきの丸のそれぞれ)、また、演算
子の間のデータの定義と使用の依存関係および演算が引
き越す副作用(たとえば、例外の発生およびメインメモ
リへの書き込み)がプログラムに記載された通りに発動
することを保証するための依存関係を、頂点間を接続す
る有向辺e=(v、w)∈E(図1の矢印のそれぞれ)
と表し、ループによる依存を無視して、プログラムを、
閉路のない有向グラフ(DAG)G=(V,E)と表
す。この有向辺eの方向は、各頂点(命令または演算
子)のデータ依存関係を示すとともに、DAGに含まれ
る各頂点それぞれから生成されたオブジェクトコードの
実行順序をも示している。
First, as described above, the compiler according to the present invention converts a source code (program: Table 1) into a DA code to be subjected to object code generation processing as follows.
Expressed in the form of G (FIG. 1). The compiler according to the present invention defines the operators (+, *, LOAD) in the program as vertices v∈V (each of the white circles in FIG. 1), and also depends on the definition and use of data between the operators. The dependencies to ensure that the relations and operations carry over (e.g., exceptions and writes to main memory) are triggered as described in the program, and the directed edge e = (V, w) ∈E (each arrow in FIG. 1)
And ignore the loop dependency,
A directed graph (DAG) without a cycle is represented by G = (V, E). The direction of the directed side e indicates the data dependency of each vertex (instruction or operator), and also indicates the execution order of the object code generated from each vertex included in the DAG.

【0032】さらに、本発明に係るコンパイラは、ある
頂点を指す有向辺の源となる頂点(先行する頂点)を持
たない頂点全てに先行する仮想的な頂点トップ┬と、あ
る頂点を指す有向辺の先となる頂点(後継する頂点)を
持たない全ての頂点に後継する仮想的な頂点ボトム┴と
を、有向グラフ(DAG)G=(V,E)に追加する。
なお、データ依存をあらわす有向辺(図1の実線の矢
印)は、演算子が先行する頂点の演算結果を参照すると
きに、プロセッサのレジスタを使うことを表し、各頂点
vには、演算を実行するために必要なマシンサイクル
数 cy(v)が割り当てられており、本発明に係るコ
ンパイラは、これらの情報を、実行サイクルを考慮した
コード生成を行うために使用する。
Further, the compiler according to the present invention provides a virtual vertex top that precedes all vertices that do not have a vertex (preceding vertex) that is a source of a directed edge indicating a certain vertex, and a vertex that indicates a certain vertex. A virtual vertex bottom ┴ to be added to all vertices that do not have vertices (succeeding vertices) preceding the opposite side is added to the directed graph (DAG) G = (V, E).
Note that a directed edge (solid arrow in FIG. 1) indicating data dependence indicates that the operator uses the processor register when referring to the operation result of the preceding vertex. Are assigned the number of machine cycles cy (v) required to execute the above, and the compiler according to the present invention uses these pieces of information to generate a code in consideration of the execution cycle.

【0033】[第2のステップの詳細]次に、本発明に
係るコンパイラは、図1に示したDAGの各頂点につい
て、コード生成で使用されるパラメータを計算する。グ
ラフ構造から数値化できるパラメータで、コードスケジ
ューリングによる最適化のための情報は、トップからの
深さ、ボトムからの深さおよびスラックネス(slacknes
s)である。使用レジスタ数についての情報は頂点の参
照数に反映される。ある頂点vのトップからの深さlt
(v)、ボトムからの深さlb(v)、スラックネスs
l(v)および参照数(参照数の増加Δref(v))
の意味は、それぞれ以下に示す通りである。
[Details of Second Step] Next, the compiler according to the present invention calculates, for each vertex of the DAG shown in FIG. 1, parameters used in code generation. Parameters that can be quantified from the graph structure. Information for optimization by code scheduling includes depth from the top, depth from the bottom, and slackness (slacknes).
s). Information on the number of used registers is reflected in the number of reference vertices. The depth lt from the top of a vertex v
(V), depth lb (v) from bottom, slackness s
l (v) and number of references (increase in number of references Δref (v))
Has the following meanings.

【0034】[トップからの深さ]図1に示した有向グ
ラフ(DAG)G=(V,E)において、ある頂点vの
トップからの深さとは、トップ┬から、有向辺を辿って
その頂点vにたどり着くまでに通る各頂点のマシンサイ
クルの累加算値の最大値として定義される。言い換える
と、トップからの深さとは、DAGで表されたプログラ
ムから生成されたオブジェクトコードを実行するプロセ
ッサ(ターゲットアーキテクチャ)が、先頭のオブジェ
クトコードの実行を開始ししてから、最大、ターゲット
アーキテクチャのマシンサイクルの何サイクル後に、そ
の頂点vの演算子に対応するオブジェクトコードを実行
するかを示す。
[Depth from Top] In the directed graph (DAG) G = (V, E) shown in FIG. 1, the depth from the top of a vertex v is determined by tracing the directed edge from the top ┬. It is defined as the maximum value of the cumulative addition value of the machine cycle of each vertex that passes before reaching the vertex v. In other words, the depth from the top refers to the maximum of the target architecture after the processor (target architecture) that executes the object code generated from the program represented by the DAG starts executing the top object code. The number of machine cycles after which the object code corresponding to the operator at the vertex v is executed.

【0035】DAG(図1)を、トップ┬から、深さ優
先探索(reverse post-order)により走査した場合に
は、ある頂点vを走査する前に、必ず、その頂点vに先
行する全ての頂点が走査される。従って、ある頂点v
のトップからの深さlt(v)は、トップ┬に近い頂点
vから順に、以下の手続1−1,1−2により計算する
ことができる。
When the DAG (FIG. 1) is scanned from the top ┬ by the depth-first search (reverse post-order), before scanning a certain vertex v, all the preceding vertices v must be read. Vertices are scanned. Therefore, a vertex v
Can be calculated in order from the vertex v close to the top に よ り by the following procedures 1-1 and 1-2.

【0036】手続1−1:ある頂点vに、先行する頂点
がない場合には、その頂点vのトップからの深さlt
(v)=0。 手続1−2:ある頂点vに、先行する頂点がある場合
は、その頂点vのトップからの深さlt(v)は、頂点
v に先行する頂点を頂点pとして、lt(v)=まx
(lt(p)+cy(p))。
Procedure 1-1: If a certain vertex v has no preceding vertex, the depth lt from the top of the vertex v
(V) = 0. Procedure 1-2: If a vertex v has a preceding vertex, the depth lt (v) from the top of the vertex v is represented by lt (v) = matrix with the vertex preceding the vertex v as the vertex p. x
(Lt (p) + cy (p)).

【0037】[ボトムからの深さ]ある頂点vのボトム
からの深さlb(v)とは、ボトム┴から、DAG(図
1)の有向辺を逆向きに辿って、その頂点vにたどり着
くまでに通る頂点のマシンサイクルの和の最大値として
定義される。つまり、ボトムからの深さlb(v)は、
DAGで表されたプログラムから生成されたオブジェク
トコードをターゲットアーキテクチャで実行するとき、
すべてのオブジェクトコードの実行の終了時点から、最
大、何サイクル前にその頂点vの演算子に対応するオブ
ジェクトコードの実行が開始されているかを示す。
[Depth from the Bottom] The depth lb (v) from the bottom of a certain vertex v is defined as the direction from the bottom ┴ to the directed side of the DAG (FIG. 1) in the opposite direction. It is defined as the maximum sum of the machine cycles of the vertices to be reached before reaching. That is, the depth lb (v) from the bottom is
When executing object code generated from a program represented by DAG on a target architecture,
It indicates how many cycles before the execution of the object code corresponding to the operator of the vertex v has been started from the end of execution of all the object codes.

【0038】頂点vのボトムからの深さlb(v)は、
トップからの深さlt(v)と同様に、有向辺を逆向き
にしたDAGをボトムから深さ優先探索(reverse post
-order)で走査して計算することができる。ボトムから
の深さlb(v)は、ボトム┴に近い頂点vから順に、
以下の手続2−1,2−2で計算することができる。
The depth lb (v) of the vertex v from the bottom is
Similar to the depth lt (v) from the top, a DAG with the directed side reversed is depth-first search from the bottom (reverse post
-order). The depth lb (v) from the bottom is, in order from the vertex v near the bottom ┴,
It can be calculated by the following procedures 2-1 and 2-2.

【0039】手続2−1:ある頂点vが後継する頂点を
有さない場合にはlb(v)=0。手続2−2:ある頂
点vが後継する頂点sを有する場合には、ボトムからの
深さlb(v)=max(lb(s))+sy(s)。
Procedure 2-1: If a vertex v has no successor vertex, lb (v) = 0. Procedure 2-2: If a vertex v has a successor vertex s, the depth lb (v) from the bottom = max (lb (s)) + sy (s).

【0040】[スラックネス]DAG(図1)のトップ
┴から、ボトムへの深さをDAGのクリティカルパス長
と呼ぶ。つまり、クリティカルパス長は、DAGで表さ
れたプログラム全体を実行し終わるのに、最小、何サイ
クルかかるかを表している。クリティカルパス長をcp
(G)とすると、各頂点vのスラックネスsl(v)
は、sl(v)=cp(G)−lt(v)−lb(v)
と定義される。つまり、スラックネスsl(v)は、オ
ブジェクトコードを生成するときの余裕を表している。
スラックネスsl(v)=0の頂点vは、トップ┬か
ら、その頂点vを通ってボトムに至るまで、最も多くの
有向辺を経由するパス(クリティカルパス)上にある。
[Slackness] The depth from the top to the bottom of the DAG (FIG. 1) is called the critical path length of the DAG. In other words, the critical path length indicates the minimum number of cycles it takes to execute the entire program represented by DAG. Critical path length is cp
(G), the slackness sl (v) of each vertex v
Is sl (v) = cp (G) -lt (v) -lb (v)
Is defined as That is, the slackness sl (v) represents a margin when the object code is generated.
The vertex v with slackness sl (v) = 0 is on the path (critical path) passing through the most directional edges from the top ┬ to the bottom through the vertex v.

【0041】スラックネスsl(v)が大きい頂点v
は、スラックネスsl(v’)がsl(v)よりも小さ
い頂点v’よりも優先順位を下げてオブジェクトコード
生成を後回しにしても、優先順位を下げたことを理由と
して、その頂点vに依存する他の頂点のオブジェクトコ
ード生成が遅れる可能性が低いことを表している。
Vertex v having large slackness sl (v)
Depends on the vertex v because slackness sl (v ') is lower in priority than vertex v' smaller than sl (v), and object code generation is postponed. It is unlikely that the generation of object codes for other vertices will be delayed.

【0042】[参照数の増加]参照数の増加Δref
(v)は、その頂点vに対応するオブジェクトコードの
実行を開始する際に使用状態が終了し、新たな使用のた
めに解放することができるレジスタの数と、新たに必要
になるレジスタの数を見積もるために用いられる。頂点
vの参照数の増加 Δref(v)は、その頂点vに後
継する有向辺の数から、その頂点vに先行する有向辺の
数を引いたものである。頂点vの参照数の増加Δref
(v)の値が負であるということは、先行する頂点に対
応するオブジェクトコードの実行のために用いられてい
たレジスタの使用状態が終了する可能性が高いことを示
す。反対に、頂点vの参照数の増加Δref(v)の値
が正であるということは、先行する頂点に対応するオブ
ジェクトコードの実行のために用いられていなかったレ
ジスタを、さらに使用する可能性が高いことを示す。
[Increase in the number of references] Increase in the number of references Δref
(V) indicates the number of registers that have been used when the execution of the object code corresponding to the vertex v is started and can be released for new use, and the number of registers newly required. Is used to estimate The increase in the reference number of the vertex v Δref (v) is obtained by subtracting the number of the directed sides preceding the vertex v from the number of the directed sides succeeding the vertex v. Increase in reference number of vertex v Δref
The fact that the value of (v) is negative indicates that the use state of the register used for executing the object code corresponding to the preceding vertex is likely to end. Conversely, a positive value of the increase in the reference number Δref (v) of the vertex v means that the register that has not been used for executing the object code corresponding to the preceding vertex may be further used. Is higher.

【0043】[第3のステップの詳細]第3のステップ
において、本発明に係るコンパイラは、上述した第2の
ステップにおいて計算したパラメータ(lt(v),l
b(v),sl(v),Δref(v))を使って、D
AG(図1)トップ┬から順に各頂点を走査して、オブ
ジェクトコードの生成を行う。
[Details of Third Step] In the third step, the compiler according to the present invention uses the parameters (lt (v), l) calculated in the above-described second step.
b (v), sl (v), Δref (v)) to obtain D
Each vertex is scanned in order from the top # of the AG (FIG. 1) to generate an object code.

【0044】[データ構造]このオブジェクトコード生
成中に、本発明に係るコンパイラは、実際の使用レジス
タ数を計算して、オブジェクトコード生成の方針を切り
替える。なお、本発明に係るコンパイラは、第3のステ
ップの実行のために以下の各データ/リストa(G),r
(G),u(G),reg,ap(v),au(v)を
用い、これらのデータ/リスト(データ構造)は、オブ
ジェクトコード生成処理の各時点における(現在の)オ
ブジェクトコード生成の状態を示す。
[Data Structure] During the generation of the object code, the compiler according to the present invention calculates the actual number of registers used and switches the object code generation policy. Note that the compiler according to the present invention executes the following data / lists a (G), r for executing the third step.
(G), u (G), reg, ap (v), au (v) are used, and these data / lists (data structures) are used for the (current) object code generation at each point in the object code generation process. Indicates the status.

【0045】a(G):既にオブジェクトコードが生成
された頂点の列、 r(G):次にオブジェクトコードを生成することがで
きる頂点の列、 u(G):未だオブジェクトコードが生成されていない
頂点の集合、 reg :現在使用可能なターゲットアーキテクチャの
物理レジスタの数。
A (G): a sequence of vertices for which an object code has already been generated, r (G): a sequence of vertices for which an object code can be generated next, u (G): an object code has yet to be generated Set of missing vertices, reg: number of physical registers of the target architecture currently available.

【0046】なお、オブジェクトコードの生成を開始す
る前の初期状態では、a(G)は空のリストであり、r
(G)はトップ┬だけを含むリストとなり、u(G)
は、トップ┬以外の全ての頂点を含む集合となり、re
gはターゲットアーキテクチャのレジスタのうち、DA
G(図1)から生成されるオブジェクトコードの実行に
使用できるレジスタの数となる。
In the initial state before the generation of the object code is started, a (G) is an empty list, and r (G) is an empty list.
(G) becomes a list containing only the top ┬, and u (G)
Is a set containing all vertices except top ┬, and re
g is DA of the registers of the target architecture.
This is the number of registers that can be used to execute the object code generated from G (FIG. 1).

【0047】また、以下のデータ構造は、まだオブジェ
クトコードの生成が終了していない各頂点の状態を表
す。
The following data structure indicates the state of each vertex for which the generation of the object code has not been completed.

【0048】ap(v):DAGにおいて頂点vに先行
する頂点であって、オブジェクトコードの生成が終了し
た頂点の数、 au(v):頂点vに対して有向辺を介して後継する頂
点であって、オブジェクトコードの生成が終了した頂点
の数。
Ap (v): the number of vertices preceding the vertex v in the DAG, for which the generation of the object code has been completed, and au (v): the vertex succeeding the vertex v via a directed edge. And the number of vertices for which object code generation has been completed.

【0049】ap(v)の初期値は、DAGにおいて、
頂点vに先行する有向辺の数であり、au(v)の初期
値は、頂点vに有向辺を介して後継する頂点の数とな
る。
The initial value of ap (v) is as follows in DAG:
This is the number of directed sides preceding vertex v, and the initial value of au (v) is the number of vertices succeeding vertex v via directed sides.

【0050】[オブジェクトコード生成アルゴリズム]
本発明に係るコンパイラは、以下の手続3−1〜3−8
により示されるアルゴリズムによりオブジェクトコード
を生成する。
[Object Code Generation Algorithm]
The compiler according to the present invention performs the following procedures 3-1 to 3-8.
The object code is generated by the algorithm indicated by.

【0051】手続3−1:r(G)の先頭の頂点vを取
り出し、a(G)の最後に加える。 手続3−2:頂点vに後継する各頂点s∈u(G)に対
応する有向辺について、ap(s)の値をap(s):
=ap(s)−1に更新する。 手続3−3:手続3−2において、ap(w)=0を与
える頂点wがあれば、r(G)に追加する。 手続3−4:4) 頂点vに先行する各頂点p∈a(G)
について、au(p)の値をau(p):=au(p)
−1に更新する。 手続3−5:regの値を、reg:=reg+Δre
g(v)に更新する。 手続3−6:r(G)の各頂点vについて、使用可能な
レジスタ数の増加Δreg(v)を算出する。 手続3−7:r(G)が空でなければ、優先順位に従っ
てr(G)の頂点を並び替え、手続3−1に戻る。つま
り、r(G)が空でなければ、現在使用可能なレジスタ
数が閾値より多いときには、下記の「使用可能レジスタ
数regが閾値thrより多い場合」に示すようにで与
えられる優先順位にしたがってr(G)の頂点を並べか
え、現在使用可能なレジスタ数が閾値より少ないときに
は、下記の「使用可能レジスタ数regが閾値thr以
下の場合」に示すように与えられる優先順位にしたがっ
てr(G)の頂点を並べ替え、手続き3−1に戻る。手
続3−8:r(G)が空ならば処理を終了する。
Procedure 3-1: The top vertex v of r (G) is extracted and added to the end of a (G). Procedure 3-2: For the directed side corresponding to each vertex s∈u (G) succeeding vertex v, change the value of ap (s) to ap (s):
= Ap (s) -1. Procedure 3-3: In procedure 3-2, if there is a vertex w that gives ap (w) = 0, it is added to r (G). Procedure 3-4: 4) Each vertex p @ a (G) preceding vertex v
, The value of au (p) is given by au (p): = au (p)
Update to -1. Procedure 3-5: Change reg value to reg: = reg + Δre
Update to g (v). Procedure 3-6: For each vertex v of r (G), calculate an increase Δreg (v) in the number of available registers. Procedure 3-7: If r (G) is not empty, rearrange the vertices of r (G) according to the priority and return to procedure 3-1. In other words, if r (G) is not empty and the number of currently available registers is larger than the threshold, according to the priority given by the following "when the number of available registers reg is larger than the threshold thr", The vertices of r (G) are rearranged, and when the number of registers currently available is smaller than the threshold, r (G) is given according to the priority given as shown in the following “when the number of available registers reg is less than or equal to the threshold thr” Are rearranged, and the procedure returns to the procedure 3-1. Procedure 3-8: If r (G) is empty, end the process.

【0052】なお、上記手続3−5および手続3−6に
おいて使用される値Δreg(v)は、ターゲットアー
キテクチャが、DAG(図1)の頂点vに対応するオブ
ジェクトコードを実行する場合に、その時点で(現在)
使用可能になるターゲットアーキテクチャのレジスタ数
を示す。換言すると、値Δreg(v)は、頂点(v)
のオブジェクトコードが実行された時点で増加する使用
可能なレジスタの数を示す。
It should be noted that the value Δreg (v) used in the above procedures 3-5 and 3-6 is obtained when the target architecture executes the object code corresponding to the vertex v of the DAG (FIG. 1). At the moment (current)
Indicates the number of registers of the target architecture that can be used. In other words, the value Δreg (v) is
Shows the number of available registers which increases when the object code of the above is executed.

【0053】値Δreg(v)は、Δreg(v)=
(頂点vのオブジェクトコードの実行により解放される
レジスタの数)−(頂点vのオブジェクトコードの実行
のために確保されるレジスタの数)として定義され、頂
点vのオブジェクトコードの実行により解放されるレジ
スタの数は、頂点vに先行する各頂点pのうち、au
(p)=1を与える頂点の数として定義され、頂点vの
オブジェクトコードの実行のために確保されるレジスタ
(頂点vの演算子が生成する値を格納するために必要な
レジスタ)の数は、頂点vが値をレジスタに生成する場
合は1、そうでなければ0である。
The value Δreg (v) is given by Δreg (v) =
(The number of registers released by the execution of the object code of the vertex v) − (the number of registers reserved for the execution of the object code of the vertex v) and is released by the execution of the object code of the vertex v The number of registers is au of each vertex p preceding vertex v.
(P) = 1 is defined as the number of vertices giving 1, and the number of registers (registers required to store the value generated by the operator of vertex v) reserved for execution of the object code of vertex v is , 1 if vertex v produces a value in the register, 0 otherwise.

【0054】また、上記手続3−7において、現在使用
可能なレジスタ数regが、一定の閾値thrより大き
いか否かにより、r(G)に含まれる頂点を整列する方
針を変更する。これにより、ターゲットアーキテクチャ
の物理レジスタ数の制約によって、オブジェクトコード
生成の方針を動的に切り替えることができる。
In the above procedure 3-7, the policy for aligning the vertices included in r (G) is changed depending on whether or not the currently available register number reg is larger than a predetermined threshold thr. Thereby, the policy of object code generation can be dynamically switched according to the restriction on the number of physical registers of the target architecture.

【0055】[使用可能レジスタ数regが閾値thr
より多い場合]優先順位が高い方から順番にオブジェク
トコードの生成を行うために、DAG(図1)に含まれ
る頂点それぞれに対して優先順位を与える。使用可能な
レジスタ数が閾値より多い場合(reg>thr)、本
発明に係るコンパイラは、現在使用可能なレジスタの数
と閾値との代償関係に応じて、優先順位を、以下の規則
a,bに従って与える。
[The number of available registers reg is equal to the threshold thr
In the case of more than one) In order to generate object codes in order from the highest priority, a priority is given to each vertex included in the DAG (FIG. 1). When the number of available registers is larger than the threshold value (reg> thr), the compiler according to the present invention determines the priority according to the following rules a and b according to the compensation relation between the number of currently available registers and the threshold value. Give according to.

【0056】規則a:スラックネスの小さい方の頂点の
優先順位を高くする。 規則b:スラックネスが同じ場合は、トップからの深さ
が小さいほうの頂点の優先順位を高くする。
Rule a: Increase the priority of the vertex with the smaller slackness. Rule b: When the slackness is the same, the priority of the vertex having the smaller depth from the top is set higher.

【0057】つまり、使用可能なレジスタ数が閾値より
多い(reg>thr)ということは、使用可能なレジ
スタが充分にあり、数に余裕があるので、DAGにおけ
るクリティカルパス上にある頂点に高い優先順位を付
し、多くのレジスタを使用して、コードスケジューリン
グによる最適化を行って演算器の遅延を隠蔽できるよう
に、オブジェクトコード生成を行う。
In other words, the fact that the number of available registers is larger than the threshold value (reg> thr) means that there are sufficient available registers and there is room in the number, so that a vertex on the critical path in the DAG has a higher priority. An object code is generated by assigning a rank and optimizing by code scheduling by using many registers to conceal a delay of a computing unit.

【0058】[使用可能なレジスタ数regが閾値th
r以下の場合]使用可能なレジスタ数が閾値以下の場合
(reg≦thr)、本発明に係るコンパイラは、優先
順位を、以下の規則c〜eに従って与える。
[The number of available registers reg is equal to the threshold th
When the number of available registers is equal to or less than the threshold (reg ≦ thr), the compiler according to the present invention assigns priorities according to the following rules c to e.

【0059】規則c:Δreg(v)が大きい頂点の優
先順位を高くする。 規則d:Δreg(v)が同じ頂点同士では、Δref
(v)が小さい頂点の優先順位を高くする。 規則e:規則c,dにより優先順位が決まらない場合
は、レジスタ数が閾値より大きい場合と同様に、スラッ
クネスとトップからの深さを使って優先順位を決める。
Rule c: The priority of a vertex having a large Δreg (v) is set higher. Rule d: For vertices having the same Δreg (v), Δref
The priority of a vertex with a small (v) is increased. Rule e: If the priority is not determined by rules c and d, the priority is determined using slackness and depth from the top, as in the case where the number of registers is larger than the threshold.

【0060】使用可能なレジスタ数が閾値以下(reg
≦thr)ということは、使用可能なレジスタ数が少な
く、余裕がないことを示し、なるべくレジスタを多く解
放し、新しく確保しないような頂点の優先順位を高くし
て、より早い順番でオブジェクトコードを生成する。つ
まり、使用可能なレジスタ数regを増やす頂点や、値
が多くの頂点に参照されないような頂点の優先順位を高
くしてオブジェクトコードの生成を行う。
The number of available registers is equal to or smaller than the threshold (reg)
≤ thr) indicates that the number of available registers is small and that there is no room, the registers are released as much as possible, the priority of vertices that are not newly secured is increased, and the object code is Generate. That is, the object code is generated by increasing the priority of a vertex that increases the number of available registers reg or a vertex whose value is not referred to by many vertices.

【0061】なお、このような優先順位の付与のために
は、r(G)の中から、次に生成すべき頂点によるレジ
スタ数の増減を、一つだけ先読みするとよい。複数の頂
点の列に対して先読みを拡張してもよいが、検討すべき
組み合わせを増やすので、コンパイル時間と最適化の効
果とをトレードオフする必要がある。つまり、本発明に
係るコンパイラは、r(G)の中から次に生成すべき頂
点を選んだときのレジスタ数の増減を計算して優先順位
を決定している。アルゴリズムを、複数の頂点の列を順
に選んだときのレジスタ数の増減を計算するように拡張
すれば、より望ましい解が得られる可能性があるが、コ
ンパイル時間と最適化のトレードオフを考える必要があ
る。
In order to assign such priorities, it is preferable to pre-read only one increase / decrease in the number of registers due to the next vertex to be generated from r (G). Although look-ahead may be extended for a plurality of vertex columns, it is necessary to trade off compile time and optimization effect because the number of combinations to be considered is increased. That is, the compiler according to the present invention determines the priority by calculating the increase or decrease in the number of registers when the next vertex to be generated is selected from r (G). Extending the algorithm to calculate the increase or decrease in the number of registers when a sequence of vertices is selected in sequence may provide a more desirable solution, but it is necessary to consider the trade-off between compile time and optimization There is.

【0062】規則eにより優先順位を決める場合には、
使用可能なレジスタの数は、さらに少なくなる。このよ
うな場合、共通部分式削除の逆変換を行うと、使用可能
なレジスタ数regを増やすことができる。まだオブジ
ェクトコード生成されていない頂点はDAGで表されて
いるので、本発明に係るコンパイラは、DAGを変形し
て逆変換を行う。
When determining the priority order according to rule e,
The number of available registers is even smaller. In such a case, when the inverse transformation of common subexpression elimination is performed, the number of available registers reg can be increased. Since vertices for which object code has not been generated are represented by DAG, the compiler according to the present invention transforms DAG and performs inverse transformation.

【0063】[共通部分式削除の逆変換の手順]本発明
に係るコンパイラは、共通部分式削除の逆変換を、以下
の手続4−1〜4−3により行う。
[Inverse Conversion of Common Subexpression Deletion] The compiler according to the present invention performs the inverse conversion of common subexpression deletion according to the following procedures 4-1 to 4-3.

【0064】手続4−1:a(G)中の頂点pからr
(G)およびu(G)中の頂点vに対して張られている
有向辺e∈Eを探す。 手続4−2:手続4−1において見つかった有向辺e=
(p,v)に先行する頂点pの内、頂点pの演算を、そ
の時点でレジスタに格納されている値のみを使って計算
可能な頂点を探す。 手続4−3:先行する頂点pを複製して頂点p’を作り
(先行する頂点pと同じ演算子、同じ先行点、同じ後継
点を持つ頂点p’を生成し)、u(G)に加えることに
より、有向辺e=(p,v)に先行する頂点を変更して
e=(p,v)とする。なお、共通部分式削除は、DA
G上では、同じ値を生成する複数の頂点を一つの頂点で
表し、後継する頂点をその頂点へ依存させる変換であ
り、手続き4−1、4−3では、共通部分式削除の結果
一つの頂点で生成されていた値を、もう一度同じ値を生
成する頂点を作ることによって、複数の頂点で生成する
ことで、共通部分式削除の逆変換を行っている。
Procedure 4-1: From vertex p to r in a (G)
(G) and directed edge eεE stretched to vertex v in u (G). Procedure 4-2: directed side e = found in procedure 4-1
Among the vertices p preceding (p, v), a search is made for a vertex that can be calculated using only the value stored in the register at that time. Procedure 4-3: Duplicate the preceding vertex p to create a vertex p ′ (generate a vertex p ′ having the same operator, the same leading point, and the same successor as the preceding vertex p), and u (G) With this addition, the vertex preceding the directed side e = (p, v) is changed to e = (p, v). Note that common subexpression elimination is DA
On G, a plurality of vertices that generate the same value are represented by one vertex, and the succeeding vertex is dependent on the vertex. In procedures 4-1 and 4-3, one common vertex is deleted as a result. The inverse transformation of common subexpression elimination is performed by creating a vertex that generates the same value once again by generating a vertex that generates the same value at a plurality of vertices.

【0065】au(p)の値を、au(p):=au
(p)−1に更新し、au(p)の値が0になれば、使
用可能なレジスタ数regを1個増やすことができる。
regを1増やすことができる理由は、先行する頂点の
値を使用している頂点がすべてコード生成されたので、
先行する頂点値はこれ以降使用されない。したがって、
レジスタを一個解放することができるためである。つま
り、DAG上で共通部分式の削除を行うと、新しいデー
タ依存の辺が導入される。DAG上で共通部分式の削除
を行うと、先行する頂点の値が複数の後継する頂点に共
有される。値が参照されていることは、DAGの辺で表
現されるので、コンパイラが、DAGを変形してデータ
依存の辺を導入する。使用可能なレジスタ数が不足した
ときに、共通部分式削除で導入された辺を選び、上の手
続4−1〜4−3に従って逆変換を行うと、使用可能な
レジスタ数が足りない部分では共通部分式削除の最適化
がキャンセルされ、使用可能なレジスタ数に余裕がある
ような部分にだけ最適化を適用することができる。
The value of au (p) is expressed as au (p): = au
When the value is updated to (p) −1 and the value of au (p) becomes 0, the number of available registers reg can be increased by one.
The reason that reg can be increased by one is that all vertices using the value of the preceding vertex have been code generated,
The preceding vertex value is no longer used. Therefore,
This is because one register can be released. That is, when the common subexpression is deleted on the DAG, a new data-dependent edge is introduced. When the common subexpression is deleted on the DAG, the value of the preceding vertex is shared by a plurality of succeeding vertices. Since the fact that a value is referred to is represented by an edge of the DAG, the compiler transforms the DAG to introduce a data-dependent edge. When the number of available registers is insufficient, an edge introduced by common subexpression elimination is selected, and inverse conversion is performed according to the above procedures 4-1 to 4-3. The optimization of the common subexpression elimination is canceled, and the optimization can be applied only to a portion where the number of available registers has room.

【0066】[本発明に係るコンパイラによる最適化の
具体例]以下、具体例として、本発明に係るコンパイラ
が、ソースプログラム(上記表1)から、そのループボ
ディ(プログラム中で繰り返して実行される部分)を表
すDAG(図1)を生成し、さらに、DAGから、イン
テル社他が製造するプロセッサ(x86アーキテクチ
ャ)およびモトローラ社が製造するプロセッサ(Pow
erPCアーキテクチャ)をターゲットアーキテクチャ
として、これらのプロセッサが実行可能なオブジェクト
コードを生成する場合の最適化結果をに対してコード生
成を行ったときの結果を説明する。
[Specific Example of Optimization by Compiler According to the Present Invention] As a specific example, the compiler according to the present invention is repeatedly executed from a source program (Table 1 above) in a loop body (in a program). A DAG (FIG. 1) is generated from the DAG, and a processor manufactured by Intel and others (x86 architecture) and a processor manufactured by Motorola (Pow) are generated from the DAG.
(erPC architecture) as a target architecture, a description will be given of the result of code generation with respect to the optimization result when these processors generate executable object code.

【0067】なお、ソースプログラム(表1)におい
て、i,nは整数の変数を示し、t1〜t8,x1〜x
4は浮動小数点数の変数をしめし、a[i]は配列アク
セスを表し、ターゲットアーキテクチャのロード命令に
対応する。説明の簡略化のために、以下、本発明に係る
コンパイラの動作を、浮動小数点数のレジスタと演算器
を使用する命令のコード生成のみに絞って説明する。
In the source program (Table 1), i and n indicate integer variables, and t1 to t8, x1 to x
Reference numeral 4 denotes a floating-point variable, and a [i] represents an array access and corresponds to a load instruction of the target architecture. For the sake of simplicity, the operation of the compiler according to the present invention will be described below focusing only on the code generation of instructions using a floating-point number register and an arithmetic unit.

【0068】上述の通り、表1に例示したソースプログ
ラムは、図1に示したをDAGに表すことができる。こ
のDAGにおいて、頂点間を結ぶ実線の有向辺は、演算
の間のデータの依存を表し、点線の有向辺は副作用の順
序による依存関係を表す。ここで、プログラミング言語
のモデルから、メモリアクセスの副作用の順序が守られ
ていなければならない場合には、変数x1〜x4は、ル
ープの外からの値を参照し、繰り返しの次の実行で値が
参照されるので、ループの繰り返しの間で値を保持す
る。従って、これらの変数x1〜x4それぞれは、浮動
小数点数レジスタを1個ずつ占有する。したがって、こ
のソースプログラムのループボディのオブジェクトコー
ドの生成開始時には、4個のレジスタが使用される。
As described above, the source program exemplified in Table 1 can be represented by DAG shown in FIG. In this DAG, the directed side of the solid line connecting the vertices represents the dependence of the data during the operation, and the directed side of the dotted line represents the dependence in the order of the side effects. Here, if the order of the side effects of the memory access must be maintained from the programming language model, the variables x1 to x4 refer to values from outside the loop, and the values are changed in the next execution of the iteration. Keep the value between iterations of the loop because it is referenced. Therefore, each of these variables x1 to x4 occupies one floating-point number register. Therefore, when the generation of the object code of the loop body of the source program starts, four registers are used.

【0069】[x86アーキテクチャ]以下、レジスタ
数が閾値より少ないという条件でコード生成が行われる
x86アーキテクチャについて説明する。x86アーキ
テクチャにおいては、レジスタをオペランドとするとき
の浮動小数点数のロード命令、乗算命令、加算命令のサ
イクル数は1である。各頂点のトップからの深さlt
(v)、ボトムからの深さlb(v)、スラックネスs
l(v)、参照数の増加Δref(v)を、本発明に係
るコンパイラは、下表2に示すように計算する。
[X86 Architecture] Hereinafter, the x86 architecture in which code generation is performed under the condition that the number of registers is smaller than the threshold will be described. In the x86 architecture, when a register is used as an operand, the cycle number of a load instruction of a floating-point number, a multiplication instruction, and an addition instruction is one. Depth lt from top of each vertex
(V), depth lb (v) from bottom, slackness s
The compiler according to the present invention calculates l (v) and the increase Δref (v) of the number of references as shown in Table 2 below.

【0070】[0070]

【表2】 [Table 2]

【0071】x86アーキテクチャは8個の浮動小数点
数レジスタを持つ。このループ全体で4個のレジスタが
占有されることが分かっているので、最初の状態で使用
可能なレジスタ数は4(=8−4)である。今、コード
生成の方針を切り替える閾値thrを、例えば2と設定
すると、最初の状態は、下表3の通りに表される。
The x86 architecture has eight floating point registers. Since it is known that four registers are occupied in the entire loop, the number of registers available in the initial state is four (= 8−4). Now, if the threshold thr for switching the code generation policy is set to, for example, 2, the initial state is expressed as shown in Table 3 below.

【0072】[0072]

【表3】 [Table 3]

【0073】本発明に係るコンパイラが、上述したデー
タ構造において次にコード生成可能な頂点の列r(G)
からトップ┬を取り出し、トップ┬のオブジェクトコー
ドを生成すると、頂点3がr(G)に加えられ、上記手
続き3−2に従ってap(3)=0となるので、頂点3
のオブジェクトコードを生成すると頂点2が、上記手続
き3−2に従ってap(2)=0となるのでr(G)に
加えられる)。本発明に係るコンパイラが、頂点2から
オブジェクトコードを生成すると、頂点1,7がr
(G)に加えられる。
In the above-described data structure, the compiler according to the present invention is capable of generating a code in the next sequence of vertices r (G)
When the top オ ブ ジ ェ ク ト is extracted and the object code of the top ┬ is generated, the vertex 3 is added to r (G), and ap (3) = 0 according to the procedure 3-2.
Is generated, the vertex 2 is added to r (G) because ap (2) = 0 according to the procedure 3-2). When the compiler according to the present invention generates an object code from vertex 2, vertices 1 and 7
(G).

【0074】ここまでは、オブジェクトコード生成可能
な頂点が一つずつしかないので、どちらの方針(上記
「使用可能なレジスタ数regが閾値thrより多い場
合」の方針と「使用可能なレジスタ数regが閾値th
r以下の場合」の方針)でも同じ順番になる。頂点2か
らオブジェクトコード生成すると、現在使用可能なレジ
スタ数reg=2となるので、レジスタ数を最小化する
コード生成方針が選択される。
Up to this point, since there is only one vertex for which object code can be generated, either one of the above-mentioned policies (when the number of available registers reg is larger than the threshold thr) and when the number of available registers is reg Is the threshold th
The same order is applied in the case of “if r or less”. When the object code is generated from the vertex 2, the number of registers currently available becomes reg = 2. Therefore, a code generation policy that minimizes the number of registers is selected.

【0075】つまり、Δreg(1)=+1,Δreg
(7)=+1であり、頂点1,7のいずれが選択されて
も占有されるレジスタは1つ増加するが、Δref
(1)=+2,Δref(7)=−1より、規則dにし
たがって頂点7の優先順位が高く設定され、データ構造
は下表4の通りとなる(規則c,d,e)。
That is, Δreg (1) = + 1, Δreg
(7) = + 1, and the register occupied by one increases even if any of the vertices 1 and 7 is selected.
From (1) = + 2, Δref (7) = − 1, the priority of vertex 7 is set higher according to rule d, and the data structure is as shown in Table 4 below (rules c, d, e).

【0076】[0076]

【表4】 [Table 4]

【0077】本発明に係るコンパイラが、頂点7からオ
ブジェクトコードを生成すると、頂点11がr(G)に
加えられ、Δreg(11)=−1,Δreg(1)=
+1より、頂点11の優先順位が高く設定され、データ
構造は下表5の通りとなる(規則c)。
When the compiler according to the present invention generates the object code from the vertex 7, the vertex 11 is added to r (G), and Δreg (11) = − 1, Δreg (1) =
The priority of the vertex 11 is set higher than +1 and the data structure is as shown in Table 5 below (rule c).

【0078】[0078]

【表5】 [Table 5]

【0079】本発明に係るコンパイラが頂点11からオ
ブジェクトコードを生成すると、reg=2となり、頂
点1のみがr(G)に残る(手続3−2)。本発明に係
るコンパイラが、以下同様に最適化を行うと、最終的
に、データ構造は、下表6の通りとなる。
When the compiler according to the present invention generates an object code from vertex 11, reg = 2, and only vertex 1 remains in r (G) (procedure 3-2). When the compiler according to the present invention performs the same optimization in the following, the data structure is finally as shown in Table 6 below.

【0080】[0080]

【表6】 [Table 6]

【0081】[PowerPCアーキテクチャ]次に、
クリティカルパス上の頂点が優先的にコード生成される
PowerPCアーキテクチャについて説明する。Po
werPCアーキテクチャの浮動小数点数のロード、乗
算、加算のサイクル数はそれぞれ1,2,1である。従
って、本発明に係るコンパイラは、各頂点vのトップか
らの深さlt(v)、ボトムからの深さlb(v)、ス
ラックネスsl(v)および参照数の増加Δref
(v)を、下表7の通りに計算する。
[PowerPC Architecture] Next,
A PowerPC architecture in which vertices on the critical path are preferentially code-generated will be described. Po
The number of cycles for loading, multiplying, and adding a floating-point number in the warPC architecture is 1, 2, 1, respectively. Accordingly, the compiler according to the present invention provides a depth lt (v) from the top of each vertex v, a depth lb (v) from the bottom, slackness sl (v), and an increase in the number of references Δref.
(V) is calculated as shown in Table 7 below.

【0082】[0082]

【表7】 [Table 7]

【0083】ここで、x86アーキテクチャと同様に、
オブジェクトコード生成の方針を切り替える閾値thr
の値を2と設定する。PowerPCアーキテクチャ
は、32個の浮動小数点数レジスタを持つので、最初の
状態でデータ構造のregの値は28(=32−4)と
なる。x86の場合と同様に、本発明に係るコンパイラ
は、最初の状態から頂点3,2からオブジェクトコード
を生成する(手続3−1〜3−8)。
Here, similar to the x86 architecture,
Threshold thr for switching object code generation policy
Is set to 2. Since the PowerPC architecture has 32 floating point number registers, the value of reg of the data structure is 28 (= 32−4) in the initial state. As in the case of x86, the compiler according to the present invention generates object codes from vertices 3 and 2 from the initial state (procedures 3-1 to 3-8).

【0084】頂点2からオブジェクトコードを生成する
と、regの値は30になるので、本発明に係るコンパ
イラは、スラックネスsl(v)とトップからの深さl
t(v)を優先するオブジェクトコード生成方針を選択
する(使用可能レジスタ数regが閾値thrより多い
場合の処理から規則c〜eまでを参照)。頂点1,7そ
れぞれのスラックネスsl(1)=0,sl(7)=3
より、頂点1に高い優先順位が付され、データ構造は、
下表8の通りとなる(上述の「実際の使用レジスタ数を
計算して、オブジェクトコード生成の方針を切り替え
る」処理を参照)。
When the object code is generated from the vertex 2, the value of reg becomes 30. Therefore, the compiler according to the present invention uses the slackness sl (v) and the depth l from the top.
An object code generation policy that prioritizes t (v) is selected (see processing from when the number of available registers reg is larger than the threshold thr to rules c to e). Slackness sl (1) = 0, sl (7) = 3 for each of vertices 1 and 7
Thus, vertex 1 is given a higher priority, and the data structure is
The results are as shown in Table 8 below (refer to the above-described process of “calculating the actual number of used registers and switching the object code generation policy”).

【0085】[0085]

【表8】 [Table 8]

【0086】本発明に係るコンパイラは、同様にして4
つのロード命令のオブジェクトコードを生成する。頂点
0のロード命令のオブジェクトコードを生成した状態で
は、次に、頂点4,5,6,7のオブジェクトコードが
生成可能になる。ここで、頂点4,5,6,7それぞれ
のスラックネスは、sl(4)=0,sl(5)=0,
sl(6)=1,sl(7)=3なので、頂点4,5に
高い優先順位が付され、頂点6,7よりも先に、頂点
4,5からオブジェクトコードが生成され、データ構造
は、下表9に示す通りとなる(手続3−1〜3−8)。
The compiler according to the present invention similarly operates
Generate object code for one load instruction. With the object code of the load instruction of vertex 0 generated, the object codes of vertices 4, 5, 6, and 7 can be generated next. Here, the slackness of each of the vertices 4, 5, 6, and 7 is sl (4) = 0, sl (5) = 0,
Since sl (6) = 1 and sl (7) = 3, vertices 4 and 5 are assigned high priority, and object codes are generated from vertices 4 and 5 before vertices 6 and 7, and the data structure is And Table 9 below (procedures 3-1 to 3-8).

【0087】[0087]

【表9】 [Table 9]

【0088】同様に、頂点8,9,10,11それぞれ
のスラックネスの値は、sl(8)=0,sl(9)=
0,sl(10)=1,sl(11)=3なので、デー
タ構造は、最終的に下表10に示す通りとなる。
Similarly, the slackness values of the vertices 8, 9, 10, and 11 are sl (8) = 0 and sl (9) =
Since 0, sl (10) = 1 and sl (11) = 3, the data structure finally becomes as shown in Table 10 below.

【0089】[0089]

【表10】 [Table 10]

【0090】[長い遅延時間を持つ演算子の遅延隠蔽]
上述したように、PowerPCアーキテクチャをター
ゲットアーキテクチャとすると、乗算の遅延時間は2マ
シンサイクルである。ここで、ターゲットアーキテクチ
ャの演算器の遅延時間を非常に大きくする演算子がクリ
ティカルパス上にある場合、スラックネスの小さい頂点
を優先すると、クリティカルパス上の命令を実行するた
めの待ち時間が無駄になってしまうことがある。
[Delay concealment of operator with long delay time]
As described above, when the PowerPC architecture is the target architecture, the multiplication delay time is two machine cycles. Here, if there is an operator on the critical path that greatly increases the delay time of the arithmetic unit of the target architecture, giving priority to a vertex with small slackness wastes the waiting time for executing an instruction on the critical path. Sometimes.

【0091】このような状態を改善するには、本発明に
係るコンパイラを、DAGからコード生成を行う際に、
各頂点の実行開始可能な時刻を計算し、クリティカルパ
ス上の命令の待ち時間に対して、スラックネスが大きい
頂点でも、実行開始可能時刻が早い頂点があれば、そち
らの優先順位を高くしてオブジェクトコード生成を行う
ように構成するとよい。
In order to improve such a state, the compiler according to the present invention performs
Calculates the execution start time of each vertex, and if there is a vertex with a large slackness with respect to the waiting time of the instruction on the critical path, if there is a vertex with an earlier execution start time, the priority is increased and the object is set. It may be configured to perform code generation.

【0092】このように構成した場合の本発明に係るコ
ンパイラの処理を、以下に説明する。オブジェクトコー
ドの生成時に、最も最近のコードが発行された時刻ct
(今までコード生成されたコードの発行時刻の最大値)
を算出し、さらに、オブジェクトコード生成中に、その
時点で未だオブジェクトコードが生成されていない頂点
v(DAGからコード生成を行う間、r(G)に属する
頂点v)について、頂点vをコード生成することが可能
な時刻rt(v)を計算する。ただし、この場合、時刻
ct,rt(v)それぞれのオブジェクトコード作成開
始時点の初期値を0とする。
The processing of the compiler according to the present invention in such a configuration will be described below. The time ct at which the latest code was issued when the object code was generated
(Maximum value of code generation time until now)
Further, during the object code generation, a vertex v is generated for the vertex v for which the object code has not yet been generated (the vertex v belonging to r (G) during the code generation from the DAG). Rt (v) is calculated. However, in this case, the initial values at the time of starting the object code creation at time ct and rt (v) are set to 0.

【0093】頂点wのオブジェクトコードを生成すると
きに、上記手続3−1において、時刻ctの値をct:
=rt(w)と設定する。手続3−3において、時刻r
t(w)の値をrt(w):=ct+cv(v)と設定
する。演算子の遅延隠蔽を行うには、上記規則a,bに
従って、スラックネスsl(v)とトップからの深さl
t(v)を優先するコード生成方針で、rt(v)をスラッ
クネスより優先してコード生成を行えばよい。rt(v)が
同じ場合はスラックネスとトップからの深さを優先す
る。
When the object code of the vertex w is generated, the value of the time ct is changed to ct:
= Rt (w). In procedure 3-3, time r
The value of t (w) is set as rt (w): = ct + cv (v). In order to perform the delay concealment of the operator, the slackness sl (v) and the depth l from the top are determined according to the rules a and b.
In the code generation policy in which t (v) is prioritized, rt (v) may be generated prior to slackness. When rt (v) is the same, priority is given to slackness and depth from the top.

【0094】[効果]共通部分式がなく、木で表される
ようなソースプログラムからオブジェクトコードを生成
する場合については、Sethi, R. and J. D. Ullman, "T
he generation of optimal code for arithmetic expre
ssions", J. ACM 17:4, 715-728.に開示されているよう
に、中間変数のための使用レジスタ数を最小化するアル
ゴリズムが開発されている。また、Aho, A. V. and S.
C. Johnson, "Optimal code generation for expressio
n trees", J. ACM 23:3, 488-501.に開示されているよ
うに、複雑な命令セットを持つアーキテクチャに対応す
るために、動的計画法を用いたアルゴリズムが開発され
ている。これらのアルゴリズムは、いずれも使用レジス
タ数だけを最小化するように工夫されている。
[Effect] In the case where an object code is generated from a source program represented by a tree without a common subexpression, see Sethi, R. and JD Ullman, "T
he generation of optimal code for arithmetic expre
ssions ", J. ACM 17: 4, 715-728. Algorithms have been developed to minimize the number of registers used for intermediate variables.
C. Johnson, "Optimal code generation for expressio
In order to cope with an architecture having a complicated instruction set, an algorithm using dynamic programming has been developed as disclosed in J. ACM 23: 3, 488-501. Each of these algorithms is devised so as to minimize only the number of used registers.

【0095】しかしながら、先に述べたとおり、使用レ
ジスタ数を最小化することと、演算の遅延時間を隠蔽し
たり、共通部分式を削減したりするオブジェクトコード
の最適化との間にはトレードオフが存在する。本発明に
係るコンパイラは、このトレードオフを、DAGからの
オブジェクトコード生成時に計算し、動的に最適化の方
針を変更することができるため、他のコード最適化を妨
げることなく、最適化の適用範囲を使用可能なレジスタ
数の制約が許す部分に限定することができるという点
で、上記Seti等により開発されたアルゴリズムよりも優
れている。
However, as described above, there is a trade-off between minimizing the number of registers used and optimizing the object code for hiding the operation delay time and reducing common sub-expressions. Exists. The compiler according to the present invention can calculate this trade-off at the time of generating the object code from the DAG and dynamically change the optimization policy, so that the optimization can be performed without hindering other code optimization. It is superior to the algorithm developed by Seti et al. In that the applicable range can be limited to a portion permitted by the restriction on the number of registers that can be used.

【0096】[第2実施形態]以下、本発明の第2の実
施形態として、レジスタ割付を工夫することによりオブ
ジェクトコードを最適化する方法を説明する。レジスタ
割付は、コンパイルの結果として選られるオブジェクト
コードのパフォーマンスを向上させるための非常に重要
な手法の一つであるが、その多くは全てのレジスタを対
称に扱っている。ところが、全てのレジスタの扱われ型
は等価ではなく、実際にはマシンの仕様やオブジェクト
コード生成慣習に基づいたレジスタ使用の非対称性が存
在する。この制約を考慮せずにレジスタ割付を行ってし
まうと、オブジェクトコード生成時にレジスタ間の移動
命令が無駄に生成されてしまい、コンパイルの結果とし
て選られるオブジェクトコードのパフォーマンスを大き
く落としてしまう可能性がある。
[Second Embodiment] A method of optimizing an object code by devising register allocation will be described below as a second embodiment of the present invention. Register allocation is one of the most important ways to improve the performance of the object code chosen as a result of compilation, but many treat all registers symmetrically. However, the handling types of all registers are not equivalent, and there is actually an asymmetry in register usage based on machine specifications and object code generation practices. If register allocation is performed without considering this restriction, instructions for moving registers between registers will be generated in vain when object code is generated, and the performance of the object code selected as a result of compilation may be greatly reduced. is there.

【0097】本発明の第2の実施形態として示す最適化
処理においては、データフロー方程式を解くことによ
り、レジスタの特定の使用に関する情報を中間コードの
後ろから前に伝播し、将来的に出現する特定レジスタの
使用制約を前もって充足しておき、また、Web(ある
変数の定義・使用連鎖および使用・定義連鎖による連結
集合)を構成している変数にレジスタが割り当てられた
時点で、 Webつまり連結集合の要素にこのレジスタを
伝播させ、同じく将来的な特定レジスタの使用をあらか
じめ決定しておく。これにより、レジスタ制約を満たす
ためのレジスタ移動が削減され、無駄のない質の高いオ
ブジェクトコードが生成可能となる。
In the optimization processing shown as the second embodiment of the present invention, information on a specific use of a register is propagated from back to front of the intermediate code by solving a data flow equation, and will appear in the future. The usage constraint of a specific register is satisfied in advance, and when a register is assigned to a variable constituting a Web (a definition / use chain of a certain variable and a linked set by use / definition chain), the Web, that is, the connection is established. This register is propagated to the members of the set, and the future use of the specific register is determined in advance. Thereby, register movement for satisfying the register constraint is reduced, and high-quality object code without waste can be generated.

【0098】第2の実施形態として示す本発明にかかる
コンパイラは、コンパイル処理に用いる中間コードにお
いて各命令のレジスタ割付が必要となる要素に、望まし
いレジスタを記述できるフィールド(以下制約記述フィ
ールド)を用意し、ターゲットマシンの性質に合わせ
て、制約記述フィールドを記述する。この制約記述フィ
ールドには、強い制約を記述するものと弱い制約を記述
するものの二つが用意される。
The compiler according to the present invention shown as the second embodiment prepares a field (hereinafter referred to as a constraint description field) that can describe a desired register in an element that requires register allocation of each instruction in the intermediate code used for the compiling process. Then, a constraint description field is described in accordance with the properties of the target machine. The constraint description field is prepared with two types, one that describes a strong constraint and one that describes a weak constraint.

【0099】次に、マシンの仕様等に基づいて中間コー
ドの各命令に弱い制約を記述していく。制約には、特定
演算に使われる専用レジスタやレジスタを介して渡され
る関数の引数などがある。特に、本発明では関数呼び出
しを越えて生存する変数が不揮発性レジスタに乗るべき
であることを考慮し、関数呼び出しの後にもっとも早く
参照される、不揮発性レジスタの個数分の変数を参照し
ている命令に、不揮発性レジスタに対応した制約を記述
する。
Next, weak constraints are described for each instruction of the intermediate code based on the specifications of the machine. The constraint includes a dedicated register used for a specific operation, a function argument passed through the register, and the like. In particular, the present invention considers that variables that survive a function call should be placed in nonvolatile registers, and refers to variables as many as the number of nonvolatile registers that are referred to earliest after a function call. The constraint corresponding to the non-volatile register is described in the instruction.

【0100】各命令に弱い制約を記述した後、これらの
制約をデータの使用から定義にむけて後ろ向きに伝播さ
せる。ここで、具体的に伝播とは、データの使用が行わ
れているのオブジェクトコードにあった情報(ここでは
弱い制約)をデータの定義が行われているのオブジェク
トコードに複写することをいう。これにより、ある命令
における変数定義が、未来においてどのようなレジスタ
制約を持って参照されるかが明らかになる。また同時
に、ある制約を持った変数と生存区間が重なるような変
数に、その制約の補集合となるような制約を記述し、同
様に伝播を行う。
After describing the weak constraints in each instruction, these constraints are propagated backward from the use of data to the definition. Here, the term “propagation” specifically refers to copying information (here, a weak constraint) in an object code in which data is used to an object code in which data is defined. As a result, it becomes clear what kind of register constraint the variable definition in a certain instruction will be referred to in the future. At the same time, a constraint that is a complement of the constraint is described in a variable whose live range overlaps with a variable having a constraint, and propagation is similarly performed.

【0101】これにより、制約を持ったレジスタを取得
する時点で、そのレジスタがすでに他の変数に割り付け
られているような事態を回避することができる。以上の
ような伝播をベーシックブロック内で行うような関数を
用意した上で、データフロー方程式を解く。以上の操作
で、ベーシックブロックを越えて弱い制約が中間コード
の全体に渡り伝播される。
Thus, it is possible to avoid a situation in which a register having a constraint is already allocated to another variable at the time of obtaining the register with the constraint. After preparing a function for performing the above propagation in the basic block, the data flow equation is solved. By the above operation, the weak constraint is propagated throughout the intermediate code beyond the basic block.

【0102】この後、中間コードを前から後ろに走査
し、記述された制約に基づいてレジスタを割り付けてい
く。このとき、変数の定義・使用連鎖および使用・定義
連鎖をたどりながら、定義を行っている変数に割り付け
られたレジスタを、強い制約としてその変数の定義が属
するWebの全体に伝播させる。ここで、Webとは、
同じ変数に対する DU- UD-chain による連結集合のこと
をいう。
Thereafter, the intermediate code is scanned from front to back, and registers are allocated based on the described constraints. At this time, the register assigned to the variable being defined is propagated as a strong constraint to the entire Web to which the definition of the variable belongs while following the definition / use chain and the use / definition chain of the variable. Here, the Web is
It refers to a connected set by the DU-UD-chain for the same variable.

【0103】これにより、各Webに属する変数に対し
て同じレジスタが割り付けられる可能性が高くなり、特
にベーシックブロックの合流点において変数の定義がマ
ージしている場合に保障的なレジスタ間の移動命令を生
成することを回避できる。この操作は各 Web に対して
一回のみおこなわれ、すでに強い制約が伝播されたWe
b上の変数にレジスタを割り付ける場合は伝播を行わな
い。
As a result, there is a high possibility that the same register is allocated to a variable belonging to each Web. Particularly, when the definition of the variable is merged at the junction of the basic blocks, the transfer instruction between the registers is guaranteed. Can be avoided. This operation is performed only once for each Web.
When a register is assigned to a variable on b, no propagation is performed.

【0104】また、レジスタマッピングの初期値(イニ
シャルキャッシュセット)を決めるときに、データフロ
ー方程式によって解かれた弱いレジスタ制約を反映さ
せ、最初からレジスタに乗っている変数に対し、それら
の変数の参照時に無駄なレジスタ間移動命令が生成され
ないようにする。
Further, when determining the initial value (initial cache set) of the register mapping, the weak register constraint solved by the data flow equation is reflected, and the variables which have already been in the registers from the beginning are referred to by those variables. At times, useless inter-register transfer instructions are prevented from being generated.

【0105】静的(Static)コンパイラで一般的に採用
されている干渉グラフの彩色アルゴリズムにおいても、
レジスタ制約を反映させる方法が開発されている。しか
しこの方法には、以下のような問題点がある。この方法
では、物理レジスタを表すノードを干渉グラフに加え、
レジスタと変数を干渉させることでレジスタ制約を消極
的に表現することが可能である。例えば、変数aをレジ
スタr1に割り当てたい場合は、r1を表すノードとa
以外の変数を表すノードに干渉を与えればよい。しかし
ながら、この方法は消極的な記述のみが可能であるた
め、複数の変数を一つのレジスタに割り当てる場合など
は制約の記述が弱くなってしまう。
In the interference graph coloring algorithm generally adopted by a static compiler,
Methods have been developed to reflect register constraints. However, this method has the following problems. In this method, a node representing a physical register is added to the interference graph,
It is possible to express the register constraint passively by causing the register and the variable to interfere with each other. For example, to assign a variable a to the register r1, a node representing r1 and a
Interference may be given to nodes representing variables other than. However, since this method can only describe passively, the description of the constraint becomes weak when a plurality of variables are assigned to one register.

【0106】また、各ノードには時間的なコンテクスト
が圧縮されているため、ある変数が異なったコンテクス
トで異なった制約を持っているような場合は、制約の記
述は行えない。さらに、レジスタ制約を表すのに必要な
干渉の数が膨大になるという問題点もある。
Further, since the temporal context is compressed in each node, when a certain variable has a different context and a different constraint, the constraint cannot be described. Further, there is a problem that the number of interferences required to represent the register constraint becomes enormous.

【0107】[第2の実施形態として示すコンパイラ]
本発明の第2の実施形態として示すコンパイラ(Jav
a Just−inーTimeコンパイラ)を説明す
る。
[Compiler Shown as Second Embodiment]
The compiler (Java) shown as the second embodiment of the present invention
a Just-in-Time compiler) will be described.

【0108】本発明にかかるコンパイラは、レジスタ転
送レベルの中間コードを用いて処理を行っている。すな
わち、各命令は、ディスティネーション、ソース(複数)
を表す変数(仮想レジスタ)と、オペレーションコードの
組として記述される。命令中の各変数はレジスタアロケ
ータによりレジスタが割り当てられる。本発明に係るこ
んぱいらは、これらの変数に対し、付属情報としてター
ゲットマシンで利用可能な物理レジスタを表現するため
のビットフィールドを用意し、以下に述べる方法で取得
されることが望ましいレジスタのビットを立てる。
The compiler according to the present invention performs processing using the intermediate code at the register transfer level. That is, each instruction is a destination, a source (plural)
(Virtual register) and an operation code. Each variable in the instruction is assigned a register by the register allocator. Compiler according to the present invention, for these variables, prepare a bit field to represent a physical register available in the target machine as ancillary information, the bit of the register is preferably obtained by the method described below Stand up.

【0109】このフィールドは強い制約が記述されるも
のと弱い制約が記述されるものの二種類を用意する。レ
ジスタアロケータは、ベーシックブロックを深さ優先順
にたどり、各ベーシック内の命令を前から後ろに走査し
ながらレジスタを割り当てていく。レジスタ割付時にお
いて、レジスタを割り当てようとしている変数に強い制
約を表すビットが立っていた場合、そのレジスタを優先
的に割り当てる。もし、そのレジスタがすでに使用され
ていた場合は、弱い制約に基づきレジスタを割り当て
る。さらにそのレジスタが使用されていた場合は、他の
レジスタを割り付ける。
This field prepares two types, one in which a strong constraint is described and one in which a weak constraint is described. The register allocator follows the basic blocks in depth-first order, and allocates registers while scanning instructions in each basic from the front to the back. At the time of register assignment, if a bit indicating a strong constraint is set in a variable to which a register is to be assigned, the register is preferentially assigned. If the register has already been used, allocate the register based on weak constraints. If the register is used, another register is allocated.

【0110】また、本手法では、ループを単位としてレ
ジスタのキャッシュセットを決定し、ループの入り口に
おいてレジスタの入れかえを行う。 ここでは、あらか
じめレジスタに乗っているべき変数は、ループの入り口
からもっとも最初に参照される物理レジスタ個の変数と
する。これらの変数に対しレジスタを初期的に割り当て
るわけであるが、このときにループの入り口に伝播され
たレジスタ制約を反映させるようにする。
In this method, a register cache set is determined for each loop, and registers are replaced at the entrance of the loop. Here, the variables that should be in the registers in advance are the variables of the physical registers that are first referred to from the entrance of the loop. Registers are initially allocated to these variables. At this time, the register constraints propagated at the entry of the loop are reflected.

【0111】[制約の記述]まず、関数呼び出しに関す
る制約を説明する。
[Description of Constraints] First, constraints on function calls will be described.

【0112】[関数の引数に関する制約]本発明にかか
るコンパイラにおいては、関数呼び出し時に引数の一部
をレジスタに乗せ、処理の高速化を図っている。どの引
数がどのレジスタに乗るかは、呼び出し慣習によってあ
らかじめ定められており、これが変数にレジスタを割り
付けるときの制約となる。本例では、関数呼び出しを行
う命令のソース変数のうち、レジスタに乗せて値が渡さ
れるもののフィールドに、呼び出し慣習で定められてい
るレジスタに対応したビットを立てる。
[Restriction on Argument of Function] In the compiler according to the present invention, a part of the argument is placed in a register at the time of calling the function, so that the processing is speeded up. Which argument rides on which register is predetermined by calling convention, which is a constraint when allocating registers to variables. In this example, among the source variables of the instruction for performing the function call, a bit corresponding to the register defined by the calling convention is set in a field of a value to be passed on a register.

【0113】[関数の戻り値に関する制約]本発明にか
かるコンパイラにおいては、関数からの復帰時に戻り値
をレジスタに乗せ、処理の高速化を図っている。戻り値
をどのレジスタに乗せるかは慣習によって決まっている
ので、戻り値となる変数にレジスタを割り付けるときに
制約が発生する。本例では、復帰を行う命令のソース変
数のフィールドに、復帰時の慣習で定められているレジ
スタに対応したビットを立てる。
[Restriction on Return Value of Function] In the compiler according to the present invention, the return value is placed in a register when returning from the function, so as to speed up the processing. Since the register to which the return value is put is determined by custom, there is a restriction when assigning a register to a variable to be a return value. In this example, a bit corresponding to a register determined by custom at the time of return is set in the field of the source variable of the instruction to perform the return.

【0114】[関数を越えて生存する変数に関する制
約]本発明にかかるコンパイラでは、関数呼び出し時に
生存しているレジスタは、呼ばれる方の(Callee)側で
必要に応じてセーブされる。したがって、関数を越えて
生存する変数を不揮発性レジスタに乗せたほうが良いと
いう一種の制約がある。本例では、関数呼び出しが起こ
った後に最も早く参照される不揮発性レジスタ個の変数
を使用する命令のソースフィールドに、不揮発性レジス
タに対応したビットを立てる。関数呼び出し後に最も早
く参照される変数をデータフロー解析を用いて求めるこ
とができる。
[Restriction on Variable Surviving Beyond Function] In the compiler according to the present invention, the register alive at the time of calling the function is saved as needed on the called side (Callee). Therefore, there is a kind of restriction that it is better to put a variable that survives beyond a function on a nonvolatile register. In this example, a bit corresponding to the nonvolatile register is set in the source field of the instruction that uses the variable of the nonvolatile register that is referred to the earliest after the function call occurs. The variable that is referred to earliest after a function call can be determined using data flow analysis.

【0115】[特定演算における制約]掛け算や割り
算、シフト命令等では、特定のレジスタを使用しなけれ
ばならないという制約がある。本実施例では、特定レジ
スタの使用が必要な命令のソース変数のフィールドにマ
シン仕様に定められたレジスタに対応したビットを立て
る。
[Restriction on Specific Operation] There is a restriction that a specific register must be used in multiplication, division, shift instruction and the like. In this embodiment, a bit corresponding to a register defined in the machine specifications is set in a field of a source variable of an instruction that requires the use of a specific register.

【0116】[制約の伝播]以下、本発明にかかるコン
パイラにおける制約の伝播を説明する。
[Propagation of Constraints] Propagation of constraints in the compiler according to the present invention will be described below.

【0117】[静的な制約伝播(弱い制約の伝播)]各ベ
ーシックブロックごとに、その入口と出口において、各
変数の持つレジスタ制約を表す配列を用意する。各ベー
シックブロックにおいて、各変数の初期レジスタ制約を
ベーシックブロックの出口の配列とし、命令を下から上
に走査して記述された制約を変数の使用から定義に伝播
させ、変数の弱い制約記述フィールドを記述していく。
また制約を持った変数と生存区間が重なるような変数
に、その制約の補集合となるような制約を記述し、同様
に伝播を行う。伝播された結果をベーシックブロックの
入口の配列に格納し、ベーシックブロックどうしの連結
状態から、あるベーシックブロックの出口の配列 = そ
のベーシックブロックから到達する全てのベーシックブ
ロックの入口の配列の論理積を計算し、この出口配列を
新たな初期値として制約の走査を行う。以上を出口配列
の変化が飽和するまで繰り返す。
[Static Constraint Propagation (Propagation of Weak Constraints)] For each basic block, an array representing the register constraints of each variable is prepared at the entrance and exit. In each basic block, the initial register constraint of each variable is set to the array of the exit of the basic block, the instruction is scanned from bottom to top, and the described constraint is propagated from the use of the variable to the definition, and the weak constraint description field of the variable is set. I will describe it.
In addition, a constraint that is a complement of the constraint is described in a variable whose live range overlaps with the variable having the constraint, and propagation is performed similarly. Stores the propagated result in the array of basic block entrances, and calculates the logical product of the array of exits of a basic block = the array of entrances of all basic blocks arriving from the basic block based on the connection state of the basic blocks The constraint array is scanned using the exit array as a new initial value. The above is repeated until the change in the outlet arrangement is saturated.

【0118】[レジスタ割付時の制約伝播(強い制約の
伝播)]レジスタ割付中、二つ以上の定義を持つWeb
を構成している変数に対するレジスタ取得が行われた場
合、命令に付された相互リンクをたどって、他のWeb
を構成要素となっている変数を検出する。この変数の強
い制約記述フィールドに、取得されたレジスタを書き込
む。また、レジスタ取得対象となっているに制約がつい
ていなかった場合、Web 上を操作して他の定義に付され
ている制約を検出し、この制約に基づいてレジスタの取
得を試みる。なお、この操作は各Webに対して一回の
みおこなわれ、すでに処理が行われたWeb上の変数に
レジスタを割り付ける場合は伝播を行わない。
[Propagation of Constraints During Register Allocation (Propagation of Strong Constraints)] During register allocation, a Web having two or more definitions
When the register acquisition is performed for the variable that configures the instruction, the link following the instruction is linked to another Web.
Is detected as a constituent variable. The obtained register is written in the strong constraint description field of this variable. If there is no restriction on the register acquisition target, operate the Web to detect the restriction attached to other definitions, and try to acquire the register based on this restriction. This operation is performed only once for each Web, and when a register is assigned to a variable on the Web that has already been processed, propagation is not performed.

【0119】[第3実施形態]以下、本発明の第3の実
施形態として、第1の実施形態および第2実施形態に示
したオブジェクトコードの最適化を行うコンパイラの実
現方法を説明する。
[Third Embodiment] Hereinafter, as a third embodiment of the present invention, a method of implementing the compiler for optimizing the object code shown in the first embodiment and the second embodiment will be described.

【0120】[コンピュータシステム]図2は、第1の
実施形態および第2の実施形態に示した本発明にかかる
コンパイラを実現するコンピュータシステムの構成を示
す図である。図2に示すように、コンピュータシステム
は、Javaコンパイラを含むJava開発環境1、ネ
ットワークあるいは記録媒体などの媒体5およびクアラ
イアント装置6から構成される。
[Computer System] FIG. 2 is a diagram showing a configuration of a computer system for realizing the compiler according to the present invention shown in the first embodiment and the second embodiment. As shown in FIG. 2, the computer system includes a Java development environment 1 including a Java compiler, a medium 5 such as a network or a recording medium, and a client device 6.

【0121】クライアント装置6は、所定数のレジスタ
・演算回路・パイプライン機構などから構成されるマイ
クロプロセッサ、RAM・ROMなどのメモリ、周辺回
路、および、ハードディスク装置・リムーバブルディス
ク装置などの記憶装置(いずれも図示せず)等から構成
されるハードウェア13を含む。このハードウェア13
は、JavaVM(Java Virtual Machine)7、および、
Windows(マイクロソフト社商品名)、OS2
(IBM社商品名)およびMacOS(アップル社商品
名)等のオペレーティングシステム(OS)12を記録
媒体からメモリにロードし、実行する。JavaVM7
は、Javaバイトコード検証部8、Javaインタプ
リタ9、JavaJITコンパイラ10を含む。
The client device 6 includes a microprocessor including a predetermined number of registers, arithmetic circuits, and a pipeline mechanism, a memory such as a RAM and a ROM, peripheral circuits, and a storage device such as a hard disk device and a removable disk device. (Not shown). This hardware 13
Is a JavaVM (Java Virtual Machine) 7 and
Windows (trade name of Microsoft Corporation), OS2
An operating system (OS) 12 such as (IBM product name) and MacOS (Apple product name) is loaded from a recording medium to a memory and executed. JavaVM7
Includes a Java bytecode verification unit 8, a Java interpreter 9, and a JavaJIT compiler 10.

【0122】[Java開発環境1]Java開発環境
1において、Javaコンパイラ3は、あらかじめ作成
されたJavaソースコード2をコンパイルし、Jav
aバイトコード4を生成する。生成されたJavaバイ
トコード5は、ネットワークにより、あるいは、記録媒
体に記録され、媒体5を介してクライアント装置6に対
して送られる。なお、Javaバイトコード4は、コン
ピュータのハードウェアおよび実行環境に関わらず実行
可能なJavaプログラムの表現形式である。
[Java Development Environment 1] In the Java development environment 1, the Java compiler 3 compiles the Java source code 2 created in advance, and
Generate a byte code 4. The generated Java bytecode 5 is recorded on a network or in a recording medium and sent to the client device 6 via the medium 5. The Java bytecode 4 is an expression format of a Java program that can be executed regardless of computer hardware and an execution environment.

【0123】[クライアント装置6]クライアント装置
6は、Java開発環境1から媒体5を介して供給され
たJavaバイトコード4を、WWWブラウザ、WWW
サーバ等のJavaVM7により実行する。
[Client Device 6] The client device 6 converts the Java bytecode 4 supplied from the Java development environment 1 via the medium 5 into a WWW browser, WWW
It is executed by the Java VM 7 such as a server.

【0124】[Javaバイトコード検証部8]クライ
アント装置6において、Javaバイトコード検証部8
は、Java開発環境1から媒体5を介してクライアン
ト装置6に送られてきたJavaバイトコード4をバイ
トコード検証し、Javaバイトコードの仕様を満たし
ているか否かを判断し、仕様を満たしている場合には、
Javaインタプリタ9およびJITコンパイラ10に
対して出力する。
[Java Bytecode Verification Unit 8] In the client device 6, the Java bytecode verification unit 8
Verifies the bytecode of the Java bytecode 4 sent from the Java development environment 1 to the client device 6 via the medium 5, determines whether the specification of the Java bytecode is satisfied, and satisfies the specification. in case of,
Output to the Java interpreter 9 and the JIT compiler 10.

【0125】[Javaインタプリタ9]Javaイン
タプリタ9は、Javaバイトコード検証部8から入力
されたJavaバイトコードをインタプリタ方式により
実行する。
[Java interpreter 9] The Java interpreter 9 executes the Java bytecode input from the Java bytecode verification unit 8 by an interpreter method.

【0126】[JITコンパイラ10]JITコンパイ
ラ10は、Javaバイトコード検証部8から入力され
たJavaバイトコード高速実行するために、ハードウ
ェア13が実行可能なマシンコード(オブジェクトコー
ド)11に変換し、実行させる。
[JIT Compiler 10] The JIT compiler 10 converts the machine code (object code) 11 that can be executed by the hardware 13 to execute the Java bytecode input from the Java bytecode verification unit 8 at high speed. Let it run.

【0127】[コンピュータシステムの動作]以下、図
3〜図8を参照して、図2に示したコンピュータシステ
ムの動作を説明する。図3は、図2に示したJITコン
パイラ10の動作を示すフローチャートである。図4
は、図3に示した中間コード最適化処理(S17)を示
す第1のフローチャートである。図5は、図4に示した
中間コード作成処理(S26)を示すフローチャートで
ある。図6は、図5に示したDAGからの中間コード作
成処理(S30)を示すフローチャートである。図7
は、図6に示した頂点列整列処理(S37)を示すフロ
ーチャートである。図8は、図3に示した中間コード最
適化処理(S17)を示す第2のフローチャートであっ
て、図4に示した処理に続く処理を示す。図9は、図3
に示したコード生成・レジスタ割付処理(S18)を示
すフローチャートである。
[Operation of Computer System] The operation of the computer system shown in FIG. 2 will be described below with reference to FIGS. FIG. 3 is a flowchart showing the operation of the JIT compiler 10 shown in FIG. FIG.
5 is a first flowchart showing the intermediate code optimization processing (S17) shown in FIG. FIG. 5 is a flowchart showing the intermediate code creation processing (S26) shown in FIG. FIG. 6 is a flowchart showing the process of creating the intermediate code from the DAG shown in FIG. 5 (S30). FIG.
7 is a flowchart showing a vertex string alignment process (S37) shown in FIG. FIG. 8 is a second flowchart showing the intermediate code optimizing process (S17) shown in FIG. 3, and shows a process subsequent to the process shown in FIG. FIG. 9 shows FIG.
9 is a flowchart showing a code generation / register allocation process (S18) shown in FIG.

【0128】Java開発環境1において、Javaコ
ンパイラ3は、Javaソースコード2からJavaバ
イトコード4を生成し、媒体5を介してクライアント装
置6に送信する。クライアント装置6において、Jav
aVM7のJavaバイトコード検証部8は、Java
バイトコード4を受信し、Javaバイトコードを検証
して、仕様に合致したJavaバイトコード4をJIT
コンパイラ10に対して出力する。
In the Java development environment 1, the Java compiler 3 generates a Java bytecode 4 from the Java source code 2 and sends it to the client device 6 via the medium 5. In the client device 6, Java
The Java bytecode verification unit 8 of the aVM 7
Bytecode 4 is received, Java bytecode is verified, and Java bytecode 4 that meets the specifications is
Output to the compiler 10.

【0129】図3に示すように、ステップ14(S1
4)において、JITコンパイラ10(図2)は、Ja
vaバイトコード検証部8からJavaバイトコード4
を受け取る。ステップ15(S15)において、JIT
コンパイラ10は、Javaバイトコード4から中間コ
ードの形式に変換し、中間コード(S16)を生成す
る。この中間コード(S16)は、JavaJITコン
パイラが解析したり、変形したりしやすいような表現形
式、つまり、変数の値を読み出し、演算を行い、結果を
変数に書き込む命令が順番に並んだ形式になっている。
As shown in FIG. 3, step 14 (S1
In 4), the JIT compiler 10 (FIG. 2)
From the Java bytecode verification unit 8 to the Java bytecode 4
Receive. In step 15 (S15), JIT
The compiler 10 converts the Java bytecode 4 into an intermediate code format and generates an intermediate code (S16). This intermediate code (S16) is in an expression format that is easily analyzed and deformed by the JavaJIT compiler, that is, a format in which instructions for reading a variable value, performing an operation, and writing a result to a variable are arranged in order. Has become.

【0130】ステップ17(S17)において、JIT
コンパイラ10は、S15の処理において生成された中
間コード(S16)を対象とした最適化処理(図4〜
8)を行う。
In step 17 (S17), the JIT
The compiler 10 performs an optimization process (FIG. 4 to FIG. 4) on the intermediate code (S16) generated in the process of S15.
Perform 8).

【0131】図4に示すように、S17(図3)のステ
ップ23(S23)において、JITコンパイラ10
(図2)は、中間コードをDAG(図1)の形式に変換
し、中間コードDAG(S24)を生成する。この中間
コードDAG(S25)は、上述のように、中間コード
が、演算子を頂点とし、演算に使用されるデータの依存
関係を辺とするような有向グラフとして表現され、JI
Tコンパイラ10は、共通部分式の削除等の最適化処理
を、この中間コードDAG(S25)に対して行う。
As shown in FIG. 4, in step 23 (S23) of S17 (FIG. 3), the JIT compiler 10
(FIG. 2) converts the intermediate code into a DAG (FIG. 1) format to generate an intermediate code DAG (S24). As described above, the intermediate code DAG (S25) is expressed as a directed graph in which the intermediate code has an operator as a vertex and a dependency of data used for the operation as an edge.
The T compiler 10 performs optimization processing such as deletion of the common subexpression on the intermediate code DAG (S25).

【0132】ステップ26(S26)において、JIT
コンパイラ10は、中間コードDAG(S25)で表現
された制約を満たすように、中間コードの演算子を順に
ならべて、再び中間コードを生成する。なお、中間コー
ドDAGで表現された制約とは、DAGの有向辺が元の
中間コードの順序制約を表すことをいう。
In step 26 (S26), the JIT
The compiler 10 generates the intermediate code again by arranging the operators of the intermediate code in order so as to satisfy the constraint expressed by the intermediate code DAG (S25). Note that the constraint expressed by the intermediate code DAG means that the directed side of the DAG represents the order constraint of the original intermediate code.

【0133】図5に示すように、S26(図4)のステ
ップ29(S29)において、JITコンパイラ10
(図2)は、DAG(S26)の各頂点について、オブ
ジェクトコード生成に使用するパラメータ(lt,l
b,sl,△ref)を計算する(上記「第2のステッ
プの詳細」を参照)。
As shown in FIG. 5, in step 29 (S29) of S26 (FIG. 4), the JIT compiler 10
FIG. 2 shows parameters (lt, l) used for object code generation for each vertex of the DAG (S26).
b, sl, △ ref) (see “Details of the second step” above).

【0134】ステップ30(S30)において、JIT
コンパイラ10は、生成された中間コードの使用レジス
タ数を計算し、中間コードを生成する方針を動的に変更
しながらオブジェクトコードを生成する(手続3−1〜
3−8)。
In step 30 (S30), the JIT
The compiler 10 calculates the number of used registers of the generated intermediate code, and generates the object code while dynamically changing the policy for generating the intermediate code (procedure 3-1 to procedure 3-1).
3-8).

【0135】図6に示すように、S30(図5)のステ
ップ33(S33)において、JITコンパイラ10
(図2)は、オブジェクトコード生成可能な頂点の列r
(G)の初期化を行う(上記手続3−1〜3−8)。つ
まり、JITコンパイラ10は、トップ┬を、オブジェ
クトコード生成可能な頂点の列に加える。
As shown in FIG. 6, in step 33 (S33) of S30 (FIG. 5), the JIT compiler 10
(FIG. 2) shows a column r of vertices from which object code can be generated.
(G) is initialized (procedures 3-1 to 3-8 described above). That is, the JIT compiler 10 adds the top ┬ to the row of vertices for which the object code can be generated.

【0136】ステップ34(S34)において、JIT
コンパイラ10は、オブジェクトコード生成可能な頂点
の列r(G)の先頭の頂点を取り出し、オブジェクトコ
ード生成された頂点の列a(G)の最後に追加する(手
続3−1,3−2)。
In step 34 (S34), the JIT
The compiler 10 extracts the top vertex of the vertex sequence r (G) in which the object code can be generated and adds it to the end of the vertex sequence a (G) in which the object code is generated (procedure 3-1 and 3-2). .

【0137】ステップ35(S35)において、JIT
コンパイラ10は、S34の処理により、新たにオブジ
ェクトコードの生成が可能になった頂点を、オブジェク
トコード生成可能な頂点の列に追加する(手続3−
3)。
In step 35 (S35), the JIT
The compiler 10 adds the vertex for which the object code can be newly generated to the column of the vertex for which the object code can be generated by the process of S34 (procedure 3-
3).

【0138】ステップ36(S36)において、JIT
コンパイラ10は、オブジェクトコード生成可能な頂点
の列が空になった場合には処理を終了し、これ以外の場
合にはS37の処理に進む(手続3−8)。
In step 36 (S36), the JIT
Compiler 10 terminates the process when the column of vertices for which object code can be generated becomes empty, and otherwise proceeds to the process of S37 (procedure 3-8).

【0139】ステップ37(S37)において、その時
点での(現在の)オブジェクトコード生成方針に従っ
て、オブジェクトコード生成可能な頂点の列を整列し、
S34の処理に戻る(手続3−7)。
In step 37 (S37), the rows of vertices for which object codes can be generated are arranged in accordance with the (current) object code generation policy at that time.
The process returns to S34 (procedure 3-7).

【0140】図7に示すように、S37(図6)のステ
ップ40(S40)において、JITコンパイラ10
(図2)は、S34の処理によるオブジェクトコード生
成により変化したレジスタ数を計算する(手続3−
5)。
As shown in FIG. 7, in step 40 (S40) of S37 (FIG. 6), the JIT compiler 10
(FIG. 2) calculates the number of registers changed by the generation of the object code in the process of S34 (procedure 3-).
5).

【0141】ステップ41(S41)において、使用可
能なレジスタ数が0の場合にはS42の処理に進み、こ
れ以外の場合にはS43の処理に進む。つまり、S41
において、共通部分式の逆変換の判定条件が判断され
る。
In step 41 (S41), if the number of available registers is 0, the process proceeds to S42, otherwise, the process proceeds to S43. That is, S41
In, the condition for determining the inverse transformation of the common sub-expression is determined.

【0142】ステップ42(S42)において、JIT
コンパイラ10は、オブジェクトコードを生成していな
いDAGの頂点であって、共通部分式の削除によって、
ハードウェア13の使用可能なレジスタが増える頂点が
あれば、その頂点に対して逆変換を行う(手続4−1〜
4−3)。
In step 42 (S42), the JIT
The compiler 10 is a vertex of the DAG for which no object code has been generated.
If there is a vertex at which the number of available registers of the hardware 13 increases, inverse transformation is performed on the vertex (procedure 4-1 to procedure 4-1).
4-3).

【0143】ステップ43(S43)において、JIT
コンパイラ10は、その時点で使用可能なハードウェア
13のレジスタ数が所定の閾値よりも多いか否かを判断
し、多い場合にはS44の処理に進み、これ以外の場合
にはS45の処理に進む(手続3−7)。
In step 43 (S43), the JIT
The compiler 10 determines whether or not the number of registers of the hardware 13 that can be used at that time is larger than a predetermined threshold. If the number is larger, the process proceeds to S44. Proceed (procedure 3-7).

【0144】ステップ44(S44)において、JIT
コンパイラ10は、使用可能なレジスタが数的に十分に
あると判断し、オブジェクトコードの並行性が高くなる
ように、DAGのクリティカルパス上の頂点を優先して
オブジェクトコードの生成を行う。
In step 44 (S44), the JIT
The compiler 10 determines that the available registers are sufficient in number, and generates the object code by giving priority to the vertices on the critical path of the DAG so that the parallelism of the object code is high.

【0145】ステップ45(S45)において、JIT
コンパイラ10は、使用可能なレジスタが少なくなって
いると判断し、オブジェクトコード生成可能な頂点の列
に含まれる各頂点について、使用可能なレジスタ数の増
減などのパラメータ(△reg)を計算し、使用可能な
レジスタ数を増やす頂点を優先して整列を行う。
In step 45 (S45), the JIT
The compiler 10 determines that the number of available registers is low, and calculates a parameter (△ reg) such as an increase or decrease in the number of available registers for each vertex included in the column of vertex where the object code can be generated, Priority is given to vertices that increase the number of available registers.

【0146】図7に示した処理に続き、JITコンパイ
ラ10は、図3に示したS17の処理の続きとして、図
8に示す弱いレジスタ制約の伝播、および、二つ以上の
定義を持つWebを検出する。図8に示すように、ステ
ップ48(S48)において、JITコンパイラ10
(図2)は、中間コード(図3のS16)中の各命令
に、ステップ49において伝播されるべき弱い制約を記
述する。つまり、JITコンパイラ10は、マシンの仕
様等に基づいて中間コードの各命令に弱い制約を記述す
る。
Following the processing shown in FIG. 7, as a continuation of the processing in S17 shown in FIG. 3, the JIT compiler 10 transmits the weak register constraint shown in FIG. 8 and the Web having two or more definitions as shown in FIG. To detect. As shown in FIG. 8, in step 48 (S48), the JIT compiler 10
(FIG. 2) describes the weak constraints to be propagated in step 49 for each instruction in the intermediate code (S16 in FIG. 3). That is, the JIT compiler 10 describes weak constraints on each instruction of the intermediate code based on the specifications of the machine and the like.

【0147】ステップ49(S49)において、JIT
コンパイラ10は、S48の処理において記述された弱
い制約をデータの使用から定義にむけて伝播する。つま
り、JITコンパイラ10は、制約をデータの使用から
定義にむけて後ろ向きに伝播させる。
In step 49 (S49), the JIT
The compiler 10 propagates the weak constraint described in the processing of S48 from the use of data to the definition. That is, the JIT compiler 10 propagates the constraint backward from use of data to definition.

【0148】ステップ50(S50)において、JIT
コンパイラ10は、データの定義および使用連鎖の情報
を利用しながら、ある変数に対する定義・使用の連結集
合(Web)を検出する。特に本ステップでは二つ以上
の定義を持つWebを検出する。つまり、JITコンパ
イラ10は、中間コードを前から後ろに走査し、記述さ
れた制約に基づいてレジスタを割り付けていく。
In step 50 (S50), the JIT
The compiler 10 detects a linked set of definitions and uses for a certain variable (Web) while using information on data definitions and usage chains. Particularly, in this step, a Web having two or more definitions is detected. That is, the JIT compiler 10 scans the intermediate code from the front to the back and allocates registers based on the described constraints.

【0149】再度、図3を参照する。ステップ18(S
18)において、JITコンパイラ10は、中間コード
内のそれぞれの命令に対し、レジスタ割付とオブジェク
トコード生成を行う。
Referring again to FIG. Step 18 (S
In 18), the JIT compiler 10 performs register allocation and object code generation for each instruction in the intermediate code.

【0150】図9に示すように、S18(図3)のステ
ップ53(S53)において、JITコンパイラ10
(図2)は、中間コードの各要素(中間コード内の各命
令)について、レジスタ割付とオブジェクトコードの作
成が終了したか否かを判断し、これらが終了した場合に
はオブジェクトコード(S20;図3)を生成してS2
1の処理に進み、これ以外の場合にはS54の処理に進
む。つまり、つまり、中間コード内の最初の命令から最
後の命令まで、コード生成とレジスタ割付を繰り返した
ことが終了条件とされる。
As shown in FIG. 9, in step 53 (S53) of S18 (FIG. 3), the JIT compiler 10
(FIG. 2) determines whether or not register allocation and object code creation are completed for each element of the intermediate code (each instruction in the intermediate code), and when these are completed, the object code (S20; Figure 3) is generated and S2
Then, the process proceeds to S54. Otherwise, the process proceeds to S54. That is, the end condition is that code generation and register allocation are repeated from the first instruction to the last instruction in the intermediate code.

【0151】ステップ54(S54)において、JIT
コンパイラ10は、中間コードの各要素について、レジ
スタの割付とオブジェクトコード生成を行う。
In step 54 (S54), the JIT
The compiler 10 performs register allocation and object code generation for each element of the intermediate code.

【0152】ステップ55(S55)において、JIT
コンパイラ10は、S54の処理において割り付けられ
たレジスタを強い制約条件として、2つ以上の定義を持
つWebに伝播する。つまり、JITコンパイラ10
は、ある命令で使用される変数に割り付けられたレジス
タを、その変数が含まれるWebをたどり、Webは定
義と使用の集合なので、その要素となってる全ての定義
と使用を行う命令に強い制約を記述する。
In step 55 (S55), the JIT
The compiler 10 propagates the register allocated in the processing of S54 to the Web having two or more definitions as a strong constraint. In other words, JIT compiler 10
Traces the register allocated to the variable used in a certain instruction to the Web in which the variable is included. Since the Web is a set of definitions and uses, there is a strong restriction on all the definitions and uses of the instructions that make up the element. Describe.

【0153】ステップ56(S56)において、JIT
コンパイラ10は、処理対象となる中間コードの次の要
素(命令)を取り出す。S57でS19が得られる。
In step 56 (S56), the JIT
The compiler 10 extracts the next element (instruction) of the intermediate code to be processed. S19 is obtained in S57.

【0154】みたび図3を参照する。ステップ21(S
21;図3)において、JITコンパイラ10(図2)
は、コードスケジュール処理を行い、高速動作可能なオ
ブジェクトコード(マシンコード11;図2)を生成す
る。
Reference is now made to FIG. Step 21 (S
21; in FIG. 3), the JIT compiler 10 (FIG. 2)
Performs a code schedule process to generate an object code (machine code 11; FIG. 2) that can operate at high speed.

【0155】[0155]

【発明の効果】以上述べたように、本発明にかかるコン
パイル装置およびその方法によれば、プロセッサの物理
レジスタ数に起因する制約を満たす範囲において、コー
ドスケジューリングおよび共通部分式削除により、オブ
ジェクトコードを効果的に最適化することができる。
As described above, according to the compiling apparatus and method of the present invention, object scheduling is performed by code scheduling and common sub-expression elimination within a range that satisfies the constraint caused by the number of physical registers of the processor. It can be optimized effectively.

【0156】また、本発明にかかるコンパイル装置およ
びその方法によれば、DAG(directed acyclic graph)
形式で表現されたソースプログラムから、レジスタ使用
数とハードウェアの実行サイクル数を評価しながらオブ
ジェクトコードの生成を行い、コードスケジューリング
による最適化および共通部分式削除の適用範囲と、物理
レジスタ数の制約とを最適にトレードオフすることがで
きる。
According to the compiling apparatus and the compiling method of the present invention, a DAG (directed acyclic graph) is provided.
Generates object code from the source program expressed in the format while evaluating the number of registers used and the number of hardware execution cycles, the scope of optimization by code scheduling and the elimination of common subexpressions, and the restrictions on the number of physical registers Can be optimally traded off.

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

【図1】DAGを例示する図である。FIG. 1 is a diagram illustrating a DAG.

【図2】第1の実施形態および第2の実施形態に示した
本発明にかかるコンパイラを実現するコンピュータシス
テムの構成を示す図である。
FIG. 2 is a diagram illustrating a configuration of a computer system that implements a compiler according to the present invention illustrated in the first embodiment and the second embodiment.

【図3】図2に示したJITコンパイラの動作を示すフ
ローチャートである。
FIG. 3 is a flowchart showing an operation of the JIT compiler shown in FIG. 2;

【図4】図3に示した中間コード最適化処理(S17)
を示す第1のフローチャートである。
FIG. 4 is an intermediate code optimizing process shown in FIG. 3 (S17);
6 is a first flowchart illustrating the process of FIG.

【図5】図4に示した中間コード作成処理(S26)を
示すフローチャートである。
FIG. 5 is a flowchart showing an intermediate code creation process (S26) shown in FIG. 4;

【図6】図5に示したDAGからの中間コード作成処理
(S30)を示すフローチャートである。
FIG. 6 is a flowchart showing a process of creating an intermediate code from a DAG shown in FIG. 5 (S30).

【図7】図6に示した頂点列整列処理(S37)を示す
フローチャートである。
FIG. 7 is a flowchart showing a vertex string alignment process (S37) shown in FIG. 6;

【図8】図3に示した中間コード最適化処理(S17)
を示す第2のフローチャートであって、図4に示した処
理に続く処理を示す。
FIG. 8 is an intermediate code optimizing process shown in FIG. 3 (S17);
5 is a second flowchart showing processing subsequent to the processing shown in FIG.

【図9】図3に示したコード生成・レジスタ割付処理
(S18)を示すフローチャートである。
FIG. 9 is a flowchart showing a code generation / register allocation process (S18) shown in FIG. 3;

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

1・・・Java開発環境 2・・・Javaソースコード 3・・・Javaコンパイラ 4・・・Javaバイトコード 5・・・媒体 6・・・クライアント装置 7・・・JavaVM 8・・・Javaバイトコード検証部 9・・・Javaインタプリタ 10・・・JITコンパイラ 11・・・マシンコード 12・・・OS 13・・・ハードウェア DESCRIPTION OF SYMBOLS 1 ... Java development environment 2 ... Java source code 3 ... Java compiler 4 ... Java bytecode 5 ... Medium 6 ... Client device 7 ... JavaVM 8 ... Java bytecode Verification unit 9 Java interpreter 10 JIT compiler 11 Machine code 12 OS 13 Hardware

───────────────────────────────────────────────────── フロントページの続き (72)発明者 古関 聰 神奈川県大和市下鶴間1623番地14 日本ア イ・ビー・エム株式会社 東京基礎研究所 内 (72)発明者 稲垣 達氏 神奈川県大和市下鶴間1623番地14 日本ア イ・ビー・エム株式会社 東京基礎研究所 内 (72)発明者 安江 俊明 神奈川県大和市下鶴間1623番地14 日本ア イ・ビー・エム株式会社 東京基礎研究所 内 (72)発明者 小松 秀昭 神奈川県大和市下鶴間1623番地14 日本ア イ・ビー・エム株式会社 東京基礎研究所 内 (72)発明者 竹内 幹雄 神奈川県大和市下鶴間1623番地14 日本ア イ・ビー・エム株式会社 東京基礎研究所 内 Fターム(参考) 5B081 CC25 CC41  ──────────────────────────────────────────────────続 き Continuing on the front page (72) Inventor Satoshi Furuseki 1623-14 Shimotsuruma, Yamato-shi, Kanagawa Prefecture Inside the Tokyo Research Laboratory, IBM Japan, Ltd. (72) Inventor Tatsu Inagaki, Yamato-shi, Kanagawa Prefecture 1623-14 Tsuruma, Tokyo Japan Basic Research Laboratories, IBM Japan, Ltd. (72) Inventor Toshiaki Yasue 1623-14 Shimotsuruma, Yamato-shi, Kanagawa Prefecture, Japan Tokyo Research Laboratories, IBM Japan, Ltd. (72 Inventor Hideaki Komatsu 1623-14 Shimotsuruma, Yamato City, Kanagawa Prefecture Inside the Tokyo Research Laboratory, IBM Japan, Ltd. (72) Mikio Takeuchi 1623-14 Shimotsuruma, Yamato City, Kanagawa Prefecture, Japan F-term in M Basic Research Laboratory Tokyo (reference) 5B081 CC25 CC41

Claims (7)

【特許請求の範囲】[Claims] 【請求項1】プログラムのソースコードをDAG形式に
変換する変換手段と、 前記変換されたソースコードに含まれる命令それぞれに
対応するオブジェクトコードを、所定数のレジスタを用
いて実行するプロセッサのパラメータを計算するパラメ
ータ計算手段と、 前記変換されたソースコードを走査し、計算された前記
プロセッサのパラメータに基づいて、前記ソースコード
をコンパイルしてオブジェクトコードを生成するコンパ
イル手段とを有するコンパイル装置であって、 前記パラメータ計算手段は、 前記命令それぞれに対応するオブジェクトコードが、前
記プロセッサにより実行されるタイミングを計算するタ
イミング計算手段と、 前記命令それぞれに対応するオブジェクトコードが実行
されるときに占有される前記プロセッサのレジスタ数の
増減を示す数値を計算するレジスタ増減計算手段とを有
するコンパイル装置。
1. A conversion means for converting a source code of a program into a DAG format, and a parameter of a processor for executing an object code corresponding to each instruction included in the converted source code by using a predetermined number of registers. A compiling device comprising: parameter calculating means for calculating; and compiling means for scanning the converted source code and compiling the source code based on the calculated parameters of the processor to generate object code. Wherein the parameter calculating means comprises: timing calculating means for calculating a timing at which the object code corresponding to each of the instructions is executed by the processor; and wherein the object code is occupied when the object code corresponding to each of the instructions is executed. Processor Compiling device having a register decrease calculation means for calculating a numerical value indicating the increase or decrease of register number.
【請求項2】前記コンパイル手段は、 前記変換されたソースコードにおける前記命令の実行順
序に沿って、前記命令に付与された優先順位に従って、
前記命令それぞれを順次コンパイルし、前記命令それぞ
れのオブジェクトコードを生成するオブジェクトコード
生成手段と、 前記レジスタ数の増減を示す数値に基づいて、次にコン
パイルされる可能性がある前記命令それぞれが実行され
るときに占有される前記プロセッサのレジスタの数を示
す占有レジスタ数を計算する占有レジスタ数計算手段
と、 計算された前記開放レジスタ数、および、前記命令のオ
ブジェクトコードが実行されるタイミングに基づいて、
次にコンパイルされる可能性がある前記命令に優先順位
を付与する優先順位付与手段とを有する請求項1に記載
のコンパイル装置。
2. The method according to claim 1, wherein the compiling means executes the instructions in the converted source code in accordance with an execution order of the instructions and a priority given to the instructions.
Object code generation means for sequentially compiling each of the instructions to generate an object code for each of the instructions; and executing each of the instructions which may be next compiled based on a numerical value indicating an increase or decrease in the number of registers. Occupied register number calculating means for calculating the number of occupied registers indicating the number of registers of the processor which are occupied when the instruction is executed, based on the calculated number of open registers and the timing at which the object code of the instruction is executed. ,
2. The compiling device according to claim 1, further comprising: a priority assigning unit that assigns a priority to the instruction that is likely to be compiled next.
【請求項3】前記優先順位付与手段は、 計算された前記占有レジスタ数と所定の閾値とを比較
し、前記計算される占有レジスタ数が所定の閾値より多
い場合には、前記計算される占有レジスタ数をより少な
く増やすか、減らす命令に高い優先順位を付し、これ以
外の場合には、クリティカルパスにある命令に高い優先
順位を付す請求項2に記載のコンパイル装置。
3. The priority assigning means compares the calculated number of occupied registers with a predetermined threshold. If the calculated number of occupied registers is larger than a predetermined threshold, the priority assigning means calculates the occupied register. 3. The compiling apparatus according to claim 2, wherein an instruction for increasing or decreasing the number of registers is assigned a high priority, and otherwise, an instruction on a critical path is assigned a high priority.
【請求項4】前記コンパイル手段は、 前記命令における共通部分式を削除してからオブジェク
トコードの生成を行うように構成されており、 前記計算される占有レジスタ数が前記所定の閾値よりも
多い場合に、前記削除された共通部分式を元に戻す逆変
換を行う逆変換手段をさらに有する請求項3に記載のコ
ンパイル装置。
4. The compile means is configured to generate an object code after deleting a common subexpression in the instruction, and when the calculated occupied register number is larger than the predetermined threshold value. 4. The compiling device according to claim 3, further comprising an inverse transform unit for performing an inverse transform for restoring the deleted common subexpression.
【請求項5】前記プロセッサのレジスタの用途を制約す
る所定の制約条件に基づいて、前記レジスタの割り付け
を行うデータ割付手段をさらに有する請求項1〜4のい
ずれかに記載のコンパイル装置。
5. The compiling device according to claim 1, further comprising data allocating means for allocating said register based on a predetermined constraint condition for restricting a use of a register of said processor.
【請求項6】プログラムのソースコードをDAG形式に
変換する変換ステップと、 前記変換されたソースコードに含まれる命令それぞれに
対応するオブジェクトコードを、所定数のレジスタを用
いて実行するプロセッサのパラメータを計算するパラメ
ータ計算ステップと、 前記変換されたソースコードを走査し、計算された前記
プロセッサのパラメータに基づいて、前記ソースコード
をコンパイルしてオブジェクトコードを生成するコンパ
イルステップとを含むコンパイル方法であって、 前記パラメータ計算ステップにおいて、 前記命令それぞれに対応するオブジェクトコードが、前
記プロセッサにより実行されるタイミングを計算し、 前記命令それぞれに対応するオブジェクトコードが実行
されるときに占有される前記プロセッサのレジスタ数の
増減を示す数値を計算するコンパイル方法。
6. A conversion step of converting a source code of a program into a DAG format, and a parameter of a processor for executing an object code corresponding to each instruction included in the converted source code by using a predetermined number of registers. A compiling method comprising: a parameter calculating step of calculating; and a compiling step of scanning the converted source code and compiling the source code based on the calculated parameters of the processor to generate an object code. In the parameter calculation step, the timing at which the object code corresponding to each of the instructions is executed by the processor is calculated, and the processor occupied when the object code corresponding to each of the instructions is executed. Compiling method for calculating a numerical value indicating the increase or decrease of static number.
【請求項7】プログラムのソースコードをDAG形式に
変換する変換ステップと、 前記変換されたソースコードに含まれる命令それぞれに
対応するオブジェクトコードを、所定数のレジスタを用
いて実行するプロセッサのパラメータを計算するパラメ
ータ計算ステップと、 前記変換されたソースコードを走査し、計算された前記
プロセッサのパラメータに基づいて、前記ソースコード
をコンパイルしてオブジェクトコードを生成するコンパ
イルステップとをコンピュータに実行させるプログラム
であって、 前記パラメータ計算ステップにおいて、 前記命令それぞれに対応するオブジェクトコードが、前
記プロセッサにより実行されるタイミングを計算する処
理と、 前記命令それぞれに対応するオブジェクトコードが実行
されるときに占有される前記プロセッサのレジスタ数の
増減を示す数値を計算する処理とをコンピュータに実行
させるプログラムを媒介する媒体。
7. A conversion step of converting a source code of a program into a DAG format, and a parameter of a processor for executing an object code corresponding to each instruction included in the converted source code by using a predetermined number of registers. A program for causing a computer to execute a parameter calculating step of calculating, and a compiling step of scanning the converted source code and compiling the source code based on the calculated parameters of the processor to generate an object code. Wherein in the parameter calculation step, a process of calculating a timing at which the object code corresponding to each of the instructions is executed by the processor; and an occupation when the object code corresponding to each of the instructions is executed. Medium mediating program for executing a process of calculating a numerical value indicating the register number of increase or decrease of the processor computers.
JP23253399A 1999-08-19 1999-08-19 Compiling apparatus and method Expired - Fee Related JP3405696B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP23253399A JP3405696B2 (en) 1999-08-19 1999-08-19 Compiling apparatus and method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP23253399A JP3405696B2 (en) 1999-08-19 1999-08-19 Compiling apparatus and method

Publications (2)

Publication Number Publication Date
JP2001075814A true JP2001075814A (en) 2001-03-23
JP3405696B2 JP3405696B2 (en) 2003-05-12

Family

ID=16940835

Family Applications (1)

Application Number Title Priority Date Filing Date
JP23253399A Expired - Fee Related JP3405696B2 (en) 1999-08-19 1999-08-19 Compiling apparatus and method

Country Status (1)

Country Link
JP (1) JP3405696B2 (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007094731A (en) * 2005-09-28 2007-04-12 Matsushita Electric Ind Co Ltd Compiler apparatus
JP2009301326A (en) * 2008-06-13 2009-12-24 Nec System Technologies Ltd Compiling device, compiler, and compiling method
WO2020262456A1 (en) * 2019-06-26 2020-12-30 コネクトフリー株式会社 Execution code provision method and software development system
CN117311727A (en) * 2023-11-27 2023-12-29 摩尔线程智能科技(北京)有限责任公司 Analysis method, analysis device, electronic equipment and storage medium

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007094731A (en) * 2005-09-28 2007-04-12 Matsushita Electric Ind Co Ltd Compiler apparatus
JP2009301326A (en) * 2008-06-13 2009-12-24 Nec System Technologies Ltd Compiling device, compiler, and compiling method
WO2020262456A1 (en) * 2019-06-26 2020-12-30 コネクトフリー株式会社 Execution code provision method and software development system
JP2021005250A (en) * 2019-06-26 2021-01-14 コネクトフリー株式会社 Execution code provision method and software development system
CN117311727A (en) * 2023-11-27 2023-12-29 摩尔线程智能科技(北京)有限责任公司 Analysis method, analysis device, electronic equipment and storage medium

Also Published As

Publication number Publication date
JP3405696B2 (en) 2003-05-12

Similar Documents

Publication Publication Date Title
US6718541B2 (en) Register economy heuristic for a cycle driven multiple issue instruction scheduler
US5202975A (en) Method for optimizing instruction scheduling for a processor having multiple functional resources
US4782444A (en) Compilation using two-colored pebbling register allocation method such that spill code amount is invariant with basic block's textual ordering
US6651247B1 (en) Method, apparatus, and product for optimizing compiler with rotating register assignment to modulo scheduled code in SSA form
US5761514A (en) Register allocation method and apparatus for truncating runaway lifetimes of program variables in a computer system
US20200272444A1 (en) Placement of explicit preemption points into compiled code
US20140053129A1 (en) Parallelization of Dataflow Actors with Local State
JP2000347874A (en) Method and device for structuring call rule prolog and epilog codes using register allocator
JPH07129412A (en) Method and equipment for compilation
Acar et al. Oracle scheduling: Controlling granularity in implicitly parallel languages
JP3651774B2 (en) Compiler and its register allocation method
Johnson et al. Combined code motion and register allocation using the value state dependence graph
JPH0738158B2 (en) Code optimization method and compiler system
Greiner et al. A provably time-efficient parallel implementation of full speculation
US20020078436A1 (en) Compiling computer programs including branch instructions
Leopoldseder et al. A Cost Model for a Graph-based Intermediate-representation in a Dynamic Compiler
Beck et al. Static scheduling for dynamic dataflow machines
Suganuma et al. Evolution of a Java just-in-time compiler for IA-32 platforms
US7007272B2 (en) Compiling computer programs including branch instructions
JP3405696B2 (en) Compiling apparatus and method
Buck Brook Spec v0. 2
Peters et al. PorcE: a deparallelizing compiler
Shevchenko Project Paper: Embedding Generic Monadic Transformer into Scala: Can We Merge Monadic Programming into Mainstream?
Hall et al. Interprocedural compilation of Fortran D
Eisl Trace Register Allocation

Legal Events

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

Free format text: PAYMENT UNTIL: 20090307

Year of fee payment: 6

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

Free format text: PAYMENT UNTIL: 20100307

Year of fee payment: 7

LAPS Cancellation because of no payment of annual fees