Skip to content

Commit 568767b

Browse files
committed
[OpenCL] Add support of __opencl_c_pipes feature macro.
'pipe' keyword is introduced in OpenCL C 2.0: so do checks for OpenCL C version while parsing and then later on check for language options to construct actual pipe. This feature requires support of __opencl_c_generic_address_space, so diagnostics for that is provided as well. This is the same patch as in D106748 but with a tiny fix in checking of diagnostic messages. Also added tests when program scope global variables are not supported. This is squashed cherry pick of D107154 and D107176
1 parent 4740e92 commit 568767b

14 files changed

+71
-25
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
224224
LANGOPT(OpenCLCPlusPlus , 1, 0, "C++ for OpenCL")
225225
LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
226226
LANGOPT(OpenCLGenericAddressSpace, 1, 0, "OpenCL generic keyword")
227-
LANGOPT(OpenCLPipe , 1, 0, "OpenCL pipe keyword")
227+
LANGOPT(OpenCLPipes , 1, 0, "OpenCL pipes language constructs and built-ins")
228228
LANGOPT(NativeHalfType , 1, 0, "Native half type support")
229229
LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
230230
LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")

clang/lib/Basic/OpenCLOptions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ bool OpenCLOptions::diagnoseUnsupportedFeatureDependencies(
112112
// supported.
113113
static const llvm::StringMap<llvm::StringRef> DependentFeaturesMap = {
114114
{"__opencl_c_read_write_images", "__opencl_c_images"},
115-
{"__opencl_c_3d_image_writes", "__opencl_c_images"}};
115+
{"__opencl_c_3d_image_writes", "__opencl_c_images"},
116+
{"__opencl_c_pipes", "__opencl_c_generic_address_space"}};
116117

117118
auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
118119

clang/lib/Basic/TargetInfo.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,18 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
400400
// OpenCL C v3.0 s6.7.5 - The generic address space requires support for
401401
// OpenCL C 2.0 or OpenCL C 3.0 with the __opencl_c_generic_address_space
402402
// feature
403-
// FIXME: OpenCLGenericAddressSpace is also defined in setLangDefaults()
403+
// OpenCL C v3.0 s6.2.1 - OpenCL pipes require support of OpenCL C 2.0
404+
// or later and __opencl_c_pipes feature
405+
// FIXME: These language options are also defined in setLangDefaults()
404406
// for OpenCL C 2.0 but with no access to target capabilities. Target
405-
// should be immutable once created and thus this language option needs
407+
// should be immutable once created and thus these language options need
406408
// to be defined only once.
407-
if (Opts.OpenCLVersion >= 300) {
409+
if (Opts.OpenCLVersion == 300) {
408410
const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
409411
Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
410412
OpenCLFeaturesMap, "__opencl_c_generic_address_space");
413+
Opts.OpenCLPipes =
414+
hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes");
411415
}
412416
}
413417

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
31733173
Opts.ZVector = 0;
31743174
Opts.setDefaultFPContractMode(LangOptions::FPM_On);
31753175
Opts.OpenCLCPlusPlus = Opts.CPlusPlus;
3176-
Opts.OpenCLPipe = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
3176+
Opts.OpenCLPipes = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
31773177
Opts.OpenCLGenericAddressSpace =
31783178
Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200;
31793179

clang/lib/Parse/ParseDecl.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,8 +3952,12 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
39523952
Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
39533953
Tok.setKind(tok::identifier);
39543954
goto DoneWithDeclSpec;
3955-
}
3956-
isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy);
3955+
} else if (!getLangOpts().OpenCLPipes) {
3956+
DiagID = diag::err_opencl_unknown_type_specifier;
3957+
PrevSpec = Tok.getIdentifierInfo()->getNameStart();
3958+
isInvalid = true;
3959+
} else
3960+
isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy);
39573961
break;
39583962
// We only need to enumerate each image type once.
39593963
#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
@@ -5126,8 +5130,10 @@ bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) {
51265130
switch (Tok.getKind()) {
51275131
default: return false;
51285132

5133+
// OpenCL 2.0 and later define this keyword.
51295134
case tok::kw_pipe:
5130-
return getLangOpts().OpenCLPipe;
5135+
return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
5136+
getLangOpts().OpenCLCPlusPlus;
51315137

51325138
case tok::identifier: // foo::bar
51335139
// Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5656,7 +5662,9 @@ static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang,
56565662
if (Kind == tok::star || Kind == tok::caret)
56575663
return true;
56585664

5659-
if (Kind == tok::kw_pipe && Lang.OpenCLPipe)
5665+
// OpenCL 2.0 and later define this keyword.
5666+
if (Kind == tok::kw_pipe &&
5667+
((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
56605668
return true;
56615669

56625670
if (!Lang.CPlusPlus)

clang/lib/Sema/Sema.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ void Sema::Initialize() {
327327
if (getLangOpts().OpenCLCPlusPlus || getLangOpts().OpenCLVersion >= 200) {
328328
addImplicitTypedef("clk_event_t", Context.OCLClkEventTy);
329329
addImplicitTypedef("queue_t", Context.OCLQueueTy);
330-
addImplicitTypedef("reserve_id_t", Context.OCLReserveIDTy);
330+
if (getLangOpts().OpenCLPipes)
331+
addImplicitTypedef("reserve_id_t", Context.OCLReserveIDTy);
331332
addImplicitTypedef("atomic_int", Context.getAtomicType(Context.IntTy));
332333
addImplicitTypedef("atomic_uint",
333334
Context.getAtomicType(Context.UnsignedIntTy));

clang/test/CodeGenOpenCL/address-spaces-mangling.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL2.0 -emit-llvm -o - | FileCheck -check-prefix=OCL-20 %s
1010
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL1.2 -emit-llvm -o - | FileCheck -check-prefix=OCL-12 %s
1111
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck -check-prefix=OCL-20 %s
12-
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL3.0 -cl-ext=-__opencl_c_generic_address_space -emit-llvm -o - | FileCheck -check-prefix=OCL-12 %s
12+
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL3.0 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -emit-llvm -o - | FileCheck -check-prefix=OCL-12 %s
1313

1414
// We can't name this f as private is equivalent to default
1515
// no specifier given address space so we get multiple definition

clang/test/CodeGenOpenCL/address-spaces.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 %s -O0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR
2-
// RUN: %clang_cc1 %s -O0 -cl-std=CL3.0 -cl-ext=-__opencl_c_generic_address_space -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR
2+
// RUN: %clang_cc1 %s -O0 -cl-std=CL3.0 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPIR
33
// RUN: %clang_cc1 %s -O0 -DCL20 -cl-std=CL2.0 -ffake-address-space-map -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
44
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s
55
// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefixes=CHECK,AMDGCN %s

clang/test/CodeGenOpenCL/pipe_types.cl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL2.0 -DTEST_STRUCT -o - %s | FileCheck --check-prefixes=CHECK,CHECK-STRUCT %s
2+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space,+__opencl_c_program_scope_global_variables -o - %s | FileCheck --check-prefixes=CHECK %s
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space,-__opencl_c_program_scope_global_variables -o - %s | FileCheck --check-prefixes=CHECK %s
24

35
// CHECK: %opencl.pipe_ro_t = type opaque
46
// CHECK: %opencl.pipe_wo_t = type opaque
@@ -32,6 +34,8 @@ kernel void test6(MyPipe p) {
3234
// CHECK: define{{.*}} spir_kernel void @test6(%opencl.pipe_ro_t* %p)
3335
}
3436

37+
#ifdef TEST_STRUCT
38+
// FIXME: not supported for OpenCL C 3.0 as language built-ins not supported yet
3539
struct Person {
3640
const char *Name;
3741
bool isFemale;
@@ -40,9 +44,10 @@ struct Person {
4044

4145
void test_reserved_read_pipe(global struct Person *SDst,
4246
read_only pipe struct Person SPipe) {
43-
// CHECK: define{{.*}} void @test_reserved_read_pipe
47+
// CHECK-STRUCT: define{{.*}} void @test_reserved_read_pipe
4448
read_pipe (SPipe, SDst);
45-
// CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
49+
// CHECK-STRUCT: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
4650
read_pipe (SPipe, SDst);
47-
// CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
51+
// CHECK-STRUCT: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
4852
}
53+
#endif // TEST_STRUCT

clang/test/CodeGenOpenCL/pipe_types_mangling.cl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// RUN: %clang_cc1 -triple x86_64-unknown-windows-pc -emit-llvm -O0 -cl-std=clc++ -o - %s -DWIN| FileCheck %s --check-prefixes=WINDOWS
33
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s --check-prefixes=LINUX
44
// RUN: %clang_cc1 -triple x86_64-unknown-windows-pc -emit-llvm -O0 -cl-std=CL2.0 -o - %s -DWIN| FileCheck %s --check-prefixes=OCLWINDOWS
5+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space -o - %s | FileCheck %s --check-prefixes=LINUX
6+
// RUN: %clang_cc1 -triple x86_64-unknown-windows-pc -emit-llvm -O0 -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space -o - %s -DWIN | FileCheck %s --check-prefixes=OCLWINDOWS
7+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space,+__opencl_c_program_scope_global_variables -o - %s | FileCheck %s --check-prefixes=LINUX
8+
// RUN: %clang_cc1 -triple x86_64-unknown-windows-pc -emit-llvm -O0 -cl-std=CL3.0 -cl-ext=+__opencl_c_pipes,+__opencl_c_generic_address_space,-__opencl_c_program_scope_global_variables -o - %s -DWIN | FileCheck %s --check-prefixes=OCLWINDOWS
59

610
typedef unsigned char __attribute__((ext_vector_type(3))) uchar3;
711
typedef int __attribute__((ext_vector_type(4))) int4;

0 commit comments

Comments
 (0)