aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Cpu/LightningJit/Arm64/MultiBlock.cs
blob: 8ac65059ab9386c170cfef333e105c058506ea20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Ryujinx.Cpu.LightningJit.Graph;
using System;
using System.Collections.Generic;

namespace Ryujinx.Cpu.LightningJit.Arm64
{
    class MultiBlock : IBlockList
    {
        public readonly List<Block> Blocks;
        public readonly RegisterMask[] ReadMasks;
        public readonly RegisterMask[] WriteMasks;
        public readonly RegisterMask GlobalUseMask;
        public readonly bool HasHostCall;
        public readonly bool HasMemoryInstruction;
        public readonly bool IsTruncated;

        public int Count => Blocks.Count;

        public IBlock this[int index] => Blocks[index];

        public MultiBlock(List<Block> blocks, RegisterMask globalUseMask, bool hasHostCall, bool hasMemoryInstruction)
        {
            Blocks = blocks;

            (ReadMasks, WriteMasks) = DataFlow.GetGlobalUses(this);

            GlobalUseMask = globalUseMask;
            HasHostCall = hasHostCall;
            HasMemoryInstruction = hasMemoryInstruction;
            IsTruncated = blocks[^1].IsTruncated;
        }

        public void PrintDebugInfo()
        {
            foreach (Block block in Blocks)
            {
                Console.WriteLine($"bb {block.Index}");

                List<int> predList = new();
                List<int> succList = new();

                for (int index = 0; index < block.PredecessorsCount; index++)
                {
                    predList.Add(block.GetPredecessor(index).Index);
                }

                for (int index = 0; index < block.SuccessorsCount; index++)
                {
                    succList.Add(block.GetSuccessor(index).Index);
                }

                Console.WriteLine($" predecessors: {string.Join(' ', predList)}");
                Console.WriteLine($" successors: {string.Join(' ', succList)}");
                Console.WriteLine($" gpr read mask: 0x{ReadMasks[block.Index].GprMask:X} 0x{block.ComputeUseMasks().Read.GprMask:X}");
                Console.WriteLine($" gpr write mask: 0x{WriteMasks[block.Index].GprMask:X}");

                for (int index = 0; index < block.Instructions.Count; index++)
                {
                    Console.WriteLine($"  {index} 0x{block.Instructions[index].Encoding:X8} {block.Instructions[index].Name}");
                }
            }
        }
    }
}