[compiler-rt] [llvm] [TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling. (PR #81691)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 23:07:33 PST 2024


================
@@ -273,18 +280,28 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
   const uint64_t NumBitmapBytes =
       __llvm_profile_get_num_bitmap_bytes(BitmapBegin, BitmapEnd);
   const uint64_t NamesSize = __llvm_profile_get_name_size(NamesBegin, NamesEnd);
+  const uint64_t NumVTables =
+      __llvm_profile_get_num_vtable(VTableBegin, VTableEnd);
+  const uint64_t VTableSectionSize =
+      __llvm_profile_get_vtable_section_size(VTableBegin, VTableEnd);
+  const uint64_t VNamesSize =
+      __llvm_profile_get_name_size(VNamesBegin, VNamesEnd);
 
   /* Create the header. */
   __llvm_profile_header Header;
 
   /* Determine how much padding is needed before/after the counters and after
    * the names. */
   uint64_t PaddingBytesBeforeCounters, PaddingBytesAfterCounters,
-      PaddingBytesAfterNames, PaddingBytesAfterBitmapBytes;
-  __llvm_profile_get_padding_sizes_for_counters(
-      DataSectionSize, CountersSectionSize, NumBitmapBytes, NamesSize,
-      &PaddingBytesBeforeCounters, &PaddingBytesAfterCounters,
-      &PaddingBytesAfterBitmapBytes, &PaddingBytesAfterNames);
+      PaddingBytesAfterBitmapBytes, PaddingBytesAfterNames,
+      PaddingBytesAfterVTable, PaddingBytesAfterVNames;
+  if (__llvm_profile_get_padding_sizes_for_counters(
----------------
minglotus-6 wrote:

`__llvm_profile_get_padding_sizes_for_counters` returns -1 to alert the [incompatibility](https://github.com/llvm/llvm-project/pull/81691/files/0c9ed57bce7d29f27ab7562d85503edfa8132670#diff-ff206eae21de963bf60f9baca54d2c90e0dd89bf53732c236b019b4e9192bd20R163) and returns 0 otherwise.

-1 is chosen to signal errors to for consistency with existing code (e.g.,  [`InstrProfilingWriter.c`](https://github.com/llvm/llvm-project/blob/118a2a52fd465b7576c54bd102ee2e417a3b9a71/compiler-rt/lib/profile/InstrProfilingWriter.c) uses -1 to return error in many places, and [InstrProfilingFile.c:writeFile](https://github.com/llvm/llvm-project/blob/118a2a52fd465b7576c54bd102ee2e417a3b9a71/compiler-rt/lib/profile/InstrProfilingFile.c#L518) also returns -1). Non-zero value is handled [here](https://github.com/llvm/llvm-project/blob/118a2a52fd465b7576c54bd102ee2e417a3b9a71/compiler-rt/lib/profile/InstrProfilingFile.c#L605-L606) to emit warnings.

Anecdotally, `llvm_unreachable` is not a way to signal errors in release build with the default LLVM config.
 * https://llvm.org/docs/CodingStandards.html#assert-liberally mentions this _When assertions are disabled (i.e. in release builds), llvm_unreachable becomes a hint to compilers to skip generating code for this branch_ 
 * https://llvm.org/docs/CMake.html#llvm-related-variables mentions `DLLVM_UNREACHABLE_OPTIMIZE` is on by default and enables the hint

https://github.com/llvm/llvm-project/pull/81691


More information about the llvm-commits mailing list