summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/AddDiscriminators.cpp
diff options
context:
space:
mode:
authorDehao Chen <dehao@google.com>2016-10-26 15:48:45 +0000
committerDehao Chen <dehao@google.com>2016-10-26 15:48:45 +0000
commite713000eb62aba018d67293814a86cf5375a8314 (patch)
treebf05896ca3a87b896f4daec62f8677ca6764961d /llvm/lib/Transforms/Utils/AddDiscriminators.cpp
parent7e0f03ecf2e3ebc3f68a9189bce0f6fba01a8772 (diff)
downloadbcm5719-llvm-e713000eb62aba018d67293814a86cf5375a8314.tar.gz
bcm5719-llvm-e713000eb62aba018d67293814a86cf5375a8314.zip
Introduce updateDiscriminator interface to DILocation to make it cleaner assigning discriminators.
Summary: This patch introduces updateDiscriminator to DILocation so that it can be directly called by AddDiscriminator. It also makes it easier to update the discriminator later. Reviewers: dnovillo, dblaikie, aprantl, echristo Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D25959 llvm-svn: 285207
Diffstat (limited to 'llvm/lib/Transforms/Utils/AddDiscriminators.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/AddDiscriminators.cpp37
1 files changed, 7 insertions, 30 deletions
diff --git a/llvm/lib/Transforms/Utils/AddDiscriminators.cpp b/llvm/lib/Transforms/Utils/AddDiscriminators.cpp
index 8120fa93113..66781ca76b4 100644
--- a/llvm/lib/Transforms/Utils/AddDiscriminators.cpp
+++ b/llvm/lib/Transforms/Utils/AddDiscriminators.cpp
@@ -57,12 +57,10 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
-#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
@@ -163,14 +161,10 @@ static bool addDiscriminators(Function &F) {
return false;
bool Changed = false;
- Module *M = F.getParent();
- LLVMContext &Ctx = M->getContext();
- DIBuilder Builder(*M, /*AllowUnresolved*/ false);
typedef std::pair<StringRef, unsigned> Location;
- typedef SmallDenseMap<DIScope *, DILexicalBlockFile *, 1> ScopeMap;
- typedef DenseMap<const BasicBlock *, ScopeMap> BBScopeMap;
- typedef DenseMap<Location, BBScopeMap> LocationBBMap;
+ typedef DenseSet<const BasicBlock *> BBSet;
+ typedef DenseMap<Location, BBSet> LocationBBMap;
typedef DenseMap<Location, unsigned> LocationDiscriminatorMap;
typedef DenseSet<Location> LocationSet;
@@ -187,29 +181,18 @@ static bool addDiscriminators(Function &F) {
const DILocation *DIL = I.getDebugLoc();
if (!DIL)
continue;
- DIScope *Scope = DIL->getScope();
Location L = std::make_pair(DIL->getFilename(), DIL->getLine());
auto &BBMap = LBM[L];
- auto R = BBMap.insert({&B, ScopeMap()});
+ auto R = BBMap.insert(&B);
if (BBMap.size() == 1)
continue;
- bool InsertSuccess = R.second;
- ScopeMap &Scopes = R.first->second;
// If we could insert more than one block with the same line+file, a
// discriminator is needed to distinguish both instructions.
- auto R1 = Scopes.insert({Scope, nullptr});
- DILexicalBlockFile *&NewScope = R1.first->second;
- if (!NewScope) {
- unsigned Discriminator = InsertSuccess ? ++LDM[L] : LDM[L];
- auto *File = Builder.createFile(DIL->getFilename(),
- Scope->getDirectory());
- NewScope = Builder.createLexicalBlockFile(Scope, File, Discriminator);
- }
- I.setDebugLoc(DILocation::get(Ctx, DIL->getLine(), DIL->getColumn(),
- NewScope, DIL->getInlinedAt()));
+ unsigned Discriminator = R.second ? ++LDM[L] : LDM[L];
+ I.setDebugLoc(DIL->cloneWithDiscriminator(Discriminator));
DEBUG(dbgs() << DIL->getFilename() << ":" << DIL->getLine() << ":"
<< DIL->getColumn() << ":"
- << dyn_cast<DILexicalBlockFile>(NewScope)->getDiscriminator()
+ << Discriminator << " "
<< I << "\n");
Changed = true;
}
@@ -232,13 +215,7 @@ static bool addDiscriminators(Function &F) {
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()));
+ Current->setDebugLoc(CurrentDIL->cloneWithDiscriminator(++LDM[L]));
Changed = true;
}
}
OpenPOWER on IntegriCloud