JP3544397B2 - Compiler device and loop optimization control method - Google Patents

Compiler device and loop optimization control method Download PDF

Info

Publication number
JP3544397B2
JP3544397B2 JP23667094A JP23667094A JP3544397B2 JP 3544397 B2 JP3544397 B2 JP 3544397B2 JP 23667094 A JP23667094 A JP 23667094A JP 23667094 A JP23667094 A JP 23667094A JP 3544397 B2 JP3544397 B2 JP 3544397B2
Authority
JP
Japan
Prior art keywords
loop
optimization
unrolling
program
optimizations
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
JP23667094A
Other languages
Japanese (ja)
Other versions
JPH08101776A (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.)
Fujitsu Ltd
Original Assignee
Fujitsu 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 Fujitsu Ltd filed Critical Fujitsu Ltd
Priority to JP23667094A priority Critical patent/JP3544397B2/en
Publication of JPH08101776A publication Critical patent/JPH08101776A/en
Application granted granted Critical
Publication of JP3544397B2 publication Critical patent/JP3544397B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Description

【0001】
【産業上の利用分野】
本発明は,最適化機能を有するコンパイラの最適化効果を促進させるコンパイラ装置およびループ最適化制御方法に関するものである。
【0002】
近年,コンピュータシステムの高速化の要求に伴い,1サイクルで複数の命令を同時に実行できるプロセッサやベクトル演算が可能なマシンが数多く開発されている。それに伴い,それらのマシンを有効に運用するために,コンパイラに対する要求も高まってきている。特に,プログラムにおけるループ部分は実行時間の比重が高いため,ループ内部のコードを最適に生成することが翻訳/実行時間の短縮に大きく貢献することになる。本発明は,ループで行われる種々の最適化を有効に活用するためのループ最適化制御技術に関するものであり,産業上の利用性は広い。
【0003】
【従来の技術】
従来のコンパイラ装置におけるループ最適化として,ループ・アンローリング,ソフトウェア・パイプライニング等,個々のループ最適化はいくつか存在する。例えば,ループ・アンローリングに関しては,回転数をループ内で使用される浮動小数点型および整数型のレジスタ数とループ内で使用される演算数からアンローリング数を算出する方法が知られている(特開平4−307624号公報,特開平4−307625号公報)。また,ループ内のそれぞれの演算に対して各演算の実行時間重みを付加してループ内演算数を算出し,その値からアンローリング数を算出する方法もすでに提案されている。
【0004】
図9ないし図12は,従来のループ最適化の例であって,特に図9はループ・アンローリング,図10はリネーミング,図11および図12はソフトウェア・パイプライニングの例を示す。
【0005】
ループ・アンローリングは,例えば図9に示すように,ループ変数Iを含む演算を複数個に展開し,ループ回数を少なくする最適化である。
リネーミングは,図10(A)に示すようなプログラム(X1〜X5は異なる任意の変数)に対して,演算間の依存性をできるだけ少なくするため,変数名を変えても結果に影響のない変数を抽出して,他の変数名に置き換える最適化である。図10の例の場合,1番目と2番目の演算における変数名Aを変数名Bに変え,3番目と4番目の演算における変数名Aを変数名Cに変えることにより,▲1▼B=X1,X2=Bと▲2▼C=X3,X4=Cと▲3▼A=X5の演算間の依存性をなくしている。なお,ここでいうリネーミングとは,レジスタ割り当てあるいは命令スケジューリングで行われるレジスタ・リネーミングではなく,最適化フェーズの中でも比較的前段階で行われる中間言語に対するリネーミングである。
【0006】
ソフトウェア・パイプライニングによる最適化は,以下のとおりである。例えば,図11(A)に示す命令列がソースプログラムから生成されたあるループを構成する命令列であったとする。ループが図11(A)のように4回アンローリングされた場合,図11(B)に示すように4回転分の命令列を一まとまりとして処理する。これらの命令列を通常のようにスケジューリングすると,図12(A)に示すようになる。これをプロローグ部とエピローグ部に分けてパイプライン化すると図12(B)に示すようになり,さらにリスケジューリングすると,図12(C)に示すようになる。これにより,ループ内の演算にかかる時間を短縮することができる。図12(A)では,ループ内の演算に7τかかっていたものが,図12(B)では,4τに短縮されている。
【0007】
以上のように,各種のループ最適化の技術が知られているが,従来,種々のループ最適化をプログラム/ハードウェアの特性を把握して統括的に制御する方法は考えられていなかった。したがって,パターンマッチング的に最適化条件を満たすというだけで,種々の最適化を動作させる傾向にあった。このため,理論的には実行性能を向上させる最適化であっても有効に活用しきれず,かえって性能が落ちることさえあった。ループ・アンローリングのループ展開しすぎによるスピル生成などは最適化の逆効果としてよく知られる例である。
【0008】
なお,スピルとはレジスタ不足によるメモリへのロード,ストアのことをいう。プログラムで使用される変数,およびコンパイラの内部で生成される変数には,高速化のためできるだけレジスタが割り当てられる。しかし,レジスタの数に制限があり,レジスタが不足したとき,コンパイラではメモリ上の領域を利用する。メモリへのアクセスはロード,ストア命令を介して行われるため,レジスタを利用する場合と比較して大変遅く,性能低下を及ぼす原因となる。
【0009】
また,従来の技術では,ループの並列化を促す最適化がループ・アンローリング,ソフトウェア・パイプライニング,リネーミング程度しかなかった。特に,近年スーパースカラやVLIWというようなアーキテクチャが広く用いられるようになってきており,このようなアーキテクチャに適した新しい最適化の技術が望まれる。
【0010】
【発明が解決しようとする課題】
従来の技術では以下のような問題があった。
1.オプション解析情報,ハードウェア解析情報,プログラム解析情報を統括的に管理し,その情報をもとに個々の最適化を制御する部分がないため,個々の最適化がそれぞれの実施条件を満足するというだけで実施されてしまう。このため,かえって性能が低下する場合がある。
【0011】
2.上記1に関連して,それぞれは意味のある最適化であるが,それらが同時に動作することによってかえって性能が落ちる場合がある。また,優先度をつけて制御(抑止)すべき最適化もある。
【0012】
3.上記1に関連して,それぞれは意味のある最適化であるが,それらが同時に動作するためには,何らかの制御または制限を加えることをしないとかえって性能が落ちる場合がある。
【0013】
4.プログラムの解析は今までにも行われていたが,その解析のレベルが低く,ループ最適化後のコードは最適な状態には至っていない。例えば,今までのアンローリング数の決定は,種々の最適化が実施される前のループ内部の変数の依存関係を解析するため,最適コードを生成するのには限界があった。したがって,ループ内変数の依存関係から実施できる最適化を予想し,その上でその最適化が行われた後のループ内で使用される変数の依存関係を把握して使用レジスタ数を見積もることによりアンローリング数を決定する必要がある。
【0014】
5.上記4で示したプログラム解析の解析レベル制御が高度でない。プログラム解析によって得られる情報としては,最適化実施後の変数の依存関係を加味した使用レジスタ数,実行時間重みの付いた演算数等様々な情報がある。これらの情報を翻訳レベルを参照して獲得するかしないかを決定することによって,プログラムの解析レベルを段階的に制御することができる必要がある。
【0015】
本発明は上記問題点の解決を図り,複数のループ最適化を個々に実施するのではなく,プログラム/ハードウェアの特性をオプティマイズレベルに応じて解析し,実施する価値のあるループ最適化をより性能が上がる条件で,かつより性能の上がる組合せで実施できるようにすることを目的とする。
【0016】
【課題を解決するための手段】
図1は本発明の原理説明図である。
図1において,10はCPUおよびメモリ等からなる処理装置,11はソースプログラムをオブジェクトプログラムに翻訳するコンパイラ,12はソースプログラムの入力および初期処理を行うフロントエンド部,13はプログラム構造を解析するプログラム構造解析部,14は最適化処理を行うループ最適化部,15は変数等に対してレジスタを割り付けるレジスタ割り付け部,16は命令実行順序等のスケジューリングを行う命令スケジューリング部,17はスケジューリング結果に従ってオブジェクトコードを生成するコード生成部を表す。また,20はループ最適化制御部であって,オプション情報解析部21,ハードウェア情報解析部22,プログラム解析部23,ループ最適化制御決定部24からなるもの,30はループ変形部であって,ループ・アンローリング,ループ・リダクション(詳しくは後述する),ソフトウェア・パイプライニング等の最適化処理を行うものを表す。
【0017】
フロントエンド部12,プログラム構造解析部13,レジスタ割り付け部15,命令スケジューリング部16およびコード生成部17の処理については従来と同様でよいので,詳しい説明は省略する。
【0018】
本発明では,ループ最適化部14のプロローグ部にループ最適化制御部20を設けることによって,ループ内で実施する価値のある最適化を選択/制御しておき,ループ変形部30にその旨を伝達することにより,任意のプログラム/アーキテクチャ上で,翻訳/実行性能を向上できるループ最適化のみを実施する。
【0019】
従来の最適化では,最適化同士がお互いに干渉し合うことがなく,2つの最適化が同時に動作することにより性能が低下することがあったが,この発明により効果的に最適化を動作させることができる。
【0020】
図1に示すように,ループ最適化制御部20は,オプション情報解析部21,ハードウェア情報解析部22,プログラム解析部23,ループ最適化制御決定部24に細分化される。
【0021】
オプション情報解析部21/ハードウェア情報解析部22では,指定されたハードウェア/オプション環境をプログラム解析部23/ループ最適化制御決定部24に伝達する。例えば,オプション情報として,オプティマイズレベル,各最適化の実施/抑止等の情報,また,ハードウェア情報として,レジスタ数,キャッシュサイズ,ターゲットのマシンが持つ各命令の実行時間等の情報がある。これらの情報を,あるテーブル上に記録し,後の処理過程にメッセージとして伝達する方法をとる。
【0022】
プログラム解析部23では,オプション解析により決定したオプティマイズレベルに依存して,どの程度のプログラム解析をするのかを決定する。プログラム解析で収集する情報の例として以下の3つがある。
【0023】
1.ループ内に出現する演算数を各演算の実行時間重みを加味してカウントした値。
2.ループ内で使用される変数間の依存関係を把握し,実際に実施されるときと同じ条件かあるいはそれより緩い条件で,ループ変形部30で実際に行われる最適化を予想した結果。
【0024】
3.その予想した最適化が実際に実施されることを加味した上で,ループ内で使用されるレジスタ数をループに対してローカルに必要な整数型変数/浮動小数点型変数,ループに対してグローバルに必要な整数型変数/浮動小数点型変数に分けて見積もった値。
【0025】
上記2において,変数の依存関係を把握する方法の一例としては,ループ内の演算を各ノードとして作成したダグによる解析法がある。上記3において,最適化予想を加味する理由は,ループ・リダクションその他のループ最適化により,ループに対してローカルな変数が増加するためである(リネーミング以外の最適化結果を加味している点が今までと違うところである)。
【0026】
例えば,これらの1,2,3の情報の収集をオプティマイズレベルに依存して可/不可にすれば,プログラムの解析レベルを操作することができる。言い替えれば,翻訳/実行性能を操作することが可能になる。さらに具体的には,オプティマイズレベルが低い場合には,作成できるロードモジュールの実行時間をそれほど追求する必要がないので,翻訳性能が上がるように1のみの収集を行う方法をとれば,実行性能もある程度維持でき,かつ,翻訳性能が上がる最適化を導くことができる。
【0027】
ループ最適化制御決定部24では,オプション情報解析部21,ハードウェア情報解析部22,プログラム解析部23からの一連の情報をもとに実施可能な最適化を決定する。そして同時に,プログラム/アーキテクチャの特性を把握し,組み合わせて動作させるべきでない最適化を優先度に従って抑止,あるいは制限付きで実行させるようにループ変形部30に伝達する。この伝達の方法の一例としては,どういう最適化をどのように実行させるかを記したテーブルを作成し,それをメッセージとしてループ変形部30に伝達する方法がある。
【0028】
ループ最適化制御決定部24の情報の一つであるアンローリング数は,プログラム解析部23での解析レベルに依存して決定される。最適化予想とそれを加味したレジスタ数が算出されていれば,ループ変形部30で行われる最適化を十分に活かし,より並列化効果のでるアンローリング数を算出できる。アンローリング数の決定方法の実施例は後述する。
【0029】
ループ変形部30では,授受したその情報を参照しながら,ループ変形をする種々の最適化,例えば,ループ・アンローリング,本発明に係るループ・リダクション,リネーミング,ソフトウェア・パイプライニング等を実施する。
【0030】
続いて,ループ・リダクションの実現方法について述べる。ループ・リダクションは,ループ中で他の演算と依存関係のない変数Qが,Q=Q+α(αは定数でない)という形で出現し,かつ,アンローリングが行われた後に行われる特殊なリネーミング処理である。アンローリング後,ループ内に含まれるQ=Q+αという同じ演算(αが配列の場合には配列の添字が異なる)に対して,ある1つの演算中の変数Qを除いたすべての変数Qをリネーミングすることにより,Qを含む演算間のdependencyをなくすことができる。これにより,特に1サイクルで複数の命令を実行できるプロセッサでは並列化が大きく促進される。ただし,Qをリネーミングしてしまったため,ループ出口における変数Qは総和演算結果とならない。したがって,ループの前にリネーミングした変数Qγ(γ=1,2,3…)を初期化する処理,ループの後に変数Qに対して変数Qγ(γ=1,2,3…)を加算する処理が必要となる。このループの後に出す変数Qに対する補正処理は,Q=Q+Q1,Q=Q+Q2,Q=Q+Q3,…というような演算ではなく,余分なレジスタを使用せずに並列化を促進するように,Tree Height Reduction (演算木の高さをできるだけ小さくし,並列化を促進する最適化)を施す必要がある。ただし,ループ・リダクションは総和演算の順序を変更するため,実行結果に誤差を生じる可能性のある最適化である。
【0031】
【作用】
従来技術では,例えばA,B,C,…という複数の最適化項目があったとき,まず最適化項目Aについての実施可否/実施条件の判定,実施可の場合に最適化項目Aの実施,次に最適化項目Bについての実施可否/実施条件の判定,実施可の場合に最適化項目Bの実施,次に最適化項目Cについての実施可否/実施条件の判定,実施可の場合に最適化項目Cの実施,…というようにそれぞれ個別に最適化を実施していたのに対し,本発明では,ループ最適化制御部20を設けることにより,まず最適化項目A,B,C,…のすべての実施可否/実施条件を最初に総合的に判定し,最適化の実施予想から最も効果的な実施条件,実施順番等を決めて,ループ最適化を行う点が大きく異なる。
【0032】
本発明により以下の事項が可能となる。
・ループ最適化を予想してから,ループ最適化の制御をすることができる(最適化実施後のループ内の依存関係を把握できるため,高度なプログラム解析および高度な最適化制御ができる)。
【0033】
・オプティマイズレベル等によりプログラム解析のレベルを制御できる(それに依存して,高いオプティマイズレベルに対してより並列化効果の高いアンローリング数を決定できる)。
【0034】
・上記のように,アーキテクチャ/プログラムをコンパイラが高度に解析することにより,動作して性能の上がる最適化のみを実施することが可能になる。
・また,同時に動作するとかえって性能が低下するような最適化同士を優先度に従い抑止,あるいは制限付きで実行することが可能になる。
【0035】
・ループ・リダクションにより並列化が大きく促進する。
これらの機能(制御)によるより豊富な情報をもとに,種々の最適化をより効果が上がるように実施/抑止し,翻訳/実行性能を向上させることができる。
【0036】
【実施例】
図2は,本発明に係るループ・リダクションの例の説明図である。
本発明では,ループ最適化の一つとして,ループの並列度を高めるための新たなループ変形を採用する。これをループ・リダクションと呼ぶ。ループ・リダクションは,例えば,図2(A)に示すようなループ・アンローリングの結果に対して,ループ中で他の演算と依存関係のない変数Qを含む演算のうち,その2番目以降の演算における変数Qを,図2(B)に示すように,それぞれQ1,Q2,Q3とリネーミングし,Qを含む演算間の相互依存性をなくすことにより,Q,Q1,Q2,Q3の演算に関する並列実行性を促進する最適化である。
【0037】
ループ・リダクションは,プログラムの構造を変えないで単に変数名だけを他の変数名に置き換える従来のリネーミングとは異なり,元々は同一に扱われるべき変数を異なる変数として扱うものであるから,ループの前に値の初期処理,ループの後に補正処理のような付加的な処理が必要になる。
【0038】
図3は,本発明の実施例によるループ最適化部14の各フェーズを詳細化したフローチャートである。
ループ最適化部14に入力されたプログラムは,ループ最適化制御部20に入る。そして,オプション情報解析部21でオプティマイズレベル,最適化の実施抑止オプションを解析して各オプションの情報を一覧できるオプション情報テーブルを作成する。一般的に,あるオプションがオプションに連動する(実際には最適化自身が連動するのであるが)ことはよくある。例えば,オプティマイズレベルを示すオプションが良い例で,オプティマイズレベルを高いレベルにすると,コンパイラはそのプログラムに対して有効と思われる最適化をできるだけ動かす。したがって,あるオプションによって連動(抑止)される最適化のチェックが必要となる。すなわち,オプション解析では単に指定されたオプションの認識だけでなく,それから連動される最適化を解析する。オプティマイズレベルが最低レベルでループ最適化を行う必要がない場合には,図3のオプション情報解析部21の下のオプティマイズレベルに関する判定でループ最適化部14から脱出する。
【0039】
ハードウェア情報解析部22では,ロードモジュールを実行するマシンの様々な情報,例えば,整数型/浮動小数点型のレジスタ数,キャッシュサイズ,各アセンブラ命令の実行時間などを,そのマシンのハードウェア情報としてハードウェア情報テーブルに登録する。採取する情報量はオプティマイズレベル等に依存して変化する。
【0040】
プログラム解析部23では,オプション情報解析部21で得られた情報(オプティマイズレベル)に依存して,プログラム解析のレベルを変動する。
プログラムで解析すべき情報としては,例えば以下のものがある。
【0041】
1.ループ内に出現する演算に対して,ハードウェア情報テーブル上に記録された各演算の重みを加味した実行時間をカウントした値(実行時間重み付き演算数)。
【0042】
2.ループ内で使用される変数間の依存関係を把握し,かつオプション情報テーブルを参照することによって実施許可が与えられていることを考慮して,ループ変形部30で実際に行われる最適化を予想した結果。
【0043】
3.その予想した最適化が実際に実施されることを加味した上で,ループ内で使用されるレジスタ数をループに対してローカルに必要な整数型変数/浮動小数点型変数,ループに対してグローバルに必要な整数型変数/浮動小数点型変数に分けて見積もった値。ここで,最適化予想を加味する理由は,リネーミング,ループ・リダクションといったループ最適化により,ループに対してローカルに必要な変数が増加するためである。
【0044】
これらのどの情報が得られるかをオプティマイズレベルに依存して変化させることによって,プログラムの解析レベルを変動することができる。上記の例では,項目1に対して,項目2,3はより高度な解析レベルで実施することになる。プログラム解析部23でもプログラム情報テーブルが作成され,上記の情報が記録される。
【0045】
ループ最適化制御決定部24では,オプション情報テーブル,ハードウェア情報テーブル,プログラム情報テーブル,およびこのループ最適化制御決定部24が持つ最適化の優先順位テーブルを参照して,どの最適化をどのような順序でどのように実施するかを決定する。この最適化優先順位テーブルには,各最適化に対して,その優先順位と,自分より優先順位の高い最適化が動作したときに抑止されるか否かのフラグ,また,その最適化が実施されるための条件(例えば,ループ・リダクションであったならばループ・アンローリングが実施されていること)等が記録されている。
【0046】
ループ最適化制御決定部24では,プログラム情報テーブルから予想される最適化を認識し,ループ制御情報テーブル中に実施か抑止かを登録する。ただし,その設定の際に,最適化優先順位テーブルを参照し,同時に実行すべきでない最適化を抑止,あるいは制限付きで実行するようにする。例えば,ループ・アンローリングとループ・リダクションが予想された場合,最適化優先順位テーブルを参照して,ループ・アンローリングを制限付きで実施するという情報を得る。それからダグ情報から得たループ変形後のレジスタ数を参照して(ループ・リダクションによりループに対してローカルに必要な変数が増えていることが考慮されている),以下の計算式(1) によりアンローリング数を算出する。
【0047】
関数FUNCでは,ループ内で行われるループ最適化を加味して,第1引数,第2引数で与えられるアンローリング数のチューニング値を返す。例えば,ソフトウェア・パイプライニングが予想されたループの場合には,ターゲットであるマシンの浮動小数点型の四則演算の中(除算を除く)で最大の実行時間の倍数である値を返し(ただしUNROLL1は越えない),ループ・リダクションが予想された場合には,下の式(2) でリダクションを加味して求められた値UNROLL1をそのまま返すというようなチューニングをする。また,ソフトウェア・パイプライニング,ループ・リダクションが予想されるときのアンローリング数はレジスタ数を越えず,さらに,それらが予想されない時のループのアンローリング数でも,アンローリング後のループ内の総演算数がキャッシュサイズを越してしまわないように考慮している。
【0048】

Figure 0003544397
・FUNC():最適化OPTが行われることを加味して,第1引数,第2引数で与えられるアンローリング数をチューニングしてその値を返す。
【0049】
・UNROLL1:最適化後のループ内の使用変数を見積もって式(2) から決定したアンローリング数。UNROLL1は,基本的にソフトウェア・パイプライニング,ループ・リダクションの実施に対して,ループ内レジスタの再利用がないことを考慮して見積もった値である(これらの最適化が実施されない時は,アンローリング後,レジスタの再利用が行われることが多い)。
【0050】
・UNROLL2:ループ内の各演算に対して,それぞれの実行時間を重みとして加味して算出した総演算数から式(3) により決定したアンローリング数。
・MAX_IST:アンローリング後のループ内の時間重み付き総演算数の最大値。
【0051】
・IST:ループに対して算出した時間重み付き総演算数。
・OPT:ループ変形をするアンローリング以外のループ最適化(ex.0x0002)。
【0052】
・INUM:システムが持つ整数型レジスタ数。
・RNUM:システムが持つ浮動小数点型レジスタ数。
・ILOCAL:ループに対してローカルに必要な整数型レジスタ数。
【0053】
・IGLOBAL:ループに対してグローバルに必要な整数型レジスタ数。
・RLOCAL:ループに対してローカルに必要な浮動小数点型レジスタ数。
・RGLOBAL:ループに対してグローバルに必要な浮動小数点型レジスタ数。
【0054】
以上の関数FUNCによって得られるアンローリング数もループ制御情報としてループ制御情報テーブルに登録される。
ループ変形部30では,そのループ制御情報テーブルを受け取り,それらの情報に従って種々の最適化を実施する。例えば,ループ・アンローリング/実施/5回展開,ループ・リダクション/実施,ソフトウェア・パイプライニング/抑止というようなテーブル上の情報により,種々の最適化を実施/抑止する。
【0055】
図4は本発明の実施例による最適化の例を示す図,図5は本発明の実施例によるループ最適化部の動作例の説明図,図6および図7は本発明の実施例において用いられるテーブルの例を示す図である。
【0056】
以下に,本発明の実施例によるループ最適化部14が実際のプログラムの入力に対してどのように動作するかを,図4(A)に示すプログラムA(program A)を例にとって説明する。
【0057】
コンパイラに対してプログラムAが与えられると,プログラムAは図1に示すフロントエンド部12,プログラム構造解析部13を通過した後,ループ最適化部14に入力され,さらに,ループ最適化制御部20に到達する。
【0058】
図5に示すように,ループ最適化制御部20では,まず,オプション情報解析部21が動作し,そこでは,オプション指定により高いオプティマイズレベルを要求されていることを認識し,また,リネーミング抑止オプションが指定されていることを認識する。そしてさらに,高いオプティマイズレベルで連動する最適化を認識する。これらの情報を後のフェーズに伝達するために,図6(A)に示すようなオプション情報テーブルを作成する。
【0059】
オプション情報テーブルにおけるオプティマイズレベルは,次のように分別される。
0:最適化しない
1:低レベルの最適化
2:中レベルの最適化
3:高レベルの最適化
また,オプション情報テーブルにおける最適化は,次のように分別される。
【0060】
0x0001:ループ・アンローリング
0x0002:ループ・リダクション
0x0004:ソフトウェア・パイプライニング
0x0008:リネーミング
すなわち,0x0007は,ループ・アンローリングとループ・リダクションとソフトウェア・パイプライニングが対象になることを示す。
【0061】
ハードウェア情報解析部22では,オプション情報解析部21の情報(オプティマイズレベル)をもとに収集する情報を決定し,ハードウェア情報テーブルに登録する。いま,ターゲットとなるマシンの整数型のレジスタ数が32,浮動小数点型のレジスタ数が32,キャッシュサイズ16Kbyteとする。これに対して,図6(B)に示すようなハードウェア情報テーブルが作成される。
【0062】
プログラム解析部23では,図6(A)に示すオプション情報テーブルを参照し,高いオプティマイズレベルが要求されていることを認識し,最も高度なプログラム解析を行う。図5に示すように,まず,ループ内の各演算に対して各演算の実行時間をその演算の重みとして付加したループ内の総演算数を算出する。続いて,ループ内の各演算の依存関係を解析するために,ループに対して,各演算をノードとするダグを作成する。このダグから,プログラムAのループがループ・リダクションできる依存関係であることを認識する。また,ループ・アンローリングできることも認識する(ループの出口が一つであること等を確認する)。そして,オプション情報テーブルを参照して,その最適化が抑止されていないかを確認し最終的な予想結果を得る。予想される最適化は,実際に実施される最適化をすべて含む。したがって,予想されない最適化が動作することはない。
【0063】
次に,それらの最適化を加味した上で,ループ内で使用されるレジスタ数を見積もる。ループ内で使用されるレジスタ数は,ループ内ローカルな整数型/浮動小数点型,ループ内グローバルな整数型/浮動小数点型に分けて見積もる。これらの情報は,図6(C)に示すようなプログラム情報テーブルに登録される。
【0064】
ループ最適化制御決定部24では,ハードウェア情報テーブル,プログラム情報テーブルを参照して,ループ・アンローリング,ループ・リダクションが予想されていること等を認識する。そして,図7(A)に示すような最適化優先順位テーブルを参照し,個々の最適化がどのように実施されるかを決定する。その結果を,図7(B)に示すようなループ制御情報テーブルに記録する。最適化優先順位テーブル中の実施条件は,テーブルの第1列に並ぶ最適化が動作する前に必ず動作していなければならない最適化を示す。
【0065】
プログラムAでは,ループ・アンローリングとループ・リダクションが予想されているので,実施順序はループ・アンローリング,ループ・リダクション,実施条件はループ・リダクションを実施できるためのループ・アンローリングが実施されているから合格となる。また,ループ・アンローリングはループ・リダクションの実施のため,ループ・アンローリングが単独で動作したときよりもアンローリング数が少なく抑えられることになる。
【0066】
最適化優先順位テーブル中の制限付き実施について説明する。
〔ループ・アンローリング〕
テーブル上にあるような並列化効果のある最適化が予想されている時のループ・アンローリング数は,ループ・アンローリングが単独で実施された場合と比較して,リネーミング処理によりレジスタ数が増えているため,その数は少なく抑えられている。
【0067】
〔ループ・リダクション/ソフトウェア・パイプライニング〕
ループ・リダクション,またはソフトウェア・パイプライニングの実施とループ・アンローリングの実施が同時に予想されても,アンローリング数がある閾値(それぞれの最適化により異なる)より小さく,並列化効果が期待できないと判断された場合には,アンローリング以外の最適化を抑止することがある。
【0068】
また,ループ・リダクション,ソフトウェア・パイプライニングが同時に予想される場合には(アンローリングも当然予想されている),基本的には,ループ・リダクションを優先し,ソフトウェア・パイプライニングを抑止するが,上記の理由で,ループ・リダクションが抑止された場合でソフトウェア・パイプライニング可能な場合にはソフトウェア・パイプライニングのみ実施する。
【0069】
アンローリング数は,プログラム情報テーブル上の各レジスタ数を先述した式(1) の計算式に代入することにより求められる。これにより,OPTで与えられる最適化を十分意識した並列効果を最大にできるアンローリング数(6回)が算出される。このアンローリング数は,図7(B)に示すように,ループ制御情報テーブルのループ・アンローリングの備考欄に記録される。プログラムAでは,式(1) の関数は,OPTで与えられるループ・リダクションの実施予想を識別して,すでにループ・リダクションによりループに対してローカルに必要な変数が増えることを考慮して見積もったレジスタ数から算出済みであるアンローリング数UNROLL1をそのまま返す。ただし,このUNROLL1がある閾値より小さかった場合には,ループ制御情報テーブルのループ・リダクションの欄を抑止にし,ループ・リダクションが予想されなかったとして,アンローリング回数のチューニングを続け最終的に求まった値を関数値として返す。
【0070】
式(1) のOPTに他の最適化がきた場合のアンローリング数のチューニングの実施例を挙げておく。ソフトウェア・パイプライニングが予想された場合のアンローリング数は,浮動小数点型の除算を除く四則演算の実行時間の最大値の倍数,かつUNROLL1を越えない値となる(下記の式(4) 参照)。ただし,リダクションの場合と同様,アンローリング数UNROLL1がBASEより小さい場合にはループ制御情報テーブルのソフトウェア・パイプライニングの欄を抑止にし,ソフトウェア・パイプライニングが予想されなかったとして,アンローリング回数のチューニングを続け最終的に求まった値を関数値として返す。また,リネーミング効果がある場合にはリダクションと同様であるが閾値はなくUNROLL1がそのまま関数値となる。それ以外は,式(1) のUNROLL1とUNROLL2に対してある閾値を設け,UNROLL1がその閾値を越えたら両者の最小値,UNROLL1とUNROLL2がその閾値以下であったら両者の最大値,それ以外はUNROLL1を返す。
【0071】
〔ソフトウェア・パイプライニングが予想されたときのアンローリング数〕
式(1) の関数値=UNROLL1−UNROLL1%BASE (4)
・BASE:ターゲットとなるマシンにおける浮動小数点型の除算を除く四則演算(ex.fadd,fmult,fsub)の実行時間の最大値。
【0072】
・A%B:AをBで割った余り。
また,各最適化の実施順序は,最適化優先順位テーブルとプログラム情報テーブルを参照して記録される。ただし,算出したアンローリング数が小さい場合の最適化抑止の情報はすでにループ制御情報テーブルに記録されているのでその情報も参照する。この結果,プログラムAでは,ループ・アンローリング,ループ・リダクションという実行順序になる(ループ・アンローリングの制限は,上記のアンローリング数算出の際にすでに加味してあるので,実施の順序さえ伝達すれば良い)。
【0073】
ループ変形部30は,ループ制御情報テーブルを参照し,ループ・アンローリングとループ・リダクションの実施が許可され,その順序で最適化を実施することを認識する。また,アンローリング数6回が最適であるという情報をそのテーブルから得る。これにより,図4(B)のように,まず,6重展開のアンローリングが行われ,その後でループ・リダクションが行われる。これにより,ループ・リダクションの効果が最も期待できるアンローリング数でループを展開することができ,ループ内の演算の並列度も最大になる。
続いて,ループ・リダクションを図4を例にとって説明する。ループ・リダクションは,図4中のプログラムAのQ=Q+A(I)というパターンを含むループがアンローリングされたとき,その2つ目以降のQに対してQ→Qα(αはアンローリング数(6)−1)という特殊なリネーミングを行う最適化である。これにより,Qを含む演算とQαを含む演算の依存関係がすべてなくなり並列化が促進される。ただし,この補正処理として,ループ前にΣQα=0という演算を入れ,ループの後にQ=Q+ΣQαを入れる必要がある(Σはα=1から5までの総和)。また,このループの後の補正演算は,Tree Height Reduction により図4(C)に示すループ・リダクション後の命令列の後部における加算演算のように,演算木の高さができるだけ低くなるような形に変形される。
【0074】
前述したアンローリング数のチューニング値を返す関数FUNCのアルゴリズムの具体例を図8に示す。
図8では,ループ・アンローリングが予想されていることが前提となって行われる処理を示している。図8において,SPはソフトウェア・パイプライニング,retはFUNCの関数値(算出されたアンローリング数)を表す。また,MAX(A,B)はA,Bの最大値,MIN(A,B)はA,Bの最小値を表す関数である。
【0075】
▲1▼まず,リダクションが予想されたループに対する処理として,リダクション可で,かつUNROLL1が閾値1以上であれば,UNROLL1を関数値として返す。
【0076】
▲2▼次に,ソフトウェア・パイプライニングが予想されたループに対する処理として,ソフトウェア・パイプライニングが可で,かつUNROLL1が前述したBASE以上であれば,(UNROLL1−UNROLL1%BASE)を関数値として返す。
【0077】
▲3▼リネーミングが予想されたループに対する処理として,リネーミング可であれば,UNROLL1を関数値として返す。
▲4▼上記以外の場合,ノーマル・ループに対する処理であり,以下の処理を行う。
【0078】
・UNROLL1が閾値2より大きければ,UNROLL1とUNROLL2のうち小さいほうを関数値として返す。
・UNROLL2が閾値2以下の場合,UNROLL1とUNROLL2のうち大きいほうを関数値として返す。
【0079】
・それ以外の場合にはUNROLL1を関数値として返す。
以上のような処理によって,次のような作用効果がある。例えば従来のループ最適化にさらに本発明に係るループ・リダクションを加えた場合を想定する。
【0080】
1.ループ内部の演算数および使用変数が多く,かつ,ループ・アンローリングできる場合で,ループ・リダクションできるパターンがループ中に出現したとき,ループ内で使用する変数をリネーミングして,別の変数にしてしまうと,ループ内で使用される変数がさらに増加して,レジスタ割り当て処理でスピルを生成する可能性がある。本発明では,ループ最適化を予想して,事前に使用レジスタ数を適切に見積もることが可能であるため,スピルの生成などを回避することができる。
【0081】
2.上記1に関連して,それぞれは意味のある最適化であるが,それらが同時に動作することによってかえって性能が落ちるような場合,すなわち,上記1の例で挙げたようなループに対して,ループ・アンローリング,ループ・リダクションを同時に実施すると,スピルを生成する可能性があるため,ループ・リダクションを抑止し,ループ・アンローリングのみを実行させるというような何らかの制御が必要となる場合に,その適切な制御が可能になる。また,例えば,ループ・リダクションとソフトウェア・パイプライニングが同時に実行予想されるとき,同時に動作するとかえって性能が落ちる可能性があるため,より並列化効果の高いループ・リダクションを優先させるような制御も可能になる。
【0082】
3.例えば,ループ・アンローリング,ループ・リダクションが実施されうるループにおいて,同時に動作させる場合にアンローリングの数を制限するというような制御が可能になる。
【0083】
4.今までのアンローリング数の決定は,種々の最適化が実施される前のループ内部の変数の依存関係を解析するため,最適コードを生成するのには限界があった。これに対し,ループ内変数の依存関係から実施できる最適化を予想し,その上でその最適化が行われた後のループ内で使用される変数の依存関係を把握して使用レジスタ数を見積もることによりアンローリング数を決定することが可能になる。
【0084】
5.例えば,高いオプティマイズレベルを要求された場合は,翻訳時間よりロードモジュールの実行時間を優先するためにできるだけ多くの情報を獲得しておき,低いオプティマイズレベルを要求された場合は,翻訳時間を優先させるため,取得に時間のかからない情報のみを獲得するということが可能になる。
【0085】
上記項目の実現により,任意のプログラム,任意のハードウェアに対して,どの最適化をどのように実施したら並列効果の高いコードを生成できるのかをコンパイラ自身が把握できるようになる。
【0086】
また,本発明の一つであるループ・リダクションは,ループ中に他の演算と依存関係のない変数Qが,Q=Q+α(αは定数でない)という形で出現し,かつアンローリングが行われた場合に施されるループ変形法であり,その並列化効果は非常に高い。
【0087】
【発明の効果】
以上説明したように,従来は最適化同士が互いに干渉していなかったため,複数の最適化が同時に動作するとかえって逆効果になる場合があったが,本発明によれば,各最適化がループ内構造を解析することによって予想され,その最適化の実施を考慮に入れたループ内レジスタ数の見積りができ,また,実施予想された最適化が互いに干渉しあうことによって,最適化の効果が最大になるように種々の最適化を実施/抑止することができるようになり,ループに対してより最適なコードが生成できるようになる。さらに,オプション情報解析部,ハードウェア情報解析部,プログラム解析部,ループ最適化制御決定部の連係を良くすることによって,任意のマシン,任意のプログラムでより最適なコードを生成できるようになる。
【0088】
ループ・リダクションの効果自体も大きく,ループ・リダクションが行われるときのループ内の演算の並列度が高くなるため実行性能は大きく向上する。
【図面の簡単な説明】
【図1】本発明の原理説明図である。
【図2】本発明に係るループ・リダクションの例の説明図である。
【図3】本発明の実施例によるループ最適化部の処理フローチャートである。
【図4】本発明の実施例による最適化の例を示す図である。
【図5】本発明の実施例によるループ最適化部の動作例の説明図である。
【図6】本発明の実施例において用いられるテーブルの例を示す図である。
【図7】本発明の実施例において用いられるテーブルの例を示す図である。
【図8】本発明の実施例におけるアンローリング数のチューニング値を返す関数FUNCの処理説明図である。
【図9】従来のループ・アンローリングによる最適化の例の説明図である。
【図10】従来のリネーミングによる最適化の例の説明図である。
【図11】従来のソフトウェア・パイプライニングによる最適化の例の説明図である。
【図12】従来のソフトウェア・パイプライニングによる最適化の例の説明図である。
【符号の説明】
10 処理装置
11 コンパイラ
12 フロントエンド部
13 プログラム構造解析部
14 ループ最適化部
15 レジスタ割り付け部
16 命令スケジューリング部
17 コード生成部
20 ループ最適化制御部
21 オプション情報解析部
22 ハードウェア情報解析部
23 プログラム解析部
24 ループ最適化制御決定部
30 ループ変形部[0001]
[Industrial applications]
The present invention relates to a compiler device and a loop optimization control method for promoting an optimization effect of a compiler having an optimization function.
[0002]
2. Description of the Related Art In recent years, with the demand for higher speed of computer systems, many processors and machines capable of performing vector operations in a single cycle have been developed. Along with this, the demands on compilers for effectively operating those machines are increasing. In particular, since the loop portion of a program has a high execution time, generating the code inside the loop optimally greatly contributes to shortening the translation / execution time. The present invention relates to a loop optimization control technique for effectively utilizing various optimizations performed in a loop, and has wide industrial applicability.
[0003]
[Prior art]
There are several individual loop optimizations such as loop unrolling and software pipelining as loop optimization in a conventional compiler device. For example, with respect to loop unrolling, a method is known in which the number of rotations is calculated from the number of floating-point and integer registers used in the loop and the number of operations used in the loop ( JP-A-4-307624, JP-A-4-307625). Also, a method has been proposed in which the execution time weight of each operation is added to each operation in the loop to calculate the number of operations in the loop, and the unrolling number is calculated from the calculated value.
[0004]
9 to 12 show examples of conventional loop optimization. In particular, FIG. 9 shows an example of loop unrolling, FIG. 10 shows an example of renaming, and FIGS. 11 and 12 show examples of software pipelining.
[0005]
The loop unrolling is an optimization for expanding the operation including the loop variable I into a plurality of operations and reducing the number of loops as shown in FIG. 9, for example.
Renaming is performed on a program as shown in FIG. 10A (X1 to X5 are arbitrary variables different from each other) so that the dependency between operations is reduced as much as possible. This is an optimization that extracts variables and replaces them with other variable names. In the example of FIG. 10, by changing the variable name A in the first and second operations to the variable name B and changing the variable name A in the third and fourth operations to the variable name C, (1) B = The dependence between the calculations of X1, X2 = B, (2) C = X3, X4 = C, and (3) A = X5 is eliminated. Note that the renaming here is not register renaming performed by register allocation or instruction scheduling, but renaming for an intermediate language performed relatively earlier in the optimization phase.
[0006]
Optimization by software pipelining is as follows. For example, it is assumed that the instruction sequence shown in FIG. 11A is an instruction sequence forming a certain loop generated from a source program. When the loop is unrolled four times as shown in FIG. 11A, the instruction sequence for four rotations is processed as a unit as shown in FIG. 11B. When these instruction strings are scheduled as usual, the result is as shown in FIG. If this is divided into a prologue section and an epilogue section and made into a pipeline, the result is as shown in FIG. 12B, and further rescheduling is as shown in FIG. 12C. As a result, the time required for the operation in the loop can be reduced. In FIG. 12A, the calculation in the loop takes 7τ, but in FIG. 12B, it is reduced to 4τ.
[0007]
As described above, various loop optimization techniques are known, but a method of controlling various loop optimizations by grasping the characteristics of a program / hardware and generally controlling the loop optimization has not been considered. Therefore, there is a tendency that various optimizations are operated simply by satisfying the optimization condition in pattern matching. For this reason, in theory, even optimization that improves execution performance could not be used effectively, and the performance could even drop. Spill generation due to excessive loop unrolling in loop unrolling is an example well known as an adverse effect of optimization.
[0008]
Note that spill refers to loading and storing to memory due to lack of registers. Registers are allocated to variables used in the program and variables generated inside the compiler as much as possible for high speed. However, there is a limit to the number of registers, and when there are not enough registers, the compiler uses an area in memory. Since access to the memory is performed via load and store instructions, it is much slower than in the case of using a register, which causes a reduction in performance.
[0009]
Further, in the prior art, the optimization for promoting the parallelization of the loop is limited to the loop unrolling, the software pipelining, and the renaming. Particularly, in recent years, architectures such as superscalar and VLIW have been widely used, and a new optimization technique suitable for such an architecture is desired.
[0010]
[Problems to be solved by the invention]
The conventional technology has the following problems.
1. It collectively manages the option analysis information, hardware analysis information, and program analysis information, and there is no part to control each optimization based on that information, so each optimization satisfies each implementation condition. It will only be implemented. For this reason, the performance may be rather deteriorated.
[0011]
2. In connection with 1 above, each is a meaningful optimization, but performance may be degraded by their simultaneous operation. There are also optimizations that need to be prioritized and controlled (suppressed).
[0012]
3. In connection with 1 above, each is a meaningful optimization, but in order for them to operate at the same time, performance may degrade without some control or restriction.
[0013]
4. Although program analysis has been performed, the level of analysis is low, and the code after loop optimization has not been optimized. For example, the determination of the number of unrolling so far has been limited in that an optimum code is generated because the dependence of variables in a loop before various optimizations are performed is analyzed. Therefore, by predicting the optimization that can be performed from the dependencies of the variables in the loop, and then grasping the dependencies of the variables used in the loop after the optimization has been performed, estimating the number of registers used The number of unrolling needs to be determined.
[0014]
5. The analysis level control of the program analysis shown in 4 above is not advanced. The information obtained by the program analysis includes various information such as the number of registers used and the number of operations with execution time weights in consideration of the dependence of variables after optimization. By determining whether or not to acquire such information by referring to the translation level, it is necessary to be able to control the analysis level of the program step by step.
[0015]
The present invention solves the above problems, and analyzes the characteristics of a program / hardware according to an optimization level, instead of individually performing a plurality of loop optimizations, and realizes a loop optimization worth performing. It is an object of the present invention to be able to implement the program in a condition with higher performance and in a combination with higher performance.
[0016]
[Means for Solving the Problems]
FIG. 1 is a diagram illustrating the principle of the present invention.
In FIG. 1, reference numeral 10 denotes a processing device including a CPU, a memory, and the like; 11, a compiler for translating a source program into an object program; 12, a front end unit for inputting and initializing a source program; and 13, a program for analyzing a program structure. A structural analysis unit, 14 is a loop optimizing unit that performs optimization processing, 15 is a register allocating unit that allocates registers to variables and the like, 16 is an instruction scheduling unit that performs scheduling such as instruction execution order, and 17 is an object according to the scheduling result. Represents a code generation unit that generates code. Reference numeral 20 denotes a loop optimization control unit, which includes an option information analysis unit 21, a hardware information analysis unit 22, a program analysis unit 23, and a loop optimization control determination unit 24. Reference numeral 30 denotes a loop deformation unit. , Loop unrolling, loop reduction (to be described in detail later), and software pipelining.
[0017]
The processes of the front end unit 12, the program structure analysis unit 13, the register allocation unit 15, the instruction scheduling unit 16, and the code generation unit 17 may be the same as those in the related art, and a detailed description thereof will be omitted.
[0018]
In the present invention, the loop optimization control unit 20 is provided in the prologue unit of the loop optimization unit 14 to select / control an optimization that is worth performing in the loop, and the loop deformation unit 30 is notified of the fact. By transmitting, only loop optimization that can improve translation / execution performance is performed on an arbitrary program / architecture.
[0019]
In the conventional optimization, the optimization did not interfere with each other, and the performance sometimes deteriorated due to the simultaneous operation of the two optimizations. However, the present invention allows the optimization to operate effectively. be able to.
[0020]
As shown in FIG. 1, the loop optimization control unit 20 is subdivided into an option information analysis unit 21, a hardware information analysis unit 22, a program analysis unit 23, and a loop optimization control determination unit 24.
[0021]
The option information analysis unit 21 / hardware information analysis unit 22 transmits the specified hardware / option environment to the program analysis unit 23 / loop optimization control determination unit 24. For example, the option information includes information such as an optimization level and execution / inhibition of each optimization, and the hardware information includes information such as the number of registers, a cache size, and the execution time of each instruction of the target machine. This information is recorded on a table and transmitted as a message to the subsequent processing.
[0022]
The program analysis unit 23 determines how much program analysis is to be performed depending on the optimization level determined by the option analysis. The following three are examples of information collected by program analysis.
[0023]
1. A value obtained by counting the number of operations that appear in the loop, taking into account the execution time weight of each operation.
2. A result of ascertaining the dependency between variables used in the loop and predicting the optimization actually performed by the loop deforming unit 30 under the same conditions as those actually performed or under conditions less strict.
[0024]
3. Taking into account the fact that the predicted optimization is actually performed, the number of registers used in the loop is changed to an integer variable / floating point variable required locally for the loop and globally for the loop. Estimated value divided into necessary integer type variables / floating point type variables.
[0025]
In the above item 2, as an example of a method for grasping the dependency of a variable, there is an analysis method using a tag created by calculating an operation in a loop as each node. In the above 3, the reason for taking into account the optimization expectation is that the number of variables local to the loop is increased by loop reduction or other loop optimization (points that optimization results other than renaming are taken into account) Is different from before).
[0026]
For example, if the collection of these information items 1, 2, and 3 is enabled / disabled depending on the optimization level, the analysis level of the program can be controlled. In other words, translation / execution performance can be manipulated. More specifically, when the optimization level is low, it is not necessary to pursue the execution time of the load module that can be created so much. Therefore, if the method of collecting only one so as to increase the translation performance is adopted, the execution performance is also improved. It can be maintained to some extent and can lead to optimization that improves translation performance.
[0027]
The loop optimization control determination unit 24 determines an executable optimization based on a series of information from the option information analysis unit 21, the hardware information analysis unit 22, and the program analysis unit 23. At the same time, grasp the characteristics of the program / architecture, In combination The optimization which should not be performed is transmitted to the loop deforming unit 30 so as to be suppressed or executed with restriction according to the priority. As an example of this transmission method, there is a method in which a table describing what kind of optimization is performed and how to execute it is transmitted to the loop transformation unit 30 as a message.
[0028]
The unrolling number, which is one of the information of the loop optimization control determining unit 24, is determined depending on the analysis level in the program analyzing unit 23. If the prediction of the optimization and the number of registers in consideration of the prediction are calculated, the optimization performed by the loop transformation unit 30 can be fully utilized, and the unrolling number that can achieve the parallelization effect can be calculated. An embodiment of the method of determining the unrolling number will be described later.
[0029]
The loop deforming unit 30 performs various optimizations for performing the loop deformation, for example, loop unrolling, loop reduction, renaming, software pipelining, and the like according to the present invention while referring to the transmitted and received information. .
[0030]
Next, a method for implementing loop reduction will be described. Loop reduction is a special renaming that occurs after a variable Q that has no dependency on other operations in a loop appears in the form of Q = Q + α (α is not a constant) and that unrolling is performed. Processing. After unrolling, for the same operation Q = Q + α included in the loop (if α is an array, the subscript of the array is different), all variables Q except the variable Q in one operation are rewritten. By naming, dependency between operations including Q can be eliminated. As a result, parallelization is greatly promoted particularly in a processor that can execute a plurality of instructions in one cycle. However, since Q has been renamed, the variable Q at the loop exit does not become the sum operation result. Therefore, the process of initializing the renamed variable Qγ (γ = 1, 2, 3,...) Before the loop, and adding the variable Qγ (γ = 1, 2, 3,...) To the variable Q after the loop Processing is required. The correction processing for the variable Q output after this loop is not an operation such as Q = Q + Q1, Q = Q + Q2, Q = Q + Q3,... It is necessary to perform Reduction (optimization to reduce the height of the operation tree as much as possible and promote parallelization). However, loop reduction is an optimization that may cause an error in the execution result because the order of the summation operation is changed.
[0031]
[Action]
In the prior art, for example, when there are a plurality of optimization items such as A, B, C,..., First, whether or not to perform the optimization item A is determined. Next, determination of the execution possibility / execution condition for optimization item B, execution of optimization item B when execution is possible, judgment of execution possibility / execution condition for optimization item C, optimization when execution is possible In contrast to the optimization of each of the optimization items C,..., Each of the optimization items A, B, C,. The point is that a loop optimization is performed by first comprehensively judging all possible / non-executable conditions / implementation conditions, and determining the most effective execution conditions, execution order, and the like from the optimization execution prediction.
[0032]
The present invention enables the following items.
-Control of loop optimization can be performed after anticipating loop optimization (because the dependence in the loop after the optimization has been performed can be grasped, advanced program analysis and advanced optimization control can be performed).
[0033]
The level of program analysis can be controlled by the optimization level or the like (depending on it, the number of unrolling with a higher parallelization effect can be determined for a higher optimization level).
[0034]
-As described above, the compiler analyzes the architecture / program to a high degree, so that it is possible to execute only the optimization that operates and improves the performance.
Also, it is possible to execute optimizations that are degraded in performance if they are operated simultaneously, with suppression or restriction according to priority.
[0035]
・ Parallelization is greatly promoted by loop reduction.
Based on abundant information obtained by these functions (controls), various optimizations can be performed / suppressed so as to increase the effect, and the translation / execution performance can be improved.
[0036]
【Example】
FIG. 2 is an explanatory diagram of an example of loop reduction according to the present invention.
In the present invention, as one of the loop optimizations, a new loop deformation for increasing the parallelism of the loop is adopted. This is called loop reduction. The loop reduction is performed, for example, on the result of loop unrolling as shown in FIG. As shown in FIG. 2B, the variable Q in the operation is renamed to Q1, Q2, and Q3, respectively, and the interdependence between the operations including Q is eliminated, so that the operation of Q, Q1, Q2, and Q3 is performed. This is an optimization that promotes parallel execution.
[0037]
Unlike conventional renaming, in which only variable names are replaced with other variable names without changing the structure of the program, loop reduction treats variables that should be treated the same as different variables from the beginning. Additional processing such as initial processing of values before the processing and correction processing after the loop is required.
[0038]
FIG. 3 is a flowchart detailing each phase of the loop optimizing unit 14 according to the embodiment of the present invention.
The program input to the loop optimization unit 14 enters the loop optimization control unit 20. Then, the option information analysis unit 21 analyzes the optimization level and the optimization suppression option, and creates an option information table capable of listing information on each option. Generally, it is common for an option to be linked to the option (although the optimization itself is actually linked). For example, if the option that indicates the optimization level is a good example, and the optimization level is set to a high level, the compiler performs as much optimization as possible for the program. Therefore, it is necessary to check the optimization linked (suppressed) by a certain option. That is, in the option analysis, not only the specified option is recognized but also the optimization linked therewith is analyzed. If it is not necessary to perform the loop optimization at the lowest optimization level, the process exits from the loop optimization unit 14 in the determination regarding the optimization level below the option information analysis unit 21 in FIG.
[0039]
The hardware information analysis unit 22 uses various information of the machine that executes the load module, such as the number of integer / floating-point registers, the cache size, and the execution time of each assembler instruction, as hardware information of the machine. Register in the hardware information table. The amount of information to be collected changes depending on the optimization level and the like.
[0040]
The program analysis unit 23 changes the level of program analysis depending on the information (optimization level) obtained by the option information analysis unit 21.
Information to be analyzed by the program includes, for example, the following.
[0041]
1. A value obtained by counting the execution time in which the weight of each operation recorded on the hardware information table is added to the operation appearing in the loop (the number of execution time weighted operations).
[0042]
2. The optimization performed by the loop deforming unit 30 is predicted in consideration of the dependency between the variables used in the loop and the fact that the execution permission is given by referring to the option information table. Result.
[0043]
3. Taking into account the fact that the predicted optimization is actually performed, the number of registers used in the loop is changed to an integer variable / floating point variable required locally for the loop and globally for the loop. Estimated value divided into necessary integer type variables / floating point type variables. Here, the reason for taking the optimization prediction into account is that variables required locally for the loop increase by loop optimization such as renaming and loop reduction.
[0044]
By changing which information is obtained depending on the optimization level, the analysis level of the program can be changed. In the above example, items 2 and 3 are performed at a higher analysis level than item 1. The program analyzing section 23 also creates a program information table and records the above information.
[0045]
The loop optimization control determining unit 24 refers to the option information table, the hardware information table, the program information table, and the priority table of the optimization that the loop optimization control determining unit 24 has, and determines which optimization is performed. Determine how to implement them in a proper order. This optimization priority table contains, for each optimization, its priority, a flag indicating whether or not the optimization with a higher priority than its own operation is suppressed, and the optimization performed. Conditions (for example, loop unrolling must be performed if the processing is loop reduction) are recorded.
[0046]
The loop optimization control determining unit 24 recognizes the optimization expected from the program information table, and registers whether to execute or inhibit the optimization in the loop control information table. However, at the time of the setting, the optimization priority order table is referred to, and the optimization that should not be performed at the same time is suppressed or executed with a limitation. For example, when the loop unrolling and the loop reduction are expected, the information that the loop unrolling is performed with a limitation is obtained by referring to the optimization priority table. Then, referring to the number of registers after the loop transformation obtained from the tag information (considering that the number of variables required locally for the loop is increased by loop reduction), the following formula (1) is used. Calculate the unrolling number.
[0047]
The function FUNC returns the tuning value of the unrolling number given by the first argument and the second argument, taking into account the loop optimization performed in the loop. For example, in the case of a loop in which software pipelining is expected, a value that is a multiple of the maximum execution time among floating-point arithmetic operations (excluding division) of the target machine is returned (however, UNROLL1 is If the loop reduction is expected, tuning is performed such that the value UNROLL1 obtained by taking into account the reduction in equation (2) below is returned as it is. Also, the number of unrolling when software pipelining and loop reduction are expected does not exceed the number of registers, and the number of unrolling of the loop when they are not expected is the total number of operations in the loop after unrolling. Care is taken that the number does not exceed the cache size.
[0048]
Figure 0003544397
FUNC (): Tune the unrolling number given by the first argument and the second argument in consideration of performing the optimization OPT, and return the value.
[0049]
UNROLL1: The unrolling number determined from Equation (2) by estimating the variables used in the loop after optimization. UNROLL1 is a value estimated in consideration of the fact that there is no reuse of registers in the loop when software pipelining and loop reduction are basically performed. After rolling, registers are often reused.)
[0050]
UNROLL2: The unrolling number determined by the equation (3) from the total number of operations calculated by taking each execution time as a weight for each operation in the loop.
MAX_IST: the maximum value of the total number of time-weighted operations in the loop after unrolling.
[0051]
IST: the total number of time-weighted operations calculated for the loop.
OPT: Loop optimization other than unrolling that performs loop deformation (ex. 0x0002).
[0052]
INUM: the number of integer registers of the system.
RNUM: the number of floating-point registers of the system.
ILOGAL: the number of integer registers required locally for the loop.
[0053]
IGLOBAL: the number of integer registers required globally for the loop.
RLOCAL: the number of floating-point registers required locally for the loop.
RGLOBAL: the number of floating-point registers required globally for the loop.
[0054]
The unrolling number obtained by the above function FUNC is also registered in the loop control information table as loop control information.
The loop deforming unit 30 receives the loop control information table and performs various optimizations according to the information. For example, various optimizations are executed / suppressed by using information on a table such as loop unrolling / execution / unfolding 5 times, loop reduction / execution, and software pipelining / suppression.
[0055]
4 is a diagram showing an example of optimization according to the embodiment of the present invention, FIG. 5 is an explanatory diagram of an operation example of the loop optimizing unit according to the embodiment of the present invention, and FIGS. 6 and 7 are used in the embodiment of the present invention. FIG. 6 is a diagram showing an example of a table to be displayed.
[0056]
Hereinafter, how the loop optimizing unit 14 according to the embodiment of the present invention operates in response to actual program input will be described with reference to a program A (program A) shown in FIG.
[0057]
When the program A is given to the compiler, the program A passes through the front end unit 12 and the program structure analysis unit 13 shown in FIG. 1 and is input to the loop optimization unit 14, and further, the loop optimization control unit 20 To reach.
[0058]
As shown in FIG. 5, in the loop optimization control unit 20, first, an option information analysis unit 21 operates, and recognizes that a high optimization level is required by specifying an option, and suppresses renaming. Recognize that an option has been specified. Furthermore, it recognizes optimization linked at a high optimization level. In order to transmit such information to a later phase, an option information table as shown in FIG. 6A is created.
[0059]
The optimization level in the option information table is classified as follows.
0: Do not optimize
1: Low level optimization
2: Medium level optimization
3: High level optimization
Further, optimization in the option information table is classified as follows.
[0060]
0x0001: Loop unrolling
0x0002: Loop reduction
0x0004: Software pipelining
0x0008: Renaming
That is, 0x0007 indicates that loop unrolling, loop reduction, and software pipelining are targets.
[0061]
The hardware information analysis unit 22 determines information to be collected based on the information (optimization level) of the option information analysis unit 21 and registers the information in the hardware information table. It is now assumed that the target machine has 32 integer-type registers, 32 floating-point registers, and a cache size of 16 Kbytes. On the other hand, a hardware information table as shown in FIG. 6B is created.
[0062]
The program analysis unit 23 refers to the option information table shown in FIG. 6A, recognizes that a high optimization level is required, and performs the most advanced program analysis. As shown in FIG. 5, first, the total number of operations in the loop is calculated by adding the execution time of each operation to each operation in the loop as the weight of the operation. Subsequently, in order to analyze the dependence of each operation in the loop, a tag is created for the loop with each operation as a node. From this tag, it is recognized that the loop of the program A has a dependency that enables the loop reduction. Also recognize that loop unrolling can be performed (confirm that there is only one loop exit). Then, by referring to the option information table, it is checked whether or not the optimization is suppressed, and a final expected result is obtained. Expected optimizations include all optimizations that are actually performed. Therefore, no unexpected optimization will work.
[0063]
Next, the number of registers used in the loop is estimated after taking these optimizations into account. The number of registers used in the loop is estimated separately for a local integer / floating-point type in the loop and a global integer / floating-point type in the loop. These pieces of information are registered in a program information table as shown in FIG.
[0064]
The loop optimization control determining unit 24 refers to the hardware information table and the program information table, and recognizes that loop unrolling and loop reduction are expected. Then, referring to the optimization priority table as shown in FIG. 7A, it is determined how each optimization is performed. The result is recorded in a loop control information table as shown in FIG. The execution condition in the optimization priority table indicates an optimization that must always be operating before the optimization in the first column of the table operates.
[0065]
In the program A, since loop unrolling and loop reduction are expected, the execution order is loop unrolling, loop reduction, and the execution condition is such that loop unrolling for performing loop reduction is performed. Passed because there is. Further, since the loop unrolling performs the loop reduction, the number of unrolling can be suppressed to be smaller than when the loop unrolling operates alone.
[0066]
The restricted implementation in the optimization priority table will be described.
[Loop unrolling]
The number of loop unrolling when the optimization with the parallelization effect as shown in the table is expected is smaller than the number of registers due to the renaming process compared to the case where loop unrolling is performed alone. Because of the increase, the number is kept low.
[0067]
[Loop Reduction / Software Pipelining]
Even if the execution of loop reduction or software pipelining and the execution of loop unrolling are expected at the same time, it is judged that the number of unrolling is smaller than a certain threshold (depending on each optimization) and the parallelization effect cannot be expected. In some cases, optimization other than unrolling may be suppressed.
[0068]
When loop reduction and software pipelining are expected at the same time (unrolling is naturally expected), basically, priority is given to loop reduction and software pipelining is suppressed. For the above reason, if loop reduction is suppressed and software pipelining is possible, only software pipelining is performed.
[0069]
The number of unrolling is obtained by substituting the number of registers in the program information table into the above-mentioned equation (1). As a result, the number of unrollings (six times) that can maximize the parallel effect that is sufficiently aware of the optimization given by the OPT is calculated. This unrolling number is recorded in the remarks column of loop unrolling in the loop control information table as shown in FIG. In the program A, the function of the equation (1) is identified by identifying the expected execution of the loop reduction given by the OPT and taking into account that the number of variables required locally for the loop is already increased by the loop reduction. The unrolling number UNROLL1 already calculated from the register number is returned as it is. However, if the UNROLL1 is smaller than a certain threshold, the loop reduction column of the loop control information table is suppressed, and it is determined that loop reduction is not expected. Returns the value as a function value.
[0070]
An example of tuning the number of unrolling when the OPT of Expression (1) is subjected to another optimization will be described. When software pipelining is expected, the unrolling number is a multiple of the maximum value of the execution time of the four arithmetic operations excluding floating-point division, and a value not exceeding UNROLL1 (see the following equation (4)). . However, as in the case of the reduction, if the unrolling number UNROLL1 is smaller than BASE, the software pipe lining column of the loop control information table is suppressed, and it is determined that software pipe lining is not expected. And return the final value as a function value. If there is a renaming effect, it is the same as reduction, but there is no threshold, and UNROLL1 is the function value as it is. Otherwise, a certain threshold value is set for UNROLL1 and UNROLL2 in the equation (1), the minimum value of UNROLL1 exceeds the threshold value, the maximum value of UNROLL1 and UNROLL2 if UNROLL2 is less than the threshold value, otherwise the maximum value of both. Returns UNROLL1.
[0071]
[Unrolling number when software pipelining is expected]
Function value of equation (1) = UNROLL1-UNROLL1% BASE (4)
BASE: The maximum value of the execution time of the four arithmetic operations (ex.fadd, fult, fsub) excluding the floating-point type division in the target machine.
[0072]
A% B: remainder of A divided by B
The execution order of each optimization is recorded with reference to the optimization priority table and the program information table. However, since the information of the optimization suppression when the calculated unrolling number is small is already recorded in the loop control information table, the information is also referred to. As a result, in program A, the execution order is loop unrolling and loop reduction (since the limitation of loop unrolling has already been taken into account when calculating the number of unrolling, even the order of execution is transmitted. Just do it).
[0073]
The loop deforming unit 30 refers to the loop control information table, and recognizes that the execution of the loop unrolling and the loop reduction is permitted, and that the optimization is performed in that order. Also, information that the number of unrolling times of six is optimal is obtained from the table. As a result, as shown in FIG. 4B, first, unrolling of six-fold expansion is performed, and thereafter, loop reduction is performed. As a result, the loop can be unrolled with the number of unrolling that is most expected to achieve the effect of the loop reduction, and the degree of parallelism of the operation in the loop is maximized.
Next, the loop reduction will be described with reference to FIG. When the loop including the pattern of Q = Q + A (I) of the program A in FIG. 4 is unrolled, Q → Qα (α is the number of unrolling (α) 6) -1) is an optimization for performing special renaming. This eliminates all dependencies between the operation including Q and the operation including Qα, and promotes parallelization. However, as this correction processing, it is necessary to insert an operation of ΣQα = 0 before the loop and insert Q = Q + ΣQα after the loop (Σ is the sum of α = 1 to 5). The correction operation after this loop is performed by Tree Height Reduction such that the height of the operation tree is as low as possible, as in the addition operation at the end of the instruction sequence after the loop reduction shown in FIG. Is transformed into
[0074]
FIG. 8 shows a specific example of the algorithm of the function FUNC that returns the tuning value of the unrolling number described above.
FIG. 8 shows a process performed on the assumption that loop unrolling is expected. In FIG. 8, SP represents software pipelining, and ret represents a function value of FUNC (calculated unrolling number). MAX (A, B) is a function representing the maximum value of A and B, and MIN (A, B) is a function representing the minimum value of A and B.
[0075]
{Circle around (1)} First, as processing for a loop in which reduction is expected, if reduction is possible and UNROLL1 is equal to or greater than a threshold value 1, UNROLL1 is returned as a function value.
[0076]
{Circle over (2)} Next, as a process for a loop in which software pipelining is expected, if software pipelining is possible and UNROLL1 is equal to or greater than the above-described BASE, (UNROLL1−UNROLL1% BASE) is returned as a function value. .
[0077]
{Circle around (3)} As a process for a loop for which renaming is expected, if renaming is possible, UNROLL1 is returned as a function value.
{Circle around (4)} In cases other than the above, the processing is for a normal loop, and the following processing is performed.
[0078]
If UNROLL1 is greater than threshold value 2, return the smaller of UNROLL1 and UNROLL2 as a function value.
When UNROLL2 is equal to or smaller than the threshold value 2, the larger one of UNROLL1 and UNROLL2 is returned as a function value.
[0079]
In other cases, UNROLL1 is returned as a function value.
The following operations and effects are obtained by the above processing. For example, assume a case in which the loop reduction according to the present invention is further added to the conventional loop optimization.
[0080]
1. When the number of operations and variables used in the loop are large and the loop can be unrolled, and a pattern that can be reduced in the loop appears in the loop, the variable used in the loop is renamed and changed to another variable. If this happens, the number of variables used in the loop will increase further, and spill may be generated in the register allocation process. According to the present invention, since the number of registers to be used can be appropriately estimated in advance by predicting loop optimization, generation of a spill or the like can be avoided.
[0081]
2. In the context of 1 above, each is a meaningful optimization, but if they operate at the same time, the performance will be degraded.・ If unrolling and loop reduction are performed at the same time, a spill may be generated. Therefore, if it is necessary to control the loop reduction and perform some control such as performing only loop unrolling, Appropriate control becomes possible. In addition, for example, when loop reduction and software pipelining are expected to be executed at the same time, the performance may be degraded if they are operated at the same time. Therefore, control that prioritizes loop reduction with higher parallelization effect is also possible. become.
[0082]
3. For example, in a loop where loop unrolling and loop reduction can be performed, it is possible to perform control such as limiting the number of unrolling when operating simultaneously.
[0083]
4. Until now, the determination of the number of unrolling has been limited in generating an optimum code because the analysis of the dependency of variables in the loop before various optimizations were performed. On the other hand, anticipate the optimization that can be performed from the dependencies of the variables in the loop, and then grasp the dependencies of the variables used in the loop after the optimization has been performed and estimate the number of registers used. This makes it possible to determine the unrolling number.
[0084]
5. For example, if a high optimization level is required, acquire as much information as possible to prioritize load module execution time over translation time, and if a low optimization level is required, prioritize translation time. Therefore, it is possible to acquire only information that does not take much time to acquire.
[0085]
By realizing the above items, the compiler itself can grasp which optimization method and how to generate a code with a high parallel effect for an arbitrary program and arbitrary hardware.
[0086]
In the loop reduction according to the present invention, a variable Q having no dependency on other operations appears in a loop in the form of Q = Q + α (α is not a constant), and unrolling is performed. This is a loop deformation method that is performed when the method is applied, and its parallelization effect is extremely high.
[0087]
【The invention's effect】
As described above, in the past, optimizations did not interfere with each other, so that when a plurality of optimizations operate simultaneously, the effect may be counterproductive. However, according to the present invention, each optimization is performed in a loop. The number of registers in the loop can be estimated by analyzing the structure and taking into account the optimization, and the effects of the optimization can be maximized because the predicted optimizations interfere with each other. , Various optimizations can be performed / suppressed so that a code more optimal for a loop can be generated. Further, by improving the coordination among the option information analysis unit, the hardware information analysis unit, the program analysis unit, and the loop optimization control determination unit, it becomes possible to generate more optimal code with any machine and any program.
[0088]
The effect of the loop reduction itself is great, and the parallelism of the operation in the loop when the loop reduction is performed is increased, so that the execution performance is greatly improved.
[Brief description of the drawings]
FIG. 1 is a diagram illustrating the principle of the present invention.
FIG. 2 is an explanatory diagram of an example of a loop reduction according to the present invention.
FIG. 3 is a processing flowchart of a loop optimizing unit according to the embodiment of the present invention.
FIG. 4 is a diagram showing an example of optimization according to an embodiment of the present invention.
FIG. 5 is an explanatory diagram of an operation example of a loop optimization unit according to the embodiment of the present invention.
FIG. 6 is a diagram showing an example of a table used in the embodiment of the present invention.
FIG. 7 is a diagram showing an example of a table used in the embodiment of the present invention.
FIG. 8 is an explanatory diagram of a process of a function FUNC for returning a tuning value of an unrolling number in the embodiment of the present invention.
FIG. 9 is an explanatory diagram of an example of optimization by conventional loop unrolling.
FIG. 10 is an explanatory diagram of an example of optimization by conventional renaming.
FIG. 11 is an explanatory diagram of an example of optimization by conventional software pipelining.
FIG. 12 is an explanatory diagram of an example of optimization by conventional software pipelining.
[Explanation of symbols]
10 Processing equipment
11 Compiler
12 Front end part
13 Program Structure Analysis Department
14 Loop optimization section
15 Register allocator
16 Instruction scheduling unit
17 Code generator
20 Loop optimization control unit
21 Option information analysis unit
22 Hardware information analysis unit
23 Program Analyzer
24 Loop optimization control decision unit
30 Loop deformation part

Claims (6)

ソースプログラムを解析し,最適化処理,レジスタ割り付け処理,命令スケジューリング,コード出力によってオブジェクトプログラムを出力するコンパイラ装置において,
プログラムおよびハードウェアの特性を解析し,組み合わせて実施することができない最適化,あるいは,組み合わせて実施するためには制限を加える必要のある最適化を認識し,複数の最適化に対するループ最適化を統括的に制御するループ最適化制御部と,
このループ最適化制御部の情報をもとに,個々のループ最適化を実施するループ変形部とを備え
前記ループ最適化制御部は,前記プログラムおよびハードウェアの特性を解析する場合に,各演算の実行時間の重み付きでカウントされたループ内演算数,ループを変形する最適化の実施予想,およびその予想された最適化を施した後のループ内で使用されるレジスタ数をループに対してローカルに必要な変数とグローバルに必要な変数とに分けて見積ったレジスタの見積り数をプログラム解析情報として,指定されたオプティマイズレベルに依存してプログラム解析レベルを変動させる
ことを特徴とするコンパイラ装置。
In a compiler that analyzes a source program and outputs an object program through optimization processing, register allocation processing, instruction scheduling, and code output,
Analyzes the characteristics of programs and hardware and recognizes optimizations that cannot be performed in combination or optimizations that need to be restricted to perform in combination, and performs loop optimization for multiple optimizations. A loop optimization control unit that performs overall control,
A loop transformation unit that performs individual loop optimization based on the information of the loop optimization control unit ;
When analyzing the characteristics of the program and the hardware, the loop optimization control unit calculates the number of operations in the loop counted with a weight of the execution time of each operation, the anticipated execution of the optimization for deforming the loop, and the The number of registers used in the loop after the expected optimization is divided into variables required locally for the loop and variables required globally, and the estimated number of registers is estimated as program analysis information. A compiler device for varying a program analysis level depending on a specified optimization level .
ソースプログラムを解析し,最適化処理,レジスタ割り付け処理,命令スケジューリング,コード出力によってオブジェクトプログラムを出力するコンパイラ装置におけるループ最適化制御方法において,
プログラムおよびハードウェアの特性を解析する過程と,
解析結果に基づいて,組み合わせて実施することができない最適化あるいは組み合わせて実施するためには制限を加える必要のある最適化を認識することにより,複数の最適化についてそれぞれ実施するかしないかを決定する過程と,
複数の最適化を実施することを決定した場合には,その実施条件および最適化の実施順序を決定する過程と,
実施する最適化について決定された実施順序および実施条件に従ってループ最適化を行う過程とを有し,
前記プログラムおよびハードウェアの特性を解析する過程では,各演算の実行時間の重み付きでカウントされたループ内演算数,ループを変形する最適化の実施予想,およびその予想された最適化を施した後のループ内で使用されるレジスタ数をループに対してローカルに必要な変数とグローバルに必要な変数とに分けて見積ったレジスタの見積り数をプログラム解析情報として,指定されたオプティマイズレベルに依存してプログラム解析レベルを変動させる
ことを特徴とするループ最適化制御方法。
In a loop optimization control method in a compiler device that analyzes a source program and outputs an object program through optimization processing, register allocation processing, instruction scheduling, and code output,
The process of analyzing the characteristics of programs and hardware;
Based on the analysis results, determine whether or not to perform each of multiple optimizations by recognizing the optimizations that cannot be performed in combination or the optimizations that need to be restricted to perform in combination The process of
If it is determined that a plurality of optimizations are to be performed, the process of determining the conditions for performing the optimizations and the order in which the optimizations are performed;
The loop optimization possess a process performed according to optimize execution sequence and execution conditions are determined for implementing,
In the process of analyzing the characteristics of the program and the hardware, the number of operations in the loop counted with the execution time of each operation weighted, the execution of optimization for deforming the loop, and the predicted optimization were performed. The number of registers used in the subsequent loop is divided into variables required locally for the loop and variables required globally, and the estimated number of registers depends on the specified optimization level as program analysis information. A loop analysis control method for varying a program analysis level .
請求項記載のループ最適化制御方法において,
ループ内で使用される変数の依存関係を解析し,その情報から,実際にループ変形を行う時と同じ条件で,各最適化が実施可能であるかどうかを判定する
ことを特徴とするループ最適化制御方法。
The loop optimization control method according to claim 2 ,
Loop optimization characterized by analyzing the dependencies of variables used in a loop and determining from the information whether or not each optimization can be performed under the same conditions as when actually performing the loop deformation. Control method.
請求項記載のループ最適化制御方法において,
最適化予想結果を加味して,ループ変形後におけるループ内で使用されるレジスタ数を見積もり,
そのレジスタ数から算出したアンローリング数と,ループ内の各演算の実行時間の重みを加味した総演算数から算出したアンローリング数と,最適化の予想とに基づいてアンローリング数を決定する
ことを特徴とするループ最適化制御方法。
The loop optimization control method according to claim 3 ,
Estimating the number of registers used in the loop after loop deformation, taking into account the optimization prediction results,
Determining the unrolling number based on the unrolling number calculated from the number of registers, the unrolling number calculated from the total number of operations taking into account the execution time weight of each operation in the loop, and the prediction of optimization And a loop optimization control method.
請求項記載のループ最適化制御方法において,
ソフトウェア・パイプライニングが予想された時のアンローリング数がターゲットであるマシンの浮動小数点型の除算を除く四則演算中の最大実行時間の倍数であること,かつ,前記算出された見積りレジスタ数を考慮したアンローリング数以下であることを満足するアンローリング数にする
ことを特徴とするループ最適化制御方法。
The loop optimization control method according to claim 4 ,
Consider that the unrolling number when software pipelining is expected is a multiple of the maximum execution time during the four arithmetic operations excluding floating-point division on the target machine, and the number of estimated registers calculated above is taken into account. A loop optimization control method characterized in that the unrolling number satisfies a value equal to or less than the set unrolling number.
請求項2記載のループ最適化制御方法において,
前記複数の最適化に,
ループ・アンローリングによるループ変形と,
ループ内の他の演算に定義も参照も現れない変数が定義オペランドと参照オペランドに現れる演算のアンローリングに対して,その定義オペランドと参照オペランドの変数名を新しい変数名に置き換え,ループ外でその補正処理を施すことによりループ内の演算の並列度を高めるループ変形とが含まれる
ことを特徴とするループ最適化制御方法。
The loop optimization control method according to claim 2,
For the multiple optimizations,
Loop deformation due to loop unrolling,
For unrolling operations where a variable that does not appear in the definition or reference in other operations in the loop appears in the definition operand and the reference operand, the variable names of the definition operand and the reference operand are replaced with new variable names, and the A loop optimization control method characterized by including a loop modification for increasing the degree of parallelism of operations in a loop by performing a correction process.
JP23667094A 1994-09-30 1994-09-30 Compiler device and loop optimization control method Expired - Fee Related JP3544397B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP23667094A JP3544397B2 (en) 1994-09-30 1994-09-30 Compiler device and loop optimization control method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP23667094A JP3544397B2 (en) 1994-09-30 1994-09-30 Compiler device and loop optimization control method

Publications (2)

Publication Number Publication Date
JPH08101776A JPH08101776A (en) 1996-04-16
JP3544397B2 true JP3544397B2 (en) 2004-07-21

Family

ID=17004049

Family Applications (1)

Application Number Title Priority Date Filing Date
JP23667094A Expired - Fee Related JP3544397B2 (en) 1994-09-30 1994-09-30 Compiler device and loop optimization control method

Country Status (1)

Country Link
JP (1) JP3544397B2 (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP3847672B2 (en) 2002-07-03 2006-11-22 松下電器産業株式会社 Compiler apparatus and compiling method
JP4879589B2 (en) * 2006-01-20 2012-02-22 パナソニック株式会社 Compiler device
JP6245031B2 (en) * 2014-03-27 2017-12-13 富士通株式会社 Compilation program, compilation method, and compilation apparatus
JP2022140995A (en) 2021-03-15 2022-09-29 富士通株式会社 Information processing device, compile program, and compile method

Also Published As

Publication number Publication date
JPH08101776A (en) 1996-04-16

Similar Documents

Publication Publication Date Title
US7448031B2 (en) Methods and apparatus to compile a software program to manage parallel μcaches
Ryoo et al. Program optimization space pruning for a multithreaded GPU
US5491823A (en) Loop scheduler
US5797013A (en) Intelligent loop unrolling
Rau Iterative modulo scheduling
Rau Iterative modulo scheduling: An algorithm for software pipelining loops
JP3311462B2 (en) Compile processing unit
US5734908A (en) System and method for optimizing a source code representation as a function of resource utilization
EP1115059A2 (en) Method for collapsing the prolog and epilog of software pipelined loops
EP0991997A4 (en) Method for compiling high level programming languages
US20080244549A1 (en) Method and apparatus for exploiting thread-level parallelism
US6892380B2 (en) Method for software pipelining of irregular conditional control loops
WO2000063775A1 (en) Dynamic code motion optimization and path tracing
US5524242A (en) System and method for determining the number of parallel processes to be created according to run cost value and parallelization overhead
Rabbah et al. Compiler orchestrated prefetching via speculation and predication
Rocha et al. Vectorization-aware loop unrolling with seed forwarding
Thoman et al. Adaptive granularity control in task parallel programs using multiversioning
Sioutas et al. Programming tensor cores from an image processing DSL
JP3544397B2 (en) Compiler device and loop optimization control method
Marcuello et al. Thread partitioning and value prediction for exploiting speculative thread-level parallelism
Carter et al. Path analysis and renaming for predicated instruction scheduling
Koseki et al. A method for estimating optimal unrolling times for nested loops
Barua et al. Cost-driven thread coarsening for GPU kernels
August Hyperblock performance optimizations for ILP processors
Gupta code Optimization as a side effect of instruction scheduling

Legal Events

Date Code Title Description
A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20031224

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20040210

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: 20040330

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20040402

R150 Certificate of patent or registration of utility model

Free format text: JAPANESE INTERMEDIATE CODE: R150

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

Free format text: PAYMENT UNTIL: 20080416

Year of fee payment: 4

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

Free format text: PAYMENT UNTIL: 20090416

Year of fee payment: 5

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

Free format text: PAYMENT UNTIL: 20090416

Year of fee payment: 5

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

Free format text: PAYMENT UNTIL: 20100416

Year of fee payment: 6

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

Free format text: PAYMENT UNTIL: 20110416

Year of fee payment: 7

LAPS Cancellation because of no payment of annual fees