Skip to content

Commit 8d2901d

Browse files
committed
[NFC][Inliner] Add Load/Store handler
This is an additional signal which may benefit sanitizers. Reviewed By: kda Differential Revision: https://reviews.llvm.org/D131129
1 parent b5244fb commit 8d2901d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ static cl::opt<int>
126126
InstrCost("inline-instr-cost", cl::Hidden, cl::init(5),
127127
cl::desc("Cost of a single instruction when inlining"));
128128

129+
static cl::opt<int>
130+
MemAccessCost("inline-memaccess-cost", cl::Hidden, cl::init(0),
131+
cl::desc("Cost of load/store instruction when inlining"));
132+
129133
static cl::opt<int> CallPenalty(
130134
"inline-call-penalty", cl::Hidden, cl::init(25),
131135
cl::desc("Call penalty that is applied per callsite when inlining"));
@@ -282,6 +286,9 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
282286
/// Called to account for a call.
283287
virtual void onCallPenalty() {}
284288

289+
/// Called to account for a load or store.
290+
virtual void onMemAccess(){};
291+
285292
/// Called to account for the expectation the inlining would result in a load
286293
/// elimination.
287294
virtual void onLoadEliminationOpportunity() {}
@@ -625,6 +632,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
625632
}
626633

627634
void onCallPenalty() override { addCost(CallPenalty); }
635+
636+
void onMemAccess() override { addCost(MemAccessCost); }
637+
628638
void onCallArgumentSetup(const CallBase &Call) override {
629639
// Pay the price of the argument setup. We account for the average 1
630640
// instruction per call argument setup here.
@@ -2044,6 +2054,7 @@ bool CallAnalyzer::visitLoad(LoadInst &I) {
20442054
return true;
20452055
}
20462056

2057+
onMemAccess();
20472058
return false;
20482059
}
20492060

@@ -2060,6 +2071,8 @@ bool CallAnalyzer::visitStore(StoreInst &I) {
20602071
// 2. We should probably at some point thread MemorySSA for the callee into
20612072
// this and then use that to actually compute *really* precise savings.
20622073
disableLoadElimination();
2074+
2075+
onMemAccess();
20632076
return false;
20642077
}
20652078

0 commit comments

Comments
 (0)