Skip to content

Commit

Permalink
Misc. Power linkage cleanup (eclipse-omr#3868)
Browse files Browse the repository at this point in the history
Misc. Power linkage cleanup
  • Loading branch information
fjeremic authored May 22, 2019
2 parents f96391d + 90fcb83 commit c910b33
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 122 deletions.
156 changes: 90 additions & 66 deletions compiler/p/codegen/OMRLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ TR::Instruction *OMR::Power::Linkage::saveArguments(TR::Instruction *cursor, boo
int32_t busyMoves[3][64];
int32_t busyIndex = 0, i1;


bool all_saved = false;

// the freeScratchable structure will not be used when saveOnly == true
// no additional conditions were added with the intention of keeping the code easier to read
// and not full of if conditions
Expand All @@ -136,26 +133,27 @@ TR::Instruction *OMR::Power::Linkage::saveArguments(TR::Instruction *cursor, boo
for (paramCursor=paramIterator.getFirst(); paramCursor!=NULL; paramCursor=paramIterator.getNext())
{
int32_t lri = paramCursor->getLinkageRegisterIndex();
TR::DataType type = paramCursor->getType();

if (lri >= 0)
{
TR::DataType type = paramCursor->getType();
TR::RealRegister::RegNum regNum;
bool twoRegs = (TR::Compiler->target.is32Bit() && type.isInt64() && lri < properties.getNumIntArgRegs()-1);

if (!type.isFloatingPoint())
{
regNum = properties.getIntegerArgumentRegister(lri);
if (paramCursor->isReferencedParameter()) freeScratchable.reset(regNum);
if (twoRegs)
if (paramCursor->isReferencedParameter()) freeScratchable.reset(regNum+1);
}
else
{
regNum = properties.getFloatArgumentRegister(lri);
if (paramCursor->isReferencedParameter()) freeScratchable.reset(regNum);
}

if (paramCursor->isReferencedParameter())
{
freeScratchable.reset(regNum);
if (twoRegs)
if (paramCursor->isReferencedParameter()) freeScratchable.reset(regNum+1);
freeScratchable.reset(regNum+1);
}
}
}
Expand All @@ -164,7 +162,7 @@ TR::Instruction *OMR::Power::Linkage::saveArguments(TR::Instruction *cursor, boo
{
int32_t lri = paramCursor->getLinkageRegisterIndex();
int32_t ai = paramCursor->getAllocatedIndex();
int32_t offset = self()->calculateParameterRegisterOffset(paramCursor->getParameterOffset(), *paramCursor);
int32_t offset = paramCursor->getParameterOffset();
TR::DataType type = paramCursor->getType();
int32_t dtype = type.getDataType();

Expand All @@ -186,50 +184,56 @@ TR::Instruction *OMR::Power::Linkage::saveArguments(TR::Instruction *cursor, boo
// If not in Full Speed Debug, the arguments will be saved.
if (((ai<0 || self()->hasToBeOnStack(paramCursor)) && !fsd) || (fsd && saveOnly))
{
TR::InstOpCode::Mnemonic op = TR::InstOpCode::bad;
int32_t length = 0;

switch (dtype)
{
case TR::Int8:
case TR::Int16:
case TR::Int32:
{
TR::InstOpCode::Mnemonic op = TR::InstOpCode::stw;
if (!all_saved) cursor = generateMemSrc1Instruction(self()->cg(), op, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, 4, self()->cg()), REAL_REGISTER(regNum), cursor);
}
op = TR::InstOpCode::stw;
length = 4;
break;

case TR::Address:
if (!all_saved) cursor = generateMemSrc1Instruction(self()->cg(),TR::InstOpCode::Op_st, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, TR::Compiler->om.sizeofReferenceAddress(), self()->cg()), REAL_REGISTER(regNum), cursor);
break;
case TR::Int64:
if (!all_saved) cursor = generateMemSrc1Instruction(self()->cg(),TR::InstOpCode::Op_st, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, TR::Compiler->om.sizeofReferenceAddress(), self()->cg()), REAL_REGISTER(regNum), cursor);
if (twoRegs)
{
if (!all_saved) cursor = generateMemSrc1Instruction(self()->cg(), TR::InstOpCode::stw, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset+4, 4, self()->cg()),
REAL_REGISTER(REGNUM(regNum+1)), cursor);
if (ai<0)
freeScratchable.set(regNum+1);
}
op = TR::InstOpCode::Op_st;
length = TR::Compiler->om.sizeofReferenceAddress();
break;

case TR::Float:
cursor = generateMemSrc1Instruction(self()->cg(), TR::InstOpCode::stfs, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, 4, self()->cg()),
REAL_REGISTER(regNum), cursor);
op = TR::InstOpCode::stfs;
length = 4;
break;

case TR::Double:
cursor = generateMemSrc1Instruction(self()->cg(), TR::InstOpCode::stfd, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, 8, self()->cg()),
REAL_REGISTER(regNum), cursor);
op = TR::InstOpCode::stfd;
length = 8;
break;

default:
TR_ASSERT(false, "assertion failure");
break;
}

cursor = generateMemSrc1Instruction(self()->cg(), op, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, length, self()->cg()),
REAL_REGISTER(regNum),
cursor);

if (twoRegs)
{
cursor = generateMemSrc1Instruction(self()->cg(), TR::InstOpCode::stw, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset+4, 4, self()->cg()),
REAL_REGISTER(REGNUM(regNum+1)),
cursor);
if (ai<0)
freeScratchable.set(regNum);
freeScratchable.set(regNum+1);
}

if (ai<0)
freeScratchable.set(regNum);
}

// Global register is allocated to this argument.
Expand Down Expand Up @@ -439,6 +443,9 @@ TR::Instruction *OMR::Power::Linkage::saveArguments(TR::Instruction *cursor, boo
int32_t target = busyMoves[1][i1];
if (!(target<0) && freeScratchable.isSet(target))
{
TR::InstOpCode::Mnemonic op = TR::InstOpCode::bad;
int32_t length = 0;

switch(busyMoves[2][i1])
{
case 0:
Expand All @@ -447,23 +454,31 @@ TR::Instruction *OMR::Power::Linkage::saveArguments(TR::Instruction *cursor, boo
freeScratchable.set(source);
break;
case 1:
cursor = generateTrg1MemInstruction(self()->cg(), TR::InstOpCode::lwz, firstNode, REAL_REGISTER(REGNUM(target)),
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, source, 4, self()->cg()), cursor);
op = TR::InstOpCode::lwz;
length = 4;
break;
case 2:
cursor = generateTrg1MemInstruction(self()->cg(), TR::InstOpCode::ld, firstNode, REAL_REGISTER(REGNUM(target)),
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, source, 8, self()->cg()), cursor);
op = TR::InstOpCode::ld;
length = 8;
break;
case 3:
cursor = generateTrg1MemInstruction(self()->cg(), TR::InstOpCode::lfs, firstNode, REAL_REGISTER(REGNUM(target)),
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, source, 4, self()->cg()), cursor);
op = TR::InstOpCode::lfs;
length = 4;
break;
case 4:
cursor = generateTrg1MemInstruction(self()->cg(), TR::InstOpCode::lfd, firstNode, REAL_REGISTER(REGNUM(target)),
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, source, 8, self()->cg()), cursor);
op = TR::InstOpCode::lfd;
length = 8;
break;
}

if (busyMoves[2][i1] != 0)
{
cursor = generateTrg1MemInstruction(self()->cg(), op, firstNode,
REAL_REGISTER(REGNUM(target)),
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, source, length, self()->cg()),
cursor);
}

freeScratchable.reset(target);
freeMore = true;
busyMoves[0][i1] = busyMoves[1][i1] = -1;
Expand Down Expand Up @@ -550,23 +565,28 @@ TR::Instruction *OMR::Power::Linkage::loadUpArguments(TR::Instruction *cursor)
else
numIntArgs+=2;
break;

case TR::Float:
if (hasToLoadFromStack &&
numFloatArgs<properties.getNumFloatArgRegs())
{
argRegister = machine->getRealRegister(properties.getFloatArgumentRegister(numFloatArgs));
cursor = generateTrg1MemInstruction(self()->cg(), TR::InstOpCode::lfs, firstNode, argRegister,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, 4, self()->cg()), cursor);
}
numFloatArgs++;
break;
case TR::Double:
if (hasToLoadFromStack &&
numFloatArgs<properties.getNumFloatArgRegs())
{
argRegister = machine->getRealRegister(properties.getFloatArgumentRegister(numFloatArgs));
cursor = generateTrg1MemInstruction(self()->cg(), TR::InstOpCode::lfd, firstNode, argRegister,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, 8, self()->cg()), cursor);

TR::InstOpCode::Mnemonic op;
int32_t length;

if (paramCursor->getDataType() == TR::Float)
{
op = TR::InstOpCode::lfs; length = 4;
}
else
{
op = TR::InstOpCode::lfd; length = 8;
}

cursor = generateTrg1MemInstruction(self()->cg(), op, firstNode, argRegister,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, length, self()->cg()), cursor);
}
numFloatArgs++;
break;
Expand Down Expand Up @@ -650,24 +670,28 @@ TR::Instruction *OMR::Power::Linkage::flushArguments(TR::Instruction *cursor)
else
numIntArgs+=2;
break;

case TR::Float:
if (hasToStoreToStack &&
numFloatArgs<properties.getNumFloatArgRegs())
{
argRegister = machine->getRealRegister(properties.getFloatArgumentRegister(numFloatArgs));
cursor = generateMemSrc1Instruction(self()->cg(), TR::InstOpCode::stfs, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, 4, self()->cg()),
argRegister, cursor);
}
numFloatArgs++;
break;
case TR::Double:
if (hasToStoreToStack &&
numFloatArgs<properties.getNumFloatArgRegs())
{
argRegister = machine->getRealRegister(properties.getFloatArgumentRegister(numFloatArgs));
cursor = generateMemSrc1Instruction(self()->cg(), TR::InstOpCode::stfd, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, 8, self()->cg()),

TR::InstOpCode::Mnemonic op;
int32_t length;

if (paramCursor->getDataType() == TR::Float)
{
op = TR::InstOpCode::stfs; length = 4;
}
else
{
op = TR::InstOpCode::stfd; length = 8;
}

cursor = generateMemSrc1Instruction(self()->cg(), op, firstNode,
new (self()->trHeapMemory()) TR::MemoryReference(stackPtr, offset, length, self()->cg()),
argRegister, cursor);
}
numFloatArgs++;
Expand Down
12 changes: 0 additions & 12 deletions compiler/p/codegen/OMRLinkage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,18 +404,6 @@ class OMR_EXTENSIBLE Linkage : public OMR::Linkage

virtual TR::Register *buildIndirectDispatch(TR::Node *callNode) = 0;

// Given an offset (generally into a stack frame) of the slot used
// to hold a parameter, compute the offset of the data itself.
// (in the case of 32-bit slots, the offset will be 3 for a char,
// 2 for a short, 0 for an int.)
//
virtual uintptr_t calculateActualParameterOffset(uintptr_t o, TR::ParameterSymbol& p) { return o; }

// And the reverse...Once paramaters are mapped, where do I store the
// actual full-sized register
//
virtual uintptr_t calculateParameterRegisterOffset(uintptr_t o, TR::ParameterSymbol& p) { return o; }

TR_ReturnInfo getReturnInfoFromReturnType(TR::DataType);
};
}
Expand Down
44 changes: 2 additions & 42 deletions compiler/p/codegen/PPCSystemLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,46 +436,6 @@ TR::PPCSystemLinkage::hasToBeOnStack(TR::ParameterSymbol *parm)
}


uintptr_t
TR::PPCSystemLinkage::calculateActualParameterOffset(
uintptr_t o,
TR::ParameterSymbol& p)
{
TR::ResolvedMethodSymbol * bodySymbol = comp()->getJittedMethodSymbol();
#ifndef TR_TARGET_64BIT
uint32_t bound = sizeof(uint32_t);
#else
size_t bound = sizeof(uint64_t);
#endif
if (1 || (p.getDataType() == TR::Aggregate) || (p.getSize() >= bound))
{
return o;
}
else
{
return o + bound - p.getSize();
}
}


uintptr_t TR::PPCSystemLinkage::calculateParameterRegisterOffset(uintptr_t o, TR::ParameterSymbol& p)
{
TR::ResolvedMethodSymbol * bodySymbol = comp()->getJittedMethodSymbol();
if (1 || (p.getDataType() == TR::Aggregate) || (p.getSize() >= sizeof(uint64_t)))
{
return o;
}
else
{
#ifdef TR_TARGET_64BIT
return o & (~(uint64_t) 7);
#else
return o & (~(uint32_t) 3);
#endif
}
}


void
TR::PPCSystemLinkage::mapParameters(
TR::ResolvedMethodSymbol *method,
Expand Down Expand Up @@ -503,9 +463,9 @@ TR::PPCSystemLinkage::mapParameters(
while (parmCursor != NULL)
{
if (saveParmsInLocalArea)
parmCursor->setParameterOffset(calculateActualParameterOffset(offset_from_top + stackIndex, *parmCursor));
parmCursor->setParameterOffset(offset_from_top + stackIndex);
else
parmCursor->setParameterOffset(calculateActualParameterOffset(offset_from_top + offsetToFirstParm + stackIndex, *parmCursor));
parmCursor->setParameterOffset(offset_from_top + offsetToFirstParm + stackIndex);
offset_from_top += (parmCursor->getSize() + slot_size - 1) & (~(slot_size - 1));
parmCursor = parameterIterator.getNext();
}
Expand Down
2 changes: 0 additions & 2 deletions compiler/p/codegen/PPCSystemLinkage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class PPCSystemLinkage : public TR::Linkage
PPCSystemLinkage(TR::CodeGenerator *cg);

virtual const TR::PPCLinkageProperties& getProperties();
virtual uintptr_t calculateActualParameterOffset(uintptr_t, TR::ParameterSymbol&);
virtual uintptr_t calculateParameterRegisterOffset(uintptr_t, TR::ParameterSymbol&);

virtual uint32_t getRightToLeft();
virtual bool hasToBeOnStack(TR::ParameterSymbol *parm);
Expand Down

0 comments on commit c910b33

Please sign in to comment.