[PATCH] [OPENMP] Fixed incorrect work with cleanups, NFC.

Alexey Bataev a.bataev at hotmail.com
Mon May 4 21:45:46 PDT 2015


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D9399

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

Index: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1154,16 +1154,22 @@
 }
 
 namespace {
-class CallEndCleanup : public EHScopeStack::Cleanup {
+template <int N> class CallEndCleanup : public EHScopeStack::Cleanup {
 public:
   typedef ArrayRef<llvm::Value *> CleanupValuesTy;
+
 private:
   llvm::Value *Callee;
-  llvm::SmallVector<llvm::Value *, 8> Args;
+  llvm::Value *Args[N];
 
 public:
-  CallEndCleanup(llvm::Value *Callee, CleanupValuesTy Args)
-      : Callee(Callee), Args(Args.begin(), Args.end()) {}
+  CallEndCleanup(llvm::Value *Callee, CleanupValuesTy CleanupArgs)
+      : Callee(Callee) {
+    assert(CleanupArgs.size() == N);
+    for (unsigned i = 0; i < N; ++i) {
+      Args[i] = CleanupArgs[i];
+    }
+  }
   void Emit(CodeGenFunction &CGF, Flags /*flags*/) override {
     CGF.EmitRuntimeCall(Callee, Args);
   }
@@ -1184,7 +1190,7 @@
                            getCriticalRegionLock(CriticalName)};
     CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_critical), Args);
     // Build a call to __kmpc_end_critical
-    CGF.EHStack.pushCleanup<CallEndCleanup>(
+    CGF.EHStack.pushCleanup<CallEndCleanup<array_lengthof(Args)>>(
         NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_critical),
         llvm::makeArrayRef(Args));
     emitInlinedDirective(CGF, CriticalOpGen);
@@ -1222,7 +1228,7 @@
       CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_master), Args);
   emitIfStmt(CGF, IsMaster, [&](CodeGenFunction &CGF) -> void {
     CodeGenFunction::RunCleanupsScope Scope(CGF);
-    CGF.EHStack.pushCleanup<CallEndCleanup>(
+    CGF.EHStack.pushCleanup<CallEndCleanup<array_lengthof(Args)>>(
         NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_master),
         llvm::makeArrayRef(Args));
     MasterOpGen(CGF);
@@ -1328,7 +1334,7 @@
       CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_single), Args);
   emitIfStmt(CGF, IsSingle, [&](CodeGenFunction &CGF) -> void {
     CodeGenFunction::RunCleanupsScope Scope(CGF);
-    CGF.EHStack.pushCleanup<CallEndCleanup>(
+    CGF.EHStack.pushCleanup<CallEndCleanup<array_lengthof(Args)>>(
         NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_single),
         llvm::makeArrayRef(Args));
     SingleOpGen(CGF);
@@ -1391,7 +1397,7 @@
     llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)};
     CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_ordered), Args);
     // Build a call to __kmpc_end_ordered
-    CGF.EHStack.pushCleanup<CallEndCleanup>(
+    CGF.EHStack.pushCleanup<CallEndCleanup<array_lengthof(Args)>>(
         NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_ordered),
         llvm::makeArrayRef(Args));
     emitInlinedDirective(CGF, OrderedOpGen);
@@ -1999,7 +2005,7 @@
             createRuntimeFunction(OMPRTL__kmpc_omp_task_begin_if0), TaskArgs);
         // Build void __kmpc_omp_task_complete_if0(ident_t *, kmp_int32 gtid,
         // kmp_task_t *new_task);
-        CGF.EHStack.pushCleanup<CallEndCleanup>(
+        CGF.EHStack.pushCleanup<CallEndCleanup<array_lengthof(TaskArgs)>>(
             NormalAndEHCleanup,
             createRuntimeFunction(OMPRTL__kmpc_omp_task_complete_if0),
             llvm::makeArrayRef(TaskArgs));
@@ -2191,7 +2197,7 @@
         ThreadId,  // i32 <gtid>
         Lock       // kmp_critical_name *&<lock>
     };
-    CGF.EHStack.pushCleanup<CallEndCleanup>(
+    CGF.EHStack.pushCleanup<CallEndCleanup<array_lengthof(EndArgs)>>(
         NormalAndEHCleanup,
         createRuntimeFunction(WithNowait ? OMPRTL__kmpc_end_reduce_nowait
                                          : OMPRTL__kmpc_end_reduce),

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9399.24935.patch
Type: text/x-patch
Size: 3813 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150505/bc73948a/attachment.bin>


More information about the cfe-commits mailing list