Michael, sorry for late answer, I had subproject to do and now I'm back with this topic. I'm happy I can do it and I will try. After analysis the graph I want to produce LLVM IR (from one of my graph passes) and then use the builtin optimalizations etc.<div>
<br></div><div>I didnt exactly understood your second question. I can change the metadata infrastructure, but how is it connected to this question? :)</div><div><br><br><div class="gmail_quote">2012/11/27 Michael Ilseman <span dir="ltr"><<a href="mailto:milseman@apple.com" target="_blank">milseman@apple.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div class="h5"><div>On Nov 17, 2012, at 1:56 PM, Wojciech Daniło <<a href="mailto:wojtek.danilo.ml@gmail.com" target="_blank">wojtek.danilo.ml@gmail.com</a>> wrote:</div>
<br><blockquote type="cite"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
> I know that LLVM Pass was designed to transform IR, but lets focus on an<br>
> example - LLVM Pass is a function that transform some set of input into<br>
> output. It can transform IR into graph of lets say strongly connected<br>
> components and then other passes can use it (that data - not IR) to generate<br>
> other data OR to manipulate the IR.<br>
><br>
> So why I can not create passes, that would need data generated by other<br>
> passes (ie. graph loaded from disk) and then transform it into LLVM IR? I do<br>
> not see any difference between these cases.<br>
> Am I wrong?<br>
<br>
</div>A little. That would be stretching the concepts/machinery of LLVM a<br>
little bit far, probably.<br>
<br>
A few minor corrections:<br>
<br>
Transformations in the LLVM sense are always IR to IR.<br>
When you talk about SSC & the like, those are analyses - an Analysis<br>
never modifies the IR, it only computes values from the IR it's<br>
given. Transformations then depend on (& invalidate) analyses to<br>
decide what transformations to perform.<br></blockquote><div>You are right, my nomenclature was wrong - I want to write analysis passes and one transformation pass genrating LLVM IR.</div><div> </div></div></blockquote><blockquote type="cite">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
What you're proposing is an analysis that doesn't analyze the IR at<br>
all (because there is none) - it loads information from an external<br>
source. There is one example (though I'm not sure if it's phrased as<br>
an Analysis) of that that I can think of in the current IR: profile<br>
guided optimization. The profile must be loaded from some external<br>
source, references built up to the IR, and then Transformations can<br>
depend on this information when choosing how to optimize.<br>
<br>
Effectively your graph transformations would exist purely as analyses<br>
- transforming non-IR data from pass to pass until you reached some<br>
transformation that would transform null IR into the actual IR<br>
represented by the graph from the analyses.<br>
<br>
It's not really going to give you a lot of value compared to just<br>
building your own graph transformation pipeline & then producing IR at<br>
the end of that.<br></blockquote><div>It allows me to use LLVM dependency pass manager - with analysis groups etc. I would have to write exactly the same the other way, I think.</div><div> </div></div></blockquote><div><br>
</div></div></div><div>But you wouldn't be able to reuse any of the analyses themselves, as they are all written for IR. You could certainly derive your own class from one of the PassManagers to operate over your graph representation. LLVM may not have something for your particular use out-of-the-box, but it might be easy enough for you to make your own pass manager given what's already there.</div>
<div class="im"><br><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
To come back to your original question: "I want to write a compiler<br>
<div>that does NOT generate LLVM IR by its own, it should simply run one of<br>
</div>available module passes and such pass will generate LLVM IR" - why do<br>
you want to do this? You're just going to have to write the graph-IR<br>
transformation sooner or later anyway? Why not do it as the first step<br>
& then do IR level optimizations? (I'm not saying there's no reason to<br>
do this, I'm just wondering what /your/ reasons are)<br></blockquote><div>The answer is simple - In the graph loaded from disk there is a lot more information than in generated IR, so I want to do some transformations on the beginning. (There are other reasons, but this one is one of the biggest).</div>
</div></blockquote><div><br></div></div><div>For optimizing with source-level information, do you need to do them in conjunction with lots of analyses? If so, can you leverage the existing metadata infrastructure for your own purposes?</div>
<div><div class="h5"><div><br></div><br><blockquote type="cite"><div class="gmail_quote">
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><font color="#888888"><br>
- David<br>
</font></span><div><div><br>
><br>
><br>
> 2012/11/17 David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>><br>
>><br>
>> On Sat, Nov 17, 2012 at 4:44 AM, Wojciech Daniło<br>
>> <<a href="mailto:wojtek.danilo.ml@gmail.com" target="_blank">wojtek.danilo.ml@gmail.com</a>> wrote:<br>
>> > Hi!<br>
>> > I'm new to LLVM but I've read tons of articles, I want to implement my<br>
>> > own<br>
>> > compiler and I came across a big problem.<br>
>> > I have several questions, that I cannot answer myself:<br>
>> ><br>
>> > 1) If I'm writing custom compiler do I have to "hardcode" passes that it<br>
>> > uses (like in Kaleidoscope example:<br>
>> > <a href="http://llvm.org/docs/tutorial/LangImpl4.html" target="_blank">http://llvm.org/docs/tutorial/LangImpl4.html</a>) or I have to generate LLVM<br>
>> > IR<br>
>> > and then use the 'opt' tool to run selected passes on generated code?<br>
>> > I think the solution with opt is not quite good, because the opt tool<br>
>> > has to<br>
>> > parse the LLVM IR (or BC) input file, which is not needed, because we<br>
>> > are<br>
>> > generating it, so we have had it in memory before.<br>
>> > Maybe there is another better solution allowing for enabling and<br>
>> > disabling<br>
>> > passes in custom compiler with argument options like in opt?<br>
>><br>
>> I believe Clang just hardcodes passes. If you a user wants to<br>
>> experiment with different pass options they can use the option to<br>
>> generate LLVM bitcode from Clang then pass that to opt themselves.<br>
>><br>
>> > 2) I want to write compiler that does NOT generate LLVM IR by its own,<br>
>> > it<br>
>> > should simply run one of available module passes and such pass will<br>
>> > generate<br>
>> > LLVM IR.<br>
>> > The motivation behind this decision is that I want to have a graph (C++<br>
>> > serialized structure) as compiler input and I want to load this graph as<br>
>> > pass, run other passes (which will modify this graph) and then run a<br>
>> > "conversion module pass", which will convert this graph into LLVM IR.<br>
>> > Additional I want to be able to read several formats and because of that<br>
>> > I<br>
>> > want to load this graph as a pass. (This pass will be of course grouped<br>
>> > with<br>
>> > other "load passes")<br>
>><br>
>> LLVM's pass system is for IR transformations only. Anything else you<br>
>> want to do you'll have to build separately/in front of LLVM. Once your<br>
>> other system generates IR, then you can pass it to LLVM.<br>
>><br>
>> ><br>
>> > Could you please tell me what will be the best (most flexible and easy)<br>
>> > solution to do this, keeping in mind the first question?<br>
>> ><br>
>> > I have an idea of solution (which does not work completely) - the idea<br>
>> > is to<br>
>> > create an compiler which will initialize the base module and will do<br>
>> > nothing<br>
>> > at all. Then I can use the opt tool with my module passes, which will<br>
>> > load,<br>
>> > modify graph and convert it to LLVM IR (with IRBUilder) - the problem is<br>
>> > if<br>
>> > the opt could be run without input file and if it will handle correctly<br>
>> > this<br>
>> > situation.<br>
>> ><br>
>> > I was researching very long and I have not found any good answer for<br>
>> > these<br>
>> > problems.<br>
>> > I would be very thankful for any help!<br>
>> ><br>
>> > _______________________________________________<br>
>> > LLVM Developers mailing list<br>
>> > <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>
_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote></div></div></div><br></div></blockquote></div><br></div>