Skip to content
Bevin Hansson edited this page Oct 11, 2018 · 7 revisions

Just random notes.

Stack access / prolog-epilog insertion

  • Use processFunctionBeforeFrameFinalized in TargetFrameInfo to do push-pop optimization. We can eliminate dead frame objects by marking them as such and they will be excluded from the stack.
  • LAO is -1 since the SP points to top of stack at function entry.
  • Prologue can either use ADD SP+e if we are GB (what about optz? can they expand the stack somehow?).
    • Otherwise we need to do some kind of LD HL, dd; ADD HL, SP; LD SP, HL. This needs to save HL if it's live (an input parameter)
    • The solution in this case could be to add HL as a CSR. (but then it will be restored? we don't want that.)
    • Wait, what about (forgot what i was going to write here lol)
    • Basically what we want is simply to add a frame object before/after the CSR frame objects are added, so we can do a PUSH HL before/after CSR and then restore it with a frame index load after the prologue.
    • This is all a good argument for excluding HL from the calling convention.

Prologue is basically:

if HL is live && (!GB || largeStack):
  Push HL (this should have the last frame object index if we do it right)
Push CSR
if GB:
  Repeat:
    ADD SP-stackSize
else:
  LD HL, -stackSize
  ADD HL, SP
  LD SP, HL
  HL = LD16_FI (frameidx of the HL we pushed) (how to make this frameindex access efficient? It's at the very far end of the stack from the HL we just made!)

Epilogue is much harder if HL is live-out, since we can't do the PUSH HL trick on function exit.

Clone this wiki locally