mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user