@@ -2828,7 +2828,7 @@ void Compiler::optCompactLoop(FlowGraphNaturalLoop* loop)
2828
2828
2829
2829
if (insertionPoint == nullptr )
2830
2830
{
2831
- insertionPoint = optFindLoopCompactionInsertionPoint ( loop, top );
2831
+ insertionPoint = loop-> GetLexicallyBottomMostBlock ( );
2832
2832
}
2833
2833
2834
2834
BasicBlock* previous = cur->Prev ();
@@ -2842,8 +2842,6 @@ void Compiler::optCompactLoop(FlowGraphNaturalLoop* loop)
2842
2842
}
2843
2843
2844
2844
// Now physically move the blocks.
2845
- BasicBlock* moveBefore = insertionPoint->Next ();
2846
-
2847
2845
fgUnlinkRange (cur, lastNonLoopBlock);
2848
2846
fgMoveBlocksAfter (cur, lastNonLoopBlock, insertionPoint);
2849
2847
ehUpdateLastBlocks (insertionPoint, lastNonLoopBlock);
@@ -2855,137 +2853,6 @@ void Compiler::optCompactLoop(FlowGraphNaturalLoop* loop)
2855
2853
}
2856
2854
}
2857
2855
2858
- // -----------------------------------------------------------------------------
2859
- // optFindLoopCompactionInsertionPoint: Find a good insertion point at which to
2860
- // move blocks from the lexical range of "loop" that is not part of the loop.
2861
- //
2862
- // Parameters:
2863
- // loop - The loop
2864
- // top - Lexical top block of the loop.
2865
- //
2866
- // Returns:
2867
- // Non-null insertion point.
2868
- //
2869
- BasicBlock* Compiler::optFindLoopCompactionInsertionPoint (FlowGraphNaturalLoop* loop, BasicBlock* top)
2870
- {
2871
- // Find an insertion point for blocks we're going to move. Move them down
2872
- // out of the loop, and if possible find a spot that won't break up fall-through.
2873
- BasicBlock* bottom = loop->GetLexicallyBottomMostBlock ();
2874
- BasicBlock* insertionPoint = bottom;
2875
- while (!insertionPoint->IsLast ())
2876
- {
2877
- switch (insertionPoint->GetKind ())
2878
- {
2879
- case BBJ_ALWAYS:
2880
- if (!insertionPoint->JumpsToNext ())
2881
- {
2882
- // Found a branch that isn't to the next block, so we won't split up any fall-through.
2883
- return insertionPoint;
2884
- }
2885
- break ;
2886
-
2887
- case BBJ_COND:
2888
- if (!insertionPoint->FalseTargetIs (insertionPoint->Next ()))
2889
- {
2890
- // Found a conditional branch that doesn't have a false branch to the next block,
2891
- // so we won't split up any fall-through.
2892
- return insertionPoint;
2893
- }
2894
- break ;
2895
-
2896
- case BBJ_CALLFINALLY:
2897
- if (!insertionPoint->isBBCallFinallyPair ())
2898
- {
2899
- // Found a retless BBJ_CALLFINALLY block, so we won't split up any fall-through.
2900
- return insertionPoint;
2901
- }
2902
- break ;
2903
-
2904
- default :
2905
- // No fall-through to split up.
2906
- return insertionPoint;
2907
- }
2908
-
2909
- // Keep looking for a better insertion point if we can.
2910
- BasicBlock* newInsertionPoint = optTryAdvanceLoopCompactionInsertionPoint (loop, insertionPoint, top, bottom);
2911
- if (newInsertionPoint == nullptr )
2912
- {
2913
- // Ran out of candidate insertion points, so just split up the fall-through.
2914
- break ;
2915
- }
2916
-
2917
- insertionPoint = newInsertionPoint;
2918
- }
2919
-
2920
- return insertionPoint;
2921
- }
2922
-
2923
- // -----------------------------------------------------------------------------
2924
- // optTryAdvanceLoopCompactionInsertionPoint: Advance the insertion point to
2925
- // avoid having to insert new blocks due to fallthrough.
2926
- //
2927
- // Parameters:
2928
- // loop - The loop
2929
- // insertionPoint - Current insertion point
2930
- // top - Lexical top block of the loop.
2931
- // bottom - Lexical bottom block of the loop.
2932
- //
2933
- // Returns:
2934
- // New insertion point.
2935
- //
2936
- BasicBlock* Compiler::optTryAdvanceLoopCompactionInsertionPoint (FlowGraphNaturalLoop* loop,
2937
- BasicBlock* insertionPoint,
2938
- BasicBlock* top,
2939
- BasicBlock* bottom)
2940
- {
2941
- BasicBlock* newInsertionPoint = insertionPoint->Next ();
2942
-
2943
- if (!BasicBlock::sameEHRegion (insertionPoint, newInsertionPoint))
2944
- {
2945
- // Don't cross an EH region boundary.
2946
- return nullptr ;
2947
- }
2948
-
2949
- // TODO-Quirk: Compatibility with old compaction
2950
- if (newInsertionPoint->KindIs (BBJ_ALWAYS, BBJ_COND))
2951
- {
2952
- BasicBlock* dest =
2953
- newInsertionPoint->KindIs (BBJ_ALWAYS) ? newInsertionPoint->GetTarget () : newInsertionPoint->GetTrueTarget ();
2954
- if ((dest->bbNum >= top->bbNum ) && (dest->bbNum <= bottom->bbNum ) && !loop->ContainsBlock (dest))
2955
- {
2956
- return nullptr ;
2957
- }
2958
- }
2959
-
2960
- // TODO-Quirk: Compatibility with old compaction
2961
- for (BasicBlock* const predBlock : newInsertionPoint->PredBlocks ())
2962
- {
2963
- if ((predBlock->bbNum >= top->bbNum ) && (predBlock->bbNum <= bottom->bbNum ) && !loop->ContainsBlock (predBlock))
2964
- {
2965
- // Don't make this forward edge a backwards edge.
2966
- return nullptr ;
2967
- }
2968
- }
2969
-
2970
- // Compaction runs on outer loops before inner loops. That means all
2971
- // unlexical blocks here are part of an ancestor loop (or trivial
2972
- // BBJ_ALWAYS exit blocks). To avoid breaking lexicality of ancestor loops
2973
- // we avoid moving any block past the bottom of an ancestor loop.
2974
- for (FlowGraphNaturalLoop* ancestor = loop->GetParent (); ancestor != nullptr ; ancestor = ancestor->GetParent ())
2975
- {
2976
- if (newInsertionPoint == ancestor->GetLexicallyBottomMostBlock ())
2977
- {
2978
- return nullptr ;
2979
- }
2980
- }
2981
-
2982
- // Advancing the insertion point is ok, except that we can't split up any call finally
2983
- // pair, so if we've got such a pair recurse to see if we can move past the whole thing.
2984
- return newInsertionPoint->isBBCallFinallyPair ()
2985
- ? optTryAdvanceLoopCompactionInsertionPoint (loop, newInsertionPoint, top, bottom)
2986
- : newInsertionPoint;
2987
- }
2988
-
2989
2856
// -----------------------------------------------------------------------------
2990
2857
// optCreatePreheader: Create (or find) a preheader for a natural loop.
2991
2858
//
0 commit comments