-
Notifications
You must be signed in to change notification settings - Fork 4
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
observe calling convention (for x86-64) #117
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
x86-64 has a calling convention of passing arguments in registers. Use this convention for compatibility with C code. So that we can call C code an be called from C code. References: https://www.agner.org/optimize/calling_conventions.pdf https://en.wikipedia.org/wiki/X86_calling_conventions#References
If there are no local variables, there is no need to make space on the stack to accomodate them. This reduces the size of the emitted code.
In x86-64, function arguments are passed in registers, we cannot calculate the address here. Maybe this change should better be done in the derefll code, but the understanding is lacking about how it even works :(
✅ Deploy Preview for espl1000 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Add some tests to cover the stackframe size and stackframe indices for local variables and arguments. Also fix some cases in which that was wrong.
Also extend rat/ to be able to name partial registers for correctly emitting load/store (mov) of different width. So for local variables the compiler now respects the width of them when load/store. Also needs to be done for the function arguments.
50112f5
to
65c4b01
Compare
When creating the stackframe, store the function parameters there. So they do not have to be saved/restored around function calls. It's just easier when they have a fixed place, relative to the current stackframe.
In x86-64 there are some callee-saved registers. Write some function to determine which registers the callee must save, depending on which registers it is touching (inspect struct RAT). To err on the side of caution, we can always save and restore more registers than actually needed. It will just make the code bigger. Stack frame layout: ----- return address ----- ... callee saved registers <- rbp ----- local variables ----- ... saved args <- rsp ----- ... ... 0x0 The registers are saved as part of TAC_SETUP_STACKFRAME and restored as part of TAC_RETURN. This is not optimal since TAC_RETURN can appear multiple times and the code to restore the registers will then be duplicated. It would be great to have some kind of IR statement to designate the function epilogue to restore the callers registers and finally 'ret'. The TAC_RETURN could then just 'jmp' there. References: https://www.agner.org/optimize/calling_conventions.pdf
Add assert_examples.sh That script loops through all ${filename}.dg files in examples/ and if ${filename}.exitcode exists, it compiles that example program and compares the exit code with whats in ${filename}.exitcode. If the exit code of the compiled example program matches, that test is PASS, otherwise it is FAIL. This makes for an easy way to write tests for various compiler features.
Some code was still not aware that the function args are saved into the stackframe and thus have an address. So there is no limitation and their address is always available inside the function.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.