JP3239907B2 - Register allocation method - Google Patents

Register allocation method

Info

Publication number
JP3239907B2
JP3239907B2 JP02465893A JP2465893A JP3239907B2 JP 3239907 B2 JP3239907 B2 JP 3239907B2 JP 02465893 A JP02465893 A JP 02465893A JP 2465893 A JP2465893 A JP 2465893A JP 3239907 B2 JP3239907 B2 JP 3239907B2
Authority
JP
Japan
Prior art keywords
priority
variable
allocation
variables
register
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.)
Expired - Fee Related
Application number
JP02465893A
Other languages
Japanese (ja)
Other versions
JPH06214802A (en
Inventor
仁 阿部
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.)
Fujifilm Business Innovation Corp
Original Assignee
Fuji Xerox Co Ltd
Fujifilm Business Innovation Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fuji Xerox Co Ltd, Fujifilm Business Innovation Corp filed Critical Fuji Xerox Co Ltd
Priority to JP02465893A priority Critical patent/JP3239907B2/en
Publication of JPH06214802A publication Critical patent/JPH06214802A/en
Application granted granted Critical
Publication of JP3239907B2 publication Critical patent/JP3239907B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Description

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

【0001】[0001]

【産業上の利用分野】本発明はレジスタ割り付け方式に
関し、詳しくは、ソースコードをオブジェクトコードに
変換するコンパイル装置(コンパイラ)のレジスタ割り
付け方式に関する。なお「レジスタ割り付け」と「レジ
スタ割り当て」の語を下記(1)と(2)のように厳格
に区別している文献もあるが、本明細書では、「レジス
タ割り付け」の語を下記(1)と(2)の双方の意味で
用いる。 (1)レジスタ割り付け=プログラム中のある点で、値
をレジスタに常駐させたい変数の集合を求める。 (2)レジスタ割り当て=レジスタ割り付けフェーズに
続いて、変数の値を常駐させる為のレジスタを選ぶ。 (上記(1)、(2)を区別している文献としては、例
えば、A.V.Aho ほか著、原田賢一訳 "コンパイラ2(但
し「2」はローマ数字)" (1990.10.10) サイエンス社
p.628)
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a register allocating method, and more particularly, to a register allocating method of a compiling device (compiler) for converting a source code into an object code. In some documents, the terms “register allocation ” and “register allocation ” are strictly distinguished as in the following (1) and (2). However, in this specification, the term “register allocation” is described in the following (1). And (2). (1) Register allocation = At a certain point in the program, a set of variables whose values are to be made resident in registers is obtained. (2) Register allocation = Subsequent to the register allocation phase, a register for making the value of a variable resident is selected. (Referring to AVAho et al., Translated by Kenichi Harada, "Compiler 2 (where" 2 "is a Roman numeral)" (1990.10.10)
p.628)

【0002】[0002]

【従来の技術】コンパイル装置でのレジスタ割り付けの
適、不適は、プログラムの実行速度に大きな影響があ
る。その最適化はコンパイル装置設計時の大きなテーマ
である。これに関する技術として、従来、下記文献に記
載されたようなものがあった。 文献1) Computer Language,1981[6] (米) G.J.Chaiti
n, M.A.Auslander, A.K.Chandra, J.Cocke, M.E.Hopkin
s and P.W.Markstein,"Register Allocation via Color
ing",p.47-57 文献2) Proceedings of the ACM SIGPLAN Symposium o
n Compiler Construction,(June 17-22,1984) (米) F.
C.Chow and J.Hennesy,"Register Allocation by Prior
ity-based Coloring",p.222-232 (ACM SIGPLAN = Assoc
iation for Computing Machinery Special interest gr
oup on programing languages) 文献3) 特開平1−103742号公報「最適コンパイ
ル方式」
2. Description of the Related Art The suitability or unsuitability of register allocation in a compiling device has a great effect on the execution speed of a program. The optimization is a major theme when designing a compiling device. As a technique related to this, there has been a technique described in the following literature. Reference 1) Computer Language, 1981 [6] (US) GJChaiti
n, MAAuslander, AKChandra, J. Cocke, MEHopkin
s and PWMarkstein, "Register Allocation via Color
ing ", p.47-57 Reference 2) Proceedings of the ACM SIGPLAN Symposium o
n Compiler Construction, (June 17-22,1984) (USA)
C. Chow and J. Hennesy, "Register Allocation by Prior
ity-based Coloring ", p.222-232 (ACM SIGPLAN = Assoc
iation for Computing Machinery Special interest gr
oup on programming languages) Reference 3) Japanese Patent Application Laid-Open No. 1-103742, "Optimal compilation method"

【0003】[0003]

【発明が解決しようとする課題】文献1の技術では、グ
ラフ彩色法を応用してレジスタ割り付けを行っている。
例えば、図6(A)のようなソースコードの場合、まず変
数の生存区間を求め(図6(B))、その生存区間から干渉
グラフを生成し(図6(C))、このグラフを基に各変数
のレジスタ(Reg1〜3)への割り付けを行なう(図
6(D))。この従来技術では、各変数の生存区間全体を
レジスタ割り付けの最小単位としている。この為、例え
ば図7(A)のように変数(E)が一つ増え、その生存
区間のごく一部だけが他(C)と干渉しているに過ぎ
ず、他の区間ではレジスタへの割り付けが可能な場合で
あっても、干渉した変数の何れかが生存区間全体として
スピルの対象となってしまい(割り付けの対象外となっ
てしまい)、生成されたオブジェクトコードの効率が良
くない、という場合があった。
In the technique of Document 1, register allocation is performed by applying a graph coloring method.
For example, in the case of a source code as shown in FIG. 6A, first, a live range of a variable is obtained (FIG. 6B), and an interference graph is generated from the live range (FIG. 6C). Each variable is assigned to a register (Reg1 to Reg3) based on this (FIG. 6D). In this prior art, the entire live range of each variable is set as the minimum unit for register allocation. For this reason, for example, as shown in FIG. 7A, the variable (E) is increased by one, and only a small part of the live range interferes with the other (C). Even if assignment is possible, any of the interfering variables is subject to spilling as a whole live range (not subject to assignment), resulting in inefficient object code generated. There was a case.

【0004】また文献2では、一通り彩色が終わった
後、スピルの対象となった変数の生存区間を複数に分割
する事で上記問題点を解消している。しかし、その際、
最初に生成した干渉グラフに新たなノードを付加し、再
計算を行なう為、計算時間が長くなり、且つ分割される
変数の生存区間が妥当でない場合があった。例えば図7
(B)のように変数A、Bが区間IR2で干渉してお
り、変数Aはこの区間IR2以外で10回参照され、終
点PEを除いて、干渉区間IR2では全く参照されてい
ない、また変数Bは干渉区間IR2の区間内のみで3回
参照されているものとする。グラフ彩色の結果では、ス
ピルの対象になるのは変数Bであり、Bが分割される。
しかしスピルの原因となった干渉区間IR2について上
記のような事情があったとすると、参照回数の多い変数
Bの方をレジスタへ割り付けるものとして残し、むしろ
変数Aを分割した方が、生成されるオブジェクトコード
の実行効率は高い。
In the literature 2, the above problem is solved by dividing the live range of the variable to be spilled into a plurality of sections after the coloring is completed. However,
Since a new node is added to the initially generated interference graph and recalculation is performed, the calculation time becomes long, and the live range of the variable to be divided may not be appropriate. For example, FIG.
As shown in (B), the variables A and B interfere in the section IR2, and the variable A is referred to 10 times outside this section IR2, and is not referenced at all in the interference section IR2 except for the end point PE. It is assumed that B is referred to three times only in the section of the interference section IR2. In the result of the graph coloring, it is the variable B that is to be spilled, and B is divided.
However, if the above situation occurs in the interference section IR2 causing the spill, it is better to leave the variable B, which has a larger number of references, as the one to be assigned to the register, and rather to divide the variable A, Code execution efficiency is high.

【0005】文献3でも、彩色のあとで割り付けの済ん
でいない変数を分割する。しかし、それによって生じた
ノードを新たに干渉グラフには追加せず、残っているレ
ジスタの空き区間に対し、残っている変数の中の優先順
位の高いものの生存区間が出来る限り長くなるようその
変数の生存区間を分割して割り付けを行う。しかしこの
従来技術でも、上記文献2のものと同じく、既に彩色さ
れてしまった干渉部分の変数の参照状況については考慮
が為されておらず、上記文献2のものについて指摘した
欠点は、解消されていない。本発明の目的は、上記従来
技術の欠点を解消し、コンパイル装置の最適化処理部に
おいて、最適レジスタ割り付けが可能なレジスタ割り付
け方式を提供することにある。
[0005] In Reference 3, variables that have not been assigned after coloring are also divided. However, the resulting node is not newly added to the interference graph, and the remaining variables are set so that the lifetime of the higher priority one among the remaining variables becomes as long as possible with respect to the free interval of the remaining register. Is divided and assigned. However, even in this prior art, as in the case of the above-mentioned document 2, no consideration is given to the reference situation of the variable of the already-colored interference part, and the disadvantage pointed out in the above-mentioned document 2 is eliminated. Not. SUMMARY OF THE INVENTION It is an object of the present invention to solve the above-mentioned drawbacks of the prior art and to provide a register allocating method capable of optimizing register allocation in an optimizing processing unit of a compiling device.

【0006】[0006]

【課題を解決するための手段】上記目的達成のため本発
明では、ソースコードをオブジェクトコードに変換する
コンパイル装置において、命令を所定数毎に区切った各
区間について、各変数の出現状態を検査する出現状態検
査手段と、前記各変数の出現状態を基に前記各区間にお
ける各変数の優先度を算定し、優先度の高い方から順に
レジスタ個数分迄の変数を割り付け候補とする割り付け
候補抽出手段と、前記各区間で割り付け候補とされた全
変数について、夫々が出現している夫々の区間での優先
度を基に該全変数についての優先順位を算定する全候補
優先順位算定手段と、前記全変数について優先順位の高
いものから順に、その変数が出現している各区間につい
て、その区間の空きレジスタへのその変数の割り付けを
行なう割り付け処理手段とを備える。
In order to achieve the above object, according to the present invention, in a compiling apparatus for converting a source code into an object code, an appearance state of each variable is inspected in each section obtained by dividing a predetermined number of instructions. Appearance state inspection means and allocation candidate extraction means for calculating the priority of each variable in each section based on the appearance state of each of the variables, and assigning variables up to the number of registers in descending order of priority as allocation candidates And all candidate priorities calculating means for calculating priorities for all the variables based on the priorities in the respective sections in which each of the variables has been assigned as an allocation candidate in each section, and Allocation processing for allocating the variable to the empty register of the section for each section in which the variable appears, in order of priority from all variables. And means.

【0007】[0007]

【作用】コンパイラ装置では、ソースコードのパージン
グ、中間言語生成、最適化処理を経てオブジェクトコー
ド生成が行なわれる。本発明レジスタ割り付け方式は、
その中の最適化処理の1つとして実施される。先ず、生
成された中間言語の一連の命令が所定数毎に区切られ、
この各区間(以後「ウィンドウ」という)について、各
変数の出現状態が検査される。出現状態の検査とは、そ
のウィンドウ内に変数の生存区間の始まり又は終りがあ
るか、そのウィンドウ内でその変数が何回参照、代入等
されているか等の検査をいう。生存区間の始まりと終り
では、レジスタ・メモリ間の変数の移動が行なわれる。
この処理はコストが高い(処理時間が掛かる)。従って
着目したウィンドウに始点、終点がある変数は、そこで
生存区間が連続しているものに比べ、レジスタ割り付け
の優先度が低く計算される。また周知のように、参照、
代入等の回数の多い変数ほどレジスタにおいた場合の処
理速度が上がる。従ってこの回数の多いものは、逆にレ
ジスタ割り付けの優先度が高く計算される。これら出現
状態を基に、各ウィンドウに於て各変数についての優先
度が算定される。そして優先度の高い方から順にレジス
タ個数分迄の変数がそのウィンドウにおけるレジスタへ
の割り付け候補とされる。例えば、そのウィンドウで使
用される変数が7個あり、レジスタが3個であったとす
れば、優先度1番から3番迄の変数が、そこでの割り付
け候補とされる。
In the compiler device, object code generation is performed through source code parsing, intermediate language generation, and optimization processing. The register allocation method of the present invention
This is performed as one of the optimization processes. First, a series of instructions of the generated intermediate language are divided into predetermined numbers,
In each section (hereinafter referred to as a “window”), the appearance state of each variable is checked. The check of the appearance state refers to a check of whether the life span of the variable is at the beginning or end within the window, and how many times the variable is referenced or substituted in the window. At the beginning and end of the live range, variables are moved between the register and the memory.
This processing is expensive (processing time is required). Therefore, a variable having a start point and an end point in the window of interest is calculated to have a lower register allocation priority than a variable having a continuous live range there. As is well known, reference,
A variable having a larger number of substitutions or the like has a higher processing speed when it is stored in a register. Therefore, the one with the larger number of times is calculated with the higher priority of register allocation. Based on these appearance states, the priority of each variable in each window is calculated. Variables up to the number of registers in descending order of priority are assigned to registers in the window. For example, if there are seven variables used in the window and three registers, the variables with the first to third priorities are set as allocation candidates there.

【0008】このようにして各ウィンドウで割り付け候
補とされた変数全てについて、今度は、夫々が出現して
いる夫々のウィンドウでの優先度を基に、全変数を対象
とした優先順位が算定される。例えば、レジスタ数が3
個であれば各ウィンドウで3個づつ割り付け候補が抽出
される。ここで、ウィンドウ3では変数x,y,u、ウ
ィンドウ4では、変数j,u,y、というように、各ウ
ィンドウ、例えば10個のウィンドウ夫々で割り付け候
補とされたものを集めると、a〜z迄の27個の変数が
あったする。この27個の変数について1番から27番
迄の優先順位が定められる。この優先順位は例えば次の
ように定められる。即ち各ウィンドウにおける優先度が
評価値の大小に比例するとされているとき、同じ変数に
ついて、それが割り付け候補とされているウィンドウ全
てに於て、その変数に与えられている評価値の積算が行
なわれ、その値の大きいものの方が優先順位が高いとさ
れる。この優先順位に従い、その変数が出現している全
ウィンドウについて、その変数の各ウィンドウの空きレ
ジスタへの割り付けが行なわれる。例えば上記例示した
変数について、優先順位がu,h,j,…,…であった
とし、またこの変数uが、ウィンドウ6〜10でも出現
していたとする。変数uは、そこでは最優先でないウィ
ンドウ3,4を始め、ウィンドウ6〜10の全てに於
て、真っ先にレジスタに割り付けられる。但し割り付け
候補外となっているウィンドウでは割り付けられない。
次は、前記例示した優先順位に従えば、変数hについ
て、それが出現するウィンドウ全てにおいてレジスタ割
り付けが行なわれる。そして全てのウィンドウで割り付
け候補の変数が無くなったとき、レジスタ割り付け処理
は終了となり、各ウィンドウのレジスタ割り付けの情報
は、後処理のコード生成ユニットに与えられ、この情報
に基づいてコード化が行なわれる。
[0008] With respect to all the variables which have been assigned as candidates in each window in this way, the priorities for all the variables are calculated based on the priorities in the respective windows in which they appear. You. For example, if the number of registers is 3
If there are three, three allocation candidates are extracted in each window. Here, the windows x, y, u in the window 3 and the variables j, u, y in the window 4, such as ten windows, are collected. There are 27 variables up to z. The priority order from No. 1 to No. 27 is determined for these 27 variables. This priority is determined, for example, as follows. That is, when the priority in each window is set to be proportional to the magnitude of the evaluation value, the evaluation value given to the variable is integrated for all the windows in which the same variable is a candidate for allocation. The higher the value, the higher the priority. In accordance with this priority order, for all windows in which the variable appears, allocation of the variable to an empty register of each window is performed. For example, it is assumed that the priority of the variables exemplified above is u, h, j,..., And that the variable u also appears in windows 6 to 10. The variable u is allocated first to the registers in all of the windows 6-10, starting with the non-highest priority windows 3,4. However, it cannot be allocated to windows that are not allocation candidates.
Next, according to the above-described priority, register allocation is performed for the variable h in all windows in which it appears. When there are no more variables to be allocated in all the windows, the register allocation processing ends, and the information of register allocation of each window is given to the post-processing code generation unit, and coding is performed based on this information. .

【0009】[0009]

【実施例】以下本発明の詳細を図示実施例に基いて説明
する。図2にコンパイル装置1の概略構成を示す。前述
のように、ソースコードは先ずパーザ2によりパージン
グされる。次に中間言語生成ユニット3により、中間言
語に置き換えられる。この中間言語は最適化処理ユニッ
ト4に於て、本発明方式によるレジスタ割り付けや、そ
の他の最適化処理を受ける。そしてコード生成ユニット
5に於てコード化され、オブジェクトコードとされる。
なお各種最適化の処理、例えば共通部分式の削除、命令
再配置、ピープホール最適化等については、A.V.Aho ほ
か著 "Compilers Principles, Technique, andTools"
(1986) Addison-Wesley Publishers Limited (米) 等に
述べられており、またコンパイラ装置の他の各処理につ
いても同書に述べられている。
DESCRIPTION OF THE PREFERRED EMBODIMENTS The details of the present invention will be described below with reference to the illustrated embodiments. FIG. 2 shows a schematic configuration of the compiling device 1. As described above, the source code is first parsed by the parser 2. Next, the intermediate language is converted into an intermediate language by the intermediate language generation unit 3. The intermediate language is subjected to register allocation and other optimization processing according to the present invention in the optimization processing unit 4. Then, it is coded in the code generation unit 5 to be an object code.
Avaho et al., "Compilers Principles, Technique, andTools", describe various optimization processes such as common subexpression elimination, instruction rearrangement, and peephole optimization.
(1986) Addison-Wesley Publishers Limited (US), etc., and other processes of the compiler unit are also described in the same book.

【0010】本発明の一実施例たる割り付け装置の構成
を図1に示す。この装置41は前記最適化処理ユニット
4の中に配置される。なお前後のユニット等、既に説明
をしたものは、同じ符号を付すのみとし、再度の説明は
しない。図に於て31は中間言語保持部で、中間言語生
成ユニット3で生成された中間言語を保持する。411
は出現状態検査部で、この中間言語の一連の命令を所定
数づつ(1ウィンドウ分づつ)読み込み、各変数の出現
状態を検査して、各ウィンドウでの各変数の出現状態を
表わす情報を出現情報保持部412に格納する。ここに
出現状態の検査とは、その変数の生存区間がそのウィン
ドウで始まっているか、或いは終りとなっているか、ま
た、その変数がそのウィンドウ内で何回参照され或いは
代入されるか等の検査をいう。前述のように、生存区間
の始まりと終りでは、レジスタ・メモリ間の変数の移動
が行なわれる。この処理はコストが高い(処理時間が掛
かる)。従って着目したウィンドウに始点、終点がある
変数は、そこで生存区間が連続しているものに比べ、優
先度が低いと算定される。また参照回数或いは代入回数
の多い変数ほどレジスタにおいた場合の処理速度が上が
る。従ってこの回数の多いものほど、レジスタ割り付け
の優先度が高いと算定される。
FIG. 1 shows the configuration of an allocating apparatus according to an embodiment of the present invention. This device 41 is arranged in the optimization processing unit 4. It should be noted that components that have already been described, such as the front and rear units, are given the same reference numerals, and will not be described again. In the figure, reference numeral 31 denotes an intermediate language holding unit which holds the intermediate language generated by the intermediate language generation unit 3. 411
Is an appearance state checker which reads a series of instructions of this intermediate language at a predetermined number (for each window), checks the appearance state of each variable, and generates information representing the appearance state of each variable in each window. The information is stored in the information storage unit 412. Here, the check of the appearance state means whether the life span of the variable starts or ends in the window, and how many times the variable is referred to or substituted in the window. Say. As described above, at the beginning and end of the live range, variables are moved between the register and the memory. This processing is expensive (processing time is required). Therefore, a variable having a start point and an end point in the window of interest is calculated as having a lower priority than a variable having a continuous live range there. In addition, the processing speed when a variable is placed in a register increases as the number of times of reference or substitution increases. Therefore, it is calculated that the higher the number of times, the higher the priority of register allocation.

【0011】413は割り付け候補抽出部で、出現情報
保持部412に格納されているこれら各変数の出現状態
の情報に基づき、各ウィンドウにおける各変数の優先度
を算定する。なお図では「割り付け」は「割付」と表示
する。例えば前述のように、そのウィンドウで使用され
る変数が7個あり、レジスタが3個であったとすれば、
優先度1番から3番迄の変数が、そのウィンドウでの割
り付け候補として抽出され、割り付け候補保持部414
に格納される。なお優先度の具体的算定例は後述する。
415は全候補優先順位算定部で、割り付け候補保持部
414に格納されている割り付け候補全てについて、夫
々が出現している夫々のウィンドウでの優先度を基に、
全変数通しての優先順位を算定する。例えば前述のよう
に、レジスタ数が3個であれば、各ウィンドウで割り付
け候補が3個づつ抽出される。そしてウィンドウ3では
変数x,y,u、ウィンドウ4では、変数j,u,y、
というように、各ウィンドウ、例えば10個のウィンド
ウ夫々で、a〜z迄の27個の変数があったする。この
27個の変数について1番から27番迄の優先順位が定
められる。この優先順位は、本実施例では次のように定
める。即ち、評価値の大なるものを優先度が高いとし、
同じ変数について、それが割り付け候補とされているウ
ィンドウ全てに於て与えられている評価値を積算する。
この積算値を大きさの順にソートし、大きいものの方を
優先順位が高いとする。全候補優先順位算定部415は
このようにして算定した全割り付け候補についての優先
順位の情報を全候補優先順位保持部416に格納する。
Reference numeral 413 denotes an allocation candidate extraction unit which calculates the priority of each variable in each window based on the information on the appearance state of each of these variables stored in the appearance information holding unit 412. In the figure, “assignment” is displayed as “assignment”. For example, as mentioned above, if there are seven variables used in the window and three registers,
The variables with the first to third priorities are extracted as allocation candidates in the window, and the allocation candidate holding unit 414
Is stored in A specific calculation example of the priority will be described later.
Reference numeral 415 denotes an all-candidate-priority calculating unit which determines all the allocation candidates stored in the allocation-candidate holding unit 414 based on the priorities in the respective windows in which each appears.
Calculate the priority over all variables. For example, as described above, if the number of registers is three, three allocation candidates are extracted in each window. In window 3, variables x, y, u, and in window 4, variables j, u, y,
Thus, in each window, for example, each of the ten windows, there are 27 variables a to z. The priority order from No. 1 to No. 27 is determined for these 27 variables. This priority is determined as follows in this embodiment. In other words, the one with the larger evaluation value has higher priority,
For the same variable, the evaluation values given in all the windows in which it is a candidate for allocation are integrated.
The integrated values are sorted in the order of the size, and the larger one is determined to have a higher priority. The all-candidate-priority calculating unit 415 stores the information on the priorities of all the allocation candidates calculated in this way in the all-candidate-priority holding unit 416.

【0012】417は割り付け処理部で、この優先順位
に従い、その変数が出現している全ウィンドウについ
て、そのウィンドウの空きレジスタへの割り付けを行な
う。例えば上記例示した変数について、優先順位がu,
h,j,…,…であったとし、この変数uが、他にもウ
ィンドウ6〜10でも出現していたとする。割り付け処
理部417は、上記例示では最優先でないウィンドウ
3,4を始め、ウィンドウ6〜10の全てに於て、この
変数uに対し、真っ先にレジスタを割り付ける。その後
は、前記例示した優先順位に従って、その変数が出現す
るウィンドウ全てに於て、それに対しレジスタが割り付
ける。全てのウィンドウで割り付け候補の変数が無くな
ったとき、割り付け処理部417はその処理を終了し、
この処理で生成されたレジスタ割り付けの情報を割り付
け情報保持部51に格納する。後処理のコード生成ユニ
ット5は、この情報に基づいてコード化処理を行なう。
Reference numeral 417 denotes an allocation processing unit which allocates all windows in which the variable appears to empty registers according to the priority order. For example, for the variables exemplified above, the priority order is u,
h, j,..., and this variable u also appears in windows 6 to 10. The allocation processing unit 417 allocates the register to the variable u first in the windows 3 to 4 which are not the highest priority in the above example and in all of the windows 6 to 10. Thereafter, registers are allocated to the variables in all the windows in which the variable appears in accordance with the above-described priority order. When there are no more allocation candidate variables in all windows, the allocation processing unit 417 ends the processing,
The register allocation information generated in this process is stored in the allocation information holding unit 51. The post-processing code generation unit 5 performs a coding process based on this information.

【0013】具体的処理例を図3に示す。同図(A)の
ようなソースコードをパージングし、同図(B)のよう
な内部表現に変えた場合、この状態ではコストの高いロ
ード/ストア命令が6回ある。例えば3命令を1つのウ
ィンドウとすると、同図(C)のように各変数a,b,
cの生存区間が分割される。これら各ウィンドウW1〜
W3内の各変数について、下記式(1)により優先順位
が算定される。レジスタ数を2とすると、その結果は同
図(D)のようになる。なお、優先順位が高いものを左
側に記載し、そのウィンドウではメモリ中に追い出され
るものを、( )で囲って表示した。次に3つのウィンド
ウW1〜W3の全部の割り付け候補が取り出され、夫々
の優先度が積算される。ここでは後述の式(1)によら
ず、単純に優先順位1位にポイント2、2位にポイント
1が与えられるとする。変数bが積算ポイント「5」、
cが「3」、aが「1」となる。
FIG. 3 shows a specific processing example. When the source code as shown in FIG. 7A is parsed and converted into an internal representation as shown in FIG. 7B, there are six load / store instructions which are expensive in this state. For example, assuming three instructions as one window, as shown in FIG.
The live range of c is divided. These windows W1 to W1
The priority of each variable in W3 is calculated by the following equation (1). Assuming that the number of registers is 2, the result is as shown in FIG. Those with the highest priority are shown on the left, and those that are evicted in the memory are displayed in parentheses in the window. Next, all the allocation candidates of the three windows W1 to W3 are extracted and their priorities are integrated. Here, it is assumed that the point 2 is simply given to the first priority and the point 1 is given to the second, regardless of the expression (1) described later. The variable b is the accumulated point “5”,
c becomes “3” and a becomes “1”.

【0014】この積算ポイントの大きい方が優先順位が
高いとされる。従って変数bが最優先とされ、この変数
bに対し、これが生存している全てのウィンドウW1〜
W3で、その部分のレジスタ1が割り付けられる(図3
(E))。優先順位2番目は変数cであった。この変数
cの生存区間はウィンドウW2,W3である。これらウ
ィンドウではまだ空きレジスタ(レジスタ2)がある。
これに変数cが割り付けられる(図3(E))。次に変
数aに対し、レジスタの割り付けが行なわれる。この変
数aの生存区間はウィンドウW1であった。このウィン
ドウではまだレジスタ2が空いている。この部分のレジ
スタ2に変数aが割り付けられる(図3(E))。図3
(E)で示されるようなレジスタ割り付け情報は、割り
付け情報保持部51を介してコード生成ユニット5に供
給される。コード生成ユニット5がこの情報に従い図3
(B)の内部表現を置き換えると、図3(F)のように
なる。命令数では1つ増えているが、コストの高い命
令、即ちメモリからのロード/ストア命令は、図3
(B)の6個から2個へと極端に減少している。この
為、実行効率は向上する。
It is assumed that the larger the accumulated points, the higher the priority. Therefore, the variable b has the highest priority, and for this variable b, all the windows W1 to
In W3, the register 1 of that part is allocated (FIG. 3
(E)). The second priority was variable c. The live range of the variable c is the windows W2 and W3. There are still empty registers (register 2) in these windows.
The variable c is assigned to this (FIG. 3E). Next, a register is allocated to the variable a. The life span of this variable a was the window W1. In this window, register 2 is still empty. The variable a is assigned to this part of the register 2 (FIG. 3E). FIG.
The register allocation information as shown in (E) is supplied to the code generation unit 5 via the allocation information holding unit 51. According to this information, the code generation unit 5
Replacing the internal representation of (B) results in FIG. 3 (F). Although the number of instructions is increased by 1, the costly instruction, that is, the load / store instruction from the memory, is shown in FIG.
The number is extremely reduced from six in (B) to two. For this reason, the execution efficiency is improved.

【0015】優先度は例えば下記式(1)で算出され
る。この優先度の値が大きい変数ほど優先順位が高いと
され、各ウィンドウにおいて、優先度の大きいものから
順にレジスタ数と同じ数だけ変数が抽出され、これらが
割り付け候補とされる。 優先度=ロード利益×ウィンドウ内の参照回数+ストア利益×ウィン ドウ内の代入回数−移動費用×n …………(式1) 各項目の内容は次の通りである。 ロード利益:その変数をレジスタに置いた場合、メモリ
に置いて参照する場合に比べ節約される実行時間 ストア利益:その変数をレジスタに置いた場合、メモリ
へストアする場合に比べ節約される実行時間 移動費用 :メモリ・レジスタ間の移動に要する時間。 n :メモリ・レジスタ間で移動する回数。
The priority is calculated, for example, by the following equation (1). Variables with higher priority values are determined to have higher priority, and in each window, variables are extracted by the same number as the number of registers in descending order of priority, and these are set as allocation candidates. Priority = load profit × the number of references in the window + store profit × the number of substitutions in the window−movement cost × n (Equation 1) The contents of each item are as follows. Load profit: execution time saved when placing the variable in a register compared to referencing in memory Store profit: execution time saved when placing the variable in a register compared to storing in memory Transfer cost: Time required to transfer between memory and register. n: Number of times of movement between memory registers.

【0016】参照回数、代入回数が多いものほどレジス
タに置いた方が有利なことは知られている。そこでこの
式(1)でも、「ロード利益×ウィンドウ内の参照回
数」及び「ストア利益×ウィンドウ内の代入回数」の値
は、優先度に対してプラスとし優先度を高める要素とし
ている。一方、レジスタに置くためには、生存区間の最
初と最後にメモリ・レジスタ間で変数の移動をしなけれ
ばならない。この移動の費用(処理時間)は高い。そこ
で「移動費用×n」の値は優先度に対しマイナスとし、
優先度を下げる要素としている。なお移動する回数n
は、具体的にはそのウィンドウ内に、その変数の生存区
間の始まり又は終りがあった場合に1を加算していくこ
とで計数され、その生存区間が前後のウィンドウに跨が
っていれば「n=0」、そのウィンドウ内に始点又は終
点があれば「n=1」、始点、終点の双方があるものは
「n=2」となり、大きいほどその変数の優先度が下が
る。
It is known that the greater the number of references and the number of substitutions, the more advantageous it is to place them in a register. Therefore, also in this equation (1), the values of “load profit × the number of references in the window” and “store profit × the number of substitutions in the window” are factors that increase the priority by making the values plus the priority. On the other hand, variables must be moved between memory registers at the beginning and end of the live range in order to place them in registers. The cost (processing time) of this transfer is high. Therefore, the value of "movement cost x n" is set to minus the priority,
This is an element that lowers the priority. The number of times of movement n
Is counted by adding 1 when the live range of the variable starts or ends in that window, and if the live range spans the previous and next windows. "N = 0", "n = 1" if there is a start point or end point in the window, "n = 2" if there is both a start point and end point, and the higher the value, the lower the priority of the variable.

【0017】図4に割り付け候補を抽出するまでのフロ
ーを示す。尚このフローは1つの変数についてのもので
ある。処理されるのは複数の変数であり、これらに対し
ては、図4のフロー全体を変数の数の分繰り返しても良
く、或いは各ステップ毎に変数全部に対して並列に処理
をしても良い。まず式(1)のnの値が初期値「0」に
される(ステップS1)。なお「ステップ」の語は以後
省略する。次にウィンドウの大きさ分のコードが読み込
まれる(ステップS2)。次に移動回数nが求められる
(S3〜S6)。そのウィンドウから生存区間が開始し
ている、あるいはそのウィンドウで生存区間が終了して
いるならば、nに1が加えられる。次に1ウィンドウ分
の各命令が順にチェックされ、その変数の参照回数と代
入回数が計数される(S7)。此処までの処理は出現状
態検査部411によって実行され、これらの値は出現情
報保持部412に格納される。
FIG. 4 shows a flow until an allocation candidate is extracted. This flow is for one variable. A plurality of variables are processed. For these variables, the entire flow of FIG. 4 may be repeated for the number of variables, or all the variables may be processed in parallel at each step. good. First, the value of n in equation (1) is set to an initial value “0” (step S1). The word “step” will be omitted hereinafter. Next, a code corresponding to the size of the window is read (step S2). Next, the number of movements n is obtained (S3 to S6). If the live range has started from the window or the live range has ended in the window, 1 is added to n. Next, the instructions for one window are sequentially checked, and the number of references and the number of substitutions of the variable are counted (S7). The processing up to this point is executed by the appearance state inspection unit 411, and these values are stored in the appearance information holding unit 412.

【0018】次にこれらの値が式(1)に代入され、そ
の変数の優先度が算出される(S8)。算出されたその
変数の優先度は割り付け候補保持部414に格納される
(S9)。このS8,S9の処理は割り付け候補抽出部
413によって行なわれる。これらの処理(S1〜S
9)を全てのウィンドウについて繰り返す(S10)。
図4の処理が終ると、割り付け候補抽出部413は割り
付け候補保持部414の変数を優先度について大きさ順
になるようにソートする。そして各ウィンドウ毎に優先
度が大きいものからレジスタ数分の変数を、そのウィン
ドウの割り付け候補として残し割り付け候補保持部41
4に再格納する。なお全ての変数について図4の処理が
終ったとき、各ウィンドウ毎の割り付け候補がレジスタ
分だけ残っているようにしても良い。このようにする場
合は割り付け候補保持部414には、始めから各ウィン
ドウ毎にレジスタ数分の格納領域のみを設けておく。そ
して各変数の優先度格納の際、先ずそのウィンドウの領
域に空きがあるかをチェックし、あれば、そのまま格納
し、また空きがないときは、既に格納されている優先度
にこの新たな優先度を加えてソートし、大きい順に領域
数分の優先度を再格納する。このようにすると、全ての
変数について図4の処理が終ったとき、割り付け候補保
持部414の各ウィンドウ毎の領域に、レジスタ分の割
り付け候補が残っていることになる。
Next, these values are substituted into equation (1), and the priority of the variable is calculated (S8). The calculated priority of the variable is stored in the allocation candidate holding unit 414 (S9). The processing in S8 and S9 is performed by the allocation candidate extracting unit 413. These processes (S1 to S
Step 9) is repeated for all windows (S10).
When the processing in FIG. 4 is completed, the allocation candidate extracting unit 413 sorts the variables in the allocation candidate holding unit 414 so that the variables are arranged in order of magnitude in priority. The variables corresponding to the number of registers from the one with the highest priority for each window are left as allocation candidates for the window, and the allocation candidate holding unit 41
4 again. When the processing of FIG. 4 is completed for all variables, the allocation candidates for each window may be left for the registers. In this case, the allocation candidate holding unit 414 is provided with only a storage area for the number of registers for each window from the beginning. At the time of storing the priority of each variable, it is first checked whether there is a free space in the window area, and if there is no free space, it is stored as it is. If there is no free space, the new stored priority is added to the stored priority. Sort by adding degrees, and store priorities for the number of areas in descending order. In this way, when the processing in FIG. 4 is completed for all variables, the allocation candidates for the registers remain in the area of each window of the allocation candidate holding unit 414.

【0019】図5にレジスタ割り付け処理のフローを示
す。まず各ウィンドウで割り付け候補とされた変数全て
について、各ウィンドウで、その変数に与えられた優先
度の積算が行なわれ、積算値の大きさの順にソートされ
る(S11)。この処理は全候補優先順位算定部415
によって行なわれ、優先順位の情報は全候補優先順位保
持部416に格納される。ここでは積算値の大きいもの
が優先順位が高い。この優先順位の高い変数から順に、
それが出現している全てのウィンドウで、その変数の空
きレジスタへの割り付けが行なわれる(S12)。この
処理は割り付け処理部417によって、割り付け候補と
された変数が無くなるまで続けられる(S13)。処理
が終ったら、生成された割り付け情報は割り付け情報保
持部51に格納される。コード生成ユニット5はこの情
報を基にコード生成を行なう。最後に請求項の構成と実
施例の構成とで名称が異なるものについて対応を説明す
る。411が出現状態検査手段にあたる。割り付け候補
抽出部413が割り付け候補抽出手段にあたる。全候補
優先順位算定部415が全候補優先順位算定手段にあた
る。割り付け処理部417が割り付け処理手段にあた
る。
FIG. 5 shows a flow of the register allocating process. First, with respect to all the variables which are the allocation candidates in each window, the priority given to the variable is integrated in each window, and the variables are sorted in the order of the magnitude of the integrated value (S11). This processing is performed by the all candidate priority calculation unit 415
The priority information is stored in the all candidate priority holding unit 416. Here, the one with the larger integrated value has the higher priority. From the variable with the highest priority,
In all the windows in which it appears, the variable is allocated to an empty register (S12). This process is continued by the allocation processing unit 417 until there are no more variables that are candidates for allocation (S13). After the processing is completed, the generated allocation information is stored in the allocation information holding unit 51. The code generation unit 5 generates a code based on this information. Finally, a description will be given of the correspondence between the structure of the claims and the structure of the embodiment having different names. Reference numeral 411 corresponds to an appearance state inspection unit. The allocation candidate extracting unit 413 corresponds to an allocation candidate extracting unit. The all-candidate-priority calculating unit 415 corresponds to all-candidate-priority calculating means. The allocation processing unit 417 corresponds to an allocation processing unit.

【0020】[0020]

【発明の効果】以上説明したように本発明では、命令を
所定数毎に区切り、その各区間について、各変数の出現
状態を検査し、その状態を基に各区間における各変数の
優先度を算定し、優先度の高い方から順にレジスタ個数
分迄の変数を割り付け候補とし、各区間で割り付け候補
とされた全ての変数を対象にして、夫々が出現している
夫々の区間での優先度を基に優先順位を算定し、優先順
位の高いものから順に、その変数が出現している各区間
について、その区間の空きレジスタへの割り付けを行な
うようにした。従って、レジスタ割り付けの効果が高い
ものから順にレジスタへの割り付けが行なわれることに
なり、従来の手法より効率の高いレジスタ割り付けが実
現できる。
As described above, according to the present invention, instructions are divided into predetermined numbers, the appearance state of each variable is examined for each section, and the priority of each variable in each section is determined based on the state. Calculate and assign variables from the highest priority up to the number of registers as allocation candidates, and for all variables that are allocation candidates in each section, the priority in each section in which each appears , The priority is calculated, and in order from the highest priority, each section in which the variable appears is assigned to an empty register in that section. Therefore, the registers are allocated to the registers in order from the one with the highest effect of register allocation, and register allocation more efficient than the conventional method can be realized.

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

【図1】実施例装置の構成を示すブロック図。FIG. 1 is a block diagram showing a configuration of an embodiment apparatus.

【図2】コンパイル装置の構成例を示すブロック図。FIG. 2 is a block diagram illustrating a configuration example of a compiling device.

【図3】本発明によるレジスタ割り付け例を示す線図。FIG. 3 is a diagram showing an example of register allocation according to the present invention.

【図4】各ウィンドウ毎の割り付け候補抽出手順例を示
すフローチャート。
FIG. 4 is a flowchart illustrating an example of an allocation candidate extraction procedure for each window.

【図5】レジスタ割り付け手順例を示す線図。FIG. 5 is a diagram showing an example of a register allocation procedure.

【図6】従来技術によるレジスタ割り付けの手順を説明
するための線図(その1)。
FIG. 6 is a diagram (part 1) for explaining a procedure of register allocation according to the related art.

【図7】従来技術によるレジスタ割り付けの手順を説明
するための線図(その2)。
FIG. 7 is a diagram (part 2) for explaining the procedure of register allocation according to the conventional technique.

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

1 コンパイル装置 411 出現状態検査手段 413 割り付け候補抽出手段 415 全候補優先順位算定手段 417 割り付け処理手段 1 Compiling device 411 Appearance state inspection means 413 Assignment candidate extraction means 415 All candidate priority calculation means 417 Assignment processing means

───────────────────────────────────────────────────── フロントページの続き (56)参考文献 特開 平4−213118(JP,A) 特開 昭62−219130(JP,A) 松岡恭生・他,「コンパイラにおける 最適化の技法」,インターフェース,日 本,CQ出版株式会社,1989年 3月 1日,Vol.15,No.3,pp. 196−210,(特許庁CSDB文献番号: CSNW199900633004) 大貫徹,「割込み処理,並列制御そし てコード・チューニング」,インターフ ェース,日本,CQ出版株式会社,1989 年 3月 1日,Vol.15,No. 3,pp.264−272,(特許庁CSDB 文献番号:CSNW199900633009) 阿部仁・他,「生存区間分割によるレ ジスタ割り付け」,情報処理学会第42回 全国大会講演論文集(分冊5),日本, 社団法人情報処理学会,1991年2月25 日,pp.113−114 (58)調査した分野(Int.Cl.7,DB名) G06F 9/45 G06F 9/46 G06F 9/30 - 9/42 G06F 9/06 410 JICSTファイル(JOIS) INSPEC(DIALOG) CSDB(日本国特許庁)────────────────────────────────────────────────── ─── Continuation of the front page (56) References JP-A-4-213118 (JP, A) JP-A-62-219130 (JP, A) Yasuo Matsuoka et al., “Optimization Techniques in Compilers”, Interface, Japan, CQ Publishing Co., Ltd., March 1, 1989, Vol. 15, No. 3, pp. 196-210, (Patent Office CSDB literature number: CSNW199900633004) Toru Onuki, "Interrupt processing, parallel control and code tuning", Interface, Japan, CQ Publishing Co., Ltd., March 1, 1989, Vol. 15, No. 3, pp. 264-272, (Patent Office CSDB Document No .: CSNW199900633009) Hitoshi Abe et al., "Register Allocation by Living Interval Division", Proc. Of the 42nd National Convention of IPSJ, Volume 5, Japanese, Information Processing Corporation Society, February 25, 1991, pp. 113-114 (58) Field surveyed (Int.Cl. 7 , DB name) G06F 9/45 G06F 9/46 G06F 9/30-9/42 G06F 9/06 410 JICST file (JOIS) INSPEC (DIALOG) CSDB (Japan Patent Office)

Claims (1)

(57)【特許請求の範囲】(57) [Claims] 【請求項1】 ソースコードをオブジェクトコードに変
換するコンパイル装置において、 命令を所定数毎に区切った各区間について、各変数の出
現状態を検査する出現状態検査手段と、 前記各変数の出現状態を基に前記各区間における各変数
の優先度を算定し、優先度の高い方から順にレジスタ個
数分迄の変数を割り付け候補とする割り付け候補抽出手
段と、 前記各区間で割り付け候補とされた全変数について、夫
々が出現している夫々の区間での優先度を基に該全変数
についての優先順位を算定する全候補優先順位算定手段
と、 前記全変数について優先順位の高いものから順に、その
変数が出現している各区間について、その区間の空きレ
ジスタへのその変数の割り付けを行なう割り付け処理手
段とを備えたことを特徴とするレジスタ割り付け方式。
1. A compiling apparatus for converting a source code into an object code, comprising: an appearance state inspection unit for inspecting an appearance state of each variable in each section obtained by dividing an instruction by a predetermined number; Assignment candidate extracting means for calculating the priority of each variable in each section based on the priority, and assigning variables up to the number of registers in descending order of priority as allocation candidates; and all variables assigned as allocation candidates in each section. , All candidate priority calculating means for calculating the priority of all the variables based on the priority in each section in which each appears, and in order from the highest priority for all the variables, Allocating means for allocating the variable to an empty register of the section for each section in which Perfomed.
JP02465893A 1993-01-20 1993-01-20 Register allocation method Expired - Fee Related JP3239907B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP02465893A JP3239907B2 (en) 1993-01-20 1993-01-20 Register allocation method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP02465893A JP3239907B2 (en) 1993-01-20 1993-01-20 Register allocation method

Publications (2)

Publication Number Publication Date
JPH06214802A JPH06214802A (en) 1994-08-05
JP3239907B2 true JP3239907B2 (en) 2001-12-17

Family

ID=12144252

Family Applications (1)

Application Number Title Priority Date Filing Date
JP02465893A Expired - Fee Related JP3239907B2 (en) 1993-01-20 1993-01-20 Register allocation method

Country Status (1)

Country Link
JP (1) JP3239907B2 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP7012402B1 (en) 2021-10-13 2022-01-28 株式会社ヤマサ Gravel production control method and computer program for gravel production control

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP3648402B2 (en) * 1999-03-31 2005-05-18 株式会社東芝 Compiling method and compiler apparatus
JP4721975B2 (en) * 2006-07-28 2011-07-13 パナソニック株式会社 Compiler device and compiling method
JP5208589B2 (en) * 2008-06-13 2013-06-12 Necシステムテクノロジー株式会社 Compiling device, compiler, and compiling method

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
大貫徹,「割込み処理,並列制御そしてコード・チューニング」,インターフェース,日本,CQ出版株式会社,1989年 3月 1日,Vol.15,No.3,pp.264−272,(特許庁CSDB文献番号:CSNW199900633009)
松岡恭生・他,「コンパイラにおける最適化の技法」,インターフェース,日本,CQ出版株式会社,1989年 3月 1日,Vol.15,No.3,pp.196−210,(特許庁CSDB文献番号:CSNW199900633004)
阿部仁・他,「生存区間分割によるレジスタ割り付け」,情報処理学会第42回全国大会講演論文集(分冊5),日本,社団法人情報処理学会,1991年2月25日,pp.113−114

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP7012402B1 (en) 2021-10-13 2022-01-28 株式会社ヤマサ Gravel production control method and computer program for gravel production control

Also Published As

Publication number Publication date
JPH06214802A (en) 1994-08-05

Similar Documents

Publication Publication Date Title
US5428793A (en) Method and apparatus for compiling computer programs with interproceduural register allocation
US5586328A (en) Module dependency based incremental compiler and method
Okasaki Purely functional data structures
US7353503B2 (en) Efficient dead code elimination
US6131189A (en) System and method to efficiently represent aliases and indirect memory operations in static single assignment form during compilation
Ruggieri et al. Lifetime analysis of dynamically allocated objects
JP3290567B2 (en) Profile instrumentation method
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.
JP3311462B2 (en) Compile processing unit
US7694288B2 (en) Static single assignment form pattern matcher
US20020010911A1 (en) Compile time pointer analysis algorithm statement of government interest
US7120904B1 (en) Data-flow method for optimizing exception-handling instructions in programs
US5535394A (en) Methods for distinguishing dynamically allocated storage along different call paths and for providing a compact representation of alias analysis
US6117185A (en) Skip list data storage during compilation
US6675377B1 (en) Program conversion apparatus
CN114791808A (en) Data flow graph generation method and device
JP3239907B2 (en) Register allocation method
Hanus Efficient implementation of narrowing and rewriting
US6421824B1 (en) Method and apparatus for producing a sparse interference graph
Marlow Update avoidance analysis by abstract interpretation
Brooks et al. Design of an optimizing, dynamically retargetable compiler for Common Lisp
Goubault Implementing functional languages with fast equality, sets and maps: an exercise in hash consing
Krall Implementation techniques for Prolog.
Gabbrielli et al. Memory Management
Mohnen Context patterns, part II

Legal Events

Date Code Title Description
LAPS Cancellation because of no payment of annual fees