Skip to content

Commit

Permalink
Remove old StructFloatFieldInfoFlags calculating routine
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeksowi committed Jun 25, 2024
1 parent 3d139ac commit 89cc148
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 324 deletions.
122 changes: 1 addition & 121 deletions src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,116 +16,6 @@ private const int
ENREGISTERED_PARAMTYPE_MAXSIZE = 16,

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build tvos-arm64 Release AllSubsets_NativeAOT)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-arm Debug AllSubsets_CoreCLR_ReleaseRuntimeLibs)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build ios-arm64 Release AllSubsets_NativeAOT)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 checked CLR_Tools_Tests)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm Debug AllSubsets_CoreCLR_ReleaseRuntimeLibs)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm checked CoreCLR_ReleaseLibraries)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-arm checked CoreCLR_ReleaseLibraries)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-arm64 Debug AllSubsets_CoreCLR_ReleaseRuntimeLibs)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug AllSubsets_CoreCLR)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests (Build linux-x64 release Runtime_Release)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug AllSubsets_CoreCLR)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug AllSubsets_CoreCLR)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Libraries_CheckedCoreCLR)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-arm64 checked CoreCLR_ReleaseLibraries)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Libraries_CheckedCoreCLR)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 checked CoreCLR_ReleaseLibraries)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug CoreCLR_Libraries)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build freebsd-x64 Debug CoreCLR)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug Libraries_CheckedCoreCLR)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests (Build osx-x64 release Runtime_Release)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)

Check failure on line 16 in src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug Libraries_CheckedCoreCLR)

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs#L16

src/coreclr/tools/Common/JitInterface/RISCV64PassStructInRegister.cs(16,13): error CA1823: (NETCORE_ENGINEERING_TELEMETRY=Build) Unused field 'ENREGISTERED_PARAMTYPE_MAXSIZE' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1823)
TARGET_POINTER_SIZE = 8;

private static bool HandleInlineArrayOld(int elementTypeIndex, int nElements, Span<StructFloatFieldInfoFlags> types, ref int typeIndex)
{
int nFlattenedFieldsPerElement = typeIndex - elementTypeIndex;
if (nFlattenedFieldsPerElement == 0)
return true;

Debug.Assert(nFlattenedFieldsPerElement == 1 || nFlattenedFieldsPerElement == 2);

if (nElements > 2)
return false;

if (nElements == 2)
{
if (typeIndex + nFlattenedFieldsPerElement > 2)
return false;

Debug.Assert(elementTypeIndex == 0);
Debug.Assert(typeIndex == 1);
types[typeIndex++] = types[elementTypeIndex]; // duplicate the array element type
}
return true;
}

private static bool FlattenFieldTypesOld(TypeDesc td, Span<StructFloatFieldInfoFlags> types, ref int typeIndex)
{
IEnumerable<FieldDesc> fields = td.GetFields();
int nFields = 0;
int elementTypeIndex = typeIndex;
FieldDesc prevField = null;
foreach (FieldDesc field in fields)
{
if (field.IsStatic)
continue;
nFields++;

if (prevField != null && prevField.Offset.AsInt + prevField.FieldType.GetElementSize().AsInt > field.Offset.AsInt)
return false; // overlapping fields

prevField = field;

TypeFlags category = field.FieldType.Category;
if (category == TypeFlags.ValueType)
{
TypeDesc nested = field.FieldType;
if (!FlattenFieldTypesOld(nested, types, ref typeIndex))
return false;
}
else if (field.FieldType.GetElementSize().AsInt <= TARGET_POINTER_SIZE)
{
if (typeIndex >= 2)
return false;

StructFloatFieldInfoFlags type =
(category is TypeFlags.Single or TypeFlags.Double ? STRUCT_FLOAT_FIELD_FIRST : (StructFloatFieldInfoFlags)0) |
(field.FieldType.GetElementSize().AsInt == TARGET_POINTER_SIZE ? STRUCT_FIRST_FIELD_SIZE_IS8 : (StructFloatFieldInfoFlags)0);
types[typeIndex++] = type;
}
else
{
return false;
}
}

if ((td as MetadataType).HasImpliedRepeatedFields())
{
Debug.Assert(nFields == 1);
int nElements = td.GetElementSize().AsInt / prevField.FieldType.GetElementSize().AsInt;
if (!HandleInlineArrayOld(elementTypeIndex, nElements, types, ref typeIndex))
return false;
}
return true;
}

private static uint GetRISCV64PassStructInRegisterFlags(TypeDesc td)
{
if (td.GetElementSize().AsInt > ENREGISTERED_PARAMTYPE_MAXSIZE)
return (uint)STRUCT_NO_FLOAT_FIELD;

Span<StructFloatFieldInfoFlags> types = stackalloc StructFloatFieldInfoFlags[] {
STRUCT_NO_FLOAT_FIELD, STRUCT_NO_FLOAT_FIELD
};
int nFields = 0;
if (!FlattenFieldTypesOld(td, types, ref nFields) || nFields == 0)
return (uint)STRUCT_NO_FLOAT_FIELD;

Debug.Assert(nFields == 1 || nFields == 2);

Debug.Assert((uint)(STRUCT_FLOAT_FIELD_SECOND | STRUCT_SECOND_FIELD_SIZE_IS8)
== (uint)(STRUCT_FLOAT_FIELD_FIRST | STRUCT_FIRST_FIELD_SIZE_IS8) << 1,
"SECOND flags need to be FIRST shifted by 1");
StructFloatFieldInfoFlags flags = types[0] | (StructFloatFieldInfoFlags)((uint)types[1] << 1);

const StructFloatFieldInfoFlags bothFloat = STRUCT_FLOAT_FIELD_FIRST | STRUCT_FLOAT_FIELD_SECOND;
if ((flags & bothFloat) == 0)
return (uint)STRUCT_NO_FLOAT_FIELD;

if ((flags & bothFloat) == bothFloat)
{
Debug.Assert(nFields == 2);
flags ^= (bothFloat | STRUCT_FLOAT_FIELD_ONLY_TWO); // replace bothFloat with ONLY_TWO
}
else if (nFields == 1)
{
Debug.Assert((flags & STRUCT_FLOAT_FIELD_FIRST) != 0);
flags ^= (STRUCT_FLOAT_FIELD_FIRST | STRUCT_FLOAT_FIELD_ONLY_ONE); // replace FIRST with ONLY_ONE
}
return (uint)flags;
}


private static void SetFpStructInRegistersInfoField(ref FpStructInRegistersInfo info, int index,
bool isFloating, FpStruct_IntKind intKind, uint size, uint offset)
{
Expand Down Expand Up @@ -252,7 +142,7 @@ TypeFlags.Array or

private static bool IsAligned(uint val, uint alignment) => 0 == (val & (alignment - 1));

private static FpStructInRegistersInfo GetRiscV64PassFpStructInRegistersInfoImpl(TypeDesc td)
public static FpStructInRegistersInfo GetRiscV64PassFpStructInRegistersInfo(TypeDesc td)
{
FpStructInRegistersInfo info = new FpStructInRegistersInfo{};
int nFields = 0;
Expand Down Expand Up @@ -305,15 +195,5 @@ private static FpStructInRegistersInfo GetRiscV64PassFpStructInRegistersInfoImpl

return info;
}

public static FpStructInRegistersInfo GetRiscV64PassFpStructInRegistersInfo(TypeDesc td)
{
FpStructInRegistersInfo info = GetRiscV64PassFpStructInRegistersInfoImpl(td);
uint flags = GetRISCV64PassStructInRegisterFlags(td);

Debug.Assert(flags == (uint)info.ToOldFlags());

return info;
}
}
}
207 changes: 5 additions & 202 deletions src/coreclr/vm/methodtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2715,194 +2715,6 @@ void MethodTable::AssignClassifiedEightByteTypes(SystemVStructRegisterPassingHe

#endif // defined(UNIX_AMD64_ABI_ITF)

#if defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
static bool HandleInlineArrayOld(int elementTypeIndex, int nElements, StructFloatFieldInfoFlags types[2], int& typeIndex)
{
int nFlattenedFieldsPerElement = typeIndex - elementTypeIndex;
if (nFlattenedFieldsPerElement == 0)
return true;

assert(nFlattenedFieldsPerElement == 1 || nFlattenedFieldsPerElement == 2);

if (nElements > 2)
return false;

if (nElements == 2)
{
if (typeIndex + nFlattenedFieldsPerElement > 2)
return false;

assert(elementTypeIndex == 0);
assert(typeIndex == 1);
types[typeIndex] = types[elementTypeIndex]; // duplicate the array element type
}
return true;
}

static bool FlattenFieldTypesOld(TypeHandle th, StructFloatFieldInfoFlags types[2], int& typeIndex)
{
bool isManaged = !th.IsTypeDesc();
MethodTable* pMT = isManaged ? th.AsMethodTable() : th.AsNativeValueType();
int nFields = isManaged ? pMT->GetNumIntroducedInstanceFields() : pMT->GetNativeLayoutInfo()->GetNumFields();

// TODO: templatize isManaged and use if constexpr for differences when we migrate to C++17
// because the logic for both branches is nearly the same.
if (isManaged)
{
FieldDesc* fields = pMT->GetApproxFieldDescListRaw();
int elementTypeIndex = typeIndex;
for (int i = 0; i < nFields; ++i)
{
if (i > 0 && fields[i-1].GetOffset() + fields[i-1].GetSize() > fields[i].GetOffset())
return false; // overlapping fields

CorElementType type = fields[i].GetFieldType();
if (type == ELEMENT_TYPE_VALUETYPE)
{
MethodTable* nested = fields[i].GetApproxFieldTypeHandleThrowing().GetMethodTable();
if (!FlattenFieldTypesOld(TypeHandle(nested), types, typeIndex))
return false;
}
else if (fields[i].GetSize() <= TARGET_POINTER_SIZE)
{
if (typeIndex >= 2)
return false;

StructFloatFieldInfoFlags retType = StructFloatFieldInfoFlags(
(CorTypeInfo::IsFloat_NoThrow(type) ? STRUCT_FLOAT_FIELD_FIRST : 0) |
(CorTypeInfo::Size_NoThrow(type) == TARGET_POINTER_SIZE ? STRUCT_FIRST_FIELD_SIZE_IS8 : 0));
types[typeIndex++] = retType;
}
else
{
return false;
}
}

if (HasImpliedRepeatedFields(pMT)) // inline array or fixed buffer
{
assert(nFields == 1);
int nElements = pMT->GetNumInstanceFieldBytes() / fields[0].GetSize();
if (!HandleInlineArrayOld(elementTypeIndex, nElements, types, typeIndex))
return false;
}
}
else // native layout
{
const NativeFieldDescriptor* fields = pMT->GetNativeLayoutInfo()->GetNativeFieldDescriptors();
for (int i = 0; i < nFields; ++i)
{
if (i > 0 && fields[i-1].GetExternalOffset() + fields[i-1].NativeSize() > fields[i].GetExternalOffset())
return false; // overlapping fields

NativeFieldCategory category = fields[i].GetCategory();
if (category == NativeFieldCategory::NESTED)
{
int elementTypeIndex = typeIndex;

MethodTable* nested = fields[i].GetNestedNativeMethodTable();
if (!FlattenFieldTypesOld(TypeHandle(nested), types, typeIndex))
return false;

// In native layout fixed arrays are marked as NESTED just like structs
int nElements = fields[i].GetNumElements();
if (!HandleInlineArrayOld(elementTypeIndex, nElements, types, typeIndex))
return false;
}
else if (fields[i].NativeSize() <= TARGET_POINTER_SIZE)
{
if (typeIndex >= 2)
return false;

StructFloatFieldInfoFlags type = StructFloatFieldInfoFlags(
(category == NativeFieldCategory::FLOAT ? STRUCT_FLOAT_FIELD_FIRST : 0) |
(fields[i].NativeSize() == TARGET_POINTER_SIZE ? STRUCT_FIRST_FIELD_SIZE_IS8 : 0));
types[typeIndex++] = type;
}
else
{
return false;
}
}
}
return true;
}
#endif

#if defined(TARGET_LOONGARCH64)
int MethodTable::GetLoongArch64PassStructInRegisterFlags(TypeHandle th)
{
if (th.GetSize() > ENREGISTERED_PARAMTYPE_MAXSIZE)
return STRUCT_NO_FLOAT_FIELD;

StructFloatFieldInfoFlags types[2] = {STRUCT_NO_FLOAT_FIELD, STRUCT_NO_FLOAT_FIELD};
int nFields = 0;
if (!FlattenFieldTypesOld(th, types, nFields) || nFields == 0)
return STRUCT_NO_FLOAT_FIELD;

assert(nFields == 1 || nFields == 2);

static_assert((STRUCT_FLOAT_FIELD_SECOND | STRUCT_SECOND_FIELD_SIZE_IS8)
== (STRUCT_FLOAT_FIELD_FIRST | STRUCT_FIRST_FIELD_SIZE_IS8) << 1,
"SECOND flags need to be FIRST shifted by 1");
int flags = types[0] | (types[1] << 1);

static const int bothFloat = STRUCT_FLOAT_FIELD_FIRST | STRUCT_FLOAT_FIELD_SECOND;
if ((flags & bothFloat) == 0)
return STRUCT_NO_FLOAT_FIELD;

if ((flags & bothFloat) == bothFloat)
{
assert(nFields == 2);
flags ^= (bothFloat | STRUCT_FLOAT_FIELD_ONLY_TWO); // replace bothFloat with ONLY_TWO
}
else if (nFields == 1)
{
assert((flags & STRUCT_FLOAT_FIELD_FIRST) != 0);
flags ^= (STRUCT_FLOAT_FIELD_FIRST | STRUCT_FLOAT_FIELD_ONLY_ONE); // replace FIRST with ONLY_ONE
}

return flags;
}
#endif

#if defined(TARGET_RISCV64)
static int GetRiscV64PassStructInRegisterFlags(TypeHandle th)
{
if (th.GetSize() > ENREGISTERED_PARAMTYPE_MAXSIZE)
return STRUCT_NO_FLOAT_FIELD;

StructFloatFieldInfoFlags types[2] = {STRUCT_NO_FLOAT_FIELD, STRUCT_NO_FLOAT_FIELD};
int nFields = 0;
if (!FlattenFieldTypesOld(th, types, nFields) || nFields == 0)
return STRUCT_NO_FLOAT_FIELD;

assert(nFields == 1 || nFields == 2);

static_assert((STRUCT_FLOAT_FIELD_SECOND | STRUCT_SECOND_FIELD_SIZE_IS8)
== (STRUCT_FLOAT_FIELD_FIRST | STRUCT_FIRST_FIELD_SIZE_IS8) << 1,
"SECOND flags need to be FIRST shifted by 1");
int flags = types[0] | (types[1] << 1);

static const int bothFloat = STRUCT_FLOAT_FIELD_FIRST | STRUCT_FLOAT_FIELD_SECOND;
if ((flags & bothFloat) == 0)
return STRUCT_NO_FLOAT_FIELD;

if ((flags & bothFloat) == bothFloat)
{
assert(nFields == 2);
flags ^= (bothFloat | STRUCT_FLOAT_FIELD_ONLY_TWO); // replace bothFloat with ONLY_TWO
}
else if (nFields == 1)
{
assert((flags & STRUCT_FLOAT_FIELD_FIRST) != 0);
flags ^= (STRUCT_FLOAT_FIELD_FIRST | STRUCT_FLOAT_FIELD_ONLY_ONE); // replace FIRST with ONLY_ONE
}

return flags;
}
#endif

#if defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
static void SetFpStructInRegistersInfoField(FpStructInRegistersInfo& info, int index,
bool isFloating, FpStruct::IntKind intKind, unsigned size, uint32_t offset)
Expand Down Expand Up @@ -3118,11 +2930,12 @@ static bool FlattenFields(TypeHandle th, uint32_t offset, FpStructInRegistersInf
}
return true;
}
#endif

#if defined(TARGET_RISCV64)

static FpStructInRegistersInfo GetRiscV64PassFpStructInRegistersInfoImpl(TypeHandle th)
FpStructInRegistersInfo MethodTable::GetRiscV64PassFpStructInRegistersInfo(TypeHandle th)
#elif defined(TARGET_LOONGARCH64)
FpStructInRegistersInfo MethodTable::GetLoongArch64PassFpStructInRegistersInfo(TypeHandle th)
#endif
{
FpStructInRegistersInfo info = {};
int nFields = 0;
Expand Down Expand Up @@ -3184,17 +2997,7 @@ static FpStructInRegistersInfo GetRiscV64PassFpStructInRegistersInfoImpl(TypeHan
));
return info;
}

FpStructInRegistersInfo MethodTable::GetRiscV64PassFpStructInRegistersInfo(TypeHandle th)
{
FpStructInRegistersInfo info = GetRiscV64PassFpStructInRegistersInfoImpl(th);
int flags = GetRiscV64PassStructInRegisterFlags(th);

assert(flags == info.ToOldFlags());

return info;
}
#endif // TARGET_RISCV64
#endif // defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)

#if !defined(DACCESS_COMPILE)
namespace
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/methodtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ class MethodTable
void CheckRunClassInitAsIfConstructingThrowing();

#if defined(TARGET_LOONGARCH64)
static int GetLoongArch64PassStructInRegisterFlags(TypeHandle th);
static FpStructInRegistersInfo GetLoongArch64PassFpStructInRegistersInfo(TypeHandle th);
#elif defined(TARGET_RISCV64)
static FpStructInRegistersInfo GetRiscV64PassFpStructInRegistersInfo(TypeHandle th);
#endif
Expand Down

0 comments on commit 89cc148

Please sign in to comment.