Commit Graph

111 Commits

Author SHA1 Message Date
Michael Gottesman
cc073968ca [sil-combine] When eliminating closures, properly release captured values.
rdar://19785715

Swift SVN r25195
2015-02-11 21:52:27 +00:00
Joe Groff
7e78ff68d1 IRGen/Runtime: Make dynamic metatype-to-AnyObject casts work.
Bonus fix for rdar://problem/19624697.

Swift SVN r24808
2015-01-28 23:06:45 +00:00
Arnold Schwaighofer
d9f28f65a4 SILCombiner: Adapt the built array opt to index_addr to stdlib changes
Int is now compiled to either Int32 or Int64 instead of Word in the stdlib.
Consequently, we get casts from those types to Word arguments that sil
instructions expect.

Adapt the pattern. Also handle other builtin functions along the way.

rdar://19608094

Swift SVN r24798
2015-01-28 18:25:16 +00:00
Arnold Schwaighofer
4740461fff SILCombine: Add another index_raw_pointer -> index_addr peephole
This time involving builtin array operations.

Take something like this:
   %stride = Builtin.strideof(T) * %distance
   %ptr' = index_raw_pointer %ptr, %stride
     = builtin "takeArrayFrontToBack"<Int>(%metatype, %ptr', ...

And convert it to this:
   %addr = pointer_to_address %ptr, $T
   %result = index_addr %addr, %distance
   %ptr' = address_to_pointer result : $RawPointer
     = builtin "takeArrayFrontToBack"<Int>(%metatype, %ptr', ...

rdar://19608094

Swift SVN r24772
2015-01-28 01:54:39 +00:00
Luqman Aden
018589d7b7 Update for some style changes and simplification as per review.
Swift SVN r24767
2015-01-28 00:56:04 +00:00
Luqman Aden
c30faa152a Delete dead code after a (cond_fail 1).
Fixes <rdar://problem/19505558>

Swift SVN r24756
2015-01-27 21:09:09 +00:00
Arnold Schwaighofer
8e1dfcbdfb SILCombine: Add an indexrawpointer to index_addr combine
This comes up after Dimitri switches the stdlib over to use explicit Int32/64
types for Ints.

rdar://17604532

Swift SVN r24738
2015-01-26 23:33:33 +00:00
Arnold Schwaighofer
aed055e110 SILCombine: Peephole a pattern generate by materializeForSetCallback
This reapplies commit r24628 with a fix: use the metatype of a boundgenerictype
to get the substitutions instead of painfully building them ourselves and making
mistakes along the way.

This is not as general as it should be. The general solution is to introduce a
builtin partial_apply_thin_recoverable as John suggested to me in person and
describes in SILGenBuiltin.cpp.

This patch addresses an important subset of problems (ie. sorting an arrays of
things) with low risk for the upcoming release.

radar://19388835

Swift SVN r24657
2015-01-22 22:50:49 +00:00
Arnold Schwaighofer
32040060b9 Revert "SILCombine: Peephole a pattern generate by materializeForSetCallback for generic struct"
This reverts commit r24628.

It probably broke the buildbot.

Conflicts:
	test/SILPasses/sil_combine.sil

Swift SVN r24654
2015-01-22 21:28:39 +00:00
Arnold Schwaighofer
5f99ddca37 SILCombine: Peephole a pattern generate by materializeForSetCallback for generic struct
types.

This is not as general as it should be. The general solution is to introduce
a builtin partial_apply_thin_recoverable as John suggested to me in person and
describes in SILGenBuiltin.cpp.

This patch addresses an important subset of problems (ie. sorting an arrays of
things) with low risk for the upcoming release.

radar://19388835

Swift SVN r24628
2015-01-22 01:59:07 +00:00
Mark Lacey
6170bbb0ed Minor code clean-up.
Primarily replacing getParent()->getParent() with getFunction().

Swift SVN r24596
2015-01-21 06:35:13 +00:00
Michael Gottesman
ca59e81cbc Simplify (ref_to_raw_pointer (unchecked_ref_bit_cast x)) to (unchecked_trivial_bit_cast x) for trivial types.
Patch by Luqman Aden!
Fixes <rdar://problem/18758871>

Swift SVN r24589
2015-01-21 04:34:43 +00:00
Michael Gottesman
897325b096 Codebase Gardening. NFC.
1. Eliminate unused variable warnings.
2. Change field names to match capitalization of the rest of the field names in the file.
3. Change method names to match rest of the file.
4. Change get,set method for a field to match the field type.

Swift SVN r24501
2015-01-19 00:34:07 +00:00
Roman Levenstein
e15b22cb8f [sil-combine] Fold checked_cast_addr_br when casting into protocol types if informations about conformances is available at compile-time.
If we know at compile-time that a type being casted is conforming to a protocol, then we can replace the checked_cast_addr_br by an unconditional_checked_cast_addr followed by a branch to the success BB of the original checked_cast_addr_br instruction.

If we cannot find at compile-time that a type being casted is conforming to the protocol, but we see that this type is not public, then we know that no new protocol conformance can be added by a different module at run-time. Therefore it is safe to assume that this type does not conform to the protocol and we can replace checked_cast_addr_br by a branch to the failure BB of the original checked_cast_addr_br instruction.

rdar://19487336

Swift SVN r24493
2015-01-17 03:08:55 +00:00
Roman Levenstein
24e6582f53 [sil-comnbine] Add a new peephole: inject_enum_addr (addr, val), select_enum_addr (addr, val: sel1, ...) -> sel1
rdar://19495527

Swift SVN r24492
2015-01-17 03:08:53 +00:00
Mark Lacey
6dafd410e9 Set the transparent bit properly when combining apply and partial_apply.
Fixes rdar://problem/19477758

Incidentally I didn't really notice a perforamance impact from this,
probably because the performance inliner was already choosing to inline
these functions.

Swift SVN r24482
2015-01-16 23:13:52 +00:00
Roman Levenstein
c80b4b2825 [sil-combine] Add cond_br (select_enum) -> switch_enum transformation.
This transformation is useful for code generated for Optionals.  It is a part of on-going work on rdar://18603827

Swift SVN r24140
2014-12-24 01:12:59 +00:00
Roman Levenstein
47651de376 [sil-devirtualizer] Significantly improve devirtualization of inherited and specialized protocol conformances.
This patch improves handling of generic parameters and implements proper handling of metatypes, which were blocking correct devirtualization of inherited and specialized conformances. It enables a corresponding test, because all its blocking issues are resolved now.

Fixes rdar://17823742, rdar://17823746 and rdar://16847192

Swift SVN r23882
2014-12-12 03:58:45 +00:00
Roman Levenstein
7e49c162fa Create a substitutions map only if it is used. NFC.
Swift SVN r23881
2014-12-12 03:58:44 +00:00
Roman Levenstein
7bf2a5a38b Rename a variable to make its purpose more clear. NFC.
Swift SVN r23880
2014-12-12 03:58:43 +00:00
Roman Levenstein
8358e1c1d3 Formatting fixes. NFC.
Swift SVN r23660
2014-12-03 22:30:46 +00:00
Roman Levenstein
58cba60076 Minor clean-up. Invoke SILType::subst only when needed.
Swift SVN r23659
2014-12-03 22:30:45 +00:00
Roman Levenstein
d1fcac63ed [sil-combine] Rename propagateExistential into propagateConcreteTypeOfInitExistential to better reflect what this method does. NFC.
Swift SVN r23658
2014-12-03 22:30:43 +00:00
Roman Levenstein
f8c3dda827 [sil-combine] Move the StringConcatenationOptimizer class into Local.h/.cpp. NFC.
This is done because this class is to be used by sil-combine and constant constant-propagation.

Swift SVN r23654
2014-12-03 21:46:27 +00:00
Roman Levenstein
610b1ceb8c Fix a few issues discovered in rdar://19121129.
When propagating concrete types into witness_method and apply instructions inside propagateExistential, propagate them also inside parameters of polymorphic functions.

Do not refer to init_existential inside apply instructions if we cannot prove that a given init_existential instruction dominates the apply instruction that would refer to it.

Swift SVN r23638
2014-12-03 03:43:56 +00:00
Roman Levenstein
2601c4e506 [sil-devirtualizer] Support devirtualization of inherited conformances.
Remove XFAIL from a corresponding test and extend it to cover more test-cases.

rdar://17823742 and rdar://17823746

Swift SVN r23619
2014-12-02 21:00:44 +00:00
Andrew Trick
bd882d4ee1 SILCombine: generalize init_enum_data_addr canonicalization.
Make the SILCombine logic aware of memory behavior.

This fixes performance issues exposed by copy forwarding.
By itself, there is one confirmed speedup:
StdlibSort +12.3%

Swift SVN r23607
2014-12-02 01:07:46 +00:00
Roman Levenstein
7243748565 Bail out in case of inherited protocol conformances for now. It should be re-enabled once our devirtualizer is able to handle inherited protocol conformances properly.
Swift SVN r23598
2014-12-01 20:49:49 +00:00
Roman Levenstein
f3771cd2f0 [sil-combine] Propagate information about a concrete type from init_existential or init_existential_ref into witness_method conformances and into apply instructions.
This helps the devirtualizer to replace witness_method by class_method instructions and then devirtualize.

Note: Invocation of protocol methods from generic classes and structs is not supported by this patch yet.

rdar://18857054 and rdar://18506660

Swift SVN r23596
2014-12-01 18:53:21 +00:00
Erik Eckstein
aeacf6f397 Add more icmp builtins to the same-operands optimization in SILCombine.
I missed these builtins in my previous commit r23441.



Swift SVN r23473
2014-11-20 09:42:07 +00:00
Erik Eckstein
510a0c62c9 SILCombine: optimize several binary builtins which receive the same value in both operands.
E.g. cmp_eq %x, %x -> true

Fixes <rdar://problem/18763596> Optimize compares of value to itself



Swift SVN r23441
2014-11-19 19:18:23 +00:00
Michael Gottesman
e6f8e6d7db Remove "Sort the list" comment.
It is obvious from calling std::sort that we are sorting the list. ; ).

Swift SVN r23373
2014-11-17 18:01:01 +00:00
Michael Gottesman
2d703a28f5 [proj] Add Projection::create{Addr,Value}Projection so one can create Projections without knowing what the internal state of the projection is.
Swift SVN r23371
2014-11-17 17:52:16 +00:00
Michael Gottesman
eeab468c8e [proj] Prepare Projection so that I can add generic create{Addr,Value}Projection.
I want to cleanup some code paths in SILCombine and LoadStoreOpts to use
generic create{Addr,Value}Projection methods which create the
appropriate projection instruction for a Projection method. Also this
will allow me to start to hide more of the internal state of Projection.

Swift SVN r23366
2014-11-17 06:43:37 +00:00
Michael Gottesman
5d4e87baa3 Add in a big comment to explain why we sort projections when canonicalizing loads in SILCombine to favor being narrow over wider.
Amazing what six months will do to ones memory.

Swift SVN r23365
2014-11-17 06:43:36 +00:00
Michael Gottesman
a4a633351f [projection] Make projection constructors private and create static failable initializers using Optional.
This changes the Projection API so that you pass in an instruction and get back
an optional depending on what theinstruction was. This is much cleaner than
always needing to do a switch.

This commit also cleans up the naming in Projection so that we always use the
term "value projection" for struct_extract, tuple_extract, and
unchecked_enum_data instead of the term "extract". This lines up better with the
name we use for the *_addr instructions, "address projection" and avoids
ambiguity since unchecked_enum_data does not have the word "extract" in it.

Additionally by adding in the failable initializers, my centralization of the
initialization logic enables me to ensure that isAddrProjection and
isValueProjection stay in sync with the various constructors via asserts. This
should prevent future bugs if we add additional notions of "projection".

Swift SVN r23356
2014-11-16 04:09:16 +00:00
Erik Eckstein
3460ec2487 Improve simplification of init_enum_data_addr+store+inject_enum_addr to an enum instruction.
The improvement is to accept harmless instructions between the store and the inject_enum_addr.
This solves <rdar://problem/18912906>



Swift SVN r23234
2014-11-11 11:08:16 +00:00
Mark Lacey
4f6e4394b2 Silence a few of the release build warnings.
Swift SVN r23156
2014-11-07 03:39:54 +00:00
Arnold Schwaighofer
ab892a7c6e SILCombiner: Delete dead partial_apply more aggressively
We used to delete partial_apply with a single strong_release user.

The new array code causes dead partial applys with mulitple
strong_retain/release users. We also want to delete those. Currently, the code
handles the case where all users are retain/releases in the same basic block.

rdar://18840718

Swift SVN r23071
2014-11-02 21:21:49 +00:00
Roman Levenstein
c8d180e660 Generalize the switch_int instruction into switch_value instruction, which may switch on arguments of builtin integer types or function types. The later is required for implementing a more efficient speculative devirtualizaiton implementation. Implement lowering of switch_value into LLVM code. In case of integer operands, it reuses LLVM's switch optimizations. Support for switching on function types is not yet bullet-proof and will be refined in the subsequent patches.
rdar://18508812

Swift SVN r23042
2014-10-31 22:55:56 +00:00
Roman Levenstein
f016754ef9 Add a new select_value instruction. This instruction should be the equivalent of select_enum, just for builtin int types. Such an instruction is needed e.g. to efficiently implement conversions of Int raw values to C-like enums.
rdar://18812325

Swift SVN r23036
2014-10-31 20:44:11 +00:00
Arnold Schwaighofer
ec0273098d SILCombiner: fix_lifetime(alloc_stack) -> fix_lifetime(load(alloc_stack))
For loadable types.

rdar://18806686

Swift SVN r23033
2014-10-31 15:58:37 +00:00
Arnold Schwaighofer
dd2d62b396 SILCombiner: Collapse existential pack/unpack/ref_to_raw_pointer casts
Also collapse existential pack/unpack/unchecked_ref_cast.

 (ref_to_raw_pointer (open_existential_ref (init_existential_ref x)))
  ->
 (ref_to_raw_pointer x)

 (unchecked_ref_cast (open_existential_ref (init_existential_ref x)))
  ->
 (unchecked_ref_cast x)

radar://18806550

Swift SVN r23032
2014-10-31 15:58:36 +00:00
Adrian Prantl
c41b30299f Audit all SILPasses to ensure that new instructions are never created
without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
2014-10-28 01:49:11 +00:00
Michael Gottesman
c89c902ec7 Fix some 80+ errors. NFC.
Swift SVN r22932
2014-10-24 22:25:12 +00:00
Arnold Schwaighofer
477594a9d8 SILCombiner: Simplify select_enum_addr -> load + select_enum for loadable types
This enables Mem2Reg'ing the enum. Without this reapplying r22828 would cause
some serious regressions.

Swift SVN r22851
2014-10-20 22:22:25 +00:00
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +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
Dmitri Hrybenko
5c9c675291 Revert "Remove type check workaround for invalid casts"
This reverts commit r22498.  We need more auditing of stdlib for invalid
casts.

rdar://18151953

Swift SVN r22536
2014-10-06 08:27:35 +00:00