jdoerfert created this revision. jdoerfert added reviewers: arsenm, spatel, efriedma, lebedev.ri, fhahn, rnk, hfinkel, regehr, nlopes. Herald added subscribers: dmgreen, bollu, wdng. Herald added a project: LLVM.
After the discussion in D79454 <https://reviews.llvm.org/D79454> it seemed clear we need to clarify the `byval` attribute semantics. This is an attempt to make it consistent with the de-facto behavior and expectations of different LLVM passes. The clarified rules are phrased such that: - an empty function with a `byval` argument is correctly classified as `readnone` (which it is today: https://godbolt.org/z/nePXM6). - a call of a `readnone` function with a `byval` argument is not classified as `readnone` (which it is today: https://godbolt.org/z/dDfQ5r) - we can eliminate the Clang rules that prevent the effect of `pure` or `const` on functions that take a `byval` argument (as they are circumvented by the middle-end anyway) I doubt this will break existing backends or other parts but actually avoid us creating (temporary) broken IR during the middle-end optimizations. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D79636 Files: llvm/docs/LangRef.rst Index: llvm/docs/LangRef.rst =================================================================== --- llvm/docs/LangRef.rst +++ llvm/docs/LangRef.rst @@ -1043,10 +1043,18 @@ is unable to modify the value in the caller. This attribute is only valid on LLVM pointer arguments. It is generally used to pass structs and arrays by value, but is also valid on pointers to - scalars. The copy is considered to belong to the caller not the - callee (for example, ``readonly`` functions should not write to - ``byval`` parameters). This is not a valid attribute for return - values. + scalars The copy is conceptually made on the call edge. This means that + the pointer argument at the call site refers to the original memmory and + the pointer argument in the callee is refering to the copy. Attributes on + the call site argument and function argument are associated with the + original and copied memory respectively. The copy is considered to be local + memory of the callee. That means, a callee can wrtie a ``byval`` parameter + and still be ``readonly`` or ``readnone`` because the write is, similar to + a write to an ``alloca``, not visible from the outside. To create the copy + the original memory, thus the call site argument, is always read. This + effect is also associated with the call site, thus it cannot be `readnone` + or `writeonly` regardless of the callee. This is not a valid attribute for + return values. The byval attribute also supports an optional type argument, which must be the same as the pointee type of the argument.
Index: llvm/docs/LangRef.rst =================================================================== --- llvm/docs/LangRef.rst +++ llvm/docs/LangRef.rst @@ -1043,10 +1043,18 @@ is unable to modify the value in the caller. This attribute is only valid on LLVM pointer arguments. It is generally used to pass structs and arrays by value, but is also valid on pointers to - scalars. The copy is considered to belong to the caller not the - callee (for example, ``readonly`` functions should not write to - ``byval`` parameters). This is not a valid attribute for return - values. + scalars The copy is conceptually made on the call edge. This means that + the pointer argument at the call site refers to the original memmory and + the pointer argument in the callee is refering to the copy. Attributes on + the call site argument and function argument are associated with the + original and copied memory respectively. The copy is considered to be local + memory of the callee. That means, a callee can wrtie a ``byval`` parameter + and still be ``readonly`` or ``readnone`` because the write is, similar to + a write to an ``alloca``, not visible from the outside. To create the copy + the original memory, thus the call site argument, is always read. This + effect is also associated with the call site, thus it cannot be `readnone` + or `writeonly` regardless of the callee. This is not a valid attribute for + return values. The byval attribute also supports an optional type argument, which must be the same as the pointee type of the argument.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits