[llvm-dev] Advice on memory copy instrumentation

Johannes Doerfert via llvm-dev llvm-dev at lists.llvm.org
Fri Feb 21 20:42:19 PST 2020


Hi Matt,

You might want to consider running mem2reg first to eliminate trivial
memory locations+writes+reads. See:
  http://lists.llvm.org/pipermail/llvm-dev/2020-February/139405.html

It is important to do that because otherwise almost no existing LLVM-IR
pass will be effective. If you compile with -O{1,2,3} it happens for
you: https://godbolt.org/z/GJXUiS

Cheers,
  Johannes

On 02/22, Matt Fysh via llvm-dev wrote:
> Thanks Hiroshi, this is exactly what I was looking for! I've been looking
> into it for a few days, and I've just found the MemorySSA (virtual IR)
> which is probably gonna help me out a bunch. Thanks again :)
> 
> On Sat, 22 Feb 2020 at 03:23, Hiroshi Yamauchi <yamauchi at google.com> wrote:
> 
> > I'm not sure if I understand exactly what you would like to do, but I
> > would imagine one could write a pass that looks for the pattern of "%x =
> > load ... store %x ..." and insert a function call that logs the copy. I
> > don't know of any existing analysis or utility code that you could build on
> > to make it easy to do that, though.
> >
> > It might be helpful if there is an example of the annotations you have in
> > mind.
> >
> > On Wed, Feb 19, 2020 at 3:07 PM Matt Fysh via llvm-dev <
> > llvm-dev at lists.llvm.org> wrote:
> >
> >> 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 :)
> >>
> >>
> >> _______________________________________________
> >> LLVM Developers mailing list
> >> llvm-dev at lists.llvm.org
> >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> >>
> >

> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


-- 

Johannes Doerfert
Researcher

Argonne National Laboratory
Lemont, IL 60439, USA

jdoerfert at anl.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200221/9baee816/attachment.sig>


More information about the llvm-dev mailing list