r295335 - [OpenMP] Teams reduction on the NVPTX device.

2017-02-16 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Feb 16 10:48:49 2017
New Revision: 295335

URL: http://llvm.org/viewvc/llvm-project?rev=295335=rev
Log:
[OpenMP] Teams reduction on the NVPTX device.

This patch implements codegen for the reduction clause on
any teams construct for elementary data types.  It builds
on parallel reductions on the GPU.  Subsequently,
the team master writes to a unique location in a global
memory scratchpad.  The last team to do so loads and
reduces this array to calculate the final result.

This patch emits two helper functions that are used by
the OpenMP runtime on the GPU to perform reductions across
teams.

Patch by Tian Jin in collaboration with Arpith Jacob

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29879

Added:
cfe/trunk/test/OpenMP/nvptx_teams_reduction_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=295335=295334=295335=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Thu Feb 16 10:48:49 2017
@@ -56,6 +56,16 @@ enum OpenMPRTLFunctionNVPTX {
   /// lane_offset, int16_t shortCircuit),
   /// void (*kmp_InterWarpCopyFctPtr)(void* src, int32_t warp_num));
   OMPRTL_NVPTX__kmpc_parallel_reduce_nowait,
+  /// \brief Call to __kmpc_nvptx_teams_reduce_nowait(int32_t global_tid,
+  /// int32_t num_vars, size_t reduce_size, void *reduce_data,
+  /// void (*kmp_ShuffleReductFctPtr)(void *rhs, int16_t lane_id, int16_t
+  /// lane_offset, int16_t shortCircuit),
+  /// void (*kmp_InterWarpCopyFctPtr)(void* src, int32_t warp_num),
+  /// void (*kmp_CopyToScratchpadFctPtr)(void *reduce_data, void * scratchpad,
+  /// int32_t index, int32_t width),
+  /// void (*kmp_LoadReduceFctPtr)(void *reduce_data, void * scratchpad, 
int32_t
+  /// index, int32_t width, int32_t reduce))
+  OMPRTL_NVPTX__kmpc_teams_reduce_nowait,
   /// \brief Call to __kmpc_nvptx_end_reduce_nowait(int32_t global_tid);
   OMPRTL_NVPTX__kmpc_end_reduce_nowait
 };
@@ -125,6 +135,9 @@ enum MachineConfiguration : unsigned {
   /// computed as log_2(WarpSize).
   LaneIDBits = 5,
   LaneIDMask = WarpSize - 1,
+
+  /// Global memory alignment for performance.
+  GlobalMemoryAlignment = 256,
 };
 
 enum NamedBarrier : unsigned {
@@ -694,6 +707,49 @@ CGOpenMPRuntimeNVPTX::createNVPTXRuntime
 FnTy, /*Name=*/"__kmpc_nvptx_parallel_reduce_nowait");
 break;
   }
+  case OMPRTL_NVPTX__kmpc_teams_reduce_nowait: {
+// Build int32_t __kmpc_nvptx_teams_reduce_nowait(int32_t global_tid,
+// int32_t num_vars, size_t reduce_size, void *reduce_data,
+// void (*kmp_ShuffleReductFctPtr)(void *rhsData, int16_t lane_id, int16_t
+// lane_offset, int16_t shortCircuit),
+// void (*kmp_InterWarpCopyFctPtr)(void* src, int32_t warp_num),
+// void (*kmp_CopyToScratchpadFctPtr)(void *reduce_data, void * scratchpad,
+// int32_t index, int32_t width),
+// void (*kmp_LoadReduceFctPtr)(void *reduce_data, void * scratchpad,
+// int32_t index, int32_t width, int32_t reduce))
+llvm::Type *ShuffleReduceTypeParams[] = {CGM.VoidPtrTy, CGM.Int16Ty,
+ CGM.Int16Ty, CGM.Int16Ty};
+auto *ShuffleReduceFnTy =
+llvm::FunctionType::get(CGM.VoidTy, ShuffleReduceTypeParams,
+/*isVarArg=*/false);
+llvm::Type *InterWarpCopyTypeParams[] = {CGM.VoidPtrTy, CGM.Int32Ty};
+auto *InterWarpCopyFnTy =
+llvm::FunctionType::get(CGM.VoidTy, InterWarpCopyTypeParams,
+/*isVarArg=*/false);
+llvm::Type *CopyToScratchpadTypeParams[] = {CGM.VoidPtrTy, CGM.VoidPtrTy,
+CGM.Int32Ty, CGM.Int32Ty};
+auto *CopyToScratchpadFnTy =
+llvm::FunctionType::get(CGM.VoidTy, CopyToScratchpadTypeParams,
+/*isVarArg=*/false);
+llvm::Type *LoadReduceTypeParams[] = {
+CGM.VoidPtrTy, CGM.VoidPtrTy, CGM.Int32Ty, CGM.Int32Ty, CGM.Int32Ty};
+auto *LoadReduceFnTy =
+llvm::FunctionType::get(CGM.VoidTy, LoadReduceTypeParams,
+/*isVarArg=*/false);
+llvm::Type *TypeParams[] = {CGM.Int32Ty,
+CGM.Int32Ty,
+CGM.SizeTy,
+CGM.VoidPtrTy,
+ShuffleReduceFnTy->getPointerTo(),
+InterWarpCopyFnTy->getPointerTo(),
+CopyToScratchpadFnTy->getPointerTo(),
+LoadReduceFnTy->getPointerTo()};
+llvm::FunctionType *FnTy =
+llvm::FunctionType::get(CGM.Int32Ty, TypeParams, /*isVarArg=*/false);
+

r295333 - [OpenMP] Parallel reduction on the NVPTX device.

2017-02-16 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Feb 16 10:20:16 2017
New Revision: 295333

URL: http://llvm.org/viewvc/llvm-project?rev=295333=rev
Log:
[OpenMP] Parallel reduction on the NVPTX device.

This patch implements codegen for the reduction clause on
any parallel construct for elementary data types.  An efficient
implementation requires hierarchical reduction within a
warp and a threadblock.  It is complicated by the fact that
variables declared in the stack of a CUDA thread cannot be
shared with other threads.

The patch creates a struct to hold reduction variables and
a number of helper functions.  The OpenMP runtime on the GPU
implements reduction algorithms that uses these helper
functions to perform reductions within a team.  Variables are
shared between CUDA threads using shuffle intrinsics.

An implementation of reductions on the NVPTX device is
substantially different to that of CPUs.  However, this patch
is written so that there are minimal changes to the rest of
OpenMP codegen.

The implemented design allows the compiler and runtime to be
decoupled, i.e., the runtime does not need to know of the
reduction operation(s), the type of the reduction variable(s),
or the number of reductions.  The design also allows reuse of
host codegen, with appropriate specialization for the NVPTX
device.

While the patch does introduce a number of abstractions, the
expected use case calls for inlining of the GPU OpenMP runtime.
After inlining and optimizations in LLVM, these abstractions
are unwound and performance of OpenMP reductions is comparable
to CUDA-canonical code.

Patch by Tian Jin in collaboration with Arpith Jacob

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29758

Added:
cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=295333=295332=295333=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Feb 16 10:20:16 2017
@@ -4257,12 +4257,10 @@ static void emitReductionCombiner(CodeGe
   CGF.EmitIgnoredExpr(ReductionOp);
 }
 
-static llvm::Value *emitReductionFunction(CodeGenModule ,
-  llvm::Type *ArgsType,
-  ArrayRef Privates,
-  ArrayRef LHSExprs,
-  ArrayRef RHSExprs,
-  ArrayRef ReductionOps) 
{
+llvm::Value *CGOpenMPRuntime::emitReductionFunction(
+CodeGenModule , llvm::Type *ArgsType, ArrayRef Privates,
+ArrayRef LHSExprs, ArrayRef RHSExprs,
+ArrayRef ReductionOps) {
   auto  = CGM.getContext();
 
   // void reduction_func(void *LHSArg, void *RHSArg);
@@ -4345,11 +4343,11 @@ static llvm::Value *emitReductionFunctio
   return Fn;
 }
 
-static void emitSingleReductionCombiner(CodeGenFunction ,
-const Expr *ReductionOp,
-const Expr *PrivateRef,
-const DeclRefExpr *LHS,
-const DeclRefExpr *RHS) {
+void CGOpenMPRuntime::emitSingleReductionCombiner(CodeGenFunction ,
+  const Expr *ReductionOp,
+  const Expr *PrivateRef,
+  const DeclRefExpr *LHS,
+  const DeclRefExpr *RHS) {
   if (PrivateRef->getType()->isArrayType()) {
 // Emit reduction for array section.
 auto *LHSVar = cast(LHS->getDecl());
@@ -4369,9 +4367,13 @@ void CGOpenMPRuntime::emitReduction(Code
 ArrayRef LHSExprs,
 ArrayRef RHSExprs,
 ArrayRef ReductionOps,
-bool WithNowait, bool SimpleReduction) {
+ReductionOptionsTy Options) {
   if (!CGF.HaveInsertPoint())
 return;
+
+  bool WithNowait = Options.WithNowait;
+  bool SimpleReduction = Options.SimpleReduction;
+
   // Next code should be emitted for reduction:
   //
   // static kmp_critical_name lock = { 0 };
@@ -4513,12 +4515,13 @@ void CGOpenMPRuntime::emitReduction(Code
   };
   auto & = [, , , ](
   CodeGenFunction , PrePostActionTy ) {
+auto  = CGF.CGM.getOpenMPRuntime();
 auto IPriv = Privates.begin();
 auto ILHS = LHSExprs.begin();
 auto 

r295323 - Revert r295319 while investigating buildbot failure.

2017-02-16 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Feb 16 08:25:35 2017
New Revision: 295323

URL: http://llvm.org/viewvc/llvm-project?rev=295323=rev
Log:
Revert r295319 while investigating buildbot failure.

Removed:
cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=295323=295322=295323=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Feb 16 08:25:35 2017
@@ -4257,10 +4257,12 @@ static void emitReductionCombiner(CodeGe
   CGF.EmitIgnoredExpr(ReductionOp);
 }
 
-llvm::Value *CGOpenMPRuntime::emitReductionFunction(
-CodeGenModule , llvm::Type *ArgsType, ArrayRef Privates,
-ArrayRef LHSExprs, ArrayRef RHSExprs,
-ArrayRef ReductionOps) {
+static llvm::Value *emitReductionFunction(CodeGenModule ,
+  llvm::Type *ArgsType,
+  ArrayRef Privates,
+  ArrayRef LHSExprs,
+  ArrayRef RHSExprs,
+  ArrayRef ReductionOps) 
{
   auto  = CGM.getContext();
 
   // void reduction_func(void *LHSArg, void *RHSArg);
@@ -4343,11 +4345,11 @@ llvm::Value *CGOpenMPRuntime::emitReduct
   return Fn;
 }
 
-void CGOpenMPRuntime::emitSingleReductionCombiner(CodeGenFunction ,
-  const Expr *ReductionOp,
-  const Expr *PrivateRef,
-  const DeclRefExpr *LHS,
-  const DeclRefExpr *RHS) {
+static void emitSingleReductionCombiner(CodeGenFunction ,
+const Expr *ReductionOp,
+const Expr *PrivateRef,
+const DeclRefExpr *LHS,
+const DeclRefExpr *RHS) {
   if (PrivateRef->getType()->isArrayType()) {
 // Emit reduction for array section.
 auto *LHSVar = cast(LHS->getDecl());
@@ -4367,13 +4369,9 @@ void CGOpenMPRuntime::emitReduction(Code
 ArrayRef LHSExprs,
 ArrayRef RHSExprs,
 ArrayRef ReductionOps,
-ReductionOptionsTy Options) {
+bool WithNowait, bool SimpleReduction) {
   if (!CGF.HaveInsertPoint())
 return;
-
-  bool WithNowait = Options.WithNowait;
-  bool SimpleReduction = Options.SimpleReduction;
-
   // Next code should be emitted for reduction:
   //
   // static kmp_critical_name lock = { 0 };
@@ -4515,13 +4513,12 @@ void CGOpenMPRuntime::emitReduction(Code
   };
   auto & = [, , , ](
   CodeGenFunction , PrePostActionTy ) {
-auto  = CGF.CGM.getOpenMPRuntime();
 auto IPriv = Privates.begin();
 auto ILHS = LHSExprs.begin();
 auto IRHS = RHSExprs.begin();
 for (auto *E : ReductionOps) {
-  RT.emitSingleReductionCombiner(CGF, E, *IPriv, cast(*ILHS),
- cast(*IRHS));
+  emitSingleReductionCombiner(CGF, E, *IPriv, cast(*ILHS),
+  cast(*IRHS));
   ++IPriv;
   ++ILHS;
   ++IRHS;

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=295323=295322=295323=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Thu Feb 16 08:25:35 2017
@@ -893,32 +893,6 @@ public:
 OpenMPDirectiveKind InnermostKind,
 const RegionCodeGenTy ,
 bool HasCancel = false);
-
-  /// Emits reduction function.
-  /// \param ArgsType Array type containing pointers to reduction variables.
-  /// \param Privates List of private copies for original reduction arguments.
-  /// \param LHSExprs List of LHS in \a ReductionOps reduction operations.
-  /// \param RHSExprs List of RHS in \a ReductionOps reduction operations.
-  /// \param ReductionOps List of reduction operations in form 'LHS binop RHS'
-  /// or 'operator binop(LHS, RHS)'.
-  llvm::Value *emitReductionFunction(CodeGenModule , llvm::Type *ArgsType,
- ArrayRef Privates,

r295319 - [OpenMP] Parallel reduction on the NVPTX device.

2017-02-16 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Feb 16 08:03:36 2017
New Revision: 295319

URL: http://llvm.org/viewvc/llvm-project?rev=295319=rev
Log:
[OpenMP] Parallel reduction on the NVPTX device.

This patch implements codegen for the reduction clause on
any parallel construct for elementary data types.  An efficient
implementation requires hierarchical reduction within a
warp and a threadblock.  It is complicated by the fact that
variables declared in the stack of a CUDA thread cannot be
shared with other threads.

The patch creates a struct to hold reduction variables and
a number of helper functions.  The OpenMP runtime on the GPU
implements reduction algorithms that uses these helper
functions to perform reductions within a team.  Variables are
shared between CUDA threads using shuffle intrinsics.

An implementation of reductions on the NVPTX device is
substantially different to that of CPUs.  However, this patch
is written so that there are minimal changes to the rest of
OpenMP codegen.

The implemented design allows the compiler and runtime to be
decoupled, i.e., the runtime does not need to know of the
reduction operation(s), the type of the reduction variable(s),
or the number of reductions.  The design also allows reuse of
host codegen, with appropriate specialization for the NVPTX
device.

While the patch does introduce a number of abstractions, the
expected use case calls for inlining of the GPU OpenMP runtime.
After inlining and optimizations in LLVM, these abstractions
are unwound and performance of OpenMP reductions is comparable
to CUDA-canonical code.

Patch by Tian Jin in collaboration with Arpith Jacob

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29758

Added:
cfe/trunk/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=295319=295318=295319=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Feb 16 08:03:36 2017
@@ -4257,12 +4257,10 @@ static void emitReductionCombiner(CodeGe
   CGF.EmitIgnoredExpr(ReductionOp);
 }
 
-static llvm::Value *emitReductionFunction(CodeGenModule ,
-  llvm::Type *ArgsType,
-  ArrayRef Privates,
-  ArrayRef LHSExprs,
-  ArrayRef RHSExprs,
-  ArrayRef ReductionOps) 
{
+llvm::Value *CGOpenMPRuntime::emitReductionFunction(
+CodeGenModule , llvm::Type *ArgsType, ArrayRef Privates,
+ArrayRef LHSExprs, ArrayRef RHSExprs,
+ArrayRef ReductionOps) {
   auto  = CGM.getContext();
 
   // void reduction_func(void *LHSArg, void *RHSArg);
@@ -4345,11 +4343,11 @@ static llvm::Value *emitReductionFunctio
   return Fn;
 }
 
-static void emitSingleReductionCombiner(CodeGenFunction ,
-const Expr *ReductionOp,
-const Expr *PrivateRef,
-const DeclRefExpr *LHS,
-const DeclRefExpr *RHS) {
+void CGOpenMPRuntime::emitSingleReductionCombiner(CodeGenFunction ,
+  const Expr *ReductionOp,
+  const Expr *PrivateRef,
+  const DeclRefExpr *LHS,
+  const DeclRefExpr *RHS) {
   if (PrivateRef->getType()->isArrayType()) {
 // Emit reduction for array section.
 auto *LHSVar = cast(LHS->getDecl());
@@ -4369,9 +4367,13 @@ void CGOpenMPRuntime::emitReduction(Code
 ArrayRef LHSExprs,
 ArrayRef RHSExprs,
 ArrayRef ReductionOps,
-bool WithNowait, bool SimpleReduction) {
+ReductionOptionsTy Options) {
   if (!CGF.HaveInsertPoint())
 return;
+
+  bool WithNowait = Options.WithNowait;
+  bool SimpleReduction = Options.SimpleReduction;
+
   // Next code should be emitted for reduction:
   //
   // static kmp_critical_name lock = { 0 };
@@ -4513,12 +4515,13 @@ void CGOpenMPRuntime::emitReduction(Code
   };
   auto & = [, , , ](
   CodeGenFunction , PrePostActionTy ) {
+auto  = CGF.CGM.getOpenMPRuntime();
 auto IPriv = Privates.begin();
 auto ILHS = LHSExprs.begin();
 auto 

r293444 - [OpenMP][NVPTX][CUDA] Adding support for printf for an NVPTX OpenMP device.

2017-01-29 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Sun Jan 29 14:49:31 2017
New Revision: 293444

URL: http://llvm.org/viewvc/llvm-project?rev=293444=rev
Log:
[OpenMP][NVPTX][CUDA] Adding support for printf for an NVPTX OpenMP device.

Support for CUDA printf is exploited to support printf for
an NVPTX OpenMP device.

To reflect the support of both programming models, the file
CGCUDABuiltin.cpp has been renamed to CGGPUBuiltin.cpp, and
the call EmitCUDADevicePrintfCallExpr has been renamed to
EmitGPUDevicePrintfCallExpr.

Reviewers: jlebar
Differential Revision: https://reviews.llvm.org/D17890

Added:
cfe/trunk/lib/CodeGen/CGGPUBuiltin.cpp
  - copied, changed from r293443, cfe/trunk/lib/CodeGen/CGCUDABuiltin.cpp
cfe/trunk/test/OpenMP/nvptx_target_printf_codegen.c
Removed:
cfe/trunk/lib/CodeGen/CGCUDABuiltin.cpp
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CMakeLists.txt
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=293444=293443=293444=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sun Jan 29 14:49:31 2017
@@ -2620,8 +2620,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 Arg));
   }
   case Builtin::BIprintf:
-if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice)
-  return EmitCUDADevicePrintfCallExpr(E, ReturnValue);
+if (getTarget().getTriple().isNVPTX())
+  return EmitNVPTXDevicePrintfCallExpr(E, ReturnValue);
 break;
   case Builtin::BI__builtin_canonicalize:
   case Builtin::BI__builtin_canonicalizef:

Removed: cfe/trunk/lib/CodeGen/CGCUDABuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCUDABuiltin.cpp?rev=293443=auto
==
--- cfe/trunk/lib/CodeGen/CGCUDABuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCUDABuiltin.cpp (removed)
@@ -1,123 +0,0 @@
-//===- CGCUDABuiltin.cpp - Codegen for CUDA builtins 
--===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-//
-// Generates code for built-in CUDA calls which are not runtime-specific.
-// (Runtime-specific codegen lives in CGCUDARuntime.)
-//
-//===--===//
-
-#include "CodeGenFunction.h"
-#include "clang/Basic/Builtins.h"
-#include "llvm/IR/DataLayout.h"
-#include "llvm/IR/Instruction.h"
-#include "llvm/Support/MathExtras.h"
-
-using namespace clang;
-using namespace CodeGen;
-
-static llvm::Function *GetVprintfDeclaration(llvm::Module ) {
-  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
-llvm::Type::getInt8PtrTy(M.getContext())};
-  llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
-  llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
-
-  if (auto* F = M.getFunction("vprintf")) {
-// Our CUDA system header declares vprintf with the right signature, so
-// nobody else should have been able to declare vprintf with a bogus
-// signature.
-assert(F->getFunctionType() == VprintfFuncType);
-return F;
-  }
-
-  // vprintf doesn't already exist; create a declaration and insert it into the
-  // module.
-  return llvm::Function::Create(
-  VprintfFuncType, llvm::GlobalVariable::ExternalLinkage, "vprintf", );
-}
-
-// Transforms a call to printf into a call to the NVPTX vprintf syscall (which
-// isn't particularly special; it's invoked just like a regular function).
-// vprintf takes two args: A format string, and a pointer to a buffer 
containing
-// the varargs.
-//
-// For example, the call
-//
-//   printf("format string", arg1, arg2, arg3);
-//
-// is converted into something resembling
-//
-//   struct Tmp {
-// Arg1 a1;
-// Arg2 a2;
-// Arg3 a3;
-//   };
-//   char* buf = alloca(sizeof(Tmp));
-//   *(Tmp*)buf = {a1, a2, a3};
-//   vprintf("format string", buf);
-//
-// buf is aligned to the max of {alignof(Arg1), ...}.  Furthermore, each of the
-// args is itself aligned to its preferred alignment.
-//
-// Note that by the time this function runs, E's args have already undergone 
the
-// standard C vararg promotion (short -> int, float -> double, etc.).
-RValue
-CodeGenFunction::EmitCUDADevicePrintfCallExpr(const CallExpr *E,
-  ReturnValueSlot ReturnValue) {
-  assert(getLangOpts().CUDA);
-  assert(getLangOpts().CUDAIsDevice);
-  assert(E->getBuiltinCallee() == Builtin::BIprintf);
-  assert(E->getNumArgs() >= 1); // printf always has at least one arg.
-
-  const llvm::DataLayout  = CGM.getDataLayout();
-  

r293183 - [OpenMP] Codegen support for 'target teams' on the NVPTX device.

2017-01-26 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Jan 26 09:43:27 2017
New Revision: 293183

URL: http://llvm.org/viewvc/llvm-project?rev=293183=rev
Log:
[OpenMP] Codegen support for 'target teams' on the NVPTX device.

This is a simple patch to teach OpenMP codegen to emit the construct
in Generic mode.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29143

Added:
cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=293183=293182=293183=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Thu Jan 26 09:43:27 2017
@@ -198,6 +198,7 @@ getExecutionModeForDirective(CodeGenModu
   OpenMPDirectiveKind DirectiveKind = D.getDirectiveKind();
   switch (DirectiveKind) {
   case OMPD_target:
+  case OMPD_target_teams:
 return CGOpenMPRuntimeNVPTX::ExecutionMode::Generic;
   case OMPD_target_parallel:
 return CGOpenMPRuntimeNVPTX::ExecutionMode::Spmd;

Added: cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp?rev=293183=auto
==
--- cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp (added)
+++ cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp Thu Jan 26 09:43:27 
2017
@@ -0,0 +1,222 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix 
CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386-unknown-unknown 
-fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx-unknown-unknown 
-fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix 
CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -verify -fopenmp -fexceptions -fcxx-exceptions -x c++ 
-triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck 
%s --check-prefix CHECK --check-prefix CHECK-32
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// Check that the execution mode of all 2 target regions is set to Generic 
Mode.
+// CHECK-DAG: {{@__omp_offloading_.+l26}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l31}}_exec_mode = weak constant i8 1
+
+template
+tx ftemplate(int n) {
+  tx a = 0;
+  short aa = 0;
+  tx b[10];
+
+  #pragma omp target teams if(0)
+  {
+b[2] += 1;
+  }
+
+  #pragma omp target teams if(1)
+  {
+a = '1';
+  }
+
+  #pragma omp target teams if(n>40)
+  {
+aa = 1;
+  }
+
+  return a;
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+  // CHECK-NOT: define {{.*}}void 
{{@__omp_offloading_.+template.+l21}}_worker()
+
+
+
+
+
+
+  // CHECK-LABEL: define {{.*}}void 
{{@__omp_offloading_.+template.+l26}}_worker()
+  // CHECK-DAG: [[OMP_EXEC_STATUS:%.+]] = alloca i8,
+  // CHECK-DAG: [[OMP_WORK_FN:%.+]] = alloca i8*,
+  // CHECK: store i8* null, i8** [[OMP_WORK_FN]],
+  // CHECK: store i8 0, i8* [[OMP_EXEC_STATUS]],
+  // CHECK: br label {{%?}}[[AWAIT_WORK:.+]]
+  //
+  // CHECK: [[AWAIT_WORK]]
+  // CHECK: call void @llvm.nvvm.barrier0()
+  // CHECK: [[KPR:%.+]] = call i1 @__kmpc_kernel_parallel(i8** [[OMP_WORK_FN]])
+  // CHECK: [[KPRB:%.+]] = zext i1 [[KPR]] to i8
+  // store i8 [[KPRB]], i8* [[OMP_EXEC_STATUS]], align 1
+  // CHECK: [[WORK:%.+]] = load i8*, i8** [[OMP_WORK_FN]],
+  // CHECK: [[SHOULD_EXIT:%.+]] = icmp eq i8* [[WORK]], null
+  // CHECK: br i1 [[SHOULD_EXIT]], label {{%?}}[[EXIT:.+]], label 
{{%?}}[[SEL_WORKERS:.+]]
+  //
+  // CHECK: [[SEL_WORKERS]]
+  // CHECK: [[ST:%.+]] = load i8, i8* [[OMP_EXEC_STATUS]]
+  // CHECK: [[IS_ACTIVE:%.+]] = icmp ne i8 [[ST]], 0
+  // CHECK: br i1 [[IS_ACTIVE]], label {{%?}}[[EXEC_PARALLEL:.+]], label 
{{%?}}[[BAR_PARALLEL:.+]]
+  //
+  // CHECK: [[EXEC_PARALLEL]]
+  // CHECK: br label {{%?}}[[TERM_PARALLEL:.+]]
+  //
+  // CHECK: [[TERM_PARALLEL]]
+  // CHECK: call void @__kmpc_kernel_end_parallel()
+  // CHECK: br label {{%?}}[[BAR_PARALLEL]]
+  //
+  // CHECK: [[BAR_PARALLEL]]
+  // CHECK: call void @llvm.nvvm.barrier0()
+  // CHECK: br label {{%?}}[[AWAIT_WORK]]
+  //
+  // CHECK: [[EXIT]]
+  // CHECK: ret void
+
+  

r293069 - [OpenMP] Support for the proc_bind-clause on 'target parallel' on the NVPTX device.

2017-01-25 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan 25 10:55:10 2017
New Revision: 293069

URL: http://llvm.org/viewvc/llvm-project?rev=293069=rev
Log:
[OpenMP] Support for the proc_bind-clause on 'target parallel' on the NVPTX 
device.

This patch adds support for the proc_bind clause on the Spmd construct
'target parallel' on the NVPTX device.  Since the parallel region is created
upon kernel launch, this clause can be safely ignored on the NVPTX device at
codegen time for level 0 parallelism.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29128

Added:
cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=293069=293068=293069=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Wed Jan 25 10:55:10 2017
@@ -642,6 +642,17 @@ CGOpenMPRuntimeNVPTX::CGOpenMPRuntimeNVP
 llvm_unreachable("OpenMP NVPTX can only handle device code.");
 }
 
+void CGOpenMPRuntimeNVPTX::emitProcBindClause(CodeGenFunction ,
+  OpenMPProcBindClauseKind 
ProcBind,
+  SourceLocation Loc) {
+  // Do nothing in case of Spmd mode and L0 parallel.
+  // TODO: If in Spmd mode and L1 parallel emit the clause.
+  if (isInSpmdExecutionMode())
+return;
+
+  CGOpenMPRuntime::emitProcBindClause(CGF, ProcBind, Loc);
+}
+
 void CGOpenMPRuntimeNVPTX::emitNumThreadsClause(CodeGenFunction ,
 llvm::Value *NumThreads,
 SourceLocation Loc) {

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h?rev=293069=293068=293069=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h Wed Jan 25 10:55:10 2017
@@ -170,6 +170,12 @@ protected:
 public:
   explicit CGOpenMPRuntimeNVPTX(CodeGenModule );
 
+  /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
+  /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
+  virtual void emitProcBindClause(CodeGenFunction ,
+  OpenMPProcBindClauseKind ProcBind,
+  SourceLocation Loc) override;
+
   /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
   /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
   /// clause.

Added: cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp?rev=293069=auto
==
--- cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp (added)
+++ cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp Wed Jan 
25 10:55:10 2017
@@ -0,0 +1,106 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc 
%s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck 
%s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o 
%t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck 
%s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -fexceptions 
-fcxx-exceptions -x c++ -triple nvptx-unknown-unknown 
-fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix 
CHECK --check-prefix CHECK-32
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// Check that the execution mode of all 3 target regions on the gpu is set to 
SPMD Mode.
+// CHECK-DAG: {{@__omp_offloading_.+l22}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l26}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l31}}_exec_mode 

r293049 - [OpenMP] Support for thread_limit-clause on the 'target teams' directive.

2017-01-25 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan 25 05:44:35 2017
New Revision: 293049

URL: http://llvm.org/viewvc/llvm-project?rev=293049=rev
Log:
[OpenMP] Support for thread_limit-clause on the 'target teams' directive.

The thread_limit-clause on the combined directive applies to the
'teams' region of this construct. We modify the ThreadLimitClause
class to capture the clause expression within the 'target' region.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29087

Added:
cfe/trunk/test/OpenMP/target_teams_thread_limit_codegen.cpp
Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=293049=293048=293049=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Wed Jan 25 05:44:35 2017
@@ -3541,7 +3541,7 @@ public:
 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
 /// with single expression 'n'.
 ///
-class OMPThreadLimitClause : public OMPClause {
+class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
   friend class OMPClauseReader;
   /// \brief Location of '('.
   SourceLocation LParenLoc;
@@ -3557,20 +3557,28 @@ public:
   /// \brief Build 'thread_limit' clause.
   ///
   /// \param E Expression associated with this clause.
+  /// \param HelperE Helper Expression associated with this clause.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
   ///
-  OMPThreadLimitClause(Expr *E, SourceLocation StartLoc,
-   SourceLocation LParenLoc, SourceLocation EndLoc)
-  : OMPClause(OMPC_thread_limit, StartLoc, EndLoc), LParenLoc(LParenLoc),
-ThreadLimit(E) {}
+  OMPThreadLimitClause(Expr *E, Stmt *HelperE,
+   OpenMPDirectiveKind CaptureRegion,
+   SourceLocation StartLoc, SourceLocation LParenLoc,
+   SourceLocation EndLoc)
+  : OMPClause(OMPC_thread_limit, StartLoc, EndLoc),
+OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
+setPreInitStmt(HelperE, CaptureRegion);
+  }
 
   /// \brief Build an empty clause.
   ///
   OMPThreadLimitClause()
   : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
-LParenLoc(SourceLocation()), ThreadLimit(nullptr) {}
+OMPClauseWithPreInit(this), LParenLoc(SourceLocation()),
+ThreadLimit(nullptr) {}
   /// \brief Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   /// \brief Returns the location of '('.

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=293049=293048=293049=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Wed Jan 25 05:44:35 2017
@@ -3003,6 +3003,7 @@ bool RecursiveASTVisitor::Visit
 template 
 bool RecursiveASTVisitor::VisitOMPThreadLimitClause(
 OMPThreadLimitClause *C) {
+  TRY_TO(VisitOMPClauseWithPreInit(C));
   TRY_TO(TraverseStmt(C->getThreadLimit()));
   return true;
 }

Modified: cfe/trunk/lib/AST/OpenMPClause.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OpenMPClause.cpp?rev=293049=293048=293049=diff
==
--- cfe/trunk/lib/AST/OpenMPClause.cpp (original)
+++ cfe/trunk/lib/AST/OpenMPClause.cpp Wed Jan 25 05:44:35 2017
@@ -54,6 +54,8 @@ const OMPClauseWithPreInit *OMPClauseWit
 return static_cast(C);
   case OMPC_num_teams:
 return static_cast(C);
+  case OMPC_thread_limit:
+return static_cast(C);
   case OMPC_default:
   case OMPC_proc_bind:
   case OMPC_final:
@@ -81,7 +83,6 @@ const OMPClauseWithPreInit *OMPClauseWit
   case OMPC_threads:
   case OMPC_simd:
   case OMPC_map:
-  case OMPC_thread_limit:
   case OMPC_priority:
   case OMPC_grainsize:
   case OMPC_nogroup:

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=293049=293048=293049=diff
==
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ 

r293048 - [OpenMP] Support for num_teams-clause on the 'target teams' directive.

2017-01-25 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan 25 05:28:18 2017
New Revision: 293048

URL: http://llvm.org/viewvc/llvm-project?rev=293048=rev
Log:
[OpenMP] Support for num_teams-clause on the 'target teams' directive.

The num_teams-clause on the combined directive applies to the
'teams' region of this construct. We modify the NumTeamsClause
class to capture the clause expression within the 'target' region.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29085

Added:
cfe/trunk/test/OpenMP/target_teams_num_teams_codegen.cpp
Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=293048=293047=293048=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Wed Jan 25 05:28:18 2017
@@ -3479,7 +3479,7 @@ public:
 /// In this example directive '#pragma omp teams' has clause 'num_teams'
 /// with single expression 'n'.
 ///
-class OMPNumTeamsClause : public OMPClause {
+class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
   friend class OMPClauseReader;
   /// \brief Location of '('.
   SourceLocation LParenLoc;
@@ -3495,20 +3495,27 @@ public:
   /// \brief Build 'num_teams' clause.
   ///
   /// \param E Expression associated with this clause.
+  /// \param HelperE Helper Expression associated with this clause.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
   ///
-  OMPNumTeamsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
+  OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
+SourceLocation StartLoc, SourceLocation LParenLoc,
 SourceLocation EndLoc)
-  : OMPClause(OMPC_num_teams, StartLoc, EndLoc), LParenLoc(LParenLoc), 
-NumTeams(E) {}
+  : OMPClause(OMPC_num_teams, StartLoc, EndLoc), 
OMPClauseWithPreInit(this),
+LParenLoc(LParenLoc), NumTeams(E) {
+setPreInitStmt(HelperE, CaptureRegion);
+  }
 
   /// \brief Build an empty clause.
   ///
   OMPNumTeamsClause()
-  : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()), 
-LParenLoc(SourceLocation()), NumTeams(nullptr) {}
+  : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
+OMPClauseWithPreInit(this), LParenLoc(SourceLocation()),
+NumTeams(nullptr) {}
   /// \brief Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   /// \brief Returns the location of '('.

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=293048=293047=293048=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Wed Jan 25 05:28:18 2017
@@ -2995,6 +2995,7 @@ bool RecursiveASTVisitor::Visit
 template 
 bool RecursiveASTVisitor::VisitOMPNumTeamsClause(
 OMPNumTeamsClause *C) {
+  TRY_TO(VisitOMPClauseWithPreInit(C));
   TRY_TO(TraverseStmt(C->getNumTeams()));
   return true;
 }

Modified: cfe/trunk/lib/AST/OpenMPClause.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OpenMPClause.cpp?rev=293048=293047=293048=diff
==
--- cfe/trunk/lib/AST/OpenMPClause.cpp (original)
+++ cfe/trunk/lib/AST/OpenMPClause.cpp Wed Jan 25 05:28:18 2017
@@ -52,6 +52,8 @@ const OMPClauseWithPreInit *OMPClauseWit
 return static_cast(C);
   case OMPC_num_threads:
 return static_cast(C);
+  case OMPC_num_teams:
+return static_cast(C);
   case OMPC_default:
   case OMPC_proc_bind:
   case OMPC_final:
@@ -79,7 +81,6 @@ const OMPClauseWithPreInit *OMPClauseWit
   case OMPC_threads:
   case OMPC_simd:
   case OMPC_map:
-  case OMPC_num_teams:
   case OMPC_thread_limit:
   case OMPC_priority:
   case OMPC_grainsize:

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=293048=293047=293048=diff
==
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Wed Jan 25 05:28:18 2017
@@ 

r293005 - [OpenMP] Codegen support for 'target teams' on the host.

2017-01-24 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Jan 24 20:18:43 2017
New Revision: 293005

URL: http://llvm.org/viewvc/llvm-project?rev=293005=rev
Log:
[OpenMP] Codegen support for 'target teams' on the host.

This patch adds support for codegen of 'target teams' on the host.
This combined directive has two captured statements, one for the
'teams' region, and the other for the 'parallel'.

This target teams region is offloaded using the __tgt_target_teams()
call. The patch sets the number of teams as an argument to
this call.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29084

Added:
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_codegen_registration_naming.cpp
Modified:
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=293005=293004=293005=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Tue Jan 24 20:18:43 2017
@@ -875,8 +875,11 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_parallel_sections:
 CaptureRegions.push_back(OMPD_parallel);
 break;
-  case OMPD_teams:
   case OMPD_target_teams:
+CaptureRegions.push_back(OMPD_target);
+CaptureRegions.push_back(OMPD_teams);
+break;
+  case OMPD_teams:
   case OMPD_simd:
   case OMPD_for:
   case OMPD_for_simd:

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=293005=293004=293005=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Jan 24 20:18:43 2017
@@ -4911,18 +4911,28 @@ emitNumTeamsForTargetDirective(CGOpenMPR
   "teams directive expected to be "
   "emitted only for the host!");
 
+  auto  = CGF.Builder;
+
+  // If the target directive is combined with a teams directive:
+  //   Return the value in the num_teams clause, if any.
+  //   Otherwise, return 0 to denote the runtime default.
+  if (isOpenMPTeamsDirective(D.getDirectiveKind())) {
+if (const auto *NumTeamsClause = D.getSingleClause()) {
+  CodeGenFunction::RunCleanupsScope NumTeamsScope(CGF);
+  auto NumTeams = CGF.EmitScalarExpr(NumTeamsClause->getNumTeams(),
+ /*IgnoreResultAssign*/ true);
+  return Bld.CreateIntCast(NumTeams, CGF.Int32Ty,
+   /*IsSigned=*/true);
+}
+
+// The default value is 0.
+return Bld.getInt32(0);
+  }
+
   // If the target directive is combined with a parallel directive but not a
   // teams directive, start one team.
-  if (isOpenMPParallelDirective(D.getDirectiveKind()) &&
-  !isOpenMPTeamsDirective(D.getDirectiveKind()))
-return CGF.Builder.getInt32(1);
-
-  // FIXME: For the moment we do not support combined directives with target 
and
-  // teams, so we do not expect to get any num_teams clause in the provided
-  // directive. Once we support that, this assertion can be replaced by the
-  // actual emission of the clause expression.
-  assert(D.getSingleClause() == nullptr &&
- "Not expecting clause in directive.");
+  if (isOpenMPParallelDirective(D.getDirectiveKind()))
+return Bld.getInt32(1);
 
   // If the current target region has a teams region enclosed, we need to get
   // the number of teams to pass to the runtime function call. This is done
@@ -4940,13 +4950,13 @@ emitNumTeamsForTargetDirective(CGOpenMPR
   CGOpenMPInnerExprInfo CGInfo(CGF, CS);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );
   llvm::Value *NumTeams = CGF.EmitScalarExpr(NTE->getNumTeams());
-  return CGF.Builder.CreateIntCast(NumTeams, CGF.Int32Ty,
-   /*IsSigned=*/true);
+  return Bld.CreateIntCast(NumTeams, CGF.Int32Ty,
+   /*IsSigned=*/true);
 }
 
 // If we have an enclosed teams directive but no num_teams clause we use
 // the default value 0.
-return CGF.Builder.getInt32(0);
+return Bld.getInt32(0);
   }
 
   // No teams associated with the directive.
@@ -4986,9 +4996,20 @@ emitNumThreadsForTargetDirective(CGOpenM
   //
   // If this is not a teams directive return nullptr.
 
-  if (isOpenMPParallelDirective(D.getDirectiveKind())) {
+  if (isOpenMPTeamsDirective(D.getDirectiveKind()) ||
+  isOpenMPParallelDirective(D.getDirectiveKind())) {
 llvm::Value *DefaultThreadLimitVal = Bld.getInt32(0);
 

r293003 - Reverting commit because an NVPTX patch sneaked in. Break up into two

2017-01-24 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Jan 24 19:45:59 2017
New Revision: 293003

URL: http://llvm.org/viewvc/llvm-project?rev=293003=rev
Log:
Reverting commit because an NVPTX patch sneaked in.  Break up into two
patches.

Removed:
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_codegen_registration_naming.cpp
Modified:
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=293003=293002=293003=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Tue Jan 24 19:45:59 2017
@@ -875,11 +875,8 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_parallel_sections:
 CaptureRegions.push_back(OMPD_parallel);
 break;
-  case OMPD_target_teams:
-CaptureRegions.push_back(OMPD_target);
-CaptureRegions.push_back(OMPD_teams);
-break;
   case OMPD_teams:
+  case OMPD_target_teams:
   case OMPD_simd:
   case OMPD_for:
   case OMPD_for_simd:

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=293003=293002=293003=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Jan 24 19:45:59 2017
@@ -4911,28 +4911,18 @@ emitNumTeamsForTargetDirective(CGOpenMPR
   "teams directive expected to be "
   "emitted only for the host!");
 
-  auto  = CGF.Builder;
-
-  // If the target directive is combined with a teams directive:
-  //   Return the value in the num_teams clause, if any.
-  //   Otherwise, return 0 to denote the runtime default.
-  if (isOpenMPTeamsDirective(D.getDirectiveKind())) {
-if (const auto *NumTeamsClause = D.getSingleClause()) {
-  CodeGenFunction::RunCleanupsScope NumTeamsScope(CGF);
-  auto NumTeams = CGF.EmitScalarExpr(NumTeamsClause->getNumTeams(),
- /*IgnoreResultAssign*/ true);
-  return Bld.CreateIntCast(NumTeams, CGF.Int32Ty,
-   /*IsSigned=*/true);
-}
-
-// The default value is 0.
-return Bld.getInt32(0);
-  }
-
   // If the target directive is combined with a parallel directive but not a
   // teams directive, start one team.
-  if (isOpenMPParallelDirective(D.getDirectiveKind()))
-return Bld.getInt32(1);
+  if (isOpenMPParallelDirective(D.getDirectiveKind()) &&
+  !isOpenMPTeamsDirective(D.getDirectiveKind()))
+return CGF.Builder.getInt32(1);
+
+  // FIXME: For the moment we do not support combined directives with target 
and
+  // teams, so we do not expect to get any num_teams clause in the provided
+  // directive. Once we support that, this assertion can be replaced by the
+  // actual emission of the clause expression.
+  assert(D.getSingleClause() == nullptr &&
+ "Not expecting clause in directive.");
 
   // If the current target region has a teams region enclosed, we need to get
   // the number of teams to pass to the runtime function call. This is done
@@ -4950,13 +4940,13 @@ emitNumTeamsForTargetDirective(CGOpenMPR
   CGOpenMPInnerExprInfo CGInfo(CGF, CS);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );
   llvm::Value *NumTeams = CGF.EmitScalarExpr(NTE->getNumTeams());
-  return Bld.CreateIntCast(NumTeams, CGF.Int32Ty,
-   /*IsSigned=*/true);
+  return CGF.Builder.CreateIntCast(NumTeams, CGF.Int32Ty,
+   /*IsSigned=*/true);
 }
 
 // If we have an enclosed teams directive but no num_teams clause we use
 // the default value 0.
-return Bld.getInt32(0);
+return CGF.Builder.getInt32(0);
   }
 
   // No teams associated with the directive.
@@ -4996,20 +4986,9 @@ emitNumThreadsForTargetDirective(CGOpenM
   //
   // If this is not a teams directive return nullptr.
 
-  if (isOpenMPTeamsDirective(D.getDirectiveKind()) ||
-  isOpenMPParallelDirective(D.getDirectiveKind())) {
+  if (isOpenMPParallelDirective(D.getDirectiveKind())) {
 llvm::Value *DefaultThreadLimitVal = Bld.getInt32(0);
 llvm::Value *NumThreadsVal = nullptr;
-llvm::Value *ThreadLimitVal = nullptr;
-
-if (const auto *ThreadLimitClause =
-D.getSingleClause()) {
-  CodeGenFunction::RunCleanupsScope ThreadLimitScope(CGF);
-  auto ThreadLimit = 
CGF.EmitScalarExpr(ThreadLimitClause->getThreadLimit(),
-  

r293001 - [OpenMP] Codegen support for 'target teams' on the host.

2017-01-24 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Jan 24 19:38:33 2017
New Revision: 293001

URL: http://llvm.org/viewvc/llvm-project?rev=293001=rev
Log:
[OpenMP] Codegen support for 'target teams' on the host.

This patch adds support for codegen of 'target teams' on the host.
This combined directive has two captured statements, one for the
'teams' region, and the other for the 'parallel'.

This target teams region is offloaded using the __tgt_target_teams()
call. The patch sets the number of teams as an argument to
this call.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29084

Added:
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_codegen_registration_naming.cpp
Modified:
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=293001=293000=293001=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Tue Jan 24 19:38:33 2017
@@ -875,8 +875,11 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_parallel_sections:
 CaptureRegions.push_back(OMPD_parallel);
 break;
-  case OMPD_teams:
   case OMPD_target_teams:
+CaptureRegions.push_back(OMPD_target);
+CaptureRegions.push_back(OMPD_teams);
+break;
+  case OMPD_teams:
   case OMPD_simd:
   case OMPD_for:
   case OMPD_for_simd:

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=293001=293000=293001=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Jan 24 19:38:33 2017
@@ -4911,18 +4911,28 @@ emitNumTeamsForTargetDirective(CGOpenMPR
   "teams directive expected to be "
   "emitted only for the host!");
 
+  auto  = CGF.Builder;
+
+  // If the target directive is combined with a teams directive:
+  //   Return the value in the num_teams clause, if any.
+  //   Otherwise, return 0 to denote the runtime default.
+  if (isOpenMPTeamsDirective(D.getDirectiveKind())) {
+if (const auto *NumTeamsClause = D.getSingleClause()) {
+  CodeGenFunction::RunCleanupsScope NumTeamsScope(CGF);
+  auto NumTeams = CGF.EmitScalarExpr(NumTeamsClause->getNumTeams(),
+ /*IgnoreResultAssign*/ true);
+  return Bld.CreateIntCast(NumTeams, CGF.Int32Ty,
+   /*IsSigned=*/true);
+}
+
+// The default value is 0.
+return Bld.getInt32(0);
+  }
+
   // If the target directive is combined with a parallel directive but not a
   // teams directive, start one team.
-  if (isOpenMPParallelDirective(D.getDirectiveKind()) &&
-  !isOpenMPTeamsDirective(D.getDirectiveKind()))
-return CGF.Builder.getInt32(1);
-
-  // FIXME: For the moment we do not support combined directives with target 
and
-  // teams, so we do not expect to get any num_teams clause in the provided
-  // directive. Once we support that, this assertion can be replaced by the
-  // actual emission of the clause expression.
-  assert(D.getSingleClause() == nullptr &&
- "Not expecting clause in directive.");
+  if (isOpenMPParallelDirective(D.getDirectiveKind()))
+return Bld.getInt32(1);
 
   // If the current target region has a teams region enclosed, we need to get
   // the number of teams to pass to the runtime function call. This is done
@@ -4940,13 +4950,13 @@ emitNumTeamsForTargetDirective(CGOpenMPR
   CGOpenMPInnerExprInfo CGInfo(CGF, CS);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );
   llvm::Value *NumTeams = CGF.EmitScalarExpr(NTE->getNumTeams());
-  return CGF.Builder.CreateIntCast(NumTeams, CGF.Int32Ty,
-   /*IsSigned=*/true);
+  return Bld.CreateIntCast(NumTeams, CGF.Int32Ty,
+   /*IsSigned=*/true);
 }
 
 // If we have an enclosed teams directive but no num_teams clause we use
 // the default value 0.
-return CGF.Builder.getInt32(0);
+return Bld.getInt32(0);
   }
 
   // No teams associated with the directive.
@@ -4986,9 +4996,20 @@ emitNumThreadsForTargetDirective(CGOpenM
   //
   // If this is not a teams directive return nullptr.
 
-  if (isOpenMPParallelDirective(D.getDirectiveKind())) {
+  if (isOpenMPTeamsDirective(D.getDirectiveKind()) ||
+  isOpenMPParallelDirective(D.getDirectiveKind())) {
 

r292999 - [OpenMP] Support for the num_threads-clause on 'target parallel' on the NVPTX device.

2017-01-24 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Jan 24 19:18:34 2017
New Revision: 292999

URL: http://llvm.org/viewvc/llvm-project?rev=292999=rev
Log:
[OpenMP] Support for the num_threads-clause on 'target parallel' on the NVPTX 
device.

This patch adds support for the Spmd construct 'target parallel' on the
NVPTX device. This involves ignoring the num_threads clause on the device
since the number of threads in this combined construct is already set on
the host through the call to __tgt_target_teams().

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29083

Added:
cfe/trunk/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=292999=292998=292999=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Tue Jan 24 19:18:34 2017
@@ -642,6 +642,17 @@ CGOpenMPRuntimeNVPTX::CGOpenMPRuntimeNVP
 llvm_unreachable("OpenMP NVPTX can only handle device code.");
 }
 
+void CGOpenMPRuntimeNVPTX::emitNumThreadsClause(CodeGenFunction ,
+llvm::Value *NumThreads,
+SourceLocation Loc) {
+  // Do nothing in case of Spmd mode and L0 parallel.
+  // TODO: If in Spmd mode and L1 parallel emit the clause.
+  if (isInSpmdExecutionMode())
+return;
+
+  CGOpenMPRuntime::emitNumThreadsClause(CGF, NumThreads, Loc);
+}
+
 void CGOpenMPRuntimeNVPTX::emitNumTeamsClause(CodeGenFunction ,
   const Expr *NumTeams,
   const Expr *ThreadLimit,

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h?rev=292999=292998=292999=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h Tue Jan 24 19:18:34 2017
@@ -170,6 +170,14 @@ protected:
 public:
   explicit CGOpenMPRuntimeNVPTX(CodeGenModule );
 
+  /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
+  /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
+  /// clause.
+  /// \param NumThreads An integer value of threads.
+  virtual void emitNumThreadsClause(CodeGenFunction ,
+llvm::Value *NumThreads,
+SourceLocation Loc) override;
+
   /// \brief This function ought to emit, in the general case, a call to
   // the openmp runtime kmpc_push_num_teams. In NVPTX backend it is not needed
   // as these numbers are obtained through the PTX grid and block 
configuration.

Added: cfe/trunk/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp?rev=292999=auto
==
--- cfe/trunk/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp (added)
+++ cfe/trunk/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp Tue Jan 
24 19:18:34 2017
@@ -0,0 +1,126 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc 
%s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck 
%s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o 
%t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck 
%s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -fexceptions 
-fcxx-exceptions -x c++ -triple nvptx-unknown-unknown 
-fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device 
-fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix 
CHECK --check-prefix CHECK-32
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// Check that the execution mode of all 2 target regions on the gpu is set to 
SPMD Mode.
+// CHECK-DAG: {{@__omp_offloading_.+l21}}_exec_mode = 

r292997 - [OpenMP] Support for the num_threads-clause on 'target parallel'.

2017-01-24 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Jan 24 18:57:16 2017
New Revision: 292997

URL: http://llvm.org/viewvc/llvm-project?rev=292997=rev
Log:
[OpenMP] Support for the num_threads-clause on 'target parallel'.

The num_threads-clause on the combined directive applies to the
'parallel' region of this construct. We modify the NumThreadsClause
class to capture the clause expression within the 'target' region.

The offload runtime call for 'target parallel' is changed to
__tgt_target_teams() with 1 team and the number of threads set by
this clause or a default if none.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29082

Added:
cfe/trunk/test/OpenMP/target_parallel_num_threads_codegen.cpp
Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_if_codegen.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=292997=292996=292997=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Tue Jan 24 18:57:16 2017
@@ -345,7 +345,7 @@ public:
 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
 /// clause with number of threads '6'.
 ///
-class OMPNumThreadsClause : public OMPClause {
+class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
   friend class OMPClauseReader;
   /// \brief Location of '('.
   SourceLocation LParenLoc;
@@ -360,20 +360,29 @@ public:
   /// \brief Build 'num_threads' clause with condition \a NumThreads.
   ///
   /// \param NumThreads Number of threads for the construct.
+  /// \param HelperNumThreads Helper Number of threads for the construct.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
   ///
-  OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
-  SourceLocation LParenLoc, SourceLocation EndLoc)
-  : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
-NumThreads(NumThreads) {}
+  OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
+  OpenMPDirectiveKind CaptureRegion,
+  SourceLocation StartLoc, SourceLocation LParenLoc,
+  SourceLocation EndLoc)
+  : OMPClause(OMPC_num_threads, StartLoc, EndLoc),
+OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
+NumThreads(NumThreads) {
+setPreInitStmt(HelperNumThreads, CaptureRegion);
+  }
 
   /// \brief Build an empty clause.
   ///
   OMPNumThreadsClause()
   : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
-LParenLoc(SourceLocation()), NumThreads(nullptr) {}
+OMPClauseWithPreInit(this), LParenLoc(SourceLocation()),
+NumThreads(nullptr) {}
 
   /// \brief Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=292997=292996=292997=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Jan 24 18:57:16 2017
@@ -2725,6 +2725,7 @@ bool RecursiveASTVisitor::Visit
 template 
 bool
 RecursiveASTVisitor::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) 
{
+  TRY_TO(VisitOMPClauseWithPreInit(C));
   TRY_TO(TraverseStmt(C->getNumThreads()));
   return true;
 }

Modified: cfe/trunk/lib/AST/OpenMPClause.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OpenMPClause.cpp?rev=292997=292996=292997=diff
==
--- cfe/trunk/lib/AST/OpenMPClause.cpp (original)
+++ cfe/trunk/lib/AST/OpenMPClause.cpp Tue Jan 24 18:57:16 2017
@@ -50,10 +50,11 @@ const OMPClauseWithPreInit *OMPClauseWit
 return static_cast(C);
   case OMPC_if:
 return static_cast(C);
+  case OMPC_num_threads:
+return static_cast(C);
   case OMPC_default:
   case OMPC_proc_bind:
   case OMPC_final:
-  case OMPC_num_threads:
   case OMPC_safelen:
   case OMPC_simdlen:
   case OMPC_collapse:

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: 

r292794 - [OpenMP] DSAChecker bug fix for combined directives.

2017-01-23 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Mon Jan 23 09:38:49 2017
New Revision: 292794

URL: http://llvm.org/viewvc/llvm-project?rev=292794=rev
Log:
[OpenMP] DSAChecker bug fix for combined directives.

The DSAChecker code in SemaOpenMP looks at the captured statement
associated with an OpenMP directive.  A combined directive such as
'target parallel' has nested capture statements, which have to be
fully traversed before executing the DSAChecker.  This is a patch
to perform the traversal for such combined directives.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D29026

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_parallel_default_messages.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=292794=292793=292794=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Mon Jan 23 09:38:49 2017
@@ -2268,7 +2268,11 @@ StmtResult Sema::ActOnOpenMPExecutableDi
 
 // Check default data sharing attributes for referenced variables.
 DSAAttrChecker DSAChecker(DSAStack, *this, cast(AStmt));
-DSAChecker.Visit(cast(AStmt)->getCapturedStmt());
+int ThisCaptureLevel = getOpenMPCaptureLevels(Kind);
+Stmt *S = AStmt;
+while (--ThisCaptureLevel >= 0)
+  S = cast(S)->getCapturedStmt();
+DSAChecker.Visit(S);
 if (DSAChecker.isErrorFound())
   return StmtError();
 // Generate list of implicitly defined firstprivate variables.

Modified: cfe/trunk/test/OpenMP/target_parallel_default_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_parallel_default_messages.cpp?rev=292794=292793=292794=diff
==
--- cfe/trunk/test/OpenMP/target_parallel_default_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/target_parallel_default_messages.cpp Mon Jan 23 
09:38:49 2017
@@ -23,5 +23,8 @@ int main(int argc, char **argv) {
   foo();
   #pragma omp target parallel default(shared)
   ++argc;
+  #pragma omp target parallel default(none)
+  #pragma omp parallel default(shared)
+  ++argc;
   return 0;
 }


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


r292437 - [OpenMP] Support for the if-clause on the combined directive 'target parallel'.

2017-01-18 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan 18 14:40:48 2017
New Revision: 292437

URL: http://llvm.org/viewvc/llvm-project?rev=292437=rev
Log:
[OpenMP] Support for the if-clause on the combined directive 'target parallel'.

The if-clause on the combined directive potentially applies to both the
'target' and the 'parallel' regions.  Codegen'ing the if-clause on the
combined directive requires additional support because the expression in
the clause must be captured by the 'target' capture statement but not
the 'parallel' capture statement.  Note that this situation arises for
other clauses such as num_threads.

The OMPIfClause class inherits OMPClauseWithPreInit to support capturing
of expressions in the clause.  A member CaptureRegion is added to
OMPClauseWithPreInit to indicate which captured statement (in this case
'target' but not 'parallel') captures these expressions.

To ensure correct codegen of captured expressions in the presence of
combined 'target' directives, OMPParallelScope was added to 'parallel'
codegen.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D28781

Added:
cfe/trunk/test/OpenMP/target_parallel_if_codegen.cpp
Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=292437=292436=292437=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Wed Jan 18 14:40:48 2017
@@ -76,10 +76,17 @@ class OMPClauseWithPreInit {
   friend class OMPClauseReader;
   /// Pre-initialization statement for the clause.
   Stmt *PreInit;
+  /// Region that captures the associated stmt.
+  OpenMPDirectiveKind CaptureRegion;
+
 protected:
   /// Set pre-initialization statement for the clause.
-  void setPreInitStmt(Stmt *S) { PreInit = S; }
-  OMPClauseWithPreInit(const OMPClause *This) : PreInit(nullptr) {
+  void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion = OMPD_unknown) {
+PreInit = S;
+CaptureRegion = ThisRegion;
+  }
+  OMPClauseWithPreInit(const OMPClause *This)
+  : PreInit(nullptr), CaptureRegion(OMPD_unknown) {
 assert(get(This) && "get is not tuned for pre-init.");
   }
 
@@ -88,6 +95,8 @@ public:
   const Stmt *getPreInitStmt() const { return PreInit; }
   /// Get pre-initialization statement for the clause.
   Stmt *getPreInitStmt() { return PreInit; }
+  /// Get capture region for the stmt in the clause.
+  OpenMPDirectiveKind getCaptureRegion() { return CaptureRegion; }
   static OMPClauseWithPreInit *get(OMPClause *C);
   static const OMPClauseWithPreInit *get(const OMPClause *C);
 };
@@ -194,7 +203,7 @@ public:
 /// In this example directive '#pragma omp parallel' has simple 'if' clause 
with
 /// condition 'a > 5' and directive name modifier 'parallel'.
 ///
-class OMPIfClause : public OMPClause {
+class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
   friend class OMPClauseReader;
   /// \brief Location of '('.
   SourceLocation LParenLoc;
@@ -225,26 +234,31 @@ public:
   ///
   /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
   /// \param Cond Condition of the clause.
+  /// \param HelperCond Helper condition for the clause.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param NameModifierLoc Location of directive name modifier.
   /// \param ColonLoc [OpenMP 4.1] Location of ':'.
   /// \param EndLoc Ending location of the clause.
   ///
-  OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond,
-  SourceLocation StartLoc, SourceLocation LParenLoc,
-  SourceLocation NameModifierLoc, SourceLocation ColonLoc,
-  SourceLocation EndLoc)
-  : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
-Condition(Cond), ColonLoc(ColonLoc), NameModifier(NameModifier),
-NameModifierLoc(NameModifierLoc) {}
+  OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
+  OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
+  SourceLocation LParenLoc, SourceLocation NameModifierLoc,
+  SourceLocation ColonLoc, SourceLocation EndLoc)
+  : OMPClause(OMPC_if, StartLoc, EndLoc), OMPClauseWithPreInit(this),
+LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc),
+NameModifier(NameModifier), 

r292428 - [OpenMP] Codegen for the 'target parallel' directive on the NVPTX device.

2017-01-18 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan 18 13:35:00 2017
New Revision: 292428

URL: http://llvm.org/viewvc/llvm-project?rev=292428=rev
Log:
[OpenMP] Codegen for the 'target parallel' directive on the NVPTX device.

This patch adds codegen for the 'target parallel' directive on the NVPTX
device.  We term offload OpenMP directives such as 'target parallel' and
'target teams distribute parallel for' as SPMD constructs.  SPMD constructs,
in contrast to Generic ones like the plain 'target', can never contain
a serial region.

SPMD constructs can be handled more efficiently on the GPU and do not
require the Warp Loop of the Generic codegen scheme. This patch adds
SPMD codegen support for 'target parallel' on the NVPTX device and can
be reused for other SPMD constructs.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D28755

Added:
cfe/trunk/test/OpenMP/nvptx_target_parallel_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=292428=292427=292428=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Wed Jan 18 13:35:00 2017
@@ -26,6 +26,11 @@ enum OpenMPRTLFunctionNVPTX {
   OMPRTL_NVPTX__kmpc_kernel_init,
   /// \brief Call to void __kmpc_kernel_deinit();
   OMPRTL_NVPTX__kmpc_kernel_deinit,
+  /// \brief Call to void __kmpc_spmd_kernel_init(kmp_int32 thread_limit,
+  /// short RequiresOMPRuntime, short RequiresDataSharing);
+  OMPRTL_NVPTX__kmpc_spmd_kernel_init,
+  /// \brief Call to void __kmpc_spmd_kernel_deinit();
+  OMPRTL_NVPTX__kmpc_spmd_kernel_deinit,
   /// \brief Call to void __kmpc_kernel_prepare_parallel(void
   /// *outlined_function);
   OMPRTL_NVPTX__kmpc_kernel_prepare_parallel,
@@ -76,6 +81,25 @@ public:
 CGF.EmitRuntimeCall(ExitCallee, ExitArgs);
   }
 };
+
+// A class to track the execution mode when codegening directives within
+// a target region. The appropriate mode (generic/spmd) is set on entry
+// to the target region and used by containing directives such as 'parallel'
+// to emit optimized code.
+class ExecutionModeRAII {
+private:
+  CGOpenMPRuntimeNVPTX::ExecutionMode SavedMode;
+  CGOpenMPRuntimeNVPTX::ExecutionMode 
+
+public:
+  ExecutionModeRAII(CGOpenMPRuntimeNVPTX::ExecutionMode ,
+CGOpenMPRuntimeNVPTX::ExecutionMode NewMode)
+  : Mode(Mode) {
+SavedMode = Mode;
+Mode = NewMode;
+  }
+  ~ExecutionModeRAII() { Mode = SavedMode; }
+};
 } // anonymous namespace
 
 /// Get the GPU warp size.
@@ -116,12 +140,17 @@ static void getNVPTXCTABarrier(CodeGenFu
 static void syncCTAThreads(CodeGenFunction ) { getNVPTXCTABarrier(CGF); }
 
 /// Get the value of the thread_limit clause in the teams directive.
-/// The runtime encodes thread_limit in the launch parameter, always starting
-/// thread_limit+warpSize threads per team.
-static llvm::Value *getThreadLimit(CodeGenFunction ) {
+/// For the 'generic' execution mode, the runtime encodes thread_limit in
+/// the launch parameters, always starting thread_limit+warpSize threads per
+/// CTA. The threads in the last warp are reserved for master execution.
+/// For the 'spmd' execution mode, all threads in a CTA are part of the team.
+static llvm::Value *getThreadLimit(CodeGenFunction ,
+   bool IsInSpmdExecutionMode = false) {
   CGBuilderTy  = CGF.Builder;
-  return Bld.CreateSub(getNVPTXNumThreads(CGF), getNVPTXWarpSize(CGF),
-   "thread_limit");
+  return IsInSpmdExecutionMode
+ ? getNVPTXNumThreads(CGF)
+ : Bld.CreateSub(getNVPTXNumThreads(CGF), getNVPTXWarpSize(CGF),
+ "thread_limit");
 }
 
 /// Get the thread id of the OMP master thread.
@@ -159,12 +188,33 @@ void CGOpenMPRuntimeNVPTX::WorkerFunctio
   CGM.SetInternalFunctionAttributes(/*D=*/nullptr, WorkerFn, *CGFI);
 }
 
+bool CGOpenMPRuntimeNVPTX::isInSpmdExecutionMode() const {
+  return CurrentExecutionMode == CGOpenMPRuntimeNVPTX::ExecutionMode::Spmd;
+}
+
+static CGOpenMPRuntimeNVPTX::ExecutionMode
+getExecutionModeForDirective(CodeGenModule ,
+ const OMPExecutableDirective ) {
+  OpenMPDirectiveKind DirectiveKind = D.getDirectiveKind();
+  switch (DirectiveKind) {
+  case OMPD_target:
+return CGOpenMPRuntimeNVPTX::ExecutionMode::Generic;
+  case OMPD_target_parallel:
+return CGOpenMPRuntimeNVPTX::ExecutionMode::Spmd;
+  default:
+llvm_unreachable("Unsupported directive on NVPTX device.");
+  }
+  llvm_unreachable("Unsupported directive on NVPTX device.");
+}
+
 void CGOpenMPRuntimeNVPTX::emitGenericKernel(const OMPExecutableDirective ,
   

r292419 - [OpenMP] Codegen support for 'target parallel' on the host.

2017-01-18 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan 18 12:18:53 2017
New Revision: 292419

URL: http://llvm.org/viewvc/llvm-project?rev=292419=rev
Log:
[OpenMP] Codegen support for 'target parallel' on the host.

This patch adds support for codegen of 'target parallel' on the host.
It is also the first combined directive that requires two or more
captured statements.  Support for this functionality is included in
the patch.

A combined directive such as 'target parallel' has two captured
statements, one for the 'target' and the other for the 'parallel'
region.  Two captured statements are required because each has
different implicit parameters (see SemaOpenMP.cpp).  For example,
the 'parallel' has 'global_tid' and 'bound_tid' while the 'target'
does not.  The patch adds support for handling multiple captured
statements based on the combined directive.

When codegen'ing the 'target parallel' directive, the 'target'
outlined function is created using the outer captured statement
and the 'parallel' outlined function is created using the inner
captured statement.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D28753

Added:
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen_registration_naming.cpp
Modified:
cfe/trunk/include/clang/AST/StmtOpenMP.h
cfe/trunk/include/clang/Basic/OpenMPKinds.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=292419=292418=292419=diff
==
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Wed Jan 18 12:18:53 2017
@@ -198,6 +198,26 @@ public:
 return const_cast(*child_begin());
   }
 
+  /// \brief Returns the captured statement associated with the
+  /// component region within the (combined) directive.
+  //
+  // \param RegionKind Component region kind.
+  CapturedStmt *getCapturedStmt(OpenMPDirectiveKind RegionKind) const {
+SmallVector CaptureRegions;
+getOpenMPCaptureRegions(CaptureRegions, getDirectiveKind());
+assert(std::any_of(
+   CaptureRegions.begin(), CaptureRegions.end(),
+   [=](const OpenMPDirectiveKind K) { return K == RegionKind; }) &&
+   "RegionKind not found in OpenMP CaptureRegions.");
+auto *CS = cast(getAssociatedStmt());
+for (auto ThisCaptureRegion : CaptureRegions) {
+  if (ThisCaptureRegion == RegionKind)
+return CS;
+  CS = cast(CS->getCapturedStmt());
+}
+llvm_unreachable("Incorrect RegionKind specified for directive.");
+  }
+
   OpenMPDirectiveKind getDirectiveKind() const { return Kind; }
 
   static bool classof(const Stmt *S) {

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.h?rev=292419=292418=292419=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.h (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.h Wed Jan 18 12:18:53 2017
@@ -234,6 +234,11 @@ bool isOpenMPTaskingDirective(OpenMPDire
 /// directives that need loop bound sharing across loops outlined in nested
 /// functions
 bool isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind);
+
+/// Return the captured regions of an OpenMP directive.
+void getOpenMPCaptureRegions(
+llvm::SmallVectorImpl ,
+OpenMPDirectiveKind DKind);
 }
 
 #endif

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=292419=292418=292419=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Jan 18 12:18:53 2017
@@ -8340,6 +8340,9 @@ public:
 return IsInOpenMPDeclareTargetContext;
   }
 
+  /// Return the number of captured regions created for an OpenMP directive.
+  static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind);
+
   /// \brief Initialization of captured region for OpenMP region.
   void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope);
   /// \brief End of OpenMP region.

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=292419=292418=292419=diff

r292400 - Revert r292374 to debug Windows buildbot failure.

2017-01-18 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan 18 09:36:05 2017
New Revision: 292400

URL: http://llvm.org/viewvc/llvm-project?rev=292400=rev
Log:
Revert r292374 to debug Windows buildbot failure.


Removed:
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen_registration_naming.cpp
Modified:
cfe/trunk/include/clang/AST/StmtOpenMP.h
cfe/trunk/include/clang/Basic/OpenMPKinds.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=292400=292399=292400=diff
==
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Wed Jan 18 09:36:05 2017
@@ -198,26 +198,6 @@ public:
 return const_cast(*child_begin());
   }
 
-  /// \brief Returns the captured statement associated with the
-  /// component region within the (combined) directive.
-  //
-  // \param RegionKind Component region kind.
-  CapturedStmt *getCapturedStmt(OpenMPDirectiveKind RegionKind) const {
-ArrayRef CaptureRegions =
-getOpenMPCaptureRegions(getDirectiveKind());
-assert(std::any_of(
-   CaptureRegions.begin(), CaptureRegions.end(),
-   [=](const OpenMPDirectiveKind K) { return K == RegionKind; }) &&
-   "RegionKind not found in OpenMP CaptureRegions.");
-auto *CS = cast(getAssociatedStmt());
-for (auto ThisCaptureRegion : CaptureRegions) {
-  if (ThisCaptureRegion == RegionKind)
-return CS;
-  CS = cast(CS->getCapturedStmt());
-}
-llvm_unreachable("Incorrect RegionKind specified for directive.");
-  }
-
   OpenMPDirectiveKind getDirectiveKind() const { return Kind; }
 
   static bool classof(const Stmt *S) {

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.h?rev=292400=292399=292400=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.h (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.h Wed Jan 18 09:36:05 2017
@@ -15,7 +15,6 @@
 #ifndef LLVM_CLANG_BASIC_OPENMPKINDS_H
 #define LLVM_CLANG_BASIC_OPENMPKINDS_H
 
-#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace clang {
@@ -235,10 +234,6 @@ bool isOpenMPTaskingDirective(OpenMPDire
 /// directives that need loop bound sharing across loops outlined in nested
 /// functions
 bool isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind);
-
-/// Return the captured regions of an OpenMP directive.
-llvm::ArrayRef
-getOpenMPCaptureRegions(OpenMPDirectiveKind DKind);
 }
 
 #endif

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=292400=292399=292400=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Jan 18 09:36:05 2017
@@ -8340,9 +8340,6 @@ public:
 return IsInOpenMPDeclareTargetContext;
   }
 
-  /// Return the number of captured regions created for an OpenMP directive.
-  static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind);
-
   /// \brief Initialization of captured region for OpenMP region.
   void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope);
   /// \brief End of OpenMP region.

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=292400=292399=292400=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Wed Jan 18 09:36:05 2017
@@ -863,101 +863,3 @@ bool clang::isOpenMPLoopBoundSharingDire
  Kind == OMPD_target_teams_distribute_parallel_for_simd ||
  Kind == OMPD_target_teams_distribute_simd;
 }
-
-ArrayRef
-clang::getOpenMPCaptureRegions(OpenMPDirectiveKind DKind) {
-  assert(DKind <= OMPD_unknown);
-  switch (DKind) {
-  case OMPD_parallel:
-  case OMPD_parallel_for:
-  case OMPD_parallel_for_simd:
-  case OMPD_parallel_sections:
-return {OMPD_parallel};
-  case OMPD_teams:
-return {OMPD_teams};
-  case OMPD_target_teams:
-return {OMPD_target_teams};
-  case OMPD_simd:
-return {OMPD_simd};
-  case OMPD_for:
-return 

r292374 - [OpenMP] Codegen support for 'target parallel' on the host.

2017-01-18 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan 18 09:14:52 2017
New Revision: 292374

URL: http://llvm.org/viewvc/llvm-project?rev=292374=rev
Log:
[OpenMP] Codegen support for 'target parallel' on the host.

This patch adds support for codegen of 'target parallel' on the host.
It is also the first combined directive that requires two or more
captured statements.  Support for this functionality is included in
the patch.

A combined directive such as 'target parallel' has two captured
statements, one for the 'target' and the other for the 'parallel'
region.  Two captured statements are required because each has
different implicit parameters (see SemaOpenMP.cpp).  For example,
the 'parallel' has 'global_tid' and 'bound_tid' while the 'target'
does not.  The patch adds support for handling multiple captured
statements based on the combined directive.

When codegen'ing the 'target parallel' directive, the 'target'
outlined function is created using the outer captured statement
and the 'parallel' outlined function is created using the inner
captured statement.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D28753

Added:
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen_registration_naming.cpp
Modified:
cfe/trunk/include/clang/AST/StmtOpenMP.h
cfe/trunk/include/clang/Basic/OpenMPKinds.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=292374=292373=292374=diff
==
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Wed Jan 18 09:14:52 2017
@@ -198,6 +198,26 @@ public:
 return const_cast(*child_begin());
   }
 
+  /// \brief Returns the captured statement associated with the
+  /// component region within the (combined) directive.
+  //
+  // \param RegionKind Component region kind.
+  CapturedStmt *getCapturedStmt(OpenMPDirectiveKind RegionKind) const {
+ArrayRef CaptureRegions =
+getOpenMPCaptureRegions(getDirectiveKind());
+assert(std::any_of(
+   CaptureRegions.begin(), CaptureRegions.end(),
+   [=](const OpenMPDirectiveKind K) { return K == RegionKind; }) &&
+   "RegionKind not found in OpenMP CaptureRegions.");
+auto *CS = cast(getAssociatedStmt());
+for (auto ThisCaptureRegion : CaptureRegions) {
+  if (ThisCaptureRegion == RegionKind)
+return CS;
+  CS = cast(CS->getCapturedStmt());
+}
+llvm_unreachable("Incorrect RegionKind specified for directive.");
+  }
+
   OpenMPDirectiveKind getDirectiveKind() const { return Kind; }
 
   static bool classof(const Stmt *S) {

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.h?rev=292374=292373=292374=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.h (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.h Wed Jan 18 09:14:52 2017
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_BASIC_OPENMPKINDS_H
 #define LLVM_CLANG_BASIC_OPENMPKINDS_H
 
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace clang {
@@ -234,6 +235,10 @@ bool isOpenMPTaskingDirective(OpenMPDire
 /// directives that need loop bound sharing across loops outlined in nested
 /// functions
 bool isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind);
+
+/// Return the captured regions of an OpenMP directive.
+llvm::ArrayRef
+getOpenMPCaptureRegions(OpenMPDirectiveKind DKind);
 }
 
 #endif

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=292374=292373=292374=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Jan 18 09:14:52 2017
@@ -8340,6 +8340,9 @@ public:
 return IsInOpenMPDeclareTargetContext;
   }
 
+  /// Return the number of captured regions created for an OpenMP directive.
+  static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind);
+
   /// \brief Initialization of captured region for OpenMP region.
   void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope);
   /// \brief End of OpenMP region.

Modified: 

r291565 - [OpenMP] Basic support for a parallel directive in a target region on an NVPTX device

2017-01-10 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Jan 10 09:42:51 2017
New Revision: 291565

URL: http://llvm.org/viewvc/llvm-project?rev=291565=rev
Log:
[OpenMP] Basic support for a parallel directive in a target region on an NVPTX 
device

Summary:

This patch introduces support for the execution of parallel constructs in a 
target
region on the NVPTX device.  Parallel regions must be in the lexical scope of 
the
target directive.

The master thread in the master warp signals parallel work for worker threads 
in worker
warps on encountering a parallel region.

Note: The patch does not yet support capture of arguments in a parallel region 
so
the test cases are simple.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D28145

Added:
cfe/trunk/test/OpenMP/nvptx_parallel_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=291565=291564=291565=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Jan 10 09:42:51 2017
@@ -99,10 +99,11 @@ class CGOpenMPOutlinedRegionInfo final :
 public:
   CGOpenMPOutlinedRegionInfo(const CapturedStmt , const VarDecl 
*ThreadIDVar,
  const RegionCodeGenTy ,
- OpenMPDirectiveKind Kind, bool HasCancel)
+ OpenMPDirectiveKind Kind, bool HasCancel,
+ StringRef HelperName)
   : CGOpenMPRegionInfo(CS, ParallelOutlinedRegion, CodeGen, Kind,
HasCancel),
-ThreadIDVar(ThreadIDVar) {
+ThreadIDVar(ThreadIDVar), HelperName(HelperName) {
 assert(ThreadIDVar != nullptr && "No ThreadID in OpenMP region.");
   }
 
@@ -111,7 +112,7 @@ public:
   const VarDecl *getThreadIDVariable() const override { return ThreadIDVar; }
 
   /// \brief Get the name of the capture helper.
-  StringRef getHelperName() const override { return ".omp_outlined."; }
+  StringRef getHelperName() const override { return HelperName; }
 
   static bool classof(const CGCapturedStmtInfo *Info) {
 return CGOpenMPRegionInfo::classof(Info) &&
@@ -123,6 +124,7 @@ private:
   /// \brief A variable or parameter storing global thread id for OpenMP
   /// constructs.
   const VarDecl *ThreadIDVar;
+  StringRef HelperName;
 };
 
 /// \brief API for captured statement code generation in OpenMP constructs.
@@ -855,7 +857,7 @@ llvm::Value *CGOpenMPRuntime::emitParall
   else if (auto *OPFD = dyn_cast())
 HasCancel = OPFD->hasCancel();
   CGOpenMPOutlinedRegionInfo CGInfo(*CS, ThreadIDVar, CodeGen, InnermostKind,
-HasCancel);
+HasCancel, getOutlinedHelperName());
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );
   return CGF.GenerateOpenMPCapturedStmtFunction(*CS);
 }
@@ -1892,9 +1894,9 @@ llvm::Function *CGOpenMPRuntime::emitThr
 /// } else {
 ///   ElseGen();
 /// }
-static void emitOMPIfClause(CodeGenFunction , const Expr *Cond,
-const RegionCodeGenTy ,
-const RegionCodeGenTy ) {
+void CGOpenMPRuntime::emitOMPIfClause(CodeGenFunction , const Expr *Cond,
+  const RegionCodeGenTy ,
+  const RegionCodeGenTy ) {
   CodeGenFunction::LexicalScope ConditionScope(CGF, Cond->getSourceRange());
 
   // If the condition constant folds and can be elided, try to avoid emitting

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=291565=291564=291565=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Tue Jan 10 09:42:51 2017
@@ -130,6 +130,35 @@ protected:
 bool IsOffloadEntry,
 const RegionCodeGenTy 
);
 
+  /// \brief Emits code for OpenMP 'if' clause using specified \a CodeGen
+  /// function. Here is the logic:
+  /// if (Cond) {
+  ///   ThenGen();
+  /// } else {
+  ///   ElseGen();
+  /// }
+  void emitOMPIfClause(CodeGenFunction , const Expr *Cond,
+   const RegionCodeGenTy ,
+   const RegionCodeGenTy );
+
+  /// \brief Emits object of ident_t type with info for source location.
+  /// \param Flags Flags for OpenMP location.
+  ///
+  llvm::Value *emitUpdateLocation(CodeGenFunction , SourceLocation Loc,
+  unsigned Flags = 0);
+
+  /// \brief Returns pointer to 

r291121 - [OpenMP] Update target codegen for NVPTX device.

2017-01-05 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Jan  5 09:24:05 2017
New Revision: 291121

URL: http://llvm.org/viewvc/llvm-project?rev=291121=rev
Log:
[OpenMP] Update target codegen for NVPTX device.

This patch includes updates for codegen of the target region for the NVPTX
device. It moves initializers from the compiler to the runtime and updates
the worker loop to assume parallel work is retrieved from the runtime. A
subsequent patch will update the codegen to retrieve the parallel work using
calls to the runtime. It includes the removal of the inline attribute
for the worker loop and disabling debug info in it.

This allows codegen for a target directive and serial execution on the
NVPTX device.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D28125

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=291121=291120=291121=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Thu Jan  5 09:24:05 2017
@@ -22,14 +22,10 @@ using namespace CodeGen;
 
 namespace {
 enum OpenMPRTLFunctionNVPTX {
-  /// \brief Call to void __kmpc_kernel_init(kmp_int32 omp_handle,
-  /// kmp_int32 thread_limit);
+  /// \brief Call to void __kmpc_kernel_init(kmp_int32 thread_limit);
   OMPRTL_NVPTX__kmpc_kernel_init,
-};
-
-// NVPTX Address space
-enum AddressSpace {
-  AddressSpaceShared = 3,
+  /// \brief Call to void __kmpc_kernel_deinit();
+  OMPRTL_NVPTX__kmpc_kernel_deinit,
 };
 } // namespace
 
@@ -70,6 +66,15 @@ static void getNVPTXCTABarrier(CodeGenFu
 /// Synchronize all GPU threads in a block.
 static void syncCTAThreads(CodeGenFunction ) { getNVPTXCTABarrier(CGF); }
 
+/// Get the value of the thread_limit clause in the teams directive.
+/// The runtime encodes thread_limit in the launch parameter, always starting
+/// thread_limit+warpSize threads per team.
+static llvm::Value *getThreadLimit(CodeGenFunction ) {
+  CGBuilderTy  = CGF.Builder;
+  return Bld.CreateSub(getNVPTXNumThreads(CGF), getNVPTXWarpSize(CGF),
+   "thread_limit");
+}
+
 /// Get the thread id of the OMP master thread.
 /// The master thread id is the first thread (lane) of the last warp in the
 /// GPU block.  Warp size is assumed to be some power of 2.
@@ -103,35 +108,105 @@ void CGOpenMPRuntimeNVPTX::WorkerFunctio
   CGM.getTypes().GetFunctionType(*CGFI), 
llvm::GlobalValue::InternalLinkage,
   /* placeholder */ "_worker", ());
   CGM.SetInternalFunctionAttributes(/*D=*/nullptr, WorkerFn, *CGFI);
-  WorkerFn->setLinkage(llvm::GlobalValue::InternalLinkage);
-  WorkerFn->addFnAttr(llvm::Attribute::NoInline);
 }
 
-void CGOpenMPRuntimeNVPTX::initializeEnvironment() {
-  //
-  // Initialize master-worker control state in shared memory.
-  //
+void CGOpenMPRuntimeNVPTX::emitGenericKernel(const OMPExecutableDirective ,
+ StringRef ParentName,
+ llvm::Function *,
+ llvm::Constant *,
+ bool IsOffloadEntry,
+ const RegionCodeGenTy ) {
+  EntryFunctionState EST;
+  WorkerFunctionState WST(CGM);
+
+  // Emit target region as a standalone region.
+  class NVPTXPrePostActionTy : public PrePostActionTy {
+CGOpenMPRuntimeNVPTX 
+CGOpenMPRuntimeNVPTX::EntryFunctionState 
+CGOpenMPRuntimeNVPTX::WorkerFunctionState 
+
+  public:
+NVPTXPrePostActionTy(CGOpenMPRuntimeNVPTX ,
+ CGOpenMPRuntimeNVPTX::EntryFunctionState ,
+ CGOpenMPRuntimeNVPTX::WorkerFunctionState )
+: RT(RT), EST(EST), WST(WST) {}
+void Enter(CodeGenFunction ) override {
+  RT.emitGenericEntryHeader(CGF, EST, WST);
+}
+void Exit(CodeGenFunction ) override {
+  RT.emitGenericEntryFooter(CGF, EST);
+}
+  } Action(*this, EST, WST);
+  CodeGen.setAction(Action);
+  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
+   IsOffloadEntry, CodeGen);
+
+  // Create the worker function
+  emitWorkerFunction(WST);
+
+  // Now change the name of the worker function to correspond to this target
+  // region's entry function.
+  WST.WorkerFn->setName(OutlinedFn->getName() + "_worker");
+}
+
+// Setup NVPTX threads for master-worker OpenMP scheme.
+void CGOpenMPRuntimeNVPTX::emitGenericEntryHeader(CodeGenFunction ,
+  EntryFunctionState ,
+  WorkerFunctionState ) {
+  CGBuilderTy  = CGF.Builder;
+
+  llvm::BasicBlock *WorkerBB = 

r290989 - Reverting commit r290983 while debugging test failure on windows.

2017-01-04 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan  4 13:14:43 2017
New Revision: 290989

URL: http://llvm.org/viewvc/llvm-project?rev=290989=rev
Log:
Reverting commit r290983 while debugging test failure on windows.


Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=290989=290988=290989=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Wed Jan  4 13:14:43 2017
@@ -22,10 +22,14 @@ using namespace CodeGen;
 
 namespace {
 enum OpenMPRTLFunctionNVPTX {
-  /// \brief Call to void __kmpc_kernel_init(kmp_int32 thread_limit);
+  /// \brief Call to void __kmpc_kernel_init(kmp_int32 omp_handle,
+  /// kmp_int32 thread_limit);
   OMPRTL_NVPTX__kmpc_kernel_init,
-  /// \brief Call to void __kmpc_kernel_deinit();
-  OMPRTL_NVPTX__kmpc_kernel_deinit,
+};
+
+// NVPTX Address space
+enum AddressSpace {
+  AddressSpaceShared = 3,
 };
 } // namespace
 
@@ -66,15 +70,6 @@ static void getNVPTXCTABarrier(CodeGenFu
 /// Synchronize all GPU threads in a block.
 static void syncCTAThreads(CodeGenFunction ) { getNVPTXCTABarrier(CGF); }
 
-/// Get the value of the thread_limit clause in the teams directive.
-/// The runtime encodes thread_limit in the launch parameter, always starting
-/// thread_limit+warpSize threads per team.
-static llvm::Value *getThreadLimit(CodeGenFunction ) {
-  CGBuilderTy  = CGF.Builder;
-  return Bld.CreateSub(getNVPTXNumThreads(CGF), getNVPTXWarpSize(CGF),
-   "thread_limit");
-}
-
 /// Get the thread id of the OMP master thread.
 /// The master thread id is the first thread (lane) of the last warp in the
 /// GPU block.  Warp size is assumed to be some power of 2.
@@ -108,105 +103,35 @@ void CGOpenMPRuntimeNVPTX::WorkerFunctio
   CGM.getTypes().GetFunctionType(*CGFI), 
llvm::GlobalValue::InternalLinkage,
   /* placeholder */ "_worker", ());
   CGM.SetInternalFunctionAttributes(/*D=*/nullptr, WorkerFn, *CGFI);
+  WorkerFn->setLinkage(llvm::GlobalValue::InternalLinkage);
+  WorkerFn->addFnAttr(llvm::Attribute::NoInline);
 }
 
-void CGOpenMPRuntimeNVPTX::emitGenericKernel(const OMPExecutableDirective ,
- StringRef ParentName,
- llvm::Function *,
- llvm::Constant *,
- bool IsOffloadEntry,
- const RegionCodeGenTy ) {
-  EntryFunctionState EST;
-  WorkerFunctionState WST(CGM);
-
-  // Emit target region as a standalone region.
-  class NVPTXPrePostActionTy : public PrePostActionTy {
-CGOpenMPRuntimeNVPTX 
-CGOpenMPRuntimeNVPTX::EntryFunctionState 
-CGOpenMPRuntimeNVPTX::WorkerFunctionState 
-
-  public:
-NVPTXPrePostActionTy(CGOpenMPRuntimeNVPTX ,
- CGOpenMPRuntimeNVPTX::EntryFunctionState ,
- CGOpenMPRuntimeNVPTX::WorkerFunctionState )
-: RT(RT), EST(EST), WST(WST) {}
-void Enter(CodeGenFunction ) override {
-  RT.emitGenericEntryHeader(CGF, EST, WST);
-}
-void Exit(CodeGenFunction ) override {
-  RT.emitGenericEntryFooter(CGF, EST);
-}
-  } Action(*this, EST, WST);
-  CodeGen.setAction(Action);
-  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
-   IsOffloadEntry, CodeGen);
-
-  // Create the worker function
-  emitWorkerFunction(WST);
-
-  // Now change the name of the worker function to correspond to this target
-  // region's entry function.
-  WST.WorkerFn->setName(OutlinedFn->getName() + "_worker");
-}
-
-// Setup NVPTX threads for master-worker OpenMP scheme.
-void CGOpenMPRuntimeNVPTX::emitGenericEntryHeader(CodeGenFunction ,
-  EntryFunctionState ,
-  WorkerFunctionState ) {
-  CGBuilderTy  = CGF.Builder;
-
-  llvm::BasicBlock *WorkerBB = CGF.createBasicBlock(".worker");
-  llvm::BasicBlock *MasterCheckBB = CGF.createBasicBlock(".mastercheck");
-  llvm::BasicBlock *MasterBB = CGF.createBasicBlock(".master");
-  EST.ExitBB = CGF.createBasicBlock(".exit");
-
-  auto *IsWorker =
-  Bld.CreateICmpULT(getNVPTXThreadID(CGF), getThreadLimit(CGF));
-  Bld.CreateCondBr(IsWorker, WorkerBB, MasterCheckBB);
-
-  CGF.EmitBlock(WorkerBB);
-  CGF.EmitCallOrInvoke(WST.WorkerFn, llvm::None);
-  CGF.EmitBranch(EST.ExitBB);
-
-  CGF.EmitBlock(MasterCheckBB);
-  auto *IsMaster =
-  Bld.CreateICmpEQ(getNVPTXThreadID(CGF), getMasterThreadID(CGF));
-  Bld.CreateCondBr(IsMaster, MasterBB, EST.ExitBB);
-
-  CGF.EmitBlock(MasterBB);
-  // First 

r290983 - [OpenMP] Update target codegen for NVPTX device.

2017-01-04 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Wed Jan  4 12:44:50 2017
New Revision: 290983

URL: http://llvm.org/viewvc/llvm-project?rev=290983=rev
Log:
[OpenMP] Update target codegen for NVPTX device.

This patch includes updates for codegen of the target region for the NVPTX
device. It moves initializers from the compiler to the runtime and updates
the worker loop to assume parallel work is retrieved from the runtime. A
subsequent patch will update the codegen to retrieve the parallel work using
calls to the runtime. It includes the removal of the inline attribute
for the worker loop and disabling debug info in it.

This allows codegen for a target directive and serial execution on the
NVPTX device.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D28125


Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=290983=290982=290983=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Wed Jan  4 12:44:50 2017
@@ -22,14 +22,10 @@ using namespace CodeGen;
 
 namespace {
 enum OpenMPRTLFunctionNVPTX {
-  /// \brief Call to void __kmpc_kernel_init(kmp_int32 omp_handle,
-  /// kmp_int32 thread_limit);
+  /// \brief Call to void __kmpc_kernel_init(kmp_int32 thread_limit);
   OMPRTL_NVPTX__kmpc_kernel_init,
-};
-
-// NVPTX Address space
-enum AddressSpace {
-  AddressSpaceShared = 3,
+  /// \brief Call to void __kmpc_kernel_deinit();
+  OMPRTL_NVPTX__kmpc_kernel_deinit,
 };
 } // namespace
 
@@ -70,6 +66,15 @@ static void getNVPTXCTABarrier(CodeGenFu
 /// Synchronize all GPU threads in a block.
 static void syncCTAThreads(CodeGenFunction ) { getNVPTXCTABarrier(CGF); }
 
+/// Get the value of the thread_limit clause in the teams directive.
+/// The runtime encodes thread_limit in the launch parameter, always starting
+/// thread_limit+warpSize threads per team.
+static llvm::Value *getThreadLimit(CodeGenFunction ) {
+  CGBuilderTy  = CGF.Builder;
+  return Bld.CreateSub(getNVPTXNumThreads(CGF), getNVPTXWarpSize(CGF),
+   "thread_limit");
+}
+
 /// Get the thread id of the OMP master thread.
 /// The master thread id is the first thread (lane) of the last warp in the
 /// GPU block.  Warp size is assumed to be some power of 2.
@@ -103,35 +108,105 @@ void CGOpenMPRuntimeNVPTX::WorkerFunctio
   CGM.getTypes().GetFunctionType(*CGFI), 
llvm::GlobalValue::InternalLinkage,
   /* placeholder */ "_worker", ());
   CGM.SetInternalFunctionAttributes(/*D=*/nullptr, WorkerFn, *CGFI);
-  WorkerFn->setLinkage(llvm::GlobalValue::InternalLinkage);
-  WorkerFn->addFnAttr(llvm::Attribute::NoInline);
 }
 
-void CGOpenMPRuntimeNVPTX::initializeEnvironment() {
-  //
-  // Initialize master-worker control state in shared memory.
-  //
+void CGOpenMPRuntimeNVPTX::emitGenericKernel(const OMPExecutableDirective ,
+ StringRef ParentName,
+ llvm::Function *,
+ llvm::Constant *,
+ bool IsOffloadEntry,
+ const RegionCodeGenTy ) {
+  EntryFunctionState EST;
+  WorkerFunctionState WST(CGM);
+
+  // Emit target region as a standalone region.
+  class NVPTXPrePostActionTy : public PrePostActionTy {
+CGOpenMPRuntimeNVPTX 
+CGOpenMPRuntimeNVPTX::EntryFunctionState 
+CGOpenMPRuntimeNVPTX::WorkerFunctionState 
+
+  public:
+NVPTXPrePostActionTy(CGOpenMPRuntimeNVPTX ,
+ CGOpenMPRuntimeNVPTX::EntryFunctionState ,
+ CGOpenMPRuntimeNVPTX::WorkerFunctionState )
+: RT(RT), EST(EST), WST(WST) {}
+void Enter(CodeGenFunction ) override {
+  RT.emitGenericEntryHeader(CGF, EST, WST);
+}
+void Exit(CodeGenFunction ) override {
+  RT.emitGenericEntryFooter(CGF, EST);
+}
+  } Action(*this, EST, WST);
+  CodeGen.setAction(Action);
+  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
+   IsOffloadEntry, CodeGen);
+
+  // Create the worker function
+  emitWorkerFunction(WST);
+
+  // Now change the name of the worker function to correspond to this target
+  // region's entry function.
+  WST.WorkerFn->setName(OutlinedFn->getName() + "_worker");
+}
+
+// Setup NVPTX threads for master-worker OpenMP scheme.
+void CGOpenMPRuntimeNVPTX::emitGenericEntryHeader(CodeGenFunction ,
+  EntryFunctionState ,
+  WorkerFunctionState ) {
+  CGBuilderTy  = CGF.Builder;
+
+  llvm::BasicBlock *WorkerBB = 

r290904 - [OpenMP] Code cleanup for NVPTX OpenMP codegen

2017-01-03 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Jan  3 14:19:56 2017
New Revision: 290904

URL: http://llvm.org/viewvc/llvm-project?rev=290904=rev
Log:
[OpenMP] Code cleanup for NVPTX OpenMP codegen

This patch cleans up private methods for NVPTX OpenMP codegen. It converts 
private
members to static functions to follow the coding style of CGOpenMPRuntime.cpp 
and
declutter the header file.

Reviewers: ABataev
Differential Revision: https://reviews.llvm.org/D28124


Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=290904=290903=290904=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Tue Jan  3 14:19:56 2017
@@ -20,53 +20,64 @@
 using namespace clang;
 using namespace CodeGen;
 
-/// \brief Get the GPU warp size.
-llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXWarpSize(CodeGenFunction ) {
+namespace {
+enum OpenMPRTLFunctionNVPTX {
+  /// \brief Call to void __kmpc_kernel_init(kmp_int32 omp_handle,
+  /// kmp_int32 thread_limit);
+  OMPRTL_NVPTX__kmpc_kernel_init,
+};
+
+// NVPTX Address space
+enum AddressSpace {
+  AddressSpaceShared = 3,
+};
+} // namespace
+
+/// Get the GPU warp size.
+static llvm::Value *getNVPTXWarpSize(CodeGenFunction ) {
   CGBuilderTy  = CGF.Builder;
   return Bld.CreateCall(
   llvm::Intrinsic::getDeclaration(
-  (), llvm::Intrinsic::nvvm_read_ptx_sreg_warpsize),
+  (), llvm::Intrinsic::nvvm_read_ptx_sreg_warpsize),
   llvm::None, "nvptx_warp_size");
 }
 
-/// \brief Get the id of the current thread on the GPU.
-llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXThreadID(CodeGenFunction ) {
+/// Get the id of the current thread on the GPU.
+static llvm::Value *getNVPTXThreadID(CodeGenFunction ) {
   CGBuilderTy  = CGF.Builder;
   return Bld.CreateCall(
   llvm::Intrinsic::getDeclaration(
-  (), llvm::Intrinsic::nvvm_read_ptx_sreg_tid_x),
+  (), llvm::Intrinsic::nvvm_read_ptx_sreg_tid_x),
   llvm::None, "nvptx_tid");
 }
 
-// \brief Get the maximum number of threads in a block of the GPU.
-llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXNumThreads(CodeGenFunction ) {
+/// Get the maximum number of threads in a block of the GPU.
+static llvm::Value *getNVPTXNumThreads(CodeGenFunction ) {
   CGBuilderTy  = CGF.Builder;
   return Bld.CreateCall(
   llvm::Intrinsic::getDeclaration(
-  (), llvm::Intrinsic::nvvm_read_ptx_sreg_ntid_x),
+  (), llvm::Intrinsic::nvvm_read_ptx_sreg_ntid_x),
   llvm::None, "nvptx_num_threads");
 }
 
-/// \brief Get barrier to synchronize all threads in a block.
-void CGOpenMPRuntimeNVPTX::getNVPTXCTABarrier(CodeGenFunction ) {
+/// Get barrier to synchronize all threads in a block.
+static void getNVPTXCTABarrier(CodeGenFunction ) {
   CGBuilderTy  = CGF.Builder;
   Bld.CreateCall(llvm::Intrinsic::getDeclaration(
-  (), llvm::Intrinsic::nvvm_barrier0));
+  (), llvm::Intrinsic::nvvm_barrier0));
 }
 
-// \brief Synchronize all GPU threads in a block.
-void CGOpenMPRuntimeNVPTX::syncCTAThreads(CodeGenFunction ) {
-  getNVPTXCTABarrier(CGF);
-}
+/// Synchronize all GPU threads in a block.
+static void syncCTAThreads(CodeGenFunction ) { getNVPTXCTABarrier(CGF); }
 
-/// \brief Get the thread id of the OMP master thread.
+/// Get the thread id of the OMP master thread.
 /// The master thread id is the first thread (lane) of the last warp in the
 /// GPU block.  Warp size is assumed to be some power of 2.
 /// Thread id is 0 indexed.
 /// E.g: If NumThreads is 33, master id is 32.
 ///  If NumThreads is 64, master id is 32.
 ///  If NumThreads is 1024, master id is 992.
-llvm::Value *CGOpenMPRuntimeNVPTX::getMasterThreadID(CodeGenFunction ) {
+static llvm::Value *getMasterThreadID(CodeGenFunction ) {
   CGBuilderTy  = CGF.Builder;
   llvm::Value *NumThreads = getNVPTXNumThreads(CGF);
 
@@ -77,19 +88,6 @@ llvm::Value *CGOpenMPRuntimeNVPTX::getMa
Bld.CreateNot(Mask), "master_tid");
 }
 
-namespace {
-enum OpenMPRTLFunctionNVPTX {
-  /// \brief Call to void __kmpc_kernel_init(kmp_int32 omp_handle,
-  /// kmp_int32 thread_limit);
-  OMPRTL_NVPTX__kmpc_kernel_init,
-};
-
-// NVPTX Address space
-enum ADDRESS_SPACE {
-  ADDRESS_SPACE_SHARED = 3,
-};
-} // namespace
-
 CGOpenMPRuntimeNVPTX::WorkerFunctionState::WorkerFunctionState(
 CodeGenModule )
 : WorkerFn(nullptr), CGFI(nullptr) {
@@ -119,14 +117,14 @@ void CGOpenMPRuntimeNVPTX::initializeEnv
   CGM.getModule(), CGM.Int32Ty, /*isConstant=*/false,
   llvm::GlobalValue::CommonLinkage,
   llvm::Constant::getNullValue(CGM.Int32Ty), "__omp_num_threads", 0,
-  llvm::GlobalVariable::NotThreadLocal, ADDRESS_SPACE_SHARED);
+  llvm::GlobalVariable::NotThreadLocal, 

r264018 - [OpenMP] Base support for target directive codegen on NVPTX device.

2016-03-21 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Mon Mar 21 20:48:56 2016
New Revision: 264018

URL: http://llvm.org/viewvc/llvm-project?rev=264018=rev
Log:
[OpenMP] Base support for target directive codegen on NVPTX device.

Summary:
This patch adds base support for codegen of the target directive on the NVPTX 
device.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D17877

Reworked test case after buildbot failure on windows.
Updated patch to integrate r263837 and test case 
nvptx_target_firstprivate_codegen.cpp.


Added:
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=264018=264017=264018=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Mon Mar 21 20:48:56 2016
@@ -4182,6 +4182,14 @@ void CGOpenMPRuntime::emitTargetOutlined
 CGF.EmitStmt(CS.getCapturedStmt());
   };
 
+  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
+   IsOffloadEntry, CodeGen);
+}
+
+void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
+const OMPExecutableDirective , StringRef ParentName,
+llvm::Function *, llvm::Constant *,
+bool IsOffloadEntry, const RegionCodeGenTy ) {
   // Create a unique name for the entry function using the source location
   // information of the current target region. The name will be something like:
   //
@@ -4203,6 +4211,8 @@ void CGOpenMPRuntime::emitTargetOutlined
<< llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
   }
 
+  const CapturedStmt  = *cast(D.getAssociatedStmt());
+
   CodeGenFunction CGF(CGM, true);
   CGOpenMPTargetRegionInfo CGInfo(CS, CodeGen, EntryFnName);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=264018=264017=264018=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Mon Mar 21 20:48:56 2016
@@ -49,7 +49,31 @@ class CodeGenModule;
 typedef llvm::function_ref RegionCodeGenTy;
 
 class CGOpenMPRuntime {
+protected:
   CodeGenModule 
+
+  /// \brief Creates offloading entry for the provided entry ID \a ID,
+  /// address \a Addr and size \a Size.
+  virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
+  uint64_t Size);
+
+  /// \brief Helper to emit outlined function for 'target' directive.
+  /// \param D Directive to emit.
+  /// \param ParentName Name of the function that encloses the target region.
+  /// \param OutlinedFn Outlined function value to be defined by this call.
+  /// \param OutlinedFnID Outlined function ID value to be defined by this 
call.
+  /// \param IsOffloadEntry True if the outlined function is an offload entry.
+  /// \param CodeGen Lambda codegen specific to an accelerator device.
+  /// An oulined function may not be an entry if, e.g. the if clause always
+  /// evaluates to false.
+  virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective 
,
+StringRef ParentName,
+llvm::Function *,
+llvm::Constant *,
+bool IsOffloadEntry,
+const RegionCodeGenTy 
);
+
+private:
   /// \brief Default const ident_t object used for initialization of all other
   /// ident_t objects.
   llvm::Constant *DefaultOpenMPPSource = nullptr;
@@ -267,11 +291,6 @@ class CGOpenMPRuntime {
   /// compilation unit. The function that does the registration is returned.
   llvm::Function *createOffloadingBinaryDescriptorRegistration();
 
-  /// \brief Creates offloading entry for the provided entry ID \a ID,
-  /// address \a Addr and size \a Size.
-  void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
-  uint64_t Size);
-
   /// \brief Creates all the offload entries in the current compilation unit
   /// along with the associated metadata.
   void createOffloadEntriesAndInfoMetadata();

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=264018=264017=264018=diff
==
--- 

r263784 - Revert r263783 as buildbot failure is being investigated.

2016-03-19 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Fri Mar 18 07:39:40 2016
New Revision: 263784

URL: http://llvm.org/viewvc/llvm-project?rev=263784=rev
Log:
Revert r263783 as buildbot failure is being investigated.


Removed:
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=263784=263783=263784=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Mar 18 07:39:40 2016
@@ -4181,14 +4181,6 @@ void CGOpenMPRuntime::emitTargetOutlined
 CGF.EmitStmt(CS.getCapturedStmt());
   };
 
-  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
-   IsOffloadEntry, CodeGen);
-}
-
-void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
-const OMPExecutableDirective , StringRef ParentName,
-llvm::Function *, llvm::Constant *,
-bool IsOffloadEntry, const RegionCodeGenTy ) {
   // Create a unique name for the entry function using the source location
   // information of the current target region. The name will be something like:
   //
@@ -4210,8 +4202,6 @@ void CGOpenMPRuntime::emitTargetOutlined
<< llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
   }
 
-  const CapturedStmt  = *cast(D.getAssociatedStmt());
-
   CodeGenFunction CGF(CGM, true);
   CGOpenMPTargetRegionInfo CGInfo(CS, CodeGen, EntryFnName);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=263784=263783=263784=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Fri Mar 18 07:39:40 2016
@@ -49,31 +49,7 @@ class CodeGenModule;
 typedef llvm::function_ref RegionCodeGenTy;
 
 class CGOpenMPRuntime {
-protected:
   CodeGenModule 
-
-  /// \brief Creates offloading entry for the provided entry ID \a ID,
-  /// address \a Addr and size \a Size.
-  virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
-  uint64_t Size);
-
-  /// \brief Helper to emit outlined function for 'target' directive.
-  /// \param D Directive to emit.
-  /// \param ParentName Name of the function that encloses the target region.
-  /// \param OutlinedFn Outlined function value to be defined by this call.
-  /// \param OutlinedFnID Outlined function ID value to be defined by this 
call.
-  /// \param IsOffloadEntry True if the outlined function is an offload entry.
-  /// \param CodeGen Lambda codegen specific to an accelerator device.
-  /// An oulined function may not be an entry if, e.g. the if clause always
-  /// evaluates to false.
-  virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective 
,
-StringRef ParentName,
-llvm::Function *,
-llvm::Constant *,
-bool IsOffloadEntry,
-const RegionCodeGenTy 
);
-
-private:
   /// \brief Default const ident_t object used for initialization of all other
   /// ident_t objects.
   llvm::Constant *DefaultOpenMPPSource = nullptr;
@@ -291,6 +267,11 @@ private:
   /// compilation unit. The function that does the registration is returned.
   llvm::Function *createOffloadingBinaryDescriptorRegistration();
 
+  /// \brief Creates offloading entry for the provided entry ID \a ID,
+  /// address \a Addr and size \a Size.
+  void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
+  uint64_t Size);
+
   /// \brief Creates all the offload entries in the current compilation unit
   /// along with the associated metadata.
   void createOffloadEntriesAndInfoMetadata();

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=263784=263783=263784=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Fri Mar 18 07:39:40 2016
@@ -18,326 +18,5 @@
 using namespace clang;
 using namespace CodeGen;
 
-/// \brief Get the GPU warp size.
-llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXWarpSize(CodeGenFunction ) {
-  CGBuilderTy  = CGF.Builder;
-  return Bld.CreateCall(
-  

r263783 - [OpenMP] Base support for target directive codegen on NVPTX device.

2016-03-19 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Fri Mar 18 06:47:43 2016
New Revision: 263783

URL: http://llvm.org/viewvc/llvm-project?rev=263783=rev
Log:
[OpenMP] Base support for target directive codegen on NVPTX device.

Summary:
Reworked test case after buildbot failure on windows.

This patch adds base support for codegen of the target directive on the NVPTX 
device.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D17877


Added:
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=263783=263782=263783=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Mar 18 06:47:43 2016
@@ -4181,6 +4181,14 @@ void CGOpenMPRuntime::emitTargetOutlined
 CGF.EmitStmt(CS.getCapturedStmt());
   };
 
+  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
+   IsOffloadEntry, CodeGen);
+}
+
+void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
+const OMPExecutableDirective , StringRef ParentName,
+llvm::Function *, llvm::Constant *,
+bool IsOffloadEntry, const RegionCodeGenTy ) {
   // Create a unique name for the entry function using the source location
   // information of the current target region. The name will be something like:
   //
@@ -4202,6 +4210,8 @@ void CGOpenMPRuntime::emitTargetOutlined
<< llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
   }
 
+  const CapturedStmt  = *cast(D.getAssociatedStmt());
+
   CodeGenFunction CGF(CGM, true);
   CGOpenMPTargetRegionInfo CGInfo(CS, CodeGen, EntryFnName);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=263783=263782=263783=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Fri Mar 18 06:47:43 2016
@@ -49,7 +49,31 @@ class CodeGenModule;
 typedef llvm::function_ref RegionCodeGenTy;
 
 class CGOpenMPRuntime {
+protected:
   CodeGenModule 
+
+  /// \brief Creates offloading entry for the provided entry ID \a ID,
+  /// address \a Addr and size \a Size.
+  virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
+  uint64_t Size);
+
+  /// \brief Helper to emit outlined function for 'target' directive.
+  /// \param D Directive to emit.
+  /// \param ParentName Name of the function that encloses the target region.
+  /// \param OutlinedFn Outlined function value to be defined by this call.
+  /// \param OutlinedFnID Outlined function ID value to be defined by this 
call.
+  /// \param IsOffloadEntry True if the outlined function is an offload entry.
+  /// \param CodeGen Lambda codegen specific to an accelerator device.
+  /// An oulined function may not be an entry if, e.g. the if clause always
+  /// evaluates to false.
+  virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective 
,
+StringRef ParentName,
+llvm::Function *,
+llvm::Constant *,
+bool IsOffloadEntry,
+const RegionCodeGenTy 
);
+
+private:
   /// \brief Default const ident_t object used for initialization of all other
   /// ident_t objects.
   llvm::Constant *DefaultOpenMPPSource = nullptr;
@@ -267,11 +291,6 @@ class CGOpenMPRuntime {
   /// compilation unit. The function that does the registration is returned.
   llvm::Function *createOffloadingBinaryDescriptorRegistration();
 
-  /// \brief Creates offloading entry for the provided entry ID \a ID,
-  /// address \a Addr and size \a Size.
-  void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
-  uint64_t Size);
-
   /// \brief Creates all the offload entries in the current compilation unit
   /// along with the associated metadata.
   void createOffloadEntriesAndInfoMetadata();

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=263783=263782=263783=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Fri Mar 18 06:47:43 2016

r263589 - Revert commit http://reviews.llvm.org/D17877 to fix tests on x86.

2016-03-15 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Mar 15 16:26:34 2016
New Revision: 263589

URL: http://llvm.org/viewvc/llvm-project?rev=263589=rev
Log:
Revert commit http://reviews.llvm.org/D17877 to fix tests on x86.


Removed:
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=263589=263588=263589=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Mar 15 16:26:34 2016
@@ -4145,14 +4145,6 @@ void CGOpenMPRuntime::emitTargetOutlined
 CGF.EmitStmt(CS.getCapturedStmt());
   };
 
-  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
-   IsOffloadEntry, CodeGen);
-}
-
-void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
-const OMPExecutableDirective , StringRef ParentName,
-llvm::Function *, llvm::Constant *,
-bool IsOffloadEntry, const RegionCodeGenTy ) {
   // Create a unique name for the entry function using the source location
   // information of the current target region. The name will be something like:
   //
@@ -4174,8 +4166,6 @@ void CGOpenMPRuntime::emitTargetOutlined
<< llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
   }
 
-  const CapturedStmt  = *cast(D.getAssociatedStmt());
-
   CodeGenFunction CGF(CGM, true);
   CGOpenMPTargetRegionInfo CGInfo(CS, CodeGen, EntryFnName);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=263589=263588=263589=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Tue Mar 15 16:26:34 2016
@@ -49,31 +49,7 @@ class CodeGenModule;
 typedef llvm::function_ref RegionCodeGenTy;
 
 class CGOpenMPRuntime {
-protected:
   CodeGenModule 
-
-  /// \brief Creates offloading entry for the provided entry ID \a ID,
-  /// address \a Addr and size \a Size.
-  virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
-  uint64_t Size);
-
-  /// \brief Helper to emit outlined function for 'target' directive.
-  /// \param D Directive to emit.
-  /// \param ParentName Name of the function that encloses the target region.
-  /// \param OutlinedFn Outlined function value to be defined by this call.
-  /// \param OutlinedFnID Outlined function ID value to be defined by this 
call.
-  /// \param IsOffloadEntry True if the outlined function is an offload entry.
-  /// \param CodeGen Lambda codegen specific to an accelerator device.
-  /// An oulined function may not be an entry if, e.g. the if clause always
-  /// evaluates to false.
-  virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective 
,
-StringRef ParentName,
-llvm::Function *,
-llvm::Constant *,
-bool IsOffloadEntry,
-const RegionCodeGenTy 
);
-
-private:
   /// \brief Default const ident_t object used for initialization of all other
   /// ident_t objects.
   llvm::Constant *DefaultOpenMPPSource = nullptr;
@@ -291,6 +267,11 @@ private:
   /// compilation unit. The function that does the registration is returned.
   llvm::Function *createOffloadingBinaryDescriptorRegistration();
 
+  /// \brief Creates offloading entry for the provided entry ID \a ID,
+  /// address \a Addr and size \a Size.
+  void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
+  uint64_t Size);
+
   /// \brief Creates all the offload entries in the current compilation unit
   /// along with the associated metadata.
   void createOffloadEntriesAndInfoMetadata();

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=263589=263588=263589=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Tue Mar 15 16:26:34 2016
@@ -18,326 +18,5 @@
 using namespace clang;
 using namespace CodeGen;
 
-/// \brief Get the GPU warp size.
-llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXWarpSize(CodeGenFunction ) {
-  CGBuilderTy  = CGF.Builder;
-  return Bld.CreateCall(
- 

r263587 - [OpenMP] Base support for target directive codegen on NVPTX device.

2016-03-15 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Mar 15 16:04:57 2016
New Revision: 263587

URL: http://llvm.org/viewvc/llvm-project?rev=263587=rev
Log:
[OpenMP] Base support for target directive codegen on NVPTX device.

Summary:
This patch adds base support for codegen of the target directive on the NVPTX 
device.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D17877


Added:
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=263587=263586=263587=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Mar 15 16:04:57 2016
@@ -4145,6 +4145,14 @@ void CGOpenMPRuntime::emitTargetOutlined
 CGF.EmitStmt(CS.getCapturedStmt());
   };
 
+  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
+   IsOffloadEntry, CodeGen);
+}
+
+void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
+const OMPExecutableDirective , StringRef ParentName,
+llvm::Function *, llvm::Constant *,
+bool IsOffloadEntry, const RegionCodeGenTy ) {
   // Create a unique name for the entry function using the source location
   // information of the current target region. The name will be something like:
   //
@@ -4166,6 +4174,8 @@ void CGOpenMPRuntime::emitTargetOutlined
<< llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
   }
 
+  const CapturedStmt  = *cast(D.getAssociatedStmt());
+
   CodeGenFunction CGF(CGM, true);
   CGOpenMPTargetRegionInfo CGInfo(CS, CodeGen, EntryFnName);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=263587=263586=263587=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Tue Mar 15 16:04:57 2016
@@ -49,7 +49,31 @@ class CodeGenModule;
 typedef llvm::function_ref RegionCodeGenTy;
 
 class CGOpenMPRuntime {
+protected:
   CodeGenModule 
+
+  /// \brief Creates offloading entry for the provided entry ID \a ID,
+  /// address \a Addr and size \a Size.
+  virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
+  uint64_t Size);
+
+  /// \brief Helper to emit outlined function for 'target' directive.
+  /// \param D Directive to emit.
+  /// \param ParentName Name of the function that encloses the target region.
+  /// \param OutlinedFn Outlined function value to be defined by this call.
+  /// \param OutlinedFnID Outlined function ID value to be defined by this 
call.
+  /// \param IsOffloadEntry True if the outlined function is an offload entry.
+  /// \param CodeGen Lambda codegen specific to an accelerator device.
+  /// An oulined function may not be an entry if, e.g. the if clause always
+  /// evaluates to false.
+  virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective 
,
+StringRef ParentName,
+llvm::Function *,
+llvm::Constant *,
+bool IsOffloadEntry,
+const RegionCodeGenTy 
);
+
+private:
   /// \brief Default const ident_t object used for initialization of all other
   /// ident_t objects.
   llvm::Constant *DefaultOpenMPPSource = nullptr;
@@ -267,11 +291,6 @@ class CGOpenMPRuntime {
   /// compilation unit. The function that does the registration is returned.
   llvm::Function *createOffloadingBinaryDescriptorRegistration();
 
-  /// \brief Creates offloading entry for the provided entry ID \a ID,
-  /// address \a Addr and size \a Size.
-  void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
-  uint64_t Size);
-
   /// \brief Creates all the offload entries in the current compilation unit
   /// along with the associated metadata.
   void createOffloadEntriesAndInfoMetadata();

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=263587=263586=263587=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Tue Mar 15 16:04:57 2016
@@ -18,5 +18,326 @@
 using namespace clang;
 using 

r263555 - Reverted http://reviews.llvm.org/D17877 to fix tests.

2016-03-15 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Mar 15 11:19:13 2016
New Revision: 263555

URL: http://llvm.org/viewvc/llvm-project?rev=263555=rev
Log:
Reverted http://reviews.llvm.org/D17877 to fix tests.


Removed:
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=263555=263554=263555=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Mar 15 11:19:13 2016
@@ -4145,14 +4145,6 @@ void CGOpenMPRuntime::emitTargetOutlined
 CGF.EmitStmt(CS.getCapturedStmt());
   };
 
-  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
-   IsOffloadEntry, CodeGen);
-}
-
-void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
-const OMPExecutableDirective , StringRef ParentName,
-llvm::Function *, llvm::Constant *,
-bool IsOffloadEntry, const RegionCodeGenTy ) {
   // Create a unique name for the entry function using the source location
   // information of the current target region. The name will be something like:
   //
@@ -4174,8 +4166,6 @@ void CGOpenMPRuntime::emitTargetOutlined
<< llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
   }
 
-  const CapturedStmt  = *cast(D.getAssociatedStmt());
-
   CodeGenFunction CGF(CGM, true);
   CGOpenMPTargetRegionInfo CGInfo(CS, CodeGen, EntryFnName);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=263555=263554=263555=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Tue Mar 15 11:19:13 2016
@@ -49,31 +49,7 @@ class CodeGenModule;
 typedef llvm::function_ref RegionCodeGenTy;
 
 class CGOpenMPRuntime {
-protected:
   CodeGenModule 
-
-  /// \brief Creates offloading entry for the provided entry ID \a ID,
-  /// address \a Addr and size \a Size.
-  virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
-  uint64_t Size);
-
-  /// \brief Helper to emit outlined function for 'target' directive.
-  /// \param D Directive to emit.
-  /// \param ParentName Name of the function that encloses the target region.
-  /// \param OutlinedFn Outlined function value to be defined by this call.
-  /// \param OutlinedFnID Outlined function ID value to be defined by this 
call.
-  /// \param IsOffloadEntry True if the outlined function is an offload entry.
-  /// \param CodeGen Lambda codegen specific to an accelerator device.
-  /// An oulined function may not be an entry if, e.g. the if clause always
-  /// evaluates to false.
-  virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective 
,
-StringRef ParentName,
-llvm::Function *,
-llvm::Constant *,
-bool IsOffloadEntry,
-const RegionCodeGenTy 
);
-
-private:
   /// \brief Default const ident_t object used for initialization of all other
   /// ident_t objects.
   llvm::Constant *DefaultOpenMPPSource = nullptr;
@@ -291,6 +267,11 @@ private:
   /// compilation unit. The function that does the registration is returned.
   llvm::Function *createOffloadingBinaryDescriptorRegistration();
 
+  /// \brief Creates offloading entry for the provided entry ID \a ID,
+  /// address \a Addr and size \a Size.
+  void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
+  uint64_t Size);
+
   /// \brief Creates all the offload entries in the current compilation unit
   /// along with the associated metadata.
   void createOffloadEntriesAndInfoMetadata();

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=263555=263554=263555=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Tue Mar 15 11:19:13 2016
@@ -18,326 +18,5 @@
 using namespace clang;
 using namespace CodeGen;
 
-/// \brief Get the GPU warp size.
-llvm::Value *CGOpenMPRuntimeNVPTX::getNVPTXWarpSize(CodeGenFunction ) {
-  CGBuilderTy  = CGF.Builder;
-  return Bld.CreateCall(
-  

r263552 - [OpenMP] Base support for target directive codegen on NVPTX device.

2016-03-15 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Tue Mar 15 10:24:52 2016
New Revision: 263552

URL: http://llvm.org/viewvc/llvm-project?rev=263552=rev
Log:
[OpenMP] Base support for target directive codegen on NVPTX device.

Summary:
This patch adds base support for codegen of the target directive on the NVPTX 
device.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D17877


Added:
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=263552=263551=263552=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Mar 15 10:24:52 2016
@@ -4145,6 +4145,14 @@ void CGOpenMPRuntime::emitTargetOutlined
 CGF.EmitStmt(CS.getCapturedStmt());
   };
 
+  emitTargetOutlinedFunctionHelper(D, ParentName, OutlinedFn, OutlinedFnID,
+   IsOffloadEntry, CodeGen);
+}
+
+void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
+const OMPExecutableDirective , StringRef ParentName,
+llvm::Function *, llvm::Constant *,
+bool IsOffloadEntry, const RegionCodeGenTy ) {
   // Create a unique name for the entry function using the source location
   // information of the current target region. The name will be something like:
   //
@@ -4166,6 +4174,8 @@ void CGOpenMPRuntime::emitTargetOutlined
<< llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
   }
 
+  const CapturedStmt  = *cast(D.getAssociatedStmt());
+
   CodeGenFunction CGF(CGM, true);
   CGOpenMPTargetRegionInfo CGInfo(CS, CodeGen, EntryFnName);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, );

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=263552=263551=263552=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Tue Mar 15 10:24:52 2016
@@ -49,7 +49,31 @@ class CodeGenModule;
 typedef llvm::function_ref RegionCodeGenTy;
 
 class CGOpenMPRuntime {
+protected:
   CodeGenModule 
+
+  /// \brief Creates offloading entry for the provided entry ID \a ID,
+  /// address \a Addr and size \a Size.
+  virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
+  uint64_t Size);
+
+  /// \brief Helper to emit outlined function for 'target' directive.
+  /// \param D Directive to emit.
+  /// \param ParentName Name of the function that encloses the target region.
+  /// \param OutlinedFn Outlined function value to be defined by this call.
+  /// \param OutlinedFnID Outlined function ID value to be defined by this 
call.
+  /// \param IsOffloadEntry True if the outlined function is an offload entry.
+  /// \param CodeGen Lambda codegen specific to an accelerator device.
+  /// An oulined function may not be an entry if, e.g. the if clause always
+  /// evaluates to false.
+  virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective 
,
+StringRef ParentName,
+llvm::Function *,
+llvm::Constant *,
+bool IsOffloadEntry,
+const RegionCodeGenTy 
);
+
+private:
   /// \brief Default const ident_t object used for initialization of all other
   /// ident_t objects.
   llvm::Constant *DefaultOpenMPPSource = nullptr;
@@ -267,11 +291,6 @@ class CGOpenMPRuntime {
   /// compilation unit. The function that does the registration is returned.
   llvm::Function *createOffloadingBinaryDescriptorRegistration();
 
-  /// \brief Creates offloading entry for the provided entry ID \a ID,
-  /// address \a Addr and size \a Size.
-  void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr,
-  uint64_t Size);
-
   /// \brief Creates all the offload entries in the current compilation unit
   /// along with the associated metadata.
   void createOffloadEntriesAndInfoMetadata();

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=263552=263551=263552=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Tue Mar 15 10:24:52 2016
@@ -18,5 +18,326 @@
 using namespace clang;
 using 

r259418 - Undoing commit r259366 to debug buildbot failure.

2016-02-01 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Mon Feb  1 16:02:05 2016
New Revision: 259418

URL: http://llvm.org/viewvc/llvm-project?rev=259418=rev
Log:
Undoing commit r259366 to debug buildbot failure.
> http://reviews.llvm.org/D16758


Modified:
cfe/trunk/include/clang/Basic/OpenMPKinds.h
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/distribute_private_messages.cpp
cfe/trunk/test/OpenMP/nesting_of_regions.cpp
cfe/trunk/test/OpenMP/target_data_device_messages.cpp
cfe/trunk/test/OpenMP/target_device_messages.cpp
cfe/trunk/test/OpenMP/target_if_messages.cpp
cfe/trunk/test/OpenMP/target_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_default_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_device_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_firstprivate_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_if_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_map_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_num_threads_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_private_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_proc_bind_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_shared_messages.cpp
cfe/trunk/test/OpenMP/target_private_messages.cpp
cfe/trunk/test/OpenMP/teams_reduction_messages.cpp

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.h?rev=259418=259417=259418=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.h (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.h Mon Feb  1 16:02:05 2016
@@ -156,20 +156,11 @@ bool isOpenMPTaskLoopDirective(OpenMPDir
 /// parallel', otherwise - false.
 bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind);
 
-/// \brief Checks if the specified directive is a target code offload 
directive.
+/// \brief Checks if the specified directive is a target-kind directive.
 /// \param DKind Specified directive.
-/// \return true - the directive is a target code offload directive like
-/// 'omp target', 'omp target parallel', 'omp target xxx'
+/// \return true - the directive is a target-like directive like 'omp target',
 /// otherwise - false.
-bool isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind);
-
-/// \brief Checks if the specified directive is a target data offload 
directive.
-/// \param DKind Specified directive.
-/// \return true - the directive is a target data offload directive like
-/// 'omp target data', 'omp target update', 'omp target enter data',
-/// 'omp target exit data'
-/// otherwise - false.
-bool isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind);
+bool isOpenMPTargetDirective(OpenMPDirectiveKind DKind);
 
 /// \brief Checks if the specified directive is a teams-kind directive.
 /// \param DKind Specified directive.

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=259418=259417=259418=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Mon Feb  1 16:02:05 2016
@@ -576,15 +576,8 @@ bool clang::isOpenMPParallelDirective(Op
  // TODO add next directives.
 }
 
-bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
-  // TODO add next directives.
-  return DKind == OMPD_target || DKind == OMPD_target_parallel;
-}
-
-bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
-  // TODO add target update directive check.
-  return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
- DKind == OMPD_target_exit_data;
+bool clang::isOpenMPTargetDirective(OpenMPDirectiveKind DKind) {
+  return DKind == OMPD_target; // TODO add next directives.
 }
 
 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=259418=259417=259418=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Mon Feb  1 16:02:05 2016
@@ -809,7 +809,7 @@ bool Sema::IsOpenMPCapturedByRef(ValueDe
   auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope);
   auto Ty = D->getType();
 
-  if (isOpenMPTargetExecutionDirective(DKind)) {
+  if (isOpenMPTargetDirective(DKind)) {
 // This table summarizes how a given variable should be passed to the 
device
 // given its type and the clauses where it appears. This table is based on
 // the description in OpenMP 4.5 [2.10.4, target Construct] and
@@ -907,7 +907,7 @@ bool 

r259464 - [OpenMP] Prevent nesting of target constructs within target code execution regions.

2016-02-01 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Mon Feb  1 22:00:47 2016
New Revision: 259464

URL: http://llvm.org/viewvc/llvm-project?rev=259464=rev
Log:
[OpenMP] Prevent nesting of target constructs within target code execution 
regions.

Summary:
This patch enhances Sema to check for the following restriction:

OpenMP 4.5 [2.17 Nesting of Regions]
If a target, target update, target data, target enter data, or
target exit data construct is encountered during execution of a
target region, the behavior is unspecified.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D16758


Modified:
cfe/trunk/include/clang/Basic/OpenMPKinds.h
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/distribute_private_messages.cpp
cfe/trunk/test/OpenMP/nesting_of_regions.cpp
cfe/trunk/test/OpenMP/target_data_device_messages.cpp
cfe/trunk/test/OpenMP/target_device_messages.cpp
cfe/trunk/test/OpenMP/target_if_messages.cpp
cfe/trunk/test/OpenMP/target_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_default_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_device_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_firstprivate_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_if_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_map_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_num_threads_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_private_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_proc_bind_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_shared_messages.cpp
cfe/trunk/test/OpenMP/target_private_messages.cpp
cfe/trunk/test/OpenMP/teams_reduction_messages.cpp

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.h?rev=259464=259463=259464=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.h (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.h Mon Feb  1 22:00:47 2016
@@ -156,11 +156,20 @@ bool isOpenMPTaskLoopDirective(OpenMPDir
 /// parallel', otherwise - false.
 bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind);
 
-/// \brief Checks if the specified directive is a target-kind directive.
+/// \brief Checks if the specified directive is a target code offload 
directive.
 /// \param DKind Specified directive.
-/// \return true - the directive is a target-like directive like 'omp target',
+/// \return true - the directive is a target code offload directive like
+/// 'omp target', 'omp target parallel', 'omp target xxx'
 /// otherwise - false.
-bool isOpenMPTargetDirective(OpenMPDirectiveKind DKind);
+bool isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind);
+
+/// \brief Checks if the specified directive is a target data offload 
directive.
+/// \param DKind Specified directive.
+/// \return true - the directive is a target data offload directive like
+/// 'omp target data', 'omp target update', 'omp target enter data',
+/// 'omp target exit data'
+/// otherwise - false.
+bool isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind);
 
 /// \brief Checks if the specified directive is a teams-kind directive.
 /// \param DKind Specified directive.

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=259464=259463=259464=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Mon Feb  1 22:00:47 2016
@@ -576,8 +576,15 @@ bool clang::isOpenMPParallelDirective(Op
  // TODO add next directives.
 }
 
-bool clang::isOpenMPTargetDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_target; // TODO add next directives.
+bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
+  // TODO add next directives.
+  return DKind == OMPD_target || DKind == OMPD_target_parallel;
+}
+
+bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
+  // TODO add target update directive check.
+  return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
+ DKind == OMPD_target_exit_data;
 }
 
 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=259464=259463=259464=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Mon Feb  1 22:00:47 2016
@@ -809,7 +809,7 @@ bool Sema::IsOpenMPCapturedByRef(ValueDe
   auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope);
   auto Ty = D->getType();
 
-  if 

r259366 - [OpenMP] Prevent nesting of target constructs within target code execution regions.

2016-02-01 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Mon Feb  1 10:32:47 2016
New Revision: 259366

URL: http://llvm.org/viewvc/llvm-project?rev=259366=rev
Log:
[OpenMP] Prevent nesting of target constructs within target code execution 
regions.

Summary:
This patch enhances Sema to check for the following restriction:

OpenMP 4.5 [2.17 Nesting of Regions]
If a target, target update, target data, target enter data, or
target exit data construct is encountered during execution of a
target region, the behavior is unspecified.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D16758


Modified:
cfe/trunk/include/clang/Basic/OpenMPKinds.h
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/distribute_private_messages.cpp
cfe/trunk/test/OpenMP/nesting_of_regions.cpp
cfe/trunk/test/OpenMP/target_data_device_messages.cpp
cfe/trunk/test/OpenMP/target_device_messages.cpp
cfe/trunk/test/OpenMP/target_if_messages.cpp
cfe/trunk/test/OpenMP/target_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_default_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_device_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_firstprivate_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_if_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_map_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_num_threads_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_private_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_proc_bind_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_shared_messages.cpp
cfe/trunk/test/OpenMP/target_private_messages.cpp
cfe/trunk/test/OpenMP/teams_reduction_messages.cpp

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.h?rev=259366=259365=259366=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.h (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.h Mon Feb  1 10:32:47 2016
@@ -156,11 +156,20 @@ bool isOpenMPTaskLoopDirective(OpenMPDir
 /// parallel', otherwise - false.
 bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind);
 
-/// \brief Checks if the specified directive is a target-kind directive.
+/// \brief Checks if the specified directive is a target code offload 
directive.
 /// \param DKind Specified directive.
-/// \return true - the directive is a target-like directive like 'omp target',
+/// \return true - the directive is a target code offload directive like
+/// 'omp target', 'omp target parallel', 'omp target xxx'
 /// otherwise - false.
-bool isOpenMPTargetDirective(OpenMPDirectiveKind DKind);
+bool isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind);
+
+/// \brief Checks if the specified directive is a target data offload 
directive.
+/// \param DKind Specified directive.
+/// \return true - the directive is a target data offload directive like
+/// 'omp target data', 'omp target update', 'omp target enter data',
+/// 'omp target exit data'
+/// otherwise - false.
+bool isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind);
 
 /// \brief Checks if the specified directive is a teams-kind directive.
 /// \param DKind Specified directive.

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=259366=259365=259366=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Mon Feb  1 10:32:47 2016
@@ -576,8 +576,15 @@ bool clang::isOpenMPParallelDirective(Op
  // TODO add next directives.
 }
 
-bool clang::isOpenMPTargetDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_target; // TODO add next directives.
+bool clang::isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind) {
+  // TODO add next directives.
+  return DKind == OMPD_target || DKind == OMPD_target_parallel;
+}
+
+bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
+  // TODO add target update directive check.
+  return DKind == OMPD_target_data || DKind == OMPD_target_enter_data ||
+ DKind == OMPD_target_exit_data;
 }
 
 bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) {

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=259366=259365=259366=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Mon Feb  1 10:32:47 2016
@@ -809,7 +809,7 @@ bool Sema::IsOpenMPCapturedByRef(ValueDe
   auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope);
   auto Ty = D->getType();
 
-  if 

r258502 - [OpenMP] Sema for depend clause on target exit data directive.

2016-01-22 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Fri Jan 22 08:58:21 2016
New Revision: 258502

URL: http://llvm.org/viewvc/llvm-project?rev=258502=rev
Log:
[OpenMP] Sema for depend clause on target exit data directive.

Summary:
Accept depend clause on target exit data directive in sema and add test cases.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D16401


Added:
cfe/trunk/test/OpenMP/target_exit_data_depend_messages.cpp
Modified:
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=258502=258501=258502=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Fri Jan 22 08:58:21 2016
@@ -372,11 +372,11 @@ OPENMP_TARGET_ENTER_DATA_CLAUSE(nowait)
 OPENMP_TARGET_ENTER_DATA_CLAUSE(depend)
 
 // Clauses allowed for OpenMP directive 'target exit data'.
-// TODO More clauses for 'target exit data' directive.
 OPENMP_TARGET_EXIT_DATA_CLAUSE(if)
 OPENMP_TARGET_EXIT_DATA_CLAUSE(device)
 OPENMP_TARGET_EXIT_DATA_CLAUSE(map)
 OPENMP_TARGET_EXIT_DATA_CLAUSE(nowait)
+OPENMP_TARGET_EXIT_DATA_CLAUSE(depend)
 
 // Clauses allowed for OpenMP directive 'teams'.
 // TODO More clauses for 'teams' directive.

Modified: cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp?rev=258502=258501=258502=diff
==
--- cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp Fri Jan 22 08:58:21 
2016
@@ -43,6 +43,22 @@ T tmain(T argc, T *argv) {
 
 #pragma omp target exit data nowait map(always,release: e)
 
+#pragma omp target exit data depend(in : argc, argv[i:argc], x[:]) nowait 
map(from: i)
+
+#pragma omp target exit data nowait depend(in : argc, argv[i:argc], x[:]) 
map(from: i) if (target exit data: j > 0)
+
+#pragma omp target exit data map(from: i) depend(in : argc, argv[i:argc], 
x[:]) if (b) nowait
+
+#pragma omp target exit data map(from: c) depend(in : argc, argv[i:argc], 
x[:]) nowait
+
+#pragma omp target exit data map(from: c) depend(in : argc, argv[i:argc], 
x[:]) nowait if(b>e)
+
+#pragma omp target exit data nowait map(release: x[0:10], c) depend(in : argc, 
argv[i:argc], x[:])
+
+#pragma omp target exit data nowait map(from: c) depend(in : argc, 
argv[i:argc], x[:]) map(release: d)
+
+#pragma omp target exit data depend(in : argc, argv[i:argc], x[:]) nowait 
map(always,release: e)
+
   return 0;
 }
 
@@ -65,6 +81,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target exit data nowait map(release: x[0:10],c)
 // CHECK-NEXT: #pragma omp target exit data nowait map(from: c) map(release: d)
 // CHECK-NEXT: #pragma omp target exit data nowait map(always,release: e)
+// CHECK-NEXT: #pragma omp target exit data depend(in : 
argc,argv[i:argc],x[:]) nowait map(from: i)
+// CHECK-NEXT: #pragma omp target exit data nowait depend(in : 
argc,argv[i:argc],x[:]) map(from: i) if(target exit data: j > 0)
+// CHECK-NEXT: #pragma omp target exit data map(from: i) depend(in : 
argc,argv[i:argc],x[:]) if(b) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) depend(in : 
argc,argv[i:argc],x[:]) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) depend(in : 
argc,argv[i:argc],x[:]) nowait if(b > e)
+// CHECK-NEXT: #pragma omp target exit data nowait map(release: x[0:10],c) 
depend(in : argc,argv[i:argc],x[:])
+// CHECK-NEXT: #pragma omp target exit data nowait map(from: c) depend(in : 
argc,argv[i:argc],x[:]) map(release: d)
+// CHECK-NEXT: #pragma omp target exit data depend(in : 
argc,argv[i:argc],x[:]) nowait map(always,release: e)
 // CHECK: template  char tmain(char argc, char 
*argv) {
 // CHECK-NEXT: char i, j, b, c, d, e, x[20];
 // CHECK-NEXT: i = argc;
@@ -84,6 +108,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target exit data nowait map(release: x[0:10],c)
 // CHECK-NEXT: #pragma omp target exit data nowait map(from: c) map(release: d)
 // CHECK-NEXT: #pragma omp target exit data nowait map(always,release: e)
+// CHECK-NEXT: #pragma omp target exit data depend(in : 
argc,argv[i:argc],x[:]) nowait map(from: i)
+// CHECK-NEXT: #pragma omp target exit data nowait depend(in : 
argc,argv[i:argc],x[:]) map(from: i) if(target exit data: j > 0)
+// CHECK-NEXT: #pragma omp target exit data map(from: i) depend(in : 
argc,argv[i:argc],x[:]) if(b) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) depend(in : 
argc,argv[i:argc],x[:]) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) depend(in : 
argc,argv[i:argc],x[:]) nowait if(b > e)
+// CHECK-NEXT: #pragma omp target exit data nowait 

r258425 - [OpenMP] Check for at least one map clause on target data directive.

2016-01-21 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Jan 21 13:57:55 2016
New Revision: 258425

URL: http://llvm.org/viewvc/llvm-project?rev=258425=rev
Log:

[OpenMP] Check for at least one map clause on target data directive.

Summary:
Adds the following restriction in the OpenMP specifications.

OpenMP [2.10.1, Restrictions, p. 97]
At least one map clause must appear on the directive.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D16341


Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_data_ast_print.cpp
cfe/trunk/test/OpenMP/target_data_device_messages.cpp
cfe/trunk/test/OpenMP/target_data_if_messages.cpp
cfe/trunk/test/OpenMP/target_data_messages.c

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=258425=258424=258425=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Jan 21 13:57:55 2016
@@ -5618,6 +5618,14 @@ StmtResult Sema::ActOnOpenMPTargetDataDi
 
   assert(isa(AStmt) && "Captured statement expected");
 
+  // OpenMP [2.10.1, Restrictions, p. 97]
+  // At least one map clause must appear on the directive.
+  if (!HasMapClause(Clauses)) {
+Diag(StartLoc, diag::err_omp_no_map_for_directive) <<
+getOpenMPDirectiveName(OMPD_target_data);
+return StmtError();
+  }
+
   getCurFunction()->setHasBranchProtectedScope();
 
   return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses,

Modified: cfe/trunk/test/OpenMP/target_data_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_data_ast_print.cpp?rev=258425=258424=258425=diff
==
--- cfe/trunk/test/OpenMP/target_data_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/target_data_ast_print.cpp Thu Jan 21 13:57:55 2016
@@ -12,13 +12,13 @@ template 
 T tmain(T argc, T *argv) {
   T i, j, b, c, d, e, x[20];
 
-#pragma omp target data
+#pragma omp target data map(to: c)
   i = argc;
 
-#pragma omp target data if (target data: j > 0)
+#pragma omp target data map(to: c) if (target data: j > 0)
   foo();
 
-#pragma omp target data if (b)
+#pragma omp target data map(to: c) if (b)
   foo();
 
 #pragma omp target data map(c)
@@ -48,11 +48,11 @@ T tmain(T argc, T *argv) {
 
 // CHECK: template  int tmain(int argc, int 
*argv) {
 // CHECK-NEXT: int i, j, b, c, d, e, x[20];
-// CHECK-NEXT: #pragma omp target data
+// CHECK-NEXT: #pragma omp target data map(to: c)
 // CHECK-NEXT: i = argc;
-// CHECK-NEXT: #pragma omp target data if(target data: j > 0)
+// CHECK-NEXT: #pragma omp target data map(to: c) if(target data: j > 0)
 // CHECK-NEXT: foo();
-// CHECK-NEXT: #pragma omp target data if(b)
+// CHECK-NEXT: #pragma omp target data map(to: c) if(b)
 // CHECK-NEXT: foo();
 // CHECK-NEXT: #pragma omp target data map(tofrom: c)
 // CHECK-NEXT: foo();
@@ -70,11 +70,11 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: foo();
 // CHECK: template  char tmain(char argc, char 
*argv) {
 // CHECK-NEXT: char i, j, b, c, d, e, x[20];
-// CHECK-NEXT: #pragma omp target data
+// CHECK-NEXT: #pragma omp target data map(to: c)
 // CHECK-NEXT: i = argc;
-// CHECK-NEXT: #pragma omp target data if(target data: j > 0)
+// CHECK-NEXT: #pragma omp target data map(to: c) if(target data: j > 0)
 // CHECK-NEXT: foo();
-// CHECK-NEXT: #pragma omp target data if(b)
+// CHECK-NEXT: #pragma omp target data map(to: c) if(b)
 // CHECK-NEXT: foo();
 // CHECK-NEXT: #pragma omp target data map(tofrom: c)
 // CHECK-NEXT: foo();
@@ -92,11 +92,11 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: foo();
 // CHECK: template  T tmain(T argc, T *argv) {
 // CHECK-NEXT: T i, j, b, c, d, e, x[20];
-// CHECK-NEXT: #pragma omp target data
+// CHECK-NEXT: #pragma omp target data map(to: c)
 // CHECK-NEXT: i = argc;
-// CHECK-NEXT: #pragma omp target data if(target data: j > 0)
+// CHECK-NEXT: #pragma omp target data map(to: c) if(target data: j > 0)
 // CHECK-NEXT: foo();
-// CHECK-NEXT: #pragma omp target data if(b)
+// CHECK-NEXT: #pragma omp target data map(to: c) if(b)
 // CHECK-NEXT: foo();
 // CHECK-NEXT: #pragma omp target data map(tofrom: c)
 // CHECK-NEXT: foo();
@@ -118,17 +118,17 @@ int main (int argc, char **argv) {
   static int a;
 // CHECK: static int a;
 
-#pragma omp target data
-// CHECK:  #pragma omp target data
+#pragma omp target data map(to: c)
+// CHECK:  #pragma omp target data map(to: c)
   a=2;
 // CHECK-NEXT: a = 2;
-#pragma omp target data if (target data: b)
-// CHECK: #pragma omp target data if(target data: b)
+#pragma omp target data map(to: c) if (target data: b)
+// CHECK: #pragma omp target data map(to: c) if(target data: b)
   foo();
 // CHECK-NEXT: foo();
 
-#pragma omp target data if (b > g)
-// CHECK: #pragma omp target data if(b > g)
+#pragma omp target data map(to: c) if (b > g)
+// CHECK: #pragma omp 

r258441 - [OpenMP] Parsing + Sema for nowait clause on target directive

2016-01-21 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Jan 21 16:18:28 2016
New Revision: 258441

URL: http://llvm.org/viewvc/llvm-project?rev=258441=rev
Log:
[OpenMP] Parsing + Sema for nowait clause on target directive

Summary:
Allow nowait clause on target directive in sema and add test cases.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D16358


Added:
cfe/trunk/test/OpenMP/target_nowait_messages.cpp
Modified:
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/test/OpenMP/target_ast_print.cpp

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=258441=258440=258441=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Thu Jan 21 16:18:28 2016
@@ -355,6 +355,7 @@ OPENMP_TARGET_CLAUSE(if)
 OPENMP_TARGET_CLAUSE(device)
 OPENMP_TARGET_CLAUSE(map)
 OPENMP_TARGET_CLAUSE(private)
+OPENMP_TARGET_CLAUSE(nowait)
 
 // Clauses allowed for OpenMP directive 'target data'.
 // TODO More clauses for 'target data' directive.

Modified: cfe/trunk/test/OpenMP/target_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_ast_print.cpp?rev=258441=258440=258441=diff
==
--- cfe/trunk/test/OpenMP/target_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/target_ast_print.cpp Thu Jan 21 16:18:28 2016
@@ -25,6 +25,8 @@ T tmain(T argc, T *argv) {
   foo();
 #pragma omp target map(always,alloc: i)
   foo();
+#pragma omp target nowait
+  foo();
   return 0;
 }
 
@@ -44,6 +46,8 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: foo()
 // CHECK-NEXT: #pragma omp target map(always,alloc: i)
 // CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp target nowait
+// CHECK-NEXT: foo()
 // CHECK: template  char tmain(char argc, char 
*argv) {
 // CHECK-NEXT: char i, j, a[20]
 // CHECK-NEXT: #pragma omp target
@@ -60,6 +64,8 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: foo()
 // CHECK-NEXT: #pragma omp target map(always,alloc: i)
 // CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp target nowait
+// CHECK-NEXT: foo()
 // CHECK: template  T tmain(T argc, T *argv) {
 // CHECK-NEXT: T i, j, a[20]
 // CHECK-NEXT: #pragma omp target
@@ -76,6 +82,8 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: foo()
 // CHECK-NEXT: #pragma omp target map(always,alloc: i)
 // CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp target nowait
+// CHECK-NEXT: foo()
 
 // CHECK-LABEL: int main(int argc, char **argv) {
 int main (int argc, char **argv) {
@@ -115,6 +123,11 @@ int main (int argc, char **argv) {
   foo();
 // CHECK-NEXT: foo();
 
+#pragma omp target nowait
+// CHECK-NEXT: #pragma omp target nowait
+  foo();
+// CHECK-NEXT: foo();
+
   return tmain(argc, ) + tmain(argv[0][0], argv[0]);
 }
 

Added: cfe/trunk/test/OpenMP/target_nowait_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_nowait_messages.cpp?rev=258441=auto
==
--- cfe/trunk/test/OpenMP/target_nowait_messages.cpp (added)
+++ cfe/trunk/test/OpenMP/target_nowait_messages.cpp Thu Jan 21 16:18:28 2016
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp 
-ferror-limit 100 -o - %s
+
+void foo() {
+}
+
+int main(int argc, char **argv) {
+  #pragma omp target nowait( // expected-warning {{extra tokens at the end of 
'#pragma omp target' are ignored}}
+  foo();
+  #pragma omp target nowait (argc)) // expected-warning {{extra tokens at the 
end of '#pragma omp target' are ignored}}
+  foo();
+  #pragma omp target nowait device (-10u)
+  foo();
+  #pragma omp target nowait (3.14) device (-10u) // expected-warning {{extra 
tokens at the end of '#pragma omp target' are ignored}}
+  foo();
+
+  return 0;
+}


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


r258457 - [OpenMP] Parsing + Sema for nowait clause on target enter data directive.

2016-01-21 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Jan 21 18:03:50 2016
New Revision: 258457

URL: http://llvm.org/viewvc/llvm-project?rev=258457=rev
Log:
[OpenMP] Parsing + Sema for nowait clause on target enter data directive.

Summary:
Accept nowait clause on target enter data directive in sema and add test cases.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D16361


Added:
cfe/trunk/test/OpenMP/target_enter_data_nowait_messages.cpp
Modified:
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=258457=258456=258457=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Thu Jan 21 18:03:50 2016
@@ -368,6 +368,7 @@ OPENMP_TARGET_DATA_CLAUSE(map)
 OPENMP_TARGET_ENTER_DATA_CLAUSE(if)
 OPENMP_TARGET_ENTER_DATA_CLAUSE(device)
 OPENMP_TARGET_ENTER_DATA_CLAUSE(map)
+OPENMP_TARGET_ENTER_DATA_CLAUSE(nowait)
 
 // Clauses allowed for OpenMP directive 'target exit data'.
 // TODO More clauses for 'target exit data' directive.

Modified: cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp?rev=258457=258456=258457=diff
==
--- cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp Thu Jan 21 18:03:50 
2016
@@ -27,6 +27,22 @@ T tmain(T argc, T *argv) {
 
 #pragma omp target enter data map(always,alloc: e)
 
+#pragma omp target enter data nowait map(to: i)
+
+#pragma omp target enter data nowait map(to: i) if (target enter data: j > 0)
+
+#pragma omp target enter data map(to: i) if (b) nowait
+
+#pragma omp target enter data map(to: c) nowait
+
+#pragma omp target enter data map(to: c) nowait if(b>e)
+
+#pragma omp target enter data nowait map(alloc: x[0:10], c)
+
+#pragma omp target enter data nowait map(to: c) map(alloc: d)
+
+#pragma omp target enter data nowait map(always,alloc: e)
+
   return 0;
 }
 
@@ -41,6 +57,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target enter data map(alloc: x[0:10],c)
 // CHECK-NEXT: #pragma omp target enter data map(to: c) map(alloc: d)
 // CHECK-NEXT: #pragma omp target enter data map(always,alloc: e)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: i)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: i) if(target enter 
data: j > 0)
+// CHECK-NEXT: #pragma omp target enter data map(to: i) if(b) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) nowait if(b > e)
+// CHECK-NEXT: #pragma omp target enter data nowait map(alloc: x[0:10],c)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: c) map(alloc: d)
+// CHECK-NEXT: #pragma omp target enter data nowait map(always,alloc: e)
 // CHECK: template  char tmain(char argc, char 
*argv) {
 // CHECK-NEXT: char i, j, b, c, d, e, x[20];
 // CHECK-NEXT: i = argc;
@@ -52,6 +76,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target enter data map(alloc: x[0:10],c)
 // CHECK-NEXT: #pragma omp target enter data map(to: c) map(alloc: d)
 // CHECK-NEXT: #pragma omp target enter data map(always,alloc: e)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: i)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: i) if(target enter 
data: j > 0)
+// CHECK-NEXT: #pragma omp target enter data map(to: i) if(b) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) nowait if(b > e)
+// CHECK-NEXT: #pragma omp target enter data nowait map(alloc: x[0:10],c)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: c) map(alloc: d)
+// CHECK-NEXT: #pragma omp target enter data nowait map(always,alloc: e)
 // CHECK: template  T tmain(T argc, T *argv) {
 // CHECK-NEXT: T i, j, b, c, d, e, x[20];
 // CHECK-NEXT: i = argc;
@@ -63,6 +95,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target enter data map(alloc: x[0:10],c)
 // CHECK-NEXT: #pragma omp target enter data map(to: c) map(alloc: d)
 // CHECK-NEXT: #pragma omp target enter data map(always,alloc: e)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: i)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: i) if(target enter 
data: j > 0)
+// CHECK-NEXT: #pragma omp target enter data map(to: i) if(b) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) nowait if(b > e)
+// CHECK-NEXT: #pragma omp target enter data nowait map(alloc: x[0:10],c)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: 

r258460 - [OpenMP] Sema for depend clause on target directive.

2016-01-21 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Jan 21 18:49:21 2016
New Revision: 258460

URL: http://llvm.org/viewvc/llvm-project?rev=258460=rev
Log:
[OpenMP] Sema for depend clause on target directive.

Summary:
Accept depend clause on target directive in sema and add test cases.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D16375


Added:
cfe/trunk/test/OpenMP/target_depend_messages.cpp
Modified:
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/test/OpenMP/target_ast_print.cpp

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=258460=258459=258460=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Thu Jan 21 18:49:21 2016
@@ -356,6 +356,7 @@ OPENMP_TARGET_CLAUSE(device)
 OPENMP_TARGET_CLAUSE(map)
 OPENMP_TARGET_CLAUSE(private)
 OPENMP_TARGET_CLAUSE(nowait)
+OPENMP_TARGET_CLAUSE(depend)
 
 // Clauses allowed for OpenMP directive 'target data'.
 // TODO More clauses for 'target data' directive.

Modified: cfe/trunk/test/OpenMP/target_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_ast_print.cpp?rev=258460=258459=258460=diff
==
--- cfe/trunk/test/OpenMP/target_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/target_ast_print.cpp Thu Jan 21 18:49:21 2016
@@ -27,6 +27,8 @@ T tmain(T argc, T *argv) {
   foo();
 #pragma omp target nowait
   foo();
+#pragma omp target depend(in : argc, argv[i:argc], a[:])
+  foo();
   return 0;
 }
 
@@ -48,6 +50,8 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: foo()
 // CHECK-NEXT: #pragma omp target nowait
 // CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp target depend(in : argc,argv[i:argc],a[:])
+// CHECK-NEXT: foo()
 // CHECK: template  char tmain(char argc, char 
*argv) {
 // CHECK-NEXT: char i, j, a[20]
 // CHECK-NEXT: #pragma omp target
@@ -66,6 +70,8 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: foo()
 // CHECK-NEXT: #pragma omp target nowait
 // CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp target depend(in : argc,argv[i:argc],a[:])
+// CHECK-NEXT: foo()
 // CHECK: template  T tmain(T argc, T *argv) {
 // CHECK-NEXT: T i, j, a[20]
 // CHECK-NEXT: #pragma omp target
@@ -84,6 +90,8 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: foo()
 // CHECK-NEXT: #pragma omp target nowait
 // CHECK-NEXT: foo()
+// CHECK-NEXT: #pragma omp target depend(in : argc,argv[i:argc],a[:])
+// CHECK-NEXT: foo()
 
 // CHECK-LABEL: int main(int argc, char **argv) {
 int main (int argc, char **argv) {
@@ -128,6 +136,11 @@ int main (int argc, char **argv) {
   foo();
 // CHECK-NEXT: foo();
 
+#pragma omp target depend(in : argc, argv[i:argc], a[:])
+// CHECK-NEXT: #pragma omp target depend(in : argc,argv[i:argc],a[:])
+  foo();
+// CHECK-NEXT: foo();
+
   return tmain(argc, ) + tmain(argv[0][0], argv[0]);
 }
 

Added: cfe/trunk/test/OpenMP/target_depend_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_depend_messages.cpp?rev=258460=auto
==
--- cfe/trunk/test/OpenMP/target_depend_messages.cpp (added)
+++ cfe/trunk/test/OpenMP/target_depend_messages.cpp Thu Jan 21 18:49:21 2016
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - -std=c++11 %s
+
+void foo() {
+}
+
+bool foobool(int argc) {
+  return argc;
+}
+
+struct S1; // expected-note {{declared here}}
+
+class vector {
+  public:
+int operator[](int index) { return 0; }
+};
+
+int main(int argc, char **argv, char *env[]) {
+  vector vec;
+  typedef float V __attribute__((vector_size(16)));
+  V a;
+  auto arr = x; // expected-error {{use of undeclared identifier 'x'}}
+
+  #pragma omp target depend // expected-error {{expected '(' after 'depend'}}
+  foo();
+  #pragma omp target depend ( // expected-error {{expected 'in', 'out' or 
'inout' in OpenMP clause 'depend'}} expected-error {{expected ')'}} 
expected-note {{to match this '('}} expected-warning {{missing ':' after 
dependency type - ignoring}}
+  foo();
+  #pragma omp target depend () // expected-error {{expected 'in', 'out' or 
'inout' in OpenMP clause 'depend'}} expected-warning {{missing ':' after 
dependency type - ignoring}}
+  foo();
+  #pragma omp target depend (argc // expected-error {{expected 'in', 'out' or 
'inout' in OpenMP clause 'depend'}} expected-warning {{missing ':' after 
dependency type - ignoring}} expected-error {{expected ')'}} expected-note {{to 
match this '('}}
+  foo();
+  #pragma omp target depend (source : argc) // expected-error {{expected 'in', 
'out' or 'inout' in OpenMP clause 'depend'}}
+  foo();
+  #pragma omp target depend (source) // expected-error {{expected expression}} 
expected-warning {{missing ':' after dependency type - 

r258459 - [OpenMP] Parsing + Sema for nowait clause on target exit data directive.

2016-01-21 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Jan 21 18:22:05 2016
New Revision: 258459

URL: http://llvm.org/viewvc/llvm-project?rev=258459=rev
Log:
[OpenMP] Parsing + Sema for nowait clause on target exit data directive.

Summary:
Accept nowait clause on target exit data directive in sema and add test cases.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D16362


Added:
cfe/trunk/test/OpenMP/target_exit_data_nowait_messages.cpp
Modified:
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=258459=258458=258459=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Thu Jan 21 18:22:05 2016
@@ -375,6 +375,7 @@ OPENMP_TARGET_ENTER_DATA_CLAUSE(nowait)
 OPENMP_TARGET_EXIT_DATA_CLAUSE(if)
 OPENMP_TARGET_EXIT_DATA_CLAUSE(device)
 OPENMP_TARGET_EXIT_DATA_CLAUSE(map)
+OPENMP_TARGET_EXIT_DATA_CLAUSE(nowait)
 
 // Clauses allowed for OpenMP directive 'teams'.
 // TODO More clauses for 'teams' directive.

Modified: cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp?rev=258459=258458=258459=diff
==
--- cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/target_exit_data_ast_print.cpp Thu Jan 21 18:22:05 
2016
@@ -27,6 +27,22 @@ T tmain(T argc, T *argv) {
 
 #pragma omp target exit data map(always,release: e)
 
+#pragma omp target exit data nowait map(from: i)
+
+#pragma omp target exit data nowait map(from: i) if (target exit data: j > 0)
+
+#pragma omp target exit data map(from: i) if (b) nowait
+
+#pragma omp target exit data map(from: c) nowait
+
+#pragma omp target exit data map(from: c) nowait if(b>e)
+
+#pragma omp target exit data nowait map(release: x[0:10], c)
+
+#pragma omp target exit data nowait map(from: c) map(release: d)
+
+#pragma omp target exit data nowait map(always,release: e)
+
   return 0;
 }
 
@@ -41,6 +57,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target exit data map(release: x[0:10],c)
 // CHECK-NEXT: #pragma omp target exit data map(from: c) map(release: d)
 // CHECK-NEXT: #pragma omp target exit data map(always,release: e)
+// CHECK-NEXT: #pragma omp target exit data nowait map(from: i)
+// CHECK-NEXT: #pragma omp target exit data nowait map(from: i) if(target exit 
data: j > 0)
+// CHECK-NEXT: #pragma omp target exit data map(from: i) if(b) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) nowait if(b > e)
+// CHECK-NEXT: #pragma omp target exit data nowait map(release: x[0:10],c)
+// CHECK-NEXT: #pragma omp target exit data nowait map(from: c) map(release: d)
+// CHECK-NEXT: #pragma omp target exit data nowait map(always,release: e)
 // CHECK: template  char tmain(char argc, char 
*argv) {
 // CHECK-NEXT: char i, j, b, c, d, e, x[20];
 // CHECK-NEXT: i = argc;
@@ -52,6 +76,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target exit data map(release: x[0:10],c)
 // CHECK-NEXT: #pragma omp target exit data map(from: c) map(release: d)
 // CHECK-NEXT: #pragma omp target exit data map(always,release: e)
+// CHECK-NEXT: #pragma omp target exit data nowait map(from: i)
+// CHECK-NEXT: #pragma omp target exit data nowait map(from: i) if(target exit 
data: j > 0)
+// CHECK-NEXT: #pragma omp target exit data map(from: i) if(b) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) nowait if(b > e)
+// CHECK-NEXT: #pragma omp target exit data nowait map(release: x[0:10],c)
+// CHECK-NEXT: #pragma omp target exit data nowait map(from: c) map(release: d)
+// CHECK-NEXT: #pragma omp target exit data nowait map(always,release: e)
 // CHECK: template  T tmain(T argc, T *argv) {
 // CHECK-NEXT: T i, j, b, c, d, e, x[20];
 // CHECK-NEXT: i = argc;
@@ -63,6 +95,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target exit data map(release: x[0:10],c)
 // CHECK-NEXT: #pragma omp target exit data map(from: c) map(release: d)
 // CHECK-NEXT: #pragma omp target exit data map(always,release: e)
+// CHECK-NEXT: #pragma omp target exit data nowait map(from: i)
+// CHECK-NEXT: #pragma omp target exit data nowait map(from: i) if(target exit 
data: j > 0)
+// CHECK-NEXT: #pragma omp target exit data map(from: i) if(b) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) nowait
+// CHECK-NEXT: #pragma omp target exit data map(from: c) nowait if(b > e)
+// CHECK-NEXT: #pragma omp target exit data nowait map(release: x[0:10],c)
+// CHECK-NEXT: #pragma omp target 

r258466 - [OpenMP] Sema for depend clause on target enter data directive.

2016-01-21 Thread Arpith Chacko Jacob via cfe-commits
Author: arpith
Date: Thu Jan 21 19:09:37 2016
New Revision: 258466

URL: http://llvm.org/viewvc/llvm-project?rev=258466=rev
Log:
[OpenMP] Sema for depend clause on target enter data directive.

Summary:
Accept depend clause on target enter data directive in sema and add test cases.

Reviewers: ABataev

Differential Revision: http://reviews.llvm.org/D16400


Added:
cfe/trunk/test/OpenMP/target_enter_data_depend_messages.cpp
Modified:
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp

Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=258466=258465=258466=diff
==
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Thu Jan 21 19:09:37 2016
@@ -365,11 +365,11 @@ OPENMP_TARGET_DATA_CLAUSE(device)
 OPENMP_TARGET_DATA_CLAUSE(map)
 
 // Clauses allowed for OpenMP directive 'target enter data'.
-// TODO More clauses for 'target enter data' directive.
 OPENMP_TARGET_ENTER_DATA_CLAUSE(if)
 OPENMP_TARGET_ENTER_DATA_CLAUSE(device)
 OPENMP_TARGET_ENTER_DATA_CLAUSE(map)
 OPENMP_TARGET_ENTER_DATA_CLAUSE(nowait)
+OPENMP_TARGET_ENTER_DATA_CLAUSE(depend)
 
 // Clauses allowed for OpenMP directive 'target exit data'.
 // TODO More clauses for 'target exit data' directive.

Modified: cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp?rev=258466=258465=258466=diff
==
--- cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/target_enter_data_ast_print.cpp Thu Jan 21 19:09:37 
2016
@@ -43,6 +43,22 @@ T tmain(T argc, T *argv) {
 
 #pragma omp target enter data nowait map(always,alloc: e)
 
+#pragma omp target enter data nowait depend(in : argc, argv[i:argc], x[:]) 
map(to: i)
+
+#pragma omp target enter data nowait map(to: i) if (target enter data: j > 0) 
depend(in : argc, argv[i:argc], x[:])
+
+#pragma omp target enter data depend(in : argc, argv[i:argc], x[:]) map(to: i) 
if (b) nowait
+
+#pragma omp target enter data map(to: c) depend(in : argc, argv[i:argc], x[:]) 
nowait
+
+#pragma omp target enter data map(to: c) nowait if(b>e) depend(in : argc, 
argv[i:argc], x[:])
+
+#pragma omp target enter data nowait map(alloc: x[0:10], c) depend(in : argc, 
argv[i:argc], x[:])
+
+#pragma omp target enter data nowait depend(in : argc, argv[i:argc], x[:]) 
map(to: c) map(alloc: d)
+
+#pragma omp target enter data nowait map(always,alloc: e) depend(in : argc, 
argv[i:argc], x[:])
+
   return 0;
 }
 
@@ -65,6 +81,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target enter data nowait map(alloc: x[0:10],c)
 // CHECK-NEXT: #pragma omp target enter data nowait map(to: c) map(alloc: d)
 // CHECK-NEXT: #pragma omp target enter data nowait map(always,alloc: e)
+// CHECK-NEXT: #pragma omp target enter data nowait depend(in : 
argc,argv[i:argc],x[:]) map(to: i)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: i) if(target enter 
data: j > 0) depend(in : argc,argv[i:argc],x[:])
+// CHECK-NEXT: #pragma omp target enter data depend(in : 
argc,argv[i:argc],x[:]) map(to: i) if(b) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) depend(in : 
argc,argv[i:argc],x[:]) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) nowait if(b > e) 
depend(in : argc,argv[i:argc],x[:])
+// CHECK-NEXT: #pragma omp target enter data nowait map(alloc: x[0:10],c) 
depend(in : argc,argv[i:argc],x[:])
+// CHECK-NEXT: #pragma omp target enter data nowait depend(in : 
argc,argv[i:argc],x[:]) map(to: c) map(alloc: d)
+// CHECK-NEXT: #pragma omp target enter data nowait map(always,alloc: e) 
depend(in : argc,argv[i:argc],x[:])
 // CHECK: template  char tmain(char argc, char 
*argv) {
 // CHECK-NEXT: char i, j, b, c, d, e, x[20];
 // CHECK-NEXT: i = argc;
@@ -84,6 +108,14 @@ T tmain(T argc, T *argv) {
 // CHECK-NEXT: #pragma omp target enter data nowait map(alloc: x[0:10],c)
 // CHECK-NEXT: #pragma omp target enter data nowait map(to: c) map(alloc: d)
 // CHECK-NEXT: #pragma omp target enter data nowait map(always,alloc: e)
+// CHECK-NEXT: #pragma omp target enter data nowait depend(in : 
argc,argv[i:argc],x[:]) map(to: i)
+// CHECK-NEXT: #pragma omp target enter data nowait map(to: i) if(target enter 
data: j > 0) depend(in : argc,argv[i:argc],x[:])
+// CHECK-NEXT: #pragma omp target enter data depend(in : 
argc,argv[i:argc],x[:]) map(to: i) if(b) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) depend(in : 
argc,argv[i:argc],x[:]) nowait
+// CHECK-NEXT: #pragma omp target enter data map(to: c) nowait if(b > e) 
depend(in : argc,argv[i:argc],x[:])
+// CHECK-NEXT: #pragma omp target enter data nowait map(alloc: