JP2018156568A - Compilation device - Google Patents
Compilation device Download PDFInfo
- Publication number
- JP2018156568A JP2018156568A JP2017054709A JP2017054709A JP2018156568A JP 2018156568 A JP2018156568 A JP 2018156568A JP 2017054709 A JP2017054709 A JP 2017054709A JP 2017054709 A JP2017054709 A JP 2017054709A JP 2018156568 A JP2018156568 A JP 2018156568A
- Authority
- JP
- Japan
- Prior art keywords
- read
- write
- dummy
- basic block
- area
- 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
実施形態は、ソースプログラムをコンパイルするコンパイル装置に関するものである。 The embodiment relates to a compiling device for compiling a source program.
高水準言語、例えばC言語などで記述されたソースプログラムは、コンパイル処理されてオブジェクトプログラムに変換される。このコンパイル処理を実行するプロセッサの仕様によっては、ソースプログラムにおけるあるコア(モジュール)がメモリやレジスタへ値を書き込む場合、書き込み命令の直後に書き込みが完了することが保証できず、書き込み命令の直後に別のコア(モジュール)が値を読み出すと、書き込み前の値(前回値)が読み出される場合がある。 A source program written in a high-level language such as C language is compiled and converted into an object program. Depending on the specifications of the processor that executes this compile processing, when a certain core (module) in the source program writes a value to the memory or register, it cannot be guaranteed that the writing is completed immediately after the write command, and immediately after the write command. When another core (module) reads a value, a value before writing (previous value) may be read.
この対策として、あるコア(モジュール)によるメモリへの書き込み後に、同一のコア(モジュール)が同一メモリ領域から値を読み出し、書き込み完了を保証するという手法がある。このような書き込み完了を保証するために必要な読み出しを「ダミーリード」と呼ぶ。 As a countermeasure, there is a technique in which after a certain core (module) writes to the memory, the same core (module) reads a value from the same memory area to guarantee the completion of the writing. Such reading necessary to guarantee the completion of writing is called “dummy read”.
ソースプログラムのコンパイル時にライト命令に対応するダミーリードの挿入漏れを検出することができるコンパイル装置を提供する。 Provided is a compiling device that can detect a dummy read insertion omission corresponding to a write instruction when compiling a source program.
実施形態のコンパイル装置は、ソースプログラムにおけるライト命令を検出するライト検出部と、前記ライト命令が検出された後のリード命令を検出するリード検出部と、前記ライト命令により書き込み領域が指定され、前記リード命令により読み出し領域が指定され、前記読み出し領域が前記書き込み領域と一致するか否かを判定する判定部とを具備する。 The compiling apparatus according to the embodiment includes a write detection unit that detects a write command in a source program, a read detection unit that detects a read command after the write command is detected, and a write area specified by the write command, A read area is designated by a read command, and a determination unit that determines whether the read area matches the write area.
以下、図面を参照して実施形態について説明する。以下の説明において、同一の機能及び構成を有する構成要素については同一符号を付す。また、以下に示す各実施形態は、この実施形態の技術的思想を具体化するための装置や方法を例示するものであって、構成部品の材質、形状、構造、及び配置等を下記のものに特定するものではない。 Hereinafter, embodiments will be described with reference to the drawings. In the following description, components having the same functions and configurations are denoted by the same reference numerals. In addition, each embodiment shown below exemplifies an apparatus and a method for embodying the technical idea of this embodiment, and the material, shape, structure, arrangement, and the like of the components are as follows. It is not something specific.
各機能ブロックは、ハードウェア、コンピュータソフトウェアのいずれかまたは両者を組み合わせたものとして実現することができる。各機能ブロックが以下の例のように区別されていることは必須ではない。例えば、一部の機能が例示の機能ブロックとは別の機能ブロックによって実行されてもよい。さらに、例示の機能ブロックがさらに細かい機能サブブロックに分割されていてもよい。 Each functional block can be realized as hardware, computer software, or a combination of both. It is not essential that each functional block is distinguished as in the following example. For example, some functions may be executed by a functional block different from the illustrated functional block. Furthermore, the illustrated functional block may be divided into smaller functional sub-blocks.
1.第1実施形態
プロセッサ上で実行するプログラムは、例えば図1に示すようなフローで開発される。
(1)プログラム開発者がソースファイル(ソースプログラム)を作成する。
(2)コンパイラを有するコンパイル装置は、ソースファイルをコンパイル処理し、実行形式ファイル(あるいは、オブジェクトプログラム)を生成する。
(3)実行形式ファイルがプロセッサ上のメモリに置かれ、各種アプリケーションが実行される。
1. First Embodiment A program executed on a processor is developed with a flow as shown in FIG. 1, for example.
(1) A program developer creates a source file (source program).
(2) A compiling device having a compiler compiles a source file and generates an executable file (or object program).
(3) The executable file is placed in the memory on the processor, and various applications are executed.
ソースプログラムは、コンパイル装置によりコンパイル処理され、中間言語ファイルの生成、およびリンカを介して実行形式ファイルとして生成される。以下に、ソースプログラムをコンパイル処理するコンパイル装置について説明する。 The source program is compiled by a compiling device, and an intermediate language file is generated and an executable format file is generated via a linker. A compiling device for compiling a source program will be described below.
1.1 コンパイル装置の構成
図2は、第1実施形態のコンパイル装置のハードウェア構成を示す図である。コンパイル装置10は、コンピュータ、例えば、汎用コンピュータ、ワークステーション、及びパーソナルコンピュータ等から構成される。図2に示すように、コンパイル装置10は、CPU(Central Processing Unit)11、RAM(Random Access Memory)12、ROM(Read Only Memory)13、及び入出力部14を備える。CPU11、RAM12、ROM13、及び入出力部14はバス15により相互に接続されている。
1.1 Configuration of Compiling Device FIG. 2 is a diagram illustrating a hardware configuration of the compiling device according to the first embodiment. The compiling device 10 includes a computer such as a general-purpose computer, a workstation, and a personal computer. As illustrated in FIG. 2, the compiling device 10 includes a CPU (Central Processing Unit) 11, a RAM (Random Access Memory) 12, a ROM (Read Only Memory) 13, and an input / output unit 14. The CPU 11, RAM 12, ROM 13, and input / output unit 14 are connected to each other by a bus 15.
CPU11は、例えば、ROM13に記憶された制御プログラムに従いハードウェア各部を制御する。CPU11は、コンパイルプログラムに従ってソースプログラムに対してコンパイル処理を実行する。コンパイルプログラムは、例えば、ROM13内に格納されており、起動時にバス15を介してRAM12へロードされる。 CPU11 controls each part of hardware according to the control program memorize | stored in ROM13, for example. The CPU 11 executes a compile process for the source program according to the compile program. The compile program is stored in the ROM 13, for example, and is loaded into the RAM 12 via the bus 15 at the time of activation.
RAM12は、CPU11によるコンパイルプログラムの実行時に発生する各種データ、例えば中間コード及びテーブルを一時的に記憶する。RAM12は、例えば、SRAM(Static RAM)または、DRAM(Dynamic RAM)、フラッシュメモリなどを含む。 The RAM 12 temporarily stores various data generated when the CPU 11 executes the compile program, for example, intermediate codes and tables. The RAM 12 includes, for example, SRAM (Static RAM), DRAM (Dynamic RAM), flash memory, or the like.
ROM13は、例えば、制御プログラム及びコンパイルプログラムなどを記憶する。 The ROM 13 stores, for example, a control program and a compile program.
入出力部14は、外部の装置あるいはユーザから信号及びデータを受け取る入力部と、外部の装置あるいはユーザへ信号及びデータを出力する出力部を備える。入力部は、例えば、外部の装置からソースプログラム、コンパイルプログラム、及びユーザからの操作指示などを受け取る。出力部は、CPU11で処理されたデータあるいはオブジェクトプログラム、RAM12に記憶されたデータなどを出力する。 The input / output unit 14 includes an input unit that receives signals and data from an external device or user, and an output unit that outputs signals and data to the external device or user. The input unit receives, for example, a source program, a compile program, and an operation instruction from a user from an external device. The output unit outputs data processed by the CPU 11 or an object program, data stored in the RAM 12, and the like.
1.2 コンパイル装置の動作
次に、ソースプログラムをオブジェクトコードに変換するコンパイル処理の手順を説明する。図3は、ソースプログラムを機械語等のオブジェクトコード(オブジェクトプログラム)に変換するコンパイル処理を示す。このコンパイル処理はCPU11によって実行される。
1.2 Operation of Compiling Device Next, a procedure of compile processing for converting a source program into object code will be described. FIG. 3 shows a compiling process for converting a source program into an object code (object program) such as a machine language. This compilation process is executed by the CPU 11.
例えば、ソースプログラムP1は、入出力部14から入力され、RAM12に記憶される。ソースプログラムP1は、高水準言語、例えばC言語などで記述されている。 For example, the source program P 1 is input from the input / output unit 14 and stored in the RAM 12. The source program P1 is described in a high-level language such as C language.
まず、ソースプログラムP1に対して字句解析を実行する(ステップS1)。 First, lexical analysis is performed on the source program P1 (step S1).
次に、ステップS1での字句解析結果が文法的に正しいかどうかを解析する。すなわち、ステップS1で分割された字句が構文規則に従っているか解析し、構文解析情報を生成する(ステップS2)。 Next, it is analyzed whether or not the lexical analysis result in step S1 is grammatically correct. That is, it analyzes whether the lexical word divided | segmented by step S1 follows a syntax rule, and produces | generates syntax analysis information (step S2).
続いて、構文解析情報に基づいて中間コードを生成する(ステップS3)。さらに、中間コードを変換して、中間コードを最適化する(ステップS4)。 Subsequently, an intermediate code is generated based on the syntax analysis information (step S3). Further, the intermediate code is converted to optimize the intermediate code (step S4).
次に、最適化された中間コードから機械語などのオブジェクトコードを生成する(ステップS5)。このコード生成の処理の詳細については後述する。 Next, an object code such as a machine language is generated from the optimized intermediate code (step S5). Details of this code generation processing will be described later.
続いて、高速実行が可能なように、オブジェクトコードを最適化する(ステップS6)。さらに、最適化されたオブジェクトコードP2を出力する(ステップS7)。 Subsequently, the object code is optimized so that high-speed execution is possible (step S6). Further, the optimized object code P2 is output (step S7).
本実施形態では、図3に示す「コード生成」の処理において、ダミーリードの挿入漏れをチェックし、挿入漏れがある場合、警告を出力する処理(以下、ダミーリードチェックと記す)が実行される。なお、ダミーリードチェックは、別の処理、例えば「構文解析」や「中間コード最適化」などの処理で実行してもよい。 In the present embodiment, in the “code generation” process shown in FIG. 3, a dummy lead insertion omission is checked, and if there is an omission, a warning is output (hereinafter referred to as a dummy read check). . The dummy read check may be executed by another process such as “syntax analysis” or “intermediate code optimization”.
また、上述では、ステップS1〜S7はCPU11が実行する処理として説明したが、ステップS1〜S7はそれぞれコンパイルプログラムの1部分(モジュール)として、「字句解析部」、「構文解析部」、「中間コード生成部」、「中間コード最適化部」、「コード生成部」、「コード最適化部」、及び「コード出力部」と捉えることもできる。 In the above description, steps S1 to S7 have been described as processing executed by the CPU 11. However, steps S1 to S7 are each a part (module) of a compile program as a “lexical analysis unit”, “syntax analysis unit”, “intermediate analysis unit”. It can also be understood as “code generation unit”, “intermediate code optimization unit”, “code generation unit”, “code optimization unit”, and “code output unit”.
図4は、図3に示したコンパイル処理中のコード生成(ステップS5)の詳細を示すフローチャートである。このコード生成の処理はCPU11によって実行される。 FIG. 4 is a flowchart showing details of code generation (step S5) during the compilation process shown in FIG. This code generation process is executed by the CPU 11.
まず、中間コード最適化(ステップS4)により最適化された中間コードから基本ブロックを作成する(ステップS11)。中間コードは、高水準言語(例えば、C言語)と機械語の中間的言語からなる。中間コードは、高水準言語で書かれたプログラムを単一の処理に分割したものである。基本ブロックは、分岐や関数呼び出しで区切られた、処理が途中で途切れない連続する中間コードで構成されるブロックをさす。 First, a basic block is created from the intermediate code optimized by the intermediate code optimization (step S4) (step S11). The intermediate code consists of an intermediate language between a high-level language (for example, C language) and a machine language. The intermediate code is obtained by dividing a program written in a high-level language into a single process. The basic block refers to a block composed of continuous intermediate codes separated by branches and function calls and in which processing is not interrupted.
次に、基本ブロックから流れグラフを作成する(ステップS12)。流れグラフは、基本ブロックをつないだものである。流れグラフによりデータアクセスの流れを追うことができる。 Next, a flow graph is created from the basic block (step S12). A flow graph is a combination of basic blocks. You can follow the flow of data access with the flow graph.
次に、流れグラフ内の中間コードに対してダミーリードチェックを実行する(ステップS13)。ダミーリードチェックは、基本ブロックと流れグラフの情報を必要とするため、流れグラフの作成後に実行する。ダミーリードチェックの詳細については後述する。 Next, a dummy read check is performed on the intermediate code in the flow graph (step S13). The dummy read check requires basic block and flow graph information, and is executed after the flow graph is created. Details of the dummy read check will be described later.
次に、レジスタの割り当てを実行する(ステップS14)。ここでは、仮想レジスタがCPU11の有するレジスタに割り当てられる。さらに、基本ブロック及び流れグラフに基づいてオブジェクトコードを生成する(ステップS15)。 Next, register allocation is executed (step S14). Here, the virtual register is assigned to the register of the CPU 11. Further, an object code is generated based on the basic block and the flow graph (step S15).
なお、ダミーリードチェックの実行は、流れグラフの作成後であればよく、レジスタ割り当ての後、あるいはオブジェクトコード生成の後であってもよい。 Note that the dummy read check may be executed after the creation of the flow graph, after register allocation, or after object code generation.
1.2.1 ダミーリードチェック
第1実施形態では、基本ブロック単位で中間コードを解析し、ダミーリードの挿入漏れをチェックする。以下に、基本ブロック内でダミーリードの挿入漏れをチェックする手順を説明する。ソースプログラム作成時のダミーリード挿入やその確認を容易にするために、ダミーリードは、ライト命令の直後に置くのが適しており、実際にライトの直後に置かれる場合が多い。このため、基本ブロック単位でダミーリードの挿入漏れをチェックするのが有効である。
1.2.1 Dummy Read Check In the first embodiment, the intermediate code is analyzed in units of basic blocks, and dummy lead insertion leakage is checked. The procedure for checking the dummy lead insertion leakage in the basic block will be described below. In order to facilitate insertion and confirmation of dummy reads when creating a source program, it is appropriate to place dummy reads immediately after a write command, and in many cases, they are actually placed immediately after a write. For this reason, it is effective to check for dummy lead insertion omission in units of basic blocks.
図5は、図4に示したコード生成処理中のダミーリードチェックの処理を示すフローチャートである。図6は、ダミーリードチェックの処理で生成されるテーブル例を示す図である。このダミーリードチェックの処理はCPU11によって実行される。 FIG. 5 is a flowchart showing a dummy read check process during the code generation process shown in FIG. FIG. 6 is a diagram illustrating an example of a table generated by the dummy read check process. This dummy read check process is executed by the CPU 11.
ダミーリードチェックが開始されると、まず、ダミーリードのチェックに使用するテーブルP3を初期化する(ステップS101)。テーブルP3には、図6に示すように、ライト処理(ライト命令)の中間コード、ライト先のアドレス、リード回数、及び次のテーブルへのポインタなどの情報が格納される。テーブルP3はRAM12に生成される。 When the dummy read check is started, first, the table P3 used for checking the dummy read is initialized (step S101). As shown in FIG. 6, the table P3 stores information such as an intermediate code of a write process (write instruction), a write destination address, the number of reads, and a pointer to the next table. The table P3 is generated in the RAM 12.
次に、基本ブロック内の中間コードを順に探索し、中間コードがライト処理(ライト命令)か否かを判定する(ステップS102)。中間コードがライト処理である場合、ライト先のアドレスと同一の(あるいは一致する)アドレスを記録したテーブルが既にあるか否かを判定する(ステップS103)。 Next, the intermediate code in the basic block is sequentially searched to determine whether or not the intermediate code is a write process (write instruction) (step S102). If the intermediate code is a write process, it is determined whether or not there is already a table in which an address that is the same as (or coincides with) the write destination address is already recorded (step S103).
ステップS103にて、同一のアドレスを記録したテーブルが既にある場合、そのテーブル内のアドレスのリード回数を“0”にする(ステップS104)。一方、同一のアドレスを記録したテーブルがない場合、新たなテーブル内にそのアドレスを保存する(ステップS105)。その後、ステップS106に進む。 If there is already a table in which the same address is recorded in step S103, the read count of the address in the table is set to “0” (step S104). On the other hand, if there is no table in which the same address is recorded, the address is stored in a new table (step S105). Thereafter, the process proceeds to step S106.
ステップS104に示したように、同一アドレスに対して複数回のライトがあるときは、最後のライトの後にダミーリードがあるかを確認する必要がある。例えば、ライト1回目→リード1回目→ライト2回目の場合、リード1回目はライト2回目のダミーリードにはならない。このため、ライト時にもテーブルを探索し、同一アドレスへのライトがあるとき、リード回数を“0”にクリアする。 As shown in step S104, when there are multiple writes to the same address, it is necessary to check whether there is a dummy read after the last write. For example, in the case of the first write → first read → second write, the first read does not become the second dummy read. For this reason, the table is searched even during writing, and the number of reads is cleared to “0” when there is a write to the same address.
次に、ステップS102にて中間コードがライト処理でない場合、中間コードがリード処理(リード命令)か否かを判定する(ステップS107)。中間コードがリード処理である場合、リード先のアドレスが、テーブル内に保存されているライト先のアドレスと同一か否かを判定する(ステップS108)。 Next, when the intermediate code is not a write process in step S102, it is determined whether the intermediate code is a read process (read instruction) (step S107). If the intermediate code is a read process, it is determined whether the read destination address is the same as the write destination address stored in the table (step S108).
ステップS108にて、アドレスが同一の場合は、リード回数を“1”加算する、すなわち、リード回数をインクリメントする。(ステップS109)。その後、ステップS106に進む。一方、アドレスが同一でない場合は、次の中間コードへ移り(ステップS110)、ステップS102へ戻る。 If the addresses are the same in step S108, the read count is incremented by "1", that is, the read count is incremented. (Step S109). Thereafter, the process proceeds to step S106. On the other hand, if the addresses are not the same, the process moves to the next intermediate code (step S110) and returns to step S102.
また、ステップS107で中間コードがリード処理でない場合、ステップS106へ進む。 If the intermediate code is not a read process in step S107, the process proceeds to step S106.
ステップS106では、基本ブロック内の全ての中間コードを調べたか否かを判定する。全ての中間コードを調べていない場合は、次の中間コードへ移り(ステップS110)、ステップS102へ戻る。その後、ステップS102以降の処理を繰り返す。 In step S106, it is determined whether all intermediate codes in the basic block have been examined. If all the intermediate codes have not been checked, the process proceeds to the next intermediate code (step S110) and returns to step S102. Thereafter, the processing after step S102 is repeated.
一方、ステップS106にて、全ての中間コードの調査が終了した場合は、ダミーリードの挿入漏れがあるか否かをチェック(以下、リード漏れチェックと記す)する(ステップS111)。リード漏れチェックでは、ライト先のアドレスを保存したテーブルP3を順に参照する。テーブルを参照した結果、リード回数が“0”のものはダミーリードの挿入漏れがあると判定され、警告信号が出力される。このリード漏れチェックの詳細については後述する。その後、ダミーリードチェックが終了する。 On the other hand, if all the intermediate codes have been checked in step S106, it is checked whether or not there is a dummy lead insertion leak (hereinafter referred to as a lead leak check) (step S111). In the read leakage check, the table P3 in which the write destination address is stored is referred to in order. As a result of referring to the table, when the number of reads is “0”, it is determined that there is a dummy lead insertion omission and a warning signal is output. Details of the lead leakage check will be described later. Thereafter, the dummy read check ends.
図7は、ダミーリードチェック処理中のリード漏れチェックの詳細を示すフローチャートである。このリード漏れチェックでは、図5の処理で記録したテーブルP3を順に参照する。 FIG. 7 is a flowchart showing details of the lead leak check during the dummy read check process. In this lead leak check, the table P3 recorded in the process of FIG.
まず、図5の処理で記録した全てのテーブルP3を参照したか否かを判定する(ステップS121)。すなわち、参照対象のテーブルP3が終わりか否かを判定する。テーブルP3が終わりでない場合、そのテーブルP3内のリード回数を判定する(ステップS122)。 First, it is determined whether or not all the tables P3 recorded in the process of FIG. 5 have been referenced (step S121). That is, it is determined whether or not the reference target table P3 is over. If the table P3 is not over, the number of reads in the table P3 is determined (step S122).
ステップS122にて、リード回数が0回である場合、ダミーリードの挿入漏れがあると判定して警告信号を出力する(ステップS123)。その後、ステップS124に進む。一方、リード回数が1回以上である場合、必要なダミーリードが挿入されていると判定し、ステップS124に進む。 If the number of reads is zero in step S122, it is determined that there is a dummy lead insertion omission and a warning signal is output (step S123). Thereafter, the process proceeds to step S124. On the other hand, if the number of reads is one or more, it is determined that the necessary dummy lead is inserted, and the process proceeds to step S124.
ステップS124では、参照対象を次のテーブルへ移し、ステップS121に戻る。そして、ステップS121以降の処理を繰り返す。 In step S124, the reference target is moved to the next table, and the process returns to step S121. And the process after step S121 is repeated.
ステップS121にて、全てのテーブルP3の参照が終了した場合、リード漏れチェックの処理を終了する。 If all the tables P3 have been referenced in step S121, the lead leakage check process ends.
図5に示したダミーリードチェックの処理において、ライトのアドレスとリードのアドレスとが同一か否かの判定は以下のように扱う。ライトとリードのアドレスの数値が同じ場合は、同一アドレスと判定する。また、ライトとリードのアドレスが同じ変数であれば、同一アドレスと判定する。また、ライトとリードのアドレスが同じ配列の異なる要素であれば、同一アドレスと判定する。さらに、ライトとリードのアドレスが同じ構造体、共用体、ビットフィールドの異なるメンバであれば、同一アドレスと判定する。 In the dummy read check process shown in FIG. 5, whether or not the write address and the read address are the same is handled as follows. If the numerical values of the write and read addresses are the same, it is determined that they are the same address. If the write and read addresses are the same variable, it is determined that they are the same address. If the write and read addresses are different elements in the same array, the addresses are determined to be the same. Furthermore, if the write and read addresses are the same structure, union, and different members of the bit field, the addresses are determined to be the same.
また、図6に示したテーブルP3は、「ライト処理の中間コードへのポインタ」を保持してもよい。ライト処理の中間コードへのポインタは、その中間コードからソースプログラム上の行番号を導出し、それを警告メッセージとするために必要な情報である。しかし、警告メッセージ中に行番号を出力しないのであれば、不要である。 Further, the table P3 illustrated in FIG. 6 may hold “a pointer to an intermediate code for write processing”. The pointer to the intermediate code of the write process is information necessary for deriving the line number on the source program from the intermediate code and using it as a warning message. However, it is unnecessary if the line number is not output in the warning message.
また、テーブルP3内の「ライト先のアドレス」は、ライト先及びリード先のアドレスとの比較のために必要である。しかし、このためであれば、「ライト処理の中間コードへのポインタ」から導出可能であるため、「ライト処理の中間コードへのポインタ」あるいは「ライト先のアドレス」のどちらか一方のみを保持してもよい。 The “write destination address” in the table P3 is necessary for comparison with the write destination address and the read destination address. However, if this is the case, it can be derived from the “pointer to the intermediate code for write processing”, so only either the “pointer to the intermediate code for write processing” or the “write destination address” is retained. May be.
1.2.2 ダミーリードチェックの変形例1
前述した第1実施形態では、ライト先及びリード先を示す同一変数へのアクセスは同一領域へのアクセスであると判定した。実際は、同じターゲット(プロセッサ毎に定義されるアクセス単位)内へのアクセスは同一領域へのアクセスであると判定する。コンパイル装置としては、同じターゲットであるかどうかは、同じセクション(データをメモリに割り当てる単位)かどうかとして判定する。
1.2.2 Modification 1 of dummy lead check
In the first embodiment described above, it is determined that access to the same variable indicating the write destination and the read destination is access to the same area. In practice, it is determined that accesses within the same target (access unit defined for each processor) are accesses to the same area. As a compiling device, whether or not they are the same target is determined as whether or not they are the same section (unit for assigning data to memory).
変形例1では、ライト先の変数とリード先の変数とが同じセクションに配置されれば、同一領域へのアクセスであるとみなす。変形例1では第1実施形態と異なる点について主に説明する
図8は、変形例1のダミーリードチェックの処理を示すフローチャートである。図9は、変形例1が適用されるプログラム例を示す図である。図10は、ダミーリードチェックの処理で生成されるテーブル例を示す図である。
In the first modification, if the write destination variable and the read destination variable are arranged in the same section, it is regarded as an access to the same area. In the first modification, differences from the first embodiment will be mainly described. FIG. 8 is a flowchart showing a dummy read check process in the first modification. FIG. 9 is a diagram illustrating a program example to which the first modification is applied. FIG. 10 is a diagram illustrating an example of a table generated by the dummy read check process.
図8に示すフローチャートにおいて、中間コードがライト処理か否かを判定する(ステップS102)。中間コードがライト処理である場合、ライト先の変数が配置されるセクションと同一のセクションを記録したテーブルP4が既にあるか否かを判定する(ステップS103A)。 In the flowchart shown in FIG. 8, it is determined whether or not the intermediate code is a write process (step S102). If the intermediate code is a write process, it is determined whether or not there is already a table P4 that records the same section as the section in which the write destination variable is arranged (step S103A).
ステップS103Aにて、同一のセクションを記録したテーブルP4が既にある場合、そのテーブル内のリード回数を0にする(ステップS104)。一方、同一のセクションを記録したテーブルがない場合、新たなテーブル内にそのセクションを保存する(ステップS105A)。その後、ステップS106に進む。 If there is already a table P4 in which the same section is recorded in step S103A, the number of reads in that table is set to 0 (step S104). On the other hand, if there is no table in which the same section is recorded, the section is stored in a new table (step S105A). Thereafter, the process proceeds to step S106.
また、ステップS102にて中間コードがライト処理でない場合、中間コードがリード処理か否かを判定する(ステップS107)。中間コードがリード処理である場合、リード先の変数が配置されるセクションが、テーブルP4内に保存されているライト先のセクションと同一か否かを判定する(ステップS108A)。 If the intermediate code is not a write process in step S102, it is determined whether the intermediate code is a read process (step S107). When the intermediate code is read processing, it is determined whether or not the section in which the read destination variable is arranged is the same as the write destination section stored in the table P4 (step S108A).
ステップS108Aにて、リード先とライト先のセクションが同一の場合は、リード回数を“1”加算する、すなわち、リード回数をインクリメントする。(ステップS109)。その後、ステップS106に進む。一方、セクションが同一でない場合は、次の中間コードへ移り(ステップS110)、ステップS102へ戻る。その他の処理は図5に示した処理と同様である。 If the read destination and write destination sections are the same in step S108A, the read count is incremented by “1”, that is, the read count is incremented. (Step S109). Thereafter, the process proceeds to step S106. On the other hand, if the sections are not identical, the process moves to the next intermediate code (step S110) and returns to step S102. Other processes are the same as those shown in FIG.
図9に示すプログラム例を参照すると、変数ary1と変数ary2は同じセクションに配置される。同じセクションに配置される変数へのライトの後にリードがあるため、このプログラム例では、ダミーリードがある、すなわちダミーリードの挿入漏れがないと判定する。この判定処理のために、図10に示すテーブルP4では、図6に示した「ライト先のアドレス」を「配置セクション名」に変更する。 Referring to the example program shown in FIG. 9, the variables ary1 and ary2 are arranged in the same section. Since there is a read after a write to a variable arranged in the same section, in this program example, it is determined that there is a dummy read, that is, there is no dummy read insertion omission. For this determination processing, the “write destination address” shown in FIG. 6 is changed to “arrangement section name” in the table P4 shown in FIG.
変形例1では、ライト命令に対応するダミーリードの挿入漏れ判定をセクション単位で行えるため、第1実施形態よりもダミーリード挿入漏れの誤判定を減らすことができる。これにより、変形例1のコンパイル装置が出力する警告に対してプログラム開発者による対応工数を低減できる。 In the first modification, since the dummy leak insertion omission determination corresponding to the write command can be performed in section units, the erroneous determination of dummy read insertion omission can be reduced as compared with the first embodiment. Thereby, it is possible to reduce the man-hours required by the program developer for the warning output by the compiling device of the first modification.
1.2.3 ダミーリードチェックの変形例2
変形例2は、変数ary1と変数ary2が異なるセクションに配置される例である。この場合、変形例1ではダミーリードの挿入漏れがある(ダミーリードが無い)と判定されるが、ダミーリードの挿入漏れがない(ダミーリードがある)と判定してよい場合がある。
1.2.3 Modification 2 of dummy lead check
In the second modification, the variable ary1 and the variable ary2 are arranged in different sections. In this case, in Modification 1, it is determined that there is a dummy lead insertion leak (no dummy lead), but it may be determined that there is no dummy lead insertion leak (there is a dummy lead).
図11は、変形例2が適用されるプログラム例を示す図である。図12は、ダミーリードチェックの処理で生成されるテーブル例を示す図である。 FIG. 11 is a diagram illustrating a program example to which the second modification is applied. FIG. 12 is a diagram illustrating an example of a table generated by the dummy read check process.
図11に示すプログラム例を参照すると、変数ary1と変数ary2は異なるセクションに配置される。このままでは、変形例1のダミーリードチェックではダミーリードが無いと判定される。 Referring to the program example shown in FIG. 11, the variables ary1 and ary2 are arranged in different sections. In this state, the dummy read check of the first modification determines that there is no dummy read.
そこで、セクションDATA_SEC1とセクションDATA_SEC2とが同一のメモリ領域に割り当てられるように指定する。例えば、「#pragma same_region」でセクションDATA_SEC1とセクションDATA_SEC2とを指定する。 Therefore, it is specified that section DATA_SEC1 and section DATA_SEC2 are allocated to the same memory area. For example, the section DATA_SEC1 and the section DATA_SEC2 are specified by “#pragma same_region”.
コンパイラプログラムにおいては、セクションDATA_SEC1とセクションDATA_SEC2とを同一のメモリ領域に割り当てる指定がソースプログラム内にあるか否かを判定する処理を備える。この判定により、前記2つのセクションを同一のメモリ領域に割り当てる指定があることを判定できれば、変数ary1と変数ary2は同一のメモリ領域と分かる。これにより、変数ary2の読み出しが変数ary1の書き込みに対応するダミーリードであると判定できる。 The compiler program includes a process for determining whether or not a designation for allocating section DATA_SEC1 and section DATA_SEC2 to the same memory area is in the source program. If it can be determined by this determination that the two sections are assigned to the same memory area, the variables ary1 and ary2 can be recognized as the same memory area. Thereby, it can be determined that the reading of the variable ary2 is a dummy read corresponding to the writing of the variable ary1.
1.3 第1実施形態の効果
第1実施形態によれば、ソースプログラムのコンパイル時にライト命令に対応するダミーリードの挿入漏れを検出することができるコンパイル装置を提供できる。
1.3 Effects of First Embodiment According to the first embodiment, it is possible to provide a compiling device that can detect a dummy read insertion omission corresponding to a write instruction when compiling a source program.
以下に、第1実施形態の効果について詳述する。 Below, the effect of 1st Embodiment is explained in full detail.
ソースプログラムにおいてライト命令の後、ダミーリードが挿入されていない場合、プロセッサ上で動作するプログラムが正常に動作しない場合がある。一方でプロセッサの仕様が複雑でありダミーリードの挿入が必要な箇所が分かりにくいために、ダミーリードの挿入が漏れたり、不要なダミーリードを挿入することでプログラムの性能が低下する場合がある。 If a dummy read is not inserted after the write instruction in the source program, the program operating on the processor may not operate normally. On the other hand, because the processor specifications are complex and it is difficult to identify the locations where dummy leads need to be inserted, the insertion of dummy leads may be leaked, or the performance of a program may be degraded by inserting unnecessary dummy leads.
本実施形態では、ソースプログラムにおけるダミーリードの挿入漏れを検出できるため、ソースプログラムの品質を向上させることができる。さらに、ソースプログラムからアプリケーションソフト完成までの開発効率を改善することができる。 In the present embodiment, since the dummy lead insertion omission in the source program can be detected, the quality of the source program can be improved. Furthermore, the development efficiency from the source program to the completion of the application software can be improved.
また、プログラム開発者は必要なダミーリードの挿入漏れを容易に確認することができ、出荷後のダミーリードの挿入漏れによるトラブルを防止できる。 In addition, the program developer can easily confirm the necessary leakage of dummy leads, and can prevent troubles caused by the leakage of dummy leads after shipment.
また、本実施形態では、以下のダミーリードの挿入漏れを検出可能である。例えば、メモリへのライト後、セマフォ解放のための関数呼び出し前のダミーリードの挿入漏れ、あるいは、ダミーリード処理にvolatile修飾が無く最適化で削除されることに起因するダミーリード漏れ、あるいは、メモリへのライト直後に関数の処理が終了することによるダミーリードの挿入漏れなどである。 In the present embodiment, the following dummy lead insertion leakage can be detected. For example, after writing to the memory, the dummy read is not inserted before calling the function to release the semaphore, or dummy read is leaked due to the dummy read processing without volatile modification and being deleted by optimization. For example, a dummy read is not inserted due to the completion of processing of the function immediately after the write operation.
2.第2実施形態
第2実施形態のコンパイル装置について説明する。第1実施形態では基本ブロック毎にダミーリードの挿入漏れをチェックしたが、第2実施形態では全ての基本ブロックを探索した後、ダミーリードの挿入漏れをチェックする。第2実施形態の構成は、図2、図3、図4に示した第1実施形態の構成と同様であるため、記載を省略する。以下に、第1実施形態と異なる点について主に説明する。
2. Second Embodiment A compiling device according to a second embodiment will be described. In the first embodiment, the dummy lead insertion leakage is checked for each basic block. In the second embodiment, after all basic blocks are searched, the dummy lead insertion leakage is checked. Since the configuration of the second embodiment is the same as the configuration of the first embodiment shown in FIGS. 2, 3, and 4, description thereof is omitted. Below, a different point from 1st Embodiment is mainly demonstrated.
2.1 ダミーリードチェック
図13は、第2実施形態のダミーリードチェックの処理を示すフローチャートである。この処理では、基本ブロックごとに作成したテーブルP3をRAM12に記憶しておく。
2.1 Dummy Read Check FIG. 13 is a flowchart showing a dummy read check process according to the second embodiment. In this process, the table P3 created for each basic block is stored in the RAM 12.
ダミーリードチェックが開始されると、まず、ダミーリードのチェックに使用するテーブルP3を初期化する(ステップS101)。 When the dummy read check is started, first, the table P3 used for checking the dummy read is initialized (step S101).
次に、基本ブロック内の中間コードを順に探索し、中間コードがライト処理(ライト命令)か否かを判定する(ステップS102)。中間コードがライト処理である場合、ライト先のアドレスと同一のアドレスを記録したテーブルが既にあるか否かを判定する(ステップS103)。 Next, the intermediate code in the basic block is sequentially searched to determine whether or not the intermediate code is a write process (write instruction) (step S102). If the intermediate code is a write process, it is determined whether there is already a table in which the same address as the write destination address is recorded (step S103).
ステップS103にて、同一のアドレスを記録したテーブルP3が既にある場合、そのテーブル内のアドレスのリード回数を“0”にする(ステップS104)。一方、同一のアドレスを記録したテーブルがない場合、新たなテーブル内にそのアドレスを保存する(ステップS105)。その後、ステップS106に進む。 If there is already a table P3 in which the same address is recorded in step S103, the read count of the address in the table is set to “0” (step S104). On the other hand, if there is no table in which the same address is recorded, the address is stored in a new table (step S105). Thereafter, the process proceeds to step S106.
次に、ステップS102にて中間コードがライト処理でない場合、中間コードがリード処理(リード命令)か否かを判定する(ステップS107)。中間コードがリード処理である場合、リード先のアドレスが、テーブル内に保存されているライト先のアドレスと同一か否かを判定する(ステップS108)。 Next, when the intermediate code is not a write process in step S102, it is determined whether the intermediate code is a read process (read instruction) (step S107). If the intermediate code is a read process, it is determined whether the read destination address is the same as the write destination address stored in the table (step S108).
ステップS108にて、アドレスが同一の場合はリード回数を“1”加算する、すなわち、リード回数をインクリメントする。(ステップS109)。その後、ステップS106に進む。一方、アドレスが同一でない場合は、次の中間コードへ移り(ステップS110)、ステップS102へ戻る。 If the addresses are the same in step S108, the read count is incremented by "1", that is, the read count is incremented. (Step S109). Thereafter, the process proceeds to step S106. On the other hand, if the addresses are not the same, the process moves to the next intermediate code (step S110) and returns to step S102.
また、ステップS107で中間コードがリード処理でない場合、ステップS106へ進む。 If the intermediate code is not a read process in step S107, the process proceeds to step S106.
ステップS106では、基本ブロック内の全ての中間コードを調べたか否かを判定する。全ての中間コードを調べていない場合は、次の中間コードへ移り(ステップS110)、ステップS102へ戻る。その後、ステップS102以降の処理を繰り返す。 In step S106, it is determined whether all intermediate codes in the basic block have been examined. If all the intermediate codes have not been checked, the process proceeds to the next intermediate code (step S110) and returns to step S102. Thereafter, the processing after step S102 is repeated.
一方、ステップS106にて、全ての中間コードの調査が終了した場合は、全ての基本ブロックを調べたか否かを判定する(ステップS201)。全ての基本ブロックを調べていない場合は、次の基本ブロックへ移り(ステップS202)、ステップS102へ戻る。その後、ステップS102以降の処理を繰り返す。 On the other hand, if all the intermediate codes have been checked in step S106, it is determined whether all the basic blocks have been checked (step S201). If all the basic blocks have not been checked, the process proceeds to the next basic block (step S202) and returns to step S102. Thereafter, the processing after step S102 is repeated.
ステップS201にて、全ての基本ブロックの調査が終了した場合は、リード漏れチェック、すなわちダミーリードの挿入漏れがあるか否かをチェックする(ステップS111)。このリード漏れチェックの詳細については後述する。その後、ダミーリードチェックが終了する。 If all the basic blocks have been checked in step S201, a lead leak check, that is, whether there is a dummy lead insertion leak is checked (step S111). Details of the lead leakage check will be described later. Thereafter, the dummy read check ends.
図14は、ダミーリードチェック処理中のリード漏れチェックの詳細を示すフローチャートである。このリード漏れチェックでは、図13の処理で記録したテーブルを順に参照する。 FIG. 14 is a flowchart showing details of a read leak check during the dummy read check process. In this lead leak check, the tables recorded in the processing of FIG.
まず、図13の処理で記録した全ての支配節の基本ブロックのテーブルP3を参照したか否かを判定する(ステップS211)。すなわち、参照対象のテーブルが終わりか否かを判定する。参照対象のテーブルが終わりでない場合、そのテーブル内のリード回数を判定する(ステップS212)。なお、支配節は、ある基本ブロックを通る際、その後に必ず通ることが保証される基本ブロックをさす。 First, it is determined whether or not the basic block table P3 of all the dominant clauses recorded in the process of FIG. 13 has been referenced (step S211). That is, it is determined whether or not the reference target table is over. If the table to be referenced is not the end, the number of reads in the table is determined (step S212). Note that a dominant clause is a basic block that is guaranteed to pass through a certain basic block.
ステップS212にてリード回数が0回である場合、その基本ブロックの支配節である基本ブロックに関数呼び出しがあるか否かを判定する。関数呼び出しがある場合、ステップS215に進む。一方、関数呼び出しがない場合、支配節の基本ブロックのテーブル内のリード回数を判定する(ステップS214)。リード回数が0回である場合、ステップS215に進む。 If the number of reads is 0 in step S212, it is determined whether or not there is a function call in the basic block that is the dominating clause of the basic block. If there is a function call, the process proceeds to step S215. On the other hand, if there is no function call, the number of reads in the table of the basic block of the dominant clause is determined (step S214). If the number of reads is 0, the process proceeds to step S215.
ステップS215では、その支配節が最後の支配節か否かを判定する。最後の支配節である場合、ダミーリードの挿入漏れがあると判定して警告信号を出力する(ステップS217)。その後、ステップS211に戻り、ステップS211以降の処理を繰り返す。 In step S215, it is determined whether or not the dominating clause is the last dominating clause. If it is the last dominant node, it is determined that there is a dummy lead insertion omission and a warning signal is output (step S217). Then, it returns to step S211 and repeats the process after step S211.
一方、ステップS215にて最後の支配節でない場合、次の支配節へ移り(ステップS216)、ステップS213へ戻り、ステップS213以降の処理を繰り返す。 On the other hand, if it is not the last dominant node in step S215, the process proceeds to the next dominant node (step S216), returns to step S213, and repeats the processing from step S213 onward.
また、ステップS212及びS214にて、リード回数が1回以上である場合、次の基本ブロックのテーブルへ移り(ステップS218)、ステップS211へ戻り、ステップS211以降の処理を繰り返す。 If the number of reads is one or more in steps S212 and S214, the process moves to the next basic block table (step S218), returns to step S211 and repeats the processes in and after step S211.
そして、ステップS211にて、全ての支配節の基本ブロックのテーブルの調査が終了した場合、リード漏れチェックの処理を終了する。 In step S211, when the investigation of the basic block tables of all the control clauses is completed, the lead leakage check process is terminated.
前述したように、第2実施形態におけるリード漏れチェックは以下のように実行される。 As described above, the lead leakage check in the second embodiment is executed as follows.
ある基本ブロックにおいてダミーリードの挿入漏れがあるか否かをチェックする場合、その基本ブロックのテーブルをまずチェックする。その基本ブロックにダミーリードがなければ、その基本ブロックの支配節となる基本ブロックのテーブルをチェックする。 When checking whether or not there is a dummy lead insertion omission in a basic block, the basic block table is first checked. If there is no dummy read in the basic block, the table of the basic block that is the dominant node of the basic block is checked.
ライト先のアドレスと同じアドレスのリードがある場合、ダミーリードの挿入漏れがない、すなわち、ダミーリードがあると判定する。ライト先のアドレスと同じアドレスのリードがない場合(テーブルがない場合、またはテーブル内のリード回数が0回の場合)、ダミーリードの挿入漏れがある、すなわち、ダミーリードがないと判定する。 If there is a read at the same address as the write destination address, it is determined that there is no dummy lead insertion omission, that is, there is a dummy read. When there is no read at the same address as the write destination address (when there is no table or when the number of reads in the table is 0), it is determined that there is a dummy read insertion omission, that is, there is no dummy read.
また、その基本ブロックの支配節に関数呼び出しがある場合、ダミーリードがあるか不明であるため、次の支配節に移る。その基本ブロックの全ての支配節の基本ブロックを探索し、リード回数が“0”であれば、ダミーリードがないと判定する。 Also, if there is a function call in the dominant clause of the basic block, it is unclear whether there is a dummy read, so the process moves to the next dominant clause. The basic block of all the dominant clauses of the basic block is searched, and if the read count is “0”, it is determined that there is no dummy read.
2.2 ダミーリードチェックの変形例
第2実施形態のダミーリードチェックでは、支配節に関数呼び出しがある場合、必ずダミーリードの挿入漏れがあると判定したが、この変形例では、関数呼び出しにより呼び出される関数がアクセスする領域が、ソースプログラムにより指定されているものとする。これにより、ライト先のアクセス領域(メモリ領域)と、呼び出される関数のアクセス領域とが同一か否かを第1実施形態に示した構成で判定できる。
2.2 Modification of dummy read check In the dummy read check of the second embodiment, it is determined that there is a dummy lead insertion omission when there is a function call in the dominant clause, but in this modification, it is called by a function call. The area accessed by the function to be accessed is specified by the source program. As a result, it is possible to determine whether or not the write destination access area (memory area) and the access area of the function to be called are the same as those in the first embodiment.
図15は、変形例が適用されるプログラム例を示す図である。アクセスする領域の指定方法としては、例えば、関数修飾子や#pragma指令がある。図15に示すプログラム例を参照すると、関数func1は、セクションDATA_SEC1のデータを読み、関数func2はセクションDATA_SEC2のデータを読む。その後、関数func1の呼び出しにより、セクションDATA_SEC1に置かれる変数ary1への書き込みに対応するダミーリードがあると判定される。同様に、関数func2の呼び出しにより、セクションDATA_SEC2に置かれる変数ary2への書き込みに対応するダミーリードがあると判定される。 FIG. 15 is a diagram illustrating a program example to which the modification is applied. As a method for specifying an area to be accessed, for example, there are a function modifier and a #pragma directive. Referring to the example program shown in FIG. 15, the function func1 reads the data in the section DATA_SEC1, and the function func2 reads the data in the section DATA_SEC2. Thereafter, by calling the function func1, it is determined that there is a dummy read corresponding to writing to the variable ary1 placed in the section DATA_SEC1. Similarly, by calling the function func2, it is determined that there is a dummy read corresponding to writing to the variable ary2 placed in the section DATA_SEC2.
前述したように、変形例では、アプリケーションのソースプログラム中の呼び出し関数がアクセスする領域を、ソースプログラム中にプログラム文によって明示する。そして、それをコンパイル装置が解釈することにより、ダミーリードの挿入漏れを、すなわちダミーリードの有無をチェックする。 As described above, in the modification, the area accessed by the call function in the source program of the application is clearly indicated by the program statement in the source program. Then, the compiling device interprets it, and checks whether or not dummy leads are inserted, that is, whether or not dummy leads are present.
この変形例では、ダミーリードの挿入対策として用意した関数(例えば、前記関数修飾子や#pragma指令)がライト命令の直後に呼ばれる場合、ダミーリードが挿入されていると判定し、警告出力の対象にしない。これにより、ダミーリード挿入漏れの誤判定を減らすことができるため、変形例のコンパイル装置が出力する警告に対してプログラム開発者による対応工数を低減できる。 In this modification, if a function prepared as a countermeasure against dummy read insertion (for example, the function qualifier or #pragma instruction) is called immediately after a write instruction, it is determined that a dummy read is inserted, and a warning output target Don't make it. Accordingly, erroneous determination of dummy lead insertion omission can be reduced, so that the number of man-hours required by the program developer for the warning output by the compiling device of the modified example can be reduced.
2.3 第2実施形態の効果
第2実施形態によれば、ソースプログラムのコンパイル時にライト命令に対応するダミーリードの挿入漏れを検出することができるコンパイル装置を提供できる。
2.3 Effects of the Second Embodiment According to the second embodiment, it is possible to provide a compiling device that can detect a dummy read insertion omission corresponding to a write instruction when compiling a source program.
さらに、基本ブロック内にライト命令に対応するダミーリードがない場合、その基本ブロックの支配節となる基本ブロックまでダミーリードの探索範囲を広げることができる。このため、ダミーリード挿入漏れの検出精度を向上させることができる。 Further, when there is no dummy read corresponding to the write command in the basic block, the search range of the dummy read can be extended to the basic block that is the dominant node of the basic block. For this reason, the detection accuracy of dummy lead insertion leakage can be improved.
3.第3実施形態
プログラム言語規格で定められているライブラリ関数には、例えば「memcpy」や「memset」のように、メモリに書き込む機能を持った関数がある。第3実施形態は、「memcpy」や「memset」のようなメモリに書き込む機能を持つ関数を使用した場合に、関数呼び出しの直後の基本ブロック(及びその支配節)に対してダミーリードチェックを行う例である。第3実施形態の構成は、図2、図3、図4に示した第1実施形態の構成と同様であるため、記載を省略する。以下に、第1実施形態と異なる点について主に説明する。
3. Third Embodiment Library functions defined in the programming language standard include functions having a function of writing to a memory, such as “memcpy” and “memset”. In the third embodiment, when a function having a function of writing to a memory such as “memcpy” or “memset” is used, a dummy read check is performed on the basic block (and its dominant clause) immediately after the function call. It is an example. Since the configuration of the third embodiment is the same as the configuration of the first embodiment shown in FIGS. 2, 3, and 4, description thereof is omitted. Below, a different point from 1st Embodiment is mainly demonstrated.
3.1 ダミーリードチェック
ソースプログラムの書き込み機能を持つライブラリ関数に対して、コンパイル装置は規格で定められる引数がメモリ書き込み先のポインタであることを認識することができる。第3実施形態では、ライブラリ関数のメモリ書き込み先に対してダミーリードの挿入漏れがないか否かをチェックする。
3.1 Dummy Read Check For a library function having a source program writing function, the compiling device can recognize that an argument defined in the standard is a pointer to a memory write destination. In the third embodiment, it is checked whether or not there is a dummy read insertion omission with respect to the memory write destination of the library function.
ライブラリ関数が書き込むメモリ領域に対して、ダミーリードを探索する基本ブロックは、関数呼び出し直後の基本ブロックとその支配節である。 The basic block for searching for a dummy read for the memory area written by the library function is the basic block immediately after the function call and its dominant clause.
第1引数が書き込み先であることは言語規格で定められているため、第1引数をライト先としてテーブルに定義する。その他のテーブル定義は第1実施形態と同様である。 Since the language standard defines that the first argument is the write destination, the first argument is defined in the table as the write destination. Other table definitions are the same as those in the first embodiment.
図16は、第3実施形態のダミーリードチェックの処理を示すフローチャートである。図17は、ダミーリードチェックの処理で生成されるテーブル例を示す図である。 FIG. 16 is a flowchart illustrating a dummy read check process according to the third embodiment. FIG. 17 is a diagram illustrating an example of a table generated by the dummy read check process.
ステップS102Aにて、基本ブロック内の中間コードが書き込み機能を持つ関数か否かを判定する。中間コードが書き込み機能を持つ関数である場合、ライト先の引数と同一の引数を記録したテーブルP5が既にあるか否かを判定する(ステップS103B)。 In step S102A, it is determined whether the intermediate code in the basic block is a function having a write function. If the intermediate code is a function having a write function, it is determined whether or not there is already a table P5 in which the same argument as the write destination argument is recorded (step S103B).
ステップS103Bにて、同一の引数を記録したテーブルが既にある場合、そのテーブル内の引数のリード回数を“0”にする(ステップS104)。一方、同一の引数を記録したテーブルがない場合、新たなテーブル内にその引数を保存する(ステップS105B)。その後、ステップS106に進む。 If there is already a table in which the same argument is recorded in step S103B, the number of times of reading the argument in the table is set to “0” (step S104). On the other hand, if there is no table in which the same argument is recorded, the argument is stored in a new table (step S105B). Thereafter, the process proceeds to step S106.
一方、ステップS102Aにて、中間コードが書き込み機能を持つ関数でない場合、中間コードがリード処理(リード命令)か否かを判定する(ステップS107)。中間コードがリード処理である場合、リード先のアドレスが、テーブルP5内に保存されているライト先の第1引数が示すアドレスと同一か否かを判定する(ステップS108B)。 On the other hand, if the intermediate code is not a function having a write function in step S102A, it is determined whether the intermediate code is a read process (read instruction) (step S107). If the intermediate code is a read process, it is determined whether the read destination address is the same as the address indicated by the first argument of the write destination stored in the table P5 (step S108B).
ステップS108Bにて、アドレスが同一の場合はリード回数を“1”加算する、すなわち、リード回数をインクリメントする。(ステップS109)。その後、ステップS106に進む。一方、引数が同一でない場合は、次の中間コードへ移り(ステップS110)、ステップS102へ戻る。 In step S108B, when the addresses are the same, the read count is incremented by “1”, that is, the read count is incremented. (Step S109). Thereafter, the process proceeds to step S106. On the other hand, if the arguments are not the same, the process moves to the next intermediate code (step S110) and returns to step S102.
その他の処理は図5に示した処理と同様である。 Other processes are the same as those shown in FIG.
3.2 第3実施形態の効果
第3実施形態によれば、ソースプログラムのコンパイル時にライト命令に対応するダミーリードの挿入漏れを検出することができるコンパイル装置を提供できる。
3.2 Effects of the Third Embodiment According to the third embodiment, it is possible to provide a compiling device that can detect a dummy read insertion omission corresponding to a write instruction when compiling a source program.
さらに、言語規格で定められている関数については、その関数の仕様に応じたダミーリードの挿入漏れチェックができる。これにより、第1実施形態で検出できなかったダミーリードの挿入漏れを検出することができる。 Furthermore, for functions defined in the language standard, dummy lead insertion omission can be checked according to the function specifications. As a result, it is possible to detect a dummy lead insertion leakage that could not be detected in the first embodiment.
4.第4実施形態
第4実施形態では、前述した第1〜第3実施形態におけるダミーリードチェックを実行するか否かを選択できるようにした例である。
4). Fourth Embodiment The fourth embodiment is an example in which it is possible to select whether or not to execute the dummy read check in the first to third embodiments described above.
図18は、第4実施形態の処理を示すフローチャートである。図示するように、ダミーリードチェックの処理(ステップS13)の前に、ダミーリードチェックを実行するか否かの判定処理(ステップS16)を設ける。ダミーリードチェックを実行する場合は、そのままダミーリードチェックへ進む。一方、ダミーリードチェックを実行しない場合は、ダミーリードチェックをパスしてレジスタ割り当ての処理(ステップS14)に進む。 FIG. 18 is a flowchart showing the processing of the fourth embodiment. As shown in the figure, before the dummy read check process (step S13), a determination process (step S16) for determining whether or not to execute the dummy read check is provided. When executing the dummy read check, the process proceeds to the dummy read check as it is. On the other hand, if the dummy read check is not executed, the dummy read check is passed and the process proceeds to the register allocation process (step S14).
4.2 第4実施形態の効果
第4実施形態よれば、ダミーリードチェックを実行するか否かを選択することができる。これにより、コンパイル処理の自由度が向上する。さらに、ダミーリードチェックを実行しない場合は、コンパイル処理に要する時間を短縮することが可能である。
4.2 Effects of the Fourth Embodiment According to the fourth embodiment, it is possible to select whether or not to execute a dummy read check. Thereby, the freedom degree of a compilation process improves. Furthermore, when the dummy read check is not executed, the time required for the compilation process can be shortened.
5.その他変形例等
本発明のいくつかの実施形態を説明したが、これらの実施形態は、例として提示したものであり、発明の範囲を限定することは意図していない。これら新規な実施形態は、その他の様々な形態で実施されることが可能であり、発明の要旨を逸脱しない範囲で、種々の省略、置き換え、変更を行うことができる。これら実施形態やその変形は、発明の範囲や要旨に含まれるとともに、特許請求の範囲に記載された発明とその均等の範囲に含まれる。
5. Other Modifications Although several embodiments of the present invention have been described, these embodiments are presented as examples and are not intended to limit the scope of the invention. These novel embodiments can be implemented in various other forms, and various omissions, replacements, and changes can be made without departing from the scope of the invention. These embodiments and modifications thereof are included in the scope and gist of the invention, and are included in the invention described in the claims and the equivalents thereof.
10…コンパイル装置、11…CPU、12…RAM、13…ROM、14…入出力部、15…バス。 DESCRIPTION OF SYMBOLS 10 ... Compile apparatus, 11 ... CPU, 12 ... RAM, 13 ... ROM, 14 ... Input-output part, 15 ... Bus.
Claims (7)
前記ライト命令が検出された後のリード命令を検出するリード検出部と、
前記ライト命令により書き込み領域が指定され、前記リード命令により読み出し領域が指定され、前記読み出し領域が前記書き込み領域と一致するか否かを判定する判定部と、
を具備するコンパイル装置。 A write detector for detecting a write command in the source program;
A read detector for detecting a read command after the write command is detected;
A determination unit that determines whether a write area is specified by the write command, a read area is specified by the read command, and the read area matches the write area;
A compiling device comprising:
前記判定部は、前記第1変数が配置される第1セクションと、前記第2変数が配置される第2セクションとが一致するか否かを判定し、
前記第1セクションは前記ライト命令によりデータが前記書き込み領域に書き込まれる単位であり、前記第2セクションは前記リード命令によりデータが前記読み出し領域から読み出される単位である請求項1に記載のコンパイル装置。 When a write area by the write instruction is indicated by a first variable, a read area by the read instruction is indicated by a second variable, and the first variable and the second variable are different,
The determination unit determines whether or not a first section in which the first variable is arranged matches a second section in which the second variable is arranged,
2. The compiling apparatus according to claim 1, wherein the first section is a unit in which data is written to the write area by the write instruction, and the second section is a unit in which data is read from the read area by the read instruction.
前記判定部は、前記第1セクションと前記第2セクションとを同一のメモリ領域に割り当てる指定が前記ソースプログラム内にあるか否かを判定する請求項2に記載のコンパイル装置。 When the first section in which the first variable is arranged does not match the second section in which the second variable is arranged,
The compiling apparatus according to claim 2, wherein the determination unit determines whether or not the designation to allocate the first section and the second section to the same memory area is in the source program.
前記ライト検出部は前記基本ブロックに対して前記ライト命令の検出を行い、前記リード検出部は前記基本ブロックに対して前記リード命令の検出を行う請求項1乃至4のいずれかに記載のコンパイル装置。 The source program is divided into basic blocks including intermediate code,
The compiling apparatus according to claim 1, wherein the write detection unit detects the write command for the basic block, and the read detection unit detects the read command for the basic block. .
前記ライト検出部は前記第1基本ブロック及び前記第2基本ブロックに対して前記ライト命令の検出を行い、前記リード検出部は前記第1基本ブロック及び前記第2基本ブロックに対して前記リード命令の検出を行う請求項1乃至4のいずれかに記載のコンパイル装置。 The source program is divided into a plurality of basic blocks including intermediate code, and the plurality of basic blocks includes a first basic block and a second basic block that always passes after passing through the first basic block,
The write detector detects the write command for the first basic block and the second basic block, and the read detector detects the read command for the first basic block and the second basic block. The compiling apparatus according to claim 1, wherein detection is performed.
前記判定部は、前記リード命令の回数に基づいて、前記ライト命令の前記書き込み領域と一致する前記読み出し領域を有する前記リード命令が前記ソースプログラムにあるか否かを判定する請求項1乃至6のいずれかに記載のコンパイル装置。 A storage unit that stores the number of times the read command having the read area that matches the write area is detected after the write instruction is detected;
7. The determination unit according to claim 1, wherein the determination unit determines whether or not the read instruction having the read area that matches the write area of the write instruction is in the source program based on the number of the read instructions. The compiling device according to any one of the above.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2017054709A JP2018156568A (en) | 2017-03-21 | 2017-03-21 | Compilation device |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2017054709A JP2018156568A (en) | 2017-03-21 | 2017-03-21 | Compilation device |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| JP2018156568A true JP2018156568A (en) | 2018-10-04 |
Family
ID=63715684
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP2017054709A Pending JP2018156568A (en) | 2017-03-21 | 2017-03-21 | Compilation device |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JP2018156568A (en) |
Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JPH08328868A (en) * | 1995-05-30 | 1996-12-13 | Toshiba Corp | Objective code optimizing apparatus and method |
| JP2000207223A (en) * | 1999-01-12 | 2000-07-28 | Matsushita Electric Ind Co Ltd | Program processing method and apparatus for parallel processing, recording medium recording program for executing program processing for parallel processing, and recording medium recording instruction sequence for parallel processing |
| JP2001067234A (en) * | 1999-08-27 | 2001-03-16 | Fujitsu Ltd | Compiler and processor |
| JP2007241612A (en) * | 2006-03-08 | 2007-09-20 | Matsushita Electric Ind Co Ltd | Multi-master system |
| JP2008269078A (en) * | 2007-04-17 | 2008-11-06 | Toshiba Corp | Bus control device |
| JP2009026260A (en) * | 2007-07-24 | 2009-02-05 | Nec Corp | Arithmetic processor, arithmetic processing method |
| EP3001312A1 (en) * | 2014-09-26 | 2016-03-30 | German Research School for Simulation Sciences GmbH | Method, device and computer program product for detecting data dependencies within a program |
-
2017
- 2017-03-21 JP JP2017054709A patent/JP2018156568A/en active Pending
Patent Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JPH08328868A (en) * | 1995-05-30 | 1996-12-13 | Toshiba Corp | Objective code optimizing apparatus and method |
| JP2000207223A (en) * | 1999-01-12 | 2000-07-28 | Matsushita Electric Ind Co Ltd | Program processing method and apparatus for parallel processing, recording medium recording program for executing program processing for parallel processing, and recording medium recording instruction sequence for parallel processing |
| JP2001067234A (en) * | 1999-08-27 | 2001-03-16 | Fujitsu Ltd | Compiler and processor |
| JP2007241612A (en) * | 2006-03-08 | 2007-09-20 | Matsushita Electric Ind Co Ltd | Multi-master system |
| JP2008269078A (en) * | 2007-04-17 | 2008-11-06 | Toshiba Corp | Bus control device |
| JP2009026260A (en) * | 2007-07-24 | 2009-02-05 | Nec Corp | Arithmetic processor, arithmetic processing method |
| EP3001312A1 (en) * | 2014-09-26 | 2016-03-30 | German Research School for Simulation Sciences GmbH | Method, device and computer program product for detecting data dependencies within a program |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| KR101786156B1 (en) | Compile-time bounds checking for user-defined types | |
| Hovemeyer et al. | Finding more null pointer bugs, but not too many | |
| US5581696A (en) | Method using a computer for automatically instrumenting a computer program for dynamic debugging | |
| US8458681B1 (en) | Method and system for optimizing the object code of a program | |
| US8181170B2 (en) | Unwind information for optimized programs | |
| US11526433B2 (en) | Data structure allocation into storage class memory during compilation | |
| US8429632B1 (en) | Method and system for debugging merged functions within a program | |
| CN105630463A (en) | Method and device for detecting JAR packet collision | |
| US7254809B2 (en) | Compilation of unified parallel C-language programs | |
| US10409559B2 (en) | Single-source-base compilation for multiple target environments | |
| Chalupa et al. | Joint forces for memory safety checking | |
| JP4041248B2 (en) | COMPILER DEVICE, COMPUTER-READABLE RECORDING MEDIUM CONTAINING COMPILING PROGRAM, AND COMPILING METHOD | |
| CN117785540A (en) | Memory error detection method, device, equipment and media | |
| US20080120604A1 (en) | Methods, Systems, And Computer Program Products For Providing Program Runtime Data Validation | |
| CN100476735C (en) | Program processing device | |
| US8918772B1 (en) | Statically analyzing program correctness for a dynamic programming language | |
| JP5719278B2 (en) | Information processing apparatus, profile object determination program and method | |
| KR102209151B1 (en) | Method and device for patching security vulnerable executable binaries | |
| US20120023307A1 (en) | Methods, systems, and computer program products for excluding an addressable entity from a translation of source code | |
| US20120023488A1 (en) | Methods, systems, and computer program products for processing an excludable addressable entity | |
| US20110202906A1 (en) | Compiling method and compiling program | |
| KR102439456B1 (en) | Compilation device and method of partial source code | |
| CN116680705B (en) | Automatic detection method and system for Rust program defects based on feature extraction | |
| US20160253120A1 (en) | Multicore programming apparatus and method | |
| JP2018156568A (en) | Compilation device |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| A711 | Notification of change in applicant |
Free format text: JAPANESE INTERMEDIATE CODE: A712 Effective date: 20170911 |
|
| A711 | Notification of change in applicant |
Free format text: JAPANESE INTERMEDIATE CODE: A711 Effective date: 20170912 |
|
| A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20181127 |
|
| A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20190911 |
|
| A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20191015 |
|
| A02 | Decision of refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A02 Effective date: 20200407 |