JP5169322B2 - Variable optimization apparatus, variable optimization program, compiler, variable optimization method, and compilation method - Google Patents

Variable optimization apparatus, variable optimization program, compiler, variable optimization method, and compilation method Download PDF

Info

Publication number
JP5169322B2
JP5169322B2 JP2008054361A JP2008054361A JP5169322B2 JP 5169322 B2 JP5169322 B2 JP 5169322B2 JP 2008054361 A JP2008054361 A JP 2008054361A JP 2008054361 A JP2008054361 A JP 2008054361A JP 5169322 B2 JP5169322 B2 JP 5169322B2
Authority
JP
Japan
Prior art keywords
array
variable
formula
expression
calculated
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.)
Active
Application number
JP2008054361A
Other languages
Japanese (ja)
Other versions
JP2009211458A (en
Inventor
靖子 多田井
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
NEC Corp
Original Assignee
NEC Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by NEC Corp filed Critical NEC Corp
Priority to JP2008054361A priority Critical patent/JP5169322B2/en
Publication of JP2009211458A publication Critical patent/JP2009211458A/en
Application granted granted Critical
Publication of JP5169322B2 publication Critical patent/JP5169322B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Description

本発明は、コンパイラ、及び、変数最適化装置に関し、更に詳しくは、ソースプログラムから中間コードを生成し、中間コードからオブジェクトプログラムを生成するコンパイラ、及び、そのようなコンパイラに用いられる変数最適化装置に関する。また、本発明は、コンパイル方法、変数最適化方法、及び、プログラムに関する。   The present invention relates to a compiler and a variable optimization apparatus, and more particularly, a compiler that generates intermediate code from a source program and generates an object program from the intermediate code, and a variable optimization apparatus used for such a compiler. About. The present invention also relates to a compilation method, a variable optimization method, and a program.

近年、CPU(プロセッサ)の動作速度は、ハードウェアの改善などにより、高速化が進んでいる。一方で、メモリアクセスの性能は、CPUの速度の高速化に比べて改善が進んでいない。このため、メモリアクセスの少ないプログラムでは、性能を大きく改善することができるものの、メモリアクセスの多いプログラムは、性能改善の幅が小さい。プログラムの生成に際しては、メモリアクセスが多いプログラムの性能をいかに改善するかが課題となっている。   In recent years, the operating speed of CPUs (processors) has been increasing due to improvements in hardware and the like. On the other hand, the performance of memory access has not been improved compared to the increase in CPU speed. For this reason, a program with little memory access can greatly improve the performance, but a program with many memory accesses has a small range of performance improvement. When generating a program, how to improve the performance of a program with many memory accesses is an issue.

メモリアクセス回数は、ループ融合などのループ変形を行い、共通式の削除により、複数のループに存在している同一メモリへのアクセスを1つにまとめることで、削減可能である。コンパイラにて、このような処理を行い、実行プログラムにおけるメモリアクセスの回数を減らすことで、ソフトウェア的に、性能改善を図ることができる。   The number of memory accesses can be reduced by performing loop transformation such as loop fusion, and by deleting the common expression to combine accesses to the same memory existing in a plurality of loops into one. By performing such processing in the compiler and reducing the number of memory accesses in the execution program, it is possible to improve performance in terms of software.

Fortranなどのプログラムでは、配列式で参照される配列の下限/上限が変数を用いて宣言されることがある。その場合、配列の形状を翻訳時には決定できないので、配列式に対して十分な最適化が行われないことがあった。変数を定数に置き換えてコンパイルする技術の一例が、特許文献1に記載されている。特許文献1では、変数の定義が一度のものを選択して、変数から定数への置換を行っている。
特開平2−118732号公報
In a program such as Fortran, the lower limit / upper limit of an array referred to by an array formula may be declared using a variable. In that case, since the shape of the sequence cannot be determined at the time of translation, the sequence formula may not be sufficiently optimized. An example of a technique for compiling by replacing variables with constants is described in Patent Document 1. In Patent Document 1, a variable that has been defined once is selected, and the variable is replaced with a constant.
JP-A-2-118732

ところで、科学技術計算で広く使われているFortranなどのプログラミング言語では、配列と配列の演算や、演算結果を代入する式を1つの文中に記述することで、配列の要素ごとに演算が可能な配列式が定義されている。図23に、ソースプログラムの一例を示す。式1−1のa(m1:m2)は、配列aの要素a(m1)からa(m2)を含む配列の一部である部分配列を表す。m1は下限、m2は上限と呼ばれている。配列の寸法は、アクセスする配列の要素の数を表す。例えば、a(1:5)の場合、a(1)、a(2)、a(3)、a(4)、a(5)の5つの要素を含むので、配列の寸法は5となる。式1−1は、m1からm2までの要素について、a(m1)=b(m1)+c(m1)、a(m1+1)=b(m1+1)+c(m1+1)のように、配列bと配列cとの要素ごとの加算結果を配列aの各要素に代入することを表す。配列の要素ごとに演算するので、1つの配列式では同じ形状の配列のみを記述するのが通常である。一方、式1−3は、全配列である。式1−3は、xの各要素に、cの部分配列の各要素を代入することを表す。   By the way, programming languages such as Fortran, which are widely used in scientific and engineering calculations, can calculate for each element of an array by describing the calculation of the array and the array, and the expression that assigns the calculation result in one sentence. An array expression is defined. FIG. 23 shows an example of a source program. A (m1: m2) in Formula 1-1 represents a partial array that is a part of the array including elements a (m1) to a (m2) of the array a. m1 is called the lower limit, and m2 is called the upper limit. The dimension of the array represents the number of elements of the array to be accessed. For example, in the case of a (1: 5), since the five elements a (1), a (2), a (3), a (4), and a (5) are included, the size of the array is 5. . In the expression 1-1, for elements from m1 to m2, an array b and an array c are expressed as a (m1) = b (m1) + c (m1) and a (m1 + 1) = b (m1 + 1) + c (m1 + 1). This means that the addition result for each element is assigned to each element of the array a. Since the calculation is performed for each element of the array, it is normal to describe only arrays of the same shape in one array formula. On the other hand, Formula 1-3 is the entire sequence. Expression 1-3 represents substituting each element of the partial array of c for each element of x.

コンパイラは、配列式に対し、その配列式に現れる配列の下限と上限とに基づいて計算した初期値と終値とを持つループを内部的に生成する。コンパイラは、生成したループに対して最適化処理を行い、同じループ回数のループを融合し、共通式を削除することでループ内にある同じ配列要素へのアクセスを削減し、プログラムの高速化を図る。この最適化処理にて、複数のループを融合するためには、翻訳時に、ループの初期値と終値とを元に計算するループの繰り返し回数が同じである必要がある。しかし、Fortranなどのプログラムでは、配列式で参照される配列の下限と上限とが変数を用いて宣言されることがあり、その場合、配列の形状を翻訳時に決定できないために、配列式に対して十分に最適化が行えないことがあった。以下、これについて説明する。   The compiler internally generates a loop having an initial value and a final value calculated based on the lower limit and upper limit of the array appearing in the array expression. The compiler optimizes the generated loop, fuses the same number of loops, and deletes common expressions to reduce access to the same array elements in the loop and speed up the program. Plan. In order to fuse a plurality of loops in this optimization process, the number of loop iterations calculated based on the initial value and the final value of the loop must be the same during translation. However, in programs such as Fortran, the lower and upper bounds of an array referenced in an array expression may be declared using variables. In this case, the shape of the array cannot be determined during translation. In some cases, optimization could not be performed sufficiently. This will be described below.

図24に、図23のソースプログラムから生成される中間コードを示す。図23のソースプログラムに含まれる式1−1〜式1−3、式1−5の配列式は、中間コード生成部により、図24に含まれる4つのループ(do〜enddoまで)に変換される。ループへの変換では、配列が全配列であれば、宣言式における下限と上限とに基づいてループの初期値と終値とを決定し、部分配列の場合は、参照箇所の下限と上限とに基づいて、初期値と終値とを決定する。例えば、配列式1−1は、部分配列(m1:m2)の演算であり、寸法はm2−m1+1であるので、また、配列式1−3は、部分配列c(m1:m2)を含むので、ループの初期値は0に、終値m2−m1に設定される。   FIG. 24 shows intermediate code generated from the source program of FIG. The array formulas of Formula 1-1 to Formula 1-3 and Formula 1-5 included in the source program of FIG. 23 are converted into four loops (from do to enddo) included in FIG. 24 by the intermediate code generation unit. The When converting to a loop, if the array is an entire array, the initial and final values of the loop are determined based on the lower and upper limits in the declaration expression, and in the case of a partial array, based on the lower and upper limits of the reference location. To determine an initial value and a closing price. For example, since the array formula 1-1 is an operation of the partial array (m1: m2) and the size is m2-m1 + 1, and the array formula 1-3 includes the partial array c (m1: m2). The initial value of the loop is set to 0 and the closing value m2-m1.

従来方式では、一つの配列式で参照する全ての配列の次元数と寸法とが同じであることを利用し、その配列式で参照される一つの配列の下限と上限とを元に、ループの初期値と終値を決定していた。例えば、配列式1−3について、配列式1−3で参照する配列の次元数と寸法のみに着目して、ループ回数をm2−m1+1に決定していた。このように、従来方式では、配列式で参照する全ての配列の下限/上限の情報を元にループの初期値と終値を決定していないので、配列の下限や上限が異なる変数や式で定義される場合は、複数の配列式間複数の配列式のループを融合することはできなかった。その結果、共通式削除によってループ内の同じ配列要素へのアクセスまとめることができず、メモリアクセスを削減できなかった。   In the conventional method, using the fact that the dimensions and dimensions of all the arrays referenced in one array formula are the same, based on the lower limit and upper limit of one array referenced in the array formula, The initial value and the closing price were determined. For example, with regard to the array formula 1-3, the loop count is determined as m2-m1 + 1 by paying attention only to the number of dimensions and dimensions of the array referred to in the array formula 1-3. As described above, in the conventional method, the initial value and the final value of the loop are not determined based on the information on the lower limit / upper limit of all the arrays referenced in the array formula. If so, multiple sequence loops could not be fused between multiple sequence formulas. As a result, access to the same array element in the loop cannot be consolidated by deleting the common expression, and memory access cannot be reduced.

例えば、図24では、配列式1−1、1−3のループ回数はm2−m1+1回に、配列式1−2のループ回数はn2−n1+1回に設定される。ここで、配列式1−3に着目すれば、全配列xの寸法と部分配列c(m1:m2)の寸法が同じことから、n2−n1とm2−m1とは等しいことがわかる。この情報を、他の配列式に適用することができれば、配列式1−2のループ回数n2−n1+1は、m2−m1+1に置き換えることが可能となり、3つのループを1つにまとめることが可能である。しかし、従来技術では、このような解析は行わないので、コンパイラは、m2−m1とn2−n1とが同じ値になることを認識できず、ループをまとめることができなかった。   For example, in FIG. 24, the loop count of the array formulas 1-1 and 1-3 is set to m2-m1 + 1 times, and the loop count of the array formula 1-2 is set to n2-n1 + 1 times. Here, paying attention to the array formula 1-3, it can be seen that n2-n1 and m2-m1 are equal since the dimensions of the entire array x and the dimensions of the partial array c (m1: m2) are the same. If this information can be applied to other array formulas, the loop count n2-n1 + 1 in the array formula 1-2 can be replaced with m2-m1 + 1, and three loops can be combined into one. is there. However, in the prior art, since such an analysis is not performed, the compiler cannot recognize that m2-m1 and n2-n1 have the same value, and cannot compile a loop.

変数の定数への置換に関し、特許文献1では、変数の定義が一度のものを選択して、変数から定数への置換を行っている。しかし、特許文献1では、手続き内に定義がない変数を定数に置換することはできない。また、変数を定数に置き換えることのみを行っており、変数同士や式を解析してはいない。このため、ループ回数が、異なる変数や式を用いて定義された場合に、ループ回数が同じであることを認識して、ループの融合を行うことはできない。   Regarding replacement of a variable with a constant, Patent Document 1 selects a variable that has been defined once and performs replacement from the variable to the constant. However, in Patent Document 1, a variable that is not defined in the procedure cannot be replaced with a constant. In addition, only variables are replaced with constants, and variables and expressions are not analyzed. For this reason, when the number of loops is defined using different variables or expressions, it is impossible to recognize that the number of loops is the same and fuse the loops.

本発明は、上記従来技術の問題点を解消し、ループ回数が、異なる変数や式を用いて定義された場合でも、ループ融合が可能なコンパイラ、変数最適化装置、方法、及び、プログラムを提供することを目的とする。   The present invention provides a compiler, a variable optimization device, a method, and a program that can solve the above-described problems of the prior art and can perform loop fusion even when the number of loops is defined using different variables and expressions. The purpose is to do.

本発明の変数最適化装置は、
複数の配列を演算する配列式を含む中間コード読み出し、前記中間コードから、配列式を複数検出する配列式検出部と、
前記配列式検出部で検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定部と、
前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出部と、
前記変数関係確定部で決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出部で前定義式が検出された位置から、前記変数定義検出部で後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換部と、
前記寸法式置換部で置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化部と、
を備えることを特徴とする。
The variable optimization apparatus of the present invention
To read out the intermediate code containing the sequence formula for calculating a plurality of sequences, from the intermediate code, and sequence type detecting unit for detecting a plurality of sequence type,
For each of the plurality of arrays calculated by the plurality of array formulas detected by the array formula detection unit, a dimension formula representing the dimensions of the array is calculated using a variable representing the upper limit and a variable representing the lower limit of the array. The dimension of the first array in which the dimensional expression is calculated using the first variable and the dimension of the second array in which the dimensional expression is calculated using the second variable are: A variable relationship determining unit that determines a relational expression representing a relation of the same dimensions when the array and the second array are operated with the same array formula;
The array formula for calculating the first array and the second array is a position before the array expression detection position detected from the intermediate code, and the value of the first variable or the second variable is A variable definition detection unit that detects a pre-defined formula that detects a pre-defined formula that defines a value of the first variable or the second variable at a position after the sequence formula detection position;
Based on the relational expression determined by the variable relation determination unit, from the position where the pre-defined expression is detected by the variable definition detection part among the dimensional expressions of the plurality of arrays respectively calculated by the plurality of array formulas , The dimension formula of the array calculated by the array formula detected at the position up to the position where the post-definition formula is detected by the variable definition detection unit, and the dimension formula calculated using the first variable, A dimensional formula replacement unit that replaces the dimensional formula calculated using the second variable;
In accordance with each of the plurality of array formulas for calculating the array of dimensions represented by the same dimension formula as the dimension formula replaced by the dimension formula replacement unit, each of the loop processes that are repeatedly executed is common to the plurality of loop processes. An optimization unit that performs a loop optimization that deletes the common arithmetic expression and fuses the plurality of loop processes;
It is characterized by providing .

本発明のコンパイラは、
コンピュータを、
複数の配列を演算する配列式を含む中間コードを読み出し、前記中間コードから、配列式を複数検出する配列式検出部、
前記配列式検出部で検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定部、
前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出部、
前記変数関係確定部で決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出部で前定義式が検出された位置から、前記変数定義検出部で後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換部、
前記寸法式置換部で置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化部、
前記最適化部でループ最適化された中間コードに基づいて、オブジェクトプログラムを生成するコード生成部、
として機能させることを特徴とする。
The compiler of the present invention
Computer
To read out the intermediate code containing the sequence formula for calculating a plurality of sequences, wherein the intermediate code, sequence type detecting unit detecting a plurality of sequence type,
For each of the plurality of arrays calculated by the plurality of array formulas detected by the array formula detection unit, a dimension formula representing the dimensions of the array is calculated using a variable representing the upper limit and a variable representing the lower limit of the array. The dimension of the first array in which the dimensional expression is calculated using the first variable and the dimension of the second array in which the dimensional expression is calculated using the second variable are: A variable relationship determining unit that determines a relational expression representing a relation of the same dimensions when the array and the second array are operated with the same array formula;
The array formula for calculating the first array and the second array is a position before the array expression detection position detected from the intermediate code, and the value of the first variable or the second variable is A variable definition detecting unit that detects a pre-defined formula that detects a pre-defined formula that defines a value of the first variable or the second variable at a position after the sequence formula detected position;
Based on the relational expression determined by the variable relation determination unit, from the position where the pre-defined expression is detected by the variable definition detection part among the dimensional expressions of the plurality of arrays respectively calculated by the plurality of array formulas , The dimension formula of the array calculated by the array formula detected at the position up to the position where the post-definition formula is detected by the variable definition detection unit, and the dimension formula calculated using the first variable, A dimension formula replacement unit that replaces the dimension formula calculated using the second variable;
In accordance with each of the plurality of array formulas for calculating the array of dimensions represented by the same dimension formula as the dimension formula replaced by the dimension formula replacement unit, each of the loop processes that are repeatedly executed is common to the plurality of loop processes. An optimization unit that performs a loop optimization that deletes the common arithmetic expression and fuses the plurality of loop processes,
A code generation unit for generating an object program based on the intermediate code loop-optimized by the optimization unit;
It is made to function as .

本発明の変数最適化方法は、
コンピュータが、複数の配列を演算する配列式を含む中間コードを読み出し、前記中間コードから、配列式を複数検出する配列式検出ステップと、
前記コンピュータが、前記配列式検出ステップで検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定ステップと、
前記コンピュータが、前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出ステップと、
前記コンピュータが、前記変数関係確定ステップで決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出ステップで前定義式が検出された位置から、前記変数定義検出ステップで後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換ステップと、
前記コンピュータが、前記寸法式置換ステップで置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化ステップと、
を有することを特徴とする。
The variable optimization method of the present invention includes:
Computer, to read out the intermediate code containing the sequence formula for calculating a plurality of sequences, from the intermediate code, and sequence type detecting step of detecting a plurality of sequence type,
For each of the plurality of arrays each calculated by the plurality of array formulas detected in the array formula detection step, the computer expresses a dimension formula representing the dimensions of the array as a variable representing the upper limit and a variable representing the lower limit. calculated using the dimensions of the first array dimension expression is calculated using the first variable, a dimension of the second sequence size equation using the second variable is calculated, it is A variable relationship determination step for determining a relational expression representing a relation of the same dimensions when the first array and the second array are operated with the same array formula;
The computer is configured to calculate the first array and the second array at a position before the array expression detection position detected from the intermediate code, and the first variable or the second array Variable definition detection that detects a pre-defined expression that defines a value of a variable and detects a post-defined expression that defines the value of the first variable or the second variable at a position after the position of detecting the array expression Steps,
Based on the relational expression determined in the variable relation determining step, the computer detects a pre-defined expression in the variable definition detecting step among a plurality of array dimensional expressions respectively calculated in the plurality of array formulas. Dimensional expression of the array calculated by the array expression detected at the position from the position to the position where the post-definition expression is detected at the variable definition detection step, calculated using the first variable A dimension formula replacing step for replacing the dimension formula with a dimension formula calculated using the second variable;
The plurality of loops from a plurality of loop processes repeatedly executed according to each of the plurality of array formulas, wherein the computer calculates an array of dimensions represented by the same dimension formula as the dimension formula replaced in the dimension formula replacing step. An optimization step for performing a loop optimization that deletes a common arithmetic expression common to the processes and fuses the plurality of loop processes;
It is characterized by having .

本発明のコンパイル方法は、
コンピュータが、複数の配列を演算する配列式を含む中間コードを読み出し、前記中間コードから、配列式を複数検出する配列式検出ステップと、
前記コンピュータが、前記配列式検出ステップで検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定ステップと、
前記コンピュータが、前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出ステップと、
前記コンピュータが、前記変数関係確定ステップで決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出ステップで前定義式が検出された位置から、前記変数定義検出ステップで後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換ステップと、
前記コンピュータが、前記寸法式置換ステップで置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化ステップと、
前記コンピュータが、前記最適化ステップでループ最適化された中間コードに基づいて、オブジェクトプログラムを生成するコード生成ステップと、
を有することを特徴とする。
The compiling method of the present invention
Computer, to read out the intermediate code containing the sequence formula for calculating a plurality of sequences, from the intermediate code, and sequence type detecting step of detecting a plurality of sequence type,
For each of the plurality of arrays each calculated by the plurality of array formulas detected in the array formula detection step, the computer expresses a dimension formula representing the dimensions of the array as a variable representing the upper limit and a variable representing the lower limit. calculated using the dimensions of the first array dimension expression is calculated using the first variable, a dimension of the second sequence size equation using the second variable is calculated, it is A variable relationship determination step for determining a relational expression representing a relation of the same dimensions when the first array and the second array are operated with the same array formula;
The computer is configured to calculate the first array and the second array at a position before the array expression detection position detected from the intermediate code, and the first variable or the second array Variable definition detection that detects a pre-defined expression that defines a value of a variable and detects a post-defined expression that defines the value of the first variable or the second variable at a position after the position of detecting the array expression Steps,
Based on the relational expression determined in the variable relation determining step, the computer detects a pre-defined expression in the variable definition detecting step among a plurality of array dimensional expressions respectively calculated in the plurality of array formulas. Dimensional expression of the array calculated by the array expression detected at the position from the position to the position where the post-definition expression is detected at the variable definition detection step, calculated using the first variable A dimension formula replacing step for replacing the dimension formula with a dimension formula calculated using the second variable;
The plurality of loops from a plurality of loop processes repeatedly executed according to each of the plurality of array formulas, wherein the computer calculates an array of dimensions represented by the same dimension formula as the dimension formula replaced in the dimension formula replacing step. An optimization step for performing a loop optimization that deletes a common arithmetic expression common to the processes and fuses the plurality of loop processes;
A code generation step in which the computer generates an object program based on the intermediate code loop-optimized in the optimization step;
It is characterized by having .

本発明の変数最適化プログラムは、
コンピュータを、
複数の配列を演算する配列式を含む中間コードを読み出し、前記中間コードから、配列式を複数検出する配列式検出部、
前記配列式検出部で検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定部、
前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出部、
前記変数関係確定部で決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出部で前定義式が検出された位置から、前記変数定義検出部で後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換部、
前記寸法式置換部で置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化部、
として機能させることを特徴とする。
The variable optimization program of the present invention is:
Computer
To read out the intermediate code containing the sequence formula for calculating a plurality of sequences, wherein the intermediate code, sequence type detecting unit detecting a plurality of sequence type,
For each of the plurality of arrays calculated by the plurality of array formulas detected by the array formula detection unit, a dimension formula representing the dimensions of the array is calculated using a variable representing the upper limit and a variable representing the lower limit of the array. The dimension of the first array in which the dimensional expression is calculated using the first variable and the dimension of the second array in which the dimensional expression is calculated using the second variable are: A variable relationship determining unit that determines a relational expression representing a relation of the same dimensions when the array and the second array are operated with the same array formula;
The array formula for calculating the first array and the second array is a position before the array expression detection position detected from the intermediate code, and the value of the first variable or the second variable is A variable definition detecting unit that detects a pre-defined formula that detects a pre-defined formula that defines a value of the first variable or the second variable at a position after the sequence formula detected position;
Based on the relational expression determined by the variable relation determination unit, from the position where the pre-defined expression is detected by the variable definition detection part among the dimensional expressions of the plurality of arrays respectively calculated by the plurality of array formulas , The dimension formula of the array calculated by the array formula detected at the position up to the position where the post-definition formula is detected by the variable definition detection unit, and the dimension formula calculated using the first variable, A dimension formula replacement unit that replaces the dimension formula calculated using the second variable;
In accordance with each of the plurality of array formulas for calculating the array of dimensions represented by the same dimension formula as the dimension formula replaced by the dimension formula replacement unit, each of the loop processes that are repeatedly executed is common to the plurality of loop processes. An optimization unit that performs a loop optimization that deletes the common arithmetic expression and fuses the plurality of loop processes,
It is made to function as .

本発明のコンパイラ、変数最適化装置、方法、及び、プログラムでは、ループ回数が、異なる変数や式を用いて定義された場合でも、ループ融合が可能である。   In the compiler, variable optimization device, method, and program of the present invention, loop fusion is possible even when the number of loops is defined using different variables and expressions.

以下、図面を参照し、本発明の実施の形態を詳細に説明する。図1は、本発明の第1実施形態のコンパイラを示している。コンパイラ10は、中間コード生成部11、変数最適化部12、最適化部13、及び、コード生成部14を有する。コンパイラは、Fortranなどのプログラムを翻訳しロードモジュールを生成する。コンパイラの各部の機能は、コンピュータ上で所定プログラムを実行することで、実現できる。   Hereinafter, embodiments of the present invention will be described in detail with reference to the drawings. FIG. 1 shows a compiler according to the first embodiment of the present invention. The compiler 10 includes an intermediate code generation unit 11, a variable optimization unit 12, an optimization unit 13, and a code generation unit 14. The compiler translates a program such as Fortran and generates a load module. The function of each part of the compiler can be realized by executing a predetermined program on a computer.

ソースプログラム31は、Fortranなどの所定のプログラミング言語で記述されたプログラムのソースである。ソースプログラム31は、メモリなどに記憶されている。中間コード生成部11は、ソースプログラム31を読み出し、ソースプログラム31に基づいて中間コード32を生成する。生成した中間コード32は、メモリなどに記憶する。   The source program 31 is a source of a program written in a predetermined programming language such as Fortran. The source program 31 is stored in a memory or the like. The intermediate code generation unit 11 reads the source program 31 and generates an intermediate code 32 based on the source program 31. The generated intermediate code 32 is stored in a memory or the like.

変数最適化部12は、中間コード32を読み出し、中間コード32における変数の最適化処理を行い、中間コード36を生成する。生成した中間コード36は、メモリなどに記憶する。最適化部13は、中間コード36に対して、ベクトル化や、並列化、ループ最適化、共通式の削除などを行う。最適化部13が行う処理は、少なくとも同一ループ回数のループをまとめるループ最適化と、共通式の削除を含むものとする。最適化部13は、ループ最適化などを行った結果の中間コード37を、メモリなどに記憶する。   The variable optimization unit 12 reads the intermediate code 32, performs variable optimization processing in the intermediate code 32, and generates an intermediate code 36. The generated intermediate code 36 is stored in a memory or the like. The optimization unit 13 performs vectorization, parallelization, loop optimization, common expression deletion, and the like on the intermediate code 36. The processing performed by the optimizing unit 13 includes at least loop optimization for grouping loops having the same number of loops and deletion of common expressions. The optimization unit 13 stores the intermediate code 37 as a result of the loop optimization or the like in a memory or the like.

コード生成部14は、最適化部13により最適化された中間コード37を読み出し、中間コード37に基づいて、オブジェクトプログラム38を生成する。生成したオブジェクトプログラム38は、メモリや保持記憶装置などに記憶する。中間コード生成部11、最適化部13、及び、コード生成部14には、それぞれ既存の中間コード生成手段、最適化手段、コード生成手段を用いることができる。   The code generation unit 14 reads the intermediate code 37 optimized by the optimization unit 13 and generates an object program 38 based on the intermediate code 37. The generated object program 38 is stored in a memory or a holding storage device. As the intermediate code generation unit 11, the optimization unit 13, and the code generation unit 14, existing intermediate code generation means, optimization means, and code generation means can be used, respectively.

変数最適化部12は、宣言情報・配列式検出手段21、参照配列検出手段22、変数関係確定手段23、変数定義検出手段24、及び、変数置換手段25を有する。宣言情報・配列式検出手段21は、中間コード32を検索して、配列の宣言情報と配列式とを検出し、宣言情報テーブル、配列式テーブル33に登録する。参照配列検出手段22は、配列式テーブルに登録されている配列式に対し、各配列式で参照している配列を調べ、各配列について、配列の種類(全配列/部分配列)、配列の下限及び上限を、参照配列テーブル34に登録する。配列の上限及び下限は、配列が全配列であれば、宣言情報テーブルに登録されている下限及び上限であり、配列が部分配列であれば、参照箇所における下限及び上限である。   The variable optimization unit 12 includes declaration information / array expression detection means 21, reference array detection means 22, variable relationship determination means 23, variable definition detection means 24, and variable replacement means 25. The declaration information / array expression detection means 21 searches the intermediate code 32 to detect array declaration information and array expressions, and registers them in the declaration information table and array expression table 33. The reference sequence detection means 22 checks the sequence referred to in each sequence formula with respect to the sequence formula registered in the sequence formula table, and for each sequence, the type of sequence (full sequence / partial sequence), the lower limit of the sequence And the upper limit are registered in the reference sequence table 34. The upper limit and lower limit of the array are the lower limit and the upper limit registered in the declaration information table if the array is an entire array, and the lower limit and the upper limit at the reference location if the array is a partial array.

変数関係確定手段23は、参照配列テーブル34を参照して、配列の下限及び上限に基づいて配列の寸法を計算し、同一配列式内の配列の各次元の寸法が同じであることを利用して、寸法の計算に用いる変数や式の値を決定する。値が決定しない場合には、他の変数や式との関係を決定する。例えば、下限/上限がn1/n2である配列と、下限/上限がm1/m2である配列とが同一配列式で参照される場合には、双方の寸法が同じであることを利用して、両者の関係式をn2−n1=m2−m1と決定する。変数関係確定手段23は、決定した値又は関係を表す関係式と、その関係を決定した配列式である決定式とを、確定変数テーブル35に登録する。   The variable relationship determining means 23 refers to the reference array table 34, calculates the dimensions of the array based on the lower limit and the upper limit of the array, and utilizes the fact that the dimensions of the arrays in the same array formula are the same. To determine the values of variables and formulas used to calculate dimensions. If the value is not determined, the relationship with other variables and expressions is determined. For example, when a sequence having a lower limit / upper limit of n1 / n2 and a sequence having a lower limit / upper limit of m1 / m2 are referred to in the same sequence formula, the fact that both dimensions are the same, The relational expression between them is determined as n2-n1 = m2-m1. The variable relationship determining unit 23 registers a relational expression representing the determined value or relationship and a determination expression that is an array expression that has determined the relation in the fixed variable table 35.

変数定義検出手段24は、確定変数テーブル35に登録されている決定式を起点に、前後の中間コード32を検索し、確定変数テーブル35に登録される関係式が、部分配列の下限又は上限に表れる変数を参照しているか否かを調べる。参照している場合は、決定式の前後で、関係式で参照する変数を定義する式を検索し、決定式よりも前で変数を定義する式(前定義式)と、後ろで変数を定義する式(後定義式)とを検出する。変数定義検出手段24は、検出した前定義式及び後定義式を、確定変数テーブル35に登録する。前定義式及び後定義式がそれぞれ複数検出される場合は、実行経路において決定式の最も近くで実行される可能性がある式を登録する。定義する式が存在しない場合は、確定変数テーブル35の前定義式又は後定義式に、NULLを登録する。全配列の宣言式で使用する変数のみ参照する場合は、確定変数テーブル35の前定義式及び後定義式にNULLを登録する。   The variable definition detection unit 24 searches the intermediate code 32 before and after the determination formula registered in the fixed variable table 35 as a starting point, and the relational expression registered in the fixed variable table 35 is the lower limit or upper limit of the partial array. Check if it refers to a variable that appears. If they are referenced, search for the expression that defines the variable referenced by the relational expression before and after the decision expression, and define the variable that defines the variable before the decision expression (pre-defined expression) and the variable after it. And an expression (post-definition expression) to be detected. The variable definition detecting unit 24 registers the detected pre-defined formula and post-defined formula in the fixed variable table 35. When a plurality of pre-defined formulas and post-defined formulas are detected, a formula that may be executed in the execution path closest to the decision formula is registered. If there is no expression to be defined, NULL is registered in the pre-defined expression or post-defined expression of the definite variable table 35. When only the variables used in the declaration expressions of all the arrays are referred to, NULL is registered in the pre-defined expression and the post-defined expression of the defined variable table 35.

変数置換手段25は、中間コード32を検索し、前定義式と後定義式との間で、確定変数テーブル35に登録された関係式の右辺又は左辺(以下では、左辺として説明する)を参照する箇所を検出し、これを、関係式の右辺で置換する。検索では、前定義式がNULLの場合には先頭から後定義式との間を検索し、後定義式がNULLの場合は前定義式から最後までを検索する。例えば、関係式がn2−n1=m2−m1であれば、中間コード32にて、前定義式と後定義式との間に、n2−n1が存在すれば、これを、m2−m1に置換する。変数置換手段25は、置換した結果を、中間コード36として出力する。   The variable replacement means 25 searches the intermediate code 32 and refers to the right side or the left side (hereinafter, described as the left side) of the relational expression registered in the defined variable table 35 between the pre-defined formula and the post-defined formula. A place to be detected is detected, and this is replaced with the right side of the relational expression. In the search, when the pre-defined formula is NULL, the search is performed from the beginning to the post-defined formula, and when the post-defined formula is NULL, the search is performed from the pre-defined formula to the end. For example, if the relational expression is n2-n1 = m2-m1, if n2-n1 exists between the pre-defined expression and the post-defined expression in the intermediate code 32, it is replaced with m2-m1. To do. The variable replacement unit 25 outputs the replacement result as an intermediate code 36.

変数最適化部12が生成した中間コード36は、最適化部13にて、ループの最適化や共通式の削除などの最適化が適用され、中間コード36に比して、メモリアクセスが削減された中間コード37が得られる。コード生成部14にて、中間コード37からオブジェクトプログラム38を生成することで、中間コード生成部11が生成した中間コード32に対して最適化部13にて最適化を行った中間コードからオブジェクトプログラムを生成した場合に比して、メモリアクセスが削減されたプログラムが得られる。   The intermediate code 36 generated by the variable optimizing unit 12 is subjected to optimization such as loop optimization and common expression deletion in the optimizing unit 13, and memory access is reduced compared to the intermediate code 36. Intermediate code 37 is obtained. By generating the object program 38 from the intermediate code 37 in the code generation unit 14, the object program is generated from the intermediate code that has been optimized by the optimization unit 13 with respect to the intermediate code 32 generated by the intermediate code generation unit 11. As compared with the case of generating the program, a program with reduced memory access can be obtained.

図2に、変数最適化部12の動作手順を示す。宣言情報・配列式検出手段21は、中間コード32を検索し、配列の宣言情報と、配列式とを検出して、これらを、宣言情報テーブル、配列式テーブル33に登録する(ステップS1)。図3及び図4に、それぞれ、宣言情報テーブル及び配列式テーブルのデータ例を示す。図23に示すソースプログラム31に対応する中間コード32から、配列の宣言情報を検出することで、配列a、b、c、d、e、x、y、zが宣言情報テーブルに登録される(図3)。また、中間コード32から、配列式を検出することで、図23の配列式1−1〜1−3、1−5に対応する配列式が配列式テーブルに登録される(図4)。   FIG. 2 shows an operation procedure of the variable optimization unit 12. The declaration information / array expression detecting means 21 searches the intermediate code 32, detects the array declaration information and the array expression, and registers them in the declaration information table and the array expression table 33 (step S1). 3 and 4 show data examples of the declaration information table and the array formula table, respectively. By detecting the declaration information of the array from the intermediate code 32 corresponding to the source program 31 shown in FIG. 23, the arrays a, b, c, d, e, x, y, and z are registered in the declaration information table ( FIG. 3). Further, by detecting an array formula from the intermediate code 32, array formulas corresponding to the array formulas 1-1 to 1-3 and 1-5 of FIG. 23 are registered in the array formula table (FIG. 4).

参照配列検出手段22は、配列式テーブルに登録されている各配列式に対して、参照配列テーブル34を作成し、各参照配列テーブルに、各配列式で参照している配列の配列名、配列の形状、配列の種別(全配列/部分配列)を登録する(ステップS2)。形状(下限:上限)については、配列が全配列であれば、宣言情報テーブルに登録されている下限と上限を登録し、部分配列であれば、参照箇所における下限と上限を登録する。図5(a)〜(d)に、参照配列テーブルのデータ例を示す。図4に示す配列式テーブルを参照すると、中間コード32には4つの配列式(配列式1−1〜1−3、1−5)があるので、これらに対応して、参照配列テーブルを作成する(図5(a)〜(d))。   The reference sequence detection means 22 creates a reference sequence table 34 for each sequence formula registered in the sequence formula table, and the array name and sequence of the sequence referenced by each sequence formula are stored in each reference sequence table. And the type of array (full array / partial array) are registered (step S2). For the shape (lower limit: upper limit), if the array is an entire array, the lower limit and the upper limit registered in the declaration information table are registered. If the array is a partial array, the lower limit and the upper limit at the reference location are registered. 5A to 5D show data examples of the reference sequence table. Referring to the array formula table shown in FIG. 4, there are four array formulas (array formulas 1-1 to 1-3 and 1-5) in the intermediate code 32, so a reference sequence table is created corresponding to these. (FIGS. 5A to 5D).

ステップS2では、式1−1に対しては配列a、b、cを(図5(a))、式1−2に対しては配列c、d、eを(図5(b))、式1−3に対してはc、xを(図5(c))、式1−5に対してはy、zを(図5(d))、それぞれ参照配列テーブルに登録する。また、式1−3の配列xに対しては全配列である旨を登録し、それ以外の配列に対しては、部分配列である旨を登録する。全配列であるxについては、宣言情報テーブルに登録されている形状(n1:n2)を参照配列テーブル34に登録し、その他の配列については、参照箇所の形状を参照配列テーブル34に登録する。例えば、図23を参照すると、式1−1の配列aの参照箇所はm1からm2であるので、式1−1に対する参照配列テーブルには、配列aの形状として、(m1:m2)を登録する。   In step S2, arrays a, b, and c are set for expression 1-1 (FIG. 5A), and arrays c, d, and e are set for expression 1-2 (FIG. 5B), C and x are registered in the reference sequence table for Expression 1-3 (FIG. 5C), and y and z are stored for Expression 1-5 (FIG. 5D). In addition, the fact that the array is the entire array is registered for the array x in Formula 1-3, and the fact that it is a partial array is registered for the other arrays. For x, which is the entire array, the shape (n1: n2) registered in the declaration information table is registered in the reference array table 34, and for other arrays, the shape of the reference location is registered in the reference array table 34. For example, referring to FIG. 23, since the reference location of the array a in Expression 1-1 is m1 to m2, (m1: m2) is registered as the shape of the array a in the reference array table for Expression 1-1. To do.

変数関係確定手段23は、参照配列テーブル34を参照して、各配列式における配列の下限と上限とから寸法を計算し、同一配列式内では配列の各次元の寸法が同じであることを利用して、寸法の計算で参照する変数や式の値を決定する。例えば、同一参照配列テーブル内にて、形状が2つの変数で定められる配列と、2つの定数で定められる配列とが存在するときは、配列の寸法が同じであることを利用して、両者の関係から変数の定数化が可能である。値が決定しないときは、他の変数や式との関係を決定する。例えば、同一参照配列テーブル内で、形状が2つの変数で定められる配列と、これとは異なる2つの変数で定められる別の配列とがあるときは、両者の寸法が同じであることを利用して、4つの変数間の関係式を導き出すことができる。変数関係確定手段23は、決定した値又は関係を表す関係式と、その関係を決定した配列式である決定式とを、確定変数テーブル35に登録する(ステップS3)。   The variable relationship determining means 23 refers to the reference sequence table 34, calculates the size from the lower limit and the upper limit of the array in each array formula, and utilizes the fact that the dimensions of each array in the same array formula are the same. Then, the values of variables and expressions to be referred to in the dimension calculation are determined. For example, in the same reference sequence table, when there are an array whose shape is defined by two variables and an array defined by two constants, using the fact that the dimensions of the arrays are the same, Variables can be made constant from the relationship. When the value is not determined, the relationship with other variables and expressions is determined. For example, in the same reference sequence table, when there is an array whose shape is defined by two variables and another array whose shape is defined by two different variables, the fact that both dimensions are the same is used. Thus, the relational expression between the four variables can be derived. The variable relationship determining unit 23 registers a relational expression representing the determined value or relationship and a determination expression that is an array expression that has determined the relation in the fixed variable table 35 (step S3).

図6に、確定変数テーブル35のデータ例を示す。式1−1、1−2、1−5に対応する参照配列テーブル(図5(a)、(b)、(d))を参照すると、これらでは、形状が同じ変数(m1、m2又はn1、n2)で定義されるので、これらから決定できる値又は関係式はない。式1−3に対応する参照配列テーブル(図5(c))を参照すると、配列xの形状は(n1:n2)で、配列cの形状(参照箇所)は(m1:m2)となっている。両者の形状が等しいことを利用すると、n1−n2=m1−m2という関係式が得られる。変数関係確定手段23は、得られた関係式「n1−n2=m1−m2」と、関係式を決定した配列式「1−3」とを、確定変数テーブル35に登録する。   FIG. 6 shows an example of data in the definite variable table 35. Referring to the reference sequence tables (FIGS. 5A, 5B, and 5D) corresponding to the expressions 1-1, 1-2, and 1-5, in these, variables (m1, m2, or n1 having the same shape) , N2), there is no value or relational expression that can be determined from these. Referring to the reference sequence table corresponding to Equation 1-3 (FIG. 5C), the shape of the array x is (n1: n2), and the shape (reference location) of the array c is (m1: m2). Yes. Using the fact that both shapes are equal, a relational expression of n1-n2 = m1-m2 is obtained. The variable relationship determining unit 23 registers the obtained relational expression “n1-n2 = m1-m2” and the array formula “1-3” for which the relational expression is determined in the fixed variable table 35.

変数定義検出手段24は、確定変数テーブル35に登録されている決定式の前後の中間コード32を検索し、決定式によって決定される関係式が、部分配列の下限/上限に表れる変数を参照しているか否かを判断する。参照している場合は、決定式の前後で、関係式で参照する変数を定義する式を検索する。変数定義検出手段24は、検索により得られた、決定式の前で変数を定義する式を前定義式として確定変数テーブル35に登録し、決定式の後ろで変数を定義する式を後定義式として確定変数テーブル35に登録する(ステップS4)。検索にて、前定義式又は後定義式が複数検索された場合は、実行経路において決定式の最も近くで実行される可能性がある式を登録する。前定義式及び後定義式がない場合は、確定変数テーブル35にNULLを登録する。また、決定式によって決定される関係式が、部分配列の下限/上限に現れる変数を参照していない場合は、確定変数テーブル35にNULLを登録する。   The variable definition detection unit 24 searches the intermediate code 32 before and after the determination formula registered in the definite variable table 35, and refers to the variable in which the relational expression determined by the determination formula appears in the lower limit / upper limit of the partial array. Judge whether or not. If it is referenced, search for an expression that defines a variable referenced by the relational expression before and after the decision expression. The variable definition detection means 24 registers the expression that defines the variable before the decision formula obtained in the search as a pre-defined formula in the fixed variable table 35, and the formula that defines the variable after the decision formula is the post-defined formula. Is registered in the definite variable table 35 (step S4). When a plurality of pre-defined formulas or post-defined formulas are searched in the search, the formula that may be executed closest to the decision formula in the execution path is registered. If there are no pre-defined formula and post-defined formula, NULL is registered in the definite variable table 35. If the relational expression determined by the determination formula does not refer to a variable appearing at the lower limit / upper limit of the partial array, NULL is registered in the defined variable table 35.

図23に示すソースプログラムにて、決定式「1−3」によって決定される関係式「n2−n1=m2−m1」が、部分配列の下限/上限に現れる変数を参照しているか否かを調べると、配列式1−1、1−2、1−5で、関係式が、部分配列の下限/上限に現れる変数を参照している。決定式の前後で、関係式で参照する変数を定義する式を検索すると、決定式よりも後の式1−4で、n2の値を定義している。決定式の前で定義する存在していない。従って、変数定義検出手段24は確定変数テーブル35の後定義式に式1−4を登録し、前定義式にNULLを登録する。   Whether or not the relational expression “n2-n1 = m2-m1” determined by the determination formula “1-3” refers to a variable appearing at the lower limit / upper limit of the partial sequence in the source program shown in FIG. When examined, the relational expressions refer to variables appearing at the lower limit / upper limit of the partial array in the array formulas 1-1, 1-2, and 1-5. When an expression that defines a variable to be referred to by a relational expression is searched before and after the determination expression, the value of n2 is defined by Expression 1-4 after the determination expression. Does not exist to define before the determinant. Therefore, the variable definition detection unit 24 registers Formula 1-4 in the post-definition formula of the definite variable table 35 and registers NULL in the pre-definition formula.

決定式よりも前に、関係式の変数を定義する式がある場合、前定義式よりも前では、関係式で定義される関係をそのまま用いることができるかどうかは不明である。同様に、決定式よりも後ろに、関係式の変数を定義する式がある場合は、その後定義式以降で、関係式で定義される関係を適用可能かどうかは不明である。従って、関係式を用いることができる範囲は、中間コード32において、前定義式と後定義式とに挟まれた範囲となる。図23では、配列式1−1、1−2、1−5で、関係式が、部分配列の下限/上限に現れる変数を参照しているが、これらのうち、配列式1−5は、後定義式よりも後なので、関係式を適用可能なのは、配列式1−1、1−2ということになる。   If there is an expression that defines a variable of the relational expression before the decision expression, it is unclear whether the relation defined by the relational expression can be used as it is before the previous definition expression. Similarly, if there is an expression that defines a variable of a relational expression after the determination formula, it is unclear whether the relation defined by the relational expression can be applied after the definition formula. Therefore, the range in which the relational expression can be used is a range sandwiched between the pre-defined formula and the post-defined formula in the intermediate code 32. In FIG. 23, in the array formulas 1-1, 1-2, and 1-5, the relational expression refers to a variable that appears at the lower limit / upper limit of the partial array. Since it is after the post-defining formula, the relational formula can be applied to the array formulas 1-1 and 1-2.

変数置換手段25は、確定変数テーブル35と参照配列テーブル34とを参照しながら中間コード32を検索し、前定義式と後定義式との間で、確定変数テーブル35に登録された関係式の左辺に該当する部分を検出し、その部分を、右辺で置換する(ステップS5)。値が決定しているときは、その値で置換する。検索は、前定義式がNULLであれば、中間コードの先頭から後定義式までの範囲で行い、後定義式がNULLであれば、前定義式から中間コードの最後までの範囲で行う。変数置換手段25は、置換後、中間コード36を出力する。   The variable replacement unit 25 searches the intermediate code 32 while referring to the fixed variable table 35 and the reference array table 34, and the relational expression registered in the fixed variable table 35 between the pre-defined formula and the post-defined formula. A part corresponding to the left side is detected, and the part is replaced with the right side (step S5). If a value has been determined, replace it with that value. If the pre-defined formula is NULL, the search is performed in the range from the beginning of the intermediate code to the post-defined formula, and if the post-defined formula is NULL, the search is performed in the range from the pre-defined formula to the end of the intermediate code. The variable replacement means 25 outputs the intermediate code 36 after the replacement.

図7に、変数最適化部12で変数最適化を行った後の中間コード36を示す。変数最適化前の中間コード32は、図24に示す通りであり、配列式1−1〜1−3がそれぞれ独立したループとなっている。それぞれのループ回数は、m2−m1+1回、n2−n1+1回、m2−m1+1回である。ステップS5では、関係式「n2−n1=m2−m1」を用いて、中間コード32にて先頭から式1−4までの範囲で、n2−n1で表される部分を、m2−m1で置き換える。これにより、図7に示す中間コード36が得られる。   FIG. 7 shows the intermediate code 36 after the variable optimization unit 12 performs variable optimization. The intermediate code 32 before variable optimization is as shown in FIG. 24, and the array formulas 1-1 to 1-3 are independent loops. The number of loops is m2-m1 + 1 times, n2-n1 + 1 times, and m2-m1 + 1 times. In step S5, the relational expression “n2-n1 = m2-m1” is used to replace the portion represented by n2-n1 with m2-m1 in the intermediate code 32 in the range from the beginning to Expression 1-4. . Thereby, the intermediate code 36 shown in FIG. 7 is obtained.

図8に、上記中間コード36に対してループ最適化や共通式の削除を行った中間コード37を示す。図7に示す中間コード36に対して、最適化部13にてループ最適化や共通式の削除を行うことで、メモリアクセスが削減された中間コード37が得られる(図8)。すなわち、配列式1−1〜1−3が、1つのループの中に記述された中間コード37が得られる。その後、中間コード37に対して、コード生成部14にてオブジェクトプログラム38を生成することで、メモリアクセスが削減され、高速化されたプログラムが得られる。   FIG. 8 shows an intermediate code 37 obtained by performing loop optimization and common expression deletion on the intermediate code 36. The intermediate code 37 shown in FIG. 7 is obtained by performing the loop optimization and the deletion of the common expression in the optimization unit 13 to obtain the intermediate code 37 with reduced memory access (FIG. 8). That is, the intermediate code 37 in which the array formulas 1-1 to 1-3 are described in one loop is obtained. Thereafter, an object program 38 is generated by the code generation unit 14 for the intermediate code 37, so that a memory access is reduced and a high-speed program is obtained.

図9に、実行されるメモリアクセスと演算とを示す。また、比較例として、図10に、図24に示す中間コードからオブジェクトプログラムを生成した場合に実行されるメモリアクセスと演算とを示す。図9及び図10において、矢印で表される部分がメモリアクセスを表している。図24の中間コードからオブジェクトプログラムを生成した場合、メモリアクセス回数は、5(m2−m1+1)+3(n2−n1+1)+2(10−n1+1)回となる。これは、m2−m1=n2−n1なので、8(m2−m1+1)+2(10−n1+1)と書き直すことができる。これに対し、図8に示す中間コードからオブジェクトプログラムを生成した場合のメモリアクセス回数は、7(m2−m1+1)+2(10−n1+1)回となる。従って、変数最適化処理を行うことで、メモリアクセス回数を(m2−m1+1)回減らすことができ、その分だけ、プログラム実行を高速化できる。   FIG. 9 shows the memory access and operation to be executed. As a comparative example, FIG. 10 shows memory access and calculation executed when an object program is generated from the intermediate code shown in FIG. In FIGS. 9 and 10, a portion indicated by an arrow represents a memory access. When the object program is generated from the intermediate code of FIG. 24, the number of memory accesses is 5 (m2-m1 + 1) +3 (n2-n1 + 1) +2 (10-n1 + 1) times. Since m2−m1 = n2−n1, this can be rewritten as 8 (m2−m1 + 1) +2 (10−n1 + 1). On the other hand, the number of memory accesses when the object program is generated from the intermediate code shown in FIG. 8 is 7 (m2−m1 + 1) +2 (10−n1 + 1) times. Therefore, by performing variable optimization processing, the number of memory accesses can be reduced by (m2−m1 + 1) times, and the program execution can be speeded up by that amount.

本実施形態では、変数関係確定手段23にて、同一配列式を構成する配列の各次元の寸法が同じであることを利用して、配列式で参照される各配列の下限/上限を定義する変数又は式の値を決定し、又は、変数間の関係式を決定する。値が決定する場合、全配列であれば手続内の配列宣言で使用する変数の値を決定でき、部分配列であれば参照箇所を決定する変数や式の値を決定できる。値が決定しないときは、他の変数や式との関係を決定する。部分配列に対しては、決定した値又は関係が他の式で変更されるか否かを解析し、決定した値又は関係が適用可能な範囲を求めておく。その後、変数置換手段25にて、決定した値により、変数や式を定数化する。また、決定した関係式を用いて、変数や式を、同じ変数又は同じ式に置換する。   In the present embodiment, the variable relationship determination unit 23 defines the lower limit / upper limit of each array referred to in the array formula using the fact that the dimensions of the arrays constituting the same array formula are the same. Determine the value of a variable or expression, or determine the relational expression between variables. When the value is determined, the value of the variable used in the array declaration in the procedure can be determined if it is an entire array, and the value of the variable or expression that determines the reference location can be determined if it is a partial array. When the value is not determined, the relationship with other variables and expressions is determined. For the partial array, it is analyzed whether or not the determined value or relationship is changed by another expression, and a range in which the determined value or relationship can be applied is obtained. Thereafter, the variable substitution means 25 converts the variable or expression into a constant according to the determined value. Also, using the determined relational expression, the variable or expression is replaced with the same variable or the same expression.

コンパイラは、配列式に対して、その配列式に現れる配列の下限と上限とを基に計算した初期値と終値とを持つループを内部的に生成する。変数置換手段25にて、変数の置換を行い、変数の定数化や変数の統一を行うことで、異なる変数で初期値と終値とが定義されるためにループ回数が同じであるか否かが不明であった複数のループのループ回数が、同じループ回数であると判定できるようになる。その結果、ループ融合が可能となり、共通式の削除が可能となる。共通式を削除し、ループ内にある同じ配列要素へのアクセスをまとめることで、メモリアクセス回数を削減するができる。これにより、プログラム実行時間を短縮できる。   The compiler internally generates a loop having an initial value and a final value calculated based on the lower limit and upper limit of the array appearing in the array expression. Whether or not the number of loops is the same since the initial value and the final value are defined in different variables by performing variable substitution in the variable substitution means 25 and making the variables constant and unifying the variables. It becomes possible to determine that the number of loops of a plurality of unknown loops is the same number of loops. As a result, loop fusion is possible and common expressions can be deleted. By deleting common expressions and grouping accesses to the same array element in a loop, the number of memory accesses can be reduced. Thereby, the program execution time can be shortened.

次に、本発明の第2実施形態について説明する。図11は、本発明の第2実施形態のコンパイラを示している。本実施形態のコンパイラ10aでは、変数最適化部15は、宣言情報・配列式検出手段21、参照配列・連続出現配列式検出手段26、寸法比較手段27、及び、分岐追加手段28を有する。第1実施形態では、変数最適化部12(図1)にて、翻訳時に各次元の寸法の計算で参照されている変数や式の値、同じ値を持つ変数又は式が決定したときに、決定した変数又は式で元の式を置き換えた。本実施形態では、翻訳時に各次元の寸法の計算で参照されている変数や式の値、同じ値を持つ変数又は式が決定しない場合に、実行時に実行するコードを選択するコードを生成する。   Next, a second embodiment of the present invention will be described. FIG. 11 shows a compiler according to the second embodiment of the present invention. In the compiler 10 a of this embodiment, the variable optimization unit 15 includes declaration information / array expression detection means 21, reference array / continuous appearance array expression detection means 26, dimension comparison means 27, and branch addition means 28. In the first embodiment, when the variable optimizing unit 12 (FIG. 1) determines a variable or expression value that is referred to in the calculation of dimensions of each dimension at the time of translation, or a variable or expression having the same value, Replaced the original expression with the determined variable or expression. In the present embodiment, when a variable or expression value that is referred to in the calculation of dimensions of each dimension at the time of translation, or a variable or expression having the same value is not determined, a code that selects a code to be executed at the time of execution is generated.

宣言情報・配列式検出手段21は、中間コード32を検索し、配列宣言の上限と下限、及び、配列式を検出し、宣言情報テーブル、配列式テーブル33に登録する。参照配列・連続出現配列式検出手段26は、配列式テーブルに登録されている配列式に対し、各配列式で参照している配列、配列の種類(全配列/部分配列)、配列の下限及び上限を調べ、参照配列テーブル39に登録する。また、配列式の直前及び直後に配列式が続くか否かを調べ、直前又は直後に配列式が続くときは、その配列式を参照配列テーブル39に登録する。   The declaration information / array expression detection means 21 searches the intermediate code 32, detects the upper and lower limits of the array declaration, and the array expression, and registers them in the declaration information table and the array expression table 33. The reference sequence / sequentially appearing sequence type detection means 26 is configured to select the sequence referenced in each sequence type, the type of sequence (total sequence / partial sequence), the lower limit of the sequence, and the sequence type registered in the sequence type table. The upper limit is checked and registered in the reference sequence table 39. Further, it is checked whether or not the array formula continues immediately before and after the array formula. If the array formula continues immediately before or immediately after, the array formula is registered in the reference sequence table 39.

寸法比較手段27は、参照配列テーブル39を参照して、連続する配列式で参照する配列の寸法が、翻訳時に同一であると判断できるか否かを調べる。翻訳時に寸法が同じであると判断できない連続した配列式がある場合、その配列式を、最適化候補配列式リスト40に登録する。分岐追加手段28は、最適化候補配列式リスト40に登録された配列式について、寸法が同じである場合と、同じでない場合とを選択するコードを、中間コード32に追加した中間コード36を生成する。寸法が同じである場合に実行されるコードについては、先頭の配列式に対して生成されるループの初期値及び終値で、他のループの初期値及び終値を置き換える。   The size comparison unit 27 refers to the reference sequence table 39 to check whether or not it is possible to determine that the size of the sequence referred to in the continuous sequence formula is the same during translation. If there is a continuous array formula that cannot be determined to have the same size at the time of translation, the array formula is registered in the optimization candidate sequence list 40. The branch addition means 28 generates an intermediate code 36 in which codes for selecting whether the dimensions are the same or not are added to the intermediate code 32 for the array formulas registered in the optimization candidate sequence list 40. To do. For the code executed when the dimensions are the same, the initial value and closing value of the other loop are replaced with the initial value and closing value of the loop generated for the first array expression.

図12に、本実施形態の変数最適化部15の動作手順を示す。宣言情報・配列式検出手段21は、中間コード32を検索し、配列の宣言情報と、配列式とを検出して、これらを、宣言情報テーブル、配列式テーブル33に登録する(ステップS11)。図13に、ソースプログラム例を示す。また、図14及び図15に、宣言情報テーブル、配列式テーブル33のデータ例を示す。図13に示すソースプログラム31に対応する中間コード32から、配列の宣言情報を検出することで、配列a、b、c、d、e、xが宣言情報テーブルに登録される(図14)。また、中間コード32から、配列式を検出することで、図13の配列式9−1〜9−3に対応する配列式が、配列式テーブルに登録される(図15)。   FIG. 12 shows an operation procedure of the variable optimization unit 15 of this embodiment. The declaration information / array expression detecting means 21 searches the intermediate code 32, detects the array declaration information and the array expression, and registers them in the declaration information table and the array expression table 33 (step S11). FIG. 13 shows an example of a source program. 14 and 15 show data examples of the declaration information table and the array formula table 33. FIG. By detecting array declaration information from the intermediate code 32 corresponding to the source program 31 shown in FIG. 13, the arrays a, b, c, d, e, and x are registered in the declaration information table (FIG. 14). Further, by detecting the array formula from the intermediate code 32, the array formula corresponding to the array formulas 9-1 to 9-3 in FIG. 13 is registered in the array formula table (FIG. 15).

参照配列・連続出現配列式検出手段26は、配列式テーブルに登録されている各配列式に対して参照配列テーブル39を作成し、各参照配列テーブルに、各配列式で参照している配列の配列名、配列の形状、配列の種別(全配列/部分配列)を登録する。また、各配列式について、当該配列式の直前又は直後に配列式があるときは、その配列式を直前又は直後の配列式として参照配列テーブル39に登録する(ステップS12)。配列の形状(下限:上限)の登録に際しては、配列が全配列であれば、宣言情報テーブルに登録されている下限と上限を登録し、部分配列であれば、参照箇所における下限と上限を登録する。   The reference sequence / continuous appearance sequence type detection means 26 creates a reference sequence table 39 for each sequence type registered in the sequence type table, and stores the reference sequence table 39 in each reference sequence table. The array name, array shape, and array type (full array / partial array) are registered. For each array formula, when there is an array formula immediately before or after the array formula, the array formula is registered in the reference sequence table 39 as the sequence formula immediately before or after (step S12). When registering the array shape (lower limit: upper limit), if the array is an entire array, register the lower limit and upper limit registered in the declaration information table, and if it is a partial array, register the lower limit and upper limit at the reference location. To do.

図16(a)〜(c)に、参照配列テーブルのデータ例を示す。図15に示す配列式テーブルを参照すると、中間コードには3つの配列式(配列式9−1〜9−3)があるので、参照配列・連続出現配列式検出手段26は、これらに対応して、参照配列テーブルを作成する(図16(a)〜(c))。その後、9−1に対しては配列a、b、cを(図16(a))、式9−2対しては配列c、d、eを(図16(b))、式9−3に対してはc、xを(図16(c))、それぞれ参照配列テーブルに登録する。配列の種別は、全て部分配列である。形状には、各配列の参照箇所の形状を参照配列テーブル39に登録する。例えば、図13を参照すると、式9−1の配列aの参照箇所はm1からm2であるので、式9−1に対する参照配列テーブルには、配列aの形状として、(m1:m2)を登録する。   FIGS. 16A to 16C show data examples of the reference sequence table. Referring to the array formula table shown in FIG. 15, since there are three array formulas (array formulas 9-1 to 9-3) in the intermediate code, the reference sequence / continuous appearance array formula detection means 26 corresponds to these. Thus, a reference sequence table is created (FIGS. 16A to 16C). Thereafter, arrays a, b, and c are assigned to 9-1 (FIG. 16 (a)), and arrays c, d, and e are assigned to expression 9-2 (FIG. 16 (b)) and expressions 9-3. C and x are registered in the reference sequence table (FIG. 16C). The array types are all partial arrays. As the shape, the shape of the reference location of each array is registered in the reference array table 39. For example, referring to FIG. 13, since the reference location of the array a in Expression 9-1 is m1 to m2, (m1: m2) is registered as the shape of the array a in the reference array table for Expression 9-1. To do.

図13を参照すると、配列式9−1の直前に他の配列式はなく、直後には配列式9−2が続く。参照配列・連続出現配列式検出手段26は、配列式9−1に対応する参照配列テーブルの「直前」に、配列式がないことを示すnoneを登録し、「直後」に、配列式9−2を登録する。配列式9−2については、直前に配列式9−1があり、直後には配列式9−3があるので、参照配列テーブルの「直前」に配列式9−1を登録し、「直後」に配列式9−3を登録する。配列式9−3は、直前に配列式9−2があり、直後には配列式がないので、参照配列テーブルの「直前」に配列式9−2を登録し、「直後」にはnoneを登録する。   Referring to FIG. 13, there is no other array formula immediately before the array formula 9-1, and immediately after the array formula 9-2. The reference sequence / sequentially appearing sequence expression detection means 26 registers “none” indicating that there is no sequence expression in “just before” of the reference sequence table corresponding to the array formula 9-1, and immediately after that, the array formula 9− 2 is registered. As for the array formula 9-2, since there is the array formula 9-1 immediately before and there is the array formula 9-3 immediately after, the array formula 9-1 is registered “just before” in the reference sequence table, and “immediately after”. The array formula 9-3 is registered in. Since the array formula 9-3 has the array formula 9-2 immediately before and there is no array formula immediately after it, the array formula 9-2 is registered “immediately before” in the reference sequence table, and “one” is set to “none”. sign up.

寸法比較手段27は、参照配列テーブル39を参照して、配列式が連続する箇所を検出する。その後、連続する配列式について、これら配列式で参照する配列の寸法が、翻訳時に同一であると判断できるか否かを調べる。翻訳時に寸法が同じであると判断できない連続した配列式がある場合は、その配列式を、最適化候補配列式リスト40に登録する(ステップS13)。図16(a)〜(c)を参照し、各配列式の「直前」、「直後」を調べることで、配列式9−1〜9−3が連続する配列式であると検出される。連続する配列式の検出後、参照配列テーブル39の各配列の形状を参照して、連続する配列式9−1〜9−3で参照する配列の寸法が同じであると判断できるか否かを調べる。   The dimension comparison means 27 refers to the reference sequence table 39 and detects a location where the array formulas are continuous. Thereafter, for successive sequence formulas, it is examined whether or not the dimensions of the sequences referred to in these sequence formulas can be determined to be the same during translation. If there is a continuous array formula that cannot be determined to have the same dimension during translation, the array formula is registered in the optimization candidate sequence list 40 (step S13). Referring to FIGS. 16A to 16C, by examining “immediately before” and “immediately” of each array formula, it is detected that array formulas 9-1 to 9-3 are continuous array formulas. After detecting the consecutive array formulas, it is determined whether or not it is possible to determine that the dimensions of the arrays referred to in the continuous array formulas 9-1 to 9-3 are the same by referring to the shape of each array in the reference sequence table 39. Investigate.

図17に、最適化候補配列式リスト40のデータ例を示す。図16(a)を参照すると、配列式9−1で参照する配列の寸法は、m2−m1+1である。図16(b)を参照すると、配列式9−2で参照する配列の寸法は、n2−n1+1である。この場合、配列式9−1と配列式9−2とで、参照する配列の寸法が同じであるか否かは不明であるので、寸法比較手段27は、最適化候補配列式リスト40に、配列式9−1、9−2を登録する(図17)。同様に、配列式9−2と配列式9−3とで、参照する配列の寸法が同じであると判断できるか否かを調べると、配列式9−3で参照する配列の寸法はm2−m1+1であるので、同じであると判断できない。寸法比較手段27は、最適化候補配列式リスト40に、配列式9−3を追加登録する。   FIG. 17 shows a data example of the optimization candidate sequence expression list 40. Referring to FIG. 16A, the size of the array referred to in the array formula 9-1 is m2-m1 + 1. Referring to FIG. 16B, the dimension of the array referred to in the array formula 9-2 is n2-n1 + 1. In this case, since it is unclear whether or not the size of the sequence to be referenced is the same between the array formula 9-1 and the array formula 9-2, the size comparison unit 27 includes the optimization candidate sequence formula list 40, The array formulas 9-1 and 9-2 are registered (FIG. 17). Similarly, when it is determined whether or not it is possible to determine that the size of the array to be referred to is the same in the array formula 9-2 and the array formula 9-3, the size of the array to be referred to in the array formula 9-3 is m2- Since it is m1 + 1, it cannot be judged that it is the same. The dimension comparison unit 27 additionally registers the sequence formula 9-3 in the optimization candidate sequence formula list 40.

分岐追加手段28は、最適化候補配列式リスト40に登録された配列式について、寸法が同じである場合と、同じでない場合とを実行時に選択するコードを、中間コード32に追加した中間コード36を生成する(ステップS14)。分岐追加手段28が生成した中間コード36が、変数最適化部15が出力する中間コードとなる。図18及び図19に、分岐追加手段28による追加前後の中間コードのデータ例を示す。図18に示す中間コード32は、中間コード生成部11にて生成された、図13に示すソースプログラムに対応した中間コードである。分岐追加手段28は、中間コード32から、配列式9−1〜9−3で参照する配列の寸法が同じ、すなわち、m2−m1=n2−n1が成立するときに実行されるコードを生成し、これを追加した中間コード36を生成する(図19)。   The branch adding means 28 adds an intermediate code 36 to the intermediate code 32 by adding, to the intermediate code 32, a code for selecting whether the dimensions are the same or not for the array formulas registered in the optimization candidate sequence list 40. Is generated (step S14). The intermediate code 36 generated by the branch addition means 28 becomes the intermediate code output from the variable optimization unit 15. 18 and 19 show examples of intermediate code data before and after addition by the branch addition means 28. FIG. The intermediate code 32 shown in FIG. 18 is an intermediate code corresponding to the source program shown in FIG. 13 generated by the intermediate code generator 11. The branch addition means 28 generates a code to be executed from the intermediate code 32 when the dimensions of the arrays referred to in the array formulas 9-1 to 9-3 are the same, that is, m2-m1 = n2-n1 is established. Then, an intermediate code 36 to which this is added is generated (FIG. 19).

図19に示す中間コード36は、m2−m1=n2−n1が成立するときに実行されるコード部分(if〜elseの間)と、成立しないときに実行されるコード部分(else〜endifの間)とを有する。寸法が同じときに実行されるコード部分は、生成元となる中間コード32(図18)における各配列式に対応するループの初期値及び終値を、先頭の配列式である配列式9−1に対応するループの初期値及び終値で置き換えたものである。つまり、図18では初期値=0、終値n2−n1であった配列式9-2に対応するループの初期値及び終値が、それぞれ配列式9−1に対応するループの初期値及び終値である0、m2−m1で置き換えられたものである。寸法が同じではないときに実行されるコード部分の内容は、図18に示す内容と同じである。   The intermediate code 36 shown in FIG. 19 includes a code part (between if and else) executed when m2-m1 = n2-n1 is established and a code part (between else and endif) executed when m2−m1 = n2−n1 is not established. ). The code portion executed when the dimensions are the same is obtained by replacing the initial value and the end value of the loop corresponding to each array expression in the intermediate code 32 (FIG. 18) as the generation source with the array expression 9-1 which is the first array expression. It is replaced with the initial value and the closing price of the corresponding loop. That is, in FIG. 18, the initial value and the closing price of the loop corresponding to the array formula 9-2 that had the initial value = 0 and the closing price n2−n1 are the initial value and the closing price of the loop corresponding to the array formula 9-1, respectively. 0 and m2-m1 are replaced. The contents of the code portion executed when the dimensions are not the same are the same as those shown in FIG.

最適化部13は、変数最適化部15が出力する中間コード36(図19)に対して、最適化を行う。図20に、最適化後の中間コード37を示す。最適化後の中間コード37では、m2−m1=n2−n1が成立するときに実行されるコード部分にて、ループが1つにまとめられる。一方、m2−m1=n2−n1が成立しないときに実行されるコード部分は、ループ融合ができないので、図18に示す中間コード32と同じままである。   The optimization unit 13 optimizes the intermediate code 36 (FIG. 19) output from the variable optimization unit 15. FIG. 20 shows the intermediate code 37 after optimization. In the optimized intermediate code 37, the loop is combined into one in the code portion that is executed when m2-m1 = n2-n1 holds. On the other hand, the code portion executed when m2-m1 = n2-n1 is not established remains the same as the intermediate code 32 shown in FIG. 18 because loop fusion cannot be performed.

図21に、図20に示す中間コードを実行したときのメモリアクセスと演算とを示す。最適化された中間コード37に基づいて生成されたオブジェクトプログラムを実行すると、実行時にm2−m1=n2−n1が成立するときのメモリアクセス回数は、7(m2−m1+1)回となる。また、実行時にm2−m1=n2−n1が成立しないときのメモリアクセス回数は、5(m2−m1+1)+3(n2−n1+1)回となる。   FIG. 21 shows memory access and calculation when the intermediate code shown in FIG. 20 is executed. When the object program generated based on the optimized intermediate code 37 is executed, the number of memory accesses when m2-m1 = n2-n1 is satisfied at the time of execution is 7 (m2-m1 + 1) times. Further, the number of memory accesses when m2−m1 = n2−n1 is not satisfied at the time of execution is 5 (m2−m1 + 1) +3 (n2−n1 + 1) times.

図18に示す中間コード32を、変数最適化部15を経ずに最適化部13にて最適化した場合は、中間コード36におけるm2−m1=n2−n1が成立しないときに実行されるコード部分と同様に、ループが融合される箇所はない。従って、中間コード32に基づいて生成されたオブジェクトプログラムを実行したときの、メモリアクセス回数は5(m2−m1+1)+3(n2−n1+1)回となる。m2−m1とn2−n1の値が等しいとすると、メモリアクセス回数は、8(m2−m1+1)回と表すことができる。   When the intermediate code 32 shown in FIG. 18 is optimized by the optimization unit 13 without passing through the variable optimization unit 15, the code executed when m2-m1 = n2-n1 in the intermediate code 36 is not satisfied. Like the part, there is no place where the loop is fused. Therefore, when the object program generated based on the intermediate code 32 is executed, the number of memory accesses is 5 (m2−m1 + 1) +3 (n2−n1 + 1). When the values of m2-m1 and n2-n1 are equal, the number of memory accesses can be expressed as 8 (m2-m1 + 1) times.

図22に、メモリアクセス回数の比較表を示す。中間コード36に基づくオブジェクトプログラムを実行した場合のメモリアクセス回数は、寸法が同じ、つまり、m2−m1=n2−n1が成立する場合で7(m2−m1+1)回、寸法が異なる、つまり、m2−m1=n2−n1が成立しない場合で5(m2−m1+1)+3(n2−n1+1)となる。一方、中間コード32に基づくオブジェクトプログラムを実行した場合のメモリアクセス回数は、m2−m1=n2−n1が成立する場合で、8(m2−m1+1)、m2−m1=n2−n1が成立しない場合で5(m2−m1+1)+3(n2−n1+1)回となる。このように、変数最適化部15で、連続する配列式が参照する配列の寸法が同じ場合に実行されるコードを追加することにより、実行時に寸法が同じときのメモリアクセス回数を(m2−m1+1)回削減することができる。   FIG. 22 shows a comparison table of the number of memory accesses. When the object program based on the intermediate code 36 is executed, the number of memory accesses is the same, that is, the size is different 7 times (m2−m1 + 1) when m2−m1 = n2−n1 holds, that is, m2. When -m1 = n2-n1 is not satisfied, 5 (m2-m1 + 1) +3 (n2-n1 + 1) is obtained. On the other hand, when the object program based on the intermediate code 32 is executed, the number of memory accesses is when m2−m1 = n2−n1 is satisfied, and when 8 (m2−m1 + 1) and m2−m1 = n2−n1 are not satisfied. This is 5 (m2-m1 + 1) +3 (n2-n1 + 1) times. In this way, the variable optimization unit 15 adds a code that is executed when the dimensions of the arrays referred to by the continuous array formula are the same, so that the number of memory accesses when the dimensions are the same at the time of execution is (m2−m1 + 1). ) Times can be reduced.

本実施形態では、連続して現れる配列式の形状が、翻訳時に一致するか否かが不明であるとき、寸法が同じときに実行されるコードを中間コードに追加し、実行時に、寸法が等しいか否かを判断して、寸法が同じときに実行されるコードと、寸法が異なるときに実行するコードを呼び分ける。寸法が同じであるときに実行されるコード部分は、最適化部13にて、ループ融合、共通式の削除が可能である。従って、実行時に、連続する配列式の寸法が等しいときのメモリアクセス回数を削減することができ、プログラムの実行速度を向上させることができる。   In this embodiment, when it is unclear whether or not the shapes of the array formulas that appear successively match at the time of translation, the code that is executed when the dimensions are the same is added to the intermediate code, and the dimensions are equal at the time of execution The code executed when the dimensions are the same and the code executed when the dimensions are different are called. The code portion executed when the dimensions are the same can be loop-fused and the common expression can be deleted by the optimization unit 13. Therefore, at the time of execution, the number of memory accesses when the dimensions of consecutive array formulas are equal can be reduced, and the execution speed of the program can be improved.

以上、本発明をその好適な実施形態に基づいて説明したが、本発明のコンパイラ、変数最適化装置、方法、及び、プログラムは、上記実施形態にのみ限定されるものではなく、上記実施形態の構成から種々の修正及び変更を施したものも、本発明の範囲に含まれる。   As described above, the present invention has been described based on the preferred embodiment. However, the compiler, the variable optimization device, the method, and the program of the present invention are not limited to the above-described embodiment. Those in which various modifications and changes have been made to the configuration are also included in the scope of the present invention.

本発明の第1実施形態のコンパイラを示すブロック図。The block diagram which shows the compiler of 1st Embodiment of this invention. 変数最適化部の動作手順を示すフローチャート。The flowchart which shows the operation | movement procedure of a variable optimization part. 宣言情報テーブルのデータ例を示す図。The figure which shows the example of data of a declaration information table. 配列式テーブルのデータ例を示す図。The figure which shows the example of data of an arrangement | sequence formula table. (a)〜(d)は、参照配列テーブルのデータ例を示す図。(A)-(d) is a figure which shows the example of data of a reference sequence table. 確定変数テーブルのデータ例を示す図。The figure which shows the example of data of a definite variable table. 変数最適化部による最適化後の中間コードを示す図。The figure which shows the intermediate code after optimization by the variable optimization part. 最適化部による最適化後の中間コードを示す図。The figure which shows the intermediate code after the optimization by the optimization part. 図8に示す中間コードにおけるメモリアクセスを示す図。The figure which shows the memory access in the intermediate code shown in FIG. 変数最適化部による最適化を経ない中間コードにおけるメモリアクセスを示す図。The figure which shows the memory access in the intermediate code | symbol which does not pass through the optimization by a variable optimization part. 本発明の第2実施形態のコンパイラを示すブロック図。The block diagram which shows the compiler of 2nd Embodiment of this invention. 第2実施形態における変数最適化部の動作手順を示すフローチャート。The flowchart which shows the operation | movement procedure of the variable optimization part in 2nd Embodiment. ソースプログラム例を示す図。The figure which shows the example of a source program. 宣言情報テーブルのデータ例を示す図。The figure which shows the example of data of a declaration information table. 配列式テーブルのデータ例を示す図。The figure which shows the example of data of an arrangement | sequence formula table. (a)〜(c)は、参照配列テーブルのデータ例を示す図。(A)-(c) is a figure which shows the example of data of a reference sequence table. 最適化候補配列式リストのデータ例を示す図。The figure which shows the example of data of an optimization candidate arrangement | sequence list. 図13に示すソースプログラムに対応する中間コードを示す図。The figure which shows the intermediate code corresponding to the source program shown in FIG. 変数最適化部による最適化後の中間コードを示す図。The figure which shows the intermediate code after optimization by the variable optimization part. 最適化部による最適化後の中間コードを示す図。The figure which shows the intermediate code after the optimization by the optimization part. 図20に示す中間コードにおけるメモリアクセスを示す図。The figure which shows the memory access in the intermediate code shown in FIG. 変数最適化前後でのメモリアクセス回数を示す図。The figure which shows the memory access frequency before and behind variable optimization. ソースプログラムの一例を示す図。The figure which shows an example of a source program. 図23のソースプログラムから生成される中間コードを示す図。The figure which shows the intermediate code produced | generated from the source program of FIG.

符号の説明Explanation of symbols

10:コンパイラ
11:中間コード生成部
12、15:変数最適化部
13:最適化部
14:コード生成部
21:宣言情報・配列式検出手段
22:参照配列検出手段
23:変数関係確定手段
24:変数定義検出手段
25:変数置換手段
26:参照配列・連続出現配列式検出手段
27:寸法比較手段
28:分岐追加手段
31:ソースプログラム
32、36、37:中間コード
33:宣言情報テーブル、配列式テーブル
34、39:参照配列テーブル
35:確定変数テーブル
38:オブジェクトプログラム
40:最適化候補配列式リスト
10: Compiler 11: Intermediate code generation unit 12, 15: Variable optimization unit 13: Optimization unit 14: Code generation unit 21: Declaration information / array expression detection unit 22: Reference sequence detection unit 23: Variable relationship determination unit 24: Variable definition detection means 25: variable replacement means 26: reference sequence / continuous appearance array expression detection means 27: dimension comparison means 28: branch addition means 31: source programs 32, 36, 37: intermediate code 33: declaration information table, array expression Tables 34 and 39: Reference sequence table 35: Deterministic variable table 38: Object program 40: Optimization candidate sequence expression list

Claims (6)

複数の配列を演算する配列式を含む中間コードを読み出し、前記中間コードから、配列式を複数検出する配列式検出部と、
前記配列式検出部で検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定部と、
前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出部と、
前記変数関係確定部で決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出部で前定義式が検出された位置から、前記変数定義検出部で後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換部と、
前記寸法式置換部で置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化部と、
を備える変数最適化装置。
To read out the intermediate code containing the sequence formula for calculating a plurality of sequences, from the intermediate code, and sequence type detecting unit for detecting a plurality of sequence type,
For each of the plurality of arrays calculated by the plurality of array formulas detected by the array formula detection unit, a dimension formula representing the dimensions of the array is calculated using a variable representing the upper limit and a variable representing the lower limit of the array. The dimension of the first array in which the dimensional expression is calculated using the first variable and the dimension of the second array in which the dimensional expression is calculated using the second variable are: A variable relationship determining unit that determines a relational expression representing a relation of the same dimensions when the array and the second array are operated with the same array formula;
The array formula for calculating the first array and the second array is a position before the array expression detection position detected from the intermediate code, and the value of the first variable or the second variable is A variable definition detection unit that detects a pre-defined formula that detects a pre-defined formula that defines a value of the first variable or the second variable at a position after the sequence formula detection position;
Based on the relational expression determined by the variable relation determination unit, from the position where the pre-defined expression is detected by the variable definition detection part among the dimensional expressions of the plurality of arrays respectively calculated by the plurality of array formulas , The dimension formula of the array calculated by the array formula detected at the position up to the position where the post-definition formula is detected by the variable definition detection unit, and the dimension formula calculated using the first variable, A dimensional formula replacement unit that replaces the dimensional formula calculated using the second variable;
In accordance with each of the plurality of array formulas for calculating the array of dimensions represented by the same dimension formula as the dimension formula replaced by the dimension formula replacement unit, each of the loop processes that are repeatedly executed is common to the plurality of loop processes. An optimization unit that performs a loop optimization that deletes the common arithmetic expression and fuses the plurality of loop processes;
A variable optimization device comprising:
前記配列式検出部で検出された複数の配列式の内で、連続して処理される複数の配列式のそれぞれで演算される複数の配列の寸法が翻訳時にそれぞれ同一であると確定しているか否かを、前記変数関係確定部で計算された寸法式に基づいて判別する寸法判別部と、
前記変数関係確定部で前記複数の配列の寸法がそれぞれ同一であると翻訳時には確定していないと判別されると、実行時に前記複数の配列の寸法がそれぞれ同じ場合に実行される寸法同一時処理と、前記複数の配列の寸法がそれぞれ同じでない場合に実行される寸法非同一時処理と、に処理を分岐する処理を追加する分岐追加部と、をさらに備え、
前記最適化部は、前記連続して処理される複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理をループ最適化した処理を前記寸法同一時処理とする、
ことを特徴とする請求項1に記載の変数最適化装置。
Among the plurality of sequence formulas detected by the sequence formula detection unit, is it determined that the dimensions of the plurality of sequences calculated by each of the plurality of sequence formulas processed in succession are the same during translation? A size discriminating unit for discriminating whether or not based on the dimensional formula calculated by the variable relationship determining unit;
When the variable relationship determining unit determines that the dimensions of the plurality of arrays are the same at the time of translation, it is determined that the dimensions of the plurality of arrays are not determined at the time of translation. And a non-identical dimension process executed when the dimensions of the plurality of arrays are not the same, and a branch addition unit for adding a process to branch the process to,
The optimization unit, according to each of the plurality of array formulas that are processed in succession, a loop optimization of a plurality of loop processing that is repeatedly executed as the same size processing,
The variable optimization apparatus according to claim 1, wherein:
コンピュータを、
複数の配列を演算する配列式を含む中間コードを読み出し、前記中間コードから、配列式を複数検出する配列式検出部、
前記配列式検出部で検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定部、
前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出部、
前記変数関係確定部で決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出部で前定義式が検出された位置から、前記変数定義検出部で後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換部、
前記寸法式置換部で置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化部、
として機能させるための変数最適化プログラム。
Computer
To read out the intermediate code containing the sequence formula for calculating a plurality of sequences, wherein the intermediate code, sequence type detecting unit detecting a plurality of sequence type,
For each of the plurality of arrays calculated by the plurality of array formulas detected by the array formula detection unit, a dimension formula representing the dimensions of the array is calculated using a variable representing the upper limit and a variable representing the lower limit of the array. The dimension of the first array in which the dimensional expression is calculated using the first variable and the dimension of the second array in which the dimensional expression is calculated using the second variable are: A variable relationship determining unit that determines a relational expression representing a relation of the same dimensions when the array and the second array are operated with the same array formula;
The array formula for calculating the first array and the second array is a position before the array expression detection position detected from the intermediate code, and the value of the first variable or the second variable is A variable definition detecting unit that detects a pre-defined formula that detects a pre-defined formula that defines a value of the first variable or the second variable at a position after the sequence formula detected position;
Based on the relational expression determined by the variable relation determination unit, from the position where the pre-defined expression is detected by the variable definition detection part among the dimensional expressions of the plurality of arrays respectively calculated by the plurality of array formulas , The dimension formula of the array calculated by the array formula detected at the position up to the position where the post-definition formula is detected by the variable definition detection unit, and the dimension formula calculated using the first variable, A dimension formula replacement unit that replaces the dimension formula calculated using the second variable;
In accordance with each of the plurality of array formulas for calculating the array of dimensions represented by the same dimension formula as the dimension formula replaced by the dimension formula replacement unit, each of the loop processes that are repeatedly executed is common to the plurality of loop processes. An optimization unit that performs a loop optimization that deletes the common arithmetic expression and fuses the plurality of loop processes,
Variable optimization program to function as
コンピュータが、複数の配列を演算する配列式を含む中間コードを読み出し、前記中間コードから、配列式を複数検出する配列式検出ステップと、
前記コンピュータが、前記配列式検出ステップで検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定ステップと、
前記コンピュータが、前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出ステップと、
前記コンピュータが、前記変数関係確定ステップで決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出ステップで前定義式が検出された位置から、前記変数定義検出ステップで後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換ステップと、
前記コンピュータが、前記寸法式置換ステップで置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化ステップと、
を有する変数最適化方法。
Computer, to read out the intermediate code containing the sequence formula for calculating a plurality of sequences, from the intermediate code, and sequence type detecting step of detecting a plurality of sequence type,
For each of the plurality of arrays each calculated by the plurality of array formulas detected in the array formula detection step, the computer expresses a dimension formula representing the dimensions of the array as a variable representing the upper limit and a variable representing the lower limit. calculated using the dimensions of the first array dimension expression is calculated using the first variable, a dimension of the second sequence size equation using the second variable is calculated, it is A variable relationship determination step for determining a relational expression representing a relation of the same dimensions when the first array and the second array are operated with the same array formula;
The computer is configured to calculate the first array and the second array at a position before the array expression detection position detected from the intermediate code, and the first variable or the second array Variable definition detection that detects a pre-defined expression that defines a value of a variable and detects a post-defined expression that defines the value of the first variable or the second variable at a position after the position of detecting the array expression Steps,
Based on the relational expression determined in the variable relation determining step, the computer detects a pre-defined expression in the variable definition detecting step among a plurality of array dimensional expressions respectively calculated in the plurality of array formulas. Dimensional expression of the array calculated by the array expression detected at the position from the position to the position where the post-definition expression is detected at the variable definition detection step, calculated using the first variable A dimension formula replacing step for replacing the dimension formula with a dimension formula calculated using the second variable;
The plurality of loops from a plurality of loop processes repeatedly executed according to each of the plurality of array formulas, wherein the computer calculates an array of dimensions represented by the same dimension formula as the dimension formula replaced in the dimension formula replacing step. An optimization step for performing a loop optimization that deletes a common arithmetic expression common to the processes and fuses the plurality of loop processes;
A variable optimization method having :
コンピュータを、
複数の配列を演算する配列式を含む中間コードを読み出し、前記中間コードから、配列式を複数検出する配列式検出部、
前記配列式検出部で検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定部、
前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出部、
前記変数関係確定部で決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出部で前定義式が検出された位置から、前記変数定義検出部で後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換部、
前記寸法式置換部で置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化部、
前記最適化部でループ最適化された中間コードに基づいて、オブジェクトプログラムを生成するコード生成部、
として機能させるためのコンパイラ。
Computer
To read out the intermediate code containing the sequence formula for calculating a plurality of sequences, wherein the intermediate code, sequence type detecting unit detecting a plurality of sequence type,
For each of the plurality of arrays calculated by the plurality of array formulas detected by the array formula detection unit, a dimension formula representing the dimensions of the array is calculated using a variable representing the upper limit and a variable representing the lower limit of the array. The dimension of the first array in which the dimensional expression is calculated using the first variable and the dimension of the second array in which the dimensional expression is calculated using the second variable are: A variable relationship determining unit that determines a relational expression representing a relation of the same dimensions when the array and the second array are operated with the same array formula;
The array formula for calculating the first array and the second array is a position before the array expression detection position detected from the intermediate code, and the value of the first variable or the second variable is A variable definition detecting unit that detects a pre-defined formula that detects a pre-defined formula that defines a value of the first variable or the second variable at a position after the sequence formula detected position;
Based on the relational expression determined by the variable relation determination unit, from the position where the pre-defined expression is detected by the variable definition detection part among the dimensional expressions of the plurality of arrays respectively calculated by the plurality of array formulas , The dimension formula of the array calculated by the array formula detected at the position up to the position where the post-definition formula is detected by the variable definition detection unit, and the dimension formula calculated using the first variable, A dimension formula replacement unit that replaces the dimension formula calculated using the second variable;
In accordance with each of the plurality of array formulas for calculating the array of dimensions represented by the same dimension formula as the dimension formula replaced by the dimension formula replacement unit, each of the loop processes that are repeatedly executed is common to the plurality of loop processes. An optimization unit that performs a loop optimization that deletes the common arithmetic expression and fuses the plurality of loop processes,
A code generation unit for generating an object program based on the intermediate code loop-optimized by the optimization unit;
Compiler to function as
コンピュータが、複数の配列を演算する配列式を含む中間コードを読み出し、前記中間コードから、配列式を複数検出する配列式検出ステップと、
前記コンピュータが、前記配列式検出ステップで検出された複数の配列式でそれぞれ演算される複数の配列のそれぞれについて、配列の寸法を表す寸法式を当該配列の上限を表す変数と下限を表す変数とを用いて計算し、第1の変数を用いて寸法式が計算された第1の配列の寸法と、第2の変数を用いて寸法式が計算された第2の配列の寸法と、は、前記第1の配列と前記第2の配列とが同じ配列式で演算される場合に、同じ寸法である、という関係を表す関係式を決定する変数関係確定ステップと、
前記コンピュータが、前記第1の配列と前記第2の配列とを演算する配列式が前記中間コードから検出された配列式検出位置よりも前の位置で、前記第1の変数若しくは前記第2の変数の値を定義する前定義式を検出し、前記配列式検出位置よりも後の位置で、前記第1の変数若しくは前記第2の変数の値を定義する後定義式を検出する変数定義検出ステップと、
前記コンピュータが、前記変数関係確定ステップで決定された関係式に基づいて、前記複数の配列式でそれぞれ演算される複数の配列の寸法式の内で、前記変数定義検出ステップで前定義式が検出された位置から、前記変数定義検出ステップで後定義式が検出された位置までの位置で検出された配列式で演算される配列の寸法式であって前記第1の変数を用いて計算された寸法式を、前記第2の変数を用いて計算された寸法式に置換する寸法式置換ステップと、
前記コンピュータが、前記寸法式置換ステップで置換された寸法式と同じ寸法式で表される寸法の配列を演算する複数の配列式にそれぞれ従って、繰り返し実行される複数のループ処理から当該複数のループ処理に共通した共通演算式を削除し、かつ当該複数のループ処理を融合させるループ最適化を行う最適化ステップと、
前記コンピュータが、前記最適化ステップでループ最適化された中間コードに基づいて、オブジェクトプログラムを生成するコード生成ステップと、
を有するコンパイル方法。
Computer, to read out the intermediate code containing the sequence formula for calculating a plurality of sequences, from the intermediate code, and sequence type detecting step of detecting a plurality of sequence type,
For each of the plurality of arrays each calculated by the plurality of array formulas detected in the array formula detection step, the computer expresses a dimension formula representing the dimensions of the array as a variable representing the upper limit and a variable representing the lower limit. calculated using the dimensions of the first array dimension expression is calculated using the first variable, a dimension of the second sequence size equation using the second variable is calculated, it is A variable relationship determination step for determining a relational expression representing a relation of the same dimensions when the first array and the second array are operated with the same array formula;
The computer is configured to calculate the first array and the second array at a position before the array expression detection position detected from the intermediate code, and the first variable or the second array Variable definition detection that detects a pre-defined expression that defines a value of a variable and detects a post-defined expression that defines the value of the first variable or the second variable at a position after the position of detecting the array expression Steps,
Based on the relational expression determined in the variable relation determining step, the computer detects a pre-defined expression in the variable definition detecting step among a plurality of array dimensional expressions respectively calculated in the plurality of array formulas. Dimensional expression of the array calculated by the array expression detected at the position from the position to the position where the post-definition expression is detected at the variable definition detection step, calculated using the first variable A dimension formula replacing step for replacing the dimension formula with a dimension formula calculated using the second variable;
The plurality of loops from a plurality of loop processes repeatedly executed according to each of the plurality of array formulas, wherein the computer calculates an array of dimensions represented by the same dimension formula as the dimension formula replaced in the dimension formula replacing step. An optimization step for performing a loop optimization that deletes a common arithmetic expression common to the processes and fuses the plurality of loop processes;
A code generation step in which the computer generates an object program based on the intermediate code loop-optimized in the optimization step;
Compile method having
JP2008054361A 2008-03-05 2008-03-05 Variable optimization apparatus, variable optimization program, compiler, variable optimization method, and compilation method Active JP5169322B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2008054361A JP5169322B2 (en) 2008-03-05 2008-03-05 Variable optimization apparatus, variable optimization program, compiler, variable optimization method, and compilation method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2008054361A JP5169322B2 (en) 2008-03-05 2008-03-05 Variable optimization apparatus, variable optimization program, compiler, variable optimization method, and compilation method

Publications (2)

Publication Number Publication Date
JP2009211458A JP2009211458A (en) 2009-09-17
JP5169322B2 true JP5169322B2 (en) 2013-03-27

Family

ID=41184528

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2008054361A Active JP5169322B2 (en) 2008-03-05 2008-03-05 Variable optimization apparatus, variable optimization program, compiler, variable optimization method, and compilation method

Country Status (1)

Country Link
JP (1) JP5169322B2 (en)

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPS63198130A (en) * 1987-02-13 1988-08-16 Nec Corp System for selecting loop optimum instruction train
JPS6418876A (en) * 1987-07-14 1989-01-23 Nec Corp Production system for vector instruction column
JPH02118732A (en) * 1988-10-28 1990-05-07 Toshiba Corp Program processing system
JP2815178B2 (en) * 1989-06-30 1998-10-27 富士通株式会社 Compiler unit
JP2701246B2 (en) * 1991-05-07 1998-01-21 日本電気株式会社 Compiler vectorization method
JPH05257707A (en) * 1992-03-13 1993-10-08 Hitachi Ltd Compiling system
JP3695798B2 (en) * 1995-08-25 2005-09-14 富士通株式会社 Computer system and code generation optimization control method
JP2002073579A (en) * 2000-08-29 2002-03-12 Hitachi Ltd Compiling method for distributed common memory
JP2003256214A (en) * 2002-02-27 2003-09-10 Hitachi Ltd Loop conversion method using array extension

Also Published As

Publication number Publication date
JP2009211458A (en) 2009-09-17

Similar Documents

Publication Publication Date Title
JP5775829B2 (en) Software structure visualization program and system
US20060195828A1 (en) Instruction generator, method for generating instructions and computer program product that executes an application for an instruction generator
CN111104335B (en) C language defect detection method and device based on multi-level analysis
US7917899B2 (en) Program development apparatus, method for developing a program, and a computer program product for executing an application for a program development apparatus
US20090249307A1 (en) Program analysis apparatus, program analysis method, and program storage medium
US20160321039A1 (en) Technology mapping onto code fragments
KR20100069573A (en) Method, computer program and computer system for assisting in analyzing program
US9715374B2 (en) Multi-branch determination syntax optimization apparatus
JP2007041804A (en) Program generation device, program verification device, and verification program
US20010044930A1 (en) Loop optimization method and a compiler
Sargsyan et al. Scalable and accurate clones detection based on metrics for dependence graph
JP5169322B2 (en) Variable optimization apparatus, variable optimization program, compiler, variable optimization method, and compilation method
JP6002507B2 (en) Software verification program and software verification system
US20160371066A1 (en) Computer that performs compiling, compiling method and storage medium that stores compiler program
JP5227646B2 (en) Compiler and code generation method thereof
JPWO2017204139A1 (en) Data processing apparatus, data processing method, and program recording medium
JP2013080407A (en) Compilation device, compilation method, compilation program, and storage medium
JP2017033342A (en) Compilation device, compilation method, and compilation program
JP6748357B2 (en) Analysis device, analysis program, and analysis method
CN112631925B (en) Method for detecting single-variable atom violation defect
JP3584204B2 (en) Automatic source program converter
JP2008015665A (en) Program analysis method and program analyzer
JP2007249262A (en) System and method for detecting access out of range of array
JP6086420B2 (en) Design description difference analysis apparatus, design description difference analysis program, and design description difference analysis method
JP3367438B2 (en) Conditional execution processing device

Legal Events

Date Code Title Description
RD01 Notification of change of attorney

Free format text: JAPANESE INTERMEDIATE CODE: A7421

Effective date: 20100224

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20120217

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20120313

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20120514

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20120911

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20121109

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

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20121217

R150 Certificate of patent or registration of utility model

Ref document number: 5169322

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150