Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-04 Thread Alexey Bataev via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


http://reviews.llvm.org/D16784



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


Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-04 Thread Samuel Antao via cfe-commits
sfantao updated this revision to Diff 46935.
sfantao added a comment.

Create CGOpenMPRuntimeNVPTX header file and mike specialization selection in 
CodeGenModule.


http://reviews.llvm.org/D16784

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenModule.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/OpenMP/target_messages.cpp

Index: test/OpenMP/target_messages.cpp
===
--- test/OpenMP/target_messages.cpp
+++ test/OpenMP/target_messages.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -o - %s
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -omptargets=aaa-bbb-ccc-ddd -o - %s 2>&1 | FileCheck %s
 // CHECK: error: OpenMP target is invalid: 'aaa-bbb-ccc-ddd'
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx64-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// CHECK-UNSUPPORTED-HOST-TARGET: error: The target '{{nvptx64-nvidia-cuda|nvptx-nvidia-cuda}}' is not a supported OpenMP host target.
 
 void foo() {
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1427,6 +1427,7 @@
 }
 
 static void ParseLangArgs(LangOptions , ArgList , InputKind IK,
+  const TargetOptions ,
   DiagnosticsEngine ) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@@ -1822,6 +1823,22 @@
   Opts.OpenMPIsDevice =
   Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
 
+  // Provide diagnostic when a given target is not expected to be an OpenMP
+  // device or host.
+  if (Opts.OpenMP && !Opts.OpenMPIsDevice) {
+llvm::Triple T(TargetOpts.Triple);
+switch (T.getArch()) {
+default:
+  break;
+// Add unsupported host targets here:
+case llvm::Triple::nvptx:
+case llvm::Triple::nvptx64:
+  Diags.Report(clang::diag::err_drv_omp_host_or_device_target_not_supported)
+  << TargetOpts.Triple << Opts.OpenMPIsDevice;
+  break;
+}
+  }
+
   // Get the OpenMP target triples if any.
   if (Arg *A = Args.getLastArg(options::OPT_omptargets_EQ)) {
 
@@ -2088,7 +2105,7 @@
 Diags, Res.getLangOpts()->Sanitize);
   } else {
 // Other LangOpts are only initialzed when the input is not AST or LLVM IR.
-ParseLangArgs(*Res.getLangOpts(), Args, DashX, Diags);
+ParseLangArgs(*Res.getLangOpts(), Args, DashX, Res.getTargetOpts(), Diags);
 if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
   Res.getLangOpts()->ObjCExceptions = 1;
   }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -20,6 +20,7 @@
 #include "CGObjCRuntime.h"
 #include "CGOpenCLRuntime.h"
 #include "CGOpenMPRuntime.h"
+#include "CGOpenMPRuntimeNVPTX.h"
 #include "CodeGenFunction.h"
 #include "CodeGenPGO.h"
 #include "CodeGenTBAA.h"
@@ -200,7 +201,21 @@
 }
 
 void CodeGenModule::createOpenMPRuntime() {
-  OpenMPRuntime = new CGOpenMPRuntime(*this);
+  // Select a specialized code generation class based on the target, if any.
+  // If it does not exist use the default implementation.
+  switch (getTarget().getTriple().getArch()) {
+
+  case llvm::Triple::nvptx:
+  case llvm::Triple::nvptx64:
+assert(getLangOpts().OpenMPIsDevice &&
+   "OpenMP NVPTX is only prepared to deal with device code.");
+OpenMPRuntime = new CGOpenMPRuntimeNVPTX(*this);
+break;
+  default:
+OpenMPRuntime = new CGOpenMPRuntime(*this);
+break;
+  }
+  return;
 }
 
 void CodeGenModule::createCUDARuntime() {
Index: lib/CodeGen/CMakeLists.txt
===
--- lib/CodeGen/CMakeLists.txt
+++ lib/CodeGen/CMakeLists.txt
@@ -57,6 +57,7 @@
   CGObjCRuntime.cpp
   CGOpenCLRuntime.cpp
   CGOpenMPRuntime.cpp
+  CGOpenMPRuntimeNVPTX.cpp
   CGRecordLayoutBuilder.cpp
   CGStmt.cpp
   CGStmtOpenMP.cpp
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.h
===
--- /dev/null
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.h
@@ -0,0 +1,31 @@
+//===- CGOpenMPRuntimeNVPTX.h - Interface to OpenMP NVPTX Runtimes ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This provides a class for OpenMP runtime code generation 

Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-04 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.


Comment at: lib/CodeGen/CodeGenModule.cpp:218
@@ -204,1 +217,3 @@
+  }
+  return;
 }

I think this must be removed


Comment at: lib/Frontend/CompilerInvocation.cpp:1837
@@ +1836,3 @@
+  
Diags.Report(clang::diag::err_drv_omp_host_or_device_target_not_supported)
+  << TargetOpts.Triple << Opts.OpenMPIsDevice;
+  break;

OpenMPIsDevice is always false here. Do we really need it here?


http://reviews.llvm.org/D16784



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


Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-04 Thread Samuel Antao via cfe-commits
sfantao updated this revision to Diff 46937.
sfantao marked 2 inline comments as done.
sfantao added a comment.

Remove return statement and use 'false' instead of relying on OpenMPIsDevice.


http://reviews.llvm.org/D16784

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenModule.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/OpenMP/target_messages.cpp

Index: test/OpenMP/target_messages.cpp
===
--- test/OpenMP/target_messages.cpp
+++ test/OpenMP/target_messages.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -o - %s
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -omptargets=aaa-bbb-ccc-ddd -o - %s 2>&1 | FileCheck %s
 // CHECK: error: OpenMP target is invalid: 'aaa-bbb-ccc-ddd'
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx64-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// CHECK-UNSUPPORTED-HOST-TARGET: error: The target '{{nvptx64-nvidia-cuda|nvptx-nvidia-cuda}}' is not a supported OpenMP host target.
 
 void foo() {
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1427,6 +1427,7 @@
 }
 
 static void ParseLangArgs(LangOptions , ArgList , InputKind IK,
+  const TargetOptions ,
   DiagnosticsEngine ) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@@ -1822,6 +1823,22 @@
   Opts.OpenMPIsDevice =
   Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
 
+  // Provide diagnostic when a given target is not expected to be an OpenMP
+  // device or host.
+  if (Opts.OpenMP && !Opts.OpenMPIsDevice) {
+llvm::Triple T(TargetOpts.Triple);
+switch (T.getArch()) {
+default:
+  break;
+// Add unsupported host targets here:
+case llvm::Triple::nvptx:
+case llvm::Triple::nvptx64:
+  Diags.Report(clang::diag::err_drv_omp_host_or_device_target_not_supported)
+  << TargetOpts.Triple << false;
+  break;
+}
+  }
+
   // Get the OpenMP target triples if any.
   if (Arg *A = Args.getLastArg(options::OPT_omptargets_EQ)) {
 
@@ -2088,7 +2105,7 @@
 Diags, Res.getLangOpts()->Sanitize);
   } else {
 // Other LangOpts are only initialzed when the input is not AST or LLVM IR.
-ParseLangArgs(*Res.getLangOpts(), Args, DashX, Diags);
+ParseLangArgs(*Res.getLangOpts(), Args, DashX, Res.getTargetOpts(), Diags);
 if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
   Res.getLangOpts()->ObjCExceptions = 1;
   }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -20,6 +20,7 @@
 #include "CGObjCRuntime.h"
 #include "CGOpenCLRuntime.h"
 #include "CGOpenMPRuntime.h"
+#include "CGOpenMPRuntimeNVPTX.h"
 #include "CodeGenFunction.h"
 #include "CodeGenPGO.h"
 #include "CodeGenTBAA.h"
@@ -200,7 +201,20 @@
 }
 
 void CodeGenModule::createOpenMPRuntime() {
-  OpenMPRuntime = new CGOpenMPRuntime(*this);
+  // Select a specialized code generation class based on the target, if any.
+  // If it does not exist use the default implementation.
+  switch (getTarget().getTriple().getArch()) {
+
+  case llvm::Triple::nvptx:
+  case llvm::Triple::nvptx64:
+assert(getLangOpts().OpenMPIsDevice &&
+   "OpenMP NVPTX is only prepared to deal with device code.");
+OpenMPRuntime = new CGOpenMPRuntimeNVPTX(*this);
+break;
+  default:
+OpenMPRuntime = new CGOpenMPRuntime(*this);
+break;
+  }
 }
 
 void CodeGenModule::createCUDARuntime() {
Index: lib/CodeGen/CMakeLists.txt
===
--- lib/CodeGen/CMakeLists.txt
+++ lib/CodeGen/CMakeLists.txt
@@ -57,6 +57,7 @@
   CGObjCRuntime.cpp
   CGOpenCLRuntime.cpp
   CGOpenMPRuntime.cpp
+  CGOpenMPRuntimeNVPTX.cpp
   CGRecordLayoutBuilder.cpp
   CGStmt.cpp
   CGStmtOpenMP.cpp
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.h
===
--- /dev/null
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.h
@@ -0,0 +1,31 @@
+//===- CGOpenMPRuntimeNVPTX.h - Interface to OpenMP NVPTX Runtimes ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This provides a class for OpenMP runtime code 

Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-04 Thread Samuel Antao via cfe-commits
sfantao updated this revision to Diff 46939.
sfantao added a comment.

Add comment.


http://reviews.llvm.org/D16784

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenModule.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/OpenMP/target_messages.cpp

Index: test/OpenMP/target_messages.cpp
===
--- test/OpenMP/target_messages.cpp
+++ test/OpenMP/target_messages.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -o - %s
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -omptargets=aaa-bbb-ccc-ddd -o - %s 2>&1 | FileCheck %s
 // CHECK: error: OpenMP target is invalid: 'aaa-bbb-ccc-ddd'
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx64-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// CHECK-UNSUPPORTED-HOST-TARGET: error: The target '{{nvptx64-nvidia-cuda|nvptx-nvidia-cuda}}' is not a supported OpenMP host target.
 
 void foo() {
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1427,6 +1427,7 @@
 }
 
 static void ParseLangArgs(LangOptions , ArgList , InputKind IK,
+  const TargetOptions ,
   DiagnosticsEngine ) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@@ -1822,6 +1823,22 @@
   Opts.OpenMPIsDevice =
   Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
 
+  // Provide diagnostic when a given target is not expected to be an OpenMP
+  // device or host.
+  if (Opts.OpenMP && !Opts.OpenMPIsDevice) {
+llvm::Triple T(TargetOpts.Triple);
+switch (T.getArch()) {
+default:
+  break;
+// Add unsupported host targets here:
+case llvm::Triple::nvptx:
+case llvm::Triple::nvptx64:
+  Diags.Report(clang::diag::err_drv_omp_host_or_device_target_not_supported)
+  << TargetOpts.Triple << /*Device=*/false;
+  break;
+}
+  }
+
   // Get the OpenMP target triples if any.
   if (Arg *A = Args.getLastArg(options::OPT_omptargets_EQ)) {
 
@@ -2088,7 +2105,7 @@
 Diags, Res.getLangOpts()->Sanitize);
   } else {
 // Other LangOpts are only initialzed when the input is not AST or LLVM IR.
-ParseLangArgs(*Res.getLangOpts(), Args, DashX, Diags);
+ParseLangArgs(*Res.getLangOpts(), Args, DashX, Res.getTargetOpts(), Diags);
 if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
   Res.getLangOpts()->ObjCExceptions = 1;
   }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -20,6 +20,7 @@
 #include "CGObjCRuntime.h"
 #include "CGOpenCLRuntime.h"
 #include "CGOpenMPRuntime.h"
+#include "CGOpenMPRuntimeNVPTX.h"
 #include "CodeGenFunction.h"
 #include "CodeGenPGO.h"
 #include "CodeGenTBAA.h"
@@ -200,7 +201,20 @@
 }
 
 void CodeGenModule::createOpenMPRuntime() {
-  OpenMPRuntime = new CGOpenMPRuntime(*this);
+  // Select a specialized code generation class based on the target, if any.
+  // If it does not exist use the default implementation.
+  switch (getTarget().getTriple().getArch()) {
+
+  case llvm::Triple::nvptx:
+  case llvm::Triple::nvptx64:
+assert(getLangOpts().OpenMPIsDevice &&
+   "OpenMP NVPTX is only prepared to deal with device code.");
+OpenMPRuntime = new CGOpenMPRuntimeNVPTX(*this);
+break;
+  default:
+OpenMPRuntime = new CGOpenMPRuntime(*this);
+break;
+  }
 }
 
 void CodeGenModule::createCUDARuntime() {
Index: lib/CodeGen/CMakeLists.txt
===
--- lib/CodeGen/CMakeLists.txt
+++ lib/CodeGen/CMakeLists.txt
@@ -57,6 +57,7 @@
   CGObjCRuntime.cpp
   CGOpenCLRuntime.cpp
   CGOpenMPRuntime.cpp
+  CGOpenMPRuntimeNVPTX.cpp
   CGRecordLayoutBuilder.cpp
   CGStmt.cpp
   CGStmtOpenMP.cpp
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.h
===
--- /dev/null
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.h
@@ -0,0 +1,31 @@
+//===- CGOpenMPRuntimeNVPTX.h - Interface to OpenMP NVPTX Runtimes ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This provides a class for OpenMP runtime code generation specialized to NVPTX
+// targets.
+//

Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-04 Thread Samuel Antao via cfe-commits
sfantao updated this revision to Diff 46941.
sfantao added a comment.

Change diagnostic for invalid host target.


http://reviews.llvm.org/D16784

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenModule.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/OpenMP/target_messages.cpp

Index: test/OpenMP/target_messages.cpp
===
--- test/OpenMP/target_messages.cpp
+++ test/OpenMP/target_messages.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -o - %s
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -omptargets=aaa-bbb-ccc-ddd -o - %s 2>&1 | FileCheck %s
 // CHECK: error: OpenMP target is invalid: 'aaa-bbb-ccc-ddd'
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx64-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// CHECK-UNSUPPORTED-HOST-TARGET: error: The target '{{nvptx64-nvidia-cuda|nvptx-nvidia-cuda}}' is not a supported OpenMP host target.
 
 void foo() {
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1427,6 +1427,7 @@
 }
 
 static void ParseLangArgs(LangOptions , ArgList , InputKind IK,
+  const TargetOptions ,
   DiagnosticsEngine ) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@@ -1822,6 +1823,22 @@
   Opts.OpenMPIsDevice =
   Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
 
+  // Provide diagnostic when a given target is not expected to be an OpenMP
+  // device or host.
+  if (Opts.OpenMP && !Opts.OpenMPIsDevice) {
+llvm::Triple T(TargetOpts.Triple);
+switch (T.getArch()) {
+default:
+  break;
+// Add unsupported host targets here:
+case llvm::Triple::nvptx:
+case llvm::Triple::nvptx64:
+  Diags.Report(clang::diag::err_drv_omp_host_target_not_supported)
+  << TargetOpts.Triple;
+  break;
+}
+  }
+
   // Get the OpenMP target triples if any.
   if (Arg *A = Args.getLastArg(options::OPT_omptargets_EQ)) {
 
@@ -2088,7 +2105,7 @@
 Diags, Res.getLangOpts()->Sanitize);
   } else {
 // Other LangOpts are only initialzed when the input is not AST or LLVM IR.
-ParseLangArgs(*Res.getLangOpts(), Args, DashX, Diags);
+ParseLangArgs(*Res.getLangOpts(), Args, DashX, Res.getTargetOpts(), Diags);
 if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
   Res.getLangOpts()->ObjCExceptions = 1;
   }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -20,6 +20,7 @@
 #include "CGObjCRuntime.h"
 #include "CGOpenCLRuntime.h"
 #include "CGOpenMPRuntime.h"
+#include "CGOpenMPRuntimeNVPTX.h"
 #include "CodeGenFunction.h"
 #include "CodeGenPGO.h"
 #include "CodeGenTBAA.h"
@@ -200,7 +201,20 @@
 }
 
 void CodeGenModule::createOpenMPRuntime() {
-  OpenMPRuntime = new CGOpenMPRuntime(*this);
+  // Select a specialized code generation class based on the target, if any.
+  // If it does not exist use the default implementation.
+  switch (getTarget().getTriple().getArch()) {
+
+  case llvm::Triple::nvptx:
+  case llvm::Triple::nvptx64:
+assert(getLangOpts().OpenMPIsDevice &&
+   "OpenMP NVPTX is only prepared to deal with device code.");
+OpenMPRuntime = new CGOpenMPRuntimeNVPTX(*this);
+break;
+  default:
+OpenMPRuntime = new CGOpenMPRuntime(*this);
+break;
+  }
 }
 
 void CodeGenModule::createCUDARuntime() {
Index: lib/CodeGen/CMakeLists.txt
===
--- lib/CodeGen/CMakeLists.txt
+++ lib/CodeGen/CMakeLists.txt
@@ -57,6 +57,7 @@
   CGObjCRuntime.cpp
   CGOpenCLRuntime.cpp
   CGOpenMPRuntime.cpp
+  CGOpenMPRuntimeNVPTX.cpp
   CGRecordLayoutBuilder.cpp
   CGStmt.cpp
   CGStmtOpenMP.cpp
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.h
===
--- /dev/null
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.h
@@ -0,0 +1,31 @@
+//===- CGOpenMPRuntimeNVPTX.h - Interface to OpenMP NVPTX Runtimes ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This provides a class for OpenMP runtime code generation specialized to NVPTX
+// targets.
+//

Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-04 Thread Samuel Antao via cfe-commits
sfantao added inline comments.


Comment at: lib/CodeGen/CodeGenModule.cpp:218
@@ -204,1 +217,3 @@
+  }
+  return;
 }

ABataev wrote:
> I think this must be removed
Ok, done.


Comment at: lib/Frontend/CompilerInvocation.cpp:1837
@@ +1836,3 @@
+  
Diags.Report(clang::diag::err_drv_omp_host_or_device_target_not_supported)
+  << TargetOpts.Triple << Opts.OpenMPIsDevice;
+  break;

ABataev wrote:
> OpenMPIsDevice is always false here. Do we really need it here?
Ok, hardcoded it to false.


http://reviews.llvm.org/D16784



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


Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-04 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.


Comment at: lib/Frontend/CompilerInvocation.cpp:1837
@@ +1836,3 @@
+  
Diags.Report(clang::diag::err_drv_omp_host_or_device_target_not_supported)
+  << TargetOpts.Triple << /*Device=*/false;
+  break;

No, I mean do we really need this argument if this is a constant? I think for 
now we should just throw it away and edit error message so that it does not 
expect the second argument,


http://reviews.llvm.org/D16784



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


Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-04 Thread Samuel Antao via cfe-commits
sfantao marked an inline comment as done.


Comment at: lib/Frontend/CompilerInvocation.cpp:1837
@@ +1836,3 @@
+  Diags.Report(clang::diag::err_drv_omp_host_target_not_supported)
+  << TargetOpts.Triple;
+  break;

Ok, I did as you say. thanks!


http://reviews.llvm.org/D16784



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


Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-03 Thread Samuel Antao via cfe-commits
sfantao updated this revision to Diff 46825.
sfantao marked 4 inline comments as done.
sfantao added a comment.

Clean up changes that are not required now.

Use CGOpenMPRuntime to contain everything that requires sharing.

Create diagnostic to notify user about unsupported OpenMP targets.


http://reviews.llvm.org/D16784

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenModule.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/OpenMP/target_messages.cpp

Index: test/OpenMP/target_messages.cpp
===
--- test/OpenMP/target_messages.cpp
+++ test/OpenMP/target_messages.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -o - %s
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -omptargets=aaa-bbb-ccc-ddd -o - %s 2>&1 | FileCheck %s
 // CHECK: error: OpenMP target is invalid: 'aaa-bbb-ccc-ddd'
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx64-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
+// CHECK-UNSUPPORTED-HOST-TARGET: error: The target '{{nvptx64-nvidia-cuda|nvptx-nvidia-cuda}}' is not a supported OpenMP host target.
 
 void foo() {
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1427,6 +1427,7 @@
 }
 
 static void ParseLangArgs(LangOptions , ArgList , InputKind IK,
+  const TargetOptions ,
   DiagnosticsEngine ) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@@ -1822,6 +1823,22 @@
   Opts.OpenMPIsDevice =
   Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
 
+  // Provide diagnostic when a given target is not expected to be an OpenMP
+  // device or host.
+  if (Opts.OpenMP && !Opts.OpenMPIsDevice) {
+llvm::Triple T(TargetOpts.Triple);
+switch (T.getArch()) {
+default:
+  break;
+// Add unsupported host targets here:
+case llvm::Triple::nvptx:
+case llvm::Triple::nvptx64:
+  Diags.Report(clang::diag::err_drv_omp_host_or_device_target_not_supported)
+  << TargetOpts.Triple << Opts.OpenMPIsDevice;
+  break;
+}
+  }
+
   // Get the OpenMP target triples if any.
   if (Arg *A = Args.getLastArg(options::OPT_omptargets_EQ)) {
 
@@ -2088,7 +2105,7 @@
 Diags, Res.getLangOpts()->Sanitize);
   } else {
 // Other LangOpts are only initialzed when the input is not AST or LLVM IR.
-ParseLangArgs(*Res.getLangOpts(), Args, DashX, Diags);
+ParseLangArgs(*Res.getLangOpts(), Args, DashX, Res.getTargetOpts(), Diags);
 if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
   Res.getLangOpts()->ObjCExceptions = 1;
   }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -200,7 +200,7 @@
 }
 
 void CodeGenModule::createOpenMPRuntime() {
-  OpenMPRuntime = new CGOpenMPRuntime(*this);
+  OpenMPRuntime = CGOpenMPRuntime::create(*this);
 }
 
 void CodeGenModule::createCUDARuntime() {
Index: lib/CodeGen/CMakeLists.txt
===
--- lib/CodeGen/CMakeLists.txt
+++ lib/CodeGen/CMakeLists.txt
@@ -57,6 +57,7 @@
   CGObjCRuntime.cpp
   CGOpenCLRuntime.cpp
   CGOpenMPRuntime.cpp
+  CGOpenMPRuntimeNVPTX.cpp
   CGRecordLayoutBuilder.cpp
   CGStmt.cpp
   CGStmtOpenMP.cpp
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- /dev/null
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -0,0 +1,30 @@
+//=== CGOpenMPRuntimeNVPTX.cpp - Interface to OpenMP NVPTX Runtimes ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This provides a class for OpenMP runtime code generation specialized to NVPTX
+// targets.
+//
+//===--===//
+
+#include "CGOpenMPRuntime.h"
+
+namespace clang {
+namespace CodeGen {
+
+class CGOpenMPRuntimeNVPTX : public CGOpenMPRuntime {
+public:
+  explicit CGOpenMPRuntimeNVPTX(CodeGenModule ) : CGOpenMPRuntime(CGM) {}
+};
+
+CGOpenMPRuntime *
+CGOpenMPRuntime::createCGOpenMPRuntimeNVPTX(CodeGenModule ) {
+  return new CGOpenMPRuntimeNVPTX(CGM);
+}
+} // CodeGen namespace.
+} // clang namespace.
Index: 

Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-03 Thread Samuel Antao via cfe-commits
sfantao added a comment.

Hi Alexey,

Thanks again for the review!



Comment at: lib/CodeGen/CGOpenMPRuntimeCommon.h:1
@@ +1,2 @@
+//=== CGOpenMPRuntimeCommon.h - Helpers for OpenMP Runtimes Codegen 
==//
+//

ABataev wrote:
> I don't think we need this new file and new namespace. If some (currently) 
> internal classes are needed, they must be exposed via CGOpenMPRuntime class. 
> Derived class will be able to use these classes.
> Also, do not expose classes if they are not required right now.
Alright. I will add what is required as protected members of CGOpenMPRuntime. 
For now I didn't do that for any of the classes given that we are not doing any 
actual codegen.


Comment at: lib/CodeGen/CGOpenMPRuntimeCommon.h:267-268
@@ +266,4 @@
+
+LValue emitLoadOfPointerLValue(CodeGenFunction , Address PtrAddr,
+  QualType Ty);
+

ABataev wrote:
> I think it is better to make this function a member of CodeGenFunction.
Ok, once we start moving things to `CGOpenMPRntime` runtime, we add this to 
CodeGenFunction accordingly.


Comment at: lib/CodeGen/CGOpenMPRuntimeCommon.h:270-279
@@ +269,12 @@
+
+/// \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 );
+

ABataev wrote:
> If you need this one, make it a virtual member of CGOpenMPRuntime
Ok. I'll do  that once we post the codegen patches.


Comment at: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp:24
@@ +23,3 @@
+  explicit CGOpenMPRuntimeNVPTX(CodeGenModule ) : CGOpenMPRuntime(CGM) {
+if (!CGM.getLangOpts().OpenMPIsDevice)
+  llvm_unreachable("OpenMP NVPTX is only prepared to deal with device 
code.");

ABataev wrote:
> I think it must be checked during creation of NVPTX specific OpenMPRuntime 
> instance.
Ok, I did that. Also I added a new diagnostic in the compiler invocation so 
that the user gets a message instead of a stack dump. Let me know if you agree.


http://reviews.llvm.org/D16784



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


Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-03 Thread Samuel Antao via cfe-commits
sfantao added a comment.

Hi Alexey,

Thanks for the feedback!



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:340-341
@@ +339,4 @@
+  case llvm::Triple::nvptx64:
+assert(CGM.getLangOpts().OpenMPIsDevice &&
+   "OpenMP NVPTX is only prepared to deal with device code.");
+return createCGOpenMPRuntimeNVPTX(CGM);

ABataev wrote:
> I think it is better to reorganize this code like that:
> ```
> switch (CGM.getTarget().getTriple().getArch()) {
>   case llvm::Triple::nvptx:
>   case llvm::Triple::nvptx64:
> assert(CGM.getLangOpts().OpenMPIsDevice &&
>"OpenMP NVPTX is only prepared to deal with device code.");
> return new CGOpenMPRuntimeNVPTX(CGM);
>   default:
> break;
> }
> return new CGOpenMPRuntime(CGM);
> ```
Ok, will do.


Comment at: lib/CodeGen/CGOpenMPRuntime.h:552-555
@@ -551,2 +551,6 @@
 
+  /// \brief Create specialized OpenMP runtime code generation class for NVPTX
+  /// targets.
+  static CGOpenMPRuntime *createCGOpenMPRuntimeNVPTX(CodeGenModule );
+
 public:

ABataev wrote:
> Do you really need this function? Currently, I don't see a point in adding 
> this platform-specific thing to (mostly) common interface
I am using that function to avoid exposing the constructor of 
`CGOpenMPRuntimeNVPTX ` in CGOpenMPRuntime.h. Do you prefer me to do that 
instead?


http://reviews.llvm.org/D16784



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


Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-03 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.


Comment at: lib/CodeGen/CGOpenMPRuntime.h:552-555
@@ -551,2 +551,6 @@
 
+  /// \brief Create specialized OpenMP runtime code generation class for NVPTX
+  /// targets.
+  static CGOpenMPRuntime *createCGOpenMPRuntimeNVPTX(CodeGenModule );
+
 public:

sfantao wrote:
> ABataev wrote:
> > Do you really need this function? Currently, I don't see a point in adding 
> > this platform-specific thing to (mostly) common interface
> I am using that function to avoid exposing the constructor of 
> `CGOpenMPRuntimeNVPTX ` in CGOpenMPRuntime.h. Do you prefer me to do that 
> instead?
Why do you need to expose constructor of CGOpenMPRuntimeNVPTX in 
CGOpenMPRuntime.h? It must be exposed only in CGOpenMPRuntime.cpp. Also, it 
would be a good idea to remove CGOpenMPRuntime::create() and move the whole 
logic to CodeGenModule::createOpenMPRuntime()


http://reviews.llvm.org/D16784



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


Re: [PATCH] D16784: [OpenMP] Reorganize code to allow specialized code generation for different devices.

2016-02-02 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.


Comment at: lib/CodeGen/CGOpenMPRuntimeCommon.h:1
@@ +1,2 @@
+//=== CGOpenMPRuntimeCommon.h - Helpers for OpenMP Runtimes Codegen 
==//
+//

I don't think we need this new file and new namespace. If some (currently) 
internal classes are needed, they must be exposed via CGOpenMPRuntime class. 
Derived class will be able to use these classes.
Also, do not expose classes if they are not required right now.


Comment at: lib/CodeGen/CGOpenMPRuntimeCommon.h:267-268
@@ +266,4 @@
+
+LValue emitLoadOfPointerLValue(CodeGenFunction , Address PtrAddr,
+  QualType Ty);
+

I think it is better to make this function a member of CodeGenFunction.


Comment at: lib/CodeGen/CGOpenMPRuntimeCommon.h:270-279
@@ +269,12 @@
+
+/// \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 );
+

If you need this one, make it a virtual member of CGOpenMPRuntime


Comment at: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp:24
@@ +23,3 @@
+  explicit CGOpenMPRuntimeNVPTX(CodeGenModule ) : CGOpenMPRuntime(CGM) {
+if (!CGM.getLangOpts().OpenMPIsDevice)
+  llvm_unreachable("OpenMP NVPTX is only prepared to deal with device 
code.");

I think it must be checked during creation of NVPTX specific OpenMPRuntime 
instance.


http://reviews.llvm.org/D16784



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