On Mon, Aug 18, 2014 at 2:11 AM, Prathamesh Kulkarni <bilbotheelffri...@gmail.com> wrote: > [gcc/doc] > * match-and-simplify.texi: Replace addres by address. > This version adds a small note for capturing expressions.
[gcc/doc] * match-and-simplify.texi: Add documentation for capturing expressions. Replace addres by address. Thanks, Prathamesh > Thanks, > Prathamesh
Index: match-and-simplify.texi =================================================================== --- match-and-simplify.texi (revision 214020) +++ match-and-simplify.texi (working copy) @@ -22,7 +22,7 @@ tries to address several issues. To address these the project introduces a simple domain specific language to write expression simplifications from which code targeting GIMPLE and GENERIC is auto-generated. The GENERIC variant follows the -fold_buildN API while for the GIMPLE variant and to addres 2) new +fold_buildN API while for the GIMPLE variant and to address 2) new APIs are introduced. @menu @@ -152,6 +152,32 @@ to enable the replacement expression. T of the @code{if} is a standard C expression which may contain references to captures. +Capturing Expressions: +Captures can also be used for capturing results of sub-expressions. + +@smallexample +#if GIMPLE +(simplify + (pointer_plus (addr@@2 @@0) INTEGER_CST_P@@1) + (if (is_gimple_min_invariant (@@2))) + @{ + HOST_WIDE_INT off; + tree base = get_addr_base_and_unit_offset (@@0, &off); + off += tree_to_uhwi (@@1); + /* Now with that we should be able to simply write + (addr (mem_ref (addr @@base) (plus @@off @@1))) */ + build1 (ADDR_EXPR, type, + build2 (MEM_REF, TREE_TYPE (TREE_TYPE (@@2)), + build_fold_addr_expr (base), + build_int_cst (ptr_type_node, off))); + @}) +#endif +@end smallexample + +In the above example, @code{@@2} captures the result of the expression (addr @code{@@0}). +For outermost expression only it's type can be captured, and the keyword +@code{type} is reserved for this purpose. + @smallexample (simplify (bit_and:c integral_op_p@@0 (bit_ior:c (bit_not @@0) @@1))