summaryrefslogtreecommitdiff
path: root/lib/Target/R600/SIMachineFunctionInfo.h
blob: 1b004fd023882c6f4a27c3102af00c008385d5a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//===- SIMachineFunctionInfo.h - SIMachineFunctionInfo interface -*- C++ -*-==//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
/// \file
//
//===----------------------------------------------------------------------===//


#ifndef SIMACHINEFUNCTIONINFO_H_
#define SIMACHINEFUNCTIONINFO_H_

#include "AMDGPUMachineFunction.h"
#include <map>

namespace llvm {

class MachineRegisterInfo;

/// This class keeps track of the SPI_SP_INPUT_ADDR config register, which
/// tells the hardware which interpolation parameters to load.
class SIMachineFunctionInfo : public AMDGPUMachineFunction {
  void anchor() override;

  unsigned SpillTIDVirtualReg;

public:

  struct SpilledReg {
    unsigned VGPR;
    int Lane;
    SpilledReg(unsigned R, int L) : VGPR (R), Lane (L) { }
    SpilledReg() : VGPR(0), Lane(-1) { }
    bool hasLane() { return Lane != -1;}
  };

  struct RegSpillTracker {
  private:
    unsigned CurrentLane;
    std::map<unsigned, SpilledReg> SpilledRegisters;
  public:
    unsigned LaneVGPR;
    RegSpillTracker() : CurrentLane(0), SpilledRegisters(), LaneVGPR(0) { }
    /// \p NumRegs The number of consecutive registers what need to be spilled.
    ///            This function will ensure that all registers are stored in
    ///            the same VGPR.
    /// \returns The lane to be used for storing the first register.
    unsigned reserveLanes(MachineRegisterInfo &MRI, MachineFunction *MF,
                          unsigned NumRegs = 1);
    void addSpilledReg(unsigned FrameIndex, unsigned Reg, int Lane = -1);
    const SpilledReg& getSpilledReg(unsigned FrameIndex);
    bool programSpillsRegisters() { return !SpilledRegisters.empty(); }
  };

  // SIMachineFunctionInfo definition

  SIMachineFunctionInfo(const MachineFunction &MF);
  unsigned PSInputAddr;
  struct RegSpillTracker SpillTracker;
  unsigned LDSWaveSpillSize;
  bool HasCalculatedTIDOffset;
  /// Key is FrameIndex, value is byte offset
  std::map<unsigned, unsigned> LDSSpillOffsets;
  unsigned getSpillTIDVirtualReg(MachineRegisterInfo &MRI, MachineFunction *MF);
  /// Returns the wave local offset for this \p FrameIndex
  unsigned allocateLDSSpaceForSpill(unsigned FrameIndex,  unsigned NumBytes);
};

} // End namespace llvm


#endif //_SIMACHINEFUNCTIONINFO_H_