reuse_operation_effect_calc(G,H) :- get_preference(try_operation_reuse,true),
(specfile:animation_minor_mode(xeventb) -> print('% OPERATION_REUSE not available for Event-B models'),nl,fail
% this didn't work ; see eg. prob_examples/examples/EventBPrologPackages/Advance_WP2/v6_Sep2014/ex_mch.eventb -animate 300 which generates deadlock
; true),
b_is_operation_name(G),
b_get_operation_normalized_read_write_info(G,_ReadG,WriteG), %print(analyse_reuse(G,_ReadG,WriteG)),nl,
WriteG \= [], /* otherwise we have a skip operation; we will not recompute state anyway */
b_get_machine_operation(H,_Results,_Parameters,_Body,OpType,_), % TO DO: check if _Body complicated enough
b_get_operation_normalized_read_write_info(H,ReadH,WriteH),
\+ ord_intersect(WriteG,ReadH),
(OpType = classic
-> \+ ord_intersect(WriteG,WriteH) % because for the moment we do not yet detect whether a potentially written variable by H is really written !
% TO DO: either store in reuse_operation the actual variables written, then we can remove the above line
% or compute the variables that are potentially written PotWriteH and intersect with those
; true
),
(debug:debug_mode(on) -> format('After: ~w reuse: ~w~n',[G,H]) ; true)
%,format('~nAfter: ~w (writes ~w)~n reuse: ~w (reads ~w, writes ~w)~n',[G,WriteG,H,ReadH,WriteH])
.
reuse_operation_effect_calc(_,_) :- get_preference(try_operation_reuse,true),
findall(G,b_is_operation_name(G),LG), length(LG,NrOps), TotPairs is NrOps*NrOps,
findall((G,H),reuse_operation_effect(G,H),Pairs), length(Pairs,NrReuse),
formatsilent('OPERATION_REUSE Statistics: ~w reuse pairs (for ~w operations, i.e. ~w pairs)~n',[NrReuse,NrOps,TotPairs]),
fail.