From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id E9E843858023 for ; Wed, 15 Dec 2021 15:55:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E9E843858023 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: DKEYJaF2socQpg6RxLMdzrvijhtDz5jfFu+s+m2Lpf0US1xCi2ShPZyIj8uH5iNq4XZWZZ3br2 /f6TrKTi1Lk+1STKMaRgbD1mqNIVuM0wAc/E0CAHEZp89L9q8W/jaDu7TO6C3yfjQckFeAf2Di QGeuy322Tt66HEnC0M2VWGfzUaZ4+L0GeE8S7FA4T9de71jPmyw5p7yF4aVFhNgN09VT8E11ds XcHI09ee7SzTk7Ak4VouYSqtzV596R9/rPJh7p5aYwwAJyyVO0PKBKeq+XiIYY3z3/IjiMXp/e bvlBeCEQ00/tR1lyIfBCoHCL X-IronPort-AV: E=Sophos;i="5.88,207,1635235200"; d="scan'208";a="69736561" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 15 Dec 2021 07:55:54 -0800 IronPort-SDR: JyDgyaPVaFpKhZSIJMWtvdCgASHGlnqa5UMcy5pvQ6crTn+rbLmroV/vOxMebapdilXfJef37q PrQWhBPr33+3NHusixLSULu8vQZS7fbkbBKuV041ZqNt/kCTuzcjHdk8iZVrmjkHZxxDsfq2dn xV2dte6g/K4MeyP4yVynuv/kmCsZ3KfvhBuNwPLx72Bdh1VLbsy9WeDN5i5E5+2TEI8sbcq6KF uCl27d4/QTAycPQWNu1b2BoBdhOv7x1opjvcshaEHxlJ4LGcJSDFgliQe6Zq4rYYQMBszSgyal tQo= From: Frederik Harwath To: CC: , , , Subject: [PATCH 15/40] graphite: Extend SCoP detection dump output Date: Wed, 15 Dec 2021 16:54:22 +0100 Message-ID: <20211215155447.19379-16-frederik@codesourcery.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211215155447.19379-1-frederik@codesourcery.com> References: <20211215155447.19379-1-frederik@codesourcery.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Dec 2021 15:55:57 -0000 Extend dump output to make understanding why Graphite rejects to include a loop in a SCoP easier (for GCC developers). ChangeLog: * graphite-scop-detection.c (scop_detection::can_represent_loop): Output reason for failure to dump file. (scop_detection::harmful_loop_in_region): Likewise. (scop_detection::graphite_can_represent_expr): Likewise. (scop_detection::stmt_has_simple_data_refs_p): Likewise. (scop_detection::stmt_simple_for_scop_p): Likewise. (print_sese_loop_numbers): New function. (scop_detection::add_scop): Use from here to print loops in rejected SCoP. --- gcc/graphite-scop-detection.c | 188 +++++++++++++++++++++++++++++----- 1 file changed, 165 insertions(+), 23 deletions(-) diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c index 3e729b159b09..46c470210d05 100644 --- a/gcc/graphite-scop-detection.c +++ b/gcc/graphite-scop-detection.c @@ -69,12 +69,27 @@ public: fprintf (output.dump_file, "%d", i); return output; } + friend debug_printer & operator<< (debug_printer &output, const char *s) { fprintf (output.dump_file, "%s", s); return output; } + + friend debug_printer & + operator<< (debug_printer &output, gimple* stmt) + { + print_gimple_stmt (output.dump_file, stmt, 0, TDF_VOPS | TDF_MEMSYMS); + return output; + } + + friend debug_printer & + operator<< (debug_printer &output, tree t) + { + print_generic_expr (output.dump_file, t, TDF_SLIM); + return output; + } } dp; #define DEBUG_PRINT(args) do \ @@ -506,6 +521,24 @@ scop_detection::merge_sese (sese_l first, sese_l secon= d) const return combined; } +/* Print the loop numbers of the loops contained + in SESE to FILE. */ + +static void +print_sese_loop_numbers (FILE *file, sese_l sese) +{ + loop_p loop; + bool printed =3D false; + FOR_EACH_LOOP (loop, 0) + { + if (loop_in_sese_p (loop, sese)) + fprintf (file, "%d, ", loop->num); + printed =3D true; + } + if (printed) + fprintf (file, "\b\b"); +} + /* Build scop outer->inner if possible. */ void @@ -519,8 +552,13 @@ scop_detection::build_scop_depth (loop_p loop) if (! next || harmful_loop_in_region (next)) { - if (s) - add_scop (s); + if (next) + DEBUG_PRINT ( + dp << "[scop-detection] Discarding SCoP on loops "; + print_sese_loop_numbers (dump_file, next); + dp << " because of harmful loops\n";); + if (s) + add_scop (s); build_scop_depth (loop); s =3D invalid_sese; } @@ -560,14 +598,62 @@ scop_detection::can_represent_loop (loop_p loop, sese= _l scop) || !single_pred_p (loop->latch) || exit->src !=3D single_pred (loop->latch) || !empty_block_p (loop->latch)) - return false; + { + DEBUG_PRINT (dp << "[can_represent_loop-fail] Loop shape unsupported= .\n"); + return false; + } + + bool edge_irreducible + =3D loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP; + if (edge_irreducible) + { + DEBUG_PRINT ( + dp << "[can_represent_loop-fail] Loop is not a natural loop.\n")= ; + return false; + } + + bool niter_is_unconditional =3D number_of_iterations_exit (loop, + single_exit (loo= p), + &niter_desc, fal= se); - return !(loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP) - && number_of_iterations_exit (loop, single_exit (loop), &niter_desc, f= alse) - && niter_desc.control.no_overflow - && (niter =3D number_of_latch_executions (loop)) - && !chrec_contains_undetermined (niter) - && graphite_can_represent_expr (scop, loop, niter); + if (!niter_is_unconditional) + { + DEBUG_PRINT ( + dp << "[can_represent_loop-fail] Loop niter not unconditional.\n= " + << "Condition: " << niter_desc.assumptions << "\n"); + return false; + } + + niter =3D number_of_latch_executions (loop); + if (!niter) + { + DEBUG_PRINT (dp << "[can_represent_loop-fail] Loop niter unknown.\n"= ); + return false; + } + if (!niter_desc.control.no_overflow) + { + DEBUG_PRINT (dp << "[can_represent_loop-fail] Loop niter can overflo= w.\n"); + return false; + } + + bool undetermined_coefficients =3D chrec_contains_undetermined (niter); + if (undetermined_coefficients) + { + DEBUG_PRINT (dp << "[can_represent_loop-fail] " + << "Loop niter chrec contains undetermined coefficients.= \n"); + return false; + } + + bool can_represent_expr =3D graphite_can_represent_expr (scop, loop, nit= er); + if (!can_represent_expr) + { + DEBUG_PRINT (dp << "[can_represent_loop-fail] " + << "Loop niter expression cannot be represented: " + << niter << "\n"); + return false; + } + + return true; } /* Return true when BEGIN is the preheader edge of a loop with a single ex= it @@ -640,6 +726,16 @@ scop_detection::add_scop (sese_l s) scops.safe_push (s); DEBUG_PRINT (dp << "[scop-detection] Adding SCoP: "; print_sese (dump_fi= le, s)); + + if (dump_file && dump_flags & TDF_DETAILS) + { + loop_p loop; + fprintf (dump_file, "Loops in SCoP: "); + FOR_EACH_LOOP (loop, 0) + if (loop_in_sese_p (loop, s)) + fprintf (dump_file, "%d ", loop->num); + fprintf (dump_file, "\n"); + } } /* Return true when a statement in SCOP cannot be represented by Graphite.= */ @@ -665,7 +761,11 @@ scop_detection::harmful_loop_in_region (sese_l scop) c= onst /* The basic block should not be part of an irreducible loop. */ if (bb->flags & BB_IRREDUCIBLE_LOOP) - return true; + { + DEBUG_PRINT (dp << "[scop-detection-fail] Found bb in irreducibl= e " + "loop.\n"); + return true; + } /* Check for unstructured control flow: CFG not generated by structu= red if-then-else. */ @@ -676,7 +776,11 @@ scop_detection::harmful_loop_in_region (sese_l scop) c= onst FOR_EACH_EDGE (e, ei, bb->succs) if (!dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest) && !dominated_by_p (CDI_DOMINATORS, e->dest, bb)) - return true; + { + DEBUG_PRINT (dp << "[scop-detection-fail] Found unstructur= ed " + "control flow.\n"); + return true; + } } /* Collect all loops in the current region. */ @@ -688,7 +792,10 @@ scop_detection::harmful_loop_in_region (sese_l scop) c= onst for (gimple_stmt_iterator gsi =3D gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) if (!stmt_simple_for_scop_p (scop, gsi_stmt (gsi), bb)) - return true; + { + DEBUG_PRINT (dp << "[scop-detection-fail] Found harmful stateme= nt.\n"); + return true; + } for (basic_block dom =3D first_dom_son (CDI_DOMINATORS, bb); dom; @@ -731,9 +838,11 @@ scop_detection::harmful_loop_in_region (sese_l scop) c= onst && ! loop_nest_has_data_refs (loop)) { DEBUG_PRINT (dp << "[scop-detection-fail] loop_" << loop->num - << "does not have any data reference.\n"); + << " does not have any data reference.\n"); return true; } + + DEBUG_PRINT (dp << "[scop-detection] loop_" << loop->num << " is har= mless.\n"); } return false; @@ -922,7 +1031,21 @@ scop_detection::graphite_can_represent_expr (sese_l s= cop, loop_p loop, tree expr) { tree scev =3D cached_scalar_evolution_in_region (scop, loop, expr); - return graphite_can_represent_scev (scop, scev); + bool can_represent =3D graphite_can_represent_scev (scop, scev); + + if (!can_represent) + { + if (dump_file) + { + fprintf (dump_file, "[graphite_can_represent_expr] Cannot repres= ent " + "scev \""); + print_generic_expr (dump_file, scev, TDF_SLIM); + fprintf (dump_file, "\" of expression "); + print_generic_expr (dump_file, expr, TDF_SLIM); + fprintf (dump_file, " in loop %d\n", loop->num); + } + } + return can_represent; } /* Return true if the data references of STMT can be represented by Graphi= te. @@ -938,7 +1061,11 @@ scop_detection::stmt_has_simple_data_refs_p (sese_l s= cop, gimple *stmt) auto_vec drs; if (! graphite_find_data_references_in_stmt (nest, loop, stmt, &drs)) - return false; + { + DEBUG_PRINT (dp << + "[stmt_has_simple_data_refs_p] Unanalyzable statement.\n= "); + return false; + } int j; data_reference_p dr; @@ -946,7 +1073,12 @@ scop_detection::stmt_has_simple_data_refs_p (sese_l s= cop, gimple *stmt) { for (unsigned i =3D 0; i < DR_NUM_DIMENSIONS (dr); ++i) if (! graphite_can_represent_scev (scop, DR_ACCESS_FN (dr, i))) - return false; + { + DEBUG_PRINT (dp << "[stmt_has_simple_data_refs_p] Cannot " + "represent access function SCEV: " + << DR_ACCESS_FN (dr, i) << "\n"); + return false; + } } return true; @@ -1027,14 +1159,24 @@ scop_detection::stmt_simple_for_scop_p (sese_l scop= , gimple *stmt, for (unsigned i =3D 0; i < 2; ++i) { tree op =3D gimple_op (stmt, i); - if (!graphite_can_represent_expr (scop, loop, op) - /* We can only constrain on integer type. */ - || ! INTEGRAL_TYPE_P (TREE_TYPE (op))) + if (!graphite_can_represent_expr (scop, loop, op)) + { + DEBUG_PRINT (dump_printf_loc (MSG_MISSED_OPTIMIZATION, stmt= , + "[scop-detection-fail] " + "Graphite cannot represent co= nd " + "stmt operator expression.\n"= )); + DEBUG_PRINT (dp << op << "\n"); + + return false; + } + + if (! INTEGRAL_TYPE_P (TREE_TYPE (op))) { - DEBUG_PRINT (dp << "[scop-detection-fail] " - << "Graphite cannot represent stmt:\n"; - print_gimple_stmt (dump_file, stmt, 0, - TDF_VOPS | TDF_MEMSYMS)); + DEBUG_PRINT (dump_printf_loc (MSG_MISSED_OPTIMIZATION, stmt= , + "[scop-detection-fail] " + "Graphite cannot represent co= nd " + "statement operator. " + "Type must be integral.\n")); return false; } } -- 2.33.0 ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=DFe 201, 8= 0634 M=FCnchen; Gesellschaft mit beschr=E4nkter Haftung; Gesch=E4ftsf=FChre= r: Thomas Heurung, Frank Th=FCrauf; Sitz der Gesellschaft: M=FCnchen; Regis= tergericht M=FCnchen, HRB 106955