Commit Graph

6634 Commits

Author SHA1 Message Date
Arnold Schwaighofer
7aa62ce835 Add an inline(late) attribute
This disables inlining at the SIL level. LLVM inlining is still enabled. We can
use this to expose one function at the SIL level - which can participate in
dominance based optimizations but which is implemented in terms of a cheap check
and an expensive check (function call) that benefits from LLVM's inlining.

Example:

The inline(late) in the example below prevents inlining of the two checks. We
can now perform dominance based optimizations on isClassOrObjExistential.
Without blocking inlining the optimizations would apply to the sizeof check
only and we would have multiple expensive function calls.

@inline(late)
func isClassOrObjExistential(t: Type) -> Bool{
  return sizeof(t) == sizeof(AnyObject) &&
    swift_isClassOrObjExistential(t)
}

We do want inlining of this function to happen at the LLVM level because the
first check is constant folded away - IRGen replaces sizeof by constants.

rdar://17961249

Swift SVN r21286
2014-08-19 18:05:44 +00:00
Michael Gottesman
56d51ca9f1 [g-arc-opts] Teach the ARC optimizer how to strip off ref count equivalent operations such as casts and ref count identity preserving typed geps.
Now that the ARC optimizer does not rely on stripCasts I also added
unchecked_trivial_bit_cast to stripCasts.

This and r21164 give the following speedups > 10%:

Ary      55.95%
MatMul   36.71%
Ary2     34.97%
Richard  32.08%
PrimeNum 15.87%

<rdar://problem/17456455>

Swift SVN r21240
2014-08-15 22:47:57 +00:00
Nadav Rotem
54458fb892 Enable access control based devirtualization.
Patch (mostly) by Jordan Rose.

rdar://17890078. 



Swift SVN r21139
2014-08-12 00:43:18 +00:00
Nadav Rotem
b432f66c97 Teach the inliner not to inline functions with the @effects attribute during the high-level SSA PM.
This is the current behavior for @semantics("readonly") and it is needed by the high-level
optimization passes because after inlining the semantics/effects information is lost.



Swift SVN r21084
2014-08-07 06:36:44 +00:00
Nadav Rotem
8dd52d63cd Add the @effects(readonly/readnone/readwrite) attribute.
Swift SVN r21070
2014-08-06 18:48:20 +00:00
Mark Lacey
2217b29956 Check for overflow in SILFunction reference count adjustments.
I have some local changes where I saw the refcount decrement below
zero. These seem like reasonable sanity checks.

Swift SVN r21060
2014-08-06 03:40:02 +00:00
Joe Groff
623aba1786 Encapsulate Substitution's state.
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
2014-07-23 18:00:38 +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
Michael Gottesman
4ec0a81e5f Add linkage SILLinkage::SharedExternal for deserialized functions with shared linkage.
*NOTE* This linkage is different from {Public,Hidden}External in that it has no
extra semantic meaning beyond shared.

The use of this linkage is to ensure that we do not serialize deserialized
shared functions. Those shared functions can always be re-deserialized from the
original module. This prevents a whole class of bugs related to the
creation of module cross references since all references to the shared
item go straight to the original module.

<rdar://problem/17772847>

Swift SVN r20375
2014-07-23 05:04: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
Manman Ren
bea41c0bd3 [Alias Analysis] handle casts in projection path.
We ignore casts when generating projection paths for alias analysis. When
comparing two paths, we say no alias when accessing different fields of
the same Decl Context.


Swift SVN r20353
2014-07-23 00:02:28 +00:00
Chris Lattner
d473159814 Implement the start of a diagnostic to detect cases where inout aliasing violations are
introduced, as these are obvious miscompilations and clearly mystifying to our user base.

This is enough to emit diagnostics like this:

writeback_conflict_diagnostics.swift:58:70: error: inout writeback aliasing conflict detected on computed property 'c_local_struct_property'
  swap(&c_local_struct_property.stored_int, &c_local_struct_property.stored_int)
                                             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
writeback_conflict_diagnostics.swift:58:33: note: concurrent writeback occurred here
  swap(&c_local_struct_property.stored_int, &c_local_struct_property.stored_int)
        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

which isn't great, but is better than nothing (better wording is totally welcome!).

This doesn't handle subscripts (or many other kinds of logical lvalue) at all yet, so 
it doesn't handle the swift WTF case, but this is progress towards that.



Swift SVN r20297
2014-07-22 05:37:42 +00:00
Mark Lacey
f6963302a4 Properly indent apply/partial_apply methods in TypeSubstCloner.
Swift SVN r20157
2014-07-18 16:51:59 +00:00
Michael Gottesman
a12880aa8c [dominance] Implement PostDominanceInfo::properlyDominates(SILInstruction *, SILInstruction *)
I am going to use this for dead store elimination in multi-bb load store optimization.

rdar://17680758

Swift SVN r20002
2014-07-16 04:26:00 +00:00
Joe Groff
2f157e393d SIL: Avoid reentering type lowering when lowering struct and enum types.
Structs and enums may recursively refer to themselves in function types and metatypes, which don't actually affect the layout of the type. We don't need to fully lower the storage types of a struct or enum to lower the type; all we need to know is its classification. We can lazily lower the fields, avoiding reentry. Fixes a few dozen radars.

Swift SVN r19968
2014-07-15 01:58:15 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Joe Groff
a14a94942d SILGen: Give dynamic thunks a proper mangling.
This lets us make them 'shared' and teach the demangler about them.

Swift SVN r19945
2014-07-14 21:01:45 +00:00
Michael Gottesman
0a15d018cc Rely on the stdlib's runtime assert and undefined behavior to promote 3/4 remaining unchecked_addr_cast types to object bit casts.
This commit enables support in the optimizer for promoting the following
unchecked_addr_cast kinds to object bit casts:

1. (Trivial => Trivial) yields a trivial bit cast.
2. (Non-Trivial => Trivial) yields a trivial bit cast.
3. (Non-Trivial => Non-Trivial) yields a ref bit cast.

We do not promote conversions in between trivial and non-trivial types
since a trivial bit cast must have a trivial output and if we allowed
for ref bit casts in between the two, we would be breaking the rule that
ref bit casts do not change the reference semantics of its input, output
types. Technically, we could lower trivial => trivial as a ref cast and
then simplify later but that is unnecessary currently.

<rdar://problem/17373087>

Swift SVN r19784
2014-07-10 05:24:00 +00:00
Joe Groff
c1228c774d ClangImporter: Track when structs have unreferenceable storage.
SIL SROA needs to know when a struct's visible fields actually completely make up the struct value, which becomes an issue if we start importing structs with yet-unrepresentable unions and bitfields. Track this in the ClangImporter, and add an 'aggregateHasUnreferenceableStorage' predicate to SILType to make it easy for passes to query. Part of <rdar://problem/17555966>.

Swift SVN r19720
2014-07-09 03:52:15 +00:00
Andrew Trick
3e7cea232b Fix SILType::getMetatypeInstanceType by lowering the type.
Fixes <rdar://problem/17579272> SILCombine assert: ty->isLegalSILType() constructing SILType with type that should have been eliminated by SIL lowering.

Fix suggested by MikeG.

Swift SVN r19701
2014-07-08 21:43:17 +00:00
Joe Groff
9f4c417095 SIL: Forward-declare witness tables with correct linkage.
Fixes <rdar://problem/16997968>.

Swift SVN r19680
2014-07-08 05:30:35 +00:00
Nadav Rotem
253b2e241a Change the doxygen style of comment from @ to \\
Swift SVN r19658
2014-07-08 00:50:30 +00:00
Nadav Rotem
f09df5764d Add a utility function for checking if a function has a specific semantics tag.
Swift SVN r19655
2014-07-08 00:38:15 +00:00
Arnold Schwaighofer
6466da193f Add a SILSSAUpdate utility
This is using LLVM's SSAUpdater utility.

I had to abstract it a little further because our 'phi' nodes are slightly
different. The SSAUpdater needs to iterate over phis in a basic block so I
abstracted this in a trait. Therefore, this commit needs a recent version of
puzzle/master which has this change applied.

Swift SVN r19634
2014-07-07 21:05:22 +00:00
Arnold Schwaighofer
2e83bdf01b Add a convenience function on SILBasicBlock to move it after another Block
Swift SVN r19633
2014-07-07 21:05:22 +00:00
Arnold Schwaighofer
4a5ba0ff87 DominanceInfo: Add a verification function
Swift SVN r19629
2014-07-07 21:05:20 +00:00
Joe Groff
af160e9c7b SIL: Lower dependent member types when substituted into context.
AST context substitution may produce a metatype, function type, or other type that requires lowering. Handle this special case to fix a crash when emitting protocol conformances with metatypes or functions as associated types. <rdar://problem/17501507>

Swift SVN r19580
2014-07-05 17:48:05 +00:00
Andrew Trick
53cbc3e858 Add a ColdBlockInfo analysis based on DominanceAnalysis.
This will be used by PerformanceInliner, GlobalOpt, and other passes in the future.

Swift SVN r19454
2014-07-02 06:35:09 +00:00
Mark Lacey
58c57b0b42 Use hasArchetype directly on SILType rather than going through Type.
Swift SVN r19452
2014-07-02 06:26:21 +00:00
Nadav Rotem
d2019d3e66 Add a an option to the inliner to ignore functions that are marked with the @semantics attribute so that we can perform high-level optimizations on them.
Swift SVN r19441
2014-07-01 23:45:26 +00:00
Manman Ren
ae9f2e25ae [@semantics] add SemanticsAttr to SILFunction.
Enable SIL parsing and SIL serialization of semantics.

We add one more field to SILFunctionLayout for semantics. We should refactor
handling of attributes at SIL level, right now they are in SILFunction as bool
or std::string and in SIL serializer as a 1-bit field or an ID field.

rdar://17525564


Swift SVN r19434
2014-07-01 22:49:46 +00:00
Mark Lacey
e348535c3c Small clean-up - use hasArchetype() directly in the optimizer.
In a few places we were calling into a function that just returned
T->hasArchetype(). This just changes those places to test it directly.

Swift SVN r19427
2014-07-01 20:02:21 +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
Michael Gottesman
f66bbd9417 Revert "Revert "Expand the amount of unchecked_addr_casts that we can handle.""
This reverts commit r19279 and adds in the necessary fixes.

Swift SVN r19295
2014-06-27 16:49:08 +00:00
Joe Groff
f722d3f6a6 Remove tons of now-dead code for dealing with the C*Pointer bridging types.
Swift SVN r19280
2014-06-27 00:11:36 +00:00
Michael Gottesman
cf896976a0 Revert "Expand the amount of unchecked_addr_casts that we can handle."
This reverts commit r19272 to unblock the submission. I am going to
cherry-pick this later.

Swift SVN r19279
2014-06-27 00:02:05 +00:00
Michael Gottesman
256f1e5515 Expand the amount of unchecked_addr_casts that we can handle.
This is tested by an assertion in IRGen. After Beta3, this code is going
to go away and be replaced by just always promoting the cast. Then the
IRGen assertion will be replaced by propagating undef. The assertion in
the stdlib will still fire in that case since the assertion is based on
the tops not the given value implying that we will not lose any
correctness.

Swift SVN r19272
2014-06-26 23:07:52 +00:00
Michael Gottesman
4f474696bc [cfg-printer] Add SILFunction::viewCFG() and move the implementation of view cfg into SILFunction. Have CFGPrinter call it.
Swift SVN r19183
2014-06-25 21:36:38 +00:00
Manman Ren
7667b829bb [noinline attribute] add noinline attribute.
Propagate it to SILFunction and use it in PerformanceInliner. We also serialize
and parse the attribute.

rdar://15882816


Swift SVN r19150
2014-06-24 23:07:45 +00:00
Adrian Prantl
b1bfbf8ceb Fix a refcounting bug in SILClonerWithScopes.
Swift SVN r19149
2014-06-24 23:06:59 +00:00
Michael Gottesman
ee818e7533 [load-store] Teach load store forwarding how to forward stores -> loads with an intervening unchecked_addr_cast of layout compatible types.
Swift SVN r19130
2014-06-24 07:21:05 +00:00
John McCall
20b1f2de3e Switch isa and as? processing over to use the new
indirect cast instructions when necessary.

Swift SVN r19079
2014-06-22 09:53:36 +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
cd6fc21900 Allow SILBasicBlocks to be constructed after a specific
block, and do so when splitting a block.

Swift SVN r19076
2014-06-22 05:01:06 +00:00
John McCall
7b4700dc5d Clone SILUndef correctly.
Noticed this only because of an error in some other code,
naturally.

Swift SVN r19075
2014-06-22 05:01:04 +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
John McCall
48d6a833a5 SILGen unconditional dynamic casts using the new
unconditional_dynamic_cast_addr instruction.

Also, fix some major semantic problems with the
existing specialization of unconditional dynamic
casts by handling optional types and being much
more conservative about deciding that a cast is
infeasible.

This commit regresses specialization slightly by
failing to turn indirect dynamic casts into scalar
ones when possible; we can fix that easily enough
in a follow-up.

Swift SVN r19044
2014-06-20 07:47:03 +00:00
John McCall
f35a181a68 Cache the most general possible abstraction pattern
the SILModule.

This is useful when coercion to the most general
abstraction is necessary (for example, to establish
consistency in dynamic casts).  Often there's an
unbounded archetype at hand, but not always.

Swift SVN r19042
2014-06-20 07:47:00 +00:00
John McCall
a669306ac9 Correctly mark the unconditional_cast_addr instructions
as reading and writing memory.

Swift SVN r19041
2014-06-20 07:47:00 +00:00