Commit Graph

11224 Commits

Author SHA1 Message Date
Roman Levenstein
6cc654759b Simplify a search for an existing generic specialization.
Use the new hasFunction API to check for existence of a specialization and clean-up the code.
2016-02-26 22:10:59 -08:00
Mark Lacey
f288c6c645 Remove two runs of the passes in AddSSAPasses.
Re-apply b00dcbe with a small test update, and a small change in pass
ordering.

I measure around a 10% reduction in compile times of release no-assert
builds of the stdlib and StdlibUnitTest.

For release + debug-swift builds, I see 20% reduction in stdlib compile
time.

My latest measurements show a few regressions at -O:
  Calculator
  NSError
  SetIsSubsetOf
  Sim2DArray

There is a small (0.1%) reduction in the libswiftCore.dylib size.

Being able to remove these is a consequence of the reordering that
happened in e50daa6.
2016-02-26 21:03:58 -08:00
eeckstein
718e9e6f72 Merge pull request #1462 from eeckstein/specializer_new_attempt
Specializer new attempt
2016-02-26 17:02:29 -08:00
Xin Tong
19c528e59d Make more passes respect no.optimize 2016-02-26 16:03:17 -08:00
Erik Eckstein
3a83cee006 Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.""
This reinstates commit 4187959e66.

The exposed crash in the ClosureSpecializer is fixed.
2016-02-26 14:05:48 -08:00
Erik Eckstein
0c2ca94ef7 Rewrite the ValueLifetimeAnalysis.
It fixes a problem with lifetime regions having "exit-edges". This crashed the ClosureSpecializer.
2016-02-26 14:05:48 -08:00
Erik Eckstein
2e6926cdce Re-format condition in loop. NFC. 2016-02-26 14:05:48 -08:00
Arnold Schwaighofer
a9cbacd456 [SILCombine] Use the opened archetype instead of reading the type from self
The opened archetype already has metatypes stripped off.

The problem was in code that tried to propagate the type from open_existentials
in static existential calls.

  %0 = metatype thick ClientSocket.Type
  %1 = init_existential_metatype %0 : thick ClientSocket.Type, thick Socket.Type
  %2 = open_existential_metatype %1 : thick Socket.Type to thick (@opened(...) Socket).Type
  %3 = witness_method opened(...) Socket, #Socket.newWithConfig!1, %2
  try_apply %3<@opened(...) Socket>(%2)

We would read the type of '%2' which is a metatype of '@open(...)' in the
substitution replacement code comparing it to the subsitution which is just
'@open(...)'. We already computed the archetype earlier so just use that
instead.

SR-811
rdar://24825970
2016-02-26 13:54:01 -08:00
Adrian Prantl
310b0433a9 Reapply "Serialize debug scope and location info in the SIL assembler language.""
This ireapplies commit 255c52de9f.

Original commit message:

Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 13:28:57 -08:00
Adrian Prantl
255c52de9f Revert "Serialize debug scope and location info in the SIL assembler language."
Temporarily reverting while updating the validation test suite.

This reverts commit c9927f66f0.
2016-02-26 11:51:57 -08:00
Adrian Prantl
c9927f66f0 Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 10:46:29 -08:00
Mark Lacey
f86f9f090d Simplify some code in GlobalOpt.
Builtin.once() expects thin functions, so we don't need to try to walk
through thin_to_thick_function here.

I suspect this might have been a vestige of having used apply for these
at one point.
2016-02-26 09:06:48 -08:00
Mark Lacey
a843d4416f Fix arity in assert message. 2016-02-26 08:30:37 -08:00
Michael Gottesman
e4914bd4f9 [loop-utils] We always create pre-headers now before this step of loop canonicalization, so change an early exit to an assert. 2016-02-25 15:32:16 -08:00
Erik Eckstein
3fe19515df Handle more complex conditions in ColdBlockInfo.
Now we can handle the case where the cond_br condition is a block argument.
This change mostly effects the inlining heuristic.

rdar://problem/24777440
2016-02-25 13:31:11 -08:00
Erik Eckstein
767d58263e Inliner: make the -sil-inline-test-threshold option useful for testing inlining into cold blocks.
Assume a test-threshold of 0 in cold blocks instead of the regular TrivialFunctionThreshold.
2016-02-25 13:28:43 -08:00
Erik Eckstein
bbc6bae6d7 Inliner: remove some code which I committed accidentially (long time ago). 2016-02-25 13:28:43 -08:00
Mark Lacey
f1891d41ef Fix 80-column violations in GlobalOpt.cpp. 2016-02-25 13:04:16 -08:00
Mark Lacey
6a5b25120d Fix 80-column violations in ColdBlockInfo.{h,cpp}. 2016-02-25 13:04:16 -08:00
swiftix
17a2106e3a Merge pull request #1429 from swiftix/wip-prespecializations-module
Move pre-specializations of popular types away from the stdlib.

This saves 4%-5% of code size in libswiftCore.dylib.
2016-02-25 12:44:36 -08:00
Max Moiseev
488b464f10 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-25 12:21:56 -08:00
Roman Levenstein
8dff92ad4d Move pre-specializations of popular types away from the standard library.
Pre-specializations were only used by Onone builds, but were kept inside the standard library dylyb anyways. This commit moves all the pre-specializations into a dedicated Swift module and a dynamic library, which are only used by Onone builds.

This reduces the code size of libswiftCore.dylib by 4%-5%.
2016-02-25 11:23:15 -08:00
Erik Eckstein
f70b53b015 Revert "Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result."""
This reverts commit c556d5cd39.

Hitting a new assert.
2016-02-25 09:50:11 -08:00
Erik Eckstein
c556d5cd39 Reinstate "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.""
This reinstates commit 4187959e66.

After Xin's recent fix in ARC (6a9a430f68) the crash on i386 should be resolved.
2016-02-25 08:48:15 -08:00
Xin Tong
6a9a430f68 Fix a thinko in ARC.
Only happens with obscure retain/release pairs.
2016-02-24 23:37:04 -08:00
Mark Lacey
b6de7239e6 Revert "Remove two runs of the passes in AddSSAPasses."
This reverts commit b00dcbebbf due to a
test failure.
2016-02-24 22:12:29 -08:00
Mark Lacey
b00dcbebbf Remove two runs of the passes in AddSSAPasses.
I measure around a 10% reduction in compile times of release no-assert
builds of the stdlib and StdlibUnitTest.

For release + debug-swift builds, I see 20% reduction in stdlib compile
time.

I saw no reproducible regressions in the benchmarks, and a few
improvements.

There is a small (0.1%) reduction in the libswiftCore.dylib size.

Being able to remove these is a consequence of the reordering that
happened in e50daa6.
2016-02-24 21:54:27 -08:00
Max Moiseev
bb3eaaf308 Merging in latest master 2016-02-24 15:10:25 -08:00
Mark Lacey
e50daa6e3b Shuffle around some of the optimization passes.
The end goal here is to end up with a good pass ordering that will allow
us to only run one set of these passes, rather than running them
twice. This is a start in that direction.

No real impact measured on compile times as of this change. On
benchmarks I see a mix of regressions and improvements.

-O improvements:
  Calculator           -17.6%     1.21x
  Chars                -54.4%     2.19x
  PolymorphicCalls     -14.7%     1.17x
  SetIsSubsetOf        -14.1%     1.16x
  Sim2DArray           -14.1%     1.16x
  StrToInt             -30.4%     1.44x

-O regressions:
  CaptureProp          +32.9%     0.75x
  DictionarySwap       +36.0%     0.74x
  XorLoop              +39.8%     0.72x

-Ounchecked improvements:
  Chars                -58.0%     2.38x

-Ounchecked regressions:
  CaptureProp          +33.3%     0.75x

-Onone improvements:
  StrToInt             -14.9%     1.18x
  StringWalk           -47.6%     1.91x
  StringWithCString    -17.2%     1.21x
  (many more smaller improvements)

-Onone regressions:
  Calculator           +21.5%     0.82x
  OpenClose            +10.1%     0.91x
2016-02-24 14:18:08 -08:00
Mark Lacey
0a893c1f88 Fix typo in comment. 2016-02-24 14:17:32 -08:00
Slava Pestov
c6a0f51611 SIL: Add devirtualizer support for default witness methods
We ignore substitutions from the conformance, using the Self type
substitution from the call site instead.

The new SILFunctionType::getDefaultWitnessMethodProtocol() method
is used to figure out what "shape" the Self substitutions need
to take.

This is cleaner than it was before the method was added, but is
still a bit of a hack; more and more it appears that we need to
stop thinking of witness_method as a separate calling convention,
and design what @rjmccall described as "abstraction patterns for
generic signatures" instead.
2016-02-24 00:29:07 -08:00
Xin Tong
e24ce07eed Remove some unreachable code. Also add an assertion. NFC 2016-02-23 16:52:35 -08:00
Xin Tong
8bb673895a Consistenly use RCIdentity to get the RCRoot of the operand.
We were using a stripCast in some places and getRCIdentityRoot in others.
stripCasts is not identical to getRCIdentityRoot.

In particular, it does not look through struct_extract, tuple_extract,
unchecked_enum_data.

Created a struct and tuple test cases for make sure things are optimized
as they should be.

We have test case for unchecked_enum_data before.
2016-02-23 16:47:19 -08:00
Michael Gottesman
a5be2fff01 [sil] Use FullApplySite instead of ApplyInst in SILInstruction::getMemoryBehavior().
We were giving special handling to ApplyInst when we were attempting to use
getMemoryBehavior(). This commit changes the special handling to work on all
full apply sites instead of just AI. Additionally, we look through partial
applies and thin to thick functions.

I also added a dumper called BasicInstructionPropertyDumper that just dumps the
results of SILInstruction::get{Memory,Releasing}Behavior() for all instructions
in order to verify this behavior.
2016-02-23 15:00:43 -08:00
Max Moiseev
0b759a409c Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-23 14:26:14 -08:00
Erik Eckstein
5b4c73ed3b Revert "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result."
This reverts commit 4187959e66.

There is a crash in StdlibUnittests on i386 (Release-Assert build)
2016-02-23 08:29:41 -08:00
practicalswift
fd621b3ece [gardening] Fix recently introduced typo: "abstruction" → "abstraction" 2016-02-23 09:09:26 +01:00
Todd Fiala
8ff40a3a22 Revert "Move pre-specializations of popular types away from the standard library."
This reverts commit 4d4c2cdba9.
2016-02-22 21:18:32 -08:00
swiftix
c978092bec Merge pull request #1392 from swiftix/wip-prespecializations-module
Move pre-specializations of popular types away from the stdlib to reduce the stdlib code size.
2016-02-22 18:17:57 -08:00
Michael Gottesman
5ace1b4b01 Merge pull request #1397 from gottesmm/remove-remaining-undefined-behavior-from-iterators
[upstream-update] dexonsmith in an upstream commit realized he missed an
2016-02-22 14:22:48 -08:00
Erik Eckstein
4187959e66 GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.
With this re-abstraction a specialized function has the same calling convention as if it would have been written with the specialized types in the first place.
In general this results in less alloc_stacks and load/stores.
It also can eliminate some re-abstraction thunks, e.g. if a generic closure is used in a non-generic context.
It some (hopefully rare) cases it may require to add re-abstraction thunks.

In case a function has multiple indirect results, only the first is converted to a direct result. This is an open TODO.
2016-02-22 13:58:10 -08:00
Erik Eckstein
682c1cb5a1 refactoring: move static function isPartialApplyOfReabstractionThunk from SILCombiner to Local.
Because it will be needed by the generic specializer, too.
NFC
2016-02-22 13:58:10 -08:00
Erik Eckstein
3b6a4d8231 Handle array.get_element semantics calls with direct results in SIL optimizations.
Currently the array.get_element calls return the element as indirect result.
The generic specializer will change so that the element can be returned as direct result.
2016-02-22 13:58:10 -08:00
Erik Eckstein
666e20381f Refactor some ArraySemanticsCall code. NFC. 2016-02-22 13:58:10 -08:00
Michael Gottesman
650600aa2f [upstream-update] dexonsmith in an upstream commit realized he missed an
iterator/pointer comparison issue that yields undefined behavior. This updates
Swift for the landing of this change in swift-llvm/stable.

I am going to cherry-pick the given change into swift-llvm/stable since there is no
reason not to do this now and it will prevent more of these conversions from
creeping into the code base.

We really want to avoid as much undefined behavior as we possibly can.
2016-02-22 13:03:15 -08:00
Max Moiseev
fcad164e18 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-22 12:59:57 -08:00
Mark Lacey
bc36b2a601 Improve handling of unreachable blocks in mem2reg.
We were handling regular uses, but not handling promotions in things
like debug_value_addr.

This was exposed by some pass ordering changes I have in an upcoming
commit.
2016-02-22 12:11:00 -08:00
Roman Levenstein
4d4c2cdba9 Move pre-specializations of popular types away from the standard library.
Pre-specializations were only used by Onone builds, but were kept inside the standard library dylyb anyways. This commit moves all the pre-specializations into a dedicated Swift module and a dynamic library, which are only used by Onone builds.

This reduces the code size of libswiftCore.dylib by 5%.
2016-02-22 07:54:44 -08:00
Xin Tong
673054473d Reorder header. NFC 2016-02-21 21:35:38 -08:00
practicalswift
46a1a8de2e [gardening] Fix recently introduced typo: "guanranteed" → "guaranteed" 2016-02-21 07:58:02 +01:00