Commit Graph

111 Commits

Author SHA1 Message Date
Arnold Schwaighofer
8016bc0fa0 Canonicalize cmp_eq %X, -1 -> xor (cmp_eq %X, 0), -1
Swift SVN r27846
2015-04-27 23:46:48 +00:00
Michael Gottesman
583d7aa30a Add a delete callback to SILBuilder so that if we delete retains and releases in emitStrongRelease, emitReleaseValue, passes (like SILCombine) can update their state. Also teach the closure deletion code how to detect such a case and not send a notification message if no new instruction is created.
Swift SVN r27803
2015-04-27 05:37:09 +00:00
Michael Gottesman
da0f1b972f Delete dead code.
Swift SVN r27773
2015-04-26 21:19:06 +00:00
Chris Lattner
79b976dfc3 '#if 0' a big function that is never called to silence a warning. Someone should
look at this and nuke the function if it really is dead.


Swift SVN r27758
2015-04-26 15:13:04 +00:00
Michael Gottesman
af1be5004d Change SILCombine to use tryDeleteDeadClosure.
rdar://19552593

Swift SVN r27750
2015-04-26 05:11:56 +00:00
Erik Eckstein
87e8fa4c8e SILCombine: Fixed missing strong_release for stores to an eliminated dead array.
rdar://problem/19460043



Swift SVN r27635
2015-04-23 13:52:35 +00:00
Roman Levenstein
61fd0abd51 [sil-combine] Fix a failure during compilation of Swiftz
rdar://20645583

Swift SVN r27555
2015-04-22 03:15:45 +00:00
Chris Lattner
ea47d6ec8e remove dead code.
Swift SVN r27515
2015-04-21 03:37:39 +00:00
Roman Levenstein
5bc45d000e [sil-combine] Peephole: inject_enum_addr (addr, val), switch_enum_addr (addr, val: bb1, ...) -> select_enum_addr, switch_value
rdar://20619835

Swift SVN r27492
2015-04-20 20:33:52 +00:00
Arnold Schwaighofer
7536fc59af SILCombine: Add missing debug scope
Swift SVN r27482
2015-04-20 16:53:16 +00:00
Mark Lacey
027c328deb The retain and release counts of a partial_apply may be unbalanced.
In hasOnlyRetainReleaseUsers() we both assert that the retain/release
are balanced, as well as do a normal check and bail.

The assert is overzealous since we can legitimately have cases where the
releases are removed due to being unreachable. In this case we should
just do the normal check and bail.

Fixes rdar://problem/20565974.

Swift SVN r27476
2015-04-20 05:11:29 +00:00
Roman Levenstein
8152b80f4d Avoid inserting a new instruction twice during cast optimizations.
CastOptimizer handles insertion of new instructions during peepholes on its own. sil-combine should not try to insert them again.

Swift SVN r27378
2015-04-16 20:28:16 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Mark Lacey
8fad304e02 Fix a leak.
swift::clearBlockBody() in Local.cpp was popping instructions rather
than erasing them, resulting in leaking any instructions removed via
this function (which is reached via removeDeadBlock(), called throughout
SimplifyCFG).

Also tweak a couple comments and remove an assert that cannot fire.

Swift SVN r27018
2015-04-05 07:12:35 +00:00
Andrew Trick
891753747f SILCombine. Bail out of propagateConcreteTypeOfInitExistential on archetypes.
Fixes <rdar://problem/20310739> HELP!!! Xcode 6.3 beta 4: segmentation fault 11.

Swift SVN r26903
2015-04-02 21:50:08 +00:00
Mark Lacey
23b6bd84f6 Do not build the call graph just to maintain it.
Before this commit, passes that were attempting to maintain the call
graph would actually build it if it wasn't already valid, just for the
sake of maintaining it.

Now we only maintain it if we already had a valid call graph built.

Swift SVN r26873
2015-04-02 17:16:01 +00:00
Roman Levenstein
05bf59ef2b [sil-combine] Inform the CallGraph about newly created ApplyInsts.
We were not updating the CallGraph with new ApplyInsts inside sil-combine yet.

Swift SVN r26867
2015-04-02 07:04:12 +00:00
Nadav Rotem
412f65a894 Fix a Release mode warning of unused variable.
Swift SVN r26657
2015-03-28 00:20:29 +00:00
Mark Lacey
1f23ff27bb Remove the transparent bit from apply instructions.
We no longer need or use it since we can always refer to the same bit on
the applied function when deciding whether to inline during mandatory
inlining.

Resolves rdar://problem/19478366.

Swift SVN r26534
2015-03-25 08:36:34 +00:00
Erik Eckstein
2c967f891d SILCombine: Optimize binary bit operations: and, or, xor.
It does the usual things, e.g. x & 0 -> 0, x | 0 -> x, etc.



Swift SVN r26489
2015-03-24 15:48:30 +00:00
Arnold Schwaighofer
d2c434727b SILCombine: Remove 'dead' alloc_stack live ranges
A dead alloc_stack live range is one that is only copied into but not otherwise
used other than being destroyed and deallocated.

rdar://19851133

Swift SVN r26317
2015-03-19 22:03:57 +00:00
Nadav Rotem
5bdfcc6599 Fix an unused variable warning.
Swift SVN r26315
2015-03-19 20:54:12 +00:00
Arnold Schwaighofer
aae8a3e263 Use ASTContext's getBridgedToObjC instead of reimplementing it.
Roman alerted me that this implementation already exists.

Swift SVN r26280
2015-03-18 22:24:05 +00:00
Roman Levenstein
9a1f1ba4b4 [sil-combine] Add a new peephole for alloc_ref_dynamic -> alloc_ref transformations.
If a metatype used by alloc_ref_dynamic is coming from a successful checked_cast_br [exact], then we know that this is the exact metatype. Therefore, we can simplify:

  checked_cast_br [exact] $Y.Type to $X.Type, bbSuccess, bbFailure
  ...
  bbSuccess(%T: $X.Type):
  alloc_ref_dynamic %T : $X.Type, $X

into:

  checked_cast_br [exact] $Y.Type to $X.Type, bbSuccess, bbFailure
  ...
  bbSuccess(%T: $X.Type):
  alloc_ref $X

Swift SVN r26276
2015-03-18 20:27:45 +00:00
Arnold Schwaighofer
4e9c1c47a5 SILCombine: Fix bugs in isCastKnownToSucceed
Add more test cases.

Swift SVN r26266
2015-03-18 17:43:10 +00:00
Arnold Schwaighofer
7f6a0a1ee2 Make sure we to only combine casts we know will succeed.
I don't think we can sneek one by the compiler but lets be conservative.

  1> import Foundation
  2> struct Unbridged {}
  3> var a : [Unbridged] = []
a: [Unbridged] = 0 values
  4> a as NSArray
repl.swift:4:3: error: '[Unbridged]' is not convertible to 'NSArray'
a as NSArray
~^~~~~~~~~~
  4> func test<T>(a :[T]) -> NSArray { return a as NSArray }
repl.swift:4:44: error: '[T]' is not convertible to 'NSArray'

Swift SVN r26259
2015-03-18 15:38:14 +00:00
Roman Levenstein
3b21c779af [sil-combine] Add a new peephole (alloc_ref_dynamic (metatype X.Type)) -> alloc_ref X
This peephole is useful on its own and it helps the devirtualizer in cases, where instances are allocated by means of alloc_ref_dynamic. This partially addresses rdar://20198045.

Swift SVN r26253
2015-03-18 08:33:59 +00:00
Arnold Schwaighofer
977f1b1b3c Fix grammar in comment.
Swift SVN r26243
2015-03-17 23:48:23 +00:00
Arnold Schwaighofer
003d6435a2 SILCombine: Teach sil-combine about bridgeTo/FromObjectiveC identity compositions
rdar://19178324

Swift SVN r26241
2015-03-17 23:27:20 +00:00
Joe Groff
7f886c924b SIL: Make 'isReferenceCounted' a bit on TypeLowering.
This allows types to be lowered as scalar reference-counted types without requiring them to have AST-level reference semantics. For now, put in a staging assertion to ensure isReferenceCounted == hasReferenceSemantics to make sure we set the bit properly everywhere.

Swift SVN r26238
2015-03-17 21:51:06 +00:00
Roman Levenstein
aea50324fc Remove the cast optimization logic from sil-combine and simplify-cfg and turn them into clients of CastOptimizer.
This is the last part of the re-factoring. Now all the logic for performing cast optimizations is inside CastOptimizer, which makes it easier to reason about it and to maintain it.

Swift SVN r26123
2015-03-14 02:23:05 +00:00
Roman Levenstein
850f567cc7 [sil-combine] Perform folding of always failing unconditional_checked_cast_addr.
Replace a failing unconditional_checked_cast_addr by a trap, followed by an "unreachable" instruction.

rdar://20115697 and rdar://20115697

Swift SVN r26031
2015-03-12 03:37:31 +00:00
Roman Levenstein
7a7a3c37bb [sil-combine] Fold always failing unconditional_check_cast instructions into traps followed by unreachable instruction.
rdar://20115009

Swift SVN r25990
2015-03-11 20:34:45 +00:00
Roman Levenstein
d674034113 [sil-combine] Add a peephole to remove any code after an "unreachable" instruction.
This is useful for cleaning-up the code generated by intermediate transformations, e.g. for cases where we perform folding of always failing casts into traps followed by an unreachable instruction. I'll make use of it in my subsequence commits.

Swift SVN r25988
2015-03-11 20:34:43 +00:00
Joe Groff
962a87f444 SIL: Rename address-only existential instructions to '{init,deinit,open}_existential_addr'.
For better consistency with other address-only instruction variants, and to open the door to new exciting existential representations (such as a refcounted boxed representation for ErrorType).

Swift SVN r25902
2015-03-09 23:55:31 +00:00
Roman Levenstein
ecd9298090 Small optimization of cast-folding: Don't generate unconditional cast if its result is not used.
Swift SVN r25691
2015-03-02 22:28:22 +00:00
Roman Levenstein
a4055afc15 Third part of the cast folding and type-casts re-factoring. Addressing JoeG's comments.
This patch does the following:
- Improvements and correctness fixes for conversions of existential metatypes. They may succeed if you have a concrete or existential metatype that conforms to the protocol. Based on Joe's review of my previous patch.
- Removes special-cases for AnyObject. AnyObject is handled as any other class existential.
- Improves folding of conversions from class existential metatypes to concrete non-class metatypes
- Improves comments.
- Adds more tests to cover new test-cases.
- Adjusts a few existing tests.

Swift SVN r25690
2015-03-02 22:28:21 +00:00
Arnold Schwaighofer
44479683b3 SILBuilder: createBuiltinCmp -> createBuiltinBinaryFunction
Also add createBuiltinBinaryFunctionWithOverflow. NFC.

Swift SVN r25663
2015-03-02 01:05:33 +00:00
Roman Levenstein
c199905a2f Second part of the cast folding and type-casts re-factoring.
This patch does the following:
- Moves the logic for handling special-case of converting to/from AnyObject.Protocol (and existential.Protocol in general) into DynamicCasts, where all other cases are handled already.
- Moves the peephole which was folding checked_cast_br into an unchecked cast and branch from sil-combine into sil-simplify-cfg, because it is a better place for it, since this peephole affects the CFG. The corresponding test is also moved from sil_combine.sil into simplify_cfg.sil.
- Adds a few checked_cast_br peepholes to sil-combine.   They try to simplify checked_cond_br instructions using existential metatypes by propagating a concrete type whenever it can be determined statically.
- Adds a new test with a lot of test-cases that make sure we are really folding many type-checks at compile-time now.

Swift SVN r25504
2015-02-24 17:31:08 +00:00
Roman Levenstein
c97f748fb9 Move the logic for folding type casts using statically known protocol conformances into DynamicCasts.cpp.
The logic for different special cases of type casting is spread over multiple places currently. This patch simply re-factors some of that  code (folding of of type casts using statically known protocol conformances) and moves it into one central place, which makes it easier to maintain. Plus, it allows other clients of DynamicCasts benefit from it as well, e.g. the inliner can use this now. NFC.

Swift SVN r25486
2015-02-23 21:30:48 +00:00
Luqman Aden
b9c360e864 Minor changes to incorporate feedback on r25416.
Swift SVN r25434
2015-02-20 19:48:07 +00:00
Luqman Aden
e1c60464d3 Fold getCmpFunction function into helper method on SILBuilder.
Swift SVN r25416
2015-02-20 04:08:08 +00:00
Luqman Aden
858d8d99df SILCombine: Add cmp_*_T . (zext U->T x, zext U->T y) => cmp_*_T (x, y)
peephole for unsigned/equality comparisons.

Fixes <rdar://problem/19759124>

Swift SVN r25404
2015-02-20 00:39:33 +00:00
Michael Gottesman
669cdc537c Create an entrypoint tryToConcatenateStrings and hide the class StringConcatenationOptimizer in Local.cpp.
In every instance, we were just creating the StringConcatenationOptimizer and
then invoking optimize on it. This is a cleaner solution since the details of
how we perform the string concatenation are hidden in Local.cpp instead of being
in a header.

NFC.

Swift SVN r25341
2015-02-17 01:59:13 +00:00
Roman Levenstein
12b8a54ea4 [sil-combine] Further correctness fix for checked_cast_addr_br folding. Check that superclasses cannot have extensions.
rdar://19852884

Swift SVN r25335
2015-02-17 00:25:16 +00:00
Roman Levenstein
b49ca38a9d [sil-combine] Correctness fix for checked_cast_addr_br folding.
Don't fold the negative case if the type is internal and we are not doing whole-module-optimization, because an extension may define a conformance in a different file.

Fold the negative case for private types. It is safe, because conformances could be defined only in the current file and we should have seen them.

rdar://19852884

Swift SVN r25331
2015-02-16 23:28:30 +00:00
Arnold Schwaighofer
fa276b92c0 We should SILCombine a checked_cast_br of metatype AnyObject.Protocol to Some.type to a direct branch
rdar://19835737

Swift SVN r25328
2015-02-16 22:42:51 +00:00
Luqman Aden
19fbae1469 Revert "SILCombine: Peephole for (unchecked_ref_cast . open_existential_ref =>"
This reverts commit r25291.

Swift SVN r25315
2015-02-16 18:13:30 +00:00
Luqman Aden
4bad794769 SILCombine: Peephole for (unchecked_ref_cast . open_existential_ref =>
unchecked_ref_cast) and (ref_to_raw_pointer . open_existential_ref) =>
ref_to_raw_pointer.

Fixes <rdar://problem/19759111>

Swift SVN r25291
2015-02-14 02:00:47 +00:00
Mark Lacey
ba444b7250 Remove unused header file.
Swift SVN r25267
2015-02-13 10:07:12 +00:00