From 51ce06385bf259a092f830f1a6dcc4b98757919e Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 1 Sep 2022 10:34:55 -0400 Subject: Create gimple_range_op_handler in a new source file. Range-ops is meant to be IL independent. Some gimple processing has be placed in range-ops, and some is located in gori. Split it all into a file and isolate it in a new class gimple_range_op_handler. * Makefile.in (OBJS): Add gimple-range-op.o. * gimple-range-edge.cc (gimple_outgoing_range_stmt_p): Use gimple_range_op_handler. * gimple-range-fold.cc (gimple_range_base_of_assignment): Move to a method in gimple_range_op_handler. (gimple_range_operand1): Ditto. (gimple_range_operand2): Ditto. (fold_using_range::fold_stmt): Use gimple_range_op_handler. (fold_using_range::range_of_range_op): Ditto. (fold_using_range::relation_fold_and_or): Ditto. (fur_source::register_outgoing_edges): Ditto. (gimple_range_ssa_names): Relocate to gimple-range-op.cc. * gimple-range-fold.h: Adjust prototypes. * gimple-range-gori.cc (gimple_range_calc_op1): Move to a method in gimple_range_op_handler. (gimple_range_calc_op2): Ditto. (gori_compute::compute_operand_range): Use gimple_range_op_handler. (gori_compute::compute_logical_operands): Ditto. (compute_operand1_range): Ditto. (gori_compute::compute_operand2_range): Ditto. (gori_compute::compute_operand1_and_operand2_range): Ditto. * gimple-range-gori.h: Adjust protoypes. * gimple-range-op.cc: New. Supply gimple_range_op_handler methods. * gimple-range-op.h: New. Supply gimple_range_op_handler class. * gimple-range.cc (gimple_ranger::prefill_name): Use gimple_range_op_handler. (gimple_ranger::prefill_stmt_dependencies): Ditto. * gimple-range.h: Include gimple-range-op.h. * range-op.cc (range_op_handler::range_op_handler): Adjust and remove gimple * parameter option. * range-op.h: Adjust prototypes. --- gcc/gimple-range-fold.cc | 153 +++++++++-------------------------------------- 1 file changed, 28 insertions(+), 125 deletions(-) (limited to 'gcc/gimple-range-fold.cc') diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index a45fc7a..addf3e7 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -42,7 +42,7 @@ along with GCC; see the file COPYING3. If not see #include "vr-values.h" #include "range.h" #include "value-query.h" -#include "range-op.h" +#include "gimple-range-op.h" #include "gimple-range.h" // Construct a fur_source, and set the m_query field. @@ -463,73 +463,6 @@ gimple_range_adjustment (vrange &res, const gimple *stmt) } } -// Return the base of the RHS of an assignment. - -static tree -gimple_range_base_of_assignment (const gimple *stmt) -{ - gcc_checking_assert (gimple_code (stmt) == GIMPLE_ASSIGN); - tree op1 = gimple_assign_rhs1 (stmt); - if (gimple_assign_rhs_code (stmt) == ADDR_EXPR) - return get_base_address (TREE_OPERAND (op1, 0)); - return op1; -} - -// Return the first operand of this statement if it is a valid operand -// supported by ranges, otherwise return NULL_TREE. Special case is -// &(SSA_NAME expr), return the SSA_NAME instead of the ADDR expr. - -tree -gimple_range_operand1 (const gimple *stmt) -{ - gcc_checking_assert (range_op_handler (stmt)); - - switch (gimple_code (stmt)) - { - case GIMPLE_COND: - return gimple_cond_lhs (stmt); - case GIMPLE_ASSIGN: - { - tree base = gimple_range_base_of_assignment (stmt); - if (base && TREE_CODE (base) == MEM_REF) - { - // If the base address is an SSA_NAME, we return it - // here. This allows processing of the range of that - // name, while the rest of the expression is simply - // ignored. The code in range_ops will see the - // ADDR_EXPR and do the right thing. - tree ssa = TREE_OPERAND (base, 0); - if (TREE_CODE (ssa) == SSA_NAME) - return ssa; - } - return base; - } - default: - break; - } - return NULL; -} - -// Return the second operand of statement STMT, otherwise return NULL_TREE. - -tree -gimple_range_operand2 (const gimple *stmt) -{ - gcc_checking_assert (range_op_handler (stmt)); - - switch (gimple_code (stmt)) - { - case GIMPLE_COND: - return gimple_cond_rhs (stmt); - case GIMPLE_ASSIGN: - if (gimple_num_ops (stmt) >= 3) - return gimple_assign_rhs2 (stmt); - default: - break; - } - return NULL_TREE; -} - // Calculate a range for statement S and return it in R. If NAME is provided it // represents the SSA_NAME on the LHS of the statement. It is only required // if there is more than one lhs/output. If a range cannot @@ -551,8 +484,9 @@ fold_using_range::fold_stmt (vrange &r, gimple *s, fur_source &src, tree name) && gimple_assign_rhs_code (s) == ADDR_EXPR) return range_of_address (as_a (r), s, src); - if (range_op_handler (s)) - res = range_of_range_op (r, s, src); + gimple_range_op_handler handler (s); + if (handler) + res = range_of_range_op (r, handler, src); else if (is_a(s)) res = range_of_phi (r, as_a (s), src); else if (is_a(s)) @@ -587,17 +521,19 @@ fold_using_range::fold_stmt (vrange &r, gimple *s, fur_source &src, tree name) // If a range cannot be calculated, return false. bool -fold_using_range::range_of_range_op (vrange &r, gimple *s, fur_source &src) +fold_using_range::range_of_range_op (vrange &r, + gimple_range_op_handler &handler, + fur_source &src) { + gcc_checking_assert (handler); + gimple *s = handler.stmt (); tree type = gimple_range_type (s); if (!type) return false; - range_op_handler handler (s); - gcc_checking_assert (handler); - tree lhs = gimple_get_lhs (s); - tree op1 = gimple_range_operand1 (s); - tree op2 = gimple_range_operand2 (s); + tree lhs = handler.lhs (); + tree op1 = handler.operand1 (); + tree op2 = handler.operand2 (); Value_Range range1 (TREE_TYPE (op1)); Value_Range range2 (op2 ? TREE_TYPE (op2) : TREE_TYPE (op1)); @@ -1430,9 +1366,10 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, else if (code != BIT_IOR_EXPR && code != TRUTH_OR_EXPR) return; - tree lhs = gimple_get_lhs (s); - tree ssa1 = gimple_range_ssa_p (gimple_range_operand1 (s)); - tree ssa2 = gimple_range_ssa_p (gimple_range_operand2 (s)); + gimple_range_op_handler handler (s); + tree lhs = handler.lhs (); + tree ssa1 = gimple_range_ssa_p (handler.operand1 ()); + tree ssa2 = gimple_range_ssa_p (handler.operand2 ()); // Deal with || and && only when there is a full set of symbolics. if (!lhs || !ssa1 || !ssa2 @@ -1448,18 +1385,18 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, gimple *ssa1_stmt = SSA_NAME_DEF_STMT (ssa1); gimple *ssa2_stmt = SSA_NAME_DEF_STMT (ssa2); - range_op_handler handler1 (SSA_NAME_DEF_STMT (ssa1)); - range_op_handler handler2 (SSA_NAME_DEF_STMT (ssa2)); + gimple_range_op_handler handler1 (ssa1_stmt); + gimple_range_op_handler handler2 (ssa2_stmt); // If either handler is not present, no relation can be found. if (!handler1 || !handler2) return; // Both stmts will need to have 2 ssa names in the stmt. - tree ssa1_dep1 = gimple_range_ssa_p (gimple_range_operand1 (ssa1_stmt)); - tree ssa1_dep2 = gimple_range_ssa_p (gimple_range_operand2 (ssa1_stmt)); - tree ssa2_dep1 = gimple_range_ssa_p (gimple_range_operand1 (ssa2_stmt)); - tree ssa2_dep2 = gimple_range_ssa_p (gimple_range_operand2 (ssa2_stmt)); + tree ssa1_dep1 = gimple_range_ssa_p (handler1.operand1 ()); + tree ssa1_dep2 = gimple_range_ssa_p (handler1.operand2 ()); + tree ssa2_dep1 = gimple_range_ssa_p (handler2.operand1 ()); + tree ssa2_dep2 = gimple_range_ssa_p (handler2.operand2 ()); if (!ssa1_dep1 || !ssa1_dep2 || !ssa2_dep1 || !ssa2_dep2) return; @@ -1516,7 +1453,7 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge tree name; basic_block bb = gimple_bb (s); - range_op_handler handler (s); + gimple_range_op_handler handler (s); if (!handler) return; @@ -1529,7 +1466,6 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge e0 = NULL; } - if (e1) { // If this edge is never taken, ignore it. @@ -1544,8 +1480,8 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge // First, register the gcond itself. This will catch statements like // if (a_2 < b_5) - tree ssa1 = gimple_range_ssa_p (gimple_range_operand1 (s)); - tree ssa2 = gimple_range_ssa_p (gimple_range_operand2 (s)); + tree ssa1 = gimple_range_ssa_p (handler.operand1 ()); + tree ssa2 = gimple_range_ssa_p (handler.operand2 ()); if (ssa1 && ssa2) { if (e0) @@ -1575,11 +1511,11 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge if (TREE_CODE (TREE_TYPE (name)) != BOOLEAN_TYPE) continue; gimple *stmt = SSA_NAME_DEF_STMT (name); - range_op_handler handler (stmt); + gimple_range_op_handler handler (stmt); if (!handler) continue; - tree ssa1 = gimple_range_ssa_p (gimple_range_operand1 (stmt)); - tree ssa2 = gimple_range_ssa_p (gimple_range_operand2 (stmt)); + tree ssa1 = gimple_range_ssa_p (handler.operand1 ()); + tree ssa2 = gimple_range_ssa_p (handler.operand2 ()); Value_Range r (TREE_TYPE (name)); if (ssa1 && ssa2) { @@ -1600,36 +1536,3 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, edge e0, edge } } } - -// Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names -// on the statement. For efficiency, it is an error to not pass in enough -// elements for the vector. Return the number of ssa-names. - -unsigned -gimple_range_ssa_names (tree *vec, unsigned vec_size, gimple *stmt) -{ - tree ssa; - int count = 0; - - if (range_op_handler (stmt)) - { - gcc_checking_assert (vec_size >= 2); - if ((ssa = gimple_range_ssa_p (gimple_range_operand1 (stmt)))) - vec[count++] = ssa; - if ((ssa = gimple_range_ssa_p (gimple_range_operand2 (stmt)))) - vec[count++] = ssa; - } - else if (is_a (stmt) - && gimple_assign_rhs_code (stmt) == COND_EXPR) - { - gcc_checking_assert (vec_size >= 3); - gassign *st = as_a (stmt); - if ((ssa = gimple_range_ssa_p (gimple_assign_rhs1 (st)))) - vec[count++] = ssa; - if ((ssa = gimple_range_ssa_p (gimple_assign_rhs2 (st)))) - vec[count++] = ssa; - if ((ssa = gimple_range_ssa_p (gimple_assign_rhs3 (st)))) - vec[count++] = ssa; - } - return count; -} -- cgit v1.1