aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2020-06-10 13:41:00 +0200
committerAldy Hernandez <aldyh@redhat.com>2020-06-10 14:13:41 +0200
commit52e2fc662a73b7b463709be2caaec1bf6454a747 (patch)
tree68f90677bee9721f4f8c603338a3c510a2087413 /gcc
parent9c7dce1bc5fd90c660f9065cfdc10ea6c4742fdc (diff)
downloadgcc-52e2fc662a73b7b463709be2caaec1bf6454a747.zip
gcc-52e2fc662a73b7b463709be2caaec1bf6454a747.tar.gz
gcc-52e2fc662a73b7b463709be2caaec1bf6454a747.tar.bz2
Tidy up gimple_state class.
Previous method names were confusing.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-ssa-evrp.c36
-rw-r--r--gcc/misc.cc171
-rw-r--r--gcc/misc.h17
-rw-r--r--gcc/tree-ssa-propagate.c1
-rw-r--r--gcc/tree-ssa-propagate.h1
5 files changed, 49 insertions, 177 deletions
diff --git a/gcc/gimple-ssa-evrp.c b/gcc/gimple-ssa-evrp.c
index 16b6432..024ade3 100644
--- a/gcc/gimple-ssa-evrp.c
+++ b/gcc/gimple-ssa-evrp.c
@@ -345,36 +345,39 @@ public:
range_analyzer.enter (bb);
}
+ void pre_fold_stmt (gimple *stmt)
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Visiting stmt ");
+ print_gimple_stmt (dump_file, stmt, 0);
+ }
+ m_gimple_state.set_orig_stmt (stmt);
+ range_analyzer.record_ranges_from_stmt (stmt, false);
+ }
+
void tmp_stats_remove_stmt (gimple *stmt, tree lhs) OVERRIDE
{
- if (evrp_trap_p ())
- m_gimple_state.remove (stmt, lhs);
+ m_gimple_state.maybe_dump_differences_and_trap (stmt, lhs);
}
void tmp_stats_changed_phi (gphi *orig_phi, gphi *new_phi) OVERRIDE
{
- gimple *save = m_gimple_state.save (orig_phi);
- if (evrp_trap_p ())
- m_gimple_state.trap_if_gimple_changed (new_phi);
- m_gimple_state.save (save);
+ gimple *save = m_gimple_state.set_orig_stmt (orig_phi);
+ m_gimple_state.maybe_dump_differences_and_trap (new_phi);
+ m_gimple_state.set_orig_stmt (save);
}
- void pre_fold_stmt (gimple *stmt)
+ void tmp_stats_set_modified (bool modified) OVERRIDE
{
- if (dump_file && (dump_flags & TDF_DETAILS))
- {
- fprintf (dump_file, "Visiting stmt ");
- print_gimple_stmt (dump_file, stmt, 0);
- }
- m_gimple_state.save (stmt);
- range_analyzer.record_ranges_from_stmt (stmt, false);
+ m_modified = modified;
}
bool fold_stmt (gimple_stmt_iterator *gsi)
{
bool res = simplifier.simplify (gsi);
- if (evrp_trap_p ())
- m_gimple_state.trap_if_gimple_changed (gsi_stmt (*gsi));
+ if (m_modified || res)
+ m_gimple_state.maybe_dump_differences_and_trap (gsi_stmt (*gsi));
return res;
}
@@ -394,6 +397,7 @@ private:
class vr_values *vr_values;
simplify_using_ranges simplifier;
class gimple_state m_gimple_state;
+ bool m_modified;
};
/* Main entry point for the early vrp pass which is a simplified non-iterative
diff --git a/gcc/misc.cc b/gcc/misc.cc
index 9648132..e65e034 100644
--- a/gcc/misc.cc
+++ b/gcc/misc.cc
@@ -124,133 +124,21 @@ highlighter::set (gimple *untainted_stmt,
}
//====================================================
-// enhanced_operand_compare
-//====================================================
-
-class enhanced_operand_compare : public operand_compare
-{
-public:
- bool operand_equal_p (const_tree, const_tree, unsigned int) OVERRIDE;
-private:
- bool compare_operands (const_tree op1, const_tree op2, unsigned n);
-};
-
-bool
-enhanced_operand_compare::compare_operands (const_tree op1, const_tree op2,
- unsigned n)
-{
- for (unsigned i = 0; i < n; ++i)
- if (!operand_equal_p (TREE_OPERAND (op1, i), TREE_OPERAND (op2, i),
- OEP_MATCH_SIDE_EFFECTS))
- return false;
- return true;
-}
-
-bool
-enhanced_operand_compare::operand_equal_p (const_tree op1, const_tree op2,
- unsigned int flags)
-{
- bool r;
- if (verify_hash_value (op1, op2, flags, &r))
- return r;
-
- if (op1 == op2)
- return true;
-
- if (!op1 || !op2)
- return op1 == op2;
-
- if (TREE_CODE (op1) != TREE_CODE (op2))
- return false;
-
- flags = OEP_MATCH_SIDE_EFFECTS | OEP_NO_HASH_CHECK;
- switch (TREE_CODE (op1))
- {
- case CASE_LABEL_EXPR:
- return compare_operands (op1, op2, 4);
-
- // There's a bunch of expressions that operand_equal_p do not
- // handle. Assume those are equal.
- case CONSTRUCTOR:
- case WITH_SIZE_EXPR:
- case OBJ_TYPE_REF:
- return true;
-
- case TREE_LIST:
- return (operand_equal_p (TREE_PURPOSE (op1), TREE_PURPOSE (op2), flags)
- && operand_equal_p (TREE_VALUE (op1), TREE_VALUE (op2), flags));
- default:
- return operand_compare::operand_equal_p (op1, op2, flags);
- }
-}
-
-//====================================================
-// gimple_different_p
-//====================================================
-
-static bool
-gimple_phi_different_p (gphi *orig_phi, gphi *new_phi)
-{
- gcc_checking_assert (gimple_phi_num_args (orig_phi)
- == gimple_phi_num_args (new_phi));
- for (unsigned i = 0; i < gimple_phi_num_args (orig_phi); ++i)
- {
- phi_arg_d *orig_arg = gimple_phi_arg (orig_phi, i);
- phi_arg_d *new_arg = gimple_phi_arg (new_phi, i);
- if (memcmp (orig_arg, new_arg, sizeof (phi_arg_d)))
- return true;
- }
- return false;
-}
-
-static bool
-gimple_different_p (gimple *orig_stmt, gimple *new_stmt)
-{
- if (gimple_code (orig_stmt) != gimple_code (new_stmt)
- || orig_stmt->subcode != new_stmt->subcode)
- return true;
-
- if (gimple_num_ops (orig_stmt) != gimple_num_ops (new_stmt))
- return true;
-
- switch (gimple_code (new_stmt))
- {
- case GIMPLE_PHI:
- return gimple_phi_different_p (as_a <gphi *> (orig_stmt),
- as_a <gphi *> (new_stmt));
- case GIMPLE_ASM:
- return false;
- default:
- break;
- }
-
- enhanced_operand_compare comparator;
- for (unsigned i = 0; i < gimple_num_ops (orig_stmt); ++i)
- {
- tree op1 = gimple_op (orig_stmt, i);
- tree op2 = gimple_op (new_stmt, i);
- if (!comparator.operand_equal_p (op1, op2, 0))
- return true;
- }
- return false;
-}
-
-//====================================================
// gimple_state
//====================================================
gimple_state::gimple_state ()
{
orig_stmt = NULL;
- if (const char *filename = getenv ("GIMPLE_CHANGES"))
+ out = stderr;
+ accumulate_changes = false;
+
+ // Instead of trapping, accumulate changes into the filename stored
+ // in EVRP_TRAPS.
+ if (const char *filename = getenv ("EVRP_TRAPS"))
{
out = fopen (filename, "a");
- trap = false;
- }
- else
- {
- out = stderr;
- trap = true;
+ accumulate_changes = true;
}
}
@@ -261,7 +149,7 @@ gimple_state::~gimple_state ()
}
gimple *
-gimple_state::save (gimple *stmt)
+gimple_state::set_orig_stmt (gimple *stmt)
{
untainted_stmt = stmt;
gimple *prev = orig_stmt;
@@ -270,42 +158,23 @@ gimple_state::save (gimple *stmt)
}
void
-gimple_state::trap_if_gimple_changed (gimple *new_stmt)
+gimple_state::maybe_dump_differences_and_trap (gimple *new_stmt, tree lhs)
{
- if (is_gimple_debug (new_stmt))
- return;
- if (gimple_different_p (orig_stmt, new_stmt))
+ if (evrp_trap_p ())
{
- dump_differences (out, new_stmt);
- if (trap)
- gcc_unreachable ();
+ if (unseen_function_p ())
+ {
+ fprintf (out, "===============================================\n");
+ highlighter.set (untainted_stmt, orig_stmt, new_stmt, lhs);
+ dump_function_to_file (current_function_decl, out, TDF_NONE);
+ highlighter.set ();
+ }
+ if (accumulate_changes)
+ return;
+ gcc_unreachable ();
}
}
-void
-gimple_state::dump_differences (FILE *out, gimple *new_stmt, tree lhs)
-{
- if (unseen_function_p ())
- {
- fprintf (out, "===================================================\n");
- highlighter.set (untainted_stmt, orig_stmt, new_stmt, lhs);
- dump_function_to_file (current_function_decl, out, TDF_NONE);
- highlighter.set ();
- }
-}
-
-void
-gimple_state::remove (gimple *stmt, tree lhs)
-{
- // Set orig_stmt because removing PHIs seems to change the original
- // statement.
- gimple *prev = save (stmt);
- dump_differences (out, NULL, lhs);
- save (prev);
- if (trap)
- gcc_unreachable ();
-}
-
//====================================================
// Miscellaneous debugging aids.
//====================================================
diff --git a/gcc/misc.h b/gcc/misc.h
index 2cfe6e4..0f2fa3e 100644
--- a/gcc/misc.h
+++ b/gcc/misc.h
@@ -4,27 +4,24 @@
// Class to report any possible changes to the IL while folding.
//
-// When environment variable GIMPLE_CHANGES is set, it points to the
-// output file to dump any IL changes to. If GIMPLE_CHANGES is not
-// set, any diagnostics are dumped to stderr and a trap occurs at the
-// first change.
+// When environment variable EVRP_TRAPS is set, it points to the
+// output file to dump any IL changes to. If EVRP_TRAPS is not set,
+// any diagnostics are dumped to stderr and a trap occurs at the first
+// change.
class gimple_state
{
public:
gimple_state ();
~gimple_state ();
- gimple *save (gimple *stmt);
- void remove (gimple *stmt, tree lhs);
- void trap_if_gimple_changed (gimple *new_stmt);
+ gimple *set_orig_stmt (gimple *stmt);
+ void maybe_dump_differences_and_trap (gimple *new_stmt, tree lhs = NULL);
private:
- void dump_differences (FILE *out, gimple *new_stmt, tree lhs = NULL);
-
gimple *orig_stmt;
gimple *untainted_stmt;
FILE *out;
- bool trap;
+ bool accumulate_changes;
};
// Hook for pretty printer to highlight a particular statement.
diff --git a/gcc/tree-ssa-propagate.c b/gcc/tree-ssa-propagate.c
index 4bb4c7f..4264bcb 100644
--- a/gcc/tree-ssa-propagate.c
+++ b/gcc/tree-ssa-propagate.c
@@ -1155,6 +1155,7 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb)
specific information. Do this before propagating
into the stmt to not disturb pass specific information. */
update_stmt_if_modified (stmt);
+ substitute_and_fold_engine->tmp_stats_set_modified (did_replace);
if (substitute_and_fold_engine->fold_stmt (&i))
{
did_replace = true;
diff --git a/gcc/tree-ssa-propagate.h b/gcc/tree-ssa-propagate.h
index 6b417e7..f763528 100644
--- a/gcc/tree-ssa-propagate.h
+++ b/gcc/tree-ssa-propagate.h
@@ -124,6 +124,7 @@ class substitute_and_fold_engine
// FIXME: These are temporarily used for keeping track of IL changes
// for evrp. They should be removed before merging upstream.
virtual void tmp_stats_remove_stmt (gimple *, tree) { }
+ virtual void tmp_stats_set_modified (bool) { }
virtual void tmp_stats_changed_phi (gphi *orig_phi ATTRIBUTE_UNUSED,
gphi *new_phi ATTRIBUTE_UNUSED) { }
};