Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
JP3675166B2 - Program processing apparatus and recording medium - Google Patents
[go: Go Back, main page]

JP3675166B2 - Program processing apparatus and recording medium - Google Patents

Program processing apparatus and recording medium Download PDF

Info

Publication number
JP3675166B2
JP3675166B2 JP09564698A JP9564698A JP3675166B2 JP 3675166 B2 JP3675166 B2 JP 3675166B2 JP 09564698 A JP09564698 A JP 09564698A JP 9564698 A JP9564698 A JP 9564698A JP 3675166 B2 JP3675166 B2 JP 3675166B2
Authority
JP
Japan
Prior art keywords
code
unresolved
instruction
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.)
Expired - Fee Related
Application number
JP09564698A
Other languages
Japanese (ja)
Other versions
JPH11296379A (en
Inventor
謙介 小谷
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 Corp
Panasonic Holdings Corp
Original Assignee
Panasonic Corp
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 Panasonic Corp, Matsushita Electric Industrial Co Ltd filed Critical Panasonic Corp
Priority to JP09564698A priority Critical patent/JP3675166B2/en
Publication of JPH11296379A publication Critical patent/JPH11296379A/en
Application granted granted Critical
Publication of JP3675166B2 publication Critical patent/JP3675166B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Description

【0001】
【発明の属する技術分野】
本発明は、高級言語からオブジェクトコードを生成するコンパイラ、複数のオブジェクトコードを連結編集し実行可能コードを生成するリンカ、を含むプログラム処理装置及び記録媒体に関するものであり、特に最終的に生成される実行形式コードのコードサイズを削減するコード最適化技術、及び、変数及びプログラムの記憶領域への配置技術に関する。
【0002】
【従来の技術】
近年、ますますマイクロコンピュータで処理させるプログラムが複雑・高度化している。これに伴い、プログラムをC言語等の高級言語で作成した後、コンパイラおよびリンカによってマイクロコンピュータが実行できる形式に変換する方法が多く用いられるようになってきた。
【0003】
特に、プログラムが膨大となりつつある昨今では、開発効率の点からプログラムを幾つかのソースコードファイルに分割し、これらを別々にコンパイルした後、リンカにより連結編集し、最終的な機械語コードを生成する分割コンパイルが一般に用いられる。
【0004】
この分割コンパイルにおける、コンパイラおよびリンカでは、それぞれの連携が重要となる。
【0005】
以下、従来のコンパイラおよびリンカについて説明する。
特開平9―212369号公報には、コンパイル時に使用されている変数のサイズを調べ、サイズの小さい順に整列した後で変数をメモリ上に配置する技術が記載されている。これにより基底アドレスからのオフセットの総和が最小に保たれるので記憶領域の削減ができる。また、同公報には、プロファイル情報を使用し、動的なアクセス数の多い順、つまり、実行される回数が多い順に変数を整列した後で、メモリ上に配置する方式も記載されている。これによりアクセス回数の多い変数は小さなオフセットによりアクセスすることができ、アクセス回数の多い変数へのアクセス命令サイズが小さくなり、結果としてコードサイズが削減される。
【0006】
【発明が解決しようとする課題】
しかしながら、従来の方式では、分割コンパイルされた場合にコードサイズ削減の観点からの最適なメモリ配置を実現することができないという問題点があった。
【0007】
すなわち、外部変数や静的変数は最終的な機械語コードで1つのみ存在する為、各ファイル内での整列では、最終機械語コードでの最適配置を実現することはできない。
【0008】
また、プロファイル情報により得られる動的なアクセス数による整列では、一般に、プログラム中のメモリ操作命令の出現数による整列と異なった結果が得られる。コードサイズを削減するためにはプログラムの字面上の命令数が多い、つまり、プログラム中の出現数の多い命令のコードサイズを削減した方が、プログラム全体のコードサイズが小さくなることは明らかであり、コードサイズ改善の余地がある。
【0009】
更に、プロファイル情報を得るためにはコンパイラはプロファイルを取得する為のコードを生成する必要があり、コンパイル時間、コンパイル時に必要な記憶容量が増大し、また、プロファイルを得る為にプログラムの予備的実行が必要となり、結果、プログラム開発期間の増大を招く。
【0010】
また、上記方式ではプログラムモジュールの配置については何ら考慮されていない為、副プログラムの呼出命令の最適化は全くなされない。
【0011】
本発明はかかる問題点に鑑みてなされたものであり、プログラムの予備的実行なしに、分割コンパイルされたプログラムに対しても変数の最適記憶領域配置を実現し、また、プログラムの最適配置を実現することにより、最終コードサイズの削減を果たすプログラム処理装置及び記録媒体を提供することを目的とする。
【0012】
【課題を解決するための手段】
本発明のプログラム処理装置は、
高級言語で記述された複数のソースコードからなるプログラムを実行可能コードに変換する装置であって、
前記複数のソースコードを複数のオブジェクトコードに変換する第1の変換手段と
前記複数のオブジェクトコードを前記実行可能コードに変換する第2の変換手段とを備え、
前記第1の変換手段は、前記複数のソースコードを前記複数のオブジェクトコードに変換する時に、前記複数のオブジェクトコードに含まれる未解決シンボルの出現回数を計測する計測手段を含み、
前記第2の変換手段は
前記未解決シンボルの出現回数が多い順に前記複数のオブジェクトコードに含まれる前記未解決シンボルに記憶領域を割り当てる記憶領域割り当て手段を備えたことを特徴とする
【0015】
また本発明のプログラム処理装置は、前記記憶領域割り当て手段は、プログラム実行中を通して値が保持される変数である前記未解決シンボルの出現回数が多い順に、前記未解決シンボルに記憶領域を割り当てるとすることができる。
【0018】
また本発明のプログラム処理装置は、前記記憶領域割り当て手段は、実体が副プログラムである前記未解決シンボルの出現回数が多い順に、前記未解決シンボルに記憶領域を割り当てることを特徴とすることができる。
【0019】
本発明のプログラム処理装置は、第1の変換手段は、前記計測手段が計測した前記未解決シンボルの出現回数を頻度情報ファイルとして出力する頻度情報出力手段を含み、前記第2の変換手段は、前記頻度情報出力手段が出力した複数の前記頻度情報ファイルを受け取り、前記未解決シンボル毎に頻度を総計する頻度情報入力手段を含むとすることができる。
【0020】
また本発明のプログラム処理装置は、前記第1の変換手段は、前記計測手段が計測した前記未解決シンボルの出現回数をオブジェクトコードに付加して出力するオブジェクトコード出力手段を含み、前記第2の変換手段は、前記オブジェクトコード出力手段が出力した複数の前記オブジェクトコードを受け取り、前記オブジェクトコードに付加されている前記出現回数を取り出して、前記未解決シンボル毎に頻度を総計する頻度情報入力手段を含むとすることができる。
【0022】
また本発明のプログラム処理装置は、前記指示手段は、前記記憶領域割り当て手段において前記未解決シンボルに割り当てられた記憶領域を絶対番地形式で操作する命令のコードサイズと前記命令の出現回数の積が、前記未解決シンボルに割り当てられた記憶領域を相対番地形式で操作する命令のコードサイズと前記命令の出現回数の積と前記相対番地をレジスタに設定する命令のコードサイズとの和を上回る場合に、前記未解決シンボルを相対番地アドレス形式で操作する命令を生成するよう、前記第1の変換手段に指示し、前記第1の変換手段は、前記指示手段からの指示がある場合に、前記未解決シンボルを相対番地形式で操作する命令を生成するとすることができる。
【0023】
また本発明の記録媒体は、高級言語で記述された複数のソースコードからなるプログラムを実行可能コードに変換するプログラムを記録した記録媒体であって、前記複数のソースコードを複数のオブジェクトコードに変換する時に、前記複数のオブジェクトコードに含まれる未解決シンボルの出現回数を計測する計測ステップを含む第1の変換ステップと、前記複数のオブジェクトコードを前記実行可能コードに変換し、前記未解決シンボルの出現回数が多い順に前記複数のオブジェクトコードに含まれる前記未解決シンボルに記憶領域を割り当てる記憶領域割り当てステップを含む第2の変換ステップをコンピュータに実行させる為のプログラムを記録するとすることができる。
【0024】
【発明の実施の形態】
以下、本発明に係るプログラム処理装置及び記録媒体について図面を参照しながら説明する。
[用語の説明]
まず初めに本説明で用いる用語の説明を行なう。
・副プログラム
メインルーチンから呼び出されるプログラム。具体的には、関数やサブルーチンを指す。
・未解決シンボル
オブジェクトコードが連結編集されるまで確定しないシンボル。外部変数や外部ラベル(副プログラムの開始アドレス)などがある。
・オブジェクト
シンボルが表す実体。例えば、高級言語としてC言語を用いた場合、AがLONG型の外部変数である場合、実体は8バイトのメモリとなる。
・セクション
連結編集の際に、オブジェクトを配置する時の区別。同じセクションのオブジェクトは一まとめにされて配置される。一般にプログラムはコードセクションとして、変数はデータセクションとしてまとめて配置される。
[1.実施の形態1]
[プログラム処理装置の構成]
図1は、本プログラム処理装置の構成及び関連するデータを示すブロック図である。
【0025】
本プログラム処理装置は、大きく2つのグループ、即ち、(1)高級言語で書かれたソースコード50からオブジェクトコード60を生成するグループ(コンパイラ上流部10、コード生成部11、頻度情報出力部12、頻度測定部13からなる変換手段1、以下コンパイラと呼ぶ)と、(2)複数のオブジェクトコード60〜61を連結編集し最終の実行可能コード70を生成するグループ(シンボル情報収集部20、頻度情報入力部21、配置最適化部22、記憶領域割り付け部23からなる変換手段2、以下リンカと呼ぶ)から構成される。
(コンパイラ上流部10)
コンパイラ上流部10は、ファイル形式で保存されている高級言語ソースコード50を読み込み、構文解析及び意味解析を行なった後に内部形式コードを生成する。更に、必要に応じて、最終的に生成される実行可能コードのサイズやその実行時間が短くなるようにその内部形式コードを最適化する。ここでの処理は、従来のコンパイラが有するコンパイラ上流部による処理と同一である。
(コード生成部11)
コード生成部11は、コンパイラ上流部10により生成され最適化された内部形式コードからオブジェクトコード60を生成する。ここで、「オブジェクトコード」とは、再配置可能情報を含んだ目的機械向け機械語プログラムである。コード生成部11は頻度測定部13を含む。頻度測定部13はコード生成部で生成されたコードに未解決シンボルが含まれていた場合にシンボル頻度情報テーブル14にアクセスしてシンボルの出現頻度を更新する。
【0026】
コード生成部11の処理の詳細は以下の通りである。
図2は、コード生成部11での処理手順を示すフローチャートである。
【0027】
コード生成部11は、コンパイラ上流部10が生成した内部形式コードの全ての命令について、以下の処理(ステップS2〜S6)を繰り返す(ステップS1、S7)。
【0028】
まず、コード生成部11は、着目する内部形式コード命令に対応する機械語コード命令(以下、単に「着目命令」と呼ぶ。)を生成する(ステップS2)。
【0029】
次に、着目命令が未解決シンボルを含むか否かを判断する(ステップS3)。未解決シンボルを含む場合には、更にその未解決シンボルが既にシンボル頻度情報テーブルに登録済みか否かを判断する(ステップS4)。
【0030】
未解決シンボルがシンボル頻度情報テーブルに登録されていない場合には、当該未解決シンボルに対応するエントリを、シンボル頻度情報テーブルに作る(ステップS5)。その際、当該シンボルの使用頻度を0に初期化する。
【0031】
次に当該シンボルの使用頻度に1を加え、シンボル頻度情報テーブルを更新する(ステップS6)。
【0032】
なお、図2中、点線で囲まれる部分がコード生成部11に含まれる頻度測定部13の処理に相当する。
(頻度情報出力部12)
図1に戻って、頻度情報出力部12は、シンボル頻度情報テーブル14を読み出し、シンボル頻度情報ファイル80として出力する。
【0033】
以上コンパイラ1の処理によりソースコード50からこれに対応したオブジェクトコード60とシンボル頻度情報ファイル80が生成される。ソースコードが複数ある場合には、コンパイラ1の処理をそれぞれのソースコード50、51に対して行なうことにより、それぞれに対応したオブジェクトコード60、61とシンボル頻度情報ファイル80、81が生成される。
(シンボル情報収集部20)
シンボル情報収集部20は、複数のオブジェクトコード60〜61を読み込みシンボル情報を収集する。更に、収集されたシンボル情報に基づき、シンボル情報テーブル24を生成する。ここでの処理は、従来のリンカが有するシンボル情報収集部による処理と同一である。また、生成されるシンボル情報テーブル24も、この段階では、従来のリンカが生成するシンボル情報テーブル24と違いはない。
(頻度情報入力部21)
頻度情報入力部21は、コンパイラ1の頻度情報出力部12が出力したシンボル頻度情報ファイル80〜81を読み込み。シンボル情報収集部20が生成したシンボル情報テーブル24の対応するエントリに、シンボル頻度情報を追加する。
(配置最適化部22)
配置最適化部22は、シンボル情報テーブル24を参照し変数のメモリ配置を最適化する。具体的にはシンボルの使用頻度に着目し、使用頻度の多い変数を記憶領域の基底アドレスに近い位置に配置する。これにより頻繁にアクセスされるメモリに対するコードが小さくなることが期待されるので全体としてコードサイズを小さくすることが可能となる。
【0034】
配置最適化部22の処理の詳細は以下の通りである。
図3は、配置最適化部22での処理手順を示すフローチャートである。
【0035】
まず配置最適化部22は、シンボル情報テーブルを頻度数の多い順に整列する(ステップT1)。整列はセクション毎に行なう。
【0036】
次に、以下の処理で用いる割り付け可能メモリ位置を、割り付け可能なメモリの先頭に初期化する(ステップT2)。この割り付け可能メモリ位置はセクション数により複数個用意される。当実施の形態では外部及び静的変数用割り付け可能メモリ位置(以下、変数用割り付け可能メモリ位置と呼ぶ)とプログラム用割り付け可能メモリ位置の2つを使用するものとする。
【0037】
次に配置最適化部22は、シンボル情報テーブルに従い割り付け対象がある間、ステップT1で整列された順に従って以下の処理(ステップT4〜T5)を繰り返す(ステップT3、T6)。
【0038】
未解決シンボルを割り付け可能メモリ位置に割り付け、割り付けたメモリ位置をシンボル情報テーブル24に登録する(ステップT4)。この際、割り付け対象の未解決シンボルが変数である場合には変数用割り付け可能メモリ位置を、プログラムである場合にはプログラム用割り付け可能メモリ位置を使用する。
【0039】
次に、割り付け可能メモリ位置を、ステップT4で割り付けたオブジェクトのサイズに従って更新する(ステップT5)。具体的には現在の割り付け可能メモリ位置にステップT4で割り付けたオブジェクトのサイズを加えて、新たな割り付け可能メモリ位置とする。目的機械の制限によりメモリアライメントに制約のある場合には、これを考慮して新たな割り付け可能メモリ位置を調整する。この際、ステップT4で割り付けた未解決シンボルが変数である場合には変数用割り付け可能メモリ位置を、プログラムである場合にはプログラム用割り付け可能メモリ位置を更新する。
(記憶領域割り付け部23)
図1に戻って、記憶領域割り付け部23は、配置最適化部22で決定された内容に従って、実際にメモリを割り付け、最終実行可能コード70を生成する。生成された実行可能コード70はファイルとして書き出される。
[プログラム処理装置の具体的な動作]
次に、本プログラム処理装置の特徴的な構成要素の動作について、具体的な命令を用いて説明する。
【0040】
まず、本プログラム処理装置が対象とする目的機械について説明する。一般に固定長命令アーキテクチャにおいては1つの命令でアクセスできるメモリ範囲は限られている。図4(a)に示すのは固定長命令アーキテクチャにおけるメモリアクセス命令の一例である。このようなメモリアクセス命令を持つ目的機械においてはメモリを指定するアドレスを表現する幅が16ビットしかないため、0番地から65535番地までの65536バイトの領域までしか1つの命令で表すことはできない(矢符a1)。この範囲を越えるメモリには2つ以上の命令で表現する必要がある(矢符a2)。副プログラム呼出命令についてはある範囲までの領域しか直接呼び出すことはできない(矢符a3)。また一方、可変長命令アーキテクチャにおいても同様の制限が存在する。図4(b)に示すのは可変長命令アーキテクチャにおける命令の一例である。この例では2バイト命令ではアドレス幅8ビット、すなわち、0番地から255番地までの256バイトの領域にアクセスすることができる(矢符a4)。同様に3バイト命令では65535番地(矢符a5)、4バイト命令では4294967295番地までの領域にアクセスすることができる(矢符a6)。つまり、可変長アーキテクチャでは1つの命令で全てのメモリ領域にアクセスすることができるが、アクセスする領域が0番地から離れるに従いコードサイズが増大することになる。副プログラムに対する呼出命令でも同様により広いメモリ領域に対する呼出命令は、命令サイズより大きくなる(矢符a7、a8)。なお、ここでは絶対番地形式のメモリアクセス命令を例としてあげているが、これが相対番地形式であっても同じことがいえる。相対番地形式の場合には基準が0番地ではなく基底レジスタの値であるという違いがあるだけで、基底レジスタから離れるに従い、必要なコードサイズは増大する。
[例]
プログラムが3つに分割コンパイルされる場合について例を用いて説明する。この場合、ソースコードは3つ存在することになる。
【0041】
まず、第1のソースコードがコンパイルされる。コンパイラに入力されたソースコードは、コンパイラ上流部10で処理され内部形式コードに変換される。ここでは図5(a)の内部形式コードが得られたとする。内部形式コードは次にコード生成部11に入力される。コード生成部11の動作について、図2に示されたフローチャートに沿って説明する。
【0042】
コード生成部11は内部形式コードがある間、ステップS1〜S7を繰り返す。
【0043】
まず命令c1が図5(b)の機械語コードm1に変換される(ステップS2)。
【0044】
続いてこの命令が未解決シンボルを含むか否かが判断される(ステップS3)。機械語コードm1に含まれるシンボルmemory1は未解決シンボルであるのでYesと判断される。
【0045】
次にこのシンボルが既にシンボル頻度情報テーブル14に登録されているかが判断される(ステップS4)。この機械語コードm1はこのソースコードを処理した最初の命令であるのでシンボル頻度情報には何も登録されていない。このためこの分岐はNoと判断される。
【0046】
次に未解決なシンボルmemory1をシンボル頻度情報テーブルに登録する(ステップS5)。具体的には、シンボル頻度情報テーブル14にシンボルmemory1の欄を作り、頻度を0に初期化する(図6(a))。
【0047】
最後に現在取り扱っているシンボルmemory1の使用頻度に1を加え、シンボル頻度情報テーブルを更新する(ステップS6)。シンボル頻度情報テーブル14は図6(b)になる。
【0048】
以上のステップを内部形式コードがある間繰り返す(ステップS7)。
内部形式コードc2、c3が処理された直後のシンボル頻度情報テーブルの内容を図6(c)、(d)に示す。内部形式コードc2、c3はそれぞれ機械語コードm2、m3に変換される。また、第1のソースコードの処理が終った後での、シンボル頻度情報テーブルの内容を図6(e)に示す。ここで図6(d)、(e)でのfunction1の上の切れ目はこれより上が変数に対するシンボル頻度情報を、これより下が副プログラムに対するシンボル頻度情報を表していることを示している。これらはそれぞれ変数用とプログラム用のセクションを形成する。
【0049】
コード生成部11の処理が終ると、制御は頻度情報出力部12に移る。頻度情報出力部12はシンボル頻度情報テーブルを参照して、その内容をシンボル頻度情報ファイル80として出力する。第1のソースコードに対応するシンボル情報ファイル80の内容を図7(a)に示す。
【0050】
第2、第3のソースコードについても同様の処理が行なわれる。第2、第3のソースコードに対応するシンボル頻度情報ファイルの内容は図7(b)、(c)の通りであるとする。ここで図7(a)〜(c)でのfunction1の上の切れ目はこれより上が変数に対するシンボル頻度情報を、これより下が副プログラムに対するシンボル頻度情報を表していることを示している。
【0051】
次にリンカの処理内容について説明する。まず、シンボル情報収集部20がコンパイラより出力された複数のオブジェクトファイル60〜61を読み込む。この際、シンボルが出現した順にシンボル情報テーブル24にエントリを生成し、リンク処理に必要な情報(オブジェクトサイズ、アライメント情報)を取り込む。これらの情報は一般にオブジェクトファイルに含まれる。この処理は従来のリンカでの処理と違いはないので詳細は省略する。この例では3つのソースコードに対応する3つのオブジェクトコードが読み込まれ、図8(a)に示すシンボル情報テーブルに形成される。
【0052】
次に頻度情報入力部21が起動される。頻度情報入力部21は、シンボル情報収集部20が読み込んだオブジェクトファイルに対応する複数のシンボル頻度情報ファイル80〜81を読み込み、シンボル情報テーブル24内各シンボルのエントリの頻度欄に、読み込んだ頻度情報ファイルに記述されている値を加算する。この例では図7(a)、(b)、(c)に示す3つのシンボル頻度情報ファイルを読み込み、結果、シンボル情報テーブルは図8(b)の様になる。
【0053】
頻度情報入力部21の処理が終ると、配置最適化部22が起動される。配置最適化部22の動作について、図3に示されたフローチャートに沿って説明する。
【0054】
まず、シンボル情報テーブルをセクション毎に頻度数の多い順に整列(ソート)する(ステップT1)。セクションは図8(a)、(b)、(c)中のfunction1欄の上の切れ目で分かれ、計2セクション存在する。この結果、シンボル情報テーブル24は図8(c)の様になる。
【0055】
次に割り付け可能メモリ位置を初期化する(ステップT2)。ここではプログラム用割り付け可能メモリ位置を0xF000番地に、変数用割り付け可能メモリ位置を0x00F0に初期化したとする。0xは後ろの数値が16進数表記であることを示す。これは以下でも同様である。
【0056】
割り付け対象がある間、ステップT4〜T5を繰り返す(ステップT3、T6)。
【0057】
次に、未解決シンボルをメモリに割り付ける(ステップT4)。シンボル情報テーブルの先頭の未解決シンボルはmemory3であるのでこれを0x00F0番地に割り付ける。
【0058】
最後に、割り付けたオブジェクトのサイズに従って割り付け可能メモリ位置を更新する(ステップT5)。ここでmemory1のサイズは0x0008であるので割り付け可能メモリ位置は0x00F8となる。
【0059】
割り付け対象が残っている間、上記ステップT3〜T6が繰り返し実行される。残りのオブジェクトに対する割り付け動作について簡単に示す。
【0060】
2番目の未解決シンボルはmemory2である。これは0x00F8番地に割り付けられ(ステップT4)、割り付け可能メモリ位置はmemory2のオブジェクトサイズ0x0008を加えて0x0100に更新される(ステップT5)。
【0061】
3番目の未解決シンボルはmemory1である。これは0x0100番地に割り付けられ(ステップT4)、割り付け可能メモリ位置はmemory1のオブジェクトサイズ0x0008を加えて0x0108に更新される(ステップT5)。
【0062】
4番目の未解決シンボルはfunction2である。これはプログラムであるので、プログラム用割り付け可能メモリ位置を参照して、0xF000番地に割り付けられる(ステップT4)。割り付け可能メモリ位置はfunction2のオブジェクトサイズ0x0120を加えて0xF120に更新される(ステップT5)。
【0063】
5番目の未解決シンボルはfunction1である。これもプログラムであるので、0xF120番地に割り付けられ(ステップT4)、割り付け可能メモリ位置はfunction1のオブジェクトサイズ0x2134を加えて0x11254に更新される(ステップT5)。
【0064】
配置最適化部22終了段階でのシンボル情報テーブルは図9の様になる。
最後に、記憶領域割り付け部23がシンボル情報テーブル24の内容に従い、入力されたオブジェクトコード中の未解決シンボルを配置先アドレスで書き換える。この処理は従来のリンカの処理と同じである。
【0065】
以上の処理により最終的な実行可能コードが得られる。この例では3つのソースコードから生成された3つのオブジェクトコードを連結編集して実行可能コードが生成される。生成された実行可能コードの一部を図5(c)に示す。図5(c)に示すのは実行可能コードの内、図5(a)、(b)に示した第1のソースコードに対応する部分をニーモニックで表記したものである。実際の実行可能コードにはこれ以外に第2、第3のソースコードに相当する部分が含まれる。図5(b)と比較して分かるように図5(b)での未解決シンボルが、シンボル情報テーブル(図9)で確定した実際のメモリアドレスで置き換えられていることが分かる。
【0066】
次に本実施の形態1に基づき生成された実行可能コードのコードサイズを示す。目的機械にアーキテクチャとして図4(b)の可変長命令アーキテクチャを想定すると、第1、第2、第3のソースコード全てを含めたプログラム全体で最も頻繁にアクセスされるメモリmemory3へのアクセス命令は、メモリmemory3が0x00F0番地に配置されるので2バイト命令となり、メモリアクセス命令のコード総計は20バイトとなる。全てのメモリアクセス命令について考慮すると、本実施の形態1では2×10+2×6+4×5=52バイトとなる。
【0067】
また副プログラムの配置においては、function1の呼出はfunction1が0xF120番地から配置されるので4バイト命令、function2の呼出もfunction2が0xF000番地から配置されるので4バイト命令となり、呼出命令全体では4×5+4×7=48バイトとなる。
【0068】
各命令のサイズを示す為に、図5(c)には第1のソースコード相当部分のコードサイズを各命令ニーモニックの右横に示した。第1のソースコード相当部分のコードサイズは30バイトとなる。
【0069】
なお、この実施の形態ではシンボル頻度情報テーブル14の内容を頻度情報ファイル80として出力してリンカに渡したが、コード生成部11が生成するオブジェクトコード60にシンボル頻度情報テーブル14の内容を付加してリンカに受け渡しても良い。
【0070】
また、memory1へのアクセス命令のように命令コードサイズ(4バイト)と出現頻度(5回)の積(20バイト)がmemory1への相対番地アドレス形式メモリアクセス命令のコードサイズ(2バイト、図4(b)矢符a9)と出現頻度(5回)の積(10バイト)と相対番地アドレス基底レジスタへの設定命令(6バイト、図4(b)矢符a10)との和(16バイト)を上回る場合には、対応する未解決シンボル(この場合memory1)を相対番地形式で出力するようにコード生成部11へ指示し、コード生成から再度繰り返すようにしても良い。これにより更にコードサイズが削減できる。
[従来のプログラム処理装置との比較]
以上の処理により、最終的な実行可能コードが得られる。本発明の特徴を明確に示す為に、従来のプログラム処理装置(コンパイラ及びリンカ)での場合と比較する。
【0071】
図13は従来のプログラム処理装置の構成を本発明の実施の形態と対比して示すブロック図である。
【0072】
このプログラム処理装置では、本実施の形態の頻度測定部13、頻度情報出力部12、頻度情報入力部21、配置最適化部22を備えていない。従って複数のオブジェクトファイルに表れる未解決シンボルの出現頻度を得る手段がなく、リンカが処理する場合、未解決シンボルの出現順にメモリを割り当てることになる。このため、第1〜第3のソースコードを処理した場合の各シンボルに割り当てられるメモリは図14の様になる。なお、図14では以下での比較の為に出現頻度を付記しているが従来の構成では出現頻度欄は存在しない。
【0073】
次に、従来のプログラム処理装置に基づき生成された実行可能コードのコードサイズを示す。本実施の形態1と同じく、目的機械にアーキテクチャとして図4(b)の可変長命令アーキテクチャを想定すると、最も頻繁にアクセスされるメモリmemory3へのアクセス命令は、memory3が0x0100番地に配置されるので4バイト命令となり、この命令が10回出現することから、このメモリへのアクセス命令のコード総計は40バイトとなる。これは本実施の形態1のプログラム処理装置での結果より、20バイト増加している。全てのメモリアクセス命令について考慮すると、従来例では2×5+2×6+4×10=62バイトとなり、本実施の形態1での結果である52バイトに比べ10バイトの増加となる。
【0074】
また、副プログラムの配置においても同様の効果が表れる。従来例ではfunction1の呼出はfunction1が0xF000番地から配置されるので2バイト命令、function2の呼出はfunction2が0x11134番地から配置されるので4バイト命令となり、呼出命令全体では4×5+6×7=62バイトとなる。これに対し本実施の形態1では、呼出命令全体でのコードサイズは48バイトであったので、従来例では本実施の形態1に比べコードサイズが14バイト増加することになる。
【0075】
なお、従来のプログラム処理装置に変数のサイズもしくは動的使用頻度に基づく自動変数の記憶領域割り付けを行なう手段が備わっている場合でも、この例で示すような複数ファイルに分割されたプログラムの外部変数に対しては、記憶領域割り付けの最適化ができないことはいうまでもない。
[2.実施の形態2]
[プログラム処理装置の構成]
図10は、本プログラム処理装置の実施の形態2における構成及び関連するデータを示すブロック図である。
【0076】
本プログラム処理装置は、大きく2つのグループ、即ち、(1)高級言語で書かれたソースコード150からオブジェクトコード160を生成するグループ(コンパイラ上流部110、コード生成部111からなるコンパイラ101)と、(2)複数のオブジェクトコード160〜161を連結編集し最終の実行可能コード170を生成するグループ(シンボル情報収集部120、頻度測定部121、配置最適化部122、記憶領域割り付け部123からなるリンカ102)から構成される。
(コンパイラ上流部110)
これは実施の形態1におけるコンパイラ上流部10と同一である。
(コード生成部111)
コード生成部111は、コンパイラ上流部110により生成され最適化された内部形式コードからオブジェクトコード160を生成する。ここで、「オブジェクトコード」とは、再配置可能情報を含んだ目的機械向け機械語プログラムである。
(シンボル情報収集部120)
これは実施の形態1におけるシンボル情報収集部20と同一である。
(頻度測定部121)
頻度測定部121は、シンボル情報収集部120が読み込んだ複数のオブジェクトコード160〜161をサーチし、シンボル情報収集部120が生成したシンボル情報テーブル124の各シンボルについて、シンボルの出現頻度を測定する。
【0077】
頻度測定部121の処理の詳細は以下の通りである。
図11は、頻度測定部121での処理手順を示すフローチャートである。
【0078】
まず、頻度測定部121は、シンボル情報テーブル124の頻度欄を全て0で初期化する(ステップU1)。
【0079】
次に、オブジェクトコード中のプログラムに相当する部分がある間以下の処理(ステップU3〜U4)を繰り返す(ステップU2、U5)。
【0080】
まず、現在処理している命令が未解決シンボルを含むか否かを判定する(ステップU3)。含まない場合はステップU5へ移行し、次の命令の処理に移る。
【0081】
未解決シンボルを含む場合には、シンボル情報テーブルの当該シンボル行の頻度欄に1を加える(ステップU4)。
【0082】
以上の処理を繰り返し、リンカに入力された全てのオブジェクトコードに対する各シンボルの頻度情報が得られる。
(配置最適化部122)
これは実施の形態1における配置最適化部22と同一である。
(記憶領域割り付け部123)
これは実施の形態1における記憶領域割り付け部23と同一である。
[プログラム処理装置の具体的な動作]
次に、実施の形態2における本プログラム処理装置の特徴的な構成要素の動作について、具体的な命令を用いて説明する。プログラムが3つに分割コンパイルされる場合について例を用いて説明する。この場合、ソースコードは3つ存在することになる。
【0083】
変換手段1については、従来のコンパイラと同等であるので動作については省略し、実施の形態1と同じ第1〜第3のソースコードを処理し、3つのオブジェクトコードが得られたとする。
【0084】
リンカの処理内容について説明する。まず、シンボル情報収集部120がコンパイラより出力された複数のオブジェクトファイル160〜161を読み込む。この際、シンボルが出現した順にシンボル情報テーブル124にエントリを生成し、リンク処理に必要な情報(オブジェクトサイズ、アライメント情報)を取り込む。これらの情報は一般にオブジェクトファイルに含まれる。この処理は従来のリンカでの処理と違いはないので詳細は省略する。この例では3つのオブジェクトコードが読み込まれ、図12(a)に示すシンボル情報テーブルに形成される。
【0085】
次に頻度測定部121が起動される。頻度測定部121は、シンボル情報収集部120が読み込んだ複数オブジェクトファイルのプログラム部分を調べ、各未解決シンボルの静的出現頻度を測定する。まず、シンボル情報テーブル124の頻度欄を0に初期化する(ステップU1、図12(b))。次にプログラム部分がある間未解決シンボルをサーチし、未解決シンボルが出現する度に対応する頻度欄に1を加える(ステップU2〜U5)。3つのオブジェクトコードに含まれるプログラム部分全ての処理が終った後のシンボル情報テーブル124は図12(c)の様になる。
【0086】
次に配置最適化部122、記憶領域割り付け部123が順に起動される。図12(c)は実施の形態1の図8(b)と全く同一なので、配置最適化部122、記憶領域割り付け部123での処理も実施の形態1での配置最適化部22、記憶領域割り付け部23での処理と同じ結果となり、最終的に、実施の形態1と同じ記憶領域割り付けが実現する。
[3.実施の形態3]
実施の形態1、2で示されるプログラム処理装置をフロッピーディスク、ハードディスク、CD―ROM、MOなどの記録媒体に入れることにより実施の形態1、2で示されるプログラム処理装置を、コンピューターで実現できる。
【0087】
【発明の効果】
以上の説明から明らかなように、本発明に係るプログラム処理装置は、高級言語で記述された複数のソースコードからなるプログラムを実行可能コードに変換する装置であって、ソースコードを目的コードに変換する変換手段1と、オブジェクトコードを実行可能コードに変換する変換手段2とを備え、変換手段2は前記未解決シンボルの出現回数が多い順に前記未解決シンボルに記憶領域を割り当てる記憶領域割り当て手段を備えることを特徴とする。
【0088】
これにより、ソースプログラム中の変数や副プログラムのうち頻繁に操作されるものが、基底アドレスに近い領域に配置されるので、これらを操作する命令のサイズが短縮され、結果、プログラム全体のコードサイズを圧縮することができる。
【0089】
ここで、前記変換手段1は未解決シンボルの出現手段を計測する計測手段1を含み、前記記憶領域割り当て手段は、前記計測手段1が計測した前記未解決シンボルの出現回数が多い順に前記未解決シンボルに記憶領域を割り当てるとすることができる。
【0090】
これによって、各ソースプログラム中の未解決シンボルの出現頻度がコンパイル時にコード生成と同時に計測されるので、記憶領域最適化機能を実現したリンク処理を、大きな付加時間なしに完了することができる。
【0091】
また、前記変換手段2が未解決シンボルの出現手段を計測する計測手段2を含み、前記記憶領域割り当て手段は、前記計測手段2が計測した前記未解決シンボルの出現回数が多い順に前記未解決シンボルに記憶領域を割り当てるとすることができる。
【0092】
これによって、プログラム中の未解決シンボルの出現頻度が既存のコンパイラの出力するオブジェクトコードから計測することができるようになるので、既存のコンパイラ及び既存のコンパイラが出力したオブジェクトコードを活用しつつ記憶領域配置の最適化を行ない、コードサイズの削減をすることが可能となる。
【0093】
また、前記記憶領域割り当て手段は、プログラムを構成する複数のソースコード全体に渡って有効な変数である前記未解決シンボルの出現回数が多い順に前記未解決シンボルに記憶領域を割り当てるとすることができる。
【0094】
これによって、頻繁に操作される外部変数に対する操作命令の命令サイズが短縮されるので、プログラム全体のコードサイズを削減することができる。
【0095】
また、前記記憶領域割り当て手段は、プログラムを構成する複数のソースコードのうち、いずれか1つのソースコードファイル全体に渡って有効な変数である前記未解決シンボルの出現回数が多い順に前記未解決シンボルに記憶領域を割り当てるとすることができる。
【0096】
これによって、頻繁に操作されるファイル内静的変数に対する操作命令の命令サイズが短縮されるので、プログラム全体のコードサイズを削減することができる。
【0097】
また、前記記憶領域割り当て手段は、プログラムを構成する複数のソースコードのうち、いずれか1つのソースコードのある一部で有効であり、且つ、プログラム実行中を通して値が保持される変数である前記未解決シンボルの出現回数が多い順に前記未解決シンボルに記憶領域を割り当てるとすることができる。
【0098】
これによって、頻繁に操作される静的変数に対する操作命令の命令サイズが短縮されるので、プログラム全体のコードサイズを削減することができる。
【0099】
また、前記記憶領域割り当て手段は、副プログラムである前記未解決シンボルの出現回数が多い順に前記未解決シンボルに記憶領域を割り当てるとすることができる。
【0100】
これによって、頻繁に呼び出される副プログラムに対する呼出命令の命令サイズが短縮されるので、プログラム全体のコードサイズを削減することができる。
【0101】
また本発明のプログラム処理装置は、前記指示手段は、前記記憶領域割り当て手段において前記未解決シンボルに割り当てられた記憶領域を絶対番地形式で操作する命令のコードサイズと前記命令の出現回数の積が、前記未解決シンボルに割り当てられた記憶領域を相対番地形式で操作する命令のコード回数と前記命令の出現回数の積と前記相対番地アドレスをレジスタに設定する命令のコードサイズとの和を上回る場合に、前記未解決シンボルを相対番地アドレス形式で操作する命令を生成するよう、前記変換手段1に指示し、前記変換手段1は、前記指示手段からの指示がある場合に、前記未解決シンボルを相対番地形アドレス式で操作する命令を生成するとすることができる。
【0102】
これによってアドレスを絶対番地形式より相対番地形式で表した方がコードサイズが小さくなる場合を的確に判断して、更にコードサイズを削減することができる。
【図面の簡単な説明】
【図1】本発明の第一の実施の形態を示すコンパイラ、リンカの構成及び関連するデータを示すブロック図
【図2】本プログラム処理装置のコード生成部11での処理手順を示すフローチャート
【図3】本プログラム処理装置の配置最適化部22での処理手順を示すフローチャート
【図4】本発明に係るプログラム処理装置が対象とする固定長命令セットの一例を示す図
【図5】本プログラム処理装置のコンパイラ上流部10が生成した内部形式コードの一例を示す図
【図6】生成途中のシンボル頻度情報テーブル14の一例を示す図
【図7】第1〜3のソースコードに対応するシンボル頻度情報ファイルの一例を示す図
【図8】処理途中のシンボル情報テーブル24の一例を示す図
【図9】配置最適化部22での処理が完了したシンボル情報テーブル24の一例を示す図
【図10】本発明の第二の実施の形態を示すコンパイラ、リンカの構成及び関連するデータを示すブロック図
【図11】本発明の第二の実施の形態におけるプログラム処理装置の頻度測定部121での処理手順を示すフローチャート
【図12】シンボル情報収集部120で生成されたシンボル情報テーブル124の一例を示す図
【図13】従来のプログラム処理装置の構成及び関連データを示すブロック図
【図14】従来のプログラム処理装置におけるシンボル情報収集部902処理完了後のシンボル情報テーブル980の一例を示す図
【符号の説明】
1 コンパイラ
2 リンカ
10 コンパイラ上流部
11 コード生成部
12 頻度情報出力部
13 頻度測定部
14 シンボル頻度情報テーブル
20 シンボル情報収集部
21 頻度情報入力部
22 配置最適化部
23 記憶領域割り付け部
24 シンボル情報テーブル
50、51 ソースコード
60、61 オブジェクトコード
70 実行可能コード
80、81 シンボル頻度情報
101 コンパイラ
102 リンカ
110 コンパイラ上流部
111 コード生成部
120 シンボル情報収集部
121 頻度測定部
122 配置最適化部
123 記憶領域割り付け部
124 シンボル情報テーブル
150 ソースコード
160、161 オブジェクトコード
170 実行可能コード
900 コンパイラ上流部
901 コード生成部
902 シンボル情報収集部
903 記憶領域割り付け部
950 ソースコード
960、961 オブジェクトコード
970 実行可能コード
980 シンボル情報テーブル
[0001]
BACKGROUND OF THE INVENTION
The present invention relates to a program processing apparatus and a recording medium including a compiler that generates object code from a high-level language, and a linker that generates a executable code by concatenating and editing a plurality of object codes. The present invention relates to a code optimization technique for reducing the code size of an executable code, and a technique for arranging variables and programs in a storage area.
[0002]
[Prior art]
In recent years, programs to be processed by a microcomputer have become more complex and sophisticated. Along with this, a method is often used in which a program is created in a high-level language such as C language and then converted into a format that can be executed by a microcomputer by a compiler and a linker.
[0003]
Especially in recent years when the program is becoming enormous, the program is divided into several source code files from the viewpoint of development efficiency, and these are compiled separately and then linked and edited by the linker to generate the final machine language code. Separate compilation is generally used.
[0004]
The cooperation between the compiler and the linker in this divided compilation is important.
[0005]
The conventional compiler and linker will be described below.
Japanese Patent Application Laid-Open No. 9-212369 describes a technique for checking the size of variables used at the time of compiling and arranging the variables on a memory after arranging them in order of increasing size. As a result, the sum of offsets from the base address is kept to a minimum, so that the storage area can be reduced. This publication also describes a method of using profile information to arrange variables on a memory after arranging variables in the order in which the number of dynamic accesses is large, that is, in the order in which the number of executions is large. As a result, a variable with a large number of accesses can be accessed with a small offset, and an access instruction size for a variable with a large number of accesses is reduced, resulting in a reduction in code size.
[0006]
[Problems to be solved by the invention]
However, the conventional method has a problem in that optimal memory allocation cannot be realized from the viewpoint of code size reduction when divided compilation is performed.
[0007]
That is, since there is only one external variable or static variable in the final machine language code, it is not possible to realize the optimum arrangement in the final machine language code by the alignment in each file.
[0008]
In addition, the alignment based on the dynamic access number obtained from the profile information generally provides a result different from the alignment based on the number of appearances of the memory operation instructions in the program. In order to reduce the code size, it is clear that the code size of the entire program will be smaller if the code size of the program has a large number of instructions, that is, if the code size of the instruction with many occurrences in the program is reduced. There is room for code size improvement.
[0009]
Furthermore, in order to obtain profile information, the compiler needs to generate code for obtaining the profile, which increases the compilation time and storage capacity required for compilation, and pre-executes the program to obtain the profile. As a result, the program development period increases.
[0010]
Further, in the above method, no consideration is given to the arrangement of the program modules, so that the subprogram call instruction is not optimized at all.
[0011]
The present invention has been made in view of such problems, and realizes optimal storage area allocation of variables even for a separately compiled program without preliminary execution of the program, and optimal program allocation. Accordingly, an object of the present invention is to provide a program processing device and a recording medium that can reduce the final code size.
[0012]
[Means for Solving the Problems]
  The program processing apparatus of the present invention
An apparatus for converting a program composed of a plurality of source codes described in a high-level language into executable code,
  SaidpluralSource codepluralConvert to object codeFirstConversion handStepped,
  SaidpluralConvert object code into the executable codeSecondConversion handSteppedWith
  The first converting means includes a measuring means for measuring the number of appearances of unresolved symbols included in the plurality of object codes when the plurality of source codes are converted into the plurality of object codes,
SaidSecondConversion handStage,
SaidIn order of appearance of unresolved symbolsIncluded in the plurality of object codesA storage area assigning means for assigning a storage area to the unresolved symbol is provided.
[0015]
  In the program processing device of the present invention, the storage area allocating means is a program.The value is preserved throughout the runA storage area may be allocated to the unresolved symbols in descending order of the number of appearances of the unresolved symbols that are variables.
[0018]
Further, the program processing apparatus of the present invention is characterized in that the storage area allocating means allocates storage areas to the unresolved symbols in descending order of the number of occurrences of the unresolved symbols whose entities are subprograms. .
[0019]
  The program processing apparatus of the present inventionFirstConversion handStageThe measuring handStepsIncluding frequency information output means for outputting the frequency of occurrence of the measured unresolved symbol as a frequency information file,SecondConversion handStageAnd a frequency information input unit that receives the plurality of frequency information files output by the frequency information output unit and totals the frequency for each of the unresolved symbols.
[0020]
  Moreover, the program processing device of the present invention provides the aboveFirstConversion handStageThe measuring handStepsIncluding object code output means for outputting the measured number of occurrences of the unresolved symbol added to the object code,SecondConversion handStage, Including frequency information input means for receiving the plurality of object codes output by the object code output means, taking out the number of appearances added to the object code, and totaling the frequency for each unresolved symbol be able to.
[0022]
  In the program processing device of the present invention, the instruction means may obtain a product of a code size of an instruction that operates the storage area assigned to the unresolved symbol in the storage area assignment means in an absolute address format and the number of appearances of the instruction. , A code of an instruction for operating a storage area allocated to the unresolved symbol in a relative address formatsizeAnd the number of occurrences of the instruction and the relative numberThe earthIn order to generate an instruction for operating the unresolved symbol in a relative address format when the sum of the code size of the instruction set in the register is exceeded.FirstConversion handIn stepsInstruct and saidFirstConversion handStageWhen there is an instruction from the instruction means, the unresolved symbol is set as a relative address.formatIt is possible to generate an instruction to be operated on.
[0023]
  The recording medium of the present invention is a recording medium recording a program for converting a program composed of a plurality of source codes written in a high-level language into an executable code,pluralSource codepluralChange to object codeA first step including a measurement step of measuring the number of appearances of unresolved symbols included in the plurality of object codes whenConversion stepAndThe abovepluralConvert object code into the executable codeAnd a second storage area allocation step of allocating a storage area to the unresolved symbols included in the plurality of object codes in descending order of the number of appearances of the unresolved symbols.Conversion stepTheIt is possible to record a program to be executed by a computer.
[0024]
DETAILED DESCRIPTION OF THE INVENTION
Hereinafter, a program processing apparatus and a recording medium according to the present invention will be described with reference to the drawings.
[Explanation of terms]
First, terms used in this description will be explained.
・ Subprogram
A program called from the main routine. Specifically, it refers to a function or subroutine.
・ Unresolved symbols
A symbol that is not fixed until the object code is linked and edited. There are external variables and external labels (start addresses of subprograms).
·object
The entity that the symbol represents. For example, when C language is used as the high-level language, when A is a LONG type external variable, the entity is an 8-byte memory.
·section
Distinguishing when placing objects during concatenation editing. Objects in the same section are arranged together. Generally, a program is arranged as a code section and variables are arranged as a data section.
[1. Embodiment 1]
[Configuration of program processing device]
FIG. 1 is a block diagram showing the configuration of the program processing apparatus and related data.
[0025]
This program processing apparatus is roughly divided into two groups: (1) a group that generates object code 60 from source code 50 written in a high-level language (compiler upstream unit 10, code generation unit 11, frequency information output unit 12, (2) a group that concatenates and edits a plurality of object codes 60 to 61 to generate a final executable code 70 (symbol information collection unit 20, frequency information) A conversion unit 2 including an input unit 21, an arrangement optimization unit 22, and a storage area allocation unit 23, hereinafter referred to as a linker).
(Upstream compiler 10)
The compiler upstream section 10 reads the high-level language source code 50 stored in the file format, performs syntax analysis and semantic analysis, and generates an internal format code. Furthermore, as necessary, the internal format code is optimized so that the size of the executable code finally generated and the execution time thereof are shortened. The processing here is the same as the processing by the upstream compiler portion of the conventional compiler.
(Code generator 11)
The code generation unit 11 generates the object code 60 from the internal format code generated and optimized by the compiler upstream unit 10. Here, the “object code” is a machine language program for the target machine including relocatable information. The code generation unit 11 includes a frequency measurement unit 13. The frequency measurement unit 13 accesses the symbol frequency information table 14 and updates the appearance frequency of symbols when an unresolved symbol is included in the code generated by the code generation unit.
[0026]
Details of the processing of the code generation unit 11 are as follows.
FIG. 2 is a flowchart showing a processing procedure in the code generation unit 11.
[0027]
The code generation unit 11 repeats the following processing (steps S2 to S6) for all instructions of the internal format code generated by the compiler upstream unit 10 (steps S1 and S7).
[0028]
  First, the code generation unit 11 selects the internal format codeIn orderCorresponding machine language code instruction(Hereinafter, simply referred to as “target instruction”.)Is generated (step S2).
[0029]
Next, it is determined whether or not the instruction of interest includes an unresolved symbol (step S3). If an unresolved symbol is included, it is further determined whether or not the unresolved symbol has already been registered in the symbol frequency information table (step S4).
[0030]
If the unresolved symbol is not registered in the symbol frequency information table, an entry corresponding to the unresolved symbol is created in the symbol frequency information table (step S5). At that time, the use frequency of the symbol is initialized to zero.
[0031]
Next, 1 is added to the frequency of use of the symbol, and the symbol frequency information table is updated (step S6).
[0032]
In FIG. 2, a portion surrounded by a dotted line corresponds to the processing of the frequency measurement unit 13 included in the code generation unit 11.
(Frequency information output unit 12)
Returning to FIG. 1, the frequency information output unit 12 reads the symbol frequency information table 14 and outputs it as a symbol frequency information file 80.
[0033]
As described above, the object code 60 and the symbol frequency information file 80 corresponding to the source code 50 are generated from the source code 50 by the processing of the compiler 1. When there are a plurality of source codes, the object code 60 and 61 and the symbol frequency information files 80 and 81 corresponding to the source code 50 and 51 are generated by performing the processing of the compiler 1 for the source codes 50 and 51, respectively.
(Symbol information collection unit 20)
The symbol information collection unit 20 reads a plurality of object codes 60 to 61 and collects symbol information. Further, a symbol information table 24 is generated based on the collected symbol information. The processing here is the same as the processing performed by the symbol information collection unit of the conventional linker. Further, the generated symbol information table 24 is not different from the symbol information table 24 generated by the conventional linker at this stage.
(Frequency information input unit 21)
The frequency information input unit 21 reads the symbol frequency information files 80 to 81 output from the frequency information output unit 12 of the compiler 1. Symbol frequency information is added to the corresponding entry of the symbol information table 24 generated by the symbol information collection unit 20.
(Placement optimization unit 22)
The arrangement optimization unit 22 refers to the symbol information table 24 and optimizes the memory arrangement of variables. Specifically, paying attention to the frequency of use of symbols, variables with high frequency of use are arranged at positions close to the base address of the storage area. As a result, it is expected that the code for the frequently accessed memory is reduced, so that the code size as a whole can be reduced.
[0034]
Details of the processing of the placement optimization unit 22 are as follows.
FIG. 3 is a flowchart showing a processing procedure in the arrangement optimization unit 22.
[0035]
First, the arrangement optimization unit 22 arranges the symbol information tables in descending order of frequency (step T1). Alignment is done for each section.
[0036]
Next, an allocatable memory location used in the following processing is initialized to the top of the allocatable memory (step T2). A plurality of allocatable memory locations are prepared depending on the number of sections. In the present embodiment, two external and static variable allocable memory locations (hereinafter referred to as variable allocable memory locations) and program allocable memory locations are used.
[0037]
Next, while there is an allocation target according to the symbol information table, the layout optimization unit 22 repeats the following processing (steps T4 to T5) in the order arranged in step T1 (steps T3 and T6).
[0038]
An unresolved symbol is allocated to an allocatable memory location, and the allocated memory location is registered in the symbol information table 24 (step T4). At this time, if the unresolved symbol to be allocated is a variable, a variable allocatable memory location is used, and if it is a program, the program allocatable memory location is used.
[0039]
Next, the allocatable memory location is updated according to the size of the object allocated in step T4 (step T5). Specifically, the size of the object allocated in step T4 is added to the current allocatable memory location to obtain a new allocatable memory location. When the memory alignment is restricted due to the restriction of the target machine, the new allocatable memory location is adjusted in consideration of this. At this time, if the unresolved symbol assigned in step T4 is a variable, the variable allocatable memory location is updated, and if it is a program, the program allocatable memory location is updated.
(Storage area allocation unit 23)
Returning to FIG. 1, the storage area allocating unit 23 actually allocates the memory according to the content determined by the layout optimization unit 22 and generates the final executable code 70. The generated executable code 70 is written out as a file.
[Specific operation of program processing device]
Next, operations of characteristic components of the program processing apparatus will be described using specific instructions.
[0040]
First, the target machine targeted by the program processing apparatus will be described. In general, in a fixed-length instruction architecture, a memory range that can be accessed by one instruction is limited. FIG. 4A shows an example of a memory access instruction in the fixed-length instruction architecture. In a target machine having such a memory access instruction, the width for expressing an address for designating a memory is only 16 bits, and therefore, only an area of 65536 bytes from address 0 to address 65535 can be represented by one instruction ( Arrow a1). Memory exceeding this range must be expressed by two or more instructions (arrow a2). The subprogram call instruction can only be directly called up to a certain range (arrow a3). On the other hand, there are similar limitations in variable-length instruction architectures. FIG. 4B shows an example of an instruction in the variable length instruction architecture. In this example, a 2-byte instruction can access an address width of 8 bits, that is, an area of 256 bytes from address 0 to address 255 (arrow a4). Similarly, an area up to address 65535 (arrow a5) can be accessed with a 3-byte instruction, and address 4294967295 can be accessed with a 4-byte instruction (arrow a6). That is, in the variable-length architecture, all memory areas can be accessed with one instruction, but the code size increases as the accessed area moves away from address 0. Even in the case of a call instruction for a subprogram, a call instruction for a larger memory area is larger than the instruction size (arrows a7 and a8). Here, an absolute address format memory access instruction is taken as an example, but the same can be said even if this is a relative address format. In the case of the relative address format, the difference is that the reference is not the address 0 but the value of the base register, and the required code size increases as the distance from the base register increases.
[Example]
A case where a program is divided and compiled into three will be described with reference to an example. In this case, there are three source codes.
[0041]
First, the first source code is compiled. The source code input to the compiler is processed by the compiler upstream unit 10 and converted into an internal format code. Here, it is assumed that the internal format code of FIG. The internal format code is then input to the code generator 11. The operation of the code generation unit 11 will be described along the flowchart shown in FIG.
[0042]
The code generation unit 11 repeats steps S1 to S7 while there is an internal format code.
[0043]
First, the instruction c1 is converted into the machine language code m1 shown in FIG. 5B (step S2).
[0044]
Subsequently, it is determined whether or not this instruction includes an unresolved symbol (step S3). Since the symbol memory1 included in the machine language code m1 is an unresolved symbol, it is determined as Yes.
[0045]
Next, it is determined whether this symbol is already registered in the symbol frequency information table 14 (step S4). Since this machine language code m1 is the first instruction for processing this source code, nothing is registered in the symbol frequency information. For this reason, this branch is determined to be No.
[0046]
Next, the unresolved symbol memory1 is registered in the symbol frequency information table (step S5). Specifically, a symbol memory1 field is created in the symbol frequency information table 14 and the frequency is initialized to 0 (FIG. 6A).
[0047]
Finally, 1 is added to the usage frequency of the symbol memory1 currently handled, and the symbol frequency information table is updated (step S6). The symbol frequency information table 14 is as shown in FIG.
[0048]
The above steps are repeated while there is an internal format code (step S7).
The contents of the symbol frequency information table immediately after the internal format codes c2 and c3 are processed are shown in FIGS. 6 (c) and 6 (d). The internal format codes c2 and c3 are converted into machine language codes m2 and m3, respectively. FIG. 6E shows the contents of the symbol frequency information table after the processing of the first source code is completed. Here, the break above function1 in FIGS. 6 (d) and 6 (e) indicates that the symbol frequency information for the variable is above and the symbol frequency information for the subprogram is below. These form sections for variables and programs, respectively.
[0049]
When the process of the code generation unit 11 is finished, the control moves to the frequency information output unit 12. The frequency information output unit 12 refers to the symbol frequency information table and outputs the contents as a symbol frequency information file 80. The contents of the symbol information file 80 corresponding to the first source code are shown in FIG.
[0050]
Similar processing is performed for the second and third source codes. Assume that the contents of the symbol frequency information file corresponding to the second and third source codes are as shown in FIGS. Here, the break above function1 in FIGS. 7A to 7C indicates that the symbol frequency information for the variable is shown above and the symbol frequency information for the subprogram is shown below.
[0051]
Next, the processing contents of the linker will be described. First, the symbol information collection unit 20 reads a plurality of object files 60 to 61 output from the compiler. At this time, entries are generated in the symbol information table 24 in the order in which the symbols appear, and information (object size and alignment information) necessary for the link processing is taken in. Such information is generally contained in an object file. Since this processing is not different from the processing by the conventional linker, the details are omitted. In this example, three object codes corresponding to three source codes are read and formed in the symbol information table shown in FIG.
[0052]
Next, the frequency information input unit 21 is activated. The frequency information input unit 21 reads a plurality of symbol frequency information files 80 to 81 corresponding to the object file read by the symbol information collection unit 20, and reads the read frequency information in the frequency column of each symbol entry in the symbol information table 24. Add the values described in the file. In this example, the three symbol frequency information files shown in FIGS. 7A, 7B, and 7C are read. As a result, the symbol information table is as shown in FIG.
[0053]
When the processing of the frequency information input unit 21 is finished, the arrangement optimization unit 22 is activated. The operation of the placement optimization unit 22 will be described with reference to the flowchart shown in FIG.
[0054]
First, the symbol information table is arranged (sorted) in the order of the frequency number for each section (step T1). The sections are divided by a break above the function1 column in FIGS. 8A, 8B, and 8C, and there are two sections in total. As a result, the symbol information table 24 is as shown in FIG.
[0055]
Next, an allocatable memory location is initialized (step T2). Here, it is assumed that the program allocable memory location is initialized to address 0xF000 and the variable allocable memory location is initialized to 0x00F0. 0x indicates that the subsequent numerical value is in hexadecimal notation. The same applies to the following.
[0056]
While there are objects to be allocated, steps T4 to T5 are repeated (steps T3 and T6).
[0057]
Next, an unresolved symbol is allocated to the memory (step T4). Since the unresolved symbol at the top of the symbol information table is memory 3, it is assigned to address 0x00F0.
[0058]
Finally, the allocatable memory location is updated according to the size of the allocated object (step T5). Here, since the size of memory1 is 0x0008, the allocatable memory location is 0x00F8.
[0059]
While the allocation target remains, the above steps T3 to T6 are repeatedly executed. The allocation operation for the remaining objects will be briefly described.
[0060]
The second unresolved symbol is memory2. This is allocated to address 0x00F8 (step T4), and the allocatable memory location is updated to 0x0100 by adding the object size 0x0008 of memory2 (step T5).
[0061]
The third unresolved symbol is memory1. This is allocated to address 0x0100 (step T4), and the allocatable memory location is updated to 0x0108 by adding the object size 0x0008 of memory1 (step T5).
[0062]
The fourth unresolved symbol is function2. Since this is a program, it is allocated to address 0xF000 with reference to the program allocable memory location (step T4). The allocatable memory location is updated to 0xF120 by adding the object size 0x0120 of function2 (step T5).
[0063]
The fifth unresolved symbol is function1. Since this is also a program, it is assigned to address 0xF120 (step T4), and the allocatable memory location is updated to 0x11254 by adding the object size 0x2134 of function1 (step T5).
[0064]
The symbol information table at the end of the placement optimization unit 22 is as shown in FIG.
Finally, the storage area allocating unit 23 rewrites the unresolved symbol in the input object code with the arrangement destination address according to the contents of the symbol information table 24. This process is the same as that of the conventional linker.
[0065]
The final executable code is obtained by the above processing. In this example, executable code is generated by concatenating and editing three object codes generated from three source codes. Part of the generated executable code is shown in FIG. FIG. 5C shows a portion of the executable code corresponding to the first source code shown in FIGS. 5A and 5B expressed in mnemonics. In addition to this, the actual executable code includes portions corresponding to the second and third source codes. As can be seen from comparison with FIG. 5B, it can be seen that the unresolved symbols in FIG. 5B are replaced with actual memory addresses determined in the symbol information table (FIG. 9).
[0066]
Next, the code size of the executable code generated based on the first embodiment is shown. Assuming the variable length instruction architecture of FIG. 4B as the architecture of the target machine, the access instruction to the memory memory 3 that is most frequently accessed in the entire program including all of the first, second, and third source codes is Since memory memory 3 is located at address 0x00F0, it becomes a 2-byte instruction, and the total code of the memory access instruction is 20 bytes. Considering all the memory access instructions, in the first embodiment, 2 × 10 + 2 × 6 + 4 × 5 = 52 bytes.
[0067]
Also, in the arrangement of subprograms, calling function1 is a 4-byte instruction because function1 is allocated from address 0xF120, and calling function2 is also a 4-byte instruction because function2 is allocated from address 0xF000, and the entire calling instruction is 4 × 5 + 4. X7 = 48 bytes.
[0068]
In order to show the size of each instruction, FIG. 5C shows the code size of the portion corresponding to the first source code on the right side of each instruction mnemonic. The code size of the portion corresponding to the first source code is 30 bytes.
[0069]
In this embodiment, the content of the symbol frequency information table 14 is output as the frequency information file 80 and passed to the linker. However, the content of the symbol frequency information table 14 is added to the object code 60 generated by the code generation unit 11. You may hand it over to the linker.
[0070]
Further, as in the access instruction to memory1, the product (20 bytes) of the instruction code size (4 bytes) and the appearance frequency (5 times) is the code size of the relative address address format memory access instruction to memory1 (2 bytes, FIG. 4). (B) Sum of product (10 bytes) of arrow a9) and appearance frequency (5 times) and setting instruction to relative address address base register (6 bytes, FIG. 4 (b) arrow a10) (16 bytes) May exceed the above, the code generation unit 11 may be instructed to output the corresponding unresolved symbol (in this case, memory1) in the relative address format, and may be repeated from the code generation. This can further reduce the code size.
[Comparison with conventional program processing devices]
With the above processing, a final executable code is obtained. In order to clearly show the features of the present invention, a comparison is made with the case of a conventional program processing apparatus (compiler and linker).
[0071]
FIG. 13 is a block diagram showing the configuration of a conventional program processing apparatus in comparison with the embodiment of the present invention.
[0072]
This program processing apparatus does not include the frequency measurement unit 13, the frequency information output unit 12, the frequency information input unit 21, and the arrangement optimization unit 22 according to the present embodiment. Therefore, there is no means for obtaining the appearance frequency of unresolved symbols appearing in a plurality of object files, and when the linker performs processing, the memory is allocated in the order of appearance of the unresolved symbols. Therefore, the memory allocated to each symbol when the first to third source codes are processed is as shown in FIG. In FIG. 14, the appearance frequency is added for the following comparison, but the appearance frequency column does not exist in the conventional configuration.
[0073]
Next, the code size of the executable code generated based on the conventional program processing apparatus is shown. As in the first embodiment, assuming the variable-length instruction architecture of FIG. 4B as the architecture of the target machine, the most frequently accessed access instruction to the memory memory3 is that memory3 is arranged at address 0x0100. Since this is a 4-byte instruction and this instruction appears 10 times, the total code of the access instruction to this memory is 40 bytes. This is an increase of 20 bytes from the result of the program processing apparatus of the first embodiment. In consideration of all the memory access instructions, in the conventional example, 2 × 5 + 2 × 6 + 4 × 10 = 62 bytes, which is an increase of 10 bytes compared with 52 bytes which is the result in the first embodiment.
[0074]
Also, the same effect appears in the arrangement of subprograms. In the conventional example, the function 1 call is a 2-byte instruction because function 1 is allocated from address 0xF000, and the function 2 call is a 4-byte instruction because function 2 is allocated from address 0x11134. The entire call instruction is 4 × 5 + 6 × 7 = 62 bytes. It becomes. On the other hand, in the first embodiment, the code size of the entire call instruction is 48 bytes, so in the conventional example, the code size is increased by 14 bytes compared to the first embodiment.
[0075]
Even when a conventional program processing device is equipped with means for allocating storage areas for automatic variables based on the size of variables or the frequency of dynamic use, external variables of a program divided into a plurality of files as shown in this example Needless to say, storage area allocation cannot be optimized.
[2. Second Embodiment]
[Configuration of program processing device]
FIG. 10 is a block diagram showing a configuration and related data in the second embodiment of the program processing apparatus.
[0076]
This program processing apparatus is roughly divided into two groups: (1) a group for generating object code 160 from source code 150 written in a high-level language (compiler 101 including compiler upstream section 110 and code generation section 111); (2) A group that concatenates and edits a plurality of object codes 160 to 161 to generate a final executable code 170 (a linker comprising a symbol information collection unit 120, a frequency measurement unit 121, a layout optimization unit 122, and a storage area allocation unit 123) 102).
(Upstream compiler part 110)
This is the same as the compiler upstream section 10 in the first embodiment.
(Code generator 111)
The code generation unit 111 generates the object code 160 from the internal format code generated and optimized by the compiler upstream unit 110. Here, the “object code” is a machine language program for the target machine including relocatable information.
(Symbol information collection unit 120)
This is the same as the symbol information collection unit 20 in the first embodiment.
(Frequency measuring unit 121)
The frequency measuring unit 121 searches the plurality of object codes 160 to 161 read by the symbol information collecting unit 120 and measures the appearance frequency of each symbol in the symbol information table 124 generated by the symbol information collecting unit 120.
[0077]
Details of the processing of the frequency measurement unit 121 are as follows.
FIG. 11 is a flowchart showing a processing procedure in the frequency measurement unit 121.
[0078]
First, the frequency measurement unit 121 initializes all the frequency fields of the symbol information table 124 with 0 (step U1).
[0079]
Next, while there is a portion corresponding to the program in the object code, the following processing (steps U3 to U4) is repeated (steps U2 and U5).
[0080]
First, it is determined whether or not the currently processed instruction includes an unresolved symbol (step U3). If not included, the process proceeds to step U5 and the process of the next instruction is performed.
[0081]
When an unresolved symbol is included, 1 is added to the frequency column of the symbol line in the symbol information table (step U4).
[0082]
The above processing is repeated to obtain frequency information of each symbol for all object codes input to the linker.
(Placement optimization unit 122)
This is the same as the placement optimization unit 22 in the first embodiment.
(Storage area allocation unit 123)
This is the same as the storage area allocation unit 23 in the first embodiment.
[Specific operation of program processing device]
Next, operations of characteristic components of the program processing apparatus according to the second embodiment will be described using specific instructions. A case where a program is divided and compiled into three will be described with reference to an example. In this case, there are three source codes.
[0083]
Since the conversion means 1 is equivalent to a conventional compiler, its operation is omitted, and the same first to third source codes as in the first embodiment are processed and three object codes are obtained.
[0084]
The processing contents of the linker will be described. First, the symbol information collection unit 120 reads a plurality of object files 160 to 161 output from the compiler. At this time, entries are generated in the symbol information table 124 in the order in which the symbols appear, and information (object size and alignment information) necessary for the link processing is taken in. Such information is generally contained in an object file. Since this processing is not different from the processing by the conventional linker, the details are omitted. In this example, three object codes are read and formed in the symbol information table shown in FIG.
[0085]
Next, the frequency measurement unit 121 is activated. The frequency measuring unit 121 examines the program part of the multiple object file read by the symbol information collecting unit 120 and measures the static appearance frequency of each unresolved symbol. First, the frequency column of the symbol information table 124 is initialized to 0 (step U1, FIG. 12B). Next, an unresolved symbol is searched while there is a program part, and 1 is added to the corresponding frequency column every time an unresolved symbol appears (steps U2 to U5). The symbol information table 124 after the processing of all the program parts included in the three object codes is as shown in FIG.
[0086]
Next, the arrangement optimization unit 122 and the storage area allocation unit 123 are activated in order. Since FIG. 12C is exactly the same as FIG. 8B of the first embodiment, the processing in the placement optimization unit 122 and the storage area allocation unit 123 is also performed in the placement optimization unit 22 and the storage area in the first embodiment. The result is the same as the processing in the allocation unit 23, and finally, the same storage area allocation as that of the first embodiment is realized.
[3. Embodiment 3]
By inserting the program processing apparatus shown in the first and second embodiments into a recording medium such as a floppy disk, a hard disk, a CD-ROM, and an MO, the program processing apparatus shown in the first and second embodiments can be realized by a computer.
[0087]
【The invention's effect】
As is apparent from the above description, the program processing device according to the present invention is a device that converts a program composed of a plurality of source codes described in a high-level language into executable code, and converts the source code into a target code. Conversion means 1 that converts the object code into executable code, and the conversion means 2 includes storage area allocation means that assigns storage areas to the unresolved symbols in descending order of the number of appearances of the unresolved symbols. It is characterized by providing.
[0088]
As a result, variables and subprograms that are frequently manipulated in the source program are placed in an area close to the base address, so the size of the instruction that manipulates them is reduced, resulting in the code size of the entire program. Can be compressed.
[0089]
Here, the conversion unit 1 includes a measurement unit 1 that measures an appearance unit of unresolved symbols, and the storage area allocation unit is configured to determine the unresolved order in descending order of the number of appearances of the unresolved symbols measured by the measurement unit 1. A storage area can be allocated to the symbol.
[0090]
As a result, the frequency of appearance of unresolved symbols in each source program is measured at the same time as code generation at the time of compilation, so that the link processing that realizes the storage area optimization function can be completed without much additional time.
[0091]
In addition, the conversion unit 2 includes a measurement unit 2 that measures an appearance unit of an unresolved symbol, and the storage area allocation unit includes the unresolved symbols in descending order of the number of appearances of the unresolved symbols measured by the measurement unit 2. It is possible to allocate a storage area.
[0092]
As a result, the appearance frequency of unresolved symbols in the program can be measured from the object code output by the existing compiler, so the storage area can be used while utilizing the existing compiler and the object code output by the existing compiler. It is possible to reduce the code size by optimizing the arrangement.
[0093]
Further, the storage area allocating means may allocate the storage areas to the unresolved symbols in descending order of the number of occurrences of the unresolved symbols that are valid variables over a plurality of source codes constituting the program. .
[0094]
As a result, the instruction size of the operation instruction for the external variable that is frequently operated is shortened, so that the code size of the entire program can be reduced.
[0095]
Further, the storage area allocating means is configured to determine the unresolved symbols in descending order of the number of occurrences of the unresolved symbols that are valid variables over the entire source code file among a plurality of source codes constituting the program. It is possible to allocate a storage area.
[0096]
As a result, the instruction size of the operation instruction with respect to the in-file static variable that is frequently operated is reduced, so that the code size of the entire program can be reduced.
[0097]
Further, the storage area allocating means is a variable that is valid in a part of any one of the plurality of source codes constituting the program and that holds a value throughout the execution of the program. A storage area can be allocated to the unresolved symbols in descending order of the number of appearances of the unresolved symbols.
[0098]
As a result, the instruction size of the operation instruction for the frequently operated static variable is shortened, so that the code size of the entire program can be reduced.
[0099]
Further, the storage area allocating means can allocate storage areas to the unresolved symbols in descending order of the number of appearances of the unresolved symbols that are subprograms.
[0100]
As a result, the instruction size of the calling instruction for the frequently called subprogram is shortened, so that the code size of the entire program can be reduced.
[0101]
In the program processing device of the present invention, the instruction means may obtain a product of a code size of an instruction that operates the storage area assigned to the unresolved symbol in the storage area assignment means in an absolute address format and the number of appearances of the instruction. , When the sum of the code number of the instruction that operates the storage area allocated to the unresolved symbol in the relative address format and the number of times the instruction appears and the code size of the instruction that sets the relative address in the register The conversion means 1 is instructed to generate an instruction for operating the unresolved symbol in a relative address format, and the conversion means 1 converts the unresolved symbol into the unresolved symbol when there is an instruction from the instruction means. It is possible to generate a command to operate with a relative number terrain address formula.
[0102]
This makes it possible to accurately determine when the code size is smaller when the address is expressed in the relative address format than in the absolute address format, and the code size can be further reduced.
[Brief description of the drawings]
FIG. 1 is a block diagram showing a configuration of a compiler and a linker and related data according to a first embodiment of the present invention.
FIG. 2 is a flowchart showing a processing procedure in the code generation unit 11 of the program processing apparatus.
FIG. 3 is a flowchart showing a processing procedure in the layout optimization unit 22 of the program processing apparatus.
FIG. 4 is a diagram showing an example of a fixed-length instruction set targeted by the program processing apparatus according to the present invention.
FIG. 5 is a diagram showing an example of an internal format code generated by the compiler upstream unit 10 of the program processing apparatus.
FIG. 6 is a diagram showing an example of a symbol frequency information table 14 in the process of generation
FIG. 7 is a diagram showing an example of a symbol frequency information file corresponding to first to third source codes.
FIG. 8 is a diagram showing an example of a symbol information table 24 during processing
FIG. 9 is a diagram showing an example of a symbol information table 24 that has been processed by the placement optimization unit 22;
FIG. 10 is a block diagram illustrating a configuration of a compiler and a linker and related data according to a second embodiment of the present invention.
FIG. 11 is a flowchart showing a processing procedure in the frequency measurement unit 121 of the program processing device according to the second embodiment of the present invention.
12 is a diagram illustrating an example of a symbol information table 124 generated by the symbol information collection unit 120. FIG.
FIG. 13 is a block diagram showing a configuration and related data of a conventional program processing apparatus.
FIG. 14 is a diagram showing an example of a symbol information table 980 after completion of processing by a symbol information collection unit 902 in a conventional program processing apparatus.
[Explanation of symbols]
1 Compiler
2 Linker
10 Compiler upstream
11 Code generator
12 Frequency information output section
13 Frequency measurement section
14 Symbol frequency information table
20 Symbol information collection department
21 Frequency information input section
22 Placement optimization section
23 Storage area allocation part
24 Symbol information table
50, 51 source code
60, 61 Object code
70 Executable code
80, 81 symbol frequency information
101 compiler
102 Linker
110 Compiler upstream
111 Code generator
120 Symbol information collection unit
121 Frequency measurement unit
122 Placement optimization unit
123 Storage area allocation unit
124 Symbol information table
150 source code
160, 161 Object code
170 Executable code
900 Compiler upstream
901 Code generator
902 Symbol information collection unit
903 Storage area allocation unit
950 source code
960, 961 Object code
970 executable code
980 symbol information table

Claims (7)

高級言語で記述された複数のソースコードからなるプログラムを実行可能コードに変換する装置であって、
前記複数のソースコードを複数のオブジェクトコードに変換する第1の変換手段と
前記複数のオブジェクトコードを前記実行可能コードに変換する第2の変換手段とを備え、
前記第1の変換手段は、前記複数のソースコードを前記複数のオブジェクトコードに変換する時に、前記複数のオブジェクトコードに含まれる未解決シンボルの出現回数を計測する計測手段を含み、
前記第2の変換手段は
前記未解決シンボルの出現回数が多い順に前記複数のオブジェクトコードに含まれる前記未解決シンボルに記憶領域を割り当てる記憶領域割り当て手段を備えたことを特徴とするプログラム処理装置。
An apparatus for converting a program composed of a plurality of source codes described in a high-level language into executable code,
A first conversion means to convert said plurality of source code into a plurality of object codes,
And a second conversion means to convert said plurality of object code to the executable code,
The first converting means includes a measuring means for measuring the number of appearances of unresolved symbols included in the plurality of object codes when the plurality of source codes are converted into the plurality of object codes,
The second conversion hand stage,
Program processing apparatus characterized by having a storage area allocation means for allocating a storage area in the unresolved symbols the included in the plurality of object codes in the order number of occurrences of unresolved symbols often.
前記記憶領域割り当て手段は、プログラム実行中を通して値が保持される変数である前記未解決シンボルの出現回数が多い順に、前記未解決シンボルに記憶領域を割り当てることを特徴とする請求項1に記載のプログラム処理装置。The storage region assignment unit, the sequentially number of occurrences of unresolved symbols often value throughout the program execution is a variable that is held, according to claim 1, characterized in that allocating a storage area in the unresolved symbol Program processing device. 前記記憶領域割り当て手段は、副プログラムである前記未解決シンボルの出現回数が多い順に、前記未解決シンボルに記憶領域を割り当てることを特徴とする請求項1に記載のプログラム処理装置。The program processing apparatus according to claim 1, wherein the storage area allocating unit allocates storage areas to the unresolved symbols in descending order of the number of appearances of the unresolved symbols that are subprograms. 前記第1の変換手段は
前記計測手段が計測した前記未解決シンボルの出現回数を頻度情報ファイルとして出力する頻度情報出力手段を含み、
前記第2の変換手段は
前記頻度情報出力手段が出力した複数の前記頻度情報ファイルを受け取り、前記未解決シンボル毎に頻度を総計する頻度情報入力手段を含むことを特徴とする請求項のいずれか1項に記載のプログラム処理装置。
The first conversion hand stage,
Includes frequency information output means for outputting the number of occurrences of the unresolved symbols the measuring hand stage was measured as frequency information file,
The second conversion hand stage,
Receiving said frequency information output means are a plurality of the frequency information file output, the according to any one of claims 1 to 3, characterized in that it comprises a frequency information input means for summing the frequency for each unresolved symbol Program processing equipment.
前記第1の変換手段は
前記計測手段が計測した前記未解決シンボルの出現回数をオブジェクトコードに付加して出力するオブジェクトコード出力手段を含み、
前記第2の変換手段は
前記オブジェクトコード出力手段が出力した複数の前記オブジェクトコードを受け取り、前記オブジェクトコードに付加されている前記出現回数を取り出して、前記未解決シンボル毎に頻度を総計する頻度情報入力手段を含むことを特徴とする請求項のいずれか1項に記載のプログラム処理装置。
The first conversion hand stage,
It includes object code output means for adding the number of occurrences of the unresolved symbols the measuring hand stage measured object code,
The second conversion hand stage,
Receiving a plurality of the object codes outputted by the object code output means, taking out the number of appearances added to the object code, and adding a frequency information input means for totaling the frequency for each unresolved symbol. The program processing device according to any one of claims 1 to 3 .
前記指示手段は、
前記記憶領域割り当て手段において前記未解決シンボルに割り当てられた記憶領域を絶対番地形式で操作する命令のコードサイズと前記命令の出現回数の積が、前記未解決シンボルに割り当てられた記憶領域を相対番地形式で操作する命令のコードサイズと前記命令の出現回数の積と前記相対番地をレジスタに設定する命令のコードサイズとの和を上回る場合に、前記未解決シンボルを相対番地アドレス形式で操作する命令を生成するよう、前記第1の変換手段に指示し、
前記第1の変換手段は
前記指示手段からの指示がある場合に、前記未解決シンボルを相対番地形式で操作する命令を生成することを特徴とする請求項1〜のいずれか1項に記載のプログラム処理装置。
The instruction means includes
The product of the code size of the instruction that operates the storage area assigned to the unresolved symbol in the absolute address format in the storage area allocating means and the number of appearances of the instruction is the relative address of the storage area assigned to the unresolved symbol. An instruction that manipulates the unresolved symbol in the relative address format when the sum of the code size of the instruction that operates in the format and the number of occurrences of the instruction exceeds the sum of the code size of the instruction that sets the relative address in the register to generate an instruction to the first conversion hand stage,
The first conversion hand stage,
Wherein when there is an instruction from the instruction means, a program processing apparatus according to any one of claims 1 to 5, characterized in that to generate an instruction for operating the unresolved symbols in relative numbers terrain type.
高級言語で記述された複数のソースコードからなるプログラムを実行可能コードに変換するプログラムを記録した記録媒体であって、
前記複数のソースコードを複数のオブジェクトコードに変換する時に、前記複数のオブジェクトコードに含まれる未解決シンボルの出現回数を計測する計測ステップを含む第1の変換ステップと
前記複数のオブジェクトコードを前記実行可能コードに変換し、前記未解決シンボルの出現回数が多い順に前記複数のオブジェクトコードに含まれる前記未解決シンボルに記憶領域を割り当てる記憶領域割り当てステップを含む第2の変換ステップをコンピュータに実行させる為のプログラムを記録したコンピュータ読み取り可能な記録媒体。
A recording medium recording a program for converting a program composed of a plurality of source codes described in a high-level language into an executable code,
When convert said plurality of source code into a plurality of object code, a first conversion steps comprising the step of measuring the number of occurrences of unresolved symbols included in the plurality of object codes,
A second storage step of converting the plurality of object codes into the executable code and allocating a storage area to the unresolved symbols included in the plurality of object codes in descending order of the number of appearances of the unresolved symbols; a computer-readable recording medium storing a program for executing the conversion steps on a computer.
JP09564698A 1998-04-08 1998-04-08 Program processing apparatus and recording medium Expired - Fee Related JP3675166B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP09564698A JP3675166B2 (en) 1998-04-08 1998-04-08 Program processing apparatus and recording medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP09564698A JP3675166B2 (en) 1998-04-08 1998-04-08 Program processing apparatus and recording medium

Publications (2)

Publication Number Publication Date
JPH11296379A JPH11296379A (en) 1999-10-29
JP3675166B2 true JP3675166B2 (en) 2005-07-27

Family

ID=14143280

Family Applications (1)

Application Number Title Priority Date Filing Date
JP09564698A Expired - Fee Related JP3675166B2 (en) 1998-04-08 1998-04-08 Program processing apparatus and recording medium

Country Status (1)

Country Link
JP (1) JP3675166B2 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
SE0002440D0 (en) 2000-06-28 2000-06-28 Virtutech Ab Interpreter
US10877743B2 (en) * 2016-11-29 2020-12-29 Mitsubishi Electric Corporation Control apparatus for updating stored program and method for updating program stored in control apparatus

Also Published As

Publication number Publication date
JPH11296379A (en) 1999-10-29

Similar Documents

Publication Publication Date Title
JP3220055B2 (en) An optimizing device for optimizing a machine language instruction sequence or an assembly language instruction sequence, and a compiler device for converting a source program described in a high-level language into a machine language or an assembly language instruction sequence.
JP3327818B2 (en) Program conversion device and recording medium
US5606697A (en) Compiler system for language processing program
US5920723A (en) Compiler with inter-modular procedure optimization
JP4487479B2 (en) SIMD instruction sequence generation method and apparatus, and SIMD instruction sequence generation program
JP2838855B2 (en) How to optimize the compiler
JP2000132403A (en) Program conversion device
JP3424520B2 (en) Program conversion device and debug device
JPH11212797A (en) Program conversion method, program converter and medium for storing program conversion program
JP3199013B2 (en) Language processing method, language processing apparatus, and storage medium storing language processing program
JPH0934725A (en) Device and method for processing language
JP3675166B2 (en) Program processing apparatus and recording medium
JP4044756B2 (en) Program conversion device, program conversion method, and program for realizing the program conversion device
JPH09223023A (en) Compile system and compiler
JP3264901B2 (en) Compiling device and compiling method
JP3266097B2 (en) Automatic reentrant method and system for non-reentrant program
JP3599888B2 (en) Object generation apparatus and method
Cilio et al. Efficient code generation for ASIPs with different word sizes
JPH10275088A (en) Link optimizing method
Kim Advanced compiler optimization for CalmRISC8 low-end embedded processor
JP2801193B2 (en) Vectorization processing device for induction variables
CN119336332A (en) A method and device for obtaining function metadata
JP3367438B2 (en) Conditional execution processing device
JPH0561687A (en) Processing system for compiler
Barry et al. Extracting parallelism in Fortran by translation to a single assignment intermediate form

Legal Events

Date Code Title Description
A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20040907

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20041108

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20041214

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20050209

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20050412

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20050425

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20090513

Year of fee payment: 4

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20100513

Year of fee payment: 5

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20110513

Year of fee payment: 6

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20110513

Year of fee payment: 6

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20120513

Year of fee payment: 7

LAPS Cancellation because of no payment of annual fees