Skip to content

Commit

Permalink
Added support for WASM compilation in the backend. (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ authored Nov 19, 2022
1 parent 511d6e7 commit 427dab5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 31 deletions.
51 changes: 20 additions & 31 deletions Src/ILGPU/Backends/Backend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,14 @@ namespace ILGPU.Backends
public enum TargetPlatform
{
/// <summary>
/// The X86 target platform.
/// The target platform is 32-bit.
/// </summary>
X86,
Platform32Bit,

/// <summary>
/// The X64 target platform.
/// The target platform is 64-bit.
/// </summary>
X64,

/// <summary>
/// The Arm target platform.
/// </summary>
Arm,

/// <summary>
/// The Arm64 target platform.
/// </summary>
Arm64,
Platform64Bit,
}

/// <summary>
Expand All @@ -63,14 +53,7 @@ public static class TargetPlatformExtensions
/// Returns true if the current runtime platform is 64-bit.
/// </summary>
public static bool Is64Bit(this TargetPlatform targetPlatform) =>
targetPlatform switch
{
TargetPlatform.X86 => false,
TargetPlatform.X64 => true,
TargetPlatform.Arm => false,
TargetPlatform.Arm64 => true,
_ => throw new NotSupportedException(),
};
targetPlatform == TargetPlatform.Platform64Bit;
}

/// <summary>
Expand Down Expand Up @@ -407,10 +390,13 @@ protected delegate void CreateTransformersHandler(
public static TargetPlatform RuntimePlatform =>
RuntimeInformation.ProcessArchitecture switch
{
Architecture.X86 => TargetPlatform.X86,
Architecture.X64 => TargetPlatform.X64,
Architecture.Arm => TargetPlatform.Arm,
Architecture.Arm64 => TargetPlatform.Arm64,
Architecture.X86 => TargetPlatform.Platform32Bit,
Architecture.X64 => TargetPlatform.Platform64Bit,
Architecture.Arm => TargetPlatform.Platform32Bit,
Architecture.Arm64 => TargetPlatform.Platform64Bit,
#if NET5_0_OR_GREATER
Architecture.Wasm => TargetPlatform.Platform64Bit,
#endif
_ => throw new NotSupportedException(),
};

Expand All @@ -420,10 +406,13 @@ protected delegate void CreateTransformersHandler(
public static TargetPlatform OSPlatform =>
RuntimeInformation.OSArchitecture switch
{
Architecture.X86 => TargetPlatform.X86,
Architecture.X64 => TargetPlatform.X64,
Architecture.Arm => TargetPlatform.Arm,
Architecture.Arm64 => TargetPlatform.Arm64,
Architecture.X86 => TargetPlatform.Platform32Bit,
Architecture.X64 => TargetPlatform.Platform64Bit,
Architecture.Arm => TargetPlatform.Platform32Bit,
Architecture.Arm64 => TargetPlatform.Platform64Bit,
#if NET5_0_OR_GREATER
Architecture.Wasm => TargetPlatform.Platform64Bit,
#endif
_ => throw new NotSupportedException(),
};

Expand Down Expand Up @@ -495,7 +484,7 @@ protected Backend(

// Setup custom pointer types
PointerArithmeticType =
Context.TargetPlatform == TargetPlatform.X64
Context.TargetPlatform.Is64Bit()
? ArithmeticBasicValueType.UInt64
: ArithmeticBasicValueType.UInt32;
PointerType = context.TypeContext.GetPrimitiveType(
Expand Down
56 changes: 56 additions & 0 deletions Src/ILGPU/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
<Right>lib/net471/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.Backends.TargetPlatform.X86</Target>
<Left>lib/net471/ILGPU.dll</Left>
<Right>lib/net471/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.Backends.TargetPlatform.X64</Target>
<Left>lib/net471/ILGPU.dll</Left>
<Right>lib/net471/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.IR.Values.ConvertFlags.Overflow</Target>
Expand All @@ -42,6 +56,20 @@
<Right>lib/net5.0/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.Backends.TargetPlatform.X86</Target>
<Left>lib/net5.0/ILGPU.dll</Left>
<Right>lib/net5.0/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.Backends.TargetPlatform.X64</Target>
<Left>lib/net5.0/ILGPU.dll</Left>
<Right>lib/net5.0/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.IR.Values.ConvertFlags.Overflow</Target>
Expand All @@ -63,6 +91,20 @@
<Right>lib/net6.0/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.Backends.TargetPlatform.X86</Target>
<Left>lib/net6.0/ILGPU.dll</Left>
<Right>lib/net6.0/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.Backends.TargetPlatform.X64</Target>
<Left>lib/net6.0/ILGPU.dll</Left>
<Right>lib/net6.0/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.IR.Values.ConvertFlags.Overflow</Target>
Expand All @@ -84,4 +126,18 @@
<Right>lib/netstandard2.1/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.Backends.TargetPlatform.X86</Target>
<Left>lib/netstandard2.1/ILGPU.dll</Left>
<Right>lib/netstandard2.1/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:ILGPU.Backends.TargetPlatform.X64</Target>
<Left>lib/netstandard2.1/ILGPU.dll</Left>
<Right>lib/netstandard2.1/ILGPU.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
</Suppressions>

0 comments on commit 427dab5

Please sign in to comment.