[PATCH] D69257: Outline non returning functions unless a longjmp

Ruijie Fang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 22 17:43:15 PDT 2020


rjf updated this revision to Diff 279985.
rjf added a comment.

Utilize profile information to mark longjmp blocks as unlikely executed if they are cold.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69257/new/

https://reviews.llvm.org/D69257

Files:
  llvm/lib/Transforms/IPO/HotColdSplitting.cpp


Index: llvm/lib/Transforms/IPO/HotColdSplitting.cpp
===================================================================
--- llvm/lib/Transforms/IPO/HotColdSplitting.cpp
+++ llvm/lib/Transforms/IPO/HotColdSplitting.cpp
@@ -102,7 +102,8 @@
   return !(isa<ReturnInst>(I) || isa<IndirectBrInst>(I));
 }
 
-bool unlikelyExecuted(BasicBlock &BB) {
+bool unlikelyExecuted(BasicBlock &BB, ProfileSummaryInfo *PSI,
+                      BlockFrequencyInfo *BFI) {
   // Exception handling blocks are unlikely executed.
   if (BB.isEHPad() || isa<ResumeInst>(BB.getTerminator()))
     return true;
@@ -115,14 +116,18 @@
         return true;
 
   // The block is cold if it has an unreachable terminator, unless it's
-  // preceded by a call to a (possibly warm) noreturn call (e.g. longjmp).
+  // preceded by a call to a (possibly warm) noreturn call (e.g. longjmp);
+  // in the case of a longjmp, if the block is cold according to
+  // profile information, we mark it as unlikely to be executed as well.
   if (blockEndsInUnreachable(BB)) {
     if (auto *CI =
             dyn_cast_or_null<CallInst>(BB.getTerminator()->getPrevNode()))
       if (CI->hasFnAttr(Attribute::NoReturn)) {
         if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI))
-          return II->getIntrinsicID() != Intrinsic::eh_sjlj_longjmp;
-        return !CI->getCalledFunction()->getName().startswith("longjmp");
+          return (II->getIntrinsicID() != Intrinsic::eh_sjlj_longjmp) ||
+                 (BFI && PSI->isColdBlock(&BB, BFI));
+        return !CI->getCalledFunction()->getName().startswith("longjmp") ||
+               (BFI && PSI->isColdBlock(&BB, BFI));
       }
     return true;
   }
@@ -579,7 +584,7 @@
       continue;
 
     bool Cold = (BFI && PSI->isColdBlock(BB, BFI)) ||
-                (EnableStaticAnalyis && unlikelyExecuted(*BB));
+                (EnableStaticAnalyis && unlikelyExecuted(*BB, PSI, BFI));
     if (!Cold)
       continue;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69257.279985.patch
Type: text/x-patch
Size: 1950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200723/633fb2f6/attachment.bin>


More information about the llvm-commits mailing list