diff options
author | Carlo Bertolli <cbertol@us.ibm.com> | 2016-04-29 01:37:30 +0000 |
---|---|---|
committer | Carlo Bertolli <cbertol@us.ibm.com> | 2016-04-29 01:37:30 +0000 |
commit | feeacac15e9542b891ed4817b333690e558a144d (patch) | |
tree | be00f0cdd712a688ea5fdd9f38d6c0fe2f992b26 | |
parent | e99495409435826c17a0e58fa3caedf3e350489b (diff) |
[OPENMP] Enable correct generation of runtime call when target directive is separated from teams directive by multiple curly brackets
http://reviews.llvm.org/D18474
This patch fixes a bug in code generation of the correct OpenMP runtime library call in presence of target and teams, when target is separated by teams with multiple curly brackets. The current implementation will not be able to see the teams directive inside target and issue a call to tgt_target instead of the correct one tgt_target_teams.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267972 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGOpenMPRuntime.cpp | 14 | ||||
-rw-r--r-- | test/OpenMP/teams_codegen.cpp | 10 |
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index 70057551d9..b280d53dd3 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -4556,6 +4556,14 @@ void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper( DeviceID, FileID, ParentName, Line, OutlinedFn, OutlinedFnID); } +/// discard all CompoundStmts intervening between two constructs +static const Stmt *ignoreCompoundStmts(const Stmt *Body) { + while (auto *CS = dyn_cast_or_null<CompoundStmt>(Body)) + Body = CS->body_front(); + + return Body; +} + /// \brief Emit the num_teams clause of an enclosed teams directive at the /// target region scope. If there is no teams directive associated with the /// target directive, or if there is no num_teams clause associated with the @@ -4586,7 +4594,8 @@ emitNumTeamsClauseForTargetDirective(CGOpenMPRuntime &OMPRuntime, // FIXME: Accommodate other combined directives with teams when they become // available. - if (auto *TeamsDir = dyn_cast<OMPTeamsDirective>(CS.getCapturedStmt())) { + if (auto *TeamsDir = dyn_cast_or_null<OMPTeamsDirective>( + ignoreCompoundStmts(CS.getCapturedStmt()))) { if (auto *NTE = TeamsDir->getSingleClause<OMPNumTeamsClause>()) { CGOpenMPInnerExprInfo CGInfo(CGF, CS); CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo); @@ -4634,7 +4643,8 @@ emitThreadLimitClauseForTargetDirective(CGOpenMPRuntime &OMPRuntime, // FIXME: Accommodate other combined directives with teams when they become // available. - if (auto *TeamsDir = dyn_cast<OMPTeamsDirective>(CS.getCapturedStmt())) { + if (auto *TeamsDir = dyn_cast_or_null<OMPTeamsDirective>( + ignoreCompoundStmts(CS.getCapturedStmt()))) { if (auto *TLE = TeamsDir->getSingleClause<OMPThreadLimitClause>()) { CGOpenMPInnerExprInfo CGInfo(CGF, CS); CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo); diff --git a/test/OpenMP/teams_codegen.cpp b/test/OpenMP/teams_codegen.cpp index 1d616c3781..c26b586257 100644 --- a/test/OpenMP/teams_codegen.cpp +++ b/test/OpenMP/teams_codegen.cpp @@ -29,6 +29,16 @@ int teams_argument_global_local(int a){ ++comp; } + // CK1: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0) + // CK1: call void @{{.+}}(i{{64|32}} %{{.+}}) + #pragma omp target + {{{ + #pragma omp teams + { + ++comp; + } + }}} + // CK1-DAG: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 [[NT:%[^,]+]], i32 0) // CK1-DAG: [[NT]] = load i32, i32* [[NTA:%[^,]+]], |