SILOptimizer: Replace [].append(contentsOf:) with [].append(element:)

if the argument is an array literal.

For example:
  arr += [1, 2, 3]

is replaced by:
  arr.append(1)
  arr.append(2)
  arr.append(3)

This gives considerable speedups up to 10x (for our micro-benchmarks which test this).

This is based on the work of @ben-ng, who implemented the first version of this optimization (thanks!).
This commit is contained in:
Erik Eckstein
2017-03-31 10:48:15 -07:00
parent dc426bd885
commit 777f5aaf7a
6 changed files with 377 additions and 92 deletions

View File

@@ -135,6 +135,12 @@ public:
/// Returns true on success, false otherwise.
bool replaceByValue(SILValue V);
/// Replace a call to append(contentsOf: ) with a series of
/// append(element: ) calls.
bool replaceByAppendingValues(SILModule &M, SILFunction *AppendFn,
const llvm::SmallVectorImpl<SILValue> &Vals,
ArrayRef<Substitution> Subs);
/// Hoist the call to the insert point.
void hoist(SILInstruction *InsertBefore, DominanceInfo *DT) {
hoistOrCopy(InsertBefore, DT, false);