annotate gcc/dwarf2cfi.c @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Dwarf2 Call Frame Information helper routines.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 1992-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "target.h"
kono
parents:
diff changeset
24 #include "function.h"
kono
parents:
diff changeset
25 #include "rtl.h"
kono
parents:
diff changeset
26 #include "tree.h"
kono
parents:
diff changeset
27 #include "tree-pass.h"
kono
parents:
diff changeset
28 #include "memmodel.h"
kono
parents:
diff changeset
29 #include "tm_p.h"
kono
parents:
diff changeset
30 #include "emit-rtl.h"
kono
parents:
diff changeset
31 #include "stor-layout.h"
kono
parents:
diff changeset
32 #include "cfgbuild.h"
kono
parents:
diff changeset
33 #include "dwarf2out.h"
kono
parents:
diff changeset
34 #include "dwarf2asm.h"
kono
parents:
diff changeset
35 #include "common/common-target.h"
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 #include "except.h" /* expand_builtin_dwarf_sp_column */
kono
parents:
diff changeset
38 #include "profile-count.h" /* For expr.h */
kono
parents:
diff changeset
39 #include "expr.h" /* init_return_column_size */
kono
parents:
diff changeset
40 #include "output.h" /* asm_out_file */
kono
parents:
diff changeset
41 #include "debug.h" /* dwarf2out_do_frame, dwarf2out_do_cfi_asm */
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* ??? Poison these here until it can be done generically. They've been
kono
parents:
diff changeset
45 totally replaced in this file; make sure it stays that way. */
kono
parents:
diff changeset
46 #undef DWARF2_UNWIND_INFO
kono
parents:
diff changeset
47 #undef DWARF2_FRAME_INFO
kono
parents:
diff changeset
48 #if (GCC_VERSION >= 3000)
kono
parents:
diff changeset
49 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
kono
parents:
diff changeset
50 #endif
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 #ifndef INCOMING_RETURN_ADDR_RTX
kono
parents:
diff changeset
53 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
kono
parents:
diff changeset
54 #endif
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
55
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
56 #ifndef DEFAULT_INCOMING_FRAME_SP_OFFSET
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
57 #define DEFAULT_INCOMING_FRAME_SP_OFFSET INCOMING_FRAME_SP_OFFSET
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
58 #endif
111
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 /* A collected description of an entire row of the abstract CFI table. */
kono
parents:
diff changeset
61 struct GTY(()) dw_cfi_row
kono
parents:
diff changeset
62 {
kono
parents:
diff changeset
63 /* The expression that computes the CFA, expressed in two different ways.
kono
parents:
diff changeset
64 The CFA member for the simple cases, and the full CFI expression for
kono
parents:
diff changeset
65 the complex cases. The later will be a DW_CFA_cfa_expression. */
kono
parents:
diff changeset
66 dw_cfa_location cfa;
kono
parents:
diff changeset
67 dw_cfi_ref cfa_cfi;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 /* The expressions for any register column that is saved. */
kono
parents:
diff changeset
70 cfi_vec reg_save;
kono
parents:
diff changeset
71 };
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
kono
parents:
diff changeset
74 struct GTY(()) reg_saved_in_data {
kono
parents:
diff changeset
75 rtx orig_reg;
kono
parents:
diff changeset
76 rtx saved_in_reg;
kono
parents:
diff changeset
77 };
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 /* Since we no longer have a proper CFG, we're going to create a facsimile
kono
parents:
diff changeset
81 of one on the fly while processing the frame-related insns.
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 We create dw_trace_info structures for each extended basic block beginning
kono
parents:
diff changeset
84 and ending at a "save point". Save points are labels, barriers, certain
kono
parents:
diff changeset
85 notes, and of course the beginning and end of the function.
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 As we encounter control transfer insns, we propagate the "current"
kono
parents:
diff changeset
88 row state across the edges to the starts of traces. When checking is
kono
parents:
diff changeset
89 enabled, we validate that we propagate the same data from all sources.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 All traces are members of the TRACE_INFO array, in the order in which
kono
parents:
diff changeset
92 they appear in the instruction stream.
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 All save points are present in the TRACE_INDEX hash, mapping the insn
kono
parents:
diff changeset
95 starting a trace to the dw_trace_info describing the trace. */
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 struct dw_trace_info
kono
parents:
diff changeset
98 {
kono
parents:
diff changeset
99 /* The insn that begins the trace. */
kono
parents:
diff changeset
100 rtx_insn *head;
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 /* The row state at the beginning and end of the trace. */
kono
parents:
diff changeset
103 dw_cfi_row *beg_row, *end_row;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 /* Tracking for DW_CFA_GNU_args_size. The "true" sizes are those we find
kono
parents:
diff changeset
106 while scanning insns. However, the args_size value is irrelevant at
kono
parents:
diff changeset
107 any point except can_throw_internal_p insns. Therefore the "delay"
kono
parents:
diff changeset
108 sizes the values that must actually be emitted for this trace. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109 poly_int64_pod beg_true_args_size, end_true_args_size;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
110 poly_int64_pod beg_delay_args_size, end_delay_args_size;
111
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 /* The first EH insn in the trace, where beg_delay_args_size must be set. */
kono
parents:
diff changeset
113 rtx_insn *eh_head;
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 /* The following variables contain data used in interpreting frame related
kono
parents:
diff changeset
116 expressions. These are not part of the "real" row state as defined by
kono
parents:
diff changeset
117 Dwarf, but it seems like they need to be propagated into a trace in case
kono
parents:
diff changeset
118 frame related expressions have been sunk. */
kono
parents:
diff changeset
119 /* ??? This seems fragile. These variables are fragments of a larger
kono
parents:
diff changeset
120 expression. If we do not keep the entire expression together, we risk
kono
parents:
diff changeset
121 not being able to put it together properly. Consider forcing targets
kono
parents:
diff changeset
122 to generate self-contained expressions and dropping all of the magic
kono
parents:
diff changeset
123 interpretation code in this file. Or at least refusing to shrink wrap
kono
parents:
diff changeset
124 any frame related insn that doesn't contain a complete expression. */
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 /* The register used for saving registers to the stack, and its offset
kono
parents:
diff changeset
127 from the CFA. */
kono
parents:
diff changeset
128 dw_cfa_location cfa_store;
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 /* A temporary register holding an integral value used in adjusting SP
kono
parents:
diff changeset
131 or setting up the store_reg. The "offset" field holds the integer
kono
parents:
diff changeset
132 value, not an offset. */
kono
parents:
diff changeset
133 dw_cfa_location cfa_temp;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 /* A set of registers saved in other registers. This is the inverse of
kono
parents:
diff changeset
136 the row->reg_save info, if the entry is a DW_CFA_register. This is
kono
parents:
diff changeset
137 implemented as a flat array because it normally contains zero or 1
kono
parents:
diff changeset
138 entry, depending on the target. IA-64 is the big spender here, using
kono
parents:
diff changeset
139 a maximum of 5 entries. */
kono
parents:
diff changeset
140 vec<reg_saved_in_data> regs_saved_in_regs;
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 /* An identifier for this trace. Used only for debugging dumps. */
kono
parents:
diff changeset
143 unsigned id;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 /* True if this trace immediately follows NOTE_INSN_SWITCH_TEXT_SECTIONS. */
kono
parents:
diff changeset
146 bool switch_sections;
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 /* True if we've seen different values incoming to beg_true_args_size. */
kono
parents:
diff changeset
149 bool args_size_undefined;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
150
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
151 /* True if we've seen an insn with a REG_ARGS_SIZE note before EH_HEAD. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
152 bool args_size_defined_for_eh;
111
kono
parents:
diff changeset
153 };
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 /* Hashtable helpers. */
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 struct trace_info_hasher : nofree_ptr_hash <dw_trace_info>
kono
parents:
diff changeset
159 {
kono
parents:
diff changeset
160 static inline hashval_t hash (const dw_trace_info *);
kono
parents:
diff changeset
161 static inline bool equal (const dw_trace_info *, const dw_trace_info *);
kono
parents:
diff changeset
162 };
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 inline hashval_t
kono
parents:
diff changeset
165 trace_info_hasher::hash (const dw_trace_info *ti)
kono
parents:
diff changeset
166 {
kono
parents:
diff changeset
167 return INSN_UID (ti->head);
kono
parents:
diff changeset
168 }
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 inline bool
kono
parents:
diff changeset
171 trace_info_hasher::equal (const dw_trace_info *a, const dw_trace_info *b)
kono
parents:
diff changeset
172 {
kono
parents:
diff changeset
173 return a->head == b->head;
kono
parents:
diff changeset
174 }
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 /* The variables making up the pseudo-cfg, as described above. */
kono
parents:
diff changeset
178 static vec<dw_trace_info> trace_info;
kono
parents:
diff changeset
179 static vec<dw_trace_info *> trace_work_list;
kono
parents:
diff changeset
180 static hash_table<trace_info_hasher> *trace_index;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 /* A vector of call frame insns for the CIE. */
kono
parents:
diff changeset
183 cfi_vec cie_cfi_vec;
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 /* The state of the first row of the FDE table, which includes the
kono
parents:
diff changeset
186 state provided by the CIE. */
kono
parents:
diff changeset
187 static GTY(()) dw_cfi_row *cie_cfi_row;
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 static GTY(()) reg_saved_in_data *cie_return_save;
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 static GTY(()) unsigned long dwarf2out_cfi_label_num;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 /* The insn after which a new CFI note should be emitted. */
kono
parents:
diff changeset
194 static rtx_insn *add_cfi_insn;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 /* When non-null, add_cfi will add the CFI to this vector. */
kono
parents:
diff changeset
197 static cfi_vec *add_cfi_vec;
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 /* The current instruction trace. */
kono
parents:
diff changeset
200 static dw_trace_info *cur_trace;
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 /* The current, i.e. most recently generated, row of the CFI table. */
kono
parents:
diff changeset
203 static dw_cfi_row *cur_row;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 /* A copy of the current CFA, for use during the processing of a
kono
parents:
diff changeset
206 single insn. */
kono
parents:
diff changeset
207 static dw_cfa_location *cur_cfa;
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 /* We delay emitting a register save until either (a) we reach the end
kono
parents:
diff changeset
210 of the prologue or (b) the register is clobbered. This clusters
kono
parents:
diff changeset
211 register saves so that there are fewer pc advances. */
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 struct queued_reg_save {
kono
parents:
diff changeset
214 rtx reg;
kono
parents:
diff changeset
215 rtx saved_reg;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
216 poly_int64_pod cfa_offset;
111
kono
parents:
diff changeset
217 };
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 static vec<queued_reg_save> queued_reg_saves;
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 /* True if any CFI directives were emitted at the current insn. */
kono
parents:
diff changeset
223 static bool any_cfis_emitted;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 /* Short-hand for commonly used register numbers. */
kono
parents:
diff changeset
226 static unsigned dw_stack_pointer_regnum;
kono
parents:
diff changeset
227 static unsigned dw_frame_pointer_regnum;
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 /* Hook used by __throw. */
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 rtx
kono
parents:
diff changeset
232 expand_builtin_dwarf_sp_column (void)
kono
parents:
diff changeset
233 {
kono
parents:
diff changeset
234 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
kono
parents:
diff changeset
235 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
kono
parents:
diff changeset
236 }
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 /* MEM is a memory reference for the register size table, each element of
kono
parents:
diff changeset
239 which has mode MODE. Initialize column C as a return address column. */
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 static void
kono
parents:
diff changeset
242 init_return_column_size (scalar_int_mode mode, rtx mem, unsigned int c)
kono
parents:
diff changeset
243 {
kono
parents:
diff changeset
244 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
kono
parents:
diff changeset
245 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
kono
parents:
diff changeset
246 emit_move_insn (adjust_address (mem, mode, offset),
kono
parents:
diff changeset
247 gen_int_mode (size, mode));
kono
parents:
diff changeset
248 }
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 /* Datastructure used by expand_builtin_init_dwarf_reg_sizes and
kono
parents:
diff changeset
251 init_one_dwarf_reg_size to communicate on what has been done by the
kono
parents:
diff changeset
252 latter. */
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 struct init_one_dwarf_reg_state
kono
parents:
diff changeset
255 {
kono
parents:
diff changeset
256 /* Whether the dwarf return column was initialized. */
kono
parents:
diff changeset
257 bool wrote_return_column;
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 /* For each hard register REGNO, whether init_one_dwarf_reg_size
kono
parents:
diff changeset
260 was given REGNO to process already. */
kono
parents:
diff changeset
261 bool processed_regno [FIRST_PSEUDO_REGISTER];
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 };
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 /* Helper for expand_builtin_init_dwarf_reg_sizes. Generate code to
kono
parents:
diff changeset
266 initialize the dwarf register size table entry corresponding to register
kono
parents:
diff changeset
267 REGNO in REGMODE. TABLE is the table base address, SLOTMODE is the mode to
kono
parents:
diff changeset
268 use for the size entry to initialize, and INIT_STATE is the communication
kono
parents:
diff changeset
269 datastructure conveying what we're doing to our caller. */
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 static
kono
parents:
diff changeset
272 void init_one_dwarf_reg_size (int regno, machine_mode regmode,
kono
parents:
diff changeset
273 rtx table, machine_mode slotmode,
kono
parents:
diff changeset
274 init_one_dwarf_reg_state *init_state)
kono
parents:
diff changeset
275 {
kono
parents:
diff changeset
276 const unsigned int dnum = DWARF_FRAME_REGNUM (regno);
kono
parents:
diff changeset
277 const unsigned int rnum = DWARF2_FRAME_REG_OUT (dnum, 1);
kono
parents:
diff changeset
278 const unsigned int dcol = DWARF_REG_TO_UNWIND_COLUMN (rnum);
kono
parents:
diff changeset
279
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
280 poly_int64 slotoffset = dcol * GET_MODE_SIZE (slotmode);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
281 poly_int64 regsize = GET_MODE_SIZE (regmode);
111
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 init_state->processed_regno[regno] = true;
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 if (rnum >= DWARF_FRAME_REGISTERS)
kono
parents:
diff changeset
286 return;
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 if (dnum == DWARF_FRAME_RETURN_COLUMN)
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 if (regmode == VOIDmode)
kono
parents:
diff changeset
291 return;
kono
parents:
diff changeset
292 init_state->wrote_return_column = true;
kono
parents:
diff changeset
293 }
kono
parents:
diff changeset
294
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
295 /* ??? When is this true? Should it be a test based on DCOL instead? */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
296 if (maybe_lt (slotoffset, 0))
111
kono
parents:
diff changeset
297 return;
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 emit_move_insn (adjust_address (table, slotmode, slotoffset),
kono
parents:
diff changeset
300 gen_int_mode (regsize, slotmode));
kono
parents:
diff changeset
301 }
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 /* Generate code to initialize the dwarf register size table located
kono
parents:
diff changeset
304 at the provided ADDRESS. */
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 void
kono
parents:
diff changeset
307 expand_builtin_init_dwarf_reg_sizes (tree address)
kono
parents:
diff changeset
308 {
kono
parents:
diff changeset
309 unsigned int i;
kono
parents:
diff changeset
310 scalar_int_mode mode = SCALAR_INT_TYPE_MODE (char_type_node);
kono
parents:
diff changeset
311 rtx addr = expand_normal (address);
kono
parents:
diff changeset
312 rtx mem = gen_rtx_MEM (BLKmode, addr);
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 init_one_dwarf_reg_state init_state;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 memset ((char *)&init_state, 0, sizeof (init_state));
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
kono
parents:
diff changeset
319 {
kono
parents:
diff changeset
320 machine_mode save_mode;
kono
parents:
diff changeset
321 rtx span;
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 /* No point in processing a register multiple times. This could happen
kono
parents:
diff changeset
324 with register spans, e.g. when a reg is first processed as a piece of
kono
parents:
diff changeset
325 a span, then as a register on its own later on. */
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 if (init_state.processed_regno[i])
kono
parents:
diff changeset
328 continue;
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 save_mode = targetm.dwarf_frame_reg_mode (i);
kono
parents:
diff changeset
331 span = targetm.dwarf_register_span (gen_rtx_REG (save_mode, i));
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 if (!span)
kono
parents:
diff changeset
334 init_one_dwarf_reg_size (i, save_mode, mem, mode, &init_state);
kono
parents:
diff changeset
335 else
kono
parents:
diff changeset
336 {
kono
parents:
diff changeset
337 for (int si = 0; si < XVECLEN (span, 0); si++)
kono
parents:
diff changeset
338 {
kono
parents:
diff changeset
339 rtx reg = XVECEXP (span, 0, si);
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 init_one_dwarf_reg_size
kono
parents:
diff changeset
342 (REGNO (reg), GET_MODE (reg), mem, mode, &init_state);
kono
parents:
diff changeset
343 }
kono
parents:
diff changeset
344 }
kono
parents:
diff changeset
345 }
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 if (!init_state.wrote_return_column)
kono
parents:
diff changeset
348 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
kono
parents:
diff changeset
351 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
kono
parents:
diff changeset
352 #endif
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 targetm.init_dwarf_reg_sizes_extra (address);
kono
parents:
diff changeset
355 }
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 static dw_trace_info *
kono
parents:
diff changeset
359 get_trace_info (rtx_insn *insn)
kono
parents:
diff changeset
360 {
kono
parents:
diff changeset
361 dw_trace_info dummy;
kono
parents:
diff changeset
362 dummy.head = insn;
kono
parents:
diff changeset
363 return trace_index->find_with_hash (&dummy, INSN_UID (insn));
kono
parents:
diff changeset
364 }
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 static bool
kono
parents:
diff changeset
367 save_point_p (rtx_insn *insn)
kono
parents:
diff changeset
368 {
kono
parents:
diff changeset
369 /* Labels, except those that are really jump tables. */
kono
parents:
diff changeset
370 if (LABEL_P (insn))
kono
parents:
diff changeset
371 return inside_basic_block_p (insn);
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 /* We split traces at the prologue/epilogue notes because those
kono
parents:
diff changeset
374 are points at which the unwind info is usually stable. This
kono
parents:
diff changeset
375 makes it easier to find spots with identical unwind info so
kono
parents:
diff changeset
376 that we can use remember/restore_state opcodes. */
kono
parents:
diff changeset
377 if (NOTE_P (insn))
kono
parents:
diff changeset
378 switch (NOTE_KIND (insn))
kono
parents:
diff changeset
379 {
kono
parents:
diff changeset
380 case NOTE_INSN_PROLOGUE_END:
kono
parents:
diff changeset
381 case NOTE_INSN_EPILOGUE_BEG:
kono
parents:
diff changeset
382 return true;
kono
parents:
diff changeset
383 }
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 return false;
kono
parents:
diff changeset
386 }
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 static inline HOST_WIDE_INT
kono
parents:
diff changeset
391 div_data_align (HOST_WIDE_INT off)
kono
parents:
diff changeset
392 {
kono
parents:
diff changeset
393 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
kono
parents:
diff changeset
394 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
kono
parents:
diff changeset
395 return r;
kono
parents:
diff changeset
396 }
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 /* Return true if we need a signed version of a given opcode
kono
parents:
diff changeset
399 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 static inline bool
kono
parents:
diff changeset
402 need_data_align_sf_opcode (HOST_WIDE_INT off)
kono
parents:
diff changeset
403 {
kono
parents:
diff changeset
404 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
kono
parents:
diff changeset
405 }
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 /* Return a pointer to a newly allocated Call Frame Instruction. */
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 static inline dw_cfi_ref
kono
parents:
diff changeset
410 new_cfi (void)
kono
parents:
diff changeset
411 {
kono
parents:
diff changeset
412 dw_cfi_ref cfi = ggc_alloc<dw_cfi_node> ();
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
kono
parents:
diff changeset
415 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 return cfi;
kono
parents:
diff changeset
418 }
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 /* Return a newly allocated CFI row, with no defined data. */
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 static dw_cfi_row *
kono
parents:
diff changeset
423 new_cfi_row (void)
kono
parents:
diff changeset
424 {
kono
parents:
diff changeset
425 dw_cfi_row *row = ggc_cleared_alloc<dw_cfi_row> ();
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 row->cfa.reg = INVALID_REGNUM;
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 return row;
kono
parents:
diff changeset
430 }
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 /* Return a copy of an existing CFI row. */
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 static dw_cfi_row *
kono
parents:
diff changeset
435 copy_cfi_row (dw_cfi_row *src)
kono
parents:
diff changeset
436 {
kono
parents:
diff changeset
437 dw_cfi_row *dst = ggc_alloc<dw_cfi_row> ();
kono
parents:
diff changeset
438
kono
parents:
diff changeset
439 *dst = *src;
kono
parents:
diff changeset
440 dst->reg_save = vec_safe_copy (src->reg_save);
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 return dst;
kono
parents:
diff changeset
443 }
kono
parents:
diff changeset
444
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
445 /* Return a copy of an existing CFA location. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
446
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
447 static dw_cfa_location *
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
448 copy_cfa (dw_cfa_location *src)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
449 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
450 dw_cfa_location *dst = ggc_alloc<dw_cfa_location> ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
451 *dst = *src;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
452 return dst;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
453 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
454
111
kono
parents:
diff changeset
455 /* Generate a new label for the CFI info to refer to. */
kono
parents:
diff changeset
456
kono
parents:
diff changeset
457 static char *
kono
parents:
diff changeset
458 dwarf2out_cfi_label (void)
kono
parents:
diff changeset
459 {
kono
parents:
diff changeset
460 int num = dwarf2out_cfi_label_num++;
kono
parents:
diff changeset
461 char label[20];
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 return xstrdup (label);
kono
parents:
diff changeset
466 }
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 /* Add CFI either to the current insn stream or to a vector, or both. */
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 static void
kono
parents:
diff changeset
471 add_cfi (dw_cfi_ref cfi)
kono
parents:
diff changeset
472 {
kono
parents:
diff changeset
473 any_cfis_emitted = true;
kono
parents:
diff changeset
474
kono
parents:
diff changeset
475 if (add_cfi_insn != NULL)
kono
parents:
diff changeset
476 {
kono
parents:
diff changeset
477 add_cfi_insn = emit_note_after (NOTE_INSN_CFI, add_cfi_insn);
kono
parents:
diff changeset
478 NOTE_CFI (add_cfi_insn) = cfi;
kono
parents:
diff changeset
479 }
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 if (add_cfi_vec != NULL)
kono
parents:
diff changeset
482 vec_safe_push (*add_cfi_vec, cfi);
kono
parents:
diff changeset
483 }
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 static void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
486 add_cfi_args_size (poly_int64 size)
111
kono
parents:
diff changeset
487 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
488 /* We don't yet have a representation for polynomial sizes. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
489 HOST_WIDE_INT const_size = size.to_constant ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
490
111
kono
parents:
diff changeset
491 dw_cfi_ref cfi = new_cfi ();
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 /* While we can occasionally have args_size < 0 internally, this state
kono
parents:
diff changeset
494 should not persist at a point we actually need an opcode. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
495 gcc_assert (const_size >= 0);
111
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
498 cfi->dw_cfi_oprnd1.dw_cfi_offset = const_size;
111
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 add_cfi (cfi);
kono
parents:
diff changeset
501 }
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 static void
kono
parents:
diff changeset
504 add_cfi_restore (unsigned reg)
kono
parents:
diff changeset
505 {
kono
parents:
diff changeset
506 dw_cfi_ref cfi = new_cfi ();
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 cfi->dw_cfi_opc = (reg & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
kono
parents:
diff changeset
509 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 add_cfi (cfi);
kono
parents:
diff changeset
512 }
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 /* Perform ROW->REG_SAVE[COLUMN] = CFI. CFI may be null, indicating
kono
parents:
diff changeset
515 that the register column is no longer saved. */
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 static void
kono
parents:
diff changeset
518 update_row_reg_save (dw_cfi_row *row, unsigned column, dw_cfi_ref cfi)
kono
parents:
diff changeset
519 {
kono
parents:
diff changeset
520 if (vec_safe_length (row->reg_save) <= column)
kono
parents:
diff changeset
521 vec_safe_grow_cleared (row->reg_save, column + 1);
kono
parents:
diff changeset
522 (*row->reg_save)[column] = cfi;
kono
parents:
diff changeset
523 }
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 /* This function fills in aa dw_cfa_location structure from a dwarf location
kono
parents:
diff changeset
526 descriptor sequence. */
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 static void
kono
parents:
diff changeset
529 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_node *loc)
kono
parents:
diff changeset
530 {
kono
parents:
diff changeset
531 struct dw_loc_descr_node *ptr;
kono
parents:
diff changeset
532 cfa->offset = 0;
kono
parents:
diff changeset
533 cfa->base_offset = 0;
kono
parents:
diff changeset
534 cfa->indirect = 0;
kono
parents:
diff changeset
535 cfa->reg = -1;
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
kono
parents:
diff changeset
538 {
kono
parents:
diff changeset
539 enum dwarf_location_atom op = ptr->dw_loc_opc;
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 switch (op)
kono
parents:
diff changeset
542 {
kono
parents:
diff changeset
543 case DW_OP_reg0:
kono
parents:
diff changeset
544 case DW_OP_reg1:
kono
parents:
diff changeset
545 case DW_OP_reg2:
kono
parents:
diff changeset
546 case DW_OP_reg3:
kono
parents:
diff changeset
547 case DW_OP_reg4:
kono
parents:
diff changeset
548 case DW_OP_reg5:
kono
parents:
diff changeset
549 case DW_OP_reg6:
kono
parents:
diff changeset
550 case DW_OP_reg7:
kono
parents:
diff changeset
551 case DW_OP_reg8:
kono
parents:
diff changeset
552 case DW_OP_reg9:
kono
parents:
diff changeset
553 case DW_OP_reg10:
kono
parents:
diff changeset
554 case DW_OP_reg11:
kono
parents:
diff changeset
555 case DW_OP_reg12:
kono
parents:
diff changeset
556 case DW_OP_reg13:
kono
parents:
diff changeset
557 case DW_OP_reg14:
kono
parents:
diff changeset
558 case DW_OP_reg15:
kono
parents:
diff changeset
559 case DW_OP_reg16:
kono
parents:
diff changeset
560 case DW_OP_reg17:
kono
parents:
diff changeset
561 case DW_OP_reg18:
kono
parents:
diff changeset
562 case DW_OP_reg19:
kono
parents:
diff changeset
563 case DW_OP_reg20:
kono
parents:
diff changeset
564 case DW_OP_reg21:
kono
parents:
diff changeset
565 case DW_OP_reg22:
kono
parents:
diff changeset
566 case DW_OP_reg23:
kono
parents:
diff changeset
567 case DW_OP_reg24:
kono
parents:
diff changeset
568 case DW_OP_reg25:
kono
parents:
diff changeset
569 case DW_OP_reg26:
kono
parents:
diff changeset
570 case DW_OP_reg27:
kono
parents:
diff changeset
571 case DW_OP_reg28:
kono
parents:
diff changeset
572 case DW_OP_reg29:
kono
parents:
diff changeset
573 case DW_OP_reg30:
kono
parents:
diff changeset
574 case DW_OP_reg31:
kono
parents:
diff changeset
575 cfa->reg = op - DW_OP_reg0;
kono
parents:
diff changeset
576 break;
kono
parents:
diff changeset
577 case DW_OP_regx:
kono
parents:
diff changeset
578 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
kono
parents:
diff changeset
579 break;
kono
parents:
diff changeset
580 case DW_OP_breg0:
kono
parents:
diff changeset
581 case DW_OP_breg1:
kono
parents:
diff changeset
582 case DW_OP_breg2:
kono
parents:
diff changeset
583 case DW_OP_breg3:
kono
parents:
diff changeset
584 case DW_OP_breg4:
kono
parents:
diff changeset
585 case DW_OP_breg5:
kono
parents:
diff changeset
586 case DW_OP_breg6:
kono
parents:
diff changeset
587 case DW_OP_breg7:
kono
parents:
diff changeset
588 case DW_OP_breg8:
kono
parents:
diff changeset
589 case DW_OP_breg9:
kono
parents:
diff changeset
590 case DW_OP_breg10:
kono
parents:
diff changeset
591 case DW_OP_breg11:
kono
parents:
diff changeset
592 case DW_OP_breg12:
kono
parents:
diff changeset
593 case DW_OP_breg13:
kono
parents:
diff changeset
594 case DW_OP_breg14:
kono
parents:
diff changeset
595 case DW_OP_breg15:
kono
parents:
diff changeset
596 case DW_OP_breg16:
kono
parents:
diff changeset
597 case DW_OP_breg17:
kono
parents:
diff changeset
598 case DW_OP_breg18:
kono
parents:
diff changeset
599 case DW_OP_breg19:
kono
parents:
diff changeset
600 case DW_OP_breg20:
kono
parents:
diff changeset
601 case DW_OP_breg21:
kono
parents:
diff changeset
602 case DW_OP_breg22:
kono
parents:
diff changeset
603 case DW_OP_breg23:
kono
parents:
diff changeset
604 case DW_OP_breg24:
kono
parents:
diff changeset
605 case DW_OP_breg25:
kono
parents:
diff changeset
606 case DW_OP_breg26:
kono
parents:
diff changeset
607 case DW_OP_breg27:
kono
parents:
diff changeset
608 case DW_OP_breg28:
kono
parents:
diff changeset
609 case DW_OP_breg29:
kono
parents:
diff changeset
610 case DW_OP_breg30:
kono
parents:
diff changeset
611 case DW_OP_breg31:
kono
parents:
diff changeset
612 cfa->reg = op - DW_OP_breg0;
kono
parents:
diff changeset
613 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
kono
parents:
diff changeset
614 break;
kono
parents:
diff changeset
615 case DW_OP_bregx:
kono
parents:
diff changeset
616 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
kono
parents:
diff changeset
617 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
kono
parents:
diff changeset
618 break;
kono
parents:
diff changeset
619 case DW_OP_deref:
kono
parents:
diff changeset
620 cfa->indirect = 1;
kono
parents:
diff changeset
621 break;
kono
parents:
diff changeset
622 case DW_OP_plus_uconst:
kono
parents:
diff changeset
623 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
kono
parents:
diff changeset
624 break;
kono
parents:
diff changeset
625 default:
kono
parents:
diff changeset
626 gcc_unreachable ();
kono
parents:
diff changeset
627 }
kono
parents:
diff changeset
628 }
kono
parents:
diff changeset
629 }
kono
parents:
diff changeset
630
kono
parents:
diff changeset
631 /* Find the previous value for the CFA, iteratively. CFI is the opcode
kono
parents:
diff changeset
632 to interpret, *LOC will be updated as necessary, *REMEMBER is used for
kono
parents:
diff changeset
633 one level of remember/restore state processing. */
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 void
kono
parents:
diff changeset
636 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
kono
parents:
diff changeset
637 {
kono
parents:
diff changeset
638 switch (cfi->dw_cfi_opc)
kono
parents:
diff changeset
639 {
kono
parents:
diff changeset
640 case DW_CFA_def_cfa_offset:
kono
parents:
diff changeset
641 case DW_CFA_def_cfa_offset_sf:
kono
parents:
diff changeset
642 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
kono
parents:
diff changeset
643 break;
kono
parents:
diff changeset
644 case DW_CFA_def_cfa_register:
kono
parents:
diff changeset
645 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
kono
parents:
diff changeset
646 break;
kono
parents:
diff changeset
647 case DW_CFA_def_cfa:
kono
parents:
diff changeset
648 case DW_CFA_def_cfa_sf:
kono
parents:
diff changeset
649 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
kono
parents:
diff changeset
650 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
kono
parents:
diff changeset
651 break;
kono
parents:
diff changeset
652 case DW_CFA_def_cfa_expression:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
653 if (cfi->dw_cfi_oprnd2.dw_cfi_cfa_loc)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
654 *loc = *cfi->dw_cfi_oprnd2.dw_cfi_cfa_loc;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
655 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
656 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
111
kono
parents:
diff changeset
657 break;
kono
parents:
diff changeset
658
kono
parents:
diff changeset
659 case DW_CFA_remember_state:
kono
parents:
diff changeset
660 gcc_assert (!remember->in_use);
kono
parents:
diff changeset
661 *remember = *loc;
kono
parents:
diff changeset
662 remember->in_use = 1;
kono
parents:
diff changeset
663 break;
kono
parents:
diff changeset
664 case DW_CFA_restore_state:
kono
parents:
diff changeset
665 gcc_assert (remember->in_use);
kono
parents:
diff changeset
666 *loc = *remember;
kono
parents:
diff changeset
667 remember->in_use = 0;
kono
parents:
diff changeset
668 break;
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 default:
kono
parents:
diff changeset
671 break;
kono
parents:
diff changeset
672 }
kono
parents:
diff changeset
673 }
kono
parents:
diff changeset
674
kono
parents:
diff changeset
675 /* Determine if two dw_cfa_location structures define the same data. */
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 bool
kono
parents:
diff changeset
678 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
kono
parents:
diff changeset
679 {
kono
parents:
diff changeset
680 return (loc1->reg == loc2->reg
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
681 && known_eq (loc1->offset, loc2->offset)
111
kono
parents:
diff changeset
682 && loc1->indirect == loc2->indirect
kono
parents:
diff changeset
683 && (loc1->indirect == 0
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
684 || known_eq (loc1->base_offset, loc2->base_offset)));
111
kono
parents:
diff changeset
685 }
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 /* Determine if two CFI operands are identical. */
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 static bool
kono
parents:
diff changeset
690 cfi_oprnd_equal_p (enum dw_cfi_oprnd_type t, dw_cfi_oprnd *a, dw_cfi_oprnd *b)
kono
parents:
diff changeset
691 {
kono
parents:
diff changeset
692 switch (t)
kono
parents:
diff changeset
693 {
kono
parents:
diff changeset
694 case dw_cfi_oprnd_unused:
kono
parents:
diff changeset
695 return true;
kono
parents:
diff changeset
696 case dw_cfi_oprnd_reg_num:
kono
parents:
diff changeset
697 return a->dw_cfi_reg_num == b->dw_cfi_reg_num;
kono
parents:
diff changeset
698 case dw_cfi_oprnd_offset:
kono
parents:
diff changeset
699 return a->dw_cfi_offset == b->dw_cfi_offset;
kono
parents:
diff changeset
700 case dw_cfi_oprnd_addr:
kono
parents:
diff changeset
701 return (a->dw_cfi_addr == b->dw_cfi_addr
kono
parents:
diff changeset
702 || strcmp (a->dw_cfi_addr, b->dw_cfi_addr) == 0);
kono
parents:
diff changeset
703 case dw_cfi_oprnd_loc:
kono
parents:
diff changeset
704 return loc_descr_equal_p (a->dw_cfi_loc, b->dw_cfi_loc);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
705 case dw_cfi_oprnd_cfa_loc:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
706 return cfa_equal_p (a->dw_cfi_cfa_loc, b->dw_cfi_cfa_loc);
111
kono
parents:
diff changeset
707 }
kono
parents:
diff changeset
708 gcc_unreachable ();
kono
parents:
diff changeset
709 }
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 /* Determine if two CFI entries are identical. */
kono
parents:
diff changeset
712
kono
parents:
diff changeset
713 static bool
kono
parents:
diff changeset
714 cfi_equal_p (dw_cfi_ref a, dw_cfi_ref b)
kono
parents:
diff changeset
715 {
kono
parents:
diff changeset
716 enum dwarf_call_frame_info opc;
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 /* Make things easier for our callers, including missing operands. */
kono
parents:
diff changeset
719 if (a == b)
kono
parents:
diff changeset
720 return true;
kono
parents:
diff changeset
721 if (a == NULL || b == NULL)
kono
parents:
diff changeset
722 return false;
kono
parents:
diff changeset
723
kono
parents:
diff changeset
724 /* Obviously, the opcodes must match. */
kono
parents:
diff changeset
725 opc = a->dw_cfi_opc;
kono
parents:
diff changeset
726 if (opc != b->dw_cfi_opc)
kono
parents:
diff changeset
727 return false;
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 /* Compare the two operands, re-using the type of the operands as
kono
parents:
diff changeset
730 already exposed elsewhere. */
kono
parents:
diff changeset
731 return (cfi_oprnd_equal_p (dw_cfi_oprnd1_desc (opc),
kono
parents:
diff changeset
732 &a->dw_cfi_oprnd1, &b->dw_cfi_oprnd1)
kono
parents:
diff changeset
733 && cfi_oprnd_equal_p (dw_cfi_oprnd2_desc (opc),
kono
parents:
diff changeset
734 &a->dw_cfi_oprnd2, &b->dw_cfi_oprnd2));
kono
parents:
diff changeset
735 }
kono
parents:
diff changeset
736
kono
parents:
diff changeset
737 /* Determine if two CFI_ROW structures are identical. */
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739 static bool
kono
parents:
diff changeset
740 cfi_row_equal_p (dw_cfi_row *a, dw_cfi_row *b)
kono
parents:
diff changeset
741 {
kono
parents:
diff changeset
742 size_t i, n_a, n_b, n_max;
kono
parents:
diff changeset
743
kono
parents:
diff changeset
744 if (a->cfa_cfi)
kono
parents:
diff changeset
745 {
kono
parents:
diff changeset
746 if (!cfi_equal_p (a->cfa_cfi, b->cfa_cfi))
kono
parents:
diff changeset
747 return false;
kono
parents:
diff changeset
748 }
kono
parents:
diff changeset
749 else if (!cfa_equal_p (&a->cfa, &b->cfa))
kono
parents:
diff changeset
750 return false;
kono
parents:
diff changeset
751
kono
parents:
diff changeset
752 n_a = vec_safe_length (a->reg_save);
kono
parents:
diff changeset
753 n_b = vec_safe_length (b->reg_save);
kono
parents:
diff changeset
754 n_max = MAX (n_a, n_b);
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 for (i = 0; i < n_max; ++i)
kono
parents:
diff changeset
757 {
kono
parents:
diff changeset
758 dw_cfi_ref r_a = NULL, r_b = NULL;
kono
parents:
diff changeset
759
kono
parents:
diff changeset
760 if (i < n_a)
kono
parents:
diff changeset
761 r_a = (*a->reg_save)[i];
kono
parents:
diff changeset
762 if (i < n_b)
kono
parents:
diff changeset
763 r_b = (*b->reg_save)[i];
kono
parents:
diff changeset
764
kono
parents:
diff changeset
765 if (!cfi_equal_p (r_a, r_b))
kono
parents:
diff changeset
766 return false;
kono
parents:
diff changeset
767 }
kono
parents:
diff changeset
768
kono
parents:
diff changeset
769 return true;
kono
parents:
diff changeset
770 }
kono
parents:
diff changeset
771
kono
parents:
diff changeset
772 /* The CFA is now calculated from NEW_CFA. Consider OLD_CFA in determining
kono
parents:
diff changeset
773 what opcode to emit. Returns the CFI opcode to effect the change, or
kono
parents:
diff changeset
774 NULL if NEW_CFA == OLD_CFA. */
kono
parents:
diff changeset
775
kono
parents:
diff changeset
776 static dw_cfi_ref
kono
parents:
diff changeset
777 def_cfa_0 (dw_cfa_location *old_cfa, dw_cfa_location *new_cfa)
kono
parents:
diff changeset
778 {
kono
parents:
diff changeset
779 dw_cfi_ref cfi;
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 /* If nothing changed, no need to issue any call frame instructions. */
kono
parents:
diff changeset
782 if (cfa_equal_p (old_cfa, new_cfa))
kono
parents:
diff changeset
783 return NULL;
kono
parents:
diff changeset
784
kono
parents:
diff changeset
785 cfi = new_cfi ();
kono
parents:
diff changeset
786
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
787 HOST_WIDE_INT const_offset;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
788 if (new_cfa->reg == old_cfa->reg
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
789 && !new_cfa->indirect
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
790 && !old_cfa->indirect
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
791 && new_cfa->offset.is_constant (&const_offset))
111
kono
parents:
diff changeset
792 {
kono
parents:
diff changeset
793 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
kono
parents:
diff changeset
794 the CFA register did not change but the offset did. The data
kono
parents:
diff changeset
795 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
kono
parents:
diff changeset
796 in the assembler via the .cfi_def_cfa_offset directive. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
797 if (const_offset < 0)
111
kono
parents:
diff changeset
798 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
kono
parents:
diff changeset
799 else
kono
parents:
diff changeset
800 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
801 cfi->dw_cfi_oprnd1.dw_cfi_offset = const_offset;
111
kono
parents:
diff changeset
802 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
803 else if (new_cfa->offset.is_constant ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
804 && known_eq (new_cfa->offset, old_cfa->offset)
111
kono
parents:
diff changeset
805 && old_cfa->reg != INVALID_REGNUM
kono
parents:
diff changeset
806 && !new_cfa->indirect
kono
parents:
diff changeset
807 && !old_cfa->indirect)
kono
parents:
diff changeset
808 {
kono
parents:
diff changeset
809 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
kono
parents:
diff changeset
810 indicating the CFA register has changed to <register> but the
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
811 offset has not changed. This requires the old CFA to have
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
812 been set as a register plus offset rather than a general
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
813 DW_CFA_def_cfa_expression. */
111
kono
parents:
diff changeset
814 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
kono
parents:
diff changeset
815 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = new_cfa->reg;
kono
parents:
diff changeset
816 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
817 else if (new_cfa->indirect == 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
818 && new_cfa->offset.is_constant (&const_offset))
111
kono
parents:
diff changeset
819 {
kono
parents:
diff changeset
820 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
kono
parents:
diff changeset
821 indicating the CFA register has changed to <register> with
kono
parents:
diff changeset
822 the specified offset. The data factoring for DW_CFA_def_cfa_sf
kono
parents:
diff changeset
823 happens in output_cfi, or in the assembler via the .cfi_def_cfa
kono
parents:
diff changeset
824 directive. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
825 if (const_offset < 0)
111
kono
parents:
diff changeset
826 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
kono
parents:
diff changeset
827 else
kono
parents:
diff changeset
828 cfi->dw_cfi_opc = DW_CFA_def_cfa;
kono
parents:
diff changeset
829 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = new_cfa->reg;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
830 cfi->dw_cfi_oprnd2.dw_cfi_offset = const_offset;
111
kono
parents:
diff changeset
831 }
kono
parents:
diff changeset
832 else
kono
parents:
diff changeset
833 {
kono
parents:
diff changeset
834 /* Construct a DW_CFA_def_cfa_expression instruction to
kono
parents:
diff changeset
835 calculate the CFA using a full location expression since no
kono
parents:
diff changeset
836 register-offset pair is available. */
kono
parents:
diff changeset
837 struct dw_loc_descr_node *loc_list;
kono
parents:
diff changeset
838
kono
parents:
diff changeset
839 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
kono
parents:
diff changeset
840 loc_list = build_cfa_loc (new_cfa, 0);
kono
parents:
diff changeset
841 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
842 if (!new_cfa->offset.is_constant ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
843 || !new_cfa->base_offset.is_constant ())
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
844 /* It's hard to reconstruct the CFA location for a polynomial
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
845 expression, so just cache it instead. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
846 cfi->dw_cfi_oprnd2.dw_cfi_cfa_loc = copy_cfa (new_cfa);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
847 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
848 cfi->dw_cfi_oprnd2.dw_cfi_cfa_loc = NULL;
111
kono
parents:
diff changeset
849 }
kono
parents:
diff changeset
850
kono
parents:
diff changeset
851 return cfi;
kono
parents:
diff changeset
852 }
kono
parents:
diff changeset
853
kono
parents:
diff changeset
854 /* Similarly, but take OLD_CFA from CUR_ROW, and update it after the fact. */
kono
parents:
diff changeset
855
kono
parents:
diff changeset
856 static void
kono
parents:
diff changeset
857 def_cfa_1 (dw_cfa_location *new_cfa)
kono
parents:
diff changeset
858 {
kono
parents:
diff changeset
859 dw_cfi_ref cfi;
kono
parents:
diff changeset
860
kono
parents:
diff changeset
861 if (cur_trace->cfa_store.reg == new_cfa->reg && new_cfa->indirect == 0)
kono
parents:
diff changeset
862 cur_trace->cfa_store.offset = new_cfa->offset;
kono
parents:
diff changeset
863
kono
parents:
diff changeset
864 cfi = def_cfa_0 (&cur_row->cfa, new_cfa);
kono
parents:
diff changeset
865 if (cfi)
kono
parents:
diff changeset
866 {
kono
parents:
diff changeset
867 cur_row->cfa = *new_cfa;
kono
parents:
diff changeset
868 cur_row->cfa_cfi = (cfi->dw_cfi_opc == DW_CFA_def_cfa_expression
kono
parents:
diff changeset
869 ? cfi : NULL);
kono
parents:
diff changeset
870
kono
parents:
diff changeset
871 add_cfi (cfi);
kono
parents:
diff changeset
872 }
kono
parents:
diff changeset
873 }
kono
parents:
diff changeset
874
kono
parents:
diff changeset
875 /* Add the CFI for saving a register. REG is the CFA column number.
kono
parents:
diff changeset
876 If SREG is -1, the register is saved at OFFSET from the CFA;
kono
parents:
diff changeset
877 otherwise it is saved in SREG. */
kono
parents:
diff changeset
878
kono
parents:
diff changeset
879 static void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
880 reg_save (unsigned int reg, unsigned int sreg, poly_int64 offset)
111
kono
parents:
diff changeset
881 {
kono
parents:
diff changeset
882 dw_fde_ref fde = cfun ? cfun->fde : NULL;
kono
parents:
diff changeset
883 dw_cfi_ref cfi = new_cfi ();
kono
parents:
diff changeset
884
kono
parents:
diff changeset
885 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
kono
parents:
diff changeset
886
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
887 if (sreg == INVALID_REGNUM)
111
kono
parents:
diff changeset
888 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
889 HOST_WIDE_INT const_offset;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
890 /* When stack is aligned, store REG using DW_CFA_expression with FP. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
891 if (fde && fde->stack_realign)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
892 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
893 cfi->dw_cfi_opc = DW_CFA_expression;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
894 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
895 cfi->dw_cfi_oprnd2.dw_cfi_loc
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
896 = build_cfa_aligned_loc (&cur_row->cfa, offset,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
897 fde->stack_realignment);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
898 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
899 else if (offset.is_constant (&const_offset))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
900 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
901 if (need_data_align_sf_opcode (const_offset))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
902 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
903 else if (reg & ~0x3f)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
904 cfi->dw_cfi_opc = DW_CFA_offset_extended;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
905 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
906 cfi->dw_cfi_opc = DW_CFA_offset;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
907 cfi->dw_cfi_oprnd2.dw_cfi_offset = const_offset;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
908 }
111
kono
parents:
diff changeset
909 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
910 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
911 cfi->dw_cfi_opc = DW_CFA_expression;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
912 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
913 cfi->dw_cfi_oprnd2.dw_cfi_loc
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
914 = build_cfa_loc (&cur_row->cfa, offset);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
915 }
111
kono
parents:
diff changeset
916 }
kono
parents:
diff changeset
917 else if (sreg == reg)
kono
parents:
diff changeset
918 {
kono
parents:
diff changeset
919 /* While we could emit something like DW_CFA_same_value or
kono
parents:
diff changeset
920 DW_CFA_restore, we never expect to see something like that
kono
parents:
diff changeset
921 in a prologue. This is more likely to be a bug. A backend
kono
parents:
diff changeset
922 can always bypass this by using REG_CFA_RESTORE directly. */
kono
parents:
diff changeset
923 gcc_unreachable ();
kono
parents:
diff changeset
924 }
kono
parents:
diff changeset
925 else
kono
parents:
diff changeset
926 {
kono
parents:
diff changeset
927 cfi->dw_cfi_opc = DW_CFA_register;
kono
parents:
diff changeset
928 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
kono
parents:
diff changeset
929 }
kono
parents:
diff changeset
930
kono
parents:
diff changeset
931 add_cfi (cfi);
kono
parents:
diff changeset
932 update_row_reg_save (cur_row, reg, cfi);
kono
parents:
diff changeset
933 }
kono
parents:
diff changeset
934
kono
parents:
diff changeset
935 /* A subroutine of scan_trace. Check INSN for a REG_ARGS_SIZE note
kono
parents:
diff changeset
936 and adjust data structures to match. */
kono
parents:
diff changeset
937
kono
parents:
diff changeset
938 static void
kono
parents:
diff changeset
939 notice_args_size (rtx_insn *insn)
kono
parents:
diff changeset
940 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
941 poly_int64 args_size, delta;
111
kono
parents:
diff changeset
942 rtx note;
kono
parents:
diff changeset
943
kono
parents:
diff changeset
944 note = find_reg_note (insn, REG_ARGS_SIZE, NULL);
kono
parents:
diff changeset
945 if (note == NULL)
kono
parents:
diff changeset
946 return;
kono
parents:
diff changeset
947
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
948 if (!cur_trace->eh_head)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
949 cur_trace->args_size_defined_for_eh = true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
950
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
951 args_size = get_args_size (note);
111
kono
parents:
diff changeset
952 delta = args_size - cur_trace->end_true_args_size;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
953 if (known_eq (delta, 0))
111
kono
parents:
diff changeset
954 return;
kono
parents:
diff changeset
955
kono
parents:
diff changeset
956 cur_trace->end_true_args_size = args_size;
kono
parents:
diff changeset
957
kono
parents:
diff changeset
958 /* If the CFA is computed off the stack pointer, then we must adjust
kono
parents:
diff changeset
959 the computation of the CFA as well. */
kono
parents:
diff changeset
960 if (cur_cfa->reg == dw_stack_pointer_regnum)
kono
parents:
diff changeset
961 {
kono
parents:
diff changeset
962 gcc_assert (!cur_cfa->indirect);
kono
parents:
diff changeset
963
kono
parents:
diff changeset
964 /* Convert a change in args_size (always a positive in the
kono
parents:
diff changeset
965 direction of stack growth) to a change in stack pointer. */
kono
parents:
diff changeset
966 if (!STACK_GROWS_DOWNWARD)
kono
parents:
diff changeset
967 delta = -delta;
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 cur_cfa->offset += delta;
kono
parents:
diff changeset
970 }
kono
parents:
diff changeset
971 }
kono
parents:
diff changeset
972
kono
parents:
diff changeset
973 /* A subroutine of scan_trace. INSN is can_throw_internal. Update the
kono
parents:
diff changeset
974 data within the trace related to EH insns and args_size. */
kono
parents:
diff changeset
975
kono
parents:
diff changeset
976 static void
kono
parents:
diff changeset
977 notice_eh_throw (rtx_insn *insn)
kono
parents:
diff changeset
978 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
979 poly_int64 args_size = cur_trace->end_true_args_size;
111
kono
parents:
diff changeset
980 if (cur_trace->eh_head == NULL)
kono
parents:
diff changeset
981 {
kono
parents:
diff changeset
982 cur_trace->eh_head = insn;
kono
parents:
diff changeset
983 cur_trace->beg_delay_args_size = args_size;
kono
parents:
diff changeset
984 cur_trace->end_delay_args_size = args_size;
kono
parents:
diff changeset
985 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
986 else if (maybe_ne (cur_trace->end_delay_args_size, args_size))
111
kono
parents:
diff changeset
987 {
kono
parents:
diff changeset
988 cur_trace->end_delay_args_size = args_size;
kono
parents:
diff changeset
989
kono
parents:
diff changeset
990 /* ??? If the CFA is the stack pointer, search backward for the last
kono
parents:
diff changeset
991 CFI note and insert there. Given that the stack changed for the
kono
parents:
diff changeset
992 args_size change, there *must* be such a note in between here and
kono
parents:
diff changeset
993 the last eh insn. */
kono
parents:
diff changeset
994 add_cfi_args_size (args_size);
kono
parents:
diff changeset
995 }
kono
parents:
diff changeset
996 }
kono
parents:
diff changeset
997
kono
parents:
diff changeset
998 /* Short-hand inline for the very common D_F_R (REGNO (x)) operation. */
kono
parents:
diff changeset
999 /* ??? This ought to go into dwarf2out.h, except that dwarf2out.h is
kono
parents:
diff changeset
1000 used in places where rtl is prohibited. */
kono
parents:
diff changeset
1001
kono
parents:
diff changeset
1002 static inline unsigned
kono
parents:
diff changeset
1003 dwf_regno (const_rtx reg)
kono
parents:
diff changeset
1004 {
kono
parents:
diff changeset
1005 gcc_assert (REGNO (reg) < FIRST_PSEUDO_REGISTER);
kono
parents:
diff changeset
1006 return DWARF_FRAME_REGNUM (REGNO (reg));
kono
parents:
diff changeset
1007 }
kono
parents:
diff changeset
1008
kono
parents:
diff changeset
1009 /* Compare X and Y for equivalence. The inputs may be REGs or PC_RTX. */
kono
parents:
diff changeset
1010
kono
parents:
diff changeset
1011 static bool
kono
parents:
diff changeset
1012 compare_reg_or_pc (rtx x, rtx y)
kono
parents:
diff changeset
1013 {
kono
parents:
diff changeset
1014 if (REG_P (x) && REG_P (y))
kono
parents:
diff changeset
1015 return REGNO (x) == REGNO (y);
kono
parents:
diff changeset
1016 return x == y;
kono
parents:
diff changeset
1017 }
kono
parents:
diff changeset
1018
kono
parents:
diff changeset
1019 /* Record SRC as being saved in DEST. DEST may be null to delete an
kono
parents:
diff changeset
1020 existing entry. SRC may be a register or PC_RTX. */
kono
parents:
diff changeset
1021
kono
parents:
diff changeset
1022 static void
kono
parents:
diff changeset
1023 record_reg_saved_in_reg (rtx dest, rtx src)
kono
parents:
diff changeset
1024 {
kono
parents:
diff changeset
1025 reg_saved_in_data *elt;
kono
parents:
diff changeset
1026 size_t i;
kono
parents:
diff changeset
1027
kono
parents:
diff changeset
1028 FOR_EACH_VEC_ELT (cur_trace->regs_saved_in_regs, i, elt)
kono
parents:
diff changeset
1029 if (compare_reg_or_pc (elt->orig_reg, src))
kono
parents:
diff changeset
1030 {
kono
parents:
diff changeset
1031 if (dest == NULL)
kono
parents:
diff changeset
1032 cur_trace->regs_saved_in_regs.unordered_remove (i);
kono
parents:
diff changeset
1033 else
kono
parents:
diff changeset
1034 elt->saved_in_reg = dest;
kono
parents:
diff changeset
1035 return;
kono
parents:
diff changeset
1036 }
kono
parents:
diff changeset
1037
kono
parents:
diff changeset
1038 if (dest == NULL)
kono
parents:
diff changeset
1039 return;
kono
parents:
diff changeset
1040
kono
parents:
diff changeset
1041 reg_saved_in_data e = {src, dest};
kono
parents:
diff changeset
1042 cur_trace->regs_saved_in_regs.safe_push (e);
kono
parents:
diff changeset
1043 }
kono
parents:
diff changeset
1044
kono
parents:
diff changeset
1045 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
kono
parents:
diff changeset
1046 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
kono
parents:
diff changeset
1047
kono
parents:
diff changeset
1048 static void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1049 queue_reg_save (rtx reg, rtx sreg, poly_int64 offset)
111
kono
parents:
diff changeset
1050 {
kono
parents:
diff changeset
1051 queued_reg_save *q;
kono
parents:
diff changeset
1052 queued_reg_save e = {reg, sreg, offset};
kono
parents:
diff changeset
1053 size_t i;
kono
parents:
diff changeset
1054
kono
parents:
diff changeset
1055 /* Duplicates waste space, but it's also necessary to remove them
kono
parents:
diff changeset
1056 for correctness, since the queue gets output in reverse order. */
kono
parents:
diff changeset
1057 FOR_EACH_VEC_ELT (queued_reg_saves, i, q)
kono
parents:
diff changeset
1058 if (compare_reg_or_pc (q->reg, reg))
kono
parents:
diff changeset
1059 {
kono
parents:
diff changeset
1060 *q = e;
kono
parents:
diff changeset
1061 return;
kono
parents:
diff changeset
1062 }
kono
parents:
diff changeset
1063
kono
parents:
diff changeset
1064 queued_reg_saves.safe_push (e);
kono
parents:
diff changeset
1065 }
kono
parents:
diff changeset
1066
kono
parents:
diff changeset
1067 /* Output all the entries in QUEUED_REG_SAVES. */
kono
parents:
diff changeset
1068
kono
parents:
diff changeset
1069 static void
kono
parents:
diff changeset
1070 dwarf2out_flush_queued_reg_saves (void)
kono
parents:
diff changeset
1071 {
kono
parents:
diff changeset
1072 queued_reg_save *q;
kono
parents:
diff changeset
1073 size_t i;
kono
parents:
diff changeset
1074
kono
parents:
diff changeset
1075 FOR_EACH_VEC_ELT (queued_reg_saves, i, q)
kono
parents:
diff changeset
1076 {
kono
parents:
diff changeset
1077 unsigned int reg, sreg;
kono
parents:
diff changeset
1078
kono
parents:
diff changeset
1079 record_reg_saved_in_reg (q->saved_reg, q->reg);
kono
parents:
diff changeset
1080
kono
parents:
diff changeset
1081 if (q->reg == pc_rtx)
kono
parents:
diff changeset
1082 reg = DWARF_FRAME_RETURN_COLUMN;
kono
parents:
diff changeset
1083 else
kono
parents:
diff changeset
1084 reg = dwf_regno (q->reg);
kono
parents:
diff changeset
1085 if (q->saved_reg)
kono
parents:
diff changeset
1086 sreg = dwf_regno (q->saved_reg);
kono
parents:
diff changeset
1087 else
kono
parents:
diff changeset
1088 sreg = INVALID_REGNUM;
kono
parents:
diff changeset
1089 reg_save (reg, sreg, q->cfa_offset);
kono
parents:
diff changeset
1090 }
kono
parents:
diff changeset
1091
kono
parents:
diff changeset
1092 queued_reg_saves.truncate (0);
kono
parents:
diff changeset
1093 }
kono
parents:
diff changeset
1094
kono
parents:
diff changeset
1095 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
kono
parents:
diff changeset
1096 location for? Or, does it clobber a register which we've previously
kono
parents:
diff changeset
1097 said that some other register is saved in, and for which we now
kono
parents:
diff changeset
1098 have a new location for? */
kono
parents:
diff changeset
1099
kono
parents:
diff changeset
1100 static bool
kono
parents:
diff changeset
1101 clobbers_queued_reg_save (const_rtx insn)
kono
parents:
diff changeset
1102 {
kono
parents:
diff changeset
1103 queued_reg_save *q;
kono
parents:
diff changeset
1104 size_t iq;
kono
parents:
diff changeset
1105
kono
parents:
diff changeset
1106 FOR_EACH_VEC_ELT (queued_reg_saves, iq, q)
kono
parents:
diff changeset
1107 {
kono
parents:
diff changeset
1108 size_t ir;
kono
parents:
diff changeset
1109 reg_saved_in_data *rir;
kono
parents:
diff changeset
1110
kono
parents:
diff changeset
1111 if (modified_in_p (q->reg, insn))
kono
parents:
diff changeset
1112 return true;
kono
parents:
diff changeset
1113
kono
parents:
diff changeset
1114 FOR_EACH_VEC_ELT (cur_trace->regs_saved_in_regs, ir, rir)
kono
parents:
diff changeset
1115 if (compare_reg_or_pc (q->reg, rir->orig_reg)
kono
parents:
diff changeset
1116 && modified_in_p (rir->saved_in_reg, insn))
kono
parents:
diff changeset
1117 return true;
kono
parents:
diff changeset
1118 }
kono
parents:
diff changeset
1119
kono
parents:
diff changeset
1120 return false;
kono
parents:
diff changeset
1121 }
kono
parents:
diff changeset
1122
kono
parents:
diff changeset
1123 /* What register, if any, is currently saved in REG? */
kono
parents:
diff changeset
1124
kono
parents:
diff changeset
1125 static rtx
kono
parents:
diff changeset
1126 reg_saved_in (rtx reg)
kono
parents:
diff changeset
1127 {
kono
parents:
diff changeset
1128 unsigned int regn = REGNO (reg);
kono
parents:
diff changeset
1129 queued_reg_save *q;
kono
parents:
diff changeset
1130 reg_saved_in_data *rir;
kono
parents:
diff changeset
1131 size_t i;
kono
parents:
diff changeset
1132
kono
parents:
diff changeset
1133 FOR_EACH_VEC_ELT (queued_reg_saves, i, q)
kono
parents:
diff changeset
1134 if (q->saved_reg && regn == REGNO (q->saved_reg))
kono
parents:
diff changeset
1135 return q->reg;
kono
parents:
diff changeset
1136
kono
parents:
diff changeset
1137 FOR_EACH_VEC_ELT (cur_trace->regs_saved_in_regs, i, rir)
kono
parents:
diff changeset
1138 if (regn == REGNO (rir->saved_in_reg))
kono
parents:
diff changeset
1139 return rir->orig_reg;
kono
parents:
diff changeset
1140
kono
parents:
diff changeset
1141 return NULL_RTX;
kono
parents:
diff changeset
1142 }
kono
parents:
diff changeset
1143
kono
parents:
diff changeset
1144 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
kono
parents:
diff changeset
1145
kono
parents:
diff changeset
1146 static void
kono
parents:
diff changeset
1147 dwarf2out_frame_debug_def_cfa (rtx pat)
kono
parents:
diff changeset
1148 {
kono
parents:
diff changeset
1149 memset (cur_cfa, 0, sizeof (*cur_cfa));
kono
parents:
diff changeset
1150
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1151 pat = strip_offset (pat, &cur_cfa->offset);
111
kono
parents:
diff changeset
1152 if (MEM_P (pat))
kono
parents:
diff changeset
1153 {
kono
parents:
diff changeset
1154 cur_cfa->indirect = 1;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1155 pat = strip_offset (XEXP (pat, 0), &cur_cfa->base_offset);
111
kono
parents:
diff changeset
1156 }
kono
parents:
diff changeset
1157 /* ??? If this fails, we could be calling into the _loc functions to
kono
parents:
diff changeset
1158 define a full expression. So far no port does that. */
kono
parents:
diff changeset
1159 gcc_assert (REG_P (pat));
kono
parents:
diff changeset
1160 cur_cfa->reg = dwf_regno (pat);
kono
parents:
diff changeset
1161 }
kono
parents:
diff changeset
1162
kono
parents:
diff changeset
1163 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
kono
parents:
diff changeset
1164
kono
parents:
diff changeset
1165 static void
kono
parents:
diff changeset
1166 dwarf2out_frame_debug_adjust_cfa (rtx pat)
kono
parents:
diff changeset
1167 {
kono
parents:
diff changeset
1168 rtx src, dest;
kono
parents:
diff changeset
1169
kono
parents:
diff changeset
1170 gcc_assert (GET_CODE (pat) == SET);
kono
parents:
diff changeset
1171 dest = XEXP (pat, 0);
kono
parents:
diff changeset
1172 src = XEXP (pat, 1);
kono
parents:
diff changeset
1173
kono
parents:
diff changeset
1174 switch (GET_CODE (src))
kono
parents:
diff changeset
1175 {
kono
parents:
diff changeset
1176 case PLUS:
kono
parents:
diff changeset
1177 gcc_assert (dwf_regno (XEXP (src, 0)) == cur_cfa->reg);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1178 cur_cfa->offset -= rtx_to_poly_int64 (XEXP (src, 1));
111
kono
parents:
diff changeset
1179 break;
kono
parents:
diff changeset
1180
kono
parents:
diff changeset
1181 case REG:
kono
parents:
diff changeset
1182 break;
kono
parents:
diff changeset
1183
kono
parents:
diff changeset
1184 default:
kono
parents:
diff changeset
1185 gcc_unreachable ();
kono
parents:
diff changeset
1186 }
kono
parents:
diff changeset
1187
kono
parents:
diff changeset
1188 cur_cfa->reg = dwf_regno (dest);
kono
parents:
diff changeset
1189 gcc_assert (cur_cfa->indirect == 0);
kono
parents:
diff changeset
1190 }
kono
parents:
diff changeset
1191
kono
parents:
diff changeset
1192 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
kono
parents:
diff changeset
1193
kono
parents:
diff changeset
1194 static void
kono
parents:
diff changeset
1195 dwarf2out_frame_debug_cfa_offset (rtx set)
kono
parents:
diff changeset
1196 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1197 poly_int64 offset;
111
kono
parents:
diff changeset
1198 rtx src, addr, span;
kono
parents:
diff changeset
1199 unsigned int sregno;
kono
parents:
diff changeset
1200
kono
parents:
diff changeset
1201 src = XEXP (set, 1);
kono
parents:
diff changeset
1202 addr = XEXP (set, 0);
kono
parents:
diff changeset
1203 gcc_assert (MEM_P (addr));
kono
parents:
diff changeset
1204 addr = XEXP (addr, 0);
kono
parents:
diff changeset
1205
kono
parents:
diff changeset
1206 /* As documented, only consider extremely simple addresses. */
kono
parents:
diff changeset
1207 switch (GET_CODE (addr))
kono
parents:
diff changeset
1208 {
kono
parents:
diff changeset
1209 case REG:
kono
parents:
diff changeset
1210 gcc_assert (dwf_regno (addr) == cur_cfa->reg);
kono
parents:
diff changeset
1211 offset = -cur_cfa->offset;
kono
parents:
diff changeset
1212 break;
kono
parents:
diff changeset
1213 case PLUS:
kono
parents:
diff changeset
1214 gcc_assert (dwf_regno (XEXP (addr, 0)) == cur_cfa->reg);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1215 offset = rtx_to_poly_int64 (XEXP (addr, 1)) - cur_cfa->offset;
111
kono
parents:
diff changeset
1216 break;
kono
parents:
diff changeset
1217 default:
kono
parents:
diff changeset
1218 gcc_unreachable ();
kono
parents:
diff changeset
1219 }
kono
parents:
diff changeset
1220
kono
parents:
diff changeset
1221 if (src == pc_rtx)
kono
parents:
diff changeset
1222 {
kono
parents:
diff changeset
1223 span = NULL;
kono
parents:
diff changeset
1224 sregno = DWARF_FRAME_RETURN_COLUMN;
kono
parents:
diff changeset
1225 }
kono
parents:
diff changeset
1226 else
kono
parents:
diff changeset
1227 {
kono
parents:
diff changeset
1228 span = targetm.dwarf_register_span (src);
kono
parents:
diff changeset
1229 sregno = dwf_regno (src);
kono
parents:
diff changeset
1230 }
kono
parents:
diff changeset
1231
kono
parents:
diff changeset
1232 /* ??? We'd like to use queue_reg_save, but we need to come up with
kono
parents:
diff changeset
1233 a different flushing heuristic for epilogues. */
kono
parents:
diff changeset
1234 if (!span)
kono
parents:
diff changeset
1235 reg_save (sregno, INVALID_REGNUM, offset);
kono
parents:
diff changeset
1236 else
kono
parents:
diff changeset
1237 {
kono
parents:
diff changeset
1238 /* We have a PARALLEL describing where the contents of SRC live.
kono
parents:
diff changeset
1239 Adjust the offset for each piece of the PARALLEL. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1240 poly_int64 span_offset = offset;
111
kono
parents:
diff changeset
1241
kono
parents:
diff changeset
1242 gcc_assert (GET_CODE (span) == PARALLEL);
kono
parents:
diff changeset
1243
kono
parents:
diff changeset
1244 const int par_len = XVECLEN (span, 0);
kono
parents:
diff changeset
1245 for (int par_index = 0; par_index < par_len; par_index++)
kono
parents:
diff changeset
1246 {
kono
parents:
diff changeset
1247 rtx elem = XVECEXP (span, 0, par_index);
kono
parents:
diff changeset
1248 sregno = dwf_regno (src);
kono
parents:
diff changeset
1249 reg_save (sregno, INVALID_REGNUM, span_offset);
kono
parents:
diff changeset
1250 span_offset += GET_MODE_SIZE (GET_MODE (elem));
kono
parents:
diff changeset
1251 }
kono
parents:
diff changeset
1252 }
kono
parents:
diff changeset
1253 }
kono
parents:
diff changeset
1254
kono
parents:
diff changeset
1255 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
kono
parents:
diff changeset
1256
kono
parents:
diff changeset
1257 static void
kono
parents:
diff changeset
1258 dwarf2out_frame_debug_cfa_register (rtx set)
kono
parents:
diff changeset
1259 {
kono
parents:
diff changeset
1260 rtx src, dest;
kono
parents:
diff changeset
1261 unsigned sregno, dregno;
kono
parents:
diff changeset
1262
kono
parents:
diff changeset
1263 src = XEXP (set, 1);
kono
parents:
diff changeset
1264 dest = XEXP (set, 0);
kono
parents:
diff changeset
1265
kono
parents:
diff changeset
1266 record_reg_saved_in_reg (dest, src);
kono
parents:
diff changeset
1267 if (src == pc_rtx)
kono
parents:
diff changeset
1268 sregno = DWARF_FRAME_RETURN_COLUMN;
kono
parents:
diff changeset
1269 else
kono
parents:
diff changeset
1270 sregno = dwf_regno (src);
kono
parents:
diff changeset
1271
kono
parents:
diff changeset
1272 dregno = dwf_regno (dest);
kono
parents:
diff changeset
1273
kono
parents:
diff changeset
1274 /* ??? We'd like to use queue_reg_save, but we need to come up with
kono
parents:
diff changeset
1275 a different flushing heuristic for epilogues. */
kono
parents:
diff changeset
1276 reg_save (sregno, dregno, 0);
kono
parents:
diff changeset
1277 }
kono
parents:
diff changeset
1278
kono
parents:
diff changeset
1279 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
kono
parents:
diff changeset
1280
kono
parents:
diff changeset
1281 static void
kono
parents:
diff changeset
1282 dwarf2out_frame_debug_cfa_expression (rtx set)
kono
parents:
diff changeset
1283 {
kono
parents:
diff changeset
1284 rtx src, dest, span;
kono
parents:
diff changeset
1285 dw_cfi_ref cfi = new_cfi ();
kono
parents:
diff changeset
1286 unsigned regno;
kono
parents:
diff changeset
1287
kono
parents:
diff changeset
1288 dest = SET_DEST (set);
kono
parents:
diff changeset
1289 src = SET_SRC (set);
kono
parents:
diff changeset
1290
kono
parents:
diff changeset
1291 gcc_assert (REG_P (src));
kono
parents:
diff changeset
1292 gcc_assert (MEM_P (dest));
kono
parents:
diff changeset
1293
kono
parents:
diff changeset
1294 span = targetm.dwarf_register_span (src);
kono
parents:
diff changeset
1295 gcc_assert (!span);
kono
parents:
diff changeset
1296
kono
parents:
diff changeset
1297 regno = dwf_regno (src);
kono
parents:
diff changeset
1298
kono
parents:
diff changeset
1299 cfi->dw_cfi_opc = DW_CFA_expression;
kono
parents:
diff changeset
1300 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
kono
parents:
diff changeset
1301 cfi->dw_cfi_oprnd2.dw_cfi_loc
kono
parents:
diff changeset
1302 = mem_loc_descriptor (XEXP (dest, 0), get_address_mode (dest),
kono
parents:
diff changeset
1303 GET_MODE (dest), VAR_INIT_STATUS_INITIALIZED);
kono
parents:
diff changeset
1304
kono
parents:
diff changeset
1305 /* ??? We'd like to use queue_reg_save, were the interface different,
kono
parents:
diff changeset
1306 and, as above, we could manage flushing for epilogues. */
kono
parents:
diff changeset
1307 add_cfi (cfi);
kono
parents:
diff changeset
1308 update_row_reg_save (cur_row, regno, cfi);
kono
parents:
diff changeset
1309 }
kono
parents:
diff changeset
1310
kono
parents:
diff changeset
1311 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_VAL_EXPRESSION
kono
parents:
diff changeset
1312 note. */
kono
parents:
diff changeset
1313
kono
parents:
diff changeset
1314 static void
kono
parents:
diff changeset
1315 dwarf2out_frame_debug_cfa_val_expression (rtx set)
kono
parents:
diff changeset
1316 {
kono
parents:
diff changeset
1317 rtx dest = SET_DEST (set);
kono
parents:
diff changeset
1318 gcc_assert (REG_P (dest));
kono
parents:
diff changeset
1319
kono
parents:
diff changeset
1320 rtx span = targetm.dwarf_register_span (dest);
kono
parents:
diff changeset
1321 gcc_assert (!span);
kono
parents:
diff changeset
1322
kono
parents:
diff changeset
1323 rtx src = SET_SRC (set);
kono
parents:
diff changeset
1324 dw_cfi_ref cfi = new_cfi ();
kono
parents:
diff changeset
1325 cfi->dw_cfi_opc = DW_CFA_val_expression;
kono
parents:
diff changeset
1326 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = dwf_regno (dest);
kono
parents:
diff changeset
1327 cfi->dw_cfi_oprnd2.dw_cfi_loc
kono
parents:
diff changeset
1328 = mem_loc_descriptor (src, GET_MODE (src),
kono
parents:
diff changeset
1329 GET_MODE (dest), VAR_INIT_STATUS_INITIALIZED);
kono
parents:
diff changeset
1330 add_cfi (cfi);
kono
parents:
diff changeset
1331 update_row_reg_save (cur_row, dwf_regno (dest), cfi);
kono
parents:
diff changeset
1332 }
kono
parents:
diff changeset
1333
kono
parents:
diff changeset
1334 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
kono
parents:
diff changeset
1335
kono
parents:
diff changeset
1336 static void
kono
parents:
diff changeset
1337 dwarf2out_frame_debug_cfa_restore (rtx reg)
kono
parents:
diff changeset
1338 {
kono
parents:
diff changeset
1339 gcc_assert (REG_P (reg));
kono
parents:
diff changeset
1340
kono
parents:
diff changeset
1341 rtx span = targetm.dwarf_register_span (reg);
kono
parents:
diff changeset
1342 if (!span)
kono
parents:
diff changeset
1343 {
kono
parents:
diff changeset
1344 unsigned int regno = dwf_regno (reg);
kono
parents:
diff changeset
1345 add_cfi_restore (regno);
kono
parents:
diff changeset
1346 update_row_reg_save (cur_row, regno, NULL);
kono
parents:
diff changeset
1347 }
kono
parents:
diff changeset
1348 else
kono
parents:
diff changeset
1349 {
kono
parents:
diff changeset
1350 /* We have a PARALLEL describing where the contents of REG live.
kono
parents:
diff changeset
1351 Restore the register for each piece of the PARALLEL. */
kono
parents:
diff changeset
1352 gcc_assert (GET_CODE (span) == PARALLEL);
kono
parents:
diff changeset
1353
kono
parents:
diff changeset
1354 const int par_len = XVECLEN (span, 0);
kono
parents:
diff changeset
1355 for (int par_index = 0; par_index < par_len; par_index++)
kono
parents:
diff changeset
1356 {
kono
parents:
diff changeset
1357 reg = XVECEXP (span, 0, par_index);
kono
parents:
diff changeset
1358 gcc_assert (REG_P (reg));
kono
parents:
diff changeset
1359 unsigned int regno = dwf_regno (reg);
kono
parents:
diff changeset
1360 add_cfi_restore (regno);
kono
parents:
diff changeset
1361 update_row_reg_save (cur_row, regno, NULL);
kono
parents:
diff changeset
1362 }
kono
parents:
diff changeset
1363 }
kono
parents:
diff changeset
1364 }
kono
parents:
diff changeset
1365
kono
parents:
diff changeset
1366 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE.
kono
parents:
diff changeset
1367 ??? Perhaps we should note in the CIE where windows are saved (instead of
kono
parents:
diff changeset
1368 assuming 0(cfa)) and what registers are in the window. */
kono
parents:
diff changeset
1369
kono
parents:
diff changeset
1370 static void
kono
parents:
diff changeset
1371 dwarf2out_frame_debug_cfa_window_save (void)
kono
parents:
diff changeset
1372 {
kono
parents:
diff changeset
1373 dw_cfi_ref cfi = new_cfi ();
kono
parents:
diff changeset
1374
kono
parents:
diff changeset
1375 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
kono
parents:
diff changeset
1376 add_cfi (cfi);
kono
parents:
diff changeset
1377 }
kono
parents:
diff changeset
1378
kono
parents:
diff changeset
1379 /* Record call frame debugging information for an expression EXPR,
kono
parents:
diff changeset
1380 which either sets SP or FP (adjusting how we calculate the frame
kono
parents:
diff changeset
1381 address) or saves a register to the stack or another register.
kono
parents:
diff changeset
1382 LABEL indicates the address of EXPR.
kono
parents:
diff changeset
1383
kono
parents:
diff changeset
1384 This function encodes a state machine mapping rtxes to actions on
kono
parents:
diff changeset
1385 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
kono
parents:
diff changeset
1386 users need not read the source code.
kono
parents:
diff changeset
1387
kono
parents:
diff changeset
1388 The High-Level Picture
kono
parents:
diff changeset
1389
kono
parents:
diff changeset
1390 Changes in the register we use to calculate the CFA: Currently we
kono
parents:
diff changeset
1391 assume that if you copy the CFA register into another register, we
kono
parents:
diff changeset
1392 should take the other one as the new CFA register; this seems to
kono
parents:
diff changeset
1393 work pretty well. If it's wrong for some target, it's simple
kono
parents:
diff changeset
1394 enough not to set RTX_FRAME_RELATED_P on the insn in question.
kono
parents:
diff changeset
1395
kono
parents:
diff changeset
1396 Changes in the register we use for saving registers to the stack:
kono
parents:
diff changeset
1397 This is usually SP, but not always. Again, we deduce that if you
kono
parents:
diff changeset
1398 copy SP into another register (and SP is not the CFA register),
kono
parents:
diff changeset
1399 then the new register is the one we will be using for register
kono
parents:
diff changeset
1400 saves. This also seems to work.
kono
parents:
diff changeset
1401
kono
parents:
diff changeset
1402 Register saves: There's not much guesswork about this one; if
kono
parents:
diff changeset
1403 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
kono
parents:
diff changeset
1404 register save, and the register used to calculate the destination
kono
parents:
diff changeset
1405 had better be the one we think we're using for this purpose.
kono
parents:
diff changeset
1406 It's also assumed that a copy from a call-saved register to another
kono
parents:
diff changeset
1407 register is saving that register if RTX_FRAME_RELATED_P is set on
kono
parents:
diff changeset
1408 that instruction. If the copy is from a call-saved register to
kono
parents:
diff changeset
1409 the *same* register, that means that the register is now the same
kono
parents:
diff changeset
1410 value as in the caller.
kono
parents:
diff changeset
1411
kono
parents:
diff changeset
1412 Except: If the register being saved is the CFA register, and the
kono
parents:
diff changeset
1413 offset is nonzero, we are saving the CFA, so we assume we have to
kono
parents:
diff changeset
1414 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
kono
parents:
diff changeset
1415 the intent is to save the value of SP from the previous frame.
kono
parents:
diff changeset
1416
kono
parents:
diff changeset
1417 In addition, if a register has previously been saved to a different
kono
parents:
diff changeset
1418 register,
kono
parents:
diff changeset
1419
kono
parents:
diff changeset
1420 Invariants / Summaries of Rules
kono
parents:
diff changeset
1421
kono
parents:
diff changeset
1422 cfa current rule for calculating the CFA. It usually
kono
parents:
diff changeset
1423 consists of a register and an offset. This is
kono
parents:
diff changeset
1424 actually stored in *cur_cfa, but abbreviated
kono
parents:
diff changeset
1425 for the purposes of this documentation.
kono
parents:
diff changeset
1426 cfa_store register used by prologue code to save things to the stack
kono
parents:
diff changeset
1427 cfa_store.offset is the offset from the value of
kono
parents:
diff changeset
1428 cfa_store.reg to the actual CFA
kono
parents:
diff changeset
1429 cfa_temp register holding an integral value. cfa_temp.offset
kono
parents:
diff changeset
1430 stores the value, which will be used to adjust the
kono
parents:
diff changeset
1431 stack pointer. cfa_temp is also used like cfa_store,
kono
parents:
diff changeset
1432 to track stores to the stack via fp or a temp reg.
kono
parents:
diff changeset
1433
kono
parents:
diff changeset
1434 Rules 1- 4: Setting a register's value to cfa.reg or an expression
kono
parents:
diff changeset
1435 with cfa.reg as the first operand changes the cfa.reg and its
kono
parents:
diff changeset
1436 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
kono
parents:
diff changeset
1437 cfa_temp.offset.
kono
parents:
diff changeset
1438
kono
parents:
diff changeset
1439 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
kono
parents:
diff changeset
1440 expression yielding a constant. This sets cfa_temp.reg
kono
parents:
diff changeset
1441 and cfa_temp.offset.
kono
parents:
diff changeset
1442
kono
parents:
diff changeset
1443 Rule 5: Create a new register cfa_store used to save items to the
kono
parents:
diff changeset
1444 stack.
kono
parents:
diff changeset
1445
kono
parents:
diff changeset
1446 Rules 10-14: Save a register to the stack. Define offset as the
kono
parents:
diff changeset
1447 difference of the original location and cfa_store's
kono
parents:
diff changeset
1448 location (or cfa_temp's location if cfa_temp is used).
kono
parents:
diff changeset
1449
kono
parents:
diff changeset
1450 Rules 16-20: If AND operation happens on sp in prologue, we assume
kono
parents:
diff changeset
1451 stack is realigned. We will use a group of DW_OP_XXX
kono
parents:
diff changeset
1452 expressions to represent the location of the stored
kono
parents:
diff changeset
1453 register instead of CFA+offset.
kono
parents:
diff changeset
1454
kono
parents:
diff changeset
1455 The Rules
kono
parents:
diff changeset
1456
kono
parents:
diff changeset
1457 "{a,b}" indicates a choice of a xor b.
kono
parents:
diff changeset
1458 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
kono
parents:
diff changeset
1459
kono
parents:
diff changeset
1460 Rule 1:
kono
parents:
diff changeset
1461 (set <reg1> <reg2>:cfa.reg)
kono
parents:
diff changeset
1462 effects: cfa.reg = <reg1>
kono
parents:
diff changeset
1463 cfa.offset unchanged
kono
parents:
diff changeset
1464 cfa_temp.reg = <reg1>
kono
parents:
diff changeset
1465 cfa_temp.offset = cfa.offset
kono
parents:
diff changeset
1466
kono
parents:
diff changeset
1467 Rule 2:
kono
parents:
diff changeset
1468 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
kono
parents:
diff changeset
1469 {<const_int>,<reg>:cfa_temp.reg}))
kono
parents:
diff changeset
1470 effects: cfa.reg = sp if fp used
kono
parents:
diff changeset
1471 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
kono
parents:
diff changeset
1472 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
kono
parents:
diff changeset
1473 if cfa_store.reg==sp
kono
parents:
diff changeset
1474
kono
parents:
diff changeset
1475 Rule 3:
kono
parents:
diff changeset
1476 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
kono
parents:
diff changeset
1477 effects: cfa.reg = fp
kono
parents:
diff changeset
1478 cfa_offset += +/- <const_int>
kono
parents:
diff changeset
1479
kono
parents:
diff changeset
1480 Rule 4:
kono
parents:
diff changeset
1481 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
kono
parents:
diff changeset
1482 constraints: <reg1> != fp
kono
parents:
diff changeset
1483 <reg1> != sp
kono
parents:
diff changeset
1484 effects: cfa.reg = <reg1>
kono
parents:
diff changeset
1485 cfa_temp.reg = <reg1>
kono
parents:
diff changeset
1486 cfa_temp.offset = cfa.offset
kono
parents:
diff changeset
1487
kono
parents:
diff changeset
1488 Rule 5:
kono
parents:
diff changeset
1489 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
kono
parents:
diff changeset
1490 constraints: <reg1> != fp
kono
parents:
diff changeset
1491 <reg1> != sp
kono
parents:
diff changeset
1492 effects: cfa_store.reg = <reg1>
kono
parents:
diff changeset
1493 cfa_store.offset = cfa.offset - cfa_temp.offset
kono
parents:
diff changeset
1494
kono
parents:
diff changeset
1495 Rule 6:
kono
parents:
diff changeset
1496 (set <reg> <const_int>)
kono
parents:
diff changeset
1497 effects: cfa_temp.reg = <reg>
kono
parents:
diff changeset
1498 cfa_temp.offset = <const_int>
kono
parents:
diff changeset
1499
kono
parents:
diff changeset
1500 Rule 7:
kono
parents:
diff changeset
1501 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
kono
parents:
diff changeset
1502 effects: cfa_temp.reg = <reg1>
kono
parents:
diff changeset
1503 cfa_temp.offset |= <const_int>
kono
parents:
diff changeset
1504
kono
parents:
diff changeset
1505 Rule 8:
kono
parents:
diff changeset
1506 (set <reg> (high <exp>))
kono
parents:
diff changeset
1507 effects: none
kono
parents:
diff changeset
1508
kono
parents:
diff changeset
1509 Rule 9:
kono
parents:
diff changeset
1510 (set <reg> (lo_sum <exp> <const_int>))
kono
parents:
diff changeset
1511 effects: cfa_temp.reg = <reg>
kono
parents:
diff changeset
1512 cfa_temp.offset = <const_int>
kono
parents:
diff changeset
1513
kono
parents:
diff changeset
1514 Rule 10:
kono
parents:
diff changeset
1515 (set (mem ({pre,post}_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
kono
parents:
diff changeset
1516 effects: cfa_store.offset -= <const_int>
kono
parents:
diff changeset
1517 cfa.offset = cfa_store.offset if cfa.reg == sp
kono
parents:
diff changeset
1518 cfa.reg = sp
kono
parents:
diff changeset
1519 cfa.base_offset = -cfa_store.offset
kono
parents:
diff changeset
1520
kono
parents:
diff changeset
1521 Rule 11:
kono
parents:
diff changeset
1522 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
kono
parents:
diff changeset
1523 effects: cfa_store.offset += -/+ mode_size(mem)
kono
parents:
diff changeset
1524 cfa.offset = cfa_store.offset if cfa.reg == sp
kono
parents:
diff changeset
1525 cfa.reg = sp
kono
parents:
diff changeset
1526 cfa.base_offset = -cfa_store.offset
kono
parents:
diff changeset
1527
kono
parents:
diff changeset
1528 Rule 12:
kono
parents:
diff changeset
1529 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
kono
parents:
diff changeset
1530
kono
parents:
diff changeset
1531 <reg2>)
kono
parents:
diff changeset
1532 effects: cfa.reg = <reg1>
kono
parents:
diff changeset
1533 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
kono
parents:
diff changeset
1534
kono
parents:
diff changeset
1535 Rule 13:
kono
parents:
diff changeset
1536 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
kono
parents:
diff changeset
1537 effects: cfa.reg = <reg1>
kono
parents:
diff changeset
1538 cfa.base_offset = -{cfa_store,cfa_temp}.offset
kono
parents:
diff changeset
1539
kono
parents:
diff changeset
1540 Rule 14:
kono
parents:
diff changeset
1541 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
kono
parents:
diff changeset
1542 effects: cfa.reg = <reg1>
kono
parents:
diff changeset
1543 cfa.base_offset = -cfa_temp.offset
kono
parents:
diff changeset
1544 cfa_temp.offset -= mode_size(mem)
kono
parents:
diff changeset
1545
kono
parents:
diff changeset
1546 Rule 15:
kono
parents:
diff changeset
1547 (set <reg> {unspec, unspec_volatile})
kono
parents:
diff changeset
1548 effects: target-dependent
kono
parents:
diff changeset
1549
kono
parents:
diff changeset
1550 Rule 16:
kono
parents:
diff changeset
1551 (set sp (and: sp <const_int>))
kono
parents:
diff changeset
1552 constraints: cfa_store.reg == sp
kono
parents:
diff changeset
1553 effects: cfun->fde.stack_realign = 1
kono
parents:
diff changeset
1554 cfa_store.offset = 0
kono
parents:
diff changeset
1555 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
kono
parents:
diff changeset
1556
kono
parents:
diff changeset
1557 Rule 17:
kono
parents:
diff changeset
1558 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
kono
parents:
diff changeset
1559 effects: cfa_store.offset += -/+ mode_size(mem)
kono
parents:
diff changeset
1560
kono
parents:
diff changeset
1561 Rule 18:
kono
parents:
diff changeset
1562 (set (mem ({pre_inc, pre_dec} sp)) fp)
kono
parents:
diff changeset
1563 constraints: fde->stack_realign == 1
kono
parents:
diff changeset
1564 effects: cfa_store.offset = 0
kono
parents:
diff changeset
1565 cfa.reg != HARD_FRAME_POINTER_REGNUM
kono
parents:
diff changeset
1566
kono
parents:
diff changeset
1567 Rule 19:
kono
parents:
diff changeset
1568 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
kono
parents:
diff changeset
1569 constraints: fde->stack_realign == 1
kono
parents:
diff changeset
1570 && cfa.offset == 0
kono
parents:
diff changeset
1571 && cfa.indirect == 0
kono
parents:
diff changeset
1572 && cfa.reg != HARD_FRAME_POINTER_REGNUM
kono
parents:
diff changeset
1573 effects: Use DW_CFA_def_cfa_expression to define cfa
kono
parents:
diff changeset
1574 cfa.reg == fde->drap_reg */
kono
parents:
diff changeset
1575
kono
parents:
diff changeset
1576 static void
kono
parents:
diff changeset
1577 dwarf2out_frame_debug_expr (rtx expr)
kono
parents:
diff changeset
1578 {
kono
parents:
diff changeset
1579 rtx src, dest, span;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1580 poly_int64 offset;
111
kono
parents:
diff changeset
1581 dw_fde_ref fde;
kono
parents:
diff changeset
1582
kono
parents:
diff changeset
1583 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
kono
parents:
diff changeset
1584 the PARALLEL independently. The first element is always processed if
kono
parents:
diff changeset
1585 it is a SET. This is for backward compatibility. Other elements
kono
parents:
diff changeset
1586 are processed only if they are SETs and the RTX_FRAME_RELATED_P
kono
parents:
diff changeset
1587 flag is set in them. */
kono
parents:
diff changeset
1588 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
kono
parents:
diff changeset
1589 {
kono
parents:
diff changeset
1590 int par_index;
kono
parents:
diff changeset
1591 int limit = XVECLEN (expr, 0);
kono
parents:
diff changeset
1592 rtx elem;
kono
parents:
diff changeset
1593
kono
parents:
diff changeset
1594 /* PARALLELs have strict read-modify-write semantics, so we
kono
parents:
diff changeset
1595 ought to evaluate every rvalue before changing any lvalue.
kono
parents:
diff changeset
1596 It's cumbersome to do that in general, but there's an
kono
parents:
diff changeset
1597 easy approximation that is enough for all current users:
kono
parents:
diff changeset
1598 handle register saves before register assignments. */
kono
parents:
diff changeset
1599 if (GET_CODE (expr) == PARALLEL)
kono
parents:
diff changeset
1600 for (par_index = 0; par_index < limit; par_index++)
kono
parents:
diff changeset
1601 {
kono
parents:
diff changeset
1602 elem = XVECEXP (expr, 0, par_index);
kono
parents:
diff changeset
1603 if (GET_CODE (elem) == SET
kono
parents:
diff changeset
1604 && MEM_P (SET_DEST (elem))
kono
parents:
diff changeset
1605 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
kono
parents:
diff changeset
1606 dwarf2out_frame_debug_expr (elem);
kono
parents:
diff changeset
1607 }
kono
parents:
diff changeset
1608
kono
parents:
diff changeset
1609 for (par_index = 0; par_index < limit; par_index++)
kono
parents:
diff changeset
1610 {
kono
parents:
diff changeset
1611 elem = XVECEXP (expr, 0, par_index);
kono
parents:
diff changeset
1612 if (GET_CODE (elem) == SET
kono
parents:
diff changeset
1613 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
kono
parents:
diff changeset
1614 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
kono
parents:
diff changeset
1615 dwarf2out_frame_debug_expr (elem);
kono
parents:
diff changeset
1616 }
kono
parents:
diff changeset
1617 return;
kono
parents:
diff changeset
1618 }
kono
parents:
diff changeset
1619
kono
parents:
diff changeset
1620 gcc_assert (GET_CODE (expr) == SET);
kono
parents:
diff changeset
1621
kono
parents:
diff changeset
1622 src = SET_SRC (expr);
kono
parents:
diff changeset
1623 dest = SET_DEST (expr);
kono
parents:
diff changeset
1624
kono
parents:
diff changeset
1625 if (REG_P (src))
kono
parents:
diff changeset
1626 {
kono
parents:
diff changeset
1627 rtx rsi = reg_saved_in (src);
kono
parents:
diff changeset
1628 if (rsi)
kono
parents:
diff changeset
1629 src = rsi;
kono
parents:
diff changeset
1630 }
kono
parents:
diff changeset
1631
kono
parents:
diff changeset
1632 fde = cfun->fde;
kono
parents:
diff changeset
1633
kono
parents:
diff changeset
1634 switch (GET_CODE (dest))
kono
parents:
diff changeset
1635 {
kono
parents:
diff changeset
1636 case REG:
kono
parents:
diff changeset
1637 switch (GET_CODE (src))
kono
parents:
diff changeset
1638 {
kono
parents:
diff changeset
1639 /* Setting FP from SP. */
kono
parents:
diff changeset
1640 case REG:
kono
parents:
diff changeset
1641 if (cur_cfa->reg == dwf_regno (src))
kono
parents:
diff changeset
1642 {
kono
parents:
diff changeset
1643 /* Rule 1 */
kono
parents:
diff changeset
1644 /* Update the CFA rule wrt SP or FP. Make sure src is
kono
parents:
diff changeset
1645 relative to the current CFA register.
kono
parents:
diff changeset
1646
kono
parents:
diff changeset
1647 We used to require that dest be either SP or FP, but the
kono
parents:
diff changeset
1648 ARM copies SP to a temporary register, and from there to
kono
parents:
diff changeset
1649 FP. So we just rely on the backends to only set
kono
parents:
diff changeset
1650 RTX_FRAME_RELATED_P on appropriate insns. */
kono
parents:
diff changeset
1651 cur_cfa->reg = dwf_regno (dest);
kono
parents:
diff changeset
1652 cur_trace->cfa_temp.reg = cur_cfa->reg;
kono
parents:
diff changeset
1653 cur_trace->cfa_temp.offset = cur_cfa->offset;
kono
parents:
diff changeset
1654 }
kono
parents:
diff changeset
1655 else
kono
parents:
diff changeset
1656 {
kono
parents:
diff changeset
1657 /* Saving a register in a register. */
kono
parents:
diff changeset
1658 gcc_assert (!fixed_regs [REGNO (dest)]
kono
parents:
diff changeset
1659 /* For the SPARC and its register window. */
kono
parents:
diff changeset
1660 || (dwf_regno (src) == DWARF_FRAME_RETURN_COLUMN));
kono
parents:
diff changeset
1661
kono
parents:
diff changeset
1662 /* After stack is aligned, we can only save SP in FP
kono
parents:
diff changeset
1663 if drap register is used. In this case, we have
kono
parents:
diff changeset
1664 to restore stack pointer with the CFA value and we
kono
parents:
diff changeset
1665 don't generate this DWARF information. */
kono
parents:
diff changeset
1666 if (fde
kono
parents:
diff changeset
1667 && fde->stack_realign
kono
parents:
diff changeset
1668 && REGNO (src) == STACK_POINTER_REGNUM)
kono
parents:
diff changeset
1669 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
kono
parents:
diff changeset
1670 && fde->drap_reg != INVALID_REGNUM
kono
parents:
diff changeset
1671 && cur_cfa->reg != dwf_regno (src));
kono
parents:
diff changeset
1672 else
kono
parents:
diff changeset
1673 queue_reg_save (src, dest, 0);
kono
parents:
diff changeset
1674 }
kono
parents:
diff changeset
1675 break;
kono
parents:
diff changeset
1676
kono
parents:
diff changeset
1677 case PLUS:
kono
parents:
diff changeset
1678 case MINUS:
kono
parents:
diff changeset
1679 case LO_SUM:
kono
parents:
diff changeset
1680 if (dest == stack_pointer_rtx)
kono
parents:
diff changeset
1681 {
kono
parents:
diff changeset
1682 /* Rule 2 */
kono
parents:
diff changeset
1683 /* Adjusting SP. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1684 if (REG_P (XEXP (src, 1)))
111
kono
parents:
diff changeset
1685 {
kono
parents:
diff changeset
1686 gcc_assert (dwf_regno (XEXP (src, 1))
kono
parents:
diff changeset
1687 == cur_trace->cfa_temp.reg);
kono
parents:
diff changeset
1688 offset = cur_trace->cfa_temp.offset;
kono
parents:
diff changeset
1689 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1690 else if (!poly_int_rtx_p (XEXP (src, 1), &offset))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1691 gcc_unreachable ();
111
kono
parents:
diff changeset
1692
kono
parents:
diff changeset
1693 if (XEXP (src, 0) == hard_frame_pointer_rtx)
kono
parents:
diff changeset
1694 {
kono
parents:
diff changeset
1695 /* Restoring SP from FP in the epilogue. */
kono
parents:
diff changeset
1696 gcc_assert (cur_cfa->reg == dw_frame_pointer_regnum);
kono
parents:
diff changeset
1697 cur_cfa->reg = dw_stack_pointer_regnum;
kono
parents:
diff changeset
1698 }
kono
parents:
diff changeset
1699 else if (GET_CODE (src) == LO_SUM)
kono
parents:
diff changeset
1700 /* Assume we've set the source reg of the LO_SUM from sp. */
kono
parents:
diff changeset
1701 ;
kono
parents:
diff changeset
1702 else
kono
parents:
diff changeset
1703 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
kono
parents:
diff changeset
1704
kono
parents:
diff changeset
1705 if (GET_CODE (src) != MINUS)
kono
parents:
diff changeset
1706 offset = -offset;
kono
parents:
diff changeset
1707 if (cur_cfa->reg == dw_stack_pointer_regnum)
kono
parents:
diff changeset
1708 cur_cfa->offset += offset;
kono
parents:
diff changeset
1709 if (cur_trace->cfa_store.reg == dw_stack_pointer_regnum)
kono
parents:
diff changeset
1710 cur_trace->cfa_store.offset += offset;
kono
parents:
diff changeset
1711 }
kono
parents:
diff changeset
1712 else if (dest == hard_frame_pointer_rtx)
kono
parents:
diff changeset
1713 {
kono
parents:
diff changeset
1714 /* Rule 3 */
kono
parents:
diff changeset
1715 /* Either setting the FP from an offset of the SP,
kono
parents:
diff changeset
1716 or adjusting the FP */
kono
parents:
diff changeset
1717 gcc_assert (frame_pointer_needed);
kono
parents:
diff changeset
1718
kono
parents:
diff changeset
1719 gcc_assert (REG_P (XEXP (src, 0))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1720 && dwf_regno (XEXP (src, 0)) == cur_cfa->reg);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1721 offset = rtx_to_poly_int64 (XEXP (src, 1));
111
kono
parents:
diff changeset
1722 if (GET_CODE (src) != MINUS)
kono
parents:
diff changeset
1723 offset = -offset;
kono
parents:
diff changeset
1724 cur_cfa->offset += offset;
kono
parents:
diff changeset
1725 cur_cfa->reg = dw_frame_pointer_regnum;
kono
parents:
diff changeset
1726 }
kono
parents:
diff changeset
1727 else
kono
parents:
diff changeset
1728 {
kono
parents:
diff changeset
1729 gcc_assert (GET_CODE (src) != MINUS);
kono
parents:
diff changeset
1730
kono
parents:
diff changeset
1731 /* Rule 4 */
kono
parents:
diff changeset
1732 if (REG_P (XEXP (src, 0))
kono
parents:
diff changeset
1733 && dwf_regno (XEXP (src, 0)) == cur_cfa->reg
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1734 && poly_int_rtx_p (XEXP (src, 1), &offset))
111
kono
parents:
diff changeset
1735 {
kono
parents:
diff changeset
1736 /* Setting a temporary CFA register that will be copied
kono
parents:
diff changeset
1737 into the FP later on. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1738 offset = -offset;
111
kono
parents:
diff changeset
1739 cur_cfa->offset += offset;
kono
parents:
diff changeset
1740 cur_cfa->reg = dwf_regno (dest);
kono
parents:
diff changeset
1741 /* Or used to save regs to the stack. */
kono
parents:
diff changeset
1742 cur_trace->cfa_temp.reg = cur_cfa->reg;
kono
parents:
diff changeset
1743 cur_trace->cfa_temp.offset = cur_cfa->offset;
kono
parents:
diff changeset
1744 }
kono
parents:
diff changeset
1745
kono
parents:
diff changeset
1746 /* Rule 5 */
kono
parents:
diff changeset
1747 else if (REG_P (XEXP (src, 0))
kono
parents:
diff changeset
1748 && dwf_regno (XEXP (src, 0)) == cur_trace->cfa_temp.reg
kono
parents:
diff changeset
1749 && XEXP (src, 1) == stack_pointer_rtx)
kono
parents:
diff changeset
1750 {
kono
parents:
diff changeset
1751 /* Setting a scratch register that we will use instead
kono
parents:
diff changeset
1752 of SP for saving registers to the stack. */
kono
parents:
diff changeset
1753 gcc_assert (cur_cfa->reg == dw_stack_pointer_regnum);
kono
parents:
diff changeset
1754 cur_trace->cfa_store.reg = dwf_regno (dest);
kono
parents:
diff changeset
1755 cur_trace->cfa_store.offset
kono
parents:
diff changeset
1756 = cur_cfa->offset - cur_trace->cfa_temp.offset;
kono
parents:
diff changeset
1757 }
kono
parents:
diff changeset
1758
kono
parents:
diff changeset
1759 /* Rule 9 */
kono
parents:
diff changeset
1760 else if (GET_CODE (src) == LO_SUM
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1761 && poly_int_rtx_p (XEXP (src, 1),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1762 &cur_trace->cfa_temp.offset))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1763 cur_trace->cfa_temp.reg = dwf_regno (dest);
111
kono
parents:
diff changeset
1764 else
kono
parents:
diff changeset
1765 gcc_unreachable ();
kono
parents:
diff changeset
1766 }
kono
parents:
diff changeset
1767 break;
kono
parents:
diff changeset
1768
kono
parents:
diff changeset
1769 /* Rule 6 */
kono
parents:
diff changeset
1770 case CONST_INT:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1771 case POLY_INT_CST:
111
kono
parents:
diff changeset
1772 cur_trace->cfa_temp.reg = dwf_regno (dest);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1773 cur_trace->cfa_temp.offset = rtx_to_poly_int64 (src);
111
kono
parents:
diff changeset
1774 break;
kono
parents:
diff changeset
1775
kono
parents:
diff changeset
1776 /* Rule 7 */
kono
parents:
diff changeset
1777 case IOR:
kono
parents:
diff changeset
1778 gcc_assert (REG_P (XEXP (src, 0))
kono
parents:
diff changeset
1779 && dwf_regno (XEXP (src, 0)) == cur_trace->cfa_temp.reg
kono
parents:
diff changeset
1780 && CONST_INT_P (XEXP (src, 1)));
kono
parents:
diff changeset
1781
kono
parents:
diff changeset
1782 cur_trace->cfa_temp.reg = dwf_regno (dest);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1783 if (!can_ior_p (cur_trace->cfa_temp.offset, INTVAL (XEXP (src, 1)),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1784 &cur_trace->cfa_temp.offset))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1785 /* The target shouldn't generate this kind of CFI note if we
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1786 can't represent it. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1787 gcc_unreachable ();
111
kono
parents:
diff changeset
1788 break;
kono
parents:
diff changeset
1789
kono
parents:
diff changeset
1790 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
kono
parents:
diff changeset
1791 which will fill in all of the bits. */
kono
parents:
diff changeset
1792 /* Rule 8 */
kono
parents:
diff changeset
1793 case HIGH:
kono
parents:
diff changeset
1794 break;
kono
parents:
diff changeset
1795
kono
parents:
diff changeset
1796 /* Rule 15 */
kono
parents:
diff changeset
1797 case UNSPEC:
kono
parents:
diff changeset
1798 case UNSPEC_VOLATILE:
kono
parents:
diff changeset
1799 /* All unspecs should be represented by REG_CFA_* notes. */
kono
parents:
diff changeset
1800 gcc_unreachable ();
kono
parents:
diff changeset
1801 return;
kono
parents:
diff changeset
1802
kono
parents:
diff changeset
1803 /* Rule 16 */
kono
parents:
diff changeset
1804 case AND:
kono
parents:
diff changeset
1805 /* If this AND operation happens on stack pointer in prologue,
kono
parents:
diff changeset
1806 we assume the stack is realigned and we extract the
kono
parents:
diff changeset
1807 alignment. */
kono
parents:
diff changeset
1808 if (fde && XEXP (src, 0) == stack_pointer_rtx)
kono
parents:
diff changeset
1809 {
kono
parents:
diff changeset
1810 /* We interpret reg_save differently with stack_realign set.
kono
parents:
diff changeset
1811 Thus we must flush whatever we have queued first. */
kono
parents:
diff changeset
1812 dwarf2out_flush_queued_reg_saves ();
kono
parents:
diff changeset
1813
kono
parents:
diff changeset
1814 gcc_assert (cur_trace->cfa_store.reg
kono
parents:
diff changeset
1815 == dwf_regno (XEXP (src, 0)));
kono
parents:
diff changeset
1816 fde->stack_realign = 1;
kono
parents:
diff changeset
1817 fde->stack_realignment = INTVAL (XEXP (src, 1));
kono
parents:
diff changeset
1818 cur_trace->cfa_store.offset = 0;
kono
parents:
diff changeset
1819
kono
parents:
diff changeset
1820 if (cur_cfa->reg != dw_stack_pointer_regnum
kono
parents:
diff changeset
1821 && cur_cfa->reg != dw_frame_pointer_regnum)
kono
parents:
diff changeset
1822 fde->drap_reg = cur_cfa->reg;
kono
parents:
diff changeset
1823 }
kono
parents:
diff changeset
1824 return;
kono
parents:
diff changeset
1825
kono
parents:
diff changeset
1826 default:
kono
parents:
diff changeset
1827 gcc_unreachable ();
kono
parents:
diff changeset
1828 }
kono
parents:
diff changeset
1829 break;
kono
parents:
diff changeset
1830
kono
parents:
diff changeset
1831 case MEM:
kono
parents:
diff changeset
1832
kono
parents:
diff changeset
1833 /* Saving a register to the stack. Make sure dest is relative to the
kono
parents:
diff changeset
1834 CFA register. */
kono
parents:
diff changeset
1835 switch (GET_CODE (XEXP (dest, 0)))
kono
parents:
diff changeset
1836 {
kono
parents:
diff changeset
1837 /* Rule 10 */
kono
parents:
diff changeset
1838 /* With a push. */
kono
parents:
diff changeset
1839 case PRE_MODIFY:
kono
parents:
diff changeset
1840 case POST_MODIFY:
kono
parents:
diff changeset
1841 /* We can't handle variable size modifications. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1842 offset = -rtx_to_poly_int64 (XEXP (XEXP (XEXP (dest, 0), 1), 1));
111
kono
parents:
diff changeset
1843
kono
parents:
diff changeset
1844 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
kono
parents:
diff changeset
1845 && cur_trace->cfa_store.reg == dw_stack_pointer_regnum);
kono
parents:
diff changeset
1846
kono
parents:
diff changeset
1847 cur_trace->cfa_store.offset += offset;
kono
parents:
diff changeset
1848 if (cur_cfa->reg == dw_stack_pointer_regnum)
kono
parents:
diff changeset
1849 cur_cfa->offset = cur_trace->cfa_store.offset;
kono
parents:
diff changeset
1850
kono
parents:
diff changeset
1851 if (GET_CODE (XEXP (dest, 0)) == POST_MODIFY)
kono
parents:
diff changeset
1852 offset -= cur_trace->cfa_store.offset;
kono
parents:
diff changeset
1853 else
kono
parents:
diff changeset
1854 offset = -cur_trace->cfa_store.offset;
kono
parents:
diff changeset
1855 break;
kono
parents:
diff changeset
1856
kono
parents:
diff changeset
1857 /* Rule 11 */
kono
parents:
diff changeset
1858 case PRE_INC:
kono
parents:
diff changeset
1859 case PRE_DEC:
kono
parents:
diff changeset
1860 case POST_DEC:
kono
parents:
diff changeset
1861 offset = GET_MODE_SIZE (GET_MODE (dest));
kono
parents:
diff changeset
1862 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
kono
parents:
diff changeset
1863 offset = -offset;
kono
parents:
diff changeset
1864
kono
parents:
diff changeset
1865 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
kono
parents:
diff changeset
1866 == STACK_POINTER_REGNUM)
kono
parents:
diff changeset
1867 && cur_trace->cfa_store.reg == dw_stack_pointer_regnum);
kono
parents:
diff changeset
1868
kono
parents:
diff changeset
1869 cur_trace->cfa_store.offset += offset;
kono
parents:
diff changeset
1870
kono
parents:
diff changeset
1871 /* Rule 18: If stack is aligned, we will use FP as a
kono
parents:
diff changeset
1872 reference to represent the address of the stored
kono
parents:
diff changeset
1873 regiser. */
kono
parents:
diff changeset
1874 if (fde
kono
parents:
diff changeset
1875 && fde->stack_realign
kono
parents:
diff changeset
1876 && REG_P (src)
kono
parents:
diff changeset
1877 && REGNO (src) == HARD_FRAME_POINTER_REGNUM)
kono
parents:
diff changeset
1878 {
kono
parents:
diff changeset
1879 gcc_assert (cur_cfa->reg != dw_frame_pointer_regnum);
kono
parents:
diff changeset
1880 cur_trace->cfa_store.offset = 0;
kono
parents:
diff changeset
1881 }
kono
parents:
diff changeset
1882
kono
parents:
diff changeset
1883 if (cur_cfa->reg == dw_stack_pointer_regnum)
kono
parents:
diff changeset
1884 cur_cfa->offset = cur_trace->cfa_store.offset;
kono
parents:
diff changeset
1885
kono
parents:
diff changeset
1886 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
kono
parents:
diff changeset
1887 offset += -cur_trace->cfa_store.offset;
kono
parents:
diff changeset
1888 else
kono
parents:
diff changeset
1889 offset = -cur_trace->cfa_store.offset;
kono
parents:
diff changeset
1890 break;
kono
parents:
diff changeset
1891
kono
parents:
diff changeset
1892 /* Rule 12 */
kono
parents:
diff changeset
1893 /* With an offset. */
kono
parents:
diff changeset
1894 case PLUS:
kono
parents:
diff changeset
1895 case MINUS:
kono
parents:
diff changeset
1896 case LO_SUM:
kono
parents:
diff changeset
1897 {
kono
parents:
diff changeset
1898 unsigned int regno;
kono
parents:
diff changeset
1899
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1900 gcc_assert (REG_P (XEXP (XEXP (dest, 0), 0)));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1901 offset = rtx_to_poly_int64 (XEXP (XEXP (dest, 0), 1));
111
kono
parents:
diff changeset
1902 if (GET_CODE (XEXP (dest, 0)) == MINUS)
kono
parents:
diff changeset
1903 offset = -offset;
kono
parents:
diff changeset
1904
kono
parents:
diff changeset
1905 regno = dwf_regno (XEXP (XEXP (dest, 0), 0));
kono
parents:
diff changeset
1906
kono
parents:
diff changeset
1907 if (cur_cfa->reg == regno)
kono
parents:
diff changeset
1908 offset -= cur_cfa->offset;
kono
parents:
diff changeset
1909 else if (cur_trace->cfa_store.reg == regno)
kono
parents:
diff changeset
1910 offset -= cur_trace->cfa_store.offset;
kono
parents:
diff changeset
1911 else
kono
parents:
diff changeset
1912 {
kono
parents:
diff changeset
1913 gcc_assert (cur_trace->cfa_temp.reg == regno);
kono
parents:
diff changeset
1914 offset -= cur_trace->cfa_temp.offset;
kono
parents:
diff changeset
1915 }
kono
parents:
diff changeset
1916 }
kono
parents:
diff changeset
1917 break;
kono
parents:
diff changeset
1918
kono
parents:
diff changeset
1919 /* Rule 13 */
kono
parents:
diff changeset
1920 /* Without an offset. */
kono
parents:
diff changeset
1921 case REG:
kono
parents:
diff changeset
1922 {
kono
parents:
diff changeset
1923 unsigned int regno = dwf_regno (XEXP (dest, 0));
kono
parents:
diff changeset
1924
kono
parents:
diff changeset
1925 if (cur_cfa->reg == regno)
kono
parents:
diff changeset
1926 offset = -cur_cfa->offset;
kono
parents:
diff changeset
1927 else if (cur_trace->cfa_store.reg == regno)
kono
parents:
diff changeset
1928 offset = -cur_trace->cfa_store.offset;
kono
parents:
diff changeset
1929 else
kono
parents:
diff changeset
1930 {
kono
parents:
diff changeset
1931 gcc_assert (cur_trace->cfa_temp.reg == regno);
kono
parents:
diff changeset
1932 offset = -cur_trace->cfa_temp.offset;
kono
parents:
diff changeset
1933 }
kono
parents:
diff changeset
1934 }
kono
parents:
diff changeset
1935 break;
kono
parents:
diff changeset
1936
kono
parents:
diff changeset
1937 /* Rule 14 */
kono
parents:
diff changeset
1938 case POST_INC:
kono
parents:
diff changeset
1939 gcc_assert (cur_trace->cfa_temp.reg
kono
parents:
diff changeset
1940 == dwf_regno (XEXP (XEXP (dest, 0), 0)));
kono
parents:
diff changeset
1941 offset = -cur_trace->cfa_temp.offset;
kono
parents:
diff changeset
1942 cur_trace->cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
kono
parents:
diff changeset
1943 break;
kono
parents:
diff changeset
1944
kono
parents:
diff changeset
1945 default:
kono
parents:
diff changeset
1946 gcc_unreachable ();
kono
parents:
diff changeset
1947 }
kono
parents:
diff changeset
1948
kono
parents:
diff changeset
1949 /* Rule 17 */
kono
parents:
diff changeset
1950 /* If the source operand of this MEM operation is a memory,
kono
parents:
diff changeset
1951 we only care how much stack grew. */
kono
parents:
diff changeset
1952 if (MEM_P (src))
kono
parents:
diff changeset
1953 break;
kono
parents:
diff changeset
1954
kono
parents:
diff changeset
1955 if (REG_P (src)
kono
parents:
diff changeset
1956 && REGNO (src) != STACK_POINTER_REGNUM
kono
parents:
diff changeset
1957 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
kono
parents:
diff changeset
1958 && dwf_regno (src) == cur_cfa->reg)
kono
parents:
diff changeset
1959 {
kono
parents:
diff changeset
1960 /* We're storing the current CFA reg into the stack. */
kono
parents:
diff changeset
1961
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1962 if (known_eq (cur_cfa->offset, 0))
111
kono
parents:
diff changeset
1963 {
kono
parents:
diff changeset
1964 /* Rule 19 */
kono
parents:
diff changeset
1965 /* If stack is aligned, putting CFA reg into stack means
kono
parents:
diff changeset
1966 we can no longer use reg + offset to represent CFA.
kono
parents:
diff changeset
1967 Here we use DW_CFA_def_cfa_expression instead. The
kono
parents:
diff changeset
1968 result of this expression equals to the original CFA
kono
parents:
diff changeset
1969 value. */
kono
parents:
diff changeset
1970 if (fde
kono
parents:
diff changeset
1971 && fde->stack_realign
kono
parents:
diff changeset
1972 && cur_cfa->indirect == 0
kono
parents:
diff changeset
1973 && cur_cfa->reg != dw_frame_pointer_regnum)
kono
parents:
diff changeset
1974 {
kono
parents:
diff changeset
1975 gcc_assert (fde->drap_reg == cur_cfa->reg);
kono
parents:
diff changeset
1976
kono
parents:
diff changeset
1977 cur_cfa->indirect = 1;
kono
parents:
diff changeset
1978 cur_cfa->reg = dw_frame_pointer_regnum;
kono
parents:
diff changeset
1979 cur_cfa->base_offset = offset;
kono
parents:
diff changeset
1980 cur_cfa->offset = 0;
kono
parents:
diff changeset
1981
kono
parents:
diff changeset
1982 fde->drap_reg_saved = 1;
kono
parents:
diff changeset
1983 break;
kono
parents:
diff changeset
1984 }
kono
parents:
diff changeset
1985
kono
parents:
diff changeset
1986 /* If the source register is exactly the CFA, assume
kono
parents:
diff changeset
1987 we're saving SP like any other register; this happens
kono
parents:
diff changeset
1988 on the ARM. */
kono
parents:
diff changeset
1989 queue_reg_save (stack_pointer_rtx, NULL_RTX, offset);
kono
parents:
diff changeset
1990 break;
kono
parents:
diff changeset
1991 }
kono
parents:
diff changeset
1992 else
kono
parents:
diff changeset
1993 {
kono
parents:
diff changeset
1994 /* Otherwise, we'll need to look in the stack to
kono
parents:
diff changeset
1995 calculate the CFA. */
kono
parents:
diff changeset
1996 rtx x = XEXP (dest, 0);
kono
parents:
diff changeset
1997
kono
parents:
diff changeset
1998 if (!REG_P (x))
kono
parents:
diff changeset
1999 x = XEXP (x, 0);
kono
parents:
diff changeset
2000 gcc_assert (REG_P (x));
kono
parents:
diff changeset
2001
kono
parents:
diff changeset
2002 cur_cfa->reg = dwf_regno (x);
kono
parents:
diff changeset
2003 cur_cfa->base_offset = offset;
kono
parents:
diff changeset
2004 cur_cfa->indirect = 1;
kono
parents:
diff changeset
2005 break;
kono
parents:
diff changeset
2006 }
kono
parents:
diff changeset
2007 }
kono
parents:
diff changeset
2008
kono
parents:
diff changeset
2009 if (REG_P (src))
kono
parents:
diff changeset
2010 span = targetm.dwarf_register_span (src);
kono
parents:
diff changeset
2011 else
kono
parents:
diff changeset
2012 span = NULL;
kono
parents:
diff changeset
2013
kono
parents:
diff changeset
2014 if (!span)
kono
parents:
diff changeset
2015 queue_reg_save (src, NULL_RTX, offset);
kono
parents:
diff changeset
2016 else
kono
parents:
diff changeset
2017 {
kono
parents:
diff changeset
2018 /* We have a PARALLEL describing where the contents of SRC live.
kono
parents:
diff changeset
2019 Queue register saves for each piece of the PARALLEL. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2020 poly_int64 span_offset = offset;
111
kono
parents:
diff changeset
2021
kono
parents:
diff changeset
2022 gcc_assert (GET_CODE (span) == PARALLEL);
kono
parents:
diff changeset
2023
kono
parents:
diff changeset
2024 const int par_len = XVECLEN (span, 0);
kono
parents:
diff changeset
2025 for (int par_index = 0; par_index < par_len; par_index++)
kono
parents:
diff changeset
2026 {
kono
parents:
diff changeset
2027 rtx elem = XVECEXP (span, 0, par_index);
kono
parents:
diff changeset
2028 queue_reg_save (elem, NULL_RTX, span_offset);
kono
parents:
diff changeset
2029 span_offset += GET_MODE_SIZE (GET_MODE (elem));
kono
parents:
diff changeset
2030 }
kono
parents:
diff changeset
2031 }
kono
parents:
diff changeset
2032 break;
kono
parents:
diff changeset
2033
kono
parents:
diff changeset
2034 default:
kono
parents:
diff changeset
2035 gcc_unreachable ();
kono
parents:
diff changeset
2036 }
kono
parents:
diff changeset
2037 }
kono
parents:
diff changeset
2038
kono
parents:
diff changeset
2039 /* Record call frame debugging information for INSN, which either sets
kono
parents:
diff changeset
2040 SP or FP (adjusting how we calculate the frame address) or saves a
kono
parents:
diff changeset
2041 register to the stack. */
kono
parents:
diff changeset
2042
kono
parents:
diff changeset
2043 static void
kono
parents:
diff changeset
2044 dwarf2out_frame_debug (rtx_insn *insn)
kono
parents:
diff changeset
2045 {
kono
parents:
diff changeset
2046 rtx note, n, pat;
kono
parents:
diff changeset
2047 bool handled_one = false;
kono
parents:
diff changeset
2048
kono
parents:
diff changeset
2049 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
kono
parents:
diff changeset
2050 switch (REG_NOTE_KIND (note))
kono
parents:
diff changeset
2051 {
kono
parents:
diff changeset
2052 case REG_FRAME_RELATED_EXPR:
kono
parents:
diff changeset
2053 pat = XEXP (note, 0);
kono
parents:
diff changeset
2054 goto do_frame_expr;
kono
parents:
diff changeset
2055
kono
parents:
diff changeset
2056 case REG_CFA_DEF_CFA:
kono
parents:
diff changeset
2057 dwarf2out_frame_debug_def_cfa (XEXP (note, 0));
kono
parents:
diff changeset
2058 handled_one = true;
kono
parents:
diff changeset
2059 break;
kono
parents:
diff changeset
2060
kono
parents:
diff changeset
2061 case REG_CFA_ADJUST_CFA:
kono
parents:
diff changeset
2062 n = XEXP (note, 0);
kono
parents:
diff changeset
2063 if (n == NULL)
kono
parents:
diff changeset
2064 {
kono
parents:
diff changeset
2065 n = PATTERN (insn);
kono
parents:
diff changeset
2066 if (GET_CODE (n) == PARALLEL)
kono
parents:
diff changeset
2067 n = XVECEXP (n, 0, 0);
kono
parents:
diff changeset
2068 }
kono
parents:
diff changeset
2069 dwarf2out_frame_debug_adjust_cfa (n);
kono
parents:
diff changeset
2070 handled_one = true;
kono
parents:
diff changeset
2071 break;
kono
parents:
diff changeset
2072
kono
parents:
diff changeset
2073 case REG_CFA_OFFSET:
kono
parents:
diff changeset
2074 n = XEXP (note, 0);
kono
parents:
diff changeset
2075 if (n == NULL)
kono
parents:
diff changeset
2076 n = single_set (insn);
kono
parents:
diff changeset
2077 dwarf2out_frame_debug_cfa_offset (n);
kono
parents:
diff changeset
2078 handled_one = true;
kono
parents:
diff changeset
2079 break;
kono
parents:
diff changeset
2080
kono
parents:
diff changeset
2081 case REG_CFA_REGISTER:
kono
parents:
diff changeset
2082 n = XEXP (note, 0);
kono
parents:
diff changeset
2083 if (n == NULL)
kono
parents:
diff changeset
2084 {
kono
parents:
diff changeset
2085 n = PATTERN (insn);
kono
parents:
diff changeset
2086 if (GET_CODE (n) == PARALLEL)
kono
parents:
diff changeset
2087 n = XVECEXP (n, 0, 0);
kono
parents:
diff changeset
2088 }
kono
parents:
diff changeset
2089 dwarf2out_frame_debug_cfa_register (n);
kono
parents:
diff changeset
2090 handled_one = true;
kono
parents:
diff changeset
2091 break;
kono
parents:
diff changeset
2092
kono
parents:
diff changeset
2093 case REG_CFA_EXPRESSION:
kono
parents:
diff changeset
2094 case REG_CFA_VAL_EXPRESSION:
kono
parents:
diff changeset
2095 n = XEXP (note, 0);
kono
parents:
diff changeset
2096 if (n == NULL)
kono
parents:
diff changeset
2097 n = single_set (insn);
kono
parents:
diff changeset
2098
kono
parents:
diff changeset
2099 if (REG_NOTE_KIND (note) == REG_CFA_EXPRESSION)
kono
parents:
diff changeset
2100 dwarf2out_frame_debug_cfa_expression (n);
kono
parents:
diff changeset
2101 else
kono
parents:
diff changeset
2102 dwarf2out_frame_debug_cfa_val_expression (n);
kono
parents:
diff changeset
2103
kono
parents:
diff changeset
2104 handled_one = true;
kono
parents:
diff changeset
2105 break;
kono
parents:
diff changeset
2106
kono
parents:
diff changeset
2107 case REG_CFA_RESTORE:
kono
parents:
diff changeset
2108 n = XEXP (note, 0);
kono
parents:
diff changeset
2109 if (n == NULL)
kono
parents:
diff changeset
2110 {
kono
parents:
diff changeset
2111 n = PATTERN (insn);
kono
parents:
diff changeset
2112 if (GET_CODE (n) == PARALLEL)
kono
parents:
diff changeset
2113 n = XVECEXP (n, 0, 0);
kono
parents:
diff changeset
2114 n = XEXP (n, 0);
kono
parents:
diff changeset
2115 }
kono
parents:
diff changeset
2116 dwarf2out_frame_debug_cfa_restore (n);
kono
parents:
diff changeset
2117 handled_one = true;
kono
parents:
diff changeset
2118 break;
kono
parents:
diff changeset
2119
kono
parents:
diff changeset
2120 case REG_CFA_SET_VDRAP:
kono
parents:
diff changeset
2121 n = XEXP (note, 0);
kono
parents:
diff changeset
2122 if (REG_P (n))
kono
parents:
diff changeset
2123 {
kono
parents:
diff changeset
2124 dw_fde_ref fde = cfun->fde;
kono
parents:
diff changeset
2125 if (fde)
kono
parents:
diff changeset
2126 {
kono
parents:
diff changeset
2127 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
kono
parents:
diff changeset
2128 if (REG_P (n))
kono
parents:
diff changeset
2129 fde->vdrap_reg = dwf_regno (n);
kono
parents:
diff changeset
2130 }
kono
parents:
diff changeset
2131 }
kono
parents:
diff changeset
2132 handled_one = true;
kono
parents:
diff changeset
2133 break;
kono
parents:
diff changeset
2134
kono
parents:
diff changeset
2135 case REG_CFA_TOGGLE_RA_MANGLE:
kono
parents:
diff changeset
2136 case REG_CFA_WINDOW_SAVE:
kono
parents:
diff changeset
2137 /* We overload both of these operations onto the same DWARF opcode. */
kono
parents:
diff changeset
2138 dwarf2out_frame_debug_cfa_window_save ();
kono
parents:
diff changeset
2139 handled_one = true;
kono
parents:
diff changeset
2140 break;
kono
parents:
diff changeset
2141
kono
parents:
diff changeset
2142 case REG_CFA_FLUSH_QUEUE:
kono
parents:
diff changeset
2143 /* The actual flush happens elsewhere. */
kono
parents:
diff changeset
2144 handled_one = true;
kono
parents:
diff changeset
2145 break;
kono
parents:
diff changeset
2146
kono
parents:
diff changeset
2147 default:
kono
parents:
diff changeset
2148 break;
kono
parents:
diff changeset
2149 }
kono
parents:
diff changeset
2150
kono
parents:
diff changeset
2151 if (!handled_one)
kono
parents:
diff changeset
2152 {
kono
parents:
diff changeset
2153 pat = PATTERN (insn);
kono
parents:
diff changeset
2154 do_frame_expr:
kono
parents:
diff changeset
2155 dwarf2out_frame_debug_expr (pat);
kono
parents:
diff changeset
2156
kono
parents:
diff changeset
2157 /* Check again. A parallel can save and update the same register.
kono
parents:
diff changeset
2158 We could probably check just once, here, but this is safer than
kono
parents:
diff changeset
2159 removing the check at the start of the function. */
kono
parents:
diff changeset
2160 if (clobbers_queued_reg_save (pat))
kono
parents:
diff changeset
2161 dwarf2out_flush_queued_reg_saves ();
kono
parents:
diff changeset
2162 }
kono
parents:
diff changeset
2163 }
kono
parents:
diff changeset
2164
kono
parents:
diff changeset
2165 /* Emit CFI info to change the state from OLD_ROW to NEW_ROW. */
kono
parents:
diff changeset
2166
kono
parents:
diff changeset
2167 static void
kono
parents:
diff changeset
2168 change_cfi_row (dw_cfi_row *old_row, dw_cfi_row *new_row)
kono
parents:
diff changeset
2169 {
kono
parents:
diff changeset
2170 size_t i, n_old, n_new, n_max;
kono
parents:
diff changeset
2171 dw_cfi_ref cfi;
kono
parents:
diff changeset
2172
kono
parents:
diff changeset
2173 if (new_row->cfa_cfi && !cfi_equal_p (old_row->cfa_cfi, new_row->cfa_cfi))
kono
parents:
diff changeset
2174 add_cfi (new_row->cfa_cfi);
kono
parents:
diff changeset
2175 else
kono
parents:
diff changeset
2176 {
kono
parents:
diff changeset
2177 cfi = def_cfa_0 (&old_row->cfa, &new_row->cfa);
kono
parents:
diff changeset
2178 if (cfi)
kono
parents:
diff changeset
2179 add_cfi (cfi);
kono
parents:
diff changeset
2180 }
kono
parents:
diff changeset
2181
kono
parents:
diff changeset
2182 n_old = vec_safe_length (old_row->reg_save);
kono
parents:
diff changeset
2183 n_new = vec_safe_length (new_row->reg_save);
kono
parents:
diff changeset
2184 n_max = MAX (n_old, n_new);
kono
parents:
diff changeset
2185
kono
parents:
diff changeset
2186 for (i = 0; i < n_max; ++i)
kono
parents:
diff changeset
2187 {
kono
parents:
diff changeset
2188 dw_cfi_ref r_old = NULL, r_new = NULL;
kono
parents:
diff changeset
2189
kono
parents:
diff changeset
2190 if (i < n_old)
kono
parents:
diff changeset
2191 r_old = (*old_row->reg_save)[i];
kono
parents:
diff changeset
2192 if (i < n_new)
kono
parents:
diff changeset
2193 r_new = (*new_row->reg_save)[i];
kono
parents:
diff changeset
2194
kono
parents:
diff changeset
2195 if (r_old == r_new)
kono
parents:
diff changeset
2196 ;
kono
parents:
diff changeset
2197 else if (r_new == NULL)
kono
parents:
diff changeset
2198 add_cfi_restore (i);
kono
parents:
diff changeset
2199 else if (!cfi_equal_p (r_old, r_new))
kono
parents:
diff changeset
2200 add_cfi (r_new);
kono
parents:
diff changeset
2201 }
kono
parents:
diff changeset
2202 }
kono
parents:
diff changeset
2203
kono
parents:
diff changeset
2204 /* Examine CFI and return true if a cfi label and set_loc is needed
kono
parents:
diff changeset
2205 beforehand. Even when generating CFI assembler instructions, we
kono
parents:
diff changeset
2206 still have to add the cfi to the list so that lookup_cfa_1 works
kono
parents:
diff changeset
2207 later on. When -g2 and above we even need to force emitting of
kono
parents:
diff changeset
2208 CFI labels and add to list a DW_CFA_set_loc for convert_cfa_to_fb_loc_list
kono
parents:
diff changeset
2209 purposes. If we're generating DWARF3 output we use DW_OP_call_frame_cfa
kono
parents:
diff changeset
2210 and so don't use convert_cfa_to_fb_loc_list. */
kono
parents:
diff changeset
2211
kono
parents:
diff changeset
2212 static bool
kono
parents:
diff changeset
2213 cfi_label_required_p (dw_cfi_ref cfi)
kono
parents:
diff changeset
2214 {
kono
parents:
diff changeset
2215 if (!dwarf2out_do_cfi_asm ())
kono
parents:
diff changeset
2216 return true;
kono
parents:
diff changeset
2217
kono
parents:
diff changeset
2218 if (dwarf_version == 2
kono
parents:
diff changeset
2219 && debug_info_level > DINFO_LEVEL_TERSE
kono
parents:
diff changeset
2220 && (write_symbols == DWARF2_DEBUG
kono
parents:
diff changeset
2221 || write_symbols == VMS_AND_DWARF2_DEBUG))
kono
parents:
diff changeset
2222 {
kono
parents:
diff changeset
2223 switch (cfi->dw_cfi_opc)
kono
parents:
diff changeset
2224 {
kono
parents:
diff changeset
2225 case DW_CFA_def_cfa_offset:
kono
parents:
diff changeset
2226 case DW_CFA_def_cfa_offset_sf:
kono
parents:
diff changeset
2227 case DW_CFA_def_cfa_register:
kono
parents:
diff changeset
2228 case DW_CFA_def_cfa:
kono
parents:
diff changeset
2229 case DW_CFA_def_cfa_sf:
kono
parents:
diff changeset
2230 case DW_CFA_def_cfa_expression:
kono
parents:
diff changeset
2231 case DW_CFA_restore_state:
kono
parents:
diff changeset
2232 return true;
kono
parents:
diff changeset
2233 default:
kono
parents:
diff changeset
2234 return false;
kono
parents:
diff changeset
2235 }
kono
parents:
diff changeset
2236 }
kono
parents:
diff changeset
2237 return false;
kono
parents:
diff changeset
2238 }
kono
parents:
diff changeset
2239
kono
parents:
diff changeset
2240 /* Walk the function, looking for NOTE_INSN_CFI notes. Add the CFIs to the
kono
parents:
diff changeset
2241 function's FDE, adding CFI labels and set_loc/advance_loc opcodes as
kono
parents:
diff changeset
2242 necessary. */
kono
parents:
diff changeset
2243 static void
kono
parents:
diff changeset
2244 add_cfis_to_fde (void)
kono
parents:
diff changeset
2245 {
kono
parents:
diff changeset
2246 dw_fde_ref fde = cfun->fde;
kono
parents:
diff changeset
2247 rtx_insn *insn, *next;
kono
parents:
diff changeset
2248
kono
parents:
diff changeset
2249 for (insn = get_insns (); insn; insn = next)
kono
parents:
diff changeset
2250 {
kono
parents:
diff changeset
2251 next = NEXT_INSN (insn);
kono
parents:
diff changeset
2252
kono
parents:
diff changeset
2253 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
kono
parents:
diff changeset
2254 fde->dw_fde_switch_cfi_index = vec_safe_length (fde->dw_fde_cfi);
kono
parents:
diff changeset
2255
kono
parents:
diff changeset
2256 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_CFI)
kono
parents:
diff changeset
2257 {
kono
parents:
diff changeset
2258 bool required = cfi_label_required_p (NOTE_CFI (insn));
kono
parents:
diff changeset
2259 while (next)
kono
parents:
diff changeset
2260 if (NOTE_P (next) && NOTE_KIND (next) == NOTE_INSN_CFI)
kono
parents:
diff changeset
2261 {
kono
parents:
diff changeset
2262 required |= cfi_label_required_p (NOTE_CFI (next));
kono
parents:
diff changeset
2263 next = NEXT_INSN (next);
kono
parents:
diff changeset
2264 }
kono
parents:
diff changeset
2265 else if (active_insn_p (next)
kono
parents:
diff changeset
2266 || (NOTE_P (next) && (NOTE_KIND (next)
kono
parents:
diff changeset
2267 == NOTE_INSN_SWITCH_TEXT_SECTIONS)))
kono
parents:
diff changeset
2268 break;
kono
parents:
diff changeset
2269 else
kono
parents:
diff changeset
2270 next = NEXT_INSN (next);
kono
parents:
diff changeset
2271 if (required)
kono
parents:
diff changeset
2272 {
kono
parents:
diff changeset
2273 int num = dwarf2out_cfi_label_num;
kono
parents:
diff changeset
2274 const char *label = dwarf2out_cfi_label ();
kono
parents:
diff changeset
2275 dw_cfi_ref xcfi;
kono
parents:
diff changeset
2276
kono
parents:
diff changeset
2277 /* Set the location counter to the new label. */
kono
parents:
diff changeset
2278 xcfi = new_cfi ();
kono
parents:
diff changeset
2279 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
kono
parents:
diff changeset
2280 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
kono
parents:
diff changeset
2281 vec_safe_push (fde->dw_fde_cfi, xcfi);
kono
parents:
diff changeset
2282
kono
parents:
diff changeset
2283 rtx_note *tmp = emit_note_before (NOTE_INSN_CFI_LABEL, insn);
kono
parents:
diff changeset
2284 NOTE_LABEL_NUMBER (tmp) = num;
kono
parents:
diff changeset
2285 }
kono
parents:
diff changeset
2286
kono
parents:
diff changeset
2287 do
kono
parents:
diff changeset
2288 {
kono
parents:
diff changeset
2289 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_CFI)
kono
parents:
diff changeset
2290 vec_safe_push (fde->dw_fde_cfi, NOTE_CFI (insn));
kono
parents:
diff changeset
2291 insn = NEXT_INSN (insn);
kono
parents:
diff changeset
2292 }
kono
parents:
diff changeset
2293 while (insn != next);
kono
parents:
diff changeset
2294 }
kono
parents:
diff changeset
2295 }
kono
parents:
diff changeset
2296 }
kono
parents:
diff changeset
2297
kono
parents:
diff changeset
2298 static void dump_cfi_row (FILE *f, dw_cfi_row *row);
kono
parents:
diff changeset
2299
kono
parents:
diff changeset
2300 /* If LABEL is the start of a trace, then initialize the state of that
kono
parents:
diff changeset
2301 trace from CUR_TRACE and CUR_ROW. */
kono
parents:
diff changeset
2302
kono
parents:
diff changeset
2303 static void
kono
parents:
diff changeset
2304 maybe_record_trace_start (rtx_insn *start, rtx_insn *origin)
kono
parents:
diff changeset
2305 {
kono
parents:
diff changeset
2306 dw_trace_info *ti;
kono
parents:
diff changeset
2307
kono
parents:
diff changeset
2308 ti = get_trace_info (start);
kono
parents:
diff changeset
2309 gcc_assert (ti != NULL);
kono
parents:
diff changeset
2310
kono
parents:
diff changeset
2311 if (dump_file)
kono
parents:
diff changeset
2312 {
kono
parents:
diff changeset
2313 fprintf (dump_file, " saw edge from trace %u to %u (via %s %d)\n",
kono
parents:
diff changeset
2314 cur_trace->id, ti->id,
kono
parents:
diff changeset
2315 (origin ? rtx_name[(int) GET_CODE (origin)] : "fallthru"),
kono
parents:
diff changeset
2316 (origin ? INSN_UID (origin) : 0));
kono
parents:
diff changeset
2317 }
kono
parents:
diff changeset
2318
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2319 poly_int64 args_size = cur_trace->end_true_args_size;
111
kono
parents:
diff changeset
2320 if (ti->beg_row == NULL)
kono
parents:
diff changeset
2321 {
kono
parents:
diff changeset
2322 /* This is the first time we've encountered this trace. Propagate
kono
parents:
diff changeset
2323 state across the edge and push the trace onto the work list. */
kono
parents:
diff changeset
2324 ti->beg_row = copy_cfi_row (cur_row);
kono
parents:
diff changeset
2325 ti->beg_true_args_size = args_size;
kono
parents:
diff changeset
2326
kono
parents:
diff changeset
2327 ti->cfa_store = cur_trace->cfa_store;
kono
parents:
diff changeset
2328 ti->cfa_temp = cur_trace->cfa_temp;
kono
parents:
diff changeset
2329 ti->regs_saved_in_regs = cur_trace->regs_saved_in_regs.copy ();
kono
parents:
diff changeset
2330
kono
parents:
diff changeset
2331 trace_work_list.safe_push (ti);
kono
parents:
diff changeset
2332
kono
parents:
diff changeset
2333 if (dump_file)
kono
parents:
diff changeset
2334 fprintf (dump_file, "\tpush trace %u to worklist\n", ti->id);
kono
parents:
diff changeset
2335 }
kono
parents:
diff changeset
2336 else
kono
parents:
diff changeset
2337 {
kono
parents:
diff changeset
2338
kono
parents:
diff changeset
2339 /* We ought to have the same state incoming to a given trace no
kono
parents:
diff changeset
2340 matter how we arrive at the trace. Anything else means we've
kono
parents:
diff changeset
2341 got some kind of optimization error. */
kono
parents:
diff changeset
2342 #if CHECKING_P
kono
parents:
diff changeset
2343 if (!cfi_row_equal_p (cur_row, ti->beg_row))
kono
parents:
diff changeset
2344 {
kono
parents:
diff changeset
2345 if (dump_file)
kono
parents:
diff changeset
2346 {
kono
parents:
diff changeset
2347 fprintf (dump_file, "Inconsistent CFI state!\n");
kono
parents:
diff changeset
2348 fprintf (dump_file, "SHOULD have:\n");
kono
parents:
diff changeset
2349 dump_cfi_row (dump_file, ti->beg_row);
kono
parents:
diff changeset
2350 fprintf (dump_file, "DO have:\n");
kono
parents:
diff changeset
2351 dump_cfi_row (dump_file, cur_row);
kono
parents:
diff changeset
2352 }
kono
parents:
diff changeset
2353
kono
parents:
diff changeset
2354 gcc_unreachable ();
kono
parents:
diff changeset
2355 }
kono
parents:
diff changeset
2356 #endif
kono
parents:
diff changeset
2357
kono
parents:
diff changeset
2358 /* The args_size is allowed to conflict if it isn't actually used. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2359 if (maybe_ne (ti->beg_true_args_size, args_size))
111
kono
parents:
diff changeset
2360 ti->args_size_undefined = true;
kono
parents:
diff changeset
2361 }
kono
parents:
diff changeset
2362 }
kono
parents:
diff changeset
2363
kono
parents:
diff changeset
2364 /* Similarly, but handle the args_size and CFA reset across EH
kono
parents:
diff changeset
2365 and non-local goto edges. */
kono
parents:
diff changeset
2366
kono
parents:
diff changeset
2367 static void
kono
parents:
diff changeset
2368 maybe_record_trace_start_abnormal (rtx_insn *start, rtx_insn *origin)
kono
parents:
diff changeset
2369 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2370 poly_int64 save_args_size, delta;
111
kono
parents:
diff changeset
2371 dw_cfa_location save_cfa;
kono
parents:
diff changeset
2372
kono
parents:
diff changeset
2373 save_args_size = cur_trace->end_true_args_size;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2374 if (known_eq (save_args_size, 0))
111
kono
parents:
diff changeset
2375 {
kono
parents:
diff changeset
2376 maybe_record_trace_start (start, origin);
kono
parents:
diff changeset
2377 return;
kono
parents:
diff changeset
2378 }
kono
parents:
diff changeset
2379
kono
parents:
diff changeset
2380 delta = -save_args_size;
kono
parents:
diff changeset
2381 cur_trace->end_true_args_size = 0;
kono
parents:
diff changeset
2382
kono
parents:
diff changeset
2383 save_cfa = cur_row->cfa;
kono
parents:
diff changeset
2384 if (cur_row->cfa.reg == dw_stack_pointer_regnum)
kono
parents:
diff changeset
2385 {
kono
parents:
diff changeset
2386 /* Convert a change in args_size (always a positive in the
kono
parents:
diff changeset
2387 direction of stack growth) to a change in stack pointer. */
kono
parents:
diff changeset
2388 if (!STACK_GROWS_DOWNWARD)
kono
parents:
diff changeset
2389 delta = -delta;
kono
parents:
diff changeset
2390
kono
parents:
diff changeset
2391 cur_row->cfa.offset += delta;
kono
parents:
diff changeset
2392 }
kono
parents:
diff changeset
2393
kono
parents:
diff changeset
2394 maybe_record_trace_start (start, origin);
kono
parents:
diff changeset
2395
kono
parents:
diff changeset
2396 cur_trace->end_true_args_size = save_args_size;
kono
parents:
diff changeset
2397 cur_row->cfa = save_cfa;
kono
parents:
diff changeset
2398 }
kono
parents:
diff changeset
2399
kono
parents:
diff changeset
2400 /* Propagate CUR_TRACE state to the destinations implied by INSN. */
kono
parents:
diff changeset
2401 /* ??? Sadly, this is in large part a duplicate of make_edges. */
kono
parents:
diff changeset
2402
kono
parents:
diff changeset
2403 static void
kono
parents:
diff changeset
2404 create_trace_edges (rtx_insn *insn)
kono
parents:
diff changeset
2405 {
kono
parents:
diff changeset
2406 rtx tmp;
kono
parents:
diff changeset
2407 int i, n;
kono
parents:
diff changeset
2408
kono
parents:
diff changeset
2409 if (JUMP_P (insn))
kono
parents:
diff changeset
2410 {
kono
parents:
diff changeset
2411 rtx_jump_table_data *table;
kono
parents:
diff changeset
2412
kono
parents:
diff changeset
2413 if (find_reg_note (insn, REG_NON_LOCAL_GOTO, NULL_RTX))
kono
parents:
diff changeset
2414 return;
kono
parents:
diff changeset
2415
kono
parents:
diff changeset
2416 if (tablejump_p (insn, NULL, &table))
kono
parents:
diff changeset
2417 {
kono
parents:
diff changeset
2418 rtvec vec = table->get_labels ();
kono
parents:
diff changeset
2419
kono
parents:
diff changeset
2420 n = GET_NUM_ELEM (vec);
kono
parents:
diff changeset
2421 for (i = 0; i < n; ++i)
kono
parents:
diff changeset
2422 {
kono
parents:
diff changeset
2423 rtx_insn *lab = as_a <rtx_insn *> (XEXP (RTVEC_ELT (vec, i), 0));
kono
parents:
diff changeset
2424 maybe_record_trace_start (lab, insn);
kono
parents:
diff changeset
2425 }
kono
parents:
diff changeset
2426 }
kono
parents:
diff changeset
2427 else if (computed_jump_p (insn))
kono
parents:
diff changeset
2428 {
kono
parents:
diff changeset
2429 rtx_insn *temp;
kono
parents:
diff changeset
2430 unsigned int i;
kono
parents:
diff changeset
2431 FOR_EACH_VEC_SAFE_ELT (forced_labels, i, temp)
kono
parents:
diff changeset
2432 maybe_record_trace_start (temp, insn);
kono
parents:
diff changeset
2433 }
kono
parents:
diff changeset
2434 else if (returnjump_p (insn))
kono
parents:
diff changeset
2435 ;
kono
parents:
diff changeset
2436 else if ((tmp = extract_asm_operands (PATTERN (insn))) != NULL)
kono
parents:
diff changeset
2437 {
kono
parents:
diff changeset
2438 n = ASM_OPERANDS_LABEL_LENGTH (tmp);
kono
parents:
diff changeset
2439 for (i = 0; i < n; ++i)
kono
parents:
diff changeset
2440 {
kono
parents:
diff changeset
2441 rtx_insn *lab =
kono
parents:
diff changeset
2442 as_a <rtx_insn *> (XEXP (ASM_OPERANDS_LABEL (tmp, i), 0));
kono
parents:
diff changeset
2443 maybe_record_trace_start (lab, insn);
kono
parents:
diff changeset
2444 }
kono
parents:
diff changeset
2445 }
kono
parents:
diff changeset
2446 else
kono
parents:
diff changeset
2447 {
kono
parents:
diff changeset
2448 rtx_insn *lab = JUMP_LABEL_AS_INSN (insn);
kono
parents:
diff changeset
2449 gcc_assert (lab != NULL);
kono
parents:
diff changeset
2450 maybe_record_trace_start (lab, insn);
kono
parents:
diff changeset
2451 }
kono
parents:
diff changeset
2452 }
kono
parents:
diff changeset
2453 else if (CALL_P (insn))
kono
parents:
diff changeset
2454 {
kono
parents:
diff changeset
2455 /* Sibling calls don't have edges inside this function. */
kono
parents:
diff changeset
2456 if (SIBLING_CALL_P (insn))
kono
parents:
diff changeset
2457 return;
kono
parents:
diff changeset
2458
kono
parents:
diff changeset
2459 /* Process non-local goto edges. */
kono
parents:
diff changeset
2460 if (can_nonlocal_goto (insn))
kono
parents:
diff changeset
2461 for (rtx_insn_list *lab = nonlocal_goto_handler_labels;
kono
parents:
diff changeset
2462 lab;
kono
parents:
diff changeset
2463 lab = lab->next ())
kono
parents:
diff changeset
2464 maybe_record_trace_start_abnormal (lab->insn (), insn);
kono
parents:
diff changeset
2465 }
kono
parents:
diff changeset
2466 else if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
kono
parents:
diff changeset
2467 {
kono
parents:
diff changeset
2468 int i, n = seq->len ();
kono
parents:
diff changeset
2469 for (i = 0; i < n; ++i)
kono
parents:
diff changeset
2470 create_trace_edges (seq->insn (i));
kono
parents:
diff changeset
2471 return;
kono
parents:
diff changeset
2472 }
kono
parents:
diff changeset
2473
kono
parents:
diff changeset
2474 /* Process EH edges. */
kono
parents:
diff changeset
2475 if (CALL_P (insn) || cfun->can_throw_non_call_exceptions)
kono
parents:
diff changeset
2476 {
kono
parents:
diff changeset
2477 eh_landing_pad lp = get_eh_landing_pad_from_rtx (insn);
kono
parents:
diff changeset
2478 if (lp)
kono
parents:
diff changeset
2479 maybe_record_trace_start_abnormal (lp->landing_pad, insn);
kono
parents:
diff changeset
2480 }
kono
parents:
diff changeset
2481 }
kono
parents:
diff changeset
2482
kono
parents:
diff changeset
2483 /* A subroutine of scan_trace. Do what needs to be done "after" INSN. */
kono
parents:
diff changeset
2484
kono
parents:
diff changeset
2485 static void
kono
parents:
diff changeset
2486 scan_insn_after (rtx_insn *insn)
kono
parents:
diff changeset
2487 {
kono
parents:
diff changeset
2488 if (RTX_FRAME_RELATED_P (insn))
kono
parents:
diff changeset
2489 dwarf2out_frame_debug (insn);
kono
parents:
diff changeset
2490 notice_args_size (insn);
kono
parents:
diff changeset
2491 }
kono
parents:
diff changeset
2492
kono
parents:
diff changeset
2493 /* Scan the trace beginning at INSN and create the CFI notes for the
kono
parents:
diff changeset
2494 instructions therein. */
kono
parents:
diff changeset
2495
kono
parents:
diff changeset
2496 static void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2497 scan_trace (dw_trace_info *trace, bool entry)
111
kono
parents:
diff changeset
2498 {
kono
parents:
diff changeset
2499 rtx_insn *prev, *insn = trace->head;
kono
parents:
diff changeset
2500 dw_cfa_location this_cfa;
kono
parents:
diff changeset
2501
kono
parents:
diff changeset
2502 if (dump_file)
kono
parents:
diff changeset
2503 fprintf (dump_file, "Processing trace %u : start at %s %d\n",
kono
parents:
diff changeset
2504 trace->id, rtx_name[(int) GET_CODE (insn)],
kono
parents:
diff changeset
2505 INSN_UID (insn));
kono
parents:
diff changeset
2506
kono
parents:
diff changeset
2507 trace->end_row = copy_cfi_row (trace->beg_row);
kono
parents:
diff changeset
2508 trace->end_true_args_size = trace->beg_true_args_size;
kono
parents:
diff changeset
2509
kono
parents:
diff changeset
2510 cur_trace = trace;
kono
parents:
diff changeset
2511 cur_row = trace->end_row;
kono
parents:
diff changeset
2512
kono
parents:
diff changeset
2513 this_cfa = cur_row->cfa;
kono
parents:
diff changeset
2514 cur_cfa = &this_cfa;
kono
parents:
diff changeset
2515
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2516 /* If the current function starts with a non-standard incoming frame
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2517 sp offset, emit a note before the first instruction. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2518 if (entry
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2519 && DEFAULT_INCOMING_FRAME_SP_OFFSET != INCOMING_FRAME_SP_OFFSET)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2520 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2521 add_cfi_insn = insn;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2522 gcc_assert (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_DELETED);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2523 this_cfa.offset = INCOMING_FRAME_SP_OFFSET;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2524 def_cfa_1 (&this_cfa);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2525 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2526
111
kono
parents:
diff changeset
2527 for (prev = insn, insn = NEXT_INSN (insn);
kono
parents:
diff changeset
2528 insn;
kono
parents:
diff changeset
2529 prev = insn, insn = NEXT_INSN (insn))
kono
parents:
diff changeset
2530 {
kono
parents:
diff changeset
2531 rtx_insn *control;
kono
parents:
diff changeset
2532
kono
parents:
diff changeset
2533 /* Do everything that happens "before" the insn. */
kono
parents:
diff changeset
2534 add_cfi_insn = prev;
kono
parents:
diff changeset
2535
kono
parents:
diff changeset
2536 /* Notice the end of a trace. */
kono
parents:
diff changeset
2537 if (BARRIER_P (insn))
kono
parents:
diff changeset
2538 {
kono
parents:
diff changeset
2539 /* Don't bother saving the unneeded queued registers at all. */
kono
parents:
diff changeset
2540 queued_reg_saves.truncate (0);
kono
parents:
diff changeset
2541 break;
kono
parents:
diff changeset
2542 }
kono
parents:
diff changeset
2543 if (save_point_p (insn))
kono
parents:
diff changeset
2544 {
kono
parents:
diff changeset
2545 /* Propagate across fallthru edges. */
kono
parents:
diff changeset
2546 dwarf2out_flush_queued_reg_saves ();
kono
parents:
diff changeset
2547 maybe_record_trace_start (insn, NULL);
kono
parents:
diff changeset
2548 break;
kono
parents:
diff changeset
2549 }
kono
parents:
diff changeset
2550
kono
parents:
diff changeset
2551 if (DEBUG_INSN_P (insn) || !inside_basic_block_p (insn))
kono
parents:
diff changeset
2552 continue;
kono
parents:
diff changeset
2553
kono
parents:
diff changeset
2554 /* Handle all changes to the row state. Sequences require special
kono
parents:
diff changeset
2555 handling for the positioning of the notes. */
kono
parents:
diff changeset
2556 if (rtx_sequence *pat = dyn_cast <rtx_sequence *> (PATTERN (insn)))
kono
parents:
diff changeset
2557 {
kono
parents:
diff changeset
2558 rtx_insn *elt;
kono
parents:
diff changeset
2559 int i, n = pat->len ();
kono
parents:
diff changeset
2560
kono
parents:
diff changeset
2561 control = pat->insn (0);
kono
parents:
diff changeset
2562 if (can_throw_internal (control))
kono
parents:
diff changeset
2563 notice_eh_throw (control);
kono
parents:
diff changeset
2564 dwarf2out_flush_queued_reg_saves ();
kono
parents:
diff changeset
2565
kono
parents:
diff changeset
2566 if (JUMP_P (control) && INSN_ANNULLED_BRANCH_P (control))
kono
parents:
diff changeset
2567 {
kono
parents:
diff changeset
2568 /* ??? Hopefully multiple delay slots are not annulled. */
kono
parents:
diff changeset
2569 gcc_assert (n == 2);
kono
parents:
diff changeset
2570 gcc_assert (!RTX_FRAME_RELATED_P (control));
kono
parents:
diff changeset
2571 gcc_assert (!find_reg_note (control, REG_ARGS_SIZE, NULL));
kono
parents:
diff changeset
2572
kono
parents:
diff changeset
2573 elt = pat->insn (1);
kono
parents:
diff changeset
2574
kono
parents:
diff changeset
2575 if (INSN_FROM_TARGET_P (elt))
kono
parents:
diff changeset
2576 {
kono
parents:
diff changeset
2577 cfi_vec save_row_reg_save;
kono
parents:
diff changeset
2578
kono
parents:
diff changeset
2579 /* If ELT is an instruction from target of an annulled
kono
parents:
diff changeset
2580 branch, the effects are for the target only and so
kono
parents:
diff changeset
2581 the args_size and CFA along the current path
kono
parents:
diff changeset
2582 shouldn't change. */
kono
parents:
diff changeset
2583 add_cfi_insn = NULL;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2584 poly_int64 restore_args_size = cur_trace->end_true_args_size;
111
kono
parents:
diff changeset
2585 cur_cfa = &cur_row->cfa;
kono
parents:
diff changeset
2586 save_row_reg_save = vec_safe_copy (cur_row->reg_save);
kono
parents:
diff changeset
2587
kono
parents:
diff changeset
2588 scan_insn_after (elt);
kono
parents:
diff changeset
2589
kono
parents:
diff changeset
2590 /* ??? Should we instead save the entire row state? */
kono
parents:
diff changeset
2591 gcc_assert (!queued_reg_saves.length ());
kono
parents:
diff changeset
2592
kono
parents:
diff changeset
2593 create_trace_edges (control);
kono
parents:
diff changeset
2594
kono
parents:
diff changeset
2595 cur_trace->end_true_args_size = restore_args_size;
kono
parents:
diff changeset
2596 cur_row->cfa = this_cfa;
kono
parents:
diff changeset
2597 cur_row->reg_save = save_row_reg_save;
kono
parents:
diff changeset
2598 cur_cfa = &this_cfa;
kono
parents:
diff changeset
2599 }
kono
parents:
diff changeset
2600 else
kono
parents:
diff changeset
2601 {
kono
parents:
diff changeset
2602 /* If ELT is a annulled branch-taken instruction (i.e.
kono
parents:
diff changeset
2603 executed only when branch is not taken), the args_size
kono
parents:
diff changeset
2604 and CFA should not change through the jump. */
kono
parents:
diff changeset
2605 create_trace_edges (control);
kono
parents:
diff changeset
2606
kono
parents:
diff changeset
2607 /* Update and continue with the trace. */
kono
parents:
diff changeset
2608 add_cfi_insn = insn;
kono
parents:
diff changeset
2609 scan_insn_after (elt);
kono
parents:
diff changeset
2610 def_cfa_1 (&this_cfa);
kono
parents:
diff changeset
2611 }
kono
parents:
diff changeset
2612 continue;
kono
parents:
diff changeset
2613 }
kono
parents:
diff changeset
2614
kono
parents:
diff changeset
2615 /* The insns in the delay slot should all be considered to happen
kono
parents:
diff changeset
2616 "before" a call insn. Consider a call with a stack pointer
kono
parents:
diff changeset
2617 adjustment in the delay slot. The backtrace from the callee
kono
parents:
diff changeset
2618 should include the sp adjustment. Unfortunately, that leaves
kono
parents:
diff changeset
2619 us with an unavoidable unwinding error exactly at the call insn
kono
parents:
diff changeset
2620 itself. For jump insns we'd prefer to avoid this error by
kono
parents:
diff changeset
2621 placing the notes after the sequence. */
kono
parents:
diff changeset
2622 if (JUMP_P (control))
kono
parents:
diff changeset
2623 add_cfi_insn = insn;
kono
parents:
diff changeset
2624
kono
parents:
diff changeset
2625 for (i = 1; i < n; ++i)
kono
parents:
diff changeset
2626 {
kono
parents:
diff changeset
2627 elt = pat->insn (i);
kono
parents:
diff changeset
2628 scan_insn_after (elt);
kono
parents:
diff changeset
2629 }
kono
parents:
diff changeset
2630
kono
parents:
diff changeset
2631 /* Make sure any register saves are visible at the jump target. */
kono
parents:
diff changeset
2632 dwarf2out_flush_queued_reg_saves ();
kono
parents:
diff changeset
2633 any_cfis_emitted = false;
kono
parents:
diff changeset
2634
kono
parents:
diff changeset
2635 /* However, if there is some adjustment on the call itself, e.g.
kono
parents:
diff changeset
2636 a call_pop, that action should be considered to happen after
kono
parents:
diff changeset
2637 the call returns. */
kono
parents:
diff changeset
2638 add_cfi_insn = insn;
kono
parents:
diff changeset
2639 scan_insn_after (control);
kono
parents:
diff changeset
2640 }
kono
parents:
diff changeset
2641 else
kono
parents:
diff changeset
2642 {
kono
parents:
diff changeset
2643 /* Flush data before calls and jumps, and of course if necessary. */
kono
parents:
diff changeset
2644 if (can_throw_internal (insn))
kono
parents:
diff changeset
2645 {
kono
parents:
diff changeset
2646 notice_eh_throw (insn);
kono
parents:
diff changeset
2647 dwarf2out_flush_queued_reg_saves ();
kono
parents:
diff changeset
2648 }
kono
parents:
diff changeset
2649 else if (!NONJUMP_INSN_P (insn)
kono
parents:
diff changeset
2650 || clobbers_queued_reg_save (insn)
kono
parents:
diff changeset
2651 || find_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL))
kono
parents:
diff changeset
2652 dwarf2out_flush_queued_reg_saves ();
kono
parents:
diff changeset
2653 any_cfis_emitted = false;
kono
parents:
diff changeset
2654
kono
parents:
diff changeset
2655 add_cfi_insn = insn;
kono
parents:
diff changeset
2656 scan_insn_after (insn);
kono
parents:
diff changeset
2657 control = insn;
kono
parents:
diff changeset
2658 }
kono
parents:
diff changeset
2659
kono
parents:
diff changeset
2660 /* Between frame-related-p and args_size we might have otherwise
kono
parents:
diff changeset
2661 emitted two cfa adjustments. Do it now. */
kono
parents:
diff changeset
2662 def_cfa_1 (&this_cfa);
kono
parents:
diff changeset
2663
kono
parents:
diff changeset
2664 /* Minimize the number of advances by emitting the entire queue
kono
parents:
diff changeset
2665 once anything is emitted. */
kono
parents:
diff changeset
2666 if (any_cfis_emitted
kono
parents:
diff changeset
2667 || find_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL))
kono
parents:
diff changeset
2668 dwarf2out_flush_queued_reg_saves ();
kono
parents:
diff changeset
2669
kono
parents:
diff changeset
2670 /* Note that a test for control_flow_insn_p does exactly the
kono
parents:
diff changeset
2671 same tests as are done to actually create the edges. So
kono
parents:
diff changeset
2672 always call the routine and let it not create edges for
kono
parents:
diff changeset
2673 non-control-flow insns. */
kono
parents:
diff changeset
2674 create_trace_edges (control);
kono
parents:
diff changeset
2675 }
kono
parents:
diff changeset
2676
kono
parents:
diff changeset
2677 add_cfi_insn = NULL;
kono
parents:
diff changeset
2678 cur_row = NULL;
kono
parents:
diff changeset
2679 cur_trace = NULL;
kono
parents:
diff changeset
2680 cur_cfa = NULL;
kono
parents:
diff changeset
2681 }
kono
parents:
diff changeset
2682
kono
parents:
diff changeset
2683 /* Scan the function and create the initial set of CFI notes. */
kono
parents:
diff changeset
2684
kono
parents:
diff changeset
2685 static void
kono
parents:
diff changeset
2686 create_cfi_notes (void)
kono
parents:
diff changeset
2687 {
kono
parents:
diff changeset
2688 dw_trace_info *ti;
kono
parents:
diff changeset
2689
kono
parents:
diff changeset
2690 gcc_checking_assert (!queued_reg_saves.exists ());
kono
parents:
diff changeset
2691 gcc_checking_assert (!trace_work_list.exists ());
kono
parents:
diff changeset
2692
kono
parents:
diff changeset
2693 /* Always begin at the entry trace. */
kono
parents:
diff changeset
2694 ti = &trace_info[0];
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2695 scan_trace (ti, true);
111
kono
parents:
diff changeset
2696
kono
parents:
diff changeset
2697 while (!trace_work_list.is_empty ())
kono
parents:
diff changeset
2698 {
kono
parents:
diff changeset
2699 ti = trace_work_list.pop ();
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2700 scan_trace (ti, false);
111
kono
parents:
diff changeset
2701 }
kono
parents:
diff changeset
2702
kono
parents:
diff changeset
2703 queued_reg_saves.release ();
kono
parents:
diff changeset
2704 trace_work_list.release ();
kono
parents:
diff changeset
2705 }
kono
parents:
diff changeset
2706
kono
parents:
diff changeset
2707 /* Return the insn before the first NOTE_INSN_CFI after START. */
kono
parents:
diff changeset
2708
kono
parents:
diff changeset
2709 static rtx_insn *
kono
parents:
diff changeset
2710 before_next_cfi_note (rtx_insn *start)
kono
parents:
diff changeset
2711 {
kono
parents:
diff changeset
2712 rtx_insn *prev = start;
kono
parents:
diff changeset
2713 while (start)
kono
parents:
diff changeset
2714 {
kono
parents:
diff changeset
2715 if (NOTE_P (start) && NOTE_KIND (start) == NOTE_INSN_CFI)
kono
parents:
diff changeset
2716 return prev;
kono
parents:
diff changeset
2717 prev = start;
kono
parents:
diff changeset
2718 start = NEXT_INSN (start);
kono
parents:
diff changeset
2719 }
kono
parents:
diff changeset
2720 gcc_unreachable ();
kono
parents:
diff changeset
2721 }
kono
parents:
diff changeset
2722
kono
parents:
diff changeset
2723 /* Insert CFI notes between traces to properly change state between them. */
kono
parents:
diff changeset
2724
kono
parents:
diff changeset
2725 static void
kono
parents:
diff changeset
2726 connect_traces (void)
kono
parents:
diff changeset
2727 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2728 unsigned i, n;
111
kono
parents:
diff changeset
2729 dw_trace_info *prev_ti, *ti;
kono
parents:
diff changeset
2730
kono
parents:
diff changeset
2731 /* ??? Ideally, we should have both queued and processed every trace.
kono
parents:
diff changeset
2732 However the current representation of constant pools on various targets
kono
parents:
diff changeset
2733 is indistinguishable from unreachable code. Assume for the moment that
kono
parents:
diff changeset
2734 we can simply skip over such traces. */
kono
parents:
diff changeset
2735 /* ??? Consider creating a DATA_INSN rtx code to indicate that
kono
parents:
diff changeset
2736 these are not "real" instructions, and should not be considered.
kono
parents:
diff changeset
2737 This could be generically useful for tablejump data as well. */
kono
parents:
diff changeset
2738 /* Remove all unprocessed traces from the list. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2739 unsigned ix, ix2;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2740 VEC_ORDERED_REMOVE_IF_FROM_TO (trace_info, ix, ix2, ti, 1,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2741 trace_info.length (), ti->beg_row == NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2742 FOR_EACH_VEC_ELT (trace_info, ix, ti)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2743 gcc_assert (ti->end_row != NULL);
111
kono
parents:
diff changeset
2744
kono
parents:
diff changeset
2745 /* Work from the end back to the beginning. This lets us easily insert
kono
parents:
diff changeset
2746 remember/restore_state notes in the correct order wrt other notes. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2747 n = trace_info.length ();
111
kono
parents:
diff changeset
2748 prev_ti = &trace_info[n - 1];
kono
parents:
diff changeset
2749 for (i = n - 1; i > 0; --i)
kono
parents:
diff changeset
2750 {
kono
parents:
diff changeset
2751 dw_cfi_row *old_row;
kono
parents:
diff changeset
2752
kono
parents:
diff changeset
2753 ti = prev_ti;
kono
parents:
diff changeset
2754 prev_ti = &trace_info[i - 1];
kono
parents:
diff changeset
2755
kono
parents:
diff changeset
2756 add_cfi_insn = ti->head;
kono
parents:
diff changeset
2757
kono
parents:
diff changeset
2758 /* In dwarf2out_switch_text_section, we'll begin a new FDE
kono
parents:
diff changeset
2759 for the portion of the function in the alternate text
kono
parents:
diff changeset
2760 section. The row state at the very beginning of that
kono
parents:
diff changeset
2761 new FDE will be exactly the row state from the CIE. */
kono
parents:
diff changeset
2762 if (ti->switch_sections)
kono
parents:
diff changeset
2763 old_row = cie_cfi_row;
kono
parents:
diff changeset
2764 else
kono
parents:
diff changeset
2765 {
kono
parents:
diff changeset
2766 old_row = prev_ti->end_row;
kono
parents:
diff changeset
2767 /* If there's no change from the previous end state, fine. */
kono
parents:
diff changeset
2768 if (cfi_row_equal_p (old_row, ti->beg_row))
kono
parents:
diff changeset
2769 ;
kono
parents:
diff changeset
2770 /* Otherwise check for the common case of sharing state with
kono
parents:
diff changeset
2771 the beginning of an epilogue, but not the end. Insert
kono
parents:
diff changeset
2772 remember/restore opcodes in that case. */
kono
parents:
diff changeset
2773 else if (cfi_row_equal_p (prev_ti->beg_row, ti->beg_row))
kono
parents:
diff changeset
2774 {
kono
parents:
diff changeset
2775 dw_cfi_ref cfi;
kono
parents:
diff changeset
2776
kono
parents:
diff changeset
2777 /* Note that if we blindly insert the remember at the
kono
parents:
diff changeset
2778 start of the trace, we can wind up increasing the
kono
parents:
diff changeset
2779 size of the unwind info due to extra advance opcodes.
kono
parents:
diff changeset
2780 Instead, put the remember immediately before the next
kono
parents:
diff changeset
2781 state change. We know there must be one, because the
kono
parents:
diff changeset
2782 state at the beginning and head of the trace differ. */
kono
parents:
diff changeset
2783 add_cfi_insn = before_next_cfi_note (prev_ti->head);
kono
parents:
diff changeset
2784 cfi = new_cfi ();
kono
parents:
diff changeset
2785 cfi->dw_cfi_opc = DW_CFA_remember_state;
kono
parents:
diff changeset
2786 add_cfi (cfi);
kono
parents:
diff changeset
2787
kono
parents:
diff changeset
2788 add_cfi_insn = ti->head;
kono
parents:
diff changeset
2789 cfi = new_cfi ();
kono
parents:
diff changeset
2790 cfi->dw_cfi_opc = DW_CFA_restore_state;
kono
parents:
diff changeset
2791 add_cfi (cfi);
kono
parents:
diff changeset
2792
kono
parents:
diff changeset
2793 old_row = prev_ti->beg_row;
kono
parents:
diff changeset
2794 }
kono
parents:
diff changeset
2795 /* Otherwise, we'll simply change state from the previous end. */
kono
parents:
diff changeset
2796 }
kono
parents:
diff changeset
2797
kono
parents:
diff changeset
2798 change_cfi_row (old_row, ti->beg_row);
kono
parents:
diff changeset
2799
kono
parents:
diff changeset
2800 if (dump_file && add_cfi_insn != ti->head)
kono
parents:
diff changeset
2801 {
kono
parents:
diff changeset
2802 rtx_insn *note;
kono
parents:
diff changeset
2803
kono
parents:
diff changeset
2804 fprintf (dump_file, "Fixup between trace %u and %u:\n",
kono
parents:
diff changeset
2805 prev_ti->id, ti->id);
kono
parents:
diff changeset
2806
kono
parents:
diff changeset
2807 note = ti->head;
kono
parents:
diff changeset
2808 do
kono
parents:
diff changeset
2809 {
kono
parents:
diff changeset
2810 note = NEXT_INSN (note);
kono
parents:
diff changeset
2811 gcc_assert (NOTE_P (note) && NOTE_KIND (note) == NOTE_INSN_CFI);
kono
parents:
diff changeset
2812 output_cfi_directive (dump_file, NOTE_CFI (note));
kono
parents:
diff changeset
2813 }
kono
parents:
diff changeset
2814 while (note != add_cfi_insn);
kono
parents:
diff changeset
2815 }
kono
parents:
diff changeset
2816 }
kono
parents:
diff changeset
2817
kono
parents:
diff changeset
2818 /* Connect args_size between traces that have can_throw_internal insns. */
kono
parents:
diff changeset
2819 if (cfun->eh->lp_array)
kono
parents:
diff changeset
2820 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2821 poly_int64 prev_args_size = 0;
111
kono
parents:
diff changeset
2822
kono
parents:
diff changeset
2823 for (i = 0; i < n; ++i)
kono
parents:
diff changeset
2824 {
kono
parents:
diff changeset
2825 ti = &trace_info[i];
kono
parents:
diff changeset
2826
kono
parents:
diff changeset
2827 if (ti->switch_sections)
kono
parents:
diff changeset
2828 prev_args_size = 0;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2829
111
kono
parents:
diff changeset
2830 if (ti->eh_head == NULL)
kono
parents:
diff changeset
2831 continue;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2832
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2833 /* We require either the incoming args_size values to match or the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2834 presence of an insn setting it before the first EH insn. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2835 gcc_assert (!ti->args_size_undefined || ti->args_size_defined_for_eh);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2836
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2837 /* In the latter case, we force the creation of a CFI note. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2838 if (ti->args_size_undefined
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2839 || maybe_ne (ti->beg_delay_args_size, prev_args_size))
111
kono
parents:
diff changeset
2840 {
kono
parents:
diff changeset
2841 /* ??? Search back to previous CFI note. */
kono
parents:
diff changeset
2842 add_cfi_insn = PREV_INSN (ti->eh_head);
kono
parents:
diff changeset
2843 add_cfi_args_size (ti->beg_delay_args_size);
kono
parents:
diff changeset
2844 }
kono
parents:
diff changeset
2845
kono
parents:
diff changeset
2846 prev_args_size = ti->end_delay_args_size;
kono
parents:
diff changeset
2847 }
kono
parents:
diff changeset
2848 }
kono
parents:
diff changeset
2849 }
kono
parents:
diff changeset
2850
kono
parents:
diff changeset
2851 /* Set up the pseudo-cfg of instruction traces, as described at the
kono
parents:
diff changeset
2852 block comment at the top of the file. */
kono
parents:
diff changeset
2853
kono
parents:
diff changeset
2854 static void
kono
parents:
diff changeset
2855 create_pseudo_cfg (void)
kono
parents:
diff changeset
2856 {
kono
parents:
diff changeset
2857 bool saw_barrier, switch_sections;
kono
parents:
diff changeset
2858 dw_trace_info ti;
kono
parents:
diff changeset
2859 rtx_insn *insn;
kono
parents:
diff changeset
2860 unsigned i;
kono
parents:
diff changeset
2861
kono
parents:
diff changeset
2862 /* The first trace begins at the start of the function,
kono
parents:
diff changeset
2863 and begins with the CIE row state. */
kono
parents:
diff changeset
2864 trace_info.create (16);
kono
parents:
diff changeset
2865 memset (&ti, 0, sizeof (ti));
kono
parents:
diff changeset
2866 ti.head = get_insns ();
kono
parents:
diff changeset
2867 ti.beg_row = cie_cfi_row;
kono
parents:
diff changeset
2868 ti.cfa_store = cie_cfi_row->cfa;
kono
parents:
diff changeset
2869 ti.cfa_temp.reg = INVALID_REGNUM;
kono
parents:
diff changeset
2870 trace_info.quick_push (ti);
kono
parents:
diff changeset
2871
kono
parents:
diff changeset
2872 if (cie_return_save)
kono
parents:
diff changeset
2873 ti.regs_saved_in_regs.safe_push (*cie_return_save);
kono
parents:
diff changeset
2874
kono
parents:
diff changeset
2875 /* Walk all the insns, collecting start of trace locations. */
kono
parents:
diff changeset
2876 saw_barrier = false;
kono
parents:
diff changeset
2877 switch_sections = false;
kono
parents:
diff changeset
2878 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
kono
parents:
diff changeset
2879 {
kono
parents:
diff changeset
2880 if (BARRIER_P (insn))
kono
parents:
diff changeset
2881 saw_barrier = true;
kono
parents:
diff changeset
2882 else if (NOTE_P (insn)
kono
parents:
diff changeset
2883 && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
kono
parents:
diff changeset
2884 {
kono
parents:
diff changeset
2885 /* We should have just seen a barrier. */
kono
parents:
diff changeset
2886 gcc_assert (saw_barrier);
kono
parents:
diff changeset
2887 switch_sections = true;
kono
parents:
diff changeset
2888 }
kono
parents:
diff changeset
2889 /* Watch out for save_point notes between basic blocks.
kono
parents:
diff changeset
2890 In particular, a note after a barrier. Do not record these,
kono
parents:
diff changeset
2891 delaying trace creation until the label. */
kono
parents:
diff changeset
2892 else if (save_point_p (insn)
kono
parents:
diff changeset
2893 && (LABEL_P (insn) || !saw_barrier))
kono
parents:
diff changeset
2894 {
kono
parents:
diff changeset
2895 memset (&ti, 0, sizeof (ti));
kono
parents:
diff changeset
2896 ti.head = insn;
kono
parents:
diff changeset
2897 ti.switch_sections = switch_sections;
kono
parents:
diff changeset
2898 ti.id = trace_info.length ();
kono
parents:
diff changeset
2899 trace_info.safe_push (ti);
kono
parents:
diff changeset
2900
kono
parents:
diff changeset
2901 saw_barrier = false;
kono
parents:
diff changeset
2902 switch_sections = false;
kono
parents:
diff changeset
2903 }
kono
parents:
diff changeset
2904 }
kono
parents:
diff changeset
2905
kono
parents:
diff changeset
2906 /* Create the trace index after we've finished building trace_info,
kono
parents:
diff changeset
2907 avoiding stale pointer problems due to reallocation. */
kono
parents:
diff changeset
2908 trace_index
kono
parents:
diff changeset
2909 = new hash_table<trace_info_hasher> (trace_info.length ());
kono
parents:
diff changeset
2910 dw_trace_info *tp;
kono
parents:
diff changeset
2911 FOR_EACH_VEC_ELT (trace_info, i, tp)
kono
parents:
diff changeset
2912 {
kono
parents:
diff changeset
2913 dw_trace_info **slot;
kono
parents:
diff changeset
2914
kono
parents:
diff changeset
2915 if (dump_file)
kono
parents:
diff changeset
2916 fprintf (dump_file, "Creating trace %u : start at %s %d%s\n", tp->id,
kono
parents:
diff changeset
2917 rtx_name[(int) GET_CODE (tp->head)], INSN_UID (tp->head),
kono
parents:
diff changeset
2918 tp->switch_sections ? " (section switch)" : "");
kono
parents:
diff changeset
2919
kono
parents:
diff changeset
2920 slot = trace_index->find_slot_with_hash (tp, INSN_UID (tp->head), INSERT);
kono
parents:
diff changeset
2921 gcc_assert (*slot == NULL);
kono
parents:
diff changeset
2922 *slot = tp;
kono
parents:
diff changeset
2923 }
kono
parents:
diff changeset
2924 }
kono
parents:
diff changeset
2925
kono
parents:
diff changeset
2926 /* Record the initial position of the return address. RTL is
kono
parents:
diff changeset
2927 INCOMING_RETURN_ADDR_RTX. */
kono
parents:
diff changeset
2928
kono
parents:
diff changeset
2929 static void
kono
parents:
diff changeset
2930 initial_return_save (rtx rtl)
kono
parents:
diff changeset
2931 {
kono
parents:
diff changeset
2932 unsigned int reg = INVALID_REGNUM;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2933 poly_int64 offset = 0;
111
kono
parents:
diff changeset
2934
kono
parents:
diff changeset
2935 switch (GET_CODE (rtl))
kono
parents:
diff changeset
2936 {
kono
parents:
diff changeset
2937 case REG:
kono
parents:
diff changeset
2938 /* RA is in a register. */
kono
parents:
diff changeset
2939 reg = dwf_regno (rtl);
kono
parents:
diff changeset
2940 break;
kono
parents:
diff changeset
2941
kono
parents:
diff changeset
2942 case MEM:
kono
parents:
diff changeset
2943 /* RA is on the stack. */
kono
parents:
diff changeset
2944 rtl = XEXP (rtl, 0);
kono
parents:
diff changeset
2945 switch (GET_CODE (rtl))
kono
parents:
diff changeset
2946 {
kono
parents:
diff changeset
2947 case REG:
kono
parents:
diff changeset
2948 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
kono
parents:
diff changeset
2949 offset = 0;
kono
parents:
diff changeset
2950 break;
kono
parents:
diff changeset
2951
kono
parents:
diff changeset
2952 case PLUS:
kono
parents:
diff changeset
2953 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2954 offset = rtx_to_poly_int64 (XEXP (rtl, 1));
111
kono
parents:
diff changeset
2955 break;
kono
parents:
diff changeset
2956
kono
parents:
diff changeset
2957 case MINUS:
kono
parents:
diff changeset
2958 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2959 offset = -rtx_to_poly_int64 (XEXP (rtl, 1));
111
kono
parents:
diff changeset
2960 break;
kono
parents:
diff changeset
2961
kono
parents:
diff changeset
2962 default:
kono
parents:
diff changeset
2963 gcc_unreachable ();
kono
parents:
diff changeset
2964 }
kono
parents:
diff changeset
2965
kono
parents:
diff changeset
2966 break;
kono
parents:
diff changeset
2967
kono
parents:
diff changeset
2968 case PLUS:
kono
parents:
diff changeset
2969 /* The return address is at some offset from any value we can
kono
parents:
diff changeset
2970 actually load. For instance, on the SPARC it is in %i7+8. Just
kono
parents:
diff changeset
2971 ignore the offset for now; it doesn't matter for unwinding frames. */
kono
parents:
diff changeset
2972 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
kono
parents:
diff changeset
2973 initial_return_save (XEXP (rtl, 0));
kono
parents:
diff changeset
2974 return;
kono
parents:
diff changeset
2975
kono
parents:
diff changeset
2976 default:
kono
parents:
diff changeset
2977 gcc_unreachable ();
kono
parents:
diff changeset
2978 }
kono
parents:
diff changeset
2979
kono
parents:
diff changeset
2980 if (reg != DWARF_FRAME_RETURN_COLUMN)
kono
parents:
diff changeset
2981 {
kono
parents:
diff changeset
2982 if (reg != INVALID_REGNUM)
kono
parents:
diff changeset
2983 record_reg_saved_in_reg (rtl, pc_rtx);
kono
parents:
diff changeset
2984 reg_save (DWARF_FRAME_RETURN_COLUMN, reg, offset - cur_row->cfa.offset);
kono
parents:
diff changeset
2985 }
kono
parents:
diff changeset
2986 }
kono
parents:
diff changeset
2987
kono
parents:
diff changeset
2988 static void
kono
parents:
diff changeset
2989 create_cie_data (void)
kono
parents:
diff changeset
2990 {
kono
parents:
diff changeset
2991 dw_cfa_location loc;
kono
parents:
diff changeset
2992 dw_trace_info cie_trace;
kono
parents:
diff changeset
2993
kono
parents:
diff changeset
2994 dw_stack_pointer_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
kono
parents:
diff changeset
2995
kono
parents:
diff changeset
2996 memset (&cie_trace, 0, sizeof (cie_trace));
kono
parents:
diff changeset
2997 cur_trace = &cie_trace;
kono
parents:
diff changeset
2998
kono
parents:
diff changeset
2999 add_cfi_vec = &cie_cfi_vec;
kono
parents:
diff changeset
3000 cie_cfi_row = cur_row = new_cfi_row ();
kono
parents:
diff changeset
3001
kono
parents:
diff changeset
3002 /* On entry, the Canonical Frame Address is at SP. */
kono
parents:
diff changeset
3003 memset (&loc, 0, sizeof (loc));
kono
parents:
diff changeset
3004 loc.reg = dw_stack_pointer_regnum;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3005 /* create_cie_data is called just once per TU, and when using .cfi_startproc
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3006 is even done by the assembler rather than the compiler. If the target
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3007 has different incoming frame sp offsets depending on what kind of
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3008 function it is, use a single constant offset for the target and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3009 if needed, adjust before the first instruction in insn stream. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3010 loc.offset = DEFAULT_INCOMING_FRAME_SP_OFFSET;
111
kono
parents:
diff changeset
3011 def_cfa_1 (&loc);
kono
parents:
diff changeset
3012
kono
parents:
diff changeset
3013 if (targetm.debug_unwind_info () == UI_DWARF2
kono
parents:
diff changeset
3014 || targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
kono
parents:
diff changeset
3015 {
kono
parents:
diff changeset
3016 initial_return_save (INCOMING_RETURN_ADDR_RTX);
kono
parents:
diff changeset
3017
kono
parents:
diff changeset
3018 /* For a few targets, we have the return address incoming into a
kono
parents:
diff changeset
3019 register, but choose a different return column. This will result
kono
parents:
diff changeset
3020 in a DW_CFA_register for the return, and an entry in
kono
parents:
diff changeset
3021 regs_saved_in_regs to match. If the target later stores that
kono
parents:
diff changeset
3022 return address register to the stack, we want to be able to emit
kono
parents:
diff changeset
3023 the DW_CFA_offset against the return column, not the intermediate
kono
parents:
diff changeset
3024 save register. Save the contents of regs_saved_in_regs so that
kono
parents:
diff changeset
3025 we can re-initialize it at the start of each function. */
kono
parents:
diff changeset
3026 switch (cie_trace.regs_saved_in_regs.length ())
kono
parents:
diff changeset
3027 {
kono
parents:
diff changeset
3028 case 0:
kono
parents:
diff changeset
3029 break;
kono
parents:
diff changeset
3030 case 1:
kono
parents:
diff changeset
3031 cie_return_save = ggc_alloc<reg_saved_in_data> ();
kono
parents:
diff changeset
3032 *cie_return_save = cie_trace.regs_saved_in_regs[0];
kono
parents:
diff changeset
3033 cie_trace.regs_saved_in_regs.release ();
kono
parents:
diff changeset
3034 break;
kono
parents:
diff changeset
3035 default:
kono
parents:
diff changeset
3036 gcc_unreachable ();
kono
parents:
diff changeset
3037 }
kono
parents:
diff changeset
3038 }
kono
parents:
diff changeset
3039
kono
parents:
diff changeset
3040 add_cfi_vec = NULL;
kono
parents:
diff changeset
3041 cur_row = NULL;
kono
parents:
diff changeset
3042 cur_trace = NULL;
kono
parents:
diff changeset
3043 }
kono
parents:
diff changeset
3044
kono
parents:
diff changeset
3045 /* Annotate the function with NOTE_INSN_CFI notes to record the CFI
kono
parents:
diff changeset
3046 state at each location within the function. These notes will be
kono
parents:
diff changeset
3047 emitted during pass_final. */
kono
parents:
diff changeset
3048
kono
parents:
diff changeset
3049 static unsigned int
kono
parents:
diff changeset
3050 execute_dwarf2_frame (void)
kono
parents:
diff changeset
3051 {
kono
parents:
diff changeset
3052 /* Different HARD_FRAME_POINTER_REGNUM might coexist in the same file. */
kono
parents:
diff changeset
3053 dw_frame_pointer_regnum = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
kono
parents:
diff changeset
3054
kono
parents:
diff changeset
3055 /* The first time we're called, compute the incoming frame state. */
kono
parents:
diff changeset
3056 if (cie_cfi_vec == NULL)
kono
parents:
diff changeset
3057 create_cie_data ();
kono
parents:
diff changeset
3058
kono
parents:
diff changeset
3059 dwarf2out_alloc_current_fde ();
kono
parents:
diff changeset
3060
kono
parents:
diff changeset
3061 create_pseudo_cfg ();
kono
parents:
diff changeset
3062
kono
parents:
diff changeset
3063 /* Do the work. */
kono
parents:
diff changeset
3064 create_cfi_notes ();
kono
parents:
diff changeset
3065 connect_traces ();
kono
parents:
diff changeset
3066 add_cfis_to_fde ();
kono
parents:
diff changeset
3067
kono
parents:
diff changeset
3068 /* Free all the data we allocated. */
kono
parents:
diff changeset
3069 {
kono
parents:
diff changeset
3070 size_t i;
kono
parents:
diff changeset
3071 dw_trace_info *ti;
kono
parents:
diff changeset
3072
kono
parents:
diff changeset
3073 FOR_EACH_VEC_ELT (trace_info, i, ti)
kono
parents:
diff changeset
3074 ti->regs_saved_in_regs.release ();
kono
parents:
diff changeset
3075 }
kono
parents:
diff changeset
3076 trace_info.release ();
kono
parents:
diff changeset
3077
kono
parents:
diff changeset
3078 delete trace_index;
kono
parents:
diff changeset
3079 trace_index = NULL;
kono
parents:
diff changeset
3080
kono
parents:
diff changeset
3081 return 0;
kono
parents:
diff changeset
3082 }
kono
parents:
diff changeset
3083
kono
parents:
diff changeset
3084 /* Convert a DWARF call frame info. operation to its string name */
kono
parents:
diff changeset
3085
kono
parents:
diff changeset
3086 static const char *
kono
parents:
diff changeset
3087 dwarf_cfi_name (unsigned int cfi_opc)
kono
parents:
diff changeset
3088 {
kono
parents:
diff changeset
3089 const char *name = get_DW_CFA_name (cfi_opc);
kono
parents:
diff changeset
3090
kono
parents:
diff changeset
3091 if (name != NULL)
kono
parents:
diff changeset
3092 return name;
kono
parents:
diff changeset
3093
kono
parents:
diff changeset
3094 return "DW_CFA_<unknown>";
kono
parents:
diff changeset
3095 }
kono
parents:
diff changeset
3096
kono
parents:
diff changeset
3097 /* This routine will generate the correct assembly data for a location
kono
parents:
diff changeset
3098 description based on a cfi entry with a complex address. */
kono
parents:
diff changeset
3099
kono
parents:
diff changeset
3100 static void
kono
parents:
diff changeset
3101 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
kono
parents:
diff changeset
3102 {
kono
parents:
diff changeset
3103 dw_loc_descr_ref loc;
kono
parents:
diff changeset
3104 unsigned long size;
kono
parents:
diff changeset
3105
kono
parents:
diff changeset
3106 if (cfi->dw_cfi_opc == DW_CFA_expression
kono
parents:
diff changeset
3107 || cfi->dw_cfi_opc == DW_CFA_val_expression)
kono
parents:
diff changeset
3108 {
kono
parents:
diff changeset
3109 unsigned r =
kono
parents:
diff changeset
3110 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3111 dw2_asm_output_data (1, r, NULL);
kono
parents:
diff changeset
3112 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
kono
parents:
diff changeset
3113 }
kono
parents:
diff changeset
3114 else
kono
parents:
diff changeset
3115 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
kono
parents:
diff changeset
3116
kono
parents:
diff changeset
3117 /* Output the size of the block. */
kono
parents:
diff changeset
3118 size = size_of_locs (loc);
kono
parents:
diff changeset
3119 dw2_asm_output_data_uleb128 (size, NULL);
kono
parents:
diff changeset
3120
kono
parents:
diff changeset
3121 /* Now output the operations themselves. */
kono
parents:
diff changeset
3122 output_loc_sequence (loc, for_eh);
kono
parents:
diff changeset
3123 }
kono
parents:
diff changeset
3124
kono
parents:
diff changeset
3125 /* Similar, but used for .cfi_escape. */
kono
parents:
diff changeset
3126
kono
parents:
diff changeset
3127 static void
kono
parents:
diff changeset
3128 output_cfa_loc_raw (dw_cfi_ref cfi)
kono
parents:
diff changeset
3129 {
kono
parents:
diff changeset
3130 dw_loc_descr_ref loc;
kono
parents:
diff changeset
3131 unsigned long size;
kono
parents:
diff changeset
3132
kono
parents:
diff changeset
3133 if (cfi->dw_cfi_opc == DW_CFA_expression
kono
parents:
diff changeset
3134 || cfi->dw_cfi_opc == DW_CFA_val_expression)
kono
parents:
diff changeset
3135 {
kono
parents:
diff changeset
3136 unsigned r =
kono
parents:
diff changeset
3137 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
kono
parents:
diff changeset
3138 fprintf (asm_out_file, "%#x,", r);
kono
parents:
diff changeset
3139 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
kono
parents:
diff changeset
3140 }
kono
parents:
diff changeset
3141 else
kono
parents:
diff changeset
3142 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
kono
parents:
diff changeset
3143
kono
parents:
diff changeset
3144 /* Output the size of the block. */
kono
parents:
diff changeset
3145 size = size_of_locs (loc);
kono
parents:
diff changeset
3146 dw2_asm_output_data_uleb128_raw (size);
kono
parents:
diff changeset
3147 fputc (',', asm_out_file);
kono
parents:
diff changeset
3148
kono
parents:
diff changeset
3149 /* Now output the operations themselves. */
kono
parents:
diff changeset
3150 output_loc_sequence_raw (loc);
kono
parents:
diff changeset
3151 }
kono
parents:
diff changeset
3152
kono
parents:
diff changeset
3153 /* Output a Call Frame Information opcode and its operand(s). */
kono
parents:
diff changeset
3154
kono
parents:
diff changeset
3155 void
kono
parents:
diff changeset
3156 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
kono
parents:
diff changeset
3157 {
kono
parents:
diff changeset
3158 unsigned long r;
kono
parents:
diff changeset
3159 HOST_WIDE_INT off;
kono
parents:
diff changeset
3160
kono
parents:
diff changeset
3161 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
kono
parents:
diff changeset
3162 dw2_asm_output_data (1, (cfi->dw_cfi_opc
kono
parents:
diff changeset
3163 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
kono
parents:
diff changeset
3164 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
kono
parents:
diff changeset
3165 ((unsigned HOST_WIDE_INT)
kono
parents:
diff changeset
3166 cfi->dw_cfi_oprnd1.dw_cfi_offset));
kono
parents:
diff changeset
3167 else if (cfi->dw_cfi_opc == DW_CFA_offset)
kono
parents:
diff changeset
3168 {
kono
parents:
diff changeset
3169 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3170 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
kono
parents:
diff changeset
3171 "DW_CFA_offset, column %#lx", r);
kono
parents:
diff changeset
3172 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
kono
parents:
diff changeset
3173 dw2_asm_output_data_uleb128 (off, NULL);
kono
parents:
diff changeset
3174 }
kono
parents:
diff changeset
3175 else if (cfi->dw_cfi_opc == DW_CFA_restore)
kono
parents:
diff changeset
3176 {
kono
parents:
diff changeset
3177 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3178 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
kono
parents:
diff changeset
3179 "DW_CFA_restore, column %#lx", r);
kono
parents:
diff changeset
3180 }
kono
parents:
diff changeset
3181 else
kono
parents:
diff changeset
3182 {
kono
parents:
diff changeset
3183 dw2_asm_output_data (1, cfi->dw_cfi_opc,
kono
parents:
diff changeset
3184 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
kono
parents:
diff changeset
3185
kono
parents:
diff changeset
3186 switch (cfi->dw_cfi_opc)
kono
parents:
diff changeset
3187 {
kono
parents:
diff changeset
3188 case DW_CFA_set_loc:
kono
parents:
diff changeset
3189 if (for_eh)
kono
parents:
diff changeset
3190 dw2_asm_output_encoded_addr_rtx (
kono
parents:
diff changeset
3191 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
kono
parents:
diff changeset
3192 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
kono
parents:
diff changeset
3193 false, NULL);
kono
parents:
diff changeset
3194 else
kono
parents:
diff changeset
3195 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
kono
parents:
diff changeset
3196 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
kono
parents:
diff changeset
3197 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
kono
parents:
diff changeset
3198 break;
kono
parents:
diff changeset
3199
kono
parents:
diff changeset
3200 case DW_CFA_advance_loc1:
kono
parents:
diff changeset
3201 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
kono
parents:
diff changeset
3202 fde->dw_fde_current_label, NULL);
kono
parents:
diff changeset
3203 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
kono
parents:
diff changeset
3204 break;
kono
parents:
diff changeset
3205
kono
parents:
diff changeset
3206 case DW_CFA_advance_loc2:
kono
parents:
diff changeset
3207 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
kono
parents:
diff changeset
3208 fde->dw_fde_current_label, NULL);
kono
parents:
diff changeset
3209 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
kono
parents:
diff changeset
3210 break;
kono
parents:
diff changeset
3211
kono
parents:
diff changeset
3212 case DW_CFA_advance_loc4:
kono
parents:
diff changeset
3213 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
kono
parents:
diff changeset
3214 fde->dw_fde_current_label, NULL);
kono
parents:
diff changeset
3215 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
kono
parents:
diff changeset
3216 break;
kono
parents:
diff changeset
3217
kono
parents:
diff changeset
3218 case DW_CFA_MIPS_advance_loc8:
kono
parents:
diff changeset
3219 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
kono
parents:
diff changeset
3220 fde->dw_fde_current_label, NULL);
kono
parents:
diff changeset
3221 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
kono
parents:
diff changeset
3222 break;
kono
parents:
diff changeset
3223
kono
parents:
diff changeset
3224 case DW_CFA_offset_extended:
kono
parents:
diff changeset
3225 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3226 dw2_asm_output_data_uleb128 (r, NULL);
kono
parents:
diff changeset
3227 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
kono
parents:
diff changeset
3228 dw2_asm_output_data_uleb128 (off, NULL);
kono
parents:
diff changeset
3229 break;
kono
parents:
diff changeset
3230
kono
parents:
diff changeset
3231 case DW_CFA_def_cfa:
kono
parents:
diff changeset
3232 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3233 dw2_asm_output_data_uleb128 (r, NULL);
kono
parents:
diff changeset
3234 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
kono
parents:
diff changeset
3235 break;
kono
parents:
diff changeset
3236
kono
parents:
diff changeset
3237 case DW_CFA_offset_extended_sf:
kono
parents:
diff changeset
3238 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3239 dw2_asm_output_data_uleb128 (r, NULL);
kono
parents:
diff changeset
3240 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
kono
parents:
diff changeset
3241 dw2_asm_output_data_sleb128 (off, NULL);
kono
parents:
diff changeset
3242 break;
kono
parents:
diff changeset
3243
kono
parents:
diff changeset
3244 case DW_CFA_def_cfa_sf:
kono
parents:
diff changeset
3245 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3246 dw2_asm_output_data_uleb128 (r, NULL);
kono
parents:
diff changeset
3247 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
kono
parents:
diff changeset
3248 dw2_asm_output_data_sleb128 (off, NULL);
kono
parents:
diff changeset
3249 break;
kono
parents:
diff changeset
3250
kono
parents:
diff changeset
3251 case DW_CFA_restore_extended:
kono
parents:
diff changeset
3252 case DW_CFA_undefined:
kono
parents:
diff changeset
3253 case DW_CFA_same_value:
kono
parents:
diff changeset
3254 case DW_CFA_def_cfa_register:
kono
parents:
diff changeset
3255 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3256 dw2_asm_output_data_uleb128 (r, NULL);
kono
parents:
diff changeset
3257 break;
kono
parents:
diff changeset
3258
kono
parents:
diff changeset
3259 case DW_CFA_register:
kono
parents:
diff changeset
3260 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3261 dw2_asm_output_data_uleb128 (r, NULL);
kono
parents:
diff changeset
3262 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
kono
parents:
diff changeset
3263 dw2_asm_output_data_uleb128 (r, NULL);
kono
parents:
diff changeset
3264 break;
kono
parents:
diff changeset
3265
kono
parents:
diff changeset
3266 case DW_CFA_def_cfa_offset:
kono
parents:
diff changeset
3267 case DW_CFA_GNU_args_size:
kono
parents:
diff changeset
3268 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
kono
parents:
diff changeset
3269 break;
kono
parents:
diff changeset
3270
kono
parents:
diff changeset
3271 case DW_CFA_def_cfa_offset_sf:
kono
parents:
diff changeset
3272 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
kono
parents:
diff changeset
3273 dw2_asm_output_data_sleb128 (off, NULL);
kono
parents:
diff changeset
3274 break;
kono
parents:
diff changeset
3275
kono
parents:
diff changeset
3276 case DW_CFA_GNU_window_save:
kono
parents:
diff changeset
3277 break;
kono
parents:
diff changeset
3278
kono
parents:
diff changeset
3279 case DW_CFA_def_cfa_expression:
kono
parents:
diff changeset
3280 case DW_CFA_expression:
kono
parents:
diff changeset
3281 case DW_CFA_val_expression:
kono
parents:
diff changeset
3282 output_cfa_loc (cfi, for_eh);
kono
parents:
diff changeset
3283 break;
kono
parents:
diff changeset
3284
kono
parents:
diff changeset
3285 case DW_CFA_GNU_negative_offset_extended:
kono
parents:
diff changeset
3286 /* Obsoleted by DW_CFA_offset_extended_sf. */
kono
parents:
diff changeset
3287 gcc_unreachable ();
kono
parents:
diff changeset
3288
kono
parents:
diff changeset
3289 default:
kono
parents:
diff changeset
3290 break;
kono
parents:
diff changeset
3291 }
kono
parents:
diff changeset
3292 }
kono
parents:
diff changeset
3293 }
kono
parents:
diff changeset
3294
kono
parents:
diff changeset
3295 /* Similar, but do it via assembler directives instead. */
kono
parents:
diff changeset
3296
kono
parents:
diff changeset
3297 void
kono
parents:
diff changeset
3298 output_cfi_directive (FILE *f, dw_cfi_ref cfi)
kono
parents:
diff changeset
3299 {
kono
parents:
diff changeset
3300 unsigned long r, r2;
kono
parents:
diff changeset
3301
kono
parents:
diff changeset
3302 switch (cfi->dw_cfi_opc)
kono
parents:
diff changeset
3303 {
kono
parents:
diff changeset
3304 case DW_CFA_advance_loc:
kono
parents:
diff changeset
3305 case DW_CFA_advance_loc1:
kono
parents:
diff changeset
3306 case DW_CFA_advance_loc2:
kono
parents:
diff changeset
3307 case DW_CFA_advance_loc4:
kono
parents:
diff changeset
3308 case DW_CFA_MIPS_advance_loc8:
kono
parents:
diff changeset
3309 case DW_CFA_set_loc:
kono
parents:
diff changeset
3310 /* Should only be created in a code path not followed when emitting
kono
parents:
diff changeset
3311 via directives. The assembler is going to take care of this for
kono
parents:
diff changeset
3312 us. But this routines is also used for debugging dumps, so
kono
parents:
diff changeset
3313 print something. */
kono
parents:
diff changeset
3314 gcc_assert (f != asm_out_file);
kono
parents:
diff changeset
3315 fprintf (f, "\t.cfi_advance_loc\n");
kono
parents:
diff changeset
3316 break;
kono
parents:
diff changeset
3317
kono
parents:
diff changeset
3318 case DW_CFA_offset:
kono
parents:
diff changeset
3319 case DW_CFA_offset_extended:
kono
parents:
diff changeset
3320 case DW_CFA_offset_extended_sf:
kono
parents:
diff changeset
3321 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
kono
parents:
diff changeset
3322 fprintf (f, "\t.cfi_offset %lu, " HOST_WIDE_INT_PRINT_DEC"\n",
kono
parents:
diff changeset
3323 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
kono
parents:
diff changeset
3324 break;
kono
parents:
diff changeset
3325
kono
parents:
diff changeset
3326 case DW_CFA_restore:
kono
parents:
diff changeset
3327 case DW_CFA_restore_extended:
kono
parents:
diff changeset
3328 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
kono
parents:
diff changeset
3329 fprintf (f, "\t.cfi_restore %lu\n", r);
kono
parents:
diff changeset
3330 break;
kono
parents:
diff changeset
3331
kono
parents:
diff changeset
3332 case DW_CFA_undefined:
kono
parents:
diff changeset
3333 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
kono
parents:
diff changeset
3334 fprintf (f, "\t.cfi_undefined %lu\n", r);
kono
parents:
diff changeset
3335 break;
kono
parents:
diff changeset
3336
kono
parents:
diff changeset
3337 case DW_CFA_same_value:
kono
parents:
diff changeset
3338 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
kono
parents:
diff changeset
3339 fprintf (f, "\t.cfi_same_value %lu\n", r);
kono
parents:
diff changeset
3340 break;
kono
parents:
diff changeset
3341
kono
parents:
diff changeset
3342 case DW_CFA_def_cfa:
kono
parents:
diff changeset
3343 case DW_CFA_def_cfa_sf:
kono
parents:
diff changeset
3344 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
kono
parents:
diff changeset
3345 fprintf (f, "\t.cfi_def_cfa %lu, " HOST_WIDE_INT_PRINT_DEC"\n",
kono
parents:
diff changeset
3346 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
kono
parents:
diff changeset
3347 break;
kono
parents:
diff changeset
3348
kono
parents:
diff changeset
3349 case DW_CFA_def_cfa_register:
kono
parents:
diff changeset
3350 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
kono
parents:
diff changeset
3351 fprintf (f, "\t.cfi_def_cfa_register %lu\n", r);
kono
parents:
diff changeset
3352 break;
kono
parents:
diff changeset
3353
kono
parents:
diff changeset
3354 case DW_CFA_register:
kono
parents:
diff changeset
3355 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
kono
parents:
diff changeset
3356 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
kono
parents:
diff changeset
3357 fprintf (f, "\t.cfi_register %lu, %lu\n", r, r2);
kono
parents:
diff changeset
3358 break;
kono
parents:
diff changeset
3359
kono
parents:
diff changeset
3360 case DW_CFA_def_cfa_offset:
kono
parents:
diff changeset
3361 case DW_CFA_def_cfa_offset_sf:
kono
parents:
diff changeset
3362 fprintf (f, "\t.cfi_def_cfa_offset "
kono
parents:
diff changeset
3363 HOST_WIDE_INT_PRINT_DEC"\n",
kono
parents:
diff changeset
3364 cfi->dw_cfi_oprnd1.dw_cfi_offset);
kono
parents:
diff changeset
3365 break;
kono
parents:
diff changeset
3366
kono
parents:
diff changeset
3367 case DW_CFA_remember_state:
kono
parents:
diff changeset
3368 fprintf (f, "\t.cfi_remember_state\n");
kono
parents:
diff changeset
3369 break;
kono
parents:
diff changeset
3370 case DW_CFA_restore_state:
kono
parents:
diff changeset
3371 fprintf (f, "\t.cfi_restore_state\n");
kono
parents:
diff changeset
3372 break;
kono
parents:
diff changeset
3373
kono
parents:
diff changeset
3374 case DW_CFA_GNU_args_size:
kono
parents:
diff changeset
3375 if (f == asm_out_file)
kono
parents:
diff changeset
3376 {
kono
parents:
diff changeset
3377 fprintf (f, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
kono
parents:
diff changeset
3378 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
kono
parents:
diff changeset
3379 if (flag_debug_asm)
kono
parents:
diff changeset
3380 fprintf (f, "\t%s args_size " HOST_WIDE_INT_PRINT_DEC,
kono
parents:
diff changeset
3381 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
kono
parents:
diff changeset
3382 fputc ('\n', f);
kono
parents:
diff changeset
3383 }
kono
parents:
diff changeset
3384 else
kono
parents:
diff changeset
3385 {
kono
parents:
diff changeset
3386 fprintf (f, "\t.cfi_GNU_args_size " HOST_WIDE_INT_PRINT_DEC "\n",
kono
parents:
diff changeset
3387 cfi->dw_cfi_oprnd1.dw_cfi_offset);
kono
parents:
diff changeset
3388 }
kono
parents:
diff changeset
3389 break;
kono
parents:
diff changeset
3390
kono
parents:
diff changeset
3391 case DW_CFA_GNU_window_save:
kono
parents:
diff changeset
3392 fprintf (f, "\t.cfi_window_save\n");
kono
parents:
diff changeset
3393 break;
kono
parents:
diff changeset
3394
kono
parents:
diff changeset
3395 case DW_CFA_def_cfa_expression:
kono
parents:
diff changeset
3396 case DW_CFA_expression:
kono
parents:
diff changeset
3397 case DW_CFA_val_expression:
kono
parents:
diff changeset
3398 if (f != asm_out_file)
kono
parents:
diff changeset
3399 {
kono
parents:
diff changeset
3400 fprintf (f, "\t.cfi_%scfa_%sexpression ...\n",
kono
parents:
diff changeset
3401 cfi->dw_cfi_opc == DW_CFA_def_cfa_expression ? "def_" : "",
kono
parents:
diff changeset
3402 cfi->dw_cfi_opc == DW_CFA_val_expression ? "val_" : "");
kono
parents:
diff changeset
3403 break;
kono
parents:
diff changeset
3404 }
kono
parents:
diff changeset
3405 fprintf (f, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
kono
parents:
diff changeset
3406 output_cfa_loc_raw (cfi);
kono
parents:
diff changeset
3407 fputc ('\n', f);
kono
parents:
diff changeset
3408 break;
kono
parents:
diff changeset
3409
kono
parents:
diff changeset
3410 default:
kono
parents:
diff changeset
3411 gcc_unreachable ();
kono
parents:
diff changeset
3412 }
kono
parents:
diff changeset
3413 }
kono
parents:
diff changeset
3414
kono
parents:
diff changeset
3415 void
kono
parents:
diff changeset
3416 dwarf2out_emit_cfi (dw_cfi_ref cfi)
kono
parents:
diff changeset
3417 {
kono
parents:
diff changeset
3418 if (dwarf2out_do_cfi_asm ())
kono
parents:
diff changeset
3419 output_cfi_directive (asm_out_file, cfi);
kono
parents:
diff changeset
3420 }
kono
parents:
diff changeset
3421
kono
parents:
diff changeset
3422 static void
kono
parents:
diff changeset
3423 dump_cfi_row (FILE *f, dw_cfi_row *row)
kono
parents:
diff changeset
3424 {
kono
parents:
diff changeset
3425 dw_cfi_ref cfi;
kono
parents:
diff changeset
3426 unsigned i;
kono
parents:
diff changeset
3427
kono
parents:
diff changeset
3428 cfi = row->cfa_cfi;
kono
parents:
diff changeset
3429 if (!cfi)
kono
parents:
diff changeset
3430 {
kono
parents:
diff changeset
3431 dw_cfa_location dummy;
kono
parents:
diff changeset
3432 memset (&dummy, 0, sizeof (dummy));
kono
parents:
diff changeset
3433 dummy.reg = INVALID_REGNUM;
kono
parents:
diff changeset
3434 cfi = def_cfa_0 (&dummy, &row->cfa);
kono
parents:
diff changeset
3435 }
kono
parents:
diff changeset
3436 output_cfi_directive (f, cfi);
kono
parents:
diff changeset
3437
kono
parents:
diff changeset
3438 FOR_EACH_VEC_SAFE_ELT (row->reg_save, i, cfi)
kono
parents:
diff changeset
3439 if (cfi)
kono
parents:
diff changeset
3440 output_cfi_directive (f, cfi);
kono
parents:
diff changeset
3441 }
kono
parents:
diff changeset
3442
kono
parents:
diff changeset
3443 void debug_cfi_row (dw_cfi_row *row);
kono
parents:
diff changeset
3444
kono
parents:
diff changeset
3445 void
kono
parents:
diff changeset
3446 debug_cfi_row (dw_cfi_row *row)
kono
parents:
diff changeset
3447 {
kono
parents:
diff changeset
3448 dump_cfi_row (stderr, row);
kono
parents:
diff changeset
3449 }
kono
parents:
diff changeset
3450
kono
parents:
diff changeset
3451
kono
parents:
diff changeset
3452 /* Save the result of dwarf2out_do_frame across PCH.
kono
parents:
diff changeset
3453 This variable is tri-state, with 0 unset, >0 true, <0 false. */
kono
parents:
diff changeset
3454 static GTY(()) signed char saved_do_cfi_asm = 0;
kono
parents:
diff changeset
3455
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3456 /* Decide whether to emit EH frame unwind information for the current
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3457 translation unit. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3458
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3459 bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3460 dwarf2out_do_eh_frame (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3461 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3462 return
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3463 (flag_unwind_tables || flag_exceptions)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3464 && targetm_common.except_unwind_info (&global_options) == UI_DWARF2;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3465 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3466
111
kono
parents:
diff changeset
3467 /* Decide whether we want to emit frame unwind information for the current
kono
parents:
diff changeset
3468 translation unit. */
kono
parents:
diff changeset
3469
kono
parents:
diff changeset
3470 bool
kono
parents:
diff changeset
3471 dwarf2out_do_frame (void)
kono
parents:
diff changeset
3472 {
kono
parents:
diff changeset
3473 /* We want to emit correct CFA location expressions or lists, so we
kono
parents:
diff changeset
3474 have to return true if we're going to output debug info, even if
kono
parents:
diff changeset
3475 we're not going to output frame or unwind info. */
kono
parents:
diff changeset
3476 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
kono
parents:
diff changeset
3477 return true;
kono
parents:
diff changeset
3478
kono
parents:
diff changeset
3479 if (saved_do_cfi_asm > 0)
kono
parents:
diff changeset
3480 return true;
kono
parents:
diff changeset
3481
kono
parents:
diff changeset
3482 if (targetm.debug_unwind_info () == UI_DWARF2)
kono
parents:
diff changeset
3483 return true;
kono
parents:
diff changeset
3484
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3485 if (dwarf2out_do_eh_frame ())
111
kono
parents:
diff changeset
3486 return true;
kono
parents:
diff changeset
3487
kono
parents:
diff changeset
3488 return false;
kono
parents:
diff changeset
3489 }
kono
parents:
diff changeset
3490
kono
parents:
diff changeset
3491 /* Decide whether to emit frame unwind via assembler directives. */
kono
parents:
diff changeset
3492
kono
parents:
diff changeset
3493 bool
kono
parents:
diff changeset
3494 dwarf2out_do_cfi_asm (void)
kono
parents:
diff changeset
3495 {
kono
parents:
diff changeset
3496 int enc;
kono
parents:
diff changeset
3497
kono
parents:
diff changeset
3498 if (saved_do_cfi_asm != 0)
kono
parents:
diff changeset
3499 return saved_do_cfi_asm > 0;
kono
parents:
diff changeset
3500
kono
parents:
diff changeset
3501 /* Assume failure for a moment. */
kono
parents:
diff changeset
3502 saved_do_cfi_asm = -1;
kono
parents:
diff changeset
3503
kono
parents:
diff changeset
3504 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
kono
parents:
diff changeset
3505 return false;
kono
parents:
diff changeset
3506 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
kono
parents:
diff changeset
3507 return false;
kono
parents:
diff changeset
3508
kono
parents:
diff changeset
3509 /* Make sure the personality encoding is one the assembler can support.
kono
parents:
diff changeset
3510 In particular, aligned addresses can't be handled. */
kono
parents:
diff changeset
3511 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
kono
parents:
diff changeset
3512 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
kono
parents:
diff changeset
3513 return false;
kono
parents:
diff changeset
3514 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
kono
parents:
diff changeset
3515 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
kono
parents:
diff changeset
3516 return false;
kono
parents:
diff changeset
3517
kono
parents:
diff changeset
3518 /* If we can't get the assembler to emit only .debug_frame, and we don't need
kono
parents:
diff changeset
3519 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3520 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE && !dwarf2out_do_eh_frame ())
111
kono
parents:
diff changeset
3521 return false;
kono
parents:
diff changeset
3522
kono
parents:
diff changeset
3523 /* Success! */
kono
parents:
diff changeset
3524 saved_do_cfi_asm = 1;
kono
parents:
diff changeset
3525 return true;
kono
parents:
diff changeset
3526 }
kono
parents:
diff changeset
3527
kono
parents:
diff changeset
3528 namespace {
kono
parents:
diff changeset
3529
kono
parents:
diff changeset
3530 const pass_data pass_data_dwarf2_frame =
kono
parents:
diff changeset
3531 {
kono
parents:
diff changeset
3532 RTL_PASS, /* type */
kono
parents:
diff changeset
3533 "dwarf2", /* name */
kono
parents:
diff changeset
3534 OPTGROUP_NONE, /* optinfo_flags */
kono
parents:
diff changeset
3535 TV_FINAL, /* tv_id */
kono
parents:
diff changeset
3536 0, /* properties_required */
kono
parents:
diff changeset
3537 0, /* properties_provided */
kono
parents:
diff changeset
3538 0, /* properties_destroyed */
kono
parents:
diff changeset
3539 0, /* todo_flags_start */
kono
parents:
diff changeset
3540 0, /* todo_flags_finish */
kono
parents:
diff changeset
3541 };
kono
parents:
diff changeset
3542
kono
parents:
diff changeset
3543 class pass_dwarf2_frame : public rtl_opt_pass
kono
parents:
diff changeset
3544 {
kono
parents:
diff changeset
3545 public:
kono
parents:
diff changeset
3546 pass_dwarf2_frame (gcc::context *ctxt)
kono
parents:
diff changeset
3547 : rtl_opt_pass (pass_data_dwarf2_frame, ctxt)
kono
parents:
diff changeset
3548 {}
kono
parents:
diff changeset
3549
kono
parents:
diff changeset
3550 /* opt_pass methods: */
kono
parents:
diff changeset
3551 virtual bool gate (function *);
kono
parents:
diff changeset
3552 virtual unsigned int execute (function *) { return execute_dwarf2_frame (); }
kono
parents:
diff changeset
3553
kono
parents:
diff changeset
3554 }; // class pass_dwarf2_frame
kono
parents:
diff changeset
3555
kono
parents:
diff changeset
3556 bool
kono
parents:
diff changeset
3557 pass_dwarf2_frame::gate (function *)
kono
parents:
diff changeset
3558 {
kono
parents:
diff changeset
3559 /* Targets which still implement the prologue in assembler text
kono
parents:
diff changeset
3560 cannot use the generic dwarf2 unwinding. */
kono
parents:
diff changeset
3561 if (!targetm.have_prologue ())
kono
parents:
diff changeset
3562 return false;
kono
parents:
diff changeset
3563
kono
parents:
diff changeset
3564 /* ??? What to do for UI_TARGET unwinding? They might be able to benefit
kono
parents:
diff changeset
3565 from the optimized shrink-wrapping annotations that we will compute.
kono
parents:
diff changeset
3566 For now, only produce the CFI notes for dwarf2. */
kono
parents:
diff changeset
3567 return dwarf2out_do_frame ();
kono
parents:
diff changeset
3568 }
kono
parents:
diff changeset
3569
kono
parents:
diff changeset
3570 } // anon namespace
kono
parents:
diff changeset
3571
kono
parents:
diff changeset
3572 rtl_opt_pass *
kono
parents:
diff changeset
3573 make_pass_dwarf2_frame (gcc::context *ctxt)
kono
parents:
diff changeset
3574 {
kono
parents:
diff changeset
3575 return new pass_dwarf2_frame (ctxt);
kono
parents:
diff changeset
3576 }
kono
parents:
diff changeset
3577
kono
parents:
diff changeset
3578 #include "gt-dwarf2cfi.h"