From 4905d63d9d03cc1b8b46f6830b50489ee93ce33f Mon Sep 17 00:00:00 2001 From: Sergey Andreenko Date: Mon, 15 Apr 2019 15:38:44 -0700 Subject: [PATCH] Fix lsraBlockEpoch check. --- src/jit/lsra.cpp | 24 +++++++++++++++++------- src/jit/lsra.h | 4 ++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/jit/lsra.cpp b/src/jit/lsra.cpp index 8a5323c..e672582 100644 --- a/src/jit/lsra.cpp +++ b/src/jit/lsra.cpp @@ -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()); } //------------------------------------------------------------------------ diff --git a/src/jit/lsra.h b/src/jit/lsra.h index e03b6f9..c5477bf 100644 --- a/src/jit/lsra.h +++ b/src/jit/lsra.h @@ -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(); -- 2.7.4