Search code examples
lualuajit

Understanding Luajit SNAP IR instruction


I am trying to trace some register coalescing too complex NYI in my luajit code. From the IR in can see that the snapshot when the NYI happens is pretty full. My attempt is to trace backwards and to find out what causes the snapshot to be filled up.

To start with I am looking to understand what information is given out by the SNAP line. for example in a SNAP line below:

> local x = 1.2 for i=1,1e3 do x = x * -3 end
---- TRACE 1 start stdin:1
0006  MULVN    0   0   1  ; -3
0007  FORL     1 => 0006
---- TRACE 1 IR
....              SNAP   #0   [ ---- ]
0001 rbp      int SLOAD  #2    CI
0002 xmm7  >  num SLOAD  #1    T
0003 xmm7   + num MUL    0002  -3  
0004 rbp    + int ADD    0001  +1  
....              SNAP   #1   [ ---- 0003 ]
0005       >  int LE     0004  +1000
....              SNAP   #2   [ ---- 0003 0004 ---- ---- 0004 ]
0006 ------------ LOOP ------------
0007 xmm7   + num MUL    0003  -3  
0008 rbp    + int ADD    0004  +1  
....              SNAP   #3   [ ---- 0007 ]
0009       >  int LE     0008  +1000
0010 rbp      int PHI    0004  0008
0011 xmm7     num PHI    0003  0007

If my understanding is correct, in first snapshot second position is written by IR at 0003. Going by the argument of IR at 0003 I guess 0002 (is this a memory location?) is x.

What I do not understand is that in second snapshot line (after IR 0005) 3rd and 6th position is modified by IR at 0004. How is that?

Now, how can I trace which variables are present in a snapshot position in above IR? For eg: in SNAP #7 [ ---- 0007 ].

Also what does the second argument to SLOAD (flags) signify? [I, CI, CRI, T, PI, PRI, R, RI] etc... I have also seen SLOAD with second argument empty.


Solution

  • This has been extensively answerd at luajit mail list by Peter Cawley in the following thread

    https://www.freelists.org/post/luajit/Understanding-SNAP