23
23
24
24
#include " swift/SIL/SILBuilder.h"
25
25
#include " swift/SIL/SILInstruction.h"
26
+ #include " swift/SIL/SILInstructionWorklist.h"
26
27
#include " swift/SIL/SILValue.h"
27
28
#include " swift/SIL/SILVisitor.h"
28
29
#include " swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h"
@@ -37,84 +38,6 @@ namespace swift {
37
38
38
39
class AliasAnalysis ;
39
40
40
- // / This is the worklist management logic for SILCombine.
41
- class SILCombineWorklist {
42
- llvm::SmallVector<SILInstruction *, 256 > Worklist;
43
- llvm::DenseMap<SILInstruction *, unsigned > WorklistMap;
44
-
45
- void operator =(const SILCombineWorklist &RHS) = delete ;
46
- SILCombineWorklist (const SILCombineWorklist &Worklist) = delete ;
47
- public:
48
- SILCombineWorklist () {}
49
-
50
- // / Returns true if the worklist is empty.
51
- bool isEmpty () const { return Worklist.empty (); }
52
-
53
- // / Add the specified instruction to the worklist if it isn't already in it.
54
- void add (SILInstruction *I);
55
-
56
- // / If the given ValueBase is a SILInstruction add it to the worklist.
57
- void addValue (ValueBase *V) {
58
- if (auto *I = V->getDefiningInstruction ())
59
- add (I);
60
- }
61
-
62
- // / Add the given list of instructions in reverse order to the worklist. This
63
- // / routine assumes that the worklist is empty and the given list has no
64
- // / duplicates.
65
- void addInitialGroup (ArrayRef<SILInstruction *> List);
66
-
67
- // If I is in the worklist, remove it.
68
- void remove (SILInstruction *I) {
69
- auto It = WorklistMap.find (I);
70
- if (It == WorklistMap.end ())
71
- return ; // Not in worklist.
72
-
73
- // Don't bother moving everything down, just null out the slot. We will
74
- // check before we process any instruction if it is null.
75
- Worklist[It->second ] = nullptr ;
76
- WorklistMap.erase (It);
77
- }
78
-
79
- // / Remove the top element from the worklist.
80
- SILInstruction *removeOne () {
81
- SILInstruction *I = Worklist.pop_back_val ();
82
- WorklistMap.erase (I);
83
- return I;
84
- }
85
-
86
- // / When an instruction has been simplified, add all of its users to the
87
- // / worklist, since additional simplifications of its users may have been
88
- // / exposed.
89
- void addUsersToWorklist (ValueBase *I) {
90
- for (auto UI : I->getUses ())
91
- add (UI->getUser ());
92
- }
93
-
94
- void addUsersToWorklist (SILValue value) {
95
- for (auto *use : value->getUses ())
96
- add (use->getUser ());
97
- }
98
-
99
- // / When an instruction has been simplified, add all of its users to the
100
- // / worklist, since additional simplifications of its users may have been
101
- // / exposed.
102
- void addUsersOfAllResultsToWorklist (SILInstruction *I) {
103
- for (auto result : I->getResults ()) {
104
- addUsersToWorklist (result);
105
- }
106
- }
107
-
108
- // / Check that the worklist is empty and nuke the backing store for the map if
109
- // / it is large.
110
- void zap () {
111
- assert (WorklistMap.empty () && " Worklist empty, but the map is not?" );
112
-
113
- // Do an explicit clear, this shrinks the map if needed.
114
- WorklistMap.clear ();
115
- }
116
- };
117
-
118
41
// / This is a class which maintains the state of the combiner and simplifies
119
42
// / many operations such as removing/adding instructions and syncing them with
120
43
// / the worklist.
@@ -134,7 +57,7 @@ class SILCombiner :
134
57
ClassHierarchyAnalysis *CHA;
135
58
136
59
// / Worklist containing all of the instructions primed for simplification.
137
- SILCombineWorklist Worklist;
60
+ SILInstructionWorklist Worklist;
138
61
139
62
// / Variable to track if the SILCombiner made any changes.
140
63
bool MadeChange;
@@ -156,7 +79,7 @@ class SILCombiner :
156
79
AliasAnalysis *AA, DominanceAnalysis *DA,
157
80
ProtocolConformanceAnalysis *PCA, ClassHierarchyAnalysis *CHA,
158
81
bool removeCondFails)
159
- : AA(AA), DA(DA), PCA(PCA), CHA(CHA), Worklist(), MadeChange(false ),
82
+ : AA(AA), DA(DA), PCA(PCA), CHA(CHA), Worklist(" SC " ), MadeChange(false ),
160
83
RemoveCondFails (removeCondFails), Iteration(0 ), Builder(B),
161
84
CastOpt(FuncBuilder, nullptr /* SILBuilderContext*/ ,
162
85
/* ReplaceValueUsesAction */
0 commit comments