Update of /cvsroot/monetdb/pathfinder/compiler/core
In directory sc8-pr-cvs16:/tmp/cvs-serv18975/core
Modified Files:
coreopt.brg
Log Message:
-- Added some rewrites/optimization:
* 'let $a := e(...) return $a' is now replaced by 'e(...)'
* 'fn:item-sequence-to-node-sequence(e(...))' on an atomic value
is replaced by 'text { string (e(...)) }'
* '#pf:merge-adjacent-text-nodes((e1(...), e2(...))) is replaced by
'(e1(...), #pf:merge-adjacent-text-nodes(e2(...))' if e1(...) contains
no text nodes or '(#pf:merge-adjacent-text-nodes(e1(...)), e2(...))'
if e2(...) contains no text nodes.
Index: coreopt.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/core/coreopt.brg,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- coreopt.brg 21 Feb 2007 14:25:51 -0000 1.45
+++ coreopt.brg 8 May 2007 11:15:53 -0000 1.46
@@ -209,32 +209,36 @@
CoreExpr: SequenceTypeCast = 3 (10);
CoreExpr: flwr (OptBindExpr, CoreExpr) = 4 (10);
+
CoreExpr: flwr (for_ (forbind (forvars (var, nil),
Atom),
nil), var) = 5 (10);
+CoreExpr: flwr (let (letbind (var, CoreExpr),
+ nil), var) = 6 (10);
+
OptBindExpr: for_ (forbind (forvars (var, OptVar),
Atom),
- OptBindExpr) = 6 (10);
+ OptBindExpr) = 7 (10);
-OptVar: nil = 7 (10);
-OptVar: var = 8 (10);
+OptVar: nil = 8 (10);
+OptVar: var = 9 (10);
-OptBindExpr: let (letbind (var, Atom), OptBindExpr) = 9 (10);
+OptBindExpr: let (letbind (var, Atom), OptBindExpr) = 10 (10);
OptBindExpr: let (letbind (var,
flwr (let (letbind (var,
CoreExpr),
nil),
CoreExpr)),
- OptBindExpr) = 10 (10);
+ OptBindExpr) = 11 (10);
OptBindExpr: let (letbind (var,
flwr (let (letbind (var,
CoreExpr),
OptBindExpr),
CoreExpr)),
- OptBindExpr) = 11 (10);
-OptBindExpr: let (letbind (var, CoreExpr), OptBindExpr) = 12 (10);
-OptBindExpr: nil = 13 (10);
+ OptBindExpr) = 12 (10);
+OptBindExpr: let (letbind (var, CoreExpr), OptBindExpr) = 13 (10);
+OptBindExpr: nil = 14 (10);
CoreExpr: typesw (Atom,
cases (case_ (SequenceType,
@@ -294,7 +298,7 @@
CoreExpr: apply (FunctionArgs) = 61 (10);
CoreExpr: apply (arg (Atom, nil)) = 62 (10);
CoreExpr: apply (arg (Atom, arg (Atom, nil))) = 63 (10);
-
+
FunctionArgs: arg (Atom, FunctionArgs) = 64 (10);
FunctionArgs: arg (SequenceTypeCast, FunctionArgs) = 65 (10);
FunctionArgs: nil = 66 (10);
@@ -338,6 +342,11 @@
/* Pathfinder extension: XRPC */
CoreExpr: xrpc (Atom, CoreExpr) = 77 (10);
+/* push down #pf:merge-adjacent-text-nodes */
+CoreExpr: flwr (let (letbind (var, seq (CoreExpr,
+ CoreExpr)),
+ nil), apply (arg (var, nil))) = 78 (10);
+
%%
/*
@@ -367,7 +376,9 @@
#define LRR(p) R(R(L(p)))
#define LLLL(p) L(L(L(L(p))))
#define LRLL(p) L(L(R(L(p))))
+#define LLRL(p) L(R(L(L(p))))
#define LRLR(p) R(L(R(L(p))))
+#define LLRR(p) R(R(L(L(p))))
#define RLR(p) R(L(R(p)))
#define RLL(p) L(L(R(p)))
@@ -453,7 +464,7 @@
break;
/* OptBindExpr: let (letbind (var, Atom), OptBindExpr) */
- case 9:
+ case 10:
/*
* Unfold atoms (a is an atom)
*
@@ -547,10 +558,22 @@
}
break;
+ /* CoreExpr: flwr (let (letbind (var, CoreExpr),
+ nil), var) */
+ case 6:
+ /* replace unnecessary let binding
+ 'let $a := ... return $a' by its input '...' */
+ if (LLL(p)->sem.var == R(p)->sem.var) {
+ *p = *LLR(p);
+ relabel (p, kids);
+ rewritten = true;
+ }
+ break;
+
/* OptBindExpr: for_ (forbind (forvars (var, OptVar),
Atom),
OptBindExpr) */
- case 6:
+ case 7:
/*
* If we iterate over a sequence that we know (from static
* typing) to always have length 1, replace the `for' by
@@ -586,7 +609,7 @@
nil),
CoreExpr)),
OptBindExpr) */
- case 10:
+ case 11:
/*
* Remove a nested let block:
*
@@ -620,7 +643,7 @@
OptBindExpr)),
CoreExpr),
OptBindExpr) */
- case 11:
+ case 12:
/*
* Remove a nested let block:
*
@@ -1030,6 +1053,14 @@
rewritten = true;
break;
}
+ else if (PFty_subtype (TY(LL(p)), PFty_atomic ())) {
+ PFfun_t *fn_string
+ = function (PFqname (PFns_fn, "string"));
+ *p = *constr(p_text, apply (fn_string,
+ arg (LL(p), nil ())));
+ rewritten = true;
+ break;
+ }
}
/*
@@ -1141,6 +1172,35 @@
}
break;
+ /* CoreExpr: flwr (let (letbind (var, seq (CoreExpr,
+ CoreExpr),
+ nil), apply (arg (var, nil))) */
+ case 78:
+ /* Special rewrite: Push down the #pf:merge-adjacent-text-nodes
+ function if its input is a sequence where at least one argument
+ does not contain text nodes. */
+ if (LLL(p)->sem.var == RLL(p)->sem.var &&
+ !PFqname_eq (R(p)->sem.fun->qname,
+ PFqname (PFns_pf,
+ "merge-adjacent-text-nodes"))) {
+ if (!PFty_subtype (PFty_opt (PFty_text ()),
+ TY(LLRL(p)))) {
+ /* push #pf:matn into right sequence constructor input */
+ PFcnode_t *lseq = LLRL(p);
+ LLR(p) = LLRR(p);
+ *p = *seq (lseq, flwr (L(p), R(p)));
+ } else if (!PFty_subtype (PFty_opt (PFty_text ()),
+ TY(LLRR(p)))) {
+ /* push #pf:matn into left sequence constructor input */
+ PFcnode_t *rseq = LLRR(p);
+ LLR(p) = LLRL(p);
+ *p = *seq (flwr (L(p), R(p)), rseq);
+ }
+ relabel (p, kids);
+ rewritten = true;
+ }
+ break;
+
default:
break;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins