diff options
author | Djordje Todorovic <djordje.todorovic@rt-rk.com> | 2019-06-26 13:32:02 +0000 |
---|---|---|
committer | Djordje Todorovic <djordje.todorovic@rt-rk.com> | 2019-06-26 13:32:02 +0000 |
commit | ed05d49aadc9441ad8afe13e6e164fbffe099929 (patch) | |
tree | f016b29502aa299fbc1c2d3aef8c9d8f62f17b1b /clang/lib/CodeGen/CGDebugInfo.cpp | |
parent | 1006a068c63f9df215a29e3185b4c1a0e4a0f83a (diff) | |
download | bcm5719-llvm-ed05d49aadc9441ad8afe13e6e164fbffe099929.tar.gz bcm5719-llvm-ed05d49aadc9441ad8afe13e6e164fbffe099929.zip |
[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 <asowda@cisco.com>
Co-authored-by: Nikola Prica <nikola.prica@rt-rk.com>
Co-authored-by: Ivan Baev <ibaev@cisco.com>
Differential Revision: https://reviews.llvm.org/D58035
llvm-svn: 364424
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index fce0902f34d..e8a6762d2b8 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/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" @@ -3588,6 +3589,12 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, if (HasDecl && isa<FunctionDecl>(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<FunctionDecl>(D)) + SPDefCache[cast<FunctionDecl>(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::EmitDeclare(const VarDecl *VD, 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; } @@ -4555,6 +4567,29 @@ void CGDebugInfo::setDwoId(uint64_t Signature) { TheCU->setDWOId(Signature); } +/// Analyzes each function parameter to determine whether it is constant +/// throughout the function body. +static void analyzeParametersModification( + ASTContext &Ctx, + llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> &SPDefCache, + llvm::DenseMap<const ParmVarDecl *, llvm::TrackingMDRef> &ParamCache) { + for (auto &SP : 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<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. @@ -4627,6 +4662,10 @@ void CGDebugInfo::finalize() { 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(), SPDefCache, ParamCache); + DBuilder.finalize(); } |