[RISCV] reorganize getFrameIndexReference to reduce code duplication [nfc]
authorPhilip Reames <preames@rivosinc.com>
Thu, 26 May 2022 15:55:47 +0000 (08:55 -0700)
committerPhilip Reames <listmail@philipreames.com>
Thu, 26 May 2022 16:44:58 +0000 (09:44 -0700)
commitd58cc0839ee5935e649dbbc18c898a8e4bcd6724
treeb47395f3c583e376f7a4af59673ca27c5f14f555
parenta831ce528fc0fd16734d644e62ae956834276c1b
[RISCV] reorganize getFrameIndexReference to reduce code duplication [nfc]

This change reorganizes the majority of frame index resolution into a two strep process.

    Step 1 - Select which base register we're going to use.
    Step 2 - Compute the offset from that base register.

The key point is that this allows us to share the step 2 logic for the SP case. This reduces the code duplication, and (I think) makes the code much easier to follow.

I also went ahead and added assertions into phase 2 to catch errors where we select an illegal base pointer. In general, we can't index from a base register to a stack location if that requires crossing a variable and unknown region. In practice, we have two such cases: dynamic stack realign and var sized objects. Note that crossing the scalable region is fine since while variable, it's a known variability which can be expressed in the offset.

Differential Revision: https://reviews.llvm.org/D126403
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp