Re: [PATCH] D13105: [OpenCL] Enable program scope variables for OpenCL2.0
Anastasia closed this revision. Anastasia added a comment. r248906 and r250892 http://reviews.llvm.org/D13105 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13105: [OpenCL] Enable program scope variables for OpenCL2.0
Anastasia updated this revision to Diff 35732. Anastasia added a comment. Thanks! The review comments are addressed in this update! http://reviews.llvm.org/D13105 Files: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Basic/Specifiers.h lib/AST/Decl.cpp lib/AST/DeclPrinter.cpp lib/CodeGen/CGDecl.cpp lib/Sema/SemaDecl.cpp test/Parser/opencl-storage-class.cl test/SemaOpenCL/storageclass-cl20.cl test/SemaOpenCL/storageclass.cl tools/libclang/CIndex.cpp Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -6604,8 +6604,6 @@ return CX_SC_Static; case SC_PrivateExtern: return CX_SC_PrivateExtern; - case SC_OpenCLWorkGroupLocal: -return CX_SC_OpenCLWorkGroupLocal; case SC_Auto: return CX_SC_Auto; case SC_Register: Index: test/SemaOpenCL/storageclass.cl === --- test/SemaOpenCL/storageclass.cl +++ test/SemaOpenCL/storageclass.cl @@ -1,14 +1,29 @@ // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2 -static constant int A = 0; +static constant int G1 = 0; +constant int G2 = 0; +int G3 = 0;// expected-error{{program scope variable must reside in constant address space}} +global int G4 = 0; // expected-error{{program scope variable must reside in constant address space}} -int X = 0; // expected-error{{global variables must have a constant address space qualifier}} - -// static is not allowed at local scope. void kernel foo() { - static int X = 5; // expected-error{{variables in function scope cannot be declared static}} - auto int Y = 7; // expected-error{{OpenCL does not support the 'auto' storage class specifier}} + // static is not allowed at local scope before CL2.0 + static int S1 = 5; // expected-error{{variables in function scope cannot be declared static}} + static constant int S2 = 5; // expected-error{{variables in function scope cannot be declared static}} + + constant int L1 = 0; + local int L2; + + auto int L3 = 7; // expected-error{{OpenCL does not support the 'auto' storage class specifier}} } static void kernel bar() { // expected-error{{kernel functions cannot be declared static}} } + +void f() { + constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}} + local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}} + { +constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}} +local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}} + } +} Index: test/SemaOpenCL/storageclass-cl20.cl === --- /dev/null +++ test/SemaOpenCL/storageclass-cl20.cl @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCL20 -cl-std=CL2.0 + +static constant int G1 = 0; +int G2 = 0;// expected-error{{program scope variable must reside in global or constant address space}} +global int G3 = 0; +local int G4 = 0;// expected-error{{program scope variable must reside in global or constant address space}} + +void kernel foo() { + static int S1 = 5;// expected-error{{program scope variable must reside in global or constant address space}} + static global int S2 = 5; + static private int S3 = 5;// expected-error{{program scope variable must reside in global or constant address space}} + + constant int L1 = 0; + local int L2; +} Index: test/Parser/opencl-storage-class.cl === --- test/Parser/opencl-storage-class.cl +++ test/Parser/opencl-storage-class.cl @@ -8,7 +8,7 @@ auto int d; // expected-error {{OpenCL does not support the 'auto' storage class specifier}} #pragma OPENCL EXTENSION cl_clang_storage_class_specifiers : enable - static int e; + static int e; // expected-error {{program scope variable must reside in constant address space}} register int f; extern int g; auto int h; Index: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -5687,12 +5687,6 @@ } if (getLangOpts().OpenCL) { -// Set up the special work-group-local storage class for variables in the -// OpenCL __local address space. -if (R.getAddressSpace() == LangAS::opencl_local) { - SC = SC_OpenCLWorkGroupLocal; -} - // OpenCL v1.2 s6.9.b p4: // The sampler type cannot be used with the __local and __global address // space qualifiers. @@ -5759,8 +5753,6 @@ break; case SC_PrivateExtern: llvm_unreachable("C storage class in c++!"); - case SC_OpenCLWorkGroupLocal: -llvm_unreachable("OpenCL storage class in
Re: [PATCH] D13105: [OpenCL] Enable program scope variables for OpenCL2.0
bader added a subscriber: bader. Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7472-7473 @@ -7469,4 +7471,4 @@ "sampler type cannot be used with the __local and __global address space qualifiers">; def err_opencl_global_invalid_addr_space : Error< - "global variables must have a constant address space qualifier">; + "program scope variables has wrong address space qualifier">; def err_opencl_no_main : Error<"%select{function|kernel}0 cannot be called 'main'">; I think we can do better diagnostics. Original message hinted on way to fix that error - add 'constant' qualifier. In our implementation we have 4 kinds of diagnostics (probably we need only 2 of them): def err_opencl_global_invalid_addr_space : Error< "program scope variables must reside in constant address space">; def err_opencl20_global_invalid_addr_space : Error< "program scope variables must reside in global or constant address space">; def err_program_scope_variable_non_constant : Error< "program scope variables are required to be declared in constant address space">; def err_program_scope_variable_non_constant_or_global : Error< "program scope variables are required to be declared either in constant or global address space">; They used for OpenCL 1.2 and OpenCL 2.0 sources correspondingly. Comment at: test/SemaOpenCL/storageclass.cl:9-11 @@ +8,5 @@ +global int G2 = 0; +#ifndef CL20 +// expected-error@-2{{program scope variables has wrong address space qualifier}} +#endif + Don't you think it's better to put OpenCL 2.0 test into separate file? http://reviews.llvm.org/D13105 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D13105: [OpenCL] Enable program scope variables for OpenCL2.0
Anastasia created this revision. Anastasia added a reviewer: pekka.jaaskelainen. Anastasia added a subscriber: cfe-commits. I would like to commit this change that enables program scope variables (PSVs) – an OpenCL2.0 feature (Section 6.5.1). There are three major changes in this patch. First change removes virtual SC_OpenCLWorkGroupLocal storage type specifier as it conflicts with static local variables now and prevents diagnosing static local address space variables correctly. Also it doesn’t seem really necessary since we can identify local AS variable by looking at the AS attribute itself. Second change makes static local variables as well as global variables allowed in OpenCL2.0 (OpenCL2.0 s6.8 and s6.5.1). Last change improves diagnostics of allowed ASes for variables in different scopes: Global or static local variables have to be in global or constant ASes (OpenCL1.2 s6.5, OpenCL2.0 s6.5.1); Non-kernel function variables can’t be declared in local or constant ASes (OpenCL1.1 s6.5.2 and s6.5.3). http://reviews.llvm.org/D13105 Files: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Basic/Specifiers.h lib/AST/Decl.cpp lib/AST/DeclPrinter.cpp lib/CodeGen/CGDecl.cpp lib/Sema/SemaDecl.cpp test/Parser/opencl-storage-class.cl test/SemaOpenCL/storageclass.cl tools/libclang/CIndex.cpp Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -6604,8 +6604,6 @@ return CX_SC_Static; case SC_PrivateExtern: return CX_SC_PrivateExtern; - case SC_OpenCLWorkGroupLocal: -return CX_SC_OpenCLWorkGroupLocal; case SC_Auto: return CX_SC_Auto; case SC_Register: Index: test/SemaOpenCL/storageclass.cl === --- test/SemaOpenCL/storageclass.cl +++ test/SemaOpenCL/storageclass.cl @@ -1,14 +1,48 @@ // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2 +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCL20 -cl-std=CL2.0 static constant int A = 0; -int X = 0; // expected-error{{global variables must have a constant address space qualifier}} +int G1 = 0;// expected-error{{program scope variables has wrong address space qualifier}} -// static is not allowed at local scope. +global int G2 = 0; +#ifndef CL20 +// expected-error@-2{{program scope variables has wrong address space qualifier}} +#endif + +local int G3 = 0;// expected-error{{program scope variables has wrong address space qualifier}} + +// static is not allowed at local scope before CL2.0 void kernel foo() { - static int X = 5; // expected-error{{variables in function scope cannot be declared static}} + static int S1 = 5; +#ifndef CL20 + // expected-error@-2{{variables in function scope cannot be declared static}} +#else + // expected-error@-4{{program scope variables has wrong address space qualifier}} +#endif + + static global int S2 = 5; +#ifndef CL20 + // expected-error@-2{{variables in function scope cannot be declared static}} +#endif + + static private int S3 = 5; +#ifndef CL20 + // expected-error@-2{{variables in function scope cannot be declared static}} +#else + // expected-error@-4{{program scope variables has wrong address space qualifier}} +#endif + + constant int G4 = 0; + local int L1; + auto int Y = 7; // expected-error{{OpenCL does not support the 'auto' storage class specifier}} } static void kernel bar() { // expected-error{{kernel functions cannot be declared static}} } + +void f(){ + constant int G5 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}} + local int L2; // expected-error{{non-kernel function variable cannot be declared in local address space}} +} Index: test/Parser/opencl-storage-class.cl === --- test/Parser/opencl-storage-class.cl +++ test/Parser/opencl-storage-class.cl @@ -8,7 +8,7 @@ auto int d; // expected-error {{OpenCL does not support the 'auto' storage class specifier}} #pragma OPENCL EXTENSION cl_clang_storage_class_specifiers : enable - static int e; + static int e; // expected-error {{program scope variables has wrong address space qualifier}} register int f; extern int g; auto int h; Index: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -5687,12 +5687,6 @@ } if (getLangOpts().OpenCL) { -// Set up the special work-group-local storage class for variables in the -// OpenCL __local address space. -if (R.getAddressSpace() == LangAS::opencl_local) { - SC = SC_OpenCLWorkGroupLocal; -} - // OpenCL v1.2 s6.9.b p4: // The sampler type cannot be used with the __local and __global address // space qualifiers. @@ -5759,8 +5753,6 @@ break; case