[PATCH] D104105: [DebugInfo] Prevent non-determinism when updating DIArgList users of a value

Stephen Tozer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 11 03:47:35 PDT 2021


StephenTozer created this revision.
StephenTozer added reviewers: aprantl, vsk, probinson, djtodoro.
StephenTozer added a project: debug-info.
Herald added subscribers: dexonsmith, mgrang, hiraditya.
StephenTozer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch fixes the most recent issue mentioned in the discussion for patch D91722 <https://reviews.llvm.org/D91722>, in which some builds had non-deterministic output. This bug is rooted in `ReplaceableMetadataImpl::getAllArgListUsers`, which returns a vector of `Metadata*`; this vector is built by iterating over a map, and the result is later used to modify/produce instructions. This patch uses the IDs associated with each user to ensure that the vector is deterministically ordered; there is no importance to the ordering itself, other than that it is deterministic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104105

Files:
  llvm/lib/IR/Metadata.cpp


Index: llvm/lib/IR/Metadata.cpp
===================================================================
--- llvm/lib/IR/Metadata.cpp
+++ llvm/lib/IR/Metadata.cpp
@@ -196,15 +196,22 @@
 }
 
 SmallVector<Metadata *, 4> ReplaceableMetadataImpl::getAllArgListUsers() {
-  SmallVector<Metadata *, 4> MDUsers;
+  SmallVector<std::pair<Metadata *, uint64_t>> MDUsersWithID;
   for (auto Pair : UseMap) {
     OwnerTy Owner = Pair.second.first;
+    uint64_t OwnerID = Pair.second.second;
     if (!Owner.is<Metadata *>())
       continue;
     Metadata *OwnerMD = Owner.get<Metadata *>();
     if (OwnerMD->getMetadataID() == Metadata::DIArgListKind)
-      MDUsers.push_back(OwnerMD);
+      MDUsersWithID.push_back({OwnerMD, OwnerID});
   }
+  llvm::sort(MDUsersWithID, [](auto UserA, auto UserB) {
+    return UserA.second < UserB.second;
+  });
+  SmallVector<Metadata *> MDUsers;
+  for (auto UserWithID : MDUsersWithID)
+    MDUsers.push_back(UserWithID.first);
   return MDUsers;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104105.351390.patch
Type: text/x-patch
Size: 981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210611/3299f1f6/attachment.bin>


More information about the llvm-commits mailing list