Author: Alexey Bataev
Date: 2020-03-04T16:30:34-05:00
New Revision: b27ff4d07ddcf6aff8aec36aa05e212da0ab6adf

URL: 
https://github.com/llvm/llvm-project/commit/b27ff4d07ddcf6aff8aec36aa05e212da0ab6adf
DIFF: 
https://github.com/llvm/llvm-project/commit/b27ff4d07ddcf6aff8aec36aa05e212da0ab6adf.diff

LOG: [OPENMP50]Codegen for 'destroy' clause in depobj directive.

If the destroy clause is appplied, the previously allocated memory for
the dependency object must be destroyed.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGOpenMPRuntime.cpp
    clang/lib/CodeGen/CGOpenMPRuntime.h
    clang/lib/CodeGen/CGStmtOpenMP.cpp
    clang/test/OpenMP/depobj_codegen.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index ce23434e1a52..09749270b830 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -5318,6 +5318,18 @@ Address CGOpenMPRuntime::emitDependClause(
   return DependenciesArray;
 }
 
+void CGOpenMPRuntime::emitDestroyClause(CodeGenFunction &CGF, LValue 
DepobjLVal,
+                                        SourceLocation Loc) {
+  llvm::Value *DepObjAddr = CGF.EmitLoadOfScalar(DepobjLVal, Loc);
+  llvm::Value *ThreadID = getThreadID(CGF, Loc);
+  // Use default allocator.
+  llvm::Value *Allocator = llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
+  llvm::Value *Args[] = {ThreadID, DepObjAddr, Allocator};
+
+  // _kmpc_free(gtid, addr, nullptr);
+  (void)CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_free), Args);
+}
+
 void CGOpenMPRuntime::emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc,
                                    const OMPExecutableDirective &D,
                                    llvm::Function *TaskFunction,

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.h 
b/clang/lib/CodeGen/CGOpenMPRuntime.h
index 54223d390057..fe526464bb1d 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -1786,6 +1786,11 @@ class CGOpenMPRuntime {
       CodeGenFunction &CGF,
       ArrayRef<std::pair<OpenMPDependClauseKind, const Expr *>> Dependencies,
       bool ForDepobj, SourceLocation Loc);
+
+  /// Emits the code to destroy the dependency object provided in depobj
+  /// directive.
+  void emitDestroyClause(CodeGenFunction &CGF, LValue DepobjLVal,
+                         SourceLocation Loc);
 };
 
 /// Class supports emissionof SIMD-only code.

diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 822542df1bc4..2de1fe65c71b 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -3811,6 +3811,11 @@ void CodeGenFunction::EmitOMPDepobjDirective(const 
OMPDepobjDirective &S) {
     Address DepAddr = CGM.getOpenMPRuntime().emitDependClause(
         *this, Dependencies, /*ForDepobj=*/true, DC->getBeginLoc());
     EmitStoreOfScalar(DepAddr.getPointer(), DOLVal);
+    return;
+  }
+  if (const auto *DC = S.getSingleClause<OMPDestroyClause>()) {
+    CGM.getOpenMPRuntime().emitDestroyClause(*this, DOLVal, DC->getBeginLoc());
+    return;
   }
 }
 

diff  --git a/clang/test/OpenMP/depobj_codegen.cpp 
b/clang/test/OpenMP/depobj_codegen.cpp
index 7a8264a81cad..1d1809b2155c 100644
--- a/clang/test/OpenMP/depobj_codegen.cpp
+++ b/clang/test/OpenMP/depobj_codegen.cpp
@@ -38,6 +38,7 @@ int main(int argc, char **argv) {
 }
 
 // CHECK-LABEL: @main
+// CHECK: [[B_ADDR:%.+]] = alloca i8*,
 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(
 // CHECK: [[DEP_ADDR_VOID:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 72, 
i8* null)
 // CHECK: [[DEP_ADDR:%.+]] = bitcast i8* [[DEP_ADDR_VOID]] to [3 x 
%struct.kmp_depend_info]*
@@ -61,8 +62,11 @@ int main(int argc, char **argv) {
 // CHECK: [[BASE_ADDR:%.+]] = getelementptr inbounds [3 x 
%struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* [[DEP_ADDR]], i{{.+}} 
0, i{{.+}} 0
 // CHECK: [[DEP:%.+]] = bitcast %struct.kmp_depend_info* [[BASE_ADDR]] to i8*
 // CHECK: store i8* [[DEP]], i8** [[MAIN_A]],
+// CHECK: [[B:%.+]] = load i8*, i8** [[B_ADDR]],
+// CHECK: call void @__kmpc_free(i32 [[GTID]], i8* [[B]], i8* null)
 
 // CHECK-LABEL: tmain
+// CHECK: [[ARGC_ADDR:%.+]] = alloca i8*,
 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(
 // CHECK: [[DEP_ADDR_VOID:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 48, 
i8* null)
 // CHECK: [[DEP_ADDR:%.+]] = bitcast i8* [[DEP_ADDR_VOID]] to [2 x 
%struct.kmp_depend_info]*
@@ -79,5 +83,7 @@ int main(int argc, char **argv) {
 // CHECK: [[BASE_ADDR:%.+]] = getelementptr inbounds [2 x 
%struct.kmp_depend_info], [2 x %struct.kmp_depend_info]* [[DEP_ADDR]], i{{.+}} 
0, i{{.+}} 0
 // CHECK: [[DEP:%.+]] = bitcast %struct.kmp_depend_info* [[BASE_ADDR]] to i8*
 // CHECK: store i8* [[DEP]], i8** [[TMAIN_A]],
+// CHECK: [[ARGC:%.+]] = load i8*, i8** [[ARGC_ADDR]],
+// CHECK: call void @__kmpc_free(i32 [[GTID]], i8* [[ARGC]], i8* null)
 
 #endif


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to