Commit Graph

140 Commits

Author SHA1 Message Date
Chris Lattner
bb6df84e1e now that we have a more disciplined approach to copyaddr explosions,
we don't need logic to compute conditional access paths.  Simplify the code.


Swift SVN r10538
2013-11-18 15:34:23 +00:00
Chris Lattner
feee9f6332 pull release processing into the main DI flow, no functionality change.
Swift SVN r10537
2013-11-18 15:28:48 +00:00
Chris Lattner
ec0e1e6feb Rewrite most of DI to work on the entire memory object at once,
instead of working a tuple-element at a time.  This requires it
to use bitvectors to compute each tuple element's liveness separately.

A big part of this is introducing the new MemoryUse type, which wraps
up the tuple elements accessed by a user of the memory object in addition
to its kind, and extending the NonLoadUses set to keep an index into the
Uses map, and a lot of other things.

This wraps up:
<rdar://problem/15228619> Eliminate the notion of Element from DefiniteInitialization



Swift SVN r10520
2013-11-17 05:14:52 +00:00
Chris Lattner
2775de4dc4 releases apply to the entire memory object, not to tuple elements within it,
stop tracking them on a per-element basis.  They also don't make sense for
global variables, so verify they don't occur there.


Swift SVN r10501
2013-11-15 22:23:06 +00:00
Chris Lattner
a3ea22349a split processing of "release" instructions out to a separate list,
since they are handled in a completely different way from other uses
and already had to be std::partitioned to the end anyway.  They will
only become more different over time.


Swift SVN r10500
2013-11-15 21:55:38 +00:00
Chris Lattner
4962fc6c9b merge more and harder.
Swift SVN r10499
2013-11-15 21:19:42 +00:00
Chris Lattner
19355152d0 merge the alloc_stack and alloc_box processing logic. NFC.
Swift SVN r10498
2013-11-15 21:12:30 +00:00
Chris Lattner
27ff69ebb3 Bitpack LiveOutBlockState to fit into a single byte. Add some
tests for empty structs (which already pass).  No functionality
change.


Swift SVN r10497
2013-11-15 20:59:00 +00:00
John McCall
2ed33e4ffa Make convenient accessors for getting a lowered SILType for
a struct/class field or a tuple element.

Make DefiniteInitialization traffic in SILTypes more.

Swift SVN r10055
2013-11-08 22:04:04 +00:00
Chris Lattner
153447496f fix rdar://15379013 - Definite initialization inappropriately changes existential initialization to assignment
We were incorrectly treating init_existential as equivalent to a struct
access, where for DI purposes, it is much more like an enum access: a store
to the result of a (not further indexed) init_existential pointer should be
treated as a full store, not a partial store.



Swift SVN r9933
2013-11-04 22:38:26 +00:00
Chris Lattner
a0c5afa7ff re-commit r9816, allowing DI to delete allocations *in* transparent
functions.  Before it would only delete them once they got inlined,
which is a waste of compile time and serves no purpose.

This exposed a bug in mandatory inlining, which is now fixed.  It
strinks the stdlib by 4500 lines, almost 10%.



Swift SVN r9906
2013-11-03 18:07:39 +00:00
Chris Lattner
a2a1b2af55 Clean up tuple and extract SILBuilder stuff:
- Introduce emitTupleExtract / emitStructExtract, which fold when their operand is a tuple/struct.
- Rename SILBuilder::createTupleExtractInst -> createTupleExtract, "Inst" isn't used as a suffix.
- Switch capture promotion and DI to use the new functions.

This trims 300 lines out of the stdlib.


Swift SVN r9897
2013-11-03 04:47:40 +00:00
Dmitri Hrybenko
c2425d5afd Revert r9816. It causes three tests to enter an inf loop:
Interpreter/archetype_casts.swift
Interpreter/classes.swift
Interpreter/generic_casts.swift


Swift SVN r9829
2013-10-31 00:01:56 +00:00
Chris Lattner
a667e61fc3 Make the "delete store only stack allocations" logic delete all allocations
in transparent functions.  They will be deleted anyway when they get inlined
into callers, so there is no reason to do the work to carry them around and
inline them, only to delete them.

This shrinks the sil for the stdlib by about 5%: from 71672 lines to 67718 lines.



Swift SVN r9818
2013-10-30 22:07:44 +00:00
Chris Lattner
2d0bc50c74 teach definite initialization to handle dealloc_addr instructions, instead of treating
them as an escape point.


Swift SVN r9725
2013-10-28 20:38:31 +00:00
Chris Lattner
1aac046e71 reimplement alloc_stack/box deletion in DI instead of being
part of allocbox_to_stack.  This is simpler and more efficent
given the info DI already has, and this enables future progress.


Swift SVN r9707
2013-10-28 16:26:04 +00:00
Chris Lattner
cbeb113a4f Fix DI to remove assign instructions from its Uses list when it
lowers them (causing the pointer to dangle).   This doesn't 
currently manifest as a problem, but will with some changes that 
are coming.


Swift SVN r9706
2013-10-28 15:44:04 +00:00
Chris Lattner
c118613de3 Fix SILValue use_iterators to type the user as a SILInstruction, not just a ValueBase.
There are no values other than instructions that can use other values.  BBArguments are
defs, not uses.  This eliminates a bunch of casts in clients that use getUser().


Swift SVN r9701
2013-10-27 23:32:14 +00:00
Chris Lattner
5f190a8e0b implement cross-block load promotion in definite initialization. This allows
us to diagnose things that span multiple blocks, e.g.:

  var xu8_3 : UInt8 = 240   // Global (cross block) analysis.
  for i in 0..10 {}
  xu8_3 += 40 // expected-error {{arithmetic operation '240 + 40' (on type 'UInt8') results in an overflow}}

This doesn't do full SSA construction in that it won't generate "phi" nodes, but will promote any loads that can be substituted with a (potentially field sensitive and decomposed) single value.  Given that no diagnostics passes are going to be looking through BB args anyway, this seems like the right level of sophistication for definite init.



Swift SVN r9523
2013-10-20 08:11:53 +00:00
Chris Lattner
be353ab347 simplify some code by getting rid of some bool results,
and computing their result at the top level.  No functionality
change.


Swift SVN r9517
2013-10-19 03:34:03 +00:00
Chris Lattner
823dab7fa8 code cleanups: remove a pointless cl::opt and inline some now really similar functions.
Swift SVN r9347
2013-10-15 06:43:38 +00:00
Chris Lattner
528ab405f8 Teach definite-init to forward stored values to copy_addrs,
exploding them on demand.  This finally resolves rdar://15170149,
which allows a bunch of tests in SILPasses/constant_propagation.swift
to work.



Swift SVN r9346
2013-10-15 06:28:47 +00:00
Chris Lattner
46e3b7b656 Several changes:
- Enhance the driver of definite initialization to scalarize copyaddrs
  that span multiple tuple elements so that DI can only thing of a single
  element at a time (when it comes to copy_addrs - inout and escapes can 
  span anything of course)
- Teach load eliminate to explode copyaddrs into its components when
  doing so would allow eliminating a load.
- Fix a bug where indexing into a tuple inside an enum could cause
  accesses to be attributed to the wrong element, which manifested
  as a crash on the testsuite now that DI is being more aggressive.

Unfortunately, DI is now exploding some copyaddrs that feed inout shadows,
disabling the inout shadow optimization on something important for 
stdlib/String.swift.  This is a regression, but is less important than
unblocking work dependent on rdar://15170149, so I'm just dialing back
the testcase and tracking this with rdar://15228172.


Swift SVN r9345
2013-10-15 04:15:32 +00:00
Chris Lattner
74645a2472 Step #2 of the load promotion rewrite: change how assigns are handled.
Previously, the definite init pass would check to see if there was a
load available to optimize out the load of a non-trivial assign.  Now
we just unconditionally lower an assign to a load/copy/store sequence,
and lead later load elimination zap the load if it is redundant.

This allows us to remove the old mechanics for doing reasoning about
load elimination, including all the "AccessPath" stuff.


Swift SVN r9340
2013-10-15 00:26:22 +00:00
Chris Lattner
5708f5d28c Take a big step towards rewriting how definite init promotes loads
into SSA form, moving to resolving rdar://15170149.

Instead of promoting loads in the middle of the process of proving
that everything passes DI requirements, do this after a full element
is ok.

Doing this requires changing just about everything about how we modeled
elements and subelements being promoted, but this is good for a lot of
reasons:
1) we now don't eagerly scalarize all loads to struct members, now we
   just scalarize top-level tuples.  This is good for preserving higher
   level operations.
2) Even without scalarization, we can still model things at an extremely 
   fine grain, but we can also keep aggregate operations together.
   This means that load promotion doesn't insert a kajillion 
   struct_extract + struct sequences to decompose then recompose things.

This is just patch #1 of a series, but this is the bulk of the hard work.



Swift SVN r9338
2013-10-15 00:03:57 +00:00
Chris Lattner
a0d7510bc1 improve a comment, improve support for copyaddrs to and from the same aggregate.
Swift SVN r9246
2013-10-12 00:27:35 +00:00
Mark Lacey
94d2c06e21 Replace MemPromotion with Definitie Init in debug output.
Also replace memory-promotion with definite-init for DEBUG_TYPE and fix
a typo.

Swift SVN r9191
2013-10-11 03:24:37 +00:00
Chris Lattner
0c78c40775 Teach copy_addr explosion to scalarize any generated loads so that we
can forward larger stores to them.


Swift SVN r9168
2013-10-10 20:46:05 +00:00
Chris Lattner
e19ce563a5 Keep track of stores produced by exploded copy_addrs in the NonLoadUses
set.  This is the last fix required to get copy_addr to forward to the
load in this trivial example from rdar://15170149:

func testTrivial(a : @inout Int) -> Int {
  return a
}

on to more testing.



Swift SVN r9167
2013-10-10 20:20:53 +00:00
Chris Lattner
a3836f430d Fix -enable-copyaddr-forwarding to properly extract out the result of a large
aggregate store to forward to a smaller load, e.g. to feed a copyaddr of an 
Int to a load of the Builtin.Int64 inside of it.



Swift SVN r9166
2013-10-10 20:14:42 +00:00
Chris Lattner
1284eacd3d The Uses vector can grow now, ElementPromotion::doIt shouldn't iterate over
it with a for-each loop.



Swift SVN r9165
2013-10-10 20:00:12 +00:00
Joe Groff
29066ca358 SIL: Make consistent use of element-type-deriving createStruct/TupleExtract helpers in DefiniteInitialization.
Swift SVN r9139
2013-10-10 15:34:20 +00:00
Joe Groff
5650130518 SIL: Substitute struct field types when creating struct ops in passes.
The AST type of the VarDecl is incorrect for bound generic structs and needs to be substituted.

Swift SVN r9130
2013-10-10 04:35:57 +00:00
Chris Lattner
75b4fcd5ac Progress towards having memory promotion explode copy_addrs when necessary to
feed loads.  The new behavior is currently only enabled by the 
-enable-copyaddr-forwarding flag and is known broken, I'm working on it!


Swift SVN r9121
2013-10-10 00:56:28 +00:00
John McCall
b880e60100 Remove SILFunctionTypeInfo in favor of SILFunctionType.
We still don't actually use this as a type, however.

Swift SVN r9091
2013-10-09 20:55:55 +00:00
Chris Lattner
bbaa07125d refactor the checkLoadAccessPathAndComputeValue to be a method
on ElementPromotion, preparing it for future changes.  No functionality
change.


Swift SVN r9070
2013-10-09 18:17:55 +00:00
Chris Lattner
d6b01a42ad add a new (skeleton) pass for deshadowing inout variables.
Swift SVN r8954
2013-10-07 15:53:40 +00:00
Stephen Lin
3f5c0dbf0e Update SILArgument::getModule(), SILBasicBlock::getModule() and SILInstruction::getModule() signatures to match SILFunction::getModule(), for consistency; standardize usage of SILFunction::getParent() to SILFunction::getModule().
Swift SVN r8932
2013-10-04 21:12:20 +00:00
Chris Lattner
767da738bb Change the command line option to sil-opt for the definite initialization
pass to be -definite-init instead of -memory-promotion, rename the
entrypoint for the pass to match, and tidy various and sundry comments.


Swift SVN r8927
2013-10-04 18:45:09 +00:00
Chris Lattner
6b6887b2e0 rename MemoryPromotion.cpp -> DefiniteInitialization.cpp.
Promotion isn't really its purpose, it just happens to do that sometimes.



Swift SVN r8925
2013-10-04 18:39:34 +00:00