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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
r600-sbDebuggingEnvironment variables
Regression debuggingIf there are any regressions as compared to the default backend (R600_SB=0), it's possible to use the following environment variables to find the incorrectly optimized shader that causes the regression.
Example - optimize only the shaders 5, 6, and 7:
All shaders compiled by the application are numbered starting from 1, the number of shaders used by the application may be obtained by running it with "R600_DEBUG=sb,sbstat" - it will print "sb: shader #index#" for each compiled shader. After figuring out the total number of shaders used by the application, the variables above allow to use bisection to find the shader that is the cause of regression. E.g. if the application uses 100 shaders, we can divide the range [1; 100] and run the application with the optimization enabled only for the first half of the shaders:
If the regression is reproduced with these parameters, then the failing shader is in the range [1; 50], if it's not reproduced - then it's in the range [51; 100]. Then we can divide the new range again and repeat the testing, until we'll reduce the range to a single failing shader. NOTE: This method relies on the assumption that the application produces the same sequence of the shaders on each run. It's not always true - some applications may produce different sequences of the shaders, in such cases the tools like apitrace may be used to record the trace with the application, then this method may be applied when replaying the trace - also this may be faster and/or more convenient than testing the application itself. Intermediate RepresentationValuesAll kinds of the operands (literal constants, references to kcache constants, references to GPRs, etc) are currently represented by the value class (possibly it makes sense to switch to hierarchy of classes derived from value instead, to save some memory). All values (except some pseudo values like the exec_mask or predicate register) represent 32bit scalar values - there are no vector values, CF/FETCH instructions use groups of 4 values for src and dst operands. NodesShader programs are represented using the tree data structure, some nodes contain a list of subnodes. Control flow nodesControl flow information is represented using four special node types (based on the ideas from [1] )
The target region of depart and repeat nodes is always the region where they are located (possibly in the nested region), there are no arbitrary jumps/goto's - control flow in the program is always structured. Typical control flow constructs can be represented as in the following examples: GLSL:
IR:
GLSL:
IR:
'Break' and 'continue' inside the loops are directly translated to the depart and repeat nodes for the corresponding loop region. This may look a bit too complicated, but in fact this allows more simple and uniform handling of the control flow. All loop_phi and phi nodes for some region always have the same number of source operands. The number of source operands for region_node::loop_phi nodes is 1 + number of repeat nodes that reference this region as a target. The number of source operands for region_node::phi nodes is equal to the number of depart nodes that reference this region as a target. All depart/repeat nodes for the region have unique indices equal to the index of source operand for phi/loop_phi nodes. First source operand for region_node::loop_phi nodes (src[0]) is an incoming value that enters the region from the outside. Each remaining source operand comes from the corresponding repeat node. More complex example: GLSL:
IR with SSA form:
Phi nodes with single source operand are just copies, they are not really necessary, but this allows to handle all depart_nodes in the uniform way. Instruction nodesInstruction nodes represent different kinds of instructions - alu_node, cf_node, fetch_node, etc. Each of them contains the "bc" structure where all fields of the bytecode are stored (the type is bc_alu for alu_node, etc). The operands are represented using the vectors of pointers to value class (node::src, node::dst) SSA-specific nodesPhi nodes currently don't have special node class, they are stored as node. Destination vector contains a single destination value, source vector contains 1 or more source values. Psi nodes [5], [6] also don't have a special node class and stored as node. Source vector contains 3 values for each source operand - the value of predicate, value of corresponding PRED_SEL field, and the source value itself. Indirect addressingSpecial kind of values (VLK_RELREG) is used to represent indirect operands. These values don't have SSA versions. The representation is mostly based on the [2]. Indirect operand contains the "offset/address" value (value::rel), (e.g. some SSA version of the AR register value, though after some passes it may be any value - constant, register, etc), also it contains the maydef and mayuse vectors of pointers to values (similar to dst/src vectors in the node) to represent the effects of aliasing in the SSA form. E.g. if we have the array R5.x ... R8.x and the following instruction :
then source indirect operand is represented with the VLK_RELREG value, value::rel is AR, value::maydef is empty (in fact it always contain the same number of elements as mayuse to simplify the handling, but they are NULLs), value::mayuse contains [R5.x, R6.x, R7.x, R8.x] (or the corresponding SSA versions after ssa_rename). Additional "virtual variables" as in HSSA [2] are not used, also there is no special handling for "zero versions". Typical programs in our case are small, indirect addressing is rare, array sizes are limited by max gpr number, so we don't really need to use special tricks to avoid the explosion of value versions. Also this allows more precise liveness computation for array elements without modifications to the algorithms. With the following instruction:
we'll have both maydef and mayuse vectors for dst operand filled with array values initially: [R5.x, R6.x, R7.x, R8.x]. After the ssa_rename pass mayuse will contain previous versions, maydef will contain new potentially-defined versions. Passes
References[1] "Tree-Based Code Optimization. A Thesis Proposal", Carl McConnell [3] "Global Code Motion. Global Value Numbering.", Cliff Click [4] "Register Allocation for Programs in SSA Form", Sebastian Hack [5] "An extension to the SSA representation for predicated code", Francois de Ferriere [6] "Improvements to the Psi-SSA Representation", F. de Ferriere |