JP5227646B2 - Compiler and code generation method thereof - Google Patents
Compiler and code generation method thereof Download PDFInfo
- Publication number
- JP5227646B2 JP5227646B2 JP2008110835A JP2008110835A JP5227646B2 JP 5227646 B2 JP5227646 B2 JP 5227646B2 JP 2008110835 A JP2008110835 A JP 2008110835A JP 2008110835 A JP2008110835 A JP 2008110835A JP 5227646 B2 JP5227646 B2 JP 5227646B2
- Authority
- JP
- Japan
- Prior art keywords
- loop
- simd
- fraction
- code
- data
- 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
本発明は、コンパイル技術に関し、特に、複数データに対するメモリアクセスや演算を行うSIMD命令を使用するためのコンパイル技術に関する。 The present invention relates to a compiling technique, and more particularly, to a compiling technique for using a SIMD instruction for performing memory access and operation on a plurality of data.
1つのレジスタ上に複数のデータを保持し、複数データに対して並列演算を実行できる命令を備えたアーキテクチャが一般的になってきている。例えば非特許文献1に記載されているマルチメディア命令拡張SSEでは、16バイトのレジスタを用いて複数のデータを一括して扱える。例えば4バイトの単精度浮動小数点データの場合、4個のデータに対する演算を、1つのレジスタ上で並列に実行できる。このような命令をSIMD(single-instruction-multiple-data)命令と呼び、SIMD命令を用いたコード生成を行う最適化をSIMD最適化と呼ぶ。
2. Description of the Related Art Architectures having instructions that can hold a plurality of data on one register and execute parallel operations on the plurality of data have become common. For example, in the multimedia instruction extension SSE described in Non-Patent
SIMD最適化を実現する方式としては、主としてストライド1の配列要素参照を用いた演算式を含むループに対してベクトル化の手法を用いた変換を行う方式(ベクトル化方式と呼ぶ)と、ループと無関係に、近傍の参照から隣接要素の組を見つけ、これらを結合することによる変換を行う方式(命令結合方式と呼ぶ)の二方式がある。ベクトル化方式については非特許文献1の第5章に記載されている。命令結合方式については、非特許文献2に記載されている。
As a method for realizing SIMD optimization, a method that performs transformation using a vectorization method on a loop that includes an arithmetic expression that uses an array element reference of stride 1 (referred to as a vectorization method), a loop, Regardless, there are two types of methods (referred to as an instruction combination method) that perform conversion by finding a set of adjacent elements from neighboring references and combining them. The vectorization method is described in
ベクトル方式による変換例を図5に示す。図5(a)のソースプログラム(C言語で記述)において、最内側のkループに着目する。配列aのアクセスは、ループ制御変数kが最下位次元の配列添え字となっているため、ストライド1の連続参照であり、本ループはベクトル化可能である。配列aの型(int型)に対して、SIMD命令により4個のデータを同時にアクセス可能である(SIMD並列度4)とすると、kループに対して4倍のループ展開(アンローリング)を適用し、SIMD化変換を行う。変換後のコードイメージを図5(b)に示す。kループ内の文で、配列aの添え字の’k:k+3’は、kからk+3、即ちk、k+1、k+2、k+3の4要素のアクセスを示す記法とする。左辺はa[i][j][k]を先頭とする4要素への代入を示し、右辺は4個のv2を1つのレジスタ上にまとめたデータを示す。このように、SIMD化対象のループ内では元の4個の文に相当する処理を1文で行う。kループの元のループ長は5であるから、4倍ループ展開による余りは1である。余りの要素a[i][j][4]に対しては、ループ後に通常の代入処理を行うコードを生成する。
An example of conversion by the vector method is shown in FIG. Focus on the innermost k-loop in the source program (described in C language) in FIG. Access to the array a is a continuous reference of
次に、命令結合方式による変換例を図7に示す。図7(a)のソースプログラム(C言語で記述)において、ループ内の3個の文に着目する。配列aのSIMD並列度を2と仮定すると、a[i][0]とa[i][1]は隣接する要素で同時アクセス可能であるから、先頭の2文を結合する。変換後のコードイメージを図7(b)に示す。 Next, an example of conversion by the instruction combination method is shown in FIG. In the source program (described in C language) in FIG. 7A, attention is paid to three sentences in the loop. Assuming that the SIMD parallelism of array a is 2, a [i] [0] and a [i] [1] can be accessed simultaneously by adjacent elements, so the first two sentences are combined. The code image after conversion is shown in FIG.
SIMD最適化の対象とする範囲のデータ長が短い場合、データ長がSIMD並列度で割り切れない場合には、端数部分にはSIMD化が適用されない。実際には連続でSIMD化適用が可能な長いデータ列があり、最適化対象に選択した部分(例えば最内側ループの参照)がそのデータ列の一部の短データ列であった場合には、端数部分にSIMD化が適用されない分、SIMD化適用率が低下し実行性能向上への効果が小さくなってしまう。例えば、図5(a)のソースプログラムの場合、kループおよびjループのアクセス範囲が配列aの3次元目と2次元目の宣言と一致しており、3重ループによりaの全要素を連続的に参照する。この場合、並列度4のSIMD化適用により、aへのストア命令は4分の1に削減可能である。ところが、図5(b)のような変換では、ループ展開後のkループは1イタレーションしか実行されず、長さ5のデータ列を2命令で実行することになるため、ストア命令数の削減率は5分の2となり、実行性能の向上が不十分である。また、図7(a)のソースプログラムにおいても配列aを連続的に参照しているため、ストア命令を2分の1に削減可能であるが、図7(b)の変換における削減率は3分の2である。
When the data length in the range subject to SIMD optimization is short, if the data length is not divisible by the SIMD parallelism, SIMD conversion is not applied to the fractional part. In fact, there is a long data string that can be continuously applied to SIMD, and if the part selected for optimization (for example, the reference of the innermost loop) is a short data string that is part of the data string, Since SIMD conversion is not applied to the fractional part, the SIMD conversion application rate decreases and the effect on improving execution performance is reduced. For example, in the case of the source program shown in FIG. 5 (a), the access range of the k loop and the j loop is the same as the declaration of the third and second dimensions of the array a, and all elements of a are continuously connected by the triple loop. Refer to it. In this case, the store instruction to a can be reduced to a quarter by applying SIMD with a parallel degree of 4. However, in the conversion as shown in FIG. 5B, the k loop after loop expansion only executes one iteration, and a data string of
本発明の目的は、従来のSIMD化方式による対象データ列が、外側ループに跨った長い連続データ列の一部分である場合に、外側ループを考慮したSIMD化変換を実施することにより、端数部分のないSIMD化コードを生成する方法を提供することにある。 The object of the present invention is to perform the SIMD conversion in consideration of the outer loop when the target data string according to the conventional SIMD conversion method is a part of a long continuous data string straddling the outer loop. There is no way to provide a way to generate SIMD code.
本発明は、対象ループを解析して、内側データ長およびSIMD並列度を取得する構造解析手段と、内側データ部を囲む外側ループのループ展開数を求める展開数計算手段と、展開数計算手段で求めた展開数に従いループを展開するループ展開手段、および展開後のループに対してSIMDコードの生成を行うSIMDコード変換手段から成る。 The present invention includes a structure analysis unit that analyzes a target loop to obtain an inner data length and a SIMD parallelism, an expansion number calculation unit that calculates a loop expansion number of an outer loop that surrounds the inner data portion, and an expansion number calculation unit. It comprises loop unrolling means for unfolding a loop according to the obtained number of unfolding, and SIMD code converting means for generating SIMD code for the unrolled loop.
展開数計算手段では、内側データ長をSIMD並列度で割ったときの余りの値(端数と呼ぶ)を計算し、SIMD並列度と端数の公倍数を端数で割った値を展開数とする。 In the expansion number calculation means, a remainder value (called a fraction) when the inner data length is divided by the SIMD parallelism is calculated, and a value obtained by dividing the SIMD parallelism and the common multiple of the fraction by the fraction is used as the expansion number.
内側データ長の取得においては、ベクトル化方式対象ループについては内側の定数ループ長を解析し、命令結合方式対象ループについては内側ループ内の連続参照から成る内側データ列のデータ長を解析する。 In the acquisition of the inner data length, the inner constant loop length is analyzed for the vectorization method target loop, and the data length of the inner data string composed of continuous references in the inner loop is analyzed for the instruction combination method target loop.
本発明によれば、内側ループに属する短データで外側ループのイタレーション間で連続なデータ列にSIMD化を適用する際、内側短データ長がSIMD並列度で割り切れない場合の端数部分に対してSIMD化が非適用になることがなくなり、SIMD命令の適用率を向上させることで生成コードの実行性能向上を図ることができる。 According to the present invention, when applying SIMD to a short data belonging to the inner loop and a continuous data string between iterations of the outer loop, the inner short data length is not divisible by the SIMD parallelism. SIMD conversion is no longer applied, and the execution performance of the generated code can be improved by improving the application rate of SIMD instructions.
以下に、本発明の実施の形態を説明する。 Hereinafter, embodiments of the present invention will be described.
以下、図面を用いて本発明の実施の形態について説明する。 Hereinafter, embodiments of the present invention will be described with reference to the drawings.
図2に本実施形態によるコンパイラが稼動する計算機システムの構成図を示す。この計算機システムは、制御手段としてのCPU(Central Processing Unit)201、表示手段としてのディスプレイ装置202、入力手段としてのキーボード203、記憶手段としての主記憶装置204、および記憶手段としての外部記憶装置205から構成されている。キーボード203により、ユーザからのコンパイラ起動命令を受け付ける。コンパイラ終了メッセージやエラーメッセージは、ディスプレイ装置202に表示される。外部記憶装置205には、ソースプログラム209と、オブジェクトプログラム210が格納される。主記憶装置204には、コンパイラ206、コンパイル過程で必要となる中間コード207およびループ表208が格納される。コンパイル処理はCPU201がコンパイラ206を実行することにより行われる。
FIG. 2 shows a configuration diagram of a computer system in which the compiler according to the present embodiment operates. This computer system includes a CPU (Central Processing Unit) 201 as control means, a
本発明によるコンパイラはSIMD最適化部211を含む。本最適化部内の特徴的な処理部として、内側データ長解析部212、SIMD並列度解析部213、ループ展開数計算部214、ループ展開変換部215がある(内側データ長解析部212とSIMD並列度解析部213をまとめて構造解析部と称す。)。これらSIMD最適化部の処理については、本発明の特徴的な部分であるので、後で詳細に説明する。
The compiler according to the present invention includes a
図3に、図2のシステムで稼動するコンパイラ206の処理手順を示す。
FIG. 3 shows a processing procedure of the
コンパイラ206は、ステップ301において、ソースプログラム209を入力として構文解析を行い、中間コード207を出力する。以下のコンパイル処理ではこの中間コードを対象に変換を行う。構文解析の方法や中間コードの例については、例えば、「Aho, Sethi, Ullman著, “Compilers: Principles, Techniques, and Tools”, Addison-Wesley, 1986」に記載されている。
In
次にステップ302のループ解析において、コンパイラ206は、プログラム内に含まれるループの集合を、求め、ループ表208に記録する。ループ解析の方法に関しては、例えば、Michael Wolfe著「High Performance Compilers for Parallel Computing」、Addison-Wesley Publishing Company, 1996の67頁に記載されている。
Next, in the loop analysis of
次にステップ303において、コンパイラ206のSIMD最適化部211がSIMD最適化303を行う。本ステップの処理手順については、本発明の特徴となる部分であるので、後述する。
Next, in
次に、コンパイラ206が、ステップ304において、レジスタ割付けを行った後、ステップ305においてコード生成を行い、中間コード207をオブジェクトプログラム210に変換して出力する。レジスタ割付けやコード生成の方法に関しては、前述のAhoらの文献に記載されている。
Next, the
ここで、上記ステップ302のループ解析により生成されるループ表208について説明する。図8にループ表208の一例を示す。ループ表208には、ループ番号801、親ループ802、子ループ803、制御変数804、初期値805、終値806、増分値807、ループ長808が格納される。
Here, the loop table 208 generated by the loop analysis in
ループ番号801は、コンパイラ内でループを識別するための番号である。親ループ802は、対象ループを取り囲む外側ループのうち最も内側のループのループ番号である。対象ループが最も外側のループの場合、「なし」が登録される。子ループ803は、対象ループの内側ループのうち最も外側のループのループ番号である。対象ループが最も内側のループの場合、「なし」が登録される。制御変数804は、対象ループの繰り返しを制御するループ制御変数である。初期値805、終値806、増分値807は、それぞれ、制御変数804の初期値、終値、繰り返しごとの増分である。ループ長808は、ループの繰り返し回数である。ループ長は、ループ制御変数の初期値、終値、増分値から求められる。
The
以下、本発明の特徴であるSIMD最適化303の処理の詳細について説明する。図1にSIMD最適化303の処理手順の詳細を示す。
Hereinafter, the details of the processing of the
本実施例におけるSIMD最適化は、ループを処理単位として実施する。そこで、ステップ101では、コンパイラ206が、未処理のループがあるかどうかを判定し、あれば未処理のループを1つ処理対象として取り出してステップ102へ進む。未処理のループがなければ処理を終了する。
The SIMD optimization in this embodiment is performed using a loop as a processing unit. Therefore, in
ステップ102では、コンパイラ206が、SIMD最適化の対象ループであるかを判定する。対象ループでなければステップ101へ戻り、次のループの処理に進む。
In
ステップ102の処理手順の詳細を図9に従って説明する。本実施形態例では、背景技術の項で述べたベクトル化方式と命令結合方式の2方式を対象とする。
Details of the processing procedure of
本実施形態例では、最内側ループを処理対象とする。ステップ901において、最内側ループかどうかを判定する。最内側ループかどうかはループ表208の子ループ欄803を参照し、子ループがないかどうかで判定できる。最内側ループであればステップ902に進み、最内側ループでなければステップ909へ進み、SIMD最適化対象でないと判定して処理を終了する。
In this embodiment, the innermost loop is the processing target. In
ステップ902、903、904は、ベクトル化方式の条件を判定する処理である。
ステップ902では、ループ表の増分値欄807により、制御変数の増分が1であるかどうかを判定する。
In
ステップ903では、ループ運搬依存の有無を判定する。
In
ステップ904では、ループ本体中のコードを調べ、条件を満たすかどうかを判定する。まず、全演算およびオペランドの型が一致することを条件とする。SIMD演算で同時に扱うデータを示すSIMD並列度は通常、対象アーキテクチャにより型ごとに定義されているため、本実施形態では簡単のため、型が全て同一の場合のみを対象とする。次に、ループ内の演算がSIMD命令を持つ演算かどうかを判定する。例えば対象アーキテクチャが備えるSIMD演算命令が加算と乗算のみの場合、除算を含むループはSIMD最適化対象外とする。次にオペランドが配列参照の場合、ストライド1の連続参照であるかどうかを調べる。また、配列参照以外のオペランドはループ不変な変数であることを条件とする。
In
ステップ902、903、904の条件を全て満たす場合、ステップ905に進み、ベクトル化方式によるSIMD最適化対象であると判定して処理を終了する。
When all of the conditions of
ステップ902、903、904において条件を満たさない場合にはステップ906に進み、命令結合方式によるSIMD最適化の条件を判定する。命令結合方式では通常、ループ本体内から、同型な演算式で配列参照などによるメモリ参照が連続参照の組を探し、SIMD結合の対象とする。例えば、’a[i]+b[i+1]+v0’と’a[i+1]+b[i+2]+v1’は結合対象である。本実施形態では簡単のため、全文が同型な場合のみを対象とする。このためステップ906では、ループ本体中のコードを調べ、全ての文が同型であるかどうかを調べる。同型である場合、次の条件を満たすかどうかを調べる。まず、全演算およびオペランドの型が一致すること、および全演算がSIMD命令を持つこと、配列参照以外のオペランドがループ不変であることについては、ステップ904の判定と同様である。配列参照については、隣接する文間でストライド1かどうかを調べる。例えば第1文がa[i]、第2文がa[i+1]、第3文がa[i+2]のような場合には、本条件を満たす。また、隣接文間で依存がないことを条件とする。
When the conditions are not satisfied in
ステップ906の条件を満たす場合には、ステップ907へ進み、命令結合方式によるSIMD最適化対象であると判定して処理を終了する。条件を満たさない場合には、ステップ908へ進み、SIMD最適化対象でないと判定して処理を終了する。
If the condition of
尚、ステップ102のSIMD最適化対象判定は、従来技術に属する部分であり、図9の処理手順による判定は、本発明の範囲に制約を与えるものではない。例えばストライド1の配列参照以外に、構造体内の隣接メンバーのようなメモリ上で連続となる領域もSIMD結合の対象となる。また、全演算がSIMD命令対象でない場合には、SIMD化適用部分と非適用部分に分けることができるなど、図9の条件以外にもSIMD最適化が適用可能な場合がある。
Note that the SIMD optimization target determination in
以上で、図9およびステップ102の説明を終了する。 Above, description of FIG. 9 and step 102 is complete | finished.
ステップ103では、コンパイラのSIMD並列度解析部213が、SIMD並列度を求める。対象アーキテクチャにより、各データ型に対するSIMD並列度が決まっている。例えばデータが4バイトの整数型でSIMD演算用のレジスタが16バイトの場合は、4並列である。ループ内の演算の型を調べ、その型に対する並列度を求める。
In
ステップ104では、コンパイラの内側データ長解析部212が、内側データ部を解析し、内側データ長Nと、展開用外側ループを求める。本ステップの処理手順を図4に従い詳細に説明する。
In
ステップ401では、内側データ長Nの初期値として1を設定し、展開用外側ループを求めるための変数UNROLLLOOPの初期値を未設定とする。
In
ステップ402では、現在処理対象のループがベクトル化可能かどうかを判定する。ステップ102(図9)の判定において、ステップ905でベクトル化方式によるSIMD最適化対象と判定したケースはベクトル化可能である。ベクトル化可能な場合にはステップ403へ進み、ベクトル方式によるSIMD化向けの処理を行う。ベクトル化可能でない場合にはステップ410へ進み、命令結合方式によるSIMD化向けの処理を行う。
In
ステップ403では、ベクトル方式対象のループに対して、OUTERLOOPに現在の処理対象の最内側ループを設定する。
In
ステップ404,405,406,407,408,409は、親ループを辿って処理を行い、展開用外側ループを外側に広げていくための処理である。
ステップ404では、OUTERLOOPの親ループがあるかどうかを判定する。本判定はループ表208の親ループ欄802により行う。親ループがあればステップ405へ進み、なければループを外側に辿る処理を終了し、ステップ412に進む。
In
ステップ405では、LOOPにOUTERLOOPを設定し、OUTERLOOPに現在のOUTERLOOPの親ループを設定する。
In
ステップ406ではLOOPのループ長を調べる。ループ長はループ表208のループ長欄808から取得できる。ループ長が定数であればその値をN1に設定し、ステップ407へ進む。定数でなければステップ412へ進む。
In
ステップ407では定数NとN1の積を計算し、この値が一定値以下であるかどうかを判定する。本判定に用いる一定値には、内側データ部の短データ長として妥当な値となるような上限値を選択すればよい。例えば、対象としているアーキテクチャのSIMD並列度の最大値の数倍程度の値を選択する。値が一定値以下ならばステップ408へ進み、そうでなければステップ412へ進む。
In
ステップ408では、SIMD化対象の各配列参照が、OUTERLOOPのイタレーション間で連続かどうかを判定する。連続かどうかは、OUTERLOOPのi回目の最後の参照とi+1回目の最初の参照が連続するかどうかを判定する。例えば、図5(a)のソースプログラム例において、OUTERLOOPがjループの場合、a[i][j][4]とa[i][j+1][0]を比較すると、aの最下位次元の要素が0から4であることから、これらの要素は連続である。連続であればステップ409へ進み、そうでなければステップ412へ進む。
In
ステップ409では、展開対象ループを外側に更新し、次の外側ループの処理に進む。即ち、Nの値をN*N1に更新し、UNROLLLOOPにOUTERLOOPを設定する。その後、ステップ404に戻り、更新したOUTERLOOPの処理を行う。
In
ステップ410は、命令結合方式によるSIMD化対象のループの処理である。処理対象ループ内の連続参照列を解析し、そのデータ長をN1に設定する。 Step 410 is processing of a loop to be converted into SIMD by the instruction combination method. Analyzes the continuous reference string in the processing target loop and sets its data length to N1.
ステップ411では、OUTERLOOPに現在処理対象の最内側ループを設定する。その後、ステップ407へ進み、ベクトル化方式対象のループと同様の処理を行う。
In
ステップ412では、UNROLLLOOPが未設定かどうかを判定する。
In
未設定ならば、ステップ413に進み、判定結果を「内側データ部なし」として処理を終了する。 If not set, the process proceeds to step 413, where the determination result is “no inner data portion” and the process is terminated.
UNROLLLOOPが設定されていれば、ステップ414に進み、内側データ長をN、展開用外側ループをUNROLLLOOPとして、処理を終了する。 If UNROLLLOOP is set, the process proceeds to step 414, where the inner data length is N and the expansion outer loop is UNROLLLOOP.
以上で、図4およびステップ104の処理手順の説明を終了する。 Above, description of the processing procedure of FIG. 4 and step 104 is complete | finished.
ステップ105では、コンパイラのループ展開数計算部214が、ステップ104の判定結果により、内側データ部があるかどうかを調べ、あればステップ106に進む。内側データ部がない場合は、本発明の適用対象外であるので、ステップ112に進み、従来技術による通常のSIMD最適化処理を行い、本ループの処理を終了してステップ101に戻る。
In
ステップ106では、コンパイラのループ展開数計算部214が、ステップ104で求めた内側データ長Nが、SIMD並列度で割り切れるかどうかを判定する。割り切れる場合には、ステップ112に進み、通常のSIMD最適化処理を行い、本ループの処理を終了する。割り切れない場合にはステップ107へ進む。
In
ステップ107では、コンパイラのループ展開数計算部214が、内側データ部にループがあるかどうかを調べる。内側データ部は、展開用外側ループの内側であるので、図8のループ表208の子ループ803を用いて展開用外側ループに子ループがあるかどうかにより判定する。内側ループがあればステップ108に進み、内側ループを解消する。内側ループが多重ループの場合(展開用外側ループの子ループがさらに子ループを持つ場合)、多重ループを構成するループ全てを最内側から順に解消する。内側データ部にループがない場合には、ステップ109へ進む。
In
ステップ109では、コンパイラのループ展開数計算部214が、展開用外側ループのループ展開数を計算する。まず、内側データ長NをSIMD並列度で割り、その余りを「端数」とする。次に、SIMD並列度と端数の公倍数を求め、その値を端数で割った商を、展開用外側ループの展開数とする。公倍数の計算においては、最小公倍数を求めると、展開数を最小にすることができる。また単純な計算方法としては、SIMD並列度と端数の積を公倍数として採用する方法もある。
In
ステップ110では、ステップ109で求めた展開数に従い、コンパイラのループ展開変換部215が、展開用外側ループのループ展開処理を行う。
In
ステップ111では、コンパイラ206が、展開後の最内側ループ内のコードをSIMD化を適用したコードに変換する。以上で、1つのループの処理を終了し、ステップ101に戻り、次のループの処理に進む。
In
以上で、図1およびステップ303の処理手順の詳細の説明を終了する。 This is the end of the detailed description of the processing procedure in FIG. 1 and step 303.
次に、図5(a)のソースプログラム(C言語で記述)に対して、本実施例を適用した場合の処理手順を説明する。 Next, a processing procedure when the present embodiment is applied to the source program (described in C language) of FIG.
ループ番号を外側から順に1,2,3とする。各ループの情報は図8に記載されている通りである。 The loop numbers are 1, 2, and 3 in order from the outside. Information of each loop is as described in FIG.
ステップ102のSIMD最適化対象ループの判定において、ループ1と2は最内側ループでないので、条件を満たさない。ループ3(kループ)の処理を説明する。ステップ902で制御変数の増分が1であることを判定し、本ループは依存を持たないためステップ903でループ運搬依存がないことを判定する。ステップ904でループ内のコードを調べる。ループ本体の文は演算を持たず、配列参照とループ不変変数v2のみである。型はint型で一致している。配列参照a[i][j][k]は最下位次元の添え字kがループ制御変数と一致しているため、ストライド1の連続参照である。条件を満たすので、ステップ905でSIMD最適化対象であると判定する。ステップ103において、例えば対象アーキテクチャのSIMDレジスタサイズが16バイト、int型のデータサイズが4バイト、int型に対するSIMD命令の並列度が4とすると、SIMD並列度を4に設定する。
In the determination of the SIMD optimization target loop in
ステップ104では、内側データ部の解析を行う。ステップ402で処理対象のkループはベクトル化可能であるから、ステップ403へ進み、OUTERLOOPにkループを設定する。ステップ404の判定後、ステップ405で、LOOPにkループを、OUTERLOOPにjループを設定する。ステップ406では、kループのループ長が定数5であることを判定し、ステップ407で、N*N1の値5が一定値以下かどうかを判定する。本実施形態においては、例えば一定値を32とすると、一定以下であると判定してステップ408へ進む。ステップ408において、配列参照a[i][j][k]がOUTERLOOP(jループ)のイタレーション間で連続かどうかを調べる。jループの1回目の最終参照はa[i][0][4]、jループの2回目の最初の参照はa[i][1][0]で、配列aの宣言と照らし合わせるとこれらは隣接する要素であるから、連続であると判定する。ステップ409では、Nに5を設定し、UNROLLLOOPにjループを設定する。
In
ステップ404に戻り、OUTERLOOPの親ループを調べ、ステップ405でLOOPをjループに、OUTERLOOPをiループに更新する。jループのループ長は3、Nとの積は15で32以下であるから、ステップ408へ進む。iループの1回目の最終参照はa[0][2][4]、jループの2回目の最初の参照はa[1][0][0]で、配列aの宣言と照らし合わせるとこれらは隣接する要素であるから、連続であると判定する。ステップ409でNを15に、UNROLLLOOPをiループに更新し、ステップ404に戻る。iループの親ループはないので、ステップ412に進み、UNROLLLOOPが設定されているので、ステップ414に進む。内側データ長を15、展開用外側ループをiループとして、ステップ104の処理を終了する。
Returning to step 404, the parent loop of OUTERLOOP is checked, and in
ステップ105で内側データ部ありと判定し、ステップ106で、内側データ長15がSIMD並列度4で割り切れるかどうかを判定する。割り切れないので、ステップ107へ進む。内側データ部にはjループとkループがあるので、ステップ108で内側ループを解消する。初めに内側のkループを解消した後、さらにjループを解消する。解消後のコード例を図6(a)に示す。
In
ステップ109において、端数は15を4で割った余りの3となる。展開数はSIMD並列度4と端数3の最小公倍数12を端数3で割り、4とする。ステップ110においてiループを4倍に展開する。展開後のコード列を図6(b)に示す。
In
ステップ111において、SIMDコードへの変換を行う。ここでは配列aへの代入文を先頭から順に4個ずつまとめ、1つの文に変換する。変換後のコード例を図6(c)に示す。本コードにおいて、a[i][0][1:3]はaの4要素への代入を示している。また(v2,v2,v2,v2)は変数v2を4個並べた値を示している。(a[i][0][4],a[i][1][0:2])は、a[i][0][4]と、これに連続するa[i][1][0]からa[i][1][2]までの3要素の合計4要素にまとめて代入することを示す。以下同様である。
In
以上で、図5(a)のソースコード例に対する変換例の説明を終了する。 This is the end of the description of the conversion example for the source code example in FIG.
次に、図7(a)ソースプログラム(C言語で記述)に対して、本実施例を適用した場合の処理手順を説明する。 Next, a processing procedure when this embodiment is applied to the source program (described in C language) in FIG. 7A will be described.
iループのループ番号を4とする。本ループの情報は図8に記載されている通りである。 The loop number of i loop is 4. The information of this loop is as described in FIG.
ステップ102のSIMD最適化対象ループの判定において、ステップ902で制御変数の増分が1であることを判定し、本ループは依存を持たないためステップ903でループ運搬依存がないことを判定する。ステップ904の判定において、配列参照a[i][0]はストライド1でないので、条件を満たさず、ステップ906へ進む。
In the determination of the SIMD optimization target loop in
ステップ906では、ループ内の3個の文を比較し、各文とも左辺が配列参照、右辺が変数であるので、同型であると判定する。型は全てdouble型で一致する。配列参照に着目すると、3個の文の参照が連続している。これらの判定からステップ906の条件を満たすと判定し、ステップ907で命令結合方式によるSIMD最適化対象とする。
In
ステップ103において、double型に対するSIMD命令の並列度が2とすると、SIMD並列度を2に設定する。
In
ステップ104では、内側データ部の解析を行う。ステップ402で処理対象のiループはベクトル化可能でないからステップ410に進み、処理対象ループ中の連続参照列を調べる。本ループの参照列は、a[i][0],a[i][1],a[i][2]であるので、データ長N1に3を設定する。ステップ411では、iループをOUTERLOOPに設定する。
In
ステップ407に進み、N*N1は3であるので、一定以下と判定する。 Proceeding to step 407, since N * N1 is 3, it is determined to be below a certain level.
ステップ408において、iループのイタレーション間の連続性を調べる。iループの1回目における配列aの参照列の最後のデータはa[0][2]である。2回目の最初のデータはa[1][0]である。配列aの宣言と照らし合わせるとこれらは隣接する要素であるから、連続であると判定する。
In
ステップ409では、Nに3を設定し、UNROLLLOOPにiループを設定する。
In
ステップ404に戻り、iループの親ループはないので、ステップ412に進み、UNROLLLOOPが設定されているので、ステップ414に進む。内側データ長を3、展開用外側ループをiループとして、ステップ104の処理を終了する。
Returning to Step 404, since there is no parent loop of i loop, the process proceeds to Step 412, and since UNROLLLOOP is set, the process proceeds to Step 414. The processing of
ステップ105で内側データ部ありと判定し、ステップ106で、内側データ長3がSIMD並列度2で割り切れるかどうかを判定する。割り切れないので、ステップ107へ進む。内側データ部にループはないので、ステップ109に進む。
In
ステップ109において、端数は3を2で割った余りの1となる。展開数はSIMD並列度2と端数1の最小公倍数2を端数1で割り、2とする。ステップ110においてiループを2倍に展開する。展開後のコード列を図7(b)に示す。
In
ステップ111において、SIMDコードへの変換を行う。ここでは配列aへの代入文を先頭から順に2個ずつまとめ、1つの文に変換する。変換後のコード例を図7(c)に示す。
In
以上で、図7(a)のソースコード例に対する変換例の説明を終了する。 This is the end of the description of the conversion example for the source code example in FIG.
本発明のコード生成方法は、複数データに対するメモリアクセスや演算を行うSIMD命令を備えたターゲットマシンに対するコード生成を行うコンパイラにおいて利用することができる。 The code generation method of the present invention can be used in a compiler that performs code generation for a target machine equipped with a SIMD instruction that performs memory access and calculation for a plurality of data.
204・・・主記憶装置、206・・・コンパイラ、207・・・中間コード、208・・・ループ表、209・・・ソースプログラム、211・・・SIMD最適化部、212・・・内側データ長解析部、213・・・SIMD並列度解析部、214・・・ループ展開数計算部、215・・・ループ展開変換部 204 ... Main memory, 206 ... Compiler, 207 ... Intermediate code, 208 ... Loop table, 209 ... Source program, 211 ... SIMD optimization unit, 212 ... Inside data Long analysis unit, 213... SIMD parallelism analysis unit, 214... Loop expansion number calculation unit, 215... Loop expansion conversion unit
Claims (9)
中間コードのループを解析して、一定値以下の定数長のSIMD命令適用対象データ列を含む内側データ部のデータ列の長さである内側データ長、およびSIMD命令により何個のデータを並列に処理するかを表わすSIMD並列度を取得する構造解析ステップと、
前記構造解析ステップで求めた前記内側データ長を前記SIMD並列度で割ったときの余りの値である端数を計算し、前記SIMD並列度と前記端数との公倍数を端数で割った値を、前記内側データ部を囲む外側ループのループ展開数として求める展開数計算ステップと、
前記展開数計算ステップで求めたループ展開数に従いループを展開するループ展開ステップと、
をコンピュータが実行することを特徴とするコード生成方法。 A computer code generation method for generating a code using a SIMD instruction for performing parallel operation on a plurality of data from a source program or intermediate code,
Analyzing the loop of the intermediate code, the inner data length, which is the length of the inner data section including the SIMD instruction application target data string with a constant length less than a certain value, and how many pieces of data are parallelized by the SIMD instruction A structural analysis step for obtaining a SIMD parallelism indicating whether to process,
A fraction which is a remainder when the inner data length obtained in the structural analysis step is divided by the SIMD parallelism is calculated, and a value obtained by dividing the common multiple of the SIMD parallelism and the fraction by the fraction is obtained. An expansion number calculation step for obtaining the number of loop expansions of the outer loop surrounding the inner data portion;
A loop unrolling step for unfolding the loop according to the number of unfolding loops obtained in the unfolding number calculating step;
A code generation method characterized in that a computer executes.
前記公倍数は、SIMD並列度と端数の最小公倍数であることを特徴とするコンピュータのコード生成方法。 The code generation method according to claim 1,
Before Kioyake multiples the code generation method of a computer which is a least common multiple of the SIMD parallelism and fractional.
前記公倍数は、SIMD並列度に端数を乗じた値であることを特徴とするコンピュータのコード生成方法。 The code generation method according to claim 1,
Before Kioyake multiples the code generation method of a computer which is a value obtained by multiplying the fraction in SIMD parallelism.
前記中間コードのループについて外側ループ及び内側ループの情報を記載したループ表を参照して、前記構造解析ステップ、前記展開数計算ステップおよび前記ループ展開ステップを前記ループに対して行うかどうか判断するステップをコンピュータが更に実行することを特徴とするコンピュータのコード生成方法。 The code generation method according to claim 1,
A step of determining whether to perform the structure analysis step, the expansion number calculation step, and the loop expansion step with respect to the loop with reference to a loop table that describes information on the outer loop and the inner loop with respect to the loop of the intermediate code code generation method of a computer, wherein a computer further execute.
コードのループを解析して、一定値以下の定数長のSIMD命令適用対象データ列を含む内側データ部のデータ列の長さである内側データ長、およびSIMD命令により何個のデータを並列に処理するかを表わすSIMD並列度を取得する構造解析ステップと、
前記構造解析ステップで求めた前記内側データ長を前記SIMD並列度で割ったときの余りの値である端数を計算し、前記SIMD並列度と、前記端数との公倍数を端数で割った値を前記内側データ部を囲む外側ループのループ展開数として求める展開数計算ステップと、
前記展開数計算ステップで求めたループ展開数に従いループを展開するループ展開変換ステップと、
をコンピュータに実行させることを特徴とするコンパイラ。 A compiler that causes a computer to generate code using a SIMD instruction that performs parallel operations on multiple data from a source program or intermediate code,
Analyze the loop of the code and process the inner data length, which is the length of the data string of the inner data section including the data string subject to SIMD instruction application with a constant length less than a certain value, and how many pieces of data are processed in parallel by the SIMD instruction A structural analysis step to obtain a SIMD parallelism representing whether to do;
A fraction that is a remainder when the inner data length obtained in the structural analysis step is divided by the SIMD parallelism is calculated, and a value obtained by dividing the common multiple of the SIMD parallelism and the fraction by the fraction is calculated. An expansion number calculation step for obtaining the number of loop expansions of the outer loop surrounding the inner data portion;
A loop expansion conversion step of expanding a loop according to the number of loop expansions determined in the expansion number calculation step;
A compiler characterized by causing a computer to execute.
前記公倍数は、前記SIMD並列度と前記端数の最小公倍数であることを特徴とするコンパイラ。 The compiler of claim 5, comprising:
Before Kioyake multiples, compiler, characterized in that said SIMD parallelism, which is the least common multiple of the fraction.
前記公倍数は、前記SIMD並列度に前記端数を乗じた値であることを特徴とするコンパイラ。 The compiler of claim 5, comprising:
Before Kioyake multiples, compiler, wherein the a value obtained by multiplying the fraction in SIMD parallelism.
前記中間コードのループについて外側ループ及び内側ループの情報を記載したループ表を参照して、前記構造解析ステップ、前記展開数計算ステップ及び前記ループ展開変換ステップを前記ループに対して処理を行わせるかどうか判断するステップを更にコンピュータに実行させることを特徴とするコンパイラ。 The compiler of claim 5, comprising:
Whether the structure analysis step, the expansion number calculation step, and the loop expansion conversion step are to be performed on the loop with reference to a loop table that describes information about the outer loop and the inner loop with respect to the loop of the intermediate code A compiler that further causes a computer to execute a step of determining whether or not.
中間コードのループを解析して、一定値以下の定数長のSIMD命令適用対象データ列を含む内側データ部のデータ列の長さである内側データ長、およびSIMD命令により何個のデータを並列に処理するかを表わすSIMD並列度を取得する構造解析部と、
前記構造解析ステップで求めた前記内側データ長を前記SIMD並列度で割ったときの余りの値である端数を計算し、前記SIMD並列度と前記端数との公倍数を端数で割った値を、前記内側データ部を囲む外側ループのループ展開数として求める展開数計算部と、
前記展開数計算ステップで求めたループ展開数に従いループを展開するループ展開変換
部と、
を有することを特徴とするコンピュータ。 A computer that generates code using SIMD instructions for performing parallel operations on multiple data from a source program or intermediate code,
Analyzing the loop of the intermediate code, the inner data length, which is the length of the inner data section including the SIMD instruction application target data string with a constant length less than a certain value, and how many pieces of data are parallelized by the SIMD instruction A structural analysis unit for obtaining SIMD parallelism indicating whether to process,
A fraction which is a remainder when the inner data length obtained in the structural analysis step is divided by the SIMD parallelism is calculated, and a value obtained by dividing the common multiple of the SIMD parallelism and the fraction by the fraction is obtained. An expansion number calculation unit for obtaining the number of loop expansions of the outer loop surrounding the inner data part;
A loop expansion conversion unit that expands a loop according to the number of loop expansions determined in the expansion number calculation step;
A computer comprising:
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2008110835A JP5227646B2 (en) | 2008-04-22 | 2008-04-22 | Compiler and code generation method thereof |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2008110835A JP5227646B2 (en) | 2008-04-22 | 2008-04-22 | Compiler and code generation method thereof |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2009265708A JP2009265708A (en) | 2009-11-12 |
JP5227646B2 true JP5227646B2 (en) | 2013-07-03 |
Family
ID=41391527
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2008110835A Expired - Fee Related JP5227646B2 (en) | 2008-04-22 | 2008-04-22 | Compiler and code generation method thereof |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP5227646B2 (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2018124877A (en) * | 2017-02-02 | 2018-08-09 | 富士通株式会社 | Code generating device, code generating method, and code generating program |
JP7006097B2 (en) * | 2017-09-29 | 2022-01-24 | 富士通株式会社 | Code generator, code generator and code generator |
JP7302727B2 (en) * | 2020-02-14 | 2023-07-04 | 日本電気株式会社 | LOOP UNROLLING PROCESSING APPARATUS, METHOD AND PROGRAM |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH01152571A (en) * | 1987-12-10 | 1989-06-15 | Agency Of Ind Science & Technol | Task allocation system in multiprocessor system |
JP2747336B2 (en) * | 1989-08-29 | 1998-05-06 | 株式会社日立製作所 | Program parallelization conversion method |
JPH04344535A (en) * | 1991-05-22 | 1992-12-01 | Nec Software Ltd | Developing device for loop |
JPH09282177A (en) * | 1996-04-12 | 1997-10-31 | Hitachi Ltd | Program conversion method and compiler |
JP2000155689A (en) * | 1998-11-20 | 2000-06-06 | Hitachi Ltd | Method and device for developing loop |
-
2008
- 2008-04-22 JP JP2008110835A patent/JP5227646B2/en not_active Expired - Fee Related
Also Published As
Publication number | Publication date |
---|---|
JP2009265708A (en) | 2009-11-12 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Henretty et al. | Data layout transformation for stencil computations on short-vector simd architectures | |
Stephens et al. | The ARM scalable vector extension | |
Sreraman et al. | A vectorizing compiler for multimedia extensions | |
US20060195828A1 (en) | Instruction generator, method for generating instructions and computer program product that executes an application for an instruction generator | |
JPH10228382A (en) | Compiling system | |
US20160321039A1 (en) | Technology mapping onto code fragments | |
JPH04211830A (en) | Parallel compiling system | |
Sato et al. | Automatic parallelization via matrix multiplication | |
JP6245031B2 (en) | Compilation program, compilation method, and compilation apparatus | |
Tian et al. | Compiling C/C++ SIMD extensions for function and loop vectorizaion on multicore-SIMD processors | |
Weng et al. | UNIT: Unifying tensorized instruction compilation | |
Hong et al. | Improving simd parallelism via dynamic binary translation | |
Adit et al. | Performance left on the table: an evaluation of compiler autovectorization for RISC-V | |
JP5227646B2 (en) | Compiler and code generation method thereof | |
US6059841A (en) | Updating data dependencies for loop strip mining | |
RU2411569C2 (en) | Method for automatic paralleling of programs | |
Arrabito et al. | Optimizing cherenkov photons generation and propagation in corsika for cta monte–carlo simulations | |
Elphick et al. | Partial evaluation of MATLAB | |
US20180217845A1 (en) | Code generation apparatus and code generation method | |
You et al. | Vectorizing spmv by exploiting dynamic regular patterns | |
Rapaport et al. | Streamlining whole function vectorization in C using higher order vector semantics | |
Bik et al. | A case study on compiler optimizations for the Intel® Core TM 2 Duo Processor | |
Baumstark et al. | Exposing data-level parallelism in sequential image processing algorithms | |
Haine et al. | Exploring and evaluating array layout restructuring for SIMDization | |
JP3196625B2 (en) | Parallel compilation method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20100825 |
|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20120724 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20120807 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20121009 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20130115 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20130128 |
|
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: 20130219 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20130318 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20160322 Year of fee payment: 3 |
|
LAPS | Cancellation because of no payment of annual fees |