[LLVMdev] Help with LLVM Bitcode function inlining and duplicating debug information on instructions
Daniel Liew
daniel.liew at imperial.ac.uk
Fri Aug 30 04:38:35 PDT 2013
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.
More information about the llvm-dev
mailing list