JPH11345127A - Compiler - Google Patents

Compiler

Info

Publication number
JPH11345127A
JPH11345127A JP11083570A JP8357099A JPH11345127A JP H11345127 A JPH11345127 A JP H11345127A JP 11083570 A JP11083570 A JP 11083570A JP 8357099 A JP8357099 A JP 8357099A JP H11345127 A JPH11345127 A JP H11345127A
Authority
JP
Japan
Prior art keywords
instruction
register
length
format
instruction format
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.)
Granted
Application number
JP11083570A
Other languages
Japanese (ja)
Other versions
JP3264901B2 (en
Inventor
Masaichi Nakajima
雅逸 中島
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.)
Panasonic Holdings Corp
Original Assignee
Matsushita Electric Industrial Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Matsushita Electric Industrial Co Ltd filed Critical Matsushita Electric Industrial Co Ltd
Priority to JP08357099A priority Critical patent/JP3264901B2/en
Publication of JPH11345127A publication Critical patent/JPH11345127A/en
Application granted granted Critical
Publication of JP3264901B2 publication Critical patent/JP3264901B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

PROBLEM TO BE SOLVED: To provide a compiler capable of generating a machine word program in a small instruction code size. SOLUTION: A first instruction stream length calculating means 32 calculates an instruction stream length, when each variable in a source program is allocated to a first register source, while using an instruction described in a first instruction format. A second instruction stream length calculating means 33 calculates an instruction stream length, when each variable in the source program is allocated to a second register source different from the first register source, while using an instruction described in a second instruction format having an instruction length different from that of the first instruction format. Resource allocation is performed, corresponding to the calculated results.

Description

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

【0001】[0001]

【発明の属する技術分野】本発明は、高級プログラミン
グ言語で書かれたソースプログラムを機械語プログラム
に翻訳するコンパイラに関する。
The present invention relates to a compiler for translating a source program written in a high-level programming language into a machine language program.

【0002】[0002]

【従来の技術】近年、C言語などの高級プログラミング
言語でプログラムを記述し、プログラムの開発効率を高
めることが盛んに行われている。高級プログラミング言
語を用いることによって、プログラマは、プログラム中
の数値の保持、演算、転送等の処理を、変数を用いた演
算(ステップ)によって、任意に定義し、また、必要な
個数だけ用いることができるため、プログラマは自由に
プログラムを記述することができる。また記述されたプ
ログラム(以下、ソースプログラムと称する)は、コン
パイラによってコンパイルされることにより、コンピュ
ータが理解可能な機械語プログラムとなる。この機械語
プログラム中の演算は、機械語命令によって表現され、
また、当該機械語命令は、レジスタ又はメモリをオペラ
ンドとするので、前記変数には、レジスタ又はメモリを
割り付ける必要がある。この割り付け処理は、資源割り
付け処理と称される。この資源割り付け処理が最適であ
れば、前記機械語プログラムのコードサイズを最小とな
る。
2. Description of the Related Art In recent years, it has been actively practiced to write programs in a high-level programming language such as C language to improve the development efficiency of the programs. By using a high-level programming language, the programmer can arbitrarily define the processing such as holding, calculating, and transferring numerical values in a program by calculating (steps) using variables, and use only the required number. Programmers can write programs freely. The described program (hereinafter, referred to as a source program) is a machine language program that can be understood by a computer by being compiled by a compiler. The operations in this machine language program are expressed by machine language instructions,
Since the machine language instruction uses a register or a memory as an operand, it is necessary to assign a register or a memory to the variable. This allocation processing is called resource allocation processing. If the resource allocation process is optimal, the code size of the machine language program is minimized.

【0003】一般的には、各変数に対して、レジスタを
割り付けた場合の方が、メモリを割り付けた場合に比較
して、コードサイズ的にも、実行時間的にも良好な結果
が得られるが、レジスタは使用できる個数が少数である
ため、如何に効率良くレジスタ資源の割り付けを行っ
て、レジスタをオペランドとする機械語命令を使用する
かということが、資源割り付け処理における最適化であ
る。従来の資源割り付けの最適化方式としては、各々の
変数が格納されている値が有効となる区間(変数の生存
区間と称する。)に基づき、同一レジスタに割り付け変
数はどれとどれであるかを検査し、その結果を用いて資
源割り付けを行う方式が採用されている。
In general, when a register is allocated to each variable, better results are obtained in terms of code size and execution time than when memory is allocated. However, since the number of registers that can be used is small, how to efficiently allocate register resources and use a machine language instruction with a register as an operand is an optimization in the resource allocation process. As a conventional resource allocation optimizing method, based on a section in which the value in which each variable is stored is valid (referred to as a variable live range), it is determined which variable is allocated to the same register. A method is adopted in which inspection is performed and resource allocation is performed using the results.

【0004】一方、本願発明者は、特願平10−596
80において、以下のような2種の命令フォーマット及
びレジスタモデルを使用するデータ処理装置を提案して
いる。図10から図20において、第1の命令フォーマ
ットの概要を示す。
On the other hand, the inventor of the present application has disclosed in Japanese Patent Application No.
80, proposes a data processing device using the following two instruction formats and register models. FIGS. 10 to 20 show an outline of the first instruction format.

【0005】第1の命令フォーマットは、最小命令語長
を1バイトとした可変長命令であり、レジスタアドレス
指定フィールドとしては、2ビットのフィールドが使用
される。従って、1つのレジスタアドレス指定フィール
ドで4個のレジスタが指定可能である。本アーキテクチ
ャでは、4個のアドレスレジスタと、4個のデータレジ
スタが定義される。命令動作として、アドレスレジスタ
を使用するか、データレジスタを使用するかを区別する
ことにより、命令で前記合計8個のレジスタを使用でき
るように構成される。
The first instruction format is a variable length instruction having a minimum instruction word length of 1 byte, and a 2-bit field is used as a register address designation field. Therefore, four registers can be specified in one register addressing field. In this architecture, four address registers and four data registers are defined. By discriminating whether to use the address register or the data register as the instruction operation, the instruction can use the eight registers in total.

【0006】図10は、最小命令語長である1バイト目
の第1の命令フィールドが、オペレーション指定フィー
ルドと、任意の数のレジスタアドレス指定フィールドと
から構成される第1の命令フォーマット(1)のビット
割り付けを示す。
FIG. 10 shows a first instruction format (1) in which the first instruction field of the first byte, which is the minimum instruction word length, is composed of an operation designation field and an arbitrary number of register address designation fields. Shows the bit allocation of.

【0007】第1の命令フォーマット(1)-(a)は、第
1の命令フィールド内に2ビットのレジスタアドレス指
定フィールドを2フィールド含み、最小命令語長である
1バイトで構成される命令フォーマットであり、2つの
オペランドが指定可能な命令フォーマットである。
The first instruction format (1)-(a) includes an instruction format including two fields of a 2-bit register address designation field in the first instruction field and having a minimum instruction word length of 1 byte. , Which is an instruction format in which two operands can be specified.

【0008】第1の命令フォーマット(1)-(b)は、第
1の命令フィールド内に2ビットのレジスタアドレス指
定フィールドを2フィールド含み、更に付加情報フィー
ルドを追加して、合計2バイト以上の命令語長を持つ命
令フォーマットである。
[0008] The first instruction format (1)-(b) includes two 2-bit register addressing fields in the first instruction field, and further adds an additional information field to make a total of 2 bytes or more. This is an instruction format having an instruction word length.

【0009】第1の命令フォーマット(1)-(c)は、第
1の命令フィールド内に2ビットのレジスタアドレス指
定フィールドを1つ含み、最小命令語長である1バイト
で構成される命令フォーマットであり、1つのオペラン
ドが指定可能な命令フォーマットである。
The first instruction format (1)-(c) includes one 2-bit register addressing field in the first instruction field, and is composed of 1 byte which is the minimum instruction word length. , Which is an instruction format in which one operand can be specified.

【0010】第1の命令フォーマット(1)-(d)は、第
1の命令フィールド内に2ビットのレジスタアドレス指
定フィールドを1フィールド含み、更に付加情報フィー
ルドを追加した2バイト以上の命令語長を持つ命令フォ
ーマットである。
The first instruction format (1)-(d) includes an instruction word length of 2 bytes or more in which the first instruction field includes one register address designating field of 2 bits and further includes an additional information field. The instruction format has

【0011】第1の命令フォーマット(1)-(e)は、第
1の命令フィールド内にレジスタアドレス指定フィール
ドを含まず、最小命令語長である1バイトで構成される
命令フォーマットであり、アドレスを用いたオペランド
指定不可能な命令フォーマットである。
The first instruction format (1)-(e) is an instruction format which does not include the register address designation field in the first instruction field and is composed of 1 byte which is the minimum instruction word length. This is an instruction format that cannot use operands.

【0012】第1の命令フォーマット(1)-(f)は、第
1の命令フィールド内にレジスタアドレス指定フィール
ドを含まず、更に付加情報フィールドを追加した2バイ
ト以上の命令語長を持つ命令フォーマットである。
The first instruction format (1)-(f) has an instruction format that does not include a register addressing field in the first instruction field and has an instruction word length of 2 bytes or more in which an additional information field is added. It is.

【0013】図11は、図10で示された個々のビット
割り付けについて、具体的な命令のリストの一部を示し
たものである。左側に命令のニーモニックを、右側に命
令の動作を各々示している。
FIG. 11 shows a part of a specific instruction list for each bit allocation shown in FIG. The mnemonic of the instruction is shown on the left side, and the operation of the instruction is shown on the right side.

【0014】図12は、最小命令語長である1バイト目
の第1の命令フィールドが命令語長指定フィールドから
なり、第2の命令フィールドが、オペレーション指定フ
ィールドと、任意の数のレジスタアドレス指定フィール
ドとから構成される第1の命令フォーマット(2)のビ
ット割り付けを示したものである。
FIG. 12 shows that the first instruction field of the first byte, which is the minimum instruction word length, is composed of an instruction word length designation field, and the second instruction field is composed of an operation designation field and an arbitrary number of register address designations. FIG. 9 shows bit assignment of a first instruction format (2) composed of fields.

【0015】第1の命令フォーマット(2)-(a)は、第
2の命令フィールド内に2ビットのレジスタアドレス指
定フィールドを2フィールド含み、2バイトで構成され
る命令フォーマットであり、2つのオペランドが指定可
能な命令フォーマットである。
The first instruction format (2)-(a) is an instruction format including two fields of a 2-bit register address designation field in the second instruction field and composed of two bytes, and has two operands. Is an instruction format that can be specified.

【0016】第1の命令フォーマット(2)-(b)は、第
2の命令フィールド内に2ビットのレジスタアドレス指
定フィールドを2フィールド含み、更に付加情報フィー
ルドを追加して、合計3バイト以上の命令語長を持つ命
令フォーマットである。
The first instruction format (2)-(b) includes two 2-bit register addressing fields in the second instruction field, and further adds an additional information field to make a total of 3 bytes or more. This is an instruction format having an instruction word length.

【0017】第1の命令フォーマット(2)-(c)は、第
2の命令フィールド内に2ビットのレジスタアドレス指
定フィールドを1つ含み、2バイトで構成される命令フ
ォーマットであり、1つのオペランドが指定可能な命令
フォーマットである。
The first instruction format (2)-(c) includes one 2-bit register addressing field in the second instruction field, and is an instruction format composed of 2 bytes, and has one operand. Is an instruction format that can be specified.

【0018】第1の命令フォーマット(2)-(d)は、第
2の命令フィールド内に2ビットのレジスタアドレス指
定フィールドを1フィールド含み、更に付加情報フィー
ルドを追加した3バイト以上の命令語長を持つ命令フォ
ーマットである。
The first instruction format (2)-(d) includes an instruction word length of 3 bytes or more in which the second instruction field includes one register address designating field of 2 bits and further includes an additional information field. The instruction format has

【0019】第1の命令フォーマット(2)-(e)は、第
2の命令フィールド内にレジスタアドレス指定フィール
ドを含まず、2バイトで構成される命令フォーマットで
あり、アドレスを用いたオペランド指定が不可能な命令
フォーマットである。
The first instruction format (2)-(e) is an instruction format composed of two bytes without including the register address designation field in the second instruction field. This is an impossible instruction format.

【0020】第1の命令フォーマット(2)-(f)は、第
2の命令フィールド内にレジスタアドレス指定フィール
ド含まず、更に、付加情報フィールドを追加した2バイ
ト以上の命令語長を持つ命令フォーマットである。
The first instruction format (2)-(f) does not include the register address designation field in the second instruction field, and further has an instruction word length of 2 bytes or more with an additional information field added. It is.

【0021】図13は、図12で示された個々のビット
割り付けについて、具体的な命令のリストの一部を示し
たものである。左側に命令のニーモニックを、右側に命
令の動作を各々示している。
FIG. 13 shows a part of a specific instruction list for each bit allocation shown in FIG. The mnemonic of the instruction is shown on the left side, and the operation of the instruction is shown on the right side.

【0022】従って、前記図10から図13に示した第
1の命令フォーマットは、第1の命令フィールドを基本
命令語長とし、第1から第Mの命令フィールドを最長命
令語長Mとして、N命令語長(Nは1〜M間での整数)
の可変長命令を特定するものであって、最小命令語長が
1バイトであるという他にない特徴を備え、プログラム
サイズの縮小に適した命令フォーマットとなっている。
Therefore, in the first instruction format shown in FIGS. 10 to 13, the first instruction field has a basic instruction word length, the first to Mth instruction fields have a maximum instruction word length M, and N Instruction word length (N is an integer between 1 and M)
This has an unique feature that the minimum instruction word length is 1 byte, and has an instruction format suitable for reducing the program size.

【0023】図14は、本データ処理装置に備える第1
のレジスタファイル220を示す。この第1のレジスタ
ファイル220は、4個のアドレスレジスタA0〜A3
と、4個のデータレジスタD0〜D3と、スタックポイ
ンタSP223と、内部のステータス情報及び制御情報
を保持するPSW(Processor Status Word)224と、プロ
グラムカウンタPC225とを含む。
FIG. 14 shows a first example of the data processing apparatus.
Is shown in FIG. The first register file 220 includes four address registers A0 to A3.
, Four data registers D0 to D3, a stack pointer SP223, a PSW (Processor Status Word) 224 holding internal status information and control information, and a program counter PC225.

【0024】更に、図15は、前記第1のレジスタファ
イル220のアドレスレジスタA0〜A3及びデータレ
ジスタD0〜D3へのアクセスについて、より詳細に示
した図である。同図は、命令の中で指定されるレジスタ
名と、レジスタアドレス指定フィールドで指定される命
令コードでのビット割り付けと、物理的なレジスタにア
クセスするための物理的なレジスタ番号、及びアクセス
する対象となる物理的なレジスタ名を一覧にして示した
ものである。
FIG. 15 is a diagram showing the access to the address registers A0 to A3 and the data registers D0 to D3 of the first register file 220 in more detail. The figure shows the register name specified in the instruction, the bit assignment in the instruction code specified in the register address specification field, the physical register number for accessing the physical register, and the access target. Is a list of physical register names.

【0025】図15に示すように、第1の命令フォーマ
ットにおいては、4個のアドレスレジスタA0〜A3へ
アクセスするために命令内に指定される命令アドレス指
定フィールドと、4個のデータレジスタD0〜D3へア
クセスするために命令内に指定される命令アドレス指定
フィールドとは、全く同一である。即ち、レジスタのア
ドレスを指定するために2ビット命令アドレス指定フィ
ールドを使用し、命令動作そのものでアドレスレジスタ
にアクセスするか、データレジスタにアクセスするかを
区別させている。
As shown in FIG. 15, in the first instruction format, an instruction addressing field specified in an instruction to access four address registers A0 to A3 and four data registers D0 to D3 are provided. The instruction addressing field specified in the instruction to access D3 is exactly the same. That is, a 2-bit instruction addressing field is used to specify the address of the register, and it is distinguished whether the instruction operation itself accesses the address register or the data register.

【0026】次に、本アーキテクチャの基本命令フォー
マットである前記図10及び図12の第1の命令フォー
マットに対して、追加拡張する第2の命令フォーマット
のビット割り付けを図16に示す。
Next, FIG. 16 shows the bit assignment of the second instruction format that is additionally extended with respect to the first instruction format of FIGS. 10 and 12 which is the basic instruction format of the present architecture.

【0027】図16に示した第2の命令フォーマットの
ビット割り付けは、最小命令語長である1バイト目の第
1の命令フィールドが命令語長指定フィールドからな
り、第2及び第3の命令フィールドが、オペレーション
指定フィールドと、任意の数のレジスタアドレス指定フ
ィールドとから構成される。第2の命令フォーマットに
おけるレジスタアドレス指定フィールドは4ビットから
構成される。
In the bit assignment of the second instruction format shown in FIG. 16, the first instruction field of the first byte, which is the minimum instruction word length, comprises an instruction word length designation field, and the second and third instruction fields Consists of an operation specification field and an arbitrary number of register address specification fields. The register addressing field in the second instruction format is composed of 4 bits.

【0028】図16において、第2の命令フォーマット
(a)は、第3の命令フィールド内に4ビットのレジス
タアドレス指定フィールドを2フィールド含み、3バイ
トで構成される命令フォーマットであり、2つのオペラ
ンドが指定可能な命令フォーマットである。
In FIG. 16, the second instruction format (a) is an instruction format that includes two fields of a 4-bit register address designation field in the third instruction field and is composed of 3 bytes. Is an instruction format that can be specified.

【0029】第2の命令フォーマット(b)は、第3の
命令フィールド内に4ビットのレジスタアドレス指定フ
ィールドを2フィールド含み、更に、付加情報フィール
ドを追加して、合計4バイト以上の命令語長を持つ命令
フォーマットである。
The second instruction format (b) includes two 4-bit register addressing fields in the third instruction field, and further adds an additional information field to make the instruction word length more than 4 bytes in total. The instruction format has

【0030】第2の命令フォーマット(c)は、第3の
命令フィールド内に4ビットのレジスタアドレス指定フ
ィールドを1つ含み、3バイトで構成される命令フォー
マットであり、1つのオペランドが指定可能な命令フォ
ーマットである。
The second instruction format (c) is an instruction format including one 4-bit register address specification field in the third instruction field and composed of three bytes, and one operand can be specified. Instruction format.

【0031】第2の命令フォーマット(d)は、第3の
命令フィールド内に4ビットのレジスタアドレス指定フ
ィールドを1フィールド含み、更に、付加情報フィール
ドを追加した4バイト以上の命令語長を持つ命令フォー
マットである。
The second instruction format (d) includes an instruction having a 4-bit register address designating field in the third instruction field, and further having an instruction word length of 4 bytes or more obtained by adding an additional information field. Format.

【0032】従って、前記第2の命令フォーマットも、
第1の命令フィールドを基本命令語長とし、第1から第
Mの命令フィールドを最長命令語長Mとして、N命令語
長(Nは1〜M間での整数)の可変長命令を特定する。
Therefore, the second instruction format is also:
A variable length instruction having an N instruction word length (N is an integer between 1 and M) is specified, with the first instruction field as the basic instruction word length and the first through Mth instruction fields as the longest instruction word length M. .

【0033】図17は、図16で示された個々のビット
割り付けについて、具体的な命令のリストの一部を示し
たものである。左側に命令のニーモニックを、右側に命
令の動作を各々示している。ニーモニックの中で、Rm、
Rn、又はRiは、レジスタアドレスの指定を表すが、指定
できるレジスタとして、図18に示されるような第2の
レジスタファイル120が定義され、4個のアドレスレ
ジスタA0〜A3、4個のデータレジスタD0〜D3、
及び8個の拡張レジスタE0〜E7から構成される16
個の汎用レジスタである。更に、この第2のレジスタフ
ァイル120は、スタックポインタSP122と、内部の
ステータス情報及び制御情報を保持するPSW(Processor
Status Word)123と、プログラムカウンタPC124と
を含んでいる。
FIG. 17 shows a part of a specific instruction list for each bit allocation shown in FIG. The mnemonic of the instruction is shown on the left side, and the operation of the instruction is shown on the right side. In the mnemonic, Rm,
Rn or Ri indicates the designation of a register address. A second register file 120 as shown in FIG. 18 is defined as a register that can be designated, and four address registers A0 to A3 and four data registers D0-D3,
And 16 comprising eight extension registers E0 to E7.
General purpose registers. Further, the second register file 120 includes a stack pointer SP 122 and a PSW (Processor) holding internal status information and control information.
Status Word) 123 and a program counter PC 124.

【0034】図19は、第1の命令フォーマットで定義
された命令を実行する際に、命令の中で指定されるレジ
スタ名と、レジスタアドレス指定フィールドで指定され
る命令コード上でのビット割り付けと、物理的なレジス
タにアクセスするための物理的なレジスタ番号、及び、
アクセスする対象となる物理的なレジスタ名を一覧にし
て示したものである。第1の命令フォーマットでは、レ
ジスタ指定フィールドは2ビットしかないが、汎用レジ
スタは16個で4ビットのアドレスでアクセスする必要
がある関係から、アドレスの変換をする必要がある。例
えば、アドレスレジスタA0をアクセスする際には、物
理的なアドレス番号として“1000”が、データレジ
スタD1をアクセスする際には、物理的なアドレス番号
として、“1101”を生成し、汎用レジスタファイル
121に出力する必要がある。
FIG. 19 shows that when executing an instruction defined in the first instruction format, the register name specified in the instruction, the bit assignment on the instruction code specified in the register address specification field, and the like. , The physical register number to access the physical register, and
This is a list of physical register names to be accessed. In the first instruction format, the register specification field has only two bits, but the address needs to be converted because there are 16 general-purpose registers that need to be accessed with 4-bit addresses. For example, when accessing the address register A0, “1000” is generated as a physical address number, and when accessing the data register D1, “1101” is generated as a physical address number. It is necessary to output to 121.

【0035】図20は、第2の命令フォーマットで定義
された命令を実行する際に、命令の中で指定されるレジ
スタ名と、レジスタアドレス指定フィールドで指定され
る命令コード上でのビット割り付けと、物理的なレジス
タにアクセスするための物理的なレジスタ番号、及び、
アクセスする対象となる物理的なレジスタ名を一覧にし
て示したものである。第2の命令フォーマットでは、4
ビットのレジスタアドレス指定フィールドを有している
ので、その4ビットをそのまま物理的なレジスタ番号と
して指定することになる。
FIG. 20 is a diagram showing, when an instruction defined in the second instruction format is executed, the register name specified in the instruction, the bit assignment on the instruction code specified in the register address specification field, and the like. , The physical register number to access the physical register, and
This is a list of physical register names to be accessed. In the second instruction format, 4
Since there is a register address specification field of bits, the four bits are directly specified as a physical register number.

【0036】[0036]

【発明が解決しようとする課題】本願発明者が特願平1
0−59680において提案したようなデータ処理装置
においては、従来のコンパイラが行っているように単に
レジスタをメモリよりも優先して資源割り付けを行う
と、以下のような問題が存在する。
SUMMARY OF THE INVENTION The present inventor has filed Japanese Patent Application No. Hei.
In a data processing device as proposed in Japanese Patent Application No. 0-59680, if resources are simply allocated with priority given to a register over a memory as performed by a conventional compiler, the following problems exist.

【0037】1) 第1のレジスタファイル(レジスタ資
源)に割り付けられた変数を第1の命令フォーマットで
記述された命令を使用して処理する場合と、第2のレジ
スタファイルに割り付けられた変数を第2の命令フォー
マットで記述された命令を使用して処理する場合とで命
令長が異なるため、両者の何れをも優先的に扱わず均一
に扱うことでは、命令コードサイズは最小にならない。
即ち、従来のコンパイラでは、各変数を第1のレジスタ
ファイルに優先的に割り付けるか、又は第2のレジスタ
ファイルに優先的に割り付けるかについて考慮していな
い。例えば、各変数をその出現順に第2のレジスタファ
イルに割り付け、これ等変数を第2の命令フォーマット
で記述された命令を使用して処理する場合には、第2の
命令フォーマットの命令長が第1の命令フォーマットの
命令長よりも長い以上、命令コードサイズは大きくな
る。
1) When the variables assigned to the first register file (register resources) are processed using the instructions described in the first instruction format, and when the variables assigned to the second register file are Since the instruction length is different between the case where the processing is performed using the instruction described in the second instruction format, the instruction code size does not become the minimum by treating both of them uniformly without prioritizing them.
That is, the conventional compiler does not consider whether each variable is preferentially assigned to the first register file or to the second register file. For example, if each variable is allocated to the second register file in the order of its appearance, and these variables are processed using an instruction described in the second instruction format, the instruction length of the second instruction format is The instruction code size increases as the instruction length becomes longer than the instruction length of the instruction format No. 1.

【0038】2) 第2の命令フォーマットで記述された
命令を使用して変数を処理する場合に対して、データを
メモリからレジスタに転送するデータ転送命令を含む命
令列では、第1の命令フォーマットを使用して変数を処
理した方が、命令数は増加しても命令長は短くなる場合
がある。従って、単純に、変数をメモリよりもレジスタ
資源に優先的に割り付けることでは、コードサイズは最
小にならない。
2) In the case where a variable is processed using an instruction described in the second instruction format, an instruction sequence including a data transfer instruction for transferring data from a memory to a register has a first instruction format. When processing variables using, the instruction length may become shorter even though the number of instructions increases. Therefore, simply allocating variables to register resources rather than memory does not minimize the code size.

【0039】本発明の目的は、命令フォーマットによっ
て扱えるレジスタ資源が異なり、且つ使用する命令フォ
ーマットに応じて命令長が異なる命令セットを有するプ
ロセッサにおいて、命令コードサイズが小さい機械語プ
ログラムを生成するコンパイラを提供することにある。
An object of the present invention is to provide a compiler that generates a machine language program with a small instruction code size in a processor having an instruction set in which register resources that can be handled differ according to the instruction format and instruction lengths differ according to the instruction format used. To provide.

【0040】[0040]

【課題を解決するための手段】前記課題を解決するため
に、本発明では、頻繁に使用される変数が、命令長の短
いフォーマットで使用可能なレジスタに割り付けられ、
且つそれ等変数が前記命令長の短いフォーマットを使用
して処理される機械語プログラムを得るようにする。
According to the present invention, a frequently used variable is assigned to a register which can be used in a format having a short instruction length.
And obtaining a machine language program in which those variables are processed using the short instruction length format.

【0041】すなわち、請求項1記載の発明のコンパイ
ラは、複数の命令からなるソースプログラムを入力し、
このソースプログラムを機械語プログラムに翻訳するコ
ンパイラであって、前記ソースプログラム中の各変数
を、第1の命令フォーマットで記述された命令を使用し
て第1のレジスタ資源に割り付けた場合の命令列の長さ
を算出する第1の命令列長算出手段と、前記ソースプロ
グラム中の各変数を、前記第1の命令フォーマットとは
命令長が異なる第2の命令フォーマットで記述された命
令を使用して、前記第1のレジスタ資源とは異なる第2
のレジスタ資源に割り付けた場合の命令列の長さを算出
する第2の命令列長算出手段とを備え、前記第1及び第
2の命令長算出手段が算出した命令長算出結果を用いて
資源割り付けを行うことを特徴とする。
That is, the compiler according to the first aspect of the present invention inputs a source program including a plurality of instructions,
A compiler for translating this source program into a machine language program, wherein an instruction sequence in which each variable in the source program is assigned to a first register resource using an instruction described in a first instruction format Using a first instruction sequence length calculating means for calculating the length of each instruction, and using each instruction in the source program as an instruction described in a second instruction format having an instruction length different from the first instruction format. A second register resource different from the first register resource.
Second instruction string length calculating means for calculating the length of the instruction string when the instruction string is allocated to the register resources of the first and second register resources, and using the instruction length calculation results calculated by the first and second instruction length calculating means. Assigning is performed.

【0042】請求項2記載の発明は、前記請求項1記載
のコンパイラにおいて、前記ソースプログラム中の各変
数を、メモリに割り付けた場合の命令列の長さを算出す
る第3の命令列長算出手段を備え、前記第1、第2及び
第3の命令長算出手段が算出した命令長算出結果を用い
て資源割り付けを行うことを特徴とする。
According to a second aspect of the present invention, in the compiler according to the first aspect, a third instruction sequence length calculation for calculating an instruction sequence length when each variable in the source program is allocated to a memory. Means for allocating resources using the instruction length calculation results calculated by the first, second, and third instruction length calculation means.

【0043】請求項3記載の発明は、前記請求項1記載
のコンパイラにおいて、前記第1及び第2の命令長算出
手段が算出した命令長算出結果を比較して、命令列長が
小さい資源割り付けを行うことを特徴とする。
According to a third aspect of the present invention, in the compiler according to the first aspect, the instruction length calculation results calculated by the first and second instruction length calculating means are compared, and resource allocation with a small instruction sequence length is performed. Is performed.

【0044】請求項4記載の発明は、前記請求項1記載
のコンパイラにおいて、前記第1のレジスタ資源は、前
記第2のレジスタ資源の一部であることを特徴とする。
According to a fourth aspect of the present invention, in the compiler according to the first aspect, the first register resource is a part of the second register resource.

【0045】請求項5記載の発明は、前記請求項4記載
のコンパイラにおいて、前記第1の命令フォーマットの
命令長は、前記第2のフォーマット命令フォーマットの
命令長より短いことを特徴とする。
According to a fifth aspect of the present invention, in the compiler according to the fourth aspect, an instruction length of the first instruction format is shorter than an instruction length of the second format instruction format.

【0046】請求項6記載の発明は、前記請求項1記載
のコンパイラにおいて、前記ソースプログラム中の各変
数の中で、使用頻度が高い変数を優先的に第1の命令フ
ォーマットで記述された命令を使用して第1のレジスタ
資源に割り付けることを特徴とする。
According to a sixth aspect of the present invention, there is provided the compiler according to the first aspect, wherein, among the variables in the source program, a frequently used variable is preferentially described in the first instruction format. Is allocated to the first register resource.

【0047】請求項7記載の発明は、前記請求項6記載
のコンパイラにおいて、前記ソースプログラム中の各変
数について、前記第1のレジスタ資源に割り付けられた
変数を操作する場合には、前記第1の命令フォーマット
を優先的に使用してその操作を記述することを特徴とす
る。
According to a seventh aspect of the present invention, in the compiler according to the sixth aspect, when the variable assigned to the first register resource is manipulated for each variable in the source program, The operation is described by preferentially using the instruction format.

【0048】請求項8記載の発明は、前記請求項6記載
のコンパイラにおいて、前記プログラム中の各変数の中
で、使用頻度が高い変数、及びこの変数と共に使用され
る変数を、優先的に第1のレジスタ資源に割り付けるこ
とを特徴とする。
According to an eighth aspect of the present invention, in the compiler according to the sixth aspect, among the variables in the program, a variable having a high frequency of use and a variable used together with the variable are preferentially ranked first. One register resource is allocated.

【0049】請求項9記載の発明の記録媒体は、複数の
命令からなるソースプログラムを翻訳した機械語プログ
ラムを記録したコンピュータ読み取り可能な記録媒体で
あって、前記機械語プログラムは、第1のレジスタ資源
を用いて第1の命令フォーマットで記述された命令と、
前記第1のレジスタ資源とは異なる第2のレジスタ資源
を用いて、前記第1の命令フォーマットとは命令長が異
なる第2の命令フォーマットで記述された命令とが混在
し、前記第1の命令フォーマット及び第2の命令フォー
マットは前記命令中の特定の領域の値により識別される
ことを特徴とする。
A recording medium according to a ninth aspect of the present invention is a computer-readable recording medium storing a machine language program obtained by translating a source program including a plurality of instructions, wherein the machine language program has a first register. An instruction described in a first instruction format using resources;
Using a second register resource different from the first register resource, instructions described in a second instruction format having an instruction length different from the first instruction format are mixed, and the first instruction The format and the second instruction format are characterized by being identified by a value of a specific area in the instruction.

【0050】以上の構成から、本発明では、命令フォー
マットの種類に応じて扱えるレジスタ資源が異なり、且
つ命令フォーマットの種類に応じて命令長が異なる命令
セットを有するプロセッサにおいて、各変数を第1の命
令フォーマットで記述された命令を使用して第1のレジ
スタ資源に割り付けた場合の命令列長の長さと、各変数
を第2の命令フォーマットで記述された命令を使用して
第2のレジスタ資源に割り付けた場合の命令列長の長さ
とが算出され、その算出結果に応じて適切な資源割り付
けが行われるので、コードサイズの小さい機械語プログ
ラムが生成される。
With the above arrangement, according to the present invention, in a processor having an instruction set in which register resources that can be handled differ according to the type of instruction format and instruction lengths differ according to the type of instruction format, each variable is set to the first value. The length of the instruction string length when the instruction is described in the instruction format and the variable is assigned to the first register resource, and each variable is stored in the second register resource using the instruction described in the second instruction format. Is calculated, and an appropriate resource allocation is performed according to the calculation result, so that a machine language program with a small code size is generated.

【0051】[0051]

【発明の実施の形態】以下、本発明の実施の形態につい
て、図1から図5を用いて説明する。
DESCRIPTION OF THE PREFERRED EMBODIMENTS Embodiments of the present invention will be described below with reference to FIGS.

【0052】最初に本発明におけるコンパイラが対象と
するプロセッサの機械語命令セットについてであるが、
命令のフォーマットによって扱えるレジスタ資源が異な
り、且つ、命令のフォーマットに応じて命令長が異なる
ような機械語命令セットを有するプロセッサとして、特
願平10−59680において提案した2種の命令フォ
ーマットを有するデータ処理装置とする。
First, regarding the machine language instruction set of the processor targeted by the compiler in the present invention,
As a processor having a machine language instruction set in which different register resources can be handled according to the instruction format and the instruction length varies according to the instruction format, data having two types of instruction formats proposed in Japanese Patent Application No. 10-59680. Processing equipment.

【0053】図1は、本発明の実施の形態におけるコン
パイラの構成図である。コンパイラは、構文解析手段1
と、最適化手段2と、資源割り付け手段3と、コード生
成手段4とで構成されている。
FIG. 1 is a configuration diagram of a compiler according to the embodiment of the present invention. The compiler uses the parsing means 1
, An optimization unit 2, a resource allocation unit 3, and a code generation unit 4.

【0054】構文解析手段1は、ファイルとして記憶さ
れているソースプログラム5の字句解析、構文解析、及
び意味解析を行う。解析結果は、中間言語プログラムと
して出力される。
The syntactic analysis means 1 performs lexical analysis, syntactic analysis and semantic analysis of the source program 5 stored as a file. The analysis result is output as an intermediate language program.

【0055】最適化手段2は、最終的に生成される機械
語プログラム6のプログラムサイズを削減し、実行時間
を短縮させる目的で中間言語プログラムの最適化を行
う。
The optimizing means 2 optimizes the intermediate language program for the purpose of reducing the program size of the finally generated machine language program 6 and shortening the execution time.

【0056】資源割り付け手段3は、プログラムの変数
の生存区間を求め、生存区間毎に各変数に対して資源で
あるレジスタやメモリを割り付けると共に、同一動作に
対しての最適な命令の割り付けも行う。
The resource allocating means 3 determines the live range of the program variable, allocates a register or memory as a resource to each variable for each live range, and also allocates an optimal instruction for the same operation. .

【0057】コード生成手段4は、最適化された中間言
語プログラムを、資源割り付け手段3の割り付け結果に
従って、ターゲットマシンの機械語命令に変換し、機械
語プログラム6として出力する。
The code generation means 4 converts the optimized intermediate language program into machine language instructions of the target machine according to the allocation result of the resource allocation means 3 and outputs it as a machine language program 6.

【0058】尚、構文解析手段1、最適化手段2、コー
ド生成手段4については公知であるので、詳細な説明を
省略する。
Since the syntax analysis means 1, the optimization means 2, and the code generation means 4 are known, detailed description will be omitted.

【0059】図2は、本発明の実施の形態におけるコン
パイラの資源割り付け手段3の構成図である。同図にお
いて、31は各変数に対しての生存区間を判定する生存
区間判定部である。32は変数を第1の命令フォーマッ
トを持つ命令群を用いてレジスタに割り付けた場合の命
令列長を算出する第1の命令長算出手段である。第1の
命令フォーマットでは、一部のレジスタしか扱うことが
できない。33は変数を第2の命令フォーマットを持つ
命令群を用いてレジスタに割り付けた場合の命令長を算
出する第2の命令長算出手段である。第2の命令フォー
マットでは全てのレジスタ資源を扱うことができる。3
4は変数をメモリに割り付けた場合の命令長を算出する
第3の命令長算出手段である。35は生存区間判定部3
1の生存区間の判定結果と、第1から第3の命令長算出
手段32〜34に応じて、変数資源の割り付けを行う変
数資源割り付け部である。36は資源割り付け手段3の
制御部36を除く全体を制御する制御部である。
FIG. 2 is a configuration diagram of the resource allocating means 3 of the compiler according to the embodiment of the present invention. In the figure, reference numeral 31 denotes a live range determination unit that determines a live range for each variable. Reference numeral 32 denotes first instruction length calculating means for calculating an instruction sequence length when variables are assigned to registers using an instruction group having a first instruction format. In the first instruction format, only some registers can be handled. Reference numeral 33 denotes second instruction length calculation means for calculating an instruction length when a variable is assigned to a register using an instruction group having the second instruction format. The second instruction format can handle all register resources. 3
Reference numeral 4 denotes third instruction length calculation means for calculating an instruction length when a variable is allocated to a memory. Reference numeral 35 denotes a live range determination unit 3
1 is a variable resource allocating unit that allocates variable resources according to the determination result of one live range and the first to third instruction length calculating means 32 to 34. Reference numeral 36 denotes a control unit for controlling the entire resource allocation unit 3 except the control unit 36.

【0060】以上のように構成されたコンパイラの資源
割り付けについて、以下、図面を用いて、その動作を述
べる。図3は、本発明の実施の形態におけるコンパイラ
の制御部36の資源割り付けの処理フローを示したフロ
ーチャートである。
The operation of the resource allocation of the compiler configured as described above will be described below with reference to the drawings. FIG. 3 is a flowchart showing a processing flow of resource allocation of the control unit 36 of the compiler according to the embodiment of the present invention.

【0061】ここで、コンパイラの資源割付けを行う対
象とする中間コードプログラム例を図4に示す。図4に
示された中間コードs1〜s8を今回の資源割付けの対
象となる基本ブロックとする。説明を簡単にするため
に、ここでは、基本ブロック内の資源割り付けについて
説明するが、基本ブロックを越えての資源割付けにおい
ても同様に説明できる。
FIG. 4 shows an example of an intermediate code program to which the compiler allocates resources. The intermediate codes s1 to s8 shown in FIG. 4 are set as basic blocks to be subjected to the current resource allocation. For the sake of simplicity, here, resource allocation within a basic block will be described, but the same can be said for resource allocation beyond a basic block.

【0062】また、説明を簡単にするために、レジスタ
資源の割り付けに関しては、以下の条件で行うものとす
る。
For the sake of simplicity, the allocation of register resources is performed under the following conditions.

【0063】1)第1の命令フォーマットで操作できる
レジスタ資源(A0〜A3,D0〜D3)の中で、アド
レスレジスタA0〜A3については、ポインタとして使
用するものとし、データ変数を格納しないものとする。
1) Among the register resources (A0 to A3, D0 to D3) that can be operated in the first instruction format, address registers A0 to A3 are used as pointers and do not store data variables. I do.

【0064】2)第1の命令フォーマットで操作できる
レジスタ資源(A0〜A3,D0〜D3)の中で、デ−
タレジスタD0〜D3は、全てデ−タ変数の格納及び操
作に使用できるが、そのうち、レジスタD0、D1につ
いてはワークレジスタとして使用し、変数を割り付けな
いものとする。
2) Among register resources (A0 to A3, D0 to D3) that can be operated in the first instruction format,
The data registers D0 to D3 can all be used for storing and manipulating data variables. Of these, the registers D0 and D1 are used as work registers and no variables are assigned.

【0065】3)第2の命令フォーマットで操作できる
レジスタ資源(A0〜A3,D0〜D3、E0〜E7)
の中で、拡張レジスタE0〜E7については、データで
もアドレスでも自由に使用できるものとする。
3) Register resources (A0-A3, D0-D3, E0-E7) that can be operated in the second instruction format
Of the extension registers E0 to E7, data and addresses can be freely used.

【0066】これ等の条件は、説明を簡単にするために
定めたものであって、本発明に何らの制約を与えるもの
ではない。
These conditions are set for the sake of simplicity, and do not impose any restrictions on the present invention.

【0067】このフローチャートに従って、図4におけ
る中間コードプログラムについて資源割り付けを行う場
合の処理について説明する。
A process for allocating resources to the intermediate code program in FIG. 4 will be described with reference to this flowchart.

【0068】先ず、ステップ301では、基本ブロック
内部の全ての変数について、個々の変数の生存区間や参
照頻度を調べる。ここで、レジスタ割付けの対象となる
のは、第1の命令フォーマットで操作できるレジスタ資
源のみ、具体的には、レジスタA0〜A3、D0〜D3
のみである。その結果によって、変数資源割付部35が
第1の命令フォーマットで操作できるレジスタ資源に対
して、レジスタ割付け可能かどうかを検査する。ここで
は、どのような手法を用いてこれ等のレジスタに変数を
割り付けるかということが重要ではなく、同一のオペレ
ーションに対して第1の命令フォーマットの命令長の方
が第2の命令フォーマットの命令長に比べて小さいの
で、第1の命令フォーマットで扱えるレジスタ資源のみ
を対象にしたレジスタ資源割り付けを行うということが
最も重要である。
First, in step 301, the life span and reference frequency of each variable are checked for all variables in the basic block. Here, register allocation is performed only for register resources that can be operated in the first instruction format, specifically, registers A0 to A3 and D0 to D3.
Only. Based on the result, the variable resource allocating unit 35 checks whether register allocation is possible for register resources that can be operated in the first instruction format. Here, it is not important how to assign variables to these registers, and the instruction length of the first instruction format is larger than the instruction length of the second instruction format for the same operation. Since it is smaller than the length, it is most important that register resources be allocated only to register resources that can be handled in the first instruction format.

【0069】次に、ステップ302では、ステップ30
1の検査結果をもとに、第1の命令フォーマットで操作
できるレジスタ資源のみで全ての変数が資源割付け可能
かどうかを判断する。
Next, in step 302, step 30
Based on the check result of No. 1, it is determined whether or not all variables can be allocated resources only with register resources that can be operated in the first instruction format.

【0070】可能な場合は、第1の命令フォーマットで
操作できるレジスタ資源のみに変数を割り付けて、資源
割付けを終了する(ステップ303)。
If possible, variables are allocated only to register resources that can be operated in the first instruction format, and resource allocation ends (step 303).

【0071】通常の基本ブロック内には、多くの変数が
存在するので、ほとんどの場合は、第1の命令フォーマ
ットで操作できるレジスタ資源に割り付けられない変数
が存在する。ステップ302では、第1の命令フォーマ
ットで操作できるレジスタ資源で全ての変数が割り付け
られない場合、先ず、第1の命令フォーマットで操作で
きるレジスタ資源を優先的に割り付けを行う。この優先
的な割り付け処理を以下に説明する。
Since there are many variables in a normal basic block, in most cases, there are variables that cannot be allocated to register resources that can be operated in the first instruction format. In step 302, if all variables cannot be assigned with register resources that can be operated in the first instruction format, first, register resources that can be operated in the first instruction format are assigned with priority. The priority assignment processing will be described below.

【0072】図5は、ステップ301で、第1の命令フ
ォーマットで操作できるレジスタ資源に割り付ける変数
を決定するために調べた、基本ブロック内での変数の生
存区間と、参照頻度とを示した図である。この結果、最
も参照頻度の高い変数であるp1とp2を第1の命令フ
ォーマットで操作できるレジスタの内、レジスタD2と
D3に割り付けるものとする。ここで、どの変数をレジ
スタに割り付けるかどうかの決定は、扱えるレジスタ資
源の数と、各変数の生存区間、参照頻度によって決定さ
れたものである。この場合、既述した条件によりレジス
タD0及びD1は使用できないので、使用できるレジス
タ資源はレジスタD2とD3との2つであり、最も使用
頻度の高い2つの変数を割り付けている。
FIG. 5 is a diagram showing the lifespan of variables in the basic block and the reference frequency, which were examined in step 301 to determine variables to be allocated to register resources that can be operated in the first instruction format. It is. As a result, variables p1 and p2, which are the most frequently referred, are assigned to registers D2 and D3 among the registers that can be operated in the first instruction format. Here, the decision as to which variable is to be assigned to a register is made based on the number of register resources that can be handled, the live range of each variable, and the reference frequency. In this case, since the registers D0 and D1 cannot be used due to the above-described conditions, the register resources that can be used are two registers D2 and D3, and the two most frequently used variables are allocated.

【0073】次に、ステップ304では、変数資源割付
部35が第1の命令フォーマットで操作できるレジスタ
資源に割り付けできなかった残りの変数について、第1
の命令フォーマットでは操作できず、第2の命令フォー
マットによってのみ操作できるレジスタ資源、具体的に
は、拡張レジスタE0〜E7に各変数を割り付けるか、
メモリ資源に割り付けるかの第1の組み合わせ(資源の
割り付け)について場合分けを行う。
Next, in step 304, the variable resource allocating unit 35 assigns the first variable to the first
Register resources that cannot be operated in the instruction format of the second instruction format and can be operated only by the second instruction format, specifically,
The first combination (resource allocation) of allocating to memory resources is classified.

【0074】更に、ステップ304では、制御部36が
第1の組み合わせの中でレジスタ資源に割り付けた場合
には、ワークレジスタD0、D1を利用して、第1の命
令フォーマットを使用するのが適当か、又はワークレジ
スタD0、D1を利用せずに第2の命令フォーマットを
使用するのが適当かも含めて、第2の組み合わせ(命令
の割り付け)を考える。拡張レジスタE0〜E7及びレ
ジスタD2、D3を使用した特定の第1の組み合わせに
対する第2の組み合わせの例を図7〜図9に示す。これ
等の図面の説明は後に詳述する。最終的には、全ての組
み合わせについて、命令列長を算出するので、ここで、
どの組み合わせを選択するかは問題にならない。
Further, in step 304, when the control unit 36 has allocated the register resources in the first combination, it is appropriate to use the first instruction format using the work registers D0 and D1. Alternatively, a second combination (allocation of instructions) is considered, including whether it is appropriate to use the second instruction format without using the work registers D0 and D1. FIGS. 7 to 9 show examples of the second combination for the specific first combination using the extension registers E0 to E7 and the registers D2 and D3. The description of these drawings will be described later in detail. Ultimately, the instruction sequence length is calculated for all combinations.
It does not matter which combination you choose.

【0075】以下に説明するステップ305〜ステップ
307では、前記第2の組み合わせの各々(図7〜図
9)に対して命令列長の算出を行う。
In steps 305 to 307 described below, the instruction sequence length is calculated for each of the second combinations (FIGS. 7 to 9).

【0076】つまり、ステップ305では、第1の命令
フォーマットを使用してレジスタに資源割り付けした命
令列長を算出する。ステップ306では、第2の命令フ
ォーマットを使用してレジスタに資源割り付けした命令
列長を算出する。
That is, in step 305, the length of the instruction sequence allocated to the registers is calculated using the first instruction format. In step 306, the length of the instruction sequence allocated to the registers is calculated using the second instruction format.

【0077】同様に、ステップ307では、レジスタ資
源ではなく、メモリ資源に変数を割り付け、第1の命令
フォーマットを割り付けた場合の命令列長を算出する。
ここでは、説明を簡単にするために、メモリ資源に変数
を割り付けた場合のアドレスは、16ビットの絶対アド
レスで指定できるものとし、その変数に対してのメモリ
/レジスタ間移動命令は、3バイトとする。またステッ
プ307では、レジスタ資源ではなく、メモリ資源に変
数を割り付け、第2の命令フォーマットを割り付けた場
合の命令列長を算出する。ここでは、説明を簡単にする
ために、メモリ資源に変数を割り付けた場合のアドレス
は、16ビットの絶対アドレスで指定できるものとし、
その変数に対してのメモリ/レジスタ間移動命令は、4
バイトとする。
Similarly, in step 307, variables are allocated not to the register resources but to the memory resources, and the instruction sequence length when the first instruction format is allocated is calculated.
Here, for simplicity of description, it is assumed that an address when a variable is assigned to a memory resource can be specified by an absolute address of 16 bits, and a memory / register transfer instruction for the variable is 3 bytes. And In step 307, variables are allocated to memory resources instead of register resources, and the instruction sequence length when the second instruction format is allocated is calculated. Here, for the sake of simplicity, it is assumed that an address when a variable is assigned to a memory resource can be specified by an absolute address of 16 bits.
The memory / register move instruction for the variable is 4
Byte.

【0078】ステップ308では、前記ステップ305
〜ステップ307の結果を用いて、この組み合わせにお
ける基本ブロック全体の命令列長を算出する。
In step 308, the step 305 is executed.
The instruction sequence length of the entire basic block in this combination is calculated using the result of Step 307.

【0079】前記処理を全ての組み合わせにおいて実行
し(ステップ309)、ステップ310では、その結
果、基本ブロック内の命令列長が最小となる組み合わせ
を選択する)。
The above processing is executed for all combinations (step 309), and in step 310, the combination that results in the minimum instruction sequence length in the basic block is selected).

【0080】以上のような処理で機械語プログラムサイ
ズを最小化するコンパイラの処理について、図を用いて
更に詳細に説明する。
The processing of the compiler for minimizing the machine language program size by the above processing will be described in more detail with reference to the drawings.

【0081】先ず、図6に、各変数のレジスタ割付けに
ついて第1の命令フォーマットによってアクセス可能な
レジスタ資源と、それ以外のレジスタ資源について、優
先度を付けずに出現順にレジスタ資源への割り付けを行
った場合(従来の方法)の変数の資源割付けと、その割
り付けに対応して命令を割り付けた場合の機械語命令プ
ログラムを示す。この場合の基本ブロックに対する命令
列長は46バイトになる。
First, FIG. 6 shows that register resources which can be accessed by the first instruction format for register assignment of each variable and other register resources are assigned to register resources in the order of appearance without assigning priority. 2 shows a resource assignment of variables in a case where the instruction is assigned (conventional method), and a machine language instruction program when instructions are assigned in accordance with the assignment. In this case, the instruction sequence length for the basic block is 46 bytes.

【0082】次に、図7に、図5で示された変数の生存
区間と出現頻度をもとに、図3のステップ302の処理
により、第1の命令フォーマットで操作可能なレジスタ
のみ(この場合、具体的には、D2レジスタとD3レジ
スタ)に、優先的にレジスタ割付けを行い、その結果、
変数p1をレジスタD2に、変数p2をレジスタD3に
割り付けた場合の変数の資源割り付けと、その割り付け
に対応して命令を割り付けた場合の機械語命令プログラ
ムを示す。この場合の基本ブロックに対する命令列長は
42バイトとなり、図6で示した場合に比べて、4バイ
トのコードサイズの削減が図れていることが判る。
Next, FIG. 7 shows only the registers that can be operated in the first instruction format by the processing of step 302 in FIG. 3 based on the live ranges and the appearance frequencies of the variables shown in FIG. In this case, specifically, registers are preferentially assigned to the D2 register and the D3 register, and as a result,
A resource allocation of a variable when the variable p1 is allocated to the register D2 and a variable p2 is allocated to the register D3, and a machine language instruction program when an instruction is allocated corresponding to the allocation. In this case, the instruction sequence length for the basic block is 42 bytes, which indicates that the code size of 4 bytes can be reduced as compared with the case shown in FIG.

【0083】更に、図8に、図7で説明した場合とレジ
スタ資源の割り付け方は同様であるが、命令フォーマッ
トとして第2の命令フォーマットを選択する代りに第1
の命令フォーマットを選択して、命令の割り付け方を変
更した場合の機械語命令プログラムを示す。この場合、
基本命令ブロックに対するトータルの命令長自体は、図
7の場合より2バイト増加して、44バイトになってい
るが、個々の中間言語毎に機械語命令列長を比較してい
くと、中間言語s1及び中間言語s8に関しては、これ
等言語s1、s8が第1の命令フォーマットで記述され
た命令を含んで、各々、1バイトずつ機械語命令長が減
少していることが判る。ここで、中間言語s1では、使
用頻度の高い変数p1及びp2が第1のレジスタファイ
ル220内のレジスタD2、D3に各々割り付けられ
る。また、これ等変数p1、p2と共に使用される変数
t1も第1のレジスタファイル220内のワークレジス
タD0に一時的に割り付けられる。これにより、命令mo
v D2,D0 及び命令add D3,D0は、各々、第1の命令フォ
ーマットを使用して1バイトで記述される。
Further, in FIG. 8, the assignment of register resources is the same as that described in FIG. 7, but instead of selecting the second instruction format as the instruction format, the first instruction format is used.
2 shows a machine language instruction program when the instruction format is selected and the method of assigning instructions is changed. in this case,
The total instruction length of the basic instruction block itself is 44 bytes, which is 2 bytes larger than that of FIG. 7, but if the machine language instruction sequence length is compared for each intermediate language, the intermediate language Regarding s1 and the intermediate language s8, it can be seen that these languages s1 and s8 each include an instruction described in the first instruction format, and each machine language instruction length is reduced by one byte. Here, in the intermediate language s1, frequently used variables p1 and p2 are allocated to registers D2 and D3 in the first register file 220, respectively. The variable t1 used together with these variables p1 and p2 is also temporarily allocated to the work register D0 in the first register file 220. This gives the instruction mo
v D2, D0 and the instructions add D3, D0 are each described in one byte using the first instruction format.

【0084】最後に、図7及び図8で示した結果をもと
に、レジスタ資源の割り付け、及び命令の割り付けを最
適化した機械語命令プログラムを図9に示す。図9で
は、図7及び図8の各中間言語の中で機械語命令長が短
い方の中間言語、即ち、中間言語s2〜s7では図7の
中間言語s2〜s7が、中間言語s1、s8では図8の
中間言語s1、s8が採用される。尚、図7の中間言語
s2、s3と図8の中間言語s2、s3とは機械語命令
長が同一であるが、図7の中間言語s2、s3、即ち命
令数が少なくて高速処理の可能な方の中間言語が採用さ
れる。その結果、図9では、図7の状態から、更に2バ
イトのコード削減が実現されており、図3及び図4で示
した中間言語プログラムに対して、最もコードサイズの
小さい機械語命令プログラムが生成されている。
Finally, FIG. 9 shows a machine instruction program in which the allocation of register resources and the allocation of instructions are optimized based on the results shown in FIGS. In FIG. 9, the intermediate language having a shorter machine language instruction length among the intermediate languages of FIGS. 7 and 8, that is, the intermediate languages s2 to s7 of FIG. Uses the intermediate languages s1 and s8 of FIG. Note that the intermediate languages s2 and s3 in FIG. 7 and the intermediate languages s2 and s3 in FIG. 8 have the same machine instruction length, but the intermediate languages s2 and s3 in FIG. The intermediate language is used. As a result, in FIG. 9, the code is further reduced by 2 bytes from the state of FIG. 7, and the machine language instruction program having the smallest code size is different from the intermediate language program shown in FIGS. Has been generated.

【0085】前記図9の機械語命令プログラムは、中間
言語s1の命令mov D2,D0 、命令add D3,D0 、及び中間
言語s8の命令add 5,D0が第1のレジスタファイル22
0内のレジスタD0、D2、D3を用いて第1の命令フ
ォーマットで記述され、他の中間言語s2〜s7が第2
のレジスタファイル120を用いて第2の命令フォーマ
ットで記述されていて、この機械語命令プログラムは、
コンピュータ読み取り可能な記録媒体に記録される。
The machine language instruction program shown in FIG. 9 includes an instruction mov D2, D0 and an instruction add D3, D0 of the intermediate language s1 and an instruction add5, D0 of the intermediate language s8.
0 is described in the first instruction format using the registers D0, D2, and D3, and the other intermediate languages s2 to s7 are stored in the second instruction format.
Is described in the second instruction format using the register file 120 of
It is recorded on a computer-readable recording medium.

【0086】尚、以上の具体例では、基本ブロックの各
変数p1、p2、t1〜t8をレジスタD2、D3、E
0〜E7に割り付けたが、資源割り付けが必要な変数が
割り付け可能なレジスタの本数を越えて同時に存在する
場合には、これ等変数は前記各レジスタとメモリ資源と
に割り付けられる。この場合は、図3のステップS30
7においてメモリ資源に割り付けた場合の命令列長が算
出される。このように変数の一部をメモリ資源に割り付
ける場合、データ転送命令を含む命令列では、第1のレ
ジスタファイル220内の何れかのレジスタを一時的に
使用して第1の命令フォーマットが使用される。これに
より、命令数は増加するが、命令列長は短くなり、命令
コードサイズは小さくなる場合がある。
In the above example, the variables p1, p2, t1 to t8 of the basic block are stored in the registers D2, D3, E8.
Although variables are allocated to 0 to E7, if variables requiring resource allocation simultaneously exist beyond the number of registers that can be allocated, these variables are allocated to the registers and memory resources. In this case, step S30 in FIG.
In step 7, the instruction sequence length when allocated to memory resources is calculated. When a part of the variables is allocated to the memory resources in this manner, in the instruction sequence including the data transfer instruction, any of the registers in the first register file 220 is temporarily used to use the first instruction format. You. As a result, the number of instructions increases, but the length of the instruction sequence becomes shorter, and the instruction code size may become smaller.

【0087】[0087]

【発明の効果】以上説明したように、本発明のコンパイ
ラによれば、命令フォーマットの種類に応じて扱えるレ
ジスタ資源が異なり、且つ命令フォーマットの種類に応
じて命令長が異なる命令セットを有するプロセッサにお
いて、コードサイズの小さい機械語プログラムを生成で
きるコンパイラを提供できるという顕著な効果が得られ
る。
As described above, according to the compiler of the present invention, in a processor having an instruction set which can handle different register resources according to the type of instruction format and has a different instruction length according to the type of instruction format. Thus, a remarkable effect that a compiler capable of generating a machine language program having a small code size can be provided is obtained.

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

【図1】本発明の一実施の形態によるコンパイラの構成
を示す構成図である。
FIG. 1 is a configuration diagram showing a configuration of a compiler according to an embodiment of the present invention.

【図2】同実施形態によるコンパイラの資源割り付け手
段の構成を示す構成図である。
FIG. 2 is a configuration diagram showing a configuration of a resource allocating unit of the compiler according to the embodiment;

【図3】同実施形態によるコンパイラの資源割り付け手
段における資源割り付けに関る処理フローを説明するフ
ローチャート図である。
FIG. 3 is a flowchart illustrating a processing flow relating to resource allocation in a resource allocation unit of the compiler according to the embodiment;

【図4】中間言語プログラムの一例を示す図である。FIG. 4 is a diagram illustrating an example of an intermediate language program.

【図5】中間言語プログラム中の各変数の生存区間と参
照頻度を示した図である。
FIG. 5 is a diagram showing a live range and a reference frequency of each variable in the intermediate language program.

【図6】変数の資源割付けとそれに対応した機械語命令
プログラムの一例を示す図である。
FIG. 6 is a diagram showing an example of resource allocation of variables and a machine language instruction program corresponding thereto.

【図7】変数の資源割付けとそれに対応した機械語命令
プログラムの一例を示す図である。
FIG. 7 is a diagram showing an example of resource allocation of variables and a machine language instruction program corresponding thereto.

【図8】変数の資源割付けとそれに対応した機械語命令
プログラムの一例を示す図である。
FIG. 8 is a diagram showing an example of resource allocation of variables and a machine language instruction program corresponding thereto.

【図9】変数の資源割付けとそれに対応した機械語命令
プログラムの一例を示す図である。
FIG. 9 is a diagram showing an example of resource allocation of variables and a machine language instruction program corresponding thereto.

【図10】本発明によるコンパイラが対象とするデータ
処理装置の第1の命令フォーマット(1)を示す図であ
る。
FIG. 10 is a diagram showing a first instruction format (1) of a data processing device targeted by a compiler according to the present invention.

【図11】同データ処理装置の第1の命令フォーマット
(1)の命令のリストの一部を示す図である。
FIG. 11 is a diagram showing a part of a list of instructions in a first instruction format (1) of the data processing apparatus.

【図12】同データ処理装置の第1の命令フォーマット
(2)を示す図である。
FIG. 12 is a diagram showing a first instruction format (2) of the data processing device.

【図13】同データ処理装置の第1の命令フォーマット
(2)の命令のリストの一部を示す図である。
FIG. 13 is a diagram showing a part of a list of instructions in a first instruction format (2) of the data processing apparatus.

【図14】同データ処理装置において、第1のレジスタ
ファイルの構成を示すブロック図である。
FIG. 14 is a block diagram showing a configuration of a first register file in the data processing device.

【図15】同データ処理装置の第1の命令フォーマット
の命令の実行時のレジスタファイルのレジスタ番号を示
す図である。
FIG. 15 is a diagram showing register numbers of a register file when an instruction of a first instruction format of the data processing device is executed.

【図16】同データ処理装置の第2の命令フォーマット
を示す図である。
FIG. 16 is a diagram showing a second instruction format of the data processing device.

【図17】同データ処理装置の第2の命令フォーマット
の命令のリストの一部を示す図である。
FIG. 17 is a diagram showing a part of a list of instructions in a second instruction format of the data processing apparatus.

【図18】同データ処理装置のレジスタファイルの構成
を示すブロック図である。
FIG. 18 is a block diagram showing a configuration of a register file of the data processing device.

【図19】同データ処理装置において、第1の命令フォ
ーマットの命令実行時のレジスタファイルのレジスタ番
号を示す図である。
FIG. 19 is a diagram showing register numbers of a register file when executing an instruction of a first instruction format in the data processing apparatus.

【図20】同データ処理装置において、第2の命令フォ
ーマットの命令の実行時のレジスタファイルのレジスタ
番号を示す図である。
FIG. 20 is a diagram showing a register number of a register file when an instruction of a second instruction format is executed in the data processing device.

【符号の説明】 1 構文解析手段 2 最適化手段 3 資源割り付け手段 4 コード生成手段 31 生存区間判定部 32 第1の命令長算出手段 33 第2の命令長算出手段 34 第3の命令長算出手段 35 変数資源割り付け部 36 制御部[Description of Signs] 1 syntax analysis means 2 optimization means 3 resource allocation means 4 code generation means 31 live range determination unit 32 first instruction length calculation means 33 second instruction length calculation means 34 third instruction length calculation means 35 Variable resource allocation unit 36 Control unit

Claims (9)

【特許請求の範囲】[Claims] 【請求項1】 複数の命令からなるソースプログラムを
入力し、このソースプログラムを機械語プログラムに翻
訳するコンパイラであって、 前記ソースプログラム中の各変数を、第1の命令フォー
マットで記述された命令を使用して第1のレジスタ資源
に割り付けた場合の命令列の長さを算出する第1の命令
列長算出手段と、 前記ソースプログラム中の各変数を、前記第1の命令フ
ォーマットとは命令長が異なる第2の命令フォーマット
で記述された命令を使用して、前記第1のレジスタ資源
とは異なる第2のレジスタ資源に割り付けた場合の命令
列の長さを算出する第2の命令列長算出手段とを備え、 前記第1及び第2の命令長算出手段が算出した命令長算
出結果を用いて資源割り付けを行うことを特徴とするコ
ンパイラ。
1. A compiler for inputting a source program consisting of a plurality of instructions and translating the source program into a machine language program, wherein each variable in the source program is described by an instruction described in a first instruction format. A first instruction sequence length calculating means for calculating the length of an instruction sequence when the instruction sequence is allocated to a first register resource using the first and second register resources; A second instruction sequence for calculating the length of an instruction sequence when allocated to a second register resource different from the first register resource using an instruction described in a second instruction format having a different length A compiler comprising: a length calculator; and allocating resources using the instruction length calculation results calculated by the first and second instruction length calculators.
【請求項2】 前記ソースプログラム中の各変数を、メ
モリに割り付けた場合の命令列の長さを算出する第3の
命令列長算出手段を備え、 前記第1、第2及び第3の命令長算出手段が算出した命
令長算出結果を用いて資源割り付けを行うことを特徴と
する請求項1記載のコンパイラ。
2. The apparatus according to claim 1, further comprising: a third instruction sequence length calculating unit configured to calculate an instruction sequence length when each variable in the source program is allocated to a memory, wherein the first, second, and third instructions are provided. 2. The compiler according to claim 1, wherein resource allocation is performed using an instruction length calculation result calculated by the length calculation means.
【請求項3】 前記第1及び第2の命令長算出手段が算
出した命令長算出結果を比較して、命令列長が小さい資
源割り付けを行うことを特徴とする請求項1記載のコン
パイラ。
3. The compiler according to claim 1, wherein the instruction length calculation results calculated by the first and second instruction length calculation means are compared, and resource allocation with a small instruction string length is performed.
【請求項4】 前記第1のレジスタ資源は、前記第2の
レジスタ資源の一部であることを特徴とする請求項1記
載のコンパイラ。
4. The compiler according to claim 1, wherein said first register resource is a part of said second register resource.
【請求項5】 前記第1の命令フォーマットの命令長
は、前記第2のフォーマット命令フォーマットの命令長
より短いことを特徴とする請求項4記載のコンパイラ。
5. The compiler according to claim 4, wherein an instruction length of said first instruction format is shorter than an instruction length of said second format instruction format.
【請求項6】 前記ソースプログラム中の各変数の中
で、使用頻度が高い変数を優先的に第1の命令フォーマ
ットで記述された命令を使用して第1のレジスタ資源に
割り付けることを特徴とする請求項1記載のコンパイ
ラ。
6. A method according to claim 1, wherein, among the variables in the source program, a frequently used variable is preferentially allocated to a first register resource using an instruction described in a first instruction format. The compiler according to claim 1, wherein
【請求項7】 前記ソースプログラム中の各変数につい
て、前記第1のレジスタ資源に割り付けられた変数を操
作する場合には、前記第1の命令フォーマットを優先的
に使用してその操作を記述することを特徴とする請求項
6記載のコンパイラ。
7. When operating a variable allocated to the first register resource for each variable in the source program, the operation is described by preferentially using the first instruction format. 7. The compiler according to claim 6, wherein:
【請求項8】 前記プログラム中の各変数の中で、使用
頻度が高い変数、及びこの変数と共に使用される変数
を、優先的に第1のレジスタ資源に割り付けることを特
徴とする請求項6記載のコンパイラ。
8. The method according to claim 6, wherein, among the variables in the program, a frequently used variable and a variable used together with the variable are preferentially allocated to the first register resource. Compiler.
【請求項9】 複数の命令からなるソースプログラムを
翻訳した機械語プログラムを記録したコンピュータ読み
取り可能な記録媒体であって、 前記機械語プログラムは、 第1のレジスタ資源を用いて第1の命令フォーマットで
記述された命令と、 前記第1のレジスタ資源とは異なる第2のレジスタ資源
を用いて、前記第1の命令フォーマットとは命令長が異
なる第2の命令フォーマットで記述された命令とが混在
し、前記第1の命令フォーマット及び第2の命令フォー
マットは前記命令中の特定の領域の値により識別される
ことを特徴とする記録媒体。
9. A computer-readable recording medium recording a machine language program translated from a source program including a plurality of instructions, wherein the machine language program uses a first register resource to execute a first instruction format. And an instruction described in a second instruction format having an instruction length different from the first instruction format using a second register resource different from the first register resource. The first instruction format and the second instruction format are identified by a value of a specific area in the instruction.
JP08357099A 1998-04-01 1999-03-26 Compiling device and compiling method Expired - Fee Related JP3264901B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP08357099A JP3264901B2 (en) 1998-04-01 1999-03-26 Compiling device and compiling method

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
JP8847398 1998-04-01
JP10-88473 1998-04-01
JP08357099A JP3264901B2 (en) 1998-04-01 1999-03-26 Compiling device and compiling method

Publications (2)

Publication Number Publication Date
JPH11345127A true JPH11345127A (en) 1999-12-14
JP3264901B2 JP3264901B2 (en) 2002-03-11

Family

ID=26424608

Family Applications (1)

Application Number Title Priority Date Filing Date
JP08357099A Expired - Fee Related JP3264901B2 (en) 1998-04-01 1999-03-26 Compiling device and compiling method

Country Status (1)

Country Link
JP (1) JP3264901B2 (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2004511043A (en) * 2000-10-05 2004-04-08 コーニンクレッカ フィリップス エレクトロニクス エヌ ヴィ Retargetable compilation system and method
US8893110B2 (en) 2006-06-08 2014-11-18 Qualcomm Incorporated Device management in a network
US9081638B2 (en) 2006-07-27 2015-07-14 Qualcomm Incorporated User experience and dependency management in a mobile device
US9141375B2 (en) 2003-07-08 2015-09-22 Qualcomm Incorporated Update package generation based on analysis of bank dependency
JP2020052953A (en) * 2018-09-28 2020-04-02 富士通株式会社 Generation program, information processing apparatus, and generation method

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2004511043A (en) * 2000-10-05 2004-04-08 コーニンクレッカ フィリップス エレクトロニクス エヌ ヴィ Retargetable compilation system and method
US9141375B2 (en) 2003-07-08 2015-09-22 Qualcomm Incorporated Update package generation based on analysis of bank dependency
US8893110B2 (en) 2006-06-08 2014-11-18 Qualcomm Incorporated Device management in a network
US9081638B2 (en) 2006-07-27 2015-07-14 Qualcomm Incorporated User experience and dependency management in a mobile device
JP2020052953A (en) * 2018-09-28 2020-04-02 富士通株式会社 Generation program, information processing apparatus, and generation method

Also Published As

Publication number Publication date
JP3264901B2 (en) 2002-03-11

Similar Documents

Publication Publication Date Title
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.
US6023583A (en) Optimized variable allocation method, optimized variable allocation system and computer-readable memory containing an optimized variable allocation program
US7103881B2 (en) Virtual machine to provide compiled code to processing elements embodied on a processor device
US7725883B1 (en) Program interpreter
JP5118745B2 (en) Vectorization of memory access instructions
US20060212440A1 (en) Program translation method and program translation apparatus
US6738966B1 (en) Compiling device, computer-readable recording medium on which a compiling program is recorded and a compiling method
US7949848B2 (en) Data processing apparatus, method and computer program product for reducing memory usage of an object oriented program
JPH01166141A (en) Debugging system
JPH09330233A (en) Optimum object code generating method
US6925639B2 (en) Method and system for register allocation
EP0947922B1 (en) Compiler
US7356812B2 (en) Passing parameters by implicit reference
JPH11345127A (en) Compiler
US7636914B1 (en) System and method for providing context to operator overloading
US6233732B1 (en) Compiling system using intermediate codes to store a plurality of values
JP2002099498A (en) Program performance device and program development support device
JPH09223023A (en) Compile system and compiler
US20070022413A1 (en) Tiered Register Allocation
CN112416313B (en) Compiling method supporting large integer data type and operator
JP3338466B2 (en) Main memory access optimization processor
JP3464019B2 (en) Register allocation method
JP4260895B2 (en) Multiple format addressing in microcontrollers
JP2004139369A (en) Analysis method for pointer pointing constant address domain
CN116775127A (en) Static symbol execution pile inserting method based on RetroWrite framework

Legal Events

Date Code Title Description
FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20071228

Year of fee payment: 6

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20081228

Year of fee payment: 7

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20091228

Year of fee payment: 8

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20091228

Year of fee payment: 8

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20101228

Year of fee payment: 9

LAPS Cancellation because of no payment of annual fees