Hi, I am new to LLVM. I want to use LLVM to instrument codes, such as function calls and basic blocks. But I don't know where to start. I wonder if there are any example codes to show how to instrument codes in the IR level? Thanks. -- zhouxu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111031/9d09abb5/attachment.html>
Hi,> I am new to LLVM. I want to use LLVM to instrument codes, such as > function calls and basic blocks. But I don't know where to start. I wonder > if there are any example codes to show how to instrument codes in the IR > level?No idea what exactly you want to achieve, but let me try. First, you might need a function doing the instrument. Say, void HowManyTimeThisFunctionGetCalled(); Then you can insert a call to the function above while creating a LLVM function [1]. In that way, every time that LLVM function get called the function doing the instrument will be called. You might need to take a look on ${LLVM_SOURCE}/example/HowToUseJIT to get a feel on how to create a LLVM module, function and basic block. Regards, chenwj [1] http://llvm.org/docs/ProgrammersManual.html#Function -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667
On 10/31/2011 2:53 AM, zhouxu(NUDT) wrote:> Hi, > I am new to LLVM. I want to use LLVM to instrument codes, such as > function calls and basic blocks. But I don't know where to start. I > wonder if there are any example codes to show how to instrument codes > in the IR level?First, have you read the Language Reference Manual, the Programmer's Manual, and the How to Write an LLVM Pass manual at http://llvm.org/docs? Those are pretty much required reading for staring to learn how to write LLVM transform passes. As you start coding, you'll find the doxygen docs (also on that web page) extremely valuable. As for examples, you might want to take a look at some of the passes in the SAFECode project (http://sva.cs.illinois.edu). The load/store instrumentation pass (safecode/lib/InsertPoolChecks/LoadStoreChecks.cpp) is a very simple example of a pass that instruments every load and store. Modifying that code to instrument function calls and basic blocks should be straightforward. There are, of course, numerous examples in LLVM itself (in lib/Transforms), too, although I'm not sure which passes are going to be small and trivial (maybe the profiling instrumentation passes). -- John T.> Thanks. > > > > -- > zhouxu > > > _______________________________________________ > 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/20111103/30e0aacf/attachment.html>
> > > First, have you read the Language Reference Manual, the Programmer's > Manual, and the How to Write an LLVM Pass manual at http://llvm.org/docs? > Those are pretty much required reading for staring to learn how to write > LLVM transform passes. >I have read the docs, and I am concerning about coding. What I need is something like the API reference of LLVM. And I cannot find such docs.> There are, of course, numerous examples in LLVM itself (in > lib/Transforms), too, although I'm not sure which passes are going to be > small and trivial (maybe the profiling instrumentation passes). > > I think the code example in Transforms/Instrumentation is much helpful. Itis simple and understandable for a beginner. Thanks! -- zhouxu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111104/d4eb4c2c/attachment.html>
> No idea what exactly you want to achieve, but let me try. > > First, you might need a function doing the instrument. Say, > > void HowManyTimeThisFunctionGetCalled(); > > Then you can insert a call to the function above while creating > a LLVM function [1]. In that way, every time that LLVM function > get called the function doing the instrument will be called. > > You might need to take a look on ${LLVM_SOURCE}/example/HowToUseJIT > to get a feel on how to create a LLVM module, function and basic block. > > Regards, > chenwj > > [1] http://llvm.org/docs/ProgrammersManual.html#Function > >Yes, instrumenting functions is just one of my purpose. The API document (though not very detailed) your provide is helpful. However, the problem of the document is that it is not up-to-date. For example, "Type::Int32Ty" is not used to acquire an integer type in LLVM2.9. So sometimes it cause confusion to me. Thanks. -- zhouxu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111104/d887711a/attachment.html>