[m-rev.] for post-commit review: Write out a bytecode representation from before the profdeep transformation in profdeep grades.

Paul Bone pbone at csse.unimelb.edu.au
Thu Sep 4 20:46:17 AEST 2008


For post-commit review by Zoltan.

Estimated hours taken: 2.5
Branches: main

Programs build in the deep profiling grade can optionally write out a
Deep.procrep file containing a bytecode representation of the program.  This
has been modified so that it writes out bytecodes equivalent to the HLDS
before the deep profiling transformation.

compiler/hlds_pred.m:
    Created a new structure, deep_original_body, that stores enough
    information to create a bytecode representation of the procedure.
    Added a deep_original_body field to deep_profile_proc_info, and improved
    the comments on the fields in this type.

compiler/deep_profiling.m:
    Make a deep_original structure, both in the first stage of the
    transformation, or in the second if the first stage wasn't run (and
    therefore didn't create a deep_original structure.

compiler/layout.m:
    Add a deep_original_body field to proc_layout_proc_static.

compiler/stack_layout.m:
    If available use the original procedure body for creating the bytecode
    representation of a procedure for the deep profiler.

compiler/proc_gen.m:
    generate_deep_prof_info now copies the deep_original_body field from the
    deep_profile_proc_info structure to the proc_layout_proc_static structure.

compiler/hlds_out.m:
    Conform to changes in hlds_pred.m.

compiler/layout_out.m:
    Conform to changes in layout.m.

Index: compiler/deep_profiling.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.76
diff -u -p -r1.76 deep_profiling.m
--- compiler/deep_profiling.m	25 Aug 2008 06:01:51 -0000	1.76
+++ compiler/deep_profiling.m	4 Sep 2008 10:09:34 -0000
@@ -135,10 +135,13 @@ apply_tail_recursion_to_proc(PredProcId,
         OrigDeepRecInfo = yes(deep_recursion_info(
             outer_proc(ClonePredProcId),
             [visible_scc_data(PredProcId, ClonePredProcId, TailCallSites)])),
-        OrigDeepProfileInfo = deep_profile_proc_info(OrigDeepRecInfo, no),
+        make_deep_original_body(ProcInfo0, !.ModuleInfo, DeepOriginalBody),
+        OrigDeepProfileInfo = deep_profile_proc_info(OrigDeepRecInfo, no,
+            DeepOriginalBody),
         CloneDeepRecInfo = yes(deep_recursion_info(inner_proc(PredProcId),
             [visible_scc_data(PredProcId, ClonePredProcId, TailCallSites)])),
-        CloneDeepProfileInfo = deep_profile_proc_info(CloneDeepRecInfo, no),
+        CloneDeepProfileInfo = deep_profile_proc_info(CloneDeepRecInfo, no, 
+            DeepOriginalBody),
         proc_info_set_maybe_deep_profile_info(yes(OrigDeepProfileInfo),
             ProcInfo1, ProcInfo),
         proc_info_set_maybe_deep_profile_info(
@@ -475,15 +478,50 @@ maybe_transform_procedure(ModuleInfo, Pr
 deep_prof_transform_proc(ModuleInfo, PredProcId, !ProcInfo) :-
     proc_info_get_maybe_deep_profile_info(!.ProcInfo, MaybeDeepInfo),
     (
-        MaybeDeepInfo = yes(DeepInfo),
-        DeepInfo = deep_profile_proc_info(MaybeDeepRecInfo, _),
-        MaybeDeepRecInfo = yes(RecInfo),
-        RecInfo ^ role = inner_proc(_)
-    ->
-        transform_inner_proc(ModuleInfo, PredProcId, !ProcInfo)
+        MaybeDeepInfo = yes(DeepInfo0),
+        DeepInfo0 = deep_profile_proc_info(MaybeDeepRecInfo, _, OrigBody),
+        (
+            MaybeDeepRecInfo = yes(RecInfo),
+            RecInfo ^ role = inner_proc(_)
+        ->
+            transform_inner_proc(ModuleInfo, PredProcId, !ProcInfo),
+            MaybeDeepLayoutInfo = no
+        ;
+            transform_normal_proc(ModuleInfo, PredProcId, !ProcInfo,
+                DeepLayoutInfo),
+            MaybeDeepLayoutInfo = yes(DeepLayoutInfo)
+        )
+    ;
+        MaybeDeepInfo = no,
+        make_deep_original_body(!.ProcInfo, ModuleInfo, OrigBody),
+        transform_normal_proc(ModuleInfo, PredProcId, !ProcInfo,
+            DeepLayoutInfo),
+        MaybeDeepLayoutInfo = yes(DeepLayoutInfo),
+        MaybeDeepRecInfo = no
+    ),
+    DeepInfo = deep_profile_proc_info(MaybeDeepRecInfo, MaybeDeepLayoutInfo, 
+        OrigBody),
+    proc_info_set_maybe_deep_profile_info(yes(DeepInfo), !ProcInfo).
+
+%-----------------------------------------------------------------------------%
+
+:- pred make_deep_original_body(proc_info::in, module_info::in, 
+    deep_original_body::out) is det.
+
+make_deep_original_body(ProcInfo, ModuleInfo, DeepOriginalBody) :-
+    proc_info_get_goal(ProcInfo, Body),
+    proc_info_get_headvars(ProcInfo, HeadVars),
+    proc_info_get_initial_instmap(ProcInfo, ModuleInfo, Instmap),
+    proc_info_get_vartypes(ProcInfo, Vartypes),
+    proc_info_get_declared_determinism(ProcInfo, MaybeDetism),
+    (
+        MaybeDetism = yes(Detism)
     ;
-        transform_normal_proc(ModuleInfo, PredProcId, !ProcInfo)
-    ).
+        MaybeDetism = no,
+        proc_info_get_inferred_determinism(ProcInfo, Detism)
+    ),
+    DeepOriginalBody = deep_original_body(Body, HeadVars, Instmap, Vartypes,
+        Detism).
 
 %-----------------------------------------------------------------------------%
 
@@ -515,9 +553,9 @@ deep_prof_transform_proc(ModuleInfo, Pre
     % Transfrom a procedure.
     %
 :- pred transform_normal_proc(module_info::in, pred_proc_id::in,
-    proc_info::in, proc_info::out) is det.
+    proc_info::in, proc_info::out, hlds_deep_layout::out) is det.
 
-transform_normal_proc(ModuleInfo, PredProcId, !ProcInfo) :-
+transform_normal_proc(ModuleInfo, PredProcId, !ProcInfo, DeepLayoutInfo) :-
     module_info_get_globals(ModuleInfo, Globals),
     proc_info_get_goal(!.ProcInfo, Goal0),
     Goal0 = hlds_goal(_, GoalInfo0),
@@ -611,7 +649,7 @@ transform_normal_proc(ModuleInfo, PredPr
     proc_info_set_varset(Vars, !ProcInfo),
     proc_info_set_vartypes(VarTypes, !ProcInfo),
     proc_info_set_goal(Goal, !ProcInfo),
-    record_hlds_proc_static(ProcStatic, ExcpVars, !ProcInfo).
+    DeepLayoutInfo = hlds_deep_layout(ProcStatic, ExcpVars).
 
 % Wrap the procedure body in the deep profiling port goals.
 
@@ -1818,28 +1856,12 @@ add_impurity_if_needed(AddedImpurity, !G
 extract_deep_rec_info(MaybeDeepProfInfo, MaybeRecInfo) :-
     (
         MaybeDeepProfInfo = yes(DeepProfInfo),
-        DeepProfInfo = deep_profile_proc_info(MaybeRecInfo, _)
+        DeepProfInfo = deep_profile_proc_info(MaybeRecInfo, _, _)
     ;
         MaybeDeepProfInfo = no,
         MaybeRecInfo = no
     ).
 
-:- pred record_hlds_proc_static(hlds_proc_static::in, hlds_deep_excp_vars::in,
-    proc_info::in, proc_info::out) is det.
-
-record_hlds_proc_static(ProcStatic, ExcpVars, !ProcInfo) :-
-    proc_info_get_maybe_deep_profile_info(!.ProcInfo, MaybeDeepInfo0),
-    MaybeDeepLayoutInfo = yes(hlds_deep_layout(ProcStatic, ExcpVars)),
-    (
-        MaybeDeepInfo0 = yes(DeepInfo0),
-        DeepInfo = DeepInfo0 ^ deep_layout := MaybeDeepLayoutInfo
-    ;
-        MaybeDeepInfo0 = no,
-        DeepInfo = deep_profile_proc_info(no, MaybeDeepLayoutInfo)
-    ),
-    MaybeDeepInfo = yes(DeepInfo),
-    proc_info_set_maybe_deep_profile_info(MaybeDeepInfo, !ProcInfo).
-
 %-----------------------------------------------------------------------------%
 % Coverage Profiling.
 %-----------------------------------------------------------------------------%
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.453
diff -u -p -r1.453 hlds_out.m
--- compiler/hlds_out.m	29 Jul 2008 23:57:57 -0000	1.453
+++ compiler/hlds_out.m	3 Sep 2008 05:58:35 -0000
@@ -4103,7 +4103,7 @@ write_proc(Indent, AppendVarNums, Module
     (
         MaybeDeepProfileInfo = yes(DeepProfileInfo),
         DeepProfileInfo = deep_profile_proc_info(MaybeRecInfo,
-            MaybeDeepLayout),
+            MaybeDeepLayout, _),
         (
             MaybeRecInfo = yes(DeepRecInfo),
             DeepRecInfo = deep_recursion_info(Role, _),
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.246
diff -u -p -r1.246 hlds_pred.m
--- compiler/hlds_pred.m	29 Jul 2008 23:57:58 -0000	1.246
+++ compiler/hlds_pred.m	4 Sep 2008 10:10:43 -0000
@@ -1709,16 +1709,34 @@ attribute_list_to_attributes(Attributes,
 :- type deep_profile_proc_info
     --->    deep_profile_proc_info(
                 deep_rec        :: maybe(deep_recursion_info),
-                deep_layout     :: maybe(hlds_deep_layout)
-                                % The first field is set during the first,
-                                % tail recursion part of the deep profiling
-                                % transformation, if that is enabled.
-                                % The deep_layout field is set during the
-                                % second part; it will be bound to `no'
-                                % before and during the first part, and
-                                % to `yes' after the second. The contents
-                                % of this field govern what will go into
-                                % MR_ProcStatic structures.
+                                % This field is set during the first part of
+                                % the deep profiling transformation; tail
+                                % recursion, if that is enabled.
+                                
+                deep_layout     :: maybe(hlds_deep_layout),
+                                % This field is set during the second part; it
+                                % will be bound to `no' before and during the
+                                % first part, and to `yes' after the second.
+                                % The contents of this field govern what will
+                                % go into MR_ProcStatic structures.
+                
+                deep_orig_body  :: deep_original_body 
+                                % This field stores the origional body of a
+                                % procedure, before either part of the deep
+                                % profiling transformation was executed.  For
+                                % inner procedures created by the tail
+                                % recursion part of the deep profiling
+                                % transformation, it holds the origional body
+                                % of the outer procedure.
+            ).
+
+:- type deep_original_body
+    --->    deep_original_body(
+                dob_body            :: hlds_goal,
+                dob_head_vars       :: list(prog_var),
+                dob_instmap         :: instmap,
+                dob_vartypes        :: vartypes,
+                dob_detism          :: determinism
             ).
 
 :- type table_arg_infos
Index: compiler/layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/layout.m,v
retrieving revision 1.38
diff -u -p -r1.38 layout.m
--- compiler/layout.m	29 Jul 2008 23:57:58 -0000	1.38
+++ compiler/layout.m	4 Sep 2008 05:22:22 -0000
@@ -159,7 +159,8 @@
 :- type proc_layout_proc_static
     --->    proc_layout_proc_static(
                 hlds_proc_static        :: hlds_proc_static,
-                deep_excp_slots         :: deep_excp_slots
+                deep_excp_slots         :: deep_excp_slots,
+                deep_original_body      :: deep_original_body 
             ).
 
 :- type maybe_proc_id_and_more
Index: compiler/layout_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/layout_out.m,v
retrieving revision 1.98
diff -u -p -r1.98 layout_out.m
--- compiler/layout_out.m	29 Jul 2008 23:57:58 -0000	1.98
+++ compiler/layout_out.m	3 Sep 2008 05:25:53 -0000
@@ -2120,7 +2120,7 @@ output_data_addr_in_vector(Prefix, DataA
 output_proc_static_data_defn(RttiProcLabel, ProcLayoutProcStatic,
         !DeclSet, !IO) :-
     ProcLayoutProcStatic = proc_layout_proc_static(HLDSProcStatic,
-        DeepExcpVars),
+        DeepExcpVars, _),
     HLDSProcStatic = hlds_proc_static(FileName, LineNumber, IsInInterface,
         CallSites, CoveragePoints),
    
Index: compiler/proc_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/proc_gen.m,v
retrieving revision 1.27
diff -u -p -r1.27 proc_gen.m
--- compiler/proc_gen.m	21 Jul 2008 03:10:12 -0000	1.27
+++ compiler/proc_gen.m	4 Sep 2008 10:36:09 -0000
@@ -546,7 +546,8 @@ generate_deep_prof_info(ProcInfo, HLDSDe
         unexpected(this_file,
             "generate_deep_prof_info: no HLDS deep profiling layout info")
     ),
-    HLDSDeepLayout = hlds_deep_layout(HLDSProcStatic, HLDSExcpVars),
+    HLDSDeepLayout = hlds_deep_layout(HLDSProcStatic, HLDSExcpVars), 
+    HLDSDeepInfo ^ deep_orig_body = OriginalProcBody,
     HLDSExcpVars = hlds_deep_excp_vars(TopCSDVar, MiddleCSDVar,
         MaybeOldOutermostVar),
     proc_info_get_stack_slots(ProcInfo, StackSlots),
@@ -569,7 +570,8 @@ generate_deep_prof_info(ProcInfo, HLDSDe
     ),
     DeepExcpSlots = deep_excp_slots(TopCSDSlotNum, MiddleCSDSlotNum,
         OldOutermostSlotNum),
-    DeepProfInfo = proc_layout_proc_static(HLDSProcStatic, DeepExcpSlots).
+    DeepProfInfo = proc_layout_proc_static(HLDSProcStatic, DeepExcpSlots,
+        OriginalProcBody).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.143
diff -u -p -r1.143 stack_layout.m
--- compiler/stack_layout.m	13 Aug 2008 07:38:08 -0000	1.143
+++ compiler/stack_layout.m	4 Sep 2008 06:00:55 -0000
@@ -572,9 +572,39 @@ construct_proc_layout(ProcLayoutInfo, In
                 DeepProfiling = no,
                 IncludeVarTable = do_not_include_variable_table
             ),
-            represent_proc_as_bytecodes(HeadVars, Goal, InstMap, VarTypes,
-                VarNumMap, ModuleInfo, IncludeVarTable, Detism, !Info, 
-                ProcBytes)
+            
+            % When the proc static is availiable (used with deep profiling) use
+            % the version of the procedure saved before the deep profiling
+            % transformation as the program representation.
+            (
+                MaybeProcStatic = yes(ProcStatic),
+                DeepOriginalBody = ProcStatic ^ deep_original_body,
+                DeepOriginalBody = deep_original_body(BytecodeBody,
+                    BytecodeHeadVars, BytecodeInstMap, BytecodeVarTypes,
+                    BytecodeDetism),
+                some [!VarNumMap, !Counter] (
+                    !:VarNumMap = map.init,
+                    !:Counter = counter.init(1),
+                    goal_util.goal_vars(BytecodeBody, BodyVarSet),
+                    set.to_sorted_list(BodyVarSet, BodyVars),
+                    list.foldl2(add_var_to_var_number_map(VarSet),
+                        BodyVars, !VarNumMap, !Counter),
+                    list.foldl2(add_var_to_var_number_map(VarSet),
+                        BytecodeHeadVars, !VarNumMap, !.Counter, _),
+                    BytecodeVarNumMap = !.VarNumMap
+                )
+            ;
+                MaybeProcStatic = no,
+                BytecodeHeadVars = HeadVars,
+                BytecodeBody = Goal,
+                BytecodeInstMap = InstMap,
+                BytecodeVarTypes = VarTypes,
+                BytecodeDetism = Detism,
+                BytecodeVarNumMap = VarNumMap
+            ),
+            represent_proc_as_bytecodes(BytecodeHeadVars, BytecodeBody,
+                BytecodeInstMap, BytecodeVarTypes, BytecodeVarNumMap,
+                ModuleInfo, IncludeVarTable, BytecodeDetism, !Info, ProcBytes)
         ;
             ProcBytes = []
         ),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20080904/681dc00b/attachment.sig>


More information about the reviews mailing list