Skip to content

Commit 0709995

Browse files
authored
LSRA: Refactor some of the methods around creating kill set (#102469)
* refactor code around buildkill * fix build errors * some more errors * jit format * fix riscv64 * make retTypeDesc as noway_assert * fix riscv64 errors * jit format
1 parent 11ffb5c commit 0709995

File tree

8 files changed

+307
-148
lines changed

8 files changed

+307
-148
lines changed

src/coreclr/jit/lsra.h

+20-12
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ class LinearScan : public LinearScanInterface
10511051
void buildRefPositionsForNode(GenTree* tree, LsraLocation loc);
10521052

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

2002-
int BuildSimple(GenTree* tree);
2003-
int BuildOperandUses(GenTree* node, regMaskTP candidates = RBM_NONE);
2004-
void AddDelayFreeUses(RefPosition* refPosition, GenTree* rmwNode);
2005-
int BuildDelayFreeUses(GenTree* node,
2006-
GenTree* rmwNode = nullptr,
2007-
regMaskTP candidates = RBM_NONE,
2008-
RefPosition** useRefPosition = nullptr);
2009-
int BuildIndirUses(GenTreeIndir* indirTree, regMaskTP candidates = RBM_NONE);
2010-
int BuildAddrUses(GenTree* addr, regMaskTP candidates = RBM_NONE);
2011-
void HandleFloatVarArgs(GenTreeCall* call, GenTree* argNode, bool* callHasFloatRegArgs);
2002+
int BuildSimple(GenTree* tree);
2003+
int BuildOperandUses(GenTree* node, regMaskTP candidates = RBM_NONE);
2004+
void AddDelayFreeUses(RefPosition* refPosition, GenTree* rmwNode);
2005+
int BuildDelayFreeUses(GenTree* node,
2006+
GenTree* rmwNode = nullptr,
2007+
regMaskTP candidates = RBM_NONE,
2008+
RefPosition** useRefPosition = nullptr);
2009+
int BuildIndirUses(GenTreeIndir* indirTree, regMaskTP candidates = RBM_NONE);
2010+
int BuildAddrUses(GenTree* addr, regMaskTP candidates = RBM_NONE);
2011+
void HandleFloatVarArgs(GenTreeCall* call, GenTree* argNode, bool* callHasFloatRegArgs);
2012+
20122013
RefPosition* BuildDef(GenTree* tree, regMaskTP dstCandidates = RBM_NONE, int multiRegIdx = 0);
20132014
void BuildDefs(GenTree* tree, int dstCount, regMaskTP dstCandidates = RBM_NONE);
2014-
void BuildDefsWithKills(GenTree* tree, int dstCount, regMaskTP dstCandidates, regMaskTP killMask);
2015+
void BuildCallDefs(GenTree* tree, int dstCount, regMaskTP dstCandidates);
2016+
void BuildKills(GenTree* tree, regMaskTP killMask);
2017+
#if defined(TARGET_ARMARCH) || defined(TARGET_RISCV64)
2018+
void BuildDefWithKills(GenTree* tree, regMaskTP dstCandidates, regMaskTP killMask);
2019+
#else
2020+
void BuildDefWithKills(GenTree* tree, int dstCount, regMaskTP dstCandidates, regMaskTP killMask);
2021+
#endif // TARGET_ARMARCH || TARGET_RISCV64
2022+
void BuildCallDefsWithKills(GenTree* tree, int dstCount, regMaskTP dstCandidates, regMaskTP killMask);
20152023

20162024
int BuildReturn(GenTree* tree);
20172025
#ifdef TARGET_XARCH

src/coreclr/jit/lsraarm.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ int LinearScan::BuildNode(GenTree* tree)
373373
assert(dstCount == 0);
374374
BuildUse(tree->gtGetOp1());
375375
killMask = compiler->compHelperCallKillSet(CORINFO_HELP_STOP_FOR_GC);
376-
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
376+
BuildKills(tree, killMask);
377377
break;
378378

379379
case GT_MUL:
@@ -422,7 +422,7 @@ int LinearScan::BuildNode(GenTree* tree)
422422
// This kills GC refs in callee save regs
423423
srcCount = 0;
424424
assert(dstCount == 0);
425-
BuildDefsWithKills(tree, 0, RBM_NONE, RBM_NONE);
425+
BuildKills(tree, RBM_NONE);
426426
break;
427427

428428
case GT_LONG:
@@ -469,7 +469,7 @@ int LinearScan::BuildNode(GenTree* tree)
469469
case GT_RETURN:
470470
srcCount = BuildReturn(tree);
471471
killMask = getKillSetForReturn();
472-
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
472+
BuildKills(tree, killMask);
473473
break;
474474

475475
case GT_RETFILT:

src/coreclr/jit/lsraarm64.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -666,14 +666,14 @@ int LinearScan::BuildNode(GenTree* tree)
666666
srcCount = 0;
667667
assert(dstCount == 0);
668668
killMask = getKillSetForProfilerHook();
669-
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
669+
BuildKills(tree, killMask);
670670
break;
671671

672672
case GT_START_PREEMPTGC:
673673
// This kills GC refs in callee save regs
674674
srcCount = 0;
675675
assert(dstCount == 0);
676-
BuildDefsWithKills(tree, 0, RBM_NONE, RBM_NONE);
676+
BuildKills(tree, RBM_NONE);
677677
break;
678678

679679
case GT_CNS_DBL:
@@ -738,7 +738,7 @@ int LinearScan::BuildNode(GenTree* tree)
738738
case GT_RETURN:
739739
srcCount = BuildReturn(tree);
740740
killMask = getKillSetForReturn();
741-
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
741+
BuildKills(tree, killMask);
742742
break;
743743

744744
#ifdef SWIFT_SUPPORT
@@ -747,7 +747,7 @@ int LinearScan::BuildNode(GenTree* tree)
747747
// Plus one for error register
748748
srcCount = BuildReturn(tree) + 1;
749749
killMask = getKillSetForReturn();
750-
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
750+
BuildKills(tree, killMask);
751751
break;
752752
#endif // SWIFT_SUPPORT
753753

@@ -839,7 +839,7 @@ int LinearScan::BuildNode(GenTree* tree)
839839
srcCount = 1;
840840
assert(dstCount == 0);
841841
killMask = compiler->compHelperCallKillSet(CORINFO_HELP_STOP_FOR_GC);
842-
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
842+
BuildKills(tree, killMask);
843843
break;
844844

845845
case GT_MOD:
@@ -1927,11 +1927,11 @@ int LinearScan::BuildHWIntrinsic(GenTreeHWIntrinsic* intrinsicTree, int* pDstCou
19271927

19281928
if ((dstCount == 1) || (dstCount == 2))
19291929
{
1930-
BuildDef(intrinsicTree, dstCandidates);
1930+
BuildDef(intrinsicTree);
19311931

19321932
if (dstCount == 2)
19331933
{
1934-
BuildDef(intrinsicTree, dstCandidates, 1);
1934+
BuildDef(intrinsicTree, RBM_NONE, 1);
19351935
}
19361936
}
19371937
else

src/coreclr/jit/lsraarmarch.cpp

+37-21
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ int LinearScan::BuildIndir(GenTreeIndir* indirTree)
127127
//
128128
int LinearScan::BuildCall(GenTreeCall* call)
129129
{
130-
bool hasMultiRegRetVal = false;
131-
const ReturnTypeDesc* retTypeDesc = nullptr;
132-
regMaskTP dstCandidates = RBM_NONE;
130+
bool hasMultiRegRetVal = false;
131+
const ReturnTypeDesc* retTypeDesc = nullptr;
132+
regMaskTP singleDstCandidates = RBM_NONE;
133133

134134
int srcCount = 0;
135135
int dstCount = 0;
@@ -227,26 +227,24 @@ int LinearScan::BuildCall(GenTreeCall* call)
227227
{
228228
// The ARM CORINFO_HELP_INIT_PINVOKE_FRAME helper uses a custom calling convention that returns with
229229
// TCB in REG_PINVOKE_TCB. fgMorphCall() sets the correct argument registers.
230-
dstCandidates = RBM_PINVOKE_TCB;
230+
singleDstCandidates = RBM_PINVOKE_TCB;
231231
}
232232
else
233233
#endif // TARGET_ARM
234-
if (hasMultiRegRetVal)
235-
{
236-
assert(retTypeDesc != nullptr);
237-
dstCandidates = retTypeDesc->GetABIReturnRegs(call->GetUnmanagedCallConv());
238-
}
239-
else if (varTypeUsesFloatArgReg(registerType))
240-
{
241-
dstCandidates = RBM_FLOATRET;
242-
}
243-
else if (registerType == TYP_LONG)
244-
{
245-
dstCandidates = RBM_LNGRET;
246-
}
247-
else
234+
if (!hasMultiRegRetVal)
248235
{
249-
dstCandidates = RBM_INTRET;
236+
if (varTypeUsesFloatArgReg(registerType))
237+
{
238+
singleDstCandidates = RBM_FLOATRET;
239+
}
240+
else if (registerType == TYP_LONG)
241+
{
242+
singleDstCandidates = RBM_LNGRET;
243+
}
244+
else
245+
{
246+
singleDstCandidates = RBM_INTRET;
247+
}
250248
}
251249

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

400398
// Now generate defs and kills.
401399
regMaskTP killMask = getKillSetForCall(call);
402-
BuildDefsWithKills(call, dstCount, dstCandidates, killMask);
400+
if (dstCount > 0)
401+
{
402+
if (hasMultiRegRetVal)
403+
{
404+
assert(retTypeDesc != nullptr);
405+
regMaskTP multiDstCandidates = retTypeDesc->GetABIReturnRegs(call->GetUnmanagedCallConv());
406+
assert(genCountBits(multiDstCandidates) > 0);
407+
BuildCallDefsWithKills(call, dstCount, multiDstCandidates, killMask);
408+
}
409+
else
410+
{
411+
assert(dstCount == 1);
412+
BuildDefWithKills(call, singleDstCandidates, killMask);
413+
}
414+
}
415+
else
416+
{
417+
BuildKills(call, killMask);
418+
}
403419

404420
#ifdef SWIFT_SUPPORT
405421
if (call->HasSwiftErrorHandling())
@@ -836,7 +852,7 @@ int LinearScan::BuildBlockStore(GenTreeBlk* blkNode)
836852

837853
buildInternalRegisterUses();
838854
regMaskTP killMask = getKillSetForBlockStore(blkNode);
839-
BuildDefsWithKills(blkNode, 0, RBM_NONE, killMask);
855+
BuildKills(blkNode, killMask);
840856
return useCount;
841857
}
842858

0 commit comments

Comments
 (0)