File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,8 @@ class BasicBlockSet {
89
89
BasicBlockFlag flag;
90
90
91
91
public:
92
+ using Element = SILBasicBlock *;
93
+
92
94
BasicBlockSet (SILFunction *function) : flag(function) {}
93
95
94
96
SILFunction *getFunction () const { return flag.getFunction (); }
@@ -101,6 +103,8 @@ class BasicBlockSet {
101
103
void erase (SILBasicBlock *block) { flag.reset (block); }
102
104
};
103
105
106
+ using BasicBlockSetWithSize = KnownSizeSet<BasicBlockSet>;
107
+
104
108
} // namespace swift
105
109
106
110
#endif
Original file line number Diff line number Diff line change @@ -94,6 +94,8 @@ class InstructionSet {
94
94
NodeSet nodeSet;
95
95
96
96
public:
97
+ using Element = SILInstruction *;
98
+
97
99
InstructionSet (SILFunction *function) : nodeSet(function) {}
98
100
99
101
SILFunction *getFunction () const { return nodeSet.getFunction (); }
@@ -106,13 +108,17 @@ class InstructionSet {
106
108
void erase (SILInstruction *inst) { nodeSet.erase (inst->asSILNode ()); }
107
109
};
108
110
111
+ using InstructionSetWithSize = KnownSizeSet<InstructionSet>;
112
+
109
113
// / A set of SILValues.
110
114
// /
111
115
// / For details see NodeBitfield.
112
116
class ValueSet {
113
117
NodeSet nodeSet;
114
118
115
119
public:
120
+ using Element = SILValue;
121
+
116
122
ValueSet (SILFunction *function) : nodeSet(function) {}
117
123
118
124
SILFunction *getFunction () const { return nodeSet.getFunction (); }
@@ -125,6 +131,8 @@ class ValueSet {
125
131
void erase (SILValue value) { nodeSet.erase (value); }
126
132
};
127
133
134
+ using ValueSetWithSize = KnownSizeSet<ValueSet>;
135
+
128
136
} // namespace swift
129
137
130
138
#endif
Original file line number Diff line number Diff line change @@ -108,6 +108,43 @@ template <class Impl, class T> class SILBitfield {
108
108
}
109
109
};
110
110
111
+ // / A set which knowns its size.
112
+ // /
113
+ // / This template adds a size property to a base `Set`.
114
+ template <class Set >
115
+ class KnownSizeSet {
116
+ Set set;
117
+ size_t numElements = 0 ;
118
+ public:
119
+ using Element = typename Set::Element;
120
+
121
+ KnownSizeSet (SILFunction *function) : set(function) {}
122
+
123
+ SILFunction *getFunction () const { return set.getFunction (); }
124
+
125
+ bool contains (Element element) const { return set.contains (element); }
126
+
127
+ // / Returns true if \p value was not contained in the set before inserting.
128
+ bool insert (Element element) {
129
+ if (set.insert (element)) {
130
+ numElements += 1 ;
131
+ return true ;
132
+ }
133
+ return false ;
134
+ }
135
+
136
+ void erase (Element element) {
137
+ if (contains (element)) {
138
+ set.erase (element);
139
+ assert (numElements > 0 );
140
+ numElements -= 1 ;
141
+ }
142
+ }
143
+
144
+ bool empty () const { return numElements == 0 ; }
145
+
146
+ size_t size () const { return numElements; }
147
+ };
111
148
112
149
} // namespace swift
113
150
You can’t perform that action at this time.
0 commit comments