mirror of
https://github.com/apple/swift.git
synced 2026-02-27 18:26:24 +01:00
These two new invariants eliminate corner cases which caused bugs if optimization didn't handle them. Also, it will significantly simplify lifetime completion. The implementation basically consists of these changes: * add a flag in SILFunction which tells optimization if they need to take care of infinite loops * add a utility to break infinite loops * let all optimizations remove unreachable blocks and break infinite loops if necessary * add verification to check the new SIL invariants The new `breakIfniniteLoops` utility breaks infinite loops in the control flow by inserting an "artificial" loop exit to a new dead-end block with an `unreachable`. It inserts a `cond_br` with a `builtin "infinite_loop_true_condition"`: ``` bb0: br bb1 bb1: br bb1 // back-end branch ``` -> ``` bb0: br bb1 bb1: %1 = builtin "infinite_loop_true_condition"() // always true, but the compiler doesn't know cond_br %1, bb2, bb3 bb2: // new back-end block br bb1 bb3: // new dead-end block unreachable ```