diff options
Diffstat (limited to 'lib/Transforms/IPO/AlwaysInliner.cpp')
-rw-r--r-- | lib/Transforms/IPO/AlwaysInliner.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/lib/Transforms/IPO/AlwaysInliner.cpp b/lib/Transforms/IPO/AlwaysInliner.cpp index 07138718ce2c..c50805692b98 100644 --- a/lib/Transforms/IPO/AlwaysInliner.cpp +++ b/lib/Transforms/IPO/AlwaysInliner.cpp @@ -1,9 +1,8 @@ //===- InlineAlways.cpp - Code to inline always_inline functions ----------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -32,8 +31,17 @@ using namespace llvm; #define DEBUG_TYPE "inline" -PreservedAnalyses AlwaysInlinerPass::run(Module &M, ModuleAnalysisManager &) { - InlineFunctionInfo IFI; +PreservedAnalyses AlwaysInlinerPass::run(Module &M, + ModuleAnalysisManager &MAM) { + // Add inline assumptions during code generation. + FunctionAnalysisManager &FAM = + MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); + std::function<AssumptionCache &(Function &)> GetAssumptionCache = + [&](Function &F) -> AssumptionCache & { + return FAM.getResult<AssumptionAnalysis>(F); + }; + InlineFunctionInfo IFI(/*cg=*/nullptr, &GetAssumptionCache); + SmallSetVector<CallSite, 16> Calls; bool Changed = false; SmallVector<Function *, 16> InlinedFunctions; @@ -146,11 +154,20 @@ InlineCost AlwaysInlinerLegacyPass::getInlineCost(CallSite CS) { Function *Callee = CS.getCalledFunction(); // Only inline direct calls to functions with always-inline attributes - // that are viable for inlining. FIXME: We shouldn't even get here for - // declarations. - if (Callee && !Callee->isDeclaration() && - CS.hasFnAttr(Attribute::AlwaysInline) && isInlineViable(*Callee)) - return InlineCost::getAlways("always inliner"); + // that are viable for inlining. + if (!Callee) + return InlineCost::getNever("indirect call"); + + // FIXME: We shouldn't even get here for declarations. + if (Callee->isDeclaration()) + return InlineCost::getNever("no definition"); + + if (!CS.hasFnAttr(Attribute::AlwaysInline)) + return InlineCost::getNever("no alwaysinline attribute"); + + auto IsViable = isInlineViable(*Callee); + if (!IsViable) + return InlineCost::getNever(IsViable.message); - return InlineCost::getNever("always inliner"); + return InlineCost::getAlways("always inliner"); } |