Hi All, I am a newbie to LLVM and I would like to write an LLVM pass where I can transform C code. Say, I would like to introduce a print statement after every loop. Could you please provide me any hints as how I should proceed to write such transformation using LLVM? Also, I would like to analyze C Code and transform. Say, I would like to use Alias analysis and decide to introduce print statements for some pointer variables inside the code itself. Any suggestion as where I should start? I've been going through documentation like, writing an LLVM Pass , but I guess, I need much more exposure than just going through such documentation. Also, do I need to look at CLANG? How is it different from writing the LLVM pass to perform the above mentioned tasks? Finally, did anyone compile Linux kernel using LLVM and booted the same? I am facing the error like "unsupported inline asm:...". Please help me with all these. And I appreciate your support and patience. Thanks, GK
Hi, Gondi> Finally, did anyone compile Linux kernel using LLVM and booted the same? I > am facing the error like "unsupported inline asm:...".It seems that LLVM does not support all inline assembly. Regards, chenwj -- Wei-Ren Chen (陳韋任) Parallel Processing Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667
On 3/23/11 11:44 PM, 陳韋任 wrote:> Hi, Gondi > >> Finally, did anyone compile Linux kernel using LLVM and booted the same? I >> am facing the error like "unsupported inline asm:...". > It seems that LLVM does not support all inline assembly.LLVM does support inline assembly, although some inline asm constraints may not be supported yet. You might find some documentation on the level of support by searching through the bug database. -- John T.> Regards, > chenwj >
On Wed, Mar 23, 2011 at 9:15 PM, Gondi, Kalpana <kgondi2 at uic.edu> wrote:> Hi All, > I am a newbie to LLVM and I would like to write an LLVM pass where I can > transform C code. Say, I would like to introduce a print statement after > every loop. Could you please provide me any hints as how I should proceed > to write such transformation using LLVM? > Also, I would like to analyze C Code and transform. Say, I would like to > use Alias analysis and decide to introduce print statements for some > pointer variables inside the code itself. Any suggestion as where I should > start? > > I've been going through documentation like, writing an LLVM Pass , but I > guess, I need much more exposure than just going through such > documentation.If you haven't looked at http://llvm.org/docs/tutorial/ , I would suggest taking a look; it's only partially relevant to what you're asking, but should give you a better feel for how stuff works.> Also, do I need to look at CLANG? How is it different from writing the > LLVM pass to perform the above mentioned tasks?It's different: clang has a rewriter you can use, for example, to insert a call after every loop. You end up with a different definition of "loop", though: at the clang level, you'll see the AST nodes for "for" and "while" loops; at the IR level, you'll see constructs which are structurally loops.> Finally, did anyone compile Linux kernel using LLVM and booted the same? I > am facing the error like "unsupported inline asm:...".IIRC, llvm-gcc is affected by some bugs related to inline asm which will likely never be fixed that affect the Linux kernel (llvm-gcc is considered deprecated). See http://llvm.org/bugs/attachment.cgi?id=3486 for building it with clang; the kernel tends to use all sorts of obscure/nasty gcc flags and constructs, which makes things tricky. -Eli
On Wed, Mar 23, 2011 at 9:49 PM, Eli Friedman <eli.friedman at gmail.com> wrote:> On Wed, Mar 23, 2011 at 9:15 PM, Gondi, Kalpana <kgondi2 at uic.edu> wrote: >> Hi All, >> I am a newbie to LLVM and I would like to write an LLVM pass where I can >> transform C code. Say, I would like to introduce a print statement after >> every loop. Could you please provide me any hints as how I should proceed >> to write such transformation using LLVM? >> Also, I would like to analyze C Code and transform. Say, I would like to >> use Alias analysis and decide to introduce print statements for some >> pointer variables inside the code itself. Any suggestion as where I should >> start? >> >> I've been going through documentation like, writing an LLVM Pass , but I >> guess, I need much more exposure than just going through such >> documentation. > > If you haven't looked at http://llvm.org/docs/tutorial/ , I would > suggest taking a look; it's only partially relevant to what you're > asking, but should give you a better feel for how stuff works. > >> Also, do I need to look at CLANG? How is it different from writing the >> LLVM pass to perform the above mentioned tasks? > > It's different: clang has a rewriter you can use, for example, to > insert a call after every loop. You end up with a different > definition of "loop", though: at the clang level, you'll see the AST > nodes for "for" and "while" loops; at the IR level, you'll see > constructs which are structurally loops. > >> Finally, did anyone compile Linux kernel using LLVM and booted the same? I >> am facing the error like "unsupported inline asm:...". > > IIRC, llvm-gcc is affected by some bugs related to inline asm which > will likely never be fixed that affect the Linux kernel (llvm-gcc is > considered deprecated). See > http://llvm.org/bugs/attachment.cgi?id=3486 for building it with > clang; the kernel tends to use all sorts of obscure/nasty gcc flags > and constructs, which makes things tricky.Err, make that http://llvm.org/bugs/show_bug.cgi?id=4068 ; accidentally copy-pasted the wrong link. -Eli
On 3/23/11 11:15 PM, Gondi, Kalpana wrote:> Hi All, > I am a newbie to LLVM and I would like to write an LLVM pass where I can > transform C code. Say, I would like to introduce a print statement after > every loop. Could you please provide me any hints as how I should proceed > to write such transformation using LLVM?You essentially want to create a call instruction to printf. Look for the doxygen documentation on the llvm.org web site and look for the llvm::CallInst class. The Create() method of CallInst is what you want to use.> Also, I would like to analyze C Code and transform. Say, I would like to > use Alias analysis and decide to introduce print statements for some > pointer variables inside the code itself. Any suggestion as where I should > start?Try to find examples that use the AliasAnalysis interface. The interface itself should be defined in a header file; it should be pretty easy to use, although the underlying implementation is still pretty simple, as far as I know.> I've been going through documentation like, writing an LLVM Pass , but I > guess, I need much more exposure than just going through such > documentation. > > Also, do I need to look at CLANG? How is it different from writing the > LLVM pass to perform the above mentioned tasks?Clang is useful for working with source-level ASTs.> Finally, did anyone compile Linux kernel using LLVM and booted the same? I > am facing the error like "unsupported inline asm:...".Yes and no, depending on one's perspective. I ported Linux 2.4 to a virtual architecture, meaning that I ripped out all the inline asm code and replaced it with calls to my VM which implemented it own assembly code. The C code parts of the kernel were compiled with LLVM. I think other people have compiled Linux 2.6 out-of-the-box (or pretty close to it) with newer versions of LLVM. I'll let them comment. -- John T.> Please help me with all these. And I appreciate your support and patience. > > Thanks, > GK > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev