[Openmp-commits] [clang-tools-extra] [openmp] [libc] [compiler-rt] [llvm] [clang] [lld] [flang] [libcxx] [lldb] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

Ethan Luis McDonough via Openmp-commits openmp-commits at lists.llvm.org
Thu Jan 4 20:45:17 PST 2024


================
@@ -163,3 +163,87 @@ Error GenericGlobalHandlerTy::readGlobalFromImage(GenericDeviceTy &Device,
 
   return Plugin::success();
 }
+
+bool GenericGlobalHandlerTy::hasProfilingGlobals(GenericDeviceTy &Device,
+                                                 DeviceImageTy &Image) {
+  GlobalTy global(getInstrProfNamesVarName().str(), 0);
+  if (auto Err = getGlobalMetadataFromImage(Device, Image, global)) {
+    consumeError(std::move(Err));
+    return false;
+  }
+  return true;
+}
+
+Expected<GPUProfGlobals>
+GenericGlobalHandlerTy::readProfilingGlobals(GenericDeviceTy &Device,
+                                             DeviceImageTy &Image) {
+  GPUProfGlobals profdata;
+  auto ELFObj = getELFObjectFile(Image);
+  if (!ELFObj)
+    return ELFObj.takeError();
+  profdata.targetTriple = ELFObj->makeTriple();
+  // Iterate through elf symbols
+  for (auto &sym : ELFObj->symbols()) {
+    if (auto name = sym.getName()) {
+      // Check if given current global is a profiling global based
+      // on name
+      if (name->equals(getInstrProfNamesVarName())) {
+        // Read in profiled function names
+        std::vector<char> chars(sym.getSize() / sizeof(char), ' ');
+        GlobalTy NamesGlobal(name->str(), sym.getSize(), chars.data());
----------------
EthanLuisMcDonough wrote:

`__llvm_prf_nm` is emitted as an array. For example:

```
@__llvm_prf_nm = protected addrspace(1) constant [63 x i8] c"_=x\DA+I-.\D1K\B6\8A\8F\CF\CF-\88\CFOK\CB\C9OL\C9\CCK\8F7\B1\887M65J41\B5\88\CFM\CC\CC\8B\CF1\B4d,!Z\B1\B1\01X\B1!\00O\F6 \CF", section "__llvm_prf_names", align 1
```

Eventually this data is going to be passed to a function in compiler-rt's profiling library so it can be used to generate a profiling file.

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


More information about the Openmp-commits mailing list