Reapply "[DebugInfo] Prevent non-determinism when updating DIArgList users of a value"
authorStephen Tozer <Stephen.Tozer@Sony.com>
Thu, 17 Jun 2021 14:21:10 +0000 (15:21 +0100)
committerStephen Tozer <Stephen.Tozer@Sony.com>
Thu, 17 Jun 2021 15:16:55 +0000 (16:16 +0100)
Reapply the commit which previously caused build failures due to the
mismatched template arguments between the return type and the returned
SmallVector.

This reverts commit e8991caea8690ec2d17b0b7e1c29bf0da6609076.

llvm/include/llvm/IR/Metadata.h
llvm/lib/IR/Metadata.cpp

index 6a9d945..aac03a5 100644 (file)
@@ -304,7 +304,7 @@ public:
   void replaceAllUsesWith(Metadata *MD);
 
   /// Returns the list of all DIArgList users of this.
-  SmallVector<Metadata *, 4> getAllArgListUsers();
+  SmallVector<Metadata *> getAllArgListUsers();
 
   /// Resolve all uses of this.
   ///
@@ -385,7 +385,7 @@ public:
   Type *getType() const { return V->getType(); }
   LLVMContext &getContext() const { return V->getContext(); }
 
-  SmallVector<Metadata *, 4> getAllArgListUsers() {
+  SmallVector<Metadata *> getAllArgListUsers() {
     return ReplaceableMetadataImpl::getAllArgListUsers();
   }
 
index 4d6ccfa..4f87ef5 100644 (file)
@@ -195,16 +195,22 @@ bool MetadataTracking::isReplaceable(const Metadata &MD) {
   return ReplaceableMetadataImpl::isReplaceable(MD);
 }
 
-SmallVector<Metadata *, 4> ReplaceableMetadataImpl::getAllArgListUsers() {
-  SmallVector<Metadata *, 4> MDUsers;
+SmallVector<Metadata *> ReplaceableMetadataImpl::getAllArgListUsers() {
+  SmallVector<std::pair<OwnerTy, uint64_t> *> MDUsersWithID;
   for (auto Pair : UseMap) {
     OwnerTy Owner = Pair.second.first;
     if (!Owner.is<Metadata *>())
       continue;
     Metadata *OwnerMD = Owner.get<Metadata *>();
     if (OwnerMD->getMetadataID() == Metadata::DIArgListKind)
-      MDUsers.push_back(OwnerMD);
+      MDUsersWithID.push_back(&UseMap[Pair.first]);
   }
+  llvm::sort(MDUsersWithID, [](auto UserA, auto UserB) {
+    return UserA->second < UserB->second;
+  });
+  SmallVector<Metadata *> MDUsers;
+  for (auto UserWithID : MDUsersWithID)
+    MDUsers.push_back(UserWithID->first.get<Metadata *>());
   return MDUsers;
 }