This is an archive of the discontinued LLVM Phabricator instance.

[MIPS] Implement support for -mstack-alignment.
ClosedPublic

Authored by bsdjhb on Jul 25 2017, 8:22 PM.

Details

Summary

This is modeled on the implementation for x86 which stores the command line
option in a 'StackAlignOverride' field in MipsSubtarget and then uses this
to compute a 'stackAlignment' value in
MipsSubtarget::initializeSubtargetDependencies.

The stackAlignment() method in MipsSubTarget is renamed to getStackAlignment()
and returns the computed 'stackAlignment'.

Event Timeline

bsdjhb created this revision.Jul 25 2017, 8:22 PM

I don't have a test for this yet. My actual use case is a MIPS-based CPU which has 256 bit registers which require 32-byte alignment. This requires the stack to be 32-byte aligned, and using this patch with '-mstack-alignment=32' permits these registers to be spilled onto the stack without alignment exceptions.

It seems that the only tests that use -mstack-alignment on x86 are written in IR (with which I'm not really familiar) but are geared towards a similar case for AVX registers. If it is possible to come up with IR that when assembled results in 'daddui sp,sp,-48' when assembled normally, then we could have a test to verify it uses '-64' when -mstack-alignment=32 is used and -48 otherwise.

sdardis set the repository for this revision to rL LLVM.Jul 31 2017, 2:49 AM
sdardis added a subscriber: llvm-commits.
sdardis edited edge metadata.Aug 3 2017, 4:27 AM

If it is possible to come up with IR that when assembled results in 'daddui sp,sp,-48' when assembled normally, then we could have a test to verify it uses '-64' when -mstack-alignment=32 is used and -48 otherwise.

See test/CodeGen/Mips/stack-alignment.ll, you'll need to modify that to accept whatever option is produced by -mstack-alignment.

lib/Target/Mips/MipsSubtarget.cpp
163

That looks incorrect. Instead, if the ABI is N32 or N64, then the stack alignment is 16, otherwise of O32 it is 8.

At least according to GCC and the documentation I have to hand.

Can you split this patch into two parts, the first one that fixes the bug and the second which implements this new feature?

bsdjhb updated this revision to Diff 109804.Aug 4 2017, 12:47 PM
  • Rebase on top of D36326.
  • Add tests.
sdardis added inline comments.Aug 5 2017, 11:55 AM
lib/Target/Mips/MipsSubtarget.cpp
166

Can you introduce an assertion here that the ABI is O32? If EABI support is ever brought back or another MIPS abi is introduced, I'd prefer debug builds complain loudly.

bsdjhb updated this revision to Diff 110110.Aug 7 2017, 4:31 PM
  • Rebase on updated D36326.
  • clang-format and add an assertion.
bsdjhb marked 2 inline comments as done.Aug 7 2017, 4:32 PM
sdardis added inline comments.Aug 8 2017, 9:03 AM
lib/Target/Mips/MipsSubtarget.cpp
166

That assert needs a && "Unknown ABI for stack alignment!".

test/CodeGen/Mips/stack-alignment.ll
11

This need to be doubled up to A32-32, A32-64 with the appropriate (d)addiu instructions.

bsdjhb updated this revision to Diff 110483.Aug 9 2017, 2:45 PM
  • Add a message to the assertion.
sdardis accepted this revision.Aug 14 2017, 6:37 AM

LGTM with a comment fix.

lib/Target/Mips/MipsSubtarget.h
162

"Override the stack alignmen.t" -> "The overridden stack alignment."

This revision is now accepted and ready to land.Aug 14 2017, 6:37 AM
bsdjhb marked 3 inline comments as done.Aug 14 2017, 10:42 AM
bsdjhb closed this revision.Aug 14 2017, 2:50 PM