[IR] Introduce dead_on_return attribute
Add `dead_on_return` attribute, which is meant to be taken advantage by the frontend, and states that the memory pointed to by the argument is dead upon function return. As with `byval`, it is supposed to be used for passing aggregates by value. The difference lies in the ABI: `byval` implies that the pointer is explicitly passed as argument to the callee (during codegen the copy is emitted as per byval contract), whereas a `dead_on_return`-marked argument implies that the copy already exists in the IR, is located at a specific stack offset within the caller, and this memory will not be read further by the caller upon callee return – or otherwise poison, if read before being written. RFC: https://discourse.llvm.org/t/rfc-add-dead-on-return-attribute/86871.
This commit is contained in:
@@ -1741,6 +1741,23 @@ Currently, only the following parameter attributes are defined:
|
||||
|
||||
This attribute cannot be applied to return values.
|
||||
|
||||
``dead_on_return``
|
||||
This attribute indicates that the memory pointed to by the argument is dead
|
||||
upon function return, both upon normal return and if the calls unwinds, meaning
|
||||
that the caller will not depend on its contents. Stores that would be observable
|
||||
either on the return path or on the unwind path may be elided.
|
||||
|
||||
Specifically, the behavior is as-if any memory written through the pointer
|
||||
during the execution of the function is overwritten with a poison value
|
||||
upon function return. The caller may access the memory, but any load
|
||||
not preceded by a store will return poison.
|
||||
|
||||
This attribute does not imply aliasing properties. For pointer arguments that
|
||||
do not alias other memory locations, ``noalias`` attribute may be used in
|
||||
conjunction. Conversely, this attribute always implies ``dead_on_unwind``.
|
||||
|
||||
This attribute cannot be applied to return values.
|
||||
|
||||
``range(<ty> <a>, <b>)``
|
||||
This attribute expresses the possible range of the parameter or return value.
|
||||
If the value is not in the specified range, it is converted to poison.
|
||||
|
||||
Reference in New Issue
Block a user