//===- 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(Caller) .getCachedResult( *CB.getParent()->getParent()->getParent()); auto &ORE = FAM.getResult(Caller); auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & { return FAM.getResult(F); }; auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & { return FAM.getResult(F); }; auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & { return FAM.getResult(F); }; Function &Callee = *CB.getCalledFunction(); auto &CalleeTTI = FAM.getResult(Callee); bool RemarksEnabled = Callee.getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled( DEBUG_TYPE); return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI, GetBFI, PSI, RemarksEnabled ? &ORE : nullptr); } std::unique_ptr>> llvm::getInlineOrder(InlinePriorityMode UseInlinePriority, FunctionAnalysisManager &FAM, const InlineParams &Params) { switch (UseInlinePriority) { case InlinePriorityMode::NoPriority: return std::make_unique>>(); case InlinePriorityMode::Size: LLVM_DEBUG(dbgs() << " Current used priority: Size priority ---- \n"); return std::make_unique( std::make_unique()); case InlinePriorityMode::Cost: LLVM_DEBUG(dbgs() << " Current used priority: Cost priority ---- \n"); return std::make_unique( std::make_unique([&](const CallBase *CB) -> InlineCost { return getInlineCostWrapper(const_cast(*CB), FAM, Params); })); default: llvm_unreachable("Unsupported Inline Priority Mode"); break; } return nullptr; }