JP2010122820A - Compile device and compile method - Google Patents
Compile device and compile method Download PDFInfo
- Publication number
- JP2010122820A JP2010122820A JP2008294733A JP2008294733A JP2010122820A JP 2010122820 A JP2010122820 A JP 2010122820A JP 2008294733 A JP2008294733 A JP 2008294733A JP 2008294733 A JP2008294733 A JP 2008294733A JP 2010122820 A JP2010122820 A JP 2010122820A
- Authority
- JP
- Japan
- Prior art keywords
- register
- code
- recovery
- save
- exit
- 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.)
- Pending
Links
Images
Landscapes
- Devices For Executing Special Programs (AREA)
Abstract
Description
本発明は、計算機の利用技術において、オブジェクトプログラムのコードサイズと実行時間を削減するコンパイル装置、コンパイル方法及びコンパイラに関する。特に、push/pop命令等のスタック操作命令を利用したcallee−saveレジスタの回復コード削減方法に関し、命令数を増加させることなく関数出口において必要なcallee−saveレジスタのみを回復するコード列を生成することで、callee−saveレジスタの回復コードを削減し、コードサイズが小さく、かつ、実行性能の良いオブジェクトプログラムを生成するcallee−saveレジスタの回復コード削減するコンパイル装置、コンパイル方法及びコンパイラに関する。 The present invention relates to a compiling device, a compiling method, and a compiler that reduce the code size and execution time of an object program in a computer utilization technique. In particular, with respect to a recovery code reduction method for a call-save register using a stack operation instruction such as a push / pop instruction, a code string for recovering only a call-save register necessary at a function exit is generated without increasing the number of instructions. The present invention relates to a compiling device, a compiling method, and a compiler that reduce a recovery code of a callee-save register, reduce a recovery code of a callee-save register that generates an object program having a small code size and good execution performance.
ソースコードを実行コードに変換するコンパイラでは、関数呼び出しを行う場合、関数の呼び出し先でレジスタの退避と回復が必要になる。このように関数の呼び出し先で退避と回復する必要のあるレジスタを一般にcallee−saveレジスタと呼んでいる。このcallee−saveレジスタの退避、回復場所は通常、予めメモリ上に設定されたスタック上に確保される。また、関数呼び出し直後にスタックの先頭位置を指し示す値(スタックポインタ)を格納するレジスタも用意されており、このレジスタのことを本明細書ではスタックレジスタ(以下、SPと記載する)と呼ぶことにする。 In a compiler that converts source code into executable code, register saving and recovery are required at the function call destination when a function call is made. A register that needs to be saved and restored at a function call destination is generally called a “calle-save register”. The save / restore location of the callee-save register is usually secured on a stack set in advance in the memory. Also, a register for storing a value (stack pointer) indicating the top position of the stack immediately after the function call is prepared, and this register is referred to as a stack register (hereinafter referred to as SP) in this specification. To do.
一般に行われているデータの退避と回復処理の一例を示すと、関数入口のコードは、図12(a)に示すとおり、callee−saveレジスタの退避を、SPのレジスタサイズ分のアドレスを減算した後、減算後のSPが指すスタック上にcallee−saveレジスタのデータをストアする命令(push命令)で実行した後、関数内で利用するワーク領域(図示の−αに相当)を確保するために、スタックレジスタの更新命令をadd命令で実行する。 An example of data saving and recovery processing that is generally performed is as follows. As shown in FIG. 12A, the function entry code saves the callee-save register and subtracts the address corresponding to the SP register size. In order to secure a work area (corresponding to -α in the figure) used in the function after executing with an instruction (push instruction) for storing the data in the callee-save register on the stack pointed to by the SP after subtraction The stack register update instruction is executed by the add instruction.
一方関数出口のコードは、図12(b)に示すとおり、スタックレジスタSPの更新命令をadd命令で実行した後、callee−saveレジスタの回復を、SPが指すスタック上からcallee−saveレジスタにデータをロードした後、SPにレジスタサイズ分のアドレスを加算する命令(pop命令)で実行する。 On the other hand, as shown in FIG. 12B, the function exit code executes the update instruction of the stack register SP with the add instruction, and then restores the callee-save register from the stack pointed to by the SP to the callee-save register. Is loaded with an instruction (pop instruction) for adding an address corresponding to the register size to SP.
上記のようなcallee−saveレジスタの退避と回復については、特許文献1に開示される技術が知られている。
ここで、関数出口が複数存在し、関数入口からある関数出口に至るパス上で、退避したcallee−saveレジスタの一部しか定義していない場合の回復コード(pop命令)について考える。この場合、関数出口においては、定義されているcallee−saveレジスタのみを回復すれば良いため、必要なレジスタのみの回復コードをpop命令で生成したとする。しかし、pop命令は、スタックからレジスタへ値を回復する機構の他に、スタックアドレスを更新する機構を含む命令である。そのため、単純に回復コードを削減しただけでは、回復するレジスタにおいて、退避時と異なるスタックアドレスから値を回復することになり、不正なコード実行することになる。 Here, a recovery code (pop instruction) in the case where there are a plurality of function exits and only a part of the saved call-save register is defined on a path from the function entry to a function exit will be considered. In this case, since only the defined call-save register needs to be recovered at the function exit, it is assumed that the recovery code of only the necessary register is generated by the pop instruction. However, the pop instruction is an instruction including a mechanism for updating the stack address in addition to a mechanism for recovering a value from the stack to the register. Therefore, if the recovery code is simply reduced, the value of the register to be recovered is recovered from a stack address different from that at the time of saving, and illegal code is executed.
そこで、本発明の目的は、callee−saveレジスタの回復コードでpop命令を利用しながら、不要な回復コードを削減できる手段を提供することにある。 Therefore, an object of the present invention is to provide means for reducing unnecessary recovery codes while using a pop instruction in the recovery code of a callee-save register.
本発明は、演算処理を行う第1のプロセッサと、前記プロセッサが利用する情報を格納する記憶部と、を備えて、関数を含むソースプログラムを読み込んでスタック操作命令を含むオブジェクトプログラムを生成するコンパイル装置において、前記ソースプログラムを読み込んで中間コードを生成する構文解析部と、前記中間コードを読み込んで、前記オブジェクトプログラムを実行する計算機を構成する第2のプロセッサのレジスタを前記中間コードに割り付けるレジスタ割り付け部と、前記レジスタに割り付けた中間コードからオブジェクトコードを生成し、オブジェクトプログラムを出力するコード生成部、とを備え、前記記憶部は、前記第2のプロセッサのレジスタの情報を格納したターゲット情報と、前記関数に割り付けられた前記レジスタの情報を格納する第1のレジスタ情報と、前記レジスタの退避順序と回復順序を格納する第2のレジスタ情報と、を有し、前記コード生成部は、前記関数の入口及び出口に割り付けられた前記レジスタの情報を収集して前記第1のレジスタ情報に格納する定義レジスタ情報収集部と、前記第1のレジスタ情報を読み込んで、前記関数の入口及び出口に割り付けられた前記レジスタの退避順序と回復順序を決定する退避・回復順序決定部と、前記退避・回復順序決定部が決定した退避順序と回復順序に従って前記レジスタの退避コードと回復コードを生成する退避・回復コード生成部と、を有し、退避・回復コード生成部は、前記レジスタの退避順序に従ってレジスタの退避コードを前記関数の入口に生成し、前記第1のレジスタ情報と前記退避順序及び回復順序から前記関数の入口から出口に至るパス上で割り付けられているレジスタに対して、前記関数の出口毎にそれぞれ回復コードを生成し、前記パス上で定義されてないレジスタのサイズの和を求め、前記関数の出口でスタックアドレスを前記レジスタのサイズの和だけ補正するスタックアドレスの更新命令を生成する。 The present invention includes a first processor that performs arithmetic processing, and a storage unit that stores information used by the processor, and that compiles a source program including a function and generates an object program including a stack operation instruction In the apparatus, a syntax analysis unit that reads the source program and generates an intermediate code, and a register allocation that allocates a register of a second processor that constitutes a computer that reads the intermediate code and executes the object program to the intermediate code And a code generation unit that generates an object code from the intermediate code allocated to the register and outputs an object program, and the storage unit includes target information storing information on the register of the second processor; Before being assigned to the function First register information for storing register information, and second register information for storing the save order and recovery order of the registers, and the code generation unit is assigned to the entry and exit of the function A definition register information collection unit that collects information on the registers and stores the information in the first register information; and a saving order of the registers assigned to the function entry and exit by reading the first register information A save / recovery order determination unit that determines a recovery order, and a save / recovery code generation unit that generates a save code and a recovery code of the register according to the save order and the recovery order determined by the save / recovery order determination unit. And a save / recovery code generation unit generates a save code for the register at the entry of the function according to the save order of the registers, and stores the first register information. And a register that is generated on the path from the entry to the exit of the function from the save order and the recovery order and generates a recovery code for each exit of the function, and is not defined on the path The stack address update instruction for correcting the stack address by the sum of the register sizes is generated at the exit of the function.
したがって、本発明によれば、複数の出口を有する関数のオブジェクトコードを生成する場合には、callee−saveレジスタの不要な回復コードが削減可能になるため、オブジェクトプログラムのコードサイズを増加させることなく、実行性能の良いオブジェクトプログラム(実行コード)を生成することが可能になる。 Therefore, according to the present invention, when generating an object code of a function having a plurality of exits, unnecessary recovery code of the callee-save register can be reduced, so that the code size of the object program is not increased. It is possible to generate an object program (execution code) with good execution performance.
以下、本発明の一実施形態を添付図面に基づいて説明する。 Hereinafter, an embodiment of the present invention will be described with reference to the accompanying drawings.
<第1実施形態>
図1は、本発明によるコンパイラが稼動する計算機システム(コンパイル装置)の構成図である。この計算機システム200は、演算処理を行うCPU(またはプロセッサ)201と、情報の表示を行うディスプレイ装置202と、情報の入力を行うキーボード203と、CPU201が利用する情報を格納する主記憶装置204、および情報を格納する外部記憶装置205より構成されている。キーボード203により、ユーザからのコンパイラ起動命令を受け付ける。コンパイラ終了メッセージやエラーメッセージは、ディスプレイ装置202に表示される。外部記憶装置205はHDDや不揮発性メモリで構成され、ソースプログラム206とオブジェクトプログラム207が格納される。主記憶装置204には、ソースプログラム206を読み込んでオブジェクトプログラム207を生成するコンパイラ208と、コンパイル過程で必要となる中間コード209と定義レジスタ情報テーブル210とレジスタ情報テーブル211及びターゲット情報テーブル212が格納される。コンパイル処理はCPU201がコンパイラ(プログラム)208を実行することにより行われる。
<First Embodiment>
FIG. 1 is a configuration diagram of a computer system (compiler) in which a compiler according to the present invention operates. The
ターゲット情報テーブル212は、オブジェクトプログラム207を実行する計算機システム(ターゲットシステム)250(図2参照)の構成に関する情報を予め格納したものである。ターゲット情報テーブル212は、例えば、ターゲットシステム250のCPUの種類や利用可能なレジスタの種類、数及びターゲットシステムで稼働するOSの種類などが予め格納されている。コンパイラ208は、ターゲット情報テーブル212からターゲットシステムの構成を読み込んでオブジェクトプログラム207を生成するコンパイル処理を実行する。
The target information table 212 stores in advance information related to the configuration of a computer system (target system) 250 (see FIG. 2) that executes the
コンパイラ208は、コンパイル処理を行う過程で、ターゲットシステム250のレジスタの割り付け(定義)状態を保持する定義レジスタ情報テーブル210を後述するように作成し、また、定義レジスタ情報テーブル210に格納されたターゲットシステムのレジスタの重要度を設定するレジスタ情報テーブル211を後述のように生成する。
The
なお、外部記憶装置205は、コンパイラ208を格納する記憶媒体として機能する。CPU201は、キーボード203からコンパイラ起動命令を受け付けると、外部記憶装置205からコンパイラ208を主記憶装置204に読み込み、ソースプログラム206を読み込んで、コンパイル処理を実行する。このとき、ターゲット情報テーブル212は予め主記憶装置204に読み込んでおくものとする。
The
なお、図1の主記憶装置204には図示しないOSが読み込まれ、CPU201によってOSが実行され、このOS上でコンパイラ208を実行しても良い。
Note that an OS (not shown) may be read into the
図2は、本発明のコンパイラ208が生成したオブジェクトプログラム207を実行する計算機システム(以下、ターゲットシステムとする)250の構成図である。このターゲットシステム250は、演算処理を行うCPU(またはプロセッサ)251と、情報の表示を行うディスプレイ装置252と、情報の入力を行うキーボード253と、CPU251が利用する情報を格納する主記憶装置254、および情報を格納する外部記憶装置255より構成されている。キーボード253により、ユーザからオブジェクトプログラム207の起動命令を受け付ける。オブジェクトプログラム207の実行結果や終了メッセージまたはエラーメッセージは、ディスプレイ装置252に表示される。外部記憶装置255はHDDや不揮発性メモリで構成され、コンパイル装置200で生成されたオブジェクトプログラム207が格納される。主記憶装置254には、OS270とオブジェクトプログラム207が格納される。OS270は主記憶装置254上にスタック領域260を確保する。
FIG. 2 is a configuration diagram of a computer system (hereinafter referred to as a target system) 250 that executes the
この例では、CPU251のレジスタとしてR1、R2、R3、…、Rn、SP(スタックレジスタ)が存在し、SPに格納されたスタックポインタがスタック領域260のアドレスを指し示す。なお、R1〜R3、…、Rnは、例えば、汎用レジスタを示す。
In this example, R1, R2, R3,..., Rn, SP (stack registers) exist as registers of the
CPU251は、キーボード253からオブジェクトプログラム207の起動命令を受け付けると、外部記憶装置255からオブジェクトプログラム207を主記憶装置254に読み込んで実行する。なお、オブジェクトプログラム207は、図示しないネットワークなどにより、コンパイル装置200からターゲットシステム250に転送されるものとする。
When the
図3は、図1の計算機システム200で稼動するコンパイラ208の処理手順を示す。
FIG. 3 shows a processing procedure of the
コンパイラ208の処理は、ソースプログラム206の構文解析301と、コード最適化302と、レジスタ割り付け303と、オブジェクトコードをオブジェクトプログラム207として生成するコード生成304の順で行う。
The processing of the
構文解析301では、コンパイラ208がソースプログラム206を入力として構文解析を行い、中間コード209を出力する。コード最適化302では、コンパイラ208が中間コード209を入力し、ループ構造変換や部分冗長性削除などの最適化を適用し、その結果を変換後の中間コード209として出力する。
In the
レジスタ割り付け303では、コンパイラ208が中間コード209の各ノード(各処理要素)に対しターゲットシステム250のプロセッサ251のレジスタR1〜R3、…、Rnを割り付ける。コード生成304では、コンパイラ208が中間コード209をオブジェクトプログラム207に変換してオブジェクトプログラム207として出力する。上記構文解析301、コード最適化302及びレジスタ割り付け303は、公知または周知の技術を適用すれば良い。
In the
callee−saveレジスタ(以下、calleeレジスタと略す)退避コード及び回復コード削減処理305は、ソースプログラム206で記述される関数の入口または出口において必要とされる退避コード(Push命令)または回復コード(Pop命令)だけを生成し、出力されるオブジェクトプログラム207のコードサイズを削減する処理であり、コード生成304内で実施される。
A save-save register (hereinafter referred to as “calle register”) save code and recovery
なお、退避コードは、ターゲットシステム250のスタック領域260に、ターゲットシステム250のcalleeレジスタ(例えばR1〜R3)の内容を退避させ、スタックポインタを更新する命令コードである。特に、push命令は、退避するレジスタのサイズ分だけスタックアドレスを減算した後、減算後のスタックアドレスの指す領域に該レジスタのデータをストアする命令である。
The save code is an instruction code that saves the contents of the callee registers (for example, R1 to R3) of the
また、回復コードは、ターゲットシステム250のスタック領域260から、ターゲットシステム250のcalleeレジスタ(例えばR1〜R3)の内容を復帰させ、スタックポインタを更新する命令コードである。特に、pop命令は、スタックアドレスの指す領域から該レジスタにデータをロードした後、当該レジスタのサイズ分だけスタックアドレスを加算する命令である。
The recovery code is an instruction code for restoring the contents of the call register (for example, R1 to R3) of the
図4に、定義レジスタ情報テーブル210の一例を示す。コンパイラ208により主記憶装置204上に生成される。定義レジスタ情報テーブルは、出口ブロック801、定義レジスタ集合802、重み803、処理済フラグ804などの欄からなる。
FIG. 4 shows an example of the definition register information table 210. It is generated on the
出口ブロック801は、ソースプログラム206で記述される関数内に存在する出口ブロック情報を登録する。出口ブロックとは、呼び出された関数で最後に実行される基本ブロックを指すものとする。これに対し、入口ブロックとは、呼び出された関数で最初に実行される基本ブロックを指すものとする。図11に示すソースプログラム206において、入口ブロックは、関数の実際の処理が行われる第3行目の処理を示し、出口ブロックは、呼び出し元に戻る第5行目または第11行目の処理を示し、図11の例では、条件分岐命令の「if」によって関数の出口ブロックが2つ存在する例を示す。
The
定義レジスタ集合802は、関数の入口ブロックから、出口ブロックに至るパス(処理過程)上で中間コード209に定義されているcalleeレジスタの集合を登録する。ここで、calleeレジスタの集合とは、コンパイラ208が上記図3のレジスタ割り付け303の処理で、ある関数についてブロック毎にターゲットシステムのCPU251のレジスタを割り付け(定義)られるので、関数の出口ブロックごとに、入口ブロックから当該出口ブロックまでのパス上で定義(割り付け)されたレジスタの番号(名称)または識別子を列記したものである。
The definition register set 802 registers a set of callee registers defined in the
また、重み803は、各出口ブロックの重要度を登録する。ここで、重要度とは、各出口ブロックがどの程度実行されるかを示した指標であり、重要度が高いほど、その出口ブロックの実行頻度が高いことを示す。この重要度を求める手法としては、コンパイラ208がコンパイル時に求める方法(これを静的手法と呼ぶ)や、コンパイラ208が生成したオブジェクトプログラム207を実行することで求める方法(これを動的手法と呼ぶ)などが考えられる。処理済フラグ804は、コンパイラ208内の各種処理で対応する出口ブロックの処理が終了しているか否かを判定する際に用いるフラグである。
The
図5(a)に、レジスタ情報テーブル211の一例を示す。レジスタ情報テーブル211は、コンパイラ208により主記憶装置204上に生成される。レジスタ情報テーブル211は、レジスタ番号901、重み902、処理済フラグ903などの欄からなる。
FIG. 5A shows an example of the register information table 211. The register information table 211 is generated on the
レジスタ番号901は、ターゲットシステム250のCPU251のレジスタ番号(または識別子)のうち中間コード209で定義されているcalleeレジスタ番号(または識別子)を登録する。重み902は、各レジスタの重要度を登録する。重要度とは、そのレジスタの回復コードがどの程度実行されるかを示した指標であり、重要度が高いほど、そのレジスタの回復コードの実行頻度が高いことを示す。この重要度は、定義レジスタ情報テーブル210の、定義レジスタ集合802と、重み803から計算することができる。詳細は、図8で説明する。処理済フラグ903は、各種処理で対応するレジスタの処理が終了しているか否かを判定する際に用いるフラグである。なお、図5(a)は、レジスタ情報テーブル211のソート前の状態を示し、図5(b)は、calleeレジスタ退避コード及び回復コード削減処理305でソートを行った後の状態を示す。
The
図6に、図3に示したcalleeレジスタ退避コード及び回復コード削減処理305の処理手順を示す。ステップ101で、コンパイラ208は、ソースプログラム206の入口ブロックから、出口ブロックに至るパス上で定義されているレジスタ情報を収集する。なお、ステップ101の処理は、関数毎やサブルーチン毎に行うことができる。
FIG. 6 shows a processing procedure of the callee register save code and recovery
ステップ102は、コンパイラ208がcalleeレジスタの退避順序または回復順序を決定する。ステップ103では、コンパイラ208が関数の入口ブロックにcalleeレジスタの退避コード(例えば、Push命令)を生成する。ステップ104は、コンパイラ208が関数の出口ブロックに、ステップ102で求めた回復順序を考慮したcalleeレジスタの回復コード(例えば、Pop命令)を生成する。この回復順序を考慮することで、不要な回復コードをオブジェクトプログラム207から削減することができる。図6のフローチャートに示したそれぞれの処理の詳細は、図7、図8、図9、図10で説明する。
In
図7に、図6で示した定義レジスタ情報収集101の処理手順を示す。ステップ401では、コンパイラ208が中間コード209を読み込んで、関数内にあるすべての出口ブロックを出口ブロック集合に登録する。なお、出口ブロック集合は変数としてコンパイラ208が主記憶装置204上に所定の領域を確保する。以下に説明する基本ブロック集合、処理済基本ブロック集合等も同様に変数としてコンパイラ208が主記憶装置204上に所定の領域を確保する。
FIG. 7 shows a processing procedure of the definition
ステップ402では、コンパイラ208が出口ブロック集合が空であるか否かを判定する。空でなければ、処理の終了していない出口ブロックが存在しているということなので、ステップ403に進む。ステップ403では、処理の終了していない出口ブロックに対応する定義レジスタ集合802を初期化のため空にする。ステップ404では、処理済基本ブロック集合を初期化のため空にする。これは、同じ基本ブロックを何度も処理しないために設けている。なお、基本ブロックは、ひとつの関数(またはサブルーチン)のうち、一連の演算処理を示し、例えば、図11のソースプログラム206に記述された1行を基本ブロックとして扱う。
In
ステップ405では、基本ブロック集合に出口ブロック集合を登録する。ステップ406では、基本ブロック集合が空か否かを判定する。基本ブロック集合が空の場合は、ステップ411に進む。基本ブロック集合が空でない場合は、ステップ407に進む。ステップ407では、基本ブロック集合から先頭要素を取り出す。取り出した先頭要素は基本ブロック集合から削除する。
In
ステップ408では、コンパイラ208がステップ407で取り出した基本ブロックに対し、基本ブロック内の全命令を辿り、それぞれの命令で定義されているレジスタを定義レジスタ情報テーブル210の定義レジスタ集合802に登録していく。ステップ409では、処理の終了した基本ブロックを、処理済基本ブロック集合に登録する。ステップ410では、ステップ407で取り出した基本ブロックの直前に実行される基本ブロックを辿り、直前に実行される基本ブロックが処理済基本ブロック集合に登録されていなければ、当該基本ブロックを基本ブロック集合に登録し、ステップ406に戻る。
In
上記ステップ406〜ステップ410の処理を繰り返すことで、入口ブロックからある出口ブロックに至るパス上で定義されている定義レジスタ集合を求めることができる。
By repeating the processing of
定義レジスタ集合を求めた後は、基本ブロック集合が空になっているはずなので、ステップ406の判定により、ステップ411に進む。ステップ411では、出口ブロックと定義レジスタ集合の組を定義レジスタ情報テーブル210へ登録する。
Since the basic block set should be empty after the definition register set is obtained, the process proceeds to step 411 based on the determination in
コンパイラ208が定義レジスタ情報テーブル210へ定義レジスタ情報802を登録することにより、入口ブロックから出口ブロックに至るパス上で定義されているレジスタ情報が図4で示すように明確になる。定義レジスタ情報テーブル210に定義されているレジスタは、出口ブロックにおいて回復の必要なレジスタとなる。よって、入口ブロックで退避されたレジスタであっても、この定義レジスタ集合に登録されてないレジスタは、回復不要なレジスタとみなすことができる。この回復不要なレジスタを抽出することで、オブジェクトプログラム207に挿入する回復コードが削減可能となるのである。つまり、ソースプログラム206で記述された処理の手順でコンパイル処理を行った場合、オブジェクトプログラム207に生成される回復コードのうち、実際には機能しない回復コードを抽出して、当該回復コードをオブジェクトプログラム207に加えるのを阻止することができる。
When the
ステップ412では、処理の終了した出口ブロックを、出口ブロック集合から削除し、ステップ402に戻る。ステップ402では、出口ブロック集合が空の場合、つまり、すべての出口ブロックの処理が終了した場合は、ステップ413に進む。ステップ413では、定義レジスタ情報テーブルに登録されている出口ブロックに対し、そのブロックの重要度を表現する重みという値を設定する。この重みが重い(大きい)ほど、その出口ブロックの定義レジスタ集合に登録されているレジスタの重要度が高くなる。
In
この重みを設定する手法として、上述したような静的に設定する手法と、動的に設定する手法などが存在する。静的に設定する手法は、コンパイラ208自身が各出口ブロックの重みを決定するものである。動的に設定する手法は、予め関数出口の実行回数をカウントするコードを埋め込んだオブジェクトプログラムを実行させ、関数出口の実行回数情報を取得した後、取得した実行回数情報をコンパイラ208が読み込み、実行回数からコンパイラ208が重みを計算して設定する。この動的な関数出口の重み付けの場合では、関数出口の実行回数情報を、ターゲット情報テーブル212で関数毎に設定しておけばよい。静的に設定する手法は、一度のコンパイルで重みを決定するため、オブジェクトプログラム207を実行しなくて良いという利点があるが、コンパイラ208の決めた重みと実際のプログラム(オブジェクトプログラム207)の動作が大きく異なる可能性があるという欠点がある。
As a method for setting the weight, there are a static setting method as described above, a dynamic setting method, and the like. In the static setting method, the
一方、動的に重みを設定する手法では、オブジェクトプログラム207をターゲットシステム250で一度実行させる手間がかかるという欠点があるが、得られた情報が実際のプログラム動作と一致しているという利点がある。
On the other hand, the method of dynamically setting the weight has the disadvantage that it takes time to execute the
図8に、calleeレジスタの退避順序及び回復順序の決定102の処理手順を示す。ステップ501では、コンパイラ208がレジスタ情報テーブル211の重みをクリアして初期化する。ステップ502では、コンパイラ208が定義レジスタ情報テーブル210の処理済フラグをクリアして初期化する。
FIG. 8 shows a processing procedure for determining the save order and
ステップ503では、コンパイラ208が定義レジスタ情報テーブル210の処理済フラグ804を読み込んで、すべての出口ブロックが処理済か否かを判定する。出口ブロックが処理済か否かは、定義レジスタ情報テーブル210に登録されている出口ブロックに対する処理済フラグ804がすべて設定されているか否かで判定する。すべての出口ブロックが処理済の場合は、ステップ509に進む。一方、すべての出口ブロックが処理済でない場合は、ステップ504に進む。
In
ステップ504では、コンパイラ208が処理対象とした出口ブロックに対応する定義レジスタ情報テーブル210の処理済みフラグをセットする。ステップ505では、コンパイラ208がまだ処理されてない出口ブロックに対応する定義レジスタ集合を定義レジスタ情報テーブル210から取り出し、ステップ506に進む。
In
ステップ506では、前記取り出した定義レジスタ集合をすべて処理したか否かを判定する。取り出した定義レジスタ集合がすべて処理済の場合は、ステップ503に戻り、次の出口ブロックの処理を行う。一方、取り出した定義レジスタ集合が、まだ処理されてない場合は、ステップ507に進む。ステップ507では、定義レジスタ集合から1つレジスタを取り出し、このレジスタの重みをステップ508で設定する。
In
ステップ508では、出口ブロック情報から定義レジスタ情報テーブル210に登録されている重み803を取り出す。さらに、処理対象のレジスタのレジスタ情報テーブル211に、ステップ508で取り出した重みを加算する。
In
上記ステップ503〜ステップ508までを繰り返すことで、定義レジスタ情報テーブル210の定義レジスタ集合に対してコンパイラ208が設定した重み803が、各レジスタに対する重みとしてレジスタ情報テーブル211に加算される。すべてのレジスタの重みが設定された後は、ステップ509に進み、重みが降順になるようにレジスタ情報テーブル211をソートする。ソート後は、図5(b)のように、レジスタ情報テーブル211の先頭(図中最上方のエントリ)から、重要と判定したレジスタが配置される。
By repeating
図9に、calleeレジスタの退避コード生成103の処理手順を示す。ステップ601では、コンパイラ208が中間コード209を読み込んで、入口ブロック集合に入口ブロックを登録する。なお、入口ブロック集合は変数としてコンパイラ208が主記憶装置204上に所定の領域を確保する。また、入口ブロックは、図11で示したように、ひとつの関数(またはサブルーチン)のうち最初の演算処理を行う基本ブロックであり、図11のソースプログラム206において、関数の最初の演算処理を行う行を指す。
FIG. 9 shows a processing procedure of the save
ステップ602では、入口ブロック集合が空か否かを判定する。空の場合は、処理を終了する。入口ブロック集合が空でない場合は、ステップ603に進む。ステップ603では、入口ブロック集合から先頭要素を取り出す。そして、取り出した先頭要素は基本ブロック集合から削除する。
In
ステップ604では、処理対象としている入口ブロックで、退避コードを挿入するための基準点となる命令を登録する。本実施形態では、ターゲットシステム250のスタックアドレス(スタックポインタ)を保持するスタックレジスタSPの更新を行う命令(例えば、add命令)を基準点として登録する。
In
ステップ605では、コンパイラ208がレジスタ情報テーブル211の処理済フラグ903をすべてクリアして初期化する。ステップ606では、すべてのレジスタの退避コードが生成されているか否かを判定する。この判定は、レジスタ情報テーブル211の処理済フラグ903がすべてセットされているか否かで行う。処理済フラグ903がすべてセットされている場合は、ステップ602に戻る。処理済フラグ903がすべてセットされてない場合は、ステップ607に進む。
In
ステップ607では、コンパイラ208がレジスタ情報テーブル211の先頭(図中最上方のエントリ)から後方(図中最下方のエントリ)へテーブルを辿りながら、処理済フラグ903がセットされてないレジスタの退避コードを生成する。退避コードは、例えば、push命令を用いる。ステップ607で生成された退避コードは、ステップ604で設定した、挿入基準命令の直前に挿入する。
In
ステップ608では、コンパイラ208が退避コードの生成を終えたレジスタに対応する、レジスタ情報テーブル211の処理済フラグ903をセットする。
In
上記ステップ606〜ステップ608までの処理を繰り返すことで、ソースプログラム206で記述された基本ブロックの入口ブロックにおいて必要なcalleeレジスタの退避コードを生成することができる。
By repeating the processing from
図10に、calleeレジスタの回復コード生成104の処理手順を示す。ステップ701では、コンパイラ208が定義レジスタ情報テーブル210の処理済フラグ804をすべてクリアして初期化する。ステップ702では、全ての出口ブロックが処理済か否かを判定する。この判定は、定義レジスタ情報テーブル210の処理済フラグ804がすべてセットされているか否かで行う。処理済フラグ804がすべてセットされている場合は、処理を終了する。
FIG. 10 shows a processing procedure of the
一方、処理済フラグ804がすべてセットされてない場合は、ステップ703に進む。ステップ703では、処理対象とした出口ブロックに対応する定義レジスタ情報テーブル210の処理済みフラグ804をセットする。ステップ704では、処理対象としている出口ブロックで、回復コードを挿入するための基準点となる命令を登録する。基準点となる命令は、上述の入口ブロックの基準点と同様に、スタックレジスタSPの更新を行う命令(例えば、Pop命令)とする。
On the other hand, if all the processed
ステップ705では、コンパイラ208が回復コード削減サイズの初期化を行う。この回復コード削減サイズが、0であるか否かを判定することで、ある出口ブロックにおいて回復コードを削減したか否かが判定可能となる。なお、回復コード削減サイズは、コンパイラ208が変数として主記憶装置204上に確保する。
In
ステップ706では、コンパイラ208がレジスタ情報テーブル211の処理済フラグ903をすべてクリアする。ステップ707では、すべてのレジスタが処理済か否かを判定する。この判定は、レジスタ情報テーブル211の処理済フラグ903がすべてセットされているか否かで行う。処理済フラグ903がすべてセットされている場合は、ステップ712に進む。処理済フラグ903がすべてセットされてない場合は、ステップ708に進む。
In
ステップ708では、レジスタ情報テーブル211の先頭から後方へテーブルを辿りながら、最初に見つけた処理済フラグ903の設定されてないレジスタ番号に対し、当該出口ブロックで回復コードが必要か否かを判定する。この判定は、当該出口ブロックに対応する定義レジスタ情報テーブル210の定義レジスタ集合802に、当該レジスタが登録されているか否かで行う。当該出口ブロックに対応する定義レジスタ情報テーブル210の定義レジスタ集合802に、当該レジスタが登録されてない場合は、入口ブロックから当該出口ブロックに至るパス上で、このレジスタの定義が行われてないと判定されるので、回復コードを生成する必要はなく、ステップ710に進む。
In
ステップ710では、削減したレジスタのサイズを記憶しておくために、コンパイラ208が上記ステップ708で回復コードの必用がないと判定したレジスタのサイズを回復コード削減サイズに加算する。
In
一方、定義レジスタ情報テーブル210の定義レジスタ集合802に当該レジスタが登録されている場合は、回復コードが必要になるため、ステップ709で回復コードを生成し、ステップ704で設定した挿入基準点の直後に挿入する。回復コードは、例えば、pop命令を用いる。
On the other hand, if the register is registered in the definition register set 802 of the definition register information table 210, a recovery code is required. Therefore, a recovery code is generated in
ステップ711では、コンパイラ208が上記回復コードの処理を終えたレジスタに対応するレジスタ情報テーブル211の処理済フラグ903をセットし、ステップ707に戻る。ステップ712では、当該出口ブロックでの回復コード削減サイズが0であるか否かを判定する。回復コード削減サイズが0の場合は、回復コードの削減が行われてないと判定して、ステップ702に戻る。回復コード削減サイズが0以外の場合は、回復コードの削減が行われていると判定して、ステップ713に進む。
In
ステップ713では、コンパイラ208が回復コードの削減が行われた出口ブロックに対し、出口ブロックのスタックレジスタSPの更新命令に削減サイズを反映させる。この反映処理により、push/pop命令利用時に回復コードを削減しても正しいコードを生成することができる。
In
以上の処理により、関数の出口毎に回復コードが挿入されるが、関数の出口が複数存在する場合は、各関数出口で関数の入口で挿入した退避コードに対応するすべてのレジスタについて回復する必用はなく、関数入口から当該関数出口までのパス上で割り付けられたレジスタのみについて回復コードを生成することになる。この結果、前記従来例では、関数入口で退避したレジスタについて、関数出口ですべてのレジスタに対して回復コードを生成したのに対し、本発明では、関数入口から関数出口のパス上で定義されていないレジスタについては退避コードの生成を行わず、オブジェクトプログラム207のサイズを削減できる。そして、回復コードを削減したレジスタについては、レジスタのサイズに相当するスタックアドレスを補正することで、回復コードの生成を省略しながら正常なオブジェクトプログラム207を生成することができる。
With the above processing, a recovery code is inserted for each function exit. However, if there are multiple function exits, it is necessary to recover all registers corresponding to the save code inserted at the function entry at each function exit. Rather, the recovery code is generated only for the registers allocated on the path from the function entry to the function exit. As a result, in the conventional example, for the registers saved at the function entry, recovery codes are generated for all the registers at the function exit, whereas in the present invention, they are defined on the path from the function entry to the function exit. For the registers that do not exist, the size of the
図11のプログラム(ソースプログラム206)例を参照して本実施形態における回復コード削減処理手順を示す。 A recovery code reduction processing procedure in the present embodiment will be described with reference to the example of the program (source program 206) in FIG.
図11のプログラム例はC言語で記述してある。このソースプログラム206、引数で渡された配列とその要素数から、配列要素の合計を求めるものである。また、4行目で配列が存在しない場合は5行目で配列要素の合計として0を返却し、配列が存在する場合は、8行目から10行目の繰り返し文により、配列要素の合計を計算し、11行目で合計を返却する。そのため、このソースプログラム206では、関数出口が5行目と11行目の2箇所存在する。この2箇所の関数出口が上述した出口ブロックとしてコンパイラ208で処理され、また、関数の入口となる3行目が入口ブロックとしてコンパイラ208で処理される。なお、1行目などは、コンパイラ208に対する定義分であるため、コード生成304では基本ブロックとして扱わないものとする。
The program example of FIG. 11 is described in C language. The
本ソースプログラム206に対し、コンパイラ208がレジスタ割り付けを行った結果、入口から11行目の出口1に至るパス上で定義されたレジスタが図1で示したターゲットシステム250のCPU251のレジスタR1、R2、R3であり、入口から5行目の出口2に至るパス上で定義されたレジスタがR3であったとし、それぞれの出口ブロックの重みが出口1で0.8、出口2で0.2であったとする。この状態でステップ101の定義レジスタ情報収集処理を適用すると、図4の定義レジスタ情報テーブル210が求められる。
As a result of the register assignment by the
次に、図4の定義レジスタ情報テーブルに対し、コンパイラ208はステップ102のcalleeレジスタの退避・回復順序を決定する処理を適用した結果を図5(a)に示す。
Next, FIG. 5A shows the result of applying the processing for determining the save / restore order of the callee register in
図4の定義レジスタ情報テーブル210において、まず、出口1では、定義レジスタ集合802にレジスタR1、R2、R3が定義されており、出口ブロックの重みが0.8と登録されているため、図5(a)のレジスタ情報テーブル211のR1、R2、R3の重みに0.8がそれぞれ設定される。図4の定義レジスタ情報テーブル210の出口2では、定義レジスタ集合802にレジスタR3だけが定義されており、出口ブロックの重みが0.2と登録されているため、レジスタ情報テーブル211のレジスタR3だけに重み0.2を加算する。その結果図5(a)で示す状態のレジスタ情報テーブル211が得られる。図5(a)のレジスタ情報テーブル211に対し、重み902に従って降順にソートした結果が図5(b)のレジスタ情報テーブル211である。
In the definition register information table 210 of FIG. 4, first, in the
図5(b)において、レジスタR3は、出口1から出る場合でも出口2から出る場合でもレジスタの回復コードが必要になるため、レジスタR1やレジスタR2よりも重要であると判定されている。つまり、出口1では、入口で退避したすべてのレジスタR1〜R3の回復が必用になるのに対し、出口2では、入口から出口2までのパス上でレジスタR3のみが定義されるだけである。このため、コンパイラ208は、出口2ではレジスタR3のみの退避コードを生成し、レジスタR1、R2の退避コードを省略することができる。
In FIG. 5B, the register R3 is determined to be more important than the register R1 and the register R2 because the register recovery code is required both when exiting from the
従来技術において図11のソースプログラム206の退避コードと、回復コードを生成した例を図12に示す。図12(a)の退避コードでは、レジスタR1、R2、R3が順番にスタック上にpush命令で退避され、その後でワーク領域を確保するためにスタックアドレス更新命令(add SP、−α)が実行されている。また、従来技術による図12(b)の回復コードでは、まずワーク領域を解放するためにスタックアドレス更新命令(add SP、α)が実行された後、レジスタR3、R2、R1の順番でスタック上からpop命令で回復されている。
FIG. 12 shows an example in which the save code and the recovery code of the
次に、図4の定義レジスタ情報テーブルと、図5(a)、図5(b)のレジスタ情報テーブルから生成される本実施形態による退避コード及び回復コードの例を図13、図14に示す。 Next, examples of the save code and the recovery code according to the present embodiment generated from the definition register information table of FIG. 4 and the register information tables of FIGS. 5A and 5B are shown in FIGS. .
図13(a)、図13(b)は、本発明により回復レジスタの削減がない出口1で退避コードと回復コードを生成した例を示している。
FIGS. 13A and 13B show an example in which the save code and the recovery code are generated at the
図13(a)の退避コードでは、重み付けに応じた順序でレジスタR3、R1、R2がスタック領域上にpush命令で退避され、その後でワーク領域を確保するためにスタックアドレス更新命令(add SP、−α)が実行されている。また、図13(b)の回復コードでは、まずワーク領域を解放するためにスタックアドレス更新命令(add SP、α)が実行された後、重み付けに応じた順序でレジスタR2、R1、R3がスタック上からpop命令で回復されている。前記従来例の図12(b)の回復コードは、退避したレジスタの逆順でレジスタの回復が行われる。この従来例に対して、本発明では図13(b)で示すように、POP命令を実行するレジスタの順序が重みに応じてR2、R1、R3の順でレジスタの回復を実行する。なお、関数入口のレジスタの退避コードの順位は、関数出口の重みの順位を援用する。 In the save code of FIG. 13A, the registers R3, R1, and R2 are saved on the stack area by a push instruction in the order according to the weighting, and then a stack address update instruction (add SP, -Α) is being executed. In the recovery code of FIG. 13B, first, a stack address update instruction (add SP, α) is executed to release the work area, and then the registers R2, R1, and R3 are stacked in the order according to the weighting. It has been recovered from above with the pop instruction. In the recovery code shown in FIG. 12B of the conventional example, the registers are recovered in the reverse order of the saved registers. In contrast to this conventional example, in the present invention, as shown in FIG. 13B, the order of the registers that execute the POP instruction is restored in the order of R2, R1, and R3 according to the weight. Note that the rank of the function exit register uses the rank of the function exit weight.
図14(b)は、回復レジスタの削減がある出口2での回復コードを示している。レジスタの重要度を考慮してレジスタの退避順序と回復順序を決定することにより、図14(b)の回復コードでレジスタR1とレジスタR2の回復コードを削減した場合でも、回復コードであるpop命令でのスタックアドレス更新サイズ(=削減レジスタサイズ)を、スタックレジスタ更新命令の更新サイズα+8に反映させることにより、上記従来例のように余計な命令を挿入することなく、回復コードの削減を行うことができる。
FIG. 14B shows the recovery code at
すなわち、図14(a)の退避コードでは、上記出口1と同様に、重み付けに応じた順でレジスタR3、R1、R2がスタック領域上にpush命令で退避され、その後でワーク領域を確保するためにスタックアドレス更新命令(add SP、−α)が実行される。
That is, in the save code shown in FIG. 14A, as in the case of the
そして、図14(b)の回復コードでは、まずワーク領域を解放するためにスタックアドレス更新命令が実行されるが、このとき、回復コードを削除するレジスタの数に応じてスタックアドレスが補正される。この例では、レジスタR1、R2の回復コードを削除するので、各レジスタR1〜R3のサイズを4バイトとすると、2つのレジスタ分の8バイトが削除レジスタサイズとなる。このため、スタックアドレス更新命令は、(add SP、α+8)となって、2つ分のレジスタに相当するスタックアドレスがシフトする。 In the recovery code of FIG. 14B, a stack address update instruction is first executed to release the work area. At this time, the stack address is corrected according to the number of registers from which the recovery code is deleted. . In this example, since the recovery codes of the registers R1 and R2 are deleted, if the size of each of the registers R1 to R3 is 4 bytes, 8 bytes for two registers become the deletion register size. Therefore, the stack address update instruction is (add SP, α + 8), and the stack addresses corresponding to two registers are shifted.
スタックアドレス更新命令が実行された後、重み付けに応じて選択されたレジスタR3のみがスタック領域からpop命令で回復されている。 After the stack address update instruction is executed, only the register R3 selected according to the weight is restored from the stack area with the pop instruction.
このように関数出口2では、連続したレジスタR1とR2の回復が不要とコンパイラ208は判定し、レジスタR3のみを回復すればよい。このため、コンパイラ208は、2つのpop命令の代わりに1つのスタックアドレス更新命令(add SP+8)を実行して、削除するレジスタの数に応じてスタックアドレスを補正してからレジスタR3のPOP命令を生成する。この結果、ターゲットシステム250でオブジェクトプログラム207を実行すると、図14(a)の退避コードでレジスタR3,R1、R2の順でスタック領域260に各レジスタの内容を退避させてからαバイトのワーク領域を確保する。
As described above, at the
関数出口2では、αバイトのワーク領域を解放し、かつ、スタックアドレスに回復コードを削除した2つのレジスタR1、R2のサイズに相当する8バイトを加算してからレジスタR3をPOP命令で回復する。これにより、2つの回復コードを削減しながらスタックレジスタSPのスタックアドレスを各レジスタR1〜R3の退避以前の状態に復帰させて、オブジェクトプログラム207を正常に実行させることができる。
このように、本第1の実施形態によれば、複数の関数出口が存在する関数のオブジェクトコードを生成する場合には、callee−saveレジスタの不要な回復コードが削減可能となって、オブジェクトプログラム207のコードサイズを削減し、実行性能の良いオブジェクトプログラム(実行コード)を生成することが可能になる。 As described above, according to the first embodiment, when generating an object code of a function having a plurality of function exits, unnecessary recovery code in the callee-save register can be reduced, and the object program can be reduced. It is possible to reduce the code size of 207 and generate an object program (execution code) with good execution performance.
また、不要な回復コードの生成を削除した分、スタックアドレスを補正するが、このとき作成しなかった回復コードのそれぞれについてスタックレジスタの更新命令を生成すると、オブジェクトコードの削減ができないが、本発明のように、関数出口のレジスタに重みを設定して、重みの降順にソートしてから複数のレジスタ更新命令を一つにまとめるようにしたので、コンパイラ208が生成するオブジェクトコードのサイズを低減することが可能となる。
Further, although the stack address is corrected by deleting unnecessary recovery code generation, if the stack register update instruction is generated for each recovery code not created at this time, the object code cannot be reduced. As described above, since the weights are set in the function exit registers and sorted in descending order of the weights, a plurality of register update instructions are combined into one, so that the size of the object code generated by the
<第2実施形態>
図15、図16に、calleeレジスタ退避・回復コード削減処理の第2の実施形態を示す。
<Second Embodiment>
15 and 16 show a second embodiment of callee register save / restore code reduction processing.
図15は、前記第1の実施形態の図3に示したcalleeレジスタ退避コード及び回復コード削減処理305の第2の処理手順を示すフローチャートである。
FIG. 15 is a flowchart showing a second processing procedure of the callee register saving code and recovery
ステップ101では、コンパイラ208が前記第1の実施形態と同様に中間コード209を読み込んで、入口ブロックから、出口ブロックに至るパス上で定義されているレジスタ情報を収集する。ステップ103では、コンパイラ208が関数入口ブロックにcalleeレジスタの退避コードを生成する。ステップ1504は、コンパイラ208がcalleeレジスタの回復コードを生成する。
In
図16に、図15で示したcalleeレジスタの回復コード生成1504の処理手順を示す。この回復コード生成処理1504では、回復が不要と判定したレジスタに対し、pop命令の代わりに、スタックアドレスを更新する命令を挿入する。スタックアドレス更新命令とは、スタックアドレスを保持するスタックレジスタ(SP)に、レジスタサイズ分の定数を加算するものである。そして、スタックアドレスを更新する命令が連続して挿入された場合、当該連続する命令を1つの命令にまとめることで、回復コードの削減を行うものである。例えば、連続する2命令を1命令にまとめた場合、スタックアドレス更新命令の定数部分は、レジスタサイズ×2となる。以下、回復コード生成処理1504の処理手順を説明する。
FIG. 16 shows a processing procedure of the
ステップ1601では、コンパイラ208が定義レジスタ情報テーブル210の処理済フラグ804をすべてクリアして初期化する。ステップ1602では、全ての出口ブロックが処理済か否かを判定する。この判定は、定義レジスタ情報テーブル210の処理済フラグ804がすべてセットされているか否かで行う。処理済フラグ804がすべてセットされている場合は、処理を終了する。一方、処理済フラグ804がすべてセットされてない場合は、ステップ1603に進む。ステップ1603では、処理対象とした出口ブロックに対応する定義レジスタ情報テーブル210の処理済みフラグ804をセットする。ステップ1604では、処理対象としている出口ブロックで、回復コードを挿入するための基準点となる命令を登録する。基準点となる命令は、前記第1の実施形態で述べたように入口ブロックの基準点と同様に、スタックレジスタの更新を行う命令とする。
In
ステップ1605では、コンパイラ208が連続するスタックアドレス更新命令を1つにまとめる際に利用する領域を初期化し、スタックアドレス更新命令を未登録の状態にする。ステップ1606では、レジスタ情報テーブル211の処理済フラグ903をすべてクリアして初期化する。ステップ1607では、すべてのレジスタが処理済か否かを判定する。この判定は、レジスタ情報テーブル211の処理済フラグ903がすべてセットされているか否かで行う。処理済フラグ903がすべてセットされている場合は、ステップ1602に戻る。一方、処理済フラグ903がすべてセットされてない場合は、ステップ1608に進む。ステップ1608では、レジスタ情報テーブル211の先頭から後方へテーブルを辿りながら、最初に見つけた処理済フラグ903がセットされてないレジスタ番号に対し、当該出口ブロックで回復コードが必要か否かを判定する。この判定は、当該出口ブロックに対応する定義レジスタ情報テーブル210の定義レジスタ集合802に、当該レジスタが登録されているか否かで行う。定義レジスタ集合802に当該レジスタが登録されている場合は、回復コードが必要になるため、ステップ1609で回復コードを生成し、ステップ1604で設定した挿入基準点の直後に挿入する。回復コードは、例えば、pop命令を用いる。
In
ステップ1610では、スタックアドレス更新命令の登録状態(変数)を初期化し、スタックアドレス更新命令を未登録の状態にする。スタックアドレス更新命令は、連続したスタックアドレス命令を1つにまとめるためのものなので、回復コードでpop命令が生成された場合は、登録状態を初期化する必要がある。ステップ1608で、コンパイラ208は、定義レジスタ集合802に当該レジスタが登録されてない場合は、入口ブロックから当該出口ブロックに至るパス上で、このレジスタの定義が行われてないと判定されるので、回復コードを生成する必要はなく、ステップ1611に進む。
In
ステップ1611では、スタックアドレス更新命令が登録済か否かを判定する。この判定は、スタックアドレス更新命令の登録状態(変数)を参照して既登録であるか否かを判定すればよい。スタックアドレス更新命令が登録されている場合は、コンパイラ208が回復コードで連続してスタックアドレス更新命令が生成されたと判定するので、命令の削減処理を行う。命令の削減は、当該レジスタに対するアドレス更新命令を生成せず、当該レジスタのサイズ分を、スタックアドレス更新命令として登録されている命令の定数加算部分に反映させることで行える。
In
この定数加算値を修正する処理をステップ1612で行う。ステップ1611で、スタックアドレス更新命令の登録状態に登録されてない場合は、ステップ1613に進む。ステップ1613では、回復コードが不要と判定されたものについて、スタックアドレス更新命令を作成し、ステップ1604で設定した挿入基準点の直後に挿入する。そして、ステップ1614で、スタックアドレス更新命令を登録する。これらの処理が終了した後は、ステップ1615でレジスタ情報テーブル211の処理済フラグ903を設定し、ステップ1607に戻る。
In
上記処理によって、連続するレジスタの回復コードが不要と判定された場合、pop命令を利用せず、1つのスタックアドレス更新命令でスタックアドレスを操作することにより、回復コードサイズを削減することができる。 If it is determined by the above processing that recovery codes of consecutive registers are unnecessary, the recovery code size can be reduced by manipulating the stack address with one stack address update instruction without using the pop instruction.
次に、図4の定義レジスタ情報テーブルと、図5(a)、図5(b)のレジスタ情報テーブルから生成される本第2実施形態による回復コードの例を図17(b)に示す。前記従来例の図12(b)では、回復レジスタの削減がない出口1での回復コードを示している。本第2の実施形態の図17(b)は、回復レジスタの削減がある出口2での回復コードを示している。図17(b)に示す出口2では、連続したレジスタR1とR2の回復が不要と判定されているため、2つのpop命令の変わりに1つのアドレス更新命令(add SP,8)が生成されるため、回復コードサイズを削減することができる。この例ではひとつのレジスタサイズを4バイトとしているため、スタックアドレス更新命令の定数部分は8(=4×2)となる。
Next, FIG. 17B shows an example of the recovery code according to the second embodiment generated from the definition register information table of FIG. 4 and the register information tables of FIGS. 5A and 5B. FIG. 12B of the conventional example shows a recovery code at the
以上のように、第2の実施形態においても、callee−saveレジスタの不要な回復コードが削減可能となって、オブジェクトプログラムのコードサイズを削減し、実行性能の良いオブジェクトプログラム(実行コード)を生成することが可能になる。 As described above, even in the second embodiment, unnecessary recovery code in the callee-save register can be reduced, the object program code size can be reduced, and an object program (execution code) with good execution performance can be generated. It becomes possible to do.
なお、上記各実施形態においては、ソースプログラム206からオブジェクトプログラム207を生成する計算機と、オブジェクトプログラム207を実行する計算機(ターゲットシステム250)が異なる例を示したが、ひとつの計算機で、コンパイル処理とオブジェクトプログラム207の実行を行っても良い。この場合、ターゲット情報テーブル212は、計算機200のリソースについて記載しておけばよい。
In each of the above embodiments, an example is shown in which the computer that generates the
以上のように、本発明では、ソースプログラムをオブジェクトプログラムに変換する処理でスタック操作命令(push/pop命令)を利用してcallee−saveレジスタ退避コードおよび回復コードを生成するコンパイル装置、コンパイラに適用できる。 As described above, the present invention is applied to a compiling device and a compiler that generate a callee-save register save code and a recovery code using a stack operation instruction (push / pop instruction) in a process of converting a source program into an object program. it can.
101 定義レジスタ情報収集処理
102 退避・回復順序の決定処理
103 退避コード生成処理
104 回復コード生成処理
200 計算機システム(コンパイル装置)
206 ソースプログラム
207 オブジェクトプログラム
208 コンパイラ
210 定義レジスタ情報テーブル
211 レジスタ情報テーブル
212 ターゲット情報テーブル
250 計算機システム(ターゲットシステム)
101 definition register
206
Claims (7)
前記ソースプログラムを読み込んで中間コードを生成する構文解析部と、
前記中間コードを読み込んで、前記オブジェクトプログラムを実行する計算機を構成する第2のプロセッサのレジスタを前記中間コードに割り付けるレジスタ割り付け部と、
前記レジスタに割り付けた中間コードからオブジェクトコードを生成し、オブジェクトプログラムを出力するコード生成部、とを備え、
前記記憶部は、
前記第2のプロセッサのレジスタの情報を格納したターゲット情報と、
前記関数に割り付けられた前記レジスタの情報を格納する第1のレジスタ情報と、
前記レジスタの退避順序と回復順序を格納する第2のレジスタ情報と、
を有し、
前記コード生成部は、
前記関数の入口及び出口に割り付けられた前記レジスタの情報を収集して前記第1のレジスタ情報に格納する定義レジスタ情報収集部と、
前記第1のレジスタ情報を読み込んで、前記関数の入口及び出口に割り付けられた前記レジスタの退避順序と回復順序を決定する退避・回復順序決定部と、
前記退避・回復順序決定部が決定した退避順序と回復順序に従って前記レジスタの退避コードと回復コードを生成する退避・回復コード生成部と、を有し、
退避・回復コード生成部は、
前記レジスタの退避順序に従ってレジスタの退避コードを前記関数の入口に生成し、前記第1のレジスタ情報と前記退避順序及び回復順序から前記関数の入口から出口に至るパス上で割り付けられているレジスタに対して、前記関数の出口毎にそれぞれ回復コードを生成し、前記パス上で定義されてないレジスタのサイズの和を求め、前記関数の出口でスタックアドレスを前記レジスタのサイズの和だけ補正するスタックアドレスの更新命令を生成することを特徴とするコンパイル装置。 In a compiling apparatus that includes a first processor that performs arithmetic processing and a storage unit that stores information used by the processor, and that reads a source program including a function and generates an object program including a stack operation instruction.
A parsing unit that reads the source program and generates intermediate code;
A register allocating unit that reads the intermediate code and allocates a register of a second processor constituting a computer that executes the object program to the intermediate code;
A code generation unit that generates an object code from the intermediate code assigned to the register and outputs an object program;
The storage unit
Target information storing register information of the second processor;
First register information for storing information of the register allocated to the function;
Second register information for storing the save order and recovery order of the registers;
Have
The code generator is
A definition register information collection unit that collects information of the registers allocated to the entry and exit of the function and stores the information in the first register information;
A save / restore order determining unit that reads the first register information and determines a save order and a restore order of the registers assigned to the entry and exit of the function;
A save / recovery code generation unit that generates a save code and a recovery code of the register according to the save order and the recovery order determined by the save / recovery order determination unit;
The evacuation / recovery code generator
A register save code is generated at the entry of the function according to the save order of the registers, and the first register information and the registers allocated on the path from the save order to the exit from the save order and the recovery order On the other hand, a stack that generates a recovery code for each exit of the function, calculates a sum of register sizes that are not defined on the path, and corrects a stack address at the exit of the function by the sum of the register sizes. A compiling device for generating an address update instruction.
前記退避・回復順序決定部は、
前記関数の出口に割り付けられたレジスタについて重み付けを行い、前記重みの順位に基づいて回復コードを生成するレジスタの順位を決定することを特徴とするコンパイル装置。 The compiling device according to claim 1,
The evacuation / recovery order determination unit
A compiling apparatus that weights a register assigned to an exit of the function and determines a rank of a register that generates a recovery code based on the rank of the weight.
前記ターゲット情報は、前記第2のプロセッサで前記オブジェクトプログラムを実行したときの関数出口の実行回数を予め格納し、
前記退避・回復順序決定部は、
前記ターゲット情報から関数出口の実行回数を読み込んで、前記実行回数の大きさから前記重みを求めることを特徴とするコンパイル装置。 The compiling device according to claim 2,
The target information stores in advance the number of executions of the function exit when the object program is executed by the second processor,
The evacuation / recovery order determination unit
A compiling device, wherein the number of executions of a function exit is read from the target information, and the weight is obtained from the size of the execution times.
前記退避コードは、前記レジスタのサイズに相当するバイト数でスタックアドレスを減算した後、減算後のスタックアドレスが指す領域に前記レジスタのデータをストアし、
前記回復コードは、前記スタックアドレスの指す領域から前記レジスタにデータをロードした後、当該レジスタのサイズに相当するバイト数を前記スタックアドレスに加算することを特徴とするコンパイル装置。 The compiling device according to claim 1,
The save code, after subtracting the stack address by the number of bytes corresponding to the size of the register, stores the data of the register in the area pointed to by the stack address after the subtraction,
The compile apparatus, wherein after the data is loaded from the area indicated by the stack address to the register, the recovery code adds the number of bytes corresponding to the size of the register to the stack address.
前記ソースプログラムを読み込んで中間コードを生成する構文解析部と、
前記中間コードを読み込んで、前記オブジェクトプログラムを実行する計算機を構成する第2のプロセッサのレジスタを前記中間コードに割り付けるレジスタ割り付け部と、
前記レジスタに割り付けた中間コードからオブジェクトコードを生成し、オブジェクトプログラムを出力するコード生成部、とを備え、
前記記憶部は、
前記第2のプロセッサのレジスタの情報を格納したターゲット情報と、
前記関数に割り付けられた前記レジスタの情報を格納する第1のレジスタ情報と、
を有し、
前記コード生成部は、
前記関数の入口及び出口に割り付けられた前記レジスタの情報を収集して前記第1のレジスタ情報に格納する定義レジスタ情報収集部と、
前記定義レジスタ情報収集部が割り付けた前記レジスタの退避コードと回復コードを生成する退避・回復コード生成部と、を有し、
退避・回復コード生成部は、
前記第1のレジスタ情報を読み込んで、前記関数の入口に割り付けられたレジスタの退避コードを生成し、前記関数の入口から出口に至るパス上で割り付けられているレジスタに対して前記関数の出口毎にそれぞれ回復コードを生成し、前記パス上で定義されてないレジスタについて当該レジスタのサイズに応じてスタックアドレスを補正するスタックアドレスの更新命令を生成することを特徴とするコンパイル装置。 In a compiling apparatus that includes a first processor that performs arithmetic processing and a storage unit that stores information used by the processor, and that reads a source program including a function and generates an object program including a stack operation instruction.
A parsing unit that reads the source program and generates intermediate code;
A register allocating unit that reads the intermediate code and allocates a register of a second processor constituting a computer that executes the object program to the intermediate code;
A code generation unit that generates an object code from the intermediate code assigned to the register and outputs an object program;
The storage unit
Target information storing register information of the second processor;
First register information for storing information of the register allocated to the function;
Have
The code generator is
A definition register information collection unit that collects information of the registers allocated to the entry and exit of the function and stores the information in the first register information;
A save / recovery code generation unit that generates a save code and a recovery code of the register allocated by the definition register information collection unit;
The evacuation / recovery code generator
Reading the first register information, generating a save code for the register allocated to the function entry, and for each register exit assigned to the register allocated on the path from the function entry to the exit A compiling device that generates a recovery code and corrects a stack address according to the size of the register for a register that is not defined on the path.
前記スタックアドレスの更新命令が連続して生成されることを検出する検出部と、
前記検出結果に従ってスタックアドレスの更新命令の値を修正する更新値修正部と、を有し、
前記更新値修正部は、
前記検出部がスタックアドレスの更新命令を連続して生成する際には、連続する2つめ以降のスタックアドレス更新命令を生成せず、最初に生成したスタックアドレス更新命令の値を、複数のスタックアドレスの補正値に修正することを特徴とするコンパイル装置。 The compiling device according to claim 5,
A detection unit for detecting that the update instruction of the stack address is continuously generated;
An update value correction unit that corrects the value of the update instruction of the stack address according to the detection result,
The update value correction unit
When the detection unit continuously generates stack address update instructions, it does not generate the second and subsequent stack address update instructions, and the value of the stack address update instruction generated first is set to a plurality of stack addresses. A compiling device for correcting to a correction value.
前記第1のプロセッサが、前記ソースプログラムを読み込んで中間コードを生成するステップと、
前記第1のプロセッサが、前記中間コードを読み込んで、前記オブジェクトプログラムを実行する第2の計算機を構成する第2のプロセッサのレジスタを前記中間コードに割り付けるステップと、
前記第1のプロセッサが、前記レジスタに割り付けた中間コードからオブジェクトコードを生成し、オブジェクトプログラムとして出力するステップ、とを含み、
前記レジスタに割り付けた中間コードからオブジェクトコードを生成し、オブジェクトプログラムとして出力するステップは、
前記関数の入口及び出口に割り付けられた前記レジスタの情報を収集して前記記憶部に設定した第1のレジスタ情報に格納するステップと、
前記第1のレジスタ情報を読み込んで、前記関数の入口及び出口に割り付けられた前記レジスタの退避順序と回復順序を決定するステップと、
前記決定した退避順序と回復順序に従って前記レジスタの退避コードと回復コードを生成するステップと、を有し、
前記決定した退避順序と回復順序に従って前記レジスタの退避コードと回復コードを生成するステップは、
前記レジスタの退避順序に従ってレジスタの退避コードを前記関数の入口に生成し、前記第1のレジスタ情報と前記退避順序及び回復順序から前記関数の入口から出口に至るパス上で割り付けられているレジスタに対して、前記関数の出口毎にそれぞれ回復コードを生成し、前記パス上で定義されてないレジスタのサイズの和を求め、前記関数の出口でスタックアドレスを前記レジスタのサイズの和だけ補正するスタックアドレスの更新命令を生成することを特徴とするコンパイル方法。 A first computer including a first processor that performs arithmetic processing and a storage unit that stores information used by the processor reads a source program including a function and generates an object program including a stack operation instruction. In the compilation method,
The first processor reads the source program and generates intermediate code;
The first processor reads the intermediate code and allocates a register of a second processor constituting a second computer that executes the object program to the intermediate code;
The first processor generates an object code from the intermediate code allocated to the register and outputs the object code as an object program;
The step of generating an object code from the intermediate code assigned to the register and outputting it as an object program,
Collecting information on the registers allocated to the entry and exit of the function and storing them in the first register information set in the storage unit;
Reading the first register information and determining a save order and a recovery order of the registers assigned to the entry and exit of the function;
Generating a save code and a recovery code of the register according to the determined save order and recovery order, and
The step of generating the save code and the recovery code of the register according to the determined save order and the recovery order,
A register save code is generated at the entry of the function according to the save order of the registers, and the first register information and the registers allocated on the path from the save order to the exit from the save order and the recovery order On the other hand, a stack that generates a recovery code for each exit of the function, calculates a sum of register sizes that are not defined on the path, and corrects a stack address at the exit of the function by the sum of the register sizes. A compiling method characterized by generating an address update instruction.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2008294733A JP2010122820A (en) | 2008-11-18 | 2008-11-18 | Compile device and compile method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2008294733A JP2010122820A (en) | 2008-11-18 | 2008-11-18 | Compile device and compile method |
Publications (1)
Publication Number | Publication Date |
---|---|
JP2010122820A true JP2010122820A (en) | 2010-06-03 |
Family
ID=42324119
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2008294733A Pending JP2010122820A (en) | 2008-11-18 | 2008-11-18 | Compile device and compile method |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP2010122820A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2019007474A (en) * | 2017-06-22 | 2019-01-17 | 株式会社デンソー | High-pressure fuel pump and fuel supply system |
CN112445484A (en) * | 2019-08-27 | 2021-03-05 | 龙芯中科技术股份有限公司 | Register processing method and device, electronic equipment and storage medium |
-
2008
- 2008-11-18 JP JP2008294733A patent/JP2010122820A/en active Pending
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2019007474A (en) * | 2017-06-22 | 2019-01-17 | 株式会社デンソー | High-pressure fuel pump and fuel supply system |
JP7035542B2 (en) | 2017-06-22 | 2022-03-15 | 株式会社デンソー | High pressure fuel pump and fuel supply system |
CN112445484A (en) * | 2019-08-27 | 2021-03-05 | 龙芯中科技术股份有限公司 | Register processing method and device, electronic equipment and storage medium |
CN112445484B (en) * | 2019-08-27 | 2023-11-24 | 龙芯中科技术股份有限公司 | Register processing method and device, electronic equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10175983B2 (en) | Branch trace compression | |
US9582321B2 (en) | System and method of data processing | |
US20160321048A1 (en) | Information processing apparatus and compiling method | |
US20150058825A1 (en) | Stack trace compression | |
US8250557B2 (en) | Configuring a dependency graph for dynamic by-pass instruction scheduling | |
US8549502B2 (en) | Compiler with user-defined type inference rules | |
JPH07234792A (en) | Compile processor | |
JPH1097430A (en) | Method and system for inserting assembly code routine into source code routine for optimization | |
US9104402B2 (en) | Branch trace compression | |
JP2008009957A (en) | Compiling device | |
US20100250564A1 (en) | Translating a comprehension into code for execution on a single instruction, multiple data (simd) execution | |
US8423980B1 (en) | Methods for handling inlined functions using sample profiles | |
US7987457B2 (en) | Targeted patching for native generation images | |
JP5048949B2 (en) | Software tools including asynchronous program flow modeling | |
EP2009547A2 (en) | Method and apparatus for parallel XSL transformation with low contention and load balancing | |
JP2007532990A (en) | Method and structure for explicit software control of thread execution including helper subthreads | |
JP2010122820A (en) | Compile device and compile method | |
JP2011141676A (en) | Apparatus and method for processing language, and computer program product | |
US10310871B2 (en) | Non-transitory computer-readable recording medium storing control program, control device and control method | |
US10108405B2 (en) | Compiling apparatus and compiling method | |
KR101670916B1 (en) | Method for storing function and system device using the same | |
US20210303283A1 (en) | Generating compilable machine code programs from dynamic language code | |
JP2008250838A (en) | Software generation device, method and program | |
JP2021184246A (en) | Instruction conversion support program, instruction conversion support method and information processing device | |
CN115004150A (en) | Method and apparatus for predicting and scheduling duplicate instructions in software pipelining loops |