Skip to content

Commit

Permalink
[LoongArch64] Synchronize with PR#102469. (#102638)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyXu-HF authored May 24, 2024
1 parent fc5b6e7 commit bbcde65
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/jit/lsra.h
Original file line number Diff line number Diff line change
Expand Up @@ -2014,11 +2014,11 @@ class LinearScan : public LinearScanInterface
void BuildDefs(GenTree* tree, int dstCount, regMaskTP dstCandidates = RBM_NONE);
void BuildCallDefs(GenTree* tree, int dstCount, regMaskTP dstCandidates);
void BuildKills(GenTree* tree, regMaskTP killMask);
#if defined(TARGET_ARMARCH) || defined(TARGET_RISCV64)
#if defined(TARGET_ARMARCH) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
void BuildDefWithKills(GenTree* tree, regMaskTP dstCandidates, regMaskTP killMask);
#else
void BuildDefWithKills(GenTree* tree, int dstCount, regMaskTP dstCandidates, regMaskTP killMask);
#endif // TARGET_ARMARCH || TARGET_RISCV64
#endif // TARGET_ARMARCH || TARGET_RISCV64 || TARGET_LOONGARCH64
void BuildCallDefsWithKills(GenTree* tree, int dstCount, regMaskTP dstCandidates, regMaskTP killMask);

int BuildReturn(GenTree* tree);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsrabuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3240,7 +3240,7 @@ void LinearScan::BuildKills(GenTree* tree, regMaskTP killMask)
}
}

#if defined(TARGET_ARMARCH) || defined(TARGET_RISCV64)
#if defined(TARGET_ARMARCH) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)

//------------------------------------------------------------------------
// BuildDefWithKills: Build one RefTypeDef RefPositions for the given node,
Expand Down
64 changes: 40 additions & 24 deletions src/coreclr/jit/lsraloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,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 @@ -170,7 +170,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 Expand Up @@ -267,7 +267,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_MUL:
Expand Down Expand Up @@ -679,9 +679,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 @@ -745,22 +745,20 @@ int LinearScan::BuildCall(GenTreeCall* call)

// Set destination candidates for return value of the call.

if (hasMultiRegRetVal)
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
{
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 @@ -872,7 +870,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);
}

// No args are placed in registers anymore.
placedArgRegs = RBM_NONE;
Expand Down Expand Up @@ -1189,7 +1205,7 @@ int LinearScan::BuildBlockStore(GenTreeBlk* blkNode)

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

Expand Down

0 comments on commit bbcde65

Please sign in to comment.