* config/ia64/ia64.md: Define new attribute "empty".
[official-gcc.git] / gcc / tree-ssa-copy.c
blob1f87c1be4bff770f983d88864fdf939664303365
1 /* Const/copy propagation and SSA_NAME replacement support routines.
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "flags.h"
27 #include "rtl.h"
28 #include "tm_p.h"
29 #include "ggc.h"
30 #include "basic-block.h"
31 #include "output.h"
32 #include "errors.h"
33 #include "expr.h"
34 #include "function.h"
35 #include "diagnostic.h"
36 #include "timevar.h"
37 #include "tree-dump.h"
38 #include "tree-flow.h"
39 #include "tree-pass.h"
40 #include "langhooks.h"
42 /* This file provides a handful of interfaces for performing const/copy
43 propagation and simple expression replacement which keep variable
44 annotations up-to-date.
46 We require that for any copy operation where the RHS and LHS have
47 a non-null memory tag that the memory tag be the same. It is OK
48 for one or both of the memory tags to be NULL.
50 We also require tracking if a variable is dereferenced in a load or
51 store operation.
53 We enforce these requirements by having all copy propagation and
54 replacements of one SSA_NAME with a different SSA_NAME to use the
55 APIs defined in this file. */
58 /* Given two SSA_NAMEs, replace the annotations for the one referred to by OP
59 with VAR's annotations.
61 If OP is a pointer, copy the memory tag used originally by OP into
62 VAR. This is needed in cases where VAR had never been dereferenced in the
63 program.
65 If FOR_PROPAGATION is true, then perform additional checks to ensure
66 that const/copy propagation of var for OP is valid. */
68 static void
69 replace_ssa_names_ann (tree op,
70 tree var,
71 bool for_propagation ATTRIBUTE_UNUSED)
73 #if defined ENABLE_CHECKING
74 if (for_propagation && !may_propagate_copy (op, var))
75 abort ();
76 #endif
78 /* If VAR doesn't have a memory tag, copy the one from the original
79 operand. Also copy the dereferenced flags. */
80 if (POINTER_TYPE_P (TREE_TYPE (op)))
82 var_ann_t new_ann = var_ann (SSA_NAME_VAR (var));
83 var_ann_t orig_ann = var_ann (SSA_NAME_VAR (op));
85 if (new_ann->type_mem_tag == NULL_TREE)
86 new_ann->type_mem_tag = orig_ann->type_mem_tag;
87 else if (orig_ann->type_mem_tag == NULL_TREE)
88 orig_ann->type_mem_tag = new_ann->type_mem_tag;
89 else if (new_ann->type_mem_tag != orig_ann->type_mem_tag)
90 abort ();
96 /* Common code for propagate_value and replace_exp.
98 Replace use operand OP_P with VAL. FOR_PROPAGATION indicates if the
99 replacement is done to propagate a value or not. */
101 static void
102 replace_exp_1 (use_operand_p op_p, tree val, bool for_propagation)
104 if (TREE_CODE (val) == SSA_NAME)
106 if (TREE_CODE (USE_FROM_PTR (op_p)) == SSA_NAME)
107 replace_ssa_names_ann (USE_FROM_PTR (op_p), val, for_propagation);
108 SET_USE (op_p, val);
110 else
111 SET_USE (op_p, lhd_unsave_expr_now (val));
115 /* Propagate the value VAL (assumed to be a constant or another SSA_NAME)
116 into the operand pointed by OP_P.
118 Use this version for const/copy propagation as it will perform additional
119 checks to ensure validity of the const/copy propagation. */
121 void
122 propagate_value (use_operand_p op_p, tree val)
124 replace_exp_1 (op_p, val, true);
128 /* Propagate the value VAL (assumed to be a constant or another SSA_NAME)
129 into the tree pointed by OP_P.
131 Use this version for const/copy propagation when SSA operands are not
132 available. It will perform the additional checks to ensure validity of
133 the const/copy propagation, but will not update any operand information.
134 Be sure to mark the stmt as modified. */
136 void
137 propagate_tree_value (tree *op_p, tree val)
139 if (TREE_CODE (val) == SSA_NAME)
141 if (TREE_CODE (*op_p) == SSA_NAME)
142 replace_ssa_names_ann (*op_p, val, true);
143 *op_p = val;
145 else
146 *op_p = lhd_unsave_expr_now (val);
150 /* Replace *OP_P with value VAL (assumed to be a constant or another SSA_NAME).
152 Use this version when not const/copy propagating values. For example,
153 PRE uses this version when building expressions as they would appear
154 in specific blocks taking into account actions of PHI nodes. */
156 void
157 replace_exp (use_operand_p op_p, tree val)
159 replace_exp_1 (op_p, val, false);