/* Dwarf2 Call Frame Information helper routines.
- Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
- 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 1992-2015 Free Software Foundation, Inc.
This file is part of GCC.
#include "version.h"
#include "flags.h"
#include "rtl.h"
+#include "alias.h"
+#include "symtab.h"
+#include "tree.h"
+#include "stor-layout.h"
+#include "hard-reg-set.h"
#include "function.h"
+#include "cfgbuild.h"
#include "dwarf2.h"
#include "dwarf2out.h"
#include "dwarf2asm.h"
-#include "ggc.h"
#include "tm_p.h"
#include "target.h"
#include "common/common-target.h"
#include "tree-pass.h"
#include "except.h" /* expand_builtin_dwarf_sp_column */
+#include "insn-config.h"
+#include "expmed.h"
+#include "dojump.h"
+#include "explow.h"
+#include "calls.h"
+#include "emit-rtl.h"
+#include "varasm.h"
+#include "stmt.h"
#include "expr.h" /* init_return_column_size */
#include "regs.h" /* expand_builtin_init_dwarf_reg_sizes */
#include "output.h" /* asm_out_file */
#define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
#endif
-/* The size of the target's pointer type. */
-#ifndef PTR_SIZE
-#define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
-#endif
-
/* Maximum size (in bytes) of an artificially generated label. */
#define MAX_ARTIFICIAL_LABEL_BYTES 30
+\f
+/* A collected description of an entire row of the abstract CFI table. */
+typedef struct GTY(()) dw_cfi_row_struct
+{
+ /* The expression that computes the CFA, expressed in two different ways.
+ The CFA member for the simple cases, and the full CFI expression for
+ the complex cases. The later will be a DW_CFA_cfa_expression. */
+ dw_cfa_location cfa;
+ dw_cfi_ref cfa_cfi;
-/* The size of addresses as they appear in the Dwarf 2 data.
- Some architectures use word addresses to refer to code locations,
- but Dwarf 2 info always uses byte addresses. On such machines,
- Dwarf 2 addresses need to be larger than the architecture's
- pointers. */
-#ifndef DWARF2_ADDR_SIZE
-#define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
-#endif
+ /* The expressions for any register column that is saved. */
+ cfi_vec reg_save;
+} dw_cfi_row;
-/* The size in bytes of a DWARF field indicating an offset or length
- relative to a debug info section, specified to be 4 bytes in the
- DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
- as PTR_SIZE. */
+/* The caller's ORIG_REG is saved in SAVED_IN_REG. */
+typedef struct GTY(()) reg_saved_in_data_struct {
+ rtx orig_reg;
+ rtx saved_in_reg;
+} reg_saved_in_data;
-#ifndef DWARF_OFFSET_SIZE
-#define DWARF_OFFSET_SIZE 4
-#endif
-/* According to the (draft) DWARF 3 specification, the initial length
- should either be 4 or 12 bytes. When it's 12 bytes, the first 4
- bytes are 0xffffffff, followed by the length stored in the next 8
- bytes.
+/* Since we no longer have a proper CFG, we're going to create a facsimile
+ of one on the fly while processing the frame-related insns.
- However, the SGI/MIPS ABI uses an initial length which is equal to
- DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
+ We create dw_trace_info structures for each extended basic block beginning
+ and ending at a "save point". Save points are labels, barriers, certain
+ notes, and of course the beginning and end of the function.
-#ifndef DWARF_INITIAL_LENGTH_SIZE
-#define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
-#endif
+ As we encounter control transfer insns, we propagate the "current"
+ row state across the edges to the starts of traces. When checking is
+ enabled, we validate that we propagate the same data from all sources.
-/* Round SIZE up to the nearest BOUNDARY. */
-#define DWARF_ROUND(SIZE,BOUNDARY) \
- ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
+ All traces are members of the TRACE_INFO array, in the order in which
+ they appear in the instruction stream.
-/* Offsets recorded in opcodes are a multiple of this alignment factor. */
-#ifndef DWARF_CIE_DATA_ALIGNMENT
-#ifdef STACK_GROWS_DOWNWARD
-#define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
-#else
-#define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
-#endif
-#endif
+ All save points are present in the TRACE_INDEX hash, mapping the insn
+ starting a trace to the dw_trace_info describing the trace. */
-/* CIE identifier. */
-#if HOST_BITS_PER_WIDE_INT >= 64
-#define DWARF_CIE_ID \
- (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
-#else
-#define DWARF_CIE_ID DW_CIE_ID
-#endif
+typedef struct
+{
+ /* The insn that begins the trace. */
+ rtx_insn *head;
-/* The DWARF 2 CFA column which tracks the return address. Normally this
- is the column for PC, or the first column after all of the hard
- registers. */
-#ifndef DWARF_FRAME_RETURN_COLUMN
-#ifdef PC_REGNUM
-#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
-#else
-#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
-#endif
-#endif
+ /* The row state at the beginning and end of the trace. */
+ dw_cfi_row *beg_row, *end_row;
-/* The mapping from gcc register number to DWARF 2 CFA column number. By
- default, we just provide columns for all registers. */
-#ifndef DWARF_FRAME_REGNUM
-#define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
-#endif
+ /* Tracking for DW_CFA_GNU_args_size. The "true" sizes are those we find
+ while scanning insns. However, the args_size value is irrelevant at
+ any point except can_throw_internal_p insns. Therefore the "delay"
+ sizes the values that must actually be emitted for this trace. */
+ HOST_WIDE_INT beg_true_args_size, end_true_args_size;
+ HOST_WIDE_INT beg_delay_args_size, end_delay_args_size;
+
+ /* The first EH insn in the trace, where beg_delay_args_size must be set. */
+ rtx_insn *eh_head;
+
+ /* The following variables contain data used in interpreting frame related
+ expressions. These are not part of the "real" row state as defined by
+ Dwarf, but it seems like they need to be propagated into a trace in case
+ frame related expressions have been sunk. */
+ /* ??? This seems fragile. These variables are fragments of a larger
+ expression. If we do not keep the entire expression together, we risk
+ not being able to put it together properly. Consider forcing targets
+ to generate self-contained expressions and dropping all of the magic
+ interpretation code in this file. Or at least refusing to shrink wrap
+ any frame related insn that doesn't contain a complete expression. */
+
+ /* The register used for saving registers to the stack, and its offset
+ from the CFA. */
+ dw_cfa_location cfa_store;
+
+ /* A temporary register holding an integral value used in adjusting SP
+ or setting up the store_reg. The "offset" field holds the integer
+ value, not an offset. */
+ dw_cfa_location cfa_temp;
+
+ /* A set of registers saved in other registers. This is the inverse of
+ the row->reg_save info, if the entry is a DW_CFA_register. This is
+ implemented as a flat array because it normally contains zero or 1
+ entry, depending on the target. IA-64 is the big spender here, using
+ a maximum of 5 entries. */
+ vec<reg_saved_in_data> regs_saved_in_regs;
+
+ /* An identifier for this trace. Used only for debugging dumps. */
+ unsigned id;
+
+ /* True if this trace immediately follows NOTE_INSN_SWITCH_TEXT_SECTIONS. */
+ bool switch_sections;
+
+ /* True if we've seen different values incoming to beg_true_args_size. */
+ bool args_size_undefined;
+} dw_trace_info;
+
+
+typedef dw_trace_info *dw_trace_info_ref;
+
+
+/* Hashtable helpers. */
+
+struct trace_info_hasher : nofree_ptr_hash <dw_trace_info>
+{
+ static inline hashval_t hash (const dw_trace_info *);
+ static inline bool equal (const dw_trace_info *, const dw_trace_info *);
+};
+
+inline hashval_t
+trace_info_hasher::hash (const dw_trace_info *ti)
+{
+ return INSN_UID (ti->head);
+}
+
+inline bool
+trace_info_hasher::equal (const dw_trace_info *a, const dw_trace_info *b)
+{
+ return a->head == b->head;
+}
+
+
+/* The variables making up the pseudo-cfg, as described above. */
+static vec<dw_trace_info> trace_info;
+static vec<dw_trace_info_ref> trace_work_list;
+static hash_table<trace_info_hasher> *trace_index;
-/* Map register numbers held in the call frame info that gcc has
- collected using DWARF_FRAME_REGNUM to those that should be output in
- .debug_frame and .eh_frame. */
-#ifndef DWARF2_FRAME_REG_OUT
-#define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
-#endif
-\f
/* A vector of call frame insns for the CIE. */
cfi_vec cie_cfi_vec;
+/* The state of the first row of the FDE table, which includes the
+ state provided by the CIE. */
+static GTY(()) dw_cfi_row *cie_cfi_row;
+
+static GTY(()) reg_saved_in_data *cie_return_save;
+
static GTY(()) unsigned long dwarf2out_cfi_label_num;
+/* The insn after which a new CFI note should be emitted. */
+static rtx_insn *add_cfi_insn;
+
+/* When non-null, add_cfi will add the CFI to this vector. */
+static cfi_vec *add_cfi_vec;
+
+/* The current instruction trace. */
+static dw_trace_info *cur_trace;
+
+/* The current, i.e. most recently generated, row of the CFI table. */
+static dw_cfi_row *cur_row;
+
+/* A copy of the current CFA, for use during the processing of a
+ single insn. */
+static dw_cfa_location *cur_cfa;
+
+/* We delay emitting a register save until either (a) we reach the end
+ of the prologue or (b) the register is clobbered. This clusters
+ register saves so that there are fewer pc advances. */
+
+typedef struct {
+ rtx reg;
+ rtx saved_reg;
+ HOST_WIDE_INT cfa_offset;
+} queued_reg_save;
+
+
+static vec<queued_reg_save> queued_reg_saves;
+
+/* True if any CFI directives were emitted at the current insn. */
+static bool any_cfis_emitted;
+
+/* Short-hand for commonly used register numbers. */
+static unsigned dw_stack_pointer_regnum;
+static unsigned dw_frame_pointer_regnum;
\f
/* Hook used by __throw. */
which has mode MODE. Initialize column C as a return address column. */
static void
-init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
+init_return_column_size (machine_mode mode, rtx mem, unsigned int c)
{
HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
- emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
+ emit_move_insn (adjust_address (mem, mode, offset),
+ gen_int_mode (size, mode));
+}
+
+/* Datastructure used by expand_builtin_init_dwarf_reg_sizes and
+ init_one_dwarf_reg_size to communicate on what has been done by the
+ latter. */
+
+typedef struct
+{
+ /* Whether the dwarf return column was initialized. */
+ bool wrote_return_column;
+
+ /* For each hard register REGNO, whether init_one_dwarf_reg_size
+ was given REGNO to process already. */
+ bool processed_regno [FIRST_PSEUDO_REGISTER];
+
+} init_one_dwarf_reg_state;
+
+/* Helper for expand_builtin_init_dwarf_reg_sizes. Generate code to
+ initialize the dwarf register size table entry corresponding to register
+ REGNO in REGMODE. TABLE is the table base address, SLOTMODE is the mode to
+ use for the size entry to initialize, and INIT_STATE is the communication
+ datastructure conveying what we're doing to our caller. */
+
+static
+void init_one_dwarf_reg_size (int regno, machine_mode regmode,
+ rtx table, machine_mode slotmode,
+ init_one_dwarf_reg_state *init_state)
+{
+ const unsigned int dnum = DWARF_FRAME_REGNUM (regno);
+ const unsigned int rnum = DWARF2_FRAME_REG_OUT (dnum, 1);
+ const unsigned int dcol = DWARF_REG_TO_UNWIND_COLUMN (rnum);
+
+ const HOST_WIDE_INT slotoffset = dcol * GET_MODE_SIZE (slotmode);
+ const HOST_WIDE_INT regsize = GET_MODE_SIZE (regmode);
+
+ init_state->processed_regno[regno] = true;
+
+ if (rnum >= DWARF_FRAME_REGISTERS)
+ return;
+
+ if (dnum == DWARF_FRAME_RETURN_COLUMN)
+ {
+ if (regmode == VOIDmode)
+ return;
+ init_state->wrote_return_column = true;
+ }
+
+ if (slotoffset < 0)
+ return;
+
+ emit_move_insn (adjust_address (table, slotmode, slotoffset),
+ gen_int_mode (regsize, slotmode));
}
-/* Generate code to initialize the register size table. */
+/* Generate code to initialize the dwarf register size table located
+ at the provided ADDRESS. */
void
expand_builtin_init_dwarf_reg_sizes (tree address)
{
unsigned int i;
- enum machine_mode mode = TYPE_MODE (char_type_node);
+ machine_mode mode = TYPE_MODE (char_type_node);
rtx addr = expand_normal (address);
rtx mem = gen_rtx_MEM (BLKmode, addr);
- bool wrote_return_column = false;
+
+ init_one_dwarf_reg_state init_state;
+
+ memset ((char *)&init_state, 0, sizeof (init_state));
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
{
- int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
+ machine_mode save_mode;
+ rtx span;
- if (rnum < DWARF_FRAME_REGISTERS)
- {
- HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
- enum machine_mode save_mode = reg_raw_mode[i];
- HOST_WIDE_INT size;
+ /* No point in processing a register multiple times. This could happen
+ with register spans, e.g. when a reg is first processed as a piece of
+ a span, then as a register on its own later on. */
+
+ if (init_state.processed_regno[i])
+ continue;
+
+ save_mode = targetm.dwarf_frame_reg_mode (i);
+ span = targetm.dwarf_register_span (gen_rtx_REG (save_mode, i));
- if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
- save_mode = choose_hard_reg_mode (i, 1, true);
- if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
+ if (!span)
+ init_one_dwarf_reg_size (i, save_mode, mem, mode, &init_state);
+ else
+ {
+ for (int si = 0; si < XVECLEN (span, 0); si++)
{
- if (save_mode == VOIDmode)
- continue;
- wrote_return_column = true;
- }
- size = GET_MODE_SIZE (save_mode);
- if (offset < 0)
- continue;
+ rtx reg = XVECEXP (span, 0, si);
- emit_move_insn (adjust_address (mem, mode, offset),
- gen_int_mode (size, mode));
+ init_one_dwarf_reg_size
+ (REGNO (reg), GET_MODE (reg), mem, mode, &init_state);
+ }
}
}
- if (!wrote_return_column)
+ if (!init_state.wrote_return_column)
init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
#ifdef DWARF_ALT_FRAME_RETURN_COLUMN
targetm.init_dwarf_reg_sizes_extra (address);
}
+\f
+static dw_trace_info *
+get_trace_info (rtx_insn *insn)
+{
+ dw_trace_info dummy;
+ dummy.head = insn;
+ return trace_index->find_with_hash (&dummy, INSN_UID (insn));
+}
+
+static bool
+save_point_p (rtx_insn *insn)
+{
+ /* Labels, except those that are really jump tables. */
+ if (LABEL_P (insn))
+ return inside_basic_block_p (insn);
+
+ /* We split traces at the prologue/epilogue notes because those
+ are points at which the unwind info is usually stable. This
+ makes it easier to find spots with identical unwind info so
+ that we can use remember/restore_state opcodes. */
+ if (NOTE_P (insn))
+ switch (NOTE_KIND (insn))
+ {
+ case NOTE_INSN_PROLOGUE_END:
+ case NOTE_INSN_EPILOGUE_BEG:
+ return true;
+ }
+
+ return false;
+}
+
/* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
static inline HOST_WIDE_INT
static inline dw_cfi_ref
new_cfi (void)
{
- dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
+ dw_cfi_ref cfi = ggc_alloc<dw_cfi_node> ();
cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
return cfi;
}
-/* Add a Call Frame Instruction to list of instructions. */
+/* Return a newly allocated CFI row, with no defined data. */
-static inline void
-add_cfi (cfi_vec *vec, dw_cfi_ref cfi)
+static dw_cfi_row *
+new_cfi_row (void)
{
- dw_fde_ref fde = current_fde ();
-
- /* When DRAP is used, CFA is defined with an expression. Redefine
- CFA may lead to a different CFA value. */
- /* ??? Of course, this heuristic fails when we're annotating epilogues,
- because of course we'll always want to redefine the CFA back to the
- stack pointer on the way out. Where should we move this check? */
- if (0 && fde && fde->drap_reg != INVALID_REGNUM)
- switch (cfi->dw_cfi_opc)
- {
- case DW_CFA_def_cfa_register:
- case DW_CFA_def_cfa_offset:
- case DW_CFA_def_cfa_offset_sf:
- case DW_CFA_def_cfa:
- case DW_CFA_def_cfa_sf:
- gcc_unreachable ();
+ dw_cfi_row *row = ggc_cleared_alloc<dw_cfi_row> ();
- default:
- break;
- }
+ row->cfa.reg = INVALID_REGNUM;
- VEC_safe_push (dw_cfi_ref, gc, *vec, cfi);
+ return row;
}
-/* Generate a new label for the CFI info to refer to. FORCE is true
- if a label needs to be output even when using .cfi_* directives. */
+/* Return a copy of an existing CFI row. */
-static char *
-dwarf2out_cfi_label (bool force)
+static dw_cfi_row *
+copy_cfi_row (dw_cfi_row *src)
{
- static char label[20];
+ dw_cfi_row *dst = ggc_alloc<dw_cfi_row> ();
- if (!force && dwarf2out_do_cfi_asm ())
- {
- /* In this case, we will be emitting the asm directive instead of
- the label, so just return a placeholder to keep the rest of the
- interfaces happy. */
- strcpy (label, "<do not output>");
- }
- else
- {
- int num = dwarf2out_cfi_label_num++;
- ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
- ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
- }
+ *dst = *src;
+ dst->reg_save = vec_safe_copy (src->reg_save);
- return label;
+ return dst;
}
-/* True if remember_state should be emitted before following CFI directive. */
-static bool emit_cfa_remember;
-
-/* True if any CFI directives were emitted at the current insn. */
-static bool any_cfis_emitted;
-
-/* Add CFI to the current fde at the PC value indicated by LABEL if specified,
- or to the CIE if LABEL is NULL. */
+/* Generate a new label for the CFI info to refer to. */
-static void
-add_fde_cfi (const char *label, dw_cfi_ref cfi)
+static char *
+dwarf2out_cfi_label (void)
{
- cfi_vec *vec;
+ int num = dwarf2out_cfi_label_num++;
+ char label[20];
- if (cie_cfi_vec == NULL)
- cie_cfi_vec = VEC_alloc (dw_cfi_ref, gc, 20);
+ ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
- vec = &cie_cfi_vec;
+ return xstrdup (label);
+}
- if (emit_cfa_remember)
- {
- dw_cfi_ref cfi_remember;
+/* Add CFI either to the current insn stream or to a vector, or both. */
- /* Emit the state save. */
- emit_cfa_remember = false;
- cfi_remember = new_cfi ();
- cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
- add_fde_cfi (label, cfi_remember);
- }
+static void
+add_cfi (dw_cfi_ref cfi)
+{
+ any_cfis_emitted = true;
- if (dwarf2out_do_cfi_asm ())
+ if (add_cfi_insn != NULL)
{
- if (label)
- {
- dw_fde_ref fde = current_fde ();
-
- gcc_assert (fde != NULL);
-
- /* We still have to add the cfi to the list so that lookup_cfa
- works later on. When -g2 and above we even need to force
- emitting of CFI labels and add to list a DW_CFA_set_loc for
- convert_cfa_to_fb_loc_list purposes. If we're generating
- DWARF3 output we use DW_OP_call_frame_cfa and so don't use
- convert_cfa_to_fb_loc_list. */
- if (dwarf_version == 2
- && debug_info_level > DINFO_LEVEL_TERSE
- && (write_symbols == DWARF2_DEBUG
- || write_symbols == VMS_AND_DWARF2_DEBUG))
- {
- switch (cfi->dw_cfi_opc)
- {
- case DW_CFA_def_cfa_offset:
- case DW_CFA_def_cfa_offset_sf:
- case DW_CFA_def_cfa_register:
- case DW_CFA_def_cfa:
- case DW_CFA_def_cfa_sf:
- case DW_CFA_def_cfa_expression:
- case DW_CFA_restore_state:
- if (*label == 0 || strcmp (label, "<do not output>") == 0)
- label = dwarf2out_cfi_label (true);
-
- if (fde->dw_fde_current_label == NULL
- || strcmp (label, fde->dw_fde_current_label) != 0)
- {
- dw_cfi_ref xcfi;
-
- label = xstrdup (label);
-
- /* Set the location counter to the new label. */
- xcfi = new_cfi ();
- /* It doesn't metter whether DW_CFA_set_loc
- or DW_CFA_advance_loc4 is added here, those aren't
- emitted into assembly, only looked up by
- convert_cfa_to_fb_loc_list. */
- xcfi->dw_cfi_opc = DW_CFA_set_loc;
- xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
- add_cfi (&fde->dw_fde_cfi, xcfi);
- fde->dw_fde_current_label = label;
- }
- break;
- default:
- break;
- }
- }
+ add_cfi_insn = emit_note_after (NOTE_INSN_CFI, add_cfi_insn);
+ NOTE_CFI (add_cfi_insn) = cfi;
+ }
- output_cfi_directive (cfi);
+ if (add_cfi_vec != NULL)
+ vec_safe_push (*add_cfi_vec, cfi);
+}
- vec = &fde->dw_fde_cfi;
- any_cfis_emitted = true;
- }
- /* ??? If this is a CFI for the CIE, we don't emit. This
- assumes that the standard CIE contents that the assembler
- uses matches the standard CIE contents that the compiler
- uses. This is probably a bad assumption. I'm not quite
- sure how to address this for now. */
- }
- else if (label)
- {
- dw_fde_ref fde = current_fde ();
+static void
+add_cfi_args_size (HOST_WIDE_INT size)
+{
+ dw_cfi_ref cfi = new_cfi ();
- gcc_assert (fde != NULL);
+ /* While we can occasionally have args_size < 0 internally, this state
+ should not persist at a point we actually need an opcode. */
+ gcc_assert (size >= 0);
- if (*label == 0)
- label = dwarf2out_cfi_label (false);
+ cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
+ cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
- if (fde->dw_fde_current_label == NULL
- || strcmp (label, fde->dw_fde_current_label) != 0)
- {
- dw_cfi_ref xcfi;
+ add_cfi (cfi);
+}
- label = xstrdup (label);
+static void
+add_cfi_restore (unsigned reg)
+{
+ dw_cfi_ref cfi = new_cfi ();
- /* Set the location counter to the new label. */
- xcfi = new_cfi ();
- /* If we have a current label, advance from there, otherwise
- set the location directly using set_loc. */
- xcfi->dw_cfi_opc = fde->dw_fde_current_label
- ? DW_CFA_advance_loc4
- : DW_CFA_set_loc;
- xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
- add_cfi (&fde->dw_fde_cfi, xcfi);
+ cfi->dw_cfi_opc = (reg & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
+ cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
- fde->dw_fde_current_label = label;
- }
+ add_cfi (cfi);
+}
- vec = &fde->dw_fde_cfi;
- any_cfis_emitted = true;
- }
+/* Perform ROW->REG_SAVE[COLUMN] = CFI. CFI may be null, indicating
+ that the register column is no longer saved. */
- add_cfi (vec, cfi);
+static void
+update_row_reg_save (dw_cfi_row *row, unsigned column, dw_cfi_ref cfi)
+{
+ if (vec_safe_length (row->reg_save) <= column)
+ vec_safe_grow_cleared (row->reg_save, column + 1);
+ (*row->reg_save)[column] = cfi;
}
/* This function fills in aa dw_cfa_location structure from a dwarf location
descriptor sequence. */
static void
-get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
+get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_node *loc)
{
- struct dw_loc_descr_struct *ptr;
+ struct dw_loc_descr_node *ptr;
cfa->offset = 0;
cfa->base_offset = 0;
cfa->indirect = 0;
}
}
-/* Subroutine of lookup_cfa. */
+/* Find the previous value for the CFA, iteratively. CFI is the opcode
+ to interpret, *LOC will be updated as necessary, *REMEMBER is used for
+ one level of remember/restore state processing. */
void
lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
}
}
-/* Find the previous value for the CFA. */
+/* Determine if two dw_cfa_location structures define the same data. */
-static void
-lookup_cfa (dw_cfa_location *loc)
+bool
+cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
{
- int ix;
- dw_cfi_ref cfi;
- dw_fde_ref fde;
- dw_cfa_location remember;
-
- memset (loc, 0, sizeof (*loc));
- loc->reg = INVALID_REGNUM;
- remember = *loc;
+ return (loc1->reg == loc2->reg
+ && loc1->offset == loc2->offset
+ && loc1->indirect == loc2->indirect
+ && (loc1->indirect == 0
+ || loc1->base_offset == loc2->base_offset));
+}
- FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
- lookup_cfa_1 (cfi, loc, &remember);
+/* Determine if two CFI operands are identical. */
- fde = current_fde ();
- if (fde)
- FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
- lookup_cfa_1 (cfi, loc, &remember);
+static bool
+cfi_oprnd_equal_p (enum dw_cfi_oprnd_type t, dw_cfi_oprnd *a, dw_cfi_oprnd *b)
+{
+ switch (t)
+ {
+ case dw_cfi_oprnd_unused:
+ return true;
+ case dw_cfi_oprnd_reg_num:
+ return a->dw_cfi_reg_num == b->dw_cfi_reg_num;
+ case dw_cfi_oprnd_offset:
+ return a->dw_cfi_offset == b->dw_cfi_offset;
+ case dw_cfi_oprnd_addr:
+ return (a->dw_cfi_addr == b->dw_cfi_addr
+ || strcmp (a->dw_cfi_addr, b->dw_cfi_addr) == 0);
+ case dw_cfi_oprnd_loc:
+ return loc_descr_equal_p (a->dw_cfi_loc, b->dw_cfi_loc);
+ }
+ gcc_unreachable ();
}
-/* The current rule for calculating the DWARF2 canonical frame address. */
-static dw_cfa_location cfa;
+/* Determine if two CFI entries are identical. */
-/* The register used for saving registers to the stack, and its offset
- from the CFA. */
-static dw_cfa_location cfa_store;
+static bool
+cfi_equal_p (dw_cfi_ref a, dw_cfi_ref b)
+{
+ enum dwarf_call_frame_info opc;
-/* The current save location around an epilogue. */
-static dw_cfa_location cfa_remember;
+ /* Make things easier for our callers, including missing operands. */
+ if (a == b)
+ return true;
+ if (a == NULL || b == NULL)
+ return false;
-/* The running total of the size of arguments pushed onto the stack. */
-static HOST_WIDE_INT args_size;
+ /* Obviously, the opcodes must match. */
+ opc = a->dw_cfi_opc;
+ if (opc != b->dw_cfi_opc)
+ return false;
-/* The last args_size we actually output. */
-static HOST_WIDE_INT old_args_size;
+ /* Compare the two operands, re-using the type of the operands as
+ already exposed elsewhere. */
+ return (cfi_oprnd_equal_p (dw_cfi_oprnd1_desc (opc),
+ &a->dw_cfi_oprnd1, &b->dw_cfi_oprnd1)
+ && cfi_oprnd_equal_p (dw_cfi_oprnd2_desc (opc),
+ &a->dw_cfi_oprnd2, &b->dw_cfi_oprnd2));
+}
-/* Determine if two dw_cfa_location structures define the same data. */
+/* Determine if two CFI_ROW structures are identical. */
-bool
-cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
+static bool
+cfi_row_equal_p (dw_cfi_row *a, dw_cfi_row *b)
{
- return (loc1->reg == loc2->reg
- && loc1->offset == loc2->offset
- && loc1->indirect == loc2->indirect
- && (loc1->indirect == 0
- || loc1->base_offset == loc2->base_offset));
-}
+ size_t i, n_a, n_b, n_max;
+
+ if (a->cfa_cfi)
+ {
+ if (!cfi_equal_p (a->cfa_cfi, b->cfa_cfi))
+ return false;
+ }
+ else if (!cfa_equal_p (&a->cfa, &b->cfa))
+ return false;
-/* This routine does the actual work. The CFA is now calculated from
- the dw_cfa_location structure. */
+ n_a = vec_safe_length (a->reg_save);
+ n_b = vec_safe_length (b->reg_save);
+ n_max = MAX (n_a, n_b);
-static void
-def_cfa_1 (const char *label, dw_cfa_location *loc_p)
-{
- dw_cfi_ref cfi;
- dw_cfa_location old_cfa, loc;
+ for (i = 0; i < n_max; ++i)
+ {
+ dw_cfi_ref r_a = NULL, r_b = NULL;
+
+ if (i < n_a)
+ r_a = (*a->reg_save)[i];
+ if (i < n_b)
+ r_b = (*b->reg_save)[i];
- cfa = *loc_p;
- loc = *loc_p;
+ if (!cfi_equal_p (r_a, r_b))
+ return false;
+ }
+
+ return true;
+}
- if (cfa_store.reg == loc.reg && loc.indirect == 0)
- cfa_store.offset = loc.offset;
+/* The CFA is now calculated from NEW_CFA. Consider OLD_CFA in determining
+ what opcode to emit. Returns the CFI opcode to effect the change, or
+ NULL if NEW_CFA == OLD_CFA. */
- loc.reg = DWARF_FRAME_REGNUM (loc.reg);
- lookup_cfa (&old_cfa);
+static dw_cfi_ref
+def_cfa_0 (dw_cfa_location *old_cfa, dw_cfa_location *new_cfa)
+{
+ dw_cfi_ref cfi;
/* If nothing changed, no need to issue any call frame instructions. */
- if (cfa_equal_p (&loc, &old_cfa))
- return;
+ if (cfa_equal_p (old_cfa, new_cfa))
+ return NULL;
cfi = new_cfi ();
- if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
+ if (new_cfa->reg == old_cfa->reg && !new_cfa->indirect && !old_cfa->indirect)
{
/* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
the CFA register did not change but the offset did. The data
factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
in the assembler via the .cfi_def_cfa_offset directive. */
- if (loc.offset < 0)
+ if (new_cfa->offset < 0)
cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
else
cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
- cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
+ cfi->dw_cfi_oprnd1.dw_cfi_offset = new_cfa->offset;
}
-
-#ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
- else if (loc.offset == old_cfa.offset
- && old_cfa.reg != INVALID_REGNUM
- && !loc.indirect
- && !old_cfa.indirect)
+ else if (new_cfa->offset == old_cfa->offset
+ && old_cfa->reg != INVALID_REGNUM
+ && !new_cfa->indirect
+ && !old_cfa->indirect)
{
/* Construct a "DW_CFA_def_cfa_register <register>" instruction,
indicating the CFA register has changed to <register> but the
offset has not changed. */
cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
- cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
+ cfi->dw_cfi_oprnd1.dw_cfi_reg_num = new_cfa->reg;
}
-#endif
-
- else if (loc.indirect == 0)
+ else if (new_cfa->indirect == 0)
{
/* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
indicating the CFA register has changed to <register> with
the specified offset. The data factoring for DW_CFA_def_cfa_sf
happens in output_cfi, or in the assembler via the .cfi_def_cfa
directive. */
- if (loc.offset < 0)
+ if (new_cfa->offset < 0)
cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
else
cfi->dw_cfi_opc = DW_CFA_def_cfa;
- cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
- cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
+ cfi->dw_cfi_oprnd1.dw_cfi_reg_num = new_cfa->reg;
+ cfi->dw_cfi_oprnd2.dw_cfi_offset = new_cfa->offset;
}
else
{
/* Construct a DW_CFA_def_cfa_expression instruction to
calculate the CFA using a full location expression since no
register-offset pair is available. */
- struct dw_loc_descr_struct *loc_list;
+ struct dw_loc_descr_node *loc_list;
cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
- loc_list = build_cfa_loc (&loc, 0);
+ loc_list = build_cfa_loc (new_cfa, 0);
cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
}
- add_fde_cfi (label, cfi);
+ return cfi;
+}
+
+/* Similarly, but take OLD_CFA from CUR_ROW, and update it after the fact. */
+
+static void
+def_cfa_1 (dw_cfa_location *new_cfa)
+{
+ dw_cfi_ref cfi;
+
+ if (cur_trace->cfa_store.reg == new_cfa->reg && new_cfa->indirect == 0)
+ cur_trace->cfa_store.offset = new_cfa->offset;
+
+ cfi = def_cfa_0 (&cur_row->cfa, new_cfa);
+ if (cfi)
+ {
+ cur_row->cfa = *new_cfa;
+ cur_row->cfa_cfi = (cfi->dw_cfi_opc == DW_CFA_def_cfa_expression
+ ? cfi : NULL);
+
+ add_cfi (cfi);
+ }
}
/* Add the CFI for saving a register. REG is the CFA column number.
- LABEL is passed to add_fde_cfi.
If SREG is -1, the register is saved at OFFSET from the CFA;
otherwise it is saved in SREG. */
static void
-reg_save (const char *label, unsigned int reg, unsigned int sreg,
- HOST_WIDE_INT offset)
+reg_save (unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
{
+ dw_fde_ref fde = cfun ? cfun->fde : NULL;
dw_cfi_ref cfi = new_cfi ();
- dw_fde_ref fde = current_fde ();
cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
cfi->dw_cfi_opc = DW_CFA_expression;
cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
cfi->dw_cfi_oprnd2.dw_cfi_loc
- = build_cfa_aligned_loc (&cfa, offset, fde->stack_realignment);
+ = build_cfa_aligned_loc (&cur_row->cfa, offset,
+ fde->stack_realignment);
}
else if (sreg == INVALID_REGNUM)
{
cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
}
else if (sreg == reg)
- cfi->dw_cfi_opc = DW_CFA_same_value;
+ {
+ /* While we could emit something like DW_CFA_same_value or
+ DW_CFA_restore, we never expect to see something like that
+ in a prologue. This is more likely to be a bug. A backend
+ can always bypass this by using REG_CFA_RESTORE directly. */
+ gcc_unreachable ();
+ }
else
{
cfi->dw_cfi_opc = DW_CFA_register;
cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
}
- add_fde_cfi (label, cfi);
+ add_cfi (cfi);
+ update_row_reg_save (cur_row, reg, cfi);
}
-/* Record the initial position of the return address. RTL is
- INCOMING_RETURN_ADDR_RTX. */
+/* A subroutine of scan_trace. Check INSN for a REG_ARGS_SIZE note
+ and adjust data structures to match. */
static void
-initial_return_save (rtx rtl)
+notice_args_size (rtx_insn *insn)
{
- unsigned int reg = INVALID_REGNUM;
- HOST_WIDE_INT offset = 0;
+ HOST_WIDE_INT args_size, delta;
+ rtx note;
- switch (GET_CODE (rtl))
- {
- case REG:
- /* RA is in a register. */
- reg = DWARF_FRAME_REGNUM (REGNO (rtl));
- break;
+ note = find_reg_note (insn, REG_ARGS_SIZE, NULL);
+ if (note == NULL)
+ return;
- case MEM:
- /* RA is on the stack. */
- rtl = XEXP (rtl, 0);
- switch (GET_CODE (rtl))
- {
- case REG:
- gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
- offset = 0;
- break;
+ args_size = INTVAL (XEXP (note, 0));
+ delta = args_size - cur_trace->end_true_args_size;
+ if (delta == 0)
+ return;
- case PLUS:
- gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
- offset = INTVAL (XEXP (rtl, 1));
- break;
+ cur_trace->end_true_args_size = args_size;
- case MINUS:
- gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
- offset = -INTVAL (XEXP (rtl, 1));
- break;
+ /* If the CFA is computed off the stack pointer, then we must adjust
+ the computation of the CFA as well. */
+ if (cur_cfa->reg == dw_stack_pointer_regnum)
+ {
+ gcc_assert (!cur_cfa->indirect);
- default:
- gcc_unreachable ();
- }
-
- break;
-
- case PLUS:
- /* The return address is at some offset from any value we can
- actually load. For instance, on the SPARC it is in %i7+8. Just
- ignore the offset for now; it doesn't matter for unwinding frames. */
- gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
- initial_return_save (XEXP (rtl, 0));
- return;
-
- default:
- gcc_unreachable ();
- }
-
- if (reg != DWARF_FRAME_RETURN_COLUMN)
- reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
-}
-
-/* Given a SET, calculate the amount of stack adjustment it
- contains. */
-
-static HOST_WIDE_INT
-stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
- HOST_WIDE_INT cur_offset)
-{
- const_rtx src = SET_SRC (pattern);
- const_rtx dest = SET_DEST (pattern);
- HOST_WIDE_INT offset = 0;
- enum rtx_code code;
-
- if (dest == stack_pointer_rtx)
- {
- code = GET_CODE (src);
-
- /* Assume (set (reg sp) (reg whatever)) sets args_size
- level to 0. */
- if (code == REG && src != stack_pointer_rtx)
- {
- offset = -cur_args_size;
-#ifndef STACK_GROWS_DOWNWARD
- offset = -offset;
-#endif
- return offset - cur_offset;
- }
-
- if (! (code == PLUS || code == MINUS)
- || XEXP (src, 0) != stack_pointer_rtx
- || !CONST_INT_P (XEXP (src, 1)))
- return 0;
-
- /* (set (reg sp) (plus (reg sp) (const_int))) */
- offset = INTVAL (XEXP (src, 1));
- if (code == PLUS)
- offset = -offset;
- return offset;
- }
+ /* Convert a change in args_size (always a positive in the
+ direction of stack growth) to a change in stack pointer. */
+ if (!STACK_GROWS_DOWNWARD)
+ delta = -delta;
- if (MEM_P (src) && !MEM_P (dest))
- dest = src;
- if (MEM_P (dest))
- {
- /* (set (mem (pre_dec (reg sp))) (foo)) */
- src = XEXP (dest, 0);
- code = GET_CODE (src);
-
- switch (code)
- {
- case PRE_MODIFY:
- case POST_MODIFY:
- if (XEXP (src, 0) == stack_pointer_rtx)
- {
- rtx val = XEXP (XEXP (src, 1), 1);
- /* We handle only adjustments by constant amount. */
- gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
- && CONST_INT_P (val));
- offset = -INTVAL (val);
- break;
- }
- return 0;
-
- case PRE_DEC:
- case POST_DEC:
- if (XEXP (src, 0) == stack_pointer_rtx)
- {
- offset = GET_MODE_SIZE (GET_MODE (dest));
- break;
- }
- return 0;
-
- case PRE_INC:
- case POST_INC:
- if (XEXP (src, 0) == stack_pointer_rtx)
- {
- offset = -GET_MODE_SIZE (GET_MODE (dest));
- break;
- }
- return 0;
-
- default:
- return 0;
- }
+ cur_cfa->offset += delta;
}
- else
- return 0;
-
- return offset;
}
-/* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
- indexed by INSN_UID. */
-
-static HOST_WIDE_INT *barrier_args_size;
+/* A subroutine of scan_trace. INSN is can_throw_internal. Update the
+ data within the trace related to EH insns and args_size. */
-/* Helper function for compute_barrier_args_size. Handle one insn. */
-
-static HOST_WIDE_INT
-compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
- VEC (rtx, heap) **next)
+static void
+notice_eh_throw (rtx_insn *insn)
{
- HOST_WIDE_INT offset = 0;
- int i;
-
- if (! RTX_FRAME_RELATED_P (insn))
- {
- if (prologue_epilogue_contains (insn))
- /* Nothing */;
- else if (GET_CODE (PATTERN (insn)) == SET)
- offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
- else if (GET_CODE (PATTERN (insn)) == PARALLEL
- || GET_CODE (PATTERN (insn)) == SEQUENCE)
- {
- /* There may be stack adjustments inside compound insns. Search
- for them. */
- for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
- if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
- offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
- cur_args_size, offset);
- }
- }
- else
- {
- rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
-
- if (expr)
- {
- expr = XEXP (expr, 0);
- if (GET_CODE (expr) == PARALLEL
- || GET_CODE (expr) == SEQUENCE)
- for (i = 1; i < XVECLEN (expr, 0); i++)
- {
- rtx elem = XVECEXP (expr, 0, i);
-
- if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
- offset += stack_adjust_offset (elem, cur_args_size, offset);
- }
- }
- }
-
-#ifndef STACK_GROWS_DOWNWARD
- offset = -offset;
-#endif
-
- cur_args_size += offset;
- if (cur_args_size < 0)
- cur_args_size = 0;
+ HOST_WIDE_INT args_size;
- if (JUMP_P (insn))
+ args_size = cur_trace->end_true_args_size;
+ if (cur_trace->eh_head == NULL)
{
- rtx dest = JUMP_LABEL (insn);
-
- if (dest)
- {
- if (barrier_args_size [INSN_UID (dest)] < 0)
- {
- barrier_args_size [INSN_UID (dest)] = cur_args_size;
- VEC_safe_push (rtx, heap, *next, dest);
- }
- }
+ cur_trace->eh_head = insn;
+ cur_trace->beg_delay_args_size = args_size;
+ cur_trace->end_delay_args_size = args_size;
}
-
- return cur_args_size;
-}
-
-/* Walk the whole function and compute args_size on BARRIERs. */
-
-static void
-compute_barrier_args_size (void)
-{
- int max_uid = get_max_uid (), i;
- rtx insn;
- VEC (rtx, heap) *worklist, *next, *tmp;
-
- barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
- for (i = 0; i < max_uid; i++)
- barrier_args_size[i] = -1;
-
- worklist = VEC_alloc (rtx, heap, 20);
- next = VEC_alloc (rtx, heap, 20);
- insn = get_insns ();
- barrier_args_size[INSN_UID (insn)] = 0;
- VEC_quick_push (rtx, worklist, insn);
- for (;;)
+ else if (cur_trace->end_delay_args_size != args_size)
{
- while (!VEC_empty (rtx, worklist))
- {
- rtx prev, body, first_insn;
- HOST_WIDE_INT cur_args_size;
-
- first_insn = insn = VEC_pop (rtx, worklist);
- cur_args_size = barrier_args_size[INSN_UID (insn)];
- prev = prev_nonnote_insn (insn);
- if (prev && BARRIER_P (prev))
- barrier_args_size[INSN_UID (prev)] = cur_args_size;
-
- for (; insn; insn = NEXT_INSN (insn))
- {
- if (INSN_DELETED_P (insn) || NOTE_P (insn))
- continue;
- if (BARRIER_P (insn))
- break;
+ cur_trace->end_delay_args_size = args_size;
- if (LABEL_P (insn))
- {
- if (insn == first_insn)
- continue;
- else if (barrier_args_size[INSN_UID (insn)] < 0)
- {
- barrier_args_size[INSN_UID (insn)] = cur_args_size;
- continue;
- }
- else
- {
- /* The insns starting with this label have been
- already scanned or are in the worklist. */
- break;
- }
- }
-
- body = PATTERN (insn);
- if (GET_CODE (body) == SEQUENCE)
- {
- HOST_WIDE_INT dest_args_size = cur_args_size;
- for (i = 1; i < XVECLEN (body, 0); i++)
- if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
- && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
- dest_args_size
- = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
- dest_args_size, &next);
- else
- cur_args_size
- = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
- cur_args_size, &next);
-
- if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
- compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
- dest_args_size, &next);
- else
- cur_args_size
- = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
- cur_args_size, &next);
- }
- else
- cur_args_size
- = compute_barrier_args_size_1 (insn, cur_args_size, &next);
- }
- }
-
- if (VEC_empty (rtx, next))
- break;
-
- /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
- tmp = next;
- next = worklist;
- worklist = tmp;
- VEC_truncate (rtx, next, 0);
+ /* ??? If the CFA is the stack pointer, search backward for the last
+ CFI note and insert there. Given that the stack changed for the
+ args_size change, there *must* be such a note in between here and
+ the last eh insn. */
+ add_cfi_args_size (args_size);
}
-
- VEC_free (rtx, heap, worklist);
- VEC_free (rtx, heap, next);
-}
-
-/* Add a CFI to update the running total of the size of arguments
- pushed onto the stack. */
-
-static void
-dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
-{
- dw_cfi_ref cfi;
-
- if (size == old_args_size)
- return;
-
- old_args_size = size;
-
- cfi = new_cfi ();
- cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
- cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
- add_fde_cfi (label, cfi);
-}
-
-/* Record a stack adjustment of OFFSET bytes. */
-
-static void
-dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
-{
- if (cfa.reg == STACK_POINTER_REGNUM)
- cfa.offset += offset;
-
- if (cfa_store.reg == STACK_POINTER_REGNUM)
- cfa_store.offset += offset;
-
- if (ACCUMULATE_OUTGOING_ARGS)
- return;
-
-#ifndef STACK_GROWS_DOWNWARD
- offset = -offset;
-#endif
-
- args_size += offset;
- if (args_size < 0)
- args_size = 0;
-
- def_cfa_1 (label, &cfa);
- if (flag_asynchronous_unwind_tables)
- dwarf2out_args_size (label, args_size);
}
-/* Check INSN to see if it looks like a push or a stack adjustment, and
- make a note of it if it does. EH uses this information to find out
- how much extra space it needs to pop off the stack. */
+/* Short-hand inline for the very common D_F_R (REGNO (x)) operation. */
+/* ??? This ought to go into dwarf2out.h, except that dwarf2out.h is
+ used in places where rtl is prohibited. */
-static void
-dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
+static inline unsigned
+dwf_regno (const_rtx reg)
{
- HOST_WIDE_INT offset;
- const char *label;
- int i;
-
- /* Don't handle epilogues at all. Certainly it would be wrong to do so
- with this function. Proper support would require all frame-related
- insns to be marked, and to be able to handle saving state around
- epilogues textually in the middle of the function. */
- if (prologue_epilogue_contains (insn))
- return;
-
- /* If INSN is an instruction from target of an annulled branch, the
- effects are for the target only and so current argument size
- shouldn't change at all. */
- if (final_sequence
- && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
- && INSN_FROM_TARGET_P (insn))
- return;
-
- /* If only calls can throw, and we have a frame pointer,
- save up adjustments until we see the CALL_INSN. */
- if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
- {
- if (CALL_P (insn) && !after_p)
- {
- /* Extract the size of the args from the CALL rtx itself. */
- insn = PATTERN (insn);
- if (GET_CODE (insn) == PARALLEL)
- insn = XVECEXP (insn, 0, 0);
- if (GET_CODE (insn) == SET)
- insn = SET_SRC (insn);
- gcc_assert (GET_CODE (insn) == CALL);
- dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
- }
- return;
- }
-
- if (CALL_P (insn) && !after_p)
- {
- if (!flag_asynchronous_unwind_tables)
- dwarf2out_args_size ("", args_size);
- return;
- }
- else if (BARRIER_P (insn))
- {
- /* Don't call compute_barrier_args_size () if the only
- BARRIER is at the end of function. */
- if (barrier_args_size == NULL && next_nonnote_insn (insn))
- compute_barrier_args_size ();
- if (barrier_args_size == NULL)
- offset = 0;
- else
- {
- offset = barrier_args_size[INSN_UID (insn)];
- if (offset < 0)
- offset = 0;
- }
-
- offset -= args_size;
-#ifndef STACK_GROWS_DOWNWARD
- offset = -offset;
-#endif
- }
- else if (GET_CODE (PATTERN (insn)) == SET)
- offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
- else if (GET_CODE (PATTERN (insn)) == PARALLEL
- || GET_CODE (PATTERN (insn)) == SEQUENCE)
- {
- /* There may be stack adjustments inside compound insns. Search
- for them. */
- for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
- if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
- offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
- args_size, offset);
- }
- else
- return;
-
- if (offset == 0)
- return;
-
- label = dwarf2out_cfi_label (false);
- dwarf2out_stack_adjust (offset, label);
+ gcc_assert (REGNO (reg) < FIRST_PSEUDO_REGISTER);
+ return DWARF_FRAME_REGNUM (REGNO (reg));
}
-/* We delay emitting a register save until either (a) we reach the end
- of the prologue or (b) the register is clobbered. This clusters
- register saves so that there are fewer pc advances. */
-
-struct GTY(()) queued_reg_save {
- struct queued_reg_save *next;
- rtx reg;
- HOST_WIDE_INT cfa_offset;
- rtx saved_reg;
-};
-
-static GTY(()) struct queued_reg_save *queued_reg_saves;
-
-/* The caller's ORIG_REG is saved in SAVED_IN_REG. */
-typedef struct GTY(()) reg_saved_in_data {
- rtx orig_reg;
- rtx saved_in_reg;
-} reg_saved_in_data;
-
-DEF_VEC_O (reg_saved_in_data);
-DEF_VEC_ALLOC_O (reg_saved_in_data, gc);
-
-/* A set of registers saved in other registers. This is implemented as
- a flat array because it normally contains zero or 1 entry, depending
- on the target. IA-64 is the big spender here, using a maximum of
- 5 entries. */
-static GTY(()) VEC(reg_saved_in_data, gc) *regs_saved_in_regs;
-
/* Compare X and Y for equivalence. The inputs may be REGs or PC_RTX. */
static bool
reg_saved_in_data *elt;
size_t i;
- FOR_EACH_VEC_ELT (reg_saved_in_data, regs_saved_in_regs, i, elt)
+ FOR_EACH_VEC_ELT (cur_trace->regs_saved_in_regs, i, elt)
if (compare_reg_or_pc (elt->orig_reg, src))
{
if (dest == NULL)
- VEC_unordered_remove(reg_saved_in_data, regs_saved_in_regs, i);
+ cur_trace->regs_saved_in_regs.unordered_remove (i);
else
elt->saved_in_reg = dest;
return;
if (dest == NULL)
return;
- elt = VEC_safe_push(reg_saved_in_data, gc, regs_saved_in_regs, NULL);
- elt->orig_reg = src;
- elt->saved_in_reg = dest;
+ reg_saved_in_data e = {src, dest};
+ cur_trace->regs_saved_in_regs.safe_push (e);
}
-static const char *last_reg_save_label;
-
/* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
static void
-queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
+queue_reg_save (rtx reg, rtx sreg, HOST_WIDE_INT offset)
{
- struct queued_reg_save *q;
+ queued_reg_save *q;
+ queued_reg_save e = {reg, sreg, offset};
+ size_t i;
/* Duplicates waste space, but it's also necessary to remove them
- for correctness, since the queue gets output in reverse
- order. */
- for (q = queued_reg_saves; q != NULL; q = q->next)
- if (REGNO (q->reg) == REGNO (reg))
- break;
-
- if (q == NULL)
- {
- q = ggc_alloc_queued_reg_save ();
- q->next = queued_reg_saves;
- queued_reg_saves = q;
- }
-
- q->reg = reg;
- q->cfa_offset = offset;
- q->saved_reg = sreg;
+ for correctness, since the queue gets output in reverse order. */
+ FOR_EACH_VEC_ELT (queued_reg_saves, i, q)
+ if (compare_reg_or_pc (q->reg, reg))
+ {
+ *q = e;
+ return;
+ }
- last_reg_save_label = label;
+ queued_reg_saves.safe_push (e);
}
/* Output all the entries in QUEUED_REG_SAVES. */
static void
dwarf2out_flush_queued_reg_saves (void)
{
- struct queued_reg_save *q;
+ queued_reg_save *q;
+ size_t i;
- for (q = queued_reg_saves; q; q = q->next)
+ FOR_EACH_VEC_ELT (queued_reg_saves, i, q)
{
unsigned int reg, sreg;
record_reg_saved_in_reg (q->saved_reg, q->reg);
- reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
+ if (q->reg == pc_rtx)
+ reg = DWARF_FRAME_RETURN_COLUMN;
+ else
+ reg = dwf_regno (q->reg);
if (q->saved_reg)
- sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
+ sreg = dwf_regno (q->saved_reg);
else
sreg = INVALID_REGNUM;
- reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
+ reg_save (reg, sreg, q->cfa_offset);
}
- queued_reg_saves = NULL;
- last_reg_save_label = NULL;
+ queued_reg_saves.truncate (0);
}
/* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
static bool
clobbers_queued_reg_save (const_rtx insn)
{
- struct queued_reg_save *q;
+ queued_reg_save *q;
+ size_t iq;
- for (q = queued_reg_saves; q; q = q->next)
+ FOR_EACH_VEC_ELT (queued_reg_saves, iq, q)
{
- size_t i;
+ size_t ir;
reg_saved_in_data *rir;
if (modified_in_p (q->reg, insn))
return true;
- FOR_EACH_VEC_ELT (reg_saved_in_data, regs_saved_in_regs, i, rir)
+ FOR_EACH_VEC_ELT (cur_trace->regs_saved_in_regs, ir, rir)
if (compare_reg_or_pc (q->reg, rir->orig_reg)
&& modified_in_p (rir->saved_in_reg, insn))
return true;
reg_saved_in (rtx reg)
{
unsigned int regn = REGNO (reg);
- struct queued_reg_save *q;
+ queued_reg_save *q;
reg_saved_in_data *rir;
size_t i;
- for (q = queued_reg_saves; q; q = q->next)
+ FOR_EACH_VEC_ELT (queued_reg_saves, i, q)
if (q->saved_reg && regn == REGNO (q->saved_reg))
return q->reg;
- FOR_EACH_VEC_ELT (reg_saved_in_data, regs_saved_in_regs, i, rir)
+ FOR_EACH_VEC_ELT (cur_trace->regs_saved_in_regs, i, rir)
if (regn == REGNO (rir->saved_in_reg))
return rir->orig_reg;
return NULL_RTX;
}
-
-/* A temporary register holding an integral value used in adjusting SP
- or setting up the store_reg. The "offset" field holds the integer
- value, not an offset. */
-static dw_cfa_location cfa_temp;
-
/* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
static void
-dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
+dwarf2out_frame_debug_def_cfa (rtx pat)
{
- memset (&cfa, 0, sizeof (cfa));
+ memset (cur_cfa, 0, sizeof (*cur_cfa));
- switch (GET_CODE (pat))
+ if (GET_CODE (pat) == PLUS)
{
- case PLUS:
- cfa.reg = REGNO (XEXP (pat, 0));
- cfa.offset = INTVAL (XEXP (pat, 1));
- break;
-
- case REG:
- cfa.reg = REGNO (pat);
- break;
-
- case MEM:
- cfa.indirect = 1;
+ cur_cfa->offset = INTVAL (XEXP (pat, 1));
+ pat = XEXP (pat, 0);
+ }
+ if (MEM_P (pat))
+ {
+ cur_cfa->indirect = 1;
pat = XEXP (pat, 0);
if (GET_CODE (pat) == PLUS)
{
- cfa.base_offset = INTVAL (XEXP (pat, 1));
+ cur_cfa->base_offset = INTVAL (XEXP (pat, 1));
pat = XEXP (pat, 0);
}
- cfa.reg = REGNO (pat);
- break;
-
- default:
- /* Recurse and define an expression. */
- gcc_unreachable ();
}
-
- def_cfa_1 (label, &cfa);
+ /* ??? If this fails, we could be calling into the _loc functions to
+ define a full expression. So far no port does that. */
+ gcc_assert (REG_P (pat));
+ cur_cfa->reg = dwf_regno (pat);
}
/* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
static void
-dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
+dwarf2out_frame_debug_adjust_cfa (rtx pat)
{
rtx src, dest;
switch (GET_CODE (src))
{
case PLUS:
- gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
- cfa.offset -= INTVAL (XEXP (src, 1));
+ gcc_assert (dwf_regno (XEXP (src, 0)) == cur_cfa->reg);
+ cur_cfa->offset -= INTVAL (XEXP (src, 1));
break;
case REG:
- break;
+ break;
default:
- gcc_unreachable ();
+ gcc_unreachable ();
}
- cfa.reg = REGNO (dest);
- gcc_assert (cfa.indirect == 0);
-
- def_cfa_1 (label, &cfa);
+ cur_cfa->reg = dwf_regno (dest);
+ gcc_assert (cur_cfa->indirect == 0);
}
/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
static void
-dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
+dwarf2out_frame_debug_cfa_offset (rtx set)
{
HOST_WIDE_INT offset;
rtx src, addr, span;
switch (GET_CODE (addr))
{
case REG:
- gcc_assert (REGNO (addr) == cfa.reg);
- offset = -cfa.offset;
+ gcc_assert (dwf_regno (addr) == cur_cfa->reg);
+ offset = -cur_cfa->offset;
break;
case PLUS:
- gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
- offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
+ gcc_assert (dwf_regno (XEXP (addr, 0)) == cur_cfa->reg);
+ offset = INTVAL (XEXP (addr, 1)) - cur_cfa->offset;
break;
default:
gcc_unreachable ();
span = NULL;
sregno = DWARF_FRAME_RETURN_COLUMN;
}
- else
+ else
{
span = targetm.dwarf_register_span (src);
- sregno = DWARF_FRAME_REGNUM (REGNO (src));
+ sregno = dwf_regno (src);
}
/* ??? We'd like to use queue_reg_save, but we need to come up with
a different flushing heuristic for epilogues. */
if (!span)
- reg_save (label, sregno, INVALID_REGNUM, offset);
+ reg_save (sregno, INVALID_REGNUM, offset);
else
{
/* We have a PARALLEL describing where the contents of SRC live.
- Queue register saves for each piece of the PARALLEL. */
- int par_index;
- int limit;
+ Adjust the offset for each piece of the PARALLEL. */
HOST_WIDE_INT span_offset = offset;
gcc_assert (GET_CODE (span) == PARALLEL);
- limit = XVECLEN (span, 0);
- for (par_index = 0; par_index < limit; par_index++)
+ const int par_len = XVECLEN (span, 0);
+ for (int par_index = 0; par_index < par_len; par_index++)
{
rtx elem = XVECEXP (span, 0, par_index);
-
- sregno = DWARF_FRAME_REGNUM (REGNO (src));
- reg_save (label, sregno, INVALID_REGNUM, span_offset);
+ sregno = dwf_regno (src);
+ reg_save (sregno, INVALID_REGNUM, span_offset);
span_offset += GET_MODE_SIZE (GET_MODE (elem));
}
}
/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
static void
-dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
+dwarf2out_frame_debug_cfa_register (rtx set)
{
rtx src, dest;
unsigned sregno, dregno;
src = XEXP (set, 1);
dest = XEXP (set, 0);
+ record_reg_saved_in_reg (dest, src);
if (src == pc_rtx)
sregno = DWARF_FRAME_RETURN_COLUMN;
else
- {
- record_reg_saved_in_reg (dest, src);
- sregno = DWARF_FRAME_REGNUM (REGNO (src));
- }
+ sregno = dwf_regno (src);
- dregno = DWARF_FRAME_REGNUM (REGNO (dest));
+ dregno = dwf_regno (dest);
/* ??? We'd like to use queue_reg_save, but we need to come up with
a different flushing heuristic for epilogues. */
- reg_save (label, sregno, dregno, 0);
+ reg_save (sregno, dregno, 0);
}
/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
static void
-dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
+dwarf2out_frame_debug_cfa_expression (rtx set)
{
rtx src, dest, span;
dw_cfi_ref cfi = new_cfi ();
+ unsigned regno;
dest = SET_DEST (set);
src = SET_SRC (set);
span = targetm.dwarf_register_span (src);
gcc_assert (!span);
+ regno = dwf_regno (src);
+
cfi->dw_cfi_opc = DW_CFA_expression;
- cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
+ cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
cfi->dw_cfi_oprnd2.dw_cfi_loc
= mem_loc_descriptor (XEXP (dest, 0), get_address_mode (dest),
GET_MODE (dest), VAR_INIT_STATUS_INITIALIZED);
/* ??? We'd like to use queue_reg_save, were the interface different,
and, as above, we could manage flushing for epilogues. */
- add_fde_cfi (label, cfi);
+ add_cfi (cfi);
+ update_row_reg_save (cur_row, regno, cfi);
}
/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
static void
-dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
+dwarf2out_frame_debug_cfa_restore (rtx reg)
{
- dw_cfi_ref cfi = new_cfi ();
- unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
+ gcc_assert (REG_P (reg));
- cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
- cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
+ rtx span = targetm.dwarf_register_span (reg);
+ if (!span)
+ {
+ unsigned int regno = dwf_regno (reg);
+ add_cfi_restore (regno);
+ update_row_reg_save (cur_row, regno, NULL);
+ }
+ else
+ {
+ /* We have a PARALLEL describing where the contents of REG live.
+ Restore the register for each piece of the PARALLEL. */
+ gcc_assert (GET_CODE (span) == PARALLEL);
- add_fde_cfi (label, cfi);
+ const int par_len = XVECLEN (span, 0);
+ for (int par_index = 0; par_index < par_len; par_index++)
+ {
+ reg = XVECEXP (span, 0, par_index);
+ gcc_assert (REG_P (reg));
+ unsigned int regno = dwf_regno (reg);
+ add_cfi_restore (regno);
+ update_row_reg_save (cur_row, regno, NULL);
+ }
+ }
}
/* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE.
assuming 0(cfa)) and what registers are in the window. */
static void
-dwarf2out_frame_debug_cfa_window_save (const char *label)
+dwarf2out_frame_debug_cfa_window_save (void)
{
dw_cfi_ref cfi = new_cfi ();
cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
- add_fde_cfi (label, cfi);
+ add_cfi (cfi);
}
/* Record call frame debugging information for an expression EXPR,
Invariants / Summaries of Rules
cfa current rule for calculating the CFA. It usually
- consists of a register and an offset.
+ consists of a register and an offset. This is
+ actually stored in *cur_cfa, but abbreviated
+ for the purposes of this documentation.
cfa_store register used by prologue code to save things to the stack
cfa_store.offset is the offset from the value of
cfa_store.reg to the actual CFA
Rule 16:
(set sp (and: sp <const_int>))
constraints: cfa_store.reg == sp
- effects: current_fde.stack_realign = 1
+ effects: cfun->fde.stack_realign = 1
cfa_store.offset = 0
fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
cfa.reg == fde->drap_reg */
static void
-dwarf2out_frame_debug_expr (rtx expr, const char *label)
+dwarf2out_frame_debug_expr (rtx expr)
{
rtx src, dest, span;
HOST_WIDE_INT offset;
if (GET_CODE (elem) == SET
&& MEM_P (SET_DEST (elem))
&& (RTX_FRAME_RELATED_P (elem) || par_index == 0))
- dwarf2out_frame_debug_expr (elem, label);
+ dwarf2out_frame_debug_expr (elem);
}
for (par_index = 0; par_index < limit; par_index++)
if (GET_CODE (elem) == SET
&& (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
&& (RTX_FRAME_RELATED_P (elem) || par_index == 0))
- dwarf2out_frame_debug_expr (elem, label);
- else if (GET_CODE (elem) == SET
- && par_index != 0
- && !RTX_FRAME_RELATED_P (elem))
- {
- /* Stack adjustment combining might combine some post-prologue
- stack adjustment into a prologue stack adjustment. */
- HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
-
- if (offset != 0)
- dwarf2out_stack_adjust (offset, label);
- }
+ dwarf2out_frame_debug_expr (elem);
}
return;
}
src = rsi;
}
- fde = current_fde ();
+ fde = cfun->fde;
switch (GET_CODE (dest))
{
{
/* Setting FP from SP. */
case REG:
- if (cfa.reg == (unsigned) REGNO (src))
+ if (cur_cfa->reg == dwf_regno (src))
{
/* Rule 1 */
/* Update the CFA rule wrt SP or FP. Make sure src is
ARM copies SP to a temporary register, and from there to
FP. So we just rely on the backends to only set
RTX_FRAME_RELATED_P on appropriate insns. */
- cfa.reg = REGNO (dest);
- cfa_temp.reg = cfa.reg;
- cfa_temp.offset = cfa.offset;
+ cur_cfa->reg = dwf_regno (dest);
+ cur_trace->cfa_temp.reg = cur_cfa->reg;
+ cur_trace->cfa_temp.offset = cur_cfa->offset;
}
else
{
/* Saving a register in a register. */
gcc_assert (!fixed_regs [REGNO (dest)]
/* For the SPARC and its register window. */
- || (DWARF_FRAME_REGNUM (REGNO (src))
- == DWARF_FRAME_RETURN_COLUMN));
+ || (dwf_regno (src) == DWARF_FRAME_RETURN_COLUMN));
/* After stack is aligned, we can only save SP in FP
if drap register is used. In this case, we have
&& REGNO (src) == STACK_POINTER_REGNUM)
gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
&& fde->drap_reg != INVALID_REGNUM
- && cfa.reg != REGNO (src));
+ && cur_cfa->reg != dwf_regno (src));
else
- queue_reg_save (label, src, dest, 0);
+ queue_reg_save (src, dest, 0);
}
break;
offset = INTVAL (XEXP (src, 1));
break;
case REG:
- gcc_assert ((unsigned) REGNO (XEXP (src, 1))
- == cfa_temp.reg);
- offset = cfa_temp.offset;
+ gcc_assert (dwf_regno (XEXP (src, 1))
+ == cur_trace->cfa_temp.reg);
+ offset = cur_trace->cfa_temp.offset;
break;
default:
gcc_unreachable ();
if (XEXP (src, 0) == hard_frame_pointer_rtx)
{
/* Restoring SP from FP in the epilogue. */
- gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
- cfa.reg = STACK_POINTER_REGNUM;
+ gcc_assert (cur_cfa->reg == dw_frame_pointer_regnum);
+ cur_cfa->reg = dw_stack_pointer_regnum;
}
else if (GET_CODE (src) == LO_SUM)
/* Assume we've set the source reg of the LO_SUM from sp. */
if (GET_CODE (src) != MINUS)
offset = -offset;
- if (cfa.reg == STACK_POINTER_REGNUM)
- cfa.offset += offset;
- if (cfa_store.reg == STACK_POINTER_REGNUM)
- cfa_store.offset += offset;
+ if (cur_cfa->reg == dw_stack_pointer_regnum)
+ cur_cfa->offset += offset;
+ if (cur_trace->cfa_store.reg == dw_stack_pointer_regnum)
+ cur_trace->cfa_store.offset += offset;
}
else if (dest == hard_frame_pointer_rtx)
{
gcc_assert (frame_pointer_needed);
gcc_assert (REG_P (XEXP (src, 0))
- && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
+ && dwf_regno (XEXP (src, 0)) == cur_cfa->reg
&& CONST_INT_P (XEXP (src, 1)));
offset = INTVAL (XEXP (src, 1));
if (GET_CODE (src) != MINUS)
offset = -offset;
- cfa.offset += offset;
- cfa.reg = HARD_FRAME_POINTER_REGNUM;
+ cur_cfa->offset += offset;
+ cur_cfa->reg = dw_frame_pointer_regnum;
}
else
{
/* Rule 4 */
if (REG_P (XEXP (src, 0))
- && REGNO (XEXP (src, 0)) == cfa.reg
+ && dwf_regno (XEXP (src, 0)) == cur_cfa->reg
&& CONST_INT_P (XEXP (src, 1)))
{
/* Setting a temporary CFA register that will be copied
into the FP later on. */
offset = - INTVAL (XEXP (src, 1));
- cfa.offset += offset;
- cfa.reg = REGNO (dest);
+ cur_cfa->offset += offset;
+ cur_cfa->reg = dwf_regno (dest);
/* Or used to save regs to the stack. */
- cfa_temp.reg = cfa.reg;
- cfa_temp.offset = cfa.offset;
+ cur_trace->cfa_temp.reg = cur_cfa->reg;
+ cur_trace->cfa_temp.offset = cur_cfa->offset;
}
/* Rule 5 */
else if (REG_P (XEXP (src, 0))
- && REGNO (XEXP (src, 0)) == cfa_temp.reg
+ && dwf_regno (XEXP (src, 0)) == cur_trace->cfa_temp.reg
&& XEXP (src, 1) == stack_pointer_rtx)
{
/* Setting a scratch register that we will use instead
of SP for saving registers to the stack. */
- gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
- cfa_store.reg = REGNO (dest);
- cfa_store.offset = cfa.offset - cfa_temp.offset;
+ gcc_assert (cur_cfa->reg == dw_stack_pointer_regnum);
+ cur_trace->cfa_store.reg = dwf_regno (dest);
+ cur_trace->cfa_store.offset
+ = cur_cfa->offset - cur_trace->cfa_temp.offset;
}
/* Rule 9 */
else if (GET_CODE (src) == LO_SUM
&& CONST_INT_P (XEXP (src, 1)))
{
- cfa_temp.reg = REGNO (dest);
- cfa_temp.offset = INTVAL (XEXP (src, 1));
+ cur_trace->cfa_temp.reg = dwf_regno (dest);
+ cur_trace->cfa_temp.offset = INTVAL (XEXP (src, 1));
}
else
gcc_unreachable ();
/* Rule 6 */
case CONST_INT:
- cfa_temp.reg = REGNO (dest);
- cfa_temp.offset = INTVAL (src);
+ cur_trace->cfa_temp.reg = dwf_regno (dest);
+ cur_trace->cfa_temp.offset = INTVAL (src);
break;
/* Rule 7 */
case IOR:
gcc_assert (REG_P (XEXP (src, 0))
- && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
+ && dwf_regno (XEXP (src, 0)) == cur_trace->cfa_temp.reg
&& CONST_INT_P (XEXP (src, 1)));
- if ((unsigned) REGNO (dest) != cfa_temp.reg)
- cfa_temp.reg = REGNO (dest);
- cfa_temp.offset |= INTVAL (XEXP (src, 1));
+ cur_trace->cfa_temp.reg = dwf_regno (dest);
+ cur_trace->cfa_temp.offset |= INTVAL (XEXP (src, 1));
break;
/* Skip over HIGH, assuming it will be followed by a LO_SUM,
/* Rule 15 */
case UNSPEC:
case UNSPEC_VOLATILE:
- gcc_assert (targetm.dwarf_handle_frame_unspec);
- targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
+ /* All unspecs should be represented by REG_CFA_* notes. */
+ gcc_unreachable ();
return;
/* Rule 16 */
Thus we must flush whatever we have queued first. */
dwarf2out_flush_queued_reg_saves ();
- gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
+ gcc_assert (cur_trace->cfa_store.reg
+ == dwf_regno (XEXP (src, 0)));
fde->stack_realign = 1;
fde->stack_realignment = INTVAL (XEXP (src, 1));
- cfa_store.offset = 0;
+ cur_trace->cfa_store.offset = 0;
- if (cfa.reg != STACK_POINTER_REGNUM
- && cfa.reg != HARD_FRAME_POINTER_REGNUM)
- fde->drap_reg = cfa.reg;
+ if (cur_cfa->reg != dw_stack_pointer_regnum
+ && cur_cfa->reg != dw_frame_pointer_regnum)
+ fde->drap_reg = cur_cfa->reg;
}
return;
default:
gcc_unreachable ();
}
-
- def_cfa_1 (label, &cfa);
break;
case MEM:
offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
- && cfa_store.reg == STACK_POINTER_REGNUM);
+ && cur_trace->cfa_store.reg == dw_stack_pointer_regnum);
- cfa_store.offset += offset;
- if (cfa.reg == STACK_POINTER_REGNUM)
- cfa.offset = cfa_store.offset;
+ cur_trace->cfa_store.offset += offset;
+ if (cur_cfa->reg == dw_stack_pointer_regnum)
+ cur_cfa->offset = cur_trace->cfa_store.offset;
if (GET_CODE (XEXP (dest, 0)) == POST_MODIFY)
- offset -= cfa_store.offset;
+ offset -= cur_trace->cfa_store.offset;
else
- offset = -cfa_store.offset;
+ offset = -cur_trace->cfa_store.offset;
break;
/* Rule 11 */
gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
== STACK_POINTER_REGNUM)
- && cfa_store.reg == STACK_POINTER_REGNUM);
+ && cur_trace->cfa_store.reg == dw_stack_pointer_regnum);
- cfa_store.offset += offset;
+ cur_trace->cfa_store.offset += offset;
/* Rule 18: If stack is aligned, we will use FP as a
reference to represent the address of the stored
regiser. */
if (fde
&& fde->stack_realign
- && src == hard_frame_pointer_rtx)
+ && REG_P (src)
+ && REGNO (src) == HARD_FRAME_POINTER_REGNUM)
{
- gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
- cfa_store.offset = 0;
+ gcc_assert (cur_cfa->reg != dw_frame_pointer_regnum);
+ cur_trace->cfa_store.offset = 0;
}
- if (cfa.reg == STACK_POINTER_REGNUM)
- cfa.offset = cfa_store.offset;
+ if (cur_cfa->reg == dw_stack_pointer_regnum)
+ cur_cfa->offset = cur_trace->cfa_store.offset;
if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
- offset += -cfa_store.offset;
+ offset += -cur_trace->cfa_store.offset;
else
- offset = -cfa_store.offset;
+ offset = -cur_trace->cfa_store.offset;
break;
/* Rule 12 */
case MINUS:
case LO_SUM:
{
- int regno;
+ unsigned int regno;
gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
&& REG_P (XEXP (XEXP (dest, 0), 0)));
if (GET_CODE (XEXP (dest, 0)) == MINUS)
offset = -offset;
- regno = REGNO (XEXP (XEXP (dest, 0), 0));
+ regno = dwf_regno (XEXP (XEXP (dest, 0), 0));
- if (cfa.reg == (unsigned) regno)
- offset -= cfa.offset;
- else if (cfa_store.reg == (unsigned) regno)
- offset -= cfa_store.offset;
+ if (cur_cfa->reg == regno)
+ offset -= cur_cfa->offset;
+ else if (cur_trace->cfa_store.reg == regno)
+ offset -= cur_trace->cfa_store.offset;
else
{
- gcc_assert (cfa_temp.reg == (unsigned) regno);
- offset -= cfa_temp.offset;
+ gcc_assert (cur_trace->cfa_temp.reg == regno);
+ offset -= cur_trace->cfa_temp.offset;
}
}
break;
/* Without an offset. */
case REG:
{
- int regno = REGNO (XEXP (dest, 0));
+ unsigned int regno = dwf_regno (XEXP (dest, 0));
- if (cfa.reg == (unsigned) regno)
- offset = -cfa.offset;
- else if (cfa_store.reg == (unsigned) regno)
- offset = -cfa_store.offset;
+ if (cur_cfa->reg == regno)
+ offset = -cur_cfa->offset;
+ else if (cur_trace->cfa_store.reg == regno)
+ offset = -cur_trace->cfa_store.offset;
else
{
- gcc_assert (cfa_temp.reg == (unsigned) regno);
- offset = -cfa_temp.offset;
+ gcc_assert (cur_trace->cfa_temp.reg == regno);
+ offset = -cur_trace->cfa_temp.offset;
}
}
break;
/* Rule 14 */
case POST_INC:
- gcc_assert (cfa_temp.reg
- == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
- offset = -cfa_temp.offset;
- cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
+ gcc_assert (cur_trace->cfa_temp.reg
+ == dwf_regno (XEXP (XEXP (dest, 0), 0)));
+ offset = -cur_trace->cfa_temp.offset;
+ cur_trace->cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
break;
default:
gcc_unreachable ();
}
- /* Rule 17 */
- /* If the source operand of this MEM operation is not a
- register, basically the source is return address. Here
- we only care how much stack grew and we don't save it. */
- if (!REG_P (src))
+ /* Rule 17 */
+ /* If the source operand of this MEM operation is a memory,
+ we only care how much stack grew. */
+ if (MEM_P (src))
break;
- if (REGNO (src) != STACK_POINTER_REGNUM
+ if (REG_P (src)
+ && REGNO (src) != STACK_POINTER_REGNUM
&& REGNO (src) != HARD_FRAME_POINTER_REGNUM
- && (unsigned) REGNO (src) == cfa.reg)
+ && dwf_regno (src) == cur_cfa->reg)
{
/* We're storing the current CFA reg into the stack. */
- if (cfa.offset == 0)
+ if (cur_cfa->offset == 0)
{
/* Rule 19 */
/* If stack is aligned, putting CFA reg into stack means
value. */
if (fde
&& fde->stack_realign
- && cfa.indirect == 0
- && cfa.reg != HARD_FRAME_POINTER_REGNUM)
+ && cur_cfa->indirect == 0
+ && cur_cfa->reg != dw_frame_pointer_regnum)
{
- dw_cfa_location cfa_exp;
+ gcc_assert (fde->drap_reg == cur_cfa->reg);
- gcc_assert (fde->drap_reg == cfa.reg);
-
- cfa_exp.indirect = 1;
- cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
- cfa_exp.base_offset = offset;
- cfa_exp.offset = 0;
+ cur_cfa->indirect = 1;
+ cur_cfa->reg = dw_frame_pointer_regnum;
+ cur_cfa->base_offset = offset;
+ cur_cfa->offset = 0;
fde->drap_reg_saved = 1;
-
- def_cfa_1 (label, &cfa_exp);
break;
}
/* If the source register is exactly the CFA, assume
we're saving SP like any other register; this happens
on the ARM. */
- def_cfa_1 (label, &cfa);
- queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
+ queue_reg_save (stack_pointer_rtx, NULL_RTX, offset);
break;
}
else
x = XEXP (x, 0);
gcc_assert (REG_P (x));
- cfa.reg = REGNO (x);
- cfa.base_offset = offset;
- cfa.indirect = 1;
- def_cfa_1 (label, &cfa);
+ cur_cfa->reg = dwf_regno (x);
+ cur_cfa->base_offset = offset;
+ cur_cfa->indirect = 1;
break;
}
}
- def_cfa_1 (label, &cfa);
- {
+ if (REG_P (src))
span = targetm.dwarf_register_span (src);
+ else
+ span = NULL;
- if (!span)
- queue_reg_save (label, src, NULL_RTX, offset);
- else
- {
- /* We have a PARALLEL describing where the contents of SRC
- live. Queue register saves for each piece of the
- PARALLEL. */
- int par_index;
- int limit;
- HOST_WIDE_INT span_offset = offset;
-
- gcc_assert (GET_CODE (span) == PARALLEL);
+ if (!span)
+ queue_reg_save (src, NULL_RTX, offset);
+ else
+ {
+ /* We have a PARALLEL describing where the contents of SRC live.
+ Queue register saves for each piece of the PARALLEL. */
+ HOST_WIDE_INT span_offset = offset;
- limit = XVECLEN (span, 0);
- for (par_index = 0; par_index < limit; par_index++)
- {
- rtx elem = XVECEXP (span, 0, par_index);
+ gcc_assert (GET_CODE (span) == PARALLEL);
- queue_reg_save (label, elem, NULL_RTX, span_offset);
- span_offset += GET_MODE_SIZE (GET_MODE (elem));
- }
- }
- }
+ const int par_len = XVECLEN (span, 0);
+ for (int par_index = 0; par_index < par_len; par_index++)
+ {
+ rtx elem = XVECEXP (span, 0, par_index);
+ queue_reg_save (elem, NULL_RTX, span_offset);
+ span_offset += GET_MODE_SIZE (GET_MODE (elem));
+ }
+ }
break;
default:
}
}
-/* Record call frame debugging information for INSN, which either
- sets SP or FP (adjusting how we calculate the frame address) or saves a
- register to the stack. If INSN is NULL_RTX, initialize our state.
+/* Record call frame debugging information for INSN, which either sets
+ SP or FP (adjusting how we calculate the frame address) or saves a
+ register to the stack. */
- If AFTER_P is false, we're being called before the insn is emitted,
- otherwise after. Call instructions get invoked twice. */
-
-void
-dwarf2out_frame_debug (rtx insn, bool after_p)
+static void
+dwarf2out_frame_debug (rtx_insn *insn)
{
- const char *label;
- rtx note, n;
+ rtx note, n, pat;
bool handled_one = false;
- bool need_flush = false;
-
- if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
- dwarf2out_flush_queued_reg_saves ();
-
- if (!RTX_FRAME_RELATED_P (insn))
- {
- /* ??? This should be done unconditionally since stack adjustments
- matter if the stack pointer is not the CFA register anymore but
- is still used to save registers. */
- if (!ACCUMULATE_OUTGOING_ARGS)
- dwarf2out_notice_stack_adjust (insn, after_p);
- return;
- }
-
- label = dwarf2out_cfi_label (false);
- any_cfis_emitted = false;
for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
switch (REG_NOTE_KIND (note))
{
case REG_FRAME_RELATED_EXPR:
- insn = XEXP (note, 0);
+ pat = XEXP (note, 0);
goto do_frame_expr;
case REG_CFA_DEF_CFA:
- dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
+ dwarf2out_frame_debug_def_cfa (XEXP (note, 0));
handled_one = true;
break;
if (GET_CODE (n) == PARALLEL)
n = XVECEXP (n, 0, 0);
}
- dwarf2out_frame_debug_adjust_cfa (n, label);
+ dwarf2out_frame_debug_adjust_cfa (n);
handled_one = true;
break;
n = XEXP (note, 0);
if (n == NULL)
n = single_set (insn);
- dwarf2out_frame_debug_cfa_offset (n, label);
+ dwarf2out_frame_debug_cfa_offset (n);
handled_one = true;
break;
if (GET_CODE (n) == PARALLEL)
n = XVECEXP (n, 0, 0);
}
- dwarf2out_frame_debug_cfa_register (n, label);
+ dwarf2out_frame_debug_cfa_register (n);
handled_one = true;
break;
n = XEXP (note, 0);
if (n == NULL)
n = single_set (insn);
- dwarf2out_frame_debug_cfa_expression (n, label);
+ dwarf2out_frame_debug_cfa_expression (n);
handled_one = true;
break;
n = XVECEXP (n, 0, 0);
n = XEXP (n, 0);
}
- dwarf2out_frame_debug_cfa_restore (n, label);
+ dwarf2out_frame_debug_cfa_restore (n);
handled_one = true;
break;
n = XEXP (note, 0);
if (REG_P (n))
{
- dw_fde_ref fde = current_fde ();
+ dw_fde_ref fde = cfun->fde;
if (fde)
{
gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
if (REG_P (n))
- fde->vdrap_reg = REGNO (n);
+ fde->vdrap_reg = dwf_regno (n);
}
}
handled_one = true;
break;
case REG_CFA_WINDOW_SAVE:
- dwarf2out_frame_debug_cfa_window_save (label);
+ dwarf2out_frame_debug_cfa_window_save ();
handled_one = true;
break;
case REG_CFA_FLUSH_QUEUE:
- /* The actual flush happens below. */
- need_flush = true;
+ /* The actual flush happens elsewhere. */
handled_one = true;
break;
break;
}
- if (handled_one)
- {
- /* Minimize the number of advances by emitting the entire queue
- once anything is emitted. */
- need_flush |= any_cfis_emitted;
- }
- else
+ if (!handled_one)
{
- insn = PATTERN (insn);
+ pat = PATTERN (insn);
do_frame_expr:
- dwarf2out_frame_debug_expr (insn, label);
+ dwarf2out_frame_debug_expr (pat);
/* Check again. A parallel can save and update the same register.
We could probably check just once, here, but this is safer than
removing the check at the start of the function. */
- if (any_cfis_emitted || clobbers_queued_reg_save (insn))
- need_flush = true;
+ if (clobbers_queued_reg_save (pat))
+ dwarf2out_flush_queued_reg_saves ();
+ }
+}
+
+/* Emit CFI info to change the state from OLD_ROW to NEW_ROW. */
+
+static void
+change_cfi_row (dw_cfi_row *old_row, dw_cfi_row *new_row)
+{
+ size_t i, n_old, n_new, n_max;
+ dw_cfi_ref cfi;
+
+ if (new_row->cfa_cfi && !cfi_equal_p (old_row->cfa_cfi, new_row->cfa_cfi))
+ add_cfi (new_row->cfa_cfi);
+ else
+ {
+ cfi = def_cfa_0 (&old_row->cfa, &new_row->cfa);
+ if (cfi)
+ add_cfi (cfi);
}
- if (need_flush)
- dwarf2out_flush_queued_reg_saves ();
+ n_old = vec_safe_length (old_row->reg_save);
+ n_new = vec_safe_length (new_row->reg_save);
+ n_max = MAX (n_old, n_new);
+
+ for (i = 0; i < n_max; ++i)
+ {
+ dw_cfi_ref r_old = NULL, r_new = NULL;
+
+ if (i < n_old)
+ r_old = (*old_row->reg_save)[i];
+ if (i < n_new)
+ r_new = (*new_row->reg_save)[i];
+
+ if (r_old == r_new)
+ ;
+ else if (r_new == NULL)
+ add_cfi_restore (i);
+ else if (!cfi_equal_p (r_old, r_new))
+ add_cfi (r_new);
+ }
}
-/* Called once at the start of final to initialize some data for the
- current function. */
-void
-dwarf2out_frame_debug_init (void)
+/* Examine CFI and return true if a cfi label and set_loc is needed
+ beforehand. Even when generating CFI assembler instructions, we
+ still have to add the cfi to the list so that lookup_cfa_1 works
+ later on. When -g2 and above we even need to force emitting of
+ CFI labels and add to list a DW_CFA_set_loc for convert_cfa_to_fb_loc_list
+ purposes. If we're generating DWARF3 output we use DW_OP_call_frame_cfa
+ and so don't use convert_cfa_to_fb_loc_list. */
+
+static bool
+cfi_label_required_p (dw_cfi_ref cfi)
{
- /* Flush any queued register saves. */
- dwarf2out_flush_queued_reg_saves ();
+ if (!dwarf2out_do_cfi_asm ())
+ return true;
+
+ if (dwarf_version == 2
+ && debug_info_level > DINFO_LEVEL_TERSE
+ && (write_symbols == DWARF2_DEBUG
+ || write_symbols == VMS_AND_DWARF2_DEBUG))
+ {
+ switch (cfi->dw_cfi_opc)
+ {
+ case DW_CFA_def_cfa_offset:
+ case DW_CFA_def_cfa_offset_sf:
+ case DW_CFA_def_cfa_register:
+ case DW_CFA_def_cfa:
+ case DW_CFA_def_cfa_sf:
+ case DW_CFA_def_cfa_expression:
+ case DW_CFA_restore_state:
+ return true;
+ default:
+ return false;
+ }
+ }
+ return false;
+}
+
+/* Walk the function, looking for NOTE_INSN_CFI notes. Add the CFIs to the
+ function's FDE, adding CFI labels and set_loc/advance_loc opcodes as
+ necessary. */
+static void
+add_cfis_to_fde (void)
+{
+ dw_fde_ref fde = cfun->fde;
+ rtx_insn *insn, *next;
+ /* We always start with a function_begin label. */
+ bool first = false;
+
+ for (insn = get_insns (); insn; insn = next)
+ {
+ next = NEXT_INSN (insn);
+
+ if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
+ {
+ fde->dw_fde_switch_cfi_index = vec_safe_length (fde->dw_fde_cfi);
+ /* Don't attempt to advance_loc4 between labels
+ in different sections. */
+ first = true;
+ }
+
+ if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_CFI)
+ {
+ bool required = cfi_label_required_p (NOTE_CFI (insn));
+ while (next)
+ if (NOTE_P (next) && NOTE_KIND (next) == NOTE_INSN_CFI)
+ {
+ required |= cfi_label_required_p (NOTE_CFI (next));
+ next = NEXT_INSN (next);
+ }
+ else if (active_insn_p (next)
+ || (NOTE_P (next) && (NOTE_KIND (next)
+ == NOTE_INSN_SWITCH_TEXT_SECTIONS)))
+ break;
+ else
+ next = NEXT_INSN (next);
+ if (required)
+ {
+ int num = dwarf2out_cfi_label_num;
+ const char *label = dwarf2out_cfi_label ();
+ dw_cfi_ref xcfi;
+
+ /* Set the location counter to the new label. */
+ xcfi = new_cfi ();
+ xcfi->dw_cfi_opc = (first ? DW_CFA_set_loc
+ : DW_CFA_advance_loc4);
+ xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
+ vec_safe_push (fde->dw_fde_cfi, xcfi);
+
+ rtx_note *tmp = emit_note_before (NOTE_INSN_CFI_LABEL, insn);
+ NOTE_LABEL_NUMBER (tmp) = num;
+ }
+
+ do
+ {
+ if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_CFI)
+ vec_safe_push (fde->dw_fde_cfi, NOTE_CFI (insn));
+ insn = NEXT_INSN (insn);
+ }
+ while (insn != next);
+ first = false;
+ }
+ }
+}
+
+/* If LABEL is the start of a trace, then initialize the state of that
+ trace from CUR_TRACE and CUR_ROW. */
+
+static void
+maybe_record_trace_start (rtx_insn *start, rtx_insn *origin)
+{
+ dw_trace_info *ti;
+ HOST_WIDE_INT args_size;
+
+ ti = get_trace_info (start);
+ gcc_assert (ti != NULL);
- /* Set up state for generating call frame debug info. */
- lookup_cfa (&cfa);
- gcc_assert (cfa.reg
- == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
+ if (dump_file)
+ {
+ fprintf (dump_file, " saw edge from trace %u to %u (via %s %d)\n",
+ cur_trace->id, ti->id,
+ (origin ? rtx_name[(int) GET_CODE (origin)] : "fallthru"),
+ (origin ? INSN_UID (origin) : 0));
+ }
+
+ args_size = cur_trace->end_true_args_size;
+ if (ti->beg_row == NULL)
+ {
+ /* This is the first time we've encountered this trace. Propagate
+ state across the edge and push the trace onto the work list. */
+ ti->beg_row = copy_cfi_row (cur_row);
+ ti->beg_true_args_size = args_size;
- cfa.reg = STACK_POINTER_REGNUM;
- cfa_store = cfa;
- cfa_temp.reg = -1;
- cfa_temp.offset = 0;
+ ti->cfa_store = cur_trace->cfa_store;
+ ti->cfa_temp = cur_trace->cfa_temp;
+ ti->regs_saved_in_regs = cur_trace->regs_saved_in_regs.copy ();
- regs_saved_in_regs = NULL;
+ trace_work_list.safe_push (ti);
- if (barrier_args_size)
+ if (dump_file)
+ fprintf (dump_file, "\tpush trace %u to worklist\n", ti->id);
+ }
+ else
{
- XDELETEVEC (barrier_args_size);
- barrier_args_size = NULL;
+
+ /* We ought to have the same state incoming to a given trace no
+ matter how we arrive at the trace. Anything else means we've
+ got some kind of optimization error. */
+ gcc_checking_assert (cfi_row_equal_p (cur_row, ti->beg_row));
+
+ /* The args_size is allowed to conflict if it isn't actually used. */
+ if (ti->beg_true_args_size != args_size)
+ ti->args_size_undefined = true;
}
}
-/* Determine if we need to save and restore CFI information around this
- epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
- we do need to save/restore, then emit the save now, and insert a
- NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
+/* Similarly, but handle the args_size and CFA reset across EH
+ and non-local goto edges. */
-void
-dwarf2out_cfi_begin_epilogue (rtx insn)
+static void
+maybe_record_trace_start_abnormal (rtx_insn *start, rtx_insn *origin)
+{
+ HOST_WIDE_INT save_args_size, delta;
+ dw_cfa_location save_cfa;
+
+ save_args_size = cur_trace->end_true_args_size;
+ if (save_args_size == 0)
+ {
+ maybe_record_trace_start (start, origin);
+ return;
+ }
+
+ delta = -save_args_size;
+ cur_trace->end_true_args_size = 0;
+
+ save_cfa = cur_row->cfa;
+ if (cur_row->cfa.reg == dw_stack_pointer_regnum)
+ {
+ /* Convert a change in args_size (always a positive in the
+ direction of stack growth) to a change in stack pointer. */
+ if (!STACK_GROWS_DOWNWARD)
+ delta = -delta;
+
+ cur_row->cfa.offset += delta;
+ }
+
+ maybe_record_trace_start (start, origin);
+
+ cur_trace->end_true_args_size = save_args_size;
+ cur_row->cfa = save_cfa;
+}
+
+/* Propagate CUR_TRACE state to the destinations implied by INSN. */
+/* ??? Sadly, this is in large part a duplicate of make_edges. */
+
+static void
+create_trace_edges (rtx_insn *insn)
{
- bool saw_frp = false;
- rtx i;
+ rtx tmp;
+ int i, n;
- /* Scan forward to the return insn, noticing if there are possible
- frame related insns. */
- for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
+ if (JUMP_P (insn))
{
- if (!INSN_P (i))
+ rtx_jump_table_data *table;
+
+ if (find_reg_note (insn, REG_NON_LOCAL_GOTO, NULL_RTX))
+ return;
+
+ if (tablejump_p (insn, NULL, &table))
+ {
+ rtvec vec = table->get_labels ();
+
+ n = GET_NUM_ELEM (vec);
+ for (i = 0; i < n; ++i)
+ {
+ rtx_insn *lab = as_a <rtx_insn *> (XEXP (RTVEC_ELT (vec, i), 0));
+ maybe_record_trace_start (lab, insn);
+ }
+ }
+ else if (computed_jump_p (insn))
+ {
+ for (rtx_insn_list *lab = forced_labels; lab; lab = lab->next ())
+ maybe_record_trace_start (lab->insn (), insn);
+ }
+ else if (returnjump_p (insn))
+ ;
+ else if ((tmp = extract_asm_operands (PATTERN (insn))) != NULL)
+ {
+ n = ASM_OPERANDS_LABEL_LENGTH (tmp);
+ for (i = 0; i < n; ++i)
+ {
+ rtx_insn *lab =
+ as_a <rtx_insn *> (XEXP (ASM_OPERANDS_LABEL (tmp, i), 0));
+ maybe_record_trace_start (lab, insn);
+ }
+ }
+ else
+ {
+ rtx_insn *lab = JUMP_LABEL_AS_INSN (insn);
+ gcc_assert (lab != NULL);
+ maybe_record_trace_start (lab, insn);
+ }
+ }
+ else if (CALL_P (insn))
+ {
+ /* Sibling calls don't have edges inside this function. */
+ if (SIBLING_CALL_P (insn))
+ return;
+
+ /* Process non-local goto edges. */
+ if (can_nonlocal_goto (insn))
+ for (rtx_insn_list *lab = nonlocal_goto_handler_labels;
+ lab;
+ lab = lab->next ())
+ maybe_record_trace_start_abnormal (lab->insn (), insn);
+ }
+ else if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
+ {
+ int i, n = seq->len ();
+ for (i = 0; i < n; ++i)
+ create_trace_edges (seq->insn (i));
+ return;
+ }
+
+ /* Process EH edges. */
+ if (CALL_P (insn) || cfun->can_throw_non_call_exceptions)
+ {
+ eh_landing_pad lp = get_eh_landing_pad_from_rtx (insn);
+ if (lp)
+ maybe_record_trace_start_abnormal (lp->landing_pad, insn);
+ }
+}
+
+/* A subroutine of scan_trace. Do what needs to be done "after" INSN. */
+
+static void
+scan_insn_after (rtx_insn *insn)
+{
+ if (RTX_FRAME_RELATED_P (insn))
+ dwarf2out_frame_debug (insn);
+ notice_args_size (insn);
+}
+
+/* Scan the trace beginning at INSN and create the CFI notes for the
+ instructions therein. */
+
+static void
+scan_trace (dw_trace_info *trace)
+{
+ rtx_insn *prev, *insn = trace->head;
+ dw_cfa_location this_cfa;
+
+ if (dump_file)
+ fprintf (dump_file, "Processing trace %u : start at %s %d\n",
+ trace->id, rtx_name[(int) GET_CODE (insn)],
+ INSN_UID (insn));
+
+ trace->end_row = copy_cfi_row (trace->beg_row);
+ trace->end_true_args_size = trace->beg_true_args_size;
+
+ cur_trace = trace;
+ cur_row = trace->end_row;
+
+ this_cfa = cur_row->cfa;
+ cur_cfa = &this_cfa;
+
+ for (prev = insn, insn = NEXT_INSN (insn);
+ insn;
+ prev = insn, insn = NEXT_INSN (insn))
+ {
+ rtx_insn *control;
+
+ /* Do everything that happens "before" the insn. */
+ add_cfi_insn = prev;
+
+ /* Notice the end of a trace. */
+ if (BARRIER_P (insn))
+ {
+ /* Don't bother saving the unneeded queued registers at all. */
+ queued_reg_saves.truncate (0);
+ break;
+ }
+ if (save_point_p (insn))
+ {
+ /* Propagate across fallthru edges. */
+ dwarf2out_flush_queued_reg_saves ();
+ maybe_record_trace_start (insn, NULL);
+ break;
+ }
+
+ if (DEBUG_INSN_P (insn) || !inside_basic_block_p (insn))
continue;
- /* Look for both regular and sibcalls to end the block. */
- if (returnjump_p (i))
- break;
- if (CALL_P (i) && SIBLING_CALL_P (i))
- break;
+ /* Handle all changes to the row state. Sequences require special
+ handling for the positioning of the notes. */
+ if (rtx_sequence *pat = dyn_cast <rtx_sequence *> (PATTERN (insn)))
+ {
+ rtx_insn *elt;
+ int i, n = pat->len ();
+
+ control = pat->insn (0);
+ if (can_throw_internal (control))
+ notice_eh_throw (control);
+ dwarf2out_flush_queued_reg_saves ();
+
+ if (JUMP_P (control) && INSN_ANNULLED_BRANCH_P (control))
+ {
+ /* ??? Hopefully multiple delay slots are not annulled. */
+ gcc_assert (n == 2);
+ gcc_assert (!RTX_FRAME_RELATED_P (control));
+ gcc_assert (!find_reg_note (control, REG_ARGS_SIZE, NULL));
+
+ elt = pat->insn (1);
+
+ if (INSN_FROM_TARGET_P (elt))
+ {
+ HOST_WIDE_INT restore_args_size;
+ cfi_vec save_row_reg_save;
+
+ /* If ELT is an instruction from target of an annulled
+ branch, the effects are for the target only and so
+ the args_size and CFA along the current path
+ shouldn't change. */
+ add_cfi_insn = NULL;
+ restore_args_size = cur_trace->end_true_args_size;
+ cur_cfa = &cur_row->cfa;
+ save_row_reg_save = vec_safe_copy (cur_row->reg_save);
+
+ scan_insn_after (elt);
+
+ /* ??? Should we instead save the entire row state? */
+ gcc_assert (!queued_reg_saves.length ());
- if (GET_CODE (PATTERN (i)) == SEQUENCE)
+ create_trace_edges (control);
+
+ cur_trace->end_true_args_size = restore_args_size;
+ cur_row->cfa = this_cfa;
+ cur_row->reg_save = save_row_reg_save;
+ cur_cfa = &this_cfa;
+ }
+ else
+ {
+ /* If ELT is a annulled branch-taken instruction (i.e.
+ executed only when branch is not taken), the args_size
+ and CFA should not change through the jump. */
+ create_trace_edges (control);
+
+ /* Update and continue with the trace. */
+ add_cfi_insn = insn;
+ scan_insn_after (elt);
+ def_cfa_1 (&this_cfa);
+ }
+ continue;
+ }
+
+ /* The insns in the delay slot should all be considered to happen
+ "before" a call insn. Consider a call with a stack pointer
+ adjustment in the delay slot. The backtrace from the callee
+ should include the sp adjustment. Unfortunately, that leaves
+ us with an unavoidable unwinding error exactly at the call insn
+ itself. For jump insns we'd prefer to avoid this error by
+ placing the notes after the sequence. */
+ if (JUMP_P (control))
+ add_cfi_insn = insn;
+
+ for (i = 1; i < n; ++i)
+ {
+ elt = pat->insn (i);
+ scan_insn_after (elt);
+ }
+
+ /* Make sure any register saves are visible at the jump target. */
+ dwarf2out_flush_queued_reg_saves ();
+ any_cfis_emitted = false;
+
+ /* However, if there is some adjustment on the call itself, e.g.
+ a call_pop, that action should be considered to happen after
+ the call returns. */
+ add_cfi_insn = insn;
+ scan_insn_after (control);
+ }
+ else
{
- int idx;
- rtx seq = PATTERN (i);
-
- if (returnjump_p (XVECEXP (seq, 0, 0)))
- break;
- if (CALL_P (XVECEXP (seq, 0, 0))
- && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
- break;
-
- for (idx = 0; idx < XVECLEN (seq, 0); idx++)
- if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
- saw_frp = true;
+ /* Flush data before calls and jumps, and of course if necessary. */
+ if (can_throw_internal (insn))
+ {
+ notice_eh_throw (insn);
+ dwarf2out_flush_queued_reg_saves ();
+ }
+ else if (!NONJUMP_INSN_P (insn)
+ || clobbers_queued_reg_save (insn)
+ || find_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL))
+ dwarf2out_flush_queued_reg_saves ();
+ any_cfis_emitted = false;
+
+ add_cfi_insn = insn;
+ scan_insn_after (insn);
+ control = insn;
}
- if (RTX_FRAME_RELATED_P (i))
- saw_frp = true;
+ /* Between frame-related-p and args_size we might have otherwise
+ emitted two cfa adjustments. Do it now. */
+ def_cfa_1 (&this_cfa);
+
+ /* Minimize the number of advances by emitting the entire queue
+ once anything is emitted. */
+ if (any_cfis_emitted
+ || find_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL))
+ dwarf2out_flush_queued_reg_saves ();
+
+ /* Note that a test for control_flow_insn_p does exactly the
+ same tests as are done to actually create the edges. So
+ always call the routine and let it not create edges for
+ non-control-flow insns. */
+ create_trace_edges (control);
}
- /* If the port doesn't emit epilogue unwind info, we don't need a
- save/restore pair. */
- if (!saw_frp)
- return;
+ add_cfi_insn = NULL;
+ cur_row = NULL;
+ cur_trace = NULL;
+ cur_cfa = NULL;
+}
- /* Otherwise, search forward to see if the return insn was the last
- basic block of the function. If so, we don't need save/restore. */
- gcc_assert (i != NULL);
- i = next_real_insn (i);
- if (i == NULL)
- return;
+/* Scan the function and create the initial set of CFI notes. */
+
+static void
+create_cfi_notes (void)
+{
+ dw_trace_info *ti;
+
+ gcc_checking_assert (!queued_reg_saves.exists ());
+ gcc_checking_assert (!trace_work_list.exists ());
- /* Insert the restore before that next real insn in the stream, and before
- a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
- properly nested. This should be after any label or alignment. This
- will be pushed into the CFI stream by the function below. */
- while (1)
+ /* Always begin at the entry trace. */
+ ti = &trace_info[0];
+ scan_trace (ti);
+
+ while (!trace_work_list.is_empty ())
{
- rtx p = PREV_INSN (i);
- if (!NOTE_P (p))
- break;
- if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
- break;
- i = p;
+ ti = trace_work_list.pop ();
+ scan_trace (ti);
}
- emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
- emit_cfa_remember = true;
+ queued_reg_saves.release ();
+ trace_work_list.release ();
+}
+
+/* Return the insn before the first NOTE_INSN_CFI after START. */
- /* And emulate the state save. */
- gcc_assert (!cfa_remember.in_use);
- cfa_remember = cfa;
- cfa_remember.in_use = 1;
+static rtx_insn *
+before_next_cfi_note (rtx_insn *start)
+{
+ rtx_insn *prev = start;
+ while (start)
+ {
+ if (NOTE_P (start) && NOTE_KIND (start) == NOTE_INSN_CFI)
+ return prev;
+ prev = start;
+ start = NEXT_INSN (start);
+ }
+ gcc_unreachable ();
}
-/* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
- required. */
+/* Insert CFI notes between traces to properly change state between them. */
-void
-dwarf2out_frame_debug_restore_state (void)
+static void
+connect_traces (void)
{
- dw_cfi_ref cfi = new_cfi ();
- const char *label = dwarf2out_cfi_label (false);
+ unsigned i, n = trace_info.length ();
+ dw_trace_info *prev_ti, *ti;
+
+ /* ??? Ideally, we should have both queued and processed every trace.
+ However the current representation of constant pools on various targets
+ is indistinguishable from unreachable code. Assume for the moment that
+ we can simply skip over such traces. */
+ /* ??? Consider creating a DATA_INSN rtx code to indicate that
+ these are not "real" instructions, and should not be considered.
+ This could be generically useful for tablejump data as well. */
+ /* Remove all unprocessed traces from the list. */
+ for (i = n - 1; i > 0; --i)
+ {
+ ti = &trace_info[i];
+ if (ti->beg_row == NULL)
+ {
+ trace_info.ordered_remove (i);
+ n -= 1;
+ }
+ else
+ gcc_assert (ti->end_row != NULL);
+ }
+
+ /* Work from the end back to the beginning. This lets us easily insert
+ remember/restore_state notes in the correct order wrt other notes. */
+ prev_ti = &trace_info[n - 1];
+ for (i = n - 1; i > 0; --i)
+ {
+ dw_cfi_row *old_row;
+
+ ti = prev_ti;
+ prev_ti = &trace_info[i - 1];
+
+ add_cfi_insn = ti->head;
+
+ /* In dwarf2out_switch_text_section, we'll begin a new FDE
+ for the portion of the function in the alternate text
+ section. The row state at the very beginning of that
+ new FDE will be exactly the row state from the CIE. */
+ if (ti->switch_sections)
+ old_row = cie_cfi_row;
+ else
+ {
+ old_row = prev_ti->end_row;
+ /* If there's no change from the previous end state, fine. */
+ if (cfi_row_equal_p (old_row, ti->beg_row))
+ ;
+ /* Otherwise check for the common case of sharing state with
+ the beginning of an epilogue, but not the end. Insert
+ remember/restore opcodes in that case. */
+ else if (cfi_row_equal_p (prev_ti->beg_row, ti->beg_row))
+ {
+ dw_cfi_ref cfi;
+
+ /* Note that if we blindly insert the remember at the
+ start of the trace, we can wind up increasing the
+ size of the unwind info due to extra advance opcodes.
+ Instead, put the remember immediately before the next
+ state change. We know there must be one, because the
+ state at the beginning and head of the trace differ. */
+ add_cfi_insn = before_next_cfi_note (prev_ti->head);
+ cfi = new_cfi ();
+ cfi->dw_cfi_opc = DW_CFA_remember_state;
+ add_cfi (cfi);
+
+ add_cfi_insn = ti->head;
+ cfi = new_cfi ();
+ cfi->dw_cfi_opc = DW_CFA_restore_state;
+ add_cfi (cfi);
+
+ old_row = prev_ti->beg_row;
+ }
+ /* Otherwise, we'll simply change state from the previous end. */
+ }
+
+ change_cfi_row (old_row, ti->beg_row);
+
+ if (dump_file && add_cfi_insn != ti->head)
+ {
+ rtx_insn *note;
+
+ fprintf (dump_file, "Fixup between trace %u and %u:\n",
+ prev_ti->id, ti->id);
+
+ note = ti->head;
+ do
+ {
+ note = NEXT_INSN (note);
+ gcc_assert (NOTE_P (note) && NOTE_KIND (note) == NOTE_INSN_CFI);
+ output_cfi_directive (dump_file, NOTE_CFI (note));
+ }
+ while (note != add_cfi_insn);
+ }
+ }
+
+ /* Connect args_size between traces that have can_throw_internal insns. */
+ if (cfun->eh->lp_array)
+ {
+ HOST_WIDE_INT prev_args_size = 0;
+
+ for (i = 0; i < n; ++i)
+ {
+ ti = &trace_info[i];
+
+ if (ti->switch_sections)
+ prev_args_size = 0;
+ if (ti->eh_head == NULL)
+ continue;
+ gcc_assert (!ti->args_size_undefined);
- cfi->dw_cfi_opc = DW_CFA_restore_state;
- add_fde_cfi (label, cfi);
+ if (ti->beg_delay_args_size != prev_args_size)
+ {
+ /* ??? Search back to previous CFI note. */
+ add_cfi_insn = PREV_INSN (ti->eh_head);
+ add_cfi_args_size (ti->beg_delay_args_size);
+ }
- gcc_assert (cfa_remember.in_use);
- cfa = cfa_remember;
- cfa_remember.in_use = 0;
+ prev_args_size = ti->end_delay_args_size;
+ }
+ }
}
-/* Run once per function. */
+/* Set up the pseudo-cfg of instruction traces, as described at the
+ block comment at the top of the file. */
-void
-dwarf2cfi_function_init (void)
+static void
+create_pseudo_cfg (void)
{
- args_size = old_args_size = 0;
+ bool saw_barrier, switch_sections;
+ dw_trace_info ti;
+ rtx_insn *insn;
+ unsigned i;
+
+ /* The first trace begins at the start of the function,
+ and begins with the CIE row state. */
+ trace_info.create (16);
+ memset (&ti, 0, sizeof (ti));
+ ti.head = get_insns ();
+ ti.beg_row = cie_cfi_row;
+ ti.cfa_store = cie_cfi_row->cfa;
+ ti.cfa_temp.reg = INVALID_REGNUM;
+ trace_info.quick_push (ti);
+
+ if (cie_return_save)
+ ti.regs_saved_in_regs.safe_push (*cie_return_save);
+
+ /* Walk all the insns, collecting start of trace locations. */
+ saw_barrier = false;
+ switch_sections = false;
+ for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
+ {
+ if (BARRIER_P (insn))
+ saw_barrier = true;
+ else if (NOTE_P (insn)
+ && NOTE_KIND (insn) == NOTE_INSN_SWITCH_TEXT_SECTIONS)
+ {
+ /* We should have just seen a barrier. */
+ gcc_assert (saw_barrier);
+ switch_sections = true;
+ }
+ /* Watch out for save_point notes between basic blocks.
+ In particular, a note after a barrier. Do not record these,
+ delaying trace creation until the label. */
+ else if (save_point_p (insn)
+ && (LABEL_P (insn) || !saw_barrier))
+ {
+ memset (&ti, 0, sizeof (ti));
+ ti.head = insn;
+ ti.switch_sections = switch_sections;
+ ti.id = trace_info.length ();
+ trace_info.safe_push (ti);
+
+ saw_barrier = false;
+ switch_sections = false;
+ }
+ }
+
+ /* Create the trace index after we've finished building trace_info,
+ avoiding stale pointer problems due to reallocation. */
+ trace_index
+ = new hash_table<trace_info_hasher> (trace_info.length ());
+ dw_trace_info *tp;
+ FOR_EACH_VEC_ELT (trace_info, i, tp)
+ {
+ dw_trace_info **slot;
+
+ if (dump_file)
+ fprintf (dump_file, "Creating trace %u : start at %s %d%s\n", tp->id,
+ rtx_name[(int) GET_CODE (tp->head)], INSN_UID (tp->head),
+ tp->switch_sections ? " (section switch)" : "");
+
+ slot = trace_index->find_slot_with_hash (tp, INSN_UID (tp->head), INSERT);
+ gcc_assert (*slot == NULL);
+ *slot = tp;
+ }
}
-/* Run once. */
+/* Record the initial position of the return address. RTL is
+ INCOMING_RETURN_ADDR_RTX. */
-void
-dwarf2cfi_frame_init (void)
+static void
+initial_return_save (rtx rtl)
+{
+ unsigned int reg = INVALID_REGNUM;
+ HOST_WIDE_INT offset = 0;
+
+ switch (GET_CODE (rtl))
+ {
+ case REG:
+ /* RA is in a register. */
+ reg = dwf_regno (rtl);
+ break;
+
+ case MEM:
+ /* RA is on the stack. */
+ rtl = XEXP (rtl, 0);
+ switch (GET_CODE (rtl))
+ {
+ case REG:
+ gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
+ offset = 0;
+ break;
+
+ case PLUS:
+ gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
+ offset = INTVAL (XEXP (rtl, 1));
+ break;
+
+ case MINUS:
+ gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
+ offset = -INTVAL (XEXP (rtl, 1));
+ break;
+
+ default:
+ gcc_unreachable ();
+ }
+
+ break;
+
+ case PLUS:
+ /* The return address is at some offset from any value we can
+ actually load. For instance, on the SPARC it is in %i7+8. Just
+ ignore the offset for now; it doesn't matter for unwinding frames. */
+ gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
+ initial_return_save (XEXP (rtl, 0));
+ return;
+
+ default:
+ gcc_unreachable ();
+ }
+
+ if (reg != DWARF_FRAME_RETURN_COLUMN)
+ {
+ if (reg != INVALID_REGNUM)
+ record_reg_saved_in_reg (rtl, pc_rtx);
+ reg_save (DWARF_FRAME_RETURN_COLUMN, reg, offset - cur_row->cfa.offset);
+ }
+}
+
+static void
+create_cie_data (void)
{
dw_cfa_location loc;
+ dw_trace_info cie_trace;
+
+ dw_stack_pointer_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
+
+ memset (&cie_trace, 0, sizeof (cie_trace));
+ cur_trace = &cie_trace;
- /* Generate the CFA instructions common to all FDE's. Do it now for the
- sake of lookup_cfa. */
+ add_cfi_vec = &cie_cfi_vec;
+ cie_cfi_row = cur_row = new_cfi_row ();
/* On entry, the Canonical Frame Address is at SP. */
- memset(&loc, 0, sizeof (loc));
- loc.reg = STACK_POINTER_REGNUM;
+ memset (&loc, 0, sizeof (loc));
+ loc.reg = dw_stack_pointer_regnum;
loc.offset = INCOMING_FRAME_SP_OFFSET;
- def_cfa_1 (NULL, &loc);
+ def_cfa_1 (&loc);
if (targetm.debug_unwind_info () == UI_DWARF2
|| targetm_common.except_unwind_info (&global_options) == UI_DWARF2)
- initial_return_save (INCOMING_RETURN_ADDR_RTX);
+ {
+ initial_return_save (INCOMING_RETURN_ADDR_RTX);
+
+ /* For a few targets, we have the return address incoming into a
+ register, but choose a different return column. This will result
+ in a DW_CFA_register for the return, and an entry in
+ regs_saved_in_regs to match. If the target later stores that
+ return address register to the stack, we want to be able to emit
+ the DW_CFA_offset against the return column, not the intermediate
+ save register. Save the contents of regs_saved_in_regs so that
+ we can re-initialize it at the start of each function. */
+ switch (cie_trace.regs_saved_in_regs.length ())
+ {
+ case 0:
+ break;
+ case 1:
+ cie_return_save = ggc_alloc<reg_saved_in_data> ();
+ *cie_return_save = cie_trace.regs_saved_in_regs[0];
+ cie_trace.regs_saved_in_regs.release ();
+ break;
+ default:
+ gcc_unreachable ();
+ }
+ }
+
+ add_cfi_vec = NULL;
+ cur_row = NULL;
+ cur_trace = NULL;
+}
+
+/* Annotate the function with NOTE_INSN_CFI notes to record the CFI
+ state at each location within the function. These notes will be
+ emitted during pass_final. */
+
+static unsigned int
+execute_dwarf2_frame (void)
+{
+ /* Different HARD_FRAME_POINTER_REGNUM might coexist in the same file. */
+ dw_frame_pointer_regnum = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
+
+ /* The first time we're called, compute the incoming frame state. */
+ if (cie_cfi_vec == NULL)
+ create_cie_data ();
+
+ dwarf2out_alloc_current_fde ();
+
+ create_pseudo_cfg ();
+
+ /* Do the work. */
+ create_cfi_notes ();
+ connect_traces ();
+ add_cfis_to_fde ();
+
+ /* Free all the data we allocated. */
+ {
+ size_t i;
+ dw_trace_info *ti;
+
+ FOR_EACH_VEC_ELT (trace_info, i, ti)
+ ti->regs_saved_in_regs.release ();
+ }
+ trace_info.release ();
+
+ delete trace_index;
+ trace_index = NULL;
+
+ return 0;
+}
+\f
+/* Convert a DWARF call frame info. operation to its string name */
+
+static const char *
+dwarf_cfi_name (unsigned int cfi_opc)
+{
+ const char *name = get_DW_CFA_name (cfi_opc);
+
+ if (name != NULL)
+ return name;
+
+ return "DW_CFA_<unknown>";
+}
+
+/* This routine will generate the correct assembly data for a location
+ description based on a cfi entry with a complex address. */
+
+static void
+output_cfa_loc (dw_cfi_ref cfi, int for_eh)
+{
+ dw_loc_descr_ref loc;
+ unsigned long size;
+
+ if (cfi->dw_cfi_opc == DW_CFA_expression)
+ {
+ unsigned r =
+ DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data (1, r, NULL);
+ loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
+ }
+ else
+ loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
+
+ /* Output the size of the block. */
+ size = size_of_locs (loc);
+ dw2_asm_output_data_uleb128 (size, NULL);
+
+ /* Now output the operations themselves. */
+ output_loc_sequence (loc, for_eh);
+}
+
+/* Similar, but used for .cfi_escape. */
+
+static void
+output_cfa_loc_raw (dw_cfi_ref cfi)
+{
+ dw_loc_descr_ref loc;
+ unsigned long size;
+
+ if (cfi->dw_cfi_opc == DW_CFA_expression)
+ {
+ unsigned r =
+ DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
+ fprintf (asm_out_file, "%#x,", r);
+ loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
+ }
+ else
+ loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
+
+ /* Output the size of the block. */
+ size = size_of_locs (loc);
+ dw2_asm_output_data_uleb128_raw (size);
+ fputc (',', asm_out_file);
+
+ /* Now output the operations themselves. */
+ output_loc_sequence_raw (loc);
+}
+
+/* Output a Call Frame Information opcode and its operand(s). */
+
+void
+output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
+{
+ unsigned long r;
+ HOST_WIDE_INT off;
+
+ if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
+ dw2_asm_output_data (1, (cfi->dw_cfi_opc
+ | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
+ "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
+ ((unsigned HOST_WIDE_INT)
+ cfi->dw_cfi_oprnd1.dw_cfi_offset));
+ else if (cfi->dw_cfi_opc == DW_CFA_offset)
+ {
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
+ "DW_CFA_offset, column %#lx", r);
+ off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
+ dw2_asm_output_data_uleb128 (off, NULL);
+ }
+ else if (cfi->dw_cfi_opc == DW_CFA_restore)
+ {
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
+ "DW_CFA_restore, column %#lx", r);
+ }
+ else
+ {
+ dw2_asm_output_data (1, cfi->dw_cfi_opc,
+ "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
+
+ switch (cfi->dw_cfi_opc)
+ {
+ case DW_CFA_set_loc:
+ if (for_eh)
+ dw2_asm_output_encoded_addr_rtx (
+ ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
+ gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
+ false, NULL);
+ else
+ dw2_asm_output_addr (DWARF2_ADDR_SIZE,
+ cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
+ fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
+ break;
+
+ case DW_CFA_advance_loc1:
+ dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
+ fde->dw_fde_current_label, NULL);
+ fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
+ break;
+
+ case DW_CFA_advance_loc2:
+ dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
+ fde->dw_fde_current_label, NULL);
+ fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
+ break;
+
+ case DW_CFA_advance_loc4:
+ dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
+ fde->dw_fde_current_label, NULL);
+ fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
+ break;
+
+ case DW_CFA_MIPS_advance_loc8:
+ dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
+ fde->dw_fde_current_label, NULL);
+ fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
+ break;
+
+ case DW_CFA_offset_extended:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data_uleb128 (r, NULL);
+ off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
+ dw2_asm_output_data_uleb128 (off, NULL);
+ break;
+
+ case DW_CFA_def_cfa:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data_uleb128 (r, NULL);
+ dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
+ break;
+
+ case DW_CFA_offset_extended_sf:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data_uleb128 (r, NULL);
+ off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
+ dw2_asm_output_data_sleb128 (off, NULL);
+ break;
+
+ case DW_CFA_def_cfa_sf:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data_uleb128 (r, NULL);
+ off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
+ dw2_asm_output_data_sleb128 (off, NULL);
+ break;
+
+ case DW_CFA_restore_extended:
+ case DW_CFA_undefined:
+ case DW_CFA_same_value:
+ case DW_CFA_def_cfa_register:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data_uleb128 (r, NULL);
+ break;
+
+ case DW_CFA_register:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data_uleb128 (r, NULL);
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
+ dw2_asm_output_data_uleb128 (r, NULL);
+ break;
+
+ case DW_CFA_def_cfa_offset:
+ case DW_CFA_GNU_args_size:
+ dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
+ break;
+
+ case DW_CFA_def_cfa_offset_sf:
+ off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
+ dw2_asm_output_data_sleb128 (off, NULL);
+ break;
+
+ case DW_CFA_GNU_window_save:
+ break;
+
+ case DW_CFA_def_cfa_expression:
+ case DW_CFA_expression:
+ output_cfa_loc (cfi, for_eh);
+ break;
+
+ case DW_CFA_GNU_negative_offset_extended:
+ /* Obsoleted by DW_CFA_offset_extended_sf. */
+ gcc_unreachable ();
+
+ default:
+ break;
+ }
+ }
+}
+
+/* Similar, but do it via assembler directives instead. */
+
+void
+output_cfi_directive (FILE *f, dw_cfi_ref cfi)
+{
+ unsigned long r, r2;
+
+ switch (cfi->dw_cfi_opc)
+ {
+ case DW_CFA_advance_loc:
+ case DW_CFA_advance_loc1:
+ case DW_CFA_advance_loc2:
+ case DW_CFA_advance_loc4:
+ case DW_CFA_MIPS_advance_loc8:
+ case DW_CFA_set_loc:
+ /* Should only be created in a code path not followed when emitting
+ via directives. The assembler is going to take care of this for
+ us. But this routines is also used for debugging dumps, so
+ print something. */
+ gcc_assert (f != asm_out_file);
+ fprintf (f, "\t.cfi_advance_loc\n");
+ break;
+
+ case DW_CFA_offset:
+ case DW_CFA_offset_extended:
+ case DW_CFA_offset_extended_sf:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
+ fprintf (f, "\t.cfi_offset %lu, " HOST_WIDE_INT_PRINT_DEC"\n",
+ r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
+ break;
+
+ case DW_CFA_restore:
+ case DW_CFA_restore_extended:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
+ fprintf (f, "\t.cfi_restore %lu\n", r);
+ break;
+
+ case DW_CFA_undefined:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
+ fprintf (f, "\t.cfi_undefined %lu\n", r);
+ break;
+
+ case DW_CFA_same_value:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
+ fprintf (f, "\t.cfi_same_value %lu\n", r);
+ break;
+
+ case DW_CFA_def_cfa:
+ case DW_CFA_def_cfa_sf:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
+ fprintf (f, "\t.cfi_def_cfa %lu, " HOST_WIDE_INT_PRINT_DEC"\n",
+ r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
+ break;
+
+ case DW_CFA_def_cfa_register:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
+ fprintf (f, "\t.cfi_def_cfa_register %lu\n", r);
+ break;
+
+ case DW_CFA_register:
+ r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
+ r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
+ fprintf (f, "\t.cfi_register %lu, %lu\n", r, r2);
+ break;
+
+ case DW_CFA_def_cfa_offset:
+ case DW_CFA_def_cfa_offset_sf:
+ fprintf (f, "\t.cfi_def_cfa_offset "
+ HOST_WIDE_INT_PRINT_DEC"\n",
+ cfi->dw_cfi_oprnd1.dw_cfi_offset);
+ break;
+
+ case DW_CFA_remember_state:
+ fprintf (f, "\t.cfi_remember_state\n");
+ break;
+ case DW_CFA_restore_state:
+ fprintf (f, "\t.cfi_restore_state\n");
+ break;
+
+ case DW_CFA_GNU_args_size:
+ if (f == asm_out_file)
+ {
+ fprintf (f, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
+ dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
+ if (flag_debug_asm)
+ fprintf (f, "\t%s args_size " HOST_WIDE_INT_PRINT_DEC,
+ ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
+ fputc ('\n', f);
+ }
+ else
+ {
+ fprintf (f, "\t.cfi_GNU_args_size " HOST_WIDE_INT_PRINT_DEC "\n",
+ cfi->dw_cfi_oprnd1.dw_cfi_offset);
+ }
+ break;
+
+ case DW_CFA_GNU_window_save:
+ fprintf (f, "\t.cfi_window_save\n");
+ break;
+
+ case DW_CFA_def_cfa_expression:
+ if (f != asm_out_file)
+ {
+ fprintf (f, "\t.cfi_def_cfa_expression ...\n");
+ break;
+ }
+ /* FALLTHRU */
+ case DW_CFA_expression:
+ if (f != asm_out_file)
+ {
+ fprintf (f, "\t.cfi_cfa_expression ...\n");
+ break;
+ }
+ fprintf (f, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
+ output_cfa_loc_raw (cfi);
+ fputc ('\n', f);
+ break;
+
+ default:
+ gcc_unreachable ();
+ }
+}
+
+void
+dwarf2out_emit_cfi (dw_cfi_ref cfi)
+{
+ if (dwarf2out_do_cfi_asm ())
+ output_cfi_directive (asm_out_file, cfi);
+}
+
+static void
+dump_cfi_row (FILE *f, dw_cfi_row *row)
+{
+ dw_cfi_ref cfi;
+ unsigned i;
+
+ cfi = row->cfa_cfi;
+ if (!cfi)
+ {
+ dw_cfa_location dummy;
+ memset (&dummy, 0, sizeof (dummy));
+ dummy.reg = INVALID_REGNUM;
+ cfi = def_cfa_0 (&dummy, &row->cfa);
+ }
+ output_cfi_directive (f, cfi);
+
+ FOR_EACH_VEC_SAFE_ELT (row->reg_save, i, cfi)
+ if (cfi)
+ output_cfi_directive (f, cfi);
+}
+
+void debug_cfi_row (dw_cfi_row *row);
+
+void
+debug_cfi_row (dw_cfi_row *row)
+{
+ dump_cfi_row (stderr, row);
}
\f
-/* Save the result of dwarf2out_do_frame across PCH. */
-static GTY(()) bool saved_do_cfi_asm = 0;
+/* Save the result of dwarf2out_do_frame across PCH.
+ This variable is tri-state, with 0 unset, >0 true, <0 false. */
+static GTY(()) signed char saved_do_cfi_asm = 0;
/* Decide whether we want to emit frame unwind information for the current
translation unit. */
-int
+bool
dwarf2out_do_frame (void)
{
/* We want to emit correct CFA location expressions or lists, so we
if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
return true;
- if (saved_do_cfi_asm)
+ if (saved_do_cfi_asm > 0)
return true;
if (targetm.debug_unwind_info () == UI_DWARF2)
/* Decide whether to emit frame unwind via assembler directives. */
-int
+bool
dwarf2out_do_cfi_asm (void)
{
int enc;
-#ifdef MIPS_DEBUGGING_INFO
- return false;
-#endif
- if (saved_do_cfi_asm)
- return true;
+ if (saved_do_cfi_asm != 0)
+ return saved_do_cfi_asm > 0;
+
+ /* Assume failure for a moment. */
+ saved_do_cfi_asm = -1;
+
if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
return false;
if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
&& targetm_common.except_unwind_info (&global_options) != UI_DWARF2)
return false;
- saved_do_cfi_asm = true;
+ /* Success! */
+ saved_do_cfi_asm = 1;
return true;
}
+namespace {
+
+const pass_data pass_data_dwarf2_frame =
+{
+ RTL_PASS, /* type */
+ "dwarf2", /* name */
+ OPTGROUP_NONE, /* optinfo_flags */
+ TV_FINAL, /* tv_id */
+ 0, /* properties_required */
+ 0, /* properties_provided */
+ 0, /* properties_destroyed */
+ 0, /* todo_flags_start */
+ 0, /* todo_flags_finish */
+};
+
+class pass_dwarf2_frame : public rtl_opt_pass
+{
+public:
+ pass_dwarf2_frame (gcc::context *ctxt)
+ : rtl_opt_pass (pass_data_dwarf2_frame, ctxt)
+ {}
+
+ /* opt_pass methods: */
+ virtual bool gate (function *);
+ virtual unsigned int execute (function *) { return execute_dwarf2_frame (); }
+
+}; // class pass_dwarf2_frame
+
+bool
+pass_dwarf2_frame::gate (function *)
+{
+#ifndef HAVE_prologue
+ /* Targets which still implement the prologue in assembler text
+ cannot use the generic dwarf2 unwinding. */
+ return false;
+#endif
+
+ /* ??? What to do for UI_TARGET unwinding? They might be able to benefit
+ from the optimized shrink-wrapping annotations that we will compute.
+ For now, only produce the CFI notes for dwarf2. */
+ return dwarf2out_do_frame ();
+}
+
+} // anon namespace
+
+rtl_opt_pass *
+make_pass_dwarf2_frame (gcc::context *ctxt)
+{
+ return new pass_dwarf2_frame (ctxt);
+}
+
#include "gt-dwarf2cfi.h"