From 2c64a1129f14d6322631e1c6d610b92c4c4871d0 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Sat, 11 Apr 2015 01:00:47 +0000 Subject: [PATCH] DebugInfo: Rewrite atSameLineAs() as MDLocation::canDiscriminate() Rewrite `DILocation::atSameLineAs()` as `MDLocation::canDiscriminate()` with a doxygen comment explaining its purpose. I've added a few FIXMEs where I think this check is too weak; fixing that is tracked by PR23199. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234674 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DebugInfo.h | 5 +---- include/llvm/IR/DebugInfoMetadata.h | 17 +++++++++++++++++ lib/Transforms/Utils/AddDiscriminators.cpp | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/llvm/IR/DebugInfo.h b/include/llvm/IR/DebugInfo.h index beb5c5769f1..9237377e2a3 100644 --- a/include/llvm/IR/DebugInfo.h +++ b/include/llvm/IR/DebugInfo.h @@ -810,10 +810,7 @@ public: } StringRef getFilename() const { return get()->getFilename(); } StringRef getDirectory() const { return get()->getDirectory(); } - bool atSameLineAs(const DILocation &Other) const { - return (getLineNumber() == Other.getLineNumber() && - getFilename() == Other.getFilename()); - } + /// \brief Get the DWAF discriminator. /// /// DWARF discriminators are used to distinguish identical file locations for diff --git a/include/llvm/IR/DebugInfoMetadata.h b/include/llvm/IR/DebugInfoMetadata.h index 374f7277636..0f42b02f808 100644 --- a/include/llvm/IR/DebugInfoMetadata.h +++ b/include/llvm/IR/DebugInfoMetadata.h @@ -1166,6 +1166,23 @@ public: return getScope(); } + /// \brief Check whether this can be discriminated from another location. + /// + /// Check \c this can be discriminated from \c RHS in a linetable entry. + /// Scope and inlined-at chains are not recorded in the linetable, so they + /// cannot be used to distinguish basic blocks. + /// + /// The current implementation is weaker than it should be, since it just + /// checks filename and line. + /// + /// FIXME: Add a check for getDiscriminator(). + /// FIXME: Add a check for getColumn(). + /// FIXME: Change the getFilename() check to getFile() (or add one for + /// getDirectory()). + bool canDiscriminate(const MDLocation &RHS) const { + return getFilename() != RHS.getFilename() || getLine() != RHS.getLine(); + } + Metadata *getRawScope() const { return getOperand(0); } Metadata *getRawInlinedAt() const { if (getNumOperands() == 2) diff --git a/lib/Transforms/Utils/AddDiscriminators.cpp b/lib/Transforms/Utils/AddDiscriminators.cpp index 0379736f15d..e8f1d5c83c6 100644 --- a/lib/Transforms/Utils/AddDiscriminators.cpp +++ b/lib/Transforms/Utils/AddDiscriminators.cpp @@ -189,7 +189,7 @@ bool AddDiscriminators::runOnFunction(Function &F) { // location as B's last instruction (Last), add a new // discriminator for First's location and all the instructions // in Succ that share the same location with First. - if (FirstDIL.atSameLineAs(LastDIL)) { + if (!FirstDIL->canDiscriminate(*LastDIL)) { // Create a new lexical scope and compute a new discriminator // number for it. StringRef Filename = FirstDIL.getFilename(); -- 2.34.1