[PATCH] D80957: [LiveDebugValues] Cache LexicalScopes::getMachineBasicBlocks, NFCI

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 2 09:52:46 PDT 2020


vsk updated this revision to Diff 267910.
vsk added a comment.

Move the caching into LexicalScopes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80957/new/

https://reviews.llvm.org/D80957

Files:
  llvm/include/llvm/CodeGen/LexicalScopes.h
  llvm/lib/CodeGen/LexicalScopes.cpp
  llvm/lib/CodeGen/LiveDebugValues.cpp


Index: llvm/lib/CodeGen/LiveDebugValues.cpp
===================================================================
--- llvm/lib/CodeGen/LiveDebugValues.cpp
+++ llvm/lib/CodeGen/LiveDebugValues.cpp
@@ -203,20 +203,15 @@
   /// Keeps track of lexical scopes associated with a user value's source
   /// location.
   class UserValueScopes {
-    DebugLoc DL;
+    const DebugLoc &DL;
     LexicalScopes &LS;
-    SmallPtrSet<const MachineBasicBlock *, 4> LBlocks;
 
   public:
-    UserValueScopes(DebugLoc D, LexicalScopes &L) : DL(std::move(D)), LS(L) {}
+    UserValueScopes(const DebugLoc &D, LexicalScopes &L) : DL(D), LS(L) {}
 
     /// Return true if current scope dominates at least one machine
     /// instruction in a given machine basic block.
-    bool dominates(MachineBasicBlock *MBB) {
-      if (LBlocks.empty())
-        LS.getMachineBasicBlocks(DL, LBlocks);
-      return LBlocks.count(MBB) != 0 || LS.dominates(DL, MBB);
-    }
+    bool dominates(MachineBasicBlock *MBB) { return LS.dominates(DL, MBB); }
   };
 
   using FragmentInfo = DIExpression::FragmentInfo;
Index: llvm/lib/CodeGen/LexicalScopes.cpp
===================================================================
--- llvm/lib/CodeGen/LexicalScopes.cpp
+++ llvm/lib/CodeGen/LexicalScopes.cpp
@@ -44,6 +44,7 @@
   AbstractScopeMap.clear();
   InlinedLexicalScopeMap.clear();
   AbstractScopesList.clear();
+  DominatedBlocks.clear();
 }
 
 /// initialize - Scan machine function and constuct lexical scope nest.
@@ -302,8 +303,6 @@
       MBBs.insert(&*CurMBBIt);
 }
 
-/// dominates - Return true if DebugLoc's lexical scope dominates at least one
-/// machine instruction's lexical scope in a given machine basic block.
 bool LexicalScopes::dominates(const DILocation *DL, MachineBasicBlock *MBB) {
   assert(MF && "Unexpected uninitialized LexicalScopes object!");
   LexicalScope *Scope = getOrCreateLexicalScope(DL);
@@ -315,11 +314,17 @@
     return true;
 
   // Fetch all the blocks in DLs scope. Because the range / block list also
-  // contain any subscopes, any instruction that DL dominates can be found
-  // in the block set.
-  SmallPtrSet<const MachineBasicBlock *, 32> Set;
-  getMachineBasicBlocks(DL, Set);
-  return Set.count(MBB) != 0;
+  // contain any subscopes, any instruction that DL dominates can be found in
+  // the block set.
+  //
+  // Cache the set of fetched blocks to avoid repeatedly recomputing the set in
+  // the LiveDebugValues pass.
+  std::unique_ptr<BlockSetT> &Set = DominatedBlocks[DL];
+  if (!Set) {
+    Set = std::make_unique<BlockSetT>();
+    getMachineBasicBlocks(DL, *Set);
+  }
+  return Set->count(MBB) != 0;
 }
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Index: llvm/include/llvm/CodeGen/LexicalScopes.h
===================================================================
--- llvm/include/llvm/CodeGen/LexicalScopes.h
+++ llvm/include/llvm/CodeGen/LexicalScopes.h
@@ -163,8 +163,8 @@
   void getMachineBasicBlocks(const DILocation *DL,
                              SmallPtrSetImpl<const MachineBasicBlock *> &MBBs);
 
-  /// dominates - Return true if DebugLoc's lexical scope dominates at least one
-  /// machine instruction's lexical scope in a given machine basic block.
+  /// Return true if DebugLoc's lexical scope dominates at least one machine
+  /// instruction's lexical scope in a given machine basic block.
   bool dominates(const DILocation *DL, MachineBasicBlock *MBB);
 
   /// findLexicalScope - Find lexical scope, either regular or inlined, for the
@@ -250,6 +250,11 @@
   /// CurrentFnLexicalScope - Top level scope for the current function.
   ///
   LexicalScope *CurrentFnLexicalScope = nullptr;
+
+  /// Map a location to the set of basic blocks it dominates. This is a cache
+  /// for \ref LexicalScopes::getMachineBasicBlocks results.
+  using BlockSetT = SmallPtrSet<const MachineBasicBlock *, 4>;
+  DenseMap<const DILocation *, std::unique_ptr<BlockSetT>> DominatedBlocks;
 };
 
 } // end namespace llvm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80957.267910.patch
Type: text/x-patch
Size: 3980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200602/2021ece2/attachment.bin>


More information about the llvm-commits mailing list