Best practices of moving pointers to addrspace(1) for RewriteStatepointsForGC pass

Hi all,

In order to run RewriteStatepointsForGC pass, we have to allocate the pointers on addrspace(1) 1. So for a given LLVM IR we can allocate all pointers in addrspace(1) (as shown in example 1) or we can allocate only the necessary pointers in addrspace(1) and use addrspacecast when it is needed (as shown in example 2).

So can you please suggest me what is the best way of doing this?

example 1:

define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) gc “statepoint-example” {
call void @foo()
%_1 = alloca i8 addrspace(1)*
store i8 addrspace(1)* %obj, i8 addrspace(1)** %_1
ret i8 addrspace(1)* %obj
}

example 2:

define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) gc “statepoint-example” {
call void @foo()
%_1 = alloca i8*
%obj_cast = addrspacecast i8 addrspace(1)* %obj to i8*
store i8* %obj_cast, i8** %_1
ret i8 addrspace(1)* %obj
}

I’m not an LLVM developer, but here’s my insight:

I think this depends on the target semantics of addrspace(1), as defined in the datalayout. If the stack addrspace is 1, then example 1 is correct. If the stack addrspace is 0 (the default), then example 2 might be correct; whether example 2 is correct then depends on whether an addrspacecast from 1 to 0 is valid.