For review: computing costs more accurately in value numbering

Zoltan Somogyi zs at cs.mu.oz.au
Sun Apr 27 21:44:40 AEST 1997


vn_cost:
	Some unary and binary operators have the same cost as an assignment.
	Don't count this cost twice.

Zoltan.

Index: compiler/vn_cost.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/vn_cost.m,v
retrieving revision 1.22
diff -u -r1.22 vn_cost.m
--- vn_cost.m	1997/01/21 05:05:21	1.22
+++ vn_cost.m	1997/04/27 07:49:38
@@ -91,9 +91,17 @@
 		->
 			Cost = RvalCost
 		;
-			% Tagging a value has the same cost as the assignment
+			% Some operations have the same cost as the assignment
 			% itself, so don't count this cost twice.
-			Rval = mkword(_, _)
+			(
+				Rval = mkword(_, _)
+			;
+				Rval = unop(Unop, _),
+				vn_cost__assign_cost_unop(Unop)
+			;
+				Rval = binop(Binop, _, _),
+				vn_cost__assign_cost_binop(Binop)
+			)
 		->
 			Cost is RvalCost + LvalCost
 		;
@@ -318,6 +326,32 @@
 		vn_type__costof_intops(Params, OpsCost),
 		Cost is RvalCost + OpsCost
 	).
+
+:- pred vn_cost__assign_cost_unop(unary_op).
+:- mode vn_cost__assign_cost_unop(in) is semidet.
+
+vn_cost__assign_cost_unop(mktag).
+vn_cost__assign_cost_unop(tag).
+vn_cost__assign_cost_unop(unmktag).
+vn_cost__assign_cost_unop(mkbody).
+vn_cost__assign_cost_unop(body).
+vn_cost__assign_cost_unop(unmkbody).
+vn_cost__assign_cost_unop(bitwise_complement).
+
+:- pred vn_cost__assign_cost_binop(binary_op).
+:- mode vn_cost__assign_cost_binop(in) is semidet.
+
+vn_cost__assign_cost_binop(+).
+vn_cost__assign_cost_binop(-).
+vn_cost__assign_cost_binop(*).
+vn_cost__assign_cost_binop(/).
+vn_cost__assign_cost_binop(mod).
+vn_cost__assign_cost_binop(<<).
+vn_cost__assign_cost_binop(>>).
+vn_cost__assign_cost_binop(&).
+vn_cost__assign_cost_binop('|').
+vn_cost__assign_cost_binop(and).
+vn_cost__assign_cost_binop(or).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%



More information about the developers mailing list