[m-rev.] diff: proc_label speedup

Zoltan Somogyi zs at unimelb.edu.au
Tue Apr 24 16:02:12 AEST 2012


This gets a speedup of 1.5% on tools/speedtest. This is a bit odd, since the
relevant procedure showed up as taking only 0.6% of runtime in the profile :-)

compiler/code_info.m:
	Construct the proc_label for the procedure being compiled just once,
	instead of doing once for every label we generate.

compiler/proc_label.m:
	We used to create create proc_labels by creating an rtti_proc_label,
	and then using SOME of its fields to make the proc_label. Some of the
	fields we didn't use were expensive to fill. So we now just get the
	values of the fields we want directly.

cvs diff: Diffing .
Index: code_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.398
diff -u -b -r1.398 code_info.m
--- code_info.m	24 Jan 2012 05:23:06 -0000	1.398
+++ code_info.m	24 Apr 2012 04:33:24 -0000
@@ -359,6 +359,9 @@
                 % The proc_info for this procedure.
                 cis_proc_info           :: proc_info,
 
+                % The proc_label for this procedure.
+                cis_proc_label          :: proc_label,
+
                 % The variables in this procedure.
                 cis_varset              :: prog_varset,
 
@@ -503,6 +506,7 @@
         FollowVars, ModuleInfo, StaticCellInfo, ResumePoint, TraceSlotInfo,
         MaybeContainingGoalMap, TSRevStringTable, TSStringTableSize,
         CodeInfo) :-
+    ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId),
     proc_info_get_initial_instmap(ProcInfo, ModuleInfo, InstMap),
     proc_info_get_liveness_info(ProcInfo, Liveness),
     CodeModel = proc_info_interface_code_model(ProcInfo),
@@ -587,6 +591,7 @@
             ProcId,
             PredInfo,
             ProcInfo,
+            ProcLabel,
             VarSet,
             SlotMax,
             no,
@@ -1151,13 +1156,11 @@
     CodeAddr = make_entry_label(ModuleInfo, PredId, ProcId, Immed).
 
 get_next_label(Label, !CI) :-
-    get_module_info(!.CI, ModuleInfo),
-    get_pred_id(!.CI, PredId),
-    get_proc_id(!.CI, ProcId),
+    get_cur_proc_label(!.CI, ProcLabel),
     get_label_counter(!.CI, C0),
     counter.allocate(N, C0, C),
     set_label_counter(C, !CI),
-    Label = make_internal_label(ModuleInfo, PredId, ProcId, N).
+    Label = internal_label(N, ProcLabel).
 
 succip_is_used(!CI) :-
     set_succip_used(yes, !CI).
@@ -1224,10 +1227,7 @@
     map.to_assoc_list(TempsInUseContentMap, Temps).
 
 get_cur_proc_label(CI, ProcLabel) :-
-    get_module_info(CI, ModuleInfo),
-    get_pred_id(CI, PredId),
-    get_proc_id(CI, ProcId),
-    ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId).
+    ProcLabel = CI ^ code_info_static ^ cis_proc_label.
 
 get_next_closure_seq_no(SeqNo, !CI) :-
     get_closure_seq_counter(!.CI, C0),
Index: proc_label.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/proc_label.m,v
retrieving revision 1.28
diff -u -b -r1.28 proc_label.m
--- proc_label.m	23 May 2011 05:08:09 -0000	1.28
+++ proc_label.m	24 Apr 2012 04:40:10 -0000
@@ -60,6 +60,28 @@
         _ProcHeadVarsWithNames, _ArgModes, _CodeModel,
         PredIsImported, _PredIsPseudoImported, Origin,
         _ProcIsExported, _ProcIsImported),
+    ProcLabel = do_make_proc_label(PredOrFunc, ThisModule, PredModule,
+        PredName, PredArity, ProcId, PredIsImported, Origin).
+
+make_proc_label(ModuleInfo, PredId, ProcId) = ProcLabel :-
+    module_info_get_name(ModuleInfo, ThisModule),
+    module_info_pred_proc_info(ModuleInfo, PredId, ProcId, PredInfo,
+        _ProcInfo),
+    PredOrFunc = pred_info_is_pred_or_func(PredInfo),
+    PredModule = pred_info_module(PredInfo),
+    PredName = pred_info_name(PredInfo),
+    PredArity = pred_info_orig_arity(PredInfo),
+    PredIsImported = (pred_info_is_imported(PredInfo) -> yes ; no),
+    pred_info_get_origin(PredInfo, Origin),
+
+    ProcLabel = do_make_proc_label(PredOrFunc, ThisModule, PredModule,
+        PredName, PredArity, ProcId, PredIsImported, Origin).
+
+:- func do_make_proc_label(pred_or_func, module_name, module_name,
+    string, arity, proc_id, bool, pred_origin) = proc_label.
+
+do_make_proc_label(PredOrFunc, ThisModule, PredModule, PredName, PredArity,
+        ProcId, PredIsImported, Origin) = ProcLabel :-
     ( Origin = origin_special_pred(SpecialPred - TypeCtor) ->
         (
             % All type_ctors other than tuples here should be module qualified,
@@ -94,10 +116,6 @@
             PredOrFunc, PredModule, PredName, PredArity, ProcId)
     ).
 
-make_proc_label(ModuleInfo, PredId, ProcId) = ProcLabel :-
-    RttiProcLabel = make_rtti_proc_label(ModuleInfo, PredId, ProcId),
-    make_proc_label_from_rtti(RttiProcLabel) = ProcLabel.
-
     % make_user_proc_label(ModuleName, PredIsImported,
     %   PredOrFunc, ModuleName, PredName, Arity, ProcId) = Label:
     %
cvs diff: Diffing 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