Skip to content

Commit

Permalink
[NFC][Inliner] Add Load/Store handler
Browse files Browse the repository at this point in the history
This is an additional signal which may benefit sanitizers.

Reviewed By: kda

Differential Revision: https://reviews.llvm.org/D131129
  • Loading branch information
vitalybuka committed Aug 5, 2022
1 parent b5244fb commit 8d2901d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions llvm/lib/Analysis/InlineCost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ static cl::opt<int>
InstrCost("inline-instr-cost", cl::Hidden, cl::init(5),
cl::desc("Cost of a single instruction when inlining"));

static cl::opt<int>
MemAccessCost("inline-memaccess-cost", cl::Hidden, cl::init(0),
cl::desc("Cost of load/store instruction when inlining"));

static cl::opt<int> CallPenalty(
"inline-call-penalty", cl::Hidden, cl::init(25),
cl::desc("Call penalty that is applied per callsite when inlining"));
Expand Down Expand Up @@ -282,6 +286,9 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
/// Called to account for a call.
virtual void onCallPenalty() {}

/// Called to account for a load or store.
virtual void onMemAccess(){};

/// Called to account for the expectation the inlining would result in a load
/// elimination.
virtual void onLoadEliminationOpportunity() {}
Expand Down Expand Up @@ -625,6 +632,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
}

void onCallPenalty() override { addCost(CallPenalty); }

void onMemAccess() override { addCost(MemAccessCost); }

void onCallArgumentSetup(const CallBase &Call) override {
// Pay the price of the argument setup. We account for the average 1
// instruction per call argument setup here.
Expand Down Expand Up @@ -2044,6 +2054,7 @@ bool CallAnalyzer::visitLoad(LoadInst &I) {
return true;
}

onMemAccess();
return false;
}

Expand All @@ -2060,6 +2071,8 @@ bool CallAnalyzer::visitStore(StoreInst &I) {
// 2. We should probably at some point thread MemorySSA for the callee into
// this and then use that to actually compute *really* precise savings.
disableLoadElimination();

onMemAccess();
return false;
}

Expand Down

0 comments on commit 8d2901d

Please sign in to comment.