Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 1 | //===----------------------- SIFrameLowering.cpp --------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 6 | // |
| 7 | //==-----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "SIFrameLowering.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 10 | #include "AMDGPUSubtarget.h" |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 11 | #include "SIInstrInfo.h" |
| 12 | #include "SIMachineFunctionInfo.h" |
Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 13 | #include "SIRegisterInfo.h" |
Tom Stellard | 44b30b4 | 2018-05-22 02:03:23 +0000 | [diff] [blame] | 14 | #include "MCTargetDesc/AMDGPUMCTargetDesc.h" |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 15 | |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/LivePhysRegs.h" |
Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 18 | #include "llvm/CodeGen/MachineFunction.h" |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/RegisterScavenging.h" |
| 21 | |
| 22 | using namespace llvm; |
| 23 | |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 24 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 25 | static ArrayRef<MCPhysReg> getAllSGPR128(const GCNSubtarget &ST, |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 26 | const MachineFunction &MF) { |
Matt Arsenault | ab3429c | 2016-05-18 15:19:50 +0000 | [diff] [blame] | 27 | return makeArrayRef(AMDGPU::SGPR_128RegClass.begin(), |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 28 | ST.getMaxNumSGPRs(MF) / 4); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 31 | static ArrayRef<MCPhysReg> getAllSGPRs(const GCNSubtarget &ST, |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 32 | const MachineFunction &MF) { |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 33 | return makeArrayRef(AMDGPU::SGPR_32RegClass.begin(), |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 34 | ST.getMaxNumSGPRs(MF)); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 37 | void SIFrameLowering::emitFlatScratchInit(const GCNSubtarget &ST, |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 38 | MachineFunction &MF, |
| 39 | MachineBasicBlock &MBB) const { |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 40 | const SIInstrInfo *TII = ST.getInstrInfo(); |
| 41 | const SIRegisterInfo* TRI = &TII->getRegisterInfo(); |
Matt Arsenault | 8623e8d | 2017-08-03 23:00:29 +0000 | [diff] [blame] | 42 | const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 43 | |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 44 | // We don't need this if we only have spills since there is no user facing |
| 45 | // scratch. |
| 46 | |
| 47 | // TODO: If we know we don't have flat instructions earlier, we can omit |
| 48 | // this from the input registers. |
| 49 | // |
| 50 | // TODO: We only need to know if we access scratch space through a flat |
| 51 | // pointer. Because we only detect if flat instructions are used at all, |
| 52 | // this will be used more often than necessary on VI. |
| 53 | |
| 54 | // Debug location must be unknown since the first debug location is used to |
| 55 | // determine the end of the prologue. |
| 56 | DebugLoc DL; |
| 57 | MachineBasicBlock::iterator I = MBB.begin(); |
| 58 | |
| 59 | unsigned FlatScratchInitReg |
Matt Arsenault | 8623e8d | 2017-08-03 23:00:29 +0000 | [diff] [blame] | 60 | = MFI->getPreloadedReg(AMDGPUFunctionArgInfo::FLAT_SCRATCH_INIT); |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 61 | |
| 62 | MachineRegisterInfo &MRI = MF.getRegInfo(); |
| 63 | MRI.addLiveIn(FlatScratchInitReg); |
| 64 | MBB.addLiveIn(FlatScratchInitReg); |
| 65 | |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 66 | unsigned FlatScrInitLo = TRI->getSubReg(FlatScratchInitReg, AMDGPU::sub0); |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 67 | unsigned FlatScrInitHi = TRI->getSubReg(FlatScratchInitReg, AMDGPU::sub1); |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 68 | |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 69 | unsigned ScratchWaveOffsetReg = MFI->getScratchWaveOffsetReg(); |
| 70 | |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 71 | // Do a 64-bit pointer add. |
| 72 | if (ST.flatScratchIsPointer()) { |
Stanislav Mekhanoshin | a632294 | 2019-04-30 22:08:23 +0000 | [diff] [blame^] | 73 | if (ST.getGeneration() >= AMDGPUSubtarget::GFX10) { |
| 74 | BuildMI(MBB, I, DL, TII->get(AMDGPU::S_ADD_U32), FlatScrInitLo) |
| 75 | .addReg(FlatScrInitLo) |
| 76 | .addReg(ScratchWaveOffsetReg); |
| 77 | BuildMI(MBB, I, DL, TII->get(AMDGPU::S_ADDC_U32), FlatScrInitHi) |
| 78 | .addReg(FlatScrInitHi) |
| 79 | .addImm(0); |
| 80 | BuildMI(MBB, I, DL, TII->get(AMDGPU::S_SETREG_B32)). |
| 81 | addReg(FlatScrInitLo). |
| 82 | addImm(int16_t(AMDGPU::Hwreg::ID_FLAT_SCR_LO | |
| 83 | (31 << AMDGPU::Hwreg::WIDTH_M1_SHIFT_))); |
| 84 | BuildMI(MBB, I, DL, TII->get(AMDGPU::S_SETREG_B32)). |
| 85 | addReg(FlatScrInitHi). |
| 86 | addImm(int16_t(AMDGPU::Hwreg::ID_FLAT_SCR_HI | |
| 87 | (31 << AMDGPU::Hwreg::WIDTH_M1_SHIFT_))); |
| 88 | return; |
| 89 | } |
| 90 | |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 91 | BuildMI(MBB, I, DL, TII->get(AMDGPU::S_ADD_U32), AMDGPU::FLAT_SCR_LO) |
| 92 | .addReg(FlatScrInitLo) |
| 93 | .addReg(ScratchWaveOffsetReg); |
| 94 | BuildMI(MBB, I, DL, TII->get(AMDGPU::S_ADDC_U32), AMDGPU::FLAT_SCR_HI) |
| 95 | .addReg(FlatScrInitHi) |
| 96 | .addImm(0); |
| 97 | |
| 98 | return; |
| 99 | } |
| 100 | |
Stanislav Mekhanoshin | a632294 | 2019-04-30 22:08:23 +0000 | [diff] [blame^] | 101 | assert(ST.getGeneration() < AMDGPUSubtarget::GFX10); |
| 102 | |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 103 | // Copy the size in bytes. |
| 104 | BuildMI(MBB, I, DL, TII->get(AMDGPU::COPY), AMDGPU::FLAT_SCR_LO) |
| 105 | .addReg(FlatScrInitHi, RegState::Kill); |
| 106 | |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 107 | // Add wave offset in bytes to private base offset. |
| 108 | // See comment in AMDKernelCodeT.h for enable_sgpr_flat_scratch_init. |
| 109 | BuildMI(MBB, I, DL, TII->get(AMDGPU::S_ADD_U32), FlatScrInitLo) |
| 110 | .addReg(FlatScrInitLo) |
| 111 | .addReg(ScratchWaveOffsetReg); |
| 112 | |
| 113 | // Convert offset to 256-byte units. |
| 114 | BuildMI(MBB, I, DL, TII->get(AMDGPU::S_LSHR_B32), AMDGPU::FLAT_SCR_HI) |
| 115 | .addReg(FlatScrInitLo, RegState::Kill) |
| 116 | .addImm(8); |
| 117 | } |
| 118 | |
| 119 | unsigned SIFrameLowering::getReservedPrivateSegmentBufferReg( |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 120 | const GCNSubtarget &ST, |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 121 | const SIInstrInfo *TII, |
| 122 | const SIRegisterInfo *TRI, |
| 123 | SIMachineFunctionInfo *MFI, |
| 124 | MachineFunction &MF) const { |
Matt Arsenault | e221849 | 2017-04-24 21:08:32 +0000 | [diff] [blame] | 125 | MachineRegisterInfo &MRI = MF.getRegInfo(); |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 126 | |
| 127 | // We need to insert initialization of the scratch resource descriptor. |
| 128 | unsigned ScratchRsrcReg = MFI->getScratchRSrcReg(); |
Matt Arsenault | e221849 | 2017-04-24 21:08:32 +0000 | [diff] [blame] | 129 | if (ScratchRsrcReg == AMDGPU::NoRegister || |
| 130 | !MRI.isPhysRegUsed(ScratchRsrcReg)) |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 131 | return AMDGPU::NoRegister; |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 132 | |
| 133 | if (ST.hasSGPRInitBug() || |
| 134 | ScratchRsrcReg != TRI->reservedPrivateSegmentBufferReg(MF)) |
| 135 | return ScratchRsrcReg; |
| 136 | |
| 137 | // We reserved the last registers for this. Shift it down to the end of those |
| 138 | // which were actually used. |
| 139 | // |
| 140 | // FIXME: It might be safer to use a pseudoregister before replacement. |
| 141 | |
| 142 | // FIXME: We should be able to eliminate unused input registers. We only |
| 143 | // cannot do this for the resources required for scratch access. For now we |
| 144 | // skip over user SGPRs and may leave unused holes. |
| 145 | |
| 146 | // We find the resource first because it has an alignment requirement. |
| 147 | |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 148 | unsigned NumPreloaded = (MFI->getNumPreloadedSGPRs() + 3) / 4; |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 149 | ArrayRef<MCPhysReg> AllSGPR128s = getAllSGPR128(ST, MF); |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 150 | AllSGPR128s = AllSGPR128s.slice(std::min(static_cast<unsigned>(AllSGPR128s.size()), NumPreloaded)); |
| 151 | |
Matt Arsenault | e0bf7d0 | 2017-02-21 19:12:08 +0000 | [diff] [blame] | 152 | // Skip the last N reserved elements because they should have already been |
| 153 | // reserved for VCC etc. |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 154 | for (MCPhysReg Reg : AllSGPR128s) { |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 155 | // Pick the first unallocated one. Make sure we don't clobber the other |
| 156 | // reserved input we needed. |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 157 | if (!MRI.isPhysRegUsed(Reg) && MRI.isAllocatable(Reg)) { |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 158 | MRI.replaceRegWith(ScratchRsrcReg, Reg); |
| 159 | MFI->setScratchRSrcReg(Reg); |
| 160 | return Reg; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return ScratchRsrcReg; |
| 165 | } |
| 166 | |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 167 | // Shift down registers reserved for the scratch wave offset and stack pointer |
| 168 | // SGPRs. |
| 169 | std::pair<unsigned, unsigned> |
| 170 | SIFrameLowering::getReservedPrivateSegmentWaveByteOffsetReg( |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 171 | const GCNSubtarget &ST, |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 172 | const SIInstrInfo *TII, |
| 173 | const SIRegisterInfo *TRI, |
| 174 | SIMachineFunctionInfo *MFI, |
| 175 | MachineFunction &MF) const { |
Matt Arsenault | e221849 | 2017-04-24 21:08:32 +0000 | [diff] [blame] | 176 | MachineRegisterInfo &MRI = MF.getRegInfo(); |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 177 | unsigned ScratchWaveOffsetReg = MFI->getScratchWaveOffsetReg(); |
Matt Arsenault | e221849 | 2017-04-24 21:08:32 +0000 | [diff] [blame] | 178 | |
| 179 | // No replacement necessary. |
| 180 | if (ScratchWaveOffsetReg == AMDGPU::NoRegister || |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 181 | !MRI.isPhysRegUsed(ScratchWaveOffsetReg)) { |
Matt Arsenault | 1cc47f8 | 2017-07-18 16:44:56 +0000 | [diff] [blame] | 182 | assert(MFI->getStackPtrOffsetReg() == AMDGPU::SP_REG); |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 183 | return std::make_pair(AMDGPU::NoRegister, AMDGPU::NoRegister); |
| 184 | } |
Matt Arsenault | e221849 | 2017-04-24 21:08:32 +0000 | [diff] [blame] | 185 | |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 186 | unsigned SPReg = MFI->getStackPtrOffsetReg(); |
| 187 | if (ST.hasSGPRInitBug()) |
| 188 | return std::make_pair(ScratchWaveOffsetReg, SPReg); |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 189 | |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 190 | unsigned NumPreloaded = MFI->getNumPreloadedSGPRs(); |
| 191 | |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 192 | ArrayRef<MCPhysReg> AllSGPRs = getAllSGPRs(ST, MF); |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 193 | if (NumPreloaded > AllSGPRs.size()) |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 194 | return std::make_pair(ScratchWaveOffsetReg, SPReg); |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 195 | |
| 196 | AllSGPRs = AllSGPRs.slice(NumPreloaded); |
| 197 | |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 198 | // We need to drop register from the end of the list that we cannot use |
| 199 | // for the scratch wave offset. |
| 200 | // + 2 s102 and s103 do not exist on VI. |
| 201 | // + 2 for vcc |
| 202 | // + 2 for xnack_mask |
| 203 | // + 2 for flat_scratch |
| 204 | // + 4 for registers reserved for scratch resource register |
| 205 | // + 1 for register reserved for scratch wave offset. (By exluding this |
| 206 | // register from the list to consider, it means that when this |
| 207 | // register is being used for the scratch wave offset and there |
| 208 | // are no other free SGPRs, then the value will stay in this register. |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 209 | // + 1 if stack pointer is used. |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 210 | // ---- |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 211 | // 13 (+1) |
| 212 | unsigned ReservedRegCount = 13; |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 213 | |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 214 | if (AllSGPRs.size() < ReservedRegCount) |
| 215 | return std::make_pair(ScratchWaveOffsetReg, SPReg); |
| 216 | |
| 217 | bool HandledScratchWaveOffsetReg = |
| 218 | ScratchWaveOffsetReg != TRI->reservedPrivateSegmentWaveByteOffsetReg(MF); |
| 219 | |
| 220 | for (MCPhysReg Reg : AllSGPRs.drop_back(ReservedRegCount)) { |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 221 | // Pick the first unallocated SGPR. Be careful not to pick an alias of the |
| 222 | // scratch descriptor, since we haven’t added its uses yet. |
Matt Arsenault | e221849 | 2017-04-24 21:08:32 +0000 | [diff] [blame] | 223 | if (!MRI.isPhysRegUsed(Reg) && MRI.isAllocatable(Reg)) { |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 224 | if (!HandledScratchWaveOffsetReg) { |
| 225 | HandledScratchWaveOffsetReg = true; |
| 226 | |
| 227 | MRI.replaceRegWith(ScratchWaveOffsetReg, Reg); |
| 228 | MFI->setScratchWaveOffsetReg(Reg); |
| 229 | ScratchWaveOffsetReg = Reg; |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 230 | break; |
| 231 | } |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 235 | return std::make_pair(ScratchWaveOffsetReg, SPReg); |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 238 | void SIFrameLowering::emitEntryFunctionPrologue(MachineFunction &MF, |
| 239 | MachineBasicBlock &MBB) const { |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 240 | assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported"); |
| 241 | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 242 | SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 243 | |
| 244 | // If we only have SGPR spills, we won't actually be using scratch memory |
| 245 | // since these spill to VGPRs. |
| 246 | // |
| 247 | // FIXME: We should be cleaning up these unused SGPR spill frame indices |
| 248 | // somewhere. |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 249 | |
Matt Arsenault | aa6fb4c | 2019-02-21 23:27:46 +0000 | [diff] [blame] | 250 | const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>(); |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 251 | const SIInstrInfo *TII = ST.getInstrInfo(); |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 252 | const SIRegisterInfo *TRI = &TII->getRegisterInfo(); |
Matt Arsenault | 296b849 | 2016-02-12 06:31:30 +0000 | [diff] [blame] | 253 | MachineRegisterInfo &MRI = MF.getRegInfo(); |
Matt Arsenault | ceafc55 | 2018-05-29 17:42:50 +0000 | [diff] [blame] | 254 | const Function &F = MF.getFunction(); |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 255 | |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 256 | // We need to do the replacement of the private segment buffer and wave offset |
| 257 | // register even if there are no stack objects. There could be stores to undef |
| 258 | // or a constant without an associated object. |
| 259 | |
| 260 | // FIXME: We still have implicit uses on SGPR spill instructions in case they |
| 261 | // need to spill to vector memory. It's likely that will not happen, but at |
| 262 | // this point it appears we need the setup. This part of the prolog should be |
| 263 | // emitted after frame indices are eliminated. |
| 264 | |
Matt Arsenault | 254ad3d | 2017-07-18 16:44:58 +0000 | [diff] [blame] | 265 | if (MFI->hasFlatScratchInit()) |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 266 | emitFlatScratchInit(ST, MF, MBB); |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 267 | |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 268 | unsigned SPReg = MFI->getStackPtrOffsetReg(); |
Matt Arsenault | 1cc47f8 | 2017-07-18 16:44:56 +0000 | [diff] [blame] | 269 | if (SPReg != AMDGPU::SP_REG) { |
| 270 | assert(MRI.isReserved(SPReg) && "SPReg used but not reserved"); |
| 271 | |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 272 | DebugLoc DL; |
Matt Arsenault | 254ad3d | 2017-07-18 16:44:58 +0000 | [diff] [blame] | 273 | const MachineFrameInfo &FrameInfo = MF.getFrameInfo(); |
| 274 | int64_t StackSize = FrameInfo.getStackSize(); |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 275 | |
| 276 | if (StackSize == 0) { |
| 277 | BuildMI(MBB, MBB.begin(), DL, TII->get(AMDGPU::COPY), SPReg) |
| 278 | .addReg(MFI->getScratchWaveOffsetReg()); |
| 279 | } else { |
| 280 | BuildMI(MBB, MBB.begin(), DL, TII->get(AMDGPU::S_ADD_U32), SPReg) |
| 281 | .addReg(MFI->getScratchWaveOffsetReg()) |
| 282 | .addImm(StackSize * ST.getWavefrontSize()); |
| 283 | } |
| 284 | } |
| 285 | |
Matt Arsenault | e221849 | 2017-04-24 21:08:32 +0000 | [diff] [blame] | 286 | unsigned ScratchRsrcReg |
| 287 | = getReservedPrivateSegmentBufferReg(ST, TII, TRI, MFI, MF); |
Matt Arsenault | 36c3122 | 2017-04-25 23:40:57 +0000 | [diff] [blame] | 288 | |
| 289 | unsigned ScratchWaveOffsetReg; |
| 290 | std::tie(ScratchWaveOffsetReg, SPReg) |
Matt Arsenault | e221849 | 2017-04-24 21:08:32 +0000 | [diff] [blame] | 291 | = getReservedPrivateSegmentWaveByteOffsetReg(ST, TII, TRI, MFI, MF); |
| 292 | |
| 293 | // It's possible to have uses of only ScratchWaveOffsetReg without |
| 294 | // ScratchRsrcReg if it's only used for the initialization of flat_scratch, |
| 295 | // but the inverse is not true. |
| 296 | if (ScratchWaveOffsetReg == AMDGPU::NoRegister) { |
| 297 | assert(ScratchRsrcReg == AMDGPU::NoRegister); |
| 298 | return; |
| 299 | } |
| 300 | |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 301 | // We need to insert initialization of the scratch resource descriptor. |
Matt Arsenault | 8623e8d | 2017-08-03 23:00:29 +0000 | [diff] [blame] | 302 | unsigned PreloadedScratchWaveOffsetReg = MFI->getPreloadedReg( |
| 303 | AMDGPUFunctionArgInfo::PRIVATE_SEGMENT_WAVE_BYTE_OFFSET); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 304 | |
| 305 | unsigned PreloadedPrivateBufferReg = AMDGPU::NoRegister; |
Konstantin Zhuravlyov | aa067cb | 2018-10-04 21:02:16 +0000 | [diff] [blame] | 306 | if (ST.isAmdHsaOrMesa(F)) { |
Matt Arsenault | 8623e8d | 2017-08-03 23:00:29 +0000 | [diff] [blame] | 307 | PreloadedPrivateBufferReg = MFI->getPreloadedReg( |
| 308 | AMDGPUFunctionArgInfo::PRIVATE_SEGMENT_BUFFER); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Matt Arsenault | e221849 | 2017-04-24 21:08:32 +0000 | [diff] [blame] | 311 | bool OffsetRegUsed = MRI.isPhysRegUsed(ScratchWaveOffsetReg); |
| 312 | bool ResourceRegUsed = ScratchRsrcReg != AMDGPU::NoRegister && |
| 313 | MRI.isPhysRegUsed(ScratchRsrcReg); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 314 | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 315 | // We added live-ins during argument lowering, but since they were not used |
| 316 | // they were deleted. We're adding the uses now, so add them back. |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 317 | if (OffsetRegUsed) { |
| 318 | assert(PreloadedScratchWaveOffsetReg != AMDGPU::NoRegister && |
| 319 | "scratch wave offset input is required"); |
| 320 | MRI.addLiveIn(PreloadedScratchWaveOffsetReg); |
| 321 | MBB.addLiveIn(PreloadedScratchWaveOffsetReg); |
| 322 | } |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 323 | |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 324 | if (ResourceRegUsed && PreloadedPrivateBufferReg != AMDGPU::NoRegister) { |
Konstantin Zhuravlyov | aa067cb | 2018-10-04 21:02:16 +0000 | [diff] [blame] | 325 | assert(ST.isAmdHsaOrMesa(F) || ST.isMesaGfxShader(F)); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 326 | MRI.addLiveIn(PreloadedPrivateBufferReg); |
| 327 | MBB.addLiveIn(PreloadedPrivateBufferReg); |
| 328 | } |
| 329 | |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 330 | // Make the register selected live throughout the function. |
| 331 | for (MachineBasicBlock &OtherBB : MF) { |
| 332 | if (&OtherBB == &MBB) |
| 333 | continue; |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 334 | |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 335 | if (OffsetRegUsed) |
| 336 | OtherBB.addLiveIn(ScratchWaveOffsetReg); |
| 337 | |
| 338 | if (ResourceRegUsed) |
| 339 | OtherBB.addLiveIn(ScratchRsrcReg); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 342 | DebugLoc DL; |
Matt Arsenault | 57bc432 | 2016-08-31 21:52:21 +0000 | [diff] [blame] | 343 | MachineBasicBlock::iterator I = MBB.begin(); |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 344 | |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 345 | // If we reserved the original input registers, we don't need to copy to the |
| 346 | // reserved registers. |
| 347 | |
| 348 | bool CopyBuffer = ResourceRegUsed && |
| 349 | PreloadedPrivateBufferReg != AMDGPU::NoRegister && |
Konstantin Zhuravlyov | aa067cb | 2018-10-04 21:02:16 +0000 | [diff] [blame] | 350 | ST.isAmdHsaOrMesa(F) && |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 351 | ScratchRsrcReg != PreloadedPrivateBufferReg; |
| 352 | |
| 353 | // This needs to be careful of the copying order to avoid overwriting one of |
| 354 | // the input registers before it's been copied to it's final |
| 355 | // destination. Usually the offset should be copied first. |
| 356 | bool CopyBufferFirst = TRI->isSubRegisterEq(PreloadedPrivateBufferReg, |
| 357 | ScratchWaveOffsetReg); |
| 358 | if (CopyBuffer && CopyBufferFirst) { |
| 359 | BuildMI(MBB, I, DL, TII->get(AMDGPU::COPY), ScratchRsrcReg) |
| 360 | .addReg(PreloadedPrivateBufferReg, RegState::Kill); |
| 361 | } |
| 362 | |
| 363 | if (OffsetRegUsed && |
| 364 | PreloadedScratchWaveOffsetReg != ScratchWaveOffsetReg) { |
Matt Arsenault | 1d21517 | 2016-08-31 21:52:25 +0000 | [diff] [blame] | 365 | BuildMI(MBB, I, DL, TII->get(AMDGPU::COPY), ScratchWaveOffsetReg) |
Marek Olsak | 584d2c0 | 2017-05-04 22:25:20 +0000 | [diff] [blame] | 366 | .addReg(PreloadedScratchWaveOffsetReg, |
| 367 | MRI.isPhysRegUsed(ScratchWaveOffsetReg) ? 0 : RegState::Kill); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 368 | } |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 369 | |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 370 | if (CopyBuffer && !CopyBufferFirst) { |
Matt Arsenault | 1d21517 | 2016-08-31 21:52:25 +0000 | [diff] [blame] | 371 | BuildMI(MBB, I, DL, TII->get(AMDGPU::COPY), ScratchRsrcReg) |
| 372 | .addReg(PreloadedPrivateBufferReg, RegState::Kill); |
Matt Arsenault | 08906a3 | 2016-10-28 19:43:31 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 375 | if (ResourceRegUsed) |
| 376 | emitEntryFunctionScratchSetup(ST, MF, MBB, MFI, I, |
| 377 | PreloadedPrivateBufferReg, ScratchRsrcReg); |
| 378 | } |
| 379 | |
| 380 | // Emit scratch setup code for AMDPAL or Mesa, assuming ResourceRegUsed is set. |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 381 | void SIFrameLowering::emitEntryFunctionScratchSetup(const GCNSubtarget &ST, |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 382 | MachineFunction &MF, MachineBasicBlock &MBB, SIMachineFunctionInfo *MFI, |
| 383 | MachineBasicBlock::iterator I, unsigned PreloadedPrivateBufferReg, |
| 384 | unsigned ScratchRsrcReg) const { |
| 385 | |
| 386 | const SIInstrInfo *TII = ST.getInstrInfo(); |
| 387 | const SIRegisterInfo *TRI = &TII->getRegisterInfo(); |
Matt Arsenault | ceafc55 | 2018-05-29 17:42:50 +0000 | [diff] [blame] | 388 | const Function &Fn = MF.getFunction(); |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 389 | DebugLoc DL; |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 390 | |
| 391 | if (ST.isAmdPalOS()) { |
| 392 | // The pointer to the GIT is formed from the offset passed in and either |
| 393 | // the amdgpu-git-ptr-high function attribute or the top part of the PC |
| 394 | unsigned RsrcLo = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub0); |
| 395 | unsigned RsrcHi = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub1); |
| 396 | unsigned Rsrc01 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub0_sub1); |
| 397 | |
| 398 | const MCInstrDesc &SMovB32 = TII->get(AMDGPU::S_MOV_B32); |
| 399 | |
| 400 | if (MFI->getGITPtrHigh() != 0xffffffff) { |
| 401 | BuildMI(MBB, I, DL, SMovB32, RsrcHi) |
| 402 | .addImm(MFI->getGITPtrHigh()) |
| 403 | .addReg(ScratchRsrcReg, RegState::ImplicitDefine); |
| 404 | } else { |
| 405 | const MCInstrDesc &GetPC64 = TII->get(AMDGPU::S_GETPC_B64); |
| 406 | BuildMI(MBB, I, DL, GetPC64, Rsrc01); |
| 407 | } |
Tim Renouf | 832f90f | 2018-02-26 14:46:43 +0000 | [diff] [blame] | 408 | auto GitPtrLo = AMDGPU::SGPR0; // Low GIT address passed in |
| 409 | if (ST.hasMergedShaders()) { |
| 410 | switch (MF.getFunction().getCallingConv()) { |
| 411 | case CallingConv::AMDGPU_HS: |
| 412 | case CallingConv::AMDGPU_GS: |
| 413 | // Low GIT address is passed in s8 rather than s0 for an LS+HS or |
| 414 | // ES+GS merged shader on gfx9+. |
| 415 | GitPtrLo = AMDGPU::SGPR8; |
| 416 | break; |
| 417 | default: |
| 418 | break; |
| 419 | } |
| 420 | } |
Tim Renouf | 7190a46 | 2018-04-10 11:25:15 +0000 | [diff] [blame] | 421 | MF.getRegInfo().addLiveIn(GitPtrLo); |
| 422 | MF.front().addLiveIn(GitPtrLo); |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 423 | BuildMI(MBB, I, DL, SMovB32, RsrcLo) |
Tim Renouf | 832f90f | 2018-02-26 14:46:43 +0000 | [diff] [blame] | 424 | .addReg(GitPtrLo) |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 425 | .addReg(ScratchRsrcReg, RegState::ImplicitDefine); |
| 426 | |
| 427 | // We now have the GIT ptr - now get the scratch descriptor from the entry |
Tim Renouf | 7190a46 | 2018-04-10 11:25:15 +0000 | [diff] [blame] | 428 | // at offset 0 (or offset 16 for a compute shader). |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 429 | PointerType *PtrTy = |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 430 | PointerType::get(Type::getInt64Ty(MF.getFunction().getContext()), |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 431 | AMDGPUAS::CONSTANT_ADDRESS); |
| 432 | MachinePointerInfo PtrInfo(UndefValue::get(PtrTy)); |
| 433 | const MCInstrDesc &LoadDwordX4 = TII->get(AMDGPU::S_LOAD_DWORDX4_IMM); |
| 434 | auto MMO = MF.getMachineMemOperand(PtrInfo, |
| 435 | MachineMemOperand::MOLoad | |
| 436 | MachineMemOperand::MOInvariant | |
| 437 | MachineMemOperand::MODereferenceable, |
Matt Arsenault | 2a64598 | 2019-01-31 01:38:47 +0000 | [diff] [blame] | 438 | 16, 4); |
Matt Arsenault | ceafc55 | 2018-05-29 17:42:50 +0000 | [diff] [blame] | 439 | unsigned Offset = Fn.getCallingConv() == CallingConv::AMDGPU_CS ? 16 : 0; |
Carl Ritson | 494b8ac | 2019-02-08 15:41:11 +0000 | [diff] [blame] | 440 | const GCNSubtarget &Subtarget = MF.getSubtarget<GCNSubtarget>(); |
| 441 | unsigned EncodedOffset = AMDGPU::getSMRDEncodedOffset(Subtarget, Offset); |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 442 | BuildMI(MBB, I, DL, LoadDwordX4, ScratchRsrcReg) |
| 443 | .addReg(Rsrc01) |
Carl Ritson | 494b8ac | 2019-02-08 15:41:11 +0000 | [diff] [blame] | 444 | .addImm(EncodedOffset) // offset |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 445 | .addImm(0) // glc |
Stanislav Mekhanoshin | a632294 | 2019-04-30 22:08:23 +0000 | [diff] [blame^] | 446 | .addImm(0) // dlc |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 447 | .addReg(ScratchRsrcReg, RegState::ImplicitDefine) |
| 448 | .addMemOperand(MMO); |
| 449 | return; |
| 450 | } |
Matt Arsenault | ceafc55 | 2018-05-29 17:42:50 +0000 | [diff] [blame] | 451 | if (ST.isMesaGfxShader(Fn) |
Tim Renouf | 1322915 | 2017-09-29 09:49:35 +0000 | [diff] [blame] | 452 | || (PreloadedPrivateBufferReg == AMDGPU::NoRegister)) { |
Konstantin Zhuravlyov | aa067cb | 2018-10-04 21:02:16 +0000 | [diff] [blame] | 453 | assert(!ST.isAmdHsaOrMesa(Fn)); |
Matt Arsenault | 1d21517 | 2016-08-31 21:52:25 +0000 | [diff] [blame] | 454 | const MCInstrDesc &SMovB32 = TII->get(AMDGPU::S_MOV_B32); |
| 455 | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 456 | unsigned Rsrc2 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub2); |
| 457 | unsigned Rsrc3 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub3); |
| 458 | |
| 459 | // Use relocations to get the pointer, and setup the other bits manually. |
| 460 | uint64_t Rsrc23 = TII->getScratchRsrcWords23(); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 461 | |
Matt Arsenault | 10fc062 | 2017-06-26 03:01:31 +0000 | [diff] [blame] | 462 | if (MFI->hasImplicitBufferPtr()) { |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 463 | unsigned Rsrc01 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub0_sub1); |
| 464 | |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 465 | if (AMDGPU::isCompute(MF.getFunction().getCallingConv())) { |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 466 | const MCInstrDesc &Mov64 = TII->get(AMDGPU::S_MOV_B64); |
| 467 | |
| 468 | BuildMI(MBB, I, DL, Mov64, Rsrc01) |
Matt Arsenault | 10fc062 | 2017-06-26 03:01:31 +0000 | [diff] [blame] | 469 | .addReg(MFI->getImplicitBufferPtrUserSGPR()) |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 470 | .addReg(ScratchRsrcReg, RegState::ImplicitDefine); |
| 471 | } else { |
| 472 | const MCInstrDesc &LoadDwordX2 = TII->get(AMDGPU::S_LOAD_DWORDX2_IMM); |
| 473 | |
| 474 | PointerType *PtrTy = |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 475 | PointerType::get(Type::getInt64Ty(MF.getFunction().getContext()), |
Konstantin Zhuravlyov | 435151a | 2017-11-01 19:12:38 +0000 | [diff] [blame] | 476 | AMDGPUAS::CONSTANT_ADDRESS); |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 477 | MachinePointerInfo PtrInfo(UndefValue::get(PtrTy)); |
| 478 | auto MMO = MF.getMachineMemOperand(PtrInfo, |
| 479 | MachineMemOperand::MOLoad | |
| 480 | MachineMemOperand::MOInvariant | |
| 481 | MachineMemOperand::MODereferenceable, |
Matt Arsenault | 2a64598 | 2019-01-31 01:38:47 +0000 | [diff] [blame] | 482 | 8, 4); |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 483 | BuildMI(MBB, I, DL, LoadDwordX2, Rsrc01) |
Matt Arsenault | 10fc062 | 2017-06-26 03:01:31 +0000 | [diff] [blame] | 484 | .addReg(MFI->getImplicitBufferPtrUserSGPR()) |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 485 | .addImm(0) // offset |
| 486 | .addImm(0) // glc |
Stanislav Mekhanoshin | a632294 | 2019-04-30 22:08:23 +0000 | [diff] [blame^] | 487 | .addImm(0) // dlc |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 488 | .addMemOperand(MMO) |
| 489 | .addReg(ScratchRsrcReg, RegState::ImplicitDefine); |
| 490 | } |
| 491 | } else { |
| 492 | unsigned Rsrc0 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub0); |
| 493 | unsigned Rsrc1 = TRI->getSubReg(ScratchRsrcReg, AMDGPU::sub1); |
| 494 | |
| 495 | BuildMI(MBB, I, DL, SMovB32, Rsrc0) |
| 496 | .addExternalSymbol("SCRATCH_RSRC_DWORD0") |
| 497 | .addReg(ScratchRsrcReg, RegState::ImplicitDefine); |
| 498 | |
| 499 | BuildMI(MBB, I, DL, SMovB32, Rsrc1) |
| 500 | .addExternalSymbol("SCRATCH_RSRC_DWORD1") |
| 501 | .addReg(ScratchRsrcReg, RegState::ImplicitDefine); |
| 502 | |
| 503 | } |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 504 | |
| 505 | BuildMI(MBB, I, DL, SMovB32, Rsrc2) |
| 506 | .addImm(Rsrc23 & 0xffffffff) |
| 507 | .addReg(ScratchRsrcReg, RegState::ImplicitDefine); |
| 508 | |
| 509 | BuildMI(MBB, I, DL, SMovB32, Rsrc3) |
| 510 | .addImm(Rsrc23 >> 32) |
| 511 | .addReg(ScratchRsrcReg, RegState::ImplicitDefine); |
| 512 | } |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 515 | // Find a scratch register that we can use at the start of the prologue to |
| 516 | // re-align the stack pointer. We avoid using callee-save registers since they |
| 517 | // may appear to be free when this is called from canUseAsPrologue (during |
| 518 | // shrink wrapping), but then no longer be free when this is called from |
| 519 | // emitPrologue. |
| 520 | // |
| 521 | // FIXME: This is a bit conservative, since in the above case we could use one |
| 522 | // of the callee-save registers as a scratch temp to re-align the stack pointer, |
| 523 | // but we would then have to make sure that we were in fact saving at least one |
| 524 | // callee-save register in the prologue, which is additional complexity that |
| 525 | // doesn't seem worth the benefit. |
| 526 | static unsigned findScratchNonCalleeSaveRegister(MachineBasicBlock &MBB) { |
| 527 | MachineFunction *MF = MBB.getParent(); |
| 528 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 529 | const GCNSubtarget &Subtarget = MF->getSubtarget<GCNSubtarget>(); |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 530 | const SIRegisterInfo &TRI = *Subtarget.getRegisterInfo(); |
| 531 | LivePhysRegs LiveRegs(TRI); |
| 532 | LiveRegs.addLiveIns(MBB); |
| 533 | |
| 534 | // Mark callee saved registers as used so we will not choose them. |
| 535 | const MCPhysReg *CSRegs = TRI.getCalleeSavedRegs(MF); |
| 536 | for (unsigned i = 0; CSRegs[i]; ++i) |
| 537 | LiveRegs.addReg(CSRegs[i]); |
| 538 | |
| 539 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 540 | |
| 541 | for (unsigned Reg : AMDGPU::SReg_32_XM0RegClass) { |
| 542 | if (LiveRegs.available(MRI, Reg)) |
| 543 | return Reg; |
| 544 | } |
| 545 | |
| 546 | return AMDGPU::NoRegister; |
| 547 | } |
| 548 | |
Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 549 | void SIFrameLowering::emitPrologue(MachineFunction &MF, |
| 550 | MachineBasicBlock &MBB) const { |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 551 | SIMachineFunctionInfo *FuncInfo = MF.getInfo<SIMachineFunctionInfo>(); |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 552 | if (FuncInfo->isEntryFunction()) { |
Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 553 | emitEntryFunctionPrologue(MF, MBB); |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 554 | return; |
| 555 | } |
| 556 | |
| 557 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 558 | const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>(); |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 559 | const SIInstrInfo *TII = ST.getInstrInfo(); |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 560 | const SIRegisterInfo &TRI = TII->getRegisterInfo(); |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 561 | |
| 562 | unsigned StackPtrReg = FuncInfo->getStackPtrOffsetReg(); |
| 563 | unsigned FramePtrReg = FuncInfo->getFrameOffsetReg(); |
| 564 | |
| 565 | MachineBasicBlock::iterator MBBI = MBB.begin(); |
| 566 | DebugLoc DL; |
| 567 | |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 568 | // XXX - Is this the right predicate? |
| 569 | |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 570 | bool NeedFP = hasFP(MF); |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 571 | uint32_t NumBytes = MFI.getStackSize(); |
| 572 | uint32_t RoundedSize = NumBytes; |
| 573 | const bool NeedsRealignment = TRI.needsStackRealignment(MF); |
| 574 | |
| 575 | if (NeedsRealignment) { |
| 576 | assert(NeedFP); |
| 577 | const unsigned Alignment = MFI.getMaxAlignment(); |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 578 | |
| 579 | RoundedSize += Alignment; |
| 580 | |
| 581 | unsigned ScratchSPReg = findScratchNonCalleeSaveRegister(MBB); |
| 582 | assert(ScratchSPReg != AMDGPU::NoRegister); |
| 583 | |
| 584 | // s_add_u32 tmp_reg, s32, NumBytes |
| 585 | // s_and_b32 s32, tmp_reg, 0b111...0000 |
| 586 | BuildMI(MBB, MBBI, DL, TII->get(AMDGPU::S_ADD_U32), ScratchSPReg) |
| 587 | .addReg(StackPtrReg) |
| 588 | .addImm((Alignment - 1) * ST.getWavefrontSize()) |
| 589 | .setMIFlag(MachineInstr::FrameSetup); |
| 590 | BuildMI(MBB, MBBI, DL, TII->get(AMDGPU::S_AND_B32), FramePtrReg) |
| 591 | .addReg(ScratchSPReg, RegState::Kill) |
| 592 | .addImm(-Alignment * ST.getWavefrontSize()) |
| 593 | .setMIFlag(MachineInstr::FrameSetup); |
| 594 | FuncInfo->setIsStackRealigned(true); |
| 595 | } else if (NeedFP) { |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 596 | // If we need a base pointer, set it up here. It's whatever the value of |
| 597 | // the stack pointer is at this point. Any variable size objects will be |
| 598 | // allocated after this, so we can still use the base pointer to reference |
| 599 | // locals. |
| 600 | BuildMI(MBB, MBBI, DL, TII->get(AMDGPU::COPY), FramePtrReg) |
| 601 | .addReg(StackPtrReg) |
| 602 | .setMIFlag(MachineInstr::FrameSetup); |
| 603 | } |
| 604 | |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 605 | if (RoundedSize != 0 && hasSP(MF)) { |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 606 | BuildMI(MBB, MBBI, DL, TII->get(AMDGPU::S_ADD_U32), StackPtrReg) |
| 607 | .addReg(StackPtrReg) |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 608 | .addImm(RoundedSize * ST.getWavefrontSize()) |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 609 | .setMIFlag(MachineInstr::FrameSetup); |
| 610 | } |
Matt Arsenault | 8e8f8f4 | 2017-08-02 01:52:45 +0000 | [diff] [blame] | 611 | |
| 612 | for (const SIMachineFunctionInfo::SGPRSpillVGPRCSR &Reg |
| 613 | : FuncInfo->getSGPRSpillVGPRs()) { |
| 614 | if (!Reg.FI.hasValue()) |
| 615 | continue; |
| 616 | TII->storeRegToStackSlot(MBB, MBBI, Reg.VGPR, true, |
| 617 | Reg.FI.getValue(), &AMDGPU::VGPR_32RegClass, |
| 618 | &TII->getRegisterInfo()); |
| 619 | } |
Matt Arsenault | 2b1f9aa | 2017-05-17 21:56:25 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 622 | void SIFrameLowering::emitEpilogue(MachineFunction &MF, |
| 623 | MachineBasicBlock &MBB) const { |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 624 | const SIMachineFunctionInfo *FuncInfo = MF.getInfo<SIMachineFunctionInfo>(); |
| 625 | if (FuncInfo->isEntryFunction()) |
| 626 | return; |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 627 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 628 | const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>(); |
Matt Arsenault | 8e8f8f4 | 2017-08-02 01:52:45 +0000 | [diff] [blame] | 629 | const SIInstrInfo *TII = ST.getInstrInfo(); |
| 630 | MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator(); |
| 631 | |
| 632 | for (const SIMachineFunctionInfo::SGPRSpillVGPRCSR &Reg |
| 633 | : FuncInfo->getSGPRSpillVGPRs()) { |
| 634 | if (!Reg.FI.hasValue()) |
| 635 | continue; |
| 636 | TII->loadRegFromStackSlot(MBB, MBBI, Reg.VGPR, |
| 637 | Reg.FI.getValue(), &AMDGPU::VGPR_32RegClass, |
| 638 | &TII->getRegisterInfo()); |
| 639 | } |
| 640 | |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 641 | unsigned StackPtrReg = FuncInfo->getStackPtrOffsetReg(); |
| 642 | if (StackPtrReg == AMDGPU::NoRegister) |
| 643 | return; |
| 644 | |
| 645 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
| 646 | uint32_t NumBytes = MFI.getStackSize(); |
| 647 | |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 648 | DebugLoc DL; |
| 649 | |
| 650 | // FIXME: Clarify distinction between no set SP and SP. For callee functions, |
| 651 | // it's really whether we need SP to be accurate or not. |
| 652 | |
| 653 | if (NumBytes != 0 && hasSP(MF)) { |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 654 | uint32_t RoundedSize = FuncInfo->isStackRealigned() ? |
| 655 | NumBytes + MFI.getMaxAlignment() : NumBytes; |
| 656 | |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 657 | BuildMI(MBB, MBBI, DL, TII->get(AMDGPU::S_SUB_U32), StackPtrReg) |
| 658 | .addReg(StackPtrReg) |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 659 | .addImm(RoundedSize * ST.getWavefrontSize()); |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 660 | } |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Matt Arsenault | 7b6c5d2 | 2017-02-22 22:23:32 +0000 | [diff] [blame] | 663 | static bool allStackObjectsAreDead(const MachineFrameInfo &MFI) { |
| 664 | for (int I = MFI.getObjectIndexBegin(), E = MFI.getObjectIndexEnd(); |
| 665 | I != E; ++I) { |
| 666 | if (!MFI.isDeadObjectIndex(I)) |
| 667 | return false; |
| 668 | } |
| 669 | |
| 670 | return true; |
| 671 | } |
| 672 | |
Konstantin Zhuravlyov | ffdb00e | 2017-03-10 19:39:07 +0000 | [diff] [blame] | 673 | int SIFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI, |
| 674 | unsigned &FrameReg) const { |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 675 | const SIRegisterInfo *RI = MF.getSubtarget<GCNSubtarget>().getRegisterInfo(); |
Konstantin Zhuravlyov | ffdb00e | 2017-03-10 19:39:07 +0000 | [diff] [blame] | 676 | |
| 677 | FrameReg = RI->getFrameRegister(MF); |
| 678 | return MF.getFrameInfo().getObjectOffset(FI); |
| 679 | } |
| 680 | |
Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 681 | void SIFrameLowering::processFunctionBeforeFrameFinalized( |
| 682 | MachineFunction &MF, |
| 683 | RegScavenger *RS) const { |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 684 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 685 | |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 686 | if (!MFI.hasStackObjects()) |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame] | 687 | return; |
| 688 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 689 | const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>(); |
Matt Arsenault | 7b6c5d2 | 2017-02-22 22:23:32 +0000 | [diff] [blame] | 690 | const SIInstrInfo *TII = ST.getInstrInfo(); |
| 691 | const SIRegisterInfo &TRI = TII->getRegisterInfo(); |
| 692 | SIMachineFunctionInfo *FuncInfo = MF.getInfo<SIMachineFunctionInfo>(); |
| 693 | bool AllSGPRSpilledToVGPRs = false; |
| 694 | |
| 695 | if (TRI.spillSGPRToVGPR() && FuncInfo->hasSpilledSGPRs()) { |
| 696 | AllSGPRSpilledToVGPRs = true; |
| 697 | |
| 698 | // Process all SGPR spills before frame offsets are finalized. Ideally SGPRs |
| 699 | // are spilled to VGPRs, in which case we can eliminate the stack usage. |
| 700 | // |
| 701 | // XXX - This operates under the assumption that only other SGPR spills are |
| 702 | // users of the frame index. I'm not 100% sure this is correct. The |
| 703 | // StackColoring pass has a comment saying a future improvement would be to |
| 704 | // merging of allocas with spill slots, but for now according to |
| 705 | // MachineFrameInfo isSpillSlot can't alias any other object. |
| 706 | for (MachineBasicBlock &MBB : MF) { |
| 707 | MachineBasicBlock::iterator Next; |
| 708 | for (auto I = MBB.begin(), E = MBB.end(); I != E; I = Next) { |
| 709 | MachineInstr &MI = *I; |
| 710 | Next = std::next(I); |
| 711 | |
| 712 | if (TII->isSGPRSpill(MI)) { |
| 713 | int FI = TII->getNamedOperand(MI, AMDGPU::OpName::addr)->getIndex(); |
Matt Arsenault | adc59d7 | 2018-04-23 15:51:26 +0000 | [diff] [blame] | 714 | assert(MFI.getStackID(FI) == SIStackID::SGPR_SPILL); |
Matt Arsenault | 7b6c5d2 | 2017-02-22 22:23:32 +0000 | [diff] [blame] | 715 | if (FuncInfo->allocateSGPRSpillToVGPR(MF, FI)) { |
| 716 | bool Spilled = TRI.eliminateSGPRToVGPRSpillFrameIndex(MI, FI, RS); |
| 717 | (void)Spilled; |
| 718 | assert(Spilled && "failed to spill SGPR to VGPR when allocated"); |
| 719 | } else |
| 720 | AllSGPRSpilledToVGPRs = false; |
| 721 | } |
| 722 | } |
| 723 | } |
Matt Arsenault | 7b6c5d2 | 2017-02-22 22:23:32 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Sander de Smalen | 7f23e0a | 2019-04-02 09:46:52 +0000 | [diff] [blame] | 726 | FuncInfo->removeSGPRToVGPRFrameIndices(MFI); |
| 727 | |
Matt Arsenault | 7b6c5d2 | 2017-02-22 22:23:32 +0000 | [diff] [blame] | 728 | // FIXME: The other checks should be redundant with allStackObjectsAreDead, |
| 729 | // but currently hasNonSpillStackObjects is set only from source |
| 730 | // allocas. Stack temps produced from legalization are not counted currently. |
| 731 | if (FuncInfo->hasNonSpillStackObjects() || FuncInfo->hasSpilledVGPRs() || |
| 732 | !AllSGPRSpilledToVGPRs || !allStackObjectsAreDead(MFI)) { |
| 733 | assert(RS && "RegScavenger required if spilling"); |
| 734 | |
Matt Arsenault | 707780b | 2017-02-22 21:05:25 +0000 | [diff] [blame] | 735 | // We force this to be at offset 0 so no user object ever has 0 as an |
| 736 | // address, so we may use 0 as an invalid pointer value. This is because |
| 737 | // LLVM assumes 0 is an invalid pointer in address space 0. Because alloca |
| 738 | // is required to be address space 0, we are forced to accept this for |
| 739 | // now. Ideally we could have the stack in another address space with 0 as a |
| 740 | // valid pointer, and -1 as the null value. |
| 741 | // |
| 742 | // This will also waste additional space when user stack objects require > 4 |
| 743 | // byte alignment. |
| 744 | // |
| 745 | // The main cost here is losing the offset for addressing modes. However |
| 746 | // this also ensures we shouldn't need a register for the offset when |
| 747 | // emergency scavenging. |
| 748 | int ScavengeFI = MFI.CreateFixedObject( |
Krzysztof Parzyszek | 44e25f3 | 2017-04-24 18:55:33 +0000 | [diff] [blame] | 749 | TRI.getSpillSize(AMDGPU::SGPR_32RegClass), 0, false); |
Matt Arsenault | 707780b | 2017-02-22 21:05:25 +0000 | [diff] [blame] | 750 | RS->addScavengingFrameIndex(ScavengeFI); |
| 751 | } |
Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 752 | } |
Konstantin Zhuravlyov | f2f3d14 | 2016-06-25 03:11:28 +0000 | [diff] [blame] | 753 | |
Matt Arsenault | ecb43ef | 2017-09-13 23:47:01 +0000 | [diff] [blame] | 754 | void SIFrameLowering::determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, |
| 755 | RegScavenger *RS) const { |
| 756 | TargetFrameLowering::determineCalleeSaves(MF, SavedRegs, RS); |
| 757 | const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
| 758 | |
| 759 | // The SP is specifically managed and we don't want extra spills of it. |
| 760 | SavedRegs.reset(MFI->getStackPtrOffsetReg()); |
| 761 | } |
| 762 | |
Matt Arsenault | b62a4eb | 2017-08-01 19:54:18 +0000 | [diff] [blame] | 763 | MachineBasicBlock::iterator SIFrameLowering::eliminateCallFramePseudoInstr( |
| 764 | MachineFunction &MF, |
| 765 | MachineBasicBlock &MBB, |
| 766 | MachineBasicBlock::iterator I) const { |
| 767 | int64_t Amount = I->getOperand(0).getImm(); |
| 768 | if (Amount == 0) |
| 769 | return MBB.erase(I); |
| 770 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 771 | const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>(); |
Matt Arsenault | b62a4eb | 2017-08-01 19:54:18 +0000 | [diff] [blame] | 772 | const SIInstrInfo *TII = ST.getInstrInfo(); |
| 773 | const DebugLoc &DL = I->getDebugLoc(); |
| 774 | unsigned Opc = I->getOpcode(); |
| 775 | bool IsDestroy = Opc == TII->getCallFrameDestroyOpcode(); |
| 776 | uint64_t CalleePopAmount = IsDestroy ? I->getOperand(1).getImm() : 0; |
| 777 | |
| 778 | const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); |
| 779 | if (!TFI->hasReservedCallFrame(MF)) { |
| 780 | unsigned Align = getStackAlignment(); |
| 781 | |
| 782 | Amount = alignTo(Amount, Align); |
| 783 | assert(isUInt<32>(Amount) && "exceeded stack address space size"); |
| 784 | const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
| 785 | unsigned SPReg = MFI->getStackPtrOffsetReg(); |
| 786 | |
| 787 | unsigned Op = IsDestroy ? AMDGPU::S_SUB_U32 : AMDGPU::S_ADD_U32; |
| 788 | BuildMI(MBB, I, DL, TII->get(Op), SPReg) |
| 789 | .addReg(SPReg) |
| 790 | .addImm(Amount * ST.getWavefrontSize()); |
| 791 | } else if (CalleePopAmount != 0) { |
| 792 | llvm_unreachable("is this used?"); |
| 793 | } |
| 794 | |
| 795 | return MBB.erase(I); |
| 796 | } |
| 797 | |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 798 | bool SIFrameLowering::hasFP(const MachineFunction &MF) const { |
| 799 | // All stack operations are relative to the frame offset SGPR. |
| 800 | // TODO: Still want to eliminate sometimes. |
| 801 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
| 802 | |
| 803 | // XXX - Is this only called after frame is finalized? Should be able to check |
| 804 | // frame size. |
| 805 | return MFI.hasStackObjects() && !allStackObjectsAreDead(MFI); |
| 806 | } |
| 807 | |
| 808 | bool SIFrameLowering::hasSP(const MachineFunction &MF) const { |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 809 | const SIRegisterInfo *TRI = MF.getSubtarget<GCNSubtarget>().getRegisterInfo(); |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 810 | // All stack operations are relative to the frame offset SGPR. |
| 811 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
Matt Arsenault | 03ae399 | 2018-03-29 21:30:06 +0000 | [diff] [blame] | 812 | return MFI.hasCalls() || MFI.hasVarSizedObjects() || TRI->needsStackRealignment(MF); |
Matt Arsenault | f28683c | 2017-06-26 17:53:59 +0000 | [diff] [blame] | 813 | } |