Files
clang-p2996/clang/test/AST/language_address_space_attribute.cpp
Alexey Bader 8d27be8dba [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
2020-07-29 17:24:53 +03:00

56 lines
1.9 KiB
C++

// Test without serialization:
// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
//
// Test with serialization:
// RUN: %clang_cc1 -emit-pch -o %t %s
// RUN: %clang_cc1 -x c++ -include-pch %t -ast-dump-all /dev/null \
// RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
// RUN: | 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_global_device '__global_device int *'
__attribute__((opencl_global_device)) int *x_global_device;
// CHECK: VarDecl {{.*}} z_global_device '__global_device int *'
[[clang::opencl_global_device]] int *z_global_device;
// CHECK: VarDecl {{.*}} x_global_host '__global_host int *'
__attribute__((opencl_global_host)) int *x_global_host;
// CHECK: VarDecl {{.*}} z_global_host '__global_host int *'
[[clang::opencl_global_host]] int *z_global_host;
// 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 *'
__attribute__((opencl_constant)) int *x_constant;
// CHECK: VarDecl {{.*}} z_constant '__constant int *'
[[clang::opencl_constant]] int *z_constant;
// CHECK: VarDecl {{.*}} x_private '__private int *'
__attribute__((opencl_private)) int *x_private;
// CHECK: VarDecl {{.*}} z_private '__private int *'
[[clang::opencl_private]] int *z_private;
// CHECK: VarDecl {{.*}} x_generic '__generic int *'
__attribute__((opencl_generic)) int *x_generic;
// CHECK: VarDecl {{.*}} z_generic '__generic int *'
[[clang::opencl_generic]] int *z_generic;
}