summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/Attributor.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [Attributor] `willreturn` + `noreturn` = UBJohannes Doerfert2019-11-021-4/+1
| | | | | | | | | | | We gave up on `noreturn` if `willreturn` was known for a while but we now again try to always derive `noreturn`. This is useful because a function that is `noreturn` + `willreturn` is basically dead as executing it would lead to undefined behavior (UB). This came up in the IPConstantProp cases where a function only contained a unreachable but was not marked `noreturn` which caused missed opportunities down the line.
* [Attributor][FIX] Make AAValueSimplifyArgument aware of thread-dependent ↵Johannes Doerfert2019-11-021-3/+13
| | | | | | | constants As in IPConstantProp, thread-dependent constants need not be propagated over callbacks. Took the comment and test from there, see also D56447.
* [Attributor][FIX] Handle the default case of a switchJohannes Doerfert2019-11-021-5/+5
| | | | | | In D69605 only the "cases" of a switch were handled but if none matched we did not make the default case life. This is fixed now and properly tested (with code from IPConstantProp/user-with-multiple-uses.ll).
* [Attributor][FIX] Make value simplification aware of "complicated" attributesJohannes Doerfert2019-11-021-0/+18
| | | | | | We cannot simply replace arguments that carry attributes like `nest`, `inalloca`, `sret`, and `byval`. Except for the last one, which we can replace if it is not written, we bail for now.
* [Attributor][NFCI] Avoid unnecessary work except for testingJohannes Doerfert2019-11-021-1/+12
| | | | | | | | Trying to deduce information for declarations and calls sites of declarations is not useful in practice but only for testing. Add a flag that disables this by default but also enable it in the tests. The misc.ll test will verify the flag "works" as expected.
* [Attributor][FIX] NoCapture is not a subsuming propertyJohannes Doerfert2019-11-021-5/+12
| | | | | | We cannot look at the subsuming positions and take their nocapture bit as shown with the two tests for which we derived nocapture on the call site argument and readonly on the argument of the second before.
* [Attributor][NFCI] Remove obsolete codeJohannes Doerfert2019-11-021-24/+0
| | | | | The code in question does not add anything as the class is a subclass of AACallSiteReturnedFromReturnedAndMustBeExecutedContext already.
* [Attributor] Really use the executed-contextJohannes Doerfert2019-10-311-14/+29
| | | | | | | | | | | | | | | | | | Before we did not follow casts and geps when we looked at the users of a pointer in the pointers must-be-executed-context. This caused us to fail to determine if it was accessed for sure. With this change we follow such users now. The above extension exposed problems in getKnownNonNullAndDerefBytesForUse which did not always check what the base pointer was. We also did not handle negative offsets as conservative as we have to without explicit loop handling. Finally, we should not derive a huge number if we access a pointer that was traversed backwards first. The problems exposed by this functional change are already tested in the existing test cases as is the functional change. Differential Revision: https://reviews.llvm.org/D69647
* [Attributor] Make AANonNull perform context sensitive queriesJohannes Doerfert2019-10-311-21/+6
| | | | | | | | | | | | | | | | | Summary: In order to get context sensitivity from isKnownNonZero we need to provide a context instruction *and* a dominator tree. The latter is passed now to which actually allows to remove some initialization code. Tests taken from PR43833. Reviewers: uenoku, sstefan1 Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69595
* [Attributor][NFCI] Improve the usage of IntegerStatesJohannes Doerfert2019-10-311-12/+8
| | | | | Setting the upper bound directly in the state can be beneficial and simplifies the logic. This also exposed more copy&paste type errors.
* [Attributor] Make liveness "edge-based"Johannes Doerfert2019-10-311-126/+186
| | | | | | | | | | | | | | | | Summary: If control is transferred to a successor is the key question when it comes to liveness. The new implementation puts that question in the focus and thereby providing a clean way to assume certain CFG edges are dead or instructions will not transfer control. Reviewers: sstefan1, uenoku Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69605
* [Attributor] Liveness for valuesJohannes Doerfert2019-10-311-31/+321
| | | | | | | | | | | | | | | | | | | | | | | Summary: This patch introduces liveness (AAIsDead) for all positions, thus for all kinds of values. For now, we say an instruction is dead if it would be removed assuming all users are dead. A call site return is different as we just look at the users. If all call site returns have been eliminated, the return values can return undef instead of their original value, eliminating uses. We try to recursively delete dead instructions now and we introduce a simple check interface for use-traversal. This is the idea tried out in D68626 but implemented in the right way. Reviewers: uenoku, sstefan1 Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68925
* [Attributor][NFC] Do not delete dead blocks but "clear" themJohannes Doerfert2019-10-311-3/+6
| | | | | | | Deleting blocks will require us to deal with dead edges, e.g., `br i1 false, label %live, label %dead` explicitly. For now we just clear the blocks and move on. This will be revisited once we actually fold branches.
* [Attributor] Add "free"-based heap2stack deductionJohannes Doerfert2019-10-301-18/+43
| | | | | | | | | | | | | | | Summary: If there is a unique free of the allocated that has to be reached from the malloc, we can apply the heap-2-stack transformation even if the pointer escapes. Reviewers: hfinkel, sstefan1, uenoku Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68958
* [Attributor][NFC] Eagerly mark attributes as fixed.Johannes Doerfert2019-10-301-4/+14
| | | | | | If an attribute did not query any optimistic (=non-fixed) information to justify its state, we know the attribute state will not change anymore. Thus, we can indicate an optimistic fixpoint.
* [Attributor][NFC] Do not record dependences on fixed attributesJohannes Doerfert2019-10-301-0/+6
| | | | | Since fixed values cannot change, we do not need to wait for it to happen, we will never notify the dependent attribute anyway.
* [Attributor][NFC] Simplify the IRPosition interfaceJohannes Doerfert2019-10-301-4/+6
| | | | | | | We pretended IRPosition came either as mutable or immutable objects while they are basically always immutable, with a single (existing) unfortunate exceptions. This patch cleans up the uses to deal with the immutable version.
* [Attributor] Make IntegerState more flexibleJohannes Doerfert2019-10-281-26/+17
| | | | | | | | | | | | | To make IntegerState more flexible but also less error prone we split it up into (1) incrementing, (2) decrementing, and (3) bit-tracking states. This adds functionality compared to before and disallows misuse, e.g., "incrementing" updates on a bit-tracking state. Part of the change is a single operator in the base class which simplifies helper functions that deal with states. There are certain functional changes but all of which should actually be corrections.
* [Attributor][FIX] Silence sign-compare warningJohannes Doerfert2019-10-211-1/+1
| | | | llvm-svn: 375384
* [Attributor] Teach AANoCapture to use information in-flight more aggressivelyJohannes Doerfert2019-10-211-8/+63
| | | | | | | | | AAReturnedValues, AAMemoryBehavior, and AANoUnwind, can provide information that helps during the tracking or even justifies no-capture. We now use this information and enable no-capture in some test cases designed a long while a ago for these cases. llvm-svn: 375382
* [Alignment][NFC] Value::getPointerAlignment returns MaybeAlignGuillaume Chatelet2019-10-151-1/+2
| | | | | | | | | | | | | | | | | Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68398 llvm-svn: 374889
* [Alignment] Migrate Attribute::getWith(Stack)AlignmentGuillaume Chatelet2019-10-151-1/+2
| | | | | | | | | | | | | | | | | | | Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, jdoerfert Reviewed By: courbet Subscribers: arsenm, jvesely, nhaehnle, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D68792 llvm-svn: 374884
* [Attributor] Shortcut no-return through will-returnJohannes Doerfert2019-10-131-8/+11
| | | | | | | | No-return and will-return are exclusive, assuming the latter is more prominent we can avoid updates of the former unless will-return is not known for sure. llvm-svn: 374739
* [Attributor][FIX] NullPointerIsDefined needs the pointer AS (AANonNull)Johannes Doerfert2019-10-131-3/+18
| | | | | | Also includes a shortcut via AADereferenceable if possible. llvm-svn: 374737
* [Attributor][MemBehavior] Fallback to the function state for argumentsJohannes Doerfert2019-10-131-8/+17
| | | | | | | | | Even if an argument is captured, we cannot have an effect the function does not have. This is fine except for the special case of `inalloca` as it does not behave by the rules. TODO: Maybe the special rule for `inalloca` is wrong after all. llvm-svn: 374736
* [Attributor][FIX] Use check prefix that is actually testedJohannes Doerfert2019-10-131-9/+24
| | | | | | | | | | | | | | | | Summary: This changes "CHECK" check lines to "ATTRIBUTOR" check lines where necessary and also fixes the now exposed, mostly minor, problems. Reviewers: sstefan1, uenoku Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68929 llvm-svn: 374735
* [Attributor][FIX] Avoid splitting blocks if possibleJohannes Doerfert2019-10-131-8/+14
| | | | | | | Before, we eagerly split blocks even if it was not necessary, e.g., they had a single unreachable instruction and only a single predecessor. llvm-svn: 374703
* [Attributor][FIX] Remove leftover, now unused, variableJohannes Doerfert2019-10-131-2/+0
| | | | llvm-svn: 374702
* [Attributor] Remove unused verification flagJohannes Doerfert2019-10-131-24/+0
| | | | | | We use the verify max iteration now which is more reliable. llvm-svn: 374701
* [Attributor][NFC] Expose call site traversal without QueryingAAJohannes Doerfert2019-10-131-9/+17
| | | | llvm-svn: 374700
* [Attributor][FIX] Ensure h2s doesn't trigger on escaped pointersJohannes Doerfert2019-10-131-1/+9
| | | | | | | | We do not yet perform h2s because we know something is free'ed but we do it because we know the pointer does not escape. Storing the pointer allows it to escape so we have to prevent that. llvm-svn: 374699
* [Attributor][FIX] Do not apply h2s for arbitrary mallocsJohannes Doerfert2019-10-131-16/+22
| | | | | | | | H2S did apply to mallocs of non-constant sizes if the uses were OK. This is now forbidden through reording of the "good" and "bad" cases in the conditional. llvm-svn: 374698
* [Attributor][FIX] Avoid modifying naked/optnone functionsJohannes Doerfert2019-10-131-5/+0
| | | | | | | | The check for naked/optnone was insufficient for different reasons. We now check before we initialize an abstract attribute and we do it for all abstract attributes. llvm-svn: 374694
* [Attributor] Extend anonymous namespace. NFC.Benjamin Kramer2019-10-121-1/+1
| | | | llvm-svn: 374647
* [Attributor][FIX] Do not replace musstail calls with constantJohannes Doerfert2019-10-111-1/+1
| | | | llvm-svn: 374498
* Fix Wdocumentation warnings. NFCI.Simon Pilgrim2019-10-101-2/+2
| | | | llvm-svn: 374364
* [Attributor][NFC] clang formatJohannes Doerfert2019-10-101-2/+2
| | | | llvm-svn: 374281
* [Attributor] Handle `null` differently in capture and alias logicJohannes Doerfert2019-10-101-4/+21
| | | | | | | | | | | | | | | | | | Summary: `null` in the default address space (=AS 0) cannot be captured nor can it alias anything. We make this clear now as it can be important for callbacks and other cases later on. In addition, this patch improves the debug output for noalias deduction. Reviewers: sstefan1, uenoku Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68624 llvm-svn: 374280
* [Attributor][MustExec] Deduce dereferenceable and nonnull attribute using ↵Hideto Ueno2019-10-081-24/+209
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MustBeExecutedContextExplorer Summary: In D65186 and related patches, MustBeExecutedContextExplorer is introduced. This enables us to traverse instructions guaranteed to execute from function entry. If we can know the argument is used as `dereferenceable` or `nonnull` in these instructions, we can mark `dereferenceable` or `nonnull` in the argument definition: 1. Memory instruction (similar to D64258) Trace memory instruction pointer operand. Currently, only inbounds GEPs are traced. ``` define i64* @f(i64* %a) { entry: %add.ptr = getelementptr inbounds i64, i64* %a, i64 1 ; (because of inbounds GEP we can know that %a is at least dereferenceable(16)) store i64 1, i64* %add.ptr, align 8 ret i64* %add.ptr ; dereferenceable 8 (because above instruction stores into it) } ``` 2. Propagation from callsite (similar to D27855) If `deref` or `nonnull` are known in call site parameter attributes we can also say that argument also that attribute. ``` declare void @use3(i8* %x, i8* %y, i8* %z); declare void @use3nonnull(i8* nonnull %x, i8* nonnull %y, i8* nonnull %z); define void @parent1(i8* %a, i8* %b, i8* %c) { call void @use3nonnull(i8* %b, i8* %c, i8* %a) ; Above instruction is always executed so we can say that@parent1(i8* nonnnull %a, i8* nonnull %b, i8* nonnull %c) call void @use3(i8* %c, i8* %a, i8* %b) ret void } ``` Reviewers: jdoerfert, sstefan1, spatel, reames Reviewed By: jdoerfert Subscribers: xbolva00, hiraditya, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65402 llvm-svn: 374063
* [Attributor] Add helper class to compose two structured deduction.Hideto Ueno2019-10-081-0/+15
| | | | | | | | | | | | | | Summary: This patch introduces a generic way to compose two structured deductions. This will be used for composing generic deduction with `MustBeExecutedExplorer` and other existing generic deduction. Reviewers: jdoerfert, sstefan1 Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66645 llvm-svn: 374060
* [Attributor][NFC] Add debug outputJohannes Doerfert2019-10-071-1/+4
| | | | llvm-svn: 373988
* [Attributor][FIX] Remove initialize calls and add undefsJohannes Doerfert2019-10-071-2/+2
| | | | | | | | | | The initialization logic has become part of the Attributor but the patches that introduced these calls here were in development when the transition happened. We also now clean up (undefine) the macros used to create attributes. llvm-svn: 373987
* [Attributor] Use local linkage instead of internalJohannes Doerfert2019-10-071-4/+4
| | | | | | | Local linkage is internal or private, and private is a specialization of internal, so either is fine for all our "local linkage" queries. llvm-svn: 373986
* [Attributor] Use abstract call sites for call site callbackJohannes Doerfert2019-10-071-23/+37
| | | | | | | | | | | | | | | | Summary: When we iterate over uses of functions and expect them to be call sites, we now use abstract call sites to allow callback calls. Reviewers: sstefan1, uenoku Subscribers: hiraditya, bollu, hfinkel, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67871 llvm-svn: 373985
* [Attributor] Deduce memory behavior of functions and argumentsJohannes Doerfert2019-10-071-3/+480
| | | | | | | | | | | | | | | Deduce the memory behavior, aka "read-none", "read-only", or "write-only", for functions and arguments. Reviewers: sstefan1, uenoku Subscribers: hiraditya, bollu, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67384 llvm-svn: 373965
* [Alignment][NFC] Remove StoreInst::setAlignment(unsigned)Guillaume Chatelet2019-10-031-1/+1
| | | | | | | | | | | | | | | | | Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, bollu, jdoerfert Subscribers: hiraditya, asbirlea, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D68268 llvm-svn: 373595
* [Alignment][NFC] Remove LoadInst::setAlignment(unsigned)Guillaume Chatelet2019-09-301-1/+1
| | | | | | | | | | | | | | | | | Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, jdoerfert Subscribers: hiraditya, asbirlea, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D68142 llvm-svn: 373195
* [Attributor] Implement "norecurse" function attribute deductionHideto Ueno2019-09-211-6/+35
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch introduces `norecurse` function attribute deduction. `norecurse` will be deduced if the following conditions hold: * The size of SCC in which the function belongs equals to 1. * The function doesn't have self-recursion. * We have `norecurse` for all call site. To avoid a large change, SCC is calculated using scc_iterator in InfoCache initialization for now. Reviewers: jdoerfert, sstefan1 Reviewed By: jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67751 llvm-svn: 372475
* Hide implementation details in namespaces.Benjamin Kramer2019-09-171-1/+3
| | | | llvm-svn: 372113
* [Attributor][Fix] Initialize the cache prior to using itJohannes Doerfert2019-09-171-59/+98
| | | | | | | | | | | | | | | | | | | | | Summary: There were segfaults as we modified and iterated the instruction maps in the cache at the same time. This was happening because we created new instructions while we populated the cache. This fix changes the order in which we perform these actions. First, the caches for the whole module are created, then we start to create abstract attributes. I don't have a unit test but the LLVM test suite exposes this problem. Reviewers: uenoku, sstefan1 Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67232 llvm-svn: 372105
OpenPOWER on IntegriCloud