-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathRCStateTransitionVisitors.h
198 lines (162 loc) · 7.35 KB
/
RCStateTransitionVisitors.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//===--- RCStateTransitionVisitors.h ----------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file contains RCStateTransitionVisitors for performing ARC dataflow. It
// is necessary to prevent a circular dependency in between RefCountState.h and
// RCStateTransition.h
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SILOPTIMIZER_PASSMANAGER_ARC_RCSTATETRANSITIONVISITORS_H
#define SWIFT_SILOPTIMIZER_PASSMANAGER_ARC_RCSTATETRANSITIONVISITORS_H
#include "ARCBBState.h"
#include "ARCRegionState.h"
#include "RCStateTransition.h"
#include "swift/Basic/ImmutablePointerSet.h"
#include "swift/Basic/BlotMapVector.h"
//===----------------------------------------------------------------------===//
// RCStateTransitionVisitor
//===----------------------------------------------------------------------===//
namespace swift {
/// Define a visitor for visiting instructions according to their
/// RCStateTransitionKind.
template <typename ImplTy, typename ResultTy>
class RCStateTransitionKindVisitor {
ImplTy &asImpl() { return *reinterpret_cast<ImplTy *>(this); }
public:
#define KIND(K) ResultTy visit ## K(SILNode *) { return ResultTy(); }
#include "RCStateTransition.def"
ResultTy visit(SILNode *N) {
switch (getRCStateTransitionKind(N)) {
#define KIND(K) \
case RCStateTransitionKind::K: \
return asImpl().visit ## K(N);
#include "RCStateTransition.def"
}
llvm_unreachable("Covered switch isn't covered?!");
}
};
} // end swift namespace
//===----------------------------------------------------------------------===//
// RCStateTransitionDataflowResult
//===----------------------------------------------------------------------===//
namespace swift {
enum class RCStateTransitionDataflowResultKind {
/// Can this dataflow result have no further effects on any state. This means
/// we can just early out and break early.
NoEffects,
/// Must we check for effects.
CheckForEffects,
};
struct RCStateTransitionDataflowResult {
using DataflowResultKind = RCStateTransitionDataflowResultKind;
DataflowResultKind Kind;
SILValue RCIdentity;
bool NestingDetected = false;
RCStateTransitionDataflowResult()
: Kind(DataflowResultKind::CheckForEffects), RCIdentity() {}
RCStateTransitionDataflowResult(DataflowResultKind Kind)
: Kind(Kind), RCIdentity() {}
RCStateTransitionDataflowResult(SILValue RCIdentity,
bool NestingDetected = false)
: Kind(DataflowResultKind::CheckForEffects), RCIdentity(RCIdentity),
NestingDetected(NestingDetected) {}
RCStateTransitionDataflowResult(const RCStateTransitionDataflowResult &) =
default;
~RCStateTransitionDataflowResult() = default;
};
} // end swift namespace
namespace llvm {
raw_ostream &operator<<(raw_ostream &os,
swift::RCStateTransitionDataflowResult Kind);
} // end llvm namespace
//===----------------------------------------------------------------------===//
// BottomUpDataflowRCStateVisitor
//===----------------------------------------------------------------------===//
namespace swift {
/// A visitor for performing the bottom up dataflow depending on the
/// RCState. Enables behavior to be cleanly customized depending on the
/// RCStateTransition associated with an instruction.
template <class ARCState>
class BottomUpDataflowRCStateVisitor
: public RCStateTransitionKindVisitor<BottomUpDataflowRCStateVisitor<ARCState>,
RCStateTransitionDataflowResult> {
/// A local typedef to make things cleaner.
using DataflowResult = RCStateTransitionDataflowResult;
using IncToDecStateMapTy =
BlotMapVector<SILInstruction *, BottomUpRefCountState>;
public:
RCIdentityFunctionInfo *RCFI;
EpilogueARCFunctionInfo *EAFI;
ARCState &DataflowState;
bool FreezeOwnedArgEpilogueReleases;
BlotMapVector<SILInstruction *, BottomUpRefCountState> &IncToDecStateMap;
ImmutablePointerSetFactory<SILInstruction> &SetFactory;
public:
BottomUpDataflowRCStateVisitor(
RCIdentityFunctionInfo *RCFI, EpilogueARCFunctionInfo *EAFI,
ARCState &DataflowState, bool FreezeOwnedArgEpilogueReleases,
IncToDecStateMapTy &IncToDecStateMap,
ImmutablePointerSetFactory<SILInstruction> &SetFactory);
DataflowResult visitAutoreleasePoolCall(SILNode *N);
DataflowResult visitStrongDecrement(SILNode *N);
DataflowResult visitStrongIncrement(SILNode *N);
};
} // end swift namespace
//===----------------------------------------------------------------------===//
// TopDownDataflowRCStateVisitor
//===----------------------------------------------------------------------===//
namespace swift {
/// A visitor for performing the bottom up dataflow depending on the
/// RCState. Enables behavior to be cleanly customized depending on the
/// RCStateTransition associated with an instruction.
template <class ARCState>
class TopDownDataflowRCStateVisitor
: public RCStateTransitionKindVisitor<TopDownDataflowRCStateVisitor<ARCState>,
RCStateTransitionDataflowResult> {
/// A local typedef to make things cleaner.
using DataflowResult = RCStateTransitionDataflowResult;
using DecToIncStateMapTy =
BlotMapVector<SILInstruction *, TopDownRefCountState>;
RCIdentityFunctionInfo *RCFI;
ARCState &DataflowState;
DecToIncStateMapTy &DecToIncStateMap;
ImmutablePointerSetFactory<SILInstruction> &SetFactory;
public:
TopDownDataflowRCStateVisitor(
RCIdentityFunctionInfo *RCFI, ARCState &State,
DecToIncStateMapTy &DecToIncStateMap,
ImmutablePointerSetFactory<SILInstruction> &SetFactory);
DataflowResult visitAutoreleasePoolCall(SILNode *N);
DataflowResult visitStrongDecrement(SILNode *N);
DataflowResult visitStrongIncrement(SILNode *N);
DataflowResult visitStrongEntrance(SILNode *N);
private:
DataflowResult visitStrongEntranceApply(ApplyInst *AI);
DataflowResult visitStrongEntrancePartialApply(PartialApplyInst *PAI);
DataflowResult visitStrongEntranceArgument(SILFunctionArgument *Arg);
DataflowResult visitStrongEntranceAllocRef(AllocRefInst *ARI);
DataflowResult visitStrongEntranceAllocRefDynamic(AllocRefDynamicInst *ARI);
DataflowResult visitStrongAllocBox(AllocBoxInst *ABI);
};
} // end swift namespace
//===----------------------------------------------------------------------===//
// Forward Template Declarations
//===----------------------------------------------------------------------===//
namespace swift {
extern template class BottomUpDataflowRCStateVisitor<
ARCSequenceDataflowEvaluator::ARCBBState>;
extern template class BottomUpDataflowRCStateVisitor<ARCRegionState>;
extern template class TopDownDataflowRCStateVisitor<
ARCSequenceDataflowEvaluator::ARCBBState>;
extern template class TopDownDataflowRCStateVisitor<ARCRegionState>;
} // end swift namespace
#endif