itanium-cxx-abi / cxx-abi

C++ ABI Summary
508 stars 96 forks source link

Add `[[trivial_abi]]` attribute #155

Open philnik777 opened 2 years ago

philnik777 commented 2 years ago

Clang implements [[clang::trivial_abi]] (docs) to allow passing classes that are non-trivial for the purposes of calls as-if they were trivial. For example, this allows passing std::unique_ptrs in registers instead of on the stack, which results in a significant performance and code size win (https://godbolt.org/z/aTsG34abP).

It would be nice to standardize the attribute to allow it to be used across compilers.

I think it should be enough to modify the definition of non-trivial for the purposes of calls to something like:

A type is considered non-trivial for the purposes of calls if:

This mostly is the list of things when [[clang::trivial_abi]] is ignored. Suggestions to simplify the definition are welcome. Should there be a note that classes marked [[trivial_abi]] have to be trivially relocatable (move + destroy are equivalent to a memcpy)?

CC @ldionne @jwakely