[PATCH] D78734: [CaptureTracking] Make MaxUsesToExplore cheaper (NFC)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 11:21:42 PDT 2020


nikic created this revision.
nikic added reviewers: skatkov, jdoerfert.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.

The change in D78624 <https://reviews.llvm.org/D78624> had a noticeable negative compile-time impact <http://llvm-compile-time-tracker.com/compare.php?from=9245c7ac13480ed48ae339ad0e68cbe680cd0642&to=c0d2bbb1d4939908545071831568b1e0b1b82860&stat=instructions>. It seems that going through a function call for the `MaxUsesToExplore` default is fairly expensive, at least if LLVM is not built with LTO.

This patch makes `MaxUsesToExpore` default to 0 and assigns the actual default in the implementation instead. This recovers <http://llvm-compile-time-tracker.com/compare.php?from=367229e100eca714276253bf95a0dd3d084a9624&to=191f8bd8e24d8371da06d3d7786c57bcd9274b52&stat=instructions> most of the regression.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78734

Files:
  include/llvm/Analysis/CaptureTracking.h
  lib/Analysis/CaptureTracking.cpp


Index: lib/Analysis/CaptureTracking.cpp
===================================================================
--- lib/Analysis/CaptureTracking.cpp
+++ lib/Analysis/CaptureTracking.cpp
@@ -230,6 +230,9 @@
 void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
                                 unsigned MaxUsesToExplore) {
   assert(V->getType()->isPointerTy() && "Capture is for pointers only!");
+  if (MaxUsesToExplore == 0)
+    MaxUsesToExplore = DefaultMaxUsesToExplore;
+
   SmallVector<const Use *, 20> Worklist;
   Worklist.reserve(getDefaultMaxUsesToExploreForCaptureTracking());
   SmallSet<const Use *, 20> Visited;
Index: include/llvm/Analysis/CaptureTracking.h
===================================================================
--- include/llvm/Analysis/CaptureTracking.h
+++ include/llvm/Analysis/CaptureTracking.h
@@ -37,8 +37,7 @@
   /// one value before giving up due too "too many uses".
   bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures,
                             bool StoreCaptures,
-                            unsigned MaxUsesToExplore =
-                                getDefaultMaxUsesToExploreForCaptureTracking());
+                            unsigned MaxUsesToExplore = 0);
 
   /// PointerMayBeCapturedBefore - Return true if this pointer value may be
   /// captured by the enclosing function (which is required to exist). If a
@@ -55,8 +54,7 @@
   bool PointerMayBeCapturedBefore(
       const Value *V, bool ReturnCaptures, bool StoreCaptures,
       const Instruction *I, const DominatorTree *DT, bool IncludeI = false,
-      unsigned MaxUsesToExplore =
-          getDefaultMaxUsesToExploreForCaptureTracking());
+      unsigned MaxUsesToExplore = 0);
 
   /// This callback is used in conjunction with PointerMayBeCaptured. In
   /// addition to the interface here, you'll need to provide your own getters
@@ -92,8 +90,7 @@
   /// MaxUsesToExplore specifies how many uses should the analysis explore for
   /// one value before giving up due too "too many uses".
   void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
-                            unsigned MaxUsesToExplore =
-                                getDefaultMaxUsesToExploreForCaptureTracking());
+                            unsigned MaxUsesToExplore = 0);
 } // end namespace llvm
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78734.259634.patch
Type: text/x-patch
Size: 2340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200423/b53a4b13/attachment.bin>


More information about the llvm-commits mailing list