I will start with that i am vary grateful for your time.And continue with, i am sorry if my Qs aren't quite accurate( i just started with the LLVM compiler). On Sat, May 9, 2009 at 5:23 PM, Eli Friedman <eli.friedman at gmail.com> wrote:> On Sat, May 9, 2009 at 5:35 AM, Rotem Varon <varonrotem at gmail.com> wrote: > > I need to add a new optimization to the LLVM compiler. > > Knowing what the optimization does would be very helpful here. > > > The optimization ALREADY written for x86 IR (i mean that the code that > > handles the optimization is designated to work on assembly 86) . > > It's designed to work on x86 assembly, or "x86 IR"?Its not x86 IR nor x86 assembly. I have x86 IR "like" instructions ( add R1, R2, R3 and so...)> If it's really > x86 assembly, you can use LLVM's code generator to get x86 assembly,Do you mean the "llvm-gcc -S file.c" , or can i have the same effect with C++ code (API) ?> but it's extremely difficult to get back to LLVM IR.Please, its vary important for me that you elaborate why it will be extremely difficult ( i can imagine it would hard, but if you inlight me i would probably create a better design...)?> If it's > something higher-level, it might not be so bad.Do you mean, higher than IR ? like c or C++ code ...> > > > So, this is what i think - > > I will add a Basic Block Pass to the LLVM, the code of the pass will > iterate > > etch instruction and convert it to x86 IR, now the optimization will take > > place, after the optimization i will convert the x86 IR code back into > LLVM > > IR. > > To the question(s): > > Do you think my idea is a good one (if yes, do you see any > > problems implementing this)? > > Do you have another idea? > > If you're going to need conversions both ways, my guess is that it'll > be faster to just rewrite the pass as an LLVM IR pass.Can you tall me where can i fined more information about the LLVM IR pass?> It depends on > how complicated the pass is, though.Lets say its only a project (academic) ...> > Is the LLVM have such built in capability ( converting LLVM IR > to other IRs > > ) ? > > If you need a different IR, I think you'll have to write your own > converter. Converting from LLVM IR to another language generally > isn't very difficult if you don't care about the quality of the > generated code too much,Again, lets say its only a project (academic) ...> but it's a lot of work, and it seems like > code quality is important here. > > -EliIf i have a pointer to Instruction, how can i get or set the VALUE of Instruction's operands ? Thank you.> > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090509/3853c8b1/attachment.html>
On Sat, May 9, 2009 at 8:37 AM, Rotem Varon <varonrotem at gmail.com> wrote:> Its not x86 IR nor x86 assembly. I have x86 IR "like" instructions ( add > R1, R2, R3 and so...) >> >> If it's really >> x86 assembly, you can use LLVM's code generator to get x86 assembly, > > Do you mean the "llvm-gcc -S file.c" , or can i have the same effect with > C++ code (API) ?Everything in LLVM is accessible through the C++ APIs.>> but it's extremely difficult to get back to LLVM IR. > > Please, its vary important for me that you elaborate why it will > be extremely difficult ( i can imagine it would hard, but if you inlight me > i would probably create a better design...)?A lot of information gets lost when converting to assembly, like types, switches, the SSA form, etc. It's not impossible, especially if you make some assumptions about the compiler, but it's difficult enough that I wouldn't suggest it. It looks like this doesn't apply here, though.>> If it's >> something higher-level, it might not be so bad. > > Do you mean, higher than IR ? like c or C++ code ...Your IR looks high-level enough that it wouldn't be so bad. It would still be a pain to write, though.>> If you're going to need conversions both ways, my guess is that it'll >> be faster to just rewrite the pass as an LLVM IR pass. > > Can you tall me where can i fined more information about the LLVM IR pass?http://llvm.org/docs/WritingAnLLVMPass.html . Also, a bunch of other stuff in http://llvm.org/docs/ is likely to be useful.>> It depends on >> how complicated the pass is, though. > > Lets say its only a project (academic) ...Then it's probably easier to rewrite as an LLVM IR pass. There's less to worry about when you're not converting back and forth.> If i have a pointer to Instruction, how can i get or set the VALUE > of Instruction's operands ?I->getOperand(0) gets the first operand, I->setOperand(0) sets it, etc. Note that in general, the best way to get used to the API is to look at existing passes, espcecially if there's already a pass that's does stuff that's related to what you're doing. -Eli
Thank you you answer. On Sun, May 10, 2009 at 12:48 AM, Eli Friedman <eli.friedman at gmail.com>wrote:> On Sat, May 9, 2009 at 8:37 AM, Rotem Varon <varonrotem at gmail.com> wrote: > > Its not x86 IR nor x86 assembly. I have x86 IR "like" instructions ( add > > R1, R2, R3 and so...) > >> > >> If it's really > >> x86 assembly, you can use LLVM's code generator to get x86 assembly, > > > > Do you mean the "llvm-gcc -S file.c" , or can i have the same effect with > > C++ code (API) ? > > Everything in LLVM is accessible through the C++ APIs. > > >> but it's extremely difficult to get back to LLVM IR. > > > > Please, its vary important for me that you elaborate why it will > > be extremely difficult ( i can imagine it would hard, but if you inlight > me > > i would probably create a better design...)? > > A lot of information gets lost when converting to assembly, like > types, switches, the SSA form, etc. It's not impossible, especially > if you make some assumptions about the compiler, but it's difficult > enough that I wouldn't suggest it. It looks like this doesn't apply > here, though. > > >> If it's > >> something higher-level, it might not be so bad. > > > > Do you mean, higher than IR ? like c or C++ code ... > > Your IR looks high-level enough that it wouldn't be so bad. It would > still be a pain to write, though. > > >> If you're going to need conversions both ways, my guess is that it'll > >> be faster to just rewrite the pass as an LLVM IR pass. > > > > Can you tall me where can i fined more information about the LLVM IR > pass? > > http://llvm.org/docs/WritingAnLLVMPass.html . Also, a bunch of other > stuff in http://llvm.org/docs/ is likely to be useful. > > >> It depends on > >> how complicated the pass is, though. > > > > Lets say its only a project (academic) ... > > Then it's probably easier to rewrite as an LLVM IR pass. There's less > to worry about when you're not converting back and forth. > > > If i have a pointer to Instruction, how can i get or set the VALUE > > of Instruction's operands ? > > I->getOperand(0) gets the first operand, I->setOperand(0) sets it, > etc. Note that in general, the best way to get used to the API is to > look at existing passes, espcecially if there's already a pass that's > does stuff that's related to what you're doing. > > -Eli > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090510/60338093/attachment.html>