X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fl2JIT.ml;h=a1f1ac4c158a619c2c9b710fefac12719e06fdaf;hb=efbad47ef803e878d25dbbc4e8c9e844b6a2eea0;hp=efe785453cd08e4cae96848a97c1e7e9110f5500;hpb=e1ae19bec9b516d8a531790bba6fb231c17c9862;p=SXSI%2Fxpathcomp.git diff --git a/src/l2JIT.ml b/src/l2JIT.ml index efe7854..a1f1ac4 100644 --- a/src/l2JIT.ml +++ b/src/l2JIT.ml @@ -207,26 +207,43 @@ let rec translate_jump tree tag (jkind:Ata.jump_kind) dir s = else assert false | _ -> assert false +let count = ref 0 +let () = at_exit (fun () -> Printf.eprintf "Compute jump called %i times\n" !count) +module Memo = Hashtbl.Make(struct + type t = Tag.t * StateSet.t * dir + let equal (a,b,c) (d,e,f) = a == d && b == e && c == f + let hash (a, b, c) = HASHINT3(a, Uid.to_int b.StateSet.Node.id, (Obj.magic c)) +end) + +let memo = Memo.create 1024 +let init () = Memo.clear memo + let compute_jump auto tree tag states dir = if !Options.no_jump then if dir == DIR_LEFT then FIRST_CHILD states else NEXT_SIBLING states else - let jkind = Ata.top_down_approx auto states tree in - let jump = translate_jump tree tag jkind dir states in - LOG(__ "level2-jit" 2 - "Computed jumps for %s %a %s, from %a : %a%!" - (Tag.to_string tag) - StateSet.print states - (if dir == DIR_LEFT then "left" else "right") - Ata.print_kind jkind - print_jump jump - ); - jump + try + Memo.find memo (tag, states, dir) + with + Not_found -> begin + incr count; + let jkind = Ata.top_down_approx auto states tree in + let jump = translate_jump tree tag jkind dir states in + LOG(__ "level2-jit" 2 + "Computed jumps for %s %a %s, from %a : %a%!" + (Tag.to_string tag) + StateSet.print states + (if dir == DIR_LEFT then "left" else "right") + Ata.print_kind jkind + print_jump jump + ); + Memo.add memo (tag, states, dir) jump; jump + end let compile cache2 auto tree tag states = let tr_list, states1, states2 = - Ata.get_trans ~attributes:(TagSet.inj_positive (Tree.attribute_tags tree)) auto states tag + Ata.get_trans (*~attributes:(TagSet.inj_positive (Tree.attribute_tags tree))*) auto states tag in let op = let empty_s1 = StateSet.is_empty states1 in @@ -250,7 +267,7 @@ let compile cache2 auto tree tag states = | BOTH(tr, NOP _, r) -> RIGHT (tr, r) | _ -> op in - add cache2 tag states op; + if not !Options.no_cache then add cache2 tag states op; op let get_transitions = function