Daniel Liew
2013-Aug-30 11:38 UTC
[LLVMdev] Help with LLVM Bitcode function inlining and duplicating debug information on instructions
Hi, I'm working on a tool (KLEE) that interprets LLVM bitcode. One of the things it does is it instruments the LLVM bitcode with checks for division by zero. It does this by injecting calls to a function "klee_div_zero_check(long long divisor)" just before every division instruction (e.g. SDiv). These checks are injected by a pass that has been implemented in KLEE. This klee_div_zero_check() function is implemented in C and is compiled to LLVM Bitcode which is then linked into the module that KLEE is interpreting. I need to change the modify the LLVM bitcode module slightly and I'm not sure how to do this using the LLVM C++ APIs. So any help would be appreciated. Here are the two things I want to do... 1. Inline all calls to klee_div_zero_check() in the LLVM bitcode module being interpreted. I tried using the always_inline attribute on the C definition of klee_div_zero_check(), i.e. void __attribute__((always_inline)) klee_div_zero_check(long long z) but that only added the keyword "alwaysinline" to the klee_div_zero_check() function in the LLVM bitcode module, it didn't do any actual inlining. I see the LLVM API has the function llvm::InlineFunction(CallInst *CI, InlineFunctionInfo &IFI, bool InsertLifetime) Should I be using this to inline all calls in a module to a particular function or is there a better way? If so what is IFI supposed to be set to? 2. I want to duplicated the debug (filename and line number information) on the division instruction (e.g. SDiv) onto every instruction (including the instructions that come from inlining klee_div_zero_check ) that I inject into the LLVM bitcode module (during the pass). The reason for wanting to do this is because when KLEE reports an error it looks at the debug information of the previous instruction. Currently the debug information references the file that klee_div_zero_check() is defined in (which is useless for error reporting) rather than the debug information for the division instruction I am trying to instrument. So how would I go about doing this using the LLVM C++ APIs? Thanks, Dan Liew.
David Blaikie
2013-Aug-30 15:20 UTC
[LLVMdev] Help with LLVM Bitcode function inlining and duplicating debug information on instructions
On Fri, Aug 30, 2013 at 4:38 AM, Daniel Liew <daniel.liew at imperial.ac.uk> wrote:> Hi, > > I'm working on a tool (KLEE) that interprets LLVM bitcode. > > One of the things it does is it instruments the LLVM bitcode with > checks for division by zero. It does this by injecting calls to a > function "klee_div_zero_check(long long divisor)" just before every > division instruction (e.g. SDiv). These checks are injected by a pass > that has been implemented in KLEE. > > This klee_div_zero_check() function is implemented in C and is > compiled to LLVM Bitcode which is then linked into the module that > KLEE is interpreting. > > I need to change the modify the LLVM bitcode module slightly and I'm > not sure how to do this using the LLVM C++ APIs. So any help would be > appreciated. > > Here are the two things I want to do... > > 1. Inline all calls to klee_div_zero_check() in the LLVM bitcode > module being interpreted. > > I tried using the always_inline attribute on the C definition of > klee_div_zero_check(), i.e. > > void __attribute__((always_inline)) klee_div_zero_check(long long z) > > but that only added the keyword "alwaysinline" to the > klee_div_zero_check() function in the LLVM bitcode module, it didn't > do any actual inlining. > > I see the LLVM API has the function > > llvm::InlineFunction(CallInst *CI, InlineFunctionInfo &IFI, bool InsertLifetime) > > Should I be using this to inline all calls in a module to a particular > function or is there a better way? If so what is IFI supposed to be > set to?I'm going to guess (because I don't know a great deal about the backend) that you want to link the bitcode file with the definition of your utility function, into the bitcode file with the usage, so that LLVM's midlevel optimizers have access to it & can inline it.> 2. I want to duplicated the debug (filename and line number > information) on the division instruction (e.g. SDiv) onto every > instruction (including the instructions that come from inlining > klee_div_zero_check ) that I inject into the LLVM bitcode module > (during the pass). The reason for wanting to do this is because when > KLEE reports an error it looks at the debug information of the > previous instruction. Currently the debug information references the > file that klee_div_zero_check() is defined in (which is useless for > error reporting) rather than the debug information for the division > instruction I am trying to instrument.This... there might be a few ways. One way could be to build the utility function without debug info - when it's inlined it /might/ end up with the same debug info as the rest of the function it's inserted into, but I'm not deeply familiar with LLVM's handling of debug info while inlining yet.> > So how would I go about doing this using the LLVM C++ APIs? > > Thanks, > Dan Liew. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Seemingly Similar Threads
- [LLVMdev] Are instr_iterators invalidated when function inlining is performed?
- [LLVMdev] Are instr_iterators invalidated when function inlining is performed?
- [LLVMdev] How to do bitcode archive linking correctly?
- [LLVMdev] How to do bitcode archive linking correctly?
- Trouble supressing ASAN reported leaks