Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Dump BB in/out memory SSAs inline when SSA is valid #95017

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

jakobbotsch
Copy link
Member

When SSA is considered to be valid, write in and out SSA numbers for memory states when dumping the blocks.

For example:

public static void Foo(C c)
{
    if (c.V % 2 == 0)
    {
        c.V = 123;
    }
    else
    {
        c.V = 456;
    }

    Console.WriteLine(c.V);
}

public class C
{
    public int V;
}

dumps

------------ BB01 [000..00A) -> BB03 (cond), preds={} succs={BB02,BB03}
ByrefExposed, GcHeap = m:1

***** BB01
STMT00000 ( 0x000[E-] ... 0x008 )
N009 ( 10, 10) [000007] ---XG------                         ▌  JTRUE     void
N008 (  8,  8) [000006] J--XG--N---                         └──▌  NE        int
N006 (  6,  6) [000004] ---XG------                            ├──▌  AND       int
N004 (  4,  4) [000002] ---XG------                            │  ├──▌  IND       int
N003 (  2,  2) [000024] -------N---                            │  │  └──▌  ADD       byref
N001 (  1,  1) [000000] -----------                            │  │     ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000023] -----------                            │  │     └──▌  CNS_INT   long   8 Fseq[V]
N005 (  1,  1) [000003] -----------                            │  └──▌  CNS_INT   int    1
N007 (  1,  1) [000005] -----------                            └──▌  CNS_INT   int    0

ByrefExposed, GcHeap = m:1

------------ BB02 [00A..014) -> BB04 (always), preds={BB01} succs={BB04}
ByrefExposed, GcHeap = m:1

***** BB02
STMT00004 ( 0x00A[E-] ... 0x00D )
N005 (  6,  6) [000020] -A-XG------                         ▌  STOREIND  int
N003 (  2,  2) [000028] -------N---                         ├──▌  ADD       byref
N001 (  1,  1) [000017] -----------                         │  ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000027] -----------                         │  └──▌  CNS_INT   long   8 Fseq[V]
N004 (  1,  1) [000018] -----------                         └──▌  CNS_INT   int    123

ByrefExposed, GcHeap = m:5

------------ BB03 [014..01F), preds={BB01} succs={BB04}
ByrefExposed, GcHeap = m:1

***** BB03
STMT00001 ( 0x014[E-] ... 0x01A )
N005 (  6,  9) [000011] -A-XG------                         ▌  STOREIND  int
N003 (  2,  2) [000026] -------N---                         ├──▌  ADD       byref
N001 (  1,  1) [000008] -----------                         │  ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000025] -----------                         │  └──▌  CNS_INT   long   8 Fseq[V]
N004 (  1,  4) [000009] -----------                         └──▌  CNS_INT   int    456

ByrefExposed, GcHeap = m:4

------------ BB04 [01F..02B) (return), preds={BB02,BB03} succs={}
ByrefExposed, GcHeap = phi(m:5, m:4)

***** BB04
STMT00002 ( 0x01F[E-] ... 0x02A )
N005 ( 18, 10) [000015] --CXG------                         ▌  CALL      void   System.Console:WriteLine(int)
N004 (  4,  4) [000014] ---XG------ arg0 in rcx             └──▌  IND       int
N003 (  2,  2) [000030] -------N---                            └──▌  ADD       byref
N001 (  1,  1) [000012] -----------                               ├──▌  LCL_VAR   ref    V00 arg0         u:1 (last use)
N002 (  1,  1) [000029] -----------                               └──▌  CNS_INT   long   8 Fseq[V]

***** BB04
STMT00003 ( 0x02A[E-] ... ??? )
N001 (  0,  0) [000016] -----------                         ▌  RETURN    void

ByrefExposed, GcHeap = m:3

after SSA.

When SSA is considered to be valid, write in and out SSA numbers for
memory states when dumping the blocks.

For example:

```csharp
public static void Foo(C c)
{
    if (c.V % 2 == 0)
    {
        c.V = 123;
    }
    else
    {
        c.V = 456;
    }

    Console.WriteLine(c.V);
}

public class C
{
    public int V;
}
```
dumps

```
------------ BB01 [000..00A) -> BB03 (cond), preds={} succs={BB02,BB03}
ByrefExposed, GcHeap = m:1

***** BB01
STMT00000 ( 0x000[E-] ... 0x008 )
N009 ( 10, 10) [000007] ---XG------                         ▌  JTRUE     void
N008 (  8,  8) [000006] J--XG--N---                         └──▌  NE        int
N006 (  6,  6) [000004] ---XG------                            ├──▌  AND       int
N004 (  4,  4) [000002] ---XG------                            │  ├──▌  IND       int
N003 (  2,  2) [000024] -------N---                            │  │  └──▌  ADD       byref
N001 (  1,  1) [000000] -----------                            │  │     ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000023] -----------                            │  │     └──▌  CNS_INT   long   8 Fseq[V]
N005 (  1,  1) [000003] -----------                            │  └──▌  CNS_INT   int    1
N007 (  1,  1) [000005] -----------                            └──▌  CNS_INT   int    0

ByrefExposed, GcHeap = m:1

------------ BB02 [00A..014) -> BB04 (always), preds={BB01} succs={BB04}
ByrefExposed, GcHeap = m:1

***** BB02
STMT00004 ( 0x00A[E-] ... 0x00D )
N005 (  6,  6) [000020] -A-XG------                         ▌  STOREIND  int
N003 (  2,  2) [000028] -------N---                         ├──▌  ADD       byref
N001 (  1,  1) [000017] -----------                         │  ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000027] -----------                         │  └──▌  CNS_INT   long   8 Fseq[V]
N004 (  1,  1) [000018] -----------                         └──▌  CNS_INT   int    123

ByrefExposed, GcHeap = m:5

------------ BB03 [014..01F), preds={BB01} succs={BB04}
ByrefExposed, GcHeap = m:1

***** BB03
STMT00001 ( 0x014[E-] ... 0x01A )
N005 (  6,  9) [000011] -A-XG------                         ▌  STOREIND  int
N003 (  2,  2) [000026] -------N---                         ├──▌  ADD       byref
N001 (  1,  1) [000008] -----------                         │  ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000025] -----------                         │  └──▌  CNS_INT   long   8 Fseq[V]
N004 (  1,  4) [000009] -----------                         └──▌  CNS_INT   int    456

ByrefExposed, GcHeap = m:4

------------ BB04 [01F..02B) (return), preds={BB02,BB03} succs={}
ByrefExposed, GcHeap = phi(m:5, m:4)

***** BB04
STMT00002 ( 0x01F[E-] ... 0x02A )
N005 ( 18, 10) [000015] --CXG------                         ▌  CALL      void   System.Console:WriteLine(int)
N004 (  4,  4) [000014] ---XG------ arg0 in rcx             └──▌  IND       int
N003 (  2,  2) [000030] -------N---                            └──▌  ADD       byref
N001 (  1,  1) [000012] -----------                               ├──▌  LCL_VAR   ref    V00 arg0         u:1 (last use)
N002 (  1,  1) [000029] -----------                               └──▌  CNS_INT   long   8 Fseq[V]

***** BB04
STMT00003 ( 0x02A[E-] ... ??? )
N001 (  0,  0) [000016] -----------                         ▌  RETURN    void

ByrefExposed, GcHeap = m:3

```

after SSA.
@ghost ghost assigned jakobbotsch Nov 20, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 20, 2023
@ghost
Copy link

ghost commented Nov 20, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

When SSA is considered to be valid, write in and out SSA numbers for memory states when dumping the blocks.

For example:

public static void Foo(C c)
{
    if (c.V % 2 == 0)
    {
        c.V = 123;
    }
    else
    {
        c.V = 456;
    }

    Console.WriteLine(c.V);
}

public class C
{
    public int V;
}

dumps

------------ BB01 [000..00A) -> BB03 (cond), preds={} succs={BB02,BB03}
ByrefExposed, GcHeap = m:1

***** BB01
STMT00000 ( 0x000[E-] ... 0x008 )
N009 ( 10, 10) [000007] ---XG------                         ▌  JTRUE     void
N008 (  8,  8) [000006] J--XG--N---                         └──▌  NE        int
N006 (  6,  6) [000004] ---XG------                            ├──▌  AND       int
N004 (  4,  4) [000002] ---XG------                            │  ├──▌  IND       int
N003 (  2,  2) [000024] -------N---                            │  │  └──▌  ADD       byref
N001 (  1,  1) [000000] -----------                            │  │     ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000023] -----------                            │  │     └──▌  CNS_INT   long   8 Fseq[V]
N005 (  1,  1) [000003] -----------                            │  └──▌  CNS_INT   int    1
N007 (  1,  1) [000005] -----------                            └──▌  CNS_INT   int    0

ByrefExposed, GcHeap = m:1

------------ BB02 [00A..014) -> BB04 (always), preds={BB01} succs={BB04}
ByrefExposed, GcHeap = m:1

***** BB02
STMT00004 ( 0x00A[E-] ... 0x00D )
N005 (  6,  6) [000020] -A-XG------                         ▌  STOREIND  int
N003 (  2,  2) [000028] -------N---                         ├──▌  ADD       byref
N001 (  1,  1) [000017] -----------                         │  ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000027] -----------                         │  └──▌  CNS_INT   long   8 Fseq[V]
N004 (  1,  1) [000018] -----------                         └──▌  CNS_INT   int    123

ByrefExposed, GcHeap = m:5

------------ BB03 [014..01F), preds={BB01} succs={BB04}
ByrefExposed, GcHeap = m:1

***** BB03
STMT00001 ( 0x014[E-] ... 0x01A )
N005 (  6,  9) [000011] -A-XG------                         ▌  STOREIND  int
N003 (  2,  2) [000026] -------N---                         ├──▌  ADD       byref
N001 (  1,  1) [000008] -----------                         │  ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000025] -----------                         │  └──▌  CNS_INT   long   8 Fseq[V]
N004 (  1,  4) [000009] -----------                         └──▌  CNS_INT   int    456

ByrefExposed, GcHeap = m:4

------------ BB04 [01F..02B) (return), preds={BB02,BB03} succs={}
ByrefExposed, GcHeap = phi(m:5, m:4)

***** BB04
STMT00002 ( 0x01F[E-] ... 0x02A )
N005 ( 18, 10) [000015] --CXG------                         ▌  CALL      void   System.Console:WriteLine(int)
N004 (  4,  4) [000014] ---XG------ arg0 in rcx             └──▌  IND       int
N003 (  2,  2) [000030] -------N---                            └──▌  ADD       byref
N001 (  1,  1) [000012] -----------                               ├──▌  LCL_VAR   ref    V00 arg0         u:1 (last use)
N002 (  1,  1) [000029] -----------                               └──▌  CNS_INT   long   8 Fseq[V]

***** BB04
STMT00003 ( 0x02A[E-] ... ??? )
N001 (  0,  0) [000016] -----------                         ▌  RETURN    void

ByrefExposed, GcHeap = m:3

after SSA.

Author: jakobbotsch
Assignees: jakobbotsch
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib

superpmi-replay failure is #95025

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion is to prefix the output by a distinguished tag (e.g., "SSA MEM: ") so it's super obvious what the output is about (and is searchable). E.g., from your example:

------------ BB01 [000..00A) -> BB03 (cond), preds={} succs={BB02,BB03}
SSA MEM: ByrefExposed, GcHeap = m:1

***** BB01
STMT00000 ( 0x000[E-] ... 0x008 )
N009 ( 10, 10) [000007] ---XG------                         ▌  JTRUE     void
N008 (  8,  8) [000006] J--XG--N---                         └──▌  NE        int
N006 (  6,  6) [000004] ---XG------                            ├──▌  AND       int
N004 (  4,  4) [000002] ---XG------                            │  ├──▌  IND       int
N003 (  2,  2) [000024] -------N---                            │  │  └──▌  ADD       byref
N001 (  1,  1) [000000] -----------                            │  │     ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000023] -----------                            │  │     └──▌  CNS_INT   long   8 Fseq[V]
N005 (  1,  1) [000003] -----------                            │  └──▌  CNS_INT   int    1
N007 (  1,  1) [000005] -----------                            └──▌  CNS_INT   int    0

SSA MEM: ByrefExposed, GcHeap = m:1

------------ BB02 [00A..014) -> BB04 (always), preds={BB01} succs={BB04}
SSA MEM: ByrefExposed, GcHeap = m:1

***** BB02
STMT00004 ( 0x00A[E-] ... 0x00D )
N005 (  6,  6) [000020] -A-XG------                         ▌  STOREIND  int
N003 (  2,  2) [000028] -------N---                         ├──▌  ADD       byref
N001 (  1,  1) [000017] -----------                         │  ├──▌  LCL_VAR   ref    V00 arg0         u:1
N002 (  1,  1) [000027] -----------                         │  └──▌  CNS_INT   long   8 Fseq[V]
N004 (  1,  1) [000018] -----------                         └──▌  CNS_INT   int    123

SSA MEM: ByrefExposed, GcHeap = m:5

@jakobbotsch jakobbotsch merged commit 186cf81 into dotnet:main Nov 21, 2023
@jakobbotsch jakobbotsch deleted the ssa-ir-dump branch November 21, 2023 13:33
@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants