mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2025-01-14 10:36:03 +00:00
ff53dcf560
* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Address or silence dotnet format IDE1006 warnings * Address or silence dotnet format CA2208 warnings * Address dotnet format CA1822 warnings * Address or silence dotnet format CA1069 warnings * Silence CA1806 and CA1834 issues * Address dotnet format CA1401 warnings * Fix new dotnet-format issues after rebase * Address review comments * Address dotnet format CA2208 warnings properly * Fix formatting for switch expressions * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Add previously silenced warnings back I have no clue how these disappeared * Revert formatting changes for OpCodeTable.cs * Enable formatting for a few cases again * Format if-blocks correctly * Enable formatting for a few more cases again * Fix inline comment alignment * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Remove a few unused parameters * Adjust namespaces * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Fix and silence a few dotnet-format warnings again * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Remove unnecessary formatting exclusion * Add unsafe dotnet format changes * Change visibility of JitSupportDarwin to internal
156 lines
4.1 KiB
C#
156 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace ARMeilleure.IntermediateRepresentation
|
|
{
|
|
class BasicBlock : IEquatable<BasicBlock>, IIntrusiveListNode<BasicBlock>
|
|
{
|
|
private const uint MaxSuccessors = 2;
|
|
|
|
private int _succCount;
|
|
private BasicBlock _succ0;
|
|
private readonly BasicBlock _succ1;
|
|
private HashSet<BasicBlock> _domFrontiers;
|
|
|
|
public int Index { get; set; }
|
|
public BasicBlockFrequency Frequency { get; set; }
|
|
public BasicBlock ListPrevious { get; set; }
|
|
public BasicBlock ListNext { get; set; }
|
|
public IntrusiveList<Operation> Operations { get; }
|
|
public List<BasicBlock> Predecessors { get; }
|
|
public BasicBlock ImmediateDominator { get; set; }
|
|
|
|
public int SuccessorsCount => _succCount;
|
|
|
|
public HashSet<BasicBlock> DominanceFrontiers
|
|
{
|
|
get
|
|
{
|
|
_domFrontiers ??= new HashSet<BasicBlock>();
|
|
|
|
return _domFrontiers;
|
|
}
|
|
}
|
|
|
|
public BasicBlock() : this(index: -1) { }
|
|
|
|
public BasicBlock(int index)
|
|
{
|
|
Operations = new IntrusiveList<Operation>();
|
|
Predecessors = new List<BasicBlock>();
|
|
|
|
Index = index;
|
|
}
|
|
|
|
public void AddSuccessor(BasicBlock block)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(block);
|
|
|
|
if ((uint)_succCount + 1 > MaxSuccessors)
|
|
{
|
|
ThrowSuccessorOverflow();
|
|
}
|
|
|
|
block.Predecessors.Add(this);
|
|
|
|
GetSuccessorUnsafe(_succCount++) = block;
|
|
}
|
|
|
|
public void RemoveSuccessor(int index)
|
|
{
|
|
if ((uint)index >= (uint)_succCount)
|
|
{
|
|
ThrowOutOfRange(nameof(index));
|
|
}
|
|
|
|
ref BasicBlock oldBlock = ref GetSuccessorUnsafe(index);
|
|
|
|
oldBlock.Predecessors.Remove(this);
|
|
oldBlock = null;
|
|
|
|
if (index == 0)
|
|
{
|
|
_succ0 = _succ1;
|
|
}
|
|
|
|
_succCount--;
|
|
}
|
|
|
|
public BasicBlock GetSuccessor(int index)
|
|
{
|
|
if ((uint)index >= (uint)_succCount)
|
|
{
|
|
ThrowOutOfRange(nameof(index));
|
|
}
|
|
|
|
return GetSuccessorUnsafe(index);
|
|
}
|
|
|
|
private ref BasicBlock GetSuccessorUnsafe(int index)
|
|
{
|
|
return ref Unsafe.Add(ref _succ0, index);
|
|
}
|
|
|
|
public void SetSuccessor(int index, BasicBlock block)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(block);
|
|
|
|
if ((uint)index >= (uint)_succCount)
|
|
{
|
|
ThrowOutOfRange(nameof(index));
|
|
}
|
|
|
|
ref BasicBlock oldBlock = ref GetSuccessorUnsafe(index);
|
|
|
|
oldBlock.Predecessors.Remove(this);
|
|
block.Predecessors.Add(this);
|
|
|
|
oldBlock = block;
|
|
}
|
|
|
|
public void Append(Operation node)
|
|
{
|
|
Operation last = Operations.Last;
|
|
|
|
// Append node before terminal or to end if no terminal.
|
|
if (last == default)
|
|
{
|
|
Operations.AddLast(node);
|
|
|
|
return;
|
|
}
|
|
|
|
switch (last.Instruction)
|
|
{
|
|
case Instruction.Return:
|
|
case Instruction.Tailcall:
|
|
case Instruction.BranchIf:
|
|
Operations.AddBefore(last, node);
|
|
break;
|
|
|
|
default:
|
|
Operations.AddLast(node);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private static void ThrowOutOfRange(string name) => throw new ArgumentOutOfRangeException(name);
|
|
private static void ThrowSuccessorOverflow() => throw new OverflowException($"BasicBlock can only have {MaxSuccessors} successors.");
|
|
|
|
public bool Equals(BasicBlock other)
|
|
{
|
|
return other == this;
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return Equals(obj as BasicBlock);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
}
|
|
}
|