コグノスケ


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 21年3月13日
    すずきさん (03/05 15:13)
    「あー、このプログラムがまずいんですね。ご...」
  • link 21年3月13日
    emkさん (03/05 12:44)
    「キャストでvolatileを外してアクセ...」
  • link 24年1月24日
    すずきさん (02/19 18:37)
    「簡単にできる方法はPowerShellの...」
  • link 24年1月24日
    KKKさん (02/19 02:30)
    「追伸です。\nネットで調べたらマイクロソ...」
  • link 24年1月24日
    KKKさん (02/19 02:25)
    「私もエラーで困ってます\n手動での回復パ...」

最近の記事20件

  • link 24年3月25日
    すずき (03/26 03:20)
    「[Might and Magic Book One TASのその後] 目次: Might and Magicファミコン版以前(...」
  • link 21年10月4日
    すずき (03/26 03:14)
    「[Might and Magicファミコン版 - まとめリンク] 目次: Might and Magicファミコン版TASに挑...」
  • link 24年3月19日
    すずき (03/20 02:52)
    「[モジュラージャックの規格] 古くは電話線で、今だとEthernetで良く見かけるモジュラージャックというコネクタとレセプタク...」
  • link 23年4月10日
    すずき (03/19 11:48)
    「[Linux - まとめリンク] 目次: Linuxカーネル、ドライバ関連。Linuxのstruct pageって何?Linu...」
  • link 24年3月18日
    すずき (03/19 11:47)
    「[画面のブランクを無効にする] 目次: LinuxROCK 3 model CのDebian bullseyeイメージは10分...」
  • link 24年3月3日
    すずき (03/19 11:07)
    「[解像度の設定を保存する] 目次: LinuxRaspberry Pi 3 Model B (以降RasPi 3B)のHDMI...」
  • link 24年3月14日
    すずき (03/16 23:03)
    「[JavaとM5Stamp C3とBluetooth LE - Bluetoothデバイスとの通信] 目次: ArduinoM...」
  • link 24年3月8日
    すずき (03/16 23:03)
    「[JavaとM5Stamp C3とBluetooth LE - BluetoothデバイスとServiceの列挙] 目次: A...」
  • link 23年6月2日
    すずき (03/16 21:11)
    「[Arduino - まとめリンク] 目次: Arduino一覧が欲しくなったので作りました。 M5Stackとesp32とA...」
  • link 23年5月15日
    すずき (03/16 00:57)
    「[車 - まとめリンク] 目次: 車三菱FTOの話。群馬県へのドライブ将来車を買い替えるとしたら?FTOのオイル交換とオイル漏...」
  • link 24年3月9日
    すずき (03/16 00:56)
    「[車のバッテリー完全に死亡で交換かと思いきや] 目次: 車またまた車のバッテリーが干上がって死にました。写真は撮っていませんが...」
  • link 24年3月10日
    すずき (03/15 03:34)
    「[誕生日] 早いもので41歳になりました。昨年の日記(2023年3月10日の日記参照)を見ると、コロナの流行を心配していました...」
  • link 24年3月6日
    すずき (03/12 01:18)
    「[Raspberry Pi 3 model Bの代わりにROCK 3 model C] 目次: Arduino最近、M5Sta...」
  • link 24年3月4日
    すずき (03/06 00:09)
    「[volatileをnon-volatileで参照してはいけない] 目次: GCC過去の日記(2021年3月13日の日記参照)...」
  • link 20年6月2日
    すずき (03/06 00:06)
    「[GCC - まとめリンク] 目次: GCCGCCについて。GCCを調べる - その1 - ビルドGCCを調べる - その2 ...」
  • link 15年5月9日
    すずき (03/05 03:00)
    「[自作ARMエミュレータ - 今さら気づいたブートローダのバグ] 目次: Linuxずっと気づいていなかった自作ARMエミュレ...」
  • link 23年6月1日
    すずき (03/05 02:59)
    「[自宅サーバー - まとめリンク] 目次: 自宅サーバーこの日記システム、Wikiの話。カウンターをPerlからPHPに移植日...」
  • link 15年5月3日
    すずき (03/05 02:59)
    「[GRUB2が起動しなくなってしまった] 目次: 自宅サーバーサーバにインストールしていたDebian 32bit版 のJes...」
  • link 15年5月2日
    すずき (03/05 02:58)
    「[systemdを使うのをあきらめた] 目次: 自宅サーバー独自ビルドのカーネルだと/sys/fs/cgroupが無いと言われ...」
  • link 15年4月30日
    すずき (03/05 02:56)
    「[Debian 8.0 Jessie] 目次: 自宅サーバーDebianのアップデートが来ていたので、試しに職場のPCをアップ...」
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

最終更新: 03/26 03:20