Hi,
We have a processor with separate memory for some specific types. Those types always live in that memory, whether they are global or local (we have two stacks). Only special instructions can access that special memory. This means - we must know whether a pointer points to a normal or special memory. For example, we have two versions of memcpy, one for normal memory and one for special memory. Before opaque pointers, we determined that by using a pointer type. With opaque pointers, we need another mechanism.
It sounds like the address space is the right tool for it. However, LLVM doesn’t support two stacks. LLVM assumes that all allocas are in the same address space. That address space is part of DataLayout, which cannot have target-specific logic to return different address spaces for different types.
Do we miss any good ideas?
CC @urnathan for awareness
At the IR level, we do allow alloca instructions to have multiple different address-spaces.
It was implemented for wasm, for a very similar purpose, see ⚙ D101045 [IR][Verifier] Relax restriction on alloca address spaces or ⚙ D101140 [WebAssembly][CodeGen] IR support for WebAssembly local variables and WebAssemblyFrameLowering::getLocalForStackObject in llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
1 Like
Yeah, I saw that the alloca
instr has a parameter for the address space, which helps a lot here.
There is no infra for choosing alloca
’s address space depending on a type, though. I guess that is the missing piece we need to implement. It seems to be the most reasonable path here. Do you have any suggestions on where to insert that logic?
DataLayout::getAllocaAddrSpace
doesn’t sound like a good place to insert the logic.