Skip to content

Commit

Permalink
Workaround EqualityComparer issues on MacOS and net8. (#1144)
Browse files Browse the repository at this point in the history
- Unit tests on MacOS and net8 are failing due to a stack overflow in ControlFlowVerifier.ComputePostOrder. Appears to be an issue with the default implicit comparer for BasicBlock.
  • Loading branch information
MoFtZ authored Jan 8, 2024
1 parent a447508 commit df4e9af
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ILGPU License
********************************************************************************
University of Illinois/NCSA Open Source License
Copyright (c) 2016-2023 ILGPU Project
Copyright (c) 2016-2024 ILGPU Project
All rights reserved.

Developed by: Marcel Koester ([email protected])
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ILGPU also provides Source Link support for a better debugging experience. Make
ILGPU is licensed under the University of Illinois/NCSA Open Source License.
Detailed license information can be found in LICENSE.txt.

Copyright (c) 2016-2023 ILGPU Project. All rights reserved.
Copyright (c) 2016-2024 ILGPU Project. All rights reserved.

Originally developed by Marcel Koester.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PackageVersion>$(Version)</PackageVersion>

<Title>ILGPU Algorithms Library</Title>
<Copyright>Copyright (c) 2016-2023 ILGPU Project. All rights reserved.</Copyright>
<Copyright>Copyright (c) 2016-2024 ILGPU Project. All rights reserved.</Copyright>
<Company />
<Authors>ILGPU Algorithms Project</Authors>
<Description>ILGPU Algorithms library for high-level GPU programming.</Description>
Expand Down
7 changes: 4 additions & 3 deletions Src/ILGPU/Backends/OpenCL/CLCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2019-2023 ILGPU Project
// Copyright (c) 2019-2024 ILGPU Project
// www.ilgpu.net
//
// File: CLCodeGenerator.cs
Expand Down Expand Up @@ -199,7 +199,7 @@ protected static string GetParameterName(Parameter parameter) =>

private int labelCounter;
private readonly Dictionary<BasicBlock, string> blockLookup =
new Dictionary<BasicBlock, string>();
new Dictionary<BasicBlock, string>(new BasicBlock.Comparer());
private readonly string labelPrefix;

private StringBuilder prefixBuilder = new StringBuilder();
Expand Down Expand Up @@ -439,7 +439,8 @@ protected void GenerateCodeInternal()
blockLookup.Add(block, DeclareLabel());

// Find all phi nodes, allocate target registers and setup internal mapping
var phiMapping = new Dictionary<BasicBlock, List<Variable>>();
var phiMapping = new Dictionary<BasicBlock, List<Variable>>(
new BasicBlock.Comparer());
var dominators = Method.Blocks.CreateDominators();
var phiBindings = PhiBindings.Create(
blocks,
Expand Down
5 changes: 3 additions & 2 deletions Src/ILGPU/Backends/PTX/PTXCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2018-2023 ILGPU Project
// Copyright (c) 2018-2024 ILGPU Project
// www.ilgpu.net
//
// File: PTXCodeGenerator.cs
Expand Down Expand Up @@ -286,7 +286,8 @@ protected static string GetParameterName(Parameter parameter) =>
#region Instance

private int labelCounter;
private readonly Dictionary<BasicBlock, string> blockLookup = new();
private readonly Dictionary<BasicBlock, string> blockLookup = new(
new BasicBlock.Comparer());

private readonly Dictionary<(Encoding, string), string> stringConstants = new();
private readonly PhiBindings phiBindings;
Expand Down
5 changes: 3 additions & 2 deletions Src/ILGPU/Backends/Velocity/VelocityCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2022-2023 ILGPU Project
// Copyright (c) 2022-2024 ILGPU Project
// www.ilgpu.net
//
// File: VelocityCodeGenerator.cs
Expand Down Expand Up @@ -96,7 +96,8 @@ public readonly record struct GeneratorArgs(
/// <summary>
/// Maps blocks to labels.
/// </summary>
private readonly Dictionary<BasicBlock, ILLabel> blockLookup = new();
private readonly Dictionary<BasicBlock, ILLabel> blockLookup =
new(new BasicBlock.Comparer());

/// <summary>
/// The masks analysis holding information about the masks being required.
Expand Down
4 changes: 2 additions & 2 deletions Src/ILGPU/Frontend/Block.CFGBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2018-2023 ILGPU Project
// Copyright (c) 2018-2024 ILGPU Project
// www.ilgpu.net
//
// File: Block.CFGBuilder.cs
Expand Down Expand Up @@ -71,7 +71,7 @@ public readonly void Apply(ILInstruction instruction, int offset) =>
private readonly Dictionary<int, Block> blockMapping =
new Dictionary<int, Block>();
private readonly Dictionary<BasicBlock, Block> basicBlockMapping =
new Dictionary<BasicBlock, Block>();
new Dictionary<BasicBlock, Block>(new BasicBlock.Comparer());
private readonly Dictionary<Block, List<Block>> successorMapping =
new Dictionary<Block, List<Block>>();

Expand Down
6 changes: 3 additions & 3 deletions Src/ILGPU/IR/Analyses/Loops.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2020-2023 ILGPU Project
// Copyright (c) 2020-2024 ILGPU Project
// www.ilgpu.net
//
// File: Loops.cs
Expand Down Expand Up @@ -757,8 +757,8 @@ private void RegisterLoop(
// Initialize all lists and sets
var headers = InlineList<BasicBlock>.Create(2);
var breakers = InlineList<BasicBlock>.Create(2);
var entryBlocks = new HashSet<BasicBlock>();
var exitBlocks = new HashSet<BasicBlock>();
var entryBlocks = new HashSet<BasicBlock>(new BasicBlock.Comparer());
var exitBlocks = new HashSet<BasicBlock>(new BasicBlock.Comparer());

// Gather all loop entries and exists
foreach (var member in members)
Expand Down
4 changes: 2 additions & 2 deletions Src/ILGPU/IR/BasicBlockCollection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2020-2023 ILGPU Project
// Copyright (c) 2020-2024 ILGPU Project
// www.ilgpu.net
//
// File: BasicBlockCollection.cs
Expand Down Expand Up @@ -339,7 +339,7 @@ public readonly HashSet<BasicBlock> ToSet() =>
public readonly HashSet<BasicBlock> ToSet<TPredicate>(TPredicate predicate)
where TPredicate : InlineList.IPredicate<BasicBlock>
{
var result = new HashSet<BasicBlock>();
var result = new HashSet<BasicBlock>(new BasicBlock.Comparer());
foreach (var block in this)
{
if (predicate.Apply(block))
Expand Down
7 changes: 4 additions & 3 deletions Src/ILGPU/IR/BasicBlockMapping.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2020-2023 ILGPU Project
// Copyright (c) 2020-2024 ILGPU Project
// www.ilgpu.net
//
// File: BasicBlockMapping.cs
Expand Down Expand Up @@ -746,7 +746,7 @@ partial struct BasicBlockSet

/// <summary cref="InitBlockSet"/>
[MemberNotNull(nameof(blockSet))]
partial void InitBlockSet() => blockSet = new HashSet<BasicBlock>();
partial void InitBlockSet() => blockSet = new(new BasicBlock.Comparer());

#endregion

Expand Down Expand Up @@ -785,7 +785,8 @@ partial struct BasicBlockMap<T>

/// <summary cref="InitBlockMap"/>
[MemberNotNull(nameof(blockMap))]
partial void InitBlockMap() => blockMap = new Dictionary<BasicBlock, T>();
partial void InitBlockMap() => blockMap =
new Dictionary<BasicBlock, T>(new BasicBlock.Comparer());

#endregion

Expand Down
18 changes: 9 additions & 9 deletions Src/ILGPU/IR/Verifier.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2020-2023 ILGPU Project
// Copyright (c) 2020-2024 ILGPU Project
// www.ilgpu.net
//
// File: Verifier.cs
Expand Down Expand Up @@ -184,11 +184,11 @@ private sealed class ControlFlowVerifier : VerifierBase
private readonly List<BasicBlock> blocksInRpo =
new List<BasicBlock>();
private readonly HashSet<BasicBlock> containedBlocks =
new HashSet<BasicBlock>();
new(new BasicBlock.Comparer());
private readonly Dictionary<BasicBlock, HashSet<BasicBlock>> predecessors =
new Dictionary<BasicBlock, HashSet<BasicBlock>>();
new(new BasicBlock.Comparer());
private readonly Dictionary<BasicBlock, HashSet<BasicBlock>> successors =
new Dictionary<BasicBlock, HashSet<BasicBlock>>();
new(new BasicBlock.Comparer());

/// <summary>
/// Constructs a new control-flow verifier.
Expand All @@ -204,15 +204,15 @@ public ControlFlowVerifier(Method method, VerificationResult result)
#region Methods

/// <summary>
/// Creates new predecessor and successor ink sets.
/// Creates new predecessor and successor link sets.
/// </summary>
/// <param name="block">The current block.</param>
private void CreateLinkSets(BasicBlock block)
{
if (!predecessors.ContainsKey(block))
predecessors.Add(block, new HashSet<BasicBlock>());
predecessors.Add(block, new(new BasicBlock.Comparer()));
if (!successors.ContainsKey(block))
successors.Add(block, new HashSet<BasicBlock>());
successors.Add(block, new(new BasicBlock.Comparer()));
}

/// <summary>
Expand Down Expand Up @@ -325,7 +325,7 @@ private sealed class ValueVerifier : VerifierBase

private readonly HashSet<Value> values = new HashSet<Value>();
private readonly Dictionary<BasicBlock, HashSet<Value>> mapping =
new Dictionary<BasicBlock, HashSet<Value>>();
new Dictionary<BasicBlock, HashSet<Value>>(new BasicBlock.Comparer());

/// <summary>
/// Constructs a new value verifier.
Expand Down Expand Up @@ -465,7 +465,7 @@ private void VerifyPhis() =>
phiValue.BasicBlock.Predecessors.Length);

// Verify nodes and sources
var visited = new HashSet<BasicBlock>();
var visited = new HashSet<BasicBlock>(new BasicBlock.Comparer());
for (int i = 0, e = phiValue.Nodes.Length; i < e; ++i)
{
Value value = phiValue.Nodes[i];
Expand Down
2 changes: 1 addition & 1 deletion Src/ILGPU/Properties/ILGPU.nuspec.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PackageVersion>$(Version)</PackageVersion>

<Title>ILGPU</Title>
<Copyright>Copyright (c) 2016-2023 ILGPU Project. All rights reserved.</Copyright>
<Copyright>Copyright (c) 2016-2024 ILGPU Project. All rights reserved.</Copyright>
<Company />
<Authors>Marcel Koester</Authors>
<Description>ILGPU Just-In-Time Compiler</Description>
Expand Down

0 comments on commit df4e9af

Please sign in to comment.