Take the 2-minute tour ×

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.

share|improve this question
+1 for compensating the pain the LLVM API may probably have caused. –  user529758 Dec 6 '12 at 17:07
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
Thanks for your suggestion. But is there also a way to convert GCC IR to LLVM IR and then back to GCC IR? So that I don't have to modify either of the front or backend. –  user1018562 Dec 6 '12 at 17:26
I am not sure LLVM IR & GCC IR are isomorphic (and I am quite sure they are not - the evil is always in the details). But what exactly do you want to achieve, and why do you ask? Why the concern on going back & forth between GCC & LLVM IR??? –  Basile Starynkevitch Dec 6 '12 at 17:29
Well what I want to achieve is to translate GCC IR to LLVM IR, apply my pass, which modifies the IR and then translate the resulting LLVM IR back to the GCC IR, so that the gcc backend can resume from there. Because I'm working on a platform which has gcc as its compiler, so its not possible to have LLVM there. –  user1018562 Dec 6 '12 at 17:40
Don't do that. Either work on the LLVM IR or on the GCC IR, but not both. –  Basile Starynkevitch Dec 6 '12 at 17:43
add comment

It will probably be much easier to simply write another version of your code that works with gcc IR. What you want to do is likely not possible, and if it is possible, it's probably extremely difficult. (More so than writing the LLVM pass in the first place.)

share|improve this answer
I definitely agree. Working back and forth from GCC IR to LLVM IR is non-sense! (and if you did it would be a nightmare). –  Basile Starynkevitch Dec 6 '12 at 17:44
add comment

Your Answer


