Re: r364424 - [clang/DIVar] Emit the flag for params that have unmodified value

2019-07-11 Thread Djordje Todorovic via cfe-commits
Hi Vedant,

This looks good! Thanks!

Regards,
Djordje

On 11.7.19. 02:11, Vedant Kumar wrote:
> Hi Djordje,
> 
> Just a heads-up that I’ve landed r365716 to fix a crash in a stage2 build of 
> AppleClang with -femit-debug-entry-values enabled.
> 
> I went ahead and landed the fix as it seemed simple enough. Let me know if 
> you have any concerns.
> 
> Thanks,
> Vedant
> 
>> On Jun 26, 2019, at 6:32 AM, Djordje Todorovic via cfe-commits 
>>  wrote:
>>
>> Author: djtodoro
>> Date: Wed Jun 26 06:32:02 2019
>> New Revision: 364424
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=364424=rev
>> Log:
>> [clang/DIVar] Emit the flag for params that have unmodified value
>>
>> Emit the debug info flag that indicates that a parameter has unchanged
>> value throughout a function.
>>
>> ([5/13] Introduce the debug entry values.)
>>
>> Co-authored-by: Ananth Sowda 
>> Co-authored-by: Nikola Prica 
>> Co-authored-by: Ivan Baev 
>>
>> Differential Revision: https://reviews.llvm.org/D58035
>>
>> Added:
>>cfe/trunk/test/CodeGen/debug-info-param-modification.c
>> Modified:
>>cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>>cfe/trunk/lib/CodeGen/CGDebugInfo.h
>>
>> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=364424=364423=364424=diff
>> ==
>> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Jun 26 06:32:02 2019
>> @@ -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"
>> @@ -3588,6 +3589,12 @@ void CGDebugInfo::EmitFunctionStart(Glob
>>   if (HasDecl && isa(D))
>> DeclCache[D->getCanonicalDecl()].reset(SP);
>>
>> +  // We use the SPDefCache only in the case when the debug entry values 
>> option
>> +  // is set, in order to speed up parameters modification analysis.
>> +  if (CGM.getCodeGenOpts().EnableDebugEntryValues && HasDecl &&
>> +  isa(D))
>> +SPDefCache[cast(D)].reset(SP);
>> +
>>   if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
>> // Starting with DWARF V5 method declarations are emitted as children of
>> // the interface type.
>> @@ -3964,6 +3971,11 @@ llvm::DILocalVariable *CGDebugInfo::Emit
>>  llvm::DebugLoc::get(Line, Column, Scope, 
>> CurInlinedAt),
>>  Builder.GetInsertBlock());
>>
>> +  if (CGM.getCodeGenOpts().EnableDebugEntryValues && ArgNo) {
>> +if (auto *PD = dyn_cast(VD))
>> +  ParamCache[PD].reset(D);
>> +  }
>> +
>>   return D;
>> }
>>
>> @@ -4555,6 +4567,29 @@ void CGDebugInfo::setDwoId(uint64_t Sign
>>   TheCU->setDWOId(Signature);
>> }
>>
>> +/// Analyzes each function parameter to determine whether it is constant
>> +/// throughout the function body.
>> +static void analyzeParametersModification(
>> +ASTContext ,
>> +llvm::DenseMap ,
>> +llvm::DenseMap ) {
>> +  for (auto  : SPDefCache) {
>> +auto *FD = SP.first;
>> +assert(FD->hasBody() && "Functions must have body here");
>> +const Stmt *FuncBody = (*FD).getBody();
>> +for (auto Parm : FD->parameters()) {
>> +  ExprMutationAnalyzer FuncAnalyzer(*FuncBody, Ctx);
>> +  if (FuncAnalyzer.isMutated(Parm))
>> +continue;
>> +
>> +  auto I = ParamCache.find(Parm);
>> +  assert(I != ParamCache.end() && "Parameters should be already 
>> cached");
>> +  auto *DIParm = cast(I->second);
>> +  DIParm->setIsNotModified();
>> +}
>> +  }
>> +}
>> +
>> void CGDebugInfo::finalize() {
>>   // Creating types might create further types - invalidating the current
>>   // element and the size(), so don't cache/reference them.
>> @@ -4627,6 +4662,10 @@ void CGDebugInfo::finalize() {
>> if (auto MD = TypeCache[RT])
>>   DBuilder.retainType(cast(MD));
>>
>> +  if (CGM.getCodeGenOpts().EnableDebugEntryValues)
>> +// This will be used to emit debug entry values.
>> +analyzeParametersModification(CGM.getContext(), SPDefCache, ParamCache);
>> +
>>   DBuilder.finalize();
>> }
>>
>>
>> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=364424=364423=364424=diff
>> ==
>> --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
>> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Wed Jun 26 06:32:02 2019
>> @@ -134,6 +134,10 @@ class CGDebugInfo {
>>
>>   llvm::DenseMap DIFileCache;
>>   llvm::DenseMap SPCache;
>> +  /// Cache function definitions relevant to use for parameters mutation
>> +  /// analysis.
>> +  llvm::DenseMap SPDefCache;
>> +  llvm::DenseMap ParamCache;
>>   /// Cache declarations relevant to 

Re: r364424 - [clang/DIVar] Emit the flag for params that have unmodified value

2019-07-10 Thread Vedant Kumar via cfe-commits
Hi Djordje,

Just a heads-up that I’ve landed r365716 to fix a crash in a stage2 build of 
AppleClang with -femit-debug-entry-values enabled.

I went ahead and landed the fix as it seemed simple enough. Let me know if you 
have any concerns.

Thanks,
Vedant

> On Jun 26, 2019, at 6:32 AM, Djordje Todorovic via cfe-commits 
>  wrote:
> 
> Author: djtodoro
> Date: Wed Jun 26 06:32:02 2019
> New Revision: 364424
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=364424=rev
> Log:
> [clang/DIVar] Emit the flag for params that have unmodified value
> 
> Emit the debug info flag that indicates that a parameter has unchanged
> value throughout a function.
> 
> ([5/13] Introduce the debug entry values.)
> 
> Co-authored-by: Ananth Sowda 
> Co-authored-by: Nikola Prica 
> Co-authored-by: Ivan Baev 
> 
> Differential Revision: https://reviews.llvm.org/D58035
> 
> Added:
>cfe/trunk/test/CodeGen/debug-info-param-modification.c
> Modified:
>cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>cfe/trunk/lib/CodeGen/CGDebugInfo.h
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=364424=364423=364424=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Jun 26 06:32:02 2019
> @@ -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"
> @@ -3588,6 +3589,12 @@ void CGDebugInfo::EmitFunctionStart(Glob
>   if (HasDecl && isa(D))
> DeclCache[D->getCanonicalDecl()].reset(SP);
> 
> +  // We use the SPDefCache only in the case when the debug entry values 
> option
> +  // is set, in order to speed up parameters modification analysis.
> +  if (CGM.getCodeGenOpts().EnableDebugEntryValues && HasDecl &&
> +  isa(D))
> +SPDefCache[cast(D)].reset(SP);
> +
>   if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
> // Starting with DWARF V5 method declarations are emitted as children of
> // the interface type.
> @@ -3964,6 +3971,11 @@ llvm::DILocalVariable *CGDebugInfo::Emit
>  llvm::DebugLoc::get(Line, Column, Scope, 
> CurInlinedAt),
>  Builder.GetInsertBlock());
> 
> +  if (CGM.getCodeGenOpts().EnableDebugEntryValues && ArgNo) {
> +if (auto *PD = dyn_cast(VD))
> +  ParamCache[PD].reset(D);
> +  }
> +
>   return D;
> }
> 
> @@ -4555,6 +4567,29 @@ void CGDebugInfo::setDwoId(uint64_t Sign
>   TheCU->setDWOId(Signature);
> }
> 
> +/// Analyzes each function parameter to determine whether it is constant
> +/// throughout the function body.
> +static void analyzeParametersModification(
> +ASTContext ,
> +llvm::DenseMap ,
> +llvm::DenseMap ) {
> +  for (auto  : SPDefCache) {
> +auto *FD = SP.first;
> +assert(FD->hasBody() && "Functions must have body here");
> +const Stmt *FuncBody = (*FD).getBody();
> +for (auto Parm : FD->parameters()) {
> +  ExprMutationAnalyzer FuncAnalyzer(*FuncBody, Ctx);
> +  if (FuncAnalyzer.isMutated(Parm))
> +continue;
> +
> +  auto I = ParamCache.find(Parm);
> +  assert(I != ParamCache.end() && "Parameters should be already cached");
> +  auto *DIParm = cast(I->second);
> +  DIParm->setIsNotModified();
> +}
> +  }
> +}
> +
> void CGDebugInfo::finalize() {
>   // Creating types might create further types - invalidating the current
>   // element and the size(), so don't cache/reference them.
> @@ -4627,6 +4662,10 @@ void CGDebugInfo::finalize() {
> if (auto MD = TypeCache[RT])
>   DBuilder.retainType(cast(MD));
> 
> +  if (CGM.getCodeGenOpts().EnableDebugEntryValues)
> +// This will be used to emit debug entry values.
> +analyzeParametersModification(CGM.getContext(), SPDefCache, ParamCache);
> +
>   DBuilder.finalize();
> }
> 
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=364424=364423=364424=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Wed Jun 26 06:32:02 2019
> @@ -134,6 +134,10 @@ class CGDebugInfo {
> 
>   llvm::DenseMap DIFileCache;
>   llvm::DenseMap SPCache;
> +  /// Cache function definitions relevant to use for parameters mutation
> +  /// analysis.
> +  llvm::DenseMap SPDefCache;
> +  llvm::DenseMap ParamCache;
>   /// Cache declarations relevant to DW_TAG_imported_declarations (C++
>   /// using declarations) that aren't covered by other more specific caches.
>   llvm::DenseMap DeclCache;
> 
> Added: cfe/trunk/test/CodeGen/debug-info-param-modification.c
> URL: 
> 

r364424 - [clang/DIVar] Emit the flag for params that have unmodified value

2019-06-26 Thread Djordje Todorovic via cfe-commits
Author: djtodoro
Date: Wed Jun 26 06:32:02 2019
New Revision: 364424

URL: http://llvm.org/viewvc/llvm-project?rev=364424=rev
Log:
[clang/DIVar] Emit the flag for params that have unmodified value

Emit the debug info flag that indicates that a parameter has unchanged
value throughout a function.

([5/13] Introduce the debug entry values.)

Co-authored-by: Ananth Sowda 
Co-authored-by: Nikola Prica 
Co-authored-by: Ivan Baev 

Differential Revision: https://reviews.llvm.org/D58035

Added:
cfe/trunk/test/CodeGen/debug-info-param-modification.c
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=364424=364423=364424=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Jun 26 06:32:02 2019
@@ -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"
@@ -3588,6 +3589,12 @@ void CGDebugInfo::EmitFunctionStart(Glob
   if (HasDecl && isa(D))
 DeclCache[D->getCanonicalDecl()].reset(SP);
 
+  // We use the SPDefCache only in the case when the debug entry values option
+  // is set, in order to speed up parameters modification analysis.
+  if (CGM.getCodeGenOpts().EnableDebugEntryValues && HasDecl &&
+  isa(D))
+SPDefCache[cast(D)].reset(SP);
+
   if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
 // Starting with DWARF V5 method declarations are emitted as children of
 // the interface type.
@@ -3964,6 +3971,11 @@ llvm::DILocalVariable *CGDebugInfo::Emit
  llvm::DebugLoc::get(Line, Column, Scope, 
CurInlinedAt),
  Builder.GetInsertBlock());
 
+  if (CGM.getCodeGenOpts().EnableDebugEntryValues && ArgNo) {
+if (auto *PD = dyn_cast(VD))
+  ParamCache[PD].reset(D);
+  }
+
   return D;
 }
 
@@ -4555,6 +4567,29 @@ void CGDebugInfo::setDwoId(uint64_t Sign
   TheCU->setDWOId(Signature);
 }
 
+/// Analyzes each function parameter to determine whether it is constant
+/// throughout the function body.
+static void analyzeParametersModification(
+ASTContext ,
+llvm::DenseMap ,
+llvm::DenseMap ) {
+  for (auto  : SPDefCache) {
+auto *FD = SP.first;
+assert(FD->hasBody() && "Functions must have body here");
+const Stmt *FuncBody = (*FD).getBody();
+for (auto Parm : FD->parameters()) {
+  ExprMutationAnalyzer FuncAnalyzer(*FuncBody, Ctx);
+  if (FuncAnalyzer.isMutated(Parm))
+continue;
+
+  auto I = ParamCache.find(Parm);
+  assert(I != ParamCache.end() && "Parameters should be already cached");
+  auto *DIParm = cast(I->second);
+  DIParm->setIsNotModified();
+}
+  }
+}
+
 void CGDebugInfo::finalize() {
   // Creating types might create further types - invalidating the current
   // element and the size(), so don't cache/reference them.
@@ -4627,6 +4662,10 @@ void CGDebugInfo::finalize() {
 if (auto MD = TypeCache[RT])
   DBuilder.retainType(cast(MD));
 
+  if (CGM.getCodeGenOpts().EnableDebugEntryValues)
+// This will be used to emit debug entry values.
+analyzeParametersModification(CGM.getContext(), SPDefCache, ParamCache);
+
   DBuilder.finalize();
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=364424=364423=364424=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Wed Jun 26 06:32:02 2019
@@ -134,6 +134,10 @@ class CGDebugInfo {
 
   llvm::DenseMap DIFileCache;
   llvm::DenseMap SPCache;
+  /// Cache function definitions relevant to use for parameters mutation
+  /// analysis.
+  llvm::DenseMap SPDefCache;
+  llvm::DenseMap ParamCache;
   /// Cache declarations relevant to DW_TAG_imported_declarations (C++
   /// using declarations) that aren't covered by other more specific caches.
   llvm::DenseMap DeclCache;

Added: cfe/trunk/test/CodeGen/debug-info-param-modification.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-param-modification.c?rev=364424=auto
==
--- cfe/trunk/test/CodeGen/debug-info-param-modification.c (added)
+++ cfe/trunk/test/CodeGen/debug-info-param-modification.c Wed Jun 26 06:32:02 
2019
@@ -0,0 +1,12 @@
+// RUN: %clang -Xclang -femit-debug-entry-values -g -O2 -S -target 
x86_64-none-linux-gnu -emit-llvm %s -o - | FileCheck %s 
-check-prefix=CHECK-ENTRY-VAL-OPT
+// CHECK-ENTRY-VAL-OPT: !DILocalVariable(name: "a", arg: 1, scope: {{.*}},