From 645ddf5d99bd4d656b0a381a3ba49c87ea7a63cf Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 19 Oct 2018 06:51:38 -0400 Subject: [PATCH 2/9] FIXME: eliminate usage of cfun in var-tracking.c --- gcc/final.c | 2 +- gcc/rtl.h | 2 +- gcc/var-tracking.c | 168 +++++++++++++++++++++++++++-------------------------- 3 files changed, 89 insertions(+), 83 deletions(-) diff --git a/gcc/final.c b/gcc/final.c index 6e61f1e..c4131c0 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -4640,7 +4640,7 @@ rest_of_handle_final (void) /* Turn debug markers into notes if the var-tracking pass has not been invoked. */ if (!flag_var_tracking && MAY_HAVE_DEBUG_MARKER_INSNS) - delete_vta_debug_insns (false); + delete_vta_debug_insns (cfun, false); assemble_start_function (current_function_decl, fnname); rtx_insn *first = get_insns (); diff --git a/gcc/rtl.h b/gcc/rtl.h index 68d3cea..7a49895 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -4275,7 +4275,7 @@ extern GTY(()) rtx stack_limit_rtx; /* In var-tracking.c */ extern unsigned int variable_tracking_main (void); -extern void delete_vta_debug_insns (bool); +extern void delete_vta_debug_insns (function *, bool); /* In stor-layout.c. */ extern void get_mode_bounds (scalar_int_mode, int, diff --git a/gcc/var-tracking.c b/gcc/var-tracking.c index 5537fa6..4e09ab3 100644 --- a/gcc/var-tracking.c +++ b/gcc/var-tracking.c @@ -117,6 +117,12 @@ #include "fibonacci_heap.h" #include "print-rtl.h" +#if (GCC_VERSION >= 3000) +#undef cfun +#pragma GCC poison cfun +// TODO: poison current_function_decl +#endif + typedef fibonacci_heap bb_heap_t; typedef fibonacci_node bb_heap_node_t; @@ -636,7 +642,7 @@ static void stack_adjust_offset_pre_post (rtx, HOST_WIDE_INT *, HOST_WIDE_INT *); static void insn_stack_adjust_offset_pre_post (rtx_insn *, HOST_WIDE_INT *, HOST_WIDE_INT *); -static bool vt_stack_adjustments (void); +static bool vt_stack_adjustments (function *); static void init_attrs_list_set (attrs **); static void attrs_list_clear (attrs **); @@ -678,13 +684,13 @@ static bool track_expr_p (tree, bool); static void add_uses_1 (rtx *, void *); static void add_stores (rtx, const_rtx, void *); static bool compute_bb_dataflow (basic_block); -static bool vt_find_locations (void); +static bool vt_find_locations (function *); static void dump_attrs_list (attrs *); static void dump_var (variable *); static void dump_vars (variable_table_type *); static void dump_dataflow_set (dataflow_set *); -static void dump_dataflow_sets (void); +static void dump_dataflow_sets (function *); static void set_dv_changed (decl_or_value, bool); static void variable_was_changed (variable *, dataflow_set *); @@ -703,11 +709,11 @@ static variable **delete_slot_part (dataflow_set *, rtx, variable **, static void delete_variable_part (dataflow_set *, rtx, decl_or_value, HOST_WIDE_INT); static void emit_notes_in_bb (basic_block, dataflow_set *); -static void vt_emit_notes (void); +static void vt_emit_notes (function *); -static void vt_add_function_parameters (void); -static bool vt_initialize (void); -static void vt_finalize (void); +static void vt_add_function_parameters (function *); +static bool vt_initialize (function *); +static void vt_finalize (function *); /* Callback for stack_adjust_offset_pre_post, called via for_each_inc_dec. */ @@ -815,24 +821,24 @@ insn_stack_adjust_offset_pre_post (rtx_insn *insn, HOST_WIDE_INT *pre, Heavily borrowed from pre_and_rev_post_order_compute. */ static bool -vt_stack_adjustments (void) +vt_stack_adjustments (function *fun) { edge_iterator *stack; int sp; /* Initialize entry block. */ - VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->visited = true; - VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->in.stack_adjust + VTI (ENTRY_BLOCK_PTR_FOR_FN (fun))->visited = true; + VTI (ENTRY_BLOCK_PTR_FOR_FN (fun))->in.stack_adjust = INCOMING_FRAME_SP_OFFSET; - VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->out.stack_adjust + VTI (ENTRY_BLOCK_PTR_FOR_FN (fun))->out.stack_adjust = INCOMING_FRAME_SP_OFFSET; /* Allocate stack for back-tracking up CFG. */ - stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1); + stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (fun) + 1); sp = 0; /* Push the first edge on to the stack. */ - stack[sp++] = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs); + stack[sp++] = ei_start (ENTRY_BLOCK_PTR_FOR_FN (fun)->succs); while (sp) { @@ -853,7 +859,7 @@ vt_stack_adjustments (void) VTI (dest)->visited = true; VTI (dest)->in.stack_adjust = offset = VTI (src)->out.stack_adjust; - if (dest != EXIT_BLOCK_PTR_FOR_FN (cfun)) + if (dest != EXIT_BLOCK_PTR_FOR_FN (fun)) for (insn = BB_HEAD (dest); insn != NEXT_INSN (BB_END (dest)); insn = NEXT_INSN (insn)) @@ -889,7 +895,7 @@ vt_stack_adjustments (void) We must check whether the adjustments on other edges are the same though. */ - if (dest != EXIT_BLOCK_PTR_FOR_FN (cfun) + if (dest != EXIT_BLOCK_PTR_FOR_FN (fun) && VTI (dest)->in.stack_adjust != VTI (src)->out.stack_adjust) { free (stack); @@ -7053,7 +7059,7 @@ compute_bb_dataflow (basic_block bb) /* Find the locations of variables in the whole function. */ static bool -vt_find_locations (void) +vt_find_locations (function *fun) { bb_heap_t *worklist = new bb_heap_t (LONG_MIN); bb_heap_t *pending = new bb_heap_t (LONG_MIN); @@ -7070,19 +7076,19 @@ vt_find_locations (void) timevar_push (TV_VAR_TRACKING_DATAFLOW); /* Compute reverse completion order of depth first search of the CFG so that the data-flow runs faster. */ - rc_order = XNEWVEC (int, n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS); - bb_order = XNEWVEC (int, last_basic_block_for_fn (cfun)); + rc_order = XNEWVEC (int, n_basic_blocks_for_fn (fun) - NUM_FIXED_BLOCKS); + bb_order = XNEWVEC (int, last_basic_block_for_fn (fun)); pre_and_rev_post_order_compute (NULL, rc_order, false); - for (i = 0; i < n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; i++) + for (i = 0; i < n_basic_blocks_for_fn (fun) - NUM_FIXED_BLOCKS; i++) bb_order[rc_order[i]] = i; free (rc_order); - auto_sbitmap visited (last_basic_block_for_fn (cfun)); - in_worklist = sbitmap_alloc (last_basic_block_for_fn (cfun)); - in_pending = sbitmap_alloc (last_basic_block_for_fn (cfun)); + auto_sbitmap visited (last_basic_block_for_fn (fun)); + in_worklist = sbitmap_alloc (last_basic_block_for_fn (fun)); + in_pending = sbitmap_alloc (last_basic_block_for_fn (fun)); bitmap_clear (in_worklist); - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) pending->insert (bb_order[bb->index], bb); bitmap_ones (in_pending); @@ -7180,11 +7186,11 @@ vt_find_locations (void) if (htabmax && htabsz > htabmax) { if (MAY_HAVE_DEBUG_BIND_INSNS) - inform (DECL_SOURCE_LOCATION (cfun->decl), + inform (DECL_SOURCE_LOCATION (fun->decl), "variable tracking size limit exceeded with " "-fvar-tracking-assignments, retrying without"); else - inform (DECL_SOURCE_LOCATION (cfun->decl), + inform (DECL_SOURCE_LOCATION (fun->decl), "variable tracking size limit exceeded"); success = false; break; @@ -7194,7 +7200,7 @@ vt_find_locations (void) { FOR_EACH_EDGE (e, ei, bb->succs) { - if (e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun)) + if (e->dest == EXIT_BLOCK_PTR_FOR_FN (fun)) continue; if (bitmap_bit_p (visited, e->dest->index)) @@ -7240,7 +7246,7 @@ vt_find_locations (void) } if (success && MAY_HAVE_DEBUG_BIND_INSNS) - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) gcc_assert (VTI (bb)->flooded); free (bb_order); @@ -7363,11 +7369,11 @@ dump_dataflow_set (dataflow_set *set) /* Print the IN and OUT sets for each basic block to dump file. */ static void -dump_dataflow_sets (void) +dump_dataflow_sets (function *fun) { basic_block bb; - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) { fprintf (dump_file, "\nBasic block %d:\n", bb->index); fprintf (dump_file, "IN:\n"); @@ -9533,7 +9539,7 @@ emit_notes_in_bb (basic_block bb, dataflow_set *set) /* Emit notes for the whole function. */ static void -vt_emit_notes (void) +vt_emit_notes (function *fun) { basic_block bb; dataflow_set cur; @@ -9542,7 +9548,7 @@ vt_emit_notes (void) /* Free memory occupied by the out hash tables, as they aren't used anymore. */ - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) dataflow_set_clear (&VTI (bb)->out); /* Enable emitting notes by functions (mainly by set_variable_part and @@ -9554,7 +9560,7 @@ vt_emit_notes (void) dataflow_set_init (&cur); - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) { /* Emit the notes for changes of variable locations between two subsequent basic blocks. */ @@ -9660,7 +9666,7 @@ record_entry_value (cselib_val *val, rtx rtl) /* Insert function parameter PARM in IN and OUT sets of ENTRY_BLOCK. */ static void -vt_add_function_parameter (tree parm) +vt_add_function_parameter (function *fun, tree parm) { rtx decl_rtl = DECL_RTL_IF_SET (parm); rtx incoming = DECL_INCOMING_RTL (parm); @@ -9792,7 +9798,7 @@ vt_add_function_parameter (tree parm) if (!track_loc_p (incoming, parm, offset, false, &mode, &const_offset)) return; - out = &VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->out; + out = &VTI (ENTRY_BLOCK_PTR_FOR_FN (fun))->out; dv = dv_from_decl (parm); @@ -9903,13 +9909,13 @@ vt_add_function_parameter (tree parm) /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK. */ static void -vt_add_function_parameters (void) +vt_add_function_parameters (function *fun) { tree parm; for (parm = DECL_ARGUMENTS (current_function_decl); parm; parm = DECL_CHAIN (parm)) - vt_add_function_parameter (parm); + vt_add_function_parameter (fun, parm); if (DECL_HAS_VALUE_EXPR_P (DECL_RESULT (current_function_decl))) { @@ -9922,7 +9928,7 @@ vt_add_function_parameters (void) && DECL_ARTIFICIAL (vexpr) && !DECL_IGNORED_P (vexpr) && DECL_NAMELESS (vexpr)) - vt_add_function_parameter (vexpr); + vt_add_function_parameter (fun, vexpr); } } @@ -9968,7 +9974,7 @@ vt_init_cfa_base (void) /* Reemit INSN, a MARKER_DEBUG_INSN, as a note. */ static rtx_insn * -reemit_marker_as_note (rtx_insn *insn) +reemit_marker_as_note (function *fun, rtx_insn *insn) { gcc_checking_assert (DEBUG_MARKER_INSN_P (insn)); @@ -9980,7 +9986,7 @@ reemit_marker_as_note (rtx_insn *insn) case NOTE_INSN_INLINE_ENTRY: { rtx_insn *note = NULL; - if (cfun->debug_nonbind_markers) + if (fun->debug_nonbind_markers) { note = emit_note_before (kind, insn); NOTE_MARKER_LOCATION (note) = INSN_LOCATION (insn); @@ -9998,7 +10004,7 @@ reemit_marker_as_note (rtx_insn *insn) and parse the RTL to get the micro operations. */ static bool -vt_initialize (void) +vt_initialize (function *fun) { basic_block bb; poly_int64 fp_cfa_offset = -1; @@ -10011,7 +10017,7 @@ vt_initialize (void) changed_variables = new variable_table_type (10); /* Init the IN and OUT sets. */ - FOR_ALL_BB_FN (bb, cfun) + FOR_ALL_BB_FN (bb, fun) { VTI (bb)->visited = false; VTI (bb)->flooded = false; @@ -10083,7 +10089,7 @@ vt_initialize (void) { rtx reg, elim; - if (!vt_stack_adjustments ()) + if (!vt_stack_adjustments (fun)) return false; #ifdef FRAME_POINTER_CFA_OFFSET @@ -10155,9 +10161,9 @@ vt_initialize (void) hard_frame_pointer_adjustment = -1; - vt_add_function_parameters (); + vt_add_function_parameters (fun); - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) { rtx_insn *insn; HOST_WIDE_INT pre, post = 0; @@ -10175,7 +10181,7 @@ vt_initialize (void) for (;;) { edge e; - if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun) + if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (fun) || ! single_pred_p (bb->next_bb)) break; e = find_edge (bb, bb->next_bb); @@ -10220,7 +10226,7 @@ vt_initialize (void) if (DEBUG_MARKER_INSN_P (insn)) { - reemit_marker_as_note (insn); + reemit_marker_as_note (fun, insn); continue; } @@ -10291,7 +10297,7 @@ vt_initialize (void) } hard_frame_pointer_adjustment = -1; - VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->flooded = true; + VTI (ENTRY_BLOCK_PTR_FOR_FN (fun))->flooded = true; cfa_base_rtx = NULL_RTX; return true; } @@ -10306,11 +10312,11 @@ static int debug_label_num = 1; variable tracking at assignments. */ static inline void -delete_vta_debug_insn (rtx_insn *insn) +delete_vta_debug_insn (function *fun, rtx_insn *insn) { if (DEBUG_MARKER_INSN_P (insn)) { - reemit_marker_as_note (insn); + reemit_marker_as_note (fun, insn); return; } @@ -10335,7 +10341,7 @@ delete_vta_debug_insn (rtx_insn *insn) longer usable. */ void -delete_vta_debug_insns (bool use_cfg) +delete_vta_debug_insns (function *fun, bool use_cfg) { basic_block bb; rtx_insn *insn, *next; @@ -10344,18 +10350,18 @@ delete_vta_debug_insns (bool use_cfg) return; if (use_cfg) - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) { FOR_BB_INSNS_SAFE (bb, insn, next) if (DEBUG_INSN_P (insn)) - delete_vta_debug_insn (insn); + delete_vta_debug_insn (fun, insn); } else for (insn = get_insns (); insn; insn = next) { next = NEXT_INSN (insn); if (DEBUG_INSN_P (insn)) - delete_vta_debug_insn (insn); + delete_vta_debug_insn (fun, insn); } } @@ -10366,25 +10372,25 @@ delete_vta_debug_insns (bool use_cfg) handled as well.. */ static void -vt_debug_insns_local (bool skipped ATTRIBUTE_UNUSED) +vt_debug_insns_local (function *fun, bool skipped ATTRIBUTE_UNUSED) { /* ??? Just skip it all for now. */ - delete_vta_debug_insns (true); + delete_vta_debug_insns (fun, true); } /* Free the data structures needed for variable tracking. */ static void -vt_finalize (void) +vt_finalize (function *fun) { basic_block bb; - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) { VTI (bb)->mos.release (); } - FOR_ALL_BB_FN (bb, cfun) + FOR_ALL_BB_FN (bb, fun) { dataflow_set_destroy (&VTI (bb)->in); dataflow_set_destroy (&VTI (bb)->out); @@ -10430,7 +10436,7 @@ vt_finalize (void) /* The entry point to variable tracking pass. */ static inline unsigned int -variable_tracking_main_1 (void) +variable_tracking_main_1 (function *fun) { bool success; @@ -10442,75 +10448,75 @@ variable_tracking_main_1 (void) any pseudos at this point. */ || targetm.no_register_allocation) { - delete_vta_debug_insns (true); + delete_vta_debug_insns (fun, true); return 0; } if (!flag_var_tracking) return 0; - if (n_basic_blocks_for_fn (cfun) > 500 - && n_edges_for_fn (cfun) / n_basic_blocks_for_fn (cfun) >= 20) + if (n_basic_blocks_for_fn (fun) > 500 + && n_edges_for_fn (fun) / n_basic_blocks_for_fn (fun) >= 20) { - vt_debug_insns_local (true); + vt_debug_insns_local (fun, true); return 0; } mark_dfs_back_edges (); - if (!vt_initialize ()) + if (!vt_initialize (fun)) { - vt_finalize (); - vt_debug_insns_local (true); + vt_finalize (fun); + vt_debug_insns_local (fun, true); return 0; } - success = vt_find_locations (); + success = vt_find_locations (fun); if (!success && flag_var_tracking_assignments > 0) { - vt_finalize (); + vt_finalize (fun); - delete_vta_debug_insns (true); + delete_vta_debug_insns (fun, true); /* This is later restored by our caller. */ flag_var_tracking_assignments = 0; - success = vt_initialize (); + success = vt_initialize (fun); gcc_assert (success); - success = vt_find_locations (); + success = vt_find_locations (fun); } if (!success) { - vt_finalize (); - vt_debug_insns_local (false); + vt_finalize (fun); + vt_debug_insns_local (fun, false); return 0; } if (dump_file && (dump_flags & TDF_DETAILS)) { - dump_dataflow_sets (); + dump_dataflow_sets (fun); dump_reg_info (dump_file); dump_flow_info (dump_file, dump_flags); } timevar_push (TV_VAR_TRACKING_EMIT); - vt_emit_notes (); + vt_emit_notes (fun); timevar_pop (TV_VAR_TRACKING_EMIT); - vt_finalize (); - vt_debug_insns_local (false); + vt_finalize (fun); + vt_debug_insns_local (fun, false); return 0; } unsigned int -variable_tracking_main (void) +variable_tracking_main (function *fun) { unsigned int ret; int save = flag_var_tracking_assignments; - ret = variable_tracking_main_1 (); + ret = variable_tracking_main_1 (fun); flag_var_tracking_assignments = save; @@ -10545,9 +10551,9 @@ public: return (flag_var_tracking && !targetm.delay_vartrack); } - virtual unsigned int execute (function *) + virtual unsigned int execute (function *fun) { - return variable_tracking_main (); + return variable_tracking_main (fun); } }; // class pass_variable_tracking -- 1.8.5.3