JPH0736706A - Optimized compiler - Google Patents

Optimized compiler

Info

Publication number
JPH0736706A
JPH0736706A JP5177883A JP17788393A JPH0736706A JP H0736706 A JPH0736706 A JP H0736706A JP 5177883 A JP5177883 A JP 5177883A JP 17788393 A JP17788393 A JP 17788393A JP H0736706 A JPH0736706 A JP H0736706A
Authority
JP
Japan
Prior art keywords
branch
condition
branch condition
block
branching
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
JP5177883A
Other languages
Japanese (ja)
Inventor
Yoshimasa Obayashi
善正 尾林
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 JP5177883A priority Critical patent/JPH0736706A/en
Publication of JPH0736706A publication Critical patent/JPH0736706A/en
Pending legal-status Critical Current

Links

Abstract

PURPOSE:To shorten calculation time for judging the branching conditions of a condition branching sentence provided with plural branches. CONSTITUTION:When it is judged that rebel branching conditions continue in a branching condition judging means 13, the length of the calculation time required for judging the authenticity of the branching conditions is evaluated in a branching condition evaluating means 14 and a block condition branching sentence for which the orders of the branching conditions and basic blocks executed when the branching conditions are judged as true are replaced in an order from the one for which the calculation time is shortest is outputted from a block condition branching sentence replacing means 15. By bringing the branching condition for which the calculation time required for judging the authenticity is short to front when the rebel branching conditions continue in the condition branching sentence provided with the plural branches, the calculation time can be shortened.

Description

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

【0001】[0001]

【産業上の利用分野】本発明は電子計算機用のコンパイ
ラに関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a compiler for electronic computers.

【0002】[0002]

【従来の技術】CやFORTRANなどの高級プログラ
ミング言語で書かれたプログラムを、電子計算機で実行
するには、一般に元のプログラムを機械語に翻訳するコ
ンパイラが使用されている。特に、近年、電子計算機の
性能を最大限に発揮させ、実行性能を向上させるための
様々な最適化を行なう、最適化コンパイラ(例えば、
A.V.Aho、R.Sethi、J.D.Ullma
n共著「Compilers−Principles,
Techniques,and Tools」や、J.
L.Hennessy,D.A.Patterson共
著「Computer Architecture:A
Quantitative Approach」)が
注目されている。
2. Description of the Related Art In order to execute a program written in a high level programming language such as C or FORTRAN on an electronic computer, a compiler that translates the original program into a machine language is generally used. Particularly, in recent years, an optimizing compiler (eg, an optimizing compiler) that performs various optimizations to maximize the performance of the electronic computer and improve the execution performance.
A. V. Aho, R.A. Sethi, J .; D. Ullma
n Co-authored “Compilers-Principles,
Techniques, and Tools, "J.
L. Hennessy, D.M. A. Patterson co-authored "Computer Architecture: A
"Quantitative Approach") is drawing attention.

【0003】以下図6及び図2及び図7を参照しなが
ら、従来の最適化コンパイラが元のプログラムを機械語
に翻訳する手順を説明する。
A procedure for a conventional optimizing compiler to translate an original program into a machine language will be described below with reference to FIGS. 6, 2 and 7.

【0004】図6は従来の最適化コンパイラの構成図で
ある。図6において、101はコンパイル対象コード入
力手段、102は字句解析手段、103は構文解析手
段、104は中間言語生成手段、105は最適化手段、
106は目的コード生成手段を示す。
FIG. 6 is a block diagram of a conventional optimizing compiler. In FIG. 6, 101 is a compiling target code input means, 102 is a lexical analysis means, 103 is a syntax analysis means, 104 is an intermediate language generation means, 105 is an optimization means,
Reference numeral 106 denotes a purpose code generating means.

【0005】図2はブロック条件分岐文の一つであるブ
ロックIF文を含むFORTRANプログラムを示す、
プログラム図である。
FIG. 2 shows a FORTRAN program including a block IF statement which is one of block conditional branch statements.
It is a program figure.

【0006】図2において、21は複数の条件分岐を含
むブロックIF文、22は浮動小数点数との比較演算を
必要とする分岐条件、23は分岐条件22が真である場
合に実行される基本ブロック、24は整数との比較演算
だけで済む分岐条件、25は分岐条件24が真である場
合に実行される基本ブロックを示す。
In FIG. 2, 21 is a block IF statement including a plurality of conditional branches, 22 is a branch condition requiring comparison operation with a floating point number, and 23 is a basic condition executed when the branch condition 22 is true. A block, 24 is a branch condition that requires only a comparison operation with an integer, and 25 is a basic block executed when the branch condition 24 is true.

【0007】図7は図2のプログラムを従来の最適化コ
ンパイラでコンパイルした結果得られる、SPARCア
ーキテクチャのマイクロプロセッサ(例えば、SPAR
CInternational,Inc.著「The
SPARC Architecture Manual
Version 8」)をターゲットとする目的コー
ドの機械語プログラムを示す、プログラム図である。
FIG. 7 shows a microprocessor of the SPARC architecture (for example, SPAR) obtained as a result of compiling the program of FIG. 2 with a conventional optimizing compiler.
C International, Inc. Written "The
SPARC Architecture Manual
It is a program figure which shows the machine language program of the object code which targets Version 8 ").

【0008】図7において、201はブロックIF文2
1に対応する機械語プログラム、202は分岐条件22
の判断を行なう浮動少数点数との比較演算、203は2
3に対応する基本ブロック、204は分岐条件24の判
断を行なう整数との比較演算、205は25に対応する
基本ブロックを示す。
In FIG. 7, 201 is a block IF statement 2
1 is a machine language program, 202 is a branch condition 22
The comparison operation with the floating-point number for determining
3 is a basic block corresponding to 3, 204 is a comparison operation with an integer for determining the branch condition 24, and 205 is a basic block corresponding to 25.

【0009】以上のように構成された従来の最適化コン
パイラについて、以下、コンパイルの手順とコンパイル
結果の機械語プログラムについて説明する。
With respect to the conventional optimizing compiler configured as described above, the procedure of compiling and the machine language program of the compiling result will be described below.

【0010】図2のFORTRANプログラムを図6の
従来の最適化コンパイラでコンパイルする場合、まず、
コンパイル対象コード入力手段101に入力され、コメ
ント行や継続行の処理等の前処理がされた後、字句解析
手段102に渡される。字句解析手段102は、前処理
後のコードをトークン列に変換し、それを受けた構文解
析手段103は、入力されたトークン列からプログラム
の構文を解析し、その結果を受けた中間言語生成手段1
04は、中間言語に変換したコードを出力する。中間言
語を入力された、最適化手段105は、共通部分式の除
去などのコード最適化を行なった中間言語を出力し、そ
れを受けた目的コード生成手段106は、目的コードの
機械語プログラムを出力する。その結果、図2のブロッ
クIF文21の分岐条件22は図7の機械語プログラム
部202に、分岐条件24は機械語プログラム部204
に、分岐条件22が真と判定された時に実行される基本
ブロック23は機械語プログラム部203に、分岐条件
24が真と判定された時に実行される基本ブロック25
は機械語プログラム部205に、コンパイルされる。
When the FORTRAN program of FIG. 2 is compiled by the conventional optimizing compiler of FIG. 6, first,
It is input to the compile target code input means 101, subjected to preprocessing such as processing of comment lines and continuation lines, and then passed to the lexical analysis means 102. The lexical analysis means 102 converts the pre-processed code into a token string, and the syntax analysis means 103 which received the code analyzes the syntax of the program from the input token string, and the intermediate language generation means which receives the result. 1
04 outputs the code converted into the intermediate language. When the intermediate language is input, the optimizing means 105 outputs the intermediate language that has been subjected to code optimization such as the removal of common subexpressions, and the object code generating means 106 that receives it outputs the machine language program of the object code. Output. As a result, the branch condition 22 of the block IF statement 21 of FIG. 2 is the machine language program unit 202 of FIG. 7, and the branch condition 24 is the machine language program unit 204.
Further, the basic block 23 executed when the branch condition 22 is determined to be true is instructed to the machine language program unit 203 by the basic block 25 executed when the branch condition 24 is determined to be true.
Is compiled into the machine language program unit 205.

【0011】[0011]

【発明が解決しようとする課題】しかし上記の従来の構
成では、真偽の判定に要する計算時間の長い分岐条件を
複数の分岐条件のうちの前部に持つブロック条件分岐文
をコンパイルして実行した際に、その分岐条件の判定結
果の値が偽であるにもかかわらずこの分岐条件の判定計
算を行なう回数が多くなり、その結果、実行性能が低下
してしまうという課題を有していた。
However, in the above-mentioned conventional configuration, a block conditional branch statement having a branch condition having a long calculation time required for true / false judgment at the front of a plurality of branch conditions is compiled and executed. However, even if the value of the branch condition judgment result is false, the number of times the branch condition judgment calculation is performed is increased, and as a result, the execution performance is deteriorated. .

【0012】図7を用いて具体的にいえば、分岐条件2
04に比べて計算時間が多くかかる分岐条件202の計
算がその真偽に関係なく必ず実行されてしまう。
Specifically, referring to FIG. 7, branch condition 2
The calculation of the branch condition 202, which requires a longer calculation time than 04, is always executed regardless of the truth.

【0013】本発明は上記課題を解決するもので、複数
の分岐条件の内、排反な分岐条件が連続してある場合
に、真偽の判定に要する計算時間の長い分岐条件の判定
計算を行なう回数を減らして計算時間を短縮し、プログ
ラムの実行性能を向上させる最適化コンパイラを提供す
ることを目的とする。
The present invention solves the above-described problems, and when a plurality of branch conditions are consecutive incompatible branch conditions, a branch condition determination calculation requiring a long calculation time for true / false determination is performed. It is an object of the present invention to provide an optimizing compiler that reduces the number of executions to shorten the calculation time and improves the program execution performance.

【0014】[0014]

【課題を解決するための手段】上記課題を解決するた
め、本発明の第1の最適化コンパイラは、ブロック条件
分岐文を検出するブロック条件分岐文検出手段と、検出
したブロック条件分岐文から分岐条件を検出する分岐条
件検出手段と、検出したブロック条件分岐文から各々の
分岐条件が成立した際に実行される基本ブロックを検出
する基本ブロック検出手段と、検出した分岐条件が排反
事象であるかを判定する分岐条件判定手段と、検出した
分岐条件の真偽の判定に要する計算時間を評価する分岐
条件評価手段と、基本ブロック検出手段の出力と分岐条
件判定手段の出力と分岐条件評価手段の出力から分岐条
件とその分岐条件が成立した際に実行される基本ブロッ
クの組の順序を入れ換えるブロック条件分岐文順序交換
手段とを備えたものである。
In order to solve the above problems, a first optimizing compiler of the present invention comprises a block conditional branch statement detecting means for detecting a block conditional branch statement, and a branch from the detected block conditional branch statement. A branch condition detecting means for detecting a condition, a basic block detecting means for detecting a basic block executed when each branch condition is satisfied from the detected block condition branch statement, and the detected branch condition is an exhaustion event. Branch condition determining means, a branch condition evaluating means for evaluating a calculation time required for determining whether the detected branch condition is true or false, an output of the basic block detecting means, an output of the branch condition determining means, and a branch condition evaluating means. A branch condition and a block condition branch statement order exchanging means for changing the order of the set of basic blocks executed when the branch condition is satisfied A.

【0015】さらに、本発明の第2の最適化コンパイラ
は、第1の最適化コンパイラにおいて、さらに実行可能
目的コードの実行時にブロック条件分岐文の全実行回数
とそのうち各分岐条件が真と判定された回数を測定し、
全実行回数に対する各分岐条件が真と判定された回数の
比を出力する分岐条件真比率測定手段を有し、ブロック
条件分岐文順序交換手段は基本ブロック検出手段の出力
と分岐条件判定手段の出力と分岐条件評価手段の出力と
分岐条件真比率測定手段の出力から分岐条件とその分岐
条件が成立した際に実行される基本ブロックの組の順序
を入れ換えるものである。
Further, the second optimizing compiler of the present invention is the first optimizing compiler, wherein when the executable object code is executed, it is determined that the total number of executions of the block conditional branch statement and each branch condition are true. Measured the number of times
It has branch condition true ratio measuring means for outputting the ratio of the number of times each branch condition is judged to be true to the total number of executions, and the block condition branch statement order exchange means outputs the basic block detecting means and the branch condition judging means. The order of the branch condition and the set of basic blocks executed when the branch condition is satisfied is exchanged from the output of the branch condition evaluating means and the output of the branch condition true ratio measuring means.

【0016】[0016]

【作用】本発明の第1の構成により、プログラム中にブ
ロック条件分岐文が含まれている場合に、これをブロッ
ク条件分岐文検出手段が検出し、その出力から、分岐条
件検出手段が分岐条件を検出し、基本ブロック検出手段
が各々の分岐条件が成立した際に実行される基本ブロッ
クを検出する。さらに、分岐条件検出手段の出力から、
分岐条件判定手段が連続した複数の分岐条件が排反であ
るかを判定し、分岐条件評価手段が分岐条件の真偽の判
定に要する計算時間を評価する。分岐条件判定手段が連
続した複数の排反な分岐条件が存在することを検出する
と、それをうけたブロック条件分岐文順序交換手段が、
分岐条件評価手段が評価したそれらの分岐条件の計算時
間を比較し、それの小さいものから順にそれらの分岐条
件と基本ブロックを並べ換えたコードを出力する。
According to the first configuration of the present invention, when the program includes a block conditional branch statement, the block conditional branch statement detecting means detects this and the branch condition detecting means detects the branch condition from its output. And the basic block detecting means detects a basic block executed when each branch condition is satisfied. Furthermore, from the output of the branch condition detection means,
The branch condition judging means judges whether or not a plurality of continuous branch conditions are rejected, and the branch condition evaluating means evaluates the calculation time required for judging the truth of the branch condition. When the branch condition determining means detects that there are a plurality of consecutive branching branch conditions, the block condition branch statement order exchanging means receiving it detects that
The branching condition evaluation means compares the calculation times of those branching conditions, and outputs the code in which those branching conditions and basic blocks are rearranged in order from the smallest.

【0017】これにより、排反な分岐条件が連続してお
り、それらの分岐条件がどのような比率で真と判定され
るかが前もってわからない場合に、真偽の判定に要する
計算時間の長い分岐条件とその分岐条件が成立した際に
実行される基本ブロックを、真偽の判定に要する計算時
間の短い分岐条件とその分岐条件が成立した際に実行さ
れる基本ブロックと順序を入れ換えて、コードの後部に
回すことができ、それらの分岐条件が真と判定される比
率を全て等しいと仮定した場合の、分岐条件の判定計算
を行なう回数の期待値を減らして計算時間の期待値を短
縮することができる。
Thus, if the branching conditions that are repulsive are continuous and the ratio of those branching conditions is determined to be true in advance, a branch that requires a long calculation time to determine the trueness or falseness is determined. The condition and the basic block that is executed when the branch condition are satisfied are changed in order by changing the order of the branch condition that requires a short calculation time for true / false judgment and the basic block that is executed when the branch condition is satisfied. The expected value of the number of times the branch condition is calculated is reduced by shortening the expected value of the calculation time, assuming that the ratios of those branch conditions that are judged to be true are all equal. be able to.

【0018】本発明の第2の構成により、プログラム中
にブロック条件分岐文が含まれている場合に、これをブ
ロック条件分岐文検出手段が検出し、その出力から、分
岐条件検出手段が分岐条件を検出し、基本ブロック検出
手段が各々の分岐条件が成立した際に実行される基本ブ
ロックを検出する。さらに、分岐条件検出手段の出力か
ら、分岐条件判定手段が連続した複数の分岐条件が排反
であるかを判定し、分岐条件評価手段が分岐条件の真偽
の判定に要する計算時間を評価する。分岐条件判定手段
が連続した複数の排反な分岐条件が存在することを検出
すると、それをうけたブロック条件分岐文順序交換手段
が、分岐条件評価手段が評価したそれらの分岐条件の計
算時間と分岐条件真比率測定手段で測定されたその分岐
条件が真と判定された回数の比の逆数との積の値を比較
し、それの小さいものから順にそれらの分岐条件と基本
ブロックを並べ換えたコードを出力する。
According to the second configuration of the present invention, when the program includes a block conditional branch statement, the block conditional branch statement detecting means detects this and the branch condition detecting means detects the branch condition from its output. And the basic block detecting means detects a basic block executed when each branch condition is satisfied. Further, from the output of the branch condition detecting means, the branch condition judging means judges whether or not a plurality of continuous branch conditions are rejected, and the branch condition evaluating means evaluates the calculation time required for judging whether the branch condition is true or false. . When the branch condition judging means detects that there are a plurality of consecutive branching branch conditions, the block condition branch statement order exchange means that receives it detects the calculation time of those branch conditions evaluated by the branch condition evaluating means. Branch condition A code that compares the product value of the branch condition true ratio measuring means and the reciprocal of the ratio of the number of times that the branch condition is determined to be true, and rearranges those branch conditions and basic blocks in ascending order. Is output.

【0019】これにより、排反な分岐条件が連続してい
る場合に、コンパイル結果の目的コードを実行した際の
各々の分岐条件の真偽の判定に要する計算時間とその分
岐条件が真と判定された回数の逆数との積が大きい分岐
条件とその分岐条件が成立した際に実行される基本ブロ
ックを、真偽の判定に要する計算時間とその分岐条件が
真と判定された回数の逆数との積が小さい分岐条件とそ
の分岐条件が成立した際に実行される基本ブロックと順
序を入れ換えて、コードの後部に回すことができ、その
分岐条件の判定計算の時間を減らしてそのブロック条件
分岐文の実行時間を最短にすることができる。
As a result, when the repulsive branch conditions are continuous, the calculation time required for determining the true or false of each branch condition when executing the object code of the compilation result and the branch condition are determined to be true. The branching condition that has a large product of the reciprocal of the number of times and the basic block that is executed when the branching condition is satisfied, and the reciprocal of the number of times that the branching condition is determined to be true The branch condition with a small product of and the basic block executed when the branch condition is satisfied can be exchanged with the order and passed to the rear part of the code, and the time required for the decision calculation of the branch condition can be reduced and the block conditional branch Statement execution time can be minimized.

【0020】[0020]

【実施例】以下本発明の実施例について、図面を参照し
ながら説明する。
Embodiments of the present invention will be described below with reference to the drawings.

【0021】(実施例1)図1は本発明の第1の実施例
の最適化コンパイラの構成図である。
(Embodiment 1) FIG. 1 is a block diagram of an optimizing compiler according to a first embodiment of the present invention.

【0022】図1において、1はコンパイル対象コード
入力手段、10はブロック条件分岐文を検出するブロッ
ク条件分岐文検出手段、11は分岐条件検出手段、12
は基本ブロック検出手段、13は分岐条件が排反事象で
あるかを判定する分岐条件判定手段、14は分岐条件の
真偽の判定に要する計算時間を評価する分岐条件評価手
段、15は分岐条件とその分岐条件が成立した際に実行
される基本ブロックを並べ変えたコードを出力するブロ
ック条件分岐文順序交換手段、2は字句解析手段、3は
構文解析手段、4は中間言語生成手段、5は最適化手
段、6は目的コード生成手段を示す。
In FIG. 1, 1 is a code input means for compiling, 10 is a block conditional branch statement detecting means for detecting a block conditional branch statement, 11 is a branch condition detecting means, 12
Is a basic block detecting means, 13 is a branching condition judging means for judging whether the branching condition is an exhaustion event, 14 is a branching condition evaluating means for evaluating the calculation time required for judging whether the branching condition is true or false, and 15 is a branching condition. And block condition branch statement order exchange means for outputting a code that rearranges basic blocks executed when the branch condition is satisfied, 2 lexical analysis means, 3 syntactic analysis means, 4 intermediate language generation means, 5 Is an optimization means, and 6 is an object code generation means.

【0023】図2はブロック条件分岐文の一つであるブ
ロックIF文を含むFORTRANプログラムを示す、
プログラム図である。図2において、21は複数の条件
分岐を含むブロックIF文、22は浮動小数点数との比
較演算を必要とする分岐条件、23は分岐条件22が真
である場合に実行される基本ブロック、24は整数との
比較演算だけで済む分岐条件、25は分岐条件24が真
である場合に実行される基本ブロックを示す。
FIG. 2 shows a FORTRAN program including a block IF statement which is one of block conditional branch statements.
It is a program figure. In FIG. 2, 21 is a block IF statement including a plurality of conditional branches, 22 is a branch condition that requires a comparison operation with a floating point number, 23 is a basic block executed when the branch condition 22 is true, 24 Indicates a branch condition that requires only a comparison operation with an integer, and 25 indicates a basic block executed when the branch condition 24 is true.

【0024】図3は本実施例の最適化コンパイラのブロ
ック条件分岐文順序交換手段15で順序が入れ換えられ
たブロックIF文を示す、プログラム図である。
FIG. 3 is a program diagram showing a block IF statement whose order has been changed by the block conditional branch statement order changing means 15 of the optimizing compiler of this embodiment.

【0025】図3において、31は21から得られたブ
ロックIF文、32は24が順序が入れ換えられて先に
なった分岐条件、33は分岐条件32が真である場合に
実行される基本ブロック、34は22が順序が入れ換え
られて後になった浮動小数点数との比較演算を必要とす
る分岐条件、35は分岐条件34が真である場合に実行
される基本ブロックを示す。
In FIG. 3, 31 is a block IF statement obtained from 21, 32 is a branch condition in which the order has been changed and the branch condition is first, and 33 is a basic block executed when the branch condition 32 is true. , 34 is a branch condition that requires a comparison operation with a floating-point number 22 that has been rearranged in order, and 35 is a basic block that is executed when the branch condition 34 is true.

【0026】図4は図3のプログラムをコンパイルした
結果得られる目的コードの機械語プログラムを示す、プ
ログラム図である。
FIG. 4 is a program diagram showing a machine language program of the object code obtained as a result of compiling the program of FIG.

【0027】図4において、41はブロックIF文31
に対応する機械語プログラム、42は分岐条件32の判
断を行なう整数との比較演算、43は33に対応する基
本ブロック、44は分岐条件34の判断を行なう浮動小
数点数との比較演算、45は35に対応する基本ブロッ
クを示す。
In FIG. 4, 41 is a block IF statement 31.
A machine language program corresponding to, 42 is a comparison operation with an integer for judging the branch condition 32, 43 is a basic block corresponding to 33, 44 is a comparison operation with a floating point number for judging the branch condition 34, and 45 is a 35 shows a basic block corresponding to 35.

【0028】以上のように構成された本実施例の最適化
コンパイラについて、以下図1〜図4を用いてその動作
を説明する。
The operation of the optimizing compiler of the present embodiment constructed as above will be described below with reference to FIGS.

【0029】図2のFORTRANプログラムを本実施
例の最適化コンパイラでコンパイルする場合、まず、コ
ンパイル対象コード入力手段1に入力され、コメント行
や継続行の処理等の前処理がされた後、ブロック条件分
岐文検出手段10に渡される。検出されたブロックIF
文から分岐条件検出手段11が各分岐条件を検出し、基
本ブロック検出手段12が各分岐条件が真と判断された
際に実行される基本ブロックを検出する。検出された分
岐条件は、分岐条件判定手段13で排反な分岐条件が連
続しているか判定される。
When the FORTRAN program shown in FIG. 2 is compiled by the optimizing compiler of this embodiment, first, it is input to the compiling target code input means 1 and subjected to preprocessing such as processing of comment lines and continuation lines, and then the block. It is passed to the conditional branch statement detecting means 10. Block IF detected
The branch condition detecting means 11 detects each branch condition from the statement, and the basic block detecting means 12 detects the basic block executed when each branch condition is judged to be true. The detected branching condition is judged by the branching condition judging means 13 to determine whether or not continuous branching conditions are continuous.

【0030】排反な分岐条件が連続している場合には、
分岐条件評価手段14の出力として得られる、分岐条件
の真偽の判定に要する計算時間の小さいものから順に、
分岐条件とそれが真と判断された際に実行される基本ブ
ロックの順序を入れ換えたブロックIF文31をブロッ
ク条件分岐文順序交換手段15から出力する。
When the disjoint branch conditions are continuous,
From the output of the branch condition evaluation means 14 in order of decreasing calculation time required for determining the true or false of the branch condition,
The block condition branch statement order exchange unit 15 outputs the block IF statement 31 in which the order of the branch condition and the basic block executed when it is determined to be true is exchanged.

【0031】ブロック条件分岐文順序交換手段15の出
力は、字句解析手段2に渡される。字句解析手段2は、
前処理後のコードをトークンの列に変換し、それを受け
た構文解析手段3は、入力されたトークン列からプログ
ラムの構文を解析し、その結果を受けた中間言語生成手
段4は、中間言語に変換したコードを出力する。中間言
語を入力された、最適化手段5は、共通部分式の除去な
どのコード最適化を行なった中間言語を出力し、それを
受けた目的コード生成手段6は、目的コードの機械語プ
ログラムを出力する。
The output of the block conditional branch statement order exchange means 15 is passed to the lexical analysis means 2. The lexical analysis means 2
The preprocessed code is converted into a sequence of tokens, and the parsing unit 3 that receives it analyzes the syntax of the program from the inputted token sequence, and the intermediate language generation unit 4 that receives the result analyzes the intermediate language. Output the code converted to. When the intermediate language is input, the optimizing means 5 outputs the intermediate language which has been subjected to code optimization such as the removal of common subexpressions, and the object code generating means 6 receiving it outputs the machine language program of the object code. Output.

【0032】その結果、図3のブロックIF文31の分
岐条件32は図4の機械語プログラム部42に、分岐条
件34は機械語プログラム部44に、分岐条件32が真
と判定された時に実行される基本ブロック33は機械語
プログラム部43に、分岐条件34が真と判定された時
に実行される基本ブロック35は機械語プログラム部4
5に、コンパイルされる。
As a result, the branch condition 32 of the block IF statement 31 of FIG. 3 is executed by the machine language program unit 42 of FIG. 4, the branch condition 34 is executed by the machine language program unit 44, and when the branch condition 32 is determined to be true. The basic block 33 is executed by the machine language program unit 43, and the basic block 35 executed when the branch condition 34 is determined to be true is executed by the machine language program unit 4.
Compile to 5.

【0033】以上のように本実施例によれば、プログラ
ムが排反な分岐条件が連続しそれらの分岐条件がどのよ
うな比率で真と判定されるかが前もってわからない条件
分岐文を含む場合に、真偽の判定に要する計算時間の長
い分岐条件とその分岐条件が成立した際に実行される基
本ブロックを、真偽の判定に要する計算時間の短い分岐
条件とその分岐条件が成立した際に実行される基本ブロ
ックと順序を入れ換えて、コードの後部に回すことがで
き、それらの分岐条件が真と判定される比率を全て等し
いと仮定した場合の、分岐条件の判定計算を行なう回数
の期待値を減らして計算時間の期待値を短縮することが
できる。
As described above, according to the present embodiment, when the program includes the conditional branch statements in which the contradictory branch conditions are consecutive and the ratio of the branch conditions is not known in advance. , A branch condition that requires a long calculation time to determine whether it is true and a basic block that is executed when that branch condition is satisfied, and a branch condition that requires a short calculation time to determine whether it is true and a branch condition that is satisfied Expect the number of times to perform branch condition decision calculations, assuming that the basic blocks to be executed can be exchanged in the order and passed to the rear part of the code, and if the ratio of those branch conditions to be judged as true is all equal. The expected value of the calculation time can be shortened by reducing the value.

【0034】(実施例2)図5は本発明の第2の実施例
の最適化コンパイラの構成図である。
(Second Embodiment) FIG. 5 is a block diagram of an optimizing compiler according to a second embodiment of the present invention.

【0035】図5において、1はコンパイル対象コード
入力手段、10はブロック条件分岐文を検出するブロッ
ク条件分岐文検出手段、11は分岐条件検出手段、12
は基本ブロック検出手段、13は分岐条件が排反事象で
あるかを判定する分岐条件判定手段、14は分岐条件の
真偽の判定に要する計算時間を評価する分岐条件評価手
段、15は分岐条件とその分岐条件が成立した際に実行
される基本ブロックを並べ変えたコードを出力するブロ
ック条件分岐文順序交換手段、16は分岐条件真比率測
定手段、2は字句解析手段、3は構文解析手段、4は中
間言語生成手段、5は最適化手段、6は目的コード生成
手段を示す。
In FIG. 5, reference numeral 1 is a compile target code input means, 10 is a block conditional branch statement detecting means for detecting a block conditional branch statement, 11 is a branch condition detecting means, 12
Is a basic block detecting means, 13 is a branching condition judging means for judging whether the branching condition is an exhaustion event, 14 is a branching condition evaluating means for evaluating the calculation time required for judging whether the branching condition is true or false, and 15 is a branching condition. And block condition branch statement order exchange means for outputting a code obtained by rearranging basic blocks executed when the branch condition is satisfied, 16 branch condition true ratio measuring means, 2 lexical analysis means, 3 syntactic analysis means Reference numeral 4 is an intermediate language generation means, 5 is an optimization means, and 6 is a target code generation means.

【0036】以上のように構成された本実施例の最適化
コンパイラについて、以下図2〜図5を用いてその動作
を説明する。
The operation of the optimizing compiler of this embodiment constructed as described above will be described below with reference to FIGS.

【0037】図2のFORTRANプログラムを本実施
例の最適化コンパイラでコンパイルする場合、まず、従
来の最適化コンパイラあるいは、第1の実施例の最適化
コンパイラで得られた実行可能目的コードを実行し、ブ
ロック条件分岐文の全実行回数と各分岐条件が真と判定
された回数が、分岐条件真比率測定手段16で測定さ
れ、そのブロック条件分岐文の全実行回数に対する各分
岐条件が真と判定された回数の比が出力される。
When the FORTRAN program of FIG. 2 is compiled by the optimizing compiler of this embodiment, first, the executable object code obtained by the conventional optimizing compiler or the optimizing compiler of the first embodiment is executed. The total number of executions of the block conditional branch statement and the number of times each branch condition is determined to be true are measured by the branch condition true ratio measuring means 16, and each branch condition is determined to be true to the total number of executions of the block conditional branch statement. The ratio of the number of times the output is performed is output.

【0038】次に、元のFORTRANコードがコンパ
イル対象コード入力手段1に入力され、コメント行や継
続行の処理等の前処理がされた後、ブロック条件分岐文
検出手段10に渡される。検出されたブロックIF文か
ら分岐条件検出手段11が各分岐条件を検出し、基本ブ
ロック検出手段12が各分岐条件が真と判断された際に
実行される基本ブロックを検出する。検出された分岐条
件は、分岐条件判定手段13で排反な分岐条件が連続し
ているか判定される。
Next, the original FORTRAN code is input to the compile target code input means 1, subjected to preprocessing such as processing of comment lines and continuation lines, and then passed to the block conditional branch statement detection means 10. From the detected block IF statement, the branch condition detecting means 11 detects each branch condition, and the basic block detecting means 12 detects the basic block executed when each branch condition is judged to be true. The detected branching condition is judged by the branching condition judging means 13 to determine whether or not continuous branching conditions are continuous.

【0039】排反な分岐条件が連続している場合には、
分岐条件評価手段14の出力として得られる、分岐条件
の真偽の判定に要する計算時間と、分岐条件真比率測定
手段16から得られるそのブロック条件分岐文の全実行
回数に対する各分岐条件が真と判定された回数の比の逆
数との積の小さいものから順に、分岐条件とそれが真と
判断された際に実行される基本ブロックの順序を入れ換
えたブロックIF文31をブロック条件分岐文順序交換
手段15から出力する。
When the disjoint branch conditions are continuous,
The calculation time required for determining the truth of the branch condition, which is obtained as the output of the branch condition evaluation means 14, and each branch condition for the total number of executions of the block condition branch statement, which is obtained from the branch condition true ratio measuring means 16, is true. A block condition branch statement order exchange is performed on the block IF statement 31 in which the branch condition and the order of the basic blocks executed when it is determined to be true are switched in order from the smallest product of the determined reciprocal of the ratio. Output from the means 15.

【0040】ブロック条件分岐文順序交換手段15の出
力は、字句解析手段2に渡される。字句解析手段2は、
前処理後のコードをトークンの列に変換し、それを受け
た構文解析手段3は、入力されたトークン列からプログ
ラムの構文を解析し、その結果を受けた中間言語生成手
段5は、中間言語に変換したコードを出力する。中間言
語を入力された、最適化手段5は、共通部分式の除去な
どのコード最適化を行なった中間言語を出力し、それを
受けた目的コード生成手段6は、目的コードの機械語プ
ログラムを出力する。
The output of the block conditional branch statement order exchange means 15 is passed to the lexical analysis means 2. The lexical analysis means 2
The preprocessed code is converted into a token string, and the syntax analysis unit 3 that receives the code analyzes the syntax of the program from the input token string, and the intermediate language generation unit 5 that receives the result analyzes the intermediate language. Output the code converted to. When the intermediate language is input, the optimizing means 5 outputs the intermediate language which has been subjected to code optimization such as the removal of common subexpressions, and the object code generating means 6 receiving it outputs the machine language program of the object code. Output.

【0041】その結果、図3のブロックIF文31の分
岐条件32は図4の機械語プログラム部42に、分岐条
件34は機械語プログラム部44に、分岐条件32が真
と判定された時に実行される基本ブロック33は機械語
プログラム部43に、分岐条件34が真と判定された時
に実行される基本ブロック35は機械語プログラム部4
5に、コンパイルされる。
As a result, the branch condition 32 of the block IF statement 31 of FIG. 3 is executed by the machine language program unit 42 of FIG. 4, the branch condition 34 is executed by the machine language program unit 44, and when the branch condition 32 is determined to be true. The basic block 33 is executed by the machine language program unit 43, and the basic block 35 executed when the branch condition 34 is determined to be true is executed by the machine language program unit 4.
Compile to 5.

【0042】以上のように本実施例によれば、プログラ
ムが排反な分岐条件が連続している条件分岐文を含む場
合に、それらの分岐条件がどのような比率で真と判定さ
れるかを測定し、真偽の判定に要する計算時間とその真
比率の逆数の値が大きい分岐条件とその分岐条件が成立
した際に実行される基本ブロックを、真偽の判定に要す
る計算時間とその真比率が小さい分岐条件とその分岐条
件が成立した際に実行される基本ブロックと順序を入れ
換えて、コードの後部に回すことができ、元のプログラ
ムをそのまま実行した場合よりも分岐条件の判定計算の
時間を減らして計算時間を短縮することができる。
As described above, according to the present embodiment, when the program includes conditional branch statements in which contradictory branch conditions are continuous, at what ratio these branch conditions are judged to be true. , The calculation time required for true / false determination and the reciprocal value of its true ratio are large, and the basic block executed when the branch condition is satisfied, the calculation time required for true / false determination and its The branch condition with a small true ratio and the basic block that is executed when the branch condition is satisfied can be swapped in the order and passed to the back of the code, and the branch condition judgment calculation compared to when the original program is executed as it is. The calculation time can be shortened by reducing the time.

【0043】[0043]

【発明の効果】以上のように、第1の本発明は、排反な
分岐条件が連続している場合に分岐条件の真偽の判定に
要する計算時間が小さいものから順に並べ変えたコード
を出力し、それらの分岐条件が真と判定される比率を全
て等しいと仮定した場合の分岐条件の判定計算を行なう
回数の期待値を減らして計算時間の期待値を短縮するこ
とができる。
As described above, according to the first aspect of the present invention, codes that are rearranged in order from the one having the smallest calculation time required for determining the trueness of the branching condition when the repulsive branching conditions are continuous. The expected value of the calculation time can be shortened by reducing the expected value of the number of times the branch condition is output and the branch condition determination calculation is performed assuming that the ratios at which those branch conditions are determined to be true are all equal.

【0044】また、第2の本発明は、排反な分岐条件が
連続している場合に分岐条件の真偽の判定に要する計算
時間と分岐条件が真と判定される比の逆数との積の値が
小さいものから順に並べ変えたコードを出力し、分岐条
件の判定計算に要する時間を減らしてそのブロック条件
分岐文の実行時間を最短にすることができる。
In the second aspect of the present invention, the product of the calculation time required to determine the truth of the branch condition and the reciprocal of the ratio at which the branch condition is determined to be true when the repulsive branch conditions are continuous. It is possible to reduce the time required for branch condition judgment calculation and minimize the execution time of the block conditional branch statement by outputting the code rearranged in order from the smallest value of.

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

【図1】本発明の第1の実施例における最適化コンパイ
ラの構成図
FIG. 1 is a configuration diagram of an optimizing compiler according to a first embodiment of the present invention.

【図2】同実施例の動作説明のためのFORTRANの
ソースプログラム図
FIG. 2 is a source program diagram of FORTRAN for explaining the operation of the embodiment.

【図3】同実施例の動作説明のためのブロックIF文入
れ換え処理後のFORTRANのプログラム図
FIG. 3 is a program diagram of FORTRAN after a block IF sentence replacement process for explaining the operation of the embodiment.

【図4】同実施例の動作説明のための機械語の目的プロ
グラム図
FIG. 4 is an object program diagram of a machine language for explaining the operation of the embodiment.

【図5】本発明の第2の実施例における最適化コンパイ
ラの構成図
FIG. 5 is a configuration diagram of an optimizing compiler according to a second embodiment of the present invention.

【図6】従来例の最適化コンパイラの構成図FIG. 6 is a configuration diagram of a conventional optimizing compiler.

【図7】従来例の動作説明のための機械語の目的プログ
ラム図
FIG. 7 is an object program diagram of a machine language for explaining the operation of the conventional example.

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

10 ブロック条件分岐文検出手段 11 分岐条件検出手段 12 基本ブロック検出手段 13 分岐条件判定手段 14 分岐条件評価手段 15 ブロック条件分岐文順序交換手段 16 分岐条件真比率測定手段 10 block condition branch statement detecting means 11 branch condition detecting means 12 basic block detecting means 13 branch condition determining means 14 branch condition evaluating means 15 block condition branch statement order exchanging means 16 branch condition true ratio measuring means

Claims (2)

【特許請求の範囲】[Claims] 【請求項1】コンパイル対象コード入力手段と、 前記コンパイル対象コード入力手段の出力から、複数の
分岐を持つ条件分岐文であるブロック条件分岐文を検出
する、ブロック条件分岐文検出手段と、 前記ブロック条件分岐文検出手段の出力から、分岐条件
を検出する、分岐条件検出手段と、 前記ブロック条件分岐文検出手段の出力から、各々の分
岐条件が成立した際に実行される文の集合である基本ブ
ロックを検出する、基本ブロック検出手段と、 前記分岐条件検出手段の出力から、それらの分岐条件が
排反事象であるかを判定する、分岐条件判定手段と、 前記分岐条件検出手段の出力から、それらの分岐条件の
真偽の判定に要する計算時間を評価する、分岐条件評価
手段と、 前記基本ブロック検出手段と前記分岐条件判定手段と前
記分岐条件評価手段の出力から、排反な分岐条件が連続
している場合に、それらの分岐条件とその分岐条件が成
立した際に実行される基本ブロックを、分岐条件の真偽
の判定に要する計算時間が小さいものから順に並べ変え
たコードを出力する、ブロック条件分岐文順序交換手段
を備えることを特徴とする最適化コンパイラ。
1. A compile target code input means, a block conditional branch statement detecting means for detecting a block conditional branch statement which is a conditional branch statement having a plurality of branches from an output of the compile target code input means, and the block. A branch condition detecting means for detecting a branch condition from the output of the conditional branch statement detecting means, and a basic set of statements executed when each branch condition is satisfied from the output of the block conditional branch statement detecting means. Detecting blocks, basic block detection means, from the output of the branch condition detection means, to determine whether those branch conditions are discharge events, branch condition determination means, from the output of the branch condition detection means, A branch condition evaluation means for evaluating the calculation time required for determining the truth of those branch conditions, the basic block detection means, the branch condition determination means, and the From the output of the branch condition evaluation means, when there are continuous branching conditions, those branching conditions and the basic block executed when the branching conditions are satisfied are required to determine the trueness or falseness of the branching conditions. An optimizing compiler comprising block conditional branch statement order exchanging means for outputting codes rearranged in order of decreasing calculation time.
【請求項2】さらに実行可能目的コードの実行時にブロ
ック条件分岐文の全実行回数とそのうちの各分岐条件が
真と判定された回数を測定し、全実行回数に対する各分
岐条件が真と判定された回数の比を出力する、分岐条件
真比率測定手段を有し、前記ブロック条件分岐文順序交
換手段は前記基本ブロック検出手段と前記分岐条件判定
手段と前記分岐条件評価手段と前記分岐条件真比率測定
手段の出力から、排反な分岐条件が連続している場合
に、それらの分岐条件とその分岐条件が成立した際に実
行される基本ブロックを、分岐条件の真偽の判定に要す
る計算時間と分岐条件が真と判定される比の逆数との積
の値が小さいものから順に並べ変えたコードを出力する
ことを特徴とする請求項1記載の最適化コンパイラ。
2. The total number of executions of a block conditional branch statement and the number of times each branch condition is determined to be true during execution of the executable object code are measured, and each branch condition for all executions is determined to be true. The branch condition true ratio measuring means for outputting the ratio of the number of times of the branching, and the block condition branch statement order exchange means includes the basic block detecting means, the branch condition determining means, the branch condition evaluating means, and the branch condition true ratio. From the output of the measurement means, when the branching conditions are continuous, the branching conditions and the basic blocks executed when the branching conditions are satisfied are calculated as the calculation time required to judge the trueness or falseness of the branching conditions. 3. The optimizing compiler according to claim 1, wherein the code is rearranged in order from a product having a smaller value of a product of the branching condition and the reciprocal of the ratio determined to be true.
JP5177883A 1993-07-19 1993-07-19 Optimized compiler Pending JPH0736706A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP5177883A JPH0736706A (en) 1993-07-19 1993-07-19 Optimized compiler

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP5177883A JPH0736706A (en) 1993-07-19 1993-07-19 Optimized compiler

Publications (1)

Publication Number Publication Date
JPH0736706A true JPH0736706A (en) 1995-02-07

Family

ID=16038728

Family Applications (1)

Application Number Title Priority Date Filing Date
JP5177883A Pending JPH0736706A (en) 1993-07-19 1993-07-19 Optimized compiler

Country Status (1)

Country Link
JP (1) JPH0736706A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH07160499A (en) * 1993-12-09 1995-06-23 Nec Corp Optimization system for multidirectional branch instruction
KR20150095648A (en) * 2012-12-10 2015-08-21 아브 이니티오 테크놀로지 엘엘시 System for transform generation
JP2017142718A (en) * 2016-02-12 2017-08-17 株式会社デンソー Electronic control device and code generation program
JP2021521538A (en) * 2018-04-13 2021-08-26 マイクロソフト テクノロジー ライセンシング,エルエルシー Sorting of compound conditions for high-speed short circuit

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH07160499A (en) * 1993-12-09 1995-06-23 Nec Corp Optimization system for multidirectional branch instruction
KR20150095648A (en) * 2012-12-10 2015-08-21 아브 이니티오 테크놀로지 엘엘시 System for transform generation
JP2016510442A (en) * 2012-12-10 2016-04-07 アビニシオ テクノロジー エルエルシー Transform generation system
US10817503B2 (en) 2012-12-10 2020-10-27 Ab Initio Technology Llc System for transform generation
JP2017142718A (en) * 2016-02-12 2017-08-17 株式会社デンソー Electronic control device and code generation program
JP2021521538A (en) * 2018-04-13 2021-08-26 マイクロソフト テクノロジー ライセンシング,エルエルシー Sorting of compound conditions for high-speed short circuit

Similar Documents

Publication Publication Date Title
US6412105B1 (en) Computer method and apparatus for compilation of multi-way decisions
US7707386B2 (en) Program segment searching for extension instruction determination to design a processor that meets performance goal
JPH05257709A (en) Parallelism discriminating method and parallelism supporting method using the same
US6286135B1 (en) Cost-sensitive SSA-based strength reduction algorithm for a machine with predication support and segmented addresses
US6308322B1 (en) Method and apparatus for reduction of indirect branch instruction overhead through use of target address hints
US7386838B2 (en) Method and apparatus for obtaining profile data for use in optimizing computer programming code
US7810081B2 (en) Compilation error isolation, optimization and resolution
US6345384B1 (en) Optimized program code generator, a method for compiling a source text and a computer-readable medium for a processor capable of operating with a plurality of instruction sets
US5946491A (en) Register allocation method and apparatus for gernerating spill code as a function of register pressure compared to dual thresholds
JP2004234126A (en) Compiler and compiling method
US7086043B2 (en) Compiler apparatus and method for unrolling a superblock in a computer program
NZ241694A (en) Compiling computer code: optimizing intermediate language flow graph using routine to fold constant expressions
US5596732A (en) Method of optimizing instruction sequence of compiler
US5581762A (en) Compiling apparatus having a function to analyze overlaps of memory addresses of two or more data expressions and a compiling method
US11928447B2 (en) Configuration management through information and code injection at compile time
US20040015918A1 (en) Program optimization method and compiler using the program optimization method
US6041181A (en) Method of, system for, and computer program product for providing quick fusion in WHERE constructs
WO1992015944A1 (en) Interface for representing effects in a multilanguage optimizing compiler
Benitez et al. The advantages of machine-dependent global optimization
US20130067196A1 (en) Vectorization of machine level scalar instructions in a computer program during execution of the computer program
EP1141825B1 (en) Method and system for identifying locations to move portions of the computer program
CN116089302A (en) Method for detecting UNSAFE code fragment defects in Rust programming language
JPH0736706A (en) Optimized compiler
US20010044930A1 (en) Loop optimization method and a compiler
CN107239260B (en) Multi-predicate control and compiling optimization method for digital signal processor