diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h --- a/llvm/include/llvm/Analysis/TargetTransformInfo.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -39,6 +39,7 @@ typedef unsigned ID; } +class AllocaInst; class AssumptionCache; class BlockFrequencyInfo; class DominatorTree; @@ -344,6 +345,10 @@ /// \returns A value to be added to the inlining threshold. unsigned adjustInliningThreshold(const CallBase *CB) const; + /// \returns The cost of having an Alloca in the caller if not inlined, to be + /// added to the threshold + unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const; + /// \returns Vector bonus in percent. /// /// Vector bonuses: We want to more aggressively inline vector-dense kernels @@ -1674,6 +1679,8 @@ virtual unsigned getInliningThresholdMultiplier() const = 0; virtual unsigned adjustInliningThreshold(const CallBase *CB) = 0; virtual int getInlinerVectorBonusPercent() const = 0; + virtual unsigned getCallerAllocaCost(const CallBase *CB, + const AllocaInst *AI) const = 0; virtual InstructionCost getMemcpyCost(const Instruction *I) = 0; virtual unsigned getEstimatedNumberOfCaseClusters(const SwitchInst &SI, unsigned &JTSize, @@ -2038,10 +2045,14 @@ } unsigned adjustInliningThreshold(const CallBase *CB) override { return Impl.adjustInliningThreshold(CB); - } + } int getInlinerVectorBonusPercent() const override { return Impl.getInlinerVectorBonusPercent(); } + unsigned getCallerAllocaCost(const CallBase *CB, + const AllocaInst *AI) const override { + return Impl.getCallerAllocaCost(CB, AI); + } InstructionCost getMemcpyCost(const Instruction *I) override { return Impl.getMemcpyCost(I); } diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -70,6 +70,9 @@ unsigned getInliningThresholdMultiplier() const { return 1; } unsigned adjustInliningThreshold(const CallBase *CB) const { return 0; } + unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const { + return 0; + }; int getInlinerVectorBonusPercent() const { return 150; } diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -534,6 +534,9 @@ unsigned getInliningThresholdMultiplier() const { return 1; } unsigned adjustInliningThreshold(const CallBase *CB) { return 0; } + unsigned getCallerAllocaCost(const CallBase *CB, const AllocaInst *AI) const { + return 0; + } int getInlinerVectorBonusPercent() const { return 150; } diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -717,7 +717,8 @@ void onInitializeSROAArg(AllocaInst *Arg) override { assert(Arg != nullptr && "Should not initialize SROA costs for null value."); - SROAArgCosts[Arg] = 0; + SROACostSavings += SROAArgCosts[Arg] = + TTI.getCallerAllocaCost(&CandidateCall, Arg); } void onAggregateSROAUse(AllocaInst *SROAArg) override { diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -217,6 +217,11 @@ return TTIImpl->adjustInliningThreshold(CB); } +unsigned TargetTransformInfo::getCallerAllocaCost(const CallBase *CB, + const AllocaInst *AI) const { + return TTIImpl->getCallerAllocaCost(CB, AI); +} + int TargetTransformInfo::getInlinerVectorBonusPercent() const { return TTIImpl->getInlinerVectorBonusPercent(); }