This patch does the following:
- Moves the logic for handling special-case of converting to/from AnyObject.Protocol (and existential.Protocol in general) into DynamicCasts, where all other cases are handled already.
- Moves the peephole which was folding checked_cast_br into an unchecked cast and branch from sil-combine into sil-simplify-cfg, because it is a better place for it, since this peephole affects the CFG. The corresponding test is also moved from sil_combine.sil into simplify_cfg.sil.
- Adds a few checked_cast_br peepholes to sil-combine. They try to simplify checked_cond_br instructions using existential metatypes by propagating a concrete type whenever it can be determined statically.
- Adds a new test with a lot of test-cases that make sure we are really folding many type-checks at compile-time now.
Swift SVN r25504
This is just good to do and hopefully will help prevent people from forgetting
to check in the future by annotating the API explicitly as returning a
potentially nullptr.
Swift SVN r25364
Replace cond branches to a trampoline BB without BBargs, by direct cond branches to the destination BB of the trampoline. Apply this transformation only if it does not introduce new critical edges as this may destroy the canonical form of the CFG which is required/assumed by some other optimizations (e.g. LoopRotate, ABCOpts, etc).
rdar://16450429
Swift SVN r24236
I refactored, generalized, and cleaned up an existing helper.
I also removed hard-coded assumptions about successor indices.
There's no point giving CondBranch a true/false API if we don't respect it.
Swift SVN r24001
It avoids generation of llvm phi nodes with identical predecessors and differing values.
This change replaces my previous fix of this problem in r23580, where I handled it in IRGen.
There were some discussions about it with the conclusion that it's better to just disallow such cond_br instructions in SIL.
It makes the life easier for some SIL optimizations which can't deal with cond_br with identical destinations.
The original radar is <rdar://problem/18568272> Swift compiler fails with "PHI node has multiple entries for the same basic block with different incoming values!"
Swift SVN r23861
DFSStack.push_back will invalidate the referenced memory if it relocates the
vector. Just increment the iterator earlier.
rdar://19070782
Swift SVN r23570
The implementation is inside a dedicated class now. Huge methods are split into smaller ones that are much easier for reviewing and understanding.
The whole thing could be moved out of SimplifyCFG into a dedicated file eventually. But currently it is not done as it still has too many dependencies on the internals of SimplifyCFG.
And, BTW, this dominator-based implementation of checked_cast_br jump-threading gives a 5x boost on the relevant PolymorphicCalls benchmark.
Swift SVN r23536
it is very beneficial for code that:
- references the same object multiple times (e.g. x.f1() + x.f2())
- and for method invocation chaining (e.g. x.f3().f4().f5())
rdar://18914224
Swift SVN r23515
Currently this is only done for integer input values and enum output values.
The purpose is to simplify enum initializations from integer raw values.
Together with an llvm patch, which I'm currently commiting, the Enum.init(rawValue: Int) will be compiled
to a range-check + int-cast.
Swift SVN r23320
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
SimplifyCFG is not maintaining the dom/postdom tree. This code assumes it is and
so is using an potentially invalid domtree.
This caused SIL verifier errors compiling the perf test suite on my machine:
"SIL verification failed: instruction isn't dominated by its operand: Dominance->properlyDominates(valueI, I)
Verifying instruction:
...
-> %639 = select_enum %634 : $Optional<Int -> ()>, default %731 : $Builtin.Word
In function @_TF11DriverUtils14findTestsToRunFT_T_ basic block:"
This reverts commit r22843.
Swift SVN r22850
terminators"
This is an assumption that the SSAUpdater makes. Verify that we preserve this
property.
With changes to the test cases, SIL documentation and add a critical edge (non
cond_br only) splitting pass to the mandatory pipeline.
This reapplies commit 22775.
Swift SVN r22803
This reverts commit r22775 as it breaks SILPasses/simplify_cfg_args.sil
and SILPasses/split_critical_edges.sil for me with:
Assertion failed: (!isCriticalEdgePred(BB.getTerminator(), Idx) && "non
cond_br critical edges not allowed"), function verify, file
/Users/dave/src/s/swift/lib/SIL/Verifier.cpp, line 2380.
Swift SVN r22780
Reinstantiate rr22712. Now that updating SSA form is more robust we should not
run into troubles anymore.
Original commit message:
"Use the inliner's heuristic to decide which instructions are 'free' (constants,
etc).
We were not jumpthreading a block because it had four instruction in it - two of
them integer_literals."
rdar://18594600
Swift SVN r22761
This way we are guaranteed to be able to build SSA form: there is guarantueed
to be a terminator branch that supports adding basic block arguments at every
join points. We were relying on the assumption that we will never have other
terminators at join points when we want to insert phi nodes. This turns out to
be a very fragile assumption in the presence of aggressive CFG simplification.
Swift SVN r22759