Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
do not spill eeStack if the last opcode was ldtoken.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Andreenko committed Apr 9, 2017
1 parent 8391d4d commit b6d776e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,10 @@ class Compiler

//---------------- Spilling the importer stack ----------------------------

// The maximum tree size in the importer before it spills all trees from the stack into local variables.
const unsigned MAX_TREE_SIZE = 200;
bool impCanSpillNow(OPCODE prevOpcode);

struct PendingDsc
{
PendingDsc* pdNext;
Expand Down
21 changes: 20 additions & 1 deletion src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,25 @@ inline IL_OFFSETX Compiler::impCurILOffset(IL_OFFSET offs, bool callInstruction)
}
}

//------------------------------------------------------------------------
// impCanSpillNow: check is it possible to spill all values from eeStack to local variables.
//
// Arguments:
// prevOpcode - last importer opcode
//
// Return Value:
// true if it is legal, false if it could be a sequence that we do not want to divide.
bool Compiler::impCanSpillNow(OPCODE prevOpcode)
{
StackEntry& lastSE = impStackTop(0);
GenTreePtr tree = lastSE.val;
if (prevOpcode == CEE_LDTOKEN)
{
return false;
}
return true;
}

/*****************************************************************************
*
* Remember the instr offset for the statements
Expand Down Expand Up @@ -9545,7 +9564,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
/* Has it been a while since we last saw a non-empty stack (which
guarantees that the tree depth isnt accumulating. */

if ((opcodeOffs - lastSpillOffs) > 200)
if ((opcodeOffs - lastSpillOffs) > MAX_TREE_SIZE && impCanSpillNow(prevOpcode))
{
impSpillStackEnsure();
lastSpillOffs = opcodeOffs;
Expand Down

0 comments on commit b6d776e

Please sign in to comment.