From e82eff7a03b0785c5a295d048516fd7a6634fee5 Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Tue, 9 Jun 2020 14:33:46 -0700 Subject: [PATCH] [llvm][NFC] Factor some common data in InlineAdvice Summary: Other derivations will all want to emit optimization remarks and, as part of that, use debug info. Additionally, drive-by const-ing. Reviewers: davidxl, dblaikie Subscribers: aprantl, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D81507 --- llvm/include/llvm/Analysis/InlineAdvisor.h | 19 ++++++++++++++----- llvm/lib/Analysis/InlineAdvisor.cpp | 13 ++++--------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h b/llvm/include/llvm/Analysis/InlineAdvisor.h index 0a11bd0..7268c11 100644 --- a/llvm/include/llvm/Analysis/InlineAdvisor.h +++ b/llvm/include/llvm/Analysis/InlineAdvisor.h @@ -48,6 +48,9 @@ class InlineAdvisor; /// obligations. class InlineAdvice { public: + InlineAdvice(InlineAdvisor *Advisor, CallBase &CB, + OptimizationRemarkEmitter &ORE, bool IsInliningRecommended); + InlineAdvice(InlineAdvice &&) = delete; InlineAdvice(const InlineAdvice &) = delete; virtual ~InlineAdvice() { @@ -81,11 +84,10 @@ public: /// Get the inlining recommendation. bool isInliningRecommended() const { return IsInliningRecommended; } + const DebugLoc &getOriginalCallSiteDebugLoc() const { return DLoc; } + const BasicBlock *getOriginalCallSiteBasicBlock() const { return Block; } protected: - InlineAdvice(InlineAdvisor *Advisor, CallBase &CB, - bool IsInliningRecommended); - virtual void recordInliningImpl() {} virtual void recordInliningWithCalleeDeletedImpl() {} virtual void recordUnsuccessfulInliningImpl(const InlineResult &Result) {} @@ -95,6 +97,13 @@ protected: /// Caller and Callee are pre-inlining. Function *const Caller; Function *const Callee; + + // Capture the context of CB before inlining, as a successful inlining may + // change that context, and we want to report success or failure in the + // original context. + const DebugLoc DLoc; + const BasicBlock *const Block; + OptimizationRemarkEmitter &ORE; const bool IsInliningRecommended; private: @@ -142,14 +151,14 @@ protected: /// after each SCC inlining (e.g. argument promotion does that). void freeDeletedFunctions(); - bool isFunctionDeleted(Function *F) const { + bool isFunctionDeleted(const Function *F) const { return DeletedFunctions.count(F); } private: friend class InlineAdvice; void markFunctionAsDeleted(Function *F); - std::unordered_set DeletedFunctions; + std::unordered_set DeletedFunctions; }; /// The default (manual heuristics) implementation of the InlineAdvisor. This diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp index 4d8a241..d5b71f6 100644 --- a/llvm/lib/Analysis/InlineAdvisor.cpp +++ b/llvm/lib/Analysis/InlineAdvisor.cpp @@ -52,8 +52,8 @@ class DefaultInlineAdvice : public InlineAdvice { public: DefaultInlineAdvice(DefaultInlineAdvisor *Advisor, CallBase &CB, Optional OIC, OptimizationRemarkEmitter &ORE) - : InlineAdvice(Advisor, CB, OIC.hasValue()), OriginalCB(&CB), OIC(OIC), - ORE(ORE), DLoc(CB.getDebugLoc()), Block(CB.getParent()) {} + : InlineAdvice(Advisor, CB, ORE, OIC.hasValue()), OriginalCB(&CB), + OIC(OIC) {} private: void recordUnsuccessfulInliningImpl(const InlineResult &Result) override { @@ -79,13 +79,6 @@ private: private: CallBase *const OriginalCB; Optional OIC; - OptimizationRemarkEmitter &ORE; - - // Capture the context of CB before inlining, as a successful inlining may - // change that context, and we want to report success or failure in the - // original context. - const DebugLoc DLoc; - const BasicBlock *const Block; }; } // namespace @@ -124,8 +117,10 @@ std::unique_ptr DefaultInlineAdvisor::getAdvice(CallBase &CB) { } InlineAdvice::InlineAdvice(InlineAdvisor *Advisor, CallBase &CB, + OptimizationRemarkEmitter &ORE, bool IsInliningRecommended) : Advisor(Advisor), Caller(CB.getCaller()), Callee(CB.getCalledFunction()), + DLoc(CB.getDebugLoc()), Block(CB.getParent()), ORE(ORE), IsInliningRecommended(IsInliningRecommended) {} void InlineAdvisor::markFunctionAsDeleted(Function *F) { -- 2.7.4