[m-rev.] Re: for review: procedure representations for the deep profiler

Paul Bone pbone at csse.unimelb.edu.au
Thu Sep 13 11:24:50 AEST 2007


On Tue, Sep 11, 2007 at 11:47:13AM +1000, Zoltan Somogyi wrote:
> For review by anyone.
> 
> Zoltan.
> 
> mdbcomp/program_representation.m:
> 	Extend the existing data structures for representing a procedure body
> 	to represent a procedure (complete with name), a module and a program.
> 	The name is implemented a string_proc_label, a form of proc_label that
> 	can be written out to files. This replaces the old proc_id type the
> 	deep profiler.
> 
> 	Extend the representation of switches to record the identity of the
> 	variable being switched on, and the cons_ids of the arms. Without the
> 	former, we cannot be sure when a variable is first used, and the latter
> 	is needed for meaningful prettyprinting of procedure bodies.
> 
> 	Add code for reading in files of bytecodes, and for making sense of the
> 	bytecodes themselves. (It is this code that uses foreign enums.)
> 


This additional change factors out some duplicated code.

That's all!

Thanks!


--- mercury-zs/mdbcomp/program_representation.m	2007-09-12 21:09:08.000000000 +1000
+++ mercury-compiler-rotd-2007-09-09/mdbcomp/program_representation.m	2007-09-13 09:43:51.000000000 +1000
@@ -909,52 +909,6 @@
             read_cases(VarNumRep, ByteCode, StringTable, Info, Cases, !Pos),
             Goal = switch_rep(Var, Cases)
         ;
-            GoalType = goal_assign,
-            read_var(VarNumRep, ByteCode, Target, !Pos),
-            read_var(VarNumRep, ByteCode, Source, !Pos),
-            AtomicGoal = unify_assign_rep(Target, Source),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_construct,
-            read_var(VarNumRep, ByteCode, Var, !Pos),
-            read_cons_id(ByteCode, StringTable, ConsId, !Pos),
-            read_vars(VarNumRep, ByteCode, ArgVars, !Pos),
-            AtomicGoal = unify_construct_rep(Var, ConsId, ArgVars),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_deconstruct,
-            read_var(VarNumRep, ByteCode, Var, !Pos),
-            read_cons_id(ByteCode, StringTable, ConsId, !Pos),
-            read_vars(VarNumRep, ByteCode, ArgVars, !Pos),
-            AtomicGoal = unify_deconstruct_rep(Var, ConsId, ArgVars),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_partial_construct,
-            read_var(VarNumRep, ByteCode, Var, !Pos),
-            read_cons_id(ByteCode, StringTable, ConsId, !Pos),
-            read_maybe_vars(VarNumRep, ByteCode, MaybeVars, !Pos),
-            AtomicGoal = partial_construct_rep(Var, ConsId, MaybeVars),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_partial_deconstruct,
-            read_var(VarNumRep, ByteCode, Var, !Pos),
-            read_cons_id(ByteCode, StringTable, ConsId, !Pos),
-            read_maybe_vars(VarNumRep, ByteCode, MaybeVars, !Pos),
-            AtomicGoal = partial_deconstruct_rep(Var, ConsId, MaybeVars),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_simple_test,
-            read_var(VarNumRep, ByteCode, Var1, !Pos),
-            read_var(VarNumRep, ByteCode, Var2, !Pos),
-            AtomicGoal = unify_simple_test_rep(Var1, Var2),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
             GoalType = goal_scope,
             read_byte(ByteCode, MaybeCutByte, !Pos),
             ( MaybeCutByte = 0 ->
@@ -967,54 +921,80 @@
             read_goal(VarNumRep, ByteCode, StringTable, Info, SubGoal, !Pos),
             Goal = scope_rep(SubGoal, MaybeCut)
         ;
-            GoalType = goal_ho_call,
-            read_var(VarNumRep, ByteCode, Var, !Pos),
-            read_vars(VarNumRep, ByteCode, Args, !Pos),
-            AtomicGoal = higher_order_call_rep(Var, Args),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_method_call,
-            read_var(VarNumRep, ByteCode, Var, !Pos),
-            read_method_num(ByteCode, MethodNum, !Pos),
-            read_vars(VarNumRep, ByteCode, Args, !Pos),
-            AtomicGoal = method_call_rep(Var, MethodNum, Args),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_cast,
-            read_var(VarNumRep, ByteCode, OutputVar, !Pos),
-            read_var(VarNumRep, ByteCode, InputVar, !Pos),
-            AtomicGoal = cast_rep(OutputVar, InputVar),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_plain_call,
-            read_string_via_offset(ByteCode, StringTable, ModuleName, !Pos),
-            read_string_via_offset(ByteCode, StringTable, PredName, !Pos),
-            read_vars(VarNumRep, ByteCode, Args, !Pos),
-            AtomicGoal = plain_call_rep(ModuleName, PredName, Args),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_builtin_call,
-            read_string_via_offset(ByteCode, StringTable, ModuleName, !Pos),
-            read_string_via_offset(ByteCode, StringTable, PredName, !Pos),
-            read_vars(VarNumRep, ByteCode, Args, !Pos),
-            AtomicGoal = builtin_call_rep(ModuleName, PredName, Args),
-            read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
-                AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_event_call,
-            read_string_via_offset(ByteCode, StringTable, EventName, !Pos),
-            read_vars(VarNumRep, ByteCode, Args, !Pos),
-            AtomicGoal = event_call_rep(EventName, Args),
-            read_atomic_info(VarNumRep, ByteCode, StringTable,
-                Info, AtomicGoal, Goal, !Pos)
-        ;
-            GoalType = goal_foreign,
-            read_vars(VarNumRep, ByteCode, Args, !Pos),
-            AtomicGoal = pragma_foreign_code_rep(Args),
+            % All atomic goals are handled in the following disjunction.
+            (
+                GoalType = goal_assign,
+                read_var(VarNumRep, ByteCode, Target, !Pos),
+                read_var(VarNumRep, ByteCode, Source, !Pos),
+                AtomicGoal = unify_assign_rep(Target, Source)
+            ;
+                GoalType = goal_construct,
+                read_var(VarNumRep, ByteCode, Var, !Pos),
+                read_cons_id(ByteCode, StringTable, ConsId, !Pos),
+                read_vars(VarNumRep, ByteCode, ArgVars, !Pos),
+                AtomicGoal = unify_construct_rep(Var, ConsId, ArgVars)
+            ;
+                GoalType = goal_deconstruct,
+                read_var(VarNumRep, ByteCode, Var, !Pos),
+                read_cons_id(ByteCode, StringTable, ConsId, !Pos),
+                read_vars(VarNumRep, ByteCode, ArgVars, !Pos),
+                AtomicGoal = unify_deconstruct_rep(Var, ConsId, ArgVars)
+            ;
+                GoalType = goal_partial_construct,
+                read_var(VarNumRep, ByteCode, Var, !Pos),
+                read_cons_id(ByteCode, StringTable, ConsId, !Pos),
+                read_maybe_vars(VarNumRep, ByteCode, MaybeVars, !Pos),
+                AtomicGoal = partial_construct_rep(Var, ConsId, MaybeVars)
+            ;
+                GoalType = goal_partial_deconstruct,
+                read_var(VarNumRep, ByteCode, Var, !Pos),
+                read_cons_id(ByteCode, StringTable, ConsId, !Pos),
+                read_maybe_vars(VarNumRep, ByteCode, MaybeVars, !Pos),
+                AtomicGoal = partial_deconstruct_rep(Var, ConsId, MaybeVars)
+            ;
+                GoalType = goal_simple_test,
+                read_var(VarNumRep, ByteCode, Var1, !Pos),
+                read_var(VarNumRep, ByteCode, Var2, !Pos),
+                AtomicGoal = unify_simple_test_rep(Var1, Var2)
+            ;
+                GoalType = goal_ho_call,
+                read_var(VarNumRep, ByteCode, Var, !Pos),
+                read_vars(VarNumRep, ByteCode, Args, !Pos),
+                AtomicGoal = higher_order_call_rep(Var, Args)
+            ;
+                GoalType = goal_method_call,
+                read_var(VarNumRep, ByteCode, Var, !Pos),
+                read_method_num(ByteCode, MethodNum, !Pos),
+                read_vars(VarNumRep, ByteCode, Args, !Pos),
+                AtomicGoal = method_call_rep(Var, MethodNum, Args)
+            ;
+                GoalType = goal_cast,
+                read_var(VarNumRep, ByteCode, OutputVar, !Pos),
+                read_var(VarNumRep, ByteCode, InputVar, !Pos),
+                AtomicGoal = cast_rep(OutputVar, InputVar)
+            ;
+                GoalType = goal_plain_call,
+                read_string_via_offset(ByteCode, StringTable, ModuleName, !Pos),
+                read_string_via_offset(ByteCode, StringTable, PredName, !Pos),
+                read_vars(VarNumRep, ByteCode, Args, !Pos),
+                AtomicGoal = plain_call_rep(ModuleName, PredName, Args)
+            ;
+                GoalType = goal_builtin_call,
+                read_string_via_offset(ByteCode, StringTable, ModuleName, !Pos),
+                read_string_via_offset(ByteCode, StringTable, PredName, !Pos),
+                read_vars(VarNumRep, ByteCode, Args, !Pos),
+                AtomicGoal = builtin_call_rep(ModuleName, PredName, Args)
+            ;
+                GoalType = goal_event_call,
+                read_string_via_offset(ByteCode, StringTable, EventName, !Pos),
+                read_vars(VarNumRep, ByteCode, Args, !Pos),
+                AtomicGoal = event_call_rep(EventName, Args)
+            ;
+                GoalType = goal_foreign,
+                read_vars(VarNumRep, ByteCode, Args, !Pos),
+                AtomicGoal = pragma_foreign_code_rep(Args)
+            ),
+            % This is done for all atomic goals.
             read_atomic_info(VarNumRep, ByteCode, StringTable, Info,
                 AtomicGoal, Goal, !Pos)
         )



--------------------------------------------------------------------------
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