[llvm-dev] Advice on memory copy instrumentation

Matt Fysh via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 19 15:06:54 PST 2020


Hi all,

Given a couple of lines of C++ code `int x = 42; int y = x`, we end up with
the following LLVM IR instructions:

%x = alloca i32, align 4
%y = alloca i32, align 4
store i32 42, i32* %x, align 4
%0 = load i32, i32* %x, align 4
store i32 %0, i32* %y, align 4

Is it possible to instrument the IR to perform a value trace?

What I'd like to do is stream a log of memory copies (reads then writes),
such that in this example, the final instruction will produce a log event
along the lines of:
"COPY: Value at <address of x> copied to <address of y>"?

Essentially what I'd like to do is annotate particular values, so that when
these same values are encountered again later in the program, I can
retrieve the annotation. I will also need the annotation to survive copies,
moves, etc. This could be considered a lightweight, parallel symbolic trace
performed at runtime on a very small subset of program values.

I am hoping to implement this tooling at the LLVM IR level, so that it can
be useful beyond C++, but if it's easier to instrument the CLang AST
instead then I guess I can start there. Looking forward to your responses :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200220/406146e7/attachment.html>


More information about the llvm-dev mailing list