JP2003280922A - Code size decreasing method - Google Patents
Code size decreasing methodInfo
- Publication number
- JP2003280922A JP2003280922A JP2002084745A JP2002084745A JP2003280922A JP 2003280922 A JP2003280922 A JP 2003280922A JP 2002084745 A JP2002084745 A JP 2002084745A JP 2002084745 A JP2002084745 A JP 2002084745A JP 2003280922 A JP2003280922 A JP 2003280922A
- Authority
- JP
- Japan
- Prior art keywords
- function
- code
- address
- symbol
- program
- 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
Links
Landscapes
- Devices For Executing Special Programs (AREA)
Abstract
Description
【0001】[0001]
【発明の属する技術分野】本発明はプログラミング言語
の処理系技術に関する。BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a programming language processing technology.
【0002】[0002]
【従来の技術】コードサイズを小さくする方法の一つ
に、呼び出されることがない関数のコードを削除する方
法がある。2. Description of the Related Art One method of reducing the code size is to delete the code of a function that is never called.
【0003】[0003]
【発明が解決しようとする課題】オブジェクト指向プロ
グラミング言語の実現では、関数呼び出し以外にも関数
シンボルを参照する場合がある。オブジェクト指向プロ
グラミングでは、仮想関数呼び出しという機能を提供す
る。その単純な実現は、ディスパッチテーブルを介した
関数呼び出しである。関数呼び出しの高速化を目指す場
合には、I−call if変換(メソッドテスト変換
など)を施すことがある。参考文献:“Detlef
s,et.al.:Inlining of Virtu
al Methods,”ECOOP99,pp.25
8−278)。In realizing an object-oriented programming language, function symbols may be referred to in addition to function calls. Object-oriented programming provides a function called virtual function call. Its simple realization is a function call via a dispatch table. In order to speed up the function call, I-call if conversion (method test conversion, etc.) may be performed. Reference: "Detref
s, et. al. : Inlining of Virtu
al Methods, "ECOOP99, pp.25.
8-278).
【0004】さらに関数の呼び出しを高速化するには、
インライン展開(参考文献:A.V.エイホ&Rセシィ、
“コンパイラ その技法と原理”、サイエンス社)があ
る。これは関数本体を呼び出し部分に直接展開する技術
である。To further speed up the function call,
In-line deployment (Reference: AV Aho & R Cecy,
"Compiler technique and principle", Science Co.). This is a technology that directly expands the function body to the calling part.
【0005】仮想関数呼び出しの実現方法について具体
例を示す。図1は間接呼び出しの実施例である。コンパ
イラが生成するソースコードの各関数のアドレスを表す
データ構造であるディスパッチテーブル(図2参照)か
ら目的の関数のアドレスを取得しその関数を呼び出す。
図3はメソッドテスト変換の実施例である。ディスパッ
チテーブルから目的の関数のアドレスを取得し、そのア
ドレスが関数methodAであるならば、関数met
hodAを直接呼び出す。図2と図3から、ディスパッ
チの内部およびメソッドテスト変換によって最適化した
仮想関数呼び出しのコードから、関数シンボルを参照し
ていることが判る。A specific example of a method for implementing a virtual function call will be shown. FIG. 1 shows an example of indirect call. The address of the target function is acquired from the dispatch table (see FIG. 2), which is the data structure representing the address of each function of the source code generated by the compiler, and the function is called.
FIG. 3 shows an example of method test conversion. If the address of the target function is acquired from the dispatch table and the address is the function methodA, the function met
Call hodA directly. It can be seen from FIGS. 2 and 3 that the function symbol is referenced from the code of the virtual function call optimized by the dispatch and the method test conversion.
【0006】従来技術であるインライン展開は、関数呼
び出しの呼び出し元に現れる関数シンボルを削除する効
果しかないので、これら仮想関数呼び出しの実現に関し
てディスパッチテーブルの中やメソッドテスト変換のコ
ード中に現れる関数シンボルを削除することは出来な
い。このとき、関数シンボルが残っている関数コード
は、たとえ関数を全て呼び出し元にインライン展開し
て、関数のコードが呼び出される可能性がなくなったと
しても削除することは出来ない。Since the inline expansion which is a conventional technique has only the effect of deleting the function symbol appearing at the caller of the function call, the function symbol appearing in the dispatch table or the code of the method test conversion in terms of implementing these virtual function calls. Cannot be deleted. At this time, the function code in which the function symbol remains cannot be deleted even if there is no possibility that the function code will be called even if all the functions are inline expanded to the caller.
【0007】[0007]
【課題を解決するための手段】直接あるいは間接的に呼
び出されることはないが、アドレスとして関数名が参照
されている関数を求め、該関数シンボルへの参照を該関
数に固有な定数で置換する。また同様にメソッドディス
パッチテーブルに、該関数のアドレスを登録する(すな
わち、関数名を記述する)代わりに、目的の関数を表す
固有の定数を登録する。そうすることにより関数名(シ
ンボル)への参照がなくなるのでインライン展開後の関
数本体を削除出来、コードサイズの削減が可能となる。[Means for Solving the Problems] A function which is not called directly or indirectly but whose function name is referred to as an address is obtained, and a reference to the function symbol is replaced with a constant unique to the function. . Similarly, instead of registering the address of the function (that is, describing the function name) in the method dispatch table, a unique constant representing the target function is registered. By doing so, since the reference to the function name (symbol) disappears, the function body after inline expansion can be deleted and the code size can be reduced.
【0008】[0008]
【発明の実施の形態】以下、本発明の実施例について図
面を用いて詳細に説明する。なお、本発明は実施例に限
定されるものではない。BEST MODE FOR CARRYING OUT THE INVENTION Embodiments of the present invention will be described in detail below with reference to the drawings. The present invention is not limited to the examples.
【0009】本発明のコンパイラが動作する計算機を図
4に示す。計算機はプロセッサ401と主記憶402,
バス403、ディスク装置404、CD−ROM読取り
装置405を有する。コンパイラはCD−ROM(記憶
媒体)406に収めておくものとする。計算機はCD−
ROM読み取り装置405にCD−ROM406がセッ
トされると、コンパイラのプログラムを読み込み、バス
403を介してディスク装置404に保管する。コンパ
イラを実行するときには、コンパイラのプログラムをデ
ィスク装置404からバス403を介して主記憶402
に収め、プロセッサ401で随時読み出して実行する。
また図示していないが計算機にはコンパイラの実行指示
等を入力するための入力装置と、コンパイラの実行結果
を表示する表示装置やコンパイラの実行結果を印刷する
印刷装置が接続される。FIG. 4 shows a computer on which the compiler of the present invention operates. The computer has a processor 401 and a main memory 402,
It has a bus 403, a disk device 404, and a CD-ROM reading device 405. The compiler is stored in the CD-ROM (storage medium) 406. Computer is CD-
When the CD-ROM 406 is set in the ROM reading device 405, the compiler program is read and stored in the disk device 404 via the bus 403. When executing the compiler, the compiler program is loaded from the disk device 404 to the main memory 402 via the bus 403.
, And the processor 401 reads out and executes at any time.
Although not shown, the computer is connected to an input device for inputting a compiler execution instruction and the like, a display device for displaying the compiler execution result, and a printing device for printing the compiler execution result.
【0010】本発明のコンパイラの実施例を図5に示
す。コンパイラ501はソースプログラム502を入力
として受け取り、中間コード変換部503で構文解析を
して中間コードに変換し、最適化部504でI−cal
l if変換やインライン展開などの最適化を施し、冗
長コード削除部505で、削除可能な関数のコードを削
除し、最後にコード生成部506で中間コードを機械コ
ード507に変換する。本実施例において冗長コード削
除部505は、直接呼び出し対象にならない関数も検出
してその関数のコードも削除する。An embodiment of the compiler of the present invention is shown in FIG. The compiler 501 receives the source program 502 as an input, parses the intermediate code conversion unit 503 to convert it into intermediate code, and the optimization unit 504 I-cal.
Optimization such as l if conversion and inline expansion is performed, the code of the deletable function is deleted by the redundant code deletion unit 505, and finally the intermediate code is converted into the machine code 507 by the code generation unit 506. In the present embodiment, the redundant code deletion unit 505 also detects a function that is not a direct call target and deletes the code of that function.
【0011】図5の冗長コード削除部505は図6に示
すように、各関数に削除可能かのフラグを設定するマー
ク部601と、関数を削除可能かフラグを見て判断し可
能ならば削除するスイープ部に分けられる。As shown in FIG. 6, the redundant code deleting unit 505 of FIG. 5 sets a mark unit 601 for setting a flag indicating whether or not each function can be deleted, and deletes the function if it can be determined by checking the flag. It is divided into sweep sections.
【0012】図6のマーク部601の詳細を図7に示
す。マーク部601はまず、集合Sにアプリケーション
で構成する全プログラムの全文を収める。そして全関数
に呼び出し状況を示すフラグを設定する。フラグには4
つの種類、UNKNOWN、INDIRECT、DIR
ECT、ADDRESSがある。各フラグはそれぞれ、
どのコードからも呼ばれることのないことを示すUNK
NOWN、間接呼び出しを示すINDIRECT、直接
呼び出しを示すDIRECT、関数のシンボルのみを参
照していることを示すADDRESSを意味する。Details of the mark portion 601 of FIG. 6 are shown in FIG. First, the mark unit 601 stores all the sentences of all programs configured by the application in the set S. Then, a flag indicating the calling status is set to all functions. 4 for the flag
Three types, UNKNOWN, INDIRECT, DIR
There are ECT and ADDRESS. Each flag is
UNK indicating that no code is called
It means NOW, INDIRECT indicating indirect call, DIRECT indicating direct call, and ADDRESS indicating that only the symbol of the function is referenced.
【0013】まず初めに全関数のフラグをUNKNOW
Nに設定する。判定702で集合Sが空集合φならば処
理を終了する。空集合φでなければ、集合Sから文を1
つ取り出す。そして判定704に進み、取り出した文が
間接呼び出しならば処理705に進む。処理705では
該文が間接呼び出ししうる全ての関数のフラグをIND
IRECTにする。判定704で該文が間接呼び出しで
なければ判定706に進み、該文が直接呼び出しである
かを判定し、直接呼び出しならば判定707に進む。判
定707では文が直接呼び出しする呼び出し先の関数の
フラグがADDRESSまたはUNKNOWNであるか
を判定し、ADDRESSまたはUNKNOWNである
ならば該関数のフラグをDIRECTに設定する。判定
707で該文が直接呼び出しでなければ判定709に進
み、該文が関数シンボルへの参照であるかを判定し、関
数シンボルへの参照ならば判定710に進む。判定71
0では文がシンボル参照する関数のフラグがUNKNO
WNであるかを判定し、UNKNOWNであるならば該
関数をADDRESSに設定する。判断709をはずし
たら判断702に戻る。First, the flags of all functions are set to UNKNOW.
Set to N. If the set S is the empty set φ in the decision 702, the process is terminated. If it is not the empty set φ, one sentence from the set S
Take out one. Then, the process proceeds to decision 704, and if the retrieved statement is an indirect call, the process proceeds to processing 705. In process 705, IND the flags of all functions that can be indirectly called by the statement.
Set to IREC. In decision 704, if the statement is not an indirect call, the procedure proceeds to decision 706, it is determined whether the statement is a direct call, and if it is a direct call, the procedure proceeds to decision 707. In the judgment 707, it is judged whether the flag of the callee function directly called by the statement is ADDRESS or UNKNOWN, and if it is ADDRESS or UNKNOWN, the flag of the function is set to DIRECT. In decision 707, if the statement is not a direct call, the procedure proceeds to decision 709, it is determined whether the statement is a reference to a function symbol, and if it is a reference to a function symbol, the procedure proceeds to decision 710. Judgment 71
In 0, the flag of the function that the statement refers to is UNKNO
It is determined whether it is WN, and if it is UNKNOWN, the function is set to ADDRESS. When the judgment 709 is removed, the process returns to the judgment 702.
【0014】判定702で集合Sが空集合φならば図6
のマーク部601が終了し、スイープ部602に進む。
スイープ部602では、関数のフラグがADDRESS
またはUNKNOWNである関数を削除対象にし、削除
を実施する。関数のフラグがUNKNOWNならば、関
数のシンボルが全く参照されなかったことを示すので、
該関数を削除する。関数のフラグがADDRESSなら
ば、該関数へのシンボル参照は存在するが、該関数を直
接あるいは間接的に呼び出す呼び出し元は存在しないの
でフラグUNKNOWN同様に該関数を削除する。本発
明のコンパイラでは、関数のアドレス、即ち関数を実現
する機械コードの先頭アドレスを4バイト境界にアライ
メントしており、したがって、関数アドレスは偶数にな
る。そこで固有の定数が他の関数アドレスと合致してし
まうことを避ける為、固有の定数は奇数を用いるように
する。よって図2に最適化を施すと図8になる。図8は
関数ディスパッチテーブル上の0番目にあたる関数のフ
ラグがADDRESSであった場合、該関数アドレスを
固有の定数「1」に置き換えたことを示す。関数フラグ
としてADDRESSが複数個設定されている場合には
スイープ部は、先に置き換えられた固有の定数(この場
合0x00000000に対する「1」)以外の定数を
割り当て、異なる関数に同じ定数を割り当てることのな
いように動作する。スイープ部で置き換えた関数と固有
の定数の関係を管理し、必要に応じ対応表を出力できる
ようにしておくことが望ましい。If the set S is an empty set φ in the decision 702, FIG.
The mark portion 601 of 1 is finished, and the process proceeds to the sweep portion 602.
In the sweep unit 602, the function flag is ADDRESS.
Alternatively, the function that is UNKNOWN is targeted for deletion, and the deletion is performed. If the function flag is UNKNOWN, it means that the function symbol was not referenced at all.
Delete the function. If the flag of the function is ADDRESS, there is a symbol reference to the function, but since there is no caller that directly or indirectly calls the function, the function is deleted similarly to the flag UNKNOWN. In the compiler of the present invention, the address of the function, that is, the start address of the machine code that implements the function is aligned on a 4-byte boundary, and therefore the function address is an even number. Therefore, in order to avoid the unique constant from matching other function addresses, an odd number is used as the unique constant. Therefore, the optimization of FIG. 2 results in FIG. FIG. 8 shows that when the flag of the 0th function on the function dispatch table is ADDRESS, the function address is replaced with a unique constant “1”. When a plurality of ADDRESS is set as the function flag, the sweep unit assigns a constant other than the unique constant that was previously replaced (in this case, “1” for 0x00000000) and assigns the same constant to different functions. Works like no. It is desirable to manage the relationship between the function replaced by the sweep section and the unique constant so that the correspondence table can be output if necessary.
【0015】[0015]
【発明の効果】インライン展開などの最適化の結果とし
て、直接的あるいは間接的に呼び出されることがなくな
ったが、アドレスとして関数シンボルのみ参照されてい
る関数について、関数シンボルへの参照を関数に固有な
定数に差し替えることで無くし、それによって関数本体
を削除することを可能にする。この結果、コードサイズ
を削減できる。本発明により、一般的にはコードサイズ
を数%程度小さくできる。As a result of optimization such as inline expansion, the function is no longer called directly or indirectly, but for functions in which only the function symbol is referenced as an address, the reference to the function symbol is unique to the function. It is possible to delete the function body by replacing it with another constant. As a result, the code size can be reduced. According to the present invention, the code size can be generally reduced by about several percent.
【図1】間接呼び出し例を示す図。FIG. 1 is a diagram showing an indirect call example.
【図2】関数のアドレスを表すデータ構造を示す図。FIG. 2 is a diagram showing a data structure representing an address of a function.
【図3】メソッドテスト変換例を示す図。FIG. 3 is a diagram showing a method test conversion example.
【図4】本発明のコンパイラを実行する計算機の構成を
示す図。FIG. 4 is a diagram showing a configuration of a computer that executes a compiler of the present invention.
【図5】本発明のコンパイラの流れを示すフローチャー
ト。FIG. 5 is a flowchart showing the flow of the compiler of the present invention.
【図6】削除メソッド検索の詳細フローチャート。FIG. 6 is a detailed flowchart of a deletion method search.
【図7】削除メソッド検索の詳細フローチャート。FIG. 7 is a detailed flowchart of a deletion method search.
【図8】本発明による関数のアドレスを表すデータ構造
例を示す図。FIG. 8 is a diagram showing an example of a data structure representing an address of a function according to the present invention.
401:プロセッサ、402:主記憶装置、403:バ
ス、404:ディスク装置、405:CD−ROM読取
装置、406:CD−ROM。401: processor, 402: main storage device, 403: bus, 404: disk device, 405: CD-ROM reading device, 406: CD-ROM.
───────────────────────────────────────────────────── フロントページの続き (72)発明者 高橋 龍太郎 神奈川県横浜市中区尾上町6丁目81番地 日立ソフトウエアエンジニアリング株式会 社内 (72)発明者 千葉 雄司 神奈川県川崎市麻生区王禅寺1099番地 株 式会社日立製作所システム開発研究所内 Fターム(参考) 5B081 AA09 CC16 CC24 ─────────────────────────────────────────────────── ─── Continued front page (72) Inventor Ryutaro Takahashi 6-81 Onoe-cho, Naka-ku, Yokohama-shi, Kanagawa Hitachi Software Engineering Stock Association In-house (72) Inventor Yuji Chiba 1099 Ozenji, Aso-ku, Kawasaki City, Kanagawa Prefecture Ceremony company Hitachi Systems Development Laboratory F-term (reference) 5B081 AA09 CC16 CC24
Claims (4)
グ言語で記述したプログラムをコンパイルする過程で、
呼び出し対象にならない関数で削除可能な関数を検出
し、該関数のコードを削除するコードサイズ削減方法。1. In the process of compiling a program written in a programming language that provides virtual function calls,
A code size reduction method for detecting a deletable function from functions that are not called and deleting the code of the function.
間接的に呼び出されることはないが、アドレスとして関
数名が参照されている関数を求め、該関数シンボルへの
参照を該関数に固有な定数で置換した上で該関数のコー
ドを削除する請求項1のコードサイズ削減方法。2. A statement in a program is scanned and a function whose function name is referred to as an address is not directly or indirectly called, but a reference to the function symbol is made unique to the function. The code size reduction method according to claim 1, wherein the code of the function is deleted after replacing with a constant.
レスとして関数名が参照されている関数を求めるステッ
プと、 該関数シンボルへの参照を該関数に固有な定数で置換し
た上で該関数のコードを削除するステップとを有するコ
ンパイラ。3. A step of scanning a statement in a program, a step of obtaining a function that is not directly or indirectly called but a function name is referred to as an address, and a reference to the function symbol is performed. Replacing with a constant specific to the function, and then deleting the code of the function.
レスとして関数名が参照されている関数を求めるステッ
プと、 該関数シンボルへの参照を該関数に固有な定数で置換し
た上で該関数のコードを削除するステップとを有するコ
ンパイラを格納した情報処理装置により読み取り可能な
記憶媒体。4. A step of scanning a statement in a program, a step of obtaining a function that is not directly or indirectly called but a function name is referred to as an address, and a reference to the function symbol is performed. A storage medium readable by an information processing apparatus, which stores a compiler having a step of deleting a code of the function after substituting with a constant unique to the function.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2002084745A JP2003280922A (en) | 2002-03-26 | 2002-03-26 | Code size decreasing method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2002084745A JP2003280922A (en) | 2002-03-26 | 2002-03-26 | Code size decreasing method |
Publications (1)
Publication Number | Publication Date |
---|---|
JP2003280922A true JP2003280922A (en) | 2003-10-03 |
Family
ID=29231955
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2002084745A Pending JP2003280922A (en) | 2002-03-26 | 2002-03-26 | Code size decreasing method |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP2003280922A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2006163686A (en) * | 2004-12-06 | 2006-06-22 | Matsushita Electric Ind Co Ltd | Compiling method, compiling program, compiling device and recording medium for compile |
JP2007531946A (en) * | 2004-04-07 | 2007-11-08 | ローベルト ボッシュ ゲゼルシャフト ミット ベシュレンクテル ハフツング | Data integrity in data processing equipment |
CN100405294C (en) * | 2005-03-15 | 2008-07-23 | 国际商业机器公司 | System, method and program product to optimize code during run time |
JP2009129327A (en) * | 2007-11-27 | 2009-06-11 | Fuji Electric Holdings Co Ltd | Program development support device, method, and program |
-
2002
- 2002-03-26 JP JP2002084745A patent/JP2003280922A/en active Pending
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2007531946A (en) * | 2004-04-07 | 2007-11-08 | ローベルト ボッシュ ゲゼルシャフト ミット ベシュレンクテル ハフツング | Data integrity in data processing equipment |
US8464236B2 (en) | 2004-04-07 | 2013-06-11 | Robert Bosch Gmbh | Data consistency in data processing systems |
JP2006163686A (en) * | 2004-12-06 | 2006-06-22 | Matsushita Electric Ind Co Ltd | Compiling method, compiling program, compiling device and recording medium for compile |
CN100405294C (en) * | 2005-03-15 | 2008-07-23 | 国际商业机器公司 | System, method and program product to optimize code during run time |
JP2009129327A (en) * | 2007-11-27 | 2009-06-11 | Fuji Electric Holdings Co Ltd | Program development support device, method, and program |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP2000035893A (en) | Method for statically initializing arrangement of data processing system, data processing method, data processing system and computer readable storage medium storing program making computer execute its control procedure | |
JP2000347872A (en) | Method and device for processing exception as regular control flow | |
JPH10240754A (en) | Text data registering and retrieving method | |
US7743020B2 (en) | Automatic instance data mapping generation | |
JP3130446B2 (en) | Program conversion device and processor | |
JP3130828B2 (en) | Assembly processing method | |
JP2003280922A (en) | Code size decreasing method | |
JP4088379B2 (en) | Compiling method and apparatus, and stack tracing method and apparatus | |
JP2000122875A (en) | Method and system for processing exception | |
JP2010123060A (en) | Method of accessing unknown object | |
JP6597356B2 (en) | Control program, control device, and control method | |
JP5702265B2 (en) | Program automatic generation apparatus and program automatic generation method | |
JP2006259805A (en) | Processor design equipment, processor design method, and processor design program | |
JP5303943B2 (en) | Arithmetic processing device and control method of arithmetic processing device | |
JP2005322110A (en) | Program converting device and processor | |
JP2721377B2 (en) | BASIC program compression method | |
JP2000305790A (en) | Label address converting device and its method and computer readable medium | |
JP2004145529A (en) | Disclosure document masking section managing method and its executing device and its processing program | |
JP3079825B2 (en) | Electronic computer equipment | |
JP2002055852A (en) | Object generation/extinction information management system | |
JP2022125690A (en) | Information processing device, information processing program, and program development support method | |
JPH07141178A (en) | Object accessing device | |
JP2002073347A (en) | Exception handling method and compiler | |
JP2000132405A (en) | In-line expansion processing device and method | |
JPH05233307A (en) | Plural process generating method |