JP3598090B2 - Compiler device and compiling method - Google Patents

Compiler device and compiling method Download PDF

Info

Publication number
JP3598090B2
JP3598090B2 JP2001349185A JP2001349185A JP3598090B2 JP 3598090 B2 JP3598090 B2 JP 3598090B2 JP 2001349185 A JP2001349185 A JP 2001349185A JP 2001349185 A JP2001349185 A JP 2001349185A JP 3598090 B2 JP3598090 B2 JP 3598090B2
Authority
JP
Japan
Prior art keywords
array operation
expression
variable
value
range
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
JP2001349185A
Other languages
Japanese (ja)
Other versions
JP2003150386A (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.)
Panasonic Corp
Panasonic Holdings Corp
Original Assignee
Panasonic Corp
Matsushita Electric Industrial Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Panasonic Corp, Matsushita Electric Industrial Co Ltd filed Critical Panasonic Corp
Priority to JP2001349185A priority Critical patent/JP3598090B2/en
Publication of JP2003150386A publication Critical patent/JP2003150386A/en
Application granted granted Critical
Publication of JP3598090B2 publication Critical patent/JP3598090B2/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】
【従来の技術】
図8は、従来のベクトル化コンパイラ装置を示す概略構成図である。図8に示すように、従来のベクトル化コンパイラ装置は、構文解析部61、ベクトル化部63、最適化部65、コード生成部67とで構成されている。ベクトル化コンパイラ装置は、最初にソースプログラム60を入力として受け取る。
【0003】
ソースプログラム60は構文解析部61に渡され、構文解析が行なわれる。その結果、ソースプログラム60の原始言語とオブジェクトコード68の目的言語との橋渡しをする中間コード62が生成される。
【0004】
中間コード62は、後のベクトル化や最適化を実行しやすくするために生成されている。次に、中間コード62はベクトル化部63に渡され、中間コード62のベクトル化判定及びベクトル化の実行が行なわれる。これによって、ベクトル化が可能な中間コード62はベクトル化されているベクトル化中間コード64に変換される。
【0005】
ベクトル化中間コード64は最適化部65に渡され、ある種の最適化が施されて最適化中間コード66が生成される。最適化中間コード66はコード生成部67に渡され、オブジェクトコード68がベクトル化コンパイラ装置より出力される。
【0006】
図9は、図8に示した従来のベクトル化コンパイラ装置における構文解析部を示す構成図である。図9に示すように、構文解析部61は、構文認識部70、シンボルテーブル登録部71、配列演算部72、構文処理部(1〜n)73、エラー処理部74、及び中間コード生成部75で構成されている。
【0007】
構文認識部70は、読み込んだソースプログラム60が、プログラム言語のどの構文に該当するかを認識する。シンボルテーブル登録部71はシンボルテーブルと呼ばれるデータベースを備えており、構文認識部70でプログラムの解析対象が変数宣言や定義であると判定された場合に呼び出され、少なくとも変数の名前(シンボル名)やその変数のデータ型の情報(シンボル情報)をシンボルテーブルに登録する。
【0008】
配列演算部72は、構文認識部70でプログラムの解析対象が配列の演算であると判定された場合に呼び出され、少なくともプログラムに記述されている配列演算の種類やオペランドのデータ型、オペランドの値を解析してその情報を中間コード生成部75に渡す。
【0009】
構文処理部73は、配列演算部72と同列のもので、配列演算以外の構文が現れた場合に構文認識部70から呼び出され、その構文に対応する解析処理を行ない中間コード生成部75に詳細情報を渡す。なお、各構文に対応する解析処理については、本明細書において重要ではないので省略する。
【0010】
エラー処理部74は、構文認識部70で構文が認識できない場合に呼び出され、エラー処理を行なう。中間コード生成部75は、配列演算部72や構文処理部73から中間コード62を生成するために必要な情報を受け取り、その情報に対応する中間コード62を生成する。
【0011】
図10は、図9に示した従来のベクトル化コンパイラ装置を構成する構文解析部の処理を示す流れ図である。図10に示すように、最初に構文認識部70により、ソースプログラム60の読み込みが行なわれる。(ステップS200)。次に、構文認識部70により、読み込まれたソースプログラム60から文が抽出されて解析が行なわれ(ステップS201)、更にプログラム文の解析対象が変数宣言又は定義であるかの判定が行なわれる(ステップS202)。
【0012】
判定が真の場合、シンボルテーブル登録部71は変数名やデータ型をシンボルテーブルに登録する(ステップS210)。その後ステップS203に移行する。一方、判定が偽の場合は、そのままステップS203に移行する。
【0013】
ステップS203では、構文認識部70により、プログラム文の解析対象が配列演算であるかどうかの判定が行なわれる。配列演算の判定が真の場合、配列演算部72により演算の種類、演算のデータ型、値に関する情報が抽出される(ステップS220)。その後、中間コード生成部75により、抽出された情報をもとに中間コード62が生成され(ステップS240)、構文認識部70によりプログラムの終了判定が行なわれる(ステップS206)。解析中のソースプログラム60のうち、配列演算に対する中間コード62は、この一連の処理(ステップS220及びS240)により生成される。
【0014】
配列演算の判定が偽であれば、構文認識部70により、配列演算以外の他の構文であるかどうか、即ち構文処理部(1〜n)のうちのいずれかが対応する構文であるかどうかの判定が行なわれる(ステップS204)。
【0015】
真の場合は、対応する構文処理部により構文処理が行なわれ、中間コード62を生成するために必要な情報が抽出される(ステップS230)。その後、中間コード生成部75により、抽出された情報に基づいて中間コード62が生成される(ステップS240)。更に、構文認識部70によりプログラムの終了判定が行なわれる(ステップS206)。
【0016】
一方、判定が偽の場合は、構文認識部70により、構文エラー処理が実行される(ステップS205)。その後、構文認識部70により、プログラムの終了判定が行なわれる(ステップS206)。
【0017】
なお、ステップS206におけるプログラムの終了判定では、構文認識部70により、解析中のソースプログラム60が終了したかどうかが判定される。真の場合は、ベクトル化部63に処理が移される。偽の場合は、ステップS201に戻り、残りのソースプログラム60の解析が続行される。
【0018】
以上のような処理によって、図8及び図9で示した構文解析部61は、中間コード62を生成する。生成された中間コード62の特徴として、配列演算に対する中間コード62は、ソースプログラム60の中で宣言された配列のデータ型で生成されていることが挙げられる。
【0019】
図11は、具体的なソースプログラムの一例、従来のベクトル化コンパイラ装置を使用した場合のシンボルテーブルの一例、及び中間コードの一例を示す図である。なお、以下の説明においては、適宜図10を引用して説明する。
【0020】
図11に示すように、入力されたソースプログラム60の各文((1)〜(12))に対して構文解析が行なわれる。先ず、(1)の文は引数なしでchar型を返す関数gの宣言であるので、ステップS210(図10)において、シンボル名(変数名)とそのデータ型がシンボルテーブル69に登録される。
【0021】
また、(1)の文は配列演算に該当せず、構文処理としては変数宣言の分類にあたるので、ステップS204(図10)の判定が真となる。よって、ステップS230(図10)に移り、ここで変数宣言に対する構文解析処理が行なわれ、ステップS240(図10)において変数宣言に対する中間コードが生成される。その後、ステップS206(図10)において、プログラムの終了判定が行なわれる。プログラムに続きがあるので、再度ステップS201(図10)に移り、処理が続行される。なお、ステップS204(図10)、ステップS230(図10)の処理は、配列演算に該当する(11)以外のすべてのプログラム文で行なわれるので、以降は説明を省略する。
【0022】
次に(2)の文は、配列変数a、b、cの宣言であるので、ステップS210(図10)においてシンボル名及びそのデータ型がシンボルテーブル69に登録される。(3)、(4)、(5)の各文はそれぞれ初期値を有する変数定義であるので、同様にステップS210においてシンボル名とそのデータ型がシンボルテーブル69に登録される。
【0023】
(6)の文では新しい変数iが定義されているので、これに対してもステップS210において、シンボル名とデータ型がシンボルテーブル69に登録される。(7)、(8)の文では、配列変数bとcに対する代入式なので、変数の定義とみなされ、ステップS210において変数名やデータ型を登録しようとするが、既に登録されているので、そのまま処理を終える。(10)の文では新しい変数jが定義されているので、これに対してもシンボル名とそのデータ型がシンボルテーブル69に登録される。
【0024】
次に、for構文の本体である(11)の文は配列演算であるので、ステップS220においてソースプログラム60やシンボルテーブル69から演算の種類、演算のデータ型及び値が抽出される。その後、ステップS240において、抽出された演算のデータ型で演算を行なう中間コード62が生成される。
【0025】
図11に示す例では、演算対象の配列要素bやcはint型であることがシンボルテーブル69よりわかる。これより、演算種類が+(加算)、演算データ型がint型、第1オペランドがb〔j〕、第2オペランドがc〔j〕である中間コード62が生成される。上記したように、従来のベクトル化コンパイラ装置で生成される配列演算に対する中間コード62は、ソースプログラム60の中で宣言されたデータ型(図11の例ではint型)で生成されていることがわかる。
【0026】
この中間コード62がベクトル化部63に渡され、中間コード62の演算とデータ型に該当するベクトル命令が存在すれば、その演算の並列度に対応するベクトル化中間コード64が生成される。図11の例では、2並列int型ベクトル加算演算が存在することを仮定しているので、並列度が2のint型加算演算(int〔2〕でintの2並列を表現)を表すベクトル化中間コード64が生成される。
【0027】
従って、ソースプログラム60に記述されているforループ内の配列演算a〔j〕=b〔j〕+c〔j〕は、a〔0〕=b〔0〕+c〔0〕とa〔1〕=b〔1〕+c〔1〕、a〔2〕=b〔2〕+c〔2〕とa〔3〕=b〔3〕+c〔3〕、a〔4〕=b〔4〕+c〔4〕とa〔5〕=b〔5〕+c〔5〕、a〔6〕=b〔6〕+c〔6〕とa〔7〕=b〔7〕+c〔7〕、a〔8〕=b〔8〕+c〔8〕とa〔9〕=b〔9〕+c〔9〕との組み合わせで並列に行なわれる。即ち、通常10回(j=0、1、・・・8、9)行なわれる配列演算は、5回(j=0、2、4、6、8)の並列配列演算で実行可能となる。
【0028】
以上のように、従来のベクトル化コンパイラ装置では、ソースプログラム60の中で演算対象について宣言されたデータ型で配列演算が実行されるように中間コード62が生成され、この中間コード62がベクトル化部63に渡される。よって、ベクトル化中間コード64もソースプログラム60の中で演算対象について宣言されたデータ型で配列演算が実行されるように生成される。
【0029】
【発明が解決しようとする課題】
ところで、一般的に、ベクトル化に対応する命令は、演算対象のデータ型のサイズが小さいほど、並列度が高まり高速に演算が実行できる。具体例を挙げると、アーキテクチャが持つレジスタのレジスタ長が64bitの場合、int型32bitの演算であれば、2(=64/32)並列の演算が可能であるのに対し、shortデータ型16bitの演算であれば、4(=64/16)並列、char型8bitの演算であれば、8(=64/8)並列の演算が可能である。このことから、配列演算のデータ型(演算対象について宣言されたデータ型)のサイズを小さくしてベクトル化を行なうことが理想である。
【0030】
しかし、上記した従来のベクトル化コンパイラ装置では、配列に格納される可能性のある値、即ち配列演算の演算値であるa〔j〕に格納される値の上限値及び下限値を解析することは行われていない。よって、演算値の取り得る数値範囲がプログラム中で宣言されたデータ型よりも小さいデータ型(扱うことができる数値範囲の狭いデータ型)の数値範囲に収まっている場合でも、より小さいデータ型でベクトル化は行われず、最初に演算対象について宣言されたデータ型でベクトル化の実行が行われる。そのため、上記した従来のベクトル化コンパイラ装置では、理想的なベクトル化、即ち、配列演算の演算値を扱うことのできる最小のデータ型でベクトル化を行なうことができず、演算の高速化が図れないという問題がある。
【0031】
本発明の目的は、配列演算の演算値の取り得る数値範囲を解析して、配列演算の演算値を扱うことのできる最小のデータ型でベクトル化を行ない得るコンパイラ装置及びコンパイル方法を提供することにある。
【0032】
【課題を解決するための手段】
上記目的を達成するために本発明にかかるコンパイラ装置は、配列演算を含むソースプログラムをコンパイルするコンパイラ装置であって、コンパイル処理における構文の解析の際に、前記配列演算に用いられる変数の取り得る数値範囲を解析し、前記配列演算に用いられる変数の取り得る数値範囲を用いて前記配列演算の演算値を格納する変数の取り得る数値範囲を解析する変数範囲解析部と、前記配列演算の演算値を格納する変数が取り得る数値範囲を扱うことができるデータ型の中から、扱うことができる数値範囲が最も狭いデータ型を検出し、前記扱うことができる数値範囲が最も狭いデータ型と前記配列演算を含むソースプログラムから抽出される前記配列演算のデータ型とが一致するかどうかを判定するデータ型判定部と、前記データ型判定部によって一致しないと判定された場合に、前記扱うことができる数値範囲が最も狭いデータ型で前記配列演算を行なう中間コードが生成されるように、前記配列演算のデータ型を変更するデータ型変更部とを少なくとも有することを特徴とする。
【0033】
上記本発明にかかるコンパイラ装置においては、前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数の上限値と下限値とが定義されている場合に、前記変数範囲解析部は、前記上限値と前記下限値とに基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析することができる。
【0034】
この場合、前記配列演算に用いられる変数がイテレータ変数であれば、前記配列演算に用いられる変数の上限値と下限値とは、前記イテレータ変数における初期値、終了条件及び増分値によって定義されている。
【0035】
上記本発明にかかるコンパイラ装置においては、前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数に定数値が代入されている場合に、前記変数範囲解析部は、前記定数値を、前記配列演算に用いられる変数の取り得る数値範囲とすることができる。
【0036】
また、上記本発明にかかるコンパイラ装置においては、前記配列演算に用いられる変数が代入式の左辺である場合に、前記変数範囲解析部は、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲を解析し、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲に基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析することができる。
【0037】
この態様においては、前記変数範囲解析部は、前記代入式が一次式であるか又は多次式であるかを判別し、多次式である場合は、前記代入式の極値を算出することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析することができる。一方、一次式である場合は、前記代入式の右辺に含まれる全ての変数の上限値及び下限値のみを前記代入式に代入することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析することができる。
【0038】
また、この態様においては、前記代入式の右辺に含まれる変数のうち少なくとも一つの変数において、上限値及び下限値の両方が定義されていない場合に、前記変数範囲解析部は、前記配列演算に用いられる変数において宣言されたデータ型が扱うことができる数値範囲を、前記上限値及び下限値の両方が定義されていない変数の取り得る数値範囲とすることができる。
【0039】
上記本発明にかかるコンパイラ装置においては、前記変数範囲解析部は、前記配列演算の式が一次式であるか又は多次式であるかを判別し、多次式である場合に、前記配列演算の極値を算出することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析することができる。一方、一次式である場合に、前記配列演算の式の右辺に含まれる前記配列演算に用いられる変数の上限値及び下限値のみを前記配列演算の式に代入することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析することができる。
【0040】
次に、上記目的を達成するために本発明にかかるコンパイル方法は、配列演算を含むソースプログラムをコンパイルする方法であって、(a)コンパイル処理における構文の解析の際に、前記配列演算に用いられる変数の取り得る数値範囲を解析し、前記配列演算に用いられる変数の取り得る数値範囲を用いて前記配列演算の演算値を格納する変数の取り得る数値範囲を解析する工程と、(b)前記配列演算の演算値を格納する変数が取り得る数値範囲を扱うことができるデータ型の中から、扱うことができる数値範囲が最も狭いデータ型を検出し、前記扱うことができる数値範囲が最も狭いデータ型と前記配列演算を含むソースプログラムから抽出される前記配列演算のデータ型とが一致するかどうかを判定する工程と、(c)一致しないと判定した場合に、前記扱うことができる数値範囲が最も狭いデータ型で前記配列演算を行なう中間コードが生成されるように、前記配列演算のデータ型を変更する工程とを少なくとも有することを特徴とする。
【0041】
上記本発明にかかるコンパイル方法においては、前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数の上限値と下限値とが定義されている場合に、前記上限値と前記下限値とに基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析することができる。
【0042】
この場合、前記配列演算に用いられる変数がイテレータ変数であれば、前記配列演算に用いられる変数の上限値と下限値とが、前記イテレータ変数における初期値、終了条件及び増分値によって定義されている。
【0043】
上記本発明にかかるコンパイル方法においては、前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数に定数値が代入されている場合に、前記定数値を、前記配列演算に用いられる変数の取り得る数値範囲とすることができる。
【0044】
また、上記本発明にかかるコンパイル方法においては、前記配列演算に用いられる変数が代入式の左辺である場合に、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲を解析し、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲に基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析することができる。
【0045】
この態様においては、前記代入式が一次式であるか又は多次式であるかを判別し、多次式である場合に、前記代入式の極値を算出することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析することができる。一方、一次式である場合に、前記代入式の右辺に含まれる全ての変数の上限値及び下限値のみを前記代入式に代入することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析することができる。
【0046】
また、この態様においては、前記代入式の右辺に含まれる変数のうち少なくとも一つの変数において、上限値及び下限値の両方が定義されていない場合に、前記配列演算に用いられる変数において宣言されたデータ型が扱うことができる数値範囲を、前記上限値及び下限値の両方が定義されていない変数の取り得る数値範囲とすることができる。
【0047】
上記本発明にかかるコンパイル方法においては、前記配列演算の式が一次式であるか又は多次式であるかを判別し、多次式である場合に、前記配列演算の極値を算出することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析することができる。一方、一次式である場合に、前記配列演算の式の右辺に含まれる前記配列演算に用いられる変数の上限値及び下限値のみを前記配列演算の式に代入することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析することができる。
【0048】
本発明は、上記の本発明にかかるコンパイル方法を具現化するためのプログラムであっても良い。この場合、かかるプログラムをコンピュータにインストールして実行することにより、上記の本発明にかかるコンパイラ装置を実現することができる。なお、本発明でいう「配列演算」とはベクトル化の対象となる配列演算をいう。
【0049】
【発明の実施の形態】
(実施の形態1)
以下、本発明の実施の形態にかかるコンパイラ装置及びコンパイル方法について、図1〜図5を参照しながら説明する。最初に、図1に基づいて本実施の形態にかかるコンパイラ装置について説明する。図1は、本実施の形態にかかるコンパイラ装置の構成を示す概略構成図である。
【0050】
図1に示すように本実施の形態にかかるコンパイラ装置は、図8に示した従来のコンパイラ装置と同様に、ソースプログラム20の構文解析を行なって中間コード5を生成する構文解析部1と、中間コード5をベクトル化中間コード6に変換するベクトル化部2、ベクトル化中間コード6を最適化中間コード7に変換する最適化部3、及び最適化中間コード7からオブジェクトコード21を生成するコード生成部4で構成されている。
【0051】
しかし、本実施の形態にかかるコンパイラ装置では、構文解析部1の構成や機能が図8で示した従来のコンパイラ装置と異なっている。なお、ベクトル化部2、最適化部3及びコード生成部4は、図8に示されたものと構成及び機能において同じである。本実施の形態にかかるコンパイラ装置における構文解析部1について以下に説明する。
【0052】
図1に示すように、構文解析部1は、構文認識部10、シンボルテーブル登録部11、配列演算部12、構文処理部(1〜n)13、エラー処理部14、中間コード生成部15、変数範囲解析部16、データ型判定部17及びデータ型変更部18で構成されている。このうち、構文認識部10、シンボルテーブル登録部11、配列演算部12、構文処理部(1〜n)13、エラー処理部14及び中間コード生成部15は、図9で示したものと同様のものである。本実施の形態にかかるコンパイラ装置は、変数範囲解析部16、データ型判定部17及びデータ型変更部18が備えられている点で、従来のコンパイラ装置と異なっている。
【0053】
変数範囲解析部16は、ソースプログラム20のコンパイル処理における構文解析の際に、ソースプログラム20中で用いられている変数の取り得る数値範囲(上限値及び下限値)を解析する機能を有している。なお、変数範囲解析部16は、変数が配列演算の演算値を格納する変数である場合は、配列演算に用いられる変数について解析した数値範囲に基づいて解析を行なう。
【0054】
データ型判定部17は、配列演算の演算値を格納する変数が取り得る数値範囲を扱うことができるデータ型の中から扱うことができる数値範囲が最も狭いデータ型を検出し、この扱うことができる数値範囲が最も狭いデータ型と配列演算のデータ型とが一致するかどうかを判定する機能を有している。なお、判定対象となる配列演算のデータ型は、ソースプログラム20中で宣言されたデータ型であり、ソースプログラム20から抽出される。
【0055】
また、データ型変更部18は、データ型が一致しない場合に、扱うことができる数値範囲最も狭いデータ型で配列演算を行なう中間コードが生成されるように、配列演算のデータ型を変更する機能を有している。
【0056】
次に、図2を用いて、図1に示すコンパイラ装置における処理及び本実施の形態にかかるコンパイル方法について説明する。図2は、図1に示すコンパイラ装置における処理の流れ及び本実施の形態にかかるコンパイル方法を示す流れ図である。なお、図2では構文解析部1における処理の流れのみが示されており、ベクトル化部2、最適化部3及びコード生成部4における処理の流れについては省略している。ベクトル化部2、最適化部3及びコード生成部4においては、従来と同様の処理が行われる。また、図1を適宜参酌しながら説明する。
【0057】
図2に示すように、最初に構文認識部10(図1参照)により、ソースプログラム20の読み込みを行ない(S1)、更にソースプログラム20から一つのプログラム文を抽出して解析を行なう(S2)。ソースプログラム20には配列演算が含まれている。
【0058】
次に、構文認識部10により、抽出されたプログラム文が変数宣言又は定義であるかどうかの判定を行なう(S3)。変数宣言や定義でない場合は、ステップS4へと移行する。
【0059】
一方、変数宣言又は変数の定義である場合は、シンボルテーブル登録部11により、変数の名前や宣言されたデータ型といった情報をシンボルテーブルに登録する(S10)。更に、この場合は、変数範囲解析部16により、シンボルテーブルに登録された情報から、抽出されたプログラム文が変数の定義であるかどうかの判断を行なう(ステップS11)。
【0060】
判断の結果、定義でない場合は、ステップS4へと移行する。変数の定義である場合は、変数範囲解析部16により、変数が取り得る数値範囲の解析を行ない、解析された数値範囲をシンボルテーブルに登録する(ステップS12)。この数値範囲の解析は、ソースプログラム20中になされた変数の定義に基づいて、変数に格納される可能性のある値の上限値及び下限値を、数学的手段を用いて算出することによって行なう。
【0061】
なお、取り得る数値範囲の解析は、解析対象となる変数が、配列演算の演算値を格納するものであるのか、又は配列演算に用いられるものであるのかに拘わらず行なう。変数が配列演算の演算値を格納する変数である場合は、配列演算に用いられる変数について解析した数値範囲に基づいて解析を行なう。なお、ステップS12の具体的な内容については、後述の図3において説明する。その後ステップS4へと移行する。
【0062】
ステップS4では、配列演算部12により、プログラム文の解析対象が配列演算であるかどうかの判定を行なう。配列演算である場合は、配列演算部12により、演算の種類、演算対象オペランドのシンボルを抽出し、シンボルテーブルから、抽出したシンボルのデータ型(配列演算のデータ型)、値(演算値を格納する変数が取り得る数値範囲)に関する情報を抽出し、これらの情報をシンボルテーブルに登録する(ステップS20)。更に、データ型判定部17により、ステップS12で解析した演算値を格納する変数が取り得る数値範囲に基づいて、この数値範囲を扱うことができるデータ型の中から、扱うことができる数値範囲が最も狭いデータ型を検出し、この扱うことができる数値範囲が最も狭いデータ型とステップS20で抽出した配列演算のデータ型とが一致するかどうかを判定する(ステップS21)。
【0063】
扱うことができる数値範囲が最も狭いデータ型とステップS20で抽出した配列演算のデータ型とが一致する場合は、ステップS40へと移行する。一方、一致しない場合は、データ型変更部18により、扱うことができる数値範囲が最も狭いデータ型で配列演算を行なう中間コードが生成されるように、配列演算のデータ型を変更する(ステップS22)。その後、ステップS40へと移行する。なお、ステップS21及びS22の具体的な内容については、後述の図4において説明する。
【0064】
ステップS40では、配列演算部12で抽出された情報及びデータ型変更部18によって変更された情報に基づき、中間コード生成部15により、中間コード5を生成する。中間コードの生成後、ステップS7へと移行する。解析中のプログラムのうち、配列演算に対する中間コード5はこの一連の処理(ステップS20〜S22及びS40)により生成される。
【0065】
ステップS4における判定において、配列演算でないと判定した場合は、構文認識部10により、配列演算以外の他の構文であるかどうか、即ち構文処理部(1〜n)13のうちのいずれかが対応する構文であるかどうかの判定を行なう(ステップS5)。配列演算以外の他の構文である場合は、対応する構文処理部13により、構文処理を行なって配列演算以外のプログラム文に対する中間コード5を生成するために必要な情報を抽出する(ステップS30)。
【0066】
更に、ステップS30で抽出された情報に基づいて、中間コード生成部15により、中間コードを生成する(ステップS40)。この後、ステップS7へと移行する。
【0067】
一方、配列演算以外の他の構文でない場合は、構文認識部10により、構文エラー処理を実行する(ステップS6)。その後、ステップS7へと移行する。
【0068】
ステップS7では、構文認識部10により、解析中のソースプログラム20が終了したかどうかを判定する。終了した場合は、ベクトル化部に処理を移す。終了していない場合は、ステップS2へと戻り、残りのプログラム文の解析を続行する。
【0069】
次に、図2で示したステップS12について図3を用いて具体的に説明する。図3は、変数範囲解析部による処理を具体的に示す流れ図である。図3に示すステップS100〜S108が図2に示すステップS12に相当する。
【0070】
図3に示すように、最初に、変数範囲解析部16は、シンボルテーブルに登録された情報に基づいて、解析対象の変数がループのイテレータ変数であるかどうかの判定を行なう(ステップS100)。イテレータ変数の場合は、ソースプログラム20に定義されている初期値、終了条件、増分値を抽出し、これらの情報を基にこのイテレータ変数の取り得る数値範囲(上限値及び下限値)を算出し、算出された数値範囲をシンボルテーブルに登録する(ステップS101)。
【0071】
イテレータ変数でない場合は、変数範囲解析部16は、解析対象の変数に定数値が代入されているかどうかの判定を行なう(ステップS102)。定数値が代入されている場合は、この定数値を解析対象の変数の取り得る数値範囲とし、この定数値をシンボルテーブルに登録する(ステップS103)。定数値が代入されていない場合はステップS104に移行する。
【0072】
解析対象の変数がイテレータ変数でなく、又定数値が代入された変数でもない場合は、代入式の左辺であるか、配列演算の演算値を格納する変数であるかのどちらかと考えられる。よって、ステップS104では、変数範囲解析部16は、代入式又は配列演算の演算式の右辺に含まれる全ての変数の取り得る数値範囲を解析する。具体的には変数範囲解析部16は、各変数について、シンボルテーブルから上限値及び下限値を抽出する。
【0073】
但し、代入式又は配列演算の演算式の右辺に含まれる変数のうち少なくとも一つの変数について、上限値及び下限値の両方がシンボルテーブルに登録されていない場合は、シンボルテーブルからの数値範囲の抽出が行なえないため、変数範囲解析部16は、上限値及び下限値の両方がシンボルテーブルに登録されていない変数が、代入式又は配列演算の演算式の右辺に含まれているかどうかを判定する(ステップS105)。
【0074】
判定の結果、上記の変数が含まれていない場合は、ステップS107に移行する。上記の変数が含まれている場合は、解析対象の変数において宣言されたデータ型が扱うことができる数値範囲を抽出する(ステップS106)。その後、ステップS107に移行する。
【0075】
ステップS107では、変数範囲解析部16は、代入式又は配列演算の演算式の右辺に含まれる全ての変数の取り得る数値範囲に基づいて、解析対象の変数の取り得る数値範囲を解析する。なお、ステップS106で解析対象の変数において宣言されたデータ型が扱うことができる数値範囲を抽出した場合は、この抽出した数値範囲を、上限値及び下限値の両方がシンボルテーブルに登録されていない変数の取り得る数値範囲として、解析対象の変数の取り得る数値範囲を解析する。
【0076】
具体的には、変数範囲解析部16は、代入式又は配列演算の演算式の右辺に含まれる全ての変数の上限値と下限値との間に存する全数値に対する代入式又は配列演算の演算式の計算値を求めることによって、解析対象の変数の取り得る数値範囲を算出する。
【0077】
但し、本実施の形態においては、変数範囲解析部16は、代入式又は配列演算の演算式が一次式であるか又は多次式であるかを判別する機能を有している。そのため、代入式又は配列演算の演算式が一次式である場合は、各変数の上限値と下限値との間に存する全数値に対する代入式又は配列演算の演算式の計算値を求める必要はない。
【0078】
この場合は、代入式又は配列演算の演算式の右辺に含まれる全ての変数の上限値及び下限値のみを代入式又は配列演算の演算式に代入することで、解析対象の変数の取り得る数値範囲を算出できる。
【0079】
また、代入式又は配列演算の演算式が多次式である場合は、数学的な極値計算を行ない、これによって求められた極値を用いて、解析対象の変数の取り得る数値範囲を算出することもできる。
【0080】
その後、数値範囲解析部16は、算出された上限値及び下限値を、解析対象となる変数の数値範囲として、シンボルテーブルに登録する(ステップS108)。このように、ソースプログラム10に含まれる全ての変数について、上記したステップS100〜S108を行なうことにより、最終的に配列演算の演算値を格納する変数の取り得る数値範囲を解析することができる。
【0081】
次に、図2で示したステップS21及びS22について図4を用いて具体的に説明する。図4は、データ型判定部及びデータ型変更部による処理を具体的に示す流れ図である。図4に示すステップS110は図2に示すステップS20に相当し、図4に示すS111〜S112は図2に示すステップS21に相当し、図4に示すステップS113は図2に示すステップS22に相当する。
【0082】
図4に示すように、最初に、データ型判定部17はシンボルテーブルから配列演算に使用されるデータ型と、図3に示したステップS100〜S108によって解析された配列演算の演算値を格納する変数の取り得る数値範囲(上限値及び下限値)を抽出する(ステップS110)。
【0083】
次に、データ型判定部17は、データ型情報(コンパイラ装置が通常有しており、アーキテクチャの機種に依存する情報)と配列演算の演算値を格納する変数の取り得る数値範囲とを対比して、この数値範囲を扱うことができるデータ型であって、扱うことができる数値範囲が最も狭いものを検出する。次いで、データ型判定部17は、ステップS110で抽出した配列演算に使用されるデータ型と、上記の検出したデータ型とが一致するかどうかを判定する(ステップS111)。
【0084】
判定の結果、一致する場合は、データ型判定部17は、シンボルテーブルから抽出した配列演算に使用されるデータ型を演算情報として中間コード生成部15に渡す(ステップS112)。よって、中間コード生成部15は、シンボルテーブルから抽出した配列演算に使用されるデータ型で配列演算が行なわれるように中間コードを生成する。
【0085】
一方、判定の結果、一致しない場合は、データ型判定部17は、データ型変更部18によって、配列演算に使用されるデータ型を上記の扱うことができる数値範囲が最も狭いデータ型に変更する。即ち、データ型判定部17は、シンボルテーブルから抽出した配列演算に使用されるデータ型の代わりに、上記の扱うことができる数値範囲が最も狭いデータ型を演算情報として中間コード生成部15に渡す(ステップS113)。よって、中間コード生成部15は、上記の扱うことができる数値範囲が最も狭いデータ型で配列演算が行なわれるように中間コードを生成する。
【0086】
以上のようにして、図1及び図2に示す中間コード5が生成される。よって、本実施の形態では、最も小さいデータ型で配列演算を行なう中間コードを生成することができ、従来に比べて並列度を上げて高速化を図ることが可能となる。
【0087】
次に、具体的なソースプログラム例に基づいて、本実施の形態にかかるコンパイラ装置及びコンパイル方法について説明する。図5は、ソースプログラム及びシンボルテーブルの一例を示す図である。なお、従来例との効果の比較を行なうため、図5に示すソースプログラム20は、図11で示したソースプログラム60と同じものである。図6は、コンパイラ装置が通常有しているデータ型情報を示す図である。図7は、図5に示すソースプログラムに基づいて生成された中間コード及びベクトル化中間コードを示す図である。
【0088】
図5に示すソースプログラム20中のプログラム文(1)〜(12)に対し、図2〜図4で示したように構文解析が行なわれて、中間コードが生成される。図5に示すソースプログラム20中において、変数aは配列演算の演算値を格納する変数であり、これ以外の変数b、c、d、e、f、j、jは配列演算に用いられる変数である。以下にプログラム文ごとに説明する。
【0089】
プログラム文(1)は、引数なしでchar型を返す関数gの宣言であるので、変数名とデータ型とがシンボルテーブルに登録される(図2/ステップS10)。但し、プログラム文(1)は定義ではないので、取り得る数値範囲の解析は行なわれない。また、プログラム文(1)は配列演算にも該当せず、構文処理としては変数宣言の分類にあたる。よって、変数宣言に対する構文解析処理が行なわれ(図2/ステップS5、S30)、変数宣言に対する中間コードが生成される(図2/ステップS40)。
【0090】
その後、プログラムの終了判定が行なわれるが(図2/ステップS7)、プログラムに続きがあるので、次のプログラム文(2)の処理が行われる(図2/ステップS2)。なお、変数宣言に対する構文解析処理(図2/ステップS5、S30)は、配列演算に該当するプログラム文(11)以外のすべてのプログラム文で行なわれる。このため、以下の説明においては省略している。
【0091】
プログラム文(2)は、配列変数a〔10〕、b〔10〕、c〔10〕の宣言である。よって、シンボル名とそのデータ型とがシンボルテーブルに登録される(図2/ステップS10)。プログラム文(2)も定義ではないため、取り得る数値範囲の解析は行なわれない。
【0092】
プログラム文(3)、(4)及び(5)は、それぞれ初期値を有する変数の定義である。よって、先ずシンボル名とそのデータ型とがシンボルテーブルに登録され(図2/ステップS10)、次に取り得る数値範囲の解析が行なわれる(図2/ステップS11及びS12)。
【0093】
ここでの数値範囲の解析について具体的に説明する。プログラム文(3)及び(4)では変数d及びeに‘100000’や‘1000’といった定数値が代入されている。よって、これらの定数値が変数d及びeの取り得る数値範囲(上限値及び下限値)としてシンボルテーブルに登録される(図3/ステップS100及びS101)。
【0094】
プログラム文(5)は変数fの代入式であり、代入式の右辺には関数gの呼び出し結果が代入される。よって、定数値が代入されていないので、シンボルテーブルから代入式の右辺に含まれる変数の上限値と下限値とが抽出される(図3/ステップS104)。ここで、シンボルテーブルにおける変数gの項目を見ると、上限値及び下限値の両方が登録されていないことがわかる。
【0095】
よって、変数fの取り得る数値範囲は、宣言時に指定されたデータ型、即ちchar型が取り得る数値範囲とされ、データ型情報から上限値及び下限値として‘127’と‘−128’とが抽出される(図3/ステップS105及びS106)。その後、変数gの上限値と下限値との間に存する全数値に対する代入式の計算値を求める(図3/ステップS107)。この場合は、関数gの返り値そのものが代入されるので、変数gの取り得る数値範囲が、変数fの取り得る数値範囲となる。よって、シンボルテーブルには、変数fの取り得る数値範囲として、上限値‘127’と下限値‘−128’とが登録される(図3/ステップS108)。
【0096】
プログラム文(6)は、新しい変数iの定義である。よって、先ずシンボル名とデータ型がシンボルテーブルに登録される(図2/ステップS10)。また、プログラム文(6)は変数iの定義であるため、取り得る数値範囲の解析が行なわれる(図2/ステップS11及びS12)。
【0097】
ここでの数値範囲の解析について具体的に説明する。変数iは、for文におけるイテレータ変数である(図3/ステップS100)。よって、初期値、終了条件及び増分値から、変数iの取り得る数値範囲(上限値及び下限値)が算出され、シンボルテーブルに登録される(図3/ステップS101)。この場合、初期値がi=0、終了条件がi<10、増分値が i++(i=i+1)であるので、変数iの上限値は9、下限値は0である。よってシンボルテーブルには上限値9と下限値0とが登録される。
【0098】
プログラム文(7)は、配列変数b〔i〕に対する代入式であり、変数b〔i〕の定義とみなされる。よって、上記のプログラム文(2)では宣言であったので、シンボル名とそのデータ型とがシンボルテーブルに登録されるだけであったが(図2/ステップS10)、プログラム文(7)は定義であるので、取り得る数値範囲の解析が行なわれる(図2/ステップS11及びS12)。
【0099】
ここでの数値範囲の解析について具体的に説明する。プログラム文(7)においては、代入式の右辺は‘d/e*i’と言うような変数を含んでいる。このためため、代入式の右辺に含まれる全ての変数(d、e、i)の取り得る数値範囲(上限値及び下限値)がシンボルテーブルから抽出される(図3/ステップS104)。
【0100】
シンボルテーブルにおいて、各変数の上限値及び下限値は、d=100000、e=1000、0≦i≦9と登録されており、上限値又は下限値が登録されていない変数は存在していない(図3/ステップS105)。よって、代入式の右辺に含まれる変数d、e及びiの上限値と下限値との間に存する全数値に対する代入式の計算値が求められる(図3/ステップS107)。
【0101】
計算の結果、‘d/e*i’の上限値は‘900’、下限値は‘0’であることがわかる。なお、プログラム文(7)の代入式は一次式であるので、上限値と下限値との間に存する全数値に対して、代入式の結果値を計算する必要はなく、各変数の上限値と下限値とのみを用いて計算が可能である。また、代入式が多次式の場合は、数学的に極値計算を行なって極値を算出し、この極値を変数b〔i〕の上限値又は下限値とすることもできる。計算結果は、変数b〔i〕の取り得る数値範囲としてシンボルテーブルに登録される(図3/ステップS108)。
【0102】
プログラム文(8)もプログラム(7)と同様、配列変数c〔i〕に対する代入式なので、変数c〔i〕の定義とみなされ、取り得る数値範囲の解析が行なわれる(図2/ステップS11及びS12)。プログラム文(8)では、代入式の右辺は‘e+f’と言うような変数を含む式である。このため、プログラム(7)の場合と同様に、代入式の右辺に含まれる全ての変数(e、f)の取り得る数値範囲(上限値及び下限値)がシンボルテーブルから抽出される(図3/ステップS104)。
【0103】
シンボルテーブルにおいて、各変数の上限値及び下限値は、e=1000、−128≦f≦127と登録されており、上限値又は下限値が登録されていない変数は存在していない(図3/ステップS105)。よって、代入式の右辺に含まれる変数e及びfの上限値と下限値との間に存する全数値に対する代入式の計算値が求められる(図3/ステップS107)。
【0104】
計算の結果、‘e+f’の上限値は‘1127’、下限値は‘872’であることがわかる。なお、プログラム文(8)の代入式も一次式であるので、上限値と下限値との間に存する全数値に対して、代入式の結果値を計算する必要はなく、各変数の上限値と下限値とのみを用いて計算が可能である。この計算結果は、変数c〔i〕の取り得る数値範囲としてシンボルテーブルに登録される(図3/ステップS108)。
【0105】
プログラム文(10)は、プログラム文(6)と同様に、イテレータ変数jの定義である。よって、プログラム文(6)と同様に、シンボル名とデータ型とがシンボルテーブル登録され(図2/ステップS10)、初期値j=0、終了条件j<10、及び増分値j++に基づいて、取り得る数値範囲が算出される。シンボルテーブルには、上限値として9が、下限値として0が登録される。
【0106】
プログラム文(11)は、配列演算の式であり、演算値を格納する配列変数a〔j〕の定義である。よって、プログラム文(7)や(8)と同様に、取り得る数値範囲の解析が行なわれる(図2/ステップS11及びS12)。プログラム文(11)において、配列演算の右辺は‘b〔j〕+c〔j〕’であり、b〔j〕及びc〔j〕といった変数を含んでいる。このため、変数b〔j〕及びc〔j〕の取り得る数値範囲(上限値及び下限値)がシンボルテーブルから抽出される(図3/ステップS104)。
【0107】
シンボルテーブルにおいて、各変数の上限値及び下限値は、0≦b〔j〕≦900、872≦c〔j〕≦1127と登録されており、上限値又は下限値が登録されていない変数は存在していない(図3/ステップS105)。よって、変数b〔j〕及びc〔j〕の上限値と下限値との間に存する全数値に対する配列演算の式の計算値が求められる(図3/ステップS107)。
【0108】
計算の結果、‘b〔j〕+c〔j〕’の上限値は‘2027’、下限値は‘872’であることがわかる。なお、プログラム文(9)の配列演算の式も一次式であるので、上限値と下限値との間に存する全数値に対して、配列演算の式の結果値を計算する必要はなく、各変数の上限値と下限値とのみを用いて計算が可能である。また、配列演算の式が多次式の場合は、数学的に極値計算を行なって極値を算出し、この極値を変数a〔i〕の上限値又は下限値とすることもできる。この計算結果は、変数a〔j〕の取り得る数値範囲としてシンボルテーブルに登録される(図3/ステップS108)。
【0109】
更に、プログラム文(11)で行なわれる演算は配列演算であるので、ソースプログラムやシンボルテーブルから演算の種類、演算のデータ型、値(演算値を格納する変数が取り得る数値範囲)が抽出される(図2/ステップS4及びS20)。演算対象の配列要素b〔j〕やc〔j〕はint型であることがシンボルテーブルより抽出されるので、演算の種類が+(加算)、演算のデータ型がint型、第1オペランドがb〔j〕、第2オペランドがc〔j〕というように抽出される。その後、データ型判定部とデータ型変更部とによる処理が実行される(図2/ステップS21及びS22)。
【0110】
具体的には、演算値を格納するa〔j〕の上限値及び下限値として872≦a〔j〕≦2027が抽出され(図4/ステップS110)、この上限値及び下限値とデータ型情報とが対比され、扱うことができる数値範囲が最も狭いデータ型が検出される。この例では、short型とunsigned short型とが抽出される。シンボルテーブルから抽出した配列演算のデータ型はint型であることから、この扱うことができる数値範囲が狭いデータ型とは一致していないことが分かる(ステップS111)。
【0111】
よって演算のデータ型を、この場合short型(又はunsigned short型)に変更する。次に、演算情報(演算の種類、演算のデータ型、オペランドの値)が中間コード生成部に渡される(図4/ステップS113)。
【0112】
その後、中間コードが生成されるが、演算のデータ型は配列演算を実行するのに必要な最小のデータ型へ変更されているので、図7に示すように生成される中間コード5は、配列演算を実行するのに必要な最小のデータ型(実施例では、shortデータ型)で生成されていることがわかる。また、図7に示すように、この中間コードがベクトル化部に渡され、中間コードの配列演算とこの配列演算のデータ型との両方に該当するベクトル命令が存在すれば、その演算の並列度に対応するベクトル化中間コード6が生成される。
【0113】
本実施の形態では、4並列short型ベクトル加算演算が存在することを仮定しているので、並列度が4のshort型加算演算(short〔4〕でshortの4並列を表現)を表すベクトル化中間コードが生成されている。
【0114】
これによって、ソースプログラム20に記述されているforループ内の配列演算a〔j〕=b〔j〕+c〔j〕は、a〔0〕=b〔0〕+c〔0〕とa〔1〕=b〔1〕+c〔1〕とa〔2〕=b〔2〕+c〔2〕とa〔3〕=b〔3〕+c〔3〕との組み合わせ、a〔4〕=b〔4〕+c〔4〕とa〔5〕=b〔5〕+c〔5〕とa〔6〕=b〔6〕+c〔6〕とa〔7〕=b〔7〕+c〔7〕との組み合わせ、a〔8〕=b〔8〕+c〔8〕とa〔9〕=b〔9〕+c〔9〕との組み合わせで、並列に行なわれる。
【0115】
つまり、従来のベクトル化コンパイラではj=0、2、4、6、8の5回行なわれていた配列演算が、j=0、4、8の3回の配列演算で実行可能となる。以上のように、本実施の形態では、演算のデータ型がソースプログラム中で宣言されているデータ型(int型)から演算実行に必要な最小のデータ型(short型)に最適化されているので、従来の方法でコンパイルした場合と比較して、演算の並列度が2から4に増加し、演算の高速化が図られていると言える。
【0116】
【発明の効果】
以上のように、本実施の形態にかかるコンパイラ装置及びコンパイル方法を用いれば、配列演算の演算値を格納する変数に格納される可能性のある値について、上限値および下限値を予測でき、この格納される可能性のある値を扱うことができる最小のデータ型でベクトル化を実行することが可能となる。この結果、利用できる最大の並列度を持つベクトル命令を使用することができ(最大の並列度でベクトル命令を実行でき)、ソースプログラムの実行の高速化を図ることができる。
【図面の簡単な説明】
【図1】本実施の形態にかかるコンパイラ装置の構成を示す概略構成図
【図2】図1に示すコンパイラ装置における処理の流れ及び本実施の形態にかかるコンパイル方法を示す流れ図
【図3】変数範囲解析部による処理を具体的に示す流れ図
【図4】データ型判定部及びデータ型変更部による処理を具体的に示す流れ図
【図5】ソースプログラム及びシンボルテーブルの一例を示す図
【図6】コンパイラ装置が通常有しているデータ型情報を示す図
【図7】図5に示すソースプログラムに基づいて生成された中間コード及びベクトル化中間コードを示す図
【図8】従来のベクトル化コンパイラ装置を示す概略構成図
【図9】図8に示した従来のベクトル化コンパイラ装置における構文解析部を示す構成図
【図10】図9に示した従来のベクトル化コンパイラ装置を構成する構文解析部の処理を示す流れ図
【図11】具体的なソースプログラムの一例、従来のベクトル化コンパイラ装置を使用した場合のシンボルテーブルの一例、及び中間コードの一例を示す
【符号の説明】
1 構文解析部
2 ベクトル化部
3 最適化部
4 コード生成部
5 中間コード
6 ベクトル化中間コード
7 最適化中間コード
10 構文認識部
11 シンボルテーブル登録部
12 配列演算部
13 構文解析部
14 エラー処理部
15 中間コード生成部
16 変数範囲解析部
17 データ判定部
18 データ型変更部
[0001]
TECHNICAL FIELD OF THE INVENTION
The present invention relates to compiling a program including an array operation, and more particularly, to a vectorizing compiler and a vectorizing compiling method.
[0002]
[Prior art]
FIG. 8 is a schematic configuration diagram showing a conventional vectorizing compiler device. As shown in FIG. 8, the conventional vectorizing compiler device includes a syntax analyzing unit 61, a vectorizing unit 63, an optimizing unit 65, and a code generating unit 67. The vectorizing compiler device first receives the source program 60 as input.
[0003]
The source program 60 is passed to a syntax analyzer 61, where a syntax analysis is performed. As a result, an intermediate code 62 that bridges the source language of the source program 60 and the target language of the object code 68 is generated.
[0004]
The intermediate code 62 is generated to make it easier to perform later vectorization and optimization. Next, the intermediate code 62 is passed to the vectorizing unit 63, and the intermediate code 62 is subjected to vectorization determination and vectorization. As a result, the vectorizable intermediate code 62 is converted into a vectorized intermediate code 64.
[0005]
The vectorized intermediate code 64 is passed to an optimizing unit 65, where some optimization is performed to generate an optimized intermediate code 66. The optimized intermediate code 66 is passed to a code generation unit 67, and an object code 68 is output from a vectorizing compiler.
[0006]
FIG. 9 is a configuration diagram showing a syntax analysis unit in the conventional vectorizing compiler device shown in FIG. As shown in FIG. 9, the syntax analysis unit 61 includes a syntax recognition unit 70, a symbol table registration unit 71, an array operation unit 72, a syntax processing unit (1 to n) 73, an error processing unit 74, and an intermediate code generation unit 75. It is composed of
[0007]
The syntax recognizing unit 70 recognizes which syntax of the program language the read source program 60 corresponds to. The symbol table registration unit 71 includes a database called a symbol table. The symbol table registration unit 71 is called when the syntax recognition unit 70 determines that the analysis target of the program is a variable declaration or definition. The data type information (symbol information) of the variable is registered in the symbol table.
[0008]
The array operation unit 72 is called when the syntax recognition unit 70 determines that the analysis target of the program is an array operation. At least the type of array operation, the data type of the operand, and the operand value described in the program And passes the information to the intermediate code generator 75.
[0009]
The syntax processing unit 73 is the same as the array operation unit 72, and is called from the syntax recognition unit 70 when a syntax other than the array operation appears, performs an analysis process corresponding to the syntax, and provides the intermediate code generation unit 75 with details. Pass information. Note that the analysis processing corresponding to each syntax is not important in this specification and will not be described.
[0010]
The error processing unit 74 is called when the syntax is not recognized by the syntax recognition unit 70, and performs error processing. The intermediate code generation unit 75 receives information necessary for generating the intermediate code 62 from the array operation unit 72 and the syntax processing unit 73, and generates the intermediate code 62 corresponding to the information.
[0011]
FIG. 10 is a flowchart showing the processing of the syntax analysis unit included in the conventional vectorizing compiler device shown in FIG. As shown in FIG. 10, the source program 60 is first read by the syntax recognition unit 70. (Step S200). Next, a sentence is extracted from the read source program 60 and analyzed by the syntax recognizing unit 70 (step S201), and it is further determined whether the analysis target of the program sentence is a variable declaration or a definition (step S201). Step S202).
[0012]
If the determination is true, the symbol table registration unit 71 registers the variable name and data type in the symbol table (Step S210). After that, the procedure moves to step S203. On the other hand, if the determination is false, the process directly proceeds to step S203.
[0013]
In step S203, the syntax recognition unit 70 determines whether the analysis target of the program sentence is an array operation. If the determination of the array operation is true, the array operation unit 72 extracts information on the type of operation, the data type of the operation, and the value (step S220). After that, the intermediate code generation unit 75 generates the intermediate code 62 based on the extracted information (step S240), and the syntax recognition unit 70 determines whether the program ends (step S206). Among the source program 60 under analysis, the intermediate code 62 for the array operation is generated by this series of processing (steps S220 and S240).
[0014]
If the determination of the array operation is false, the syntax recognition unit 70 determines whether the syntax is other than the array operation, that is, whether any of the syntax processing units (1 to n) is a corresponding syntax. Is determined (step S204).
[0015]
If true, the syntax processing is performed by the corresponding syntax processing unit, and information necessary to generate the intermediate code 62 is extracted (step S230). After that, the intermediate code generator 75 generates the intermediate code 62 based on the extracted information (Step S240). Furthermore, the end of the program is determined by the syntax recognition unit 70 (step S206).
[0016]
On the other hand, if the determination is false, syntax error processing is performed by the syntax recognition unit 70 (step S205). Thereafter, the end of the program is determined by the syntax recognition unit 70 (step S206).
[0017]
In the program termination determination in step S206, the syntax recognition unit 70 determines whether the source program 60 being analyzed has terminated. If true, the process proceeds to the vectorization unit 63. If false, the process returns to step S201, and the analysis of the remaining source program 60 is continued.
[0018]
Through the processing described above, the syntax analyzer 61 shown in FIGS. 8 and 9 generates the intermediate code 62. A feature of the generated intermediate code 62 is that the intermediate code 62 for the array operation is generated in the data type of the array declared in the source program 60.
[0019]
FIG. 11 is a diagram showing an example of a specific source program, an example of a symbol table when a conventional vectorizing compiler is used, and an example of an intermediate code. In the following description, description will be made with reference to FIG.
[0020]
As shown in FIG. 11, syntax analysis is performed on each sentence ((1) to (12)) of the input source program 60. First, since the statement (1) is a declaration of a function g that returns a char type without an argument, the symbol name (variable name) and its data type are registered in the symbol table 69 in step S210 (FIG. 10).
[0021]
Also, the sentence (1) does not correspond to an array operation, and corresponds to the classification of variable declaration as syntax processing, so that the determination in step S204 (FIG. 10) is true. Accordingly, the process proceeds to step S230 (FIG. 10), where syntax analysis processing is performed on the variable declaration, and in step S240 (FIG. 10), an intermediate code for the variable declaration is generated. Thereafter, in step S206 (FIG. 10), the end of the program is determined. Since there is a continuation of the program, the process returns to step S201 (FIG. 10), and the process is continued. Note that the processing of step S204 (FIG. 10) and step S230 (FIG. 10) are performed for all program statements other than (11) corresponding to the array operation, and thus description thereof will be omitted.
[0022]
Next, since the statement in (2) is a declaration of array variables a, b, and c, the symbol name and its data type are registered in the symbol table 69 in step S210 (FIG. 10). Since each of the statements (3), (4), and (5) is a variable definition having an initial value, the symbol name and its data type are similarly registered in the symbol table 69 in step S210.
[0023]
Since a new variable i is defined in the statement (6), the symbol name and data type are registered in the symbol table 69 also in step S210. In the statements of (7) and (8), since they are substitution expressions for the array variables b and c, they are regarded as the definition of variables, and the variable name and data type are registered in step S210. Finish the process as it is. In the statement of (10), a new variable j is defined, and therefore the symbol name and its data type are registered in the symbol table 69.
[0024]
Next, since the sentence (11), which is the body of the for syntax, is an array operation, the type of operation, the data type and the value of the operation are extracted from the source program 60 and the symbol table 69 in step S220. Thereafter, in step S240, an intermediate code 62 for performing an operation using the data type of the extracted operation is generated.
[0025]
In the example shown in FIG. 11, it can be seen from the symbol table 69 that the array elements b and c to be operated are of the int type. Thus, an intermediate code 62 is generated in which the operation type is + (addition), the operation data type is int type, the first operand is b [j], and the second operand is c [j]. As described above, the intermediate code 62 for the array operation generated by the conventional vectorizing compiler device is generated in the data type declared in the source program 60 (int type in the example of FIG. 11). Understand.
[0026]
The intermediate code 62 is passed to the vectorization unit 63, and if there is a vector instruction corresponding to the operation and data type of the intermediate code 62, a vectorized intermediate code 64 corresponding to the degree of parallelism of the operation is generated. In the example of FIG. 11, since it is assumed that there is a two-parallel int-type vector addition operation, vectorization representing an int-type addition operation with a degree of parallelism of 2 (int [2] represents two parallels of int). An intermediate code 64 is generated.
[0027]
Therefore, the array operation a [j] = b [j] + c [j] in the for loop described in the source program 60 is a [0] = b [0] + c [0] and a [1] = b [1] + c [1], a [2] = b [2] + c [2] and a [3] = b [3] + c [3], a [4] = b [4] + c [4] And a [5] = b [5] + c [5], a [6] = b [6] + c [6] and a [7] = b [7] + c [7], a [8] = b [ 8] + c [8] and a [9] = b [9] + c [9] are performed in parallel. That is, an array operation normally performed 10 times (j = 0, 1,..., 8, 9) can be executed by a parallel array operation performed 5 times (j = 0, 2, 4, 6, 8).
[0028]
As described above, in the conventional vectorizing compiler device, the intermediate code 62 is generated so that the array operation is executed with the data type declared for the operation target in the source program 60, and the intermediate code 62 is It is passed to the unit 63. Therefore, the vectorized intermediate code 64 is also generated such that the array operation is executed with the data type declared for the operation target in the source program 60.
[0029]
[Problems to be solved by the invention]
By the way, in general, as for the instruction corresponding to vectorization, the smaller the size of the data type to be operated, the higher the degree of parallelism and the faster the operation can be executed. To give a specific example, when the register length of the register of the architecture is 64 bits, 2 (= 64/32) parallel operations can be performed with an int type 32 bit operation, whereas a short data type 16 bit operation is possible. 4 (= 64/16) parallel operations can be performed in an arithmetic operation, and 8 (= 64/8) parallel operations can be performed in a char-type 8-bit operation. For this reason, it is ideal to perform vectorization by reducing the size of the data type of the array operation (the data type declared for the operation target).
[0030]
However, the above-described conventional vectorizing compiler analyzes the values that may be stored in the array, that is, the upper limit and lower limit of the value stored in a [j], which is the operation value of the array operation. Has not been done. Therefore, even if the numerical range that the operation value can take is within the numerical range of a data type smaller than the data type declared in the program (a data type with a narrower numerical range that can be handled), a smaller data type Vectorization is not performed, and the vectorization is first performed using the data type declared for the operation target. Therefore, the conventional vectorization compiler described above cannot perform ideal vectorization, that is, vectorization cannot be performed with a minimum data type that can handle an operation value of an array operation. There is no problem.
[0031]
SUMMARY OF THE INVENTION An object of the present invention is to provide a compiler device and a compiling method capable of analyzing a numerical value range of an operation value of an array operation and performing vectorization with a minimum data type capable of handling the operation value of the array operation. It is in.
[0032]
[Means for Solving the Problems]
In order to achieve the above object, a compiler device according to the present invention is a compiler device for compiling a source program including an array operation, and is capable of taking variables used in the array operation when analyzing a syntax in a compilation process. A variable range analysis unit that analyzes a numerical range and analyzes a possible numerical range of a variable storing an operation value of the array operation using a possible numerical range of a variable used in the array operation, and an operation of the array operation From the data types that can handle the numerical range that the variable storing the value can take, detect the data type with the narrowest numerical range that can be handled, and the data type with the narrowest numerical range that can be handled A data type determination unit that determines whether or not the data type of the array operation extracted from the source program including the array operation matches; The data type of the array operation is changed so that when the data type determination unit determines that they do not match, the intermediate code for performing the array operation with the data type having the narrowest numerical range that can be handled is generated. And at least a data type changing unit.
[0033]
In the compiler apparatus according to the present invention, in a source program including the array operation, when an upper limit value and a lower limit value of a variable used in the array operation are defined, the variable range analysis unit may include Based on the upper limit value and the lower limit value, it is possible to analyze a possible numerical range of a variable used in the array operation.
[0034]
In this case, if the variable used in the array operation is an iterator variable, the upper limit and lower limit of the variable used in the array operation are defined by an initial value, an end condition, and an increment value in the iterator variable. .
[0035]
In the compiler device according to the present invention, in a source program including the array operation, when a constant value is substituted for a variable used in the array operation, the variable range analysis unit sets the constant value to: It can be a numerical range that can be taken by a variable used in the array operation.
[0036]
In the compiler apparatus according to the present invention, when the variable used in the array operation is the left side of the assignment expression, the variable range analysis unit can take all variables included in the right side of the assignment expression. By analyzing the numerical range, the possible numerical range of the variables used in the array operation can be analyzed based on the possible numerical ranges of all the variables included in the right side of the substitution expression.
[0037]
In this aspect, the variable range The analysis unit determines whether the substitution expression is a linear expression or a polynomial expression, and if it is a polynomial expression, calculates the extremum of the substitution expression to be used in the array operation. It is possible to analyze the possible numerical range of variables. On the other hand, when the expression is a linear expression, by substituting only the upper limit value and the lower limit value of all the variables included in the right-hand side of the assignment expression into the assignment expression, the possible numerical range of the variable used in the array operation is obtained. Can be analyzed.
[0038]
Further, in this aspect, in at least one of the variables included in the right side of the assignment expression, an upper limit value and a lower limit value are set. Both When the variable is not defined, the variable range analysis unit sets the numerical range that can be handled by the data type declared in the variable used in the array operation to the upper limit value and the lower limit value. Both Can be in the range of possible values for undefined variables.
[0039]
In the compiler apparatus according to the present invention, the variable range The analysis unit determines whether the expression of the array operation is a linear expression or a polynomial expression, and when the expression is a polynomial expression, calculates an extreme value of the array operation, thereby calculating the array operation. It is possible to analyze a numerical range that can be taken by a variable that stores an operation value. On the other hand, when the expression is a linear expression, the upper limit and the lower limit of only the variables used in the array operation included in the right side of the array operation expression are substituted into the array operation expression, whereby the operation of the array operation is performed. It is possible to analyze the numerical range that can be taken by the variable that stores the value.
[0040]
Next, in order to achieve the above object, a compiling method according to the present invention is a method for compiling a source program including an array operation. (B) analyzing a possible numerical range of a variable to be obtained and analyzing a possible numerical range of a variable storing an operation value of the array operation using the allowable numerical range of a variable used in the array operation; From the data types that can handle the numerical range that can be taken by the variable that stores the operation value of the array operation, the data type with the narrowest numerical range that can be handled is detected, and the numerical range that can be handled is the most. Determining whether the narrow data type matches the data type of the array operation extracted from the source program including the array operation; and (c) not matching If it is determined, at least the step of changing the data type of the array operation so that an intermediate code for performing the array operation with the data type having the narrowest numerical range that can be handled is generated. I do.
[0041]
In the compile method according to the present invention, in a source program including the array operation, when an upper limit value and a lower limit value of a variable used in the array operation are defined, the upper limit value and the lower limit value The range of possible values of the variables used in the array operation can be analyzed based on
[0042]
In this case, if the variable used in the array operation is an iterator variable, the upper limit and lower limit of the variable used in the array operation are defined by an initial value, an end condition, and an increment value in the iterator variable. .
[0043]
In the compile method according to the present invention, in a source program including the array operation, when a constant value is substituted for a variable used in the array operation, the constant value is replaced with a variable used in the array operation. Can be in the range of values that can be taken.
[0044]
Further, in the compiling method according to the present invention, when the variable used in the array operation is the left side of the assignment expression, the possible numerical range of all variables included in the right side of the assignment expression is analyzed, The possible numerical ranges of the variables used in the array operation can be analyzed based on the possible numerical ranges of all the variables included in the right side of the assignment expression.
[0045]
In this embodiment, it is determined whether the substitution expression is a linear expression or a polynomial expression, and if the substitution expression is a polynomial expression, the extreme value of the substitution expression is calculated to be used in the array operation. It is possible to analyze the possible numerical range of the variable to be taken. On the other hand, when the expression is a linear expression, by substituting only the upper limit value and the lower limit value of all the variables included in the right side of the assignment expression into the assignment expression, the possible numerical range of the variables used in the array operation is obtained. Can be analyzed.
[0046]
Further, in this aspect, in at least one of the variables included in the right side of the assignment expression, an upper limit value and a lower limit value are set. Both If one is not defined, the numerical range that can be handled by the data type declared in the variable used in the array operation is the upper limit and the lower limit. Both Can be in the range of possible values for undefined variables.
[0047]
In the compiling method according to the present invention, it is determined whether the expression of the array operation is a linear expression or a polynomial expression, and if the expression is a polynomial expression, an extreme value of the array operation is calculated. Thus, a numerical value range that can be taken by a variable that stores the operation value of the array operation can be analyzed. On the other hand, when the expression is a linear expression, the upper limit and the lower limit of only the variables used in the array operation included in the right side of the array operation expression are substituted into the array operation expression, whereby the operation of the array operation is performed. It is possible to analyze the numerical range that can be taken by the variable that stores the value.
[0048]
The present invention may be a program for implementing the compiling method according to the present invention. In this case, the above-described compiler device according to the present invention can be realized by installing and executing such a program on a computer. The “array operation” in the present invention refers to an array operation to be vectorized.
[0049]
BEST MODE FOR CARRYING OUT THE INVENTION
(Embodiment 1)
Hereinafter, a compiler device and a compiling method according to an embodiment of the present invention will be described with reference to FIGS. First, a compiler device according to the present embodiment will be described with reference to FIG. FIG. 1 is a schematic configuration diagram illustrating a configuration of a compiler device according to the present embodiment.
[0050]
As shown in FIG. 1, the compiler device according to the present embodiment, like the conventional compiler device shown in FIG. 8, performs a syntax analysis of a source program 20 to generate an intermediate code 5; A vectorization unit 2 that converts the intermediate code 5 into a vectorized intermediate code 6, an optimization unit 3 that converts the vectorized intermediate code 6 into an optimized intermediate code 7, and a code that generates an object code 21 from the optimized intermediate code 7. It comprises a generation unit 4.
[0051]
However, in the compiler device according to the present embodiment, the configuration and function of the syntax analyzer 1 are different from those of the conventional compiler device shown in FIG. Note that the vectorizing unit 2, the optimizing unit 3, and the code generating unit 4 are the same in configuration and function as those shown in FIG. The syntax analyzer 1 in the compiler according to the present embodiment will be described below.
[0052]
As shown in FIG. 1, the syntax analysis unit 1 includes a syntax recognition unit 10, a symbol table registration unit 11, an array operation unit 12, a syntax processing unit (1 to n) 13, an error processing unit 14, an intermediate code generation unit 15, It comprises a variable range analysis unit 16, a data type determination unit 17, and a data type change unit 18. Among them, the syntax recognition unit 10, the symbol table registration unit 11, the array operation unit 12, the syntax processing units (1 to n) 13, the error processing unit 14, and the intermediate code generation unit 15 are the same as those shown in FIG. Things. The compiler device according to the present embodiment is different from a conventional compiler device in that a variable range analysis unit 16, a data type determination unit 17, and a data type change unit 18 are provided.
[0053]
The variable range analysis unit 16 has a function of analyzing a possible numerical range (upper limit value and lower limit value) of a variable used in the source program 20 at the time of syntax analysis in compiling the source program 20. I have. When the variable is a variable that stores an operation value of an array operation, the variable range analysis unit 16 performs analysis based on a numerical range obtained by analyzing a variable used in the array operation.
[0054]
The data type determination unit 17 detects a data type having a narrowest numerical range that can be handled from among data types that can handle a numerical range that can be taken by a variable that stores an operation value of an array operation. It has a function of determining whether the data type having the narrowest possible numerical value range matches the data type of the array operation. The data type of the array operation to be determined is a data type declared in the source program 20 and is extracted from the source program 20.
[0055]
Also, the data type changing unit 18 can handle a numerical value range that can be handled when the data types do not match. But It has a function to change the data type of array operation so that an intermediate code that performs array operation with the narrowest data type is generated.
[0056]
Next, with reference to FIG. 2, a process in the compiler device shown in FIG. 1 and a compiling method according to the present embodiment will be described. FIG. 2 is a flowchart showing a processing flow in the compiler device shown in FIG. 1 and a compiling method according to the present embodiment. FIG. 2 shows only the flow of processing in the syntax analysis unit 1, and omits the flow of processing in the vectorization unit 2, the optimization unit 3, and the code generation unit 4. In the vectorization unit 2, the optimization unit 3, and the code generation unit 4, the same processing as in the related art is performed. The description will be made with reference to FIG.
[0057]
As shown in FIG. 2, first, a source program 20 is read by the syntax recognition unit 10 (see FIG. 1) (S1), and one program statement is extracted from the source program 20 and analyzed (S2). . The source program 20 includes an array operation.
[0058]
Next, the syntax recognition unit 10 determines whether the extracted program statement is a variable declaration or a definition (S3). If it is not a variable declaration or definition, the process proceeds to step S4.
[0059]
On the other hand, if it is a variable declaration or a variable definition, the symbol table registration unit 11 registers information such as the name of the variable and the declared data type in the symbol table (S10). Further, in this case, the variable range analysis unit 16 determines whether or not the extracted program statement is a definition of a variable based on the information registered in the symbol table (step S11).
[0060]
If the result of the determination is that it is not a definition, the process moves to step S4. If it is a variable definition, the variable range analysis unit 16 analyzes the numerical range that the variable can take, and registers the analyzed numerical range in the symbol table (step S12). The analysis of the numerical range is performed by calculating, using mathematical means, upper and lower limits of the values that may be stored in the variables based on the definitions of the variables made in the source program 20. .
[0061]
The analysis of the numerical range that can be performed is performed irrespective of whether a variable to be analyzed stores an operation value of an array operation or is used for an array operation. When the variable is a variable that stores an operation value of an array operation, analysis is performed based on a numerical range obtained by analyzing a variable used in the array operation. The specific contents of step S12 will be described later with reference to FIG. Thereafter, the process proceeds to step S4.
[0062]
In step S4, the array operation unit 12 determines whether or not the analysis target of the program statement is an array operation. In the case of an array operation, the type of operation and the symbol of the operand to be operated are extracted by the array operation unit 12, and the data type (data type of the array operation) and the value (the operation value are stored) of the extracted symbol from the symbol table Then, information on a variable range that can be taken by the variable to be performed is extracted, and the information is registered in the symbol table (step S20). Further, based on the numerical range that can be taken by the variable storing the operation value analyzed in step S12, the data type determining unit 17 selects a numerical range that can be handled from the data types that can handle this numerical range. The narrowest data type is detected, and it is determined whether or not the data type having the narrowest numerical range that can be handled matches the data type of the array operation extracted in step S20 (step S21).
[0063]
If the data type that can handle the narrowest numerical range matches the data type of the array operation extracted in step S20, the process proceeds to step S40. On the other hand, if they do not match, the data type changing unit 18 changes the data type of the array operation so that an intermediate code for performing the array operation with the data type with the narrowest numerical range that can be handled is generated (step S22). ). Thereafter, the process proceeds to step S40. The specific contents of steps S21 and S22 will be described later with reference to FIG.
[0064]
In step S40, the intermediate code generating unit 15 generates the intermediate code 5 based on the information extracted by the array operation unit 12 and the information changed by the data type changing unit 18. After the generation of the intermediate code, the process proceeds to step S7. Among the programs under analysis, the intermediate code 5 for the array operation is generated by this series of processing (steps S20 to S22 and S40).
[0065]
If it is determined in step S4 that the operation is not an array operation, the syntax recognizing unit 10 determines whether the syntax is other than the array operation, that is, one of the syntax processing units (1 to n) 13 It is determined whether or not the syntax is to be executed (step S5). If the syntax is other than the array operation, the corresponding syntax processing unit 13 performs syntax processing and extracts information necessary for generating the intermediate code 5 for the program statement other than the array operation (step S30). .
[0066]
Further, based on the information extracted in step S30, the intermediate code is 5 It is generated (step S40). Thereafter, the process proceeds to step S7.
[0067]
On the other hand, if it is not a syntax other than the array operation, the syntax recognizing unit 10 executes a syntax error process (step S6). Thereafter, the process proceeds to step S7.
[0068]
In step S7, the syntax recognizing unit 10 determines whether the source program 20 being analyzed has ended. If finished, the vectorization unit 2 Transfer processing to If not, the process returns to step S2 to continue analyzing the remaining program statements.
[0069]
Next, step S12 shown in FIG. 2 will be specifically described with reference to FIG. FIG. 3 is a flowchart specifically showing processing by the variable range analysis unit. Steps S100 to S108 shown in FIG. 3 correspond to step S12 shown in FIG.
[0070]
As shown in FIG. 3, first, the variable range analysis unit 16 determines whether the variable to be analyzed is an iterator variable of a loop based on the information registered in the symbol table (step S100). In the case of an iterator variable, an initial value, an end condition, and an increment value defined in the source program 20 are extracted, and a possible numerical range (upper limit value and lower limit value) of the iterator variable is calculated based on the information. The calculated numerical range is registered in the symbol table (step S101).
[0071]
If the variable is not an iterator variable, the variable range analysis unit 16 determines whether a constant value has been assigned to the variable to be analyzed (step S102). If a constant value is substituted, the constant value is set as a numerical value range that can be taken by the variable to be analyzed, and the constant value is registered in the symbol table (step S103). If the constant value has not been substituted, the process proceeds to step S104.
[0072]
If the variable to be analyzed is neither an iterator variable nor a variable to which a constant value is substituted, it is considered that it is either the left side of the substitution expression or a variable that stores the operation value of an array operation. Therefore, in step S104, the variable range analysis unit 16 analyzes the possible numerical ranges of all the variables included in the right side of the assignment expression or the operation expression of the array operation. Specifically, the variable range analysis unit 16 extracts an upper limit value and a lower limit value for each variable from the symbol table.
[0073]
However, for at least one of the variables included in the right side of the assignment expression or the operation expression of the array operation, the upper limit value and lower limit value Both Is not registered in the symbol table, the value range cannot be extracted from the symbol table. range The analysis unit 16 calculates an upper limit value and a lower limit value. Both It is determined whether the variable not registered in the symbol table is included in the right side of the assignment expression or the operation expression of the array operation (step S105).
[0074]
If the result of the determination is that the above variables are not included, the process moves to step S107. If the variable is included, a numerical range that can be handled by the data type declared in the variable to be analyzed is extracted (step S106). After that, it moves to step S107.
[0075]
In step S107, the variable range analysis unit 16 analyzes the possible numerical ranges of the variables to be analyzed based on the possible numerical ranges of all the variables included in the right side of the assignment expression or the arithmetic expression of the array operation. When a numerical range that can be handled by the data type declared in the variable to be analyzed is extracted in step S106, the extracted numerical range is set to the upper limit value and the lower limit value. Both In this case, the numerical value range of the variable to be analyzed is analyzed as the numerical value range of the variable not registered in the symbol table.
[0076]
Specifically, the variable range analysis unit 16 calculates the assignment expression or the operation expression of the array operation for all the numerical values existing between the upper limit value and the lower limit value of all the variables included in the right side of the assignment expression or the operation expression of the array operation. By calculating the calculated value of, a possible numerical range of the variable to be analyzed is calculated.
[0077]
However, in the present embodiment, the variable range analyzer 16 has a function of determining whether the assignment expression or the operation expression of the array operation is a linear expression or a polynomial expression. Therefore, when the assignment expression or the operation expression of the array operation is a linear expression, there is no need to obtain the calculated value of the assignment expression or the operation expression of the array operation for all the numerical values existing between the upper limit value and the lower limit value of each variable. .
[0078]
In this case, by assigning only the upper and lower limits of all the variables included in the right side of the assignment expression or the operation expression of the array operation to the assignment expression or the operation expression of the array operation, The range can be calculated.
[0079]
If the assignment expression or the operation expression of the array operation is a polynomial expression, a mathematical extremum calculation is performed, and the extremal value obtained thereby is used to calculate a possible numerical range of the variable to be analyzed. You can also.
[0080]
After that, the numerical range analysis unit 16 registers the calculated upper limit and lower limit in the symbol table as the numerical range of the variable to be analyzed (step S108). As described above, by performing the above-described steps S100 to S108 for all variables included in the source program 10, it is possible to finally analyze the range of possible values of the variables storing the operation values of the array operation.
[0081]
next, FIG. Steps S21 and S22 indicated by are described in detail with reference to FIG. FIG. 4 is a flowchart specifically showing processing by the data type determining unit and the data type changing unit. Step S110 shown in FIG. 4 corresponds to step S20 shown in FIG. 2, steps S111 to S112 shown in FIG. 4 correspond to step S21 shown in FIG. 2, and step S113 shown in FIG. 4 corresponds to step S22 shown in FIG. I do.
[0082]
As shown in FIG. 4, first, the data type determination unit 17 stores the data type used for the array operation from the symbol table and the operation value of the array operation analyzed in steps S100 to S108 shown in FIG. 3. A possible numerical range (upper limit and lower limit) of the variable is extracted (step S110).
[0083]
Next, the data type determination unit 17 compares the data type information (information that the compiler device normally has and depends on the model of the architecture) with the possible value range of the variable that stores the operation value of the array operation. Then, a data type which can handle this numerical range and which can handle the narrowest numerical range is detected. Next, the data type determination unit 17 determines whether the data type used for the array operation extracted in step S110 matches the detected data type (step S111).
[0084]
If the result of the determination is that they match, the data type determination unit 17 passes the data type used for the array operation extracted from the symbol table to the intermediate code generation unit 15 as operation information (step S112). Therefore, the intermediate code generation unit 15 generates the intermediate code so that the array operation is performed using the data type used for the array operation extracted from the symbol table.
[0085]
On the other hand, if the result of the determination is that they do not match, the data type determination unit 17 By the data type changing unit 18, Change the data type used for array operation to the data type with the narrowest numerical range that can be handled as described above. That is, the data type determination unit 17 passes the data type having the narrowest numerical range that can be handled as the calculation information to the intermediate code generation unit 15 instead of the data type used for the array operation extracted from the symbol table. (Step S113). Therefore, the intermediate code generation unit 15 generates the intermediate code such that the array operation is performed in the data type having the narrowest numerical range that can be handled.
[0086]
As described above, the intermediate code 5 shown in FIGS. 1 and 2 is generated. Therefore, in the present embodiment, it is possible to generate an intermediate code for performing an array operation with the smallest data type, and it is possible to increase the degree of parallelism and increase the speed as compared with the related art.
[0087]
Next, a compiler device and a compiling method according to the present embodiment will be described based on a specific example of a source program. FIG. 5 is a diagram illustrating an example of a source program and a symbol table. Note that the source program 20 shown in FIG. 5 is the same as the source program 60 shown in FIG. 11 in order to compare the effect with the conventional example. FIG. 6 is a diagram showing data type information that the compiler device normally has. FIG. 7 is a diagram showing an intermediate code and a vectorized intermediate code generated based on the source program shown in FIG.
[0088]
Syntax analysis is performed on the program statements (1) to (12) in the source program 20 shown in FIG. 5 as shown in FIGS. 2 to 4 to generate an intermediate code. In the source program 20 shown in FIG. 5, a variable a is a variable that stores an operation value of an array operation, and other variables b, c, d, e, f, j, and j are variables used for the array operation. is there. The following describes each program statement.
[0089]
Since the program statement (1) is a declaration of a function g that returns a char type without an argument, the variable name and the data type are registered in the symbol table (FIG. 2 / step S10). However, since the program statement (1) is not a definition, an analysis of a possible numerical range is not performed. Further, the program statement (1) does not correspond to the array operation, and the syntax processing corresponds to the classification of variable declaration. Therefore, a syntax analysis process for the variable declaration is performed (FIG. 2 / steps S5 and S30), and an intermediate code for the variable declaration is generated (FIG. 2 / step S40).
[0090]
Thereafter, the end of the program is determined (FIG. 2 / step S7), but since there is a continuation of the program, the processing of the next program statement (2) is performed (FIG. 2 / step S2). The syntax analysis processing for the variable declaration (FIG. 2 / steps S5 and S30) is performed for all program statements other than the program statement (11) corresponding to the array operation. Therefore, they are omitted in the following description.
[0091]
The program statement (2) is a declaration of array variables a [10], b [10] and c [10]. Therefore, the symbol name and its data type are registered in the symbol table (FIG. 2 / step S10). Since the program statement (2) is not a definition, the analysis of the possible numerical range is not performed.
[0092]
The program statements (3), (4) and (5) are definitions of variables each having an initial value. Therefore, first, the symbol name and its data type are registered in the symbol table (FIG. 2 / step S10), and the possible numerical range is analyzed (FIG. 2 / steps S11 and S12).
[0093]
The analysis of the numerical range here will be specifically described. In the program statements (3) and (4), constant values such as '100000' and '1000' are substituted for the variables d and e. Therefore, these constant values are registered in the symbol table as numerical ranges (upper and lower limits) that the variables d and e can take (FIG. 3 / steps S100 and S101).
[0094]
The program statement (5) is an assignment expression for the variable f, and the call result of the function g is assigned to the right side of the assignment expression. Therefore, since the constant value has not been substituted, the upper limit value and the lower limit value of the variables included in the right side of the substitution expression are extracted from the symbol table (FIG. 3 / step S104). Here, from the item of the variable g in the symbol table, it can be seen that both the upper limit and the lower limit are not registered.
[0095]
Therefore, the range of values that the variable f can take is the range of values that can be taken by the data type specified at the declaration, that is, the char type. It is extracted (FIG. 3 / steps S105 and S106). Thereafter, the calculated value of the substitution formula for all the numerical values existing between the upper limit value and the lower limit value of the variable g is obtained (FIG. 3 / step S107). In this case, the return value of the function g is substituted, so that the value range of the variable g is the value range of the variable f. Therefore, the upper limit value '127' and the lower limit value '-128' are registered in the symbol table as possible numerical ranges of the variable f (FIG. 3 / step S108).
[0096]
Program sentence (6) is the definition of a new variable i. Therefore, first, the symbol name and the data type are registered in the symbol table (FIG. 2 / step S10). Further, since the program sentence (6) is a definition of the variable i, a possible numerical range is analyzed (FIG. 2 / steps S11 and S12).
[0097]
The analysis of the numerical range here will be specifically described. The variable i is an iterator variable in the for statement (FIG. 3 / step S100). Therefore, a possible numerical range (upper limit and lower limit) of the variable i is calculated from the initial value, the end condition, and the increment value, and is registered in the symbol table (FIG. 3 / step S101). In this case, since the initial value is i = 0, the end condition is i <10, and the increment value is i ++ (i = i + 1), the upper limit value of the variable i is 9 and the lower limit value is 0. Therefore, the upper limit 9 and the lower limit 0 are registered in the symbol table.
[0098]
The program sentence (7) is an assignment expression for the array variable b [i], and is regarded as the definition of the variable b [i]. Therefore, since the program statement (2) is a declaration, the symbol name and its data type are only registered in the symbol table (FIG. 2 / step S10), but the program statement (7) is defined. Therefore, an analysis of a possible numerical range is performed (FIG. 2 / steps S11 and S12).
[0099]
The analysis of the numerical range here will be specifically described. In the program sentence (7), the right side of the assignment expression includes a variable such as 'd / e * i'. Therefore, the possible numerical ranges (upper and lower limits) of all the variables (d, e, i) included in the right side of the substitution expression are extracted from the symbol table (FIG. 3 / step S104).
[0100]
In the symbol table, the upper limit value and the lower limit value of each variable are registered as d = 100000, e = 1000, and 0 ≦ i ≦ 9, and there is no variable for which no upper limit value or lower limit value is registered ( (FIG. 3 / Step S105). Therefore, the calculated value of the assignment formula for all the numerical values existing between the upper limit value and the lower limit value of the variables d, e, and i included in the right side of the assignment formula is obtained (FIG. 3 / step S107).
[0101]
As a result of the calculation, it can be seen that the upper limit of 'd / e * i' is '900' and the lower limit is '0'. Since the assignment expression of the program statement (7) is a linear expression, it is not necessary to calculate the result value of the assignment expression for all numerical values existing between the upper limit value and the lower limit value. The calculation can be performed using only the and the lower limit. When the substitution expression is a polynomial expression, the extreme value may be mathematically calculated to calculate the extreme value, and the extreme value may be set as the upper limit or the lower limit of the variable b [i]. The calculation result is registered in the symbol table as a possible numerical range of the variable b [i] (FIG. 3 / step S108).
[0102]
Similarly to the program (7), the program sentence (8) is an assignment expression for the array variable c [i], so that it is regarded as the definition of the variable c [i], and the possible numerical range is analyzed (FIG. 2 / step S11). And S12). In the program sentence (8), the right side of the assignment expression is an expression including a variable such as 'e + f'. Therefore, as in the case of the program (7), the possible numerical ranges (upper and lower limits) of all the variables (e, f) included in the right side of the assignment expression are extracted from the symbol table (FIG. 3). / Step S104).
[0103]
In the symbol table, the upper limit and the lower limit of each variable are registered as e = 1000 and −128 ≦ f ≦ 127, and there is no variable for which the upper limit or the lower limit is not registered (FIG. 3 / Step S105). Therefore, the calculated value of the substitution formula for all the numerical values existing between the upper limit value and the lower limit value of the variables e and f included in the right side of the substitution formula is obtained (FIG. 3 / step S107).
[0104]
As a result of the calculation, it can be seen that the upper limit of 'e + f' is '1127' and the lower limit is '872'. Since the assignment expression of the program statement (8) is also a linear expression, it is not necessary to calculate the result value of the assignment expression for all numerical values existing between the upper limit value and the lower limit value. The calculation can be performed using only the and the lower limit. This calculation result is registered in the symbol table as a possible numerical range of the variable c [i] (FIG. 3 / step S108).
[0105]
The program sentence (10) is a definition of the iterator variable j, similarly to the program sentence (6). Therefore, similarly to the program statement (6), the symbol name and the data type are registered in the symbol table (step S10 in FIG. 2), and based on the initial value j = 0, the end condition j <10, and the increment value j ++, A possible numerical range is calculated. In the symbol table, 9 is registered as the upper limit and 0 is registered as the lower limit.
[0106]
The program sentence (11) is an expression of an array operation, and is a definition of an array variable a [j] that stores an operation value. Therefore, as in the case of the program statements (7) and (8), an analysis of a possible numerical range is performed (FIG. 2 / steps S11 and S12). In the program sentence (11), the right side of the array operation is 'b [j] + c [j]', and includes variables such as b [j] and c [j]. Therefore, the possible numerical ranges (upper and lower limits) of the variables b [j] and c [j] are extracted from the symbol table (FIG. 3 / step S104).
[0107]
In the symbol table, the upper and lower limits of each variable are registered as 0 ≦ b [j] ≦ 900 and 872 ≦ c [j] ≦ 1127, and there are variables for which no upper or lower limit is registered. Not performed (FIG. 3 / step S105). Accordingly, the calculated value of the array operation expression for all the numerical values existing between the upper limit value and the lower limit value of the variables b [j] and c [j] is obtained (FIG. 3 / step S107).
[0108]
As a result of the calculation, it can be seen that the upper limit of 'b [j] + c [j]' is '2027' and the lower limit is '872'. Since the expression of the array operation in the program statement (9) is also a linear expression, it is not necessary to calculate the result value of the array operation expression for all numerical values existing between the upper limit and the lower limit. The calculation can be performed using only the upper limit value and the lower limit value of the variable. Further, when the expression of the array operation is a polynomial, an extreme value may be mathematically calculated to calculate an extreme value, and the extreme value may be set as an upper limit or a lower limit of the variable a [i]. This calculation result is registered in the symbol table as a possible numerical range of the variable a [j] (FIG. 3 / step S108).
[0109]
Further, since the operation performed in the program statement (11) is an array operation, the type of operation, the data type of the operation, and the value (a numerical value range that can be stored in the variable storing the operation value) are extracted from the source program or the symbol table. (FIG. 2 / Steps S4 and S20). Since it is extracted from the symbol table that the array elements b [j] and c [j] to be operated are of int type, the operation type is + (addition), the operation data type is int type, and the first operand is b [j] and the second operand are extracted as c [j]. Thereafter, the processing by the data type determining unit and the data type changing unit is performed (FIG. 2 / steps S21 and S22).
[0110]
Specifically, 872 ≦ a [j] ≦ 2027 is extracted as the upper limit and lower limit of a [j] storing the operation value (FIG. 4 / step S110), and the upper limit and lower limit and the data type information are extracted. Is compared, and a data type with the narrowest numerical range that can be handled is detected. In this example, a short type and an unsigned short type are extracted. Since the data type of the array operation extracted from the symbol table is the int type, it can be seen that the data type does not match the data type whose numerical value range that can be handled is narrow (step S111).
[0111]
Therefore, the data type of the operation is changed to a short type (or an unsigned short type) in this case. Next, the operation information (operation type, operation data type, operand value) is passed to the intermediate code generation unit (FIG. 4 / step S113).
[0112]
Thereafter, an intermediate code is generated. Since the data type of the operation has been changed to the minimum data type necessary for executing the array operation, the intermediate code 5 generated as shown in FIG. It can be seen that the data is generated in the minimum data type (in this embodiment, short data type) necessary to execute the operation. As shown in FIG. 7, this intermediate code is passed to the vectorization unit, and if there is a vector instruction corresponding to both the array operation of the intermediate code and the data type of this array operation, the parallelism of the operation is determined. Is generated.
[0113]
In this embodiment, since it is assumed that there is a 4-parallel short-type vector addition operation, vectorization representing a short-type addition operation with a degree of parallelism of 4 (short [4] represents 4-parallel short). Intermediate code has been generated.
[0114]
Thus, the array operation a [j] = b [j] + c [j] in the for loop described in the source program 20 is a [0] = b [0] + c [0] and a [1] = B [1] + c [1] and a [2] = b [2] + c [2] and a [3] = b [3] + c [3], a [4] = b [4] A combination of + c [4] and a [5] = b [5] + c [5] and a [6] = b [6] + c [6] and a [7] = b [7] + c [7], It is performed in parallel by a combination of a [8] = b [8] + c [8] and a [9] = b [9] + c [9].
[0115]
In other words, the array operation performed five times with j = 0, 2, 4, 6, and 8 in the conventional vectorizing compiler can be executed with three array operations with j = 0, 4, and 8. As described above, in the present embodiment, the data type of the operation is optimized from the data type (int type) declared in the source program to the minimum data type (short type) necessary for executing the operation. Therefore, it can be said that the degree of parallelism of the operation is increased from 2 to 4 as compared with the case of compiling by the conventional method, and the operation is speeded up.
[0116]
【The invention's effect】
As described above, by using the compiler apparatus and the compiling method according to the present embodiment, the upper limit value and the lower limit value can be predicted for the value that may be stored in the variable that stores the operation value of the array operation. Vectorization can be performed with the smallest data type that can handle values that may be stored. As a result, a vector instruction having the maximum available degree of parallelism can be used (the vector instruction can be executed with the maximum degree of parallelism), and the speed of execution of the source program can be increased.
[Brief description of the drawings]
FIG. 1 is a schematic configuration diagram showing a configuration of a compiler device according to an embodiment;
FIG. 2 is a flowchart showing a processing flow in a compiler device shown in FIG. 1 and a compiling method according to the embodiment;
FIG. 3 is a flowchart specifically showing processing by a variable range analysis unit;
FIG. 4 is a flowchart specifically showing processing by a data type determination unit and a data type change unit;
FIG. 5 is a diagram showing an example of a source program and a symbol table.
FIG. 6 is a diagram showing data type information normally included in a compiler device.
FIG. 7 is a view showing an intermediate code and a vectorized intermediate code generated based on the source program shown in FIG. 5;
FIG. 8 is a schematic configuration diagram showing a conventional vectorizing compiler device.
9 is a configuration diagram showing a syntax analysis unit in the conventional vectorizing compiler device shown in FIG.
FIG. 10 is a flowchart showing the processing of a syntax analysis unit constituting the conventional vectorizing compiler device shown in FIG.
FIG. 11 shows an example of a specific source program, an example of a symbol table when a conventional vectorizing compiler is used, and an example of an intermediate code.
[Explanation of symbols]
1 Syntax analyzer
2 Vectorizer
3 optimization section
4 Code generator
5 Intermediate code
6 Vectorized intermediate code
7 Optimized intermediate code
10 Syntax Recognition Unit
11 Symbol table registration section
12 Array operation unit
13 Syntax analyzer
14 Error processing unit
15 Intermediate code generator
16 Variable range analyzer
17 Data judgment part
18 Data Type Change Section

Claims (30)

配列演算を含むソースプログラムをコンパイルするコンパイラ装置であって、
コンパイル処理における構文の解析の際に、前記配列演算に用いられる変数の取り得る数値範囲を解析し、前記配列演算に用いられる変数の取り得る数値範囲を用いて前記配列演算の演算値を格納する変数の取り得る数値範囲を解析する変数範囲解析部と、
前記配列演算の演算値を格納する変数が取り得る数値範囲を扱うことができるデータ型の中から、扱うことができる数値範囲が最も狭いデータ型を検出し、前記扱うことができる数値範囲が最も狭いデータ型と前記配列演算を含むソースプログラムから抽出される前記配列演算のデータ型とが一致するかどうかを判定するデータ型判定部と、
前記データ型判定部によって一致しないと判定された場合に、前記扱うことができる数値範囲が最も狭いデータ型で前記配列演算を行なう中間コードが生成されるように、前記配列演算のデータ型を変更するデータ型変更部とを少なくとも有することを特徴とするコンパイラ装置。
A compiler device for compiling a source program including an array operation,
At the time of analyzing the syntax in the compiling process, the possible numerical value range of the variable used in the array operation is analyzed, and the calculated value of the array operation is stored using the possible numerical range of the variable used in the array operation. A variable range analysis unit for analyzing a numerical range that the variable can take;
From the data types that can handle the numerical range that can be taken by the variable that stores the operation value of the array operation, the data type with the narrowest numerical range that can be handled is detected, and the numerical range that can be handled is the most. A data type determination unit that determines whether a narrow data type matches a data type of the array operation extracted from the source program including the array operation,
If the data type determination unit determines that they do not match, the data type of the array operation is changed so that an intermediate code for performing the array operation is generated with the data type having the narrowest numerical range that can be handled. And a data type change unit that performs the conversion.
前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数の上限値と下限値とが定義されている場合に、前記変数範囲解析部が、前記上限値と前記下限値とに基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項1記載のコンパイラ装置。In the source program including the array operation, when an upper limit value and a lower limit value of a variable used in the array operation are defined, the variable range analysis unit may perform a calculation based on the upper limit value and the lower limit value. 2. The compiler apparatus according to claim 1, wherein the compiler analyzes a range of possible values of variables used in the array operation. 前記配列演算に用いられる変数がイテレータ変数であり、前記配列演算に用いられる変数の上限値と下限値とが、前記イテレータ変数における初期値、終了条件及び増分値によって定義されている請求項2記載のコンパイラ装置。The variable used in the array operation is an iterator variable, and upper and lower limits of the variable used in the array operation are defined by an initial value, an end condition, and an increment value in the iterator variable. Compiler unit. 前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数に定数値が代入されている場合に、前記変数範囲解析部が、前記定数値を、前記配列演算に用いられる変数の取り得る数値範囲とする請求項1記載のコンパイラ装置。In a source program including the array operation, when a constant value is substituted for a variable used in the array operation, the variable range analysis unit can take the constant value as a variable used in the array operation. 2. The compiler device according to claim 1, wherein the range is a numerical value range. 前記配列演算に用いられる変数が代入式の左辺である場合に、前記変数範囲解析部が、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲を解析し、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲に基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項1記載のコンパイラ装置。When the variable used in the array operation is the left side of the assignment expression, the variable range analysis unit analyzes the possible numerical range of all variables included in the right side of the assignment expression, 2. The compiler device according to claim 1, wherein a possible numerical range of the variables used in the array operation is analyzed based on a possible numerical range of all the included variables. 前記変数範囲解析部が、前記代入式が一次式であるか又は多次式であるかを判別し、多次式である場合に、前記代入式の極値を算出することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項5記載のコンパイラ装置。The variable range analysis unit determines whether the substitution expression is a linear expression or a polynomial expression, and if the substitution expression is a polynomial expression, calculates the extremum of the substitution expression, thereby performing the array operation. 6. The compiler device according to claim 5, wherein a possible numerical range of a variable used in the analysis is analyzed. 前記変数範囲解析部が、前記代入式が一次式であるか又は多次式であるかを判別し、一次式である場合に、前記代入式の右辺に含まれる全ての変数の上限値及び下限値のみを前記代入式に代入することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項5記載のコンパイラ装置。The variable range analysis unit determines whether the substitution expression is a linear expression or a polynomial expression.If the substitution expression is a linear expression, the upper and lower limits of all variables included in the right side of the substitution expression. 6. The compiler device according to claim 5, wherein only the value is substituted into the substitution expression to analyze a possible numerical range of a variable used in the array operation. 前記代入式の右辺に含まれる変数のうち少なくとも一つの変数において、上限値及び下限値の両方が定義されていない場合に、前記変数範囲解析部が、前記配列演算に用いられる変数において宣言されたデータ型が扱うことができる数値範囲を、前記上限値及び下限値の両方が定義されていない変数の取り得る数値範囲とする請求項5記載のコンパイラ装置。In at least one variable of the variables included in the right side of the assignment, when both the upper limit and the lower limit is not defined, the variable range analyzing unit, is declared in the variable used for the array operation and the numerical range which can be data types handled, the upper limit value and the compiler apparatus according to claim 5, wherein both it is to the possible numerical range of variables not defined lower limit. 前記変数範囲解析部が、前記配列演算の式が一次式であるか又は多次式であるかを判別し、多次式である場合に、前記配列演算の極値を算出することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析する請求項1記載のコンパイラ装置。The variable range analysis unit determines whether the expression of the array operation is a linear expression or a polynomial expression, and when it is a polynomial expression, by calculating an extreme value of the array operation, 2. The compiler device according to claim 1, wherein a numerical value range which can be taken by a variable storing an operation value of the array operation is analyzed. 前記変数範囲解析部が、前記配列演算の式が一次式であるか又は多次式であるかを判別し、一次式である場合に、前記配列演算の式の右辺に含まれる前記配列演算に用いられる変数の上限値及び下限値のみを前記配列演算の式に代入することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析する請求項1記載のコンパイラ装置。The variable range analysis unit determines whether the expression of the array operation is a linear expression or a polynomial expression.If the expression is a linear expression, the variable range analysis unit performs an operation on the array operation included in the right side of the expression of the array operation. 2. The compiler device according to claim 1, wherein only the upper limit value and the lower limit value of the variables used are substituted into the expression of the array operation to analyze a possible numerical range of the variable storing the operation value of the array operation. 配列演算を含むソースプログラムをコンパイルする方法であって、
(a)コンパイル処理における構文の解析の際に、前記配列演算に用いられる変数の取り得る数値範囲を解析し、前記配列演算に用いられる変数の取り得る数値範囲を用いて前記配列演算の演算値を格納する変数の取り得る数値範囲を解析する工程と、
(b)前記配列演算の演算値を格納する変数が取り得る数値範囲を扱うことができるデータ型の中から、扱うことができる数値範囲が最も狭いデータ型を検出し、前記扱うことができる数値範囲が最も狭いデータ型と前記配列演算を含むソースプログラムから抽出される前記配列演算のデータ型とが一致するかどうかを判定する工程と、
(c)一致しないと判定した場合に、前記扱うことができる数値範囲が最も狭いデータ型で前記配列演算を行なう中間コードが生成されるように、前記配列演算のデータ型を変更する工程とを少なくとも有することを特徴とするコンパイル方法。
A method for compiling a source program including an array operation, comprising:
(A) At the time of analyzing the syntax in the compiling process, the possible numerical value range of the variable used in the array operation is analyzed, and the calculated value of the array operation is calculated using the possible numerical value range of the variable used in the array operation. Analyzing the possible numerical range of the variable that stores the
(B) Among the data types that can handle the numerical range that can be taken by the variable that stores the operation value of the array operation, a data type that can handle the narrowest numerical range is detected and the numerical value that can be handled Determining whether the data type of the narrowest range matches the data type of the array operation extracted from the source program including the array operation,
(C) changing the data type of the array operation so that, when it is determined that they do not match, an intermediate code for performing the array operation with a data type having the narrowest numerical range that can be handled is generated. A compiling method characterized by having at least:
前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数の上限値と下限値とが定義されている場合に、前記上限値と前記下限値とに基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項11記載のコンパイル方法。In a source program including the array operation, when an upper limit and a lower limit of a variable used for the array operation are defined, the variable is used for the array operation based on the upper limit and the lower limit. compiling method of claim 11, wherein analyzing the possible numerical range of variables. 前記配列演算に用いられる変数がイテレータ変数であり、前記配列演算に用いられる変数の上限値と下限値とが、前記イテレータ変数における初期値、終了条件及び増分値によって定義されている請求項12記載のコンパイル方法。13. The variable used in the array operation is an iterator variable, and upper and lower limits of the variable used in the array operation are defined by an initial value, an end condition, and an increment value in the iterator variable. How to compile. 前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数に定数値が代入されている場合に、前記定数値を、前記配列演算に用いられる変数の取り得る数値範囲とする請求項11記載のコンパイル方法。12. In a source program including the array operation, when a constant value is substituted for a variable used for the array operation, the constant value is set to a value range that the variable used for the array operation can take. The compilation method described. 前記配列演算に用いられる変数が代入式の左辺である場合に、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲を解析し、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲に基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項11記載のコンパイル方法。When the variable used for the array operation is the left side of the assignment expression, the possible numerical range of all the variables included in the right side of the assignment expression is analyzed, and the range of all the variables included in the right side of the assignment expression is analyzed. 12. The compiling method according to claim 11, wherein a possible numerical range of a variable used in the array operation is analyzed based on the obtained numerical range. 前記代入式が一次式であるか又は多次式であるかを判別し、多次式である場合に、前記代入式の極値を算出することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項15記載のコンパイル方法。By determining whether the substitution expression is a linear expression or a polynomial expression, and when the substitution expression is a polynomial expression, by calculating an extreme value of the substitution expression, a variable used in the array operation can be obtained. 16. The compiling method according to claim 15, wherein a numerical range is analyzed. 前記代入式が一次式であるか又は多次式であるかを判別し、一次式である場合に、前記代入式の右辺に含まれる全ての変数の上限値及び下限値のみを前記代入式に代入することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項15記載のコンパイル方法。Determine whether the assignment expression is a linear expression or a polynomial expression, and if it is a primary expression, only the upper limit and lower limit of all variables included in the right side of the assignment expression are assigned to the assignment expression. 16. The compiling method according to claim 15, wherein a numerical value range of a variable used in the array operation is analyzed by the substitution. 前記代入式の右辺に含まれる変数のうち少なくとも一つの変数において、上限値及び下限値の両方が定義されていない場合に、前記配列演算に用いられる変数において宣言されたデータ型が扱うことができる数値範囲を、前記上限値及び下限値の両方が定義されていない変数の取り得る数値範囲とする請求項15記載のコンパイル方法。In at least one variable of the variables included in the right side of the assignment, when both the upper limit and the lower limit is not defined, it declared data type in the variable used for the array operation handled the numerical range for the upper limit and the compiling method of claim 15, wherein both it is to the possible numerical range of variables not defined lower limit. 前記配列演算の式が一次式であるか又は多次式であるかを判別し、多次式である場合に、前記配列演算の極値を算出することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析する請求項11記載のコンパイル方法。Determine whether the array operation expression is a linear expression or a polynomial expression, and if it is a polynomial expression, calculate the extreme value of the array operation to store the operation value of the array operation 12. The compiling method according to claim 11, wherein a numerical value range which can be taken by the variable to be performed is analyzed. 前記配列演算の式が一次式であるか又は多次式であるかを判別し、一次式である場合に、前記配列演算の式の右辺に含まれる前記配列演算に用いられる変数の上限値及び下限値のみを前記配列演算の式に代入することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析する請求項11記載のコンパイル方法。Determine whether the array operation expression is a linear expression or a polynomial expression, and if it is a primary expression, the upper limit value of the variables used in the array operation included in the right side of the array operation expression and 12. The compiling method according to claim 11, wherein a numerical value range which can be taken by a variable storing an operation value of the array operation is analyzed by substituting only the lower limit value into the array operation expression. 配列演算を含むソースプログラムをコンパイルする方法を、コンピュータに実行させるためのプログラムであって、
(a)コンパイル処理における構文の解析の際に、前記配列演算に用いられる変数の取り得る数値範囲を解析し、前記配列演算に用いられる変数の取り得る数値範囲を用いて前記配列演算の演算値を格納する変数の取り得る数値範囲を解析するステップと、
(b)前記配列演算の演算値を格納する変数が取り得る数値範囲を扱うことができるデータ型の中から、扱うことができる数値範囲が最も狭いデータ型を検出し、前記扱うことができる数値範囲が最も狭いデータ型と前記配列演算を含むソースプログラムから抽出される前記配列演算のデータ型とが一致するかどうかを判定するステップと、
(c)一致しないと判定した場合に、前記扱うことができる数値範囲が最も狭いデータ型で前記配列演算を行なう中間コードが生成されるように、前記配列演算のデータ型を変更するステップとを少なくとも有することを特徴とするコンピュータに実行させるプログラム。
A program for causing a computer to execute a method of compiling a source program including an array operation,
(A) At the time of analyzing the syntax in the compiling process, the possible numerical value range of the variable used in the array operation is analyzed, and the calculated value of the array operation is calculated using the possible numerical value range of the variable used in the array operation. Analyzing the possible numerical range of the variable that stores
(B) Among the data types that can handle the numerical range that can be taken by the variable that stores the operation value of the array operation, a data type that can handle the narrowest numerical range is detected and the numerical value that can be handled Determining whether the data type of the narrowest range matches the data type of the array operation extracted from the source program including the array operation,
(C) changing the data type of the array operation so that, when it is determined that they do not match, an intermediate code for performing the array operation with a data type having the narrowest numerical range that can be handled is generated. A program to be executed by a computer characterized by having at least a program.
前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数の上限値と下限値とが定義されている場合に、前記上限値と前記下限値とに基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項21記載のプログラム。In a source program including the array operation, when an upper limit and a lower limit of a variable used for the array operation are defined, the variable is used for the array operation based on the upper limit and the lower limit. claim 21, wherein the program for analyzing the possible numerical range of variables. 前記配列演算に用いられる変数がイテレータ変数であり、前記配列演算に用いられる変数の上限値と下限値とが、前記イテレータ変数における初期値、終了条件及び増分値によって定義されている請求項22記載のプログラム。23. The variable used in the array operation is an iterator variable, and upper and lower limits of the variable used in the array operation are defined by an initial value, an end condition, and an increment value in the iterator variable. Program. 前記配列演算を含むソースプログラム中において、前記配列演算に用いられる変数に定数値が代入されている場合に、前記定数値を、前記配列演算に用いられる変数の取り得る数値範囲とする請求項21記載のプログラム。22. In a source program including the array operation, when a constant value is substituted for a variable used in the array operation, the constant value is set to a value range that the variable used in the array operation can take. The program described. 前記配列演算に用いられる変数が代入式の左辺である場合に、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲を解析し、前記代入式の右辺に含まれる全ての変数の取り得る数値範囲に基づいて、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項21記載のプログラム。When the variable used for the array operation is the left side of the assignment expression, the possible numerical range of all the variables included in the right side of the assignment expression is analyzed, and the range of all the variables included in the right side of the assignment expression is analyzed. 22. The program according to claim 21, wherein a possible numerical range of a variable used in the array operation is analyzed based on the obtained numerical range. 前記代入式が一次式であるか又は多次式であるかを判別し、多次式である場合に、前記代入式の極値を算出することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項25記載のプログラム。Determine whether the substitution expression is a linear expression or a polynomial expression, and when the substitution expression is a polynomial expression, calculate the extremum of the substitution expression to obtain a variable used in the array operation. The program according to claim 25, wherein the program analyzes a numerical range. 前記代入式が一次式であるか又は多次式であるかを判別し、一次式である場合に、前記代入式の右辺に含まれる全ての変数の上限値及び下限値のみを前記代入式に代入することによって、前記配列演算に用いられる変数の取り得る数値範囲を解析する請求項25記載のプログラム。Determine whether the assignment expression is a linear expression or a polynomial expression, and if it is a primary expression, only the upper limit and lower limit of all variables included in the right side of the assignment expression are assigned to the assignment expression. 26. The program according to claim 25, wherein the substitution is performed to analyze a possible numerical range of a variable used in the array operation. 前記代入式の右辺に含まれる変数のうち少なくとも一つの変数において、上限値及び下限値の両方が定義されていない場合に、前記配列演算に用いられる変数において宣言されたデータ型が扱うことができる数値範囲を、前記上限値及び下限値の両方が定義されていない変数の取り得る数値範囲とする請求項25記載のプログラム。In at least one variable of the variables included in the right side of the assignment, when both the upper limit and the lower limit is not defined, it declared data type in the variable used for the array operation handled numerical range for a claim 25, wherein the program according to the possible numerical range of variables both the upper limit and the lower limit is not defined. 前記配列演算の式が一次式であるか又は多次式であるかを判別し、多次式である場合に、前記配列演算の極値を算出することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析する請求項21記載のプログラム。Determine whether the array operation expression is a linear expression or a polynomial expression, and if it is a polynomial expression, calculate the extreme value of the array operation to store the operation value of the array operation 22. The program according to claim 21, wherein a numerical value range which can be taken by the variable to be analyzed is analyzed. 前記配列演算の式が一次式であるか又は多次式であるかを判別し、一次式である場合に、前記配列演算の式の右辺に含まれる前記配列演算に用いられる変数の上限値及び下限値のみを前記配列演算の式に代入することによって、前記配列演算の演算値を格納する変数が取り得る数値範囲を解析する請求項21記載のプログラム。Determine whether the array operation expression is a linear expression or a polynomial expression, and if it is a primary expression, the upper limit value of the variables used in the array operation included in the right side of the array operation expression and 22. The non-transitory computer-readable storage medium according to claim 21, wherein a numerical range that can be taken by a variable storing an operation value of the array operation is analyzed by substituting only a lower limit value into the expression of the array operation.
JP2001349185A 2001-11-14 2001-11-14 Compiler device and compiling method Expired - Fee Related JP3598090B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2001349185A JP3598090B2 (en) 2001-11-14 2001-11-14 Compiler device and compiling method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2001349185A JP3598090B2 (en) 2001-11-14 2001-11-14 Compiler device and compiling method

Publications (2)

Publication Number Publication Date
JP2003150386A JP2003150386A (en) 2003-05-23
JP3598090B2 true JP3598090B2 (en) 2004-12-08

Family

ID=19161893

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2001349185A Expired - Fee Related JP3598090B2 (en) 2001-11-14 2001-11-14 Compiler device and compiling method

Country Status (1)

Country Link
JP (1) JP3598090B2 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005301415A (en) * 2004-04-07 2005-10-27 Ricoh Co Ltd Compile system, simulator, emulator, and program development supporting system
WO2011096016A1 (en) * 2010-02-05 2011-08-11 株式会社 東芝 Compiler device

Also Published As

Publication number Publication date
JP2003150386A (en) 2003-05-23

Similar Documents

Publication Publication Date Title
Healy et al. Supporting timing analysis by automatic bounding of loop iterations
JP4105264B2 (en) compiler
US8024718B2 (en) System and method for optimizing source code
CN110096439B (en) Test case generation method for solidity language
US4773007A (en) Complier code optimization method for a source program having a first and second array definition and use statements in a loop
US20060195828A1 (en) Instruction generator, method for generating instructions and computer program product that executes an application for an instruction generator
US7917899B2 (en) Program development apparatus, method for developing a program, and a computer program product for executing an application for a program development apparatus
US20160321039A1 (en) Technology mapping onto code fragments
JPH03111971A (en) Vectorizing diagnostic system
JP2008510230A (en) Method for recognizing acyclic instruction patterns
Etessami et al. Model checking of recursive probabilistic systems
JPH07114473A (en) Instruction series optimizing method for compiler
Lee et al. Raive: Runtime assessment of floating-point instability by vectorization
JP3598090B2 (en) Compiler device and compiling method
Pearce Integer range analysis for Whiley on embedded systems
Sargsyan et al. Scalable and accurate clones detection based on metrics for dependence graph
Sharma et al. Sound bit-precise numerical domains
JP5227646B2 (en) Compiler and code generation method thereof
JPH09160784A (en) Paralleled compiling system
JP2018049461A (en) Compilation device, compilation method and compilation program
Pearce Practical verification condition generation for a bytecode language
Gómez Obtaining High-Level Semantic Information from Binary Code
JP5169322B2 (en) Variable optimization apparatus, variable optimization program, compiler, variable optimization method, and compilation method
Escalada Gómez Obtaining Higher Level Semantics Information from Binary Code
CN115934103A (en) Node fusion processing method and device and electronic equipment

Legal Events

Date Code Title Description
A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20040622

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20040816

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

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20040910

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

Year of fee payment: 4

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

Free format text: PAYMENT UNTIL: 20080917

Year of fee payment: 4

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

Free format text: PAYMENT UNTIL: 20090917

Year of fee payment: 5

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

Free format text: PAYMENT UNTIL: 20090917

Year of fee payment: 5

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

Free format text: PAYMENT UNTIL: 20100917

Year of fee payment: 6

LAPS Cancellation because of no payment of annual fees