[cfe-dev] [LLVMdev] Language-specific vs target-specific address spaces (was Re: [PATCH] OpenCL support - update on keywords)

David Neto dneto.llvm at gmail.com
Thu Mar 3 11:18:26 PST 2011


On Thu, Mar 3, 2011 at 9:02 AM, Ken Dyck <kd at kendyck.com> wrote:
>
> On second thought, Clang's TargetInfo class would probably be a better
> location for this logic, since the TargetMachine object isn't
> instantiated until back-end code generation, which is too late to be
> useful for IR generation.
>
> Roughly, I'm proposing the following additions to TargetInfo.h:
>
> + enum OpenCLAddressSpace {
> +   OPENCL_PRIVATE,
> +   OPENCL_GLOBAL,
> +   OPENCL_LOCAL,
> +   OPENCL_CONSTANT
> + };
>
> ...
>  class TargetInfo {
> ...
>
> + /// hasOpenCLAddressSpaces - returns true if the target supports a
> mapping of the OpenCL address
> + /// spaces (private, global, local, and constant) to address space
> numbers via getAddressSpace().
> + virtual bool hasOpenCLAddressSpaces() const { return false; }
> +
> + /// getAddressSpace - returns the target-specific address space
> number corresponding to the given
> + /// OpenCL address space qualifier.
> + virtual unsigned getAddressSpace(OpenCLAddressSpace qualifier) { return 0; }
>
> Obviously, hasOpenCLAddressSpaces() and getAddressSpace() would need
> to be overridden for the targets that can support OpenCL.
>
> -Ken


This looks good to me.

We'd have to consider how to handle checked-in Clang tests for OpenCL
support, especially the tests for front-end functionality.  It would
be nice if they were checked on all mainstream platforms.

For example I currently work with x86_64-unknown-linux-gnu.  It would
be nice if the OpenCL tests always ran even though my native backend
doesn't support OpenCL.

Perhaps we could invent a "fakeopencl" target feature to add to common
platforms.  This feature would enable the OpenCL address spaces with
some (arbitrary) numbers.  Then we would write OpenCL tests to always
use something like this:

  // RUN:  %clang_cc1 -target-feature +fakeopencl  %s .....

Of course we could add a special %clang_cc1_opencl macro to the "lit"
config to reduce overall awkwardness.

This would enable convenient testing on all common platforms.   Those
with specific targets would write their own target-specific tests to
make sure the right address space numbers were coming through the IR.

Sound reasonable?

thanks,
david




More information about the cfe-dev mailing list