[llvm] [DebugInfo] Handle followup loop metadata in updateLoopMetadataDebugLocations (PR #157557)
Stephen Tozer via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 23 10:36:44 PDT 2025
================
@@ -375,6 +375,32 @@ bool DebugInfoFinder::addScope(DIScope *Scope) {
return true;
}
+// Recursively handle DILocations in followup metadata etc.
+static Metadata *updateLoopMetadataDebugLocationsRecursive(
+ Metadata *MetadataIn, function_ref<Metadata *(Metadata *)> Updater) {
+ const MDNode *M = dyn_cast_or_null<MDNode>(MetadataIn);
+ // The loop metadata options should start with a MDString.
+ if (!M || M->getNumOperands() < 1 || !isa<MDString>(M->getOperand(0)))
+ return nullptr;
+
+ bool Updated = false;
+ SmallVector<Metadata *, 4> MDs{M->getOperand(0)};
+ for (Metadata *MD : llvm::drop_begin(M->operands())) {
+ if (!MD) {
+ MDs.push_back(nullptr);
+ } else if (Metadata *NewMD =
+ updateLoopMetadataDebugLocationsRecursive(MD, Updater)) {
+ MDs.push_back(NewMD);
+ Updated = true;
+ } else if (Metadata *NewMD = Updater(MD)) {
+ MDs.push_back(NewMD);
+ Updated |= NewMD != MD;
+ }
+ }
+
+ return Updated ? MDNode::get(M->getContext(), MDs) : nullptr;
----------------
SLTozer wrote:
Is it guaranteed that there are no `distinct` loop metadata options? I can't see a reason they would exist, but may be worth adding an assert to that effect anyway.
https://github.com/llvm/llvm-project/pull/157557
More information about the llvm-commits
mailing list