Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 1 | //===----------------------- R600FrameLowering.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 | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 6 | // |
| 7 | //==-----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "R600FrameLowering.h" |
Konstantin Zhuravlyov | ffdb00e | 2017-03-10 19:39:07 +0000 | [diff] [blame] | 10 | #include "AMDGPUSubtarget.h" |
| 11 | #include "R600RegisterInfo.h" |
Konstantin Zhuravlyov | ffdb00e | 2017-03-10 19:39:07 +0000 | [diff] [blame] | 12 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/MachineFunction.h" |
Konstantin Zhuravlyov | ffdb00e | 2017-03-10 19:39:07 +0000 | [diff] [blame] | 14 | #include "llvm/Support/MathExtras.h" |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 15 | |
| 16 | using namespace llvm; |
| 17 | |
Eugene Zelenko | 6a9226d | 2016-12-12 22:23:53 +0000 | [diff] [blame] | 18 | R600FrameLowering::~R600FrameLowering() = default; |
Konstantin Zhuravlyov | ffdb00e | 2017-03-10 19:39:07 +0000 | [diff] [blame] | 19 | |
| 20 | /// \returns The number of registers allocated for \p FI. |
| 21 | int R600FrameLowering::getFrameIndexReference(const MachineFunction &MF, |
| 22 | int FI, |
| 23 | unsigned &FrameReg) const { |
| 24 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
| 25 | const R600RegisterInfo *RI |
| 26 | = MF.getSubtarget<R600Subtarget>().getRegisterInfo(); |
| 27 | |
| 28 | // Fill in FrameReg output argument. |
| 29 | FrameReg = RI->getFrameRegister(MF); |
| 30 | |
| 31 | // Start the offset at 2 so we don't overwrite work group information. |
| 32 | // FIXME: We should only do this when the shader actually uses this |
| 33 | // information. |
| 34 | unsigned OffsetBytes = 2 * (getStackWidth(MF) * 4); |
| 35 | int UpperBound = FI == -1 ? MFI.getNumObjects() : FI; |
| 36 | |
| 37 | for (int i = MFI.getObjectIndexBegin(); i < UpperBound; ++i) { |
| 38 | OffsetBytes = alignTo(OffsetBytes, MFI.getObjectAlignment(i)); |
| 39 | OffsetBytes += MFI.getObjectSize(i); |
| 40 | // Each register holds 4 bytes, so we must always align the offset to at |
| 41 | // least 4 bytes, so that 2 frame objects won't share the same register. |
| 42 | OffsetBytes = alignTo(OffsetBytes, 4); |
| 43 | } |
| 44 | |
| 45 | if (FI != -1) |
| 46 | OffsetBytes = alignTo(OffsetBytes, MFI.getObjectAlignment(FI)); |
| 47 | |
| 48 | return OffsetBytes / (getStackWidth(MF) * 4); |
| 49 | } |