HomePhabricator

[HeapProf] Clang and LLVM support for heap profiling instrumentation

Authored by tejohnson on Aug 13 2020, 4:29 PM.

Description

[HeapProf] Clang and LLVM support for heap profiling instrumentation

See RFC for background:
http://lists.llvm.org/pipermail/llvm-dev/2020-June/142744.html

Note that the runtime changes will be sent separately (hopefully this
week, need to add some tests).

This patch includes the LLVM pass to instrument memory accesses with
either inline sequences to increment the access count in the shadow
location, or alternatively to call into the runtime. It also changes
calls to memset/memcpy/memmove to the equivalent runtime version.
The pass is modeled on the address sanitizer pass.

The clang changes add the driver option to invoke the new pass, and to
link with the upcoming heap profiling runtime libraries.

Currently there is no attempt to optimize the instrumentation, e.g. to
aggregate updates to the same memory allocation. That will be
implemented as follow on work.

Differential Revision: https://reviews.llvm.org/D85948

Event Timeline

etiotto added inline comments.
/clang/include/clang/Driver/Options.td
998

Personally I would prefer -fmemory-profiling as the option name.

/llvm/include/llvm/Transforms/Instrumentation/HeapProfiler.h
1

Formatting. Line too short?

42

no need for this line.

/llvm/lib/Transforms/Instrumentation/HeapProfiler.cpp
1

Formatting

167

Can you make this member function const?

Thanks for your comments, @etiotto. I'll address them in the next day or so. Alternate suggestion below for flag.

/clang/include/clang/Driver/Options.td
998

I'd rather make it an imperative similar to other profile related flags. How about -fmemory-profile ?

@davidxl wdyt?

I am fine with -fmemory-profiler.

I am fine with -fmemory-profiler.

Do you mean -fmemory-profile (my alternate to the suggested -fmemory-profiling)?

I accidentally threw in a third choice :). Yes -fmemory-profile is fine
which is consistent with -fsanitize=

David