[llvm] 8d2901d - [NFC][Inliner] Add Load/Store handler

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 13:42:33 PDT 2022


Author: Vitaly Buka
Date: 2022-08-05T13:42:17-07:00
New Revision: 8d2901d53708b72ae3cb56ac78d3cd0e591db669

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

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

Added: 
    

Modified: 
    llvm/lib/Analysis/InlineCost.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 4f7b342d9f1ac..ebb1f20641bd0 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -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"));
@@ -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() {}
@@ -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.
@@ -2044,6 +2054,7 @@ bool CallAnalyzer::visitLoad(LoadInst &I) {
     return true;
   }
 
+  onMemAccess();
   return false;
 }
 
@@ -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;
 }
 


        


More information about the llvm-commits mailing list