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]

Proposal and patch: Allow whitespace in md constraints


How about making it possible to align those constraint alternatives,
for easier reading?  I believe it makes for less and/or fewer mistakes.
From the upcoming MMIX port:

(define_insn "movdi"
  [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r, r ,x,r,m ,r,m,r")
	(match_operand:DI 1 "general_operand"	    "r,LS,KR,r,x,HI,m,r,s"))]
  ""
  ...)

IMHO it is faster to grok than this:

(define_insn "movdi"
  [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,x,r,m,r,m,r")
	(match_operand:DI 1 "general_operand"	    "r,LS,KR,r,x,HI,m,r,s"))]
  ""
  ...)

(The exact reason why I'm having multiple constraint letters in this
particular instance is perhaps a bad one; GCC sometimes passes the
constant as a CONST_DOUBLE in VOIDmode, sometimes as a CONST_INT, so I
have to catch them both, which I could have done using just
EXTRA_CONSTRAINTS letters for DImode, but hopefully you get the point.
And yes, I need to add a "n" alternative.)

Then take a look at, for instance, movdf+1 in "m68k.md".  Brr! :-)
Taste is different, so spaces can go after the comma as well, or anywhere
except the first position (just laziness; a trivial change to
validate_pattern in genrecog.c which in hindsight would have been easier
than trying to explain why not).

Does this feature sound good, and is this ok to commit?

Mon Feb 14 11:50:27 2000  Hans-Peter Nilsson  <hp@bitrange.com>

	* md.texi (Simple Constraints): Add item about whitespace.
	* genoutput.c (strip_whitespace): New.
	(scan_operands) [MATCH_OPERAND, MATCH_SCRATCH]: Call
	strip_whitespace for constraints.

Index: md.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/md.texi,v
retrieving revision 1.38
diff -p -c -r1.38 md.texi
*** md.texi	2000/02/14 10:37:12	1.38
--- md.texi	2000/02/14 10:58:45
*************** which describes one kind of operand that
*** 665,670 ****
--- 665,676 ----
  the letters that are allowed:
  
  @table @asis
+ @item whitespace
+ Whitespace characters are ignored and can be inserted at any position
+ except the first.  This enables each alternative for different operands to
+ be visually aligned in the machine description even if they have different
+ number of constraints and modifiers.
+ 
  @cindex @samp{m} in constraint
  @cindex memory references in constraints
  @item @samp{m}
Index: genoutput.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/genoutput.c,v
retrieving revision 1.46
diff -p -c -r1.46 genoutput.c
*** genoutput.c	2000/02/05 04:56:11	1.46
--- genoutput.c	2000/02/14 10:58:54
*************** struct obstack *rtl_obstack = &obstack;
*** 104,109 ****
--- 104,110 ----
  #define obstack_chunk_free free
  
  static int n_occurrences PARAMS ((int, char *));
+ static void strip_whitespace PARAMS ((char *));
  
  /* insns in the machine description are assigned sequential code numbers
     that are used by insn-recog.c (produced by genrecog) to communicate
*************** scan_operands (d, part, this_address_p, 
*** 439,444 ****
--- 440,446 ----
        d->operand[opno].strict_low = this_strict_low;
        d->operand[opno].predicate = XSTR (part, 1);
        d->operand[opno].constraint = XSTR (part, 2);
+       strip_whitespace (d->operand[opno].constraint);
        if (XSTR (part, 2) != 0 && *XSTR (part, 2) != 0)
  	d->operand[opno].n_alternatives
  	  = n_occurrences (',', XSTR (part, 2)) + 1;
*************** scan_operands (d, part, this_address_p, 
*** 464,469 ****
--- 466,472 ----
        d->operand[opno].strict_low = 0;
        d->operand[opno].predicate = "scratch_operand";
        d->operand[opno].constraint = XSTR (part, 1);
+       strip_whitespace (d->operand[opno].constraint);
        if (XSTR (part, 1) != 0 && *XSTR (part, 1) != 0)
  	d->operand[opno].n_alternatives
  	  = n_occurrences (',', XSTR (part, 1)) + 1;
*************** n_occurrences (c, s)
*** 968,971 ****
--- 971,989 ----
    while (*s)
      n += (*s++ == c);
    return n;
+ }
+ 
+ /* Remove whitespace in `s' by moving up characters until the end.
+    Use a simple method since we will not use it for large data.  */
+ static void
+ strip_whitespace (s)
+      char *s;
+ {
+   while (*s)
+     {
+       if (ISSPACE (*s))
+ 	memmove (s, s + 1, strlen (s + 1) + 1);
+       else
+ 	s++;
+     }
  }

brgds, H-P


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