This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] reorganize getFrameIndexReference to reduce code duplication [nfc]
ClosedPublic

Authored by reames on May 25 2022, 11:45 AM.

Details

Summary

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.

After D125787, I believe this to be fully NFC. Careful review to confirm that is appreciated. :)

Diff Detail

Event Timeline

reames created this revision.May 25 2022, 11:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2022, 11:45 AM
reames requested review of this revision.May 25 2022, 11:45 AM

Thanks for refactoring it! I think it's fully NFC.

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
794

Do you think it would be better to mention the BP here?

Looks good, thank you. Should be easier to work with.

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
758

A quick grep shows that starting assertion messages with lower-case letters is far less common in the RISCV backend than upper-case ones.

766

What would you say to an early return here after FrameReg == getFPReg(STI)?

794

Mentioning BP makes sense to me. But then the question may become whether we should mention that if it's BP then there's var-sized objects below it, in case people think SP always equals BP? Maybe I'm overthinking it.

reames marked an inline comment as done.May 26 2022, 9:17 AM
reames added inline comments.
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
794

This point is mentioned in the comment during base register selection. I went ahead and duplicated that here for now.

The comments have a bunch of unhelpful duplication. I'm planning a separate follow up change (with separate review) to address that.

This revision was not accepted when it landed; it landed in state Needs Review.May 26 2022, 9:45 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.