Skip to content

Commit

Permalink
Merge pull request #7426 from gita-omr/ool_in_warm_pr
Browse files Browse the repository at this point in the history
Move out-of-line instructions to warm cache
  • Loading branch information
0xdaryl authored Aug 20, 2024
2 parents e0dde22 + f93c09f commit f2a5b8c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/control/OMROptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ TR::OptionTable OMR::Options::_jitOptions[] = {
TR::Options::setStaticNumeric, (intptr_t)&OMR::Options::_minProfiledCheckcastFrequency, 0, "F%d", NOT_IN_SUBSET},
{"minSleepTimeMsForCompThrottling=", "M<nnn>\tLower bound for sleep time during compilation throttling (ms)",
TR::Options::setStaticNumeric, (intptr_t)&OMR::Options::_minSleepTimeMsForCompThrottling, 0, "F%d", NOT_IN_SUBSET },
{"moveOOLInstructionsToWarmCode", "M\tmove out-of-line instructions to after last warm instruction", SET_OPTION_BIT(TR_MoveOOLInstructionsToWarmCode), "F"},
{"noAotSecondRunDetection", "M\tdo not do second run detection for AOT", SET_OPTION_BIT(TR_NoAotSecondRunDetection), "F", NOT_IN_SUBSET },
#ifdef DEBUG
{"noExceptions", "C\tfail compilation for methods with exceptions",
Expand Down
2 changes: 1 addition & 1 deletion compiler/control/OMROptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ enum TR_CompilationOptions
TR_BreakOnNew = 0x08000000 + 9,
TR_DisableInliningUnrecognizedIntrinsics = 0x10000000 + 9,
TR_EnableVectorAPIExpansion = 0x20000000 + 9,
// Available = 0x40000000 + 9,
TR_MoveOOLInstructionsToWarmCode = 0x40000000 + 9,
// Available = 0x80000000 + 9,

// Option word 10
Expand Down
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_MoveOOLInstructionsToWarmCode))
moveOutOfLineInstructionsToWarmCode();
}

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::moveOutOfLineInstructionsToWarmCode()
{
// 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 happened to be
// there (e.g. there are no cold instructions)
//
if (!self()->getLastWarmInstruction())
return;

if (self()->comp()->getOption(TR_TraceCG))
traceMsg(self()->comp(), "Moving OutOfLine instructions to after %p\n", self()->getLastWarmInstruction());

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

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

TR_ASSERT_FATAL(firstOLInstruction, "VFPRestore instruction 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() != firstOLInstruction->getPrev())
{
// remove from previous location
if (firstOLInstruction->getPrev())
firstOLInstruction->getPrev()->setNext(lastOLInstruction->getNext());

if (lastOLInstruction->getNext())
lastOLInstruction->getNext()->setPrev(firstOLInstruction->getPrev());

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

// insert after last warm instruction
TR::Instruction *mainlineAppendInstruction = self()->getLastWarmInstruction();
mainlineAppendInstruction->setLastWarmInstruction(false);
lastOLInstruction->setLastWarmInstruction(true);
self()->setLastWarmInstruction(lastOLInstruction);

TR::Instruction *mainlineFollowInstruction = mainlineAppendInstruction->getNext();

mainlineAppendInstruction->setNext(firstOLInstruction);
firstOLInstruction->setPrev(mainlineAppendInstruction);

lastOLInstruction->setNext(mainlineFollowInstruction);

if (mainlineFollowInstruction)
mainlineFollowInstruction->setPrev(lastOLInstruction);
}

++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 moveOutOfLineInstructionsToWarmCode();

uint32_t getOutOfLineCodeSize();

/*
Expand Down

0 comments on commit f2a5b8c

Please sign in to comment.