r319222 - [OpenMP] Stable sort Privates to remove non-deterministic ordering

Mandeep Singh Grang via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 28 12:41:13 PST 2017


Author: mgrang
Date: Tue Nov 28 12:41:13 2017
New Revision: 319222

URL: http://llvm.org/viewvc/llvm-project?rev=319222&view=rev
Log:
[OpenMP] Stable sort Privates to remove non-deterministic ordering

Summary:
This fixes the following failures uncovered by D39245:
    Clang :: OpenMP/task_firstprivate_codegen.cpp
    Clang :: OpenMP/task_private_codegen.cpp
    Clang :: OpenMP/taskloop_firstprivate_codegen.cpp
    Clang :: OpenMP/taskloop_lastprivate_codegen.cpp
    Clang :: OpenMP/taskloop_private_codegen.cpp
    Clang :: OpenMP/taskloop_simd_firstprivate_codegen.cpp
    Clang :: OpenMP/taskloop_simd_lastprivate_codegen.cpp
    Clang :: OpenMP/taskloop_simd_private_codegen.cpp

Reviewers: rjmccall, ABataev, AndreyChurbanov

Reviewed By: rjmccall, ABataev

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D39947

Modified:
    cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=319222&r1=319221&r2=319222&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Nov 28 12:41:13 2017
@@ -4056,9 +4056,9 @@ emitTaskPrivateMappingFunction(CodeGenMo
   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.
@@ -4286,8 +4286,7 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFun
                          /*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);




More information about the cfe-commits mailing list