Skip to content

Conversation

@PaulusParssinen
Copy link
Contributor

@PaulusParssinen PaulusParssinen commented Jan 31, 2024

Came across some low-hanging fruits while browsing through ILCompiler and decided to try utilize some newer .NET APIs to make the code a bit more "modern". Shouldn't be much of a performance optimization though.

Commits

  • Spanify ILReader
    • Yet another ref struct span holder to the runtime.
    • Make ILReader ref struct, only holding IL body bytes and a offset
    • Use BinaryPrimitives instead of manual bit-shifting
    • Remove unused ILStreamReader.cs
    • Make ReadMIbcGroup return List<MethodProfileData> instead of using enumerator, which prevented the use of ILReader (now a ref struct)
  • Spanify ILStackHelper
    • Use ILReader instead to deduplicate reading logic
    • Aand fix regression.. also combined two branches by using ILReader.ReadBranchDestination
  • Use built-in Read7BitEncodedInt
    • These were recently exposed public.
    • This commit also removes the import ReaderExtensions.cs from ILCompiler.Ryujit. It wasn't used in the project.

Had trouble running NativeAOT smoketests locally because my hardware doesn't support AVX512, which caused nativeaot.SmokeTests\HardwareIntrinsics\X64Avx512 to fail.

* Make ILReader ref struct, only holding IL body bytes and a offset
* Use BinaryPrimitives instead of manual bit-shifting
* Remove unused ILStreamReader.cs
* Make ReadMIbcGroup return List instead of using enumerator
* Remove ReaderExtensions.cs from ILCompiler.Ryujit
@ghost ghost added area-crossgen2-coreclr community-contribution Indicates that the PR has been added by a community member labels Jan 31, 2024
@PaulusParssinen PaulusParssinen marked this pull request as draft January 31, 2024 23:13
* Use ILReader.ReadBranchDestination to merge two switch branches
Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Thank you, looks great!

Cc @jakobbotsch for IBC changes.


if (!isVariableSize)
currentOffset += opcode.GetSize();
if (!hasReadOperand)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: wasn't isVariableSize better? We defaulted to false and had to set to true in one case. Now we still default to false, but need to set it to true in two cases.

Copy link
Contributor Author

@PaulusParssinen PaulusParssinen Feb 1, 2024

Choose a reason for hiding this comment

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

I thought about name of this for a while. I think the meaning of the variable changed because it's using ILReader now.
Before we manually kept track of the currentOffset where isVariableSize was used to skip the ILOpcode.switch_ case in which the currentOffset was calculated manually.
Now by using ILReader.Skip(opcode) (which essentially is operandSize - op.GetSize() + switch handling) we can avoid this duplicated logic, however because we want to read the operand in two cases for stack height tracking purposes (branches and calls/newobj) we need to flip the bit to avoid "reading" the operand twice in ILReader. That was why I called it hasReadOperand.

tldr: the current branches that use the bool are not variable sized, switch was the only special case and we now handle it in ILReader.Skip(op)

@MichalStrehovsky MichalStrehovsky merged commit 65a0617 into dotnet:main Feb 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-crossgen2-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants