JP4579425B2 - Information processing device - Google Patents
Information processing device Download PDFInfo
- Publication number
- JP4579425B2 JP4579425B2 JP2001006492A JP2001006492A JP4579425B2 JP 4579425 B2 JP4579425 B2 JP 4579425B2 JP 2001006492 A JP2001006492 A JP 2001006492A JP 2001006492 A JP2001006492 A JP 2001006492A JP 4579425 B2 JP4579425 B2 JP 4579425B2
- Authority
- JP
- Japan
- Prior art keywords
- loop
- branch
- code
- source code
- word
- 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
Links
Images
Landscapes
- Devices For Executing Special Programs (AREA)
Description
【0001】
【発明の属する技術分野】
本発明は情報処理装置に関し、特に、ソースコードをコンパイルしてオブジェクトコードを生成する情報処理装置に関する。
【0002】
【従来の技術】
プログラムを最適化する方法は従来から種々提案されている。例えば、その一例として、多重ループを単一ループに変換する方法やインデックスを入れ換える方法がある。
【0003】
図7は、前者の多重ループを単一ループに変換する方法を説明する図である。
図7(A)に示すソースプログラムでは、行番号“01”において、2行2列で要素数がそれぞれ“10”である実数型の行列A,B,Cが宣言されている。
【0004】
行番号“02”には、インデックスJを“1”から“10”までカウントアップするループが記述されており、これは行番号“06”を終端とするループである。また、行番号“03”には、インデックスIを1から10までカウントアップするループが記述されており、これは行番号“05”を終端とするループである。従って、このソースプログラムは、インデックスI,Jによる2重ループが形成されている。
【0005】
行番号“04”では、配列Bの要素(I,J)と配列Cの要素(I,J)を加算した値を配列Aの要素(I,J)に対して格納する演算が実行される。
このような2重ループに対しては、図7(B)に示すように、インデックスIおよびインデックスJをまとめてインデックスIJとし、これを1から100までカウントアップする1重ループに変換することにより、変数の数を減らして処理を高速化することができる。
【0006】
図8は、後者のインデックスを入れ換える方法を説明する図である。
図8(A)に示すソースコードは、図7(A)の場合と同様である。この例では、図8(B)に示すように、内側と外側のインデックスを入れ換えることにより、メモリへのアクセスを連続にし、最適化を図っている。即ち、2次元配列は、メモリ上の連続した領域に確保されるので、この領域へのアクセスが連続して行われるようにインデックスの入れ換えを行う。
【0007】
なお、以上の例は、2重ループを例に挙げて説明したが、それ以上の多重ループの場合にも前述の方法によって同様の効果を得ることができる。
【0008】
【発明が解決しようとする課題】
しかし、以上のような多重ループの最適化方法は、外側ループと内側ループの間(以下、セカンダリと称す)に分岐を伴う命令(分岐言)が存在しないことが条件となる。従って、セカンダリに分岐言が存在している場合には、最適化ができないという問題点があった。
【0009】
本発明は、このような点に鑑みてなされたものであり、セカンダリに分岐言を含む多重ループであっても最適化することが可能な情報処理装置を提供することを目的とする。
【0010】
【課題を解決するための手段】
本発明では上記課題を解決するために、ソースコードをコンパイルしてオブジェクトコードを生成する情報処理装置において、外側ループと内側ループの間に分岐命令である分岐言を有する2重ループを、前記分岐言がループ外への分岐ではないこと、前記分岐言以前に変数または配列の定義が存在しないこと、ループ内に前記分岐言が複数含まれていないこと、の条件を満たす場合に前記ソースコードから検出するループ検出手段と、前記分岐言の真率を算定するソースコードである真率算定コードを生成して前記ソースコードに付加する真率算定コード生成手段と、前記分岐言を除く2重ループのソースコードを無分岐言ループコードとして前記ソースコードに複写する複写手段と、前記真率が100%である場合には、前記無分岐言ループコードに分岐し、それ以外の場合には分岐言を含むもとの2重ループに分岐する分岐コードを生成して前記ソースコードに付加する分岐コード生成手段と、前記無分岐言ループコードを最適化する最適化手段と、を有することを特徴とする情報処理装置が提供される。
【0012】
【発明の実施の形態】
以下、本発明の実施の形態を図面を参照して説明する。
図1は、本発明の実施の形態の構成例を示すブロック図である。この図において、記憶装置1はコンパイル処理の対象となるソースコードを格納している。
【0013】
多重ループ検出手段2は、セカンダリに分岐言を有する多重ループを記憶装置1から供給されたソースコードから検出する。
真率算定コード生成手段3は、多重ループに含まれている分岐言の真率を算定するコードである真率算定コードを生成してソースコードに付加する。
【0014】
複写手段4は、分岐言を除く多重ループのコードを無分岐言ループコードとしてソースコードに複写する。
分岐コード生成手段5は、真率が100%である場合には、無分岐言ループコードに分岐し、それ以外の場合には分岐言を含むもとの多重ループに分岐する分岐コードを生成してソースコードに付加する。
【0015】
最適化手段6は、無分岐言ループコードを最適化する。
次に、以上の実施の形態の動作について説明する。先ず、以下では、図2を参照して本発明の動作原理を簡単に説明した後、具体的な動作について説明する。
【0016】
図2(A)は、最適化の対象とするソースコードの一例を示す図である。このソースコードでは、行番号“01”において、要素数が“10”の実数型1次元配列Cが宣言されており、また、行番号“02”において、要素数が10×10の実数型2次元配列A,Bが宣言されている。
【0017】
また、行番号“03”には、インデックスIを1から10までカウントアップするループが記述されており、これは行番号“09”を終端とするループである。また、行番号“05”には、インデックスJを1から10までカウントアップするループが記述されており、これは行番号“07”を終端とするループである。従って、このソースプログラムは、インデックスI,Jによる2重ループが形成されている。
【0018】
行番号“04”には、判断命令が記述されており、これは、配列Cの第I番目の要素が“1”よりも大きい場合にのみ行番号“05”から行番号“07”までの処理に分岐する判断命令である。従って、これは分岐言である。
【0019】
ここで、分岐言の条件が全ての場合において必ず真ならば、図2(A)は、図2(B)に示すように簡略化することができる。この場合には、セカンダリに分岐言を含まない通常の多重ループであるので、前述の何れかの方法により最適化することができる。
【0020】
本発明ではこのように、多重ループのセカンダリに存在している分岐言が全ての場合において真であるか否かを判定し、真である場合にはその分岐言を除外して得られた多重ループを最適化したものを実行し、それ以外の場合にはもとの多重ループ(分岐言を含む多重ループ)を実行する。
【0021】
次に、図1に示す実施例の具体的な動作を図2(A)に示すソースコードを例に挙げて説明する。
いま、記憶装置1には、図2(A)に示すソースコードが格納されており、このソースコードをコンパイルの対象として処理が開始されたとすると、多重ループ検出手段2は、記憶装置1から該当するソースコードを読み込み、セカンダリに分岐言を有する多重ループを検出する。
【0022】
真率算定コード生成手段3は、多重ループ検出手段2によって検出された分岐言をセカンダリに含む多重ループから、分岐言を抽出するとともにインデックスの値の変化を参照して分岐言の真率を算定するソースコードである真率算定コード生成する。
【0023】
真率算定コードの一例を図3の行番号“01”から“05”に示す。この例では、行番号“01”において、変数MASK2が宣言されるとともにその初期値が“0”に設定されている。
【0024】
行番号“02”には、インデックスI’を1から10までカウントアップするループが記述されており、これは行番号“05”を終端とするループである。
ループ間である、行番号“03”には、「配列Cの第I’番目の要素が“1”以下である」という命題に対する真理値が変数MASK1に格納される。従って、配列Cの第I’番目の要素が“1”より大きい場合(図2(A)の行番号“04”に示す分岐言が真となる場合)にはこの命題は偽となるので、MASK1には“0”が代入される。
【0025】
行番号“04”では、変数MASK2に対してMASK1の値が累積加算される。従って、行番号“03”の命題が全て偽である場合(即ち、図2(A)の行番号“04”に示す分岐言が全て真となる場合)には、変数MASK2の値は“0”となる。
【0026】
次に、複写手段4は、対象となる多重ループを取得してその中から分岐言を除外する。そして、得られた多重ループのコードを、無分岐言ループコードとしてソースコードに複写する。
【0027】
無分岐言ループコードの一例を図3の行番号“19”から“23”に示す。この例では、図2(A)に示す2重ループから行番号“04”の分岐言が除外されたコードが複写されている。
【0028】
次に、分岐コード生成手段5は、真率が100%である場合には、無分岐言ループコードに分岐し、それ以外の場合には分岐言を含むもとの多重ループに分岐する分岐コードを生成してソースコードに付加する。
【0029】
無分岐言ループコードの一例を図3の行番号“07”に示す。この例では、変数MASK2の値が“0”である場合、即ち、全ての場合において図2(A)の行番号“04”に示す分岐言が真である場合には行番号“19”に進み、それ以外の場合には行番号“09”以降の処理が実行される。なお、行番号“09”から“15”までは、もとのソースコードであり、分岐言がセカンダリに含まれている。従って、変数MASK2の値が“0”以外である場合には通常の処理が実行される。
【0030】
なお、分岐コード生成手段5は、行番号“17”に対して新たな分岐命令(無条件分岐命令)を付加しているので、行番号“09”から行番号“15”の処理が終了した場合には、行番号“25”に無条件に分岐し、行番号“19”以降の処理の実行を中止する。
【0031】
最適化手段6は、以上のようにして生成されたソースコードに含まれている、無分岐言ループ(セカンダリに分岐言を有しない通常の多重ループ)を検出して、これを前述した方法の何れかによって最適化する。
【0032】
コンパイル部7は、最適化手段6によって最適化された部分を含むソースコードをコンパイルしてオブジェクトコードを生成し、記憶装置8に供給してそこに記憶させる。
【0033】
次に、以上の処理によって生成されたソースコードの概要について説明する。
図4は、図2(A)に示すソースコードの行番号“03”から“09”までの処理の流れを模式的に示した図である。この図において、白丸「○」は、各行に記述されたコードに対応しており、また矢印は処理の流れを示している。この図に示すように、“#1”と“#7”は外側のループを構成しており、また、“#3”と“#5”は、内側のループを構成している。更に、“#2”は分岐言であり、判断の結果に応じて“#3”または“#6”に分岐する。
【0034】
図5は、図3に示すソースコードの処理の流れを模式的に示す図である。この図において黒丸「●」は、新たに追加されたコードを示している。即ち、“#A”は、図3に示す行番号“01”から“07”までに対応している。“#B”は、図3に示す行番号“17”に対応している。“#1’”から“#7’”は、図3に示す行番号“19”から“23”までに対応しており無分岐言ループである。また、“#C”は、図3に示す行番号“25”の「END」に対応している。
【0035】
このソースコードが実行されると、先ず、“#A”の分岐コードにより真率が算定され、真率が“100%”である場合には“#1’”に進み、それ以外の場合には“#1”以降の処理が実行される。なお、“#1”以降の処理が実行された場合には、“#B”において無条件に“#C”に分岐して処理を終了する。
【0036】
また、“#1’”に分岐した場合には、無分岐言ループ(最適化されたループ)が実行されることになる。
以上の処理によれば、セカンダリに分岐言を有する多重ループがソースコードに存在している場合には、分岐言の真率を算定する真率算定コードと、分岐言を除く多重ループのソースコード(無分岐言ループコード)と、真率が100%である場合には、無分岐言ループコードに分岐し、それ以外の場合には分岐言を含むもとの多重ループに分岐する分岐言をソースコードに付加し、無分岐言ループコードに対しては最適化を施すようにしたので、セカンダリに分岐言を含むソースコードを最適化することが可能となる。
【0037】
最後に、図6を参照して、図1に示す実施の形態において実行される処理の一例について説明する。
[S1]多重ループ検出手段2は、記憶装置1に記憶されているソースコードから多重ループを検出した場合にはステップS2に進み、それ以外の場合にはステップS1に戻って同様の処理を繰り返す。
[S2]多重ループ検出手段2は、ステップS1において検出した多重ループがセカンダリに分岐言を含むか否かを判定し、分岐言を含む場合にはステップS3に進み、それ以外の場合にはステップS2に戻って同様の処理を繰り返す。
[S3]多重ループ検出手段2は、検出した多重化ループが後述する条件を満足しているか否かを判定し、満足している場合にはステップS4に進み、それ以外の場合にはステップS1に戻って同様の処理を繰り返す。
【0038】
ここで、判断の条件を以下に示す。
(1)ループ内の分岐命令は1つである。
(2)ループからの飛び出しになる分岐ではない。
(3)分岐命令以前に変数または配列への定義がない。
(4)分岐命令はセカンダリに存在する。
【0039】
なお、このような条件を課すのは、ループの最適化によって削減されるコストよりも新たに発生するコストの方が高くつくことを防止するためである。例えば、(1)の例では、分岐命令が複数存在する場合には、全ての分岐命令に対して真率を求める必要が生じ、そのコストの方が最適化によるコストの削減を上回る場合が想定されるからである。
[S4]複写手段4は、ソースコードから分岐言を除くループを取得する。
[S5]複写手段4は、ステップS4で取得した分岐言を除くループ(無分岐言ループ)をソースコードに対して複写する。
[S6]分岐コード生成手段5は、ソースコードから分岐言を取得する。
[S7]分岐コード生成手段5は、真率算定コードを生成してソースコードに付加する。
[S8]分岐コード生成手段5は、分岐コードを生成してソースコードに付加する。
[S9]情報処理装置は、処理を継続するか否かを判定し、継続する場合にはステップS1に戻って前述の場合と同様の処理を繰り返し、それ以外の場合にはステップS10に進む。
[S10]最適化手段6は、無分岐言ループコードに対して最適化処理を施す。
【0040】
なお、この最適化処理は、図7または図8を参照して説明した2種類の最適化処理の何れを用いてもよい。
[S11]コンパイル部7は、最適化されたソースコードに対してコンパイル処理を施し、得られたオブジェクトコードを記憶装置8に対して出力する。
【0041】
以上の処理によれば、図1に示す実施の形態の動作を実現することが可能となる。
なお、以上の実施の形態では、2重ループの場合を例に挙げて説明したが、3重ループ以上の場合にも本発明を適用することができることはいうまでもない。
【0042】
最後に、上記の処理機能は、コンピュータによって実現することができる。その場合、情報処理装置が有すべき機能の処理内容は、コンピュータで読み取り可能な記録媒体に記録されたプログラムに記述されており、このプログラムをコンピュータで実行することにより、上記処理がコンピュータで実現される。コンピュータで読み取り可能な記録媒体としては、磁気記録装置や半導体メモリ等がある。市場へ流通させる場合には、CD−ROM(Compact Disk Read Only Memory)やフロッピーディスク等の可搬型記録媒体にプログラムを格納して流通させたり、ネットワークを介して接続されたコンピュータの記憶装置に格納しておき、ネットワークを通じて他のコンピュータに転送することもできる。コンピュータで実行する際には、コンピュータ内のハードディスク装置等にプログラムを格納しておき、メインメモリにロードして実行する。
【0043】
【発明の効果】
以上説明したように本発明では、ソースコードをコンパイルしてオブジェクトコードを生成する情報処理装置において、セカンダリに分岐言を有する多重ループをソースコードから検出する多重ループ検出手段と、分岐言の真率を算定するソースコードである真率算定コードを生成してソースコードに付加する真率算定コード生成手段と、分岐言を除く多重ループのソースコードを無分岐言ループコードとしてソースコードに複写する複写手段と、真率が100%である場合には、無分岐言ループコードに分岐し、それ以外の場合には分岐言を含むもとの多重ループに分岐する分岐コードを生成してソースコードに付加する分岐コード生成手段と、無分岐言ループコードを最適化する最適化手段と、を有するようにしたので、セカンダリに分岐言を有する多重ループを最適化することが可能となる。
【図面の簡単な説明】
【図1】本発明の実施の形態の構成例を示すブロック図である。
【図2】本発明の動作原理を説明する図である。
【図3】図2に示すソースコードに対して最適化を施した場合に得られるソースコードの一例である。
【図4】図2(A)に示すソースコードの行番号“03”から“09”までの処理の流れを模式的に示した図である。
【図5】図3に示すソースコードの処理の流れを模式的に示す図である。
【図6】図1に示す実施の形態において実行される処理の一例を説明するフローチャートである。
【図7】多重ループを単一ループに変換する最適化方法を説明する図である。
【図8】多重ループのインデックスを入れ換える最適化方法を説明する図である。
【符号の説明】
1 記憶装置
2 多重ループ検出手段
3 真率算定コード生成手段
4 複写手段
5 分岐コード生成手段
6 最適化手段
7 コンパイル部
8 記憶装置[0001]
BACKGROUND OF THE INVENTION
The present invention relates to an information processing apparatus, and more particularly to an information processing apparatus that compiles a source code and generates an object code.
[0002]
[Prior art]
Various methods for optimizing programs have been proposed. For example, there are a method of converting a multiple loop into a single loop and a method of switching indexes.
[0003]
FIG. 7 is a diagram for explaining a method of converting the former multiple loop into a single loop.
In the source program shown in FIG. 7A, in the row number “01”, real type matrices A, B, and C each having “10” in 2 rows and 2 columns are declared.
[0004]
In the line number “02”, a loop for counting up the index J from “1” to “10” is described. This is a loop that ends at the line number “06”. The line number “03” describes a loop for counting up the index I from 1 to 10, and this is a loop ending with the line number “05”. Therefore, this source program has a double loop formed by indexes I and J.
[0005]
In the row number “04”, an operation for storing the value obtained by adding the element (I, J) of the array B and the element (I, J) of the array C for the element (I, J) of the array A is executed. .
For such a double loop, as shown in FIG. 7B, the index I and the index J are combined into an index IJ, which is converted into a single loop that counts up from 1 to 100. Reduce the number of variables to speed up the process.
[0006]
FIG. 8 is a diagram for explaining a method of replacing the latter index.
The source code shown in FIG. 8A is the same as that in FIG. In this example, as shown in FIG. 8B, the inner and outer indexes are interchanged, thereby making the access to the memory continuous and optimizing. That is, since the two-dimensional array is secured in a continuous area on the memory, the index is changed so that access to this area is continuously performed.
[0007]
Although the above example has been described by taking a double loop as an example, the same effect can be obtained by the above-described method even in the case of a multiple loop.
[0008]
[Problems to be solved by the invention]
However, the multi-loop optimization method as described above is conditional on that there is no instruction (branch word) that involves a branch between the outer loop and the inner loop (hereinafter referred to as secondary). Therefore, there is a problem that optimization cannot be performed when a branching word exists in the secondary.
[0009]
The present invention has been made in view of such a point, and an object of the present invention is to provide an information processing apparatus that can optimize even a multiple loop including a branch word in the secondary.
[0010]
[Means for Solving the Problems]
In the present invention, in order to solve the above problem, in an information processing apparatus that compiles source code and generates object code, a double loop having a branch word that is a branch instruction between an outer loop and an inner loop From the source code when the condition is not branching out of the loop, there is no variable or array definition before the branching statement, and there are no multiple branching statements in the loop. Loop detecting means for detecting; true rate calculating code generating means for generating a true rate calculating code which is a source code for calculating the true rate of the branch word; and adding to the source code; a double loop excluding the branch word A copy means for copying the source code of the source code into the source code as a non-branch word loop code, and when the true rate is 100%, Branch code generation means for generating a branch code that branches to the original code and branching to the original double loop that includes the branch language, and for adding the non-branch language loop code to the source code. There is provided an information processing apparatus characterized by having optimization means for converting the information processing apparatus.
[0012]
DETAILED DESCRIPTION OF THE INVENTION
Hereinafter, embodiments of the present invention will be described with reference to the drawings.
FIG. 1 is a block diagram showing a configuration example of an embodiment of the present invention. In this figure, the
[0013]
The multiple loop detection means 2 detects a multiple loop having a branch word in the secondary from the source code supplied from the
The true rate calculation code generation means 3 generates a true rate calculation code that is a code for calculating the true rate of the branching words included in the multiple loops and adds it to the source code.
[0014]
The copying means 4 copies the multi-loop code excluding the branching word into the source code as a non-branching word loop code.
The branch code generation means 5 generates a branch code that branches to a non-branch word loop code when the truth rate is 100%, and branches to the original multiple loop that includes the branch word otherwise. To the source code.
[0015]
The optimization means 6 optimizes the no-branch word loop code.
Next, the operation of the above embodiment will be described. First, the operation principle of the present invention will be briefly described with reference to FIG. 2 and then the specific operation will be described.
[0016]
FIG. 2A is a diagram illustrating an example of source code to be optimized. In this source code, a real type one-dimensional array C having the number of elements “10” is declared at the line number “01”, and a
[0017]
The line number “03” describes a loop that counts up the index I from 1 to 10, and this is a loop that ends at the line number “09”. The line number “05” describes a loop for counting up the index J from 1 to 10, which is a loop ending with the line number “07”. Therefore, this source program has a double loop formed by indexes I and J.
[0018]
In the line number “04”, a determination instruction is described. This is because the line number “05” to the line number “07” are only obtained when the I-th element of the array C is larger than “1”. This is a decision instruction that branches to processing. This is therefore a bifurcation.
[0019]
Here, if the branching condition is always true in all cases, FIG. 2A can be simplified as shown in FIG. In this case, since it is a normal multiple loop that does not include a branch word in the secondary, it can be optimized by any of the methods described above.
[0020]
In the present invention, as described above, it is determined whether or not the branch word existing in the secondary of the multiple loop is true in all cases, and if it is true, the multiple words obtained by excluding the branch word are obtained. The optimized loop is executed, otherwise the original multiple loop (multiple loop including a branch word) is executed.
[0021]
Next, the specific operation of the embodiment shown in FIG. 1 will be described using the source code shown in FIG. 2A as an example.
Now, if the source code shown in FIG. 2A is stored in the
[0022]
The true rate calculation code generation means 3 extracts the branch words from the multiple loop that includes the branch words detected by the multiple loop detection means 2 as secondary, and calculates the true rate of the branch words by referring to the change in the index value. The true rate calculation code that is the source code to be generated is generated.
[0023]
An example of the true rate calculation code is shown in line numbers “01” to “05” in FIG. In this example, in line number “01”, variable MASK2 is declared and its initial value is set to “0”.
[0024]
In the line number “02”, a loop for counting up the index I ′ from 1 to 10 is described. This is a loop that ends at the line number “05”.
In the row number “03” between the loops, a truth value for the proposition “the I'th element of the array C is“ 1 ”or less” is stored in the variable MASK1. Therefore, when the I'th element of the array C is larger than “1” (when the branching word indicated by the line number “04” in FIG. 2A is true), this proposition is false. “0” is assigned to MASK1.
[0025]
In the row number “04”, the value of MASK1 is cumulatively added to the variable MASK2. Therefore, when all the propositions of the line number “03” are false (that is, when all the branching words indicated by the line number “04” in FIG. 2A are true), the value of the variable MASK2 is “0”. "
[0026]
Next, the copying
[0027]
An example of the no-branch loop code is shown in line numbers “19” to “23” in FIG. In this example, the code in which the branching word with the line number “04” is excluded from the double loop shown in FIG.
[0028]
Next, the branch code generation means 5 branches to a non-branch word loop code if the true rate is 100%, and otherwise branches to the original multiple loop including the branch word. Is generated and added to the source code.
[0029]
An example of the no-branch loop code is shown in line number “07” in FIG. In this example, when the value of the variable MASK2 is “0”, that is, in all cases, the branching word indicated by the line number “04” in FIG. 2A is true, the line number “19” is set. In other cases, the process after the line number “09” is executed. Note that the line numbers “09” to “15” are the original source code, and branch words are included in the secondary. Therefore, when the value of the variable MASK2 is other than “0”, normal processing is executed.
[0030]
Since the branch
[0031]
The optimization means 6 detects a no-branch loop (a normal multiple loop that does not have a branch phrase in the secondary) included in the source code generated as described above, and this is detected by the method described above. Optimize by either.
[0032]
The compiling
[0033]
Next, an outline of the source code generated by the above processing will be described.
FIG. 4 is a diagram schematically showing the flow of processing from line numbers “03” to “09” of the source code shown in FIG. In this figure, white circles “◯” correspond to the codes described in each line, and arrows indicate the flow of processing. As shown in this figure, “# 1” and “# 7” constitute an outer loop, and “# 3” and “# 5” constitute an inner loop. Furthermore, “# 2” is a branching word and branches to “# 3” or “# 6” depending on the result of the determination.
[0034]
FIG. 5 is a diagram schematically showing the flow of processing of the source code shown in FIG. In this figure, a black circle “●” indicates a newly added code. That is, “#A” corresponds to the row numbers “01” to “07” shown in FIG. “#B” corresponds to the line number “17” shown in FIG. “# 1 ′” to “# 7 ′” correspond to the line numbers “19” to “23” shown in FIG. “#C” corresponds to “END” of the row number “25” shown in FIG.
[0035]
When this source code is executed, first, the true rate is calculated from the branch code of “#A”, and when the true rate is “100%”, the process proceeds to “# 1 ′”, otherwise The processes after “# 1” are executed. If the processing after “# 1” is executed, the processing branches to “#C” unconditionally at “#B” and the processing is terminated.
[0036]
Further, when branching to “# 1 ′”, a non-branch word loop (optimized loop) is executed.
According to the above processing, when a multiple loop having a branch word in the secondary exists in the source code, the true rate calculation code for calculating the true rate of the branch word and the source code of the multiple loop excluding the branch word (Unbranched word loop code) and if the true rate is 100%, branch to the unbranched word loop code, otherwise branch to the original multiple loop including the branched word Since it is added to the source code and optimization is performed on the no-branch word loop code, it is possible to optimize the source code including the branch word in the secondary.
[0037]
Finally, an example of processing executed in the embodiment shown in FIG. 1 will be described with reference to FIG.
[S1] The multiplex loop detection means 2 proceeds to step S2 if a multiplex loop is detected from the source code stored in the
[S2] The multiple loop detection means 2 determines whether or not the multiple loop detected in step S1 includes a branch word in the secondary. If the multiple loop includes the branch word, the process proceeds to step S3. Returning to S2, the same processing is repeated.
[S3] The multiplex loop detection means 2 determines whether or not the detected multiplex loop satisfies a condition to be described later. If satisfied, the process proceeds to step S4. Otherwise, the process proceeds to step S1. Go back to and repeat the same process.
[0038]
Here, the conditions for determination are shown below.
(1) There is one branch instruction in the loop.
(2) It is not a branch that jumps out of the loop.
(3) There is no definition for a variable or array before the branch instruction.
(4) The branch instruction exists in the secondary.
[0039]
The reason for imposing such a condition is to prevent the newly generated cost from becoming more expensive than the cost reduced by the loop optimization. For example, in the example of (1), when there are a plurality of branch instructions, it is necessary to obtain the true rate for all branch instructions, and the cost is assumed to exceed the cost reduction by optimization. Because it is done.
[S4] The copying
[S5] The copying
[S6] The branch code generation means 5 acquires a branch word from the source code.
[S7] The branch code generation means 5 generates a true rate calculation code and adds it to the source code.
[S8] The branch code generation means 5 generates a branch code and adds it to the source code.
[S9] The information processing apparatus determines whether or not to continue the process. If the process is continued, the process returns to step S1 and repeats the same process as described above. Otherwise, the process proceeds to step S10.
[S10] The optimization means 6 performs an optimization process on the non-branch word loop code.
[0040]
Note that this optimization processing may use any of the two types of optimization processing described with reference to FIG. 7 or FIG.
[S11] The
[0041]
According to the above processing, the operation of the embodiment shown in FIG. 1 can be realized.
In the above embodiment, the case of a double loop has been described as an example. Needless to say, the present invention can be applied to a case of a triple loop or more.
[0042]
Finally, the above processing functions can be realized by a computer. In this case, the processing contents of the functions that the information processing apparatus should have are described in a program recorded on a computer-readable recording medium, and the above processing is realized by the computer by executing the program by the computer. Is done. Examples of the computer-readable recording medium include a magnetic recording device and a semiconductor memory. When distributing to the market, store the program on a portable recording medium such as a CD-ROM (Compact Disk Read Only Memory) or floppy disk, or store it in a computer storage device connected via a network. In addition, it can be transferred to another computer through the network. When executed by a computer, the program is stored in a hard disk device or the like in the computer, loaded into the main memory and executed.
[0043]
【The invention's effect】
As described above, according to the present invention, in an information processing apparatus that compiles source code and generates object code, multiple loop detection means for detecting a multiple loop having a branch word in the secondary from the source code, and the true rate of the branch word True rate calculation code generation means for generating and adding to the source code the true rate calculation code that is the source code for calculating the source code, and copying to copy the source code of multiple loops excluding branch language into the source code as non-branch language loop code If the truth rate is 100%, branch to a no-branch loop code, otherwise generate a branch code that branches to the original multiple loop containing the branch phrase and generate the source code Since the branch code generation means to be added and the optimization means for optimizing the no-branch loop code have been provided, It is possible to optimize the multiple loops having the word.
[Brief description of the drawings]
FIG. 1 is a block diagram illustrating a configuration example of an embodiment of the present invention.
FIG. 2 is a diagram illustrating the operating principle of the present invention.
FIG. 3 is an example of source code obtained when optimization is performed on the source code shown in FIG. 2;
4 is a diagram schematically showing the flow of processing from line numbers “03” to “09” of the source code shown in FIG.
FIG. 5 is a diagram schematically showing the flow of processing of the source code shown in FIG. 3;
6 is a flowchart for explaining an example of processing executed in the embodiment shown in FIG. 1; FIG.
FIG. 7 is a diagram illustrating an optimization method for converting a multiple loop into a single loop.
FIG. 8 is a diagram for explaining an optimization method for switching indexes of multiple loops.
[Explanation of symbols]
DESCRIPTION OF
Claims (3)
外側ループと内側ループの間に分岐命令である分岐言を有する2重ループを、前記分岐言がループ外への分岐ではないこと、前記分岐言以前に変数または配列の定義が存在しないこと、ループ内に前記分岐言が複数含まれていないこと、の条件を満たす場合に前記ソースコードから検出するループ検出手段と、
前記分岐言の真率を算定するソースコードである真率算定コードを生成して前記ソースコードに付加する真率算定コード生成手段と、
前記分岐言を除く2重ループのソースコードを無分岐言ループコードとして前記ソースコードに複写する複写手段と、
前記真率が100%である場合には、前記無分岐言ループコードに分岐し、それ以外の場合には分岐言を含むもとの2重ループに分岐する分岐コードを生成して前記ソースコードに付加する分岐コード生成手段と、
前記無分岐言ループコードを最適化する最適化手段と、
を有することを特徴とする情報処理装置。In an information processing apparatus that compiles source code and generates object code,
A double loop having a branch word is a branch instruction between the outer loop and an inner loop, the possible branch word is not a branch outside the loop, that the definitions of branch words previously variable or array does not exist, the loop wherein a detection to Lulu-loop detecting means from the source code if the branch word will be free multiple, satisfies the condition of the inside,
A true rate calculation code generating means for generating a true rate calculation code that is a source code for calculating the true rate of the branching word and adding it to the source code;
And copying means for copying the source code of the double loop excluding the branch words in the source code as unbranched words loop code,
If the true rate is 100%, the branches to unbranched words loop code, the source code to generate a branch code for branching to the original double loop including a branch word in other cases Branch code generation means to be added to,
An optimization means for optimizing the no-branch loop code;
An information processing apparatus comprising:
コンピュータを、
外側ループと内側ループの間に分岐命令である分岐言を有する2重ループを、前記分岐言がループ外への分岐ではないこと、前記分岐言以前に変数または配列の定義が存在しないこと、ループ内に前記分岐言が複数含まれていないこと、の条件を満たす場合に前記ソースコードから検出するループ検出手段、
前記分岐言の真率を算定するソースコードである真率算定コードを生成して前記ソースコードに付加する真率算定コード生成手段、
前記分岐言を除く2重ループのソースコードを無分岐言ループコードとして前記ソースコードに複写する複写手段、
前記真率が100%である場合には、前記無分岐言ループコードに分岐し、それ以外の場合には分岐言を含むもとの2重ループに分岐する分岐コードを生成して前記ソースコードに付加する分岐コード生成手段、
前記無分岐言ループコードを最適化する最適化手段、
として機能させるプログラムを記録したコンピュータ読み取り可能な記録媒体。In a computer-readable recording medium recording a program for causing a computer to function to compile source code and generate object code,
Computer
A double loop having a branch word is a branch instruction between the outer loop and an inner loop, the possible branch word is not a branch outside the loop, that the definitions of branch words previously variable or array does not exist, the loop wherein the branch word is not included plurality of detection to Lulu-loop detecting means from the source code if they meet the condition within,
A true rate calculation code generating means for generating a true rate calculation code which is a source code for calculating the true rate of the branch word and adding the true rate calculation code to the source code;
Copying means for copying the source code of the double loop excluding the branch words in the source code as unbranched words loop code,
If the true rate is 100%, the branches to unbranched words loop code, the source code to generate a branch code for branching to the original double loop including a branch word in other cases Branch code generation means to be added to
Optimization means for optimizing the unbranched word loop code;
A computer-readable recording medium storing a program that functions as a computer.
コンピュータを、
外側ループと内側ループの間に分岐命令である分岐言を有する2重ループを、前記分岐言がループ外への分岐ではないこと、前記分岐言以前に変数または配列の定義が存在しないこと、ループ内に分岐言が複数含まれていないこと、の条件を満たす場合に前記ソースコードから検出するループ検出手段、
前記分岐言の真率を算定するソースコードである真率算定コードを生成して前記ソースコードに付加する真率算定コード生成手段、
前記分岐言を除く2重ループのソースコードを無分岐言ループコードとして前記ソースコードに複写する複写手段、
前記真率が100%である場合には、前記無分岐言ループコードに分岐し、それ以外の場合には分岐言を含むもとの2重ループに分岐する分岐コードを生成して前記ソースコードに付加する分岐コード生成手段、
前記無分岐言ループコードを最適化する最適化手段、
として機能させるプログラム。In a program that causes a computer to function to compile source code and generate object code,
Computer
A double loop having a branch word is a branch instruction between the outer loop and an inner loop, the possible branch word is not a branch outside the loop, that the definitions of branch words previously variable or array does not exist, the loop detection to Lulu-loop detecting means from the source code if the branch word will be free multiple, satisfies the condition of the inside,
A true rate calculation code generating means for generating a true rate calculation code which is a source code for calculating the true rate of the branch word and adding the true rate calculation code to the source code;
Copying means for copying the source code of the double loop excluding the branch words in the source code as unbranched words loop code,
If the true rate is 100%, the branches to unbranched words loop code, the source code to generate a branch code for branching to the original double loop including a branch word in other cases Branch code generation means to be added to
Optimization means for optimizing the unbranched word loop code;
Program to function as.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2001006492A JP4579425B2 (en) | 2000-01-13 | 2001-01-15 | Information processing device |
Applications Claiming Priority (3)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2000009959 | 2000-01-13 | ||
| JP2000-9959 | 2000-01-13 | ||
| JP2001006492A JP4579425B2 (en) | 2000-01-13 | 2001-01-15 | Information processing device |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| JP2001265606A JP2001265606A (en) | 2001-09-28 |
| JP4579425B2 true JP4579425B2 (en) | 2010-11-10 |
Family
ID=26583743
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP2001006492A Expired - Fee Related JP4579425B2 (en) | 2000-01-13 | 2001-01-15 | Information processing device |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JP4579425B2 (en) |
Family Cites Families (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JPH02253472A (en) * | 1989-03-28 | 1990-10-12 | Nec Corp | Vectorizing system |
| JPH03110670A (en) * | 1989-09-25 | 1991-05-10 | Nec Corp | Vector computer |
| EP0422398A3 (en) * | 1989-10-12 | 1992-07-08 | International Business Machines Corporation | A method of optimizing a computer program by removing invariant branches from loops |
| JPH11195011A (en) * | 1998-01-05 | 1999-07-21 | Nec Corp | Language translation processor, language translation processing method and record medium recording language translation processing program |
-
2001
- 2001-01-15 JP JP2001006492A patent/JP4579425B2/en not_active Expired - Fee Related
Also Published As
| Publication number | Publication date |
|---|---|
| JP2001265606A (en) | 2001-09-28 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US10346145B2 (en) | Loop execution with predicate computing for dataflow machines | |
| Beck et al. | From control flow to dataflow | |
| TWI446267B (en) | Systems and methods for compiler-based vectorization of non-leaf code | |
| Verdoolaege et al. | Equivalence checking of static affine programs using widening to handle recurrences | |
| TWI455028B (en) | Speculative compilation for generating suggestion messages | |
| US9430203B2 (en) | Information processing apparatus and compilation method | |
| Zhang et al. | Using hammock graphs to structure programs | |
| JP2001166949A (en) | Method and device for compiling source code by using symbolic execution | |
| US9069545B2 (en) | Relaxation of synchronization for iterative convergent computations | |
| JPH0535772A (en) | Parallel execution method | |
| US12039305B2 (en) | Method for compilation, electronic device and storage medium | |
| EP1107115A2 (en) | Method and apparatus for compiling source code by flattening hierarchies | |
| US20060200796A1 (en) | Program development apparatus, method for developing a program, and a computer program product for executing an application for a program development apparatus | |
| EP1164477A2 (en) | A loop optimization method and a compiler | |
| JP4579425B2 (en) | Information processing device | |
| US7181735B1 (en) | Method and apparatus for analyzing program based on rules of programming language before optimization in compiler | |
| JP5048949B2 (en) | Software tools including asynchronous program flow modeling | |
| Chen et al. | A framework for fine-grained program versioning | |
| US20210034333A1 (en) | Boolean multi-flow programming | |
| Chandraiah et al. | Designer-controlled generation of parallel and flexible heterogeneous MPSoC specification | |
| Baudisch et al. | Translating synchronous systems to data-flow process networks | |
| Dhamdhere et al. | Characterization of program loops in code optimization | |
| Anand et al. | Synthesizing and verifying multicore parallelism in categories of nested code graphs | |
| von Hanxleden et al. | A balanced code placement framework | |
| Logothetis et al. | Compiling short‐circuit boolean expressions in one pass |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20060612 |
|
| A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20081218 |
|
| A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20090804 |
|
| A521 | Request for written amendment filed |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20091002 |
|
| A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20100601 |
|
| A521 | Request for written amendment filed |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20100730 |
|
| 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: 20100824 |
|
| A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 |
|
| A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20100826 |
|
| FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20130903 Year of fee payment: 3 |
|
| R150 | Certificate of patent or registration of utility model |
Free format text: JAPANESE INTERMEDIATE CODE: R150 |
|
| LAPS | Cancellation because of no payment of annual fees |