@@ -543,15 +543,13 @@ struct BasicBlock : private LIR::Range
543543 return bbJumpKind;
544544 }
545545
546- void SetJumpKind (BBjumpKinds jumpKind DEBUG_ARG (Compiler* compiler) )
546+ void ChangeJumpKind (BBjumpKinds jumpKind)
547547 {
548- #ifdef DEBUG
549- // BBJ_NONE should only be assigned when optimizing jumps in Compiler::optOptimizeLayout
550- // TODO: Change assert to check if compiler is in appropriate optimization phase to use BBJ_NONE
551- // (right now, this assertion does the null check to avoid unused variable warnings)
552- assert ((jumpKind != BBJ_NONE) || (compiler != nullptr ));
553- #endif // DEBUG
548+ // If this block's jump kind requires a target, ensure it is already set
549+ assert (HasJump () || !KindIs (BBJ_ALWAYS, BBJ_CALLFINALLY, BBJ_COND, BBJ_EHCATCHRET, BBJ_LEAVE));
554550 bbJumpKind = jumpKind;
551+ // If new jump kind requires a target, ensure a target is already set
552+ assert (HasJump () || !KindIs (BBJ_ALWAYS, BBJ_CALLFINALLY, BBJ_COND, BBJ_EHCATCHRET, BBJ_LEAVE));
555553 }
556554
557555 BasicBlock* Prev () const
@@ -611,54 +609,83 @@ struct BasicBlock : private LIR::Range
611609 return bbJumpOffs;
612610 }
613611
614- void SetJumpOffs ( unsigned jumpOffs)
612+ void SetJumpKindAndTarget (BBjumpKinds jumpKind, unsigned jumpOffs)
615613 {
614+ bbJumpKind = jumpKind;
616615 bbJumpOffs = jumpOffs;
616+ assert (KindIs (BBJ_ALWAYS, BBJ_COND, BBJ_LEAVE));
617617 }
618618
619619 BasicBlock* GetJumpDest () const
620620 {
621+ // If bbJumpKind indicates this block has a jump, bbJumpDest cannot be null
622+ assert (HasJump () || !KindIs (BBJ_ALWAYS, BBJ_CALLFINALLY, BBJ_COND, BBJ_EHCATCHRET, BBJ_LEAVE));
621623 return bbJumpDest;
622624 }
623625
624626 void SetJumpDest (BasicBlock* jumpDest)
625627 {
628+ // If bbJumpKind indicates this block has a jump,
629+ // bbJumpDest should have previously been set in SetJumpKindAndTarget().
630+ assert (HasJump () || !KindIs (BBJ_ALWAYS, BBJ_CALLFINALLY, BBJ_COND, BBJ_EHCATCHRET, BBJ_LEAVE));
631+
632+ // SetJumpKindAndTarget() nulls jumpDest for non-jump kinds,
633+ // so don't use SetJumpDest() to null bbJumpDest without updating bbJumpKind.
626634 bbJumpDest = jumpDest;
635+ assert (HasJump ());
627636 }
628637
629- void SetJumpKindAndTarget (BBjumpKinds jumpKind, BasicBlock* jumpDest)
638+ void SetJumpKindAndTarget (BBjumpKinds jumpKind, BasicBlock* jumpDest DEBUG_ARG (Compiler* compiler) )
630639 {
631- assert (jumpDest != nullptr );
640+ #ifdef DEBUG
641+ // BBJ_NONE should only be assigned when optimizing jumps in Compiler::optOptimizeLayout
642+ // TODO: Change assert to check if compiler is in appropriate optimization phase to use BBJ_NONE
643+ //
644+ // (right now, this assertion does the null check to avoid unused variable warnings)
645+ assert ((jumpKind != BBJ_NONE) || (compiler != nullptr ));
646+ #endif // DEBUG
647+
632648 bbJumpKind = jumpKind;
633649 bbJumpDest = jumpDest;
634- assert (KindIs (BBJ_ALWAYS, BBJ_CALLFINALLY, BBJ_COND, BBJ_EHCATCHRET, BBJ_LEAVE));
650+
651+ // If bbJumpKind indicates this block has a jump, bbJumpDest cannot be null
652+ assert (HasJump () || !KindIs (BBJ_ALWAYS, BBJ_CALLFINALLY, BBJ_COND, BBJ_EHCATCHRET, BBJ_LEAVE));
653+ }
654+
655+ void SetJumpKindAndTarget (BBjumpKinds jumpKind DEBUG_ARG (Compiler* compiler))
656+ {
657+ SetJumpKindAndTarget (jumpKind, nullptr DEBUG_ARG (compiler));
658+ }
659+
660+ bool HasJump () const
661+ {
662+ return (bbJumpDest != nullptr );
635663 }
636664
637665 bool HasJumpTo (const BasicBlock* jumpDest) const
638666 {
667+ assert (HasJump ());
668+ assert (!KindIs (BBJ_SWITCH, BBJ_EHFINALLYRET));
639669 return (bbJumpDest == jumpDest);
640670 }
641671
642672 bool JumpsToNext () const
643673 {
674+ assert (HasJump ());
644675 return (bbJumpDest == bbNext);
645676 }
646677
647678 BBswtDesc* GetJumpSwt () const
648679 {
680+ assert (KindIs (BBJ_SWITCH));
681+ assert (bbJumpSwt != nullptr );
649682 return bbJumpSwt;
650683 }
651684
652- void SetJumpSwt (BBswtDesc* jumpSwt)
653- {
654- bbJumpSwt = jumpSwt;
655- }
656-
657- void SetJumpKindAndTarget (BBjumpKinds jumpKind, BBswtDesc* jumpSwt)
685+ void SetSwitchKindAndTarget (BBswtDesc* jumpSwt)
658686 {
659- assert (jumpKind == BBJ_SWITCH);
660687 assert (jumpSwt != nullptr );
661- bbJumpKind = jumpKind ;
688+ bbJumpKind = BBJ_SWITCH ;
662689 bbJumpSwt = jumpSwt;
663690 }
664691
@@ -1747,7 +1774,7 @@ inline BBArrayIterator BBEhfSuccList::end() const
17471774inline BasicBlock::BBSuccList::BBSuccList (const BasicBlock* block)
17481775{
17491776 assert (block != nullptr );
1750- switch (block->GetJumpKind () )
1777+ switch (block->bbJumpKind )
17511778 {
17521779 case BBJ_THROW:
17531780 case BBJ_RETURN:
@@ -1763,19 +1790,19 @@ inline BasicBlock::BBSuccList::BBSuccList(const BasicBlock* block)
17631790 case BBJ_ALWAYS:
17641791 case BBJ_EHCATCHRET:
17651792 case BBJ_LEAVE:
1766- m_succs[0 ] = block->GetJumpDest () ;
1793+ m_succs[0 ] = block->bbJumpDest ;
17671794 m_begin = &m_succs[0 ];
17681795 m_end = &m_succs[1 ];
17691796 break ;
17701797
17711798 case BBJ_NONE:
1772- m_succs[0 ] = block->Next () ;
1799+ m_succs[0 ] = block->bbNext ;
17731800 m_begin = &m_succs[0 ];
17741801 m_end = &m_succs[1 ];
17751802 break ;
17761803
17771804 case BBJ_COND:
1778- m_succs[0 ] = block->Next () ;
1805+ m_succs[0 ] = block->bbNext ;
17791806 m_begin = &m_succs[0 ];
17801807
17811808 // If both fall-through and branch successors are identical, then only include
@@ -1786,17 +1813,17 @@ inline BasicBlock::BBSuccList::BBSuccList(const BasicBlock* block)
17861813 }
17871814 else
17881815 {
1789- m_succs[1 ] = block->GetJumpDest () ;
1816+ m_succs[1 ] = block->bbJumpDest ;
17901817 m_end = &m_succs[2 ];
17911818 }
17921819 break ;
17931820
17941821 case BBJ_SWITCH:
17951822 // We don't use the m_succs in-line data for switches; use the existing jump table in the block.
1796- assert (block->GetJumpSwt () != nullptr );
1797- assert (block->GetJumpSwt () ->bbsDstTab != nullptr );
1798- m_begin = block->GetJumpSwt () ->bbsDstTab ;
1799- m_end = block->GetJumpSwt () ->bbsDstTab + block->GetJumpSwt () ->bbsCount ;
1823+ assert (block->bbJumpSwt != nullptr );
1824+ assert (block->bbJumpSwt ->bbsDstTab != nullptr );
1825+ m_begin = block->bbJumpSwt ->bbsDstTab ;
1826+ m_end = block->bbJumpSwt ->bbsDstTab + block->bbJumpSwt ->bbsCount ;
18001827 break ;
18011828
18021829 default :
0 commit comments