コグノスケ


link 未来から過去へ表示(*)  link 過去から未来へ表示

link もっと前
2019年6月14日 >>> 2019年6月14日
link もっと後

2019年6月14日

GCCを調べる - その3 - RTL (Register Transfer Language) の出力

目次: GCC

GCCの内部情報を出力してみます。GCCのバックエンドはGIMPLEとRTL (Register Transfer Language) があります。

ざっくり言ってC言語(など)→ GIMPLE → RTL → アセンブラの順に変換されます。GIMPLEの内容はまだよく知らないので説明できません……。今回はRTLを見ていこうと思います。

RTLを出力する方法

GCCでRTLを出力するには、コンパイル時に-fdump-rtl-allオプションを付けます。

RTLの出力オプション

$ riscv32-unknown-elf-gcc a.c -fdump-rtl-all

試しに下記のコードをコンパイルし、RTLを出力させると、

サンプルコード(C言語, a.c)

void main()
{
        int a = 1, b = 2, c;

        c = a + b;

        return c;
}

下記のようなRTLが出力されます(GCC-8.3.0での結果)。C言語のファイル名がa.cだとすると、RTLはa.c.NNNr.XXXXという名前で出力されます。NNNは最適化パスの番号、XXXXは最適化パスの名前が入ります。

サンプルコード(RTL, a.c.235r.vregs)

;; Function main (main, funcdef_no=0, decl_uid=1514, cgraph_uid=0, symbol_order=0)

(note 1 0 3 NOTE_INSN_DELETED)
(note 3 1 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 2 3 5 2 NOTE_INSN_FUNCTION_BEG)
(insn 5 2 6 2 (set (reg:SI 104)
        (const_int 1 [0x1])) "a.c":3 132 {*movsi_internal}
     (nil))
(insn 6 5 7 2 (set (mem/c:SI (plus:SI (reg/f:SI 65 frame)
                (const_int -4 [0xfffffffffffffffc])) [1 a+0 S4 A32])
        (reg:SI 104)) "a.c":3 132 {*movsi_internal}
     (nil))
(insn 7 6 8 2 (set (reg:SI 105)
        (const_int 2 [0x2])) "a.c":3 132 {*movsi_internal}
     (nil))
(insn 8 7 9 2 (set (mem/c:SI (plus:SI (reg/f:SI 65 frame)
                (const_int -8 [0xfffffffffffffff8])) [1 b+0 S4 A32])
        (reg:SI 105)) "a.c":3 132 {*movsi_internal}
     (nil))
(insn 9 8 10 2 (set (reg:SI 107)
        (mem/c:SI (plus:SI (reg/f:SI 65 frame)
                (const_int -4 [0xfffffffffffffffc])) [1 a+0 S4 A32])) "a.c":5 132 {*movsi_internal}
     (nil))
(insn 10 9 11 2 (set (reg:SI 108)
        (mem/c:SI (plus:SI (reg/f:SI 65 frame)
                (const_int -8 [0xfffffffffffffff8])) [1 b+0 S4 A32])) "a.c":5 132 {*movsi_internal}
     (nil))
(insn 11 10 12 2 (set (reg:SI 106)
        (plus:SI (reg:SI 107)
            (reg:SI 108))) "a.c":5 3 {addsi3}
     (nil))
(insn 12 11 17 2 (set (mem/c:SI (plus:SI (reg/f:SI 65 frame)
                (const_int -12 [0xfffffffffffffff4])) [1 c+0 S4 A32])
        (reg:SI 106)) "a.c":5 132 {*movsi_internal}
     (nil))
(insn 17 12 0 2 (const_int 0 [0]) "a.c":7 240 {nop}
     (nil))

RTLは最適化処理を実行するたびに内容が変わるため、たくさんのファイルが出力されます。上記のRTLはGIMPLEからRTLに変換した後、命令割当のみ行った状態のものです。最適化パス名でいうとvregsというパスが終わった後のRTL です。

長くなってきたので分割します。

編集者:すずき(2023/09/24 11:46)

コメント一覧

  • コメントはありません。
open/close この記事にコメントする



link もっと前
2019年6月14日 >>> 2019年6月14日
link もっと後

管理用メニュー

link 記事を新規作成

<2019>
<<<06>>>
------1
2345678
9101112131415
16171819202122
23242526272829
30------

最近のコメント5件

  • link 24年4月22日
    hdkさん (04/24 08:36)
    「うちのHHFZ4310は15年突破しまし...」
  • link 24年4月22日
    すずきさん (04/24 00:37)
    「ちゃんと数えてないですけど蛍光管が10年...」
  • link 24年4月22日
    hdkさん (04/23 20:52)
    「おお... うちのHHFZ4310より後...」
  • link 20年6月19日
    すずきさん (04/06 22:54)
    「ディレクトリを予め作成しておけば良いです...」
  • link 20年6月19日
    斎藤さん (04/06 16:25)
    「「Preferencesというメニューか...」

最近の記事3件

  • link 24年2月7日
    すずき (04/24 02:52)
    「[複数の音声ファイルのラウドネスを統一したい] PCやデジタル音楽プレーヤーで音楽を聞いていると、曲によって音量の大小が激しく...」
  • link 24年4月22日
    すずき (04/23 20:13)
    「[仕事部屋の照明が壊れた] いきなり仕事部屋のシーリングライトが消えました。蛍光管の寿命にしては去年(2022年10月19日の...」
  • link 24年4月17日
    すずき (04/18 22:44)
    「[VSCodeとMarkdownとPlantUMLのローカルサーバー] 目次: LinuxVSCodeのPlantUML Ex...」
link もっとみる

こんてんつ

open/close wiki
open/close Linux JM
open/close Java API

過去の日記

open/close 2002年
open/close 2003年
open/close 2004年
open/close 2005年
open/close 2006年
open/close 2007年
open/close 2008年
open/close 2009年
open/close 2010年
open/close 2011年
open/close 2012年
open/close 2013年
open/close 2014年
open/close 2015年
open/close 2016年
open/close 2017年
open/close 2018年
open/close 2019年
open/close 2020年
open/close 2021年
open/close 2022年
open/close 2023年
open/close 2024年
open/close 過去日記について

その他の情報

open/close アクセス統計
open/close サーバ一覧
open/close サイトの情報

合計:  counter total
本日:  counter today

link About www.katsuster.net
RDFファイル RSS 1.0

最終更新: 04/24 08:36