Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
public sealed class InlineArrayAttribute : Attribute
{
public InlineArrayAttribute(int length)
{
Length = length;
}

public int Length { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<Compile Include="Internal\Runtime\MethodTable.Runtime.cs" />
<Compile Include="System\Runtime\CompilerServices\CastCache.cs" />
<Compile Include="System\Runtime\CompilerServices\ClassConstructorRunner.cs" />
<Compile Include="System\Runtime\CompilerServices\InlineArrayAttribute.cs" />
<Compile Include="System\Runtime\CompilerServices\StaticClassConstructionContext.cs" />
<Compile Include="System\Runtime\InteropServices\InAttribute.cs" />
<Compile Include="System\Diagnostics\CodeAnalysis\DoesNotReturnIfAttribute.cs" />
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/tools/Common/JitInterface/SwiftPhysicalLowering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ public List<CorInfoType> GetLoweredTypeSequence()
// opaque range of > 4 bytes that we must not pad to 8 bytes.


// As long as we need to fill more than 4 bytes and the sequence is currently 8-byte aligned, we'll split into 8-byte integers.
// If we have more than 2 bytes but less than 4 and the sequence is 4-byte aligned, we'll use a 4-byte integer to represent the rest of the parameters.
// If we have 2 bytes and the sequence is 2-byte aligned, we'll use a 2-byte integer to represent the rest of the parameters.
// If we have 1 byte, we'll use a 1-byte integer to represent the rest of the parameters.
// While we need to fill more than 4 bytes and the sequence is currently 8-byte aligned, we'll split into 8-byte integers.
// While we need to fill more than 2 bytes but less than 4 and the sequence is 4-byte aligned, we'll use a 4-byte integer to represent the rest of the parameters.
// While we need to fill more than 1 bytes and the sequence is 2-byte aligned, we'll use a 2-byte integer to represent the rest of the parameters.
// While we need to fill at least 1 byte, we'll use a 1-byte integer to represent the rest of the parameters.
int remainingIntervalSize = interval.Size;
while (remainingIntervalSize > 4 && loweredSequenceSize == loweredSequenceSize.AlignUp(8))
{
Expand All @@ -154,21 +154,21 @@ public List<CorInfoType> GetLoweredTypeSequence()
remainingIntervalSize -= 8;
}

if (remainingIntervalSize > 2 && loweredSequenceSize == loweredSequenceSize.AlignUp(4))
while (remainingIntervalSize > 2 && loweredSequenceSize == loweredSequenceSize.AlignUp(4))
{
loweredTypes.Add(CorInfoType.CORINFO_TYPE_INT);
loweredSequenceSize += 4;
remainingIntervalSize -= 4;
}

if (remainingIntervalSize > 1 && loweredSequenceSize == loweredSequenceSize.AlignUp(2))
while (remainingIntervalSize > 1 && loweredSequenceSize == loweredSequenceSize.AlignUp(2))
{
loweredTypes.Add(CorInfoType.CORINFO_TYPE_SHORT);
loweredSequenceSize += 2;
remainingIntervalSize -= 2;
}

if (remainingIntervalSize == 1)
while (remainingIntervalSize > 0)
{
loweredSequenceSize += 1;
loweredTypes.Add(CorInfoType.CORINFO_TYPE_BYTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public void AddToFieldLayout(int offset, TypeDesc fieldType, bool addTrailingEmp
{
if (NeedsRecursiveLayout(offset, fieldType))
{
if (fieldType is MetadataType { IsInlineArray: true } mdType)
{
fieldType = new TypeWithRepeatedFields(mdType);
}

List<FieldLayoutInterval> nestedIntervals = new List<FieldLayoutInterval>();
foreach (FieldDesc field in fieldType.GetFields())
{
Expand Down Expand Up @@ -123,6 +128,11 @@ private void AddToFieldLayout(List<FieldLayoutInterval> fieldLayout, int offset,
{
if (NeedsRecursiveLayout(offset, fieldType))
{
if (fieldType is MetadataType { IsInlineArray: true } mdType)
{
fieldType = new TypeWithRepeatedFields(mdType);
}

foreach (FieldDesc field in fieldType.GetFields())
{
int fieldOffset = offset + field.Offset.AsInt;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.TypeSystem;

namespace ILCompiler
namespace Internal.TypeSystem
{
public sealed class ImpliedRepeatedFieldDesc : FieldDesc
{
Expand Down Expand Up @@ -36,13 +34,13 @@ public ImpliedRepeatedFieldDesc(DefType owningType, FieldDesc underlyingFieldDes

public int FieldIndex { get; }

protected override int ClassCode => 31666958;
protected internal override int ClassCode => 31666958;

public override EmbeddedSignatureData[] GetEmbeddedSignatureData() => _underlyingFieldDesc.GetEmbeddedSignatureData();

public override bool HasCustomAttribute(string attributeNamespace, string attributeName) => _underlyingFieldDesc.HasCustomAttribute(attributeNamespace, attributeName);

protected override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
protected internal override int CompareToImpl(FieldDesc other, TypeSystemComparer comparer)
{
var impliedRepeatedFieldDesc = (ImpliedRepeatedFieldDesc)other;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Internal.TypeSystem;

namespace ILCompiler
namespace Internal.TypeSystem
{
/// <summary>
/// This type represents a type that has one field in metadata,
Expand Down Expand Up @@ -90,7 +89,7 @@ public override IEnumerable<FieldDesc> GetFields()
public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(string name) => MetadataType.FindMethodsImplWithMatchingDeclName(name);
public override int GetHashCode() => MetadataType.GetHashCode();
protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() => Array.Empty<MethodImplRecord>();
protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer) => comparer.Compare(MetadataType, ((TypeWithRepeatedFields)other).MetadataType);
protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer) => comparer.Compare(MetadataType, ((TypeWithRepeatedFields)other).MetadataType);

protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
{
Expand Down Expand Up @@ -166,7 +165,7 @@ protected override TypeFlags ComputeTypeFlags(TypeFlags mask)

public override TypeSystemContext Context => MetadataType.Context;

protected override int ClassCode => 779393465;
protected internal override int ClassCode => 779393465;

public override IEnumerable<MethodDesc> GetMethods() => MethodDesc.EmptyMethods;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Internal.TypeSystem;

namespace ILCompiler
namespace Internal.TypeSystem
{
/// <summary>
/// Represents an algorithm that computes field layout for intrinsic vector types (Vector64/Vector128/Vector256).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace ILCompiler.Compiler.Tests.Assets.SwiftTypes;
Expand Down Expand Up @@ -92,3 +93,20 @@ public struct F114_S0
public short F2;
public ushort F3;
}

[ExpectedLowering(ExpectedLoweringAttribute.Lowered.Double, ExpectedLoweringAttribute.Lowered.Float, ExpectedLoweringAttribute.Lowered.Int32, ExpectedLoweringAttribute.Lowered.Int32)]
[StructLayout(LayoutKind.Sequential, Size = 20)]
struct F352_S0
{
public double F0;
public float F1;
public uint F2;
public int F3;
}

[ExpectedLowering(ExpectedLoweringAttribute.Lowered.Int64, ExpectedLoweringAttribute.Lowered.Int64, ExpectedLoweringAttribute.Lowered.Int64, ExpectedLoweringAttribute.Lowered.Int64)]
[InlineArray(4)]
public struct InlineArray4Longs
{
private long l;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\Common\Compiler\ImpliedRepeatedFieldDesc.cs" Link="Compiler\ImpliedRepeatedFieldDesc.cs" />
<Compile Include="..\..\Common\Compiler\TypeWithRepeatedFields.cs" Link="Compiler\TypeWithRepeatedFields.cs" />
<Compile Include="..\..\Common\Compiler\TypeWithRepeatedFieldsFieldLayoutAlgorithm.cs" Link="Compiler\TypeWithRepeatedFieldsFieldLayoutAlgorithm.cs" />
<Compile Include="..\..\Common\Compiler\Win32Resources\ResourceData.cs" Link="Compiler\Win32Resources\ResourceData.cs" />
<Compile Include="..\..\Common\Compiler\Win32Resources\ResourceData.Reader.cs" Link="Compiler\Win32Resources\ResourceData.Reader.cs" />
<Compile Include="..\..\Common\Compiler\Win32Resources\ResourceData.ResourcesDataModel.cs" Link="Compiler\Win32Resources\ResourceData.ResourcesDataModel.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
<Import Project="..\..\Common\Compiler\GenericCycleDetection\GenericCycleDetection.projitems" />

<ItemGroup>
<Compile Include="..\..\Common\Compiler\ImpliedRepeatedFieldDesc.cs" Link="Compiler\ImpliedRepeatedFieldDesc.cs" />
<Compile Include="..\..\Common\Compiler\TypeWithRepeatedFields.cs" Link="Compiler\TypeWithRepeatedFields.cs" />
<Compile Include="..\..\Common\Compiler\TypeWithRepeatedFieldsFieldLayoutAlgorithm.cs" Link="Compiler\TypeWithRepeatedFieldsFieldLayoutAlgorithm.cs" />
<Compile Include="..\..\Common\Internal\Runtime\CorConstants.cs" Link="Common\CorConstants.cs" />
<Compile Include="..\..\Common\Internal\Runtime\ReadyToRunConstants.cs" Link="Common\ReadyToRunConstants.cs" />
<Compile Include="..\..\Common\Internal\Runtime\ReadyToRunInstructionSet.cs" Link="Common\ReadyToRunInstructionSet.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@
<Compile Include="..\..\Common\TypeSystem\Common\ThrowHelper.Common.cs">
<Link>TypeSystem\Common\ThrowHelper.Common.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\TypeWithRepeatedFields.cs">
<Link>TypeSystem\Common\TypeWithRepeatedFields.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\TypeWithRepeatedFieldsFieldLayoutAlgorithm.cs">
<Link>TypeSystem\Common\TypeWithRepeatedFieldsFieldLayoutAlgorithm.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\UniversalCanonLayoutAlgorithm.cs">
<Link>TypeSystem\Common\UniversalCanonLayoutAlgorithm.cs</Link>
</Compile>
Expand Down Expand Up @@ -236,6 +242,9 @@
<Compile Include="..\..\Common\TypeSystem\Common\FieldLayoutAlgorithm.cs">
<Link>TypeSystem\Common\FieldLayoutAlgorithm.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\ImpliedRepeatedFieldDesc.cs">
<Link>TypeSystem\Common\ImpliedRepeatedFieldDesc.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\InstantiatedMethod.cs">
<Link>TypeSystem\Common\InstantiatedMethod.cs</Link>
</Compile>
Expand Down