Commit Graph

6634 Commits

Author SHA1 Message Date
Joe Groff
259dad38f2 PredictableMemOpt: Don't try to diagnose recursive value types.
They're invalid, and we don't want to blow the stack trying to decompose a type with infinite elements. Fixes rdar://problem/17920535.

Swift SVN r23775
2014-12-08 01:58:19 +00:00
Dave Abrahams
ee145a1ac6 s/implicitely/implicitly/g
Correct a pervasive spelling error

Swift SVN r23774
2014-12-07 22:03:36 +00:00
Michael Gottesman
cb8760148d Reapply "Revert "[func-sig-opts] If we know all callsites of a function, delete the old unoptimized function instead of creating a thunk.""
This reverts commit r23725. This time with fixes so we don't hit that
assertion.

Swift SVN r23762
2014-12-06 23:08:17 +00:00
Chris Willmore
36d0f187ec Sema, SILGen, ClangImporter: Add special support for Set<T>
Add the following functionality to the Swift compiler:

* covariant subtyping of Set
* upcasting, downcasting of Set
* automatic bridging between Set and NSSet, including
    * NSSet params/return values in ObjC are imported as Set<NSObject>
    * Set params/return values in Swift are visible to ObjC as NSSet

<rdar://problem/18853078> Implement Set<T> up and downcasting

Swift SVN r23751
2014-12-06 02:52:33 +00:00
Manman Ren
16cc4dfa65 Revert r23713
Swift SVN r23739
2014-12-05 18:41:27 +00:00
Mark Lacey
bd33410e16 Fix MemoryBehavior on SIL instructions that have a CastConsumptionKind.
Having the wrong memory behavior here can cause SIL Code Motion to move
retains and releases across these instructions, which is invalid.

This resulted in a retain-after-free issue in the DollarChain benchmark
after I committed r23673 (which was soon after backed out in r23679).

Swift SVN r23722
2014-12-05 04:43:37 +00:00
Mark Lacey
f80f9325b0 Fix 80-column violation.
Swift SVN r23721
2014-12-05 04:43:36 +00:00
Manman Ren
d0068877f5 [PGO] Add SILMetadata for branch weights.
SILMetadata is the base class with a single enum member (MDKind).
SILBranchNode is the derived class with additional members:
  unsigned NumOperands
  an array of uint32_t

A static member function SILBranchNode::get is implemented to get or create
SILBranchNode. All SILMetadata created are uniqued and saved in SILModule's
member variable:
  llvm::FoldingSet<SILMetadata> Metadatas

Usage of SILMetadta by SILInstruction is captured in SILModule's member variable:
  llvm::DenseMap<const SILInstruction *, SILMetadata *> MetadataStore
This is similar to LLVM's Metadata. Another option is to add a SILMetadata* to
SILInstruction. The disadvantage is the waste of space when we don't have PGO on.

This commit also enables parsing and printing of SILMetadata.

We add keyword sil_metadata to define SILMetadata:
  sil_metadata !0 = {"branch_weights", 3, 5}

For parsing, we add a map in SILModule
  llvm::DenseMap<unsigned, SILMetadata *> NumberedMetadata
that maps from ID to SILMetadata* to help matching usage of "!id" in SILFunction
with definition of "!id" in sil_metadata section.

For printing, we assign IDs to SILMetadata at SILModule scope, we then pass in
an optional argument of
  llvm::DenseMap<const SILMetadata *, unsigned> *MetadataMap
to SILFunction::print in order to get the ID of SILMetadata used in
SILInstruction.

Post-commit review will be appreciated.

rdar://18269754


Swift SVN r23713
2014-12-05 01:47:11 +00:00
John McCall
dd07c8ca10 Add 'mark_dependence', which indicates that an address
or pointer depends on another for validity in a
non-obvious way.

Also, document some basic value-propagation rules
based roughly on the optimization rules for ARC.

Swift SVN r23695
2014-12-04 22:38:09 +00:00
Michael Gottesman
85e2502f96 Pass in SILOptions to SILModule.
This should have been done a long time ago since SILOptions are options that
should be able to effect everything SIL related. In this case I just want to
pass in a flag on the SILModule to enable +0 self. By putting it on the
SILModule I can conveniently check it in SILFunctionType without exposing any
internal state from SILFunctionType.cpp.

Swift SVN r23647
2014-12-03 07:43:52 +00:00
Mark Lacey
8becf62650 Allow uninitialized void types in SILMem2Reg.
I ran into this while working on rdar://problem/18709125.

Fixes rdar://problem/19118507.

Swift SVN r23620
2014-12-02 23:01:05 +00:00
Michael Gottesman
652b5aeeea Add a verifier check to make sure that functions that have a function signature that should have a self parameter coming out of SILGen actually do so.
This was discovered while I was refactoring SILGen convention code.

Swift SVN r23611
2014-12-02 05:29:54 +00:00
Michael Gottesman
6d61aad42e [proj] Add a new data structure called a "Projection Tree".
A "Projection Tree" takes in a type and constructs a tree where each non-leaf
node represents an aggregate that can be split up and all leaf nodes represent a
subtype of the original type that we can not split.

It additionally provides the capability to propagate usage information
and liveness information through the tree, making it trivial to perform
SROA + partial dead use elimination. I am using this in function
signature opts for that purpose.

Swift SVN r23586
2014-11-28 20:38:55 +00:00
Michael Gottesman
a1373cd1b6 Add a helper overload of SILBasicBlock::insertBBArgs that takes an
integer index as a position instead of a bbarg_iterator.

Swift SVN r23585
2014-11-28 20:38:54 +00:00
Erik Eckstein
88c674161c refactoring: Add operator for comparing OperandValueArrayRefs.
And use it in SimplifyCFG. NFC



Swift SVN r23581
2014-11-25 09:43:35 +00:00
Joe Groff
f8dfcaa84e SIL: Consider the original Clang type of a decl before bridging Bool back to ObjCBool.
It's not always correct to map a Swift Bool back to ObjCBool in C land, since Bool could have originally been a proper _Bool. Pass the clang::Decl down to type lowering so we can recognize this. We still don't have a great solution for block types, because there's no decl to refer to, and Swift's user-level type system erases the distinction between void(^)(_Bool) and void(^)(BOOL). However, this is enough to let us start using C APIs that traffic in _Bool.

Swift SVN r23546
2014-11-22 05:21:55 +00:00
Michael Gottesman
1afc987739 Refactor the SILArgument API on SILBasicBlock so we can insert bb arguments anywhere in the argument list. Also clean up the API names so that they all match.
Swift SVN r23543
2014-11-22 00:24:40 +00:00
Roman Levenstein
ab7b1c26ca Move stripClassCasts into SILValue. NFC.
Swift SVN r23539
2014-11-21 22:21:52 +00:00
Arnold Schwaighofer
c322b3592d Add a data dependence between opened existential values and method_inst that 'use' them.
Before this patch there was no dependence visible to the optimizer between a
open_existential and the witness_method allowing the optimizer to reorder the
two instruction. The dependence was implicit in the opened archetype but this
is not a concept model by the SIL optimizer.

  %2 = open_existential %0 : $*FooProto to $*@opened("...") FooProto
  %3 = witness_method $@opened("...") FooProto,
                      #FooProto.bar!1 : $@cc(...)
  %4 = apply %3<...>(%2)

This patch changes the SIL representation such that witness_methods on opened
archetypes take the open_existential (or the producer of the opened existential)
as an operand preventing the optimizer from reordering them.

  %2 = open_existential %0 : $*FooProto to $*@opened("...") FooProto
  %3 = witness_method $@opened("...") FooProto,
                      #FooProto.bar!1,
                      %2 : $*@opened("...") FooProto : $@cc(...)
  %4 = apply %3<...>(%2)

rdar://18984526

Swift SVN r23438
2014-11-19 17:22:22 +00:00
Michael Gottesman
2d703a28f5 [proj] Add Projection::create{Addr,Value}Projection so one can create Projections without knowing what the internal state of the projection is.
Swift SVN r23371
2014-11-17 17:52:16 +00:00
Michael Gottesman
eeab468c8e [proj] Prepare Projection so that I can add generic create{Addr,Value}Projection.
I want to cleanup some code paths in SILCombine and LoadStoreOpts to use
generic create{Addr,Value}Projection methods which create the
appropriate projection instruction for a Projection method. Also this
will allow me to start to hide more of the internal state of Projection.

Swift SVN r23366
2014-11-17 06:43:37 +00:00
Michael Gottesman
06724fce02 [projection] Add comment to explain what projection path is.
Swift SVN r23357
2014-11-16 04:19:34 +00:00
Michael Gottesman
a4a633351f [projection] Make projection constructors private and create static failable initializers using Optional.
This changes the Projection API so that you pass in an instruction and get back
an optional depending on what theinstruction was. This is much cleaner than
always needing to do a switch.

This commit also cleans up the naming in Projection so that we always use the
term "value projection" for struct_extract, tuple_extract, and
unchecked_enum_data instead of the term "extract". This lines up better with the
name we use for the *_addr instructions, "address projection" and avoids
ambiguity since unchecked_enum_data does not have the word "extract" in it.

Additionally by adding in the failable initializers, my centralization of the
initialization logic enables me to ensure that isAddrProjection and
isValueProjection stay in sync with the various constructors via asserts. This
should prevent future bugs if we add additional notions of "projection".

Swift SVN r23356
2014-11-16 04:09:16 +00:00
Michael Gottesman
7285835422 [projection] Rename isAddressProjection => isAddrProjection and add isValueProjection.
This is apart of some cleanups of the Projection class.

I also improved the comment at the top of projection to make its usage
clearer.

Swift SVN r23355
2014-11-16 04:09:15 +00:00
Michael Gottesman
fae31cbaa2 [dead-object-elim] Add SILInstruction::mayTrap(), change SILInstruction::mayHaveSideEffects() to call it, and change dead object elimination to call mayHaveSideEffects().
Note that I did not change any actual memory behavior. That will come via a
later cleanup phase. Since this is a correctness fix I wanted to only make
things more conservative.

rdar://18568601

Swift SVN r23311
2014-11-14 00:05:15 +00:00
Arnold Schwaighofer
2120382bf9 OpenExistentialInst reads the memory pointed to by its operand
rdar://18964796

Swift SVN r23305
2014-11-13 18:05:20 +00:00
Erik Eckstein
581a5d02f5 Some bug fixes in the SwitchValueInst and SelectValueInst implementations.
Currently these instructions are not generated, so the bugs didn't cause any problems.



Swift SVN r23301
2014-11-13 09:06:50 +00:00
Roman Levenstein
3910c25da1 Minor re-factoring: Move the logic to decide if a given instruction can be (easily) duplicated into SILInstruction. So far it was mainly used by jump-threading related optimizations. But it could be generally useful, or at least generally important, to optimizations that want to duplicate code.
Swift SVN r23213
2014-11-10 23:15:07 +00:00
Erik Eckstein
da9f08aec8 Replace the default-entry with a corresponding case-entry in select_enum[ _addr], if possible.
This is exactly the same thing as I did for switch_enum.



Swift SVN r23116
2014-11-05 12:48:11 +00:00
Manman Ren
276af26e12 [Global Opt] adds GlobalGetter as one kind of SILDeclRef.
Also handles mangling, demangling, printing and parsing.

This is the first patch to use global getter for "let" globals.

rdar://16614767


Swift SVN r23106
2014-11-05 00:40:32 +00:00
Michael Gottesman
3ae10834d6 [ls-opts] Teach LoadStoreOpts how to forward smaller previous loaded items to the uses of larger later loads that partially alias the load.
This will help the ARC optimizer given future function sig optimization work and
is in general good since this has been a hole in our load store forwarding for a
while.

rdar://18831605

Swift SVN r23102
2014-11-04 19:44:06 +00:00
Michael Gottesman
01a00347ca [aa] Add ProjectionPath::computeSubSeqRelation() and use it to teach AA how to check for partial aliasing.
rdar://18831605

Swift SVN r23076
2014-11-03 03:38:01 +00:00
Michael Gottesman
4ad4b2db46 Remove newly dead swift::findAddressProjectionPathBetweenValues.
Swift SVN r23064
2014-11-02 02:53:37 +00:00
Michael Gottesman
5f70b01e4d [load-store-opts] Refactor load store opts to use the new ProjectionPath infrastructure.
rdar://18831605

Swift SVN r23063
2014-11-02 02:53:36 +00:00
Michael Gottesman
bb48674cf3 [aa] Move address projection path AA to use projection path infrastructure.
rdar://18831605

Swift SVN r23061
2014-11-02 00:41:13 +00:00
Michael Gottesman
596f406f31 [aa] Refactor all projection path logic into a class called ProjectionPath.
rdar://18831605

Swift SVN r23060
2014-11-02 00:41:13 +00:00
Roman Levenstein
03a5d72a35 Get rid of virtual functions. Use CRTP instead.
Swift SVN r23057
2014-11-01 06:34:30 +00:00
Roman Levenstein
c8d180e660 Generalize the switch_int instruction into switch_value instruction, which may switch on arguments of builtin integer types or function types. The later is required for implementing a more efficient speculative devirtualizaiton implementation. Implement lowering of switch_value into LLVM code. In case of integer operands, it reuses LLVM's switch optimizations. Support for switching on function types is not yet bullet-proof and will be refined in the subsequent patches.
rdar://18508812

Swift SVN r23042
2014-10-31 22:55:56 +00:00
Roman Levenstein
f016754ef9 Add a new select_value instruction. This instruction should be the equivalent of select_enum, just for builtin int types. Such an instruction is needed e.g. to efficiently implement conversions of Int raw values to C-like enums.
rdar://18812325

Swift SVN r23036
2014-10-31 20:44:11 +00:00
Erik Eckstein
743d6af4a4 Fix typo
Swift SVN r23004
2014-10-29 16:51:38 +00:00
Erik Eckstein
4df8f66b9a Replace the default-entry with a corresponding case-entry in switch_enum[_addr], if possible.
<rdar://problem/18709388> SimplifyCFG: Canonicalize default cases of covered switches to not use a default case




Swift SVN r23003
2014-10-29 14:56:34 +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
f40f3a93a0 New implementation of dead function elimination, which includes dead method elimination.
If vtable or witness methods are never called, e.g. because they are completely devirtualized,
then they are removed from the tables and eliminated.

Another improvement of the new algorithm is that it is able to eliminate dead function cycles
(e.g. A() calls B() and vice versa).



Swift SVN r22969
2014-10-27 16:41:02 +00:00
Michael Gottesman
ea88457258 Add SILArgument::hasConvention() to easily check if a SILArgument's parameter info has the given convention.
Swift SVN r22960
2014-10-27 09:15:56 +00:00
Michael Gottesman
a0a66e3883 Reapply "[func-sig-opts] Add SILFunction::findReturnBB to easily find the unique basic block containing a ReturnInst in a SILFunction."
This reverts commit r22933. Now with fixes so this actually compiles!

Swift SVN r22935
2014-10-25 00:14:39 +00:00
Jordan Rose
ef30948e4e Revert "[func-sig-opts] Add SILFunction::findReturnBB to easily find the unique basic block containing a ReturnInst in a SILFunction."
This reverts r22923, which doesn't actually compile. The fix is probably
obvious (s/F/this/) but I didn't want to mess with it in case it's wrong.

Swift SVN r22933
2014-10-24 23:33:19 +00:00
Michael Gottesman
c42bdcf418 [func-sig-opts] Add SILFunction::findReturnBB to easily find the unique basic block containing a ReturnInst in a SILFunction.
Swift SVN r22923
2014-10-24 22:21:48 +00:00
Erik Eckstein
60cb1a619a Support for eliminated witness methods in SILWitnessTable.
A method entry in SILWitnessTable can now be null.
This will be needed by dead method elimination.



Swift SVN r22914
2014-10-24 16:26:12 +00:00
Erik Eckstein
3eea8e3052 Set SILLinkage of witness tables according to the protocol visibility.
This is the same change as already done for functions and globals
(for details see <rdar://problem/18201785>).




Swift SVN r22907
2014-10-24 09:02:05 +00:00
Michael Gottesman
af10399976 [rc-id] Teach RCId how to strip off StructInst, TupleInst, and TupleExtractInst.
Specifically:

1. Given a struct literal with only one stored non-trivial field, a ref count
operation on the struct is equivalent to a ref count operation on the field.

2. Given a tuple literal with only one non-trivial elt , a ref count
operation on the tuple is equivalent to a ref count operation on the elt.

3. Given a tuple_extract, if the tuple_extract is extracting the only
non-trivial element of the tuple, a ref count on the tuple_extract is equivalent
to a ref count on the original type.

rdar://18499023

Swift SVN r22902
2014-10-23 23:38:26 +00:00