File tree Expand file tree Collapse file tree 7 files changed +63
-1
lines changed
SwiftCompilerSources/Sources/Optimizer
include/swift/SILOptimizer Expand file tree Collapse file tree 7 files changed +63
-1
lines changed Original file line number Diff line number Diff line change 8
8
9
9
swift_compiler_sources (Optimizer
10
10
AliasAnalysis.swift
11
- CalleeAnalysis.swift )
11
+ CalleeAnalysis.swift
12
+ DeadEndBlocksAnalysis.swift )
Original file line number Diff line number Diff line change
1
+ //===--- DeadEndBlocksAnalysis.swift - the dead-end blocks analysis -------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2021 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
+ import OptimizerBridging
14
+ import SIL
15
+
16
+ public struct DeadEndBlocksAnalysis {
17
+ let bridged : BridgedDeadEndBlocksAnalysis
18
+
19
+ public func isDeadEnd( _ block: BasicBlock ) -> Bool {
20
+ return DeadEndBlocksAnalysis_isDeadEnd ( bridged, block. bridged) != 0
21
+ }
22
+ }
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ struct PassContext {
36
36
return CalleeAnalysis ( bridged: bridgeCA)
37
37
}
38
38
39
+ var deadEndBlocks : DeadEndBlocksAnalysis {
40
+ let bridgeDEA = PassContext_getDeadEndBlocksAnalysis ( _bridged)
41
+ return DeadEndBlocksAnalysis ( bridged: bridgeDEA)
42
+ }
43
+
39
44
func notifyInstructionsChanged( ) {
40
45
PassContext_notifyChanges ( _bridged, instructionsChanged)
41
46
}
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ class DeadEndBlocksAnalysis final : public FunctionAnalysisBase<DeadEndBlocks> {
26
26
DeadEndBlocksAnalysis (const DeadEndBlocksAnalysis &) = delete ;
27
27
DeadEndBlocksAnalysis &operator =(const DeadEndBlocksAnalysis &) = delete ;
28
28
29
+ static SILAnalysisKind getAnalysisKind () {
30
+ return SILAnalysisKind::DeadEndBlocks;
31
+ }
32
+
29
33
static bool classof (const SILAnalysis *s) {
30
34
return s->getKind () == SILAnalysisKind::DeadEndBlocks;
31
35
}
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ typedef struct {
39
39
void * _Nullable bca ;
40
40
} BridgedCalleeAnalysis ;
41
41
42
+ typedef struct {
43
+ void * _Nullable dea ;
44
+ } BridgedDeadEndBlocksAnalysis ;
45
+
42
46
typedef struct {
43
47
void * _Nonnull opaquePtr ;
44
48
unsigned char kind ;
@@ -82,6 +86,12 @@ SwiftInt BridgedFunctionArray_size(BridgedCalleeList callees);
82
86
BridgedFunction BridgedFunctionArray_get (BridgedCalleeList callees ,
83
87
SwiftInt index );
84
88
89
+ BridgedDeadEndBlocksAnalysis
90
+ PassContext_getDeadEndBlocksAnalysis (BridgedPassContext context );
91
+
92
+ SwiftInt DeadEndBlocksAnalysis_isDeadEnd (BridgedDeadEndBlocksAnalysis debAnalysis ,
93
+ BridgedBasicBlock );
94
+
85
95
BridgedSlab PassContext_getNextSlab (BridgedSlab slab );
86
96
BridgedSlab PassContext_getPreviousSlab (BridgedSlab slab );
87
97
BridgedSlab PassContext_allocSlab (BridgedPassContext passContext ,
Original file line number Diff line number Diff line change 10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " swift/SIL/SILBridgingUtils.h"
13
14
#include " swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
15
+ #include " swift/SILOptimizer/OptimizerBridging.h"
14
16
#include " swift/AST/Decl.h"
15
17
#include " swift/SIL/SILFunction.h"
16
18
@@ -55,3 +57,13 @@ void DeadEndBlocksAnalysis::verify(DeadEndBlocks *deBlocks) const {
55
57
SILAnalysis *swift::createDeadEndBlocksAnalysis (SILModule *) {
56
58
return new DeadEndBlocksAnalysis ();
57
59
}
60
+
61
+ // ===----------------------------------------------------------------------===//
62
+ // Swift Bridging
63
+ // ===----------------------------------------------------------------------===//
64
+
65
+ SwiftInt DeadEndBlocksAnalysis_isDeadEnd (BridgedDeadEndBlocksAnalysis debAnalysis,
66
+ BridgedBasicBlock block) {
67
+ auto *dea = static_cast <DeadEndBlocks *>(debAnalysis.dea );
68
+ return dea->isDeadEnd (castToBasicBlock (block));
69
+ }
Original file line number Diff line number Diff line change 21
21
#include " swift/SIL/SILModule.h"
22
22
#include " swift/SILOptimizer/Analysis/AliasAnalysis.h"
23
23
#include " swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
24
+ #include " swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
24
25
#include " swift/SILOptimizer/Analysis/FunctionOrder.h"
25
26
#include " swift/SILOptimizer/OptimizerBridging.h"
26
27
#include " swift/SILOptimizer/PassManager/PrettyStackTrace.h"
@@ -1241,6 +1242,13 @@ BridgedCalleeAnalysis PassContext_getCalleeAnalysis(BridgedPassContext context)
1241
1242
return {pm->getAnalysis <BasicCalleeAnalysis>()};
1242
1243
}
1243
1244
1245
+ BridgedDeadEndBlocksAnalysis
1246
+ PassContext_getDeadEndBlocksAnalysis (BridgedPassContext context) {
1247
+ SwiftPassInvocation *invocation = castToPassInvocation (context);
1248
+ SILPassManager *pm = invocation->getPassManager ();
1249
+ return {pm->getAnalysis <DeadEndBlocksAnalysis>(invocation->getFunction ())};
1250
+ }
1251
+
1244
1252
BridgedBasicBlockSet PassContext_allocBasicBlockSet (BridgedPassContext context) {
1245
1253
return {castToPassInvocation (context)->allocBlockSet ()};
1246
1254
}
You can’t perform that action at this time.
0 commit comments