GCC Middle and Back End API Reference
tree-dfa.h
Go to the documentation of this file.
1 /* Header file for tree data flow functions.
2  Copyright (C) 2013 Free Software Foundation, Inc.
3 
4 This file is part of GCC.
5 
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.
10 
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.
15 
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/>. */
19 
20 #ifndef GCC_TREE_DFA_H
21 #define GCC_TREE_DFA_H
22 
23 extern void renumber_gimple_stmt_uids (void);
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);
36 extern void dump_enumerated_decls (FILE *, int);
37 
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? */
47 
48 static inline tree
50  tree (*valueize) (tree))
51 {
52  HOST_WIDE_INT byte_offset = 0;
53 
54  /* Compute cumulative byte-offset for nested component-refs and array-refs,
55  and find the ultimate containing object. */
56  while (1)
57  {
58  switch (TREE_CODE (exp))
59  {
60  case BIT_FIELD_REF:
61  {
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;
66  }
67  break;
68 
69  case COMPONENT_REF:
70  {
71  tree field = TREE_OPERAND (exp, 1);
72  tree this_offset = component_ref_field_offset (exp);
73  HOST_WIDE_INT hthis_offset;
74 
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;
80 
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;
85  }
86  break;
87 
88  case ARRAY_REF:
89  case ARRAY_RANGE_REF:
90  {
91  tree index = TREE_OPERAND (exp, 1);
92  tree low_bound, unit_size;
93 
94  if (valueize
95  && TREE_CODE (index) == SSA_NAME)
96  index = (*valueize) (index);
97 
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))
104  {
105  HOST_WIDE_INT hindex = TREE_INT_CST_LOW (index);
106 
107  hindex -= TREE_INT_CST_LOW (low_bound);
108  hindex *= TREE_INT_CST_LOW (unit_size);
109  byte_offset += hindex;
110  }
111  else
112  return NULL_TREE;
113  }
114  break;
115 
116  case REALPART_EXPR:
117  break;
118 
119  case IMAGPART_EXPR:
120  byte_offset += TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (exp)));
121  break;
122 
123  case VIEW_CONVERT_EXPR:
124  break;
125 
126  case MEM_REF:
127  {
128  tree base = TREE_OPERAND (exp, 0);
129  if (valueize
130  && TREE_CODE (base) == SSA_NAME)
131  base = (*valueize) (base);
132 
133  /* Hand back the decl for MEM[&decl, off]. */
134  if (TREE_CODE (base) == ADDR_EXPR)
135  {
136  if (!integer_zerop (TREE_OPERAND (exp, 1)))
137  {
138  double_int off = mem_ref_offset (exp);
139  gcc_assert (off.high == -1 || off.high == 0);
140  byte_offset += off.to_shwi ();
141  }
142  exp = TREE_OPERAND (base, 0);
143  }
144  goto done;
145  }
146 
147  case TARGET_MEM_REF:
148  {
149  tree base = TREE_OPERAND (exp, 0);
150  if (valueize
151  && TREE_CODE (base) == SSA_NAME)
152  base = (*valueize) (base);
153 
154  /* Hand back the decl for MEM[&decl, off]. */
155  if (TREE_CODE (base) == ADDR_EXPR)
156  {
157  if (TMR_INDEX (exp) || TMR_INDEX2 (exp))
158  return NULL_TREE;
159  if (!integer_zerop (TMR_OFFSET (exp)))
160  {
161  double_int off = mem_ref_offset (exp);
162  gcc_assert (off.high == -1 || off.high == 0);
163  byte_offset += off.to_shwi ();
164  }
165  exp = TREE_OPERAND (base, 0);
166  }
167  goto done;
168  }
169 
170  default:
171  goto done;
172  }
173 
174  exp = TREE_OPERAND (exp, 0);
175  }
176 done:
177 
178  *poffset = byte_offset;
179  return exp;
180 }
181 
182 
183 
184 #endif /* GCC_TREE_DFA_H */