-
Notifications
You must be signed in to change notification settings - Fork 396
[HWToLLVM][ArcToLLVM] Spill array values early #9218
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
[HWToLLVM][ArcToLLVM] Spill array values early #9218
Conversation
3c40229 to
1e486ed
Compare
|
@SimonEbner, could you check if this actually fixes the compile time regression in your example? |
|
Thanks for checking. |
|
Sure, I think this patch is great, more than good enough. Thanks for looking into this |
maerhart
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great! Thanks!
lib/Conversion/HWToLLVM/HWToLLVM.cpp
Outdated
| auto oneC = LLVM::ConstantOp::create( | ||
| rewriter, op->getLoc(), IntegerType::get(rewriter.getContext(), 32), | ||
| rewriter.getI32IntegerAttr(1)); | ||
| arrPtr = LLVM::AllocaOp::create( | ||
| rewriter, op->getLoc(), | ||
| LLVM::LLVMPointerType::get(rewriter.getContext()), | ||
| adaptor.getInput().getType(), oneC, | ||
| /*alignment=*/4); | ||
| LLVM::StoreOp::create(rewriter, op->getLoc(), adaptor.getInput(), arrPtr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: as this occurs a few times, we could factor it out into a helper function.
89a8174 to
dceae1b
Compare
Co-authored-by: Martin Erhart <[email protected]>
Co-authored-by: Martin Erhart <[email protected]>
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.