aboutsummaryrefslogtreecommitdiff
path: root/llvm/docs/LangRef.rst
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-08-16 15:22:57 +0200
committerNikita Popov <npopov@redhat.com>2023-11-01 10:46:31 +0100
commit6b8ed78719d0ae8eff55b937a976602f3a748697 (patch)
tree777ad1d42bb2be569d79dc46b66a66c05119878c /llvm/docs/LangRef.rst
parent50dec541f328a251c2830421f354e4439e635def (diff)
downloadllvm-6b8ed78719d0ae8eff55b937a976602f3a748697.zip
llvm-6b8ed78719d0ae8eff55b937a976602f3a748697.tar.gz
llvm-6b8ed78719d0ae8eff55b937a976602f3a748697.tar.bz2
[IR] Add writable attribute
This adds a writable attribute, which in conjunction with dereferenceable(N) states that a spurious store of N bytes is introduced on function entry. This implies that this many bytes are writable without trapping or introducing data races. See https://llvm.org/docs/Atomics.html#optimization-outside-atomic for why the second point is important. This attribute can be added to sret arguments. I believe Rust will also be able to use it for by-value (moved) arguments. Rust likely won't be able to use it for &mut arguments (tree borrows does not appear to allow spurious stores). In this patch the new attribute is only used by LICM scalar promotion. However, the actual motivation for this is to fix a correctness issue in call slot optimization, which needs this attribute to avoid optimization regressions. Followup to the discussion on D157499. Differential Revision: https://reviews.llvm.org/D158081
Diffstat (limited to 'llvm/docs/LangRef.rst')
-rw-r--r--llvm/docs/LangRef.rst24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index d867982..9c8e264 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -1532,6 +1532,30 @@ Currently, only the following parameter attributes are defined:
If a function reads from a writeonly pointer argument, the behavior is
undefined.
+``writable``
+ This attribute is only meaningful in conjunction with ``dereferenceable(N)``
+ or another attribute that implies the first ``N`` bytes of the pointer
+ argument are dereferenceable.
+
+ In that case, the attribute indicates that the first ``N`` bytes will be
+ (non-atomically) loaded and stored back on entry to the function.
+
+ This implies that it's possible to introduce spurious stores on entry to
+ the function without introducing traps or data races. This does not
+ necessarily hold throughout the whole function, as the pointer may escape
+ to a different thread during the execution of the function. See also the
+ :ref:`atomic optimization guide <Optimization outside atomic>`
+
+ The "other attributes" that imply dereferenceability are
+ ``dereferenceable_or_null`` (if the pointer is non-null) and the
+ ``sret``, ``byval``, ``byref``, ``inalloca``, ``preallocated`` family of
+ attributes. Note that not all of these combinations are useful, e.g.
+ ``byval`` arguments are known to be writable even without this attribute.
+
+ The ``writable`` attribute cannot be combined with ``readnone``,
+ ``readonly`` or a ``memory`` attribute that does not contain
+ ``argmem: write``.
+
.. _gc:
Garbage Collector Strategy Names