djtodoro updated this revision to Diff 200486. djtodoro added a comment. -Use `SPCache` instead of `DeclCache` -Refactor the code by addressing suggestions
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> ParamCache; /// 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" @@ -3515,6 +3516,12 @@ if (HasDecl && isa<FunctionDecl>(D)) DeclCache[D->getCanonicalDecl()].reset(SP); + // We use the SPCache 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<FunctionDecl>(D)) + SPCache[cast<FunctionDecl>(D)->getCanonicalDecl()].reset(SP); + if (CGM.getCodeGenOpts().DwarfVersion >= 5) { // Starting with DWARF V5 method declarations are emitted as children of // the interface type. @@ -3880,6 +3887,11 @@ llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt), Builder.GetInsertBlock()); + if (CGM.getCodeGenOpts().EnableDebugEntryValues && ArgNo) { + if (auto *PD = dyn_cast<ParmVarDecl>(VD)) + ParamCache[PD].reset(D); + } + return D; } @@ -4454,6 +4466,26 @@ TheCU->setDWOId(Signature); } +static void analyzeParametersModification( + ASTContext &Ctx, + llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> &SPCache, + llvm::DenseMap<const ParmVarDecl *, llvm::TrackingMDRef> &ParamCache) { + for (auto &SP : SPCache) { + auto *FD = SP.first; + const Stmt *FuncBody = (*FD).getBody(); + for (auto Parm : FD->parameters()) { + ExprMutationAnalyzer FuncAnalyzer(*FuncBody, Ctx); + if (!FuncAnalyzer.isMutated(Parm)) { + auto I = ParamCache.find(Parm); + if (I != ParamCache.end()) { + auto *DIParm = cast<llvm::DILocalVariable>(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. @@ -4526,6 +4558,10 @@ if (auto MD = TypeCache[RT]) DBuilder.retainType(cast<llvm::DIType>(MD)); + if (CGM.getCodeGenOpts().EnableDebugEntryValues) + // This will be used to emit debug entry values. + analyzeParametersModification(CGM.getContext(), SPCache, ParamCache); + DBuilder.finalize(); }
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> ParamCache; /// 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" @@ -3515,6 +3516,12 @@ if (HasDecl && isa<FunctionDecl>(D)) DeclCache[D->getCanonicalDecl()].reset(SP); + // We use the SPCache 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<FunctionDecl>(D)) + SPCache[cast<FunctionDecl>(D)->getCanonicalDecl()].reset(SP); + if (CGM.getCodeGenOpts().DwarfVersion >= 5) { // Starting with DWARF V5 method declarations are emitted as children of // the interface type. @@ -3880,6 +3887,11 @@ llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt), Builder.GetInsertBlock()); + if (CGM.getCodeGenOpts().EnableDebugEntryValues && ArgNo) { + if (auto *PD = dyn_cast<ParmVarDecl>(VD)) + ParamCache[PD].reset(D); + } + return D; } @@ -4454,6 +4466,26 @@ TheCU->setDWOId(Signature); } +static void analyzeParametersModification( + ASTContext &Ctx, + llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> &SPCache, + llvm::DenseMap<const ParmVarDecl *, llvm::TrackingMDRef> &ParamCache) { + for (auto &SP : SPCache) { + auto *FD = SP.first; + const Stmt *FuncBody = (*FD).getBody(); + for (auto Parm : FD->parameters()) { + ExprMutationAnalyzer FuncAnalyzer(*FuncBody, Ctx); + if (!FuncAnalyzer.isMutated(Parm)) { + auto I = ParamCache.find(Parm); + if (I != ParamCache.end()) { + auto *DIParm = cast<llvm::DILocalVariable>(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. @@ -4526,6 +4558,10 @@ if (auto MD = TypeCache[RT]) DBuilder.retainType(cast<llvm::DIType>(MD)); + if (CGM.getCodeGenOpts().EnableDebugEntryValues) + // This will be used to emit debug entry values. + analyzeParametersModification(CGM.getContext(), SPCache, ParamCache); + DBuilder.finalize(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits