summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/IR/DebugInfoMetadata.h18
-rw-r--r--llvm/lib/IR/DebugInfo.cpp20
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp27
3 files changed, 35 insertions, 30 deletions
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index bee8cf8a39d..b1f08e7c67c 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -1419,19 +1419,15 @@ public:
/// represented in a single line entry. In this case, no location
/// should be set, unless the merged instruction is a call, which we will
/// set the merged debug location as line 0 of the nearest common scope
- /// where 2 locations are inlined from. This only applies to Instruction,
- /// For MachineInstruction, as it is post-inline, we will treat the call
+ /// where 2 locations are inlined from. This only applies to Instruction;
+ /// for MachineInstruction, as it is post-inline, we will treat the call
/// instruction the same way as other instructions.
///
- /// This should only be used by MachineInstruction because call can be
- /// treated the same as other instructions. Otherwise, use
- /// \p applyMergedLocation instead.
- static const DILocation *getMergedLocation(const DILocation *LocA,
- const DILocation *LocB) {
- if (LocA && LocB && (LocA == LocB || !LocA->canDiscriminate(*LocB)))
- return LocA;
- return nullptr;
- }
+ /// \p ForInst: The Instruction the merged DILocation is for. If the
+ /// Instruction is unavailable or non-existent, use nullptr.
+ static const DILocation *
+ getMergedLocation(const DILocation *LocA, const DILocation *LocB,
+ const Instruction *ForInst = nullptr);
/// Returns the base discriminator for a given encoded discriminator \p D.
static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D) {
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index b34383f5ada..df0c52d4463 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -676,25 +676,7 @@ unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
void Instruction::applyMergedLocation(const DILocation *LocA,
const DILocation *LocB) {
- if (LocA && LocB && (LocA == LocB || !LocA->canDiscriminate(*LocB))) {
- setDebugLoc(LocA);
- return;
- }
- if (!LocA || !LocB || !isa<CallInst>(this)) {
- setDebugLoc(nullptr);
- return;
- }
- SmallPtrSet<DILocation *, 5> InlinedLocationsA;
- for (DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
- InlinedLocationsA.insert(L);
- const DILocation *Result = LocB;
- for (DILocation *L = LocB->getInlinedAt(); L; L = L->getInlinedAt()) {
- Result = L;
- if (InlinedLocationsA.count(L))
- break;
- }
- setDebugLoc(DILocation::get(
- Result->getContext(), 0, 0, Result->getScope(), Result->getInlinedAt()));
+ setDebugLoc(DILocation::getMergedLocation(LocA, LocB, this));
}
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 645bba1652d..0a9c5c19e5a 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -14,9 +14,11 @@
#include "llvm/IR/DebugInfoMetadata.h"
#include "LLVMContextImpl.h"
#include "MetadataImpl.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
using namespace llvm;
@@ -66,6 +68,31 @@ DILocation *DILocation::getImpl(LLVMContext &Context, unsigned Line,
Storage, Context.pImpl->DILocations);
}
+const DILocation *
+DILocation::getMergedLocation(const DILocation *LocA, const DILocation *LocB,
+ const Instruction *ForInst) {
+ if (!LocA || !LocB)
+ return nullptr;
+
+ if (LocA == LocB || !LocA->canDiscriminate(*LocB))
+ return LocA;
+
+ if (!dyn_cast_or_null<CallInst>(ForInst))
+ return nullptr;
+
+ SmallPtrSet<DILocation *, 5> InlinedLocationsA;
+ for (DILocation *L = LocA->getInlinedAt(); L; L = L->getInlinedAt())
+ InlinedLocationsA.insert(L);
+ const DILocation *Result = LocB;
+ for (DILocation *L = LocB->getInlinedAt(); L; L = L->getInlinedAt()) {
+ Result = L;
+ if (InlinedLocationsA.count(L))
+ break;
+ }
+ return DILocation::get(Result->getContext(), 0, 0, Result->getScope(),
+ Result->getInlinedAt());
+}
+
DINode::DIFlags DINode::getFlag(StringRef Flag) {
return StringSwitch<DIFlags>(Flag)
#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
OpenPOWER on IntegriCloud