Skip to content

Commit

Permalink
Move out-of-line instructions to warm cache
Browse files Browse the repository at this point in the history
- during code cache disclaim, it's beneficial to move
OOL code into warm code cache
  • Loading branch information
gita-omr committed Jul 27, 2024
1 parent 56cb81f commit 9a6d5fe
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
62 changes: 62 additions & 0 deletions compiler/x/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,9 @@ void OMR::X86::CodeGenerator::doRegisterAssignment(TR_RegisterKinds kindsToAssig

self()->doBackwardsRegisterAssignment(kindsToAssign, self()->getAppendInstruction());
}

if (TR::Options::getCmdLineOptions()->getOption(TR_EnableCodeCacheDisclaiming))
moveOutOfLineInstructionsToWarm();
}

bool OMR::X86::CodeGenerator::isReturnInstruction(TR::Instruction *instr)
Expand Down Expand Up @@ -3500,3 +3503,62 @@ OMR::X86::CodeGenerator::getOutOfLineCodeSize()

return totalSize;
}

void
OMR::X86::CodeGenerator::moveOutOfLineInstructionsToWarm()
{
// OOL instructions are already attached at the end of the IL (after cold instructions)
// and register allocated.
// Move them to immediately after the last warm instruction, unless they already happend to be
// there (e.g. there are no cold instructions)
//
if (self()->comp()->getOption(TR_TraceCG))
traceMsg(self()->comp(), "Moving OutOfLine instructions\n");

auto oiIterator = self()->getOutlinedInstructionsList().begin();

while (oiIterator != self()->getOutlinedInstructionsList().end())
{
TR::Instruction *firstInstruction = (*oiIterator)->getFirstInstruction();
TR::Instruction *lastInstruction = (*oiIterator)->getAppendInstruction();

TR_ASSERT_FATAL(firstInstruction, "VFPRestore instruciton should preceeed any OOL section\n");
TR_ASSERT_FATAL(self()->getLastWarmInstruction() != self()->getAppendInstruction(),
"Last warm instruction can't be append instruction since OOL code was attached already\n");

if (self()->getLastWarmInstruction() &&
self()->getLastWarmInstruction() != firstInstruction->getPrev())
{
TR::Instruction *appendInstruction;

// remove from prrevious location
if (firstInstruction->getPrev())
firstInstruction->getPrev()->setNext(lastInstruction->getNext());

if (lastInstruction->getNext())
lastInstruction->getNext()->setPrev(firstInstruction->getPrev());

// update codegen append instruction
if (lastInstruction == self()->getAppendInstruction())
self()->setAppendInstruction(firstInstruction->getPrev());

// insert after last warm instruction
appendInstruction = self()->getLastWarmInstruction();
appendInstruction->setLastWarmInstruction(false);
lastInstruction->setLastWarmInstruction(true);
self()->setLastWarmInstruction(lastInstruction);

TR::Instruction *followInstruction = appendInstruction->getNext();

appendInstruction->setNext(firstInstruction);
firstInstruction->setPrev(appendInstruction);

lastInstruction->setNext(followInstruction);

if (followInstruction)
followInstruction->setPrev(lastInstruction);
}

++oiIterator;
}
}
6 changes: 6 additions & 0 deletions compiler/x/codegen/OMRCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGenerator
bool considerTypeForGRA(TR::DataType dt);
bool considerTypeForGRA(TR::SymbolReference *symRef);

/*
* \brief move out-of-line instructions from cold code to warm
*
*/
void moveOutOfLineInstructionsToWarm();

uint32_t getOutOfLineCodeSize();

/*
Expand Down

0 comments on commit 9a6d5fe

Please sign in to comment.