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]

[match-and-simplify] reject conditional convert and commutative ops in result operand


I suppose we should reject conditional convert and commutative ops in
result operand ? since it would create 1-n mapping from match ->
result.

* genmatch.c
  (fatal_at): New overloaded function with source_location as first parameter.
  (has_opt_convert_or_commutative_ops): New function.
  (lower): Call has_opt_convert_or_commutative_ops.

Thanks,
Prathamesh
Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 216718)
+++ gcc/genmatch.c	(working copy)
@@ -83,6 +83,18 @@
 #if GCC_VERSION >= 4001
 __attribute__((format (printf, 2, 3)))
 #endif
+fatal_at (source_location src_loc, const char *msg, ...)
+{
+  va_list ap;
+  va_start (ap, msg);
+  error_cb (0, CPP_DL_FATAL, 0, src_loc, 0, msg, &ap);
+  va_end (ap);
+}
+
+static void
+#if GCC_VERSION >= 4001
+__attribute__((format (printf, 2, 3)))
+#endif
 fatal_at (const cpp_token *tk, const char *msg, ...)
 {
   va_list ap;
@@ -877,11 +889,46 @@
     simplifiers.safe_push (worklist[i]);
 }
 
+bool
+has_opt_convert_or_commutative_ops (operand *o)
+{
+  if (!o)
+    return false;
+
+  if (capture *c = dyn_cast<capture *> (o))
+    {
+      if (c->what)
+	return has_opt_convert_or_commutative_ops (c->what);
+      else
+	return false;
+    }
+
+  expr *e = dyn_cast<expr *> (o);
+  if (!e)
+    return false;
+
+  if (*e->operation == CONVERT0 || *e->operation == CONVERT1
+      || *e->operation == CONVERT2 || e->is_commutative)
+    return true;
+
+  for (unsigned i = 0; i < e->ops.length (); ++i)
+    if (has_opt_convert_or_commutative_ops (e->ops[i]))
+      return true;
+
+  return false;
+}
+
+  
+
 /* Lower the AST for everything in SIMPLIFIERS.  */
 
 static void
 lower (vec<simplify *>& simplifiers)
 {
+  for (unsigned i = 0; i < simplifiers.length (); ++i)
+    if (has_opt_convert_or_commutative_ops (simplifiers[i]->result))
+      fatal_at (simplifiers[i]->result_location, "result operand cannot contain conditional convert or commutative operator");
+
   auto_vec<simplify *> out_simplifiers0;
   for (unsigned i = 0; i < simplifiers.length (); ++i)
     lower_opt_convert (simplifiers[i], out_simplifiers0);

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