LLVM  8.0.1
R600FrameLowering.cpp
Go to the documentation of this file.
1 //===----------------------- R600FrameLowering.cpp ------------------------===//
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 
10 #include "R600FrameLowering.h"
11 #include "AMDGPUSubtarget.h"
12 #include "R600RegisterInfo.h"
16 
17 using namespace llvm;
18 
20 
21 /// \returns The number of registers allocated for \p FI.
23  int FI,
24  unsigned &FrameReg) const {
25  const MachineFrameInfo &MFI = MF.getFrameInfo();
26  const R600RegisterInfo *RI
27  = MF.getSubtarget<R600Subtarget>().getRegisterInfo();
28 
29  // Fill in FrameReg output argument.
30  FrameReg = RI->getFrameRegister(MF);
31 
32  // Start the offset at 2 so we don't overwrite work group information.
33  // FIXME: We should only do this when the shader actually uses this
34  // information.
35  unsigned OffsetBytes = 2 * (getStackWidth(MF) * 4);
36  int UpperBound = FI == -1 ? MFI.getNumObjects() : FI;
37 
38  for (int i = MFI.getObjectIndexBegin(); i < UpperBound; ++i) {
39  OffsetBytes = alignTo(OffsetBytes, MFI.getObjectAlignment(i));
40  OffsetBytes += MFI.getObjectSize(i);
41  // Each register holds 4 bytes, so we must always align the offset to at
42  // least 4 bytes, so that 2 frame objects won't share the same register.
43  OffsetBytes = alignTo(OffsetBytes, 4);
44  }
45 
46  if (FI != -1)
47  OffsetBytes = alignTo(OffsetBytes, MFI.getObjectAlignment(FI));
48 
49  return OffsetBytes / (getStackWidth(MF) * 4);
50 }
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
unsigned getNumObjects() const
Return the number of objects.
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:685
Interface definition for R600RegisterInfo.
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
int getObjectIndexBegin() const
Return the minimum frame object index.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
~R600FrameLowering() override
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
unsigned getFrameRegister(const MachineFunction &MF) const override
unsigned getStackWidth(const MachineFunction &MF) const