376 | | |
| 376 | For each symbol (PIR register or declared symbol), a [source:/trunk/compilers/pirc/src/pirregalloc.h#L29 live_interval struct] instance is allocated. Most important are the {{{startpoint}}} and {{{endpoint}}} fields, which keep track of the start and end point respectively of the live interval of the variable. Consider the following example: |
| 377 | |
| 378 | {{{ |
| 379 | |
| 380 | .sub main |
| 381 | 0 $I10 = 1 |
| 382 | 1 $I11 = 2 |
| 383 | 2 print $I0 |
| 384 | 3 print $I1 |
| 385 | .end |
| 386 | |
| 387 | }}} |
| 388 | |
| 389 | In this code snippet, the numbers in front of the statements indicate the sequence of instructions. As you can see, {{{$I0}}} lives from 0 to 2, whereas {{{$I1}}} lives from 1 to 3. Since these live intervals are overlapping, this means that these variables cannot share a register. On the other hand, consider the following example: |
| 390 | |
| 391 | {{{ |
| 392 | |
| 393 | .sub main |
| 394 | 0 $I0 = 1 |
| 395 | 1 print $I0 |
| 396 | 2 $I1 = 2 |
| 397 | 3 print $I1 |
| 398 | .end |
| 399 | |
| 400 | }}} |
| 401 | |
| 402 | In this case, {{{$I0}}} lives from 0 to 1, whereas {{{$1}}} lives from 2 to 3. Since they do not overlap, these variables can share a register. This can be calculated by the algorithm described in the above mentioned paper. These details will not be discussed here; instead the reader is referred to the paper. |