1 /* Dwarf2 Call Frame Information helper routines.
2 Copyright (C) 1992-2024 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 */
42 #include "flags.h" /* dwarf_debuginfo_p */
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 #ifndef DEFAULT_INCOMING_FRAME_SP_OFFSET
57 #define DEFAULT_INCOMING_FRAME_SP_OFFSET INCOMING_FRAME_SP_OFFSET
60 /* A collected description of an entire row of the abstract CFI table. */
61 struct GTY(()) dw_cfi_row
63 /* The expression that computes the CFA, expressed in two different ways.
64 The CFA member for the simple cases, and the full CFI expression for
65 the complex cases. The later will be a DW_CFA_cfa_expression. */
69 /* The expressions for any register column that is saved. */
72 /* True if the register window is saved. */
75 /* True if the return address is in a mangled state. */
79 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
80 struct GTY(()) reg_saved_in_data
{
86 /* Since we no longer have a proper CFG, we're going to create a facsimile
87 of one on the fly while processing the frame-related insns.
89 We create dw_trace_info structures for each extended basic block beginning
90 and ending at a "save point". Save points are labels, barriers, certain
91 notes, and of course the beginning and end of the function.
93 As we encounter control transfer insns, we propagate the "current"
94 row state across the edges to the starts of traces. When checking is
95 enabled, we validate that we propagate the same data from all sources.
97 All traces are members of the TRACE_INFO array, in the order in which
98 they appear in the instruction stream.
100 All save points are present in the TRACE_INDEX hash, mapping the insn
101 starting a trace to the dw_trace_info describing the trace. */
105 /* The insn that begins the trace. */
108 /* The row state at the beginning and end of the trace. */
109 dw_cfi_row
*beg_row
, *end_row
;
111 /* Tracking for DW_CFA_GNU_args_size. The "true" sizes are those we find
112 while scanning insns. However, the args_size value is irrelevant at
113 any point except can_throw_internal_p insns. Therefore the "delay"
114 sizes the values that must actually be emitted for this trace. */
115 poly_int64 beg_true_args_size
, end_true_args_size
;
116 poly_int64 beg_delay_args_size
, end_delay_args_size
;
118 /* The first EH insn in the trace, where beg_delay_args_size must be set. */
121 /* The following variables contain data used in interpreting frame related
122 expressions. These are not part of the "real" row state as defined by
123 Dwarf, but it seems like they need to be propagated into a trace in case
124 frame related expressions have been sunk. */
125 /* ??? This seems fragile. These variables are fragments of a larger
126 expression. If we do not keep the entire expression together, we risk
127 not being able to put it together properly. Consider forcing targets
128 to generate self-contained expressions and dropping all of the magic
129 interpretation code in this file. Or at least refusing to shrink wrap
130 any frame related insn that doesn't contain a complete expression. */
132 /* The register used for saving registers to the stack, and its offset
134 dw_cfa_location cfa_store
;
136 /* A temporary register holding an integral value used in adjusting SP
137 or setting up the store_reg. The "offset" field holds the integer
138 value, not an offset. */
139 dw_cfa_location cfa_temp
;
141 /* A set of registers saved in other registers. This is the inverse of
142 the row->reg_save info, if the entry is a DW_CFA_register. This is
143 implemented as a flat array because it normally contains zero or 1
144 entry, depending on the target. IA-64 is the big spender here, using
145 a maximum of 5 entries. */
146 vec
<reg_saved_in_data
> regs_saved_in_regs
;
148 /* An identifier for this trace. Used only for debugging dumps. */
151 /* True if this trace immediately follows NOTE_INSN_SWITCH_TEXT_SECTIONS. */
152 bool switch_sections
;
154 /* True if we've seen different values incoming to beg_true_args_size. */
155 bool args_size_undefined
;
157 /* True if we've seen an insn with a REG_ARGS_SIZE note before EH_HEAD. */
158 bool args_size_defined_for_eh
;
162 /* Hashtable helpers. */
164 struct trace_info_hasher
: nofree_ptr_hash
<dw_trace_info
>
166 static inline hashval_t
hash (const dw_trace_info
*);
167 static inline bool equal (const dw_trace_info
*, const dw_trace_info
*);
171 trace_info_hasher::hash (const dw_trace_info
*ti
)
173 return INSN_UID (ti
->head
);
177 trace_info_hasher::equal (const dw_trace_info
*a
, const dw_trace_info
*b
)
179 return a
->head
== b
->head
;
183 /* The variables making up the pseudo-cfg, as described above. */
184 static vec
<dw_trace_info
> trace_info
;
185 static vec
<dw_trace_info
*> trace_work_list
;
186 static hash_table
<trace_info_hasher
> *trace_index
;
188 /* A vector of call frame insns for the CIE. */
191 /* The state of the first row of the FDE table, which includes the
192 state provided by the CIE. */
193 static GTY(()) dw_cfi_row
*cie_cfi_row
;
195 static GTY(()) reg_saved_in_data
*cie_return_save
;
197 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
199 /* The insn after which a new CFI note should be emitted. */
200 static rtx_insn
*add_cfi_insn
;
202 /* When non-null, add_cfi will add the CFI to this vector. */
203 static cfi_vec
*add_cfi_vec
;
205 /* The current instruction trace. */
206 static dw_trace_info
*cur_trace
;
208 /* The current, i.e. most recently generated, row of the CFI table. */
209 static dw_cfi_row
*cur_row
;
211 /* A copy of the current CFA, for use during the processing of a
213 static dw_cfa_location
*cur_cfa
;
215 /* We delay emitting a register save until either (a) we reach the end
216 of the prologue or (b) the register is clobbered. This clusters
217 register saves so that there are fewer pc advances. */
219 struct queued_reg_save
{
222 poly_int64 cfa_offset
;
226 static vec
<queued_reg_save
> queued_reg_saves
;
228 /* True if any CFI directives were emitted at the current insn. */
229 static bool any_cfis_emitted
;
231 /* Short-hand for commonly used register numbers. */
232 static struct cfa_reg dw_stack_pointer_regnum
;
233 static struct cfa_reg dw_frame_pointer_regnum
;
235 /* Hook used by __throw. */
238 expand_builtin_dwarf_sp_column (void)
240 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
241 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
244 /* MEM is a memory reference for the register size table, each element of
245 which has mode MODE. Initialize column C as a return address column. */
248 init_return_column_size (scalar_int_mode mode
, rtx mem
, unsigned int c
)
250 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
251 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
252 emit_move_insn (adjust_address (mem
, mode
, offset
),
253 gen_int_mode (size
, mode
));
256 /* Datastructure used by expand_builtin_init_dwarf_reg_sizes and
257 init_one_dwarf_reg_size to communicate on what has been done by the
260 struct init_one_dwarf_reg_state
262 /* Whether the dwarf return column was initialized. */
263 bool wrote_return_column
;
265 /* For each hard register REGNO, whether init_one_dwarf_reg_size
266 was given REGNO to process already. */
267 bool processed_regno
[FIRST_PSEUDO_REGISTER
];
271 /* Helper for expand_builtin_init_dwarf_reg_sizes. Generate code to
272 initialize the dwarf register size table entry corresponding to register
273 REGNO in REGMODE. TABLE is the table base address, SLOTMODE is the mode to
274 use for the size entry to initialize, and INIT_STATE is the communication
275 datastructure conveying what we're doing to our caller. */
278 void init_one_dwarf_reg_size (int regno
, machine_mode regmode
,
279 rtx table
, machine_mode slotmode
,
280 init_one_dwarf_reg_state
*init_state
)
282 const unsigned int dnum
= DWARF_FRAME_REGNUM (regno
);
283 const unsigned int rnum
= DWARF2_FRAME_REG_OUT (dnum
, 1);
284 const unsigned int dcol
= DWARF_REG_TO_UNWIND_COLUMN (rnum
);
286 poly_int64 slotoffset
= dcol
* GET_MODE_SIZE (slotmode
);
287 poly_int64 regsize
= GET_MODE_SIZE (regmode
);
289 init_state
->processed_regno
[regno
] = true;
291 if (rnum
>= DWARF_FRAME_REGISTERS
)
294 if (dnum
== DWARF_FRAME_RETURN_COLUMN
)
296 if (regmode
== VOIDmode
)
298 init_state
->wrote_return_column
= true;
301 /* ??? When is this true? Should it be a test based on DCOL instead? */
302 if (maybe_lt (slotoffset
, 0))
305 emit_move_insn (adjust_address (table
, slotmode
, slotoffset
),
306 gen_int_mode (regsize
, slotmode
));
309 /* Generate code to initialize the dwarf register size table located
310 at the provided ADDRESS. */
313 expand_builtin_init_dwarf_reg_sizes (tree address
)
316 scalar_int_mode mode
= SCALAR_INT_TYPE_MODE (char_type_node
);
317 rtx addr
= expand_normal (address
);
318 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
320 init_one_dwarf_reg_state init_state
;
322 memset ((char *)&init_state
, 0, sizeof (init_state
));
324 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
326 machine_mode save_mode
;
329 /* No point in processing a register multiple times. This could happen
330 with register spans, e.g. when a reg is first processed as a piece of
331 a span, then as a register on its own later on. */
333 if (init_state
.processed_regno
[i
])
336 save_mode
= targetm
.dwarf_frame_reg_mode (i
);
337 span
= targetm
.dwarf_register_span (gen_rtx_REG (save_mode
, i
));
340 init_one_dwarf_reg_size (i
, save_mode
, mem
, mode
, &init_state
);
343 for (int si
= 0; si
< XVECLEN (span
, 0); si
++)
345 rtx reg
= XVECEXP (span
, 0, si
);
347 init_one_dwarf_reg_size
348 (REGNO (reg
), GET_MODE (reg
), mem
, mode
, &init_state
);
353 if (!init_state
.wrote_return_column
)
354 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
356 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
357 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
360 targetm
.init_dwarf_reg_sizes_extra (address
);
364 static dw_trace_info
*
365 get_trace_info (rtx_insn
*insn
)
369 return trace_index
->find_with_hash (&dummy
, INSN_UID (insn
));
373 save_point_p (rtx_insn
*insn
)
375 /* Labels, except those that are really jump tables. */
377 return inside_basic_block_p (insn
);
379 /* We split traces at the prologue/epilogue notes because those
380 are points at which the unwind info is usually stable. This
381 makes it easier to find spots with identical unwind info so
382 that we can use remember/restore_state opcodes. */
384 switch (NOTE_KIND (insn
))
386 case NOTE_INSN_PROLOGUE_END
:
387 case NOTE_INSN_EPILOGUE_BEG
:
394 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
396 static inline HOST_WIDE_INT
397 div_data_align (HOST_WIDE_INT off
)
399 HOST_WIDE_INT r
= off
/ DWARF_CIE_DATA_ALIGNMENT
;
400 gcc_assert (r
* DWARF_CIE_DATA_ALIGNMENT
== off
);
404 /* Return true if we need a signed version of a given opcode
405 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
408 need_data_align_sf_opcode (HOST_WIDE_INT off
)
410 return DWARF_CIE_DATA_ALIGNMENT
< 0 ? off
> 0 : off
< 0;
413 /* Return a pointer to a newly allocated Call Frame Instruction. */
415 static inline dw_cfi_ref
418 dw_cfi_ref cfi
= ggc_alloc
<dw_cfi_node
> ();
420 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
421 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
426 /* Return a newly allocated CFI row, with no defined data. */
431 dw_cfi_row
*row
= ggc_cleared_alloc
<dw_cfi_row
> ();
433 row
->cfa
.reg
.set_by_dwreg (INVALID_REGNUM
);
438 /* Return a copy of an existing CFI row. */
441 copy_cfi_row (dw_cfi_row
*src
)
443 dw_cfi_row
*dst
= ggc_alloc
<dw_cfi_row
> ();
446 dst
->reg_save
= vec_safe_copy (src
->reg_save
);
451 /* Return a copy of an existing CFA location. */
453 static dw_cfa_location
*
454 copy_cfa (dw_cfa_location
*src
)
456 dw_cfa_location
*dst
= ggc_alloc
<dw_cfa_location
> ();
461 /* Generate a new label for the CFI info to refer to. */
464 dwarf2out_cfi_label (void)
466 int num
= dwarf2out_cfi_label_num
++;
469 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", num
);
471 return xstrdup (label
);
474 /* Add CFI either to the current insn stream or to a vector, or both. */
477 add_cfi (dw_cfi_ref cfi
)
479 any_cfis_emitted
= true;
481 if (add_cfi_insn
!= NULL
)
483 add_cfi_insn
= emit_note_after (NOTE_INSN_CFI
, add_cfi_insn
);
484 NOTE_CFI (add_cfi_insn
) = cfi
;
487 if (add_cfi_vec
!= NULL
)
488 vec_safe_push (*add_cfi_vec
, cfi
);
492 add_cfi_args_size (poly_int64 size
)
494 /* We don't yet have a representation for polynomial sizes. */
495 HOST_WIDE_INT const_size
= size
.to_constant ();
497 dw_cfi_ref cfi
= new_cfi ();
499 /* While we can occasionally have args_size < 0 internally, this state
500 should not persist at a point we actually need an opcode. */
501 gcc_assert (const_size
>= 0);
503 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
504 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= const_size
;
510 add_cfi_restore (unsigned reg
)
512 dw_cfi_ref cfi
= new_cfi ();
514 cfi
->dw_cfi_opc
= (reg
& ~0x3f ? DW_CFA_restore_extended
: DW_CFA_restore
);
515 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
520 /* Perform ROW->REG_SAVE[COLUMN] = CFI. CFI may be null, indicating
521 that the register column is no longer saved. */
524 update_row_reg_save (dw_cfi_row
*row
, unsigned column
, dw_cfi_ref cfi
)
526 if (vec_safe_length (row
->reg_save
) <= column
)
527 vec_safe_grow_cleared (row
->reg_save
, column
+ 1, true);
528 (*row
->reg_save
)[column
] = cfi
;
531 /* This function fills in aa dw_cfa_location structure from a dwarf location
532 descriptor sequence. */
535 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_node
*loc
)
537 struct dw_loc_descr_node
*ptr
;
539 cfa
->base_offset
= 0;
541 cfa
->reg
.set_by_dwreg (INVALID_REGNUM
);
543 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
545 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
581 cfa
->reg
.set_by_dwreg (op
- DW_OP_reg0
);
584 cfa
->reg
.set_by_dwreg (ptr
->dw_loc_oprnd1
.v
.val_int
);
619 if (cfa
->reg
.reg
== INVALID_REGNUM
)
623 ? ptr
->dw_loc_oprnd1
.v
.val_int
: op
- DW_OP_breg0
);
624 cfa
->reg
.set_by_dwreg (regno
);
625 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
629 /* Handle case when span can cover multiple registers. We
630 only support the simple case of consecutive registers
631 all with the same size. DWARF that we are dealing with
632 will look something like:
633 <DW_OP_bregx: (r49) 0; DW_OP_const1u: 32; DW_OP_shl;
634 DW_OP_bregx: (r48) 0; DW_OP_plus> */
638 ? ptr
->dw_loc_oprnd1
.v
.val_int
: op
- DW_OP_breg0
);
639 gcc_assert (regno
== cfa
->reg
.reg
- 1);
641 /* From all the consecutive registers used, we want to set
642 cfa->reg.reg to lower number register. */
643 cfa
->reg
.reg
= regno
;
644 /* The offset was the shift value. Use it to get the
645 span_width and then set it to 0. */
646 cfa
->reg
.span_width
= cfa
->offset
.to_constant () / 8;
687 gcc_assert (known_eq (cfa
->offset
, 0));
688 cfa
->offset
= op
- DW_OP_lit0
;
698 gcc_assert (known_eq (cfa
->offset
, 0));
699 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
702 cfa
->offset
= -cfa
->offset
;
705 /* The offset is already in place. */
707 case DW_OP_plus_uconst
:
708 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
716 /* Find the previous value for the CFA, iteratively. CFI is the opcode
717 to interpret, *LOC will be updated as necessary, *REMEMBER is used for
718 one level of remember/restore state processing. */
721 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
, dw_cfa_location
*remember
)
723 switch (cfi
->dw_cfi_opc
)
725 case DW_CFA_def_cfa_offset
:
726 case DW_CFA_def_cfa_offset_sf
:
727 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
729 case DW_CFA_def_cfa_register
:
730 loc
->reg
.set_by_dwreg (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
733 case DW_CFA_def_cfa_sf
:
734 loc
->reg
.set_by_dwreg (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
735 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
737 case DW_CFA_def_cfa_expression
:
738 if (cfi
->dw_cfi_oprnd2
.dw_cfi_cfa_loc
)
739 *loc
= *cfi
->dw_cfi_oprnd2
.dw_cfi_cfa_loc
;
741 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
744 case DW_CFA_remember_state
:
745 gcc_assert (!remember
->in_use
);
747 remember
->in_use
= 1;
749 case DW_CFA_restore_state
:
750 gcc_assert (remember
->in_use
);
752 remember
->in_use
= 0;
760 /* Determine if two dw_cfa_location structures define the same data. */
763 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
765 return (loc1
->reg
== loc2
->reg
766 && known_eq (loc1
->offset
, loc2
->offset
)
767 && loc1
->indirect
== loc2
->indirect
768 && (loc1
->indirect
== 0
769 || known_eq (loc1
->base_offset
, loc2
->base_offset
)));
772 /* Determine if two CFI operands are identical. */
775 cfi_oprnd_equal_p (enum dw_cfi_oprnd_type t
, dw_cfi_oprnd
*a
, dw_cfi_oprnd
*b
)
779 case dw_cfi_oprnd_unused
:
781 case dw_cfi_oprnd_reg_num
:
782 return a
->dw_cfi_reg_num
== b
->dw_cfi_reg_num
;
783 case dw_cfi_oprnd_offset
:
784 return a
->dw_cfi_offset
== b
->dw_cfi_offset
;
785 case dw_cfi_oprnd_addr
:
786 return (a
->dw_cfi_addr
== b
->dw_cfi_addr
787 || strcmp (a
->dw_cfi_addr
, b
->dw_cfi_addr
) == 0);
788 case dw_cfi_oprnd_loc
:
789 return loc_descr_equal_p (a
->dw_cfi_loc
, b
->dw_cfi_loc
);
790 case dw_cfi_oprnd_cfa_loc
:
791 /* If any of them is NULL, don't dereference either. */
792 if (!a
->dw_cfi_cfa_loc
|| !b
->dw_cfi_cfa_loc
)
793 return a
->dw_cfi_cfa_loc
== b
->dw_cfi_cfa_loc
;
794 return cfa_equal_p (a
->dw_cfi_cfa_loc
, b
->dw_cfi_cfa_loc
);
799 /* Determine if two CFI entries are identical. */
802 cfi_equal_p (dw_cfi_ref a
, dw_cfi_ref b
)
804 enum dwarf_call_frame_info opc
;
806 /* Make things easier for our callers, including missing operands. */
809 if (a
== NULL
|| b
== NULL
)
812 /* Obviously, the opcodes must match. */
814 if (opc
!= b
->dw_cfi_opc
)
817 /* Compare the two operands, re-using the type of the operands as
818 already exposed elsewhere. */
819 return (cfi_oprnd_equal_p (dw_cfi_oprnd1_desc (opc
),
820 &a
->dw_cfi_oprnd1
, &b
->dw_cfi_oprnd1
)
821 && cfi_oprnd_equal_p (dw_cfi_oprnd2_desc (opc
),
822 &a
->dw_cfi_oprnd2
, &b
->dw_cfi_oprnd2
));
825 /* Determine if two CFI_ROW structures are identical. */
828 cfi_row_equal_p (dw_cfi_row
*a
, dw_cfi_row
*b
)
830 size_t i
, n_a
, n_b
, n_max
;
834 if (!cfi_equal_p (a
->cfa_cfi
, b
->cfa_cfi
))
837 else if (!cfa_equal_p (&a
->cfa
, &b
->cfa
))
840 n_a
= vec_safe_length (a
->reg_save
);
841 n_b
= vec_safe_length (b
->reg_save
);
842 n_max
= MAX (n_a
, n_b
);
844 for (i
= 0; i
< n_max
; ++i
)
846 dw_cfi_ref r_a
= NULL
, r_b
= NULL
;
849 r_a
= (*a
->reg_save
)[i
];
851 r_b
= (*b
->reg_save
)[i
];
853 if (!cfi_equal_p (r_a
, r_b
))
857 if (a
->window_save
!= b
->window_save
)
860 if (a
->ra_mangled
!= b
->ra_mangled
)
866 /* The CFA is now calculated from NEW_CFA. Consider OLD_CFA in determining
867 what opcode to emit. Returns the CFI opcode to effect the change, or
868 NULL if NEW_CFA == OLD_CFA. */
871 def_cfa_0 (dw_cfa_location
*old_cfa
, dw_cfa_location
*new_cfa
)
875 /* If nothing changed, no need to issue any call frame instructions. */
876 if (cfa_equal_p (old_cfa
, new_cfa
))
881 HOST_WIDE_INT const_offset
;
882 if (new_cfa
->reg
== old_cfa
->reg
883 && new_cfa
->reg
.span
== 1
884 && !new_cfa
->indirect
885 && !old_cfa
->indirect
886 && new_cfa
->offset
.is_constant (&const_offset
))
888 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
889 the CFA register did not change but the offset did. The data
890 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
891 in the assembler via the .cfi_def_cfa_offset directive. */
892 if (const_offset
< 0)
893 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
895 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
896 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= const_offset
;
898 else if (new_cfa
->offset
.is_constant ()
899 && known_eq (new_cfa
->offset
, old_cfa
->offset
)
900 && old_cfa
->reg
.reg
!= INVALID_REGNUM
901 && new_cfa
->reg
.span
== 1
902 && !new_cfa
->indirect
903 && !old_cfa
->indirect
)
905 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
906 indicating the CFA register has changed to <register> but the
907 offset has not changed. This requires the old CFA to have
908 been set as a register plus offset rather than a general
909 DW_CFA_def_cfa_expression. */
910 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
911 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= new_cfa
->reg
.reg
;
913 else if (new_cfa
->indirect
== 0
914 && new_cfa
->offset
.is_constant (&const_offset
)
915 && new_cfa
->reg
.span
== 1)
917 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
918 indicating the CFA register has changed to <register> with
919 the specified offset. The data factoring for DW_CFA_def_cfa_sf
920 happens in output_cfi, or in the assembler via the .cfi_def_cfa
922 if (const_offset
< 0)
923 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
925 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
926 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= new_cfa
->reg
.reg
;
927 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= const_offset
;
931 /* Construct a DW_CFA_def_cfa_expression instruction to
932 calculate the CFA using a full location expression since no
933 register-offset pair is available. */
934 struct dw_loc_descr_node
*loc_list
;
936 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
937 loc_list
= build_cfa_loc (new_cfa
, 0);
938 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
939 if (!new_cfa
->offset
.is_constant ()
940 || !new_cfa
->base_offset
.is_constant ())
941 /* It's hard to reconstruct the CFA location for a polynomial
942 expression, so just cache it instead. */
943 cfi
->dw_cfi_oprnd2
.dw_cfi_cfa_loc
= copy_cfa (new_cfa
);
945 cfi
->dw_cfi_oprnd2
.dw_cfi_cfa_loc
= NULL
;
951 /* Similarly, but take OLD_CFA from CUR_ROW, and update it after the fact. */
954 def_cfa_1 (dw_cfa_location
*new_cfa
)
958 if (cur_trace
->cfa_store
.reg
== new_cfa
->reg
&& new_cfa
->indirect
== 0)
959 cur_trace
->cfa_store
.offset
= new_cfa
->offset
;
961 cfi
= def_cfa_0 (&cur_row
->cfa
, new_cfa
);
964 cur_row
->cfa
= *new_cfa
;
965 cur_row
->cfa_cfi
= (cfi
->dw_cfi_opc
== DW_CFA_def_cfa_expression
972 /* Add the CFI for saving a register. REG is the CFA column number.
973 If SREG is INVALID_REGISTER, the register is saved at OFFSET from the CFA;
974 otherwise it is saved in SREG. */
977 reg_save (unsigned int reg
, struct cfa_reg sreg
, poly_int64 offset
)
979 dw_fde_ref fde
= cfun
? cfun
->fde
: NULL
;
980 dw_cfi_ref cfi
= new_cfi ();
982 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
984 if (sreg
.reg
== INVALID_REGNUM
)
986 HOST_WIDE_INT const_offset
;
987 /* When stack is aligned, store REG using DW_CFA_expression with FP. */
988 if (fde
&& fde
->stack_realign
)
990 cfi
->dw_cfi_opc
= DW_CFA_expression
;
991 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
992 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
993 = build_cfa_aligned_loc (&cur_row
->cfa
, offset
,
994 fde
->stack_realignment
);
996 else if (offset
.is_constant (&const_offset
))
998 if (need_data_align_sf_opcode (const_offset
))
999 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
1000 else if (reg
& ~0x3f)
1001 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
1003 cfi
->dw_cfi_opc
= DW_CFA_offset
;
1004 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= const_offset
;
1008 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1009 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1010 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1011 = build_cfa_loc (&cur_row
->cfa
, offset
);
1014 else if (sreg
.reg
== reg
)
1016 /* While we could emit something like DW_CFA_same_value or
1017 DW_CFA_restore, we never expect to see something like that
1018 in a prologue. This is more likely to be a bug. A backend
1019 can always bypass this by using REG_CFA_RESTORE directly. */
1022 else if (sreg
.span
> 1)
1024 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1025 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
1026 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
= build_span_loc (sreg
);
1030 cfi
->dw_cfi_opc
= DW_CFA_register
;
1031 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
.reg
;
1035 update_row_reg_save (cur_row
, reg
, cfi
);
1038 /* A subroutine of scan_trace. Check INSN for a REG_ARGS_SIZE note
1039 and adjust data structures to match. */
1042 notice_args_size (rtx_insn
*insn
)
1044 poly_int64 args_size
, delta
;
1047 note
= find_reg_note (insn
, REG_ARGS_SIZE
, NULL
);
1051 if (!cur_trace
->eh_head
)
1052 cur_trace
->args_size_defined_for_eh
= true;
1054 args_size
= get_args_size (note
);
1055 delta
= args_size
- cur_trace
->end_true_args_size
;
1056 if (known_eq (delta
, 0))
1059 cur_trace
->end_true_args_size
= args_size
;
1061 /* If the CFA is computed off the stack pointer, then we must adjust
1062 the computation of the CFA as well. */
1063 if (cur_cfa
->reg
== dw_stack_pointer_regnum
)
1065 gcc_assert (!cur_cfa
->indirect
);
1067 /* Convert a change in args_size (always a positive in the
1068 direction of stack growth) to a change in stack pointer. */
1069 if (!STACK_GROWS_DOWNWARD
)
1072 cur_cfa
->offset
+= delta
;
1076 /* A subroutine of scan_trace. INSN is can_throw_internal. Update the
1077 data within the trace related to EH insns and args_size. */
1080 notice_eh_throw (rtx_insn
*insn
)
1082 poly_int64 args_size
= cur_trace
->end_true_args_size
;
1083 if (cur_trace
->eh_head
== NULL
)
1085 cur_trace
->eh_head
= insn
;
1086 cur_trace
->beg_delay_args_size
= args_size
;
1087 cur_trace
->end_delay_args_size
= args_size
;
1089 else if (maybe_ne (cur_trace
->end_delay_args_size
, args_size
))
1091 cur_trace
->end_delay_args_size
= args_size
;
1093 /* ??? If the CFA is the stack pointer, search backward for the last
1094 CFI note and insert there. Given that the stack changed for the
1095 args_size change, there *must* be such a note in between here and
1096 the last eh insn. */
1097 add_cfi_args_size (args_size
);
1101 /* Short-hand inline for the very common D_F_R (REGNO (x)) operation. */
1102 /* ??? This ought to go into dwarf2out.h, except that dwarf2out.h is
1103 used in places where rtl is prohibited. */
1105 static inline unsigned
1106 dwf_regno (const_rtx reg
)
1108 gcc_assert (REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
1109 return DWARF_FRAME_REGNUM (REGNO (reg
));
1112 /* Like dwf_regno, but when the value can span multiple registers. */
1114 static struct cfa_reg
1115 dwf_cfa_reg (rtx reg
)
1117 struct cfa_reg result
;
1119 result
.reg
= dwf_regno (reg
);
1121 result
.span_width
= 0;
1123 rtx span
= targetm
.dwarf_register_span (reg
);
1126 /* We only support the simple case of consecutive registers all with the
1128 result
.span
= XVECLEN (span
, 0);
1129 result
.span_width
= GET_MODE_SIZE (GET_MODE (XVECEXP (span
, 0, 0)))
1134 /* Ensure that the above assumption is accurate. */
1135 for (unsigned int i
= 0; i
< result
.span
; i
++)
1137 gcc_assert (GET_MODE_SIZE (GET_MODE (XVECEXP (span
, 0, i
)))
1138 .to_constant () == result
.span_width
);
1139 gcc_assert (REG_P (XVECEXP (span
, 0, i
)));
1140 gcc_assert (dwf_regno (XVECEXP (span
, 0, i
)) == result
.reg
+ i
);
1148 /* More efficient comparisons that don't call targetm.dwarf_register_span
1149 unnecessarily. These cfa_reg vs. rtx comparisons should be done at
1150 least for call-saved REGs that might not be CFA related (like stack
1151 pointer, hard frame pointer or DRAP registers are), in other cases it is
1152 just a compile time and memory optimization. */
1155 operator== (cfa_reg
&cfa
, rtx reg
)
1157 unsigned int regno
= dwf_regno (reg
);
1158 if (cfa
.reg
!= regno
)
1160 struct cfa_reg other
= dwf_cfa_reg (reg
);
1161 return cfa
== other
;
1165 operator!= (cfa_reg
&cfa
, rtx reg
)
1167 return !(cfa
== reg
);
1170 /* Compare X and Y for equivalence. The inputs may be REGs or PC_RTX. */
1173 compare_reg_or_pc (rtx x
, rtx y
)
1175 if (REG_P (x
) && REG_P (y
))
1176 return REGNO (x
) == REGNO (y
);
1180 /* Record SRC as being saved in DEST. DEST may be null to delete an
1181 existing entry. SRC may be a register or PC_RTX. */
1184 record_reg_saved_in_reg (rtx dest
, rtx src
)
1186 reg_saved_in_data
*elt
;
1189 FOR_EACH_VEC_ELT (cur_trace
->regs_saved_in_regs
, i
, elt
)
1190 if (compare_reg_or_pc (elt
->orig_reg
, src
))
1193 cur_trace
->regs_saved_in_regs
.unordered_remove (i
);
1195 elt
->saved_in_reg
= dest
;
1202 reg_saved_in_data e
= {src
, dest
};
1203 cur_trace
->regs_saved_in_regs
.safe_push (e
);
1206 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1207 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1210 queue_reg_save (rtx reg
, rtx sreg
, poly_int64 offset
)
1213 queued_reg_save e
= {reg
, sreg
, offset
};
1216 /* Duplicates waste space, but it's also necessary to remove them
1217 for correctness, since the queue gets output in reverse order. */
1218 FOR_EACH_VEC_ELT (queued_reg_saves
, i
, q
)
1219 if (compare_reg_or_pc (q
->reg
, reg
))
1225 queued_reg_saves
.safe_push (e
);
1228 /* Output all the entries in QUEUED_REG_SAVES. */
1231 dwarf2out_flush_queued_reg_saves (void)
1236 FOR_EACH_VEC_ELT (queued_reg_saves
, i
, q
)
1239 struct cfa_reg sreg
;
1241 record_reg_saved_in_reg (q
->saved_reg
, q
->reg
);
1243 if (q
->reg
== pc_rtx
)
1244 reg
= DWARF_FRAME_RETURN_COLUMN
;
1246 reg
= dwf_regno (q
->reg
);
1248 sreg
= dwf_cfa_reg (q
->saved_reg
);
1250 sreg
.set_by_dwreg (INVALID_REGNUM
);
1251 reg_save (reg
, sreg
, q
->cfa_offset
);
1254 queued_reg_saves
.truncate (0);
1257 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1258 location for? Or, does it clobber a register which we've previously
1259 said that some other register is saved in, and for which we now
1260 have a new location for? */
1263 clobbers_queued_reg_save (const_rtx insn
)
1268 FOR_EACH_VEC_ELT (queued_reg_saves
, iq
, q
)
1271 reg_saved_in_data
*rir
;
1273 if (modified_in_p (q
->reg
, insn
))
1276 FOR_EACH_VEC_ELT (cur_trace
->regs_saved_in_regs
, ir
, rir
)
1277 if (compare_reg_or_pc (q
->reg
, rir
->orig_reg
)
1278 && modified_in_p (rir
->saved_in_reg
, insn
))
1285 /* What register, if any, is currently saved in REG? */
1288 reg_saved_in (rtx reg
)
1290 unsigned int regn
= REGNO (reg
);
1292 reg_saved_in_data
*rir
;
1295 FOR_EACH_VEC_ELT (queued_reg_saves
, i
, q
)
1296 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1299 FOR_EACH_VEC_ELT (cur_trace
->regs_saved_in_regs
, i
, rir
)
1300 if (regn
== REGNO (rir
->saved_in_reg
))
1301 return rir
->orig_reg
;
1306 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1309 dwarf2out_frame_debug_def_cfa (rtx pat
)
1311 memset (cur_cfa
, 0, sizeof (*cur_cfa
));
1313 pat
= strip_offset (pat
, &cur_cfa
->offset
);
1316 cur_cfa
->indirect
= 1;
1317 pat
= strip_offset (XEXP (pat
, 0), &cur_cfa
->base_offset
);
1319 /* ??? If this fails, we could be calling into the _loc functions to
1320 define a full expression. So far no port does that. */
1321 gcc_assert (REG_P (pat
));
1322 cur_cfa
->reg
= dwf_cfa_reg (pat
);
1325 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1328 dwarf2out_frame_debug_adjust_cfa (rtx pat
)
1332 gcc_assert (GET_CODE (pat
) == SET
);
1333 dest
= XEXP (pat
, 0);
1334 src
= XEXP (pat
, 1);
1336 switch (GET_CODE (src
))
1339 gcc_assert (cur_cfa
->reg
== XEXP (src
, 0));
1340 cur_cfa
->offset
-= rtx_to_poly_int64 (XEXP (src
, 1));
1350 cur_cfa
->reg
= dwf_cfa_reg (dest
);
1351 gcc_assert (cur_cfa
->indirect
== 0);
1354 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1357 dwarf2out_frame_debug_cfa_offset (rtx set
)
1360 rtx src
, addr
, span
;
1361 unsigned int sregno
;
1363 src
= XEXP (set
, 1);
1364 addr
= XEXP (set
, 0);
1365 gcc_assert (MEM_P (addr
));
1366 addr
= XEXP (addr
, 0);
1368 /* As documented, only consider extremely simple addresses. */
1369 switch (GET_CODE (addr
))
1372 gcc_assert (cur_cfa
->reg
== addr
);
1373 offset
= -cur_cfa
->offset
;
1376 gcc_assert (cur_cfa
->reg
== XEXP (addr
, 0));
1377 offset
= rtx_to_poly_int64 (XEXP (addr
, 1)) - cur_cfa
->offset
;
1386 sregno
= DWARF_FRAME_RETURN_COLUMN
;
1390 span
= targetm
.dwarf_register_span (src
);
1391 sregno
= dwf_regno (src
);
1394 /* ??? We'd like to use queue_reg_save, but we need to come up with
1395 a different flushing heuristic for epilogues. */
1396 struct cfa_reg invalid
;
1397 invalid
.set_by_dwreg (INVALID_REGNUM
);
1399 reg_save (sregno
, invalid
, offset
);
1402 /* We have a PARALLEL describing where the contents of SRC live.
1403 Adjust the offset for each piece of the PARALLEL. */
1404 poly_int64 span_offset
= offset
;
1406 gcc_assert (GET_CODE (span
) == PARALLEL
);
1408 const int par_len
= XVECLEN (span
, 0);
1409 for (int par_index
= 0; par_index
< par_len
; par_index
++)
1411 rtx elem
= XVECEXP (span
, 0, par_index
);
1412 sregno
= dwf_regno (src
);
1413 reg_save (sregno
, invalid
, span_offset
);
1414 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
1419 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
1422 dwarf2out_frame_debug_cfa_register (rtx set
)
1426 struct cfa_reg dregno
;
1428 src
= XEXP (set
, 1);
1429 dest
= XEXP (set
, 0);
1431 record_reg_saved_in_reg (dest
, src
);
1433 sregno
= DWARF_FRAME_RETURN_COLUMN
;
1435 sregno
= dwf_regno (src
);
1437 dregno
= dwf_cfa_reg (dest
);
1439 /* ??? We'd like to use queue_reg_save, but we need to come up with
1440 a different flushing heuristic for epilogues. */
1441 reg_save (sregno
, dregno
, 0);
1444 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
1447 dwarf2out_frame_debug_cfa_expression (rtx set
)
1449 rtx src
, dest
, span
;
1450 dw_cfi_ref cfi
= new_cfi ();
1453 dest
= SET_DEST (set
);
1454 src
= SET_SRC (set
);
1456 gcc_assert (REG_P (src
));
1457 gcc_assert (MEM_P (dest
));
1459 span
= targetm
.dwarf_register_span (src
);
1462 regno
= dwf_regno (src
);
1464 cfi
->dw_cfi_opc
= DW_CFA_expression
;
1465 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= regno
;
1466 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1467 = mem_loc_descriptor (XEXP (dest
, 0), get_address_mode (dest
),
1468 GET_MODE (dest
), VAR_INIT_STATUS_INITIALIZED
);
1470 /* ??? We'd like to use queue_reg_save, were the interface different,
1471 and, as above, we could manage flushing for epilogues. */
1473 update_row_reg_save (cur_row
, regno
, cfi
);
1476 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_VAL_EXPRESSION
1480 dwarf2out_frame_debug_cfa_val_expression (rtx set
)
1482 rtx dest
= SET_DEST (set
);
1483 gcc_assert (REG_P (dest
));
1485 rtx span
= targetm
.dwarf_register_span (dest
);
1488 rtx src
= SET_SRC (set
);
1489 dw_cfi_ref cfi
= new_cfi ();
1490 cfi
->dw_cfi_opc
= DW_CFA_val_expression
;
1491 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= dwf_regno (dest
);
1492 cfi
->dw_cfi_oprnd2
.dw_cfi_loc
1493 = mem_loc_descriptor (src
, GET_MODE (src
),
1494 GET_MODE (dest
), VAR_INIT_STATUS_INITIALIZED
);
1496 update_row_reg_save (cur_row
, dwf_regno (dest
), cfi
);
1499 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE
1500 note. When called with EMIT_CFI set to false emitting a CFI
1501 statement is suppressed. */
1504 dwarf2out_frame_debug_cfa_restore (rtx reg
, bool emit_cfi
)
1506 gcc_assert (REG_P (reg
));
1508 rtx span
= targetm
.dwarf_register_span (reg
);
1511 unsigned int regno
= dwf_regno (reg
);
1513 add_cfi_restore (regno
);
1514 update_row_reg_save (cur_row
, regno
, NULL
);
1518 /* We have a PARALLEL describing where the contents of REG live.
1519 Restore the register for each piece of the PARALLEL. */
1520 gcc_assert (GET_CODE (span
) == PARALLEL
);
1522 const int par_len
= XVECLEN (span
, 0);
1523 for (int par_index
= 0; par_index
< par_len
; par_index
++)
1525 reg
= XVECEXP (span
, 0, par_index
);
1526 gcc_assert (REG_P (reg
));
1527 unsigned int regno
= dwf_regno (reg
);
1529 add_cfi_restore (regno
);
1530 update_row_reg_save (cur_row
, regno
, NULL
);
1535 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE.
1537 ??? Perhaps we should note in the CIE where windows are saved (instead
1538 of assuming 0(cfa)) and what registers are in the window. */
1541 dwarf2out_frame_debug_cfa_window_save (void)
1543 dw_cfi_ref cfi
= new_cfi ();
1545 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
1547 cur_row
->window_save
= true;
1550 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_TOGGLE_RA_MANGLE.
1551 Note: DW_CFA_GNU_window_save dwarf opcode is reused for toggling RA mangle
1552 state, this is a target specific operation on AArch64 and can only be used
1553 on other targets if they don't use the window save operation otherwise. */
1556 dwarf2out_frame_debug_cfa_toggle_ra_mangle (void)
1558 dw_cfi_ref cfi
= new_cfi ();
1560 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
1562 cur_row
->ra_mangled
= !cur_row
->ra_mangled
;
1565 /* Record call frame debugging information for an expression EXPR,
1566 which either sets SP or FP (adjusting how we calculate the frame
1567 address) or saves a register to the stack or another register.
1568 LABEL indicates the address of EXPR.
1570 This function encodes a state machine mapping rtxes to actions on
1571 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1572 users need not read the source code.
1574 The High-Level Picture
1576 Changes in the register we use to calculate the CFA: Currently we
1577 assume that if you copy the CFA register into another register, we
1578 should take the other one as the new CFA register; this seems to
1579 work pretty well. If it's wrong for some target, it's simple
1580 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1582 Changes in the register we use for saving registers to the stack:
1583 This is usually SP, but not always. Again, we deduce that if you
1584 copy SP into another register (and SP is not the CFA register),
1585 then the new register is the one we will be using for register
1586 saves. This also seems to work.
1588 Register saves: There's not much guesswork about this one; if
1589 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1590 register save, and the register used to calculate the destination
1591 had better be the one we think we're using for this purpose.
1592 It's also assumed that a copy from a call-saved register to another
1593 register is saving that register if RTX_FRAME_RELATED_P is set on
1594 that instruction. If the copy is from a call-saved register to
1595 the *same* register, that means that the register is now the same
1596 value as in the caller.
1598 Except: If the register being saved is the CFA register, and the
1599 offset is nonzero, we are saving the CFA, so we assume we have to
1600 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1601 the intent is to save the value of SP from the previous frame.
1603 In addition, if a register has previously been saved to a different
1606 Invariants / Summaries of Rules
1608 cfa current rule for calculating the CFA. It usually
1609 consists of a register and an offset. This is
1610 actually stored in *cur_cfa, but abbreviated
1611 for the purposes of this documentation.
1612 cfa_store register used by prologue code to save things to the stack
1613 cfa_store.offset is the offset from the value of
1614 cfa_store.reg to the actual CFA
1615 cfa_temp register holding an integral value. cfa_temp.offset
1616 stores the value, which will be used to adjust the
1617 stack pointer. cfa_temp is also used like cfa_store,
1618 to track stores to the stack via fp or a temp reg.
1620 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1621 with cfa.reg as the first operand changes the cfa.reg and its
1622 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1625 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1626 expression yielding a constant. This sets cfa_temp.reg
1627 and cfa_temp.offset.
1629 Rule 5: Create a new register cfa_store used to save items to the
1632 Rules 10-14: Save a register to the stack. Define offset as the
1633 difference of the original location and cfa_store's
1634 location (or cfa_temp's location if cfa_temp is used).
1636 Rules 16-20: If AND operation happens on sp in prologue, we assume
1637 stack is realigned. We will use a group of DW_OP_XXX
1638 expressions to represent the location of the stored
1639 register instead of CFA+offset.
1643 "{a,b}" indicates a choice of a xor b.
1644 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1647 (set <reg1> <reg2>:cfa.reg)
1648 effects: cfa.reg = <reg1>
1649 cfa.offset unchanged
1650 cfa_temp.reg = <reg1>
1651 cfa_temp.offset = cfa.offset
1654 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1655 {<const_int>,<reg>:cfa_temp.reg}))
1656 effects: cfa.reg = sp if fp used
1657 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1658 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1659 if cfa_store.reg==sp
1662 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1663 effects: cfa.reg = fp
1664 cfa_offset += +/- <const_int>
1667 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1668 constraints: <reg1> != fp
1670 effects: cfa.reg = <reg1>
1671 cfa_temp.reg = <reg1>
1672 cfa_temp.offset = cfa.offset
1675 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1676 constraints: <reg1> != fp
1678 effects: cfa_store.reg = <reg1>
1679 cfa_store.offset = cfa.offset - cfa_temp.offset
1682 (set <reg> <const_int>)
1683 effects: cfa_temp.reg = <reg>
1684 cfa_temp.offset = <const_int>
1687 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1688 effects: cfa_temp.reg = <reg1>
1689 cfa_temp.offset |= <const_int>
1692 (set <reg> (high <exp>))
1696 (set <reg> (lo_sum <exp> <const_int>))
1697 effects: cfa_temp.reg = <reg>
1698 cfa_temp.offset = <const_int>
1701 (set (mem ({pre,post}_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1702 effects: cfa_store.offset -= <const_int>
1703 cfa.offset = cfa_store.offset if cfa.reg == sp
1705 cfa.base_offset = -cfa_store.offset
1708 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
1709 effects: cfa_store.offset += -/+ mode_size(mem)
1710 cfa.offset = cfa_store.offset if cfa.reg == sp
1712 cfa.base_offset = -cfa_store.offset
1715 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1718 effects: cfa.reg = <reg1>
1719 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1722 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1723 effects: cfa.reg = <reg1>
1724 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1727 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
1728 effects: cfa.reg = <reg1>
1729 cfa.base_offset = -cfa_temp.offset
1730 cfa_temp.offset -= mode_size(mem)
1733 (set <reg> {unspec, unspec_volatile})
1734 effects: target-dependent
1737 (set sp (and: sp <const_int>))
1738 constraints: cfa_store.reg == sp
1739 effects: cfun->fde.stack_realign = 1
1740 cfa_store.offset = 0
1741 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1744 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1745 effects: cfa_store.offset += -/+ mode_size(mem)
1748 (set (mem ({pre_inc, pre_dec} sp)) fp)
1749 constraints: fde->stack_realign == 1
1750 effects: cfa_store.offset = 0
1751 cfa.reg != HARD_FRAME_POINTER_REGNUM
1754 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1755 constraints: fde->stack_realign == 1
1757 && cfa.indirect == 0
1758 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1759 effects: Use DW_CFA_def_cfa_expression to define cfa
1760 cfa.reg == fde->drap_reg */
1763 dwarf2out_frame_debug_expr (rtx expr
)
1765 rtx src
, dest
, span
;
1769 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1770 the PARALLEL independently. The first element is always processed if
1771 it is a SET. This is for backward compatibility. Other elements
1772 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1773 flag is set in them. */
1774 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1777 int limit
= XVECLEN (expr
, 0);
1780 /* PARALLELs have strict read-modify-write semantics, so we
1781 ought to evaluate every rvalue before changing any lvalue.
1782 It's cumbersome to do that in general, but there's an
1783 easy approximation that is enough for all current users:
1784 handle register saves before register assignments. */
1785 if (GET_CODE (expr
) == PARALLEL
)
1786 for (par_index
= 0; par_index
< limit
; par_index
++)
1788 elem
= XVECEXP (expr
, 0, par_index
);
1789 if (GET_CODE (elem
) == SET
1790 && MEM_P (SET_DEST (elem
))
1791 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1792 dwarf2out_frame_debug_expr (elem
);
1795 for (par_index
= 0; par_index
< limit
; par_index
++)
1797 elem
= XVECEXP (expr
, 0, par_index
);
1798 if (GET_CODE (elem
) == SET
1799 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
1800 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1801 dwarf2out_frame_debug_expr (elem
);
1806 gcc_assert (GET_CODE (expr
) == SET
);
1808 src
= SET_SRC (expr
);
1809 dest
= SET_DEST (expr
);
1813 rtx rsi
= reg_saved_in (src
);
1820 switch (GET_CODE (dest
))
1823 switch (GET_CODE (src
))
1825 /* Setting FP from SP. */
1827 if (cur_cfa
->reg
== src
)
1830 /* Update the CFA rule wrt SP or FP. Make sure src is
1831 relative to the current CFA register.
1833 We used to require that dest be either SP or FP, but the
1834 ARM copies SP to a temporary register, and from there to
1835 FP. So we just rely on the backends to only set
1836 RTX_FRAME_RELATED_P on appropriate insns. */
1837 cur_cfa
->reg
= dwf_cfa_reg (dest
);
1838 cur_trace
->cfa_temp
.reg
= cur_cfa
->reg
;
1839 cur_trace
->cfa_temp
.offset
= cur_cfa
->offset
;
1843 /* Saving a register in a register. */
1844 gcc_assert (!fixed_regs
[REGNO (dest
)]
1845 /* For the SPARC and its register window. */
1846 || (dwf_regno (src
) == DWARF_FRAME_RETURN_COLUMN
));
1848 /* After stack is aligned, we can only save SP in FP
1849 if drap register is used. In this case, we have
1850 to restore stack pointer with the CFA value and we
1851 don't generate this DWARF information. */
1853 && fde
->stack_realign
1854 && REGNO (src
) == STACK_POINTER_REGNUM
)
1856 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
1857 && fde
->drap_reg
!= INVALID_REGNUM
1858 && cur_cfa
->reg
!= src
1861 /* The save of hard frame pointer has been deferred
1862 until this point when Rule 18 applied. Emit it now. */
1863 queue_reg_save (dest
, NULL_RTX
, 0);
1864 /* And as the instruction modifies the hard frame pointer,
1865 flush the queue as well. */
1866 dwarf2out_flush_queued_reg_saves ();
1869 queue_reg_save (src
, dest
, 0);
1876 if (dest
== stack_pointer_rtx
)
1880 if (REG_P (XEXP (src
, 1)))
1882 gcc_assert (cur_trace
->cfa_temp
.reg
== XEXP (src
, 1));
1883 offset
= cur_trace
->cfa_temp
.offset
;
1885 else if (!poly_int_rtx_p (XEXP (src
, 1), &offset
))
1888 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1890 /* Restoring SP from FP in the epilogue. */
1891 gcc_assert (cur_cfa
->reg
== dw_frame_pointer_regnum
);
1892 cur_cfa
->reg
= dw_stack_pointer_regnum
;
1894 else if (GET_CODE (src
) == LO_SUM
)
1895 /* Assume we've set the source reg of the LO_SUM from sp. */
1898 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
1900 if (GET_CODE (src
) != MINUS
)
1902 if (cur_cfa
->reg
== dw_stack_pointer_regnum
)
1903 cur_cfa
->offset
+= offset
;
1904 if (cur_trace
->cfa_store
.reg
== dw_stack_pointer_regnum
)
1905 cur_trace
->cfa_store
.offset
+= offset
;
1907 else if (dest
== hard_frame_pointer_rtx
)
1910 /* Either setting the FP from an offset of the SP,
1911 or adjusting the FP */
1912 gcc_assert (frame_pointer_needed
);
1914 gcc_assert (REG_P (XEXP (src
, 0))
1915 && cur_cfa
->reg
== XEXP (src
, 0));
1916 offset
= rtx_to_poly_int64 (XEXP (src
, 1));
1917 if (GET_CODE (src
) != MINUS
)
1919 cur_cfa
->offset
+= offset
;
1920 cur_cfa
->reg
= dw_frame_pointer_regnum
;
1924 gcc_assert (GET_CODE (src
) != MINUS
);
1927 if (REG_P (XEXP (src
, 0))
1928 && cur_cfa
->reg
== XEXP (src
, 0)
1929 && poly_int_rtx_p (XEXP (src
, 1), &offset
))
1931 /* Setting a temporary CFA register that will be copied
1932 into the FP later on. */
1934 cur_cfa
->offset
+= offset
;
1935 cur_cfa
->reg
= dwf_cfa_reg (dest
);
1936 /* Or used to save regs to the stack. */
1937 cur_trace
->cfa_temp
.reg
= cur_cfa
->reg
;
1938 cur_trace
->cfa_temp
.offset
= cur_cfa
->offset
;
1942 else if (REG_P (XEXP (src
, 0))
1943 && cur_trace
->cfa_temp
.reg
== XEXP (src
, 0)
1944 && XEXP (src
, 1) == stack_pointer_rtx
)
1946 /* Setting a scratch register that we will use instead
1947 of SP for saving registers to the stack. */
1948 gcc_assert (cur_cfa
->reg
== dw_stack_pointer_regnum
);
1949 cur_trace
->cfa_store
.reg
= dwf_cfa_reg (dest
);
1950 cur_trace
->cfa_store
.offset
1951 = cur_cfa
->offset
- cur_trace
->cfa_temp
.offset
;
1955 else if (GET_CODE (src
) == LO_SUM
1956 && poly_int_rtx_p (XEXP (src
, 1),
1957 &cur_trace
->cfa_temp
.offset
))
1958 cur_trace
->cfa_temp
.reg
= dwf_cfa_reg (dest
);
1966 case CONST_POLY_INT
:
1967 cur_trace
->cfa_temp
.reg
= dwf_cfa_reg (dest
);
1968 cur_trace
->cfa_temp
.offset
= rtx_to_poly_int64 (src
);
1973 gcc_assert (REG_P (XEXP (src
, 0))
1974 && cur_trace
->cfa_temp
.reg
== XEXP (src
, 0)
1975 && CONST_INT_P (XEXP (src
, 1)));
1977 cur_trace
->cfa_temp
.reg
= dwf_cfa_reg (dest
);
1978 if (!can_ior_p (cur_trace
->cfa_temp
.offset
, INTVAL (XEXP (src
, 1)),
1979 &cur_trace
->cfa_temp
.offset
))
1980 /* The target shouldn't generate this kind of CFI note if we
1981 can't represent it. */
1985 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1986 which will fill in all of the bits. */
1993 case UNSPEC_VOLATILE
:
1994 /* All unspecs should be represented by REG_CFA_* notes. */
2000 /* If this AND operation happens on stack pointer in prologue,
2001 we assume the stack is realigned and we extract the
2003 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
2005 /* We interpret reg_save differently with stack_realign set.
2006 Thus we must flush whatever we have queued first. */
2007 dwarf2out_flush_queued_reg_saves ();
2009 gcc_assert (cur_trace
->cfa_store
.reg
2011 fde
->stack_realign
= 1;
2012 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
2013 cur_trace
->cfa_store
.offset
= 0;
2015 if (cur_cfa
->reg
!= dw_stack_pointer_regnum
2016 && cur_cfa
->reg
!= dw_frame_pointer_regnum
)
2018 gcc_assert (cur_cfa
->reg
.span
== 1);
2019 fde
->drap_reg
= cur_cfa
->reg
.reg
;
2031 /* Saving a register to the stack. Make sure dest is relative to the
2033 switch (GET_CODE (XEXP (dest
, 0)))
2039 /* We can't handle variable size modifications. */
2040 offset
= -rtx_to_poly_int64 (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
2042 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
2043 && cur_trace
->cfa_store
.reg
== dw_stack_pointer_regnum
);
2045 cur_trace
->cfa_store
.offset
+= offset
;
2046 if (cur_cfa
->reg
== dw_stack_pointer_regnum
)
2047 cur_cfa
->offset
= cur_trace
->cfa_store
.offset
;
2049 if (GET_CODE (XEXP (dest
, 0)) == POST_MODIFY
)
2050 offset
-= cur_trace
->cfa_store
.offset
;
2052 offset
= -cur_trace
->cfa_store
.offset
;
2059 offset
= GET_MODE_SIZE (GET_MODE (dest
));
2060 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
2063 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
2064 == STACK_POINTER_REGNUM
)
2065 && cur_trace
->cfa_store
.reg
== dw_stack_pointer_regnum
);
2067 cur_trace
->cfa_store
.offset
+= offset
;
2069 /* Rule 18: If stack is aligned, we will use FP as a
2070 reference to represent the address of the stored
2073 && fde
->stack_realign
2075 && REGNO (src
) == HARD_FRAME_POINTER_REGNUM
)
2077 gcc_assert (cur_cfa
->reg
!= dw_frame_pointer_regnum
);
2078 cur_trace
->cfa_store
.offset
= 0;
2082 if (cur_cfa
->reg
== dw_stack_pointer_regnum
)
2083 cur_cfa
->offset
= cur_trace
->cfa_store
.offset
;
2085 if (GET_CODE (XEXP (dest
, 0)) == POST_DEC
)
2086 offset
+= -cur_trace
->cfa_store
.offset
;
2088 offset
= -cur_trace
->cfa_store
.offset
;
2092 /* With an offset. */
2097 struct cfa_reg regno
;
2099 gcc_assert (REG_P (XEXP (XEXP (dest
, 0), 0)));
2100 offset
= rtx_to_poly_int64 (XEXP (XEXP (dest
, 0), 1));
2101 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
2104 regno
= dwf_cfa_reg (XEXP (XEXP (dest
, 0), 0));
2106 if (cur_cfa
->reg
== regno
)
2107 offset
-= cur_cfa
->offset
;
2108 else if (cur_trace
->cfa_store
.reg
== regno
)
2109 offset
-= cur_trace
->cfa_store
.offset
;
2112 gcc_assert (cur_trace
->cfa_temp
.reg
== regno
);
2113 offset
-= cur_trace
->cfa_temp
.offset
;
2119 /* Without an offset. */
2122 struct cfa_reg regno
= dwf_cfa_reg (XEXP (dest
, 0));
2124 if (cur_cfa
->reg
== regno
)
2125 offset
= -cur_cfa
->offset
;
2126 else if (cur_trace
->cfa_store
.reg
== regno
)
2127 offset
= -cur_trace
->cfa_store
.offset
;
2130 gcc_assert (cur_trace
->cfa_temp
.reg
== regno
);
2131 offset
= -cur_trace
->cfa_temp
.offset
;
2138 gcc_assert (cur_trace
->cfa_temp
.reg
== XEXP (XEXP (dest
, 0), 0));
2139 offset
= -cur_trace
->cfa_temp
.offset
;
2140 cur_trace
->cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
2148 /* If the source operand of this MEM operation is a memory,
2149 we only care how much stack grew. */
2154 && REGNO (src
) != STACK_POINTER_REGNUM
2155 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
2156 && cur_cfa
->reg
== src
)
2158 /* We're storing the current CFA reg into the stack. */
2160 if (known_eq (cur_cfa
->offset
, 0))
2163 /* If stack is aligned, putting CFA reg into stack means
2164 we can no longer use reg + offset to represent CFA.
2165 Here we use DW_CFA_def_cfa_expression instead. The
2166 result of this expression equals to the original CFA
2169 && fde
->stack_realign
2170 && cur_cfa
->indirect
== 0
2171 && cur_cfa
->reg
!= dw_frame_pointer_regnum
)
2173 gcc_assert (fde
->drap_reg
== cur_cfa
->reg
.reg
);
2175 cur_cfa
->indirect
= 1;
2176 cur_cfa
->reg
= dw_frame_pointer_regnum
;
2177 cur_cfa
->base_offset
= offset
;
2178 cur_cfa
->offset
= 0;
2180 fde
->drap_reg_saved
= 1;
2184 /* If the source register is exactly the CFA, assume
2185 we're saving SP like any other register; this happens
2187 queue_reg_save (stack_pointer_rtx
, NULL_RTX
, offset
);
2192 /* Otherwise, we'll need to look in the stack to
2193 calculate the CFA. */
2194 rtx x
= XEXP (dest
, 0);
2198 gcc_assert (REG_P (x
));
2200 cur_cfa
->reg
= dwf_cfa_reg (x
);
2201 cur_cfa
->base_offset
= offset
;
2202 cur_cfa
->indirect
= 1;
2208 span
= targetm
.dwarf_register_span (src
);
2215 /* Just verify the hard frame pointer save when doing dynamic
2216 realignment uses expected offset. The actual queue_reg_save
2217 needs to be deferred until the instruction that sets
2218 hard frame pointer to stack pointer, see PR99334 for
2220 gcc_assert (known_eq (offset
, 0));
2222 queue_reg_save (src
, NULL_RTX
, offset
);
2226 /* We have a PARALLEL describing where the contents of SRC live.
2227 Queue register saves for each piece of the PARALLEL. */
2228 poly_int64 span_offset
= offset
;
2230 gcc_assert (GET_CODE (span
) == PARALLEL
);
2232 const int par_len
= XVECLEN (span
, 0);
2233 for (int par_index
= 0; par_index
< par_len
; par_index
++)
2235 rtx elem
= XVECEXP (span
, 0, par_index
);
2236 queue_reg_save (elem
, NULL_RTX
, span_offset
);
2237 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2247 /* Record call frame debugging information for INSN, which either sets
2248 SP or FP (adjusting how we calculate the frame address) or saves a
2249 register to the stack. */
2252 dwarf2out_frame_debug (rtx_insn
*insn
)
2255 bool handled_one
= false;
2257 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
2258 switch (REG_NOTE_KIND (note
))
2260 case REG_FRAME_RELATED_EXPR
:
2261 pat
= XEXP (note
, 0);
2264 case REG_CFA_DEF_CFA
:
2265 dwarf2out_frame_debug_def_cfa (XEXP (note
, 0));
2269 case REG_CFA_ADJUST_CFA
:
2274 if (GET_CODE (n
) == PARALLEL
)
2275 n
= XVECEXP (n
, 0, 0);
2277 dwarf2out_frame_debug_adjust_cfa (n
);
2281 case REG_CFA_OFFSET
:
2284 n
= single_set (insn
);
2285 dwarf2out_frame_debug_cfa_offset (n
);
2289 case REG_CFA_REGISTER
:
2294 if (GET_CODE (n
) == PARALLEL
)
2295 n
= XVECEXP (n
, 0, 0);
2297 dwarf2out_frame_debug_cfa_register (n
);
2301 case REG_CFA_EXPRESSION
:
2302 case REG_CFA_VAL_EXPRESSION
:
2305 n
= single_set (insn
);
2307 if (REG_NOTE_KIND (note
) == REG_CFA_EXPRESSION
)
2308 dwarf2out_frame_debug_cfa_expression (n
);
2310 dwarf2out_frame_debug_cfa_val_expression (n
);
2315 case REG_CFA_RESTORE
:
2316 case REG_CFA_NO_RESTORE
:
2321 if (GET_CODE (n
) == PARALLEL
)
2322 n
= XVECEXP (n
, 0, 0);
2325 dwarf2out_frame_debug_cfa_restore (n
, REG_NOTE_KIND (note
) == REG_CFA_RESTORE
);
2329 case REG_CFA_SET_VDRAP
:
2333 dw_fde_ref fde
= cfun
->fde
;
2336 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
2338 fde
->vdrap_reg
= dwf_regno (n
);
2344 case REG_CFA_TOGGLE_RA_MANGLE
:
2345 dwarf2out_frame_debug_cfa_toggle_ra_mangle ();
2349 case REG_CFA_WINDOW_SAVE
:
2350 dwarf2out_frame_debug_cfa_window_save ();
2354 case REG_CFA_FLUSH_QUEUE
:
2355 /* The actual flush happens elsewhere. */
2365 pat
= PATTERN (insn
);
2367 dwarf2out_frame_debug_expr (pat
);
2369 /* Check again. A parallel can save and update the same register.
2370 We could probably check just once, here, but this is safer than
2371 removing the check at the start of the function. */
2372 if (clobbers_queued_reg_save (pat
))
2373 dwarf2out_flush_queued_reg_saves ();
2377 /* Emit CFI info to change the state from OLD_ROW to NEW_ROW. */
2380 change_cfi_row (dw_cfi_row
*old_row
, dw_cfi_row
*new_row
)
2382 size_t i
, n_old
, n_new
, n_max
;
2385 if (new_row
->cfa_cfi
&& !cfi_equal_p (old_row
->cfa_cfi
, new_row
->cfa_cfi
))
2386 add_cfi (new_row
->cfa_cfi
);
2389 cfi
= def_cfa_0 (&old_row
->cfa
, &new_row
->cfa
);
2394 n_old
= vec_safe_length (old_row
->reg_save
);
2395 n_new
= vec_safe_length (new_row
->reg_save
);
2396 n_max
= MAX (n_old
, n_new
);
2398 for (i
= 0; i
< n_max
; ++i
)
2400 dw_cfi_ref r_old
= NULL
, r_new
= NULL
;
2403 r_old
= (*old_row
->reg_save
)[i
];
2405 r_new
= (*new_row
->reg_save
)[i
];
2409 else if (r_new
== NULL
)
2410 add_cfi_restore (i
);
2411 else if (!cfi_equal_p (r_old
, r_new
))
2415 if (!old_row
->window_save
&& new_row
->window_save
)
2417 dw_cfi_ref cfi
= new_cfi ();
2419 gcc_assert (!old_row
->ra_mangled
&& !new_row
->ra_mangled
);
2420 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
2424 if (old_row
->ra_mangled
!= new_row
->ra_mangled
)
2426 dw_cfi_ref cfi
= new_cfi ();
2428 gcc_assert (!old_row
->window_save
&& !new_row
->window_save
);
2429 /* DW_CFA_GNU_window_save is reused for toggling RA mangle state. */
2430 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
2435 /* Examine CFI and return true if a cfi label and set_loc is needed
2436 beforehand. Even when generating CFI assembler instructions, we
2437 still have to add the cfi to the list so that lookup_cfa_1 works
2438 later on. When -g2 and above we even need to force emitting of
2439 CFI labels and add to list a DW_CFA_set_loc for convert_cfa_to_fb_loc_list
2440 purposes. If we're generating DWARF3 output we use DW_OP_call_frame_cfa
2441 and so don't use convert_cfa_to_fb_loc_list. */
2444 cfi_label_required_p (dw_cfi_ref cfi
)
2446 if (!dwarf2out_do_cfi_asm ())
2449 if (dwarf_version
== 2
2450 && debug_info_level
> DINFO_LEVEL_TERSE
2451 && dwarf_debuginfo_p ())
2453 switch (cfi
->dw_cfi_opc
)
2455 case DW_CFA_def_cfa_offset
:
2456 case DW_CFA_def_cfa_offset_sf
:
2457 case DW_CFA_def_cfa_register
:
2458 case DW_CFA_def_cfa
:
2459 case DW_CFA_def_cfa_sf
:
2460 case DW_CFA_def_cfa_expression
:
2461 case DW_CFA_restore_state
:
2470 /* Walk the function, looking for NOTE_INSN_CFI notes. Add the CFIs to the
2471 function's FDE, adding CFI labels and set_loc/advance_loc opcodes as
2474 add_cfis_to_fde (void)
2476 dw_fde_ref fde
= cfun
->fde
;
2477 rtx_insn
*insn
, *next
;
2479 for (insn
= get_insns (); insn
; insn
= next
)
2481 next
= NEXT_INSN (insn
);
2483 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
)
2484 fde
->dw_fde_switch_cfi_index
= vec_safe_length (fde
->dw_fde_cfi
);
2486 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_CFI
)
2488 bool required
= cfi_label_required_p (NOTE_CFI (insn
));
2490 if (NOTE_P (next
) && NOTE_KIND (next
) == NOTE_INSN_CFI
)
2492 required
|= cfi_label_required_p (NOTE_CFI (next
));
2493 next
= NEXT_INSN (next
);
2495 else if (active_insn_p (next
)
2496 || (NOTE_P (next
) && (NOTE_KIND (next
)
2497 == NOTE_INSN_SWITCH_TEXT_SECTIONS
)))
2500 next
= NEXT_INSN (next
);
2503 int num
= dwarf2out_cfi_label_num
;
2504 const char *label
= dwarf2out_cfi_label ();
2507 /* Set the location counter to the new label. */
2509 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
2510 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
2511 vec_safe_push (fde
->dw_fde_cfi
, xcfi
);
2513 rtx_note
*tmp
= emit_note_before (NOTE_INSN_CFI_LABEL
, insn
);
2514 NOTE_LABEL_NUMBER (tmp
) = num
;
2519 if (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_CFI
)
2520 vec_safe_push (fde
->dw_fde_cfi
, NOTE_CFI (insn
));
2521 insn
= NEXT_INSN (insn
);
2523 while (insn
!= next
);
2528 static void dump_cfi_row (FILE *f
, dw_cfi_row
*row
);
2530 /* If LABEL is the start of a trace, then initialize the state of that
2531 trace from CUR_TRACE and CUR_ROW. */
2534 maybe_record_trace_start (rtx_insn
*start
, rtx_insn
*origin
)
2538 ti
= get_trace_info (start
);
2539 gcc_assert (ti
!= NULL
);
2543 fprintf (dump_file
, " saw edge from trace %u to %u (via %s %d)\n",
2544 cur_trace
->id
, ti
->id
,
2545 (origin
? rtx_name
[(int) GET_CODE (origin
)] : "fallthru"),
2546 (origin
? INSN_UID (origin
) : 0));
2549 poly_int64 args_size
= cur_trace
->end_true_args_size
;
2550 if (ti
->beg_row
== NULL
)
2552 /* This is the first time we've encountered this trace. Propagate
2553 state across the edge and push the trace onto the work list. */
2554 ti
->beg_row
= copy_cfi_row (cur_row
);
2555 ti
->beg_true_args_size
= args_size
;
2557 ti
->cfa_store
= cur_trace
->cfa_store
;
2558 ti
->cfa_temp
= cur_trace
->cfa_temp
;
2559 ti
->regs_saved_in_regs
= cur_trace
->regs_saved_in_regs
.copy ();
2561 trace_work_list
.safe_push (ti
);
2564 fprintf (dump_file
, "\tpush trace %u to worklist\n", ti
->id
);
2569 /* We ought to have the same state incoming to a given trace no
2570 matter how we arrive at the trace. Anything else means we've
2571 got some kind of optimization error. */
2573 if (!cfi_row_equal_p (cur_row
, ti
->beg_row
))
2577 fprintf (dump_file
, "Inconsistent CFI state!\n");
2578 fprintf (dump_file
, "SHOULD have:\n");
2579 dump_cfi_row (dump_file
, ti
->beg_row
);
2580 fprintf (dump_file
, "DO have:\n");
2581 dump_cfi_row (dump_file
, cur_row
);
2588 /* The args_size is allowed to conflict if it isn't actually used. */
2589 if (maybe_ne (ti
->beg_true_args_size
, args_size
))
2590 ti
->args_size_undefined
= true;
2594 /* Similarly, but handle the args_size and CFA reset across EH
2595 and non-local goto edges. */
2598 maybe_record_trace_start_abnormal (rtx_insn
*start
, rtx_insn
*origin
)
2600 poly_int64 save_args_size
, delta
;
2601 dw_cfa_location save_cfa
;
2603 save_args_size
= cur_trace
->end_true_args_size
;
2604 if (known_eq (save_args_size
, 0))
2606 maybe_record_trace_start (start
, origin
);
2610 delta
= -save_args_size
;
2611 cur_trace
->end_true_args_size
= 0;
2613 save_cfa
= cur_row
->cfa
;
2614 if (cur_row
->cfa
.reg
== dw_stack_pointer_regnum
)
2616 /* Convert a change in args_size (always a positive in the
2617 direction of stack growth) to a change in stack pointer. */
2618 if (!STACK_GROWS_DOWNWARD
)
2621 cur_row
->cfa
.offset
+= delta
;
2624 maybe_record_trace_start (start
, origin
);
2626 cur_trace
->end_true_args_size
= save_args_size
;
2627 cur_row
->cfa
= save_cfa
;
2630 /* Propagate CUR_TRACE state to the destinations implied by INSN. */
2631 /* ??? Sadly, this is in large part a duplicate of make_edges. */
2634 create_trace_edges (rtx_insn
*insn
)
2641 rtx_jump_table_data
*table
;
2643 if (find_reg_note (insn
, REG_NON_LOCAL_GOTO
, NULL_RTX
))
2646 if (tablejump_p (insn
, NULL
, &table
))
2648 rtvec vec
= table
->get_labels ();
2650 n
= GET_NUM_ELEM (vec
);
2651 for (i
= 0; i
< n
; ++i
)
2653 rtx_insn
*lab
= as_a
<rtx_insn
*> (XEXP (RTVEC_ELT (vec
, i
), 0));
2654 maybe_record_trace_start (lab
, insn
);
2657 /* Handle casesi dispatch insns. */
2658 if ((tmp
= tablejump_casesi_pattern (insn
)) != NULL_RTX
)
2660 rtx_insn
* lab
= label_ref_label (XEXP (SET_SRC (tmp
), 2));
2661 maybe_record_trace_start (lab
, insn
);
2664 else if (computed_jump_p (insn
))
2668 FOR_EACH_VEC_SAFE_ELT (forced_labels
, i
, temp
)
2669 maybe_record_trace_start (temp
, insn
);
2671 else if (returnjump_p (insn
))
2673 else if ((tmp
= extract_asm_operands (PATTERN (insn
))) != NULL
)
2675 n
= ASM_OPERANDS_LABEL_LENGTH (tmp
);
2676 for (i
= 0; i
< n
; ++i
)
2679 as_a
<rtx_insn
*> (XEXP (ASM_OPERANDS_LABEL (tmp
, i
), 0));
2680 maybe_record_trace_start (lab
, insn
);
2685 rtx_insn
*lab
= JUMP_LABEL_AS_INSN (insn
);
2686 gcc_assert (lab
!= NULL
);
2687 maybe_record_trace_start (lab
, insn
);
2690 else if (CALL_P (insn
))
2692 /* Sibling calls don't have edges inside this function. */
2693 if (SIBLING_CALL_P (insn
))
2696 /* Process non-local goto edges. */
2697 if (can_nonlocal_goto (insn
))
2698 for (rtx_insn_list
*lab
= nonlocal_goto_handler_labels
;
2701 maybe_record_trace_start_abnormal (lab
->insn (), insn
);
2703 else if (rtx_sequence
*seq
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
2705 int i
, n
= seq
->len ();
2706 for (i
= 0; i
< n
; ++i
)
2707 create_trace_edges (seq
->insn (i
));
2711 /* Process EH edges. */
2712 if (CALL_P (insn
) || cfun
->can_throw_non_call_exceptions
)
2714 eh_landing_pad lp
= get_eh_landing_pad_from_rtx (insn
);
2716 maybe_record_trace_start_abnormal (lp
->landing_pad
, insn
);
2720 /* A subroutine of scan_trace. Do what needs to be done "after" INSN. */
2723 scan_insn_after (rtx_insn
*insn
)
2725 if (RTX_FRAME_RELATED_P (insn
))
2726 dwarf2out_frame_debug (insn
);
2727 notice_args_size (insn
);
2730 /* Scan the trace beginning at INSN and create the CFI notes for the
2731 instructions therein. */
2734 scan_trace (dw_trace_info
*trace
, bool entry
)
2736 rtx_insn
*prev
, *insn
= trace
->head
;
2737 dw_cfa_location this_cfa
;
2740 fprintf (dump_file
, "Processing trace %u : start at %s %d\n",
2741 trace
->id
, rtx_name
[(int) GET_CODE (insn
)],
2744 trace
->end_row
= copy_cfi_row (trace
->beg_row
);
2745 trace
->end_true_args_size
= trace
->beg_true_args_size
;
2748 cur_row
= trace
->end_row
;
2750 this_cfa
= cur_row
->cfa
;
2751 cur_cfa
= &this_cfa
;
2753 /* If the current function starts with a non-standard incoming frame
2754 sp offset, emit a note before the first instruction. */
2756 && DEFAULT_INCOMING_FRAME_SP_OFFSET
!= INCOMING_FRAME_SP_OFFSET
)
2758 add_cfi_insn
= insn
;
2759 gcc_assert (NOTE_P (insn
) && NOTE_KIND (insn
) == NOTE_INSN_DELETED
);
2760 this_cfa
.offset
= INCOMING_FRAME_SP_OFFSET
;
2761 def_cfa_1 (&this_cfa
);
2764 for (prev
= insn
, insn
= NEXT_INSN (insn
);
2766 prev
= insn
, insn
= NEXT_INSN (insn
))
2770 /* Do everything that happens "before" the insn. */
2771 add_cfi_insn
= prev
;
2773 /* Notice the end of a trace. */
2774 if (BARRIER_P (insn
))
2776 /* Don't bother saving the unneeded queued registers at all. */
2777 queued_reg_saves
.truncate (0);
2780 if (save_point_p (insn
))
2782 /* Propagate across fallthru edges. */
2783 dwarf2out_flush_queued_reg_saves ();
2784 maybe_record_trace_start (insn
, NULL
);
2788 if (DEBUG_INSN_P (insn
) || !inside_basic_block_p (insn
))
2791 /* Handle all changes to the row state. Sequences require special
2792 handling for the positioning of the notes. */
2793 if (rtx_sequence
*pat
= dyn_cast
<rtx_sequence
*> (PATTERN (insn
)))
2796 int i
, n
= pat
->len ();
2798 control
= pat
->insn (0);
2799 if (can_throw_internal (control
))
2800 notice_eh_throw (control
);
2801 dwarf2out_flush_queued_reg_saves ();
2803 if (JUMP_P (control
) && INSN_ANNULLED_BRANCH_P (control
))
2805 /* ??? Hopefully multiple delay slots are not annulled. */
2806 gcc_assert (n
== 2);
2807 gcc_assert (!RTX_FRAME_RELATED_P (control
));
2808 gcc_assert (!find_reg_note (control
, REG_ARGS_SIZE
, NULL
));
2810 elt
= pat
->insn (1);
2812 if (INSN_FROM_TARGET_P (elt
))
2814 cfi_vec save_row_reg_save
;
2816 /* If ELT is an instruction from target of an annulled
2817 branch, the effects are for the target only and so
2818 the args_size and CFA along the current path
2819 shouldn't change. */
2820 add_cfi_insn
= NULL
;
2821 poly_int64 restore_args_size
= cur_trace
->end_true_args_size
;
2822 cur_cfa
= &cur_row
->cfa
;
2823 save_row_reg_save
= vec_safe_copy (cur_row
->reg_save
);
2825 scan_insn_after (elt
);
2827 /* ??? Should we instead save the entire row state? */
2828 gcc_assert (!queued_reg_saves
.length ());
2830 create_trace_edges (control
);
2832 cur_trace
->end_true_args_size
= restore_args_size
;
2833 cur_row
->cfa
= this_cfa
;
2834 cur_row
->reg_save
= save_row_reg_save
;
2835 cur_cfa
= &this_cfa
;
2839 /* If ELT is a annulled branch-taken instruction (i.e.
2840 executed only when branch is not taken), the args_size
2841 and CFA should not change through the jump. */
2842 create_trace_edges (control
);
2844 /* Update and continue with the trace. */
2845 add_cfi_insn
= insn
;
2846 scan_insn_after (elt
);
2847 def_cfa_1 (&this_cfa
);
2852 /* The insns in the delay slot should all be considered to happen
2853 "before" a call insn. Consider a call with a stack pointer
2854 adjustment in the delay slot. The backtrace from the callee
2855 should include the sp adjustment. Unfortunately, that leaves
2856 us with an unavoidable unwinding error exactly at the call insn
2857 itself. For jump insns we'd prefer to avoid this error by
2858 placing the notes after the sequence. */
2859 if (JUMP_P (control
))
2860 add_cfi_insn
= insn
;
2862 for (i
= 1; i
< n
; ++i
)
2864 elt
= pat
->insn (i
);
2865 scan_insn_after (elt
);
2868 /* Make sure any register saves are visible at the jump target. */
2869 dwarf2out_flush_queued_reg_saves ();
2870 any_cfis_emitted
= false;
2872 /* However, if there is some adjustment on the call itself, e.g.
2873 a call_pop, that action should be considered to happen after
2874 the call returns. */
2875 add_cfi_insn
= insn
;
2876 scan_insn_after (control
);
2880 /* Flush data before calls and jumps, and of course if necessary. */
2881 if (can_throw_internal (insn
))
2883 notice_eh_throw (insn
);
2884 dwarf2out_flush_queued_reg_saves ();
2886 else if (!NONJUMP_INSN_P (insn
)
2887 || clobbers_queued_reg_save (insn
)
2888 || find_reg_note (insn
, REG_CFA_FLUSH_QUEUE
, NULL
))
2889 dwarf2out_flush_queued_reg_saves ();
2890 any_cfis_emitted
= false;
2892 add_cfi_insn
= insn
;
2893 scan_insn_after (insn
);
2897 /* Between frame-related-p and args_size we might have otherwise
2898 emitted two cfa adjustments. Do it now. */
2899 def_cfa_1 (&this_cfa
);
2901 /* Minimize the number of advances by emitting the entire queue
2902 once anything is emitted. */
2903 if (any_cfis_emitted
2904 || find_reg_note (insn
, REG_CFA_FLUSH_QUEUE
, NULL
))
2905 dwarf2out_flush_queued_reg_saves ();
2907 /* Note that a test for control_flow_insn_p does exactly the
2908 same tests as are done to actually create the edges. So
2909 always call the routine and let it not create edges for
2910 non-control-flow insns. */
2911 create_trace_edges (control
);
2914 gcc_assert (!cfun
->fde
|| !cfun
->fde
->rule18
);
2915 add_cfi_insn
= NULL
;
2921 /* Scan the function and create the initial set of CFI notes. */
2924 create_cfi_notes (void)
2928 gcc_checking_assert (!queued_reg_saves
.exists ());
2929 gcc_checking_assert (!trace_work_list
.exists ());
2931 /* Always begin at the entry trace. */
2932 ti
= &trace_info
[0];
2933 scan_trace (ti
, true);
2935 while (!trace_work_list
.is_empty ())
2937 ti
= trace_work_list
.pop ();
2938 scan_trace (ti
, false);
2941 queued_reg_saves
.release ();
2942 trace_work_list
.release ();
2945 /* Return the insn before the first NOTE_INSN_CFI after START. */
2948 before_next_cfi_note (rtx_insn
*start
)
2950 rtx_insn
*prev
= start
;
2953 if (NOTE_P (start
) && NOTE_KIND (start
) == NOTE_INSN_CFI
)
2956 start
= NEXT_INSN (start
);
2961 /* Insert CFI notes between traces to properly change state between them. */
2964 connect_traces (void)
2967 dw_trace_info
*prev_ti
, *ti
;
2969 /* ??? Ideally, we should have both queued and processed every trace.
2970 However the current representation of constant pools on various targets
2971 is indistinguishable from unreachable code. Assume for the moment that
2972 we can simply skip over such traces. */
2973 /* ??? Consider creating a DATA_INSN rtx code to indicate that
2974 these are not "real" instructions, and should not be considered.
2975 This could be generically useful for tablejump data as well. */
2976 /* Remove all unprocessed traces from the list. */
2978 VEC_ORDERED_REMOVE_IF_FROM_TO (trace_info
, ix
, ix2
, ti
, 1,
2979 trace_info
.length (), ti
->beg_row
== NULL
);
2980 FOR_EACH_VEC_ELT (trace_info
, ix
, ti
)
2981 gcc_assert (ti
->end_row
!= NULL
);
2983 /* Work from the end back to the beginning. This lets us easily insert
2984 remember/restore_state notes in the correct order wrt other notes. */
2985 n
= trace_info
.length ();
2986 prev_ti
= &trace_info
[n
- 1];
2987 for (i
= n
- 1; i
> 0; --i
)
2989 dw_cfi_row
*old_row
;
2992 prev_ti
= &trace_info
[i
- 1];
2994 add_cfi_insn
= ti
->head
;
2996 /* In dwarf2out_switch_text_section, we'll begin a new FDE
2997 for the portion of the function in the alternate text
2998 section. The row state at the very beginning of that
2999 new FDE will be exactly the row state from the CIE. */
3000 if (ti
->switch_sections
)
3001 old_row
= cie_cfi_row
;
3004 old_row
= prev_ti
->end_row
;
3005 /* If there's no change from the previous end state, fine. */
3006 if (cfi_row_equal_p (old_row
, ti
->beg_row
))
3008 /* Otherwise check for the common case of sharing state with
3009 the beginning of an epilogue, but not the end. Insert
3010 remember/restore opcodes in that case. */
3011 else if (cfi_row_equal_p (prev_ti
->beg_row
, ti
->beg_row
))
3015 /* Note that if we blindly insert the remember at the
3016 start of the trace, we can wind up increasing the
3017 size of the unwind info due to extra advance opcodes.
3018 Instead, put the remember immediately before the next
3019 state change. We know there must be one, because the
3020 state at the beginning and head of the trace differ. */
3021 add_cfi_insn
= before_next_cfi_note (prev_ti
->head
);
3023 cfi
->dw_cfi_opc
= DW_CFA_remember_state
;
3026 add_cfi_insn
= ti
->head
;
3028 cfi
->dw_cfi_opc
= DW_CFA_restore_state
;
3031 /* If the target unwinder does not save the CFA as part of the
3032 register state, we need to restore it separately. */
3033 if (targetm
.asm_out
.should_restore_cfa_state ()
3034 && (cfi
= def_cfa_0 (&old_row
->cfa
, &ti
->beg_row
->cfa
)))
3037 old_row
= prev_ti
->beg_row
;
3039 /* Otherwise, we'll simply change state from the previous end. */
3042 change_cfi_row (old_row
, ti
->beg_row
);
3044 if (dump_file
&& add_cfi_insn
!= ti
->head
)
3048 fprintf (dump_file
, "Fixup between trace %u and %u:\n",
3049 prev_ti
->id
, ti
->id
);
3054 note
= NEXT_INSN (note
);
3055 gcc_assert (NOTE_P (note
) && NOTE_KIND (note
) == NOTE_INSN_CFI
);
3056 output_cfi_directive (dump_file
, NOTE_CFI (note
));
3058 while (note
!= add_cfi_insn
);
3062 /* Connect args_size between traces that have can_throw_internal insns. */
3063 if (cfun
->eh
->lp_array
)
3065 poly_int64 prev_args_size
= 0;
3067 for (i
= 0; i
< n
; ++i
)
3069 ti
= &trace_info
[i
];
3071 if (ti
->switch_sections
)
3074 if (ti
->eh_head
== NULL
)
3077 /* We require either the incoming args_size values to match or the
3078 presence of an insn setting it before the first EH insn. */
3079 gcc_assert (!ti
->args_size_undefined
|| ti
->args_size_defined_for_eh
);
3081 /* In the latter case, we force the creation of a CFI note. */
3082 if (ti
->args_size_undefined
3083 || maybe_ne (ti
->beg_delay_args_size
, prev_args_size
))
3085 /* ??? Search back to previous CFI note. */
3086 add_cfi_insn
= PREV_INSN (ti
->eh_head
);
3087 add_cfi_args_size (ti
->beg_delay_args_size
);
3090 prev_args_size
= ti
->end_delay_args_size
;
3095 /* Set up the pseudo-cfg of instruction traces, as described at the
3096 block comment at the top of the file. */
3099 create_pseudo_cfg (void)
3101 bool saw_barrier
, switch_sections
;
3106 /* The first trace begins at the start of the function,
3107 and begins with the CIE row state. */
3108 trace_info
.create (16);
3109 memset (&ti
, 0, sizeof (ti
));
3110 ti
.head
= get_insns ();
3111 ti
.beg_row
= cie_cfi_row
;
3112 ti
.cfa_store
= cie_cfi_row
->cfa
;
3113 ti
.cfa_temp
.reg
.set_by_dwreg (INVALID_REGNUM
);
3114 trace_info
.quick_push (ti
);
3116 if (cie_return_save
)
3117 ti
.regs_saved_in_regs
.safe_push (*cie_return_save
);
3119 /* Walk all the insns, collecting start of trace locations. */
3120 saw_barrier
= false;
3121 switch_sections
= false;
3122 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3124 if (BARRIER_P (insn
))
3126 else if (NOTE_P (insn
)
3127 && NOTE_KIND (insn
) == NOTE_INSN_SWITCH_TEXT_SECTIONS
)
3129 /* We should have just seen a barrier. */
3130 gcc_assert (saw_barrier
);
3131 switch_sections
= true;
3133 /* Watch out for save_point notes between basic blocks.
3134 In particular, a note after a barrier. Do not record these,
3135 delaying trace creation until the label. */
3136 else if (save_point_p (insn
)
3137 && (LABEL_P (insn
) || !saw_barrier
))
3139 memset (&ti
, 0, sizeof (ti
));
3141 ti
.switch_sections
= switch_sections
;
3142 ti
.id
= trace_info
.length ();
3143 trace_info
.safe_push (ti
);
3145 saw_barrier
= false;
3146 switch_sections
= false;
3150 /* Create the trace index after we've finished building trace_info,
3151 avoiding stale pointer problems due to reallocation. */
3153 = new hash_table
<trace_info_hasher
> (trace_info
.length ());
3155 FOR_EACH_VEC_ELT (trace_info
, i
, tp
)
3157 dw_trace_info
**slot
;
3160 fprintf (dump_file
, "Creating trace %u : start at %s %d%s\n", tp
->id
,
3161 rtx_name
[(int) GET_CODE (tp
->head
)], INSN_UID (tp
->head
),
3162 tp
->switch_sections
? " (section switch)" : "");
3164 slot
= trace_index
->find_slot_with_hash (tp
, INSN_UID (tp
->head
), INSERT
);
3165 gcc_assert (*slot
== NULL
);
3170 /* Record the initial position of the return address. RTL is
3171 INCOMING_RETURN_ADDR_RTX. */
3174 initial_return_save (rtx rtl
)
3177 reg
.set_by_dwreg (INVALID_REGNUM
);
3178 poly_int64 offset
= 0;
3180 switch (GET_CODE (rtl
))
3183 /* RA is in a register. */
3184 reg
= dwf_cfa_reg (rtl
);
3188 /* RA is on the stack. */
3189 rtl
= XEXP (rtl
, 0);
3190 switch (GET_CODE (rtl
))
3193 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
3198 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
3199 offset
= rtx_to_poly_int64 (XEXP (rtl
, 1));
3203 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
3204 offset
= -rtx_to_poly_int64 (XEXP (rtl
, 1));
3214 /* The return address is at some offset from any value we can
3215 actually load. For instance, on the SPARC it is in %i7+8. Just
3216 ignore the offset for now; it doesn't matter for unwinding frames. */
3217 gcc_assert (CONST_INT_P (XEXP (rtl
, 1)));
3218 initial_return_save (XEXP (rtl
, 0));
3225 if (reg
.reg
!= DWARF_FRAME_RETURN_COLUMN
)
3227 if (reg
.reg
!= INVALID_REGNUM
)
3228 record_reg_saved_in_reg (rtl
, pc_rtx
);
3229 reg_save (DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cur_row
->cfa
.offset
);
3234 create_cie_data (void)
3236 dw_cfa_location loc
;
3237 dw_trace_info cie_trace
;
3239 dw_stack_pointer_regnum
= dwf_cfa_reg (stack_pointer_rtx
);
3241 memset (&cie_trace
, 0, sizeof (cie_trace
));
3242 cur_trace
= &cie_trace
;
3244 add_cfi_vec
= &cie_cfi_vec
;
3245 cie_cfi_row
= cur_row
= new_cfi_row ();
3247 /* On entry, the Canonical Frame Address is at SP. */
3248 memset (&loc
, 0, sizeof (loc
));
3249 loc
.reg
= dw_stack_pointer_regnum
;
3250 /* create_cie_data is called just once per TU, and when using .cfi_startproc
3251 is even done by the assembler rather than the compiler. If the target
3252 has different incoming frame sp offsets depending on what kind of
3253 function it is, use a single constant offset for the target and
3254 if needed, adjust before the first instruction in insn stream. */
3255 loc
.offset
= DEFAULT_INCOMING_FRAME_SP_OFFSET
;
3258 if (targetm
.debug_unwind_info () == UI_DWARF2
3259 || targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
3261 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
3263 /* For a few targets, we have the return address incoming into a
3264 register, but choose a different return column. This will result
3265 in a DW_CFA_register for the return, and an entry in
3266 regs_saved_in_regs to match. If the target later stores that
3267 return address register to the stack, we want to be able to emit
3268 the DW_CFA_offset against the return column, not the intermediate
3269 save register. Save the contents of regs_saved_in_regs so that
3270 we can re-initialize it at the start of each function. */
3271 switch (cie_trace
.regs_saved_in_regs
.length ())
3276 cie_return_save
= ggc_alloc
<reg_saved_in_data
> ();
3277 *cie_return_save
= cie_trace
.regs_saved_in_regs
[0];
3278 cie_trace
.regs_saved_in_regs
.release ();
3290 /* Annotate the function with NOTE_INSN_CFI notes to record the CFI
3291 state at each location within the function. These notes will be
3292 emitted during pass_final. */
3295 execute_dwarf2_frame (void)
3297 /* Different HARD_FRAME_POINTER_REGNUM might coexist in the same file. */
3298 dw_frame_pointer_regnum
= dwf_cfa_reg (hard_frame_pointer_rtx
);
3300 /* The first time we're called, compute the incoming frame state. */
3301 if (cie_cfi_vec
== NULL
)
3304 dwarf2out_alloc_current_fde ();
3306 create_pseudo_cfg ();
3309 create_cfi_notes ();
3313 /* Free all the data we allocated. */
3318 FOR_EACH_VEC_ELT (trace_info
, i
, ti
)
3319 ti
->regs_saved_in_regs
.release ();
3321 trace_info
.release ();
3327 /* Convert a DWARF call frame info. operation to its string name */
3330 dwarf_cfi_name (unsigned int cfi_opc
)
3332 const char *name
= get_DW_CFA_name (cfi_opc
);
3337 return "DW_CFA_<unknown>";
3340 /* This routine will generate the correct assembly data for a location
3341 description based on a cfi entry with a complex address. */
3344 output_cfa_loc (dw_cfi_ref cfi
, int for_eh
)
3346 dw_loc_descr_ref loc
;
3349 if (cfi
->dw_cfi_opc
== DW_CFA_expression
3350 || cfi
->dw_cfi_opc
== DW_CFA_val_expression
)
3353 DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3354 dw2_asm_output_data (1, r
, NULL
);
3355 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
3358 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3360 /* Output the size of the block. */
3361 size
= size_of_locs (loc
);
3362 dw2_asm_output_data_uleb128 (size
, NULL
);
3364 /* Now output the operations themselves. */
3365 output_loc_sequence (loc
, for_eh
);
3368 /* Similar, but used for .cfi_escape. */
3371 output_cfa_loc_raw (dw_cfi_ref cfi
)
3373 dw_loc_descr_ref loc
;
3376 if (cfi
->dw_cfi_opc
== DW_CFA_expression
3377 || cfi
->dw_cfi_opc
== DW_CFA_val_expression
)
3380 DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3381 fprintf (asm_out_file
, "%#x,", r
);
3382 loc
= cfi
->dw_cfi_oprnd2
.dw_cfi_loc
;
3385 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3387 /* Output the size of the block. */
3388 size
= size_of_locs (loc
);
3389 dw2_asm_output_data_uleb128_raw (size
);
3390 fputc (',', asm_out_file
);
3392 /* Now output the operations themselves. */
3393 output_loc_sequence_raw (loc
);
3396 /* Output a Call Frame Information opcode and its operand(s). */
3399 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
3404 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
3405 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
3406 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
3407 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
3408 ((unsigned HOST_WIDE_INT
)
3409 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
3410 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
3412 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3413 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3414 "DW_CFA_offset, column %#lx", r
);
3415 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3416 dw2_asm_output_data_uleb128 (off
, NULL
);
3418 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
3420 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3421 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
3422 "DW_CFA_restore, column %#lx", r
);
3426 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
3427 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
3429 switch (cfi
->dw_cfi_opc
)
3431 case DW_CFA_set_loc
:
3433 dw2_asm_output_encoded_addr_rtx (
3434 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3435 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
3438 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
3439 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
3440 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3443 case DW_CFA_advance_loc1
:
3444 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3445 fde
->dw_fde_current_label
, NULL
);
3446 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3449 case DW_CFA_advance_loc2
:
3450 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3451 fde
->dw_fde_current_label
, NULL
);
3452 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3455 case DW_CFA_advance_loc4
:
3456 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3457 fde
->dw_fde_current_label
, NULL
);
3458 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3461 case DW_CFA_MIPS_advance_loc8
:
3462 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
3463 fde
->dw_fde_current_label
, NULL
);
3464 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
3467 case DW_CFA_offset_extended
:
3468 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3469 dw2_asm_output_data_uleb128 (r
, NULL
);
3470 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3471 dw2_asm_output_data_uleb128 (off
, NULL
);
3474 case DW_CFA_def_cfa
:
3475 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3476 dw2_asm_output_data_uleb128 (r
, NULL
);
3477 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
3480 case DW_CFA_offset_extended_sf
:
3481 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3482 dw2_asm_output_data_uleb128 (r
, NULL
);
3483 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3484 dw2_asm_output_data_sleb128 (off
, NULL
);
3487 case DW_CFA_def_cfa_sf
:
3488 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3489 dw2_asm_output_data_uleb128 (r
, NULL
);
3490 off
= div_data_align (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3491 dw2_asm_output_data_sleb128 (off
, NULL
);
3494 case DW_CFA_restore_extended
:
3495 case DW_CFA_undefined
:
3496 case DW_CFA_same_value
:
3497 case DW_CFA_def_cfa_register
:
3498 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3499 dw2_asm_output_data_uleb128 (r
, NULL
);
3502 case DW_CFA_register
:
3503 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
3504 dw2_asm_output_data_uleb128 (r
, NULL
);
3505 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
3506 dw2_asm_output_data_uleb128 (r
, NULL
);
3509 case DW_CFA_def_cfa_offset
:
3510 case DW_CFA_GNU_args_size
:
3511 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
3514 case DW_CFA_def_cfa_offset_sf
:
3515 off
= div_data_align (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3516 dw2_asm_output_data_sleb128 (off
, NULL
);
3519 case DW_CFA_GNU_window_save
:
3522 case DW_CFA_def_cfa_expression
:
3523 case DW_CFA_expression
:
3524 case DW_CFA_val_expression
:
3525 output_cfa_loc (cfi
, for_eh
);
3528 case DW_CFA_GNU_negative_offset_extended
:
3529 /* Obsoleted by DW_CFA_offset_extended_sf. */
3538 /* Similar, but do it via assembler directives instead. */
3541 output_cfi_directive (FILE *f
, dw_cfi_ref cfi
)
3543 unsigned long r
, r2
;
3545 switch (cfi
->dw_cfi_opc
)
3547 case DW_CFA_advance_loc
:
3548 case DW_CFA_advance_loc1
:
3549 case DW_CFA_advance_loc2
:
3550 case DW_CFA_advance_loc4
:
3551 case DW_CFA_MIPS_advance_loc8
:
3552 case DW_CFA_set_loc
:
3553 /* Should only be created in a code path not followed when emitting
3554 via directives. The assembler is going to take care of this for
3555 us. But this routines is also used for debugging dumps, so
3557 gcc_assert (f
!= asm_out_file
);
3558 fprintf (f
, "\t.cfi_advance_loc\n");
3562 case DW_CFA_offset_extended
:
3563 case DW_CFA_offset_extended_sf
:
3564 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3565 fprintf (f
, "\t.cfi_offset %lu, " HOST_WIDE_INT_PRINT_DEC
"\n",
3566 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3569 case DW_CFA_restore
:
3570 case DW_CFA_restore_extended
:
3571 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3572 fprintf (f
, "\t.cfi_restore %lu\n", r
);
3575 case DW_CFA_undefined
:
3576 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3577 fprintf (f
, "\t.cfi_undefined %lu\n", r
);
3580 case DW_CFA_same_value
:
3581 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3582 fprintf (f
, "\t.cfi_same_value %lu\n", r
);
3585 case DW_CFA_def_cfa
:
3586 case DW_CFA_def_cfa_sf
:
3587 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3588 fprintf (f
, "\t.cfi_def_cfa %lu, " HOST_WIDE_INT_PRINT_DEC
"\n",
3589 r
, cfi
->dw_cfi_oprnd2
.dw_cfi_offset
);
3592 case DW_CFA_def_cfa_register
:
3593 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3594 fprintf (f
, "\t.cfi_def_cfa_register %lu\n", r
);
3597 case DW_CFA_register
:
3598 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, 1);
3599 r2
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, 1);
3600 fprintf (f
, "\t.cfi_register %lu, %lu\n", r
, r2
);
3603 case DW_CFA_def_cfa_offset
:
3604 case DW_CFA_def_cfa_offset_sf
:
3605 fprintf (f
, "\t.cfi_def_cfa_offset "
3606 HOST_WIDE_INT_PRINT_DEC
"\n",
3607 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3610 case DW_CFA_remember_state
:
3611 fprintf (f
, "\t.cfi_remember_state\n");
3613 case DW_CFA_restore_state
:
3614 fprintf (f
, "\t.cfi_restore_state\n");
3617 case DW_CFA_GNU_args_size
:
3618 if (f
== asm_out_file
)
3620 fprintf (f
, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size
);
3621 dw2_asm_output_data_uleb128_raw (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3623 fprintf (f
, "\t%s args_size " HOST_WIDE_INT_PRINT_DEC
,
3624 ASM_COMMENT_START
, cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3629 fprintf (f
, "\t.cfi_GNU_args_size " HOST_WIDE_INT_PRINT_DEC
"\n",
3630 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
3634 case DW_CFA_GNU_window_save
:
3635 fprintf (f
, "\t.cfi_window_save\n");
3638 case DW_CFA_def_cfa_expression
:
3639 case DW_CFA_expression
:
3640 case DW_CFA_val_expression
:
3641 if (f
!= asm_out_file
)
3643 fprintf (f
, "\t.cfi_%scfa_%sexpression ...\n",
3644 cfi
->dw_cfi_opc
== DW_CFA_def_cfa_expression
? "def_" : "",
3645 cfi
->dw_cfi_opc
== DW_CFA_val_expression
? "val_" : "");
3648 fprintf (f
, "\t.cfi_escape %#x,", cfi
->dw_cfi_opc
);
3649 output_cfa_loc_raw (cfi
);
3659 dwarf2out_emit_cfi (dw_cfi_ref cfi
)
3661 if (dwarf2out_do_cfi_asm ())
3662 output_cfi_directive (asm_out_file
, cfi
);
3666 dump_cfi_row (FILE *f
, dw_cfi_row
*row
)
3674 dw_cfa_location dummy
;
3675 memset (&dummy
, 0, sizeof (dummy
));
3676 dummy
.reg
.set_by_dwreg (INVALID_REGNUM
);
3677 cfi
= def_cfa_0 (&dummy
, &row
->cfa
);
3679 output_cfi_directive (f
, cfi
);
3681 FOR_EACH_VEC_SAFE_ELT (row
->reg_save
, i
, cfi
)
3683 output_cfi_directive (f
, cfi
);
3686 void debug_cfi_row (dw_cfi_row
*row
);
3689 debug_cfi_row (dw_cfi_row
*row
)
3691 dump_cfi_row (stderr
, row
);
3695 /* Save the result of dwarf2out_do_frame across PCH.
3696 This variable is tri-state, with 0 unset, >0 true, <0 false. */
3697 static GTY(()) signed char saved_do_cfi_asm
= 0;
3699 /* Decide whether to emit EH frame unwind information for the current
3700 translation unit. */
3703 dwarf2out_do_eh_frame (void)
3706 (flag_unwind_tables
|| flag_exceptions
)
3707 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
;
3710 /* Decide whether we want to emit frame unwind information for the current
3711 translation unit. */
3714 dwarf2out_do_frame (void)
3716 /* We want to emit correct CFA location expressions or lists, so we
3717 have to return true if we're going to generate debug info, even if
3718 we're not going to output frame or unwind info. */
3719 if (dwarf_debuginfo_p () || dwarf_based_debuginfo_p ())
3722 if (saved_do_cfi_asm
> 0)
3725 if (targetm
.debug_unwind_info () == UI_DWARF2
)
3728 if (dwarf2out_do_eh_frame ())
3734 /* Decide whether to emit frame unwind via assembler directives. */
3737 dwarf2out_do_cfi_asm (void)
3741 if (saved_do_cfi_asm
!= 0)
3742 return saved_do_cfi_asm
> 0;
3744 /* Assume failure for a moment. */
3745 saved_do_cfi_asm
= -1;
3747 if (!flag_dwarf2_cfi_asm
|| !dwarf2out_do_frame ())
3749 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
)
3752 /* Make sure the personality encoding is one the assembler can support.
3753 In particular, aligned addresses can't be handled. */
3754 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
3755 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
3757 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
3758 if ((enc
& 0x70) != 0 && (enc
& 0x70) != DW_EH_PE_pcrel
)
3761 /* If we can't get the assembler to emit only .debug_frame, and we don't need
3762 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
3763 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
&& !dwarf2out_do_eh_frame ())
3767 saved_do_cfi_asm
= 1;
3773 const pass_data pass_data_dwarf2_frame
=
3775 RTL_PASS
, /* type */
3776 "dwarf2", /* name */
3777 OPTGROUP_NONE
, /* optinfo_flags */
3778 TV_FINAL
, /* tv_id */
3779 0, /* properties_required */
3780 0, /* properties_provided */
3781 0, /* properties_destroyed */
3782 0, /* todo_flags_start */
3783 0, /* todo_flags_finish */
3786 class pass_dwarf2_frame
: public rtl_opt_pass
3789 pass_dwarf2_frame (gcc::context
*ctxt
)
3790 : rtl_opt_pass (pass_data_dwarf2_frame
, ctxt
)
3793 /* opt_pass methods: */
3794 bool gate (function
*) final override
;
3795 unsigned int execute (function
*) final override
3797 execute_dwarf2_frame ();
3801 }; // class pass_dwarf2_frame
3804 pass_dwarf2_frame::gate (function
*)
3806 /* Targets which still implement the prologue in assembler text
3807 cannot use the generic dwarf2 unwinding. */
3808 if (!targetm
.have_prologue ())
3811 /* ??? What to do for UI_TARGET unwinding? They might be able to benefit
3812 from the optimized shrink-wrapping annotations that we will compute.
3813 For now, only produce the CFI notes for dwarf2. */
3814 return dwarf2out_do_frame ();
3820 make_pass_dwarf2_frame (gcc::context
*ctxt
)
3822 return new pass_dwarf2_frame (ctxt
);
3825 void dwarf2cfi_cc_finalize ()
3827 add_cfi_insn
= NULL
;
3834 #include "gt-dwarf2cfi.h"