Pages

Monday, 21 March 2011

Crazy JIT Prototype. Work In Progress.

Bon jour


In last couple of days I was thinking about "CJP". Major change in approach — I will actually "JIT" few ops in one go. It doesn't makes any sense to JIT one op only even for prototype.

I'm currently playing with JITting small sub like this:
.sub 'main' :main
    say "Answer"
    say 42
    say "Correct"
.end

Bytecode for this sub is:

0000: 00000000 00000000 say_sc
0002: 00000001 0000002a say_ic
0004: 00000000 00000001 say_sc
0006: 00000002 end



Basically now I can:
  • Create basic structure for "jitted sub". Including "entry", "leave" and blocks for each opcode.
  • Handle parameters inside "jitted sub"
  • Handle return from "jitted sub"
  • Handle goto offset bracnhes.
And there is long-boring-output of t/jit/test.t (which should be called prototype.t but whatever)
~/src/parrot (jit_prototype)$ ./parrot-nqp t/jit/test.t 
ok 1 - Unpacked
ok 2 - Got PF Directory
ok 3 - Got bytecode
ok 4 - Got OpMap
# Parsing t/jit/jitted.ops...
# Parsed t/jit/jitted.ops in 0.232 seconds; found 14 ops.
ok 5 - Got Ops::Trans::JIT
ok 6 - jit_context
ok 7 - VTABLE
ok 8 - PMC
ok 9 - interp_struct
ok 10 - opcode_t *
# say_sc
# say_ic
# say_sc
# end
# 0 say_sc
# 2 say_ic
# 4 say_sc
# 6 end
; ModuleID = 'foo'

%0 = type { %1, i32, i32, i32 }
%1 = type opaque
%opcode_ptr = type i32*
%struct.PMC = type { i32, %struct.VTABLE*, i8*, %struct.PMC* }
%struct.VTABLE = type { }
%struct.parrot_interp_t = type { %struct.PMC* }

define i32* @foo(i32* %cur_opcode, %struct.parrot_interp_t* %interp) {
entry:
  %cur_opcode_addr = alloca i32*                  ; <i32**> [#uses=1]
  store i32* %cur_opcode, i32** %cur_opcode_addr
  %interp_addr = alloca %struct.parrot_interp_t*  ; <%struct.parrot_interp_t**> [#uses=1]
  store %struct.parrot_interp_t* %interp, %struct.parrot_interp_t** %interp_addr
  %retval = alloca i32*                           ; <i32**> [#uses=2]
  %CUR_CTX = alloca %0*                           ; <%0**> [#uses=0]
  br label %L0

L0:                                               ; preds = %entry
  br label %L2

L2:                                               ; preds = %L0
  br label %L4

L4:                                               ; preds = %L2
  br label %L6

L6:                                               ; preds = %L4
  store i32* null, i32** %retval
  br label %leave

leave:                                            ; preds = %L6
  %0 = load i32** %retval                         ; <i32*> [#uses=1]
  ret i32* %0
}
ok 11 - Module verified
~/src/parrot (jit_prototype)$ 

Stay tuned! We can have first functional prototype in just few days :)