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

Improve union field access in IR. #4354

Open
otrho opened this issue Mar 27, 2023 · 0 comments
Open

Improve union field access in IR. #4354

otrho opened this issue Mar 27, 2023 · 0 comments
Labels
compiler: codegen Everything to do with IR->ASM, register allocation, etc. compiler: ir IRgen and sway-ir including optimization passes enhancement New feature or request

Comments

@otrho
Copy link
Contributor

otrho commented Mar 27, 2023

Prior to #4336 the IR would index different union fields or variants via the extract_value instruction. This was a bit of a convenient hack as it worked fairly well and didn't require a special extra instruction to do it instead.

This behaviour has translated over to now by done by get_elem_ptr. It's still a hack but no longer necessary. A more proper approach would be to use a cast_ptr instruction, which is what LLVM does.

Care would have to be taken though in ASMgen since we lay out memory in a big-endian format, simply changing the type but not the actual address may not point to the proper field value bytes. (This is an advantage of using little-endian memory!)

@otrho otrho added enhancement New feature or request compiler: ir IRgen and sway-ir including optimization passes compiler: codegen Everything to do with IR->ASM, register allocation, etc. labels Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: codegen Everything to do with IR->ASM, register allocation, etc. compiler: ir IRgen and sway-ir including optimization passes enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant