Skip to content

Commit 5ef19cf

Browse files
committed
libswift: add back legacy pass to fix Windows test
1 parent e90fc5f commit 5ef19cf

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ PASS(ArrayCountPropagation, "array-count-propagation",
131131
"Array Count Propagation")
132132
PASS(ArrayElementPropagation, "array-element-propagation",
133133
"Array Element Propagation")
134-
SWIFT_FUNCTION_PASS(AssumeSingleThreaded, "sil-assume-single-threaded",
134+
SWIFT_FUNCTION_PASS_WITH_LEGACY(AssumeSingleThreaded, "sil-assume-single-threaded",
135135
"Assume Single-Threaded Environment")
136136
PASS(BasicInstructionPropertyDumper, "basic-instruction-property-dump",
137137
"Print SIL Instruction MemBehavior and ReleaseBehavior Information")
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//===--- AssumeSingleThreaded.cpp - Assume single-threaded execution -----===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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-thread.
14+
//
15+
// Convert all reference counting operations into non-atomic ones.
16+
//
17+
// To get read 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+
#include "swift/SIL/SILFunction.h"
29+
#include "swift/SIL/SILInstruction.h"
30+
#include "swift/SIL/SILModule.h"
31+
#include "swift/SILOptimizer/PassManager/Passes.h"
32+
#include "swift/SILOptimizer/PassManager/Transforms.h"
33+
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
34+
#include "llvm/Support/CommandLine.h"
35+
36+
using namespace swift;
37+
38+
namespace {
39+
class AssumeSingleThreaded : public swift::SILFunctionTransform {
40+
/// The entry point to the transformation.
41+
void run() override {
42+
if (!getOptions().AssumeSingleThreaded)
43+
return;
44+
for (auto &BB : *getFunction()) {
45+
for (auto &I : BB) {
46+
if (auto RCInst = dyn_cast<RefCountingInst>(&I))
47+
RCInst->setNonAtomic();
48+
}
49+
}
50+
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);
51+
}
52+
};
53+
} // end anonymous namespace
54+
55+
SILTransform *swift::createLegacyAssumeSingleThreaded() {
56+
return new AssumeSingleThreaded();
57+
}

lib/SILOptimizer/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ target_sources(swiftSILOptimizer PRIVATE
77
AllocBoxToStack.cpp
88
ArrayCountPropagation.cpp
99
ArrayElementValuePropagation.cpp
10+
AssumeSingleThreaded.cpp
1011
COWOpts.cpp
1112
CSE.cpp
1213
ConditionForwarding.cpp

0 commit comments

Comments
 (0)