JPH10275088A - Link optimizing method - Google Patents

Link optimizing method

Info

Publication number
JPH10275088A
JPH10275088A JP7958997A JP7958997A JPH10275088A JP H10275088 A JPH10275088 A JP H10275088A JP 7958997 A JP7958997 A JP 7958997A JP 7958997 A JP7958997 A JP 7958997A JP H10275088 A JPH10275088 A JP H10275088A
Authority
JP
Japan
Prior art keywords
external
variable
variables
intermediate code
module
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
JP7958997A
Other languages
Japanese (ja)
Inventor
Kenichi Miyata
賢一 宮田
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 Ltd
Original Assignee
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 Ltd filed Critical Hitachi Ltd
Priority to JP7958997A priority Critical patent/JPH10275088A/en
Publication of JPH10275088A publication Critical patent/JPH10275088A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

PROBLEM TO BE SOLVED: To provide the optimizing method by a linker for enabling reference to different external variables by registers less than the external variables. SOLUTION: When a load module is generated by the linker, respective source modules 201 to 203 are compiled by a compiler 204 to generate intermediate codes 207 to 209 and external symbol tables 210 to 212 in the module. Then the external symbol tables 210 to 212 and libraries 213 to 214 are read in by the linker 215 to generate an external symbol table 217. Further, the external symbol 217 and intermediate codes 207 to 209 are used to convert reference of external variables included in a specific address range determined by an object CPU into reference using one external variable by a base register common-use process 220. Lastly, a load module 223 is generated by a link process 222.

Description

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

【0001】[0001]

【発明の属する技術分野】本発明は、計算機の利用にお
いて、実行命令数を削減するリンク方法に関する。
[0001] 1. Field of the Invention [0002] The present invention relates to a link method for reducing the number of execution instructions in a computer.

【0002】[0002]

【従来の技術】複数のソースファイルからひとつのロー
ドモジュールを作成するために、コンパイラとリンカを
利用する。コンパイラは各ソースファイルをひとつずつ
コンパイルし、各ソースファイルに対応するオブジェク
トモジュールを生成する。そしてリンカは生成されたす
べてのオブジェクトモジュールと必要なライブラリとを
結合して最終的なロードモジュールを生成する。
2. Description of the Related Art A compiler and a linker are used to create one load module from a plurality of source files. The compiler compiles each source file one by one and generates an object module corresponding to each source file. Then, the linker combines all the generated object modules and necessary libraries to generate a final load module.

【0003】ソースファイル中で使用する変数はその通
用範囲によって以下のように分類できる。
[0003] Variables used in a source file can be classified as follows according to the scope of their use.

【0004】(1) ひとつの関数や手続き内でのみ通用す
る変数 (2) ひとつのモジュール内でのみ通用する変数 (3) モジュール間にわたって通用する変数 分類(1)と分類(2)の変数のメモリ位置(アドレス)はコン
パイル時に決定されるのに対して、分類(3)の変数はリ
ンク時にメモリ位置が決定する。分類(3)の変数を外部
変数と呼び、オブジェクトモジュールごとに外部変数の
メモリ位置を管理する表を備えている。このメモリ位置
管理表としてTOC(Table Of Contents)などがある。
リンカは各オブジェクトモジュールとライブラリのすべ
てのメモリ位置管理表を走査して各外部変数のメモリ位
置を決定し、メモリ位置管理表に決定した外部変数のア
ドレスを書き込む。
(1) Variables that are valid only within one function or procedure (2) Variables that are valid only within one module (3) Variables that are valid across modules Classification (1) and classification (2) The memory location (address) is determined at compile time, while the variable of category (3) is determined at link time at the time of linking. The variables of the category (3) are called external variables, and a table is provided for managing the memory locations of the external variables for each object module. The memory location management table is, for example, TOC (Table Of Contents).
The linker scans all memory location management tables of each object module and library to determine the memory location of each external variable, and writes the address of the determined external variable to the memory location management table.

【0005】ここでTOCを通した外部変数の参照につ
いて説明する。外部変数のメモリ位置はコンパイル時に
は決められないため、TOCを通して間接的に行う必要
がある。図1に外部変数の間接参照の一般的な例を示
す。主記憶装置106に蓄えられている値107が外部変数A
とBの値とする。オブジェクトモジュール101は大きく
分けてプログラムを格納しているコード部102とプログ
ラムが参照するデータや変数のアドレスを格納している
データ部103から構成されている。たとえば外部変数A
を参照するためには、ふたつの命令108aと109aが必要で
ある。まず命令108aで外部変数Aの格納されている主記
憶上のアドレス110aをレジスタr1にロードする。次に命
令109aでロードしたアドレスから実際のAの値をレジス
タfr1にロードする。外部変数の格納されているアドレ
スを得るために、命令108aでは、TOC領域の先頭アド
レスを保持するレジスタRTOC(104)とAのアドレス
が格納されているTOC内位置を表わすオフセットoffs
etA(110a)を加える。外部変数Bについても同様で、ふ
たつの命令108bと109bによって外部変数Bを参照するこ
とになる。外部変数BのTOC内のオフセットはoffset
B(110b)であり、変数の値は107bに保存されている。
Here, reference to an external variable through the TOC will be described. Since the memory location of the external variable is not determined at compile time, it must be indirectly performed through the TOC. FIG. 1 shows a general example of indirect reference of an external variable. The value 107 stored in the main memory 106 is the external variable A
And B. The object module 101 is roughly divided into a code section 102 storing a program and a data section 103 storing addresses of data and variables referred to by the program. For example, external variable A
Requires two instructions 108a and 109a. First, the instruction 110a loads the address 110a in the main memory where the external variable A is stored into the register r1. Next, the actual value of A is loaded into the register fr1 from the address loaded by the instruction 109a. In order to obtain the address where the external variable is stored, the instruction 108a uses a register RTOC (104) for holding the head address of the TOC area and an offset offs indicating the position in the TOC where the address of A is stored.
Add etA (110a). Similarly, the external variable B is referred to by the two instructions 108b and 109b. The offset in the TOC of external variable B is offset
B (110b), and the value of the variable is stored in 107b.

【0006】通常は異なる外部変数は異なる外部変数ア
ドレス保持用レジスタを通して参照しなければならな
い。たとえば図1ではふたつの外部変数AとBを参照し
ている。これらの外部変数の参照のために、外部変数A
に対しては108aでアドレス保持用レジスタr1を使用し、
外部変数Bに対しては108bでアドレス保持用レジスタr2
を使用している。外部変数AとBのアドレスはリンク時
に決定するが、リンク時に必要な複数のオブジェクトモ
ジュールとライブラリの指定順序によって外部変数のア
ドレスは変わりうる。またレジスタの割り付けはコンパ
イル時に行われる処理であるために、異なる外部変数に
対して共通のアドレス保持用レジスタをコンパイル時に
割り付けるわけにはいかない。
Normally, different external variables must be referred to through different external variable address holding registers. For example, FIG. 1 refers to two external variables A and B. For reference to these external variables, the external variables A
Use the address holding register r1 at 108a,
For the external variable B, the address holding register r2 is set to 108b.
You are using The addresses of the external variables A and B are determined at the time of linking. However, the addresses of the external variables can be changed depending on the order in which a plurality of object modules and libraries required at the time of linking are specified. Also, since register allocation is a process performed at the time of compilation, it is not possible to allocate a common address holding register to different external variables at the time of compilation.

【0007】しかしメモリ位置が決定している変数同士
が同じ特定のアドレス範囲に属していれば、異なる変数
であっても特定のメモリ位置をベースとして参照するこ
とができる。ここで、「特定のアドレス範囲に属する」
とは、メモリを参照するためのCPUの命令において、
即値(レジスタを通した間接的な値ではなく、整数値そ
のもの)で表わせるメモリ範囲に収まることを意味す
る。ひとつのモジュール内であれば、C言語の構造体や
Fortran言語のCOMMONの中で宣言されている変数
は宣言の順にメモリ上に連続して並べられることが保証
されているため、構造体やCOMMONの先頭アドレス
をベースとして、そのベースからのオフセット(ベース
からの語数)を用いてそれぞれの要素変数を参照でき
る。この事実を利用したコンパイラの最適化はすでによ
く行われている。
However, if the variables whose memory locations are determined belong to the same specific address range, different variables can be referred to based on the specific memory location. Here, "belongs to a specific address range"
Is an instruction of the CPU for referring to the memory,
This means that the value falls within the memory range that can be represented by an immediate value (not an indirect value through a register, but an integer value itself). Within one module, it is guaranteed that variables declared in a C language structure or a FORTRAN language COMMON are consecutively arranged in memory in the order of declaration. Each element variable can be referred to using an offset from the base (the number of words from the base) based on the start address of the base. Compiler optimizations that take advantage of this fact are already well-known.

【0008】外部変数のメモリ位置がリンク時に決定す
ることを利用して、リンク時に最適化を行なう方法やリ
ンクとコンパイルを一体化した方式が研究されている。
まず従来技術(1)として、A.Srivastava, D.W.W
all "Link-Time Optimization of Address Calcul
ation on a 64-bit Architecture" ACM SIGPL
AN '94がある。これは、オブジェクトモジュールごと
にもつ外部変数管理用テーブルを一体化しロードモジュ
ールにひとつもたせるというOSのコンベンションを利
用して、外部変数の参照を間接参照ではなく直接参照と
すること、つまりメモリ位置管理表に変数のアドレスで
はなく変数の値そのものを書き込んでおくことによって
余分なアドレス計算を省き、実行性能を高めるものであ
る。
[0008] A method of optimizing at the time of linking and a method of integrating linking and compiling utilizing the fact that the memory location of an external variable is determined at the time of linking have been studied.
First, as prior art (1), A.I. Srivastava, D.S. W. W
all "Link-Time Optimization of Address Calcul
ation on a 64-bit Architecture "ACM SIGPL
There is AN '94. This is because, using the OS convention of unifying the external variable management table for each object module and giving one to the load module, direct external variable references instead of indirect references, that is, memory location management tables By writing the value of the variable itself instead of the address of the variable, unnecessary address calculation is omitted and execution performance is improved.

【0009】また従来技術(2)として、V.Santhanam,
D.Odnert "Register Allocation Across Proce
dure and Module Boundaries" ACM SIGPLA
N '90がある。これは、複数の関数をグループ化し、グ
ループ内で共通して参照される外部変数に対してレジス
タを割り当てる。本来は関数が呼び出される毎に外部変
数のアドレスのロードが必要であるところを、グループ
内の関数が最初に呼び出されたときに外部変数のアドレ
スをロードし、それ以降のグループ内関数呼び出しでは
アドレスのロードを省略するというものである。
As the prior art (2), V.I. Santanam,
D. Odnert "Register Allocation Across Proce
dure and Module Boundaries "ACM SIGPLA
There is N'90. This groups a plurality of functions and allocates registers to external variables that are commonly referenced within the group. Where it is necessary to load the address of the external variable every time the function is called, the address of the external variable is loaded when the function in the group is called for the first time. Is omitted.

【0010】この方法は3つのフェーズに分かれてい
て、(1)各ソースファイルを中間コードに変換すると同
時に、外部変数や関数呼び出しなどに関するプログラム
情報を生成するフェーズと、(2)生成されたプログラム
情報を利用しながら外部変数にジスタを割り当て、オブ
ジェクトモジュールを出力するフェーズと、(3)各オブ
ジェクトモジュールとライブラリとから最終的なロード
モジュールを生成するフェーズ、から構成されている。
This method is divided into three phases: (1) a phase in which each source file is converted into intermediate code and, at the same time, program information on external variables and function calls is generated; and (2) a generated program It consists of a phase for allocating a register to an external variable while using information and outputting an object module, and (3) a phase for generating a final load module from each object module and library.

【0011】[0011]

【発明が解決しようとする課題】上記従来技術(1)は外
部変数表の参照を間接参照から直接参照に変えること
で、本来は2命令必要なところを1命令で済まそうとす
るものである。しかしリンク後も外部変数表をオブジェ
クトモジュール毎に持たせることを要求するOSで直接
参照をしようとすると、ひとつの外部変数の値が複数の
表に同時に存在することになり、外部変数の値の更新ご
とにすべての外部変数表の値を書き換えなければなら
ず、逆に性能を低下させるという問題がある。
In the prior art (1), the reference of the external variable table is changed from the indirect reference to the direct reference, so that two instructions can be reduced to one instruction. . However, if the OS that requires the object module to have an external variable table even after linking attempts to directly reference it, the value of one external variable will exist in multiple tables at the same time, and the value of the external variable It is necessary to rewrite all the values of the external variable table for each update, which causes a problem of deteriorating the performance.

【0012】また、従来技術(2)は外部変数のアドレス
のロード命令を削減しようとするものである。しかし外
部変数毎にひとつのレジスタを割り当てなければならな
いため、手続き内で多数の外部変数を使用している場合
はレジスタの数が足りなくなる。するとレジスタの待避
回復コードが多数生成されてしまうため、性能低下を引
き起こす。
The prior art (2) is intended to reduce the number of instructions for loading the address of an external variable. However, since one register must be allocated to each external variable, the number of registers becomes insufficient when a large number of external variables are used in a procedure. As a result, a large number of register recovery codes are generated, resulting in performance degradation.

【0013】上記従来技術の問題点の他に以下のような
問題がある。モジュール間で使用される外部変数の間の
メモリ配置はコンパイル時に決定できないため、外部変
数が最終的にメモリ上で隣接するように配置されたとし
ても、それらを参照するためには変数ごとに一時変数を
用意しなければならない。あらかじめメモリ上に隣接し
ていると分かっていれば、たとえば変数Xのアドレスが
Pだとすると、隣の変数YはアドレスP+1を参照する
ことで変数Yの値を取り出すことができるはずである。
ここで、一時変数は通常はCPUのレジスタに割り当て
られるので、一時変数の数が多くなることは、限られた
数しか持たないCPUのレジスタの多くを使用すること
を要求するということを意味するため、その他のコンパ
イル上重要な最適化のために使用できるレジスタの数を
制限してしまう。レジスタの数が足りなくなると、あふ
れたレジスタに蓄えられていた値を主記憶上に待避する
ためのストア命令と、必要に応じてレジスタの値を回復
するためのロード命令を生成することになる。その結
果、命令数の増加によるロードモジュールの実行速度の
低下を引き起こす。このような待避・回復命令がループ
中で生成されると、大幅な速度低下の原因となる。また
待避・回復命令が増加するとキャッシュミスがおこる可
能性も増加し、CPUのパイプラインの流れを乱す。そ
の結果さらにロードモジュールの実行速度を低下させ
る。
In addition to the above-mentioned problems of the prior art, there are the following problems. Since the memory allocation between external variables used between modules cannot be determined at compile time, even if the external variables are finally arranged adjacently in memory, temporary reference must be made for each variable to refer to them. You have to prepare variables. If it is known in advance that the variable X is adjacent to the memory, for example, if the address of the variable X is P, the value of the variable Y should be able to be extracted by referring to the address P + 1.
Here, since the temporary variables are usually assigned to the registers of the CPU, an increase in the number of temporary variables means that many of the registers of the CPU having a limited number are required to be used. This limits the number of registers that can be used for other compilation important optimizations. When the number of registers is insufficient, a store instruction to save the value stored in the overflowing register to the main memory and a load instruction to restore the register value as necessary are generated. . As a result, the execution speed of the load module decreases due to the increase in the number of instructions. When such a save / restore instruction is generated in a loop, it causes a significant reduction in speed. When the number of save / restore instructions increases, the possibility of a cache miss also increases, which disrupts the flow of the CPU pipeline. As a result, the execution speed of the load module is further reduced.

【0014】[0014]

【課題を解決するための手段】本発明はリンカが行なう
最適化において、リンカへの入力としてモジュール内で
参照される外部変数とロードモジュールを生成するのに
必要なライブラリを与えてコンパイル時には決定できな
いすべての外部変数のアドレスを求める。
SUMMARY OF THE INVENTION In the optimization performed by the linker, the present invention provides external variables referenced in the module as inputs to the linker and libraries necessary for generating a load module, and cannot be determined at compile time. Find the addresses of all external variables.

【0015】この外部変数のアドレスを用いることによ
って、対象CPUによって決まるアドレス範囲に複数の
外部変数が入っていることが分かれば、従来は異なる外
部変数に対しては異なる一時変数を用いる必要があった
ものをひとつの一時変数で参照することができる。
By using the addresses of the external variables, if it is known that a plurality of external variables are included in the address range determined by the target CPU, it is conventionally necessary to use different temporary variables for different external variables. Can be referenced by a single temporary variable.

【0016】そこで外部変数のアドレスから特定のアド
レス範囲に入っている変数のグループを求め、グループ
に属する外部変数の値の参照をひとつの一時変数で行な
うように中間コードを変換する。
Therefore, a group of variables in a specific address range is obtained from the address of the external variable, and the intermediate code is converted so that the value of the external variable belonging to the group is referred to by one temporary variable.

【0017】その結果一時変数に割り当てなければなら
ないCPUレジスタの数を削減することができ、他の最
適化にあまったレジスタを使用することができる。
As a result, the number of CPU registers that must be allocated to temporary variables can be reduced, and other optimized registers can be used.

【0018】[0018]

【発明の実施の形態】以下、本発明の実施の形態を詳細
に説明する。
Embodiments of the present invention will be described below in detail.

【0019】図2は本発明に係わるコンパイラ及びリン
カの構成を示したものである。
FIG. 2 shows a configuration of a compiler and a linker according to the present invention.

【0020】201〜203はロードモジュールを作成するた
めに必要なソースモジュールである。個々のソースモジ
ュールはひとつずつコンパイラ204に入力して、それぞ
れ独立に処理する。コンパイラ204の内部では、たとえ
ばソースモジュール201に対しては、構文解析処理204を
行なう。この処理ではソースモジュールの文法誤りを検
出しながらコンパイラ内部で処理しやすい中間コードを
生成する。続いて最適化処理206を行なうことによって
コンパイラの出力となる中間コード207とモジュール内
外部記号表210を生成する。中間コードはコンパイラが
処理しやすいように変換したものであると同時に、最適
化処理の途中結果としてコンパイラ内部で形を変えなが
ら流れてゆく。モジュール内外部記号表はソースモジュ
ール内で参照する外部記号(変数や関数)に関する情報を
含んでいる。
Reference numerals 201 to 203 denote source modules necessary for creating a load module. Each source module is input to the compiler 204 one by one, and is processed independently. Inside the compiler 204, for example, the syntax analysis processing 204 is performed on the source module 201. In this process, an intermediate code that is easy to process inside the compiler is generated while detecting a syntax error in the source module. Subsequently, an optimization process 206 is performed to generate an intermediate code 207 and an internal module external symbol table 210 which are output from the compiler. The intermediate code is converted so as to be easily processed by the compiler, and at the same time, flows while changing the shape inside the compiler as an intermediate result of the optimization processing. The external symbol table in the module contains information on external symbols (variables and functions) referenced in the source module.

【0021】すべてのソースモジュールから生成された
中間コード207〜209とモジュール内外部記号表210〜212
と、ロードモジュールを生成するのに必要なライブラリ
213〜214をリンカ215に入力する。リンカ215では入力さ
れたモジュール内外部記号表と207〜209とライブラリ21
3〜214とから外部記号表作成処理215によって外部記号
表217を生成する。外部記号表217はロードモジュールを
作成するのに必要な外部変数すべての情報を含んでい
る。この外部記号表217と中間コード207〜209を最適化
処理218によって最適化する。最適化処理にはいくつか
のステップ219〜221があり、その中に本発明に係わるベ
ース変数共通化処理220がある。
Intermediate codes 207 to 209 generated from all source modules and external symbol tables 210 to 212
And the libraries needed to generate the load module
213 to 214 are input to the linker 215. In the linker 215, the input external symbol table in the module, 207 to 209 and the library 21
An external symbol table 217 is generated from 3 to 214 by an external symbol table creation process 215. The external symbol table 217 contains information on all external variables required to create a load module. The external symbol table 217 and the intermediate codes 207 to 209 are optimized by the optimization processing 218. The optimization process includes several steps 219 to 221, among which there is a base variable unification process 220 according to the present invention.

【0022】最適化の結果得られた中間コードをリンク
処理222によって結合し最終的なロードモジュール223を
得る。
The intermediate code obtained as a result of the optimization is combined by a link processing 222 to obtain a final load module 223.

【0023】図3は外部変数を使用するソースモジュー
ルの例を示したものである。
FIG. 3 shows an example of a source module using external variables.

【0024】301ではひとつの要素が4バイトのfloat
(浮動小数)型で、要素数が100個の1次元配列A・B・
Cを外部変数として記憶装置上に領域を確保することを
示している。これらの変数は他のソースモジュールから
も参照することができる。つまりこれらの変数の値を変
更すると、他のモジュールでは変更された値を使用する
ことができるということである。302〜307は関数func1
を宣言する。宣言された関数は他の関数から呼び出すこ
とができ、呼び出されるごとに関数内の処理が行われる
ことになる。303はint(整数)型の変数iを関数func1内で
使用することを宣言する。この変数は関数内でのみ通用
する変数であり、他の関数や他のソースモジュールから
は参照することはできない。304〜306が実行部分であ
る。304〜306はループで、iを0から99まで1ずつ変え
ながらA[i]+B[i]の値を計算し、その値をC[i]に代
入することを示している。
In 301, one element is a float of 4 bytes.
(Floating point) type, one-dimensional array AB with 100 elements
This indicates that an area is secured on the storage device using C as an external variable. These variables can be referenced from other source modules. This means that if you change the values of these variables, other modules can use the changed values. 302 to 307 are functions func1
Declare The declared function can be called from other functions, and the processing in the function is performed each time it is called. 303 declares that an int (integer) type variable i is used in the function func1. This variable is valid only within a function and cannot be referenced from other functions or other source modules. 304 to 306 are execution parts. Reference numerals 304 to 306 denote loops in which the value of A [i] + B [i] is calculated while changing i by 1 from 0 to 99, and the value is substituted for C [i].

【0025】301で宣言された外部変数A・B・Cは記
憶装置上に連続して領域を割り当てられるとは限らず、
また宣言の順に並んでいるとも限らない。この並び方は
リンカが決定する。
The external variables A, B, and C declared in 301 are not always allocated continuously on the storage device.
They are not necessarily arranged in the order of declaration. This arrangement is determined by the linker.

【0026】図4は本発明に係わるコンパイラの構成を
示す。
FIG. 4 shows a configuration of a compiler according to the present invention.

【0027】コンパイラ204は記憶装置401からソースモ
ジュール201を読み込み、それをステップ205において構
文解析処理を行い、コンパイラが処理しやすい中間コー
ド402に変換するとともに、以下のステップで行われる
最適化に必要な情報(たとえば変数間の依存関係)を生
成する。この構文解析処理の詳細については、たとえば
「エイホ・セシィ・ウルマン著:コンパイラ1(サイエン
ス社 1990年)第30〜74ページ」に記載されているので説
明は省略する。
The compiler 204 reads the source module 201 from the storage device 401, performs a syntax analysis process in step 205, converts the source module 201 into an intermediate code 402 that can be easily processed by the compiler, and is necessary for the optimization performed in the following steps. Information (for example, dependencies between variables). The details of this syntax analysis processing are described in, for example, "Eiho Cessie Ullman: Compiler 1 (Science Inc., 1990), pp. 30-74", and a description thereof will be omitted.

【0028】次にステップ206において上記中間コード4
02を読み込み最適化処理を行ない、改良された中間コー
ド207とモジュール内外部記号表210を出力する。このス
テップ206で行われる最適化はCPUのレジスタ数には
依存しない最適化を行なう。たとえばループ変換や部分
式削除のような最適化である。このような最適化につい
ては、たとえば「Michael Wolfe著:High Performan
ce Compilers ForParallel Computing(Addison-W
esley 1996)第307〜366ページ」に記載されているので
説明は省略する。
Next, at step 206, the intermediate code 4
02 and performs optimization processing, and outputs an improved intermediate code 207 and an external symbol table 210 inside the module. The optimization performed in step 206 performs optimization independent of the number of CPU registers. For example, optimization such as loop transformation and subexpression elimination. Such optimization is described, for example, in “Michael Wolfe: High Performan
ce Compilers ForParallel Computing (Addison-W
esley 1996) pp. 307-366 ", and a description thereof will be omitted.

【0029】モジュール内外部記号表210については図
7で説明する。
The module internal symbol table 210 will be described with reference to FIG.

【0030】図5は図3のプログラムを従来のコンパイ
ラでコンパイルしたときの中間コードの例を示したもの
である。中間コードは最初に構文解析処理によって作成
され、以後各最適化処理を適用するごとに形を変えてゆ
く。
FIG. 5 shows an example of an intermediate code when the program of FIG. 3 is compiled by a conventional compiler. The intermediate code is first created by a parsing process, and changes in shape each time each optimization process is applied.

【0031】図5の中間コードは基本ブロックを辺で結
んだグラフで表現されている。
The intermediate code shown in FIG. 5 is represented by a graph in which basic blocks are connected by edges.

【0032】501〜505は基本ブロックである。基本ブロ
ックは途中で分岐や飛び込みのない一連のコード列を表
わしていて、構文解析処理205によって構成される。辺
は基本ブロックの制御の流れを表わしていて、たとえば
基本ブロック504の処理が終わると次に基本ブロック503
に処理が移ることを意味している。504から503への処理
の移動により、503と504でループを形成していることが
分かる。
Reference numerals 501 to 505 are basic blocks. The basic block represents a series of code strings without branching or jumping in the middle, and is constituted by the syntax analysis processing 205. The side indicates the control flow of the basic block. For example, when the processing of the basic block 504 is completed,
Means that the process moves to By moving the process from 504 to 503, it can be seen that a loop is formed by 503 and 504.

【0033】図6に基本ブロック502の内容を詳細に示
す。
FIG. 6 shows the contents of the basic block 502 in detail.

【0034】基本ブロック502は4個の文からなり、各
文は文番号601・文の処理内容602・文が代入文のときに
代入文の左辺の変数名603と左辺の変数が使用される文
番号のリスト604からなっている。文番号601はひとつの
中間コード全体で一意につけられた番号である。また処
理内容602は3番地記法で書かれている。3番地記法に
ついてはたとえば「エイホ・セシィ・ウルマン著:コン
パイラ2(サイエンス社 1990年)第567〜568ページ」に
記されているので説明は省略する。
The basic block 502 is composed of four sentences. Each sentence uses a statement number 601, a sentence processing content 602, and a variable name 603 on the left side of the assignment statement and a variable on the left side when the sentence is an assignment statement. It consists of a sentence number list 604. The statement number 601 is a number uniquely assigned to one entire intermediate code. The processing content 602 is written in the address number 3 notation. The third address notation is described in, for example, "Eiho Cessie Ulman: Compiler 2 (Science Inc., 1990), pp. 567-568", and the description is omitted.

【0035】たとえば605〜608は基本ブロック502の内
容を示したものである。文605では一時変数t1に0を代
入することを意味している。ここで演算子「:=」は右
辺を計算した値を左辺の変数に代入することを表わす。
文606では変数Aのアドレスを変数t2に代入することを意
味している。演算子「&」は演算子のオペランドに現れ
る変数の記憶装置上のアドレスを求めることを表わす。
同様に文607では変数Bのアドレスを変数t3に代入し、文
608では変数Cのアドレスを変数t4に代入する。
For example, reference numerals 605 to 608 show the contents of the basic block 502. The statement 605 means that 0 is substituted for the temporary variable t1. Here, the operator “: =” indicates that the value calculated on the right side is substituted for the variable on the left side.
The statement 606 means that the address of the variable A is substituted for the variable t2. The operator "&" indicates that the address on the storage device of the variable appearing in the operand of the operator is obtained.
Similarly, in statement 607, the address of variable B is assigned to variable t3,
At 608, the address of the variable C is substituted for the variable t4.

【0036】また、基本ブロック504で現れる演算子
「*」はオペランドに現れる式を記憶装置上のアドレス
として、そのアドレスに含まれている値を取り出すもの
である。この「&」と「*」の演算子は図1のコード部
102の命令109aと110a(あるいは109bと110b)にそれぞれ
対応し、外部変数の値を求めるためには必ずこれらの演
算子が中間コード中に現れる。つまり演算子「*」を適
用する式の中に整数定数が含まれていると生成された命
令の即値部分にその定数が現れることになる。逆に命令
の即値部分に整数定数を指定するためには中間コードの
「*」演算子の式中に整数定数を置けばよい。
The operator "*" appearing in the basic block 504 is for taking the expression contained in the operand as an address on the storage device and extracting the value contained in the address. These "&" and "*" operators are the code part in Fig. 1.
These operators correspond to the 102 instructions 109a and 110a (or 109b and 110b), respectively, and these operators always appear in the intermediate code in order to determine the value of the external variable. That is, if an integer constant is included in the expression to which the operator “*” is applied, the constant will appear in the immediate portion of the generated instruction. Conversely, to specify an integer constant in the immediate part of the instruction, the integer constant may be placed in the expression of the "*" operator in the intermediate code.

【0037】図7はモジュール内外部記号表の例であ
る。
FIG. 7 is an example of an external symbol table in the module.

【0038】モジュール内外部記号表はコンパイラが管
理しているモジュール内の変数や関数などの情報からス
テップ206で作成される。
The external symbol table in the module is created in step 206 from information such as variables and functions in the module managed by the compiler.

【0039】モジュール内外部記号表は記号名701・記
号が変数か関数かを示す種類702・記号がモジュール内
で定義されているのか他のモジュール内で定義されてい
てそれを使用しているのかを示す参照形式703・変数が
記憶装置内で占める領域のサイズ704からなっている。
In the external symbol table in the module, the symbol name 701, the type 702 indicating whether the symbol is a variable or a function, and whether the symbol is defined in the module or used in another module is used. The reference format 703 indicates the size 704 of the area occupied by the variable in the storage device.

【0040】図8は本発明に係わるリンカの構成を示
す。
FIG. 8 shows the structure of the linker according to the present invention.

【0041】リンカ215は記憶装置401から上記コンパイ
ラで生成されたモジュール内外部記号表210〜212と必要
なライブラリ213〜214を読み込み、最終的にひとつのロ
ードモジュール222を出力する。外部記号表作成処理(ス
テップ216)においてはモジュール内外部記号表210〜212
と必要なライブラリ213〜214を読み込み、外部記号表21
7を作成する。外部記号表には外部記号名と外部記号間
の記憶装置上の位置を表わすアドレスが示されている。
この外部記号表の内容については図9で説明する。また
外部記号表の作成処理については、たとえば「村岡洋一
著:コンピュータ・アーキテクチャ(近代科学社 1985
年)第66ページ〜73ページ」に記載されているので、説
明は省略する。
The linker 215 reads from the storage device 401 the external symbol tables 210 to 212 generated by the compiler and necessary libraries 213 to 214, and finally outputs one load module 222. In the external symbol table creation processing (step 216), the module internal symbol tables 210 to 212
And necessary libraries 213 to 214 are read and the external symbol table 21
Create 7. The external symbol table shows external symbol names and addresses representing positions on the storage device between the external symbols.
The contents of the external symbol table will be described with reference to FIG. Regarding the process of creating the external symbol table, see, for example, “Youichi Muraoka: Computer Architecture (Kindai Kagakusha 1985
Year) pages 66-73 ", and the description is omitted.

【0042】次に最適化処理217で中間コード207〜209
とライブラリ213〜214を読み込み各種最適化218〜220を
行なう。ここで行なう最適化はCPUのレジスタ割り付
けに関係するものである。この最適化処理217の中で本
発明に係わるベースレジスタ共通化処理219を行なう。
ベースレジスタ共通化はCPUレジスタ割り当ての前に
行う最適化処理で、外部変数間の位置関係をもとに、複
数の一時変数をひとつのレジスタで参照できるように中
間コードを変換するものである。このベースレジスタ共
通化の流れについては図10〜図14で詳しく説明す
る。
Next, in the optimization processing 217, the intermediate codes 207 to 209
And the libraries 213 to 214 are read and various optimizations 218 to 220 are performed. The optimization performed here relates to the register allocation of the CPU. In the optimization processing 217, the base register sharing processing 219 according to the present invention is performed.
The base register commonization is an optimization process performed before CPU register allocation, in which intermediate codes are converted based on the positional relationship between external variables so that a plurality of temporary variables can be referred to by one register. The flow of the base register sharing will be described in detail with reference to FIGS.

【0043】その後、最終的な中間コード801〜803とラ
イブラリ213〜214と外部記号表217とからリンク処理221
によって最終的なロードモジュール222を生成する。コ
ード生成については、たとえば「エイホ・セシィ・ウル
マン著:コンパイラ2(サイエンス社 1990年)第624〜7
07ページ」に記載されているので、説明は省略する。
Thereafter, link processing 221 is performed based on the final intermediate codes 801 to 803, libraries 213 to 214, and external symbol table 217.
Generates the final load module 222. For code generation, see, for example, "Aho Sesi Ullman: Compiler 2 (Science Inc. 1990) No. 624-7.
Page 07 ", so the description is omitted.

【0044】図9外部記号表217の内容を示したもので
ある。
FIG. 9 shows the contents of the external symbol table 217.

【0045】外部記号表は外部記号名901・外部記号が
変数か関数かを表す種別902・記号が記憶装置内で占め
る領域の大きさを表すサイズ903・記号が記憶装置のど
の位置に格納されるかを表す位置(アドレス)904からな
る。
The external symbol table stores an external symbol name 901, a type 902 indicating whether the external symbol is a variable or a function, a size 903 indicating the size of the area occupied by the symbol in the storage device, and a location in the storage device where the symbol is stored. It consists of a position (address) 904 that indicates whether the

【0046】図10は本発明に係わるベース変数共通化
の流れをフローチャートで示したものである。
FIG. 10 is a flowchart showing the flow of the common use of the base variables according to the present invention.

【0047】ベース変数共通化は中間コードに含まれる
基本ブロックごとに行なう。まずステップ1001で中間コ
ードをひとつとり、その中の基本ブロックをひとつ取る
(ステップ1002)。取り出した基本ブロックに外部変数
のアドレスの参照があるかどうかを検査し(ステップ100
3)、含まれていればその外部変数に対するベース変数を
求め(ステップ1004)、外部変数の値を使用する文を適切
に書き換える。
The base variables are shared for each basic block included in the intermediate code. First, in step 1001, one intermediate code is taken, and one basic block is taken (step 1002). Check whether the address of the external variable is referenced in the fetched basic block (step 100
3) If it is included, the base variable for the external variable is obtained (step 1004), and the sentence using the value of the external variable is appropriately rewritten.

【0048】ベース変数共通化ができた場合、もともと
ある文のうちのいくつかは無用コードとなる。無用コー
ドとは、プログラム中でまったく使用されない値を計算
する文のことである。異なる変数それぞれの値を参照す
るためには異なる一時変数を必要とするが(たとえば図
5の基本ブロッ502など)、ベース変数共通化によりひと
つの一時変数で足りてしまうからである。したがって無
用コードを削除することによってベース変数共通化の効
果をあげることができる。無用コード削除についてはた
とえば「エイホ・セシィ・ウルマン著:コンパイラ2
(サイエンス社 1990年)第725〜726ページ」に記載され
ているので、説明は省略する。
If the base variables can be standardized, some of the original statements become useless codes. Useless code is a statement that calculates a value that is never used in the program. Although different temporary variables are required to refer to the values of different variables (for example, the basic block 502 in FIG. 5), one temporary variable is sufficient due to the common base variable. Therefore, the effect of unifying the base variables can be improved by deleting the unnecessary code. Regarding the useless code deletion, for example, refer to “Aho Sesi Ullman: Compiler 2
(Science Inc., 1990), pp. 725-726 ", and a description thereof will be omitted.

【0049】基本ブロックに外部変数のアドレスの参照
が無い場合、あるいは外部変数の値を使用する文の更新
が終わったとき、次の基本ブロックがあるかどうかを検
査し(ステップ1007)、あればステップ1002にもどり、な
ければ次の中間コードがあるかどうかを検査する(ステ
ップ1008)。さらに中間コードがあればステップ1001に
もどり、なければベース変数共通化を終了する。
When there is no reference to the address of the external variable in the basic block, or when the update of the statement using the value of the external variable is completed, it is checked whether or not the next basic block exists (step 1007). Returning to step 1002, if there is no next intermediate code, it is checked (step 1008). If there is an intermediate code, the process returns to step 1001; otherwise, the base variable sharing is terminated.

【0050】図11は各基本ブロックに対するベース変
数表を示したものである。
FIG. 11 shows a base variable table for each basic block.

【0051】ベース変数表は図12(ステップ1004を詳
しく説明したもの)で説明する処理によって作られる。
The base variable table is created by the process described with reference to FIG. 12 (which describes step 1004 in detail).

【0052】ベース変数表はベース変数となる外部変数
1101・ベース変数の記憶装置上の位置1102・ベース変数
で表わせる範囲にある外部変数のリスト1103からなって
いる。
A base variable table is an external variable serving as a base variable.
1101 is a position 1102 of the base variable in the storage device. 1103 is a list of external variables in a range that can be represented by the base variable.

【0053】図12は図10のステップ1004のベース変
数を求める処理をフローチャートで示したものである。
FIG. 12 is a flowchart showing the process of obtaining the base variable in step 1004 of FIG.

【0054】まず外部変数を外部記号表からひとつとる
(ステップ1201)。取り出した外部変数名をXとすると外
部記号表217の記号名901の列から外部変数名Xに等しい
行を見つけ、その行の位置の欄904を参照すると外部変
数Xの位置がLXとわかったとする。もしXがすでにベ
ース変数表にベース変数として登録してある(図11の
ベース変数表の変数名1101の列に外部変数Xが登録され
ている)か、ベース変数で参照できる変数として登録し
てある(図11のベース変数表のメンバ1103の列に外部
変数Xが登録されている)ならば(ステップ1202)次の外
部変数を探す(ステップ1207)。
First, take one external variable from the external symbol table
(Step 1201). Assuming that the extracted external variable name is X, a row equal to the external variable name X is found from the column of the symbol name 901 in the external symbol table 217, and when the column 904 of the row position is found, the position of the external variable X is found to be LX. I do. If X is already registered as a base variable in the base variable table (external variable X is registered in the column of variable name 1101 in the base variable table in FIG. 11) or registered as a variable that can be referred to by the base variable If there is any (external variable X is registered in the column of member 1103 of the base variable table in FIG. 11) (step 1202), the next external variable is searched (step 1207).

【0055】まだXがベース変数表に登録されていなけ
れば次にXがベース変数になりうるかどうかを検査す
る。ステップ1203でベース変数表からひとつベース変数
を取り出す。取り出した変数をY・位置をLYとする。
If X has not been registered in the base variable table, it is checked whether X can be a base variable. In step 1203, one base variable is extracted from the base variable table. Let Y and the position of the extracted variable be LY.

【0056】最終的に作成するロードモジュールの対象
CPUによって、命令の即値で表わせる記憶装置上の領
域の大きさは決まっている。この大きさをdispとする。
dispで表わせる範囲に複数の外部変数が入っている場
合、それらの外部変数はその領域内のある点ベースにし
てすべて参照することができる。本実施の形態では同じ
ベース変数で表わせる外部変数群のうち、基本ブロック
内で最初に現れる外部変数をベース変数として登録する
ことにする。つまりすでに登録済みのベース変数Yの位
置LYと現在処理中の外部変数Yの位置LYの差がdisp
よりも小さければ、変数Yは変数Xを用いて表わすこと
ができる。この検査を行なうのがステップ1204である。
The size of the area on the storage device that can be represented by the immediate value of the instruction is determined by the target CPU of the load module to be finally created. This size is defined as disp.
If there are multiple external variables in the range that can be represented by disp, those external variables can all be referenced based on a certain point in the area. In the present embodiment, among the external variable groups that can be represented by the same base variable, the external variable that appears first in the basic block is registered as the base variable. That is, the difference between the registered position LY of the base variable Y and the position LY of the external variable Y currently being processed is disp.
If less, the variable Y can be represented using the variable X. This inspection is performed in step 1204.

【0057】ステップ1204の条件を満たせば、XをYの
メンバ変数としてベース変数表に登録する(ステップ120
5)。
If the condition of step 1204 is satisfied, X is registered in the base variable table as a member variable of Y (step 120).
Five).

【0058】ステップ1204の条件を満たさなければ、X
をあらたなベース変数としてベース変数表に登録する
(ステップ1206)。
If the condition of step 1204 is not satisfied, X
Is registered in the base variable table as a new base variable
(Step 1206).

【0059】以上の処理が終わったら次の外部変数が基
本ブロック内にあるかどうかを検査して(ステップ120
7)、あればステップ1201にもどって以上の処理を繰り返
す。なければベース変数の登録処理は終了である。
When the above processing is completed, it is checked whether or not the next external variable is in the basic block (step 120).
7) If there is, return to step 1201 and repeat the above processing. If not, the base variable registration process ends.

【0060】図13はベース変数を用いて外部変数の値
を使用するように更新する処理の流れを示したものであ
る。
FIG. 13 shows a flow of a process of updating the values of the external variables using the values of the base variables.

【0061】初期状態1301は、外部変数Bが配列のとき
に、配列の要素B[i]の値を一時変数t4に求める典型的
な中間コードの例である。文1301aでBのアドレスを一
時変数t1に代入し、文1301bで一時変数t3に格納されて
いる添字値をBのアドレスに加え、文1301cでB[i]の値
を一時変数t4に代入する。
The initial state 1301 is an example of a typical intermediate code for obtaining the value of the element B [i] of the array as the temporary variable t4 when the external variable B is an array. In statement 1301a, the address of B is assigned to the temporary variable t1, in statement 1301b, the subscript value stored in the temporary variable t3 is added to the address of B, and in statement 1301c, the value of B [i] is assigned to the temporary variable t4. .

【0062】この外部変数Bがベース変数Aで表わすこ
とができる場合、つまりベース変数表にAのメンバとし
てBが登録されている場合は、BをAの参照に代えるこ
とができる。ここでBの位置とAの位置の差を400であ
るとすると、ベース変数化によって1302のように変換で
きる。つまり文1302aの「&」演算子の対象の式をBか
らAに変え、さらに400を加えればよい。
When the external variable B can be represented by the base variable A, that is, when B is registered as a member of A in the base variable table, B can be replaced with reference to A. Here, assuming that the difference between the position of B and the position of A is 400, it can be converted into 1302 by base variable conversion. That is, the expression targeted for the “&” operator in the statement 1302a is changed from B to A, and 400 is added.

【0063】この文1302aに対してCPUの命令を生成
すると加算とTOCからのロードの2命令が必要となる
が、「400」という値を配列の値を参照する文1302cまで
伝搬することができれば、1302cに対するCPU命令で
「400」を吸収することができる。
When CPU instructions are generated for this statement 1302a, two instructions of addition and loading from the TOC are required. If the value "400" can be propagated to the statement 1302c referring to the array value, , 1302c can absorb “400” by the CPU instruction.

【0064】整数定数の伝搬は、アドレスの加算のオペ
ランドを伝搬するものなので、伝搬する途中に文1302b
のような加算があってもそのまま通り抜けることができ
る。つまり1302cの「*」演算子に対する式はt2 = (A+4
00) + t3 = A + 400 + t3 =(A + t3) + 400であるか
ら、t1 = &Aとすれば文1302bには何も変更を加える必要
はなく、文1302aと文1302cだけを更新すればよいことに
なる。
Since the propagation of the integer constant propagates the operand of the address addition, the statement 1302b
Even if there is such an addition, it can pass through as it is. In other words, the expression for the “*” operator in 1302c is t2 = (A + 4
00) + t3 = A + 400 + t3 = (A + t3) + 400, so if t1 = & A, there is no need to change statement 1302b, only statement 1302a and statement 1302c need to be updated. It will be good.

【0065】伝搬できた結果を1303に示す。文1303cで
は演算子「*」に対する式の中に定数「400」が現れて
いる。
The result of the propagation is shown in 1303. In the sentence 1303c, the constant "400" appears in the expression for the operator "*".

【0066】図14は図10のステップ1005のベース変
数を用いて外部変数の値を使用する文の更新の処理をフ
ローチャートで示したものである。
FIG. 14 is a flowchart showing a process of updating a statement using the value of an external variable using the base variable in step 1005 of FIG.

【0067】外部変数の値を使用する文の更新とは、ベ
ース変数共通化によって演算子「&」の中に現れる整数
定数を、変数の使用時に用いる演算子「*」の中に伝搬
することである。
Updating a statement using the value of an external variable is to propagate an integer constant appearing in the operator "&" due to the unification of the base variable into the operator "*" used when using the variable. It is.

【0068】まず基本ブロック内の文を走査して外部変
数のアドレスを使用している文をみつける(ステップ140
1)。この外部変数をYとすると外部記号表から位置がL
Yとわかる。
First, the statement in the basic block is scanned to find the statement using the address of the external variable (step 140).
1). If this external variable is Y, the position is L from the external symbol table.
I understand Y.

【0069】次にこの外部変数Yに対するベース変数を
ベース変数表からみつける(ステップ1402)。この外部変
数をX・位置をLXとする。
Next, a base variable for this external variable Y is found in a base variable table (step 1402). This external variable is X. The position is LX.

【0070】もしXとYが等しければベース変数共通化
を行なう必要はないので、ステップ1403でそれを検査
し、XとYが等しければステップ1410で次の外部変数が
あるかどうかを確かめる。
If X and Y are equal, there is no need to perform base variable consolidation, so that it is checked in step 1403, and if X and Y are equal, in step 1410 it is checked whether or not the next external variable exists.

【0071】XとYが等しくなければ中間コードを走査
して変数Yの値を使用する部分をベース変数Xによる使
用に更新する処理を行なう。
If X and Y are not equal, a process of scanning the intermediate code and updating the portion using the value of the variable Y to use the base variable X is performed.

【0072】まず変数Xの使用先の文を外部記号表から
ひとつ求める(ステップ1404)。ここで使用先の文の種類
によって処理が分かれる。
First, one sentence in which the variable X is used is obtained from the external symbol table (step 1404). Here, processing depends on the type of sentence used.

【0073】(1) 加減算の場合 この場合はそのまま通り抜けることができる。つまり加
減算の左辺の変数の使用先をたどればよい(ステップ120
6)。
(1) Addition and Subtraction In this case, it is possible to pass through as it is. In other words, it is sufficient to follow the usage of the variable on the left side of addition and subtraction (step 120
6).

【0074】(2) 変数の値の使用の場合(「*」演算の
場合) この場合はすでに「*」演算の中に現れている即値部分
とLY−LXを足した結果がCPUの命令で指定できる
即値の大きさの範囲に入っていれば、即値部分を即値+
(LY−LX)で置き換える(ステップ1209)。範囲を越
えていれば、外部変数Yに対するベース変数共通化をあ
きらめて、次の外部変数を探しにゆく(ステップ1411)。
(2) In the case of using the value of a variable (in the case of "*" operation) In this case, the result of adding the immediate part already appearing in the "*" operation and LY-LX is the instruction of the CPU. If the value is within the range of the immediate value that can be specified,
(LY-LX) (step 1209). If it exceeds the range, the base variable sharing for the external variable Y is abandoned, and the next external variable is searched for (step 1411).

【0075】(3) その他の場合 整数定数の伝搬ができないものとして、外部変数Yに対
するベース変数共通化をあきらめて、次の外部変数を探
しにゆく(ステップ1411)。
(3) In Other Cases Since it is impossible to propagate an integer constant, the base variable sharing for the external variable Y is abandoned, and the next external variable is searched for (step 1411).

【0076】以上の処理を行なった後、次の使用先の文
があれば(ステップ1409)、ステップ1404にもどって処理
を繰り返す。なければ次の外部変数をみつけて(ステッ
プ1410)ステップ1401から繰り返す。
After performing the above processing, if there is a next sentence to be used (step 1409), the process returns to step 1404 to repeat the processing. If not, find the next external variable (step 1410) and repeat from step 1401.

【0077】図15は本発明に係わるベース変数共通化
の効果を表わすために、図5の中間コードにベース変数
共通化処理220の中のロード命令更新処理1005を適用し
た直後の中間コードを示したものである。
FIG. 15 shows an intermediate code immediately after applying the load instruction update processing 1005 in the base variable common processing 220 to the intermediate code of FIG. 5 in order to show the effect of the base variable commonization according to the present invention. It is a thing.

【0078】基本ブロック1501は基本ブロック502に対
応する。502では3つの外部変数A・B・Cに対するア
ドレス保持用変数を使用しているが、1501では外部変数
Aのみに対するアドレス保持用変数になっている。基本
ブロック1502は基本ブロック504に対応する。504では上
記の3つのアドレス保持用変数を用いて配列要素を参照
していた。それに対して1502では1つのアドレス保持用
変数のみを使用するように変わっている。
The basic block 1501 corresponds to the basic block 502. In 502, address holding variables for three external variables A, B, and C are used. In 1501, address holding variables for only the external variable A are used. Basic block 1502 corresponds to basic block 504. In 504, an array element is referred to using the three address holding variables. In contrast, in 1502, only one address holding variable is used.

【0079】図16は本発明に係わるベース変数共通化
の効果を表わすために、図5の中間コードにベース変数
共通化処理220の中の無用コード削除処理1006を適用し
たときの中間コードを示したものである。
FIG. 16 shows an intermediate code when the useless code deletion processing 1006 in the base variable common processing 220 is applied to the intermediate code of FIG. 5 in order to show the effect of base variable commonization according to the present invention. It is a thing.

【0080】基本ブロック1502中の変数t3とt4はループ
中で参照されることがないので削除してもプログラムの
実行には影響を及ぼさない。1502中のt3とt4の文の削除
の結果、1502は1602のように変化する。さらに基本ブロ
ック1501中の変数t3とt4も参照されることがなくなり、
これらも削除することができる。1501のt3とt4の削除の
結果、1501は1601のように変化する。
Since the variables t3 and t4 in the basic block 1502 are not referred to in the loop, deleting them does not affect the execution of the program. As a result of deleting the statements of t3 and t4 in 1502, 1502 changes like 1602. Furthermore, the variables t3 and t4 in the basic block 1501 are no longer referred to,
These can also be deleted. As a result of deleting t3 and t4 of 1501, 1501 changes like 1601.

【0081】この結果、図5の中間コードからみて4つ
の代入文と2つの変数を削除できたことになる。図5の
中間コードに対して実行される文の数は4+1+8×100=805
個なのに対して、図16の中間コードに対して実行され
る文の数は2+1+6×100=602個となる。つまり約25%(1-60
2/805)の文を削除できたことになる。また変数t3とt4の
2つを削除できている。ひとつの変数はレジスタ割り付
け処理によってひとつのCPUレジスタが割り当てられ
ることになるので、レジスタ数も2個削減できたことに
なる。
As a result, four assignment statements and two variables have been deleted from the intermediate code shown in FIG. The number of statements executed for the intermediate code in FIG. 5 is 4 + 1 + 8 × 100 = 805
However, the number of statements executed for the intermediate code in FIG. 16 is 2 + 1 + 6 × 100 = 602. That is, about 25% (1-60
2/805) has been deleted. Also, two variables t3 and t4 have been deleted. Since one CPU register is assigned to one variable by the register assignment process, the number of registers can be reduced by two.

【0082】[0082]

【発明の効果】異なる外部変数の参照に伴うロード・ス
トア命令の数を削減し実行命令数を削減し実行速度の向
上が得られる。また外部変数に割り当てるCPUのレジ
スタ数の削減により、他最適化の負担を軽減するととも
に最適化の機会を増加させ、実行速度が向上する。
According to the present invention, the number of load / store instructions involved in referring to different external variables is reduced, the number of executed instructions is reduced, and the execution speed is improved. Also, by reducing the number of registers of the CPU to be allocated to the external variables, the burden of other optimizations is reduced, the opportunities for optimization are increased, and the execution speed is improved.

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

【図1】外部変数の間接参照の仕方を示す。FIG. 1 shows a method of indirectly referencing an external variable.

【図2】本発明に係わるコンパイラとリンカの構成を示
したものである。
FIG. 2 shows a configuration of a compiler and a linker according to the present invention.

【図3】外部変数を使用するソースモジュールの例を示
したものである。
FIG. 3 shows an example of a source module using an external variable.

【図4】本発明にかかわるコンパイラの構成を示したも
のである。
FIG. 4 shows a configuration of a compiler according to the present invention.

【図5】中間コードの例を示したものである。FIG. 5 shows an example of an intermediate code.

【図6】基本ブロックの内容を示したものである。。FIG. 6 shows the contents of a basic block. .

【図7】モジュール内外部記号表を示したものである。FIG. 7 shows an external symbol table in the module.

【図8】本発明に係わるリンカの構成を示したものであ
る。
FIG. 8 shows a configuration of a linker according to the present invention.

【図9】外部記号表を示したものである。FIG. 9 shows an external symbol table.

【図10】本発明に係わるベース変数共通化の処理の流
れを示したフローチャートである。
FIG. 10 is a flowchart showing a flow of a process of unifying base variables according to the present invention.

【図11】ベース変数共通化で用いるベース変数表を示
したものである。
FIG. 11 shows a base variable table used in base variable unification.

【図12】ベース変数の登録処理を示したフローチャー
トである。
FIG. 12 is a flowchart showing a base variable registration process.

【図13】ベース変数共通化による中間コードの変化を
示したものである。
FIG. 13 shows a change in intermediate code due to sharing of base variables.

【図14】ベース変数共通化による変数使用点の更新処
理を示したフローチャートである。
FIG. 14 is a flowchart showing a variable use point updating process by base variable commonality.

【図15】ロード命令更新処理直後の中間コードの例を
示したものである。
FIG. 15 illustrates an example of an intermediate code immediately after a load instruction update process.

【図16】無用コード削除処理の直後の中間コードの例
を示したものである。
FIG. 16 shows an example of an intermediate code immediately after useless code deletion processing.

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

201…ソースモジュール、204…コンパイラ、20
5…構文解析ステップ、206…コンパイラによる最適
化ステップ、207…中間コード、 210…モジ
ュール内外部記号表、213…ライブラリ、215…リ
ンカ、 216…外部記号表作成ステップ、217…外
部記号表、220…ベース変数共通化ステップ、222
…リンクステップ、 223…ロードモジュール、10
04…ベース変数を求めるステップ、1005…ロード
命令を更新するステップ、1006…無用コードを削除
するステップ。
201: source module, 204: compiler, 20
5 ... Syntax analysis step, 206 ... Compiler optimization step, 207 ... Intermediate code, 210 ... Module internal symbol table, 213 ... Library, 215 ... Linker, 216 ... External symbol table creation step, 217 ... External symbol table, 220 ... Base variable commonization step, 222
... Link step, 223 ... Load module, 10
04: a step of obtaining a base variable; 1005: a step of updating a load instruction; 1006: a step of deleting unnecessary code.

Claims (3)

【特許請求の範囲】[Claims] 【請求項1】リンカによるロードモジュール生成の際
に、 コンパイラの生成したモジュール内外部記号表とライブ
ラリを読み込むステップと、 コンパイラの生成した中間コードを読み込むステップ
と、 中間コードを走査して最適化を行なうステップと、 中間コードとライブラリとからロードモジュールを生成
するステップとを有し、上記中間コード最適化を行なう
ステップでは外部変数を参照するためのレジスタ数を削
減することを特徴とする、リンク最適化方法。
When a load module is generated by a linker, a step of reading an external symbol table and a library in a module generated by a compiler, a step of reading an intermediate code generated by a compiler, and scanning the intermediate code to perform optimization. Link optimization, comprising the steps of: generating a load module from an intermediate code and a library; and reducing the number of registers for referencing external variables in the step of performing the intermediate code optimization. Method.
【請求項2】請求項1のリンク最適化方法であって、上
記中間コードを最適化するステップでは、使用レジスタ
数を削減するために、 ベースレジスタを共通化することを特徴とする、リンク
最適化方法。
2. The link optimization method according to claim 1, wherein in the step of optimizing the intermediate code, a base register is shared in order to reduce the number of registers used. Method.
【請求項3】コンパイラによる中間コード生成の際に、 ソースファイルを入力するステップと、 ソースファイルを構文解析し中間コードを生成するステ
ップと、 中間コードを走査して外部変数情報を生成するステップ
と、 中間コードを最適化して中間コードを生成するステップ
とを有し、 リンカに外部変数情報に基づく最適化を行なわせるため
に外部変数情報を生成することを特徴とする、リンク最
適化方法。
3. A step of inputting a source file when generating an intermediate code by a compiler, a step of parsing the source file to generate an intermediate code, and a step of scanning the intermediate code to generate external variable information. Generating an intermediate code by optimizing the intermediate code, wherein the external variable information is generated to cause the linker to perform optimization based on the external variable information.
JP7958997A 1997-03-31 1997-03-31 Link optimizing method Pending JPH10275088A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP7958997A JPH10275088A (en) 1997-03-31 1997-03-31 Link optimizing method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP7958997A JPH10275088A (en) 1997-03-31 1997-03-31 Link optimizing method

Publications (1)

Publication Number Publication Date
JPH10275088A true JPH10275088A (en) 1998-10-13

Family

ID=13694193

Family Applications (1)

Application Number Title Priority Date Filing Date
JP7958997A Pending JPH10275088A (en) 1997-03-31 1997-03-31 Link optimizing method

Country Status (1)

Country Link
JP (1) JPH10275088A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2014531680A (en) * 2011-10-03 2014-11-27 インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation Compile code for enhanced application binary interface (ABI) using decode time instruction optimization
JP2014533394A (en) * 2011-10-03 2014-12-11 インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation Code linking for enhanced application binary interface (ABI) using decode time instruction optimization
US8959502B2 (en) 2011-07-27 2015-02-17 International Business Machines Corporation Processing table of content access overflow in an application
CN109918074A (en) * 2017-12-08 2019-06-21 中标软件有限公司 Compiling link optimization method
US10489131B2 (en) 2017-01-25 2019-11-26 Fujitsu Limited Efficient compilation for link time optimization

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8959502B2 (en) 2011-07-27 2015-02-17 International Business Machines Corporation Processing table of content access overflow in an application
JP2014531680A (en) * 2011-10-03 2014-11-27 インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation Compile code for enhanced application binary interface (ABI) using decode time instruction optimization
JP2014533394A (en) * 2011-10-03 2014-12-11 インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation Code linking for enhanced application binary interface (ABI) using decode time instruction optimization
US10489131B2 (en) 2017-01-25 2019-11-26 Fujitsu Limited Efficient compilation for link time optimization
CN109918074A (en) * 2017-12-08 2019-06-21 中标软件有限公司 Compiling link optimization method
CN109918074B (en) * 2017-12-08 2022-09-27 中标软件有限公司 Compiling link optimization method

Similar Documents

Publication Publication Date Title
US6427234B1 (en) System and method for performing selective dynamic compilation using run-time information
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.
US5999737A (en) Link time optimization via dead code elimination, code motion, code partitioning, code grouping, loop analysis with code motion, loop invariant analysis and active variable to register analysis
Van Put et al. Diablo: a reliable, retargetable and extensible link-time rewriting framework
Wimmer et al. Linear scan register allocation on SSA form
JP3311462B2 (en) Compile processing unit
Wimmer et al. Optimized interval splitting in a linear scan register allocator
US6973644B2 (en) Program interpreter
US20090113404A1 (en) Optimum code generation method and compiler device for multiprocessor
JPH04322329A (en) System and method for information processing copying with many machine types
JP6718119B2 (en) Compiling program, compiling method, and information processing apparatus
JP2018510445A (en) Domain-specific system and method for improving program performance
Novillo Design and implementation of Tree SSA
US7155707B2 (en) Compiling computer programs including branch instructions
Barua et al. OMPSan: static verification of OpenMP’s data mapping constructs
JPH10275088A (en) Link optimizing method
Ashcraft et al. Compiler optimization of accelerator data transfers
US7007272B2 (en) Compiling computer programs including branch instructions
US6721945B1 (en) Optimization of calls in programming languages using pointers for passing reference parameters
Sampaio et al. Spill code placement for simd machines
Doerfert et al. Polyhedral expression propagation
Chatarasi et al. A unified approach to variable renaming for enhanced vectorization
Böckle Exploitation of fine-grain parallelism
Mogensen Data-Flow Analysis and Optimisation
Eisl Trace Register Allocation