2012-12-11 22:25:42 +01:00
|
|
|
//===-- SIRegisterInfo.h - SI Register Info Interface ----------*- C++ -*--===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
/// \brief Interface definition for SIRegisterInfo
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-11 09:00:27 +01:00
|
|
|
#ifndef LLVM_LIB_TARGET_AMDGPU_SIREGISTERINFO_H
|
|
|
|
#define LLVM_LIB_TARGET_AMDGPU_SIREGISTERINFO_H
|
2012-12-11 22:25:42 +01:00
|
|
|
|
|
|
|
#include "AMDGPURegisterInfo.h"
|
2015-12-01 20:57:17 +01:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-12-11 22:25:42 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2016-06-24 08:30:11 +02:00
|
|
|
class SISubtarget;
|
|
|
|
class MachineRegisterInfo;
|
|
|
|
|
2016-08-29 22:42:07 +02:00
|
|
|
class SIRegisterInfo final : public AMDGPURegisterInfo {
|
2015-08-26 20:54:50 +02:00
|
|
|
private:
|
2016-08-26 23:16:37 +02:00
|
|
|
unsigned SGPRSetID;
|
|
|
|
unsigned VGPRSetID;
|
2016-03-23 02:53:22 +01:00
|
|
|
BitVector SGPRPressureSets;
|
|
|
|
BitVector VGPRPressureSets;
|
2016-01-13 17:10:10 +01:00
|
|
|
|
2015-08-26 20:54:50 +02:00
|
|
|
void reserveRegisterTuples(BitVector &, unsigned Reg) const;
|
2016-03-23 02:53:22 +01:00
|
|
|
void classifyPressureSet(unsigned PSetID, unsigned Reg,
|
|
|
|
BitVector &PressureSets) const;
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2015-08-26 20:54:50 +02:00
|
|
|
public:
|
2015-03-11 19:43:21 +01:00
|
|
|
SIRegisterInfo();
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2015-11-30 22:16:03 +01:00
|
|
|
/// Return the end register initially reserved for the scratch buffer in case
|
|
|
|
/// spilling is needed.
|
|
|
|
unsigned reservedPrivateSegmentBufferReg(const MachineFunction &MF) const;
|
|
|
|
|
|
|
|
/// Return the end register initially reserved for the scratch wave offset in
|
|
|
|
/// case spilling is needed.
|
|
|
|
unsigned reservedPrivateSegmentWaveByteOffsetReg(
|
|
|
|
const MachineFunction &MF) const;
|
|
|
|
|
2014-04-29 09:57:24 +02:00
|
|
|
BitVector getReservedRegs(const MachineFunction &MF) const override;
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2014-07-21 17:45:01 +02:00
|
|
|
bool requiresRegisterScavenging(const MachineFunction &Fn) const override;
|
|
|
|
|
2016-04-16 04:13:37 +02:00
|
|
|
|
2016-03-04 19:02:01 +01:00
|
|
|
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override;
|
2016-04-16 04:13:37 +02:00
|
|
|
bool requiresVirtualBaseRegisters(const MachineFunction &Fn) const override;
|
2016-07-12 01:56:30 +02:00
|
|
|
bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override;
|
2016-04-16 04:13:37 +02:00
|
|
|
|
|
|
|
int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
|
|
|
|
int Idx) const override;
|
|
|
|
|
|
|
|
bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
|
|
|
|
|
|
|
|
void materializeFrameBaseRegister(MachineBasicBlock *MBB,
|
|
|
|
unsigned BaseReg, int FrameIdx,
|
|
|
|
int64_t Offset) const override;
|
|
|
|
|
|
|
|
void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg,
|
|
|
|
int64_t Offset) const override;
|
|
|
|
|
|
|
|
bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg,
|
|
|
|
int64_t Offset) const override;
|
|
|
|
|
|
|
|
const TargetRegisterClass *getPointerRegClass(
|
|
|
|
const MachineFunction &MF, unsigned Kind = 0) const override;
|
2016-03-04 19:02:01 +01:00
|
|
|
|
2016-10-04 03:14:56 +02:00
|
|
|
void spillSGPR(MachineBasicBlock::iterator MI,
|
|
|
|
int FI, RegScavenger *RS) const;
|
|
|
|
|
|
|
|
void restoreSGPR(MachineBasicBlock::iterator MI,
|
|
|
|
int FI, RegScavenger *RS) const;
|
|
|
|
|
2014-07-21 17:45:01 +02:00
|
|
|
void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,
|
|
|
|
unsigned FIOperandNum,
|
|
|
|
RegScavenger *RS) const override;
|
|
|
|
|
2016-06-24 08:30:11 +02:00
|
|
|
unsigned getHWRegIndex(unsigned Reg) const {
|
|
|
|
return getEncodingValue(Reg) & 0xff;
|
|
|
|
}
|
2013-11-14 00:36:50 +01:00
|
|
|
|
2013-08-07 01:08:18 +02:00
|
|
|
/// \brief Return the 'base' register class for this register.
|
2015-01-07 21:59:25 +01:00
|
|
|
/// e.g. SGPR0 => SReg_32, VGPR => VGPR_32 SGPR0_SGPR1 -> SReg_32, etc.
|
2013-08-07 01:08:18 +02:00
|
|
|
const TargetRegisterClass *getPhysRegClass(unsigned Reg) const;
|
2013-08-15 01:24:24 +02:00
|
|
|
|
|
|
|
/// \returns true if this class contains only SGPR registers
|
2014-09-24 04:17:12 +02:00
|
|
|
bool isSGPRClass(const TargetRegisterClass *RC) const {
|
|
|
|
return !hasVGPRs(RC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \returns true if this class ID contains only SGPR registers
|
|
|
|
bool isSGPRClassID(unsigned RCID) const {
|
|
|
|
return isSGPRClass(getRegClass(RCID));
|
|
|
|
}
|
2013-11-14 00:36:37 +01:00
|
|
|
|
2015-12-01 20:57:17 +01:00
|
|
|
bool isSGPRReg(const MachineRegisterInfo &MRI, unsigned Reg) const {
|
2016-03-21 21:28:33 +01:00
|
|
|
const TargetRegisterClass *RC;
|
2015-12-01 20:57:17 +01:00
|
|
|
if (TargetRegisterInfo::isVirtualRegister(Reg))
|
2016-03-21 21:28:33 +01:00
|
|
|
RC = MRI.getRegClass(Reg);
|
|
|
|
else
|
|
|
|
RC = getPhysRegClass(Reg);
|
|
|
|
return isSGPRClass(RC);
|
2015-12-01 20:57:17 +01:00
|
|
|
}
|
|
|
|
|
2013-11-14 00:36:37 +01:00
|
|
|
/// \returns true if this class contains VGPR registers.
|
|
|
|
bool hasVGPRs(const TargetRegisterClass *RC) const;
|
|
|
|
|
|
|
|
/// \returns A VGPR reg class with the same width as \p SRC
|
|
|
|
const TargetRegisterClass *getEquivalentVGPRClass(
|
|
|
|
const TargetRegisterClass *SRC) const;
|
|
|
|
|
2016-02-11 22:45:07 +01:00
|
|
|
/// \returns A SGPR reg class with the same width as \p SRC
|
|
|
|
const TargetRegisterClass *getEquivalentSGPRClass(
|
|
|
|
const TargetRegisterClass *VRC) const;
|
|
|
|
|
2013-11-14 00:36:37 +01:00
|
|
|
/// \returns The register class that is used for a sub-register of \p RC for
|
|
|
|
/// the given \p SubIdx. If \p SubIdx equals NoSubRegister, \p RC will
|
|
|
|
/// be returned.
|
|
|
|
const TargetRegisterClass *getSubRegClass(const TargetRegisterClass *RC,
|
|
|
|
unsigned SubIdx) const;
|
2014-05-02 17:41:42 +02:00
|
|
|
|
2015-09-24 10:36:14 +02:00
|
|
|
bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
|
|
|
|
unsigned DefSubReg,
|
|
|
|
const TargetRegisterClass *SrcRC,
|
|
|
|
unsigned SrcSubReg) const override;
|
|
|
|
|
2015-01-12 20:33:18 +01:00
|
|
|
/// \returns True if operands defined with this operand type can accept
|
2014-09-23 23:26:25 +02:00
|
|
|
/// a literal constant (i.e. any 32-bit immediate).
|
2015-01-12 20:33:18 +01:00
|
|
|
bool opCanUseLiteralConstant(unsigned OpType) const;
|
2014-07-02 22:53:44 +02:00
|
|
|
|
2015-01-12 20:33:18 +01:00
|
|
|
/// \returns True if operands defined with this operand type can accept
|
2014-09-23 23:26:25 +02:00
|
|
|
/// an inline constant. i.e. An integer value in the range (-16, 64) or
|
2015-11-30 22:15:57 +01:00
|
|
|
/// -4.0f, -2.0f, -1.0f, -0.5f, 0.0f, 0.5f, 1.0f, 2.0f, 4.0f.
|
2015-01-12 20:33:18 +01:00
|
|
|
bool opCanUseInlineConstant(unsigned OpType) const;
|
2014-07-21 17:45:01 +02:00
|
|
|
|
|
|
|
enum PreloadedValue {
|
2015-10-01 04:02:46 +02:00
|
|
|
// SGPRS:
|
2016-02-12 07:31:30 +01:00
|
|
|
PRIVATE_SEGMENT_BUFFER = 0,
|
2015-11-26 01:43:29 +01:00
|
|
|
DISPATCH_PTR = 1,
|
2015-11-30 22:15:57 +01:00
|
|
|
QUEUE_PTR = 2,
|
|
|
|
KERNARG_SEGMENT_PTR = 3,
|
2016-02-12 07:31:30 +01:00
|
|
|
DISPATCH_ID = 4,
|
|
|
|
FLAT_SCRATCH_INIT = 5,
|
2015-11-30 22:15:57 +01:00
|
|
|
WORKGROUP_ID_X = 10,
|
|
|
|
WORKGROUP_ID_Y = 11,
|
|
|
|
WORKGROUP_ID_Z = 12,
|
|
|
|
PRIVATE_SEGMENT_WAVE_BYTE_OFFSET = 14,
|
|
|
|
|
2015-10-01 04:02:46 +02:00
|
|
|
// VGPRS:
|
|
|
|
FIRST_VGPR_VALUE = 15,
|
2015-11-30 22:15:57 +01:00
|
|
|
WORKITEM_ID_X = FIRST_VGPR_VALUE,
|
|
|
|
WORKITEM_ID_Y = 16,
|
|
|
|
WORKITEM_ID_Z = 17
|
2014-07-21 17:45:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Returns the physical register that \p Value is stored in.
|
|
|
|
unsigned getPreloadedValue(const MachineFunction &MF,
|
|
|
|
enum PreloadedValue Value) const;
|
|
|
|
|
2015-01-14 16:42:31 +01:00
|
|
|
unsigned findUnusedRegister(const MachineRegisterInfo &MRI,
|
2016-07-28 16:30:43 +02:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const MachineFunction &MF) const;
|
2015-01-14 16:42:31 +01:00
|
|
|
|
2016-08-26 23:16:37 +02:00
|
|
|
unsigned getSGPRPressureSet() const { return SGPRSetID; };
|
|
|
|
unsigned getVGPRPressureSet() const { return VGPRSetID; };
|
2016-01-13 17:10:10 +01:00
|
|
|
|
2016-04-30 02:23:06 +02:00
|
|
|
bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const;
|
|
|
|
|
2016-08-26 23:16:37 +02:00
|
|
|
bool isSGPRPressureSet(unsigned SetID) const {
|
|
|
|
return SGPRPressureSets.test(SetID) && !VGPRPressureSets.test(SetID);
|
|
|
|
}
|
|
|
|
bool isVGPRPressureSet(unsigned SetID) const {
|
|
|
|
return VGPRPressureSets.test(SetID) && !SGPRPressureSets.test(SetID);
|
|
|
|
}
|
|
|
|
|
2016-09-06 22:22:28 +02:00
|
|
|
/// \returns SGPR allocation granularity supported by the subtarget.
|
|
|
|
unsigned getSGPRAllocGranule() const {
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \returns Total number of SGPRs supported by the subtarget.
|
|
|
|
unsigned getTotalNumSGPRs(const SISubtarget &ST) const;
|
|
|
|
|
|
|
|
/// \returns Number of addressable SGPRs supported by the subtarget.
|
|
|
|
unsigned getNumAddressableSGPRs(const SISubtarget &ST) const;
|
|
|
|
|
|
|
|
/// \returns Number of reserved SGPRs supported by the subtarget.
|
|
|
|
unsigned getNumReservedSGPRs(const SISubtarget &ST) const;
|
|
|
|
|
|
|
|
/// \returns Minimum number of SGPRs that meets given number of waves per
|
|
|
|
/// execution unit requirement for given subtarget.
|
|
|
|
unsigned getMinNumSGPRs(const SISubtarget &ST, unsigned WavesPerEU) const;
|
|
|
|
|
|
|
|
/// \returns Maximum number of SGPRs that meets given number of waves per
|
|
|
|
/// execution unit requirement for given subtarget.
|
|
|
|
unsigned getMaxNumSGPRs(const SISubtarget &ST, unsigned WavesPerEU) const;
|
|
|
|
|
|
|
|
/// \returns Maximum number of SGPRs that meets number of waves per execution
|
|
|
|
/// unit requirement for function \p MF, or number of SGPRs explicitly
|
|
|
|
/// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
|
|
|
|
///
|
|
|
|
/// \returns Value that meets number of waves per execution unit requirement
|
|
|
|
/// if explicitly requested value cannot be converted to integer, violates
|
|
|
|
/// subtarget's specifications, or does not meet number of waves per execution
|
|
|
|
/// unit requirement.
|
|
|
|
unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
|
|
|
|
|
|
|
|
/// \returns VGPR allocation granularity supported by the subtarget.
|
|
|
|
unsigned getVGPRAllocGranule() const {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \returns Total number of VGPRs supported by the subtarget.
|
|
|
|
unsigned getTotalNumVGPRs() const {
|
|
|
|
return 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \returns Number of reserved VGPRs for debugger use supported by the
|
|
|
|
/// subtarget.
|
|
|
|
unsigned getNumDebuggerReservedVGPRs(const SISubtarget &ST) const;
|
|
|
|
|
|
|
|
/// \returns Minimum number of SGPRs that meets given number of waves per
|
|
|
|
/// execution unit requirement.
|
|
|
|
unsigned getMinNumVGPRs(unsigned WavesPerEU) const;
|
|
|
|
|
|
|
|
/// \returns Maximum number of VGPRs that meets given number of waves per
|
|
|
|
/// execution unit requirement.
|
|
|
|
unsigned getMaxNumVGPRs(unsigned WavesPerEU) const;
|
|
|
|
|
|
|
|
/// \returns Maximum number of VGPRs that meets number of waves per execution
|
|
|
|
/// unit requirement for function \p MF, or number of VGPRs explicitly
|
|
|
|
/// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
|
|
|
|
///
|
|
|
|
/// \returns Value that meets number of waves per execution unit requirement
|
|
|
|
/// if explicitly requested value cannot be converted to integer, violates
|
|
|
|
/// subtarget's specifications, or does not meet number of waves per execution
|
|
|
|
/// unit requirement.
|
|
|
|
unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
|
|
|
|
|
2016-11-07 17:39:22 +01:00
|
|
|
ArrayRef<int16_t> getRegSplitParts(const TargetRegisterClass *RC,
|
|
|
|
unsigned EltSize) const;
|
|
|
|
|
2015-01-14 16:42:31 +01:00
|
|
|
private:
|
2016-10-26 17:08:16 +02:00
|
|
|
void buildSpillLoadStore(MachineBasicBlock::iterator MI,
|
|
|
|
unsigned LoadStoreOp, const MachineOperand *SrcDst,
|
|
|
|
unsigned ScratchRsrcReg, unsigned ScratchOffset,
|
|
|
|
int64_t Offset,
|
|
|
|
RegScavenger *RS) const;
|
2012-12-11 22:25:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End namespace llvm
|
|
|
|
|
2014-08-13 18:26:38 +02:00
|
|
|
#endif
|