JPH07168719A - Redundant type removing device - Google Patents

Redundant type removing device

Info

Publication number
JPH07168719A
JPH07168719A JP5313289A JP31328993A JPH07168719A JP H07168719 A JPH07168719 A JP H07168719A JP 5313289 A JP5313289 A JP 5313289A JP 31328993 A JP31328993 A JP 31328993A JP H07168719 A JPH07168719 A JP H07168719A
Authority
JP
Japan
Prior art keywords
cost
arithmetic expression
detected
type
operand
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.)
Granted
Application number
JP5313289A
Other languages
Japanese (ja)
Other versions
JP3313859B2 (en
Inventor
Nobuteru Tominaga
宣輝 富永
Akira Tanaka
旭 田中
Jiyunko Irikou
旬子 入交
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 JP31328993A priority Critical patent/JP3313859B2/en
Publication of JPH07168719A publication Critical patent/JPH07168719A/en
Application granted granted Critical
Publication of JP3313859B2 publication Critical patent/JP3313859B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Abstract

PURPOSE:To remove an operation expression to be redundant by comparing cost before and after the reload of a program and reloading arithmetic in the program later. CONSTITUTION:A cost extracting part 7 retrieves a cost storage part 5 and extracts the cost, and first, second and third reloading cost extracting parts 8, 9 and 10 reload an element to be calculated by arithmetic, retrieve a cost storage part 5 and an addressing cost storage part 6 with the reloaded arithmetic and extract the cost of arithmetic. A comparison part 11 compares the extracted cost. When the cost extracted by the first, second and third reloading cost extracting parts 8, 9 and 10 is smaller as the result of comparison, reloading is performed, and the redundant operation expression is removed.

Description

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

【0001】[0001]

【産業上の利用分野】本発明は、高級言語で書かれたソ
ースプログラムを機械語プログラムに翻訳するコンパイ
ラに備えられ、処理対象となるプログラムから冗長とな
る演算式を除去する冗長式除去装置に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a redundant expression removing device which is provided in a compiler for translating a source program written in a high-level language into a machine language program and removes redundant arithmetic expressions from a program to be processed. .

【0002】[0002]

【従来の技術】近年、C言語などの高級言語でプログラ
ムを記述し、プログラムの開発効率を高めることが盛ん
に行われている。これら高級言語で記述されたソースプ
ログラムは様々なコンパイラを使用することによってコ
ンピュータが理解可能な機械語プログラムに翻訳され
る。
2. Description of the Related Art In recent years, programs have been written in a high-level language such as C language to improve program development efficiency. Source programs written in these high-level languages are translated into machine language programs that can be understood by a computer by using various compilers.

【0003】コンパイラは、最終的に作成する機械語プ
ログラムの実行時間をより短く、メモリサイズをより小
さくするため(最終的に作成する機械語プログラムの実
行時間、あるいは、メモリサイズを一括してコストと呼
ぶ。)、プログラマか作成したソースプログラム、ある
いは、コンパイラが内部処理を行うために作成した中間
言語プログラムに対して様々な処理を施している。この
ようにコストを低減させる方法のひとつにプログラム中
から、冗長な演算式を削除する方法がある。このような
冗長な演算式(この演算式を冗長式と呼ぶ。)の削除を
行うため、従来のコンパイラは、様々な削除方法によっ
て冗長式の除去を行う冗長式除去装置を備えている。冗
長式除去装置について説明する前に、使用する用語につ
いて以下に定義する。 ・演算 例えば、100*x+2、x/200+yのように、変
数、定数、および演算子から構成されるプログラムのコ
ードをいう。 ・演算式 例えば、y=130、y=100*x+2、y=x/2
00+10のように、等号の左側に変数が存在し、また
右側に演算が存在する式である。 ・変数の定義 例えば、a=b+c、s=100*2のように、演算に
よって、変数の中身を設定することである。 ・変数の使用 演算の被演算子に変数を使用することである。 ・スタック変数 スタック領域のメモリ上に置く変数のことである。 ・静的変数 スタック領域外の特定のアドレスのメモリ上に置く変数
のことである。 ・レジスタ変数 レジスタ上に置く変数のことである。 第1に、共通部分式の削除を行う冗長式除去装置につい
て説明する。共通部分式の削除とは、全く同一の演算を
行う演算が、プログラム中に複数個存在する場合、それ
らのうちの1つだけを残して、他のものを全て削除する
処理をいう。図10は、共通部分式の削除を行う冗長式
除去装置の構成図である。
The compiler shortens the execution time of the machine language program finally created and reduces the memory size (execution time of the machine language program finally created, or the memory size collectively The source program created by the programmer, or the intermediate language program created by the compiler to perform internal processing is subjected to various processing. One of the methods of reducing the cost in this way is to delete redundant arithmetic expressions from the program. In order to delete such a redundant arithmetic expression (this arithmetic expression is referred to as a redundant expression), the conventional compiler is equipped with a redundant expression removing device that removes the redundant expression by various deleting methods. Before describing the redundant removal device, the terms used are defined below. -Operation This refers to the code of a program composed of variables, constants, and operators, such as 100 * x + 2 and x / 200 + y. Calculation formula For example, y = 130, y = 100 * x + 2, y = x / 2
This is an expression in which a variable exists on the left side of the equal sign and an operation exists on the right side, such as 00 + 10. Definition of variables The contents of variables are set by calculation, for example, a = b + c, s = 100 * 2. -Use of variables The use of variables as operands of operations. -Stack variable A variable that is placed on the memory of the stack area. -Static variable A variable that is placed on the memory at a specific address outside the stack area. -Register variables These are variables placed on registers. First, a redundant type elimination device for eliminating common sub-expressions will be described. Deletion of a common subexpression means a process in which, when a plurality of operations for performing the same operation are present in a program, only one of them is left and all others are deleted. FIG. 10 is a block diagram of a redundant type removal device that deletes a common sub-expression.

【0004】共通部分式の削除を行う冗長式除去装置
(図中の共通部分式の削除を行う装置)は、演算出現場
所検出部22と、結果使用場所検出部23と、被演算子
書き換え部24と、演算式除去部25と、処理対象保持
部26とで構成される。演算出現場所検出部22は、被
演算子が全く同一の演算を、処理対象保持部26に保持
されているプログラムから全て検出する。具体的には、
演算出現場所検出部22は、処理対象保持部26に保持
されているプログラム中の、全ての演算の演算子、被演
算子を比較し(被演算子が変数である場合、その変数の
中身を比較に用いる。)、被演算子が同一の演算を全て
検出する。検出後、演算出現場所検出部22は、その演
算が等号の右辺に存在する演算式の位置を、演算式除去
部25に通知する(この演算式を共通部分式と呼
ぶ。)。また、検出した演算によって定義される変数を
検出し、これらの変数で、第1番目に位置する変数(こ
の変数を指定変数と呼ぶ。)を被演算子書き換え部24
に出力し、2番目以降に位置する変数(これの変数を削
除変数と呼ぶ。)を結果使用場所検出部23に出力す
る。
A redundant expression removing device for deleting common sub-expressions (device for deleting common sub-expressions in the figure) is a calculation appearance place detecting section 22, a result use place detecting section 23, and an operator rewriting section. 24, an arithmetic expression removing unit 25, and a processing target holding unit 26. The operation appearance location detection unit 22 detects all the operations whose operands are exactly the same from the programs stored in the processing target storage unit 26. In particular,
The operation appearance location detection unit 22 compares the operators and operands of all operations in the program held in the processing target holding unit 26 (if the operand is a variable, the contents of the variable are It is used for comparison.), And all operations whose operands are the same are detected. After the detection, the operation appearance place detection unit 22 notifies the arithmetic expression removal unit 25 of the position of the arithmetic expression whose operation exists on the right side of the equal sign (this arithmetic expression is referred to as a common subexpression). Also, variables defined by the detected operation are detected, and among these variables, the variable located first (this variable is referred to as the designated variable) is the operand rewriting unit 24.
And outputs the second and subsequent variables (these variables are called deletion variables) to the result use place detection unit 23.

【0005】結果使用場所検出部23は、前記演算出現
場所検出部22から削除変数を受け取り、削除変数が、
被演算子として用いられているような演算(この演算を
書き換え演算式と呼ぶ。)を検出して、検出した位置
を、被演算子書き換え部24に通知する。被演算子書き
換え部24は、演算出現場所検出部22から指定変数を
受け取り、結果使用場所検出部23から知らされた位置
の書き換え演算式で、被演算子として使用されている削
除変数を、指定変数に書き換える。
The result use place detection unit 23 receives the deletion variable from the operation appearance place detection unit 22, and the deletion variable is
An operation used as an operand (this operation is called a rewriting arithmetic expression) is detected, and the detected position is notified to the operator rewriting unit 24. The operand rewriting unit 24 receives the designated variable from the operation appearance location detection unit 22 and designates the deletion variable used as the operand in the rewriting arithmetic expression of the position notified from the result use location detection unit 23. Rewrite as a variable.

【0006】演算式除去部25は、演算出現場所検出部
22から知らされた位置の演算式を削除する。処理対象
保持部26は、処理対象となるプログラムを保持する。
尚、保持されるプログラムは、プログラマによって記述
されたソースコードで記述されていてもよいし、コンパ
イラが内部処理の都合上生成した内部コードで記述され
ていてもよい。
The arithmetic expression removing section 25 deletes the arithmetic expression at the position notified from the arithmetic appearance location detecting section 22. The processing target holding unit 26 holds a program to be processed.
The program to be held may be written in the source code written by the programmer or may be written in the internal code generated by the compiler for the convenience of internal processing.

【0007】以上のように構成された共通部分式の除去
を行う冗長式除去装置が、図11に示すようなプログラ
ムに対して共通部分式の削除を行う。先ず、演算出現場
所検出部22が、矢符a1、a2、a3に示す演算を検
出する。次に結果使用場所検出部23が、削除変数であ
るx1、y1が被演算子として使用されている演算(図
中の矢符b1、b2に示す演算)を検出する。検出後、
被演算子書き換え部24は、矢符b1、b2の演算の被
演算子を、図12の矢符c1、c2のように指定変数x
に書き換える。その結果、このプログラムは、図12に
示すように書き換えられる。
The redundant type elimination device configured as described above for eliminating common sub-expressions removes common sub-expressions from a program as shown in FIG. First, the calculation appearance location detection unit 22 detects the calculation indicated by the arrows a1, a2, and a3. Next, the result use place detection unit 23 detects the operation (the operation shown by the arrows b1 and b2 in the figure) in which the deletion variables x1 and y1 are used as the operands. After detection,
The operand rewriting unit 24 replaces the operands of the operations of the arrows b1 and b2 with the designated variable x as indicated by the arrows c1 and c2 of FIG.
Rewrite As a result, this program is rewritten as shown in FIG.

【0008】第2に値の伝搬を行う冗長式除去装置につ
いて説明する。値の伝搬とは、演算で、被演算子として
使用されている変数を、同じ値を持つ変数あるいは定数
に書き換えて、その被演算子として使用されている変数
の演算式を、プログラム中から削除することである。図
13は、値の伝搬を行う冗長式除去装置の構成図であ
る。
Secondly, a redundant type elimination device for propagating a value will be described. In value propagation, the variable used as an operand in an operation is rewritten as a variable or constant with the same value, and the arithmetic expression of the variable used as the operand is deleted from the program. It is to be. FIG. 13 is a block diagram of a redundant removal device that propagates a value.

【0009】値の伝搬を行う冗長式除去装置(図中の値
の伝搬を行う装置)は、代入出現場所検出部32と、結
果使用場所検出部33と、被演算子書き換え部34と、
代入除去部35と、処理対象保持部36とで構成され
る。代入出現場所検出部32は、変数を定数に代入する
演算式、あるいは、変数に変数を代入する演算式を、処
理対象保持部36に保持されているプログラムから全て
検出し、演算式の位置を、代入除去部35に通知する。
更に検出した演算式によって定義される変数(この変数
をも削除変数と呼ぶ。)を検出して、被演算子書き換え
部34に出力する。また、上記の演算式で、等号の右辺
に存在する変数、定数(これらを指定代入数と呼ぶ。)
を被演算子書き換え部34に出力する。
The redundant type elimination device (propagation device for propagating values in the figure) for propagating a value has a substitution appearance place detecting section 32, a result using place detecting section 33, an operand rewriting section 34,
The substitution removing unit 35 and the processing target holding unit 36 are included. The substitution appearance location detection unit 32 detects all arithmetic expressions for substituting variables for constants or arithmetic expressions for substituting variables for variables from the program stored in the processing target storage unit 36, and determines the position of the arithmetic expression. , The substitution removing unit 35 is notified.
Further, a variable defined by the detected arithmetic expression (this variable is also called a deletion variable) is detected and output to the operand rewriting unit 34. Further, in the above arithmetic expression, variables and constants existing on the right side of the equal sign (these are called designated substitution numbers).
Is output to the operator rewriting unit 34.

【0010】結果使用場所検出部33は、代入出現場所
検出部32から削除変数を受け取り、削除変数が、被演
算子として用いられているような演算(この演算を書き
換え演算式と呼ぶ。)を検出して、検出した位置を、被
演算子書き換え部34に通知する。被演算子書き換え部
34は、代入出現場所検出部32から指定代入数を受け
取り、結果使用場所検出部33から知らされた位置の書
き換え演算式で、被演算子として使用されている削除変
数を、指定代入数に書き換える。
The result use place detection unit 33 receives the deletion variable from the substitution appearance place detection unit 32, and performs an operation in which the deletion variable is used as an operand (this operation is called a rewriting operation expression). Then, the detected position is notified to the operator rewriting unit 34. The operand rewriting unit 34 receives the designated number of substitutions from the substitution appearance place detection unit 32, and in the rewriting arithmetic expression of the position notified from the result use place detection unit 33, deletes the deletion variable used as the operand, Rewrite to the specified substitution number.

【0011】代入除去部35は、結果使用場所検出部3
3から知らされた位置の演算式を削除する。処理対象保
持部36は、処理対象保持部26と同様に、処理対象と
なるプログラムを保持する。以上のように構成された値
の伝搬を行う冗長式除去装置が、図14に示すようなプ
ログラムに対して値の伝搬を行う。先ず代入出現場所検
出部32が、矢符d1に示す演算式を検出し、次に結果
使用場所検出部33が、矢符e1、e2に示す演算を検
出する。検出後、被演算子書き換え部24は、矢符e
1、e2の演算の被演算子を、図15の矢符f1、f2
のように指定代入数4000に書き換える。その結果、
このプログラムは、図15に示すように書き換えられ
る。
The substitution removing unit 35 is a result use place detecting unit 3
The arithmetic expression of the position notified from 3 is deleted. The processing target holding unit 36 holds the program to be processed, similar to the processing target holding unit 26. The redundant removal device configured to propagate the value configured as described above propagates the value to the program as shown in FIG. First, the substitution appearance place detection unit 32 detects the arithmetic expression shown by the arrow d1, and then the result use place detection unit 33 detects the calculation shown by the arrows e1 and e2. After the detection, the operand rewriting unit 24 displays the arrow e
The operands of the operations 1 and e2 are represented by the arrows f1 and f2 in FIG.
The designated substitution number 4000 is rewritten as follows. as a result,
This program is rewritten as shown in FIG.

【0012】[0012]

【発明が解決しようとする課題】しかしながら上記従来
技術によれば、共通部分式の削除および値の伝搬を行う
冗長式除去装置は、処理対象となる演算の被演算子が、
定数、レジスタ変数、スタック変数、静的変数の何れか
に該当するかを調べることなく被演算子の書き換えを行
っていたので、書き換えによってかえってコストが高く
なってしまうことがあるという問題点があった。
However, according to the above-mentioned prior art, in the redundant expression elimination device that deletes common sub-expressions and propagates values, the operands of the operations to be processed are
Since the operand is rewritten without checking whether it corresponds to a constant, a register variable, a stack variable, or a static variable, there is a problem that the rewriting may increase the cost. It was

【0013】また、ターゲットマシンのプロセッサが、
インデックスおよびオフセット付きの間接アドレス参
照、オフセット付きの間接アドレス参照等、アドレッシ
ングモードを使用することができる場合、コンパイラ
は、これらのアドレッシングモードを、有効に活用でき
るような演算の書き換えが行えないので、コストの低減
が充分に図れていないという問題点があった。
Further, the processor of the target machine is
When addressing modes such as indirect address reference with index and offset, indirect address reference with offset, etc. can be used, the compiler cannot rewrite operations that can effectively use these addressing modes. There is a problem that the cost cannot be reduced sufficiently.

【0014】例えば、図11、図14に示したプログラ
ムで、変数xはスタック領域に置かれるスタック変数で
あり、変数x1、y1はレジスタ上に置かれるレジスタ
変数であるとする。一般にスタック変数は、スタック領
域のメモリをアクセスする必要があり、レジスタ変数よ
りコストが高い。そのため、レジスタ変数x1、y1が
使用されている演算をスタック変数xに書き換えると、
書き換えによってプログラム全体のコストは高くなるこ
ともある。また、機械語命令において、16ビット以上
の定数値を被演算子とする演算は、その被演算子を機械
語命令のオペランドに記述する必要があり、レジスタ、
メモリを被演算子とする演算に比べてコストが高いこと
が多い。そのため、図7の変数xを、16ビット以上の
定数値に書き換えた場合、書き換えによってプログラム
全体のコストは高くなることもある。
For example, in the programs shown in FIGS. 11 and 14, it is assumed that the variable x is a stack variable placed in the stack area and the variables x1 and y1 are register variables placed in a register. Generally, the stack variable needs to access the memory in the stack area, and is more expensive than the register variable. Therefore, if the operation in which the register variables x1 and y1 are used is rewritten to the stack variable x,
Rewriting may increase the cost of the entire program. In addition, in a machine language instruction, for an operation that uses a constant value of 16 bits or more as an operand, it is necessary to describe the operand in the operand of the machine language instruction.
It is often more expensive than operations that use memory as the operand. Therefore, when the variable x in FIG. 7 is rewritten to a constant value of 16 bits or more, the rewriting may increase the cost of the entire program.

【0015】また、図16(a)は、C言語のポインタ
変数を用いて、アドレスの計算を記述したプログラムの
一部であり、図16(b)は、これらの変数の資源割り
付けの結果である。また、ターゲットマシンのプロセッ
サは、2オペランド形式のプロセッサであるが、図16
(c)に示すようなアドレスレジスタ間接参照も行え
る。このようにアドレッシングモードを利用できるよう
な状況でも、コンパイラが行う書き換えは、2オペラン
ド形式のプロセッサに対する書き換えであり、図16
(c)のアドレッシングモードの機械語命令と対応させ
るように、演算を書き換えることはできない。そのた
め、コンパイラは、このようなアドレスレジスタ間接参
照を行う機械語命令を、機械語プログラムの翻訳の過程
において用いることはできず、その分だけプログラムの
コストは高くなる。
Further, FIG. 16A shows a part of a program in which address calculation is described by using pointer variables of C language, and FIG. 16B shows a result of resource allocation of these variables. is there. The processor of the target machine is a two-operand type processor.
Address register indirect reference as shown in (c) can also be performed. Even in such a situation that the addressing mode can be used, the rewriting performed by the compiler is the rewriting for the 2-operand format processor.
The operation cannot be rewritten so as to correspond to the machine language instruction in the addressing mode of (c). Therefore, the compiler cannot use the machine language instruction for performing such address register indirect reference in the process of translating the machine language program, and the cost of the program increases accordingly.

【0016】本発明は、上記問題点に鑑み、演算の被演
算子を書き換える前に、その書き換えが有効であるか否
かを判定し、書き換えが有効であるならば、被演算子を
書き換え、書き換えによって不要となる演算式を除去
し、更にアドレッシングモードが、有効利用されるよう
に演算を書き換える冗長式除去装置を提供することを目
的とする。
In view of the above problems, the present invention judges whether or not rewriting is effective before rewriting the operand of an operation, and if the rewriting is effective, rewrites the operand, An object of the present invention is to provide a redundant expression removing device that removes unnecessary arithmetic expressions by rewriting and further rewrites operations so that the addressing mode is effectively used.

【0017】[0017]

【課題を解決するための手段】上記課題を解決するため
に本発明の冗長式除去装置は、コンパイラに備えられ、
プログラム保持手段に保持されているプログラムの演算
を書き換えて、書き換え後、冗長な演算式を除去する冗
長式除去装置であって、プログラム保持手段のプログラ
ムから演算子、被演算子が同一の演算を全て検出し、当
該演算によって定義されている全ての変数を検出して、
検出した演算と変数とを含む演算式の位置を記憶する演
算検出手段と、演算検出手段が検出した変数のうち2番
目以降に位置する変数が、被演算子として使用されてい
る演算を全て検出する被演算子検出手段と、演算式の型
と、演算式の型がこれらの型に該当する演算式のコスト
とを記憶するコスト記憶手段と、被演算子検出手段が検
出した演算式の型でコスト記憶手段を検索し、当該演算
式の型に対応するコストを取り出す第1のコスト取出手
段と、被演算子検出手段が検出した演算式の被演算子
に、演算検出手段が検出した変数のうち1番目に位置す
る変数を用いた場合の演算式の型でコスト記憶手段を検
索し、当該演算式の型に対応するコストを取り出す第2
のコスト取出手段と、第1のコスト取出手段が取り出し
たコストと、第2のコスト取出手段が取り出したコスト
とを比較する比較手段と、比較手段が比較した結果、第
2のコスト取出手段が取り出したコストが小さければ、
被演算子検出手段が検出した演算で、被演算子として使
用されている変数のプログラム中の位置を、演算検出手
段が1番目に検出した変数に書き換える書き換え手段
と、被演算子検出手段が検出した全ての演算中の変数
を、書き換え手段が書き換えた場合、被演算子検出手段
が検出した演算で被演算子として使用されていた変数
と、その変数が定義されていた演算とを含む演算式を、
プログラム中から除去する除去手段とを備えている。
In order to solve the above-mentioned problems, the redundant type elimination device of the present invention is provided in a compiler,
A redundant expression removing device that rewrites the operation of a program held in the program holding means and removes a redundant arithmetic expression after rewriting, in which an operator and an operand are the same operation from the program of the program holding means. Detect all, detect all variables defined by the operation,
The operation detecting means for storing the position of the operation expression including the detected operation and the variable, and the variables located after the second among the variables detected by the operation detecting means detect all the operations used as the operands. Cost detecting means for storing the operand detection means, the type of the arithmetic expression, and the cost of the arithmetic expression corresponding to these types, and the type of the arithmetic expression detected by the operand detecting means The first cost extraction means for extracting the cost corresponding to the type of the arithmetic expression by the cost storage means and the operand of the arithmetic expression detected by the operand detection means and the variable detected by the operation detection means. Second, the cost storage unit is searched for the type of the arithmetic expression when the variable located first is used to retrieve the cost corresponding to the type of the arithmetic expression.
Of the cost take-out means, the cost taken out by the first cost take-out means, and the cost taken out by the second cost take-out means, and the result of the comparison means comparing, the second cost take-out means is If the cost of taking out is small,
Rewriting means for rewriting the position in the program of the variable used as the operand to the variable detected first by the operation detecting means by the operation detected by the operator detecting means, and detected by the operator detecting means When the rewriting means rewrites all the variables under operation, the operation expression including the variable used as the operand in the operation detected by the operand detecting means and the operation in which the variable was defined To
And removing means for removing from the program.

【0018】また、第1のコスト取出手段は、取り出し
たコストの総和を求め、第2のコスト取出手段は、取り
出したコストの総和を求めて、比較手段は、第1のコス
ト取出手段が求めたコストの総和と、第2のコスト取出
手段が求めたコストの総和とを比較してもよい。また、
比較手段は、第1のコスト取出手段が取り出した個別の
コストと、第2のコスト取出手段が取り出した個別のコ
ストとを比較してもよい。
The first cost take-out means obtains the total sum of the taken-out costs, the second cost take-out means obtains the total sum of the taken-out costs, and the comparison means obtains the first cost take-out means. The total sum of the costs may be compared with the total sum of the costs obtained by the second cost extraction means. Also,
The comparison means may compare the individual cost extracted by the first cost extraction means with the individual cost extracted by the second cost extraction means.

【0019】また、コンパイラに備えられ、プログラム
保持手段に保持されているプログラムの演算を書き換え
て、書き換え後、冗長な演算式を除去する冗長式除去装
置であって、プログラム保持手段のプログラムから演算
子、被演算子が同一の演算を全て検出し、当該演算によ
って定義されている全ての変数を検出して、検出した演
算と変数とを含む演算式の位置を記憶する演算検出手段
と、演算検出手段が検出した変数のうち2番目以降に位
置する変数が、被演算子として使用されている演算を全
て検出する被演算子検出手段と、演算式の型と、演算式
の型がこれらの型に該当する演算式のコストとを記憶す
るコスト記憶手段と、被演算子検出手段が検出した演算
式の型でコスト記憶手段を検索し、当該演算式の型に対
応するコストを取り出す第1のコスト取出手段と、演算
検出手段が検出した演算のうち、2番目以降に位置する
演算を含む演算式についての演算式の型でコスト記憶手
段を検索し、当該演算式の型に対応するコストを取り出
す冗長式コスト取出手段と第1のコスト取出手段が取り
出したコストと、冗長式コスト取出手段が取り出したコ
ストとの和を求める算出手段と被演算子検出手段が検出
した演算式の被演算子に、演算検出手段が検出した変数
のうち1番目に位置する変数を用いた場合の演算式の型
でコスト記憶手段を検索し、当該演算式の型に対応する
コストを取り出す第2のコスト取出手段と、算出手段が
求めたコストの和と、第2のコスト取出手段が取り出し
たコストとを比較する比較手段と比較手段が比較した結
果、第2のコスト取出手段が取り出したコストが小さけ
れば、被演算子検出手段が検出した演算で、被演算子と
して使用されている変数のプログラム中の位置を、演算
検出手段が1番目に検出した変数に書き換える書き換え
手段と、被演算子検出手段が検出した全ての演算中の変
数を、書き換え手段が書き換えた場合、被演算子検出手
段が検出した演算で被演算子として使用されていた変数
と、その変数が定義されていた演算とを含む演算式を、
プログラム中から除去する除去手段とを備えていてもよ
い。
Further, the redundancy removing apparatus is provided in the compiler and rewrites the operation of the program held in the program holding means, and removes redundant arithmetic expressions after the rewriting. Operation detecting means for detecting all operations having the same child and operand, detecting all variables defined by the operations, and storing the position of the operation expression including the detected operation and the variables; Among the variables detected by the detection means, the second and subsequent variables are the operand detection means for detecting all the operations used as the operands, the type of the arithmetic expression, and the type of the arithmetic expression. The cost storage means for storing the cost of the arithmetic expression corresponding to the type and the cost storage means for the type of the arithmetic expression detected by the operand detection means are searched for the cost corresponding to the type of the arithmetic expression. The cost storage means is searched for with an arithmetic expression type of an arithmetic expression including a first cost extracting means to be issued and an arithmetic operation positioned after the first operation among the operations detected by the operation detecting means, and the type of the arithmetic expression is obtained. A calculating means for obtaining the sum of the costs taken out by the redundant type cost taking means for taking out the corresponding costs and the first cost taking means and the costs taken out by the redundant type cost taking means, and the arithmetic expression detected by the operand detection means The cost storage means is searched for by the type of the arithmetic expression when the variable located first among the variables detected by the arithmetic detection means is used as the operand of, and the cost corresponding to the type of the arithmetic expression is extracted. As a result of comparison between the comparison means and the comparison means for comparing the sum of the costs obtained by the second cost extraction means and the calculation means with the costs extracted by the second cost extraction means, the second cost extraction means extracts the costs. If the cost is small, the rewriting means for rewriting the position in the program of the variable used as the operand by the operation detected by the operand detecting means to the variable detected first by the operation detecting means; When the rewriting means rewrites all the variables in the operation detected by the operator detecting means, the variable used as the operand in the operation detected by the operand detecting means and the variable are defined. An arithmetic expression that includes and
A removing means for removing from the program may be provided.

【0020】また、第1のコスト取出手段は、取り出し
たコストの総和を求め、算出手段は、第1のコスト取手
段が取り出したコストの総和と、冗長式コスト取出手段
が取り出したコストとの和を求め、第2のコスト取出手
段は、取り出したコストの総和を求めて、比較手段は、
算出手段が求めたコストの和と、第2のコスト取出手段
が求めたコストの総和とを比較するようにしてもよい。
Further, the first cost take-out means obtains the sum of the taken out costs, and the calculating means takes the sum of the costs taken out by the first cost taking means and the cost taken out by the redundant type cost take-out means. The second cost extraction means calculates the sum, and the comparison means calculates the sum of the extracted costs.
You may make it compare the sum of the cost calculated | required by the calculation means, and the sum total of the cost calculated | required by the 2nd cost extraction means.

【0021】また、算出手段は、第1のコスト取手段が
取り出した個別のコストと、冗長式コスト取出手段が取
り出したコストとの和を求め、比較手段は、算出手段が
求めたコストの和と、第2のコスト取出手段が求めた個
別のコストとを比較するようにしてもよい。また、コン
パイラに備えられ、プログラム保持手段に保持されてい
るプログラムの演算を書き換えて、書き換え後、冗長な
演算式を除去する冗長式除去装置であって、プログラム
保持手段に保持されているプログラムから、変数に定数
を代入する演算式、及び、変数に変数の値を代入する演
算式を全て検出する演算式検出手段と、演算式検出手段
が検出した演算式の等号の左側に存在する変数が、被演
算子として使用される演算式をプログラム保持手段から
全て検出する被演算子検出手段と、演算式の型と、演算
式の型がこれらの型に該当する演算式のコストとを記憶
するコスト記憶手段と、被演算子検出手段が検出した演
算式の型でコスト記憶手段を検索し、当該演算式の型に
対応するコストを取り出す第1のコスト取出手段と、被
演算子検出手段が検出した演算式の被演算子に、演算式
検出手段が検出した変数のうち1番目に位置する変数を
用いた場合の演算式の型でコスト記憶手段を検索し、当
該演算式の型に対応するコストを取り出す第2のコスト
取出手段と、第1のコスト取出手段が取り出したコスト
と、第2のコスト取出手段が取り出したコストとを比較
する比較手段と、第1のコスト取出手段が取り出したコ
ストと、第2のコスト取出手段が検出したコストとを比
較する比較手段と、比較手段が比較した結果、第2のコ
スト取出手段が取り出したコストが小さければ、被演算
子検出手段が検出した演算で被演算子として使用されて
いる変数のプログラム中の位置を、演算式検出手段が検
出した変数あるいは定数に書き換える書き換え手段と、
被演算子検出手段が検出した全ての演算中の変数を、書
き換え手段が書き換えた場合、被演算子検出手段が検出
した演算で被演算子として使用されていた変数が等号の
左側に存在する演算式であり、かつ、演算式検出手段が
検出した演算式を、プログラム中から除去する除去手段
とを備えている。
The calculating means obtains the sum of the individual costs taken out by the first cost taking means and the cost taken out by the redundant cost taking means, and the comparing means gives the sum of the costs obtained by the calculating means. And the individual costs obtained by the second cost extraction means may be compared. In addition, a redundant removal device that is provided in the compiler, rewrites the operation of the program held in the program holding means, and removes a redundant arithmetic expression after the rewriting. , An arithmetic expression for substituting a constant for a variable, and an arithmetic expression detecting means for detecting all arithmetic expressions for substituting the value of a variable for a variable, and a variable existing on the left side of the equal sign of the arithmetic expression detected by the arithmetic expression detecting means. Stores the operand detection means for detecting all the arithmetic expressions used as operands from the program holding means, the type of the arithmetic expression, and the cost of the arithmetic expression whose arithmetic expression type corresponds to these types. First cost extraction means for extracting the cost corresponding to the type of the arithmetic expression by searching the cost storage means with the type of the arithmetic expression detected by the operand detection means, and the operand The cost storage means is searched with the type of the arithmetic expression when the variable located first in the variables detected by the arithmetic expression detecting means is used as the operand of the arithmetic expression detected by the outputting means, Second cost extraction means for extracting the cost corresponding to the mold, comparison means for comparing the cost extracted by the first cost extraction means with the cost extracted by the second cost extraction means, and the first cost extraction If the cost extracted by the means and the cost detected by the second cost extracting means are compared with each other by the comparing means, and if the cost extracted by the second cost extracting means is small, the operand detection is performed. Rewriting means for rewriting the position in the program of the variable used as the operand in the operation detected by the means to the variable or constant detected by the operation expression detecting means,
When the rewriting means rewrites all variables in the operation detected by the operand detection means, the variable used as the operand in the operation detected by the operand detection means exists on the left side of the equal sign. And a removal unit that removes from the program an arithmetic expression that is an arithmetic expression and that is detected by the arithmetic expression detection unit.

【0022】また、第1のコスト取出手段は、取り出し
たコストの総和を求め、第2のコスト取出手段は、取り
出したコストの総和を求めて、比較手段は、第1のコス
ト取出手段が求めたコストの総和と、第2のコスト取出
手段が求めたコストの総和とを比較するようにしてもよ
い。また、比較手段は、第1のコスト取出手段が取り出
した個別のコストと、第2のコスト取出手段が取り出し
た個別のコストとを比較するようにしてもよい。
Further, the first cost take-out means obtains the total sum of the taken out costs, the second cost take-out means obtains the total sum of the taken out costs, and the comparison means obtains the first cost take-out means. The total sum of the costs may be compared with the total sum of the costs obtained by the second cost extraction means. Further, the comparing means may compare the individual cost extracted by the first cost extracting means with the individual cost extracted by the second cost extracting means.

【0023】また、コンパイラに備えられ、プログラム
保持手段に保持されているプログラムの演算を書き換え
て、書き換え後、冗長な演算式を除去する冗長式除去装
置であって、プログラム保持手段に保持されているプロ
グラムから、変数に定数を代入する演算式、及び、変数
に変数の値を代入する演算式を全て検出する演算式検出
手段と、演算式検出手段が検出した演算式の等号の左側
に存在する変数が、被演算子として使用される演算式を
プログラム保持手段から全て検出する被演算子検出手段
と、演算式の型と、演算式の型がこれらの型に該当する
演算式のコストとを記憶するコスト記憶手段と、被演算
子検出手段が検出した演算式の型でコスト記憶手段を検
索し、当該演算式の型に対応するコストを取り出す第1
のコスト取出手段と、演算式検出手段が検出した演算式
の演算式の型でコスト記憶手段を検索し、当該演算式の
型に対応するコストを取り出す冗長式コスト取出手段と
第1のコスト取出手段が取り出したコストと、冗長式コ
スト取出手段が取り出したコストとの和を求める算出手
段と被演算子検出手段が検出した演算式の被演算子に、
演算式検出手段が検出した変数のうち1番目に位置する
変数を用いた場合の演算式の型でコスト記憶手段を検索
し、当該演算式の型に対応するコストを取り出す第2の
コスト取出手段と、算出手段が求めたコストの和と、第
2のコスト取出手段が取り出したコストとを比較する比
較手段と比較手段が比較した結果、第2のコスト取出手
段が取り出したコストが小さければ、被演算子検出手段
が検出した演算で被演算子として使用されている変数の
プログラム中の位置を、演算式検出手段が検出した変数
あるいは定数に書き換える書き換え手段と、被演算子検
出手段が検出した全ての演算中の変数を、書き換え手段
が書き換えた場合、被演算子検出手段が検出した演算で
被演算子として使用されていた変数が等号の左側に存在
する演算式であり、かつ、演算式検出手段が検出した演
算式を、プログラム中から除去する除去手段とを備える
ことを特徴とする冗長式除去装置また、第1のコスト取
出手段は、取り出したコストの総和を求め、算出手段
は、第1のコスト取手段が取り出したコストの総和と、
冗長式コスト取出手段が取り出したコストとの和を求
め、第2のコスト取出手段は、取り出したコストの総和
を求めて、比較手段は、算出手段が求めたコストの和
と、第2のコスト取出手段が求めたコストの総和とを比
較するようにしてもよい。
Further, the redundant type removing device is provided in the compiler and rewrites the operation of the program held in the program holding means and removes the redundant arithmetic expression after the rewriting, and is held in the program holding means. To the left side of the equal sign of the arithmetic expression detected by the arithmetic expression detection means and the arithmetic expression that substitutes the value of the variable into the variable Operand detection means for detecting all operation expressions used as operands from the program holding means, existing operation types, operation expression types, and operation expression costs where the operation expression types correspond to these types A cost storage means for storing and a cost storage means for searching the cost storage means by the type of the arithmetic expression detected by the operand detection means, and extracting a cost corresponding to the type of the arithmetic expression
Redundant cost take-out means and first cost take-out means for searching the cost storage means with the type of the arithmetic expression of the arithmetic expression detected by the arithmetic expression detecting means and taking out the cost corresponding to the type of the arithmetic expression The cost extracted by the means and the calculation means for obtaining the sum of the costs extracted by the redundant cost extraction means and the operand of the arithmetic expression detected by the operand detection means,
Second cost extraction means for searching the cost storage means with the type of the arithmetic expression when the variable located first in the variables detected by the arithmetic expression detection means is used and for extracting the cost corresponding to the type of the arithmetic expression And the comparison means for comparing the sum of the costs calculated by the calculation means and the costs extracted by the second cost extraction means, and the comparison means, if the cost extracted by the second cost extraction means is small, Rewriting means for rewriting the position in the program of the variable used as the operand in the operation detected by the operand detection means to the variable or constant detected by the arithmetic expression detection means and the operand detection means detected When the rewriting means rewrites all the variables in the calculation, the variable used as the operand in the calculation detected by the operand detecting means is an arithmetic expression on the left side of the equal sign. And, the redundant expression removing device characterized by comprising a removing means for removing the arithmetic expression detected by the arithmetic expression detecting means from the program, and the first cost extracting means obtains the total of the extracted costs, The calculation means calculates the sum of the costs extracted by the first cost acquisition means,
The second cost extracting means obtains the sum of the extracted costs, the second cost extracting means obtains the total of the extracted costs, and the comparing means obtains the sum of the costs obtained by the calculating means and the second cost. You may make it compare with the sum total of the cost which the extraction means calculated.

【0024】また、算出手段は、第1のコスト取手段が
取り出した個別のコストと、冗長式コスト取出手段が取
り出したコストとの和を求め、比較手段は、算出手段が
求めたコストの和と、第2のコスト取出手段が求めた個
別のコストとを比較するようにしてもよい。また、コン
パイラに備えられ、プログラム保持手段に保持されてい
るプログラムの演算を書き換えて、書き換え後、冗長な
演算式を除去する冗長式除去装置であって、プログラム
保持手段のプログラムから、ポインタである変数が定義
されている演算式を検出し、検出した演算および変数が
含まれる演算式の位置を記憶する演算検出手段と、演算
検出手段が検出した変数が、被演算子として使用されて
いる演算式を全て検出する被演算子検出手段と、1つの
機械語命令で実行可能な演算式であり、かつ、ポインタ
に使用される被演算子、インデックスに使用される被演
算子、およびオフセットに使用される被演算子のうち、
少なくとも2つの被演算子を含むものの型と、当該演算
式の型に対応する演算式のコストとを記憶するコスト記
憶手段と、被演算子検出手段が検出した演算式で、コス
ト記憶手段を検索し、当該演算式に対応する演算式のコ
ストを取り出す第1のコスト取出手段と、被演算子検出
手段が検出した演算式の被演算子に、前記演算検出手段
が検出した演算を当てはめた場合の演算式の型で、コス
ト記憶手段を検索し、当該演算式に対応するコストを取
り出す第2のコスト取出手段と、第1のコスト取出手段
が取り出したコストと、第2のコスト取出手段が取り出
したコストとを比較する比較手段と、比較手段が比較し
た結果、第2のコスト取出手段が取り出したコストが小
さければ、被演算子検出手段が検出した演算式で、被演
算子として使用されている変数のプログラム中の位置
を、演算検出手段が検出した演算に書き換える書き換え
手段と、被演算子検出手段が検出した全ての演算式中の
変数を、書き換え手段が書き換えた場合、演算検出手段
が検出した演算を含む演算式を、プログラム中から除去
する除去手段とを備えている。
The calculating means obtains the sum of the individual costs taken out by the first cost taking means and the cost taken out by the redundant cost taking means, and the comparing means gives the sum of the costs obtained by the calculating means. And the individual costs obtained by the second cost extraction means may be compared. Further, it is a redundant type removing device which is provided in the compiler, rewrites the operation of the program held in the program holding means, and removes a redundant arithmetic expression after the rewriting, and is a pointer from the program of the program holding means. An operation detecting unit that detects an operation expression in which a variable is defined and stores the detected operation and the position of the operation expression including the variable, and an operation in which the variable detected by the operation detecting unit is used as an operand. Operand detecting means for detecting all expressions, and an arithmetic expression that can be executed by one machine language instruction, and is used as an operand used for a pointer, an operand used for an index, and an offset Of the operands that are
The cost storage means is searched by a cost storage means for storing the type of the one including at least two operands, the cost of the arithmetic expression corresponding to the type of the arithmetic expression, and the arithmetic expression detected by the operand detection means. When the operation detected by the operation detecting means is applied to the first cost extracting means for extracting the cost of the arithmetic expression corresponding to the arithmetic expression and the operand of the arithmetic expression detected by the operand detecting means The second cost extraction means for searching the cost storage means and extracting the cost corresponding to the calculation expression by the type of the arithmetic expression, the cost extracted by the first cost extraction means, and the second cost extraction means If the cost extracted by the second cost extraction means is small as a result of comparison by the comparison means for comparing the extracted cost with the comparison means, it is used as the operand in the arithmetic expression detected by the operand detection means. Rewriting means for rewriting the position of the variable in the program to the operation detected by the operation detecting means, and when the rewriting means rewrites the variables in all the arithmetic expressions detected by the operand detection means, the operation detecting means And a removing unit that removes the arithmetic expression including the arithmetic operation detected by the program.

【0025】また、第1のコスト取出手段は、取り出し
たコストの総和を求め、第2のコスト取出手段は、取り
出したコストの総和を求めて、比較手段は、第1のコス
ト取出手段が求めたコストの総和と、第2のコスト取出
手段が求めたコストの総和とを比較するようにしてもよ
い。また、比較手段は、第1のコスト取出手段が取り出
した個別のコストと、第2のコスト取出手段が取り出し
た個別のコストとを比較するようにしてもよい。
Further, the first cost take-out means obtains the total sum of the taken-out costs, the second cost take-out means obtains the total sum of the taken-out costs, and the comparison means obtains the first cost take-out means. The total sum of the costs may be compared with the total sum of the costs obtained by the second cost extraction means. Further, the comparing means may compare the individual cost extracted by the first cost extracting means with the individual cost extracted by the second cost extracting means.

【0026】また、コンパイラに備えられ、プログラム
保持手段に保持されているプログラムの演算を書き換え
て、書き換え後、冗長な演算式を除去する冗長式除去装
置であって、プログラム保持手段のプログラムから、ポ
インタである変数が定義されている演算式を検出し、検
出した演算および変数が含まれる演算式の位置を記憶す
る演算検出手段と、演算検出手段が検出した変数が、被
演算子として使用されている演算式を全て検出する被演
算子検出手段と、1つの機械語命令で実行可能な演算式
であり、かつ、ポインタに使用される被演算子、インデ
ックスに使用される被演算子、およびオフセットに使用
される被演算子のうち、少なくとも2つの被演算子を含
むものの型と、当該演算式の型に対応する演算式のコス
トとを記憶するコスト記憶手段と、被演算子検出手段が
検出した演算式で、コスト記憶手段を検索し、当該演算
式に対応する演算式のコストを取り出す第1のコスト取
出手段と、演算検出手段が検出した演算のうち、2番目
以降に位置する演算を含む演算式についての演算式の型
でコスト記憶手段を検索し、当該演算式の型に対応する
コストを取り出す冗長式コスト取出手段と第1のコスト
取出手段が取り出したコストと、冗長式コスト取出手段
が取り出したコストとの和を求める算出手段と被演算子
検出手段が検出した演算式の被演算子に、演算検出手段
が検出した変数のうち1番目に位置する変数を用いた場
合の演算式の型でコスト記憶手段を検索し、当該演算式
の型に対応するコストを取り出す第2のコスト取出手段
と、算出手段が求めたコストの和と、第2のコスト取出
手段が取り出したコストとを比較する比較手段と比較手
段が比較した結果、第2のコスト取出手段が取り出した
コストが小さければ、被演算子検出手段が検出した演算
式で、被演算子として使用されている変数のプログラム
中の位置を、演算検出手段が検出した演算に書き換える
書き換え手段と、被演算子検出手段が検出した全ての演
算式中の変数を、書き換え手段が書き換えた場合、演算
検出手段が検出した演算を含む演算式を、プログラム中
から除去する除去手段とを備えていてもよい。
Further, the redundancy removing apparatus is provided in the compiler and rewrites the operation of the program held in the program holding means, and removes the redundant arithmetic expression after the rewriting. An operation detection unit that detects an operation expression that defines a variable that is a pointer and stores the detected operation and the position of the operation expression that includes the variable, and the variable that the operation detection unit detects are used as operands. Operator detecting means for detecting all the arithmetic expressions that are present, an arithmetic expression that is an arithmetic expression that can be executed by one machine language instruction, and that is used as a pointer, an operand that is used as an index, and Of the operands used for the offset, a type that stores at least two operands and a cost of the arithmetic expression corresponding to the type of the arithmetic expression The first cost extraction means for extracting the cost of the arithmetic expression corresponding to the arithmetic expression by the cost storage means and the arithmetic expression detected by the operand detection means, and the operation detection means Redundant type cost extraction means for searching the cost storage means with an operation expression type of an operation expression including an operation positioned after the second operation and extracting a cost corresponding to the operation expression type and the first cost Among the variables detected by the operation detection means, the operand of the arithmetic expression detected by the calculation means and the operand detection means for obtaining the sum of the cost extracted by the extraction means and the cost extracted by the redundant type cost extraction means The sum of the cost obtained by the second cost extraction means that retrieves the cost corresponding to the type of the arithmetic expression by searching the cost storage means with the type of the arithmetic expression when the variable located first is used, and the cost calculated by the calculation means. When As a result of comparison between the comparison means and the comparison means for comparing the cost extracted by the second cost extraction means, if the cost extracted by the second cost extraction means is small, the arithmetic expression detected by the operand detection means Rewriting means for rewriting the position of the variable used as the operand in the program to the operation detected by the operation detecting means, and rewriting means for rewriting the variables in all arithmetic expressions detected by the operand detecting means In this case, the arithmetic expression including the arithmetic operation detected by the arithmetic operation detecting means may be removed from the program.

【0027】また、第1のコスト取出手段は、取り出し
たコストの総和を求め、算出手段は、第1のコスト取手
段が取り出したコストの総和と、冗長式コスト取出手段
が取り出したコストとの和を求め、第2のコスト取出手
段は、取り出したコストの総和を求めて、比較手段は、
算出手段が求めたコストの和と、第2のコスト取出手段
が求めたコストの総和とを比較するようにしてもよい。
Further, the first cost take-out means obtains the total sum of the taken out costs, and the calculation means takes the sum of the costs taken out by the first cost take-out means and the cost taken out by the redundant type cost take-out means. The second cost extraction means calculates the sum, and the comparison means calculates the sum of the extracted costs.
You may make it compare the sum of the cost calculated | required by the calculation means, and the sum total of the cost calculated | required by the 2nd cost extraction means.

【0028】また、算出手段は、第1のコスト取手段が
取り出した個別のコストと、冗長式コスト取出手段が取
り出したコストとの和を求め、比較手段は、算出手段が
求めたコストの和と、第2のコスト取出手段が求めた個
別のコストとを比較するようにしてもよい。また、前記
コスト記憶手段が記憶するコストとは、演算式の型に対
応する機械語命令の実行時間および/またはメモリサイ
ズであることを特徴としてもよい。
The calculating means obtains the sum of the individual costs taken out by the first cost taking means and the cost taken out by the redundant cost taking means, and the comparing means gives the sum of the costs obtained by the calculating means. And the individual costs obtained by the second cost extraction means may be compared. Further, the cost stored in the cost storage means may be the execution time and / or the memory size of the machine language instruction corresponding to the type of the arithmetic expression.

【0029】[0029]

【作用】上記の手段により本発明の冗長式除去装置にお
いて、プログラム保持手段のプログラムに対して、演算
検出手段が作動し、演算子、被演算子が同一の演算が全
て検出され、当該演算によって定義されている全ての変
数を検出されて、検出した演算と変数とを含む演算式の
位置が記憶される。演算検出手段が検出した変数のうち
2番目以降に位置する変数に対して、被演算子検出手段
が作動し、被演算子として使用されている演算が全て検
出される。コスト記憶手段には、演算式の型と、演算式
の型がこれらの型に該当する演算式のコストとが記憶さ
れ、当該コスト記憶手段に対して、第1のコスト取出手
段によって、被演算子検出手段が検出した演算式の型に
よる検索が行われ、当該演算式の型に対応するコストを
取り出される。またコスト記憶手段に対して、第2のコ
スト取出手段によって、被演算子検出手段が検出した演
算式の被演算子に、演算検出手段が検出した変数のうち
1番目に位置する変数を用いた場合の演算式の型で検索
が行われ、当該演算式の型に対応するコストを取り出さ
れる。取り出し後、第1のコスト取出手段が取り出した
コストと、第2のコスト取出手段が取り出したコストと
で、比較手段によって比較が行われる。比較手段が比較
した結果、第2のコスト取出手段が取り出したコストが
小さければ、被演算子検出手段が検出した演算で、被演
算子として使用されている変数のプログラム中の位置
が、書き換え手段によって、演算検出手段が1番目に検
出した変数に書き換えられる。被演算子検出手段が検出
した全ての演算中の変数を、書き換え手段が書き換えた
場合、被演算子検出手段が検出した演算で被演算子とし
て使用されていた変数と、その変数が定義されていた演
算とを含む演算式とが、除去手段によってプログラム中
から除去される。
With the above-mentioned means, in the redundant type elimination apparatus of the present invention, the operation detecting means operates for the program of the program holding means, and all the operations having the same operator and operand are detected. All the defined variables are detected, and the position of the arithmetic expression including the detected operation and the variable is stored. Among the variables detected by the calculation detecting means, the operand detecting means operates for the second and subsequent variables, and all the operations used as the operands are detected. The cost storage means stores the types of the arithmetic expressions and the costs of the arithmetic expressions corresponding to these types of arithmetic expressions, and the first cost extraction means operates the cost storage means for the operands. The type of the arithmetic expression detected by the child detection means is searched, and the cost corresponding to the type of the arithmetic expression is extracted. Further, with respect to the cost storage means, the variable located first in the variables detected by the operation detecting means is used as the operand of the arithmetic expression detected by the operand detecting means by the second cost extracting means. In this case, a search is performed with the type of the arithmetic expression, and the cost corresponding to the type of the arithmetic expression is extracted. After taking out, the comparison means compares the cost taken out by the first cost taking means with the cost taken out by the second cost taking means. As a result of comparison by the comparison means, if the cost taken out by the second cost extraction means is small, the position in the program of the variable used as the operand in the operation detected by the operand detection means is rewritten by the rewriting means. By this, the calculation detecting means is rewritten to the first detected variable. When the rewriting means rewrites all variables in the operation detected by the operand detecting means, the variables used as the operand in the operation detected by the operand detecting means and the variables are defined. The arithmetic expression including the calculated arithmetic operation is removed from the program by the removing unit.

【0030】また、上記手段により本発明の冗長式除去
装置において、演算式検出手段によって、プログラム保
持手段に保持されているプログラムから、変数に定数を
代入する演算式、及び、変数に変数の値を代入する演算
式が全て検出される。被演算子検出手段によって、演算
式検出手段が検出した演算式の等号の左側に存在する変
数が、被演算子として使用される演算式が、プログラム
保持手段から全て検出される。コスト記憶手段には、演
算式の型と、演算式の型がこれらの型に該当する演算式
のコストとを記憶され、第1のコスト取出手段によっ
て、被演算子検出手段が検出した演算式の型でコスト記
憶手段の検索が行われ、当該演算式の型に対応するコス
トを取り出される。第2のコスト取出手段によって、被
演算子検出手段が検出した演算式の被演算子に、演算式
検出手段が検出した変数のうち1番目に位置する変数を
用いた場合の演算式の型でコスト記憶手段を検索され、
当該演算式の型に対応するコストを取り出される。第1
のコスト取出手段が取り出したコストと、第2のコスト
取出手段が取り出したコストとを比較手段が比較し、比
較手段が比較した結果、第2のコスト取出手段が取り出
したコストが小さければ、被演算子検出手段が検出した
演算で被演算子として使用されている変数のプログラム
中の位置が、書き換え手段によって演算式検出手段が検
出した変数あるいは定数に書き換えられる。被演算子検
出手段が検出した全ての演算中の変数を、書き換え手段
が書き換えた場合、被演算子検出手段が検出した演算で
被演算子として使用されていた変数が等号の左側に存在
する演算式であり、かつ、演算式検出手段が検出した演
算式が、除去手段によってプログラム中から除去され
る。
Further, in the redundant type elimination apparatus of the present invention by the above means, the arithmetic expression detecting means, by the arithmetic expression detecting means, substitutes a constant into the variable from the program held in the program holding means, and the value of the variable in the variable. All arithmetic expressions substituting for are detected. The operator detecting means detects, from the program holding means, all the arithmetic expressions used as operands of the variables existing on the left side of the equal sign of the arithmetic expression detected by the arithmetic expression detecting means. The cost storage means stores the types of the arithmetic expressions and the costs of the arithmetic expressions corresponding to the types of the arithmetic expressions, and the arithmetic expressions detected by the operand detecting means by the first cost extracting means. The cost storage means is searched with the type of, and the cost corresponding to the type of the arithmetic expression is retrieved. In the type of the arithmetic expression when the second cost extracting means uses the variable located first in the variables detected by the arithmetic expression detecting means as the operand of the arithmetic expression detected by the operand detecting means. Search the cost storage means,
The cost corresponding to the type of the arithmetic expression is retrieved. First
The cost taken out by the cost take-out means and the cost taken out by the second cost take-out means are compared by the comparison means, and as a result of the comparison means comparing, if the cost taken out by the second cost take-out means is small, The position in the program of the variable used as the operand in the operation detected by the operator detecting means is rewritten by the rewriting means to the variable or constant detected by the arithmetic expression detecting means. When the rewriting means rewrites all variables in the operation detected by the operand detection means, the variable used as the operand in the operation detected by the operand detection means exists on the left side of the equal sign. The arithmetic expression which is an arithmetic expression and which is detected by the arithmetic expression detecting means is removed from the program by the removing means.

【0031】また、上記手段により本発明の冗長式除去
装置において、演算検出手段によって、プログラム保持
手段のプログラムから、ポインタである変数が定義され
ている演算式が検出され、検出した演算および変数が含
まれる演算式の位置が記憶される。演算検出手段が検出
した変数が、被演算子として使用されている演算式が、
被演算子検出手段によって全て検出される。コスト記憶
手段には、1つの機械語命令で実行可能な演算式であ
り、かつ、ポインタに使用される被演算子、インデック
スに使用される被演算子、およびオフセットに使用され
る被演算子のうち、少なくとも2つの被演算子を含むも
のの型と、当該演算式の型に対応する演算式のコストと
が記憶される。被演算子検出手段が検出した演算式で、
第1のコスト取出手段によって、当該記憶手段が検索さ
れ、当該演算式に対応する演算式のコストを取り出され
る。第2のコスト取出手段によって、被演算子検出手段
が検出した演算式の被演算子に、前記演算検出手段が検
出した演算を当てはめた場合の演算式の型で、コスト記
憶手段を検索され、当該演算式に対応するコストを取り
出される。比較手段によって第1のコスト取出手段が取
り出したコストと、第2のコスト取出手段が取り出した
コストとが比較される。比較手段が比較した結果、第2
のコスト取出手段が取り出したコストが小さければ、書
き換え手段によって、被演算子検出手段が検出した演算
式で、被演算子として使用されている変数のプログラム
中の位置が、演算検出手段が検出した演算に書き換えら
れる。被演算子検出手段が検出した全ての演算式中の変
数を、書き換え手段が書き換えた場合、除去手段によっ
て、演算検出手段が検出した演算を含む演算式が、プロ
グラム中から除去される。
Further, in the redundant type elimination apparatus of the present invention by the above means, the operation detecting means detects the operation expression in which the variable which is the pointer is defined from the program of the program holding means, and the detected operation and variable are detected. The position of the included arithmetic expression is stored. The variable detected by the operation detection means is the operation expression used as the operand,
All are detected by the operand detection means. The cost storage means is an arithmetic expression that can be executed by one machine language instruction, and includes operands used for pointers, operands used for indexes, and operands used for offsets. Of these, the type of the one including at least two operands and the cost of the arithmetic expression corresponding to the type of the arithmetic expression are stored. An arithmetic expression detected by the operand detection means,
The first cost extraction unit searches the storage unit and extracts the cost of the arithmetic expression corresponding to the arithmetic expression. The second cost extraction means searches the cost storage means with the type of the arithmetic expression when the arithmetic operation detected by the arithmetic operation detection means is applied to the operand of the arithmetic expression detected by the operand detection means, The cost corresponding to the arithmetic expression is retrieved. The comparison means compares the cost extracted by the first cost extraction means with the cost extracted by the second cost extraction means. As a result of comparison by the comparison means, the second
If the cost taken out by the cost extracting means is small, the rewriting means detects the position in the program of the variable used as the operand by the operation detecting means by the arithmetic expression detected by the operand detecting means. Can be rewritten as arithmetic. When the rewriting means rewrites the variables in all the arithmetic expressions detected by the operand detecting means, the arithmetic expressions including the arithmetic operations detected by the arithmetic detecting means are removed from the program by the removing means.

【0032】[0032]

【実施例】本発明の一実施例の冗長式除去装置について
説明を行う。この冗長式除去装置は、C言語のように、
変数を用いてアドレス計算が記述できる高級言語のコン
パイラに備えられ、コンパイラが、ソースプログラムの
字句解析、構文解析および意味解析が行われ、また、そ
れぞれの変数の中身が、プログラム中のそれぞれの演算
式においてどれだけの値になっているかが解析された後
に起動される。処理対象となるプログラムは、コンパイ
ラが、字句解析、構文解析および意味解析を行った後に
解析結果として出力する中間言語プログラムである。こ
の冗長式除去装置の構成を図1に示す。
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS A redundant type removing apparatus according to an embodiment of the present invention will be described. This redundant removal device, like C language,
It is equipped with a high-level language compiler that can describe address calculation using variables. The compiler performs lexical analysis, syntactic analysis, and semantic analysis of the source program, and the contents of each variable are the respective operations in the program. Fired after the value of the expression is parsed. The program to be processed is an intermediate language program that the compiler outputs as an analysis result after performing lexical analysis, syntactic analysis, and semantic analysis. The structure of this redundant removal device is shown in FIG.

【0033】冗長式除去装置10は、制御部1、演算生
成位置検出部3、値使用位置検出部4、コスト記憶部
5、アドレッシングコスト記憶部6、コスト取出部7、
第1の書き換えコスト取出部8、第2の書き換えコスト
取出部9、第3の書き換えコスト取出部10、比較部1
1、第1の書き換え部12、第1の演算式除去部13、
第2の書き換え部14、第2の演算式除去部15、第3
の書き換え部16、第3の演算式除去部17、および処
理対象保持部18で構成される。
The redundant type elimination device 10 includes a control unit 1, a calculation generation position detection unit 3, a value use position detection unit 4, a cost storage unit 5, an addressing cost storage unit 6, a cost extraction unit 7,
1st rewriting cost extraction part 8, 2nd rewriting cost extraction part 9, 3rd rewriting cost extraction part 10, comparison part 1
1, the first rewriting unit 12, the first arithmetic expression removing unit 13,
Second rewriting unit 14, second arithmetic expression removing unit 15, third
Rewriting unit 16, third arithmetic expression removing unit 17, and processing target holding unit 18.

【0034】制御部1は、演算生成位置検出部3、値使
用位置検出部4、コスト取出部7、第1の書き換えコス
ト取出部8、第2の書き換えコスト取出部9、第3の書
き換えコスト取出部10、比較部11を順に起動する。
演算生成位置検出部3は、演算出現位置検出部3aと、
代入出現位置検出部3bと、ポインタ演算式検出部3c
とからなる。
The control unit 1 includes a calculation generation position detecting unit 3, a value use position detecting unit 4, a cost extracting unit 7, a first rewriting cost extracting unit 8, a second rewriting cost extracting unit 9, and a third rewriting cost. The extraction unit 10 and the comparison unit 11 are activated in sequence.
The calculation generation position detector 3 includes a calculation appearance position detector 3a,
Substitution appearance position detector 3b and pointer arithmetic expression detector 3c
Consists of.

【0035】演算出現位置検出部3aは、被演算子が全
く同一の演算を、処理対象保持部21に保持されている
プログラムから全て検出する。具体的には、演算出現位
置検出部3aは、処理対象保持部18に保持されている
プログラム中の、全ての演算の演算子、被演算子を比較
し(被演算子が変数である場合、その変数の中身を比較
に用いる。)、同一の演算を全て検出する。検出後、演
算出現位置検出部3aは、その演算が等号の右辺に存在
する演算式のうち、1番目に位置する演算式を(この演
算式を指定演算式と呼ぶ。)、コスト取出部7に出力す
る。次に2番目以降に位置する演算式の位置を、第1の
演算式除去部13に通知する(この演算式を共通部分式
と呼ぶ。)。また、検出した演算式によって定義される
変数を検出し、これらの変数で、第1番目に位置する変
数(この変数を指定変数と呼ぶ。)を第1の書き換えコ
スト取出部8に出力し、2番目以降に位置する変数(こ
の変数を削除変数と呼ぶ。)を第1の値使用位置検出部
4aに出力する。
The operation appearance position detection unit 3a detects all operations having the same operands from the programs stored in the processing target storage unit 21. Specifically, the operation appearance position detection unit 3a compares operators and operands of all operations in the program held in the processing target holding unit 18 (if the operand is a variable, The contents of that variable are used for comparison.), And all the same operations are detected. After the detection, the operation appearance position detection unit 3a selects the operation expression located first in the operation expressions whose operation exists on the right side of the equal sign (this operation expression is referred to as a designated operation expression), and the cost extraction unit. Output to 7. Next, the positions of the second and subsequent arithmetic expressions are notified to the first arithmetic expression removing unit 13 (this arithmetic expression is called a common sub-expression). Further, the variables defined by the detected arithmetic expression are detected, and among these variables, the variable located first (this variable is referred to as the designated variable) is output to the first rewriting cost extraction unit 8, The second and subsequent variables (this variable is called a deletion variable) are output to the first value use position detector 4a.

【0036】代入出現位置検出部3bは、変数に定数を
代入する演算式、あるいは、変数に変数の値を代入する
演算式を、処理対象保持部18に保持されているプログ
ラムから全て検出し、検出した演算式の位置を、第2の
演算式除去部15に通知する。更に検出した演算式によ
って代入される変数(本実施例において、この変数をも
削除変数と呼ぶ。)を検出して、第2の値使用位置検出
部4bおよび第2の書き換えコスト取出部9に出力す
る。また、上記の演算式で、等号の右辺に存在する変
数、定数(本実施例では、これらも指定代入数と呼
ぶ。)を第2の書き換えコスト取出部9に出力する。
The substitution appearance position detection unit 3b detects all arithmetic expressions for substituting constants for variables, or arithmetic expressions for substituting the values of variables for variables from the program held in the processing target holding unit 18, The position of the detected arithmetic expression is notified to the second arithmetic expression removing unit 15. Further, a variable (in the present embodiment, this variable is also referred to as a deletion variable) substituted by the detected arithmetic expression is detected, and the second value use position detection unit 4b and the second rewriting cost extraction unit 9 are detected. Output. Further, in the above arithmetic expression, the variables and constants present on the right side of the equal sign (in the present embodiment, these are also referred to as designated substitution numbers) are output to the second rewriting cost extraction unit 9.

【0037】ポインタ演算式検出部3cは、ポインタ変
数が定義される演算式を、処理対象保持部21に保持さ
れているプログラムから全て検出する。具体的には、ポ
インタ演算式検出部3cは、処理対象保持部18に保持
されているプログラム中の演算式のうち、等号の左側に
ポインタ変数が存在する演算式を全て検出する。検出
後、ポインタ演算式検出部3cは、検出したポインタ変
数を第3の値使用位置検出部4cに出力し、そのポイン
タ変数を定義する演算(この演算をポインタ演算と呼
び、ポインタ演算とポインタ変数とを含む演算式をポイ
ンタ演算式と呼ぶ。)を検出して、第3の書き換えコス
ト取出部10に出力する。最後に検出した演算式の位置
を第3の演算式除去部17に通知する。
The pointer arithmetic expression detection unit 3c detects all arithmetic expressions in which pointer variables are defined from the program held in the processing target holding unit 21. Specifically, the pointer arithmetic expression detection unit 3c detects all arithmetic expressions having pointer variables on the left side of the equal sign among the arithmetic expressions in the program held in the processing target holding unit 18. After the detection, the pointer operation expression detection unit 3c outputs the detected pointer variable to the third value use position detection unit 4c, and an operation that defines the pointer variable (this operation is called a pointer operation, a pointer operation and a pointer variable). An arithmetic expression including and is referred to as a pointer arithmetic expression) is detected and output to the third rewriting cost extraction unit 10. The position of the finally detected arithmetic expression is notified to the third arithmetic expression removing unit 17.

【0038】値使用位置検出部4は、第1の値使用位置
検出部4aと、第2の値使用位置検出部4bと、第3の
値使用位置検出部4cとからなる。第1の値使用位置検
出部4aは、演算出現位置検出部3aから削除変数を受
け取り、削除変数が、被演算子として用いられているよ
うな演算式(本実施例において、この演算を書き換え演
算式と呼ぶ。)を全て検出する。検出後、第1の値使用
位置検出部4aは、プログラム中の、共通部分式から書
き換え演算式までの領域に、その演算式で、被演算子と
して使用されている変数が、定義されているかどうかを
確認し、定義されていなければ、書き換え演算式を第1
の書き換えコスト取出部8に出力する。
The value use position detector 4 comprises a first value use position detector 4a, a second value use position detector 4b, and a third value use position detector 4c. The first value use position detection unit 4a receives the deletion variable from the operation appearance position detection unit 3a, and the deletion variable is used as an operand (in the present embodiment, this operation is rewritten to perform an operation. This is called an expression.) Is detected. After the detection, the first value use position detection unit 4a determines whether a variable used as an operand is defined in the arithmetic expression in the area from the common subexpression to the rewriting arithmetic expression in the program. Check if it is not defined.
It is output to the rewriting cost extraction unit 8.

【0039】第2の値使用位置検出部4bは、代入出現
位置検出部3bから削除変数を受け取り、削除変数が、
被演算子として用いられているような演算式(本実施例
において、この演算をも書き換え演算式と呼ぶ。)を全
て検出して、第2の書き換えコスト取出部9に出力す
る。第3の値使用位置検出部4cは、ポインタ演算式検
出部3cからポインタ変数を受け取り、ポインタ変数
が、被演算子として用いられているような演算式(本実
施例において、この演算をも書き換え演算式と呼ぶ。)
を全て検出する。検出後、第3の値使用位置検出部4c
は、プログラム中の、ポインタ変数から書き換え演算式
までの領域に、その演算で、被演算子として使用されて
いる変数が、定義されているかどうかを確認し、定義さ
れていなければ、書き換え演算式を第3の書き換えコス
ト取出部10に出力する。
The second value use position detector 4b receives the deletion variable from the substitution appearance position detector 3b, and the deletion variable is
All arithmetic expressions used as operands (in the present embodiment, this arithmetic operation is also called a rewriting arithmetic expression) are detected and output to the second rewriting cost extraction unit 9. The third value use position detector 4c receives the pointer variable from the pointer arithmetic expression detector 3c, and the pointer variable is used as an operand (in this embodiment, this arithmetic operation is also rewritten). It is called an arithmetic expression.)
To detect all. After the detection, the third value use position detector 4c
Checks whether the variable used as the operand in the operation is defined in the area from the pointer variable to the rewrite operation expression in the program, and if it is not defined, the rewrite operation expression Is output to the third rewriting cost extraction unit 10.

【0040】コスト記憶部5は、演算式の型と、その演
算式の型に該当する演算式のコストを記憶する。本実施
例において、上記の演算式の型が定められる5つの項目
が存在し、これらの項目は、コスト取出部7、第1の書
き換えコスト取出部8が検索を行うための検索項目とな
る。またコスト記憶部5は、これらの検索項目の組み合
わせに対応するコストを記憶する。図2は、ターゲット
マシンが2オペランド方式で、Second to f
irst方式(2番目のオペランドを1番目のオペラン
ドに作用する方式)と呼ばれているものの一例を示した
ものである。上述の検索項目とは、演算子の種類の項
目、演算の型の項目、演算子の右側の被演算子(第1の
被演算子と呼ぶ)の項目、演算子の左側の被演算子(第
2の被演算子と呼ぶ)の項目、及び演算結果の格納場所
の項目という5つの項目である。上記の演算子の種類の
項目には、加算、減算、乗算、除算等、演算子等の種類
が示されている。演算の型の項目には、8bit整数型か、
16bit整数型、32bit整数型、単精度浮動小数点型、倍精
度浮動小数点型等、演算の型が示されている。第1、第
2の被演算子の種類には、被演算子が、定数、静的変
数、ポインタを格納する静的変数、スタック変数、ポイ
ンタを格納するスタック変数、レジスタ変数、ポインタ
を格納するレジスタ変数等、変数の型が示されている。
演算結果の格納場所の項目には、静的変数、ポインタを
格納する静的変数、スタック変数、ポインタを格納する
スタック変数、レジスタ変数、ポインタを格納するレジ
スタ変数等、変数の型が示されている。コストの項目に
は、これらの検索項目の条件に該当する機械語命令のク
ロック数、あるいは、メモリサイズが記録されている。
尚、図2において、ポインタを格納している変数は、下
の項目にポインタと記載している。
The cost storage unit 5 stores the type of the arithmetic expression and the cost of the arithmetic expression corresponding to the type of the arithmetic expression. In the present embodiment, there are five items in which the types of the above arithmetic expressions are determined, and these items are search items for the cost extraction unit 7 and the first rewriting cost extraction unit 8 to perform a search. The cost storage unit 5 also stores costs corresponding to combinations of these search items. In FIG. 2, the target machine is a two-operand method, and the second to second
This is an example of what is called the irst method (method in which the second operand acts on the first operand). The above-mentioned search items are the operator type item, the operation type item, the operand on the right side of the operator (called the first operand), and the operand on the left side of the operator ( The second item is called the second operand, and the item of the storage location of the operation result is five items. In the above-mentioned operator type item, types of operators such as addition, subtraction, multiplication and division are shown. The operation type item is 8bit integer type,
Operation types such as 16-bit integer type, 32-bit integer type, single precision floating point type, double precision floating point type are shown. In the first and second types of operands, the operands store constants, static variables, static variables that store pointers, stack variables, stack variables that store pointers, register variables, and pointers. The types of variables such as register variables are shown.
The item of the storage location of the operation result shows the type of variable such as static variable, static variable that stores a pointer, stack variable, stack variable that stores a pointer, register variable, register variable that stores a pointer, etc. There is. In the cost item, the clock number of the machine language instruction corresponding to the conditions of these search items or the memory size is recorded.
In FIG. 2, the variable storing the pointer is described as a pointer in the item below.

【0041】アドレッシングコスト記憶部6は、第3の
書き換えコスト取出部10が検索を行うための、アドレ
ッシングモードを用いた機械語命令のコストを記憶す
る。図3にアドレッシングコスト記憶部6の一例を示
す。アドレッシングコスト記憶部6の構成は、コスト記
憶部5に類似している。異なるのは、アドレッシングコ
スト記憶部6には、第2の演算子の項目と、第2の演算
子の右側に存在する被演算子(第3の被演算子)の項目
とが存在し、7つの検索項目の組み合わせに該当するコ
ストを記憶する。
The addressing cost storage unit 6 stores the cost of the machine language instruction using the addressing mode for the third rewriting cost extraction unit 10 to search. FIG. 3 shows an example of the addressing cost storage unit 6. The configuration of the addressing cost storage unit 6 is similar to that of the cost storage unit 5. The difference is that the addressing cost storage unit 6 has an item of the second operator and an item of the operand (third operand) on the right side of the second operator. The cost corresponding to the combination of one search item is stored.

【0042】コスト取出部7は、演算出現位置検出部3
aが検出した指定演算式でコスト記憶部5を検索し、当
該演算式に対応する機械語命令のコストを取り出して比
較部11に出力する。具体的には、コスト取出部7は、
指定演算式を演算出現位置検出部3aから受け取り、受
け取った指定演算式で被演算子として使用されている変
数の型を調べ、第1、第2の被演算子が、定数である
か、静的変数であるか、ポインタを格納する静的変数で
あるか、スタック変数であるか、ポインタを格納するス
タック変数であるか、レジスタ変数であるか、ポインタ
を格納するレジスタ変数であるかを調べる。これらを調
べた後、コスト取出部7は、演算結果の格納場所が、静
的変数であるか、ポインタを格納する静的変数である
か、スタック変数であるか、ポインタを格納するスタッ
ク変数であるか、レジスタ変数であるか、ポインタを格
納するレジスタ変数であるかを調べる。これらの調査結
果に基づいて、コスト記憶部5を検索し、該当するコス
トを取り出して比較部11に出力する。
The cost extraction unit 7 is a calculation appearance position detection unit 3
The cost storage unit 5 is searched with the specified arithmetic expression detected by a, and the cost of the machine language instruction corresponding to the arithmetic expression is extracted and output to the comparison unit 11. Specifically, the cost extraction unit 7
The specified arithmetic expression is received from the arithmetic appearance position detection unit 3a, the type of the variable used as the operand in the received specified arithmetic expression is checked, and whether the first and second operands are constants or static A static variable, a static variable that stores a pointer, a stack variable, a stack variable that stores a pointer, a register variable, or a register variable that stores a pointer . After checking these, the cost extraction unit 7 determines whether the storage location of the operation result is a static variable, a static variable storing a pointer, a stack variable, or a stack variable storing a pointer. Examine whether it exists, is a register variable, or is a register variable that stores a pointer. Based on the results of these investigations, the cost storage unit 5 is searched, and the corresponding cost is extracted and output to the comparison unit 11.

【0043】第1の書き換えコスト取出部8は、演算出
現位置検出部3aから指定変数を受け取り、第1の値使
用位置検出部4aから書き換え演算式を受け取って、書
き換え演算式中の削除変数を、指定変数に書き換え、書
き換えた演算式でコスト記憶部5を検索し、演算式のコ
ストを取り出して比較部11に出力する。例えば、変数
aが指定変数であり、変数bが削除変数、演算式「d=
b+3」が書き換え演算式である場合、第1の書き換え
コスト取出部8は、演算式「d=b+3」を、演算式
「d=a+3」に書き換えてコスト記憶部5を検索し、
コストを取り出して、比較部11に出力する。第1の書
き換えコスト取出部8が行うコストの検索の方法は、コ
スト取出部7と同じであるので説明を省略する。
The first rewriting cost extracting unit 8 receives the designated variable from the operation appearance position detecting unit 3a, receives the rewriting arithmetic expression from the first value use position detecting unit 4a, and deletes the deletion variable in the rewriting arithmetic expression. , The cost storage unit 5 is searched by the rewritten arithmetic expression, the cost of the arithmetic expression is extracted and output to the comparison unit 11. For example, the variable a is a designated variable, the variable b is a deletion variable, and the arithmetic expression “d =
When “b + 3” is the rewriting arithmetic expression, the first rewriting cost extraction unit 8 rewrites the arithmetic expression “d = b + 3” into the arithmetic expression “d = a + 3” to search the cost storage unit 5,
The cost is taken out and output to the comparison unit 11. The method of searching for the cost performed by the first rewriting cost deriving unit 8 is the same as that of the cost deriving unit 7, and the description thereof will be omitted.

【0044】第2の書き換えコスト取出部9は、代入出
現位置検出部3bから削除変数、指定代入数を受け取
り、第2の値使用位置検出部4bから書き換え演算式を
受け取って、その削除変数が、ポインタを格納している
か否かを判定し、もし格納していれば、書き換え演算式
中の削除変数を、指定代入数に書き換え、書き換えた演
算式でコスト記憶部5を検索し、書き換えた演算式に対
応するコストを取り出して比較部11に出力する。例え
ば、変数3が指定代入数であり、変数bが削除変数、演
算式「a=b+c」が書き換え演算式である場合、第1
の書き換えコスト取出部8は、演算「a=b+c」を、
演算「a=3+c」に書き換えてコスト記憶部5を検索
し、コストを取り出して、比較部11に出力する。第2
の書き換えコスト取出部9が行うコストの検索の方法
は、コスト取出部7と同じ方法であるので説明を省略す
る。
The second rewriting cost extraction unit 9 receives the deletion variable and the designated number of substitutions from the substitution appearance position detection unit 3b, receives the rewriting arithmetic expression from the second value use position detection unit 4b, and deletes the deletion variable. , It is determined whether or not the pointer is stored, and if so, the deletion variable in the rewriting arithmetic expression is rewritten to the specified number of substitutions, and the cost storage unit 5 is searched with the rewritten arithmetic expression and rewritten. The cost corresponding to the arithmetic expression is extracted and output to the comparison unit 11. For example, when the variable 3 is the designated substitution number, the variable b is the deletion variable, and the arithmetic expression “a = b + c” is the rewriting arithmetic expression, the first
The rewriting cost extraction unit 8 of the calculation “a = b + c”
The cost storage unit 5 is searched by rewriting the calculation to “a = 3 + c”, the cost is extracted, and the cost is output to the comparison unit 11. Second
The method of searching for the cost performed by the rewriting cost extracting unit 9 is the same as that of the cost extracting unit 7, and therefore the description thereof will be omitted.

【0045】第3の書き換えコスト取出部10は、ポイ
ンタ演算式検出部3cからポインタ変数、ポインタ演算
を受け取り、第3の値使用位置検出部4cから書き換え
演算式を受け取って、書き換え演算式中の削除変数を、
ポインタ演算に書き換え、書き換えた演算でアドレッシ
ングコスト記憶部6を検索し、その演算に対応するアド
レッシングモードの機械語命令のコストを取り出して比
較部11に出力する。例えば、変数bが指定代入数であ
り、指定演算が「a+2」、書き換え演算式が「d=b
+c」である場合、第1の書き換えコスト取出部8は、
書き換え演算式「d=b+c」を、演算「d=a+2+
c」に書き換えてアドレッシングコスト記憶部6を検索
し、コストを取り出して、比較部11に出力する。コス
トの検索の方法は、コスト取出部7と同じである。
The third rewriting cost extraction unit 10 receives the pointer variable and the pointer operation from the pointer arithmetic expression detecting unit 3c, receives the rewriting arithmetic expression from the third value use position detecting unit 4c, and writes the rewriting arithmetic expression in the rewriting arithmetic expression. Delete variables,
It is rewritten to a pointer operation, the addressing cost storage unit 6 is searched by the rewritten operation, and the cost of the machine language instruction in the addressing mode corresponding to the operation is fetched and output to the comparison unit 11. For example, the variable b is the number of designated substitutions, the designated calculation is “a + 2”, and the rewriting calculation formula is “d = b”.
+ C ”, the first rewriting cost extraction unit 8
The rewriting arithmetic expression “d = b + c” is calculated by the operation “d = a + 2 +
The addressing cost storage unit 6 is searched by rewriting to “c”, the cost is taken out, and output to the comparison unit 11. The method of cost search is the same as that of the cost extraction unit 7.

【0046】比較部11は、コスト取出部7、第1のコ
スト書き換え取出部8、第2のコスト書き換え取出部
9、第3のコスト書き換え取出部10が取り出したコス
トを受け取り、それぞれの比較を行う。コスト取出部
7、第1のコスト書き換え取出部8からコストを受け取
れば、比較部11は、それぞれを比較する。比較した結
果、第1の書き換えコスト取出部8が取り出したコスト
が小さければ、第1の書き換え部12を起動する。同様
に第2のコスト書き換え取出部9、第3の書き換えコス
ト取出部10からコストを受け取れば、比較部11は、
それらをコスト取出部7から受け取ったコストと比較
し、もし、第2の書き換えコスト取出部9、第3の書き
換えコスト取出部10が取り出したコストが小さけれ
ば、第2の書き換え部14、第3の書き換え部16を起
動する。
The comparing section 11 receives the costs extracted by the cost extracting section 7, the first cost rewriting extracting section 8, the second cost rewriting extracting section 9, and the third cost rewriting extracting section 10, and compares them with each other. To do. When the costs are received from the cost extraction unit 7 and the first cost rewriting extraction unit 8, the comparison unit 11 compares the costs. As a result of the comparison, if the cost taken out by the first rewriting cost extracting unit 8 is small, the first rewriting unit 12 is activated. Similarly, if the costs are received from the second cost rewriting and extracting unit 9 and the third rewriting cost extracting unit 10, the comparison unit 11
These are compared with the costs received from the cost retrieving unit 7, and if the costs retrieved by the second rewriting cost retrieval unit 9 and the third rewriting cost retrieval unit 10 are small, the second rewriting unit 14, the third rewriting unit 14 The rewriting unit 16 is activated.

【0047】第1の書き換え部12は、演算出現位置検
出部3aから指定変数を受け取り、第1の値使用位置検
出部4aが検出した書き換え演算式中の削除変数のプロ
グラム上の位置を、指定変数に書き換える。第1の演算
式除去部13は、第1の書き換え部12が全ての削除変
数を指定変数に書き換えた場合、演算出現位置検出部3
aから知らされた位置の演算式を、プログラムから削除
する。
The first rewriting unit 12 receives the designated variable from the operation appearance position detecting unit 3a, and designates the program position of the deletion variable in the rewriting arithmetic expression detected by the first value use position detecting unit 4a. Rewrite as a variable. When the first rewriting unit 12 rewrites all the deletion variables into the designated variables, the first arithmetic expression removing unit 13 calculates the operation appearance position detecting unit 3
The arithmetic expression of the position notified from a is deleted from the program.

【0048】第2の書き換え部14は、代入出現位置検
出部3bから削除変数を受け取り、第2の値使用位置検
出部4bが検出した書き換え演算式中の削除変数のプロ
グラム上の位置を、指定代入数に書き換える。第2の演
算式除去部15は、第2の書き換え部14が全ての削除
変数を指定変数に書き換えた場合、代入出現位置検出部
3bから知らされた位置の演算式を、プログラムから削
除する。
The second rewriting unit 14 receives the deletion variable from the substitution appearance position detection unit 3b, and specifies the position on the program of the deletion variable in the rewriting arithmetic expression detected by the second value use position detection unit 4b. Rewrite with the number of substitutions. When the second rewriting unit 14 rewrites all the deletion variables into the designated variables, the second arithmetic expression removing unit 15 deletes the arithmetic expression at the position notified from the substitution appearance position detecting unit 3b from the program.

【0049】第3の書き換え部16は、演算出現位置検
出部3aからポインタ演算を受け取り、第3の値使用位
置検出部4cが検出した書き換え演算式中のポインタ変
数のプログラム上の位置を、ポインタ演算に書き換え
る。第3の演算式除去部17は、第3の書き換え部16
が全ての削除変数を指定変数に書き換えた場合、ポイン
タ演算式検出部3cから知らされた位置のポインタ演算
式をプログラムから削除する。
The third rewriting unit 16 receives the pointer operation from the operation appearance position detecting unit 3a, and indicates the position on the program of the pointer variable in the rewriting operation expression detected by the third value use position detecting unit 4c. Rewrite as calculation. The third arithmetic expression removing unit 17 includes a third rewriting unit 16
When all the deleted variables are rewritten to the designated variables, the pointer arithmetic expression at the position notified from the pointer arithmetic expression detection unit 3c is deleted from the program.

【0050】処理対象保持部18は、処理対象となるプ
ログラムを保持する。保持されるプログラムは、コンパ
イラが内部処理の都合上生成した内部コードで記述され
ている。尚、保持されるプログラムは、プログラマによ
って記述されたソースコードで記述されていてもよい。
以上のように構成された冗長式除去装置の動作を、{例
1}〜{例3}までの例を用いて説明する。
The processing object holding unit 18 holds the program to be processed. The stored program is written in the internal code generated by the compiler for the convenience of internal processing. The stored program may be written in source code written by a programmer.
The operation of the redundant removal device configured as described above will be described using examples from {Example 1} to {Example 3}.

【0051】{例1}図4のように、プログラム中に、
全く同一の演算を行う演算が、複数個存在する場合の動
作 (1)演算出現位置検出部3aは、処理対象保持部18
に保持されている図7に示すプログラムから、指定演算
式「g=f+400」を検出し、指定変数gを検出す
る。また、演算「f+400」と同一の演算を等号の右
側に持つ演算式「h=f+400」を検出し、削除変数
hを検出する。
{Example 1} As shown in FIG. 4, in the program,
Operation when there are a plurality of operations that perform exactly the same operation (1) The operation appearance position detection unit 3a includes the processing target holding unit 18
The specified arithmetic expression “g = f + 400” is detected from the program stored in FIG. 7 and the specified variable g is detected. Also, the arithmetic expression “h = f + 400” having the same arithmetic operation as the arithmetic operation “f + 400” on the right side of the equal sign is detected, and the deletion variable h is detected.

【0052】(2)第1の値使用位置検出部4aは、演
算出現位置検出部3aから削除変数hを受け取り、削除
変数hが、被演算子として用いられているような書き換
え演算式「*a=h*70」を検出する。 (3)コスト取出部7は、値使用位置検出部4aが検出
した書き換え演算式「*a=h*70」でコスト記憶部
5を検索し、当該演算に対応する機械語命令のコストを
取り出して比較部11に出力する。
(2) The first value use position detection unit 4a receives the deletion variable h from the operation appearance position detection unit 3a, and the deletion variable h is used as a rewritten arithmetic expression "*". a = h * 70 ”is detected. (3) The cost extraction unit 7 searches the cost storage unit 5 with the rewriting arithmetic expression “* a = h * 70” detected by the value use position detection unit 4a, and extracts the cost of the machine language instruction corresponding to the calculation. And outputs to the comparison unit 11.

【0053】(5)第1の書き換えコスト取出部8は、
演算出現位置検出部3aから指定変数gを受け取り、第
1の値使用位置検出部4aから書き換え演算式「*a=
h*70」を受け取って、書き換え演算式中の削除変数
hを、指定変数gに書き換え、書き換えた演算式「*a
=g*40」でコスト記憶部5を検索し、演算式のコス
トを取り出して比較部11に出力する。
(5) The first rewriting cost extraction section 8
The specified variable g is received from the arithmetic appearance position detection unit 3a, and the rewriting arithmetic expression “* a =
h * 70 ”, the deletion variable h in the rewriting arithmetic expression is rewritten to the designated variable g, and the rewritten arithmetic expression“ * a
= G * 40 ”, the cost storage unit 5 is searched, and the cost of the arithmetic expression is extracted and output to the comparison unit 11.

【0054】(6)比較部11は、コスト取出部7、第
1のコスト書き換え取出部8が取り出したコストを受け
取り、それぞれの比較を行う。この場合、第1の書き換
えコスト取出部8から受け取ったコストが小さいので、
第1の書き換え部12を起動する。 (7)第1の書き換え部12は、演算出現位置検出部3
aから指定変数gを受け取り、第1の値使用位置検出部
4aが検出した書き換え演算式「*a=h*70」の削
除変数hを、指定変数gに書き換える。
(6) The comparing section 11 receives the costs extracted by the cost extracting section 7 and the first cost rewriting extracting section 8 and compares them with each other. In this case, since the cost received from the first rewriting cost extraction unit 8 is small,
The first rewriting unit 12 is activated. (7) The first rewriting unit 12 includes the calculation appearance position detecting unit 3
The designated variable g is received from a, and the deletion variable h of the rewriting arithmetic expression “* a = h * 70” detected by the first value use position detection unit 4a is rewritten to the designated variable g.

【0055】(8)第1の演算式除去部13は、第1の
書き換え部12の書き換え後、演算出現位置検出部3a
から知らされた位置の演算式「h=f+400」を、プ
ログラムから削除する。以上のような動作によって、図
4に示したプログラムは、図5に示すプログラムに書き
換えられる。 {例2}図6のようにプログラム中に、変数を変数に代
入する演算式、定数を変数に代入する演算式が存在する
場合の動作 (1)代入出現位置検出部3bは、図6に示すプログラ
ムから、変数に定数を代入する演算式「f=20」を検
出する。
(8) The first arithmetic expression removing unit 13 rewrites the first rewriting unit 12, and then the arithmetic appearance position detecting unit 3a.
The arithmetic expression “h = f + 400” of the position informed from is deleted from the program. By the above operation, the program shown in FIG. 4 is rewritten to the program shown in FIG. {Example 2} Operation when there is an arithmetic expression for substituting a variable for a variable and an arithmetic expression for substituting a constant for a variable in a program as shown in FIG. 6 (1) The substitution appearance position detection unit 3b is shown in FIG. From the program shown, an arithmetic expression "f = 20" for substituting a constant for a variable is detected.

【0056】(2)第2の値使用位置検出部4bは、代
入出現位置検出部3bから削除変数を受け取り、削除変
数が、被演算子として用いられているような書き換え演
算式「g=f+*a」を検出して、第2の書き換えコス
ト取出部9に出力する。 (3)コスト取出部7は、値使用位置検出部4bが検出
した書き換え演算式「g=f+*a」でコスト記憶部5
を検索し、演算式に対応する機械語命令のコストを取り
出して比較部11に出力する。
(2) The second value use position detection unit 4b receives the deletion variable from the substitution appearance position detection unit 3b, and the deletion variable is a rewriting arithmetic expression "g = f +" used as an operand. * A "is detected and output to the second rewriting cost extraction unit 9. (3) The cost extraction unit 7 uses the rewriting arithmetic expression “g = f + * a” detected by the value use position detection unit 4b to generate the cost storage unit 5.
Is retrieved, the cost of the machine language instruction corresponding to the arithmetic expression is extracted and output to the comparison unit 11.

【0057】(4)第2の書き換えコスト取出部9は、
代入出現位置検出部3bから削除変数「f」、指定代入
数「20」を受け取り、第2の値使用位置検出部4bか
ら書き換え演算式「g=f+*a」を受け取って、演算
式「g=f+*a」を「g=20+*a」に書き換え、
書き換え後の演算式に対応する機械語命令のコストを取
り出して比較部11に出力する。
(4) The second rewriting cost extraction unit 9
The deletion variable “f” and the designated substitution number “20” are received from the substitution appearance position detection unit 3b, and the rewriting arithmetic expression “g = f + * a” is received from the second value use position detection unit 4b, and the arithmetic expression “g” is received. = F + * a ”is changed to“ g = 20 + * a ”,
The cost of the machine language instruction corresponding to the rewritten arithmetic expression is extracted and output to the comparison unit 11.

【0058】(5)比較部11は、コスト取出部7、第
2のコスト書き換え取出部9が取り出したコストを受け
取り、それぞれの比較を行う。この場合、第2のコスト
書き換え取出部9が取り出したコストが小さいので第2
の書き換え部14を起動する。 (6)第2の書き換え部14は、代入出現位置検出部3
bから指定代入数「20」を受け取り、第2の値使用位
置検出部4bが検出した書き換え演算式中の削除変数
「f」を、指定代入数「20」に書き換える。
(5) The comparing unit 11 receives the costs extracted by the cost extracting unit 7 and the second cost rewriting extracting unit 9 and compares them with each other. In this case, since the cost taken out by the second cost rewriting and taking-out unit 9 is small,
The rewriting unit 14 is started. (6) The second rewriting unit 14 includes the substitution appearance position detection unit 3
The designated substitution number "20" is received from b, and the deletion variable "f" in the rewriting arithmetic expression detected by the second value use position detection unit 4b is rewritten to the designated substitution number "20".

【0059】(7)第2の演算式除去部15は、第2の
書き換え部14の書き換え後、代入出現位置検出部3b
から知らされた位置の指定演算式「f=20」を、プロ
グラムから削除する。冗長式除去装置が、このような処
理を行った場合、図6に示したプログラムは、図7に示
すように書き換えられる。 {例3}図8のように、プログラム中にポインタ変数で
書かれた変数を用いてアドレスを計算し、計算したアド
レスの内容を変数に代入している記述が存在する場合 (1)ポインタ演算式検出部3cは、図8に示すプログ
ラムから、ポインタ演算式「d=c+400」、「d1
=c*400」を検出する。
(7) The second arithmetic expression removing unit 15 rewrites the second rewriting unit 14 and then substitutes the appearance position detecting unit 3b.
The specified arithmetic expression “f = 20” for the position informed from is deleted from the program. When the redundant removal apparatus performs such processing, the program shown in FIG. 6 is rewritten as shown in FIG. {Example 3} As shown in FIG. 8, when there is a description in the program in which the address is calculated using the variable written as the pointer variable and the content of the calculated address is substituted into the variable (1) Pointer operation From the program shown in FIG. 8, the expression detection unit 3c uses the pointer arithmetic expressions “d = c + 400” and “d1.
= C * 400 ”is detected.

【0060】(2)第3の値使用位置検出部4cは、ポ
インタ演算式検出部3cからポインタ変数「d」、「d
1」を受け取り、ポインタ演算式「a=*(b+
d)」、「a=*(b+d1)」を検出する。 (3)コスト取出部7は、第3の値使用位置検出部4c
が検出した書き換え演算式「a=*(b+d)」、「a
=*(b+d1)」でコスト記憶部5を検索し、当該演
算式に対応する機械語命令のコストを取り出して比較部
11に出力する。
(2) The third value use position detector 4c receives the pointer variables "d" and "d" from the pointer arithmetic expression detector 3c.
1 ”, and the pointer arithmetic expression“ a = * (b +
d) ”and“ a = * (b + d1) ”are detected. (3) The cost extraction unit 7 includes the third value use position detection unit 4c
Rewriting arithmetic expression “a = * (b + d)”, “a
= * (B + d1) ”, the cost storage unit 5 is searched, and the cost of the machine language instruction corresponding to the arithmetic expression is extracted and output to the comparison unit 11.

【0061】(4)第3の書き換えコスト取出部10
は、ポインタ演算式検出部3cから指定変数d、d1、
指定演算「c+400」、「c*400」を受け取り、
第3の値使用位置検出部4cから書き換え演算式「a=
*(b+d)」、「a=*(b+d1)」を受け取っ
て、書き換え演算式中の削除変数d、d1を、指定演算
「c+400」、「c*400」に書き換え、書き換え
た演算式「a=*(b+c+400)」、「a=*(b
+c*400)」でコスト記憶部5を検索し、その演算
に対応するアドレッシングモードの機械語命令のコスト
を取り出して比較部11に出力する。
(4) Third rewriting cost extraction unit 10
Are designated variables d, d1, from the pointer arithmetic expression detection unit 3c.
Receive the specified operation "c + 400", "c * 400",
From the third value use position detector 4c, the rewriting arithmetic expression "a =
"* (B + d)" and "a = * (b + d1)" are received, and the deleted variables d and d1 in the rewriting arithmetic expression are rewritten to the specified operations "c + 400" and "c * 400", and the rewritten arithmetic expression "a" = * (B + c + 400) ”,“ a = * (b
+ C * 400) ”, the cost storage unit 5 is searched, and the cost of the machine language instruction in the addressing mode corresponding to the operation is extracted and output to the comparison unit 11.

【0062】(5)比較部11は、コスト取出部7、第
3のコスト書き換え取出部10が取り出したコストを受
け取り、それぞれの比較を行う。比較した結果、第3の
書き換えコスト取出部8が取り出したコストが小さいの
で、第3の書き換え部10を起動する。 (6)第3の書き換え部16は、演算出現位置検出部3
aからポインタ演算「c+400」、「c*400」を
受け取り、第3の値使用位置検出部4cが検出した書き
換え演算式中の指定変数を、ポインタ演算に書き換え
る。
(5) The comparing section 11 receives the costs extracted by the cost extracting section 7 and the third cost rewriting extracting section 10 and compares them with each other. As a result of the comparison, since the cost taken out by the third rewriting cost extracting unit 8 is small, the third rewriting unit 10 is activated. (6) The third rewriting unit 16 includes the calculation appearance position detecting unit 3
The pointer calculation “c + 400”, “c * 400” is received from a, and the designated variable in the rewriting calculation expression detected by the third value use position detection unit 4c is rewritten to the pointer calculation.

【0063】(7)第3の演算式除去部17は、第3の
書き換え部16の書き換え後、演算出現位置検出部3a
から知らされた位置の指定演算式「d=c+400」、
「d1=c*400)」をプログラムから削除する。こ
のような処理を行った場合、図8に示したプログラム
は、図9に示すように書き換えられる。尚、本発明の冗
長式除去装置の構成は、上記の構成に限定されるもので
はなく、演算出現位置検出部3aが検出した演算のう
ち、2番目以降に位置する演算を含む演算式(冗長式)
についての演算式の型でコスト記憶部5を検索し、当該
演算式の型に対応するコストを取り出す冗長式コスト取
出部と、コスト取出部7が取り出したコストと、冗長式
コスト取出部が取り出したコストとの和を求める算出部
とを備え、比較手段は、算出部が求めたコストの和と、
第1、2、3の書き換えコスト取出部8、9、10が取
り出したコストとを比較して、書き換え、冗長式の除去
を行うか否かを決定してもよい。
(7) The third arithmetic expression removing unit 17 rewrites the third rewriting unit 16, and then the arithmetic appearance position detecting unit 3a.
The specified arithmetic expression “d = c + 400” of the position informed from
Delete "d1 = c * 400)" from the program. When such processing is performed, the program shown in FIG. 8 is rewritten as shown in FIG. The configuration of the redundant type removing device of the present invention is not limited to the above-described configuration, and the arithmetic expression including the second and subsequent operations among the operations detected by the operation appearance position detection unit 3a (redundancy formula)
Is searched for in the cost storage unit 5 by the type of the arithmetic expression and the cost corresponding to the type of the arithmetic expression is taken out by the redundant type cost take-out unit, the cost taken out by the cost take-out unit 7 and the redundant type cost take-out unit take out the cost. And a calculating unit for calculating the sum of the costs, and the comparing unit calculates the sum of the costs calculated by the calculating unit,
The first, second and third rewriting cost extraction units 8, 9 and 10 may be compared with the costs extracted to determine whether or not to rewrite and remove the redundant expression.

【0064】また、コスト取出部7、第1、2、3の書
き換えコスト取出部8、9、10は、取り出したコスト
の総和を求め、比較部11は、こうして求めたコストの
総和を比較して、書き換え、冗長式の除去を行うか否か
を決定してもよい。また、冗長式コスト取出部は、演算
出現位置検出部3aが検出した演算のうち、2番目以降
に位置する演算を含む演算式についての演算式の型でコ
スト記憶部5を検索し、当該演算式の型に対応するコス
トを取り出し、コスト取出部7、第1、2、3の書き換
えコスト取出部8、9、10は、取り出したコストの総
和を求め、算出部は、コスト取出部7が取り出したコス
トの総和と、冗長式コスト取出部が取り出したコストと
の和を求めて、コスト取出部7は、算出部が求めたコス
トの和と、第1、2、3の書き換えコスト取出部8、
9、10が取り出したコストの総和とを比較して、書き
換え、冗長式の除去を行うか否かを決定してもよい。
Further, the cost extraction unit 7, the first, second and third rewriting cost extraction units 8, 9 and 10 calculate the total sum of the extracted costs, and the comparison unit 11 compares the total sum of the thus calculated costs. Then, it may be determined whether or not to rewrite and remove the redundant expression. In addition, the redundant type cost extraction unit searches the cost storage unit 5 for the type of the arithmetic expression for the arithmetic expression including the second or later arithmetic operation among the arithmetic operations detected by the arithmetic appearance position detection unit 3a, and performs the operation. The cost corresponding to the type of expression is extracted, the cost extraction unit 7, the first, second, and third rewrite cost extraction units 8, 9, and 10 calculate the sum of the extracted costs, and the calculation unit sets the cost extraction unit 7 to The cost extraction unit 7 calculates the sum of the extracted costs and the cost extracted by the redundant cost extraction unit, and the cost extraction unit 7 calculates the sum of the costs calculated by the calculation unit and the first, second, and third rewriting cost extraction units. 8,
It is also possible to compare the total cost extracted by 9 and 10 and determine whether to rewrite and remove the redundant expression.

【0065】[0065]

【発明の効果】以上説明してきたように、本発明の冗長
式除去装置によれば、処理対象となる演算の被演算子
が、定数、レジスタ変数、スタック変数、静的変数のど
れに該当するかを調べ、書き換え前後のコストを比較し
た後に被演算子の書き換えを行うので、演算の書き換え
が有効な場合のみ演算を書き換えることができるという
効果がある。
As described above, according to the redundant expression removing apparatus of the present invention, the operand of the operation to be processed corresponds to any of a constant, a register variable, a stack variable and a static variable. Since the operator is rewritten after comparing the costs before and after the rewriting, the operation can be rewritten only when the rewriting of the operation is effective.

【0066】また、ターゲットマシンのプロセッサが、
インデックスおよびオフセット付きの間接アドレス参
照、オフセット付きの間接アドレス参照等、アドレッシ
ングモードを使用することができる場合、これらのアド
レッシングモードを、有効に活用できるような演算の書
き換えが行うので、コストの低減を充分に図ることがで
きるという効果がある。
The processor of the target machine is
When addressing modes such as indirect address reference with index and offset, indirect address reference with offset, etc. can be used, the operation is rewritten to make effective use of these addressing modes, thus reducing the cost. The effect is that it can be achieved sufficiently.

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

【図1】本発明の一実施例における冗長式除去装置の装
置10の構成を示す図である。
FIG. 1 is a diagram showing a configuration of an apparatus 10 of a redundant removal apparatus according to an embodiment of the present invention.

【図2】コスト記憶部5の内容を示す図である。FIG. 2 is a diagram showing the contents of a cost storage unit 5.

【図3】アドレッシングコスト記憶部6の内容を示す図
である。
FIG. 3 is a diagram showing the contents of an addressing cost storage unit 6.

【図4】処理対象のプログラムを示す図であるFIG. 4 is a diagram showing a program to be processed.

【図5】冗長式除去装置によって書き換えられたプログ
ラムを示す図である。
FIG. 5 is a diagram showing a program rewritten by the redundancy removing apparatus.

【図6】処理対象のプログラムを示す図であるFIG. 6 is a diagram showing a program to be processed.

【図7】冗長式除去装置によって書き換えられたプログ
ラムを示す図である。
FIG. 7 is a diagram showing a program rewritten by the redundancy removing apparatus.

【図8】処理対象のプログラムを示す図であるFIG. 8 is a diagram showing a program to be processed.

【図9】冗長式除去装置によって書き換えられたプログ
ラムを示す図である。
FIG. 9 is a diagram showing a program rewritten by the redundancy removing apparatus.

【図10】従来の共通部分式の削除を行う冗長式除去装
置の構成を示す図である。
FIG. 10 is a diagram showing a configuration of a conventional redundant removal apparatus that deletes a common subexpression.

【図11】処理対象のプログラムを示す図であるFIG. 11 is a diagram showing a program to be processed.

【図12】従来の冗長式除去装置によって書き換えられ
たプログラムを示す図である。
FIG. 12 is a diagram showing a program rewritten by a conventional redundant removal apparatus.

【図13】従来の値の伝搬を行う冗長式除去装置の構成
を示す図である。
FIG. 13 is a diagram showing a configuration of a conventional redundant removal device that propagates a value.

【図14】処理対象のプログラムを示す図であるFIG. 14 is a diagram showing a program to be processed.

【図15】従来の冗長式除去装置によって書き換えられ
たプログラムを示す図である。
FIG. 15 is a diagram showing a program rewritten by a conventional redundant removal apparatus.

【図16】プログラムとアドレッシングモードとの対応
を示す図である。
FIG. 16 is a diagram showing correspondence between programs and addressing modes.

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

1 制御部 3a 演算出現位置検出部 3b 代入出現位置検出部 3c ポインタ演算式検出部 4a 第1の値使用位置検出部 4b 第2の値使用位置検出部 4c 第3の値使用位置検出部 5 コスト記憶部 6 アドレッシングコスト記憶部 7 コスト取出部 8 第1の書き換えコスト取出部 9 第2の書き換えコスト取出部 10 第3の書き換えコスト取出部 11 比較部 12 第1の書き換え部 13 第1の演算式除去部 14 第2の書き換え部 15 第2の演算式除去部 16 第3の書き換え部 17 第3の演算式除去部 18 処理対象保持部 1 Control Unit 3a Calculation Appearance Position Detection Unit 3b Substitution Appearance Position Detection Unit 3c Pointer Arithmetic Expression Detection Unit 4a First Value Use Position Detection Unit 4b Second Value Use Position Detection Unit 4c Third Value Use Position Detection Unit 5 Cost Storage unit 6 Addressing cost storage unit 7 Cost extraction unit 8 First rewriting cost extraction unit 9 Second rewriting cost extraction unit 10 Third rewriting cost extraction unit 11 Comparison unit 12 First rewriting unit 13 First arithmetic expression Removing unit 14 Second rewriting unit 15 Second arithmetic expression removing unit 16 Third rewriting unit 17 Third arithmetic expression removing unit 18 Processing target holding unit

Claims (19)

【特許請求の範囲】[Claims] 【請求項1】コンパイラに備えられ、プログラム保持手
段に保持されているプログラムの演算を書き換えて、書
き換え後、冗長な演算式を除去する冗長式除去装置であ
って、 プログラム保持手段のプログラムから演算子、被演算子
が同一の演算を全て検出し、当該演算によって定義され
ている全ての変数を検出して、検出した演算と変数とを
含む演算式の位置を記憶する演算検出手段と、 演算検出手段が検出した変数のうち2番目以降に位置す
る変数が、被演算子として使用されている演算を全て検
出する被演算子検出手段と、 演算式の型と、演算式の型がこれらの型に該当する演算
式のコストとを記憶するコスト記憶手段と、 被演算子検出手段が検出した演算式の型でコスト記憶手
段を検索し、当該演算式の型に対応するコストを取り出
す第1のコスト取出手段と、 被演算子検出手段が検出した演算式の被演算子に、演算
検出手段が検出した変数のうち1番目に位置する変数を
用いた場合の演算式の型でコスト記憶手段を検索し、当
該演算式の型に対応するコストを取り出す第2のコスト
取出手段と、 第1のコスト取出手段が取り出したコストと、第2のコ
スト取出手段が取り出したコストとを比較する比較手段
と、 比較手段が比較した結果、第2のコスト取出手段が取り
出したコストが小さければ、被演算子検出手段が検出し
た演算で、被演算子として使用されている変数のプログ
ラム中の位置を、演算検出手段が1番目に検出した変数
に書き換える書き換え手段と、 被演算子検出手段が検出した全ての演算中の変数を、書
き換え手段が書き換えた場合、被演算子検出手段が検出
した演算で被演算子として使用されていた変数と、その
変数が定義されていた演算とを含む演算式を、プログラ
ム中から除去する除去手段とを備えることを特徴とする
冗長式除去装置。
Claims: 1. A redundant type elimination device, which is provided in a compiler, rewrites an operation of a program held in a program holding means, and removes a redundant arithmetic expression after the rewriting. An operation detecting means for detecting all operations whose children and operands are the same, detecting all variables defined by the operations, and storing the position of the operation expression including the detected operation and the variables; Among the variables detected by the detection means, the second and subsequent variables are the operand detection means for detecting all operations used as operands, the type of the arithmetic expression, and the type of the arithmetic expression are these The cost storage means for storing the cost of the arithmetic expression corresponding to the type and the cost storage means for the type of the arithmetic expression detected by the operand detection means are searched, and the cost corresponding to the type of the arithmetic expression is retrieved. The first cost extracting means and the arithmetic expression type in the case where the first variable of the variables detected by the operation detecting means is used as the operand of the arithmetic expression detected by the operand detecting means. A second cost extraction unit that retrieves the cost corresponding to the type of the arithmetic expression by searching the cost storage unit, a cost extracted by the first cost extraction unit, and a cost extracted by the second cost extraction unit If the cost extracted by the second cost extraction means is small as a result of comparison between the comparison means for comparison and the comparison means, in the program of the variable used as the operand by the operation detected by the operand detection means. Rewriting means for rewriting the position of No. 1 to the variable detected first by the operation detecting means, and when the rewriting means rewrites all the variables under operation detected by the operand detection means, the operand detection means Redundant expression removing device, comprising: a removing means for removing an arithmetic expression including a variable used as an operand in an operation detected by the operator and an operation in which the variable was defined from a program. .
【請求項2】第1のコスト取出手段は、取り出したコス
トの総和を求め、第2のコスト取出手段は、取り出した
コストの総和を求めて、比較手段は、第1のコスト取出
手段が求めたコストの総和と、第2のコスト取出手段が
求めたコストの総和とを比較することを特徴とする請求
項1記載の冗長式除去装置。
2. A first cost extracting means obtains a total of extracted costs, a second cost extracting means obtains a total of extracted costs, and a comparing means obtains the first cost extracting means. 2. The redundant removing apparatus according to claim 1, wherein the sum of the costs is compared with the sum of the costs obtained by the second cost extracting means.
【請求項3】比較手段は、第1のコスト取出手段が取り
出した個別のコストと、第2のコスト取出手段が取り出
した個別のコストとを比較することを特徴とする請求項
1記載の冗長式除去装置。
3. The redundancy according to claim 1, wherein the comparison means compares the individual costs extracted by the first cost extraction means with the individual costs extracted by the second cost extraction means. Type removal device.
【請求項4】コンパイラに備えられ、プログラム保持手
段に保持されているプログラムの演算を書き換えて、書
き換え後、冗長な演算式を除去する冗長式除去装置であ
って、 プログラム保持手段のプログラムから演算子、被演算子
が同一の演算を全て検出し、当該演算によって定義され
ている全ての変数を検出して、検出した演算と変数とを
含む演算式の位置を記憶する演算検出手段と、 演算検出手段が検出した変数のうち2番目以降に位置す
る変数が、被演算子として使用されている演算を全て検
出する被演算子検出手段と、 演算式の型と、演算式の型がこれらの型に該当する演算
式のコストとを記憶するコスト記憶手段と、 被演算子検出手段が検出した演算式の型でコスト記憶手
段を検索し、当該演算式の型に対応するコストを取り出
す第1のコスト取出手段と、 演算検出手段が検出した演算のうち、2番目以降に位置
する演算を含む演算式についての演算式の型でコスト記
憶手段を検索し、当該演算式の型に対応するコストを取
り出す冗長式コスト取出手段と第1のコスト取出手段が
取り出したコストと、冗長式コスト取出手段が取り出し
たコストとの和を求める算出手段と被演算子検出手段が
検出した演算式の被演算子に、演算検出手段が検出した
変数のうち1番目に位置する変数を用いた場合の演算式
の型でコスト記憶手段を検索し、当該演算式の型に対応
するコストを取り出す第2のコスト取出手段と、算出手
段が求めたコストの和と、第2のコスト取出手段が取り
出したコストとを比較する比較手段と比較手段が比較し
た結果、第2のコスト取出手段が取り出したコストが小
さければ、被演算子検出手段が検出した演算で、被演算
子として使用されている変数のプログラム中の位置を、
演算検出手段が1番目に検出した変数に書き換える書き
換え手段と、 被演算子検出手段が検出した全ての演算中の変数を、書
き換え手段が書き換えた場合、被演算子検出手段が検出
した演算で被演算子として使用されていた変数と、その
変数が定義されていた演算とを含む演算式を、プログラ
ム中から除去する除去手段とを備えることを特徴とする
冗長式除去装置。
4. A redundant type elimination device, which is provided in a compiler, rewrites an operation of a program held in a program holding means, and removes a redundant arithmetic expression after the rewriting, wherein the program is stored in the program holding means. An operation detecting means for detecting all operations whose children and operands are the same, detecting all variables defined by the operations, and storing the position of the operation expression including the detected operation and the variables; Among the variables detected by the detection means, the second and subsequent variables are the operand detection means for detecting all operations used as operands, the type of the arithmetic expression, and the type of the arithmetic expression are these The cost storage means for storing the cost of the arithmetic expression corresponding to the type and the cost storage means for the type of the arithmetic expression detected by the operand detection means are searched, and the cost corresponding to the type of the arithmetic expression is retrieved. The cost storage means is searched for with the first cost extraction means and the operation expression type for the operation expression including the second or later operation among the operations detected by the operation detection means, and the type of the operation expression is obtained. A calculating means for obtaining the sum of the costs taken out by the redundant type cost taking means for taking out the corresponding costs and the first cost taking means and the costs taken out by the redundant type cost taking means, and the arithmetic expression detected by the operand detection means The cost storage means is searched for by the type of the arithmetic expression when the variable located first among the variables detected by the arithmetic detection means is used as the operand of, and the cost corresponding to the type of the arithmetic expression is extracted. As a result of the comparison between the sum of the cost extraction means of No. 2 and the cost obtained by the calculation means and the cost extracted by the second cost extraction means and the comparison means, the second cost extraction means extracted. If the cost is small, the position in the program of the variable used as the operand in the operation detected by the operand detection means,
When the rewriting means rewrites all variables in the operation detected by the operand detecting means and the rewriting means that rewrites to the variable detected first by the operation detecting means, the operation detected by the operator detecting means is used as the rewriting means. A redundant expression removing apparatus comprising: a removing unit that removes an arithmetic expression including a variable used as an operator and an operation in which the variable is defined from a program.
【請求項5】第1のコスト取出手段は、取り出したコス
トの総和を求め、算出手段は、第1のコスト取手段が取
り出したコストの総和と、冗長式コスト取出手段が取り
出したコストとの和を求め、第2のコスト取出手段は、
取り出したコストの総和を求めて、比較手段は、算出手
段が求めたコストの和と、第2のコスト取出手段が求め
たコストの総和とを比較することを特徴とする請求項4
記載の冗長式除去装置。
5. The first cost take-out means obtains the total sum of the taken out costs, and the calculating means takes the sum of the costs taken out by the first cost taking means and the cost taken out by the redundant type cost take-out means. The second means of taking out the cost is
5. The sum total of the extracted costs, and the comparing means compares the sum of the costs calculated by the calculating means with the sum of the costs calculated by the second cost extracting means.
Redundant removal device as described.
【請求項6】算出手段は、第1のコスト取手段が取り出
した個別のコストと、冗長式コスト取出手段が取り出し
たコストとの和を求め、比較手段は、算出手段が求めた
コストの和と、第2のコスト取出手段が求めた個別のコ
ストとを比較することを特徴とする請求項4記載の冗長
式除去装置。
6. The calculating means obtains the sum of the individual costs taken out by the first cost taking means and the cost taken out by the redundant cost taking means, and the comparing means gives the sum of the costs found by the calculating means. 5. The redundant removal device according to claim 4, characterized in that the individual cost calculated by the second cost extracting means is compared with the individual cost.
【請求項7】コンパイラに備えられ、プログラム保持手
段に保持されているプログラムの演算を書き換えて、書
き換え後、冗長な演算式を除去する冗長式除去装置であ
って、 プログラム保持手段に保持されているプログラムから、
変数に定数を代入する演算式、及び、変数に変数の値を
代入する演算式を全て検出する演算式検出手段と、 演算式検出手段が検出した演算式の等号の左側に存在す
る変数が、被演算子として使用される演算式をプログラ
ム保持手段から全て検出する被演算子検出手段と、 演算式の型と、演算式の型がこれらの型に該当する演算
式のコストとを記憶するコスト記憶手段と、 被演算子検出手段が検出した演算式の型でコスト記憶手
段を検索し、当該演算式の型に対応するコストを取り出
す第1のコスト取出手段と、 被演算子検出手段が検出した演算式の被演算子に、演算
式検出手段が検出した変数のうち1番目に位置する変数
を用いた場合の演算式の型でコスト記憶手段を検索し、
当該演算式の型に対応するコストを取り出す第2のコス
ト取出手段と、 第1のコスト取出手段が取り出したコストと、第2のコ
スト取出手段が取り出したコストとを比較する比較手段
と、 第1のコスト取出手段が取り出したコストと、第2のコ
スト取出手段が検出したコストとを比較する比較手段
と、 比較手段が比較した結果、第2のコスト取出手段が取り
出したコストが小さければ、被演算子検出手段が検出し
た演算で被演算子として使用されている変数のプログラ
ム中の位置を、演算式検出手段が検出した変数あるいは
定数に書き換える書き換え手段と、 被演算子検出手段が検出した全ての演算中の変数を、書
き換え手段が書き換えた場合、被演算子検出手段が検出
した演算で被演算子として使用されていた変数が等号の
左側に存在する演算式であり、かつ、演算式検出手段が
検出した演算式を、プログラム中から除去する除去手段
とを備えることを特徴とする冗長式除去装置。
7. A redundant type removing device, which is provided in a compiler, rewrites the operation of a program held in the program holding means, and removes redundant arithmetic expressions after the rewriting, which is held in the program holding means. From the program
There is an arithmetic expression for substituting a constant for a variable and an arithmetic expression detecting means for detecting all arithmetic expressions for substituting a variable value for a variable, and a variable existing on the left side of the equal sign of the arithmetic expression detected by the arithmetic expression detecting means , Operand detection means for detecting all the arithmetic expressions used as operands from the program holding means, the type of the arithmetic expression, and the cost of the arithmetic expression whose arithmetic expression type corresponds to these types are stored. The cost storage means and the first cost extraction means for searching the cost storage means by the type of the arithmetic expression detected by the operand detection means and extracting the cost corresponding to the type of the arithmetic expression, and the operand detection means The cost storage means is searched by the type of the arithmetic expression when the variable located first in the variables detected by the arithmetic expression detecting means is used as the operand of the detected arithmetic expression,
Second cost extraction means for extracting a cost corresponding to the type of the arithmetic expression, comparison means for comparing the cost extracted by the first cost extraction means with the cost extracted by the second cost extraction means, If the cost taken out by the second cost take-out means is small as a result of the comparison means comparing the cost taken out by the first cost take-out means with the cost detected by the second cost take-out means, Rewriting means for rewriting the position in the program of the variable used as the operand in the operation detected by the operand detection means to the variable or constant detected by the arithmetic expression detection means, and the operand detection means detected When the rewriting means rewrites all the variables in the calculation, the variable used as the operand in the calculation detected by the operand detection means exists on the left side of the equal sign. And a removal unit that removes the calculation formula detected by the calculation formula detection unit from the program.
【請求項8】第1のコスト取出手段は、取り出したコス
トの総和を求め、第2のコスト取出手段は、取り出した
コストの総和を求めて、比較手段は、第1のコスト取出
手段が求めたコストの総和と、第2のコスト取出手段が
求めたコストの総和とを比較することを特徴とする請求
項7記載の冗長式除去装置。
8. A first cost extraction means calculates a total of extracted costs, a second cost extraction means calculates a total of extracted costs, and a comparison means calculates a first cost extraction means. 8. The redundant removing apparatus according to claim 7, wherein the sum of the costs is compared with the sum of the costs obtained by the second cost extracting means.
【請求項9】比較手段は、第1のコスト取出手段が取り
出した個別のコストと、第2のコスト取出手段が取り出
した個別のコストとを比較することを特徴とする請求項
7記載の冗長式除去装置。
9. The redundancy according to claim 7, wherein the comparison means compares the individual costs extracted by the first cost extraction means with the individual costs extracted by the second cost extraction means. Type removal device.
【請求項10】コンパイラに備えられ、プログラム保持
手段に保持されているプログラムの演算を書き換えて、
書き換え後、冗長な演算式を除去する冗長式除去装置で
あって、 プログラム保持手段に保持されているプログラムから、
変数に定数を代入する演算式、及び、変数に変数の値を
代入する演算式を全て検出する演算式検出手段と、 演算式検出手段が検出した演算式の等号の左側に存在す
る変数が、被演算子として使用される演算式をプログラ
ム保持手段から全て検出する被演算子検出手段と、 演算式の型と、演算式の型がこれらの型に該当する演算
式のコストとを記憶するコスト記憶手段と、 被演算子検出手段が検出した演算式の型でコスト記憶手
段を検索し、当該演算式の型に対応するコストを取り出
す第1のコスト取出手段と、 演算式検出手段が検出した演算式の演算式の型でコスト
記憶手段を検索し、当該演算式の型に対応するコストを
取り出す冗長式コスト取出手段と第1のコスト取出手段
が取り出したコストと、冗長式コスト取出手段が取り出
したコストとの和を求める算出手段と被演算子検出手段
が検出した演算式の被演算子に、演算式検出手段が検出
した変数のうち1番目に位置する変数を用いた場合の演
算式の型でコスト記憶手段を検索し、当該演算式の型に
対応するコストを取り出す第2のコスト取出手段と、 算出手段が求めたコストの和と、第2のコスト取出手段
が取り出したコストとを比較する比較手段と比較手段が
比較した結果、第2のコスト取出手段が取り出したコス
トが小さければ、被演算子検出手段が検出した演算で被
演算子として使用されている変数のプログラム中の位置
を、演算式検出手段が検出した変数あるいは定数に書き
換える書き換え手段と、 被演算子検出手段が検出した全ての演算中の変数を、書
き換え手段が書き換えた場合、被演算子検出手段が検出
した演算で被演算子として使用されていた変数が等号の
左側に存在する演算式であり、かつ、演算式検出手段が
検出した演算式を、プログラム中から除去する除去手段
とを備えることを特徴とする冗長式除去装置。
10. An operation of a program held in a program holding means provided in a compiler is rewritten,
A redundant type removal device for removing redundant arithmetic expressions after rewriting, wherein the program stored in the program storage means is
There is an arithmetic expression for substituting a constant for a variable and an arithmetic expression detecting means for detecting all arithmetic expressions for substituting a variable value for a variable, and a variable existing on the left side of the equal sign of the arithmetic expression detected by the arithmetic expression detecting means , Operand detection means for detecting all the arithmetic expressions used as operands from the program holding means, the type of the arithmetic expression, and the cost of the arithmetic expression whose arithmetic expression type corresponds to these types are stored. The cost storage means and the first cost extraction means for searching the cost storage means by the type of the arithmetic expression detected by the operand detection means and extracting the cost corresponding to the type of the arithmetic expression, and the arithmetic expression detection means The cost storage means is searched by the type of the arithmetic expression of the arithmetic expression and the cost corresponding to the type of the arithmetic expression is extracted by the redundant type cost extracting means and the first cost extracting means, and the redundant type cost extracting means. Taken out The type of the arithmetic expression in the case where the first variable among the variables detected by the arithmetic expression detecting means is used as the operand of the arithmetic expression detected by the calculating means for obtaining the sum The second cost extraction means for searching the cost storage means with to extract the cost corresponding to the type of the arithmetic expression, the sum of the costs calculated by the calculation means and the cost extracted by the second cost extraction means As a result of the comparison between the comparison means and the comparison means, if the cost extracted by the second cost extraction means is small, the position in the program of the variable used as the operand in the operation detected by the operand detection means is determined. , Rewriting means for rewriting to the variable or constant detected by the arithmetic expression detection means, and when the rewriting means rewrites all the variables in the operation detected by the operand detection means, the operand detection means detects The variable used as the operand in the arithmetic operation is an arithmetic expression existing on the left side of the equal sign, and the arithmetic expression detected by the arithmetic expression detecting means is removed from the program. Characteristic redundant removal device.
【請求項11】第1のコスト取出手段は、取り出したコ
ストの総和を求め、算出手段は、第1のコスト取手段が
取り出したコストの総和と、冗長式コスト取出手段が取
り出したコストとの和を求め、第2のコスト取出手段
は、取り出したコストの総和を求めて、比較手段は、算
出手段が求めたコストの和と、第2のコスト取出手段が
求めたコストの総和とを比較することを特徴とする請求
項10記載の冗長式除去装置。
11. The first cost take-out means obtains the total sum of the taken out costs, and the calculating means takes the sum of the costs taken out by the first cost take-out means and the cost taken out by the redundant type cost take-out means. The second cost extraction means calculates the sum of the extracted costs, and the comparison means compares the sum of the costs calculated by the calculation means and the sum of the costs calculated by the second cost extraction means. The redundant removing device according to claim 10, wherein
【請求項12】算出手段は、第1のコスト取手段が取り
出した個別のコストと、冗長式コスト取出手段が取り出
したコストとの和を求め、比較手段は、算出手段が求め
たコストの和と、第2のコスト取出手段が求めた個別の
コストとを比較することを特徴とする請求項10記載の
冗長式除去装置。
12. The calculating means obtains the sum of the individual costs taken out by the first cost taking means and the costs taken out by the redundant cost taking means, and the comparing means takes the sum of the costs obtained by the calculating means. 11. The redundant removal device according to claim 10, wherein the cost is compared with the individual cost obtained by the second cost extraction means.
【請求項13】コンパイラに備えられ、プログラム保持
手段に保持されているプログラムの演算を書き換えて、
書き換え後、冗長な演算式を除去する冗長式除去装置で
あって、 プログラム保持手段のプログラムから、ポインタである
変数が定義されている演算式を検出し、検出した演算お
よび変数が含まれる演算式の位置を記憶する演算検出手
段と、 演算検出手段が検出した変数が、被演算子として使用さ
れている演算式を全て検出する被演算子検出手段と、 1つの機械語命令で実行可能な演算式であり、かつ、ポ
インタに使用される被演算子、インデックスに使用され
る被演算子、およびオフセットに使用される被演算子の
うち、少なくとも2つの被演算子を含むものの型と、当
該演算式の型に対応する演算式のコストとを記憶するコ
スト記憶手段と、 被演算子検出手段が検出した演算式で、コスト記憶手段
を検索し、当該演算式に対応する演算式のコストを取り
出す第1のコスト取出手段と、 被演算子検出手段が検出した演算式の被演算子に、前記
演算検出手段が検出した演算を当てはめた場合の演算式
の型で、コスト記憶手段を検索し、当該演算式に対応す
るコストを取り出す第2のコスト取出手段と、 第1のコスト取出手段が取り出したコストと、第2のコ
スト取出手段が取り出したコストとを比較する比較手段
と、 比較手段が比較した結果、第2のコスト取出手段が取り
出したコストが小さければ、被演算子検出手段が検出し
た演算式で、被演算子として使用されている変数のプロ
グラム中の位置を、演算検出手段が検出した演算に書き
換える書き換え手段と、 被演算子検出手段が検出した全ての演算式中の変数を、
書き換え手段が書き換えた場合、演算検出手段が検出し
た演算を含む演算式を、プログラム中から除去する除去
手段とを備えることを特徴とする冗長式除去装置。
13. An operation of a program held in a program holding means provided in a compiler is rewritten,
A redundant expression removing device for removing a redundant arithmetic expression after rewriting, wherein an arithmetic expression in which a variable that is a pointer is defined is detected from a program of a program holding means, and the detected arithmetic operation and an arithmetic expression including the variable are detected. , An operation detecting means for storing the position of, an operator detecting means for detecting all arithmetic expressions used as operands by variables detected by the operation detecting means, and an operation executable by one machine language instruction The type of an expression that includes at least two operands among the operands used for pointers, the operands used for indexes, and the operands used for offsets, and the operation A cost storage means for storing the cost of the arithmetic expression corresponding to the type of the expression, and an arithmetic expression corresponding to the arithmetic expression searched for in the cost storage means by the arithmetic expression detected by the operand detection means. Cost storage means in the form of an arithmetic expression when the operation detected by the operation detection means is applied to the operand of the arithmetic expression detected by the operand detection means and the first cost extraction means for extracting the cost And a comparing means for comparing the cost extracted by the first cost extracting means with the cost extracted by the second cost extracting means. As a result of comparison by the comparison means, if the cost extracted by the second cost extraction means is small, the position in the program of the variable used as the operand is calculated by the arithmetic expression detected by the operand detection means, The rewriting means for rewriting the operation detected by the operation detecting means, and the variables in all the operation expressions detected by the operand detection means,
A redundant type removing device comprising: a removing unit that removes an arithmetic expression including an operation detected by the operation detecting unit from a program when the rewriting unit rewrites.
【請求項14】第1のコスト取出手段は、取り出したコ
ストの総和を求め、第2のコスト取出手段は、取り出し
たコストの総和を求めて、比較手段は、第1のコスト取
出手段が求めたコストの総和と、第2のコスト取出手段
が求めたコストの総和とを比較することを特徴とする請
求項13記載の冗長式除去装置。
14. A first cost extracting means obtains a total of extracted costs, a second cost extracting means obtains a total of extracted costs, and a comparing means obtains the first cost extracting means. 14. The redundant removal apparatus according to claim 13, wherein the total sum of the costs is compared with the total sum of the costs obtained by the second cost extracting means.
【請求項15】比較手段は、第1のコスト取出手段が取
り出した個別のコストと、第2のコスト取出手段が取り
出した個別のコストとを比較することを特徴とする請求
項13記載の冗長式除去装置。
15. The redundancy according to claim 13, wherein the comparison means compares the individual costs extracted by the first cost extraction means with the individual costs extracted by the second cost extraction means. Type removal device.
【請求項16】コンパイラに備えられ、プログラム保持
手段に保持されているプログラムの演算を書き換えて、
書き換え後、冗長な演算式を除去する冗長式除去装置で
あって、 プログラム保持手段のプログラムから、ポインタである
変数が定義されている演算式を検出し、検出した演算お
よび変数が含まれる演算式の位置を記憶する演算検出手
段と、 演算検出手段が検出した変数が、被演算子として使用さ
れている演算式を全て検出する被演算子検出手段と、 1つの機械語命令で実行可能な演算式であり、かつ、ポ
インタに使用される被演算子、インデックスに使用され
る被演算子、およびオフセットに使用される被演算子の
うち、少なくとも2つの被演算子を含むものの型と、当
該演算式の型に対応する演算式のコストとを記憶するコ
スト記憶手段と、 被演算子検出手段が検出した演算式で、コスト記憶手段
を検索し、当該演算式に対応する演算式のコストを取り
出す第1のコスト取出手段と、 演算検出手段が検出した演算のうち、2番目以降に位置
する演算を含む演算式についての演算式の型でコスト記
憶手段を検索し、当該演算式の型に対応するコストを取
り出す冗長式コスト取出手段と第1のコスト取出手段が
取り出したコストと、冗長式コスト取出手段が取り出し
たコストとの和を求める算出手段と被演算子検出手段が
検出した演算式の被演算子に、演算検出手段が検出した
変数のうち1番目に位置する変数を用いた場合の演算式
の型でコスト記憶手段を検索し、当該演算式の型に対応
するコストを取り出す第2のコスト取出手段と、 算出手段が求めたコストの和と、第2のコスト取出手段
が取り出したコストとを比較する比較手段と比較手段が
比較した結果、第2のコスト取出手段が取り出したコス
トが小さければ、被演算子検出手段が検出した演算式
で、被演算子として使用されている変数のプログラム中
の位置を、演算検出手段が検出した演算に書き換える書
き換え手段と、 被演算子検出手段が検出した全ての演算式中の変数を、
書き換え手段が書き換えた場合、演算検出手段が検出し
た演算を含む演算式を、プログラム中から除去する除去
手段とを備えることを特徴とする冗長式除去装置。
16. A rewriting operation of a program held in a program holding means, which is provided in a compiler,
A redundant expression removing device for removing a redundant arithmetic expression after rewriting, wherein an arithmetic expression in which a variable that is a pointer is defined is detected from a program of a program holding means, and the detected arithmetic operation and an arithmetic expression including the variable are detected. , An operation detecting means for storing the position of, an operator detecting means for detecting all arithmetic expressions used as operands by variables detected by the operation detecting means, and an operation executable by one machine language instruction The type of an expression that includes at least two operands among the operands used for pointers, the operands used for indexes, and the operands used for offsets, and the operation A cost storage means for storing the cost of the arithmetic expression corresponding to the type of the expression, and an arithmetic expression corresponding to the arithmetic expression searched for in the cost storage means by the arithmetic expression detected by the operand detection means. The cost storage means is searched for with a first cost extraction means for extracting the cost of the cost and an operation expression type of an operation expression including an operation positioned second and later among the operations detected by the operation detection means, and the operation expression Of the redundant type cost take-out means for taking out the cost corresponding to the type of the first cost take-out means, and the cost taken out by the redundant type cost take-out means The cost storage means is searched with the type of the arithmetic expression when the variable located first in the variables detected by the arithmetic detection means is used as the operand of the arithmetic expression, and the cost corresponding to the type of the arithmetic expression is searched. The second cost extraction means compares the sum of the costs obtained by the second cost extraction means with the calculation means and the cost extracted by the second cost extraction means with the comparison means and the comparison means. If the cost taken out by the means is small, rewriting means for rewriting the position in the program of the variable used as the operand in the arithmetic expression detected by the operand detecting means to the operation detected by the arithmetic detecting means, Variables in all arithmetic expressions detected by the operand detection means,
A redundant type removing device comprising: a removing unit that removes an arithmetic expression including an operation detected by the operation detecting unit from a program when the rewriting unit rewrites.
【請求項17】第1のコスト取出手段は、取り出したコ
ストの総和を求め、算出手段は、第1のコスト取手段が
取り出したコストの総和と、冗長式コスト取出手段が取
り出したコストとの和を求め、第2のコスト取出手段
は、取り出したコストの総和を求めて、比較手段は、算
出手段が求めたコストの和と、第2のコスト取出手段が
求めたコストの総和とを比較することを特徴とする請求
項16記載の冗長式除去装置。
17. The first cost take-out means obtains the total sum of the taken-out costs, and the calculating means takes the sum of the costs taken out by the first cost take-out means and the cost taken out by the redundant type cost take-out means. The second cost extraction means calculates the sum of the extracted costs, and the comparison means compares the sum of the costs calculated by the calculation means and the sum of the costs calculated by the second cost extraction means. 17. The redundant removal device according to claim 16, wherein:
【請求項18】算出手段は、第1のコスト取手段が取り
出した個別のコストと、冗長式コスト取出手段が取り出
したコストとの和を求め、比較手段は、算出手段が求め
たコストの和と、第2のコスト取出手段が求めた個別の
コストとを比較することを特徴とする請求項16記載の
冗長式除去装置。
18. The calculating means obtains the sum of the individual costs taken out by the first cost taking means and the costs taken out by the redundant type cost taking means, and the comparing means takes the sum of the costs obtained by the calculating means. 17. The redundant removal device according to claim 16, characterized in that the individual cost calculated by the second cost extraction means is compared with the individual cost.
【請求項19】前記コスト記憶手段が記憶するコストと
は、演算式の型に対応する機械語命令の実行時間および
/またはメモリサイズであることを特徴とする請求項1
から18記載の何れかの冗長式除去装置。
19. The cost stored in the cost storage means is an execution time and / or a memory size of a machine language instruction corresponding to a type of an arithmetic expression.
22. The redundant removal device according to any one of 18 to 18.
JP31328993A 1993-12-14 1993-12-14 Redundant remover Expired - Fee Related JP3313859B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP31328993A JP3313859B2 (en) 1993-12-14 1993-12-14 Redundant remover

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP31328993A JP3313859B2 (en) 1993-12-14 1993-12-14 Redundant remover

Publications (2)

Publication Number Publication Date
JPH07168719A true JPH07168719A (en) 1995-07-04
JP3313859B2 JP3313859B2 (en) 2002-08-12

Family

ID=18039430

Family Applications (1)

Application Number Title Priority Date Filing Date
JP31328993A Expired - Fee Related JP3313859B2 (en) 1993-12-14 1993-12-14 Redundant remover

Country Status (1)

Country Link
JP (1) JP3313859B2 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000284970A (en) * 1999-03-29 2000-10-13 Matsushita Electric Ind Co Ltd Program converting device and processor
JP2007272679A (en) * 2006-03-31 2007-10-18 Mitsubishi Electric Corp Ladder program optimization apparatus and optimization program
JP2021518710A (en) * 2018-03-27 2021-08-02 エヌチェーン ホールディングス リミテッドNchain Holdings Limited Computer-implemented systems and methods for serialization of arithmetic circuits

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000284970A (en) * 1999-03-29 2000-10-13 Matsushita Electric Ind Co Ltd Program converting device and processor
JP2007272679A (en) * 2006-03-31 2007-10-18 Mitsubishi Electric Corp Ladder program optimization apparatus and optimization program
JP4494361B2 (en) * 2006-03-31 2010-06-30 三菱電機株式会社 Ladder program optimization device and optimization program
JP2021518710A (en) * 2018-03-27 2021-08-02 エヌチェーン ホールディングス リミテッドNchain Holdings Limited Computer-implemented systems and methods for serialization of arithmetic circuits

Also Published As

Publication number Publication date
JP3313859B2 (en) 2002-08-12

Similar Documents

Publication Publication Date Title
US4656583A (en) Method for improving global common subexpression elimination and code motion in an optimizing compiler
EP1280056B1 (en) Generation of debugging information
US6966055B2 (en) Optimizing post-link code
US7200843B2 (en) Retrieval of symbol attributes
JPH10228382A (en) Compiling system
US20100095286A1 (en) Register reduction and liveness analysis techniques for program code
US6684394B1 (en) Relocation format for linking with relocation instructions containing operations for combining section data
US6240546B1 (en) Identifying date fields for runtime year 2000 system solution process, method and article of manufacture
JP3130446B2 (en) Program conversion device and processor
EP1085411B1 (en) A relocation format for linking
Rieu-Helft et al. How to get an efficient yet verified arbitrary-precision integer library
US6687899B1 (en) Relocation format for linking
US9027008B2 (en) Method, computer, and computer program for speculatively optimizing code
JPH10133884A (en) Method for executing programming code including conjectural code
US6077314A (en) Method of, system for, and computer program product for providing improved code motion and code redundancy removal using extended global value numbering
US6202203B1 (en) Method of, system for, and computer program product for providing global value numbering
JP2012053679A (en) Optimization device, optimization method and compiler program
JP2817786B2 (en) Simulation apparatus and simulation method
JPH07168719A (en) Redundant type removing device
Housel et al. A methodology for machine language decompilation
JP3461185B2 (en) Method and apparatus for registering source code line number to load module
US4212058A (en) Computer store mechanism
JP3608446B2 (en) Compiler device and processor
US20060095896A1 (en) Apparatus, system, and method of removing exception related dependencies
JP3324542B2 (en) Virtual machine

Legal Events

Date Code Title Description
LAPS Cancellation because of no payment of annual fees