Commit Graph

1693 Commits

Author SHA1 Message Date
Joe Groff
be45322668 SIL: Drop the upcast_existential* instructions.
Swift SVN r22388
2014-09-30 16:11:54 +00:00
Joe Groff
c098645f34 SIL: Conformances relate to formal types, so change witness_method's lookup type to a CanType.
Should be NFC in practice, since only nominal types can currently conform to protocols anyway, but improves modeling of the system.

Swift SVN r22360
2014-09-29 20:44:00 +00:00
Joe Groff
152aa9e244 Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22345.

Swift SVN r22353
2014-09-29 13:46:41 +00:00
Joe Groff
1e343fb430 SIL: Drop the upcast_existential* instructions.
Swift SVN r22345
2014-09-28 19:24:33 +00:00
Joe Groff
0518f2067f Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22333.

Swift SVN r22337
2014-09-28 18:41:05 +00:00
Joe Groff
727c9b5ed7 SIL: Drop the upcast_existential* instructions.
Swift SVN r22333
2014-09-28 16:38:13 +00:00
Joe Groff
a3126706da SIL: Eliminate the dead 'alloc_array' insn.
Swift SVN r22292
2014-09-26 02:28:10 +00:00
Adrian Prantl
afd1901ee9 add a comment
Swift SVN r22267
2014-09-24 16:51:37 +00:00
Michael Gottesman
ab92c2e096 Fix = typo in assert. Should be ==.
Swift SVN r22113
2014-09-19 02:16:42 +00:00
Manman Ren
18042db194 [Global Opt] update SILGlobalOpt to use static initializer if possible.
This is off by default and is a modified version of r21996 (reverted in r22001).

Update SILGlobalOpt to remove "once" call from addressor and set the
InitializerF for SILGlboalVariable if legal.

For calls to addressor in non-cold block, we check the addressor to find out
the globalinit_func and the associated SILGlobalVariable. If legal, we set
InitializerF of SILGlobalVariable and remove "once" call from addressor.

The current rules for legality:
1> the addressor contains a single "once" call and it calls globalinit_func.
2> the globalinit_func is called by "once" from a single location.
   When we inline the addressor, the globalinit_func will be called by "once"
   from multiple locations. After we remove the "once" from the addressor, the
   inlined version will mistakely initialize the global variable again.
3> the globalinit_func is trivial as defined by
   SILGlobalVariable::canBeStaticInitializer().

Update IRGen to generate constant initializers for global variables with static
initializers (i.e non-null InitializerF).

Joe's suggestion on having the static initializer to return the result instead
of storing it is not implemented in this commit. But we do verify that a static
initializer has a single store to the global variable. The suggestion is tracked
in rdar://18382039.

Implement rdar://16621368, rdar://18169093.


Swift SVN r22083
2014-09-18 17:40:24 +00:00
Manman Ren
9f279fb168 [Global Opt] Refactor lowering of LiteralInst in IRGen. NFC.
Follow-on patches will use these functions as well.


Swift SVN r22081
2014-09-18 17:27:09 +00:00
Joe Groff
1c4e08a9c8 Fix up a tangle of issues related to reabstraction.
- A spot fix in SILGen for reabstracting the result of a downcast, which fixes checked casts to function types.
- Associate the layout information in type metadata records with the most abstract representation of the type. This is the correct thing to do in cases where we need the metadata as a tag for an opaque value--if we store a value in an Any, or pass it as an unconstrained generic parameter, we must maximally reabstract it. This fixes the value semantics of existentials containing trivial metatypes.
- To ensure that we get runtime layout of structs and enums correct when they contain reabstractable types, introduce a "metadata for layout" concept, which doesn't need to describe the canonical metadata for the type, but only needs to describe a type with equivalent layout and value semantics. This is a correctness fix that allows us to correctly lay out generic types containing dependent tuples and functions, and although we don't really take advantage of it here, it's also a potential runtime performance win down the road, because we could potentially produce direct metadata for a primitive type that's layout-equivalent with a runtime-instantiated type. To aid in type safety here, push SILType deeper into IRGen in places where we potentially care about specific representations of types.
- Finally, fix an inconsistency between the runtime and IRGen's concept of what spare bits unmanaged references and thick metatypes have.

Together, these fixes address rdar://problem/16406907, rdar://problem/17822208, rdar://problem/18189508, and likely many other related issues, and also fixes crash suite cases 012 and 024.

Swift SVN r21963
2014-09-16 01:44:34 +00:00
Joe Groff
e004ad7df4 SIL: Carry AST types through init_existential instructions.
This is necessary to be able to properly stash values with nontrivial lowerings, such as metatypes and functions, inside existential containers. Modify SILGen to lower values to the proper abstraction level before storing them in an existential container. Part of the fix for rdar://problem/18189508, though runtime problems still remain when trying to actually dynamicCast out a metatype from an Any container.

Swift SVN r21830
2014-09-10 05:56:36 +00:00
Michael Gottesman
9f3e7c5595 [irgen] Handle lowering of fix_lifetime of addresses correctly.
Swift SVN r21722
2014-09-04 22:58:36 +00:00
Michael Gottesman
9514ba5a7d [irgen] Lower fix_lifetime => swift_keepAlive().
I introduced a function swift_keepAlive2() which has a different signature from
swift_keepAlive() until I can verify that the stdlib is using the new
infrastructure.

The difference in signature is that swift_keepAlive2 takes just a pointer while
swift_keepAlive also takes a metadata value that is not necessary for our
purposes anymore.

Swift SVN r21718
2014-09-04 21:53:18 +00:00
Doug Gregor
c504086266 Revert r21707 "Remove the SIL is_nonnull instruction. It's no longer useful."
We want to be able to work around problems with non-failable
Objective-C initializers actually failing, which can happen when the
API audit data incorrectly marks an initializer as non-failable.



Swift SVN r21711
2014-09-04 17:26:34 +00:00
Doug Gregor
cdf94885ae Remove the SIL is_nonnull instruction. It's no longer useful.
Swift SVN r21707
2014-09-04 15:56:12 +00:00
Adrian Prantl
9a02e797ed Debug info: emit -O0 shadow copies for let-declared values, even if they
are explosions.

rdar://problem/17375963

Swift SVN r21650
2014-09-02 20:02:21 +00:00
Chris Lattner
0275a37935 enhance the SIL is_nonnull instruction to work with values of function type. This
isn't used yet.


Swift SVN r21636
2014-09-02 01:06:07 +00:00
Joe Groff
ea26f65b62 SIL/IRGen: Implement Builtin.bridgeFromRawPointer for arbitrary bridgeable object types.
Any single-refcounted-pointer type can be cast from a raw pointer. Also generalize unchecked_ref_cast to cast among arbitrary single-refcounted-pointer types. Fixes rdar://problem/18184883.

Swift SVN r21609
2014-08-30 17:07:18 +00:00
John McCall
0ddc7ee5b6 Resilience expansion is not an IR-generation concept.
If a type has to be passed or returned resiliently, it
will necessarily be passed indirectly, which is already
represented in SILFunctionType.  There is no need to
represent this as a separate channel of information.

NFC. Also fixes a problem where the signature cache
for ExtraData::Block was writing past the end of an
array (but into the storage for an adjacent array
which was fortunately never used).

ExtraData should also disappear as a concept, but we're
still relying on that for existential protocol witnesses.

Swift SVN r21548
2014-08-28 23:07:50 +00:00
Adrian Prantl
2665ad5f03 Simplify the debug scope handling in IRGenSIL to ignore instructions
that don't have a scope.

This gets rid of undesirable gaps in the line table.

<rdar://problem/17916256> XCode 6 beta 5 creating unwanted duplicate breakpoints

Swift SVN r21498
2014-08-28 00:05:48 +00:00
Joe Groff
6cb2bf96b8 IRGen: Implement the dealloc_box instruction.
Failable initializers will need to clean up an uninitialized 'self' box in the case where a class initializer calls out to a 'super.init' or 'self.init' fails. Because some framework classes assume that they have a refcount of exactly one during initialization, we have to take 'self' from the box during the delegation, and reinitialize the box with the result of the delegation on success. This means we actually have to implement lowering for dealloc_box.

Swift SVN r21493
2014-08-27 22:44:53 +00:00
Joe Groff
4c65da9772 Make Builtin.bridgeToRawPointer work with class existentials.
It should definitely work with AnyObject, but it can also apply to any class existential by just shedding the witness tables. This lets us eliminate a bunch of unsafeBitCasts from the alimentary canals of the stdlib.

Swift SVN r21472
2014-08-27 00:58:42 +00:00
Adrian Prantl
8cfc6089e3 Debug info: Gracefully handle anonymous variables.
Found via <rdar://problem/17999350>

Swift SVN r21464
2014-08-26 21:38:31 +00:00
John McCall
dc6f63cebe When Clang says to coerce an argument to a struct type,
it means that the argument should be passed as that
expanded sequence of types.

It turns out that LLVM makes an effort to automatically
break apart such arguments during CC lowering, but (1) it's
friendlier to break them apart ourselves and (2) it's
necessary to break them apart if we want to call inline
functions from the header.

Fixes rdar://17631440

Swift SVN r21420
2014-08-22 20:53:21 +00:00
Adrian Prantl
9ab436ad05 Expect stricter scoping requirements from inlining and clonening passes.
Swift SVN r20863
2014-08-01 00:18:52 +00:00
Nadav Rotem
2ac6177a91 IRGen: Fix another bug in the lowering of checked_cast_br.
Swift SVN r20795
2014-07-31 01:07:20 +00:00
Adrian Prantl
e4c9c400d3 Do not emit debug info for declless/anonymous variables. It is impossible to
determine a mangled type name  if the type is generic, and the debugger
can't really do anything with an anonymous variable anyway.

Swift SVN r20785
2014-07-30 23:01:03 +00:00
Nadav Rotem
a16f01cf21 IRGEN: re-apply r20748 (fix to CheckedCastBranchInst lowering) with support for non address types!
Swift SVN r20769
2014-07-30 20:32:09 +00:00
Doug Gregor
a9ac767295 Revert "Fix the lowering of CheckedCastBranchInst. We need to cast the argument to the correct pointer type."
This reverts commit r20748. It's causing failure on the buildbots.

Swift SVN r20763
2014-07-30 18:05:29 +00:00
Nadav Rotem
875738aa3a Fix the lowering of CheckedCastBranchInst. We need to cast the argument to the correct pointer type.
Testcase in the next commit.



Swift SVN r20748
2014-07-30 09:49:05 +00:00
Erik Eckstein
a124e3239d Generate a runtime fail for bitcasts with different sizes instead of a failed assert.
Fixes <rdar://problem/17821040>


Swift SVN r20747
2014-07-30 09:23:32 +00:00
John McCall
6165da998c Rename some of the emitTypeMetadataFor... routines to make
it clear that they're requesting a dynamic type.

Some conceptual functional change; practical functionality
change should be limited.

Swift SVN r20733
2014-07-30 04:40:51 +00:00
Adrian Prantl
10d2e7e2c5 Debug info: Emit a more efficient representation for -O0 shadow copies for
explosions by copying them into a single, aggregate alloca.
This also happens to hide <rdar://problem/17815972> for llvm-600.

Swift SVN r20582
2014-07-26 00:18:16 +00:00
Adrian Prantl
cf91513c55 Debug info: Emit shadow copies for by-value parameters at -O0 to ensure
that they are visibly for the entirety of the function.

rdar://problem/17538433.

Swift SVN r20505
2014-07-24 18:34:21 +00:00
Jordan Rose
b6818046a8 Eliminate optimization levels 0-3 in favor of -Onone/-O/-Ofast.
We were already effectively doing this everywhere /except/ when building
the standard library (which used -O2), so just use the model we want going
forward.

Swift SVN r20455
2014-07-24 01:12:59 +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
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
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Dmitri Hrybenko
6f814ded6b Remove the '-disable-all-runtime-checks' option that predates current SIL-level
optimization/inlining scheme.

It was actually used while building a release version of stdlib, and
effectively disabled safety checks in debug builds.


Swift SVN r19461
2014-07-02 14:47:29 +00:00
Adrian Prantl
3ae5326d21 Tweak the scope guessing for instructions without SILDebugScopes to reuse
the scope of the previous instruction.

<rdar://problem/17021591> Gap in lexical block coincides with the first line-table entry for a line => no variables at that line

Swift SVN r19318
2014-06-28 02:08:26 +00:00
Joe Groff
fc13ea5ed0 SIL/IRGen: Allow unowned/unmanaged storage to be optional at the SIL level.
Allow @sil_unowned and @sil_unmanaged types to be optional. The sema for 'unowned' is a bit of a mess, and I'm not sure how to fix that right away. This is necessary in order for the unmanaged writeback for an AutoreleasingUnsafePointer<NSError?> or similar to compile correctly.

Swift SVN r19148
2014-06-24 22:38:00 +00:00
Joe Groff
f43d120421 IRGen: Test bitcast codegen, and fix a bug.
Swift SVN r19059
2014-06-21 00:23:48 +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
Adrian Prantl
adc520715c [DebugInfo] Remove unnecessary indirection from byref types.
<rdar://problem/17203231> Swift variable has wrong indirect location in the Swift debug info

Swift SVN r19013
2014-06-19 21:36:57 +00:00
Adrian Prantl
b1a7a7af1b Reference-count inlined functions to keep them alive until we emit debug
info for them and generally clean up the inline scope handling a bit.
Fix the debug scope handling for all clients of SILCloner, especially
the SIL-level spezializers and inliners.
This also adds a ton of additional assertions that will ensure that
future optimization passes won't mess with the debug info in a way that
could confuse the LLVM backend.

Swift SVN r18984
2014-06-18 22:34:10 +00:00
Doug Gregor
39e1b0886d Start using ConditionalCheckedCastExpr and ForcedCheckedCastExpr for collection downcasts.
NFC; just a cleanup.


Swift SVN r18979
2014-06-18 13:00:57 +00:00