Skip to content

Commit

Permalink
Migrate DCB register allocation code to S390DebugCounterBumpInstruction
Browse files Browse the repository at this point in the history
The code which looks for a free real register to associate with the DCB
instruction can be migrated to the overloaded `assignRegisters` vritual
API.
  • Loading branch information
fjeremic committed Apr 30, 2021
1 parent 739caac commit 8c45dc1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
28 changes: 0 additions & 28 deletions compiler/z/codegen/OMRCodeGenerator.cpp
Expand Up @@ -1707,34 +1707,6 @@ OMR::Z::CodeGenerator::doRegisterAssignment(TR_RegisterKinds kindsToAssign)
{
TR::Node *treeNode=instructionCursor->getNode();

/**
* Find a free real register for DCB to use during generate binary encoding phase
* @see S390DebugCounterBumpInstruction::generateBinaryEncoding()
*/
if(instructionCursor->getOpCodeValue() == TR::InstOpCode::DCB)
{
TR::S390DebugCounterBumpInstruction *dcbInstr = static_cast<TR::S390DebugCounterBumpInstruction*>(instructionCursor);

int32_t first = TR::RealRegister::FirstGPR + 1; // skip GPR0
int32_t last = TR::RealRegister::LastAssignableGPR;

TR::RealRegister * realReg;

for (int32_t i=first; i<=last; i++)
{
realReg = self()->machine()->realRegister(static_cast<TR::RealRegister::RegNum>(i));

if ( realReg->getState() == TR::RealRegister::Free)
{
dcbInstr->setAssignableReg(realReg);
realReg->setHasBeenAssignedInMethod(true);
break;
}
}

self()->traceRegisterAssignment("BEST FREE REG for DCB is %R", dcbInstr->getAssignableReg());
}

self()->tracePreRAInstruction(instructionCursor);

prevInstruction = instructionCursor->getPrev();
Expand Down
19 changes: 19 additions & 0 deletions compiler/z/codegen/S390Instruction.cpp
Expand Up @@ -1028,6 +1028,25 @@ TR::S390PseudoInstruction::estimateBinaryLength(int32_t currentEstimate)
// TR::S390DebugCounterBumpInstruction:: member functions
////////////////////////////////////////////////////////////////////////////////

void
TR::S390DebugCounterBumpInstruction::assignRegisters(TR_RegisterKinds kindToBeAssigned)
{
// Find a free real register for DCB to use during binary encoding to avoid spilling scratch registers
for (auto i = TR::RealRegister::FirstGPR + 1; i <= TR::RealRegister::LastAssignableGPR; i++)
{
TR::RealRegister *realReg = cg()->machine()->realRegister(static_cast<TR::RealRegister::RegNum>(i));

if (realReg->getState() == TR::RealRegister::Free)
{
_assignableReg = realReg;
realReg->setHasBeenAssignedInMethod(true);
break;
}
}

assignRegistersAndDependencies(kindToBeAssigned);
}

/**
* This instruction is bumps the value at the snippet corresponding to the address of the debug counter count.
* The valid opcode is TR::InstOpCode::DCB
Expand Down
8 changes: 2 additions & 6 deletions compiler/z/codegen/S390Instruction.hpp
Expand Up @@ -680,12 +680,6 @@ class S390DebugCounterBumpInstruction : public S390PseudoInstruction
_assignableReg(NULL),
_delta(delta){}

/**
* A real register must only be assigned for DCB to use if it is guaranteed to be free at the cursor position where DCB is inserted
* @param ar Real Register to be assigned
*/
void setAssignableReg(TR::RealRegister * ar){ _assignableReg = ar; }

/**
* @return Assigned Real Register
*/
Expand All @@ -701,6 +695,8 @@ class S390DebugCounterBumpInstruction : public S390PseudoInstruction
*/
int32_t getDelta(){ return _delta; }

virtual void assignRegisters(TR_RegisterKinds kindToBeAssigned);

virtual uint8_t *generateBinaryEncoding();
};

Expand Down

0 comments on commit 8c45dc1

Please sign in to comment.