Commit Graph

1328 Commits

Author SHA1 Message Date
Joe Groff
5a2f48e3be Add a Builtin.BridgeObject type.
This is a type that has ownership of a reference while allowing access to the
spare bits inside the pointer, but which can also safely hold an ObjC tagged pointer
reference (with no spare bits of course). It additionally blesses one
Foundation-coordinated bit with the meaning of "has swift refcounting" in order
to get a faster short-circuit to native refcounting. It supports the following
builtin operations:

- Builtin.castToBridgeObject<T>(ref: T, bits: Builtin.Word) ->
  Builtin.BridgeObject

  Creates a BridgeObject that contains the bitwise-OR of the bit patterns of
  "ref" and "bits". It is the user's responsibility to ensure "bits" doesn't
  interfere with the reference identity of the resulting value. In other words,
  it is undefined behavior unless:

    castReferenceFromBridgeObject(castToBridgeObject(ref, bits)) === ref

  This means "bits" must be zero if "ref" is a tagged pointer. If "ref" is a real
  object pointer, "bits" must not have any non-spare bits set (unless they're
  already set in the pointer value). The native discriminator bit may only be set
  if the object is Swift-refcounted.

- Builtin.castReferenceFromBridgeObject<T>(bo: Builtin.BridgeObject) -> T

  Extracts the reference from a BridgeObject.

- Builtin.castBitPatternFromBridgeObject(bo: Builtin.BridgeObject) -> Builtin.Word

  Presents the bit pattern of a BridgeObject as a Word.

BridgeObject's bits are set up as follows on the various platforms:

i386, armv7:

  No ObjC tagged pointers
  Swift native refcounting flag bit: 0x0000_0001
  Other available spare bits:        0x0000_0002

x86_64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0001
  Swift native refcounting flag bit: 0x0000_0000_0000_0002
  Other available spare bits:        0x7F00_0000_0000_0004

arm64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0000
  Swift native refcounting flag bit: 0x4000_0000_0000_0000
  Other available spare bits:        0x3F00_0000_0000_0007

TODO: BridgeObject doesn't present any extra inhabitants. It ought to at least provide null as an extra inhabitant for Optional.

Swift SVN r22880
2014-10-23 00:09:23 +00:00
Joe Groff
3f23b82e6d SIL: Rename SILGlobalAddr to GlobalAddr.
All globals are SIL globals now.

Swift SVN r22827
2014-10-18 17:08:28 +00:00
Joe Groff
ea65d1e60b SIL: Remove the builtin_function_ref instruction.
Swift SVN r22797
2014-10-16 16:18:40 +00:00
Arnold Schwaighofer
ad0e20a316 Make isa work with SwitchEnumInstBase.
Swift SVN r22755
2014-10-15 17:07:02 +00:00
Joe Groff
bb46f4bbd9 SIL: Remove the global_addr instruction.
It's no longer needed now that we always lower to SIL globals.

Swift SVN r22693
2014-10-12 17:19:06 +00:00
Joe Groff
a60a52d72e SIL: Add a "builtin" instruction to represent builtin invocations.
Modeling builtins as first-class function values doesn't really make sense because there's no real function value to emit, and modeling them this way complicates passes that work with builtins because they have to invent function types for builtin invocations. It's much more straightforward to have a single instruction that references the builtin by ID, along with the type information for the necessary values, type parameters, and results, so add a new "builtin" instruction that directly represents a builtin invocation. NFC yet.

Swift SVN r22690
2014-10-11 20:34:24 +00:00
Mark Lacey
0542dc421b Fix comment.
Swift SVN r22654
2014-10-10 04:58:28 +00:00
Joe Groff
9205bf64cf SIL: Remove enum_is_tag.
Swift SVN r22616
2014-10-09 05:03:43 +00:00
Joe Groff
c2fc9f58b8 SIL passes: Work with select_enum instead of enum_is_tag.
Simplify binary switches to select_enum instead of enum_is_tag, and make a first attempt at changing passes over to recognize limited forms of select_enum instead of enum_is_tag. There is one case in test/SILPasses/simplify_cfg.sil I wasn't able to figure out, and there are a lot more general passes we could define in terms of select_enum.

Swift SVN r22615
2014-10-09 03:49:31 +00:00
John McCall
89e60f31aa Add protocol witness tables to existential metatype
layouts.  Introduce new SIL instructions to initialize
and open existential metatype values.

Don't actually, y'know, lift any of the restriction on
existential metatypes; just pointlessly burn extra
memory storing them.

Swift SVN r22592
2014-10-08 01:20:13 +00:00
Joe Groff
ca8b168188 SIL: Add select_enum and select_enum_addr insns.
Similar to LLVM's "select" instruction, the instruction picks one of its operands based on the case tag of an enum value.

Swift SVN r22578
2014-10-07 21:45:08 +00:00
Michael Gottesman
b4c06632e2 Add a helper method SILInstruction::replaceAllUsesWithUndef().
This should really be on ValueBase, but currently ValueBase does not
have access to a SILModule.

Swift SVN r22559
2014-10-07 00:53:56 +00:00
Andrew Trick
43b928bc7c Added ApplyInst::getArgumentOperandNumber to avoid hard-coding this in many places.
Swift SVN r22516
2014-10-04 01:23:10 +00:00
Andrew Trick
89a53d1205 Make StoreInst operand position enum public for the same reason as CopyAddrInst.
Swift SVN r22515
2014-10-04 01:23:10 +00:00
Andrew Trick
245097d4d1 Add a UnaryInstructionBase::getOperandRef helper so I can safely get
to the operand.

Swift SVN r22514
2014-10-04 01:23:09 +00:00
Andrew Trick
66b75ba820 Make CopyAddrInst operand enum public.
I think all the enums that identify operand position should be public.
I've noticed a number of places where we hard-code operand positions
which seems pretty horrible to me.

Swift SVN r22513
2014-10-04 01:23:08 +00:00
Joe Groff
782833f054 SIL: Remove the project_existential* instructions.
Swift SVN r22457
2014-10-02 04:06:10 +00:00
Joe Groff
3a606b9eb8 SIL: Drop the protocol_method instruction.
Swift SVN r22446
2014-10-01 23:35:41 +00:00
Joe Groff
be45322668 SIL: Drop the upcast_existential* instructions.
Swift SVN r22388
2014-09-30 16:11:54 +00:00
Joe Groff
c098645f34 SIL: Conformances relate to formal types, so change witness_method's lookup type to a CanType.
Should be NFC in practice, since only nominal types can currently conform to protocols anyway, but improves modeling of the system.

Swift SVN r22360
2014-09-29 20:44:00 +00:00
Joe Groff
152aa9e244 Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22345.

Swift SVN r22353
2014-09-29 13:46:41 +00:00
Joe Groff
1e343fb430 SIL: Drop the upcast_existential* instructions.
Swift SVN r22345
2014-09-28 19:24:33 +00:00
Joe Groff
0518f2067f Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22333.

Swift SVN r22337
2014-09-28 18:41:05 +00:00
Joe Groff
727c9b5ed7 SIL: Drop the upcast_existential* instructions.
Swift SVN r22333
2014-09-28 16:38:13 +00:00
Joe Groff
a3126706da SIL: Eliminate the dead 'alloc_array' insn.
Swift SVN r22292
2014-09-26 02:28:10 +00:00
Michael Gottesman
561ab6980e [simplify-cfg] Canonicalize enum_is_tag on Optionals to always be on Some by swapping cond_br arguments if we have a .None check.
Swift SVN r22158
2014-09-21 10:56:30 +00:00
Michael Gottesman
a30dbd1fc0 Add some helper methods to CondBranchInst for getting True, False operands and a swapSuccessor method.
Swift SVN r22157
2014-09-21 10:56:28 +00:00
Michael Gottesman
8d9e358ad4 [closure-spec] Use the signature of the closure's function_ref instead of the
arguments of the closure since if the closure is an external declaration, it
wont have a first BB.

Swift SVN r22114
2014-09-19 02:33:58 +00:00
Arnold Schwaighofer
73fd579edf SILInstruction: Add setArgument and setSelfArgument to ApplyInst
Swift SVN r21924
2014-09-12 21:05:20 +00:00
Joe Groff
e004ad7df4 SIL: Carry AST types through init_existential instructions.
This is necessary to be able to properly stash values with nontrivial lowerings, such as metatypes and functions, inside existential containers. Modify SILGen to lower values to the proper abstraction level before storing them in an existential container. Part of the fix for rdar://problem/18189508, though runtime problems still remain when trying to actually dynamicCast out a metatype from an Any container.

Swift SVN r21830
2014-09-10 05:56:36 +00:00
Doug Gregor
c504086266 Revert r21707 "Remove the SIL is_nonnull instruction. It's no longer useful."
We want to be able to work around problems with non-failable
Objective-C initializers actually failing, which can happen when the
API audit data incorrectly marks an initializer as non-failable.



Swift SVN r21711
2014-09-04 17:26:34 +00:00
Doug Gregor
cdf94885ae Remove the SIL is_nonnull instruction. It's no longer useful.
Swift SVN r21707
2014-09-04 15:56:12 +00:00
Michael Gottesman
1ba4322412 Make a small fix for LLVM style by inverting an if (condition) {return} into an if (!condition) {continue} return. NFC.
Swift SVN r21615
2014-08-31 18:18:38 +00:00
Michael Gottesman
ec7cc211cb [g-arc-opts] A struct_extract of the only non-trivial stored field of a struct is always a ref count identity preserving identity.
rdar://18189325

Swift SVN r21614
2014-08-31 18:08:30 +00:00
Roman Levenstein
97014172b7 [sil-combine] String literal concatenation optimization. Constant-fold concatenation of string literals known at compile-time.
Addresses rdar://17033696.

Swift SVN r21526
2014-08-28 11:33:21 +00:00
Mark Lacey
51e710170a Fix typo in comment.
Swift SVN r21461
2014-08-26 19:49:46 +00:00
Erik Eckstein
17c4a50766 Let the switch_enum instruction return a unqiue enum case for the default block, if possible.
This enables removal of more redundant switch_enum instructions, like

  switch_enum %0 : ..., default bb2
bb2:
  switch_enum %0 : ...




Swift SVN r21418
2014-08-22 18:51:56 +00:00
Michael Gottesman
73434aa4fa Rename SwitchEnumInst::getBBCase => getUniqueCaseForDestination.
This matches the name for SwitchEnumInst::getCaseDestination() and includes the word
'unique' so that the name self documents.

I also removed a local function doing the same work in SimplifyCFG and changed
its user to use getUniqueCaseForDestination instead.

Swift SVN r21339
2014-08-21 04:06:19 +00:00
Michael Gottesman
6d7ace6013 Make sure that when stripping non phi rc identity preserving args from switch enums, we only strip off switch enum inst if our BB is mapped to the first payloaded case of the enum.
Swift SVN r21336
2014-08-21 03:46:26 +00:00
Michael Gottesman
96ef9814f5 Change CondBranchInst::getArgForDestBB() so that it returns SILValue() if the TrueBB and the False BB equal and so that it takes the SILArgument instead of the index.
Swift SVN r21335
2014-08-21 03:45:35 +00:00
Michael Gottesman
5038acfe09 Remove trailing whitespace. NFC.
Swift SVN r21327
2014-08-20 23:40:49 +00:00
Michael Gottesman
dec1bea98b Add support to SILArgument for finding the index of the SILArgument and a method on CondBranchInst to return the ith argument associated with a specific BB.
Together these allow you to find the specific cond_br argument that will be
passed to a BB by performing:

CBI->getArgForBB(BB, BBArg->getIndex())

Swift SVN r21326
2014-08-20 23:40:48 +00:00
Pete Cooper
d6877f60a4 Add enum_is_tag instruction.
This returns an i1 given an enum and enum element, and allows us to check the tag without the control flow required by switch_enum

Note, the following -O3 performance numbers are with r20242 reverted.

benchmark      ,  baserun0  ,  optrun0   ,  delta,   speedup
2Sum           ,  1613.00   ,  1656.00   ,  43.00    ,        -2.6%
Ackermann      ,  4560.00   ,  4473.00   ,  87.00    ,        1.9%
DeltaBlue      ,  22122.00  ,  22181.00  ,  59.00    ,        -0.3%
Dictionary     ,  927.00    ,  898.00    ,  29.00    ,        3.2%
EditDistance   ,  1573.00   ,  1564.00   ,  9.00     ,        0.6%
ForLoops       ,  2122.00   ,  2142.00   ,  20.00    ,        -0.9%
Forest         ,  1131.00   ,  1130.00   ,  1.00     ,        0.1%
GlobalClass    ,  2926.00   ,  2712.00   ,  214.00   ,        7.9%
Hash           ,  1970.00   ,  1280.00   ,  690.00   ,        53.9%
Histogram      ,  1860.00   ,  1606.00   ,  254.00   ,        15.8%
Life           ,  1669.00   ,  1750.00   ,  81.00    ,        -4.6%
LinkedList     ,  1555.00   ,  1558.00   ,  3.00     ,        -0.2%
Memset         ,  328.00    ,  333.00    ,  5.00     ,        -1.5%
NBody          ,  114.00    ,  46.00     ,  68.00    ,        147.8%
Phonebook      ,  1434.00   ,  1379.00   ,  55.00    ,        4.0%
Prims          ,  1833.00   ,  1669.00   ,  164.00   ,        9.8%
QuickSort      ,  107.00    ,  106.00    ,  1.00     ,        0.9%
R17315246      ,  1103.00   ,  817.00    ,  286.00   ,        35.0%
RC4            ,  884.00    ,  57.00     ,  827.00   ,        1450.9%
Rectangles     ,  1624.00   ,  1624.00   ,  0.00     ,        0.0%
SmallPT        ,  1067.00   ,  1012.00   ,  55.00    ,        5.4%
StringBuilder  ,  942.00    ,  921.00    ,  21.00    ,        2.3%
StringWalk     ,  1253.00   ,  1260.00   ,  7.00     ,        -0.6%
Totals         ,  55770.00  ,  52317.00  ,  3453.00  ,        6.6%

Swift SVN r20361
2014-07-23 02:53:43 +00:00
John McCall
97ce0d2fd6 Pull a few enum declarations out of SILInstruction.h.
Swift SVN r19330
2014-06-30 11:55:19 +00:00
John McCall
e8428377de Add some functions to query a CastConsumptionKind.
Swift SVN r19077
2014-06-22 09:53:31 +00:00
John McCall
385879beea Remove the CheckedCastKind from SIL dynamic casts.
It is straightforward and less redundant to recover this
information from the operand types.

Swift SVN r19056
2014-06-20 22:43:53 +00:00
Joe Groff
d9d451cea5 SIL: Add unchecked_{trivial,ref}_bit_cast instructions.
These instructions do a bitcast operation without stack traffic (at the SIL level). unchecked_trivial_bit_cast represents a conversion from a potentially nontrivial type to a trivial type, such as from a class reference to Int. unchecked_ref_bit_cast represents a conversion between types for which retain_value and release_value has equivalent effects when applied on the input or output values.

Swift SVN r19053
2014-06-20 22:02:38 +00:00
Adrian Prantl
b1a7a7af1b Reference-count inlined functions to keep them alive until we emit debug
info for them and generally clean up the inline scope handling a bit.
Fix the debug scope handling for all clients of SILCloner, especially
the SIL-level spezializers and inliners.
This also adds a ton of additional assertions that will ensure that
future optimization passes won't mess with the debug info in a way that
could confuse the LLVM backend.

Swift SVN r18984
2014-06-18 22:34:10 +00:00
John McCall
f0e14f7e65 Carry the formal types of the arguments in the indirect-cast
instructions.

Swift SVN r18934
2014-06-16 17:35:43 +00:00
Michael Gottesman
85a349554c RetainValue, ReleaseValue, and AutoreleaseValue are all reference count
instructions. Make them subclasses of RefCountingInst.

This is a useful superclass that enables one to quickly perform queries
on whether or not a specific instruction is an instruction that
manipulates reference counts.

Swift SVN r18891
2014-06-14 05:42:31 +00:00