[llvm] e82eff7 - [llvm][NFC] Factor some common data in InlineAdvice

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 11 08:01:12 PDT 2020


Author: Mircea Trofin
Date: 2020-06-11T08:01:00-07:00
New Revision: e82eff7a03b0785c5a295d048516fd7a6634fee5

URL: https://github.com/llvm/llvm-project/commit/e82eff7a03b0785c5a295d048516fd7a6634fee5
DIFF: https://github.com/llvm/llvm-project/commit/e82eff7a03b0785c5a295d048516fd7a6634fee5.diff

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/InlineAdvisor.h
    llvm/lib/Analysis/InlineAdvisor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/InlineAdvisor.h b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 0a11bd04777d..7268c11fdd79 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 @@ class InlineAdvice {
 
   /// 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 @@ class InlineAdvice {
   /// 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 @@ class InlineAdvisor {
   /// 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<Function *> DeletedFunctions;
+  std::unordered_set<const Function *> 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 4d8a241ef9fe..d5b71f644d80 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<InlineCost> 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 @@ class DefaultInlineAdvice : public InlineAdvice {
 private:
   CallBase *const OriginalCB;
   Optional<InlineCost> 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<InlineAdvice> 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) {


        


More information about the llvm-commits mailing list