JP5208589B2 - Compiling device, compiler, and compiling method - Google Patents

Compiling device, compiler, and compiling method Download PDF

Info

Publication number
JP5208589B2
JP5208589B2 JP2008155192A JP2008155192A JP5208589B2 JP 5208589 B2 JP5208589 B2 JP 5208589B2 JP 2008155192 A JP2008155192 A JP 2008155192A JP 2008155192 A JP2008155192 A JP 2008155192A JP 5208589 B2 JP5208589 B2 JP 5208589B2
Authority
JP
Japan
Prior art keywords
variable
priority
register
loop
code
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
JP2008155192A
Other languages
Japanese (ja)
Other versions
JP2009301326A (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.)
NEC Solution Innovators Ltd
Original Assignee
NEC System Technologies 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 NEC System Technologies Ltd filed Critical NEC System Technologies Ltd
Priority to JP2008155192A priority Critical patent/JP5208589B2/en
Publication of JP2009301326A publication Critical patent/JP2009301326A/en
Application granted granted Critical
Publication of JP5208589B2 publication Critical patent/JP5208589B2/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Description

本発明はコンパイル装置、コンパイラ、コンパイル方法に関する。   The present invention relates to a compiling device, a compiler, and a compiling method.

特許文献1には、変数に一つの優先度を付与し、当該優先度に基づいて変数をレジスタに割り当てるコンパイラが記載されている。   Patent Document 1 describes a compiler that assigns one priority to a variable and assigns the variable to a register based on the priority.

特許文献2には、ループ内の命令で使用される変数のレジスタ割り当てが終了した後に、ループの入り口及び出口で値の保証が必要な変数へのレジスタ割り当てを、変数の一の優先度に従って行うコンパイラが記載されている。   In Patent Document 2, after register allocation of variables used in instructions in a loop is completed, register allocation to variables that require value guarantee at the entrance and exit of the loop is performed according to one priority of the variables. A compiler is described.

特許文献3には、状態グラフに基づいて、スピルコード挿入位置を特定するコンパイル装置が記載されている。   Patent Document 3 describes a compiling device that specifies a spill code insertion position based on a state graph.

特許文献4には、プログラムを所定命令数毎に区間分割し、変数の各区間の出現状態に基づいて各区間の優先度を決定するコンパイル装置が記載されている。このコンパイル装置は、当該優先度に基づいて、当該区間のレジスタ割り当てを決定する。   Patent Document 4 describes a compiling device that divides a program into sections for each predetermined number of instructions and determines the priority of each section based on the appearance state of each section of variables. The compiling device determines register allocation for the section based on the priority.

特許文献5には、レジスタ割り付け後に、命令スケジューリングをするコンパイル処理装置が記載されている。   Patent Document 5 describes a compile processing device that performs instruction scheduling after register allocation.

特開2004−21336号公報JP 2004-21336 A 特開2004−21344号公報Japanese Patent Laid-Open No. 2004-21344 特開2004−227025号公報JP 2004-227025 A 特開平6−214802号公報JP-A-6-214802 特開平7−234792号公報Japanese Patent Laid-Open No. 7-234792

上述の技術は、ループおよびその他の部分からなるプログラムの変数へのレジスタ割り当てに於いて、「ループおよびその他の部分」(全体)、に基づく変数の優先度に従った割り当てを、「ループ」(局所)に基づく優先度を考慮して変更するものではない。したがって、プログラム全体の最適化と局所的な最適化の調和を取った最適化ができないという課題があった。   In the above-described technique, the assignment of variables according to the priority of variables based on “loops and other parts” (overall) is assigned to “loops” (all loops and other parts). It is not changed in consideration of the priority based on (local). Therefore, there is a problem that optimization cannot be performed in harmony with optimization of the entire program and local optimization.

本発明の目的は、上述した課題を解決するための、コンパイル装置、コンパイラ、コンパイル方法を提供することにある。   An object of the present invention is to provide a compiling device, a compiler, and a compiling method for solving the above-described problems.

本発明の一実施形態のコンパイル装置は、ループとその他の部分からなるプログラムを入力して、前記ループおよびその他の部分に基づいて前記プログラムの各変数に第1の優先度を与え、第1の優先度の高い順に所定数の前記変数(第1の変数)にグローバルレジスタを、残りの前記変数(第2の変数)に否グローバルレジスタを割り当てる割り当て(第1の割り当て)を行い、前記ループ部分に基づいて各前記変数に第2の優先度を与え、前記第2の変数のうち、前記第2の優先度が、何れかの前記第1の変数の前記第2の優先度より高い何れかの変数(第4の変数)に、前記第1の変数のうち、前記第2の優先度が、前記第4の変数の前記第2の優先度より低い何れかの変数(第3の変数)に割り当てた前記グローバルレジスタを割り当て直した割り当て(第2の割り当て)を行い、前記ループ部分からは前記第2の割り当てに従ったコードを、前記他の部分からは前記第1の割り当てに従ったコードを生成するレジスタ割り当て部を備える。   A compiling device according to an embodiment of the present invention inputs a program composed of a loop and other parts, gives a first priority to each variable of the program based on the loop and other parts, The loop portion is assigned (first assignment) in which a global register is assigned to a predetermined number of the variables (first variables) and a non-global register is assigned to the remaining variables (second variables) in descending order of priority. A second priority is given to each of the variables based on the second variable, and the second priority among the second variables is higher than the second priority of any of the first variables. Among the first variables, any variable (third variable) whose second priority is lower than the second priority of the fourth variable. Allocate the global register assigned to A register allocating unit that performs a corrected allocation (second allocation) and generates a code according to the second allocation from the loop part and a code according to the first allocation from the other part Is provided.

本発明の一実施形態のコンパイラは、コンピュータに、ループとその他の部分からなるプログラムを入力して、前記ループおよびその他の部分に基づいて前記プログラムの各変数に第1の優先度を与え、第1の優先度の高い順に所定数の前記変数(第1の変数)にグローバルレジスタを、残りの前記変数(第2の変数)に否グローバルレジスタを割り当てる割り当て(第1の割り当て)を行い、前記ループ部分に基づいて各前記変数に第2の優先度を与え、前記第2の変数のうち、前記第2の優先度が、何れかの前記第1の変数の前記第2の優先度より高い何れかの変数(第4の変数)に、前記第1の変数のうち、前記第2の優先度が、前記第4の変数の前記第2の優先度より低い何れかの変数(第3の変数)に割り当てた前記グローバルレジスタを割り当て直した割り当て(第2の割り当て)を行い、前記ループ部分からは前記第2の割り当てに従ったコードを、前記他の部分からは前記第1の割り当てに従ったコードを生成するレジスタ割り当てを実行させる。   A compiler according to an embodiment of the present invention inputs a program composed of a loop and other parts to a computer, gives a first priority to each variable of the program based on the loop and other parts, Assigning a global register to a predetermined number of the variables (first variables) and assigning a non-global register to the remaining variables (second variables) (first assignment) in order of highest priority of 1; A second priority is given to each of the variables based on a loop portion, and the second priority of the second variables is higher than the second priority of any of the first variables. Any variable (fourth variable) includes any one of the first variables, the second priority of which is lower than the second priority of the fourth variable (third variable). Variable) A register that performs assignment (second assignment) by reassigning a star and generates a code according to the second assignment from the loop part and a code according to the first assignment from the other part. Make the assignment run.

本発明の一実施形態のコンパイル方法は、コンピュータが、ループとその他の部分からなるプログラムを入力して、前記ループおよびその他の部分に基づいて前記プログラムの各変数に第1の優先度を与え、第1の優先度の高い順に所定数の前記変数(第1の変数)にグローバルレジスタを、残りの前記変数(第2の変数)に否グローバルレジスタを割り当てる割り当て(第1の割り当て)を行い、前記ループ部分に基づいて各前記変数に第2の優先度を与え、前記第2の変数のうち、前記第2の優先度が、何れかの前記第1の変数の前記第2の優先度より高い何れかの変数(第4の変数)に、前記第1の変数のうち、前記第2の優先度が、前記第4の変数の前記第2の優先度より低い何れかの変数(第3の変数)に割り当てた前記グローバルレジスタを割り当て直した割り当て(第2の割り当て)を行い、前記ループ部分からは前記第2の割り当てに従ったコードを、前記他の部分からは前記第1の割り当てに従ったコードを生成するレジスタ割り当て行程を有するコンパイル方法。   In a compiling method according to an embodiment of the present invention, a computer inputs a program including a loop and other parts, and gives a first priority to each variable of the program based on the loops and other parts. An assignment (first assignment) is performed in which a global register is assigned to a predetermined number of the variables (first variables) and a global register is assigned to the remaining variables (second variables) in descending order of the first priority; A second priority is assigned to each of the variables based on the loop portion, and the second priority of the second variables is greater than the second priority of any of the first variables. Among any variables that are higher (fourth variable), among the first variables, any one of the first variables (third variable) in which the second priority is lower than the second priority of the fourth variable. Assigned to the variable) A register which performs assignment (second assignment) by reassigning a register, and generates a code according to the second assignment from the loop part and a code according to the first assignment from the other part A compilation method with an allocation process.

本発明は、プログラム全体の最適化と局所的な最適化の調和を取った最適化を行うことが出来る。   The present invention can perform optimization in harmony with optimization of the entire program and local optimization.

図1は、本発明の第1の実施形態にかかるコンパイル装置10の構成図である。コンパイル装置10は、フロントエンド11、最適化部12、レジスタ割り当て部13、コードスケジューラ14、出力部15を備える。これらは、コンピュータであるコンパイル装置10の図示しないプロセッサーが、図示しない主記憶装置に格納されているプログラムであるコンパイラ19を読み込んで実行することで機能する。ハードウェアが、同等な機能を実現していてもよい。   FIG. 1 is a configuration diagram of a compiling device 10 according to the first embodiment of the present invention. The compiling device 10 includes a front end 11, an optimization unit 12, a register allocation unit 13, a code scheduler 14, and an output unit 15. These function when a processor (not shown) of the compiling device 10 which is a computer reads and executes a compiler 19 which is a program stored in a main storage device (not shown). The hardware may realize an equivalent function.

ソース形式プログラム21、第1の中間言語形式プログラム22、第2の中間言語形式プログラム23、コード24、オブジェクト形式プログラム25は、コンパイル装置10に接続された図示しないディスク装置上などにファイルとして設けられる。同様に、変数表30、パラメータ表40は、図示しないディスク装置上などにファイルとして設けられる。コード24は、第3の中間言語形式プログラムとも呼ばれる。コンパイル装置10の各部(レジスタ割り当て部13、コードスケジューラ14等)はこれらを入出力する。   The source format program 21, the first intermediate language format program 22, the second intermediate language format program 23, the code 24, and the object format program 25 are provided as files on a disk device (not shown) connected to the compiling device 10. . Similarly, the variable table 30 and the parameter table 40 are provided as files on a disk device (not shown). The code 24 is also called a third intermediate language format program. Each unit (the register allocation unit 13, the code scheduler 14, etc.) of the compiling device 10 inputs and outputs these.

ソース形式プログラム21は、C言語などの高級言語のソースコード形式のプログラムを格納する。オブジェクト形式プログラム25は、機械語形式のプログラムを格納する。コンパイル装置10は、ソース形式プログラム21を入力してオブジェクト形式プログラム25に変換して出力する。第1の中間言語形式プログラム22、第2の中間言語形式プログラム23、および、コード24は、当該変換過程に於ける中間形式のプログラムを格納する。   The source format program 21 stores a source code format program of a high-level language such as C language. The object format program 25 stores a machine language format program. The compiling device 10 inputs the source format program 21, converts it into an object format program 25, and outputs it. The first intermediate language format program 22, the second intermediate language format program 23, and the code 24 store an intermediate format program in the conversion process.

フロントエンド11は、ソース形式プログラム21の構文解析、意味解析などを行い、第1の中間言語形式プログラム22を出力する。最適化部12は、第1の中間言語形式プログラム22から、冗長な命令を省く、ループ内で繰り返し実行される命令をループ外に移動するなどの最適化を行い、第2の中間言語形式プログラム23を出力する。   The front end 11 performs syntax analysis and semantic analysis of the source format program 21, and outputs a first intermediate language format program 22. The optimization unit 12 performs optimization such as eliminating redundant instructions from the first intermediate language format program 22 and moving an instruction repeatedly executed in the loop to the outside of the loop, and the second intermediate language format program 23 is output.

レジスタ割り当て部13は、第2の中間言語形式プログラム23内の変数にレジスタを割り当ててコード24を出力する。コードスケジューラ14は、VLIW(Very Long Instruction Word)計算機などでの並列実行可能正を高める為に、コード24を並べ替える。コードスケジューラ14は、例えば、Mike Johnson著、村上和彰監訳、「スーパースカラ・プロセッサ」、日経BP出版センター、に記載されている技術を使用しても良い。出力部15は、コード24を機械語に変換して、オブジェクト形式プログラム25を出力する。   The register allocation unit 13 allocates a register to a variable in the second intermediate language format program 23 and outputs a code 24. The code scheduler 14 rearranges the codes 24 in order to increase parallel executable in a VLIW (Very Long Instruction Word) computer or the like. The code scheduler 14 may use, for example, a technique described in Mike Johnson, translated by Kazuaki Murakami, “Superscalar Processor”, Nikkei BP Publishing Center. The output unit 15 converts the code 24 into a machine language and outputs an object format program 25.

変数表30は、レジスタ割り当て部13からアクセスされて、プログラム内で使用されている変数に関する情報を格納する。図2は、変数表30の構成を示す。   The variable table 30 is accessed from the register allocation unit 13 and stores information on variables used in the program. FIG. 2 shows the configuration of the variable table 30.

変数表30は、各変数の、ID31、定義箇所32、参照箇所33、第1の優先度34、第1の割り当てレジスタ番号35、参照ループデータ36を包含する。参照ループデータ36は、ループごとに存在する。ループがネストするときは、例えば、一番外側のループごとに存在するようにしてもよい。   The variable table 30 includes ID 31, definition location 32, reference location 33, first priority 34, first allocation register number 35, and reference loop data 36 for each variable. The reference loop data 36 exists for each loop. When loops are nested, for example, they may exist for each outermost loop.

参照ループデータ36は、範囲37、第2の優先度38、第2の割り当てレジスタ番号39を包含する。範囲37には、各ループの先頭と最終の箇所が格納される。ここで、箇所とは、命令の位置、例えば、プログラム内での命令番号や相対命令アドレスである。   The reference loop data 36 includes a range 37, a second priority 38, and a second allocation register number 39. The range 37 stores the beginning and end of each loop. Here, the location is an instruction position, for example, an instruction number or a relative instruction address in the program.

定義箇所32、参照箇所33には、ID31で示される変数の定義(値代入)の箇所と参照の箇所が格納される。定義箇所32は一つ、参照箇所33は複数の箇所を格納する。本発明における変数は、プログラマが宣言した変数そのものではない。プログラマが宣言した変数に値が確定するたびに、当該変数は本発明に於ける別の変数となる。   The definition location 32 and the reference location 33 store the location of variable definition (value substitution) indicated by the ID 31 and the location of reference. One definition location 32 and a reference location 33 store a plurality of locations. The variable in the present invention is not the variable itself declared by the programmer. Each time a value is determined for a variable declared by the programmer, that variable becomes another variable in the present invention.

図3は、パラメータ表40の構成を示す。パラメータ表40は、グローバルレジスタ数41と否グローバルレジスタ数42を格納する。   FIG. 3 shows the configuration of the parameter table 40. The parameter table 40 stores a global register number 41 and a non-global register number 42.

グローバルレジスタと否グローバルレジスタは共に、オブジェクト形式プログラム25が実行されるコンピュータが備えるレジスタである。グローバルレジスタは、関数やサブルーチンの呼び出しで値が保証される(破壊されない)レジスタである。即ち、グローバルレジスタは、例えば、関数やサブルーチンが、その入り口出口で値を退避回復するレジスタである。   Both the global register and the non-global register are registers provided in the computer in which the object format program 25 is executed. A global register is a register whose value is guaranteed (not destroyed) by calling a function or subroutine. That is, the global register is, for example, a register that saves and recovers a value at the entrance / exit of a function or subroutine.

否グローバルレジスタは、関数やサブルーチンの呼び出しで値が保証されないレジスタである。関数やサブルーチンの呼び出しの前後で、否グローバルレジスタの値を保証するためには、呼び出し命令の前後で退避回復が必要になる。   The reject global register is a register whose value is not guaranteed by calling a function or a subroutine. In order to guarantee the value of the non-global register before and after calling a function or subroutine, it is necessary to save and restore before and after the call instruction.

本実施形態のコンパイル装置10は、先ず、プログラムの全体に基づいて、変数に第1の優先度34を付与し、それに従ってプログラム全体のレジスタ割り当て(第1の割り当て)を決定する。次に、同装置は、プログラムのループ部分に基づいて、変数に第2の優先度38を付与し、それに従って、ループ部分について第1の割り当ての一部を変更したレジスタ割り当て(第2の割り当て)をする場合がある。   First, the compiling apparatus 10 according to the present embodiment assigns a first priority 34 to a variable based on the entire program, and determines register allocation (first allocation) of the entire program accordingly. Next, the apparatus assigns a second priority 38 to the variable based on the loop portion of the program, and changes a part of the first assignment for the loop portion accordingly (second allocation). ).

図4は、レジスタ割り当て部13の概略フローチャートである。同部はまず、プログラムからグローバル変数を抽出して変数表30に登録する、変数登録処理を行う(S11)。ここで、グローバル変数は、プログラムの基本ブロックを超えて、定義および参照される変数である。定義及び全ての参照が、プログラムの一つの基本ブロック内に閉じている変数は否グローバル変数である。なお、基本ブロックは、一入り口一出口の命令ブロックである。   FIG. 4 is a schematic flowchart of the register allocation unit 13. First, the same part performs a variable registration process in which global variables are extracted from the program and registered in the variable table 30 (S11). Here, the global variable is a variable that is defined and referenced beyond the basic block of the program. A variable whose definition and all references are closed within one basic block of the program is a non-global variable. The basic block is an instruction block with one entrance and one exit.

次に、レジスタ割り当て部13は、各グローバル変数に第1の優先度34を付与し、同優先度に基づいてグローバル変数にグローバルレジスタを割り当てる、グローバルレジスタ割り当て処理を行う(S12)。引き続き、同部は、グローバルレジスタが割り当てられなかったグローバル変数に、同優先度に基づき否グローバルレジスタを割り当てる、否グローバルレジスタ割り当て処理を行う(S13)。この過程で、レジスタ割り当ての変更が発生し得る。   Next, the register allocation unit 13 assigns a first priority 34 to each global variable, and performs a global register allocation process in which a global register is allocated to the global variable based on the same priority (S12). Subsequently, the same part performs a reject global register assignment process in which a reject global register is assigned to a global variable to which a global register is not assigned based on the same priority (S13). In this process, register allocation changes can occur.

その後、同部は、レジスタ割り当てを反映したコード24を生成する、コード生成処理(S14)を行う。   Thereafter, the same part performs a code generation process (S14) for generating a code 24 reflecting the register assignment.

図5は、レジスタ割り当て部13の変数登録処理のフローチャートである。レジスタ割り当て部13は、第2の中間言語形式プログラム23の先頭から順に一つの命令を取得する(S21)。当該命令が変数(変数Aと仮称)を定義する命令であった(S22でY)場合、同部は、当該命令を包含する基本ブロックの先頭命令と最終命令の箇所を取得する(S23)。   FIG. 5 is a flowchart of the variable registration process of the register allocation unit 13. The register allocation unit 13 acquires one instruction in order from the top of the second intermediate language format program 23 (S21). If the instruction is an instruction defining a variable (tentative name as variable A) (Y in S22), the same part acquires the first instruction and the last instruction of the basic block including the instruction (S23).

次に、同部は、第2の中間言語形式プログラム23全体から、変数Aを参照する全ての命令の箇所を取得して(S24)、それらが全て上述の基本ブロック内に入っているか判断する(S25)。   Next, the same part acquires all instruction locations referring to the variable A from the entire second intermediate language format program 23 (S24), and determines whether they are all in the basic block. (S25).

それらが全て上述の基本ブロック内に入っていない場合(S25でN)、変数Aはグローバル変数である。この場合、同部は、変数AのID31、定義箇所32、参照箇所33を変数表30に格納する(S26)。ここで、変数AのID31は、例えば、変数Aの定義命令の変数名に定義通番を付して生成する。   If they are not all in the basic block (N in S25), the variable A is a global variable. In this case, the same part stores the ID 31 of variable A, the definition location 32, and the reference location 33 in the variable table 30 (S26). Here, the ID 31 of the variable A is generated, for example, by adding a definition serial number to the variable name of the variable A definition instruction.

変数Aを参照する命令の箇所が全て上述の基本ブロック内に入っている場合(S25でY)、変数Aは否グローバル変数である。この場合、同部は何もしない。即ち、変数表30は、グローバル変数のみを格納する。   When all the instruction locations that refer to the variable A are included in the basic block (Y in S25), the variable A is a non-global variable. In this case, the part does nothing. That is, the variable table 30 stores only global variables.

同部は、第2の中間言語形式プログラム23の最後(S27)まで、この変数登録処理を繰り返す。   This part repeats this variable registration process until the end of the second intermediate language format program 23 (S27).

図6は、レジスタ割り当て部13のグローバルレジスタ割り当て処理のフローチャートである。まず、レジスタ割り当て部13は、変数表30から変数を一つ取得する(S31)。   FIG. 6 is a flowchart of the global register allocation process of the register allocation unit 13. First, the register allocation unit 13 acquires one variable from the variable table 30 (S31).

同部は、第2の中間言語形式プログラム23全体を走査して、当該変数の定義および参照の間に存在する関数やサブルーチンの呼び出し命令の数(値A)を求める(S32)。具体的に、同部は、定義箇所32と最初の参照箇所33との間の呼び出し命令の数、各参照箇所33とその次の参照箇所33の間の呼び出し命令の数を数えて、その合計値を値Aとする。   The same part scans the entire second intermediate language format program 23 and obtains the number (value A) of calling instructions of functions and subroutines existing between the definition and reference of the variable (S32). Specifically, the same part counts the number of call instructions between the definition location 32 and the first reference location 33, the number of call instructions between each reference location 33 and the next reference location 33, and the total Let the value be the value A.

このとき、同部は、プログラム中にループがあれば、当該ループの繰り返し回数を考慮して、値Aを求めても良い。ループの繰り返し数は、プログラムから静的に決定できればその数とし、実行時にしか決定できなければ所定値(例えば100)としても良い。   At this time, if there is a loop in the program, the same unit may obtain the value A in consideration of the number of repetitions of the loop. The number of loop iterations may be the number if it can be determined statically from the program, or may be a predetermined value (for example, 100) if it can only be determined at the time of execution.

次に、同部は、第2の中間言語形式プログラム23全体を走査して、当該変数の参照回数(値B)を求める(S33)。例えば、同部は、参照命令の数を数える。このとき、同部は、プログラム中にループがあれば、当該ループの繰り返し回数を考慮して、値Bを求めても良い。   Next, the same unit scans the entire second intermediate language format program 23 and obtains the reference count (value B) of the variable (S33). For example, the same part counts the number of reference instructions. At this time, if there is a loop in the program, the same unit may obtain the value B in consideration of the number of repetitions of the loop.

同部は、値Aと値Bの合計値を求めて、第1の優先度34に格納する(S34)。即ち、第1の優先度34は、当該変数の参照が多いほど、かつ、定義/参照間に存在する呼び出し命令が多いほど大きな(高い)ものとなる。   The same unit calculates the total value of the value A and the value B and stores it in the first priority 34 (S34). That is, the first priority 34 becomes larger (higher) as the number of references to the variable increases and the number of call instructions existing between the definitions / references increases.

同部は、変数表30の最後(S35)まで、上記の処理を繰り返す。その後(S35でY)、同部は、第1の優先度34の高い順に、変数にグローバルレジスタを割り当てて、当該レジスタの番号を第1の割り当てレジスタ番号35に格納する(S36)。   The same part repeats the above processing until the end of the variable table 30 (S35). Thereafter (Y in S35), the same unit assigns global registers to variables in descending order of the first priority 34, and stores the register numbers in the first assigned register number 35 (S36).

グローバルレジスタが割り当てられた変数は、第1の変数と称される。第1の変数の個数は、グローバルレジスタ数41である。   The variable to which the global register is assigned is referred to as the first variable. The number of first variables is 41 global registers.

一般に、変数の数は当該数以上であるので、この時点では、レジスタが割り当てられていない変数が残存する。(プログラムが極端に小さくて変数の数が少ないときには、そうでない場合がありうる。この場合、コンパイル装置10は、否グローバル割り当て処理を省略して、直ちにコード生成処理を実行する。)
図7は、レジスタ割り当て部13の否グローバルレジスタ割り当て処理のフローチャート(1/3)である。図8は、レジスタ割り当て部13の否グローバルレジスタ割り当て処理のフローチャート(2/3)である。図9は、レジスタ割り当て部13の否グローバルレジスタ割り当て処理のフローチャート(3/3)である。
In general, since the number of variables is equal to or greater than the number, variables to which no register is assigned remain at this point. (When the program is extremely small and the number of variables is small, this may not be the case. In this case, the compiling device 10 omits the no global assignment process and immediately executes the code generation process.)
FIG. 7 is a flowchart (1/3) of the non-global register allocation process of the register allocation unit 13. FIG. 8 is a flowchart (2/3) of the non-global register allocation process of the register allocation unit 13. FIG. 9 is a flowchart (3/3) of the non-global register allocation process of the register allocation unit 13.

レジスタ割り当て部13は、変数表30から、レジスタが割り当てられていない変数のうち、第1の優先度34が最も高い変数(変数Xと仮称)を取得する(S41)。同部は、どの変数にも割り当てられていない否グローバルレジスタが有ることを確認する(S42でY)と、変数Xに当該否グローバルレジスタを割り当てて、当該レジスタの番号を第1の割り当てレジスタ番号35に格納する(S43)。   The register allocator 13 acquires from the variable table 30 a variable (tentative name, variable X) having the highest first priority 34 among variables to which no register is allocated (S41). When the same part confirms that there is a non-global register that is not assigned to any variable (Y in S42), the same part is assigned to the variable X, and the number of the register is assigned to the first assigned register number. 35 (S43).

このように、否グローバルレジスタが割り当てられた変数は、第2の変数と称される。第2の変数の個数は、否グローバルレジスタ数42である。このように、第1の優先度34に従って、第1の変数と第2の変数にレジスタを割り当てることが、第1の割り当てである。   In this way, the variable to which the negative global register is assigned is referred to as a second variable. The number of second variables is the number of non-global registers 42. Thus, according to the first priority 34, assigning registers to the first variable and the second variable is the first assignment.

同部は、割り当てられていない否グローバルレジスタが無いことを検出する(S42でN)と、処理を終了する。同部は、変数Xおよび変数Xより第1の優先度34が低い変数にはレジスタの割り当てが出来ないことになる。   When the same part detects that there is no global register that is not assigned (N in S42), the process ends. In the same part, it is impossible to assign a register to the variable X and the variable having the first priority 34 lower than the variable X.

このようなレジスタ未割り当ての変数は、メモリ上でのみ演算されても良いし、短期間のみ上述のレジスタとは別の作業用レジスタを使用して演算されても良い。本発明では、レジスタ未割り当ての変数の扱いを特定しない。   Such a register unassigned variable may be calculated only on the memory, or may be calculated using a working register different from the above-mentioned register only for a short period. The present invention does not specify the handling of variables not assigned to registers.

なお、プログラムが小さくて変数の数が少ないときには、全ての変数にグローバルレジスタか否グローバルレジスタが割り当てられる場合もある。この場合、同部が、割り当てられていない否グローバルレジスタが無いことを検出する(S42でN)ことはない。   When the program is small and the number of variables is small, all variables may be assigned global registers or not. In this case, the same unit does not detect that there is no global register not assigned (N in S42).

同部は、第2の中間言語形式プログラム23全体を走査して、変数Xの参照箇所33がループ内に存在する(S44でY)場合、当該参照箇所33を含む一番外側のループの先頭と最終の箇所を抽出して範囲37に格納する(S45)。   The same part scans the entire second intermediate language format program 23, and if the reference location 33 of the variable X exists in the loop (Y in S44), the head of the outermost loop including the reference location 33 And the last part is extracted and stored in the range 37 (S45).

なお、変数Xの参照箇所33は複数であり、参照箇所33を含む一番外側のループは複数存在する可能性があるが、下記説明では、簡単のため、これは一つであると仮定する。複数ある場合、以降の処理が一番外側のループ毎に繰り返される。   Note that there are a plurality of reference locations 33 of the variable X, and there may be a plurality of outermost loops including the reference location 33. However, in the following description, it is assumed that this is one for simplicity. . If there are multiple, the subsequent processing is repeated for each outermost loop.

レジスタ割り当て部13は、変数表30から、変数(変数Yと仮称)を取り出して(S46)、変数Yが当該ループ内で参照されているか(S47)を確認する。具体的に、同部は、変数Yの参照箇所33のいずれかが変数Xの範囲37内に入っているかを確認する。   The register allocation unit 13 extracts a variable (tentative name, variable Y) from the variable table 30 (S46), and checks whether the variable Y is referenced in the loop (S47). Specifically, the same part checks whether any of the reference locations 33 of the variable Y is within the range 37 of the variable X.

変数Yが当該ループ内で参照されている場合(S47でY)、同部は、当該ループ内で変数Yの定義及び参照の間に存在する関数やサブルーチンの呼び出し命令の数(値a)を求め、変数Yの第2の優先度38に格納する(S48)。具体的に、同部は、当該ループ内の定義箇所32と最初の参照箇所33との間の呼び出し命令の数、各参照箇所33とその次の参照箇所33の間の呼び出し命令の数を数えて、その合計値を値aとする。なお、当該ループ内に定義箇所32がない場合は、参照間の呼び出し命令数を求めて値aとする。このとき、同部は、当該ループ内にループのネストがあれば、ネストしている当該ループの繰り返し回数を考慮して、値aを求めても良い。   When the variable Y is referenced in the loop (Y in S47), the same unit displays the number of function or subroutine call instructions (value a) existing between the definition and reference of the variable Y in the loop. It is obtained and stored in the second priority 38 of the variable Y (S48). Specifically, the same section counts the number of call instructions between the definition location 32 and the first reference location 33 in the loop, and the number of call instructions between each reference location 33 and the next reference location 33. The total value is defined as value a. If there is no definition part 32 in the loop, the number of calling instructions between references is obtained and set as the value a. At this time, if there is a loop nest in the loop, the same unit may obtain the value a in consideration of the number of repetitions of the nested loop.

変数Yが当該ループ内で参照されていない場合(S47でN)、同部は、0を変数Yの第2の優先度38に格納する(S49)。   When the variable Y is not referenced in the loop (N in S47), the same unit stores 0 in the second priority 38 of the variable Y (S49).

同部は、変数表30の最後(S4A)まで、上記S46乃至S49の処理を繰り返す。   The same part repeats the processes of S46 to S49 until the end of the variable table 30 (S4A).

その後(S4AでY)、同部は、変数表30を走査して、グローバルレジスタが割り当てられた変数(第1の変数)のなかで、変数Xの第2の優先度38より低い第2の優先度38を持つ変数が有るかを検査する(S51)。   Thereafter (Y in S4A), the same part scans the variable table 30, and among the variables (first variables) to which the global register is assigned, the second lower than the second priority 38 of the variable X. It is checked whether there is a variable having the priority 38 (S51).

そのような変数が有る場合(S52でY)、同部は、当該変数中、最低(最小)の第2の優先度38を持つ変数(第3の変数)を取得する(S53)。最低の第2の優先度38を持つ変数が複数ある場合、同部は、その中から第1の優先度34が最低の変数を第3の変数として取得する。   If there is such a variable (Y in S52), the same unit acquires a variable (third variable) having the lowest (minimum) second priority 38 among the variables (S53). When there are a plurality of variables having the lowest second priority 38, the same unit acquires a variable having the lowest first priority 34 as the third variable.

同部は、第3の変数の第1の割り当てレジスタ番号35を取り出して、変数X(第4の変数となる)の第2の割り当てレジスタ番号39に格納する(S54)。同部は、第3の変数の退避(スピル)/リストア命令を生成して、当該ループの入り口出口に挿入する(S55)。   The same unit takes out the first allocation register number 35 of the third variable and stores it in the second allocation register number 39 of the variable X (becomes the fourth variable) (S54). The same part generates a save (spill) / restore command for the third variable and inserts it into the entrance / exit of the loop (S55).

なお、同部はここで、第1の割り当てに於いて第3の変数に割り当てたグローバルレジスタを、当該ループ内に限って第4の変数に割当直した。このように、第2の優先度38に従って、当該ループ内に限って第1の割り当てを変更してレジスタを割り当てることが第2の割り当てである。   Here, the same part reassigns the global register assigned to the third variable in the first assignment to the fourth variable only within the loop. In this way, according to the second priority 38, the second assignment is to change the first assignment and assign the registers only within the loop.

その後、同部は、変数表30の最後(S68)まで、本否グローバルレジスタ割り当て処理を繰り返す。   Thereafter, the same part repeats the main global register assignment process until the end of the variable table 30 (S68).

第3の変数がない場合(S52でN)、同部は、変数Xの第1の割り当てレジスタ番号35を取り出して、変数Xの第2の割り当てレジスタ番号39に格納する(S56)。即ち、同部は、当該ループ内においても第1の割り当てを変更しない。即ち、変数Xには、否グローバルレジスタが割り当てられたままである。   When there is no third variable (N in S52), the same unit retrieves the first allocation register number 35 of the variable X and stores it in the second allocation register number 39 of the variable X (S56). That is, the same part does not change the first assignment even in the loop. That is, the no global register is still assigned to the variable X.

この場合、同部は、所定の基本ブロックの入り口出口に変数Xのスピル命令とリストア命令を生成して挿入する。その処理は以下の通りである。   In this case, the same unit generates and inserts a spill instruction and a restore instruction for the variable X at the entrance / exit of a predetermined basic block. The processing is as follows.

レジスタ割り当て部13は、第2の中間言語形式プログラム23の先頭から順に一つの命令を取得する(S61)。当該命令が呼び出し命令であれば(S62でY)、同部は、当該命令を含む基本ブロックの先頭と最終の命令の箇所を取得する(S63)。   The register allocation unit 13 acquires one instruction in order from the top of the second intermediate language format program 23 (S61). If the instruction is a call instruction (Y in S62), the same unit acquires the beginning and the end of the last instruction including the instruction (S63).

変数Xの定義箇所32と参照箇所33が当該ブロックの前後に存在し(S64でY)、かつ、当該ブロック内に存在しない(S65でY)場合、同部は、当該基本ブロックの入り口出口に変数Xのスピル命令とリストア命令を生成して挿入する(S66)。ただし、同部は、既に当該基本ブロックの入り口出口に変数Xのスピル命令とリストア命令が挿入されていれば、重ねて挿入することはしない。   If the definition location 32 and the reference location 33 of the variable X exist before and after the block (Y in S64) and do not exist in the block (Y in S65), the same part is located at the entrance / exit of the basic block. A spill instruction and a restore instruction for variable X are generated and inserted (S66). However, if the spill instruction and the restore instruction of the variable X have already been inserted at the entrance / exit of the basic block, the same part is not inserted again.

S62、S64、S65の何れかでNとなれば、同部は何もしない。   If it becomes N in any of S62, S64, and S65, the part does nothing.

同部は、第2の中間言語形式プログラム23の最後(S67)までS61乃至S66の処理を繰り返す。この終了(S67でY)の後、当該変数Xが変数表30の最後の変数で無ければ(S68でN)、次の変数について否グローバル割り当て処理を繰り返す(S41に戻る)。   This part repeats the processing of S61 to S66 until the end (S67) of the second intermediate language format program 23. After the end (Y in S67), if the variable X is not the last variable in the variable table 30 (N in S68), the non-global assignment process is repeated for the next variable (return to S41).

図10は、レジスタ割り当て部13のコード生成処理のフローチャートである。なお、本フローチャートでは、レジスタ未割り付けの変数が存在しないことを前提としている。   FIG. 10 is a flowchart of the code generation process of the register allocation unit 13. In this flowchart, it is assumed that there is no register unallocated variable.

レジスタ割り当て部13は、第2の中間言語形式プログラム23の先頭から順に一つの命令を取得する(S81)。当該命令が変数を定義または参照する場合(S82でY)、同部は、当該命令がループ内に存在するかをチェックする(S83)。   The register allocation unit 13 acquires one instruction in order from the top of the second intermediate language format program 23 (S81). If the instruction defines or refers to a variable (Y in S82), the same part checks whether the instruction exists in the loop (S83).

当該命令がループ内に存在しなければ(S83でN)、同部は、当該命令から変数のID31を生成して、変数に当該ID31に対応する第1の割り当てレジスタ番号35のレジスタを割り当てたコード24を生成する(S84)。   If the instruction does not exist in the loop (N in S83), the same unit generates a variable ID31 from the instruction and allocates the register of the first allocation register number 35 corresponding to the ID31 to the variable. The code 24 is generated (S84).

当該命令がループ内に存在すれば(S83でY)、同部は、当該命令から変数のID31を生成して、変数に当該ID31に対応する第2の割り当てレジスタ番号39のレジスタを割り当てたコード24を生成する(S86)。   If the instruction exists in the loop (Y in S83), the same part generates a variable ID31 from the instruction, and assigns the register of the second assigned register number 39 corresponding to the ID31 to the variable. 24 is generated (S86).

なお、プログラムに一番外側のループが複数存在する場合、同部は、当該命令が包含されるループのプログラム先頭からの順番などに基づいて、当該ループに対応する参照ループデータ36を認識して、その第2の割り当てレジスタ番号39を参照する。   When there are a plurality of outermost loops in the program, the same unit recognizes the reference loop data 36 corresponding to the loop based on the order from the top of the program of the loop in which the instruction is included. The second allocation register number 39 is referred to.

同部は、第2の中間言語形式プログラム23の最後(S85)まで、このコード生成処理を繰り返す。   This part repeats this code generation process until the end of the second intermediate language format program 23 (S85).

本実施形態のコンパイル装置10は、プログラム全体としての最適化と局所的な最適化の調和を取ったレジスタ割り当てを行うことが出来る(第1の効果)。その理由は、同装置は、先ず、プログラム全体にわたるレジスタ割り当てを、プログラム全体に基づいて行う(第1の割り当て)からである。そして、同装置は、ループ部分について、当該ループ部分のプログラムに基づいて、第1の割り当ての一部を変更したレジスタ割り当て(第2の割り当て)を行うからである。   The compiling device 10 according to the present embodiment can perform register allocation in harmony with optimization as a whole program and local optimization (first effect). The reason is that the apparatus first performs register allocation over the entire program based on the entire program (first allocation). This is because the apparatus performs register assignment (second assignment) in which a part of the first assignment is changed for the loop part based on the program of the loop part.

具体的には、本発明のコンパイル装置10は、プログラム全体として、メモリアクセスを減らすようなレジスタ割り当てを行いつつも、ループ内で使用していないグローバル変数については、ループの直前にスピル命令を生成し挿入する。同装置は、そのうえで、当該グローバル変数に割り当てられていたグローバルレジスタをループ内の別のグローバル変数に割り当てることで、作成したオブジェクト形式プログラム25の実行速度を向上させる。ループ内に不要なスピル命令を生成、挿入する必要がなくなるため、実行速度が向上するのである。   Specifically, the compiling device 10 of the present invention generates a spill instruction immediately before the loop for global variables that are not used in the loop while performing register allocation to reduce memory access as a whole program. Then insert. The apparatus further increases the execution speed of the created object format program 25 by assigning the global register assigned to the global variable to another global variable in the loop. Since there is no need to generate and insert an unnecessary spill instruction in the loop, the execution speed is improved.

第2の割り当てに於いて、第1の割り当てを全て変更するものではないため、この割り当ては、ループ部分にのみ基づいた割り当てと、その他の部分にのみ基づいた割り当てを組み合わせたものとは異なる。   Since the second assignment does not change all of the first assignment, this assignment is different from a combination of assignments based only on the loop portion and assignments based only on the other portions.

本実施形態のコンパイル装置10は、レジスタ割り当て部13が生成したスピル命令も、並列実行可能正を高める為に並べ替えが可能である(第2の効果)。その理由は、レジスタ割り当て部13がスピル命令挿入したコード24を対象に、コードスケジューラ14が命令の並べ替えを行うからである。スピル命令も最適な場所に移動できるため、実行速度が向上する。   The compiling apparatus 10 according to the present embodiment can rearrange the spill instructions generated by the register allocation unit 13 in order to increase the parallel executable positive (second effect). The reason is that the code scheduler 14 rearranges instructions for the code 24 in which the spill instruction is inserted by the register allocation unit 13. Since the spill instruction can be moved to the optimum place, the execution speed is improved.

図11は、本発明の第2の実施形態にかかる、レジスタ割り当て部13のグローバルレジスタ割り当て処理のフローチャートである。本実施形態のコンパイル装置10は、その他の点では第1の実施形態と同じである。   FIG. 11 is a flowchart of global register allocation processing of the register allocation unit 13 according to the second embodiment of the present invention. The compiling device 10 of this embodiment is the same as that of the first embodiment in other points.

まず、レジスタ割り当て部13は、変数表30から変数を一つ取得する(S91)。   First, the register allocation unit 13 acquires one variable from the variable table 30 (S91).

同部は、第2の中間言語形式プログラム23全体を走査して、当該変数の定義および参照の間に存在する関数やサブルーチンの呼び出し命令の数(値A)を求める(S92)。具体的に、同部は、定義箇所32と最初の参照箇所33との間の呼び出し命令の数、各参照箇所33とその次の参照箇所33の間の呼び出し命令の数を数えて、その合計値を値Aとする。   The same part scans the entire second intermediate language format program 23 to obtain the number of function or subroutine call instructions (value A) existing between the definition and reference of the variable (S92). Specifically, the same part counts the number of call instructions between the definition location 32 and the first reference location 33, the number of call instructions between each reference location 33 and the next reference location 33, and the total Let the value be the value A.

このとき、同部は、プログラム中にループがあれば、当該ループの繰り返し回数を考慮して、値Aを求めても良い。ループの数は、プログラムから静的に決定できればその数とし、実行時にしか決定できなければ所定値(例えば100)としても良い。   At this time, if there is a loop in the program, the same unit may obtain the value A in consideration of the number of repetitions of the loop. The number of loops may be the number if it can be determined statically from the program, and may be a predetermined value (for example, 100) if it can only be determined at the time of execution.

次に、同部は、第2の中間言語形式プログラム23全体を走査して、当該変数の参照回数(値B)を求める(S93)。例えば、同部は、参照命令の数を数える。このとき、同部は、プログラム中にループがあれば、当該ループの繰り返し回数を考慮して、値Bを求めても良い。   Next, the same part scans the entire second intermediate language format program 23 and obtains the reference count (value B) of the variable (S93). For example, the same part counts the number of reference instructions. At this time, if there is a loop in the program, the same unit may obtain the value B in consideration of the number of repetitions of the loop.

同部は、値Bの高い順に変数を、グローバルレジスタ数41と否グローバルレジスタ数42の合計値数分だけ選択する(S94)。次に同部は、選択した変数には値Aの大きな順に大きな第1の優先度34を付与し、選択されなかった変数には最低(例えば0)の第1の優先度34を付与する(S95)。   The same part selects the variables corresponding to the total number of the global register number 41 and the non-global register number 42 in descending order of the value B (S94). Next, the same part gives the selected variable the first priority 34 in descending order of the value A, and assigns the lowest (for example, 0) first priority 34 to the unselected variable ( S95).

同部は、変数表30の最後(S96)まで、上記の処理を繰り返す。その後(S96でY)、同部は、第1の優先度34の高い順に、変数にグローバルレジスタを割り当てて、当該レジスタの番号を第1の割り当てレジスタ番号35に格納する(S97)。   The same part repeats the above processing until the end of the variable table 30 (S96). Thereafter (Y in S96), the same unit assigns global registers to variables in descending order of the first priority 34, and stores the register numbers in the first assigned register number 35 (S97).

本実施例のコンパイル装置10は、グローバルレジスタの最適な割り当てが可能となる。定義、参照間の呼び出し命令数が多い変数を、確実にグローバルレジスタに割り当てるからである。   The compiling apparatus 10 according to the present embodiment can optimally allocate global registers. This is because a variable having a large number of calling instructions between definition and reference is surely assigned to a global register.

図12は、本発明にかかるコンパイル装置10の基本的な構成を示す。本発明のコンパイル装置10は、レジスタ割り当て部13を備える。   FIG. 12 shows a basic configuration of the compiling device 10 according to the present invention. The compiling device 10 of the present invention includes a register allocation unit 13.

同部は、先ず、ループとその他の部分からなるプログラム20を入力して、ループおよびその他の部分に基づいてプログラム20の各変数に第1の優先度34を与える。同部は更に、第1の優先度34の高い順に所定数の変数(第1の変数)にグローバルレジスタを、残りの変数(第2の変数)に否グローバルレジスタを割り当てる割り当て(第1の割り当て)を行う。   The same part first inputs a program 20 consisting of a loop and other parts, and gives a first priority 34 to each variable of the program 20 based on the loops and other parts. The same unit further assigns a global register to a predetermined number of variables (first variable) in descending order of the first priority 34, and assigns a global register to the remaining variable (second variable) (first assignment). )I do.

同部は、次に、ループ部分に基づいて各変数に第2の優先度38を与える。同部は更に、第2の変数のうち、第2の優先度38が、何れかの第1の変数の第2の優先度38より高い何れかの変数(第4の変数)に、第1の変数のうち、第2の優先度38が、第4の変数の第2の優先度38より低い何れかの変数(第3の変数)に割り当てた前記グローバルレジスタを割り当て直した割り当て(第2の割り当て)を行う。   The part then gives a second priority 38 to each variable based on the loop portion. The same unit further sets the first variable to any one of the second variables (fourth variable) whose second priority 38 is higher than the second priority 38 of any first variable. Among the variables, the global register assigned to any variable (third variable) whose second priority 38 is lower than the second priority 38 of the fourth variable is reassigned (second Assignment).

そして、同部は、ループ部分からは第2の割り当てに従ったコード24を、他の部分からは第1の割り当てに従ったコード24を生成する。   Then, the same part generates a code 24 according to the second assignment from the loop part and a code 24 according to the first assignment from the other part.

なお、プログラム20は、第2の中間言語形式プログラム23であってもよいが、それに限定されない。プログラム20の変数にレジスタ割り当てが可能な形式であれば良い。例えば、プログラム20は、レジスタ番号以外はオブジェクト形式プログラム25と同一形式であっても良い。   The program 20 may be the second intermediate language format program 23, but is not limited thereto. Any format that allows register allocation to the variables of the program 20 may be used. For example, the program 20 may have the same format as the object format program 25 except for register numbers.

図1は、本発明の第1の実施形態にかかるコンパイル装置10の構成図である。FIG. 1 is a configuration diagram of a compiling device 10 according to the first embodiment of the present invention. 図2は、変数表30の構成を示す。FIG. 2 shows the configuration of the variable table 30. 図3は、パラメータ表40の構成を示す。FIG. 3 shows the configuration of the parameter table 40. 図4は、レジスタ割り当て部13の概略フローチャートである。FIG. 4 is a schematic flowchart of the register allocation unit 13. 図5は、レジスタ割り当て部13の変数登録処理のフローチャートである。FIG. 5 is a flowchart of the variable registration process of the register allocation unit 13. 図6は、レジスタ割り当て部13のグローバルレジスタ割り当て処理のフローチャートである。FIG. 6 is a flowchart of the global register allocation process of the register allocation unit 13. 図7は、レジスタ割り当て部13の否グローバルレジスタ割り当て処理のフローチャート(1/3)である。FIG. 7 is a flowchart (1/3) of the non-global register allocation process of the register allocation unit 13. 図8は、レジスタ割り当て部13の否グローバルレジスタ割り当て処理のフローチャート(2/3)である。FIG. 8 is a flowchart (2/3) of the non-global register allocation process of the register allocation unit 13. 図9は、レジスタ割り当て部13の否グローバルレジスタ割り当て処理のフローチャート(3/3)である。FIG. 9 is a flowchart (3/3) of the non-global register allocation process of the register allocation unit 13. 図10は、レジスタ割り当て部13のコード生成処理のフローチャートである。FIG. 10 is a flowchart of the code generation process of the register allocation unit 13. 図11は、本発明の第2の実施形態にかかる、レジスタ割り当て部13のグローバルレジスタ割り当て処理のフローチャートである。FIG. 11 is a flowchart of global register allocation processing of the register allocation unit 13 according to the second embodiment of the present invention. 図12は、本発明にかかるコンパイル装置10の基本的な構成を示す。FIG. 12 shows a basic configuration of the compiling device 10 according to the present invention.

符号の説明Explanation of symbols

10 コンパイル装置
11 フロントエンド
12 最適化部
13 レジスタ割り当て部
14 コードスケジューラ
15 出力部
19 コンパイラ
20 プログラム
21 ソース形式プログラム
22 第1の中間言語形式プログラム
23 第2の中間言語形式プログラム
24 コード
25 オブジェクト形式プログラム
30 変数表
31 ID
32 定義箇所
33 参照箇所
34 第1の優先度
35 第1の割り当てレジスタ番号
36 参照ループデータ
37 範囲
38 第2の優先度
39 第2の割り当てレジスタ番号
40 パラメータ表
41 グローバルレジスタ数
42 否グローバルレジスタ数
DESCRIPTION OF SYMBOLS 10 Compile apparatus 11 Front end 12 Optimization part 13 Register allocation part 14 Code scheduler 15 Output part 19 Compiler 20 Program 21 Source format program 22 1st intermediate language format program 23 2nd intermediate language format program 24 Code 25 Object format program 30 variable table 31 ID
32 Definition part 33 Reference part 34 First priority 35 First allocation register number 36 Reference loop data 37 Range 38 Second priority 39 Second allocation register number 40 Parameter table 41 Number of global registers 42 Number of global registers

Claims (17)

ループとその他の部分からなるプログラムを入力して、
前記ループおよびその他の部分に基づいて前記プログラムの各変数に第1の優先度を与
え、第1の優先度の高い順に所定数の前記変数(第1の変数)にグローバルレジスタを、
残りの前記変数(第2の変数)にグローバルレジスタを割り当てる割り当て(第1の割
り当て)を行い、
前記ループ部分に基づいて各前記変数に第2の優先度を与え、前記第2の変数のうち、
前記第2の優先度が、何れかの前記第1の変数の前記第2の優先度より高い何れかの変数
(第4の変数)に、前記第1の変数のうち、前記第2の優先度が、前記第4の変数の前記
第2の優先度より低い何れかの変数(第3の変数)に割り当てた前記グローバルレジスタ
を割り当て直した割り当て(第2の割り当て)を行い、
前記ループ部分からは前記第2の割り当てに従ったコードを、前記他の部分からは前記
第1の割り当てに従ったコードを生成するレジスタ割り当て部を備えるコンパイル装置。
Enter a program consisting of a loop and other parts,
A first priority is given to each variable of the program based on the loop and other parts, a global register is assigned to a predetermined number of the variables (first variables) in order of the first priority,
Assign the first variable to assign a non- global register to the remaining variable (second variable);
Giving each variable a second priority based on the loop portion, of the second variable,
The second priority among the first variables is set to any variable (fourth variable) whose second priority is higher than the second priority of any of the first variables. Assigning (second assignment) by reassigning the global register assigned to any variable (third variable) whose degree is lower than the second priority of the fourth variable;
A compiling apparatus comprising a register allocation unit that generates code according to the second allocation from the loop portion and generates code according to the first allocation from the other portion.
前記コードの前記ループ部分の入り口に前記第4の変数のスピル命令を挿入する前記レジ
スタ割り当て部と
前記コードの並べ替えを行うコードスケジューラを備える請求項1のコンパイル装置。
The compiling device according to claim 1, further comprising: the register allocation unit that inserts a spill instruction of the fourth variable at an entrance of the loop portion of the code; and a code scheduler that rearranges the code.
前記レジスタ割り当て部は、前記ループにおいて、前記変数の定義箇所と参照箇所の間の
呼び出し命令の数が多いほど、高い前記第2の優先度を前記変数に与える請求項1または
2のコンパイル装置。
3. The compiling device according to claim 1, wherein the register allocation unit gives the second priority higher to the variable as the number of calling instructions between the definition part and the reference part of the variable increases in the loop.
前記レジスタ割り当て部は、前記ループにおいて、前記変数の定義または参照がある場合
に無い場合より、高い前記第2の優先度を前記変数に与える請求項1乃至3の何れかのコ
ンパイル装置。
The compiling device according to any one of claims 1 to 3, wherein the register allocation unit gives the variable a second priority that is higher than when there is no definition or reference of the variable in the loop.
前記レジスタ割り当て部は、前記第2の変数の定義箇所と参照箇所の間に呼び出し命令が
存在する基本ブロックの入り口で、前記第2の変数のスピル命令を前記コードに挿入する
請求項1乃至4の何れかのコンパイル装置。
5. The register allocating unit inserts a spill instruction of the second variable into the code at an entrance of a basic block where a call instruction exists between a definition location and a reference location of the second variable. Any compile device.
前記レジスタ割り当て部は、前記ループおよびその他の部分において、前記変数の定義箇
所と参照箇所の間の呼び出し命令の数が多いほど、前記変数の定義箇所または参照箇所を
含むループ回数が多いほど、高い前記第1の優先度を前記変数に与える請求項1乃至5の
何れかのコンパイル装置。
In the loop and other parts, the register allocating unit is higher as the number of calling instructions between the definition part and the reference part of the variable is larger and the number of loops including the definition part or the reference part of the variable is larger 6. The compiling device according to claim 1, wherein the first priority is given to the variable.
前記プログラムのソースを入力して構文解析を行い、第1の中間言語を出力するフロント
エンドと、
前記第1の中間言語を入力して共通処理削除を行い、第2の中間言語を出力する最適化
部と、
前記第2の中間言語を入力して、第3の中間言語形式プログラムを前記コードとして出
力する前記レジスタ割り当て部と、
前記コードスケジューラと、
前記第3の中間言語形式プログラムを入力してオブジェクトを出力する出力部を備える
、請求項1乃至6の何れかのコンパイル装置。
A front end for inputting the source of the program, performing syntax analysis, and outputting a first intermediate language;
An optimization unit that inputs the first intermediate language, deletes common processing, and outputs a second intermediate language;
The register allocating unit for inputting the second intermediate language and outputting a third intermediate language format program as the code;
The code scheduler;
7. The compiling device according to claim 1, further comprising an output unit that inputs the third intermediate language format program and outputs an object.
コンピュータに、
ループとその他の部分からなるプログラムを入力して、
前記ループおよびその他の部分に基づいて前記プログラムの各変数に第1の優先度を与
え、第1の優先度の高い順に所定数の前記変数(第1の変数)にグローバルレジスタを、残りの前記変数(第2の変数)にグローバルレジスタを割り当てる割り当て(第1の割
り当て)を行い、
前記ループ部分に基づいて各前記変数に第2の優先度を与え、前記第2の変数のうち、
前記第2の優先度が、何れかの前記第1の変数の前記第2の優先度より高い何れかの変数
(第4の変数)に、前記第1の変数のうち、前記第2の優先度が、前記第4の変数の前記
第2の優先度より低い何れかの変数(第3の変数)に割り当てた前記グローバルレジスタ
を割り当て直した割り当て(第2の割り当て)を行い、
前記ループ部分からは前記第2の割り当てに従ったコードを、前記他の部分からは前記
第1の割り当てに従ったコードを生成するレジスタ割り当てを実行させるコンパイラ。
On the computer,
Enter a program consisting of a loop and other parts,
A first priority is given to each variable of the program based on the loop and other parts, a global register is assigned to a predetermined number of the variables (first variables) in order of the first priority, and the remaining variables Assign the first variable to assign a non- global register to the variable (second variable)
Giving each variable a second priority based on the loop portion, of the second variable,
The second priority among the first variables is set to any variable (fourth variable) whose second priority is higher than the second priority of any of the first variables. Assigning (second assignment) by reassigning the global register assigned to any variable (third variable) whose degree is lower than the second priority of the fourth variable;
A compiler that executes code assignment according to the second assignment from the loop portion and register assignment that generates code according to the first assignment from the other portion.
前記コンピュータに、
前記コードの前記ループ部分の入り口に前記第4の変数のスピル命令を挿入する前記レ
ジスタ割り当て処理と
前記コードの並べ替えを行うコードスケジュール処理を実行させる請求項8のコンパイ
ラ。
In the computer,
The compiler according to claim 8, wherein the register allocation process for inserting the spill instruction of the fourth variable at the entrance of the loop portion of the code and the code schedule process for rearranging the code are executed.
前記コンピュータに、
前記ループにおいて、前記変数の定義箇所と参照箇所の間の呼び出し命令の数が多いほ
ど、高い前記第2の優先度を前記変数に与える前記レジスタ割り当て処理を実行させる請
求項8または9のコンパイラ。
In the computer,
10. The compiler according to claim 8, wherein, in the loop, as the number of calling instructions between the definition part and the reference part of the variable increases, the register allocation processing that gives the second priority higher to the variable is executed.
前記コンピュータに、
前記ループにおいて、前記変数の定義または参照がある場合に無い場合より、高い前記
第2の優先度を前記変数に与える前記レジスタ割り当て処理を実行させる請求項8乃至1
0の何れかのコンパイラ。
In the computer,
The register allocation processing for giving the second priority higher to the variable than when there is no definition or reference of the variable in the loop is executed.
0 compiler.
前記コンピュータに、
前記第2の変数の定義箇所と参照箇所の間に呼び出し命令が存在する基本ブロックの入り
口で、前記第2の変数のスピル命令を前記コードに挿入する前記レジスタ割り当て処理を
実行させる請求項8乃至11の何れかのコンパイラ。
In the computer,
9. The register allocation processing for inserting the spill instruction of the second variable into the code is executed at the entrance of a basic block where a call instruction exists between the definition location and the reference location of the second variable. Any one of 11 compilers.
前記コンピュータに、
前記ループおよびその他の部分において、前記変数の定義箇所と参照箇所の間の呼び出し
命令の数が多いほど、前記変数の定義箇所または参照箇所を含むループ回数が多いほど、
高い前記第1の優先度を前記変数に与える前記レジスタ割り当て処理を実行させる請求項
8乃至12の何れかのコンパイラ。
In the computer,
In the loop and other parts, the more the number of calling instructions between the definition part and the reference part of the variable, the more the number of loops including the definition part or the reference part of the variable,
The compiler according to any one of claims 8 to 12, wherein the register allocation processing for giving the variable the first priority to the variable is executed.
前記コンピュータに、
前記プログラムのソースを入力して構文解析を行い、第1の中間言語を出力するフロン
トエンド処理と、
前記第1の中間言語を入力して共通処理削除を行い、第2の中間言語を出力する最適化
処理と、
前記第2の中間言語を入力して、第3の中間言語形式プログラムを前記コードとして出
力する前記レジスタ割り当て処理と、
前記コードスケジュール処理と、
前記第3の中間言語形式プログラムを入力してオブジェクトを出力する出力処理を実行
させる請求項8乃至13の何れかのコンパイラ。
In the computer,
Front-end processing for inputting the source of the program, performing syntax analysis, and outputting a first intermediate language;
An optimization process for inputting the first intermediate language, deleting a common process, and outputting a second intermediate language;
The register allocation processing for inputting the second intermediate language and outputting a third intermediate language format program as the code;
The code schedule processing;
14. The compiler according to claim 8, wherein the third intermediate language format program is input to execute an output process for outputting an object.
コンピュータが、
ループとその他の部分からなるプログラムを入力して、 前記ループおよびその他の部分に基づいて前記プログラムの各変数に第1の優先度を与
え、第1の優先度の高い順に所定数の前記変数(第1の変数)にグローバルレジスタを、
残りの前記変数(第2の変数)にグローバルレジスタを割り当てる割り当て(第1の割
り当て)を行い、
前記ループ部分に基づいて各前記変数に第2の優先度を与え、前記第2の変数のうち、
前記第2の優先度が、何れかの前記第1の変数の前記第2の優先度より高い何れかの変数
(第4の変数)に、前記第1の変数のうち、前記第2の優先度が、前記第4の変数の前記
第2の優先度より低い何れかの変数(第3の変数)に割り当てた前記グローバルレジスタ
を割り当て直した割り当て(第2の割り当て)を行い、
前記ループ部分からは前記第2の割り当てに従ったコードを、前記他の部分からは前記
第1の割り当てに従ったコードを生成するレジスタ割り当て行程を有するコンパイル方法
Computer
A program consisting of a loop and other parts is input, a first priority is given to each variable of the program based on the loop and other parts, and a predetermined number of the variables (in order of the first priority) ( The global register in the first variable)
Assign the first variable to assign a non- global register to the remaining variable (second variable);
Giving each variable a second priority based on the loop portion, of the second variable,
The second priority among the first variables is set to any variable (fourth variable) whose second priority is higher than the second priority of any of the first variables. Assigning (second assignment) by reassigning the global register assigned to any variable (third variable) whose degree is lower than the second priority of the fourth variable;
A compiling method comprising a register allocation step of generating a code according to the second allocation from the loop portion and a code according to the first allocation from the other portion.
前記コンピュータが、
前記コードの前記ループ部分の入り口に前記第4の変数のスピル命令を挿入する前記レ
ジスタ割り当て行程と
前記コードの並べ替えを行うコードスケジュール行程を有する請求項15のコンパイル
方法。
The computer is
The compiling method according to claim 15, further comprising: a register allocation process for inserting the spill instruction of the fourth variable at an entrance of the loop portion of the code; and a code schedule process for rearranging the code.
前記コンピュータが、
前記ループにおいて、前記変数の定義箇所と参照箇所の間の呼び出し命令の数が多いほ
ど、高い前記第2の優先度を前記変数に与える前記レジスタ割り当て行程を有する請求項
15または16のコンパイル方法。
The computer is
17. The compiling method according to claim 15, further comprising: the register allocation step of giving the second priority higher to the variable as the number of calling instructions between the definition portion and the reference portion of the variable is larger in the loop.
JP2008155192A 2008-06-13 2008-06-13 Compiling device, compiler, and compiling method Expired - Fee Related JP5208589B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2008155192A JP5208589B2 (en) 2008-06-13 2008-06-13 Compiling device, compiler, and compiling method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2008155192A JP5208589B2 (en) 2008-06-13 2008-06-13 Compiling device, compiler, and compiling method

Publications (2)

Publication Number Publication Date
JP2009301326A JP2009301326A (en) 2009-12-24
JP5208589B2 true JP5208589B2 (en) 2013-06-12

Family

ID=41548147

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2008155192A Expired - Fee Related JP5208589B2 (en) 2008-06-13 2008-06-13 Compiling device, compiler, and compiling method

Country Status (1)

Country Link
JP (1) JP5208589B2 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP5402752B2 (en) * 2010-03-19 2014-01-29 富士通株式会社 Compiling device and compiling program

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPS63225829A (en) * 1987-03-13 1988-09-20 Fujitsu Ltd Global register assignment system
JP3239907B2 (en) * 1993-01-20 2001-12-17 富士ゼロックス株式会社 Register allocation method
JP3311462B2 (en) * 1994-02-23 2002-08-05 富士通株式会社 Compile processing unit
JP3405696B2 (en) * 1999-08-19 2003-05-12 インターナショナル・ビジネス・マシーンズ・コーポレーション Compiling apparatus and method
JP3871312B2 (en) * 2002-02-27 2007-01-24 インターナショナル・ビジネス・マシーンズ・コーポレーション Program conversion method, data processing apparatus using the same, and program
JP3956112B2 (en) * 2002-06-12 2007-08-08 インターナショナル・ビジネス・マシーンズ・コーポレーション Compiler, register allocation device, program, recording medium, compilation method, and register allocation method
JP2004021344A (en) * 2002-06-12 2004-01-22 Nec Corp Compiler, and register assignment method to in-loop variable
JP2004227025A (en) * 2003-01-17 2004-08-12 Fujitsu Ltd Spill code issuance position specification method, device and program

Also Published As

Publication number Publication date
JP2009301326A (en) 2009-12-24

Similar Documents

Publication Publication Date Title
JP4957729B2 (en) Program parallelization method, program parallelization apparatus and program
US8266603B2 (en) Technique for allocating register to variable for compiling
US9652286B2 (en) Runtime handling of task dependencies using dependence graphs
US8122442B2 (en) Method and system for array optimization
JP3901180B2 (en) Program parallelization apparatus and method, and program
US20140053129A1 (en) Parallelization of Dataflow Actors with Local State
US20110119660A1 (en) Program conversion apparatus and program conversion method
JP2007506199A5 (en)
US20100229161A1 (en) Compile method and compiler
US7827542B2 (en) Compiler apparatus
JP2008009957A (en) Compiling device
WO2024131097A1 (en) Neural network model compilation method and apparatus, and electronic device and storage medium
US20090164773A1 (en) Dynamic reconfiguration supporting method, dynamic reconfiguration supporting apparatus, and dynamic reconfiguration system
JP5146134B2 (en) Compile processing device, access pattern change processing method, and processing program
US20090187897A1 (en) Compiling method and compiling program
US8612958B2 (en) Program converting apparatus and program conversion method
JP5208589B2 (en) Compiling device, compiler, and compiling method
JP2005129001A (en) Apparatus and method for program execution, and microprocessor
JP5038760B2 (en) Source code conversion apparatus and source code conversion method
JP2008305337A (en) Program converter, program conversion method, program, storage medium, debugging device, debugging method and program development system
Baloukas et al. Mapping embedded applications on MPSoCs: the MNEMEE approach
Kumar Comparison of instruction scheduling and register allocation for Mips And Hpl-Pd architecture for exploitation of instruction level parallelism
JP2011180814A (en) Compiler apparatus, compiling method and program
JP2011181114A (en) Device and method for converting program, and recording medium
JP2009064207A (en) Compiler

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20110310

RD01 Notification of change of attorney

Free format text: JAPANESE INTERMEDIATE CODE: A7421

Effective date: 20110712

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20121016

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20121113

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20130107

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20130129

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20130220

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

Free format text: PAYMENT UNTIL: 20160301

Year of fee payment: 3

R150 Certificate of patent or registration of utility model

Ref document number: 5208589

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

Free format text: JAPANESE INTERMEDIATE CODE: R150

S111 Request for change of ownership or part of ownership

Free format text: JAPANESE INTERMEDIATE CODE: R313111

R350 Written notification of registration of transfer

Free format text: JAPANESE INTERMEDIATE CODE: R350

LAPS Cancellation because of no payment of annual fees