[RFC][OpenCL] Allow users to add supported OpenCL extensions by pragma

Have we come to the conclusion here now?

Sorry for the delay. I was busy with other works.

I think it is less controversial that the diagnostics related to builtin functions associated with an extension need improvement. The concern may be the complexity of implementation. As far as I see, the following features are desired:

1. when an extension is disabled and a builtin function belonging to that extension is called, an error msg should be emitted.
2. when an extension is disabled, the builtin functions belonging to that extension should not be looked up for resolving overloaded function calls.
3. when an extension is disabled and a type belonging to that extension is used, an error msg should be emitted.

To keep the complexity manageable, we may not want to allow users to declare a function or a type with the same name which is disabled due to disabling their belonging extension. Basically, the declarations of functions and types belonging to an extension still exist even if the extension is disabled. Only usages of these functions and types are disabled.

To implement these features, we need:

1. a representation for functions and types belonging to an extension
2. a way to add a function or type declaration to an extension programmatically (for builtin functions and types defined in Clang)
3. a way to add a function or type declaration to an extension in source code (pragmas)

I may come up with a patch but it may take some time.

Sam

Hi Sam,

Basically, the declarations of functions and types belonging to an extension still exist even if the extension is disabled.

I am just not very sure whether this might create any problem in the future. As far as I know Spec doesn't clarify whether the identifiers from the extensions are reserved and therefore can't be used for other purposes. To me it feels a bit strict but if there is any benefit to do so we could go this way.

Cheers,
Anastasia

If we allow redeclare types or functions of disabled extensions, we may end up with some OpenCL program which is invalid without this feature, e.g.

#pragma OPNECL EXTENSION cl_ext1 : begin
struct A {
  int i;
};
#pragma OPENCL EXTENSION cl_ext1 : end

#pragma OPNECL EXTENSION cl_ext2 : begin
struct A {
  float f;
};
#pragma OPENCL EXTENSION cl_ext2 : end

void f() {
#pragma OPNECL EXTENSION cl_ext1 : enable
struct A a;
a.i = 1;

#pragma OPNECL EXTENSION cl_ext1 : disable
#pragma OPNECL EXTENSION cl_ext2 : enable
struct A b;
b.f = 1;
}

Such a program won't compile with a common OpenCL compiler.

To avoid confusion, I think we'd better not allow types and functions associated with an extension to be redeclared.

Basically, if an extension is supported, its types and functions are always declared. However these types and functions can only be used when the extension is enabled.

Sam

Resend since the format is messed up.

I see your point. It seems like it can lead to some confusions if the same identifiers is used in different extensions.

Yes indeed, it might be better to keep them unique in the full declaration scope of OpenCL.

Thanks,
Anastasia

I updated the review with the implementation https://reviews.llvm.org/D21698

There may still be some missing pieces but the basic feature is there.

Sam