10b57cec5SDimitry Andric //===----------------------- R600FrameLowering.cpp ------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //==-----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "R600FrameLowering.h"
10e8d8bef9SDimitry Andric #include "R600Subtarget.h"
11*81ad6265SDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h"
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric using namespace llvm;
140b57cec5SDimitry Andric
150b57cec5SDimitry Andric R600FrameLowering::~R600FrameLowering() = default;
160b57cec5SDimitry Andric
170b57cec5SDimitry Andric /// \returns The number of registers allocated for \p FI.
18e8d8bef9SDimitry Andric StackOffset
getFrameIndexReference(const MachineFunction & MF,int FI,Register & FrameReg) const19e8d8bef9SDimitry Andric R600FrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
205ffd83dbSDimitry Andric Register &FrameReg) const {
210b57cec5SDimitry Andric const MachineFrameInfo &MFI = MF.getFrameInfo();
220b57cec5SDimitry Andric const R600RegisterInfo *RI
230b57cec5SDimitry Andric = MF.getSubtarget<R600Subtarget>().getRegisterInfo();
240b57cec5SDimitry Andric
250b57cec5SDimitry Andric // Fill in FrameReg output argument.
260b57cec5SDimitry Andric FrameReg = RI->getFrameRegister(MF);
270b57cec5SDimitry Andric
280b57cec5SDimitry Andric // Start the offset at 2 so we don't overwrite work group information.
290b57cec5SDimitry Andric // FIXME: We should only do this when the shader actually uses this
300b57cec5SDimitry Andric // information.
310b57cec5SDimitry Andric unsigned OffsetBytes = 2 * (getStackWidth(MF) * 4);
320b57cec5SDimitry Andric int UpperBound = FI == -1 ? MFI.getNumObjects() : FI;
330b57cec5SDimitry Andric
340b57cec5SDimitry Andric for (int i = MFI.getObjectIndexBegin(); i < UpperBound; ++i) {
355ffd83dbSDimitry Andric OffsetBytes = alignTo(OffsetBytes, MFI.getObjectAlign(i));
360b57cec5SDimitry Andric OffsetBytes += MFI.getObjectSize(i);
370b57cec5SDimitry Andric // Each register holds 4 bytes, so we must always align the offset to at
380b57cec5SDimitry Andric // least 4 bytes, so that 2 frame objects won't share the same register.
395ffd83dbSDimitry Andric OffsetBytes = alignTo(OffsetBytes, Align(4));
400b57cec5SDimitry Andric }
410b57cec5SDimitry Andric
420b57cec5SDimitry Andric if (FI != -1)
435ffd83dbSDimitry Andric OffsetBytes = alignTo(OffsetBytes, MFI.getObjectAlign(FI));
440b57cec5SDimitry Andric
45e8d8bef9SDimitry Andric return StackOffset::getFixed(OffsetBytes / (getStackWidth(MF) * 4));
460b57cec5SDimitry Andric }
47