[PATCH] D46015: [OpenCL] Add separate read_only and write_only pipe IR types

Stuart Brady via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 25 09:51:05 PDT 2018


stuart added a comment.

In https://reviews.llvm.org/D46015#1078260, @AlexeySotkin wrote:

> In https://reviews.llvm.org/D46015#1078235, @stuart wrote:
>
> > In https://reviews.llvm.org/D46015#1078217, @AlexeySotkin wrote:
> >
> > > There should not be need for bitcast. Could give an example ? Thanks.
> >
> >
> > If I have a `write_only` pipe as the argument to `get_pipe_max_packets()`, and this uses a single `__get_pipe_num_packets()` function taking a `read_only` pipe, we will automatically get a bitcast:
> >
> >   %20 = call i32 bitcast (i32 (%opencl.pipe_ro_t*, i32, i32)* @__get_pipe_max_packets to i32 (%opencl.pipe_wo_t*, i32, i32)*)(%opencl.pipe_wo_t* %19, i32 4, i32 4)
> >
>
>
> Sorry, but I don't quite understand what does  `get_pipe_max_packets()`, **uses** `__get_pipe_num_packets()`  mean. Could you clarify? Possibly OpenCL C source example could help.


I mean that without these two separate versions, the call to `__get_pipe_num_packets()` that is emitted can include a bitcast.

For example:

  void foo(read_only pipe int r, write_only pipe int w) {
    get_pipe_num_packets(w);
    get_pipe_num_packets(r);
  }

`get_pipe_num_packets(w)` is seen first, causing `i32 @__get_pipe_num_packets(%opencl.pipe_wo_t*, i32, i32)` to be implicitly declared.

When the call to `__get_pipe_num_packets()` is emitted, this will be with an autogenerated bitcast from the type of the implicit declaration, i.e. `i32 (%opencl.pipe_wo_t*, i32, i32)*` to the type in the emitted expression, i.e. `i32 (%opencl.pipe_ro_t*, i32, i32)*`.

Here is the relevant section of IR:

  %0 = load %opencl.pipe_wo_t*, %opencl.pipe_wo_t** %w.addr, align 8
  %1 = call i32 @__get_pipe_num_packets_ro(%opencl.pipe_wo_t* %0, i32 4, i32 4)
  %2 = load %opencl.pipe_ro_t*, %opencl.pipe_ro_t** %r.addr, align 8
  %3 = call i32 bitcast (i32 (%opencl.pipe_wo_t*, i32, i32)* @__get_pipe_num_packets_ro to i32 (%opencl.pipe_ro_t*, i32, i32)*)(%opencl.pipe_ro_t* %2, i32 4, i32 4)

If we swap the two calls to `__get_pipe_num_packets()` in the example above, then the type of the implicit declaration will be `i32 (%opencl.pipe_ro_t*, i32, i32)*` and bitcasts will instead be automatically generated when using `get_pipe_num_packets()` with a `write_only` pipe. It seems especially unfortunate that the type of the implicit declaration varies depending on the access qualifier of the first use.


https://reviews.llvm.org/D46015





More information about the cfe-commits mailing list