[PATCH] D39947: [OpenMP] Stable sort Privates to remove non-deterministic ordering

Mandeep Singh Grang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 13 17:08:28 PST 2017


mgrang updated this revision to Diff 122751.
mgrang added a comment.

Fixed the sorting order for stable_sort.


Repository:
  rL LLVM

https://reviews.llvm.org/D39947

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4048,9 +4048,9 @@
   return TaskPrivatesMap;
 }
 
-static int array_pod_sort_comparator(const PrivateDataTy *P1,
-                                     const PrivateDataTy *P2) {
-  return P1->first < P2->first ? 1 : (P2->first < P1->first ? -1 : 0);
+static bool stable_sort_comparator(const PrivateDataTy P1,
+                                   const PrivateDataTy P2) {
+  return P1.first > P2.first;
 }
 
 /// Emit initialization for private variables in task-based directives.
@@ -4278,8 +4278,7 @@
                          /*PrivateElemInit=*/nullptr)));
     ++I;
   }
-  llvm::array_pod_sort(Privates.begin(), Privates.end(),
-                       array_pod_sort_comparator);
+  std::stable_sort(Privates.begin(), Privates.end(), stable_sort_comparator);
   auto KmpInt32Ty = C.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1);
   // Build type kmp_routine_entry_t (if not built yet).
   emitKmpRoutineEntryT(KmpInt32Ty);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39947.122751.patch
Type: text/x-patch
Size: 1120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171114/917f8bbb/attachment.bin>


More information about the cfe-commits mailing list