[LLVMdev] Dynamic optimalization passes in LLVM based compiler

David Blaikie dblaikie at gmail.com
Sat Nov 17 08:07:42 PST 2012


On Sat, Nov 17, 2012 at 4:44 AM, Wojciech DaniƂo
<wojtek.danilo.ml at gmail.com> wrote:
> Hi!
> I'm new to LLVM but I've read tons of articles, I want to implement my own
> compiler and I came across a big problem.
> I have several questions, that I cannot answer myself:
>
> 1) If I'm writing custom compiler do I have to "hardcode" passes that it
> uses (like in Kaleidoscope example:
> http://llvm.org/docs/tutorial/LangImpl4.html) or I have to generate LLVM IR
> and then use the 'opt' tool to run selected passes on generated code?
> I think the solution with opt is not quite good, because the opt tool has to
> parse the LLVM IR (or BC) input file, which is not needed, because we are
> generating it, so we have had it in memory before.
> Maybe there is another better solution allowing for enabling and disabling
> passes in custom compiler with argument options like in opt?

I believe Clang just hardcodes passes. If you a user wants to
experiment with different pass options they can use the option to
generate LLVM bitcode from Clang then pass that to opt themselves.

> 2) I want to write compiler that does NOT generate LLVM IR by its own, it
> should simply run one of available module passes and such pass will generate
> LLVM IR.
> The motivation behind this decision is that I want to have a graph (C++
> serialized structure) as compiler input and I want to load this graph as
> pass, run other passes (which will modify this graph) and then run a
> "conversion module pass", which will convert this graph into LLVM IR.
> Additional I want to be able to read several formats and because of that I
> want to load this graph as a pass. (This pass will be of course grouped with
> other "load passes")

LLVM's pass system is for IR transformations only. Anything else you
want to do you'll have to build separately/in front of LLVM. Once your
other system generates IR, then you can pass it to LLVM.

>
> Could you please tell me what will be the best (most flexible and easy)
> solution to do this, keeping in mind the first question?
>
> I have an idea of solution (which does not work completely) - the idea is to
> create an compiler which will initialize the base module and will do nothing
> at all. Then I can use the opt tool with my module passes, which will load,
> modify graph and convert it to LLVM IR (with IRBUilder) - the problem is if
> the opt could be run without input file and if it will handle correctly this
> situation.
>
> I was researching very long and I have not found any good answer for these
> problems.
> I would be very thankful for any help!
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list