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

[RISC-V] Fix MarshalStructAsLayoutSeq #90719

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ var_types Compiler::getReturnTypeForStruct(CORINFO_CLASS_HANDLE clsHnd,

#elif defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)

// On LOONGARCH64 struct that is 1-16 bytes is returned by value in one/two register(s)
// On LOONGARCH64/RISCV64 struct that is 1-16 bytes is returned by value in one/two register(s)
howToReturnStruct = SPK_ByValue;
useType = TYP_STRUCT;

Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25620,6 +25620,13 @@ void ReturnTypeDesc::InitializeStructReturnType(Compiler* comp,
m_regType[1] =
(floatFieldFlags & STRUCT_SECOND_FIELD_SIZE_IS8) ? comp->getJitGCType(gcPtrs[1]) : TYP_INT;
}
#ifdef TARGET_RISCV64
else if ((floatFieldFlags | STRUCT_FLOAT_FIELD_SECOND | STRUCT_FIRST_FIELD_SIZE_IS8) == floatFieldFlags)
{
m_regType[0] = comp->getJitGCType(gcPtrs[0]);
m_regType[1] = comp->getJitGCType(gcPtrs[1]);
}
#endif // TARGET_RISCV64
else if (floatFieldFlags & STRUCT_FLOAT_FIELD_SECOND)
{
comp->compFloatingPointUsed = true;
Expand Down
11 changes: 11 additions & 0 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,15 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un
argRegTypeInStruct1 = (floatFlags & STRUCT_FIRST_FIELD_SIZE_IS8) ? TYP_DOUBLE : TYP_FLOAT;
argRegTypeInStruct2 = (floatFlags & STRUCT_SECOND_FIELD_SIZE_IS8) ? TYP_LONG : TYP_INT;
}
#ifdef TARGET_RISCV64
else if ((floatFlags | STRUCT_FLOAT_FIELD_SECOND | STRUCT_FIRST_FIELD_SIZE_IS8) == floatFlags)
{
canPassArgInRegisters = varDscInfo->canEnreg(TYP_LONG, 2);

argRegTypeInStruct1 = TYP_LONG;
argRegTypeInStruct2 = TYP_LONG;
}
#endif // TARGET_RISCV64
clamp03 marked this conversation as resolved.
Show resolved Hide resolved
else if ((floatFlags & STRUCT_FLOAT_FIELD_SECOND) != 0)
{
floatNum = 1;
Expand All @@ -892,7 +901,9 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un
argRegTypeInStruct2 = (floatFlags & STRUCT_SECOND_FIELD_SIZE_IS8) ? TYP_DOUBLE : TYP_FLOAT;
}

#ifndef TARGET_RISCV64
assert((floatNum == 1) || (floatNum == 2));
#endif // !TARGET_RISCV64

if (!canPassArgInRegisters)
{
Expand Down
27 changes: 25 additions & 2 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,13 @@ void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call
#endif

passUsingFloatRegs = (floatFieldFlags & STRUCT_HAS_FLOAT_FIELDS_MASK) ? true : false;

#ifdef TARGET_RISCV64
passUsingFloatRegs =
passUsingFloatRegs &&
((floatFieldFlags | STRUCT_FLOAT_FIELD_SECOND | STRUCT_FIRST_FIELD_SIZE_IS8) != floatFieldFlags);
#endif // TARGET_RISCV64

comp->compFloatingPointUsed |= passUsingFloatRegs;

if ((floatFieldFlags & (STRUCT_HAS_FLOAT_FIELDS_MASK ^ STRUCT_FLOAT_FIELD_ONLY_ONE)) != 0)
Expand All @@ -2475,8 +2482,14 @@ void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call
// TODO-LoongArch64: fix "getPrimitiveTypeForStruct".
structBaseType = TYP_STRUCT;
}

if ((floatFieldFlags & (STRUCT_HAS_FLOAT_FIELDS_MASK ^ STRUCT_FLOAT_FIELD_ONLY_TWO)) != 0)
#ifdef TARGET_RISCV64
if ((floatFieldFlags | STRUCT_FLOAT_FIELD_SECOND | STRUCT_FIRST_FIELD_SIZE_IS8) == floatFieldFlags)
{
size = 2;
}
else
#endif // TARGET_RISCV64
if ((floatFieldFlags & (STRUCT_HAS_FLOAT_FIELDS_MASK ^ STRUCT_FLOAT_FIELD_ONLY_TWO)) != 0)
{
size = 1;
}
Expand Down Expand Up @@ -2892,6 +2905,16 @@ void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call
assert(size == 2);
intArgRegNum = maxRegArgs;
}
#ifdef TARGET_RISCV64
else if ((floatFieldFlags | STRUCT_FLOAT_FIELD_SECOND | STRUCT_FIRST_FIELD_SIZE_IS8) ==
floatFieldFlags)
{
assert(!passUsingFloatRegs);
arg.AbiInfo.StructFloatFieldType[0] = TYP_LONG;
arg.AbiInfo.StructFloatFieldType[1] = TYP_LONG;
intArgRegNum += size;
}
#endif // TARGET_RISCV64
else if ((floatFieldFlags & STRUCT_HAS_FLOAT_FIELDS_MASK) == 0x0)
{
if (passUsingFloatRegs)
Expand Down