Skip to content

Commit 264f3dc

Browse files
committed
Address Review comments
Change-Id: I7df86a09024b78c48e728119d42c2d3d812bbebd
1 parent 1f0d0c6 commit 264f3dc

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

llvm/lib/Target/AMDGPU/SIRegisterInfo.td

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,21 @@ class SIRegisterClass <string n, list<ValueType> rTypes, int Align, dag rList>
110110
let TSFlags{3} = HasAGPR;
111111
let TSFlags{4} = HasSGPR;
112112

113-
// RegisterClass (e.g. AGPR / VGPR) priority for allocation
114-
field int RegClassPriority = 1;
115-
field int RegClassBit = 5;
113+
// RA will use RegisterClass AllocationPriority amongst other info (e.g. ordering in the basic block)
114+
// to decide which registers to try to assign first. Usually, this RegisterClass priority is given
115+
// very high priority, if not the highest priority, when considering which VirtReg to allocate next.
116+
//
117+
// We have 5 bits to assign AllocationPriorities to RegisterClasses. Generally, it is beneficial to
118+
// assign more constrained RegisterClasses first. As a result, we prioritize larger register classes
119+
// over smaller register classes.
120+
//
121+
// The interesting case is the vector register case on architectures which have ARegs, VRegs, AVRegs.
122+
// In this case, we would like to assign ARegs and VRegs before AVRegs, as AVRegs are less constrained
123+
// and can be assigned to both AGPRs and VGPRs. We use the 5th bit to encode this into the
124+
// RegisterClass AllocationPriority. BaseClassPriority is used to turn the bit on, and BaseClassScaleFactor
125+
// is used for scaling of the bit (i.e. 1 << 4).
126+
field int BaseClassPriority = 1;
127+
field int BaseClassScaleFactor = 16;
116128

117129
}
118130

@@ -579,7 +591,7 @@ let HasVGPR = 1 in {
579591
def VGPR_16 : SIRegisterClass<"AMDGPU", Reg16Types.types, 16,
580592
(add (interleave (sequence "VGPR%u_LO16", 0, 255),
581593
(sequence "VGPR%u_HI16", 0, 255)))> {
582-
let AllocationPriority = !add(2, !mul(RegClassPriority, !shl(1, RegClassBit)));
594+
let AllocationPriority = !add(2, !mul(BaseClassPriority, BaseClassScaleFactor));
583595
let Size = 16;
584596
let GeneratePressureSet = 0;
585597

@@ -605,7 +617,7 @@ def VGPR_16_Lo128 : SIRegisterClass<"AMDGPU", Reg16Types.types, 16,
605617
// i16/f16 only on VI+
606618
def VGPR_32 : SIRegisterClass<"AMDGPU", !listconcat(Reg32Types.types, Reg16Types.types), 32,
607619
(add (sequence "VGPR%u", 0, 255))> {
608-
let AllocationPriority = !add(0, !mul(RegClassPriority, !shl(1, RegClassBit)));
620+
let AllocationPriority = !add(0, !mul(BaseClassPriority, BaseClassScaleFactor));
609621
let Size = 32;
610622
let Weight = 1;
611623
let BaseClassOrder = 32;
@@ -614,7 +626,7 @@ def VGPR_32 : SIRegisterClass<"AMDGPU", !listconcat(Reg32Types.types, Reg16Types
614626
// Identical to VGPR_32 except it only contains the low 128 (Lo128) registers.
615627
def VGPR_32_Lo128 : SIRegisterClass<"AMDGPU", !listconcat(Reg32Types.types, Reg16Types.types), 32,
616628
(add (sequence "VGPR%u", 0, 127))> {
617-
let AllocationPriority = !add(0, !mul(RegClassPriority, !shl(1, RegClassBit)));
629+
let AllocationPriority = !add(0, !mul(BaseClassPriority, BaseClassScaleFactor));
618630
let GeneratePressureSet = 0;
619631
let Size = 32;
620632
let Weight = 1;
@@ -944,15 +956,23 @@ class VRegClassBase<int numRegs, list<ValueType> regTypes, dag regList> :
944956

945957
// Requires n v_mov_b32 to copy
946958
let CopyCost = numRegs;
959+
960+
// Since we only have 5 bits for the RegisterClass Allocation Priorty, and since we use the
961+
// 5th bit for BaseClassPriority, we need to encode the SizePriority into 4 bits. As a result
962+
// of this encoding, for registers with numRegs 15 or 16, we give SizePriority of 14, and for
963+
// regsters with numRegs 17+ we give SizePriority of 15. In practice, there is only one
964+
// RegClass per Vector Register type in each of these groups (i.e. numRegs = 15,16 : {VReg_512},
965+
// and numRegs = 17+ : {VReg_1024}). Therefore, we have not lost any info by compressing.
947966
defvar SizePrioriity = !if(!le(numRegs, 14), !sub(numRegs, 1), !if(!le(numRegs, 16), 14, 15));
948-
let AllocationPriority = !add(SizePrioriity, !mul(RegClassPriority, !shl(1, RegClassBit)));
967+
968+
let AllocationPriority = !add(SizePrioriity, !mul(BaseClassPriority, BaseClassScaleFactor));
949969
let Weight = numRegs;
950970
}
951971

952972
// Define a register tuple class, along with one requiring an even
953973
// aligned base register.
954974
multiclass VRegClass<int numRegs, list<ValueType> regTypes, dag regList> {
955-
let HasVGPR = 1, RegClassPriority = 1 in {
975+
let HasVGPR = 1, BaseClassPriority = 1 in {
956976
// Define the regular class.
957977
def "" : VRegClassBase<numRegs, regTypes, regList> {
958978
let BaseClassOrder = !mul(numRegs, 32);
@@ -986,7 +1006,7 @@ defm VReg_1024 : VRegClass<32, Reg1024Types.types, (add VGPR_1024)>;
9861006
}
9871007

9881008
multiclass ARegClass<int numRegs, list<ValueType> regTypes, dag regList> {
989-
let CopyCost = !add(numRegs, numRegs, 1), HasAGPR = 1, RegClassPriority = 1 in {
1009+
let CopyCost = !add(numRegs, numRegs, 1), HasAGPR = 1, BaseClassPriority = 1 in {
9901010
// Define the regular class.
9911011
def "" : VRegClassBase<numRegs, regTypes, regList> {
9921012
let BaseClassOrder = !mul(numRegs, 32);
@@ -1071,7 +1091,7 @@ def VS_64 : SIRegisterClass<"AMDGPU", VReg_64.RegTypes, 32, (add VReg_64, SReg_6
10711091
def AV_32 : SIRegisterClass<"AMDGPU", VGPR_32.RegTypes, 32, (add VGPR_32, AGPR_32)> {
10721092
let HasVGPR = 1;
10731093
let HasAGPR = 1;
1074-
let RegClassPriority = 0;
1094+
let BaseClassPriority = 0;
10751095
let Size = 32;
10761096
}
10771097
} // End GeneratePressureSet = 0
@@ -1080,7 +1100,7 @@ def AV_32 : SIRegisterClass<"AMDGPU", VGPR_32.RegTypes, 32, (add VGPR_32, AGPR_3
10801100
// aligned base register.
10811101
multiclass AVRegClass<int numRegs, list<ValueType> regTypes,
10821102
dag vregList, dag aregList> {
1083-
let HasVGPR = 1, HasAGPR = 1, RegClassPriority = 0 in {
1103+
let HasVGPR = 1, HasAGPR = 1, BaseClassPriority = 0 in {
10841104
// Define the regular class.
10851105
def "" : VRegClassBase<numRegs, regTypes, (add vregList, aregList)>;
10861106

0 commit comments

Comments
 (0)