The expansion of the frame indices
In principle, replacing the frame indices that you’ve used so far is an easy task. As already mentioned, the MachineFrameInfo
instance of your function maintains a mapping of the frame indices to an offset in your stack. Therefore, replacing the frame indices with the stack address is as simple as translating each index with its corresponding computation: stack plus offset.
Note
The offset held by the mapping in the MachineFrameInfo
instance is described from the beginning of the stack frame. Therefore, you can use this offset directly if you use a frame pointer, but you need to adjust it to account for the changes made in the prologue if you use a stack pointer. We will come back to this and illustrate it in Figure 20.3.
In practice, things get more complicated because materializing your stack-plus-offset value may require you to introduce additional instructions, and since the expansion happens after register allocation...