[HWToLLVM][ArcToLLVM] Spill array values early #9218
+412
−57
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.
Spill
hw.arrayvalues on the stack at their definition site instead of their use sites to reduce the number of redundant alloca + store ops created. This should mitigate the negative effects of #9172, fixing #9211.This PR adds the
HWToLLVMArraySpillCachehelper to the HWToLLVM conversion patterns. Certain operations on!hw.arraytyped values need to "spill" (i.e., copy into a buffer, usually stack allocated) their input arrays in order to access dynamically indexed elements. The cache is used to avoid spilling the array for each such user separately. Instead,operations that create an array value which needs spilling allocate a buffer that can be shared by the value's users. HW Dialect operations that inherently allocate a buffer for their output arrays (AggregateConstantOp,ArrayInjectOp,ArraySliceOp) use the cache to associate their output value with a pointer to the buffer, so it does not need to be spilled again. Non-HW Dialect producers of HW array values (e.g.,arc.state_load) need to be handled pre conversion. This is done by invokingspillNonHWOps.Use of the cache is optional and can be disabled by passing
spill-arrays-early=falsetoconvert-hw-to-llvmor using anulloptvalue for the cache argument ofpopulateHWToLLVMConversionPatterns. In fact, conversions passes that do not disableallowPatternRollbackmust not use the cache since a buffer added to the cache once cannot be removed in case of a rollback.