Skip to content

Commit 8ac0d1f

Browse files
authored
Merge pull request #71514 from gottesmm/pr-85e5179e39a39e9323682e5a512e5b167e887a82
[region-analysis] Add a pass that explicitly invalidates RegionAnalysis.
2 parents 6dccf3d + e29e035 commit 8ac0d1f

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ PASS(DebugInfoCanonicalizer, "sil-onone-debuginfo-canonicalizer",
481481
"Canonicalize debug info at -Onone by propagating debug info into coroutine funclets")
482482
PASS(PartialApplySimplification, "partial-apply-simplification",
483483
"Transform partial_apply instructions into explicit closure box constructions")
484+
PASS(RegionAnalysisInvalidationTransform, "region-analysis-invalidation-transform",
485+
"Delete the analysis state associated with region analysis")
484486
PASS(MovedAsyncVarDebugInfoPropagator, "sil-moved-async-var-dbginfo-propagator",
485487
"Propagate debug info from moved async vars after coroutine funclet boundaries")
486488
PASS(MoveOnlyBorrowToDestructureTransform,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===--- AnalysisInvalidationTransform.h ----------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 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+
/// This file defines a transform that can be used to explicitly invalidate an
14+
/// analysis in the pass pipeline. It is intended to be used in a situation
15+
/// where passes are reusing state from an analysis and one wants to explicitly
16+
/// placed into the pass pipeline that it is expected that the analysis be
17+
/// invalidated after the series of passes complete. If we were to just place
18+
/// the invalidation in the last run of the passes, it is possible for a
19+
/// programmer later to add another pass to the end of the pipeline. This would
20+
/// then force recomputation and may prevent invalidation from happening. So by
21+
/// doing this, it is clear to someone adding a new pass that this needs to
22+
/// happen last.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#ifndef SWIFT_SILOPTIMIZER_UTILS_ANALYSISINVALIDATIONTRANSFORM_H
27+
#define SWIFT_SILOPTIMIZER_UTILS_ANALYSISINVALIDATIONTRANSFORM_H
28+
29+
#include "swift/SILOptimizer/Analysis/Analysis.h"
30+
#include "swift/SILOptimizer/PassManager/Transforms.h"
31+
32+
namespace swift {
33+
34+
template <typename AnalysisTy>
35+
struct AnalysisInvalidationTransform : public SILFunctionTransform {
36+
void run() override {
37+
getAnalysis<AnalysisTy>()->invalidate();
38+
}
39+
};
40+
41+
} // namespace swift
42+
43+
#endif

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ target_sources(swiftSILOptimizer PRIVATE
4848
YieldOnceCheck.cpp
4949
OSLogOptimization.cpp
5050
MoveOnlyWrappedTypeEliminator.cpp
51+
RegionAnalysisInvalidationTransform.cpp
5152
OwnershipModelEliminator.cpp)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===--- RegionAnalysisInvalidationTransform.cpp --------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 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+
#include "swift/SILOptimizer/Analysis/RegionAnalysis.h"
14+
#include "swift/SILOptimizer/Transforms/AnalysisInvalidationTransform.h"
15+
16+
using namespace swift;
17+
18+
SILTransform *swift::createRegionAnalysisInvalidationTransform() {
19+
return new AnalysisInvalidationTransform<RegionAnalysis>();
20+
}

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,16 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
137137
P.addAddressLowering();
138138

139139
P.addFlowIsolation();
140+
141+
//===---
142+
// Passes that depend on region analysis information
143+
//
144+
140145
P.addTransferNonSendable();
146+
147+
// Now that we have completed running passes that use region analysis, clear
148+
// region analysis.
149+
P.addRegionAnalysisInvalidationTransform();
141150
// Lower tuple addr constructor. Eventually this can be merged into later
142151
// passes. This ensures we do not need to update later passes for something
143152
// that is only needed by TransferNonSendable().

0 commit comments

Comments
 (0)