1 #===-- SIGenRegisterInfo.pl - Script for generating register info files ----===#
3 # The LLVM Compiler Infrastructure
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
8 #===------------------------------------------------------------------------===#
10 # This perl script prints to stdout .td code to be used as SIRegisterInfo.td
11 # it also generates a file called SIHwRegInfo.include, which contains helper
12 # functions for determining the hw encoding of registers.
14 #===------------------------------------------------------------------------===#
22 my $SGPR_MAX_IDX = $SGPR_COUNT - 1;
23 my $VGPR_MAX_IDX = $VGPR_COUNT - 1;
25 my $INDEX_FILE = defined($ARGV[0]) ? $ARGV[0] : '';
29 let Namespace = "AMDGPU" in {
30 def low : SubRegIndex;
31 def high : SubRegIndex;
33 def sub0 : SubRegIndex;
34 def sub1 : SubRegIndex;
35 def sub2 : SubRegIndex;
36 def sub3 : SubRegIndex;
37 def sub4 : SubRegIndex;
38 def sub5 : SubRegIndex;
39 def sub6 : SubRegIndex;
40 def sub7 : SubRegIndex;
43 class SIReg <string n, bits<16> encoding = 0> : Register<n> {
44 let Namespace = "AMDGPU";
45 let HWEncoding = encoding;
48 class SI_64 <string n, list<Register> subregs, bits<16> encoding> : RegisterWithSubRegs<n, subregs> {
49 let Namespace = "AMDGPU";
50 let SubRegIndices = [low, high];
51 let HWEncoding = encoding;
54 class SI_128 <string n, list<Register> subregs, bits<16> encoding> : RegisterWithSubRegs<n, subregs> {
55 let Namespace = "AMDGPU";
56 let SubRegIndices = [sel_x, sel_y, sel_z, sel_w];
57 let HWEncoding = encoding;
60 class SI_256 <string n, list<Register> subregs, bits<16> encoding> : RegisterWithSubRegs<n, subregs> {
61 let Namespace = "AMDGPU";
62 let SubRegIndices = [sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7];
63 let HWEncoding = encoding;
66 class SGPR_32 <bits<16> num, string name> : SIReg<name, num>;
68 class VGPR_32 <bits<16> num, string name> : SIReg<name, num>;
70 class SGPR_64 <bits<16> num, string name, list<Register> subregs> :
71 SI_64 <name, subregs, num>;
73 class VGPR_64 <bits<16> num, string name, list<Register> subregs> :
74 SI_64 <name, subregs, num>;
76 class SGPR_128 <bits<16> num, string name, list<Register> subregs> :
77 SI_128 <name, subregs, num>;
79 class VGPR_128 <bits<16> num, string name, list<Register> subregs> :
80 SI_128 <name, subregs, num>;
82 class SGPR_256 <bits<16> num, string name, list<Register> subregs> :
83 SI_256 <name, subregs, num>;
85 def VCC : SIReg<"VCC">;
86 def SCC : SIReg<"SCC">;
87 def SREG_LIT_0 : SIReg <"S LIT 0", 128>;
89 def M0 : SIReg <"M0", 124>;
91 //Interpolation registers
93 def PERSP_SAMPLE_I : SIReg <"PERSP_SAMPLE_I">;
94 def PERSP_SAMPLE_J : SIReg <"PERSP_SAMPLE_J">;
95 def PERSP_CENTER_I : SIReg <"PERSP_CENTER_I">;
96 def PERSP_CENTER_J : SIReg <"PERSP_CENTER_J">;
97 def PERSP_CENTROID_I : SIReg <"PERSP_CENTROID_I">;
98 def PERSP_CENTROID_J : SIReg <"PERP_CENTROID_J">;
99 def PERSP_I_W : SIReg <"PERSP_I_W">;
100 def PERSP_J_W : SIReg <"PERSP_J_W">;
101 def PERSP_1_W : SIReg <"PERSP_1_W">;
102 def LINEAR_SAMPLE_I : SIReg <"LINEAR_SAMPLE_I">;
103 def LINEAR_SAMPLE_J : SIReg <"LINEAR_SAMPLE_J">;
104 def LINEAR_CENTER_I : SIReg <"LINEAR_CENTER_I">;
105 def LINEAR_CENTER_J : SIReg <"LINEAR_CENTER_J">;
106 def LINEAR_CENTROID_I : SIReg <"LINEAR_CENTROID_I">;
107 def LINEAR_CENTROID_J : SIReg <"LINEAR_CENTROID_J">;
108 def LINE_STIPPLE_TEX_COORD : SIReg <"LINE_STIPPLE_TEX_COORD">;
109 def POS_X_FLOAT : SIReg <"POS_X_FLOAT">;
110 def POS_Y_FLOAT : SIReg <"POS_Y_FLOAT">;
111 def POS_Z_FLOAT : SIReg <"POS_Z_FLOAT">;
112 def POS_W_FLOAT : SIReg <"POS_W_FLOAT">;
113 def FRONT_FACE : SIReg <"FRONT_FACE">;
114 def ANCILLARY : SIReg <"ANCILLARY">;
115 def SAMPLE_COVERAGE : SIReg <"SAMPLE_COVERAGE">;
116 def POS_FIXED_PT : SIReg <"POS_FIXED_PT">;
123 for (my $i = 0; $i < $SGPR_COUNT; $i++) {
124 print "def SGPR$i : SGPR_32 <$i, \"SGPR$i\">;\n";
125 $SGPR[$i] = "SGPR$i";
129 for (my $i = 0; $i < $VGPR_COUNT; $i++) {
130 print "def VGPR$i : VGPR_32 <$i, \"VGPR$i\">;\n";
131 $VGPR[$i] = "VGPR$i";
136 def SReg_32 : RegisterClass<"AMDGPU", [f32, i32], 32,
137 (add (sequence "SGPR%u", 0, $SGPR_MAX_IDX), SREG_LIT_0, M0)
140 def VReg_32 : RegisterClass<"AMDGPU", [f32, i32], 32,
141 (add (sequence "VGPR%u", 0, $VGPR_MAX_IDX),
142 PERSP_SAMPLE_I, PERSP_SAMPLE_J,
143 PERSP_CENTER_I, PERSP_CENTER_J,
144 PERSP_CENTROID_I, PERSP_CENTROID_J,
145 PERSP_I_W, PERSP_J_W, PERSP_1_W,
146 LINEAR_SAMPLE_I, LINEAR_SAMPLE_J,
147 LINEAR_CENTER_I, LINEAR_CENTER_J,
148 LINEAR_CENTROID_I, LINEAR_CENTROID_J,
149 LINE_STIPPLE_TEX_COORD,
161 def AllReg_32 : RegisterClass<"AMDGPU", [f32, i32], 32,
162 (add VReg_32, SReg_32)
165 def CCReg : RegisterClass<"AMDGPU", [f32], 32, (add VCC, SCC)>;
169 my @subregs_64 = ('low', 'high');
170 my @subregs_128 = ('sel_x', 'sel_y', 'sel_z', 'sel_w');
171 my @subregs_256 = ('sub0', 'sub1', 'sub2', 'sub3', 'sub4', 'sub5', 'sub6', 'sub7');
173 my @SGPR64 = print_sgpr_class(64, \@subregs_64, ('i64'));
174 my @SGPR128 = print_sgpr_class(128, \@subregs_128, ('v4f32', 'v4i32'));
175 my @SGPR256 = print_sgpr_class(256, \@subregs_256, ('v8i32'));
177 my @VGPR64 = print_vgpr_class(64, \@subregs_64, ('i64'));
178 my @VGPR128 = print_vgpr_class(128, \@subregs_128, ('v4f32'));
181 my $sgpr64_list = join(',', @SGPR64);
182 my $vgpr64_list = join(',', @VGPR64);
185 def AllReg_64 : RegisterClass<"AMDGPU", [f64, i64], 64,
186 (add $sgpr64_list, $vgpr64_list)
191 sub print_sgpr_class {
192 my ($reg_width, $sub_reg_ref, @types) = @_;
193 return print_reg_class('SReg', 'SGPR', $reg_width, $SGPR_COUNT, $sub_reg_ref, @types);
196 sub print_vgpr_class {
197 my ($reg_width, $sub_reg_ref, @types) = @_;
198 return print_reg_class('VReg', 'VGPR', $reg_width, $VGPR_COUNT, $sub_reg_ref, @types);
201 sub print_reg_class {
202 my ($class_prefix, $reg_prefix, $reg_width, $reg_count, $sub_reg_ref, @types) = @_;
204 my $component_count = $reg_width / 32;
206 for (my $i = 0; $i < $reg_count; $i += $component_count) {
207 my $reg_name = $reg_prefix . $i . '_' . $reg_width;
209 for (my $idx = 0; $idx < $component_count; $idx++) {
210 my $sub_idx = $i + $idx;
211 push(@sub_regs, $reg_prefix . $sub_idx);
213 print "def $reg_name : $reg_prefix\_$reg_width <$i, \"$reg_name\", [ ", join(',', @sub_regs) , "]>;\n";
217 push (@registers, $reg_name);
219 my $reg_list = join(', ', @registers);
221 print "def $class_prefix\_$reg_width : RegisterClass<\"AMDGPU\", [" . join (', ', @types) . "], $reg_width,\n (add $reg_list)\n>{\n";