Skip to content

Commit e82eff7

Browse files
committed
[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
1 parent 7706c7a commit e82eff7

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

llvm/include/llvm/Analysis/InlineAdvisor.h

+14-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class InlineAdvisor;
4848
/// obligations.
4949
class InlineAdvice {
5050
public:
51+
InlineAdvice(InlineAdvisor *Advisor, CallBase &CB,
52+
OptimizationRemarkEmitter &ORE, bool IsInliningRecommended);
53+
5154
InlineAdvice(InlineAdvice &&) = delete;
5255
InlineAdvice(const InlineAdvice &) = delete;
5356
virtual ~InlineAdvice() {
@@ -81,11 +84,10 @@ class InlineAdvice {
8184

8285
/// Get the inlining recommendation.
8386
bool isInliningRecommended() const { return IsInliningRecommended; }
87+
const DebugLoc &getOriginalCallSiteDebugLoc() const { return DLoc; }
88+
const BasicBlock *getOriginalCallSiteBasicBlock() const { return Block; }
8489

8590
protected:
86-
InlineAdvice(InlineAdvisor *Advisor, CallBase &CB,
87-
bool IsInliningRecommended);
88-
8991
virtual void recordInliningImpl() {}
9092
virtual void recordInliningWithCalleeDeletedImpl() {}
9193
virtual void recordUnsuccessfulInliningImpl(const InlineResult &Result) {}
@@ -95,6 +97,13 @@ class InlineAdvice {
9597
/// Caller and Callee are pre-inlining.
9698
Function *const Caller;
9799
Function *const Callee;
100+
101+
// Capture the context of CB before inlining, as a successful inlining may
102+
// change that context, and we want to report success or failure in the
103+
// original context.
104+
const DebugLoc DLoc;
105+
const BasicBlock *const Block;
106+
OptimizationRemarkEmitter &ORE;
98107
const bool IsInliningRecommended;
99108

100109
private:
@@ -142,14 +151,14 @@ class InlineAdvisor {
142151
/// after each SCC inlining (e.g. argument promotion does that).
143152
void freeDeletedFunctions();
144153

145-
bool isFunctionDeleted(Function *F) const {
154+
bool isFunctionDeleted(const Function *F) const {
146155
return DeletedFunctions.count(F);
147156
}
148157

149158
private:
150159
friend class InlineAdvice;
151160
void markFunctionAsDeleted(Function *F);
152-
std::unordered_set<Function *> DeletedFunctions;
161+
std::unordered_set<const Function *> DeletedFunctions;
153162
};
154163

155164
/// The default (manual heuristics) implementation of the InlineAdvisor. This

llvm/lib/Analysis/InlineAdvisor.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class DefaultInlineAdvice : public InlineAdvice {
5252
public:
5353
DefaultInlineAdvice(DefaultInlineAdvisor *Advisor, CallBase &CB,
5454
Optional<InlineCost> OIC, OptimizationRemarkEmitter &ORE)
55-
: InlineAdvice(Advisor, CB, OIC.hasValue()), OriginalCB(&CB), OIC(OIC),
56-
ORE(ORE), DLoc(CB.getDebugLoc()), Block(CB.getParent()) {}
55+
: InlineAdvice(Advisor, CB, ORE, OIC.hasValue()), OriginalCB(&CB),
56+
OIC(OIC) {}
5757

5858
private:
5959
void recordUnsuccessfulInliningImpl(const InlineResult &Result) override {
@@ -79,13 +79,6 @@ class DefaultInlineAdvice : public InlineAdvice {
7979
private:
8080
CallBase *const OriginalCB;
8181
Optional<InlineCost> OIC;
82-
OptimizationRemarkEmitter &ORE;
83-
84-
// Capture the context of CB before inlining, as a successful inlining may
85-
// change that context, and we want to report success or failure in the
86-
// original context.
87-
const DebugLoc DLoc;
88-
const BasicBlock *const Block;
8982
};
9083

9184
} // namespace
@@ -124,8 +117,10 @@ std::unique_ptr<InlineAdvice> DefaultInlineAdvisor::getAdvice(CallBase &CB) {
124117
}
125118

126119
InlineAdvice::InlineAdvice(InlineAdvisor *Advisor, CallBase &CB,
120+
OptimizationRemarkEmitter &ORE,
127121
bool IsInliningRecommended)
128122
: Advisor(Advisor), Caller(CB.getCaller()), Callee(CB.getCalledFunction()),
123+
DLoc(CB.getDebugLoc()), Block(CB.getParent()), ORE(ORE),
129124
IsInliningRecommended(IsInliningRecommended) {}
130125

131126
void InlineAdvisor::markFunctionAsDeleted(Function *F) {

0 commit comments

Comments
 (0)