Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OpenCL] Allow address spaces as method qualifiers.
Methods can now be qualified with address spaces to prevent undesirable conversions to generic or to provide custom implementation to be used if the object is located in certain memory segments. This commit extends parsing and standard C++ overloading to work for an address space of a method (i.e. implicit 'this' parameter). Differential Revision: https://reviews.llvm.org/D55850 llvm-svn: 351747
- Loading branch information
Anastasia Stulova
committed
Jan 21, 2019
1 parent
cfa434a
commit 5cffa45
Showing
9 changed files
with
187 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
clang/test/CodeGenOpenCLCXX/method-overload-address-space.cl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s | ||
|
||
struct C { | ||
void foo() __local; | ||
void foo() __global; | ||
void foo(); | ||
void bar(); | ||
}; | ||
|
||
__global C c1; | ||
|
||
__kernel void k() { | ||
__local C c2; | ||
C c3; | ||
__global C &c_ref = c1; | ||
__global C *c_ptr; | ||
|
||
// CHECK: call void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)* | ||
c1.foo(); | ||
// CHECK: call void @_ZNU3AS31C3fooEv(%struct.C addrspace(3)* | ||
c2.foo(); | ||
// CHECK: call void @_ZNU3AS41C3fooEv(%struct.C addrspace(4)* | ||
c3.foo(); | ||
// CHECK: call void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)* | ||
c_ptr->foo(); | ||
// CHECK: void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)* | ||
c_ref.foo(); | ||
|
||
// CHECK: call void @_ZNU3AS41C3barEv(%struct.C addrspace(4)* addrspacecast (%struct.C addrspace(1)* @c1 to %struct.C addrspace(4)*)) | ||
c1.bar(); | ||
//FIXME: Doesn't compile yet | ||
//c_ptr->bar(); | ||
// CHECK: call void @_ZNU3AS41C3barEv(%struct.C addrspace(4)* addrspacecast (%struct.C addrspace(1)* @c1 to %struct.C addrspace(4)*)) | ||
c_ref.bar(); | ||
} |
18 changes: 18 additions & 0 deletions
18
clang/test/SemaOpenCLCXX/address-space-of-this-class-scope.cl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify | ||
|
||
struct C { | ||
auto fGlob() __global -> decltype(this); | ||
auto fGen() -> decltype(this); | ||
auto fErr() __global __local -> decltype(this); //expected-error{{multiple address spaces specified for type}} | ||
}; | ||
|
||
void bar(__local C*); | ||
// expected-note@-1{{candidate function not viable: address space mismatch in 1st argument ('decltype(this)' (aka '__global C *')), parameter type must be '__local C *'}} | ||
// expected-note@-2{{candidate function not viable: address space mismatch in 1st argument ('decltype(this)' (aka 'C *')), parameter type must be '__local C *'}} | ||
|
||
__global C Glob; | ||
void foo(){ | ||
bar(Glob.fGlob()); // expected-error{{no matching function for call to 'bar'}} | ||
// FIXME: AS of 'this' below should be correctly deduced to generic | ||
bar(Glob.fGen()); // expected-error{{no matching function for call to 'bar'}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify | ||
|
||
struct C { | ||
void m1() __local __local; //expected-warning{{multiple identical address spaces specified for type}} | ||
//expected-note@-1{{candidate function}} | ||
void m1() __global; | ||
//expected-note@-1{{candidate function}} | ||
void m2() __global __local; //expected-error{{multiple address spaces specified for type}} | ||
}; | ||
|
||
__global C c_glob; | ||
|
||
__kernel void bar() { | ||
__local C c_loc; | ||
C c_priv; | ||
|
||
c_glob.m1(); | ||
c_loc.m1(); | ||
c_priv.m1(); //expected-error{{no matching member function for call to 'm1'}} | ||
} |