[PATCH] D48803: Place the BlockAddress type in the program address space
Dylan McKay via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 27 04:29:41 PDT 2020
dylanmckay requested changes to this revision.
dylanmckay added inline comments.
This revision now requires changes to proceed.
================
Comment at: llvm/lib/AsmParser/LLParser.cpp:3394
+ nullptr, "", nullptr, GlobalValue::NotThreadLocal,
+ M->getDataLayout().getProgramAddressSpace());
+ }
----------------
bjope wrote:
> arsenm wrote:
> > Why wouldn't this come from the parent function? You should be able to mix functions with different address spaces in the same module
> (Maybe @arichardson got a different reason, but sharing my point-of-view here anyway.)
>
> While it's possible to annotate calls and functions definitions with non-zero program address spaces, I think one need to be consistent. I don't think we really support multiple program address spaces (is there an actual use case for supporting that?).
>
> I'm also not exactly sure what you mean by "parent function". The addrspce in the resulting pointer type need to match the addrspace of the function referenced in the first argument of the blockaddress. And that function has not been defined yet, since we are inside the "!F" clause.
>
> I guess we have to trust the datalayout if the function hasn't been defined yet (or use some kind of forward ref and backtrack to fill in addrspace to get the correct type later). I wonder if we'd get some kind of type error later if we assume that datalayout is correct here, and we find a different addrspace when finding the function definition later?
>
> (We also got the usual problem that if datalayout is set by a datalayout definition that comes later in the ll file we haven't parsed the datalayout yet. But if I remember correclty that is a general problem also for the function definitions etc.)
>
> I'm also not exactly sure what you mean by "parent function". The addrspce in the resulting pointer type need to match the addrspace of the function referenced in the first argument of the blockaddress. And that function has not been defined yet, since we are inside the "!F" clause.
I suspect @arsenm is suggesting that the address space be copied from the `LLParserPerFunctionState* PFS` argument this function has.
For example, replace `M->getDataLayout().getProgramAddressSpace()` with `PFS->getFunction()->getFunctionType()->getPointerAddressSpace()`
- [`PerFunctionState::getFunction` documentation](https://ldhldh.myds.me:10081/docs/llvm700/classllvm_1_1_l_l_parser_1_1_per_function_state.html#a9b14016c1937d715c8f305742547764e)
This seems like a better alternative, as it means that if a function did opt to use a different address space from the program address space in the data layout, the blockaddresses within it will use that same address space rather than assuming the one from the datalayout.
This also makes an assumption about the address space of the target function, although I feel the case for that assumption is stronger than the current one of "assume address space from datalayout" as the address space from the parent function could be considered "closer to the source". Indeed, we directly lookup the actual address space for this block address in this branch as this is the case for when the actual function has not been defined yet and so the address space information is not available.
Please make this replacement and then the patch should be good to go.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D48803/new/
https://reviews.llvm.org/D48803
More information about the llvm-commits
mailing list