[llvm] [memprof] Simplify readMemprof (NFC) (PR #119930)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 22:17:11 PST 2024


================
@@ -969,9 +967,15 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
   // Build maps of the location hash to all profile data with that leaf location
   // (allocation info and the callsites).
   std::map<uint64_t, std::set<const AllocationInfo *>> LocHashToAllocInfo;
-  // For the callsites we need to record the index of the associated frame in
-  // the frame array (see comments below where the map entries are added).
-  std::map<uint64_t, std::set<std::pair<const std::vector<Frame> *, unsigned>>>
+  // A hash function for std::unordered_set<ArrayRef<Frame>> to work.
+  struct CallStackHash {
----------------
kazutakahirata wrote:

With that, I wouldn't be able to use `std::map::operator[]`; I would have to do:

```
      LocHashToCallSites.try_emplace(StackId, &computeFullStackId)
          .first->second.insert(ArrayRef<Frame>(CS).drop_front(Idx++));
```

Note that if we pass `decltype(&computeFullStackId)` as a template parameter, we need to initialize an instance of `decltype(&computeFullStackId)` to `&computeFullStackId`.  The function pointer type doesn't default-construct itself to be equal to `&computeFullStackId`.

For this reason, I prefer a little bit of upfront cost, namely the definition of `struct CallStackHash`, for the simplicity of `std::map::operator[]` at the use site.


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


More information about the llvm-commits mailing list