diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/libs/llvm12/lib/Transforms/IPO/HotColdSplitting.cpp | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
download | ydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/Transforms/IPO/HotColdSplitting.cpp')
-rw-r--r-- | contrib/libs/llvm12/lib/Transforms/IPO/HotColdSplitting.cpp | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/contrib/libs/llvm12/lib/Transforms/IPO/HotColdSplitting.cpp b/contrib/libs/llvm12/lib/Transforms/IPO/HotColdSplitting.cpp index 0f91173aab..aa708ee520 100644 --- a/contrib/libs/llvm12/lib/Transforms/IPO/HotColdSplitting.cpp +++ b/contrib/libs/llvm12/lib/Transforms/IPO/HotColdSplitting.cpp @@ -67,9 +67,9 @@ #include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/ValueMapper.h" #include <algorithm> -#include <limits> +#include <limits> #include <cassert> -#include <string> +#include <string> #define DEBUG_TYPE "hotcoldsplit" @@ -78,29 +78,29 @@ STATISTIC(NumColdRegionsOutlined, "Number of cold regions outlined."); using namespace llvm; -static cl::opt<bool> EnableStaticAnalysis("hot-cold-static-analysis", - cl::init(true), cl::Hidden); +static cl::opt<bool> EnableStaticAnalysis("hot-cold-static-analysis", + cl::init(true), cl::Hidden); static cl::opt<int> SplittingThreshold("hotcoldsplit-threshold", cl::init(2), cl::Hidden, cl::desc("Base penalty for splitting cold code (as a " "multiple of TCC_Basic)")); -static cl::opt<bool> EnableColdSection( - "enable-cold-section", cl::init(false), cl::Hidden, - cl::desc("Enable placement of extracted cold functions" - " into a separate section after hot-cold splitting.")); - -static cl::opt<std::string> - ColdSectionName("hotcoldsplit-cold-section-name", cl::init("__llvm_cold"), - cl::Hidden, - cl::desc("Name for the section containing cold functions " - "extracted by hot-cold splitting.")); - -static cl::opt<int> MaxParametersForSplit( - "hotcoldsplit-max-params", cl::init(4), cl::Hidden, - cl::desc("Maximum number of parameters for a split function")); - +static cl::opt<bool> EnableColdSection( + "enable-cold-section", cl::init(false), cl::Hidden, + cl::desc("Enable placement of extracted cold functions" + " into a separate section after hot-cold splitting.")); + +static cl::opt<std::string> + ColdSectionName("hotcoldsplit-cold-section-name", cl::init("__llvm_cold"), + cl::Hidden, + cl::desc("Name for the section containing cold functions " + "extracted by hot-cold splitting.")); + +static cl::opt<int> MaxParametersForSplit( + "hotcoldsplit-max-params", cl::init(4), cl::Hidden, + cl::desc("Maximum number of parameters for a split function")); + namespace { // Same as blockEndsInUnreachable in CodeGen/BranchFolding.cpp. Do not modify // this function unless you modify the MBB version as well. @@ -237,11 +237,11 @@ bool HotColdSplitting::shouldOutlineFrom(const Function &F) const { } /// Get the benefit score of outlining \p Region. -static InstructionCost getOutliningBenefit(ArrayRef<BasicBlock *> Region, - TargetTransformInfo &TTI) { +static InstructionCost getOutliningBenefit(ArrayRef<BasicBlock *> Region, + TargetTransformInfo &TTI) { // Sum up the code size costs of non-terminator instructions. Tight coupling // with \ref getOutliningPenalty is needed to model the costs of terminators. - InstructionCost Benefit = 0; + InstructionCost Benefit = 0; for (BasicBlock *BB : Region) for (Instruction &I : BB->instructionsWithoutDebug()) if (&I != BB->getTerminator()) @@ -275,55 +275,55 @@ static int getOutliningPenalty(ArrayRef<BasicBlock *> Region, } for (BasicBlock *SuccBB : successors(BB)) { - if (!is_contained(Region, SuccBB)) { + if (!is_contained(Region, SuccBB)) { NoBlocksReturn = false; SuccsOutsideRegion.insert(SuccBB); } } } - // Count the number of phis in exit blocks with >= 2 incoming values from the - // outlining region. These phis are split (\ref severSplitPHINodesOfExits), - // and new outputs are created to supply the split phis. CodeExtractor can't - // report these new outputs until extraction begins, but it's important to - // factor the cost of the outputs into the cost calculation. - unsigned NumSplitExitPhis = 0; - for (BasicBlock *ExitBB : SuccsOutsideRegion) { - for (PHINode &PN : ExitBB->phis()) { - // Find all incoming values from the outlining region. - int NumIncomingVals = 0; - for (unsigned i = 0; i < PN.getNumIncomingValues(); ++i) - if (find(Region, PN.getIncomingBlock(i)) != Region.end()) { - ++NumIncomingVals; - if (NumIncomingVals > 1) { - ++NumSplitExitPhis; - break; - } - } - } - } - - // Apply a penalty for calling the split function. Factor in the cost of - // materializing all of the parameters. - int NumOutputsAndSplitPhis = NumOutputs + NumSplitExitPhis; - int NumParams = NumInputs + NumOutputsAndSplitPhis; - if (NumParams > MaxParametersForSplit) { - LLVM_DEBUG(dbgs() << NumInputs << " inputs and " << NumOutputsAndSplitPhis - << " outputs exceeds parameter limit (" - << MaxParametersForSplit << ")\n"); - return std::numeric_limits<int>::max(); - } - const int CostForArgMaterialization = 2 * TargetTransformInfo::TCC_Basic; - LLVM_DEBUG(dbgs() << "Applying penalty for: " << NumParams << " params\n"); - Penalty += CostForArgMaterialization * NumParams; - - // Apply the typical code size cost for an output alloca and its associated - // reload in the caller. Also penalize the associated store in the callee. - LLVM_DEBUG(dbgs() << "Applying penalty for: " << NumOutputsAndSplitPhis - << " outputs/split phis\n"); - const int CostForRegionOutput = 3 * TargetTransformInfo::TCC_Basic; - Penalty += CostForRegionOutput * NumOutputsAndSplitPhis; - + // Count the number of phis in exit blocks with >= 2 incoming values from the + // outlining region. These phis are split (\ref severSplitPHINodesOfExits), + // and new outputs are created to supply the split phis. CodeExtractor can't + // report these new outputs until extraction begins, but it's important to + // factor the cost of the outputs into the cost calculation. + unsigned NumSplitExitPhis = 0; + for (BasicBlock *ExitBB : SuccsOutsideRegion) { + for (PHINode &PN : ExitBB->phis()) { + // Find all incoming values from the outlining region. + int NumIncomingVals = 0; + for (unsigned i = 0; i < PN.getNumIncomingValues(); ++i) + if (find(Region, PN.getIncomingBlock(i)) != Region.end()) { + ++NumIncomingVals; + if (NumIncomingVals > 1) { + ++NumSplitExitPhis; + break; + } + } + } + } + + // Apply a penalty for calling the split function. Factor in the cost of + // materializing all of the parameters. + int NumOutputsAndSplitPhis = NumOutputs + NumSplitExitPhis; + int NumParams = NumInputs + NumOutputsAndSplitPhis; + if (NumParams > MaxParametersForSplit) { + LLVM_DEBUG(dbgs() << NumInputs << " inputs and " << NumOutputsAndSplitPhis + << " outputs exceeds parameter limit (" + << MaxParametersForSplit << ")\n"); + return std::numeric_limits<int>::max(); + } + const int CostForArgMaterialization = 2 * TargetTransformInfo::TCC_Basic; + LLVM_DEBUG(dbgs() << "Applying penalty for: " << NumParams << " params\n"); + Penalty += CostForArgMaterialization * NumParams; + + // Apply the typical code size cost for an output alloca and its associated + // reload in the caller. Also penalize the associated store in the callee. + LLVM_DEBUG(dbgs() << "Applying penalty for: " << NumOutputsAndSplitPhis + << " outputs/split phis\n"); + const int CostForRegionOutput = 3 * TargetTransformInfo::TCC_Basic; + Penalty += CostForRegionOutput * NumOutputsAndSplitPhis; + // Apply a `noreturn` bonus. if (NoBlocksReturn) { LLVM_DEBUG(dbgs() << "Applying bonus for: " << Region.size() @@ -333,7 +333,7 @@ static int getOutliningPenalty(ArrayRef<BasicBlock *> Region, // Apply a penalty for having more than one successor outside of the region. // This penalty accounts for the switch needed in the caller. - if (SuccsOutsideRegion.size() > 1) { + if (SuccsOutsideRegion.size() > 1) { LLVM_DEBUG(dbgs() << "Applying penalty for: " << SuccsOutsideRegion.size() << " non-region successors\n"); Penalty += (SuccsOutsideRegion.size() - 1) * TargetTransformInfo::TCC_Basic; @@ -358,12 +358,12 @@ Function *HotColdSplitting::extractColdRegion( // splitting. SetVector<Value *> Inputs, Outputs, Sinks; CE.findInputsOutputs(Inputs, Outputs, Sinks); - InstructionCost OutliningBenefit = getOutliningBenefit(Region, TTI); + InstructionCost OutliningBenefit = getOutliningBenefit(Region, TTI); int OutliningPenalty = getOutliningPenalty(Region, Inputs.size(), Outputs.size()); LLVM_DEBUG(dbgs() << "Split profitability: benefit = " << OutliningBenefit << ", penalty = " << OutliningPenalty << "\n"); - if (!OutliningBenefit.isValid() || OutliningBenefit <= OutliningPenalty) + if (!OutliningBenefit.isValid() || OutliningBenefit <= OutliningPenalty) return nullptr; Function *OrigF = Region[0]->getParent(); @@ -377,12 +377,12 @@ Function *HotColdSplitting::extractColdRegion( } CI->setIsNoInline(); - if (EnableColdSection) - OutF->setSection(ColdSectionName); - else { - if (OrigF->hasSection()) - OutF->setSection(OrigF->getSection()); - } + if (EnableColdSection) + OutF->setSection(ColdSectionName); + else { + if (OrigF->hasSection()) + OutF->setSection(OrigF->getSection()); + } markFunctionCold(*OutF, BFI != nullptr); @@ -625,7 +625,7 @@ bool HotColdSplitting::outlineColdRegions(Function &F, bool HasProfileSummary) { continue; bool Cold = (BFI && PSI->isColdBlock(BB, BFI)) || - (EnableStaticAnalysis && unlikelyExecuted(*BB)); + (EnableStaticAnalysis && unlikelyExecuted(*BB)); if (!Cold) continue; |