29
29
#include " swift/SIL/SILValue.h"
30
30
#include " swift/SIL/SILVisitor.h"
31
31
#include " swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h"
32
+ #include " swift/SILOptimizer/Analysis/NonLocalAccessBlockAnalysis.h"
32
33
#include " swift/SILOptimizer/Analysis/ProtocolConformanceAnalysis.h"
33
34
#include " swift/SILOptimizer/Utils/CastOptimizer.h"
34
35
#include " swift/SILOptimizer/Utils/Existential.h"
@@ -46,6 +47,7 @@ class AliasAnalysis;
46
47
// / the worklist.
47
48
class SILCombiner :
48
49
public SILInstructionVisitor<SILCombiner, SILInstruction *> {
50
+ SILFunctionTransform *parentTransform;
49
51
50
52
AliasAnalysis *AA;
51
53
@@ -59,6 +61,10 @@ class SILCombiner :
59
61
// / conforming class.
60
62
ClassHierarchyAnalysis *CHA;
61
63
64
+ // / Non local access block analysis that we use when canonicalize object
65
+ // / lifetimes in OSSA.
66
+ NonLocalAccessBlockAnalysis *NLABA;
67
+
62
68
// / Worklist containing all of the instructions primed for simplification.
63
69
SmallSILInstructionWorklist<256 > Worklist;
64
70
@@ -97,39 +103,47 @@ class SILCombiner :
97
103
OwnershipFixupContext ownershipFixupContext;
98
104
99
105
public:
100
- SILCombiner (SILOptFunctionBuilder &FuncBuilder, SILBuilder &B,
106
+ SILCombiner (SILFunctionTransform *parentTransform,
107
+ SILOptFunctionBuilder &FuncBuilder, SILBuilder &B,
101
108
AliasAnalysis *AA, DominanceAnalysis *DA,
102
109
ProtocolConformanceAnalysis *PCA, ClassHierarchyAnalysis *CHA,
103
- bool removeCondFails)
104
- : AA(AA), DA(DA), PCA(PCA), CHA(CHA), Worklist(" SC" ),
105
- deadEndBlocks (&B.getFunction()), MadeChange(false ),
106
- RemoveCondFails(removeCondFails), Iteration(0 ), Builder(B),
107
- CastOpt(
108
- FuncBuilder, nullptr /* SILBuilderContext*/ ,
109
- /* ReplaceValueUsesAction */
110
- [&](SILValue Original, SILValue Replacement) {
111
- replaceValueUsesWith (Original, Replacement);
112
- },
113
- /* ReplaceInstUsesAction */
114
- [&](SingleValueInstruction *I, ValueBase *V) {
115
- replaceInstUsesWith (*I, V);
116
- },
117
- /* EraseAction */
118
- [&](SILInstruction *I) { eraseInstFromFunction (*I); }),
119
- instModCallbacks (),
120
- deBlocks (&B.getFunction()),
110
+ NonLocalAccessBlockAnalysis *NLABA, bool removeCondFails)
111
+ : parentTransform(parentTransform), AA(AA), DA(DA), PCA(PCA), CHA(CHA),
112
+ NLABA (NLABA), Worklist(" SC" ), deadEndBlocks(&B.getFunction()),
113
+ MadeChange(false ), RemoveCondFails(removeCondFails), Iteration(0 ),
114
+ Builder(B), CastOpt(
115
+ FuncBuilder, nullptr /* SILBuilderContext*/ ,
116
+ /* ReplaceValueUsesAction */
117
+ [&](SILValue Original, SILValue Replacement) {
118
+ replaceValueUsesWith (Original, Replacement);
119
+ },
120
+ /* ReplaceInstUsesAction */
121
+ [&](SingleValueInstruction *I, ValueBase *V) {
122
+ replaceInstUsesWith (*I, V);
123
+ },
124
+ /* EraseAction */
125
+ [&](SILInstruction *I) { eraseInstFromFunction (*I); }),
126
+ instModCallbacks (), deBlocks(&B.getFunction()),
121
127
ownershipFixupContext (instModCallbacks, deBlocks) {
122
- instModCallbacks = InstModCallbacks ()
123
- .onDelete ([&](SILInstruction *instToDelete) {
124
- eraseInstFromFunction (*instToDelete);
125
- })
126
- .onCreateNewInst ([&](SILInstruction *newlyCreatedInst) {
127
- Worklist.add (newlyCreatedInst);
128
- })
129
- .onSetUseValue ([&](Operand *use, SILValue newValue) {
130
- use->set (newValue);
131
- Worklist.add (use->getUser ());
132
- });
128
+ instModCallbacks =
129
+ InstModCallbacks ()
130
+ .onDelete ([&](SILInstruction *instToDelete) {
131
+ // We allow for users in SILCombine to perform 2 stage deletion,
132
+ // so we need to split the erasing of instructions from adding
133
+ // operands to the worklist.
134
+ eraseInstFromFunction (
135
+ *instToDelete, false /* do not add operands to the worklist*/ );
136
+ })
137
+ .onNotifyWillBeDeleted ([&](SILInstruction *instThatWillBeDeleted) {
138
+ Worklist.addOperandsToWorklist (*instThatWillBeDeleted);
139
+ })
140
+ .onCreateNewInst ([&](SILInstruction *newlyCreatedInst) {
141
+ Worklist.add (newlyCreatedInst);
142
+ })
143
+ .onSetUseValue ([&](Operand *use, SILValue newValue) {
144
+ use->set (newValue);
145
+ Worklist.add (use->getUser ());
146
+ });
133
147
}
134
148
135
149
bool runOnFunction (SILFunction &F);
0 commit comments