[clang] [clang] Split up `SemaDeclAttr.cpp` (PR #93966)

2024-05-31 Thread Alexey Bader via cfe-commits


@@ -14,9 +14,11 @@
 #define LLVM_CLANG_SEMA_SEMASYCL_H
 
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"

bader wrote:

I'm okay with that.
It just looks strange to add forward declaration for `Decl` class when full 
declaration is included with `#include "clang/AST/Decl.h"`. Probably the 
cleaner solution would be to drop forward declaration of `Decl` and add it in 
the follow-up patch.
Anyway, this is a minor comment and should not block the merge.

https://github.com/llvm/llvm-project/pull/93966
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Split up `SemaDeclAttr.cpp` (PR #93966)

2024-05-31 Thread Alexey Bader via cfe-commits


@@ -14,9 +14,11 @@
 #define LLVM_CLANG_SEMA_SEMASYCL_H
 
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"

bader wrote:

> This one should be fixed as well now.

Can we drop `#include "clang/AST/Decl.h"` as well?

https://github.com/llvm/llvm-project/pull/93966
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-05-30 Thread Alexey Bader via cfe-commits

https://github.com/bader commented:

I'm okay with the patch in general, but I'd like either @michalpaszkowski or 
@VyacheslavLevytskyy to take a look.
Just one question about doubling the test scope for LLVM tests with spir64 
target triple.

https://github.com/llvm/llvm-project/pull/89796
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-05-30 Thread Alexey Bader via cfe-commits


@@ -1,4 +1,5 @@
 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: llc -O0 -mtriple=spirv64-amd-amdhsa %s -o - | FileCheck %s

bader wrote:

I'm not sure if there is a value in testing `spirv64-amd-amdhsa` triple in 
addition to `spirv64-unknown-unknown` for most of llvm/test/CodeGen/SPIRV 
tests. It makes sense to extend testing for vendor extensions mentioned in the 
description, but I suppose most of the tests cover core functionality which 
should work any `spir64-*` triple. Am I right?

https://github.com/llvm/llvm-project/pull/89796
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-05-30 Thread Alexey Bader via cfe-commits

https://github.com/bader edited https://github.com/llvm/llvm-project/pull/89796
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-05-13 Thread Alexey Bader via cfe-commits

bader wrote:

@AlexVlx, do you think it's worth promoting 
[SPV_INTEL_inline_assembly](https://github.com/intel/llvm/blob/sycl/sycl/doc/design/spirv-extensions/SPV_INTEL_inline_assembly.asciidoc)
 and 
[SPV_INTEL_function_pointers](https://github.com/intel/llvm/blob/sycl/sycl/doc/design/spirv-extensions/SPV_INTEL_function_pointers.asciidoc)
 to Khronos extensions?

https://github.com/llvm/llvm-project/pull/89796
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Add AS for Globals to SPIR & SPIRV datalayouts (PR #88455)

2024-04-12 Thread Alexey Bader via cfe-commits

https://github.com/bader commented:

> I'll emphasise that this is only a problem for things such as implicitly 
> generated globals (e.g. VTables or typeinfo for classes etc.)

I suppose usage of VTables and typeinfo is kind of restricted in GPU 
programming models. Right?

Anyway, I think it's a reasonable change for SPIR target, which fixes mapping 
from `global` address space to `1` LLVM address space.
It's less obvious for SPIR-V, which is not LLVM-based format and mapping 
between SPIR-V and LLVM addresses spaces is technically an implementation 
detail, which can be adjusted.
According to my understanding, today LLVM IR for SPIR-V target just follows 
SPIR target nomenclature.

I'd like Eli/John to give formal approval for this change, but I'm okay with 
it.  Thanks!

https://github.com/llvm/llvm-project/pull/88455
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Add AS for Globals to SPIR & SPIRV datalayouts (PR #88455)

2024-04-12 Thread Alexey Bader via cfe-commits

bader wrote:

The change seems reasonable.

> CodeGen/LLVM will default to AS0 in this case, which produces Globals that 
> end up in the private address space for e.g. OCL, HIPSPV or SYCL.

Can we add a test checking LLVM address space for globals emitted from 
OCL/HIPSPV/SYCL, please? It's surprising that we need to modify only a 
datalayout string check.

https://github.com/llvm/llvm-project/pull/88455
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Adding the amdgpu-num-work-groups function attribute (PR #75647)

2024-01-16 Thread Alexey Bader via cfe-commits

bader wrote:

> How does this attribute relate to `reqd_work_group_size` and related existing 
> attributes?

They seems to be different/"unrelated". Based on the description of the 
`amdgpu-num-work-groups` attribute it provides "number of work-groups", whereas 
`reqd_work_group_size` provides "number of work-items in a work-group".

I think this attributed can be useful for other targets. The optimization ideas 
described in 
https://github.com/llvm/llvm-project/pull/75647#issuecomment-1863352459 seems 
to be generic. There is an RFC to unify some existing functionality exposing 
"grid" information: 
https://discourse.llvm.org/t/proposing-llvm-gpu-intrinsics/75374. This might 
fall into similar category.

https://github.com/llvm/llvm-project/pull/75647
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a2e2f47 - [Clang][Docs] Fix typo in clang-offload-packager documentation

2023-09-11 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2023-09-11T16:24:37-07:00
New Revision: a2e2f471c51f0aea836a4929dfdf50523dcff1eb

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

LOG: [Clang][Docs] Fix typo in clang-offload-packager documentation

Fixed formatting of the section violating 80-char line limit.

Added: 


Modified: 
clang/docs/ClangOffloadPackager.rst

Removed: 




diff  --git a/clang/docs/ClangOffloadPackager.rst 
b/clang/docs/ClangOffloadPackager.rst
index 1d6ded952e8adfe..2b985e260e302de 100644
--- a/clang/docs/ClangOffloadPackager.rst
+++ b/clang/docs/ClangOffloadPackager.rst
@@ -124,7 +124,7 @@ array of the :ref:`string entry` 
format.
 
+--+--+---+
 |   Type   |   Identifier | Description
   |
 
+==+==+===+
-| uint64_t |  key offset  | Absolute byte offset of the key in th string 
table|
+| uint64_t |  key offset  | Absolute byte offset of the key in the string 
table   |
 
+--+--+---+
 | uint64_t | value offset | Absolute byte offset of the value in the 
string table |
 
+--+--+---+
@@ -145,9 +145,9 @@ Usage
 =
 
 This tool can be used with the following arguments. Generally information is
-passed as a key-value pair to the ``image=`` argument. The ``file`` and 
``triple``,
-arguments are considered mandatory to make a valid image. The ``arch`` argument
-is suggested.
+passed as a key-value pair to the ``image=`` argument. The ``file`` and
+``triple``, arguments are considered mandatory to make a valid image.
+The ``arch`` argument is suggested.
 
 .. code-block:: console
 



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


[clang] 66bd607 - [Attr][Doc] Fix pragma unroll documentation.

2022-10-19 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2022-10-19T03:50:47-07:00
New Revision: 66bd6074c133402e45075b591c062c22f308ef26

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

LOG: [Attr][Doc] Fix pragma unroll documentation.

There is a contradiction in the #pragma unroll behavior documentation.
It says that specifying `#pragma unroll` without a parameter directs the
loop unroller to attempt to partially unroll the loop if the trip count
is not known at compile time. At the same time later it states that
`#pragma unroll` has identical semantics to `#pragma clang loop unroll(full)`,
which doesn't attempt to unroll partially if the trip count is not known
at compile time.

pragma clang loop unroll(enable):
If unroll(enable) is specified the unroller will attempt to fully unroll
the loop if the trip count is known at compile time. If the fully
unrolled code size is greater than an internal limit the loop will be
partially unrolled up to this limit. If the trip count is not known at
compile time the loop will be partially unrolled with a heuristically
chosen unroll factor.

pragma clang loop unroll(full):
If unroll(full) is specified the unroller will attempt to fully unroll
the loop if the trip count is known at compile time identically to
unroll(enable). However, with unroll(full) the loop will not be unrolled
if the loop count is not known at compile time.

Differential Revision: https://reviews.llvm.org/D136160

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 33a18ac033252..484052f4db8ad 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3569,7 +3569,7 @@ Specifying ``#pragma nounroll`` indicates that the loop 
should not be unrolled:
   }
 
 ``#pragma unroll`` and ``#pragma unroll _value_`` have identical semantics to
-``#pragma clang loop unroll(full)`` and
+``#pragma clang loop unroll(enable)`` and
 ``#pragma clang loop unroll_count(_value_)`` respectively. ``#pragma nounroll``
 is equivalent to ``#pragma clang loop unroll(disable)``. See
 `language extensions



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


[clang] 923b56e - [NFC] Add a TODO comment to apply nounwind attribute in all GPU modes.

2022-07-06 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2022-07-06T06:20:09-07:00
New Revision: 923b56e7ca96e03cedcb0e3a5df5c05e8e975a38

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

LOG: [NFC] Add a TODO comment to apply nounwind attribute in all GPU modes.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 4e26c35c6342..104a30dd6b25 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1931,6 +1931,9 @@ void 
CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
   }
 
+  // TODO: NoUnwind attribute should be added for other GPU modes OpenCL, HIP,
+  // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device
+  // code.
   if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) {
 // Exceptions aren't supported in CUDA device code.
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);



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


[clang] 87b28f5 - [clang][NFC] Extract the EmitAssemblyHelper::TargetTriple member

2022-04-04 Thread Alexey Bader via cfe-commits

Author: Pavel Samolysov
Date: 2022-04-04T12:16:39+03:00
New Revision: 87b28f5092f2f92fc380f18e8578746bdd2a54b2

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

LOG: [clang][NFC] Extract the EmitAssemblyHelper::TargetTriple member

Few times in different methods of the EmitAssemblyHelper class the following
code snippet is used to get the TargetTriple and then use it's single method
to check some conditions:

TargetTriple(TheModule->getTargetTriple())

The parsing of a target triple string is not a trivial operation and it takes
time to repeat the parsing many times in different methods of the class and
even numerous times in one method just to call a getter
(llvm::Triple(TheModule->getTargetTriple()).getVendor()), for example.
The patch extracts the TargetTriple member of the EmitAssemblyHelper class to
parse the triple only once in the class' constructor.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D122587

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 61677d368029e..36776d39b952a 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -118,6 +118,8 @@ class EmitAssemblyHelper {
 
   std::unique_ptr OS;
 
+  Triple TargetTriple;
+
   TargetIRAnalysis getTargetIRAnalysis() const {
 if (TM)
   return TM->getTargetIRAnalysis();
@@ -170,7 +172,8 @@ class EmitAssemblyHelper {
  const LangOptions , Module *M)
   : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M),
-CodeGenerationTime("codegen", "Code Generation Time") {}
+CodeGenerationTime("codegen", "Code Generation Time"),
+TargetTriple(TheModule->getTargetTriple()) {}
 
   ~EmitAssemblyHelper() {
 if (CodeGenOpts.DisableFree)
@@ -695,7 +698,6 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager 
,
   // manually (and not via PMBuilder), since some passes (eg. InstrProfiling)
   // are inserted before PMBuilder ones - they'd get the default-constructed
   // TLI with an unknown target otherwise.
-  Triple TargetTriple(TheModule->getTargetTriple());
   std::unique_ptr TLII(
   createTLII(TargetTriple, CodeGenOpts));
 
@@ -965,7 +967,6 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager 
,
raw_pwrite_stream ,
raw_pwrite_stream *DwoOS) {
   // Add LibraryInfo.
-  llvm::Triple TargetTriple(TheModule->getTargetTriple());
   std::unique_ptr TLII(
   createTLII(TargetTriple, CodeGenOpts));
   CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
@@ -1054,10 +1055,8 @@ void 
EmitAssemblyHelper::EmitAssemblyWithLegacyPassManager(
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
   bool EmitLTOSummary =
-  (CodeGenOpts.PrepareForLTO &&
-   !CodeGenOpts.DisableLLVMPasses &&
-   llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
-   llvm::Triple::Apple);
+  (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
+   TargetTriple.getVendor() != llvm::Triple::Apple);
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
@@ -1338,7 +1337,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 
   // Register the target library analysis directly and give it a customized
   // preset TLI.
-  Triple TargetTriple(TheModule->getTargetTriple());
   std::unique_ptr TLII(
   createTLII(TargetTriple, CodeGenOpts));
   FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
@@ -1474,8 +1472,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   // targets
   bool EmitLTOSummary =
   (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-   llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
-   llvm::Triple::Apple);
+   TargetTriple.getVendor() != llvm::Triple::Apple);
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));



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


[clang] 9ae5810 - [HIPSPV] Convert HIP kernels to SPIR-V kernels

2021-12-08 Thread Alexey Bader via cfe-commits

Author: Henry Linjamäki
Date: 2021-12-08T12:18:15+03:00
New Revision: 9ae5810b53c2e096d7442ba8af3f00ebc3d301b0

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

LOG: [HIPSPV] Convert HIP kernels to SPIR-V kernels

This patch translates HIP kernels to SPIR-V kernels when the HIP
compilation mode is targeting SPIR-S. This involves:

* Setting Cuda calling convention to CC_OpenCLKernel (which maps to
  SPIR_KERNEL in LLVM IR later on).

* Coercing pointer arguments with default address space (AS) qualifier
  to CrossWorkGroup AS (__global in OpenCL). HIPSPV's device code is
  ultimately SPIR-V for OpenCL execution environment (as
  starter/default) where Generic or Function (OpenCL's private) is not
  supported as storage class for kernel pointer types. This leaves the
  CrossWorkGroup to be the only reasonable choice for HIP buffers.

Reviewed By: yaxunl

Differential Revision: https://reviews.llvm.org/D109818

Added: 
clang/test/CodeGenHIP/hipspv-kernel.cpp

Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index ade937de234cd..0e03588f9b248 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -10228,12 +10228,23 @@ class CommonSPIRABIInfo : public DefaultABIInfo {
 private:
   void setCCs();
 };
+
+class SPIRVABIInfo : public CommonSPIRABIInfo {
+public:
+  SPIRVABIInfo(CodeGenTypes ) : CommonSPIRABIInfo(CGT) {}
+  void computeInfo(CGFunctionInfo ) const override;
+
+private:
+  ABIArgInfo classifyKernelArgumentType(QualType Ty) const;
+};
 } // end anonymous namespace
 namespace {
 class CommonSPIRTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   CommonSPIRTargetCodeGenInfo(CodeGen::CodeGenTypes )
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  CommonSPIRTargetCodeGenInfo(std::unique_ptr ABIInfo)
+  : TargetCodeGenInfo(std::move(ABIInfo)) {}
 
   LangAS getASTAllocaAddressSpace() const override {
 return getLangASFromTargetAS(
@@ -10242,18 +10253,60 @@ class CommonSPIRTargetCodeGenInfo : public 
TargetCodeGenInfo {
 
   unsigned getOpenCLKernelCallingConv() const override;
 };
-
+class SPIRVTargetCodeGenInfo : public CommonSPIRTargetCodeGenInfo {
+public:
+  SPIRVTargetCodeGenInfo(CodeGen::CodeGenTypes )
+  : CommonSPIRTargetCodeGenInfo(std::make_unique(CGT)) {}
+  void setCUDAKernelCallingConvention(const FunctionType *) const override;
+};
 } // End anonymous namespace.
+
 void CommonSPIRABIInfo::setCCs() {
   assert(getRuntimeCC() == llvm::CallingConv::C);
   RuntimeCC = llvm::CallingConv::SPIR_FUNC;
 }
 
+ABIArgInfo SPIRVABIInfo::classifyKernelArgumentType(QualType Ty) const {
+  if (getContext().getLangOpts().HIP) {
+// Coerce pointer arguments with default address space to CrossWorkGroup
+// pointers for HIPSPV. When the language mode is HIP, the SPIRTargetInfo
+// maps cuda_device to SPIR-V's CrossWorkGroup address space.
+llvm::Type *LTy = CGT.ConvertType(Ty);
+auto DefaultAS = getContext().getTargetAddressSpace(LangAS::Default);
+auto GlobalAS = getContext().getTargetAddressSpace(LangAS::cuda_device);
+if (LTy->isPointerTy() && LTy->getPointerAddressSpace() == DefaultAS) {
+  LTy = llvm::PointerType::get(
+  cast(LTy)->getElementType(), GlobalAS);
+  return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
+}
+  }
+  return classifyArgumentType(Ty);
+}
+
+void SPIRVABIInfo::computeInfo(CGFunctionInfo ) const {
+  // The logic is same as in DefaultABIInfo with an exception on the kernel
+  // arguments handling.
+  llvm::CallingConv::ID CC = FI.getCallingConvention();
+
+  if (!getCXXABI().classifyReturnType(FI))
+FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+  for (auto  : FI.arguments()) {
+if (CC == llvm::CallingConv::SPIR_KERNEL) {
+  I.info = classifyKernelArgumentType(I.type);
+} else {
+  I.info = classifyArgumentType(I.type);
+}
+  }
+}
+
 namespace clang {
 namespace CodeGen {
 void computeSPIRKernelABIInfo(CodeGenModule , CGFunctionInfo ) {
-  DefaultABIInfo SPIRABI(CGM.getTypes());
-  SPIRABI.computeInfo(FI);
+  if (CGM.getTarget().getTriple().isSPIRV())
+SPIRVABIInfo(CGM.getTypes()).computeInfo(FI);
+  else
+CommonSPIRABIInfo(CGM.getTypes()).computeInfo(FI);
 }
 }
 }
@@ -10262,6 +10315,16 @@ unsigned 
CommonSPIRTargetCodeGenInfo::getOpenCLKernelCallingConv() const {
   return llvm::CallingConv::SPIR_KERNEL;
 }
 
+void SPIRVTargetCodeGenInfo::setCUDAKernelCallingConvention(
+const FunctionType *) const {
+  // Convert HIP kernels to SPIR-V kernels.
+  if (getABIInfo().getContext().getLangOpts().HIP) {
+FT = getABIInfo().getContext().adjustFunctionType(
+FT, 

[clang] 49682f1 - [SPIR-V] Add translator tool

2021-11-17 Thread Alexey Bader via cfe-commits

Author: Henry Linjamäki
Date: 2021-11-18T03:41:24+03:00
New Revision: 49682f14bf3fb8db5e2721d9896b27bb4c2bd635

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

LOG: [SPIR-V] Add translator tool

Add a tool for constructing commands for translating LLVM IR to
SPIR-V.

Used by HIPSPV tool chain (D110618).

Reviewed By: bader

Differential Revision: https://reviews.llvm.org/D112404

Added: 
clang/lib/Driver/ToolChains/SPIRV.cpp
clang/lib/Driver/ToolChains/SPIRV.h

Modified: 
clang/lib/Driver/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 61a1cd04e088..31e357b67361 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -69,6 +69,7 @@ add_clang_library(clangDriver
   ToolChains/PS4CPU.cpp
   ToolChains/RISCVToolchain.cpp
   ToolChains/Solaris.cpp
+  ToolChains/SPIRV.cpp
   ToolChains/TCE.cpp
   ToolChains/VEToolchain.cpp
   ToolChains/WebAssembly.cpp

diff  --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
new file mode 100644
index ..3f942478e2ad
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -0,0 +1,48 @@
+//===--- SPIRV.cpp - SPIR-V Tool Implementations *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "SPIRV.h"
+#include "CommonArgs.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/InputInfo.h"
+#include "clang/Driver/Options.h"
+
+using namespace clang::driver::tools;
+using namespace llvm::opt;
+
+void SPIRV::constructTranslateCommand(Compilation , const Tool ,
+  const JobAction ,
+  const InputInfo ,
+  const InputInfo ,
+  const llvm::opt::ArgStringList ) {
+  llvm::opt::ArgStringList CmdArgs(Args);
+  CmdArgs.push_back(Input.getFilename());
+
+  if (Input.getType() == types::TY_PP_Asm)
+CmdArgs.push_back("-to-binary");
+  if (Output.getType() == types::TY_PP_Asm)
+CmdArgs.push_back("-spirv-text");
+
+  CmdArgs.append({"-o", Output.getFilename()});
+
+  const char *Exec =
+  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
+ Exec, CmdArgs, Input, Output));
+}
+
+void SPIRV::Translator::ConstructJob(Compilation , const JobAction ,
+ const InputInfo ,
+ const InputInfoList ,
+ const ArgList ,
+ const char *LinkingOutput) const {
+  claimNoWarnArgs(Args);
+  if (Inputs.size() != 1)
+llvm_unreachable("Invalid number of input files.");
+  constructTranslateCommand(C, *this, JA, Output, Inputs[0], {});
+}

diff  --git a/clang/lib/Driver/ToolChains/SPIRV.h 
b/clang/lib/Driver/ToolChains/SPIRV.h
new file mode 100644
index ..35d0446bd8b8
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/SPIRV.h
@@ -0,0 +1,46 @@
+//===--- SPIRV.h - SPIR-V Tool Implementations --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SPIRV_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SPIRV_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace SPIRV {
+
+void addTranslatorArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList );
+
+void constructTranslateCommand(Compilation , const Tool ,
+   const JobAction , const InputInfo ,
+   const InputInfo ,
+   const llvm::opt::ArgStringList );
+
+class LLVM_LIBRARY_VISIBILITY Translator : public Tool {
+public:
+  Translator(const ToolChain )
+  : Tool("SPIR-V::Translator", "llvm-spirv", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+  bool hasIntegratedAssembler() const override { return true; }
+
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , 

[clang] 15feaaa - Add myself as a code owner for SYCL support

2021-09-20 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-09-20T09:32:25+03:00
New Revision: 15feaaa359c7245bb59ff0a2aa3b806682f44286

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

LOG: Add myself as a code owner for SYCL support

Added: 


Modified: 
clang/CODE_OWNERS.TXT

Removed: 




diff  --git a/clang/CODE_OWNERS.TXT b/clang/CODE_OWNERS.TXT
index faf9575a2898..740aeeb7125b 100644
--- a/clang/CODE_OWNERS.TXT
+++ b/clang/CODE_OWNERS.TXT
@@ -8,6 +8,10 @@ beautification by scripts.  The fields are: name (N), email 
(E), web-address
 (W), PGP key ID and fingerprint (P), description (D), and snail-mail address
 (S).
 
+N: Alexey Bader
+E: alexey.ba...@intel.com
+D: SYCL support
+
 N: Aaron Ballman
 E: aa...@aaronballman.com
 D: Clang attributes



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


[clang] d754b97 - [NFC] Drop idle compiler option from the test.

2021-08-13 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-08-13T13:20:11+03:00
New Revision: d754b970eddb83b1c68346a36b067391d93166b0

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

LOG: [NFC] Drop idle compiler option from the test.

Differential Revision: https://reviews.llvm.org/D108020

Added: 


Modified: 
clang/test/AST/ast-print-sycl-unique-stable-name.cpp

Removed: 




diff  --git a/clang/test/AST/ast-print-sycl-unique-stable-name.cpp 
b/clang/test/AST/ast-print-sycl-unique-stable-name.cpp
index 3f49ea9ee733c..b55d01aa1b6b6 100644
--- a/clang/test/AST/ast-print-sycl-unique-stable-name.cpp
+++ b/clang/test/AST/ast-print-sycl-unique-stable-name.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ast-print -fsycl-is-device %s -o - -triple 
spir64-sycldevice | FileCheck %s
+// RUN: %clang_cc1 -ast-print -fsycl-is-device %s -o - | FileCheck %s
 
 template 
 void WrappedInTemplate(T t) {



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


[clang] c064ba3 - [NFC] Add commas in code comments.

2021-08-13 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-08-13T08:59:47+03:00
New Revision: c064ba34c7d867c1180279fe3dca8817d835cb28

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

LOG: [NFC] Add commas in code comments.

Added: 


Modified: 
clang/include/clang/Sema/ParsedAttr.h

Removed: 




diff  --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index 61a36ddcc1db..408032cec7e8 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -627,7 +627,7 @@ class ParsedAttr final
   /// a Spelling enumeration, the value UINT_MAX is returned.
   unsigned getSemanticSpelling() const;
 
-  /// If this is an OpenCL address space attribute returns its representation
+  /// If this is an OpenCL address space attribute, returns its representation
   /// in LangAS, otherwise returns default address space.
   LangAS asOpenCLLangAS() const {
 switch (getParsedKind()) {
@@ -650,7 +650,7 @@ class ParsedAttr final
 }
   }
 
-  /// If this is an OpenCL address space attribute returns its SYCL
+  /// If this is an OpenCL address space attribute, returns its SYCL
   /// representation in LangAS, otherwise returns default address space.
   LangAS asSYCLLangAS() const {
 switch (getKind()) {



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


[clang] 2ab513c - [SYCL] Enable `opencl_global_[host,device]` attributes for SYCL

2021-05-18 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-05-18T10:27:35+03:00
New Revision: 2ab513cd3e0648806db7ed1f8170ad4a3d4e7749

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

LOG: [SYCL] Enable `opencl_global_[host,device]` attributes for SYCL

Differential Revision: https://reviews.llvm.org/D100396

Added: 


Modified: 
clang/docs/SYCLSupport.rst
clang/include/clang/AST/Type.h
clang/include/clang/Basic/AddressSpaces.h
clang/include/clang/Sema/ParsedAttr.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Basic/Targets/SPIR.h
clang/lib/Basic/Targets/TCE.h
clang/lib/Basic/Targets/X86.h
clang/test/CodeGenSYCL/address-space-conversions.cpp
clang/test/SemaSYCL/address-space-conversions.cpp
clang/test/SemaTemplate/address_space-dependent.cpp

Removed: 




diff  --git a/clang/docs/SYCLSupport.rst b/clang/docs/SYCLSupport.rst
index d45ecfbea53f8..6b529e3eb0127 100644
--- a/clang/docs/SYCLSupport.rst
+++ b/clang/docs/SYCLSupport.rst
@@ -34,10 +34,20 @@ the address space qualifier inference as detailed in
 
 The default address space is "generic-memory", which is a virtual address space
 that overlaps the global, local, and private address spaces. SYCL mode enables
-explicit conversions to/from the default address space from/to the address
-space-attributed type and implicit conversions from the address 
space-attributed
-type to the default address space. All named address spaces are disjoint and
-sub-sets of default address space.
+following conversions:
+
+- explicit conversions to/from the default address space from/to the address
+  space-attributed type
+- implicit conversions from the address space-attributed type to the default
+  address space
+- explicit conversions to/from the global address space from/to the
+  ``__attribute__((opencl_global_device))`` or
+  ``__attribute__((opencl_global_host))`` address space-attributed type
+- implicit conversions from the ``__attribute__((opencl_global_device))`` or
+  ``__attribute__((opencl_global_host))`` address space-attributed type to the
+  global address space
+
+All named address spaces are disjoint and sub-sets of default address space.
 
 The SPIR target allocates SYCL namespace scope variables in the global address
 space.
@@ -93,6 +103,10 @@ space attributes for pointers:
  - SYCL address_space enumeration
* - ``__attribute__((opencl_global))``
  - global_space, constant_space
+   * - ``__attribute__((opencl_global_device))``
+ - global_space
+   * - ``__attribute__((opencl_global_host))``
+ - global_space
* - ``__attribute__((opencl_local))``
  - local_space
* - ``__attribute__((opencl_private))``

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 84de51aba5b2d..9f46d53378976 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -486,13 +486,16 @@ class Qualifiers {
// allocated on device, which are a subset of __global.
(A == LangAS::opencl_global && (B == LangAS::opencl_global_device ||
B == LangAS::opencl_global_host)) ||
+   (A == LangAS::sycl_global && (B == LangAS::sycl_global_device ||
+ B == LangAS::sycl_global_host)) ||
// Consider pointer size address spaces to be equivalent to default.
((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
 (isPtrSizeAddressSpace(B) || B == LangAS::Default)) ||
// Default is a superset of SYCL address spaces.
(A == LangAS::Default &&
 (B == LangAS::sycl_private || B == LangAS::sycl_local ||
- B == LangAS::sycl_global));
+ B == LangAS::sycl_global || B == LangAS::sycl_global_device ||
+ B == LangAS::sycl_global_host));
   }
 
   /// Returns true if the address space in these qualifiers is equal to or

diff  --git a/clang/include/clang/Basic/AddressSpaces.h 
b/clang/include/clang/Basic/AddressSpaces.h
index 5fa031250a629..99bb67fd26d19 100644
--- a/clang/include/clang/Basic/AddressSpaces.h
+++ b/clang/include/clang/Basic/AddressSpaces.h
@@ -46,6 +46,8 @@ enum class LangAS : unsigned {
 
   // SYCL specific address spaces.
   sycl_global,
+  sycl_global_device,
+  sycl_global_host,
   sycl_local,
   sycl_private,
 

diff  --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index 347925873b30f..f47f557adeb10 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -657,6 +657,10 @@ class ParsedAttr final
 switch (getKind()) {
 case 

[clang] 76f84e7 - [Doc] Fix sphinx warnings about wrong code-block format

2021-04-30 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-04-30T11:40:10+03:00
New Revision: 76f84e772978a3daef33df5bea7da676a0163f28

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

LOG: [Doc] Fix sphinx warnings about wrong code-block format

Differential Revision: https://reviews.llvm.org/D101549

Added: 


Modified: 
clang/docs/SYCLSupport.rst

Removed: 




diff  --git a/clang/docs/SYCLSupport.rst b/clang/docs/SYCLSupport.rst
index 8c1ed19dff4e6..d45ecfbea53f8 100644
--- a/clang/docs/SYCLSupport.rst
+++ b/clang/docs/SYCLSupport.rst
@@ -99,7 +99,7 @@ space attributes for pointers:
  - private_space
 
 
-.. code-block::
+.. code-block:: C++
+
+//TODO: add support for __attribute__((opencl_global_host)) and 
__attribute__((opencl_global_device)).
 
-   TODO: add support for `__attribute__((opencl_global_host))` and
-   `__attribute__((opencl_global_device))`.



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


[clang] b2bb13a - [Doc] Add SYCLSupport.rst to index toctree.

2021-04-26 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-04-26T16:16:10+03:00
New Revision: b2bb13a761644f675ec9f2d0b4371c51a05ab51c

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

LOG: [Doc] Add SYCLSupport.rst to index toctree.

Added: 


Modified: 
clang/docs/index.rst

Removed: 




diff  --git a/clang/docs/index.rst b/clang/docs/index.rst
index a3a76c073b99..149f5680b333 100644
--- a/clang/docs/index.rst
+++ b/clang/docs/index.rst
@@ -43,6 +43,7 @@ Using Clang as a Compiler
MSVCCompatibility
OpenCLSupport
OpenMPSupport
+   SYCLSupport
ThinLTO
APINotes
CommandGuide/index



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


[clang] b52e69c - [SYCL][Doc] Add design document for SYCL mode

2021-04-26 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-04-26T15:39:43+03:00
New Revision: b52e69c4268181d8143fe49aee0ea85395c8737d

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

LOG: [SYCL][Doc] Add design document for SYCL mode

Initial version of the document covers address space handling

Differential Revision: https://reviews.llvm.org/D99488

Added: 
clang/docs/SYCLSupport.rst

Modified: 


Removed: 




diff  --git a/clang/docs/SYCLSupport.rst b/clang/docs/SYCLSupport.rst
new file mode 100644
index ..8c1ed19dff4e
--- /dev/null
+++ b/clang/docs/SYCLSupport.rst
@@ -0,0 +1,105 @@
+=
+SYCL Compiler and Runtime architecture design
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+This document describes the architecture of the SYCL compiler and runtime
+library. More details are provided in
+`external document 
`_\
 ,
+which are going to be added to clang documentation in the future.
+
+Address space handling
+==
+
+The SYCL specification represents pointers to disjoint memory regions using C++
+wrapper classes on an accelerator to enable compilation with a standard C++
+toolchain and a SYCL compiler toolchain. Section 3.8.2 of SYCL 2020
+specification defines
+`memory model 
`_\
 ,
+section 4.7.7 - `address space classes 
`_
+and section 5.9 covers `address space deduction 
`_.
+The SYCL specification allows two modes of address space deduction: "generic as
+default address space" (see section 5.9.3) and "inferred address space" (see
+section 5.9.4). Current implementation supports only "generic as default 
address
+space" mode.
+
+SYCL borrows its memory model from OpenCL however SYCL doesn't perform
+the address space qualifier inference as detailed in
+`OpenCL C v3.0 6.7.8 
`_.
+
+The default address space is "generic-memory", which is a virtual address space
+that overlaps the global, local, and private address spaces. SYCL mode enables
+explicit conversions to/from the default address space from/to the address
+space-attributed type and implicit conversions from the address 
space-attributed
+type to the default address space. All named address spaces are disjoint and
+sub-sets of default address space.
+
+The SPIR target allocates SYCL namespace scope variables in the global address
+space.
+
+Pointers to default address space should get lowered into a pointer to a 
generic
+address space (or flat to reuse more general terminology). But depending on the
+allocation context, the default address space of a non-pointer type is assigned
+to a specific address space. This is described in
+`common address space deduction rules 
`_
+section.
+
+This is also in line with the behaviour of CUDA (`small example
+`_).
+
+``multi_ptr`` class implementation example:
+
+.. code-block:: C++
+
+   // check that SYCL mode is ON and we can use non-standard decorations
+   #if defined(__SYCL_DEVICE_ONLY__)
+   // GPU/accelerator implementation
+   template  class multi_ptr {
+ // DecoratedType applies corresponding address space attribute to the 
type T
+ // DecoratedType::type == 
"__attribute__((opencl_global)) T"
+ // See sycl/include/CL/sycl/access/access.hpp for more details
+ using pointer_t = typename DecoratedType::type *;
+
+ pointer_t m_Pointer;
+ public:
+ pointer_t get() { return m_Pointer; }
+ T& operator* () { return *reinterpret_cast(m_Pointer); }
+   }
+   #else
+   // CPU/host implementation
+   template  class multi_ptr {
+ T *m_Pointer; // regular undecorated pointer
+ public:
+ T *get() { return m_Pointer; }
+ T& operator* () { return *m_Pointer; }
+   }
+   #endif
+
+Depending on the compiler mode, ``multi_ptr`` will either decorate its internal
+data with the address space attribute or not.
+
+To utilize clang's existing functionality, we reuse the following OpenCL 
address
+space attributes for pointers:
+
+.. list-table::
+   :header-rows: 1
+
+   * - Address space attribute
+ - SYCL address_space enumeration
+   * - ``__attribute__((opencl_global))``
+ - global_space, constant_space
+   * - 

[clang] 7818906 - [SYCL] Implement SYCL address space attributes handling

2021-04-26 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-04-26T13:44:10+03:00
New Revision: 7818906ca134775edffb77857f436359d3a50b90

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

LOG: [SYCL] Implement SYCL address space attributes handling

Default address space (applies when no explicit address space was
specified) maps to generic (4) address space.

Added SYCL named address spaces `sycl_global`, `sycl_local` and
`sycl_private` defined as sub-sets of the default address space.

Static variables without address space now reside in global address
space when compile for SPIR target, unless they have an explicit address
space qualifier in source code.

Differential Revision: https://reviews.llvm.org/D89909

Added: 
clang/test/CodeGenSYCL/address-space-conversions.cpp
clang/test/CodeGenSYCL/address-space-deduction.cpp
clang/test/CodeGenSYCL/address-space-mangling.cpp
clang/test/SemaSYCL/address-space-conversions.cpp

Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Basic/AddressSpaces.h
clang/include/clang/Sema/ParsedAttr.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Basic/Targets/SPIR.h
clang/lib/Basic/Targets/TCE.h
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Sema/SemaType.cpp
clang/test/SemaTemplate/address_space-dependent.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 530b3cecc023b..84de51aba5b2d 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -488,7 +488,11 @@ class Qualifiers {
B == LangAS::opencl_global_host)) ||
// Consider pointer size address spaces to be equivalent to default.
((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
-(isPtrSizeAddressSpace(B) || B == LangAS::Default));
+(isPtrSizeAddressSpace(B) || B == LangAS::Default)) ||
+   // Default is a superset of SYCL address spaces.
+   (A == LangAS::Default &&
+(B == LangAS::sycl_private || B == LangAS::sycl_local ||
+ B == LangAS::sycl_global));
   }
 
   /// Returns true if the address space in these qualifiers is equal to or

diff  --git a/clang/include/clang/Basic/AddressSpaces.h 
b/clang/include/clang/Basic/AddressSpaces.h
index a9db52dfcc9c8..5fa031250a629 100644
--- a/clang/include/clang/Basic/AddressSpaces.h
+++ b/clang/include/clang/Basic/AddressSpaces.h
@@ -44,6 +44,11 @@ enum class LangAS : unsigned {
   cuda_constant,
   cuda_shared,
 
+  // SYCL specific address spaces.
+  sycl_global,
+  sycl_local,
+  sycl_private,
+
   // Pointer size and extension address spaces.
   ptr32_sptr,
   ptr32_uptr,

diff  --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index e508b4651be1c..347925873b30f 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -628,8 +628,8 @@ class ParsedAttr final
   /// a Spelling enumeration, the value UINT_MAX is returned.
   unsigned getSemanticSpelling() const;
 
-  /// If this is an OpenCL addr space attribute returns its representation
-  /// in LangAS, otherwise returns default addr space.
+  /// If this is an OpenCL address space attribute returns its representation
+  /// in LangAS, otherwise returns default address space.
   LangAS asOpenCLLangAS() const {
 switch (getParsedKind()) {
 case ParsedAttr::AT_OpenCLConstantAddressSpace:
@@ -651,6 +651,22 @@ class ParsedAttr final
 }
   }
 
+  /// If this is an OpenCL address space attribute returns its SYCL
+  /// representation in LangAS, otherwise returns default address space.
+  LangAS asSYCLLangAS() const {
+switch (getKind()) {
+case ParsedAttr::AT_OpenCLGlobalAddressSpace:
+  return LangAS::sycl_global;
+case ParsedAttr::AT_OpenCLLocalAddressSpace:
+  return LangAS::sycl_local;
+case ParsedAttr::AT_OpenCLPrivateAddressSpace:
+  return LangAS::sycl_private;
+case ParsedAttr::AT_OpenCLGenericAddressSpace:
+default:
+  return LangAS::Default;
+}
+  }
+
   AttributeCommonInfo::Kind getKind() const {
 return AttributeCommonInfo::Kind(Info.AttrKind);
   }

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index aefb2ade81d2a..85e5a61836337 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -931,6 +931,9 @@ static const LangASMap *getAddressSpaceMap(const TargetInfo 
,

[clang] 95c614a - [NFC][SYCL] Drop idle triple component from regression tests.

2021-04-13 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-04-13T08:00:21+03:00
New Revision: 95c614afcd4de71d00a240d6a4a02c036c972ed0

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

LOG: [NFC][SYCL] Drop idle triple component from regression tests.

Added: 


Modified: 
clang/test/CodeGenSYCL/convergent.cpp
clang/test/CodeGenSYCL/filescope_asm.c

Removed: 




diff  --git a/clang/test/CodeGenSYCL/convergent.cpp 
b/clang/test/CodeGenSYCL/convergent.cpp
index 58be1b153c937..779f1592da0e0 100644
--- a/clang/test/CodeGenSYCL/convergent.cpp
+++ b/clang/test/CodeGenSYCL/convergent.cpp
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
-// RUN:  -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | \
-// RUN:   FileCheck %s
+// RUN:  -triple spir64 -emit-llvm %s -o - | FileCheck %s
 
 // CHECK-DAG: Function Attrs:
 // CHECK-DAG-SAME: convergent

diff  --git a/clang/test/CodeGenSYCL/filescope_asm.c 
b/clang/test/CodeGenSYCL/filescope_asm.c
index 3c1c12fd589a6..9c0d088ec0a2d 100644
--- a/clang/test/CodeGenSYCL/filescope_asm.c
+++ b/clang/test/CodeGenSYCL/filescope_asm.c
@@ -1,4 +1,4 @@
-// RUN:  %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice 
-emit-llvm %s -o - | FileCheck %s
+// RUN:  %clang_cc1 -fsycl-is-device -triple spir64 -emit-llvm %s -o - | 
FileCheck %s
 //
 // Check that file-scope asm is ignored during device-side SYCL compilation.
 //



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


[clang] a500a43 - [CodeGen][AMDGPU] Fix ICE for static initializer IR generation

2020-12-12 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2020-12-12T23:26:54+03:00
New Revision: a500a4358789d1794bc672421c55900ea2bbc938

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

LOG: [CodeGen][AMDGPU] Fix ICE for static initializer IR generation

Differential Revision: https://reviews.llvm.org/D92782

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/test/CodeGen/address-space.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 478821665e45..a01638f0b67b 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -353,12 +353,11 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const 
VarDecl ,
   if (GV->getValueType() != Init->getType()) {
 llvm::GlobalVariable *OldGV = GV;
 
-GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
-  OldGV->isConstant(),
-  OldGV->getLinkage(), Init, "",
-  /*InsertBefore*/ OldGV,
-  OldGV->getThreadLocalMode(),
-   
CGM.getContext().getTargetAddressSpace(D.getType()));
+GV = new llvm::GlobalVariable(
+CGM.getModule(), Init->getType(), OldGV->isConstant(),
+OldGV->getLinkage(), Init, "",
+/*InsertBefore*/ OldGV, OldGV->getThreadLocalMode(),
+OldGV->getType()->getPointerAddressSpace());
 GV->setVisibility(OldGV->getVisibility());
 GV->setDSOLocal(OldGV->isDSOLocal());
 GV->setComdat(OldGV->getComdat());

diff  --git a/clang/test/CodeGen/address-space.c 
b/clang/test/CodeGen/address-space.c
index c66dfc87c0c0..baefb4b983fc 100644
--- a/clang/test/CodeGen/address-space.c
+++ b/clang/test/CodeGen/address-space.c
@@ -59,3 +59,14 @@ void __attribute__((address_space(1)))*
 void_ptr_arithmetic_test(void __attribute__((address_space(1))) *arg) {
 return arg + 4;
 }
+
+// CHECK-LABEL: define i32* @test5(
+const unsigned *test5() {
+  // Intentionally leave a part of an array uninitialized. This triggers a
+  // 
diff erent code path contrary to a fully initialized array.
+  // CHECK: ret i32* getelementptr inbounds ([256 x i32]
+  static const unsigned bars[256] = {
+  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+  11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
+  return [0];
+}



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


[clang] 9263931 - [SYCL] Assume SYCL device functions are convergent

2020-09-29 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2020-09-29T15:23:50+03:00
New Revision: 9263931fcccdc99000c1de668bea330711333729

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

LOG: [SYCL] Assume SYCL device functions are convergent

SYCL device compiler (similar to other SPMD compilers) assumes that
functions are convergent by default to avoid invalid transformations.
This attribute can be removed if compiler can prove that function does
not have convergent operations.

Reviewed By: Naghasan

Differential Revision: https://reviews.llvm.org/D87282

Added: 
clang/test/CodeGenSYCL/convergent.cpp

Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2d008d8a3fbe..42224339250d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2882,7 +2882,8 @@ static void ParseLangArgs(LangOptions , ArgList 
, InputKind IK,
   Opts.Coroutines = Opts.CPlusPlus20 || Args.hasArg(OPT_fcoroutines_ts);
 
   Opts.ConvergentFunctions = Opts.OpenCL || (Opts.CUDA && Opts.CUDAIsDevice) ||
-Args.hasArg(OPT_fconvergent_functions);
+ Opts.SYCLIsDevice ||
+ Args.hasArg(OPT_fconvergent_functions);
 
   Opts.DoubleSquareBracketAttributes =
   Args.hasFlag(OPT_fdouble_square_bracket_attributes,

diff  --git a/clang/test/CodeGenSYCL/convergent.cpp 
b/clang/test/CodeGenSYCL/convergent.cpp
new file mode 100644
index ..784fb8976c27
--- /dev/null
+++ b/clang/test/CodeGenSYCL/convergent.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsycl -fsycl-is-device -emit-llvm -disable-llvm-passes \
+// RUN:  -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | \
+// RUN:   FileCheck %s
+
+// CHECK-DAG: Function Attrs:
+// CHECK-DAG-SAME: convergent
+// CHECK-DAG-NEXT: define void @_Z3foov
+void foo() {
+  int a = 1;
+}
+
+template 
+__attribute__((sycl_kernel)) void kernel_single_task(const Func ) {
+  kernelFunc();
+}
+
+int main() {
+  kernel_single_task([] { foo(); });
+  return 0;
+}



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


[clang] 8d27be8 - [OpenCL] Add global_device and global_host address spaces

2020-07-29 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2020-07-29T17:24:53+03:00
New Revision: 8d27be8dbaffce0519ac41173d51923fc2524b1b

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

LOG: [OpenCL] Add global_device and global_host address spaces

This patch introduces 2 new address spaces in OpenCL: global_device and 
global_host
which are a subset of a global address space, so the address space scheme will 
be
looking like:

```
generic->global->host
  ->device
 ->private
 ->local
constant
```

Justification: USM allocations may be associated with both host and device 
memory. We
want to give users a way to tell the compiler the allocation type of a USM 
pointer for
optimization purposes. (Link to the Unified Shared Memory extension:
https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc)

Before this patch USM pointer could be only in opencl_global
address space, hence a device backend can't tell if a particular pointer
points to host or device memory. On FPGAs at least we can generate more
efficient hardware code if the user tells us where the pointer can point -
being able to distinguish between these types of pointers at compile time
allows us to instantiate simpler load-store units to perform memory
transactions.

Patch by Dmitry Sidorov.

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D82174

Added: 
clang/test/SemaOpenCL/usm-address-spaces-conversions.cl

Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Basic/AddressSpaces.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Sema/ParsedAttr.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Basic/Targets/SPIR.h
clang/lib/Basic/Targets/TCE.h
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaType.cpp
clang/test/AST/language_address_space_attribute.cpp
clang/test/CodeGenCXX/mangle-address-space.cpp
clang/test/CodeGenOpenCL/address-spaces-conversions.cl
clang/test/CodeGenOpenCL/address-spaces.cl
clang/test/SemaTemplate/address_space-dependent.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 7fe652492b0e..7d943ebc78c0 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -480,6 +480,11 @@ class Qualifiers {
// Otherwise in OpenCLC v2.0 s6.5.5: every address space except
// for __constant can be used as __generic.
(A == LangAS::opencl_generic && B != LangAS::opencl_constant) ||
+   // We also define global_device and global_host address spaces,
+   // to distinguish global pointers allocated on host from pointers
+   // allocated on device, which are a subset of __global.
+   (A == LangAS::opencl_global && (B == LangAS::opencl_global_device ||
+   B == LangAS::opencl_global_host)) ||
// Consider pointer size address spaces to be equivalent to default.
((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
 (isPtrSizeAddressSpace(B) || B == LangAS::Default));

diff  --git a/clang/include/clang/Basic/AddressSpaces.h 
b/clang/include/clang/Basic/AddressSpaces.h
index faf7f303aa2d..a9db52dfcc9c 100644
--- a/clang/include/clang/Basic/AddressSpaces.h
+++ b/clang/include/clang/Basic/AddressSpaces.h
@@ -36,6 +36,8 @@ enum class LangAS : unsigned {
   opencl_constant,
   opencl_private,
   opencl_generic,
+  opencl_global_device,
+  opencl_global_host,
 
   // CUDA specific address spaces.
   cuda_device,

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 0ee3c5188563..f9bf3f0acd55 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1178,6 +1178,16 @@ def OpenCLGlobalAddressSpace : TypeAttr {
   let Documentation = [OpenCLAddressSpaceGlobalDocs];
 }
 
+def OpenCLGlobalDeviceAddressSpace : TypeAttr {
+  let Spellings = [Clang<"opencl_global_device">];
+  let Documentation = [OpenCLAddressSpaceGlobalExtDocs];
+}
+
+def OpenCLGlobalHostAddressSpace : TypeAttr {
+  let Spellings = [Clang<"opencl_global_host">];
+  let Documentation = [OpenCLAddressSpaceGlobalExtDocs];
+}
+
 def OpenCLLocalAddressSpace : TypeAttr {
   let Spellings = [Keyword<"__local">, Keyword<"local">, 
Clang<"opencl_local">];
   let Documentation = [OpenCLAddressSpaceLocalDocs];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 

[clang] 0bdcd95 - [SYCL][OpenMP] Implement thread-local storage restriction

2020-06-17 Thread Alexey Bader via cfe-commits

Author: Mariya Podchishchaeva
Date: 2020-06-17T14:36:00+03:00
New Revision: 0bdcd95bf20f159a2512aff1ef032bec52039bf6

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

LOG: [SYCL][OpenMP] Implement thread-local storage restriction

Summary:
SYCL and OpenMP prohibits thread local storage in device code,
so this commit ensures that error is emitted for device code and not
emitted for host code when host target supports it.

Reviewers: jdoerfert, erichkeane, bader

Reviewed By: jdoerfert, erichkeane

Subscribers: guansong, riccibruno, ABataev, yaxunl, ebevhan, Anastasia, 
sstefan1, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81641

Added: 
clang/test/OpenMP/nvptx_prohibit_thread_local.cpp
clang/test/SemaSYCL/prohibit-thread-local.cpp

Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/OpenMP/nvptx_target_codegen.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2bf16d138d5a..80469e3bedbe 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7077,7 +7077,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
diag::err_thread_non_global)
 << DeclSpec::getSpecifierName(TSCS);
 else if (!Context.getTargetInfo().isTLSSupported()) {
-  if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) {
+  if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
+  getLangOpts().SYCLIsDevice) {
 // Postpone error emission until we've collected attributes required to
 // figure out whether it's a host or device variable and whether the
 // error should be ignored.
@@ -7179,13 +7180,18 @@ NamedDecl *Sema::ActOnVariableDeclarator(
   // Handle attributes prior to checking for duplicates in MergeVarDecl
   ProcessDeclAttributes(S, NewVD, D);
 
-  if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) {
+  if (getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
+  getLangOpts().SYCLIsDevice) {
 if (EmitTLSUnsupportedError &&
 ((getLangOpts().CUDA && DeclAttrsMatchCUDAMode(getLangOpts(), NewVD)) 
||
  (getLangOpts().OpenMPIsDevice &&
   OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(NewVD
   Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
diag::err_thread_unsupported);
+
+if (EmitTLSUnsupportedError &&
+(LangOpts.SYCLIsDevice || (LangOpts.OpenMP && 
LangOpts.OpenMPIsDevice)))
+  targetDiag(D.getIdentifierLoc(), diag::err_thread_unsupported);
 // CUDA B.2.5: "__shared__ and __constant__ variables have implied static
 // storage [duration]."
 if (SC == SC_None && S->getFnParent() != nullptr &&

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 66a2ec1fe9dc..ffc72140dcf4 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -355,10 +355,16 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
 
   diagnoseUseOfInternalDeclInInlineFunction(*this, D, Loc);
 
-  if (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice))
+  if (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice)) {
 if (const auto *VD = dyn_cast(D))
   checkDeviceDecl(VD, Loc);
 
+if (!Context.getTargetInfo().isTLSSupported())
+  if (const auto *VD = dyn_cast(D))
+if (VD->getTLSKind() != VarDecl::TLS_None)
+  targetDiag(*Locs.begin(), diag::err_thread_unsupported);
+  }
+
   if (isa(D) && isa(D->getDeclContext()) &&
   !isUnevaluatedContext()) {
 // C++ [expr.prim.req.nested] p3

diff  --git a/clang/test/OpenMP/nvptx_prohibit_thread_local.cpp 
b/clang/test/OpenMP/nvptx_prohibit_thread_local.cpp
new file mode 100644
index ..b84918e528cb
--- /dev/null
+++ b/clang/test/OpenMP/nvptx_prohibit_thread_local.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-linux 
-fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown 
-aux-triple x86_64-unknown-linux -fopenmp-targets=nvptx64-nvidia-cuda %s 
-fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc -fsyntax-only
+
+thread_local const int prohobit_ns_scope = 0;
+thread_local int prohobit_ns_scope2 = 0;
+thread_local const int allow_ns_scope = 0;
+
+struct S {
+  static const thread_local int prohibit_static_member;
+  static thread_local int prohibit_static_member2;
+};
+
+struct T {
+  static const thread_local int allow_static_member;
+};
+
+void foo() {
+  // expected-error@+1{{thread-local storage is not supported for the current 
target}}
+  thread_local const int prohibit_local = 0;
+  // expected-error@+1{{thread-local storage is not supported for 

[clang] 93cd411 - [NFC] Run clang-format on clang/test/OpenMP/nvptx_target_codegen.cpp

2020-06-17 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2020-06-17T13:04:01+03:00
New Revision: 93cd4115799cefa698833ca7a2f1899243d94c77

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

LOG: [NFC] Run clang-format on clang/test/OpenMP/nvptx_target_codegen.cpp

Added: 


Modified: 
clang/test/OpenMP/nvptx_target_codegen.cpp

Removed: 




diff  --git a/clang/test/OpenMP/nvptx_target_codegen.cpp 
b/clang/test/OpenMP/nvptx_target_codegen.cpp
index 20415c0dc1b6..d615b8536c48 100644
--- a/clang/test/OpenMP/nvptx_target_codegen.cpp
+++ b/clang/test/OpenMP/nvptx_target_codegen.cpp
@@ -16,16 +16,16 @@
 // CHECK-DAG: {{@__omp_offloading_.+l123}}_exec_mode = weak constant i8 1
 // CHECK-DAG: {{@__omp_offloading_.+l200}}_exec_mode = weak constant i8 1
 // CHECK-DAG: {{@__omp_offloading_.+l310}}_exec_mode = weak constant i8 1
-// CHECK-DAG: {{@__omp_offloading_.+l348}}_exec_mode = weak constant i8 1
-// CHECK-DAG: {{@__omp_offloading_.+l366}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l347}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l365}}_exec_mode = weak constant i8 1
 // CHECK-DAG: {{@__omp_offloading_.+l331}}_exec_mode = weak constant i8 1
 
 __thread int id;
 
 int baz(int f, double );
 
-template
-struct TT{
+template 
+struct TT {
   tx X;
   ty Y;
   tx [](int i) { return X; }
@@ -56,258 +56,258 @@ int foo(int n) {
   double cn[5][n];
   TT d;
 
-  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+foo.+l123}}_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 @__kmpc_barrier_simple_spmd(%struct.ident_t* null, i32 0)
-  // 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: br label {{%?}}[[BAR_PARALLEL]]
-  //
-  // CHECK: [[BAR_PARALLEL]]
-  // CHECK: call void @__kmpc_barrier_simple_spmd(%struct.ident_t* null, i32 0)
-  // CHECK: br label {{%?}}[[AWAIT_WORK]]
-  //
-  // CHECK: [[EXIT]]
-  // CHECK: ret void
-
-  // CHECK: define {{.*}}void [[T1:@__omp_offloading_.+foo.+l123]]()
-  // CHECK-DAG: [[TID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
-  // CHECK-DAG: [[NTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
-  // CHECK-DAG: [[WS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
-  // CHECK-DAG: [[TH_LIMIT:%.+]] = sub nuw i32 [[NTH]], [[WS]]
-  // CHECK: [[IS_WORKER:%.+]] = icmp ult i32 [[TID]], [[TH_LIMIT]]
-  // CHECK: br i1 [[IS_WORKER]], label {{%?}}[[WORKER:.+]], label 
{{%?}}[[CHECK_MASTER:.+]]
-  //
-  // CHECK: [[WORKER]]
-  // CHECK: {{call|invoke}} void [[T1]]_worker()
-  // CHECK: br label {{%?}}[[EXIT:.+]]
-  //
-  // CHECK: [[CHECK_MASTER]]
-  // CHECK-DAG: [[CMTID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
-  // CHECK-DAG: [[CMNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
-  // CHECK-DAG: [[CMWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
-  // CHECK: [[IS_MASTER:%.+]] = icmp eq i32 [[CMTID]],
-  // CHECK: br i1 [[IS_MASTER]], label {{%?}}[[MASTER:.+]], label 
{{%?}}[[EXIT]]
-  //
-  // CHECK: [[MASTER]]
-  // CHECK-DAG: [[MNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
-  // CHECK-DAG: [[MWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
-  // CHECK: [[MTMP1:%.+]] = sub nuw i32 [[MNTH]], [[MWS]]
-  // CHECK: call void @__kmpc_kernel_init(i32 [[MTMP1]]
-  // CHECK: br label {{%?}}[[TERMINATE:.+]]
-  //
-  // CHECK: [[TERMINATE]]
-  // CHECK: call void @__kmpc_kernel_deinit(
-  // CHECK: call void @__kmpc_barrier_simple_spmd(%struct.ident_t* null, i32 0)
-  // CHECK: br label {{%?}}[[EXIT]]
-  //
-  // CHECK: [[EXIT]]
-  // CHECK: ret void
-  #pragma omp target
+// CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+foo.+l123}}_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 @__kmpc_barrier_simple_spmd(%struct.ident_t* null, i32 0)
+// 

[clang] bd85b7d - [OpenMP][SYCL] Do not crash on attempt to diagnose unsupported type use

2020-05-30 Thread Alexey Bader via cfe-commits

Author: Mariya Podchishchaeva
Date: 2020-05-30T12:27:58+03:00
New Revision: bd85b7d6688725e854a694f9f3e8baa6a3077a4a

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

LOG: [OpenMP][SYCL] Do not crash on attempt to diagnose unsupported type use

Summary:
Do not ask size of type if it is dependent. ASTContext doesn't seem expecting
this.

Reviewers: jdoerfert, ABataev, bader

Reviewed By: ABataev

Subscribers: yaxunl, guansong, ebevhan, Anastasia, sstefan1, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80829

Added: 


Modified: 
clang/lib/Sema/Sema.cpp
clang/test/OpenMP/nvptx_unsupported_type_messages.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 8c11a1a59e9c..ffe2e4d4d56a 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1725,6 +1725,9 @@ void Sema::checkDeviceDecl(const ValueDecl *D, 
SourceLocation Loc) {
   }
 
   auto CheckType = [&](QualType Ty) {
+if (Ty->isDependentType())
+  return;
+
 if ((Ty->isFloat16Type() && !Context.getTargetInfo().hasFloat16Type()) ||
 ((Ty->isFloat128Type() ||
   (Ty->isRealFloatingType() && Context.getTypeSize(Ty) == 128)) &&

diff  --git a/clang/test/OpenMP/nvptx_unsupported_type_messages.cpp 
b/clang/test/OpenMP/nvptx_unsupported_type_messages.cpp
index 22ce8175fd05..e56105adeb83 100644
--- a/clang/test/OpenMP/nvptx_unsupported_type_messages.cpp
+++ b/clang/test/OpenMP/nvptx_unsupported_type_messages.cpp
@@ -120,3 +120,14 @@ void hostFoo() {
 long double qa, qb;
 decltype(qa + qb) qc;
 double qd[sizeof(-(-(qc * 2)))];
+
+struct A { };
+
+template 
+struct A_type { typedef A type; };
+
+template 
+struct B {
+  enum { value = bool(Sp::value) || bool(Tp::value) };
+  typedef typename A_type::type type;
+};



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


[clang] cf6cc66 - [OpenMP][SYCL] Improve diagnosing of unsupported types usage

2020-05-29 Thread Alexey Bader via cfe-commits

Author: Mariya Podchishchaeva
Date: 2020-05-29T18:00:48+03:00
New Revision: cf6cc6622b1416430f517850be9032788e39

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

LOG: [OpenMP][SYCL] Improve diagnosing of unsupported types usage

Summary:
Diagnostic is emitted if some declaration of unsupported type
declaration is used inside device code.
Memcpy operations for structs containing member with unsupported type
are allowed. Fixed crash on attempt to emit diagnostic outside of the
functions.

The approach is generalized between SYCL and OpenMP.
CUDA/OMP deferred diagnostic interface is going to be used for SYCL device.

Reviewers: rsmith, rjmccall, ABataev, erichkeane, bader, jdoerfert, 
aaron.ballman

Reviewed By: jdoerfert

Subscribers: guansong, sstefan1, yaxunl, mgorny, bader, ebevhan, Anastasia, 
cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74387

Added: 
clang/lib/Sema/SemaSYCL.cpp
clang/test/SemaSYCL/float128.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/CMakeLists.txt
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Headers/nvptx_device_math_sin.c
clang/test/Headers/nvptx_device_math_sin.cpp
clang/test/OpenMP/nvptx_unsupported_type_codegen.cpp
clang/test/OpenMP/nvptx_unsupported_type_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 845e329033c3..63af9f42dfd3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10204,8 +10204,8 @@ def err_omp_invariant_or_linear_dependency : Error<
   "expected loop invariant expression or ' * %0 + ' 
kind of expression">;
 def err_omp_wrong_dependency_iterator_type : Error<
   "expected an integer or a pointer type of the outer loop counter '%0' for 
non-rectangular nests">;
-def err_omp_unsupported_type : Error <
-  "host requires %0 bit size %1 type support, but device '%2' does not support 
it">;
+def err_device_unsupported_type : Error <
+  "%0 requires %1 bit size %2 type support, but device '%3' does not support 
it">;
 def err_omp_lambda_capture_in_declare_target_not_to : Error<
   "variable captured in declare target region must appear in a to clause">;
 def err_omp_device_type_mismatch : Error<

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index dc7ee2ddd0b8..594c6e03aa38 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9868,10 +9868,6 @@ class Sema final {
   /// Pop OpenMP function region for non-capturing function.
   void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI);
 
-  /// Check if the expression is allowed to be used in expressions for the
-  /// OpenMP devices.
-  void checkOpenMPDeviceExpr(const Expr *E);
-
   /// Checks if a type or a declaration is disabled due to the owning extension
   /// being disabled, and emits diagnostic messages if it is disabled.
   /// \param D type or declaration to be checked.
@@ -11654,6 +11650,10 @@ class Sema final {
 
   DeviceDiagBuilder targetDiag(SourceLocation Loc, unsigned DiagID);
 
+  /// Check if the expression is allowed to be used in expressions for the
+  /// offloading devices.
+  void checkDeviceDecl(const ValueDecl *D, SourceLocation Loc);
+
   enum CUDAFunctionTarget {
 CFT_Device,
 CFT_Global,
@@ -12396,6 +12396,40 @@ class Sema final {
 ConstructorDestructor,
 BuiltinFunction
   };
+  /// Creates a DeviceDiagBuilder that emits the diagnostic if the current
+  /// context is "used as device code".
+  ///
+  /// - If CurLexicalContext is a kernel function or it is known that the
+  ///   function will be emitted for the device, emits the diagnostics
+  ///   immediately.
+  /// - If CurLexicalContext is a function and we are compiling
+  ///   for the device, but we don't know that this function will be codegen'ed
+  ///   for devive yet, creates a diagnostic which is emitted if and when we
+  ///   realize that the function will be codegen'ed.
+  ///
+  /// Example usage:
+  ///
+  /// Diagnose __float128 type usage only from SYCL device code if the current
+  /// target doesn't support it
+  /// if (!S.Context.getTargetInfo().hasFloat128Type() &&
+  /// S.getLangOpts().SYCLIsDevice)
+  ///   SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128";
+  DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
+
+  /// Check whether we're allowed to call Callee from the current context.
+  

[clang] e95ee30 - [SYCL] Prohibit arithmetic operations for incompatible pointers

2020-05-22 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2020-05-22T13:43:24+03:00
New Revision: e95ee300c0530158d86430fd82ffabd36262e862

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

LOG: [SYCL] Prohibit arithmetic operations for incompatible pointers

Summary:
This change enables OpenCL diagnostics for the pointers annotated with
address space attribute SYCL mode.

Move `isAddressSpaceOverlapping` method from PointerType to QualType.

Reviewers: Anastasia, rjmccall

Reviewed By: rjmccall

Subscribers: rjmccall, jeroen.dobbelaere, Fznamznon, yaxunl, ebevhan, 
cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80317

Added: 
clang/test/SemaCXX/address-space-arithmetic.cpp

Modified: 
clang/include/clang/AST/Type.h
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/address_spaces.c

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 21b14de997cb..ed31dea925f3 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1064,6 +1064,21 @@ class QualType {
   /// Return the address space of this type.
   inline LangAS getAddressSpace() const;
 
+  /// Returns true if address space qualifiers overlap with T address space
+  /// qualifiers.
+  /// OpenCL C defines conversion rules for pointers to 
diff erent address spaces
+  /// and notion of overlapping address spaces.
+  /// CL1.1 or CL1.2:
+  ///   address spaces overlap iff they are they same.
+  /// OpenCL C v2.0 s6.5.5 adds:
+  ///   __generic overlaps with any address space except for __constant.
+  bool isAddressSpaceOverlapping(QualType T) const {
+Qualifiers Q = getQualifiers();
+Qualifiers TQ = T.getQualifiers();
+// Address spaces overlap if at least one of them is a superset of another
+return Q.isAddressSpaceSupersetOf(TQ) || TQ.isAddressSpaceSupersetOf(Q);
+  }
+
   /// Returns gc attribute of this type.
   inline Qualifiers::GC getObjCGCAttr() const;
 
@@ -2631,22 +2646,6 @@ class PointerType : public Type, public 
llvm::FoldingSetNode {
 public:
   QualType getPointeeType() const { return PointeeType; }
 
-  /// Returns true if address spaces of pointers overlap.
-  /// OpenCL v2.0 defines conversion rules for pointers to 
diff erent
-  /// address spaces (OpenCLC v2.0 s6.5.5) and notion of overlapping
-  /// address spaces.
-  /// CL1.1 or CL1.2:
-  ///   address spaces overlap iff they are they same.
-  /// CL2.0 adds:
-  ///   __generic overlaps with any address space except for __constant.
-  bool isAddressSpaceOverlapping(const PointerType ) const {
-Qualifiers thisQuals = PointeeType.getQualifiers();
-Qualifiers otherQuals = other.getPointeeType().getQualifiers();
-// Address spaces overlap if at least one of them is a superset of another
-return thisQuals.isAddressSpaceSupersetOf(otherQuals) ||
-   otherQuals.isAddressSpaceSupersetOf(thisQuals);
-  }
-
   bool isSugared() const { return false; }
   QualType desugar() const { return QualType(this, 0); }
 

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index a4fe90f79eb9..fe4fcdd01301 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -2391,7 +2391,7 @@ static TryCastResult TryAddressSpaceCast(Sema , 
ExprResult ,
 return TC_NotApplicable;
   auto SrcPointeeType = SrcPtrType->getPointeeType();
   auto DestPointeeType = DestPtrType->getPointeeType();
-  if (!DestPtrType->isAddressSpaceOverlapping(*SrcPtrType)) {
+  if (!DestPointeeType.isAddressSpaceOverlapping(SrcPointeeType)) {
 msg = diag::err_bad_cxx_cast_addr_space_mismatch;
 return TC_Failed;
   }
@@ -2434,9 +2434,9 @@ void CastOperation::checkAddressSpaceCast(QualType 
SrcType, QualType DestType) {
   const PointerType *SrcPPtr = cast(SrcPtr);
   QualType DestPPointee = DestPPtr->getPointeeType();
   QualType SrcPPointee = SrcPPtr->getPointeeType();
-  if (Nested ? DestPPointee.getAddressSpace() !=
-   SrcPPointee.getAddressSpace()
- : !DestPPtr->isAddressSpaceOverlapping(*SrcPPtr)) {
+  if (Nested
+  ? DestPPointee.getAddressSpace() != SrcPPointee.getAddressSpace()
+  : !DestPPointee.isAddressSpaceOverlapping(SrcPPointee)) {
 Self.Diag(OpRange.getBegin(), DiagID)
 << SrcType << DestType << Sema::AA_Casting
 << SrcExpr.get()->getSourceRange();

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 93e67ad2940c..261e69b44052 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10087,10 +10087,8 @@ static bool checkArithmeticBinOpPointerOperands(Sema 
, SourceLocation Loc,
   if (isRHSPointer) RHSPointeeTy = RHSExpr->getType()->getPointeeType();
 

[clang] 118b057 - [SYCL] Driver option to select SYCL version

2020-03-07 Thread Alexey Bader via cfe-commits

Author: Ruyman
Date: 2020-03-07T18:28:54+03:00
New Revision: 118b057f1268d1789e40ffceb214e73772df04f4

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

LOG: [SYCL] Driver option to select SYCL version

Summary:
User can select the version of SYCL the compiler will
use via the flag -sycl-std, similar to -cl-std.

The flag defines the LangOpts.SYCLVersion option to the
version of SYCL. The default value is undefined.
If driver is building SYCL code, flag is set to the default SYCL
version (1.2.1)

The preprocessor uses this variable to define CL_SYCL_LANGUAGE_VERSION macro,
which should be defined according to SYCL 1.2.1 standard.

Only valid value at this point for the flag is 1.2.1.

Co-Authored-By: David Wood 
Signed-off-by: Ruyman Reyes 

Subscribers: ebevhan, Anastasia, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72857

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Driver/sycl.c
clang/test/Frontend/sycl-aux-triple.cpp
clang/test/Preprocessor/sycl-macro.cpp
clang/test/SemaSYCL/kernel-attribute.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 3cc7c384ac10..53b87b737568 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -230,7 +230,9 @@ LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate 
relocatable device code")
 LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions 
for HIP")
 LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for 
kernel launch bounds for HIP")
 
+LANGOPT(SYCL  , 1, 0, "SYCL")
 LANGOPT(SYCLIsDevice  , 1, 0, "Generate code for SYCL device")
+LANGOPT(SYCLVersion   , 32, 0, "Version of the SYCL standard used")
 
 LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2aaf85434214..0d5cba8d682a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3422,10 +3422,12 @@ defm underscoring : BooleanFFlag<"underscoring">, 
Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
 
 // C++ SYCL options
-def fsycl : Flag<["-"], "fsycl">, Group,
+def fsycl : Flag<["-"], "fsycl">, Group, Flags<[CC1Option, 
CoreOption]>,
   HelpText<"Enable SYCL kernels compilation for device">;
-def fno_sycl : Flag<["-"], "fno-sycl">, Group,
+def fno_sycl : Flag<["-"], "fno-sycl">, Group, Flags<[CoreOption]>,
   HelpText<"Disable SYCL kernels compilation for device">;
+def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
+  HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 
1.2.1, sycl-1.2.1">;
 
 include "CC1Options.td"
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3ca034e69b3b..99faae396be3 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4048,9 +4048,18 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
   }
 
-  if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false))
+  if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false)) {
+CmdArgs.push_back("-fsycl");
 CmdArgs.push_back("-fsycl-is-device");
 
+if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
+  A->render(Args, CmdArgs);
+} else {
+  // Ensure the default version in SYCL mode is 1.2.1 (aka 2017)
+  CmdArgs.push_back("-sycl-std=2017");
+}
+  }
+
   if (IsOpenMPDevice) {
 // We have to pass the triple of the host if compiling for an OpenMP 
device.
 std::string NormalizedTriple =

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 48c65aded817..9f3522a3e654 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2544,6 +2544,24 @@ static void ParseLangArgs(LangOptions , ArgList 
, InputKind IK,
   LangStd = OpenCLLangStd;
   }
 
+  Opts.SYCL = Args.hasArg(options::OPT_fsycl);
+  Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
+  if (Opts.SYCL) {
+// -sycl-std applies to any SYCL source, not only those containing kernels,
+// but also those using the SYCL API
+if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
+  Opts.SYCLVersion = 

[clang] 740ed61 - Revert "[SYCL] Driver option to select SYCL version"

2020-02-27 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2020-02-27T16:23:54+03:00
New Revision: 740ed617f7d4d16e7883636c5eff994f8be7eba4

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

LOG: Revert "[SYCL] Driver option to select SYCL version"

This reverts commit bd97704eb5a95ecb048ce343c1a4be5d94e5.

It broke tests on mac: http://45.33.8.238/mac/9011/step_7.txt

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Driver/sycl.c
clang/test/Frontend/sycl-aux-triple.cpp
clang/test/Preprocessor/sycl-macro.cpp
clang/test/SemaSYCL/kernel-attribute.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 53b87b737568..3cc7c384ac10 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -230,9 +230,7 @@ LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate 
relocatable device code")
 LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions 
for HIP")
 LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for 
kernel launch bounds for HIP")
 
-LANGOPT(SYCL  , 1, 0, "SYCL")
 LANGOPT(SYCLIsDevice  , 1, 0, "Generate code for SYCL device")
-LANGOPT(SYCLVersion   , 32, 0, "Version of the SYCL standard used")
 
 LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 36626342e364..f1801e3e89e7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3420,12 +3420,10 @@ defm underscoring : BooleanFFlag<"underscoring">, 
Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
 
 // C++ SYCL options
-def fsycl : Flag<["-"], "fsycl">, Group, Flags<[CC1Option, 
CoreOption]>,
+def fsycl : Flag<["-"], "fsycl">, Group,
   HelpText<"Enable SYCL kernels compilation for device">;
-def fno_sycl : Flag<["-"], "fno-sycl">, Group, Flags<[CoreOption]>,
+def fno_sycl : Flag<["-"], "fno-sycl">, Group,
   HelpText<"Disable SYCL kernels compilation for device">;
-def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
-  HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 
1.2.1, sycl-1.2.1">;
 
 include "CC1Options.td"
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 87596dd19c5a..d387a1dc2079 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4040,18 +4040,9 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
   }
 
-  if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false)) {
-CmdArgs.push_back("-fsycl");
+  if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false))
 CmdArgs.push_back("-fsycl-is-device");
 
-if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
-  A->render(Args, CmdArgs);
-} else {
-  // Ensure the default version in SYCL mode is 1.2.1 (aka 2017)
-  CmdArgs.push_back("-sycl-std=2017");
-}
-  }
-
   if (IsOpenMPDevice) {
 // We have to pass the triple of the host if compiling for an OpenMP 
device.
 std::string NormalizedTriple =

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 76f63d065017..9cc41c9d96f8 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2535,24 +2535,6 @@ static void ParseLangArgs(LangOptions , ArgList 
, InputKind IK,
   LangStd = OpenCLLangStd;
   }
 
-  Opts.SYCL = Args.hasArg(options::OPT_fsycl);
-  Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
-  if (Opts.SYCL) {
-// -sycl-std applies to any SYCL source, not only those containing kernels,
-// but also those using the SYCL API
-if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
-  Opts.SYCLVersion = llvm::StringSwitch(A->getValue())
- .Cases("2017", "1.2.1", "121", "sycl-1.2.1", 2017)
- .Default(0U);
-
-  if (Opts.SYCLVersion == 0U) {
-// User has passed an invalid value to the flag, this is an error
-Diags.Report(diag::err_drv_invalid_value)
-<< A->getAsString(Args) << A->getValue();
-  }
-}
-  }
-
   Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
   Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins);

[clang] bd97704 - [SYCL] Driver option to select SYCL version

2020-02-27 Thread Alexey Bader via cfe-commits

Author: Ruyman
Date: 2020-02-27T15:08:42+03:00
New Revision: bd97704eb5a95ecb048ce343c1a4be5d94e5

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

LOG: [SYCL] Driver option to select SYCL version

Summary:
User can select the version of SYCL the compiler will
use via the flag -sycl-std, similar to -cl-std.

The flag defines the LangOpts.SYCLVersion option to the
version of SYCL. The default value is undefined.
If driver is building SYCL code, flag is set to the default SYCL
version (1.2.1)

The preprocessor uses this variable to define CL_SYCL_LANGUAGE_VERSION macro,
which should be defined according to SYCL 1.2.1 standard.

Only valid value at this point for the flag is 1.2.1.

Co-Authored-By: David Wood 
Signed-off-by: Ruyman Reyes 

Subscribers: ebevhan, Anastasia, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72857

Signed-off-by: Alexey Bader 

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Driver/sycl.c
clang/test/Frontend/sycl-aux-triple.cpp
clang/test/Preprocessor/sycl-macro.cpp
clang/test/SemaSYCL/kernel-attribute.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 3cc7c384ac10..53b87b737568 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -230,7 +230,9 @@ LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate 
relocatable device code")
 LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions 
for HIP")
 LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for 
kernel launch bounds for HIP")
 
+LANGOPT(SYCL  , 1, 0, "SYCL")
 LANGOPT(SYCLIsDevice  , 1, 0, "Generate code for SYCL device")
+LANGOPT(SYCLVersion   , 32, 0, "Version of the SYCL standard used")
 
 LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f1801e3e89e7..36626342e364 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3420,10 +3420,12 @@ defm underscoring : BooleanFFlag<"underscoring">, 
Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
 
 // C++ SYCL options
-def fsycl : Flag<["-"], "fsycl">, Group,
+def fsycl : Flag<["-"], "fsycl">, Group, Flags<[CC1Option, 
CoreOption]>,
   HelpText<"Enable SYCL kernels compilation for device">;
-def fno_sycl : Flag<["-"], "fno-sycl">, Group,
+def fno_sycl : Flag<["-"], "fno-sycl">, Group, Flags<[CoreOption]>,
   HelpText<"Disable SYCL kernels compilation for device">;
+def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
+  HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 
1.2.1, sycl-1.2.1">;
 
 include "CC1Options.td"
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index d387a1dc2079..87596dd19c5a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4040,9 +4040,18 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
   }
 
-  if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false))
+  if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false)) {
+CmdArgs.push_back("-fsycl");
 CmdArgs.push_back("-fsycl-is-device");
 
+if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
+  A->render(Args, CmdArgs);
+} else {
+  // Ensure the default version in SYCL mode is 1.2.1 (aka 2017)
+  CmdArgs.push_back("-sycl-std=2017");
+}
+  }
+
   if (IsOpenMPDevice) {
 // We have to pass the triple of the host if compiling for an OpenMP 
device.
 std::string NormalizedTriple =

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 9cc41c9d96f8..76f63d065017 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2535,6 +2535,24 @@ static void ParseLangArgs(LangOptions , ArgList 
, InputKind IK,
   LangStd = OpenCLLangStd;
   }
 
+  Opts.SYCL = Args.hasArg(options::OPT_fsycl);
+  Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
+  if (Opts.SYCL) {
+// -sycl-std applies to any SYCL source, not only those containing kernels,
+// but also those using the SYCL API
+if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
+  

[clang] 863d975 - [SYCL][Driver] Add clang driver option to enable SYCL compilation mode

2020-02-06 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2020-02-06T08:42:31+03:00
New Revision: 863d9752105f390b31b3d08d1980d2888c15b034

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

LOG: [SYCL][Driver] Add clang driver option to enable SYCL compilation mode

Summary:
As a first step this implementation enables compilation of the offload
code.

Reviewers: ABataev

Subscribers: ebevhan, Anastasia, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74048

Added: 
clang/test/Driver/sycl.c

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2c925d018da7..2dea0ac2ba5c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -124,6 +124,9 @@ def pedantic_Group : OptionGroup<"">, 
Group,
 def opencl_Group : OptionGroup<"">, Group,
DocName<"OpenCL flags">;
 
+def sycl_Group : OptionGroup<"">, Group,
+ DocName<"SYCL flags">;
+
 def m_Group : OptionGroup<"">, Group,
   DocName<"Target-dependent compilation options">;
 
@@ -3407,6 +3410,11 @@ defm stack_arrays : BooleanFFlag<"stack-arrays">, 
Group;
 defm underscoring : BooleanFFlag<"underscoring">, Group;
 defm whole_file : BooleanFFlag<"whole-file">, Group;
 
+// C++ SYCL options
+def fsycl : Flag<["-"], "fsycl">, Group,
+  HelpText<"Enable SYCL kernels compilation for device">;
+def fno_sycl : Flag<["-"], "fno-sycl">, Group,
+  HelpText<"Disable SYCL kernels compilation for device">;
 
 include "CC1Options.td"
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index ccdfbe8c604f..0bed933185f6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4023,6 +4023,9 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
   }
 
+  if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false))
+CmdArgs.push_back("-fsycl-is-device");
+
   if (IsOpenMPDevice) {
 // We have to pass the triple of the host if compiling for an OpenMP 
device.
 std::string NormalizedTriple =

diff  --git a/clang/test/Driver/sycl.c b/clang/test/Driver/sycl.c
new file mode 100644
index ..6c4b291f387b
--- /dev/null
+++ b/clang/test/Driver/sycl.c
@@ -0,0 +1,10 @@
+// RUN: %clang -### -fsycl -c %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -fno-sycl -fsycl %s 2>&1 | FileCheck %s 
--check-prefix=ENABLED
+// RUN: %clangxx -### -fsycl %s 2>&1 | FileCheck %s --check-prefix=ENABLED
+// RUN: %clangxx -### -fno-sycl %s 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %clangxx -### -fsycl -fno-sycl %s 2>&1 | FileCheck %s 
--check-prefix=DISABLED
+// RUN: %clangxx -### %s 2>&1 | FileCheck %s --check-prefix=DISABLED
+
+// ENABLED: "-cc1"{{.*}} "-fsycl-is-device"
+// DISABLED-NOT: "-fsycl-is-device"



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


[clang] dd18729 - [Attr][Doc][NFC] Fix code snippet formatting for attribute documentation

2020-01-21 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2020-01-21T18:30:56+03:00
New Revision: dd18729b2a7a23b76b8d74fbf4f4bb4efbe8aa97

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

LOG: [Attr][Doc][NFC] Fix code snippet formatting for attribute documentation

Reviewers: aaron.ballman, Fznamznon

Subscribers: ebevhan, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73104

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 456edd1daafc..8fd59a0c9b38 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -260,6 +260,7 @@ The ``sycl_kernel`` attribute specifies that a function 
template will be used
 to outline device code and to generate an OpenCL kernel.
 Here is a code example of the SYCL program, which demonstrates the compiler's
 outlining job:
+
 .. code-block:: c++
 
   int foo(int x) { return ++x; }
@@ -282,27 +283,29 @@ compilation of functions for the device part can be found 
in the SYCL 1.2.1
 specification Section 6.4.
 To show to the compiler entry point to the "device part" of the code, the SYCL
 runtime can use the ``sycl_kernel`` attribute in the following way:
+
 .. code-block:: c++
-namespace cl {
-namespace sycl {
-class handler {
-  template 
-  __attribute__((sycl_kernel)) void sycl_kernel_function(KernelType 
KernelFuncObj) {
-// ...
-KernelFuncObj();
-  }
 
-  template 
-  void parallel_for(range NumWorkItems, KernelType KernelFunc) {
-#ifdef __SYCL_DEVICE_ONLY__
-sycl_kernel_function(KernelFunc);
-#else
-// Host implementation
-#endif
-  }
-};
-} // namespace sycl
-} // namespace cl
+  namespace cl {
+  namespace sycl {
+  class handler {
+template 
+__attribute__((sycl_kernel)) void sycl_kernel_function(KernelType 
KernelFuncObj) {
+  // ...
+  KernelFuncObj();
+}
+
+template 
+void parallel_for(range NumWorkItems, KernelType KernelFunc) {
+  #ifdef __SYCL_DEVICE_ONLY__
+  sycl_kernel_function(KernelFunc);
+  #else
+  // Host implementation
+  #endif
+}
+  };
+  } // namespace sycl
+  } // namespace cl
 
 The compiler will also generate an OpenCL kernel using the function marked with
 the ``sycl_kernel`` attribute.



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


[clang] 128f39d - Fix crash in getFullyQualifiedName for inline namespace

2019-12-28 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2019-12-28T16:35:51+03:00
New Revision: 128f39da932be50cb49646084820119e6e0d1e22

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

LOG: Fix crash in getFullyQualifiedName for inline namespace

Summary: The ICE happens when the most outer namespace is an inline namespace.

Reviewers: bkramer, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ebevhan, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71962

Added: 


Modified: 
clang/lib/AST/QualTypeNames.cpp
clang/unittests/Tooling/QualTypeNamesTest.cpp

Removed: 




diff  --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp
index f28f00171cce..73a33a208233 100644
--- a/clang/lib/AST/QualTypeNames.cpp
+++ b/clang/lib/AST/QualTypeNames.cpp
@@ -192,7 +192,7 @@ static NestedNameSpecifier *createOuterNNS(const ASTContext 
, const Decl *D,
   // Ignore inline namespace;
   NS = dyn_cast(NS->getDeclContext());
 }
-if (NS->getDeclName()) {
+if (NS && NS->getDeclName()) {
   return createNestedNameSpecifier(Ctx, NS, WithGlobalNsPrefix);
 }
 return nullptr;  // no starting '::', no anonymous

diff  --git a/clang/unittests/Tooling/QualTypeNamesTest.cpp 
b/clang/unittests/Tooling/QualTypeNamesTest.cpp
index b6c302977876..ff6b78c2666d 100644
--- a/clang/unittests/Tooling/QualTypeNamesTest.cpp
+++ b/clang/unittests/Tooling/QualTypeNamesTest.cpp
@@ -223,6 +223,17 @@ TEST(QualTypeNameTest, getFullyQualifiedName) {
   "}\n"
   );
 
+  TypeNameVisitor InlineNamespace;
+  InlineNamespace.ExpectedQualTypeNames["c"] = "B::C";
+  InlineNamespace.runOver("inline namespace A {\n"
+  "  namespace B {\n"
+  "class C {};\n"
+  "  }\n"
+  "}\n"
+  "using namespace A::B;\n"
+  "C c;\n",
+  TypeNameVisitor::Lang_CXX11);
+
   TypeNameVisitor AnonStrucs;
   AnonStrucs.ExpectedQualTypeNames["a"] = "short";
   AnonStrucs.ExpectedQualTypeNames["un_in_st_1"] =



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


[clang] 2d6a5e4 - [OpenMP][Test] Add check for aux-triple predefined macros

2019-12-12 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2019-12-12T14:36:11+03:00
New Revision: 2d6a5e4fe45d0a1f1c94df6b3422ffb0d676fb6d

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

LOG: [OpenMP][Test] Add check for aux-triple predefined macros

Summary:
Make sure that auxiliary target specific macros are defined in OpenMP
mode.

Reviewers: ABataev, jdoerfert

Subscribers: guansong, ebevhan, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71413

Added: 
clang/test/OpenMP/aux-triple-macros.cpp

Modified: 


Removed: 




diff  --git a/clang/test/OpenMP/aux-triple-macros.cpp 
b/clang/test/OpenMP/aux-triple-macros.cpp
new file mode 100644
index ..73b74bd92f6d
--- /dev/null
+++ b/clang/test/OpenMP/aux-triple-macros.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -triple nvptx64 -aux-triple x86_64-unknown-linux-gnu -E 
-dM | FileCheck %s
+// RUN: %clang_cc1 %s -fopenmp -fopenmp-is-device -triple nvptx64 -aux-triple 
x86_64-unknown-linux-gnu -E -dM | FileCheck --check-prefix=CHECK-OMP-DEVICE %s
+
+// CHECK-NOT:#define __x86_64__ 1
+// CHECK-OMP-DEVICE:#define __x86_64__ 1



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


[clang] cb30ad7 - [SYCL] Add support for auxiliary triple specification to Frontend

2019-12-11 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2019-12-11T12:40:43+03:00
New Revision: cb30ad728f0b791c72a6a1399f36ebc60ad5

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

LOG: [SYCL] Add support for auxiliary triple specification to Frontend

Summary:
Add host predefined macros to compilation for SYCL device, which is
required for pre-processing host specific includes (e.g. system
headers).

Reviewers: ABataev, jdoerfert

Subscribers: ebevhan, Anastasia, cfe-commits, keryell, Naghasan, Fznamznon

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71286

Signed-off-by: Alexey Bader 

Added: 
clang/test/Frontend/sycl-aux-triple.cpp

Modified: 
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/InitPreprocessor.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index b69dc4f854ff..05ecc3f447cc 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -917,8 +917,9 @@ bool CompilerInstance::ExecuteAction(FrontendAction ) {
   if (!hasTarget())
 return false;
 
-  // Create TargetInfo for the other side of CUDA and OpenMP compilation.
-  if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice) &&
+  // Create TargetInfo for the other side of CUDA/OpenMP/SYCL compilation.
+  if ((getLangOpts().CUDA || getLangOpts().OpenMPIsDevice ||
+   getLangOpts().SYCLIsDevice) &&
   !getFrontendOpts().AuxTriple.empty()) {
 auto TO = std::make_shared();
 TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index c27c33c530f6..b1c7aed0d44e 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1124,7 +1124,8 @@ void clang::InitializePreprocessor(
   if (InitOpts.UsePredefines) {
 // FIXME: This will create multiple definitions for most of the predefined
 // macros. This is not the right way to handle this.
-if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice) && PP.getAuxTargetInfo())
+if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice || LangOpts.SYCLIsDevice) &&
+PP.getAuxTargetInfo())
   InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
  PP.getPreprocessorOpts(), Builder);
 

diff  --git a/clang/test/Frontend/sycl-aux-triple.cpp 
b/clang/test/Frontend/sycl-aux-triple.cpp
new file mode 100644
index ..38b6a24fb3ce
--- /dev/null
+++ b/clang/test/Frontend/sycl-aux-triple.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -triple spir -aux-triple x86_64-unknown-linux-gnu -E -dM 
| FileCheck %s
+// RUN: %clang_cc1 %s -fsycl-is-device -triple spir -aux-triple 
x86_64-unknown-linux-gnu -E -dM | FileCheck --check-prefix=CHECK-SYCL %s
+
+// CHECK-NOT:#define __x86_64__ 1
+// CHECK-SYCL:#define __x86_64__ 1



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


[clang] 11a9bae - [AST] Enable expression of OpenCL language address spaces an attribute

2019-12-05 Thread Alexey Bader via cfe-commits

Author: Victor Lomuller
Date: 2019-12-05T12:24:06+03:00
New Revision: 11a9bae8f66986751078501988b4414f24dbe37e

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

LOG: [AST] Enable expression of OpenCL language address spaces an attribute

Summary:
Enable a way to set OpenCL language address space using attributes
in addition to existing keywords.

Signed-off-by: Victor Lomuller vic...@codeplay.com

Reviewers: aaron.ballman, Anastasia

Subscribers: yaxunl, ebevhan, cfe-commits, Naghasan

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71005

Signed-off-by: Alexey Bader 

Added: 
clang/test/AST/language_address_space_attribute.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Sema/SemaType.cpp
clang/test/SemaOpenCL/address-spaces.cl

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4ea1c9f58beb..9ca4be0e07c8 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1120,27 +1120,27 @@ def OpenCLAccess : Attr {
 }
 
 def OpenCLPrivateAddressSpace : TypeAttr {
-  let Spellings = [Keyword<"__private">, Keyword<"private">];
+  let Spellings = [Keyword<"__private">, Keyword<"private">, 
Clang<"opencl_private">];
   let Documentation = [OpenCLAddressSpacePrivateDocs];
 }
 
 def OpenCLGlobalAddressSpace : TypeAttr {
-  let Spellings = [Keyword<"__global">, Keyword<"global">];
+  let Spellings = [Keyword<"__global">, Keyword<"global">, 
Clang<"opencl_global">];
   let Documentation = [OpenCLAddressSpaceGlobalDocs];
 }
 
 def OpenCLLocalAddressSpace : TypeAttr {
-  let Spellings = [Keyword<"__local">, Keyword<"local">];
+  let Spellings = [Keyword<"__local">, Keyword<"local">, 
Clang<"opencl_local">];
   let Documentation = [OpenCLAddressSpaceLocalDocs];
 }
 
 def OpenCLConstantAddressSpace : TypeAttr {
-  let Spellings = [Keyword<"__constant">, Keyword<"constant">];
+  let Spellings = [Keyword<"__constant">, Keyword<"constant">, 
Clang<"opencl_constant">];
   let Documentation = [OpenCLAddressSpaceConstantDocs];
 }
 
 def OpenCLGenericAddressSpace : TypeAttr {
-  let Spellings = [Keyword<"__generic">, Keyword<"generic">];
+  let Spellings = [Keyword<"__generic">, Keyword<"generic">, 
Clang<"opencl_generic">];
   let Documentation = [OpenCLAddressSpaceGenericDocs];
 }
 

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 52a0581643bc..1375ccbabc50 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -7407,6 +7407,16 @@ static void HandleLifetimeBoundAttr(TypeProcessingState 
,
   }
 }
 
+static bool isAddressSpaceKind(const ParsedAttr ) {
+  auto attrKind = attr.getKind();
+
+  return attrKind == ParsedAttr::AT_AddressSpace ||
+ attrKind == ParsedAttr::AT_OpenCLPrivateAddressSpace ||
+ attrKind == ParsedAttr::AT_OpenCLGlobalAddressSpace ||
+ attrKind == ParsedAttr::AT_OpenCLLocalAddressSpace ||
+ attrKind == ParsedAttr::AT_OpenCLConstantAddressSpace ||
+ attrKind == ParsedAttr::AT_OpenCLGenericAddressSpace;
+}
 
 static void processTypeAttrs(TypeProcessingState , QualType ,
  TypeAttrLocation TAL,
@@ -7445,11 +7455,11 @@ static void processTypeAttrs(TypeProcessingState 
, QualType ,
   if (!IsTypeAttr)
 continue;
 }
-  } else if (TAL != TAL_DeclChunk &&
- attr.getKind() != ParsedAttr::AT_AddressSpace) {
+  } else if (TAL != TAL_DeclChunk && !isAddressSpaceKind(attr)) {
 // Otherwise, only consider type processing for a C++11 attribute if
 // it's actually been applied to a type.
-// We also allow C++11 address_space attributes to pass through.
+// We also allow C++11 address_space and
+// OpenCL language address space attributes to pass through.
 continue;
   }
 }

diff  --git a/clang/test/AST/language_address_space_attribute.cpp 
b/clang/test/AST/language_address_space_attribute.cpp
new file mode 100644
index ..7c6bdca06c06
--- /dev/null
+++ b/clang/test/AST/language_address_space_attribute.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+
+// Verify that the language address space attribute is
+// understood correctly by clang.
+
+void langas() {
+  // CHECK: VarDecl {{.*}} x_global '__global int *'
+  __attribute__((opencl_global)) int *x_global;
+
+  // CHECK: VarDecl {{.*}} z_global '__global int *'
+  [[clang::opencl_global]] int *z_global;
+
+  // CHECK: VarDecl {{.*}} x_local '__local int *'
+  __attribute__((opencl_local)) int *x_local;
+
+  // CHECK: VarDecl {{.*}} z_local '__local int *'
+  [[clang::opencl_local]] int *z_local;
+
+  // CHECK: VarDecl {{.*}} x_constant '__constant int *'
+  

[clang] c094e7d - [SYCL] Add sycl_kernel attribute for accelerated code outlining

2019-12-03 Thread Alexey Bader via cfe-commits

Author: Mariya Podchishchaeva
Date: 2019-12-03T16:13:22+03:00
New Revision: c094e7dc4b3f9d1c1e590b008bb1cc46e3496abd

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

LOG: [SYCL] Add sycl_kernel attribute for accelerated code outlining

SYCL is single source offload programming model relying on compiler to
separate device code (i.e. offloaded to an accelerator) from the code
executed on the host.

Here is code example of the SYCL program to demonstrate compiler
outlining work:

```
int foo(int x) { return ++x; }
int bar(int x) { throw std::exception("CPU code only!"); }
...
using namespace cl::sycl;
queue Q;
buffer a(range<1>{1024});
Q.submit([&](handler& cgh) {
  auto A = a.get_access(cgh);
  cgh.parallel_for(range<1>{1024}, [=](id<1> index) {
A[index] = index[0] + foo(42);
  });
}
...
```

SYCL device compiler must compile lambda expression passed to
cl::sycl::handler::parallel_for method and function foo called from this
lambda expression for an "accelerator". SYCL device compiler also must
ignore bar function as it's not required for offloaded code execution.

This patch adds the sycl_kernel attribute, which is used to mark code
passed to cl::sycl::handler::parallel_for as "accelerated code".

Attribute must be applied to function templates which parameters include
at least "kernel name" and "kernel function object". These parameters
will be used to establish an ABI between the host application and
offloaded part.

Reviewers: jlebar, keryell, Naghasan, ABataev, Anastasia, bader, aaron.ballman, 
rjmccall, rsmith

Reviewed By: keryell, bader

Subscribers: mgorny, OlegM, ArturGainullin, agozillon, aaron.ballman, ebevhan, 
Anastasia, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60455

Signed-off-by: Alexey Bader 

Added: 
clang/test/SemaSYCL/kernel-attribute-on-non-sycl.cpp
clang/test/SemaSYCL/kernel-attribute.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 21cf53f0a815..4ea1c9f58beb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -121,6 +121,11 @@ def GlobalVar : SubsetSubjectisInlineSpecified()}], "inline functions">;
 
+def FunctionTmpl
+: SubsetSubjectgetTemplatedKind() ==
+ FunctionDecl::TK_FunctionTemplate}],
+"function templates">;
+
 // FIXME: this hack is needed because DeclNodes.td defines the base Decl node
 // type to be a class, not a definition. This makes it impossible to create an
 // attribute subject which accepts a Decl. Normally, this is not a problem,
@@ -296,6 +301,7 @@ def MicrosoftExt : LangOpt<"MicrosoftExt">;
 def Borland : LangOpt<"Borland">;
 def CUDA : LangOpt<"CUDA">;
 def HIP : LangOpt<"HIP">;
+def SYCL : LangOpt<"SYCLIsDevice">;
 def COnly : LangOpt<"COnly", "!LangOpts.CPlusPlus">;
 def CPlusPlus : LangOpt<"CPlusPlus">;
 def OpenCL : LangOpt<"OpenCL">;
@@ -1056,6 +1062,13 @@ def CUDAShared : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
+def SYCLKernel : InheritableAttr {
+  let Spellings = [Clang<"sycl_kernel">];
+  let Subjects = SubjectList<[FunctionTmpl]>;
+  let LangOpts = [SYCL];
+  let Documentation = [SYCLKernelDocs];
+}
+
 def C11NoReturn : InheritableAttr {
   let Spellings = [Keyword<"_Noreturn">];
   let Subjects = SubjectList<[Function], ErrorDiag>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f35199f81c3e..d47315a3f518 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -253,6 +253,79 @@ any option of a multiversioned function is undefined.
   }];
 }
 
+def SYCLKernelDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``sycl_kernel`` attribute specifies that a function template will be used
+to outline device code and to generate an OpenCL kernel.
+Here is a code example of the SYCL program, which demonstrates the compiler's
+outlining job:
+.. code-block:: c++
+
+  int foo(int x) { return ++x; }
+
+  using namespace cl::sycl;
+  queue Q;
+  buffer a(range<1>{1024});
+  Q.submit([&](handler& cgh) {
+auto A = a.get_access(cgh);
+cgh.parallel_for(range<1>{1024}, [=](id<1> index) {
+  A[index] = index[0] + foo(42);
+});
+  }
+
+A C++ function object passed to the ``parallel_for`` is called a "SYCL kernel".
+A SYCL kernel defines the entry point to the "device part" of the code. The
+compiler will emit all symbols accessible from a "kernel". In this code
+example, the compiler will emit "foo" function.  

r354773 - [SYCL] Add clang front-end option to enable SYCL device compilation flow.

2019-02-25 Thread Alexey Bader via cfe-commits
Author: bader
Date: Mon Feb 25 03:48:48 2019
New Revision: 354773

URL: http://llvm.org/viewvc/llvm-project?rev=354773=rev
Log:
[SYCL] Add clang front-end option to enable SYCL device compilation flow.

Patch by Mariya Podchishchaeva 

Added:
cfe/trunk/test/Preprocessor/sycl-macro.cpp   (with props)
Modified:
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=354773=354772=354773=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Mon Feb 25 03:48:48 2019
@@ -217,6 +217,8 @@ LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "
 LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate 
transcendental functions")
 LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
 
+LANGOPT(SYCLIsDevice  , 1, 0, "Generate code for SYCL device")
+
 LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are 
unavailable")

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=354773=354772=354773=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Feb 25 03:48:48 2019
@@ -836,8 +836,14 @@ def fopenmp_is_device : Flag<["-"], "fop
 def fopenmp_host_ir_file_path : Separate<["-"], "fopenmp-host-ir-file-path">,
   HelpText<"Path to the IR file produced by the frontend for the host.">;
 
-} // let Flags = [CC1Option]
+//===--===//
+// SYCL Options
+//===--===//
 
+def fsycl_is_device : Flag<["-"], "fsycl-is-device">,
+  HelpText<"Generate code for SYCL device.">;
+
+} // let Flags = [CC1Option]
 
 
//===--===//
 // cc1as-only Options

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=354773=354772=354773=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Feb 25 03:48:48 2019
@@ -2879,6 +2879,8 @@ static void ParseLangArgs(LangOptions 
   << Opts.OMPHostIRFile;
   }
 
+  Opts.SYCLIsDevice = Args.hasArg(options::OPT_fsycl_is_device);
+
   // Set CUDA mode for OpenMP target NVPTX if specified in options
   Opts.OpenMPCUDAMode = Opts.OpenMPIsDevice && T.isNVPTX() &&
 Args.hasArg(options::OPT_fopenmp_cuda_mode);

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=354773=354772=354773=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Mon Feb 25 03:48:48 2019
@@ -1057,6 +1057,12 @@ static void InitializePredefinedMacros(c
 Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__");
   }
 
+  // Define a macro indicating that the source file is being compiled with a
+  // SYCL device compiler which doesn't produce host binary.
+  if (LangOpts.SYCLIsDevice) {
+Builder.defineMacro("__SYCL_DEVICE_ONLY__", "1");
+  }
+
   // OpenCL definitions.
   if (LangOpts.OpenCL) {
 #define OPENCLEXT(Ext) 
\

Added: cfe/trunk/test/Preprocessor/sycl-macro.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/sycl-macro.cpp?rev=354773=auto
==
--- cfe/trunk/test/Preprocessor/sycl-macro.cpp (added)
+++ cfe/trunk/test/Preprocessor/sycl-macro.cpp Mon Feb 25 03:48:48 2019
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -E -dM | FileCheck %s
+// RUN: %clang_cc1 %s -fsycl-is-device -E -dM | FileCheck 
--check-prefix=CHECK-SYCL %s
+
+// CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
+// CHECK-SYCL:#define __SYCL_DEVICE_ONLY__ 1

Propchange: cfe/trunk/test/Preprocessor/sycl-macro.cpp
--
svn:eol-style = native

Propchange: cfe/trunk/test/Preprocessor/sycl-macro.cpp

r354337 - [OpenCL] Change type of block pointer for OpenCL

2019-02-19 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Feb 19 07:19:06 2019
New Revision: 354337

URL: http://llvm.org/viewvc/llvm-project?rev=354337=rev
Log:
[OpenCL] Change type of block pointer for OpenCL

Summary:

For some reason OpenCL blocks in LLVM IR are represented as function pointers.
These pointers do not point to any real function and never get called. Actually
they point to some structure, which in turn contains pointer to the real block
invoke function.
This patch changes represntation of OpenCL blocks in LLVM IR from function
pointers to pointers to `%struct.__block_literal_generic`.
Such representation allows to avoid unnecessary bitcasts and simplifies
further processing (e.g. translation to SPIR-V ) of the module for targets
which do not support function pointers.

Patch by: Alexey Sotkin.

Reviewers: Anastasia, yaxunl, svenvh

Reviewed By: Anastasia

Subscribers: alexbatashev, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58277

Modified:
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/test/CodeGenOpenCL/blocks.cl
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=354337=354336=354337=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Tue Feb 19 07:19:06 2019
@@ -635,7 +635,9 @@ llvm::Type *CodeGenTypes::ConvertType(Qu
 
   case Type::BlockPointer: {
 const QualType FTy = cast(Ty)->getPointeeType();
-llvm::Type *PointeeType = ConvertTypeForMem(FTy);
+llvm::Type *PointeeType = CGM.getLangOpts().OpenCL
+  ? CGM.getGenericBlockLiteralType()
+  : ConvertTypeForMem(FTy);
 unsigned AS = Context.getTargetAddressSpace(FTy);
 ResultType = llvm::PointerType::get(PointeeType, AS);
 break;

Modified: cfe/trunk/test/CodeGenOpenCL/blocks.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/blocks.cl?rev=354337=354336=354337=diff
==
--- cfe/trunk/test/CodeGenOpenCL/blocks.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/blocks.cl Tue Feb 19 07:19:06 2019
@@ -35,11 +35,10 @@ void foo(){
   // SPIR: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8 
addrspace(4)*, i32 }>, <{ i32, i32, i8 addrspace(4)*, i32 }>* %[[block]], i32 
0, i32 3
   // SPIR: %[[i_value:.*]] = load i32, i32* %i
   // SPIR: store i32 %[[i_value]], i32* %[[block_captured]],
-  // SPIR: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 }>* 
%[[block]] to i32 ()*
-  // SPIR: %[[blk_gen_ptr:.*]] = addrspacecast i32 ()* %[[blk_ptr]] to i32 () 
addrspace(4)*
-  // SPIR: store i32 () addrspace(4)* %[[blk_gen_ptr]], i32 () addrspace(4)** 
%[[block_B:.*]],
-  // SPIR: %[[blk_gen_ptr:.*]] = load i32 () addrspace(4)*, i32 () 
addrspace(4)** %[[block_B]]
-  // SPIR: %[[block_literal:.*]] = bitcast i32 () addrspace(4)* 
%[[blk_gen_ptr]] to %struct.__opencl_block_literal_generic addrspace(4)*
+  // SPIR: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 }>* 
%[[block]] to %struct.__opencl_block_literal_generic*
+  // SPIR: %[[blk_gen_ptr:.*]] = addrspacecast 
%struct.__opencl_block_literal_generic* %[[blk_ptr]] to 
%struct.__opencl_block_literal_generic addrspace(4)*
+  // SPIR: store %struct.__opencl_block_literal_generic addrspace(4)* 
%[[blk_gen_ptr]], %struct.__opencl_block_literal_generic addrspace(4)** 
%[[block_B:.*]],
+  // SPIR: %[[block_literal:.*]] = load %struct.__opencl_block_literal_generic 
addrspace(4)*, %struct.__opencl_block_literal_generic addrspace(4)** 
%[[block_B]]
   // SPIR: %[[invoke_addr:.*]] = getelementptr inbounds 
%struct.__opencl_block_literal_generic, %struct.__opencl_block_literal_generic 
addrspace(4)* %[[block_literal]], i32 0, i32 2
   // SPIR: %[[blk_gen_ptr:.*]] = bitcast 
%struct.__opencl_block_literal_generic addrspace(4)* %[[block_literal]] to i8 
addrspace(4)*
   // SPIR: %[[invoke_func_ptr:.*]] = load i8 addrspace(4)*, i8 addrspace(4)* 
addrspace(4)* %[[invoke_addr]]
@@ -50,11 +49,10 @@ void foo(){
   // AMDGCN: %[[block_captured:.*]] = getelementptr inbounds <{ i32, i32, i8*, 
i32 }>, <{ i32, i32, i8*, i32 }> addrspace(5)* %[[block]], i32 0, i32 3
   // AMDGCN: %[[i_value:.*]] = load i32, i32 addrspace(5)* %i
   // AMDGCN: store i32 %[[i_value]], i32 addrspace(5)* %[[block_captured]],
-  // AMDGCN: %[[blk_ptr:.*]] = bitcast <{ i32, i32, i8*, i32 }> addrspace(5)* 
%[[block]] to i32 () addrspace(5)*
-  // AMDGCN: %[[blk_gen_ptr:.*]] = addrspacecast i32 () addrspace(5)* 
%[[blk_ptr]] to i32 ()*
-  // AMDGCN: store i32 ()* %[[blk_gen_ptr]], i32 ()* addrspace(5)* 
%[[block_B:.*]],
-  // AMDGCN: %[[blk_gen_ptr:.*]] = load i32 ()*, i32 ()* addrspace(5)* 
%[[block_B]]
-  // AMDGCN: %[[block_literal:.*]] = bitcast i32 

r335103 - [Sema] Allow creating types with multiple of the same addrspace.

2018-06-20 Thread Alexey Bader via cfe-commits
Author: bader
Date: Wed Jun 20 01:31:24 2018
New Revision: 335103

URL: http://llvm.org/viewvc/llvm-project?rev=335103=rev
Log:
[Sema] Allow creating types with multiple of the same addrspace.

Summary:
The comment with the OpenCL clause about this clearly
says: "No type shall be qualified by qualifiers for
two or more different address spaces."

This must mean that two or more qualifiers for the
_same_ address space is allowed. However, it is
likely unintended by the programmer, so emit a
warning.

For dependent address space types, reject them like
before since we cannot know what the address space
will be.

Patch by Bevin Hansson (ebevhan).

Reviewers: Anastasia

Reviewed By: Anastasia

Subscribers: bader, cfe-commits

Differential Revision: https://reviews.llvm.org/D47630

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Sema/address_spaces.c
cfe/trunk/test/SemaOpenCL/address-spaces.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=335103=335102=335103=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jun 20 01:31:24 
2018
@@ -2576,6 +2576,9 @@ def err_attribute_address_space_too_high
   "address space is larger than the maximum supported (%0)">;
 def err_attribute_address_multiple_qualifiers : Error<
   "multiple address spaces specified for type">;
+def warn_attribute_address_multiple_identical_qualifiers : Warning<
+  "multiple identical address spaces specified for type">,
+  InGroup;
 def err_attribute_address_function_type : Error<
   "function type may not be qualified with an address space">;
 def err_as_qualified_auto_decl : Error<

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=335103=335102=335103=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Jun 20 01:31:24 2018
@@ -5758,14 +5758,6 @@ QualType Sema::BuildAddressSpaceAttr(Qua
  SourceLocation AttrLoc) {
   if (!AddrSpace->isValueDependent()) { 
 
-// If this type is already address space qualified, reject it.
-// ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "No type shall be qualified
-// by qualifiers for two or more different address spaces."
-if (T.getAddressSpace() != LangAS::Default) {
-  Diag(AttrLoc, diag::err_attribute_address_multiple_qualifiers);
-  return QualType();
-}
-
 llvm::APSInt addrSpace(32);
 if (!AddrSpace->isIntegerConstantExpr(addrSpace, Context)) {
   Diag(AttrLoc, diag::err_attribute_argument_type)
@@ -5796,6 +5788,20 @@ QualType Sema::BuildAddressSpaceAttr(Qua
 LangAS ASIdx =
 getLangASFromTargetAS(static_cast(addrSpace.getZExtValue()));
 
+// If this type is already address space qualified with a different
+// address space, reject it.
+// ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "No type shall be qualified
+// by qualifiers for two or more different address spaces."
+if (T.getAddressSpace() != LangAS::Default) {
+  if (T.getAddressSpace() != ASIdx) {
+Diag(AttrLoc, diag::err_attribute_address_multiple_qualifiers);
+return QualType();
+  } else
+// Emit a warning if they are identical; it's likely unintended.
+Diag(AttrLoc,
+ diag::warn_attribute_address_multiple_identical_qualifiers);
+}
+
 return Context.getAddrSpaceQualType(T, ASIdx);
   }
 
@@ -5817,15 +5823,6 @@ QualType Sema::BuildAddressSpaceAttr(Qua
 /// space for the type.
 static void HandleAddressSpaceTypeAttribute(QualType ,
 const AttributeList , Sema 
){
-  // If this type is already address space qualified, reject it.
-  // ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "No type shall be qualified by
-  // qualifiers for two or more different address spaces."
-  if (Type.getAddressSpace() != LangAS::Default) {
-S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers);
-Attr.setInvalid();
-return;
-  }
-
   // ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "A function type shall not be
   // qualified by an address-space qualifier."
   if (Type->isFunctionType()) {
@@ -5888,6 +5885,21 @@ static void HandleAddressSpaceTypeAttrib
   llvm_unreachable("Invalid address space");
 }
 
+// If this type is already address space qualified with a different
+// address space, reject it.
+// ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "No type shall be qualified 
by
+// qualifiers for two or more different address spaces."
+if (Type.getAddressSpace() != 

r323522 - [OpenCL] Add "cles_khr_int64" extension.

2018-01-26 Thread Alexey Bader via cfe-commits
Author: bader
Date: Fri Jan 26 03:48:46 2018
New Revision: 323522

URL: http://llvm.org/viewvc/llvm-project?rev=323522=rev
Log:
[OpenCL] Add "cles_khr_int64" extension.

Summary:
For OpenCL 1.1 embedded profile 64 bit integers i.e. long,
ulong including the appropriate vector data types and operations
on 64-bit integers are optional. The "cles_khr_int64" extension
string will be reported if the embedded profile implementation
supports 64-bit integers.

Reviewers: Anastasia, bader

Reviewed By: Anastasia, bader

Subscribers: bader, yaxunl, Anastasia, cfe-commits

Differential Revision: https://reviews.llvm.org/D42532

Modified:
cfe/trunk/include/clang/Basic/OpenCLExtensions.def
cfe/trunk/test/SemaOpenCL/extension-version.cl

Modified: cfe/trunk/include/clang/Basic/OpenCLExtensions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenCLExtensions.def?rev=323522=323521=323522=diff
==
--- cfe/trunk/include/clang/Basic/OpenCLExtensions.def (original)
+++ cfe/trunk/include/clang/Basic/OpenCLExtensions.def Fri Jan 26 03:48:46 2018
@@ -53,6 +53,9 @@ OPENCLEXT_INTERNAL(cl_khr_icd, 100, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_gl_event, 110, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_d3d10_sharing, 110, ~0U)
 
+// EMBEDDED_PROFILE
+OPENCLEXT_INTERNAL(cles_khr_int64, 110, ~0U)
+
 // OpenCL 1.2.
 OPENCLEXT_INTERNAL(cl_khr_context_abort, 120, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_d3d11_sharing, 120, ~0U)

Modified: cfe/trunk/test/SemaOpenCL/extension-version.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extension-version.cl?rev=323522=323521=323522=diff
==
--- cfe/trunk/test/SemaOpenCL/extension-version.cl (original)
+++ cfe/trunk/test/SemaOpenCL/extension-version.cl Fri Jan 26 03:48:46 2018
@@ -131,6 +131,15 @@
 #endif
 #pragma OPENCL EXTENSION cl_khr_d3d10_sharing: enable
 
+#if (__OPENCL_C_VERSION__ >= 110)
+#ifndef cles_khr_int64
+#error "Missing cles_khr_int64 define"
+#endif
+#else
+// expected-warning@+2{{unsupported OpenCL extension 'cles_khr_int64' - 
ignoring}}
+#endif
+#pragma OPENCL EXTENSION cles_khr_int64: enable
+
 #if (__OPENCL_C_VERSION__ >= 120)
 #ifndef cl_khr_context_abort
 #error "Missing cl_context_abort define"


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


r318290 - [OpenCL] Fix code generation of function-scope constant samplers.

2017-11-15 Thread Alexey Bader via cfe-commits
Author: bader
Date: Wed Nov 15 03:38:17 2017
New Revision: 318290

URL: http://llvm.org/viewvc/llvm-project?rev=318290=rev
Log:
[OpenCL] Fix code generation of function-scope constant samplers.

Summary:
Constant samplers are handled as static variables and clang's code generation
library, which leads to llvm::unreachable. We bypass emitting sampler variable
as static since it's translated to a function call later.

Reviewers: yaxunl, Anastasia

Reviewed By: yaxunl, Anastasia

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D34342

Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenOpenCL/sampler.cl
cfe/trunk/test/SemaOpenCL/sampler_t.cl

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=318290=318289=318290=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed Nov 15 03:38:17 2017
@@ -162,6 +162,10 @@ void CodeGenFunction::EmitVarDecl(const
   // needs to be emitted like a static variable, e.g. a function-scope
   // variable in constant address space in OpenCL.
   if (D.getStorageDuration() != SD_Automatic) {
+// Static sampler variables translated to function calls.
+if (D.getType()->isSamplerT())
+  return;
+
 llvm::GlobalValue::LinkageTypes Linkage =
 CGM.getLLVMLinkageVarDefinition(, /*isConstant=*/false);
 

Modified: cfe/trunk/test/CodeGenOpenCL/sampler.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/sampler.cl?rev=318290=318289=318290=diff
==
--- cfe/trunk/test/CodeGenOpenCL/sampler.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/sampler.cl Wed Nov 15 03:38:17 2017
@@ -20,6 +20,8 @@
 constant sampler_t glb_smp = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
 // CHECK-NOT: glb_smp
 
+int get_sampler_initializer(void);
+
 void fnc4smp(sampler_t s) {}
 // CHECK: define spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* %
 
@@ -58,4 +60,20 @@ kernel void foo(sampler_t smp_par) {
   fnc4smp(5);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 5)
   // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
+
+  const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
+  fnc4smp(const_smp);
+   // CHECK: [[CONST_SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)
+  // CHECK: store %opencl.sampler_t addrspace(2)* [[CONST_SAMP]], 
%opencl.sampler_t addrspace(2)** [[CONST_SMP_PTR:%[a-zA-Z0-9]+]]
+  fnc4smp(const_smp);
+  // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, 
%opencl.sampler_t addrspace(2)** [[CONST_SMP_PTR]]
+  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
+
+  constant sampler_t constant_smp = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
+  fnc4smp(constant_smp);
+  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)
+  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
+
+  // TODO: enable sampler initialization with non-constant integer.
+  //const sampler_t const_smp_func_init = get_sampler_initializer();
 }

Modified: cfe/trunk/test/SemaOpenCL/sampler_t.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/sampler_t.cl?rev=318290=318289=318290=diff
==
--- cfe/trunk/test/SemaOpenCL/sampler_t.cl (original)
+++ cfe/trunk/test/SemaOpenCL/sampler_t.cl Wed Nov 15 03:38:17 2017
@@ -46,36 +46,11 @@ const constant sampler_t glb_smp11 = CLK
 
 void kernel ker(sampler_t argsmp) {
   local sampler_t smp; // expected-error{{sampler type cannot be used with the 
__local and __global address space qualifiers}}
-  const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
-  const sampler_t const_smp2;
-  const sampler_t const_smp3 = const_smp;
-  const sampler_t const_smp4 = f();
   const sampler_t const_smp5 = 1.0f; // expected-error{{initializing 'const 
sampler_t' with an expression of incompatible type 'float'}}
   const sampler_t const_smp6 = 0x1LL; // expected-error{{sampler_t 
initialization requires 32-bit integer, not 'long long'}}
 
-  foo(glb_smp);
-  foo(glb_smp2);
-  foo(glb_smp3);
-  foo(glb_smp4);
-  foo(glb_smp5);
-  foo(glb_smp6);
-  foo(glb_smp7);
-  foo(glb_smp8);
-  foo(glb_smp9);
-  foo(smp);
-  foo(sampler_str.smp);
-  foo(const_smp);
-  foo(const_smp2);
-  foo(const_smp3);
-  foo(const_smp4);
-  foo(const_smp5);
-  foo(const_smp6);
-  foo(argsmp);
-  foo(5);
   foo(5.0f); // expected-error {{passing 

r315453 - [OpenCL] Allow function declaration with empty argument list.

2017-10-11 Thread Alexey Bader via cfe-commits
Author: bader
Date: Wed Oct 11 04:16:31 2017
New Revision: 315453

URL: http://llvm.org/viewvc/llvm-project?rev=315453=rev
Log:
[OpenCL] Allow function declaration with empty argument list.

Treat 'f()' as 'f(void)' rather than a function w/o a prototype.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia, yaxunl

Subscribers: cfe-commits, echuraev, chapuni

Differential Revision: https://reviews.llvm.org/D33681

Re-apply revision 306653.


Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/func.cl
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=315453=315452=315453=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Oct 11 04:16:31 2017
@@ -5989,7 +5989,8 @@ void Parser::ParseFunctionDeclarator(Dec
 else if (RequiresArg)
   Diag(Tok, diag::err_argument_required_after_attribute);
 
-HasProto = ParamInfo.size() || getLangOpts().CPlusPlus;
+HasProto = ParamInfo.size() || getLangOpts().CPlusPlus
+|| getLangOpts().OpenCL;
 
 // If we have the closing ')', eat it.
 Tracker.consumeClose();

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=315453=315452=315453=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Oct 11 04:16:31 2017
@@ -4460,7 +4460,8 @@ static TypeSourceInfo *GetFullTypeForDec
 
   FunctionType::ExtInfo EI(getCCForDeclaratorChunk(S, D, FTI, chunkIndex));
 
-  if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus) {
+  if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus
+&& !LangOpts.OpenCL) {
 // Simple void foo(), where the incoming T is the result type.
 T = Context.getFunctionNoProtoType(T, EI);
   } else {

Modified: cfe/trunk/test/SemaOpenCL/func.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/func.cl?rev=315453=315452=315453=diff
==
--- cfe/trunk/test/SemaOpenCL/func.cl (original)
+++ cfe/trunk/test/SemaOpenCL/func.cl Wed Oct 11 04:16:31 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -triple 
spir-unknown-unknown
 
 // Variadic functions
 void vararg_f(int, ...);// expected-error {{invalid 
prototype, variadic arguments are not allowed in OpenCL}}
@@ -16,6 +16,9 @@ typedef struct s
 //Function pointer
 void foo(void*);
 
+// Expect no diagnostics for an empty parameter list.
+void bar();
+
 void bar()
 {
   // declaring a function pointer is an error

Modified: cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl?rev=315453=315452=315453=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl Wed Oct 11 04:16:31 2017
@@ -3,7 +3,7 @@
 global pipe int gp;// expected-error {{type '__global read_only 
pipe int' can only be used as a function parameter in OpenCL}}
 global reserve_id_t rid;  // expected-error {{the '__global 
reserve_id_t' type cannot be used to declare a program scope variable}}
 
-extern pipe write_only int get_pipe(); // expected-error {{type '__global 
write_only pipe int ()' can only be used as a function parameter in OpenCL}}
+extern pipe write_only int get_pipe(); // expected-error {{type '__global 
write_only pipe int (void)' can only be used as a function parameter in OpenCL}}
 
 kernel void test_invalid_reserved_id(reserve_id_t ID) { // expected-error 
{{'reserve_id_t' cannot be used as the type of a kernel parameter}}
 }


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


r306653 - [OpenCL] Allow function declaration with empty argument list.

2017-06-29 Thread Alexey Bader via cfe-commits
Author: bader
Date: Thu Jun 29 01:44:10 2017
New Revision: 306653

URL: http://llvm.org/viewvc/llvm-project?rev=306653=rev
Log:
[OpenCL] Allow function declaration with empty argument list.

Summary:
does it make sense to enable K function declaration style for OpenCL?
clang throws following error message for the declaration w/o arguments:

```
int my_func();
error: function with no prototype cannot use the spir_function calling 
convention
```

Current way to fix this issue is to specify that parameter list is empty by 
using 'void':

```
int my_func(void);
```

Let me know what do you think about this patch.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: cfe-commits, echuraev

Differential Revision: https://reviews.llvm.org/D33681

Added:
cfe/trunk/test/SemaOpenCL/function-no-args.cl
Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=306653=306652=306653=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Jun 29 01:44:10 2017
@@ -4355,7 +4355,7 @@ static TypeSourceInfo *GetFullTypeForDec
 
   FunctionType::ExtInfo EI(getCCForDeclaratorChunk(S, D, FTI, chunkIndex));
 
-  if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus) {
+  if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus  && 
!LangOpts.OpenCL) {
 // Simple void foo(), where the incoming T is the result type.
 T = Context.getFunctionNoProtoType(T, EI);
   } else {

Added: cfe/trunk/test/SemaOpenCL/function-no-args.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/function-no-args.cl?rev=306653=auto
==
--- cfe/trunk/test/SemaOpenCL/function-no-args.cl (added)
+++ cfe/trunk/test/SemaOpenCL/function-no-args.cl Thu Jun 29 01:44:10 2017
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+// expected-no-diagnostics
+
+global int gi;
+int my_func();
+int my_func() {
+  gi = 2;
+  return gi;
+}

Modified: cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl?rev=306653=306652=306653=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl Thu Jun 29 01:44:10 2017
@@ -3,7 +3,7 @@
 global pipe int gp;// expected-error {{type '__global read_only 
pipe int' can only be used as a function parameter in OpenCL}}
 global reserve_id_t rid;  // expected-error {{the '__global 
reserve_id_t' type cannot be used to declare a program scope variable}}
 
-extern pipe write_only int get_pipe(); // expected-error {{type '__global 
write_only pipe int ()' can only be used as a function parameter in OpenCL}}
+extern pipe write_only int get_pipe(); // expected-error {{type '__global 
write_only pipe int (void)' can only be used as a function parameter in OpenCL}}
 
 kernel void test_invalid_reserved_id(reserve_id_t ID) { // expected-error 
{{'reserve_id_t' cannot be used as the type of a kernel parameter}}
 }


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


r305796 - [OpenCL] Fix OpenCL and SPIR version metadata generation.

2017-06-20 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Jun 20 09:30:18 2017
New Revision: 305796

URL: http://llvm.org/viewvc/llvm-project?rev=305796=rev
Log:
[OpenCL] Fix OpenCL and SPIR version metadata generation.

Summary: OpenCL and SPIR version metadata must be generated once per module 
instead of once per mangled global value.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: ahatanak, cfe-commits

Differential Revision: https://reviews.llvm.org/D34235

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGenOpenCL/spir_version.cl

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=305796=305795=305796=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jun 20 09:30:18 2017
@@ -506,6 +506,26 @@ void CodeGenModule::Release() {
   LangOpts.CUDADeviceFlushDenormalsToZero ? 1 : 0);
   }
 
+  // Emit OpenCL specific module metadata: OpenCL/SPIR version.
+  if (LangOpts.OpenCL) {
+EmitOpenCLMetadata();
+// Emit SPIR version.
+if (getTriple().getArch() == llvm::Triple::spir ||
+getTriple().getArch() == llvm::Triple::spir64) {
+  // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
+  // opencl.spir.version named metadata.
+  llvm::Metadata *SPIRVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, LangOpts.OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (LangOpts.OpenCLVersion / 100 > 1) ? 0 : 2))};
+  llvm::NamedMDNode *SPIRVerMD =
+  TheModule.getOrInsertNamedMetadata("opencl.spir.version");
+  llvm::LLVMContext  = TheModule.getContext();
+  SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));
+}
+  }
+
   if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
 assert(PLevel < 3 && "Invalid PIC Level");
 getModule().setPICLevel(static_cast(PLevel));
@@ -529,6 +549,20 @@ void CodeGenModule::Release() {
   EmitTargetMetadata();
 }
 
+void CodeGenModule::EmitOpenCLMetadata() {
+  // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
+  // opencl.ocl.version named metadata node.
+  llvm::Metadata *OCLVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, LangOpts.OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (LangOpts.OpenCLVersion % 100) / 10))};
+  llvm::NamedMDNode *OCLVerMD =
+  TheModule.getOrInsertNamedMetadata("opencl.ocl.version");
+  llvm::LLVMContext  = TheModule.getContext();
+  OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+}
+
 void CodeGenModule::UpdateCompletedType(const TagDecl *TD) {
   // Make sure that this type is translated.
   Types.UpdateCompletedType(TD);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=305796=305795=305796=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue Jun 20 09:30:18 2017
@@ -1321,6 +1321,9 @@ private:
   /// Emits target specific Metadata for global declarations.
   void EmitTargetMetadata();
 
+  /// Emits OpenCL specific Metadata e.g. OpenCL version.
+  void EmitOpenCLMetadata();
+
   /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
   /// .gcda files in a way that persists in .bc files.
   void EmitCoverageFile();

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=305796=305795=305796=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Tue Jun 20 09:30:18 2017
@@ -7344,8 +7344,6 @@ public:
 };
 }
 
-static void appendOpenCLVersionMD (CodeGen::CodeGenModule );
-
 void AMDGPUTargetCodeGenInfo::setTargetAttributes(
 const Decl *D,
 llvm::GlobalValue *GV,
@@ -7402,8 +7400,6 @@ void AMDGPUTargetCodeGenInfo::setTargetA
 if (NumVGPR != 0)
   F->addFnAttr("amdgpu-num-vgpr", llvm::utostr(NumVGPR));
   }
-
-  appendOpenCLVersionMD(M);
 }
 
 unsigned AMDGPUTargetCodeGenInfo::getOpenCLKernelCallingConv() const {
@@ -8074,8 +8070,6 @@ class SPIRTargetCodeGenInfo : public Tar
 public:
   SPIRTargetCodeGenInfo(CodeGen::CodeGenTypes )
 : TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
-  void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
-CodeGen::CodeGenModule ) const override;
   unsigned 

r304575 - [OpenCL] Harden function pointer diagnostics.

2017-06-02 Thread Alexey Bader via cfe-commits
Author: bader
Date: Fri Jun  2 13:08:58 2017
New Revision: 304575

URL: http://llvm.org/viewvc/llvm-project?rev=304575=rev
Log:
[OpenCL] Harden function pointer diagnostics.

Summary: Improve OpenCL type checking by rejecting function pointer types.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D33821


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/func.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=304575=304574=304575=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun  2 13:08:58 
2017
@@ -7268,7 +7268,7 @@ def err_invalid_conversion_between_vecto
   "invalid conversion between vector type %0 and integer type %1 "
   "of different size">;
 
-def err_opencl_function_pointer_variable : Error<
+def err_opencl_function_pointer : Error<
   "pointers to functions are not allowed">;
 
 def err_opencl_taking_function_address : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=304575=304574=304575=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jun  2 13:08:58 2017
@@ -6160,7 +6160,7 @@ NamedDecl *Sema::ActOnVariableDeclarator
 QualType NR = R;
 while (NR->isPointerType()) {
   if (NR->isFunctionPointerType()) {
-Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer_variable);
+Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer);
 D.setInvalidType();
 break;
   }

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=304575=304574=304575=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Jun  2 13:08:58 2017
@@ -1881,6 +1881,11 @@ QualType Sema::BuildPointerType(QualType
 return QualType();
   }
 
+  if (T->isFunctionType() && getLangOpts().OpenCL) {
+Diag(Loc, diag::err_opencl_function_pointer);
+return QualType();
+  }
+
   if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer))
 return QualType();
 

Modified: cfe/trunk/test/SemaOpenCL/func.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/func.cl?rev=304575=304574=304575=diff
==
--- cfe/trunk/test/SemaOpenCL/func.cl (original)
+++ cfe/trunk/test/SemaOpenCL/func.cl Fri Jun  2 13:08:58 2017
@@ -4,8 +4,15 @@
 void vararg_f(int, ...);// expected-error {{invalid 
prototype, variadic arguments are not allowed in OpenCL}}
 void __vararg_f(int, ...);
 typedef void (*vararg_fptr_t)(int, ...);// expected-error {{invalid 
prototype, variadic arguments are not allowed in OpenCL}}
+// expected-error@-1{{pointers to 
functions are not allowed}}
 int printf(__constant const char *st, ...); // expected-error {{invalid 
prototype, variadic arguments are not allowed in OpenCL}}
 
+// Struct type with function pointer field
+typedef struct s
+{
+   void (*f)(struct s *self, int *i);   // expected-error{{pointers to 
functions are not allowed}}
+} s_t;
+
 //Function pointer
 void foo(void*);
 


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


r288891 - [OpenCL] Added a LIT test for ensuring address space mangling is done the same both in OpenCL1.2 and OpenCL2.0.

2016-12-07 Thread Alexey Bader via cfe-commits
Author: bader
Date: Wed Dec  7 02:43:49 2016
New Revision: 288891

URL: http://llvm.org/viewvc/llvm-project?rev=288891=rev
Log:
[OpenCL] Added a LIT test for ensuring address space mangling is done the same 
both in OpenCL1.2 and OpenCL2.0.

Patch by Egor Churaev (echuraev).

Reviewers: Anastasia

Subscribers: yaxunl, cfe-commits, bader

Differential Revision: https://reviews.llvm.org/D27403

Modified:
cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl

Modified: cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl?rev=288891=288890=288891=diff
==
--- cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl Wed Dec  7 02:43:49 
2016
@@ -1,6 +1,10 @@
 // RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck -check-prefix=ASMANG %s
 // RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefix=NOASMANG 
%s
 
+// We check that the address spaces are mangled the same in both version of 
OpenCL
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL2.0 -emit-llvm -o 
- | FileCheck -check-prefix=OCL-20 %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL1.2 -emit-llvm -o 
- | FileCheck -check-prefix=OCL-12 %s
+
 // We can't name this f as private is equivalent to default
 // no specifier given address space so we get multiple definition
 // warnings, but we do want it for comparison purposes.
@@ -8,23 +12,33 @@ __attribute__((overloadable))
 void ff(int *arg) { }
 // ASMANG: @_Z2ffPi
 // NOASMANG: @_Z2ffPi
+// OCL-20-DAG: @_Z2ffPU3AS4i
+// OCL-12-DAG: @_Z2ffPi
 
 __attribute__((overloadable))
 void f(private int *arg) { }
 // ASMANG: @_Z1fPi
 // NOASMANG: @_Z1fPi
+// OCL-20-DAG: @_Z1fPi
+// OCL-12-DAG: @_Z1fPi
 
 __attribute__((overloadable))
 void f(global int *arg) { }
 // ASMANG: @_Z1fPU3AS1i
 // NOASMANG: @_Z1fPU8CLglobali
+// OCL-20-DAG: @_Z1fPU3AS1i
+// OCL-12-DAG: @_Z1fPU3AS1i
 
 __attribute__((overloadable))
 void f(local int *arg) { }
 // ASMANG: @_Z1fPU3AS2i
 // NOASMANG: @_Z1fPU7CLlocali
+// OCL-20-DAG: @_Z1fPU3AS2i
+// OCL-12-DAG: @_Z1fPU3AS2i
 
 __attribute__((overloadable))
 void f(constant int *arg) { }
 // ASMANG: @_Z1fPU3AS3i
 // NOASMANG: @_Z1fPU10CLconstanti
+// OCL-20-DAG: @_Z1fPU3AS3i
+// OCL-12-DAG: @_Z1fPU3AS3i


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


r288890 - [OpenCL] Fix SPIR version generation.

2016-12-07 Thread Alexey Bader via cfe-commits
Author: bader
Date: Wed Dec  7 02:38:24 2016
New Revision: 288890

URL: http://llvm.org/viewvc/llvm-project?rev=288890=rev
Log:
[OpenCL] Fix SPIR version generation.

Patch by Egor Churaev (echuraev).

Reviewers: Anastasia

Subscribers: bader, yaxunl, cfe-commits

Differential Revision: https://reviews.llvm.org/D27300


Modified:
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGenOpenCL/spir_version.cl

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=288890=29=288890=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Dec  7 02:38:24 2016
@@ -7801,8 +7801,10 @@ void SPIRTargetCodeGenInfo::emitTargetMD
   // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
   // opencl.spir.version named metadata.
   llvm::Metadata *SPIRVerElts[] = {
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 2)),
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 0))};
+  llvm::ConstantAsMetadata::get(
+  llvm::ConstantInt::get(Int32Ty, CGM.getLangOpts().OpenCLVersion / 
100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (CGM.getLangOpts().OpenCLVersion / 100 > 1) ? 0 : 2))};
   llvm::NamedMDNode *SPIRVerMD =
   M.getOrInsertNamedMetadata("opencl.spir.version");
   SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));

Modified: cfe/trunk/test/CodeGenOpenCL/spir_version.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/spir_version.cl?rev=288890=29=288890=diff
==
--- cfe/trunk/test/CodeGenOpenCL/spir_version.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/spir_version.cl Wed Dec  7 02:38:24 2016
@@ -13,19 +13,22 @@ kernel void foo() {}
 
 // CHECK-SPIR-CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
 // CHECK-SPIR-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-SPIR-CL10: [[SPIR]] = !{i32 2, i32 0}
+// CHECK-SPIR-CL10: [[SPIR]] = !{i32 1, i32 2}
 // CHECK-SPIR-CL10: [[OCL]] = !{i32 1, i32 0}
-// CHECK-SPIR-CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-SPIR-CL12: [[SPIR]] = !{i32 2, i32 0}
-// CHECK-SPIR-CL12: [[OCL]] = !{i32 1, i32 2}
-// CHECK-SPIR-CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL20: [[SPIR]] = !{i32 2, i32 0}
+// CHECK-SPIR-CL12: !opencl.spir.version = !{[[VER:![0-9]+]]}
+// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[VER]]}
+// CHECK-SPIR-CL12: [[VER]] = !{i32 1, i32 2}
 
+// CHECK-SPIR-CL20: !opencl.spir.version = !{[[VER:![0-9]+]]}
+// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[VER]]}
+// CHECK-SPIR-CL20: [[VER]] = !{i32 2, i32 0}
+
+// CHECK-AMDGCN-CL10-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
 // CHECK-AMDGCN-CL10: [[OCL]] = !{i32 1, i32 0}
+// CHECK-AMDGCN-CL12-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
 // CHECK-AMDGCN-CL12: [[OCL]] = !{i32 1, i32 2}
+// CHECK-AMDGCN-CL20-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL20: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-AMDGCN-CL20: [[OCL]] = !{i32 2, i32 0}
\ No newline at end of file
+// CHECK-AMDGCN-CL20: [[OCL]] = !{i32 2, i32 0}


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


r288126 - [OpenCL] Prohibit using reserve_id_t in program scope.

2016-11-29 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Nov 29 04:21:40 2016
New Revision: 288126

URL: http://llvm.org/viewvc/llvm-project?rev=288126=rev
Log:
[OpenCL] Prohibit using reserve_id_t in program scope.

Patch by Egor Churaev (echuraev).

Reviewers: Anastasia

Subscribers: cfe-commits, yaxunl, bader

Differential Revision: https://reviews.llvm.org/D27099


Added:
cfe/trunk/test/SemaOpenCL/invalid-clk-events-cl2.0.cl
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/event_t.cl
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=288126=288125=288126=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Nov 29 04:21:40 
2016
@@ -8075,8 +8075,6 @@ def note_within_field_of_type : Note<
   "within field of type %0 declared here">;
 def note_illegal_field_declared_here : Note<
   "field of illegal %select{type|pointer type}0 %1 declared here">;
-def err_event_t_global_var : Error<
-  "the event_t type cannot be used to declare a program scope variable">;
 def err_opencl_type_struct_or_union_field : Error<
   "the %0 type cannot be used to declare a structure or union field">;
 def err_event_t_addr_space_qual : Error<
@@ -8589,6 +8587,8 @@ def note_related_result_type_inferred :
 def note_related_result_type_explicit : Note<
   "%select{overridden|current}0 method is explicitly declared 'instancetype'"
   "%select{| and is expected to return an instance of its class type}0">;
+def err_invalid_type_for_program_scope_var : Error<
+  "the %0 type cannot be used to declare a program scope variable">;
 
 }
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=288126=288125=288126=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 04:21:40 2016
@@ -5909,32 +5909,31 @@ NamedDecl *Sema::ActOnVariableDeclarator
 return nullptr;
   }
 
-  // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
-  // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
-  // argument.
-  if (getLangOpts().OpenCL && (R->isImageType() || R->isPipeType())) {
-Diag(D.getIdentifierLoc(),
- diag::err_opencl_type_can_only_be_used_as_function_parameter)
-<< R;
-D.setInvalidType();
-return nullptr;
-  }
-
-  DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec();
-  StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec());
-
-  // dllimport globals without explicit storage class are treated as extern. We
-  // have to change the storage class this early to get the right DeclContext.
-  if (SC == SC_None && !DC->isRecord() &&
-  hasParsedAttr(S, D, AttributeList::AT_DLLImport) &&
-  !hasParsedAttr(S, D, AttributeList::AT_DLLExport))
-SC = SC_Extern;
+  if (getLangOpts().OpenCL) {
+// OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
+// OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
+// argument.
+if (R->isImageType() || R->isPipeType()) {
+  Diag(D.getIdentifierLoc(),
+   diag::err_opencl_type_can_only_be_used_as_function_parameter)
+  << R;
+  D.setInvalidType();
+  return nullptr;
+}
 
-  DeclContext *OriginalDC = DC;
-  bool IsLocalExternDecl = SC == SC_Extern &&
-   adjustContextForLocalExternDecl(DC);
+// OpenCL v1.2 s6.9.r:
+// The event type cannot be used to declare a program scope variable.
+// OpenCL v2.0 s6.9.q:
+// The clk_event_t and reserve_id_t types cannot be declared in program 
scope.
+if (NULL == S->getParent()) {
+  if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {
+Diag(D.getIdentifierLoc(),
+ diag::err_invalid_type_for_program_scope_var) << R;
+D.setInvalidType();
+return nullptr;
+  }
+}
 
-  if (getLangOpts().OpenCL) {
 // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
 QualType NR = R;
 while (NR->isPointerType()) {
@@ -5954,8 +5953,40 @@ NamedDecl *Sema::ActOnVariableDeclarator
 D.setInvalidType();
   }
 }
+
+// OpenCL v1.2 s6.9.b p4:
+// The sampler type cannot be used with the __local and __global address
+// space qualifiers.
+if (R->isSamplerT() && (R.getAddressSpace() == LangAS::opencl_local ||
+  R.getAddressSpace() == LangAS::opencl_global)) {
+  Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace);
+}
+
+// OpenCL v1.2 s6.9.r:
+// The event type cannot be used with 

[PATCH] D26746: [OpenCL] Split PipeType into ReadPipe/WritePipe

2016-11-17 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!
A few minor comments regarding outdated comments and style.




Comment at: include/clang/AST/ASTContext.h:1124
 
   /// \brief Return pipe type for the specified type.
+  QualType getReadPipeType(QualType T) const;

Please, update the comment to specify that this function return pipe type with 
'__read_only' access qualifier.



Comment at: lib/AST/ASTContext.cpp:3341
 
 /// Return pipe type for the specified type.
+QualType ASTContext::getReadPipeType(QualType T) const {

Please, remove this comment. It's a copy of the comment from the header file.



Comment at: lib/Serialization/ASTReader.cpp:5806-5807
+return Context.getReadPipeType(ElementType);
+  }
+  case TYPE_WRITE_PIPE: {
+if (Record.size() != 1) {

Please, separate case with an empty line.


Repository:
  rL LLVM

https://reviews.llvm.org/D26746



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


[PATCH] D26157: [OpenCL] always use SPIR address spaces for kernel_arg_addr_space MD

2016-11-02 Thread Alexey Bader via cfe-commits
bader added a comment.

@pekka.jaaskelainen, I have related question: what is the problem with 
retaining OpenCL address space information in LLVM IR?
My understanding is that target CodeGen can ignore this information for the 
machines with 'flat' address space model.
On the other hand I would expect this information be useful for the Optimizer 
to resolve pointer aliasing.
Does it make any sense to keep OpenCL address space information in LLVM IR 
generated for the machines with 'flat' address space (e.g. CPU)?


Repository:
  rL LLVM

https://reviews.llvm.org/D26157



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


[PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-11-01 Thread Alexey Bader via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285700: [OpenCL] Override supported OpenCL extensions with 
-cl-ext option (authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D23712?vs=75568=76571#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23712

Files:
  cfe/trunk/include/clang/Basic/OpenCLOptions.h
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/include/clang/Basic/TargetOptions.h
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/SemaOpenCL/extensions.cl

Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -688,6 +688,13 @@
   HelpText<"include a detailed record of preprocessing actions">;
 
 //===--===//
+// OpenCL Options
+//===--===//
+
+def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">,
+  HelpText<"OpenCL only. Enable or disable OpenCL extensions. The argument is a comma-separated sequence of one or more extension names, each prefixed by '+' or '-'.">;
+
+//===--===//
 // CUDA Options
 //===--===//
 
Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -995,6 +995,13 @@
   /// \brief Set supported OpenCL extensions and optional core features.
   virtual void setSupportedOpenCLOpts() {}
 
+  /// \brief Set supported OpenCL extensions as written on command line
+  virtual void setOpenCLExtensionOpts() {
+for (const auto  : getTargetOpts().OpenCLExtensionsAsWritten) {
+  getTargetOpts().SupportedOpenCLOptions.set(Ext);
+}
+  }
+
   /// \brief Get supported OpenCL extensions and optional core features.
   OpenCLOptions () {
 return getTargetOpts().SupportedOpenCLOptions;
Index: cfe/trunk/include/clang/Basic/TargetOptions.h
===
--- cfe/trunk/include/clang/Basic/TargetOptions.h
+++ cfe/trunk/include/clang/Basic/TargetOptions.h
@@ -58,6 +58,10 @@
 
   /// Supported OpenCL extensions and optional core features.
   OpenCLOptions SupportedOpenCLOptions;
+
+  /// \brief The list of OpenCL extensions to enable or disable, as written on
+  /// the command line.
+  std::vector OpenCLExtensionsAsWritten;
 };
 
 }  // end namespace clang
Index: cfe/trunk/include/clang/Basic/OpenCLOptions.h
===
--- cfe/trunk/include/clang/Basic/OpenCLOptions.h
+++ cfe/trunk/include/clang/Basic/OpenCLOptions.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 #define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 
+#include "llvm/ADT/StringRef.h"
+
 namespace clang {
 
 /// \brief OpenCL supported extensions and optional core features
@@ -28,9 +30,39 @@
 #include "clang/Basic/OpenCLExtensions.def"
   }
 
-  // Enable all options.
-  void setAll() {
-#define OPENCLEXT(nm)   nm = 1;
+  // Enable or disable all options.
+  void setAll(bool Enable = true) {
+#define OPENCLEXT(nm)   nm = Enable;
+#include "clang/Basic/OpenCLExtensions.def"
+  }
+
+  /// \brief Enable or disable support for OpenCL extensions
+  /// \param Ext name of the extension optionally prefixed with
+  ///'+' or '-'
+  /// \param Enable used when \p Ext is not prefixed by '+' or '-'
+  void set(llvm::StringRef Ext, bool Enable = true) {
+assert(!Ext.empty() && "Extension is empty.");
+
+switch (Ext[0]) {
+case '+':
+  Enable = true;
+  Ext = Ext.drop_front();
+  break;
+case '-':
+  Enable = false;
+  Ext = Ext.drop_front();
+  break;
+}
+
+if (Ext.equals("all")) {
+  setAll(Enable);
+  return;
+}
+
+#define OPENCLEXT(nm)   \
+if (Ext.equals(#nm)) {  \
+  nm = Enable;  \
+}
 #include "clang/Basic/OpenCLExtensions.def"
   }
 
Index: cfe/trunk/test/SemaOpenCL/extensions.cl
===
--- cfe/trunk/test/SemaOpenCL/extensions.cl
+++ cfe/trunk/test/SemaOpenCL/extensions.cl
@@ -2,7 +2,26 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
 
 // Test with a target not supporting fp64.
-// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64
+// RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
+
+// Test with some extensions enabled or disabled by cmd-line 

r285700 - [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-11-01 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Nov  1 10:50:52 2016
New Revision: 285700

URL: http://llvm.org/viewvc/llvm-project?rev=285700=rev
Log:
[OpenCL] Override supported OpenCL extensions with -cl-ext option

Summary:
This patch adds a command line option '-cl-ext' to control a set of
supported OpenCL extensions. Option accepts a comma-separated list
of extensions prefixed with '+' or '-'.

It can be used together with a target triple to override support for some
extensions:

  // spir target supports all extensions, but we want to disable fp64
  clang -cc1 -triple spir-unknown-unknown -cl-ext=-cl_khr_fp64

Special 'all' extension allows to enable or disable all possible
extensions:

  // only fp64 will be supported
  clang -cc1 -triple spir-unknown-unknown -cl-ext=-all,+cl_khr_fp64

Patch by asavonic (Andrew Savonichev).

Reviewers: joey, yaxunl

Subscribers: yaxunl, bader, Anastasia, cfe-commits

Differential Revision: https://reviews.llvm.org/D23712



Modified:
cfe/trunk/include/clang/Basic/OpenCLOptions.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/include/clang/Basic/TargetOptions.h
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/SemaOpenCL/extensions.cl

Modified: cfe/trunk/include/clang/Basic/OpenCLOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenCLOptions.h?rev=285700=285699=285700=diff
==
--- cfe/trunk/include/clang/Basic/OpenCLOptions.h (original)
+++ cfe/trunk/include/clang/Basic/OpenCLOptions.h Tue Nov  1 10:50:52 2016
@@ -15,6 +15,8 @@
 #ifndef LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 #define LLVM_CLANG_BASIC_OPENCLOPTIONS_H
 
+#include "llvm/ADT/StringRef.h"
+
 namespace clang {
 
 /// \brief OpenCL supported extensions and optional core features
@@ -28,9 +30,39 @@ public:
 #include "clang/Basic/OpenCLExtensions.def"
   }
 
-  // Enable all options.
-  void setAll() {
-#define OPENCLEXT(nm)   nm = 1;
+  // Enable or disable all options.
+  void setAll(bool Enable = true) {
+#define OPENCLEXT(nm)   nm = Enable;
+#include "clang/Basic/OpenCLExtensions.def"
+  }
+
+  /// \brief Enable or disable support for OpenCL extensions
+  /// \param Ext name of the extension optionally prefixed with
+  ///'+' or '-'
+  /// \param Enable used when \p Ext is not prefixed by '+' or '-'
+  void set(llvm::StringRef Ext, bool Enable = true) {
+assert(!Ext.empty() && "Extension is empty.");
+
+switch (Ext[0]) {
+case '+':
+  Enable = true;
+  Ext = Ext.drop_front();
+  break;
+case '-':
+  Enable = false;
+  Ext = Ext.drop_front();
+  break;
+}
+
+if (Ext.equals("all")) {
+  setAll(Enable);
+  return;
+}
+
+#define OPENCLEXT(nm)   \
+if (Ext.equals(#nm)) {  \
+  nm = Enable;  \
+}
 #include "clang/Basic/OpenCLExtensions.def"
   }
 

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=285700=285699=285700=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Tue Nov  1 10:50:52 2016
@@ -995,6 +995,13 @@ public:
   /// \brief Set supported OpenCL extensions and optional core features.
   virtual void setSupportedOpenCLOpts() {}
 
+  /// \brief Set supported OpenCL extensions as written on command line
+  virtual void setOpenCLExtensionOpts() {
+for (const auto  : getTargetOpts().OpenCLExtensionsAsWritten) {
+  getTargetOpts().SupportedOpenCLOptions.set(Ext);
+}
+  }
+
   /// \brief Get supported OpenCL extensions and optional core features.
   OpenCLOptions () {
 return getTargetOpts().SupportedOpenCLOptions;

Modified: cfe/trunk/include/clang/Basic/TargetOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetOptions.h?rev=285700=285699=285700=diff
==
--- cfe/trunk/include/clang/Basic/TargetOptions.h (original)
+++ cfe/trunk/include/clang/Basic/TargetOptions.h Tue Nov  1 10:50:52 2016
@@ -58,6 +58,10 @@ public:
 
   /// Supported OpenCL extensions and optional core features.
   OpenCLOptions SupportedOpenCLOptions;
+
+  /// \brief The list of OpenCL extensions to enable or disable, as written on
+  /// the command line.
+  std::vector OpenCLExtensionsAsWritten;
 };
 
 }  // end namespace clang

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=285700=285699=285700=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Nov  1 

[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-31 Thread Alexey Bader via cfe-commits
bader added a comment.

Committed at 285557 with updated tests.


https://reviews.llvm.org/D25305



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


r285557 - [OpenCL] Setting constant address space for array initializers

2016-10-31 Thread Alexey Bader via cfe-commits
Author: bader
Date: Mon Oct 31 05:26:31 2016
New Revision: 285557

URL: http://llvm.org/viewvc/llvm-project?rev=285557=rev
Log:
[OpenCL] Setting constant address space for array initializers

Summary: Setting constant address space for global constants used for 
memcpy-initialization of arrays.

Patch by Alexey Sotkin.

Reviewers: bader, yaxunl, Anastasia

Subscribers: cfe-commits, AlexeySotkin

Differential Revision: https://reviews.llvm.org/D25305


Added:
cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=285557=285556=285557=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Oct 31 05:26:31 2016
@@ -1225,10 +1225,16 @@ void CodeGenFunction::EmitAutoVarInit(co
 // Otherwise, create a temporary global with the initializer then
 // memcpy from the global to the alloca.
 std::string Name = getStaticDeclName(CGM, D);
+unsigned AS = 0;
+if (getLangOpts().OpenCL) {
+  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
+  BP = llvm::PointerType::getInt8PtrTy(getLLVMContext(), AS);
+}
 llvm::GlobalVariable *GV =
   new llvm::GlobalVariable(CGM.getModule(), constant->getType(), true,
llvm::GlobalValue::PrivateLinkage,
-   constant, Name);
+   constant, Name, nullptr,
+   llvm::GlobalValue::NotThreadLocal, AS);
 GV->setAlignment(Loc.getAlignment().getQuantity());
 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 

Modified: cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl?rev=285557=285556=285557=diff
==
--- cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl Mon Oct 31 05:26:31 2016
@@ -24,7 +24,7 @@ int4 GV1 = (int4)((int2)(1,2),3,4);
 // CHECK: @GV2 = addrspace(1) global <4 x i32> , 
align 16
 int4 GV2 = (int4)(1);
 
-// CHECK: @f.S = private unnamed_addr constant %struct.StrucTy { i32 1, i32 2, 
i32 0 }, align 4
+// CHECK: @f.S = private unnamed_addr addrspace(2) constant %struct.StrucTy { 
i32 1, i32 2, i32 0 }, align 4
 
 // CHECK-LABEL: define spir_func void @f()
 void f(void) {
@@ -46,7 +46,7 @@ void f(void) {
   float A[6][6]  = {1.0f, 2.0f};
 
   // CHECK: %[[v5:.*]] = bitcast %struct.StrucTy* %S to i8*
-  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[v5]], i8* bitcast 
(%struct.StrucTy* @f.S to i8*), i32 12, i32 4, i1 false)
+  // CHECK: call void @llvm.memcpy.p0i8.p2i8.i32(i8* %[[v5]], i8 addrspace(2)* 
bitcast (%struct.StrucTy addrspace(2)* @f.S to i8 addrspace(2)*), i32 12, i32 
4, i1 false)
   StrucTy S = {1, 2};
 
   // CHECK: store <2 x i32> , <2 x i32>* %[[compoundliteral1]], 
align 8

Added: cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl?rev=285557=auto
==
--- cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl Mon Oct 31 
05:26:31 2016
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | 
FileCheck %s
+
+// CHECK: @test.arr = private unnamed_addr addrspace(2) constant [3 x i32] 
[i32 1, i32 2, i32 3], align 4
+
+void test() {
+  __private int arr[] = {1, 2, 3};
+// CHECK:  %[[arr_i8_ptr:[0-9]+]] = bitcast [3 x i32]* %arr to i8*
+// CHECK:  call void @llvm.memcpy.p0i8.p2i8.i32(i8* %[[arr_i8_ptr]], i8 
addrspace(2)* bitcast ([3 x i32] addrspace(2)* @test.arr to i8 addrspace(2)*), 
i32 12, i32 4, i1 false)
+}


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


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-25 Thread Alexey Bader via cfe-commits
bader added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1272
+if (getLangOpts().OpenCL) {
+  UA = llvm::GlobalValue::UnnamedAddr::None;
+  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);

Anastasia wrote:
> bader wrote:
> > AlexeySotkin wrote:
> > > Anastasia wrote:
> > > > Why this change?
> > > Without this change, global variables with unnamed address space are 
> > > translated to SPIR-V as variables with "Function" storage class, which is 
> > > wrong.
> > > This should fix this issue: 
> > > https://github.com/KhronosGroup/SPIRV-LLVM/issues/50
> > There is inconsistency with how Clang maps initializers to OpenCL memory 
> > model.
> > Consider example from the test case:
> > ```
> > __private int arr[] = {1, 2, 3};
> > ```
> > This code allocates a global constant for initializer {1, 2, 3} and later 
> > copies values from this global constant to the private array using memcpy 
> > intrinsic. The global constant must be allocated in constant address space, 
> > but old code do assign any address space, which is considered to be a 
> > private memory region.
> > This patch puts global constant objects to constant address space.
> Yes, this is perfectly fine. I was specifically asking about setting 
> llvm::GlobalValue::UnnamedAddr::None attribute. I can't see why this has to 
> be done or is it because we now assign concrete address space and private was 
> treated as no address space at all?
This attribute has nothing to do with address spaces.
See http://llvm.org/docs/LangRef.html#global-variables for local_unnamed_addr 
and unnamed_addr attributes description.
My understanding is that llvm::GlobalValue::UnnamedAddr::Global should be fine 
here.


https://reviews.llvm.org/D25305



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


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-24 Thread Alexey Bader via cfe-commits
bader added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1272
+if (getLangOpts().OpenCL) {
+  UA = llvm::GlobalValue::UnnamedAddr::None;
+  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);

AlexeySotkin wrote:
> Anastasia wrote:
> > Why this change?
> Without this change, global variables with unnamed address space are 
> translated to SPIR-V as variables with "Function" storage class, which is 
> wrong.
> This should fix this issue: 
> https://github.com/KhronosGroup/SPIRV-LLVM/issues/50
There is inconsistency with how Clang maps initializers to OpenCL memory model.
Consider example from the test case:
```
__private int arr[] = {1, 2, 3};
```
This code allocates a global constant for initializer {1, 2, 3} and later 
copies values from this global constant to the private array using memcpy 
intrinsic. The global constant must be allocated in constant address space, but 
old code do assign any address space, which is considered to be a private 
memory region.
This patch puts global constant objects to constant address space.


https://reviews.llvm.org/D25305



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


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-19 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a comment.

LGTM


https://reviews.llvm.org/D25305



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


Re: [PATCH] D23992: [OpenCL] Augment pipe built-ins with pipe packet size and alignment.

2016-09-23 Thread Alexey Bader via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL282252: [OpenCL] Augment pipe built-ins with pipe packet 
size and alignment. (authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D23992?vs=70366=72276#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23992

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
  cfe/trunk/lib/CodeGen/CGOpenCLRuntime.h
  cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
  cfe/trunk/test/CodeGenOpenCL/pipe_types.cl

Index: cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
===
--- cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
+++ cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
@@ -4,59 +4,59 @@
 // CHECK: %opencl.reserve_id_t = type opaque
 
 void test1(read_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
   read_pipe(p, ptr);
-  // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_read_pipe(p, 2);
-  // CHECK: call i32 @__read_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}}, i32 4, i32 4)
   read_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   commit_read_pipe(p, rid);
 }
 
 void test2(write_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__write_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__write_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
   write_pipe(p, ptr);
-  // CHECK: call %opencl.reserve_id_t* @__reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_write_pipe(p, 2);
-  // CHECK: call i32 @__write_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__write_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}}, i32 4, i32 4)
   write_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   commit_write_pipe(p, rid);
 }
 
 void test3(read_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = work_group_reserve_read_pipe(p, 2);
-  // CHECK: call void @__work_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__work_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   work_group_commit_read_pipe(p, rid);
 }
 
 void test4(write_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = work_group_reserve_write_pipe(p, 2);
-  // CHECK: call void @__work_group_commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__work_group_commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   work_group_commit_write_pipe(p, rid);
 }
 
 void test5(read_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__sub_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__sub_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = sub_group_reserve_read_pipe(p, 2);
-  // CHECK: call void @__sub_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__sub_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   sub_group_commit_read_pipe(p, rid);
 }
 
 void test6(write_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__sub_group_reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* 

r282252 - [OpenCL] Augment pipe built-ins with pipe packet size and alignment.

2016-09-23 Thread Alexey Bader via cfe-commits
Author: bader
Date: Fri Sep 23 09:20:00 2016
New Revision: 282252

URL: http://llvm.org/viewvc/llvm-project?rev=282252=rev
Log:
[OpenCL] Augment pipe built-ins with pipe packet size and alignment.

Reviewers: Anastasia, vpykhtin

Subscribers: dmitry, cfe-commits

Differential Revision: https://reviews.llvm.org/D23992


Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.h
cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
cfe/trunk/test/CodeGenOpenCL/pipe_types.cl

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=282252=282251=282252=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Sep 23 09:20:00 2016
@@ -14,6 +14,7 @@
 #include "CodeGenFunction.h"
 #include "CGCXXABI.h"
 #include "CGObjCRuntime.h"
+#include "CGOpenCLRuntime.h"
 #include "CodeGenModule.h"
 #include "TargetInfo.h"
 #include "clang/AST/ASTContext.h"
@@ -2139,6 +2140,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   case Builtin::BIwrite_pipe: {
 Value *Arg0 = EmitScalarExpr(E->getArg(0)),
   *Arg1 = EmitScalarExpr(E->getArg(1));
+CGOpenCLRuntime OpenCLRT(CGM);
+Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0));
+Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0));
 
 // Type of the generic packet parameter.
 unsigned GenericAS =
@@ -2152,19 +2156,21 @@ RValue CodeGenFunction::EmitBuiltinExpr(
  : 
"__write_pipe_2";
   // Creating a generic function type to be able to call with any builtin 
or
   // user defined type.
-  llvm::Type *ArgTys[] = {Arg0->getType(), I8PTy};
+  llvm::Type *ArgTys[] = {Arg0->getType(), I8PTy, Int32Ty, Int32Ty};
   llvm::FunctionType *FTy = llvm::FunctionType::get(
   Int32Ty, llvm::ArrayRef(ArgTys), false);
   Value *BCast = Builder.CreatePointerCast(Arg1, I8PTy);
-  return RValue::get(Builder.CreateCall(
-  CGM.CreateRuntimeFunction(FTy, Name), {Arg0, BCast}));
+  return RValue::get(
+  Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),
+ {Arg0, BCast, PacketSize, PacketAlign}));
 } else {
   assert(4 == E->getNumArgs() &&
  "Illegal number of parameters to pipe function");
   const char *Name = (BuiltinID == Builtin::BIread_pipe) ? "__read_pipe_4"
  : 
"__write_pipe_4";
 
-  llvm::Type *ArgTys[] = {Arg0->getType(), Arg1->getType(), Int32Ty, 
I8PTy};
+  llvm::Type *ArgTys[] = {Arg0->getType(), Arg1->getType(), Int32Ty, I8PTy,
+  Int32Ty, Int32Ty};
   Value *Arg2 = EmitScalarExpr(E->getArg(2)),
 *Arg3 = EmitScalarExpr(E->getArg(3));
   llvm::FunctionType *FTy = llvm::FunctionType::get(
@@ -2175,7 +2181,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   if (Arg2->getType() != Int32Ty)
 Arg2 = Builder.CreateZExtOrTrunc(Arg2, Int32Ty);
   return RValue::get(Builder.CreateCall(
-  CGM.CreateRuntimeFunction(FTy, Name), {Arg0, Arg1, Arg2, BCast}));
+  CGM.CreateRuntimeFunction(FTy, Name),
+  {Arg0, Arg1, Arg2, BCast, PacketSize, PacketAlign}));
 }
   }
   // OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe reserve read and write
@@ -2204,9 +2211,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 Value *Arg0 = EmitScalarExpr(E->getArg(0)),
   *Arg1 = EmitScalarExpr(E->getArg(1));
 llvm::Type *ReservedIDTy = ConvertType(getContext().OCLReserveIDTy);
+CGOpenCLRuntime OpenCLRT(CGM);
+Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0));
+Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0));
 
 // Building the generic function prototype.
-llvm::Type *ArgTys[] = {Arg0->getType(), Int32Ty};
+llvm::Type *ArgTys[] = {Arg0->getType(), Int32Ty, Int32Ty, Int32Ty};
 llvm::FunctionType *FTy = llvm::FunctionType::get(
 ReservedIDTy, llvm::ArrayRef(ArgTys), false);
 // We know the second argument is an integer type, but we may need to cast
@@ -2214,7 +2224,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 if (Arg1->getType() != Int32Ty)
   Arg1 = Builder.CreateZExtOrTrunc(Arg1, Int32Ty);
 return RValue::get(
-Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), {Arg0, 
Arg1}));
+Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),
+   {Arg0, Arg1, PacketSize, PacketAlign}));
   }
   // OpenCL v2.0 s6.13.16, s9.17.3.5 - Built-in pipe commit read and write
   // functions
@@ -2240,15 +2251,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 
 Value *Arg0 = EmitScalarExpr(E->getArg(0)),
   *Arg1 = EmitScalarExpr(E->getArg(1));
+

Re: [PATCH] D24666: [OpenCL] Allow half type kernel argument when cl_khr_fp16 is enabled

2016-09-16 Thread Alexey Bader via cfe-commits
bader added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:7599-7602
@@ -7595,3 +7598,6 @@
 // of event_t type.
-S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT;
+// Do not diagnose half type since it is diagnosed as invalid argument
+// type for any function eleswhere.
+if (!PT->isHalfType())
+  S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT;
 D.setInvalidType();

It looks strange to me. First we check if parameter type is half - we set 
InvalidKernelParam status, later we check again and do not report an error.
I think it would be simpler just return ValidKernelParam for half data type 
from getOpenCLKernelParameterType,

I think the whole patch should two deleted lines from 
getOpenCLKernelParameterType function + test case.


https://reviews.llvm.org/D24666



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


Re: [PATCH] D24666: [OpenCL] Allow half type kernel argument when cl_khr_fp16 is enabled

2016-09-16 Thread Alexey Bader via cfe-commits
bader added inline comments.


Comment at: test/SemaOpenCL/half.cl:29
@@ +28,3 @@
+kernel void half_disabled_kernel(global half *p,
+ half h);  // expected-error{{'half' cannot be 
used as the type of a kernel parameter}} // expected-error{{declaring function 
parameter of type 'half' is not allowed; did you forget * ?}}
+

It's not related to your change, but it looks like there are two checks that 
report the same error.
Could you remove the duplication, please?


https://reviews.llvm.org/D24666



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


Re: [PATCH] D24626: [OpenCL] Diagnose assignment to dereference of half type pointer

2016-09-16 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


https://reviews.llvm.org/D24626



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


Re: [PATCH] D23992: [OpenCL] Augment pipe built-ins with pipe packet size and alignment.

2016-09-07 Thread Alexey Bader via cfe-commits
bader added a comment.

Valery, do you have any additional comments/questions regarding this patch?


https://reviews.llvm.org/D23992



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


Re: [PATCH] D24136: [OpenCL] Fix pipe built-in functions return type.

2016-09-07 Thread Alexey Bader via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL280800: [OpenCL] Fix pipe built-in functions return type. 
(authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D24136?vs=70368=70516#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24136

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl

Index: cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
===
--- cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
+++ cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
@@ -59,3 +59,19 @@
   // CHECK: call i32 @__get_pipe_max_packets(%opencl.pipe_t* %{{.*}})
   *ptr = get_pipe_max_packets(p);
 }
+
+void test8(read_only pipe int r, write_only pipe int w, global int *ptr) {
+  // verify that return type is correctly casted to i1 value
+  // CHECK: %[[R:[0-9]+]] = call i32 @__read_pipe_2
+  // CHECK: icmp ne i32 %[[R]], 0
+  if (read_pipe(r, ptr)) *ptr = -1;
+  // CHECK: %[[W:[0-9]+]] = call i32 @__write_pipe_2
+  // CHECK: icmp ne i32 %[[W]], 0
+  if (write_pipe(w, ptr)) *ptr = -1;
+  // CHECK: %[[N:[0-9]+]] = call i32 @__get_pipe_num_packets
+  // CHECK: icmp ne i32 %[[N]], 0
+  if (get_pipe_num_packets(r)) *ptr = -1;
+  // CHECK: %[[M:[0-9]+]] = call i32 @__get_pipe_max_packets
+  // CHECK: icmp ne i32 %[[M]], 0
+  if (get_pipe_max_packets(w)) *ptr = -1;
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -1020,6 +1020,7 @@
 // check for the argument.
 if (SemaBuiltinRWPipe(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.IntTy);
 break;
   case Builtin::BIreserve_read_pipe:
   case Builtin::BIreserve_write_pipe:
@@ -1047,6 +1048,7 @@
   case Builtin::BIget_pipe_max_packets:
 if (SemaBuiltinPipePackets(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.UnsignedIntTy);
 break;
   case Builtin::BIto_global:
   case Builtin::BIto_local:


Index: cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
===
--- cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
+++ cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
@@ -59,3 +59,19 @@
   // CHECK: call i32 @__get_pipe_max_packets(%opencl.pipe_t* %{{.*}})
   *ptr = get_pipe_max_packets(p);
 }
+
+void test8(read_only pipe int r, write_only pipe int w, global int *ptr) {
+  // verify that return type is correctly casted to i1 value
+  // CHECK: %[[R:[0-9]+]] = call i32 @__read_pipe_2
+  // CHECK: icmp ne i32 %[[R]], 0
+  if (read_pipe(r, ptr)) *ptr = -1;
+  // CHECK: %[[W:[0-9]+]] = call i32 @__write_pipe_2
+  // CHECK: icmp ne i32 %[[W]], 0
+  if (write_pipe(w, ptr)) *ptr = -1;
+  // CHECK: %[[N:[0-9]+]] = call i32 @__get_pipe_num_packets
+  // CHECK: icmp ne i32 %[[N]], 0
+  if (get_pipe_num_packets(r)) *ptr = -1;
+  // CHECK: %[[M:[0-9]+]] = call i32 @__get_pipe_max_packets
+  // CHECK: icmp ne i32 %[[M]], 0
+  if (get_pipe_max_packets(w)) *ptr = -1;
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -1020,6 +1020,7 @@
 // check for the argument.
 if (SemaBuiltinRWPipe(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.IntTy);
 break;
   case Builtin::BIreserve_read_pipe:
   case Builtin::BIreserve_write_pipe:
@@ -1047,6 +1048,7 @@
   case Builtin::BIget_pipe_max_packets:
 if (SemaBuiltinPipePackets(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.UnsignedIntTy);
 break;
   case Builtin::BIto_global:
   case Builtin::BIto_local:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r280800 - [OpenCL] Fix pipe built-in functions return type.

2016-09-07 Thread Alexey Bader via cfe-commits
Author: bader
Date: Wed Sep  7 05:32:03 2016
New Revision: 280800

URL: http://llvm.org/viewvc/llvm-project?rev=280800=rev
Log:
[OpenCL] Fix pipe built-in functions return type.

By default return type of call expressions calling built-in
functions is set to bool.

Fixes https://llvm.org/bugs/show_bug.cgi?id=30219.

Reviewers: Anastasia

Subscribers: dmitry, cfe-commits, yaxunl

Differential Revision: https://reviews.llvm.org/D24136


Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=280800=280799=280800=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Sep  7 05:32:03 2016
@@ -1020,6 +1020,7 @@ Sema::CheckBuiltinFunctionCall(FunctionD
 // check for the argument.
 if (SemaBuiltinRWPipe(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.IntTy);
 break;
   case Builtin::BIreserve_read_pipe:
   case Builtin::BIreserve_write_pipe:
@@ -1047,6 +1048,7 @@ Sema::CheckBuiltinFunctionCall(FunctionD
   case Builtin::BIget_pipe_max_packets:
 if (SemaBuiltinPipePackets(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.UnsignedIntTy);
 break;
   case Builtin::BIto_global:
   case Builtin::BIto_local:

Modified: cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl?rev=280800=280799=280800=diff
==
--- cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl Wed Sep  7 05:32:03 2016
@@ -59,3 +59,19 @@ void test7(write_only pipe int p, global
   // CHECK: call i32 @__get_pipe_max_packets(%opencl.pipe_t* %{{.*}})
   *ptr = get_pipe_max_packets(p);
 }
+
+void test8(read_only pipe int r, write_only pipe int w, global int *ptr) {
+  // verify that return type is correctly casted to i1 value
+  // CHECK: %[[R:[0-9]+]] = call i32 @__read_pipe_2
+  // CHECK: icmp ne i32 %[[R]], 0
+  if (read_pipe(r, ptr)) *ptr = -1;
+  // CHECK: %[[W:[0-9]+]] = call i32 @__write_pipe_2
+  // CHECK: icmp ne i32 %[[W]], 0
+  if (write_pipe(w, ptr)) *ptr = -1;
+  // CHECK: %[[N:[0-9]+]] = call i32 @__get_pipe_num_packets
+  // CHECK: icmp ne i32 %[[N]], 0
+  if (get_pipe_num_packets(r)) *ptr = -1;
+  // CHECK: %[[M:[0-9]+]] = call i32 @__get_pipe_max_packets
+  // CHECK: icmp ne i32 %[[M]], 0
+  if (get_pipe_max_packets(w)) *ptr = -1;
+}


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


Re: [PATCH] D23915: [OpenCL] Remove access qualifiers on images in arg info metadata.

2016-09-06 Thread Alexey Bader via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL280699: [OpenCL] Remove access qualifiers on images in arg 
info metadata. (authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D23915?vs=69649=70372#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23915

Files:
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl

Index: cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
===
--- cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
+++ cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-kernel-arg-info | FileCheck %s -check-prefix ARGINFO
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown -cl-kernel-arg-info | FileCheck %s -check-prefix ARGINFO
 
 kernel void foo(__global int * restrict X, const int Y, 
 volatile int anotherArg, __constant float * restrict Z) {
@@ -14,7 +14,7 @@
 // CHECK-NOT: !kernel_arg_name
 // ARGINFO: !kernel_arg_name ![[MD15:[0-9]+]]
 
-kernel void foo2(read_only image1d_t img1, image2d_t img2, write_only image2d_array_t img3) {
+kernel void foo2(read_only image1d_t img1, image2d_t img2, write_only image2d_array_t img3, read_write image1d_t img4) {
 }
 // CHECK: define spir_kernel void @foo2{{[^!]+}}
 // CHECK: !kernel_arg_addr_space ![[MD21:[0-9]+]]
@@ -65,11 +65,11 @@
 // CHECK: ![[MD13]] = !{!"int*", !"int", !"int", !"float*"}
 // CHECK: ![[MD14]] = !{!"restrict", !"const", !"volatile", !"restrict const"}
 // ARGINFO: ![[MD15]] = !{!"X", !"Y", !"anotherArg", !"Z"}
-// CHECK: ![[MD21]] = !{i32 1, i32 1, i32 1}
-// CHECK: ![[MD22]] = !{!"read_only", !"read_only", !"write_only"}
-// CHECK: ![[MD23]] = !{!"__read_only image1d_t", !"__read_only image2d_t", !"__write_only image2d_array_t"}
-// CHECK: ![[MD24]] = !{!"", !"", !""}
-// ARGINFO: ![[MD25]] = !{!"img1", !"img2", !"img3"}
+// CHECK: ![[MD21]] = !{i32 1, i32 1, i32 1, i32 1}
+// CHECK: ![[MD22]] = !{!"read_only", !"read_only", !"write_only", !"read_write"}
+// CHECK: ![[MD23]] = !{!"image1d_t", !"image2d_t", !"image2d_array_t", !"image1d_t"}
+// CHECK: ![[MD24]] = !{!"", !"", !"", !""}
+// ARGINFO: ![[MD25]] = !{!"img1", !"img2", !"img3", !"img4"}
 // CHECK: ![[MD31]] = !{i32 1}
 // CHECK: ![[MD32]] = !{!"none"}
 // CHECK: ![[MD33]] = !{!"half*"}
@@ -82,7 +82,7 @@
 // CHECK: ![[MD45]] = !{!"", !""}
 // ARGINFO: ![[MD46]] = !{!"X", !"Y"}
 // CHECK: ![[MD51]] = !{!"read_only", !"write_only"}
-// CHECK: ![[MD52]] = !{!"myImage", !"__write_only image1d_t"}
-// CHECK: ![[MD53]] = !{!"__read_only image1d_t", !"__write_only image1d_t"}
+// CHECK: ![[MD52]] = !{!"myImage", !"image1d_t"}
+// CHECK: ![[MD53]] = !{!"image1d_t", !"image1d_t"}
 // ARGINFO: ![[MD54]] = !{!"img1", !"img2"}
 
Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
@@ -428,6 +428,26 @@
   EmitNounwindRuntimeCall(F, args);
 }
 
+static void removeImageAccessQualifier(std::string& TyName) {
+  std::string ReadOnlyQual("__read_only");
+  std::string::size_type ReadOnlyPos = TyName.find(ReadOnlyQual);
+  if (ReadOnlyPos != std::string::npos)
+// "+ 1" for the space after access qualifier.
+TyName.erase(ReadOnlyPos, ReadOnlyQual.size() + 1);
+  else {
+std::string WriteOnlyQual("__write_only");
+std::string::size_type WriteOnlyPos = TyName.find(WriteOnlyQual);
+if (WriteOnlyPos != std::string::npos)
+  TyName.erase(WriteOnlyPos, WriteOnlyQual.size() + 1);
+else {
+  std::string ReadWriteQual("__read_write");
+  std::string::size_type ReadWritePos = TyName.find(ReadWriteQual);
+  if (ReadWritePos != std::string::npos)
+TyName.erase(ReadWritePos, ReadWriteQual.size() + 1);
+}
+  }
+}
+
 // OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
 // information in the program executable. The argument information stored
 // includes the argument name, its type, the address and access qualifiers used.
@@ -524,8 +544,6 @@
   if (ty.isCanonical() && pos != std::string::npos)
 typeName.erase(pos+1, 8);
 
-  argTypeNames.push_back(llvm::MDString::get(Context, typeName));
-
   std::string baseTypeName;
   if (isPipe)
 baseTypeName = ty.getCanonicalType()->getAs()
@@ -535,6 +553,17 @@
 baseTypeName =
   ty.getUnqualifiedType().getCanonicalType().getAsString(Policy);
 
+  // Remove access qualifiers on images
+  // (as they are inseparable from type in clang implementation,
+  // but OpenCL spec provides a special query to get access 

r280699 - [OpenCL] Remove access qualifiers on images in arg info metadata.

2016-09-06 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Sep  6 05:10:28 2016
New Revision: 280699

URL: http://llvm.org/viewvc/llvm-project?rev=280699=rev
Log:
[OpenCL] Remove access qualifiers on images in arg info metadata.

Summary:
Remove access qualifiers on images in arg info metadata:
 * kernel_arg_type
 * kernel_arg_base_type

Image access qualifiers are inseparable from type in clang implementation,
but OpenCL spec provides a special query to get access qualifier
via clGetKernelArgInfo with CL_KERNEL_ARG_ACCESS_QUALIFIER.

Besides that OpenCL conformance test_api get_kernel_arg_info expects
image types without access qualifier.

Patch by Evgeniy Tyurin.

Reviewers: bader, yaxunl, Anastasia

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D23915


Modified:
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=280699=280698=280699=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Sep  6 05:10:28 2016
@@ -428,6 +428,26 @@ void CodeGenFunction::EmitFunctionInstru
   EmitNounwindRuntimeCall(F, args);
 }
 
+static void removeImageAccessQualifier(std::string& TyName) {
+  std::string ReadOnlyQual("__read_only");
+  std::string::size_type ReadOnlyPos = TyName.find(ReadOnlyQual);
+  if (ReadOnlyPos != std::string::npos)
+// "+ 1" for the space after access qualifier.
+TyName.erase(ReadOnlyPos, ReadOnlyQual.size() + 1);
+  else {
+std::string WriteOnlyQual("__write_only");
+std::string::size_type WriteOnlyPos = TyName.find(WriteOnlyQual);
+if (WriteOnlyPos != std::string::npos)
+  TyName.erase(WriteOnlyPos, WriteOnlyQual.size() + 1);
+else {
+  std::string ReadWriteQual("__read_write");
+  std::string::size_type ReadWritePos = TyName.find(ReadWriteQual);
+  if (ReadWritePos != std::string::npos)
+TyName.erase(ReadWritePos, ReadWriteQual.size() + 1);
+}
+  }
+}
+
 // OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
 // information in the program executable. The argument information stored
 // includes the argument name, its type, the address and access qualifiers 
used.
@@ -524,8 +544,6 @@ static void GenOpenCLArgMetadata(const F
   if (ty.isCanonical() && pos != std::string::npos)
 typeName.erase(pos+1, 8);
 
-  argTypeNames.push_back(llvm::MDString::get(Context, typeName));
-
   std::string baseTypeName;
   if (isPipe)
 baseTypeName = ty.getCanonicalType()->getAs()
@@ -535,6 +553,17 @@ static void GenOpenCLArgMetadata(const F
 baseTypeName =
   ty.getUnqualifiedType().getCanonicalType().getAsString(Policy);
 
+  // Remove access qualifiers on images
+  // (as they are inseparable from type in clang implementation,
+  // but OpenCL spec provides a special query to get access qualifier
+  // via clGetKernelArgInfo with CL_KERNEL_ARG_ACCESS_QUALIFIER):
+  if (ty->isImageType()) {
+removeImageAccessQualifier(typeName);
+removeImageAccessQualifier(baseTypeName);
+  }
+
+  argTypeNames.push_back(llvm::MDString::get(Context, typeName));
+
   // Turn "unsigned type" to "utype"
   pos = baseTypeName.find("unsigned");
   if (pos != std::string::npos)

Modified: cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl?rev=280699=280698=280699=diff
==
--- cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl Tue Sep  6 05:10:28 2016
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck 
%s
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown 
-cl-kernel-arg-info | FileCheck %s -check-prefix ARGINFO
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple 
spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -triple 
spir-unknown-unknown -cl-kernel-arg-info | FileCheck %s -check-prefix ARGINFO
 
 kernel void foo(__global int * restrict X, const int Y, 
 volatile int anotherArg, __constant float * restrict Z) {
@@ -14,7 +14,7 @@ kernel void foo(__global int * restrict
 // CHECK-NOT: !kernel_arg_name
 // ARGINFO: !kernel_arg_name ![[MD15:[0-9]+]]
 
-kernel void foo2(read_only image1d_t img1, image2d_t img2, write_only 
image2d_array_t img3) {
+kernel void foo2(read_only image1d_t img1, image2d_t img2, write_only 
image2d_array_t img3, read_write image1d_t img4) {
 }
 // CHECK: define spir_kernel void @foo2{{[^!]+}}
 // CHECK: !kernel_arg_addr_space ![[MD21:[0-9]+]]
@@ -65,11 +65,11 @@ kernel void foo5(myImage img1, 

Re: [PATCH] D24136: [OpenCL] Fix pipe built-in functions return type.

2016-09-06 Thread Alexey Bader via cfe-commits
bader updated this revision to Diff 70368.
bader added a comment.

Added get_pipe_num_packets and get_pipe_max_packets test cases.


https://reviews.llvm.org/D24136

Files:
  lib/Sema/SemaChecking.cpp
  test/CodeGenOpenCL/pipe_builtin.cl

Index: test/CodeGenOpenCL/pipe_builtin.cl
===
--- test/CodeGenOpenCL/pipe_builtin.cl
+++ test/CodeGenOpenCL/pipe_builtin.cl
@@ -59,3 +59,19 @@
   // CHECK: call i32 @__get_pipe_max_packets(%opencl.pipe_t* %{{.*}})
   *ptr = get_pipe_max_packets(p);
 }
+
+void test8(read_only pipe int r, write_only pipe int w, global int *ptr) {
+  // verify that return type is correctly casted to i1 value
+  // CHECK: %[[R:[0-9]+]] = call i32 @__read_pipe_2
+  // CHECK: icmp ne i32 %[[R]], 0
+  if (read_pipe(r, ptr)) *ptr = -1;
+  // CHECK: %[[W:[0-9]+]] = call i32 @__write_pipe_2
+  // CHECK: icmp ne i32 %[[W]], 0
+  if (write_pipe(w, ptr)) *ptr = -1;
+  // CHECK: %[[N:[0-9]+]] = call i32 @__get_pipe_num_packets
+  // CHECK: icmp ne i32 %[[N]], 0
+  if (get_pipe_num_packets(r)) *ptr = -1;
+  // CHECK: %[[M:[0-9]+]] = call i32 @__get_pipe_max_packets
+  // CHECK: icmp ne i32 %[[M]], 0
+  if (get_pipe_max_packets(w)) *ptr = -1;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1020,6 +1020,7 @@
 // check for the argument.
 if (SemaBuiltinRWPipe(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.IntTy);
 break;
   case Builtin::BIreserve_read_pipe:
   case Builtin::BIreserve_write_pipe:
@@ -1047,6 +1048,7 @@
   case Builtin::BIget_pipe_max_packets:
 if (SemaBuiltinPipePackets(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.UnsignedIntTy);
 break;
   case Builtin::BIto_global:
   case Builtin::BIto_local:


Index: test/CodeGenOpenCL/pipe_builtin.cl
===
--- test/CodeGenOpenCL/pipe_builtin.cl
+++ test/CodeGenOpenCL/pipe_builtin.cl
@@ -59,3 +59,19 @@
   // CHECK: call i32 @__get_pipe_max_packets(%opencl.pipe_t* %{{.*}})
   *ptr = get_pipe_max_packets(p);
 }
+
+void test8(read_only pipe int r, write_only pipe int w, global int *ptr) {
+  // verify that return type is correctly casted to i1 value
+  // CHECK: %[[R:[0-9]+]] = call i32 @__read_pipe_2
+  // CHECK: icmp ne i32 %[[R]], 0
+  if (read_pipe(r, ptr)) *ptr = -1;
+  // CHECK: %[[W:[0-9]+]] = call i32 @__write_pipe_2
+  // CHECK: icmp ne i32 %[[W]], 0
+  if (write_pipe(w, ptr)) *ptr = -1;
+  // CHECK: %[[N:[0-9]+]] = call i32 @__get_pipe_num_packets
+  // CHECK: icmp ne i32 %[[N]], 0
+  if (get_pipe_num_packets(r)) *ptr = -1;
+  // CHECK: %[[M:[0-9]+]] = call i32 @__get_pipe_max_packets
+  // CHECK: icmp ne i32 %[[M]], 0
+  if (get_pipe_max_packets(w)) *ptr = -1;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1020,6 +1020,7 @@
 // check for the argument.
 if (SemaBuiltinRWPipe(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.IntTy);
 break;
   case Builtin::BIreserve_read_pipe:
   case Builtin::BIreserve_write_pipe:
@@ -1047,6 +1048,7 @@
   case Builtin::BIget_pipe_max_packets:
 if (SemaBuiltinPipePackets(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.UnsignedIntTy);
 break;
   case Builtin::BIto_global:
   case Builtin::BIto_local:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23992: [OpenCL] Augment pipe built-ins with pipe packet size and alignment.

2016-09-06 Thread Alexey Bader via cfe-commits
bader updated this revision to Diff 70366.
bader added a comment.

Applied code review comment from Anastasia.

Use getTypeSizeInChars instead of getTypeSize to get type size in bytes. Assume 
that char size is always one byte.


https://reviews.llvm.org/D23992

Files:
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp
  lib/CodeGen/CGOpenCLRuntime.h
  test/CodeGenOpenCL/pipe_builtin.cl
  test/CodeGenOpenCL/pipe_types.cl

Index: test/CodeGenOpenCL/pipe_types.cl
===
--- test/CodeGenOpenCL/pipe_types.cl
+++ test/CodeGenOpenCL/pipe_types.cl
@@ -41,7 +41,7 @@
  read_only pipe struct Person SPipe) {
 // CHECK: define void @test_reserved_read_pipe
   read_pipe (SPipe, SDst);
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
   read_pipe (SPipe, SDst);
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
 }
Index: test/CodeGenOpenCL/pipe_builtin.cl
===
--- test/CodeGenOpenCL/pipe_builtin.cl
+++ test/CodeGenOpenCL/pipe_builtin.cl
@@ -4,58 +4,58 @@
 // CHECK: %opencl.reserve_id_t = type opaque
 
 void test1(read_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
   read_pipe(p, ptr);
-  // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_read_pipe(p, 2);
-  // CHECK: call i32 @__read_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}}, i32 4, i32 4)
   read_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   commit_read_pipe(p, rid);
 }
 
 void test2(write_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__write_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__write_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
   write_pipe(p, ptr);
-  // CHECK: call %opencl.reserve_id_t* @__reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_write_pipe(p, 2);
-  // CHECK: call i32 @__write_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__write_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}}, i32 4, i32 4)
   write_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   commit_write_pipe(p, rid);
 }
 
 void test3(read_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = work_group_reserve_read_pipe(p, 2);
-  // CHECK: call void @__work_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__work_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   work_group_commit_read_pipe(p, rid);
 }
 
 void test4(write_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = work_group_reserve_write_pipe(p, 2);
-  // CHECK: call void @__work_group_commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__work_group_commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   work_group_commit_write_pipe(p, rid);
 }
 
 void test5(read_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__sub_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__sub_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   

Re: [PATCH] D24054: Do not validate pch when -fno-validate-pch is set

2016-09-04 Thread Alexey Bader via cfe-commits
bader added a comment.

Could you a regression test, please?


https://reviews.llvm.org/D24054



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


[PATCH] D24136: [OpenCL] Fix pipe built-in functions return type.

2016-09-01 Thread Alexey Bader via cfe-commits
bader created this revision.
bader added a reviewer: Anastasia.
bader added subscribers: yaxunl, cfe-commits.

By default return type of call expressions calling built-in
functions is set to bool.

Fixes https://llvm.org/bugs/show_bug.cgi?id=30219.

https://reviews.llvm.org/D24136

Files:
  lib/Sema/SemaChecking.cpp
  test/CodeGenOpenCL/pipe_builtin.cl

Index: test/CodeGenOpenCL/pipe_builtin.cl
===
--- test/CodeGenOpenCL/pipe_builtin.cl
+++ test/CodeGenOpenCL/pipe_builtin.cl
@@ -59,3 +59,13 @@
   // CHECK: call i32 @__get_pipe_max_packets(%opencl.pipe_t* %{{.*}})
   *ptr = get_pipe_max_packets(p);
 }
+
+void test8(read_only pipe int r, write_only pipe int w, global int *ptr) {
+  // verify that return type is correctly casted to i1 value
+  // CHECK: %[[R:[0-9]+]] = call i32 @__read_pipe_2
+  // CHECK: icmp ne i32 %[[R]], 0
+  if (read_pipe(r, ptr)) *ptr = -1;
+  // CHECK: %[[W:[0-9]+]] = call i32 @__write_pipe_2
+  // CHECK: icmp ne i32 %[[W]], 0
+  if (write_pipe(w, ptr)) *ptr = -1;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1020,6 +1020,7 @@
 // check for the argument.
 if (SemaBuiltinRWPipe(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.IntTy);
 break;
   case Builtin::BIreserve_read_pipe:
   case Builtin::BIreserve_write_pipe:
@@ -1047,6 +1048,7 @@
   case Builtin::BIget_pipe_max_packets:
 if (SemaBuiltinPipePackets(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.UnsignedIntTy);
 break;
   case Builtin::BIto_global:
   case Builtin::BIto_local:


Index: test/CodeGenOpenCL/pipe_builtin.cl
===
--- test/CodeGenOpenCL/pipe_builtin.cl
+++ test/CodeGenOpenCL/pipe_builtin.cl
@@ -59,3 +59,13 @@
   // CHECK: call i32 @__get_pipe_max_packets(%opencl.pipe_t* %{{.*}})
   *ptr = get_pipe_max_packets(p);
 }
+
+void test8(read_only pipe int r, write_only pipe int w, global int *ptr) {
+  // verify that return type is correctly casted to i1 value
+  // CHECK: %[[R:[0-9]+]] = call i32 @__read_pipe_2
+  // CHECK: icmp ne i32 %[[R]], 0
+  if (read_pipe(r, ptr)) *ptr = -1;
+  // CHECK: %[[W:[0-9]+]] = call i32 @__write_pipe_2
+  // CHECK: icmp ne i32 %[[W]], 0
+  if (write_pipe(w, ptr)) *ptr = -1;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1020,6 +1020,7 @@
 // check for the argument.
 if (SemaBuiltinRWPipe(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.IntTy);
 break;
   case Builtin::BIreserve_read_pipe:
   case Builtin::BIreserve_write_pipe:
@@ -1047,6 +1048,7 @@
   case Builtin::BIget_pipe_max_packets:
 if (SemaBuiltinPipePackets(*this, TheCall))
   return ExprError();
+TheCall->setType(Context.UnsignedIntTy);
 break;
   case Builtin::BIto_global:
   case Builtin::BIto_local:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r280097 - [OpenCL] Make is_valid_event, create_user_event overloadable.

2016-08-30 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Aug 30 09:42:54 2016
New Revision: 280097

URL: http://llvm.org/viewvc/llvm-project?rev=280097=rev
Log:
[OpenCL] Make is_valid_event, create_user_event overloadable.

Summary: Make is_valid_event and create_user_event overloadable like other 
built-ins.

Patch by Evgeniy Tyurin.

Reviewers: bader, yaxunl

Subscribers: Anastasia, cfe-commits

Differential Revision: https://reviews.llvm.org/D23914


Modified:
cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=280097=280096=280097=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Tue Aug 30 09:42:54 2016
@@ -16729,11 +16729,11 @@ void __ovld retain_event(clk_event_t);
 
 void __ovld release_event(clk_event_t);
 
-clk_event_t create_user_event(void);
+clk_event_t __ovld create_user_event(void);
 
 void __ovld set_user_event_status(clk_event_t e, int state);
 
-bool is_valid_event (clk_event_t event);
+bool __ovld is_valid_event (clk_event_t event);
 
 void __ovld capture_event_profiling_info(clk_event_t, clk_profiling_info, 
__global void* value);
 


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


Re: [PATCH] D23914: [OpenCL] Make is_valid_event, create_user_event overloadable.

2016-08-30 Thread Alexey Bader via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL280097: [OpenCL] Make is_valid_event, create_user_event 
overloadable. (authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D23914?vs=69650=69682#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23914

Files:
  cfe/trunk/lib/Headers/opencl-c.h

Index: cfe/trunk/lib/Headers/opencl-c.h
===
--- cfe/trunk/lib/Headers/opencl-c.h
+++ cfe/trunk/lib/Headers/opencl-c.h
@@ -16729,11 +16729,11 @@
 
 void __ovld release_event(clk_event_t);
 
-clk_event_t create_user_event(void);
+clk_event_t __ovld create_user_event(void);
 
 void __ovld set_user_event_status(clk_event_t e, int state);
 
-bool is_valid_event (clk_event_t event);
+bool __ovld is_valid_event (clk_event_t event);
 
 void __ovld capture_event_profiling_info(clk_event_t, clk_profiling_info, 
__global void* value);
 


Index: cfe/trunk/lib/Headers/opencl-c.h
===
--- cfe/trunk/lib/Headers/opencl-c.h
+++ cfe/trunk/lib/Headers/opencl-c.h
@@ -16729,11 +16729,11 @@
 
 void __ovld release_event(clk_event_t);
 
-clk_event_t create_user_event(void);
+clk_event_t __ovld create_user_event(void);
 
 void __ovld set_user_event_status(clk_event_t e, int state);
 
-bool is_valid_event (clk_event_t event);
+bool __ovld is_valid_event (clk_event_t event);
 
 void __ovld capture_event_profiling_info(clk_event_t, clk_profiling_info, __global void* value);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23992: [OpenCL] Augment pipe built-ins with pipe packet size and alignment.

2016-08-29 Thread Alexey Bader via cfe-commits
bader created this revision.
bader added reviewers: Anastasia, vpykhtin.
bader added a subscriber: cfe-commits.

Keep pipe packet size and alignment in LLVM IR layer to enable
translation from LLVM IR to SPIR-V format.

https://reviews.llvm.org/D23992

Files:
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp
  lib/CodeGen/CGOpenCLRuntime.h
  test/CodeGenOpenCL/pipe_builtin.cl
  test/CodeGenOpenCL/pipe_types.cl

Index: test/CodeGenOpenCL/pipe_types.cl
===
--- test/CodeGenOpenCL/pipe_types.cl
+++ test/CodeGenOpenCL/pipe_types.cl
@@ -41,7 +41,7 @@
  read_only pipe struct Person SPipe) {
 // CHECK: define void @test_reserved_read_pipe
   read_pipe (SPipe, SDst);
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
   read_pipe (SPipe, SDst);
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
 }
Index: test/CodeGenOpenCL/pipe_builtin.cl
===
--- test/CodeGenOpenCL/pipe_builtin.cl
+++ test/CodeGenOpenCL/pipe_builtin.cl
@@ -4,58 +4,58 @@
 // CHECK: %opencl.reserve_id_t = type opaque
 
 void test1(read_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
   read_pipe(p, ptr);
-  // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_read_pipe(p, 2);
-  // CHECK: call i32 @__read_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__read_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}}, i32 4, i32 4)
   read_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   commit_read_pipe(p, rid);
 }
 
 void test2(write_only pipe int p, global int *ptr) {
-  // CHECK: call i32 @__write_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__write_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
   write_pipe(p, ptr);
-  // CHECK: call %opencl.reserve_id_t* @__reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = reserve_write_pipe(p, 2);
-  // CHECK: call i32 @__write_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}})
+  // CHECK: call i32 @__write_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8* %{{.*}}, i32 4, i32 4)
   write_pipe(p, rid, 2, ptr);
-  // CHECK: call void @__commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   commit_write_pipe(p, rid);
 }
 
 void test3(read_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = work_group_reserve_read_pipe(p, 2);
-  // CHECK: call void @__work_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__work_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   work_group_commit_read_pipe(p, rid);
 }
 
 void test4(write_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__work_group_reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = work_group_reserve_write_pipe(p, 2);
-  // CHECK: call void @__work_group_commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}})
+  // CHECK: call void @__work_group_commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 4, i32 4)
   work_group_commit_write_pipe(p, rid);
 }
 
 void test5(read_only pipe int p, global int *ptr) {
-  // CHECK: call %opencl.reserve_id_t* @__sub_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}})
+  // CHECK: call %opencl.reserve_id_t* @__sub_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}, i32 4, i32 4)
   reserve_id_t rid = 

Re: [PATCH] D23915: [OpenCL] Remove access qualifiers on images in arg info metadata.

2016-08-26 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D23915



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


Re: [PATCH] D23914: [OpenCL] Make is_valid_event overloadable.

2016-08-26 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D23914



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


Re: [PATCH] D23120: [OpenCL] Added underscores to the names of 'to_addr' OpenCL built-ins.

2016-08-04 Thread Alexey Bader via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277743: [OpenCL] Added underscores to the names of 'to_addr' 
OpenCL built-ins. (authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D23120?vs=66653=66832#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23120

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl

Index: cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl
===
--- cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl
+++ cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl
@@ -14,74 +14,74 @@
   generic int *gen;
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(glob);
   
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(loc);
  
   //CHECK: %[[ARG:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(priv);
  
   //CHECK: %[[ARG:.*]] = bitcast i32 addrspace(4)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(gen);
   
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(glob);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(loc);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(priv);
 
   //CHECK: %[[ARG:.*]] = bitcast i32 addrspace(4)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(gen);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8* @to_private(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8* @__to_private(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8* %[[RET]] to i32*
   priv = to_private(glob);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8* @to_private(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8* @__to_private(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8* %[[RET]] to i32*
   priv = to_private(loc);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8* @to_private(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8* @__to_private(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8* %[[RET]] to i32*
   priv = to_private(priv);
 
   //CHECK: %[[ARG:.*]] = bitcast i32 addrspace(4)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8* @to_private(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8* @__to_private(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8* %[[RET]] to i32*
   priv = to_private(gen);
 
   //CHECK: %[[ARG:.*]] = addrspacecast %[[A]]* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: 

r277743 - [OpenCL] Added underscores to the names of 'to_addr' OpenCL built-ins.

2016-08-04 Thread Alexey Bader via cfe-commits
Author: bader
Date: Thu Aug  4 13:06:27 2016
New Revision: 277743

URL: http://llvm.org/viewvc/llvm-project?rev=277743=rev
Log:
[OpenCL] Added underscores to the names of 'to_addr' OpenCL built-ins.

Summary:
In order to re-define OpenCL built-in functions
'to_{private,local,global}' in OpenCL run-time library LLVM names must
be different from the clang built-in function names.

Reviewers: yaxunl, Anastasia

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D23120

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=277743=277742=277743=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Aug  4 13:06:27 2016
@@ -2209,8 +2209,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   NewArg = Builder.CreateAddrSpaceCast(Arg0, NewArgT);
 else
   NewArg = Builder.CreateBitOrPointerCast(Arg0, NewArgT);
-auto NewCall = Builder.CreateCall(CGM.CreateRuntimeFunction(FTy,
-  E->getDirectCallee()->getName()), {NewArg});
+auto NewName = std::string("__") + E->getDirectCallee()->getName().str();
+auto NewCall =
+Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, NewName), {NewArg});
 return RValue::get(Builder.CreateBitOrPointerCast(NewCall,
   ConvertType(E->getType(;
   }

Modified: cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl?rev=277743=277742=277743=diff
==
--- cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl Thu Aug  4 13:06:27 2016
@@ -14,74 +14,74 @@ void test(void) {
   generic int *gen;
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 
addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* 
%[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* 
%[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(glob);
   
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 
addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* 
%[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* 
%[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(loc);
  
   //CHECK: %[[ARG:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* 
%[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* 
%[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(priv);
  
   //CHECK: %[[ARG:.*]] = bitcast i32 addrspace(4)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* 
%[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* 
%[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(gen);
   
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 
addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* 
%[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* 
%[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(glob);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 
addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* 
%[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* 
%[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(loc);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* 
%[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* 
%[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(priv);
 
   //CHECK: %[[ARG:.*]] = bitcast i32 addrspace(4)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* 
%[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* 
%[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(gen);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 
addrspace(4)*
-  

[PATCH] D23120: [OpenCL] Added underscores to the names of 'to_addr' OpenCL built-ins.

2016-08-03 Thread Alexey Bader via cfe-commits
bader created this revision.
bader added reviewers: Anastasia, yaxunl.
bader added a subscriber: cfe-commits.

In order to re-define OpenCL built-in functions
'to_{private,local,global}' in OpenCL run-time library LLVM names must
be different from the clang built-in function names.

https://reviews.llvm.org/D23120

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/to_addr_builtin.cl

Index: test/CodeGenOpenCL/to_addr_builtin.cl
===
--- test/CodeGenOpenCL/to_addr_builtin.cl
+++ test/CodeGenOpenCL/to_addr_builtin.cl
@@ -14,74 +14,74 @@
   generic int *gen;
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(glob);
   
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(loc);
  
   //CHECK: %[[ARG:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(priv);
  
   //CHECK: %[[ARG:.*]] = bitcast i32 addrspace(4)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(1)* %[[RET]] to i32 addrspace(1)*
   glob = to_global(gen);
   
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(glob);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(loc);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(priv);
 
   //CHECK: %[[ARG:.*]] = bitcast i32 addrspace(4)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @to_local(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(3)* @__to_local(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8 addrspace(3)* %[[RET]] to i32 addrspace(3)*
   loc = to_local(gen);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(1)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8* @to_private(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8* @__to_private(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8* %[[RET]] to i32*
   priv = to_private(glob);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32 addrspace(3)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8* @to_private(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8* @__to_private(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8* %[[RET]] to i32*
   priv = to_private(loc);
 
   //CHECK: %[[ARG:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8* @to_private(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8* @__to_private(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8* %[[RET]] to i32*
   priv = to_private(priv);
 
   //CHECK: %[[ARG:.*]] = bitcast i32 addrspace(4)* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8* @to_private(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8* @__to_private(i8 addrspace(4)* %[[ARG]])
   //CHECK: %{{.*}} = bitcast i8* %[[RET]] to i32*
   priv = to_private(gen);
 
   //CHECK: %[[ARG:.*]] = addrspacecast %[[A]]* %{{.*}} to i8 addrspace(4)*
-  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @to_global(i8 addrspace(4)* %[[ARG]])
+  //CHECK: %[[RET:.*]] = call i8 addrspace(1)* @__to_global(i8 addrspace(4)* 

Re: [PATCH] D23086: [OpenCL] Generate concrete struct type for ndrange_t

2016-08-03 Thread Alexey Bader via cfe-commits
bader added inline comments.


Comment at: test/CodeGenOpenCL/cl20-device-side-enqueue.cl:12
@@ -11,3 +11,3 @@
   unsigned flags = 0;
-  // CHECK: %ndrange = alloca %opencl.ndrange_t*
+  // CHECK: %ndrange = alloca %ndrange_t
   ndrange_t ndrange;

Could you also add a regression test to validate that ndrange_t is defined in 
LLVM as struct type, please?


Repository:
  rL LLVM

https://reviews.llvm.org/D23086



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


Re: [PATCH] D20948: [OpenCL] Fix access qualifiers handling for typedefs

2016-07-08 Thread Alexey Bader via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL274858: [OpenCL] Fix access qualifiers handling for typedefs 
(authored by bader).

Changed prior to commit:
  http://reviews.llvm.org/D20948?vs=63222=63235#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20948

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/AttributeList.h
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
  cfe/trunk/test/SemaOpenCL/access-qualifier.cl
  cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl

Index: cfe/trunk/include/clang/Sema/AttributeList.h
===
--- cfe/trunk/include/clang/Sema/AttributeList.h
+++ cfe/trunk/include/clang/Sema/AttributeList.h
@@ -880,6 +880,7 @@
   ExpectedMethod,
   ExpectedFieldOrGlobalVar,
   ExpectedStruct,
+  ExpectedParameterOrTypedef,
   ExpectedVariableOrTypedef,
   ExpectedTLSVar,
   ExpectedVariableOrField,
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -688,7 +688,8 @@
   let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
Keyword<"__write_only">, Keyword<"write_only">,
Keyword<"__read_write">, Keyword<"read_write">];
-  let Subjects = SubjectList<[ParmVar], ErrorDiag>;
+  let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag,
+ "ExpectedParameterOrTypedef">;
   let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
Keyword<"read_only">]>,
Accessor<"isReadWrite", [Keyword<"__read_write">,
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2506,8 +2506,8 @@
   "variables and functions|functions and methods|parameters|"
   "functions, methods and blocks|functions, methods, and classes|"
   "functions, methods, and parameters|classes|enums|variables|methods|"
-  "fields and global variables|structs|variables and typedefs|thread-local variables|"
-  "variables and fields|variables, data members and tag types|"
+  "fields and global variables|structs|parameters and typedefs|variables and typedefs|"
+  "thread-local variables|variables and fields|variables, data members and tag types|"
   "types and namespaces|Objective-C interfaces|methods and properties|"
   "struct or union|struct, union or class|types|"
   "Objective-C instance methods|init methods of interface or class extension declarations|"
@@ -7923,9 +7923,11 @@
 def err_opencl_invalid_access_qualifier : Error<
   "access qualifier can only be used for pipe and image type">;
 def err_opencl_invalid_read_write : Error<
-  "access qualifier %0 can not be used for %1 %select{|earlier than OpenCL version 2.0}2">;
+  "access qualifier %0 can not be used for %1 %select{|prior to OpenCL version 2.0}2">;
 def err_opencl_multiple_access_qualifiers : Error<
   "multiple access qualifiers">;
+def note_opencl_typedef_access_qualifier : Note<
+  "previously declared '%0' here">;
 
 // OpenCL Section 6.8.g
 def err_opencl_unknown_type_specifier : Error<
Index: cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
===
--- cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
+++ cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl
@@ -49,7 +49,7 @@
 // ARGINFO: !kernel_arg_name ![[MD46:[0-9]+]]
 
 typedef image1d_t myImage;
-kernel void foo5(read_only myImage img1, write_only image1d_t img2) {
+kernel void foo5(myImage img1, write_only image1d_t img2) {
 }
 // CHECK: define spir_kernel void @foo5{{[^!]+}}
 // CHECK: !kernel_arg_addr_space ![[MD41:[0-9]+]]
Index: cfe/trunk/test/SemaOpenCL/access-qualifier.cl
===
--- cfe/trunk/test/SemaOpenCL/access-qualifier.cl
+++ cfe/trunk/test/SemaOpenCL/access-qualifier.cl
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s
+// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s
+
+typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}}
+
+typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}}
+typedef read_only image1d_t img1d_ro;
+
+#if __OPENCL_C_VERSION__ >= 200
+typedef read_write image1d_t img1d_rw;
+#endif
+
+typedef int Int;
+typedef read_only int IntRO; // expected-error {{access qualifier can only be used for pipe and image type}}
+
+
+void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing 

r274858 - [OpenCL] Fix access qualifiers handling for typedefs

2016-07-08 Thread Alexey Bader via cfe-commits
Author: bader
Date: Fri Jul  8 10:34:59 2016
New Revision: 274858

URL: http://llvm.org/viewvc/llvm-project?rev=274858=rev
Log:
[OpenCL] Fix access qualifiers handling for typedefs

OpenCL s6.6: "Access qualifier must be used with image object arguments
of kernels and of user-defined functions [...] If no qualifier is
provided, read_only is assumed".

This does not define the behavior for image types used in typedef
declaration, but following the spec logic, we should allow access
qualifiers specification in typedefs, e.g.:

  typedef write_only image1d_t img1d_wo;

Unlike cv-qualifiers, user cannot add access qualifier to a typedef
type, i.e. this is not allowed:

  typedef image1d_t img1d; // note: previously declared 'read_only' here
  void foo(write_only img1d im) {} // error: multiple access qualifier

Patch by Andrew Savonichev.
Reviewers: Anastasia Stulova.

Differential revision: http://reviews.llvm.org/D20948

Added:
cfe/trunk/test/SemaOpenCL/access-qualifier.cl
Removed:
cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=274858=274857=274858=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Fri Jul  8 10:34:59 2016
@@ -688,7 +688,8 @@ def OpenCLAccess : Attr {
   let Spellings = [Keyword<"__read_only">, Keyword<"read_only">,
Keyword<"__write_only">, Keyword<"write_only">,
Keyword<"__read_write">, Keyword<"read_write">];
-  let Subjects = SubjectList<[ParmVar], ErrorDiag>;
+  let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag,
+ "ExpectedParameterOrTypedef">;
   let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">,
Keyword<"read_only">]>,
Accessor<"isReadWrite", [Keyword<"__read_write">,

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=274858=274857=274858=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul  8 10:34:59 
2016
@@ -2506,8 +2506,8 @@ def warn_attribute_wrong_decl_type : War
   "variables and functions|functions and methods|parameters|"
   "functions, methods and blocks|functions, methods, and classes|"
   "functions, methods, and parameters|classes|enums|variables|methods|"
-  "fields and global variables|structs|variables and typedefs|thread-local 
variables|"
-  "variables and fields|variables, data members and tag types|"
+  "fields and global variables|structs|parameters and typedefs|variables and 
typedefs|"
+  "thread-local variables|variables and fields|variables, data members and tag 
types|"
   "types and namespaces|Objective-C interfaces|methods and properties|"
   "struct or union|struct, union or class|types|"
   "Objective-C instance methods|init methods of interface or class extension 
declarations|"
@@ -7923,9 +7923,11 @@ def err_opencl_builtin_pipe_invalid_acce
 def err_opencl_invalid_access_qualifier : Error<
   "access qualifier can only be used for pipe and image type">;
 def err_opencl_invalid_read_write : Error<
-  "access qualifier %0 can not be used for %1 %select{|earlier than OpenCL 
version 2.0}2">;
+  "access qualifier %0 can not be used for %1 %select{|prior to OpenCL version 
2.0}2">;
 def err_opencl_multiple_access_qualifiers : Error<
   "multiple access qualifiers">;
+def note_opencl_typedef_access_qualifier : Note<
+  "previously declared '%0' here">;
 
 // OpenCL Section 6.8.g
 def err_opencl_unknown_type_specifier : Error<

Modified: cfe/trunk/include/clang/Sema/AttributeList.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=274858=274857=274858=diff
==
--- cfe/trunk/include/clang/Sema/AttributeList.h (original)
+++ cfe/trunk/include/clang/Sema/AttributeList.h Fri Jul  8 10:34:59 2016
@@ -880,6 +880,7 @@ enum AttributeDeclKind {
   ExpectedMethod,
   ExpectedFieldOrGlobalVar,
   ExpectedStruct,
+  ExpectedParameterOrTypedef,
   ExpectedVariableOrTypedef,
   ExpectedTLSVar,
   ExpectedVariableOrField,

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=274858=274857=274858=diff

Re: [PATCH] D21989: [OpenCL] Improve diagnostics of OpenCL types

2016-07-05 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a comment.
This revision is now accepted and ready to land.

LGTM.
A few minor style comments.



Comment at: lib/Sema/SemaExpr.cpp:10806-10807
@@ -10816,4 +10805,4 @@
 // the ATOMIC_VAR_INIT macro.
 if (LHSExpr->getType()->isAtomicType() ||
 RHSExpr->getType()->isAtomicType()) {
   SourceRange SR(LHSExpr->getLocStart(), RHSExpr->getLocEnd());

Please, refactor this code to use LHSTy & RHSTy.


Comment at: lib/Sema/SemaType.cpp:3832
@@ -3829,1 +3831,3 @@
+if (LangOpts.OpenCL)
+  DeclType.Cls.TypeQuals|=DeclSpec::TQ_const;
 T = S.BuildQualifiedType(T, DeclType.Loc, DeclType.Cls.TypeQuals);

Please, add spaces around |=.


Comment at: test/SemaOpenCL/invalid-pipes-cl2.0.cl:10
@@ -9,2 +9,3 @@
 void test4() {
-  pipe int p; // expected-error {{type 'pipe int' can only be used as a 
function parameter}}
+  pipe int p; // expected-error {{type 'pipe int' can only be used as a 
function parameter}}gedit test.cl
+  //TODO: fix parsing of this pipe int (*p);

Please, remove 'gedit test.cl' at the end of the line.


Comment at: test/SemaOpenCL/sampler_t.cl:22
@@ +21,3 @@
+
+void bar(){
+  sampler_t smp1 = 7;

Please, add space before {.


http://reviews.llvm.org/D21989



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


Re: [PATCH] D21744: [OpenCL] Fix code generation of kernel pipe parameters.

2016-07-04 Thread Alexey Bader via cfe-commits
bader added a comment.

Ping.
Xiuli, do you have any comments?


http://reviews.llvm.org/D21744



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


Re: [PATCH] D20249: [OpenCL] Hierarchical/dynamic parallelism - enqueue kernel in OpenCL 2.0

2016-07-01 Thread Alexey Bader via cfe-commits
bader added a comment.

LGTM!
Thanks a lot for working on this.


http://reviews.llvm.org/D20249



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


Re: [PATCH] D20249: [OpenCL] Hierarchical/dynamic parallelism - enqueue kernel in OpenCL 2.0

2016-07-01 Thread Alexey Bader via cfe-commits
bader added inline comments.


Comment at: lib/Sema/SemaChecking.cpp:6773-6774
@@ -6772,4 +7016,2 @@
 
-namespace {
-
 /// Structure recording the 'active' range of an integer-valued

The con of this change - it will export all the symbols from this unnamed 
namespace.
The better approach would be to move the code that uses CheckImplicitConversion 
method below this namespace.


http://reviews.llvm.org/D20249



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


r274120 - [OpenCL] Fix typo in as_type test.

2016-06-29 Thread Alexey Bader via cfe-commits
Author: bader
Date: Wed Jun 29 07:25:58 2016
New Revision: 274120

URL: http://llvm.org/viewvc/llvm-project?rev=274120=rev
Log:
[OpenCL] Fix typo in as_type test.

Reset astype variable in f6 function to avoid matching with wrong value from f5 
function.

Modified:
cfe/trunk/test/CodeGenOpenCL/as_type.cl

Modified: cfe/trunk/test/CodeGenOpenCL/as_type.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/as_type.cl?rev=274120=274119=274120=diff
==
--- cfe/trunk/test/CodeGenOpenCL/as_type.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/as_type.cl Wed Jun 29 07:25:58 2016
@@ -44,7 +44,7 @@ int f5(char3 x) {
 }
 
 //CHECK: define spir_func i32 @f6(<4 x i8> %[[x:.*]])
-//CHECK: %[[astype]] = bitcast <4 x i8> %[[x]] to i32
+//CHECK: %[[astype:.*]] = bitcast <4 x i8> %[[x]] to i32
 //CHECK-NOT: shufflevector
 //CHECK: ret i32 %[[astype]]
 int f6(char4 x) {


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


Re: [PATCH] D21744: [OpenCL] Fix code generation of kernel pipe parameters.

2016-06-28 Thread Alexey Bader via cfe-commits
bader updated this revision to Diff 62100.
bader added a comment.

Re-format the patch.
No functional changes.


http://reviews.llvm.org/D21744

Files:
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGenOpenCL/pipe_types.cl

Index: test/CodeGenOpenCL/pipe_types.cl
===
--- test/CodeGenOpenCL/pipe_types.cl
+++ test/CodeGenOpenCL/pipe_types.cl
@@ -25,3 +25,23 @@
 void test5(read_only pipe int4 p) {
 // CHECK: define void @test5(%opencl.pipe_t* %p)
 }
+
+typedef pipe int MyPipe;
+kernel void test6(read_only MyPipe p) {
+// CHECK: define void @test6(%opencl.pipe_t* %p)
+}
+
+struct Person {
+  const char *Name;
+  bool isFemale;
+  int ID;
+};
+
+void test_reserved_read_pipe(global struct Person *SDst,
+ read_only pipe struct Person SPipe) {
+// CHECK: define void @test_reserved_read_pipe
+  read_pipe (SPipe, SDst);
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  read_pipe (SPipe, SDst);
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+}
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -516,7 +516,8 @@
   // Get argument type name.
   std::string typeName;
   if (isPipe)
-typeName = cast(ty)->getElementType().getAsString(Policy);
+typeName = ty.getCanonicalType()->getAs()->getElementType()
+ .getAsString(Policy);
   else
 typeName = ty.getUnqualifiedType().getAsString(Policy);
 
@@ -529,8 +530,9 @@
 
   std::string baseTypeName;
   if (isPipe)
-baseTypeName =
-  
cast(ty)->getElementType().getCanonicalType().getAsString(Policy);
+baseTypeName = ty.getCanonicalType()->getAs()
+  ->getElementType().getCanonicalType()
+  .getAsString(Policy);
   else
 baseTypeName =
   ty.getUnqualifiedType().getCanonicalType().getAsString(Policy);


Index: test/CodeGenOpenCL/pipe_types.cl
===
--- test/CodeGenOpenCL/pipe_types.cl
+++ test/CodeGenOpenCL/pipe_types.cl
@@ -25,3 +25,23 @@
 void test5(read_only pipe int4 p) {
 // CHECK: define void @test5(%opencl.pipe_t* %p)
 }
+
+typedef pipe int MyPipe;
+kernel void test6(read_only MyPipe p) {
+// CHECK: define void @test6(%opencl.pipe_t* %p)
+}
+
+struct Person {
+  const char *Name;
+  bool isFemale;
+  int ID;
+};
+
+void test_reserved_read_pipe(global struct Person *SDst,
+ read_only pipe struct Person SPipe) {
+// CHECK: define void @test_reserved_read_pipe
+  read_pipe (SPipe, SDst);
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+  read_pipe (SPipe, SDst);
+  // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}})
+}
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -516,7 +516,8 @@
   // Get argument type name.
   std::string typeName;
   if (isPipe)
-typeName = cast(ty)->getElementType().getAsString(Policy);
+typeName = ty.getCanonicalType()->getAs()->getElementType()
+ .getAsString(Policy);
   else
 typeName = ty.getUnqualifiedType().getAsString(Policy);
 
@@ -529,8 +530,9 @@
 
   std::string baseTypeName;
   if (isPipe)
-baseTypeName =
-  cast(ty)->getElementType().getCanonicalType().getAsString(Policy);
+baseTypeName = ty.getCanonicalType()->getAs()
+  ->getElementType().getCanonicalType()
+  .getAsString(Policy);
   else
 baseTypeName =
   ty.getUnqualifiedType().getCanonicalType().getAsString(Policy);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21795: [OpenCL] Add attribute 'pure' to read_image built-in functions to enable optimizations.

2016-06-28 Thread Alexey Bader via cfe-commits
bader created this revision.
bader added reviewers: Anastasia, yaxunl.
bader added subscribers: cfe-commits, pxli168, pekka.jaaskelainen.

http://reviews.llvm.org/D21795

Files:
  lib/Headers/opencl-c.h

Index: lib/Headers/opencl-c.h
===
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -19,7 +19,7 @@
 #define __ovld __attribute__((overloadable))
 
 // Optimizations
-
+#define __purefn __attribute__((pure))
 #define __cnfn __attribute__((const))
 
 // built-in scalar data types:
@@ -15685,324 +15685,324 @@
  * in the description above are undefined.
  */
 
-float4 __ovld read_imagef(read_only image2d_t image, sampler_t sampler, int2 coord);
-float4 __ovld read_imagef(read_only image2d_t image, sampler_t sampler, float2 coord);
+float4 __purefn __ovld read_imagef(read_only image2d_t image, sampler_t sampler, int2 coord);
+float4 __purefn __ovld read_imagef(read_only image2d_t image, sampler_t sampler, float2 coord);
 
-int4 __ovld read_imagei(read_only image2d_t image, sampler_t sampler, int2 coord);
-int4 __ovld read_imagei(read_only image2d_t image, sampler_t sampler, float2 coord);
-uint4 __ovld read_imageui(read_only image2d_t image, sampler_t sampler, int2 coord);
-uint4 __ovld read_imageui(read_only image2d_t image, sampler_t sampler, float2 coord);
+int4 __purefn __ovld read_imagei(read_only image2d_t image, sampler_t sampler, int2 coord);
+int4 __purefn __ovld read_imagei(read_only image2d_t image, sampler_t sampler, float2 coord);
+uint4 __purefn __ovld read_imageui(read_only image2d_t image, sampler_t sampler, int2 coord);
+uint4 __purefn __ovld read_imageui(read_only image2d_t image, sampler_t sampler, float2 coord);
 
-float4 __ovld read_imagef(read_only image3d_t image, sampler_t sampler, int4 coord);
-float4 __ovld read_imagef(read_only image3d_t image, sampler_t sampler, float4 coord);
+float4 __purefn __ovld read_imagef(read_only image3d_t image, sampler_t sampler, int4 coord);
+float4 __purefn __ovld read_imagef(read_only image3d_t image, sampler_t sampler, float4 coord);
 
-int4 __ovld read_imagei(read_only image3d_t image, sampler_t sampler, int4 coord);
-int4 __ovld read_imagei(read_only image3d_t image, sampler_t sampler, float4 coord);
-uint4 __ovld read_imageui(read_only image3d_t image, sampler_t sampler, int4 coord);
-uint4 __ovld read_imageui(read_only image3d_t image, sampler_t sampler, float4 coord);
+int4 __purefn __ovld read_imagei(read_only image3d_t image, sampler_t sampler, int4 coord);
+int4 __purefn __ovld read_imagei(read_only image3d_t image, sampler_t sampler, float4 coord);
+uint4 __purefn __ovld read_imageui(read_only image3d_t image, sampler_t sampler, int4 coord);
+uint4 __purefn __ovld read_imageui(read_only image3d_t image, sampler_t sampler, float4 coord);
 
-float4 __ovld read_imagef(read_only image2d_array_t image_array, sampler_t sampler, int4 coord);
-float4 __ovld read_imagef(read_only image2d_array_t image_array, sampler_t sampler, float4 coord);
+float4 __purefn __ovld read_imagef(read_only image2d_array_t image_array, sampler_t sampler, int4 coord);
+float4 __purefn __ovld read_imagef(read_only image2d_array_t image_array, sampler_t sampler, float4 coord);
 
-int4 __ovld read_imagei(read_only image2d_array_t image_array, sampler_t sampler, int4 coord);
-int4 __ovld read_imagei(read_only image2d_array_t image_array, sampler_t sampler, float4 coord);
-uint4 __ovld read_imageui(read_only image2d_array_t image_array, sampler_t sampler, int4 coord);
-uint4 __ovld read_imageui(read_only image2d_array_t image_array, sampler_t sampler, float4 coord);
+int4 __purefn __ovld read_imagei(read_only image2d_array_t image_array, sampler_t sampler, int4 coord);
+int4 __purefn __ovld read_imagei(read_only image2d_array_t image_array, sampler_t sampler, float4 coord);
+uint4 __purefn __ovld read_imageui(read_only image2d_array_t image_array, sampler_t sampler, int4 coord);
+uint4 __purefn __ovld read_imageui(read_only image2d_array_t image_array, sampler_t sampler, float4 coord);
 
-float4 __ovld read_imagef(read_only image1d_t image, sampler_t sampler, int coord);
-float4 __ovld read_imagef(read_only image1d_t image, sampler_t sampler, float coord);
+float4 __purefn __ovld read_imagef(read_only image1d_t image, sampler_t sampler, int coord);
+float4 __purefn __ovld read_imagef(read_only image1d_t image, sampler_t sampler, float coord);
 
-int4 __ovld read_imagei(read_only image1d_t image, sampler_t sampler, int coord);
-int4 __ovld read_imagei(read_only image1d_t image, sampler_t sampler, float coord);
-uint4 __ovld read_imageui(read_only image1d_t image, sampler_t sampler, int coord);
-uint4 __ovld read_imageui(read_only image1d_t image, sampler_t sampler, float coord);
+int4 __purefn __ovld read_imagei(read_only image1d_t image, sampler_t sampler, int coord);
+int4 __purefn __ovld read_imagei(read_only image1d_t image, sampler_t sampler, float coord);
+uint4 __purefn __ovld read_imageui(read_only 

Re: [PATCH] D20249: [OpenCL] Hierarchical/dynamic parallelism - enqueue kernel in OpenCL 2.0

2016-06-27 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a comment.

LGTM.
A few style nitpicks.



Comment at: lib/CodeGen/CGBuiltin.cpp:2180-2181
@@ +2179,4 @@
+}
+// Could have events and/or vaargs.
+if (NumArgs >= 5) {
+  if (E->getArg(3)->getType()->isBlockPointerType()) {

[Style] Minor suggestion to consider.
To avoid indentation of almost 100 lines of code inside if statement this can 
be implemented as:
if (NumArgs < 5) llvm_unreachable("Unhandled enqueue_kernel signature");

There is no else branch for that condition anyway.


Comment at: lib/CodeGen/CGBuiltin.cpp:2189-2190
@@ +2188,4 @@
+// express to the runtime the number of variadic arguments.
+std::vector Args{Queue, Flags, Range, Block,
+ConstantInt::get(IntTy, NumArgs - 4)};
+std::vector ArgTys = {QueueTy, IntTy, RangeTy, Int8PtrTy,

[Style] Use an equals before the open curly brace.
http://llvm.org/docs/CodingStandards.html#do-not-use-braced-initializer-lists-to-call-a-constructor


Comment at: lib/CodeGen/CGBuiltin.cpp:2195
@@ +2194,3 @@
+// Add the variadics.
+for (unsigned i = 4; i < NumArgs; ++i) {
+  llvm::Value *ArgSize = EmitScalarExpr(E->getArg(i));

[Style] CamelCase: i -> I
http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly



Comment at: lib/CodeGen/CGBuiltin.cpp:2238-2239
@@ +2237,4 @@
+EventPtrAS4Ty, EventPtrAS5Ty, Int8PtrTy};
+std::vector Args{Queue, Flags,Range, NumEvents,
+EventList, ClkEvent, Block};
+

[Style] Use an equals before the open curly brace.
http://llvm.org/docs/CodingStandards.html#do-not-use-braced-initializer-lists-to-call-a-constructor


Comment at: lib/CodeGen/CGBuiltin.cpp:2249
@@ +2248,3 @@
+ llvm::ArrayRef(Args)));
+} else {
+  // Has event info and variadics

[Style] 'else' here is unnecessary:
http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return



Comment at: lib/CodeGen/CGBuiltin.cpp:2257
@@ +2256,3 @@
+  // Add the variadics.
+  for (unsigned i = 7; i < NumArgs; ++i) {
+llvm::Value *ArgSize = EmitScalarExpr(E->getArg(i));

[Style] CamelCase: i -> I
http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly


Comment at: lib/Sema/SemaChecking.cpp:124-126
@@ +123,5 @@
+   diag::err_opencl_enqueue_kernel_expected_type) << "block";
+return true;
+  } else
+return checkBlockArgs(S, BlockArg);
+}

[Style] 'else' here is unnecessary:
http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return


Comment at: lib/Sema/SemaChecking.cpp:132
@@ +131,3 @@
+  bool IllegalParams = false;
+  for (unsigned i = Start; i <= End; ++i) {
+QualType Ty = TheCall->getArg(i)->getType();

[Style] CamelCase: i -> I
http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly


Comment at: lib/Sema/SemaChecking.cpp:145
@@ +144,3 @@
+}
+
+/// OpenCL v2.0, s6.13.17.1 - Check that sizes are provided for all

Anastasia wrote:
> I think the problem is that in C99 there are implicit casts among integer 
> types, therefore making this check more restrictive would imply the cast has 
> to be done explicitly instead.
> 
> Thus, this would have to be modified as follows:
> 
>   enqueue_kernel(...,  64); -> enqueue_kernel(...,  (uint)64); or 
> enqueue_kernel(...,  64U);
> 
> which in my opinion is undesirable and also a bit unexpected because by 
> analogy to C99 you can compile the following successfully:
>   
>   void g(unsigned);
> 
>   void f() {
> char i;
> g(i);
>   }
> 
> I have added a check for a size however not to be larger than 32 bits and 
> handled type cast in CodeGen. The test cases are added too.
> 
> What's your opinion about it?
I'm OK with allowing implicit conversions as long as there is a way to enforce 
strict check for unsigned 32-bit integer here (e.g. with -Wconversion or in 
pedatic mode).
Can we check that mode?


Comment at: lib/Sema/SemaChecking.cpp:238-239
@@ +237,4 @@
+  << "block";
+  return true;
+} else { // we have a block type, check the prototype
+  const BlockPointerType *BPT =

[Style] 'else' here is unnecessary:
http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return


Comment at: lib/Sema/SemaChecking.cpp:250
@@ +249,3 @@
+return false;
+  } else {
+// we can have block + varargs.

[Style] 'else' here is unnecessary:
http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return


Re: [PATCH] D20249: [OpenCL] Hierarchical/dynamic parallelism - enqueue kernel in OpenCL 2.0

2016-06-23 Thread Alexey Bader via cfe-commits
bader added a comment.

Hi Anastasia,

Sorry for the delay.
I have just a few comments.

Thanks,
Alexey



Comment at: lib/Sema/SemaChecking.cpp:95
@@ +94,3 @@
+  IllegalParams = true;
+  break;
+}

It looks like this function will report only first invalid parameter. Can we 
report all of them by moving code from lines 109-120 inside the loop?


Comment at: lib/Sema/SemaChecking.cpp:145
@@ +144,3 @@
+  for (unsigned i = Start; i < End; ++i)
+if (!TheCall->getArg(i)->getType().getTypePtr()->isIntegerType())
+  return false;

If I understand it correctly the intention is to convert this integer type to 
i32. Am I right?
By the spec it must be unsigned 32-bit integer, not just any integer type.



Comment at: lib/Sema/SemaChecking.cpp:201
@@ +200,3 @@
+///clk_event_t *event_ret,
+///void (^block)(void*, ...),
+///uint size0, ...)

block arguments must be pointers to the local memory (the same as previous 
declaration).


Comment at: lib/Sema/SemaChecking.cpp:249
@@ +248,3 @@
+} else
+  return checkBlockArgs(S, Arg3);
+  } else if (NumArgs >= 5) {

Could you clarify that code path?
My understanding is that if NumArgs ==4, clang should except only block with 
empty parameter list. Am I right?

   /// int enqueue_kernel(queue_t queue,
   ///kernel_enqueue_flags_t flags,
   ///const ndrange_t ndrange,
   ///void (^block)(void))


Comment at: lib/Sema/SemaChecking.cpp:250
@@ +249,3 @@
+  return checkBlockArgs(S, Arg3);
+  } else if (NumArgs >= 5) {
+// we can have block + varargs.

This check is redundant.
It's known to be always true at this point.


Comment at: lib/Sema/SemaChecking.cpp:297
@@ +296,3 @@
+return false;
+  else if (NumArgs >= 7) // check if varargs are correct types.
+return checkEnqueueVariadicArgs(S, TheCall, Arg6, 7);

This check is redundant. This condition is known to be true at line 250.


Comment at: lib/Sema/SemaChecking.cpp:302
@@ +301,3 @@
+
+  // None of the specific case has been detected, give generic error
+  S.Diag(TheCall->getLocStart(),

Shouldn't by default we return false and report an error only if checks above 
find inconsistency?
I expect code to be much simpler with this approach.


http://reviews.llvm.org/D20249



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


Re: [PATCH] D20979: [OpenCL] Use function metadata to represent kernel attributes

2016-06-20 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a comment.

LGTM.



Comment at: test/CodeGenOpenCL/kernel-attributes.cl:9
@@ -8,3 +10,1 @@
 
-// CHECK: opencl.kernels = !{[[MDNODE0:![0-9]+]], [[MDNODE3:![0-9]+]]}
-

AFAIK, this named metadata node were also useful for kernel functions traversal.
What is the new BKM to differentiate kernel/non-kernel functions?
Check for !kernel_arg_* function attribute?


http://reviews.llvm.org/D20979



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


Re: [PATCH] D20444: [OpenCL] Include opencl-c.h by default as a clang module

2016-06-02 Thread Alexey Bader via cfe-commits
bader accepted this revision.


Comment at: test/Headers/opencl-c-header.cl:30-31
@@ +29,4 @@
+
+// ===
+// Compile for OpenCL 2.0 for the first time. The module should change.
+// RUN: %clang_cc1 -cc1  -emit-llvm -o - -cl-std=CL2.0 
-finclude-default-header -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -fdisable-module-hash %s | FileCheck 
--check-prefix=CHECK20 %s

It would be nice to re-use that part of module that agnostic to OpenCL version. 
Most of the OpenCL 2.0 declarations are already in the module for OpenCL 1.0.
Pointer/size_t arguments could another reason to re-parse the header.

Just FYI: at the moment we use chained PCHes to reduce the footprint of the 
PCHes we ship with OpenCL implementation.
The chain looks like:  +  + , where 60% is occupied by , which is shared across 
all possible compilations.



http://reviews.llvm.org/D20444



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


Re: [PATCH] D20249: [OpenCL] Hierarchical/dynamic parallelism - enqueue kernel in OpenCL 2.0

2016-05-31 Thread Alexey Bader via cfe-commits
bader added a comment.

Sorry for the delay.

Is this code valid:

  clk_event_t e1, e2, e3;
  clk_event_t events[] = {e1, e2};
  enqueue_kernel(get_default_queue(), 0, get_ndrange(), 2, events, , ...);

With this patch clang rejects it with an error:

  'illegal call to enqueue_kernel, expected 'clk_event_t *' argument type'

C rules allows implicit conversion of to pointer by taking address of the first 
element of the array.



Comment at: lib/Sema/SemaChecking.cpp:154
@@ +153,3 @@
+ unsigned NumNonVarArgs) {
+  const BlockPointerType *BPT = cast(BlockArg->getType());
+  unsigned NumBlockParams =

Here block type must be canonical too.


http://reviews.llvm.org/D20249



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


  1   2   >