From b4c74c6603cd1951bffde8b188e7d785a37ab479 Mon Sep 17 00:00:00 2001 From: Gheorghe-Teodor Bercea Date: Tue, 12 Dec 2017 21:38:43 +0000 Subject: [PATCH] [OpenMP] Add function attribute for triggering data sharing. Summary: The backend should only emit data sharing code for the cases where it is needed. A new function attribute is used by Clang to enable data sharing only for the cases where OpenMP semantics require it and there are variables that need to be shared. Reviewers: hfinkel, Hahnfeld, ABataev, carlo.bertolli, caomhin Reviewed By: ABataev Subscribers: cfe-commits, jholewinski Differential Revision: https://reviews.llvm.org/D41123 llvm-svn: 320527 --- clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp | 2 ++ clang/test/OpenMP/nvptx_data_sharing.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp index bc769f4f4953c..b5fc8d308067e 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp @@ -942,6 +942,8 @@ void CGOpenMPRuntimeNVPTX::emitGenericParallelCall( llvm::Value *ID = Bld.CreateBitOrPointerCast(WFn, CGM.Int8PtrTy); if (!CapturedVars.empty()) { + // There's somehting to share, add the attribute + CGF.CurFn->addFnAttr("has-nvptx-shared-depot"); // Prepare for parallel region. Indicate the outlined function. Address SharedArgs = CGF.CreateDefaultAlignTempAlloca(CGF.VoidPtrPtrTy, diff --git a/clang/test/OpenMP/nvptx_data_sharing.cpp b/clang/test/OpenMP/nvptx_data_sharing.cpp index 4b8d2df1dab3e..65215cd2c4f97 100644 --- a/clang/test/OpenMP/nvptx_data_sharing.cpp +++ b/clang/test/OpenMP/nvptx_data_sharing.cpp @@ -22,7 +22,7 @@ void test_ds(){ /// ========= In the worker function ========= /// -// CK1: define internal void @__omp_offloading_{{.*}}test_ds{{.*}}worker(){{.*}}{ +// CK1: define internal void @__omp_offloading_{{.*}}test_ds{{.*}}worker() [[ATTR1:#.*]] { // CK1: [[SHAREDARGS:%.+]] = alloca i8** // CK1: call i1 @__kmpc_kernel_parallel(i8** %work_fn, i8*** [[SHAREDARGS]]) // CK1: [[SHARGSTMP:%.+]] = load i8**, i8*** [[SHAREDARGS]] @@ -30,7 +30,7 @@ void test_ds(){ /// ========= In the kernel function ========= /// -// CK1: {{.*}}define void @__omp_offloading{{.*}}test_ds{{.*}}() +// CK1: {{.*}}define void @__omp_offloading{{.*}}test_ds{{.*}}() [[ATTR2:#.*]] { // CK1: [[SHAREDARGS1:%.+]] = alloca i8** // CK1: call void @__kmpc_kernel_prepare_parallel({{.*}}, i8*** [[SHAREDARGS1]], i32 1) // CK1: [[SHARGSTMP1:%.+]] = load i8**, i8*** [[SHAREDARGS1]] @@ -40,7 +40,7 @@ void test_ds(){ /// ========= In the data sharing wrapper function ========= /// -// CK1: {{.*}}define internal void @__omp_outlined___wrapper({{.*}}i8**){{.*}}{ +// CK1: {{.*}}define internal void @__omp_outlined___wrapper({{.*}}i8**) [[ATTR1]] { // CK1: [[SHAREDARGS2:%.+]] = alloca i8** // CK1: store i8** %2, i8*** [[SHAREDARGS2]] // CK1: [[SHARGSTMP3:%.+]] = load i8**, i8*** [[SHAREDARGS2]] @@ -49,4 +49,9 @@ void test_ds(){ // CK1: [[SHARGSTMP6:%.+]] = load i32*, i32** [[SHARGSTMP5]] // CK1: call void @__omp_outlined__({{.*}}, i32* [[SHARGSTMP6]]) +/// ========= Attributes ========= /// + +// CK1-NOT: attributes [[ATTR1]] = { {{.*}}"has-nvptx-shared-depot"{{.*}} } +// CK1: attributes [[ATTR2]] = { {{.*}}"has-nvptx-shared-depot"{{.*}} } + #endif