[llvm] r341838 - HotColdSplitting: check that target supports cold calling convention

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 10 08:08:02 PDT 2018


Author: spop
Date: Mon Sep 10 08:08:02 2018
New Revision: 341838

URL: http://llvm.org/viewvc/llvm-project?rev=341838&view=rev
Log:
HotColdSplitting: check that target supports cold calling convention

Before tagging a function with coldcc make sure the target supports cold calling
convention. Without this patch HotColdSplitting pass fails on aarch64 with:

  fatal error: error in backend: Unsupported calling convention.

Modified:
    llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp

Modified: llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp?rev=341838&r1=341837&r2=341838&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp Mon Sep 10 08:08:02 2018
@@ -22,6 +22,7 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/PostDominators.h"
 #include "llvm/Analysis/ProfileSummaryInfo.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/DataLayout.h"
@@ -166,8 +167,9 @@ class HotColdSplitting {
 public:
   HotColdSplitting(ProfileSummaryInfo *ProfSI,
                    function_ref<BlockFrequencyInfo *(Function &)> GBFI,
+                   function_ref<TargetTransformInfo &(Function &)> GTTI,
                    std::function<OptimizationRemarkEmitter &(Function &)> *GORE)
-      : PSI(ProfSI), GetBFI(GBFI), GetORE(GORE) {}
+      : PSI(ProfSI), GetBFI(GBFI), GetTTI(GTTI), GetORE(GORE) {}
   bool run(Module &M);
 
 private:
@@ -195,6 +197,7 @@ private:
   SmallPtrSet<const Function *, 2> OutlinedFunctions;
   ProfileSummaryInfo *PSI;
   function_ref<BlockFrequencyInfo *(Function &)> GetBFI;
+  function_ref<TargetTransformInfo &(Function &)> GetTTI;
   std::function<OptimizationRemarkEmitter &(Function &)> *GetORE;
 };
 
@@ -209,6 +212,7 @@ public:
     AU.addRequired<AssumptionCacheTracker>();
     AU.addRequired<BlockFrequencyInfoWrapperPass>();
     AU.addRequired<ProfileSummaryInfoWrapperPass>();
+    AU.addRequired<TargetTransformInfoWrapperPass>();
   }
 
   bool runOnModule(Module &M) override;
@@ -262,8 +266,10 @@ HotColdSplitting::extractColdRegion(cons
     CallInst *CI = cast<CallInst>(U);
     CallSite CS(CI);
     NumColdSESEOutlined++;
-    OutF->setCallingConv(CallingConv::Cold);
-    CS.setCallingConv(CallingConv::Cold);
+    if (GetTTI(*OutF).useColdCCForColdCall(*OutF)) {
+      OutF->setCallingConv(CallingConv::Cold);
+      CS.setCallingConv(CallingConv::Cold);
+    }
     CI->setIsNoInline();
     LLVM_DEBUG(llvm::dbgs() << "Outlined Region at block: " << Region.front());
     return OutF;
@@ -344,6 +350,9 @@ bool HotColdSplittingLegacyPass::runOnMo
     return false;
   ProfileSummaryInfo *PSI =
       getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
+  auto GTTI = [this](Function &F) -> TargetTransformInfo & {
+    return this->getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
+  };
   auto GBFI = [this](Function &F) {
     return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
   };
@@ -354,7 +363,7 @@ bool HotColdSplittingLegacyPass::runOnMo
     return *ORE.get();
   };
 
-  return HotColdSplitting(PSI, GBFI, &GetORE).run(M);
+  return HotColdSplitting(PSI, GBFI, GTTI, &GetORE).run(M);
 }
 
 char HotColdSplittingLegacyPass::ID = 0;




More information about the llvm-commits mailing list