[LLVMdev] Methods on addrspace pointers

Matt Arsenault Matthew.Arsenault at amd.com
Mon Jan 20 15:41:07 PST 2014


On 01/20/2014 03:29 PM, Hal Finkel wrote:
>
> 2. Is there a way to create methods that can be called with pointers
> to different address spaces? It seems there is no way to declare
> these in C++ using GNU attributes, and addrspace() seems to not be
> supported by C++11 attribute syntax, which could possibly express
> this. You can use __attribute__((address_space(N))
>
>
>
> I have already been using that syntax to annotate pointer
> declarations. However I don’t think it can be applied to methods the
> way I was thinking. At least it doesn’t actually change them:
>
>
>
> struct Foo {
> long x;
>
> __attribute__((address_space(7))) void bar(long y) {
> printf("%ld %ld\n", x, y);
> }
> };
>
>
> Generates this declaration still:
>
>
> define linkonce_odr void @_ZN3Foo3barEl(%struct.Foo* %this, i64 %y)
> ssp uwtable align 2
>
>
> Though I think desired behavior would be:
>
>
> define linkonce_odr void @_ZN3Foo3barEl(%struct.Foo addrspace(7) *
> %this, i64 %y) ssp uwtable align 2
>
>
> (actually I think it’s more tricky because the address_space
> attribute could be applying to the return type. I’d think the
> correct way to specify the attribute on “this” would be to put it
> where “const” goes, after the parentheses)
> Does it make sense for 'this' to be in one address space on some functions and in a different address space in other functions? If so, should the address space of 'this' contribute to overload resolution?
>
>   -Hal

Yes it would. The struct itself has no specified address space, but the 
instances of it would.

__attribute__((address_space(1)) Foo f1;
__attribute__((address_space(2)) Foo f2;

f1.bar() and f2.bar() would need to call functions with different 
address spaced this pointers. Support for this would be required to 
support the OpenCL static C++ extension

>
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>






More information about the llvm-dev mailing list