[LLVMdev] Dynamic optimalization passes in LLVM based compiler

Wojciech DaniƂo wojtek.danilo.ml at gmail.com
Sat Nov 17 04:44:21 PST 2012


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?

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")

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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121117/b24ad75a/attachment.html>


More information about the llvm-dev mailing list