User:Gso321/LLVM codegen GCC
From Gentoo Wiki
Jump to:navigation
Jump to:search
Note
This page can be edited by anyone. mlir-gccjit is a related project that uses MLIR instead of LLVM IR (Both can expressed each other). It does require cmake and C++.
This page can be edited by anyone. mlir-gccjit is a related project that uses MLIR instead of LLVM IR (Both can expressed each other). It does require cmake and C++.
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. Ideally, RTL to get target dependent optimizations would be better but this is the most modern progress on GCC IR to LLVM backend converter I could find.
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. Ideally, RTL to get target dependent optimizations would be better but this is the most modern progress on GCC IR to LLVM backend converter I could find.
This will explained how to compile LLVM Bitcode (Compressed LLVM IR) to GCC backend by outputting GNU C++ to be compiled by GCC, written in C. 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. This does not use libgccjit due to limited API compared to GNU C++. C is not used because LLVM IR has exceptions instructions and others that only works on GNU C++.
BPPIR
LLVM bitcode file is converted to Before C++ IR:
FILE
bppir.h
BPPIR main()extern struct llvm_codegen_gcc_bppir *llvm_codegen_gcc_filename_to_bppir(const char * restrict path);
This is because a C++ file will first have C++ headers, user defined types dec, function/(global variables) declaration then function/(global variables) definition.
Using struct llvm_codegen_gcc_bppir makes it easier to print C++.