[PATCH] D124900: [BOLT] Add icp-inline mode

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 3 19:18:49 PDT 2022


Amir created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
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.

Add an option to only peel ICP targets that can be subsequently inlined.
Yet there's no guarantee that they will be inlined.

The mode is independent from the heuristic used to choose ICP targets: by exec
count, mispredictions, or memory profile.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124900

Files:
  bolt/lib/Passes/IndirectCallPromotion.cpp


Index: bolt/lib/Passes/IndirectCallPromotion.cpp
===================================================================
--- bolt/lib/Passes/IndirectCallPromotion.cpp
+++ bolt/lib/Passes/IndirectCallPromotion.cpp
@@ -13,6 +13,7 @@
 #include "bolt/Passes/IndirectCallPromotion.h"
 #include "bolt/Passes/BinaryFunctionCallGraph.h"
 #include "bolt/Passes/DataflowInfoManager.h"
+#include "bolt/Passes/Inliner.h"
 #include "llvm/Support/CommandLine.h"
 
 #define DEBUG_TYPE "ICP"
@@ -120,6 +121,9 @@
         "for jump tables, optimize indirect jmp targets instead of indices"),
     cl::init(false), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltOptCategory));
 
+static cl::opt<bool> ICPPeelForInline(
+    "icp-inline", cl::desc("only promote call targets eligible for inlining"),
+    cl::init(false), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltOptCategory));
 
 } // namespace opts
 
@@ -1035,6 +1039,20 @@
     }
   }
 
+  // Filter by inline-ability of target functions, stop at first target that
+  // can't be inlined.
+  if (opts::ICPPeelForInline) {
+    for (size_t I = 0; I < N; ++I) {
+      const MCSymbol *TargetSym = Targets[I].To.Sym;
+      const BinaryFunction *TargetBF = BC.getFunctionForSymbol(TargetSym);
+      if (!BinaryFunctionPass::shouldOptimize(*TargetBF) ||
+          getInliningInfo(*TargetBF).Type == InliningType::INL_NONE) {
+        N = I;
+        break;
+      }
+    }
+  }
+
   // Filter functions that can have ICP applied (for debugging)
   if (!opts::ICPFuncsList.empty()) {
     for (std::string &Name : opts::ICPFuncsList)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124900.426898.patch
Type: text/x-patch
Size: 1553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220504/ec606141/attachment.bin>


More information about the llvm-commits mailing list