I would like my optimization pass to change an object’s address space that is created by llvm.lifetime.start intrinsic. Because I want to be able to identify them later in a codegen pass. I can get a pointer from the intrinsic using CallInst::getArgOperand() function. However, I don’t know what to do with it (or if it is the pointer that I want). How can I change its address space? If there is an easier way to “mark” that object, I would like to know that too.
There’s no easy way to change the address space of a value, though I would like there to be one. You have to specifically handle all users and use mutateType. AMDGPUPromoteAlloca is an example of a pass which does this, although it’s somewhat buggy. If you’re just trying to identify the pointer with an address space, you should be fine using an addrspacecast.
What are you trying to do with this? I don’t see why you would need special handling just to identify these. In a codegen pass you can look at the LIFETIME_START/LIFETIME_END operand which will give you the frame index which you can identify users with.
My goal is to place thread-private variables in a different address space than shared variables in an OpenMP program. I found out that lifetime.start instrinsic starts the lifetime of shared objects before entering a parallel region (in IR). So I am thinking about changing the address space of all variables excluding those.
If I do it with a codegen pass, how can I look for lifetime_start/end operands (since they are defined in IR level)? And when I do an addrspacecast, how do I preserve the type?
This sounds like a frontend problem to me. These should be emitted in the correct address space to begin with when the IR is originally produced. What address spaces are you trying to use for these? Right now there is an unfortunate constraint on alloca that it only produces addrspace(0) pointers. I thought the lifetime intrinsics were only for allocas, so I’m not sure why you would be seeing them on some kind of shared global variable.