[PATCH] D40023: [RISCV] Implement ABI lowering

Alex Bradbury via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 13 01:54:56 PST 2018


asb added inline comments.


================
Comment at: lib/CodeGen/TargetInfo.cpp:8913
+  }
+  return getNaturalAlignIndirect(Ty, /*ByVal=*/true);
+}
----------------
efriedma wrote:
> asb wrote:
> > efriedma wrote:
> > > The spec says "Aggregates larger than 2✕XLEN bits are passed by reference and are replaced in the argument list with the address".  That's not byval.
> > The LLVM backend lowers byval in that way. Given that at this point we have a trivial data type (plain struct or similar) which is copied-by-value by C semantics, the only difference is whether the generated IR indicates implicit copying with 'byval' or relies on the caller explicitly doing the copy. For some reason I thought 'byval' was preferred, but looking again it seems uncommon to do it this way. I've changed it to false - thanks for spotting this.
> "byval" generally means the value is memcpy'ed into the argument list (so there is no pointer in the argument list). This is useful for handling C calling conventions which allow excessively large structs to be passed in the argument list, so the backend can emit a memcpy rather than expanding the operation into straight-line code.  The RISCV backend handling of byval is wrong, in the sense that it isn't consistent with what any other backend does.
> 
> This isn't relevant to the RISC-V C calling convention, but you should probably fix the backend at some point to avoid future confusion.
If I understand your concern correctly, it's that the RISCV backend passes a pointer to the byval copied argument rather than passing it direct on the stack? Isn't that consistent with what the Sparc, Lanai and the PPC backends do? It also seems consistent with my reading of the description of the byval attribute in the langref - a hidden copy is made. Whether that hidden copy is passed direct or a pointer to it is passed (which is consistent with the RISC-V calling convention for large values) seems an orthogonal concern.


https://reviews.llvm.org/D40023





More information about the cfe-commits mailing list