JPH0553822A - Method and device for erasing common partial expressional sentence - Google Patents

Method and device for erasing common partial expressional sentence

Info

Publication number
JPH0553822A
JPH0553822A JP21511791A JP21511791A JPH0553822A JP H0553822 A JPH0553822 A JP H0553822A JP 21511791 A JP21511791 A JP 21511791A JP 21511791 A JP21511791 A JP 21511791A JP H0553822 A JPH0553822 A JP H0553822A
Authority
JP
Japan
Prior art keywords
expression
sentence
sub
statement
expressional
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.)
Pending
Application number
JP21511791A
Other languages
Japanese (ja)
Inventor
Jiyunko Irikou
旬子 入交
Akira Tanaka
旭 田中
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Panasonic Holdings Corp
Original Assignee
Matsushita Electric Industrial Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Matsushita Electric Industrial Co Ltd filed Critical Matsushita Electric Industrial Co Ltd
Priority to JP21511791A priority Critical patent/JPH0553822A/en
Publication of JPH0553822A publication Critical patent/JPH0553822A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

PURPOSE:To efficiently erase a common partial expressional sentence by detecting the pattern of an expressional sentence to be a common part among expressional sentences in a program and selecting the partial expressional sentence used for calculation. CONSTITUTION:The pattern to be divided as an instruction code is detected in respect to the partial expressional sentence divided into the partial expressional sentence for each arithmetic unit by an expressional sentence dividing means 1 and divided by a partial expressional sentence pattern detection part 2. A partial expressional sentence pattern selection part 3 selects the partial expressional sentence used for the calculation of the expressional sentence from the detected partial expressional sentence pattern. An expressional sentence transforming means 4 transforms the selected partial expressional sentence, and the transformed common partial expressional sentence and a corresponding identifier are separately held. Namely, after comparatively checking the pattern of the optimum partial expressional sentence, the selection of the optimum common partial expressional sentence and the transformation to the identifier are executed. Therefore, the calculated result of the identifier can be adopted for calculating the other expressional sentence in the calculation of the expressional sentence, and the calculation of the expressional sentence is reduced.

Description

【発明の詳細な説明】Detailed Description of the Invention

【0001】[0001]

【産業上の利用分野】本発明はコンパイラの最適化手法
における共通部分式文の削除方法及び削除装置に関す
る。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a method and apparatus for deleting common subexpression statements in a compiler optimization method.

【0002】[0002]

【従来の技術】共通部分式文の削除は、同じ部分式文が
複数現れる場合に最初に計算した結果を利用することに
よって後の共通部分式文の演算回数を減らし生成コード
の実行速度を向上するため採用されるものであり、最適
化技術の有力な一手段として使用されている。
2. Description of the Related Art The common sub-expression statement is deleted by using the result calculated first when the same sub-expression statement appears more than once, thereby reducing the number of operations of the subsequent common sub-expression statement and improving the execution speed of the generated code. It has been adopted as a means of optimizing technology.

【0003】図4は従来の共通部分式文の削除装置の構
成図である。図中、401は式文分割部で、式文を評価
するのに最小のコードになるように分割するものであ
る。402は共通部分式文判定部で、対象としているコ
ードの部分式文が今までのコードの中に存在していたか
否かを部分式文を登録している後述の部分式文記憶部4
05の中に登録されているか否かで判定をする。そして
部分式文を構成する識別子の値が、部分式文を登録した
時点と異なる値を持つ場合には、別の部分式文と判定す
る。403は部分式文登録部で、共通部分式文判定部で
部分式文が今までのコードの中に存在していないと判定
された場合に起動され、部分式文を後述の部分式文記憶
部405に登録する。一方、既に部分式文が部分式文記
憶部405に登録されていると判断された場合には起動
されない。404は共通部分式文削除部で、前記共通部
分式文検出部で検出された共通部分式文に対して、登録
されている部分式文により定義されている識別子で部分
式文を置き換えることにより、計算式の当該共通部分式
文分を削除するものである。405は部分式文記憶部
で、コードの中の部分式文と、共通部分式文として登録
された部分式文の値を保持する識別子を登録するもので
ある。既に部分式文が登録されている場合には新しく登
録されない。又、表面上同じ部分式文であっても、プロ
グラム等の都合で識別子の値が異なることとなる場合に
は、異なる部分式文として登録される。
FIG. 4 is a block diagram of a conventional common sub-expression sentence deletion device. In the figure, reference numeral 401 denotes an expression sentence dividing unit, which divides an expression sentence so that it has the smallest code for evaluation. Reference numeral 402 denotes a common sub-expression statement determination unit, which registers a sub-expression statement as to whether or not the sub-expression statement of the target code exists in the code up to now, which will be described later.
Judgment is made based on whether or not it is registered in 05. If the value of the identifier forming the sub-expression statement has a value different from the time when the sub-expression statement was registered, it is determined to be another sub-expression statement. 403 is a sub-expression statement registration unit, which is activated when the common sub-expression statement determination unit determines that the sub-expression statement does not exist in the code so far, and stores the sub-expression statement in the sub-expression statement storage described later. Register in section 405. On the other hand, if it is determined that the partial expression sentence is already registered in the partial expression sentence storage unit 405, it is not activated. Reference numeral 404 denotes a common sub-expression sentence deleting unit, which replaces the common sub-expression sentence detected by the common sub-expression sentence detecting unit with the identifier defined by the registered sub-expression sentence. , The common subexpression sentence of the calculation formula is deleted. A sub-expression sentence storage unit 405 registers a sub-expression sentence in the code and an identifier that holds the value of the sub-expression sentence registered as the common sub-expression sentence. If a sub-expression has already been registered, it will not be newly registered. Further, even if the subexpressions are the same on the surface, if the values of the identifiers are different due to the reasons such as programs, they are registered as different subexpressions.

【0004】前述のように構成された従来の共通部分式
文の削除装置の動作を図5のフローチャートに沿って説
明する。 (51)コード分割部401が起動され、対象とする式
文がなくなるまで式文を分割する。 (52)式文分割部401は読み込んだ式文を部分式文
に分割する。 (53)分割されたコードがなくなるまで、以下の(5
4)から(56)までの動作を繰り返す。 (54)共通部分式文判定部402を起動する。共通部
分式文判定部402はコードの部分式文が部分式文登録
部405に登録されているか否かを判定する。 (55)部分式文が登録されていない場合には、部分式
文登録部403を起動する。部分式文が登録されている
場合には、共通部分式文削除部404を起動する。 (56)部分式文登録部403は、部分式文記憶部40
5に部分式文と、その結果を保持する識別子を登録す
る。 (57)共通部分式文削除部404は、コードの部分式
文の部分を削除し、登録されている部分式文の結果を保
持する識別子の代入文に変換する。
The operation of the conventional common sub-expression sentence erasing device configured as described above will be described with reference to the flowchart of FIG. (51) The code division unit 401 is activated, and the expression sentence is divided until there is no target expression sentence. (52) The expression statement dividing unit 401 divides the read expression statement into sub-expression statements. (53) The following (5
The operations from 4) to (56) are repeated. (54) The common subexpression determination unit 402 is activated. The common sub-expression sentence determination unit 402 determines whether the sub-expression sentence of the code is registered in the sub-expression sentence registration unit 405. (55) If the partial expression sentence is not registered, the partial expression sentence registration unit 403 is activated. If the subexpression is registered, the common subexpression deletion unit 404 is activated. (56) The partial expression sentence registering unit 403 is connected to the partial expression sentence storage unit 40.
A subexpression statement and an identifier holding the result are registered in 5. (57) The common subexpression statement deletion unit 404 deletes the subexpression statement portion of the code and converts it into an assignment statement of an identifier holding the result of the registered subexpression statement.

【0005】以上のように動作する従来の共通部分式文
の削除方法における具体的な動作を次に説明する。図6
は従来の共通部分式文の削除方法により共通部分式文を
削除する過程の一例を示す摸式図である。ここでは、演
算子は演算数の入れ換えが可能であり、計算結果は変換
しないことは保証されていると仮定する。いま、式文が
図6の状態であったとする。式文が部分式文に分割さ
れ、その状態は図6(b)の状態となる。分割された部
分式文を順に読み込み、共通部分式文判定部を起動す
る。部分式文Aを読み込み、部分式文記憶部に登録され
ているか否かを判定する。その結果、部分式文は登録さ
れていないと判断されたため、その部分式文は登録さ
れ、図6(c)の状態となる。次に、部分式文Bを読み
込み、共通部分式文判定部により、登録されていないこ
とが判定され、部分式文記憶部に登録される。続いて、
部分式文Cを読み込み、共通部分式文判定部を起動す
る。共通部分式文判定部は部分式文は登録されていない
と判定され、その結果、式文の共通部分式文の削除は行
なわれず、図6(d)の状態となってしまう。
A specific operation in the conventional method of deleting a common subexpression statement that operates as described above will be described below. Figure 6
FIG. 4 is a schematic diagram showing an example of a process of deleting a common subexpression sentence by a conventional method of deleting a common subexpression sentence. Here, it is assumed that the operators can exchange the number of operations and that the calculation result is not converted. It is assumed that the formula sentence is in the state shown in FIG. The expression sentence is divided into partial expression sentences, and the state thereof is as shown in FIG. The divided sub-expression sentences are sequentially read, and the common sub-expression sentence determination unit is activated. The partial expression sentence A is read and it is determined whether or not it is registered in the partial expression sentence storage unit. As a result, it is determined that the sub-expression has not been registered, so the sub-expression is registered and the state shown in FIG. 6C is obtained. Next, the sub-expression sentence B is read, the common sub-expression sentence determination unit determines that it is not registered, and is registered in the sub-expression sentence storage unit. continue,
The subexpression sentence C is read and the common subexpression sentence determination unit is activated. The common subexpression statement determination unit determines that the subexpression statement is not registered, and as a result, the common subexpression statement of the expression statement is not deleted, resulting in the state of FIG. 6D.

【0006】[0006]

【発明が解決しようとする課題】しかしながら、従来の
共通部分式文の削除方法においては前述の具体例で説明
したように、式文を構成する識別子の選択が可能であ
り、適切な識別子の選択がなされれば共通部分式文とし
て削除可能なものが存在する場合でも、先立って別の識
別子が選択されていた場合には、共通部分式文が別のコ
ードに分割されてしまうためその削除ができなかった。
すなわち、図6においては、XとYには共通式文a+c
が存在するにもかかわらず、最終段階の(d)において
も結果的には削除されていない。
However, in the conventional method for deleting common subexpressions, the identifiers forming the expression sentence can be selected as described in the above-mentioned specific example, and the selection of an appropriate identifier is possible. Even if there is a common sub-expression statement that can be deleted, the common sub-expression statement will be split into another code if another identifier is selected in advance. could not.
That is, in FIG. 6, the common expression sentence a + c is assigned to X and Y.
Although it exists, it is not deleted even in the final stage (d).

【0007】本発明は、従来の共通部分式文を検出し、
最適な共通部分式文を選択することにより共通部分式文
を最も効率よく削除することが可能となる共通部分式文
の削除方法を提供することを目的とする。
The present invention detects conventional common subexpression sentences,
An object of the present invention is to provide a method of deleting a common subexpression statement that enables the most efficient deletion of the common subexpression statement by selecting the optimum common subexpression statement.

【0008】[0008]

【課題を解決するための手段】上記目的を達成するため
に、請求項1に係る発明においては式文を単一の演算で
構成される部分式文に分割する式文分割ステップと、前
記式文分割ステップで分割された部分式文に対して命令
コードとして分割可能なパターンを検出する部分式文パ
ターン検出ステップと、前記部分式文パターン検出ステ
ップで検出された部分式文パターンの中から式文の計算
に使用する部分式文を選択する部分式文パターン選択ス
テップと、式文の前記部分式文パターン選択ステップで
選択された部分式文を相応の識別子に変換する式文変換
ステップと、前記式文変換ステップにより変換された式
文の共通部分式文と相応じた識別子を別途保持するステ
ップとを有することを特徴としている。
In order to achieve the above object, in the invention according to claim 1, an expression sentence dividing step of dividing an expression sentence into sub-expression sentences composed of a single operation; A subexpression sentence pattern detection step of detecting a pattern that can be divided as an instruction code for the subexpression sentence divided in the sentence division step, and an expression from among the subexpression sentence patterns detected in the subexpression sentence pattern detection step. A sub-expression statement pattern selecting step of selecting a sub-expression statement used for statement calculation, and a sub-expression statement converting step of converting the sub-expression statement selected in the sub-expression statement pattern selecting step of the expression statement to a corresponding identifier, And a step of separately storing an identifier corresponding to the common sub-expression sentence of the expression sentence converted by the expression sentence conversion step.

【0009】請求項2に係る発明においては上記共通部
分式文パターンの選択が階層的になされることを特徴と
している。請求項3に係る発明においては式文を単一の
演算の式文に分割する式文分割部と、前記式文分割部で
分割された部分式文に対して命令コードとして分割可能
な部分式文パターンを検出する部分式文パターン検出部
と、前記部分式文パターン検出部で検出された部分式文
パターンの中から式文の計算に使用する部分式文を選択
する部分式文パターン選択部と、式文中の前記部分式文
パターン選択部で選択された部分式文を相応の識別子に
変換する式文変換部と、前記式文変換部で変換された式
文の共通部分式文と相応じた識別子とを別途保持する共
通部分式文識別子記憶部とを備えたことを特徴としてい
る。
The invention according to claim 2 is characterized in that the common sub-expression sentence pattern is selected hierarchically. In the invention according to claim 3, an expression statement division unit that divides an expression statement into expression statements of a single operation, and a partial expression that can be divided as an instruction code with respect to the partial expression statement divided by the expression statement division unit A sub-expression sentence pattern detection unit that detects a sentence pattern, and a sub-expression sentence pattern selection unit that selects a sub-expression sentence to be used for calculation of the expression sentence from the sub-expression sentence patterns detected by the sub-expression sentence pattern detection unit And an expression sentence conversion unit that converts the partial expression sentence selected by the partial expression sentence pattern selection unit in the expression sentence into a corresponding identifier, and a common partial expression sentence of the expression sentence converted by the expression sentence conversion unit. A common subexpression sentence identifier storage unit that separately holds a corresponding identifier is provided.

【0010】請求項4に係る発明においては上記共通部
分式文パターンの選択を階層的に行う手段を有すること
を特徴とする。
According to a fourth aspect of the invention, there is provided means for hierarchically selecting the common sub-expression sentence pattern.

【0011】[0011]

【作用】本発明の共通部分式文の削除手段は前記した構
成により、式文分割手段で演算単位毎の部分式文に分割
し、部分式文パターン検出部で分割可能な部分式文のパ
ターンを検出し、部分式文パターン選択部で式文の実際
の計算に使用する部分式文を選択し、式文変換手段で上
記選択された部分式文を変換し、変換された共通部分式
文と相応じた識別子とを別途保持することにより、コン
パイラにおける最適な演算手段を提供することを可能と
するものである。
With the above-described structure, the common sub-expression statement deleting means of the present invention divides into sub-expression statements for each operation unit by the expression statement dividing means, and the sub-expression statement pattern that can be divided by the sub-expression statement pattern detecting section. Is detected, the sub-expression statement pattern selecting unit selects a sub-expression statement to be used for the actual calculation of the expression statement, the expression sentence conversion means converts the selected sub-expression statement, and the converted common sub-expression statement By separately holding the corresponding identifiers, it is possible to provide the optimum arithmetic means in the compiler.

【0012】[0012]

【実施例】以下、本発明の共通部分式文の削除手段の一
実施例を図面を用いて説明する。図1は本発明に係る共
通部分式文の削除手段の一実施例の構成図である。図
中、1は式文分割部で、式文を単一演算で構成される部
分式文に分割するものである。2は部分式文パターン検
出部で、前記式文分割部で分割された部分式文をもと
に、命令コードの部分式文として分割可能な部分式文の
パターンを検出し、その付属部たる後述の部分式文記憶
部7にパターン毎にその出現回数をカウントさせるもの
である。3は部分式文パターン選択部で、前記部分式文
パターン検出部で検出された部分式文のパターンの中か
ら、式文の計算に際して最終的に採用する部分式文を選
択するものである。4は式文変換部で、前記部分式文パ
ターン選択部で選択された式文中の部分式文をそれに相
応する識別子に変換する。変換された部分式文は、最初
に計算が実行される部分式文以外は全て共通部分式文識
別子記憶部を起動させることとなる。5は共通部分式文
識別子記憶部で、前記式文変換部で相応する識別子に変
換された共通部分式文と相応の識別子を記憶するもので
ある。従って式文の演算においては、同一の識別子の間
においては最初に計算が実行された識別子の計算結果が
記憶された後他の式文の計算ではその結果が採用され
る。従って、式文の計算においては削除されたのと同じ
こととなる。6は共通部分式文階層的選択制御部で式文
中の選択された部分式文に相応する部分を識別子に還元
する操作が階層的になされるよう制御する。7は部分式
文記憶部であり、演算の種類毎に前記部分式文パターン
検出部2の指示のもと部分式文のパターン等の引数の数
に従って、N次元配列で記憶内容等が記憶されるもので
ある。以上の他、従来技術のコンパイラーと同じく各
種、各階層の識別子等を記憶し、また対応する記憶部、
式文にあたって必要な時に最初の計算結果を通知、提供
の上その計算に利用させる制御部等があるが、これらは
本発明の要旨ではないため図示していない。
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS An embodiment of the common subexpression deletion means of the present invention will be described below with reference to the drawings. FIG. 1 is a block diagram of an embodiment of a common sub-expression sentence deleting means according to the present invention. In the figure, reference numeral 1 denotes an expression statement dividing unit, which divides an expression statement into sub-expression statements composed of a single operation. Reference numeral 2 denotes a partial expression sentence pattern detection unit that detects a pattern of a partial expression sentence that can be divided as a partial expression sentence of an instruction code based on the partial expression sentence divided by the expression sentence division unit, and is a sub-unit of the pattern. The subexpression sentence storage unit 7 described later counts the number of appearances of each pattern. A partial expression sentence pattern selection unit 3 selects a partial expression sentence that is finally adopted in the calculation of the expression sentence from the patterns of the partial expression sentence detected by the partial expression sentence pattern detection unit. Reference numeral 4 denotes an expression sentence conversion unit, which converts the partial expression sentence in the expression sentence selected by the partial expression sentence pattern selection unit into an identifier corresponding thereto. All of the converted sub-expression sentences activate the common sub-expression sentence identifier storage unit except for the sub-expression sentence in which the calculation is first executed. A common sub-expression sentence identifier storage unit 5 stores the common sub-expression sentence converted into the corresponding identifier by the formula sentence conversion unit and the corresponding identifier. Therefore, in the calculation of the formula sentence, the calculation result of the identifier for which the calculation is first performed is stored between the same identifiers, and then the calculation result of the other formula sentence is adopted. Therefore, it is the same as deleted in the calculation of the formula sentence. Reference numeral 6 denotes a common sub-expression sentence hierarchical selection control unit, which controls so that a portion corresponding to the selected sub-expression sentence in the expression sentence is reduced to an identifier in a hierarchical manner. Reference numeral 7 denotes a partial expression sentence storage unit, which stores the stored contents and the like in an N-dimensional array according to the number of arguments such as the pattern of the partial expression sentence under the instruction of the partial expression sentence pattern detection unit 2 for each type of operation. It is something. In addition to the above, like the compiler of the prior art, stores various types, identifiers of each layer, and the like, a corresponding storage unit,
Although there is a control unit or the like for notifying and providing the first calculation result when it is necessary for the formula sentence and using it for the calculation, these are not shown because they are not the gist of the present invention.

【0013】以上のように動作する本実施例の共通部分
式文の削除装置における具体的な動作を次に説明する。
図3は本実施例の共通部分式文装置により共通部分式文
を削除する過程の一例を示す摸式図である。いま、式文
が同図(a)の状態であったとする。式文分割部1が式
文を( )(かっこ)で区切られた式文毎に分割し、そ
の結果、式文は(b)の状態となる。ここで、( )に
区切られた式文毎に分割するのはXとYの演算において
は、( )(かっこ)、+(足し算)、*(掛け算、本
明細書では×でなく*で示す。)が存在するが、この3
種の演算の中では( )が最優先されることによる。次
に、部分式文パターン検出部2は、分割された式文の中
で命令コードとして使用可能な部分式文パターンを検出
し、検出された部分式文のパターン毎にその出現回数を
部分式文記憶部7にカウントさせる。その内容を以下に
示す。
A specific operation of the common subexpression deleting apparatus according to this embodiment, which operates as described above, will be described below.
FIG. 3 is a schematic diagram showing an example of a process of deleting a common sub-expression sentence by the common sub-expression sentence device of this embodiment. Now, assume that the expression sentence is in the state shown in FIG. The expression sentence division unit 1 divides the expression sentence into each expression sentence separated by () (parentheses), and as a result, the expression sentence becomes the state of (b). Here, it is to divide each expression sentence delimited by () into () (parentheses), + (addition), * (multiplication, in this specification indicated by * instead of × in the operation of X and Y) .) Exists, but this 3
This is because () has the highest priority among the seed operations. Next, the sub-expression statement pattern detection unit 2 detects a sub-expression statement pattern that can be used as an instruction code in the divided expression statements, and the number of appearances of each sub-expression statement pattern is detected as a sub-expression. The sentence storage unit 7 is caused to count. The contents are shown below.

【0014】本実施例においては、分割された部分式文
中の演算は足し算のみであるため、部分式文パターン検
出部2のパターンの検出手段及び部分式文記憶部7の記
憶方法としては2次元行列が採用されている。図3
(c)において列の次元、行の次元のインデックスa,
b,c,dは各々+(足し算)の演算毎の部分式文を構
成する要素、すなわち演算子を表す。行列の各々の数値
は、インデックスとインデックスの組み合わせで構成さ
れる部分式文のパターンの全式文、すなわちXとYの計
算における出現回数を表す。本実施例においては2次元
行列の同じ列の部分式文のパターンは、同時に式文を分
割する部分式として採用することは不可能としているた
め、どの部分式文パターンを選択するのが最適かがこの
面から決定される。その選択手法を次に説明する。
In the present embodiment, since the operation in the divided partial expression sentence is only addition, the pattern detecting means of the partial expression sentence pattern detecting portion 2 and the storing method of the partial expression sentence storing portion 7 are two-dimensional. Matrix has been adopted. Figure 3
In (c), column dimension, row dimension index a,
Each of b, c, and d represents an element that constitutes a partial expression statement for each operation of + (addition), that is, an operator. Each numerical value of the matrix represents the number of appearances in the calculation of X and Y, that is, all the formula sentences of the pattern of the sub-formula sentence formed by the indexes and the combination of the indexes. In the present embodiment, the patterns of subexpression sentences in the same column of the two-dimensional matrix cannot be adopted as subexpressions that divide the expression sentence at the same time, so which subexpression sentence pattern should be selected optimally? Is determined from this aspect. The selection method will be described below.

【0015】インデックスaはcとXとYの演算におい
てペアとなるのが5回、それに対し、b,dとペアにな
るのは各々2回である。このため、部分式文パターン選
択部3はXとYの計算にあたり本階層で、最終的に採用
する部分式文パターンとしてa+cをa+b及びa+d
に優先させる。しかる後、式文変換部4は式文中の選択
された演算a+cを一次識別子s1に変換する。このた
めXとY中のa+b+cはs1+bに、Y中のa+b+
cはs1+dに変換される。そして、この形でXとYと
S1とS1に応じた部分式文a+cとが共通部分式文識
別子記憶部5に記憶される。これで+の演算についての
変換は終了する。これにより、X、Yは各々図3(d)
の状態になる。次に共通部分式文階層的選択制御部6の
働きにより*の演算Yについての部分式文の検討がなさ
れる。図3(e)の2次元行列において、列、行のイン
デックスs1,s1+b、s1+d、a+bは各々*の
演算毎の部分式文を構成する要素を表す。行列の数値は
インデックスとインデックスの組み合わせで構成される
部分式文のパターンの全式文、すなわちXとYの計算に
おける出現回数を表す。例えばs1は、s1+bとはペ
アで掛け算されることがX、Y双方に存在するためs1
は、s1行とs1+b列、あるいはs1列とs1+b行
の要素は2となる。行列の他の要素は、相異なるインデ
ックス相互の掛け算がXとYのいずれか一方にしかあら
われないため全て1である。このため、部分式文パター
ン選択部3は、XとYの計算として本階層で最終的に採
用する部分式文パターンとして、s1*(s1+b)を
選択する。選択された部分式文s1*(s1+b)は式
文変換部4により2次識別子t1に変換される。一方、
Yの要素(s1+d)は(s1+d)のままとなる。こ
れによりXとYは最終的には図3(f)のごとくなる。
そして、この形でX,Y,s1,t1及びs1とt1に
応じた各共通部分式文が共通部分式文識別子記憶部5に
記憶される。何故ならば、二次識別子の計算に先立ち、
その構成要素たる一次識別子の計算は必ずなされるから
である。従って、s1の計算が実行されるとその結果は
別途記憶され、通常のコンパイラと同じく制御部の働き
によりt1の計算及びYの計算過程における(s1+
d)の計算双方に使用されることとなる。なお、上記第
1実施例においては、同一レベルの演算は一種づつ、す
なわち+(足し算)のみ及び*(掛け算)のみであった
が、−(引き算)、/(割り算)が存在する場合には、
同一演算子(インデックス)でも演算が逆のものは別の
演算子(インデックス)とみなすことにより同じ手順で
部分式文パターンの選択がなされる。 (第2実施例)式文を今図3(g)に示すごとく、 U=(a+b+c)*(a+c)*(a+d) V=(a+c+d)*(a+c)/(a+b+c+e)
とする。 本第2実施例においては同一階層の演算においても一部
要素が重複して識別子に使用されるのが異なる。すなわ
ち、第1実施例と同じ手順で一次識別子s1が決定され
た段階、すなわち、図3(h)に示す段階で更に新たに
s1を1つの要素とみなした上で更に同じ演算、すなわ
ち+(足し算)での部分式文パターンの選択可能性が判
定される。図3(i)はこのための二次元行列を示す。
行s1と列bあるいは行bと列s1の数値は2、他は1
である。従って、X及びYのs1+bは新たに他の一次
識別子s2に置き換えられ、XとYは図3(j)の状態
となる。この状態では、XとYにはbと足し算をしない
s1が残っているため、これについては第1実施例にお
けるt1に対するs1と同じくs2とは別途その旨共通
部分式文識別子記憶部にて管理される。
The index a is paired 5 times in the operations of c, X and Y, while it is paired with b and d twice each. For this reason, the sub-expression statement pattern selection unit 3 uses a + c as a + b and a + d as the sub-expression statement pattern to be finally adopted in this layer when calculating X and Y.
Prioritize. Thereafter, the expression sentence conversion unit 4 converts the selected operation a + c in the expression sentence into the primary identifier s1. Therefore, a + b + c in X and Y becomes s1 + b, and a + b + in Y.
c is converted to s1 + d. Then, in this form, the subexpression sentence a + c corresponding to X, Y, S1, and S1 is stored in the common subexpression sentence identifier storage unit 5. This completes the conversion for the + operation. As a result, X and Y are respectively shown in FIG.
It becomes the state of. Next, the subexpression statement for the operation Y of * is examined by the function of the common subexpression statement hierarchical selection control unit 6. In the two-dimensional matrix of FIG. 3 (e), column and row indices s1, s1 + b, s1 + d, and a + b represent elements that form a subexpression statement for each operation *. Numerical values of the matrix represent the number of appearances in the calculation of X and Y, that is, all the formula sentences of the pattern of the sub-formula sentence composed of the indexes and the combinations of the indexes. For example, since s1 is multiplied by s1 + b in a pair, it exists in both X and Y, so s1
Has 2 elements in the s1 row and the s1 + b column or the s1 column and the s1 + b row. The other elements of the matrix are all 1's because the multiplications of the different indices appear only in either X or Y. For this reason, the sub-expression sentence pattern selection unit 3 selects s1 * (s1 + b) as the sub-expression sentence pattern to be finally adopted in this layer for the calculation of X and Y. The selected partial expression sentence s1 * (s1 + b) is converted into a secondary identifier t1 by the expression sentence conversion unit 4. on the other hand,
The element (s1 + d) of Y remains (s1 + d). As a result, X and Y finally become as shown in FIG.
Then, in this form, the common subexpression sentences corresponding to X, Y, s1, t1 and s1 and t1 are stored in the common subexpression sentence identifier storage unit 5. Because before the calculation of the secondary identifier,
This is because the calculation of the primary identifier that is the constituent element is always performed. Therefore, when the calculation of s1 is executed, the result is stored separately, and (s1 +
It will be used for both calculations in d). In the first embodiment, the operations at the same level are one type at a time, that is, only + (addition) and * (multiplication), but when-(subtraction) and / (division) are present, ,
Even if the same operator (index) has the opposite operation, it is regarded as another operator (index), and the subexpression sentence pattern is selected by the same procedure. (Second embodiment) As shown in FIG. 3 (g), U = (a + b + c) * (a + c) * (a + d) V = (a + c + d) * (a + c) / (a + b + c + e)
And In the second embodiment, some elements are duplicated and used as an identifier even in the operation of the same layer. That is, at the stage where the primary identifier s1 is determined by the same procedure as in the first embodiment, that is, at the stage shown in FIG. 3 (h), s1 is newly considered as one element, and the same calculation is performed, that is, + ( The possibility of selecting the partial expression sentence pattern by (addition) is determined. FIG. 3 (i) shows a two-dimensional matrix for this purpose.
The numerical value of row s1 and column b or row b and column s1 is 2, and the others are 1
Is. Therefore, s1 + b of X and Y is newly replaced by another primary identifier s2, and X and Y are in the state of FIG. 3 (j). In this state, since s1 that does not add to b remains in X and Y, this is managed separately in the common sub-expression statement identifier storage unit from s1 similar to s1 for t1 in the first embodiment. To be done.

【0016】以上、本発明を実施例に基づき説明してき
たが、本発明は何もこれらに限定されるものではない。
すなわち、演算をなすべき式文が多数あれば一次識別子
等は多数作成される。更に同一レベルの演算(例えば足
し算)での部分式文パターンの選択は2次元(例えばa
+bを選択するかa+cを選択するかあるいはb+cを
選択するか)でなされたが、同一レベルの演算子にて多
様な組み合わせの可能性が有る場合には高次元(例え
ば、a+b+cを選択するかa+bを選択するかa+c
を選択するかあるいはb+cを選択するか)でなされて
もよい。また、演算の種類が置換、累乗等多数存在すれ
ば、三次識別子、四次識別子等も作成される。その際、
部分式文の分割、部分式文のパターンの選択等は実施例
と同じく演算の優先度に応じてなされ、また部分式文選
択の優先度は出現回数に応じてなされるのが原則であ
る。しかし、式文、コンパイラの用途、内容等によって
は用途による重みづけ等が採用されてもよい。更に、単
なる部分式文のみならず、式文の結合、サブルーチン的
なものに応用されてもよい。更に、上記実施例はあくま
でも本発明の要旨を説明したものであり、実際にはコン
パイラとして充分使用可能なごとく他の機能が付加され
ているのは勿論である。例えば、a+cをs1に変換し
た際に、a+b+c=s1+bと、あるいは本実施例に
おける式文XとYの計算のみではその必要性は少ないが
更にs1+c=r2と、他の必要な変換及びそれに伴う
必要な削除、式文W中の(a+b+c)*(a+c)と
式文Z中の(a+c)*(a+b+c)とが同じ演算で
あることを認識する、逆に演算子と演算の配列上は同じ
式文であっても意味内容等が異なる場合にはその旨を認
識する、識別子の必要な記憶及び二次のものより一次の
ものが優先する等計算の順位の優先度の決定、必要に応
じての計算結果の記憶等である。更にまた、全式文を通
じての最適な共通部分式文のパターンの選択、すなわち
削除に先立って、演算毎に分割された部分式文を一時的
に他の識別子に置き換える、例えば実施例1における式
文分割部が式文XとYとをカッコで区切られた部分式文
に分割した段階(図3(b)の段階)で、各分割された
式文a+b+c,a+c,a+d,a+c+d,a+c
を各々一時識別子r1,r2,r3,r4とおき、X=
r1*r2*r3 Y=r4*r2*r1と表す、等の
操作がなされてもよいのも勿論である。
Although the present invention has been described based on the embodiments, the present invention is not limited thereto.
That is, if there are many expression sentences to be operated, many primary identifiers are created. Furthermore, the selection of the sub-expression sentence pattern in the same level of operation (eg addition) is two-dimensional (eg a
+ B, a + c, or b + c is selected), but if there are various combinations of operators at the same level, a higher dimension (for example, a + b + c should be selected) Select a + b or a + c
Is selected or b + c is selected). Also, if there are many types of operations such as substitution and exponentiation, a tertiary identifier, a quaternary identifier, etc. are created. that time,
As in the embodiment, the division of the sub-expression sentence, the selection of the pattern of the sub-expression sentence, etc. are made according to the priority of the operation, and the priority of the sub-expression sentence selection is made in accordance with the number of appearances. However, depending on the expression sentence, the purpose of the compiler, the content, etc., weighting according to the purpose may be adopted. Furthermore, the present invention may be applied not only to simple sub-expression statements, but also to combination of expression statements and subroutines. Furthermore, the above-described embodiment is merely an explanation of the gist of the present invention, and it goes without saying that other functions are added so that it can be sufficiently used as a compiler in practice. For example, when a + c is converted to s1, a + b + c = s1 + b, or s1 + c = r2, which is less necessary only by calculation of the formula sentences X and Y in this embodiment, and other necessary conversions and Necessary deletion, recognize that (a + b + c) * (a + c) in formula sentence W and (a + c) * (a + b + c) in formula sentence Z are the same operation. Recognize the fact that the meanings are different even if they are the same expression sentence, memorize necessary identifiers and determine the priority of calculation order, such that the primary one has priority over the secondary one. For example, the calculation result is stored in memory. Furthermore, prior to selection of the optimum common subexpression sentence pattern among all the expression sentences, that is, deletion, the subexpression sentence divided for each operation is temporarily replaced with another identifier, for example, the expression in the first embodiment. At the stage where the sentence dividing unit divides the expression sentences X and Y into parenthesized sub-expression sentences (stage in FIG. 3B), each divided expression sentence a + b + c, a + c, a + d, a + c + d, a + c.
As temporary identifiers r1, r2, r3, r4, respectively, and X =
Of course, operations such as r1 * r2 * r3 Y = r4 * r2 * r1 may be performed.

【0017】[0017]

【発明の効果】以上説明したように本発明に係る共通部
分式文の削除装置においては、共通部分式文に成り得る
全ての部分式文のパターンを検出し、最適な部分式文の
パーンが比較検討された上で最適な共通部分式文の選
択、識別子への変換がなされる。また、共通部分式文と
なる部分式文の演算の順番に関係なく共通部分式文の演
算の削除も可能となる。このため、コンパイラ最適化技
術としての実用的効果は大きい。
As described above, in the common sub-expression sentence deleting apparatus according to the present invention, the patterns of all sub-expression sentences that can be a common sub-expression sentence are detected, and the optimum sub-expression sentence pattern is determined. After comparison and examination, the optimum common subexpression sentence is selected and converted into an identifier. Further, it is possible to delete the operation of the common sub-expression statement regardless of the order of operation of the sub-expression statements that become the common sub-expression statement. Therefore, the practical effect as a compiler optimization technique is great.

【図面の簡単な説明】[Brief description of drawings]

【図1】本発明の一実施例の共通部分式文の削除装置の
構成図である。
FIG. 1 is a configuration diagram of a common sub-expression statement deletion device according to an embodiment of the present invention.

【図2】本発明の一実施例の共通部分式文削除方法のフ
ローチャートである。
FIG. 2 is a flowchart of a common subexpression sentence deletion method according to an embodiment of the present invention.

【図3】本発明の一実施例の共通部分式文の削除装置に
より式文の共通部分式文を削除する過程を示す模式図で
ある。
FIG. 3 is a schematic diagram showing a process of deleting a common sub-expression sentence of a formula sentence by a common sub-expression sentence deleting device according to an embodiment of the present invention.

【図4】従来の共通部分式文の削除装置の構成図であ
る。
FIG. 4 is a block diagram of a conventional common subexpression deletion device.

【図5】従来の共通部分式文の削除装置により共通部分
式文の削除する手順を示すフローチャートである。
FIG. 5 is a flowchart showing a procedure for deleting a common sub-expression sentence by a conventional common sub-expression sentence deleting device.

【図6】従来の共通部分式文の削除装置による共通部分
式文の削除の過程を示す模式図である。
FIG. 6 is a schematic diagram showing a process of deleting a common sub-expression sentence by a conventional common sub-expression sentence deleting device.

【符号の説明】[Explanation of symbols]

1 式文分割部 2 部分式文パターン検出部 3 部分式文パターン選択部 4 式文変換部 5 共通部分式文識別子記憶部 6 共通部分式文階層的選択制御部 7 部分式文記憶部 1 Expression sentence division unit 2 Partial expression sentence pattern detection unit 3 Partial expression sentence pattern selection unit 4 Expression sentence conversion unit 5 Common partial expression sentence identifier storage unit 6 Common partial expression sentence hierarchical selection control unit 7 Sub expression sentence storage unit

Claims (4)

【特許請求の範囲】[Claims] 【請求項1】 式文を単一の演算で構成される部分式文
に分割する式文分割ステップと、 前記式文分割ステップで分割された部分式文に対して命
令コードとして分割可能なパターンを検出する部分式文
パターン検出ステップと、 前記部分式文パターン検出ステップで検出された部分式
文パターンの中から式文の計算に使用する部分式文を選
択する部分式文パターン選択ステップと、 式文の前記部分式文パターン選択ステップで選択された
部分式文を相応の識別子に変換する式文変換ステップ
と、 前記式文変換ステップにより変換された式文の共通部分
式文と相応じた識別子を別途保持するステップとを有す
ることを特徴とする共通部分式文の削除方法。
1. An expression statement division step of dividing an expression statement into subexpression statements composed of a single operation, and a pattern that can be divided as an instruction code with respect to the subexpression statements divided in the expression statement division step. A sub-expression sentence pattern detecting step of detecting, a sub-expression sentence pattern selecting step of selecting a sub-expression sentence used in the calculation of the expression sentence from the sub-expression sentence pattern detected in the sub-expression sentence pattern detecting step, An expression statement conversion step of converting the sub-expression statement selected in the sub-expression statement pattern selection step of the expression statement into a corresponding identifier, and a common sub-expression statement corresponding to the expression statement converted by the expression statement conversion step. And a step of holding an identifier separately, the method of deleting a common subexpression statement.
【請求項2】 上記共通部分式文パターンの選択が階層
的になされることを特徴とする請求項1記載の共通部分
式文の削除方法。
2. The method for deleting a common sub-expression sentence according to claim 1, wherein the selection of the common sub-expression sentence pattern is performed hierarchically.
【請求項3】 式文を単一の演算の式文に分割する式文
分割部と、 前記式文分割部で分割された部分式文に対して命令コー
ドとして分割可能な部分式文パターンを検出する部分式
文パターン検出部と、 前記部分式文パターン検出部で検出された部分式文パタ
ーンの中から式文の計算に使用する部分式文を選択する
部分式文パターン選択部と、 式文中の前記部分式文パターン選択部で選択された部分
式文を相応の識別子に変換する式文変換部と、 前記式文変換部で変換された式文の共通部分式文と相応
じた識別子とを別途保持する共通部分式文識別子記憶部
とを備えたことを特徴とする共通部分式文の削除装置。
3. An expression statement division unit that divides an expression statement into expression statements of a single operation, and a partial expression statement pattern that can be divided as an instruction code with respect to the partial expression statement divided by the expression statement division unit. A sub-expression sentence pattern detection unit for detecting, a sub-expression sentence pattern selection unit for selecting a sub-expression sentence to be used for calculation of the expression sentence from the sub-expression sentence patterns detected by the sub-expression sentence pattern detection unit, and an expression An expression statement conversion unit that converts the sub-expression statement selected by the sub-expression statement pattern selection unit in the sentence into a corresponding identifier, and an identifier corresponding to the common sub-expression statement of the expression statement converted by the expression statement conversion unit And a common subexpression sentence identifier storage section for separately holding and.
【請求項4】 上記共通部分式文パターンの選択を階層
的に行う手段を有することを特徴とする請求項3記載の
共通部分式文の削除装置。
4. The apparatus for deleting a common sub-expression sentence according to claim 3, further comprising means for hierarchically selecting the common sub-expression sentence pattern.
JP21511791A 1991-08-27 1991-08-27 Method and device for erasing common partial expressional sentence Pending JPH0553822A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP21511791A JPH0553822A (en) 1991-08-27 1991-08-27 Method and device for erasing common partial expressional sentence

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP21511791A JPH0553822A (en) 1991-08-27 1991-08-27 Method and device for erasing common partial expressional sentence

Publications (1)

Publication Number Publication Date
JPH0553822A true JPH0553822A (en) 1993-03-05

Family

ID=16667030

Family Applications (1)

Application Number Title Priority Date Filing Date
JP21511791A Pending JPH0553822A (en) 1991-08-27 1991-08-27 Method and device for erasing common partial expressional sentence

Country Status (1)

Country Link
JP (1) JPH0553822A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2004051470A1 (en) * 2002-12-05 2004-06-17 System's Co.,Ltd. Program automatic converting method and program automatic converting device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2004051470A1 (en) * 2002-12-05 2004-06-17 System's Co.,Ltd. Program automatic converting method and program automatic converting device
US7831964B2 (en) 2002-12-05 2010-11-09 System's Co., Ltd. Program automatic converting method and program automatic converting device

Similar Documents

Publication Publication Date Title
DE60034926D1 (en) System and method for optimizing a variety of operating and control parameters in a nuclear reactor
JPH06103463B2 (en) Code generation method
US6925639B2 (en) Method and system for register allocation
US20060156292A1 (en) Program automatic converting method and program automatic converting device
JPH0553822A (en) Method and device for erasing common partial expressional sentence
JP2002527816A (en) Program optimization apparatus and method
JPH01118931A (en) Program conversion system
JP3318051B2 (en) Translation processing method
JP3461185B2 (en) Method and apparatus for registering source code line number to load module
JPH0117175B2 (en)
JP3637606B2 (en) Data processing device
JPH0744397A (en) Program processing accelerating system
JP3580394B2 (en) Program conversion device and program conversion method
JPH0619721A (en) Machine language translation optimizing system
JPH02204835A (en) Rule type program executing method
JP2507676B2 (en) Index I / O statement execution processing method
JPH05289867A (en) Multibranch branching control system
JPS62251849A (en) Access optimizing system for data base
JPH06208470A (en) Objective code optimizing device
JPH07141198A (en) Method for optimizing compiling
JPH04241630A (en) System for optimizing register allocation by graph painting
JPH086689A (en) Complementation system for comand input time
JPH02222032A (en) Optimization system for addition/subtraction instruction
JPH03211627A (en) Data type conversion system
JPH04273572A (en) Input option recognition system