|
| 1 | +//===--- AssumeSingleThreaded.swift - Assume single-threaded execution ----===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// |
| 13 | +// Assume that user code is single-threaded. |
| 14 | +// |
| 15 | +// Convert all reference counting operations into non-atomic ones. |
| 16 | +// |
| 17 | +// To get rid of most atomic reference counting operations, the standard |
| 18 | +// library should be compiled in this mode as well . |
| 19 | +// |
| 20 | +// This pass affects only reference counting operations resulting from SIL |
| 21 | +// instructions. It wouldn't affect places in the runtime C++ code which |
| 22 | +// hard-code calls to retain/release. We could take advantage of the Instruments |
| 23 | +// instrumentation stubs to redirect calls from the runtime if it was |
| 24 | +// significant, or else just build a single-threaded variant of the runtime. |
| 25 | +// |
| 26 | +//===----------------------------------------------------------------------===// |
| 27 | + |
| 28 | +import SIL |
| 29 | + |
| 30 | +let assumeSingleThreadedPass = FunctionPass( |
| 31 | + name: "sil-assume-single-threaded", { function, context in |
| 32 | + for block in function.blocks { |
| 33 | + for inst in block.instructions { |
| 34 | + guard let rcInst = inst as? RefCountingInst else { continue } |
| 35 | + |
| 36 | + context.setAtomicity(of: rcInst, isAtomic: false) |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | +) |
0 commit comments