Skip to content

Commit

Permalink
Merge pull request eclipse-omr#4798 from fjeremic/document-private-li…
Browse files Browse the repository at this point in the history
…nkage-double-slot

Common getOffsetToFirstParm in the linkage class across codegens
  • Loading branch information
0xdaryl authored Jun 1, 2020
2 parents e9267f3 + 214f1e0 commit c65b0bc
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 73 deletions.
2 changes: 1 addition & 1 deletion compiler/aarch64/codegen/ARM64SystemLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ TR::ARM64SystemLinkage::ARM64SystemLinkage(TR::CodeGenerator *cg)
_properties._j9methodArgumentRegister = TR::RealRegister::NoReg;

_properties._numberOfDependencyGPRegisters = 32; // To be determined
_properties._offsetToFirstParm = 0; // To be determined
setOffsetToFirstParm(0); // To be determined
_properties._offsetToFirstLocal = 0; // To be determined
}

Expand Down
3 changes: 0 additions & 3 deletions compiler/aarch64/codegen/OMRLinkage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ struct ARM64LinkageProperties
TR::RealRegister::RegNum _vtableIndexArgumentRegister; // for icallVMprJavaSendPatchupVirtual
TR::RealRegister::RegNum _j9methodArgumentRegister; // for icallVMprJavaSendStatic
uint8_t _numberOfDependencyGPRegisters;
int8_t _offsetToFirstParm;
int8_t _offsetToFirstLocal;

uint32_t getNumIntArgRegs() const {return _numIntegerArgumentRegisters;}
Expand Down Expand Up @@ -264,8 +263,6 @@ struct ARM64LinkageProperties
return _j9methodArgumentRegister;
}

int32_t getOffsetToFirstParm() const {return _offsetToFirstParm;}

int32_t getOffsetToFirstLocal() const {return _offsetToFirstLocal;}

uint32_t getNumberOfDependencyGPRegisters() const {return _numberOfDependencyGPRegisters;}
Expand Down
45 changes: 23 additions & 22 deletions compiler/arm/codegen/ARMDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,16 +1118,17 @@ TR_Debug::print(TR::FILE *pOutFile, TR::ARMCallSnippet * snippet)
printSnippetLabel(pOutFile, snippet->getSnippetLabel(), bufferPos, getName(snippet), getName(methodSymRef));

TR::Machine *machine = _cg->machine();
const TR::ARMLinkageProperties &linkage = _cg->getLinkage(methodSymbol->getLinkageConvention())->getProperties();
TR::Linkage *linkage = _cg->getLinkage(methodSymbol->getLinkageConvention());
const TR::ARMLinkageProperties &linkageProperties = linkage->getProperties();

uint32_t numIntArgs = 0;
uint32_t numFloatArgs = 0;

int32_t offset;
if (linkage.getRightToLeft())
offset = linkage.getOffsetToFirstParm();
if (linkageProperties.getRightToLeft())
offset = linkage->getOffsetToFirstParm();
else
offset = snippet->getSizeOfArguments() + linkage.getOffsetToFirstParm();
offset = snippet->getSizeOfArguments() + linkage->getOffsetToFirstParm();

for (int i = callNode->getFirstArgumentIndex(); i < callNode->getNumChildren(); i++)
{
Expand All @@ -1137,68 +1138,68 @@ TR_Debug::print(TR::FILE *pOutFile, TR::ARMCallSnippet * snippet)
case TR::Int16:
case TR::Int32:
case TR::Address:
if (!linkage.getRightToLeft())
if (!linkageProperties.getRightToLeft())
offset -= 4;
if (numIntArgs < linkage.getNumIntArgRegs())
if (numIntArgs < linkageProperties.getNumIntArgRegs())
{
printPrefix(pOutFile, NULL, bufferPos, 4);
trfprintf(pOutFile, "str\t[gr7, %+d], ", offset);
print(pOutFile, machine->getRealRegister(linkage.getIntegerArgumentRegister(numIntArgs)));
print(pOutFile, machine->getRealRegister(linkageProperties.getIntegerArgumentRegister(numIntArgs)));
bufferPos += 4;
}
numIntArgs++;
if (linkage.getRightToLeft())
if (linkageProperties.getRightToLeft())
offset += 4;
break;
case TR::Int64:
if (!linkage.getRightToLeft())
if (!linkageProperties.getRightToLeft())
offset -= 8;
if (numIntArgs < linkage.getNumIntArgRegs())
if (numIntArgs < linkageProperties.getNumIntArgRegs())
{
printPrefix(pOutFile, NULL, bufferPos, 4);
trfprintf(pOutFile, "str\t[gr7, %+d], ", offset);
print(pOutFile, machine->getRealRegister(linkage.getIntegerArgumentRegister(numIntArgs)));
print(pOutFile, machine->getRealRegister(linkageProperties.getIntegerArgumentRegister(numIntArgs)));
bufferPos += 4;
if (numIntArgs < linkage.getNumIntArgRegs() - 1)
if (numIntArgs < linkageProperties.getNumIntArgRegs() - 1)
{
printPrefix(pOutFile, NULL, bufferPos, 4);
trfprintf(pOutFile, "str\t[gr7, %+d], ", offset + 4);
print(pOutFile, machine->getRealRegister(linkage.getIntegerArgumentRegister(numIntArgs + 1)));
print(pOutFile, machine->getRealRegister(linkageProperties.getIntegerArgumentRegister(numIntArgs + 1)));
bufferPos += 4;
}
}
numIntArgs += 2;
if (linkage.getRightToLeft())
if (linkageProperties.getRightToLeft())
offset += 8;
break;
// TODO FLOAT
#if 0
case TR::Float:
if (!linkage.getRightToLeft())
if (!linkageProperties.getRightToLeft())
offset -= 4;
if (numFloatArgs < linkage.getNumFloatArgRegs())
if (numFloatArgs < linkageProperties.getNumFloatArgRegs())
{
printPrefix(pOutFile, NULL, bufferPos, 4);
trfprintf(pOutFile, "stfs\t[gr7, %+d], ", offset);
print(pOutFile, machine->getRealRegister(linkage.getFloatArgumentRegister(numFloatArgs)));
print(pOutFile, machine->getRealRegister(linkageProperties.getFloatArgumentRegister(numFloatArgs)));
bufferPos += 4;
}
numFloatArgs++;
if (linkage.getRightToLeft())
if (linkageProperties.getRightToLeft())
offset += 4;
break;
case TR::Double:
if (!linkage.getRightToLeft())
if (!linkageProperties.getRightToLeft())
offset -= 8;
if (numFloatArgs < linkage.getNumFloatArgRegs())
if (numFloatArgs < linkageProperties.getNumFloatArgRegs())
{
printPrefix(pOutFile, NULL, bufferPos, 4);
trfprintf(pOutFile, "stfd\t[gr7, %+d], ", offset);
print(pOutFile, machine->getRealRegister(linkage.getFloatArgumentRegister(numFloatArgs)));
print(pOutFile, machine->getRealRegister(linkageProperties.getFloatArgumentRegister(numFloatArgs)));
bufferPos += 4;
}
numFloatArgs++;
if (linkage.getRightToLeft())
if (linkageProperties.getRightToLeft())
offset += 8;
break;
#endif
Expand Down
7 changes: 6 additions & 1 deletion compiler/arm/codegen/ARMSystemLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ TR::ARMLinkageProperties TR::ARMSystemLinkage::properties =
TR::RealRegister::NoReg, // vtable index register
TR::RealRegister::NoReg, // j9method argument register
15, // numberOfDependencyGPRegisters
0, // offsetToFirstStackParm (relative to old sp)
-4, // offsetToFirstLocal (not counting out-args)
4, // numIntegerArgumentRegisters
0, // firstIntegerArgumentRegister (index into ArgumentRegisters)
Expand All @@ -176,6 +175,12 @@ TR::ARMLinkageProperties TR::ARMSystemLinkage::properties =
#endif
};

TR::ARMSystemLinkage::ARMSystemLinkage(TR::CodeGenerator *cg)
: TR::Linkage(cg)
{
setOffsetToFirstParm(0);
}

void TR::ARMSystemLinkage::initARMRealRegisterLinkage()
{
TR::Machine *machine = cg()->machine();
Expand Down
2 changes: 1 addition & 1 deletion compiler/arm/codegen/ARMSystemLinkage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ARMSystemLinkage : public TR::Linkage

public:

ARMSystemLinkage(TR::CodeGenerator *codeGen) : TR::Linkage(codeGen) {}
ARMSystemLinkage(TR::CodeGenerator *codeGen);

virtual uint32_t getRightToLeft();
virtual void mapStack(TR::ResolvedMethodSymbol *method);
Expand Down
4 changes: 2 additions & 2 deletions compiler/arm/codegen/OMRLinkage.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -644,7 +644,7 @@ printf("%s: numIntegerArgs %d numMemArgs %d\n", sig, numIntegerArgs, numMemArgs
numIntegerArgs = 0;
numFloatArgs = 0;

int32_t argSize = -(properties.getOffsetToFirstParm());
int32_t argSize = -(self()->getOffsetToFirstParm());
int32_t memArg = 0;
for (i = from; (isHelper && i > to) || (!isHelper && i < to); i += step)
{
Expand Down
5 changes: 1 addition & 4 deletions compiler/arm/codegen/OMRLinkage.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -91,7 +91,6 @@ struct ARMLinkageProperties
TR::RealRegister::RegNum _j9methodArgumentRegister; // for icallVMprJavaSendStatic

uint8_t _numberOfDependencyGPRegisters;
int8_t _offsetToFirstParm;
int8_t _offsetToFirstLocal;

uint8_t _numIntegerArgumentRegisters;
Expand Down Expand Up @@ -263,8 +262,6 @@ struct ARMLinkageProperties
return _j9methodArgumentRegister;
}

int32_t getOffsetToFirstParm() const {return _offsetToFirstParm;}

int32_t getOffsetToFirstLocal() const {return _offsetToFirstLocal;}

uint32_t getNumberOfDependencyGPRegisters() const {return _numberOfDependencyGPRegisters;}
Expand Down
38 changes: 38 additions & 0 deletions compiler/codegen/OMRLinkage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,42 @@ class OMR_EXTENSIBLE Linkage
*/
virtual void performPostBinaryEncoding() { }

/** @brief
* Gets the offset (in number of bytes) from the stack frame pointer to the location on the stack where the first
* (closest to the frame pointer) parameter is located.
*
* @details
* For example given the following stack frame layout, for a stack which grows towards 0x0000 (we subtract the
* stack pointer for each additional frame), and assuming a call to a function with 4 parameters:
*
* @code
* 0x04E8 +--------+ <- stack pointer
* | .... |
* 0x0518 +--------+ <- frame pointer
* | .... |
* 0x0550 +--------+ <- offset to first parm relative to the frame pointer (0x0550 - 0x0518 = 0x0038)
* | ARG4 |
* 0x0558 +--------+
* | ARG3 |
* 0x0560 +--------+
* | ARG2 |
* 0x0568 +--------+
* | ARG1 |
* 0x0570 +--------+
* @endcode
*
* The offset returned by this function (0x0038 in the above example) may not be the first argument (in argument
* order) passed by the caller on the stack. It is up to the linkage to make use of this function to initialize
* parameter offsets depending on the order in which the caller passes the arguments to the callee.
*/
inline int32_t getOffsetToFirstParm() const;

/** @brief
* Sets the offset (in number of bytes) from the stack frame pointer to the location on the stack where the first
* (closest to the frame pointer) parameter is located.
*/
inline int32_t setOffsetToFirstParm(int32_t offset);

/**
* @brief Provides the entry point in a method to use when that method is invoked
* from a method compiled with the same linkage.
Expand Down Expand Up @@ -167,6 +203,8 @@ class OMR_EXTENSIBLE Linkage
protected:

TR::CodeGenerator *_cg;

int32_t _offsetToFirstParm;
};
}

Expand Down
13 changes: 12 additions & 1 deletion compiler/codegen/OMRLinkage_inlines.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -79,4 +79,15 @@ OMR::Linkage::trStackMemory()
return self()->trMemory();
}

int32_t
OMR::Linkage::getOffsetToFirstParm() const
{
return _offsetToFirstParm;
}

int32_t
OMR::Linkage::setOffsetToFirstParm(int32_t offset)
{
return _offsetToFirstParm = offset;
}
#endif
2 changes: 1 addition & 1 deletion compiler/p/codegen/OMRLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TR::MemoryReference *OMR::Power::Linkage::getOutgoingArgumentMemRef(int32_t argS
const TR::PPCLinkageProperties& properties = self()->getProperties();

TR::MemoryReference *result = new (self()->trHeapMemory()) TR::MemoryReference(machine->getRealRegister(properties.getNormalStackPointerRegister()),
argSize+properties.getOffsetToFirstParm(), length, self()->cg());
argSize+self()->getOffsetToFirstParm(), length, self()->cg());
memArg.argRegister = argReg;
memArg.argMemory = result;
memArg.opCode = opCode;
Expand Down
3 changes: 0 additions & 3 deletions compiler/p/codegen/OMRLinkage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ struct PPCLinkageProperties
TR::RealRegister::RegNum _vtableIndexArgumentRegister; // for icallVMprJavaSendPatchupVirtual
TR::RealRegister::RegNum _j9methodArgumentRegister; // for icallVMprJavaSendStatic
uint8_t _numberOfDependencyGPRegisters;
int8_t _offsetToFirstParm;
int8_t _offsetToFirstLocal;

uint32_t getNumIntArgRegs() const {return _numIntegerArgumentRegisters;}
Expand Down Expand Up @@ -349,8 +348,6 @@ struct PPCLinkageProperties
return _j9methodArgumentRegister;
}

int32_t getOffsetToFirstParm() const {return _offsetToFirstParm;}

int32_t getOffsetToFirstLocal() const {return _offsetToFirstLocal;}

uint32_t getNumberOfDependencyGPRegisters() const {return _numberOfDependencyGPRegisters;}
Expand Down
14 changes: 7 additions & 7 deletions compiler/p/codegen/PPCSystemLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ TR::PPCSystemLinkage::PPCSystemLinkage(TR::CodeGenerator *cg)

// Volatile GPR (0,2-12) + FPR (0-13) + CCR (0-1,5-7) + VR (0-19) + FPR (14-31) if used as vector
_properties._numberOfDependencyGPRegisters = 12 + 14 + 5 + 20 + 18;
_properties._offsetToFirstParm = isBE?48:32;
setOffsetToFirstParm(isBE ? 48 : 32);
_properties._offsetToFirstLocal = isBE?48:32;
}
else
Expand All @@ -348,14 +348,14 @@ TR::PPCSystemLinkage::PPCSystemLinkage(TR::CodeGenerator *cg)
{
// Volatile GPR (0,2-12) + FPR (0-13) + CCR (0-1,5-7) + VR (0-19) + FPR (14-31) if used as vector
_properties._numberOfDependencyGPRegisters = 12 + 14 + 5 + 20 + 18;
_properties._offsetToFirstParm = 24;
setOffsetToFirstParm(24);
_properties._offsetToFirstLocal = 24;
}
else
{
// Volatile GPR (0,3-12) + FPR (0-13) + CCR (0-1,5-7) + VR (0-19) + FPR (14-31) if used as vector
_properties._numberOfDependencyGPRegisters = 11 + 14 + 5 + 20 + 18;
_properties._offsetToFirstParm = 8;
setOffsetToFirstParm(8);
_properties._offsetToFirstLocal = 8;
}
}
Expand Down Expand Up @@ -466,7 +466,7 @@ TR::PPCSystemLinkage::mapParameters(
ListIterator<TR::ParameterSymbol> parameterIterator(&parmList);
TR::ParameterSymbol *parmCursor = parameterIterator.getFirst();
const TR::PPCLinkageProperties& linkage = getProperties();
int32_t offsetToFirstParm = linkage.getOffsetToFirstParm();
int32_t offsetToFirstParm = self()->getOffsetToFirstParm();
int32_t offset_from_top = 0;
int32_t slot_size = sizeof(uintptr_t);

Expand Down Expand Up @@ -567,7 +567,7 @@ TR::PPCSystemLinkage::mapStack(TR::ResolvedMethodSymbol *method)

method->setLocalMappingCursor(stackIndex);

int32_t offsetToFirstParm = linkage.getOffsetToFirstParm();
int32_t offsetToFirstParm = self()->getOffsetToFirstParm();
mapParameters(method, method->getParameterList());

#ifdef __LITTLE_ENDIAN__
Expand Down Expand Up @@ -709,7 +709,7 @@ TR::PPCSystemLinkage::createPrologue(
// stack frame if there are any saved non-volatiles
//

if ( size > properties.getOffsetToFirstParm() - argSize)
if (size > self()->getOffsetToFirstParm() - argSize)
{
if (size > (-LOWER_IMMED))
{
Expand Down Expand Up @@ -804,7 +804,7 @@ TR::PPCSystemLinkage::createEpilogue(TR::Instruction *cursor)
// Some opcodes write into temps above stack, therefore need to allocate
// stack frame if there are any saved non-volatiles
//
if (size > properties.getOffsetToFirstParm() - saveSize)
if (size > self()->getOffsetToFirstParm() - saveSize)
{
if (size > UPPER_IMMED)
{
Expand Down
5 changes: 1 addition & 4 deletions compiler/riscv/codegen/OMRLinkage.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -117,7 +117,6 @@ struct RVLinkageProperties
TR::RealRegister::RegNum _stackPointerRegister;
TR::RealRegister::RegNum _framePointerRegister;
uint8_t _numberOfDependencyGPRegisters;
int8_t _offsetToFirstParm;
int8_t _offsetToFirstLocal;

uint32_t getNumIntArgRegs() const {return _numIntegerArgumentRegisters;}
Expand Down Expand Up @@ -255,8 +254,6 @@ struct RVLinkageProperties
return _framePointerRegister;
}

int32_t getOffsetToFirstParm() const {return _offsetToFirstParm;}

int32_t getOffsetToFirstLocal() const {return _offsetToFirstLocal;}

uint32_t getNumberOfDependencyGPRegisters() const {return _numberOfDependencyGPRegisters;}
Expand Down
Loading

0 comments on commit c65b0bc

Please sign in to comment.