Commit Graph

79 Commits

Author SHA1 Message Date
Michael Gottesman
a3aa89d4c4 Remove Callback from SILBuilder and instead rename
emit{StrongRelease,ReleaseValue} => emit{StrongRelease,ReleaseValue}AndFold.
Then introduce a new method emit{StrongRelease,ReleaseValue} that returns a
PointerUnion containing the increment to be deleted if it exists. This obviates
the need for the callback.

Swift SVN r27804
2015-04-27 07:29:13 +00:00
Michael Gottesman
abb34fa1b0 Teach mandatory inlining how to use closure deletion infrastructure.
rdar://19552593

Swift SVN r27751
2015-04-26 05:11:57 +00:00
Nadav Rotem
196ee35f2c Teach the Mandatory inliner to handle TryApply instructions.
Swift SVN r27331
2015-04-15 21:22:55 +00:00
Nadav Rotem
1891de29a4 Teach getCalleeFunction to work with FullApplySite, that wraps TryApply and Apply instructions. NFC.
Swift SVN r27329
2015-04-15 21:22:48 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Mark Lacey
730ef41385 Make devirtualizer clients remove old applies.
This makes it feasible for clients to maintain the call graph.

Swift SVN r26997
2015-04-05 02:27:57 +00:00
Mark Lacey
07a5ebed66 Rename devirtualizeApply to tryDevirtualizeApply.
This is more consistent with the other naming in the devirtualization
code for things that might fail.

Swift SVN r26788
2015-04-01 02:10:52 +00:00
Mark Lacey
db3530e7c8 Tweak function deletion logic in mandatory inlining.
Now that we generate autoclosure functions with the transparent bit set,
we only need to check that bit to determine whether we can delete
inlined functions.

Swift SVN r26535
2015-03-25 09:03:38 +00:00
Mark Lacey
a367feae6a Make all autoclosures transparent, and stop checking isTransparent on apply.
This should clear the way for removing isTransparent on apply entirely.

Previously we marked any apply of an autoclosure transparent, but now
that the mandatory inliner inlines anything marked transparent, we don't
need that.

Resolves rdar://problem/20286251.

Swift SVN r26525
2015-03-25 05:55:33 +00:00
Mark Lacey
3bb5122aaa During mandatory inlining, look at isTransparent() on the callee.
Mandatory inlining normally only looks at isTransparent() on the apply
instruction. This change makes it also inline in cases where the apply
is not marked isTransparent(), but the applied function is. This can
arise in cases where previous transparent inlining exposes new
opportunities, e.g. when a transparent function is passed as a parameter
to another transparent function.

Resolves rdar://problem/19419019.

Swift SVN r26516
2015-03-25 02:48:11 +00:00
Nadav Rotem
d78b376d07 [passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the
call graph, so we've decided to change the way passes invalidate analysis.  In the new scheme, the lattice
is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches.
Now, passes report which traits they preserve, which is the opposite of the previous implementation where
passes needed to report what they invalidate.

Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some
of the code in a following commit.

Swift SVN r26449
2015-03-23 21:18:58 +00:00
Mark Lacey
3ab2e208af Devirtualize during mandatory inlining.
With this change we will devirtualize in trivial cases where mandatory
inlining has exposed opportunities due to substituting types, for
example substituting a struct type into a witness_method where we can
now easily determine exactly what method will be called.

This makes it possible to use @transparent on struct methods that are
dispatched via generic functions, resulting in the opportunity to emit
diagnostics for these methods as well as eliminate the overhead of the
indirect call.

I saw a handful of 10+% perf improvements at -Onone on our benchmarks.

In theory this should allow us to remove the overloads for ++/-- in
FixedPoint.swift.gyb without a performance penalty (and with the proper
overflow diagnostics), but unfortunately if we were to do so, we would
currently dispatch to functions that lack runtime overflow
checks (rdar://problem/20226526).

Swift SVN r26397
2015-03-21 23:05:24 +00:00
Mark Lacey
d57fdb9426 Move the responsibility for deleting the apply outside of inlineFunction().
Make the clients remove the apply, which paves the way for the clients
to potentially update the call graph when inlining is successful.

Swift SVN r26075
2015-03-13 01:18:05 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Erik Eckstein
792b7b5f1b Don't mandatory-inline into thunks.
This means that even transparent functions are not inlined into thunks.
Part of rdar://problem/19701613.

This reduces the size of protocol witnesses in the dylib by 24% resulting in a total code size reduction of 5% (in the dylib).
There are no significant changes in the benchmarks.



Swift SVN r25037
2015-02-06 13:34:10 +00:00
Mark Lacey
a8944f4540 Enable mandatory inlining of generic functions with unbound generic types.
This allows us to inline @transparent functions in cases like this:

  @transparent
  func partial<T, U>(x: T, f: (T) -> U) -> U {
    return f(x)
  }

  func applyPartial<U>(x: Int32, f: (Int32) -> U) -> U {
    return partial(x, f)
  }

I had planned on enabling this same behavior in the performance inliner
first in order to be able to test the underlying functionality more
thoroughly, but I hit a blocking issue pretty quickly in type
lowering (rdar://problem/19387372).

Given that @transparent is not currently user-facing, it seems
reasonable to go ahead and enable this now and fix any new issues it
exposes since it should be easy to work around those issues by not using
@transparent.

There were lots of performance differences as a result of this change,
mostly positive. Below I list the 10 largest improvements for each of
-Onone, -O, and -Ounchecked, along with all regressions greater than
10%. I will be opening radars for these.

-Onone
---------------------------------------
ArrayOfPOD                     104.200%
ArrayOfGenericPOD               40.700%
TwoSum                          37.800%
EditDistance                    35.600%
GenericStack                    33.500%
SwiftStructuresStack            29.700%
SwiftStructuresInsertionSort    29.300%
Havlak                          27.200%
NestedLoop                      26.800%
Life                            26.400%

SwiftStructuresTrie            -15.500%

-O
---------------------------------------
TwoSum                          46.200%
GenericStack                    37.900%
SwiftStructuresStack            37.100%
Dictionary                      30.200%
Forest                          27.800%
NSDictionaryImplicitConversion  24.400%
Prims                           23.500%
Dictionary2                     19.600%
DollarFilter                    17.00%
SwiftStructuresQueue            16.600%

NSStringConversion             -22.600%
SwiftStructuresTrie            -25.900%
PopFrontArray                  -44.100%

-Ounchecked
---------------------------------------
SwiftStructuresStack            38.900%
GenericStack                    37.400%
NSDictionaryImplicitConversion  21.200%
TwoSum                          20.500%
Histogram                       16.600%
DollarFilter                    15.900%
DollarFunction                  13.600%
ArrayLiteral                    12.900%
Forest                          12.300%
Prims                           10.300%

ImageProc                      -10.900%
InsertionSort                  -11.200%
StrToInt                       -11.800%
NBody                          -14.900%
SwiftStructuresTrie            -29.900%

Swift SVN r24263
2015-01-08 03:36:08 +00:00
Mark Lacey
9d6e7cddc8 Reapply r23673, which was reverted in r23679.
It had exposed a problem with the MemBehavior on a couple SIL
instructions which resulted in code motion moving a retain across an
instruction that can release (fixed in r23722).

From the original commit message:

    Remove restriction on substituting existentials during mandatory inlining.

    Issues around this have now been resolved, so we should now support
    anything that Sema lets through.

    Fixes rdar://problem/17769717.

Swift SVN r23729
2014-12-05 05:47:42 +00:00
Mark Lacey
2cb14c32fe Revert "Remove restriction on substituting existentials during mandatory inlining."
This reverts commit r23673.

It looks like this broke the DollarChain benchmark so I am backing it
out while I investigate.

Swift SVN r23679
2014-12-04 05:40:49 +00:00
Mark Lacey
f3b82c7bfd Remove restriction on substituting existentials during mandatory inlining.
Issues around this have now been resolved, so we should now support
anything that Sema lets through.

Fixes rdar://problem/17769717.

Swift SVN r23673
2014-12-04 01:12:42 +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
Erik Eckstein
43f68b6974 Enable dead function removal for internal function in whole-module compilation.
This is controlled by a new isWholeModule() attribute in SILModule.

It gives about 9% code size reduction on the benchmark executables.
For test-suite reasons it is currently not done for the stdlib.



Swift SVN r22491
2014-10-03 14:14:23 +00:00
Erik Eckstein
92dc4ee237 Don't increment refcounts of inlined SILFunctions for the purpose of debug info generation.
This prevented dead function removal of inlined dead functions. Beside the stdlib it's mostly
an issue of SIL size (and therefore compiletime), because llvm did remove such functions anyway.



Swift SVN r22301
2014-09-26 16:07:26 +00:00
Mark Lacey
33003d42e2 Fix 80-column violations.
Swift SVN r21059
2014-08-06 03:40:01 +00:00
Mark Lacey
a7556c89f9 Enable transparent inlining of some generic functions.
Fixes part of <rdar://problem/16196801>.

Inline generic functions, but only when:

- There are no unbound archetypes being substituted (due to various
  assumptions in TypeSubstCloner about having all concrete types).

- When no substitution is an existential (due to
  <rdar://problem/17431105>, <rdar://problem/17544901>, and
  <rdar://problem/17714025>).

This gets things limping along, but we really need to fix the above
limitations so that mandatory inlining never fails.

This doesn't enable inlining generics in the performance inliner. There
is no reason it shouldn't work as well, but there is no compelling
reason to do so now and it could have unintended effects on performance.

Some highlights from PreCommitBench -
O0:
            old (ms)   new (ms)  delta (ms)   speedup
ForLoops    1127.00     294.00      833.00     283.3%
LinkedList   828.00     165.00      663.00     401.8%
R17315246    982.00     288.00      694.00     241.0%
SmallPT     3018.00    1388.00     1630.00     117.4%
StringWalk  1276.00      89.00     1187.00    1333.7%
-- most others improve ~10% --

O3:
            old (ms)   new (ms)  delta (ms)   speedup
Ackermann   4138.00    3724.00      414.00      11.1%
Life          59.00      64.00        5.00      -7.8%
Phonebook   2103.00    1815.00      288.00      15.9%
R17315246    430.00     582.00      152.00     -26.1%
StringWalk  1173.00    1097.00       76.00       6.9%

Ofast:
            old (ms)   new (ms)  delta (ms)   speedup
Ackermann   3505.00    3715.00      210.00      -5.7%
Life          49.00      41.00        8.00      19.5%
Memset       684.00     554.00      130.00      23.5%
Phonebook   2166.00    1769.00      397.00      22.4%
StringWalk   829.00     790.00       39.00       4.9%

I've opened the following to track remaining issues that need to be
fixed before we can inline all transparent function applications:
<rdar://problem/17431105>
<rdar://problem/17544901>
<rdar://problem/17714025>
<rdar://problem/17768777>
<rdar://problem/17768931>
<rdar://problem/17769717>

Swift SVN r20378
2014-07-23 06:29:23 +00:00
Mark Lacey
1e87d7aab2 Minor clean-up of inliner code.
Don't pass substitutions as an argument since they are always going to
be from the apply we're passing in.

Swift SVN r18672
2014-05-30 20:24:48 +00:00
Mark Lacey
60044a9c54 Another small cleanup to mandatory inlining.
Move the check for transparency into the caller of getCalleeFunction()
rather than returning nullptr from getCalleeFunction() if the apply
isn't transparent.

Also remove an assert and a nullptr check that can't fail under
reasonable circumstances based on the current SIL design.

Swift SVN r16902
2014-04-27 01:02:55 +00:00
Mark Lacey
cd7a81633d Small clean-up. Use for loop rather than while.
Swift SVN r16901
2014-04-27 01:02:53 +00:00
Mark Lacey
1452d24671 Small cleanup: Remove unnecessary calls to getDef(), mostly in dyn_cast<>(...).
Swift SVN r16235
2014-04-11 23:05:16 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Chris Lattner
6540423613 rename CopyValueInst -> RetainValueInst. The .sil syntax
isn't changed yet.


Swift SVN r15775
2014-04-02 05:11:31 +00:00
Chris Lattner
001c1890e5 put all the SIL*Transform classes in anonymous namespaces, there is
no need for their symbols to be exported out of their implementation
file.


Swift SVN r14714
2014-03-06 01:49:53 +00:00
Michael Gottesman
c25d6f8390 [mandatory-inlining] Use getOptions() instead of passing around options.
Swift SVN r14493
2014-02-28 01:51:53 +00:00
Michael Gottesman
29e1a53bbb [deserialization] Deserialize transparent functions lazily iff they will be used in mandatory inlining.
Swift SVN r14490
2014-02-28 01:05:01 +00:00
Andrew Trick
731000b4cd Added -sil-print-all and -sil-verify-all options.
Swift SVN r13662
2014-02-07 23:07:11 +00:00
Nadav Rotem
27a1a63134 Remove unneeded empty virtual destructors.
Swift SVN r13599
2014-02-06 22:24:33 +00:00
Nadav Rotem
1ef0d157ca PassManager: Inject the function/module into the Transformation.
Now the pass does not need to know about the pass manager. We also don't have
runOnFunction or runOnModule anymore because the trnasformation knows
which module it is processing. The Pass itself knows how to invalidate the
analysis, based on the injected pass manager that is internal to the
transformation.

Now our DCE transformation looks like this:

class DCE : public SILModuleTransform {
  void run() {
    performSILDeadCodeElimination(getModule());
    invalidateAnalysis(SILAnalysis::InvalidationKind::All);
  }
};





Swift SVN r13598
2014-02-06 22:11:21 +00:00
Nadav Rotem
99b075c32a Rename SILFunctionTrans -> SILFunctionTransform
Swift SVN r13536
2014-02-06 01:32:10 +00:00
Nadav Rotem
f8c7b54d28 Delete the unused performXXX() functions.
Swift SVN r13531
2014-02-06 00:57:28 +00:00
Michael Gottesman
631f9326ab [PM] Change enum => enum class everywhere in the PM code. Additionally fix some typos.
Swift SVN r13507
2014-02-05 21:25:15 +00:00
Nadav Rotem
1df8e93bbb Convert the diagnostic methods into passes.
Swift SVN r13503
2014-02-05 20:30:49 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
Chris Lattner
79cbdc5c32 Teach the performance inliner that debug_value[_addr] are free.
Teach the mandatory inliner to drop debug_value[_addr] instructions
when inlining.  Otherwise, we get debug_value's for all of the arguments
splattered all over the place.  We want transparent functions to be
effectively ((nodebug)) in C parlance.


Swift SVN r12404
2014-01-16 16:06:47 +00:00
Chris Lattner
65454c4d2b Teach the mandatory inliner to tolerate debug_value instructions
hanging off partial_apply's when it is cleaning them up.  These
occur when autoclosure arguments are marked let, because that is
how debug info for lets is recorded.


Swift SVN r12369
2014-01-16 01:00:18 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Michael Gottesman
9de0af9d4a Change SILInliner to let the user specify the type of location (i.e. mandatory or not) that will be used by all the inlined instructions.
Swift SVN r11430
2013-12-18 19:06:23 +00:00
Michael Gottesman
4379283013 Remove inclusion of SILPasses/Passes.h into Subsystems.h and update all relevant files.
Swift SVN r10880
2013-12-05 19:58:21 +00:00
Chris Lattner
d5f2162c3b enhance the mandatory inline pass to delete the bodies of closures
that get fully inlined, in addition to transparent functions which
it already did.


Swift SVN r10454
2013-11-14 04:51:41 +00:00
Chris Lattner
4968cc208b A couple of related changes:
- Enhance SILBuilder::emitStrongRelease to be smarter.
- Start using emitStrongRelease in type lowering, SILGen,
  CapturePromotion (replacing its implementation of the
  same logic), and MandatoryInlining (one more place)
- Rename the primitive createStrongRetain/ReleaseInst
  instructions to lose their suffix.
- Now that createStrongRetain/ReleaseInst are not special
  cases from the naming perspective, remove some special cases
  from DeserializeSIL and ParseSIL.
  


Swift SVN r10449
2013-11-14 02:21:27 +00:00
Chris Lattner
9570e1fb0c Remove the "createStrongRetain" and "createStrongRelease" SILBuilder methods.
They are the same as createStrongRetainInst and createStrongReleaseInst, but
peephole away FunctionRefInst.  It turns out that there is only a couple
places in SILGen where this behavior is necessary, and this tramples on the
general pattern used in SILBuilder.


Swift SVN r10448
2013-11-14 02:00:41 +00:00
Chris Lattner
b2ac1db9f6 introduce a new helper to SILBuilder that emits a StrongRelease operation,
scanning up the local block to see if it immediately cancels a retain 
operation.

Use this in mandatory inlining to zap more retains and release.  Before
this patch, the result LogicValue allocation blocked this optimization,
preventing the partial_apply from being deleted from the case in 
rdar://15328833.




Swift SVN r10447
2013-11-14 01:50:28 +00:00