[Polly] [PPCGCodeGeneration] Skip Scops which contain function pointers.
commitaf182190f53de74c27cb8d58d8c51e1b40410526
authorSiddharth Bhat <siddu.druid@gmail.com>
Mon, 12 Jun 2017 11:41:09 +0000 (12 11:41 +0000)
committerSiddharth Bhat <siddu.druid@gmail.com>
Mon, 12 Jun 2017 11:41:09 +0000 (12 11:41 +0000)
tree59f02c73e05226d80747a87c3140613618b080d7
parenta7933f8bf2662c56b202453e009896d8afa6a65d
[Polly] [PPCGCodeGeneration] Skip Scops which contain function pointers.

In `PPCGCodeGeneration`, we try to take the references of every `Value`
that is used within a Scop to offload to the kernel. This occurs in
`GPUNodeBuilder::createLaunchParameters`.

This breaks if one of the values is a function pointer, since one of
these cases will trigger:

1. We try to to take the references of an intrinsic function, and this
breaks at `verifyModule`, since it is illegal to take the reference of
an intrinsic.

2. We manage to take the reference to a function, but this fails at
`verifyModule` since the function will not be present in the module that
is created in the kernel.

3. Even if `verifyModule` succeeds (which should not occur), we would
then try to call a *host function* from the *device*, which is
illegal runtime behaviour.

So, we disable this entire range of possibilities by simply not allowing
function references within a `Scop` which corresponds to a kernel.

However, note that this is too conservative. We *can* allow intrinsics
within kernels if the backend can lower the intrinsic correctly. For
example, an intrinsic like `llvm.powi.*` can actually be lowered by the `NVPTX`
backend.

We will now gradually whitelist intrinsics which are known to be safe.

Differential Revision: https://reviews.llvm.org/D33414

git-svn-id: https://llvm.org/svn/llvm-project/polly/trunk@305185 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/PPCGCodeGeneration.cpp
test/GPGPU/unknown-fn-call-not-copied-into-kernel.ll [new file with mode: 0644]