[m-rev.] diff: IL back-end: improve commit handling
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Jul 13 21:19:39 AEST 2001
Estimated hours taken: 1
Branches: main
Improve the efficiency and maintainability of the way we handle
commits for the IL back-end.
compiler/ml_code_gen.m:
Delete the IL-specific code for commit handling.
This code belongs in mlds_to_il.m.
compiler/mlds_to_il.m:
Handle do_commit instructions by just doing the equivalent of
"throw new mercury::runtime::Commit();". This is more efficient
than the old code that we used to generate, which would assign
the result of the newobj instruction to a variable or environment
field, only to immediately get it back again.
Workspace: /home/mars/fjh/ws1/mercury
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.93
diff -u -d -r1.93 ml_code_gen.m
--- compiler/ml_code_gen.m 2001/07/12 23:58:38 1.93
+++ compiler/ml_code_gen.m 2001/07/13 10:58:07
@@ -1563,9 +1563,11 @@
% {
% #endif
% MR_COMMIT_TYPE ref;
+ %
% void success() {
% MR_DO_COMMIT(ref);
% }
+ %
% MR_TRY_COMMIT(ref, {
% <Goal && success()>
% succeeded = FALSE;
@@ -1599,29 +1601,9 @@
{ DoCommitStmt = do_commit(lval(CommitRefLval)) },
{ DoCommitStatement =
mlds__statement(DoCommitStmt, MLDS_Context) },
- =(MLDSGenInfo),
- { ml_gen_info_get_module_info(MLDSGenInfo, ModuleInfo) },
- { module_info_globals(ModuleInfo, Globals) },
- { globals__get_target(Globals, Target) },
- { Target = il ->
- % XXX would be a good performance thing
- % to re-use the same pre-allocated commit
- % object over and over again, instead of
- % allocating them each time.
- NewCommitObject = mlds__statement(
- atomic(new_object(CommitRefLval, no,
- mlds__commit_type, no, no, [], [])),
- MLDS_Context),
- DoCommitBody = ml_gen_block([],
- [NewCommitObject,
- DoCommitStatement],
- Context)
- ;
- DoCommitBody = DoCommitStatement
- },
/* pop nesting level */
ml_gen_nondet_label_func(SuccessFuncLabel, Context,
- DoCommitBody, SuccessFunc),
+ DoCommitStatement, SuccessFunc),
ml_get_env_ptr(EnvPtrRval),
{ SuccessCont = success_cont(SuccessFuncLabelRval,
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.47
diff -u -d -r1.47 mlds_to_il.m
--- compiler/mlds_to_il.m 2001/07/13 10:44:01 1.47
+++ compiler/mlds_to_il.m 2001/07/13 11:10:21
@@ -1258,38 +1258,44 @@
br(label_target(Label))
]) }.
-statement_to_il(statement(do_commit(Ref), Context), Instrs) -->
+statement_to_il(statement(do_commit(_Ref), Context), Instrs) -->
% For commits, we use exception handling.
%
- % We generate code of the following form:
+ % For a do_commit instruction, we generate code equivalent
+ % to the following C++/C#/Java code:
+ %
+ % throw new mercury::runtime::Commit();
+ %
+ % In IL the code looks like this:
%
- % <load exception rval -- should be of a special commit type>
+ % newobj instance void
+ % ['mercury']'mercury'.'runtime'.'Commit'::.ctor()
% throw
- %
%
- load(Ref, RefLoadInstrs),
+ { NewObjInstr = newobj_constructor(il_commit_class_name) },
{ Instrs = tree__list([
context_node(Context),
comment_node("do_commit/1"),
- RefLoadInstrs,
+ instr_node(NewObjInstr),
instr_node(throw)
]) }.
-statement_to_il(statement(try_commit(Ref, GoalToTry, CommitHandlerGoal),
+statement_to_il(statement(try_commit(_Ref, GoalToTry, CommitHandlerGoal),
Context), Instrs) -->
% For commits, we use exception handling.
%
- % We generate code of the following form:
+ % For try_commit instructions, we generate IL code
+ % of the following form:
%
% .try {
- % GoalToTry
+ % <GoalToTry>
% leave label1
% } catch commit_type {
% pop // discard the exception object
- % CommitHandlerGoal
+ % <CommitHandlerGoal>
% leave label1
% }
% label1:
@@ -1301,9 +1307,7 @@
statement_to_il(CommitHandlerGoal, HandlerInstrsTree),
il_info_make_next_label(DoneLabel),
- { rval_to_type(lval(Ref), MLDSRefType) },
- DataRep =^ il_data_rep,
- { ClassName = mlds_type_to_ilds_class_name(DataRep, MLDSRefType) },
+ { ClassName = il_commit_class_name },
{ Instrs = tree__list([
context_node(Context),
comment_node("try_commit/3"),
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list