llvm.org GIT mirror llvm / b64145c
[MIPS] Implement support for -mstack-alignment. 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'. Reviewers: sdardis Reviewed By: sdardis Subscribers: llvm-commits, arichardson Differential Revision: https://reviews.llvm.org/D35874 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310891 91177308-0d34-0410-b5e6-96231b3b80d8 John Baldwin 2 years ago
7 changed file(s) with 36 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
3737 using namespace llvm;
3838
3939 Mips16FrameLowering::Mips16FrameLowering(const MipsSubtarget &STI)
40 : MipsFrameLowering(STI, STI.stackAlignment()) {}
40 : MipsFrameLowering(STI, STI.getStackAlignment()) {}
4141
4242 void Mips16FrameLowering::emitPrologue(MachineFunction &MF,
4343 MachineBasicBlock &MBB) const {
717717 StringRef CPU = MIPS_MC::selectMipsCPU(TT, TM.getTargetCPU());
718718 StringRef FS = TM.getTargetFeatureString();
719719 const MipsTargetMachine &MTM = static_cast(TM);
720 const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM);
720 const MipsSubtarget STI(TT, CPU, FS, MTM.isLittleEndian(), MTM, 0);
721721
722722 bool IsABICalls = STI.isABICalls();
723723 const MipsABIInfo &ABI = MTM.getABI();
389389 }
390390
391391 MipsSEFrameLowering::MipsSEFrameLowering(const MipsSubtarget &STI)
392 : MipsFrameLowering(STI, STI.stackAlignment()) {}
392 : MipsFrameLowering(STI, STI.getStackAlignment()) {}
393393
394394 void MipsSEFrameLowering::emitPrologue(MachineFunction &MF,
395395 MachineBasicBlock &MBB) const {
5959 void MipsSubtarget::anchor() {}
6060
6161 MipsSubtarget::MipsSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
62 bool little, const MipsTargetMachine &TM)
62 bool little, const MipsTargetMachine &TM,
63 unsigned StackAlignOverride)
6364 : MipsGenSubtargetInfo(TT, CPU, FS), MipsArchVersion(MipsDefault),
6465 IsLittle(little), IsSoftFloat(false), IsSingleFloat(false), IsFPXX(false),
6566 NoABICalls(false), IsFP64bit(false), UseOddSPReg(true),
6970 InMips16HardFloat(Mips16HardFloat), InMicroMipsMode(false), HasDSP(false),
7071 HasDSPR2(false), HasDSPR3(false), AllowMixed16_32(Mixed16_32 | Mips_Os16),
7172 Os16(Mips_Os16), HasMSA(false), UseTCCInDIV(false), HasSym32(false),
72 HasEVA(false), DisableMadd4(false), HasMT(false), TM(TM),
73 TargetTriple(TT), TSInfo(),
74 InstrInfo(
75 MipsInstrInfo::create(initializeSubtargetDependencies(CPU, FS, TM))),
73 HasEVA(false), DisableMadd4(false), HasMT(false),
74 StackAlignOverride(StackAlignOverride), TM(TM), TargetTriple(TT),
75 TSInfo(), InstrInfo(MipsInstrInfo::create(
76 initializeSubtargetDependencies(CPU, FS, TM))),
7677 FrameLowering(MipsFrameLowering::create(*this)),
7778 TLInfo(MipsTargetLowering::create(TM, *this)) {
7879
156157 if (InMips16Mode && !IsSoftFloat)
157158 InMips16HardFloat = true;
158159
160 if (StackAlignOverride)
161 stackAlignment = StackAlignOverride;
162 else if (isABI_N32() || isABI_N64())
163 stackAlignment = 16;
164 else {
165 assert(isABI_O32() && "Unknown ABI for stack alignment!");
166 stackAlignment = 8;
167 }
168
159169 return *this;
160170 }
161171
154154 // Disable use of the `jal` instruction.
155155 bool UseLongCalls = false;
156156
157 /// The minimum alignment known to hold of the stack frame on
158 /// entry to the function and which must be maintained by every function.
159 unsigned stackAlignment;
160
161 /// The overridden stack alignment.
162 unsigned StackAlignOverride;
163
157164 InstrItineraryData InstrItins;
158165
159166 // We can override the determination of whether we are in mips16 mode
185192 /// This constructor initializes the data members to match that
186193 /// of the specified triple.
187194 MipsSubtarget(const Triple &TT, StringRef CPU, StringRef FS, bool little,
188 const MipsTargetMachine &TM);
195 const MipsTargetMachine &TM, unsigned StackAlignOverride);
189196
190197 /// ParseSubtargetFeatures - Parses features string setting specified
191198 /// subtarget options. Definition of function is auto generated by tblgen.
294301 // really use them if in addition we are in mips16 mode
295302 static bool useConstantIslands();
296303
297 unsigned stackAlignment() const {
298 return isABI_N32() || isABI_N64() ? 16 : 8;
299 }
304 unsigned getStackAlignment() const { return stackAlignment; }
300305
301306 // Grab relocation model
302307 Reloc::Model getRelocationModel() const;
113113 getEffectiveCodeModel(CM), OL),
114114 isLittle(isLittle), TLOF(llvm::make_unique()),
115115 ABI(MipsABIInfo::computeTargetABI(TT, CPU, Options.MCOptions)),
116 Subtarget(nullptr), DefaultSubtarget(TT, CPU, FS, isLittle, *this),
116 Subtarget(nullptr), DefaultSubtarget(TT, CPU, FS, isLittle, *this,
117 Options.StackAlignmentOverride),
117118 NoMips16Subtarget(TT, CPU, FS.empty() ? "-mips16" : FS.str() + ",-mips16",
118 isLittle, *this),
119 isLittle, *this, Options.StackAlignmentOverride),
119120 Mips16Subtarget(TT, CPU, FS.empty() ? "+mips16" : FS.str() + ",+mips16",
120 isLittle, *this) {
121 isLittle, *this, Options.StackAlignmentOverride) {
121122 Subtarget = &DefaultSubtarget;
122123 initAsmInfo();
123124 }
190191 // function that reside in TargetOptions.
191192 resetTargetOptions(F);
192193 I = llvm::make_unique(TargetTriple, CPU, FS, isLittle,
193 *this);
194 *this, Options.StackAlignmentOverride);
194195 }
195196 return I.get();
196197 }
0 ; RUN: llc -march=mipsel < %s | FileCheck %s -check-prefix=32
1 ; RUN: llc -march=mipsel -stack-alignment=32 < %s | FileCheck %s -check-prefix=A32-32
12 ; RUN: llc -march=mipsel -mattr=+fp64 < %s | FileCheck %s -check-prefix=32
23 ; RUN: llc -march=mips64el -mcpu=mips3 < %s | FileCheck %s -check-prefix=64
34 ; RUN: llc -march=mips64el -mcpu=mips4 < %s | FileCheck %s -check-prefix=64
45 ; RUN: llc -march=mips64el -mcpu=mips64 < %s | FileCheck %s -check-prefix=64
6 ; RUN: llc -march=mips64el -mcpu=mips64 -stack-alignment=32 < %s | FileCheck %s -check-prefix=A32-64
57
68 ; 32: addiu $sp, $sp, -8
79 ; 64: daddiu $sp, $sp, -16
10 ; A32-32: addiu $sp, $sp, -32
11 ; A32-64: daddiu $sp, $sp, -32
812
913 define i32 @foo1() #0 {
1014 entry: