This is an archive of the discontinued LLVM Phabricator instance.

[MemProf] Use new option/pass for profile feedback and matching
ClosedPublic

Authored by tejohnson on Jul 10 2023, 8:58 AM.

Details

Summary

Previously the MemProf profile was expected to be in the same profile
file as a normal PGO profile, passed via the usual -fprofile-use=
option, and was matched in the same pass. To simplify profile
preparation, since the raw MemProf profile requires the binary for
symbolization and may be simpler to index separately from the raw PGO
profile, and also to enable providing a MemProf profile for a SamplePGO
build, separate out the MemProf feedback option and matching pass.

This patch adds the -fmemory-profile-use=${file} option, and the
provided file is passed down to LLVM and ultimately used in a new
MemProfUsePass which performs the matching of just the memory profile
contents of that file.

Note that a single profile file containing both normal PGO and MemProf
profile data is still supported, and the relevant profile data is
matched by the appropriate matching pass(es) based on which option(s)
the profile is provided with (the same profile file can be supplied to
both feedback options).

Diff Detail

Event Timeline

tejohnson created this revision.Jul 10 2023, 8:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2023, 8:58 AM
Herald added subscribers: wlei, Enna1, ormris and 3 others. · View Herald Transcript
tejohnson requested review of this revision.Jul 10 2023, 8:58 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 10 2023, 8:58 AM
Herald added a subscriber: MaskRay. · View Herald Transcript
snehasish added inline comments.Jul 10 2023, 10:33 AM
llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
912

I think we can we split this patch into two to make the changes clearer. Consider the following --

First move the readMemprof and its callees to MemProfiler.cpp and call it from the original code. Also in this step consider using Error as the return type of readMemprof, right now the bool returned is ignored. Using Error doesn't need to be fatal, we can handle it and emit a warning but it would enforce the check I think.

Second, add the pass to MemProfiler and all the related options/plumbing.

What do you think?

tejohnson added inline comments.Jul 10 2023, 10:45 AM
llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
912

Ok let me try that. I think actually readMemprof should have a void return. The only time we are returning false the error has already been handled within readMemprof itself.

tejohnson added inline comments.Jul 10 2023, 11:43 AM
llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
912

D154872. I will rebase this patch once that is committed.

snehasish accepted this revision.Jul 10 2023, 4:08 PM

lgtm, thanks for testing the various combinations of profiles passed to each option.

This revision is now accepted and ready to land.Jul 10 2023, 4:08 PM
This revision was landed with ongoing or failed builds.Jul 10 2023, 4:43 PM
This revision was automatically updated to reflect the committed changes.
jplehr added a subscriber: jplehr.Jul 11 2023, 2:24 AM

The preparation patch (https://reviews.llvm.org/D154872) caused the AMD GPU OpenMP buildbot to fail.

Hi @tejohnson, I'm seeing crashes after this revision:

Failed Tests (2):
  LLVM-Unit :: Passes/./PluginsTests/0/2
  LLVM-Unit :: Passes/./PluginsTests/1/2

A stack trace looks as follows:

 #0 0x00007fba1f899667 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/jhahnfel/LLVM/src/llvm/lib/Support/Unix/Signals.inc:602:13
 #1 0x00007fba1f897752 llvm::sys::RunSignalHandlers() /home/jhahnfel/LLVM/src/llvm/lib/Support/Signals.cpp:105:18
 #2 0x00007fba1f899cef SignalHandler(int) /home/jhahnfel/LLVM/src/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007fba234cacf0 __restore_rt (/lib64/libpthread.so.0+0x12cf0)
 #4 0x00007fba1a416ea2 __memcpy_avx_unaligned_erms (/lib64/libc.so.6+0xceea2)
 #5 0x00007fba1f81c09f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_length(unsigned long) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/basic_string.h:229:26
 #6 0x00007fba1f81c09f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_set_length(unsigned long) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/basic_string.h:267:2
 #7 0x00007fba1f81c09f void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_construct<char*>(char*, char*, std::forward_iterator_tag) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/basic_string.tcc:247:2
 #8 0x00007fba1f81c09f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/basic_string.h:544:2
 #9 0x00007fba1f81c09f llvm::PGOOptions::PGOOptions(llvm::PGOOptions const&) /home/jhahnfel/LLVM/src/llvm/lib/Support/PGOOptions.cpp:54:13
#10 0x00007fba22e95528 void std::_Optional_payload_base<llvm::PGOOptions>::_M_construct<llvm::PGOOptions const&>(llvm::PGOOptions const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:280:21
#11 0x00007fba22e95528 std::_Optional_payload_base<llvm::PGOOptions>::_Optional_payload_base(bool, std::_Optional_payload_base<llvm::PGOOptions> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:145:10
#12 0x00007fba22e95528 std::_Optional_payload<llvm::PGOOptions, true, false, false>::_Optional_payload(bool, std::_Optional_payload_base<llvm::PGOOptions> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:397:42
#13 0x00007fba22e95528 std::_Optional_payload<llvm::PGOOptions, false, false, false>::_Optional_payload(bool, std::_Optional_payload_base<llvm::PGOOptions> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:431:57
#14 0x00007fba22e95528 std::_Optional_base<llvm::PGOOptions, false, false>::_Optional_base(std::_Optional_base<llvm::PGOOptions, false, false> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:538:9
#15 0x00007fba22e95528 std::optional<llvm::PGOOptions>::optional(std::optional<llvm::PGOOptions> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:705:11
#16 0x00007fba22e95528 llvm::PassBuilder::PassBuilder(llvm::TargetMachine*, llvm::PipelineTuningOptions, std::optional<llvm::PGOOptions>, llvm::PassInstrumentationCallbacks*) /home/jhahnfel/LLVM/src/llvm/lib/Passes/PassBuilder.cpp:407:25
#17 0x0000000000231c10 std::_Optional_payload_base<llvm::PGOOptions>::_M_reset() /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:317:12
#18 0x0000000000231c10 std::_Optional_payload<llvm::PGOOptions, false, false, false>::~_Optional_payload() /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:439:57
#19 0x0000000000231c10 std::_Optional_base<llvm::PGOOptions, false, false>::~_Optional_base() /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:510:12
#20 0x0000000000231c10 PluginsTests_LoadMultiplePlugins_Test::TestBody() /home/jhahnfel/LLVM/src/llvm/unittests/Passes/PluginsTest.cpp:102:15
#21 0x0000000000243a7f testing::internal::UnitTestImpl::os_stack_trace_getter() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:5635:7
#22 0x0000000000243a7f testing::Test::Run() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:2515:9
#23 0x00000000002451b9 testing::TestInfo::Run() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:0:0
#24 0x00000000002459e1 testing::TestSuite::Run() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:2815:44
#25 0x00000000002524c7 testing::internal::UnitTestImpl::RunAllTests() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:5337:24
#26 0x0000000000251d0c testing::UnitTest::Run() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:4925:10
#27 0x000000000023535c main /home/jhahnfel/LLVM/src/third-party/unittest/UnitTestMain/TestMain.cpp:55:3
#28 0x00007fba1a382d85 __libc_start_main (/lib64/libc.so.6+0x3ad85)
#29 0x000000000022eb9e _start (/home/jhahnfel/LLVM/build-asserts/unittests/Passes/./PluginsTests+0x22eb9e)

Does that ring a bell for you? I will try to investigate later today or tomorrow, just wanted to see if you have an idea.

Hi @tejohnson, I'm seeing crashes after this revision:

Failed Tests (2):
  LLVM-Unit :: Passes/./PluginsTests/0/2
  LLVM-Unit :: Passes/./PluginsTests/1/2

I haven't seen these in my testing or any bots. How do I reproduce?

A stack trace looks as follows:

 #0 0x00007fba1f899667 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/jhahnfel/LLVM/src/llvm/lib/Support/Unix/Signals.inc:602:13
 #1 0x00007fba1f897752 llvm::sys::RunSignalHandlers() /home/jhahnfel/LLVM/src/llvm/lib/Support/Signals.cpp:105:18
 #2 0x00007fba1f899cef SignalHandler(int) /home/jhahnfel/LLVM/src/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007fba234cacf0 __restore_rt (/lib64/libpthread.so.0+0x12cf0)
 #4 0x00007fba1a416ea2 __memcpy_avx_unaligned_erms (/lib64/libc.so.6+0xceea2)
 #5 0x00007fba1f81c09f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_length(unsigned long) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/basic_string.h:229:26
 #6 0x00007fba1f81c09f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_set_length(unsigned long) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/basic_string.h:267:2
 #7 0x00007fba1f81c09f void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_construct<char*>(char*, char*, std::forward_iterator_tag) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/basic_string.tcc:247:2
 #8 0x00007fba1f81c09f std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/basic_string.h:544:2
 #9 0x00007fba1f81c09f llvm::PGOOptions::PGOOptions(llvm::PGOOptions const&) /home/jhahnfel/LLVM/src/llvm/lib/Support/PGOOptions.cpp:54:13
#10 0x00007fba22e95528 void std::_Optional_payload_base<llvm::PGOOptions>::_M_construct<llvm::PGOOptions const&>(llvm::PGOOptions const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:280:21
#11 0x00007fba22e95528 std::_Optional_payload_base<llvm::PGOOptions>::_Optional_payload_base(bool, std::_Optional_payload_base<llvm::PGOOptions> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:145:10
#12 0x00007fba22e95528 std::_Optional_payload<llvm::PGOOptions, true, false, false>::_Optional_payload(bool, std::_Optional_payload_base<llvm::PGOOptions> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:397:42
#13 0x00007fba22e95528 std::_Optional_payload<llvm::PGOOptions, false, false, false>::_Optional_payload(bool, std::_Optional_payload_base<llvm::PGOOptions> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:431:57
#14 0x00007fba22e95528 std::_Optional_base<llvm::PGOOptions, false, false>::_Optional_base(std::_Optional_base<llvm::PGOOptions, false, false> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:538:9
#15 0x00007fba22e95528 std::optional<llvm::PGOOptions>::optional(std::optional<llvm::PGOOptions> const&) /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:705:11
#16 0x00007fba22e95528 llvm::PassBuilder::PassBuilder(llvm::TargetMachine*, llvm::PipelineTuningOptions, std::optional<llvm::PGOOptions>, llvm::PassInstrumentationCallbacks*) /home/jhahnfel/LLVM/src/llvm/lib/Passes/PassBuilder.cpp:407:25
#17 0x0000000000231c10 std::_Optional_payload_base<llvm::PGOOptions>::_M_reset() /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:317:12
#18 0x0000000000231c10 std::_Optional_payload<llvm::PGOOptions, false, false, false>::~_Optional_payload() /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:439:57
#19 0x0000000000231c10 std::_Optional_base<llvm::PGOOptions, false, false>::~_Optional_base() /opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/optional:510:12
#20 0x0000000000231c10 PluginsTests_LoadMultiplePlugins_Test::TestBody() /home/jhahnfel/LLVM/src/llvm/unittests/Passes/PluginsTest.cpp:102:15
#21 0x0000000000243a7f testing::internal::UnitTestImpl::os_stack_trace_getter() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:5635:7
#22 0x0000000000243a7f testing::Test::Run() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:2515:9
#23 0x00000000002451b9 testing::TestInfo::Run() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:0:0
#24 0x00000000002459e1 testing::TestSuite::Run() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:2815:44
#25 0x00000000002524c7 testing::internal::UnitTestImpl::RunAllTests() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:5337:24
#26 0x0000000000251d0c testing::UnitTest::Run() /home/jhahnfel/LLVM/src/third-party/unittest/googletest/src/gtest.cc:4925:10
#27 0x000000000023535c main /home/jhahnfel/LLVM/src/third-party/unittest/UnitTestMain/TestMain.cpp:55:3
#28 0x00007fba1a382d85 __libc_start_main (/lib64/libc.so.6+0x3ad85)
#29 0x000000000022eb9e _start (/home/jhahnfel/LLVM/build-asserts/unittests/Passes/./PluginsTests+0x22eb9e)

Does that ring a bell for you? I will try to investigate later today or tomorrow, just wanted to see if you have an idea.

Ok, turns out I had old test binaries around that got automatically picked up by lit. Sorry for the noise.