@@ -251,18 +251,21 @@ SILValue SILDeserializer::getLocalValue(ValueID Id, unsigned ResultNum,
251
251
252
252
// / Return the SILBasicBlock of a given ID.
253
253
SILBasicBlock *SILDeserializer::getBBForDefinition (SILFunction *Fn,
254
+ SILBasicBlock *Prev,
254
255
unsigned ID) {
255
256
SILBasicBlock *&BB = BlocksByID[ID];
256
257
// If the block has never been named yet, just create it.
257
258
if (BB == nullptr )
258
- return BB = new (SILMod) SILBasicBlock (Fn);
259
+ return BB = new (SILMod) SILBasicBlock (Fn, Prev );
259
260
260
261
// If it already exists, it was either a forward reference or a redefinition.
261
262
// The latter should never happen.
262
263
bool wasForwardReferenced = UndefinedBlocks.erase (BB);
263
264
assert (wasForwardReferenced);
264
265
(void )wasForwardReferenced;
265
266
267
+ if (Prev)
268
+ BB->moveAfter (Prev);
266
269
return BB;
267
270
}
268
271
@@ -531,7 +534,7 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,
531
534
kind != SIL_WITNESSTABLE) {
532
535
if (kind == SIL_BASIC_BLOCK)
533
536
// Handle a SILBasicBlock record.
534
- CurrentBB = readSILBasicBlock (fn, scratch);
537
+ CurrentBB = readSILBasicBlock (fn, CurrentBB, scratch);
535
538
else {
536
539
// If CurrentBB is empty, just return fn. The code in readSILInstruction
537
540
// assumes that such a situation means that fn is a declaration. Thus it
@@ -570,13 +573,14 @@ SILFunction *SILDeserializer::readSILFunction(DeclID FID,
570
573
}
571
574
572
575
SILBasicBlock *SILDeserializer::readSILBasicBlock (SILFunction *Fn,
576
+ SILBasicBlock *Prev,
573
577
SmallVectorImpl<uint64_t > &scratch) {
574
578
ArrayRef<uint64_t > Args;
575
579
SILBasicBlockLayout::readRecord (scratch, Args);
576
580
577
581
// Args should be a list of pairs, the first number is a TypeID, the
578
582
// second number is a ValueID.
579
- SILBasicBlock *CurrentBB = getBBForDefinition (Fn, BasicBlockID++);
583
+ SILBasicBlock *CurrentBB = getBBForDefinition (Fn, Prev, BasicBlockID++);
580
584
for (unsigned I = 0 , E = Args.size (); I < E; I += 3 ) {
581
585
TypeID TyID = Args[I];
582
586
if (!TyID) return nullptr ;
0 commit comments