[llvm] r285207 - Introduce updateDiscriminator interface to DILocation to make it cleaner assigning discriminators.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 26 08:48:45 PDT 2016
Author: dehao
Date: Wed Oct 26 10:48:45 2016
New Revision: 285207
URL: http://llvm.org/viewvc/llvm-project?rev=285207&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/Transforms/Utils/AddDiscriminators.cpp
llvm/trunk/test/Transforms/AddDiscriminators/inlined.ll
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=285207&r1=285206&r2=285207&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Wed Oct 26 10:48:45 2016
@@ -1270,6 +1270,9 @@ public:
/// instructions that are on different basic blocks.
inline unsigned getDiscriminator() const;
+ /// Returns a new DILocation with updated \p Discriminator.
+ inline DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
+
Metadata *getRawScope() const { return getOperand(0); }
Metadata *getRawInlinedAt() const {
if (getNumOperands() == 2)
@@ -1612,6 +1615,22 @@ unsigned DILocation::getDiscriminator()
return 0;
}
+DILocation *DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
+ DIScope *Scope = getScope();
+ // Skip all parent DILexicalBlockFile that already have a discriminator
+ // assigned. We do not want to have nested DILexicalBlockFiles that have
+ // mutliple discriminators because only the leaf DILexicalBlockFile's
+ // dominator will be used.
+ for (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope);
+ LBF && LBF->getDiscriminator() != 0;
+ LBF = dyn_cast<DILexicalBlockFile>(Scope))
+ Scope = LBF->getScope();
+ DILexicalBlockFile *NewScope =
+ DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
+ return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
+ getInlinedAt());
+}
+
class DINamespace : public DIScope {
friend class LLVMContextImpl;
friend class MDNode;
Modified: llvm/trunk/lib/Transforms/Utils/AddDiscriminators.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/AddDiscriminators.cpp?rev=285207&r1=285206&r2=285207&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/AddDiscriminators.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/AddDiscriminators.cpp Wed Oct 26 10:48:45 2016
@@ -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 &
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 &
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 &
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;
}
}
Modified: llvm/trunk/test/Transforms/AddDiscriminators/inlined.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/AddDiscriminators/inlined.ll?rev=285207&r1=285206&r2=285207&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/AddDiscriminators/inlined.ll (original)
+++ llvm/trunk/test/Transforms/AddDiscriminators/inlined.ll Wed Oct 26 10:48:45 2016
@@ -75,9 +75,7 @@ attributes #3 = { nounwind readnone }
!17 = distinct !DILexicalBlock(scope: !7, file: !1, line: 1, column: 9)
!18 = !DILocation(line: 1, column: 9, scope: !7)
!19 = !DILocation(line: 1, column: 27, scope: !12, inlinedAt: !13)
-; CHECK: ![[BR]] = !DILocation(line: 1, column: 9, scope: ![[BF2:[0-9]+]])
-; CHECK: ![[BF2]] = !DILexicalBlockFile(scope: ![[BF]],
-; CHECK-SAME: discriminator: 1)
+; CHECK: ![[BR]] = !DILocation(line: 1, column: 9, scope: !14)
!20 = !DILocation(line: 1, column: 9, scope: !14)
!21 = distinct !{!21, !18}
!22 = !DILocation(line: 1, column: 56, scope: !12)
More information about the llvm-commits
mailing list