[compiler-rt] [llvm] [compiler-rt] Rework profile data handling for GPU targets (PR #187136)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 06:50:14 PDT 2026


================
@@ -286,41 +264,33 @@ Error GPUProfGlobals::write() const {
                          "The compiler-rt profiling library must be linked for "
                          "GPU PGO to work.");
 
-  size_t DataSize = Data.size() * sizeof(__llvm_profile_data),
-         CountsSize = Counts.size() * sizeof(int64_t);
-  __llvm_profile_data *DataBegin, *DataEnd;
-  char *CountersBegin, *CountersEnd, *NamesBegin, *NamesEnd;
-
-  // Initialize array of contiguous data. We need to make sure each section is
-  // contiguous so that the PGO library can compute deltas properly
-  SmallVector<uint8_t> ContiguousData(NamesData.size() + DataSize + CountsSize);
-
-  // Compute region pointers
-  DataBegin = (__llvm_profile_data *)(ContiguousData.data() + CountsSize);
-  DataEnd =
-      (__llvm_profile_data *)(ContiguousData.data() + CountsSize + DataSize);
-  CountersBegin = (char *)ContiguousData.data();
-  CountersEnd = (char *)(ContiguousData.data() + CountsSize);
-  NamesBegin = (char *)(ContiguousData.data() + CountsSize + DataSize);
-  NamesEnd = (char *)(ContiguousData.data() + CountsSize + DataSize +
-                      NamesData.size());
-
-  // Copy data to contiguous buffer
-  memcpy(DataBegin, Data.data(), DataSize);
-  memcpy(CountersBegin, Counts.data(), CountsSize);
-  memcpy(NamesBegin, NamesData.data(), NamesData.size());
-
-  // Invoke compiler-rt entrypoint
-  int result = __llvm_write_custom_profile(
-      TargetTriple.str().c_str(), DataBegin, DataEnd, CountersBegin,
-      CountersEnd, NamesBegin, NamesEnd, &Version);
-  if (result != 0)
+  // The sections must be laid out contiguously so that lprofWriteDataImpl
----------------
jhuber6 wrote:

Good catch, I didn't closely inspect the layout that was already here.

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


More information about the llvm-commits mailing list