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

[NativeAOT-LLVM] Address post-merge tasks #2542

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
<PropertyGroup Label="CalculateTargetAuxiliary">
<!-- Will include wasm64 once we support it -->
<TargetsWasm Condition="'$(TargetArchitecture)' == 'wasm'">true</TargetsWasm>
<TargetsSingleThreadedWasm Condition="'$(TargetsWasm)' == 'true' and '$(FeatureWasmThreads)' != 'true'">true</TargetsSingleThreadedWasm>
<TargetsSingleThreadedWasm Condition="'$(TargetsWasm)' == 'true' and '$(WasmEnableThreads)' != 'true'">true</TargetsSingleThreadedWasm>
</PropertyGroup>

<PropertyGroup Label="CalculateTargetOSName">
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/llvmcodegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,7 @@ bool Llvm::isAddressAligned(GenTree* addr, unsigned alignment)

// TODO-LLVM-CQ: support array elements here using ARR_ADDR.
// TODO-LLVM-CQ: support static fields (using field sequences). Likewise with larger than pointer size fields.
return false;
return alignment == 1; // Any address is aligned to one byte.
}

Value* Llvm::consumeInitVal(GenTree* initVal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@
<PropertyGroup>
<MonoBclSourcesRoot>$([MSBuild]::NormalizePath('$(MonoProjectRoot)', 'System.Private.CoreLib', 'src'))</MonoBclSourcesRoot>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsBrowser)' == 'true' and '$(FeatureWasmThreads)' != 'true'">
<ItemGroup Condition="'$(TargetsBrowser)' == 'true' and '$(TargetsSingleThreadedWasm)' == 'true'">
<Compile Include="$(MonoBclSourcesRoot)\System\Threading\ThreadPoolBoundHandle.Browser.Mono.cs" />
<Compile Include="$(MonoBclSourcesRoot)\System\Threading\PreAllocatedOverlapped.Browser.Mono.cs" />
<Compile Include="$(MonoBclSourcesRoot)\System\Threading\ThreadPool.Browser.Mono.cs" />
<Compile Include="$(MonoBclSourcesRoot)\System\Threading\TimerQueue.Browser.Mono.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWasi)' == 'true' and '$(FeatureWasmThreads)' != 'true'">
<ItemGroup Condition="'$(TargetsWasi)' == 'true' and '$(TargetsSingleThreadedWasm)' == 'true'">
<Compile Include="$(MonoBclSourcesRoot)\System\Threading\ThreadPoolBoundHandle.Browser.Mono.cs" />
<Compile Include="$(MonoBclSourcesRoot)\System\Threading\PreAllocatedOverlapped.Browser.Mono.cs" />
<Compile Include="$(MonoBclSourcesRoot)\System\Threading\ThreadPool.Wasi.Mono.cs" />
Expand Down Expand Up @@ -554,10 +554,10 @@
<Compile Include="$(RuntimeBasePath)System\Runtime\GCStress.cs">
<Link>Runtime.Base\src\System\Runtime\GCStress.cs</Link>
</Compile>
<Compile Include="$(RuntimeBasePath)System\Runtime\__Finalizer.cs" Condition="'$(WasmAbi)' != 'true' or '$(FeatureWasmThreads)' == 'true'">
<Compile Include="$(RuntimeBasePath)System\Runtime\__Finalizer.cs" Condition="'$(TargetsSingleThreadedWasm)' != 'true'">
<Link>Runtime.Base\src\System\Runtime\__Finalizer.cs</Link>
</Compile>
<Compile Include="$(RuntimeBasePath)System\Runtime\__Finalizer.SingleThreaded.cs" Condition="'$(WasmAbi)' == 'true' and '$(FeatureWasmThreads)' != 'true'">
<Compile Include="$(RuntimeBasePath)System\Runtime\__Finalizer.SingleThreaded.cs" Condition="'$(TargetsSingleThreadedWasm)' == 'true'">
<Link>Runtime.Base\src\System\Runtime\__Finalizer.SingleThreaded.cs</Link>
</Compile>
<Compile Include="$(RuntimeBasePath)System\Runtime\MethodTable.Runtime.cs">
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
<Compile Include="..\..\Runtime.Base\src\System\Runtime\GCStress.cs">
<Link>Runtime.Base\src\System\Runtime\GCStress.cs</Link>
</Compile>
<Compile Include="..\..\Runtime.Base\src\System\Runtime\__Finalizer.cs" Condition="'$(WasmAbi)' != 'true' or '$(FeatureWasmThreads)' == 'true'">
<Compile Include="..\..\Runtime.Base\src\System\Runtime\__Finalizer.cs" Condition="'$(TargetsSingleThreadedWasm)' != 'true'">
<Link>Runtime.Base\src\System\Runtime\__Finalizer.cs</Link>
</Compile>
<Compile Include="..\..\Runtime.Base\src\System\Runtime\__Finalizer.SingleThreaded.cs" Condition="'$(WasmAbi)' == 'true' and '$(FeatureWasmThreads)' != 'true'">
<Compile Include="..\..\Runtime.Base\src\System\Runtime\__Finalizer.SingleThreaded.cs" Condition="'$(TargetsSingleThreadedWasm)' == 'true'">
<Link>Runtime.Base\src\System\Runtime\__Finalizer.SingleThreaded.cs</Link>
</Compile>
<Compile Include="..\..\Runtime.Base\src\System\Runtime\MethodTable.Runtime.cs">
Expand Down
182 changes: 158 additions & 24 deletions src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2539,27 +2539,41 @@ static void TestInterlocked()
static int InterlockedAnd(ref int location, int value) => Interlocked.And(ref location, value);
static int InterlockedOr(ref int location, int value) => Interlocked.Or(ref location, value);
static int InterlockedAdd(ref int location, int value) => Interlocked.Add(ref location, value);
static int InterlockedExchange(ref int location, int value) => Interlocked.Exchange(ref location, value);
static byte InterlockedExchangeByte(ref byte location, byte value) => Interlocked.Exchange(ref location, value);
static short InterlockedExchangeInt16(ref short location, short value) => Interlocked.Exchange(ref location, value);
static int InterlockedExchangeInt32(ref int location, int value) => Interlocked.Exchange(ref location, value);
static object InterlockedExchangeObj(ref object location, object value) => Interlocked.Exchange(ref location, value);
static int InterlockedCompareExchange(ref int location, int value, int comparand) => Interlocked.CompareExchange(ref location, value, comparand);
static byte InterlockedCompareExchangeByte(ref byte location, byte value, byte comparand) => Interlocked.CompareExchange(ref location, value, comparand);
static short InterlockedCompareExchangeInt16(ref short location, short value, short comparand) => Interlocked.CompareExchange(ref location, value, comparand);
static int InterlockedCompareExchangeInt32(ref int location, int value, int comparand) => Interlocked.CompareExchange(ref location, value, comparand);
static object InterlockedCompareExchangeObj(ref object location, object value, object comparand) => Interlocked.CompareExchange(ref location, value, comparand);

// Test statically direct (in the wrapper) calls to the atomics.
TestInterlockedImpl(
&InterlockedAnd,
&InterlockedOr,
&InterlockedAdd,
&InterlockedExchange,
&InterlockedExchangeByte,
&InterlockedExchangeInt16,
&InterlockedExchangeInt32,
&InterlockedExchangeObj,
&InterlockedCompareExchange,
&InterlockedCompareExchangeByte,
&InterlockedCompareExchangeInt16,
&InterlockedCompareExchangeInt32,
&InterlockedCompareExchangeObj,
"");

// Test indirect calls to the atomics.
TestInterlockedImpl(
(delegate*<ref int, int, int>)&Interlocked.And,
(delegate*<ref int, int, int>)&Interlocked.Or,
(delegate*<ref int, int, int>)&Interlocked.Add,
(delegate*<ref byte, byte, byte>)&Interlocked.Exchange,
(delegate*<ref short, short, short>)&Interlocked.Exchange,
(delegate*<ref int, int, int>)&Interlocked.Exchange,
(delegate*<ref object, object, object>)&Interlocked.Exchange,
(delegate*<ref byte, byte, byte, byte>)&Interlocked.CompareExchange,
(delegate*<ref short, short, short, short>)&Interlocked.CompareExchange,
(delegate*<ref int, int, int, int>)&Interlocked.CompareExchange,
(delegate*<ref object, object, object, object>)&Interlocked.CompareExchange,
" (indirect)");
Expand All @@ -2569,9 +2583,13 @@ static void TestInterlockedImpl(
delegate*<ref int, int, int> interlockedAnd,
delegate*<ref int, int, int> interlockedOr,
delegate*<ref int, int, int> interlockedAdd,
delegate*<ref int, int, int> interlockedExchange,
delegate*<ref byte, byte, byte> interlockedExchangeByte,
delegate*<ref short, short, short> interlockedExchangeInt16,
delegate*<ref int, int, int> interlockedExchangeInt32,
delegate*<ref object, object, object> interlockedExchangeObj,
delegate*<ref int, int, int, int> interlockedCompareExchange,
delegate*<ref byte, byte, byte, byte> interlockedCompareExchangeByte,
delegate*<ref short, short, short, short> interlockedCompareExchangeInt16,
delegate*<ref int, int, int, int> interlockedCompareExchangeInt32,
delegate*<ref object, object, object, object> interlockedCompareExchangeObj,
string postfix)
{
Expand Down Expand Up @@ -2684,36 +2702,94 @@ static void TestInterlockedImpl(
}
PassTest();

StartTest("Test Interlocked.Exchange" + postfix);
StartTest("Test Interlocked.Exchange<byte>" + postfix);
{
byte initValue = 0;
if (interlockedExchangeByte(ref initValue, 1) != 0)
{
FailTest("Interlocked.Exchange<byte> - old value");
return;
}
if (initValue != 1)
{
FailTest("Interlocked.Exchange<byte> - new value");
return;
}
try
{
interlockedExchangeByte(ref *(byte*)null, 0);
FailTest("Interlocked.Exchange<byte> - null location");
return;
}
catch (NullReferenceException) { }
}
PassTest();

StartTest("Test Interlocked.Exchange<int16>" + postfix);
{
short initValue = 0;
if (interlockedExchangeInt16(ref initValue, 1) != 0)
{
FailTest("Interlocked.Exchange<int16> - old value");
return;
}
if (initValue != 1)
{
FailTest("Interlocked.Exchange<int16> - new value");
return;
}
try
{
interlockedExchangeInt16(ref *(short*)null, 0);
FailTest("Interlocked.Exchange<int16> - null location");
return;
}
catch (NullReferenceException) { }
try
{
interlockedExchangeInt16(ref *(short*)(alignedLongAddress + 1), 0);
FailTest("Interlocked.Exchange<int16> - unaligned location");
return;
}
catch (DataMisalignedException) { }
if (longLocation != LongLocationValue)
{
FailTest("Interlocked.Exchange<int16> - unaligned store observed");
return;
}
}
PassTest();

StartTest("Test Interlocked.Exchange<int32>" + postfix);
{
int initValue = 0;
if (interlockedExchange(ref initValue, 1) != 0)
if (interlockedExchangeInt32(ref initValue, 1) != 0)
{
FailTest("Interlocked.Exchange - old value");
FailTest("Interlocked.Exchange<int32> - old value");
return;
}
if (initValue != 1)
{
FailTest("Interlocked.Exchange - new value");
FailTest("Interlocked.Exchange<int32> - new value");
return;
}
try
{
interlockedExchange(ref *(int*)null, 0);
FailTest("Interlocked.Exchange - null location");
interlockedExchangeInt32(ref *(int*)null, 0);
FailTest("Interlocked.Exchange<int32> - null location");
return;
}
catch (NullReferenceException) { }
try
{
interlockedExchange(ref *(int*)(alignedLongAddress + 1), 0);
FailTest("Interlocked.Exchange - unaligned location");
interlockedExchangeInt32(ref *(int*)(alignedLongAddress + 1), 0);
FailTest("Interlocked.Exchange<int32> - unaligned location");
return;
}
catch (DataMisalignedException) { }
if (longLocation != LongLocationValue)
{
FailTest("Interlocked.Exchange - unaligned store observed");
FailTest("Interlocked.Exchange<int32> - unaligned store observed");
return;
}
}
Expand Down Expand Up @@ -2743,36 +2819,94 @@ static void TestInterlockedImpl(
}
PassTest();

StartTest("Test Interlocked.CompareExchange" + postfix);
StartTest("Test Interlocked.CompareExchange<byte>" + postfix);
{
byte initValue = 0;
if (interlockedCompareExchangeByte(ref initValue, 1, 0) != 0)
{
FailTest("Interlocked.CompareExchange<byte> - old value");
return;
}
if (initValue != 1)
{
FailTest("Interlocked.CompareExchange<byte> - new value");
return;
}
try
{
interlockedCompareExchangeByte(ref *(byte*)null, 0, 0);
FailTest("Interlocked.CompareExchange<byte> - null location");
return;
}
catch (NullReferenceException) { }
}
PassTest();

StartTest("Test Interlocked.CompareExchange<int16>" + postfix);
{
short initValue = 0;
if (interlockedCompareExchangeInt16(ref initValue, 1, 0) != 0)
{
FailTest("Interlocked.CompareExchange<int16> - old value");
return;
}
if (initValue != 1)
{
FailTest("Interlocked.CompareExchange<int16> - new value");
return;
}
try
{
interlockedCompareExchangeInt16(ref *(short*)null, 0, 0);
FailTest("Interlocked.CompareExchange<int16> - null location");
return;
}
catch (NullReferenceException) { }
try
{
interlockedCompareExchangeInt16(ref *(short*)(alignedLongAddress + 1), 0, 0);
FailTest("Interlocked.CompareExchange<int16> - unaligned location");
return;
}
catch (DataMisalignedException) { }
if (longLocation != LongLocationValue)
{
FailTest("Interlocked.CompareExchange<int16> - unaligned store observed");
return;
}
}
PassTest();

StartTest("Test Interlocked.CompareExchange<int32>" + postfix);
{
int initValue = 0;
if (interlockedCompareExchange(ref initValue, 1, 0) != 0)
if (interlockedCompareExchangeInt32(ref initValue, 1, 0) != 0)
{
FailTest("Interlocked.CompareExchange - old value");
FailTest("Interlocked.CompareExchange<int32> - old value");
return;
}
if (initValue != 1)
{
FailTest("Interlocked.CompareExchange - new value");
FailTest("Interlocked.CompareExchange<int32> - new value");
return;
}
try
{
interlockedCompareExchange(ref *(int*)null, 0, 0);
FailTest("Interlocked.CompareExchange - null location");
interlockedCompareExchangeInt32(ref *(int*)null, 0, 0);
FailTest("Interlocked.CompareExchange<int32> - null location");
return;
}
catch (NullReferenceException) { }
try
{
interlockedCompareExchange(ref *(int*)(alignedLongAddress + 1), 0, 0);
FailTest("Interlocked.CompareExchange - unaligned location");
interlockedCompareExchangeInt32(ref *(int*)(alignedLongAddress + 1), 0, 0);
FailTest("Interlocked.CompareExchange<int32> - unaligned location");
return;
}
catch (DataMisalignedException) { }
if (longLocation != LongLocationValue)
{
FailTest("Interlocked.CompareExchange - unaligned store observed");
FailTest("Interlocked.CompareExchange<int32> - unaligned store observed");
return;
}
}
Expand Down
Loading