diff options
author | Antonio Frighetto <me@antoniofrighetto.com> | 2025-07-02 09:23:22 +0200 |
---|---|---|
committer | Antonio Frighetto <me@antoniofrighetto.com> | 2025-07-02 09:29:36 +0200 |
commit | f1cc0b607b03548028db3ca57bb057b2599b1711 (patch) | |
tree | bb9c8f0c81f52d3cead1c23ba0a31fde611d697f /llvm/lib/IR/Function.cpp | |
parent | d5608d6751315f2e34a0445ca7f5be44a1520463 (diff) | |
download | llvm-f1cc0b607b03548028db3ca57bb057b2599b1711.zip llvm-f1cc0b607b03548028db3ca57bb057b2599b1711.tar.gz llvm-f1cc0b607b03548028db3ca57bb057b2599b1711.tar.bz2 |
[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.
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r-- | llvm/lib/IR/Function.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 3e7fcbb..7a03663 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -130,6 +130,12 @@ bool Argument::hasByValAttr() const { return hasAttribute(Attribute::ByVal); } +bool Argument::hasDeadOnReturnAttr() const { + if (!getType()->isPointerTy()) + return false; + return hasAttribute(Attribute::DeadOnReturn); +} + bool Argument::hasByRefAttr() const { if (!getType()->isPointerTy()) return false; |