JPH0689187A - Inline expansion optimizing method - Google Patents

Inline expansion optimizing method

Info

Publication number
JPH0689187A
JPH0689187A JP23914792A JP23914792A JPH0689187A JP H0689187 A JPH0689187 A JP H0689187A JP 23914792 A JP23914792 A JP 23914792A JP 23914792 A JP23914792 A JP 23914792A JP H0689187 A JPH0689187 A JP H0689187A
Authority
JP
Japan
Prior art keywords
function
inline
inline expansion
expansion
temporary variable
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
JP23914792A
Other languages
Japanese (ja)
Inventor
Atsuo Anzaki
篤郎 安崎
Kiyoshi Takahashi
高橋  清
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.)
Hitachi Software Engineering Co Ltd
Hitachi Ltd
Original Assignee
Hitachi Software Engineering Co Ltd
Hitachi 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 Hitachi Software Engineering Co Ltd, Hitachi Ltd filed Critical Hitachi Software Engineering Co Ltd
Priority to JP23914792A priority Critical patent/JPH0689187A/en
Publication of JPH0689187A publication Critical patent/JPH0689187A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

PURPOSE:To improve the execution performance of a function by reducing a temporary variable generating and copy instruction for transfer of parameters and return values based on analysis information of the function at the time of inline expansion of the function. CONSTITUTION:A syntax analysis part 103 reads in a source program 101 and performs the syntax analysis to generate an intermediate code 104 on a storage device 121. The reduction (inline expansion optimization) of the temporary variable generating and copy instruction for parameters and return values is integrated in the processing of an inline expansion optimizing part 105, and the intermediate code 104 on the storage device 121 is changed with an intermediate code of the expansion result. An optimizing part 110 takes the intermediate code 104 as the input and optimizes various codes of function units to change the intermediate code 104. An object program generating part 111 takes the intermediate code 104 as the input and assigns storages and registers to various data in the intermediate code to generate a machine instruction string, thereby outputting an object program 112 to the storage device 121.

Description

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

【0001】[0001]

【産業上の利用分野】本発明は、関数のパラメタやリタ
ン値が値渡しであるC言語のようなプログラミング言語
で記述されたソースプログラムをコンパイル対象とする
コンパイラに係り、特に、関数のインライン展開の最適
化方法に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a compiler which compiles a source program written in a programming language such as C language in which function parameters and return values are passed by value, and in particular, inline expansion of functions. Regarding the optimization method of.

【0002】[0002]

【従来の技術】従来、コンパイラにおいて、サブル−チ
ンや関数の呼び出し時のオ−バヘッドの削減方式とし
て、例えば中田育男著「コンパイラ」第220ペ−ジに
記載されているようなインライン展開が用いられてい
た。これは呼び出される関数の本体を、呼び出し箇所に
展開する手法であり、関数呼び出し時の動的記憶域割り
当て、レジスタの退避回復、リタンアドレスのメンテナ
ンスに係るオ−バヘッドを削減することができる。
2. Description of the Related Art Conventionally, in a compiler, inline expansion such as that described in Ikuo Nakata, "Compiler", page 220, has been used as a method of reducing the overhead at the time of calling a subroutine or a function. It was being done. This is a method of expanding the main body of the called function to the calling location, and it is possible to reduce the overhead related to dynamic storage allocation, register save / recovery, and return address maintenance when the function is called.

【0003】この方式をC言語に適用した事例として、
W.W.Hwu,P.P.Chang,"Inline Function
Expantion for Compiling C Programs",Proceedi
ngsof the SIGPLAN '89 Conference on Pro
graming Language Designand Implementation 等が
報告されている。この論文の報告では、インライン展開
により、さらに定数伝播、死コ−ド削除のような一般的
な最適化も強化されるとある。しかし、C言語のように
関数呼び出し時に多くのパラメタおよびリタン値をも
ち、これらが値渡しであるような場合に生じる一時変数
生成と複写命令の削減については報告されていない。即
ち、値渡しのパラメタ、リタン値に対しては、例外なし
に一時変数の生成と、これに対する複写命令を実行する
ようになっていた。
As an example of applying this method to C language,
W. W. Hwu, P. P. Chang, "Inline Function
Expansion for Compiling C Programs ", Processedi
ngsof the SIGPLAN '89 Conference on Pro
The graming Language Design and Implementation etc. have been reported. In this paper, inline expansion further enhances general optimizations such as constant propagation and dead code elimination. However, the reduction of temporary variable generation and copy instructions that occur when a large number of parameters and return values are called at the time of function call as in the C language and these are value-passed have not been reported. That is, for a parameter passed by value and a return value, a temporary variable is generated without exception and a copy instruction for the temporary variable is executed.

【0004】[0004]

【発明が解決しようとする課題】上述のように、従来の
コンパイラにおいては、関数呼び出し時に多くのパラメ
タおよびリタン値をもち、これらが値渡しであるような
場合に生じる一時変数生成と複写命令の削減について配
慮がされていない。
As described above, the conventional compiler has a large number of parameters and return values at the time of function call, and the temporary variable generation and copy instructions generated when these are passed by value. No consideration is given to reduction.

【0005】一例として、図2に示すC言語ソ−スプロ
グラムをコンパイルする場合を考える。図7は、このC
言語ソースプログラムを従来のコンパイラで処理した場
合の目的プログラムの動作を表わす擬似Cコードを示し
ている。
As an example, consider the case of compiling the C language source program shown in FIG. Figure 7 shows this C
The pseudo C code showing the operation of the target program when the language source program is processed by the conventional compiler is shown.

【0006】図7に見られるように従来は、関数gのイ
ンライン展開によりパラメタa,bに対し一時変数
a’,b’を生成し、関数gのインライン展開部分に先
行して引数aをa’に、引数bをb’に複写し、インラ
イン展開中でパラメタの参照をa’,b’に置換しなけ
ればならない。また、リタン値についても、一時変数t
を生成し、リタン値をtに設定し、インライン展開部分
の最後でtをcに複写しなければならない。
As shown in FIG. 7, conventionally, temporary variables a'and b'are generated for the parameters a and b by the inline expansion of the function g, and the argument a is preceded by a before the inline expansion part of the function g. It is necessary to copy the argument b into b'into 'and replace the parameter reference with a'and b'in the inline expansion. Also, regarding the return value, the temporary variable t
Must be generated, the return value must be set to t, and t must be copied to c at the end of the inline expansion.

【0007】しかしながら、インライン展開において、
呼び出される関数中でパラメタに対する副作用がない場
合には、パラメタに対する一時変数生成と複写を行なう
必要はないものであり、また、呼び出し元でリタン値が
代入演算により別の変数に代入される場合には、この変
数を一時変数と置換することによって、リタン値に対す
る一時変数生成と複写は不要になるものである。
However, in the inline expansion,
If there is no side effect on the parameter in the called function, it is not necessary to create and copy a temporary variable for the parameter. Also, if the return value is assigned to another variable by the assignment operation at the caller. Replaces this variable with a temporary variable, which eliminates the need for temporary variable generation and copying for the return value.

【0008】本発明の目的は、このようなパラメタやリ
タン値の値渡しのための不要な一時変数生成と複写命令
を削除することによって、関数の実行性能を向上させる
インライン展開最適化方法を提供することにある。
An object of the present invention is to provide an inline expansion optimizing method for improving the execution performance of a function by deleting unnecessary temporary variable generation and copy instructions for passing values such as parameters and return values. To do.

【0009】[0009]

【課題を解決するための手段】本発明は、関数のパラメ
タやリタン値が値渡しのC言語等のソースプログラムを
対象とし、関数のインライン展開を行なうコンパイラに
おいて、インライン展開される関数に関し予め解析を行
なうことにより、そのパラメタやリタン値の値渡しのた
めの一時変数生成及び複写命令の要否を判断するための
情報を収集し、この情報に基づき、関数のインライン展
開時にパラメタやリタン値の値渡しのための一時変数生
成及び複写命令の削減を行なうことを骨子とするもので
ある。
SUMMARY OF THE INVENTION The present invention targets a source program in C language or the like in which function parameters and return values are passed by value, and in a compiler that performs inline expansion of functions, the functions to be inline expanded are analyzed in advance. By collecting the information for determining the necessity of the temporary variable generation and copy instruction for passing the parameter or the return value of the value, and based on this information, the parameter or the return value of the parameter or the return value is expanded when the function is inline expanded. The main idea is to create temporary variables for passing by value and reduce the number of copy commands.

【0010】[0010]

【作用】本発明によれば、関数の解析情報に基づき、一
時変数が必要と判断されるパラメタに対しては、従来と
同様な処理、すなわち一時変数を割り当て、この一時変
数へのパラメタ値の複写コードを挿入し、関数本体のコ
ードを呼び出し元に複写する際にパラメタの参照を一時
変数の参照に置換する、という処理が行なわれることに
なるが、一時変数が不要と判断されるパラメタに対して
は、このような処理は省かれる。
According to the present invention, based on the analysis information of the function, the same processing as in the past, that is, a temporary variable is assigned to the parameter for which the temporary variable is determined to be necessary, and the parameter value of the temporary variable is assigned. The process of inserting the copy code and replacing the reference of the parameter with the reference of the temporary variable when copying the code of the function body to the caller will be performed, but for the parameter judged that the temporary variable is unnecessary On the other hand, such processing is omitted.

【0011】また、解析情報に基づき一時変数が必要と
判断されるリタン値に対しては、従来と同様に、一時変
数を割り当て、関数本体のインライン展開時にリタン式
の評価値をこの一時変数に代入するコードに置換する、
という処理が行なわれることになるが、一時変数が不要
と判断されるリタン値に対しては、関数本体のインライ
ン展開時にリタン式の評価結果を呼び出し元の変数に直
接代入するコードに置換するという処理のみとなる。
Further, as in the conventional case, a temporary variable is assigned to a return value that is determined to require a temporary variable based on the analysis information, and the evaluation value of the return expression is assigned to this temporary variable at the time of inline expansion of the function body. Replace with the code to substitute,
However, for the return value that is judged to be unnecessary for the temporary variable, it is said that when the inline expansion of the function body is performed, the evaluation result of the return expression is replaced with the code that directly assigns it to the calling variable. Only processing is possible.

【0012】[0012]

【実施例】図1は本発明の一実施例を示すものであり、
120と121は計算機の中央処理装置(CPU)と記
憶装置である。ここでは、コンパイラ102と、その入
力たるソースプログラム101及び出力たる目的プログ
ラム112はすべて記憶装置121上に置かれるものと
して示している。
FIG. 1 shows an embodiment of the present invention.
Reference numerals 120 and 121 are a central processing unit (CPU) and a storage device of the computer. Here, it is shown that the compiler 102, the source program 101 that is the input thereof, and the target program 112 that is the output thereof are all placed on the storage device 121.

【0013】コンパイラ102は、ソ−スプログラム1
01を読み込みコンパイル処理を行なって目的プログラ
ム112を記憶装置121上に生成するものであり、機
能的には構文解析部103、インライン展開最適化部1
05、最適化部110、目的プログラム生成部111に
分かれる。
The compiler 102 uses the source program 1
01 is read and compiled to generate the target program 112 on the storage device 121. Functionally, the syntax analysis unit 103 and the inline expansion optimization unit 1
05, the optimization unit 110, and the target program generation unit 111.

【0014】構文解析部103は、ソ−スプログラム1
01を読み込み、その構文解析を行って中間コ−ド10
4を記憶装置121上に生成する。インライン展開最適
化部105は、中間コ−ド104を取り込んで解析する
ことによってコ−ルグラフ107を作成するコ−ルグラ
フ作成部106、このコ−ルグラフ107を入力として
インライン展開の可否を判定するインライン展開選択部
108、インライン展開選択部108においてインライ
ン展開可能と判定された関数の呼び出し地点に呼び出さ
れる関数を展開するインライン展開部109から構成さ
れる。本発明のパラメタ、リタン値に対する一時変数生
成と複写命令の削減(インライン展開最適化)は、この
インライン展開最適化部105の処理に統合され、展開
結果の中間コ−ドで記憶装置121上の中間コ−ド10
4を変更する。最適化部110は中間コ−ド104を入
力し、関数単位の各種コ−ド最適化を行い、中間コ−ド
104を変更する。目的プログラム生成部111は、中
間コ−ド104を入力し、中間コ−ド内の各種デ−タに
対する記憶域とレジスタを割り当て、機械命令列を生成
することによって、目的プログラム112を記憶装置1
21上に出力する。ここで、インライン展開最適化の処
理について、より具体的に述べる。コールグラフ作成部
106で、コンパイル対象のソ−スプログラム101の
構文解析により得られた中間コ−ド104をすべて走査
してコ−ルグラフ107を作成するが、このコ−ルグラ
フ作成段階で、呼び出し元の形式と、呼び出し先のパラ
メタの使用形態の情報も収集してコ−ルグラフ107に
格納する。このコ−ルグラフ107をもとにインライン
展開選択部108で、どの関数呼び出しをインライン展
開するかを決定する。
The syntactic analysis unit 103 uses the source program 1
01 is read, the parsing is performed, and the intermediate code 10
4 is generated on the storage device 121. An inline expansion optimization unit 105 takes in the intermediate code 104 and analyzes it to create a call graph 107. A call graph creation unit 106, and an inline for determining whether inline expansion is possible by using this call graph 107 as an input. The expansion selection unit 108 and the inline expansion selection unit 108 include an inline expansion unit 109 that expands a function called at a call point of a function determined to be inline expandable. The temporary variable generation and the reduction of copy commands (inline expansion optimization) for the parameters and the return value of the present invention are integrated into the processing of the inline expansion optimization unit 105, and the intermediate code of the expansion result is stored in the storage device 121. Intermediate code 10
Change 4. The optimization unit 110 inputs the intermediate code 104, performs various code optimizations for each function, and changes the intermediate code 104. The target program generation unit 111 inputs the intermediate code 104, allocates storage areas and registers for various data in the intermediate code, and generates a machine instruction sequence to store the target program 112 in the storage device 1.
21 output on. Here, the inline expansion optimization process will be described more specifically. The call graph creating unit 106 scans all the intermediate codes 104 obtained by the syntax analysis of the source program 101 to be compiled to create a call graph 107, which is called at the call graph creating stage. Information on the original format and the usage pattern of the callee parameter is also collected and stored in the call graph 107. Based on the call graph 107, the inline expansion selection unit 108 determines which function call is to be expanded inline.

【0015】インライン展開部109では、選択された
関数について、その呼び出し元に関数の本体のコ−ドを
複写するが、この際に、コールグラフ107に格納され
ている呼び出し元の形式と、呼び出し先のパラメタの使
用形態の情報を参照し、パラメタに対する一時変数生成
と複写の要否、並びにリタン値に対する一時変数生成の
要否を判断する。
The inline expansion unit 109 copies the code of the body of the function to the caller of the selected function. At this time, the format of the caller stored in the call graph 107 and the call By referring to the information on the usage form of the parameter, it is determined whether or not the temporary variable generation and copying for the parameter are necessary and the temporary variable generation for the return value is necessary.

【0016】そして、一時変数の必要なパラメタに対し
ては、インライン展開に先行して一時変数を割り当て、
一時変数へのパラメタ値の複写コ−ドを挿入し、関数本
体のインライン展開時にはパラメタの参照を一時変数の
参照に置換する。一時変数の不要なパラメタに対して
は、これらの処理は行わない。また、一時変数の必要な
リタン値に対しては、インライン展開に先行して一時変
数を割り当て、関数本体のインライン展開時にはリタン
式の評価結果をこの一時変数に代入するコ−ドに置換す
るが、一時変数の不要なリタン値に対しては、関数本体
のインライン展開時にリタン式の評価結果を呼び出し元
の変数に直接代入するコ−ドに置換するだけである。
Then, for the required parameter of the temporary variable, the temporary variable is assigned prior to the inline expansion,
Insert the copy code of the parameter value into the temporary variable and replace the parameter reference with the temporary variable reference when the function body is inline expanded. These processes are not performed for unnecessary parameters of temporary variables. Also, for the required return value of a temporary variable, a temporary variable is assigned prior to inline expansion, and when the function body is inline expanded, the result of evaluating the return expression is replaced with the code that assigns to this temporary variable. As for the unnecessary return value of the temporary variable, the evaluation result of the return expression is simply replaced with the code that is directly assigned to the calling variable when the function body is inline expanded.

【0017】インライン展開最適化に関連して、コ−ル
グラフ107は次のような形式とされる。
With respect to inline expansion optimization, the call graph 107 is of the form:

【0018】G=(N,A) N:コンパイル対象ソ−スプログラム中の各関数を示す
ノ−ド。 A:コンパイル対象ソ−スプログラム中の各関数呼び出
しに対応するア−ク。呼び出しごとに作成する。
G = (N, A) N: A node indicating each function in the source program to be compiled. A: An arc corresponding to each function call in the source program to be compiled. Create for each call.

【0019】N=(FA,PU) FA:関数Nの属性。 PU:関数N内での各パラメタの使用状況を示すフラグ
列。パラメタが関数内で参照のみの場合”参照のみ”と
し、値が変更される可能性がある場合”変更されうる”
とする。
N = (FA, PU) FA: Attribute of function N. PU: A flag string indicating the usage status of each parameter in the function N. If the parameter is reference only in the function, it is "reference only", and if the value may change, it may be changed.
And

【0020】A=(S,T,AA,AU) S:呼び出し元の関数に対応するノ−ド。 T:呼び出し先の関数に対応するノ−ド。 AA:呼び出し地点の属性。 AU:引数およびリタン値の形態を示すフラグ列。各引
数が対象ア−キテクチャで1機械命令以下でアクセスで
きる場合は”単純”とし、2命令以上となりうる場合
は”複雑”とする。リタン値については、呼び出しもと
で代入元として使用される場合は”単純”とし、代入元
として使用されない場合は”複雑”とする。
A = (S, T, AA, AU) S: Node corresponding to the calling function. T: A node corresponding to the called function. AA: Attribute of calling point. AU: A flag string indicating the form of the argument and the return value. When each argument can be accessed by one machine instruction or less in the target architecture, it is "simple", and when it can be two or more instructions, it is "complex". The return value is "simple" when it is used as the assignment source in the call source, and "complex" when it is not used as the assignment source.

【0021】インライン展開最適化に係るコ−ルグラフ
の要素はPUおよびAUである。このPU,AUの情報
収集に関連し、コ−ルグラフ作成部106に追加される
処理をPAD図として図5に示す。各ステップの内容は
以下のとおりである。
The elements of the call graph relating to the inline expansion optimization are PU and AU. The processing added to the call graph creation unit 106 in relation to the information collection of PU and AU is shown in FIG. 5 as a PAD diagram. The contents of each step are as follows.

【0022】ステップ1:コンパイル対象ソ−スプログ
ラム中の各関数fに対して、ステップ2からステップ7
までの処理を繰り返す。
Step 1: Steps 2 to 7 for each function f in the source program to be compiled
Repeat the process up to.

【0023】ステップ2:まだコ−ルグラフ中に関数f
に対するノ−ドが作成されていなければ関数fに対する
ノ−ドを作成し、FA,PUの情報を初期化する。PU
の初期化は、関数fのパラメタ数分のフラグ配列を割り
当て”参照のみ”に設定する。コ−ルグラフ中に関数f
に対するノ−ドが作成されている場合にはFA,PUの
情報の初期化のみを行う。
Step 2: Function f still in the call graph
If the node for F is not created, the node for the function f is created and the FA and PU information is initialized. PU
For initialization, the flag arrays corresponding to the number of parameters of the function f are allocated and set to “reference only”. Function f in the call graph
When the node for is created, only the FA and PU information is initialized.

【0024】ステップ3:関数f中のすべての演算に対
してステップ4からステップ7までの処理を繰り返す。
Step 3: Steps 4 to 7 are repeated for all operations in the function f.

【0025】ステップ4:演算がパラメタを参照する場
合にはパラメタの値が変更される可能性があるならば、
対応するPU情報を”変更されうる”に変更する。
Step 4: If the value of the parameter may change if the operation references the parameter, then
The corresponding PU information is changed to "changeable".

【0026】ステップ5:演算が関数gの呼び出しの場
合に、ステップ6からステップ7までの処理を行う。
Step 5: When the calculation is the call of the function g, the processing from step 6 to step 7 is performed.

【0027】ステップ6:呼び出し先関数gに対するノ
−ドが作成されていなければ関数fに対するノ−ドを作
成する。
Step 6: If the node for the called function g is not created, the node for the function f is created.

【0028】ステップ7:関数fから関数gへのア−ク
を作成しAA,AU情報を設定する。AU情報は、各引
数が対象ア−キテクチャで1機械命令以下でアクセスで
きる場合に”単純”と設定し、2命令以上となりうる場
合に”複雑”と設定する。リタン値については、関数g
の結果が代入演算の代入元として使用される場合に”単
純”と設定し、代入元として使用されない場合に”複
雑”と設定する。
Step 7: Create an arc from the function f to the function g and set the AA and AU information. The AU information is set to "simple" when each argument can be accessed with one machine instruction or less in the target architecture, and is set to "complex" when there are two or more instructions. For the return value, the function g
If the result of is used as the substitution source of the substitution operation, it is set as "simple", and if it is not used as the substitution source, it is set as "complex".

【0029】インライン展開選択部108によりインラ
イン展開可能と判定された関数呼び出し地点に、呼び出
される関数を展開するインライン展開部109の処理
を、PAD図として図3に示す。各ステップの内容は以
下のとおりである。
FIG. 3 is a PAD diagram showing the processing of the inline expansion unit 109 for expanding the function to be called at the function call point determined by the inline expansion selection unit 108 to be inline expandable. The contents of each step are as follows.

【0030】ステップ11:関数呼び出しに対応するア
−クAのAU情報と、T関数に対応するノ−ドのPU情
報を取り出す。
Step 11: The AU information of the arc A corresponding to the function call and the PU information of the node corresponding to the T function are taken out.

【0031】ステップ12:各パラメタに対してステッ
プ13からステップ14を行う。
Step 12: Steps 13 to 14 are performed for each parameter.

【0032】ステップ13:AU情報が”単純”で、か
つPU情報が”参照のみ”であれば、なにも行わない。
そうでなければステップ14を行う。
Step 13: If the AU information is "simple" and the PU information is "reference only", nothing is done.
If not, step 14 is performed.

【0033】ステップ14:パラメタに対する一時変数
を割り当て、この変数に対して引数を複写するコ−ドを
挿入する。また、パラメタを参照する演算を一時変数参
照に置換するために、置換対レコ−ドを作成する。
Step 14: Allocate a temporary variable for the parameter and insert a code for copying the argument into this variable. Also, a replacement pair record is created in order to replace the operation that refers to the parameter with the temporary variable reference.

【0034】ステップ15:リタン値に対するAU情報
が”単純”の場合はステップ16を、そうでなければス
テップ17を行う。
Step 15: If the AU information for the return value is "simple", then step 16 is carried out. If not, step 17 is carried out.

【0035】ステップ16:リタン式の評価結果の代入
先を示すリタン値代入先レコ−ドに、呼び出し元の代入
演算の代入先を設定する。
Step 16: The assignment destination of the assignment operation of the calling source is set in the return value assignment destination record indicating the assignment destination of the evaluation result of the return expression.

【0036】ステップ17:リタン値に対する一時変数
を割り当て、リタン式の評価結果の代入先を示す一時変
数となるよう、リタン値代入先レコ−ドにこの一時変数
を設定する。
Step 17: A temporary variable is assigned to the return value, and this temporary variable is set in the return value assignment destination record so that it becomes a temporary variable indicating the assignment destination of the evaluation result of the return expression.

【0037】ステップ18:呼び出し先関数中のすべて
の演算に対してステップ19からステップ21までの処
理を繰り返す。
Step 18: Repeat steps 19 to 21 for all the operations in the callee function.

【0038】ステップ19:演算が置換対レコ−ドの置
換元を参照する場合には、置換先に変更して呼び出し元
に挿入する。
Step 19: If the operation refers to the replacement source of the replacement pair record, it is changed to the replacement destination and inserted into the caller.

【0039】ステップ20:演算がリタン式の場合に
は、リタン値代入先レコ−ドへの代入演算に変更して呼
び出し元に挿入する。
Step 20: If the operation is a Ritan expression, the operation is changed to an operation for assigning a record to which a return value is assigned and is inserted into the caller.

【0040】ステップ21:その他の演算の場合には、
そのまま呼び出し元に挿入する。
Step 21: For other calculations,
Insert it as it is in the caller.

【0041】ステップ22:リタン値に対するAU情報
が”複雑”の場合、呼び出し元の演算をリタン値代入先
レコ−ド(この場合一時変数である)に置き換えて挿入
する。
Step 22: When the AU information for the return value is "complex", the caller's operation is replaced with the return value substitution destination record (in this case, a temporary variable) and inserted.

【0042】本発明のコンパイラ102により、図4の
C言語ソ−スプログラムを処理した場合、コ−ルグラフ
作成部106により図6に示す内容のコ−ルグラフ10
7が作成される。この例の場合、パラメタa,bが関数
g内で参照としてしかアクセスされていないことから、
関数gに対応するPU情報はa,b共に”参照のみ”と
なり、関数fから関数gの呼び出しに対応するア−クの
AU情報は引数a,bおよびリタン値のすべてで”単
純”となる。
When the C language source program of FIG. 4 is processed by the compiler 102 of the present invention, the call graph 10 having the contents shown in FIG.
7 is created. In the case of this example, since the parameters a and b are accessed only as a reference in the function g,
The PU information corresponding to the function g is "reference only" for both a and b, and the AU information of the arc corresponding to the call of the function f from the function f is "simple" for all the arguments a, b and the return value. .

【0043】インライン展開選択部108において、こ
の関数呼び出しがインライン可と判定された場合、イン
ライン展開部109では、関数gに対応するPU情報が
a,b共に”参照のみ”であり、関数fから関数gの呼
び出しに対応するア−クのAU情報が引数a,b共に”
単純”であるため、パラメタに対する一時変数割り当
て、引数の一時変数への複写を行わない。リタン値につ
いても、関数fから関数gの呼び出しに対応するア−ク
のAU情報がリタン値に対して”単純”であるため、一
時変数割り当てを行わず、リタン式の評価結果を呼び出
し元の変数に直接代入する。
When the inline expansion selection unit 108 determines that this function call is inline enabled, the inline expansion unit 109 determines that the PU information corresponding to the function g is “reference only” for both a and b, and the function f The AU information of the arc corresponding to the call of the function g is "argument a and b".
Since it is "simple", the temporary variable is not assigned to the parameter and the argument is not copied to the temporary variable. Regarding the return value, the AU information of the arc corresponding to the call from the function f to the function g is also applied to the return value. Since it is "simple", the temporary variable is not allocated and the evaluation result of the Ritan expression is directly assigned to the caller variable.

【0044】したがって、図4のC言語ソースプログラ
ムに対する目的プログラムは、図5に擬似Cコードによ
り示すように実行されることとなる。この例から理解さ
れるように、本発明によれば、インライン展開により最
適化された関数の実行性能を向上させることができる。
また、この最適化をインライン展開最適化処理内で統一
して実行できるとともに、その結果として、その後の一
般的な関数内最適化処理(最適化部110)の負荷を低
減し、かつ、その効果を増すことができる。
Therefore, the target program for the C language source program of FIG. 4 is executed as shown by the pseudo C code in FIG. As can be seen from this example, according to the present invention, it is possible to improve the execution performance of a function optimized by inline expansion.
In addition, this optimization can be executed uniformly in the inline expansion optimization process, and as a result, the load of the general in-function optimization process (optimization unit 110) thereafter can be reduced and its effect can be obtained. Can be increased.

【0045】[0045]

【発明の効果】以上に詳細に説明した如く、本発明によ
れば、コンパイラにおいて、関数の解析情報に基づき、
関数のインライン展開時にパラメタやリタン値の値渡し
のための一時変数生成及び複写命令の削減を行なうこと
により、関数の実行性能を向上させることができる。
As described in detail above, according to the present invention, in the compiler, based on the analysis information of the function,
Execution performance of a function can be improved by reducing the number of temporary variables and copying instructions for passing a parameter or a return value when inlining a function.

【0046】なお、従来技術を適用した後にコピ−伝播
をするによっても同様の効果を期待できる場合もあろ
う。しかし、一時変数の数が増えると、コピ−伝播のよ
うな最適化の処理のオ−バヘッドが増大し、最適化対象
から外れる場合も生じる。最適化対象から外れた場合に
は、一時変数への複写がメモリアクセスを伴うことにな
り、ロ−ドストアア−キテクチャでは、特に大きな性能
劣化となる。本発明によれば、最適化によって新たに生
成するコ−ドはないので、そのような性能劣化が起こる
ことはない。
The same effect may be expected in some cases by performing copy propagation after applying the conventional technique. However, as the number of temporary variables increases, the overhead of optimization processing such as copy propagation increases, which may result in being out of the optimization target. If it is out of the optimization target, copying to a temporary variable involves memory access, and in the load store architecture, the performance is particularly large. According to the present invention, since no code is newly generated by optimization, such performance deterioration does not occur.

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

【図1】本発明の一実施例の構成を示す。FIG. 1 shows the configuration of an embodiment of the present invention.

【図2】コ−ルグラフ作成部106の追加処理のPAD
図である。
FIG. 2 is a PAD of additional processing of the call graph creation unit 106.
It is a figure.

【図3】インライン展開部109の処理のPAD図であ
る。
FIG. 3 is a PAD diagram of processing of an inline expansion unit 109.

【図4】C言語ソ−スプログラムの一例を示す。FIG. 4 shows an example of a C language source program.

【図5】図4のソ−スプログラムを本実施例で処理した
場合の目的プログラムの動作を示す疑似Cコ−ドであ
る。
5 is a pseudo C code showing the operation of the object program when the source program of FIG. 4 is processed in this embodiment.

【図6】図4のソ−スプログラムより生成されるコ−ル
グラフの内容を示す。
6 shows the contents of a call graph generated from the source program of FIG.

【図7】図4のソ−スプログラムを従来技術で処理した
場合の目的プログラムの動作を示す疑似Cコ−ドであ
る。
FIG. 7 is a pseudo C code showing the operation of the target program when the source program of FIG. 4 is processed by the conventional technique.

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

101 ソースプログラム 102 コンパイラ 103 構文解析部 105 インライン展開最適化部 106 コールグラフ作成部 107 コールグラフ 108 インライン展開選択部 109 インライン展開部 110 最適化部 111 目的プログラム生成部 112 目的プログラム 120 中央処理装置 121 記憶装置 Reference numeral 101 source program 102 compiler 103 syntactic analysis unit 105 inline expansion optimization unit 106 call graph creation unit 107 call graph 108 inline expansion selection unit 109 inline expansion unit 110 optimization unit 111 target program generation unit 112 target program 120 central processing unit 121 storage apparatus

───────────────────────────────────────────────────── フロントページの続き (72)発明者 高橋 清 神奈川県横浜市中区尾上町6丁目81番地 日立ソフトウェアエンジニアリング株式会 社内 ─────────────────────────────────────────────────── ─── Continuation of the front page (72) Inventor Kiyoshi Takahashi 6-81 Onoue-cho, Naka-ku, Yokohama-shi, Kanagawa Hitachi Software Engineering Co., Ltd. In-house

Claims (3)

【特許請求の範囲】[Claims] 【請求項1】 関数のインライン展開を行なうコンパイ
ラにおいて、インライン展開される関数に関し予め解析
を行なうことにより、そのパラメタ及びリタン値の値渡
しのための一時変数生成及び複写命令の要否を判断する
ための情報を収集し、この情報に基づき、関数のインラ
イン展開時にパラメタ及びリタン値の値渡しのための一
時変数生成及び複写命令の削減を行なうことを特徴とす
るインライン展開最適化方法。
1. A compiler that performs inline expansion of a function determines whether or not a temporary variable generation and copy instruction for passing a parameter and a return value of the function is necessary by performing an analysis in advance for the function to be inline expanded. A method for optimizing inline expansion, which is characterized by collecting temporary information and performing temporary expansion and temporary reduction of temporary variables for passing parameters and return values at the time of inline expansion of a function based on this information.
【請求項2】 関数のインライン展開を行なうコンパイ
ラにおいて、インライン展開される関数に関し予め解析
を行なうことにより、そのパラメタの値渡しのための一
時変数生成及び複写命令の要否を判断するための情報を
収集し、この情報に基づき、関数のインライン展開時に
パラメタの値渡しのための一時変数の生成及び複写命令
の削減を行なうことを特徴とするインライン展開最適化
方法。
2. Information for determining whether or not a temporary variable generation and copy instruction for passing a value of a parameter is necessary by analyzing in advance the function to be inlined in a compiler that performs inline expansion of a function. And an inline expansion optimizing method characterized by generating temporary variables for passing parameter values and reducing copy instructions based on this information.
【請求項3】 関数のインライン展開を行なうコンパイ
ラにおいて、インライン展開される関数に関し予め解析
を行なうことにより、そのリタン値の値渡しのための一
時変数生成及び複写命令の要否を判断するための情報を
収集し、この情報に基づき、関数のインライン展開時に
リタン値の値渡しのための一時変数の生成及び複写命令
の削減を行なうことを特徴とするインライン展開最適化
方法。
3. A compiler for performing inline expansion of a function, for analyzing the function to be inline expanded in advance to determine whether or not a temporary variable generation and copy instruction for passing the return value is necessary. An inline expansion optimizing method characterized by collecting information, and based on this information, generating a temporary variable for passing a return value by value and reducing copy instructions when the function is inline expanded.
JP23914792A 1992-09-08 1992-09-08 Inline expansion optimizing method Pending JPH0689187A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP23914792A JPH0689187A (en) 1992-09-08 1992-09-08 Inline expansion optimizing method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP23914792A JPH0689187A (en) 1992-09-08 1992-09-08 Inline expansion optimizing method

Publications (1)

Publication Number Publication Date
JPH0689187A true JPH0689187A (en) 1994-03-29

Family

ID=17040455

Family Applications (1)

Application Number Title Priority Date Filing Date
JP23914792A Pending JPH0689187A (en) 1992-09-08 1992-09-08 Inline expansion optimizing method

Country Status (1)

Country Link
JP (1) JPH0689187A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7373641B2 (en) 2001-12-20 2008-05-13 International Business Machines Corporation Method, computer unit and program for converting a program
JP2012014526A (en) * 2010-07-01 2012-01-19 Hitachi Ltd Structure conversion apparatus for program code, and code structure conversion program
JP2012038231A (en) * 2010-08-11 2012-02-23 Internatl Business Mach Corp <Ibm> Compile method for optimizing binary code, compiler system therefor, and computer program

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7373641B2 (en) 2001-12-20 2008-05-13 International Business Machines Corporation Method, computer unit and program for converting a program
JP2012014526A (en) * 2010-07-01 2012-01-19 Hitachi Ltd Structure conversion apparatus for program code, and code structure conversion program
JP2012038231A (en) * 2010-08-11 2012-02-23 Internatl Business Mach Corp <Ibm> Compile method for optimizing binary code, compiler system therefor, and computer program

Similar Documents

Publication Publication Date Title
US7725883B1 (en) Program interpreter
EP0905617B1 (en) Method for generating a java bytecode data flow graph
US5815720A (en) Use of dynamic translation to collect and exploit run-time information in an optimizing compilation system
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.
US7784039B2 (en) Compiler, compilation method, and compilation program
US5920723A (en) Compiler with inter-modular procedure optimization
US6249910B1 (en) Apparatus and method for incrementally update static single assignment form for cloned variable name definitions
US6072952A (en) Method and apparatus for coalescing variables
JPH10124325A (en) Method and device for optimum arrangement of variable, and computer-readable recording medium stored with optimum arrangement program for variable
JP2000035893A (en) Method for statically initializing arrangement of data processing system, data processing method, data processing system and computer readable storage medium storing program making computer execute its control procedure
JP4041248B2 (en) COMPILER DEVICE, COMPUTER-READABLE RECORDING MEDIUM CONTAINING COMPILING PROGRAM, AND COMPILING METHOD
JP3813087B2 (en) Program conversion method, computer apparatus and program
JPH0926884A (en) Method and apparatus for making required flow information usable during task requiring binary information
US10013244B2 (en) Apparatus and method to compile a variadic template function
US5854928A (en) Use of run-time code generation to create speculation recovery code in a computer system
US6665864B1 (en) Method and apparatus for generating code for array range check and method and apparatus for versioning
US7240341B2 (en) Global constant pool to allow deletion of constant pool entries
JPH0689187A (en) Inline expansion optimizing method
JP2000353097A (en) Method and device for generating low density interference graph
JP2004139369A (en) Analysis method for pointer pointing constant address domain
JP3551352B2 (en) Loop splitting method
Teodosiu Hare: An optimizing portable compiler for Scheme
JP3018783B2 (en) Compilation method
JP2002082811A (en) Compiling method and recording medium
JP2944500B2 (en) Compiling apparatus and method