JPH09146775A - Prolog code generation method for subroutine - Google Patents

Prolog code generation method for subroutine

Info

Publication number
JPH09146775A
JPH09146775A JP32811295A JP32811295A JPH09146775A JP H09146775 A JPH09146775 A JP H09146775A JP 32811295 A JP32811295 A JP 32811295A JP 32811295 A JP32811295 A JP 32811295A JP H09146775 A JPH09146775 A JP H09146775A
Authority
JP
Japan
Prior art keywords
register
instruction
subroutine
call
routine
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
Application number
JP32811295A
Other languages
Japanese (ja)
Inventor
Yoshitaka Nishiyama
由高 西山
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.)
Oki Electric Industry Co Ltd
Original Assignee
Oki Electric Industry Co Ltd
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 Oki Electric Industry Co Ltd filed Critical Oki Electric Industry Co Ltd
Priority to JP32811295A priority Critical patent/JPH09146775A/en
Publication of JPH09146775A publication Critical patent/JPH09146775A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

PROBLEM TO BE SOLVED: To provide the method which can reduce the code size of a program by deleting the instruction string that is used for setting a relevant register out of the subroutine instruction string to be compiled. SOLUTION: A prolog code generation part 22 deletes the constant data setting instruction out of the subroutine instruction string which is generated by an intermediate code generation/optimization part 21 and undergone assignment of a register. Then the part 22 adds the instructions to the inlet and the outlet of the subroutine instruction string to call out the prolog/epilog routines 4 and also assigns the constant data set by the deleted constant data setting instruction to a memory. A machine language code generation part 23 converts the instruction string given from the part 22 into a machine language instruction of a target CPU to generate an object program 3. Thus it is possible to reduce the size of the program 3 by adding the constant data setting instruction into the prolog routine.

Description

【発明の詳細な説明】Detailed Description of the Invention

【0001】[0001]

【発明の属する技術分野】本発明は、高級言語により記
述されたプログラムをコンパイルする際に、オブジェク
トプログラムのサブルーチンのプロローグコードをオブ
ジェクトプログラムのコード量を削減するようにコンパ
イルするサブルーチンのプロローグコード生成方法に関
する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a subroutine prologue code generation method for compiling a program written in a high-level language so that the prologue code of the subroutine of the object program is reduced to reduce the code amount of the object program. Regarding

【0002】[0002]

【従来の技術】コボル、フォートラン、C言語、ベーシ
ック等、プログラム記述のための高級言語は、コンパイ
ラによりコンパイルされてオブジェクトプログラムが生
成される。この場合に、多くのレジスタを持つプロセッ
サのためのコードを生成する最適化コンパイラでは、豊
富なレジスタを最大限に利用した最適化を行う。通常、
16個以上のレジスタを持つようなプロセッサがこれに
該当する。このようなコンパイラではレジスタに使用頻
度の高い変数や定数を割り付けたり、メモリの内容を保
持したりして実行命令数を減らすと共に、レジスタに比
べてアクセス速度の遅いメモリへのアクセス回数を減ら
し、高速演算処理の可能な機械語命令列を生成する。
2. Description of the Related Art High-level languages for describing programs, such as Cobol, Fortran, C language, and basic, are compiled by a compiler to generate an object program. In this case, an optimizing compiler that generates code for a processor having a large number of registers performs optimization by making full use of abundant registers. Normal,
This corresponds to a processor having 16 or more registers. In such a compiler, frequently used variables and constants are assigned to registers, the contents of memory are retained to reduce the number of execution instructions, and the number of accesses to memory, which has a slower access speed than registers, is reduced. A machine language instruction sequence capable of high-speed arithmetic processing is generated.

【0003】一方、コンパイラでは、複数あるレジスタ
を、サブルーチン呼び出しの前後で、その値を保存して
おく必要のあるレジスタと、そうでないレジスタに分け
て使用している。前者のレジスタは呼び出し保存レジス
タと呼んでいる。このようなレジスタをコンパイル中の
サブルーチンに割り付けた場合には、それらの呼び出し
保存レジスタの値を退避するための命令列をサブルーチ
ンの入口に生成する必要がある。更に、サブルーチンが
スタックを使用する場合には、スタック上に領域を割り
付けるための命令列も生成する必要がある。また、サブ
ルーチンの出口では入口で退避した呼び出し保存レジス
タ値の復帰やスタック領域の解放のための命令列を生成
する必要がある。一般に、サブルーチン入口に生成され
るレジスタ退避とスタック割り付けのための命令列はプ
ロローグコードと呼ばれる。また、サブルーチンの出口
に生成されるレジスタ復帰とスタック解放のための命令
列はエピローグコードと呼ばれる。多くのレジスタを持
つプロセッサにはレジスタウインドウやレジスタスタッ
ク等の特別な機構や複数のレジスタを、一括してメモリ
に退避したり(書き込み)、復帰(読み出し)したりす
る特殊な命令を持つものがある。しかしながら、このよ
うな特別な機構や命令を持たないプロセッサでは、レジ
スタの退避復帰やスタックの割り付け解放のための命令
列によってプロローグコードやエピローグコードが大き
くなり、オブジェクトプログラム全体のサイズが大きく
なってしまう。
On the other hand, in the compiler, a plurality of registers are used by dividing them into registers that need to save the values before and after calling a subroutine and registers that do not. The former register is called a call save register. When such a register is allocated to a subroutine being compiled, it is necessary to generate an instruction sequence for saving the values of those call save registers at the entrance of the subroutine. Furthermore, when the subroutine uses a stack, it is necessary to generate an instruction sequence for allocating an area on the stack. At the exit of the subroutine, it is necessary to generate an instruction sequence for restoring the call save register value saved at the entrance and releasing the stack area. Generally, an instruction sequence for register saving and stack allocation generated at the entrance of a subroutine is called a prolog code. The instruction sequence for register restoration and stack release generated at the exit of the subroutine is called an epilogue code. Some processors with many registers have special mechanisms such as register windows and register stacks, and special instructions to save (write) or restore (read) multiple registers at once. is there. However, in a processor that does not have such a special mechanism or instruction, the prolog code or epilog code becomes large due to the instruction sequence for register saving / restoring or stack allocation release, and the size of the entire object program becomes large. .

【0004】そこで、このようなプロセッサに対するコ
ンパイラではコードサイズを小さくするために次のよう
な方法を採用している。即ち、呼び出し保存レジスタの
退避とスタック領域の割り付けを行うプロローグコード
と、呼び出し保存レジスタの復帰とスタック領域の解放
を行うエピローグコードをライブラリルーチン(サブル
ーチン)として別に用意しておき、サブルーチンの入口
や出口で各ライブラリルーチンを呼び出すためのコード
を生成する。これにより、プロローグコードによるライ
ブラリルーチンやエピローグコードによるライブラリル
ーチンを呼び出すためのオーバーヘッドによって実行速
度を一部犠牲にするものの、プログラムコードやエピロ
ーグコードのサイズを小さくすることを実現している。
この種の技術は次のような文献に記載されている(コミ
ュニケーションズオブエーシーエム(COMUNICATIONS OF
THE ACM. June 1994/Vol.37, No.6 pp62 ))。
Therefore, the compiler for such a processor adopts the following method in order to reduce the code size. That is, a prologue code for saving the call save register and allocating the stack area, and an epilogue code for returning the call save register and releasing the stack area are separately prepared as library routines (subroutines), and the entrance and exit of the subroutine are prepared. Generate code to call each library routine. As a result, although the execution speed is partially sacrificed by the overhead of calling the library routine of the prolog code or the library routine of the epilog code, it is possible to reduce the size of the program code and the epilog code.
This type of technology is described in the following literature (COMUNICATIONS OF
THE ACM. June 1994 / Vol.37, No.6 pp62)).

【0005】[0005]

【発明が解決しようとする課題】ところで、上記のよう
な従来のサブルーチンのプロローグコード生成方法には
次のような解決すべき課題があった。コンパイル対象の
サブルーチンがメモリ上に割り付けられた変数の参照や
変更を行ったり、大きな値の数値定数を用いたりする場
合がある。また、C言語で記述したサブルーチンがその
外部で定義した変数の参照や変更を行う場合がある。こ
れらの場合、変数のシンボルアドレスを一旦レジスタに
設定し、そのレジスタを用いてメモリにアクセスする
か、シンボルアドレスや値の大きな数字定数を命令の即
値オペランドに格納しておく必要がある。
The conventional prologue code generation method for a subroutine as described above has the following problems to be solved. The subroutine to be compiled may refer to or change the variable allocated in memory, or use a numerical constant with a large value. In addition, a subroutine described in C language may refer to or change a variable defined outside the subroutine. In these cases, it is necessary to temporarily set the symbol address of the variable in the register and access the memory using the register, or store the symbol address or a numeric constant having a large value in the immediate operand of the instruction.

【0006】また、シンボルアドレスをレジスタに設定
する場合、メモリアドレスが32ビット長で表現され、
命令長も32ビットで固定されるプロセッサがある。こ
のようなプロセッサではメモリアドレスをレジスタに設
定する場合、少なくとも2命令を要する。即ち、例えば
1つ目の命令で32ビットアドレスの下位16ビットを
設定し、次の命令で上位16ビットを設定する。
Further, when the symbol address is set in the register, the memory address is represented by a 32-bit length,
For some processors, the instruction length is fixed at 32 bits. In such a processor, setting a memory address in a register requires at least two instructions. That is, for example, the first instruction sets the lower 16 bits of the 32-bit address, and the next instruction sets the upper 16 bits.

【0007】また、シンボルアドレスを命令のオペラン
ドに直接格納できるようなプロセッサであっても同じシ
ンボルアドレスを複数回使用する場合は、シンボルアド
レスを一定のレジスタに設定し、それを再利用すること
が好ましい。その方が例えば32ビット長程度のシンボ
ルアドレスを、毎回、命令の即値オペランドに格納して
おくよりもコードサイズを小さくできる。なお、この場
合は、レジスタが十分な数だけ確保され、空きがあるこ
とが条件となる。上記のような状況は既知の数値定数、
例えば「0x4fff00ff」といった数値を用いる場合にも発
生する。このようにサブルーチン中でメモリ上に割り付
けられた変数のシンボルアドレスや値の大きな数値定数
等の定数データを多く使用する場合、その定数データを
レジスタに設定する命令が多くなると、オブジェクトプ
ログラムのコードサイズを大きくしてしまう。このよう
な傾向は固定長命令を採用しているRISC型プロセッ
サに多く見かけられる。また、サブルーチンの引き数レ
ジスタの複写命令が多ければやはりプログラムのコード
サイズを大きくしてしまう。
Further, even in a processor capable of storing the symbol address directly in the operand of the instruction, when the same symbol address is used a plurality of times, it is possible to set the symbol address in a certain register and reuse it. preferable. In that case, the code size can be made smaller than that of storing a symbol address of, for example, about 32 bits in the immediate operand of the instruction every time. In this case, it is a condition that a sufficient number of registers are secured and there is a space. The above situations are known numerical constants,
For example, it occurs when a numerical value such as "0x4fff00ff" is used. When a large amount of constant data such as a symbol address of a variable allocated in memory or a numerical constant with a large value is used in a subroutine like this, if the number of instructions to set that constant data in a register increases, the code size of the object program will increase. Will be increased. This tendency is often found in RISC type processors that employ fixed length instructions. Further, if there are many copy instructions of the argument register of the subroutine, the code size of the program is also increased.

【0008】[0008]

【課題を解決するための手段】本発明は以上の点を解決
するため次の構成を採用する。 〈構成1〉オブジェクトプログラムのサブルーチン入口
で、レジスタの退避を含む処理を実行するプロローグコ
ードと、サブルーチン出口で、レジスタの復帰を含む処
理を実行するエピローグコードを用いてサブルーチン呼
び出しを実現するコンパイラにより、サブルーチンの命
令列中から、所定の定数データを呼び出し保存レジスタ
に設定する命令であって、かつ、そのサブルーチン入口
に移動可能なものを抽出して削除し、その定数データ設
定先の呼び出し保存レジスタとして、予め定めた特定の
呼び出し保存レジスタを割り付け、定数データはメモリ
上に格納しておき、メモリ上の定数データを予め定めた
特定の呼び出し保存レジスタに複写するためのプロロー
グルーチンを呼び出す処理を含む命令列を含むプロロー
グコードを生成する。
The present invention employs the following structure to solve the above problems. <Structure 1> A compiler that implements a subroutine call using a prologue code that executes processing including register saving at the entrance of a subroutine of an object program and an epilogue code that executes processing including restoration of the register at the exit of the subroutine From the instruction sequence of the subroutine, the instruction that sets the specified constant data in the call save register and that can be moved to the entrance of the subroutine is extracted and deleted, and is used as the call save register of the constant data setting destination. , An instruction including a process of allocating a predetermined specific call save register, storing constant data in the memory, and calling a prologue routine for copying the constant data in the memory to the predetermined specific call save register Generate prolog code containing columns .

【0009】〈説明〉オブジェクトプログラムは、所定
のタイミングでサブルーチンを呼び出す。このとき、サ
ブルーチンの入口にあるプロローグコードは、呼び出し
保存レジスタの退避やスタックの割り付けを行う。ま
た、サブルーチンの出口にあるエピローグコードは、ス
タックの開放やレジスタの復帰を行う。一方、サブルー
チン中には、定数データをレジスタに設定する命令列が
含まれる場合がある。定数データとは、シンボルアドレ
スや数値定数のことをいう。この設定先レジスタは通常
はいずれかのレジスタが割り付けられるが、これを特定
の呼び出し保存レジスタに割り付ける。こうすれば、メ
モリから定数データをその特定の呼び出し保存レジスタ
に複写する処理をサブルーチン化できる。そこで、上記
プロローグコードとこの複写命令を併せて、サブルーチ
ン化する。このサブルーチンがプロローグルーチンであ
る。これは、他のサブルーチンからも呼び出すことがで
きる共通化された処理である。従って、そのプロローグ
ルーチンをプロローグコード中で呼び出す。こうしてコ
ンパイル対象のサブルーチン命令列から、そのレジスタ
設定のための命令列を削除できるので、コードサイズが
低減される。
<Description> The object program calls a subroutine at a predetermined timing. At this time, the prologue code at the entrance of the subroutine saves the call save register and allocates the stack. The epilogue code at the exit of the subroutine opens the stack and restores the registers. On the other hand, the subroutine may include an instruction string for setting constant data in the register. Constant data refers to symbol addresses and numerical constants. This setting destination register is normally assigned any register, but it is assigned to a specific call save register. In this way, the process of copying the constant data from the memory to the specific call save register can be made into a subroutine. Therefore, the above prolog code and this copy instruction are combined into a subroutine. This subroutine is a prologue routine. This is a common process that can be called from other subroutines. Therefore, the prolog routine is called in the prolog code. In this way, the instruction sequence for register setting can be deleted from the subroutine instruction sequence to be compiled, so that the code size is reduced.

【0010】〈構成2〉サブルーチンの命令列中から抽
出した、所定の定数データをレジスタに設定する定数設
定命令によって設定される呼び出し保存レジスタが、プ
ロローグルーチンとの間で予め定められた所内の呼び出
し保存レジスタ群に含まれない場合に、定数設定命令に
よって設定される呼び出し保存レジスタと交換可能なレ
ジスタが、所定の呼び出し保存レジスタ群中に存在する
かどうかを調べ、交換可能なレジスタ同士を入れ換え
て、これらのレジスタを参照しもしくは定義しているサ
ブルーチン中の命令のオペランドを書き換える。
<Structure 2> A call save register set by a constant setting instruction for setting predetermined constant data in the register extracted from the instruction sequence of the subroutine is called in a predetermined place with the prolog routine. If it is not included in the save register group, check whether the register that can be exchanged with the call save register set by the constant setting instruction exists in the specified call save register group, and replace the exchangeable registers with each other. , Rewrite the operand of the instruction in the subroutine that refers to or defines these registers.

【0011】〈説明〉所定の定数データをレジスタに設
定する定数設定命令によって設定される呼び出し保存レ
ジスタが、プロローグコードとサブルーチンとの間で予
め定められた呼び出し保存レジスタ群と偶然に一致する
ときは、このようなレジスタの交換は不要になる。書換
え後のレジスタ設定命令列による定数設定先の呼び出し
保存レジスタが、構成1の特定の呼び出し保存レジスタ
となる。
<Description> When the call save register set by the constant setting instruction for setting the predetermined constant data in the register happens to coincide with the call save register group predetermined between the prologue code and the subroutine. It is not necessary to replace such a register. The call save register to which the constant is set by the register setting instruction sequence after rewriting becomes the specific call save register of configuration 1.

【0012】〈構成3〉オブジェクトプログラムのサブ
ルーチン入口で、レジスタの退避を含む処理を実行する
プロローグコードと、サブルーチン出口で、レジスタの
復帰を含む処理を実行するエピローグコードを用いてサ
ブルーチン呼び出しを実現するコンパイラにより、サブ
ルーチンの入口の基本ブロック内で、引き数レジスタの
複写が行われる場合に、その複写命令を抽出して削除
し、引き数レジスタの複写先のレジスタとして、予め定
めた特定の呼び出し保存レジスタを割り付け、特定の呼
び出し保存レジスタへの引き数の複写命令を含むプロロ
ーグルーチンを呼び出す処理を含むプロローグコードを
生成する。
<Structure 3> A subroutine call is realized by using a prologue code for executing a process including saving of registers at the entrance of a subroutine of an object program and an epilogue code for executing a process including restoration of registers at the exit of the subroutine. When the argument register is copied by the compiler in the basic block at the entrance of the subroutine, the copy instruction is extracted and deleted, and a specific call is saved in advance as the register to which the argument register is copied. Prologue code is generated that includes the process of allocating registers and calling a prologue routine that contains a copy instruction of the argument to a particular call save register.

【0013】〈説明〉引き数の複写先のレジスタを特定
の呼び出し保存レジスタに割り付けてしまうことによ
り、複写命令をサブルーチン化できる。この複写命令列
をサブルーチンから削除すれば、構成1と同様にオブジ
ェクトプログラムのコードのサイズを削減できる。
<Explanation> The copy instruction can be made into a subroutine by allocating the register of the copy destination of the argument to a specific call save register. If this copy instruction sequence is deleted from the subroutine, the code size of the object program can be reduced as in the case of the configuration 1.

【0014】[0014]

【発明の実施の形態】以下、本発明の実施の形態を具体
例を用いて説明する。 〈具体例1〉図1は、本発明の方法を実施するためのシ
ステムのブロック図である。即ち、このシステムは、図
に示すように、ソースプログラム1を読み込んでコンパ
イルを行い、オブジェクトプログラム3を生成するコン
パイラ2と、オブジェクトプログラム3とプロローグル
ーチン及びエピローグルーチン4とその他のライブラリ
ルーチン5をリンクして実行プログラム7を生成するリ
ンカ6から成る。
BEST MODE FOR CARRYING OUT THE INVENTION Embodiments of the present invention will be described below with reference to specific examples. SPECIFIC EXAMPLE 1 FIG. 1 is a block diagram of a system for carrying out the method of the present invention. That is, as shown in the figure, this system links a compiler 2 that reads a source program 1 and compiles it to generate an object program 3, an object program 3, a prolog routine, an epilog routine 4, and another library routine 5. And a linker 6 for generating an execution program 7.

【0015】コンパイラ2は、中間コード生成部及び最
適化部21と、プロローグコード生成部22と、機械語
コード生成部23とを備える。中間コード生成部及び最
適化部21は、ソースプログラム1中の各サブルーチン
に対し、呼び出し保存レジスタの退避と復帰、及びスタ
ック割り付けと解放を行うためのプロローグコードとエ
ピローグコード以外の中間言語命令列(以下では単に
「命令列」と呼ぶ)を生成し、その命令列に各種最適化
を施し、ターゲットCPUのレジスタを割り付ける。プ
ロローグコード生成部22は、中間コード生成部及び最
適化部21が生成したレジスタ割り付け後のサブルーチ
ン命令列の中から、定数データ設定命令を削除し(削除
可能なもののみ)、プロローグルーチンとエピローグル
ーチン4を呼び出す命令を、サブルーチンの命令列の入
口と出口にそれぞれ追加すると共に、削除した定数デー
タ設定命令が設定する定数データをメモリ上に割り付け
る。機械語コード生成部23は、プロローグコード生成
部22から渡された命令列(中間言語)を、ターゲット
CPUの機械語命令列に変換して、オブジェクトプログ
ラム3を生成する。
The compiler 2 includes an intermediate code generation / optimization unit 21, a prologue code generation unit 22, and a machine language code generation unit 23. The intermediate code generation unit and the optimization unit 21 saves and restores the call save register, and allocates and releases the stack for each subroutine in the source program 1, and an intermediate language instruction string other than the prologue code and epilogue code ( (Hereinafter, simply referred to as "instruction sequence") is generated, various optimizations are performed on the instruction sequence, and registers of the target CPU are allocated. The prologue code generation unit 22 deletes the constant data setting instruction from the subroutine instruction sequence after register allocation generated by the intermediate code generation unit and the optimization unit 21 (only those that can be deleted), the prologue routine and the epilogue routine. The instruction for calling 4 is added to each of the entry and the exit of the instruction sequence of the subroutine, and the constant data set by the deleted constant data setting instruction is allocated on the memory. The machine language code generation unit 23 converts the instruction sequence (intermediate language) passed from the prologue code generation unit 22 into a machine language instruction sequence of the target CPU to generate the object program 3.

【0016】また、プロローグコード生成部22は、定
数データ設定命令抽出手段221と、レジスタ交換手段
222と、定数データ設定命令削除手段223と、サブ
ルーチン呼び出し命令生成手段224とを備える。定数
データ設定命令抽出手段221は、サブルーチン命令列
中から、シンボルアドレスや値の大きな数値定数等の定
数データを呼び出し保存レジスタに設定する定数データ
設定命令群を探し出し、かつ、その定数データ設定命令
群の中から、サブルーチン入口に移動可能な命令とし
て、定数データ設定先の呼び出し保存レジスタをサブル
ーチン入口の基本ブロック内で最初に設定している命令
か、サブルーチンの全命令列中で1度しか設定されない
呼び出し保存レジスタを設定している命令のみを選び出
す。
Further, the prologue code generator 22 comprises a constant data setting instruction extracting means 221, a register exchanging means 222, a constant data setting instruction deleting means 223, and a subroutine call instruction generating means 224. The constant data setting instruction extracting means 221 searches for a constant data setting instruction group that calls constant data such as a symbol address or a numerical constant having a large value in the save register from the subroutine instruction sequence, and sets the constant data setting instruction group. From the above, as an instruction that can be moved to the subroutine entry, the instruction that first sets the call save register of the constant data setting destination in the basic block of the subroutine entry, or is set only once in the entire instruction sequence of the subroutine Select only the instructions for which the call save register is set.

【0017】レジスタ交換手段222は、上記のサブル
ーチン入口に移動可能な定数データ設定命令群中の各命
令に対し、その定数データ設定先の呼び出し保存レジス
タ(b)が、プロローグルーチン4との間で予め決めら
れている呼び出し保存レジスタ群(A)の中に含まれて
いない場合に、呼び出し保存レジスタ群(A)の中から
交換可能なレジスタ(a)を選び出し、(もし有れば)
それの2つのレジスタ(a)と(b)を入れ換え、それ
に応じて、サブルーチン命令列中で2つのレジスタ
(a)と(b)を参照または定義する命令のオペランド
も書き換える。定数データ設定命令削除手段223は、
上記レジスタ交換手段222によるオペランド書き換え
後の定数データ設定命令群の中から、定数データ設定先
レジスタ(b)が、プロローグルーチン4との間で決め
たレジスタ群(A)の中に含まれる命令群(K)を探し
出し、それをサブルーチン命令列から削除する。
The register exchanging means 222, for each instruction in the constant data setting instruction group that can be moved to the above-mentioned subroutine entry, has a call save register (b) at the constant data setting destination with the prolog routine 4. If the call save register group (A) is not included in the predetermined call save register group (A), the exchangeable register (a) is selected from the call save register group (A) (if any).
The two registers (a) and (b) are exchanged, and the operand of the instruction that refers to or defines the two registers (a) and (b) in the subroutine instruction sequence is also rewritten accordingly. The constant data setting command deletion means 223
From the constant data setting instruction group after the operand rewriting by the register exchanging means 222, the constant data setting destination register (b) is included in the register group (A) determined with the prolog routine 4. Find (K) and delete it from the subroutine instruction sequence.

【0018】サブルーチン呼び出し命令生成手段224
は、プロローグルーチンとエピローグルーチン4を呼び
出す命令列を、サブルーチンの命令列の先頭と終わりに
追加すると共に、定数データ設定命令群(K)中の命令
が設定していた定数データを、プロローグルーチンを呼
び出す命令列の直後に割り付ける。
Subroutine call instruction generation means 224
Adds a sequence of instructions that calls the prologue routine and the epilogue routine 4 to the beginning and end of the sequence of instructions of the subroutine, and sets the constant data set by the instructions in the constant data setting instruction group (K) to the prologue routine. It is assigned immediately after the instruction sequence to be called.

【0019】図2はそのコンパイルの対象となるC言語
サブルーチンを示し、図3はコンパイル結果の命令列を
示している。以下、本発明によるプロローグコード生成
方法の動作を、図2に示したサブルーチンf()のコン
パイル例である図3の命令列を用いて詳細に説明する。
ただし、コンパイラ内部で使用される中間言語命令とタ
ーゲットCPUの機械語命令は、簡単化のため同じ形式
の命令を用いて説明する。また、特に区別する必要がな
い場合は、中間言語命令(列)も機械語命令(列)も単
に命令(列)と呼ぶことにする。図3の命令列は、図1
の中間コード生成部及び最適化部21が出力したレジス
タ割り付け後の命令列を表している。この命令列中で
は、シンボルアドレス_a〜_dを即値設定命令set
dでレジスタに設定している。(図3の(s1)〜(s
4))。ここにはプロローグコードとエピローグコード
はまだ付加されていない。
FIG. 2 shows a C language subroutine to be compiled, and FIG. 3 shows an instruction sequence as a compilation result. Hereinafter, the operation of the prologue code generation method according to the present invention will be described in detail with reference to the instruction sequence shown in FIG. 3, which is a compilation example of the subroutine f () shown in FIG.
However, the intermediate language instructions used inside the compiler and the machine language instructions of the target CPU will be described using the same type of instructions for simplification. In addition, if there is no particular need to distinguish between them, both the intermediate language instruction (sequence) and the machine language instruction (sequence) will be simply referred to as the instruction (sequence). The instruction sequence shown in FIG. 3 corresponds to that shown in FIG.
The instruction sequence after register allocation output from the intermediate code generation unit and the optimization unit 21 is shown. In this instruction sequence, the symbol addresses _a to _d are set to the immediate value setting instruction set.
It is set in the register with d. ((S1) to (s of FIG. 3
4)). The prologue code and epilogue code have not yet been added here.

【0020】図4には、(a)に以下の説明で用いるレ
ジスタの一覧を示し、(b)にそれを使用したいくつか
の命令の例を示している。各レジスタの長さは32ビッ
ト(4バイト)、アドレス幅は32ビットでバイトアド
レスで指定するものとする。また、即値設定命令set
dは64ビット(8バイト)長であり、それ以外の命令
は32ビット長であるとする。コンパイル時に値の分か
らないシンボルアドレスをレジスタに設定するには、s
eti命令ではなくsetd命令を使用する。
FIG. 4A shows a list of registers used in the following description, and FIG. 4B shows examples of some instructions using the registers. The length of each register is 32 bits (4 bytes), the address width is 32 bits, and it is specified by a byte address. Also, an immediate value setting command set
It is assumed that d has a length of 64 bits (8 bytes) and the other instructions have a length of 32 bits. To set a symbol address whose value is unknown at compile time to a register, use s
Use setd instructions instead of eti instructions.

【0021】図5には、プロローグルーチンで予め決め
てある定数データ設定先の呼び出し保存レジスタ群を示
している。これらのレジスタに設定する定数データをメ
モリ上に配置する際には、%r18、%r19、%r2
0の順にアドレスの小さい側から並べることとし、対応
する定数データが無い場合はアドレスの小さい側に詰め
て配置することとする。
FIG. 5 shows a call save register group to which constant data is preset, which is predetermined by the prologue routine. When arranging the constant data set in these registers on the memory,% r18,% r19,% r2
It is assumed that the addresses are arranged in the order of 0 from the side having the smallest address, and when there is no corresponding constant data, the data are arranged so as to be arranged on the side having the smallest address.

【0022】図6(a)、(b)には、それぞれ従来の
プロローグルーチンとエピローグルーチンの例を示す。
また、図7には、図6に示したプロローグルーチンとエ
ピローグルーチンが、それぞれ呼び出し保存レジスタの
退避と復帰に使用するスタック上の格納位置(スタック
ポインタ%r31との相対位置)の例を示している。図
6のプロローグルーチンとエピローグルーチンには、そ
れぞれ.saveNと.restoreN(N=1〜1
2)という複数のエントリ(ラベル)が用意されてい
る。各エントリは、退避あるいは復帰する呼び出し保存
レジスタの個数Nに対応している。また、プロローグル
ーチンが割り付けるスタックサイズは、呼び出し保存で
ないレジスタ%r16に乗せて渡すものとし、スタック
はアドレスの小さい側に延びるものとする。
FIGS. 6A and 6B show examples of a conventional prologue routine and epilogue routine, respectively.
Further, FIG. 7 shows an example of the storage position on the stack (relative position to the stack pointer% r31) used by the prolog routine and the epilog routine shown in FIG. 6 for saving and restoring the call save register, respectively. There is. The prologue routine and the epilogue routine shown in FIG. saveN and. restoreN (N = 1 to 1
A plurality of entries (labels) called 2) are prepared. Each entry corresponds to the number N of call save registers to be saved or restored. Further, the stack size allocated by the prolog routine is placed on the register% r16 which is not stored as a call and passed, and the stack extends to the side having a smaller address.

【0023】例えば、呼び出し保存レジスタの%r18
〜%r21(4個)を退避し、スタック領域を52バイ
ト割り付けるためには、サブルーチン(S)の先頭でプ
ロローグルーチン.save4を下記の3つの命令列で
呼び出せばよい。 sw %r0,[%r31] …(1) seti 52,%r16 …(2) call .save4 …(3) 先頭のストア命令“sw%r0、[%r31]”は、プ
ロローグルーチン.save4の呼び出しによりサブル
ーチン(S)の返り番地%r0が破壊されないように、
予めスタック上に退避するためのものである。
For example,% r18 of the call save register
~ To save% r21 (4 pieces) and allocate a stack area of 52 bytes, a prolog routine. It suffices to call save4 with the following three instruction sequences. sw% r0, [% r31] (1) seti 52,% r16 (2) call. save4 (3) The first store instruction “sw% r0, [% r31]” is a prologue routine. Make sure that the return address% r0 of the subroutine (S) is not destroyed by calling save4.
This is for saving on the stack in advance.

【0024】一方、呼び出し保存レジスタ%r18〜%
r24(4個)の値を復帰し、スタック領域(52バイ
ト)を解放するには、エピローグルーチン.resto
re4を下記の1命令で呼び出すだけでよい。 bra .restore4 …(4) .restoreNの呼び出しは、ラベル.resto
reNへの無条件分岐(bra命令)でよい。なぜな
ら、サブルーチン(S)の返り番地は、.saveNを
呼び出す前にスタック上に保存されているからである。
また、プロローグルーチン.saveNでは、図6の
(1)に示すように、フレームポインタ%r30を変更
前のスタックポインタ%r31の位置(値)に設定して
いるため、エピローグルーチンでスタックを解放するに
は、フレームポインタ%r30をスタックポインタ%r
31に代入するだけでよい。これは図6の(2)に示し
た。フレームポインタが使用できない場合は、.sav
eNを呼び出した場合と同様、%r16にスタックサイ
ズを設定してから、.restoreNを呼び出し、.
restoreNでは%r16を用いて、スタックポイ
ンタの変更を行うようにすればよい。
On the other hand, the call save register% r18 to%
To restore the value of r24 (4) and release the stack area (52 bytes), the epilog routine. resto
It suffices to call re4 with one instruction below. bra. restore4 ... (4). A call to restoreN calls the label. resto
An unconditional branch (bra instruction) to reN is sufficient. Because the return address of the subroutine (S) is. This is because it is saved on the stack before calling saveN.
Also, the prologue routine. In saveN, as shown in (1) of FIG. 6, the frame pointer% r30 is set to the position (value) of the stack pointer% r31 before the change. Therefore, in order to release the stack in the epilogue routine, the frame pointer % R30 is the stack pointer% r
All we have to do is substitute 31. This is shown in (2) of FIG. If the frame pointer is not available ,. sav
As with calling eN, set the stack size to% r16 and then. Call restoreN ,.
In restoreN,% r16 may be used to change the stack pointer.

【0025】図8には、図3のサブルーチン命令列に従
来のプロローグルーチン.save3とエピローグルー
チン.restore3を呼び出す命令を追加した例を
示す。図9には、この具体例で用いるプロローグルーチ
ン.newsaveNの例を示す。このプロローグルー
チンには、メモリ上に配置された定数データを図5の呼
び出し保存レジスタに設定するロード命令を含んでいる
(図9の(1)の部分)。番号Nの意味は、.save
Nの場合と同様に退避すべき呼び出し保存レジスタの個
数である。
In FIG. 8, the conventional prolog routine. save3 and epilogue routine. An example in which an instruction to call restore3 is added will be shown. FIG. 9 shows the prologue routine used in this specific example. An example of newsaveN is shown. This prologue routine includes a load instruction for setting the constant data arranged on the memory in the call saving register of FIG. 5 (portion (1) of FIG. 9). The meaning of the number N is. save
As in the case of N, this is the number of call save registers to be saved.

【0026】メモリ上に配置されている各定数データは
32ビット固定長であり、図5の各レジスタ%r18〜
%r20に設定すべき定数データがメモリ上にあるか否
かは、レジスタ%r17にビットフラグとして設定され
ているものとする。なお、%r16には、図6の従来の
プロローグルーチン.saveNと同様に、スタック領
域のサイズを設定する。レジスタ%r17のビット0
(最下位ビット)〜ビット2は、それぞれレジスタ%r
18〜%r20に設定すべき定数データがメモリ上に格
納されているか否かを示す。ビットの値が1なら対応す
る定数データがある。また、定数データを格納している
メモリアドレスは、プロローグルーチン.newsav
eNからの返り番地レジスタ%r0に格納されているも
のとし、実際の返り番地はその定数データ格納領域の直
後の命令であるとする。
Each constant data arranged on the memory has a fixed length of 32 bits, and each register% r18 to FIG.
Whether or not the constant data to be set in% r20 is on the memory is assumed to be set as a bit flag in the register% r17. Note that% r16 is the conventional prolog routine. Similar to saveN, the size of the stack area is set. Bit 0 of register% r17
(Least significant bit) to bit 2 are register% r
It indicates whether or not constant data to be set to 18 to% r20 is stored in the memory. If the bit value is 1, there is corresponding constant data. The memory address that stores constant data is the prolog routine. newsav
It is assumed that it is stored in the return address register% r0 from the eN, and the actual return address is the instruction immediately after the constant data storage area.

【0027】例えば、%r18と%r20にのみ定数デ
ータを設定する場合は、レジスタ%r17にビットフラ
グ0x5を設定して、次のようにしてプロローグルーチ
ン.newsaveNを呼び出せばよい。“.int”
は、32ビット定数データをメモリ上に配置するための
(疑似)命令である。 sw %r0,[%r31] seti 〈スタックサイズ〉,%r16 seti 0x5,%r17 call .newsaveN .int 〈%r18に設定する32ビット定数データ〉 (n1) .int 〈%r20に設定する32ビット定数データ〉 〈次の命令 x〉 (n2)
For example, when the constant data is set only in% r18 and% r20, the bit flag 0x5 is set in the register% r17 and the prolog routine. All you have to do is call newsaveN. ".Int"
Is a (pseudo) instruction for arranging 32-bit constant data on the memory. sw% r0, [% r31] seti <stack size>,% r16 seti 0x5,% r17 call. newsaveN. int <32-bit constant data set to% r18> (n1). int <32-bit constant data set to% r20><Next instruction x> (n2)

【0028】.newsaveNに分岐した直後には、
返り番地レジスタ%r0は、上記の(n1)のデータ格
納アドレスを指すことになる。.newsaveNから
の実際の返り先は、上記の(n2)の命令である。この
ための返り番地レジスタ%r0の調整は、%r17に設
定されたビットフラグによって、.newsaveNが
行う。
[0028] Immediately after branching to newsaveN,
The return address register% r0 points to the above-mentioned (n1) data storage address. . The actual return destination from newsaveN is the instruction (n2) above. Adjustment of the return address register% r0 for this purpose is performed by the bit flag set in% r17. done by newsaveN.

【0029】図10には、図3のサブルーチン命令列
に、この具体例で説明するプロローグコード生成方法を
適用し、プロローグルーチン.newsave4を呼び
出す命令を追加した例を示す。エピローグルーチンの呼
び出し命令は図8の従来の方法の場合と同じである。以
下では、図10の命令列が図1に示したプロローグコー
ド生成部22で、どのように生成されるかについて、そ
の詳細を説明する。定数データ設定命令抽出手段221
は、まず、図3のサブルーチン命令列の先頭の基本ブロ
ック内にあるsetd命令(64ビット長)群の中から
設定先の呼び出し保存レジスタをその基本ブロック内で
初めて設定しているものを探し出す。ただし、基本ブロ
ックの終わりは、ラベルの直前の命令か、サブルーチン
命令列の最後の命令である。図3の場合、基本ブロック
の終わりは下記の通りラベルL100の直前の命令であ
る。 sw %r9,[%r21]
In FIG. 10, the prologue code generation method described in this specific example is applied to the subroutine instruction sequence of FIG. An example in which an instruction to call newsave4 is added will be shown. The call instruction of the epilogue routine is the same as in the conventional method of FIG. In the following, details of how the instruction sequence of FIG. 10 is generated by the prolog code generation unit 22 shown in FIG. 1 will be described. Constant data setting instruction extraction means 221
First, from among the setd instruction (64-bit length) group in the first basic block of the subroutine instruction sequence of FIG. 3, the one in which the call save register of the setting destination is set for the first time in that basic block is searched. However, the end of the basic block is the instruction immediately before the label or the last instruction of the subroutine instruction sequence. In the case of FIG. 3, the end of the basic block is the instruction immediately before the label L100 as described below. sw% r9, [% r21]

【0030】また、上記の条件を満足するsetd命令
のリストは、出現順に下記の3つである。 setd _a,%r18 (s1) setd _b,%r21 (s2) setd _d,%r19 (s4) 図3中の(s3)のsetd命令は、(s1)のset
d命令と同じレジスタ%r18を設定しているので、上
記のリストには含まれない。次に、定数データ設定命令
抽出手段221は、サブルーチン命令列中のsetd命
令群の中からその設定先の呼び出し保存レジスタが、サ
ブルーチン命令列中の他の命令で変更されることのない
もの(つまりsetd命令自身が唯一そのレジスタを変
更する)を選び出し、上記のsetd命令リストに追加
する。図3のサブルーチンではそのようなsetd命令
は無い。
The list of setd instructions satisfying the above conditions is the following three in the order of appearance. setd_a,% r18 (s1) setd_b,% r21 (s2) setd_d,% r19 (s4) The setd instruction of (s3) in FIG. 3 is the set of (s1).
Since the same register% r18 as the d instruction is set, it is not included in the above list. Next, the constant data setting instruction extraction means 221 does not change the call save register of the set destination from the setd instruction group in the subroutine instruction sequence by another instruction in the subroutine instruction sequence (that is, The setd instruction itself only modifies its register) and adds it to the setd instruction list above. In the subroutine of FIG. 3, there is no such setd instruction.

【0031】図1に示すレジスタ交換手段222は、上
記のsetd命令リスト(s1)−(s2)−(s4)
中の各命令に対して、その設定先の呼び出し保存レジス
タが、プロローグルーチンとの間で予め決まっている図
5に示したレジスタ群に含まれるか否かを調べて、含ま
れない場合はレジスタの交換を試みる。上記のsetd
命令リスト中の(s1)と(s4)は、それぞれレジス
タ%r18と%r19を設定先としているので問題は無
い。しかし、(s2)の設定レジスタは%r21であ
り、図5のレジスタには含まれないため、交換を試み
る。
The register exchanging means 222 shown in FIG. 1 uses the above setd instruction list (s1)-(s2)-(s4).
For each instruction in the inside, it is checked whether the call save register of the setting destination is included in the register group shown in FIG. 5 which is predetermined with the prolog routine, and if it is not included, the register is saved. Try to replace. Setd above
There is no problem because (s1) and (s4) in the instruction list have registers% r18 and% r19 as the setting destinations, respectively. However, the setting register of (s2) is% r21, which is not included in the register of FIG.

【0032】レジスタの交換は、図5のレジスタ中から
setd命令リスト中の他のsetd命令が設定してい
ないレジスタを1つ選び、そのレジスタとsetd命令
が設定しているレジスタの入れ換えが可能か否か、その
2つのレジスタを参照あるいは定義している命令を調べ
る。入れ換えができない場合は、レジスタの交換を行わ
ずに、そのsetd命令をのsetd命令リストから削
除する。上記の(s2)の場合は、その設定先のレジス
タ%r21と図5のレジスタ%r20との入れ換えの可
能性を調べることになる。なお、%r18と%r19
は、それぞれ(s1)と(s4)が設定している。
For register exchange, is it possible to select one of the registers in FIG. 5 which is not set by another setd instruction in the setd instruction list, and replace that register with the register set by the setd instruction? Whether or not the instruction that refers to or defines the two registers is checked. If the exchange is not possible, the setd instruction is deleted from the setd instruction list without exchanging the register. In the case of the above (s2), the possibility of exchanging the register% r21 of the setting destination and the register% r20 of FIG. 5 is examined. Note that% r18 and% r19
Are set by (s1) and (s4), respectively.

【0033】図3の命令列の中でレジスタ%r20と%
r21を参照または設定している命令群は以下の通りで
ある。 mov %r8,%r20 setd _b,%r21 lw [%r21],%r9 sw %r9,[%r21] add %r20,1,%r12 これらの命令は、図4に示したように任意のレジスタ
(%r0〜%r31)をオペランドに指定できるので、
%r20と%r21を入れ換えて、次のように書き換え
ることができる。 mov %r8,%r21 setd _b,%r20 lw [%r20],%r9 sw %r9,[%r20] add %r21,1,%r12
Registers% r20 and% in the instruction sequence of FIG.
The instruction group that references or sets r21 is as follows. mov% r8,% r20 setd_b,% r21 lw [% r21],% r9 sw% r9, [% r21] add% r20,1,% r12 These instructions are arbitrary registers as shown in FIG. Since (% r0 to% r31) can be specified as an operand,
% R20 and% r21 can be exchanged and rewritten as follows. mov% r8,% r21 setd_b,% r20 lw [% r20],% r9 sw% r9, [% r20] add% r21,1,% r12

【0034】また、この書き換えを行った後のsetd
命令のリストは次のようになる。 setd _a,%r18 (s1) setd _b,%r20 (s2) setd _d,%r19 (s4) 特定の呼び出し保存レジスタしかオペランドに指定でき
ないような命令が存在する場合は、このような書き換え
が行えないことになる。例えば、上記のadd命令が%
r21をオペランドに指定できない場合は、上記のよう
な書き換えは行わない。
Also, setd after this rewriting
The list of instructions looks like this: setd _a,% r18 (s1) setd _b,% r20 (s2) setd _d,% r19 (s4) If there is an instruction that can only specify a specific call save register as an operand, such rewriting cannot be performed. It will be. For example, the above add instruction is%
If r21 cannot be specified as an operand, the above rewriting is not performed.

【0035】図1に示す定数データ設定命令削除手段2
23は、上記のレジスタの交換を行った後のsetd命
令リスト(s1)−(s2)−(s4)の中で、その設
定先のレジスタが図5に示したレジスタ群の中に含まれ
るものを削除する。上記の(s1)、(s2)、(s
4)のsetd命令は、いずれも図5のレジスタを設定
しているため、全て削除できる。削除後の命令列は図1
0の(3)の部分になる。図1に示すサブルーチン呼び
出し命令生成手段224は、定数データ設定命令を含ん
だ図9のプロローグルーチン呼び出し命令を、上記定数
データ設定命令削除後の命令列の先頭に追加する。ま
た、エピローグルーチン呼び出し命令は命令列の最後に
追加する。
Constant data setting instruction deleting means 2 shown in FIG.
23 is a setd instruction list (s1)-(s2)-(s4) after the above-mentioned register exchange, and the register of the setting destination is included in the register group shown in FIG. To delete. Above (s1), (s2), (s
All of the setd instructions in 4) set the registers in FIG. 5, so they can all be deleted. The instruction sequence after deletion is shown in Figure 1.
It becomes part (3) of 0. The subroutine call instruction generation means 224 shown in FIG. 1 adds the prolog routine call instruction of FIG. 9 containing the constant data setting instruction to the head of the instruction sequence after the constant data setting instruction is deleted. The epilogue routine call instruction is added to the end of the instruction sequence.

【0036】図10の(1)の部分にはプロローグルー
チンを呼び出す命令列を示す。このサブルーチンの例で
は、%r18〜%r21までの4個の呼び出し保存レジ
スタを使用するため、プロローグルーチン.newsa
ve4を呼び出している。なお、プロローグルーチン.
newsave4への引き数は%r16と%r17に設
定する。また、52バイトのスタック領域を割り付ける
ために%r16にサイズを設定し、レジスタ%r18、
%r19、%r20にシンボルアドレス_a,_b,_
dを設定するために%r17にビットフラグ0x7を設
定している。定数データはプロローグルーチン呼び出し
命令“call.newsave4”の直後に配置して
いる(図10の(2)の部分)。
The part (1) of FIG. 10 shows an instruction sequence for calling the prologue routine. In the example of this subroutine, since four call save registers of% r18 to% r21 are used, the prolog routine. newsa
calling ve4. The prologue routine.
The arguments to newsave4 are set to% r16 and% r17. Also, in order to allocate the stack area of 52 bytes, set the size to% r16, register% r18,
Symbol addresses _a, _b, _ at% r19 and% r20
A bit flag 0x7 is set in% r17 to set d. The constant data is arranged immediately after the prologue routine calling instruction "call.newsave4" (portion (2) in FIG. 10).

【0037】削除可能な定数データ設定命令が見つから
ない場合、図1に示すサブルーチン呼び出し命令生成手
段224は、従来通りのプロローグルーチン.save
Nを呼び出す命令列を生成する。ただし、プロローグル
ーチンとして.newsaveNしか用意していない場
合は、レジスタ%r17に0を設定して、.newsa
veNを呼び出してもよい。
When the deletable constant data setting instruction is not found, the subroutine call instruction generating means 224 shown in FIG. 1 is the conventional prolog routine. save
An instruction sequence for calling N is generated. However, as a prologue routine. If only newsaveN is prepared, 0 is set in the register% r17, and. newsa
You may call veN.

【0038】図1に示す機械語コード生成部23は、中
間言語の命令列をターゲットCPUの機械語に変換し
て、オブジェクトプログラム3を生成する。リンカ6
は、オブジェクトプログラム3、プロローグルーチンお
よびエピローグルーチン4、必要に応じてその他のライ
ブラリルーチン5をリンクして、実行プログラム7を生
成する。
The machine language code generator 23 shown in FIG. 1 converts the instruction string of the intermediate language into the machine language of the target CPU to generate the object program 3. Linker 6
Creates an execution program 7 by linking the object program 3, the prolog routine and the epilog routine 4, and other library routines 5 as necessary.

【0039】〈具体例1の効果〉以上の処理により、
(s1)、(s2)、(s4)の3つのsetd命令
(64ビット)を削除する代わりに、図10の(2)の
部分に示す3つの定数データ(各データは32ビット
長)を用意し、ビットフラグ0x7の設定命令“set
i 0x7,%r17”を追加するだけでよいため、差
し引き64ビット(8バイト)のコード削減になる。即
ち、以上のプロローグコード生成方法では、従来、呼び
出し保存レジスタの退避、スタックの割り付け、あるい
はその両方の処理しか行わなかったプロローグルーチン
に、シンボルアドレスや数値定数等の定数データをレジ
スタに設定する処理を含められるようにするために、コ
ンパイル対象のサブルーチン命令列中から、定数データ
をレジスタに設定する命令で、かつ、サブルーチン入口
に移動可能なものを探し出し、その定数データの設定先
レジスタに、予め決めておいた特定の呼び出し保存レジ
スタを割り付けると共に、その特定レジスタに設定する
定数データをメモリ上に格納しておき、プロローグルー
チンによってメモリ上に格納した定数データを、予め決
めておいた特定の呼び出し保存レジスタに設定するよう
にした。定数データ設定命令をプロローグルーチンに含
めることにより、サブルーチン本体の命令列からその定
数データ設定命令を削除することが可能になり、オブジ
ェクトプログラムのサイズを削減できるようになる。
<Effect of Concrete Example 1> By the above processing,
Instead of deleting the three setd instructions (64 bits) of (s1), (s2), and (s4), prepare three constant data (each data is 32 bits long) shown in part (2) of FIG. The bit flag 0x7 setting instruction “set
Since i 0x7,% r17 ”is simply added, the code is reduced by 64 bits (8 bytes). That is, in the above prolog code generation method, conventionally, the call save register is saved, the stack is allocated, or In order to enable the prologue routine that performed only both of these processes to include the process of setting constant data such as symbol addresses and numeric constants in registers, the constant data is registered in the register from the subroutine instruction string to be compiled. Find a command that can be set and that can be moved to the entrance of the subroutine, assign a specific call save register that has been determined in advance to the register to which the constant data is set, and store the constant data that is set in that specific register in the memory. Stored on the memory by the prolog routine The constant data stored above is set to a specific call save register that has been determined in advance.By including the constant data setting instruction in the prolog routine, the constant data setting instruction is deleted from the instruction string of the subroutine body. It becomes possible to reduce the size of the object program.

【0040】〈具体例2〉この具体例2の方法は、複数
のレジスタを有し、そのレジスタを呼び出し保存である
ものとそうでないものとに分けて使用し、かつ、サブル
ーチン引き数を呼び出し保存でないレジスタに乗せて渡
すようなコードを生成するコンパイラにおいて、次のよ
うな処理を行う。まず、呼び出し保存でない引き数レジ
スタ(A)と、その退避先の呼び出し保存レジスタ
(B)の組を予め決めておく。その呼び出し保存レジス
タ(B)に引き数レジスタ(A)を複写する命令列を含
めたプロローグルーチンと、コンパイラのレジスタ割り
付け終了後に、サブルーチンの入口の基本ブロック内の
命令列から、引き数レジスタ(A)を呼び出し保存レジ
スタ(C)に複写する命令群(I)を探し出す引き数複
写命令検出手段を設ける。
<Specific Example 2> The method of this specific example 2 has a plurality of registers, and those registers are used by being divided into those which are called and saved and those which are not called, and the subroutine arguments are called and saved. In a compiler that generates code that is passed in a non-register, the following processing is performed. First, a pair of an argument register (A) which is not a call save and a call save register (B) which is the save destination is determined in advance. The prolog routine including an instruction sequence for copying the argument register (A) into the call save register (B) and the instruction sequence in the basic block at the entrance of the subroutine after the compiler register allocation is completed ) Is stored in the call save register (C), and an argument copy instruction detecting means for searching the instruction group (I) is provided.

【0041】さらに、上記引き数複写命令群(I)中の
各命令に対し、その複写先の呼び出し保存レジスタ
(C)が、プロローグルーチンとの間で予め決められて
いる呼び出し保存レジスタ(B)と異なる場合に、その
2つのレジスタ(B)と(C)の交換が可能か否かを、
その2つのレジスタを参照または定義しているサブルー
チン中の全命令群(J)に対して検査し、交換可能なら
ばその2つのレジスタを入れ換えて、それに応じて命令
群(J)のオペランドを書き換えるレジスタ交換手段を
設ける。また、上記レジスタ交換手段によるオペランド
書き換え後の引き数複写命令群(I)の中から、引き数
レジスタと複写先の呼び出し保存レジスタの組が、プロ
ローグルーチンとの間で決めたレジスタの組(A)と
(B)に同じであるものを探し出し、それをサブルーチ
ン入口の基本ブロック内の命令列から削除する引き数複
写命令削除手段と、プロローグルーチンを呼び出す命令
を、サブルーチンの命令列の先頭に生成するサブルーチ
ン呼び出し命令生成手段とを設ける。
Furthermore, for each instruction in the argument copy instruction group (I), the call save register (C) of the copy destination is a call save register (B) which is predetermined with the prologue routine. If the two registers (B) and (C) can be exchanged,
All the instruction groups (J) in the subroutine referencing or defining the two registers are inspected, and if they are exchangeable, the two registers are exchanged and the operands of the instruction group (J) are rewritten accordingly. A register exchange means is provided. Further, from the argument copy instruction group (I) after the operand rewriting by the register exchanging means, the set of the argument register and the call save register of the copy destination is the register set (A) determined between the prolog routine. ) And (B) are found, and an argument copy instruction deleting means for locating the same thing as the instruction string in the basic block at the entrance of the subroutine and an instruction for calling the prolog routine are generated at the head of the instruction string of the subroutine. And a subroutine call instruction generating means for performing the same.

【0042】図11は、サブルーチンf()で、図12
の命令列は、具体例2を実施するために図1に示す中間
コード生成部及び最適化部21が出力したレジスタ割り
付け後の命令列を表している。プロローグコードとエピ
ローグコードはまだ付加されていない。図13には、プ
ロローグルーチンで予め決めてある引き数レジスタと、
その複写先の呼び出し保存レジスタの組を示している。
FIG. 11 shows the subroutine f () in FIG.
The instruction sequence of 1 represents the instruction sequence after register allocation output by the intermediate code generation unit and the optimization unit 21 shown in FIG. 1 to implement the second specific example. The prologue code and epilogue code have not been added yet. FIG. 13 shows an argument register which is predetermined in the prologue routine,
The set of call save registers of the copy destination is shown.

【0043】図14には、図12のサブルーチン命令列
に従来のエピローグルーチン.save3とエピローグ
ルーチン.restore3を呼び出す命令を追加した
例を示す。図15には、この具体例2で用いるプロロー
グルーチン.newsaveNの例を示す。また、図1
6には、図12のサブルーチン命令列にこの具体例2で
説明するプロローグコード生成方法で用いるプロローグ
ルーチン.newsave3を呼び出す命令を追加した
例を示す。エピローグルーチンの呼び出し命令は図14
の従来の方法の場合と同じである。以下では、図16の
命令列が図1に示すプロローグコード生成部22で、ど
のように生成されるかについて、その詳細を説明する。
FIG. 14 shows the conventional epilogue routine. save3 and epilogue routine. An example in which an instruction to call restore3 is added will be shown. FIG. 15 shows a prologue routine used in the second specific example. An example of newsaveN is shown. FIG.
6 includes a prolog routine used in the prolog code generation method described in the second specific example in the subroutine instruction sequence of FIG. An example in which an instruction to call newsave3 is added will be shown. The instruction to call the epilogue routine is shown in FIG.
This is the same as in the conventional method of. Hereinafter, the details of how the prolog code generation unit 22 shown in FIG. 1 generates the instruction sequence of FIG. 16 will be described.

【0044】図1の定数データ設定命令抽出手段221
は、この具体例では引き数複写命令抽出手段として動作
し、図12の命令列の先頭の基本ブロック内から引き数
レジスタ%r8〜%r11を、呼び出し保存レジスタ%
r18〜%r29に複写している命令(引き数複写命
令)群を探し出す。基本ブロックの終わりは、ラベルか
サブルーチン呼び出し命令の直前の命令、またはサブル
ーチン命令列の最後の命令であるため、図12の例で
は、次のサブルーチン呼び出し命令が基本ブロックの終
わりになる。 call g また、その基本ブロック内にある引き数複写命令は次の
2つである。 mov %r8,%r18 (m1) mov %r9,%r20 (m2)
Constant data setting command extracting means 221 shown in FIG.
Operates as argument copy instruction extracting means in this specific example, and calls the argument save registers% r8 to% r11 from the basic block at the head of the instruction sequence in FIG.
The group of commands (argument copy commands) copied from r18 to% r29 is searched for. Since the end of the basic block is the instruction immediately before the label or the subroutine call instruction, or the last instruction of the subroutine instruction sequence, the next subroutine call instruction is the end of the basic block in the example of FIG. call g Further, the following two argument copy instructions are included in the basic block. mov% r8,% r18 (m1) mov% r9,% r20 (m2)

【0045】レジスタ交換手段222は、上記の2つの
引き数複写命令(m1)と(m2)に対し、その複写先
の呼び出し保存レジスタが、図13に示したレジスタと
同じか否かを調べる。引き数複写命令(m1)は、引き
数レジスタ%r8を図13に示した呼び出し保存レジス
タ%r18に複写しているが、引き数複写命令(m2)
は、引き数レジスタ%r9を呼び出し保存レジスタ%r
19ではなく、別の呼び出し保存レジスタ%r20に複
写している。そこで、レジスタ交換手段222は、呼び
出し保存レジスタ%r19と%r20の交換が可能か否
かを、図12に示した全ての命令列に対してチェックす
る。図12の命令列中で%r19と%r20を参照また
は定義している命令群は、次の通りである。
The register exchanging means 222 checks whether or not the call save register of the copy destination is the same as the register shown in FIG. 13 for the above two argument copy instructions (m1) and (m2). The argument copy instruction (m1) copies the argument register% r8 to the call save register% r18 shown in FIG. 13, but the argument copy instruction (m2)
Calls the argument register% r9 and save register% r
Instead of 19, it is copied to another call save register% r20. Therefore, the register exchanging unit 222 checks whether or not the call save registers% r19 and% r20 can be exchanged for all the instruction sequences shown in FIG. The instruction groups that refer to or define% r19 and% r20 in the instruction sequence of FIG. 12 are as follows.

【0046】 mov %r9,%r20 add %r18,%r20,%r19 cmpi %r20,0 mov %r18,%r20 add %r18,%r19,%r12 add %r12,%r20,%r12 これらの命令は、任意のレジスタ(%r0〜%r31)
をオペランドに指定できるので、%r19と%r20を
入れ換えて、それぞれ次のように書き換えることができ
る。 mov %r9,%r19 add %r18,%r19,%r20 cmpi %r19,0 mov %r18,%r19 add %r18,%r20,%r12 add %r12,%r19,%r12
Mov% r9,% r20 add% r18,% r20,% r19 cmpi% r20, 0 mov% r18,% r20 add% r18,% r19,% r12 add% r12,% r20,% r12 These instructions Is any register (% r0 to% r31)
Can be specified as an operand,% R19 and% r20 can be exchanged and rewritten as follows. mov% r9,% r19 add% r18,% r19,% r20 cmpi% r19,0 mov% r18,% r19 add% r18,% r20,% r12 add% r12,% r19,% r12

【0047】また、この書き換えを行った後の引き数複
写命令は次のようになる。 mov %r8,%r18 (m3) mov %r9,%r19 (m4) 特定の呼び出し保存レジスタしかオペランドに指定でき
ないような命令が存在する場合は、このような書き換え
が行えないことになる。例えば、上記のcmpi命令が
%r20しかオペランドに指定できない場合は、上記の
ような書き換えは行わない。
The argument copy instruction after this rewriting is as follows. mov% r8,% r18 (m3) mov% r9,% r19 (m4) If there is an instruction in which only a specific call save register can be designated as an operand, such rewriting cannot be performed. For example, if the above cmpi instruction can specify only% r20 as an operand, the above rewriting is not performed.

【0048】図1の定数データ設定命令削除手段223
は、具体例2では引数複写命令削除手段として動作し、
上記のレジスタの交換を行った後の引き数複写命令(m
3)と(m4)の中で、図13に示した引き数レジスタ
と複写先レジスタの組を満足するものを削除する。上記
の(m3)と(m4)はいずれも図13のレジスタの組
と同じであるため、全て削除できる。上記のレジスタの
交換と引き数複写命令(m3)と(m4)の削除を行っ
た後の命令列は図16の(2)式の部分になる。サブル
ーチン呼び出し命令生成手段224は、引き数複写命令
を含んだ図15のプロローグルーチン呼び出し命令を、
引き数複写命令削除後の命令列の先頭に追加する。ま
た、エピローグルーチン呼び出し命令は命令列の最後に
追加する。
The constant data setting command deleting means 223 shown in FIG.
Operates as argument copy instruction deleting means in the second specific example,
Argument copy instruction (m after replacement of the above registers)
Among 3) and (m4), those satisfying the set of argument register and copy destination register shown in FIG. 13 are deleted. Since both of (m3) and (m4) are the same as the set of registers in FIG. 13, they can all be deleted. The instruction sequence after the above-mentioned register exchange and the deletion of the argument copy instructions (m3) and (m4) becomes the portion of the equation (2) in FIG. The subroutine call instruction generation means 224 executes the prolog routine call instruction of FIG. 15 including the argument copy instruction,
Add to the beginning of the command sequence after the argument copy command is deleted. The epilogue routine call instruction is added to the end of the instruction sequence.

【0049】図16の(1)の部分にはプロローグルー
チンを呼び出す命令列を示す。このサブルーチンf()
の例では、%r18〜%r20の3個の呼び出し保存レ
ジスタを退避し、52バイトのスタック領域を割り付け
るため、プロローグルーチン.newsave3への引
き数レジスタ%r16にスタック領域のサイズ52を設
定して.newsave3を呼び出している。削除可能
な引き数複写命令が無い場合、サブルーチン呼び出し命
令生成手段224は、従来通りのプロローグルーチン.
saveNを呼び出す命令列を生成する。ただし、プロ
ローグルーチンとして.newsaveNしか用意して
いない場合には、常に.newsaveNを呼び出して
もよい。なお、その場合にはsaveNの引き数複写命
令部分は無駄な処理である。
The part (1) of FIG. 16 shows an instruction sequence for calling the prologue routine. This subroutine f ()
In the above example, since the three call save registers of% r18 to% r20 are saved and the stack area of 52 bytes is allocated, the prolog routine. Set the size 52 of the stack area in the argument register% r16 to newsave3. Calling newsave3. If there is no deletable argument copy instruction, the subroutine call instruction generation means 224 is the same as the conventional prolog routine.
An instruction sequence for calling saveN is generated. However, as a prologue routine. When only newsaveN is prepared, always. You may call newsaveN. In that case, the argument copy instruction part of saveN is a wasteful process.

【0050】〈具体例2の効果〉以上のプロローグコー
ド生成方法では、引き数複写命令を、プロローグルーチ
ンに含めることによりもとのサブルーチンから削除可能
になり、オブジェクトプログラムのサイズを削減できる
ようになる。
<Effect of Concrete Example 2> In the above prolog code generation method, the argument copy instruction can be deleted from the original subroutine by including it in the prolog routine, and the size of the object program can be reduced. .

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

【図1】本発明の方法を実施するためのシステムブロッ
ク図である。
FIG. 1 is a system block diagram for implementing the method of the present invention.

【図2】サブルーチンのC言語ソースプログラム例説明
図である。
FIG. 2 is an explanatory diagram of an example of a C language source program of a subroutine.

【図3】コンパイル結果の命令列の説明図である。FIG. 3 is an explanatory diagram of an instruction sequence resulting from compilation.

【図4】レジスタと命令の内容説明図である。FIG. 4 is a diagram illustrating the contents of registers and instructions.

【図5】呼び出し保存レジスタの説明図である。FIG. 5 is an explanatory diagram of a call storage register.

【図6】プロローグルーチンとエピローグルーチンの説
明図である。
FIG. 6 is an explanatory diagram of a prologue routine and an epilogue routine.

【図7】スタックの内容説明図である。FIG. 7 is an explanatory diagram of contents of a stack.

【図8】従来の方法によるコンパイル結果の命令列説明
図である。
FIG. 8 is an explanatory diagram of an instruction sequence of a compilation result by the conventional method.

【図9】プロローグルーチンの例説明図である。FIG. 9 is an explanatory diagram of an example of a prologue routine.

【図10】本発明によるコンパイル結果の命令列説明図
である。
FIG. 10 is an explanatory diagram of an instruction sequence of a compilation result according to the present invention.

【図11】サブルーチンのC言語ソースプログラム例説
明図である。
FIG. 11 is an explanatory diagram of an example of a C language source program of a subroutine.

【図12】コンパイル結果の命令列の説明図である。FIG. 12 is an explanatory diagram of an instruction sequence resulting from compilation.

【図13】呼び出し保存レジスタの説明図である。FIG. 13 is an explanatory diagram of a call saving register.

【図14】従来の方法によるコンパイル結果の命令列説
明図である。
FIG. 14 is an explanatory diagram of an instruction sequence of a compilation result by the conventional method.

【図15】プロローグルーチンの例説明図である。FIG. 15 is an explanatory diagram of an example of a prologue routine.

【図16】本発明によるコンパイル結果の命令列説明図
である。
FIG. 16 is an explanatory diagram of an instruction sequence of a compilation result according to the present invention.

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

1 ソースプログラム 2 コンパイラ 3 オブジェクトプログラム 4 プロローグルーチン,エピローグルーチン 5 ライブラリ 6 リンカ 7 実行プログラム 21 中間コード生成部及び最適化部 22 プロローグコード生成部 23 機械語コード生成部 1 Source Program 2 Compiler 3 Object Program 4 Prolog Routine, Epilog Routine 5 Library 6 Linker 7 Execution Program 21 Intermediate Code Generator and Optimizer 22 Prolog Code Generator 23 Machine Language Code Generator

Claims (3)

【特許請求の範囲】[Claims] 【請求項1】 オブジェクトプログラムのサブルーチン
入口で、レジスタの退避を含む処理を実行するプロロー
グコードと、サブルーチン出口で、レジスタの復帰を含
む処理を実行するエピローグコードを用いてサブルーチ
ン呼び出しを実現するコンパイラにより、 前記サブルーチンの命令列中から、所定の定数データを
レジスタに設定する命令であって、かつ、そのサブルー
チン入口に移動可能なものを抽出して削除し、 その定数データ設定先のレジスタとして、予め定めた特
定の呼び出し保存レジスタを割り付け、 前記定数データはメモリ上に格納しておき、 前記メモリ上の定数データを前記予め定めた特定の呼び
出し保存レジスタに複写するためのプロローグルーチン
を呼び出す処理を含むプロローグコードを生成すること
を特徴とするサブルーチンのプロローグコード生成方
法。
1. A compiler that implements a subroutine call by using a prologue code that executes a process including register saving at a subroutine entrance of an object program and an epilogue code that executes a process including register restoration at a subroutine exit , An instruction that sets a predetermined constant data in a register from the instruction sequence of the subroutine and that can be moved to the entrance of the subroutine is extracted and deleted. Allocating a predetermined specific call save register, storing the constant data in a memory, and calling a prologue routine for copying the constant data in the memory to the predetermined specific call save register Characterized by generating a prologue code Prologue code generation method of the subroutine that.
【請求項2】 サブルーチンの命令列中から抽出した、
所定の定数データをレジスタに設定する定数設定命令に
よって設定される呼び出し保存レジスタが、プロローグ
ルーチンとの間で予め定められた所内の呼び出し保存レ
ジスタ群に含まれない場合に、 前記定数設定命令によって設定される呼び出し保存レジ
スタと交換可能なレジスタが、前記所定の呼び出し保存
レジスタ群中に存在するかどうかを調べ、 交換可能なレジスタ同士を入れ換えて、 これらのレジスタを参照しもしくは定義しているサブル
ーチン中の命令のオペランドを書き換えることを特徴と
する請求項1記載のサブルーチンのプロローグコード生
成方法。
2. Extracted from the instruction sequence of the subroutine,
Set by the constant setting instruction when the call save register set by the constant setting instruction that sets the predetermined constant data in the register is not included in the call save register group in the place predetermined with the prologue routine. Check whether or not there is a register that can be exchanged with the call save register that is exchanged in the specified call save register group, replace the exchangeable registers with each other, and refer to or define these registers in the subroutine. 2. The method of claim 1, wherein the operand of the instruction is rewritten.
【請求項3】 オブジェクトプログラムのサブルーチン
入口で、レジスタの退避を含む処理を実行するプロロー
グコードと、サブルーチン出口で、レジスタの復帰を含
む処理を実行するエピローグコードを用いてサブルーチ
ン呼び出しを実現するコンパイラにより、 前記サブルーチンの入口の基本ブロック内で、引き数レ
ジスタの複写が行われる場合に、その複写命令を抽出し
て削除し、 前記引き数レジスタの複写先のレジスタとして、予め定
めた特定の呼び出し保存レジスタを割り付け、 前記特定の呼び出し保存レジスタへの引き数の複写命令
を含むプロローグルーチンを呼び出す処理を含むプロロ
ーグコードを生成することを特徴とするサブルーチンの
プロローグコード生成方法。
3. A compiler that implements a subroutine call by using a prologue code that executes processing including register saving at the entrance of a subroutine of an object program and an epilogue code that executes processing including register restoration at the exit of the subroutine. If a copy of the argument register is performed in the basic block at the entrance of the subroutine, the copy instruction is extracted and deleted, and a predetermined specific call save is performed as a register to which the argument register is copied. A method of generating a prologue code for a subroutine, which comprises allocating a register and generating a prologue code including a process of calling a prologue routine including a copy instruction of an argument to the specific call save register.
JP32811295A 1995-11-22 1995-11-22 Prolog code generation method for subroutine Pending JPH09146775A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP32811295A JPH09146775A (en) 1995-11-22 1995-11-22 Prolog code generation method for subroutine

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP32811295A JPH09146775A (en) 1995-11-22 1995-11-22 Prolog code generation method for subroutine

Publications (1)

Publication Number Publication Date
JPH09146775A true JPH09146775A (en) 1997-06-06

Family

ID=18206632

Family Applications (1)

Application Number Title Priority Date Filing Date
JP32811295A Pending JPH09146775A (en) 1995-11-22 1995-11-22 Prolog code generation method for subroutine

Country Status (1)

Country Link
JP (1) JPH09146775A (en)

Similar Documents

Publication Publication Date Title
JP3602857B2 (en) Multi-model compatible information processing system and method
Shao et al. A type-based compiler for Standard ML
JP3553834B2 (en) Computer architecture emulation system
US5613120A (en) System and method for enabling, without recompilation, modification of class definitions and implementations in an object-oriented computer program
JP4573189B2 (en) Program code conversion method
US6226789B1 (en) Method and apparatus for data flow analysis
US7725883B1 (en) Program interpreter
US5313387A (en) Re-execution of edit-compile-run cycles for changed lines of source code, with storage of associated data in buffers
JP3220055B2 (en) An optimizing device for optimizing a machine language instruction sequence or an assembly language instruction sequence, and a compiler device for converting a source program described in a high-level language into a machine language or an assembly language instruction sequence.
US5201050A (en) Line-skip compiler for source-code development system
US20020199179A1 (en) Method and apparatus for compiler-generated triggering of auxiliary codes
JP4833206B2 (en) Generation of unwind information for optimized programs
US7036118B1 (en) System for executing computer programs on a limited-memory computing machine
JPH01166141A (en) Debugging system
US7181730B2 (en) Methods and apparatus for indirect VLIW memory allocation
JP2002527811A (en) How to inline virtual calls directly without on-stack replacement
US5613121A (en) Method and system of generating combined storage references
JP4041248B2 (en) COMPILER DEVICE, COMPUTER-READABLE RECORDING MEDIUM CONTAINING COMPILING PROGRAM, AND COMPILING METHOD
Kieburtz The G-machine: A fast, graph-reduction evaluator
JPH06324881A (en) Compiler device with superposition deciding function of memory data
US5940621A (en) Language independent optimal size-based storage allocation
US5555412A (en) Complier and method for alias checking in a complier
Bartley et al. The implementation of PC Scheme
US20020032901A1 (en) Unitary data structure systems, methods, and computer program products, for global conflict determination
US20030079210A1 (en) Integrated register allocator in a compiler