@@ -4761,9 +4761,7 @@ BasicBlock* Compiler::fgSplitBlockAtEnd(BasicBlock* curr)
47614761{
47624762 // We'd like to use fgNewBBafter(), but we need to update the preds list before linking in the new block.
47634763 // (We need the successors of 'curr' to be correct when we do this.)
4764- BasicBlock* newBlock;
4765-
4766- newBlock = BasicBlock::New (this );
4764+ BasicBlock* newBlock = BasicBlock::New (this );
47674765
47684766 // Start the new block with no refs. When we set the preds below, this will get updated correctly.
47694767 newBlock->bbRefs = 0 ;
@@ -4789,10 +4787,6 @@ BasicBlock* Compiler::fgSplitBlockAtEnd(BasicBlock* curr)
47894787 }
47904788 }
47914789
4792- // Transfer the kind and target. Do this after the code above, to avoid null-ing out the old targets used by the
4793- // above code.
4794- newBlock->TransferTarget (curr);
4795-
47964790 newBlock->inheritWeight (curr);
47974791
47984792 // Set the new block's flags. Note that the new block isn't BBF_INTERNAL unless the old block is.
@@ -4821,6 +4815,11 @@ BasicBlock* Compiler::fgSplitBlockAtEnd(BasicBlock* curr)
48214815 // Remove flags from the old block that are no longer possible.
48224816 curr->RemoveFlags (BBF_HAS_JMP | BBF_RETLESS_CALL);
48234817
4818+ // Transfer the kind and target. Do this after the code above, to avoid null-ing out the old targets used by the
4819+ // above code (and so newBlock->bbNext is valid, so SetCond() can initialize bbFalseTarget if newBlock is a
4820+ // BBJ_COND).
4821+ newBlock->TransferTarget (curr);
4822+
48244823 // Default to fallthrough, and add the arc for that.
48254824 curr->SetKindAndTarget (BBJ_ALWAYS, newBlock);
48264825 curr->SetFlags (BBF_NONE_QUIRK);
@@ -5080,6 +5079,7 @@ BasicBlock* Compiler::fgSplitEdge(BasicBlock* curr, BasicBlock* succ)
50805079
50815080 if (curr->KindIs (BBJ_COND))
50825081 {
5082+ curr->SetFalseTarget (curr->Next ());
50835083 fgReplacePred (succ, curr, newBlock);
50845084 if (curr->TrueTargetIs (succ))
50855085 {
@@ -5455,6 +5455,8 @@ BasicBlock* Compiler::fgRemoveBlock(BasicBlock* block, bool unreachable)
54555455 break ;
54565456
54575457 case BBJ_COND:
5458+ bPrev->SetFalseTarget (block->Next ());
5459+
54585460 /* Check if both sides of the BBJ_COND now jump to the same block */
54595461 if (bPrev->TrueTargetIs (bPrev->GetFalseTarget ()))
54605462 {
@@ -5514,7 +5516,7 @@ void Compiler::fgPrepareCallFinallyRetForRemoval(BasicBlock* block)
55145516// fgConnectFallThrough: fix flow from a block that previously had a fall through
55155517//
55165518// Arguments:
5517- // bSrc - source of fall through (may be null?)
5519+ // bSrc - source of fall through
55185520// bDst - target of fall through
55195521//
55205522// Returns:
@@ -5523,87 +5525,77 @@ void Compiler::fgPrepareCallFinallyRetForRemoval(BasicBlock* block)
55235525//
55245526BasicBlock* Compiler::fgConnectFallThrough (BasicBlock* bSrc, BasicBlock* bDst)
55255527{
5528+ assert (bSrc != nullptr );
55265529 assert (fgPredsComputed);
55275530 BasicBlock* jmpBlk = nullptr ;
55285531
5529- /* If bSrc is non-NULL */
5532+ /* If bSrc falls through to a block that is not bDst, we will insert a jump to bDst */
55305533
5531- if (bSrc != nullptr )
5534+ if (bSrc-> KindIs (BBJ_COND) && !bSrc-> NextIs (bDst) )
55325535 {
5533- /* If bSrc falls through to a block that is not bDst, we will insert a jump to bDst */
5534-
5535- if (bSrc->bbFallsThrough () && !bSrc->NextIs (bDst))
5536- {
5537- switch (bSrc->GetKind ())
5538- {
5539- case BBJ_CALLFINALLY:
5540- case BBJ_COND:
5536+ // Add a new block after bSrc which jumps to 'bDst'
5537+ jmpBlk = fgNewBBafter (BBJ_ALWAYS, bSrc, true , bDst);
5538+ bSrc->SetFalseTarget (jmpBlk);
5539+ fgAddRefPred (jmpBlk, bSrc, fgGetPredForBlock (bDst, bSrc));
55415540
5542- // Add a new block after bSrc which jumps to 'bDst'
5543- jmpBlk = fgNewBBafter (BBJ_ALWAYS, bSrc, true , bDst);
5544- fgAddRefPred (jmpBlk, bSrc, fgGetPredForBlock (bDst, bSrc));
5541+ // Record the loop number in the new block
5542+ jmpBlk->bbNatLoopNum = bSrc->bbNatLoopNum ;
55455543
5546- // Record the loop number in the new block
5547- jmpBlk->bbNatLoopNum = bSrc->bbNatLoopNum ;
5548-
5549- // When adding a new jmpBlk we will set the bbWeight and bbFlags
5550- //
5551- if (fgHaveValidEdgeWeights && fgHaveProfileWeights ())
5552- {
5553- FlowEdge* const newEdge = fgGetPredForBlock (jmpBlk, bSrc);
5554-
5555- jmpBlk->bbWeight = (newEdge->edgeWeightMin () + newEdge->edgeWeightMax ()) / 2 ;
5556- if (bSrc->bbWeight == BB_ZERO_WEIGHT)
5557- {
5558- jmpBlk->bbWeight = BB_ZERO_WEIGHT;
5559- }
5560-
5561- if (jmpBlk->bbWeight == BB_ZERO_WEIGHT)
5562- {
5563- jmpBlk->SetFlags (BBF_RUN_RARELY);
5564- }
5565-
5566- weight_t weightDiff = (newEdge->edgeWeightMax () - newEdge->edgeWeightMin ());
5567- weight_t slop = BasicBlock::GetSlopFraction (bSrc, bDst);
5568- //
5569- // If the [min/max] values for our edge weight is within the slop factor
5570- // then we will set the BBF_PROF_WEIGHT flag for the block
5571- //
5572- if (weightDiff <= slop)
5573- {
5574- jmpBlk->SetFlags (BBF_PROF_WEIGHT);
5575- }
5576- }
5577- else
5578- {
5579- // We set the bbWeight to the smaller of bSrc->bbWeight or bDst->bbWeight
5580- if (bSrc->bbWeight < bDst->bbWeight )
5581- {
5582- jmpBlk->bbWeight = bSrc->bbWeight ;
5583- jmpBlk->CopyFlags (bSrc, BBF_RUN_RARELY);
5584- }
5585- else
5586- {
5587- jmpBlk->bbWeight = bDst->bbWeight ;
5588- jmpBlk->CopyFlags (bDst, BBF_RUN_RARELY);
5589- }
5590- }
5544+ // When adding a new jmpBlk we will set the bbWeight and bbFlags
5545+ //
5546+ if (fgHaveValidEdgeWeights && fgHaveProfileWeights ())
5547+ {
5548+ FlowEdge* const newEdge = fgGetPredForBlock (jmpBlk, bSrc);
55915549
5592- fgReplacePred (bDst, bSrc, jmpBlk);
5550+ jmpBlk->bbWeight = (newEdge->edgeWeightMin () + newEdge->edgeWeightMax ()) / 2 ;
5551+ if (bSrc->bbWeight == BB_ZERO_WEIGHT)
5552+ {
5553+ jmpBlk->bbWeight = BB_ZERO_WEIGHT;
5554+ }
55935555
5594- JITDUMP (" Added an unconditional jump to " FMT_BB " after block " FMT_BB " \n " ,
5595- jmpBlk->GetTarget ()->bbNum , bSrc->bbNum );
5596- break ;
5556+ if (jmpBlk->bbWeight == BB_ZERO_WEIGHT)
5557+ {
5558+ jmpBlk->SetFlags (BBF_RUN_RARELY);
5559+ }
55975560
5598- default :
5599- noway_assert (!" Unexpected bbKind" );
5600- break ;
5561+ weight_t weightDiff = (newEdge->edgeWeightMax () - newEdge->edgeWeightMin ());
5562+ weight_t slop = BasicBlock::GetSlopFraction (bSrc, bDst);
5563+ //
5564+ // If the [min/max] values for our edge weight is within the slop factor
5565+ // then we will set the BBF_PROF_WEIGHT flag for the block
5566+ //
5567+ if (weightDiff <= slop)
5568+ {
5569+ jmpBlk->SetFlags (BBF_PROF_WEIGHT);
56015570 }
56025571 }
5603- else if (bSrc-> KindIs (BBJ_ALWAYS) && bSrc-> HasInitializedTarget () && bSrc-> JumpsToNext ())
5572+ else
56045573 {
5605- bSrc->SetFlags (BBF_NONE_QUIRK);
5574+ // We set the bbWeight to the smaller of bSrc->bbWeight or bDst->bbWeight
5575+ if (bSrc->bbWeight < bDst->bbWeight )
5576+ {
5577+ jmpBlk->bbWeight = bSrc->bbWeight ;
5578+ jmpBlk->CopyFlags (bSrc, BBF_RUN_RARELY);
5579+ }
5580+ else
5581+ {
5582+ jmpBlk->bbWeight = bDst->bbWeight ;
5583+ jmpBlk->CopyFlags (bDst, BBF_RUN_RARELY);
5584+ }
56065585 }
5586+
5587+ fgReplacePred (bDst, bSrc, jmpBlk);
5588+
5589+ JITDUMP (" Added an unconditional jump to " FMT_BB " after block " FMT_BB " \n " , jmpBlk->GetTarget ()->bbNum ,
5590+ bSrc->bbNum );
5591+ }
5592+ else if (bSrc->KindIs (BBJ_ALWAYS) && bSrc->HasInitializedTarget () && bSrc->JumpsToNext ())
5593+ {
5594+ bSrc->SetFlags (BBF_NONE_QUIRK);
5595+ }
5596+ else if (bSrc->KindIs (BBJ_COND) && bSrc->NextIs (bDst))
5597+ {
5598+ bSrc->SetFalseTarget (bDst);
56075599 }
56085600
56095601 return jmpBlk;
0 commit comments