LLVM  4.0.0
AMDGPUFrameLowering.cpp
Go to the documentation of this file.
1 //===----------------------- AMDGPUFrameLowering.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 // Interface to describe a layout of a stack frame on a AMDGPU target machine.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "AMDGPUFrameLowering.h"
15 #include "AMDGPURegisterInfo.h"
16 #include "AMDGPUSubtarget.h"
20 
21 using namespace llvm;
23  int LAO, unsigned TransAl)
24  : TargetFrameLowering(D, StackAl, LAO, TransAl) { }
25 
27 
29  // XXX: Hardcoding to 1 for now.
30  //
31  // I think the StackWidth should stored as metadata associated with the
32  // MachineFunction. This metadata can either be added by a frontend, or
33  // calculated by a R600 specific LLVM IR pass.
34  //
35  // The StackWidth determines how stack objects are laid out in memory.
36  // For a vector stack variable, like: int4 stack[2], the data will be stored
37  // in the following ways depending on the StackWidth.
38  //
39  // StackWidth = 1:
40  //
41  // T0.X = stack[0].x
42  // T1.X = stack[0].y
43  // T2.X = stack[0].z
44  // T3.X = stack[0].w
45  // T4.X = stack[1].x
46  // T5.X = stack[1].y
47  // T6.X = stack[1].z
48  // T7.X = stack[1].w
49  //
50  // StackWidth = 2:
51  //
52  // T0.X = stack[0].x
53  // T0.Y = stack[0].y
54  // T1.X = stack[0].z
55  // T1.Y = stack[0].w
56  // T2.X = stack[1].x
57  // T2.Y = stack[1].y
58  // T3.X = stack[1].z
59  // T3.Y = stack[1].w
60  //
61  // StackWidth = 4:
62  // T0.X = stack[0].x
63  // T0.Y = stack[0].y
64  // T0.Z = stack[0].z
65  // T0.W = stack[0].w
66  // T1.X = stack[1].x
67  // T1.Y = stack[1].y
68  // T1.Z = stack[1].z
69  // T1.W = stack[1].w
70  return 1;
71 }
72 
73 /// \returns The number of registers allocated for \p FI.
75  int FI,
76  unsigned &FrameReg) const {
77  const MachineFrameInfo &MFI = MF.getFrameInfo();
78  const AMDGPURegisterInfo *RI
79  = MF.getSubtarget<AMDGPUSubtarget>().getRegisterInfo();
80 
81  // Fill in FrameReg output argument.
82  FrameReg = RI->getFrameRegister(MF);
83 
84  // Start the offset at 2 so we don't overwrite work group information.
85  // XXX: We should only do this when the shader actually uses this
86  // information.
87  unsigned OffsetBytes = 2 * (getStackWidth(MF) * 4);
88  int UpperBound = FI == -1 ? MFI.getNumObjects() : FI;
89 
90  for (int i = MFI.getObjectIndexBegin(); i < UpperBound; ++i) {
91  OffsetBytes = alignTo(OffsetBytes, MFI.getObjectAlignment(i));
92  OffsetBytes += MFI.getObjectSize(i);
93  // Each register holds 4 bytes, so we must always align the offset to at
94  // least 4 bytes, so that 2 frame objects won't share the same register.
95  OffsetBytes = alignTo(OffsetBytes, 4);
96  }
97 
98  if (FI != -1)
99  OffsetBytes = alignTo(OffsetBytes, MFI.getObjectAlignment(FI));
100 
101  return OffsetBytes / (getStackWidth(MF) * 4);
102 }
AMDGPU specific subclass of TargetSubtarget.
size_t i
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:664
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
Interface to describe a layout of a stack frame on an AMDGPU target.
TargetRegisterInfo interface that is implemented by all hw codegen targets.
int getObjectIndexBegin() const
Return the minimum frame object index.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
AMDGPUFrameLowering(StackDirection D, unsigned StackAl, int LAO, unsigned TransAl=1)
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
Information about stack frame layout on the target.
unsigned getStackWidth(const MachineFunction &MF) const
unsigned getFrameRegister(const MachineFunction &MF) const override
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.