[llvm] [nfc][ctx_prof] Efficient profile traversal and update (PR #110052)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 15:29:57 PDT 2024


================
@@ -279,16 +278,44 @@ static void preorderVisit(ProfilesTy &Profiles,
     Traverser(P);
 }
 
-void PGOContextualProfile::update(Visitor V, const Function *F) {
-  GlobalValue::GUID G = F ? getDefinedFunctionGUID(*F) : 0U;
+void PGOContextualProfile::initIndex() {
+  // Initialize the head of the index list for each function. We don't need it
+  // after this point.
+  DenseMap<GlobalValue::GUID, PGOCtxProfContext *> InsertionPoints;
+  for (auto &FI : FuncInfo)
+    InsertionPoints[FI.first] = &FI.second.Index;
----------------
kazutakahirata wrote:

May I suggest structured binding here?

```suggestion
  for (auto &[Guid, FI] : FuncInfo)
    InsertionPoints[Guid] = &FI.Index;
```

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


More information about the llvm-commits mailing list