JPH0546404A - Branch instruction deletion optimization method - Google Patents

Branch instruction deletion optimization method

Info

Publication number
JPH0546404A
JPH0546404A JP20022291A JP20022291A JPH0546404A JP H0546404 A JPH0546404 A JP H0546404A JP 20022291 A JP20022291 A JP 20022291A JP 20022291 A JP20022291 A JP 20022291A JP H0546404 A JPH0546404 A JP H0546404A
Authority
JP
Japan
Prior art keywords
branch
instruction
branch instruction
intermediate language
operands
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP20022291A
Other languages
Japanese (ja)
Inventor
Yuuki Tachikawa
結貴 立川
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujitsu Ltd
Original Assignee
Fujitsu Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujitsu Ltd filed Critical Fujitsu Ltd
Priority to JP20022291A priority Critical patent/JPH0546404A/en
Publication of JPH0546404A publication Critical patent/JPH0546404A/en
Pending legal-status Critical Current

Links

Landscapes

  • Advance Control (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

(57)【要約】 【目的】 本発明は、翻訳時に分岐命令を削除して最適
化する分岐命令削除最適化方式に関し、翻訳時に、既に
分岐命令の分岐先が確定する分岐命令を削除し、実行性
能を向上させることを目的とする。 【構成】 ソースプログラム(中間言語)の判定文のオ
ペランドが定数のときあるいは変数が同じときに、分岐
命令を削除する比較・分岐削除処理2を備え、この比較
・分岐削除処理2が翻訳時にソースプログラム(中間言
語)の判定文のオペランドが全て定数のときあるいはオ
ペランドの変数が同じときに、当該判定文および分岐先
でない方の命令を削除し、最適化するように構成する。
(57) [Summary] [Object] The present invention relates to a branch instruction deletion optimization method that deletes and optimizes a branch instruction at the time of translation, and at the time of translation, deletes a branch instruction whose branch destination has already been determined, The purpose is to improve execution performance. [Composition] A comparison / branch deletion processing 2 for deleting a branch instruction is provided when the operand of the judgment statement of the source program (intermediate language) is a constant or the variables are the same, and this comparison / branch deletion processing 2 is the source during translation. When all the operands of the judgment sentence of the program (intermediate language) are constants or when the variables of the operands are the same, the judgment sentence and the instruction that is not the branch destination are deleted and optimized.

Description

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

【0001】[0001]

【産業上の利用分野】本発明は、翻訳時に分岐命令を削
除して最適化する分岐命令削除最適化方式に関するもの
である。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a branch instruction deletion optimizing method for optimizing a branch instruction by deleting it during translation.

【0002】[0002]

【従来の技術】ソースプログラムに判定文を書いた場
合、機械命令では分岐命令になる。従来のコンパイラ
は、翻訳時に分岐先が確定している分岐命令であっても
分岐命令を削除していなくそのまま翻訳し、機械命令を
生成していた。例えば図5の(イ)に示すC言語のソー
スプログラム(中間言語)のif文 について、最適化を行うと、図5の(ロ)に示すよう
に、当該if文のオペランドa、bに値が置き換えら
れ、下記のようにしていた。
2. Description of the Related Art When a judgment statement is written in a source program, a machine instruction becomes a branch instruction. Conventional compilers generate a machine instruction by directly converting a branch instruction without deleting the branch instruction, even if the branch instruction is fixed at the time of translation. For example, the if statement of the C language source program (intermediate language) shown in FIG. With respect to the above, when the optimization is performed, the values are replaced in the operands a and b of the if statement, as shown in FIG.

【0003】 [0003]

【0004】[0004]

【発明が解決しようとする課題】このように、従来はi
f文などで分岐先が確定していても、図5の(イ)を最
適化によって図5の(ロ)に示すようにif文などのオ
ペランドに値(定数)を置き換え、これを機械語に翻訳
していたため、機械語で分岐命令の分だけ実行時間が多
く必要になってしまい、実行性能が悪くなると共に、実
行しない個所があり、余分な機械語が残ってしまい、ロ
ードモジュールのサイズを大きくしてしまうという問題
があった。このため、実行しない個所を最適化して削除
することが望まれている。
As described above, the conventional i
Even if the branch destination is determined by the f statement or the like, the value (constant) is replaced with the operand of the if statement or the like as shown in (b) of FIG. Since it was translated to, the execution time was increased by the amount of branch instructions in the machine language, the execution performance deteriorates, there are parts that are not executed, extra machine language remains, load module size There was a problem of increasing. Therefore, it is desired to optimize and delete the portions that are not executed.

【0005】本発明は、翻訳時に、既に分岐命令の分岐
先が確定する分岐命令を削除し、実行性能を向上させる
ことを目的としている。
An object of the present invention is to improve the execution performance by deleting a branch instruction whose branch destination of the branch instruction is already determined at the time of translation.

【0006】[0006]

【課題を解決するための手段】図1を参照して課題を解
決するための手段を説明する。図1において、比較・分
岐削除処理2は、ソースプログラム(中間言語)4の判
定文のオペランドが定数かあるいは変数が同じかを比較
したり、分岐命令を削除したりするものである。
[Means for Solving the Problems] Means for solving the problems will be described with reference to FIG. In FIG. 1, the comparison / branch deletion processing 2 is to compare whether the operands of the judgment statement of the source program (intermediate language) 4 are constants or variables are the same, or delete the branch instruction.

【0007】ソースプログラム(中間言語)4は、最適
化対象のソースプログラムを変換した中間言語である。
The source program (intermediate language) 4 is an intermediate language obtained by converting the source program to be optimized.

【0008】[0008]

【作用】本発明は、図1に示すように、比較・分岐削除
処理2が翻訳時にソースプログラム(中間言語)4を順
次取込み、判定文のオペランドが全て定数であった場
合、あるいはオペランドの変数が全て同じであった場
合、ソースプログラム(中間言語)4の判定文および分
岐先でない方の命令を削除し、最適化を行うようにして
いる。
According to the present invention, as shown in FIG. 1, when the comparison / branch deletion processing 2 sequentially takes in the source program (intermediate language) 4 at the time of translation and all the operands of the judgment statement are constants, or the variables of the operands. If all are the same, the decision statement of the source program (intermediate language) 4 and the instruction that is not the branch destination are deleted and optimization is performed.

【0009】従って、翻訳時に、既に分岐命令の分岐先
が確定する分岐命令の判定文および分岐先でない方の命
令を削除し、実行性能を向上させることが可能となる。
Therefore, at the time of translation, it becomes possible to improve the execution performance by deleting the judgment statement of the branch instruction in which the branch destination of the branch instruction has already been determined and the instruction that is not the branch destination.

【0010】[0010]

【実施例】次に、図1から図4を用いて本発明の実施例
の構成および動作を順次詳細に説明する。
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS Next, the construction and operation of an embodiment of the present invention will be described in detail with reference to FIGS.

【0011】図1において、コンパイラ1は、ソースプ
ログラムを読込み、中間言語に変換したり、この中間言
語について最適化を行ったり、最適化後の中間言語を機
械語に翻訳したりなどするものであって、ここでは、本
発明の比較・分岐削除処理2などから構成されるもので
ある。
In FIG. 1, a compiler 1 reads a source program, converts it into an intermediate language, optimizes this intermediate language, translates the optimized intermediate language into a machine language, and so on. Therefore, here, the comparison / branch deletion processing 2 of the present invention is included.

【0012】比較・分岐削除処理2は、ソースプログラ
ム(中間言語)4の判定文のオペランドが定数である
か、あるいは変数が同じかを比較したり、分岐命令を削
除したりするものである。例えばif文 のうちのif(a==b)のオペランドaと、bとが定
数か否かを判定する。これが例えば図3の(イ)のよう
にif(10==8)と判明したときにオペランドa、
bが共に定数となり、削除対象と判定する。
The comparison / branch deletion processing 2 is to compare whether the operands of the judgment statement of the source program (intermediate language) 4 are constants or variables are the same, or delete the branch instruction. For example if sentence Of if (a == b) of operands a and b are constants. When this is found to be if (10 == 8) as shown in (a) of FIG. 3, the operand a,
Both b are constants, and it is determined that they are to be deleted.

【0013】メモリ3は、ソースプログラム(中間言
語)4などを格納するメモリである。ソースプログラム
(中間言語)4は、本実施例の判定文を削除する対象
の、ソースプログラムを変換した中間言語である。右側
のフローは、左側のソースプログラム(中間言語)の処
理をイメージ図として表示したものである。ここでin
t a,b,x;/変数a、b、xは整数である a=10;/変数aの値は10である b=8;/変数bの値は8である 次に、図2のフローチャートに示す順序に従い、図3
の(イ)の最適化前の状態から図3の(ロ)の最適化後
の状態を生成する処理を詳細に説明する。
The memory 3 is a memory for storing a source program (intermediate language) 4 and the like. The source program (intermediate language) 4 is an intermediate language obtained by converting the source program, which is a target for deleting the determination statement of the present embodiment. The flow on the right shows the processing of the source program (intermediate language) on the left as an image diagram. Where in
t a, b, x; / variables a, b, x are integers a = 10; / the value of variable a is 10 b = 8; / the value of variable b is 8 Next, according to the order shown in the flowchart of FIG.
The process of generating the post-optimization state of FIG. 3B from the pre-optimization state of FIG. 3A will be described in detail.

【0014】図2において、S1は、命令は残っている
か否かを判別する。これは、図3の(イ)の最適化前の
状態(ソースプログラムを変換した中間言語の本発明の
最適化前の状態)で命令を先頭から順次取込み、未処理
の命令が残っているか否かを判別する。NOの場合に
は、終了する。YESの場合には、S2で次の命令(中
間言語の命令)を1つ読み出し、S3に進む。
In FIG. 2, S1 determines whether or not there are any remaining commands. This is because the instructions are sequentially fetched from the beginning in the pre-optimization state (pre-optimization state of the present invention of the intermediate language obtained by converting the source program) of FIG. Determine whether. If NO, the process ends. In the case of YES, one next instruction (intermediate language instruction) is read in S2, and the process proceeds to S3.

【0015】S3は、命令が分岐命令か否かを判別す
る。YESの場合には、本発明の最適化の対象の分岐命
令であったので、S4に進む。NOの場合には、本発明
の最適化の対象の分岐命令でなかったので、S1を繰り
返し行う。
In step S3, it is determined whether the instruction is a branch instruction. In the case of YES, the branch instruction is the optimization target of the present invention, so the process proceeds to S4. In the case of NO, since the branch instruction is not the optimization target of the present invention, S1 is repeated.

【0016】S4は、分岐命令のオペランドが全て定数
か否かを判別する。これは、例えばif文がif(a=
=b)のときオペランドa、bが共に定数であるか否か
を判別する。YESの場合には、分岐命令のオペランド
が全て定数であって、分岐先が確定しているので、当該
分岐命令を削除できることが判明したので、S6に進
み、オペランドと分岐条件から真か偽か判定し、真のと
きにS7で分岐命令と偽のときの命令とを削除し、偽の
ときにS8で分岐命令と真のときの命令とを削除する。
一方、S4でNOの場合、オペランドが全て定数でなか
ったので、S5に進む。
In step S4, it is determined whether all the operands of the branch instruction are constants. This means that if the if sentence is if (a =
= B), it is determined whether or not the operands a and b are both constants. In the case of YES, since the operands of the branch instruction are all constants and the branch destination has been determined, it was found that the branch instruction can be deleted. Therefore, the process proceeds to S6, and whether the operand and the branch condition are true or false. If YES, the branch instruction and the false instruction are deleted in S7 when true, and the branch instruction and the true instruction are deleted in S8 when false.
On the other hand, in the case of NO in S4, since all the operands are not constants, the process proceeds to S5.

【0017】S5は、分岐命令のオペランドの変数が同
じか否かを判別する。YESの場合には、S6に進み、
オペランドと分岐条件から真か偽かを判定し、真のとき
にS7で分岐命令と偽のときの命令を削除し、偽のとき
にS8で分岐命令と真のときの命令を削除する。
In step S5, it is determined whether or not the operand variables of the branch instruction are the same. If YES, go to S6
Whether it is true or false is determined from the operand and the branch condition. When it is true, the branch instruction and the false instruction are deleted in S7, and when it is false, the branch instruction and the true instruction are deleted in S8.

【0018】具体的に説明すると、図3の(イ)におい
て、if文である のうちのif(10==8)のオペランド10、8が共
に定数であると判明したので(図2のS4のYES)、
オペランドと分岐条件からここでは偽と判定し(図2の
S6の偽)、分岐命令if(10==8)と、真のとき
の命令x=18を削除し、上記一連のif文を x=2; とする。これにより、図3の(イ)の最適化前の状態の
中間言語が、図3の(ロ)の最適化後の中間言語に最適
化されることとなる。
More specifically, it is an if statement in FIG. 3A. Since it has been found that the operands 10 and 8 of if (10 == 8) among them are constants (YES in S4 of FIG. 2),
From the operand and the branch condition, it is determined to be false here (false in S6 of FIG. 2), the branch instruction if (10 == 8) and the true instruction x = 18 are deleted, and the above series of if statements is converted to x. = 2; As a result, the intermediate language in the pre-optimization state of FIG. 3A is optimized to the post-optimization intermediate language of FIG. 3B.

【0019】以上のように、最適化前の状態の中間言語
の命令を1つ1つ読込み、分岐命令であった場合に、こ
の分岐命令のオペランドが全て定数であったとき、ある
いは全て同一の変数であったとき、分岐先が確定したの
で、分岐命令および分岐先以外の命令を削除してもよ
い。これにより、翻訳時に分岐先の確定した無意味の分
岐命令を削除して最適化を行うことが可能となる。
As described above, when the instructions of the intermediate language in the state before optimization are read one by one and the instructions are branch instructions, when the operands of the branch instructions are all constants or they are all the same. If it is a variable, the branch destination is determined, and thus the branch instruction and the instruction other than the branch destination may be deleted. As a result, it is possible to optimize by deleting meaningless branch instructions whose branch destinations are fixed during translation.

【0020】図3は、具体例説明図を示す。これは、c
言語のif文の最適化の場合のものである。図3の
(イ)は、ソースプログラムを変換した中間言語の最適
化前の状態を示す。左側は中間言語のif文を示し、右
側はそのときの処理のフローをイメージ図として表わし
たものを示す。
FIG. 3 shows a specific example explanatory view. This is c
This is a case of optimizing the if sentence of the language. FIG. 3A shows a state before optimization of the intermediate language obtained by converting the source program. The left side shows an intermediate language if sentence, and the right side shows an image diagram showing the flow of processing at that time.

【0021】ここで、if文であるif(10==8)
のオペランド10、8が共に定数であり、偽であるので
(図2のS1のYES、S2、S3のYES、S4のY
ES、S5の偽であるので)、図2のS8で分岐命令で
ある if(10==8) と、真のときの命令である x=18; と、if文に付随したelseなどを削除し、図3の
(ロ)に示すようにする。
Here, if (10 == 8) which is an if sentence
Since both operands 10 and 8 are constant and false (YES in S1 of FIG. 2, S2, YES in S3, Y in S4).
Since ES and S5 are false), the branch instruction if (10 == 8) in S8 of FIG. 2 and the true instruction x = 18; and the else etc. attached to the if statement are deleted. Then, as shown in FIG.

【0022】図3の(ロ)は、図3の(イ)の最適化前
の状態の中間言語を、最適化した後の中間言語を示す。
ここで、図3の(イ)の のif文および真の命令などを削除し、 x=2; に最適化している。
FIG. 3B shows an intermediate language after optimization of the intermediate language in the state before optimization shown in FIG.
Here, in (a) of FIG. Of the if statement and the true instruction are deleted and optimized to x = 2 ;.

【0023】図4は、本発明の他の具体例説明図を示
す。これは、c言語のswitch文の最適化の場合の
ものである。図4の(イ)は、ソースプログラムを変換
した中間言語の最適化前の状態を示す。左側は中間言語
のswitch文を示し、右側はそのときの処理のフロ
ーをイメージ図として表わしたものを示す。
FIG. 4 shows another embodiment of the present invention. This is the case of optimizing a switch statement in the c language. FIG. 4A shows a state before optimization of the intermediate language obtained by converting the source program. The left side shows an intermediate language switch statement, and the right side shows an image diagram showing the flow of processing at that time.

【0024】ここで、switch文であるswitc
h(c)のオペランドcが定数2であるので(図2のS
1のYES、S2、S3のYES、S4のYES、S5
の真であるので)、図2のS7で分岐命令である switch(c) と、偽の命令である case 1: x=a+b; break case 3: x=a/b; break default: x=a*b; break などを削除し、図4の(ロ)に示すようにする。
Here, switchc which is a switch statement
Since the operand c of h (c) is the constant 2, (S in FIG.
YES of 1, S2, YES of S3, YES of S4, S5
2), a branch instruction switch (c) in S7 of FIG. 2 and a false instruction case 1: x = a + b; break case 3: x = a / b; break default: x = a * B: Delete break etc., and make it as shown in (b) of FIG.

【0025】図4の(ロ)は、図4の(イ)の最適化前
の状態の中間言語を、最適化した後の中間言語を示す。
ここで、図4の(イ)の からswitch文および偽の命令などを削除し、 に最適化している。
FIG. 4B shows an intermediate language after optimization of the intermediate language in the state before optimization shown in FIG.
Here, in (a) of FIG. Delete the switch statement and fake command from Has been optimized for.

【0026】[0026]

【発明の効果】以上説明したように、本発明によれば、
翻訳時に、既に分岐命令の分岐先が確定する分岐命令の
判定文および分岐先でない方の命令を削除して最適化を
行う構成を採用しているため、翻訳性能を向上させ、翻
訳した後の機械語の実行時に分岐命令の実行を無くして
実行速度を向上させることができる。
As described above, according to the present invention,
At the time of translation, since the decision statement of the branch instruction in which the branch destination of the branch instruction has already been determined and the instruction that is not the branch destination are deleted for optimization, the translation performance is improved and The execution speed can be improved by eliminating the execution of the branch instruction when executing the machine language.

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

【図1】本発明の1実施例構成図である。FIG. 1 is a configuration diagram of an embodiment of the present invention.

【図2】本発明の動作説明フローチャートである。FIG. 2 is a flowchart for explaining the operation of the present invention.

【図3】本発明の具体例説明図である。FIG. 3 is a diagram illustrating a specific example of the present invention.

【図4】本発明の他の具体例説明図である。FIG. 4 is an explanatory diagram of another specific example of the present invention.

【図5】従来技術の説明図である。FIG. 5 is an explanatory diagram of a conventional technique.

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

1:コンパイラ 2:比較・分岐削除処理 3:メモリ 4:ソースプログラム(中間言語) 1: Compiler 2: Comparison / branch deletion processing 3: Memory 4: Source program (intermediate language)

Claims (1)

【特許請求の範囲】[Claims] 【請求項1】 翻訳時に分岐命令を削除して最適化する
分岐命令削除最適化方式において、 ソースプログラム(中間言語)の判定文のオペランドが
定数のときあるいは変数が同じときに、分岐命令を削除
する比較・分岐削除処理(2)を備え、 この比較・分岐削除処理(2)が翻訳時にソースプログ
ラム(中間言語)の判定文のオペランドが全て定数のと
きあるいはオペランドの変数が同じときに、当該判定文
および分岐先でない方の命令を削除し、最適化するよう
に構成したことを特徴とする分岐命令削除最適化方式。
1. In a branch instruction deletion optimizing method for optimizing a branch instruction by deleting it at the time of translation, the branch instruction is deleted when the operands of the judgment statement of the source program (intermediate language) are constants or variables are the same. The comparison / branch deletion processing (2) is provided, and when the comparison / branch deletion processing (2) has all the operands of the determination statement of the source program (intermediate language) are constants or the variables of the operands are the same at the time of translation, A branch instruction deletion optimizing method characterized in that a judgment statement and an instruction which is not a branch destination are deleted and optimized.
JP20022291A 1991-08-09 1991-08-09 Branch instruction deletion optimization method Pending JPH0546404A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP20022291A JPH0546404A (en) 1991-08-09 1991-08-09 Branch instruction deletion optimization method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP20022291A JPH0546404A (en) 1991-08-09 1991-08-09 Branch instruction deletion optimization method

Publications (1)

Publication Number Publication Date
JPH0546404A true JPH0546404A (en) 1993-02-26

Family

ID=16420841

Family Applications (1)

Application Number Title Priority Date Filing Date
JP20022291A Pending JPH0546404A (en) 1991-08-09 1991-08-09 Branch instruction deletion optimization method

Country Status (1)

Country Link
JP (1) JPH0546404A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0744397A (en) * 1993-07-30 1995-02-14 Nec Corp Program processing accelerating system
JPH07152583A (en) * 1993-11-30 1995-06-16 Nec Corp Executable file generator
US6440062B1 (en) 1999-11-10 2002-08-27 Asahi Kogaku Kogyo Kabushiki Kaisha Control wire driving mechanism for use in endoscope
WO2009098739A1 (en) * 2008-02-05 2009-08-13 Panasonic Corporation Program optimization device and program optimization method

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0744397A (en) * 1993-07-30 1995-02-14 Nec Corp Program processing accelerating system
JPH07152583A (en) * 1993-11-30 1995-06-16 Nec Corp Executable file generator
US6440062B1 (en) 1999-11-10 2002-08-27 Asahi Kogaku Kogyo Kabushiki Kaisha Control wire driving mechanism for use in endoscope
WO2009098739A1 (en) * 2008-02-05 2009-08-13 Panasonic Corporation Program optimization device and program optimization method
JPWO2009098739A1 (en) * 2008-02-05 2011-05-26 パナソニック株式会社 Program optimization apparatus and program optimization method

Similar Documents

Publication Publication Date Title
JPH0721033A (en) Device and method for processing language
JPH0546404A (en) Branch instruction deletion optimization method
JP2636665B2 (en) Execution information collection device
JP3430635B2 (en) Constant reference optimization processor
JP2001125793A (en) Compiler system, compile method and recording medium
JP3239830B2 (en) Transfer instruction optimization apparatus and method
JPH05113882A (en) Out-fitted man-machine interface realizing system by intermediate file
JP3004340B2 (en) Program optimization device
JPS5852752A (en) Section decision system
JPH0527986A (en) Compiler optimization method and optimization apparatus
JPS63318634A (en) Instruction prefetching system
JPH0644082A (en) System for generating optimized text
JPH0776926B2 (en) Loop control processing method
JPH05100720A (en) Managing device for program
JPH09330231A (en) Interpreter execution device
JP3327634B2 (en) Program conversion device and program conversion method
JPH04116756A (en) Dynamic link system for user definition command in application
JPH04323731A (en) Optimized text editing system
JPH1124939A (en) Program conversion method
JPS60220468A (en) Vector arithmetic control system
JPS6297031A (en) Matching system for bit number of mantissa part
KR19990069515A (en) Real time data processing device and method of PLC system
JPH05158706A (en) Optimization processing method of intermediate language
JPH05158507A (en) Instrumentation control device
JPH05151000A (en) Optimal internal call instruction generation processing method

Legal Events

Date Code Title Description
A02 Decision of refusal

Free format text: JAPANESE INTERMEDIATE CODE: A02

Effective date: 20001024