gccgimple

Can GCC compile GIMPLE?


GIMPLE is one of internal representations in GCC system. It is possible to dump GIMPLE or any other internal representation via -fdump-* compiler argument. But is there any way to compile dumped GIMPLE or any other representation? It seems that GCC doesn't have GIMPLE front-end. What I'd like to do is to dump, analyze, modify and then recompile dumped GIMPLE to perform various code instrumentations.

PS I know about GCC plugins, and I know about LLVM/Clang, so please try to answer the exact question and do not suggest alternative solutions. Thanks!


Solution

  • This project is called GIMPLE FE (front-end). The first try never reached a usable state. It was restarted during GSoC'16, merged into gcc-8, and has been regularly improving since. It is enabled with -fgimple.

    The goal is to help write testcases. It is not a complete dump/reload facility as llvm provides. The dumps you get with -fdump-* (there is a -gimple modifier, as in -fdump-tree-all-gimple, to get a syntax that matches what the FE reads) are nice to let you know what is going on, but they don't contain enough information to rebuild the internal structures. And the FE reads a dialect that only lets you specify a small subset of the information that GIMPLE can encode.

    Similarly, there exists a partial RTL front-end, for this other internal representation of gcc.

    A more complete dump/reload is provided by LTO. When you compile a file with -flto -c, gcc saves a bytecode representation of GIMPLE in a section of the .o file, which it can read again when called as a linker. This representation is almost complete (there are some issues with debug information I think). However, it is not meant to be easy to read like a text dump, and the exact format changes with every minor version of the compiler. Also, you can only dump/reload at one predefined point in the pipeline, not after an arbitrary pass.