Skip to content

Conversation

@ornata
Copy link

@ornata ornata commented Aug 26, 2022

For more details, read the comments on rdar://84254277.

This revert is unfortunately very large. I've squashed everything
together to make it easier to see what's going on. This will be the
last time we have to do this though. :)

To make the coverage format compatible, we need, in InstrProfData.inc:

  • INSTR_PROF_RAW_VERSION 5
  • INSTR_PROF_INDEX_VERSION 7
  • INSTR_PROF_COVMAP_VERSION 4

Prior to this revert we have

  • INSTR_PROF_RAW_VERSION 8
  • INSTR_PROF_INDEX_VERSION 8
  • INSTR_PROF_COVMAP_VERSION 5

So, this revert includes every commit which directly impacts these
values and any changes in-between that

  • Refactor code significantly
  • Make assumptions about the new format.

This might seem like a bit of a sledgehammer. However, say, avoiding
reverting NFC refactors would introduce tricky merge conflicts. Fixing
those merge conflicts is likely to introduce bugs.

Testing:

  • ninja check-all does not exhibit any new failures with this change.
  • llvm-profdata show can handle raw profiles produced by building the
    LLVM test suite with clang-1316. Output is identical.
  • llvm-profdata merge handles raw profiles produced with the 1316 format
    on the LLVM test suite with the same output as the 1316 llvm-profdata.

Conflicts:
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CoverageMapping/abspath.cpp
clang/test/Profile/profile-prefix-map.c
compiler-rt/include/profile/MemProfData.inc
compiler-rt/lib/memprof/memprof_rawprofile.cpp
compiler-rt/lib/profile/InstrProfilingInternal.h
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
compiler-rt/test/profile/Linux/binary-id.c
compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
llvm/docs/CommandGuide/llvm-profdata.rst
llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
llvm/include/llvm/ProfileData/InstrProfCorrelator.h
llvm/include/llvm/ProfileData/MemProf.h
llvm/include/llvm/ProfileData/MemProfData.inc
llvm/include/llvm/ProfileData/RawMemProfReader.h
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/ProfileData/InstrProfCorrelator.cpp
llvm/lib/ProfileData/InstrProfReader.cpp
llvm/lib/ProfileData/RawMemProfReader.cpp
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
llvm/test/Instrumentation/InstrProfiling/profiling.ll
llvm/test/tools/llvm-profdata/Inputs/basic.memprofraw
llvm/test/tools/llvm-profdata/Inputs/c-general.profraw
llvm/test/tools/llvm-profdata/Inputs/multi.memprofraw
llvm/test/tools/llvm-profdata/large-binary-id-size.test
llvm/test/tools/llvm-profdata/malformed-not-space-for-another-header.test
llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test
llvm/test/tools/llvm-profdata/memprof-basic.test
llvm/test/tools/llvm-profdata/memprof-multi.test
llvm/unittests/ProfileData/CoverageMappingTest.cpp
llvm/unittests/ProfileData/MemProfTest.cpp

Cherry-picks:

  • 703a0ea Revert "[Coverage] Store compilation dir separately in coverage mapping"

New (non-revert, non-cherry-picked) changes:

  • Update icall-nocomdat.ll to work with old coverage format
  • Remove coverage mapping directory from ScanAndUpdateArgs
  • Update profiling.ll for old profiling/coverage format
  • Regenerate coverage_prefix_map test for old coverage format

Reverts:

  • 6dd6a61 [memprof] Deduplicate and outline frame storage in the memprof profile.
  • 14415a3 "Apply clang-tidy fixes for readability-redundant-smartptr-get in InstrProfReader.cpp (NFC)"
  • 0ca8ff4 "[llvm-profdata] Unify default cutoffs for detailed summary printing".
  • 27a4f25 "Reland "[memprof] Store callsite metadata with memprof records.""
  • f4b7944 "Revert "[memprof] Store callsite metadata with memprof records.""
  • 0d362c9 "[memprof] Store callsite metadata with memprof records."
  • 9c35303 "[InstrProf][NFC] Fix warning by removing typecast"
  • fc97efa "Cleanup includes: ProfileData"
  • b681799 "[instrprof] Rename the profile kind types to be more descriptive."
  • 0a41849 "Reland "[memprof] Extend the index prof format to include memory profiles.""
  • 19bdf44 "Revert "Reland "[memprof] Extend the index prof format to include memory profiles."""
  • 807ba7a "Reland "[memprof] Extend the index prof format to include memory profiles.""
  • a3beb34 "Reland "[InstrProf] Make the IndexedInstrProf header backwards compatible.""
  • 9fd2cb2 "Revert "[InstrProf] Make the IndexedInstrProf header backwards compatible.""
  • 85355a5 "Revert "Reland "[memprof] Extend the index prof format to include memory profiles."""
  • de54e4a "Reland "[memprof] Extend the index prof format to include memory profiles.""
  • 34a62f9 "[llvm-profdata] Fix use-after-move"
  • 0f73fb1 "Revert "[memprof] Extend the index prof format to include memory profiles.""
  • 43c2348 "[memprof] Extend the index prof format to include memory profiles."
  • 14cc41a "[InstrProf] Make the IndexedInstrProf header backwards compatible."
  • 216575e "Revert "Revert "[ProfileData] Read and symbolize raw memprof profiles."""
  • dbf47d2 "Revert "[ProfileData] Read and symbolize raw memprof profiles.""
  • 26f978d "[ProfileData] Read and symbolize raw memprof profiles."
  • 14f4f63 "[memprof] Print out the summary in YAML format."
  • d2df8d5 "[instrprof][NFC] Templatize the instrprof iterator."
  • 7756b34 "[InstrProf][NFC] Remove stray option in InstrProfWriter"
  • 186dcd4 "[instrprof][NFC] Refactor out the common logic for getProfileKind."
  • eea002a "[InstrProf][NFC] Move function out of InstrProf.h"
  • 11d3074 "[InstrProf] Add single byte coverage mode"
  • 13d8947 "[InstrProf][NFC] Refactor Profile kind into a bitset enum."
  • c9baa56 "[InstrProf][Correlate] Verify debug info with llvm-profdata show"
  • 6d52391 "[InstrProf][Correlate] Improve error messages"
  • f170595 "[InstrProf][Correlator] Do not compress names when reading debug info"
  • ccb09a4 "Fix broken comment in InstrProfData.inc"
  • 88d8177 "[InstrProf] Restore InstrProfData.inc to fix Fuchsia builds"
  • f214737 "[InstrProf][NFC] Do not assume size of counter type"
  • 4ecf15b "[llvm-profdata] Make -debug-info visible"
  • ac719d7 "[InstrProf] Don't profile merge by default in lightweight mode"
  • 65d7fd0 "[Try2][InstrProf] Add Correlator class to read debug info"
  • bdc68ee "Revert "[InstrProf] Add Correlator class to read debug info""
  • 95946d2 "[InstrProf] Add Correlator class to read debug info"
  • 58d9c1a "[Try2][InstrProf] Attach debug info to counters"
  • c809da7 "Revert "[InstrProf] Attach debug info to counters""
  • 800bf8e "[InstrProf] Attach debug info to counters"
  • 7cca33b "[memprof] Extend llvm-profdata to display MemProf profile summaries."
  • 24c615f "[InstrProfData] Bump the raw profile version to 8"
  • ee88b8d "[compiler-rt] Add more diagnostic to InstrProfError"
  • 743f78e "[InstrProfiling] Fix warnings when building for Windows"
  • a1532ed "[InstrProfiling] Make CountersPtr in _profd relative"
  • b9f547e "[llvm][profile] Add padding after binary IDs"
  • 1df7289 "[compiler-rt/profile] Include __llvm_profile_get_magic in module signature"
  • 83302c8 "[profile] Fix profile merging with binary IDs"
  • c579c65 "[compiler-rt][profile] Make corrupted-profile.c more robust"
  • f984ac2 "[profile] Add binary id into profiles"
  • f0a616efa42b33cd280d5a45c3c2e3aabe278bb5 "Revert "[llvm-profdata] Fix use-after-move""
  • 4578233ce8250c206bb342e85632b1d2969039c5 "Revert "[instrprof][NFC] Templatize the instrprof iterator.""
  • e8d4a36dc9ea5719c3bea227d3fde15a005f7443 "Revert "[llvm-profdata] Unify default cutoffs for detailed summary printing""

@ornata
Copy link
Author

ornata commented Aug 26, 2022

@swift-ci test

@ornata ornata force-pushed the the-big-profiling-revert branch from ed83a83 to 3132ad9 Compare August 26, 2022 20:45
@ornata
Copy link
Author

ornata commented Aug 26, 2022

Removed some binary_ids-related code which somehow got restored in Linux/Fuchsia while I was melding everything together.

@ornata
Copy link
Author

ornata commented Aug 26, 2022

@swift-ci test

@haoNoQ
Copy link

haoNoQ commented Aug 26, 2022

I'll do my best to read through this today.

@ornata ornata force-pushed the the-big-profiling-revert branch from 3132ad9 to 36162b7 Compare August 27, 2022 02:45
@ornata
Copy link
Author

ornata commented Aug 27, 2022

Revert some memprof-related commits I missed:

    * 8306968b592d942cc49bde2e387061e673a9fbb7 "[memprof] Move the meminfo block struct to MemProfData.inc."
    * a2ce97cc3f99c8af80b2325acf03a4c171ffb48f "[memprof] Fix unit test build after refactoring shared header."
    * f89319b841c0826822b7b8533b3d4f6443d3429b "Reland "[memprof] Refactor out the MemInfoBlock into a macro based def.""

Hopefully will get the Linux build working.

@ornata
Copy link
Author

ornata commented Aug 27, 2022

@swift-ci test

@ornata ornata force-pushed the the-big-profiling-revert branch from 36162b7 to c5daf29 Compare August 27, 2022 03:31
@ornata
Copy link
Author

ornata commented Aug 27, 2022

One of the necessary cherry-picks (703a0ea) changes the constructor for CoverageFilenamesSectionWriter. This causes Swift builds to fail.

Partially revert that cherry-pick to use ArrayRef<std::string> Filenames for CoverageFilenamesSectionWriter instead of ArrayRef<StringRef> Filenames.

This ought to be equivalent because the current behaviour is to store the filenames twice: once using std::string once using StringRef.

All of my local testing passed with this change. (ninja check-profile, ninja checks on Instrumentation, and the end-to-end LLVM test suite test)

@ornata
Copy link
Author

ornata commented Aug 27, 2022

@swift-ci test

For more details, read the comments on rdar://84254277.

This revert is unfortunately very large. I've squashed everything
together to make it easier to see what's going on. This will be the
last time we have to do this though. :)

To make the coverage format compatible, we need, in InstrProfData.inc:

* `INSTR_PROF_RAW_VERSION 5`
* `INSTR_PROF_INDEX_VERSION 7`
* `INSTR_PROF_COVMAP_VERSION 4`

Prior to this revert we have

* `INSTR_PROF_RAW_VERSION 8`
* `INSTR_PROF_INDEX_VERSION 8`
* `INSTR_PROF_COVMAP_VERSION 5`

So, this revert includes every commit which directly impacts these
values *and* any changes in-between that

* Refactor code significantly
* Make assumptions about the new format.

This might seem like a bit of a sledgehammer. However, say, avoiding
reverting NFC refactors would introduce tricky merge conflicts. Fixing
those merge conflicts is likely to introduce bugs.

Testing:
* `ninja check-all` does not exhibit any new failures with this change.
* `llvm-profdata show` can handle raw profiles produced by building the
  LLVM test suite with clang-1316. Output is identical.
* `llvm-profdata merge` handles raw profiles produced with the 1316 format
  on the LLVM test suite with the same output as the 1316 `llvm-profdata`.

 Conflicts:
	clang/include/clang/Basic/CodeGenOptions.h
	clang/include/clang/Driver/Options.td
	clang/lib/CodeGen/BackendUtil.cpp
	clang/lib/CodeGen/CoverageMappingGen.cpp
	clang/lib/Driver/ToolChains/Clang.cpp
	clang/test/CoverageMapping/abspath.cpp
	clang/test/Profile/profile-prefix-map.c
	compiler-rt/include/profile/MemProfData.inc
	compiler-rt/lib/memprof/memprof_rawprofile.cpp
	compiler-rt/lib/profile/InstrProfilingInternal.h
	compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
	compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c
	compiler-rt/test/profile/Linux/binary-id.c
	compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
	llvm/docs/CommandGuide/llvm-profdata.rst
	llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
	llvm/include/llvm/ProfileData/InstrProfCorrelator.h
	llvm/include/llvm/ProfileData/MemProf.h
	llvm/include/llvm/ProfileData/MemProfData.inc
	llvm/include/llvm/ProfileData/RawMemProfReader.h
	llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
	llvm/lib/ProfileData/InstrProf.cpp
	llvm/lib/ProfileData/InstrProfCorrelator.cpp
	llvm/lib/ProfileData/InstrProfReader.cpp
	llvm/lib/ProfileData/RawMemProfReader.cpp
	llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
	llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
	llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll
	llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
	llvm/test/Instrumentation/InstrProfiling/profiling.ll
	llvm/test/tools/llvm-profdata/Inputs/basic.memprofraw
	llvm/test/tools/llvm-profdata/Inputs/c-general.profraw
	llvm/test/tools/llvm-profdata/Inputs/multi.memprofraw
	llvm/test/tools/llvm-profdata/large-binary-id-size.test
	llvm/test/tools/llvm-profdata/malformed-not-space-for-another-header.test
	llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
	llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test
	llvm/test/tools/llvm-profdata/memprof-basic.test
	llvm/test/tools/llvm-profdata/memprof-multi.test
	llvm/unittests/ProfileData/CoverageMappingTest.cpp
	llvm/unittests/ProfileData/MemProfTest.cpp
	compiler-rt/lib/memprof/memprof_allocator.cpp

Cherry-picks:
* 703a0ea Revert "[Coverage] Store compilation dir separately in coverage mapping"

New (non-revert, non-cherry-picked) changes:
* Update icall-nocomdat.ll to work with old coverage format
* Remove coverage mapping directory from `ScanAndUpdateArgs`
* Update profiling.ll for old profiling/coverage format
* Regenerate `coverage_prefix_map` test for old coverage format
* CoverageFilenamesSectionWriter uses `ArrayRef<std::string>` for compatability with Swift's GenCoverage.cpp.

Reverts:
* 6dd6a61 [memprof] Deduplicate and outline frame storage in the memprof profile.
* 14415a3 "Apply clang-tidy fixes for readability-redundant-smartptr-get in InstrProfReader.cpp (NFC)"
* 0ca8ff4 "[llvm-profdata] Unify default cutoffs for detailed summary printing".
* 27a4f25 "Reland "[memprof] Store callsite metadata with memprof records.""
* f4b7944 "Revert "[memprof] Store callsite metadata with memprof records.""
* 0d362c9 "[memprof] Store callsite metadata with memprof records."
* 9c35303 "[InstrProf][NFC] Fix warning by removing typecast"
* fc97efa "Cleanup includes: ProfileData"
* b681799 "[instrprof] Rename the profile kind types to be more descriptive."
* 0a41849 "Reland "[memprof] Extend the index prof format to include memory profiles.""
* 19bdf44 "Revert "Reland "[memprof] Extend the index prof format to include memory profiles."""
* 807ba7a "Reland "[memprof] Extend the index prof format to include memory profiles.""
* a3beb34 "Reland "[InstrProf] Make the IndexedInstrProf header backwards compatible.""
* 9fd2cb2 "Revert "[InstrProf] Make the IndexedInstrProf header backwards compatible.""
* 85355a5 "Revert "Reland "[memprof] Extend the index prof format to include memory profiles."""
* de54e4a "Reland "[memprof] Extend the index prof format to include memory profiles.""
* 34a62f9 "[llvm-profdata] Fix use-after-move"
* 0f73fb1 "Revert "[memprof] Extend the index prof format to include memory profiles.""
* 43c2348 "[memprof] Extend the index prof format to include memory profiles."
* 14cc41a "[InstrProf] Make the IndexedInstrProf header backwards compatible."
* 216575e "Revert "Revert "[ProfileData] Read and symbolize raw memprof profiles."""
* dbf47d2 "Revert "[ProfileData] Read and symbolize raw memprof profiles.""
* 26f978d "[ProfileData] Read and symbolize raw memprof profiles."
* 14f4f63 "[memprof] Print out the summary in YAML format."
* d2df8d5 "[instrprof][NFC] Templatize the instrprof iterator."
* 7756b34 "[InstrProf][NFC] Remove stray option in InstrProfWriter"
* 186dcd4 "[instrprof][NFC] Refactor out the common logic for getProfileKind."
* eea002a "[InstrProf][NFC] Move function out of InstrProf.h"
* 11d3074 "[InstrProf] Add single byte coverage mode"
* 13d8947 "[InstrProf][NFC] Refactor Profile kind into a bitset enum."
* c9baa56 "[InstrProf][Correlate] Verify debug info with llvm-profdata show"
* 6d52391 "[InstrProf][Correlate] Improve error messages"
* f170595 "[InstrProf][Correlator] Do not compress names when reading debug info"
* ccb09a4 "Fix broken comment in InstrProfData.inc"
* 88d8177 "[InstrProf] Restore InstrProfData.inc to fix Fuchsia builds"
* f214737 "[InstrProf][NFC] Do not assume size of counter type"
* 4ecf15b "[llvm-profdata] Make -debug-info visible"
* ac719d7 "[InstrProf] Don't profile merge by default in lightweight mode"
* 65d7fd0 "[Try2][InstrProf] Add Correlator class to read debug info"
* bdc68ee "Revert "[InstrProf] Add Correlator class to read debug info""
* 95946d2 "[InstrProf] Add Correlator class to read debug info"
* 58d9c1a "[Try2][InstrProf] Attach debug info to counters"
* c809da7 "Revert "[InstrProf] Attach debug info to counters""
* 800bf8e "[InstrProf] Attach debug info to counters"
* 7cca33b "[memprof] Extend llvm-profdata to display MemProf profile summaries."
* 24c615f "[InstrProfData] Bump the raw profile version to 8"
* ee88b8d "[compiler-rt] Add more diagnostic to InstrProfError"
* 743f78e "[InstrProfiling] Fix warnings when building for Windows"
* a1532ed "[InstrProfiling] Make CountersPtr in __profd_ relative"
* b9f547e "[llvm][profile] Add padding after binary IDs"
* 1df7289 "[compiler-rt/profile] Include __llvm_profile_get_magic in module signature"
* 83302c8 "[profile] Fix profile merging with binary IDs"
* c579c65 "[compiler-rt][profile] Make corrupted-profile.c more robust"
* f984ac2 "[profile] Add binary id into profiles"
* f0a616efa42b33cd280d5a45c3c2e3aabe278bb5 "Revert "[llvm-profdata] Fix use-after-move""
* 4578233ce8250c206bb342e85632b1d2969039c5 "Revert "[instrprof][NFC] Templatize the instrprof iterator.""
* e8d4a36dc9ea5719c3bea227d3fde15a005f7443 "Revert "[llvm-profdata] Unify default cutoffs for detailed summary printing""
* 440d971 "Work around non-existence of ElfW(type) macro on FreeBSD"
* 8306968 "[memprof] Move the meminfo block struct to MemProfData.inc."
* a2ce97c "[memprof] Fix unit test build after refactoring shared header."
* f89319b "Reland "[memprof] Refactor out the MemInfoBlock into a macro based def.""
@ornata ornata force-pushed the the-big-profiling-revert branch from c5daf29 to a2fc322 Compare August 27, 2022 04:13
@ornata
Copy link
Author

ornata commented Aug 27, 2022

Seems like I may have mismerged 7cca33b, causing build failures in the checks.

Hopefully this is the last of the memprofile things to revert. (I just realized it probably doesn't build by default, which is why I'm not seeing these failures on my end.)

@ornata
Copy link
Author

ornata commented Aug 27, 2022

@swift-ci test

@haoNoQ
Copy link

haoNoQ commented Aug 29, 2022

53/141 files. I don't know much about these profiling/coverage formats so I'm mostly looking at formal problems, and so far I haven't found any. I think I could have done a better job if the patch was actually split up into commits, so I was able to understand what each change is trying to accomplish. But I don't think this warrants re-doing the patch for me.

I also applied the static analyzer before/after and it hasn't found any new issues! (:

This whole char * <=> uint64_t * business looks scary af. It's very easy to forget a multiplication somewhere, even though I haven't found any concrete problems. It's unlikely that the old code (to which we're reverting) had a forgotten multiplication, but it's somewhat likely that more multiplications were added later, that also needed to be reverted, but we wouldn't know about that; I don't know how to go after such bugs without significant (and otherwise counter-productive) investment in tooling. Also character-like types are exempt from strict aliasing so I'm somewhat worried that the compiler could have become smarter about strict aliasing since the patch was committed, and the revert could expose that.

Copy link

@haoNoQ haoNoQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I looked through all the code and questioned all the scary places that I've encountered and I haven't discovered any apparent problems. So I hope it'll all work out one way or another!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants