This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: An old patch: [Fwd: Re: [G95-develop] Expression reordering]


Paul Brook wrote:

As you say there is no way to represent the semantics we desire in the current gcc backend. The current optimiser behaviour should be correct but overly conservative.



I thought about this some more, and putting a C sequence point in places where the optimizer shouldn't optimize across (i.e. parentheses in fortran) should do the trick, even if the optimizers become more aggressive, but as nobody has suggested this on the gcc list, I guess there must be more to it than I think.


If you could update your patch, it would be more than welcome. Even if we can't pass the information on to the backend I would still like to get it right in the frontend. During translation to gcc trees we can just skip it and move to the contained expression.

There are probably a few other places that may need to be taught about this new operator. Expression resolution routines, the tree dumper (invoked using -fdump-parse-tree), and folding/simplification spring to mind.


Yeah, I had accidentally not included those parts. They were included in the first patch I had sent to the g95 list back then. I attached that patch below, the matchexpr.c part needs to be replaced with the one I posted before. Sorry, for some reason I can't cut&paste currently.


I'm afraid you will need a gcc copyright assignment before we can accept patches from you. Alternatively please file a bug report so we don't forget about this issue, possibly referencing this thread.

Since I posted that patch well before g95 forked, I think my copyright assignment should suffice. If you still think that's not the case, I'll file a bug and see if I can get a new Copyright Assignment in place. Whom do I have to contact?


Regards,
- Tobi
--- expr.c	11 Oct 2002 03:50:24 -0000	1.87
+++ expr.c	18 Oct 2002 17:07:26 -0000
@@ -736,6 +736,13 @@
   p->op2 = NULL;
 
   switch(p->operator) {
+  case INTRINSIC_PARENTHESES:
+    if (op1->expr_type == EXPR_CONSTANT)
+      result = op1;
+    else
+      result = NULL;
+    break;
+
   case INTRINSIC_UPLUS:
     result = g95_uplus(op1);
     break;
@@ -1627,6 +1634,7 @@
     case INTRINSIC_LT:      g95_status("< ");     break;
     case INTRINSIC_LE:      g95_status("<= ");    break;
     case INTRINSIC_NOT:     g95_status("NOT ");   break;
+    case INTRINSIC_PARENTHESES: g95_status("parens "); break;
 
     default:
       g95_internal_error("g95_show_expr(): Bad intrinsic in expression!");
--- g95.h	11 Oct 2002 03:50:24 -0000	1.201
+++ g95.h	18 Oct 2002 17:09:06 -0000
@@ -145,7 +145,7 @@
 	       INTRINSIC_AND, INTRINSIC_OR, INTRINSIC_EQV, INTRINSIC_NEQV,
 	       INTRINSIC_EQ, INTRINSIC_NE, INTRINSIC_GT, INTRINSIC_GE,
 	       INTRINSIC_LT, INTRINSIC_LE, INTRINSIC_NOT, INTRINSIC_USER,
-	       INTRINSIC_ASSIGN
+	       INTRINSIC_ASSIGN, INTRINSIC_PARENTHESES
 } g95_intrinsic_op;
 
 /* This macro is the number of intrinsic operators that exist.
--- matchexp.c	23 Jun 2002 22:46:32 -0000	1.18
+++ matchexp.c	18 Oct 2002 17:10:08 -0000
@@ -113,6 +113,8 @@
 
 static match match_primary(g95_expr **result) {
 match m;
+g95_expr *e1, *e2;
+locus where;
 
   m = g95_match_literal_constant(result, 0);
   if (m != MATCH_NO) return m;
@@ -125,15 +127,29 @@
 
 /* Match an expression in parenthesis */
 
+  e1 = e2 = NULL;
+  where = *g95_current_locus();
   if (g95_match_char('(') != MATCH_YES) return MATCH_NO;
 
-  m = g95_match_expr(result);
+  m = g95_match_expr(&e1);
   if (m == MATCH_NO) goto syntax;
   if (m == MATCH_ERROR) return m;
 
   m = g95_match_char(')');
   if (m == MATCH_NO)
     g95_error("Expected a right parenthesis in expression at %C");
+
+  /* now we have the expression inside the parentheses, build the 
+     expression pointing to it */
+  e2 = g95_get_expr();
+  e2->expr_type = EXPR_OP;
+  e2->ts        = e1->ts;
+  e2->rank      = e1->rank;
+  e2->operator  = INTRINSIC_PARENTHESES;
+  e2->where     = where;
+  e2->op1       = e1;
+  e2->op2       = NULL;
+  *result = e2;
 
   if (m != MATCH_YES) {
     g95_free_expr(*result);
--- resolve.c	11 Oct 2002 04:14:47 -0000	1.83
+++ resolve.c	18 Oct 2002 17:10:31 -0000
@@ -890,6 +890,7 @@
   case INTRINSIC_NOT:
   case INTRINSIC_UPLUS:
   case INTRINSIC_UMINUS:
+  case INTRINSIC_PARENTHESES:
     if (g95_resolve_expr(e->op1) == FAILURE) return FAILURE;
     break;
   }
@@ -994,6 +995,10 @@
 	    g95_typename(&op2->ts));
 
     goto bad_op;
+
+  case INTRINSIC_PARENTHESES:
+    e->ts = op1->ts;
+    break;
 
   case INTRINSIC_USER:
     if (op2 == NULL)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]