@@ -126,6 +126,10 @@ static cl::opt<int>
126
126
InstrCost (" inline-instr-cost" , cl::Hidden, cl::init(5 ),
127
127
cl::desc(" Cost of a single instruction when inlining" ));
128
128
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
+
129
133
static cl::opt<int > CallPenalty (
130
134
" inline-call-penalty" , cl::Hidden, cl::init(25 ),
131
135
cl::desc(" Call penalty that is applied per callsite when inlining" ));
@@ -282,6 +286,9 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
282
286
// / Called to account for a call.
283
287
virtual void onCallPenalty () {}
284
288
289
+ // / Called to account for a load or store.
290
+ virtual void onMemAccess (){};
291
+
285
292
// / Called to account for the expectation the inlining would result in a load
286
293
// / elimination.
287
294
virtual void onLoadEliminationOpportunity () {}
@@ -625,6 +632,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
625
632
}
626
633
627
634
void onCallPenalty () override { addCost (CallPenalty); }
635
+
636
+ void onMemAccess () override { addCost (MemAccessCost); }
637
+
628
638
void onCallArgumentSetup (const CallBase &Call) override {
629
639
// Pay the price of the argument setup. We account for the average 1
630
640
// instruction per call argument setup here.
@@ -2044,6 +2054,7 @@ bool CallAnalyzer::visitLoad(LoadInst &I) {
2044
2054
return true ;
2045
2055
}
2046
2056
2057
+ onMemAccess ();
2047
2058
return false ;
2048
2059
}
2049
2060
@@ -2060,6 +2071,8 @@ bool CallAnalyzer::visitStore(StoreInst &I) {
2060
2071
// 2. We should probably at some point thread MemorySSA for the callee into
2061
2072
// this and then use that to actually compute *really* precise savings.
2062
2073
disableLoadElimination ();
2074
+
2075
+ onMemAccess ();
2063
2076
return false ;
2064
2077
}
2065
2078
0 commit comments