From e87868b7e9178cc404dd9c475fdf56de5d4fb3c2 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Thu, 28 Jun 2018 20:07:47 +0000 Subject: [PATCH] [ThinLTO] Port InlinerFunctionImportStats handling to new PM Summary: The InlinerFunctionImportStats will collect and dump stats regarding how many function inlined into the module were imported by ThinLTO. Reviewers: wmi, dexonsmith Subscribers: mehdi_amini, inglorion, llvm-commits, eraman Differential Revision: https://reviews.llvm.org/D48729 llvm-svn: 335914 --- llvm/include/llvm/Transforms/IPO/Inliner.h | 5 +++++ llvm/lib/Transforms/IPO/Inliner.cpp | 18 ++++++++++++++++++ llvm/test/Transforms/Inline/inline_stats.ll | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/llvm/include/llvm/Transforms/IPO/Inliner.h b/llvm/include/llvm/Transforms/IPO/Inliner.h index eda8cf4..610e450 100644 --- a/llvm/include/llvm/Transforms/IPO/Inliner.h +++ b/llvm/include/llvm/Transforms/IPO/Inliner.h @@ -96,12 +96,17 @@ class InlinerPass : public PassInfoMixin { public: InlinerPass(InlineParams Params = getInlineParams()) : Params(std::move(Params)) {} + ~InlinerPass(); + InlinerPass(InlinerPass &&Arg) + : Params(std::move(Arg.Params)), + ImportedFunctionsStats(std::move(Arg.ImportedFunctionsStats)) {} PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR); private: InlineParams Params; + std::unique_ptr ImportedFunctionsStats; }; } // end namespace llvm diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp index 1698e0b..3da0c2e 100644 --- a/llvm/lib/Transforms/IPO/Inliner.cpp +++ b/llvm/lib/Transforms/IPO/Inliner.cpp @@ -793,6 +793,14 @@ bool LegacyInlinerBase::removeDeadFunctions(CallGraph &CG, return true; } +InlinerPass::~InlinerPass() { + if (ImportedFunctionsStats) { + assert(InlinerFunctionImportStats != InlinerFunctionImportStatsOpts::No); + ImportedFunctionsStats->dump(InlinerFunctionImportStats == + InlinerFunctionImportStatsOpts::Verbose); + } +} + PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR) { @@ -804,6 +812,13 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC, Module &M = *InitialC.begin()->getFunction().getParent(); ProfileSummaryInfo *PSI = MAM.getCachedResult(M); + if (!ImportedFunctionsStats && + InlinerFunctionImportStats != InlinerFunctionImportStatsOpts::No) { + ImportedFunctionsStats = + llvm::make_unique(); + ImportedFunctionsStats->setModuleInfo(M); + } + // We use a single common worklist for calls across the entire SCC. We // process these in-order and append new calls introduced during inlining to // the end. @@ -1009,6 +1024,9 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC, Calls.push_back({CS, NewHistoryID}); } + if (InlinerFunctionImportStats != InlinerFunctionImportStatsOpts::No) + ImportedFunctionsStats->recordInline(F, Callee); + // Merge the attributes based on the inlining. AttributeFuncs::mergeAttributesForInlining(F, Callee); diff --git a/llvm/test/Transforms/Inline/inline_stats.ll b/llvm/test/Transforms/Inline/inline_stats.ll index bc005b6a..40d6cb3 100644 --- a/llvm/test/Transforms/Inline/inline_stats.ll +++ b/llvm/test/Transforms/Inline/inline_stats.ll @@ -1,6 +1,11 @@ +; First with legacy PM ; RUN: opt -S -inline -inliner-function-import-stats=basic < %s 2>&1 | FileCheck %s -check-prefix=CHECK-BASIC -check-prefix=CHECK ; RUN: opt -S -inline -inliner-function-import-stats=verbose < %s 2>&1 | FileCheck %s -check-prefix="CHECK-VERBOSE" -check-prefix=CHECK +; Do again with new PM +; RUN: opt -S -passes=inline -inliner-function-import-stats=basic < %s 2>&1 | FileCheck %s -check-prefix=CHECK-BASIC -check-prefix=CHECK +; RUN: opt -S -passes=inline -inliner-function-import-stats=verbose < %s 2>&1 | FileCheck %s -check-prefix="CHECK-VERBOSE" -check-prefix=CHECK + ; CHECK: ------- Dumping inliner stats for [] ------- ; CHECK-BASIC-NOT: -- List of inlined functions: ; CHECK-BASIC-NOT: -- Inlined not imported function -- 2.7.4