|
21 | 21 |
|
22 | 22 | using namespace swift;
|
23 | 23 |
|
| 24 | +/// Determine which kind of array semantics function this is. |
| 25 | +ArrayCallKind swift::getArraySemanticsKind(SILFunction *f) { |
| 26 | + ArrayCallKind Kind = ArrayCallKind::kNone; |
| 27 | + |
| 28 | + for (auto &Attrs : f->getSemanticsAttrs()) { |
| 29 | + auto Tmp = |
| 30 | + llvm::StringSwitch<ArrayCallKind>(Attrs) |
| 31 | + .Case("array.props.isNativeTypeChecked", |
| 32 | + ArrayCallKind::kArrayPropsIsNativeTypeChecked) |
| 33 | + .StartsWith("array.init", ArrayCallKind::kArrayInit) |
| 34 | + .Case("array.uninitialized", ArrayCallKind::kArrayUninitialized) |
| 35 | + .Case("array.uninitialized_intrinsic", ArrayCallKind::kArrayUninitializedIntrinsic) |
| 36 | + .Case("array.check_subscript", ArrayCallKind::kCheckSubscript) |
| 37 | + .Case("array.check_index", ArrayCallKind::kCheckIndex) |
| 38 | + .Case("array.get_count", ArrayCallKind::kGetCount) |
| 39 | + .Case("array.get_capacity", ArrayCallKind::kGetCapacity) |
| 40 | + .Case("array.get_element", ArrayCallKind::kGetElement) |
| 41 | + .Case("array.make_mutable", ArrayCallKind::kMakeMutable) |
| 42 | + .Case("array.get_element_address", |
| 43 | + ArrayCallKind::kGetElementAddress) |
| 44 | + .Case("array.mutate_unknown", ArrayCallKind::kMutateUnknown) |
| 45 | + .Case("array.reserve_capacity_for_append", |
| 46 | + ArrayCallKind::kReserveCapacityForAppend) |
| 47 | + .Case("array.withUnsafeMutableBufferPointer", |
| 48 | + ArrayCallKind::kWithUnsafeMutableBufferPointer) |
| 49 | + .Case("array.append_contentsOf", ArrayCallKind::kAppendContentsOf) |
| 50 | + .Case("array.append_element", ArrayCallKind::kAppendElement) |
| 51 | + .Default(ArrayCallKind::kNone); |
| 52 | + if (Tmp != ArrayCallKind::kNone) { |
| 53 | + assert(Kind == ArrayCallKind::kNone && "Multiple array semantic " |
| 54 | + "strings?!"); |
| 55 | + Kind = Tmp; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + return Kind; |
| 60 | +} |
| 61 | + |
24 | 62 | static ParameterConvention
|
25 | 63 | getSelfParameterConvention(ApplyInst *SemanticsCall) {
|
26 | 64 | FunctionRefInst *FRI = cast<FunctionRefInst>(SemanticsCall->getCallee());
|
@@ -161,40 +199,7 @@ ArrayCallKind swift::ArraySemanticsCall::getKind() const {
|
161 | 199 | auto F = cast<FunctionRefInst>(SemanticsCall->getCallee())
|
162 | 200 | ->getInitiallyReferencedFunction();
|
163 | 201 |
|
164 |
| - ArrayCallKind Kind = ArrayCallKind::kNone; |
165 |
| - |
166 |
| - for (auto &Attrs : F->getSemanticsAttrs()) { |
167 |
| - auto Tmp = |
168 |
| - llvm::StringSwitch<ArrayCallKind>(Attrs) |
169 |
| - .Case("array.props.isNativeTypeChecked", |
170 |
| - ArrayCallKind::kArrayPropsIsNativeTypeChecked) |
171 |
| - .StartsWith("array.init", ArrayCallKind::kArrayInit) |
172 |
| - .Case("array.uninitialized", ArrayCallKind::kArrayUninitialized) |
173 |
| - .Case("array.uninitialized_intrinsic", ArrayCallKind::kArrayUninitializedIntrinsic) |
174 |
| - .Case("array.check_subscript", ArrayCallKind::kCheckSubscript) |
175 |
| - .Case("array.check_index", ArrayCallKind::kCheckIndex) |
176 |
| - .Case("array.get_count", ArrayCallKind::kGetCount) |
177 |
| - .Case("array.get_capacity", ArrayCallKind::kGetCapacity) |
178 |
| - .Case("array.get_element", ArrayCallKind::kGetElement) |
179 |
| - .Case("array.make_mutable", ArrayCallKind::kMakeMutable) |
180 |
| - .Case("array.get_element_address", |
181 |
| - ArrayCallKind::kGetElementAddress) |
182 |
| - .Case("array.mutate_unknown", ArrayCallKind::kMutateUnknown) |
183 |
| - .Case("array.reserve_capacity_for_append", |
184 |
| - ArrayCallKind::kReserveCapacityForAppend) |
185 |
| - .Case("array.withUnsafeMutableBufferPointer", |
186 |
| - ArrayCallKind::kWithUnsafeMutableBufferPointer) |
187 |
| - .Case("array.append_contentsOf", ArrayCallKind::kAppendContentsOf) |
188 |
| - .Case("array.append_element", ArrayCallKind::kAppendElement) |
189 |
| - .Default(ArrayCallKind::kNone); |
190 |
| - if (Tmp != ArrayCallKind::kNone) { |
191 |
| - assert(Kind == ArrayCallKind::kNone && "Multiple array semantic " |
192 |
| - "strings?!"); |
193 |
| - Kind = Tmp; |
194 |
| - } |
195 |
| - } |
196 |
| - |
197 |
| - return Kind; |
| 202 | + return getArraySemanticsKind(F); |
198 | 203 | }
|
199 | 204 |
|
200 | 205 | bool swift::ArraySemanticsCall::hasSelf() const {
|
|
0 commit comments