[m-rev.] inline mark_hp & restore_hp for MLDS back-end

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Mar 6 08:45:58 AEDT 2002


Estimated hours taken: 0.5
Branches: main

Improve the efficiency of code generated for
`--restore-hp-on-failure' with the MLDS back-end.

compiler/ml_optimize.m:
	Convert calls to private_builtin:mark_hp() and
	private_builtin:restore_hp() into the MLDS builtin
	mark_hp and restore_hp statements, so that they
	get generated as inline code.

Workspace: /home/ceres/fjh/mercury
Index: compiler/ml_optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_optimize.m,v
retrieving revision 1.17
diff -u -d -r1.17 ml_optimize.m
--- compiler/ml_optimize.m	3 Mar 2002 13:43:49 -0000	1.17
+++ compiler/ml_optimize.m	5 Mar 2002 21:45:14 -0000
@@ -42,6 +42,7 @@
 :- implementation.
 
 :- import_module ml_util, ml_code_util.
+:- import_module prog_data, prog_util.
 :- import_module builtin_ops, globals, options, error_util.
 
 :- import_module bool, int, list, require, std_util, string.
@@ -194,16 +195,20 @@
 
 %-----------------------------------------------------------------------------%
 
+:- inst g == ground.
+:- inst call ---> mlds__call(g, g, g, g, g, g).
+
 :- func optimize_in_call_stmt(opt_info, mlds__stmt) = mlds__stmt.
+:- mode optimize_in_call_stmt(in, in(call)) = out is det.
 
 optimize_in_call_stmt(OptInfo, Stmt0) = Stmt :-
+	Stmt0 = call(_Signature, FuncRval, _MaybeObject, CallArgs,
+		_Results, _IsTailCall),
 		% If we have a self-tailcall, assign to the arguments and
 		% then goto the top of the tailcall loop.
 	(
 		globals__lookup_bool_option(OptInfo ^ globals,
 			optimize_tailcalls, yes),
-		Stmt0 = call(_Signature, _FuncRval, _MaybeObject, CallArgs,
-			_Results, _IsTailCall),
 		can_optimize_tailcall(qual(OptInfo ^ module_name, 
 			OptInfo ^ entity_name), Stmt0)
 	->
@@ -225,6 +230,35 @@
 			GotoStatement
 			],
 		Stmt = block([], CallReplaceStatements)
+	;
+		% Convert calls to `mark_hp' and `restore_hp' to the
+		% corresponding MLDS instructions.  This ensures that
+		% they get generated as inline code.  (Without this
+		% they won't, since HLDS inlining doesn't get run again
+		% after the add_heap_ops pass that adds these calls.)
+		% This approach is better than running HLDS inlining
+		% again, both because it cheaper in compilation time
+		% and because inlining the C code doesn't help with
+		% the --target asm back-end, whereas generating the
+		% appropriate MLDS instructions does.
+		%
+		FuncRval = const(code_addr_const(proc(qual(ModName, 
+                        pred(predicate, _DefnModName, PredName, _Arity,
+				_CodeModel, _NonOutputFunc) - _ProcId),
+			_FuncSignature))), 
+		(
+			PredName = "mark_hp",
+			CallArgs = [mem_addr(Lval)],
+			AtomicStmt = mark_hp(Lval)
+		;
+			PredName = "restore_hp",
+			CallArgs = [Rval],
+			AtomicStmt = restore_hp(Rval)
+		),
+		mercury_private_builtin_module(PrivateBuiltin),
+		ModName = mercury_module_name_to_mlds(PrivateBuiltin)
+	->
+		Stmt = atomic(AtomicStmt)
 	;
 		Stmt = Stmt0
 	).

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