User:Gso321/LLVM codegen GCC
From Gentoo Wiki
Jump to:navigation
Jump to:search
Note
mlir-gccjit is a related project that uses MLIR instead of LLVM IR (Both can expressed each other). It uses libgccjit instead of GCC GENERIC.
mlir-gccjit is a related project that uses MLIR instead of LLVM IR (Both can expressed each other). It uses libgccjit instead of GCC GENERIC.
Note
The modern inverse of this where GCC IR is compiled down through LLVM backend is Wyrm. It does require using GCC plugin and only works on GIMPLE.
The modern inverse of this where GCC IR is compiled down through LLVM backend is Wyrm. It does require using GCC plugin and only works on GIMPLE.
This will explained how to compile LLVM Bitcode (Compressed LLVM IR) to GCC backend by using GCC GENERIC IR. A example use case could be to optimize C code by using Clang's -O2 then GCC -O2 optimizations. For full source code, see this project. It aims to be faster and directly interact with GCC compared to alternative implementation with libgccjit due to limited API compared to GCC GENERIC.
Copy the files to gcc/llvm subdirectory, then run this make command:
user $
../src/configure --prefix=$(pwd)/../gcc-install --disable-bootstrap --disable-multilib --enable-languages=c,c++,llvm
user $
make -j9 CXXFLAGS="-O2 $(llvm-config --cxxflags)" LDFLAGS="$(llvm-config --libs core) $(llvm-config --ldflags)"
user $
make install -j9
Internals
GCC has to compile function tree via gimplify_function_tree() then cgraph_node::finalize_function(). The code can be borrowed from jit-playback.cc since it interacts with GENERIC's tree.