Commit Graph

6634 Commits

Author SHA1 Message Date
Joe Groff
dba8a23d64 AST: Refactor get*UnsafePointerDecl() lookups onto the AST context.
These types are needed by enough of the stack now that it makes sense to centralize their lookup and caching onto the AST context like other core types.

Swift SVN r19029
2014-06-20 03:02:29 +00:00
Pete Cooper
f4a2e8294b Make PatternMatch behave the same for ApplyInst arguments, regardless of whether we are matching a SILValue or another subpattern. The problem here was that we'd access arguments in one path but operands in another. Test case to follow soon
Swift SVN r19000
2014-06-19 15:59:58 +00:00
John McCall
7effec113c Change ImplicitlyUnwrappedOptional to be an enum type itself,
not a struct wrapping an Optional.

Among other things, this means you can now pattern-match on
an IUO.  It also makes it more convenient to build and destroy
them.

SILGen's type lowering should probably canonicalize one kind
of optional to the other so that we don't get silly abstraction
costs from conversion.

Swift SVN r18991
2014-06-18 23:27:08 +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
Michael Gottesman
735a23a0a3 [sil-combine] Rewrite unchecked_addr_cast to access layout compatible first element fields via typed GEPS.
A first element field of a nominal type is either the first element of a
struct or the first payload of an enum. We currently allow the stdlib to
rappel into struct heirarchies using reinterpretCast. This patch teaches
the optimizer how to rewrite such unchecked_addr_cast into
unchecked_enum_data_addr and struct_element_addr instructions. Then
Mem2Reg and Load Store Forwarding will remove the allocation generated
by such uses of reinterpret cast.

<rdar://problem/16703656>

Swift SVN r18977
2014-06-18 09:34:05 +00:00
Mark Lacey
0850bcc4d7 Make TypeSubstCloner take a substitution list directly.
Rather than calling getSubstitutions() in various places on the apply
that we are cloning the body of, pass the substitution list in
directly when creating the cloner.

This is not interesting for the generic specializer, but is important in
mandatory inlining when we go to inline an apply of a partial apply,
where we need to use the full list of substitutions for both.

Swift SVN r18951
2014-06-17 08:28:56 +00:00
John McCall
7c3f911ba3 Incremental work to try to hide the type of an AbstractionPattern.
Swift SVN r18936
2014-06-16 20:28:12 +00:00
John McCall
f0e14f7e65 Carry the formal types of the arguments in the indirect-cast
instructions.

Swift SVN r18934
2014-06-16 17:35:43 +00:00
Adrian Prantl
17e3604b43 Make sure all non-inlining uses of SILCloner also clone the SILDebugScope
hierarchy. I still need to figure out a reliable way to write testcases
for this. For now it's ensured via an assertion in SILCloner::postprocess.

Swift SVN r18917
2014-06-15 20:50:49 +00:00
Doug Gregor
5bb6969af3 Type checker support for dictionary downcasting.
This is the semantic-analysis portion of <rdar://problem/16847470>.


Swift SVN r18900
2014-06-14 18:27:38 +00:00
Michael Gottesman
85a349554c RetainValue, ReleaseValue, and AutoreleaseValue are all reference count
instructions. Make them subclasses of RefCountingInst.

This is a useful superclass that enables one to quickly perform queries
on whether or not a specific instruction is an instruction that
manipulates reference counts.

Swift SVN r18891
2014-06-14 05:42:31 +00:00
Michael Gottesman
90d1b06ef6 [sil-combine] Simplify (apply (partial_apply f)) -> (apply f) when the
partial apply is a partial apply of a generic function with a
non-generic substitution list.

rdar://17303157

Swift SVN r18885
2014-06-14 01:16:55 +00:00
Pete Cooper
73bda9a8ed Clean up pattern match m_zero and m_One to avoid duplication. Thanks Jordan for the feedback
Swift SVN r18870
2014-06-13 17:11:47 +00:00
Nadav Rotem
2a7b156427 Handle CheckedCastKind::Identical in a few places that I missed.
Swift SVN r18868
2014-06-13 16:35:21 +00:00
Nadav Rotem
1b650dcdf6 Add helper functions to SILBlock and SILFunction.
Swift SVN r18858
2014-06-13 06:10:07 +00:00
Pete Cooper
9c00e8a55a Simplify add/sub/mul overflow intrinsics where one operand is a 0 or 1
Swift SVN r18857
2014-06-13 06:06:53 +00:00
Mark Lacey
904d73b71e Remove unused parameters to TypeSubstCloner ctor.
These are used by a helper in the generic specializer, but not
need for the cloner class itself.

Swift SVN r18848
2014-06-12 23:50:19 +00:00
Mark Lacey
70fdc6d9ed Make SpecializingCloner inherit from TypeSubstCloner.
This is mostly cleanup in TypeSubstCloner to make it possible to use
in the CRTP.

Swift SVN r18847
2014-06-12 23:50:19 +00:00
Bob Wilson
2df66cf8c4 Implement inline scopes for the performance inliner.
Mandatory-inlined (aka transparent functions) are still treated as if they
had the location and scope of the call site. <rdar://problem/14845844>
Support inline scopes once we have an optimizing SIL-based inliner

Patch by Adrian Prantl.

Swift SVN r18835
2014-06-12 19:48:43 +00:00
Joe Groff
afafa9d24e SILGen: Implement metatype-to-object conversions.
Use the new SIL instructions to lower metatype-to-object conversions.

Swift SVN r18827
2014-06-12 18:21:45 +00:00
John McCall
9f5736880e Basic IR-generation support for checked_cast_addr
in terms of swift_dynamicCast.

Swift SVN r18825
2014-06-12 08:08:20 +00:00
Joe Groff
1f1c00cf9e SIL: Add instructions to convert metatypes to object references.
Add objc_metatype_to_object and objc_existential_metatype_to_object to convert metatypes to AnyObject, and objc_protocol to get a reference to an @objc protocol descriptor as a Protocol class instance.

Swift SVN r18824
2014-06-12 05:34:03 +00:00
Mark Lacey
87e94268a6 Move TypeSubstCloner into its own file.
This will allow it to be used both by the generic specializer as well as
the inliner.

Swift SVN r18812
2014-06-11 23:23:01 +00:00
John McCall
f5749cc037 Track the consumption behavior of the new indirect-cast
instructions.

Swift SVN r18785
2014-06-10 22:27:56 +00:00
John McCall
0f0874bb4b Add variants of the checked-cast instructions that
put the result in a different place.

WIP: no IRGen support yet.

This will eventually be the required form when casting
to an address-only type; the existing instructions will
have only scalar outputs.

Swift SVN r18780
2014-06-10 07:43:22 +00:00
John McCall
c266b15293 Cache whether a type involves an archetype in the recursive
type properties.

Swift SVN r18773
2014-06-10 01:41:00 +00:00
Arnold Schwaighofer
a14aa42ce1 SILLoopInfo: Implement SIL loop info analysis using LLVM's LoopInfo
Swift SVN r18718
2014-06-05 22:25:42 +00:00
Arnold Schwaighofer
c882046288 Add more GraphTraits for SILBasicBlocks
Swift SVN r18717
2014-06-05 22:25:42 +00:00
Mark Lacey
19fd2ce0d2 Clean-up hashing in CSE by using the stored kind of the inst.
Swift SVN r18703
2014-06-04 18:21:59 +00:00
Michael Gottesman
3ba4ca1b31 Add support for printing SIL with SIL entities sorted by name behind the flag -sil-sort-by-output-names.
This significantly reduces the diff size when diffing the standard
library.

Swift SVN r18700
2014-06-04 05:22:52 +00:00
Manman Ren
b3e72be9d9 Remove unused deserialized SILFunctions.
The deserializer holds a reference to the deserialized SILFunction, which
prevents Dead Function Elimination from erasing them. 

We have a tradeoff on how often we should clean up the unused deserialized
SILFunctions. If we clean up at every optimization iteration, we may
end up deserializing the same SILFunction multiple times. For now, we clean
up only after we are done with the optimization iteration.

rdar://17046033


Swift SVN r18697
2014-06-04 00:30:34 +00:00
Mark Lacey
8156008cd8 Add a dead code elimination optimization pass.
In a loop like this:
  var j = 2
  for var i = 0; i < 100; ++i {
    j += 3
  }
it will completely eliminate j.

It does not yet support rewriting conditional branches as unconditional
branches in the cases where only empty blocks are control dependent on
an edge. Once this support is added, it will also completely eliminate
the loop itself.

Swift SVN r18615
2014-05-24 07:02:18 +00:00
Joe Groff
0141da1107 SILGen: Attach an OwnershipComponent to weak/unowned member references.
Partially fixes <rdar://problem/16989616>, but exposes an IRGen crash (which is likely <rdar://problem/16979789>) behind it.

Swift SVN r18585
2014-05-23 04:20:25 +00:00
Michael Gottesman
9755d8cbf9 [sil-combine] partial_apply without a substitution list or arguments is equivalent to a thin-to-thick function.
rdar://16860213

Swift SVN r18458
2014-05-20 19:15:26 +00:00
Michael Gottesman
54ac7cb7bb [devirtualizer] Fix issues where the position of Self in arguments/substitutions were confused.
I added some helpers to ApplyInst that should hopefully linguistically eliminate
the issue by allowing users of the API to not need to remember that the self
substitution is first, but the self argument is last.

We should really just remove the dichotomy. But that is for after WWDC.

I also disabled devirtualization of inherited protocol conformances for
protocol_methods. This will be less likely to be used than specialized
protocol conformances protocol_method devirtualization (which is
currently).

<rdar://problem/16951124>

Swift SVN r18282
2014-05-17 23:15:55 +00:00
Joe Groff
e8f71c12a2 Rename ObjCMutablePointer to AutoreleasingUnsafePointer.
This relates its interface and behavior to that of UnsafePointer, and draws an analogy to '__autoreleasing *' in ARC.

Swift SVN r18236
2014-05-17 04:44:44 +00:00
Michael Gottesman
fc91eb68fa [sil-aa] Remove type classifier methods from SILType.
Swift SVN r18165
2014-05-16 03:04:17 +00:00
Michael Gottesman
9f5d430e93 [sil-aa] Add predicates to SILType that will be used in TBAA so that TBAA does not need to touch the AST.
We should never touch the AST from SIL if we don't need to. The specific
added methods are:

1. SILType::isBuiltinNativeObjectType().
2. SILType::isBuiltinRawPointerType().
3. SILType::isBuiltinType().
4. SILType::isBuiltinIntegerType().
5. SILType::isBuiltinFloatType().
6. SILType::isGenericType(). This supersedes the hasUnboundGenerics
function in Local.h. After WWDC, we should remove that method but I
don't want to update random parts of the SILPasses.
7. SILType::aggregateContainsRecord. Enables easy queries to determine
if a SILType T1 contains a separate SILType T2 as a member.

rdar://16651852

Swift SVN r18147
2014-05-16 00:21:41 +00:00
Joe Groff
793fe06a34 SILGen: Emit an artificial toplevel for files with @UIApplicationMain classes.
If a source file contains the main class for its module, then implicitly emit a top_level_code that invokes UIApplicationMain with the name of the marked class.

Swift SVN r18088
2014-05-15 00:53:38 +00:00
Doug Gregor
5159201aed Bridge T[] to NSArray when T is bridged to Objective-C.
Generalize the bridging of AnyObject[] to NSArray into bridging T[] to
NSArray, following what we already have for dictionaries. Use some new
Foundation-level entry points for the bridging, which could use an
audit from someone who understands Array better than I do.

Part of <rdar://problem/16535097>.


Swift SVN r17869
2014-05-11 06:12:34 +00:00
Doug Gregor
104cf17d5d SILGen: Bridge Dictionary<K, V> <-> NSDictionary in Objective-C thunks.
Implements the majority of Dictionary bridging in SILGen
<rdar://problem/16870626>.

Swift SVN r17838
2014-05-10 19:51:00 +00:00
Joe Groff
d6957d0328 Make existential-to-concrete metatype casts work.
This mostly falls out from the metatype cast infrastructure, but we need to generalize some Sema and SILGen code to accept AnyMetatypeType. Concrete-to-existential metatypes will need more runtime checking that isn't implemented, so raise a 'not implemented' error on those for now.

Swift SVN r17798
2014-05-09 20:57:55 +00:00
Michael Gottesman
fd0a78b301 [sil-combine] Canonicalize index_raw_addr byte indexing operations => index_addr object size indexing operations.
This should eliminate pointless operations that get added to our inline
cost itinerary.

rdar://15567647
rdar://16762768
rdar://16832529

Swift SVN r17644
2014-05-07 22:01:30 +00:00
Michael Gottesman
b56c31dc5f [sil-combine] convert_function simplification.
convert_function works essentially as a bitcast on functions that
enables you to change address/ref type parameters. This commit enforces
that invariant in the verifier and teaches SILCombine how to simplify it
so we can use it in the devirtualizer.

Swift SVN r17516
2014-05-06 01:16:14 +00:00
Michael Gottesman
a7bb61265c [deserialization] Tighten up deserialization of witness tables.
We now enforce via an assert that each witness table is unique and that
every protocol conformance that is referenceable from SIL must have a
witness table matched to it.

Also, I taught the linker that it should deserialize witness tables for
InitExistentialRefInst instructions, something that was missed before.

Swift SVN r17283
2014-05-02 22:28:13 +00:00
Michael Gottesman
0f8733867b [deserialization] Change the return value of findFuncInWitnessTable to match the
ordering of SILWitnessTable, ArrayRef<Substitution> in lookUpWitnessTable.

Swift SVN r17266
2014-05-02 19:15:41 +00:00
Manman Ren
c2f32d7e24 [Inliner] revert r17101 since it causes a performance regression on MD5.
See rdar://16676020 for details.
r17101 tries to solve r16761933 by checking non-direct recursions in
the call graph. We are in discussion of solving it in a different way.

Todo: figure out why r17101 causes a preformance regression.


Swift SVN r17265
2014-05-02 19:00:36 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Michael Gottesman
5dbfb3ab7f [devirtualization] Return the witness table when looking up SILFunctions from a witness table.
This is important since it enables one to analyze the type of the
conformance that the witness table implements which may be different
than the original type. This follows the precedent where we return the
Substitutions from the protocol conformance tree traversal.

Swift SVN r17220
2014-05-02 01:43:31 +00:00