| //===- InlineOrder.cpp - Inlining order abstraction -*- C++ ---*-----------===// |
| // |
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| // See https://llvm.org/LICENSE.txt for license information. |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| // |
| //===----------------------------------------------------------------------===// |
| |
| #include "llvm/Analysis/InlineOrder.h" |
| #include "llvm/Analysis/AssumptionCache.h" |
| #include "llvm/Analysis/BlockFrequencyInfo.h" |
| #include "llvm/Analysis/GlobalsModRef.h" |
| #include "llvm/Analysis/InlineAdvisor.h" |
| #include "llvm/Analysis/InlineCost.h" |
| #include "llvm/Analysis/OptimizationRemarkEmitter.h" |
| #include "llvm/Analysis/ProfileSummaryInfo.h" |
| #include "llvm/Analysis/TargetLibraryInfo.h" |
| #include "llvm/Analysis/TargetTransformInfo.h" |
| |
| using namespace llvm; |
| |
| #define DEBUG_TYPE "inline-order" |
| |
| static llvm::InlineCost getInlineCostWrapper(CallBase &CB, |
| FunctionAnalysisManager &FAM, |
| const InlineParams &Params) { |
| Function &Caller = *CB.getCaller(); |
| ProfileSummaryInfo *PSI = |
| FAM.getResult<ModuleAnalysisManagerFunctionProxy>(Caller) |
| .getCachedResult<ProfileSummaryAnalysis>( |
| *CB.getParent()->getParent()->getParent()); |
| |
| auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(Caller); |
| auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & { |
| return FAM.getResult<AssumptionAnalysis>(F); |
| }; |
| auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & { |
| return FAM.getResult<BlockFrequencyAnalysis>(F); |
| }; |
| auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & { |
| return FAM.getResult<TargetLibraryAnalysis>(F); |
| }; |
| |
| Function &Callee = *CB.getCalledFunction(); |
| auto &CalleeTTI = FAM.getResult<TargetIRAnalysis>(Callee); |
| bool RemarksEnabled = |
| Callee.getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled( |
| DEBUG_TYPE); |
| return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI, |
| GetBFI, PSI, RemarksEnabled ? &ORE : nullptr); |
| } |
| |
| std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>> |
| llvm::getInlineOrder(InlinePriorityMode UseInlinePriority, |
| FunctionAnalysisManager &FAM, const InlineParams &Params) { |
| switch (UseInlinePriority) { |
| case InlinePriorityMode::NoPriority: |
| return std::make_unique<DefaultInlineOrder<std::pair<CallBase *, int>>>(); |
| |
| case InlinePriorityMode::Size: |
| LLVM_DEBUG(dbgs() << " Current used priority: Size priority ---- \n"); |
| return std::make_unique<PriorityInlineOrder>( |
| std::make_unique<SizePriority>()); |
| |
| case InlinePriorityMode::Cost: |
| LLVM_DEBUG(dbgs() << " Current used priority: Cost priority ---- \n"); |
| return std::make_unique<PriorityInlineOrder>( |
| std::make_unique<CostPriority>([&](const CallBase *CB) -> InlineCost { |
| return getInlineCostWrapper(const_cast<CallBase &>(*CB), FAM, Params); |
| })); |
| |
| default: |
| llvm_unreachable("Unsupported Inline Priority Mode"); |
| break; |
| } |
| return nullptr; |
| } |