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: Replace BlockSet with BitVec, and remove BB epoch #110034

Merged
merged 11 commits into from
Nov 21, 2024

Conversation

amanasifkhalid
Copy link
Member

@amanasifkhalid amanasifkhalid commented Nov 21, 2024

Part of #107749. Prerequisite for #110026.

  • Use postorder number-based BitVecs in RBO and block layout.
  • Use bbID-based BitVecs in fgIncorporateProfileData. This runs early enough in the JIT frontend such that I would expect bbIDs and bbNums to be 1:1, so I don't expect any TP impact from this change.

Switch descriptor creation still uses bbNums as a key into a BitVec as a workaround for BB epoch invariants -- I'll try switching this over to bbID in a follow-up to evaluate the TP cost of a sparser bitset.

@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 21, 2024
Copy link
Contributor

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

@amanasifkhalid
Copy link
Member Author

cc @dotnet/jit-contrib, @jakobbotsch PTAL. No diffs. Thanks!

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

Can we delete BlockSet/and the epoch fields as well now?

@amanasifkhalid
Copy link
Member Author

Can we delete BlockSet/and the epoch fields as well now?

Yes. I can include that in this PR, if you'd like.

@amanasifkhalid amanasifkhalid changed the title JIT: Replace remaining BlockSet usages with BitVec JIT: Replace BlockSet with BitVec, and remove BB epoch Nov 21, 2024
unsigned bbNumMax = compiler->fgBBNumMax;
BitVecTraits bitVecTraits(bbNumMax + 1, compiler);
BitVec uniqueSuccBlocks(BitVecOps::MakeEmpty(&bitVecTraits));
unsigned* const targetNums = new unsigned[NumSucc()];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
unsigned* const targetNums = new unsigned[NumSucc()];
unsigned* const targetNums = new (compiler, CMK_DebugOnly) unsigned[NumSucc()];

But is this change even necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess not -- if we get to the point where we don't need bbNum at all, we can rewrite this logic altogether to print in bbID order (or some other order).

Comment on lines 3925 to 3941
// Create a set with all the successors.
BitVecTraits bitVecTraits(compBasicBlockID, this);
BitVec succBlocks(BitVecOps::MakeEmpty(&bitVecTraits));
for (BasicBlock* const bTarget : block->SwitchTargets())
{
BitVecOps::AddElemD(&bitVecTraits, succBlocks, bTarget->bbNum);
BitVecOps::AddElemD(&bitVecTraits, succBlocks, bTarget->bbID);
}
// Now we should have a set of unique successors that matches what's in the switchMap.
// First, check the number of entries, then make sure all the blocks in uniqueSuccSet
// are in the BlockSet.
// are in the BitVec.
unsigned count = BitVecOps::Count(&bitVecTraits, succBlocks);
assert(uniqueSuccSet.numDistinctSuccs == count);
for (unsigned i = 0; i < uniqueSuccSet.numDistinctSuccs; i++)
{
assert(BitVecOps::IsMember(&bitVecTraits, succBlocks,
uniqueSuccSet.nonDuplicates[i]->getDestinationBlock()->bbNum));
uniqueSuccSet.nonDuplicates[i]->getDestinationBlock()->bbID));
}
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not necessary for removing BlockSet, but these are the last few usages of bbNum-based BitVecs, so I thought I'd get rid of them while I'm here.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see anything wrong with bitsets based on either bbNum or bbID. I suppose it depends on whether the end goal is to remove bbID in favor of bbNum or bbNum in favor of bbID. I am slightly biased towards keeping the name as bbNum considering that we are going to be using them as indices, and that it has been much more pervasive than bbID in the JIT, but I guess it's unimportant.

I would suggest we make these changes in the PR that eventually unifies the two fields and removes one of them, though.

{
nonDups[nonDupInd] = succEdge;
nonDupInd++;
BitVecOps::RemoveElemD(&blockVecTraits, uniqueSuccBlocks, targ->bbNum);
BitVecOps::RemoveElemD(&blockVecTraits, uniqueSuccBlocks, targ->bbID);
}
Copy link
Member

Choose a reason for hiding this comment

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

Ditto here, it seems unnecessary to change this.

Copy link
Member Author

Choose a reason for hiding this comment

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

This switch to bbID-based BitVecs isn't Debug-only like the other ones, though the sparser set doesn't seem to have impacted TP all that much.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I would be surprised if the sparser bit sets are going to have any noticeable impact on performance.. A few bits wasted due to optimizing out entire basic blocks is going to be a drop in the bucket compared to everything else that's happening when handling the IR in those basic blocks.

My feedback here probably more comes down to bikeshedding over the naming of the final field we are going to end up with...

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

LGTM!

@amanasifkhalid
Copy link
Member Author

/ba-g linux-x64 build timed out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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