[NVPTX] Add NVPTXLowerStructArgs pass
authorJustin Holewinski <jholewinski@nvidia.com>
Wed, 5 Nov 2014 18:19:30 +0000 (18:19 +0000)
committerJustin Holewinski <jholewinski@nvidia.com>
Wed, 5 Nov 2014 18:19:30 +0000 (18:19 +0000)
commite459c0bf653ad494bcfad323d00c0afe7bf33b66
tree1acea36edfff45617c8097f587910b23e1a2646f
parentbad06b13bac2c7f59d804c8f90caedc63978276d
[NVPTX] Add NVPTXLowerStructArgs pass

This works around the limitation that PTX does not allow .param space
loads/stores with arbitrary pointers.

If a function has a by-val struct ptr arg, say foo(%struct.x *byval %d), then
add the following instructions to the first basic block :

%temp = alloca %struct.x, align 8
%tt1 = bitcast %struct.x * %d to i8 *
%tt2 = llvm.nvvm.cvt.gen.to.param %tt2
%tempd = bitcast i8 addrspace(101) * to %struct.x addrspace(101) *
%tv = load %struct.x addrspace(101) * %tempd
store %struct.x %tv, %struct.x * %temp, align 8

The above code allocates some space in the stack and copies the incoming
struct from param space to local space. Then replace all occurences of %d
by %temp.

Fixes PR21465.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221377 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/NVPTX/CMakeLists.txt
lib/Target/NVPTX/NVPTX.h
lib/Target/NVPTX/NVPTXLowerStructArgs.cpp [new file with mode: 0644]
lib/Target/NVPTX/NVPTXTargetMachine.cpp
test/CodeGen/NVPTX/bug21465.ll [new file with mode: 0644]