[PATCH] D58035: [clang/DIVar] Emit flag for params that have unchanged values

Djordje Todorovic via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 16 05:49:16 PDT 2019


djtodoro updated this revision to Diff 195359.
djtodoro added a comment.

-Run clang-format
-Use `cast` instead of '`dyn_cast`'


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

https://reviews.llvm.org/D58035

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h


Index: lib/CodeGen/CGDebugInfo.h
===================================================================
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -133,6 +133,7 @@
 
   llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
   llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
+  llvm::DenseMap<const ParmVarDecl *, llvm::TrackingMDRef> ParmCache;
   /// Cache declarations relevant to DW_TAG_imported_declarations (C++
   /// using declarations) that aren't covered by other more specific caches.
   llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -18,6 +18,7 @@
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "ConstantEmitter.h"
+#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclObjC.h"
@@ -3880,6 +3881,11 @@
                          llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
                          Builder.GetInsertBlock());
 
+  if (ArgNo) {
+    auto *PD = dyn_cast<ParmVarDecl>(VD);
+    ParmCache[PD].reset(D);
+  }
+
   return D;
 }
 
@@ -4526,6 +4532,25 @@
     if (auto MD = TypeCache[RT])
       DBuilder.retainType(cast<llvm::DIType>(MD));
 
+  if (CGM.getCodeGenOpts().EnableParamEntryValues &&
+      CGM.getLangOpts().Optimize) {
+    for (auto &SP : DeclCache) {
+      auto *D = SP.first;
+      if (const auto *FD = dyn_cast_or_null<FunctionDecl>(D)) {
+        const Stmt *FuncBody = (*FD).getBody();
+        for (auto Parm : FD->parameters()) {
+          ExprMutationAnalyzer FuncAnalyzer(*FuncBody, CGM.getContext());
+          if (!FuncAnalyzer.isMutated(Parm)) {
+            auto I = ParmCache.find(Parm);
+            if (I != ParmCache.end()) {
+              auto *DIParm = cast<llvm::DILocalVariable>(I->second);
+              DIParm->setIsNotModified();
+            }
+          }
+        }
+      }
+    }
+  }
   DBuilder.finalize();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58035.195359.patch
Type: text/x-patch
Size: 2145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190416/727eafba/attachment.bin>


More information about the cfe-commits mailing list