Skip to content

Commit

Permalink
fixed the split error for LoongArch64. (dotnet#101656)
Browse files Browse the repository at this point in the history
* fixed the split error for LoongArch64.

* amend code for CRs.

* amend the splitting's judge independent of the `var->lvIsSplit` which
will be delete in future.
  • Loading branch information
shushanhf authored and matouskozak committed Apr 30, 2024
1 parent f6a5bd5 commit d9e0723
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/coreclr/jit/abi.cpp
Expand Up @@ -259,13 +259,17 @@ bool ABIPassingInformation::HasExactlyOneStackSegment() const
bool ABIPassingInformation::IsSplitAcrossRegistersAndStack() const
{
if (NumSegments < 2)
{
return false;
}

bool isFirstInReg = Segments[0].IsPassedInRegister();
for (unsigned i = 1; i < NumSegments; i++)
{
if (isFirstInReg != Segments[i].IsPassedInRegister())
{
return true;
}
}
return false;
}
Expand Down
55 changes: 36 additions & 19 deletions src/coreclr/jit/codegencommon.cpp
Expand Up @@ -4119,7 +4119,7 @@ void CodeGen::genEnregisterOSRArgsAndLocals()
}
}

#if defined(SWIFT_SUPPORT) || defined(TARGET_RISCV64)
#if defined(SWIFT_SUPPORT) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
//-----------------------------------------------------------------------------
// genHomeSwiftStructParameters: Move the incoming segment to the local stack frame.
//
Expand Down Expand Up @@ -4159,8 +4159,16 @@ void CodeGen::genHomeStackSegment(unsigned lclNum,
}
emitAttr size = emitTypeSize(loadType);

int loadOffset =
-(isFramePointerUsed() ? genCallerSPtoFPdelta() : genCallerSPtoInitialSPdelta()) + (int)seg.GetStackOffset();
int loadOffset = (int)seg.GetStackOffset();
if (isFramePointerUsed())
{
loadOffset -= genCallerSPtoFPdelta();
}
else
{
loadOffset -= genCallerSPtoInitialSPdelta();
}

#ifdef TARGET_XARCH
GetEmitter()->emitIns_R_AR(ins_Load(loadType), size, initReg, genFramePointerReg(), loadOffset);
#else
Expand All @@ -4171,7 +4179,7 @@ void CodeGen::genHomeStackSegment(unsigned lclNum,
if (initRegStillZeroed)
*initRegStillZeroed = false;
}
#endif // defined(SWIFT_SUPPORT) || defined(TARGET_RISCV64)
#endif // defined(SWIFT_SUPPORT) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)

#ifdef SWIFT_SUPPORT

Expand Down Expand Up @@ -4248,32 +4256,41 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack)
//
void CodeGen::genHomeStackPartOfSplitParameter(regNumber initReg, bool* initRegStillZeroed)
{
#ifdef TARGET_RISCV64
#if defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
unsigned lclNum = 0;
for (; lclNum < compiler->info.compArgsCount; lclNum++)
{
LclVarDsc* var = compiler->lvaGetDesc(lclNum);
if (!var->lvIsSplit || !var->lvOnFrame)
if (!var->lvOnFrame || !varTypeIsStruct(var))
{
continue;
}

JITDUMP("Homing stack part of split parameter V%02u\n", lclNum);

assert(varTypeIsStruct(var));
assert(!compiler->lvaIsImplicitByRefLocal(lclNum));
const ABIPassingInformation& abiInfo = compiler->lvaGetParameterABIInfo(lclNum);
assert(abiInfo.NumSegments == 2);
assert(abiInfo.Segments[0].GetRegister() == REG_ARG_LAST);
const ABIPassingSegment& seg = abiInfo.Segments[1];
if (abiInfo.IsSplitAcrossRegistersAndStack())
{
assert(var->lvIsSplit);
JITDUMP("Homing stack part of split parameter V%02u\n", lclNum);

genHomeStackSegment(lclNum, seg, initReg, initRegStillZeroed);
assert(abiInfo.NumSegments == 2);
assert(abiInfo.Segments[0].GetRegister() == REG_ARG_LAST);
assert(abiInfo.Segments[1].GetStackOffset() == 0);
const ABIPassingSegment& seg = abiInfo.Segments[1];

for (lclNum += 1; lclNum < compiler->info.compArgsCount; lclNum++)
{
assert(!compiler->lvaGetDesc(lclNum)->lvIsSplit); // There should be only one split parameter
genHomeStackSegment(lclNum, seg, initReg, initRegStillZeroed);

#ifdef DEBUG
for (lclNum += 1; lclNum < compiler->info.compArgsCount; lclNum++)
{
const ABIPassingInformation& abiInfo2 = compiler->lvaGetParameterABIInfo(lclNum);
// There should be only one split parameter
assert(!abiInfo2.IsSplitAcrossRegistersAndStack());
}
#endif
break;
}
break;
}
#endif
#endif // TARGET_RISCV64 || TARGET_LOONGARCH64
}

/*-----------------------------------------------------------------------------
Expand Down

0 comments on commit d9e0723

Please sign in to comment.