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