circt icon indicating copy to clipboard operation
circt copied to clipboard

[HWToLLVM] Lower constant HW arrays to static global LLVM arrays

Open zyedidia opened this issue 1 year ago • 3 comments

Currently an HW array that only consists of constants is lowered in the same way as an array containing dynamic arrays: by creating the array at runtime and allocating it on the stack. For constant arrays this is very wasteful compared to statically allocating the array. This change makes the ArrayCreateOpConversion lower to a static global LLVM array if the HW array is constant. It will return an array loaded from a global address.

The ArrayGetOpConversion checks if the array was loaded from a LoadOp, and if so just gets the element through the pointer directly rather than dynamically allocating the array on the stack.

I'm not sure how to handle the naming for the generated arrays. I'm currently using a global namespace to do this, but I'm not sure that's a great solution. Let me know if there's a better way, thanks!

zyedidia avatar Aug 10 '22 00:08 zyedidia

I'm going to move this over the to HWToLLVM pass to resolve the conflicts.

zyedidia avatar Aug 10 '22 01:08 zyedidia

I think the CI is failing due to an unrelated bug that was in main at the time when it ran. Is it possible to re-run the test?

zyedidia avatar Aug 11 '22 04:08 zyedidia

@zyedidia you can rebase the PR

youngar avatar Aug 11 '22 06:08 youngar

Great, thanks! I will make these additional changes, and I'm currently rebasing and resolving conflicts.

zyedidia avatar Aug 15 '22 22:08 zyedidia

Thanks for the comments, I think I have made all the requested changes!

zyedidia avatar Aug 16 '22 00:08 zyedidia