Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ committed Dec 27, 2023
1 parent 03904bb commit 3fc5fe6
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Src/ILGPU/Backends/OpenCL/CLCodeGenerator.cs
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion Src/ILGPU/Backends/PTX/PTXCodeGenerator.cs
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion Src/ILGPU/Backends/Velocity/VelocityCodeGenerator.cs
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion Src/ILGPU/Frontend/Block.CFGBuilder.cs
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions Src/ILGPU/IR/Analyses/Loops.cs
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion Src/ILGPU/IR/BasicBlockCollection.cs
Original file line number Diff line number Diff line change
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
5 changes: 3 additions & 2 deletions Src/ILGPU/IR/BasicBlockMapping.cs
Original file line number Diff line number Diff line change
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
14 changes: 7 additions & 7 deletions Src/ILGPU/IR/Verifier.cs
Original file line number Diff line number Diff line change
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 @@ -210,9 +210,9 @@ public ControlFlowVerifier(Method method, VerificationResult result)
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

0 comments on commit 3fc5fe6

Please sign in to comment.