<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/98859>98859</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[PowerPC] [LLD][Compiler] support tail call across modules for ELFv2
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chenzheng1030
</td>
</tr>
</table>
<pre>
This is from https://github.com/llvm/llvm-project/issues/63214#issuecomment-2128605743 and https://github.com/llvm/llvm-project/issues/63214#issuecomment-2128669372
For ELFv2, tail call optimization should be allowed even across modules. The idea is:
(Function A and function B share the TOC; B calls function C which does not share TOC with B.)
1: Changes in the compiler side:
- For the call between A and B, use the `st_other === 1` feature to let linker know that when B is called, the caller A needs to restore the TOC although they share the TOC.
- From ABI: for `st_other == 1`: The local and global entry points are the same, and r2 should be treated as caller-saved for local and global callers."
- inside the compiler, for the call between A and B, we should not use `PPCISD::CALL`, instead `PPCISD::CALL_NOP` should be used to allow the tail call.
- B should set `st_other` to 1
- For the tail call between A and B, use the tail call opcode
2: Changes in the lld linker side:
- no need for the `nop` after `b` even for the b cross the modules. For now, linker will report an error `call to bar lacks nop, can't restore toc`, see https://github.com/llvm/llvm-project/issues/63214#issuecomment-2217053717 and https://github.com/llvm/llvm-project/issues/63214#issuecomment-2219264350
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VV1v4jgU_TXm5arIsfMBD3kgYZFGqraVtu8jJ75gb42NbKdR59evbKDQ2WpXWu1ICEhyP86559xYhKAPFrElVUeq7UJMUTnfjgrtD4X2UFBOF4OT7-2L0gF0gL13R1AxngLhG8J2hO0OOqppWI7uSNjOmLfrz8PJuz9xjITtdAgTBsJ2NWdFSRjPN0Z3PKKND6xgq5pWTclBWPlLqtdr3jBCt4Ruzt875-G3x90bI6yHKLSBURgD7hT1Uf8QUTsLQbnJSBgQhDFuRgn4hhbE6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