Commit Graph

73 Commits

Author SHA1 Message Date
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
swift-ci
d80084ea16 Merge remote-tracking branch 'origin/master' into master-next 2017-12-22 12:09:13 -08:00
David Zarzycki
ed85954275 [SIL] NFC: Migrate TupleInst to llvm::TrailingObjects
Also, repack the count variable into the misc object header bits.
2017-12-22 11:33:47 -05:00
David Zarzycki
83c1054034 [SIL] NFC: Migrate StructInst to llvm::TrailingObjects
Also, repack the count variable into the misc object header bits.
2017-12-22 11:16:33 -05:00
David Zarzycki
5012a80e39 [SIL] NFC: Repack misc StringLiteralInst bits 2017-12-22 10:58:21 -05:00
David Zarzycki
fcfdd4c8ca [SIL] NFC: Migrate BuiltinInst to llvm::TrailingObjects
Also, repack the count variables into the misc object header bits.
2017-12-22 10:29:41 -05:00
swift-ci
8e75a2fbbd Merge remote-tracking branch 'origin/master' into master-next 2017-12-18 13:28:54 -08:00
swift-ci
0302515cf0 Merge remote-tracking branch 'origin/master' into master-next 2017-12-18 12:48:55 -08:00
John McCall
94116347a2 Fix some warnings: extra semicolons, anonymous structs. 2017-12-18 15:31:47 -05:00
David Zarzycki
c75e8299f1 [SIL] NFC: Repack misc MetatypeInst bits 2017-12-17 21:35:27 -05:00
David Zarzycki
bc44e5a150 [SIL] NFC: Repack misc BeginAccessInst bits 2017-12-17 21:23:37 -05:00
David Zarzycki
931ea24f99 [SIL] NFC: Repack misc EndAccessInst bits 2017-12-17 21:14:49 -05:00
David Zarzycki
1cd19eae36 [SIL] NFC: Repack misc PointerToAddressInst bits 2017-12-17 20:58:45 -05:00
David Zarzycki
315cf677dd [SIL] NFC: Repack misc SwitchValueInst bits 2017-12-17 20:54:01 -05:00
David Zarzycki
5443923a0c [SIL] NFC: Repack misc SwitchEnumInstBase bits 2017-12-17 20:24:14 -05:00
David Zarzycki
f0bd535261 [SIL] NFC: Repack misc TupleElementAddrInst bits 2017-12-17 19:58:24 -05:00
David Zarzycki
cf443ecfcf [SIL] NFC: Repack misc TupleExtractInst bits 2017-12-17 19:55:17 -05:00