Skip to content

Commit ffbe85f

Browse files
committed
[NFC] Extracted emitPackExpansionElementMetadata.
The function emits the metadata for the element of a pack expansion at a specified index. It was previously defined inline in the loop--defined in emitPackExpansionType--which populates a new metadata array with elements derived from a preexisting array. It will be used to emit a single element in the case that only one is needed.
1 parent 764ef35 commit ffbe85f

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

lib/IRGen/GenPack.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -164,30 +164,9 @@ static Address emitFixedSizeMetadataPackRef(IRGenFunction &IGF,
164164
return pack;
165165
}
166166

167-
static void emitPackExpansionType(IRGenFunction &IGF,
168-
Address pack,
169-
CanPackExpansionType expansionTy,
170-
llvm::Value *dynamicIndex,
171-
llvm::Value *dynamicLength,
172-
DynamicMetadataRequest request) {
173-
auto *prev = IGF.Builder.GetInsertBlock();
174-
auto *check = IGF.createBasicBlock("pack-expansion-check");
175-
auto *loop = IGF.createBasicBlock("pack-expansion-loop");
176-
auto *rest = IGF.createBasicBlock("pack-expansion-rest");
177-
178-
IGF.Builder.CreateBr(check);
179-
IGF.Builder.emitBlock(check);
180-
181-
// An index into the source metadata pack.
182-
auto *phi = IGF.Builder.CreatePHI(IGF.IGM.SizeTy, 2);
183-
phi->addIncoming(llvm::ConstantInt::get(IGF.IGM.SizeTy, 0), prev);
184-
185-
// If we reach the end, jump to the continuation block.
186-
auto *cond = IGF.Builder.CreateICmpULT(phi, dynamicLength);
187-
IGF.Builder.CreateCondBr(cond, loop, rest);
188-
189-
IGF.Builder.emitBlock(loop);
190-
167+
static llvm::Value *emitPackExpansionElementMetadata(
168+
IRGenFunction &IGF, CanPackExpansionType expansionTy, llvm::Value *phi,
169+
DynamicMetadataRequest request) {
191170
auto patternTy = expansionTy.getPatternType();
192171

193172
// Find all the pack archetypes appearing in the pattern type.
@@ -247,6 +226,34 @@ static void emitPackExpansionType(IRGenFunction &IGF,
247226
// Emit the element metadata.
248227
auto element = IGF.emitTypeMetadataRef(instantiatedPatternTy, request)
249228
.getMetadata();
229+
return element;
230+
}
231+
232+
static void emitPackExpansionType(IRGenFunction &IGF, Address pack,
233+
CanPackExpansionType expansionTy,
234+
llvm::Value *dynamicIndex,
235+
llvm::Value *dynamicLength,
236+
DynamicMetadataRequest request) {
237+
auto *prev = IGF.Builder.GetInsertBlock();
238+
auto *check = IGF.createBasicBlock("pack-expansion-check");
239+
auto *loop = IGF.createBasicBlock("pack-expansion-loop");
240+
auto *rest = IGF.createBasicBlock("pack-expansion-rest");
241+
242+
IGF.Builder.CreateBr(check);
243+
IGF.Builder.emitBlock(check);
244+
245+
// An index into the source metadata pack.
246+
auto *phi = IGF.Builder.CreatePHI(IGF.IGM.SizeTy, 2);
247+
phi->addIncoming(llvm::ConstantInt::get(IGF.IGM.SizeTy, 0), prev);
248+
249+
// If we reach the end, jump to the continuation block.
250+
auto *cond = IGF.Builder.CreateICmpULT(phi, dynamicLength);
251+
IGF.Builder.CreateCondBr(cond, loop, rest);
252+
253+
IGF.Builder.emitBlock(loop);
254+
255+
auto *element =
256+
emitPackExpansionElementMetadata(IGF, expansionTy, phi, request);
250257

251258
// Store the element metadata into to the current destination index.
252259
auto *eltIndex = IGF.Builder.CreateAdd(dynamicIndex, phi);

0 commit comments

Comments
 (0)