[llvm] a08a831 - [DLCov][NFC] Propagate annotated DebugLocs through transformations (#138047)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 06:06:31 PDT 2025
Author: Stephen Tozer
Date: 2025-06-12T14:06:27+01:00
New Revision: a08a831515919bcc384b453799f33bc97860c73b
URL: https://github.com/llvm/llvm-project/commit/a08a831515919bcc384b453799f33bc97860c73b
DIFF: https://github.com/llvm/llvm-project/commit/a08a831515919bcc384b453799f33bc97860c73b.diff
LOG: [DLCov][NFC] Propagate annotated DebugLocs through transformations (#138047)
Part of the coverage-tracking feature, following #107279.
In order for DebugLoc coverage testing to work, we firstly have to set
annotations for intentionally-empty DebugLocs, and secondly we have to
ensure that we do not drop these annotations as we propagate DebugLocs
throughout compilation. As the annotations exist as part of the DebugLoc
class, and not the underlying DILocation, they will not survive a
DebugLoc->DILocation->DebugLoc roundtrip. Therefore this patch modifies
a number of places in the compiler to propagate DebugLocs directly
rather than via the underlying DILocation. This has no effect on the
output of normal builds; it only ensures that during coverage builds, we
do not drop incorrectly annotations and therefore create false
positives.
The bulk of these changes are in replacing
DILocation::getMergedLocation(s) with a DebugLoc equivalent, and in
changing the IRBuilder to store a DebugLoc directly rather than storing
DILocations in its general Metadata array. We also use a new function,
`DebugLoc::orElse`, which selects the "best" DebugLoc out of a pair
(valid location > annotated > empty), preferring the current DebugLoc on
a tie - this encapsulates the existing behaviour at a few sites where we
_may_ assign a DebugLoc to an existing instruction, while extending the
logic to handle annotation DebugLocs at the same time.
Added:
Modified:
llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/include/llvm/IR/DebugLoc.h
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/Instruction.h
llvm/lib/CodeGen/BranchFolding.cpp
llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/lib/CodeGen/MachineSink.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/IR/DebugLoc.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/IR/Instruction.cpp
llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/lib/Transforms/Vectorize/VPlan.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h b/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
index 3712a7fa06d9a..22f6a5fde546a 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
@@ -100,8 +100,8 @@ class LegalizationArtifactCombiner {
const LLT DstTy = MRI.getType(DstReg);
if (isInstLegal({TargetOpcode::G_CONSTANT, {DstTy}})) {
auto &CstVal = SrcMI->getOperand(1);
- auto *MergedLocation = DILocation::getMergedLocation(
- MI.getDebugLoc().get(), SrcMI->getDebugLoc().get());
+ auto MergedLocation =
+ DebugLoc::getMergedLocation(MI.getDebugLoc(), SrcMI->getDebugLoc());
// Set the debug location to the merged location of the SrcMI and the MI
// if the aext fold is successful.
Builder.setDebugLoc(MergedLocation);
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index 02f0a9f677db3..18228b7757897 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2437,25 +2437,21 @@ class DILocation : public MDNode {
inline std::optional<const DILocation *>
cloneByMultiplyingDuplicationFactor(unsigned DF) const;
- /// When two instructions are combined into a single instruction we also
- /// need to combine the original locations into a single location.
- /// When the locations are the same we can use either location.
- /// When they
diff er, we need a third location which is distinct from either.
- /// If they share a common scope, use this scope and compare the line/column
- /// pair of the locations with the common scope:
- /// * if both match, keep the line and column;
- /// * if only the line number matches, keep the line and set the column as 0;
- /// * otherwise set line and column as 0.
- /// If they do not share a common scope the location is ambiguous and can't be
- /// represented in a line entry. In this case, set line and column as 0 and
- /// use the scope of any location.
- ///
- /// \p LocA \p LocB: The locations to be merged.
+ /// Attempts to merge \p LocA and \p LocB into a single location; see
+ /// DebugLoc::getMergedLocation for more details.
+ /// NB: When merging the locations of instructions, prefer to use
+ /// DebugLoc::getMergedLocation(), as an instruction's DebugLoc may contain
+ /// additional metadata that will not be preserved when merging the unwrapped
+ /// DILocations.
LLVM_ABI static DILocation *getMergedLocation(DILocation *LocA,
DILocation *LocB);
/// Try to combine the vector of locations passed as input in a single one.
/// This function applies getMergedLocation() repeatedly left-to-right.
+ /// NB: When merging the locations of instructions, prefer to use
+ /// DebugLoc::getMergedLocations(), as an instruction's DebugLoc may contain
+ /// additional metadata that will not be preserved when merging the unwrapped
+ /// DILocations.
///
/// \p Locs: The locations to be merged.
LLVM_ABI static DILocation *getMergedLocations(ArrayRef<DILocation *> Locs);
diff --git a/llvm/include/llvm/IR/DebugLoc.h b/llvm/include/llvm/IR/DebugLoc.h
index c3d0fb80354a4..2fabae9bfc66e 100644
--- a/llvm/include/llvm/IR/DebugLoc.h
+++ b/llvm/include/llvm/IR/DebugLoc.h
@@ -142,6 +142,51 @@ namespace llvm {
static inline DebugLoc getDropped() { return DebugLoc(); }
#endif // LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING
+ /// When two instructions are combined into a single instruction we also
+ /// need to combine the original locations into a single location.
+ /// When the locations are the same we can use either location.
+ /// When they
diff er, we need a third location which is distinct from
+ /// either. If they share a common scope, use this scope and compare the
+ /// line/column pair of the locations with the common scope:
+ /// * if both match, keep the line and column;
+ /// * if only the line number matches, keep the line and set the column as
+ /// 0;
+ /// * otherwise set line and column as 0.
+ /// If they do not share a common scope the location is ambiguous and can't
+ /// be represented in a line entry. In this case, set line and column as 0
+ /// and use the scope of any location.
+ ///
+ /// \p LocA \p LocB: The locations to be merged.
+ LLVM_ABI static DebugLoc getMergedLocation(DebugLoc LocA, DebugLoc LocB);
+
+ /// Try to combine the vector of locations passed as input in a single one.
+ /// This function applies getMergedLocation() repeatedly left-to-right.
+ ///
+ /// \p Locs: The locations to be merged.
+ LLVM_ABI static DebugLoc getMergedLocations(ArrayRef<DebugLoc> Locs);
+
+ /// If this DebugLoc is non-empty, returns this DebugLoc; otherwise, selects
+ /// \p Other.
+ /// In coverage-tracking builds, this also accounts for whether this or
+ /// \p Other have an annotative DebugLocKind applied, such that if both are
+ /// empty but exactly one has an annotation, we prefer that annotated
+ /// location.
+ DebugLoc orElse(DebugLoc Other) const {
+ if (*this)
+ return *this;
+#if LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING
+ if (Other)
+ return Other;
+ if (getKind() != DebugLocKind::Normal)
+ return *this;
+ if (Other.getKind() != DebugLocKind::Normal)
+ return Other;
+ return *this;
+#else
+ return Other;
+#endif // LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING
+ }
+
/// Get the underlying \a DILocation.
///
/// \pre !*this or \c isa<DILocation>(getAsMDNode()).
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index a0cc20d34303a..59295089d6e91 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -113,12 +113,19 @@ class FMFSource {
/// Common base class shared among various IRBuilders.
class IRBuilderBase {
/// Pairs of (metadata kind, MDNode *) that should be added to all newly
- /// created instructions, like !dbg metadata.
+ /// created instructions, excluding !dbg metadata, which is stored in the
+ /// StoredDL field.
SmallVector<std::pair<unsigned, MDNode *>, 2> MetadataToCopy;
+ /// The DebugLoc that will be applied to instructions inserted by this
+ /// builder.
+ DebugLoc StoredDL;
/// Add or update the an entry (Kind, MD) to MetadataToCopy, if \p MD is not
/// null. If \p MD is null, remove the entry with \p Kind.
void AddOrRemoveMetadataToCopy(unsigned Kind, MDNode *MD) {
+ assert(Kind != LLVMContext::MD_dbg &&
+ "MD_dbg metadata must be stored in StoredDL");
+
if (!MD) {
erase_if(MetadataToCopy, [Kind](const std::pair<unsigned, MDNode *> &KV) {
return KV.first == Kind;
@@ -238,7 +245,9 @@ class IRBuilderBase {
/// Set location information used by debugging information.
void SetCurrentDebugLocation(DebugLoc L) {
- AddOrRemoveMetadataToCopy(LLVMContext::MD_dbg, L.getAsMDNode());
+ // For !dbg metadata attachments, we use DebugLoc instead of the raw MDNode
+ // to include optional introspection data for use in Debugify.
+ StoredDL = std::move(L);
}
/// Set nosanitize metadata.
@@ -252,8 +261,12 @@ class IRBuilderBase {
/// not on \p Src will be dropped from MetadataToCopy.
void CollectMetadataToCopy(Instruction *Src,
ArrayRef<unsigned> MetadataKinds) {
- for (unsigned K : MetadataKinds)
- AddOrRemoveMetadataToCopy(K, Src->getMetadata(K));
+ for (unsigned K : MetadataKinds) {
+ if (K == LLVMContext::MD_dbg)
+ SetCurrentDebugLocation(Src->getDebugLoc());
+ else
+ AddOrRemoveMetadataToCopy(K, Src->getMetadata(K));
+ }
}
/// Get location information used by debugging information.
@@ -267,6 +280,7 @@ class IRBuilderBase {
void AddMetadataToInst(Instruction *I) const {
for (const auto &KV : MetadataToCopy)
I->setMetadata(KV.first, KV.second);
+ SetInstDebugLocation(I);
}
/// Get the return type of the current function that we're emitting
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 10fc9c1298607..8e1ef24226789 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -698,7 +698,7 @@ class Instruction : public User,
/// applications, thus the N-way merging should be in code path.
/// The DebugLoc attached to this instruction will be overwritten by the
/// merged DebugLoc.
- LLVM_ABI void applyMergedLocation(DILocation *LocA, DILocation *LocB);
+ LLVM_ABI void applyMergedLocation(DebugLoc LocA, DebugLoc LocB);
/// Updates the debug location given that the instruction has been hoisted
/// from a block to a predecessor of that block.
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index e0f7466ceacff..ff9f0ff5d5bc3 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -862,7 +862,7 @@ void BranchFolder::mergeCommonTails(unsigned commonTailIndex) {
"Reached BB end within common tail");
}
assert(MI.isIdenticalTo(*Pos) && "Expected matching MIIs!");
- DL = DILocation::getMergedLocation(DL, Pos->getDebugLoc());
+ DL = DebugLoc::getMergedLocation(DL, Pos->getDebugLoc());
NextCommonInsts[i] = ++Pos;
}
MI.setDebugLoc(DL);
diff --git a/llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
index 10c72641ce2df..e3e6c72165ebb 100644
--- a/llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
@@ -53,8 +53,7 @@ CSEMIRBuilder::getDominatingInstrForID(FoldingSetNodeID &ID,
} else if (!dominates(MI, CurrPos)) {
// Update the spliced machineinstr's debug location by merging it with the
// debug location of the instruction at the insertion point.
- auto *Loc = DILocation::getMergedLocation(getDebugLoc().get(),
- MI->getDebugLoc().get());
+ auto Loc = DebugLoc::getMergedLocation(getDebugLoc(), MI->getDebugLoc());
MI->setDebugLoc(Loc);
CurMBB->splice(CurrPos, CurMBB, MI);
}
@@ -170,7 +169,7 @@ CSEMIRBuilder::generateCopiesIfRequired(ArrayRef<DstOp> DstOps,
if (Observer)
Observer->changingInstr(*MIB);
MIB->setDebugLoc(
- DILocation::getMergedLocation(MIB->getDebugLoc(), getDebugLoc()));
+ DebugLoc::getMergedLocation(MIB->getDebugLoc(), getDebugLoc()));
if (Observer)
Observer->changedInstr(*MIB);
}
diff --git a/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp b/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp
index 78cd9bc7891e0..f68420ed66e4b 100644
--- a/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp
@@ -370,7 +370,7 @@ bool LoadStoreOpt::doSingleStoreMerge(SmallVectorImpl<GStore *> &Stores) {
// For each store, compute pairwise merged debug locs.
DebugLoc MergedLoc = Stores.front()->getDebugLoc();
for (auto *Store : drop_begin(Stores))
- MergedLoc = DILocation::getMergedLocation(MergedLoc, Store->getDebugLoc());
+ MergedLoc = DebugLoc::getMergedLocation(MergedLoc, Store->getDebugLoc());
Builder.setInstr(*Stores.back());
Builder.setDebugLoc(MergedLoc);
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index ccc164a0881e9..48b406e016c05 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1574,7 +1574,7 @@ MachineBasicBlock::findBranchDebugLoc() {
DL = TI->getDebugLoc();
for (++TI ; TI != end() ; ++TI)
if (TI->isBranch())
- DL = DILocation::getMergedLocation(DL, TI->getDebugLoc());
+ DL = DebugLoc::getMergedLocation(DL, TI->getDebugLoc());
}
return DL;
}
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index e3f6eda8ff065..8411d5c4b09c8 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -1611,8 +1611,8 @@ static void performSink(MachineInstr &MI, MachineBasicBlock &SuccToSinkTo,
// location to prevent debug-info driven tools from potentially reporting
// wrong location information.
if (!SuccToSinkTo.empty() && InsertPos != SuccToSinkTo.end())
- MI.setDebugLoc(DILocation::getMergedLocation(MI.getDebugLoc(),
- InsertPos->getDebugLoc()));
+ MI.setDebugLoc(DebugLoc::getMergedLocation(MI.getDebugLoc(),
+ InsertPos->getDebugLoc()));
else
MI.setDebugLoc(DebugLoc());
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 2a84e7bae0f10..9527c3e0b5d67 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -960,8 +960,8 @@ unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
return 0;
}
-void Instruction::applyMergedLocation(DILocation *LocA, DILocation *LocB) {
- setDebugLoc(DILocation::getMergedLocation(LocA, LocB));
+void Instruction::applyMergedLocation(DebugLoc LocA, DebugLoc LocB) {
+ setDebugLoc(DebugLoc::getMergedLocation(LocA, LocB));
}
void Instruction::mergeDIAssignID(
diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp
index 0e65ddcec8934..0be6d55d724e0 100644
--- a/llvm/lib/IR/DebugLoc.cpp
+++ b/llvm/lib/IR/DebugLoc.cpp
@@ -143,6 +143,27 @@ DebugLoc DebugLoc::appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt,
return Last;
}
+DebugLoc DebugLoc::getMergedLocations(ArrayRef<DebugLoc> Locs) {
+ if (Locs.empty())
+ return DebugLoc();
+ if (Locs.size() == 1)
+ return Locs[0];
+ DebugLoc Merged = Locs[0];
+ for (const DebugLoc &DL : llvm::drop_begin(Locs)) {
+ Merged = getMergedLocation(Merged, DL);
+ if (!Merged)
+ break;
+ }
+ return Merged;
+}
+DebugLoc DebugLoc::getMergedLocation(DebugLoc LocA, DebugLoc LocB) {
+ if (!LocA)
+ return LocA;
+ if (!LocB)
+ return LocB;
+ return DILocation::getMergedLocation(LocA, LocB);
+}
+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void DebugLoc::dump() const { print(dbgs()); }
#endif
diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp
index 59623b4295bb1..a33ef9c7d4a17 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -61,19 +61,12 @@ Type *IRBuilderBase::getCurrentFunctionReturnType() const {
return BB->getParent()->getReturnType();
}
-DebugLoc IRBuilderBase::getCurrentDebugLocation() const {
- for (auto &KV : MetadataToCopy)
- if (KV.first == LLVMContext::MD_dbg)
- return {cast<DILocation>(KV.second)};
-
- return {};
-}
+DebugLoc IRBuilderBase::getCurrentDebugLocation() const { return StoredDL; }
void IRBuilderBase::SetInstDebugLocation(Instruction *I) const {
- for (const auto &KV : MetadataToCopy)
- if (KV.first == LLVMContext::MD_dbg) {
- I->setDebugLoc(DebugLoc(KV.second));
- return;
- }
+ // We prefer to set our current debug location if any has been set, but if
+ // our debug location is empty and I has a valid location, we shouldn't
+ // overwrite it.
+ I->setDebugLoc(StoredDL.orElse(I->getDebugLoc()));
}
Value *IRBuilderBase::CreateAggregateCast(Value *V, Type *DestTy) {
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 1b60caab6c11a..cbf39b8adf1b2 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -1354,6 +1354,9 @@ void Instruction::swapProfMetadata() {
void Instruction::copyMetadata(const Instruction &SrcInst,
ArrayRef<unsigned> WL) {
+ if (WL.empty() || is_contained(WL, LLVMContext::MD_dbg))
+ setDebugLoc(SrcInst.getDebugLoc().orElse(getDebugLoc()));
+
if (!SrcInst.hasMetadata())
return;
@@ -1367,8 +1370,6 @@ void Instruction::copyMetadata(const Instruction &SrcInst,
if (WL.empty() || WLS.count(MD.first))
setMetadata(MD.first, MD.second);
}
- if (WL.empty() || WLS.count(LLVMContext::MD_dbg))
- setDebugLoc(SrcInst.getDebugLoc());
}
Instruction *Instruction::clone() const {
diff --git a/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp b/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp
index 77bbeab3c2790..222eb19e3eeef 100644
--- a/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp
+++ b/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp
@@ -150,10 +150,10 @@ static CallInst *isGEPAndStore(Value *I) {
}
template <class T = Instruction>
-static DILocation *mergeDILocations(SmallVector<T *> &Insns) {
- DILocation *Merged = (*Insns.begin())->getDebugLoc();
+static DebugLoc mergeDebugLocs(SmallVector<T *> &Insns) {
+ DebugLoc Merged = (*Insns.begin())->getDebugLoc();
for (T *I : Insns)
- Merged = DILocation::getMergedLocation(Merged, I->getDebugLoc());
+ Merged = DebugLoc::getMergedLocation(Merged, I->getDebugLoc());
return Merged;
}
@@ -227,7 +227,7 @@ static Instruction *makeGEPAndLoad(Module *M, GEPChainInfo &GEP,
CallInst *Call = makeIntrinsicCall(M, Intrinsic::bpf_getelementptr_and_load,
{Load->getType()}, Args);
setParamElementType(Call, 0, GEP.SourceElementType);
- Call->applyMergedLocation(mergeDILocations(GEP.Members), Load->getDebugLoc());
+ Call->applyMergedLocation(mergeDebugLocs(GEP.Members), Load->getDebugLoc());
Call->setName((*GEP.Members.rbegin())->getName());
if (Load->isUnordered()) {
Call->setOnlyReadsMemory();
@@ -251,8 +251,7 @@ static Instruction *makeGEPAndStore(Module *M, GEPChainInfo &GEP,
setParamElementType(Call, 1, GEP.SourceElementType);
if (Store->getValueOperand()->getType()->isPointerTy())
setParamReadNone(Call, 0);
- Call->applyMergedLocation(mergeDILocations(GEP.Members),
- Store->getDebugLoc());
+ Call->applyMergedLocation(mergeDebugLocs(GEP.Members), Store->getDebugLoc());
if (Store->isUnordered()) {
Call->setOnlyWritesMemory();
Call->setOnlyAccessesArgMemory();
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 324e6022f3f05..1d208de75db3b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1581,8 +1581,8 @@ bool InstCombinerImpl::mergeStoreIntoSuccessor(StoreInst &SI) {
// Insert a PHI node now if we need it.
Value *MergedVal = OtherStore->getValueOperand();
// The debug locations of the original instructions might
diff er. Merge them.
- DebugLoc MergedLoc = DILocation::getMergedLocation(SI.getDebugLoc(),
- OtherStore->getDebugLoc());
+ DebugLoc MergedLoc =
+ DebugLoc::getMergedLocation(SI.getDebugLoc(), OtherStore->getDebugLoc());
if (MergedVal != SI.getValueOperand()) {
PHINode *PN =
PHINode::Create(SI.getValueOperand()->getType(), 2, "storemerge");
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index e261807bbc035..dc2a8cb0115e7 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -5340,8 +5340,7 @@ bool InstCombinerImpl::run() {
// We copy the old instruction's DebugLoc to the new instruction, unless
// InstCombine already assigned a DebugLoc to it, in which case we
// should trust the more specifically selected DebugLoc.
- if (!Result->getDebugLoc())
- Result->setDebugLoc(I->getDebugLoc());
+ Result->setDebugLoc(Result->getDebugLoc().orElse(I->getDebugLoc()));
// We also copy annotation metadata to the new instruction.
Result->copyMetadata(*I, LLVMContext::MD_annotation);
// Everything uses the new instruction now.
diff --git a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
index 07bc623c3dea0..839f5933e09b0 100644
--- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -883,7 +883,7 @@ bool ConstantHoistingPass::emitBaseConstants(GlobalVariable *BaseGV) {
emitBaseConstants(Base, &R);
ReBasesNum++;
// Use the same debug location as the last user of the constant.
- Base->setDebugLoc(DILocation::getMergedLocation(
+ Base->setDebugLoc(DebugLoc::getMergedLocation(
Base->getDebugLoc(), R.User.Inst->getDebugLoc()));
}
assert(!Base->use_empty() && "The use list is empty!?");
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 3024ccb330b1a..bd59caa6a959a 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -2224,10 +2224,10 @@ bool llvm::promoteLoopAccessesToScalars(
});
// Look at all the loop uses, and try to merge their locations.
- std::vector<DILocation *> LoopUsesLocs;
- for (auto *U : LoopUses)
- LoopUsesLocs.push_back(U->getDebugLoc().get());
- auto DL = DebugLoc(DILocation::getMergedLocations(LoopUsesLocs));
+ std::vector<DebugLoc> LoopUsesLocs;
+ for (auto U : LoopUses)
+ LoopUsesLocs.push_back(U->getDebugLoc());
+ auto DL = DebugLoc::getMergedLocations(LoopUsesLocs);
// We use the SSAUpdater interface to insert phi nodes as required.
SmallVector<PHINode *, 16> NewPHIs;
diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
index 4e437e9abeb43..d20378ece4eea 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -128,7 +128,7 @@ performBlockTailMerging(Function &F, ArrayRef<BasicBlock *> BBs,
// Now, go through each block (with the current terminator type)
// we've recorded, and rewrite it to branch to the new common block.
- DILocation *CommonDebugLoc = nullptr;
+ DebugLoc CommonDebugLoc;
for (BasicBlock *BB : BBs) {
auto *Term = BB->getTerminator();
assert(Term->getOpcode() == CanonicalTerm->getOpcode() &&
@@ -145,7 +145,7 @@ performBlockTailMerging(Function &F, ArrayRef<BasicBlock *> BBs,
CommonDebugLoc = Term->getDebugLoc();
else
CommonDebugLoc =
- DILocation::getMergedLocation(CommonDebugLoc, Term->getDebugLoc());
+ DebugLoc::getMergedLocation(CommonDebugLoc, Term->getDebugLoc());
// And turn BB into a block that just unconditionally branches
// to the canonical block.
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index f67a6414ca316..0980f0e57aa6d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2095,11 +2095,11 @@ bool SimplifyCFGOpt::hoistSuccIdenticalTerminatorToSwitchOrIf(
// Ensure terminator gets a debug location, even an unknown one, in case
// it involves inlinable calls.
- SmallVector<DILocation *, 4> Locs;
+ SmallVector<DebugLoc, 4> Locs;
Locs.push_back(I1->getDebugLoc());
for (auto *OtherSuccTI : OtherSuccTIs)
Locs.push_back(OtherSuccTI->getDebugLoc());
- NT->setDebugLoc(DILocation::getMergedLocations(Locs));
+ NT->setDebugLoc(DebugLoc::getMergedLocations(Locs));
// PHIs created below will adopt NT's merged DebugLoc.
IRBuilder<NoFolder> Builder(NT);
@@ -2896,7 +2896,7 @@ static void mergeCompatibleInvokesImpl(ArrayRef<InvokeInst *> Invokes,
MergedDebugLoc = II->getDebugLoc();
else
MergedDebugLoc =
- DILocation::getMergedLocation(MergedDebugLoc, II->getDebugLoc());
+ DebugLoc::getMergedLocation(MergedDebugLoc, II->getDebugLoc());
// And replace the old `invoke` with an unconditionally branch
// to the block with the merged `invoke`.
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 1838562f26b82..b74ef91f26e70 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -395,7 +395,7 @@ void VPTransformState::setDebugLocFrom(DebugLoc DL) {
LLVM_DEBUG(dbgs() << "Failed to create new discriminator: "
<< DIL->getFilename() << " Line: " << DIL->getLine());
} else
- Builder.SetCurrentDebugLocation(DIL);
+ Builder.SetCurrentDebugLocation(DL);
}
void VPTransformState::packScalarIntoVectorizedValue(const VPValue *Def,
More information about the llvm-commits
mailing list