@@ -4931,7 +4931,6 @@ Compiler::ThreeOptLayout::ThreeOptLayout(Compiler* comp)
4931
4931
, blockOrder(nullptr )
4932
4932
, tempOrder(nullptr )
4933
4933
, numCandidateBlocks(0 )
4934
- , currEHRegion(0 )
4935
4934
{
4936
4935
}
4937
4936
@@ -5125,7 +5124,7 @@ void Compiler::ThreeOptLayout::ConsiderEdge(FlowEdge* edge)
5125
5124
BasicBlock* const dstBlk = edge->getDestinationBlock ();
5126
5125
5127
5126
// Ignore cross-region branches
5128
- if ((srcBlk-> bbTryIndex != currEHRegion) || ( dstBlk-> bbTryIndex != currEHRegion ))
5127
+ if (! BasicBlock::sameTryRegion (srcBlk, dstBlk))
5129
5128
{
5130
5129
return ;
5131
5130
}
@@ -5224,8 +5223,7 @@ void Compiler::ThreeOptLayout::AddNonFallthroughPreds(unsigned blockPos)
5224
5223
}
5225
5224
5226
5225
// -----------------------------------------------------------------------------
5227
- // Compiler::ThreeOptLayout::Run: Runs 3-opt for each contiguous region of the block list
5228
- // we're interested in reordering.
5226
+ // Compiler::ThreeOptLayout::Run: Runs 3-opt on the candidate span of hot blocks.
5229
5227
// We skip reordering handler regions for now, as these are assumed to be cold.
5230
5228
//
5231
5229
void Compiler::ThreeOptLayout::Run ()
@@ -5271,41 +5269,9 @@ void Compiler::ThreeOptLayout::Run()
5271
5269
5272
5270
// Repurpose 'bbPostorderNum' for the block's ordinal
5273
5271
block->bbPostorderNum = numCandidateBlocks++;
5274
-
5275
- // While walking the span of blocks to reorder,
5276
- // remember where each try region ends within this span.
5277
- // We'll use this information to run 3-opt per region.
5278
- EHblkDsc* const HBtab = compiler->ehGetBlockTryDsc (block);
5279
- if (HBtab != nullptr )
5280
- {
5281
- HBtab->ebdTryLast = block;
5282
- }
5283
- }
5284
-
5285
- // Reorder try regions first
5286
- bool modified = false ;
5287
- for (EHblkDsc* const HBtab : EHClauses (compiler))
5288
- {
5289
- // If multiple region indices map to the same region,
5290
- // make sure we reorder its blocks only once
5291
- BasicBlock* const tryBeg = HBtab->ebdTryBeg ;
5292
- if (tryBeg->getTryIndex () != currEHRegion++)
5293
- {
5294
- continue ;
5295
- }
5296
-
5297
- // Only reorder try regions within the candidate span of blocks
5298
- if ((tryBeg->bbPostorderNum < numCandidateBlocks) && (blockOrder[tryBeg->bbPostorderNum ] == tryBeg))
5299
- {
5300
- JITDUMP (" Running 3-opt for try region #%d\n " , (currEHRegion - 1 ));
5301
- modified |= RunThreeOptPass (tryBeg, HBtab->ebdTryLast );
5302
- }
5303
5272
}
5304
5273
5305
- // Finally, reorder the main method body
5306
- currEHRegion = 0 ;
5307
- JITDUMP (" Running 3-opt for main method body\n " );
5308
- modified |= RunThreeOptPass (compiler->fgFirstBB , blockOrder[numCandidateBlocks - 1 ]);
5274
+ const bool modified = RunThreeOptPass ();
5309
5275
5310
5276
if (modified)
5311
5277
{
@@ -5314,14 +5280,25 @@ void Compiler::ThreeOptLayout::Run()
5314
5280
BasicBlock* const block = blockOrder[i - 1 ];
5315
5281
BasicBlock* const next = blockOrder[i];
5316
5282
5283
+ if (block->NextIs (next))
5284
+ {
5285
+ continue ;
5286
+ }
5287
+
5317
5288
// Only reorder within EH regions to maintain contiguity.
5318
- // TODO: Allow moving blocks in different regions when 'next' is the region entry.
5319
- // This would allow us to move entire regions up/down because of the contiguity requirement.
5320
- if (!block->NextIs (next) && BasicBlock::sameEHRegion (block, next))
5289
+ if (!BasicBlock::sameEHRegion (block, next))
5290
+ {
5291
+ continue ;
5292
+ }
5293
+
5294
+ // Don't move the entry of an EH region.
5295
+ if (compiler->bbIsTryBeg (next) || compiler->bbIsHandlerBeg (next))
5321
5296
{
5322
- compiler->fgUnlinkBlock (next);
5323
- compiler->fgInsertBBafter (block, next);
5297
+ continue ;
5324
5298
}
5299
+
5300
+ compiler->fgUnlinkBlock (next);
5301
+ compiler->fgInsertBBafter (block, next);
5325
5302
}
5326
5303
}
5327
5304
}
@@ -5466,12 +5443,6 @@ bool Compiler::ThreeOptLayout::RunGreedyThreeOptPass(unsigned startPos, unsigned
5466
5443
continue ;
5467
5444
}
5468
5445
5469
- // Don't consider any cut points that would disturb other EH regions
5470
- if (!BasicBlock::sameEHRegion (s2Block, s3Block))
5471
- {
5472
- continue ;
5473
- }
5474
-
5475
5446
// Compute the cost delta of this partition
5476
5447
const weight_t currCost = currCostBase + GetCost (s3BlockPrev, s3Block);
5477
5448
const weight_t newCost =
@@ -5529,22 +5500,15 @@ bool Compiler::ThreeOptLayout::RunGreedyThreeOptPass(unsigned startPos, unsigned
5529
5500
}
5530
5501
5531
5502
// -----------------------------------------------------------------------------
5532
- // Compiler::ThreeOptLayout::RunThreeOptPass: Runs 3-opt for the given block range.
5533
- //
5534
- // Parameters:
5535
- // startBlock - The first block of the range to reorder
5536
- // endBlock - The last block (inclusive) of the range to reorder
5503
+ // Compiler::ThreeOptLayout::RunThreeOptPass: Runs 3-opt on the candidate span of blocks.
5537
5504
//
5538
5505
// Returns:
5539
5506
// True if we reordered anything, false otherwise
5540
5507
//
5541
- bool Compiler::ThreeOptLayout::RunThreeOptPass (BasicBlock* startBlock, BasicBlock* endBlock )
5508
+ bool Compiler::ThreeOptLayout::RunThreeOptPass ()
5542
5509
{
5543
- assert (startBlock != nullptr );
5544
- assert (endBlock != nullptr );
5545
-
5546
- const unsigned startPos = startBlock->bbPostorderNum ;
5547
- const unsigned endPos = endBlock->bbPostorderNum ;
5510
+ const unsigned startPos = 0 ;
5511
+ const unsigned endPos = numCandidateBlocks - 1 ;
5548
5512
const unsigned numBlocks = (endPos - startPos + 1 );
5549
5513
assert (startPos <= endPos);
5550
5514
0 commit comments