Commit Graph

6583 Commits

Author SHA1 Message Date
nate-chandler
2fc7659ed7 Merge pull request #60670 from nate-chandler/lexical_lifetimes/owned_arguments
[SIL] Maintain owned argument lifetimes at inlining.
2023-01-26 18:30:24 -08:00
Andrew Trick
21f69d4741 Revert "At -Onone preserve debug info after splitting loads"
This reverts commit 02f7450759.

Fixes rdar://104667596 (incorrectly reports an error when resolving
initialization out of a switch)
2023-01-26 10:04:05 -08:00
Michael Gottesman
89176928ee Merge pull request #63213 from gottesmm/rdar103271138
[move-only] Implement borrow+struct_extract to restructure transform
2023-01-26 07:19:10 -08:00
swift-ci
281088eb73 Merge pull request #63204 from meg-gupta/ptrauthcodegenpr
Initial support for ptrauth qualified function pointers in C
2023-01-25 22:19:34 -08:00
Meghana Gupta
ba052abec1 Add signed access enforcement to begin_access
This will be used for supporting imported c function pointers with custom __ptrauth qualifier.
2023-01-25 14:03:15 -08:00
Nate Chandler
3277d0e35b [InstUtils] Look through move as copy/cast inst.
Add move_value to the list of instructions through which
getSingleValueCopyOrCast looks.
2023-01-25 11:36:33 -08:00
Andrew Trick
5d0fbaad5c Merge pull request #63210 from atrick/cleanup-prunedliveness
Cleanup PrunedLiveness interface.
2023-01-25 10:13:43 -08:00
Erik Eckstein
7d8bf37e5e change to the new llvm::Optional APIs
This is a follow-up of https://github.com/apple/swift/pull/62217
2023-01-25 09:18:36 +01:00
Andrew Trick
7990dda02b Cleanup PrunedLiveness interface.
In preparation for adding OwnershipLiveness.

Rename Simple LiveRangeSummary to LiveRangeSummary.

Add initializeDefNode helpers to avoid confusion about the argument
type.

Add defBegin/defEnd iterators in MultiDefPrunedLiveness.
2023-01-24 23:26:40 -08:00
Michael Gottesman
a5d7a095d2 [sil] Add the ability to create an ExtendedASTNodeLoc that is only used for diagnostics and not for debugging.
We already have entry points for creating an ExtendedASTNodeLoc with an empty
location for diagnostics and a location for debugging. This does the inverse so
one can emit diagnostics that point at a terminator sourceloc without needing to
add a ReturnInst to the instruction which is illegal and would cause the
SILVerifier to assert.
2023-01-24 16:55:54 -08:00
Michael Gottesman
151d275b1c [sil] Add helper DestructureStruct::getStructDecl().
StructExtract has a similar routine, so it makes sense to add it to destructure
struct as well.
2023-01-24 15:28:12 -08:00
Michael Gottesman
4ad2bc93ba [field-sensitive-pruned-liveness] Some small changes.
Specifically:

1. I added to the documentation at the top of the file that our representation
allows for partial init/reinit of structs/tuples from parts.

2. I renamed SubElementNumber to SubElementOffset. This I think fits the actual
use case better and makes it clearer what one is working with (the offset inside
a type of a subelement of the type).

3. I added some small helpers to TypeSubElementCount and SubElementOffset for
adding/subtracting from them.

4. I added the ability to iterate over just consuming/nonconsuming users in
FieldSensitivePrunedLiveness. Just a useful little helper.
2023-01-24 15:28:12 -08:00
Doug Gregor
d192bfc7e5 Merge pull request #63125 from DougGregor/debug-info-dump-macro-expansion-buffers 2023-01-21 07:43:45 -08:00
Doug Gregor
456fbf84f5 [Debug info] Dump macro expansion buffers to disk for debug info to reference
When emitting debug info that references into a macro expansion, dump
the macro expansion buffer into a file on disk (in the temporary
directory) so that one can see the macro expansion buffers in the
source files themselves.

The test here validates that the generated LLVM IR looks correct, but
I'm having a problem getting LLDB to actually locate the source code
correctly.
2023-01-19 21:30:25 -08:00
John McCall
374c202b99 Add SIL instructions to generate pack indices 2023-01-19 23:57:22 -05:00
John McCall
595d923bd1 Fix doc comment on OpenPackElementInst to match the committed design 2023-01-19 23:57:13 -05:00
John McCall
7825d177a9 [NFC] Introduce NullaryInstructionWithTypeDependentOperandsBase
We have a similar helper class for the unary-but-for case, might
as well have one for the nullary-but-for case.
2023-01-19 23:57:13 -05:00
Erik Eckstein
d96ef3bedd Swift SIL: add some APIs to Location
* `var description`
* `func ==`
* `func hasSameSourceLocation(as:)`
2023-01-16 19:00:09 +01:00
Erik Eckstein
3f457eb1d4 Swift SIL: add IntegerLiteralInst.value 2023-01-16 19:00:09 +01:00
Erik Eckstein
221a16ba17 Swift SIL: add more arguments to Builder.createApply
add the `isNonThrowing` and `isNonAsync` flags and the `specializationInfo`
2023-01-16 19:00:09 +01:00
Erik Eckstein
cf8c68c6c4 Swift SIL: add Type.hasArchetype 2023-01-16 19:00:09 +01:00
Erik Eckstein
230c93df30 SIL Optimizer: add some SIL modification APIs
* `MutatingContext.notifyInvalidatedStackNesting` and `MutatingContext.needFixStackNesting`
* `MutatingContext.tryDeleteDeadClosure`
* `MutatingContext.erase(block:)`
* `Undef.get`
* `BasicBlock.moveAllInstructions`
* `BasicBlock.eraseAllArguments`
* `BasicBlock.moveAllArguments`
* `TermInst.replaceBranchTarget`
2023-01-16 19:00:09 +01:00
Erik Eckstein
edce513580 SIL: simplify replaceBranchTarget
Instead of re-creating all kind of terminator instructions, just re-assign the terminator's successor.
2023-01-16 18:55:35 +01:00
Erik Eckstein
0523dbee9d SILBitFields: don't set bitfields of deleted nodes 2023-01-16 16:16:51 +01:00
Andrew Trick
7dc9405131 Add a visited set for PrunedLiveness guaranteed value. 2023-01-13 14:16:15 -08:00
Andrew Trick
599b1d1ae4 Handle guaranteed phis conservatively in a few more places. 2023-01-13 08:55:16 -08:00
Andrew Trick
5279ac1f34 Document PrunedLiveness to explain guaranteed phis liveness.
In a sense, liveness is wrong for dead guaranteed phis that aren't
enclosed in a separate borrow scope:

     left:           // live-within
       br merge(%v)
     right:          // live-within
       br merge(%v)
     merge(%deadPhi) // dead

But this is the way that liveness layering works. PrunedLiveness
simply doesn't know which phis will "end" liveness. This will be the
job of OwnershipLiveness, which will have safe APIs for situations
where this weirdness matters.
2023-01-13 08:55:16 -08:00
John McCall
37baf9b2dc Add a SIL instruction to open a pack as an element archetype
IRGen not yet done.
2023-01-11 03:11:30 -05:00
John McCall
d673a45c88 More opened-existential vs. local-archetype fixes in SIL 2023-01-11 03:11:30 -05:00
Michael Gottesman
b405782727 Revert change to a comment. 2023-01-09 11:25:51 -08:00
Michael Gottesman
193348694f Merge pull request #62916 from gottesmm/pruned-liveness-boundary
[move-only-addr] Finish field sensitive pruned liveness boundary and use it in the move only address checker.
2023-01-09 08:02:19 -08:00
nate-chandler
fb01580e41 Merge pull request #62873 from nate-chandler/bug/20230105/1
[SSADestroyHoisting] Don't fold over trivial use.
2023-01-09 07:05:22 -08:00
Michael Gottesman
1c459b6c5b [move-only-addr] Wire up the move only address checker to Field Sensitive Pruned Liveness Boundary.
This let me fix an issue around hoisting destroy_addr/store [assign] when
working in multi-block cfgs.

I also added some .sil tests.
2023-01-08 21:51:40 -08:00
Michael Gottesman
0e7b04acf3 [field-pruned-liveness] Add two helper constructors to TypeTreeLeafTypeRange.
The first is a default constructor that initializes both startEltOffset and
endEltOffset to 0. This is used to ensure that we can use certain standard
algorithms that expect to be able to perform a default constructor when
inserting an initial value into a collection.

The second adds the ability to construct a TypeTreeLeafTypeRange for a
SILType/SILFunction if one has a type without an actual value.
2023-01-08 14:54:48 -08:00
Michael Gottesman
c2adaa9b75 [field-pruned-liveness] Add helper for TypeSubElementCount that takes a SILFunction.
This just calls TypeSubElementCount(SILType, SILModule &, TypeExpansionContext)
using the module and type expansion context from the SILFunction.
2023-01-08 14:53:04 -08:00
Michael Gottesman
c16e0cfac8 [sil] Implement helper function SILType::getFieldType(VarDecl *, SILFunction *) const.
This just calls:

```
SILType::getFieldType(VarDecl *, SILModule &, TypeExpansionContext) const
```

using the state in the SILFunction to handle the SILModule and
TypeExpansionContext parameters.

Just trimming down a larger commit into smaller commits.
2023-01-08 14:03:52 -08:00
Michael Gottesman
e6b63fbf3d [pruned-liveness] Change markBlockLive to call the scalar implementation for each bit rather than attempt to do it for all bits at the same time. 2023-01-07 14:29:48 -08:00
Michael Gottesman
82abf02883 [pruned-liveness] Change the internal machinery of updateForUse to use only scalar logic.
I did this by doing the following:

1. I renamed computeUseBlockLiveness to computeScalarUseBlockLiveness and
changed it to take a specific bit that it is testing for.

2. I changed the logic that already existed in this code path that worked scalar
by scalar to use scalar logic rather than call the broken multi-bit at a time
code path.

3. We took advantage of resultingFoundLiveness now only returning the requested
bits instead of all bits. This ensures that we do not run
computeScalarUseBlockLiveness for those unneeded dead bits resulting in liveness
being inappropriately propagated into predecessors.
2023-01-07 14:28:41 -08:00
Michael Gottesman
be50c56f55 [pruned-liveness] Specialize scalar pruned liveness routines
Just a small cleanup that will improve performance in the scalar case which is
important for OSSA utilities.
2023-01-07 14:14:59 -08:00
Michael Gottesman
2637c0b637 [pruned-liveness] Change PrunedLiveBlocks::getLiveness(...) to return only one entry per live bit.
Previously, we would pan the array with isDead. The thinking is that this would
make it easier to bitmask directly against. In practice, this usage was a minor
use case and doing this lead to a bunch of logic mistakes in forthcoming code.
2023-01-07 14:14:59 -08:00
Nate Chandler
b3f033759e [MemAccessUtils] Added PathNode::isPrefixOf.
It's just a passthrough to the same method on IndexTrieNode.
2023-01-05 15:05:38 -08:00
Pavel Yaskevich
449acae01f Merge pull request #62813 from xedin/expand-sildeclref-kind-by-one-bit
[SILDeclRef] Expand `kind` by one bit because `RuntimeAttributeGenera…
2023-01-04 09:48:40 -08:00
eeckstein
bc2bb5bf7a Merge pull request #62771 from eeckstein/debug-info
Some small debug-info fixes
2023-01-04 11:24:39 +01:00
Pavel Yaskevich
733e51f6ad [SILDeclRef] Expand kind by one bit because RuntimeAttributeGenerator is 16th entry 2023-01-03 11:00:21 -08:00
Andrew Trick
0a9484597f Add findEnclosingDefs and findBorrowIntroducers utilities.
These APIs are essential for complete OSSA liveness analysis.  The
existing ad-hoc OSSA logic always misses some of the cases handled by
these new utilities. We need to start replacing that ad-hoc logic with
new utilities built on top of these APIs to define away potential
latent bugs.

Add FIXMEs to the inverse API: visitAdjacentBorrowsOfPhi. It should
probably be redesigned in terms of these new APIs.
2023-01-03 09:33:39 -08:00
Andrew Trick
c2ae7e0359 Add visitForwardedGuaranteedOperands utility.
Factors a mess of code in MemAccessUtils to handle forwarding
instruction types into a simpler utility. This utility is also needed
for ownership APIs, which need to be extended to handle these cases.
2023-01-03 09:33:39 -08:00
Andrew Trick
6e12fff564 80-col formatting 2023-01-03 09:33:39 -08:00
Erik Eckstein
6711c907d9 SILBuilder: add an assertion in getInsertionPointLoc() 2023-01-02 13:37:31 +01:00
Allan Shortlidge
2e8857d867 IRGen: Add #_hasSymbol support for clang function decls and ObjC classes.
Resolves rdar://103408651.
2022-12-22 10:55:30 -05:00
Meghana Gupta
4cf6f79938 Merge pull request #62714 from meg-gupta/fixassert
Create begin_borrow in OSSA only
2022-12-20 21:49:55 -08:00