Add donated scratch regs to dependency list only when they are used #7628
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds msrUsedDonated flag to mark that a donated scratch register has been used.
If using
findOrCreateScratchRegister
within ICF and there are no free registers,cg->allocateRegister
is called causing a fatal assertionTR_ASSERT_FATAL(false, "Attempting to assign a register (%s) inside ICF", getRegisterName(targetRegister, self()->cg()));
Thus, we have to donate registers before entering an internal control flow region where we request a scratch register.
For example, there are cases where we need at most 2 scratch registers, and the use of the second register is guarded by an if statement (i.e. in the java superclass test on Z):
Since the superclass test is generated inside an ICF region, we need to allocate the 2 registers before entering the region. But when
castClassDepth != -1
, we never use one of the donated registers. Adding this unused register to the dependency list results in an extra real register being allocated.This change allows the Scratch Register Manager to treat donated and non-donated registers in the same way:
they are only added to the dependency list if they are actually used
. This way, we allow the user to set the capacity of the scratch register manager to the maximum amount they need, and donate how ever many they want (up to the maximum), without worrying about whether all donated registers are used in all cases.