<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/llvm/lib/Analysis/CaptureTracking.cpp, branch main</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/'/>
<entry>
<title>[IR] Introduce !captures metadata (#160913)</title>
<updated>2025-10-01T06:58:47+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-10-01T06:58:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=63ca8483d0efc544c5b8c4484d36a64c3b3ff210'/>
<id>63ca8483d0efc544c5b8c4484d36a64c3b3ff210</id>
<content type='text'>
This introduces `!captures` metadata on stores, which looks like this:

```
store ptr %x, ptr %y, !captures !{!"address", !"read_provenance"}
```

The semantics are the same as replacing the store with a call like this:
```
call void @llvm.store(ptr captures(address, read_provenance) %x, ptr %y)
```

This metadata is intended for annotation by frontends -- it's not
something we can feasibly infer at this point, as it would require
analyzing uses of the pointer stored in memory.

The motivating use case for this is Rust's `println!()` machinery, which
involves storing a reference to the value inside a structure. This means
that printing code (including conditional debugging code), can inhibit
optimizations because the pointer escapes. With the new metadata we can
annotate this as a read-only capture, which has less impact on
optimizations.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This introduces `!captures` metadata on stores, which looks like this:

```
store ptr %x, ptr %y, !captures !{!"address", !"read_provenance"}
```

The semantics are the same as replacing the store with a call like this:
```
call void @llvm.store(ptr captures(address, read_provenance) %x, ptr %y)
```

This metadata is intended for annotation by frontends -- it's not
something we can feasibly infer at this point, as it would require
analyzing uses of the pointer stored in memory.

The motivating use case for this is Rust's `println!()` machinery, which
involves storing a reference to the value inside a structure. This means
that printing code (including conditional debugging code), can inhibit
optimizations because the pointer escapes. With the new metadata we can
annotate this as a read-only capture, which has less impact on
optimizations.</pre>
</div>
</content>
</entry>
<entry>
<title>[CaptureTracking] Fix handling for non-returning read-only calls (#158979)</title>
<updated>2025-09-17T09:27:06+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-09-17T09:27:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=0969e2c4203ce5ba7c6a042c6542ce45c0ebbae4'/>
<id>0969e2c4203ce5ba7c6a042c6542ce45c0ebbae4</id>
<content type='text'>
We currently infer `captures(none)` for calls that are read-only,
nounwind and willreturn. As pointed out in
https://github.com/llvm/llvm-project/issues/129090, this is not correct
even with this set of pre-conditions, because the function could
conditionally cause UB depending on the address.

As such, change this logic to instead report `captures(address)`. This
also allows dropping the nounwind and willreturn checks, as these can
also only capture the address.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We currently infer `captures(none)` for calls that are read-only,
nounwind and willreturn. As pointed out in
https://github.com/llvm/llvm-project/issues/129090, this is not correct
even with this set of pre-conditions, because the function could
conditionally cause UB depending on the address.

As such, change this logic to instead report `captures(address)`. This
also allows dropping the nounwind and willreturn checks, as these can
also only capture the address.</pre>
</div>
</content>
</entry>
<entry>
<title>[llvm] Remove unused includes of SmallSet.h (NFC) (#154893)</title>
<updated>2025-08-22T17:33:46+00:00</updated>
<author>
<name>Kazu Hirata</name>
<email>kazu@google.com</email>
</author>
<published>2025-08-22T17:33:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=11b4f110e0f9f1a0f987faa121c594af1bcd43cc'/>
<id>11b4f110e0f9f1a0f987faa121c594af1bcd43cc</id>
<content type='text'>
We just replaced SmallSet&lt;T *, N&gt; with SmallPtrSet&lt;T *, N&gt;, bypassing
the redirection found in SmallSet.h.  With that, we no longer need to
include SmallSet.h in many files.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We just replaced SmallSet&lt;T *, N&gt; with SmallPtrSet&lt;T *, N&gt;, bypassing
the redirection found in SmallSet.h.  With that, we no longer need to
include SmallSet.h in many files.</pre>
</div>
</content>
</entry>
<entry>
<title>[llvm] Replace SmallSet with SmallPtrSet (NFC) (#154068)</title>
<updated>2025-08-18T14:01:29+00:00</updated>
<author>
<name>Kazu Hirata</name>
<email>kazu@google.com</email>
</author>
<published>2025-08-18T14:01:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=07eb7b76928d6873c60859a0339591ed9e0f512a'/>
<id>07eb7b76928d6873c60859a0339591ed9e0f512a</id>
<content type='text'>
This patch replaces SmallSet&lt;T *, N&gt; with SmallPtrSet&lt;T *, N&gt;.  Note
that SmallSet.h "redirects" SmallSet to SmallPtrSet for pointer
element types:

  template &lt;typename PointeeType, unsigned N&gt;
class SmallSet&lt;PointeeType*, N&gt; : public SmallPtrSet&lt;PointeeType*, N&gt;
{};

We only have 140 instances that rely on this "redirection", with the
vast majority of them under llvm/. Since relying on the redirection
doesn't improve readability, this patch replaces SmallSet with
SmallPtrSet for pointer element types.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch replaces SmallSet&lt;T *, N&gt; with SmallPtrSet&lt;T *, N&gt;.  Note
that SmallSet.h "redirects" SmallSet to SmallPtrSet for pointer
element types:

  template &lt;typename PointeeType, unsigned N&gt;
class SmallSet&lt;PointeeType*, N&gt; : public SmallPtrSet&lt;PointeeType*, N&gt;
{};

We only have 140 instances that rely on this "redirection", with the
vast majority of them under llvm/. Since relying on the redirection
doesn't improve readability, this patch replaces SmallSet with
SmallPtrSet for pointer element types.</pre>
</div>
</content>
</entry>
<entry>
<title>[CaptureTracking] Handle ptrtoaddr</title>
<updated>2025-08-08T21:22:42+00:00</updated>
<author>
<name>Alexander Richardson</name>
<email>alexrichardson@google.com</email>
</author>
<published>2025-08-08T21:22:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=3cf7262876cf261b5704bcf1d70d2de13d595e15'/>
<id>3cf7262876cf261b5704bcf1d70d2de13d595e15</id>
<content type='text'>
Unlike ptrtoint, ptrtoaddr does not capture provenance, only the address.
Note: As defined by the LangRef, we always treat `ptrtoaddr` as a
location-independent address capture since it is a direct inspection of the
pointer address.

Reviewed By: nikic

Pull Request: https://github.com/llvm/llvm-project/pull/152221
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Unlike ptrtoint, ptrtoaddr does not capture provenance, only the address.
Note: As defined by the LangRef, we always treat `ptrtoaddr` as a
location-independent address capture since it is a direct inspection of the
pointer address.

Reviewed By: nikic

Pull Request: https://github.com/llvm/llvm-project/pull/152221
</pre>
</div>
</content>
</entry>
<entry>
<title>[AA] Take read-only provenance captures into account (#143097)</title>
<updated>2025-06-12T12:13:15+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-06-12T12:13:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=bc7fafbeea08bf8cd9a18fa10d3d3bc63f0c45a3'/>
<id>bc7fafbeea08bf8cd9a18fa10d3d3bc63f0c45a3</id>
<content type='text'>
Update the AA CaptureAnalysis providers to return CaptureComponents, so
we can distinguish between full provenance and read-only provenance
captures.

Use this to restrict "other" memory effects on call from ModRef to Ref.

Ideally we would also apply the same reasoning for escape sources, but
the current API cannot actually convey the necessary information (we can
only say NoAlias or MayAlias, not MayAlias but only via Ref).</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Update the AA CaptureAnalysis providers to return CaptureComponents, so
we can distinguish between full provenance and read-only provenance
captures.

Use this to restrict "other" memory effects on call from ModRef to Ref.

Ideally we would also apply the same reasoning for escape sources, but
the current API cannot actually convey the necessary information (we can
only say NoAlias or MayAlias, not MayAlias but only via Ref).</pre>
</div>
</content>
</entry>
<entry>
<title>[AA] Merge isNonEscapingLocalObject() into SimpleCaptureAnalysis (NFC) (#142971)</title>
<updated>2025-06-06T07:40:57+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-06-06T07:40:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=10dd83d274e04bc974770d2ad8bb8e2b850a74d6'/>
<id>10dd83d274e04bc974770d2ad8bb8e2b850a74d6</id>
<content type='text'>
isNonEscapingLocalObject() is only used by SimpleCaptureAnalysis and
tightly integrated with its implementation (in particular its cache), so
inline and simplify the implementation.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
isNonEscapingLocalObject() is only used by SimpleCaptureAnalysis and
tightly integrated with its implementation (in particular its cache), so
inline and simplify the implementation.</pre>
</div>
</content>
</entry>
<entry>
<title>[CaptureTracking] Remove dereferenceable_or_null special case (#135613)</title>
<updated>2025-04-17T10:44:57+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-04-17T10:44:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=d69ee885cccecb49f0b288ec634186c35c8ecfb5'/>
<id>d69ee885cccecb49f0b288ec634186c35c8ecfb5</id>
<content type='text'>
Remove the special case where comparing a dereferenceable_or_null
pointer with null results in captures(none) instead of
captures(address_is_null).

This special case is not entirely correct. Let's say we have an
allocated object of size 2 at address 1 and have a pointer `%p` pointing
either to address 1 or 2. Then passing `gep p, -1` to a
`dereferenceable_or_null(1)` function is well-defined, and allows us to
distinguish between the two possible pointers, capturing information
about the address.

Now that we ignore address captures in alias analysis, I think we're
ready to drop this special case. Additionally, if there are regressions
in other places, the fact that this is inferred as address_is_null
should allow us to easily address them if necessary.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Remove the special case where comparing a dereferenceable_or_null
pointer with null results in captures(none) instead of
captures(address_is_null).

This special case is not entirely correct. Let's say we have an
allocated object of size 2 at address 1 and have a pointer `%p` pointing
either to address 1 or 2. Then passing `gep p, -1` to a
`dereferenceable_or_null(1)` function is well-defined, and allows us to
distinguish between the two possible pointers, capturing information
about the address.

Now that we ignore address captures in alias analysis, I think we're
ready to drop this special case. Additionally, if there are regressions
in other places, the fact that this is inferred as address_is_null
should allow us to easily address them if necessary.</pre>
</div>
</content>
</entry>
<entry>
<title>[CaptureTracking][AA] Only consider provenance captures (#130777)</title>
<updated>2025-03-13T08:54:36+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-03-13T08:54:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=de895751d2a250fb4127e1c7ea0863dd8e234325'/>
<id>de895751d2a250fb4127e1c7ea0863dd8e234325</id>
<content type='text'>
For the purposes of alias analysis, we should only consider provenance
captures, not address captures. To support this, change (or add)
CaptureTracking APIs to accept a Mask and StopFn argument. The Mask
determines which components we are interested in (for AA that would be
Provenance).

The StopFn determines when we can abort the walk early. Currently, we
want to do this as soon as any of the components in the Mask is
captured. The purpose of making this a separate predicate is that in the
future we will also want to distinguish between capturing full
provenance and read-only provenance. In that case, we can only stop
early once full provenance is captured. The earliest escape analysis
does not get a StopFn, because it must always inspect all captures.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
For the purposes of alias analysis, we should only consider provenance
captures, not address captures. To support this, change (or add)
CaptureTracking APIs to accept a Mask and StopFn argument. The Mask
determines which components we are interested in (for AA that would be
Provenance).

The StopFn determines when we can abort the walk early. Currently, we
want to do this as soon as any of the components in the Mask is
captured. The purpose of making this a separate predicate is that in the
future we will also want to distinguish between capturing full
provenance and read-only provenance. In that case, we can only stop
early once full provenance is captured. The earliest escape analysis
does not get a StopFn, because it must always inspect all captures.</pre>
</div>
</content>
</entry>
<entry>
<title>[CaptureTracking] Take non-willreturn calls into account</title>
<updated>2025-02-28T10:15:28+00:00</updated>
<author>
<name>Nikita Popov</name>
<email>npopov@redhat.com</email>
</author>
<published>2025-02-28T09:23:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=abd97d9685c07c4787ff22e56c0a7b8963630063'/>
<id>abd97d9685c07c4787ff22e56c0a7b8963630063</id>
<content type='text'>
We can leak one bit of information about the address by either
diverging or not.

Part of https://github.com/llvm/llvm-project/issues/129090.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We can leak one bit of information about the address by either
diverging or not.

Part of https://github.com/llvm/llvm-project/issues/129090.
</pre>
</div>
</content>
</entry>
</feed>
