Commit Graph

6 Commits

Author SHA1 Message Date
Zak Kent
3b4e94f65b [SILGen] Emit toplevel code through emitFunctionDefinition
Emit SILDeclRefs representing entry points with SourceFile
source correctly.
2023-08-08 11:25:11 -07:00
Erik Eckstein
7c54be27ad SILCombine: a better fix for optimizing keypath-offset-of
Instead of bailing out, use the lowered type.

rdar://103834325
2023-01-05 08:07:50 +01:00
Erik Eckstein
a081e04f8c SILCombine: fix a crash when optimizing keypath-offset-of
Need to check if the keypath's root type is a legal SIL type.

rdar://103834325
2023-01-03 17:31:38 +01:00
Erik Eckstein
1a0c4d07a6 Reinstate "SILCombine: Constant-fold MemoryLayout<T>.offset(of: \.literalKeyPath)"
This reinstates commit d7d829c059 with a fix for C tail-allocated arrays.

Replace a call of the getter of AnyKeyPath._storedInlineOffset with a "constant" offset, in case of a keypath literal.
"Constant" offset means a series of struct_element_addr and tuple_element_addr instructions with a 0-pointer as base address.
These instructions can then be lowered to "real" constants in IRGen for concrete types, or to metatype offset lookups for generic or resilient types.

Replace:
  %kp = keypath ...
  %offset = apply %_storedInlineOffset_method(%kp)
with:
  %zero = integer_literal $Builtin.Word, 0
  %null_ptr = unchecked_trivial_bit_cast %zero to $Builtin.RawPointer
  %null_addr = pointer_to_address %null_ptr
  %projected_addr = struct_element_addr %null_addr
   ... // other address projections
  %offset_ptr = address_to_pointer %projected_addr
  %offset_builtin_int = unchecked_trivial_bit_cast %offset_ptr
  %offset_int = struct $Int (%offset_builtin_int)
  %offset = enum $Optional<Int>, #Optional.some!enumelt, %offset_int

rdar://problem/53309403
2020-07-03 18:40:47 +02:00
Erik Eckstein
723a205f0b Revert "SILCombine: Constant-fold MemoryLayout<T>.offset(of: \.literalKeyPath)"
This reverts commit d7d829c059.

The test stdlib/KeyPath.swift is failing on linux.

rdar://problem/64997950
2020-07-01 21:49:52 +02:00
Erik Eckstein
d7d829c059 SILCombine: Constant-fold MemoryLayout<T>.offset(of: \.literalKeyPath)
Replace a call of the getter of AnyKeyPath._storedInlineOffset with a "constant" offset, in case of a keypath literal.
"Constant" offset means a series of struct_element_addr and tuple_element_addr instructions with a 0-pointer as base address.
These instructions can then be lowered to "real" constants in IRGen for concrete types, or to metatype offset lookups for generic or resilient types.

Replace:
  %kp = keypath ...
  %offset = apply %_storedInlineOffset_method(%kp)
with:
  %zero = integer_literal $Builtin.Word, 0
  %null_ptr = unchecked_trivial_bit_cast %zero to $Builtin.RawPointer
  %null_addr = pointer_to_address %null_ptr
  %projected_addr = struct_element_addr %null_addr
   ... // other address projections
  %offset_ptr = address_to_pointer %projected_addr
  %offset_builtin_int = unchecked_trivial_bit_cast %offset_ptr
  %offset_int = struct $Int (%offset_builtin_int)
  %offset = enum $Optional<Int>, #Optional.some!enumelt, %offset_int

rdar://problem/53309403
2020-07-01 15:10:22 +02:00