1 /* Dwarf2 Call Frame Information helper routines.
2 Copyright (C) 1992-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "tree-pass.h"
31 #include "stor-layout.h"
33 #include "dwarf2out.h"
34 #include "dwarf2asm.h"
35 #include "common/common-target.h"
37 #include "except.h" /* expand_builtin_dwarf_sp_column */
38 #include "profile-count.h" /* For expr.h */
39 #include "expr.h" /* init_return_column_size */
40 #include "output.h" /* asm_out_file */
41 #include "debug.h" /* dwarf2out_do_frame, dwarf2out_do_cfi_asm */
44 /* ??? Poison these here until it can be done generically. They've been
45 totally replaced in this file; make sure it stays that way. */
46 #undef DWARF2_UNWIND_INFO
47 #undef DWARF2_FRAME_INFO
48 #if (GCC_VERSION >= 3000)
49 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
52 #ifndef INCOMING_RETURN_ADDR_RTX
53 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
56 /* A collected description of an entire row of the abstract CFI table. */
57 struct GTY(()) dw_cfi_row
59 /* The expression that computes the CFA, expressed in two different ways.
60 The CFA member for the simple cases, and the full CFI expression for
61 the complex cases. The later will be a DW_CFA_cfa_expression. */
65 /* The expressions for any register column that is saved. */
69 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
70 struct GTY(()) reg_saved_in_data
{
76 /* Since we no longer have a proper CFG, we're going to create a facsimile
77 of one on the fly while processing the frame-related insns.
79 We create dw_trace_info structures for each extended basic block beginning
80 and ending at a "save point". Save points are labels, barriers, certain
81 notes, and of course the beginning and end of the function.
83 As we encounter control transfer insns, we propagate the "current"
84 row state across the edges to the starts of traces. When checking is
85 enabled, we validate that we propagate the same data from all sources.
87 All traces are members of the TRACE_INFO array, in the order in which
88 they appear in the instruction stream.
90 All save points are present in the TRACE_INDEX hash, mapping the insn
91 starting a trace to the dw_trace_info describing the trace. */
95 /* The insn that begins the trace. */
98 /* The row state at the beginning and end of the trace. */
99 dw_cfi_row
*beg_row
, *end_row
;
101 /* Tracking for DW_CFA_GNU_args_size. The "true" sizes are those we find
102 while scanning insns. However, the args_size value is irrelevant at
103 any point except can_throw_internal_p insns. Therefore the "delay"
104 sizes the values that must actually be emitted for this trace. */
105 poly_int64_pod beg_true_args_size
, end_true_args_size
;
106 poly_int64_pod beg_delay_args_size
, end_delay_args_size
;
108 /* The first EH insn in the trace, where beg_delay_args_size must be set. */
111 /* The following variables contain data used in interpreting frame related
112 expressions. These are not part of the "real" row state as defined by
113 Dwarf, but it seems like they need to be propagated into a trace in case
114 frame related expressions have been sunk. */
115 /* ??? This seems fragile. These variables are fragments of a larger
116 expression. If we do not keep the entire expression together, we risk
117 not being able to put it together properly. Consider forcing targets
118 to generate self-contained expressions and dropping all of the magic
119 interpretation code in this file. Or at least refusing to shrink wrap
120 any frame related insn that doesn't contain a complete expression. */
122 /* The register used for saving registers to the stack, and its offset
124 dw_cfa_location cfa_store
;
126 /* A temporary register holding an integral value used in adjusting SP
127 or setting up the store_reg. The "offset" field holds the integer
128 value, not an offset. */
129 dw_cfa_location cfa_temp
;
131 /* A set of registers saved in other registers. This is the inverse of
132 the row->reg_save info, if the entry is a DW_CFA_register. This is
133 implemented as a flat array because it normally contains zero or 1
134 entry, depending on the target. IA-64 is the big spender here, using
135 a maximum of 5 entries. */
136 vec
<reg_saved_in_data
> regs_saved_in_regs
;
138 /* An identifier for this trace. Used only for debugging dumps. */
141 /* True if this trace immediately follows NOTE_INSN_SWITCH_TEXT_SECTIONS. */
142 bool switch_sections
;
144 /* True if we've seen different values incoming to beg_true_args_size. */
145 bool args_size_undefined
;
149 /* Hashtable helpers. */
151 struct trace_info_hasher
: nofree_ptr_hash
<dw_trace_info
>
153 static inline hashval_t
hash (const dw_trace_info
*);
154 static inline bool equal (const dw_trace_info
*, const dw_trace_info
*);
158 trace_info_hasher::hash (const dw_trace_info
*ti
)
160 return INSN_UID (ti
->head
);
164 trace_info_hasher::equal (const dw_trace_info
*a
, const dw_trace_info
*b
)
166 return a
->head
== b
->head
;
170 /* The variables making up the pseudo-cfg, as described above. */
171 static vec
<dw_trace_info
> trace_info
;
172 static vec
<dw_trace_info
*> trace_work_list
;
173 static hash_table
<trace_info_hasher
> *trace_index
;
175 /* A vector of call frame insns for the CIE. */
178 /* The state of the first row of the FDE table, which includes the
179 state provided by the CIE. */
180 static GTY(()) dw_cfi_row
*cie_cfi_row
;
182 static GTY(()) reg_saved_in_data
*cie_return_save
;
184 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
186 /* The insn after which a new CFI note should be emitted. */
187 static rtx_insn
*add_cfi_insn
;
189 /* When non-null, add_cfi will add the CFI to this vector. */
190 static cfi_vec
*add_cfi_vec
;
192 /* The current instruction trace. */
193 static dw_trace_info
*cur_trace
;
195 /* The current, i.e. most recently generated, row of the CFI table. */
196 static dw_cfi_row
*cur_row
;
198 /* A copy of the current CFA, for use during the processing of a
200 static dw_cfa_location
*cur_cfa
;
202 /* We delay emitting a register save until either (a) we reach the end
203 of the prologue or (b) the register is clobbered. This clusters
204 register saves so that there are fewer pc advances. */
206 struct queued_reg_save
{
209 poly_int64_pod cfa_offset
;
213 static vec
<queued_reg_save
> queued_reg_saves
;
215 /* True if any CFI directives were emitted at the current insn. */
216 static bool any_cfis_emitted
;
218 /* Short-hand for commonly used register numbers. */
219 static unsigned dw_stack_pointer_regnum
;
220 static unsigned dw_frame_pointer_regnum
;
222 /* Hook used by __throw. */
225 expand_builtin_dwarf_sp_column (void)
227 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
228 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
231 /* MEM is a memory reference for the register size table, each element of
232 which has mode MODE. Initialize column C as a return address column. */
235 init_return_column_size (scalar_int_mode mode
, rtx mem
, unsigned int c
)
237 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
238 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
239 emit_move_insn (adjust_address (mem
, mode
, offset
),
240 gen_int_mode (size
, mode
));
243 /* Datastructure used by expand_builtin_init_dwarf_reg_sizes and
244 init_one_dwarf_reg_size to communicate on what has been done by the
247 struct init_one_dwarf_reg_state
249 /* Whether the dwarf return column was initialized. */
250 bool wrote_return_column
;
252 /* For each hard register REGNO, whether init_one_dwarf_reg_size
253 was given REGNO to process already. */
254 bool processed_regno
[FIRST_PSEUDO_REGISTER
];
258 /* Helper for expand_builtin_init_dwarf_reg_sizes. Generate code to
259 initialize the dwarf register size table entry corresponding to register
260 REGNO in REGMODE. TABLE is the table base address, SLOTMODE is the mode to
261 use for the size entry to initialize, and INIT_STATE is the communication
262 datastructure conveying what we're doing to our caller. */
265 void init_one_dwarf_reg_size (int regno
, machine_mode regmode
,
266 rtx table
, machine_mode slotmode
,
267 init_one_dwarf_reg_state
*init_state
)
269 const unsigned int dnum
= DWARF_FRAME_REGNUM (regno
);
270 const unsigned int rnum
= DWARF2_FRAME_REG_OUT (dnum
, 1);
271 const unsigned int dcol
= DWARF_REG_TO_UNWIND_COLUMN (rnum
);
273 const HOST_WIDE_INT slotoffset
= dcol
* GET_MODE_SIZE (slotmode
);
274 const HOST_WIDE_INT regsize
= GET_MODE_SIZE (regmode
);
276 init_state
->processed_regno
[regno
] = true;
278 if (rnum
>= DWARF_FRAME_REGISTERS
)
281 if (dnum
== DWARF_FRAME_RETURN_COLUMN
)
283 if (regmode
== VOIDmode
)
285 init_state
->wrote_return_column
= true;
291 emit_move_insn (adjust_address (table
, slotmode
, slotoffset
),
292 gen_int_mode (regsize
, slotmode
));
295 /* Generate code to initialize the dwarf register size table located
296 at the provided ADDRESS. */
299 expand_builtin_init_dwarf_reg_sizes (tree address
)
302 scalar_int_mode mode
= SCALAR_INT_TYPE_MODE (char_type_node
);
303 rtx addr
= expand_normal (address
);
304 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
306 init_one_dwarf_reg_state init_state
;
308 memset ((char *)&init_state
, 0, sizeof (init_state
));
310 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
312 machine_mode save_mode
;
315 /* No point in processing a register multiple times. This could happen
316 with register spans, e.g. when a reg is first processed as a piece of
317 a span, then as a register on its own later on. */
319 if (init_state
.processed_regno
[i
])
322 save_mode
= targetm
.dwarf_frame_reg_mode (i
);
323 span
= targetm
.dwarf_register_span (gen_rtx_REG (save_mode
, i
));
326 init_one_dwarf_reg_size (i
, save_mode
, mem
, mode
, &init_state
);
329 for (int si
= 0; si
< XVECLEN (span
, 0); si
++)
331 rtx reg
= XVECEXP (span
, 0, si
);
333 init_one_dwarf_reg_size
334 (REGNO (reg
), GET_MODE (reg
), mem
, mode
, &init_state
);
339 if (!init_state
.wrote_return_column
)
340 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
342 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
343 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
346 targetm
.init_dwarf_reg_sizes_extra (address
);
350 static dw_trace_info
*
351 get_trace_info (rtx_insn
*insn
)
355 return trace_index
->find_with_hash (&dummy
, INSN_UID (insn
));
359 save_point_p (rtx_insn
*insn
)
361 /* Labels, except those that are really jump tables. */
363 return inside_basic_block_p (insn
);
365 /* We split traces at the prologue/epilogue notes because those
366 are points at which the unwind info is usually stable. This
367 makes it easier to find spots with identical unwind info so
368 that we can use remember/restore_state opcodes. */
370 switch (NOTE_KIND (insn
))
372 case NOTE_INSN_PROLOGUE_END
:
373 case NOTE_INSN_EPILOGUE_BEG
:
380 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
382 static inline HOST_WIDE_INT
383 div_data_align (HOST_WIDE_INT off
)
385 HOST_WIDE_INT r
= off
/ DWARF_CIE_DATA_ALIGNMENT
;
386 gcc_assert (r
* DWARF_CIE_DATA_ALIGNMENT
== off
);
390 /* Return true if we need a signed version of a given opcode
391 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
394 need_data_align_sf_opcode (HOST_WIDE_INT off
)
396 return DWARF_CIE_DATA_ALIGNMENT
< 0 ? off
> 0 : off
< 0;
399 /* Return a pointer to a newly allocated Call Frame Instruction. */
401 static inline dw_cfi_ref
404 dw_cfi_ref cfi
= ggc_alloc
<dw_cfi_node
> ();
406 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
407 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
412 /* Return a newly allocated CFI row, with no defined data. */
417 dw_cfi_row
*row
= ggc_cleared_alloc
<dw_cfi_row
> ();
419 row
->cfa
.reg
= INVALID_REGNUM
;
424 /* Return a copy of an existing CFI row. */
427 copy_cfi_row (dw_cfi_row
*src
)
429 dw_cfi_row
*dst
= ggc_alloc
<dw_cfi_row
> ();
432 dst
->reg_save
= vec_safe_copy (src
->reg_save
);
437 /* Return a copy of an existing CFA location. */
439 static dw_cfa_location
*
440 copy_cfa (dw_cfa_location
*src
)
442 dw_cfa_location
*dst
= ggc_alloc
<dw_cfa_location
> ();
447 /* Generate a new label for the CFI info to refer to. */
450 dwarf2out_cfi_label (void)
452 int num
= dwarf2out_cfi_label_num
++;
455 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", num
);
457 return xstrdup (label
);
460 /* Add CFI either to the current insn stream or to a vector, or both. */
463 add_cfi (dw_cfi_ref cfi
)
465 any_cfis_emitted
= true;
467 if (add_cfi_insn
!= NULL
)
469 add_cfi_insn
= emit_note_after (NOTE_INSN_CFI
, add_cfi_insn
);
470 NOTE_CFI (add_cfi_insn
) = cfi
;
473 if (add_cfi_vec
!= NULL
)
474 vec_safe_push (*add_cfi_vec
, cfi
);
478 add_cfi_args_size (poly_int64 size
)
480 /* We don't yet have a representation for polynomial sizes. */
481 HOST_WIDE_INT const_size
= size
.to_constant ();
483 dw_cfi_ref cfi
= new_cfi ();
485 /* While we can occasionally have args_size < 0 internally, this state
486 should not persist at a point we actually need an opcode. */
487 gcc_assert (const_size
>= 0);
489 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
490 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= const_size
;
496 add_cfi_restore (unsigned reg
)
498 dw_cfi_ref cfi
= new_cfi ();
500 cfi
->dw_cfi_opc
= (reg
& ~0x3f ? DW_CFA_restore_extended
: DW_CFA_restore
);
501 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
506 /* Perform ROW->REG_SAVE[COLUMN] = CFI. CFI may be null, indicating
507 that the register column is no longer saved. */
510 update_row_reg_save (dw_cfi_row
*row
, unsigned column
, dw_cfi_ref cfi
)
512 if (vec_safe_length (row
->reg_save
) <= column
)
513 vec_safe_grow_cleared (row
->reg_save
, column
+ 1);
514 (*row
->reg_save
)[column
] = cfi
;
517 /* This function fills in aa dw_cfa_location structure from a dwarf location
518 descriptor sequence. */
521 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_node
*loc
)
523 struct dw_loc_descr_node
*ptr
;
525 cfa
->base_offset
= 0;
529 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
531 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
567 cfa
->reg
= op
- DW_OP_reg0
;
570 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
604 cfa
->reg
= op
- DW_OP_breg0
;
605 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
608 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
609 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
614 case DW_OP_plus_uconst
:
615 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
623 /* Find the previous value for the CFA, iteratively. CFI is the opcode
624 to interpret, *LOC will be updated as necessary, *REMEMBER is used for
625 one level of remember/restore state processing. */
628 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
, dw_cfa_location
*remember
)
630 switch (cfi
->dw_cfi_opc
)
632 case DW_CFA_def_cfa_offset
:
633 case DW_CFA_def_cfa_offset_sf
:
634 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
636 case DW_CFA_def_cfa_register
:
637 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
640 case DW_CFA_def_cfa_sf
:
641 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
642 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
644 case DW_CFA_def_cfa_expression
:
645 if (cfi
->dw_cfi_oprnd2
.dw_cfi_cfa_loc
)
646 *loc
= *cfi
->dw_cfi_oprnd2
.dw_cfi_cfa_loc
;
648 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
651 case DW_CFA_remember_state
:
652 gcc_assert (!remember
->in_use
);
654 remember
->in_use
= 1;
656 case DW_CFA_restore_state
:
657 gcc_assert (remember
->in_use
);
659 remember
->in_use
= 0;
667 /* Determine if two dw_cfa_location structures define the same data. */
670 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
672 return (loc1
->reg
== loc2
->reg
673 && known_eq (loc1
->offset
, loc2
->offset
)
674 && loc1
->indirect
== loc2
->indirect
675 && (loc1
->indirect
== 0
676 || known_eq (loc1
->base_offset
, loc2
->base_offset
)));
679 /* Determine if two CFI operands are identical. */
682 cfi_oprnd_equal_p (enum dw_cfi_oprnd_type t
, dw_cfi_oprnd
*a
, dw_cfi_oprnd
*b
)
686 case dw_cfi_oprnd_unused
:
688 case dw_cfi_oprnd_reg_num
:
689 return a
->dw_cfi_reg_num
== b
->dw_cfi_reg_num
;
690 case dw_cfi_oprnd_offset
:
691 return a
->dw_cfi_offset
== b
->dw_cfi_offset
;
692 case dw_cfi_oprnd_addr
:
693 return (a
->dw_cfi_addr
== b
->dw_cfi_addr
694 || strcmp (a
->dw_cfi_addr
, b
->dw_cfi_addr
) == 0);
695 case dw_cfi_oprnd_loc
:
696 return loc_descr_equal_p (a
->dw_cfi_loc
, b
->dw_cfi_loc
);
697 case dw_cfi_oprnd_cfa_loc
:
698 return cfa_equal_p (a
->dw_cfi_cfa_loc
, b
->dw_cfi_cfa_loc
);
703 /* Determine if two CFI entries are identical. */
706 cfi_equal_p (dw_cfi_ref a
, dw_cfi_ref b
)
708 enum dwarf_call_frame_info opc
;
710 /* Make things easier for our callers, including missing operands. */
713 if (a
== NULL
|| b
== NULL
)
716 /* Obviously, the opcodes must match. */
718 if (opc
!= b
->dw_cfi_opc
)
721 /* Compare the two operands, re-using the type of the operands as
722 already exposed elsewhere. */
723 return (cfi_oprnd_equal_p (dw_cfi_oprnd1_desc (opc
),
724 &a
->dw_cfi_oprnd1
, &b
->dw_cfi_oprnd1
)
725 && cfi_oprnd_equal_p (dw_cfi_oprnd2_desc (opc
),
726 &a
->dw_cfi_oprnd2
, &b
->dw_cfi_oprnd2
));
729 /* Determine if two CFI_ROW structures are identical. */
732 cfi_row_equal_p (dw_cfi_row
*a
, dw_cfi_row
*b
)
734 size_t i
, n_a
, n_b
, n_max
;
738 if (!cfi_equal_p (a
->cfa_cfi
, b
->cfa_cfi
))
741 else if (!cfa_equal_p (&a
->cfa
, &b
->cfa
))
744 n_a
= vec_safe_length (a
->reg_save
);
745 n_b
= vec_safe_length (b
->reg_save
);
746 n_max
= MAX (n_a
, n_b
);
748 for (i
= 0; i
< n_max
; ++i
)
750 dw_cfi_ref r_a
= NULL
, r_b
= NULL
;
753 r_a
= (*a
->reg_save
)[i
];
755 r_b
= (*b
->reg_save
)[i
];
757 if (!cfi_equal_p (r_a
, r_b
))
764 /* The CFA is now calculated from NEW_CFA. Consider OLD_CFA in determining
765 what opcode to emit. Returns the CFI opcode to effect the change, or
766 NULL if NEW_CFA == OLD_CFA. */
769 def_cfa_0 (dw_cfa_location
*old_cfa
, dw_cfa_location
*new_cfa
)
773 /* If nothing changed, no need to issue any call frame instructions. */
774 if (cfa_equal_p (old_cfa
, new_cfa
))
779 HOST_WIDE_INT const_offset
;
780 if (new_cfa
->reg
== old_cfa
->reg
781 && !new_cfa
->indirect
782 && !old_cfa
->indirect
783 && new_cfa
->offset
.is_constant (&const_offset
))
785 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
786 the CFA register did not change but the offset did. The data
787 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
788 in the assembler via the .cfi_def_cfa_offset directive. */
789 if (const_offset
< 0)
790 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
792 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
793 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= const_offset
;
795 else if (new_cfa
->offset
.is_constant ()
796 && known_eq (new_cfa
->offset
, old_cfa
->offset
)
797 && old_cfa
->reg
!= INVALID_REGNUM
798 && !new_cfa
->indirect
799 && !old_cfa
->indirect
)
801 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
802 indicating the CFA register has changed to <register> but the
803 offset has not changed. This requires the old CFA to have
804 been set as a register plus offset rather than a general
805 DW_CFA_def_cfa_expression. */
806 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
807 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= new_cfa
->reg
;
809 else if (new_cfa
->indirect
== 0
810 && new_cfa
->offset
.is_constant (&const_offset
))
812 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
813 indicating the CFA register has changed to <register> with
814 the specified offset. The data factoring for DW_CFA_def_cfa_sf
815 happens in output_cfi, or in the assembler via the .cfi_def_cfa
817 if (const_offset
< 0)
818 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
820 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
821 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= new_cfa
->reg
;
822 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= const_offset
;
826 /* Construct a DW_CFA_def_cfa_expression instruction to
827 calculate the CFA using a full location expression since no
828 register-offset pair is available. */
829 struct dw_loc_descr_node
*loc_list
;
831 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
832 loc_list
= build_cfa_loc (new_cfa
, 0);
833 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
834 if (!new_cfa
->offset
.is_constant ()
835 || !new_cfa
->base_offset
.is_constant ())
836 /* It's hard to reconstruct the CFA location for a polynomial
837 expression, so just cache it instead. */
838 cfi
->dw_cfi_oprnd2
.dw_cfi_cfa_loc
= copy_cfa (new_cfa
);
840 cfi
->dw_cfi_oprnd2
.dw_cfi_cfa_loc
= NULL
;
846 /* Similarly, but take OLD_CFA from CUR_ROW, and update it after the fact. */
849 def_cfa_1 (dw_cfa_location
*new_cfa
)
853 if (cur_trace
->cfa_store
.reg
== new_cfa
->reg
&& new_cfa
->indirect
== 0)
854 cur_trace
->cfa_store
.offset
= new_cfa
->offset
;
856 cfi
= def_cfa_0 (&cur_row
->cfa
, new_cfa
);
859 cur_row
->cfa
= *new_cfa
;
860 cur_row
->cfa_cfi
= (cfi
->dw_cfi_opc
== DW_CFA_def_cfa_expression
867 /* Add the CFI for saving a register. REG is the CFA column number.
868 If SREG is -1, the register is saved at OFFSET from the CFA;
869 otherwise it is saved in SREG. */
872 reg_save (unsigned int reg
, unsigned int sreg
, poly_int64 offset
)
874 dw_fde_ref fde
= cfun
? cfun
->fde
: NULL
;
875 dw_cfi_ref cfi
= new_cfi ();
877 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
879 if (sreg
== INVALID_REGNUM
)
881 HOST_WIDE_INT const_offset
;
882 /* When stack is aligned, store REG using DW_CFA_expression with FP. */
883 if (fde
&& fde
->stack_realign
)
885 cfi
->dw_cfi_opc
= DW_CFA_expression
;
886 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
887 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
888 = build_cfa_aligned_loc (&cur_row
->cfa
, offset
,
889 fde
->stack_realignment
);
891 else if (offset
.is_constant (&const_offset
))
893 if (need_data_align_sf_opcode (const_offset
))
894 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
895 else if (reg
& ~0x3f)
896 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
898 cfi
->dw_cfi_opc
= DW_CFA_offset
;
899 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= const_offset
;
903 cfi
->dw_cfi_opc
= DW_CFA_expression
;
904 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
905 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
906 = build_cfa_loc (&cur_row
->cfa
, offset
);
909 else if (sreg
== reg
)
911 /* While we could emit something like DW_CFA_same_value or
912 DW_CFA_restore, we never expect to see something like that
913 in a prologue. This is more likely to be a bug. A backend
914 can always bypass this by using REG_CFA_RESTORE directly. */
919 cfi
->dw_cfi_opc
= DW_CFA_register
;
920 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
924 update_row_reg_save (cur_row
, reg
, cfi
);
927 /* A subroutine of scan_trace. Check INSN for a REG_ARGS_SIZE note
928 and adjust data structures to match. */
931 notice_args_size (rtx_insn
*insn
)
933 poly_int64 args_size
, delta
;
936 note
= find_reg_note (insn
, REG_ARGS_SIZE
, NULL
);
940 args_size
= get_args_size (note
);
941 delta
= args_size
- cur_trace
->end_true_args_size
;
942 if (known_eq (delta
, 0))
945 cur_trace
->end_true_args_size
= args_size
;
947 /* If the CFA is computed off the stack pointer, then we must adjust
948 the computation of the CFA as well. */
949 if (cur_cfa
->reg
== dw_stack_pointer_regnum
)
951 gcc_assert (!cur_cfa
->indirect
);
953 /* Convert a change in args_size (always a positive in the
954 direction of stack growth) to a change in stack pointer. */
955 if (!STACK_GROWS_DOWNWARD
)
958 cur_cfa
->offset
+= delta
;
962 /* A subroutine of scan_trace. INSN is can_throw_internal. Update the
963 data within the trace related to EH insns and args_size. */
966 notice_eh_throw (rtx_insn
*insn
)
968 poly_int64 args_size
= cur_trace
->end_true_args_size
;
969 if (cur_trace
->eh_head
== NULL
)
971 cur_trace
->eh_head
= insn
;
972 cur_trace
->beg_delay_args_size
= args_size
;
973 cur_trace
->end_delay_args_size
= args_size
;
975 else if (maybe_ne (cur_trace
->end_delay_args_size
, args_size
))
977 cur_trace
->end_delay_args_size
= args_size
;
979 /* ??? If the CFA is the stack pointer, search backward for the last
980 CFI note and insert there. Given that the stack changed for the
981 args_size change, there *must* be such a note in between here and
983 add_cfi_args_size (args_size
);
987 /* Short-hand inline for the very common D_F_R (REGNO (x)) operation. */
988 /* ??? This ought to go into dwarf2out.h, except that dwarf2out.h is
989 used in places where rtl is prohibited. */
991 static inline unsigned
992 dwf_regno (const_rtx reg
)
994 gcc_assert (REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
995 return DWARF_FRAME_REGNUM (REGNO (reg
));
998 /* Compare X and Y for equivalence. The inputs may be REGs or PC_RTX. */
1001 compare_reg_or_pc (rtx x
, rtx y
)
1003 if (REG_P (x
) && REG_P (y
))
1004 return REGNO (x
) == REGNO (y
);
1008 /* Record SRC as being saved in DEST. DEST may be null to delete an
1009 existing entry. SRC may be a register or PC_RTX. */
1012 record_reg_saved_in_reg (rtx dest
, rtx src
)
1014 reg_saved_in_data
*elt
;
1017 FOR_EACH_VEC_ELT (cur_trace
->regs_saved_in_regs
, i
, elt
)
1018 if (compare_reg_or_pc (elt
->orig_reg
, src
))
1021 cur_trace
->regs_saved_in_regs
.unordered_remove (i
);
1023 elt
->saved_in_reg
= dest
;
1030 reg_saved_in_data e
= {src
, dest
};
1031 cur_trace
->regs_saved_in_regs
.safe_push (e
);
1034 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1035 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1038 queue_reg_save (rtx reg
, rtx sreg
, poly_int64 offset
)
1041 queued_reg_save e
= {reg
, sreg
, offset
};
1044 /* Duplicates waste space, but it's also necessary to remove them
1045 for correctness, since the queue gets output in reverse order. */
1046 FOR_EACH_VEC_ELT (queued_reg_saves
, i
, q
)
1047 if (compare_reg_or_pc (q
->reg
, reg
))
1053 queued_reg_saves
.safe_push (e
);
1056 /* Output all the entries in QUEUED_REG_SAVES. */
1059 dwarf2out_flush_queued_reg_saves (void)
1064 FOR_EACH_VEC_ELT (queued_reg_saves
, i
, q
)
1066 unsigned int reg
, sreg
;
1068 record_reg_saved_in_reg (q
->saved_reg
, q
->reg
);
1070 if (q
->reg
== pc_rtx
)
1071 reg
= DWARF_FRAME_RETURN_COLUMN
;
1073 reg
= dwf_regno (q
->reg
);
1075 sreg
= dwf_regno (q
->saved_reg
);
1077 sreg
= INVALID_REGNUM
;
1078 reg_save (reg
, sreg
, q
->cfa_offset
);
1081 queued_reg_saves
.truncate (0);
1084 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1085 location for? Or, does it clobber a register which we've previously
1086 said that some other register is saved in, and for which we now
1087 have a new location for? */
1090 clobbers_queued_reg_save (const_rtx insn
)
1095 FOR_EACH_VEC_ELT (queued_reg_saves
, iq
, q
)
1098 reg_saved_in_data
*rir
;
1100 if (modified_in_p (q
->reg
, insn
))
1103 FOR_EACH_VEC_ELT (cur_trace
->regs_saved_in_regs
, ir
, rir
)
1104 if (compare_reg_or_pc (q
->reg
, rir
->orig_reg
)
1105 && modified_in_p (rir
->saved_in_reg
, insn
))
1112 /* What register, if any, is currently saved in REG? */
1115 reg_saved_in (rtx reg
)
1117 unsigned int regn
= REGNO (reg
);
1119 reg_saved_in_data
*rir
;
1122 FOR_EACH_VEC_ELT (queued_reg_saves
, i
, q
)
1123 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1126 FOR_EACH_VEC_ELT (cur_trace
->regs_saved_in_regs
, i
, rir
)
1127 if (regn
== REGNO (rir
->saved_in_reg
))
1128 return rir
->orig_reg
;
1133 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1136 dwarf2out_frame_debug_def_cfa (rtx pat
)
1138 memset (cur_cfa
, 0, sizeof (*cur_cfa
));
1140 pat
= strip_offset (pat
, &cur_cfa
->offset
);
1143 cur_cfa
->indirect
= 1;
1144 pat
= strip_offset (XEXP (pat
, 0), &cur_cfa
->base_offset
);
1146 /* ??? If this fails, we could be calling into the _loc functions to
1147 define a full expression. So far no port does that. */
1148 gcc_assert (REG_P (pat
));
1149 cur_cfa
->reg
= dwf_regno (pat
);
1152 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1155 dwarf2out_frame_debug_adjust_cfa (rtx pat
)
1159 gcc_assert (GET_CODE (pat
) == SET
);
1160 dest
= XEXP (pat
, 0);
1161 src
= XEXP (pat
, 1);
1163 switch (GET_CODE (src
))
1166 gcc_assert (dwf_regno (XEXP (src
, 0)) == cur_cfa
->reg
);
1167 cur_cfa
->offset
-= rtx_to_poly_int64 (XEXP (src
, 1));
1177 cur_cfa
->reg
= dwf_regno (dest
);
1178 gcc_assert (cur_cfa
->indirect
== 0);
1181 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1184 dwarf2out_frame_debug_cfa_offset (rtx set
)
1187 rtx src
, addr
, span
;
1188 unsigned int sregno
;
1190 src
= XEXP (set
, 1);
1191 addr
= XEXP (set
, 0);
1192 gcc_assert (MEM_P (addr
));
1193 addr
= XEXP (addr
, 0);
1195 /* As documented, only consider extremely simple addresses. */
1196 switch (GET_CODE (addr
))
1199 gcc_assert (dwf_regno (addr
) == cur_cfa
->reg
);
1200 offset
= -cur_cfa
->offset
;
1203 gcc_assert (dwf_regno (XEXP (addr
, 0)) == cur_cfa
->reg
);
1204 offset
= rtx_to_poly_int64 (XEXP (addr
, 1)) - cur_cfa
->offset
;
1213 sregno
= DWARF_FRAME_RETURN_COLUMN
;
1217 span
= targetm
.dwarf_register_span (src
);
1218 sregno
= dwf_regno (src
);
1221 /* ??? We'd like to use queue_reg_save, but we need to come up with
1222 a different flushing heuristic for epilogues. */
1224 reg_save (sregno
, INVALID_REGNUM
, offset
);
1227 /* We have a PARALLEL describing where the contents of SRC live.
1228 Adjust the offset for each piece of the PARALLEL. */
1229 poly_int64 span_offset
= offset
;
1231 gcc_assert (GET_CODE (span
) == PARALLEL
);
1233 const int par_len
= XVECLEN (span
, 0);
1234 for (int par_index
= 0; par_index
< par_len
; par_index
++)
1236 rtx elem
= XVECEXP (span
, 0, par_index
);
1237 sregno
= dwf_regno (src
);
1238 reg_save (sregno
, INVALID_REGNUM
, span_offset
);
1239 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
1244 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1247 dwarf2out_frame_debug_cfa_register (rtx set
)
1250 unsigned sregno
, dregno
;
1252 src
= XEXP (set
, 1);
1253 dest
= XEXP (set
, 0);
1255 record_reg_saved_in_reg (dest
, src
);
1257 sregno
= DWARF_FRAME_RETURN_COLUMN
;
1259 sregno
= dwf_regno (src
);
1261 dregno
= dwf_regno (dest
);
1263 /* ??? We'd like to use queue_reg_save, but we need to come up with
1264 a different flushing heuristic for epilogues. */
1265 reg_save (sregno
, dregno
, 0);
1268 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
1271 dwarf2out_frame_debug_cfa_expression (rtx set
)
1273 rtx src
, dest
, span
;
1274 dw_cfi_ref cfi
= new_cfi ();
1277 dest
= SET_DEST (set
);
1278 src
= SET_SRC (set
);
1280 gcc_assert (REG_P (src
));
1281 gcc_assert (MEM_P (dest
));
1283 span
= targetm
.dwarf_register_span (src
);
1286 regno
= dwf_regno (src
);
1288 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1289 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= regno
;
1290 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1291 = mem_loc_descriptor (XEXP (dest
, 0), get_address_mode (dest
),
1292 GET_MODE (dest
), VAR_INIT_STATUS_INITIALIZED
);
1294 /* ??? We'd like to use queue_reg_save, were the interface different,
1295 and, as above, we could manage flushing for epilogues. */
1297 update_row_reg_save (cur_row
, regno
, cfi
);
1300 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_VAL_EXPRESSION
1304 dwarf2out_frame_debug_cfa_val_expression (rtx set
)
1306 rtx dest
= SET_DEST (set
);
1307 gcc_assert (REG_P (dest
));
1309 rtx span
= targetm
.dwarf_register_span (dest
);
1312 rtx src
= SET_SRC (set
);
1313 dw_cfi_ref cfi
= new_cfi ();
1314 cfi
->dw_cfi_opc
= DW_CFA_val_expression
;
1315 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= dwf_regno (dest
);
1316 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1317 = mem_loc_descriptor (src
, GET_MODE (src
),
1318 GET_MODE (dest
), VAR_INIT_STATUS_INITIALIZED
);
1320 update_row_reg_save (cur_row
, dwf_regno (dest
), cfi
);
1323 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
1326 dwarf2out_frame_debug_cfa_restore (rtx reg
)
1328 gcc_assert (REG_P (reg
));
1330 rtx span
= targetm
.dwarf_register_span (reg
);
1333 unsigned int regno
= dwf_regno (reg
);
1334 add_cfi_restore (regno
);
1335 update_row_reg_save (cur_row
, regno
, NULL
);
1339 /* We have a PARALLEL describing where the contents of REG live.
1340 Restore the register for each piece of the PARALLEL. */
1341 gcc_assert (GET_CODE (span
) == PARALLEL
);
1343 const int par_len
= XVECLEN (span
, 0);
1344 for (int par_index
= 0; par_index
< par_len
; par_index
++)
1346 reg
= XVECEXP (span
, 0, par_index
);
1347 gcc_assert (REG_P (reg
));
1348 unsigned int regno
= dwf_regno (reg
);
1349 add_cfi_restore (regno
);
1350 update_row_reg_save (cur_row
, regno
, NULL
);
1355 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE.
1356 ??? Perhaps we should note in the CIE where windows are saved (instead of
1357 assuming 0(cfa)) and what registers are in the window. */
1360 dwarf2out_frame_debug_cfa_window_save (void)
1362 dw_cfi_ref cfi
= new_cfi ();
1364 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
1368 /* Record call frame debugging information for an expression EXPR,
1369 which either sets SP or FP (adjusting how we calculate the frame
1370 address) or saves a register to the stack or another register.
1371 LABEL indicates the address of EXPR.
1373 This function encodes a state machine mapping rtxes to actions on
1374 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1375 users need not read the source code.
1377 The High-Level Picture
1379 Changes in the register we use to calculate the CFA: Currently we
1380 assume that if you copy the CFA register into another register, we
1381 should take the other one as the new CFA register; this seems to
1382 work pretty well. If it's wrong for some target, it's simple
1383 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1385 Changes in the register we use for saving registers to the stack:
1386 This is usually SP, but not always. Again, we deduce that if you
1387 copy SP into another register (and SP is not the CFA register),
1388 then the new register is the one we will be using for register
1389 saves. This also seems to work.
1391 Register saves: There's not much guesswork about this one; if
1392 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1393 register save, and the register used to calculate the destination
1394 had better be the one we think we're using for this purpose.
1395 It's also assumed that a copy from a call-saved register to another
1396 register is saving that register if RTX_FRAME_RELATED_P is set on
1397 that instruction. If the copy is from a call-saved register to
1398 the *same* register, that means that the register is now the same
1399 value as in the caller.
1401 Except: If the register being saved is the CFA register, and the
1402 offset is nonzero, we are saving the CFA, so we assume we have to
1403 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1404 the intent is to save the value of SP from the previous frame.
1406 In addition, if a register has previously been saved to a different
1409 Invariants / Summaries of Rules
1411 cfa current rule for calculating the CFA. It usually
1412 consists of a register and an offset. This is
1413 actually stored in *cur_cfa, but abbreviated
1414 for the purposes of this documentation.
1415 cfa_store register used by prologue code to save things to the stack
1416 cfa_store.offset is the offset from the value of
1417 cfa_store.reg to the actual CFA
1418 cfa_temp register holding an integral value. cfa_temp.offset
1419 stores the value, which will be used to adjust the
1420 stack pointer. cfa_temp is also used like cfa_store,
1421 to track stores to the stack via fp or a temp reg.
1423 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1424 with cfa.reg as the first operand changes the cfa.reg and its
1425 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1428 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1429 expression yielding a constant. This sets cfa_temp.reg
1430 and cfa_temp.offset.
1432 Rule 5: Create a new register cfa_store used to save items to the
1435 Rules 10-14: Save a register to the stack. Define offset as the
1436 difference of the original location and cfa_store's
1437 location (or cfa_temp's location if cfa_temp is used).
1439 Rules 16-20: If AND operation happens on sp in prologue, we assume
1440 stack is realigned. We will use a group of DW_OP_XXX
1441 expressions to represent the location of the stored
1442 register instead of CFA+offset.
1446 "{a,b}" indicates a choice of a xor b.
1447 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1450 (set <reg1> <reg2>:cfa.reg)
1451 effects: cfa.reg = <reg1>
1452 cfa.offset unchanged
1453 cfa_temp.reg = <reg1>
1454 cfa_temp.offset = cfa.offset
1457 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1458 {<const_int>,<reg>:cfa_temp.reg}))
1459 effects: cfa.reg = sp if fp used
1460 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1461 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1462 if cfa_store.reg==sp
1465 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1466 effects: cfa.reg = fp
1467 cfa_offset += +/- <const_int>
1470 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1471 constraints: <reg1> != fp
1473 effects: cfa.reg = <reg1>
1474 cfa_temp.reg = <reg1>
1475 cfa_temp.offset = cfa.offset
1478 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1479 constraints: <reg1> != fp
1481 effects: cfa_store.reg = <reg1>
1482 cfa_store.offset = cfa.offset - cfa_temp.offset
1485 (set <reg> <const_int>)
1486 effects: cfa_temp.reg = <reg>
1487 cfa_temp.offset = <const_int>
1490 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1491 effects: cfa_temp.reg = <reg1>
1492 cfa_temp.offset |= <const_int>
1495 (set <reg> (high <exp>))
1499 (set <reg> (lo_sum <exp> <const_int>))
1500 effects: cfa_temp.reg = <reg>
1501 cfa_temp.offset = <const_int>
1504 (set (mem ({pre,post}_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1505 effects: cfa_store.offset -= <const_int>
1506 cfa.offset = cfa_store.offset if cfa.reg == sp
1508 cfa.base_offset = -cfa_store.offset
1511 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
1512 effects: cfa_store.offset += -/+ mode_size(mem)
1513 cfa.offset = cfa_store.offset if cfa.reg == sp
1515 cfa.base_offset = -cfa_store.offset
1518 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1521 effects: cfa.reg = <reg1>
1522 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1525 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1526 effects: cfa.reg = <reg1>
1527 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1530 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
1531 effects: cfa.reg = <reg1>
1532 cfa.base_offset = -cfa_temp.offset
1533 cfa_temp.offset -= mode_size(mem)
1536 (set <reg> {unspec, unspec_volatile})
1537 effects: target-dependent
1540 (set sp (and: sp <const_int>))
1541 constraints: cfa_store.reg == sp
1542 effects: cfun->fde.stack_realign = 1
1543 cfa_store.offset = 0
1544 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1547 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1548 effects: cfa_store.offset += -/+ mode_size(mem)
1551 (set (mem ({pre_inc, pre_dec} sp)) fp)
1552 constraints: fde->stack_realign == 1
1553 effects: cfa_store.offset = 0
1554 cfa.reg != HARD_FRAME_POINTER_REGNUM
1557 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1558 constraints: fde->stack_realign == 1
1560 && cfa.indirect == 0
1561 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1562 effects: Use DW_CFA_def_cfa_expression to define cfa
1563 cfa.reg == fde->drap_reg */
1566 dwarf2out_frame_debug_expr (rtx expr
)
1568 rtx src
, dest
, span
;
1572 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1573 the PARALLEL independently. The first element is always processed if
1574 it is a SET. This is for backward compatibility. Other elements
1575 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1576 flag is set in them. */
1577 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1580 int limit
= XVECLEN (expr
, 0);
1583 /* PARALLELs have strict read-modify-write semantics, so we
1584 ought to evaluate every rvalue before changing any lvalue.
1585 It's cumbersome to do that in general, but there's an
1586 easy approximation that is enough for all current users:
1587 handle register saves before register assignments. */
1588 if (GET_CODE (expr
) == PARALLEL
)
1589 for (par_index
= 0; par_index
< limit
; par_index
++)
1591 elem
= XVECEXP (expr
, 0, par_index
);
1592 if (GET_CODE (elem
) == SET
1593 && MEM_P (SET_DEST (elem
))
1594 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1595 dwarf2out_frame_debug_expr (elem
);
1598 for (par_index
= 0; par_index
< limit
; par_index
++)
1600 elem
= XVECEXP (expr
, 0, par_index
);
1601 if (GET_CODE (elem
) == SET
1602 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
1603 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1604 dwarf2out_frame_debug_expr (elem
);
1609 gcc_assert (GET_CODE (expr
) == SET
);
1611 src
= SET_SRC (expr
);
1612 dest
= SET_DEST (expr
);
1616 rtx rsi
= reg_saved_in (src
);
1623 switch (GET_CODE (dest
))
1626 switch (GET_CODE (src
))
1628 /* Setting FP from SP. */
1630 if (cur_cfa
->reg
== dwf_regno (src
))
1633 /* Update the CFA rule wrt SP or FP. Make sure src is
1634 relative to the current CFA register.
1636 We used to require that dest be either SP or FP, but the
1637 ARM copies SP to a temporary register, and from there to
1638 FP. So we just rely on the backends to only set
1639 RTX_FRAME_RELATED_P on appropriate insns. */
1640 cur_cfa
->reg
= dwf_regno (dest
);
1641 cur_trace
->cfa_temp
.reg
= cur_cfa
->reg
;
1642 cur_trace
->cfa_temp
.offset
= cur_cfa
->offset
;
1646 /* Saving a register in a register. */
1647 gcc_assert (!fixed_regs
[REGNO (dest
)]
1648 /* For the SPARC and its register window. */
1649 || (dwf_regno (src
) == DWARF_FRAME_RETURN_COLUMN
));
1651 /* After stack is aligned, we can only save SP in FP
1652 if drap register is used. In this case, we have
1653 to restore stack pointer with the CFA value and we
1654 don't generate this DWARF information. */
1656 && fde
->stack_realign
1657 && REGNO (src
) == STACK_POINTER_REGNUM
)
1658 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
1659 && fde
->drap_reg
!= INVALID_REGNUM
1660 && cur_cfa
->reg
!= dwf_regno (src
));
1662 queue_reg_save (src
, dest
, 0);
1669 if (dest
== stack_pointer_rtx
)
1673 if (REG_P (XEXP (src
, 1)))
1675 gcc_assert (dwf_regno (XEXP (src
, 1))
1676 == cur_trace
->cfa_temp
.reg
);
1677 offset
= cur_trace
->cfa_temp
.offset
;
1679 else if (!poly_int_rtx_p (XEXP (src
, 1), &offset
))
1682 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1684 /* Restoring SP from FP in the epilogue. */
1685 gcc_assert (cur_cfa
->reg
== dw_frame_pointer_regnum
);
1686 cur_cfa
->reg
= dw_stack_pointer_regnum
;
1688 else if (GET_CODE (src
) == LO_SUM
)
1689 /* Assume we've set the source reg of the LO_SUM from sp. */
1692 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
1694 if (GET_CODE (src
) != MINUS
)
1696 if (cur_cfa
->reg
== dw_stack_pointer_regnum
)
1697 cur_cfa
->offset
+= offset
;
1698 if (cur_trace
->cfa_store
.reg
== dw_stack_pointer_regnum
)
1699 cur_trace
->cfa_store
.offset
+= offset
;
1701 else if (dest
== hard_frame_pointer_rtx
)
1704 /* Either setting the FP from an offset of the SP,
1705 or adjusting the FP */
1706 gcc_assert (frame_pointer_needed
);
1708 gcc_assert (REG_P (XEXP (src
, 0))
1709 && dwf_regno (XEXP (src
, 0)) == cur_cfa
->reg
);
1710 offset
= rtx_to_poly_int64 (XEXP (src
, 1));
1711 if (GET_CODE (src
) != MINUS
)
1713 cur_cfa
->offset
+= offset
;
1714 cur_cfa
->reg
= dw_frame_pointer_regnum
;
1718 gcc_assert (GET_CODE (src
) != MINUS
);
1721 if (REG_P (XEXP (src
, 0))
1722 && dwf_regno (XEXP (src
, 0)) == cur_cfa
->reg
1723 && poly_int_rtx_p (XEXP (src
, 1), &offset
))
1725 /* Setting a temporary CFA register that will be copied
1726 into the FP later on. */
1728 cur_cfa
->offset
+= offset
;
1729 cur_cfa
->reg
= dwf_regno (dest
);
1730 /* Or used to save regs to the stack. */
1731 cur_trace
->cfa_temp
.reg
= cur_cfa
->reg
;
1732 cur_trace
->cfa_temp
.offset
= cur_cfa
->offset
;
1736 else if (REG_P (XEXP (src
, 0))
1737 && dwf_regno (XEXP (src
, 0)) == cur_trace
->cfa_temp
.reg
1738 && XEXP (src
, 1) == stack_pointer_rtx
)
1740 /* Setting a scratch register that we will use instead
1741 of SP for saving registers to the stack. */
1742 gcc_assert (cur_cfa
->reg
== dw_stack_pointer_regnum
);
1743 cur_trace
->cfa_store
.reg
= dwf_regno (dest
);
1744 cur_trace
->cfa_store
.offset
1745 = cur_cfa
->offset
- cur_trace
->cfa_temp
.offset
;
1749 else if (GET_CODE (src
) == LO_SUM
1750 && poly_int_rtx_p (XEXP (src
, 1),
1751 &cur_trace
->cfa_temp
.offset
))
1752 cur_trace
->cfa_temp
.reg
= dwf_regno (dest
);
1761 cur_trace
->cfa_temp
.reg
= dwf_regno (dest
);
1762 cur_trace
->cfa_temp
.offset
= rtx_to_poly_int64 (src
);
1767 gcc_assert (REG_P (XEXP (src
, 0))
1768 && dwf_regno (XEXP (src
, 0)) == cur_trace
->cfa_temp
.reg
1769 && CONST_INT_P (XEXP (src
, 1)));
1771 cur_trace
->cfa_temp
.reg
= dwf_regno (dest
);
1772 if (!can_ior_p (cur_trace
->cfa_temp
.offset
, INTVAL (XEXP (src
, 1)),
1773 &cur_trace
->cfa_temp
.offset
))
1774 /* The target shouldn't generate this kind of CFI note if we
1775 can't represent it. */
1779 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1780 which will fill in all of the bits. */
1787 case UNSPEC_VOLATILE
:
1788 /* All unspecs should be represented by REG_CFA_* notes. */
1794 /* If this AND operation happens on stack pointer in prologue,
1795 we assume the stack is realigned and we extract the
1797 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
1799 /* We interpret reg_save differently with stack_realign set.
1800 Thus we must flush whatever we have queued first. */
1801 dwarf2out_flush_queued_reg_saves ();
1803 gcc_assert (cur_trace
->cfa_store
.reg
1804 == dwf_regno (XEXP (src
, 0)));
1805 fde
->stack_realign
= 1;
1806 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
1807 cur_trace
->cfa_store
.offset
= 0;
1809 if (cur_cfa
->reg
!= dw_stack_pointer_regnum
1810 && cur_cfa
->reg
!= dw_frame_pointer_regnum
)
1811 fde
->drap_reg
= cur_cfa
->reg
;
1822 /* Saving a register to the stack. Make sure dest is relative to the
1824 switch (GET_CODE (XEXP (dest
, 0)))
1830 /* We can't handle variable size modifications. */
1831 offset
= -rtx_to_poly_int64 (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1833 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
1834 && cur_trace
->cfa_store
.reg
== dw_stack_pointer_regnum
);
1836 cur_trace
->cfa_store
.offset
+= offset
;
1837 if (cur_cfa
->reg
== dw_stack_pointer_regnum
)
1838 cur_cfa
->offset
= cur_trace
->cfa_store
.offset
;
1840 if (GET_CODE (XEXP (dest
, 0)) == POST_MODIFY
)
1841 offset
-= cur_trace
->cfa_store
.offset
;
1843 offset
= -cur_trace
->cfa_store
.offset
;
1850 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1851 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1854 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
1855 == STACK_POINTER_REGNUM
)
1856 && cur_trace
->cfa_store
.reg
== dw_stack_pointer_regnum
);
1858 cur_trace
->cfa_store
.offset
+= offset
;
1860 /* Rule 18: If stack is aligned, we will use FP as a
1861 reference to represent the address of the stored
1864 && fde
->stack_realign
1866 && REGNO (src
) == HARD_FRAME_POINTER_REGNUM
)
1868 gcc_assert (cur_cfa
->reg
!= dw_frame_pointer_regnum
);
1869 cur_trace
->cfa_store
.offset
= 0;
1872 if (cur_cfa
->reg
== dw_stack_pointer_regnum
)
1873 cur_cfa
->offset
= cur_trace
->cfa_store
.offset
;
1875 if (GET_CODE (XEXP (dest
, 0)) == POST_DEC
)
1876 offset
+= -cur_trace
->cfa_store
.offset
;
1878 offset
= -cur_trace
->cfa_store
.offset
;
1882 /* With an offset. */
1889 gcc_assert (REG_P (XEXP (XEXP (dest
, 0), 0)));
1890 offset
= rtx_to_poly_int64 (XEXP (XEXP (dest
, 0), 1));
1891 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1894 regno
= dwf_regno (XEXP (XEXP (dest
, 0), 0));
1896 if (cur_cfa
->reg
== regno
)
1897 offset
-= cur_cfa
->offset
;
1898 else if (cur_trace
->cfa_store
.reg
== regno
)
1899 offset
-= cur_trace
->cfa_store
.offset
;
1902 gcc_assert (cur_trace
->cfa_temp
.reg
== regno
);
1903 offset
-= cur_trace
->cfa_temp
.offset
;
1909 /* Without an offset. */
1912 unsigned int regno
= dwf_regno (XEXP (dest
, 0));
1914 if (cur_cfa
->reg
== regno
)
1915 offset
= -cur_cfa
->offset
;
1916 else if (cur_trace
->cfa_store
.reg
== regno
)
1917 offset
= -cur_trace
->cfa_store
.offset
;
1920 gcc_assert (cur_trace
->cfa_temp
.reg
== regno
);
1921 offset
= -cur_trace
->cfa_temp
.offset
;
1928 gcc_assert (cur_trace
->cfa_temp
.reg
1929 == dwf_regno (XEXP (XEXP (dest
, 0), 0)));
1930 offset
= -cur_trace
->cfa_temp
.offset
;
1931 cur_trace
->cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1939 /* If the source operand of this MEM operation is a memory,
1940 we only care how much stack grew. */
1945 && REGNO (src
) != STACK_POINTER_REGNUM
1946 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1947 && dwf_regno (src
) == cur_cfa
->reg
)
1949 /* We're storing the current CFA reg into the stack. */
1951 if (known_eq (cur_cfa
->offset
, 0))
1954 /* If stack is aligned, putting CFA reg into stack means
1955 we can no longer use reg + offset to represent CFA.
1956 Here we use DW_CFA_def_cfa_expression instead. The
1957 result of this expression equals to the original CFA
1960 && fde
->stack_realign
1961 && cur_cfa
->indirect
== 0
1962 && cur_cfa
->reg
!= dw_frame_pointer_regnum
)
1964 gcc_assert (fde
->drap_reg
== cur_cfa
->reg
);
1966 cur_cfa
->indirect
= 1;
1967 cur_cfa
->reg
= dw_frame_pointer_regnum
;
1968 cur_cfa
->base_offset
= offset
;
1969 cur_cfa
->offset
= 0;
1971 fde
->drap_reg_saved
= 1;
1975 /* If the source register is exactly the CFA, assume
1976 we're saving SP like any other register; this happens
1978 queue_reg_save (stack_pointer_rtx
, NULL_RTX
, offset
);
1983 /* Otherwise, we'll need to look in the stack to
1984 calculate the CFA. */
1985 rtx x
= XEXP (dest
, 0);
1989 gcc_assert (REG_P (x
));
1991 cur_cfa
->reg
= dwf_regno (x
);
1992 cur_cfa
->base_offset
= offset
;
1993 cur_cfa
->indirect
= 1;
1999 span
= targetm
.dwarf_register_span (src
);
2004 queue_reg_save (src
, NULL_RTX
, offset
);
2007 /* We have a PARALLEL describing where the contents of SRC live.
2008 Queue register saves for each piece of the PARALLEL. */
2009 poly_int64 span_offset
= offset
;
2011 gcc_assert (GET_CODE (span
) == PARALLEL
);
2013 const int par_len
= XVECLEN (span
, 0);
2014 for (int par_index
= 0; par_index
< par_len
; par_index
++)
2016 rtx elem
= XVECEXP (span
, 0, par_index
);
2017 queue_reg_save (elem
, NULL_RTX
, span_offset
);
2018 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2028 /* Record call frame debugging information for INSN, which either sets
2029 SP or FP (adjusting how we calculate the frame address) or saves a
2030 register to the stack. */
2033 dwarf2out_frame_debug (rtx_insn
*insn
)
2036 bool handled_one
= false;
2038 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
2039 switch (REG_NOTE_KIND (note
))
2041 case REG_FRAME_RELATED_EXPR
:
2042 pat
= XEXP (note
, 0);
2045 case REG_CFA_DEF_CFA
:
2046 dwarf2out_frame_debug_def_cfa (XEXP (note
, 0));
2050 case REG_CFA_ADJUST_CFA
:
2055 if (GET_CODE (n
) == PARALLEL
)
2056 n
= XVECEXP (n
, 0, 0);
2058 dwarf2out_frame_debug_adjust_cfa (n
);
2062 case REG_CFA_OFFSET
:
2065 n
= single_set (insn
);
2066 dwarf2out_frame_debug_cfa_offset (n
);
2070 case REG_CFA_REGISTER
:
2075 if (GET_CODE (n
) == PARALLEL
)
2076 n
= XVECEXP (n
, 0, 0);
2078 dwarf2out_frame_debug_cfa_register (n
);
2082 case REG_CFA_EXPRESSION
:
2083 case REG_CFA_VAL_EXPRESSION
:
2086 n
= single_set (insn
);
2088 if (REG_NOTE_KIND (note
) == REG_CFA_EXPRESSION
)
2089 dwarf2out_frame_debug_cfa_expression (n
);
2091 dwarf2out_frame_debug_cfa_val_expression (n
);
2096 case REG_CFA_RESTORE
:
2101 if (GET_CODE (n
) == PARALLEL
)
2102 n
= XVECEXP (n
, 0, 0);
2105 dwarf2out_frame_debug_cfa_restore (n
);
2109 case REG_CFA_SET_VDRAP
:
2113 dw_fde_ref fde
= cfun
->fde
;
2116 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
2118 fde
->vdrap_reg
= dwf_regno (n
);
2124 case REG_CFA_TOGGLE_RA_MANGLE
:
2125 case REG_CFA_WINDOW_SAVE
:
2126 /* We overload both of these operations onto the same DWARF opcode. */
2127 dwarf2out_frame_debug_cfa_window_save ();
2131 case REG_CFA_FLUSH_QUEUE
:
2132 /* The actual flush happens elsewhere. */
2142 pat
= PATTERN (insn
);
2144 dwarf2out_frame_debug_expr (pat
);
2146 /* Check again. A parallel can save and update the same register.
2147 We could probably check just once, here, but this is safer than
2148 removing the check at the start of the function. */
2149 if (clobbers_queued_reg_save (pat
))
2150 dwarf2out_flush_queued_reg_saves ();
2154 /* Emit CFI info to change the state from OLD_ROW to NEW_ROW. */
2157 change_cfi_row (dw_cfi_row
*old_row
, dw_cfi_row
*new_row
)
2159 size_t i
, n_old
, n_new
, n_max
;
2162 if (new_row
->cfa_cfi
&& !cfi_equal_p (old_row
->cfa_cfi
, new_row
->cfa_cfi
))
2163 add_cfi (new_row
->cfa_cfi
);
2166 cfi
= def_cfa_0 (&old_row
->cfa
, &new_row
->cfa
);
2171 n_old
= vec_safe_length (old_row
->reg_save
);
2172 n_new
= vec_safe_length (new_row
->reg_save
);
2173 n_max
= MAX (n_old
, n_new
);
2175 for (i
= 0; i
< n_max
; ++i
)
2177 dw_cfi_ref r_old
= NULL
, r_new
= NULL
;
2180 r_old
= (*old_row
->reg_save
)[i
];
2182 r_new
= (*new_row
->reg_save
)[i
];
2186 else if (r_new
== NULL
)
2187 add_cfi_restore (i
);
2188 else if (!cfi_equal_p (r_old
, r_new
))
2193 /* Examine CFI and return true if a cfi label and set_loc is needed
2194 beforehand. Even when generating CFI assembler instructions, we
2195 still have to add the cfi to the list so that lookup_cfa_1 works
2196 later on. When -g2 and above we even need to force emitting of
2197 CFI labels and add to list a DW_CFA_set_loc for convert_cfa_to_fb_loc_list
2198 purposes. If we're generating DWARF3 output we use DW_OP_call_frame_cfa
2199 and so don't use convert_cfa_to_fb_loc_list. */
2202 cfi_label_required_p (dw_cfi_ref cfi
)
2204 if (!dwarf2out_do_cfi_asm ())
2207 if (dwarf_version
== 2
2208 && debug_info_level
> DINFO_LEVEL_TERSE
2209 && (write_symbols
== DWARF2_DEBUG
2210 || write_symbols
== VMS_AND_DWARF2_DEBUG
))
2212 switch (cfi
->dw_cfi_opc
)
2214 case DW_CFA_def_cfa_offset
:
2215 case DW_CFA_def_cfa_offset_sf
:
2216 case DW_CFA_def_cfa_register
:
2217 case DW_CFA_def_cfa
:
2218 case DW_CFA_def_cfa_sf
:
2219 case DW_CFA_def_cfa_expression
:
2220 case DW_CFA_restore_state
:
2229 /* Walk the function, looking for NOTE_INSN_CFI notes. Add the CFIs to the
2230 function's FDE, adding CFI labels and set_loc/advance_loc opcodes as
2233 add_cfis_to_fde (void)
2235 dw_fde_ref fde
= cfun
->fde
;
2236 rtx_insn
*insn
, *next
;
2238 for (insn
= get_insns (); insn
; insn
= next
)
2240 next
= NEXT_INSN (insn
);
2242 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
)
2243 fde
->dw_fde_switch_cfi_index
= vec_safe_length (fde
->dw_fde_cfi
);
2245 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_CFI
)
2247 bool required
= cfi_label_required_p (NOTE_CFI (insn
));
2249 if (NOTE_P (next
) && NOTE_KIND (next
) == NOTE_INSN_CFI
)
2251 required
|= cfi_label_required_p (NOTE_CFI (next
));
2252 next
= NEXT_INSN (next
);
2254 else if (active_insn_p (next
)
2255 || (NOTE_P (next
) && (NOTE_KIND (next
)
2256 == NOTE_INSN_SWITCH_TEXT_SECTIONS
)))
2259 next
= NEXT_INSN (next
);
2262 int num
= dwarf2out_cfi_label_num
;
2263 const char *label
= dwarf2out_cfi_label ();
2266 /* Set the location counter to the new label. */
2268 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
2269 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
2270 vec_safe_push (fde
->dw_fde_cfi
, xcfi
);
2272 rtx_note
*tmp
= emit_note_before (NOTE_INSN_CFI_LABEL
, insn
);
2273 NOTE_LABEL_NUMBER (tmp
) = num
;
2278 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_CFI
)
2279 vec_safe_push (fde
->dw_fde_cfi
, NOTE_CFI (insn
));
2280 insn
= NEXT_INSN (insn
);
2282 while (insn
!= next
);
2287 static void dump_cfi_row (FILE *f
, dw_cfi_row
*row
);
2289 /* If LABEL is the start of a trace, then initialize the state of that
2290 trace from CUR_TRACE and CUR_ROW. */
2293 maybe_record_trace_start (rtx_insn
*start
, rtx_insn
*origin
)
2297 ti
= get_trace_info (start
);
2298 gcc_assert (ti
!= NULL
);
2302 fprintf (dump_file
, " saw edge from trace %u to %u (via %s %d)\n",
2303 cur_trace
->id
, ti
->id
,
2304 (origin
? rtx_name
[(int) GET_CODE (origin
)] : "fallthru"),
2305 (origin
? INSN_UID (origin
) : 0));
2308 poly_int64 args_size
= cur_trace
->end_true_args_size
;
2309 if (ti
->beg_row
== NULL
)
2311 /* This is the first time we've encountered this trace. Propagate
2312 state across the edge and push the trace onto the work list. */
2313 ti
->beg_row
= copy_cfi_row (cur_row
);
2314 ti
->beg_true_args_size
= args_size
;
2316 ti
->cfa_store
= cur_trace
->cfa_store
;
2317 ti
->cfa_temp
= cur_trace
->cfa_temp
;
2318 ti
->regs_saved_in_regs
= cur_trace
->regs_saved_in_regs
.copy ();
2320 trace_work_list
.safe_push (ti
);
2323 fprintf (dump_file
, "\tpush trace %u to worklist\n", ti
->id
);
2328 /* We ought to have the same state incoming to a given trace no
2329 matter how we arrive at the trace. Anything else means we've
2330 got some kind of optimization error. */
2332 if (!cfi_row_equal_p (cur_row
, ti
->beg_row
))
2336 fprintf (dump_file
, "Inconsistent CFI state!\n");
2337 fprintf (dump_file
, "SHOULD have:\n");
2338 dump_cfi_row (dump_file
, ti
->beg_row
);
2339 fprintf (dump_file
, "DO have:\n");
2340 dump_cfi_row (dump_file
, cur_row
);
2347 /* The args_size is allowed to conflict if it isn't actually used. */
2348 if (maybe_ne (ti
->beg_true_args_size
, args_size
))
2349 ti
->args_size_undefined
= true;
2353 /* Similarly, but handle the args_size and CFA reset across EH
2354 and non-local goto edges. */
2357 maybe_record_trace_start_abnormal (rtx_insn
*start
, rtx_insn
*origin
)
2359 poly_int64 save_args_size
, delta
;
2360 dw_cfa_location save_cfa
;
2362 save_args_size
= cur_trace
->end_true_args_size
;
2363 if (known_eq (save_args_size
, 0))
2365 maybe_record_trace_start (start
, origin
);
2369 delta
= -save_args_size
;
2370 cur_trace
->end_true_args_size
= 0;
2372 save_cfa
= cur_row
->cfa
;
2373 if (cur_row
->cfa
.reg
== dw_stack_pointer_regnum
)
2375 /* Convert a change in args_size (always a positive in the
2376 direction of stack growth) to a change in stack pointer. */
2377 if (!STACK_GROWS_DOWNWARD
)
2380 cur_row
->cfa
.offset
+= delta
;
2383 maybe_record_trace_start (start
, origin
);
2385 cur_trace
->end_true_args_size
= save_args_size
;
2386 cur_row
->cfa
= save_cfa
;
2389 /* Propagate CUR_TRACE state to the destinations implied by INSN. */
2390 /* ??? Sadly, this is in large part a duplicate of make_edges. */
2393 create_trace_edges (rtx_insn
*insn
)
2400 rtx_jump_table_data
*table
;
2402 if (find_reg_note (insn
, REG_NON_LOCAL_GOTO
, NULL_RTX
))
2405 if (tablejump_p (insn
, NULL
, &table
))
2407 rtvec vec
= table
->get_labels ();
2409 n
= GET_NUM_ELEM (vec
);
2410 for (i
= 0; i
< n
; ++i
)
2412 rtx_insn
*lab
= as_a
<rtx_insn
*> (XEXP (RTVEC_ELT (vec
, i
), 0));
2413 maybe_record_trace_start (lab
, insn
);
2416 else if (computed_jump_p (insn
))
2420 FOR_EACH_VEC_SAFE_ELT (forced_labels
, i
, temp
)
2421 maybe_record_trace_start (temp
, insn
);
2423 else if (returnjump_p (insn
))
2425 else if ((tmp
= extract_asm_operands (PATTERN (insn
))) != NULL
)
2427 n
= ASM_OPERANDS_LABEL_LENGTH (tmp
);
2428 for (i
= 0; i
< n
; ++i
)
2431 as_a
<rtx_insn
*> (XEXP (ASM_OPERANDS_LABEL (tmp
, i
), 0));
2432 maybe_record_trace_start (lab
, insn
);
2437 rtx_insn
*lab
= JUMP_LABEL_AS_INSN (insn
);
2438 gcc_assert (lab
!= NULL
);
2439 maybe_record_trace_start (lab
, insn
);
2442 else if (CALL_P (insn
))
2444 /* Sibling calls don't have edges inside this function. */
2445 if (SIBLING_CALL_P (insn
))
2448 /* Process non-local goto edges. */
2449 if (can_nonlocal_goto (insn
))
2450 for (rtx_insn_list
*lab
= nonlocal_goto_handler_labels
;
2453 maybe_record_trace_start_abnormal (lab
->insn (), insn
);
2455 else if (rtx_sequence
*seq
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
2457 int i
, n
= seq
->len ();
2458 for (i
= 0; i
< n
; ++i
)
2459 create_trace_edges (seq
->insn (i
));
2463 /* Process EH edges. */
2464 if (CALL_P (insn
) || cfun
->can_throw_non_call_exceptions
)
2466 eh_landing_pad lp
= get_eh_landing_pad_from_rtx (insn
);
2468 maybe_record_trace_start_abnormal (lp
->landing_pad
, insn
);
2472 /* A subroutine of scan_trace. Do what needs to be done "after" INSN. */
2475 scan_insn_after (rtx_insn
*insn
)
2477 if (RTX_FRAME_RELATED_P (insn
))
2478 dwarf2out_frame_debug (insn
);
2479 notice_args_size (insn
);
2482 /* Scan the trace beginning at INSN and create the CFI notes for the
2483 instructions therein. */
2486 scan_trace (dw_trace_info
*trace
)
2488 rtx_insn
*prev
, *insn
= trace
->head
;
2489 dw_cfa_location this_cfa
;
2492 fprintf (dump_file
, "Processing trace %u : start at %s %d\n",
2493 trace
->id
, rtx_name
[(int) GET_CODE (insn
)],
2496 trace
->end_row
= copy_cfi_row (trace
->beg_row
);
2497 trace
->end_true_args_size
= trace
->beg_true_args_size
;
2500 cur_row
= trace
->end_row
;
2502 this_cfa
= cur_row
->cfa
;
2503 cur_cfa
= &this_cfa
;
2505 for (prev
= insn
, insn
= NEXT_INSN (insn
);
2507 prev
= insn
, insn
= NEXT_INSN (insn
))
2511 /* Do everything that happens "before" the insn. */
2512 add_cfi_insn
= prev
;
2514 /* Notice the end of a trace. */
2515 if (BARRIER_P (insn
))
2517 /* Don't bother saving the unneeded queued registers at all. */
2518 queued_reg_saves
.truncate (0);
2521 if (save_point_p (insn
))
2523 /* Propagate across fallthru edges. */
2524 dwarf2out_flush_queued_reg_saves ();
2525 maybe_record_trace_start (insn
, NULL
);
2529 if (DEBUG_INSN_P (insn
) || !inside_basic_block_p (insn
))
2532 /* Handle all changes to the row state. Sequences require special
2533 handling for the positioning of the notes. */
2534 if (rtx_sequence
*pat
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
2537 int i
, n
= pat
->len ();
2539 control
= pat
->insn (0);
2540 if (can_throw_internal (control
))
2541 notice_eh_throw (control
);
2542 dwarf2out_flush_queued_reg_saves ();
2544 if (JUMP_P (control
) && INSN_ANNULLED_BRANCH_P (control
))
2546 /* ??? Hopefully multiple delay slots are not annulled. */
2547 gcc_assert (n
== 2);
2548 gcc_assert (!RTX_FRAME_RELATED_P (control
));
2549 gcc_assert (!find_reg_note (control
, REG_ARGS_SIZE
, NULL
));
2551 elt
= pat
->insn (1);
2553 if (INSN_FROM_TARGET_P (elt
))
2555 cfi_vec save_row_reg_save
;
2557 /* If ELT is an instruction from target of an annulled
2558 branch, the effects are for the target only and so
2559 the args_size and CFA along the current path
2560 shouldn't change. */
2561 add_cfi_insn
= NULL
;
2562 poly_int64 restore_args_size
= cur_trace
->end_true_args_size
;
2563 cur_cfa
= &cur_row
->cfa
;
2564 save_row_reg_save
= vec_safe_copy (cur_row
->reg_save
);
2566 scan_insn_after (elt
);
2568 /* ??? Should we instead save the entire row state? */
2569 gcc_assert (!queued_reg_saves
.length ());
2571 create_trace_edges (control
);
2573 cur_trace
->end_true_args_size
= restore_args_size
;
2574 cur_row
->cfa
= this_cfa
;
2575 cur_row
->reg_save
= save_row_reg_save
;
2576 cur_cfa
= &this_cfa
;
2580 /* If ELT is a annulled branch-taken instruction (i.e.
2581 executed only when branch is not taken), the args_size
2582 and CFA should not change through the jump. */
2583 create_trace_edges (control
);
2585 /* Update and continue with the trace. */
2586 add_cfi_insn
= insn
;
2587 scan_insn_after (elt
);
2588 def_cfa_1 (&this_cfa
);
2593 /* The insns in the delay slot should all be considered to happen
2594 "before" a call insn. Consider a call with a stack pointer
2595 adjustment in the delay slot. The backtrace from the callee
2596 should include the sp adjustment. Unfortunately, that leaves
2597 us with an unavoidable unwinding error exactly at the call insn
2598 itself. For jump insns we'd prefer to avoid this error by
2599 placing the notes after the sequence. */
2600 if (JUMP_P (control
))
2601 add_cfi_insn
= insn
;
2603 for (i
= 1; i
< n
; ++i
)
2605 elt
= pat
->insn (i
);
2606 scan_insn_after (elt
);
2609 /* Make sure any register saves are visible at the jump target. */
2610 dwarf2out_flush_queued_reg_saves ();
2611 any_cfis_emitted
= false;
2613 /* However, if there is some adjustment on the call itself, e.g.
2614 a call_pop, that action should be considered to happen after
2615 the call returns. */
2616 add_cfi_insn
= insn
;
2617 scan_insn_after (control
);
2621 /* Flush data before calls and jumps, and of course if necessary. */
2622 if (can_throw_internal (insn
))
2624 notice_eh_throw (insn
);
2625 dwarf2out_flush_queued_reg_saves ();
2627 else if (!NONJUMP_INSN_P (insn
)
2628 || clobbers_queued_reg_save (insn
)
2629 || find_reg_note (insn
, REG_CFA_FLUSH_QUEUE
, NULL
))
2630 dwarf2out_flush_queued_reg_saves ();
2631 any_cfis_emitted
= false;
2633 add_cfi_insn
= insn
;
2634 scan_insn_after (insn
);
2638 /* Between frame-related-p and args_size we might have otherwise
2639 emitted two cfa adjustments. Do it now. */
2640 def_cfa_1 (&this_cfa
);
2642 /* Minimize the number of advances by emitting the entire queue
2643 once anything is emitted. */
2644 if (any_cfis_emitted
2645 || find_reg_note (insn
, REG_CFA_FLUSH_QUEUE
, NULL
))
2646 dwarf2out_flush_queued_reg_saves ();
2648 /* Note that a test for control_flow_insn_p does exactly the
2649 same tests as are done to actually create the edges. So
2650 always call the routine and let it not create edges for
2651 non-control-flow insns. */
2652 create_trace_edges (control
);
2655 add_cfi_insn
= NULL
;
2661 /* Scan the function and create the initial set of CFI notes. */
2664 create_cfi_notes (void)
2668 gcc_checking_assert (!queued_reg_saves
.exists ());
2669 gcc_checking_assert (!trace_work_list
.exists ());
2671 /* Always begin at the entry trace. */
2672 ti
= &trace_info
[0];
2675 while (!trace_work_list
.is_empty ())
2677 ti
= trace_work_list
.pop ();
2681 queued_reg_saves
.release ();
2682 trace_work_list
.release ();
2685 /* Return the insn before the first NOTE_INSN_CFI after START. */
2688 before_next_cfi_note (rtx_insn
*start
)
2690 rtx_insn
*prev
= start
;
2693 if (NOTE_P (start
) && NOTE_KIND (start
) == NOTE_INSN_CFI
)
2696 start
= NEXT_INSN (start
);
2701 /* Insert CFI notes between traces to properly change state between them. */
2704 connect_traces (void)
2706 unsigned i
, n
= trace_info
.length ();
2707 dw_trace_info
*prev_ti
, *ti
;
2709 /* ??? Ideally, we should have both queued and processed every trace.
2710 However the current representation of constant pools on various targets
2711 is indistinguishable from unreachable code. Assume for the moment that
2712 we can simply skip over such traces. */
2713 /* ??? Consider creating a DATA_INSN rtx code to indicate that
2714 these are not "real" instructions, and should not be considered.
2715 This could be generically useful for tablejump data as well. */
2716 /* Remove all unprocessed traces from the list. */
2717 for (i
= n
- 1; i
> 0; --i
)
2719 ti
= &trace_info
[i
];
2720 if (ti
->beg_row
== NULL
)
2722 trace_info
.ordered_remove (i
);
2726 gcc_assert (ti
->end_row
!= NULL
);
2729 /* Work from the end back to the beginning. This lets us easily insert
2730 remember/restore_state notes in the correct order wrt other notes. */
2731 prev_ti
= &trace_info
[n
- 1];
2732 for (i
= n
- 1; i
> 0; --i
)
2734 dw_cfi_row
*old_row
;
2737 prev_ti
= &trace_info
[i
- 1];
2739 add_cfi_insn
= ti
->head
;
2741 /* In dwarf2out_switch_text_section, we'll begin a new FDE
2742 for the portion of the function in the alternate text
2743 section. The row state at the very beginning of that
2744 new FDE will be exactly the row state from the CIE. */
2745 if (ti
->switch_sections
)
2746 old_row
= cie_cfi_row
;
2749 old_row
= prev_ti
->end_row
;
2750 /* If there's no change from the previous end state, fine. */
2751 if (cfi_row_equal_p (old_row
, ti
->beg_row
))
2753 /* Otherwise check for the common case of sharing state with
2754 the beginning of an epilogue, but not the end. Insert
2755 remember/restore opcodes in that case. */
2756 else if (cfi_row_equal_p (prev_ti
->beg_row
, ti
->beg_row
))
2760 /* Note that if we blindly insert the remember at the
2761 start of the trace, we can wind up increasing the
2762 size of the unwind info due to extra advance opcodes.
2763 Instead, put the remember immediately before the next
2764 state change. We know there must be one, because the
2765 state at the beginning and head of the trace differ. */
2766 add_cfi_insn
= before_next_cfi_note (prev_ti
->head
);
2768 cfi
->dw_cfi_opc
= DW_CFA_remember_state
;
2771 add_cfi_insn
= ti
->head
;
2773 cfi
->dw_cfi_opc
= DW_CFA_restore_state
;
2776 old_row
= prev_ti
->beg_row
;
2778 /* Otherwise, we'll simply change state from the previous end. */
2781 change_cfi_row (old_row
, ti
->beg_row
);
2783 if (dump_file
&& add_cfi_insn
!= ti
->head
)
2787 fprintf (dump_file
, "Fixup between trace %u and %u:\n",
2788 prev_ti
->id
, ti
->id
);
2793 note
= NEXT_INSN (note
);
2794 gcc_assert (NOTE_P (note
) && NOTE_KIND (note
) == NOTE_INSN_CFI
);
2795 output_cfi_directive (dump_file
, NOTE_CFI (note
));
2797 while (note
!= add_cfi_insn
);
2801 /* Connect args_size between traces that have can_throw_internal insns. */
2802 if (cfun
->eh
->lp_array
)
2804 poly_int64 prev_args_size
= 0;
2806 for (i
= 0; i
< n
; ++i
)
2808 ti
= &trace_info
[i
];
2810 if (ti
->switch_sections
)
2812 if (ti
->eh_head
== NULL
)
2814 gcc_assert (!ti
->args_size_undefined
);
2816 if (maybe_ne (ti
->beg_delay_args_size
, prev_args_size
))
2818 /* ??? Search back to previous CFI note. */
2819 add_cfi_insn
= PREV_INSN (ti
->eh_head
);
2820 add_cfi_args_size (ti
->beg_delay_args_size
);
2823 prev_args_size
= ti
->end_delay_args_size
;
2828 /* Set up the pseudo-cfg of instruction traces, as described at the
2829 block comment at the top of the file. */
2832 create_pseudo_cfg (void)
2834 bool saw_barrier
, switch_sections
;
2839 /* The first trace begins at the start of the function,
2840 and begins with the CIE row state. */
2841 trace_info
.create (16);
2842 memset (&ti
, 0, sizeof (ti
));
2843 ti
.head
= get_insns ();
2844 ti
.beg_row
= cie_cfi_row
;
2845 ti
.cfa_store
= cie_cfi_row
->cfa
;
2846 ti
.cfa_temp
.reg
= INVALID_REGNUM
;
2847 trace_info
.quick_push (ti
);
2849 if (cie_return_save
)
2850 ti
.regs_saved_in_regs
.safe_push (*cie_return_save
);
2852 /* Walk all the insns, collecting start of trace locations. */
2853 saw_barrier
= false;
2854 switch_sections
= false;
2855 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
2857 if (BARRIER_P (insn
))
2859 else if (NOTE_P (insn
)
2860 && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
)
2862 /* We should have just seen a barrier. */
2863 gcc_assert (saw_barrier
);
2864 switch_sections
= true;
2866 /* Watch out for save_point notes between basic blocks.
2867 In particular, a note after a barrier. Do not record these,
2868 delaying trace creation until the label. */
2869 else if (save_point_p (insn
)
2870 && (LABEL_P (insn
) || !saw_barrier
))
2872 memset (&ti
, 0, sizeof (ti
));
2874 ti
.switch_sections
= switch_sections
;
2875 ti
.id
= trace_info
.length ();
2876 trace_info
.safe_push (ti
);
2878 saw_barrier
= false;
2879 switch_sections
= false;
2883 /* Create the trace index after we've finished building trace_info,
2884 avoiding stale pointer problems due to reallocation. */
2886 = new hash_table
<trace_info_hasher
> (trace_info
.length ());
2888 FOR_EACH_VEC_ELT (trace_info
, i
, tp
)
2890 dw_trace_info
**slot
;
2893 fprintf (dump_file
, "Creating trace %u : start at %s %d%s\n", tp
->id
,
2894 rtx_name
[(int) GET_CODE (tp
->head
)], INSN_UID (tp
->head
),
2895 tp
->switch_sections
? " (section switch)" : "");
2897 slot
= trace_index
->find_slot_with_hash (tp
, INSN_UID (tp
->head
), INSERT
);
2898 gcc_assert (*slot
== NULL
);
2903 /* Record the initial position of the return address. RTL is
2904 INCOMING_RETURN_ADDR_RTX. */
2907 initial_return_save (rtx rtl
)
2909 unsigned int reg
= INVALID_REGNUM
;
2910 poly_int64 offset
= 0;
2912 switch (GET_CODE (rtl
))
2915 /* RA is in a register. */
2916 reg
= dwf_regno (rtl
);
2920 /* RA is on the stack. */
2921 rtl
= XEXP (rtl
, 0);
2922 switch (GET_CODE (rtl
))
2925 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
2930 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
2931 offset
= rtx_to_poly_int64 (XEXP (rtl
, 1));
2935 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
2936 offset
= -rtx_to_poly_int64 (XEXP (rtl
, 1));
2946 /* The return address is at some offset from any value we can
2947 actually load. For instance, on the SPARC it is in %i7+8. Just
2948 ignore the offset for now; it doesn't matter for unwinding frames. */
2949 gcc_assert (CONST_INT_P (XEXP (rtl
, 1)));
2950 initial_return_save (XEXP (rtl
, 0));
2957 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
2959 if (reg
!= INVALID_REGNUM
)
2960 record_reg_saved_in_reg (rtl
, pc_rtx
);
2961 reg_save (DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cur_row
->cfa
.offset
);
2966 create_cie_data (void)
2968 dw_cfa_location loc
;
2969 dw_trace_info cie_trace
;
2971 dw_stack_pointer_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
2973 memset (&cie_trace
, 0, sizeof (cie_trace
));
2974 cur_trace
= &cie_trace
;
2976 add_cfi_vec
= &cie_cfi_vec
;
2977 cie_cfi_row
= cur_row
= new_cfi_row ();
2979 /* On entry, the Canonical Frame Address is at SP. */
2980 memset (&loc
, 0, sizeof (loc
));
2981 loc
.reg
= dw_stack_pointer_regnum
;
2982 loc
.offset
= INCOMING_FRAME_SP_OFFSET
;
2985 if (targetm
.debug_unwind_info () == UI_DWARF2
2986 || targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
2988 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2990 /* For a few targets, we have the return address incoming into a
2991 register, but choose a different return column. This will result
2992 in a DW_CFA_register for the return, and an entry in
2993 regs_saved_in_regs to match. If the target later stores that
2994 return address register to the stack, we want to be able to emit
2995 the DW_CFA_offset against the return column, not the intermediate
2996 save register. Save the contents of regs_saved_in_regs so that
2997 we can re-initialize it at the start of each function. */
2998 switch (cie_trace
.regs_saved_in_regs
.length ())
3003 cie_return_save
= ggc_alloc
<reg_saved_in_data
> ();
3004 *cie_return_save
= cie_trace
.regs_saved_in_regs
[0];
3005 cie_trace
.regs_saved_in_regs
.release ();
3017 /* Annotate the function with NOTE_INSN_CFI notes to record the CFI
3018 state at each location within the function. These notes will be
3019 emitted during pass_final. */
3022 execute_dwarf2_frame (void)
3024 /* Different HARD_FRAME_POINTER_REGNUM might coexist in the same file. */
3025 dw_frame_pointer_regnum
= DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
3027 /* The first time we're called, compute the incoming frame state. */
3028 if (cie_cfi_vec
== NULL
)
3031 dwarf2out_alloc_current_fde ();
3033 create_pseudo_cfg ();
3036 create_cfi_notes ();
3040 /* Free all the data we allocated. */
3045 FOR_EACH_VEC_ELT (trace_info
, i
, ti
)
3046 ti
->regs_saved_in_regs
.release ();
3048 trace_info
.release ();
3056 /* Convert a DWARF call frame info. operation to its string name */
3059 dwarf_cfi_name (unsigned int cfi_opc
)
3061 const char *name
= get_DW_CFA_name (cfi_opc
);
3066 return "DW_CFA_<unknown>";
3069 /* This routine will generate the correct assembly data for a location
3070 description based on a cfi entry with a complex address. */
3073 output_cfa_loc (dw_cfi_ref cfi
, int for_eh
)
3075 dw_loc_descr_ref loc
;
3078 if (cfi
->dw_cfi_opc
== DW_CFA_expression
3079 || cfi
->dw_cfi_opc
== DW_CFA_val_expression
)
3082 DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3083 dw2_asm_output_data (1, r
, NULL
);
3084 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
3087 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3089 /* Output the size of the block. */
3090 size
= size_of_locs (loc
);
3091 dw2_asm_output_data_uleb128 (size
, NULL
);
3093 /* Now output the operations themselves. */
3094 output_loc_sequence (loc
, for_eh
);
3097 /* Similar, but used for .cfi_escape. */
3100 output_cfa_loc_raw (dw_cfi_ref cfi
)
3102 dw_loc_descr_ref loc
;
3105 if (cfi
->dw_cfi_opc
== DW_CFA_expression
3106 || cfi
->dw_cfi_opc
== DW_CFA_val_expression
)
3109 DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3110 fprintf (asm_out_file
, "%#x,", r
);
3111 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
3114 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3116 /* Output the size of the block. */
3117 size
= size_of_locs (loc
);
3118 dw2_asm_output_data_uleb128_raw (size
);
3119 fputc (',', asm_out_file
);
3121 /* Now output the operations themselves. */
3122 output_loc_sequence_raw (loc
);
3125 /* Output a Call Frame Information opcode and its operand(s). */
3128 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
3133 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
3134 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
3135 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
3136 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
3137 ((unsigned HOST_WIDE_INT
)
3138 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
3139 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
3141 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3142 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3143 "DW_CFA_offset, column %#lx", r
);
3144 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3145 dw2_asm_output_data_uleb128 (off
, NULL
);
3147 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
3149 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3150 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3151 "DW_CFA_restore, column %#lx", r
);
3155 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
3156 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
3158 switch (cfi
->dw_cfi_opc
)
3160 case DW_CFA_set_loc
:
3162 dw2_asm_output_encoded_addr_rtx (
3163 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3164 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
3167 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3168 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
3169 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3172 case DW_CFA_advance_loc1
:
3173 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3174 fde
->dw_fde_current_label
, NULL
);
3175 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3178 case DW_CFA_advance_loc2
:
3179 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3180 fde
->dw_fde_current_label
, NULL
);
3181 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3184 case DW_CFA_advance_loc4
:
3185 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3186 fde
->dw_fde_current_label
, NULL
);
3187 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3190 case DW_CFA_MIPS_advance_loc8
:
3191 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3192 fde
->dw_fde_current_label
, NULL
);
3193 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3196 case DW_CFA_offset_extended
:
3197 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3198 dw2_asm_output_data_uleb128 (r
, NULL
);
3199 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3200 dw2_asm_output_data_uleb128 (off
, NULL
);
3203 case DW_CFA_def_cfa
:
3204 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3205 dw2_asm_output_data_uleb128 (r
, NULL
);
3206 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
3209 case DW_CFA_offset_extended_sf
:
3210 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3211 dw2_asm_output_data_uleb128 (r
, NULL
);
3212 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3213 dw2_asm_output_data_sleb128 (off
, NULL
);
3216 case DW_CFA_def_cfa_sf
:
3217 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3218 dw2_asm_output_data_uleb128 (r
, NULL
);
3219 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3220 dw2_asm_output_data_sleb128 (off
, NULL
);
3223 case DW_CFA_restore_extended
:
3224 case DW_CFA_undefined
:
3225 case DW_CFA_same_value
:
3226 case DW_CFA_def_cfa_register
:
3227 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3228 dw2_asm_output_data_uleb128 (r
, NULL
);
3231 case DW_CFA_register
:
3232 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3233 dw2_asm_output_data_uleb128 (r
, NULL
);
3234 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
3235 dw2_asm_output_data_uleb128 (r
, NULL
);
3238 case DW_CFA_def_cfa_offset
:
3239 case DW_CFA_GNU_args_size
:
3240 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
3243 case DW_CFA_def_cfa_offset_sf
:
3244 off
= div_data_align (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3245 dw2_asm_output_data_sleb128 (off
, NULL
);
3248 case DW_CFA_GNU_window_save
:
3251 case DW_CFA_def_cfa_expression
:
3252 case DW_CFA_expression
:
3253 case DW_CFA_val_expression
:
3254 output_cfa_loc (cfi
, for_eh
);
3257 case DW_CFA_GNU_negative_offset_extended
:
3258 /* Obsoleted by DW_CFA_offset_extended_sf. */
3267 /* Similar, but do it via assembler directives instead. */
3270 output_cfi_directive (FILE *f
, dw_cfi_ref cfi
)
3272 unsigned long r
, r2
;
3274 switch (cfi
->dw_cfi_opc
)
3276 case DW_CFA_advance_loc
:
3277 case DW_CFA_advance_loc1
:
3278 case DW_CFA_advance_loc2
:
3279 case DW_CFA_advance_loc4
:
3280 case DW_CFA_MIPS_advance_loc8
:
3281 case DW_CFA_set_loc
:
3282 /* Should only be created in a code path not followed when emitting
3283 via directives. The assembler is going to take care of this for
3284 us. But this routines is also used for debugging dumps, so
3286 gcc_assert (f
!= asm_out_file
);
3287 fprintf (f
, "\t.cfi_advance_loc\n");
3291 case DW_CFA_offset_extended
:
3292 case DW_CFA_offset_extended_sf
:
3293 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3294 fprintf (f
, "\t.cfi_offset %lu, " HOST_WIDE_INT_PRINT_DEC
"\n",
3295 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3298 case DW_CFA_restore
:
3299 case DW_CFA_restore_extended
:
3300 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3301 fprintf (f
, "\t.cfi_restore %lu\n", r
);
3304 case DW_CFA_undefined
:
3305 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3306 fprintf (f
, "\t.cfi_undefined %lu\n", r
);
3309 case DW_CFA_same_value
:
3310 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3311 fprintf (f
, "\t.cfi_same_value %lu\n", r
);
3314 case DW_CFA_def_cfa
:
3315 case DW_CFA_def_cfa_sf
:
3316 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3317 fprintf (f
, "\t.cfi_def_cfa %lu, " HOST_WIDE_INT_PRINT_DEC
"\n",
3318 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3321 case DW_CFA_def_cfa_register
:
3322 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3323 fprintf (f
, "\t.cfi_def_cfa_register %lu\n", r
);
3326 case DW_CFA_register
:
3327 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3328 r2
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, 1);
3329 fprintf (f
, "\t.cfi_register %lu, %lu\n", r
, r2
);
3332 case DW_CFA_def_cfa_offset
:
3333 case DW_CFA_def_cfa_offset_sf
:
3334 fprintf (f
, "\t.cfi_def_cfa_offset "
3335 HOST_WIDE_INT_PRINT_DEC
"\n",
3336 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3339 case DW_CFA_remember_state
:
3340 fprintf (f
, "\t.cfi_remember_state\n");
3342 case DW_CFA_restore_state
:
3343 fprintf (f
, "\t.cfi_restore_state\n");
3346 case DW_CFA_GNU_args_size
:
3347 if (f
== asm_out_file
)
3349 fprintf (f
, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size
);
3350 dw2_asm_output_data_uleb128_raw (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3352 fprintf (f
, "\t%s args_size " HOST_WIDE_INT_PRINT_DEC
,
3353 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3358 fprintf (f
, "\t.cfi_GNU_args_size " HOST_WIDE_INT_PRINT_DEC
"\n",
3359 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3363 case DW_CFA_GNU_window_save
:
3364 fprintf (f
, "\t.cfi_window_save\n");
3367 case DW_CFA_def_cfa_expression
:
3368 case DW_CFA_expression
:
3369 case DW_CFA_val_expression
:
3370 if (f
!= asm_out_file
)
3372 fprintf (f
, "\t.cfi_%scfa_%sexpression ...\n",
3373 cfi
->dw_cfi_opc
== DW_CFA_def_cfa_expression
? "def_" : "",
3374 cfi
->dw_cfi_opc
== DW_CFA_val_expression
? "val_" : "");
3377 fprintf (f
, "\t.cfi_escape %#x,", cfi
->dw_cfi_opc
);
3378 output_cfa_loc_raw (cfi
);
3388 dwarf2out_emit_cfi (dw_cfi_ref cfi
)
3390 if (dwarf2out_do_cfi_asm ())
3391 output_cfi_directive (asm_out_file
, cfi
);
3395 dump_cfi_row (FILE *f
, dw_cfi_row
*row
)
3403 dw_cfa_location dummy
;
3404 memset (&dummy
, 0, sizeof (dummy
));
3405 dummy
.reg
= INVALID_REGNUM
;
3406 cfi
= def_cfa_0 (&dummy
, &row
->cfa
);
3408 output_cfi_directive (f
, cfi
);
3410 FOR_EACH_VEC_SAFE_ELT (row
->reg_save
, i
, cfi
)
3412 output_cfi_directive (f
, cfi
);
3415 void debug_cfi_row (dw_cfi_row
*row
);
3418 debug_cfi_row (dw_cfi_row
*row
)
3420 dump_cfi_row (stderr
, row
);
3424 /* Save the result of dwarf2out_do_frame across PCH.
3425 This variable is tri-state, with 0 unset, >0 true, <0 false. */
3426 static GTY(()) signed char saved_do_cfi_asm
= 0;
3428 /* Decide whether to emit EH frame unwind information for the current
3429 translation unit. */
3432 dwarf2out_do_eh_frame (void)
3435 (flag_unwind_tables
|| flag_exceptions
)
3436 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
;
3439 /* Decide whether we want to emit frame unwind information for the current
3440 translation unit. */
3443 dwarf2out_do_frame (void)
3445 /* We want to emit correct CFA location expressions or lists, so we
3446 have to return true if we're going to output debug info, even if
3447 we're not going to output frame or unwind info. */
3448 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
3451 if (saved_do_cfi_asm
> 0)
3454 if (targetm
.debug_unwind_info () == UI_DWARF2
)
3457 if (dwarf2out_do_eh_frame ())
3463 /* Decide whether to emit frame unwind via assembler directives. */
3466 dwarf2out_do_cfi_asm (void)
3470 if (saved_do_cfi_asm
!= 0)
3471 return saved_do_cfi_asm
> 0;
3473 /* Assume failure for a moment. */
3474 saved_do_cfi_asm
= -1;
3476 if (!flag_dwarf2_cfi_asm
|| !dwarf2out_do_frame ())
3478 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
)
3481 /* Make sure the personality encoding is one the assembler can support.
3482 In particular, aligned addresses can't be handled. */
3483 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
3484 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
3486 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
3487 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
3490 /* If we can't get the assembler to emit only .debug_frame, and we don't need
3491 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
3492 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
&& !dwarf2out_do_eh_frame ())
3496 saved_do_cfi_asm
= 1;
3502 const pass_data pass_data_dwarf2_frame
=
3504 RTL_PASS
, /* type */
3505 "dwarf2", /* name */
3506 OPTGROUP_NONE
, /* optinfo_flags */
3507 TV_FINAL
, /* tv_id */
3508 0, /* properties_required */
3509 0, /* properties_provided */
3510 0, /* properties_destroyed */
3511 0, /* todo_flags_start */
3512 0, /* todo_flags_finish */
3515 class pass_dwarf2_frame
: public rtl_opt_pass
3518 pass_dwarf2_frame (gcc::context
*ctxt
)
3519 : rtl_opt_pass (pass_data_dwarf2_frame
, ctxt
)
3522 /* opt_pass methods: */
3523 virtual bool gate (function
*);
3524 virtual unsigned int execute (function
*) { return execute_dwarf2_frame (); }
3526 }; // class pass_dwarf2_frame
3529 pass_dwarf2_frame::gate (function
*)
3531 /* Targets which still implement the prologue in assembler text
3532 cannot use the generic dwarf2 unwinding. */
3533 if (!targetm
.have_prologue ())
3536 /* ??? What to do for UI_TARGET unwinding? They might be able to benefit
3537 from the optimized shrink-wrapping annotations that we will compute.
3538 For now, only produce the CFI notes for dwarf2. */
3539 return dwarf2out_do_frame ();
3545 make_pass_dwarf2_frame (gcc::context
*ctxt
)
3547 return new pass_dwarf2_frame (ctxt
);
3550 #include "gt-dwarf2cfi.h"