diff options
author | Andrew Macleod <amacleod@redhat.com> | 2013-07-12 22:06:36 +0000 |
---|---|---|
committer | Andrew Macleod <amacleod@redhat.com> | 2013-07-12 22:06:36 +0000 |
commit | 207d0b006fbb9d18da0b2a310a4d301fbebd0768 (patch) | |
tree | 17d5c3f4a6b9a275377e679d9481ef488b538abd | |
parent | dd95e709622763dbcd54fabd391199b7e1cd98ad (diff) |
Add as_a<Type>tree-wrapper
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/tree-wrapper@200930 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/gimple-tree-core.h | 11 | ||||
-rw-r--r-- | gcc/gimple-tree.h | 63 | ||||
-rw-r--r-- | gcc/tree-outof-ssa.c | 21 | ||||
-rw-r--r-- | gcc/tree-ssa-copyrename.c | 18 | ||||
-rw-r--r-- | gcc/tree-ssanames.c | 4 |
5 files changed, 92 insertions, 25 deletions
diff --git a/gcc/gimple-tree-core.h b/gcc/gimple-tree-core.h index 9c3098a2e81..247a3f5de2d 100644 --- a/gcc/gimple-tree-core.h +++ b/gcc/gimple-tree-core.h @@ -80,6 +80,10 @@ class GimpleValue : public TreeBase void set_code (enum tree_code); GimpleType type() const; void set_type (GimpleType); + void strip_nops(); + GimpleValue value_operand(const int i) const; + location_t expr_location() const; + template <typename T> inline T as_a() const; }; class GimpleDecl : public GimpleValue @@ -106,6 +110,13 @@ class GimpleDecl : public GimpleValue bool decl_from_inline () const; bool readonly () const; bool decl_ignored_p () const; + bool decl_external () const; + bool decl_visibility_specified() const; + bool decl_comdat() const; + + bool decl_static() const; + bool decl_public() const; + bool decl_asm_written() const; }; class SSADecl : public GimpleValue diff --git a/gcc/gimple-tree.h b/gcc/gimple-tree.h index eba0c0e2e65..bfeb41a3bc6 100644 --- a/gcc/gimple-tree.h +++ b/gcc/gimple-tree.h @@ -61,6 +61,24 @@ inline void GimpleValue::set_type (GimpleType t) { CONTAINS_STRUCT_CHECK (Tree, TS_TYPED)->typed.type = t; } +inline void +GimpleValue::strip_nops() +{ STRIP_NOPS (Tree); } + +inline GimpleValue +GimpleValue::value_operand(const int i) const +{ + GimpleValue tmp; + tmp = *(CONST_CAST2 (tree*, typeof (Tree)*, + tree_operand_check (Tree, i, __FILE__, __LINE__, __FUNCTION__))); + return tmp; +} + +inline location_t +GimpleValue::expr_location() const +{ return CAN_HAVE_LOCATION_P (Tree) ? Tree->exp.locus : UNKNOWN_LOCATION; } + + // // GimpleDecl methods // @@ -91,6 +109,31 @@ inline bool GimpleDecl::readonly () const { return NON_TYPE_CHECK (Tree)->base.readonly_flag; } +inline bool +GimpleDecl::decl_external () const +{ return DECL_COMMON_CHECK (Tree)->decl_common.decl_flag_1; } + + +inline bool +GimpleDecl::decl_static() const +{ return Tree->base.static_flag; } + +inline bool +GimpleDecl::decl_visibility_specified() const +{ return DECL_WITH_VIS_CHECK (Tree)->decl_with_vis.visibility_specified; } + +inline bool +GimpleDecl::decl_public() const +{ return Tree->base.public_flag; } + +inline bool +GimpleDecl::decl_comdat() const +{ return DECL_WITH_VIS_CHECK (Tree)->decl_with_vis.comdat_flag; } + +inline bool +GimpleDecl::decl_asm_written() const +{ return Tree->base.asm_written_flag; } + // // SSADecl @@ -183,4 +226,24 @@ inline bool SSADecl::ssa_name_same_base (const SSADecl &n) const { return (Tree->ssa_name.var == n.Tree->ssa_name.var); } +template <> +inline GimpleDecl +GimpleValue::as_a<GimpleDecl>() const +{ + GimpleDecl tmp; + if (Tree && tree_code_type[(int)code()] == tcc_declaration) + return tmp = Tree; + return tmp; +} + +template <> +inline SSADecl +GimpleValue::as_a<SSADecl>() const +{ + SSADecl tmp; + if (Tree && code() == SSA_NAME) + return tmp = Tree; + return tmp; +} + #endif diff --git a/gcc/tree-outof-ssa.c b/gcc/tree-outof-ssa.c index e6b1678bf05..a76fd880493 100644 --- a/gcc/tree-outof-ssa.c +++ b/gcc/tree-outof-ssa.c @@ -518,7 +518,7 @@ eliminate_build (elim_graph g) left in SSA form, just queue a copy to be emitted on this edge. */ if (!phi_ssa_name_p (Ti) - || (Ti.code() == SSA_NAME + || (Ti.as_a<SSADecl>() && var_to_partition (g->map, Ti) == NO_PARTITION)) { /* Save constant copies until all other copies have been emitted @@ -598,11 +598,10 @@ elim_backward (elim_graph g, int T) in NAME (a decl or SSA name), i.e. with matching mode and attributes. */ static rtx -get_temp_reg (GimpleValue name) +get_temp_reg (SSADecl name) { - GimpleDecl var = (name.code() == SSA_NAME - ? SSADecl(name).ssa_name_var() : name); + GimpleDecl var = name.ssa_name_var(); GimpleType type = var.type(); int unsignedp; enum machine_mode reg_mode = promote_decl_mode (var, &unsignedp); @@ -722,15 +721,14 @@ remove_gimple_phi_args (gimple phi) FOR_EACH_PHI_ARG (arg_p, phi, iter, SSA_OP_USE) { GimpleValue arg = USE_FROM_PTR (arg_p); - if (arg.code() == SSA_NAME) + if (SSADecl name = arg.as_a<SSADecl>()) { /* Remove the reference to the existing argument. */ SET_USE (arg_p, NULL_TREE); - if (has_zero_uses (arg)) + if (has_zero_uses (name)) { gimple stmt; gimple_stmt_iterator gsi; - SSADecl name = arg; stmt = name.ssa_name_def_stmt (); @@ -771,7 +769,7 @@ eliminate_useless_phis (void) for (i = 0; i < gimple_phi_num_args (phi); i++) { GimpleValue arg = PHI_ARG_DEF (phi, i); - if (arg.code() == SSA_NAME + if (arg.as_a<SSADecl>() && !virtual_operand_p (arg)) { fprintf (stderr, "Argument of PHI is not virtual ("); @@ -828,7 +826,7 @@ rewrite_trees (var_map map ATTRIBUTE_UNUSED) { GimpleValue arg = PHI_ARG_DEF (phi, i); - if (arg.code() == SSA_NAME + if (arg.as_a<SSADecl>() && var_to_partition (map, arg) != NO_PARTITION) { fprintf (stderr, "Argument of PHI is in a partition :("); @@ -1038,12 +1036,9 @@ insert_backedge_copies (void) for (i = 0; i < gimple_phi_num_args (phi); i++) { GimpleValue arg = gimple_phi_arg_def (phi, i); - SSADecl ssa_arg; + SSADecl ssa_arg = arg.as_a<SSADecl>(); edge e = gimple_phi_arg_edge (phi, i); - if (arg.code() == SSA_NAME) - ssa_arg = arg; - /* If the argument is not an SSA_NAME, then we will need a constant initialization. If the argument is an SSA_NAME with a different underlying variable then a copy statement will be diff --git a/gcc/tree-ssa-copyrename.c b/gcc/tree-ssa-copyrename.c index 4cde3d4bccd..ed95b5bebd3 100644 --- a/gcc/tree-ssa-copyrename.c +++ b/gcc/tree-ssa-copyrename.c @@ -354,9 +354,8 @@ rename_ssa_copies (void) for (i = 0; i < gimple_phi_num_args (phi); i++) { GimpleValue arg = PHI_ARG_DEF (phi, i); - if (arg.code () == SSA_NAME) - copy_rename_partition_coalesce (map, res, arg, - debug); + if (SSADecl name = arg.as_a<SSADecl>()) + copy_rename_partition_coalesce (map, res, name, debug); } /* Else if all arguments are in the same partition try to merge it with the result. */ @@ -367,14 +366,8 @@ rename_ssa_copies (void) for (i = 0; i < gimple_phi_num_args (phi); i++) { GimpleValue arg = PHI_ARG_DEF (phi, i); - if (arg.code() != SSA_NAME) + if (SSADecl name = arg.as_a<SSADecl>()) { - all_p_same = 0; - break; - } - else - { - SSADecl name = arg; if (all_p_same == -1) { p = partition_find (map->var_partition, @@ -389,6 +382,11 @@ rename_ssa_copies (void) break; } } + else + { + all_p_same = 0; + break; + } } if (all_p_same == 1) copy_rename_partition_coalesce (map, res, diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c index 8545355ac68..56b88c20379 100644 --- a/gcc/tree-ssanames.c +++ b/gcc/tree-ssanames.c @@ -398,8 +398,8 @@ release_defs (gimple stmt) gcc_assert (gimple_in_ssa_p (cfun)); FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_ALL_DEFS) - if (def.code () == SSA_NAME) - release_ssa_name (def); + if (SSADecl name = def.as_a<SSADecl>()) + release_ssa_name (name); } |