I would love to ask you one more question. You have written:<div><span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></span></div><div><span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">It's not really going to give you a lot of value compared to just</span><br style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">building your own graph transformation pipeline & then producing IR at</span><br style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(80,0,80);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">the end of that.</span></div><div><br></div><div>Could you please tell more about this topic? Why my custom solution (custom pass manager etc) would be better than making LLVM (non IR) passes?</div>
<div><br><div class="gmail_quote">2012/11/17 Wojciech Daniło <span dir="ltr"><<a href="mailto:wojtek.danilo.ml@gmail.com" target="_blank">wojtek.danilo.ml@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><div class="gmail_quote"><div class="im"><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><div>You are right, my nomenclature was wrong - I want to write analysis passes and one transformation pass genrating LLVM IR.</div><div class="im"><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc 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><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 class="im"><div> </div><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><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><div class="h5">
<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></div></div><br>
</blockquote></div><br></div>