Prologue/epilogue doesn't adjust stack pointer #187
Comments
Yep. We also need to set up a frame pointer and restore the old one in the epilogue. The We don't currently have instructions that can manipulate the stack and frame pointer registers. I don't think we should track those registers as SSA values since there are so many implicit uses of them. There is a I expect that prologues and epilogues will often contain ISA-specific instructions (like enter/leave), so the whole thing is delegated to |
Oh, and functions with a |
Here's an overview of what's required to fix this issue and #189. TargetIsa hookPrologue and epilogue code is quite dependent on both the ISA and the function's calling convention, so the responsibility for generating this code is delegated to the
Currently, the ProloguesThe prologue code must:
For most ABIs, the frame pointer should point to the stack address where the previous frame pointer was saved so the frames form a linked list: struct Frame {
struct Frame *caller_fp;
void *return_address;
}; See figure 3.3 in the x86-64 ABI specification. EpiloguesThe epilogues before each return instruction must:
Callee-saved registersThe x86-64 ABI specifies that For an initial implementation, we can save the full set of callee-saved registers. This will work correctly, but a common optimization is to only save those registers that are clobbered by the function body. This requires some collaboration with the register allocator. ... more implementation notes to follow ... |
Example for x86-64This is what I imagine the prologue and epilogue code would look like in a function that has 168 bytes of local variables and that uses the callee-saved
New instructionsWe need to define some new instructions for manipulating the stack pointer and the frame pointer. Some are ISA-independent instructions defined in
New instructions specific to Intel ISAs are defined in
All of these new instructions need to be marked as OptimizationsWe should start out focusing on creating correct code for prologues and epilogues. Later we can add some optimizations:
|
Hey Jakob! I'm interested in starting to work on the optimizations you listed at the end here. If you have plans or ideas for how these should be implemented, I'm all ears. |
@tyler, I've commented over in #189. I'll flesh it out more later. |
Closing this since we have native prologues now. Leaving #189 open for the optimizations |
Prologues and epilogues don't yet include code to adjust the stack pointer.
For example, running
cton-util compile
on this input:Produces this output:
which is this machine code:
which has spills but no stack allocation.
The text was updated successfully, but these errors were encountered: