diff options
author | Dehao Chen <dehao@google.com> | 2016-04-14 18:37:18 +0000 |
---|---|---|
committer | Dehao Chen <dehao@google.com> | 2016-04-14 18:37:18 +0000 |
commit | 46f8fbbb1b2ffc6b3b045c76a46a1ab8877e2cd6 (patch) | |
tree | 304095e1781afa55b806c08b48cc500ae26f6e70 /llvm/lib/Transforms/Utils/AddDiscriminators.cpp | |
parent | 9c4fb0a8331cae2d4e2e4beaa4e7af06062a6b58 (diff) | |
download | bcm5719-llvm-46f8fbbb1b2ffc6b3b045c76a46a1ab8877e2cd6.tar.gz bcm5719-llvm-46f8fbbb1b2ffc6b3b045c76a46a1ab8877e2cd6.zip |
Update discriminator assignment algorithm to handle nested call correctly.
Summary: Add discriminator for nested call correctly.
Reviewers: davidxl, dnovillo
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D19127
llvm-svn: 266354
Diffstat (limited to 'llvm/lib/Transforms/Utils/AddDiscriminators.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/AddDiscriminators.cpp | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/llvm/lib/Transforms/Utils/AddDiscriminators.cpp b/llvm/lib/Transforms/Utils/AddDiscriminators.cpp index 24d4c352153..94e9b236a2c 100644 --- a/llvm/lib/Transforms/Utils/AddDiscriminators.cpp +++ b/llvm/lib/Transforms/Utils/AddDiscriminators.cpp @@ -53,6 +53,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DIBuilder.h" @@ -169,6 +170,7 @@ bool AddDiscriminators::runOnFunction(Function &F) { typedef DenseMap<const BasicBlock *, Metadata *> BBScopeMap; typedef DenseMap<Location, BBScopeMap> LocationBBMap; typedef DenseMap<Location, unsigned> LocationDiscriminatorMap; + typedef DenseSet<Location> LocationSet; LocationBBMap LBM; LocationDiscriminatorMap LDM; @@ -213,32 +215,24 @@ bool AddDiscriminators::runOnFunction(Function &F) { // Sample base profile needs to distinguish different function calls within // a same source line for correct profile annotation. for (BasicBlock &B : F) { - const DILocation *FirstDIL = nullptr; + LocationSet CallLocations; for (auto &I : B.getInstList()) { CallInst *Current = dyn_cast<CallInst>(&I); if (!Current || isa<DbgInfoIntrinsic>(&I)) continue; DILocation *CurrentDIL = Current->getDebugLoc(); - if (FirstDIL) { - if (CurrentDIL && CurrentDIL->getLine() == FirstDIL->getLine() && - CurrentDIL->getFilename() == FirstDIL->getFilename()) { - auto *Scope = FirstDIL->getScope(); - auto *File = Builder.createFile(FirstDIL->getFilename(), - Scope->getDirectory()); - Location L = - std::make_pair(FirstDIL->getFilename(), FirstDIL->getLine()); - auto *NewScope = - Builder.createLexicalBlockFile(Scope, File, ++LDM[L]); - Current->setDebugLoc(DILocation::get( - Ctx, CurrentDIL->getLine(), CurrentDIL->getColumn(), NewScope, - CurrentDIL->getInlinedAt())); - Changed = true; - } else { - FirstDIL = CurrentDIL; - } - } else { - FirstDIL = CurrentDIL; + Location L = + std::make_pair(CurrentDIL->getFilename(), CurrentDIL->getLine()); + if (!CallLocations.insert(L).second) { + auto *Scope = CurrentDIL->getScope(); + auto *File = Builder.createFile(CurrentDIL->getFilename(), + Scope->getDirectory()); + auto *NewScope = Builder.createLexicalBlockFile(Scope, File, ++LDM[L]); + Current->setDebugLoc(DILocation::get(Ctx, CurrentDIL->getLine(), + CurrentDIL->getColumn(), NewScope, + CurrentDIL->getInlinedAt())); + Changed = true; } } } |