2014-02-21 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / tree-dfa.h
blob86590ad462d353a9b187493e39d5d60d9a3f9c59
1 /* Header file for tree data flow functions.
2 Copyright (C) 2013-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_TREE_DFA_H
21 #define GCC_TREE_DFA_H
23 extern void renumber_gimple_stmt_uids (void);
24 extern void renumber_gimple_stmt_uids_in_blocks (basic_block *, int);
25 extern void dump_variable (FILE *, tree);
26 extern void debug_variable (tree);
27 extern void dump_dfa_stats (FILE *);
28 extern void debug_dfa_stats (void);
29 extern tree ssa_default_def (struct function *, tree);
30 extern void set_ssa_default_def (struct function *, tree, tree);
31 extern tree get_or_create_ssa_default_def (struct function *, tree);
32 extern tree get_ref_base_and_extent (tree, HOST_WIDE_INT *,
33 HOST_WIDE_INT *, HOST_WIDE_INT *);
34 extern tree get_addr_base_and_unit_offset (tree, HOST_WIDE_INT *);
35 extern bool stmt_references_abnormal_ssa_name (gimple);
36 extern void dump_enumerated_decls (FILE *, int);
38 /* Returns the base object and a constant BITS_PER_UNIT offset in *POFFSET that
39 denotes the starting address of the memory access EXP.
40 Returns NULL_TREE if the offset is not constant or any component
41 is not BITS_PER_UNIT-aligned.
42 VALUEIZE if non-NULL is used to valueize SSA names. It should return
43 its argument or a constant if the argument is known to be constant. */
44 /* ??? This is a static inline here to avoid the overhead of the indirect calls
45 to VALUEIZE. But is this overhead really that significant? And should we
46 perhaps just rely on WHOPR to specialize the function? */
48 static inline tree
49 get_addr_base_and_unit_offset_1 (tree exp, HOST_WIDE_INT *poffset,
50 tree (*valueize) (tree))
52 HOST_WIDE_INT byte_offset = 0;
54 /* Compute cumulative byte-offset for nested component-refs and array-refs,
55 and find the ultimate containing object. */
56 while (1)
58 switch (TREE_CODE (exp))
60 case BIT_FIELD_REF:
62 HOST_WIDE_INT this_off = TREE_INT_CST_LOW (TREE_OPERAND (exp, 2));
63 if (this_off % BITS_PER_UNIT)
64 return NULL_TREE;
65 byte_offset += this_off / BITS_PER_UNIT;
67 break;
69 case COMPONENT_REF:
71 tree field = TREE_OPERAND (exp, 1);
72 tree this_offset = component_ref_field_offset (exp);
73 HOST_WIDE_INT hthis_offset;
75 if (!this_offset
76 || TREE_CODE (this_offset) != INTEGER_CST
77 || (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field))
78 % BITS_PER_UNIT))
79 return NULL_TREE;
81 hthis_offset = TREE_INT_CST_LOW (this_offset);
82 hthis_offset += (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field))
83 / BITS_PER_UNIT);
84 byte_offset += hthis_offset;
86 break;
88 case ARRAY_REF:
89 case ARRAY_RANGE_REF:
91 tree index = TREE_OPERAND (exp, 1);
92 tree low_bound, unit_size;
94 if (valueize
95 && TREE_CODE (index) == SSA_NAME)
96 index = (*valueize) (index);
98 /* If the resulting bit-offset is constant, track it. */
99 if (TREE_CODE (index) == INTEGER_CST
100 && (low_bound = array_ref_low_bound (exp),
101 TREE_CODE (low_bound) == INTEGER_CST)
102 && (unit_size = array_ref_element_size (exp),
103 TREE_CODE (unit_size) == INTEGER_CST))
105 double_int doffset
106 = (TREE_INT_CST (index) - TREE_INT_CST (low_bound))
107 .sext (TYPE_PRECISION (TREE_TYPE (index)));
108 doffset *= tree_to_double_int (unit_size);
109 byte_offset += doffset.to_shwi ();
111 else
112 return NULL_TREE;
114 break;
116 case REALPART_EXPR:
117 break;
119 case IMAGPART_EXPR:
120 byte_offset += TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (exp)));
121 break;
123 case VIEW_CONVERT_EXPR:
124 break;
126 case MEM_REF:
128 tree base = TREE_OPERAND (exp, 0);
129 if (valueize
130 && TREE_CODE (base) == SSA_NAME)
131 base = (*valueize) (base);
133 /* Hand back the decl for MEM[&decl, off]. */
134 if (TREE_CODE (base) == ADDR_EXPR)
136 if (!integer_zerop (TREE_OPERAND (exp, 1)))
138 double_int off = mem_ref_offset (exp);
139 gcc_assert (off.high == -1 || off.high == 0);
140 byte_offset += off.to_shwi ();
142 exp = TREE_OPERAND (base, 0);
144 goto done;
147 case TARGET_MEM_REF:
149 tree base = TREE_OPERAND (exp, 0);
150 if (valueize
151 && TREE_CODE (base) == SSA_NAME)
152 base = (*valueize) (base);
154 /* Hand back the decl for MEM[&decl, off]. */
155 if (TREE_CODE (base) == ADDR_EXPR)
157 if (TMR_INDEX (exp) || TMR_INDEX2 (exp))
158 return NULL_TREE;
159 if (!integer_zerop (TMR_OFFSET (exp)))
161 double_int off = mem_ref_offset (exp);
162 gcc_assert (off.high == -1 || off.high == 0);
163 byte_offset += off.to_shwi ();
165 exp = TREE_OPERAND (base, 0);
167 goto done;
170 default:
171 goto done;
174 exp = TREE_OPERAND (exp, 0);
176 done:
178 *poffset = byte_offset;
179 return exp;
184 #endif /* GCC_TREE_DFA_H */