Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting GCC IR to LLVM IR

Tags:

c++

c

gcc

llvm

I have written an LLVM pass that modifies the Intermediate Representation (IR) code. To increase portability, I also want it to work with a gcc compiler. So I was wondering if there is any tool which can convert some Intermediate Representation (IR) of gcc to LLVM IR.

like image 238
pythonic Avatar asked Dec 06 '12 17:12

pythonic


People also ask

Is LLVM IR assembly?

LLVM IR is a low-level intermediate representation used by the LLVM compiler framework. You can think of LLVM IR as a platform-independent assembly language with an infinite number of function local registers.

Does GCC have an IR?

The data structure that the compiler translates your source code into is called an Intermediate Representation (IR), and gcc has three of them! This part of the compiler that parses the source code into IR is known as the front end.

How do you read LLVM IR?

LLVM uses BasicBlock to represent groups of instructions, and a basic block has an exit point and a list of instructions. My guess would be that the compiler has decided to use the return as the exit from the basic block and has opted to put in at least one instruction into the block.

How big is LLVM?

An LLVM-only build will need about 1-3 GB of space. A full build of LLVM and Clang will need around 15-20 GB of disk space. The exact space requirements will vary by system. (It is so large because of all the debugging information and the fact that the libraries are statically linked into multiple tools).


1 Answers

You probably want dragonegg (which is using the GCC front-end to build an LLVM IR).

And if you wanted to work on the GCC internal representations, MELT (a high level domain specific language to extend GCC) is probably the right tool.

like image 51
Basile Starynkevitch Avatar answered Sep 24 '22 10:09

Basile Starynkevitch