[PATCH] D83458: [StackSafety,NFC] Reduce FunctionSummary size

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 00:46:54 PDT 2020


vitalybuka created this revision.
vitalybuka added a reviewer: tejohnson.
Herald added subscribers: llvm-commits, arphaman.
Herald added a project: LLVM.

Most compiler infocations will not need ParamAccess,
so we can optimize memory usage there with smaller unique_ptr
instead of empty vector.
Suggested in D80908 <https://reviews.llvm.org/D80908> review.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83458

Files:
  llvm/include/llvm/IR/ModuleSummaryIndex.h


Index: llvm/include/llvm/IR/ModuleSummaryIndex.h
===================================================================
--- llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -629,7 +629,8 @@
   std::unique_ptr<TypeIdInfo> TIdInfo;
 
   /// Uses for every parameter to this function.
-  std::vector<ParamAccess> ParamAccesses;
+  using ParamAccessesTy = std::vector<ParamAccess>;
+  std::unique_ptr<ParamAccessesTy> ParamAccesses;
 
 public:
   FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags,
@@ -640,19 +641,20 @@
                   std::vector<VFuncId> TypeCheckedLoadVCalls,
                   std::vector<ConstVCall> TypeTestAssumeConstVCalls,
                   std::vector<ConstVCall> TypeCheckedLoadConstVCalls,
-                  std::vector<ParamAccess> ParamAccesses)
+                  std::vector<ParamAccess> Params)
       : GlobalValueSummary(FunctionKind, Flags, std::move(Refs)),
         InstCount(NumInsts), FunFlags(FunFlags), EntryCount(EntryCount),
-        CallGraphEdgeList(std::move(CGEdges)),
-        ParamAccesses(std::move(ParamAccesses)) {
+        CallGraphEdgeList(std::move(CGEdges)) {
     if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
         !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
         !TypeCheckedLoadConstVCalls.empty())
-      TIdInfo = std::make_unique<TypeIdInfo>(TypeIdInfo{
-          std::move(TypeTests), std::move(TypeTestAssumeVCalls),
-          std::move(TypeCheckedLoadVCalls),
-          std::move(TypeTestAssumeConstVCalls),
-          std::move(TypeCheckedLoadConstVCalls)});
+      TIdInfo = std::make_unique<TypeIdInfo>(
+          TypeIdInfo{std::move(TypeTests), std::move(TypeTestAssumeVCalls),
+                     std::move(TypeCheckedLoadVCalls),
+                     std::move(TypeTestAssumeConstVCalls),
+                     std::move(TypeCheckedLoadConstVCalls)});
+    if (!Params.empty())
+      ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(Params));
   }
   // Gets the number of readonly and writeonly refs in RefEdgeList
   std::pair<unsigned, unsigned> specialRefCounts() const;
@@ -724,11 +726,20 @@
   }
 
   /// Returns the list of known uses of pointer parameters.
-  ArrayRef<ParamAccess> paramAccesses() const { return ParamAccesses; }
+  ArrayRef<ParamAccess> paramAccesses() const {
+    if (ParamAccesses)
+      return *ParamAccesses;
+    return {};
+  }
 
   /// Sets the list of known uses of pointer parameters.
   void setParamAccesses(std::vector<ParamAccess> NewParams) {
-    ParamAccesses = std::move(NewParams);
+    if (NewParams.empty())
+      ParamAccesses.reset();
+    else if (ParamAccesses)
+      *ParamAccesses = std::move(NewParams);
+    else
+      ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(NewParams));
   }
 
   /// Add a type test to the summary. This is used by WholeProgramDevirt if we


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83458.276648.patch
Type: text/x-patch
Size: 2937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200709/aee7190d/attachment.bin>


More information about the llvm-commits mailing list