Fix lsraBlockEpoch check.
authorSergey Andreenko <seandree@microsoft.com>
Mon, 15 Apr 2019 22:38:44 +0000 (15:38 -0700)
committerSergey Andreenko <seandree@microsoft.com>
Tue, 16 Apr 2019 00:34:02 +0000 (17:34 -0700)
src/jit/lsra.cpp
src/jit/lsra.h

index 8a5323c..e672582 100644 (file)
@@ -740,7 +740,7 @@ BasicBlock* LinearScan::getNextCandidateFromWorkList()
 }
 
 //------------------------------------------------------------------------
-// setBlockSequence:Determine the block order for register allocation.
+// setBlockSequence: Determine the block order for register allocation.
 //
 // Arguments:
 //    None
@@ -756,9 +756,16 @@ BasicBlock* LinearScan::getNextCandidateFromWorkList()
 
 void LinearScan::setBlockSequence()
 {
-    // Reset the "visited" flag on each block.
+    assert(!blockSequencingDone); // The method should be called only once.
+
     compiler->EnsureBasicBlockEpoch();
+#ifdef DEBUG
+    blockEpoch = compiler->GetCurBasicBlockEpoch();
+#endif // DEBUG
+
+    // Initialize the "visited" blocks set.
     bbVisitedSet = BlockSetOps::MakeEmpty(compiler);
+
     BlockSet readySet(BlockSetOps::MakeEmpty(compiler));
     BlockSet predSet(BlockSetOps::MakeEmpty(compiler));
 
@@ -1094,10 +1101,14 @@ BasicBlock* LinearScan::startBlockSequence()
     {
         setBlockSequence();
     }
+    else
+    {
+        clearVisitedBlocks();
+    }
+
     BasicBlock* curBB = compiler->fgFirstBB;
     curBBSeqNum       = 0;
     curBBNum          = curBB->bbNum;
-    clearVisitedBlocks();
     assert(blockSequence[0] == compiler->fgFirstBB);
     markBlockVisited(curBB);
     return curBB;
@@ -1172,8 +1183,6 @@ void LinearScan::doLinearScan()
         enregisterLocalVars = false;
     }
 
-    unsigned lsraBlockEpoch = compiler->GetCurBasicBlockEpoch();
-
     splitBBNumToTargetBBNumMap = nullptr;
 
     // This is complicated by the fact that physical registers have refs associated
@@ -1189,7 +1198,6 @@ void LinearScan::doLinearScan()
 
     DBEXEC(VERBOSE, lsraDumpIntervals("after buildIntervals"));
 
-    clearVisitedBlocks();
     initVarRegMaps();
     allocateRegisters();
     allocationPassComplete = true;
@@ -1197,6 +1205,9 @@ void LinearScan::doLinearScan()
     resolveRegisters();
     compiler->EndPhase(PHASE_LINEAR_SCAN_RESOLVE);
 
+    assert(blockSequencingDone); // Should do at least one traversal.
+    assert(blockEpoch == compiler->GetCurBasicBlockEpoch());
+
 #if TRACK_LSRA_STATS
     if ((JitConfig.DisplayLsraStats() != 0)
 #ifdef DEBUG
@@ -1211,7 +1222,6 @@ void LinearScan::doLinearScan()
     DBEXEC(VERBOSE, TupleStyleDump(LSRA_DUMP_POST));
 
     compiler->compLSRADone = true;
-    noway_assert(lsraBlockEpoch = compiler->GetCurBasicBlockEpoch());
 }
 
 //------------------------------------------------------------------------
index e03b6f9..c5477bf 100644 (file)
@@ -1397,6 +1397,10 @@ private:
     int compareBlocksForSequencing(BasicBlock* block1, BasicBlock* block2, bool useBlockWeights);
     BasicBlockList* blockSequenceWorkList;
     bool            blockSequencingDone;
+#ifdef DEBUG
+    // LSRA must not change number of blocks and blockEpoch that it initializes at start.
+    unsigned blockEpoch;
+#endif // DEBUG
     void addToBlockSequenceWorkList(BlockSet sequencedBlockSet, BasicBlock* block, BlockSet& predSet);
     void removeFromBlockSequenceWorkList(BasicBlockList* listNode, BasicBlockList* prevNode);
     BasicBlock* getNextCandidateFromWorkList();