[PATCH] D52704: Improve static analysis of cold basic blocks

Aditya Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 30 10:08:55 PDT 2018


hiraditya created this revision.
hiraditya added reviewers: sebpop, brzycki, SirishP, sirishrp.

A basic block calling one of exception handling routines is cold.


https://reviews.llvm.org/D52704

Files:
  lib/Transforms/IPO/HotColdSplitting.cpp


Index: lib/Transforms/IPO/HotColdSplitting.cpp
===================================================================
--- lib/Transforms/IPO/HotColdSplitting.cpp
+++ lib/Transforms/IPO/HotColdSplitting.cpp
@@ -110,19 +110,38 @@
   return succ_empty(&BB);
 }
 
+static bool exceptionHandlingFunctions(const CallInst *CI) {
+  auto F = CI->getCalledFunction();
+  if (!F)
+    return false;
+  auto FName = F->getName();
+  return FName == "__cxa_begin_catch" ||
+         FName == "__cxa_free_exception" ||
+         FName == "__cxa_allocate_exception" ||
+         FName == "__cxa_begin_catch" ||
+         FName == "__cxa_end_catch";
+}
+
 static
 bool unlikelyExecuted(const BasicBlock &BB) {
-  if (blockEndsInUnreachable(BB))
+  if (blockEndsInUnreachable(BB)) {
+    LLVM_DEBUG(dbgs() << "\ncold unreachable BB: " << BB);
     return true;
+  }
   // Exception handling blocks are unlikely executed.
-  if (BB.isEHPad())
+  if (BB.isEHPad()) {
+    LLVM_DEBUG(dbgs() << "\ncold ehpad BB: " << BB);
     return true;
+  }
   for (const Instruction &I : BB)
     if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
       // The block is cold if it calls functions tagged as cold or noreturn.
       if (CI->hasFnAttr(Attribute::Cold) ||
-          CI->hasFnAttr(Attribute::NoReturn))
+          CI->hasFnAttr(Attribute::NoReturn) ||
+          exceptionHandlingFunctions(CI)) {
+        LLVM_DEBUG(dbgs() << "\ncold instruction: " << I);
         return true;
+      }
 
       // Assume that inline assembly is hot code.
       if (isa<InlineAsm>(CI->getCalledValue()))
@@ -132,7 +151,7 @@
 }
 
 static DenseSetBB getHotBlocks(Function &F) {
-
+  LLVM_DEBUG(dbgs() << "\nprocessing Function: " << F.getName());
   // Mark all cold basic blocks.
   DenseSetBB ColdBlocks;
   for (BasicBlock &BB : F)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52704.167652.patch
Type: text/x-patch
Size: 1800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180930/f927db4e/attachment.bin>


More information about the llvm-commits mailing list