[m-rev.] for review: optimize bits_per_int operations

Zoltan Somogyi zs at csse.unimelb.edu.au
Tue Dec 19 14:27:40 AEDT 2006


Ihave two questions for the reviewers of this diff. First, should the new
option default to --cross-compiling or --no-cross-compiling? The former is
safer, the second yields faster code. Second, the new option should of course
be mentioned in the user guide, but exactly where?

Zoltan.

Optimize the functions involving int.bits_per_int, since doing this can speed
up sparse_bitset.m.

compiler/options.m:
	Add an option that says whether we are cross-compiling, since our
	optimizations work only int.bits_per_int returns the same in the
	running program as in the compiler that generates its code.

compiler/simplify.m:
	If we are not cross compiling, replace calls to the functions
	involving bits_per_int whose other arguments have unknown values
	with simpler, faster operations, one of whose operands is the
	compiler's value for bits_per_int.

	Shift some work from const_prop to simplify, since the code to do the
	above needs it also.

compiler/const_prop.m:
	If we are not cross compiling, evaluate calls to the functions
	involving bits_per_int whose other arguments have known values.

compiler/add_pragma.m:
	Just as we report errors for attempts to define builtins via clauses,
	report errors for attempts to define builtins via foreign_procs.

compiler/hlds_module.m:
	Factor out some common code.

compiler/Mercury.options:
	Turn on the new optimizations for sparse_bitset.m.

mdbcomp/prim_data.m:
	Provide a utility predicate for recognizing standard library modules,
	for use in simplify.m.

cvs diff: Diffing compiler
Index: compiler/call_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/call_gen.m,v
retrieving revision 1.188
diff -u -b -r1.188 call_gen.m
--- compiler/call_gen.m	14 Dec 2006 04:35:44 -0000	1.188
+++ compiler/call_gen.m	16 Dec 2006 17:38:10 -0000
@@ -103,7 +103,7 @@
     code_info.get_module_info(!.CI, ModuleInfo),
     Address = make_proc_entry_label(!.CI, ModuleInfo, PredId, ProcId, yes),
     code_info.get_next_label(ReturnLabel, !CI),
-    call_gen.call_comment(CodeModel, CallComment),
+    call_gen.call_comment(!.CI, PredId, CodeModel, CallComment),
     goal_info_get_context(GoalInfo, Context),
     goal_info_get_goal_path(GoalInfo, GoalPath),
     CallCode = node([
@@ -454,11 +454,31 @@
         FailHandlingCode = empty
     ).
 
-:- pred call_comment(code_model::in, string::out) is det.
+:- pred call_comment(code_info::in, pred_id::in, code_model::in, string::out)
+    is det.
 
-call_comment(model_det,  "branch to det procedure").
-call_comment(model_semi, "branch to semidet procedure").
-call_comment(model_non,  "branch to nondet procedure").
+call_comment(CI, PredId, CodeModel, Msg) :-
+    (
+        CodeModel = model_det,
+        BaseMsg = "branch to det procedure"
+    ;
+        CodeModel = model_semi,
+        BaseMsg = "branch to semidet procedure"
+    ;
+        CodeModel = model_non,
+        BaseMsg = "branch to nondet procedure"
+    ),
+    code_info.get_auto_comments(CI, AutoComments),
+    (
+        AutoComments = yes,
+        code_info.get_module_info(CI, ModuleInfo),
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
+        PredName = pred_info_name(PredInfo),
+        Msg = BaseMsg ++ " " ++ PredName
+    ;
+        AutoComments = no,
+        Msg = BaseMsg
+    ).
 
 %---------------------------------------------------------------------------%
 
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.337
diff -u -b -r1.337 code_info.m
--- compiler/code_info.m	7 Dec 2006 06:22:22 -0000	1.337
+++ compiler/code_info.m	16 Dec 2006 17:35:43 -0000
@@ -213,6 +213,8 @@
 
 :- pred get_opt_trail_ops(code_info::in, bool::out) is det.
 
+:- pred get_auto_comments(code_info::in, bool::out) is det.
+
 %---------------------------------------------------------------------------%
 
 :- implementation.
@@ -341,9 +343,12 @@
                 emit_trail_ops      :: bool,
                                     % Should we emit trail operations?
 
-                opt_trail_ops       :: bool
+                opt_trail_ops       :: bool,
                                     % Should we try to avoid emiting trail
                                     % operations?
+
+                auto_comments       :: bool
+                                    % The setting of --auto-comments.
             ).
 
 :- type code_info_loc_dep
@@ -510,6 +515,7 @@
         EmitTrailOps = no
     ),
     globals.lookup_bool_option(Globals, optimize_trail_usage, OptTrailOps),
+    globals.lookup_bool_option(Globals, auto_comments, AutoComments),
     CodeInfo0 = code_info(
         code_info_static(
             Globals,
@@ -523,7 +529,8 @@
             no,
             OptNoReturnCalls,
             EmitTrailOps,
-            OptTrailOps
+            OptTrailOps,
+            AutoComments
         ),
         code_info_loc_dep(
             Liveness,
@@ -586,6 +593,7 @@
 get_opt_no_return_calls(CI, CI ^ code_info_static ^ opt_no_resume_calls).
 get_emit_trail_ops(CI, CI ^ code_info_static ^ emit_trail_ops).
 get_opt_trail_ops(CI, CI ^ code_info_static ^ opt_trail_ops).
+get_auto_comments(CI, CI ^ code_info_static ^ auto_comments).
 get_forward_live_vars(CI, CI ^ code_info_loc_dep ^ forward_live_vars).
 get_instmap(CI, CI ^ code_info_loc_dep ^ instmap).
 get_zombies(CI, CI ^ code_info_loc_dep ^ zombies).
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.299
diff -u -b -r1.299 llds_out.m
--- compiler/llds_out.m	1 Dec 2006 15:04:03 -0000	1.299
+++ compiler/llds_out.m	18 Dec 2006 04:04:48 -0000
@@ -2131,7 +2131,7 @@
         ;
             io.write_string("\t\t/* ", !IO),
             io.write_string(Comment, !IO),
-            io.write_string("*/\n", !IO)
+            io.write_string(" */\n", !IO)
         )
     ).
 
cvs diff: Diffing compiler/notes
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list