llvm.org GIT mirror llvm / 98ab42a
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285207 91177308-0d34-0410-b5e6-96231b3b80d8 Dehao Chen 2 years ago
3 changed file(s) with 27 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
12691269 /// instructions that are on different basic blocks.
12701270 inline unsigned getDiscriminator() const;
12711271
1272 /// Returns a new DILocation with updated \p Discriminator.
1273 inline DILocation *cloneWithDiscriminator(unsigned Discriminator) const;
1274
12721275 Metadata *getRawScope() const { return getOperand(0); }
12731276 Metadata *getRawInlinedAt() const {
12741277 if (getNumOperands() == 2)
16111614 return 0;
16121615 }
16131616
1617 DILocation *DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
1618 DIScope *Scope = getScope();
1619 // Skip all parent DILexicalBlockFile that already have a discriminator
1620 // assigned. We do not want to have nested DILexicalBlockFiles that have
1621 // mutliple discriminators because only the leaf DILexicalBlockFile's
1622 // dominator will be used.
1623 for (auto *LBF = dyn_cast(Scope);
1624 LBF && LBF->getDiscriminator() != 0;
1625 LBF = dyn_cast(Scope))
1626 Scope = LBF->getScope();
1627 DILexicalBlockFile *NewScope =
1628 DILexicalBlockFile::get(getContext(), Scope, getFile(), Discriminator);
1629 return DILocation::get(getContext(), getLine(), getColumn(), NewScope,
1630 getInlinedAt());
1631 }
1632
16141633 class DINamespace : public DIScope {
16151634 friend class LLVMContextImpl;
16161635 friend class MDNode;
5656 #include "llvm/ADT/DenseSet.h"
5757 #include "llvm/IR/BasicBlock.h"
5858 #include "llvm/IR/Constants.h"
59 #include "llvm/IR/DIBuilder.h"
6059 #include "llvm/IR/DebugInfo.h"
6160 #include "llvm/IR/Instructions.h"
6261 #include "llvm/IR/IntrinsicInst.h"
6362 #include "llvm/IR/LLVMContext.h"
64 #include "llvm/IR/Module.h"
6563 #include "llvm/Pass.h"
6664 #include "llvm/Support/CommandLine.h"
6765 #include "llvm/Support/Debug.h"
162160 return false;
163161
164162 bool Changed = false;
165 Module *M = F.getParent();
166 LLVMContext &Ctx = M->getContext();
167 DIBuilder Builder(*M, /*AllowUnresolved*/ false);
168163
169164 typedef std::pair Location;
170 typedef SmallDenseMap ScopeMap;
171 typedef DenseMap BBScopeMap;
172 typedef DenseMap LocationBBMap;
165 typedef DenseSet BBSet;
166 typedef DenseMap LocationBBMap;
173167 typedef DenseMap LocationDiscriminatorMap;
174168 typedef DenseSet LocationSet;
175169
186180 const DILocation *DIL = I.getDebugLoc();
187181 if (!DIL)
188182 continue;
189 DIScope *Scope = DIL->getScope();
190183 Location L = std::make_pair(DIL->getFilename(), DIL->getLine());
191184 auto &BBMap = LBM[L];
192 auto R = BBMap.insert({&B, ScopeMap()});
185 auto R = BBMap.insert(&B);
193186 if (BBMap.size() == 1)
194187 continue;
195 bool InsertSuccess = R.second;
196 ScopeMap &Scopes = R.first->second;
197188 // If we could insert more than one block with the same line+file, a
198189 // discriminator is needed to distinguish both instructions.
199 auto R1 = Scopes.insert({Scope, nullptr});
200 DILexicalBlockFile *&NewScope = R1.first->second;
201 if (!NewScope) {
202 unsigned Discriminator = InsertSuccess ? ++LDM[L] : LDM[L];
203 auto *File = Builder.createFile(DIL->getFilename(),
204 Scope->getDirectory());
205 NewScope = Builder.createLexicalBlockFile(Scope, File, Discriminator);
206 }
207 I.setDebugLoc(DILocation::get(Ctx, DIL->getLine(), DIL->getColumn(),
208 NewScope, DIL->getInlinedAt()));
190 unsigned Discriminator = R.second ? ++LDM[L] : LDM[L];
191 I.setDebugLoc(DIL->cloneWithDiscriminator(Discriminator));
209192 DEBUG(dbgs() << DIL->getFilename() << ":" << DIL->getLine() << ":"
210193 << DIL->getColumn() << ":"
211 << dyn_cast(NewScope)->getDiscriminator()
194 << Discriminator << " "
212195 << I << "\n");
213196 Changed = true;
214197 }
231214 Location L =
232215 std::make_pair(CurrentDIL->getFilename(), CurrentDIL->getLine());
233216 if (!CallLocations.insert(L).second) {
234 auto *Scope = CurrentDIL->getScope();
235 auto *File = Builder.createFile(CurrentDIL->getFilename(),
236 Scope->getDirectory());
237 auto *NewScope = Builder.createLexicalBlockFile(Scope, File, ++LDM[L]);
238 Current->setDebugLoc(DILocation::get(Ctx, CurrentDIL->getLine(),
239 CurrentDIL->getColumn(), NewScope,
240 CurrentDIL->getInlinedAt()));
217 Current->setDebugLoc(CurrentDIL->cloneWithDiscriminator(++LDM[L]));
241218 Changed = true;
242219 }
243220 }
7474 !17 = distinct !DILexicalBlock(scope: !7, file: !1, line: 1, column: 9)
7575 !18 = !DILocation(line: 1, column: 9, scope: !7)
7676 !19 = !DILocation(line: 1, column: 27, scope: !12, inlinedAt: !13)
77 ; CHECK: ![[BR]] = !DILocation(line: 1, column: 9, scope: ![[BF2:[0-9]+]])
78 ; CHECK: ![[BF2]] = !DILexicalBlockFile(scope: ![[BF]],
79 ; CHECK-SAME: discriminator: 1)
77 ; CHECK: ![[BR]] = !DILocation(line: 1, column: 9, scope: !14)
8078 !20 = !DILocation(line: 1, column: 9, scope: !14)
8179 !21 = distinct !{!21, !18}
8280 !22 = !DILocation(line: 1, column: 56, scope: !12)