Skip to content

Commit d1e4b25

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. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D106748
1 parent 754520a commit d1e4b25

15 files changed

+66
-35
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
@@ -333,7 +333,8 @@ void Sema::Initialize() {
333333
if (getLangOpts().OpenCLCPlusPlus || getLangOpts().OpenCLVersion >= 200) {
334334
addImplicitTypedef("clk_event_t", Context.OCLClkEventTy);
335335
addImplicitTypedef("queue_t", Context.OCLQueueTy);
336-
addImplicitTypedef("reserve_id_t", Context.OCLReserveIDTy);
336+
if (getLangOpts().OpenCLPipes)
337+
addImplicitTypedef("reserve_id_t", Context.OCLReserveIDTy);
337338
addImplicitTypedef("atomic_int", Context.getAtomicType(Context.IntTy));
338339
addImplicitTypedef("atomic_uint",
339340
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_builtin.cl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,16 @@ void test8(write_only pipe int p, global int *ptr) {
7171
// CHECK: call i32 @__get_pipe_max_packets_wo(%opencl.pipe_wo_t* %{{.*}}, i32 4, i32 4)
7272
*ptr = get_pipe_max_packets(p);
7373
}
74+
75+
struct Person {
76+
const char *Name;
77+
bool isFemale;
78+
int ID;
79+
};
80+
81+
void test9(global struct Person *SDst, read_only pipe struct Person SPipe) {
82+
// CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
83+
read_pipe (SPipe, SDst);
84+
// CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
85+
read_pipe (SPipe, SDst);
86+
}

clang/test/CodeGenOpenCL/pipe_types.cl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %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 -o - %s | FileCheck %s
23

34
// CHECK: %opencl.pipe_ro_t = type opaque
45
// CHECK: %opencl.pipe_wo_t = type opaque
@@ -31,18 +32,3 @@ typedef read_only pipe int MyPipe;
3132
kernel void test6(MyPipe p) {
3233
// CHECK: define{{.*}} spir_kernel void @test6(%opencl.pipe_ro_t* %p)
3334
}
34-
35-
struct Person {
36-
const char *Name;
37-
bool isFemale;
38-
int ID;
39-
};
40-
41-
void test_reserved_read_pipe(global struct Person *SDst,
42-
read_only pipe struct Person SPipe) {
43-
// CHECK: define{{.*}} void @test_reserved_read_pipe
44-
read_pipe (SPipe, SDst);
45-
// CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
46-
read_pipe (SPipe, SDst);
47-
// CHECK: call i32 @__read_pipe_2(%opencl.pipe_ro_t* %{{.*}}, i8* %{{.*}}, i32 16, i32 8)
48-
}

0 commit comments

Comments
 (0)