-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
IR explicit pointer refactor. #4336
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We don't optimise stores of loads of integers any more, until we have proper data analysis and can detect mutations of values which are considered for this transform.
…TypeInfo::Aliases
…s/sway into otrho/2819_pointer-as-an-ir-type
…' into otrho/2819_pointer-as-an-ir-type
Though this sort of things will be handled by peephole opts when they arrive.
otrho
added
big
this task is hard and will take a while
code quality
compiler: ir
IRgen and sway-ir including optimization passes
compiler: codegen
Everything to do with IR->ASM, register allocation, etc.
compiler: optimization
IR Optimization Passes
labels
Mar 27, 2023
This was referenced Mar 27, 2023
This was referenced Mar 27, 2023
vaivaswatha
reviewed
Mar 28, 2023
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.
Except for ir_generation/function.rs
and the tests, I've (mostly) reviewed the other files. Leaving some comments before I get to these two.
vaivaswatha
previously approved these changes
Mar 29, 2023
vaivaswatha
approved these changes
Mar 29, 2023
tritao
approved these changes
Apr 2, 2023
This was referenced Apr 6, 2023
This was referenced May 30, 2023
vaivaswatha
added a commit
that referenced
this pull request
Jul 19, 2023
This was required previously, but after the IR refactoring (#4336), this is no longer required, and actually worsens things. Fixes #4747. For the two tests mentioned there, (both based on https://github.com/hashcloak/fuel-crypto/) the compile time now comes down from 30m -> 16s and 180m -> 31s.
vaivaswatha
added a commit
that referenced
this pull request
Jul 21, 2023
This was required previously, but after the IR refactoring (#4336), this is no longer required, and actually worsens things. Fixes #4747. For the two tests mentioned there, (both based on https://github.com/hashcloak/fuel-crypto/) the compile time now comes down from 1. 30m -> 16s 2. 180m -> 31s Also fixes two bugs uncovered: 1. Bug in DCE - Fixes #4763. (1b512b8) 2. Bug in interaction b/w asm gen and reg alloc spiller (7a40496). --------- Co-authored-by: IGI-111 <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
big
this task is hard and will take a while
code quality
compiler: codegen
Everything to do with IR->ASM, register allocation, etc.
compiler: ir
IRgen and sway-ir including optimization passes
compiler: optimization
IR Optimization Passes
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.
This is a big refactor of the IR and ASMgen, closes #2819.
The main purpose is multi-faceted but still generally related to pointers in IR while supporting various backends other than just Fuel VM.
Pointer
is a member ofType
(again).extract_value
andinsert_element
have been removed.get_elem_ptr
(GEP) instruction is now used to index aggregate fields.addr_of
has been replaced byptr_to_int
.Sway does not have explicit references. But values which cannot fit in a register must be passed by reference. Therefore the implementation has generally followed the idea of 'copy' types and 'reference' types. The size of a register is target specific, but until recently the only target we had was the Fuel VM. This is no longer true so assumptions about 'copy' types vs 'reference' types needed to be relaxed.
The IRgen now tries not to assume which atomic types are 'reference' types and assumes all atomic types (including
b256
) may be passed by value. Aggregate types (structs, enums, arrays) are all assumed to be passed by reference. All memory reads and writes are performed byload
orstore
rather than explicitly usingmem_copy
.The IR itself makes no assumptions about passing by value or reference as all uses of pointers are explicit. If a value is to be passed by reference then is must use a pointer type.
To accommodate the 64-bit register size of the Fuel VM and atomic types which don't fit (primarily
b256
, but potentially any integer type wider than 64 bits) some new transformational 'demotion' passes have been introduced. These find all the unsupported uses of wide types and 'demotes' them to temporary values on the stack and refers to their pointers.constdemotion
- demotes large immediate constants.argdemotion
- demotes large arguments to functions, explicitly passing them by reference.retdemotion
- demotes large return values to be stored locally by the caller and updated in place by the callee.miscdemotion
- demotes other miscellaneous values:log
instruction.ptr_to_int
instruction.These passes don't alter the use by value vs reference semantics though and will still use
load
andstore
on the large values. To fix this another new pass has been introduced.memcpyopt
will primarily search forstore
s ofload
s and convert them to amem_copy_val
. This greatly simplifies ASMgen, which can now assume aload
orstore
is only for register sized values, andMCP
can be used otherwise.Unfortunately adding these temporaries adds some bloat to the raw IRgen output.
memcpyopt
also attempts copy propagation to reduce redundant memory copies. At this stage it uses a very conservative algorithm but may be improved in the future when we can introduce comprehensive data flow analysis.This is still a partial work in progress in that it has uncovered many new issues which need to be addressed, which I'll be adding shortly. They should be listed below as they'll reference this PR.