This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 25/89] Introduce gimple_catch
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Mon, 21 Apr 2014 12:56:56 -0400
- Subject: [PATCH 25/89] Introduce gimple_catch
- Authentication-results: sourceware.org; auth=none
- References: <1398099480-49147-1-git-send-email-dmalcolm at redhat dot com>
gcc/
* coretypes.h (gimple_catch): New typedef.
(const_gimple_catch): New typedef.
* gimple-low.c (lower_try_catch): Add checked cast to gimple_catch.
(gimple_try_catch_may_fallthru): Likewise.
* gimple-pretty-print.c (dump_gimple_catch): Require a gimple_catch
rather than a plain gimple.
(pp_gimple_stmt_1): Add checked cast to gimple_catch within
GIMPLE_CATCH case of switch statement.
* gimple-walk.c (walk_gimple_op): Likewise.
(walk_gimple_stmt): Likewise.
* gimple.c (gimple_build_catch): Return a gimple_catch rather than
a plain gimple.
(gimple_copy): Add checked casts to gimple_catch within
GIMPLE_CATCH case of switch statement, introducing new locals.
* gimple.h (gimple_statement_base::as_a_gimple_catch): New
(gimple_statement_base::dyn_cast_gimple_catch): New.
(gimple_build_catch): Return a gimple_catch rather than
a plain gimple.
(gimple_catch_types_ptr): Require a gimple_catch rather than a
plain gimple.
(gimple_catch_handler_ptr): Likewise.
(gimple_catch_handler): Likewise.
(gimple_catch_set_types): Likewise.
(gimple_catch_set_handler): Likewise.
* omp-low.c (lower_omp_1): Add checked cast to gimple_catch within
GIMPLE_CATCH case of switch statement.
* tree-cfg.c (verify_gimple_in_seq_2): Likewise.
(do_warn_unused_result): Likewise.
* tree-eh.c (collect_finally_tree): Likewise.
(replace_goto_queue_1): Likewise.
(lower_catch): Convert local from gimple to gimple_catch.
(refactor_eh_r): Add checked cast to gimple_catch within
GIMPLE_CATCH case of switch statement.
* tree-inline.c (remap_gimple_stmt): Likewise.
(estimate_num_insns): Add checked cast to gimple_catch within
GIMPLE_CATCH case of switch statement, introducing new local.
---
gcc/coretypes.h | 4 ++++
gcc/gimple-low.c | 7 +++++--
gcc/gimple-pretty-print.c | 4 ++--
gcc/gimple-walk.c | 9 +++++----
gcc/gimple.c | 16 ++++++++++------
gcc/gimple.h | 40 ++++++++++++++++++++++++----------------
gcc/omp-low.c | 2 +-
gcc/tree-cfg.c | 5 +++--
gcc/tree-eh.c | 14 +++++++++-----
gcc/tree-inline.c | 11 ++++++++---
10 files changed, 71 insertions(+), 41 deletions(-)
diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index 284fcb6..1dd36fb 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -113,6 +113,10 @@ struct gimple_statement_bind;
typedef struct gimple_statement_bind *gimple_bind;
typedef const struct gimple_statement_bind *const_gimple_bind;
+struct gimple_statement_catch;
+typedef struct gimple_statement_catch *gimple_catch;
+typedef const struct gimple_statement_catch *const_gimple_catch;
+
struct gimple_statement_phi;
typedef struct gimple_statement_phi *gimple_phi;
typedef const struct gimple_statement_phi *const_gimple_phi;
diff --git a/gcc/gimple-low.c b/gcc/gimple-low.c
index 5f19f6e..3fa1c44 100644
--- a/gcc/gimple-low.c
+++ b/gcc/gimple-low.c
@@ -455,7 +455,9 @@ lower_try_catch (gimple_stmt_iterator *gsi, struct lower_data *data)
for (; !gsi_end_p (i); gsi_next (&i))
{
data->cannot_fallthru = false;
- lower_sequence (gimple_catch_handler_ptr (gsi_stmt (i)), data);
+ lower_sequence (gimple_catch_handler_ptr (
+ gsi_stmt (i)->as_a_gimple_catch ()),
+ data);
if (!data->cannot_fallthru)
cannot_fallthru = false;
}
@@ -517,7 +519,8 @@ gimple_try_catch_may_fallthru (gimple stmt)
through iff any of the catch bodies falls through. */
for (; !gsi_end_p (i); gsi_next (&i))
{
- if (gimple_seq_may_fallthru (gimple_catch_handler (gsi_stmt (i))))
+ if (gimple_seq_may_fallthru (gimple_catch_handler (
+ gsi_stmt (i)->as_a_gimple_catch ())))
return true;
}
return false;
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index dfb6459..ec16f13 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -978,7 +978,7 @@ dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags)
dumpfile.h). */
static void
-dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags)
+dump_gimple_catch (pretty_printer *buffer, gimple_catch gs, int spc, int flags)
{
if (flags & TDF_RAW)
dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs,
@@ -2200,7 +2200,7 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
break;
case GIMPLE_CATCH:
- dump_gimple_catch (buffer, gs, spc, flags);
+ dump_gimple_catch (buffer, gs->as_a_gimple_catch (), spc, flags);
break;
case GIMPLE_EH_FILTER:
diff --git a/gcc/gimple-walk.c b/gcc/gimple-walk.c
index 2d987c6..f9b641d 100644
--- a/gcc/gimple-walk.c
+++ b/gcc/gimple-walk.c
@@ -278,8 +278,8 @@ walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
break;
case GIMPLE_CATCH:
- ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
- pset);
+ ret = walk_tree (gimple_catch_types_ptr (stmt->as_a_gimple_catch ()),
+ callback_op, wi, pset);
if (ret)
return ret;
break;
@@ -551,8 +551,9 @@ walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
break;
case GIMPLE_CATCH:
- ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt,
- callback_op, wi);
+ ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (
+ stmt->as_a_gimple_catch ()),
+ callback_stmt, callback_op, wi);
if (ret)
return wi->callback_result;
break;
diff --git a/gcc/gimple.c b/gcc/gimple.c
index 7ee7da1..4bc844b 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -610,10 +610,10 @@ gimple_build_asm_vec (const char *string, vec<tree, va_gc> *inputs,
TYPES are the catch types.
HANDLER is the exception handler. */
-gimple
+gimple_catch
gimple_build_catch (tree types, gimple_seq handler)
{
- gimple p = gimple_alloc (GIMPLE_CATCH, 0);
+ gimple_catch p = gimple_alloc (GIMPLE_CATCH, 0)->as_a_gimple_catch ();
gimple_catch_set_types (p, types);
if (handler)
gimple_catch_set_handler (p, handler);
@@ -1642,10 +1642,14 @@ gimple_copy (gimple stmt)
break;
case GIMPLE_CATCH:
- new_seq = gimple_seq_copy (gimple_catch_handler (stmt));
- gimple_catch_set_handler (copy, new_seq);
- t = unshare_expr (gimple_catch_types (stmt));
- gimple_catch_set_types (copy, t);
+ {
+ gimple_catch catch_stmt = stmt->as_a_gimple_catch ();
+ gimple_catch catch_copy = copy->as_a_gimple_catch ();
+ new_seq = gimple_seq_copy (gimple_catch_handler (catch_stmt));
+ gimple_catch_set_handler (catch_copy, new_seq);
+ t = unshare_expr (gimple_catch_types (catch_stmt));
+ gimple_catch_set_types (catch_copy, t);
+ }
break;
case GIMPLE_EH_FILTER:
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 7cb778d..e12e066 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -288,6 +288,12 @@ public:
return as_a <gimple_statement_bind> (this);
}
+ inline gimple_catch
+ as_a_gimple_catch ()
+ {
+ return as_a <gimple_statement_catch> (this);
+ }
+
inline gimple_phi
as_a_gimple_phi ()
{
@@ -368,6 +374,12 @@ public:
return dyn_cast <gimple_statement_bind> (this);
}
+ inline gimple_catch
+ dyn_cast_gimple_catch ()
+ {
+ return dyn_cast <gimple_statement_catch> (this);
+ }
+
inline gimple_phi
dyn_cast_gimple_phi ()
{
@@ -1499,7 +1511,7 @@ gimple_bind gimple_build_bind (tree, gimple_seq, tree);
gimple_asm gimple_build_asm_vec (const char *, vec<tree, va_gc> *,
vec<tree, va_gc> *, vec<tree, va_gc> *,
vec<tree, va_gc> *);
-gimple gimple_build_catch (tree, gimple_seq);
+gimple_catch gimple_build_catch (tree, gimple_seq);
gimple gimple_build_eh_filter (tree, gimple_seq);
gimple gimple_build_eh_must_not_throw (tree);
gimple gimple_build_eh_else (gimple_seq, gimple_seq);
@@ -3676,53 +3688,49 @@ gimple_catch_types (const_gimple gs)
}
-/* Return a pointer to the types handled by GIMPLE_CATCH statement GS. */
+/* Return a pointer to the types handled by GIMPLE_CATCH statement CATCH_STMT. */
static inline tree *
-gimple_catch_types_ptr (gimple gs)
+gimple_catch_types_ptr (gimple_catch catch_stmt)
{
- gimple_statement_catch *catch_stmt = as_a <gimple_statement_catch> (gs);
return &catch_stmt->types;
}
/* Return a pointer to the GIMPLE sequence representing the body of
- the handler of GIMPLE_CATCH statement GS. */
+ the handler of GIMPLE_CATCH statement CATCH_STMT. */
static inline gimple_seq *
-gimple_catch_handler_ptr (gimple gs)
+gimple_catch_handler_ptr (gimple_catch catch_stmt)
{
- gimple_statement_catch *catch_stmt = as_a <gimple_statement_catch> (gs);
return &catch_stmt->handler;
}
/* Return the GIMPLE sequence representing the body of the handler of
- GIMPLE_CATCH statement GS. */
+ GIMPLE_CATCH statement CATCH_STMT. */
static inline gimple_seq
-gimple_catch_handler (gimple gs)
+gimple_catch_handler (gimple_catch catch_stmt)
{
- return *gimple_catch_handler_ptr (gs);
+ return *gimple_catch_handler_ptr (catch_stmt);
}
-/* Set T to be the set of types handled by GIMPLE_CATCH GS. */
+/* Set T to be the set of types handled by GIMPLE_CATCH CATCH_STMT. */
static inline void
-gimple_catch_set_types (gimple gs, tree t)
+gimple_catch_set_types (gimple_catch catch_stmt, tree t)
{
- gimple_statement_catch *catch_stmt = as_a <gimple_statement_catch> (gs);
catch_stmt->types = t;
}
-/* Set HANDLER to be the body of GIMPLE_CATCH GS. */
+/* Set HANDLER to be the body of GIMPLE_CATCH CATCH_STMT. */
static inline void
-gimple_catch_set_handler (gimple gs, gimple_seq handler)
+gimple_catch_set_handler (gimple_catch catch_stmt, gimple_seq handler)
{
- gimple_statement_catch *catch_stmt = as_a <gimple_statement_catch> (gs);
catch_stmt->handler = handler;
}
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index b1eb22d..8407f0e 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -10002,7 +10002,7 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx)
gimple_regimplify_operands (stmt, gsi_p);
break;
case GIMPLE_CATCH:
- lower_omp (gimple_catch_handler_ptr (stmt), ctx);
+ lower_omp (gimple_catch_handler_ptr (stmt->as_a_gimple_catch ()), ctx);
break;
case GIMPLE_EH_FILTER:
lower_omp (gimple_eh_filter_failure_ptr (stmt), ctx);
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index a2557e4..c504798 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -4569,7 +4569,8 @@ verify_gimple_in_seq_2 (gimple_seq stmts)
break;
case GIMPLE_CATCH:
- err |= verify_gimple_in_seq_2 (gimple_catch_handler (stmt));
+ err |= verify_gimple_in_seq_2 (gimple_catch_handler (
+ stmt->as_a_gimple_catch ()));
break;
case GIMPLE_TRANSACTION:
@@ -8305,7 +8306,7 @@ do_warn_unused_result (gimple_seq seq)
do_warn_unused_result (gimple_try_cleanup (g));
break;
case GIMPLE_CATCH:
- do_warn_unused_result (gimple_catch_handler (g));
+ do_warn_unused_result (gimple_catch_handler (g->as_a_gimple_catch ()));
break;
case GIMPLE_EH_FILTER:
do_warn_unused_result (gimple_eh_filter_failure (g));
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index c5eda1f..940b565 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -285,7 +285,9 @@ collect_finally_tree (gimple stmt, gimple region)
break;
case GIMPLE_CATCH:
- collect_finally_tree_1 (gimple_catch_handler (stmt), region);
+ collect_finally_tree_1 (gimple_catch_handler (
+ stmt->as_a_gimple_catch ()),
+ region);
break;
case GIMPLE_EH_FILTER:
@@ -543,7 +545,9 @@ replace_goto_queue_1 (gimple stmt, struct leh_tf_state *tf,
replace_goto_queue_stmt_list (gimple_try_cleanup_ptr (stmt), tf);
break;
case GIMPLE_CATCH:
- replace_goto_queue_stmt_list (gimple_catch_handler_ptr (stmt), tf);
+ replace_goto_queue_stmt_list (gimple_catch_handler_ptr (
+ stmt->as_a_gimple_catch ()),
+ tf);
break;
case GIMPLE_EH_FILTER:
replace_goto_queue_stmt_list (gimple_eh_filter_failure_ptr (stmt), tf);
@@ -1791,10 +1795,10 @@ lower_catch (struct leh_state *state, gimple tp)
gsi_next (&gsi))
{
eh_catch c;
- gimple gcatch;
+ gimple_catch gcatch;
gimple_seq handler;
- gcatch = gsi_stmt (gsi);
+ gcatch = gsi_stmt (gsi)->as_a_gimple_catch ();
c = gen_eh_region_catch (try_region, gimple_catch_types (gcatch));
handler = gimple_catch_handler (gcatch);
@@ -3091,7 +3095,7 @@ refactor_eh_r (gimple_seq seq)
refactor_eh_r (gimple_try_cleanup (one));
break;
case GIMPLE_CATCH:
- refactor_eh_r (gimple_catch_handler (one));
+ refactor_eh_r (gimple_catch_handler (one->as_a_gimple_catch ()));
break;
case GIMPLE_EH_FILTER:
refactor_eh_r (gimple_eh_filter_failure (one));
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 69d5953..f516113 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -1296,8 +1296,11 @@ remap_gimple_stmt (gimple stmt, copy_body_data *id)
break;
case GIMPLE_CATCH:
- s1 = remap_gimple_seq (gimple_catch_handler (stmt), id);
- copy = gimple_build_catch (gimple_catch_types (stmt), s1);
+ {
+ gimple_catch catch_stmt = stmt->as_a_gimple_catch ();
+ s1 = remap_gimple_seq (gimple_catch_handler (catch_stmt), id);
+ copy = gimple_build_catch (gimple_catch_types (catch_stmt), s1);
+ }
break;
case GIMPLE_EH_FILTER:
@@ -3935,7 +3938,9 @@ estimate_num_insns (gimple stmt, eni_weights *weights)
return estimate_num_insns_seq (gimple_eh_filter_failure (stmt), weights);
case GIMPLE_CATCH:
- return estimate_num_insns_seq (gimple_catch_handler (stmt), weights);
+ return estimate_num_insns_seq (gimple_catch_handler (
+ stmt->as_a_gimple_catch ()),
+ weights);
case GIMPLE_TRY:
return (estimate_num_insns_seq (gimple_try_eval (stmt), weights)
--
1.8.5.3