Skip to content

JIT: Add flowgraph dumping for new loops - #95748

Merged
jakobbotsch merged 5 commits into
dotnet:mainfrom
jakobbotsch:new-loops-fg-dump
Dec 9, 2023
Merged

jakobbotsch merged 5 commits into
dotnet:mainfrom
jakobbotsch:new-loops-fg-dump

Conversation

@jakobbotsch

@jakobbotsch jakobbotsch commented Dec 7, 2023 •

Copy link
Copy Markdown
Member

It does not yet support intermixed EH regions and loops (which I think the old stuff does), but this just makes it so we at least can get something for the new loops.

Example

It does not yet support intermixed EH regions and loops (which I think
the old stuff does), but this just makes it so we at least can get
something for the new loops.
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 7, 2023
@ghost ghost assigned jakobbotsch Dec 7, 2023
@ghost

ghost commented Dec 7, 2023

Copy link
Copy Markdown

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

Issue Details

It does not yet support intermixed EH regions and loops (which I think the old stuff does), but this just makes it so we at least can get something for the new loops.

Author: jakobbotsch
Assignees: jakobbotsch
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
jakobbotsch marked this pull request as ready for review December 7, 2023 20:20
@jakobbotsch

Copy link
Copy Markdown
Member Author

cc @dotnet/jit-contrib PTAL @BruceForstall

@BruceForstall

BruceForstall commented Dec 7, 2023 •

Copy link
Copy Markdown
Contributor

I think you shouldn't remove the old loop region graph dumping... yet. Maybe you can add a DOTNET config to dump the old one and make dumping the new one the default?

Why couldn't you use the existing RegionGraph graph structure and add the loop into it instead of writing your own dumper?

Presumably new loops are properly nested within EH regions, or properly encompass entire EH regions, so wouldn't inserting the new loops in the existing RegionGraph as is done with the old loops give support for displaying both?

I guess the issue for new loops is loop nesting is not lexical (by block ranges). Although there should still be block-disjoint well-formed loop nesting, and that nesting should be well-formed w.r.t. EH regions.

@jakobbotsch

Copy link
Copy Markdown
Member Author

I think you shouldn't remove the old loop region graph dumping... yet. Maybe you can add a DOTNET config to dump the old one and make dumping the new one the default?

That's fair, I can do that.

Why couldn't you use the existing RegionGraph graph structure and add the loop into it instead of writing your own dumper?

Presumably new loops are properly nested within EH regions, or properly encompass entire EH regions, so wouldn't inserting the new loops in the existing RegionGraph as is done with the old loops give support for displaying both?

I guess the issue for new loops is loop nesting is not lexical (by block ranges).

Right, that's the problem.

Although there should still be block-disjoint well-formed loop nesting, and that nesting should be well-formed w.r.t. EH regions.

While there is some form of nesting property, it is not generally true that EH regions are well-scoped with regards to the parent loops. That is, not all blocks of an EH region inside a loop are necessarily part of the loop.
Consider the following example:

for (int i = 0; i < 100; i++)
{
  try
  {
    // BB01
    if (i == 50)
    {
      // BB02
      break;
    }
    // BB03
    Foo();
  }
  catch
  {
    // BB04
    break;
  }
}

The loop here contains BB01 and BB03, but it does not contain BB02 and BB04. On the other hand, the EH region does contain BB01, BB02 and BB03. So there is no general way to draw a nested relationship between the loop and (full) EH region, I think.

@jakobbotsch

Copy link
Copy Markdown
Member Author

I've reintroduced the old loop dumping under JitDumpFgOldLoops=1, can you please take another look @BruceForstall?

@BruceForstall

Copy link
Copy Markdown
Contributor

Regarding your example: note that an EH "region" is either the 'try' or the handler, not both: the 'try' and handler are considered separately. So in your example, the loop BB01/BB03 are properly nested within the 'try'.

The change is that the RegionGraph as currently implemented depends on BasicBlock bbNum ranges to determine nesting. For new loops, you would have to tell it both the set of blocks in a loop and what the nesting relationship is between a loop and it's parent loop. (Or have a separate implementation entirely, if warranted.)

But it's still valid, I think, to be able to represent EH and loop nesting.

CONFIG_INTEGER(JitDumpFgDot, W("JitDumpFgDot"), 1) // 0 == dump XML format; non-zero == dump DOT format
CONFIG_INTEGER(JitDumpFgEH, W("JitDumpFgEH"), 0) // 0 == no EH regions; non-zero == include EH regions
CONFIG_INTEGER(JitDumpFgLoops, W("JitDumpFgLoops"), 0) // 0 == no loop regions; non-zero == include loop regions
CONFIG_INTEGER(JitDumpFgOldLoops, W("JitDumpFgOldLoops"), 0) // 0 == no old loop regions; non-zero == include old loop

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this.

@jakobbotsch

Copy link
Copy Markdown
Member Author

Regarding your example: note that an EH "region" is either the 'try' or the handler, not both: the 'try' and handler are considered separately. So in your example, the loop BB01/BB03 are properly nested within the 'try'.

The regions for the loop and try would intersect and be disjoint; the try does not contain all blocks of the loop (e.g. i++) and the loop does not contain all blocks of the try (e.g. BB02), but they do share several blocks (e.g. BB01). So there is no nesting relationship.

@BruceForstall

Copy link
Copy Markdown
Contributor

ok, makes sense.

@jakobbotsch
jakobbotsch merged commit 7847872 into dotnet:main Dec 9, 2023
@jakobbotsch
jakobbotsch deleted the new-loops-fg-dump branch December 9, 2023 10:23
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 9, 2024
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