Improve SSA renaming memory usage (dotnet/coreclr#15000)
authormikedn <onemihaid@hotmail.com>
Fri, 8 Mar 2019 18:29:07 +0000 (20:29 +0200)
committerSergey Andreenko <seandree@microsoft.com>
Fri, 8 Mar 2019 18:29:06 +0000 (10:29 -0800)
commite083eb94e63ee16f9fe7281e9f2c42599bc431e0
treebbaaf93deaf802119accf7b82945f031b22a5b7e
parent07c8afd9257154ee535124c6365e0a44790db41a
Improve SSA renaming memory usage (dotnet/coreclr#15000)

* Cleanup DumpStacks

It's not exactly useful to dump all the stacks after pushing to a stack. Nor is it useful to dump all the stack after popping only some, perhaps none, in PopBlockStacks.

Also dump stack from top to bottom, makes it easier to find the top, which is usually what you care about during SSA renaming.

* Stop passing null block to SsaRenameState::Push

It makes no difference if the definition is in the "block before any real blocks..." or at the start of the first block, it's just an unnecessary complication.

* Stop handling byrefStatesMatchGcHeapStates in SsaRenameState

SsaBuilder already handles that, doing it again in SsaRenameState just duplicates logic.

* Stop using "count" as a name for "SSA number"

Worst name ever.

Also use "block" consistently, instead of a mix of "bb" and "block".

* Delete "ConstructedArray", not needed

* Various cleanup

- Change SsaRenameState to a class
- Cleanup remaining function comments
- Move SsaRenameStateForBlock & SsaRenameStateLocDef inside SsaRenameState
- Make EnsureStacks private
- Reorder data members
- Use m_ prefix consistently

* Replace jitstd::list with a custom stack

std::list has a few drawbacks:
- It's a doubly linked list but a singly linked list suffices so every node wastes 8 bytes for an extra pointer.
- The list object itself is relatively large 2 head/tail pointers, node count and memory allocator. There can be hundreds of such objects (one for each local variable) so the smaller the better.

Replace with a simple singly linked, intrusive list based stack.

* Share push code between lclvar and memory

It's pretty much the same logic (the only difference is that in the memory case "top" can't ever be null so by sharing the code we get a redundant null check).

Commit migrated from https://github.com/dotnet/coreclr/commit/fb583867ae37e75cf9f5c4f556627283a257d67b
src/coreclr/src/jit/gentree.h
src/coreclr/src/jit/ssabuilder.cpp
src/coreclr/src/jit/ssabuilder.h
src/coreclr/src/jit/ssarenamestate.cpp
src/coreclr/src/jit/ssarenamestate.h