Commit 044a73da by Patrick Palka

Reduce nesting of parentheses in conditionals generated by genattrtab

gcc/ChangeLog:

	* genattrtab.c (write_test_expr): New parameter EMIT_PARENS
	which defaults to true.  Emit an outer pair of parentheses only if
	EMIT_PARENS.  When continuing a chain of && or || (or & or |),
	don't emit parentheses for the right-hand operand.

From-SVN: r235536
parent 565f4070
2016-04-27 Patrick Palka <ppalka@gcc.gnu.org>
* genattrtab.c (write_test_expr): New parameter EMIT_PARENS
which defaults to true. Emit an outer pair of parentheses only if
EMIT_PARENS. When continuing a chain of && or || (or & or |),
don't emit parentheses for the right-hand operand.
2016-04-27 Jeff Law <law@redhat.com> 2016-04-27 Jeff Law <law@redhat.com>
* tree-ssa-dom.c (record_temporary_equivalences): Fix typo in comment. * tree-ssa-dom.c (record_temporary_equivalences): Fix typo in comment.
......
...@@ -3416,7 +3416,10 @@ find_attrs_to_cache (rtx exp, bool create) ...@@ -3416,7 +3416,10 @@ find_attrs_to_cache (rtx exp, bool create)
/* Given a piece of RTX, print a C expression to test its truth value to OUTF. /* Given a piece of RTX, print a C expression to test its truth value to OUTF.
We use AND and IOR both for logical and bit-wise operations, so We use AND and IOR both for logical and bit-wise operations, so
interpret them as logical unless they are inside a comparison expression. */ interpret them as logical unless they are inside a comparison expression.
An outermost pair of parentheses is emitted around this C expression unless
EMIT_PARENS is false. */
/* Interpret AND/IOR as bit-wise operations instead of logical. */ /* Interpret AND/IOR as bit-wise operations instead of logical. */
#define FLG_BITWISE 1 #define FLG_BITWISE 1
...@@ -3432,16 +3435,16 @@ find_attrs_to_cache (rtx exp, bool create) ...@@ -3432,16 +3435,16 @@ find_attrs_to_cache (rtx exp, bool create)
#define FLG_OUTSIDE_AND 8 #define FLG_OUTSIDE_AND 8
static unsigned int static unsigned int
write_test_expr (FILE *outf, rtx exp, unsigned int attrs_cached, int flags) write_test_expr (FILE *outf, rtx exp, unsigned int attrs_cached, int flags,
bool emit_parens = true)
{ {
int comparison_operator = 0; int comparison_operator = 0;
RTX_CODE code; RTX_CODE code;
struct attr_desc *attr; struct attr_desc *attr;
/* In order not to worry about operator precedence, surround our part of if (emit_parens)
the expression with parentheses. */ fprintf (outf, "(");
fprintf (outf, "(");
code = GET_CODE (exp); code = GET_CODE (exp);
switch (code) switch (code)
{ {
...@@ -3575,8 +3578,18 @@ write_test_expr (FILE *outf, rtx exp, unsigned int attrs_cached, int flags) ...@@ -3575,8 +3578,18 @@ write_test_expr (FILE *outf, rtx exp, unsigned int attrs_cached, int flags)
|| GET_CODE (XEXP (exp, 1)) == EQ_ATTR || GET_CODE (XEXP (exp, 1)) == EQ_ATTR
|| (GET_CODE (XEXP (exp, 1)) == NOT || (GET_CODE (XEXP (exp, 1)) == NOT
&& GET_CODE (XEXP (XEXP (exp, 1), 0)) == EQ_ATTR))) && GET_CODE (XEXP (XEXP (exp, 1), 0)) == EQ_ATTR)))
attrs_cached {
= write_test_expr (outf, XEXP (exp, 1), attrs_cached, flags); bool need_parens = true;
/* No need to emit parentheses around the right-hand operand if we are
continuing a chain of && or || (or & or |). */
if (GET_CODE (XEXP (exp, 1)) == code)
need_parens = false;
attrs_cached
= write_test_expr (outf, XEXP (exp, 1), attrs_cached, flags,
need_parens);
}
else else
write_test_expr (outf, XEXP (exp, 1), attrs_cached, write_test_expr (outf, XEXP (exp, 1), attrs_cached,
flags | comparison_operator); flags | comparison_operator);
...@@ -3794,7 +3807,9 @@ write_test_expr (FILE *outf, rtx exp, unsigned int attrs_cached, int flags) ...@@ -3794,7 +3807,9 @@ write_test_expr (FILE *outf, rtx exp, unsigned int attrs_cached, int flags)
GET_RTX_NAME (code)); GET_RTX_NAME (code));
} }
fprintf (outf, ")"); if (emit_parens)
fprintf (outf, ")");
return attrs_cached; return attrs_cached;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment