Commit Graph

47 Commits

Author SHA1 Message Date
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
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +00:00
Dmitri Hrybenko
5c9c675291 Revert "Remove type check workaround for invalid casts"
This reverts commit r22498.  We need more auditing of stdlib for invalid
casts.

rdar://18151953

Swift SVN r22536
2014-10-06 08:27:35 +00:00
Arnold Schwaighofer
a934abf2a8 Remove type check workaround for invalid casts
The stdlib has been fixed and no longer produces invalid casts.

rdar://18151953

Swift SVN r22498
2014-10-03 17:01:07 +00:00
Arnold Schwaighofer
ef3adb2186 Dont' trivial bitcast between differently sized structs.
Really we want to only cast between equally sized types. SIL does not really
have a concept of types of the same size so this solution is a workaround
(temporary) for acutal code in the standard library which casts a pointer of an
UTF16 type to a pointer of an UTF8 type.

rdar://18118602

Swift SVN r21470
2014-08-27 00:05:04 +00:00
Michael Gottesman
eeca7e5186 [load-store] We no longer perform single BB load-store opts so we should always have a post dominator tree. Remove NULL check.
Swift SVN r21272
2014-08-19 04:13:01 +00:00
Manman Ren
084ad2f21c [Load Store Opts] use BBArguments to merge in multiple stores.
We use a DenseMap to map an address to a list of reaching StoreInsts,
one for each predecessor. The map is passed as function arguments instead
of a member in LSBBForwarder since it is only used during one invocation
of optimizing a basic block.

We can now remove all loads in rdar://17613168 and enable dead object
elimination. There is one issue though, one of the loads is loop invariant
and is moved outside by LICM, but we need to run LoadStoreOpt and DeadObjectElim
afterwards to actually remove the dead object.

Performance for rdar://17613168 (with added passes after LICM):
-Ounchecked: 13.8s to 0.199s
-O: 15.4s to 2s


Swift SVN r20922
2014-08-01 22:04:59 +00:00
Manman Ren
c02607305e [Load Store Opts] more refactoring. NFC.
Swift SVN r20918
2014-08-01 21:37:47 +00:00
Manman Ren
f98a535eb5 [Load Store Opts] fix typo.
Swift SVN r20905
2014-08-01 18:24:18 +00:00
Manman Ren
0b7cd65a57 [Load Store Opts] separate the feasibility check. NFC.
To help adding BBArguments to merge in multiple stores, we separate
the feasibility check so we can check the feasibility before creating
BBArguments.


Swift SVN r20904
2014-08-01 18:23:06 +00:00
Manman Ren
cd31f6a361 [Load Store Opts] add comments and remove clear inside the loop.
There is no need to clear the state before merging in the states of
the predecessors. In the case of a self loop, we need the previous
state of the basic block, otherwise, the state will be initialized to
the state of the first predecessor.


Swift SVN r20766
2014-07-30 18:54:23 +00:00
Manman Ren
658b8f0c9a [Load Store Opts] remove AA and other members from LSBBForwarder. NFC.
Swift SVN r20721
2014-07-29 23:38:25 +00:00
Andrew Trick
cbad3697a3 TODO comment to remind me of what I wanted to change.
Swift SVN r20447
2014-07-23 23:43:32 +00:00
Michael Gottesman
9ceca6d313 Add in a small TODO. NFC.
Swift SVN r20351
2014-07-22 23:45:25 +00:00
Michael Gottesman
ec533fafa7 [load-store-opts] Enable global load store opts.
rdar://17680758



Swift SVN r20349
2014-07-22 23:43:44 +00:00
Manman Ren
3260a4182c [Global Load Store Opts] fix a issue when a BB is its own predecessor.
When BB is its own predecessor, we can't do the following
state[BB] = state[first pred of BB]
state[BB].merge(state[other predecessors])
--> here we are merging in the updated state[BB]

Instead we should do
state[BB].merge(state[predecessors other than BB])


Swift SVN r20114
2014-07-17 21:50:50 +00:00
Michael Gottesman
d47255dbcc Remove dead var that snuck in.
Swift SVN r20011
2014-07-16 06:10:40 +00:00
Michael Gottesman
e5d7111db8 [load-store-opts] Change load store opts single BB pass to be a simple forward dataflow with an intersection merge operation.
This is not run by default unless one passes in the flag -Xllvm -enable-global-load-store-opts.

Also in order to make sure in the face of multi-bbs dead store elimination is
still correct, we use the post order dominator tree to determine if the dead
store is post dominated by the store that is causing it to be dead.

With this pass enabled, we see a 3.5% decrease in overall time in the precommit
bench and the following tests increase in speed by > 5%:

2Sum:          8.9%
Rectangles:    7.35%
Ackermann:     6.43%
StringBuilder: 6.16%
EditDistance:  5.71%
StringWalk:    5.58%

That means that 30% of our benchmarks increased in speed by > 5%. Many of the
other benchmarks increased in speed significantly but not as drmatically.

The only benchmark that regressed is SmallPt which I am looking into.

rdar://17680758

Swift SVN r20009
2014-07-16 06:01:37 +00:00
Mark Lacey
f1a6921564 Fix an assert in store-to-load forwarding.
The code does the right thing, but the assert should be checking that
the load we're about to replace has the same type as the value we're
replacing it with.

This was exposed by changes to inline generic code.

Swift SVN r19921
2014-07-14 06:32:15 +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
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
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
3fc1042ca1 [load-store] Refactor load->load and store->load forwarding to use the same underlying method.
Both have the same form of, (Address, Value, Load). For the store->load I pass in
(SI->getDest(), SI->getSrc(), LI) and for the load->load I pass in
(OldLI->getOperand(), OldLI, LI).

This also for free lets our load deduplication support forwarding from casts.

Swift SVN r19133
2014-06-24 09:57:23 +00:00
Michael Gottesman
f6eefe63a3 [load-store] Teach load store opts how to forward stores -> partial loads which are related via typed GEPs.
I also refactored findExtractPathBetweenValues to be able to be used for both
partial load duplication and forwarding stores to partial loads.

Swift SVN r19132
2014-06-24 08:37:14 +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
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
Michael Gottesman
102cd40ea0 [load-store-opts] RetainValue is insert from a load store opts perspective despite it having side effects due to it touching reference counts.
Swift SVN r18912
2014-06-15 20:01:42 +00:00
Michael Gottesman
aa70a16d7e [load-store-opts] Track, perform load forwarding, and eliminate multiple stores.
rdar://16703656

Swift SVN r17746
2014-05-09 00:44:28 +00:00
Michael Gottesman
9fee32d515 [load-store-opts] Do not invalidate stores if AA says that an instruction does not alias the store's destination conservatively.
Swift SVN r17738
2014-05-09 00:00:21 +00:00
Michael Gottesman
02c42cd0a4 [load-store-opts] Refactor out special cases for strong_retain, cond-fail, and dealloc_stack into a helper function call isLSForwardingInertInstruction.
Swift SVN r17735
2014-05-08 23:34:22 +00:00
Michael Gottesman
f18dbbe9e8 [load-store-opts] Refactor load forwarding into its own method LSBBForwarder::tryToForwardLoad.
Now the main optimize method of load store forwarding is ~60 lines and
is significantly more readable.

Swift SVN r17718
2014-05-08 22:42:16 +00:00
Michael Gottesman
df441227f1 [load-store-opts] Refactor out dead store elimination into LSBBForwarder::tryToEliminateDeadStore.
Swift SVN r17717
2014-05-08 22:42:16 +00:00
Michael Gottesman
d4698e3beb [load-store-opts] Move invalidateAliasingLoads onto LSBBForwarder and remove unneeded arguments.
Swift SVN r17716
2014-05-08 22:42:16 +00:00
Michael Gottesman
f510d16666 [load-store-opts] Refactor out call to recursivelyDeleteTriviallyDeadInstructions -> LSBBForwarder::deleteInstruction.
Swift SVN r17715
2014-05-08 22:42:15 +00:00
Michael Gottesman
328dd3cf52 [load-store-opts] Refactor/Simplify LoadStoreOpts by including a BBState structure.
This makes the main method able to be broken down into simpler pieces
without the need to pass as many things around.

Swift SVN r17714
2014-05-08 22:42:14 +00:00
Michael Gottesman
bd62e9d9e7 [load-store-opts] Keeping performing load store optimizations on a basic block until we no longer eliminate anything.
Swift SVN r17670
2014-05-08 02:33:35 +00:00
Manman Ren
fb299a4899 [LoadStoreOpt] make sure Loads do not hold deleted SILInstructions.
We add a callback function to recursivelyDeleteTriviallyDeadInstructions.
When a Load instruction is deleted, we erase it from Loads.

rdar://16815627


Swift SVN r17558
2014-05-06 20:02:31 +00:00
Mark Lacey
1452d24671 Small cleanup: Remove unnecessary calls to getDef(), mostly in dyn_cast<>(...).
Swift SVN r16235
2014-04-11 23:05:16 +00:00
Nadav Rotem
cce0b2d342 Add comments that describe the purpose of the set.
Swift SVN r15394
2014-03-23 20:55:24 +00:00
Nadav Rotem
4d9598fad1 Remove store instructions that store a loaded value that is known to be unmodified.
After this change swap in RC4 contains only 2 stores (of the swapped values).



Swift SVN r15386
2014-03-23 08:03:58 +00:00
Nadav Rotem
79c552b003 Zero -> Nullptr. NFC.
Swift SVN r15384
2014-03-23 07:04:14 +00:00
Nadav Rotem
8e4ff9bf10 Any instruction that invalidates loads should also invalidate stores.
Swift SVN r15382
2014-03-23 06:54:16 +00:00
Nadav Rotem
20c8272388 Promote partial-loads after stores.
Swift SVN r14217
2014-02-21 18:41:58 +00:00
Nadav Rotem
0a5f7b57a7 Change the debug string to match the ail-opt flag.
Swift SVN r14216
2014-02-21 18:40:35 +00:00
Michael Gottesman
fbe2ccf0d6 [sil-aa] Add in convenience methods for querying AliasAnalysis::getMemoryBehavior.
The methods are:

 * mayWriteToMemory()
 * mayReadFromMemory()
 * mayReadOrWriteMemory()
 * mayHaveSideEffects() [Side effects + writing to memory]
 * mayHavePureSideEffects() [Only side effects, ignores writes to memory]

Swift SVN r13791
2014-02-12 00:14:29 +00:00
Michael Gottesman
8cff098f1e Split SILCodeMotion into two passes, LoadStoreOpts and SILCodeMotion.
LoadStoreOpts removes duplicate loads, forwards stores to loads, and eliminates
dead stores.

Swift SVN r13789
2014-02-11 23:36:51 +00:00