Skip to content

Commit ec9844b

Browse files
committed
[SIL Optimization] Add a new mandatory pass for unrolling forEach
calls over arrays created from array literals. This enables optimizing further the output of the OSLogOptimization pass, and results in highly-compact and optimized IR for calls to the new os log API. <rdar://58928427>
1 parent d2604a0 commit ec9844b

File tree

12 files changed

+1175
-0
lines changed

12 files changed

+1175
-0
lines changed

include/swift/AST/SemanticAttrs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ SEMANTICS_ATTR(ARRAY_COUNT, "array.count")
6060
SEMANTICS_ATTR(ARRAY_DEALLOC_UNINITIALIZED, "array.dealloc_uninitialized")
6161
SEMANTICS_ATTR(ARRAY_UNINITIALIZED_INTRINSIC, "array.uninitialized_intrinsic")
6262

63+
SEMANTICS_ATTR(SEQUENCE_FOR_EACH, "sequence.forEach")
64+
6365
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_NEVER, "optimize.sil.specialize.generic.never")
6466
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_PARTIAL_NEVER,
6567
"optimize.sil.specialize.generic.partial.never")

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ PASS(NonInlinableFunctionSkippingChecker, "check-non-inlinable-function-skipping
319319
PASS(YieldOnceCheck, "yield-once-check",
320320
"Check correct usage of yields in yield-once coroutines")
321321
PASS(OSLogOptimization, "os-log-optimization", "Optimize os log calls")
322+
PASS(ForEachLoopUnroll, "for-each-loop-unroll",
323+
"Unroll forEach loops over array literals")
322324
PASS(MandatoryCombine, "mandatory-combine",
323325
"Perform mandatory peephole combines")
324326
PASS(BugReducerTester, "bug-reducer-tester",

include/swift/SILOptimizer/Utils/InstOptUtils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ class InstructionDeleter {
145145
SILInstruction *inst,
146146
llvm::function_ref<void(SILInstruction *)> callback =
147147
[](SILInstruction *) {});
148+
149+
/// Recursively visit users of \c inst (including \c inst)and force delete
150+
/// them. Also, destroy the consumed operands of the deleted instructions
151+
/// whenever necessary. Invoke the \c callback on instructions that are
152+
/// deleted.
153+
void recursivelyForceDeleteUsersAndFixLifetimes(
154+
SILInstruction *inst,
155+
llvm::function_ref<void(SILInstruction *)> callback =
156+
[](SILInstruction *) {});
148157
};
149158

150159
/// If \c inst is dead, delete it and recursively eliminate all code that

lib/SILOptimizer/LoopTransforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ silopt_register_sources(
55
LoopRotate.cpp
66
LoopUnroll.cpp
77
LICM.cpp
8+
ForEachLoopUnroll.cpp
89
)

0 commit comments

Comments
 (0)