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