Skip to content

Commit

Permalink
AArch64: Add support for CHelper in PrivateLinkage
Browse files Browse the repository at this point in the history
This commit adds support for CHelper in ARM64PrivateLinkage, which
passes the VM thread as the implicit first argument.
  • Loading branch information
knn-k committed Sep 11, 2020
1 parent 5ef8df8 commit 0cb4f56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions runtime/codert_vm/arm64nathelp.m4
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ define({NEW_DUAL_MODE_HELPER},{
ret x0
.L_old_slow_$1:
RESTORE_C_NONVOLATILE_REGS
SWITCH_TO_JAVA_STACK
.L_done_$1:
RESTORE_FPLR
SWITCH_TO_JAVA_STACK
ldr x0,[J9VMTHREAD,{#}J9TR_VMThread_returnValue]
ret
END_PROC($1)
Expand All @@ -201,9 +201,9 @@ define({NEW_DUAL_MODE_HELPER_NO_RETURN_VALUE},{
ret x0
.L_old_slow_$1:
RESTORE_C_NONVOLATILE_REGS
SWITCH_TO_JAVA_STACK
.L_done_$1:
RESTORE_FPLR
SWITCH_TO_JAVA_STACK
ret
END_PROC($1)
})
Expand Down
28 changes: 26 additions & 2 deletions runtime/compiler/aarch64/codegen/ARM64PrivateLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ int32_t J9::ARM64::PrivateLinkage::buildPrivateLinkageArgs(TR::Node *callNode,
int32_t argIndex = 0;
int32_t numMemArgs = 0;
int32_t memArgSize = 0;
int32_t firstExplicitArg = 0;
int32_t from, to, step;
int32_t argSize = -getOffsetToFirstParm();
int32_t totalSize = 0;
Expand Down Expand Up @@ -909,6 +910,14 @@ int32_t J9::ARM64::PrivateLinkage::buildPrivateLinkageArgs(TR::Node *callNode,
from += step;
}

// C helpers have an implicit first argument (the VM thread) that we have to account for
if (linkage == TR_CHelper)
{
TR_ASSERT(numIntArgRegs > 0, "This code doesn't handle passing this implicit arg on the stack");
numIntegerArgs++;
totalSize += TR::Compiler->om.sizeofReferenceAddress();
}

for (int32_t i = from; (rightToLeft && i >= to) || (!rightToLeft && i <= to); i += step)
{
child = callNode->getChild(i);
Expand Down Expand Up @@ -960,6 +969,19 @@ int32_t J9::ARM64::PrivateLinkage::buildPrivateLinkageArgs(TR::Node *callNode,
numIntegerArgs = 0;
numFloatArgs = 0;

// C helpers have an implicit first argument (the VM thread) that we have to account for
if (linkage == TR_CHelper)
{
TR_ASSERT(numIntArgRegs > 0, "This code doesn't handle passing this implicit arg on the stack");
TR::Register *vmThreadArgRegister = cg()->allocateRegister();
generateMovInstruction(cg(), callNode, vmThreadArgRegister, cg()->getMethodMetaDataRegister());
dependencies->addPreCondition(vmThreadArgRegister, properties.getIntegerArgumentRegister(numIntegerArgs));
if (resType.getDataType() == TR::NoType)
dependencies->addPostCondition(vmThreadArgRegister, properties.getIntegerArgumentRegister(numIntegerArgs));
numIntegerArgs++;
firstExplicitArg = 1;
}

// Helper linkage preserves all argument registers except the return register
// TODO: C helper linkage does not, this code needs to make sure argument registers are killed in post dependencies
for (int32_t i = from; (rightToLeft && i >= to) || (!rightToLeft && i <= to); i += step)
Expand Down Expand Up @@ -1021,16 +1043,18 @@ int32_t J9::ARM64::PrivateLinkage::buildPrivateLinkageArgs(TR::Node *callNode,
generateMovInstruction(cg(), callNode, tempReg, argRegister);
argRegister = tempReg;
}
if (numIntegerArgs == 0)
if (numIntegerArgs == firstExplicitArg)
{
// the first integer argument
TR::Register *resultReg;
if (resType.isAddress())
resultReg = cg()->allocateCollectedReferenceRegister();
else
resultReg = cg()->allocateRegister();
dependencies->addPreCondition(argRegister, TR::RealRegister::x0);
dependencies->addPreCondition(argRegister, properties.getIntegerArgumentRegister(numIntegerArgs));
dependencies->addPostCondition(resultReg, TR::RealRegister::x0);
if (firstExplicitArg == 1)
dependencies->addPostCondition(argRegister, properties.getIntegerArgumentRegister(numIntegerArgs));
}
else
{
Expand Down

0 comments on commit 0cb4f56

Please sign in to comment.