2929#include " swift/SIL/SILValue.h"
3030#include " swift/SIL/SILVisitor.h"
3131#include " swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h"
32+ #include " swift/SILOptimizer/Analysis/NonLocalAccessBlockAnalysis.h"
3233#include " swift/SILOptimizer/Analysis/ProtocolConformanceAnalysis.h"
3334#include " swift/SILOptimizer/Utils/CastOptimizer.h"
3435#include " swift/SILOptimizer/Utils/Existential.h"
@@ -46,6 +47,7 @@ class AliasAnalysis;
4647// / the worklist.
4748class SILCombiner :
4849 public SILInstructionVisitor<SILCombiner, SILInstruction *> {
50+ SILFunctionTransform *parentTransform;
4951
5052 AliasAnalysis *AA;
5153
@@ -59,6 +61,10 @@ class SILCombiner :
5961 // / conforming class.
6062 ClassHierarchyAnalysis *CHA;
6163
64+ // / Non local access block analysis that we use when canonicalize object
65+ // / lifetimes in OSSA.
66+ NonLocalAccessBlockAnalysis *NLABA;
67+
6268 // / Worklist containing all of the instructions primed for simplification.
6369 SmallSILInstructionWorklist<256 > Worklist;
6470
@@ -97,39 +103,47 @@ class SILCombiner :
97103 OwnershipFixupContext ownershipFixupContext;
98104
99105public:
100- SILCombiner (SILOptFunctionBuilder &FuncBuilder, SILBuilder &B,
106+ SILCombiner (SILFunctionTransform *parentTransform,
107+ SILOptFunctionBuilder &FuncBuilder, SILBuilder &B,
101108 AliasAnalysis *AA, DominanceAnalysis *DA,
102109 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()),
121127 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+ });
133147 }
134148
135149 bool runOnFunction (SILFunction &F);
0 commit comments