649 Commits

Author SHA1 Message Date
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
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
24fc579f57 [Attributor][NFC] Exit manifestAttrs early if there are no attributes 2023-07-03 10:07:03 -07:00
Johannes Doerfert
7b330fa80b [Attributor][NFCI] Avoid creating unnecessary AAs
If the IR has a boolean attribute, or the function is not IPO amendable,
we can avoid creating AAs that would just be forced into a trivial
fixpoint anyway. Since we check boolean IR attributes via
`AA::hasAssumedIRAttr`, we don't need AAs even if they would be fixed
optimistic right away. The only change is in the dependency graph
ordering as we move AAs around to simplify the code flow. There is no
reason for the order we seed AAs, so this order is just as fine.
2023-06-29 23:08:11 -07:00
Johannes Doerfert
5186c2f9f8 [Attributor][NFC] Introduce IRP helpers for Attr and Arg handling 2023-06-29 13:32:06 -07:00
Johannes Doerfert
1716924ccf [Attributor][NFC] Introduce a flag to skip liveness checks
While we can disallow AAs, liveness checks are everywhere and if the
user doesn't want them it is costly to go through just to find out
everything is assumed live.
2023-06-29 09:18:36 -07:00
Johannes Doerfert
339a1f3ce3 [Attributor] Avoid more AAs through IR implication 2023-06-24 00:35:31 -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
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
23dafbb1e5 [Attributor] Remove the iteration count verification
It was never really useful to track #iterations, though it helped during
the initial development. What we should track, in a follow up, are
potentially #updates. That is also what we should restrict instead of
the #iterations.
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
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
Shilei Tian
e0ea44720d [Attributor] Set up a dedicated simplification call back map for GlobalVariable
Currently we don't check call backs for global variable simplification.
What's more, the only way that we can register a simplification call back for
global variable is through its initializer (essentially a `Constant *`). It might
not correspond to the right global variable. In this patch, we set up a dedicated
simplification map for `GlobalVariable`.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D144749
2023-04-21 00:08:35 -04:00
Bjorn Pettersson
a20f7efbc5 Remove several no longer needed includes. NFCI
Mostly removing includes of InitializePasses.h and Pass.h in
passes that no longer has support for the legacy PM.
2023-04-17 13:54:19 +02: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
19529458c4 [Attributor][NFC] Reduce output verbosity 2023-03-20 17:44:23 -07:00
Matt Arsenault
94026ce56d Attributor: Start inferring nofpclass
Some of this is boilerplate which doesn't do anything yet.
2023-03-16 23:19:34 -04:00
Arthur Eubanks
773d663e47 [IPO] Remove various legacy passes
These are part of the optimization pipeline, of which the legacy pass manager version is deprecated and being removed.
2023-02-27 19:06:08 -08:00
Johannes Doerfert
7495a2e51b [Attributor][FIX] Ensure we adjust types properly
When we simplify loads we need to adjust types (esp. null-values)
properly to avoid inconsinstencies down the line. Add a cast and an
error message.

Fixes: https://github.com/llvm/llvm-project/issues/60788
2023-02-16 17:45:56 -08:00
Johannes Doerfert
1763c63254 [Attributor][NFCI] Use a set to track dependences 2023-02-10 11:56:09 -06:00
Johannes Doerfert
76a1919026 [Attributor][NFC] Avoid unnecessary string operations
This caused multiple string operations which we don't need if we do not
create a profile.
2023-02-10 11:56:09 -06:00
Johannes Doerfert
bf9964fb13 [Attributor][NFCI] Create a AAIsDead for the function eagerly 2023-02-10 11:56:09 -06:00
Johannes Doerfert
63b02271a8 [Attributor][NFCI] Avoid spending time resolving kernel reachability queries
We know kernels (generally) cannot be called from within the module. Thus,
for reachability we would need to step back from a kernel which would allow
us to reach anything anyway. Even if a kernel is invoked from another
kernel, values like allocas and shared memory are not accessible. We
implicitly check for this situation to avoid costly lookups.
2023-02-02 13:59:58 -08:00
Johannes Doerfert
c4ad24deee [Attributor][NCFI] Explicitly state what interfering accesses to look for
We used to check the query instructions for effects but that does not
work well with complex accesses we will probably support in the future.
Now we simply let the user decide what accesses to look for.
2023-02-02 13:59:57 -08:00
Johannes Doerfert
1771d81475 [Attributor] Allow to delete (assume) intrinsics outside the SCC 2023-01-23 20:32:07 -08:00
Johannes Doerfert
75728b41f8 [Attributor][FIX] Reachability needs to process the entire worklist 2023-01-23 20:32:06 -08:00
Johannes Doerfert
43c1c59f73 [OpenMP] Merge barrier elimination into AAExecutionDomain
With this patch we track aligned barriers in AAExecutionDomain and also
delete unnecessary barriers there. This allows us to eliminate barriers
across blocks, across functions, and in the presence of complex accesses
that do not force a barrier. Further, we can use the collected
information to enable store-load forwarding in a threaded environment
(follow up patch).

Differential Revision: https://reviews.llvm.org/D140463
2023-01-22 16:34:59 -08:00
Johannes Doerfert
39b9ea5084 [Attributor] Enable tests and ensure all call sites are updated
This reverts commit 9e08b083a09ef4e02fb0a4de2c0d3ddc0eccadde and ensures
signature rewriting also updates dead call sites to avoid the call graph
assertion.
2023-01-12 11:18:53 -08:00
Johannes Doerfert
5d64ad8544 [Attributor][FIX] Avoid creating accidental poison callees
Back with f3ad8cf00e213 we introduced a bug that caused us to skip
callees when we replace uses. This is not sound since subsequent IR
cleanup will assume replacement has happend. As such we created poison
callees for a long while. The original intend of the check was to
prevent call graph invalidation, however, we now properly check if the
instructions (here the call) are inside the SCC or not.
2023-01-12 02:13:08 -08:00
Johannes Doerfert
27944bbbe7 [Attributor][FIX] Avoid deleting (internal) library functions
In CGSCC mode we cannot delete internal library functions, esp.
__kmpc_alloc_shared, or we trigger an assertion. While the assertion is
probably too narrow, we avoid deleting those unused functions for now to
unblock the AMDGPU buildbot.
2023-01-12 01:17:23 -08:00
Johannes Doerfert
cefa5cefdc [OpenMP] Replace ExternalizationRAII with virtual uses
The externalization was always a stopgap solution. One of the drawbacks
is that it is very conservative no matter if we actually require the
functions at the end of the pass. The new concept is more generic and
properly integrates into the dependence graph. Whenever we might need a
function, it has a "virtual use" that cannot be analyzed. If we do not
because of some AA state, there will be a dependence to ensure state
changes trigger revisits of uses, including a potentially new virtual
use.
2023-01-12 00:14:06 -08:00
Johannes Doerfert
74ace2c7ae [Attributor] Ensure no recursive reasoning is used for isAssumedDead
This is a precaution for the future.
2023-01-12 00:14:06 -08:00
Johannes Doerfert
9b7b5482fa [Attributor] Allow AAs to iterate on their own state
Future AAs might need to iterate their own state until they reach a
fixpoint. We do not want to forbid that but we want to avoid negative
effects or bugs once this happens. As a precaution, we now rerun an AA
that did not require outside information. If it does not change anymore
we are done, otherwise the AA needs to iterate some more.
2023-01-11 23:49:10 -08:00
Johannes Doerfert
d7be8227a8 [Attributor][FIX] Improve care when dealing with liveness
This patch adds two checks that have in experiments caused issues. One
was an oversight that allowed new AAs during cleanup to be optimistic.
The other treated functions as functions even if they were used as
values, e.g., in a cast instruction. In such cases we might have assumed
the value is dead if the function is not entered, which isn't true.

The new test functions don't expose a bug but I kept them around.
2023-01-11 23:49:10 -08:00
Johannes Doerfert
96c335e2cc [Attributor] Always ensure the correct AAIsDead object is used
Since the Attributor::isAssumedDead lookups can jump between functions
we need to potentially replace a given FnLivenessAA for it to be useful.
2023-01-11 23:49:09 -08:00
Guillaume Chatelet
48f5d77eee [NFC] Use TypeSize::getKnownMinValue() instead of TypeSize::getKnownMinSize()
This change is one of a series to implement the discussion from
https://reviews.llvm.org/D141134.
2023-01-11 16:36:39 +00:00
Johannes Doerfert
31ad4dbcb9 Reapply "[Attributor] Introduce AA[Intra/Inter]Reachability"
This reverts commit e425a4c45618fcfa8ffb13be4ddfaa5d28aa38f1 after the
memory leak has been fixed.
2023-01-10 12:29:24 -08:00
Johannes Doerfert
1b9ba5856a [Attributor] Allow cfg reasoning for thread-local objects
If an object (=memory) is thread-local we do not need to worry about
threading effects.
2023-01-09 16:40:20 -08:00
Shilei Tian
acd22b2751 [AAUnderlyingObjects] Introduce an AA for getting underlying objects of a pointer
This patch introduces a new AA `AAUnderlyingObjects`. It is basically like a wrapper
AA of the function `AA::getAssumedUnderlyingObjects`, but it can recursively do
query if the underlying object is an indirect access, such as a phi node or a select
instruction.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D141164
2023-01-08 16:45:50 -05:00
Johannes Doerfert
81f3deec19 [Attributor][FIX] Ensure to delete all AAs
Before we might have missed calling the destructor on an abstract
attribute if it was created outside the seeding or update phase.
All AAs are now in the AAMap and we can use it to delete them all.
2022-12-17 17:45:25 -08:00
Mitch Phillips
e425a4c456 Revert "[Attributor] Introduce AA[Intra/Inter]Reachability"
This reverts commit fc21f2d7bae2e0be630470cc7ca9323ed5859892.

This patch broke the ASan buildbot. See
https://reviews.llvm.org/rGfc21f2d7bae2e0be630470cc7ca9323ed5859892 for
more information.
2022-12-16 17:56:48 -08:00
Fangrui Song
21c4dc7997 std::optional::value => operator*/operator->
value() has undesired exception checking semantics and calls
__throw_bad_optional_access in libc++. Moreover, the API is unavailable without
_LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS).

This fixes clang.
2022-12-17 00:42:05 +00:00
Vasileios Porpodas
dc891846b8 [NFC] Cleanup: Replace Function::getBasicBlockList().splice() with Function::splice()
This is part of a series of patches that aim at making Function::getBasicBlockList() private.

Differential Revision: https://reviews.llvm.org/D139984
2022-12-14 15:34:19 -08:00
Johannes Doerfert
fc21f2d7ba [Attributor] Introduce AA[Intra/Inter]Reachability
We had two AAs for reachability but it was very cumbersome to extend
them. We also had some fallback to use LLVM-core mechanisms and cache
the result. The new design shares the query code and interface nicely
between AAIntraFnReachability and AAInterFnReachability.

As part of the rewrite we also added the ExclusionSet to the queries.
2022-12-13 19:38:15 -08:00
Sameer Sahasrabuddhe
5ac633d2de [NFC][AAPointerInfo] rename OffsetAndSize to RangeTy
This is in preparation for future changes that introduce an actual list of
ranges per Access, to be called a RangeList.

Differential Revision: https://reviews.llvm.org/D138644
2022-12-08 12:14:28 +05:30
Johannes Doerfert
2a607d912e [Attributor] Delete stores only required for assumes (with the assumes)
We keep loads if they feed into assumes but even if we cannot predict
their value we should delete them if the associated stores are deleted
as well. This is not perfect but prioritizes deleting stores now.
2022-12-07 22:26:11 -08:00
Johannes Doerfert
db86f45478 [Attributor] Introduce assumption accesses in AAPointerInfo
Assumptions can help us reason about memory content. This patch teaches
AAPointerInfo to reason about memory assumptions of the following form:

```
%x = load %ptr
... code not writing memory, may include branches ...
%c = %x == %val
... code not writing memory, may include branches ...
llvm.assume(%c)
```

Assumption accesses are recognized from the involved load (%x above).

Assumption accesses are treated special and neither as ordinary read or
write. We use read encoding with an extra flag. Reads are not impacting
other reads or writes. Writes could do that. We don't want assumptions
to impact other writes as they themselves only confirm a value, not
write it. So the "other" write might be required as the assumption only
confirms the effect of that write.
2022-12-07 15:39:07 -08:00
Fangrui Song
75801e3b45 Transforms/IPO: llvm::Optional => std::optional 2022-12-05 07:07:19 +00:00