Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- ARMFrameLowering.cpp - ARM Frame Information ----------------------===// |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 10 | // This file contains the ARM implementation of TargetFrameLowering class. |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 14 | #include "ARMFrameLowering.h" |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 15 | #include "ARMBaseInstrInfo.h" |
Evan Cheng | e45d685 | 2011-01-11 21:46:47 +0000 | [diff] [blame] | 16 | #include "ARMBaseRegisterInfo.h" |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 17 | #include "ARMConstantPoolValue.h" |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 18 | #include "ARMMachineFunctionInfo.h" |
Evan Cheng | a20cde3 | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 19 | #include "MCTargetDesc/ARMAddressingModes.h" |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 21 | #include "llvm/CodeGen/MachineFunction.h" |
| 22 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Evan Cheng | eb56dca | 2010-11-22 18:12:04 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/RegisterScavenging.h" |
Tim Northover | e0ccdc6 | 2015-10-28 22:46:43 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCAsmInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 27 | #include "llvm/IR/CallingConv.h" |
| 28 | #include "llvm/IR/Function.h" |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCContext.h" |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 30 | #include "llvm/Support/CommandLine.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetOptions.h" |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 32 | |
Reid Kleckner | bdfc05f | 2016-10-11 21:14:03 +0000 | [diff] [blame] | 33 | #define DEBUG_TYPE "arm-frame-lowering" |
| 34 | |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
Benjamin Kramer | 9fceb90 | 2012-02-24 22:09:25 +0000 | [diff] [blame] | 37 | static cl::opt<bool> |
Jakob Stoklund Olesen | 68a922c | 2012-01-06 22:19:37 +0000 | [diff] [blame] | 38 | SpillAlignedNEONRegs("align-neon-spills", cl::Hidden, cl::init(true), |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 39 | cl::desc("Align ARM NEON spills in prolog and epilog")); |
| 40 | |
| 41 | static MachineBasicBlock::iterator |
| 42 | skipAlignedDPRCS2Spills(MachineBasicBlock::iterator MI, |
| 43 | unsigned NumAlignedDPRCS2Regs); |
| 44 | |
Eric Christopher | 45fb7b6 | 2014-06-26 19:29:59 +0000 | [diff] [blame] | 45 | ARMFrameLowering::ARMFrameLowering(const ARMSubtarget &sti) |
| 46 | : TargetFrameLowering(StackGrowsDown, sti.getStackAlignment(), 0, 4), |
| 47 | STI(sti) {} |
| 48 | |
Akira Hatanaka | ddf76aa | 2015-05-23 01:14:08 +0000 | [diff] [blame] | 49 | bool ARMFrameLowering::noFramePointerElim(const MachineFunction &MF) const { |
| 50 | // iOS always has a FP for backtracking, force other targets to keep their FP |
| 51 | // when doing FastISel. The emitted code is currently superior, and in cases |
| 52 | // like test-suite's lencod FastISel isn't quite correct when FP is eliminated. |
| 53 | return TargetFrameLowering::noFramePointerElim(MF) || |
| 54 | MF.getSubtarget<ARMSubtarget>().useFastISel(); |
| 55 | } |
| 56 | |
Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 57 | /// hasFP - Return true if the specified function should have a dedicated frame |
| 58 | /// pointer register. This is true if the function has variable sized allocas |
| 59 | /// or if frame pointer elimination is disabled. |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 60 | bool ARMFrameLowering::hasFP(const MachineFunction &MF) const { |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 61 | const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo(); |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 62 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 63 | |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 64 | // ABI-required frame pointer. |
| 65 | if (MF.getTarget().Options.DisableFramePointerElim(MF)) |
Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 66 | return true; |
| 67 | |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 68 | // Frame pointer required for use within this function. |
| 69 | return (RegInfo->needsStackRealignment(MF) || |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 70 | MFI.hasVarSizedObjects() || |
| 71 | MFI.isFrameAddressTaken()); |
Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 74 | /// hasReservedCallFrame - Under normal circumstances, when a frame pointer is |
| 75 | /// not required, we reserve argument space for call sites in the function |
| 76 | /// immediately on entry to the current function. This eliminates the need for |
| 77 | /// add/sub sp brackets around call sites. Returns true if the call frame is |
| 78 | /// included as part of the stack frame. |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 79 | bool ARMFrameLowering::hasReservedCallFrame(const MachineFunction &MF) const { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 80 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
| 81 | unsigned CFSize = MFI.getMaxCallFrameSize(); |
Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 82 | // It's not always a good idea to include the call frame as part of the |
| 83 | // stack frame. ARM (especially Thumb) has small immediate offset to |
| 84 | // address the stack frame. So a large call frame can cause poor codegen |
| 85 | // and may even makes it impossible to scavenge a register. |
| 86 | if (CFSize >= ((1 << 12) - 1) / 2) // Half of imm12 |
| 87 | return false; |
| 88 | |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 89 | return !MFI.hasVarSizedObjects(); |
Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 92 | /// canSimplifyCallFramePseudos - If there is a reserved call frame, the |
| 93 | /// call frame pseudos can be simplified. Unlike most targets, having a FP |
| 94 | /// is not sufficient here since we still may reference some objects via SP |
| 95 | /// even when FP is available in Thumb2 mode. |
| 96 | bool |
| 97 | ARMFrameLowering::canSimplifyCallFramePseudos(const MachineFunction &MF) const { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 98 | return hasReservedCallFrame(MF) || MF.getFrameInfo().hasVarSizedObjects(); |
Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 101 | static bool isCSRestore(MachineInstr &MI, const ARMBaseInstrInfo &TII, |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 102 | const MCPhysReg *CSRegs) { |
Eric Christopher | b006fc9 | 2010-11-18 19:40:05 +0000 | [diff] [blame] | 103 | // Integer spill area is handled with "pop". |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 104 | if (isPopOpcode(MI.getOpcode())) { |
Eric Christopher | b006fc9 | 2010-11-18 19:40:05 +0000 | [diff] [blame] | 105 | // The first two operands are predicates. The last two are |
| 106 | // imp-def and imp-use of SP. Check everything in between. |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 107 | for (int i = 5, e = MI.getNumOperands(); i != e; ++i) |
| 108 | if (!isCalleeSavedRegister(MI.getOperand(i).getReg(), CSRegs)) |
Eric Christopher | b006fc9 | 2010-11-18 19:40:05 +0000 | [diff] [blame] | 109 | return false; |
| 110 | return true; |
| 111 | } |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 112 | if ((MI.getOpcode() == ARM::LDR_POST_IMM || |
| 113 | MI.getOpcode() == ARM::LDR_POST_REG || |
| 114 | MI.getOpcode() == ARM::t2LDR_POST) && |
| 115 | isCalleeSavedRegister(MI.getOperand(0).getReg(), CSRegs) && |
| 116 | MI.getOperand(1).getReg() == ARM::SP) |
Jim Grosbach | bdb7ed1 | 2010-12-10 18:41:15 +0000 | [diff] [blame] | 117 | return true; |
Eric Christopher | b006fc9 | 2010-11-18 19:40:05 +0000 | [diff] [blame] | 118 | |
| 119 | return false; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 122 | static void emitRegPlusImmediate( |
| 123 | bool isARM, MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, |
| 124 | const DebugLoc &dl, const ARMBaseInstrInfo &TII, unsigned DestReg, |
| 125 | unsigned SrcReg, int NumBytes, unsigned MIFlags = MachineInstr::NoFlags, |
| 126 | ARMCC::CondCodes Pred = ARMCC::AL, unsigned PredReg = 0) { |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 127 | if (isARM) |
Tim Northover | c9432eb | 2013-11-04 23:04:15 +0000 | [diff] [blame] | 128 | emitARMRegPlusImmediate(MBB, MBBI, dl, DestReg, SrcReg, NumBytes, |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 129 | Pred, PredReg, TII, MIFlags); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 130 | else |
Tim Northover | c9432eb | 2013-11-04 23:04:15 +0000 | [diff] [blame] | 131 | emitT2RegPlusImmediate(MBB, MBBI, dl, DestReg, SrcReg, NumBytes, |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 132 | Pred, PredReg, TII, MIFlags); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Tim Northover | c9432eb | 2013-11-04 23:04:15 +0000 | [diff] [blame] | 135 | static void emitSPUpdate(bool isARM, MachineBasicBlock &MBB, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 136 | MachineBasicBlock::iterator &MBBI, const DebugLoc &dl, |
Tim Northover | c9432eb | 2013-11-04 23:04:15 +0000 | [diff] [blame] | 137 | const ARMBaseInstrInfo &TII, int NumBytes, |
| 138 | unsigned MIFlags = MachineInstr::NoFlags, |
| 139 | ARMCC::CondCodes Pred = ARMCC::AL, |
| 140 | unsigned PredReg = 0) { |
| 141 | emitRegPlusImmediate(isARM, MBB, MBBI, dl, TII, ARM::SP, ARM::SP, NumBytes, |
| 142 | MIFlags, Pred, PredReg); |
| 143 | } |
| 144 | |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 145 | static int sizeOfSPAdjustment(const MachineInstr &MI) { |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 146 | int RegSize; |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 147 | switch (MI.getOpcode()) { |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 148 | case ARM::VSTMDDB_UPD: |
| 149 | RegSize = 8; |
| 150 | break; |
| 151 | case ARM::STMDB_UPD: |
| 152 | case ARM::t2STMDB_UPD: |
| 153 | RegSize = 4; |
| 154 | break; |
| 155 | case ARM::t2STR_PRE: |
| 156 | case ARM::STR_PRE_IMM: |
| 157 | return 4; |
| 158 | default: |
| 159 | llvm_unreachable("Unknown push or pop like instruction"); |
| 160 | } |
| 161 | |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 162 | int count = 0; |
| 163 | // ARM and Thumb2 push/pop insts have explicit "sp, sp" operands (+ |
| 164 | // pred) so the list starts at 4. |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 165 | for (int i = MI.getNumOperands() - 1; i >= 4; --i) |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 166 | count += RegSize; |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 167 | return count; |
| 168 | } |
| 169 | |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 170 | static bool WindowsRequiresStackProbe(const MachineFunction &MF, |
| 171 | size_t StackSizeInBytes) { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 172 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
Saleem Abdulrasool | fb8a66f | 2015-01-31 02:26:37 +0000 | [diff] [blame] | 173 | const Function *F = MF.getFunction(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 174 | unsigned StackProbeSize = (MFI.getStackProtectorIndex() > 0) ? 4080 : 4096; |
Saleem Abdulrasool | fb8a66f | 2015-01-31 02:26:37 +0000 | [diff] [blame] | 175 | if (F->hasFnAttribute("stack-probe-size")) |
| 176 | F->getFnAttribute("stack-probe-size") |
| 177 | .getValueAsString() |
| 178 | .getAsInteger(0, StackProbeSize); |
| 179 | return StackSizeInBytes >= StackProbeSize; |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 182 | namespace { |
| 183 | struct StackAdjustingInsts { |
| 184 | struct InstInfo { |
| 185 | MachineBasicBlock::iterator I; |
| 186 | unsigned SPAdjust; |
| 187 | bool BeforeFPSet; |
| 188 | }; |
| 189 | |
| 190 | SmallVector<InstInfo, 4> Insts; |
| 191 | |
| 192 | void addInst(MachineBasicBlock::iterator I, unsigned SPAdjust, |
| 193 | bool BeforeFPSet = false) { |
| 194 | InstInfo Info = {I, SPAdjust, BeforeFPSet}; |
| 195 | Insts.push_back(Info); |
| 196 | } |
| 197 | |
| 198 | void addExtraBytes(const MachineBasicBlock::iterator I, unsigned ExtraBytes) { |
David Majnemer | 562e829 | 2016-08-12 00:18:03 +0000 | [diff] [blame] | 199 | auto Info = find_if(Insts, [&](InstInfo &Info) { return Info.I == I; }); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 200 | assert(Info != Insts.end() && "invalid sp adjusting instruction"); |
| 201 | Info->SPAdjust += ExtraBytes; |
| 202 | } |
| 203 | |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 204 | void emitDefCFAOffsets(MachineBasicBlock &MBB, const DebugLoc &dl, |
| 205 | const ARMBaseInstrInfo &TII, bool HasFP) { |
| 206 | MachineFunction &MF = *MBB.getParent(); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 207 | unsigned CFAOffset = 0; |
| 208 | for (auto &Info : Insts) { |
| 209 | if (HasFP && !Info.BeforeFPSet) |
| 210 | return; |
| 211 | |
| 212 | CFAOffset -= Info.SPAdjust; |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 213 | unsigned CFIIndex = MF.addFrameInst( |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 214 | MCCFIInstruction::createDefCfaOffset(nullptr, CFAOffset)); |
| 215 | BuildMI(MBB, std::next(Info.I), dl, |
Adrian Prantl | b9fa945 | 2014-12-16 00:20:49 +0000 | [diff] [blame] | 216 | TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 217 | .addCFIIndex(CFIIndex) |
| 218 | .setMIFlags(MachineInstr::FrameSetup); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 222 | } |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 223 | |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 224 | /// Emit an instruction sequence that will align the address in |
| 225 | /// register Reg by zero-ing out the lower bits. For versions of the |
| 226 | /// architecture that support Neon, this must be done in a single |
| 227 | /// instruction, since skipAlignedDPRCS2Spills assumes it is done in a |
| 228 | /// single instruction. That function only gets called when optimizing |
| 229 | /// spilling of D registers on a core with the Neon instruction set |
| 230 | /// present. |
| 231 | static void emitAligningInstructions(MachineFunction &MF, ARMFunctionInfo *AFI, |
| 232 | const TargetInstrInfo &TII, |
| 233 | MachineBasicBlock &MBB, |
| 234 | MachineBasicBlock::iterator MBBI, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 235 | const DebugLoc &DL, const unsigned Reg, |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 236 | const unsigned Alignment, |
| 237 | const bool MustBeSingleInstruction) { |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 238 | const ARMSubtarget &AST = |
| 239 | static_cast<const ARMSubtarget &>(MF.getSubtarget()); |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 240 | const bool CanUseBFC = AST.hasV6T2Ops() || AST.hasV7Ops(); |
| 241 | const unsigned AlignMask = Alignment - 1; |
| 242 | const unsigned NrBitsToZero = countTrailingZeros(Alignment); |
| 243 | assert(!AFI->isThumb1OnlyFunction() && "Thumb1 not supported"); |
| 244 | if (!AFI->isThumbFunction()) { |
| 245 | // if the BFC instruction is available, use that to zero the lower |
| 246 | // bits: |
| 247 | // bfc Reg, #0, log2(Alignment) |
| 248 | // otherwise use BIC, if the mask to zero the required number of bits |
| 249 | // can be encoded in the bic immediate field |
| 250 | // bic Reg, Reg, Alignment-1 |
| 251 | // otherwise, emit |
| 252 | // lsr Reg, Reg, log2(Alignment) |
| 253 | // lsl Reg, Reg, log2(Alignment) |
| 254 | if (CanUseBFC) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 255 | BuildMI(MBB, MBBI, DL, TII.get(ARM::BFC), Reg) |
| 256 | .addReg(Reg, RegState::Kill) |
| 257 | .addImm(~AlignMask) |
| 258 | .add(predOps(ARMCC::AL)); |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 259 | } else if (AlignMask <= 255) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 260 | AddDefaultCC(BuildMI(MBB, MBBI, DL, TII.get(ARM::BICri), Reg) |
| 261 | .addReg(Reg, RegState::Kill) |
| 262 | .addImm(AlignMask) |
| 263 | .add(predOps(ARMCC::AL))); |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 264 | } else { |
| 265 | assert(!MustBeSingleInstruction && |
| 266 | "Shouldn't call emitAligningInstructions demanding a single " |
| 267 | "instruction to be emitted for large stack alignment for a target " |
| 268 | "without BFC."); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 269 | AddDefaultCC(BuildMI(MBB, MBBI, DL, TII.get(ARM::MOVsi), Reg) |
| 270 | .addReg(Reg, RegState::Kill) |
| 271 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsr, NrBitsToZero)) |
| 272 | .add(predOps(ARMCC::AL))); |
| 273 | AddDefaultCC(BuildMI(MBB, MBBI, DL, TII.get(ARM::MOVsi), Reg) |
| 274 | .addReg(Reg, RegState::Kill) |
| 275 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, NrBitsToZero)) |
| 276 | .add(predOps(ARMCC::AL))); |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 277 | } |
| 278 | } else { |
| 279 | // Since this is only reached for Thumb-2 targets, the BFC instruction |
| 280 | // should always be available. |
| 281 | assert(CanUseBFC); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 282 | BuildMI(MBB, MBBI, DL, TII.get(ARM::t2BFC), Reg) |
| 283 | .addReg(Reg, RegState::Kill) |
| 284 | .addImm(~AlignMask) |
| 285 | .add(predOps(ARMCC::AL)); |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 289 | void ARMFrameLowering::emitPrologue(MachineFunction &MF, |
| 290 | MachineBasicBlock &MBB) const { |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 291 | MachineBasicBlock::iterator MBBI = MBB.begin(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 292 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 293 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 294 | MachineModuleInfo &MMI = MF.getMMI(); |
| 295 | MCContext &Context = MMI.getContext(); |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 296 | const TargetMachine &TM = MF.getTarget(); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 297 | const MCRegisterInfo *MRI = Context.getRegisterInfo(); |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 298 | const ARMBaseRegisterInfo *RegInfo = STI.getRegisterInfo(); |
| 299 | const ARMBaseInstrInfo &TII = *STI.getInstrInfo(); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 300 | assert(!AFI->isThumb1OnlyFunction() && |
| 301 | "This emitPrologue does not support Thumb1!"); |
| 302 | bool isARM = !AFI->isThumbFunction(); |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 303 | unsigned Align = STI.getFrameLowering()->getStackAlignment(); |
Tim Northover | 775aaeb | 2015-11-05 21:54:58 +0000 | [diff] [blame] | 304 | unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 305 | unsigned NumBytes = MFI.getStackSize(); |
| 306 | const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo(); |
Tim Northover | 775aaeb | 2015-11-05 21:54:58 +0000 | [diff] [blame] | 307 | |
| 308 | // Debug location must be unknown since the first debug location is used |
| 309 | // to determine the end of the prologue. |
| 310 | DebugLoc dl; |
| 311 | |
| 312 | unsigned FramePtr = RegInfo->getFrameRegister(MF); |
| 313 | |
| 314 | // Determine the sizes of each callee-save spill areas and record which frame |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 315 | // belongs to which callee-save spill areas. |
| 316 | unsigned GPRCS1Size = 0, GPRCS2Size = 0, DPRCSSize = 0; |
| 317 | int FramePtrSpillFI = 0; |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 318 | int D8SpillFI = 0; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 319 | |
Jakob Stoklund Olesen | e380183 | 2012-10-26 21:46:57 +0000 | [diff] [blame] | 320 | // All calls are tail calls in GHC calling conv, and functions have no |
| 321 | // prologue/epilogue. |
Eric Christopher | b332236 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 322 | if (MF.getFunction()->getCallingConv() == CallingConv::GHC) |
| 323 | return; |
| 324 | |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 325 | StackAdjustingInsts DefCFAOffsetCandidates; |
Sergey Dmitrouk | 3cc62b3 | 2015-04-08 10:10:12 +0000 | [diff] [blame] | 326 | bool HasFP = hasFP(MF); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 327 | |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 328 | // Allocate the vararg register save area. |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 329 | if (ArgRegsSaveSize) { |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 330 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -ArgRegsSaveSize, |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 331 | MachineInstr::FrameSetup); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 332 | DefCFAOffsetCandidates.addInst(std::prev(MBBI), ArgRegsSaveSize, true); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 333 | } |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 334 | |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 335 | if (!AFI->hasStackFrame() && |
| 336 | (!STI.isTargetWindows() || !WindowsRequiresStackProbe(MF, NumBytes))) { |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 337 | if (NumBytes - ArgRegsSaveSize != 0) { |
| 338 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -(NumBytes - ArgRegsSaveSize), |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 339 | MachineInstr::FrameSetup); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 340 | DefCFAOffsetCandidates.addInst(std::prev(MBBI), |
| 341 | NumBytes - ArgRegsSaveSize, true); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 342 | } |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 343 | DefCFAOffsetCandidates.emitDefCFAOffsets(MBB, dl, TII, HasFP); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 344 | return; |
| 345 | } |
| 346 | |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 347 | // Determine spill area sizes. |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 348 | for (unsigned i = 0, e = CSI.size(); i != e; ++i) { |
| 349 | unsigned Reg = CSI[i].getReg(); |
| 350 | int FI = CSI[i].getFrameIdx(); |
| 351 | switch (Reg) { |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 352 | case ARM::R8: |
| 353 | case ARM::R9: |
| 354 | case ARM::R10: |
| 355 | case ARM::R11: |
| 356 | case ARM::R12: |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 357 | if (STI.splitFramePushPop(MF)) { |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 358 | GPRCS2Size += 4; |
| 359 | break; |
| 360 | } |
Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 361 | LLVM_FALLTHROUGH; |
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 362 | case ARM::R0: |
| 363 | case ARM::R1: |
| 364 | case ARM::R2: |
| 365 | case ARM::R3: |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 366 | case ARM::R4: |
| 367 | case ARM::R5: |
| 368 | case ARM::R6: |
| 369 | case ARM::R7: |
| 370 | case ARM::LR: |
| 371 | if (Reg == FramePtr) |
| 372 | FramePtrSpillFI = FI; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 373 | GPRCS1Size += 4; |
| 374 | break; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 375 | default: |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 376 | // This is a DPR. Exclude the aligned DPRCS2 spills. |
| 377 | if (Reg == ARM::D8) |
| 378 | D8SpillFI = FI; |
Tim Northover | c9432eb | 2013-11-04 23:04:15 +0000 | [diff] [blame] | 379 | if (Reg < ARM::D8 || Reg >= ARM::D8 + AFI->getNumAlignedDPRCS2Regs()) |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 380 | DPRCSSize += 8; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 381 | } |
| 382 | } |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 383 | |
Eric Christopher | b006fc9 | 2010-11-18 19:40:05 +0000 | [diff] [blame] | 384 | // Move past area 1. |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 385 | MachineBasicBlock::iterator LastPush = MBB.end(), GPRCS1Push, GPRCS2Push; |
| 386 | if (GPRCS1Size > 0) { |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 387 | GPRCS1Push = LastPush = MBBI++; |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 388 | DefCFAOffsetCandidates.addInst(LastPush, GPRCS1Size, true); |
| 389 | } |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 390 | |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 391 | // Determine starting offsets of spill areas. |
Tim Northover | 228c943 | 2014-11-05 00:27:13 +0000 | [diff] [blame] | 392 | unsigned GPRCS1Offset = NumBytes - ArgRegsSaveSize - GPRCS1Size; |
| 393 | unsigned GPRCS2Offset = GPRCS1Offset - GPRCS2Size; |
| 394 | unsigned DPRAlign = DPRCSSize ? std::min(8U, Align) : 4U; |
| 395 | unsigned DPRGapSize = (GPRCS1Size + GPRCS2Size + ArgRegsSaveSize) % DPRAlign; |
| 396 | unsigned DPRCSOffset = GPRCS2Offset - DPRGapSize - DPRCSSize; |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 397 | int FramePtrOffsetInPush = 0; |
| 398 | if (HasFP) { |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 399 | FramePtrOffsetInPush = |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 400 | MFI.getObjectOffset(FramePtrSpillFI) + ArgRegsSaveSize; |
| 401 | AFI->setFramePtrSpillOffset(MFI.getObjectOffset(FramePtrSpillFI) + |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 402 | NumBytes); |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 403 | } |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 404 | AFI->setGPRCalleeSavedArea1Offset(GPRCS1Offset); |
| 405 | AFI->setGPRCalleeSavedArea2Offset(GPRCS2Offset); |
| 406 | AFI->setDPRCalleeSavedAreaOffset(DPRCSOffset); |
| 407 | |
Tim Northover | c9432eb | 2013-11-04 23:04:15 +0000 | [diff] [blame] | 408 | // Move past area 2. |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 409 | if (GPRCS2Size > 0) { |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 410 | GPRCS2Push = LastPush = MBBI++; |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 411 | DefCFAOffsetCandidates.addInst(LastPush, GPRCS2Size); |
| 412 | } |
Tim Northover | c9432eb | 2013-11-04 23:04:15 +0000 | [diff] [blame] | 413 | |
Tim Northover | 228c943 | 2014-11-05 00:27:13 +0000 | [diff] [blame] | 414 | // Prolog/epilog inserter assumes we correctly align DPRs on the stack, so our |
| 415 | // .cfi_offset operations will reflect that. |
| 416 | if (DPRGapSize) { |
| 417 | assert(DPRGapSize == 4 && "unexpected alignment requirements for DPRs"); |
Duncan P. N. Exon Smith | ec083b5 | 2016-08-17 00:53:04 +0000 | [diff] [blame] | 418 | if (LastPush != MBB.end() && |
| 419 | tryFoldSPUpdateIntoPushPop(STI, MF, &*LastPush, DPRGapSize)) |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 420 | DefCFAOffsetCandidates.addExtraBytes(LastPush, DPRGapSize); |
| 421 | else { |
Tim Northover | 228c943 | 2014-11-05 00:27:13 +0000 | [diff] [blame] | 422 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -DPRGapSize, |
| 423 | MachineInstr::FrameSetup); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 424 | DefCFAOffsetCandidates.addInst(std::prev(MBBI), DPRGapSize); |
| 425 | } |
Tim Northover | 228c943 | 2014-11-05 00:27:13 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Eric Christopher | b006fc9 | 2010-11-18 19:40:05 +0000 | [diff] [blame] | 428 | // Move past area 3. |
Evan Cheng | 70d2963 | 2011-02-25 00:24:46 +0000 | [diff] [blame] | 429 | if (DPRCSSize > 0) { |
Evan Cheng | 70d2963 | 2011-02-25 00:24:46 +0000 | [diff] [blame] | 430 | // Since vpush register list cannot have gaps, there may be multiple vpush |
Evan Cheng | a921dc5 | 2011-02-25 01:29:29 +0000 | [diff] [blame] | 431 | // instructions in the prologue. |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 432 | while (MBBI->getOpcode() == ARM::VSTMDDB_UPD) { |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 433 | DefCFAOffsetCandidates.addInst(MBBI, sizeOfSPAdjustment(*MBBI)); |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 434 | LastPush = MBBI++; |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 435 | } |
Evan Cheng | 70d2963 | 2011-02-25 00:24:46 +0000 | [diff] [blame] | 436 | } |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 437 | |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 438 | // Move past the aligned DPRCS2 area. |
| 439 | if (AFI->getNumAlignedDPRCS2Regs() > 0) { |
| 440 | MBBI = skipAlignedDPRCS2Spills(MBBI, AFI->getNumAlignedDPRCS2Regs()); |
| 441 | // The code inserted by emitAlignedDPRCS2Spills realigns the stack, and |
| 442 | // leaves the stack pointer pointing to the DPRCS2 area. |
| 443 | // |
| 444 | // Adjust NumBytes to represent the stack slots below the DPRCS2 area. |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 445 | NumBytes += MFI.getObjectOffset(D8SpillFI); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 446 | } else |
| 447 | NumBytes = DPRCSOffset; |
| 448 | |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 449 | if (STI.isTargetWindows() && WindowsRequiresStackProbe(MF, NumBytes)) { |
| 450 | uint32_t NumWords = NumBytes >> 2; |
| 451 | |
| 452 | if (NumWords < 65536) |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 453 | BuildMI(MBB, MBBI, dl, TII.get(ARM::t2MOVi16), ARM::R4) |
| 454 | .addImm(NumWords) |
| 455 | .setMIFlags(MachineInstr::FrameSetup) |
| 456 | .add(predOps(ARMCC::AL)); |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 457 | else |
| 458 | BuildMI(MBB, MBBI, dl, TII.get(ARM::t2MOVi32imm), ARM::R4) |
Saleem Abdulrasool | 985dcf1 | 2014-05-07 03:03:31 +0000 | [diff] [blame] | 459 | .addImm(NumWords) |
| 460 | .setMIFlags(MachineInstr::FrameSetup); |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 461 | |
| 462 | switch (TM.getCodeModel()) { |
| 463 | case CodeModel::Small: |
| 464 | case CodeModel::Medium: |
| 465 | case CodeModel::Default: |
| 466 | case CodeModel::Kernel: |
| 467 | BuildMI(MBB, MBBI, dl, TII.get(ARM::tBL)) |
| 468 | .addImm((unsigned)ARMCC::AL).addReg(0) |
| 469 | .addExternalSymbol("__chkstk") |
Saleem Abdulrasool | 985dcf1 | 2014-05-07 03:03:31 +0000 | [diff] [blame] | 470 | .addReg(ARM::R4, RegState::Implicit) |
| 471 | .setMIFlags(MachineInstr::FrameSetup); |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 472 | break; |
| 473 | case CodeModel::Large: |
Saleem Abdulrasool | 7158303 | 2014-05-01 04:19:59 +0000 | [diff] [blame] | 474 | case CodeModel::JITDefault: |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 475 | BuildMI(MBB, MBBI, dl, TII.get(ARM::t2MOVi32imm), ARM::R12) |
Saleem Abdulrasool | 985dcf1 | 2014-05-07 03:03:31 +0000 | [diff] [blame] | 476 | .addExternalSymbol("__chkstk") |
| 477 | .setMIFlags(MachineInstr::FrameSetup); |
Saleem Abdulrasool | 7158303 | 2014-05-01 04:19:59 +0000 | [diff] [blame] | 478 | |
Saleem Abdulrasool | acd0338 | 2014-05-07 03:03:27 +0000 | [diff] [blame] | 479 | BuildMI(MBB, MBBI, dl, TII.get(ARM::tBLXr)) |
| 480 | .addImm((unsigned)ARMCC::AL).addReg(0) |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 481 | .addReg(ARM::R12, RegState::Kill) |
Saleem Abdulrasool | 985dcf1 | 2014-05-07 03:03:31 +0000 | [diff] [blame] | 482 | .addReg(ARM::R4, RegState::Implicit) |
| 483 | .setMIFlags(MachineInstr::FrameSetup); |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 484 | break; |
| 485 | } |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 486 | |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 487 | AddDefaultCC(BuildMI(MBB, MBBI, dl, TII.get(ARM::t2SUBrr), ARM::SP) |
| 488 | .addReg(ARM::SP, RegState::Kill) |
| 489 | .addReg(ARM::R4, RegState::Kill) |
| 490 | .setMIFlags(MachineInstr::FrameSetup) |
| 491 | .add(predOps(ARMCC::AL))); |
Saleem Abdulrasool | 25947c3 | 2014-04-30 07:05:07 +0000 | [diff] [blame] | 492 | NumBytes = 0; |
| 493 | } |
| 494 | |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 495 | if (NumBytes) { |
| 496 | // Adjust SP after all the callee-save spills. |
Tim Northover | beb5bcc | 2015-09-23 22:21:09 +0000 | [diff] [blame] | 497 | if (AFI->getNumAlignedDPRCS2Regs() == 0 && |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 498 | tryFoldSPUpdateIntoPushPop(STI, MF, &*LastPush, NumBytes)) |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 499 | DefCFAOffsetCandidates.addExtraBytes(LastPush, NumBytes); |
| 500 | else { |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 501 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -NumBytes, |
| 502 | MachineInstr::FrameSetup); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 503 | DefCFAOffsetCandidates.addInst(std::prev(MBBI), NumBytes); |
| 504 | } |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 505 | |
Evan Cheng | eb56dca | 2010-11-22 18:12:04 +0000 | [diff] [blame] | 506 | if (HasFP && isARM) |
| 507 | // Restore from fp only in ARM mode: e.g. sub sp, r7, #24 |
| 508 | // Note it's not safe to do this in Thumb2 mode because it would have |
| 509 | // taken two instructions: |
| 510 | // mov sp, r7 |
| 511 | // sub sp, #24 |
| 512 | // If an interrupt is taken between the two instructions, then sp is in |
| 513 | // an inconsistent state (pointing to the middle of callee-saved area). |
| 514 | // The interrupt handler can end up clobbering the registers. |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 515 | AFI->setShouldRestoreSPFromFP(true); |
| 516 | } |
| 517 | |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 518 | // Set FP to point to the stack slot that contains the previous FP. |
| 519 | // For iOS, FP is R7, which has now been stored in spill area 1. |
| 520 | // Otherwise, if this is not iOS, all the callee-saved registers go |
| 521 | // into spill area 1, including the FP in R11. In either case, it |
| 522 | // is in area one and the adjustment needs to take place just after |
| 523 | // that push. |
| 524 | if (HasFP) { |
| 525 | MachineBasicBlock::iterator AfterPush = std::next(GPRCS1Push); |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 526 | unsigned PushSize = sizeOfSPAdjustment(*GPRCS1Push); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 527 | emitRegPlusImmediate(!AFI->isThumbFunction(), MBB, AfterPush, |
| 528 | dl, TII, FramePtr, ARM::SP, |
| 529 | PushSize + FramePtrOffsetInPush, |
| 530 | MachineInstr::FrameSetup); |
| 531 | if (FramePtrOffsetInPush + PushSize != 0) { |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 532 | unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createDefCfa( |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 533 | nullptr, MRI->getDwarfRegNum(FramePtr, true), |
| 534 | -(ArgRegsSaveSize - FramePtrOffsetInPush))); |
| 535 | BuildMI(MBB, AfterPush, dl, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
Adrian Prantl | b9fa945 | 2014-12-16 00:20:49 +0000 | [diff] [blame] | 536 | .addCFIIndex(CFIIndex) |
| 537 | .setMIFlags(MachineInstr::FrameSetup); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 538 | } else { |
| 539 | unsigned CFIIndex = |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 540 | MF.addFrameInst(MCCFIInstruction::createDefCfaRegister( |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 541 | nullptr, MRI->getDwarfRegNum(FramePtr, true))); |
| 542 | BuildMI(MBB, AfterPush, dl, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
Adrian Prantl | b9fa945 | 2014-12-16 00:20:49 +0000 | [diff] [blame] | 543 | .addCFIIndex(CFIIndex) |
| 544 | .setMIFlags(MachineInstr::FrameSetup); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | |
| 548 | // Now that the prologue's actual instructions are finalised, we can insert |
| 549 | // the necessary DWARF cf instructions to describe the situation. Start by |
| 550 | // recording where each register ended up: |
| 551 | if (GPRCS1Size > 0) { |
| 552 | MachineBasicBlock::iterator Pos = std::next(GPRCS1Push); |
| 553 | int CFIIndex; |
Jim Grosbach | f92e8f5 | 2014-04-04 02:10:55 +0000 | [diff] [blame] | 554 | for (const auto &Entry : CSI) { |
| 555 | unsigned Reg = Entry.getReg(); |
| 556 | int FI = Entry.getFrameIdx(); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 557 | switch (Reg) { |
| 558 | case ARM::R8: |
| 559 | case ARM::R9: |
| 560 | case ARM::R10: |
| 561 | case ARM::R11: |
| 562 | case ARM::R12: |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 563 | if (STI.splitFramePushPop(MF)) |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 564 | break; |
Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 565 | LLVM_FALLTHROUGH; |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 566 | case ARM::R0: |
| 567 | case ARM::R1: |
| 568 | case ARM::R2: |
| 569 | case ARM::R3: |
| 570 | case ARM::R4: |
| 571 | case ARM::R5: |
| 572 | case ARM::R6: |
| 573 | case ARM::R7: |
| 574 | case ARM::LR: |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 575 | CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset( |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 576 | nullptr, MRI->getDwarfRegNum(Reg, true), MFI.getObjectOffset(FI))); |
Rafael Espindola | b1f25f1 | 2014-03-07 06:08:31 +0000 | [diff] [blame] | 577 | BuildMI(MBB, Pos, dl, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
Adrian Prantl | b9fa945 | 2014-12-16 00:20:49 +0000 | [diff] [blame] | 578 | .addCFIIndex(CFIIndex) |
| 579 | .setMIFlags(MachineInstr::FrameSetup); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 580 | break; |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 585 | if (GPRCS2Size > 0) { |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 586 | MachineBasicBlock::iterator Pos = std::next(GPRCS2Push); |
Jim Grosbach | f92e8f5 | 2014-04-04 02:10:55 +0000 | [diff] [blame] | 587 | for (const auto &Entry : CSI) { |
| 588 | unsigned Reg = Entry.getReg(); |
| 589 | int FI = Entry.getFrameIdx(); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 590 | switch (Reg) { |
| 591 | case ARM::R8: |
| 592 | case ARM::R9: |
| 593 | case ARM::R10: |
| 594 | case ARM::R11: |
| 595 | case ARM::R12: |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 596 | if (STI.splitFramePushPop(MF)) { |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 597 | unsigned DwarfReg = MRI->getDwarfRegNum(Reg, true); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 598 | unsigned Offset = MFI.getObjectOffset(FI); |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 599 | unsigned CFIIndex = MF.addFrameInst( |
Rafael Espindola | b1f25f1 | 2014-03-07 06:08:31 +0000 | [diff] [blame] | 600 | MCCFIInstruction::createOffset(nullptr, DwarfReg, Offset)); |
| 601 | BuildMI(MBB, Pos, dl, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
Adrian Prantl | b9fa945 | 2014-12-16 00:20:49 +0000 | [diff] [blame] | 602 | .addCFIIndex(CFIIndex) |
| 603 | .setMIFlags(MachineInstr::FrameSetup); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 604 | } |
| 605 | break; |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (DPRCSSize > 0) { |
| 611 | // Since vpush register list cannot have gaps, there may be multiple vpush |
| 612 | // instructions in the prologue. |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 613 | MachineBasicBlock::iterator Pos = std::next(LastPush); |
Jim Grosbach | f92e8f5 | 2014-04-04 02:10:55 +0000 | [diff] [blame] | 614 | for (const auto &Entry : CSI) { |
| 615 | unsigned Reg = Entry.getReg(); |
| 616 | int FI = Entry.getFrameIdx(); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 617 | if ((Reg >= ARM::D0 && Reg <= ARM::D31) && |
| 618 | (Reg < ARM::D8 || Reg >= ARM::D8 + AFI->getNumAlignedDPRCS2Regs())) { |
| 619 | unsigned DwarfReg = MRI->getDwarfRegNum(Reg, true); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 620 | unsigned Offset = MFI.getObjectOffset(FI); |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 621 | unsigned CFIIndex = MF.addFrameInst( |
Rafael Espindola | b1f25f1 | 2014-03-07 06:08:31 +0000 | [diff] [blame] | 622 | MCCFIInstruction::createOffset(nullptr, DwarfReg, Offset)); |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 623 | BuildMI(MBB, Pos, dl, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
Adrian Prantl | b9fa945 | 2014-12-16 00:20:49 +0000 | [diff] [blame] | 624 | .addCFIIndex(CFIIndex) |
| 625 | .setMIFlags(MachineInstr::FrameSetup); |
Artyom Skrobov | f6830f4 | 2014-02-14 17:19:07 +0000 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
Tim Northover | 603d316 | 2014-11-14 22:45:33 +0000 | [diff] [blame] | 630 | // Now we can emit descriptions of where the canonical frame address was |
| 631 | // throughout the process. If we have a frame pointer, it takes over the job |
| 632 | // half-way through, so only the first few .cfi_def_cfa_offset instructions |
| 633 | // actually get emitted. |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 634 | DefCFAOffsetCandidates.emitDefCFAOffsets(MBB, dl, TII, HasFP); |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 635 | |
Evan Cheng | eb56dca | 2010-11-22 18:12:04 +0000 | [diff] [blame] | 636 | if (STI.isTargetELF() && hasFP(MF)) |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 637 | MFI.setOffsetAdjustment(MFI.getOffsetAdjustment() - |
| 638 | AFI->getFramePtrSpillOffset()); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 639 | |
| 640 | AFI->setGPRCalleeSavedArea1Size(GPRCS1Size); |
| 641 | AFI->setGPRCalleeSavedArea2Size(GPRCS2Size); |
Tim Northover | 228c943 | 2014-11-05 00:27:13 +0000 | [diff] [blame] | 642 | AFI->setDPRCalleeSavedGapSize(DPRGapSize); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 643 | AFI->setDPRCalleeSavedAreaSize(DPRCSSize); |
| 644 | |
| 645 | // If we need dynamic stack realignment, do it here. Be paranoid and make |
| 646 | // sure if we also have VLAs, we have a base pointer for frame access. |
Jakob Stoklund Olesen | 103318e | 2011-12-24 04:17:01 +0000 | [diff] [blame] | 647 | // If aligned NEON registers were spilled, the stack has already been |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 648 | // realigned. |
| 649 | if (!AFI->getNumAlignedDPRCS2Regs() && RegInfo->needsStackRealignment(MF)) { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 650 | unsigned MaxAlign = MFI.getMaxAlignment(); |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 651 | assert(!AFI->isThumb1OnlyFunction()); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 652 | if (!AFI->isThumbFunction()) { |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 653 | emitAligningInstructions(MF, AFI, TII, MBB, MBBI, dl, ARM::SP, MaxAlign, |
| 654 | false); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 655 | } else { |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 656 | // We cannot use sp as source/dest register here, thus we're using r4 to |
| 657 | // perform the calculations. We're emitting the following sequence: |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 658 | // mov r4, sp |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 659 | // -- use emitAligningInstructions to produce best sequence to zero |
| 660 | // -- out lower bits in r4 |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 661 | // mov sp, r4 |
| 662 | // FIXME: It will be better just to find spare register here. |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 663 | BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::R4) |
| 664 | .addReg(ARM::SP, RegState::Kill) |
| 665 | .add(predOps(ARMCC::AL)); |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 666 | emitAligningInstructions(MF, AFI, TII, MBB, MBBI, dl, ARM::R4, MaxAlign, |
| 667 | false); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 668 | BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::SP) |
| 669 | .addReg(ARM::R4, RegState::Kill) |
| 670 | .add(predOps(ARMCC::AL)); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | AFI->setShouldRestoreSPFromFP(true); |
| 674 | } |
| 675 | |
| 676 | // If we need a base pointer, set it up here. It's whatever the value |
| 677 | // of the stack pointer is at this point. Any variable size objects |
| 678 | // will be allocated after this, so we can still use the base pointer |
| 679 | // to reference locals. |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 680 | // FIXME: Clarify FrameSetup flags here. |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 681 | if (RegInfo->hasBasePointer(MF)) { |
| 682 | if (isARM) |
| 683 | BuildMI(MBB, MBBI, dl, |
| 684 | TII.get(ARM::MOVr), RegInfo->getBaseRegister()) |
| 685 | .addReg(ARM::SP) |
| 686 | .addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 687 | else |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 688 | BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), RegInfo->getBaseRegister()) |
| 689 | .addReg(ARM::SP) |
| 690 | .add(predOps(ARMCC::AL)); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | // If the frame has variable sized objects then the epilogue must restore |
Eric Christopher | d5bbeba | 2011-01-10 23:10:59 +0000 | [diff] [blame] | 694 | // the sp from fp. We can assume there's an FP here since hasFP already |
| 695 | // checks for hasVarSizedObjects. |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 696 | if (MFI.hasVarSizedObjects()) |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 697 | AFI->setShouldRestoreSPFromFP(true); |
| 698 | } |
| 699 | |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 700 | void ARMFrameLowering::emitEpilogue(MachineFunction &MF, |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 701 | MachineBasicBlock &MBB) const { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 702 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 703 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 704 | const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo(); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 705 | const ARMBaseInstrInfo &TII = |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 706 | *static_cast<const ARMBaseInstrInfo *>(MF.getSubtarget().getInstrInfo()); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 707 | assert(!AFI->isThumb1OnlyFunction() && |
| 708 | "This emitEpilogue does not support Thumb1!"); |
| 709 | bool isARM = !AFI->isThumbFunction(); |
| 710 | |
Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 711 | unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 712 | int NumBytes = (int)MFI.getStackSize(); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 713 | unsigned FramePtr = RegInfo->getFrameRegister(MF); |
| 714 | |
Jakob Stoklund Olesen | e380183 | 2012-10-26 21:46:57 +0000 | [diff] [blame] | 715 | // All calls are tail calls in GHC calling conv, and functions have no |
| 716 | // prologue/epilogue. |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 717 | if (MF.getFunction()->getCallingConv() == CallingConv::GHC) |
Eric Christopher | b332236 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 718 | return; |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 719 | |
| 720 | // First put ourselves on the first (from top) terminator instructions. |
| 721 | MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator(); |
| 722 | DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); |
Eric Christopher | b332236 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 723 | |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 724 | if (!AFI->hasStackFrame()) { |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 725 | if (NumBytes - ArgRegsSaveSize != 0) |
| 726 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, NumBytes - ArgRegsSaveSize); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 727 | } else { |
| 728 | // Unwind MBBI to point to first LDR / VLDRD. |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 729 | const MCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&MF); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 730 | if (MBBI != MBB.begin()) { |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 731 | do { |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 732 | --MBBI; |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 733 | } while (MBBI != MBB.begin() && isCSRestore(*MBBI, TII, CSRegs)); |
| 734 | if (!isCSRestore(*MBBI, TII, CSRegs)) |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 735 | ++MBBI; |
| 736 | } |
| 737 | |
| 738 | // Move SP to start of FP callee save spill area. |
Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 739 | NumBytes -= (ArgRegsSaveSize + |
| 740 | AFI->getGPRCalleeSavedArea1Size() + |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 741 | AFI->getGPRCalleeSavedArea2Size() + |
Tim Northover | 228c943 | 2014-11-05 00:27:13 +0000 | [diff] [blame] | 742 | AFI->getDPRCalleeSavedGapSize() + |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 743 | AFI->getDPRCalleeSavedAreaSize()); |
| 744 | |
| 745 | // Reset SP based on frame pointer only if the stack frame extends beyond |
| 746 | // frame pointer stack slot or target is ELF and the function has FP. |
| 747 | if (AFI->shouldRestoreSPFromFP()) { |
| 748 | NumBytes = AFI->getFramePtrSpillOffset() - NumBytes; |
| 749 | if (NumBytes) { |
| 750 | if (isARM) |
| 751 | emitARMRegPlusImmediate(MBB, MBBI, dl, ARM::SP, FramePtr, -NumBytes, |
| 752 | ARMCC::AL, 0, TII); |
Evan Cheng | eb56dca | 2010-11-22 18:12:04 +0000 | [diff] [blame] | 753 | else { |
| 754 | // It's not possible to restore SP from FP in a single instruction. |
Evan Cheng | 801d98b | 2012-01-04 01:55:04 +0000 | [diff] [blame] | 755 | // For iOS, this looks like: |
Evan Cheng | eb56dca | 2010-11-22 18:12:04 +0000 | [diff] [blame] | 756 | // mov sp, r7 |
| 757 | // sub sp, #24 |
| 758 | // This is bad, if an interrupt is taken after the mov, sp is in an |
| 759 | // inconsistent state. |
| 760 | // Use the first callee-saved register as a scratch register. |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 761 | assert(!MFI.getPristineRegs(MF).test(ARM::R4) && |
Evan Cheng | eb56dca | 2010-11-22 18:12:04 +0000 | [diff] [blame] | 762 | "No scratch register to restore SP from FP!"); |
| 763 | emitT2RegPlusImmediate(MBB, MBBI, dl, ARM::R4, FramePtr, -NumBytes, |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 764 | ARMCC::AL, 0, TII); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 765 | BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::SP) |
| 766 | .addReg(ARM::R4) |
| 767 | .add(predOps(ARMCC::AL)); |
Evan Cheng | eb56dca | 2010-11-22 18:12:04 +0000 | [diff] [blame] | 768 | } |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 769 | } else { |
| 770 | // Thumb2 or ARM. |
| 771 | if (isARM) |
| 772 | BuildMI(MBB, MBBI, dl, TII.get(ARM::MOVr), ARM::SP) |
| 773 | .addReg(FramePtr).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 774 | else |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 775 | BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::SP) |
| 776 | .addReg(FramePtr) |
| 777 | .add(predOps(ARMCC::AL)); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 778 | } |
Tim Northover | dee8604 | 2013-12-02 14:46:26 +0000 | [diff] [blame] | 779 | } else if (NumBytes && |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 780 | !tryFoldSPUpdateIntoPushPop(STI, MF, &*MBBI, NumBytes)) |
| 781 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, NumBytes); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 782 | |
Eric Christopher | b006fc9 | 2010-11-18 19:40:05 +0000 | [diff] [blame] | 783 | // Increment past our save areas. |
Duncan P. N. Exon Smith | 8f44c98 | 2016-08-21 00:08:10 +0000 | [diff] [blame] | 784 | if (MBBI != MBB.end() && AFI->getDPRCalleeSavedAreaSize()) { |
Evan Cheng | 70d2963 | 2011-02-25 00:24:46 +0000 | [diff] [blame] | 785 | MBBI++; |
| 786 | // Since vpop register list cannot have gaps, there may be multiple vpop |
| 787 | // instructions in the epilogue. |
Duncan P. N. Exon Smith | 8f44c98 | 2016-08-21 00:08:10 +0000 | [diff] [blame] | 788 | while (MBBI != MBB.end() && MBBI->getOpcode() == ARM::VLDMDIA_UPD) |
Evan Cheng | 70d2963 | 2011-02-25 00:24:46 +0000 | [diff] [blame] | 789 | MBBI++; |
| 790 | } |
Tim Northover | 228c943 | 2014-11-05 00:27:13 +0000 | [diff] [blame] | 791 | if (AFI->getDPRCalleeSavedGapSize()) { |
| 792 | assert(AFI->getDPRCalleeSavedGapSize() == 4 && |
| 793 | "unexpected DPR alignment gap"); |
| 794 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, AFI->getDPRCalleeSavedGapSize()); |
| 795 | } |
| 796 | |
Eric Christopher | b006fc9 | 2010-11-18 19:40:05 +0000 | [diff] [blame] | 797 | if (AFI->getGPRCalleeSavedArea2Size()) MBBI++; |
| 798 | if (AFI->getGPRCalleeSavedArea1Size()) MBBI++; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 801 | if (ArgRegsSaveSize) |
| 802 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, ArgRegsSaveSize); |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 803 | } |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 804 | |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 805 | /// getFrameIndexReference - Provide a base+offset reference to an FI slot for |
| 806 | /// debug info. It's the same as what we use for resolving the code-gen |
| 807 | /// references for now. FIXME: This can go wrong when references are |
| 808 | /// SP-relative and simple call frames aren't used. |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 809 | int |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 810 | ARMFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI, |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 811 | unsigned &FrameReg) const { |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 812 | return ResolveFrameIndexReference(MF, FI, FrameReg, 0); |
| 813 | } |
| 814 | |
| 815 | int |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 816 | ARMFrameLowering::ResolveFrameIndexReference(const MachineFunction &MF, |
Evan Cheng | c0d2004 | 2011-04-22 01:42:52 +0000 | [diff] [blame] | 817 | int FI, unsigned &FrameReg, |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 818 | int SPAdj) const { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 819 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 820 | const ARMBaseRegisterInfo *RegInfo = static_cast<const ARMBaseRegisterInfo *>( |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 821 | MF.getSubtarget().getRegisterInfo()); |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 822 | const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 823 | int Offset = MFI.getObjectOffset(FI) + MFI.getStackSize(); |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 824 | int FPOffset = Offset - AFI->getFramePtrSpillOffset(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 825 | bool isFixed = MFI.isFixedObjectIndex(FI); |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 826 | |
| 827 | FrameReg = ARM::SP; |
| 828 | Offset += SPAdj; |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 829 | |
Jakob Stoklund Olesen | 92c15b2 | 2012-02-28 01:15:01 +0000 | [diff] [blame] | 830 | // SP can move around if there are allocas. We may also lose track of SP |
| 831 | // when emergency spilling inside a non-reserved call frame setup. |
Bob Wilson | ca69032 | 2012-03-20 19:28:22 +0000 | [diff] [blame] | 832 | bool hasMovingSP = !hasReservedCallFrame(MF); |
Jakob Stoklund Olesen | 92c15b2 | 2012-02-28 01:15:01 +0000 | [diff] [blame] | 833 | |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 834 | // When dynamically realigning the stack, use the frame pointer for |
| 835 | // parameters, and the stack/base pointer for locals. |
| 836 | if (RegInfo->needsStackRealignment(MF)) { |
| 837 | assert (hasFP(MF) && "dynamic stack realignment without a FP!"); |
| 838 | if (isFixed) { |
| 839 | FrameReg = RegInfo->getFrameRegister(MF); |
| 840 | Offset = FPOffset; |
Jakob Stoklund Olesen | 92c15b2 | 2012-02-28 01:15:01 +0000 | [diff] [blame] | 841 | } else if (hasMovingSP) { |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 842 | assert(RegInfo->hasBasePointer(MF) && |
| 843 | "VLAs and dynamic stack alignment, but missing base pointer!"); |
| 844 | FrameReg = RegInfo->getBaseRegister(); |
| 845 | } |
| 846 | return Offset; |
| 847 | } |
| 848 | |
| 849 | // If there is a frame pointer, use it when we can. |
| 850 | if (hasFP(MF) && AFI->hasStackFrame()) { |
| 851 | // Use frame pointer to reference fixed objects. Use it for locals if |
| 852 | // there are VLAs (and thus the SP isn't reliable as a base). |
Jakob Stoklund Olesen | 92c15b2 | 2012-02-28 01:15:01 +0000 | [diff] [blame] | 853 | if (isFixed || (hasMovingSP && !RegInfo->hasBasePointer(MF))) { |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 854 | FrameReg = RegInfo->getFrameRegister(MF); |
| 855 | return FPOffset; |
Jakob Stoklund Olesen | 92c15b2 | 2012-02-28 01:15:01 +0000 | [diff] [blame] | 856 | } else if (hasMovingSP) { |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 857 | assert(RegInfo->hasBasePointer(MF) && "missing base pointer!"); |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 858 | if (AFI->isThumb2Function()) { |
Evan Cheng | c0d2004 | 2011-04-22 01:42:52 +0000 | [diff] [blame] | 859 | // Try to use the frame pointer if we can, else use the base pointer |
| 860 | // since it's available. This is handy for the emergency spill slot, in |
| 861 | // particular. |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 862 | if (FPOffset >= -255 && FPOffset < 0) { |
| 863 | FrameReg = RegInfo->getFrameRegister(MF); |
| 864 | return FPOffset; |
| 865 | } |
Evan Cheng | c0d2004 | 2011-04-22 01:42:52 +0000 | [diff] [blame] | 866 | } |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 867 | } else if (AFI->isThumb2Function()) { |
Andrew Trick | f7ecc16 | 2011-08-25 17:40:54 +0000 | [diff] [blame] | 868 | // Use add <rd>, sp, #<imm8> |
Evan Cheng | c0d2004 | 2011-04-22 01:42:52 +0000 | [diff] [blame] | 869 | // ldr <rd>, [sp, #<imm8>] |
| 870 | // if at all possible to save space. |
| 871 | if (Offset >= 0 && (Offset & 3) == 0 && Offset <= 1020) |
| 872 | return Offset; |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 873 | // In Thumb2 mode, the negative offset is very limited. Try to avoid |
Evan Cheng | c0d2004 | 2011-04-22 01:42:52 +0000 | [diff] [blame] | 874 | // out of range references. ldr <rt>,[<rn>, #-<imm8>] |
Anton Korobeynikov | 4687778 | 2010-11-20 15:59:32 +0000 | [diff] [blame] | 875 | if (FPOffset >= -255 && FPOffset < 0) { |
| 876 | FrameReg = RegInfo->getFrameRegister(MF); |
| 877 | return FPOffset; |
| 878 | } |
| 879 | } else if (Offset > (FPOffset < 0 ? -FPOffset : FPOffset)) { |
| 880 | // Otherwise, use SP or FP, whichever is closer to the stack slot. |
| 881 | FrameReg = RegInfo->getFrameRegister(MF); |
| 882 | return FPOffset; |
| 883 | } |
| 884 | } |
| 885 | // Use the base pointer if we have one. |
| 886 | if (RegInfo->hasBasePointer(MF)) |
| 887 | FrameReg = RegInfo->getBaseRegister(); |
| 888 | return Offset; |
| 889 | } |
| 890 | |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 891 | void ARMFrameLowering::emitPushInst(MachineBasicBlock &MBB, |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 892 | MachineBasicBlock::iterator MI, |
| 893 | const std::vector<CalleeSavedInfo> &CSI, |
| 894 | unsigned StmOpc, unsigned StrOpc, |
| 895 | bool NoGap, |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 896 | bool(*Func)(unsigned, bool), |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 897 | unsigned NumAlignedDPRCS2Regs, |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 898 | unsigned MIFlags) const { |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 899 | MachineFunction &MF = *MBB.getParent(); |
Tim Northover | 775aaeb | 2015-11-05 21:54:58 +0000 | [diff] [blame] | 900 | const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); |
Tim Northover | 46a6f0f | 2016-11-14 20:28:24 +0000 | [diff] [blame] | 901 | const TargetRegisterInfo &TRI = *STI.getRegisterInfo(); |
Tim Northover | 775aaeb | 2015-11-05 21:54:58 +0000 | [diff] [blame] | 902 | |
| 903 | DebugLoc DL; |
| 904 | |
Tim Northover | 46a6f0f | 2016-11-14 20:28:24 +0000 | [diff] [blame] | 905 | typedef std::pair<unsigned, bool> RegAndKill; |
| 906 | SmallVector<RegAndKill, 4> Regs; |
Tim Northover | 775aaeb | 2015-11-05 21:54:58 +0000 | [diff] [blame] | 907 | unsigned i = CSI.size(); |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 908 | while (i != 0) { |
| 909 | unsigned LastReg = 0; |
| 910 | for (; i != 0; --i) { |
| 911 | unsigned Reg = CSI[i-1].getReg(); |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 912 | if (!(Func)(Reg, STI.splitFramePushPop(MF))) continue; |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 913 | |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 914 | // D-registers in the aligned area DPRCS2 are NOT spilled here. |
| 915 | if (Reg >= ARM::D8 && Reg < ARM::D8 + NumAlignedDPRCS2Regs) |
| 916 | continue; |
| 917 | |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 918 | bool isLiveIn = MF.getRegInfo().isLiveIn(Reg); |
| 919 | if (!isLiveIn) |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 920 | MBB.addLiveIn(Reg); |
Eric Christopher | 2a2e65c | 2010-12-09 01:57:45 +0000 | [diff] [blame] | 921 | // If NoGap is true, push consecutive registers and then leave the rest |
Evan Cheng | 9d54ae6 | 2010-12-08 06:29:02 +0000 | [diff] [blame] | 922 | // for other instructions. e.g. |
Eric Christopher | 2a2e65c | 2010-12-09 01:57:45 +0000 | [diff] [blame] | 923 | // vpush {d8, d10, d11} -> vpush {d8}, vpush {d10, d11} |
Evan Cheng | 9d54ae6 | 2010-12-08 06:29:02 +0000 | [diff] [blame] | 924 | if (NoGap && LastReg && LastReg != Reg-1) |
| 925 | break; |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 926 | LastReg = Reg; |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 927 | // Do not set a kill flag on values that are also marked as live-in. This |
| 928 | // happens with the @llvm-returnaddress intrinsic and with arguments |
| 929 | // passed in callee saved registers. |
| 930 | // Omitting the kill flags is conservatively correct even if the live-in |
| 931 | // is not used after all. |
| 932 | Regs.push_back(std::make_pair(Reg, /*isKill=*/!isLiveIn)); |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 935 | if (Regs.empty()) |
| 936 | continue; |
Tim Northover | 46a6f0f | 2016-11-14 20:28:24 +0000 | [diff] [blame] | 937 | |
Tim Northover | 3d38c38 | 2016-11-14 20:31:53 +0000 | [diff] [blame] | 938 | std::sort(Regs.begin(), Regs.end(), [&](const RegAndKill &LHS, |
| 939 | const RegAndKill &RHS) { |
Tim Northover | 46a6f0f | 2016-11-14 20:28:24 +0000 | [diff] [blame] | 940 | return TRI.getEncodingValue(LHS.first) < TRI.getEncodingValue(RHS.first); |
| 941 | }); |
| 942 | |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 943 | if (Regs.size() > 1 || StrOpc== 0) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 944 | MachineInstrBuilder MIB = BuildMI(MBB, MI, DL, TII.get(StmOpc), ARM::SP) |
| 945 | .addReg(ARM::SP) |
| 946 | .setMIFlags(MIFlags) |
| 947 | .add(predOps(ARMCC::AL)); |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 948 | for (unsigned i = 0, e = Regs.size(); i < e; ++i) |
| 949 | MIB.addReg(Regs[i].first, getKillRegState(Regs[i].second)); |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 950 | } else if (Regs.size() == 1) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 951 | BuildMI(MBB, MI, DL, TII.get(StrOpc), ARM::SP) |
| 952 | .addReg(Regs[0].first, getKillRegState(Regs[0].second)) |
| 953 | .addReg(ARM::SP) |
| 954 | .setMIFlags(MIFlags) |
| 955 | .addImm(-4) |
| 956 | .add(predOps(ARMCC::AL)); |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 957 | } |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 958 | Regs.clear(); |
Tim Northover | 3cccc45 | 2014-03-12 11:29:23 +0000 | [diff] [blame] | 959 | |
| 960 | // Put any subsequent vpush instructions before this one: they will refer to |
| 961 | // higher register numbers so need to be pushed first in order to preserve |
| 962 | // monotonicity. |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 963 | if (MI != MBB.begin()) |
| 964 | --MI; |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 965 | } |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 966 | } |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 967 | |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 968 | void ARMFrameLowering::emitPopInst(MachineBasicBlock &MBB, |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 969 | MachineBasicBlock::iterator MI, |
| 970 | const std::vector<CalleeSavedInfo> &CSI, |
| 971 | unsigned LdmOpc, unsigned LdrOpc, |
| 972 | bool isVarArg, bool NoGap, |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 973 | bool(*Func)(unsigned, bool), |
| 974 | unsigned NumAlignedDPRCS2Regs) const { |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 975 | MachineFunction &MF = *MBB.getParent(); |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 976 | const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); |
Tim Northover | 46a6f0f | 2016-11-14 20:28:24 +0000 | [diff] [blame] | 977 | const TargetRegisterInfo &TRI = *STI.getRegisterInfo(); |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 978 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 979 | DebugLoc DL; |
| 980 | bool isTailCall = false; |
| 981 | bool isInterrupt = false; |
Oleg Ranevskyy | 6389dd9 | 2015-10-23 17:17:59 +0000 | [diff] [blame] | 982 | bool isTrap = false; |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 983 | if (MBB.end() != MI) { |
| 984 | DL = MI->getDebugLoc(); |
| 985 | unsigned RetOpcode = MI->getOpcode(); |
| 986 | isTailCall = (RetOpcode == ARM::TCRETURNdi || RetOpcode == ARM::TCRETURNri); |
| 987 | isInterrupt = |
| 988 | RetOpcode == ARM::SUBS_PC_LR || RetOpcode == ARM::t2SUBS_PC_LR; |
Oleg Ranevskyy | 6389dd9 | 2015-10-23 17:17:59 +0000 | [diff] [blame] | 989 | isTrap = |
| 990 | RetOpcode == ARM::TRAP || RetOpcode == ARM::TRAPNaCl || |
| 991 | RetOpcode == ARM::tTRAP; |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 992 | } |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 993 | |
| 994 | SmallVector<unsigned, 4> Regs; |
| 995 | unsigned i = CSI.size(); |
| 996 | while (i != 0) { |
| 997 | unsigned LastReg = 0; |
| 998 | bool DeleteRet = false; |
| 999 | for (; i != 0; --i) { |
| 1000 | unsigned Reg = CSI[i-1].getReg(); |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 1001 | if (!(Func)(Reg, STI.splitFramePushPop(MF))) continue; |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 1002 | |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1003 | // The aligned reloads from area DPRCS2 are not inserted here. |
| 1004 | if (Reg >= ARM::D8 && Reg < ARM::D8 + NumAlignedDPRCS2Regs) |
| 1005 | continue; |
| 1006 | |
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 1007 | if (Reg == ARM::LR && !isTailCall && !isVarArg && !isInterrupt && |
Oleg Ranevskyy | 6389dd9 | 2015-10-23 17:17:59 +0000 | [diff] [blame] | 1008 | !isTrap && STI.hasV5TOps()) { |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 1009 | if (MBB.succ_empty()) { |
| 1010 | Reg = ARM::PC; |
| 1011 | DeleteRet = true; |
| 1012 | LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET; |
| 1013 | } else |
| 1014 | LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_UPD : ARM::LDMIA_UPD; |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 1015 | // Fold the return instruction into the LDM. |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Evan Cheng | 9d54ae6 | 2010-12-08 06:29:02 +0000 | [diff] [blame] | 1018 | // If NoGap is true, pop consecutive registers and then leave the rest |
| 1019 | // for other instructions. e.g. |
| 1020 | // vpop {d8, d10, d11} -> vpop {d8}, vpop {d10, d11} |
| 1021 | if (NoGap && LastReg && LastReg != Reg-1) |
| 1022 | break; |
| 1023 | |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 1024 | LastReg = Reg; |
| 1025 | Regs.push_back(Reg); |
| 1026 | } |
| 1027 | |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 1028 | if (Regs.empty()) |
| 1029 | continue; |
Tim Northover | 46a6f0f | 2016-11-14 20:28:24 +0000 | [diff] [blame] | 1030 | |
| 1031 | std::sort(Regs.begin(), Regs.end(), [&](unsigned LHS, unsigned RHS) { |
| 1032 | return TRI.getEncodingValue(LHS) < TRI.getEncodingValue(RHS); |
| 1033 | }); |
| 1034 | |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 1035 | if (Regs.size() > 1 || LdrOpc == 0) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1036 | MachineInstrBuilder MIB = BuildMI(MBB, MI, DL, TII.get(LdmOpc), ARM::SP) |
| 1037 | .addReg(ARM::SP) |
| 1038 | .add(predOps(ARMCC::AL)); |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 1039 | for (unsigned i = 0, e = Regs.size(); i < e; ++i) |
| 1040 | MIB.addReg(Regs[i], getDefRegState(true)); |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 1041 | if (DeleteRet && MI != MBB.end()) { |
Duncan P. N. Exon Smith | fd8cc23 | 2016-02-27 20:01:33 +0000 | [diff] [blame] | 1042 | MIB.copyImplicitOps(*MI); |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 1043 | MI->eraseFromParent(); |
Andrew Trick | 6446bf7 | 2011-08-25 17:50:53 +0000 | [diff] [blame] | 1044 | } |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 1045 | MI = MIB; |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 1046 | } else if (Regs.size() == 1) { |
| 1047 | // If we adjusted the reg to PC from LR above, switch it back here. We |
| 1048 | // only do that for LDM. |
| 1049 | if (Regs[0] == ARM::PC) |
| 1050 | Regs[0] = ARM::LR; |
| 1051 | MachineInstrBuilder MIB = |
| 1052 | BuildMI(MBB, MI, DL, TII.get(LdrOpc), Regs[0]) |
| 1053 | .addReg(ARM::SP, RegState::Define) |
| 1054 | .addReg(ARM::SP); |
| 1055 | // ARM mode needs an extra reg0 here due to addrmode2. Will go away once |
| 1056 | // that refactoring is complete (eventually). |
Owen Anderson | 2aedba6 | 2011-07-26 20:54:26 +0000 | [diff] [blame] | 1057 | if (LdrOpc == ARM::LDR_POST_REG || LdrOpc == ARM::LDR_POST_IMM) { |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 1058 | MIB.addReg(0); |
| 1059 | MIB.addImm(ARM_AM::getAM2Opc(ARM_AM::add, 4, ARM_AM::no_shift)); |
| 1060 | } else |
| 1061 | MIB.addImm(4); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1062 | MIB.add(predOps(ARMCC::AL)); |
Evan Cheng | 775ead3 | 2010-12-07 23:08:38 +0000 | [diff] [blame] | 1063 | } |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 1064 | Regs.clear(); |
Tim Northover | 3cccc45 | 2014-03-12 11:29:23 +0000 | [diff] [blame] | 1065 | |
| 1066 | // Put any subsequent vpop instructions after this one: they will refer to |
| 1067 | // higher register numbers so need to be popped afterwards. |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 1068 | if (MI != MBB.end()) |
| 1069 | ++MI; |
Evan Cheng | c27c956 | 2010-12-07 19:59:34 +0000 | [diff] [blame] | 1070 | } |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1073 | /// Emit aligned spill instructions for NumAlignedDPRCS2Regs D-registers |
Jakob Stoklund Olesen | 103318e | 2011-12-24 04:17:01 +0000 | [diff] [blame] | 1074 | /// starting from d8. Also insert stack realignment code and leave the stack |
| 1075 | /// pointer pointing to the d8 spill slot. |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1076 | static void emitAlignedDPRCS2Spills(MachineBasicBlock &MBB, |
| 1077 | MachineBasicBlock::iterator MI, |
| 1078 | unsigned NumAlignedDPRCS2Regs, |
| 1079 | const std::vector<CalleeSavedInfo> &CSI, |
| 1080 | const TargetRegisterInfo *TRI) { |
| 1081 | MachineFunction &MF = *MBB.getParent(); |
| 1082 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Quentin Colombet | 5084e44 | 2015-10-15 00:41:26 +0000 | [diff] [blame] | 1083 | DebugLoc DL = MI != MBB.end() ? MI->getDebugLoc() : DebugLoc(); |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 1084 | const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1085 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1086 | |
| 1087 | // Mark the D-register spill slots as properly aligned. Since MFI computes |
| 1088 | // stack slot layout backwards, this can actually mean that the d-reg stack |
| 1089 | // slot offsets can be wrong. The offset for d8 will always be correct. |
| 1090 | for (unsigned i = 0, e = CSI.size(); i != e; ++i) { |
| 1091 | unsigned DNum = CSI[i].getReg() - ARM::D8; |
Tim Northover | e0ccdc6 | 2015-10-28 22:46:43 +0000 | [diff] [blame] | 1092 | if (DNum > NumAlignedDPRCS2Regs - 1) |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1093 | continue; |
| 1094 | int FI = CSI[i].getFrameIdx(); |
| 1095 | // The even-numbered registers will be 16-byte aligned, the odd-numbered |
| 1096 | // registers will be 8-byte aligned. |
| 1097 | MFI.setObjectAlignment(FI, DNum % 2 ? 8 : 16); |
| 1098 | |
| 1099 | // The stack slot for D8 needs to be maximally aligned because this is |
| 1100 | // actually the point where we align the stack pointer. MachineFrameInfo |
| 1101 | // computes all offsets relative to the incoming stack pointer which is a |
| 1102 | // bit weird when realigning the stack. Any extra padding for this |
| 1103 | // over-alignment is not realized because the code inserted below adjusts |
| 1104 | // the stack pointer by numregs * 8 before aligning the stack pointer. |
| 1105 | if (DNum == 0) |
| 1106 | MFI.setObjectAlignment(FI, MFI.getMaxAlignment()); |
| 1107 | } |
| 1108 | |
| 1109 | // Move the stack pointer to the d8 spill slot, and align it at the same |
| 1110 | // time. Leave the stack slot address in the scratch register r4. |
| 1111 | // |
| 1112 | // sub r4, sp, #numregs * 8 |
| 1113 | // bic r4, r4, #align - 1 |
| 1114 | // mov sp, r4 |
| 1115 | // |
| 1116 | bool isThumb = AFI->isThumbFunction(); |
| 1117 | assert(!AFI->isThumb1OnlyFunction() && "Can't realign stack for thumb1"); |
| 1118 | AFI->setShouldRestoreSPFromFP(true); |
| 1119 | |
| 1120 | // sub r4, sp, #numregs * 8 |
| 1121 | // The immediate is <= 64, so it doesn't need any special encoding. |
| 1122 | unsigned Opc = isThumb ? ARM::t2SUBri : ARM::SUBri; |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1123 | AddDefaultCC(BuildMI(MBB, MI, DL, TII.get(Opc), ARM::R4) |
| 1124 | .addReg(ARM::SP) |
| 1125 | .addImm(8 * NumAlignedDPRCS2Regs) |
| 1126 | .add(predOps(ARMCC::AL))); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1127 | |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1128 | unsigned MaxAlign = MF.getFrameInfo().getMaxAlignment(); |
Kristof Beyls | 933de7a | 2015-01-08 15:09:14 +0000 | [diff] [blame] | 1129 | // We must set parameter MustBeSingleInstruction to true, since |
| 1130 | // skipAlignedDPRCS2Spills expects exactly 3 instructions to perform |
| 1131 | // stack alignment. Luckily, this can always be done since all ARM |
| 1132 | // architecture versions that support Neon also support the BFC |
| 1133 | // instruction. |
| 1134 | emitAligningInstructions(MF, AFI, TII, MBB, MI, DL, ARM::R4, MaxAlign, true); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1135 | |
| 1136 | // mov sp, r4 |
| 1137 | // The stack pointer must be adjusted before spilling anything, otherwise |
| 1138 | // the stack slots could be clobbered by an interrupt handler. |
| 1139 | // Leave r4 live, it is used below. |
| 1140 | Opc = isThumb ? ARM::tMOVr : ARM::MOVr; |
| 1141 | MachineInstrBuilder MIB = BuildMI(MBB, MI, DL, TII.get(Opc), ARM::SP) |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1142 | .addReg(ARM::R4) |
| 1143 | .add(predOps(ARMCC::AL)); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1144 | if (!isThumb) |
| 1145 | AddDefaultCC(MIB); |
| 1146 | |
| 1147 | // Now spill NumAlignedDPRCS2Regs registers starting from d8. |
| 1148 | // r4 holds the stack slot address. |
| 1149 | unsigned NextReg = ARM::D8; |
| 1150 | |
| 1151 | // 16-byte aligned vst1.64 with 4 d-regs and address writeback. |
| 1152 | // The writeback is only needed when emitting two vst1.64 instructions. |
| 1153 | if (NumAlignedDPRCS2Regs >= 6) { |
| 1154 | unsigned SupReg = TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1155 | &ARM::QQPRRegClass); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1156 | MBB.addLiveIn(SupReg); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1157 | BuildMI(MBB, MI, DL, TII.get(ARM::VST1d64Qwb_fixed), ARM::R4) |
| 1158 | .addReg(ARM::R4, RegState::Kill) |
| 1159 | .addImm(16) |
| 1160 | .addReg(NextReg) |
| 1161 | .addReg(SupReg, RegState::ImplicitKill) |
| 1162 | .add(predOps(ARMCC::AL)); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1163 | NextReg += 4; |
| 1164 | NumAlignedDPRCS2Regs -= 4; |
| 1165 | } |
| 1166 | |
| 1167 | // We won't modify r4 beyond this point. It currently points to the next |
| 1168 | // register to be spilled. |
| 1169 | unsigned R4BaseReg = NextReg; |
| 1170 | |
| 1171 | // 16-byte aligned vst1.64 with 4 d-regs, no writeback. |
| 1172 | if (NumAlignedDPRCS2Regs >= 4) { |
| 1173 | unsigned SupReg = TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1174 | &ARM::QQPRRegClass); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1175 | MBB.addLiveIn(SupReg); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1176 | BuildMI(MBB, MI, DL, TII.get(ARM::VST1d64Q)) |
| 1177 | .addReg(ARM::R4) |
| 1178 | .addImm(16) |
| 1179 | .addReg(NextReg) |
| 1180 | .addReg(SupReg, RegState::ImplicitKill) |
| 1181 | .add(predOps(ARMCC::AL)); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1182 | NextReg += 4; |
| 1183 | NumAlignedDPRCS2Regs -= 4; |
| 1184 | } |
| 1185 | |
| 1186 | // 16-byte aligned vst1.64 with 2 d-regs. |
| 1187 | if (NumAlignedDPRCS2Regs >= 2) { |
| 1188 | unsigned SupReg = TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1189 | &ARM::QPRRegClass); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1190 | MBB.addLiveIn(SupReg); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1191 | BuildMI(MBB, MI, DL, TII.get(ARM::VST1q64)) |
| 1192 | .addReg(ARM::R4) |
| 1193 | .addImm(16) |
| 1194 | .addReg(SupReg) |
| 1195 | .add(predOps(ARMCC::AL)); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1196 | NextReg += 2; |
| 1197 | NumAlignedDPRCS2Regs -= 2; |
| 1198 | } |
| 1199 | |
| 1200 | // Finally, use a vanilla vstr.64 for the odd last register. |
| 1201 | if (NumAlignedDPRCS2Regs) { |
| 1202 | MBB.addLiveIn(NextReg); |
| 1203 | // vstr.64 uses addrmode5 which has an offset scale of 4. |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1204 | BuildMI(MBB, MI, DL, TII.get(ARM::VSTRD)) |
| 1205 | .addReg(NextReg) |
| 1206 | .addReg(ARM::R4) |
| 1207 | .addImm((NextReg - R4BaseReg) * 2) |
| 1208 | .add(predOps(ARMCC::AL)); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | // The last spill instruction inserted should kill the scratch register r4. |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 1212 | std::prev(MI)->addRegisterKilled(ARM::R4, TRI); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | /// Skip past the code inserted by emitAlignedDPRCS2Spills, and return an |
| 1216 | /// iterator to the following instruction. |
| 1217 | static MachineBasicBlock::iterator |
| 1218 | skipAlignedDPRCS2Spills(MachineBasicBlock::iterator MI, |
| 1219 | unsigned NumAlignedDPRCS2Regs) { |
| 1220 | // sub r4, sp, #numregs * 8 |
| 1221 | // bic r4, r4, #align - 1 |
| 1222 | // mov sp, r4 |
| 1223 | ++MI; ++MI; ++MI; |
| 1224 | assert(MI->mayStore() && "Expecting spill instruction"); |
| 1225 | |
| 1226 | // These switches all fall through. |
| 1227 | switch(NumAlignedDPRCS2Regs) { |
| 1228 | case 7: |
| 1229 | ++MI; |
| 1230 | assert(MI->mayStore() && "Expecting spill instruction"); |
| 1231 | default: |
| 1232 | ++MI; |
| 1233 | assert(MI->mayStore() && "Expecting spill instruction"); |
| 1234 | case 1: |
| 1235 | case 2: |
| 1236 | case 4: |
| 1237 | assert(MI->killsRegister(ARM::R4) && "Missed kill flag"); |
| 1238 | ++MI; |
| 1239 | } |
| 1240 | return MI; |
| 1241 | } |
| 1242 | |
| 1243 | /// Emit aligned reload instructions for NumAlignedDPRCS2Regs D-registers |
| 1244 | /// starting from d8. These instructions are assumed to execute while the |
| 1245 | /// stack is still aligned, unlike the code inserted by emitPopInst. |
| 1246 | static void emitAlignedDPRCS2Restores(MachineBasicBlock &MBB, |
| 1247 | MachineBasicBlock::iterator MI, |
| 1248 | unsigned NumAlignedDPRCS2Regs, |
| 1249 | const std::vector<CalleeSavedInfo> &CSI, |
| 1250 | const TargetRegisterInfo *TRI) { |
| 1251 | MachineFunction &MF = *MBB.getParent(); |
| 1252 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Quentin Colombet | 5084e44 | 2015-10-15 00:41:26 +0000 | [diff] [blame] | 1253 | DebugLoc DL = MI != MBB.end() ? MI->getDebugLoc() : DebugLoc(); |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 1254 | const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1255 | |
| 1256 | // Find the frame index assigned to d8. |
| 1257 | int D8SpillFI = 0; |
| 1258 | for (unsigned i = 0, e = CSI.size(); i != e; ++i) |
| 1259 | if (CSI[i].getReg() == ARM::D8) { |
| 1260 | D8SpillFI = CSI[i].getFrameIdx(); |
| 1261 | break; |
| 1262 | } |
| 1263 | |
| 1264 | // Materialize the address of the d8 spill slot into the scratch register r4. |
| 1265 | // This can be fairly complicated if the stack frame is large, so just use |
| 1266 | // the normal frame index elimination mechanism to do it. This code runs as |
| 1267 | // the initial part of the epilog where the stack and base pointers haven't |
| 1268 | // been changed yet. |
| 1269 | bool isThumb = AFI->isThumbFunction(); |
| 1270 | assert(!AFI->isThumb1OnlyFunction() && "Can't realign stack for thumb1"); |
| 1271 | |
| 1272 | unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri; |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1273 | AddDefaultCC(BuildMI(MBB, MI, DL, TII.get(Opc), ARM::R4) |
| 1274 | .addFrameIndex(D8SpillFI) |
| 1275 | .addImm(0) |
| 1276 | .add(predOps(ARMCC::AL))); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1277 | |
| 1278 | // Now restore NumAlignedDPRCS2Regs registers starting from d8. |
| 1279 | unsigned NextReg = ARM::D8; |
| 1280 | |
| 1281 | // 16-byte aligned vld1.64 with 4 d-regs and writeback. |
| 1282 | if (NumAlignedDPRCS2Regs >= 6) { |
| 1283 | unsigned SupReg = TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1284 | &ARM::QQPRRegClass); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1285 | BuildMI(MBB, MI, DL, TII.get(ARM::VLD1d64Qwb_fixed), NextReg) |
| 1286 | .addReg(ARM::R4, RegState::Define) |
| 1287 | .addReg(ARM::R4, RegState::Kill) |
| 1288 | .addImm(16) |
| 1289 | .addReg(SupReg, RegState::ImplicitDefine) |
| 1290 | .add(predOps(ARMCC::AL)); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1291 | NextReg += 4; |
| 1292 | NumAlignedDPRCS2Regs -= 4; |
| 1293 | } |
| 1294 | |
| 1295 | // We won't modify r4 beyond this point. It currently points to the next |
| 1296 | // register to be spilled. |
| 1297 | unsigned R4BaseReg = NextReg; |
| 1298 | |
| 1299 | // 16-byte aligned vld1.64 with 4 d-regs, no writeback. |
| 1300 | if (NumAlignedDPRCS2Regs >= 4) { |
| 1301 | unsigned SupReg = TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1302 | &ARM::QQPRRegClass); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1303 | BuildMI(MBB, MI, DL, TII.get(ARM::VLD1d64Q), NextReg) |
| 1304 | .addReg(ARM::R4) |
| 1305 | .addImm(16) |
| 1306 | .addReg(SupReg, RegState::ImplicitDefine) |
| 1307 | .add(predOps(ARMCC::AL)); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1308 | NextReg += 4; |
| 1309 | NumAlignedDPRCS2Regs -= 4; |
| 1310 | } |
| 1311 | |
| 1312 | // 16-byte aligned vld1.64 with 2 d-regs. |
| 1313 | if (NumAlignedDPRCS2Regs >= 2) { |
| 1314 | unsigned SupReg = TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1315 | &ARM::QPRRegClass); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1316 | BuildMI(MBB, MI, DL, TII.get(ARM::VLD1q64), SupReg) |
| 1317 | .addReg(ARM::R4) |
| 1318 | .addImm(16) |
| 1319 | .add(predOps(ARMCC::AL)); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1320 | NextReg += 2; |
| 1321 | NumAlignedDPRCS2Regs -= 2; |
| 1322 | } |
| 1323 | |
| 1324 | // Finally, use a vanilla vldr.64 for the remaining odd register. |
| 1325 | if (NumAlignedDPRCS2Regs) |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 1326 | BuildMI(MBB, MI, DL, TII.get(ARM::VLDRD), NextReg) |
| 1327 | .addReg(ARM::R4) |
| 1328 | .addImm(2 * (NextReg - R4BaseReg)) |
| 1329 | .add(predOps(ARMCC::AL)); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1330 | |
| 1331 | // Last store kills r4. |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 1332 | std::prev(MI)->addRegisterKilled(ARM::R4, TRI); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 1335 | bool ARMFrameLowering::spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 1336 | MachineBasicBlock::iterator MI, |
| 1337 | const std::vector<CalleeSavedInfo> &CSI, |
| 1338 | const TargetRegisterInfo *TRI) const { |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 1339 | if (CSI.empty()) |
| 1340 | return false; |
| 1341 | |
| 1342 | MachineFunction &MF = *MBB.getParent(); |
| 1343 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 1344 | |
| 1345 | unsigned PushOpc = AFI->isThumbFunction() ? ARM::t2STMDB_UPD : ARM::STMDB_UPD; |
Jim Grosbach | 05dec8b1 | 2011-09-02 18:46:15 +0000 | [diff] [blame] | 1346 | unsigned PushOneOpc = AFI->isThumbFunction() ? |
| 1347 | ARM::t2STR_PRE : ARM::STR_PRE_IMM; |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 1348 | unsigned FltOpc = ARM::VSTMDDB_UPD; |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1349 | unsigned NumAlignedDPRCS2Regs = AFI->getNumAlignedDPRCS2Regs(); |
| 1350 | emitPushInst(MBB, MI, CSI, PushOpc, PushOneOpc, false, &isARMArea1Register, 0, |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1351 | MachineInstr::FrameSetup); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1352 | emitPushInst(MBB, MI, CSI, PushOpc, PushOneOpc, false, &isARMArea2Register, 0, |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 1353 | MachineInstr::FrameSetup); |
| 1354 | emitPushInst(MBB, MI, CSI, FltOpc, 0, true, &isARMArea3Register, |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1355 | NumAlignedDPRCS2Regs, MachineInstr::FrameSetup); |
| 1356 | |
| 1357 | // The code above does not insert spill code for the aligned DPRCS2 registers. |
| 1358 | // The stack realignment code will be inserted between the push instructions |
| 1359 | // and these spills. |
| 1360 | if (NumAlignedDPRCS2Regs) |
| 1361 | emitAlignedDPRCS2Spills(MBB, MI, NumAlignedDPRCS2Regs, CSI, TRI); |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 1362 | |
| 1363 | return true; |
| 1364 | } |
| 1365 | |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 1366 | bool ARMFrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB, |
Bob Wilson | 657f227 | 2011-01-13 21:10:12 +0000 | [diff] [blame] | 1367 | MachineBasicBlock::iterator MI, |
| 1368 | const std::vector<CalleeSavedInfo> &CSI, |
| 1369 | const TargetRegisterInfo *TRI) const { |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 1370 | if (CSI.empty()) |
| 1371 | return false; |
| 1372 | |
| 1373 | MachineFunction &MF = *MBB.getParent(); |
| 1374 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 1375 | bool isVarArg = AFI->getArgRegsSaveSize() > 0; |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1376 | unsigned NumAlignedDPRCS2Regs = AFI->getNumAlignedDPRCS2Regs(); |
| 1377 | |
| 1378 | // The emitPopInst calls below do not insert reloads for the aligned DPRCS2 |
| 1379 | // registers. Do that here instead. |
| 1380 | if (NumAlignedDPRCS2Regs) |
| 1381 | emitAlignedDPRCS2Restores(MBB, MI, NumAlignedDPRCS2Regs, CSI, TRI); |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 1382 | |
| 1383 | unsigned PopOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_UPD : ARM::LDMIA_UPD; |
Jim Grosbach | 05dec8b1 | 2011-09-02 18:46:15 +0000 | [diff] [blame] | 1384 | unsigned LdrOpc = AFI->isThumbFunction() ? ARM::t2LDR_POST :ARM::LDR_POST_IMM; |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 1385 | unsigned FltOpc = ARM::VLDMDIA_UPD; |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1386 | emitPopInst(MBB, MI, CSI, FltOpc, 0, isVarArg, true, &isARMArea3Register, |
| 1387 | NumAlignedDPRCS2Regs); |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 1388 | emitPopInst(MBB, MI, CSI, PopOpc, LdrOpc, isVarArg, false, |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1389 | &isARMArea2Register, 0); |
Jim Grosbach | 5fccad8 | 2010-12-09 18:31:13 +0000 | [diff] [blame] | 1390 | emitPopInst(MBB, MI, CSI, PopOpc, LdrOpc, isVarArg, false, |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1391 | &isARMArea1Register, 0); |
Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 1392 | |
| 1393 | return true; |
| 1394 | } |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1395 | |
| 1396 | // FIXME: Make generic? |
| 1397 | static unsigned GetFunctionSizeInBytes(const MachineFunction &MF, |
| 1398 | const ARMBaseInstrInfo &TII) { |
| 1399 | unsigned FnSize = 0; |
Jim Grosbach | f92e8f5 | 2014-04-04 02:10:55 +0000 | [diff] [blame] | 1400 | for (auto &MBB : MF) { |
| 1401 | for (auto &MI : MBB) |
Sjoerd Meijer | 89217f8 | 2016-07-28 16:32:22 +0000 | [diff] [blame] | 1402 | FnSize += TII.getInstSizeInBytes(MI); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1403 | } |
| 1404 | return FnSize; |
| 1405 | } |
| 1406 | |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1407 | /// estimateRSStackSizeLimit - Look at each instruction that references stack |
| 1408 | /// frames and return the stack size limit beyond which some of these |
| 1409 | /// instructions will require a scratch register during their expansion later. |
| 1410 | // FIXME: Move to TII? |
| 1411 | static unsigned estimateRSStackSizeLimit(MachineFunction &MF, |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 1412 | const TargetFrameLowering *TFI) { |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1413 | const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1414 | unsigned Limit = (1 << 12) - 1; |
Jim Grosbach | f92e8f5 | 2014-04-04 02:10:55 +0000 | [diff] [blame] | 1415 | for (auto &MBB : MF) { |
| 1416 | for (auto &MI : MBB) { |
| 1417 | for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { |
| 1418 | if (!MI.getOperand(i).isFI()) |
| 1419 | continue; |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1420 | |
| 1421 | // When using ADDri to get the address of a stack object, 255 is the |
| 1422 | // largest offset guaranteed to fit in the immediate offset. |
Jim Grosbach | f92e8f5 | 2014-04-04 02:10:55 +0000 | [diff] [blame] | 1423 | if (MI.getOpcode() == ARM::ADDri) { |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1424 | Limit = std::min(Limit, (1U << 8) - 1); |
| 1425 | break; |
| 1426 | } |
| 1427 | |
| 1428 | // Otherwise check the addressing mode. |
Jim Grosbach | f92e8f5 | 2014-04-04 02:10:55 +0000 | [diff] [blame] | 1429 | switch (MI.getDesc().TSFlags & ARMII::AddrModeMask) { |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1430 | case ARMII::AddrMode3: |
| 1431 | case ARMII::AddrModeT2_i8: |
| 1432 | Limit = std::min(Limit, (1U << 8) - 1); |
| 1433 | break; |
| 1434 | case ARMII::AddrMode5: |
| 1435 | case ARMII::AddrModeT2_i8s4: |
| 1436 | Limit = std::min(Limit, ((1U << 8) - 1) * 4); |
| 1437 | break; |
| 1438 | case ARMII::AddrModeT2_i12: |
| 1439 | // i12 supports only positive offset so these will be converted to |
| 1440 | // i8 opcodes. See llvm::rewriteT2FrameIndex. |
| 1441 | if (TFI->hasFP(MF) && AFI->hasStackFrame()) |
| 1442 | Limit = std::min(Limit, (1U << 8) - 1); |
| 1443 | break; |
| 1444 | case ARMII::AddrMode4: |
| 1445 | case ARMII::AddrMode6: |
| 1446 | // Addressing modes 4 & 6 (load/store) instructions can't encode an |
| 1447 | // immediate offset for stack references. |
| 1448 | return 0; |
| 1449 | default: |
| 1450 | break; |
| 1451 | } |
| 1452 | break; // At most one FI per instruction |
| 1453 | } |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | return Limit; |
| 1458 | } |
| 1459 | |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1460 | // In functions that realign the stack, it can be an advantage to spill the |
| 1461 | // callee-saved vector registers after realigning the stack. The vst1 and vld1 |
| 1462 | // instructions take alignment hints that can improve performance. |
| 1463 | // |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1464 | static void |
| 1465 | checkNumAlignedDPRCS2Regs(MachineFunction &MF, BitVector &SavedRegs) { |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1466 | MF.getInfo<ARMFunctionInfo>()->setNumAlignedDPRCS2Regs(0); |
| 1467 | if (!SpillAlignedNEONRegs) |
| 1468 | return; |
| 1469 | |
| 1470 | // Naked functions don't spill callee-saved registers. |
Duncan P. N. Exon Smith | 2cff9e1 | 2015-02-14 02:24:44 +0000 | [diff] [blame] | 1471 | if (MF.getFunction()->hasFnAttribute(Attribute::Naked)) |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1472 | return; |
| 1473 | |
| 1474 | // We are planning to use NEON instructions vst1 / vld1. |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 1475 | if (!static_cast<const ARMSubtarget &>(MF.getSubtarget()).hasNEON()) |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1476 | return; |
| 1477 | |
| 1478 | // Don't bother if the default stack alignment is sufficiently high. |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 1479 | if (MF.getSubtarget().getFrameLowering()->getStackAlignment() >= 8) |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1480 | return; |
| 1481 | |
| 1482 | // Aligned spills require stack realignment. |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 1483 | if (!static_cast<const ARMBaseRegisterInfo *>( |
| 1484 | MF.getSubtarget().getRegisterInfo())->canRealignStack(MF)) |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1485 | return; |
| 1486 | |
| 1487 | // We always spill contiguous d-registers starting from d8. Count how many |
| 1488 | // needs spilling. The register allocator will almost always use the |
| 1489 | // callee-saved registers in order, but it can happen that there are holes in |
| 1490 | // the range. Registers above the hole will be spilled to the standard DPRCS |
| 1491 | // area. |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1492 | unsigned NumSpills = 0; |
| 1493 | for (; NumSpills < 8; ++NumSpills) |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1494 | if (!SavedRegs.test(ARM::D8 + NumSpills)) |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1495 | break; |
| 1496 | |
| 1497 | // Don't do this for just one d-register. It's not worth it. |
| 1498 | if (NumSpills < 2) |
| 1499 | return; |
| 1500 | |
| 1501 | // Spill the first NumSpills D-registers after realigning the stack. |
| 1502 | MF.getInfo<ARMFunctionInfo>()->setNumAlignedDPRCS2Regs(NumSpills); |
| 1503 | |
| 1504 | // A scratch register is required for the vst1 / vld1 instructions. |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1505 | SavedRegs.set(ARM::R4); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1508 | void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF, |
| 1509 | BitVector &SavedRegs, |
| 1510 | RegScavenger *RS) const { |
| 1511 | TargetFrameLowering::determineCalleeSaves(MF, SavedRegs, RS); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1512 | // This tells PEI to spill the FP as if it is any other callee-save register |
| 1513 | // to take advantage the eliminateFrameIndex machinery. This also ensures it |
| 1514 | // is spilled in the order specified by getCalleeSavedRegs() to make it easier |
| 1515 | // to combine multiple loads / stores. |
| 1516 | bool CanEliminateFrame = true; |
| 1517 | bool CS1Spilled = false; |
| 1518 | bool LRSpilled = false; |
| 1519 | unsigned NumGPRSpills = 0; |
Weiming Zhao | 5b5501e | 2016-05-08 05:11:54 +0000 | [diff] [blame] | 1520 | unsigned NumFPRSpills = 0; |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1521 | SmallVector<unsigned, 4> UnspilledCS1GPRs; |
| 1522 | SmallVector<unsigned, 4> UnspilledCS2GPRs; |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 1523 | const ARMBaseRegisterInfo *RegInfo = static_cast<const ARMBaseRegisterInfo *>( |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 1524 | MF.getSubtarget().getRegisterInfo()); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1525 | const ARMBaseInstrInfo &TII = |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 1526 | *static_cast<const ARMBaseInstrInfo *>(MF.getSubtarget().getInstrInfo()); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1527 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1528 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Jakob Stoklund Olesen | 410eae5 | 2012-10-26 21:43:05 +0000 | [diff] [blame] | 1529 | MachineRegisterInfo &MRI = MF.getRegInfo(); |
Reid Kleckner | bdfc05f | 2016-10-11 21:14:03 +0000 | [diff] [blame] | 1530 | const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); |
| 1531 | (void)TRI; // Silence unused warning in non-assert builds. |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1532 | unsigned FramePtr = RegInfo->getFrameRegister(MF); |
| 1533 | |
| 1534 | // Spill R4 if Thumb2 function requires stack realignment - it will be used as |
| 1535 | // scratch register. Also spill R4 if Thumb2 function has varsized objects, |
Evan Cheng | 572756a | 2011-01-16 05:14:33 +0000 | [diff] [blame] | 1536 | // since it's not always possible to restore sp from fp in a single |
| 1537 | // instruction. |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1538 | // FIXME: It will be better just to find spare register here. |
| 1539 | if (AFI->isThumb2Function() && |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1540 | (MFI.hasVarSizedObjects() || RegInfo->needsStackRealignment(MF))) |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1541 | SavedRegs.set(ARM::R4); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1542 | |
Evan Cheng | 572756a | 2011-01-16 05:14:33 +0000 | [diff] [blame] | 1543 | if (AFI->isThumb1OnlyFunction()) { |
| 1544 | // Spill LR if Thumb1 function uses variable length argument lists. |
Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 1545 | if (AFI->getArgRegsSaveSize() > 0) |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1546 | SavedRegs.set(ARM::LR); |
Evan Cheng | 572756a | 2011-01-16 05:14:33 +0000 | [diff] [blame] | 1547 | |
Jim Grosbach | dca8531 | 2011-06-13 21:18:25 +0000 | [diff] [blame] | 1548 | // Spill R4 if Thumb1 epilogue has to restore SP from FP. We don't know |
| 1549 | // for sure what the stack size will be, but for this, an estimate is good |
| 1550 | // enough. If there anything changes it, it'll be a spill, which implies |
| 1551 | // we've used all the registers and so R4 is already used, so not marking |
Chad Rosier | add38c1 | 2011-10-20 00:07:12 +0000 | [diff] [blame] | 1552 | // it here will be OK. |
Evan Cheng | 572756a | 2011-01-16 05:14:33 +0000 | [diff] [blame] | 1553 | // FIXME: It will be better just to find spare register here. |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1554 | unsigned StackSize = MFI.estimateStackSize(MF); |
| 1555 | if (MFI.hasVarSizedObjects() || StackSize > 508) |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1556 | SavedRegs.set(ARM::R4); |
Evan Cheng | 572756a | 2011-01-16 05:14:33 +0000 | [diff] [blame] | 1557 | } |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1558 | |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1559 | // See if we can spill vector registers to aligned stack. |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1560 | checkNumAlignedDPRCS2Regs(MF, SavedRegs); |
Jakob Stoklund Olesen | 0965585 | 2011-12-23 00:36:18 +0000 | [diff] [blame] | 1561 | |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1562 | // Spill the BasePtr if it's used. |
| 1563 | if (RegInfo->hasBasePointer(MF)) |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1564 | SavedRegs.set(RegInfo->getBaseRegister()); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1565 | |
| 1566 | // Don't spill FP if the frame can be eliminated. This is determined |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1567 | // by scanning the callee-save registers to see if any is modified. |
Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 1568 | const MCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&MF); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1569 | for (unsigned i = 0; CSRegs[i]; ++i) { |
| 1570 | unsigned Reg = CSRegs[i]; |
| 1571 | bool Spilled = false; |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1572 | if (SavedRegs.test(Reg)) { |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1573 | Spilled = true; |
| 1574 | CanEliminateFrame = false; |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
Weiming Zhao | 5b5501e | 2016-05-08 05:11:54 +0000 | [diff] [blame] | 1577 | if (!ARM::GPRRegClass.contains(Reg)) { |
| 1578 | if (Spilled) { |
| 1579 | if (ARM::SPRRegClass.contains(Reg)) |
| 1580 | NumFPRSpills++; |
| 1581 | else if (ARM::DPRRegClass.contains(Reg)) |
| 1582 | NumFPRSpills += 2; |
| 1583 | else if (ARM::QPRRegClass.contains(Reg)) |
| 1584 | NumFPRSpills += 4; |
| 1585 | } |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1586 | continue; |
Weiming Zhao | 5b5501e | 2016-05-08 05:11:54 +0000 | [diff] [blame] | 1587 | } |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1588 | |
| 1589 | if (Spilled) { |
| 1590 | NumGPRSpills++; |
| 1591 | |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 1592 | if (!STI.splitFramePushPop(MF)) { |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1593 | if (Reg == ARM::LR) |
| 1594 | LRSpilled = true; |
| 1595 | CS1Spilled = true; |
| 1596 | continue; |
| 1597 | } |
| 1598 | |
| 1599 | // Keep track if LR and any of R4, R5, R6, and R7 is spilled. |
| 1600 | switch (Reg) { |
| 1601 | case ARM::LR: |
| 1602 | LRSpilled = true; |
Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 1603 | LLVM_FALLTHROUGH; |
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 1604 | case ARM::R0: case ARM::R1: |
| 1605 | case ARM::R2: case ARM::R3: |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1606 | case ARM::R4: case ARM::R5: |
| 1607 | case ARM::R6: case ARM::R7: |
| 1608 | CS1Spilled = true; |
| 1609 | break; |
| 1610 | default: |
| 1611 | break; |
| 1612 | } |
| 1613 | } else { |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 1614 | if (!STI.splitFramePushPop(MF)) { |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1615 | UnspilledCS1GPRs.push_back(Reg); |
| 1616 | continue; |
| 1617 | } |
| 1618 | |
| 1619 | switch (Reg) { |
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 1620 | case ARM::R0: case ARM::R1: |
| 1621 | case ARM::R2: case ARM::R3: |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1622 | case ARM::R4: case ARM::R5: |
| 1623 | case ARM::R6: case ARM::R7: |
| 1624 | case ARM::LR: |
| 1625 | UnspilledCS1GPRs.push_back(Reg); |
| 1626 | break; |
| 1627 | default: |
| 1628 | UnspilledCS2GPRs.push_back(Reg); |
| 1629 | break; |
| 1630 | } |
| 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | bool ForceLRSpill = false; |
| 1635 | if (!LRSpilled && AFI->isThumb1OnlyFunction()) { |
| 1636 | unsigned FnSize = GetFunctionSizeInBytes(MF, TII); |
| 1637 | // Force LR to be spilled if the Thumb function size is > 2048. This enables |
| 1638 | // use of BL to implement far jump. If it turns out that it's not needed |
| 1639 | // then the branch fix up path will undo it. |
| 1640 | if (FnSize >= (1 << 11)) { |
| 1641 | CanEliminateFrame = false; |
| 1642 | ForceLRSpill = true; |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | // If any of the stack slot references may be out of range of an immediate |
| 1647 | // offset, make sure a register (or a spill slot) is available for the |
| 1648 | // register scavenger. Note that if we're indexing off the frame pointer, the |
| 1649 | // effective stack size is 4 bytes larger since the FP points to the stack |
| 1650 | // slot of the previous FP. Also, if we have variable sized objects in the |
| 1651 | // function, stack slot references will often be negative, and some of |
| 1652 | // our instructions are positive-offset only, so conservatively consider |
| 1653 | // that case to want a spill slot (or register) as well. Similarly, if |
| 1654 | // the function adjusts the stack pointer during execution and the |
| 1655 | // adjustments aren't already part of our stack size estimate, our offset |
| 1656 | // calculations may be off, so be conservative. |
| 1657 | // FIXME: We could add logic to be more precise about negative offsets |
| 1658 | // and which instructions will need a scratch register for them. Is it |
| 1659 | // worth the effort and added fragility? |
Weiming Zhao | 5b5501e | 2016-05-08 05:11:54 +0000 | [diff] [blame] | 1660 | unsigned EstimatedStackSize = |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1661 | MFI.estimateStackSize(MF) + 4 * (NumGPRSpills + NumFPRSpills); |
Weiming Zhao | 5b5501e | 2016-05-08 05:11:54 +0000 | [diff] [blame] | 1662 | if (hasFP(MF)) { |
| 1663 | if (AFI->hasStackFrame()) |
| 1664 | EstimatedStackSize += 4; |
| 1665 | } else { |
| 1666 | // If FP is not used, SP will be used to access arguments, so count the |
| 1667 | // size of arguments into the estimation. |
| 1668 | EstimatedStackSize += MF.getInfo<ARMFunctionInfo>()->getArgumentStackSize(); |
| 1669 | } |
| 1670 | EstimatedStackSize += 16; // For possible paddings. |
| 1671 | |
| 1672 | bool BigStack = EstimatedStackSize >= estimateRSStackSizeLimit(MF, this) || |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1673 | MFI.hasVarSizedObjects() || |
| 1674 | (MFI.adjustsStack() && !canSimplifyCallFramePseudos(MF)); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1675 | bool ExtraCSSpill = false; |
| 1676 | if (BigStack || !CanEliminateFrame || RegInfo->cannotEliminateFrame(MF)) { |
| 1677 | AFI->setHasStackFrame(true); |
| 1678 | |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 1679 | if (hasFP(MF)) { |
| 1680 | SavedRegs.set(FramePtr); |
| 1681 | // If the frame pointer is required by the ABI, also spill LR so that we |
| 1682 | // emit a complete frame record. |
| 1683 | if (MF.getTarget().Options.DisableFramePointerElim(MF) && !LRSpilled) { |
| 1684 | SavedRegs.set(ARM::LR); |
| 1685 | LRSpilled = true; |
| 1686 | NumGPRSpills++; |
Reid Kleckner | bdfc05f | 2016-10-11 21:14:03 +0000 | [diff] [blame] | 1687 | auto LRPos = find(UnspilledCS1GPRs, ARM::LR); |
| 1688 | if (LRPos != UnspilledCS1GPRs.end()) |
| 1689 | UnspilledCS1GPRs.erase(LRPos); |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 1690 | } |
| 1691 | auto FPPos = find(UnspilledCS1GPRs, FramePtr); |
| 1692 | if (FPPos != UnspilledCS1GPRs.end()) |
| 1693 | UnspilledCS1GPRs.erase(FPPos); |
| 1694 | NumGPRSpills++; |
| 1695 | if (FramePtr == ARM::R7) |
| 1696 | CS1Spilled = true; |
| 1697 | } |
| 1698 | |
Reid Kleckner | bdfc05f | 2016-10-11 21:14:03 +0000 | [diff] [blame] | 1699 | if (AFI->isThumb1OnlyFunction()) { |
| 1700 | // For Thumb1-only targets, we need some low registers when we save and |
| 1701 | // restore the high registers (which aren't allocatable, but could be |
| 1702 | // used by inline assembly) because the push/pop instructions can not |
| 1703 | // access high registers. If necessary, we might need to push more low |
| 1704 | // registers to ensure that there is at least one free that can be used |
| 1705 | // for the saving & restoring, and preferably we should ensure that as |
| 1706 | // many as are needed are available so that fewer push/pop instructions |
| 1707 | // are required. |
| 1708 | |
| 1709 | // Low registers which are not currently pushed, but could be (r4-r7). |
| 1710 | SmallVector<unsigned, 4> AvailableRegs; |
| 1711 | |
| 1712 | // Unused argument registers (r0-r3) can be clobbered in the prologue for |
| 1713 | // free. |
| 1714 | int EntryRegDeficit = 0; |
| 1715 | for (unsigned Reg : {ARM::R0, ARM::R1, ARM::R2, ARM::R3}) { |
| 1716 | if (!MF.getRegInfo().isLiveIn(Reg)) { |
| 1717 | --EntryRegDeficit; |
| 1718 | DEBUG(dbgs() << PrintReg(Reg, TRI) |
| 1719 | << " is unused argument register, EntryRegDeficit = " |
| 1720 | << EntryRegDeficit << "\n"); |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | // Unused return registers can be clobbered in the epilogue for free. |
| 1725 | int ExitRegDeficit = AFI->getReturnRegsCount() - 4; |
| 1726 | DEBUG(dbgs() << AFI->getReturnRegsCount() |
| 1727 | << " return regs used, ExitRegDeficit = " << ExitRegDeficit |
| 1728 | << "\n"); |
| 1729 | |
| 1730 | int RegDeficit = std::max(EntryRegDeficit, ExitRegDeficit); |
| 1731 | DEBUG(dbgs() << "RegDeficit = " << RegDeficit << "\n"); |
| 1732 | |
| 1733 | // r4-r6 can be used in the prologue if they are pushed by the first push |
| 1734 | // instruction. |
| 1735 | for (unsigned Reg : {ARM::R4, ARM::R5, ARM::R6}) { |
| 1736 | if (SavedRegs.test(Reg)) { |
| 1737 | --RegDeficit; |
| 1738 | DEBUG(dbgs() << PrintReg(Reg, TRI) |
| 1739 | << " is saved low register, RegDeficit = " << RegDeficit |
| 1740 | << "\n"); |
| 1741 | } else { |
| 1742 | AvailableRegs.push_back(Reg); |
| 1743 | DEBUG(dbgs() |
| 1744 | << PrintReg(Reg, TRI) |
| 1745 | << " is non-saved low register, adding to AvailableRegs\n"); |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | // r7 can be used if it is not being used as the frame pointer. |
| 1750 | if (!hasFP(MF)) { |
| 1751 | if (SavedRegs.test(ARM::R7)) { |
| 1752 | --RegDeficit; |
| 1753 | DEBUG(dbgs() << "%R7 is saved low register, RegDeficit = " |
| 1754 | << RegDeficit << "\n"); |
| 1755 | } else { |
| 1756 | AvailableRegs.push_back(ARM::R7); |
| 1757 | DEBUG(dbgs() |
| 1758 | << "%R7 is non-saved low register, adding to AvailableRegs\n"); |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | // Each of r8-r11 needs to be copied to a low register, then pushed. |
| 1763 | for (unsigned Reg : {ARM::R8, ARM::R9, ARM::R10, ARM::R11}) { |
| 1764 | if (SavedRegs.test(Reg)) { |
| 1765 | ++RegDeficit; |
| 1766 | DEBUG(dbgs() << PrintReg(Reg, TRI) |
| 1767 | << " is saved high register, RegDeficit = " << RegDeficit |
| 1768 | << "\n"); |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | // LR can only be used by PUSH, not POP, and can't be used at all if the |
| 1773 | // llvm.returnaddress intrinsic is used. This is only worth doing if we |
| 1774 | // are more limited at function entry than exit. |
| 1775 | if ((EntryRegDeficit > ExitRegDeficit) && |
| 1776 | !(MF.getRegInfo().isLiveIn(ARM::LR) && |
| 1777 | MF.getFrameInfo().isReturnAddressTaken())) { |
| 1778 | if (SavedRegs.test(ARM::LR)) { |
| 1779 | --RegDeficit; |
| 1780 | DEBUG(dbgs() << "%LR is saved register, RegDeficit = " << RegDeficit |
| 1781 | << "\n"); |
| 1782 | } else { |
| 1783 | AvailableRegs.push_back(ARM::LR); |
| 1784 | DEBUG(dbgs() << "%LR is not saved, adding to AvailableRegs\n"); |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | // If there are more high registers that need pushing than low registers |
| 1789 | // available, push some more low registers so that we can use fewer push |
| 1790 | // instructions. This might not reduce RegDeficit all the way to zero, |
| 1791 | // because we can only guarantee that r4-r6 are available, but r8-r11 may |
| 1792 | // need saving. |
| 1793 | DEBUG(dbgs() << "Final RegDeficit = " << RegDeficit << "\n"); |
| 1794 | for (; RegDeficit > 0 && !AvailableRegs.empty(); --RegDeficit) { |
| 1795 | unsigned Reg = AvailableRegs.pop_back_val(); |
| 1796 | DEBUG(dbgs() << "Spilling " << PrintReg(Reg, TRI) |
| 1797 | << " to make up reg deficit\n"); |
| 1798 | SavedRegs.set(Reg); |
| 1799 | NumGPRSpills++; |
| 1800 | CS1Spilled = true; |
| 1801 | ExtraCSSpill = true; |
| 1802 | UnspilledCS1GPRs.erase(find(UnspilledCS1GPRs, Reg)); |
| 1803 | if (Reg == ARM::LR) |
| 1804 | LRSpilled = true; |
| 1805 | } |
| 1806 | DEBUG(dbgs() << "After adding spills, RegDeficit = " << RegDeficit << "\n"); |
| 1807 | } |
| 1808 | |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1809 | // If LR is not spilled, but at least one of R4, R5, R6, and R7 is spilled. |
| 1810 | // Spill LR as well so we can fold BX_RET to the registers restore (LDM). |
| 1811 | if (!LRSpilled && CS1Spilled) { |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1812 | SavedRegs.set(ARM::LR); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1813 | NumGPRSpills++; |
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 1814 | SmallVectorImpl<unsigned>::iterator LRPos; |
David Majnemer | 0d955d0 | 2016-08-11 22:21:41 +0000 | [diff] [blame] | 1815 | LRPos = find(UnspilledCS1GPRs, (unsigned)ARM::LR); |
Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 1816 | if (LRPos != UnspilledCS1GPRs.end()) |
| 1817 | UnspilledCS1GPRs.erase(LRPos); |
| 1818 | |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1819 | ForceLRSpill = false; |
| 1820 | ExtraCSSpill = true; |
| 1821 | } |
| 1822 | |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1823 | // If stack and double are 8-byte aligned and we are spilling an odd number |
| 1824 | // of GPRs, spill one extra callee save GPR so we won't have to pad between |
| 1825 | // the integer and double callee save areas. |
Reid Kleckner | bdfc05f | 2016-10-11 21:14:03 +0000 | [diff] [blame] | 1826 | DEBUG(dbgs() << "NumGPRSpills = " << NumGPRSpills << "\n"); |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 1827 | unsigned TargetAlign = getStackAlignment(); |
Tim Northover | dc0d9e4 | 2014-11-05 00:27:20 +0000 | [diff] [blame] | 1828 | if (TargetAlign >= 8 && (NumGPRSpills & 1)) { |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1829 | if (CS1Spilled && !UnspilledCS1GPRs.empty()) { |
| 1830 | for (unsigned i = 0, e = UnspilledCS1GPRs.size(); i != e; ++i) { |
| 1831 | unsigned Reg = UnspilledCS1GPRs[i]; |
Saleem Abdulrasool | 1825fac | 2015-10-09 03:19:03 +0000 | [diff] [blame] | 1832 | // Don't spill high register if the function is thumb. In the case of |
| 1833 | // Windows on ARM, accept R11 (frame pointer) |
Peter Collingbourne | 78f1ecc | 2015-04-23 20:31:26 +0000 | [diff] [blame] | 1834 | if (!AFI->isThumbFunction() || |
Saleem Abdulrasool | 1825fac | 2015-10-09 03:19:03 +0000 | [diff] [blame] | 1835 | (STI.isTargetWindows() && Reg == ARM::R11) || |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1836 | isARMLowRegister(Reg) || Reg == ARM::LR) { |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1837 | SavedRegs.set(Reg); |
Reid Kleckner | bdfc05f | 2016-10-11 21:14:03 +0000 | [diff] [blame] | 1838 | DEBUG(dbgs() << "Spilling " << PrintReg(Reg, TRI) |
| 1839 | << " to make up alignment\n"); |
Jakob Stoklund Olesen | 410eae5 | 2012-10-26 21:43:05 +0000 | [diff] [blame] | 1840 | if (!MRI.isReserved(Reg)) |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1841 | ExtraCSSpill = true; |
| 1842 | break; |
| 1843 | } |
| 1844 | } |
| 1845 | } else if (!UnspilledCS2GPRs.empty() && !AFI->isThumb1OnlyFunction()) { |
| 1846 | unsigned Reg = UnspilledCS2GPRs.front(); |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1847 | SavedRegs.set(Reg); |
Reid Kleckner | bdfc05f | 2016-10-11 21:14:03 +0000 | [diff] [blame] | 1848 | DEBUG(dbgs() << "Spilling " << PrintReg(Reg, TRI) |
| 1849 | << " to make up alignment\n"); |
Jakob Stoklund Olesen | 410eae5 | 2012-10-26 21:43:05 +0000 | [diff] [blame] | 1850 | if (!MRI.isReserved(Reg)) |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1851 | ExtraCSSpill = true; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | // Estimate if we might need to scavenge a register at some point in order |
| 1856 | // to materialize a stack offset. If so, either spill one additional |
| 1857 | // callee-saved register or reserve a special spill slot to facilitate |
| 1858 | // register scavenging. Thumb1 needs a spill slot for stack pointer |
| 1859 | // adjustments also, even when the frame itself is small. |
| 1860 | if (BigStack && !ExtraCSSpill) { |
| 1861 | // If any non-reserved CS register isn't spilled, just spill one or two |
| 1862 | // extra. That should take care of it! |
| 1863 | unsigned NumExtras = TargetAlign / 4; |
| 1864 | SmallVector<unsigned, 2> Extras; |
| 1865 | while (NumExtras && !UnspilledCS1GPRs.empty()) { |
| 1866 | unsigned Reg = UnspilledCS1GPRs.back(); |
| 1867 | UnspilledCS1GPRs.pop_back(); |
Jakob Stoklund Olesen | 410eae5 | 2012-10-26 21:43:05 +0000 | [diff] [blame] | 1868 | if (!MRI.isReserved(Reg) && |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1869 | (!AFI->isThumb1OnlyFunction() || isARMLowRegister(Reg) || |
| 1870 | Reg == ARM::LR)) { |
| 1871 | Extras.push_back(Reg); |
| 1872 | NumExtras--; |
| 1873 | } |
| 1874 | } |
| 1875 | // For non-Thumb1 functions, also check for hi-reg CS registers |
| 1876 | if (!AFI->isThumb1OnlyFunction()) { |
| 1877 | while (NumExtras && !UnspilledCS2GPRs.empty()) { |
| 1878 | unsigned Reg = UnspilledCS2GPRs.back(); |
| 1879 | UnspilledCS2GPRs.pop_back(); |
Jakob Stoklund Olesen | 410eae5 | 2012-10-26 21:43:05 +0000 | [diff] [blame] | 1880 | if (!MRI.isReserved(Reg)) { |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1881 | Extras.push_back(Reg); |
| 1882 | NumExtras--; |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | if (Extras.size() && NumExtras == 0) { |
| 1887 | for (unsigned i = 0, e = Extras.size(); i != e; ++i) { |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1888 | SavedRegs.set(Extras[i]); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1889 | } |
| 1890 | } else if (!AFI->isThumb1OnlyFunction()) { |
| 1891 | // note: Thumb1 functions spill to R12, not the stack. Reserve a slot |
| 1892 | // closest to SP or frame pointer. |
Weiming Zhao | 5b5501e | 2016-05-08 05:11:54 +0000 | [diff] [blame] | 1893 | assert(RS && "Register scavenging not provided"); |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1894 | const TargetRegisterClass *RC = &ARM::GPRRegClass; |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1895 | RS->addScavengingFrameIndex(MFI.CreateStackObject(RC->getSize(), |
| 1896 | RC->getAlignment(), |
| 1897 | false)); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | if (ForceLRSpill) { |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 1903 | SavedRegs.set(ARM::LR); |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 1904 | AFI->setLRIsSpilledForFarJump(true); |
| 1905 | } |
| 1906 | } |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 1907 | |
Hans Wennborg | e1a2e90 | 2016-03-31 18:33:38 +0000 | [diff] [blame] | 1908 | MachineBasicBlock::iterator ARMFrameLowering::eliminateCallFramePseudoInstr( |
| 1909 | MachineFunction &MF, MachineBasicBlock &MBB, |
| 1910 | MachineBasicBlock::iterator I) const { |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 1911 | const ARMBaseInstrInfo &TII = |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 1912 | *static_cast<const ARMBaseInstrInfo *>(MF.getSubtarget().getInstrInfo()); |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 1913 | if (!hasReservedCallFrame(MF)) { |
| 1914 | // If we have alloca, convert as follows: |
| 1915 | // ADJCALLSTACKDOWN -> sub, sp, sp, amount |
| 1916 | // ADJCALLSTACKUP -> add, sp, sp, amount |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 1917 | MachineInstr &Old = *I; |
| 1918 | DebugLoc dl = Old.getDebugLoc(); |
| 1919 | unsigned Amount = Old.getOperand(0).getImm(); |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 1920 | if (Amount != 0) { |
| 1921 | // We need to keep the stack aligned properly. To do this, we round the |
| 1922 | // amount of space needed for the outgoing arguments up to the next |
| 1923 | // alignment boundary. |
Guozhi Wei | f66d384 | 2015-08-17 22:36:27 +0000 | [diff] [blame] | 1924 | Amount = alignSPAdjust(Amount); |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 1925 | |
| 1926 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1927 | assert(!AFI->isThumb1OnlyFunction() && |
| 1928 | "This eliminateCallFramePseudoInstr does not support Thumb1!"); |
| 1929 | bool isARM = !AFI->isThumbFunction(); |
| 1930 | |
| 1931 | // Replace the pseudo instruction with a new instruction... |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 1932 | unsigned Opc = Old.getOpcode(); |
| 1933 | int PIdx = Old.findFirstPredOperandIdx(); |
| 1934 | ARMCC::CondCodes Pred = |
| 1935 | (PIdx == -1) ? ARMCC::AL |
| 1936 | : (ARMCC::CondCodes)Old.getOperand(PIdx).getImm(); |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 1937 | if (Opc == ARM::ADJCALLSTACKDOWN || Opc == ARM::tADJCALLSTACKDOWN) { |
| 1938 | // Note: PredReg is operand 2 for ADJCALLSTACKDOWN. |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 1939 | unsigned PredReg = Old.getOperand(2).getReg(); |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 1940 | emitSPUpdate(isARM, MBB, I, dl, TII, -Amount, MachineInstr::NoFlags, |
| 1941 | Pred, PredReg); |
| 1942 | } else { |
| 1943 | // Note: PredReg is operand 3 for ADJCALLSTACKUP. |
Duncan P. N. Exon Smith | 29c5249 | 2016-07-08 20:21:17 +0000 | [diff] [blame] | 1944 | unsigned PredReg = Old.getOperand(3).getReg(); |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 1945 | assert(Opc == ARM::ADJCALLSTACKUP || Opc == ARM::tADJCALLSTACKUP); |
| 1946 | emitSPUpdate(isARM, MBB, I, dl, TII, Amount, MachineInstr::NoFlags, |
| 1947 | Pred, PredReg); |
| 1948 | } |
| 1949 | } |
| 1950 | } |
Hans Wennborg | e1a2e90 | 2016-03-31 18:33:38 +0000 | [diff] [blame] | 1951 | return MBB.erase(I); |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 1954 | /// Get the minimum constant for ARM that is greater than or equal to the |
| 1955 | /// argument. In ARM, constants can have any value that can be produced by |
| 1956 | /// rotating an 8-bit value to the right by an even number of bits within a |
| 1957 | /// 32-bit word. |
| 1958 | static uint32_t alignToARMConstant(uint32_t Value) { |
| 1959 | unsigned Shifted = 0; |
| 1960 | |
| 1961 | if (Value == 0) |
| 1962 | return 0; |
| 1963 | |
| 1964 | while (!(Value & 0xC0000000)) { |
| 1965 | Value = Value << 2; |
| 1966 | Shifted += 2; |
| 1967 | } |
| 1968 | |
| 1969 | bool Carry = (Value & 0x00FFFFFF); |
| 1970 | Value = ((Value & 0xFF000000) >> 24) + Carry; |
| 1971 | |
| 1972 | if (Value & 0x0000100) |
| 1973 | Value = Value & 0x000001FC; |
| 1974 | |
| 1975 | if (Shifted > 24) |
| 1976 | Value = Value >> (Shifted - 24); |
| 1977 | else |
| 1978 | Value = Value << (24 - Shifted); |
| 1979 | |
| 1980 | return Value; |
| 1981 | } |
| 1982 | |
| 1983 | // The stack limit in the TCB is set to this many bytes above the actual |
| 1984 | // stack limit. |
| 1985 | static const uint64_t kSplitStackAvailable = 256; |
| 1986 | |
| 1987 | // Adjust the function prologue to enable split stacks. This currently only |
| 1988 | // supports android and linux. |
| 1989 | // |
| 1990 | // The ABI of the segmented stack prologue is a little arbitrarily chosen, but |
| 1991 | // must be well defined in order to allow for consistent implementations of the |
| 1992 | // __morestack helper function. The ABI is also not a normal ABI in that it |
| 1993 | // doesn't follow the normal calling conventions because this allows the |
| 1994 | // prologue of each function to be optimized further. |
| 1995 | // |
| 1996 | // Currently, the ABI looks like (when calling __morestack) |
| 1997 | // |
| 1998 | // * r4 holds the minimum stack size requested for this function call |
| 1999 | // * r5 holds the stack size of the arguments to the function |
| 2000 | // * the beginning of the function is 3 instructions after the call to |
| 2001 | // __morestack |
| 2002 | // |
| 2003 | // Implementations of __morestack should use r4 to allocate a new stack, r5 to |
| 2004 | // place the arguments on to the new stack, and the 3-instruction knowledge to |
| 2005 | // jump directly to the body of the function when working on the new stack. |
| 2006 | // |
| 2007 | // An old (and possibly no longer compatible) implementation of __morestack for |
| 2008 | // ARM can be found at [1]. |
| 2009 | // |
| 2010 | // [1] - https://github.com/mozilla/rust/blob/86efd9/src/rt/arch/arm/morestack.S |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 2011 | void ARMFrameLowering::adjustForSegmentedStacks( |
| 2012 | MachineFunction &MF, MachineBasicBlock &PrologueMBB) const { |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2013 | unsigned Opcode; |
| 2014 | unsigned CFIIndex; |
Eric Christopher | 22b2ad2 | 2015-02-20 08:24:37 +0000 | [diff] [blame] | 2015 | const ARMSubtarget *ST = &MF.getSubtarget<ARMSubtarget>(); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2016 | bool Thumb = ST->isThumb(); |
| 2017 | |
| 2018 | // Sadly, this currently doesn't support varargs, platforms other than |
| 2019 | // android/linux. Note that thumb1/thumb2 are support for android/linux. |
| 2020 | if (MF.getFunction()->isVarArg()) |
| 2021 | report_fatal_error("Segmented stacks do not support vararg functions."); |
| 2022 | if (!ST->isTargetAndroid() && !ST->isTargetLinux()) |
Alp Toker | 16f98b2 | 2014-04-09 14:47:27 +0000 | [diff] [blame] | 2023 | report_fatal_error("Segmented stacks not supported on this platform."); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2024 | |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 2025 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2026 | MachineModuleInfo &MMI = MF.getMMI(); |
| 2027 | MCContext &Context = MMI.getContext(); |
| 2028 | const MCRegisterInfo *MRI = Context.getRegisterInfo(); |
| 2029 | const ARMBaseInstrInfo &TII = |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 2030 | *static_cast<const ARMBaseInstrInfo *>(MF.getSubtarget().getInstrInfo()); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2031 | ARMFunctionInfo *ARMFI = MF.getInfo<ARMFunctionInfo>(); |
| 2032 | DebugLoc DL; |
| 2033 | |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 2034 | uint64_t StackSize = MFI.getStackSize(); |
Tim Northover | f9e798b | 2014-05-22 13:03:43 +0000 | [diff] [blame] | 2035 | |
| 2036 | // Do not generate a prologue for functions with a stack of size zero |
| 2037 | if (StackSize == 0) |
| 2038 | return; |
| 2039 | |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2040 | // Use R4 and R5 as scratch registers. |
| 2041 | // We save R4 and R5 before use and restore them before leaving the function. |
| 2042 | unsigned ScratchReg0 = ARM::R4; |
| 2043 | unsigned ScratchReg1 = ARM::R5; |
| 2044 | uint64_t AlignedStackSize; |
| 2045 | |
| 2046 | MachineBasicBlock *PrevStackMBB = MF.CreateMachineBasicBlock(); |
| 2047 | MachineBasicBlock *PostStackMBB = MF.CreateMachineBasicBlock(); |
| 2048 | MachineBasicBlock *AllocMBB = MF.CreateMachineBasicBlock(); |
| 2049 | MachineBasicBlock *GetMBB = MF.CreateMachineBasicBlock(); |
| 2050 | MachineBasicBlock *McrMBB = MF.CreateMachineBasicBlock(); |
| 2051 | |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 2052 | // Grab everything that reaches PrologueMBB to update there liveness as well. |
| 2053 | SmallPtrSet<MachineBasicBlock *, 8> BeforePrologueRegion; |
| 2054 | SmallVector<MachineBasicBlock *, 2> WalkList; |
| 2055 | WalkList.push_back(&PrologueMBB); |
| 2056 | |
| 2057 | do { |
| 2058 | MachineBasicBlock *CurMBB = WalkList.pop_back_val(); |
| 2059 | for (MachineBasicBlock *PredBB : CurMBB->predecessors()) { |
| 2060 | if (BeforePrologueRegion.insert(PredBB).second) |
| 2061 | WalkList.push_back(PredBB); |
| 2062 | } |
| 2063 | } while (!WalkList.empty()); |
| 2064 | |
| 2065 | // The order in that list is important. |
| 2066 | // The blocks will all be inserted before PrologueMBB using that order. |
| 2067 | // Therefore the block that should appear first in the CFG should appear |
| 2068 | // first in the list. |
| 2069 | MachineBasicBlock *AddedBlocks[] = {PrevStackMBB, McrMBB, GetMBB, AllocMBB, |
| 2070 | PostStackMBB}; |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 2071 | |
Craig Topper | 8072081 | 2015-12-01 06:13:01 +0000 | [diff] [blame] | 2072 | for (MachineBasicBlock *B : AddedBlocks) |
| 2073 | BeforePrologueRegion.insert(B); |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 2074 | |
Matthias Braun | d9da162 | 2015-09-09 18:08:03 +0000 | [diff] [blame] | 2075 | for (const auto &LI : PrologueMBB.liveins()) { |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 2076 | for (MachineBasicBlock *PredBB : BeforePrologueRegion) |
Matthias Braun | b2b7ef1 | 2015-08-24 22:59:52 +0000 | [diff] [blame] | 2077 | PredBB->addLiveIn(LI); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 2080 | // Remove the newly added blocks from the list, since we know |
| 2081 | // we do not have to do the following updates for them. |
Craig Topper | 8072081 | 2015-12-01 06:13:01 +0000 | [diff] [blame] | 2082 | for (MachineBasicBlock *B : AddedBlocks) { |
| 2083 | BeforePrologueRegion.erase(B); |
| 2084 | MF.insert(PrologueMBB.getIterator(), B); |
Quentin Colombet | 71a7148 | 2015-07-20 21:42:14 +0000 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | for (MachineBasicBlock *MBB : BeforePrologueRegion) { |
| 2088 | // Make sure the LiveIns are still sorted and unique. |
| 2089 | MBB->sortUniqueLiveIns(); |
| 2090 | // Replace the edges to PrologueMBB by edges to the sequences |
| 2091 | // we are about to add. |
| 2092 | MBB->ReplaceUsesOfBlockWith(&PrologueMBB, AddedBlocks[0]); |
| 2093 | } |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2094 | |
| 2095 | // The required stack size that is aligned to ARM constant criterion. |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2096 | AlignedStackSize = alignToARMConstant(StackSize); |
| 2097 | |
| 2098 | // When the frame size is less than 256 we just compare the stack |
| 2099 | // boundary directly to the value of the stack pointer, per gcc. |
| 2100 | bool CompareStackPointer = AlignedStackSize < kSplitStackAvailable; |
| 2101 | |
| 2102 | // We will use two of the callee save registers as scratch registers so we |
| 2103 | // need to save those registers onto the stack. |
| 2104 | // We will use SR0 to hold stack limit and SR1 to hold the stack size |
| 2105 | // requested and arguments for __morestack(). |
| 2106 | // SR0: Scratch Register #0 |
| 2107 | // SR1: Scratch Register #1 |
| 2108 | // push {SR0, SR1} |
| 2109 | if (Thumb) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2110 | BuildMI(PrevStackMBB, DL, TII.get(ARM::tPUSH)) |
| 2111 | .add(predOps(ARMCC::AL)) |
| 2112 | .addReg(ScratchReg0) |
| 2113 | .addReg(ScratchReg1); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2114 | } else { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2115 | BuildMI(PrevStackMBB, DL, TII.get(ARM::STMDB_UPD)) |
| 2116 | .addReg(ARM::SP, RegState::Define) |
| 2117 | .addReg(ARM::SP) |
| 2118 | .add(predOps(ARMCC::AL)) |
| 2119 | .addReg(ScratchReg0) |
| 2120 | .addReg(ScratchReg1); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | // Emit the relevant DWARF information about the change in stack pointer as |
| 2124 | // well as where to find both r4 and r5 (the callee-save registers) |
| 2125 | CFIIndex = |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 2126 | MF.addFrameInst(MCCFIInstruction::createDefCfaOffset(nullptr, -8)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2127 | BuildMI(PrevStackMBB, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 2128 | .addCFIIndex(CFIIndex); |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 2129 | CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset( |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2130 | nullptr, MRI->getDwarfRegNum(ScratchReg1, true), -4)); |
| 2131 | BuildMI(PrevStackMBB, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 2132 | .addCFIIndex(CFIIndex); |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 2133 | CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset( |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2134 | nullptr, MRI->getDwarfRegNum(ScratchReg0, true), -8)); |
| 2135 | BuildMI(PrevStackMBB, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 2136 | .addCFIIndex(CFIIndex); |
| 2137 | |
| 2138 | // mov SR1, sp |
| 2139 | if (Thumb) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2140 | BuildMI(McrMBB, DL, TII.get(ARM::tMOVr), ScratchReg1) |
| 2141 | .addReg(ARM::SP) |
| 2142 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2143 | } else if (CompareStackPointer) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2144 | BuildMI(McrMBB, DL, TII.get(ARM::MOVr), ScratchReg1) |
| 2145 | .addReg(ARM::SP) |
| 2146 | .add(predOps(ARMCC::AL)) |
| 2147 | .addReg(0); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | // sub SR1, sp, #StackSize |
| 2151 | if (!CompareStackPointer && Thumb) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2152 | AddDefaultCC(BuildMI(McrMBB, DL, TII.get(ARM::tSUBi8), ScratchReg1)) |
| 2153 | .addReg(ScratchReg1) |
| 2154 | .addImm(AlignedStackSize) |
| 2155 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2156 | } else if (!CompareStackPointer) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2157 | BuildMI(McrMBB, DL, TII.get(ARM::SUBri), ScratchReg1) |
| 2158 | .addReg(ARM::SP) |
| 2159 | .addImm(AlignedStackSize) |
| 2160 | .add(predOps(ARMCC::AL)) |
| 2161 | .addReg(0); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | if (Thumb && ST->isThumb1Only()) { |
| 2165 | unsigned PCLabelId = ARMFI->createPICLabelUId(); |
| 2166 | ARMConstantPoolValue *NewCPV = ARMConstantPoolSymbol::Create( |
Oliver Stannard | 92e0fc0 | 2014-04-03 08:45:16 +0000 | [diff] [blame] | 2167 | MF.getFunction()->getContext(), "__STACK_LIMIT", PCLabelId, 0); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2168 | MachineConstantPool *MCP = MF.getConstantPool(); |
Tim Northover | 956b008 | 2015-10-02 18:07:13 +0000 | [diff] [blame] | 2169 | unsigned CPI = MCP->getConstantPoolIndex(NewCPV, 4); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2170 | |
| 2171 | // ldr SR0, [pc, offset(STACK_LIMIT)] |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2172 | BuildMI(GetMBB, DL, TII.get(ARM::tLDRpci), ScratchReg0) |
| 2173 | .addConstantPoolIndex(CPI) |
| 2174 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2175 | |
| 2176 | // ldr SR0, [SR0] |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2177 | BuildMI(GetMBB, DL, TII.get(ARM::tLDRi), ScratchReg0) |
| 2178 | .addReg(ScratchReg0) |
| 2179 | .addImm(0) |
| 2180 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2181 | } else { |
| 2182 | // Get TLS base address from the coprocessor |
| 2183 | // mrc p15, #0, SR0, c13, c0, #3 |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2184 | BuildMI(McrMBB, DL, TII.get(ARM::MRC), ScratchReg0) |
| 2185 | .addImm(15) |
| 2186 | .addImm(0) |
| 2187 | .addImm(13) |
| 2188 | .addImm(0) |
| 2189 | .addImm(3) |
| 2190 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2191 | |
| 2192 | // Use the last tls slot on android and a private field of the TCP on linux. |
| 2193 | assert(ST->isTargetAndroid() || ST->isTargetLinux()); |
| 2194 | unsigned TlsOffset = ST->isTargetAndroid() ? 63 : 1; |
| 2195 | |
| 2196 | // Get the stack limit from the right offset |
| 2197 | // ldr SR0, [sr0, #4 * TlsOffset] |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2198 | BuildMI(GetMBB, DL, TII.get(ARM::LDRi12), ScratchReg0) |
| 2199 | .addReg(ScratchReg0) |
| 2200 | .addImm(4 * TlsOffset) |
| 2201 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | // Compare stack limit with stack size requested. |
| 2205 | // cmp SR0, SR1 |
| 2206 | Opcode = Thumb ? ARM::tCMPr : ARM::CMPrr; |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2207 | BuildMI(GetMBB, DL, TII.get(Opcode)) |
| 2208 | .addReg(ScratchReg0) |
| 2209 | .addReg(ScratchReg1) |
| 2210 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2211 | |
| 2212 | // This jump is taken if StackLimit < SP - stack required. |
| 2213 | Opcode = Thumb ? ARM::tBcc : ARM::Bcc; |
| 2214 | BuildMI(GetMBB, DL, TII.get(Opcode)).addMBB(PostStackMBB) |
| 2215 | .addImm(ARMCC::LO) |
| 2216 | .addReg(ARM::CPSR); |
| 2217 | |
| 2218 | |
| 2219 | // Calling __morestack(StackSize, Size of stack arguments). |
| 2220 | // __morestack knows that the stack size requested is in SR0(r4) |
| 2221 | // and amount size of stack arguments is in SR1(r5). |
| 2222 | |
| 2223 | // Pass first argument for the __morestack by Scratch Register #0. |
| 2224 | // The amount size of stack required |
| 2225 | if (Thumb) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2226 | AddDefaultCC(BuildMI(AllocMBB, DL, TII.get(ARM::tMOVi8), ScratchReg0)) |
| 2227 | .addImm(AlignedStackSize) |
| 2228 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2229 | } else { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2230 | BuildMI(AllocMBB, DL, TII.get(ARM::MOVi), ScratchReg0) |
| 2231 | .addImm(AlignedStackSize) |
| 2232 | .add(predOps(ARMCC::AL)) |
| 2233 | .addReg(0); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2234 | } |
| 2235 | // Pass second argument for the __morestack by Scratch Register #1. |
| 2236 | // The amount size of stack consumed to save function arguments. |
| 2237 | if (Thumb) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2238 | AddDefaultCC(BuildMI(AllocMBB, DL, TII.get(ARM::tMOVi8), ScratchReg1)) |
| 2239 | .addImm(alignToARMConstant(ARMFI->getArgumentStackSize())) |
| 2240 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2241 | } else { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2242 | BuildMI(AllocMBB, DL, TII.get(ARM::MOVi), ScratchReg1) |
| 2243 | .addImm(alignToARMConstant(ARMFI->getArgumentStackSize())) |
| 2244 | .add(predOps(ARMCC::AL)) |
| 2245 | .addReg(0); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | // push {lr} - Save return address of this function. |
| 2249 | if (Thumb) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2250 | BuildMI(AllocMBB, DL, TII.get(ARM::tPUSH)) |
| 2251 | .add(predOps(ARMCC::AL)) |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2252 | .addReg(ARM::LR); |
| 2253 | } else { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2254 | BuildMI(AllocMBB, DL, TII.get(ARM::STMDB_UPD)) |
| 2255 | .addReg(ARM::SP, RegState::Define) |
| 2256 | .addReg(ARM::SP) |
| 2257 | .add(predOps(ARMCC::AL)) |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2258 | .addReg(ARM::LR); |
| 2259 | } |
| 2260 | |
| 2261 | // Emit the DWARF info about the change in stack as well as where to find the |
| 2262 | // previous link register |
| 2263 | CFIIndex = |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 2264 | MF.addFrameInst(MCCFIInstruction::createDefCfaOffset(nullptr, -12)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2265 | BuildMI(AllocMBB, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 2266 | .addCFIIndex(CFIIndex); |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 2267 | CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset( |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2268 | nullptr, MRI->getDwarfRegNum(ARM::LR, true), -12)); |
| 2269 | BuildMI(AllocMBB, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 2270 | .addCFIIndex(CFIIndex); |
| 2271 | |
| 2272 | // Call __morestack(). |
| 2273 | if (Thumb) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2274 | BuildMI(AllocMBB, DL, TII.get(ARM::tBL)) |
| 2275 | .add(predOps(ARMCC::AL)) |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2276 | .addExternalSymbol("__morestack"); |
| 2277 | } else { |
| 2278 | BuildMI(AllocMBB, DL, TII.get(ARM::BL)) |
| 2279 | .addExternalSymbol("__morestack"); |
| 2280 | } |
| 2281 | |
| 2282 | // pop {lr} - Restore return address of this original function. |
| 2283 | if (Thumb) { |
| 2284 | if (ST->isThumb1Only()) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2285 | BuildMI(AllocMBB, DL, TII.get(ARM::tPOP)) |
| 2286 | .add(predOps(ARMCC::AL)) |
| 2287 | .addReg(ScratchReg0); |
| 2288 | BuildMI(AllocMBB, DL, TII.get(ARM::tMOVr), ARM::LR) |
| 2289 | .addReg(ScratchReg0) |
| 2290 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2291 | } else { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2292 | BuildMI(AllocMBB, DL, TII.get(ARM::t2LDR_POST)) |
| 2293 | .addReg(ARM::LR, RegState::Define) |
| 2294 | .addReg(ARM::SP, RegState::Define) |
| 2295 | .addReg(ARM::SP) |
| 2296 | .addImm(4) |
| 2297 | .add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2298 | } |
| 2299 | } else { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2300 | BuildMI(AllocMBB, DL, TII.get(ARM::LDMIA_UPD)) |
| 2301 | .addReg(ARM::SP, RegState::Define) |
| 2302 | .addReg(ARM::SP) |
| 2303 | .add(predOps(ARMCC::AL)) |
| 2304 | .addReg(ARM::LR); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | // Restore SR0 and SR1 in case of __morestack() was called. |
| 2308 | // __morestack() will skip PostStackMBB block so we need to restore |
| 2309 | // scratch registers from here. |
| 2310 | // pop {SR0, SR1} |
| 2311 | if (Thumb) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2312 | BuildMI(AllocMBB, DL, TII.get(ARM::tPOP)) |
| 2313 | .add(predOps(ARMCC::AL)) |
| 2314 | .addReg(ScratchReg0) |
| 2315 | .addReg(ScratchReg1); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2316 | } else { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2317 | BuildMI(AllocMBB, DL, TII.get(ARM::LDMIA_UPD)) |
| 2318 | .addReg(ARM::SP, RegState::Define) |
| 2319 | .addReg(ARM::SP) |
| 2320 | .add(predOps(ARMCC::AL)) |
| 2321 | .addReg(ScratchReg0) |
| 2322 | .addReg(ScratchReg1); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | // Update the CFA offset now that we've popped |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 2326 | CFIIndex = MF.addFrameInst(MCCFIInstruction::createDefCfaOffset(nullptr, 0)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2327 | BuildMI(AllocMBB, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 2328 | .addCFIIndex(CFIIndex); |
| 2329 | |
| 2330 | // bx lr - Return from this function. |
| 2331 | Opcode = Thumb ? ARM::tBX_RET : ARM::BX_RET; |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2332 | BuildMI(AllocMBB, DL, TII.get(Opcode)).add(predOps(ARMCC::AL)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2333 | |
| 2334 | // Restore SR0 and SR1 in case of __morestack() was not called. |
| 2335 | // pop {SR0, SR1} |
| 2336 | if (Thumb) { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2337 | BuildMI(PostStackMBB, DL, TII.get(ARM::tPOP)) |
| 2338 | .add(predOps(ARMCC::AL)) |
| 2339 | .addReg(ScratchReg0) |
| 2340 | .addReg(ScratchReg1); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2341 | } else { |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 2342 | BuildMI(PostStackMBB, DL, TII.get(ARM::LDMIA_UPD)) |
| 2343 | .addReg(ARM::SP, RegState::Define) |
| 2344 | .addReg(ARM::SP) |
| 2345 | .add(predOps(ARMCC::AL)) |
| 2346 | .addReg(ScratchReg0) |
| 2347 | .addReg(ScratchReg1); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | // Update the CFA offset now that we've popped |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 2351 | CFIIndex = MF.addFrameInst(MCCFIInstruction::createDefCfaOffset(nullptr, 0)); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2352 | BuildMI(PostStackMBB, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 2353 | .addCFIIndex(CFIIndex); |
| 2354 | |
| 2355 | // Tell debuggers that r4 and r5 are now the same as they were in the |
| 2356 | // previous function, that they're the "Same Value". |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 2357 | CFIIndex = MF.addFrameInst(MCCFIInstruction::createSameValue( |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2358 | nullptr, MRI->getDwarfRegNum(ScratchReg0, true))); |
| 2359 | BuildMI(PostStackMBB, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 2360 | .addCFIIndex(CFIIndex); |
Matthias Braun | f23ef43 | 2016-11-30 23:48:42 +0000 | [diff] [blame] | 2361 | CFIIndex = MF.addFrameInst(MCCFIInstruction::createSameValue( |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2362 | nullptr, MRI->getDwarfRegNum(ScratchReg1, true))); |
| 2363 | BuildMI(PostStackMBB, DL, TII.get(TargetOpcode::CFI_INSTRUCTION)) |
| 2364 | .addCFIIndex(CFIIndex); |
| 2365 | |
| 2366 | // Organizing MBB lists |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 2367 | PostStackMBB->addSuccessor(&PrologueMBB); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2368 | |
| 2369 | AllocMBB->addSuccessor(PostStackMBB); |
| 2370 | |
| 2371 | GetMBB->addSuccessor(PostStackMBB); |
| 2372 | GetMBB->addSuccessor(AllocMBB); |
| 2373 | |
| 2374 | McrMBB->addSuccessor(GetMBB); |
| 2375 | |
| 2376 | PrevStackMBB->addSuccessor(McrMBB); |
| 2377 | |
Filipe Cabecinhas | 0da9937 | 2016-04-29 15:22:48 +0000 | [diff] [blame] | 2378 | #ifdef EXPENSIVE_CHECKS |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 2379 | MF.verify(); |
| 2380 | #endif |
| 2381 | } |