535 Commits

Author SHA1 Message Date
Johannes Doerfert
9207a90be5 [Attributor] Do not expand dead indirect call sites 2023-09-01 22:14:38 -07:00
Johannes Doerfert
a8ac969b10 [Attributor][NFC] Use common helper to avoid duplication
Many AAs translated callee information to the call site explicitly but
they now all use the helper we already had for callee return to call
site return propagation. In a follow up the helper is going to be
extended to handle multiple callees.
2023-09-01 21:04:03 -07:00
Johannes Doerfert
ac0d3869c5 [Attributor][NFC] Simplify the helper APIs
We have various helpers to propagate information. This patch cleans up
the API to allow less template parameters and more uniform handling.
2023-09-01 21:04:02 -07:00
Johannes Doerfert
6b95126b9b [Attributor][NFC] Rename AACallSiteReturnedFromReturned
In a follow up we'll use it for more than "callee return" -> "call site
return" deduction, effectively allowing "callee" -> "call site".
2023-09-01 21:04:02 -07:00
Johannes Doerfert
37642714ed [Attributor][FIX] Support non-0 AS for function pointers 2023-09-01 17:17:51 -07:00
Johannes Doerfert
8dd3b4581c [Attributor][NFC] Clean include order 2023-08-31 19:32:52 -07:00
Matt Arsenault
850ec7bbb1 Attributor: Try to propagate concrete denormal-fp-math{-f32}
Allow specialization of functions with "dynamic" denormal modes to a
known IEEE or DAZ mode based on callers. This should make it possible
to implement a is-denormal-flushing-enabled test using
llvm.canonicalize and have it be free after LTO.

https://reviews.llvm.org/D156129
2023-08-31 08:26:32 -04:00
Johannes Doerfert
6f0ca01c57 [Attributor] Introduce AAGlobalValueInfo to track global value uses
GlobalValues are often interesting, especially if they have local
linkage. We now track all uses of those and refine potential callees
with it. Effectively, if an internal function cannot reach an indirect
call site, it cannot be a potential callee, even if it has its address
taken.
2023-08-29 22:41:54 -07:00
Johannes Doerfert
498887ae8a [Attributor] Introduce the closed world flag
The Attributor user can now set the closed world flag
(`AttributorConfig.IsClosedWorldModule` or
`-attributor-assume-closed-world`) in order to specialize call edges
based only on available callees. That means, we assume all functions are
known and hence all potential callees must be declared/defined in the
module. We will use this for GPUs and LTO cases, but for now the user
has to set it via a flag.
2023-08-29 22:35:17 -07:00
Johannes Doerfert
936661084c [Attributor][NFC] Add querying AA to shouldSpecializeCallSiteForCallee
The callback might require an AA, e.g., to ask other AAs for information
in a way that will enfore dependences.
2023-08-29 22:35:16 -07:00
Matt Arsenault
d2a06ef05a Attributor: Allow refining of callsite attributes that already have nofpclass
https://reviews.llvm.org/D158419
2023-08-28 13:54:49 -04:00
Johannes Doerfert
e5313ef55f [Attributor] Filter potential callees based on noundef arguments
If a potential callee has more arguments than the call site, the values
passed will be `poison`. If the potential callee would exhibit UB for
such `undef` argument, e.g., they are marked `noundef`, we can rule the
potential callee out.
2023-08-25 14:36:43 -07:00
Johannes Doerfert
d0b5523632 [Attributor] Introduce limit for indirect call specialization
The user can now limit the number of indirect calls specialized for a
given call site with `-attributor-max-specializations-per-call-base=N`
or the AttributorConfig callback. We further attach the `!callee`
metadata if all remaining callees are known.
2023-08-25 14:36:42 -07:00
Johannes Doerfert
f118e3bcca [Attributor][NFC] Fix typo 2023-08-25 14:36:42 -07:00
Johannes Doerfert
d2c37fc4f7 [Attributor][FIX] Avoid dangling stack references in map
The old code did not account for new queries during an update, which
caused us to leave stack RQIs in the map. We are now explicit about
temporary vs non-temporary RQIs.

Fixes: https://github.com/llvm/llvm-project/issues/64959
2023-08-24 16:28:10 -07:00
Johannes Doerfert
9a80ebe63c [Attributor] Simplify assumptions "stores"
When we add an assumption about memory to the AAPointerInfo bins, we
should simplify the assumed value, like we do for stores.
2023-08-23 15:14:14 -07:00
Johannes Doerfert
78b8f1f78f [Attributor][FIX] Remove the visited set from AAInterFnReachability
The visited set was used to not visit the same function twice, however,
the (new) algorithm requires we do since we start the queries at
different call sites.
2023-08-23 11:48:18 -07:00
Johannes Doerfert
3e19416e4e [Attributor][FIX] Initialize variable 2023-08-18 21:47:57 -07:00
Johannes Doerfert
9c08e76f3e [Attributor] Introduce AAIndirectCallInfo
AAIndirectCallInfo will collect information and specialize indirect call
sites. It is similar to our IndirectCallPromotion but runs as part of
the Attributor (so with assumed callee information). It also expands
more calls and let's the rest of the pipeline figure out what is UB, for
now. We use existing call promotion logic to improve the result,
otherwise we rely on the (implicit) function pointer cast.

This effectively "fixes" #60327 as it will undo the type punning early
enough for the inliner to work with the (now specialized, thus direct)
call.

Fixes: https://github.com/llvm/llvm-project/issues/60327
2023-08-18 16:44:05 -07:00
Johannes Doerfert
361b536bbc [Attributor] Simplify switches with more than one potential condition
Before, we allowed the condition to be simplified to a simple constant
only, otherwise we assumed all successors are live. Now we allow
multiple constants, and mark the default successor as dead accordingly.
2023-08-17 22:42:38 -07:00
Johannes Doerfert
bfa1afb81c [OpenMPOpt] Improve __kmpc_alloc_shared handling
We know that __kmpc_alloc_shared is by construction matched with a
unique __kmpc_free_shared. Making the compiler aware of these facts
helps to avoid mallocs/allocas.

Fixes: https://github.com/llvm/llvm-project/issues/64551
2023-08-17 19:25:32 -07:00
Johannes Doerfert
5a406b63e9 [Attributor][FIX] Stores capture, even for readonly functions
If we end up visiting a store use, we couldn't follow to the "reloads".
The capture effect of a store is more than memory as the reloads are
unknown.

Fixes: https://github.com/llvm/llvm-project/issues/64613
2023-08-11 14:17:33 -07:00
Johannes Doerfert
d70ab63bc2 [Attributor][NFCI] Filter uninteresting accesses early
We can prevent the costly interference check if an access is not
interesting in the first place. Let the user decide via a callback.
2023-08-04 11:36:58 -07:00
Johannes Doerfert
78daab0a85 [Attributor][NFCI] Compute ReachabilityQueryInfo hash once and on demand 2023-08-03 00:12:46 -07:00
Johannes Doerfert
2a20c64a73 [Attributor][NFCI] Use DominatorTree to short circuit reachability queries
If we do not have exlusion blocks and the target is live, we only need
to reach a dominating block.
2023-08-03 00:12:46 -07:00
Johannes Doerfert
4fd9874696 [Attributor][NFCI] Exit reachability queries early if the target is not live 2023-08-03 00:12:45 -07:00
Johannes Doerfert
578ab3312f [Attributor][NFCI] Use a uniform necessary query to avoid a unique one
If we cannot reach the target from the entry of a function without
exclusion set, we cannot reach it at all. This can allow us to filter
unique queries based on a uniform one.
2023-08-03 00:12:45 -07:00
Bjorn Pettersson
e6e9a87534 Drop some typed pointer handling
Differential Revision: https://reviews.llvm.org/D156739
2023-08-02 12:08:37 +02:00
Johannes Doerfert
a598e39063 [AAInterFnReachabilityFunction][NFC] Remove unused members 2023-07-26 00:03:06 -07:00
Johannes Doerfert
b3fec1067a [Attributor] Improve NonNull deduction
We can improve our deduction if we stop at PHI and select instructions
and also iterate the returned values explicitly. The latter helps with
isImpliedByIR deductions.
2023-07-25 20:31:21 -07:00
Johannes Doerfert
88b5d23021 [Attributor] Allow multiple LHS/RHS values when simplifying comparisons
We use to deal with multiple values but not in the handleCmp function.
Now we also allow multiple simplified operands there.
2023-07-25 20:31:21 -07:00
Johannes Doerfert
0cd8a28941 [Attributor][FIX] No IntraFnReachability does not mean unreachable
Also, first check inter fn reachability as it seems to be cheaper in
practise.
2023-07-25 17:47:33 -07:00
Johannes Doerfert
ba0be698c5 [Attributor][NFC] Rename variable to be less confusing 2023-07-25 17:47:33 -07:00
Johannes Doerfert
e31724f1a6 [Attributor] Check readonly call sites for nosync in AANoSync
See @nosync_convergent_callee_test() in nosync.ll. The other changes are
call sites now annotated with `nosync`.
2023-07-25 17:47:33 -07:00
Johannes Doerfert
c3f30687b5 [Attributor][NFCI] Add a shortcut for constants 2023-07-19 10:27:01 -07:00
Alexander Batashev
17508cbcc6 [NFC] Fix builds on recent GCC with C++20 enabled
The following pattern fails on recent GCC versions with -std=c++20 flag passed
and succeeds with -std=c++17. Such behavior is not observed on Clang 16.0.

```c++
template <typename T>
struct Foo {
    Foo<T>(int a) {}
};
```

This patch removes template parameter from constructor in two occurences to
make the following command complete successfully:
bazel build -c fastbuild --cxxopt=-std=c++20 --host_cxxopt=-std=c++20 @llvm-project//llvm/...

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D154782
2023-07-18 19:44:06 +03:00
Nikita Popov
7be7f23269 [llvm] Remove uses of getWithSamePointeeType() (NFC) 2023-07-18 12:07:09 +02:00
Johannes Doerfert
cd69b0cc88 [Attributor][FIX] Initialize out parameters 2023-07-17 16:26:32 -07:00
Johannes Doerfert
f26d05d306 [Attributor] Replace AAReturnedValues with AAPotentialValuesReturned
The very first AA, at least the first one in order, is not necessary
anymore. `AAReturnedValues` was from a different time; one might say, a
simpler time.

It was rewriten once to use `Attribute::getAssumedSimplifiedValues`,
which is what the replacement, `AAPotentialValuesReturned`, does too.
To match the old behavior we needed to avoid the helper
`AAReturnedFromReturnedValues` and iterate the return instructions
explicitly, however, it is still less complexity than it was before.
`AAReturnedFromReturnedValues` and `getAssumedSimplifiedValues` now
allow users to stop at PHI and select nodes or to ignore those and look
through. `AANoFPClass` will stop at select and phi nodes to read the
fast math flags.

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

Differential Revision: https://reviews.llvm.org/D154917
2023-07-17 10:43:23 -07:00
Johannes Doerfert
a5d194e975 [Attributor][NFC] Improve debug message 2023-07-17 10:43:22 -07:00
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