[PATCH] D124877: [BOLT][NFC] ICP: simplify findTargetsIndex

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 3 14:16:51 PDT 2022


Amir created this revision.
Herald added subscribers: ayermolo, arphaman.
Herald added a reviewer: rafauler.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

Unnest lambda and use `llvm::is_contained`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124877

Files:
  bolt/lib/Passes/IndirectCallPromotion.cpp


Index: bolt/lib/Passes/IndirectCallPromotion.cpp
===================================================================
--- bolt/lib/Passes/IndirectCallPromotion.cpp
+++ bolt/lib/Passes/IndirectCallPromotion.cpp
@@ -515,20 +515,17 @@
   JumpTableInfoType HotTargets =
       maybeGetHotJumpTableTargets(BB, CallInst, TargetFetchInst, JT);
 
-  if (!HotTargets.empty()) {
-    auto findTargetsIndex = [&](uint64_t JTIndex) {
-      for (size_t I = 0; I < Targets.size(); ++I) {
-        std::vector<uint64_t> &JTIs = Targets[I].JTIndices;
-        if (std::find(JTIs.begin(), JTIs.end(), JTIndex) != JTIs.end())
-          return I;
-      }
-      LLVM_DEBUG(
-          dbgs() << "BOLT-ERROR: Unable to find target index for hot jump "
-                 << " table entry in " << *BB.getFunction() << "\n");
-      llvm_unreachable("Hot indices must be referred to by at least one "
-                       "callsite");
-    };
+  auto findTargetsIndex = [&](uint64_t JTIndex) {
+    for (size_t I = 0; I < Targets.size(); ++I)
+      if (llvm::is_contained(Targets[I].JTIndices, JTIndex))
+        return I;
+    LLVM_DEBUG(dbgs() << "BOLT-ERROR: Unable to find target index for hot jump "
+                      << " table entry in " << *BB.getFunction() << "\n");
+    llvm_unreachable("Hot indices must be referred to by at least one "
+                     "callsite");
+  };
 
+  if (!HotTargets.empty()) {
     if (opts::Verbosity >= 1)
       for (size_t I = 0; I < HotTargets.size(); ++I)
         outs() << "BOLT-INFO: HotTarget[" << I << "] = (" << HotTargets[I].first


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124877.426831.patch
Type: text/x-patch
Size: 1577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220503/c1488005/attachment.bin>


More information about the llvm-commits mailing list