[m-rev.] for review: flatten nested blocks in the mlds

Peter Ross pro at missioncriticalit.com
Fri Feb 27 23:51:57 AEDT 2004


Hi,


===================================================================


Estimated hours taken: 1
Branches: main

Remove any unnecessary nesting of blocks in the mlds.  This allows us
to avoid a fixed limit of nesting in the MS Visual C compiler when
compiling xml.parse.chars.m.

compiler/ml_optimize.m:
	If a list of statements contains a block with no local
	variables, then bring the block up one level.

Index: compiler/ml_optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_optimize.m,v
retrieving revision 1.24
diff -u -r1.24 ml_optimize.m
--- compiler/ml_optimize.m	20 Feb 2004 02:39:57 -0000	1.24
+++ compiler/ml_optimize.m	27 Feb 2004 12:46:21 -0000
@@ -146,7 +146,8 @@
 			Defns0, Defns1, Statements0, Statements1),
 		maybe_eliminate_locals(OptInfo, Defns1, Defns,
 			Statements1, Statements2),
-		Statements = optimize_in_statements(OptInfo, Statements2),
+		maybe_flatten_block(Statements2, Statements3),
+		Statements = optimize_in_statements(OptInfo, Statements3),
 		Stmt = block(Defns, Statements)
 	;
 		Stmt0 = while(Rval, Statement0, Once),
@@ -461,6 +462,27 @@
 target_supports_break_and_continue_2(il) = no.
 target_supports_break_and_continue_2(java) = yes.
 % target_supports_break_and_continue_2(c_sharp) = yes.
+
+%-----------------------------------------------------------------------------%
+
+%
+% If the list of statements contains a block with no local variables,
+% then bring the block up one level.  This optimization is needed to avoid
+% a compiler limit in the Microsoft C compiler for too deeply nested blocks.
+%
+:- pred maybe_flatten_block(mlds__statements::in, mlds__statements::out) is det.
+
+maybe_flatten_block(!Stmts) :-
+	!:Stmts = list__condense(list__map(flatten_block, !.Stmts)).
+
+:- func flatten_block(mlds__statement) = mlds__statements.
+
+flatten_block(Statement) =
+	( Statement = mlds__statement(block([], BlockStatements), _) ->
+		BlockStatements
+	;
+		[Statement]
+	).
 
 %-----------------------------------------------------------------------------%
 


-- 
Peter Ross		
Software Engineer                                (Work)   +32 2 757 10 15
Mission Critical                                 (Mobile) +32 485 482 559
--------------------------------------------------------------------------
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