On Fri, Oct 31, 2014 at 3:30 PM, Prathamesh Kulkarni <bilbotheelffri...@gmail.com> wrote: > On Fri, Oct 31, 2014 at 7:33 PM, Prathamesh Kulkarni > <bilbotheelffri...@gmail.com> wrote: >> Hi, >> I was wondering if it would be a good idea to add "debugging" >> output to the patterns. >> sth like: >> >> (simplify >> (plus @x integer_zerop) >> (non_lvalue @x) >> debug_out "Simplified pattern_foo")
Hmm. Jakub requested to put back the (optional) naming of patterns. So instead of just printing file:line we could name the pattern that applied. Of course for (simplify "foo" (mult @x @y) (if (integer_zerop (@y)) @y) (if (integer_onep (@y)) @x)) it wouldn't distinguish both cases. But yes, using the file:line in testcases makes them too volatile to changes. >> the corresponding change in gimple-match.c/generic-match.c would be: >> if (dump_file && (dump_flags & TDF_DETAILS)) >> { >> fprintf (dump_file, "Applying pattern match.pd:161, %s:%d\n", >> __FILE__, __LINE__); >> fprintf (dump_file, "Simplified pattern_foo\n"); >> } > Transforms that involve subexpressions may return false, so it woudn't > be correct to place debug_out there. Hmm, why? Ah, because if "seq" is NULL. > maybe instead place debug_out string just above "return true;" ? Yeah, we probably should move the existing debug output there. So besides from putting naming of simplify patterns back we probably need to add a counter for the transform inside it so we could print "Applying simplification 2 in pattern foo" if we applied x * 1 -> x. OTOH it doesn't tell you the full story either if it is (for op (mult plus) (simplify (op @x integer_zerop) @x)) because ideally you'd want to know the operator that was used as well... (so print "with op == mult"?). What about commutates and conditional converts? In the end having both match.pd line and generated file line gets me enough information for my debugging. And for dump files all users of gimple_simplify add their own debug dumping (which doesn't always tell the whole story). (it's always a good idea to include a gcc mailing list in such discussions) Richard. > for the above pattern: > > /* #line 3 "plus.pd" */ > tree captures[2] ATTRIBUTE_UNUSED = {}; > captures[0] = op0; > captures[1] = op1; > if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, > "Applying pattern plus.pd:3, %s:%d\n", __FILE__, __LINE__); > res_ops[0] = captures[0]; > *res_code = TREE_CODE (res_ops[0]); > // add here > if (dump_file && (dump_flags & TDF_DETAILS)) fprintf ("Simplified > pattern_foo\n"); > return true; >> >> and in the test-cases we can simply grep for "Simplified pattern_foo". >> sth like: >> >> int test (int x) >> { >> int t1 = 0; >> int t2 = x + t1; >> return t2; >> } >> /* { dg-final { scan-tree-dump "Simplified pattern_foo" "ccp1" } } */ >> >> or maybe introduce name to simplifiers ? >> (simplify "pattern_foo" >> (plus @x integer_zerop) >> (non_lvalue @x)) >> >> and corresponding gimple-match.c change: >> fprintf (dump_file, "pattern_foo\n"); >> >> (not sure if it's correct grepping for debug_out in test-cases, it >> worked for the >> above pattern though). >> >> Thanks. >> Prathamesh