495 Commits

Author SHA1 Message Date
Shilei Tian
bcba20b5d0 [Attributor] Add AAAddressSpace to deduce address spaces
This patch adds initial support for the `AAAddressSpace` abstract
attributor interface to deduce and query address space information for a
pointer. We simply query the underlying objects that a pointer can point
to and find a common address space if they exist. This is the minimal
support for the interface, we currently manifest changes on loads and
stores. Additionally we should use the target transform information to
deduce if an address space transformation is a no-op for the target
machine when calculating compatibility.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D120586
2023-07-12 15:47:41 -04:00
Shilei Tian
f3bd221adc [NFC] clang-format attributor related files 2023-07-09 22:37:30 -04:00
Johannes Doerfert
ab513fe63b [Attributor] Ensure call sites with missing callees are tracked 2023-07-09 19:25:09 -07:00
Kazu Hirata
60db0b8d3a [IPO] Fix uused-variable warnings
This patch fixes:

  llvm/lib/Transforms/IPO/AttributorAttributes.cpp:2038:10: error:
  unused variable 'IsKnown' [-Werror,-Wunused-variable]
2023-07-09 17:54:30 -07:00
Johannes Doerfert
ba7cc56782 [Attributor] Port AANoRecurse to the isImpliedByIR interface 2023-07-09 16:04:22 -07:00
Johannes Doerfert
18d9f7ebba [Attributor] Port AANoReturn to the isImpliedByIR interface 2023-07-09 16:04:22 -07:00
Johannes Doerfert
c272728624 [Attributor] Port AANoSync to the isImpliedByIR interface 2023-07-09 16:04:21 -07:00
Johannes Doerfert
c33fa5a6f8 [Attributor] Port AANoUnwind to the isImpliedByIR interface 2023-07-09 16:04:21 -07:00
Johannes Doerfert
6e7eb729c0 [Attributor] Port AAMustProgress to the checkAndQueryIRAttr interface 2023-07-09 16:04:21 -07:00
Johannes Doerfert
0348652cb0 [Attributor] Port AAWillReturn to the checkAndQueryIRAttr interface 2023-07-09 16:04:21 -07:00
Johannes Doerfert
5163779232 [Attributor] Port AANoFree to the isImpliedByIR interface 2023-07-09 16:04:20 -07:00
Johannes Doerfert
ebec3dd1bf [Attributor] Port AANoCapture to the isImpliedByIR interface
AANoCapture is now the first non-boolean AA that is always queried via
the new APIs and not created manually.

We explicitly do not manifest nocapture for `null` and `undef` anymore.
2023-07-09 16:04:20 -07:00
Johannes Doerfert
59fd610558 [Attributor] Port AANoUndef to the isImpliedByIR interface 2023-07-09 16:04:20 -07:00
Johannes Doerfert
aae749b275 [Attributor] Port AANoAlias to the isImpliedByIR interface
As part of this we do not annotate literal `null` and `undef/poison` as
`noalias` anymore. This was not really needed anyway.
2023-07-09 16:04:20 -07:00
Johannes Doerfert
02a4fcec6b [Attributor] Port AANonNull to the isImpliedByIR interface
AANonNull is now the first AA that is always queried via the new APIs
and not created manually. Others will follow shortly to avoid trivial
AAs whenever possible.

This commit introduced some helper logic that will make it simpler to
port the next one. It also untangles AADereferenceable and AANonNull
such that the former does not keep a handle on the latter. Finally,
we stop deducing `nonnull` for `undef`, which was incorrect.
2023-07-09 16:04:19 -07:00
Johannes Doerfert
7e77e812ab [Attributor][FIX] Require the store to be aligned for value propagation 2023-07-07 16:38:34 -07:00
Johannes Doerfert
d081296212 [Attributor] Check all NoFPClass attributes found in the IR 2023-07-06 21:30:04 -07:00
Johannes Doerfert
3b04d119b2 [Attributor][NFCI] Use AA::hasAssumedIRAttr for NoSync 2023-07-06 21:30:04 -07:00
Johannes Doerfert
aafdc9ea26 [Attributor] Make isImpliedByIR and hasAssumedIRAttr more useful
Checking more than one attribute kind was never done and we want to
later check the IR w/o creating an AA as fallback.
2023-07-03 16:05:16 -07:00
Johannes Doerfert
f086f383d8 [Attributor][NFCI] Move attribute collection and manifest to Attributor
Before, we checked and manifested attributes right in the IR. This was
bad as we modified the IR before the manifest stage. Now we can
add/remove/inspect attributes w/o going to the IR (except for the
initial query).
2023-07-03 11:57:30 -07:00
Johannes Doerfert
77dbd1d712 [Attributor][NFCI] Manifest assumption attributes explicitly
We had some custom manifest for assumption attributes but we use the
generic manifest logic. If we later decide to curb duplication (of
attributes on the call site and callee), we can do that at a single
location and for all attributes.

The test changes basically add known `llvm.assume` callee information to
the call sites.
2023-07-03 11:57:29 -07:00
Johannes Doerfert
b672c602c7 [Attributor][NFCI] Merge MemoryEffects explicitly
We had some custom handling for existing MemoryEffects but we now move
it to the place we check other existing attributes before we manifest
new ones. If we later decide to curb duplication (of attributes on the
call site and callee), we can do that at a single location and for all
attributes.

The test changes basically add known `memory` callee information to the
call sites.
2023-07-03 11:57:29 -07:00
Johannes Doerfert
41086f38ec [Attributor][NFC] Check for the Explorer first to avoid traversing uses 2023-07-03 10:07:03 -07:00
Johannes Doerfert
d6fa3b374f [Attributor] Remove now obsolete initialization code
With the helpers in place to judge AAs [1] we can remove the custom
rolled initialization checking code. This exposed a minor oversight in
the AAMemoryLocation where we did not check the IR before we gave up for
a declaration.

[1] d33bca840a
2023-06-29 13:32:06 -07:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00
Johannes Doerfert
339a1f3ce3 [Attributor] Avoid more AAs through IR implication 2023-06-24 00:35:31 -07:00
Johannes Doerfert
7d16a35c83 [Attributor][FIX] Do not ignore refinement for IPO
This is just a cleanup commit, a follow up will make this way more
structured.
2023-06-23 20:10:12 -07:00
Johannes Doerfert
732bdb6073 [Attributor] Avoid the type check in getCalledFunction
We now consistently use `CallBase::getCalledOperand` rather than
`getCalledFunction`, as we do not want the type checked performed by the
latter. This exposed various missing checks to handle mismatches
properly, but it is good to have them explicit now.

In a follow up we might want to flag certain calls as UB, but for now,
we allow everything to cut down on unexpected differences.
2023-06-23 20:10:12 -07:00
Johannes Doerfert
badafc53c6 [Attributor] Check IR attributes before creating new AAs
Instead of creating an AA for an IR attribute we can first check if it
is implied/known. If so, we can save the time to create the AA, figure
out it is implied, fix it, and later manifest it in the IR
(redundantly). Other IR attributes can be added to the list in
`AA::hasAssumedIRAttr` later on, for now we support 8 different ones.
2023-06-23 17:21:21 -07:00
Johannes Doerfert
e9fc399db3 [Attributor][NFCI] Use pointers to pass around AAs
This will make it easier to create less trivial AAs in the future as we
can simply return `nullptr` rather than an AA with in invalid state.
2023-06-23 17:21:20 -07:00
Johannes Doerfert
767e429a80 [Attributor][NFC] Allow to restrict the Attributor to cached passes
If the user wants to avoid running additional passes, they can now
initialize the AnalysisGetter accordingly.
2023-06-23 16:32:36 -07:00
Johannes Doerfert
bed6a6e7e0 [Attributor][NFC] Make the MustBeExecutedContextExplorer optional
For a lightweight pass we do not want to instantiate or use the
MustBeExecutedContextExplorer. This simply allows such a configuration.
While at it, the explorer is now allocated with the bump allocator.
2023-06-13 16:49:56 -07:00
Johannes Doerfert
6d8f14f001 [Attributor][FIX] Ensure unknown accesses are honored
If we had an unknown access but already some prior knowledge (known), we
could have ended up ignoring the unknown access all together. The
problem is that we track unknown not as all locations but separately.
This patch bridges the gap and expands the unknown bits to "all bits"
when we add an access.

Fixes: https://github.com/llvm/llvm-project/issues/63291
2023-06-13 16:21:56 -07:00
Johannes Doerfert
cb17c48fdd [Attributor] Identify and remove no-op fences
The logic and implementation follows the removal of no-op barriers. If
the fence is not making updates visible, either to the world or the
current thread, it is not needed. Said differently, the fences we remove
do not establish synchronization (happens-before) edges.
This allows us to eliminate some of the regression caused by:
  https://reviews.llvm.org/D145290
2023-06-05 17:14:00 -07:00
Johannes Doerfert
dbbe9b3776 [Attributor] Create AAMustProgress for the mustprogress attribute
Derive the mustprogress attribute based on the willreturn attribute
or the fact that all callers are mustprogress.

Differential Revision: https://reviews.llvm.org/D94740
2023-06-05 16:33:52 -07:00
Johannes Doerfert
d037b237de [Attributor] Teach AAMemoryLocation about constant GPU memory
AS(4), when targeting GPUs, is constant. Accesses to constant memory are
(historically) not treated as "memory accesses", hence we should deduce
`memory(none)` for those.
2023-05-18 13:27:43 -07:00
Kazu Hirata
1ca0cb717a [llvm] Replace None with std::nullopt in comments (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-04-25 23:53:32 -07:00
Doru Bercea
1a58c3d601 Avoid capping heap to stack optimization for __kmpc_alloc_shared allocations.
Review: https://reviews.llvm.org/D148849
2023-04-21 09:27:53 -04:00
Johannes Doerfert
119a94b5ae [Attributor][FIX] Ensure to cache all intra procedural AA queries
We failed to cache queries without an exclusion set that resulted in
non-reachable results. That is obviously bad as changes to liveness can
influence the result.

Fixes: https://github.com/llvm/llvm-project/issues/61883
2023-04-17 18:01:04 -07:00
Nikita Popov
9fe78db4cd [FunctionAttrs] Fix nounwind inference for landingpads
Currently, FunctionAttrs treats landingpads as non-throwing, and
will infer nounwind for functions with landingpads (assuming they
can't unwind in some other way, e.g. via resum). There are two
problems with this:

* Non-cleanup landingpads with catch/filter clauses do not
  necessarily catch all exceptions. Unless there are catch ptr null
  or filter [0 x ptr] zeroinitializer clauses, we should assume
  that we may unwind past this landingpad. This seems like an
  outright bug.
* Cleanup landingpads are skipped during phase one unwinding, so
  we effectively need to support unwinding past them. Marking these
  nounwind is technically correct, but not compatible with how
  unwinding works in reality.

Fixes https://github.com/llvm/llvm-project/issues/61945.

Differential Revision: https://reviews.llvm.org/D147694
2023-04-14 11:46:00 +02:00
Nikita Popov
c508e93327 [InstSimplify] Remove unused ORE argument (NFC) 2023-04-14 10:38:32 +02:00
Johannes Doerfert
7ccf4d1ad7 [Attributor][FIX] Account for blocks w/o predecessors 2023-03-27 21:30:23 -07:00
Ishaan Gandhi
aead502b11 [Attributor] Add convergent abstract attribute
This patch adds the AANonConvergent abstract attribute. It removes the
convergent attribute from functions that only call non-convergent
functions.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D143228
2023-03-20 22:33:50 -07:00
Johannes Doerfert
c0f3a3d7b5 [Attributor][FIX] Avoid H2S on GPUs if the pointer can be shared
If the stack is not accessible by other threads, e.g., on a GPU, we need
to ensure heap-2-stack will not create a stack version of a pointer that
might be passed to another thread. Since passing through memory is by
default transparent, we need to register a callback and inspect stores
we might look through explicitly.
2023-03-20 17:44:24 -07:00
Johannes Doerfert
b89558a2ae [OpenMP][FIX] Properly track and lookup Execution Domains
This is a two part fix. First, we need two Execution Domains (ED) to
track the values of a function. One for incoming values and one for
outgoing values. This was conflated before. Second, at the function
entry we need to look at the incoming information from call sites not
iterate over non-existing predecessors.
2023-03-20 17:44:24 -07:00
Johannes Doerfert
0fc63d4e64 [Attributor][FIX] Ensure loop PHI replacements are dynamically unique
Similar to loads, PHIs can be used to introduce non-dynamically unique
values into the simplification "algorithm". We need to check that PHIs
do not carry such a value from one iteration into the next as can cause
downstream reasoning to fail, e.g., downstream could think a comparison
is equal because the simplified values are equal while they are defined
in different loop iterations. Similarly, instructions in cycles are now
conservatively treated as non-dynamically unique. We could do better but
I'll leave that for the future.

The change in AAUnderlyingObjects allows us to ignore dynamically unique
when we simply look for underlying objects. The user of that AA should
be aware that the result might not be a dynamically unique value.
2023-03-20 17:44:24 -07:00
Matt Arsenault
221512e7b2 Revert "Attributor: Add isAtFixpoint part of nofpclass handling"
This reverts commit 78313e8531c412f4b57b23e0ee04ea4a131e8d71.

Accidentally pushed
2023-03-17 08:15:28 -04:00
Matt Arsenault
d2404ea6ce Attributor: Assume handling for nofpclass 2023-03-17 07:39:40 -04:00
Matt Arsenault
78313e8531 Attributor: Add isAtFixpoint part of nofpclass handling 2023-03-17 07:02:47 -04:00
Matt Arsenault
6705f634f6 Attributor: Start looking at uses when inferring nofpclass
Pretty much just copy pasted from noundef handling
2023-03-17 07:02:41 -04:00