Commit Graph

139 Commits

Author SHA1 Message Date
Andrew Trick
6ed58c6380 Add debug_value [poison] flag.
If the '[poison]' flag is set, then all references within this debug
value will be overwritten with a sentinel at this point in the
program. This is used in debug builds when shortening non-trivial
value lifetimes to ensure the debugger cannot inspect invalid
memory. `debug_value` instructions with the poison flag are not
generated until OSSA islowered. They are not expected to be serialized
within the module, and the pipeline is not expected to do any
significant code motion after lowering.
2021-03-12 19:33:23 -08:00
Andrew Trick
73cde15abe Merge pull request #36299 from atrick/poison-destroy
[NFC] Add a poison flag to SIL destroy_value.
2021-03-04 22:55:54 -08:00
Andrew Trick
e0a440c036 Add a poison flag to SIL destroy_value.
When the IRGen side is implemented, this will overwrite shadow debug
variables with a poison sentinel for all references within the value.
2021-03-04 17:26:18 -08:00
Erik Eckstein
9055e93af9 SIL: some improvements/fixes around assign_by_wrapper
* Refactoring: replace "Destination" and the ownership qualifier by a single "Mode".  This represents much better the mode how the instruction is to be lowered. NFC
* Make assign_by_wrapper printable and parseable.
* Fix lowering of the assign modes for indirect results of the init-closure: The indirect result was initialized and not assigned to. The fix is to insert a destroy_addr before calling the init closure. This fixes a memory lifetime error and/or a memory leak. Found by inspection.
* Fix an iterator-invalidation crash in RawSILInstLowering
* Add tests for lowering assign_by_wrapper.
2021-03-03 18:57:02 +01:00
Erik Eckstein
65208c0642 SIL: efficiently store SILLocation in SILInstruction
Store the 1-byte kindAndFlags of SILLocation in the instruction's SILNode bitfield and only store SILLocation::storage in SILInstruction directly.
This reduces the space for the location from 2 to 1 word in SILInstruction.
2021-01-29 20:28:21 +01:00
Erik Eckstein
011358edd6 SIL: let SingleValueInstruction only inherit from a single SILNode.
This removes the ambiguity when casting from a SingleValueInstruction to SILNode, which makes the code simpler. E.g. the "isRepresentativeSILNode" logic is not needed anymore.
Also, it reduces the size of the most used instruction class - SingleValueInstruction - by one pointer.

Conceptually, SILInstruction is still a SILNode. But implementation-wise SILNode is not a base class of SILInstruction anymore.
Only the two sub-classes of SILInstruction - SingleValueInstruction and NonSingleValueInstruction - inherit from SILNode. SingleValueInstruction's SILNode is embedded into a ValueBase and its relative offset in the class is the same as in NonSingleValueInstruction (see SILNodeOffsetChecker).
This makes it possible to cast from a SILInstruction to a SILNode without knowing which SILInstruction sub-class it is.
Casting to SILNode cannot be done implicitly, but only with an LLVM `cast` or with SILInstruction::asSILNode(). But this is a rare case anyway.
2021-01-27 16:40:15 +01:00
Eric Miotto
8e7f9c9cbd Revert "SIL: let SingleValueInstruction only inherit from a single SILNode." 2021-01-26 10:02:24 -08:00
Erik Eckstein
ff1991740a SIL: let SingleValueInstruction only inherit from a single SILNode.
This removes the ambiguity when casting from a SingleValueInstruction to SILNode, which makes the code simpler. E.g. the "isRepresentativeSILNode" logic is not needed anymore.
Also, it reduces the size of the most used instruction class - SingleValueInstruction - by one pointer.

Conceptually, SILInstruction is still a SILNode. But implementation-wise SILNode is not a base class of SILInstruction anymore.
Only the two sub-classes of SILInstruction - SingleValueInstruction and NonSingleValueInstruction - inherit from SILNode. SingleValueInstruction's SILNode is embedded into a ValueBase and its relative offset in the class is the same as in NonSingleValueInstruction (see SILNodeOffsetChecker).
This makes it possible to cast from a SILInstruction to a SILNode without knowing which SILInstruction sub-class it is.
Casting to SILNode cannot be done implicitly, but only with an LLVM `cast` or with SILInstruction::asSILNode(). But this is a rare case anyway.
2021-01-25 09:30:04 +01:00
Michael Gottesman
f0f78a1477 [sil] Templatize base class of FieldIndexCacheBase.
Previously FieldIndexCacheBase only had a parent class of
SingleValueInstruction. I need to be able to in certain cases shim in a
SingleValueInstruction subclass as a parent class instead. In my case it is to
imbue ownership forwarding on StructExtractInst.

This commit itself doesn't make that change and instead just always templatizes
using SingleValueInstruction.
2020-12-01 15:45:25 -08:00
David Zarzycki
96d6bde027 [SIL] NFC: fix extra semi warning 2020-11-13 09:38:35 -05:00
Michael Gottesman
264955ccb3 [ownership] Convert switch_enum to be an ownership forwarding inst and store the forwarding ownership kind within it.
Previously, we always inferred the ownership of the switch_enum from its phi
operands. This forced us to need to model a failure to find a good
OperandOwnershipKindMap in OperandOwnership.cpp. We want to eliminate such
conditions so that we can use failing to find a constraint to mean that a value
can accept any value rather than showing a failure.
2020-11-08 20:32:20 -08:00
Joe Groff
3364c51b1d SIL: Verify invariants of async_continuation instructions.
- Enforce types of continuations and resume/error BBargs for await
- Can't access the continuation again or exit the function mid-suspend
2020-10-09 14:57:38 -07:00
swift_jenkins
f375a35b29 Merge remote-tracking branch 'origin/master' into master-next 2020-05-14 02:19:22 -07:00
Erik Eckstein
f5a8f600ea SIL: new instructions for copy-on-write support
* a new [immutable] attribute on ref_element_addr and ref_tail_addr
* new instructions: begin_cow_mutation and end_cow_mutation

These new instructions are intended to be used for the stdlib's COW containers, e.g. Array.
They allow more aggressive optimizations, especially for Array.
2020-05-14 08:39:54 +02:00
Alex Langford
9c99dd39d5 Include llvm PointerLikeTypeTraits header where used
Most likely another header was including this so SILNode.h was getting the
header transitively.
2020-03-03 12:41:45 -08:00
Doug Gregor
c02ecf9859 [SE-0258] Rename to Property Wrappers 2019-05-29 22:17:50 -07:00
Andrew Trick
6befb10d35 Cache struct/class field offsets in SIL.
The field's ordinal value is used by the Projection abstraction, which is
the basis of efficiently comparing and sorting access paths in SIL. It must
be cached before it is used by any SIL passes, including the verifier, or it
causes widespread quadratic complexity.

Fixes <rdar://problem/50353228> Swift compile time regression with optimizations enabled

In production code, a file that was taking 40 minutes to compile now
takes 1 minute, with more than half of the time in LLVM.

Here's a short script that reproduces the problem. It used to take 30s
and now takes 0.06s:

// swift genlazyinit.swift > lazyinit.sil
// sil-opt ./lazyinit.sil --access-enforcement-opts

var NumProperties = 300

print("""
      sil_stage canonical

      import Builtin
      import Swift
      import SwiftShims

      public class LazyProperties {
      """)

for i in 0..<NumProperties {
  print("""
          //  public lazy var i\(i): Int { get set }
          @_hasStorage @_hasInitialValue final var __lazy_storage__i\(i): Int? { get set }
        """)
}

print("""
      }

     // LazyProperties.init()
     sil @$s4lazy14LazyPropertiesCACycfc : $@convention(method) (@owned LazyProperties) -> @owned LazyProperties {
     bb0(%0 : $LazyProperties):
       %enum = enum $Optional<Int>, #Optional.none!enumelt
     """)

for i in 0..<NumProperties {
  let adr = (i*4) + 2
  let access = adr + 1
  print("""
          %\(adr) = ref_element_addr %0 : $LazyProperties, #LazyProperties.__lazy_storage__i\(i)
          %\(access) = begin_access [modify] [dynamic] %\(adr) : $*Optional<Int>
          store %enum to %\(access) : $*Optional<Int>
          end_access %\(access) : $*Optional<Int>
        """)
}

print("""
        return %0 : $LazyProperties
      } // end sil function '$s4lazy14LazyPropertiesCACycfc'
      """)
2019-05-13 16:54:55 -07:00
Erik Eckstein
2e01b0edeb SIL: add assign_by_delegate instruction
Used for property delegates.
2019-04-23 11:32:28 -07:00
Azoy
5af2663c57 Textualize assign init kind
Rename [assign] to [reassign]

fix some tests

AssignOwnershipQualifier

formatting

moar formatting
2019-02-12 20:16:25 -06:00
Arnold Schwaighofer
73df12c09f Remove dead constant_string_literal
constant_string_literal was added to support a one word representation
of String that never materialized.
2018-09-05 12:13:57 -07:00
Erik Eckstein
e5b47a28fe SIL: remove the now unused atomicity bit in SILNode.h for strong_pin 2018-08-25 11:14:18 -07:00
Andrew Trick
c9033ed938 Add a SIL attribute [without_actually_escaping].
ConvertFunction and reabstraction thunks need this attribute. Otherwise,
there is no way to identify that withoutActuallyEscaping was used
to explicitly perform a conversion.

The destination of a [without_actually_escaping] conversion always has
an escaping function type. The source may have either an escaping or
@noescape function type. The conversion itself may be a nop, and there
is nothing distinctive about it. The thing that is special about these
conversions is that the source function type may have unboxed
captures. i.e. they have @inout_aliasable parameters. Exclusivity
requires that the compiler enforce a SIL data flow invariant that
nonescaping closures with unboxed captures can never be stored or
passed as an @escaping function argument. Adding this attribute allows
the compiler to enforce the invariant in general with an escape hatch
for withoutActuallyEscaping.
2018-08-14 17:14:25 -07:00
Andrew Trick
fe326266cc [exclusivity] Add a [builtin] flag to begin_[unpaired_]access.
This flag supports promoting KeyPath access violations to an error in
Swift 4+, while building the standard library in Swift 3 mode. This is
only necessary as long as the standard library continues to build in
Swift 3 mode. Once the standard library build migrates, it can all be
ripped out.

<rdar://problem/40115738> [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.
2018-05-09 21:42:37 -07:00
Doug Gregor
408aaa5332 [SIL] Use SubstitutionMap in BuiltinInst. 2018-05-03 08:48:55 -07:00
Doug Gregor
d2cf60c465 Revert "[SIL] Replace more SubstitutionLists with SubstitutionMap" 2018-05-03 08:35:20 -07:00
Doug Gregor
ed1983d9d0 [SIL] Use SubstitutionMap in BuiltinInst. 2018-05-03 00:05:21 -07:00
Andrew Trick
e50faa5125 [exclusivity] Add 'no_nested_conflict' flag to begin_access.
This statically guarantees that the access has no inner conflict within
its own scope.

IRGen will turn this into a "nontracking" access in which an
exclusivity check is performed for conflicts on an outer scope. However,
unlike normal accesses the runtime does not record the access, and the
access will not be checked for subsequent conflicts.

end_unpaired_access [no_nested_conflict] is not currently
supported. Making a begin_unpaired_access [no_nested_conflict] requires
deleting the corresponding end_unpaired_access. Future runtimes
could support this for verification by storing inline data in the
valud buffer. However, the runtime can never assume that a
[no_nested_conflict] begin_unpaired_access will have a corresponding
end_unpaired_access call without adding a new ExclusivityFlag for
that purpose.
2018-03-27 10:50:07 -07:00
Andrew Trick
a30f438037 Consistently use bitfield packing for different kinds of access markers for sanity sake. 2018-03-27 09:10:35 -07:00
swift-ci
cc373f9c30 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-01-08 12:27:47 -08:00
David Zarzycki
77a29c9551 [AST] Perf: Improve getDesugaredType() efficiency
Make getDesugaredType() as fast as possible for now. With the old way:

1) Switching over the sugared types turned into a frequently
   mispredicted branch because the sugar in the type system is random
   as far as the processor is concerned.
2) Storing the underlying/singlely-desugared type at different offsets
   in memory adds more code bloat and misprediction.

Short of a major redesign to avoid pointer chasing, this is probably as
fast as the method will get.
2018-01-03 09:45:48 -05:00
swift-ci
ea5116e40b Merge remote-tracking branch 'origin/master' into master-next 2017-12-28 08:29:21 -08:00
David Zarzycki
da238539f5 [Basic] NFC: Inline bitfield cleanup
1) Remove SWIFT_INLINE_BITS boilerplate. Now that we're not using anonymous/transparent unions, we don't need the
SWIFT_BITFIELD_BITS macro.
2) Refine the the bitfield size check to better support templated bitfields.
3) Refine the SIL templated bitfields to not be prematurely "full".
2017-12-28 09:20:31 -05:00
swift-ci
f8dde3619a Merge remote-tracking branch 'origin/master' into master-next 2017-12-27 10:49:23 -08:00
David Zarzycki
679538b72c [SIL] NFC: Migrate SelectInstBase subclasses to InstructionBaseWithTrailingOperands 2017-12-27 11:14:17 -05:00
David Zarzycki
d532fdefe0 [SIL] NFC: Migrate AllocRefInstBase subclasses to InstructionBaseWithTrailingOperands 2017-12-27 08:00:20 -05:00
David Zarzycki
26a1187a3a [SIL] NFC: Migrate CondBranchInst to InstructionBaseWithTrailingOperands
Also, repack misc bits and stop hard coding the number of fixed operands.
2017-12-26 07:39:59 -05:00
David Zarzycki
32284f1023 [SIL] NFC: Migrate ObjectInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
9f42304dd7 [SIL] NFC: Migrate MarkFunctionEscapeInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
81c29d7f98 [SIL] NFC: Migrate SwitchValueInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
bc31a3542f [SIL] NFC: Migrate YieldInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
25b85596b2 [SIL] NFC: Migrate BranchInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
2dc1917283 [SIL] NFC: Migrate AllocBoxInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
2630944535 [SIL] NFC: Migrate AllocExistentialBoxInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
f572569fb1 [SIL] NFC: Migrate BuiltinInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
33300640ae [SIL] NFC: Migrate BindMemoryInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
d2552969f6 [SIL] NFC: Migrate StructInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
65a31cf113 [SIL] NFC: Migrate TupleInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:59 -05:00
David Zarzycki
1321eceb0c [SIL] NFC: Migrate MetatypeInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:58 -05:00
David Zarzycki
ee0550ecdf [SIL] NFC: Migrate WitnessMethodInst to InstructionBaseWithTrailingOperands 2017-12-26 07:39:58 -05:00
David Zarzycki
09d541f758 [SIL] NFC: Refactor UnaryInstructionWithTypeDependentOperandsBase
Refactor UnaryInstructionWithTypeDependentOperandsBase into two template
classes, where the original template now subclasses a simpler template
called "InstructionBaseWithTrailingObjects".
2017-12-26 07:39:58 -05:00