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]

[PATCH] Document a bunch of expression tree codes


The following patch documents a number of expression tree codes
in c-tree.texi.  Whilst investigating a PR related to UN*_EXPR,
I noticed that these codes weren't documented.  Then whilst I was
there I noticed that EXACT_DIV_EXPR wasn't documented, which in
turn required documenting FLOOR_DIV_EXPR and CEIL_DIV_EXPR, etc...
I also noticed that PREINCREMENT_EXPR, POSTINCREMENT_EXPR and
several other tree codes were documented, but didn't appear in
the index.

I'm posting this in the hope that someone can double check for
(American) spelling, grammar and technical accuracy.  For example,
if I understand these tree codes correctly we should be able to
constant fold

	NOT_EXPR (UNORDERED_EXPR (x, y)) => ORDERED_EXPR (x, y)
	NOT_EXPR (ORDERED_EXPR (x, y)) => UNORDERED_EXPR (x, y)
	UNORDERED (x, x) => isnan (x)
	ORDERED (x, x) => NOT_EXPR (isnan (x))
	isnan (x) || isnan (y) => UNORDERED (x, y)
	!isnan (x) && !isnan (y) => ORDERED (x, y)

And if -fno-trapping-math,

	NOT_EXPR (UNLT_EXPR (x, y)) => GE_EXPR (x, y)

And if -fno-trapping-math and HONOR_NANS (mode),

	NOT_EXPR (GE_EXPR (x, y)) => UNLT_EXPR (x, y)

and likewise for inverting the remaining comparison operators.
Does this look correct?


The following patch has been tested on i686-pc-linux-gnu with
"make dvi" and inspecting the output.


2004-05-25  Roger Sayle  <roger@eyesopen.com>

	* doc/c-tree.texi (Expressions): Document FLOOR_DIV_EXPR,
	CEIL_DIV_EXPR, ROUND_DIV_EXPR, FLOOR_MOD_EXPR, CEIL_MOD_EXPR,
	ROUND_MOD_EXPR, EXACT_DIV_EXPR, ORDERED_EXPR, UNORDERED_EXPR,
	UNLT_EXPR, UNLE_EXPR, UNGT_EXPR, UNGE_EXPR, UNEQ_EXPR.  Improve
	documentation of TRUNC_DIV_EXPR, TRUNC_MOD_EXPR and comparison
	operations.  Add missing (but documented) tree nodes to the index.


Index: c-tree.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/c-tree.texi,v
retrieving revision 1.54
diff -c -3 -p -r1.54 c-tree.texi
*** c-tree.texi	13 May 2004 06:40:23 -0000	1.54
--- c-tree.texi	26 May 2004 01:05:56 -0000
*************** This macro returns the attributes on the
*** 1692,1697 ****
--- 1692,1698 ----
  @node Expression trees
  @section Expressions
  @cindex expression
+ @findex TREE_TYPE
  @findex TREE_OPERAND
  @tindex INTEGER_CST
  @findex TREE_INT_CST_HIGH
*************** This macro returns the attributes on the
*** 1712,1717 ****
--- 1713,1722 ----
  @tindex ABS_EXPR
  @tindex BIT_NOT_EXPR
  @tindex TRUTH_NOT_EXPR
+ @tindex PREDECREMENT_EXPR
+ @tindex PREINCREMENT_EXPR
+ @tindex POSTDECREMENT_EXPR
+ @tindex POSTINCREMENT_EXPR
  @tindex ADDR_EXPR
  @tindex INDIRECT_REF
  @tindex FIX_TRUNC_EXPR
*************** This macro returns the attributes on the
*** 1720,1725 ****
--- 1725,1731 ----
  @tindex CONJ_EXPR
  @tindex REALPART_EXPR
  @tindex IMAGPART_EXPR
+ @tindex NON_LVALUE_EXPR
  @tindex NOP_EXPR
  @tindex CONVERT_EXPR
  @tindex THROW_EXPR
*************** This macro returns the attributes on the
*** 1736,1764 ****
  @tindex PLUS_EXPR
  @tindex MINUS_EXPR
  @tindex MULT_EXPR
  @tindex TRUNC_DIV_EXPR
  @tindex TRUNC_MOD_EXPR
! @tindex RDIV_EXPR
  @tindex LT_EXPR
  @tindex LE_EXPR
  @tindex GT_EXPR
  @tindex GE_EXPR
  @tindex EQ_EXPR
  @tindex NE_EXPR
! @tindex INIT_EXPR
  @tindex MODIFY_EXPR
  @tindex COMPONENT_REF
  @tindex COMPOUND_EXPR
  @tindex COND_EXPR
  @tindex CALL_EXPR
- @tindex CONSTRUCTOR
- @tindex COMPOUND_LITERAL_EXPR
  @tindex STMT_EXPR
  @tindex BIND_EXPR
  @tindex LOOP_EXPR
  @tindex EXIT_EXPR
  @tindex CLEANUP_POINT_EXPR
! @tindex ARRAY_REF
  @tindex VTABLE_REF
  @tindex VA_ARG_EXPR

--- 1742,1788 ----
  @tindex PLUS_EXPR
  @tindex MINUS_EXPR
  @tindex MULT_EXPR
+ @tindex RDIV_EXPR
  @tindex TRUNC_DIV_EXPR
+ @tindex FLOOR_DIV_EXPR
+ @tindex CEIL_DIV_EXPR
+ @tindex ROUND_DIV_EXPR
  @tindex TRUNC_MOD_EXPR
! @tindex FLOOR_MOD_EXPR
! @tindex CEIL_MOD_EXPR
! @tindex ROUND_MOD_EXPR
! @tindex EXACT_DIV_EXPR
! @tindex ARRAY_REF
! @tindex ARRAY_RANGE_REF
  @tindex LT_EXPR
  @tindex LE_EXPR
  @tindex GT_EXPR
  @tindex GE_EXPR
  @tindex EQ_EXPR
  @tindex NE_EXPR
! @tindex ORDERED_EXPR
! @tindex UNORDERED_EXPR
! @tindex UNLT_EXPR
! @tindex UNLE_EXPR
! @tindex UNGT_EXPR
! @tindex UNGE_EXPR
! @tindex UNEQ_EXPR
  @tindex MODIFY_EXPR
+ @tindex INIT_EXPR
  @tindex COMPONENT_REF
  @tindex COMPOUND_EXPR
  @tindex COND_EXPR
  @tindex CALL_EXPR
  @tindex STMT_EXPR
  @tindex BIND_EXPR
  @tindex LOOP_EXPR
  @tindex EXIT_EXPR
  @tindex CLEANUP_POINT_EXPR
! @tindex CONSTRUCTOR
! @tindex COMPOUND_LITERAL_EXPR
! @tindex SAVE_EXPR
! @tindex TARGET_EXPR
! @tindex AGGR_INIT_EXPR
  @tindex VTABLE_REF
  @tindex VA_ARG_EXPR

*************** not matter.
*** 2057,2081 ****
  @itemx PLUS_EXPR
  @itemx MINUS_EXPR
  @itemx MULT_EXPR
- @itemx TRUNC_DIV_EXPR
- @itemx TRUNC_MOD_EXPR
- @itemx RDIV_EXPR
  These nodes represent various binary arithmetic operations.
  Respectively, these operations are addition, subtraction (of the second
! operand from the first), multiplication, integer division, integer
! remainder, and floating-point division.  The operands to the first three
! of these may have either integral or floating type, but there will never
! be case in which one operand is of floating type and the other is of
! integral type.
!
! The result of a @code{TRUNC_DIV_EXPR} is always rounded towards zero.
! The @code{TRUNC_MOD_EXPR} of two operands @code{a} and @code{b} is
! always @code{a - (a/b)*b} where the division is as if computed by a
! @code{TRUNC_DIV_EXPR}.

  The behavior of these operations on signed arithmetic overflow is
  controlled by the @code{flag_wrapv} and @code{flag_trapv} variables.

  @item ARRAY_REF
  These nodes represent array accesses.  The first operand is the array;
  the second is the index.  To calculate the address of the memory
--- 2081,2130 ----
  @itemx PLUS_EXPR
  @itemx MINUS_EXPR
  @itemx MULT_EXPR
  These nodes represent various binary arithmetic operations.
  Respectively, these operations are addition, subtraction (of the second
! operand from the first) and multiplication.  Their operands may have
! either integral or floating type, but there will never be case in which
! one operand is of floating type and the other is of integral type.

  The behavior of these operations on signed arithmetic overflow is
  controlled by the @code{flag_wrapv} and @code{flag_trapv} variables.

+ @item RDIV_EXPR
+ This node represents a floating point division operation.
+
+ @item TRUNC_DIV_EXPR
+ @itemx FLOOR_DIV_EXPR
+ @itemx CEIL_DIV_EXPR
+ @itemx ROUND_DIV_EXPR
+ These nodes represent integer division operations that return an integer
+ result.  @code{TRUNC_DIV_EXPR} rounds towards zero, @code{FLOOR_DIV_EXPR}
+ rounds towards negative infinity, @code{CEIL_DIV_EXPR} rounds towards
+ positive infinity and @code{ROUND_DIV_EXPR} rounds to the closest integer.
+ Integer division in C and C++ is truncating, i.e@. @code{TRUNC_DIV_EXPR}.
+
+ The behavior of these operations on signed arithmetic overflow, when
+ dividing the minimum signed integer by minus one, is controlled by the
+ @code{flag_wrapv} and @code{flag_trapv} variables.
+
+ @item TRUNC_MOD_EXPR
+ @itemx FLOOR_MOD_EXPR
+ @itemx CEIL_MOD_EXPR
+ @itemx ROUND_MOD_EXPR
+ These nodes represent the integer remainder or modulus operation.
+ The integer modulus of two operands @code{a} and @code{b} is
+ defined as @code{a - (a/b)*b} where the division calculated using
+ the corresponding division operator.  Hence for @code{TRUNC_MOD_EXPR}
+ this definition assumes division using truncation towards zero, i.e@.
+ @code{TRUNC_DIV_EXPR}.  Integer remainder in C and C++ uses truncating
+ division, i.e@. @code{TRUNC_MOD_EXPR}.
+
+ @item EXACT_DIV_EXPR
+ The @code{EXACT_DIV_EXPR} code is used to represent integer divisions where
+ the numerator is known to be an exact multiple of the denominator.  This
+ allows the backend to choose between the faster of @code{TRUNC_DIV_EXPR},
+ @code{CEIL_DIV_EXPR} and @code{FLOOR_DIV_EXPR} for the current target.
+
  @item ARRAY_REF
  These nodes represent array accesses.  The first operand is the array;
  the second is the index.  To calculate the address of the memory
*************** meanings.  The type of these expressions
*** 2090,2110 ****
  type is the same as that of the first operand.  The range of that array
  type determines the amount of data these expressions access.

- @item EXACT_DIV_EXPR
- Document.
-
  @item LT_EXPR
  @itemx LE_EXPR
  @itemx GT_EXPR
  @itemx GE_EXPR
  @itemx EQ_EXPR
  @itemx NE_EXPR
-
  These nodes represent the less than, less than or equal to, greater
  than, greater than or equal to, equal, and not equal comparison
  operators.  The first and second operand with either be both of integral
  type or both of floating type.  The result type of these expressions
! will always be of integral or boolean type.

  @item MODIFY_EXPR
  These nodes represent assignment.  The left-hand side is the first
--- 2139,2189 ----
  type is the same as that of the first operand.  The range of that array
  type determines the amount of data these expressions access.

  @item LT_EXPR
  @itemx LE_EXPR
  @itemx GT_EXPR
  @itemx GE_EXPR
  @itemx EQ_EXPR
  @itemx NE_EXPR
  These nodes represent the less than, less than or equal to, greater
  than, greater than or equal to, equal, and not equal comparison
  operators.  The first and second operand with either be both of integral
  type or both of floating type.  The result type of these expressions
! will always be of integral or boolean type.  These operations return
! the result type's zero value for false, and the result type's one value
! for true.
!
! For floating point comparisons, if we honor IEEE NaNs and either operand
! is NaN, then @code{NE_EXPR} always returns true and the remaining operators
! always return false.  On some targets, comparisons against an IEEE NaN,
! other than equality and inequality, may generate a floating point exception.
!
! @item ORDERED_EXPR
! @itemx UNORDERED_EXPR
! These nodes represent non-trapping ordered and unordered comparison
! operators.  These operations take two floating point operands and
! determine whether they are ordered or unordered relative to each other.
! If either operand is an IEEE NaN, their comparison is defined to be
! unordered, otherwise the comparison is defined to be ordered.  The
! result type of these expressions will always be of integral or boolean
! type.  These operations return the result type's zero value for false,
! and the result type's one value for true.
!
! @item UNLT_EXPR
! @itemx UNLE_EXPR
! @itemx UNGT_EXPR
! @itemx UNGE_EXPR
! @itemx UNEQ_EXPR
! These nodes represent the non-trapping unordered comparison operators.
! These operations take two floating point operands and determine whether
! the operands are unordered or are less than, less than or equal to,
! greater than, greater than or equal to, or equal respectively.  For
! example, @code{UNLT_EXPR} returns true if either operand is an IEEE
! NaN or the first operand is less than the second.  These operations
! are guaranteed not to generate a floating point exception.  The result
! type of these expressions will always be of integral or boolean type.
! These operations return the result type's zero value for false,
! and the result type's one value for true.

  @item MODIFY_EXPR
  These nodes represent assignment.  The left-hand side is the first


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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