Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSRA: Refactor some of the methods around creating kill set #102469

Merged
merged 8 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/coreclr/jit/lsra.h
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ class LinearScan : public LinearScanInterface
void buildRefPositionsForNode(GenTree* tree, LsraLocation loc);

#if FEATURE_PARTIAL_SIMD_CALLEE_SAVE
void buildUpperVectorSaveRefPositions(GenTree* tree, LsraLocation currentLoc, regMaskTP fpCalleeKillSet);
void buildUpperVectorSaveRefPositions(GenTree* tree, LsraLocation currentLoc DEBUG_ARG(regMaskTP fpCalleeKillSet));
void buildUpperVectorRestoreRefPosition(
Interval* lclVarInterval, LsraLocation currentLoc, GenTree* node, bool isUse, unsigned multiRegIdx);
#endif // FEATURE_PARTIAL_SIMD_CALLEE_SAVE
Expand Down Expand Up @@ -1999,19 +1999,27 @@ class LinearScan : public LinearScanInterface
void getTgtPrefOperands(GenTree* tree, GenTree* op1, GenTree* op2, bool* prefOp1, bool* prefOp2);
bool supportsSpecialPutArg();

int BuildSimple(GenTree* tree);
int BuildOperandUses(GenTree* node, regMaskTP candidates = RBM_NONE);
void AddDelayFreeUses(RefPosition* refPosition, GenTree* rmwNode);
int BuildDelayFreeUses(GenTree* node,
GenTree* rmwNode = nullptr,
regMaskTP candidates = RBM_NONE,
RefPosition** useRefPosition = nullptr);
int BuildIndirUses(GenTreeIndir* indirTree, regMaskTP candidates = RBM_NONE);
int BuildAddrUses(GenTree* addr, regMaskTP candidates = RBM_NONE);
void HandleFloatVarArgs(GenTreeCall* call, GenTree* argNode, bool* callHasFloatRegArgs);
int BuildSimple(GenTree* tree);
int BuildOperandUses(GenTree* node, regMaskTP candidates = RBM_NONE);
void AddDelayFreeUses(RefPosition* refPosition, GenTree* rmwNode);
int BuildDelayFreeUses(GenTree* node,
GenTree* rmwNode = nullptr,
regMaskTP candidates = RBM_NONE,
RefPosition** useRefPosition = nullptr);
int BuildIndirUses(GenTreeIndir* indirTree, regMaskTP candidates = RBM_NONE);
int BuildAddrUses(GenTree* addr, regMaskTP candidates = RBM_NONE);
void HandleFloatVarArgs(GenTreeCall* call, GenTree* argNode, bool* callHasFloatRegArgs);

RefPosition* BuildDef(GenTree* tree, regMaskTP dstCandidates = RBM_NONE, int multiRegIdx = 0);
void BuildDefs(GenTree* tree, int dstCount, regMaskTP dstCandidates = RBM_NONE);
void BuildDefsWithKills(GenTree* tree, int dstCount, regMaskTP dstCandidates, regMaskTP killMask);
void BuildCallDefs(GenTree* tree, int dstCount, regMaskTP dstCandidates);
void BuildKills(GenTree* tree, regMaskTP killMask);
#if defined(TARGET_ARMARCH) || defined(TARGET_RISCV64)
void BuildDefWithKills(GenTree* tree, regMaskTP dstCandidates, regMaskTP killMask);
#else
void BuildDefWithKills(GenTree* tree, int dstCount, regMaskTP dstCandidates, regMaskTP killMask);
#endif // TARGET_ARMARCH || TARGET_RISCV64
void BuildCallDefsWithKills(GenTree* tree, int dstCount, regMaskTP dstCandidates, regMaskTP killMask);

int BuildReturn(GenTree* tree);
#ifdef TARGET_XARCH
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/lsraarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ int LinearScan::BuildNode(GenTree* tree)
assert(dstCount == 0);
BuildUse(tree->gtGetOp1());
killMask = compiler->compHelperCallKillSet(CORINFO_HELP_STOP_FOR_GC);
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
BuildKills(tree, killMask);
break;

case GT_MUL:
Expand Down Expand Up @@ -422,7 +422,7 @@ int LinearScan::BuildNode(GenTree* tree)
// This kills GC refs in callee save regs
srcCount = 0;
assert(dstCount == 0);
BuildDefsWithKills(tree, 0, RBM_NONE, RBM_NONE);
BuildKills(tree, RBM_NONE);
break;

case GT_LONG:
Expand Down Expand Up @@ -469,7 +469,7 @@ int LinearScan::BuildNode(GenTree* tree)
case GT_RETURN:
srcCount = BuildReturn(tree);
killMask = getKillSetForReturn();
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
BuildKills(tree, killMask);
break;

case GT_RETFILT:
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/jit/lsraarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,14 @@ int LinearScan::BuildNode(GenTree* tree)
srcCount = 0;
assert(dstCount == 0);
killMask = getKillSetForProfilerHook();
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
BuildKills(tree, killMask);
break;

case GT_START_PREEMPTGC:
// This kills GC refs in callee save regs
srcCount = 0;
assert(dstCount == 0);
BuildDefsWithKills(tree, 0, RBM_NONE, RBM_NONE);
BuildKills(tree, RBM_NONE);
break;

case GT_CNS_DBL:
Expand Down Expand Up @@ -738,7 +738,7 @@ int LinearScan::BuildNode(GenTree* tree)
case GT_RETURN:
srcCount = BuildReturn(tree);
killMask = getKillSetForReturn();
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
BuildKills(tree, killMask);
break;

#ifdef SWIFT_SUPPORT
Expand All @@ -747,7 +747,7 @@ int LinearScan::BuildNode(GenTree* tree)
// Plus one for error register
srcCount = BuildReturn(tree) + 1;
killMask = getKillSetForReturn();
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
BuildKills(tree, killMask);
break;
#endif // SWIFT_SUPPORT

Expand Down Expand Up @@ -839,7 +839,7 @@ int LinearScan::BuildNode(GenTree* tree)
srcCount = 1;
assert(dstCount == 0);
killMask = compiler->compHelperCallKillSet(CORINFO_HELP_STOP_FOR_GC);
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
BuildKills(tree, killMask);
break;

case GT_MOD:
Expand Down Expand Up @@ -1927,11 +1927,11 @@ int LinearScan::BuildHWIntrinsic(GenTreeHWIntrinsic* intrinsicTree, int* pDstCou

if ((dstCount == 1) || (dstCount == 2))
{
BuildDef(intrinsicTree, dstCandidates);
BuildDef(intrinsicTree);

if (dstCount == 2)
{
BuildDef(intrinsicTree, dstCandidates, 1);
BuildDef(intrinsicTree, RBM_NONE, 1);
}
}
else
Expand Down
58 changes: 37 additions & 21 deletions src/coreclr/jit/lsraarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ int LinearScan::BuildIndir(GenTreeIndir* indirTree)
//
int LinearScan::BuildCall(GenTreeCall* call)
{
bool hasMultiRegRetVal = false;
const ReturnTypeDesc* retTypeDesc = nullptr;
regMaskTP dstCandidates = RBM_NONE;
bool hasMultiRegRetVal = false;
const ReturnTypeDesc* retTypeDesc = nullptr;
regMaskTP singleDstCandidates = RBM_NONE;

int srcCount = 0;
int dstCount = 0;
Expand Down Expand Up @@ -227,26 +227,24 @@ int LinearScan::BuildCall(GenTreeCall* call)
{
// The ARM CORINFO_HELP_INIT_PINVOKE_FRAME helper uses a custom calling convention that returns with
// TCB in REG_PINVOKE_TCB. fgMorphCall() sets the correct argument registers.
dstCandidates = RBM_PINVOKE_TCB;
singleDstCandidates = RBM_PINVOKE_TCB;
}
else
#endif // TARGET_ARM
if (hasMultiRegRetVal)
{
assert(retTypeDesc != nullptr);
dstCandidates = retTypeDesc->GetABIReturnRegs(call->GetUnmanagedCallConv());
}
else if (varTypeUsesFloatArgReg(registerType))
{
dstCandidates = RBM_FLOATRET;
}
else if (registerType == TYP_LONG)
{
dstCandidates = RBM_LNGRET;
}
else
if (!hasMultiRegRetVal)
{
dstCandidates = RBM_INTRET;
if (varTypeUsesFloatArgReg(registerType))
{
singleDstCandidates = RBM_FLOATRET;
}
else if (registerType == TYP_LONG)
{
singleDstCandidates = RBM_LNGRET;
}
else
{
singleDstCandidates = RBM_INTRET;
}
}

// First, count reg args
Expand Down Expand Up @@ -399,7 +397,25 @@ int LinearScan::BuildCall(GenTreeCall* call)

// Now generate defs and kills.
regMaskTP killMask = getKillSetForCall(call);
BuildDefsWithKills(call, dstCount, dstCandidates, killMask);
if (dstCount > 0)
{
if (hasMultiRegRetVal)
{
assert(retTypeDesc != nullptr);
regMaskTP multiDstCandidates = retTypeDesc->GetABIReturnRegs(call->GetUnmanagedCallConv());
assert(genCountBits(multiDstCandidates) > 0);
BuildCallDefsWithKills(call, dstCount, multiDstCandidates, killMask);
}
else
{
assert(dstCount == 1);
BuildDefWithKills(call, singleDstCandidates, killMask);
}
}
else
{
BuildKills(call, killMask);
}

#ifdef SWIFT_SUPPORT
if (call->HasSwiftErrorHandling())
Expand Down Expand Up @@ -836,7 +852,7 @@ int LinearScan::BuildBlockStore(GenTreeBlk* blkNode)

buildInternalRegisterUses();
regMaskTP killMask = getKillSetForBlockStore(blkNode);
BuildDefsWithKills(blkNode, 0, RBM_NONE, killMask);
BuildKills(blkNode, killMask);
return useCount;
}

Expand Down
Loading
Loading