diff: more extensions for `any' insts

Fergus Henderson fjh at hydra.cs.mu.oz.au
Sun Sep 21 18:35:28 AEST 1997


Estimated hours: 1

Extend the handling of `any' insts.

compiler/inst_util.m:
	Change inst_merge to allow merging of `any' with `ground'.
	This is safe now that we assume that `any' insts and `ground'
	insts have the same representation.

compiler/inst_util.m:
compiler/inst_match.m:
	Change inst_matches_initial, inst_matches_final,
	and inst_merge to allow `free' insts to match with
	`any' in the case where the result is not live
	(i.e. it is a `clobbered' or `mostly_clobbered' any).
	This is safe even though `free' insts may be represented
	as uninitialized memory, because `clobbered' or `mostly_clobbered'
	inst guarantees that the memory will never be accessed.

cvs diff: Diffing .
Index: inst_match.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/inst_match.m,v
retrieving revision 1.36
diff -u -r1.36 inst_match.m
--- inst_match.m	1997/09/15 20:09:54	1.36
+++ inst_match.m	1997/09/20 02:45:16
@@ -284,15 +284,21 @@
 inst_matches_initial_3(any(UniqA), any(UniqB), _, _) :-
 	unique_matches_initial(UniqA, UniqB).
 inst_matches_initial_3(any(_), free, _, _).
-/* not yet:
-inst_matches_initial_3(free, any(_), _, _).
-*/
+inst_matches_initial_3(free, any(Uniq), _, _) :-
+	/* we do not yet allow `free' to match `any',
+	   unless the `any' is `clobbered_any' or `mostly_clobbered_any' */
+	( Uniq = clobbered ; Uniq = mostly_clobbered ).
 inst_matches_initial_3(free, free, _, _).
 inst_matches_initial_3(bound(UniqA, ListA), any(UniqB), ModuleInfo, _) :-
 	unique_matches_initial(UniqA, UniqB),
 	bound_inst_list_matches_uniq(ListA, UniqB, ModuleInfo),
-	/* we do not yet allow `free' to match `any' */
-	bound_inst_list_is_ground_or_any(ListA, ModuleInfo).
+	/* we do not yet allow `free' to match `any',
+	   unless the `any' is `clobbered_any' or `mostly_clobbered_any' */
+	( ( UniqB = clobbered ; UniqB = mostly_clobbered ) ->
+		true
+	;
+		bound_inst_list_is_ground_or_any(ListA, ModuleInfo)
+	).
 inst_matches_initial_3(bound(_Uniq, _List), free, _, _).
 inst_matches_initial_3(bound(UniqA, ListA), bound(UniqB, ListB), ModuleInfo,
 		Expansions) :-
@@ -512,10 +518,10 @@
 
 inst_matches_final_3(any(UniqA), any(UniqB), _, _) :-
 	unique_matches_final(UniqA, UniqB).
-/***
-	% not yet:
-inst_matches_final_3(free, any(_), _, _).
-***/
+inst_matches_final_3(free, any(Uniq), _, _) :-
+	/* we do not yet allow `free' to match `any',
+	   unless the `any' is `clobbered_any' or `mostly_clobbered_any' */
+	( Uniq = clobbered ; Uniq = mostly_clobbered ).
 inst_matches_final_3(free, free, _, _).
 inst_matches_final_3(bound(UniqA, ListA), any(UniqB), ModuleInfo, _) :-
 	unique_matches_final(UniqA, UniqB),
Index: inst_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/inst_util.m,v
retrieving revision 1.5
diff -u -r1.5 inst_util.m
--- inst_util.m	1997/09/15 13:47:08	1.5
+++ inst_util.m	1997/09/20 04:44:12
@@ -1260,24 +1260,54 @@
 :- pred inst_merge_3(inst, inst, module_info, inst, module_info).
 :- mode inst_merge_3(in, in, in, out, out) is semidet.
 
+% We do not yet allow merging of `free' and `any',
+% except in the case where the any is `mostly_clobbered_any'
+% or `clobbered_any', because that would require inserting
+% additional code to initialize the free var.
+%
+% We do NOT plan to allow merging of `free' and `ground'
+% to produce `any', because that would introduce `any'
+% insts even for builtin types such as `int' which can't
+% support `any'.  It might also make the mode system
+% too weak -- it might not be able to detect bugs as well
+% as it can currently.
+
 inst_merge_3(any(UniqA), any(UniqB), M, any(Uniq), M) :-
 	merge_uniq(UniqA, UniqB, Uniq).
-/* not yet:
-inst_merge_3(any(Uniq), free, M, any(Uniq), M).
-inst_merge_3(any(UniqA), bound(UniqB, ListB), M, any(Uniq), M) :-
-	merge_uniq_bound(UniqA, UniqB, ListB, ModuleInfo, Uniq),
+inst_merge_3(any(Uniq), free, M, any(Uniq), M) :-
+	% we do not yet allow merge of any with free, except for clobbered anys
+	( Uniq = clobbered ; Uniq = mostly_clobbered ).
+inst_merge_3(any(UniqA), bound(UniqB, ListB), ModInfo, any(Uniq), ModInfo) :-
+	merge_uniq_bound(UniqA, UniqB, ListB, ModInfo, Uniq),
+	% we do not yet allow merge of any with free, except for clobbered anys
+	( ( Uniq = clobbered ; Uniq = mostly_clobbered ) ->
+		true
+	;
+		bound_inst_list_is_ground_or_any(ListB, ModInfo)
+	).
 inst_merge_3(any(UniqA), ground(UniqB, _), M, any(Uniq), M) :-
 	merge_uniq(UniqA, UniqB, Uniq).
 inst_merge_3(any(UniqA), abstract_inst(_, _), M, any(Uniq), M) :-
-	merge_uniq(UniqA, shared, Uniq).
-inst_merge_3(free, any(Uniq), M, any(Uniq), M).
-inst_merge_3(bound(UniqA, ListA), any(UniqB), M, any(Uniq), M) :-
-	merge_uniq_bound(UniqB, UniqA, ListA, ModuleInfo, Uniq),
+	merge_uniq(UniqA, shared, Uniq),
+	% we do not yet allow merge of any with free, except for clobbered anys
+	( Uniq = clobbered ; Uniq = mostly_clobbered ).
+inst_merge_3(free, any(Uniq), M, any(Uniq), M) :-
+	% we do not yet allow merge of any with free, except for clobbered anys
+	( Uniq = clobbered ; Uniq = mostly_clobbered ).
+inst_merge_3(bound(UniqA, ListA), any(UniqB), ModInfo, any(Uniq), ModInfo) :-
+	merge_uniq_bound(UniqB, UniqA, ListA, ModInfo, Uniq),
+	% we do not yet allow merge of any with free, except for clobbered anys
+	( ( Uniq = clobbered ; Uniq = mostly_clobbered ) ->
+		true
+	;
+		bound_inst_list_is_ground_or_any(ListA, ModInfo)
+	).
 inst_merge_3(ground(UniqA, _), any(UniqB), M, any(Uniq), M) :-
-	merge_uniq(UniqA, UniqB).
+	merge_uniq(UniqA, UniqB, Uniq).
 inst_merge_3(abstract_inst(_, _), any(UniqB), M, any(Uniq), M) :-
-	merge_uniq(shared, UniqB, Uniq).
-*/
+	merge_uniq(shared, UniqB, Uniq),
+	% we do not yet allow merge of any with free, except for clobbered anys
+	( Uniq = clobbered ; Uniq = mostly_clobbered ).
 inst_merge_3(free, free, M, free, M).
 inst_merge_3(bound(UniqA, ListA), bound(UniqB, ListB), ModuleInfo0,
 		bound(Uniq, List), ModuleInfo) :-
cvs diff: Diffing notes

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list